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