MirBSD manpage: unifdef(1)

UNIFDEF(1)                   BSD Reference Manual                   UNIFDEF(1)


     unifdef - remove preprocessor conditionals from code


     unifdef [-cdeklst] [-Ipath -Dsym[=val] -Usym -iDsym[=val] -iUsym] ...
             [-x 0|1|2] [file]


     The unifdef utility selectively processes conditional cpp(1) directives.
     It removes from a file both the directives and any additional text that
     they specify should be removed, while otherwise leaving the file alone.

     The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and
     #endif lines, and it understands only the commonly-used subset of the ex-
     pression 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.

     Available options:

             Specify that a symbol is defined, and optionally specify what
             value to give it for the purpose of handling #if and #elif direc-

     -Ipath  Ignored, for compatibility with cpp.

     -Usym   Specify that a symbol is undefined. If the same symbol appears in
             more than one argument, the last occurrence dominates.

     -c      If the -c flag is specified, then the operation of unifdef is
             complemented, i.e., the lines that would have been removed or
             blanked are retained and vice versa.

     -d      Show debugging output. Only useful for developing unifdef itself.

     -e      Because unifdef processes its input one line at a time, it cannot
             remove preprocessor directives that span more than one line. The
             most common example of this is a directive with a multi-line com-
             ment hanging off its right hand end. By default, if unifdef has
             to process such a directive, it will complain that the line is
             too obfuscated. The -e option changes the behavior so that, where
             possible, such lines are left unprocessed instead of reporting an

     -k      Process #if and #elif lines with constant expressions. By de-
             fault, sections controlled by such lines are passed through un-
             changed because they typically start #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.

     -l      Replace removed lines with blank lines instead of deleting them.

     -s      Instead of processing the input file as usual, this option causes
             unifdef to produce a list of symbols that appear in expressions
             that unifdef understands. It is useful in conjunction with the
             -dM option of cpp(1) for creating unifdef command lines.

     -t      Disables parsing for C comments and line continuations, which is
             useful for plain text.

     -x mode
             Control the exit status of the unifdef utility. Default: 0

                                           condition \ mode    0    1    2
                   the output is an exact copy of the input    0    1    0
                   it is not an exact copy of the input        1    0    0
                   when in trouble                             2    2    2

     -iUsym  Ignore #ifdefs. If your C code uses #ifdefs to delimit non-C
             lines, such as comments or code which is under construction, then
             you must tell unifdef which symbols are used for that purpose so
             that it will not try to parse comments and line continuations in-
             side those #ifdefs. One specifies ignored symbols with
             -iDsym[=val] and -iUsym similar to -Dsym[=val] and -Usym above.

     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).


     Too many levels of nesting.

     Inappropriate #elif, #else or #endif.

     Obfuscated preprocessor control line.

     Premature EOF (with the line number of the most recent unterminated #if).

     EOF in comment.

     See -x mode above for the exit status of the unifdef utility.


     cpp(1), diff(1)


     The unifdef command appeared in 4.3BSD.


     Expression evaluation is very limited.

     Preprocessor control lines split across more than one physical line (be-
     cause of comments or backslash-newline) cannot be handled in every situa-

     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 doesn't correspond to modern
     cpp(1) behaviour.

MirBSD #10-current            September 3, 2022                              1

Generated on 2022-12-24 01:00:14 by $MirOS: src/scripts/roff2htm,v 1.113 2022/12/21 23:14:31 tg Exp $ — This product includes material provided by mirabilos.

These manual pages and other documentation are copyrighted by their respective writers; their sources are available at the project’s CVSweb, AnonCVS and other mirrors. The rest is Copyright © 2002–2022 MirBSD.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.

Kontakt / Impressum & Datenschutzerklärung