tradcpp - K&R-style C preprocessor

tradcpp is a K&R-style ("traditional") C preprocessor. It was written to support historical uses of the C preprocessor for preprocessing things that aren't C, as the preprocessors that ship with C compilers are increasingly unsuitable for this task and/or don't provide a traditional mode at all.

In particular, tradcpp preserves whitespace as much as possible, so it can be used in contexts where whitespace is significant and/or rearranging whitespace causes things to break, such as makefiles. Preprocessing makefiles with cpp is a fairly common property of sufficiently old legacy build systems, including old versions of Emacs and anything that uses imake.

pkgsrc, the NetBSD package system, has been using tradcpp for these purposes since 2013.

Note that tradcpp is specialized to its task and doesn't support many more or less conventional cpp features that don't tend to come up in its role. Adding support for these things is not a priority, but I'm happy to take noninvasive/sane patches. If you are intending to preprocess C code you probably want some other cpp that supports C89/C99/C11 — if you have a pile of legacy C code that only works with a K&R preprocessor (and compiler) you're better off (in even the fairly short term) modernizing the code than looking for tools to compile it as is.

One of the more interesting features that tradcpp does have is a trace mode, that produces a log of the definitions and conditionals encountered and substitutions made. This can be used to debug complex systems of cpp abuse; it was written to diagnose a mysterious problem with imake on Solaris.

tradcpp is available under a 2-clause BSD license, so you can pretty much do whatever you want with it. If you use it to win a Turing award or something I'd appreciate being credited appropriately, and if you manage to use it to make lots of money please feel free to send some to me (or to the NetBSD Foundation), but none of this is mandated.

The latest release is 0.5.3. There is a Mercurial repository but the public copy isn't currently working.

Report bugs (and send patches) using the NetBSD and pkgsrc bug database; set the Category to "pkg" and include "devel/tradcpp" in the Synopsis (summary).