unifdef.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1982 Regents of the University of California */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* unifdef - remove ifdef'ed lines
*/
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#define BSS
#ifndef YES
#define YES 1
#define NO 0
#endif
#define MAXSYMS 100
#define KWSIZE 8
#define QUOTE1 0
#define QUOTE2 1
char *skipcomment ();
char *skipquote ();
char *nextsym();
#ifdef i386
#define gettext(s) s
#endif
int argc;
char **argv;
{
char **curarg;
register char *cp;
register char *cp1;
char ignorethis;
/* i386 doesn't handle this yet */
#ifndef i386
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
#endif
break;
if (*++cp1 == 'i') {
ignorethis = YES;
cp1++;
}
else
ignorethis = NO;
if ( ( *cp1 == 'D'
|| *cp1 == 'U'
)
) {
prname ();
exit (2);
}
}
else if (ignorethis)
goto unrec;
complement = YES;
else {
prname ();
goto usage;
}
}
if (nsyms == 0) {
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 ();
}
else if (argc == 1) {
pfile();
}
else {
prname ();
}
}
else {
filename = "[stdin]";
pfile();
}
/* NOTREACHED */
}
/* types of input lines: */
#define PLAIN 0 /* ordinary line */
/* should be int declaration, was char */
char *errs[] = {
#define NO_ERR 0
"",
#define END_ERR 1
"",
#define ELSE_ERR 2
"Inappropriate else",
#define ENDIF_ERR 3
"Inappropriate endif",
#define IEOF_ERR 4
"Premature EOF in ifdef",
#define CEOF_ERR 5
"Premature EOF in comment",
#define Q1EOF_ERR 6
"Premature EOF in quoted character",
#define Q2EOF_ERR 7
"Premature EOF in quoted string"
};
pfile ()
{
reject = 0;
return;
}
register int thissym; /* index of the symbol who was last ifdef'ed */
int inif; /* YES or NO we are inside an ifdef */
int prevreject; /* previous value of reject */
int depth; /* depth of ifdef's */
{
register int lineval;
register int 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 */
for (;;) {
case PLAIN:
break;
case TRUE:
case FALSE:
thisreject = reject;
else {
if (reject < 2)
}
else {
exitstat = 0;
}
break;
case OTHER:
break;
case ELSE:
if (inif != 1)
inif = 2;
if (thissym >= 0) {
else
reject = prevreject;
break;
}
}
break;
case ENDIF:
if (inif == 0)
if (thissym >= 0) {
reject = prevreject;
return NO_ERR;
}
}
return NO_ERR;
case LEOF: {
int err;
? CEOF_ERR
: NO_ERR;
if (inif) {
}
else
return NO_ERR;
}
}
}
}
#define MAXLINE 256
int *cursym;
{
register char *cp;
register char *symp;
register char chr;
char *scp;
int retval;
int symind;
linenum++;
return LEOF;
|| incomment
)
goto eol;
goto eol;
}
*symp = '\0';
goto ifdef;
}
/* skip to identifier */
++cp;
goto ifdef;
}
else {
goto eol;
}
}
ifdef:
if (incomment) {
goto eol;
}
for (symind = 0; ; ) {
)
{}
break;
}
}
break;
}
}
}
eol:
for (; *cp; ) {
if (incomment)
else if (*cp == '\'')
else if (*cp == '"')
else
cp++;
}
return retval;
}
/* Skip over comments and stop at the next character
* position that is not whitespace.
*/
char *
register char *cp;
{
if (incomment)
goto inside;
for (;; cp++) {
cp++;
if (text)
return cp;
if ( cp[0] != '/'
)
return cp;
cp += 2;
if (!incomment) {
}
for (;;) {
if (*cp == '\0')
return cp;
if (*++cp == '/')
break;
}
}
}
/* Skip over a quoted string or character and stop at the next charaacter
* position that is not whitespace.
*/
char *
register char *cp;
register int type;
{
register char qchar;
goto inside;
for (;; cp++) {
return cp;
cp++;
}
for (; ; cp++) {
break;
if ( *cp == '\0'
|| *cp == '\\'
&& *++cp == '\0'
)
return cp;
}
}
}
/*
* special getlin - treats form-feed as an end-of-line
* and expands tabs if asked for
*
*/
register char *line;
int maxline;
int expandtabs;
{
int tmp;
register int num;
register int chr;
#ifdef FFSPECIAL
#endif
num = 0;
#ifdef FFSPECIAL
if (havechar) {
goto ent;
}
#endif
#ifdef FFSPECIAL
ent:
#endif
num++;
}
else
switch (chr) {
case EOF:
return EOF;
case '\t':
if (expandtabs) {
do
*line++ = ' ';
while (--tmp);
break;
}
default:
num++;
break;
case '\n':
*line = '\n';
num++;
goto end;
#ifdef FFSPECIAL
case '\f':
if (++num == 1)
*line = '\f';
else {
*line = '\n';
}
goto end;
#endif
}
}
end:
*++line = '\0';
return num;
}
{
else if (lnblank)
return;
}
/*
* putlin - for tools
*
*/
register char *line;
{
register char chr;
return;
}
prname ()
{
return;
}
{
return err;
prname ();
#ifndef TESTING
#endif
#ifdef TESTING
#endif
exitstat = 1;
}
/* return the next token in the line buffer */
char *
nextsym(p)
char *p;
{
register char *key;
register int i = KWSIZE;
while (!endsym(*p) && --i)
*key++ = *p++;
*key = '\0';
return (buf);
}