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
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,
127 .Ic * , / , % , + , - ,
128 .Ic < , <= , > , >= , == , != , & , ^ , \&| ,
130 and parenthesized expressions.
131 Division by zero is treated as an unknown value.
134 evaluation is used for the
137 if either operand is definitely false then the result is false,
138 even if the value of the other operand is unknown.
142 is definitely true then the result is true.
144 When evaluating an expression,
146 does not expand macros first.
147 The value of a macro must be a simple number,
149 A limited form of indirection is allowed,
150 where one macro's value is the name of another.
154 does not distinguish between object-like macros
155 (without arguments) and function-like macros (with arguments).
156 A function-like macro invocation can appear in
161 If the macro is not explicitly defined,
162 or is defined with the
164 flag on the command-line,
170 its arguments are ignored.
171 If a macro is explicitly undefined on the command line with the
179 it may not have any arguments since this leads to a syntax error.
183 utility understands just enough about C
184 to know when one of the directives is inactive
187 or affected by a backslash-continued line.
188 It spots unusually-formatted preprocessor directives
189 and knows when the layout is too odd for it to handle.
193 can be used to remove all conditional
195 directives from a file.
200 to get lists of all the controlling macros
201 and their definitions (or lack thereof),
204 with appropriate arguments to process the file.
206 .Bl -tag -width indent -compact
207 .It Fl D Ns Ar sym Ns = Ns Ar val
208 Specify that a macro is defined to a given value.
211 Specify that a macro is defined to the value 1.
214 Specify that a macro is undefined.
216 If the same macro appears in more than one argument,
217 the last occurrence dominates.
219 .It Fl iD Ns Ar sym Ns Op = Ns Ar val
222 and line continuations
229 specified with these options.
238 preprocessor directives,
239 which have the same effect as the corresponding
243 command-line arguments.
244 You can have multiple
246 arguments and mix them with
251 later options override earlier ones.
253 Each directive must be on a single line.
254 Object-like macro definitions (without arguments)
255 are set to the given value.
256 Function-like macro definitions (with arguments)
257 are treated as if they are set to 1.
260 string literals and character constants are not parsed correctly in
265 Replace removed lines with blank lines
266 instead of deleting them.
267 Mutually exclusive with the
272 Compress blank lines around a deleted section.
273 Mutually exclusive with the
279 i.e., lines that would have been removed or blanked
280 are retained and vice versa.
283 Turn on printing of debugging messages.
288 will report an error if it needs to remove
289 a preprocessor directive that spans more than one line,
290 for example, if it has a multi-line
291 comment hanging off its right hand end.
294 flag makes it ignore the line instead.
302 an additional place to look for
305 This option is ignored by
307 for compatibility with
309 and to simplify the implementation of
313 Always treat the result of
317 operators as unknown if either operand is unknown,
318 instead of short-circuiting when unknown operands can't affect the result.
319 This option is for compatibility with older versions of
327 lines with constant expressions.
328 By default, sections controlled by such lines are passed through unchanged
329 because they typically start
331 and are used as a kind of comment to sketch out future or past development.
332 It would be rude to strip them out, just as it would be for normal comments.
335 Modify one or more input files in place.
336 If an input file is not modified,
337 the original is preserved instead of being overwritten with an identical copy.
340 Modify input files in place, and keep backups of the original files by
343 to the input filenames.
346 behaves the same as the
353 directives to the output following any deleted lines,
354 so that errors produced when compiling the output file correspond to
355 line numbers in the input file.
358 Write output to the file
360 instead of the standard output when processing a single file.
363 Instead of processing an input file as usual,
366 to produce a list of macros that are used in
367 preprocessor directive controlling expressions.
372 option, but the nesting depth of each macro is also printed.
373 This is useful for working out the number of possible combinations
374 of interdependent defined/undefined macros.
377 Disables parsing for C strings, comments,
378 and line continuations,
381 This is a blanket version of the
388 Print version details.
390 .It Fl x Bro Ar 012 Brc
391 Set exit status mode to zero, one, or two.
394 section below for details.
399 utility takes its input from
408 options if there are multiple input files.
409 You can specify input from stdin or output to stdout with
414 utility works nicely with the
421 utility's exit status depends on the mode set using the
425 If the exit mode is zero (the default) then
427 exits with status 0 if the output is an exact copy of the input,
428 or with status 1 if the output differs.
430 If the exit mode is one,
432 exits with status 1 if the output is unmodified
435 If the exit mode is two,
437 exits with status zero in both cases.
441 exits with status 2 if there is an error.
443 The exit status is 0 if the
447 command line options are given.
460 Missing macro name in #define or #undef
462 Obfuscated preprocessor control line
466 (with the line number of the most recent unterminated
469 Too many levels of nesting
471 Unrecognized preprocessor directive
473 Unterminated char or string literal
479 The unifdef home page is
480 .Pa https://dotat.at/prog/unifdef
491 The original implementation was written by
492 .An Dave Yost Aq Mt Dave@Yost.com .
493 .An Tony Finch Aq Mt dot@dotat.at
494 rewrote it to support
497 Expression evaluation is very limited.
499 Character constants are not evaluated.
500 String literals and character constants in
502 definition files are ignored rather than parsed as
503 part of a macro's replacement tokens.
505 Handling one line at a time means
506 preprocessor directives split across more than one physical line
507 (because of comments or backslash-newline)
508 cannot be handled in every situation.
510 Trigraphs are not recognized.
512 There is no support for macros with different definitions at
513 different points in the source file.
515 The text-mode and ignore functionality does not correspond to modern