Run files through clang-format before editing.
This commit is contained in:
parent
fa1ba55ad2
commit
dd00b81080
|
@ -27,20 +27,18 @@ int IncludeLevel = 0;
|
|||
#endif
|
||||
|
||||
extern char options[];
|
||||
extern char **inctable; /* list of include directories */
|
||||
extern char *getwdir();
|
||||
extern char** inctable; /* list of include directories */
|
||||
extern char* getwdir();
|
||||
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
|
||||
/* 1 if a corresponding ELSE has been */
|
||||
/* encountered. */
|
||||
/* 1 if a corresponding ELSE has been */
|
||||
/* encountered. */
|
||||
|
||||
int nestlevel = -1;
|
||||
|
||||
void macro_def();
|
||||
void do_define();
|
||||
|
||||
struct idf *
|
||||
GetIdentifier(skiponerr)
|
||||
int skiponerr; /* skip the rest of the line on error */
|
||||
struct idf* GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on error */
|
||||
{
|
||||
/* returns a pointer to the descriptor of the identifier that is
|
||||
read from the input stream. When the input doe not contain
|
||||
|
@ -56,9 +54,11 @@ GetIdentifier(skiponerr)
|
|||
tok = GetToken(&tk);
|
||||
ReplaceMacros = 1;
|
||||
UnknownIdIsZero = tmp;
|
||||
if (tok != IDENTIFIER) {
|
||||
if (skiponerr && tok != EOI) SkipToNewLine();
|
||||
return (struct idf *)0;
|
||||
if (tok != IDENTIFIER)
|
||||
{
|
||||
if (skiponerr && tok != EOI)
|
||||
SkipToNewLine();
|
||||
return (struct idf*)0;
|
||||
}
|
||||
return tk.tk_idf;
|
||||
}
|
||||
|
@ -80,9 +80,11 @@ domacro()
|
|||
ReplaceMacros = 0;
|
||||
toknum = GetToken(&tk);
|
||||
ReplaceMacros = 1;
|
||||
switch(toknum) { /* select control line action */
|
||||
switch (toknum)
|
||||
{ /* select control line action */
|
||||
case IDENTIFIER: /* is it a macro keyword? */
|
||||
switch (tk.tk_idf->id_resmac) {
|
||||
switch (tk.tk_idf->id_resmac)
|
||||
{
|
||||
case K_DEFINE: /* "define" */
|
||||
do_define();
|
||||
break;
|
||||
|
@ -111,7 +113,8 @@ domacro()
|
|||
/* set LineNumber and FileName according to
|
||||
the arguments.
|
||||
*/
|
||||
if (GetToken(&tk) != INTEGER) {
|
||||
if (GetToken(&tk) != INTEGER)
|
||||
{
|
||||
lexerror("bad #line syntax");
|
||||
SkipToNewLine();
|
||||
}
|
||||
|
@ -125,7 +128,7 @@ domacro()
|
|||
do_pragma();
|
||||
break;
|
||||
case K_UNDEF: /* "undef" */
|
||||
do_undef((struct idf *) 0);
|
||||
do_undef((struct idf*)0);
|
||||
break;
|
||||
default:
|
||||
/* invalid word seen after the '#' */
|
||||
|
@ -149,9 +152,7 @@ domacro()
|
|||
int lint_skip_comment;
|
||||
#endif
|
||||
|
||||
void
|
||||
skip_block(to_endif)
|
||||
int to_endif;
|
||||
void skip_block(to_endif) int to_endif;
|
||||
{
|
||||
/* skip_block() skips the input from
|
||||
1) a false #if, #ifdef, #ifndef or #elif until the
|
||||
|
@ -170,12 +171,15 @@ int to_endif;
|
|||
lint_skip_comment++;
|
||||
#endif
|
||||
NoUnstack++;
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
ch = GetChar(); /* read first character after newline */
|
||||
while (class(ch) == STSKIP)
|
||||
ch = GetChar();
|
||||
if (ch != '#') {
|
||||
if (ch == EOI) {
|
||||
if (ch != '#')
|
||||
{
|
||||
if (ch == EOI)
|
||||
{
|
||||
NoUnstack--;
|
||||
#ifdef LINT
|
||||
lint_skip_comment--;
|
||||
|
@ -183,22 +187,29 @@ int to_endif;
|
|||
return;
|
||||
}
|
||||
/* A possible '/' is not pushed back */
|
||||
if (ch == '/') {
|
||||
if (ch == '/')
|
||||
{
|
||||
ch = GetChar();
|
||||
if (ch != '*') UnGetChar();
|
||||
else {
|
||||
if (ch != '*')
|
||||
UnGetChar();
|
||||
else
|
||||
{
|
||||
skipcomment();
|
||||
continue;
|
||||
}
|
||||
} else UnGetChar();
|
||||
}
|
||||
else
|
||||
UnGetChar();
|
||||
SkipToNewLine();
|
||||
continue;
|
||||
}
|
||||
ReplaceMacros = 0;
|
||||
toknum = GetToken(&tk);
|
||||
ReplaceMacros = 1;
|
||||
if (toknum != IDENTIFIER) {
|
||||
if (toknum != INTEGER) {
|
||||
if (toknum != IDENTIFIER)
|
||||
{
|
||||
if (toknum != INTEGER)
|
||||
{
|
||||
lexerror("illegal # line");
|
||||
}
|
||||
SkipToNewLine();
|
||||
|
@ -209,7 +220,8 @@ int to_endif;
|
|||
Interpret #else, #elif and #endif if they occur
|
||||
on the same level.
|
||||
*/
|
||||
switch(tk.tk_idf->id_resmac) {
|
||||
switch (tk.tk_idf->id_resmac)
|
||||
{
|
||||
default:
|
||||
case K_UNKNOWN:
|
||||
/* invalid word seen after the '#' */
|
||||
|
@ -233,10 +245,12 @@ int to_endif;
|
|||
case K_ELIF:
|
||||
if (ifstack[nestlevel])
|
||||
lexerror("#elif after #else");
|
||||
if (!to_endif && nestlevel == skiplevel) {
|
||||
if (!to_endif && nestlevel == skiplevel)
|
||||
{
|
||||
nestlevel--;
|
||||
push_if();
|
||||
if (ifexpr()) {
|
||||
if (ifexpr())
|
||||
{
|
||||
NoUnstack--;
|
||||
#ifdef LINT
|
||||
lint_skip_comment--;
|
||||
|
@ -244,14 +258,17 @@ int to_endif;
|
|||
return;
|
||||
}
|
||||
}
|
||||
else SkipToNewLine(); /* otherwise done in ifexpr() */
|
||||
else
|
||||
SkipToNewLine(); /* otherwise done in ifexpr() */
|
||||
break;
|
||||
case K_ELSE:
|
||||
if (ifstack[nestlevel])
|
||||
lexerror("#else after #else");
|
||||
++(ifstack[nestlevel]);
|
||||
if (!to_endif && nestlevel == skiplevel) {
|
||||
if (SkipToNewLine()) {
|
||||
if (!to_endif && nestlevel == skiplevel)
|
||||
{
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
if (!options['o'])
|
||||
lexstrict("garbage following #else");
|
||||
}
|
||||
|
@ -261,12 +278,15 @@ int to_endif;
|
|||
#endif
|
||||
return;
|
||||
}
|
||||
else SkipToNewLine();
|
||||
else
|
||||
SkipToNewLine();
|
||||
break;
|
||||
case K_ENDIF:
|
||||
assert(nestlevel > nestlow);
|
||||
if (nestlevel == skiplevel) {
|
||||
if (SkipToNewLine()) {
|
||||
if (nestlevel == skiplevel)
|
||||
{
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
if (!options['o'])
|
||||
lexstrict("garbage following #endif");
|
||||
}
|
||||
|
@ -277,14 +297,14 @@ int to_endif;
|
|||
#endif
|
||||
return;
|
||||
}
|
||||
else SkipToNewLine();
|
||||
else
|
||||
SkipToNewLine();
|
||||
nestlevel--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ifexpr()
|
||||
{
|
||||
/* ifexpr() returns whether the restricted constant
|
||||
|
@ -311,30 +331,35 @@ do_include()
|
|||
{
|
||||
/* do_include() performs the inclusion of a file.
|
||||
*/
|
||||
char *filenm;
|
||||
char *result;
|
||||
char* filenm;
|
||||
char* result;
|
||||
int tok;
|
||||
struct token tk;
|
||||
|
||||
AccFileSpecifier = 1;
|
||||
if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING)
|
||||
filenm = tk.tk_bts;
|
||||
else {
|
||||
else
|
||||
{
|
||||
lexerror("bad include syntax");
|
||||
filenm = (char *)0;
|
||||
filenm = (char*)0;
|
||||
}
|
||||
AccFileSpecifier = 0;
|
||||
if (SkipToNewLine()) {
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
lexerror("bad include syntax");
|
||||
}
|
||||
inctable[0] = WorkingDir;
|
||||
if (filenm) {
|
||||
if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){
|
||||
if (filenm)
|
||||
{
|
||||
if (!InsertFile(filenm, &inctable[tok == FILESPECIFIER], &result))
|
||||
{
|
||||
lexerror("cannot open include file \"%s\"", filenm);
|
||||
add_dependency(filenm);
|
||||
free(filenm);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
add_dependency(result);
|
||||
WorkingDir = getwdir(result);
|
||||
File_Inserted = 1;
|
||||
|
@ -343,31 +368,33 @@ do_include()
|
|||
nestlow = nestlevel;
|
||||
#ifdef DBSYMTAB
|
||||
IncludeLevel++;
|
||||
if (options['g']) {
|
||||
C_ms_stb_cst(FileName, N_BINCL, 0, (arith) 0);
|
||||
if (options['g'])
|
||||
{
|
||||
C_ms_stb_cst(FileName, N_BINCL, 0, (arith)0);
|
||||
}
|
||||
#endif /* DBSYMTAB */
|
||||
if (result != filenm) free(filenm);
|
||||
if (result != filenm)
|
||||
free(filenm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
do_define()
|
||||
void do_define()
|
||||
{
|
||||
/* do_define() interprets a #define control line.
|
||||
*/
|
||||
struct idf *id; /* the #defined identifier's descriptor */
|
||||
struct idf* id; /* the #defined identifier's descriptor */
|
||||
int nformals = -1; /* keep track of the number of formals */
|
||||
char *formals[NPARAMS]; /* pointers to the names of the formals */
|
||||
char* formals[NPARAMS]; /* pointers to the names of the formals */
|
||||
char parbuf[PARBUFSIZE]; /* names of formals */
|
||||
char *repl_text; /* start of the replacement text */
|
||||
char* repl_text; /* start of the replacement text */
|
||||
int length; /* length of the replacement text */
|
||||
register ch;
|
||||
char *get_text();
|
||||
char* get_text();
|
||||
|
||||
/* read the #defined macro's name */
|
||||
if (!(id = GetIdentifier(1))) {
|
||||
if (!(id = GetIdentifier(1)))
|
||||
{
|
||||
lexerror("illegal #define line");
|
||||
return;
|
||||
}
|
||||
|
@ -375,15 +402,17 @@ do_define()
|
|||
followed immediately by a '('.
|
||||
*/
|
||||
ch = GetChar();
|
||||
if (ch == '(') {
|
||||
if ((nformals = getparams(formals, parbuf)) == -1) {
|
||||
if (ch == '(')
|
||||
{
|
||||
if ((nformals = getparams(formals, parbuf)) == -1)
|
||||
{
|
||||
SkipToNewLine();
|
||||
return; /* an error occurred */
|
||||
}
|
||||
ch = GetChar();
|
||||
}
|
||||
/* read the replacement text if there is any */
|
||||
ch = skipspaces(ch,0); /* find first character of the text */
|
||||
ch = skipspaces(ch, 0); /* find first character of the text */
|
||||
assert(ch != EOI);
|
||||
/* UnGetChar() is not right when replacement starts with a '/' */
|
||||
ChPushBack(ch);
|
||||
|
@ -402,12 +431,15 @@ push_if()
|
|||
|
||||
do_elif()
|
||||
{
|
||||
if (nestlevel <= nestlow) {
|
||||
if (nestlevel <= nestlow)
|
||||
{
|
||||
lexerror("#elif without corresponding #if");
|
||||
SkipToNewLine();
|
||||
}
|
||||
else { /* restart at this level as if a #if is detected. */
|
||||
if (ifstack[nestlevel]) {
|
||||
else
|
||||
{ /* restart at this level as if a #if is detected. */
|
||||
if (ifstack[nestlevel])
|
||||
{
|
||||
lexerror("#elif after #else");
|
||||
SkipToNewLine();
|
||||
}
|
||||
|
@ -424,8 +456,10 @@ do_else()
|
|||
lexstrict("garbage following #else");
|
||||
if (nestlevel <= nestlow)
|
||||
lexerror("#else without corresponding #if");
|
||||
else { /* mark this level as else-d */
|
||||
if (ifstack[nestlevel]) {
|
||||
else
|
||||
{ /* mark this level as else-d */
|
||||
if (ifstack[nestlevel])
|
||||
{
|
||||
lexerror("#else after #else");
|
||||
}
|
||||
++(ifstack[nestlevel]);
|
||||
|
@ -435,14 +469,17 @@ do_else()
|
|||
|
||||
do_endif()
|
||||
{
|
||||
if (SkipToNewLine()) {
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
if (!options['o'])
|
||||
lexstrict("garbage following #endif");
|
||||
}
|
||||
if (nestlevel <= nestlow) {
|
||||
if (nestlevel <= nestlow)
|
||||
{
|
||||
lexerror("#endif without corresponding #if");
|
||||
}
|
||||
else nestlevel--;
|
||||
else
|
||||
nestlevel--;
|
||||
}
|
||||
|
||||
do_if()
|
||||
|
@ -454,7 +491,7 @@ do_if()
|
|||
|
||||
do_ifdef(how)
|
||||
{
|
||||
register struct idf *id;
|
||||
register struct idf* id;
|
||||
|
||||
/* how == 1 : ifdef; how == 0 : ifndef
|
||||
*/
|
||||
|
@ -463,8 +500,7 @@ do_ifdef(how)
|
|||
lexerror("illegal #ifdef construction");
|
||||
else if (SkipToNewLine())
|
||||
if (!options['o'])
|
||||
lexstrict("garbage following #%s <identifier>",
|
||||
how ? "ifdef" : "ifndef");
|
||||
lexstrict("garbage following #%s <identifier>", how ? "ifdef" : "ifndef");
|
||||
|
||||
/* The next test is a shorthand for:
|
||||
(how && !id->id_macro) || (!how && id->id_macro)
|
||||
|
@ -474,23 +510,28 @@ do_ifdef(how)
|
|||
}
|
||||
|
||||
/* argidf != NULL when the undef came from a -U option */
|
||||
do_undef(argidf)
|
||||
struct idf *argidf;
|
||||
do_undef(argidf) struct idf* argidf;
|
||||
{
|
||||
register struct idf *id = argidf;
|
||||
register struct idf* id = argidf;
|
||||
|
||||
/* Forget a macro definition. */
|
||||
if (id || (id = GetIdentifier(1))) {
|
||||
if (id->id_macro) { /* forget the macro */
|
||||
if (id->id_macro->mc_flag & NOUNDEF) {
|
||||
if (id || (id = GetIdentifier(1)))
|
||||
{
|
||||
if (id->id_macro)
|
||||
{ /* forget the macro */
|
||||
if (id->id_macro->mc_flag & NOUNDEF)
|
||||
{
|
||||
lexerror("it is not allowed to undef %s", id->id_text);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
free(id->id_macro->mc_text);
|
||||
free_macro(id->id_macro);
|
||||
id->id_macro = (struct macro *) 0;
|
||||
id->id_macro = (struct macro*)0;
|
||||
}
|
||||
} /* else: don't complain */
|
||||
if (!argidf) {
|
||||
if (!argidf)
|
||||
{
|
||||
if (SkipToNewLine())
|
||||
if (!options['o'])
|
||||
lexstrict("garbage following #undef");
|
||||
|
@ -503,18 +544,16 @@ do_undef(argidf)
|
|||
do_error()
|
||||
{
|
||||
int len;
|
||||
char *get_text();
|
||||
char *bp = get_text((char **) 0, &len);
|
||||
char* get_text();
|
||||
char* bp = get_text((char**)0, &len);
|
||||
|
||||
lexerror("user error: %s", bp);
|
||||
free(bp);
|
||||
LineNumber++;
|
||||
}
|
||||
|
||||
int
|
||||
getparams(buf, parbuf)
|
||||
char *buf[];
|
||||
char parbuf[];
|
||||
int getparams(buf, parbuf) char* buf[];
|
||||
char parbuf[];
|
||||
{
|
||||
/* getparams() reads the formal parameter list of a macro
|
||||
definition.
|
||||
|
@ -526,19 +565,22 @@ getparams(buf, parbuf)
|
|||
Note that the '(' has already been eaten.
|
||||
The names of the formal parameters are stored into parbuf.
|
||||
*/
|
||||
register char **pbuf = &buf[0];
|
||||
register char** pbuf = &buf[0];
|
||||
register int c;
|
||||
register char *ptr = &parbuf[0];
|
||||
register char **pbuf2;
|
||||
register char* ptr = &parbuf[0];
|
||||
register char** pbuf2;
|
||||
|
||||
c = GetChar();
|
||||
c = skipspaces(c,0);
|
||||
if (c == ')') { /* no parameters: #define name() */
|
||||
*pbuf = (char *) 0;
|
||||
c = skipspaces(c, 0);
|
||||
if (c == ')')
|
||||
{ /* no parameters: #define name() */
|
||||
*pbuf = (char*)0;
|
||||
return 0;
|
||||
}
|
||||
for (;;) { /* eat the formal parameter list */
|
||||
if (class(c) != STIDF && class(c) != STELL) {
|
||||
for (;;)
|
||||
{ /* eat the formal parameter list */
|
||||
if (class(c) != STIDF && class(c) != STELL)
|
||||
{
|
||||
lexerror("#define: bad formal parameter");
|
||||
return -1;
|
||||
}
|
||||
|
@ -546,7 +588,8 @@ getparams(buf, parbuf)
|
|||
*ptr++ = c;
|
||||
if (ptr >= &parbuf[PARBUFSIZE])
|
||||
fatal("formal parameter buffer overflow");
|
||||
do { /* eat the identifier name */
|
||||
do
|
||||
{ /* eat the identifier name */
|
||||
c = GetChar();
|
||||
*ptr++ = c;
|
||||
if (ptr >= &parbuf[PARBUFSIZE])
|
||||
|
@ -557,45 +600,49 @@ getparams(buf, parbuf)
|
|||
/* Check if this formal parameter is already used.
|
||||
Usually, macros do not have many parameters, so ...
|
||||
*/
|
||||
for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) {
|
||||
if (!strcmp(*pbuf2, *pbuf)) {
|
||||
lexerror("formal parameter \"%s\" already used",
|
||||
*pbuf);
|
||||
for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--)
|
||||
{
|
||||
if (!strcmp(*pbuf2, *pbuf))
|
||||
{
|
||||
lexerror("formal parameter \"%s\" already used", *pbuf);
|
||||
}
|
||||
}
|
||||
|
||||
pbuf++;
|
||||
c = skipspaces(c,0);
|
||||
if (c == ')') { /* end of the formal parameter list */
|
||||
*pbuf = (char *) 0;
|
||||
c = skipspaces(c, 0);
|
||||
if (c == ')')
|
||||
{ /* end of the formal parameter list */
|
||||
*pbuf = (char*)0;
|
||||
return pbuf - buf;
|
||||
}
|
||||
if (c != ',') {
|
||||
if (c != ',')
|
||||
{
|
||||
lexerror("#define: bad formal parameter list");
|
||||
return -1;
|
||||
}
|
||||
c = GetChar();
|
||||
c = skipspaces(c,0);
|
||||
c = skipspaces(c, 0);
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
void
|
||||
macro_def(id, text, nformals, length, flags)
|
||||
register struct idf *id;
|
||||
char *text;
|
||||
void macro_def(id, text, nformals, length, flags) register struct idf* id;
|
||||
char* text;
|
||||
{
|
||||
register struct macro *newdef = id->id_macro;
|
||||
register struct macro* newdef = id->id_macro;
|
||||
|
||||
/* macro_def() puts the contents and information of a macro
|
||||
definition into a structure and stores it into the symbol
|
||||
table entry belonging to the name of the macro.
|
||||
An error is given if there was already a definition
|
||||
*/
|
||||
if (newdef) { /* is there a redefinition? */
|
||||
if (newdef->mc_flag & NOUNDEF) {
|
||||
if (newdef)
|
||||
{ /* is there a redefinition? */
|
||||
if (newdef->mc_flag & NOUNDEF)
|
||||
{
|
||||
lexerror("it is not allowed to redefine %s", id->id_text);
|
||||
} else if (!macroeq(newdef->mc_text, text))
|
||||
}
|
||||
else if (!macroeq(newdef->mc_text, text))
|
||||
lexerror("illegal redefine of \"%s\"", id->id_text);
|
||||
free(text);
|
||||
return;
|
||||
|
@ -607,15 +654,13 @@ macro_def(id, text, nformals, length, flags)
|
|||
newdef->mc_flag = flags; /* special flags */
|
||||
}
|
||||
|
||||
int
|
||||
find_name(nm, index)
|
||||
char *nm, *index[];
|
||||
int find_name(nm, index) char *nm, *index[];
|
||||
{
|
||||
/* find_name() returns the index of "nm" in the namelist
|
||||
"index" if it can be found there. 0 is returned if it is
|
||||
not there.
|
||||
*/
|
||||
register char **ip = &index[0];
|
||||
register char** ip = &index[0];
|
||||
|
||||
while (*ip)
|
||||
if (strcmp(nm, *ip++) == 0)
|
||||
|
@ -626,10 +671,8 @@ find_name(nm, index)
|
|||
|
||||
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
|
||||
|
||||
char *
|
||||
get_text(formals, length)
|
||||
char *formals[];
|
||||
int *length;
|
||||
char* get_text(formals, length) char* formals[];
|
||||
int* length;
|
||||
{
|
||||
/* get_text() copies the replacement text of a macro
|
||||
definition with zero, one or more parameters, thereby
|
||||
|
@ -655,104 +698,131 @@ get_text(formals, length)
|
|||
*/
|
||||
register int c;
|
||||
struct repl repls;
|
||||
register struct repl *repl = &repls;
|
||||
register struct repl* repl = &repls;
|
||||
int blank = 0;
|
||||
|
||||
c = GetChar();
|
||||
|
||||
repl->r_ptr = repl->r_text = Malloc(repl->r_size = ITEXTSIZE);
|
||||
*repl->r_ptr = '\0';
|
||||
while ((c != EOI) && (class(c) != STNL)) {
|
||||
if (BLANK(c)) {
|
||||
while ((c != EOI) && (class(c) != STNL))
|
||||
{
|
||||
if (BLANK(c))
|
||||
{
|
||||
blank++;
|
||||
c = GetChar();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\'' || c == '"') {
|
||||
if (c == '\'' || c == '"')
|
||||
{
|
||||
register int delim = c;
|
||||
|
||||
if (blank) {
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
do {
|
||||
do
|
||||
{
|
||||
add2repl(repl, c);
|
||||
if (c == '\\') add2repl(repl, GetChar());
|
||||
if (c == '\\')
|
||||
add2repl(repl, GetChar());
|
||||
c = GetChar();
|
||||
} while (c != delim && c != EOI && class(c) != STNL);
|
||||
if (c == EOI || class(c) == STNL) {
|
||||
if (c == EOI || class(c) == STNL)
|
||||
{
|
||||
lexstrict("unclosed opening %c", delim);
|
||||
break;
|
||||
}
|
||||
add2repl(repl, c);
|
||||
c = GetChar();
|
||||
} else if (c == '/') {
|
||||
}
|
||||
else if (c == '/')
|
||||
{
|
||||
c = GetChar();
|
||||
if (c == '*') {
|
||||
if (c == '*')
|
||||
{
|
||||
skipcomment();
|
||||
blank++;
|
||||
c = GetChar();
|
||||
continue;
|
||||
}
|
||||
if (blank) {
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
add2repl(repl, '/');
|
||||
} else if (formals
|
||||
&& (class(c) == STIDF || class(c) == STELL)) {
|
||||
}
|
||||
else if (formals && (class(c) == STIDF || class(c) == STELL))
|
||||
{
|
||||
char id_buf[IDFSIZE + 1];
|
||||
register char *idp = id_buf;
|
||||
register char* idp = id_buf;
|
||||
int n;
|
||||
|
||||
/* read identifier: it may be a formal parameter */
|
||||
*idp++ = c;
|
||||
do {
|
||||
do
|
||||
{
|
||||
c = GetChar();
|
||||
if (idp <= &id_buf[IDFSIZE])
|
||||
*idp++ = c;
|
||||
} while (in_idf(c));
|
||||
*--idp = '\0';
|
||||
|
||||
if (blank) {
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
/* construct the formal parameter mark or identifier */
|
||||
if (n = find_name(id_buf, formals))
|
||||
add2repl(repl, FORMALP | (char) n);
|
||||
else {
|
||||
add2repl(repl, FORMALP | (char)n);
|
||||
else
|
||||
{
|
||||
idp = id_buf;
|
||||
while (*idp) add2repl(repl, *idp++);
|
||||
while (*idp)
|
||||
add2repl(repl, *idp++);
|
||||
}
|
||||
} else if (class(c) == STNUM) {
|
||||
if (blank) {
|
||||
}
|
||||
else if (class(c) == STNUM)
|
||||
{
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
add2repl(repl, c);
|
||||
if (c == '.') {
|
||||
if (c == '.')
|
||||
{
|
||||
c = GetChar();
|
||||
if (class(c) != STNUM) {
|
||||
if (class(c) != STNUM)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
add2repl(repl, c);
|
||||
}
|
||||
c = GetChar();
|
||||
while(in_idf(c) || c == '.') {
|
||||
while (in_idf(c) || c == '.')
|
||||
{
|
||||
add2repl(repl, c);
|
||||
if((c = GetChar()) == 'e' || c == 'E') {
|
||||
if ((c = GetChar()) == 'e' || c == 'E')
|
||||
{
|
||||
add2repl(repl, c);
|
||||
c = GetChar();
|
||||
if (c == '+' || c == '-') {
|
||||
if (c == '+' || c == '-')
|
||||
{
|
||||
add2repl(repl, c);
|
||||
c = GetChar();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (blank) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
|
@ -761,7 +831,7 @@ get_text(formals, length)
|
|||
}
|
||||
}
|
||||
*length = repl->r_ptr - repl->r_text;
|
||||
return Realloc(repl->r_text, (unsigned)(repl->r_ptr - repl->r_text +1));
|
||||
return Realloc(repl->r_text, (unsigned)(repl->r_ptr - repl->r_text + 1));
|
||||
}
|
||||
|
||||
/* macroeq() decides whether two macro replacement texts are
|
||||
|
@ -769,33 +839,37 @@ get_text(formals, length)
|
|||
as strings, without taking care of the leading and trailing
|
||||
blanks (spaces and tabs).
|
||||
*/
|
||||
macroeq(s, t)
|
||||
register char *s, *t;
|
||||
macroeq(s, t) register char* s, *t;
|
||||
{
|
||||
|
||||
/* skip leading spaces */
|
||||
while (BLANK(*s)) s++;
|
||||
while (BLANK(*t)) t++;
|
||||
while (BLANK(*s))
|
||||
s++;
|
||||
while (BLANK(*t))
|
||||
t++;
|
||||
/* first non-blank encountered in both strings */
|
||||
/* The actual comparison loop: */
|
||||
while (*s && *s == *t)
|
||||
s++, t++;
|
||||
/* two cases are possible when arrived here: */
|
||||
if (*s == '\0') { /* *s == '\0' */
|
||||
while (BLANK(*t)) t++;
|
||||
if (*s == '\0')
|
||||
{ /* *s == '\0' */
|
||||
while (BLANK(*t))
|
||||
t++;
|
||||
return *t == '\0';
|
||||
}
|
||||
else { /* *s != *t */
|
||||
while (BLANK(*s)) s++;
|
||||
while (BLANK(*t)) t++;
|
||||
else
|
||||
{ /* *s != *t */
|
||||
while (BLANK(*s))
|
||||
s++;
|
||||
while (BLANK(*t))
|
||||
t++;
|
||||
return (*s == '\0') && (*t == '\0');
|
||||
}
|
||||
}
|
||||
#else /* NOPP */
|
||||
|
||||
struct idf *
|
||||
GetIdentifier(skiponerr)
|
||||
int skiponerr; /* skip the rest of the line on error */
|
||||
struct idf* GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on error */
|
||||
{
|
||||
/* returns a pointer to the descriptor of the identifier that is
|
||||
read from the input stream. When the input does not contain
|
||||
|
@ -807,9 +881,11 @@ GetIdentifier(skiponerr)
|
|||
struct token tk;
|
||||
|
||||
tok = GetToken(&tk);
|
||||
if (tok != IDENTIFIER) {
|
||||
if (skiponerr && tok != EOI) SkipToNewLine();
|
||||
return (struct idf *)0;
|
||||
if (tok != IDENTIFIER)
|
||||
{
|
||||
if (skiponerr && tok != EOI)
|
||||
SkipToNewLine();
|
||||
return (struct idf*)0;
|
||||
}
|
||||
return tk.tk_idf;
|
||||
}
|
||||
|
@ -820,14 +896,18 @@ domacro()
|
|||
struct token tk;
|
||||
|
||||
EoiForNewline = 1;
|
||||
if ((tok = GetToken(&tk)) == IDENTIFIER) {
|
||||
if (! strcmp(tk.tk_idf->id_text, "pragma")) {
|
||||
if ((tok = GetToken(&tk)) == IDENTIFIER)
|
||||
{
|
||||
if (!strcmp(tk.tk_idf->id_text, "pragma"))
|
||||
{
|
||||
do_pragma();
|
||||
EoiForNewline = 0;
|
||||
return;
|
||||
}
|
||||
} else if (tok == INTEGER) {
|
||||
do_line((unsigned int) tk.tk_ival);
|
||||
}
|
||||
else if (tok == INTEGER)
|
||||
{
|
||||
do_line((unsigned int)tk.tk_ival);
|
||||
EoiForNewline = 0;
|
||||
return;
|
||||
}
|
||||
|
@ -837,22 +917,23 @@ domacro()
|
|||
}
|
||||
#endif /* NOPP */
|
||||
|
||||
|
||||
do_line(l)
|
||||
unsigned int l;
|
||||
do_line(l) unsigned int l;
|
||||
{
|
||||
struct token tk;
|
||||
int t = GetToken(&tk);
|
||||
|
||||
if (t != EOI) SkipToNewLine();
|
||||
if (t != EOI)
|
||||
SkipToNewLine();
|
||||
LineNumber = l; /* the number of the next input line */
|
||||
if (t == STRING) { /* is there a filespecifier? */
|
||||
/*
|
||||
if (t == STRING)
|
||||
{ /* is there a filespecifier? */
|
||||
/*
|
||||
* Do not attempt to free the old string, since it might
|
||||
* be used in a def structure.
|
||||
*/
|
||||
#ifdef DBSYMTAB
|
||||
if (options['g'] && strcmp(FileName, tk.tk_bts) != 0) {
|
||||
if (options['g'] && strcmp(FileName, tk.tk_bts) != 0)
|
||||
{
|
||||
C_ms_std(tk.tk_bts, N_SOL, 0);
|
||||
}
|
||||
#endif /* DBSYMTAB */
|
||||
|
|
|
@ -22,23 +22,21 @@
|
|||
#include "replace.h"
|
||||
|
||||
extern char options[];
|
||||
extern char **inctable; /* list of include directories */
|
||||
extern char *getwdir();
|
||||
extern char** inctable; /* list of include directories */
|
||||
extern char* getwdir();
|
||||
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
|
||||
/* 1 if a corresponding ELSE has been */
|
||||
/* encountered. */
|
||||
/* 1 if a corresponding ELSE has been */
|
||||
/* encountered. */
|
||||
|
||||
int nestlevel = -1;
|
||||
int svnestlevel[30] = {-1};
|
||||
int svnestlevel[30] = { -1 };
|
||||
int nestcount;
|
||||
extern int do_preprocess;
|
||||
|
||||
void macro_def();
|
||||
void do_define();
|
||||
|
||||
char *
|
||||
GetIdentifier(skiponerr)
|
||||
int skiponerr; /* skip the rest of the line on error */
|
||||
char* GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on error */
|
||||
{
|
||||
/* Returns a pointer to the identifier that is read from the
|
||||
input stream. When the input does not contain an
|
||||
|
@ -55,9 +53,11 @@ GetIdentifier(skiponerr)
|
|||
tok = GetToken(&tk);
|
||||
ReplaceMacros = 1;
|
||||
UnknownIdIsZero = tmp;
|
||||
if (tok != IDENTIFIER) {
|
||||
if (skiponerr && tok != EOF) SkipToNewLine();
|
||||
return (char *)0;
|
||||
if (tok != IDENTIFIER)
|
||||
{
|
||||
if (skiponerr && tok != EOF)
|
||||
SkipToNewLine();
|
||||
return (char*)0;
|
||||
}
|
||||
return tk.tk_str;
|
||||
}
|
||||
|
@ -74,23 +74,26 @@ GetIdentifier(skiponerr)
|
|||
domacro()
|
||||
{
|
||||
struct token tk; /* the token itself */
|
||||
register struct idf *id;
|
||||
register struct idf* id;
|
||||
int toknum;
|
||||
|
||||
ReplaceMacros = 0;
|
||||
toknum = GetToken(&tk);
|
||||
ReplaceMacros = 1;
|
||||
switch(toknum) { /* select control line action */
|
||||
switch (toknum)
|
||||
{ /* select control line action */
|
||||
case IDENTIFIER: /* is it a macro keyword? */
|
||||
id = findidf(tk.tk_str);
|
||||
if (!id) {
|
||||
if (!id)
|
||||
{
|
||||
error("%s: unknown control", tk.tk_str);
|
||||
SkipToNewLine();
|
||||
free(tk.tk_str);
|
||||
break;
|
||||
}
|
||||
free(tk.tk_str);
|
||||
switch (id->id_resmac) {
|
||||
switch (id->id_resmac)
|
||||
{
|
||||
case K_DEFINE: /* "define" */
|
||||
do_define();
|
||||
break;
|
||||
|
@ -119,7 +122,8 @@ domacro()
|
|||
/* set LineNumber and FileName according to
|
||||
the arguments.
|
||||
*/
|
||||
if (GetToken(&tk) != INTEGER) {
|
||||
if (GetToken(&tk) != INTEGER)
|
||||
{
|
||||
error("bad #line syntax");
|
||||
SkipToNewLine();
|
||||
}
|
||||
|
@ -133,7 +137,7 @@ domacro()
|
|||
do_pragma();
|
||||
break;
|
||||
case K_UNDEF: /* "undef" */
|
||||
do_undef((char *)0);
|
||||
do_undef((char*)0);
|
||||
break;
|
||||
default:
|
||||
/* invalid word seen after the '#' */
|
||||
|
@ -152,9 +156,7 @@ domacro()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
skip_block(to_endif)
|
||||
int to_endif;
|
||||
void skip_block(to_endif) int to_endif;
|
||||
{
|
||||
/* skip_block() skips the input from
|
||||
1) a false #if, #ifdef, #ifndef or #elif until the
|
||||
|
@ -168,33 +170,43 @@ int to_endif;
|
|||
register int skiplevel = nestlevel; /* current nesting level */
|
||||
struct token tk;
|
||||
int toknum;
|
||||
struct idf *id;
|
||||
struct idf* id;
|
||||
|
||||
NoUnstack++;
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
ch = GetChar(); /* read first character after newline */
|
||||
while (class(ch) == STSKIP)
|
||||
ch = GetChar();
|
||||
if (ch != '#') {
|
||||
if (ch == EOI) {
|
||||
if (ch != '#')
|
||||
{
|
||||
if (ch == EOI)
|
||||
{
|
||||
NoUnstack--;
|
||||
return;
|
||||
}
|
||||
if (ch == '/') {
|
||||
if (ch != '*') UnGetChar();
|
||||
else {
|
||||
if (ch == '/')
|
||||
{
|
||||
if (ch != '*')
|
||||
UnGetChar();
|
||||
else
|
||||
{
|
||||
skipcomment();
|
||||
continue;
|
||||
}
|
||||
} else UnGetChar();
|
||||
}
|
||||
else
|
||||
UnGetChar();
|
||||
SkipToNewLine();
|
||||
continue;
|
||||
}
|
||||
ReplaceMacros = 0;
|
||||
toknum = GetToken(&tk);
|
||||
ReplaceMacros = 1;
|
||||
if (toknum != IDENTIFIER) {
|
||||
if (toknum != INTEGER) {
|
||||
if (toknum != IDENTIFIER)
|
||||
{
|
||||
if (toknum != INTEGER)
|
||||
{
|
||||
error("illegal # line");
|
||||
}
|
||||
SkipToNewLine();
|
||||
|
@ -206,13 +218,16 @@ int to_endif;
|
|||
on the same level.
|
||||
*/
|
||||
id = findidf(tk.tk_str);
|
||||
if (id == (struct idf *)0) {
|
||||
if (id == (struct idf*)0)
|
||||
{
|
||||
/* invalid word seen after the '#' */
|
||||
warning("%s: unknown control", tk.tk_str);
|
||||
}
|
||||
free(tk.tk_str);
|
||||
if (id == (struct idf *)0) continue;
|
||||
switch(id->id_resmac) {
|
||||
if (id == (struct idf*)0)
|
||||
continue;
|
||||
switch (id->id_resmac)
|
||||
{
|
||||
case K_DEFINE:
|
||||
case K_ERROR:
|
||||
case K_INCLUDE:
|
||||
|
@ -231,34 +246,42 @@ int to_endif;
|
|||
case K_ELIF:
|
||||
if (ifstack[nestlevel])
|
||||
error("#elif after #else");
|
||||
if (!to_endif && nestlevel == skiplevel) {
|
||||
if (!to_endif && nestlevel == skiplevel)
|
||||
{
|
||||
nestlevel--;
|
||||
push_if();
|
||||
if (ifexpr()) {
|
||||
if (ifexpr())
|
||||
{
|
||||
NoUnstack--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else SkipToNewLine(); /* otherwise done in ifexpr() */
|
||||
else
|
||||
SkipToNewLine(); /* otherwise done in ifexpr() */
|
||||
break;
|
||||
case K_ELSE:
|
||||
if (ifstack[nestlevel])
|
||||
error("#else after #else");
|
||||
++(ifstack[nestlevel]);
|
||||
if (!to_endif && nestlevel == skiplevel) {
|
||||
if (SkipToNewLine()) {
|
||||
if (!to_endif && nestlevel == skiplevel)
|
||||
{
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
if (!options['o'])
|
||||
strict("garbage following #else");
|
||||
}
|
||||
NoUnstack--;
|
||||
return;
|
||||
}
|
||||
else SkipToNewLine();
|
||||
else
|
||||
SkipToNewLine();
|
||||
break;
|
||||
case K_ENDIF:
|
||||
assert(nestlevel > svnestlevel[nestcount]);
|
||||
if (nestlevel == skiplevel) {
|
||||
if (SkipToNewLine()) {
|
||||
if (nestlevel == skiplevel)
|
||||
{
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
if (!options['o'])
|
||||
strict("garbage following #endif");
|
||||
}
|
||||
|
@ -266,14 +289,14 @@ int to_endif;
|
|||
NoUnstack--;
|
||||
return;
|
||||
}
|
||||
else SkipToNewLine();
|
||||
else
|
||||
SkipToNewLine();
|
||||
nestlevel--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ifexpr()
|
||||
{
|
||||
/* ifexpr() returns whether the restricted constant
|
||||
|
@ -299,30 +322,37 @@ do_include()
|
|||
{
|
||||
/* do_include() performs the inclusion of a file.
|
||||
*/
|
||||
char *filenm;
|
||||
char *result;
|
||||
char* filenm;
|
||||
char* result;
|
||||
int tok;
|
||||
struct token tk;
|
||||
|
||||
AccFileSpecifier = 1;
|
||||
if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING)
|
||||
filenm = tk.tk_str;
|
||||
else {
|
||||
else
|
||||
{
|
||||
error("bad include syntax");
|
||||
filenm = (char *)0;
|
||||
filenm = (char*)0;
|
||||
}
|
||||
AccFileSpecifier = 0;
|
||||
if (SkipToNewLine()) {
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
error("bad include syntax");
|
||||
}
|
||||
inctable[0] = WorkingDir;
|
||||
if (filenm) {
|
||||
if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){
|
||||
if (do_preprocess) error("cannot open include file \"%s\"", filenm);
|
||||
else warning("cannot open include file \"%s\"", filenm);
|
||||
if (filenm)
|
||||
{
|
||||
if (!InsertFile(filenm, &inctable[tok == FILESPECIFIER], &result))
|
||||
{
|
||||
if (do_preprocess)
|
||||
error("cannot open include file \"%s\"", filenm);
|
||||
else
|
||||
warning("cannot open include file \"%s\"", filenm);
|
||||
add_dependency(filenm);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
add_dependency(result);
|
||||
WorkingDir = getwdir(result);
|
||||
svnestlevel[++nestcount] = nestlevel;
|
||||
|
@ -332,22 +362,22 @@ do_include()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
do_define()
|
||||
void do_define()
|
||||
{
|
||||
/* do_define() interprets a #define control line.
|
||||
*/
|
||||
register char *str; /* the #defined identifier's descriptor */
|
||||
register char* str; /* the #defined identifier's descriptor */
|
||||
int nformals = -1; /* keep track of the number of formals */
|
||||
char *formals[NPARAMS]; /* pointers to the names of the formals */
|
||||
char* formals[NPARAMS]; /* pointers to the names of the formals */
|
||||
char parbuf[PARBUFSIZE]; /* names of formals */
|
||||
char *repl_text; /* start of the replacement text */
|
||||
char* repl_text; /* start of the replacement text */
|
||||
int length; /* length of the replacement text */
|
||||
register ch;
|
||||
char *get_text();
|
||||
char* get_text();
|
||||
|
||||
/* read the #defined macro's name */
|
||||
if (!(str = GetIdentifier(1))) {
|
||||
if (!(str = GetIdentifier(1)))
|
||||
{
|
||||
error("#define: illegal macro name");
|
||||
return;
|
||||
}
|
||||
|
@ -355,8 +385,10 @@ do_define()
|
|||
followed immediately by a '('.
|
||||
*/
|
||||
ch = GetChar();
|
||||
if (ch == '(') {
|
||||
if ((nformals = getparams(formals, parbuf)) == -1) {
|
||||
if (ch == '(')
|
||||
{
|
||||
if ((nformals = getparams(formals, parbuf)) == -1)
|
||||
{
|
||||
SkipToNewLine();
|
||||
free(str);
|
||||
return; /* an error occurred */
|
||||
|
@ -364,7 +396,7 @@ do_define()
|
|||
ch = GetChar();
|
||||
}
|
||||
/* read the replacement text if there is any */
|
||||
ch = skipspaces(ch,0); /* find first character of the text */
|
||||
ch = skipspaces(ch, 0); /* find first character of the text */
|
||||
assert(ch != EOI);
|
||||
/* UnGetChar() is not right when replacement starts with a '/' */
|
||||
ChPushBack(ch);
|
||||
|
@ -383,12 +415,15 @@ push_if()
|
|||
|
||||
do_elif()
|
||||
{
|
||||
if (nestlevel <= svnestlevel[nestcount]) {
|
||||
if (nestlevel <= svnestlevel[nestcount])
|
||||
{
|
||||
error("#elif without corresponding #if");
|
||||
SkipToNewLine();
|
||||
}
|
||||
else { /* restart at this level as if a #if is detected. */
|
||||
if (ifstack[nestlevel]) {
|
||||
else
|
||||
{ /* restart at this level as if a #if is detected. */
|
||||
if (ifstack[nestlevel])
|
||||
{
|
||||
error("#elif after #else");
|
||||
SkipToNewLine();
|
||||
}
|
||||
|
@ -400,14 +435,17 @@ do_elif()
|
|||
|
||||
do_else()
|
||||
{
|
||||
if (SkipToNewLine()) {
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
if (!options['o'])
|
||||
strict("garbage following #else");
|
||||
}
|
||||
if (nestlevel <= svnestlevel[nestcount])
|
||||
error("#else without corresponding #if");
|
||||
else { /* mark this level as else-d */
|
||||
if (ifstack[nestlevel]) {
|
||||
else
|
||||
{ /* mark this level as else-d */
|
||||
if (ifstack[nestlevel])
|
||||
{
|
||||
error("#else after #else");
|
||||
}
|
||||
++(ifstack[nestlevel]);
|
||||
|
@ -417,14 +455,17 @@ do_else()
|
|||
|
||||
do_endif()
|
||||
{
|
||||
if (SkipToNewLine()) {
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
if (!options['o'])
|
||||
strict("garbage following #endif");
|
||||
}
|
||||
if (nestlevel <= svnestlevel[nestcount]) {
|
||||
if (nestlevel <= svnestlevel[nestcount])
|
||||
{
|
||||
error("#endif without corresponding #if");
|
||||
}
|
||||
else nestlevel--;
|
||||
else
|
||||
nestlevel--;
|
||||
}
|
||||
|
||||
do_if()
|
||||
|
@ -436,23 +477,26 @@ do_if()
|
|||
|
||||
do_ifdef(how)
|
||||
{
|
||||
register struct idf *id;
|
||||
register char *str;
|
||||
register struct idf* id;
|
||||
register char* str;
|
||||
|
||||
/* how == 1 : ifdef; how == 0 : ifndef
|
||||
*/
|
||||
push_if();
|
||||
if (!(str = GetIdentifier(1))) {
|
||||
if (!(str = GetIdentifier(1)))
|
||||
{
|
||||
error("illegal #ifdef construction");
|
||||
id = (struct idf *)0;
|
||||
} else {
|
||||
id = (struct idf*)0;
|
||||
}
|
||||
else
|
||||
{
|
||||
id = findidf(str);
|
||||
free(str);
|
||||
}
|
||||
if (SkipToNewLine()) {
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
if (str && !options['o'])
|
||||
strict("garbage following #%s <identifier>",
|
||||
how ? "ifdef" : "ifndef");
|
||||
strict("garbage following #%s <identifier>", how ? "ifdef" : "ifndef");
|
||||
}
|
||||
|
||||
/* The next test is a shorthand for:
|
||||
|
@ -463,26 +507,32 @@ do_ifdef(how)
|
|||
}
|
||||
|
||||
/* argstr != NULL when the undef came from a -U option */
|
||||
do_undef(argstr)
|
||||
char *argstr;
|
||||
do_undef(argstr) char* argstr;
|
||||
{
|
||||
register struct idf *id;
|
||||
register char *str = argstr;
|
||||
register struct idf* id;
|
||||
register char* str = argstr;
|
||||
|
||||
/* Forget a macro definition. */
|
||||
if (str || (str = GetIdentifier(1))) {
|
||||
if ((id = findidf(str)) && id->id_macro) {
|
||||
if (id->id_macro->mc_flag & NOUNDEF) {
|
||||
if (str || (str = GetIdentifier(1)))
|
||||
{
|
||||
if ((id = findidf(str)) && id->id_macro)
|
||||
{
|
||||
if (id->id_macro->mc_flag & NOUNDEF)
|
||||
{
|
||||
error("it is not allowed to #undef %s", str);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
free(id->id_macro->mc_text);
|
||||
free_macro(id->id_macro);
|
||||
id->id_macro = (struct macro *) 0;
|
||||
id->id_macro = (struct macro*)0;
|
||||
}
|
||||
} /* else: don't complain */
|
||||
if (!argstr){
|
||||
if (!argstr)
|
||||
{
|
||||
free(str);
|
||||
if (SkipToNewLine()) {
|
||||
if (SkipToNewLine())
|
||||
{
|
||||
if (!options['o'])
|
||||
strict("garbage following #undef");
|
||||
}
|
||||
|
@ -495,18 +545,16 @@ do_undef(argstr)
|
|||
do_error()
|
||||
{
|
||||
int len;
|
||||
char *get_text();
|
||||
char *bp = get_text((char **) 0, &len);
|
||||
char* get_text();
|
||||
char* bp = get_text((char**)0, &len);
|
||||
|
||||
error("user error: %s", bp);
|
||||
free(bp);
|
||||
LineNumber++;
|
||||
}
|
||||
|
||||
int
|
||||
getparams(buf, parbuf)
|
||||
char *buf[];
|
||||
char parbuf[];
|
||||
int getparams(buf, parbuf) char* buf[];
|
||||
char parbuf[];
|
||||
{
|
||||
/* getparams() reads the formal parameter list of a macro
|
||||
definition.
|
||||
|
@ -518,19 +566,22 @@ getparams(buf, parbuf)
|
|||
Note that the '(' has already been eaten.
|
||||
The names of the formal parameters are stored into parbuf.
|
||||
*/
|
||||
register char **pbuf = &buf[0];
|
||||
register char** pbuf = &buf[0];
|
||||
register int c;
|
||||
register char *ptr = &parbuf[0];
|
||||
register char **pbuf2;
|
||||
register char* ptr = &parbuf[0];
|
||||
register char** pbuf2;
|
||||
|
||||
c = GetChar();
|
||||
c = skipspaces(c,0);
|
||||
if (c == ')') { /* no parameters: #define name() */
|
||||
*pbuf = (char *) 0;
|
||||
c = skipspaces(c, 0);
|
||||
if (c == ')')
|
||||
{ /* no parameters: #define name() */
|
||||
*pbuf = (char*)0;
|
||||
return 0;
|
||||
}
|
||||
for (;;) { /* eat the formal parameter list */
|
||||
if (class(c) != STIDF && class(c) != STELL) {
|
||||
for (;;)
|
||||
{ /* eat the formal parameter list */
|
||||
if (class(c) != STIDF && class(c) != STELL)
|
||||
{
|
||||
error("#define: bad formal parameter");
|
||||
return -1;
|
||||
}
|
||||
|
@ -538,7 +589,8 @@ getparams(buf, parbuf)
|
|||
*ptr++ = c;
|
||||
if (ptr >= &parbuf[PARBUFSIZE])
|
||||
fatal("formal parameter buffer overflow");
|
||||
do { /* eat the identifier name */
|
||||
do
|
||||
{ /* eat the identifier name */
|
||||
c = GetChar();
|
||||
*ptr++ = c;
|
||||
if (ptr >= &parbuf[PARBUFSIZE])
|
||||
|
@ -549,52 +601,61 @@ getparams(buf, parbuf)
|
|||
/* Check if this formal parameter is already used.
|
||||
Usually, macros do not have many parameters, so ...
|
||||
*/
|
||||
for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) {
|
||||
if (!strcmp(*pbuf2, *pbuf)) {
|
||||
warning("formal parameter \"%s\" already used",
|
||||
*pbuf);
|
||||
for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--)
|
||||
{
|
||||
if (!strcmp(*pbuf2, *pbuf))
|
||||
{
|
||||
warning("formal parameter \"%s\" already used", *pbuf);
|
||||
}
|
||||
}
|
||||
|
||||
pbuf++;
|
||||
c = skipspaces(c,0);
|
||||
if (c == ')') { /* end of the formal parameter list */
|
||||
*pbuf = (char *) 0;
|
||||
c = skipspaces(c, 0);
|
||||
if (c == ')')
|
||||
{ /* end of the formal parameter list */
|
||||
*pbuf = (char*)0;
|
||||
return pbuf - buf;
|
||||
}
|
||||
if (c != ',') {
|
||||
if (c != ',')
|
||||
{
|
||||
error("#define: bad formal parameter list");
|
||||
return -1;
|
||||
}
|
||||
c = GetChar();
|
||||
c = skipspaces(c,0);
|
||||
c = skipspaces(c, 0);
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
void
|
||||
macro_def(id, text, nformals, length, flags)
|
||||
register struct idf *id;
|
||||
char *text;
|
||||
void macro_def(id, text, nformals, length, flags) register struct idf* id;
|
||||
char* text;
|
||||
{
|
||||
register struct macro *newdef = id->id_macro;
|
||||
register struct macro* newdef = id->id_macro;
|
||||
|
||||
/* macro_def() puts the contents and information of a macro
|
||||
definition into a structure and stores it into the symbol
|
||||
table entry belonging to the name of the macro.
|
||||
An error is given if there was already a definition
|
||||
*/
|
||||
if (newdef) { /* is there a redefinition? */
|
||||
if (newdef->mc_flag & NOUNDEF) {
|
||||
if (newdef)
|
||||
{ /* is there a redefinition? */
|
||||
if (newdef->mc_flag & NOUNDEF)
|
||||
{
|
||||
error("it is not allowed to redefine %s", id->id_text);
|
||||
} else if (!macroeq(newdef->mc_text, text))
|
||||
}
|
||||
else if (!macroeq(newdef->mc_text, text))
|
||||
error("illegal redefine of \"%s\"", id->id_text);
|
||||
free(text);
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DOBITS
|
||||
register char *p = id->id_text;
|
||||
#define setbit(bx) if (!*p) goto go_on; bits[*p++] |= (bx)
|
||||
register char* p = id->id_text;
|
||||
#define setbit(bx) \
|
||||
if (!*p) \
|
||||
goto go_on; \
|
||||
bits[*p++] |= (bx)
|
||||
setbit(bit0);
|
||||
setbit(bit1);
|
||||
setbit(bit2);
|
||||
|
@ -614,15 +675,13 @@ macro_def(id, text, nformals, length, flags)
|
|||
newdef->mc_flag = flags; /* special flags */
|
||||
}
|
||||
|
||||
int
|
||||
find_name(nm, index)
|
||||
char *nm, *index[];
|
||||
int find_name(nm, index) char *nm, *index[];
|
||||
{
|
||||
/* find_name() returns the index of "nm" in the namelist
|
||||
"index" if it can be found there. 0 is returned if it is
|
||||
not there.
|
||||
*/
|
||||
register char **ip = &index[0];
|
||||
register char** ip = &index[0];
|
||||
|
||||
while (*ip)
|
||||
if (strcmp(nm, *ip++) == 0)
|
||||
|
@ -633,10 +692,8 @@ find_name(nm, index)
|
|||
|
||||
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
|
||||
|
||||
char *
|
||||
get_text(formals, length)
|
||||
char *formals[];
|
||||
int *length;
|
||||
char* get_text(formals, length) char* formals[];
|
||||
int* length;
|
||||
{
|
||||
/* get_text() copies the replacement text of a macro
|
||||
definition with zero, one or more parameters, thereby
|
||||
|
@ -662,104 +719,131 @@ get_text(formals, length)
|
|||
*/
|
||||
register int c;
|
||||
struct repl repls;
|
||||
register struct repl *repl = &repls;
|
||||
register struct repl* repl = &repls;
|
||||
int blank = 0;
|
||||
|
||||
c = GetChar();
|
||||
|
||||
repl->r_ptr = repl->r_text = Malloc((unsigned)(repl->r_size = ITEXTSIZE));
|
||||
*repl->r_ptr = '\0';
|
||||
while ((c != EOI) && (class(c) != STNL)) {
|
||||
if (BLANK(c)) {
|
||||
while ((c != EOI) && (class(c) != STNL))
|
||||
{
|
||||
if (BLANK(c))
|
||||
{
|
||||
blank++;
|
||||
c = GetChar();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\'' || c == '"') {
|
||||
if (c == '\'' || c == '"')
|
||||
{
|
||||
register int delim = c;
|
||||
|
||||
if (blank) {
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
do {
|
||||
do
|
||||
{
|
||||
add2repl(repl, c);
|
||||
if (c == '\\') add2repl(repl, GetChar());
|
||||
if (c == '\\')
|
||||
add2repl(repl, GetChar());
|
||||
c = GetChar();
|
||||
} while (c != delim && c != EOI && class(c) != STNL);
|
||||
if (c != delim) {
|
||||
if (c != delim)
|
||||
{
|
||||
strict("unclosed opening %c", delim);
|
||||
break;
|
||||
}
|
||||
add2repl(repl, c);
|
||||
c = GetChar();
|
||||
} else if (c == '/') {
|
||||
}
|
||||
else if (c == '/')
|
||||
{
|
||||
c = GetChar();
|
||||
if (c == '*') {
|
||||
if (c == '*')
|
||||
{
|
||||
skipcomment();
|
||||
blank++;
|
||||
c = GetChar();
|
||||
continue;
|
||||
}
|
||||
if (blank) {
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
add2repl(repl, '/');
|
||||
} else if (formals
|
||||
&& (class(c) == STIDF || class(c) == STELL)) {
|
||||
}
|
||||
else if (formals && (class(c) == STIDF || class(c) == STELL))
|
||||
{
|
||||
char id_buf[IDFSIZE + 1];
|
||||
register char *idp = id_buf;
|
||||
register char* idp = id_buf;
|
||||
int n;
|
||||
|
||||
/* read identifier: it may be a formal parameter */
|
||||
*idp++ = c;
|
||||
do {
|
||||
do
|
||||
{
|
||||
c = GetChar();
|
||||
if (idp <= &id_buf[IDFSIZE])
|
||||
*idp++ = c;
|
||||
} while (in_idf(c));
|
||||
*--idp = '\0';
|
||||
|
||||
if (blank) {
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
/* construct the formal parameter mark or identifier */
|
||||
if (n = find_name(id_buf, formals))
|
||||
add2repl(repl, FORMALP | (char) n);
|
||||
else {
|
||||
add2repl(repl, FORMALP | (char)n);
|
||||
else
|
||||
{
|
||||
idp = id_buf;
|
||||
while (*idp) add2repl(repl, *idp++);
|
||||
while (*idp)
|
||||
add2repl(repl, *idp++);
|
||||
}
|
||||
} else if (class(c) == STNUM) {
|
||||
if (blank) {
|
||||
}
|
||||
else if (class(c) == STNUM)
|
||||
{
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
add2repl(repl, c);
|
||||
if (c == '.') {
|
||||
if (c == '.')
|
||||
{
|
||||
c = GetChar();
|
||||
if (class(c) != STNUM) {
|
||||
if (class(c) != STNUM)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
add2repl(repl, c);
|
||||
}
|
||||
c = GetChar();
|
||||
while(in_idf(c) || c == '.') {
|
||||
while (in_idf(c) || c == '.')
|
||||
{
|
||||
add2repl(repl, c);
|
||||
if((c = GetChar()) == 'e' || c == 'E') {
|
||||
if ((c = GetChar()) == 'e' || c == 'E')
|
||||
{
|
||||
add2repl(repl, c);
|
||||
c = GetChar();
|
||||
if (c == '+' || c == '-') {
|
||||
if (c == '+' || c == '-')
|
||||
{
|
||||
add2repl(repl, c);
|
||||
c = GetChar();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (blank) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (blank)
|
||||
{
|
||||
blank = 0;
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
|
@ -768,7 +852,7 @@ get_text(formals, length)
|
|||
}
|
||||
}
|
||||
*length = repl->r_ptr - repl->r_text;
|
||||
return Realloc(repl->r_text, (unsigned)(repl->r_ptr - repl->r_text +1));
|
||||
return Realloc(repl->r_text, (unsigned)(repl->r_ptr - repl->r_text + 1));
|
||||
}
|
||||
|
||||
/* macroeq() decides whether two macro replacement texts are
|
||||
|
@ -776,36 +860,42 @@ get_text(formals, length)
|
|||
as strings, without taking care of the leading and trailing
|
||||
blanks (spaces and tabs).
|
||||
*/
|
||||
macroeq(s, t)
|
||||
register char *s, *t;
|
||||
macroeq(s, t) register char* s, *t;
|
||||
{
|
||||
|
||||
/* skip leading spaces */
|
||||
while (BLANK(*s)) s++;
|
||||
while (BLANK(*t)) t++;
|
||||
while (BLANK(*s))
|
||||
s++;
|
||||
while (BLANK(*t))
|
||||
t++;
|
||||
/* first non-blank encountered in both strings */
|
||||
/* The actual comparison loop: */
|
||||
while (*s && *s == *t)
|
||||
s++, t++;
|
||||
/* two cases are possible when arrived here: */
|
||||
if (*s == '\0') { /* *s == '\0' */
|
||||
while (BLANK(*t)) t++;
|
||||
if (*s == '\0')
|
||||
{ /* *s == '\0' */
|
||||
while (BLANK(*t))
|
||||
t++;
|
||||
return *t == '\0';
|
||||
}
|
||||
else { /* *s != *t */
|
||||
while (BLANK(*s)) s++;
|
||||
while (BLANK(*t)) t++;
|
||||
else
|
||||
{ /* *s != *t */
|
||||
while (BLANK(*s))
|
||||
s++;
|
||||
while (BLANK(*t))
|
||||
t++;
|
||||
return (*s == '\0') && (*t == '\0');
|
||||
}
|
||||
}
|
||||
|
||||
do_line(l)
|
||||
unsigned int l;
|
||||
do_line(l) unsigned int l;
|
||||
{
|
||||
struct token tk;
|
||||
int t = GetToken(&tk);
|
||||
|
||||
if (t != EOF) SkipToNewLine();
|
||||
if (t != EOF)
|
||||
SkipToNewLine();
|
||||
LineNumber = l; /* the number of the next input line */
|
||||
if (t == STRING) /* is there a filespecifier? */
|
||||
FileName = tk.tk_str;
|
||||
|
|
Loading…
Reference in a new issue