The unifdef(1) command is useful for removing ifdefed
lines from a file, otherwise leaving the file alone.
The unifdef(1) command acts on #ifdef,#ifndef, #else, and
#endif lines; it knows only enough about C to discern when one of
these is inactive because it is inside a comment, or a single or
double quote. Its process of parsing for quotes is very simple:
when it finds an open quote, it ignores everything (except escaped
quotes) until it finds a close quote; it will not complain if it
gets to the end of a line and finds no backslash for
continuation.
This version of unifdef(1) has been extended to strip out
specified tagged comments. See the -C option for more
details
Available options:
-c
If the -c flag is specified, the operation of
unifdef(1) is complemented; that is, the lines that would
have been removed or blanked are retained and vice versa.
-Cstring
Strip out comments beginning with /* or // and
immediately followed by string. For example, the
command-line option -C@home will cause all comments
beginning with /*@home or //@home to be stripped,
including (for /*) multiline comments.
-Dsym
-Usym
Specify which symbols to define or undefine. The lines inside
those ifdefs will be copied to the output or removed as
appropriate. The ifdef, ifndef, else, and endif lines associated
with sym will also be removed. Ifdefs involving symbols you
do not specify and "#if" control lines are untouched and copied out
along with their associated ifdef, else, and endif lines. If an
ifdef X occurs nested inside another ifdef X, the inside ifdef is
treated as if it were an unrecognized symbol. If the same symbol
appears in more than one argument, the last occurrence
dominates.
-iDsym
-iUsym
Ignore the ifdefs associated with sym. If your C code
uses ifdefs to delimit non-C lines, such as comments or code that
is under construction, you must tell unifdef(1) which
symbols are used for that purpose so that it will not try to parse
for quotes and comments inside those ifdefs. Specify ignored ifdefs
with -iDsym and -iUsym, similar to
-Dsym and -Usym above.
-l
Replace removed lines with blank lines instead of deleting
them.
-t
Disables parsing for C comments and quotes, which is useful for
plain text.
The unifdef(1) command copies its output to stdout and
will take its input from stdin if no file argument is
given.
The unifdef(1) command works nicely with the -Dsym option added to diff(1) as of the 4.1 Berkeley
Software Distribution (BSD).