Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/unifdef ANSI C support, from http://dotat.at/prog/misc/



details:   https://anonhg.NetBSD.org/src/rev/c7a0ef755725
branches:  trunk
changeset: 550104:c7a0ef755725
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Jul 30 08:21:46 2003 +0000

description:
ANSI C support, from http://dotat.at/prog/misc/
PR 22303

diffstat:

 usr.bin/unifdef/Makefile      |     4 +-
 usr.bin/unifdef/unifdef.1     |   286 ++++++-
 usr.bin/unifdef/unifdef.c     |  1402 ++++++++++++++++++++++++----------------
 usr.bin/unifdef/unifdefall.sh |    29 +
 4 files changed, 1100 insertions(+), 621 deletions(-)

diffs (truncated from 1904 to 300 lines):

diff -r 0025311d3a1b -r c7a0ef755725 usr.bin/unifdef/Makefile
--- a/usr.bin/unifdef/Makefile  Wed Jul 30 07:00:32 2003 +0000
+++ b/usr.bin/unifdef/Makefile  Wed Jul 30 08:21:46 2003 +0000
@@ -1,6 +1,8 @@
-#      $NetBSD: Makefile,v 1.3 1994/12/07 00:33:47 jtc Exp $
+#      $NetBSD: Makefile,v 1.4 2003/07/30 08:21:46 itojun Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 
 PROG=  unifdef
 
+SCRIPTS=unifdefall
+
 .include <bsd.prog.mk>
diff -r 0025311d3a1b -r c7a0ef755725 usr.bin/unifdef/unifdef.1
--- a/usr.bin/unifdef/unifdef.1 Wed Jul 30 07:00:32 2003 +0000
+++ b/usr.bin/unifdef/unifdef.1 Wed Jul 30 08:21:46 2003 +0000
@@ -1,10 +1,10 @@
-.\"    $NetBSD: unifdef.1,v 1.7 2001/12/08 19:20:18 wiz Exp $
+.\"    $NetBSD: unifdef.1,v 1.8 2003/07/30 08:21:47 itojun 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.
+.\" Dave Yost. Support for #if and #elif was added by Tony Finch.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
@@ -35,60 +35,115 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)unifdef.1  8.2 (Berkeley) 4/1/94
+.\"    $dotat: things/unifdef.1,v 1.45 2003/01/20 14:37:08 fanf2 Exp $
+.\" $FreeBSD: src/usr.bin/unifdef/unifdef.1,v 1.19 2003/01/20 12:41:41 fanf Exp $
 .\"
-.Dd April 1, 1994
+.Dd September 24, 2002
 .Dt UNIFDEF 1
 .Os
 .Sh NAME
-.Nm unifdef
-.Nd remove ifdef'ed lines
+.Nm unifdef , unifdefall
+.Nd remove preprocessor conditionals from code
 .Sh SYNOPSIS
 .Nm
-.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
+.Op Fl ceklst
+.Op Fl I Ns Ar path
+.Op Fl D Ns Ar sym Ns Op = Ns Ar val
+.Op Fl U Ns Ar sym
+.Op Fl iD Ns Ar sym Ns Op = Ns Ar val
+.Op Fl iU Ns Ar sym
 .Ar ...
 .Op Ar file
+.Nm unifdefall
+.Op Fl I Ns Ar path
+.Ar ...
+.Ar file
 .Sh DESCRIPTION
+The
 .Nm
-is useful for removing ifdef'ed lines
-from a file while otherwise leaving the file alone.
+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
+The
 .Nm
