]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - usr.bin/unifdef/unifdef.1
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.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 - 2005 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: things/unifdef.1,v 1.51 2005/03/08 12:39:01 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 cdeklnst
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 and it understands only the commonly-used subset
75 of the expression syntax for
76 .Ic #if
77 and
78 .Ic #elif
79 lines.
80 It handles
81 integer values of symbols defined on the command line,
82 the
83 .Fn defined
84 operator applied to symbols defined or undefined on the command line,
85 the operators
86 .Ic \&! , < , > , <= , >= , == , != , && , || ,
87 and parenthesized expressions.
88 Anything that it does not understand is passed through unharmed.
89 It only processes
90 .Ic #ifdef
91 and
92 .Ic #ifndef
93 directives if the symbol is specified on the command line,
94 otherwise they are also passed through unchanged.
95 By default, it ignores
96 .Ic #if
97 and
98 .Ic #elif
99 lines with constant expressions,
100 or they may be processed by specifying the
101 .Fl k
102 flag on the command line.
103 .Pp
104 The
105 .Nm
106 utility also understands just enough about C
107 to know when one of the directives is inactive
108 because it is inside
109 a comment,
110 or affected by a backslash-continued line.
111 It spots unusually-formatted preprocessor directives
112 and knows when the layout is too odd to handle.
113 .Pp
114 A script called
115 .Nm unifdefall
116 can be used to remove all conditional
117 .Xr cpp 1
118 directives from a file.
119 It uses
120 .Nm Fl s
121 and
122 .Nm cpp Fl dM
123 to get lists of all the controlling symbols
124 and their definitions (or lack thereof),
125 then invokes
126 .Nm
127 with appropriate arguments to process the file.
128 .Pp
129 Available options:
130 .Pp
131 .Bl -tag -width indent -compact
132 .It Fl D Ns Ar sym Ns Op = Ns Ar val
133 Specify that a symbol is defined,
134 and optionally specify what value to give it
135 for the purpose of handling
136 .Ic #if
137 and
138 .Ic #elif
139 directives.
140 .Pp
141 .It Fl U Ns Ar sym
142 Specify that a symbol is undefined.
143 If the same symbol appears in more than one argument,
144 the last occurrence dominates.
145 .Pp
146 .It Fl c
147 If the
148 .Fl c
149 flag is specified,
150 then the operation of
151 .Nm
152 is complemented,
153 i.e., the lines that would have been removed or blanked
154 are retained and vice versa.
155 .Pp
156 .It Fl d
157 Turn on printing of degugging messages.
158 .Pp
159 .It Fl e
160 Because
161 .Nm
162 processes its input one line at a time,
163 it cannot remove preprocessor directives that span more than one line.
164 The most common example of this is a directive with a multi-line
165 comment hanging off its right hand end.
166 By default,
167 if
168 .Nm
169 has to process such a directive,
170 it will complain that the line is too obfuscated.
171 The
172 .Fl e
173 option changes the behaviour so that,
174 where possible,
175 such lines are left unprocessed instead of reporting an error.
176 .Pp
177 .It Fl k
178 Process
179 .Ic #if
180 and
181 .Ic #elif
182 lines with constant expressions.
183 By default, sections controlled by such lines are passed through unchanged
184 because they typically start
185 .Dq Li "#if 0"
186 and are used as a kind of comment to sketch out future or past development.
187 It would be rude to strip them out, just as it would be for normal comments.
188 .Pp
189 .It Fl l
190 Replace removed lines with blank lines
191 instead of deleting them.
192 .Pp
193 .It Fl n
194 Add
195 .Li #line
196 directives to the output following any deleted lines,
197 so that errors produced when compiling the output file correspond to
198 line numbers in the input file.
199 .Pp
200 .It Fl s
201 Instead of processing the input file as usual,
202 this option causes
203 .Nm
204 to produce a list of symbols that appear in expressions
205 that
206 .Nm
207 understands.
208 It is useful in conjunction with the
209 .Fl dM
210 option of
211 .Xr cpp 1
212 for creating
213 .Nm
214 command lines.
215 .Pp
216 .It Fl t
217 Disables parsing for C comments
218 and line continuations,
219 which is useful
220 for plain text.
221 .Pp
222 .It Fl iD Ns Ar sym Ns Op = Ns Ar val
223 .It Fl iU Ns Ar sym
224 Ignore
225 .Ic #ifdef Ns s .
226 If your C code uses
227 .Ic #ifdef Ns s
228 to delimit non-C lines,
229 such as comments
230 or code which is under construction,
231 then you must tell
232 .Nm
233 which symbols are used for that purpose so that it will not try to parse
234 comments
235 and line continuations
236 inside those
237 .Ic #ifdef Ns s .
238 One specifies ignored symbols with
239 .Fl iD Ns Ar sym Ns Oo = Ns Ar val Oc
240 and
241 .Fl iU Ns Ar sym
242 similar to
243 .Fl D Ns Ar sym Ns Op = Ns Ar val
244 and
245 .Fl U Ns Ar sym
246 above.
247 .Pp
248 .It Fl I Ns Ar path
249 Specifies to
250 .Nm unifdefall
251 an additional place to look for
252 .Ic #include
253 files.
254 This option is ignored by
255 .Nm
256 for compatibility with
257 .Xr cpp 1
258 and to simplify the implementation of
259 .Nm unifdefall .
260 .El
261 .Pp
262 The
263 .Nm
264 utility copies its output to
265 .Em stdout
266 and will take its input from
267 .Em stdin
268 if no
269 .Ar file
270 argument is given.
271 .Pp
272 The
273 .Nm
274 utility works nicely with the
275 .Fl D Ns Ar sym
276 option of
277 .Xr diff 1 .
278 .Sh EXIT STATUS
279 The
280 .Nm
281 utility exits 0 if the output is an exact copy of the input,
282 1 if not, and 2 if in trouble.
283 .Sh DIAGNOSTICS
284 .Bl -item
285 .It
286 Too many levels of nesting.
287 .It
288 Inappropriate
289 .Ic #elif ,
290 .Ic #else
291 or
292 .Ic #endif .
293 .It
294 Obfuscated preprocessor control line.
295 .It
296 Premature
297 .Tn EOF
298 (with the line number of the most recent unterminated
299 .Ic #if ) .
300 .It
301 .Tn EOF
302 in comment.
303 .El
304 .Sh SEE ALSO
305 .Xr cpp 1 ,
306 .Xr diff 1
307 .Sh HISTORY
308 The
309 .Nm
310 command appeared in
311 .Bx 2.9 .
312 .Tn ANSI\~C
313 support was added in
314 .Fx 4.7 .
315 .Sh AUTHORS
316 This implementation was originally written by
317 .An Dave Yost Aq Dave@Yost.com .
318 .An Tony Finch Aq dot@dotat.at
319 rewrote it to support
320 .Tn ANSI\~C .
321 .Sh BUGS
322 Expression evaluation is very limited.
323 .Pp
324 Preprocessor control lines split across more than one physical line
325 (because of comments or backslash-newline)
326 cannot be handled in every situation.
327 .Pp
328 Trigraphs are not recognized.
329 .Pp
330 There is no support for symbols with different definitions at
331 different points in the source file.
332 .Pp
333 The text-mode and ignore functionality does not correspond to modern
334 .Xr cpp 1
335 behaviour.