~ubuntu-branches/ubuntu/feisty/unifdef/feisty

« back to all changes in this revision

Viewing changes to src/unifdef.1

  • Committer: Bazaar Package Importer
  • Author(s): Bob Proulx
  • Date: 2004-07-03 18:09:39 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040703180939-f7bj8405sqvixczk
Tags: upstream-1.0+20030701
ImportĀ upstreamĀ versionĀ 1.0+20030701

Show diffs side-by-side

added added

removed removed

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