/*
* 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 2005 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>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef YES
#define NO 0
#endif
char *progname;
char *filename;
char true[MAXSYMS];
char nsyms;
char incomment;
#define QUOTE1 0
int exitstat;
static char *skipcomment(char *cp);
static char *nextsym(char *p);
static void pfile(void);
static void prname(void);
static void
usage(void)
{
"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);
}
int
{
char **curarg;
char *cp;
char *cp1;
char ignorethis;
#if !defined(TEXT_DOMAIN)
#endif
(void) textdomain(TEXT_DOMAIN);
break;
if (*++cp1 == 'i') {
ignorethis = YES;
cp1++;
} else
ignorethis = NO;
prname();
gettext("too many symbols.\n"));
exit(2);
}
} else if (ignorethis)
goto unrec;
complement = YES;
else {
prname();
usage();
}
}
if (nsyms == 0) {
usage();
}
if (argc > 1) {
prname();
} else if (argc == 1) {
pfile();
} else {
prname();
}
} else {
filename = "[stdin]";
pfile();
}
return (exitstat);
}
/* types of input lines: */
/* should be int declaration, was char */
char *errs[] = {
#define NO_ERR 0
"",
"",
"Inappropriate else",
"Inappropriate endif",
"Premature EOF in ifdef",
"Premature EOF in comment",
"Premature EOF in quoted character",
"Premature EOF in quoted string"
};
static void
pfile(void)
{
reject = 0;
}
static int
doif(
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 */
)
{
int lineval;
int thisreject;
int err;
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:
? CEOF_ERR
: NO_ERR;
if (inif) {
else
return (NO_ERR);
}
}
}
static int
{
char *cp;
char *symp;
char chr;
char *scp;
int retval;
int symind;
linenum++;
return (LEOF);
goto eol;
goto eol;
}
*symp = '\0';
goto ifdef;
/* skip to identifier */
++cp;
goto ifdef;
} else {
goto eol;
}
ifdef:
if (incomment) {
goto eol;
}
symind = 0;
for (;;) {
/* NULL */
}
break;
}
}
break;
}
}
eol:
while (*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.
*/
static char *
{
if (incomment)
goto inside;
for (;;) {
cp++;
if (text)
return (cp);
return (cp);
cp += 2;
if (!incomment) {
}
for (;;) {
if (*cp == '\0')
return (cp);
if (*++cp == '/')
break;
}
cp++;
}
}
/*
* Skip over a quoted string or character and stop at the next charaacter
* position that is not whitespace.
*/
static char *
{
char qchar;
goto inside;
for (;;) {
return (cp);
cp++;
}
for (; ; cp++) {
break;
return (cp);
}
cp++;
}
}
/*
* special getlin - treats form-feed as an end-of-line
* and expands tabs if asked for
*/
static int
{
int tmp;
int num;
int chr;
#ifdef FFSPECIAL
static char svchar;
#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);
}
static void
{
else if (lnblank)
}
/*
* putlin - for tools
*/
static void
{
char chr;
}
static void
prname(void)
{
}
static int
{
return (err);
prname();
#ifndef TESTING
#endif
#ifdef TESTING
#endif
exitstat = 1;
}
/* return the next token in the line buffer */
char *
nextsym(char *p)
{
char *key;
int i = KWSIZE;
while (!endsym(*p) && --i)
*key++ = *p++;
*key = '\0';
return (buf);
}