move pcc into /usr/old
[unix-history] / usr / src / usr.bin / unifdef / unifdef.1
CommitLineData
9cd74d67 1.\" Copyright (c) 1985, 1991 The Regents of the University of California.
dc533d04 2.\" All rights reserved.
6be9699a 3.\"
dc533d04
KB
4.\" This code is derived from software contributed to Berkeley by
5.\" Dave Yost.
6.\"
9cd74d67 7.\" %sccs.include.redist.roff%
dc533d04 8.\"
9cd74d67 9.\" @(#)unifdef.1 6.5 (Berkeley) %G%
6be9699a 10.\"
9cd74d67
CL
11.Dd
12.Dt UNIFDEF 1
13.Os BSD 4.3
14.Sh NAME
15.Nm unifdef
16.Nd remove ifdef'ed lines
17.Sh SYNOPSIS
18.Nm unifdef
19.Oo
20.Fl t l c
21.Fl D Ns Ar sym
22.Fl U Ns Ar sym
23.Fl iD Ns Ar sym
24.Fl iD Ns Ar sym
25.Oc
26.Ar ...
27.Op Ar file
28.Sh DESCRIPTION
29.Nm Unifdef
30is useful for removing ifdef'ed lines
f42d2b57 31from a file while otherwise leaving the file alone.
9cd74d67
CL
32.Nm Unifdef
33acts on
f42d2b57
KB
34#ifdef, #ifndef, #else, and #endif lines,
35and it knows only enough about C
36to know when one of these is inactive
37because it is inside
38a comment,
39or a single or double quote.
40Parsing for quotes is very simplistic:
41when it finds an open quote,
42it ignores everything (except escaped quotes)
43until it finds a close quote, and
44it will not complain if it gets
45to the end of a line and finds no backslash for continuation.
9cd74d67
CL
46.Pp
47Available options:
48.Bl -tag -width Ds -compact
49.It Fl D Ns Ar sym
50.It Fl U Ns Ar sym
51Specify which symbols to define or undefine.
6be9699a
KM
52and the lines inside those ifdefs will be copied to the output or removed as
53appropriate.
54The ifdef, ifndef, else, and endif lines associated with
9cd74d67
CL
55.Ar sym
56will also be removed.
f42d2b57
KB
57Ifdefs involving symbols you don't specify
58and ``#if'' control lines
59are untouched and copied out
6be9699a
KM
60along with their associated
61ifdef, else, and endif lines.
62If an ifdef X occurs nested inside another ifdef X, then the
63inside ifdef is treated as if it were an unrecognized symbol.
f42d2b57
KB
64If the same symbol appears in more than one argument,
65the last occurrence dominates.
9cd74d67
CL
66.Pp
67.It Fl c
68If the
69.Fl c
70flag is specified,
71then the operation of
72.Nm unifdef
73is complemented,
74i.e. the lines that would have been removed or blanked
75are retained and vice versa.
76.Pp
77.It Fl l
78Replace removed lines with blank lines
6be9699a 79instead of deleting them.
9cd74d67
CL
80.It Fl t
81Disables parsing for
82C comments and quotes useful for plain text
83(not C code).
84.Pp
85.It Fl iD Ns Ar sym
86.It Fl iU Ns Ar sym
87Ignore ifdefs.
f42d2b57
KB
88If your C code uses ifdefs to delimit non-C lines,
89such as comments
6be9699a 90or code which is under construction,
9cd74d67
CL
91then you must tell
92.Nm unifdef
6be9699a
KM
93which symbols are used for that purpose so that it won't try to parse
94for quotes and comments
f42d2b57 95inside those ifdefs.
9cd74d67
CL
96One specifies ignored ifdefs with
97.Fl iD Ns Ar sym
6be9699a 98and
9cd74d67 99.Fl iU Ns Ar sym
6be9699a 100similar to
9cd74d67 101.Fl D Ns Ar sym
6be9699a 102and
9cd74d67 103.Fl U Ns Ar sym
6be9699a 104above.
9cd74d67
CL
105.El
106.Pp
107.Nm Unifdef
108copies its output to
109.Em stdout
110and will take its input from
111.Em stdin
112if no
113.Ar file
114argument is given.
115.Pp
116.Nm Unifdef
117works nicely with the
118.Fl D Ns Ar sym
119option added to
120.Xr diff 1
121as of the 4.1 Berkeley Software Distribution.
122.Sh SEE ALSO
123.Xr diff 1
124.Sh DIAGNOSTICS
f42d2b57
KB
125Inappropriate else or endif.
126.br
9cd74d67
CL
127Premature
128.Tn EOF
129with line numbers of the unterminated #ifdefs.
130.Pp
6be9699a 131Exit status is 0 if output is exact copy of input, 1 if not, 2 if trouble.
9cd74d67 132.Sh BUGS
f42d2b57 133Should try to deal with ``#if'' lines.
9cd74d67 134.Pp
f42d2b57 135Doesn't work correctly if input contains null characters.
9cd74d67
CL
136.Sh HISTORY
137The
138.Nm
139command appeared in
140.Bx 4.3 .