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