Annotation of src/usr.bin/unifdef/unifdef.1, Revision 1.14
1.14 ! jmc 1: .\" $OpenBSD: unifdef.1,v 1.13 2003/06/10 09:12:12 jmc Exp $
1.1 deraadt 2: .\" Copyright (c) 1985, 1991, 1993
3: .\" The Regents of the University of California. All rights reserved.
4: .\"
5: .\" This code is derived from software contributed to Berkeley by
1.9 deraadt 6: .\" Dave Yost. Support for #if and #elif was added by Tony Finch.
1.1 deraadt 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.
1.12 millert 16: .\" 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 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
1.9 deraadt 33: .\" $dotat: things/unifdef.1,v 1.26 2002/09/24 19:44:12 fanf2 Exp $
34: .\" $FreeBSD: src/usr.bin/unifdef/unifdef.1,v 1.15 2002/09/24 19:48:39 fanf Exp $
1.1 deraadt 35: .\"
1.9 deraadt 36: .Dd September 24, 2002
1.1 deraadt 37: .Dt UNIFDEF 1
1.4 aaron 38: .Os
1.1 deraadt 39: .Sh NAME
1.10 deraadt 40: .Nm unifdef
1.9 deraadt 41: .Nd remove preprocessor conditionals from code
1.1 deraadt 42: .Sh SYNOPSIS
1.9 deraadt 43: .Nm
1.11 deraadt 44: .Op Fl ceklst
1.1 deraadt 45: .Oo
1.9 deraadt 46: .Fl I Ns Ar path
1.1 deraadt 47: .Fl D Ns Ar sym
1.9 deraadt 48: .Ns Op = Ns Ar val
1.1 deraadt 49: .Fl U Ns Ar sym
50: .Fl iD Ns Ar sym
1.9 deraadt 51: .Ns Op = Ns Ar val
52: .Fl iU Ns Ar sym
1.1 deraadt 53: .Oc
54: .Ar ...
55: .Op Ar file
56: .Sh DESCRIPTION
1.9 deraadt 57: The
1.8 aaron 58: .Nm
1.9 deraadt 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
1.8 aaron 68: .Nm
1.9 deraadt 69: utility acts on
1.14 ! jmc 70: .Ic #if , #ifdef , #ifndef ,
! 71: .Ic #elif , #else ,
1.9 deraadt 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
1.14 ! jmc 87: .Ic \&! , < , > , <= ,
! 88: .Ic >= , == , != , && ,
! 89: .Ic || ,
1.9 deraadt 90: and parenthesized expressions.
91: Anything that it does not understand is passed through unharmed.
92: It only processes
93: .Ic #ifdef
94: and
95: .Ic #ifndef
96: directives if the symbol is specified on the command line,
97: otherwise they are also passed through unchanged.
98: By default, it ignores
99: .Ic #if
100: and
101: .Ic #elif
102: lines with constant expressions,
103: or they may be processed by specifying the
104: .Fl k
105: flag on the command line.
106: .Pp
107: The
108: .Nm
109: utility also understands just enough about C
110: to know when one of the directives is inactive
1.1 deraadt 111: because it is inside
112: a comment,
1.11 deraadt 113: or affected by a backslash-continued line.
114: It spots unusually-formatted preprocessor directives
115: and knows when the layout is too odd to handle.
1.1 deraadt 116: .Pp
1.9 deraadt 117: Available options:
118: .Bl -tag -width indent -compact
119: .It Fl D Ns Ar sym
120: .Ns Op = Ns Ar val
121: Specify that a symbol is defined,
122: and optionally specify what value to give it
123: for the purpose of handling
124: .Ic #if
125: and
126: .Ic #elif
127: directives.
128: .Pp
129: .It Fl U Ns Ar sym
130: Specify that a symbol is undefined.
1.1 deraadt 131: If the same symbol appears in more than one argument,
132: the last occurrence dominates.
1.9 deraadt 133: .Pp
1.1 deraadt 134: .It Fl c
135: If the
136: .Fl c
137: flag is specified,
138: then the operation of
1.8 aaron 139: .Nm
1.1 deraadt 140: is complemented,
1.8 aaron 141: i.e., the lines that would have been removed or blanked
1.1 deraadt 142: are retained and vice versa.
1.9 deraadt 143: .Pp
1.11 deraadt 144: .It Fl e
145: Because
146: .Nm
147: processes its input one line at a time,
148: it cannot remove preprocessor directives that span more than one line.
149: The most common example of this is a directive with a multi-line
150: comment hanging off its right hand end.
151: By default,
152: if
153: .Nm
154: has to process such a directive,
155: it will complain that the line is too obfuscated.
156: The
157: .Fl e
158: option changes the behavior so that,
159: where possible,
160: such lines are left unprocessed instead of reporting an error.
161: .Pp
1.9 deraadt 162: .It Fl k
163: Process
164: .Ic #if
165: and
166: .Ic #elif
167: lines with constant expressions.
168: By default, sections controlled by such lines are passed through unchanged
169: because they typically start
170: .Li #if 0
171: and are used as a kind of comment to sketch out future or past development.
172: It would be rude to strip them out, just as it would be for normal comments.
173: .Pp
1.1 deraadt 174: .It Fl l
175: Replace removed lines with blank lines
176: instead of deleting them.
1.9 deraadt 177: .Pp
178: .It Fl s
179: Instead of processing the input file as usual,
180: this option causes
181: .Nm
182: to produce a list of symbols that appear in expressions
183: that
184: .Nm
185: understands.
186: It is useful in conjunction with the
187: .Fl dM
188: option of
189: .Xr cpp 1
190: for creating
191: .Nm
192: command lines.
193: .Pp
1.1 deraadt 194: .It Fl t
1.11 deraadt 195: Disables parsing for C comments
196: and line continuations,
197: which is useful
1.1 deraadt 198: for plain text.
1.9 deraadt 199: .Pp
200: .It Fl iD Ns Ar sym
201: .Ns Op = Ns Ar val
202: .It Fl iU Ns Ar sym
203: Ignore
204: .Ic #ifdef Ns s .
205: If your C code uses
206: .Ic #ifdef Ns s
207: to delimit non-C lines,
1.1 deraadt 208: such as comments
209: or code which is under construction,
210: then you must tell
1.8 aaron 211: .Nm
1.9 deraadt 212: which symbols are used for that purpose so that it will not try to parse
1.11 deraadt 213: comments and line continuations
1.9 deraadt 214: inside those
215: .Ic #ifdef Ns s .
216: One specifies ignored symbols with
1.1 deraadt 217: .Fl iD Ns Ar sym
1.9 deraadt 218: .Ns Oo = Ns Ar val Oc
1.1 deraadt 219: and
220: .Fl iU Ns Ar sym
221: similar to
222: .Fl D Ns Ar sym
1.9 deraadt 223: .Ns Op = Ns Ar val
1.1 deraadt 224: and
225: .Fl U Ns Ar sym
226: above.
227: .El
228: .Pp
1.9 deraadt 229: The
1.8 aaron 230: .Nm
1.9 deraadt 231: utility copies its output to
1.1 deraadt 232: .Em stdout
233: and will take its input from
234: .Em stdin
235: if no
236: .Ar file
237: argument is given.
238: .Pp
1.9 deraadt 239: The
1.8 aaron 240: .Nm
1.9 deraadt 241: utility works nicely with the
1.1 deraadt 242: .Fl D Ns Ar sym
1.9 deraadt 243: option of
244: .Xr diff 1 .
1.1 deraadt 245: .Sh DIAGNOSTICS
1.9 deraadt 246: .Bl -item
247: .It
1.11 deraadt 248: Too many levels of nesting.
249: .It
250: Inappropriate
251: .Ic #elif ,
252: .Ic #else
253: or
254: .Ic #endif .
255: .It
256: Obfuscated preprocessor control line.
1.9 deraadt 257: .It
1.1 deraadt 258: Premature
259: .Tn EOF
1.11 deraadt 260: (with the line number of the most recent unterminated
261: .Ic #if ) .
262: .It
263: .Tn EOF
264: in comment.
1.9 deraadt 265: .El
266: .Pp
267: The
268: .Nm
269: utility exits 0 if the output is an exact copy of the input,
270: 1 if not, and 2 if in trouble.
1.13 jmc 271: .Sh SEE ALSO
272: .Xr cpp 1 ,
273: .Xr diff 1
274: .Sh HISTORY
275: The
276: .Nm
277: command appeared in
278: .Bx 4.3 .
1.9 deraadt 279: .Sh BUGS
280: Expression evaluation is very limited.
1.1 deraadt 281: .Pp
1.11 deraadt 282: Preprocessor control lines split across more than one physical line
283: (because of comments or backslash-newline)
284: cannot be handled in every situation.
285: .Pp
286: Trigraphs are not recognized.
287: .Pp
288: There is no support for symbols with different definitions at
289: different points in the source file.
290: .Pp
291: The text-mode and ignore functionality doesn't correspond to modern
292: .Xr cpp 1
293: behaviour.