1 .\" $NetBSD: unifdef.1,v 1.12 2009/06/11 03:16:34 ginsbach Exp $
3 .\" Copyright (c) 1985, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" Portions of this code (support for #if and #elif) are Copyright (c)
34 .\" 2002, 2003 Tony Finch.
36 .\" Redistribution and use in source and binary forms, with or without
37 .\" modification, are permitted provided that the following conditions
39 .\" 1. Redistributions of source code must retain the above copyright
40 .\" notice, this list of conditions and the following disclaimer.
41 .\" 2. Redistributions in binary form must reproduce the above copyright
42 .\" notice, this list of conditions and the following disclaimer in the
43 .\" documentation and/or other materials provided with the distribution.
44 .\" 3. All advertising materials mentioning features or use of this software
45 .\" must display the following acknowledgement:
46 .\" This product includes software developed by the University of
47 .\" California, Berkeley and its contributors.
48 .\" 4. Neither the name of the University nor the names of its contributors
49 .\" may be used to endorse or promote products derived from this software
50 .\" without specific prior written permission.
52 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 .\" @(#)unifdef.1 8.2 (Berkeley) 4/1/94
65 .\" $dotat: things/unifdef.1,v 1.45 2003/01/20 14:37:08 fanf2 Exp $
66 .\" $FreeBSD: src/usr.bin/unifdef/unifdef.1,v 1.19 2003/01/20 12:41:41 fanf Exp $
74 .Nd remove preprocessor conditionals from code
79 .Op Fl D Ns Ar sym Ns Op = Ns Ar val
81 .Op Fl iD Ns Ar sym Ns Op = Ns Ar val
93 utility selectively processes conditional
96 It removes from a file both the directives and any additional text
97 that they specify should be removed, while otherwise leaving the
103 .Ic #if , #ifdef , #ifndef , #elif , #else ,
107 and it understands only the commonly-used subset
108 of the expression syntax for
114 integer values of symbols defined on the command line,
117 operator applied to symbols defined or undefined on the command line,
119 .Ic \&! , \*[Lt] , \*[Gt] , \*[Lt]= , \*[Gt]= , == , != , \*[Am]\*[Am] , || ,
120 and parenthesized expressions.
121 Anything that it does not understand is passed through unharmed.
126 directives if the symbol is specified on the command line,
127 otherwise they are also passed through unchanged.
128 By default, it ignores
132 lines with constant expressions,
133 or they may be processed by specifying the
135 flag on the command line.
139 utility also understands just enough about C
140 to know when one of the directives is inactive
143 or affected by a backslash-continued line.
144 It spots unusually-formatted preprocessor directives
145 and knows when the layout is too odd to handle.
149 can be used to remove all conditional
151 directives from a file.
156 to get lists of all the controlling symbols
157 and their definitions (or lack thereof),
160 with appropriate arguments to process the file.
163 .Bl -tag -width indent -compact
164 .It Fl D Ns Ar sym Ns Op = Ns Ar val
165 Specify that a symbol is defined,
166 and optionally specify what value to give it
167 for the purpose of handling
173 Specify that a symbol is undefined.
174 If the same symbol appears in more than one argument,
175 the last occurrence dominates.
180 then the operation of
183 i.e., the lines that would have been removed or blanked
184 are retained and vice versa.
188 processes its input one line at a time,
189 it cannot remove preprocessor directives that span more than one line.
190 The most common example of this is a directive with a multi-line
191 comment hanging off its right hand end.
195 has to process such a directive,
196 it will complain that the line is too obfuscated.
199 option changes the behaviour so that,
201 such lines are left unprocessed instead of reporting an error.
207 lines with constant expressions.
208 By default, sections controlled by such lines are passed through unchanged
209 because they typically start
211 and are used as a kind of comment to sketch out future or past development.
212 It would be rude to strip them out, just as it would be for normal comments.
214 Replace removed lines with blank lines
215 instead of deleting them.
217 The argument given is the name of an
219 file to be used instead of the standard output.
220 This file can be the same as the input file.
222 Instead of processing the input file as usual,
225 to produce a list of symbols that appear in expressions
229 It is useful in conjunction with the
237 Disables parsing for C comments
238 and line continuations,
241 .It Fl iD Ns Ar sym Ns Op = Ns Ar val
247 to delimit non-C lines,
249 or code which is under construction,
252 which symbols are used for that purpose so that it will not try to parse
254 and line continuations
257 One specifies ignored symbols with
258 .Fl iD Ns Ar sym Ns Oo = Ns Ar val Oc
262 .Fl D Ns Ar sym Ns Op = Ns Ar val
269 an additional place to look for
272 This option is ignored by
274 for compatibility with
276 and to simplify the implementation of
282 utility copies its output to
284 and will take its input from
292 utility works nicely with the
299 Too many levels of nesting.
307 Obfuscated preprocessor control line.
311 (with the line number of the most recent unterminated
320 utility exits 0 if the output is an exact copy of the input,
321 1 if not, and 2 if in trouble.
334 Expression evaluation is very limited.
336 Preprocessor control lines split across more than one physical line
337 (because of comments or backslash-newline)
338 cannot be handled in every situation.
340 Trigraphs are not recognized.
342 There is no support for symbols with different definitions at
343 different points in the source file.
345 The text-mode and ignore functionality does not correspond to modern