1UNIFDEF(1) BSD General Commands Manual UNIFDEF(1)
2
4 unifdef, unifdefall — remove preprocessor conditionals from code
5
7 unifdef [-cdeklnst] [-Ipath] [-Dsym[=val]] [-Usym] [-iDsym[=val]]
8 [-iUsym] ... [file]
9 unifdefall [-Ipath] ... file
10
12 The unifdef utility selectively processes conditional cpp(1) directives.
13 It removes from a file both the directives and any additional text that
14 they specify should be removed, while otherwise leaving the file alone.
15
16 The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and
17 #endif lines, and it understands only the commonly-used subset of the
18 expression syntax for #if and #elif lines. It handles integer values of
19 symbols defined on the command line, the defined() operator applied to
20 symbols defined or undefined on the command line, the operators !, <, >,
21 <=, >=, ==, !=, &&, ||, and parenthesized expressions. Anything that it
22 does not understand is passed through unharmed. It only processes #ifdef
23 and #ifndef directives if the symbol is specified on the command line,
24 otherwise they are also passed through unchanged. By default, it ignores
25 #if and #elif lines with constant expressions, or they may be processed
26 by specifying the -k flag on the command line.
27
28 The unifdef utility also understands just enough about C to know when one
29 of the directives is inactive because it is inside a comment, or affected
30 by a backslash-continued line. It spots unusually-formatted preprocessor
31 directives and knows when the layout is too odd to handle.
32
33 A script called unifdefall can be used to remove all conditional cpp(1)
34 directives from a file. It uses unifdef -s and cpp -dM to get lists of
35 all the controlling symbols and their definitions (or lack thereof), then
36 invokes unifdef with appropriate arguments to process the file.
37
38 Available options:
39
40 -Dsym[=val]
41 Specify that a symbol is defined, and optionally specify what
42 value to give it for the purpose of handling #if and #elif direc‐
43 tives.
44
45 -Usym Specify that a symbol is undefined. If the same symbol appears
46 in more than one argument, the last occurrence dominates.
47
48 -c If the -c flag is specified, then the operation of unifdef is
49 complemented, i.e., the lines that would have been removed or
50 blanked are retained and vice versa.
51
52 -d Turn on printing of degugging messages.
53
54 -e Because unifdef processes its input one line at a time, it cannot
55 remove preprocessor directives that span more than one line. The
56 most common example of this is a directive with a multi-line com‐
57 ment hanging off its right hand end. By default, if unifdef has
58 to process such a directive, it will complain that the line is
59 too obfuscated. The -e option changes the behaviour so that,
60 where possible, such lines are left unprocessed instead of
61 reporting an error.
62
63 -k Process #if and #elif lines with constant expressions. By
64 default, sections controlled by such lines are passed through
65 unchanged because they typically start “#if 0” and are used as a
66 kind of comment to sketch out future or past development. It
67 would be rude to strip them out, just as it would be for normal
68 comments.
69
70 -l Replace removed lines with blank lines instead of deleting them.
71
72 -n Add #line directives to the output following any deleted lines,
73 so that errors produced when compiling the output file correspond
74 to line numbers in the input file.
75
76 -s Instead of processing the input file as usual, this option causes
77 unifdef to produce a list of symbols that appear in expressions
78 that unifdef understands. It is useful in conjunction with the
79 -dM option of cpp(1) for creating unifdef command lines.
80
81 -t Disables parsing for C comments and line continuations, which is
82 useful for plain text.
83
84 -iDsym[=val]
85 -iUsym Ignore #ifdefs. If your C code uses #ifdefs to delimit non-C
86 lines, such as comments or code which is under construction, then
87 you must tell unifdef which symbols are used for that purpose so
88 that it will not try to parse comments and line continuations
89 inside those #ifdefs. One specifies ignored symbols with
90 -iDsym[=val] and -iUsym similar to -Dsym[=val] and -Usym above.
91
92 -Ipath Specifies to unifdefall an additional place to look for #include
93 files. This option is ignored by unifdef for compatibility with
94 cpp(1) and to simplify the implementation of unifdefall.
95
96 The unifdef utility copies its output to stdout and will take its input
97 from stdin if no file argument is given.
98
99 The unifdef utility works nicely with the -Dsym option of diff(1).
100
102 The unifdef utility exits 0 if the output is an exact copy of the input,
103 1 if not, and 2 if in trouble.
104
106 Too many levels of nesting.
107
108 Inappropriate #elif, #else or #endif.
109
110 Obfuscated preprocessor control line.
111
112 Premature EOF (with the line number of the most recent unterminated #if).
113
114 EOF in comment.
115
117 cpp(1), diff(1)
118
120 The unifdef command appeared in 4.3BSD. ANSI C support was added in
121 FreeBSD 4.7.
122
124 Expression evaluation is very limited.
125
126 Preprocessor control lines split across more than one physical line
127 (because of comments or backslash-newline) cannot be handled in every
128 situation.
129
130 Trigraphs are not recognized.
131
132 There is no support for symbols with different definitions at different
133 points in the source file.
134
135 The text-mode and ignore functionality does not correspond to modern
136 cpp(1) behaviour.
137
138BSD September 24, 2002 BSD