386BSD 0.0 development
[unix-history] / usr / src / usr.bin / unifdef / unifdef.1
CommitLineData
c3facf4a
WJ
1.\" Copyright (c) 1985, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Dave Yost.
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. All advertising materials mentioning features or use of this software
16.\" must display the following acknowledgement:
17.\" This product includes software developed by the University of
18.\" California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\" may be used to endorse or promote products derived from this software
21.\" without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\" @(#)unifdef.1 6.5 (Berkeley) 4/23/91
36.\"
37.Dd April 23, 1991
38.Dt UNIFDEF 1
39.Os BSD 4.3
40.Sh NAME
41.Nm unifdef
42.Nd remove ifdef'ed lines
43.Sh SYNOPSIS
44.Nm unifdef
45.Oo
46.Fl t l c
47.Fl D Ns Ar sym
48.Fl U Ns Ar sym
49.Fl iD Ns Ar sym
50.Fl iD Ns Ar sym
51.Oc
52.Ar ...
53.Op Ar file
54.Sh DESCRIPTION
55.Nm Unifdef
56is useful for removing ifdef'ed lines
57from a file while otherwise leaving the file alone.
58.Nm Unifdef
59acts on
60#ifdef, #ifndef, #else, and #endif lines,
61and it knows only enough about C
62to know when one of these is inactive
63because it is inside
64a comment,
65or a single or double quote.
66Parsing for quotes is very simplistic:
67when it finds an open quote,
68it ignores everything (except escaped quotes)
69until it finds a close quote, and
70it will not complain if it gets
71to the end of a line and finds no backslash for continuation.
72.Pp
73Available options:
74.Bl -tag -width Ds -compact
75.It Fl D Ns Ar sym
76.It Fl U Ns Ar sym
77Specify which symbols to define or undefine.
78and the lines inside those ifdefs will be copied to the output or removed as
79appropriate.
80The ifdef, ifndef, else, and endif lines associated with
81.Ar sym
82will also be removed.
83Ifdefs involving symbols you don't specify
84and ``#if'' control lines
85are untouched and copied out
86along with their associated
87ifdef, else, and endif lines.
88If an ifdef X occurs nested inside another ifdef X, then the
89inside ifdef is treated as if it were an unrecognized symbol.
90If the same symbol appears in more than one argument,
91the last occurrence dominates.
92.Pp
93.It Fl c
94If the
95.Fl c
96flag is specified,
97then the operation of
98.Nm unifdef
99is complemented,
100i.e. the lines that would have been removed or blanked
101are retained and vice versa.
102.Pp
103.It Fl l
104Replace removed lines with blank lines
105instead of deleting them.
106.It Fl t
107Disables parsing for
108C comments and quotes useful for plain text
109(not C code).
110.Pp
111.It Fl iD Ns Ar sym
112.It Fl iU Ns Ar sym
113Ignore ifdefs.
114If your C code uses ifdefs to delimit non-C lines,
115such as comments
116or code which is under construction,
117then you must tell
118.Nm unifdef
119which symbols are used for that purpose so that it won't try to parse
120for quotes and comments
121inside those ifdefs.
122One specifies ignored ifdefs with
123.Fl iD Ns Ar sym
124and
125.Fl iU Ns Ar sym
126similar to
127.Fl D Ns Ar sym
128and
129.Fl U Ns Ar sym
130above.
131.El
132.Pp
133.Nm Unifdef
134copies its output to
135.Em stdout
136and will take its input from
137.Em stdin
138if no
139.Ar file
140argument is given.
141.Pp
142.Nm Unifdef
143works nicely with the
144.Fl D Ns Ar sym
145option added to
146.Xr diff 1
147as of the 4.1 Berkeley Software Distribution.
148.Sh SEE ALSO
149.Xr diff 1
150.Sh DIAGNOSTICS
151Inappropriate else or endif.
152.br
153Premature
154.Tn EOF
155with line numbers of the unterminated #ifdefs.
156.Pp
157Exit status is 0 if output is exact copy of input, 1 if not, 2 if trouble.
158.Sh BUGS
159Should try to deal with ``#if'' lines.
160.Pp
161Doesn't work correctly if input contains null characters.
162.Sh HISTORY
163The
164.Nm
165command appeared in
166.Bx 4.3 .