1994-05-27 12:33:43 +00:00
|
|
|
.\" 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
|
2002-05-15 16:30:28 +00:00
|
|
|
.\" Dave Yost. Support for #if and #elif was added by Tony Finch.
|
1994-05-27 12:33:43 +00:00
|
|
|
.\"
|
|
|
|
.\" 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
|
2002-09-24 19:27:44 +00:00
|
|
|
.\" $dotat: things/unifdef.1,v 1.25 2002/09/24 19:16:29 fanf2 Exp $
|
1999-08-28 01:08:13 +00:00
|
|
|
.\" $FreeBSD$
|
1994-05-27 12:33:43 +00:00
|
|
|
.\"
|
2002-09-24 19:27:44 +00:00
|
|
|
.Dd September 24, 2002
|
1994-05-27 12:33:43 +00:00
|
|
|
.Dt UNIFDEF 1
|
2001-07-10 14:16:33 +00:00
|
|
|
.Os
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh NAME
|
2002-05-30 11:29:25 +00:00
|
|
|
.Nm unifdef , unifdefall
|
2002-05-15 16:30:28 +00:00
|
|
|
.Nd remove preprocessor conditionals from code
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh SYNOPSIS
|
2000-11-20 19:21:22 +00:00
|
|
|
.Nm
|
2002-09-24 19:27:44 +00:00
|
|
|
.Op Fl cklst
|
1994-05-27 12:33:43 +00:00
|
|
|
.Oo
|
2002-05-15 16:30:28 +00:00
|
|
|
.Fl I Ns Ar path
|
2002-05-30 11:29:25 +00:00
|
|
|
.Fl D Ns Ar sym Ns Op = Ns Ar val
|
1994-05-27 12:33:43 +00:00
|
|
|
.Fl U Ns Ar sym
|
2002-05-30 11:29:25 +00:00
|
|
|
.Fl iD Ns Ar sym Ns Op = Ns Ar val
|
2000-10-22 23:49:29 +00:00
|
|
|
.Fl iU Ns Ar sym
|
1994-05-27 12:33:43 +00:00
|
|
|
.Oc
|
|
|
|
.Ar ...
|
|
|
|
.Op Ar file
|
2002-05-15 16:30:28 +00:00
|
|
|
.Nm unifdefall
|
|
|
|
.Op Fl I Ns Ar path
|
|
|
|
.Ar ...
|
|
|
|
.Ar file
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh DESCRIPTION
|
2002-04-20 12:18:28 +00:00
|
|
|
The
|
|
|
|
.Nm
|
2002-05-15 16:30:28 +00:00
|
|
|
utility selectively processes conditional
|
|
|
|
.Xr cpp 1
|
|
|
|
directives.
|
|
|
|
It removes from a file
|
|
|
|
both the directives
|
|
|
|
and any additional text that they specify should be removed,
|
|
|
|
while otherwise leaving the file alone.
|
|
|
|
.Pp
|
2002-04-20 12:18:28 +00:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility acts on
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #if , #ifdef , #ifndef , #elif , #else ,
|
2002-05-15 16:30:28 +00:00
|
|
|
and
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #endif
|
2002-05-15 16:30:28 +00:00
|
|
|
lines,
|
|
|
|
and it understands only the commonly-used subset
|
|
|
|
of the expression syntax for
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #if
|
2002-05-15 16:30:28 +00:00
|
|
|
and
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #elif
|
2002-05-15 16:30:28 +00:00
|
|
|
lines.
|
|
|
|
Integer values of symbols defined on the command line,
|
|
|
|
the
|
|
|
|
.Fn defined
|
|
|
|
operator applied to symbols defined or undefined on the command line,
|
|
|
|
the operators
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic \&! , < , > , <= , >= , == , != , && , || ,
|
2002-05-15 16:30:28 +00:00
|
|
|
and parenthesized expressions
|
|
|
|
are handled,
|
|
|
|
and anything more complicated is passed through unharmed.
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #ifdef
|
2002-05-15 16:30:28 +00:00
|
|
|
and
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #ifndef
|
2002-05-15 16:30:28 +00:00
|
|
|
directives are only processed
|
|
|
|
if the symbol is specified on the command line,
|
2002-05-30 11:29:25 +00:00
|
|
|
otherwise they are also passed through unchanged.
|
2002-09-24 19:27:44 +00:00
|
|
|
Constant
|
|
|
|
.Ic #if
|
|
|
|
and
|
|
|
|
.Ic #elif
|
|
|
|
expressions are passed through by default,
|
|
|
|
or they may be processed by specifying the
|
|
|
|
.Fl k
|
|
|
|
flag.
|
2002-05-15 16:30:28 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility also understands just enough about C
|
|
|
|
to know when one of the directives is inactive
|
1994-05-27 12:33:43 +00:00
|
|
|
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
|
2002-05-15 16:30:28 +00:00
|
|
|
A script called
|
|
|
|
.Nm unifdefall
|
|
|
|
can be used to remove all conditional
|
|
|
|
.Xr cpp 1
|
|
|
|
directives from a file.
|
|
|
|
It uses
|
2002-05-30 11:29:25 +00:00
|
|
|
.Nm Fl s
|
2002-05-15 16:30:28 +00:00
|
|
|
and
|
2002-05-30 11:29:25 +00:00
|
|
|
.Nm cpp Fl dM
|
2002-05-15 16:30:28 +00:00
|
|
|
to get lists of all the controlling symbols
|
|
|
|
and their definitions (or lack thereof),
|
|
|
|
then invokes
|
2002-05-30 11:29:25 +00:00
|
|
|
.Nm
|
2002-05-15 16:30:28 +00:00
|
|
|
with appropriate arguments to process the file.
|
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
Available options:
|
2002-05-30 11:29:25 +00:00
|
|
|
.Bl -tag -width indent -compact
|
|
|
|
.It Fl D Ns Ar sym Ns Op = Ns Ar val
|
2002-05-15 16:30:28 +00:00
|
|
|
Specify that a symbol is defined,
|
|
|
|
and optionally specify what value to give it
|
|
|
|
for the purpose of handling
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #if
|
2002-05-15 16:30:28 +00:00
|
|
|
and
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #elif
|
2002-05-15 16:30:28 +00:00
|
|
|
directives.
|
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
.It Fl U Ns Ar sym
|
2002-05-15 16:30:28 +00:00
|
|
|
Specify that a symbol is undefined.
|
1994-05-27 12:33:43 +00:00
|
|
|
If the same symbol appears in more than one argument,
|
|
|
|
the last occurrence dominates.
|
|
|
|
.Pp
|
|
|
|
.It Fl c
|
|
|
|
If the
|
|
|
|
.Fl c
|
|
|
|
flag is specified,
|
|
|
|
then the operation of
|
1997-08-20 11:07:53 +00:00
|
|
|
.Nm
|
1994-05-27 12:33:43 +00:00
|
|
|
is complemented,
|
2002-05-30 11:29:25 +00:00
|
|
|
i.e., the lines that would have been removed or blanked
|
1994-05-27 12:33:43 +00:00
|
|
|
are retained and vice versa.
|
|
|
|
.Pp
|
2002-09-24 19:27:44 +00:00
|
|
|
.It Fl k
|
|
|
|
Process
|
|
|
|
.Ic #if
|
|
|
|
and
|
|
|
|
.Ic #elif
|
|
|
|
lines with constant expressions.
|
|
|
|
By default, sections controlled by such lines are passed through unchanged
|
|
|
|
because they typically start
|
|
|
|
.Li #if 0
|
|
|
|
and are used as a kind of comment to sketch out future or past development.
|
|
|
|
It would be rude to strip them out, just as it would be for normal comments.
|
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
.It Fl l
|
|
|
|
Replace removed lines with blank lines
|
|
|
|
instead of deleting them.
|
2002-05-15 16:30:28 +00:00
|
|
|
.Pp
|
|
|
|
.It Fl s
|
|
|
|
Instead of processing the input file as usual,
|
|
|
|
this option causes
|
|
|
|
.Nm
|
|
|
|
to produce a list of symbols that appear in expressions
|
|
|
|
that
|
|
|
|
.Nm
|
|
|
|
understands.
|
|
|
|
It is useful in conjunction with the
|
|
|
|
.Fl dM
|
|
|
|
option of
|
|
|
|
.Xr cpp 1
|
|
|
|
for creating
|
|
|
|
.Nm
|
|
|
|
command lines.
|
|
|
|
.Pp
|
1994-05-27 12:33:43 +00:00
|
|
|
.It Fl t
|
|
|
|
Disables parsing for C comments and quotes, which is useful
|
|
|
|
for plain text.
|
|
|
|
.Pp
|
2002-05-30 11:29:25 +00:00
|
|
|
.It Fl iD Ns Ar sym Ns Op = Ns Ar val
|
1994-05-27 12:33:43 +00:00
|
|
|
.It Fl iU Ns Ar sym
|
2002-05-30 11:29:25 +00:00
|
|
|
Ignore
|
|
|
|
.Ic #ifdef Ns s .
|
|
|
|
If your C code uses
|
|
|
|
.Ic #ifdef Ns s
|
|
|
|
to delimit non-C lines,
|
1994-05-27 12:33:43 +00:00
|
|
|
such as comments
|
|
|
|
or code which is under construction,
|
|
|
|
then you must tell
|
1997-08-20 11:07:53 +00:00
|
|
|
.Nm
|
2002-05-30 11:29:25 +00:00
|
|
|
which symbols are used for that purpose so that it will not try to parse
|
1994-05-27 12:33:43 +00:00
|
|
|
for quotes and comments
|
2002-05-30 11:29:25 +00:00
|
|
|
inside those
|
|
|
|
.Ic #ifdef Ns s .
|
2002-05-15 16:30:28 +00:00
|
|
|
One specifies ignored symbols with
|
|
|
|
.Fl iD Ns Ar sym Ns Oo = Ns Ar val Oc
|
1994-05-27 12:33:43 +00:00
|
|
|
and
|
|
|
|
.Fl iU Ns Ar sym
|
|
|
|
similar to
|
2002-05-30 11:29:25 +00:00
|
|
|
.Fl D Ns Ar sym Ns Op = Ns Ar val
|
1994-05-27 12:33:43 +00:00
|
|
|
and
|
|
|
|
.Fl U Ns Ar sym
|
|
|
|
above.
|
2002-05-15 16:30:28 +00:00
|
|
|
.Pp
|
|
|
|
.It Fl I Ns Ar path
|
|
|
|
Specifies to
|
|
|
|
.Nm unifdefall
|
|
|
|
an additional place to look for
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #include
|
2002-05-15 16:30:28 +00:00
|
|
|
files.
|
|
|
|
This option is ignored by
|
|
|
|
.Nm
|
|
|
|
for compatibility with
|
|
|
|
.Xr cpp 1
|
|
|
|
and to simplify the implementation of
|
|
|
|
.Nm unifdefall .
|
1994-05-27 12:33:43 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
2002-04-20 12:18:28 +00:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility copies its output to
|
1994-05-27 12:33:43 +00:00
|
|
|
.Em stdout
|
|
|
|
and will take its input from
|
|
|
|
.Em stdin
|
|
|
|
if no
|
|
|
|
.Ar file
|
|
|
|
argument is given.
|
|
|
|
.Pp
|
2002-04-20 12:18:28 +00:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility works nicely with the
|
1994-05-27 12:33:43 +00:00
|
|
|
.Fl D Ns Ar sym
|
2002-05-15 16:30:28 +00:00
|
|
|
option of
|
|
|
|
.Xr diff 1 .
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh SEE ALSO
|
2002-05-15 16:30:28 +00:00
|
|
|
.Xr cpp 1 ,
|
1994-05-27 12:33:43 +00:00
|
|
|
.Xr diff 1
|
|
|
|
.Sh DIAGNOSTICS
|
2002-05-30 11:29:25 +00:00
|
|
|
.Bl -item
|
2000-11-10 17:46:15 +00:00
|
|
|
.It
|
2002-05-15 16:30:28 +00:00
|
|
|
Inappropriate elif, else or endif.
|
2000-11-10 17:46:15 +00:00
|
|
|
.It
|
1994-05-27 12:33:43 +00:00
|
|
|
Premature
|
|
|
|
.Tn EOF
|
2002-05-15 16:30:28 +00:00
|
|
|
with line numbers of the unterminated
|
2002-05-30 11:29:25 +00:00
|
|
|
.Ic #ifdef Ns s .
|
2000-11-10 17:46:15 +00:00
|
|
|
.El
|
1994-05-27 12:33:43 +00:00
|
|
|
.Pp
|
2002-05-30 11:29:25 +00:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility exits 0 if the output is an exact copy of the input,
|
|
|
|
1 if not, and 2 if in trouble.
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh BUGS
|
2002-05-15 16:30:28 +00:00
|
|
|
Expression evaluation is very limited.
|
1994-05-27 12:33:43 +00:00
|
|
|
.Pp
|
2002-05-30 11:42:44 +00:00
|
|
|
Does not work correctly if input contains nul characters.
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
command appeared in
|
|
|
|
.Bx 4.3 .
|