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 .Nd remove preprocessor conditionals from code
43 .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 using macros specified in
78 command line options or in
81 A directive is processed
82 if the macro specifications are sufficient to provide
83 a definite value for its control expression.
84 If the result is false,
85 the directive and the following lines under its control are removed.
86 If the result is true,
87 only the directive is removed.
92 directive is passed through unchanged
93 if its controlling macro is not specified.
98 control expression that has an unknown value or that
100 cannot parse is passed through unchanged.
107 lines with constant expressions;
108 it can be told to process them by specifying the
110 flag on the command line.
112 It understands a commonly-used subset
113 of the expression syntax for
119 integer values of macros defined on the command line,
125 .Ic <= , >= , == , != ,
127 and parenthesized expressions.
130 evaluation is used for the
133 if either operand is definitely false then the result is false,
134 even if the value of the other operand is unknown.
138 is definitely true then the result is true.
140 When evaluating an expression,
142 does not expand macros first.
143 The value of a macro must be a simple number,
145 A limited form of indirection is allowed,
146 where one macro's value is the name of another.
150 does not distinguish between object-like macros
151 (without arguments) and function-like macros (with arguments).
152 A function-like macro invocation can appear in
157 If the macro is not explicitly defined,
158 or is defined with the
160 flag on the command-line,
166 its arguments are ignored.
167 If a macro is explicitly undefined on the command line with the
175 it may not have any arguments since this leads to a syntax error.
179 utility understands just enough about C
180 to know when one of the directives is inactive
183 or affected by a backslash-continued line.
184 It spots unusually-formatted preprocessor directives
185 and knows when the layout is too odd for it to handle.
189 can be used to remove all conditional
191 directives from a file.
196 to get lists of all the controlling macros
197 and their definitions (or lack thereof),
200 with appropriate arguments to process the file.
202 .Bl -tag -width indent -compact
203 .It Fl D Ns Ar sym Ns = Ns Ar val
204 Specify that a macro is defined to a given value.
207 Specify that a macro is defined to the value 1.
210 Specify that a macro is undefined.
212 If the same macro appears in more than one argument,
213 the last occurrence dominates.
215 .It Fl iD Ns Ar sym Ns Op = Ns Ar val
218 and line continuations
225 specified with these options.
234 preprocessor directives,
235 which have the same effect as the corresponding
239 command-line arguments.
240 You can have multiple
242 arguments and mix them with
247 later options override earlier ones.
249 Each directive must be on a single line.
250 Object-like macro definitions (without arguments)
251 are set to the given value.
252 Function-like macro definitions (with arguments)
253 are treated as if they are set to 1.
256 Replace removed lines with blank lines
257 instead of deleting them.
258 Mutually exclusive with the
263 Compress blank lines around a deleted section.
264 Mutually exclusive with the
270 i.e., lines that would have been removed or blanked
271 are retained and vice versa.
274 Turn on printing of debugging messages.
279 will report an error if it needs to remove
280 a preprocessor directive that spans more than one line,
281 for example, if it has a multi-line
282 comment hanging off its right hand end.
285 flag makes it ignore the line instead.
293 an additional place to look for
296 This option is ignored by
298 for compatibility with
300 and to simplify the implementation of
304 Always treat the result of
308 operators as unknown if either operand is unknown,
309 instead of short-circuiting when unknown operands can't affect the result.
310 This option is for compatibility with older versions of
318 lines with constant expressions.
319 By default, sections controlled by such lines are passed through unchanged
320 because they typically start
322 and are used as a kind of comment to sketch out future or past development.
323 It would be rude to strip them out, just as it would be for normal comments.
326 Modify one or more input files in place.
327 If an input file is not modified,
328 the original is preserved instead of being overwritten with an identical copy.
331 Modify input files in place, and keep backups of the original files by
334 to the input filenames.
339 directives to the output following any deleted lines,
340 so that errors produced when compiling the output file correspond to
341 line numbers in the input file.
344 Write output to the file
346 instead of the standard output when processing a single file.
349 Instead of processing an input file as usual,
352 to produce a list of macros that are used in
353 preprocessor directive controlling expressions.
358 option, but the nesting depth of each macro is also printed.
359 This is useful for working out the number of possible combinations
360 of interdependent defined/undefined macros.
363 Disables parsing for C strings, comments,
364 and line continuations,
367 This is a blanket version of the
374 Print version details.
376 .It Fl x Bro Ar 012 Brc
377 Set exit status mode to zero, one, or two.
380 section below for details.
385 utility takes its input from
394 options if there are multiple input files.
395 You can specify inut from stdin or output to stdout with
400 utility works nicely with the
407 utility's exit status depends on the mode set using the
411 If the exit mode is zero (the default) then
413 exits with status 0 if the output is an exact copy of the input,
414 or with status 1 if the output differs.
416 If the exit mode is one,
418 exits with status 1 if the output is unmodified
421 If the exit mode is two,
423 exits with status zero in both cases.
427 exits with status 2 if there is an error.
429 The exit status is 0 if the
433 command line options are given.
437 Too many levels of nesting.
445 Obfuscated preprocessor control line.
449 (with the line number of the most recent unterminated
459 The unifdef home page is
460 .Pa http://dotat.at/prog/unifdef
470 The original implementation was written by
471 .An Dave Yost Aq Mt Dave@Yost.com .
472 .An Tony Finch Aq Mt dot@dotat.at
473 rewrote it to support
476 Expression evaluation is very limited.
478 Handling one line at a time means
479 preprocessor directives split across more than one physical line
480 (because of comments or backslash-newline)
481 cannot be handled in every situation.
483 Trigraphs are not recognized.
485 There is no support for macros with different definitions at
486 different points in the source file.
488 The text-mode and ignore functionality does not correspond to modern