new copyright; att/bsd/shared
[unix-history] / usr / src / usr.bin / unifdef / unifdef.1
CommitLineData
dc533d04
KB
1.\" Copyright (c) 1985 The Regents of the University of California.
2.\" All rights reserved.
6be9699a 3.\"
dc533d04
KB
4.\" This code is derived from software contributed to Berkeley by
5.\" Dave Yost.
6.\"
0fc6e47b 7.\" %sccs.include.redist.man%
dc533d04 8.\"
0fc6e47b 9.\" @(#)unifdef.1 6.4 (Berkeley) %G%
6be9699a
KM
10.\"
11.TH UNIFDEF 1 ""
6be9699a
KM
12.SH NAME
13unifdef \- remove ifdef'ed lines
14.SH SYNOPSIS
f42d2b57 15\fBunifdef\fR
6be9699a 16[
f42d2b57
KB
17\fB\-t\fR
18\fB\-l\fR
19\fB\-c\fR
20\fB\-D\fR\fIsym\fR
21\fB\-U\fR\fIsym\fR
22\fB\-iD\fR\fIsym\fR
23\fB\-iD\fR\fIsym\fR
6be9699a
KM
24] ... [ file ]
25.SH DESCRIPTION
f42d2b57
KB
26\fIUnifdef\fR is useful for removing ifdef'ed lines
27from a file while otherwise leaving the file alone.
28\fIUnifdef\fR acts on
29#ifdef, #ifndef, #else, and #endif lines,
30and it knows only enough about C
31to know when one of these is inactive
32because it is inside
33a comment,
34or a single or double quote.
35Parsing for quotes is very simplistic:
36when it finds an open quote,
37it ignores everything (except escaped quotes)
38until it finds a close quote, and
39it will not complain if it gets
40to the end of a line and finds no backslash for continuation.
41.PP
42If you want to use \fIunifdef\fR
43for plain text (not C code),
44use the \fB\-t\fR option,
45which disables this parsing for
46C comments and quotes.
47.PP
6be9699a 48You specify which symbols you want defined
f42d2b57 49(\fB\-D\fR\fIsym\fR)
6be9699a 50or undefined
f42d2b57 51(\fB\-U\fR\fIsym\fR)
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
f42d2b57
KB
55\fIsym\fR will also be removed.
56Ifdefs involving symbols you don't specify
57and ``#if'' control lines
58are untouched and copied out
6be9699a
KM
59along with their associated
60ifdef, else, and endif lines.
61If an ifdef X occurs nested inside another ifdef X, then the
62inside ifdef is treated as if it were an unrecognized symbol.
f42d2b57
KB
63If the same symbol appears in more than one argument,
64the last occurrence dominates.
6be9699a 65.PP
f42d2b57 66The \fB\-l\fR option causes \fIunifdef\fR
6be9699a
KM
67to replace removed lines with blank lines
68instead of deleting them.
69.PP
f42d2b57
KB
70If your C code uses ifdefs to delimit non-C lines,
71such as comments
6be9699a 72or code which is under construction,
f42d2b57 73then you must tell \fIunifdef\fR
6be9699a
KM
74which symbols are used for that purpose so that it won't try to parse
75for quotes and comments
f42d2b57
KB
76inside those ifdefs.
77You specify ignored ifdefs with
78\fB\-iD\fR\fIsym\fR
6be9699a 79and
f42d2b57 80\fB\-iU\fR\fIsym\fR
6be9699a 81similar to
f42d2b57 82\fB\-D\fR\fIsym\fR
6be9699a 83and
f42d2b57 84\fB\-U\fR\fIsym\fR
6be9699a
KM
85above.
86.PP
f42d2b57
KB
87\fIUnifdef\fR copies its output to \fIstdout\fR
88and will take its input from \fIstdin\fR
89if no \fIfile\fR argument is given.
90If the \fB\-c\fR argument is specified,
91then the operation of \fIunifdef\fR is complemented,
6be9699a
KM
92i.e. the lines that would have been removed or blanked
93are retained and vice versa.
f42d2b57
KB
94.PP
95\fIUnifdef\fR works nicely with the \fB\-D\fR\fIsym\fR option added
96to \fIdiff\fR(1) as of the 4.1 Berkeley Software Distribution.
6be9699a
KM
97.SH "SEE ALSO"
98diff(1)
99.SH DIAGNOSTICS
f42d2b57
KB
100Inappropriate else or endif.
101.br
102Premature EOF with line numbers of the unterminated #ifdefs.
6be9699a
KM
103.PP
104Exit status is 0 if output is exact copy of input, 1 if not, 2 if trouble.
f42d2b57
KB
105.SH AUTHOR
106Dave Yost for The Rand Corporation.
107.br
108Still maintained independently by Dave Yost as of 3/85
6be9699a 109.SH BUGS
f42d2b57 110Should try to deal with ``#if'' lines.
6be9699a 111.br
f42d2b57 112Doesn't work correctly if input contains null characters.