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