UNIFDEF(1) | General Commands Manual | UNIFDEF(1) |
unifdef | [-ceklst] [-Ipath] [-Dsym[=val]] [-Usym] [-iDsym[=val]] [-iUsym] ... [-o output] [file] |
unifdefall | [-Ipath] ... file |
The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and #endif lines, and it understands only the commonly-used subset of the expression syntax for #if and #elif lines. It handles integer values of symbols defined on the command line, the defined() operator applied to symbols defined or undefined on the command line, the operators !, <, >, <=, >=, ==, !=, &&, ||, and parenthesized expressions. Anything that it does not understand is passed through unharmed. It only processes #ifdef and #ifndef directives if the symbol is specified on the command line, otherwise they are also passed through unchanged. By default, it ignores #if and #elif lines with constant expressions, or they may be processed by specifying the -k flag on the command line.
The unifdef utility also understands just enough about C to know when one of the directives is inactive because it is inside a comment, or affected by a backslash-continued line. It spots unusually-formatted preprocessor directives and knows when the layout is too odd to handle.
A script called unifdefall can be used to remove all conditional cpp(1) directives from a file. It uses unifdef -s and cpp -dM to get lists of all the controlling symbols and their definitions (or lack thereof), then invokes unifdef with appropriate arguments to process the file.
Available options:
#if 0
” and are used as a kind of comment to sketch out future or past development. It would be rude to strip them out, just as it would be for normal comments.The unifdef utility copies its output to stdout and will take its input from stdin if no file argument is given.
The unifdef utility works nicely with the -Dsym option of diff(1).
The unifdef utility exits 0 if the output is an exact copy of the input, 1 if not, and 2 if in trouble.
Preprocessor control lines split across more than one physical line (because of comments or backslash-newline) cannot be handled in every situation.
Trigraphs are not recognized.
There is no support for symbols with different definitions at different points in the source file.
The text-mode and ignore functionality does not correspond to modern cpp(1) behaviour.
June 5, 2009 | NetBSD 6.1 |