xref: /minix3/usr.bin/unifdef/unifdef.1 (revision b6f0c436268cdf3df867d9382f2423f5a36f7a4d)
1*b6f0c436SThomas Cort.\"	$NetBSD: unifdef.1,v 1.12 2009/06/11 03:16:34 ginsbach Exp $
2*b6f0c436SThomas Cort.\"
3*b6f0c436SThomas Cort.\" Copyright (c) 1985, 1991, 1993
4*b6f0c436SThomas Cort.\"	The Regents of the University of California.  All rights reserved.
5*b6f0c436SThomas Cort.\"
6*b6f0c436SThomas Cort.\" This code is derived from software contributed to Berkeley by
7*b6f0c436SThomas Cort.\" Dave Yost.
8*b6f0c436SThomas Cort.\"
9*b6f0c436SThomas Cort.\" Redistribution and use in source and binary forms, with or without
10*b6f0c436SThomas Cort.\" modification, are permitted provided that the following conditions
11*b6f0c436SThomas Cort.\" are met:
12*b6f0c436SThomas Cort.\" 1. Redistributions of source code must retain the above copyright
13*b6f0c436SThomas Cort.\"    notice, this list of conditions and the following disclaimer.
14*b6f0c436SThomas Cort.\" 2. Redistributions in binary form must reproduce the above copyright
15*b6f0c436SThomas Cort.\"    notice, this list of conditions and the following disclaimer in the
16*b6f0c436SThomas Cort.\"    documentation and/or other materials provided with the distribution.
17*b6f0c436SThomas Cort.\" 3. Neither the name of the University nor the names of its contributors
18*b6f0c436SThomas Cort.\"    may be used to endorse or promote products derived from this software
19*b6f0c436SThomas Cort.\"    without specific prior written permission.
20*b6f0c436SThomas Cort.\"
21*b6f0c436SThomas Cort.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22*b6f0c436SThomas Cort.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*b6f0c436SThomas Cort.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*b6f0c436SThomas Cort.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25*b6f0c436SThomas Cort.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*b6f0c436SThomas Cort.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27*b6f0c436SThomas Cort.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28*b6f0c436SThomas Cort.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29*b6f0c436SThomas Cort.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30*b6f0c436SThomas Cort.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*b6f0c436SThomas Cort.\" SUCH DAMAGE.
32*b6f0c436SThomas Cort.\"
33*b6f0c436SThomas Cort.\" Portions of this code (support for #if and #elif) are Copyright (c)
34*b6f0c436SThomas Cort.\" 2002, 2003 Tony Finch.
35*b6f0c436SThomas Cort.\"
36*b6f0c436SThomas Cort.\" Redistribution and use in source and binary forms, with or without
37*b6f0c436SThomas Cort.\" modification, are permitted provided that the following conditions
38*b6f0c436SThomas Cort.\" are met:
39*b6f0c436SThomas Cort.\" 1. Redistributions of source code must retain the above copyright
40*b6f0c436SThomas Cort.\"    notice, this list of conditions and the following disclaimer.
41*b6f0c436SThomas Cort.\" 2. Redistributions in binary form must reproduce the above copyright
42*b6f0c436SThomas Cort.\"    notice, this list of conditions and the following disclaimer in the
43*b6f0c436SThomas Cort.\"    documentation and/or other materials provided with the distribution.
44*b6f0c436SThomas Cort.\" 3. All advertising materials mentioning features or use of this software
45*b6f0c436SThomas Cort.\"    must display the following acknowledgement:
46*b6f0c436SThomas Cort.\"	This product includes software developed by the University of
47*b6f0c436SThomas Cort.\"	California, Berkeley and its contributors.
48*b6f0c436SThomas Cort.\" 4. Neither the name of the University nor the names of its contributors
49*b6f0c436SThomas Cort.\"    may be used to endorse or promote products derived from this software
50*b6f0c436SThomas Cort.\"    without specific prior written permission.
51*b6f0c436SThomas Cort.\"
52*b6f0c436SThomas Cort.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53*b6f0c436SThomas Cort.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54*b6f0c436SThomas Cort.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55*b6f0c436SThomas Cort.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56*b6f0c436SThomas Cort.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57*b6f0c436SThomas Cort.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58*b6f0c436SThomas Cort.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59*b6f0c436SThomas Cort.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60*b6f0c436SThomas Cort.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61*b6f0c436SThomas Cort.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62*b6f0c436SThomas Cort.\" SUCH DAMAGE.
63*b6f0c436SThomas Cort.\"
64*b6f0c436SThomas Cort.\"     @(#)unifdef.1	8.2 (Berkeley) 4/1/94
65*b6f0c436SThomas Cort.\"	$dotat: things/unifdef.1,v 1.45 2003/01/20 14:37:08 fanf2 Exp $
66*b6f0c436SThomas Cort.\" $FreeBSD: src/usr.bin/unifdef/unifdef.1,v 1.19 2003/01/20 12:41:41 fanf Exp $
67*b6f0c436SThomas Cort.\"
68*b6f0c436SThomas Cort.Dd June 5, 2009
69*b6f0c436SThomas Cort.Dt UNIFDEF 1
70*b6f0c436SThomas Cort.Os
71*b6f0c436SThomas Cort.Sh NAME
72*b6f0c436SThomas Cort.Nm unifdef ,
73*b6f0c436SThomas Cort.Nm unifdefall
74*b6f0c436SThomas Cort.Nd remove preprocessor conditionals from code
75*b6f0c436SThomas Cort.Sh SYNOPSIS
76*b6f0c436SThomas Cort.Nm
77*b6f0c436SThomas Cort.Op Fl ceklst
78*b6f0c436SThomas Cort.Op Fl I Ns Ar path
79*b6f0c436SThomas Cort.Op Fl D Ns Ar sym Ns Op = Ns Ar val
80*b6f0c436SThomas Cort.Op Fl U Ns Ar sym
81*b6f0c436SThomas Cort.Op Fl iD Ns Ar sym Ns Op = Ns Ar val
82*b6f0c436SThomas Cort.Op Fl iU Ns Ar sym
83*b6f0c436SThomas Cort.Ar ...
84*b6f0c436SThomas Cort.Op Fl o Ar output
85*b6f0c436SThomas Cort.Op Ar file
86*b6f0c436SThomas Cort.Nm unifdefall
87*b6f0c436SThomas Cort.Op Fl I Ns Ar path
88*b6f0c436SThomas Cort.Ar ...
89*b6f0c436SThomas Cort.Ar file
90*b6f0c436SThomas Cort.Sh DESCRIPTION
91*b6f0c436SThomas CortThe
92*b6f0c436SThomas Cort.Nm
93*b6f0c436SThomas Cortutility selectively processes conditional
94*b6f0c436SThomas Cort.Xr cpp 1
95*b6f0c436SThomas Cortdirectives.
96*b6f0c436SThomas CortIt removes from a file both the directives and any additional text
97*b6f0c436SThomas Cortthat they specify should be removed, while otherwise leaving the
98*b6f0c436SThomas Cortfile alone.
99*b6f0c436SThomas Cort.Pp
100*b6f0c436SThomas CortThe
101*b6f0c436SThomas Cort.Nm
102*b6f0c436SThomas Cortutility acts on
103*b6f0c436SThomas Cort.Ic #if , #ifdef , #ifndef , #elif , #else ,
104*b6f0c436SThomas Cortand
105*b6f0c436SThomas Cort.Ic #endif
106*b6f0c436SThomas Cortlines,
107*b6f0c436SThomas Cortand it understands only the commonly-used subset
108*b6f0c436SThomas Cortof the expression syntax for
109*b6f0c436SThomas Cort.Ic #if
110*b6f0c436SThomas Cortand
111*b6f0c436SThomas Cort.Ic #elif
112*b6f0c436SThomas Cortlines.
113*b6f0c436SThomas CortIt handles
114*b6f0c436SThomas Cortinteger values of symbols defined on the command line,
115*b6f0c436SThomas Cortthe
116*b6f0c436SThomas Cort.Fn defined
117*b6f0c436SThomas Cortoperator applied to symbols defined or undefined on the command line,
118*b6f0c436SThomas Cortthe operators
119*b6f0c436SThomas Cort.Ic \&! , \*[Lt] , \*[Gt] , \*[Lt]= , \*[Gt]= , == , != , \*[Am]\*[Am] , || ,
120*b6f0c436SThomas Cortand parenthesized expressions.
121*b6f0c436SThomas CortAnything that it does not understand is passed through unharmed.
122*b6f0c436SThomas CortIt only processes
123*b6f0c436SThomas Cort.Ic #ifdef
124*b6f0c436SThomas Cortand
125*b6f0c436SThomas Cort.Ic #ifndef
126*b6f0c436SThomas Cortdirectives if the symbol is specified on the command line,
127*b6f0c436SThomas Cortotherwise they are also passed through unchanged.
128*b6f0c436SThomas CortBy default, it ignores
129*b6f0c436SThomas Cort.Ic #if
130*b6f0c436SThomas Cortand
131*b6f0c436SThomas Cort.Ic #elif
132*b6f0c436SThomas Cortlines with constant expressions,
133*b6f0c436SThomas Cortor they may be processed by specifying the
134*b6f0c436SThomas Cort.Fl k
135*b6f0c436SThomas Cortflag on the command line.
136*b6f0c436SThomas Cort.Pp
137*b6f0c436SThomas CortThe
138*b6f0c436SThomas Cort.Nm
139*b6f0c436SThomas Cortutility also understands just enough about C
140*b6f0c436SThomas Cortto know when one of the directives is inactive
141*b6f0c436SThomas Cortbecause it is inside
142*b6f0c436SThomas Corta comment,
143*b6f0c436SThomas Cortor affected by a backslash-continued line.
144*b6f0c436SThomas CortIt spots unusually-formatted preprocessor directives
145*b6f0c436SThomas Cortand knows when the layout is too odd to handle.
146*b6f0c436SThomas Cort.Pp
147*b6f0c436SThomas CortA script called
148*b6f0c436SThomas Cort.Nm unifdefall
149*b6f0c436SThomas Cortcan be used to remove all conditional
150*b6f0c436SThomas Cort.Xr cpp 1
151*b6f0c436SThomas Cortdirectives from a file.
152*b6f0c436SThomas CortIt uses
153*b6f0c436SThomas Cort.Nm Fl s
154*b6f0c436SThomas Cortand
155*b6f0c436SThomas Cort.Nm cpp Fl dM
156*b6f0c436SThomas Cortto get lists of all the controlling symbols
157*b6f0c436SThomas Cortand their definitions (or lack thereof),
158*b6f0c436SThomas Cortthen invokes
159*b6f0c436SThomas Cort.Nm
160*b6f0c436SThomas Cortwith appropriate arguments to process the file.
161*b6f0c436SThomas Cort.Pp
162*b6f0c436SThomas CortAvailable options:
163*b6f0c436SThomas Cort.Bl -tag -width indent -compact
164*b6f0c436SThomas Cort.It Fl D Ns Ar sym Ns Op = Ns Ar val
165*b6f0c436SThomas CortSpecify that a symbol is defined,
166*b6f0c436SThomas Cortand optionally specify what value to give it
167*b6f0c436SThomas Cortfor the purpose of handling
168*b6f0c436SThomas Cort.Ic #if
169*b6f0c436SThomas Cortand
170*b6f0c436SThomas Cort.Ic #elif
171*b6f0c436SThomas Cortdirectives.
172*b6f0c436SThomas Cort.It Fl U Ns Ar sym
173*b6f0c436SThomas CortSpecify that a symbol is undefined.
174*b6f0c436SThomas CortIf the same symbol appears in more than one argument,
175*b6f0c436SThomas Cortthe last occurrence dominates.
176*b6f0c436SThomas Cort.It Fl c
177*b6f0c436SThomas CortIf the
178*b6f0c436SThomas Cort.Fl c
179*b6f0c436SThomas Cortflag is specified,
180*b6f0c436SThomas Cortthen the operation of
181*b6f0c436SThomas Cort.Nm
182*b6f0c436SThomas Cortis complemented,
183*b6f0c436SThomas Corti.e., the lines that would have been removed or blanked
184*b6f0c436SThomas Cortare retained and vice versa.
185*b6f0c436SThomas Cort.It Fl e
186*b6f0c436SThomas CortBecause
187*b6f0c436SThomas Cort.Nm
188*b6f0c436SThomas Cortprocesses its input one line at a time,
189*b6f0c436SThomas Cortit cannot remove preprocessor directives that span more than one line.
190*b6f0c436SThomas CortThe most common example of this is a directive with a multi-line
191*b6f0c436SThomas Cortcomment hanging off its right hand end.
192*b6f0c436SThomas CortBy default,
193*b6f0c436SThomas Cortif
194*b6f0c436SThomas Cort.Nm
195*b6f0c436SThomas Corthas to process such a directive,
196*b6f0c436SThomas Cortit will complain that the line is too obfuscated.
197*b6f0c436SThomas CortThe
198*b6f0c436SThomas Cort.Fl e
199*b6f0c436SThomas Cortoption changes the behaviour so that,
200*b6f0c436SThomas Cortwhere possible,
201*b6f0c436SThomas Cortsuch lines are left unprocessed instead of reporting an error.
202*b6f0c436SThomas Cort.It Fl k
203*b6f0c436SThomas CortProcess
204*b6f0c436SThomas Cort.Ic #if
205*b6f0c436SThomas Cortand
206*b6f0c436SThomas Cort.Ic #elif
207*b6f0c436SThomas Cortlines with constant expressions.
208*b6f0c436SThomas CortBy default, sections controlled by such lines are passed through unchanged
209*b6f0c436SThomas Cortbecause they typically start
210*b6f0c436SThomas Cort.Dq Li "#if 0"
211*b6f0c436SThomas Cortand are used as a kind of comment to sketch out future or past development.
212*b6f0c436SThomas CortIt would be rude to strip them out, just as it would be for normal comments.
213*b6f0c436SThomas Cort.It Fl l
214*b6f0c436SThomas CortReplace removed lines with blank lines
215*b6f0c436SThomas Cortinstead of deleting them.
216*b6f0c436SThomas Cort.It Fl o Ar output
217*b6f0c436SThomas CortThe argument given is the name of an
218*b6f0c436SThomas Cort.Ar output
219*b6f0c436SThomas Cortfile to be used instead of the standard output.
220*b6f0c436SThomas CortThis file can be the same as the input file.
221*b6f0c436SThomas Cort.It Fl s
222*b6f0c436SThomas CortInstead of processing the input file as usual,
223*b6f0c436SThomas Cortthis option causes
224*b6f0c436SThomas Cort.Nm
225*b6f0c436SThomas Cortto produce a list of symbols that appear in expressions
226*b6f0c436SThomas Cortthat
227*b6f0c436SThomas Cort.Nm
228*b6f0c436SThomas Cortunderstands.
229*b6f0c436SThomas CortIt is useful in conjunction with the
230*b6f0c436SThomas Cort.Fl dM
231*b6f0c436SThomas Cortoption of
232*b6f0c436SThomas Cort.Xr cpp 1
233*b6f0c436SThomas Cortfor creating
234*b6f0c436SThomas Cort.Nm
235*b6f0c436SThomas Cortcommand lines.
236*b6f0c436SThomas Cort.It Fl t
237*b6f0c436SThomas CortDisables parsing for C comments
238*b6f0c436SThomas Cortand line continuations,
239*b6f0c436SThomas Cortwhich is useful
240*b6f0c436SThomas Cortfor plain text.
241*b6f0c436SThomas Cort.It Fl iD Ns Ar sym Ns Op = Ns Ar val
242*b6f0c436SThomas Cort.It Fl iU Ns Ar sym
243*b6f0c436SThomas CortIgnore
244*b6f0c436SThomas Cort.Ic #ifdef Ns s .
245*b6f0c436SThomas CortIf your C code uses
246*b6f0c436SThomas Cort.Ic #ifdef Ns s
247*b6f0c436SThomas Cortto delimit non-C lines,
248*b6f0c436SThomas Cortsuch as comments
249*b6f0c436SThomas Cortor code which is under construction,
250*b6f0c436SThomas Cortthen you must tell
251*b6f0c436SThomas Cort.Nm
252*b6f0c436SThomas Cortwhich symbols are used for that purpose so that it will not try to parse
253*b6f0c436SThomas Cortcomments
254*b6f0c436SThomas Cortand line continuations
255*b6f0c436SThomas Cortinside those
256*b6f0c436SThomas Cort.Ic #ifdef Ns s .
257*b6f0c436SThomas CortOne specifies ignored symbols with
258*b6f0c436SThomas Cort.Fl iD Ns Ar sym Ns Oo = Ns Ar val Oc
259*b6f0c436SThomas Cortand
260*b6f0c436SThomas Cort.Fl iU Ns Ar sym
261*b6f0c436SThomas Cortsimilar to
262*b6f0c436SThomas Cort.Fl D Ns Ar sym Ns Op = Ns Ar val
263*b6f0c436SThomas Cortand
264*b6f0c436SThomas Cort.Fl U Ns Ar sym
265*b6f0c436SThomas Cortabove.
266*b6f0c436SThomas Cort.It Fl I Ns Ar path
267*b6f0c436SThomas CortSpecifies to
268*b6f0c436SThomas Cort.Nm unifdefall
269*b6f0c436SThomas Cortan additional place to look for
270*b6f0c436SThomas Cort.Ic #include
271*b6f0c436SThomas Cortfiles.
272*b6f0c436SThomas CortThis option is ignored by
273*b6f0c436SThomas Cort.Nm
274*b6f0c436SThomas Cortfor compatibility with
275*b6f0c436SThomas Cort.Xr cpp 1
276*b6f0c436SThomas Cortand to simplify the implementation of
277*b6f0c436SThomas Cort.Nm unifdefall .
278*b6f0c436SThomas Cort.El
279*b6f0c436SThomas Cort.Pp
280*b6f0c436SThomas CortThe
281*b6f0c436SThomas Cort.Nm
282*b6f0c436SThomas Cortutility copies its output to
283*b6f0c436SThomas Cort.Em stdout
284*b6f0c436SThomas Cortand will take its input from
285*b6f0c436SThomas Cort.Em stdin
286*b6f0c436SThomas Cortif no
287*b6f0c436SThomas Cort.Ar file
288*b6f0c436SThomas Cortargument is given.
289*b6f0c436SThomas Cort.Pp
290*b6f0c436SThomas CortThe
291*b6f0c436SThomas Cort.Nm
292*b6f0c436SThomas Cortutility works nicely with the
293*b6f0c436SThomas Cort.Fl D Ns Ar sym
294*b6f0c436SThomas Cortoption of
295*b6f0c436SThomas Cort.Xr diff 1 .
296*b6f0c436SThomas Cort.Sh DIAGNOSTICS
297*b6f0c436SThomas Cort.Bl -item
298*b6f0c436SThomas Cort.It
299*b6f0c436SThomas CortToo many levels of nesting.
300*b6f0c436SThomas Cort.It
301*b6f0c436SThomas CortInappropriate
302*b6f0c436SThomas Cort.Ic #elif ,
303*b6f0c436SThomas Cort.Ic #else
304*b6f0c436SThomas Cortor
305*b6f0c436SThomas Cort.Ic #endif .
306*b6f0c436SThomas Cort.It
307*b6f0c436SThomas CortObfuscated preprocessor control line.
308*b6f0c436SThomas Cort.It
309*b6f0c436SThomas CortPremature
310*b6f0c436SThomas Cort.Dv EOF
311*b6f0c436SThomas Cort(with the line number of the most recent unterminated
312*b6f0c436SThomas Cort.Ic #if ) .
313*b6f0c436SThomas Cort.It
314*b6f0c436SThomas Cort.Dv EOF
315*b6f0c436SThomas Cortin comment.
316*b6f0c436SThomas Cort.El
317*b6f0c436SThomas Cort.Pp
318*b6f0c436SThomas CortThe
319*b6f0c436SThomas Cort.Nm
320*b6f0c436SThomas Cortutility exits 0 if the output is an exact copy of the input,
321*b6f0c436SThomas Cort1 if not, and 2 if in trouble.
322*b6f0c436SThomas Cort.Sh SEE ALSO
323*b6f0c436SThomas Cort.Xr cpp 1 ,
324*b6f0c436SThomas Cort.Xr diff 1
325*b6f0c436SThomas Cort.Sh HISTORY
326*b6f0c436SThomas CortThe
327*b6f0c436SThomas Cort.Nm
328*b6f0c436SThomas Cortcommand appeared in
329*b6f0c436SThomas Cort.Bx 4.3 .
330*b6f0c436SThomas Cort.Tn ANSI\~C
331*b6f0c436SThomas Cortsupport was added in
332*b6f0c436SThomas Cort.Fx 4.7 .
333*b6f0c436SThomas Cort.Sh BUGS
334*b6f0c436SThomas CortExpression evaluation is very limited.
335*b6f0c436SThomas Cort.Pp
336*b6f0c436SThomas CortPreprocessor control lines split across more than one physical line
337*b6f0c436SThomas Cort(because of comments or backslash-newline)
338*b6f0c436SThomas Cortcannot be handled in every situation.
339*b6f0c436SThomas Cort.Pp
340*b6f0c436SThomas CortTrigraphs are not recognized.
341*b6f0c436SThomas Cort.Pp
342*b6f0c436SThomas CortThere is no support for symbols with different definitions at
343*b6f0c436SThomas Cortdifferent points in the source file.
344*b6f0c436SThomas Cort.Pp
345*b6f0c436SThomas CortThe text-mode and ignore functionality does not correspond to modern
346*b6f0c436SThomas Cort.Xr cpp 1
347*b6f0c436SThomas Cortbehaviour.
348