1 .\" Copyright (c) 1985, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
3 .\" Copyright (c) 2002 - 2015 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
36 .Nm unifdef , unifdefall
37 .Nd remove preprocessor conditionals from code
42 .Op Fl [i]D Ns Ar sym Ns Op = Ns Ar val
46 .Op Fl x Bro Ar 012 Brc
57 utility selectively processes conditional
60 It removes from a file
62 and any additional text that they specify should be removed,
63 while otherwise leaving the file alone.
68 .Ic #if , #ifdef , #ifndef ,
73 using macros specified in
77 command line options or in
80 A directive is processed
81 if the macro specifications are sufficient to provide
82 a definite value for its control expression.
83 If the result is false,
84 the directive and the following lines under its control are removed.
85 If the result is true,
86 only the directive is removed.
91 directive is passed through unchanged
92 if its controlling macro is not specified.
97 control expression that has an unknown value or that
99 cannot parse is passed through unchanged.
106 lines with constant expressions;
107 it can be told to process them by specifying the
109 flag on the command line.
111 It understands a commonly-used subset
112 of the expression syntax for
118 integer values of macros defined on the command line,
125 .Ic * , / , % , + , - ,
126 .Ic < , <= , > , >= , == , != , & , ^ , \&| ,
128 and parenthesized expressions.
129 Division by zero is treated as an unknown value.
132 evaluation is used for the
135 if either operand is definitely false then the result is false,
136 even if the value of the other operand is unknown.
140 is definitely true then the result is true.
142 When evaluating an expression,
144 does not expand macros first.
145 The value of a macro must be a simple number,
147 A limited form of indirection is allowed,
148 where one macro's value is the name of another.
152 does not distinguish between object-like macros
153 (without arguments) and function-like macros (with arguments).
154 A function-like macro invocation can appear in
159 If the macro is not explicitly defined,
160 or is defined with the
162 flag on the command-line,
168 its arguments are ignored.
169 If a macro is explicitly undefined on the command line with the
177 it may not have any arguments since this leads to a syntax error.
181 utility understands just enough about C
182 to know when one of the directives is inactive
185 or cannot be evaluated because it is split by a backslash-continued line.
186 It spots unusually-formatted preprocessor directives
187 and passes them through unchanged when the layout is too odd for it to handle.
194 can be used to remove all conditional
196 directives from a file.
201 to get lists of all the controlling macros
202 and their definitions (or lack thereof),
205 with appropriate arguments to process the file.
207 .Bl -tag -width indent -compact
208 .It Fl D Ns Ar sym Ns = Ns Ar val
209 Specify that a macro is defined to a given value.
212 Specify that a macro is defined to the value 1.
215 Specify that a macro is undefined.
217 If the same macro appears in more than one argument,
218 the last occurrence dominates.
220 .It Fl iD Ns Ar sym Ns Op = Ns Ar val
223 and line continuations
230 specified with these options.
239 preprocessor directives,
240 which have the same effect as the corresponding
244 command-line arguments.
245 You can have multiple
247 arguments and mix them with
252 later options override earlier ones.
254 Each directive must be on a single line.
255 Object-like macro definitions (without arguments)
256 are set to the given value.
257 Function-like macro definitions (with arguments)
258 are treated as if they are set to 1.
261 string literals and character constants are not parsed correctly in
266 Replace removed lines with blank lines
267 instead of deleting them.
268 Mutually exclusive with the
273 Compress blank lines around a deleted section.
274 Mutually exclusive with the
280 i.e., lines that would have been removed or blanked
281 are retained and vice versa.
284 Turn on printing of debugging messages.
289 will report an error if it needs to remove
290 a preprocessor directive that spans more than one line,
291 for example, if it has a multi-line
292 comment hanging off its right hand end.
295 flag makes it ignore the line instead.
303 an additional place to look for
306 This option is ignored by
308 for compatibility with
310 and to simplify the implementation of
314 Always treat the result of
318 operators as unknown if either operand is unknown,
319 instead of short-circuiting when unknown operands can't affect the result.
320 This option is for compatibility with older versions of
328 lines with constant expressions.
329 By default, sections controlled by such lines are passed through unchanged
330 because they typically start
332 and are used as a kind of comment to sketch out future or past development.
333 It would be rude to strip them out, just as it would be for normal comments.
336 Modify one or more input files in place.
337 If an input file is not modified,
338 the original is preserved instead of being overwritten with an identical copy.
341 Modify input files in place, and keep backups of the original files by
344 to the input filenames.
347 behaves the same as the
354 directives to the output following any deleted lines,
355 so that errors produced when compiling the output file correspond to
356 line numbers in the input file.
359 Write output to the file
361 instead of the standard output when processing a single file.
364 Instead of processing an input file as usual,
367 to produce a list of macros that are used in
368 preprocessor directive controlling expressions.
373 option, but the nesting depth of each macro is also printed.
374 This is useful for working out the number of possible combinations
375 of interdependent defined/undefined macros.
378 Disables parsing for C strings, comments,
379 and line continuations,
382 This is a blanket version of the
389 Print version details.
391 .It Fl x Bro Ar 012 Brc
392 Set exit status mode to zero, one, or two.
395 section below for details.
400 utility takes its input from
409 options if there are multiple input files.
410 You can specify inut from stdin or output to stdout with
415 utility works nicely with the
422 utility's exit status depends on the mode set using the
426 If the exit mode is zero (the default) then
428 exits with status 0 if the output is an exact copy of the input,
429 or with status 1 if the output differs.
431 If the exit mode is one,
433 exits with status 1 if the output is unmodified
436 If the exit mode is two,
438 exits with status zero in both cases.
442 exits with status 2 if there is an error.
444 The exit status is 0 if the
448 command line options are given.
461 Missing macro name in #define or #undef
463 Obfuscated preprocessor control line
467 (with the line number of the most recent unterminated
470 Too many levels of nesting
472 Unrecognized preprocessor directive
474 Unterminated char or string literal
480 The unifdef home page is
481 .Pa http://dotat.at/prog/unifdef
492 The original implementation was written by
493 .An Dave Yost Aq Mt Dave@Yost.com .
494 .An Tony Finch Aq Mt dot@dotat.at
495 rewrote it to support
500 Expression evaluation is very limited.
502 Character constants are not evaluated.
503 String literals and character constants in
505 definition files are ignored rather than parsed as
506 part of a macro's replacement tokens.
508 Only the basic form of C++ raw string literals is recognized,
511 without delimiters as in
512 .Li R"delimiter(string)delimiter" .
514 Source files are processed one line at a time,
515 so preprocessor directives split across more than one physical line
516 (because of comments or backslash-newline)
517 cannot be handled in every situation.
519 Trigraphs are not recognized.
521 There is no support for macros with different definitions at
522 different points in the source file.
524 The text-mode and ignore functionality does not correspond to modern
529 Please send bug reports by email to
530 .Aq Mt dot@dotat.at .