1 .\" Copyright (c) 1985, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
3 .\" Copyright (c) 2002 - 2013 Tony Finch <dot@dotat.at>. All rights reserved.
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Dave Yost. It was rewritten to support ANSI C by Tony Finch.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 .Nm unifdef , unifdefall
39 .Nd remove preprocessor conditionals from code
44 .Op Fl [i]D Ns Ar sym Ns Op = Ns Ar val
47 .Op Fl x Bro Ar 012 Brc
58 utility selectively processes conditional
61 It removes from a file
63 and any additional text that they specify should be removed,
64 while otherwise leaving the file alone.
69 .Ic #if , #ifdef , #ifndef ,
74 A directive is only processed
75 if the symbols specified on the command line are sufficient to allow
77 to get a definite value for its control expression.
78 If the result is false,
79 the directive and the following lines under its control are removed.
80 If the result is true,
81 only the directive is removed.
86 directive is passed through unchanged
87 if its controlling symbol is not specified on the command line.
92 control expression that has an unknown value or that
94 cannot parse is passed through unchanged.
101 lines with constant expressions;
102 it can be told to process them by specifying the
104 flag on the command line.
106 It understands a commonly-used subset
107 of the expression syntax for
113 integer values of symbols defined on the command line,
119 .Ic <= , >= , == , != ,
121 and parenthesized expressions.
124 evaluation is used for the
127 if either operand is definitely false then the result is false,
128 even if the value of the other operand is unknown.
132 is definitely true then the result is true.
136 utility does not distinguish between object-like macros
137 (without arguments) and function-like arguments (with arguments).
138 If a macro is not explicitly defined, or is defined with the
140 flag on the command-line, its arguments are ignored.
141 If a macro is explicitly undefined on the command line with the
143 flag, it may not have any arguments since this leads to a syntax error.
147 utility understands just enough about C
148 to know when one of the directives is inactive
151 or affected by a backslash-continued line.
152 It spots unusually-formatted preprocessor directives
153 and knows when the layout is too odd for it to handle.
157 can be used to remove all conditional
159 directives from a file.
164 to get lists of all the controlling symbols
165 and their definitions (or lack thereof),
168 with appropriate arguments to process the file.
170 .Bl -tag -width indent -compact
171 .It Fl D Ns Ar sym Ns = Ns Ar val
172 Specify that a symbol is defined to a given value
173 which is used when evaluating
180 Specify that a symbol is defined to the value 1.
183 Specify that a symbol is undefined.
184 If the same symbol appears in more than one argument,
185 the last occurrence dominates.
187 .It Fl iD Ns Ar sym Ns Op = Ns Ar val
190 and line continuations
196 controlled by symbols
197 specified with these options.
200 Replace removed lines with blank lines
201 instead of deleting them.
202 Mutually exclusive with the
207 Compress blank lines around a deleted section.
208 Mutually exclusive with the
214 i.e., lines that would have been removed or blanked
215 are retained and vice versa.
218 Turn on printing of debugging messages.
223 will report an error if it needs to remove
224 a preprocessor directive that spans more than one line,
225 for example, if it has a multi-line
226 comment hanging off its right hand end.
229 flag makes it ignore the line instead.
237 an additional place to look for
240 This option is ignored by
242 for compatibility with
244 and to simplify the implementation of
248 Always treat the result of
252 operators as unknown if either operand is unknown,
253 instead of short-circuiting when unknown operands can't affect the result.
254 This option is for compatibility with older versions of
262 lines with constant expressions.
263 By default, sections controlled by such lines are passed through unchanged
264 because they typically start
266 and are used as a kind of comment to sketch out future or past development.
267 It would be rude to strip them out, just as it would be for normal comments.
270 Modify one or more input files in place.
273 Modify input files in place, and keep backups of the original files by
276 to the input filenames.
281 directives to the output following any deleted lines,
282 so that errors produced when compiling the output file correspond to
283 line numbers in the input file.
286 Write output to the file
288 instead of the standard output when processing a single file.
291 Instead of processing an input file as usual,
294 to produce a list of symbols that appear in expressions
298 It is useful in conjunction with the
309 option, but the nesting depth of each symbol is also printed.
310 This is useful for working out the number of possible combinations
311 of interdependent defined/undefined symbols.
314 Disables parsing for C strings, comments,
315 and line continuations,
318 This is a blanket version of the
325 Print version details.
327 .It Fl x Bro Ar 012 Brc
328 Set exit status mode to zero, one, or two.
331 section below for details.
336 utility takes its input from
345 options if there are multiple input files.
346 You can specify inut from stdin or output to stdout with
351 utility works nicely with the
358 utility's exit status depends on the mode set using the
362 If the exit mode is zero (the default) then
364 exits with status 0 if the output is an exact copy of the input,
365 or with status 1 if the output differs.
367 If the exit mode is one,
369 exits with status 1 if the output is unmodified
372 If the exit mode is two,
374 exits with status zero in both cases.
378 exits with status 2 if there is an error.
380 The exit status is 0 if the
384 command line options are given.
388 Too many levels of nesting.
396 Obfuscated preprocessor control line.
400 (with the line number of the most recent unterminated
418 The original implementation was written by
419 .An Dave Yost Aq Dave@Yost.com .
420 .An Tony Finch Aq dot@dotat.at
421 rewrote it to support
424 Expression evaluation is very limited.
426 Handling one line at a time means
427 preprocessor directives split across more than one physical line
428 (because of comments or backslash-newline)
429 cannot be handled in every situation.
431 Trigraphs are not recognized.
433 There is no support for symbols with different definitions at
434 different points in the source file.
436 The text-mode and ignore functionality does not correspond to modern