WARNSify, fix .Nm usage, KNFify
This commit is contained in:
parent
9998247baa
commit
8d32174590
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: unifdef.1,v 1.4 1994/12/07 00:33:48 jtc Exp $
|
||||
.\" $NetBSD: unifdef.1,v 1.5 1997/10/20 02:23:13 lukem Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1985, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -43,7 +43,7 @@
|
||||
.Nm unifdef
|
||||
.Nd remove ifdef'ed lines
|
||||
.Sh SYNOPSIS
|
||||
.Nm unifdef
|
||||
.Nm
|
||||
.Op Fl clt
|
||||
.Oo
|
||||
.Fl D Ns Ar sym
|
||||
@ -54,10 +54,10 @@
|
||||
.Ar ...
|
||||
.Op Ar file
|
||||
.Sh DESCRIPTION
|
||||
.Nm Unifdef
|
||||
.Nm
|
||||
is useful for removing ifdef'ed lines
|
||||
from a file while otherwise leaving the file alone.
|
||||
.Nm Unifdef
|
||||
.Nm
|
||||
acts on
|
||||
#ifdef, #ifndef, #else, and #endif lines,
|
||||
and it knows only enough about C
|
||||
@ -97,7 +97,7 @@ If the
|
||||
.Fl c
|
||||
flag is specified,
|
||||
then the operation of
|
||||
.Nm unifdef
|
||||
.Nm
|
||||
is complemented,
|
||||
i.e. the lines that would have been removed or blanked
|
||||
are retained and vice versa.
|
||||
@ -116,7 +116,7 @@ If your C code uses ifdefs to delimit non-C lines,
|
||||
such as comments
|
||||
or code which is under construction,
|
||||
then you must tell
|
||||
.Nm unifdef
|
||||
.Nm
|
||||
which symbols are used for that purpose so that it won't try to parse
|
||||
for quotes and comments
|
||||
inside those ifdefs.
|
||||
@ -131,7 +131,7 @@ and
|
||||
above.
|
||||
.El
|
||||
.Pp
|
||||
.Nm Unifdef
|
||||
.Nm
|
||||
copies its output to
|
||||
.Em stdout
|
||||
and will take its input from
|
||||
@ -140,7 +140,7 @@ if no
|
||||
.Ar file
|
||||
argument is given.
|
||||
.Pp
|
||||
.Nm Unifdef
|
||||
.Nm
|
||||
works nicely with the
|
||||
.Fl D Ns Ar sym
|
||||
option added to
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: unifdef.c,v 1.4 1994/12/20 01:44:07 jtc Exp $ */
|
||||
/* $NetBSD: unifdef.c,v 1.5 1997/10/20 02:23:14 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1985, 1993
|
||||
@ -36,17 +36,17 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1985, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
__COPYRIGHT("@(#) Copyright (c) 1985, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)unifdef.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static char rcsid[] = "$NetBSD: unifdef.c,v 1.4 1994/12/20 01:44:07 jtc Exp $";
|
||||
__RCSID("$NetBSD: unifdef.c,v 1.5 1997/10/20 02:23:14 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -77,7 +77,8 @@ char *progname BSS;
|
||||
char *filename BSS;
|
||||
char text BSS; /* -t option in effect: this is a text file */
|
||||
char lnblank BSS; /* -l option in effect: blank deleted lines */
|
||||
char complement BSS; /* -c option in effect: complement the operation */
|
||||
char complement BSS; /* -c option in effect: complement the
|
||||
* operation */
|
||||
|
||||
#define MAXSYMS 100
|
||||
char *symname[MAXSYMS] BSS; /* symbol name */
|
||||
@ -101,6 +102,7 @@ int error __P((int, int, int));
|
||||
int findsym __P((char *));
|
||||
void flushline __P((Bool));
|
||||
int getlin __P((char *, int, FILE *, int));
|
||||
int main __P((int, char **));
|
||||
void pfile __P((void));
|
||||
void prname __P((void));
|
||||
char *skipcomment __P((char *));
|
||||
@ -112,8 +114,8 @@ int argc;
|
||||
char **argv;
|
||||
{
|
||||
char **curarg;
|
||||
register char *cp;
|
||||
register char *cp1;
|
||||
char *cp;
|
||||
char *cp1;
|
||||
char ignorethis;
|
||||
|
||||
progname = argv[0][0] ? argv[0] : "unifdef";
|
||||
@ -131,7 +133,7 @@ char **argv;
|
||||
)
|
||||
&& cp1[1] != '\0'
|
||||
) {
|
||||
register int symind;
|
||||
int symind;
|
||||
|
||||
if ((symind = findsym(&cp1[1])) < 0) {
|
||||
if (nsyms >= MAXSYMS) {
|
||||
@ -145,13 +147,17 @@ char **argv;
|
||||
}
|
||||
ignore[symind] = ignorethis;
|
||||
true[symind] = *cp1 == 'D' ? YES : NO;
|
||||
} else if (ignorethis)
|
||||
} else
|
||||
if (ignorethis)
|
||||
goto unrec;
|
||||
else if (strcmp (&cp[1], "t") == 0)
|
||||
else
|
||||
if (strcmp(&cp[1], "t") == 0)
|
||||
text = YES;
|
||||
else if (strcmp (&cp[1], "l") == 0)
|
||||
else
|
||||
if (strcmp(&cp[1], "l") == 0)
|
||||
lnblank = YES;
|
||||
else if (strcmp (&cp[1], "c") == 0)
|
||||
else
|
||||
if (strcmp(&cp[1], "c") == 0)
|
||||
complement = YES;
|
||||
else {
|
||||
unrec:
|
||||
@ -167,11 +173,11 @@ Usage: %s [-l] [-t] [-c] [[-Dsym] [-Usym] [-iDsym] [-iUsym]]... [file]\n\
|
||||
At least one arg from [-D -U -iD -iU] is required\n", progname);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
prname();
|
||||
fprintf(stderr, "can only do one file.\n");
|
||||
} else if (argc == 1) {
|
||||
} else
|
||||
if (argc == 1) {
|
||||
filename = *curarg;
|
||||
if ((input = fopen(filename, "r")) != NULL) {
|
||||
pfile();
|
||||
@ -190,7 +196,6 @@ Usage: %s [-l] [-t] [-c] [[-Dsym] [-Usym] [-iDsym] [-iUsym]]... [file]\n\
|
||||
(void) fflush(stdout);
|
||||
exit(exitstat);
|
||||
}
|
||||
|
||||
/* types of input lines: */
|
||||
typedef int Linetype;
|
||||
#define LT_PLAIN 0 /* ordinary line */
|
||||
@ -230,7 +235,6 @@ char *errs[] = {
|
||||
#define Q2EOF_ERR 7
|
||||
"Premature EOF in quoted string"
|
||||
};
|
||||
|
||||
/* States for inif arg to doif */
|
||||
#define IN_NONE 0
|
||||
#define IN_IF 1
|
||||
@ -246,13 +250,13 @@ pfile ()
|
||||
|
||||
int
|
||||
doif(thissym, inif, prevreject, depth)
|
||||
register int thissym; /* index of the symbol who was last ifdef'ed */
|
||||
int thissym; /* index of the symbol who was last ifdef'ed */
|
||||
int inif; /* YES or NO we are inside an ifdef */
|
||||
Reject_level prevreject;/* previous value of reject */
|
||||
int depth; /* depth of ifdef's */
|
||||
{
|
||||
register Linetype lineval;
|
||||
register Reject_level thisreject;
|
||||
Linetype lineval;
|
||||
Reject_level thisreject;
|
||||
int doret; /* tmp return value of doif */
|
||||
int cursym; /* index of the symbol returned by checkline */
|
||||
int stline; /* line number when called this time */
|
||||
@ -299,7 +303,8 @@ int depth; /* depth of ifdef's */
|
||||
if (insym[thissym] == SYM_TRUE) {
|
||||
reject = ignore[thissym] ? REJ_IGNORE : REJ_YES;
|
||||
insym[thissym] = SYM_FALSE;
|
||||
} else { /* (insym[thissym] == SYM_FALSE) */
|
||||
} else { /* (insym[thissym] ==
|
||||
* SYM_FALSE) */
|
||||
reject = prevreject;
|
||||
insym[thissym] = SYM_TRUE;
|
||||
}
|
||||
@ -338,7 +343,8 @@ int depth; /* depth of ifdef's */
|
||||
if (err != NO_ERR)
|
||||
(void) error(err, stqcline, depth);
|
||||
return error(IEOF_ERR, stline, depth);
|
||||
} else if (err != NO_ERR)
|
||||
} else
|
||||
if (err != NO_ERR)
|
||||
return error(err, stqcline, depth);
|
||||
else
|
||||
return NO_ERR;
|
||||
@ -346,7 +352,6 @@ int depth; /* depth of ifdef's */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define endsym(c) (!isalpha (c) && !isdigit (c) && c != '_')
|
||||
|
||||
#define MAXLINE 256
|
||||
@ -354,10 +359,11 @@ char tline[MAXLINE] BSS;
|
||||
|
||||
Linetype
|
||||
checkline(cursym)
|
||||
int *cursym; /* if LT_TRUE or LT_FALSE returned, set this to sym index */
|
||||
int *cursym; /* if LT_TRUE or LT_FALSE returned, set this
|
||||
* to sym index */
|
||||
{
|
||||
register char *cp;
|
||||
register char *symp;
|
||||
char *cp;
|
||||
char *symp;
|
||||
char *scp;
|
||||
Linetype retval;
|
||||
#define KWSIZE 8
|
||||
@ -387,15 +393,15 @@ int *cursym; /* if LT_TRUE or LT_FALSE returned, set this to sym index */
|
||||
if (strcmp(keyword, "ifdef") == 0) {
|
||||
retval = YES;
|
||||
goto ifdef;
|
||||
} else if (strcmp (keyword, "ifndef") == 0) {
|
||||
} else
|
||||
if (strcmp(keyword, "ifndef") == 0) {
|
||||
retval = NO;
|
||||
ifdef:
|
||||
scp = cp = skipcomment(++cp);
|
||||
if (incomment) {
|
||||
retval = LT_PLAIN;
|
||||
goto eol;
|
||||
}
|
||||
{
|
||||
} {
|
||||
int symind;
|
||||
|
||||
if ((symind = findsym(scp)) >= 0)
|
||||
@ -404,11 +410,14 @@ int *cursym; /* if LT_TRUE or LT_FALSE returned, set this to sym index */
|
||||
else
|
||||
retval = LT_OTHER;
|
||||
}
|
||||
} else if (strcmp (keyword, "if") == 0)
|
||||
} else
|
||||
if (strcmp(keyword, "if") == 0)
|
||||
retval = LT_IF;
|
||||
else if (strcmp (keyword, "else") == 0)
|
||||
else
|
||||
if (strcmp(keyword, "else") == 0)
|
||||
retval = LT_ELSE;
|
||||
else if (strcmp (keyword, "endif") == 0)
|
||||
else
|
||||
if (strcmp(keyword, "endif") == 0)
|
||||
retval = LT_ENDIF;
|
||||
|
||||
eol:
|
||||
@ -416,29 +425,33 @@ int *cursym; /* if LT_TRUE or LT_FALSE returned, set this to sym index */
|
||||
for (; *cp;) {
|
||||
if (incomment)
|
||||
cp = skipcomment(cp);
|
||||
else if (inquote == QUOTE_SINGLE)
|
||||
else
|
||||
if (inquote == QUOTE_SINGLE)
|
||||
cp = skipquote(cp, QUOTE_SINGLE);
|
||||
else if (inquote == QUOTE_DOUBLE)
|
||||
else
|
||||
if (inquote == QUOTE_DOUBLE)
|
||||
cp = skipquote(cp, QUOTE_DOUBLE);
|
||||
else if (*cp == '/' && cp[1] == '*')
|
||||
else
|
||||
if (*cp == '/' && cp[1] == '*')
|
||||
cp = skipcomment(cp);
|
||||
else if (*cp == '\'')
|
||||
else
|
||||
if (*cp == '\'')
|
||||
cp = skipquote(cp, QUOTE_SINGLE);
|
||||
else if (*cp == '"')
|
||||
else
|
||||
if (*cp == '"')
|
||||
cp = skipquote(cp, QUOTE_DOUBLE);
|
||||
else
|
||||
cp++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip over comments and stop at the next charaacter
|
||||
* position that is not whitespace.
|
||||
*/
|
||||
char *
|
||||
skipcomment(cp)
|
||||
register char *cp;
|
||||
char *cp;
|
||||
{
|
||||
if (incomment)
|
||||
goto inside;
|
||||
@ -468,17 +481,16 @@ register char *cp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip over a quoted string or character and stop at the next charaacter
|
||||
* position that is not whitespace.
|
||||
*/
|
||||
char *
|
||||
skipquote(cp, type)
|
||||
register char *cp;
|
||||
register int type;
|
||||
char *cp;
|
||||
int type;
|
||||
{
|
||||
register char qchar;
|
||||
char qchar;
|
||||
|
||||
qchar = type == QUOTE_SINGLE ? '\'' : '"';
|
||||
|
||||
@ -494,15 +506,12 @@ register int type;
|
||||
for (;; cp++) {
|
||||
if (*cp == qchar)
|
||||
break;
|
||||
if ( *cp == '\0'
|
||||
|| *cp == '\\' && *++cp == '\0'
|
||||
)
|
||||
if (*cp == '\0' || (*cp == '\\' && *++cp == '\0'))
|
||||
return cp;
|
||||
}
|
||||
inquote = QUOTE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* findsym - look for the symbol in the symbol table.
|
||||
* if found, return symbol table index,
|
||||
@ -512,10 +521,10 @@ int
|
||||
findsym(str)
|
||||
char *str;
|
||||
{
|
||||
register char *cp;
|
||||
register char *symp;
|
||||
register int symind;
|
||||
register char chr;
|
||||
char *cp;
|
||||
char *symp;
|
||||
int symind;
|
||||
char chr;
|
||||
|
||||
for (symind = 0; symind < nsyms; ++symind) {
|
||||
if (insym[symind] == SYM_INACTIVE) {
|
||||
@ -531,21 +540,20 @@ char *str;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* getlin - expands tabs if asked for
|
||||
* and (if compiled in) treats form-feed as an end-of-line
|
||||
*/
|
||||
int
|
||||
getlin(line, maxline, inp, expandtabs)
|
||||
register char *line;
|
||||
char *line;
|
||||
int maxline;
|
||||
FILE *inp;
|
||||
int expandtabs;
|
||||
{
|
||||
int tmp;
|
||||
register int num;
|
||||
register int chr;
|
||||
int num;
|
||||
int chr;
|
||||
#ifdef FFSPECIAL
|
||||
static char havechar = NO; /* have leftover char from last time */
|
||||
static char svchar BSS;
|
||||
@ -613,13 +621,14 @@ flushline (keep)
|
||||
Bool keep;
|
||||
{
|
||||
if ((keep && reject != REJ_YES) ^ complement) {
|
||||
register char *line = tline;
|
||||
register FILE *out = stdout;
|
||||
register char chr;
|
||||
char *line = tline;
|
||||
FILE *out = stdout;
|
||||
char chr;
|
||||
|
||||
while (chr = *line++)
|
||||
while ((chr = *line++) != 0)
|
||||
putc(chr, out);
|
||||
} else if (lnblank)
|
||||
} else
|
||||
if (lnblank)
|
||||
putc('\n', stdout);
|
||||
return;
|
||||
}
|
||||
@ -633,7 +642,8 @@ prname ()
|
||||
|
||||
int
|
||||
error(err, line, depth)
|
||||
int err; /* type of error & index into error string array */
|
||||
int err; /* type of error & index into error string
|
||||
* array */
|
||||
int line; /* line number */
|
||||
int depth; /* how many ifdefs we are inside */
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user