UNIFDEF(1)                                                          UNIFDEF(1)


NAME
     unifdef - strip or reduce ifdefs in C code

SYNOPSIS
     unifdef [-Dname] [-Dname=string] [-Uname] [-ooutput] [-z] [input...]

DESCRIPTION
     Unifdef reads C source files and prints all input lines except those
     excluded by #ifdef constructs that refer to specified identifiers.

     The -D option defines name as a macro with the value 1, causing unifdef
     to simplify

          #ifdef name
          Included text
          #else
          Excluded text
          #endif


     to just

          Included text


     and contrariwise for #ifndef.

     The -U option works like -D except that name is undefined, so the #ifdef
     above would simplify to

          Excluded text


     -Dname=string causes unifdef to replace occurrences of name with string
     when evaluating #if and #elif expressions.  For example, unifdef -DBSD=43
     would rewrite

          #if BSD == 43
          4.3BSD code
          #elif BSD == 42
          4.2BSD code
          #endif


     as

          4.3BSD code


     All #ifdef constructs that refer to names not defined with -D or
     undefined with -U are passed unchanged to output.  Unifdef simplifies #if
     expressions that mix defined or undefined names with unknown names to


     express operations on just the unknown names.  Thus unifdef -Dsgi would
     rewrite

          #if defined sgi && !defined KERNEL


     as

          #ifndef KERNEL


     and would preserve associated #else and #endif sections.  Unifdef
     simplifies #elif chains as if they consisted of #if constructs nested
     within #else sections.  For example, unifdef -DBSD=43 would rewrite

          #if SYSV
          System V code
          #elif BSD == 42
          4.2BSD code
          #elif BSD == 43
          4.3BSD code
          #elif XENIX
          Xenix code
          #endif


     as

          #if SYSV
          System V code
          #else
          4.3BSD code
          #if XENIX
          Xenix code
          #endif
          #endif


     Unifdef rewrites #else and #endif lines to conform to ANSI C, by
     enclosing any tokens after these keywords with comment delimiters.  For
     example,

          #ifdef DEBUG
          Debugging code
          #endif DEBUG


     would be transcribed as

          #ifdef DEBUG
          Debugging code
          #endif /* DEBUG */


     Unifdef writes to standard output by default.  The -o option may be used
     in lieu of shell redirection to specify an output file.  More important,
     the file specified by output may be identical to one of the input files,
     or to standard input if there are no arguments.  In this case, unifdef
     will safely overwrite the input file.

     The -z option causes unifdef to simplify or eliminate sections controlled
     by #if constructs that test constant integer expressions.  By default,
     constructs such as

          #if 0
          Excluded text
          #endif


     are left intact.

AUTHOR
     Brendan Eich, 03/16/89

SEE ALSO
     cc(1), cpp(1).


                                                                        Page 3