-acts on
-#ifdef, #ifndef, #else, and #endif lines,
-and it knows only enough about C
-to know when one of these is inactive
+utility acts on
+.Ic #if , #ifdef , #ifndef , #elif , #else ,
+and
+.Ic #endif
+lines,
+and it understands only the commonly-used subset
+of the expression syntax for
+.Ic #if
+and
+.Ic #elif
+lines.
+It handles
+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
+.Ic \&! , < , > , <= , >= , == , != , && , || ,
+and parenthesized expressions.
+Anything that it does not understand is passed through unharmed.
+It only processes
+.Ic #ifdef
+and
+.Ic #ifndef
+directives if the symbol is specified on the command line,
+otherwise they are also passed through unchanged.
+By default, it ignores
+.Ic #if
+and
+.Ic #elif
+lines with constant expressions,
+or they may be processed by specifying the
+.Fl k
+flag on the command line.
+.Pp
+The
+.Nm
+utility also understands just enough about C
+to know when one of the directives 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.
+or affected by a backslash-continued line.
+It spots unusually-formatted preprocessor directives
+and knows when the layout is too odd to handle.
+.Pp
+A script called
+.Nm unifdefall
+can be used to remove all conditional
+.Xr cpp 1
+directives from a file.
+It uses
+.Nm Fl s
+and
+.Nm cpp Fl dM
+to get lists of all the controlling symbols
+and their definitions (or lack thereof),
+then invokes
+.Nm
+with appropriate arguments to process the file.
 .Pp
 Available options:
-.Bl -tag -width Ds -compact
-.It Fl D Ns Ar sym
+.Bl -tag -width indent -compact
+.It Fl D Ns Ar sym Ns Op = Ns Ar val
+Specify that a symbol is defined,
+and optionally specify what value to give it
+for the purpose of handling
+.Ic #if
+and
+.Ic #elif
+directives.
+.Pp
 .It Fl U Ns Ar sym
-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 ``#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.
+Specify that a symbol is undefined.
 If the same symbol appears in more than one argument,
 the last occurrence dominates.
 .Pp
@@ -99,40 +154,108 @@
 then the operation of
 .Nm
 is complemented,
-i.e. the lines that would have been removed or blanked
+i.e., the lines that would have been removed or blanked
 are retained and vice versa.
 .Pp
+.It Fl e
+Because
+.Nm
+processes its input one line at a time,
+it cannot remove preprocessor directives that span more than one line.
+The most common example of this is a directive with a multi-line
+comment hanging off its right hand end.
+By default,
+if
+.Nm
+has to process such a directive,
+it will complain that the line is too obfuscated.
+The
+.Fl e
+option changes the behaviour so that,
+where possible,
+such lines are left unprocessed instead of reporting an error.
+.Pp
+.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
+.Dq 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
 .It Fl l
 Replace removed lines with blank lines
 instead of deleting them.
+.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
 .It Fl t
-Disables parsing for C comments and quotes, which is useful
+Disables parsing for C comments
+and line continuations,
+which is useful
 for plain text.
 .Pp
-.It Fl iD Ns Ar sym
+.It Fl iD Ns Ar sym Ns Op = Ns Ar val
 .It Fl iU Ns Ar sym
-Ignore ifdefs.
-If your C code uses ifdefs to delimit non-C lines,
+Ignore
+.Ic #ifdef Ns s .
+If your C code uses
+.Ic #ifdef Ns s
+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
+which symbols are used for that purpose so that it will not try to parse
+comments
+and line continuations
+inside those
+.Ic #ifdef Ns s .
+One specifies ignored symbols with
+.Fl iD Ns Ar sym Ns Oo = Ns Ar val Oc
 and
 .Fl iU Ns Ar sym
 similar to
-.Fl D Ns Ar sym
+.Fl D Ns Ar sym Ns Op = Ns Ar val
 and
 .Fl U Ns Ar sym
 above.
+.Pp
+.It Fl I Ns Ar path
+Specifies to
+.Nm unifdefall
+an additional place to look for
+.Ic #include
+files.
+This option is ignored by
+.Nm
+for compatibility with
+.Xr cpp 1
+and to simplify the implementation of
+.Nm unifdefall .
 .El
 .Pp
+The
 .Nm
-copies its output to



Home | Main Index | Thread Index | Old Index