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
48 .Op Fl x Bro Ar 012 Brc
59 utility selectively processes conditional
62 It removes from a file
64 and any additional text that they specify should be removed,
65 while otherwise leaving the file alone.
70 .Ic #if , #ifdef , #ifndef ,
75 using macros specified in
79 command line options or in
82 A directive is processed
83 if the macro specifications are sufficient to provide
84 a definite value for its control expression.
85 If the result is false,
86 the directive and the following lines under its control are removed.
87 If the result is true,
88 only the directive is removed.
93 directive is passed through unchanged
94 if its controlling macro is not specified.
99 control expression that has an unknown value or that
101 cannot parse is passed through unchanged.
108 lines with constant expressions;
109 it can be told to process them by specifying the
111 flag on the command line.
113 It understands a commonly-used subset
114 of the expression syntax for
120 integer values of macros defined on the command line,
126 .Ic <= , >= , == , != ,
128 and parenthesized expressions.
131 evaluation is used for the
134 if either operand is definitely false then the result is false,
135 even if the value of the other operand is unknown.
139 is definitely true then the result is true.
141 When evaluating an expression,
143 does not expand macros first.
144 The value of a macro must be a simple number,
146 A limited form of indirection is allowed,
147 where one macro's value is the name of another.
151 does not distinguish between object-like macros
152 (without arguments) and function-like macros (with arguments).
153 A function-like macro invocation can appear in
158 If the macro is not explicitly defined,
159 or is defined with the
161 flag on the command-line,
167 its arguments are ignored.
168 If a macro is explicitly undefined on the command line with the
176 it may not have any arguments since this leads to a syntax error.
180 utility understands just enough about C
181 to know when one of the directives is inactive
184 or affected by a backslash-continued line.
185 It spots unusually-formatted preprocessor directives
186 and knows when the layout is too odd for it to handle.
190 can be used to remove all conditional
192 directives from a file.
197 to get lists of all the controlling macros
198 and their definitions (or lack thereof),
201 with appropriate arguments to process the file.
203 .Bl -tag -width indent -compact
204 .It Fl D Ns Ar sym Ns = Ns Ar val
205 Specify that a macro is defined to a given value.
208 Specify that a macro is defined to the value 1.
211 Specify that a macro is undefined.
213 If the same macro appears in more than one argument,
214 the last occurrence dominates.
216 .It Fl iD Ns Ar sym Ns Op = Ns Ar val
219 and line continuations
226 specified with these options.
235 preprocessor directives,
236 which have the same effect as the corresponding
240 command-line arguments.
241 You can have multiple
243 arguments and mix them with
248 later options override earlier ones.
250 Each directive must be on a single line.
251 Object-like macro definitions (without arguments)
252 are set to the given value.
253 Function-like macro definitions (with arguments)
254 are treated as if they are set to 1.
257 Replace removed lines with blank lines
258 instead of deleting them.
259 Mutually exclusive with the
264 Compress blank lines around a deleted section.
265 Mutually exclusive with the
271 i.e., lines that would have been removed or blanked
272 are retained and vice versa.
275 Turn on printing of debugging messages.
280 will report an error if it needs to remove
281 a preprocessor directive that spans more than one line,
282 for example, if it has a multi-line
283 comment hanging off its right hand end.
286 flag makes it ignore the line instead.
294 an additional place to look for
297 This option is ignored by
299 for compatibility with
301 and to simplify the implementation of
305 Always treat the result of
309 operators as unknown if either operand is unknown,
310 instead of short-circuiting when unknown operands can't affect the result.
311 This option is for compatibility with older versions of
319 lines with constant expressions.
320 By default, sections controlled by such lines are passed through unchanged
321 because they typically start
323 and are used as a kind of comment to sketch out future or past development.
324 It would be rude to strip them out, just as it would be for normal comments.
327 Modify one or more input files in place.
330 Modify input files in place, and keep backups of the original files by
333 to the input filenames.
338 directives to the output following any deleted lines,
339 so that errors produced when compiling the output file correspond to
340 line numbers in the input file.
343 Write output to the file
345 instead of the standard output when processing a single file.
348 Instead of processing an input file as usual,
351 to produce a list of macros that are used in
352 preprocessor directive controlling expressions.
357 option, but the nesting depth of each macro is also printed.
358 This is useful for working out the number of possible combinations
359 of interdependent defined/undefined macros.
362 Disables parsing for C strings, comments,
363 and line continuations,
366 This is a blanket version of the
373 Print version details.
375 .It Fl x Bro Ar 012 Brc
376 Set exit status mode to zero, one, or two.
379 section below for details.
384 utility takes its input from
393 options if there are multiple input files.
394 You can specify inut from stdin or output to stdout with
399 utility works nicely with the
406 utility's exit status depends on the mode set using the
410 If the exit mode is zero (the default) then
412 exits with status 0 if the output is an exact copy of the input,
413 or with status 1 if the output differs.
415 If the exit mode is one,
417 exits with status 1 if the output is unmodified
420 If the exit mode is two,
422 exits with status zero in both cases.
426 exits with status 2 if there is an error.
428 The exit status is 0 if the
432 command line options are given.
436 Too many levels of nesting.
444 Obfuscated preprocessor control line.
448 (with the line number of the most recent unterminated
458 The unifdef home page is
459 .Pa http://dotat.at/prog/unifdef
469 The original implementation was written by
470 .An Dave Yost Aq Dave@Yost.com .
471 .An Tony Finch Aq dot@dotat.at
472 rewrote it to support
475 Expression evaluation is very limited.
477 Handling one line at a time means
478 preprocessor directives split across more than one physical line
479 (because of comments or backslash-newline)
480 cannot be handled in every situation.
482 Trigraphs are not recognized.
484 There is no support for macros with different definitions at
485 different points in the source file.
487 The text-mode and ignore functionality does not correspond to modern