Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pix/cppp
Fork of cppp: A Partial Preprocessor for C from Brian Raiter
https://github.com/pix/cppp
Last synced: 16 days ago
JSON representation
Fork of cppp: A Partial Preprocessor for C from Brian Raiter
- Host: GitHub
- URL: https://github.com/pix/cppp
- Owner: pix
- Created: 2012-09-12T12:47:48.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-09-12T12:49:24.000Z (about 12 years ago)
- Last Synced: 2024-07-31T22:58:07.434Z (3 months ago)
- Language: C
- Size: 117 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
cppp is a partial preprocessor for C/C++ code. It implements enough of
the C preprocessor to identify the preprocessor statements #if,
#ifdef, et al., and applies their effects for the identifiers that are
specified on the command-line. Preprocessor statements using
identifiers not specified by the user are passed through without
modification. And no other part of the input is altered.Thus, if cppp is invoked with the options -DFOO -UBAR, then FOO will
be defined, BAR will be undefined, and all other identifiers will be
unaffected. A section guarded by "#ifdef FOO" will be included in the
output without the guard statements, and a section guarded by "#ifdef
BAR" will be entirely dropped from the output.In addition to removing #ifdef statements, cppp understands complex
expressions in #if statements that involve the defined operator, and
will apply the effects even partially. Thus for example the
preprocessor statement "#if (defined(BAR) || defined(BAZ))" would be
edited to read "#if defined(BAZ)" in the output.cppp can also handle simple numeric tests. For example, giving cppp
the option -D_LIB_VERSION=5 would cause the preprocessor statement
"#if _LIB_VERSION >= 4" to succeed. Note, however, that cppp is
limited to dealing with integer constants. The preprocessor statement
"#if _LIB_VERSION >= _HEADER_FILE_VERSION" would simply get rewritten
to "#if 5 >= _HEADER_FILE_VERSION", even if a definition for
_HEADER_FILE_VERSION was provided in the same file.The general purpose of this program is to deal with legacy code bases
where #ifdefs have crept in and infiltrated the source. This sort of
thing usually happens while code is transitioning from one platform to
another, in the misguided belief that this will ease the process
rather than make it more confusing. Then, if the time finally comes
that the ifdefs can be safely removed, it often doesn't get done
because it's too tedious and error-prone to do it manually.I originally wrote cppp as an interesting exercise, but I later wound
up using it to save myself from just such a tedious task. Sadly,
because the code was not originally intended to be seen by anyone, it
is not well-written and in some places it is downright opaque. I have
attempted to ameliorate this by cleaning up some of the most egregious
inconsistencies and adding a handful of comments, but the central
functions are quite large and not easily explicated (particularly with
all the intervening years since the time of its original creation). I
offer it solely as a tool that might save you from a mind-numbing
chore, but not as something to learn from.Brian Raiter
[email protected]
June, 2011