1 .\" Copyright (c) 1985, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
3 .\" Copyright (c) 2002 - 2010 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
32 .\" $FreeBSD: src/usr.bin/unifdef/unifdef.1,v 1.30 2010/08/01 09:10:09 joel Exp $
38 .Nm unifdef , unifdefall
39 .Nd remove preprocessor conditionals from code
44 .Op Fl D Ns Ar sym Ns Op = Ns Ar val
46 .Op Fl iD Ns Ar sym Ns Op = Ns Ar val
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 , #elif , #else ,
73 A directive is only processed
74 if the symbols specified on the command line are sufficient to allow
76 to get a definite value for its control expression.
77 If the result is false,
78 the directive and the following lines under its control are removed.
79 If the result is true,
80 only the directive is removed.
85 directive is passed through unchanged
86 if its controlling symbol is not specified on the command line.
91 control expression that has an unknown value or that
93 cannot parse is passed through unchanged.
100 lines with constant expressions;
101 it can be told to process them by specifying the
103 flag on the command line.
105 It understands a commonly-used subset
106 of the expression syntax for
112 integer values of symbols defined on the command line,
117 .Ic \&! , < , > , <= , >= , == , != , && , || ,
118 and parenthesized expressions.
121 evaluation is used for the
124 if either operand is definitely false then the result is false,
125 even if the value of the other operand is unknown.
129 is definitely true then the result is true.
133 utility does not distinguish between object-like macros
134 (without arguments) and function-like arguments (with arguments).
135 If a macro is not explicitly defined, or is defined with the
137 flag on the command-line, its arguments are ignored.
138 If a macro is explicitly undefined on the command line with the
140 flag, it may not have any arguments since this leads to a syntax error.
144 utility understands just enough about C
145 to know when one of the directives is inactive
148 or affected by a backslash-continued line.
149 It spots unusually-formatted preprocessor directives
150 and knows when the layout is too odd for it to handle.
154 can be used to remove all conditional
156 directives from a file.
161 to get lists of all the controlling symbols
162 and their definitions (or lack thereof),
165 with appropriate arguments to process the file.
168 .Bl -tag -width indent -compact
169 .It Fl D Ns Ar sym Ns = Ns Ar val
170 Specify that a symbol is defined to a given value
171 which is used when evaluating
178 Specify that a symbol is defined to the value 1.
181 Specify that a symbol is undefined.
182 If the same symbol appears in more than one argument,
183 the last occurrence dominates.
186 Replace removed lines with blank lines
187 instead of deleting them.
188 Mutually exclusive with the
193 Compress blank lines around a deleted section.
194 Mutually exclusive with the
202 then the operation of
205 i.e., the lines that would have been removed or blanked
206 are retained and vice versa.
209 Turn on printing of debugging messages.
214 processes its input one line at a time,
215 it cannot remove preprocessor directives that span more than one line.
216 The most common example of this is a directive with a multi-line
217 comment hanging off its right hand end.
221 has to process such a directive,
222 it will complain that the line is too obfuscated.
225 option changes the behaviour so that,
227 such lines are left unprocessed instead of reporting an error.
230 Always treat the result of
234 operators as unknown if either operand is unknown,
235 instead of short-circuiting when unknown operands can't affect the result.
236 This option is for compatibility with older versions of
244 lines with constant expressions.
245 By default, sections controlled by such lines are passed through unchanged
246 because they typically start
248 and are used as a kind of comment to sketch out future or past development.
249 It would be rude to strip them out, just as it would be for normal comments.
254 directives to the output following any deleted lines,
255 so that errors produced when compiling the output file correspond to
256 line numbers in the input file.
259 Write output to the file
261 instead of the standard output.
264 is the same as the input file,
265 the output is written to a temporary file
266 which is renamed into place when
268 completes successfully.
271 Instead of processing the input file as usual,
274 to produce a list of symbols that appear in expressions
278 It is useful in conjunction with the
289 option, but the nesting depth of each symbol is also printed.
290 This is useful for working out the number of possible combinations
291 of interdependent defined/undefined symbols.
294 Disables parsing for C comments
295 and line continuations,
299 .It Fl iD Ns Ar sym Ns Op = Ns Ar val
305 to delimit non-C lines,
307 or code which is under construction,
310 which symbols are used for that purpose so that it will not try to parse
312 and line continuations
315 You can specify ignored symbols with
316 .Fl iD Ns Ar sym Ns Oo = Ns Ar val Oc
320 .Fl D Ns Ar sym Ns Op = Ns Ar val
328 an additional place to look for
331 This option is ignored by
333 for compatibility with
335 and to simplify the implementation of
339 Print version details.
344 utility copies its output to
346 and will take its input from
354 utility works nicely with the
361 utility exits 0 if the output is an exact copy of the input,
362 1 if not, and 2 if in trouble.
366 Too many levels of nesting.
374 Obfuscated preprocessor control line.
378 (with the line number of the most recent unterminated
396 The original implementation was written by
397 .An Dave Yost Aq Dave@Yost.com .
398 .An Tony Finch Aq dot@dotat.at
399 rewrote it to support
402 Expression evaluation is very limited.
404 Preprocessor control lines split across more than one physical line
405 (because of comments or backslash-newline)
406 cannot be handled in every situation.
408 Trigraphs are not recognized.
410 There is no support for symbols with different definitions at
411 different points in the source file.
413 The text-mode and ignore functionality does not correspond to modern