]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - usr.bin/unifdef/unifdef.1
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / usr.bin / unifdef / unifdef.1
1 .\" Copyright (c) 1985, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\" Copyright (c) 2002 - 2009 Tony Finch <dot@dotat.at>.  All rights reserved.
4 .\"
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Dave Yost. It was rewritten to support ANSI C by Tony Finch.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
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.
19 .\"
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
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)unifdef.1   8.2 (Berkeley) 4/1/94
33 .\"     $dotat: unifdef/unifdef.1,v 1.60 2009/11/25 00:11:02 fanf2 Exp $
34 .\" $FreeBSD$
35 .\"
36 .Dd September 24, 2002
37 .Dt UNIFDEF 1
38 .Os
39 .Sh NAME
40 .Nm unifdef , unifdefall
41 .Nd remove preprocessor conditionals from code
42 .Sh SYNOPSIS
43 .Nm
44 .Op Fl BbcdeKknst
45 .Op Fl I Ns Ar path
46 .Op Fl D Ns Ar sym Ns Op = Ns Ar val
47 .Op Fl U Ns Ar sym
48 .Op Fl iD Ns Ar sym Ns Op = Ns Ar val
49 .Op Fl iU Ns Ar sym
50 .Ar ...
51 .Op Ar file
52 .Nm unifdefall
53 .Op Fl I Ns Ar path
54 .Ar ...
55 .Ar file
56 .Sh DESCRIPTION
57 The
58 .Nm
59 utility selectively processes conditional
60 .Xr cpp 1
61 directives.
62 It removes from a file
63 both the directives
64 and any additional text that they specify should be removed,
65 while otherwise leaving the file alone.
66 .Pp
67 The
68 .Nm
69 utility acts on
70 .Ic #if , #ifdef , #ifndef , #elif , #else ,
71 and
72 .Ic #endif
73 lines.
74 A directive is only processed
75 if the symbols specified on the command line are sufficient to allow
76 .Nm
77 to get a definite value for its control expression.
78 If the result is false,
79 the directive and the following lines under its control are removed.
80 If the result is true,
81 only the directive is removed.
82 An
83 .Ic #ifdef
84 or
85 .Ic #ifndef
86 directive is passed through unchanged
87 if its controlling symbol is not specified on the command line.
88 Any
89 .Ic #if
90 or
91 .Ic #elif
92 control expression that has an unknown value or that
93 .Nm
94 cannot parse is passed through unchanged.
95 By default,
96 .Nm
97 ignores
98 .Ic #if
99 and
100 .Ic #elif
101 lines with constant expressions;
102 it can be told to process them by specifying the
103 .Fl k
104 flag on the command line.
105 .Pp
106 It understands a commonly-used subset
107 of the expression syntax for
108 .Ic #if
109 and
110 .Ic #elif
111 lines:
112 integer constants,
113 integer values of symbols defined on the command line,
114 the
115 .Fn defined
116 operator,
117 the operators
118 .Ic \&! , < , > , <= , >= , == , != , && , || ,
119 and parenthesized expressions.
120 A kind of
121 .Dq "short circuit"
122 evaluation is used for the
123 .Ic &&
124 operator:
125 if either operand is definitely false then the result is false,
126 even if the value of the other operand is unknown.
127 Similarly,
128 if either operand of
129 .Ic ||
130 is definitely true then the result is true.
131 .Pp
132 In most cases, the
133 .Nm
134 utility does not distinguish between object-like macros
135 (without arguments) and function-like arguments (with arguments).
136 If a macro is not explicitly defined, or is defined with the
137 .Fl D
138 flag on the command-line, its arguments are ignored.
139 If a macro is explicitly undefined on the command line with the
140 .Fl U
141 flag, it may not have any arguments since this leads to a syntax error.
142 .Pp
143 The
144 .Nm
145 utility understands just enough about C
146 to know when one of the directives is inactive
147 because it is inside
148 a comment,
149 or affected by a backslash-continued line.
150 It spots unusually-formatted preprocessor directives
151 and knows when the layout is too odd for it to handle.
152 .Pp
153 A script called
154 .Nm unifdefall
155 can be used to remove all conditional
156 .Xr cpp 1
157 directives from a file.
158 It uses
159 .Nm Fl s
160 and
161 .Nm cpp Fl dM
162 to get lists of all the controlling symbols
163 and their definitions (or lack thereof),
164 then invokes
165 .Nm
166 with appropriate arguments to process the file.
167 .Sh OPTIONS
168 .Pp
169 .Bl -tag -width indent -compact
170 .It Fl D Ns Ar sym Ns Op = Ns Ar val
171 Specify that a symbol is defined,
172 and optionally specify what value to give it
173 for the purpose of handling
174 .Ic #if
175 and
176 .Ic #elif
177 directives.
178 .Pp
179 .It Fl U Ns Ar sym
180 Specify that a symbol is undefined.
181 If the same symbol appears in more than one argument,
182 the last occurrence dominates.
183 .Pp
184 .It Fl B
185 Compress blank lines around a deleted section.
186 Mutually exclusive with the
187 .Fl b
188 option.
189 .Pp
190 .It Fl b
191 Replace removed lines with blank lines
192 instead of deleting them.
193 Mutually exclusive with the
194 .Fl B
195 option.
196 .Pp
197 .It Fl c
198 If the
199 .Fl c
200 flag is specified,
201 then the operation of
202 .Nm
203 is complemented,
204 i.e., the lines that would have been removed or blanked
205 are retained and vice versa.
206 .Pp
207 .It Fl d
208 Turn on printing of degugging messages.
209 .Pp
210 .It Fl e
211 Because
212 .Nm
213 processes its input one line at a time,
214 it cannot remove preprocessor directives that span more than one line.
215 The most common example of this is a directive with a multi-line
216 comment hanging off its right hand end.
217 By default,
218 if
219 .Nm
220 has to process such a directive,
221 it will complain that the line is too obfuscated.
222 The
223 .Fl e
224 option changes the behaviour so that,
225 where possible,
226 such lines are left unprocessed instead of reporting an error.
227 .Pp
228 .It Fl K
229 Always treat the result of
230 .Ic &&
231 and
232 .Ic ||
233 operators as unknown if either operand is unknown,
234 instead of short-circuiting when unknown operands can't affect the result.
235 This option is for compatibility with older versions of
236 .Nm .
237 .Pp
238 .It Fl k
239 Process
240 .Ic #if
241 and
242 .Ic #elif
243 lines with constant expressions.
244 By default, sections controlled by such lines are passed through unchanged
245 because they typically start
246 .Dq Li "#if 0"
247 and are used as a kind of comment to sketch out future or past development.
248 It would be rude to strip them out, just as it would be for normal comments.
249 .Pp
250 .It Fl n
251 Add
252 .Li #line
253 directives to the output following any deleted lines,
254 so that errors produced when compiling the output file correspond to
255 line numbers in the input file.
256 .Pp
257 .It Fl s
258 Instead of processing the input file as usual,
259 this option causes
260 .Nm
261 to produce a list of symbols that appear in expressions
262 that
263 .Nm
264 understands.
265 It is useful in conjunction with the
266 .Fl dM
267 option of
268 .Xr cpp 1
269 for creating
270 .Nm
271 command lines.
272 .Pp
273 .It Fl t
274 Disables parsing for C comments
275 and line continuations,
276 which is useful
277 for plain text.
278 .Pp
279 .It Fl iD Ns Ar sym Ns Op = Ns Ar val
280 .It Fl iU Ns Ar sym
281 Ignore
282 .Ic #ifdef Ns s .
283 If your C code uses
284 .Ic #ifdef Ns s
285 to delimit non-C lines,
286 such as comments
287 or code which is under construction,
288 then you must tell
289 .Nm
290 which symbols are used for that purpose so that it will not try to parse
291 comments
292 and line continuations
293 inside those
294 .Ic #ifdef Ns s .
295 You can specify ignored symbols with
296 .Fl iD Ns Ar sym Ns Oo = Ns Ar val Oc
297 and
298 .Fl iU Ns Ar sym
299 similar to
300 .Fl D Ns Ar sym Ns Op = Ns Ar val
301 and
302 .Fl U Ns Ar sym
303 above.
304 .Pp
305 .It Fl I Ns Ar path
306 Specifies to
307 .Nm unifdefall
308 an additional place to look for
309 .Ic #include
310 files.
311 This option is ignored by
312 .Nm
313 for compatibility with
314 .Xr cpp 1
315 and to simplify the implementation of
316 .Nm unifdefall .
317 .El
318 .Pp
319 The
320 .Nm
321 utility copies its output to
322 .Em stdout
323 and will take its input from
324 .Em stdin
325 if no
326 .Ar file
327 argument is given.
328 .Pp
329 The
330 .Nm
331 utility works nicely with the
332 .Fl D Ns Ar sym
333 option of
334 .Xr diff 1 .
335 .Sh EXIT STATUS
336 The
337 .Nm
338 utility exits 0 if the output is an exact copy of the input,
339 1 if not, and 2 if in trouble.
340 .Sh DIAGNOSTICS
341 .Bl -item
342 .It
343 Too many levels of nesting.
344 .It
345 Inappropriate
346 .Ic #elif ,
347 .Ic #else
348 or
349 .Ic #endif .
350 .It
351 Obfuscated preprocessor control line.
352 .It
353 Premature
354 .Tn EOF
355 (with the line number of the most recent unterminated
356 .Ic #if ) .
357 .It
358 .Tn EOF
359 in comment.
360 .El
361 .Sh SEE ALSO
362 .Xr cpp 1 ,
363 .Xr diff 1
364 .Sh HISTORY
365 The
366 .Nm
367 command appeared in
368 .Bx 2.9 .
369 .Tn ANSI\~C
370 support was added in
371 .Fx 4.7 .
372 .Sh AUTHORS
373 The original implementation was written by
374 .An Dave Yost Aq Dave@Yost.com .
375 .An Tony Finch Aq dot@dotat.at
376 rewrote it to support
377 .Tn ANSI\~C .
378 .Sh BUGS
379 Expression evaluation is very limited.
380 .Pp
381 Preprocessor control lines split across more than one physical line
382 (because of comments or backslash-newline)
383 cannot be handled in every situation.
384 .Pp
385 Trigraphs are not recognized.
386 .Pp
387 There is no support for symbols with different definitions at
388 different points in the source file.
389 .Pp
390 The text-mode and ignore functionality does not correspond to modern
391 .Xr cpp 1
392 behaviour.