Run files through clang-format before editing.
This commit is contained in:
parent
fa1ba55ad2
commit
dd00b81080
2 changed files with 928 additions and 757 deletions
|
@ -38,9 +38,7 @@ int nestlevel = -1;
|
||||||
void macro_def();
|
void macro_def();
|
||||||
void do_define();
|
void do_define();
|
||||||
|
|
||||||
struct idf *
|
struct idf* GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on error */
|
||||||
GetIdentifier(skiponerr)
|
|
||||||
int skiponerr; /* skip the rest of the line on error */
|
|
||||||
{
|
{
|
||||||
/* returns a pointer to the descriptor of the identifier that is
|
/* returns a pointer to the descriptor of the identifier that is
|
||||||
read from the input stream. When the input doe not contain
|
read from the input stream. When the input doe not contain
|
||||||
|
@ -56,8 +54,10 @@ GetIdentifier(skiponerr)
|
||||||
tok = GetToken(&tk);
|
tok = GetToken(&tk);
|
||||||
ReplaceMacros = 1;
|
ReplaceMacros = 1;
|
||||||
UnknownIdIsZero = tmp;
|
UnknownIdIsZero = tmp;
|
||||||
if (tok != IDENTIFIER) {
|
if (tok != IDENTIFIER)
|
||||||
if (skiponerr && tok != EOI) SkipToNewLine();
|
{
|
||||||
|
if (skiponerr && tok != EOI)
|
||||||
|
SkipToNewLine();
|
||||||
return (struct idf*)0;
|
return (struct idf*)0;
|
||||||
}
|
}
|
||||||
return tk.tk_idf;
|
return tk.tk_idf;
|
||||||
|
@ -80,9 +80,11 @@ domacro()
|
||||||
ReplaceMacros = 0;
|
ReplaceMacros = 0;
|
||||||
toknum = GetToken(&tk);
|
toknum = GetToken(&tk);
|
||||||
ReplaceMacros = 1;
|
ReplaceMacros = 1;
|
||||||
switch(toknum) { /* select control line action */
|
switch (toknum)
|
||||||
|
{ /* select control line action */
|
||||||
case IDENTIFIER: /* is it a macro keyword? */
|
case IDENTIFIER: /* is it a macro keyword? */
|
||||||
switch (tk.tk_idf->id_resmac) {
|
switch (tk.tk_idf->id_resmac)
|
||||||
|
{
|
||||||
case K_DEFINE: /* "define" */
|
case K_DEFINE: /* "define" */
|
||||||
do_define();
|
do_define();
|
||||||
break;
|
break;
|
||||||
|
@ -111,7 +113,8 @@ domacro()
|
||||||
/* set LineNumber and FileName according to
|
/* set LineNumber and FileName according to
|
||||||
the arguments.
|
the arguments.
|
||||||
*/
|
*/
|
||||||
if (GetToken(&tk) != INTEGER) {
|
if (GetToken(&tk) != INTEGER)
|
||||||
|
{
|
||||||
lexerror("bad #line syntax");
|
lexerror("bad #line syntax");
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
}
|
}
|
||||||
|
@ -149,9 +152,7 @@ domacro()
|
||||||
int lint_skip_comment;
|
int lint_skip_comment;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void skip_block(to_endif) int to_endif;
|
||||||
skip_block(to_endif)
|
|
||||||
int to_endif;
|
|
||||||
{
|
{
|
||||||
/* skip_block() skips the input from
|
/* skip_block() skips the input from
|
||||||
1) a false #if, #ifdef, #ifndef or #elif until the
|
1) a false #if, #ifdef, #ifndef or #elif until the
|
||||||
|
@ -170,12 +171,15 @@ int to_endif;
|
||||||
lint_skip_comment++;
|
lint_skip_comment++;
|
||||||
#endif
|
#endif
|
||||||
NoUnstack++;
|
NoUnstack++;
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
ch = GetChar(); /* read first character after newline */
|
ch = GetChar(); /* read first character after newline */
|
||||||
while (class(ch) == STSKIP)
|
while (class(ch) == STSKIP)
|
||||||
ch = GetChar();
|
ch = GetChar();
|
||||||
if (ch != '#') {
|
if (ch != '#')
|
||||||
if (ch == EOI) {
|
{
|
||||||
|
if (ch == EOI)
|
||||||
|
{
|
||||||
NoUnstack--;
|
NoUnstack--;
|
||||||
#ifdef LINT
|
#ifdef LINT
|
||||||
lint_skip_comment--;
|
lint_skip_comment--;
|
||||||
|
@ -183,22 +187,29 @@ int to_endif;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* A possible '/' is not pushed back */
|
/* A possible '/' is not pushed back */
|
||||||
if (ch == '/') {
|
if (ch == '/')
|
||||||
|
{
|
||||||
ch = GetChar();
|
ch = GetChar();
|
||||||
if (ch != '*') UnGetChar();
|
if (ch != '*')
|
||||||
else {
|
UnGetChar();
|
||||||
|
else
|
||||||
|
{
|
||||||
skipcomment();
|
skipcomment();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else UnGetChar();
|
}
|
||||||
|
else
|
||||||
|
UnGetChar();
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ReplaceMacros = 0;
|
ReplaceMacros = 0;
|
||||||
toknum = GetToken(&tk);
|
toknum = GetToken(&tk);
|
||||||
ReplaceMacros = 1;
|
ReplaceMacros = 1;
|
||||||
if (toknum != IDENTIFIER) {
|
if (toknum != IDENTIFIER)
|
||||||
if (toknum != INTEGER) {
|
{
|
||||||
|
if (toknum != INTEGER)
|
||||||
|
{
|
||||||
lexerror("illegal # line");
|
lexerror("illegal # line");
|
||||||
}
|
}
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
|
@ -209,7 +220,8 @@ int to_endif;
|
||||||
Interpret #else, #elif and #endif if they occur
|
Interpret #else, #elif and #endif if they occur
|
||||||
on the same level.
|
on the same level.
|
||||||
*/
|
*/
|
||||||
switch(tk.tk_idf->id_resmac) {
|
switch (tk.tk_idf->id_resmac)
|
||||||
|
{
|
||||||
default:
|
default:
|
||||||
case K_UNKNOWN:
|
case K_UNKNOWN:
|
||||||
/* invalid word seen after the '#' */
|
/* invalid word seen after the '#' */
|
||||||
|
@ -233,10 +245,12 @@ int to_endif;
|
||||||
case K_ELIF:
|
case K_ELIF:
|
||||||
if (ifstack[nestlevel])
|
if (ifstack[nestlevel])
|
||||||
lexerror("#elif after #else");
|
lexerror("#elif after #else");
|
||||||
if (!to_endif && nestlevel == skiplevel) {
|
if (!to_endif && nestlevel == skiplevel)
|
||||||
|
{
|
||||||
nestlevel--;
|
nestlevel--;
|
||||||
push_if();
|
push_if();
|
||||||
if (ifexpr()) {
|
if (ifexpr())
|
||||||
|
{
|
||||||
NoUnstack--;
|
NoUnstack--;
|
||||||
#ifdef LINT
|
#ifdef LINT
|
||||||
lint_skip_comment--;
|
lint_skip_comment--;
|
||||||
|
@ -244,14 +258,17 @@ int to_endif;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else SkipToNewLine(); /* otherwise done in ifexpr() */
|
else
|
||||||
|
SkipToNewLine(); /* otherwise done in ifexpr() */
|
||||||
break;
|
break;
|
||||||
case K_ELSE:
|
case K_ELSE:
|
||||||
if (ifstack[nestlevel])
|
if (ifstack[nestlevel])
|
||||||
lexerror("#else after #else");
|
lexerror("#else after #else");
|
||||||
++(ifstack[nestlevel]);
|
++(ifstack[nestlevel]);
|
||||||
if (!to_endif && nestlevel == skiplevel) {
|
if (!to_endif && nestlevel == skiplevel)
|
||||||
if (SkipToNewLine()) {
|
{
|
||||||
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
lexstrict("garbage following #else");
|
lexstrict("garbage following #else");
|
||||||
}
|
}
|
||||||
|
@ -261,12 +278,15 @@ int to_endif;
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else SkipToNewLine();
|
else
|
||||||
|
SkipToNewLine();
|
||||||
break;
|
break;
|
||||||
case K_ENDIF:
|
case K_ENDIF:
|
||||||
assert(nestlevel > nestlow);
|
assert(nestlevel > nestlow);
|
||||||
if (nestlevel == skiplevel) {
|
if (nestlevel == skiplevel)
|
||||||
if (SkipToNewLine()) {
|
{
|
||||||
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
lexstrict("garbage following #endif");
|
lexstrict("garbage following #endif");
|
||||||
}
|
}
|
||||||
|
@ -277,14 +297,14 @@ int to_endif;
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else SkipToNewLine();
|
else
|
||||||
|
SkipToNewLine();
|
||||||
nestlevel--;
|
nestlevel--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ifexpr()
|
ifexpr()
|
||||||
{
|
{
|
||||||
/* ifexpr() returns whether the restricted constant
|
/* ifexpr() returns whether the restricted constant
|
||||||
|
@ -319,22 +339,27 @@ do_include()
|
||||||
AccFileSpecifier = 1;
|
AccFileSpecifier = 1;
|
||||||
if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING)
|
if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING)
|
||||||
filenm = tk.tk_bts;
|
filenm = tk.tk_bts;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
lexerror("bad include syntax");
|
lexerror("bad include syntax");
|
||||||
filenm = (char*)0;
|
filenm = (char*)0;
|
||||||
}
|
}
|
||||||
AccFileSpecifier = 0;
|
AccFileSpecifier = 0;
|
||||||
if (SkipToNewLine()) {
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
lexerror("bad include syntax");
|
lexerror("bad include syntax");
|
||||||
}
|
}
|
||||||
inctable[0] = WorkingDir;
|
inctable[0] = WorkingDir;
|
||||||
if (filenm) {
|
if (filenm)
|
||||||
if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){
|
{
|
||||||
|
if (!InsertFile(filenm, &inctable[tok == FILESPECIFIER], &result))
|
||||||
|
{
|
||||||
lexerror("cannot open include file \"%s\"", filenm);
|
lexerror("cannot open include file \"%s\"", filenm);
|
||||||
add_dependency(filenm);
|
add_dependency(filenm);
|
||||||
free(filenm);
|
free(filenm);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
add_dependency(result);
|
add_dependency(result);
|
||||||
WorkingDir = getwdir(result);
|
WorkingDir = getwdir(result);
|
||||||
File_Inserted = 1;
|
File_Inserted = 1;
|
||||||
|
@ -343,17 +368,18 @@ do_include()
|
||||||
nestlow = nestlevel;
|
nestlow = nestlevel;
|
||||||
#ifdef DBSYMTAB
|
#ifdef DBSYMTAB
|
||||||
IncludeLevel++;
|
IncludeLevel++;
|
||||||
if (options['g']) {
|
if (options['g'])
|
||||||
|
{
|
||||||
C_ms_stb_cst(FileName, N_BINCL, 0, (arith)0);
|
C_ms_stb_cst(FileName, N_BINCL, 0, (arith)0);
|
||||||
}
|
}
|
||||||
#endif /* DBSYMTAB */
|
#endif /* DBSYMTAB */
|
||||||
if (result != filenm) free(filenm);
|
if (result != filenm)
|
||||||
|
free(filenm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void do_define()
|
||||||
do_define()
|
|
||||||
{
|
{
|
||||||
/* do_define() interprets a #define control line.
|
/* do_define() interprets a #define control line.
|
||||||
*/
|
*/
|
||||||
|
@ -367,7 +393,8 @@ do_define()
|
||||||
char* get_text();
|
char* get_text();
|
||||||
|
|
||||||
/* read the #defined macro's name */
|
/* read the #defined macro's name */
|
||||||
if (!(id = GetIdentifier(1))) {
|
if (!(id = GetIdentifier(1)))
|
||||||
|
{
|
||||||
lexerror("illegal #define line");
|
lexerror("illegal #define line");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -375,8 +402,10 @@ do_define()
|
||||||
followed immediately by a '('.
|
followed immediately by a '('.
|
||||||
*/
|
*/
|
||||||
ch = GetChar();
|
ch = GetChar();
|
||||||
if (ch == '(') {
|
if (ch == '(')
|
||||||
if ((nformals = getparams(formals, parbuf)) == -1) {
|
{
|
||||||
|
if ((nformals = getparams(formals, parbuf)) == -1)
|
||||||
|
{
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
return; /* an error occurred */
|
return; /* an error occurred */
|
||||||
}
|
}
|
||||||
|
@ -402,12 +431,15 @@ push_if()
|
||||||
|
|
||||||
do_elif()
|
do_elif()
|
||||||
{
|
{
|
||||||
if (nestlevel <= nestlow) {
|
if (nestlevel <= nestlow)
|
||||||
|
{
|
||||||
lexerror("#elif without corresponding #if");
|
lexerror("#elif without corresponding #if");
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
}
|
}
|
||||||
else { /* restart at this level as if a #if is detected. */
|
else
|
||||||
if (ifstack[nestlevel]) {
|
{ /* restart at this level as if a #if is detected. */
|
||||||
|
if (ifstack[nestlevel])
|
||||||
|
{
|
||||||
lexerror("#elif after #else");
|
lexerror("#elif after #else");
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
}
|
}
|
||||||
|
@ -424,8 +456,10 @@ do_else()
|
||||||
lexstrict("garbage following #else");
|
lexstrict("garbage following #else");
|
||||||
if (nestlevel <= nestlow)
|
if (nestlevel <= nestlow)
|
||||||
lexerror("#else without corresponding #if");
|
lexerror("#else without corresponding #if");
|
||||||
else { /* mark this level as else-d */
|
else
|
||||||
if (ifstack[nestlevel]) {
|
{ /* mark this level as else-d */
|
||||||
|
if (ifstack[nestlevel])
|
||||||
|
{
|
||||||
lexerror("#else after #else");
|
lexerror("#else after #else");
|
||||||
}
|
}
|
||||||
++(ifstack[nestlevel]);
|
++(ifstack[nestlevel]);
|
||||||
|
@ -435,14 +469,17 @@ do_else()
|
||||||
|
|
||||||
do_endif()
|
do_endif()
|
||||||
{
|
{
|
||||||
if (SkipToNewLine()) {
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
lexstrict("garbage following #endif");
|
lexstrict("garbage following #endif");
|
||||||
}
|
}
|
||||||
if (nestlevel <= nestlow) {
|
if (nestlevel <= nestlow)
|
||||||
|
{
|
||||||
lexerror("#endif without corresponding #if");
|
lexerror("#endif without corresponding #if");
|
||||||
}
|
}
|
||||||
else nestlevel--;
|
else
|
||||||
|
nestlevel--;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_if()
|
do_if()
|
||||||
|
@ -463,8 +500,7 @@ do_ifdef(how)
|
||||||
lexerror("illegal #ifdef construction");
|
lexerror("illegal #ifdef construction");
|
||||||
else if (SkipToNewLine())
|
else if (SkipToNewLine())
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
lexstrict("garbage following #%s <identifier>",
|
lexstrict("garbage following #%s <identifier>", how ? "ifdef" : "ifndef");
|
||||||
how ? "ifdef" : "ifndef");
|
|
||||||
|
|
||||||
/* The next test is a shorthand for:
|
/* The next test is a shorthand for:
|
||||||
(how && !id->id_macro) || (!how && id->id_macro)
|
(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 */
|
/* argidf != NULL when the undef came from a -U option */
|
||||||
do_undef(argidf)
|
do_undef(argidf) struct idf* argidf;
|
||||||
struct idf *argidf;
|
|
||||||
{
|
{
|
||||||
register struct idf* id = argidf;
|
register struct idf* id = argidf;
|
||||||
|
|
||||||
/* Forget a macro definition. */
|
/* Forget a macro definition. */
|
||||||
if (id || (id = GetIdentifier(1))) {
|
if (id || (id = GetIdentifier(1)))
|
||||||
if (id->id_macro) { /* forget the macro */
|
{
|
||||||
if (id->id_macro->mc_flag & NOUNDEF) {
|
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);
|
lexerror("it is not allowed to undef %s", id->id_text);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
free(id->id_macro->mc_text);
|
free(id->id_macro->mc_text);
|
||||||
free_macro(id->id_macro);
|
free_macro(id->id_macro);
|
||||||
id->id_macro = (struct macro*)0;
|
id->id_macro = (struct macro*)0;
|
||||||
}
|
}
|
||||||
} /* else: don't complain */
|
} /* else: don't complain */
|
||||||
if (!argidf) {
|
if (!argidf)
|
||||||
|
{
|
||||||
if (SkipToNewLine())
|
if (SkipToNewLine())
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
lexstrict("garbage following #undef");
|
lexstrict("garbage following #undef");
|
||||||
|
@ -511,9 +552,7 @@ do_error()
|
||||||
LineNumber++;
|
LineNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int getparams(buf, parbuf) char* buf[];
|
||||||
getparams(buf, parbuf)
|
|
||||||
char *buf[];
|
|
||||||
char parbuf[];
|
char parbuf[];
|
||||||
{
|
{
|
||||||
/* getparams() reads the formal parameter list of a macro
|
/* getparams() reads the formal parameter list of a macro
|
||||||
|
@ -533,12 +572,15 @@ getparams(buf, parbuf)
|
||||||
|
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
c = skipspaces(c, 0);
|
c = skipspaces(c, 0);
|
||||||
if (c == ')') { /* no parameters: #define name() */
|
if (c == ')')
|
||||||
|
{ /* no parameters: #define name() */
|
||||||
*pbuf = (char*)0;
|
*pbuf = (char*)0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (;;) { /* eat the formal parameter list */
|
for (;;)
|
||||||
if (class(c) != STIDF && class(c) != STELL) {
|
{ /* eat the formal parameter list */
|
||||||
|
if (class(c) != STIDF && class(c) != STELL)
|
||||||
|
{
|
||||||
lexerror("#define: bad formal parameter");
|
lexerror("#define: bad formal parameter");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -546,7 +588,8 @@ getparams(buf, parbuf)
|
||||||
*ptr++ = c;
|
*ptr++ = c;
|
||||||
if (ptr >= &parbuf[PARBUFSIZE])
|
if (ptr >= &parbuf[PARBUFSIZE])
|
||||||
fatal("formal parameter buffer overflow");
|
fatal("formal parameter buffer overflow");
|
||||||
do { /* eat the identifier name */
|
do
|
||||||
|
{ /* eat the identifier name */
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
*ptr++ = c;
|
*ptr++ = c;
|
||||||
if (ptr >= &parbuf[PARBUFSIZE])
|
if (ptr >= &parbuf[PARBUFSIZE])
|
||||||
|
@ -557,20 +600,23 @@ getparams(buf, parbuf)
|
||||||
/* Check if this formal parameter is already used.
|
/* Check if this formal parameter is already used.
|
||||||
Usually, macros do not have many parameters, so ...
|
Usually, macros do not have many parameters, so ...
|
||||||
*/
|
*/
|
||||||
for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) {
|
for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--)
|
||||||
if (!strcmp(*pbuf2, *pbuf)) {
|
{
|
||||||
lexerror("formal parameter \"%s\" already used",
|
if (!strcmp(*pbuf2, *pbuf))
|
||||||
*pbuf);
|
{
|
||||||
|
lexerror("formal parameter \"%s\" already used", *pbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pbuf++;
|
pbuf++;
|
||||||
c = skipspaces(c, 0);
|
c = skipspaces(c, 0);
|
||||||
if (c == ')') { /* end of the formal parameter list */
|
if (c == ')')
|
||||||
|
{ /* end of the formal parameter list */
|
||||||
*pbuf = (char*)0;
|
*pbuf = (char*)0;
|
||||||
return pbuf - buf;
|
return pbuf - buf;
|
||||||
}
|
}
|
||||||
if (c != ',') {
|
if (c != ',')
|
||||||
|
{
|
||||||
lexerror("#define: bad formal parameter list");
|
lexerror("#define: bad formal parameter list");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -580,9 +626,7 @@ getparams(buf, parbuf)
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void macro_def(id, text, nformals, length, flags) register struct idf* id;
|
||||||
macro_def(id, text, nformals, length, flags)
|
|
||||||
register struct idf *id;
|
|
||||||
char* text;
|
char* text;
|
||||||
{
|
{
|
||||||
register struct macro* newdef = id->id_macro;
|
register struct macro* newdef = id->id_macro;
|
||||||
|
@ -592,10 +636,13 @@ macro_def(id, text, nformals, length, flags)
|
||||||
table entry belonging to the name of the macro.
|
table entry belonging to the name of the macro.
|
||||||
An error is given if there was already a definition
|
An error is given if there was already a definition
|
||||||
*/
|
*/
|
||||||
if (newdef) { /* is there a redefinition? */
|
if (newdef)
|
||||||
if (newdef->mc_flag & NOUNDEF) {
|
{ /* is there a redefinition? */
|
||||||
|
if (newdef->mc_flag & NOUNDEF)
|
||||||
|
{
|
||||||
lexerror("it is not allowed to redefine %s", id->id_text);
|
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);
|
lexerror("illegal redefine of \"%s\"", id->id_text);
|
||||||
free(text);
|
free(text);
|
||||||
return;
|
return;
|
||||||
|
@ -607,9 +654,7 @@ macro_def(id, text, nformals, length, flags)
|
||||||
newdef->mc_flag = flags; /* special flags */
|
newdef->mc_flag = flags; /* special flags */
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int find_name(nm, index) char *nm, *index[];
|
||||||
find_name(nm, index)
|
|
||||||
char *nm, *index[];
|
|
||||||
{
|
{
|
||||||
/* find_name() returns the index of "nm" in the namelist
|
/* find_name() returns the index of "nm" in the namelist
|
||||||
"index" if it can be found there. 0 is returned if it is
|
"index" if it can be found there. 0 is returned if it is
|
||||||
|
@ -626,9 +671,7 @@ find_name(nm, index)
|
||||||
|
|
||||||
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
|
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
|
||||||
|
|
||||||
char *
|
char* get_text(formals, length) char* formals[];
|
||||||
get_text(formals, length)
|
|
||||||
char *formals[];
|
|
||||||
int* length;
|
int* length;
|
||||||
{
|
{
|
||||||
/* get_text() copies the replacement text of a macro
|
/* get_text() copies the replacement text of a macro
|
||||||
|
@ -662,97 +705,124 @@ get_text(formals, length)
|
||||||
|
|
||||||
repl->r_ptr = repl->r_text = Malloc(repl->r_size = ITEXTSIZE);
|
repl->r_ptr = repl->r_text = Malloc(repl->r_size = ITEXTSIZE);
|
||||||
*repl->r_ptr = '\0';
|
*repl->r_ptr = '\0';
|
||||||
while ((c != EOI) && (class(c) != STNL)) {
|
while ((c != EOI) && (class(c) != STNL))
|
||||||
if (BLANK(c)) {
|
{
|
||||||
|
if (BLANK(c))
|
||||||
|
{
|
||||||
blank++;
|
blank++;
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == '\'' || c == '"') {
|
if (c == '\'' || c == '"')
|
||||||
|
{
|
||||||
register int delim = c;
|
register int delim = c;
|
||||||
|
|
||||||
if (blank) {
|
if (blank)
|
||||||
|
{
|
||||||
blank = 0;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
if (c == '\\') add2repl(repl, GetChar());
|
if (c == '\\')
|
||||||
|
add2repl(repl, GetChar());
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
} while (c != delim && c != EOI && class(c) != STNL);
|
} 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);
|
lexstrict("unclosed opening %c", delim);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
} else if (c == '/') {
|
}
|
||||||
|
else if (c == '/')
|
||||||
|
{
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
if (c == '*') {
|
if (c == '*')
|
||||||
|
{
|
||||||
skipcomment();
|
skipcomment();
|
||||||
blank++;
|
blank++;
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (blank) {
|
if (blank)
|
||||||
|
{
|
||||||
blank = 0;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
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];
|
char id_buf[IDFSIZE + 1];
|
||||||
register char* idp = id_buf;
|
register char* idp = id_buf;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
/* read identifier: it may be a formal parameter */
|
/* read identifier: it may be a formal parameter */
|
||||||
*idp++ = c;
|
*idp++ = c;
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
if (idp <= &id_buf[IDFSIZE])
|
if (idp <= &id_buf[IDFSIZE])
|
||||||
*idp++ = c;
|
*idp++ = c;
|
||||||
} while (in_idf(c));
|
} while (in_idf(c));
|
||||||
*--idp = '\0';
|
*--idp = '\0';
|
||||||
|
|
||||||
if (blank) {
|
if (blank)
|
||||||
|
{
|
||||||
blank = 0;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
/* construct the formal parameter mark or identifier */
|
/* construct the formal parameter mark or identifier */
|
||||||
if (n = find_name(id_buf, formals))
|
if (n = find_name(id_buf, formals))
|
||||||
add2repl(repl, FORMALP | (char)n);
|
add2repl(repl, FORMALP | (char)n);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
idp = id_buf;
|
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;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
if (c == '.') {
|
if (c == '.')
|
||||||
|
{
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
if (class(c) != STNUM) {
|
if (class(c) != STNUM)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
}
|
}
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
while(in_idf(c) || c == '.') {
|
while (in_idf(c) || c == '.')
|
||||||
|
{
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
if((c = GetChar()) == 'e' || c == 'E') {
|
if ((c = GetChar()) == 'e' || c == 'E')
|
||||||
|
{
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
if (c == '+' || c == '-') {
|
if (c == '+' || c == '-')
|
||||||
|
{
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (blank) {
|
else
|
||||||
|
{
|
||||||
|
if (blank)
|
||||||
|
{
|
||||||
blank = 0;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
|
@ -769,33 +839,37 @@ get_text(formals, length)
|
||||||
as strings, without taking care of the leading and trailing
|
as strings, without taking care of the leading and trailing
|
||||||
blanks (spaces and tabs).
|
blanks (spaces and tabs).
|
||||||
*/
|
*/
|
||||||
macroeq(s, t)
|
macroeq(s, t) register char* s, *t;
|
||||||
register char *s, *t;
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/* skip leading spaces */
|
/* skip leading spaces */
|
||||||
while (BLANK(*s)) s++;
|
while (BLANK(*s))
|
||||||
while (BLANK(*t)) t++;
|
s++;
|
||||||
|
while (BLANK(*t))
|
||||||
|
t++;
|
||||||
/* first non-blank encountered in both strings */
|
/* first non-blank encountered in both strings */
|
||||||
/* The actual comparison loop: */
|
/* The actual comparison loop: */
|
||||||
while (*s && *s == *t)
|
while (*s && *s == *t)
|
||||||
s++, t++;
|
s++, t++;
|
||||||
/* two cases are possible when arrived here: */
|
/* two cases are possible when arrived here: */
|
||||||
if (*s == '\0') { /* *s == '\0' */
|
if (*s == '\0')
|
||||||
while (BLANK(*t)) t++;
|
{ /* *s == '\0' */
|
||||||
|
while (BLANK(*t))
|
||||||
|
t++;
|
||||||
return *t == '\0';
|
return *t == '\0';
|
||||||
}
|
}
|
||||||
else { /* *s != *t */
|
else
|
||||||
while (BLANK(*s)) s++;
|
{ /* *s != *t */
|
||||||
while (BLANK(*t)) t++;
|
while (BLANK(*s))
|
||||||
|
s++;
|
||||||
|
while (BLANK(*t))
|
||||||
|
t++;
|
||||||
return (*s == '\0') && (*t == '\0');
|
return (*s == '\0') && (*t == '\0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else /* NOPP */
|
#else /* NOPP */
|
||||||
|
|
||||||
struct idf *
|
struct idf* GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on error */
|
||||||
GetIdentifier(skiponerr)
|
|
||||||
int skiponerr; /* skip the rest of the line on error */
|
|
||||||
{
|
{
|
||||||
/* returns a pointer to the descriptor of the identifier that is
|
/* returns a pointer to the descriptor of the identifier that is
|
||||||
read from the input stream. When the input does not contain
|
read from the input stream. When the input does not contain
|
||||||
|
@ -807,8 +881,10 @@ GetIdentifier(skiponerr)
|
||||||
struct token tk;
|
struct token tk;
|
||||||
|
|
||||||
tok = GetToken(&tk);
|
tok = GetToken(&tk);
|
||||||
if (tok != IDENTIFIER) {
|
if (tok != IDENTIFIER)
|
||||||
if (skiponerr && tok != EOI) SkipToNewLine();
|
{
|
||||||
|
if (skiponerr && tok != EOI)
|
||||||
|
SkipToNewLine();
|
||||||
return (struct idf*)0;
|
return (struct idf*)0;
|
||||||
}
|
}
|
||||||
return tk.tk_idf;
|
return tk.tk_idf;
|
||||||
|
@ -820,13 +896,17 @@ domacro()
|
||||||
struct token tk;
|
struct token tk;
|
||||||
|
|
||||||
EoiForNewline = 1;
|
EoiForNewline = 1;
|
||||||
if ((tok = GetToken(&tk)) == IDENTIFIER) {
|
if ((tok = GetToken(&tk)) == IDENTIFIER)
|
||||||
if (! strcmp(tk.tk_idf->id_text, "pragma")) {
|
{
|
||||||
|
if (!strcmp(tk.tk_idf->id_text, "pragma"))
|
||||||
|
{
|
||||||
do_pragma();
|
do_pragma();
|
||||||
EoiForNewline = 0;
|
EoiForNewline = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (tok == INTEGER) {
|
}
|
||||||
|
else if (tok == INTEGER)
|
||||||
|
{
|
||||||
do_line((unsigned int)tk.tk_ival);
|
do_line((unsigned int)tk.tk_ival);
|
||||||
EoiForNewline = 0;
|
EoiForNewline = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -837,22 +917,23 @@ domacro()
|
||||||
}
|
}
|
||||||
#endif /* NOPP */
|
#endif /* NOPP */
|
||||||
|
|
||||||
|
do_line(l) unsigned int l;
|
||||||
do_line(l)
|
|
||||||
unsigned int l;
|
|
||||||
{
|
{
|
||||||
struct token tk;
|
struct token tk;
|
||||||
int t = GetToken(&tk);
|
int t = GetToken(&tk);
|
||||||
|
|
||||||
if (t != EOI) SkipToNewLine();
|
if (t != EOI)
|
||||||
|
SkipToNewLine();
|
||||||
LineNumber = l; /* the number of the next input line */
|
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
|
* Do not attempt to free the old string, since it might
|
||||||
* be used in a def structure.
|
* be used in a def structure.
|
||||||
*/
|
*/
|
||||||
#ifdef DBSYMTAB
|
#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);
|
C_ms_std(tk.tk_bts, N_SOL, 0);
|
||||||
}
|
}
|
||||||
#endif /* DBSYMTAB */
|
#endif /* DBSYMTAB */
|
||||||
|
|
|
@ -36,9 +36,7 @@ extern int do_preprocess;
|
||||||
void macro_def();
|
void macro_def();
|
||||||
void do_define();
|
void do_define();
|
||||||
|
|
||||||
char *
|
char* GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on error */
|
||||||
GetIdentifier(skiponerr)
|
|
||||||
int skiponerr; /* skip the rest of the line on error */
|
|
||||||
{
|
{
|
||||||
/* Returns a pointer to the identifier that is read from the
|
/* Returns a pointer to the identifier that is read from the
|
||||||
input stream. When the input does not contain an
|
input stream. When the input does not contain an
|
||||||
|
@ -55,8 +53,10 @@ GetIdentifier(skiponerr)
|
||||||
tok = GetToken(&tk);
|
tok = GetToken(&tk);
|
||||||
ReplaceMacros = 1;
|
ReplaceMacros = 1;
|
||||||
UnknownIdIsZero = tmp;
|
UnknownIdIsZero = tmp;
|
||||||
if (tok != IDENTIFIER) {
|
if (tok != IDENTIFIER)
|
||||||
if (skiponerr && tok != EOF) SkipToNewLine();
|
{
|
||||||
|
if (skiponerr && tok != EOF)
|
||||||
|
SkipToNewLine();
|
||||||
return (char*)0;
|
return (char*)0;
|
||||||
}
|
}
|
||||||
return tk.tk_str;
|
return tk.tk_str;
|
||||||
|
@ -80,17 +80,20 @@ domacro()
|
||||||
ReplaceMacros = 0;
|
ReplaceMacros = 0;
|
||||||
toknum = GetToken(&tk);
|
toknum = GetToken(&tk);
|
||||||
ReplaceMacros = 1;
|
ReplaceMacros = 1;
|
||||||
switch(toknum) { /* select control line action */
|
switch (toknum)
|
||||||
|
{ /* select control line action */
|
||||||
case IDENTIFIER: /* is it a macro keyword? */
|
case IDENTIFIER: /* is it a macro keyword? */
|
||||||
id = findidf(tk.tk_str);
|
id = findidf(tk.tk_str);
|
||||||
if (!id) {
|
if (!id)
|
||||||
|
{
|
||||||
error("%s: unknown control", tk.tk_str);
|
error("%s: unknown control", tk.tk_str);
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
free(tk.tk_str);
|
free(tk.tk_str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(tk.tk_str);
|
free(tk.tk_str);
|
||||||
switch (id->id_resmac) {
|
switch (id->id_resmac)
|
||||||
|
{
|
||||||
case K_DEFINE: /* "define" */
|
case K_DEFINE: /* "define" */
|
||||||
do_define();
|
do_define();
|
||||||
break;
|
break;
|
||||||
|
@ -119,7 +122,8 @@ domacro()
|
||||||
/* set LineNumber and FileName according to
|
/* set LineNumber and FileName according to
|
||||||
the arguments.
|
the arguments.
|
||||||
*/
|
*/
|
||||||
if (GetToken(&tk) != INTEGER) {
|
if (GetToken(&tk) != INTEGER)
|
||||||
|
{
|
||||||
error("bad #line syntax");
|
error("bad #line syntax");
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
}
|
}
|
||||||
|
@ -152,9 +156,7 @@ domacro()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void skip_block(to_endif) int to_endif;
|
||||||
skip_block(to_endif)
|
|
||||||
int to_endif;
|
|
||||||
{
|
{
|
||||||
/* skip_block() skips the input from
|
/* skip_block() skips the input from
|
||||||
1) a false #if, #ifdef, #ifndef or #elif until the
|
1) a false #if, #ifdef, #ifndef or #elif until the
|
||||||
|
@ -171,30 +173,40 @@ int to_endif;
|
||||||
struct idf* id;
|
struct idf* id;
|
||||||
|
|
||||||
NoUnstack++;
|
NoUnstack++;
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
ch = GetChar(); /* read first character after newline */
|
ch = GetChar(); /* read first character after newline */
|
||||||
while (class(ch) == STSKIP)
|
while (class(ch) == STSKIP)
|
||||||
ch = GetChar();
|
ch = GetChar();
|
||||||
if (ch != '#') {
|
if (ch != '#')
|
||||||
if (ch == EOI) {
|
{
|
||||||
|
if (ch == EOI)
|
||||||
|
{
|
||||||
NoUnstack--;
|
NoUnstack--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ch == '/') {
|
if (ch == '/')
|
||||||
if (ch != '*') UnGetChar();
|
{
|
||||||
else {
|
if (ch != '*')
|
||||||
|
UnGetChar();
|
||||||
|
else
|
||||||
|
{
|
||||||
skipcomment();
|
skipcomment();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else UnGetChar();
|
}
|
||||||
|
else
|
||||||
|
UnGetChar();
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ReplaceMacros = 0;
|
ReplaceMacros = 0;
|
||||||
toknum = GetToken(&tk);
|
toknum = GetToken(&tk);
|
||||||
ReplaceMacros = 1;
|
ReplaceMacros = 1;
|
||||||
if (toknum != IDENTIFIER) {
|
if (toknum != IDENTIFIER)
|
||||||
if (toknum != INTEGER) {
|
{
|
||||||
|
if (toknum != INTEGER)
|
||||||
|
{
|
||||||
error("illegal # line");
|
error("illegal # line");
|
||||||
}
|
}
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
|
@ -206,13 +218,16 @@ int to_endif;
|
||||||
on the same level.
|
on the same level.
|
||||||
*/
|
*/
|
||||||
id = findidf(tk.tk_str);
|
id = findidf(tk.tk_str);
|
||||||
if (id == (struct idf *)0) {
|
if (id == (struct idf*)0)
|
||||||
|
{
|
||||||
/* invalid word seen after the '#' */
|
/* invalid word seen after the '#' */
|
||||||
warning("%s: unknown control", tk.tk_str);
|
warning("%s: unknown control", tk.tk_str);
|
||||||
}
|
}
|
||||||
free(tk.tk_str);
|
free(tk.tk_str);
|
||||||
if (id == (struct idf *)0) continue;
|
if (id == (struct idf*)0)
|
||||||
switch(id->id_resmac) {
|
continue;
|
||||||
|
switch (id->id_resmac)
|
||||||
|
{
|
||||||
case K_DEFINE:
|
case K_DEFINE:
|
||||||
case K_ERROR:
|
case K_ERROR:
|
||||||
case K_INCLUDE:
|
case K_INCLUDE:
|
||||||
|
@ -231,34 +246,42 @@ int to_endif;
|
||||||
case K_ELIF:
|
case K_ELIF:
|
||||||
if (ifstack[nestlevel])
|
if (ifstack[nestlevel])
|
||||||
error("#elif after #else");
|
error("#elif after #else");
|
||||||
if (!to_endif && nestlevel == skiplevel) {
|
if (!to_endif && nestlevel == skiplevel)
|
||||||
|
{
|
||||||
nestlevel--;
|
nestlevel--;
|
||||||
push_if();
|
push_if();
|
||||||
if (ifexpr()) {
|
if (ifexpr())
|
||||||
|
{
|
||||||
NoUnstack--;
|
NoUnstack--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else SkipToNewLine(); /* otherwise done in ifexpr() */
|
else
|
||||||
|
SkipToNewLine(); /* otherwise done in ifexpr() */
|
||||||
break;
|
break;
|
||||||
case K_ELSE:
|
case K_ELSE:
|
||||||
if (ifstack[nestlevel])
|
if (ifstack[nestlevel])
|
||||||
error("#else after #else");
|
error("#else after #else");
|
||||||
++(ifstack[nestlevel]);
|
++(ifstack[nestlevel]);
|
||||||
if (!to_endif && nestlevel == skiplevel) {
|
if (!to_endif && nestlevel == skiplevel)
|
||||||
if (SkipToNewLine()) {
|
{
|
||||||
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
strict("garbage following #else");
|
strict("garbage following #else");
|
||||||
}
|
}
|
||||||
NoUnstack--;
|
NoUnstack--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else SkipToNewLine();
|
else
|
||||||
|
SkipToNewLine();
|
||||||
break;
|
break;
|
||||||
case K_ENDIF:
|
case K_ENDIF:
|
||||||
assert(nestlevel > svnestlevel[nestcount]);
|
assert(nestlevel > svnestlevel[nestcount]);
|
||||||
if (nestlevel == skiplevel) {
|
if (nestlevel == skiplevel)
|
||||||
if (SkipToNewLine()) {
|
{
|
||||||
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
strict("garbage following #endif");
|
strict("garbage following #endif");
|
||||||
}
|
}
|
||||||
|
@ -266,14 +289,14 @@ int to_endif;
|
||||||
NoUnstack--;
|
NoUnstack--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else SkipToNewLine();
|
else
|
||||||
|
SkipToNewLine();
|
||||||
nestlevel--;
|
nestlevel--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ifexpr()
|
ifexpr()
|
||||||
{
|
{
|
||||||
/* ifexpr() returns whether the restricted constant
|
/* ifexpr() returns whether the restricted constant
|
||||||
|
@ -307,22 +330,29 @@ do_include()
|
||||||
AccFileSpecifier = 1;
|
AccFileSpecifier = 1;
|
||||||
if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING)
|
if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING)
|
||||||
filenm = tk.tk_str;
|
filenm = tk.tk_str;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
error("bad include syntax");
|
error("bad include syntax");
|
||||||
filenm = (char*)0;
|
filenm = (char*)0;
|
||||||
}
|
}
|
||||||
AccFileSpecifier = 0;
|
AccFileSpecifier = 0;
|
||||||
if (SkipToNewLine()) {
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
error("bad include syntax");
|
error("bad include syntax");
|
||||||
}
|
}
|
||||||
inctable[0] = WorkingDir;
|
inctable[0] = WorkingDir;
|
||||||
if (filenm) {
|
if (filenm)
|
||||||
if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){
|
{
|
||||||
if (do_preprocess) error("cannot open include file \"%s\"", filenm);
|
if (!InsertFile(filenm, &inctable[tok == FILESPECIFIER], &result))
|
||||||
else warning("cannot open include file \"%s\"", filenm);
|
{
|
||||||
|
if (do_preprocess)
|
||||||
|
error("cannot open include file \"%s\"", filenm);
|
||||||
|
else
|
||||||
|
warning("cannot open include file \"%s\"", filenm);
|
||||||
add_dependency(filenm);
|
add_dependency(filenm);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
add_dependency(result);
|
add_dependency(result);
|
||||||
WorkingDir = getwdir(result);
|
WorkingDir = getwdir(result);
|
||||||
svnestlevel[++nestcount] = nestlevel;
|
svnestlevel[++nestcount] = nestlevel;
|
||||||
|
@ -332,8 +362,7 @@ do_include()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void do_define()
|
||||||
do_define()
|
|
||||||
{
|
{
|
||||||
/* do_define() interprets a #define control line.
|
/* do_define() interprets a #define control line.
|
||||||
*/
|
*/
|
||||||
|
@ -347,7 +376,8 @@ do_define()
|
||||||
char* get_text();
|
char* get_text();
|
||||||
|
|
||||||
/* read the #defined macro's name */
|
/* read the #defined macro's name */
|
||||||
if (!(str = GetIdentifier(1))) {
|
if (!(str = GetIdentifier(1)))
|
||||||
|
{
|
||||||
error("#define: illegal macro name");
|
error("#define: illegal macro name");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -355,8 +385,10 @@ do_define()
|
||||||
followed immediately by a '('.
|
followed immediately by a '('.
|
||||||
*/
|
*/
|
||||||
ch = GetChar();
|
ch = GetChar();
|
||||||
if (ch == '(') {
|
if (ch == '(')
|
||||||
if ((nformals = getparams(formals, parbuf)) == -1) {
|
{
|
||||||
|
if ((nformals = getparams(formals, parbuf)) == -1)
|
||||||
|
{
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
free(str);
|
free(str);
|
||||||
return; /* an error occurred */
|
return; /* an error occurred */
|
||||||
|
@ -383,12 +415,15 @@ push_if()
|
||||||
|
|
||||||
do_elif()
|
do_elif()
|
||||||
{
|
{
|
||||||
if (nestlevel <= svnestlevel[nestcount]) {
|
if (nestlevel <= svnestlevel[nestcount])
|
||||||
|
{
|
||||||
error("#elif without corresponding #if");
|
error("#elif without corresponding #if");
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
}
|
}
|
||||||
else { /* restart at this level as if a #if is detected. */
|
else
|
||||||
if (ifstack[nestlevel]) {
|
{ /* restart at this level as if a #if is detected. */
|
||||||
|
if (ifstack[nestlevel])
|
||||||
|
{
|
||||||
error("#elif after #else");
|
error("#elif after #else");
|
||||||
SkipToNewLine();
|
SkipToNewLine();
|
||||||
}
|
}
|
||||||
|
@ -400,14 +435,17 @@ do_elif()
|
||||||
|
|
||||||
do_else()
|
do_else()
|
||||||
{
|
{
|
||||||
if (SkipToNewLine()) {
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
strict("garbage following #else");
|
strict("garbage following #else");
|
||||||
}
|
}
|
||||||
if (nestlevel <= svnestlevel[nestcount])
|
if (nestlevel <= svnestlevel[nestcount])
|
||||||
error("#else without corresponding #if");
|
error("#else without corresponding #if");
|
||||||
else { /* mark this level as else-d */
|
else
|
||||||
if (ifstack[nestlevel]) {
|
{ /* mark this level as else-d */
|
||||||
|
if (ifstack[nestlevel])
|
||||||
|
{
|
||||||
error("#else after #else");
|
error("#else after #else");
|
||||||
}
|
}
|
||||||
++(ifstack[nestlevel]);
|
++(ifstack[nestlevel]);
|
||||||
|
@ -417,14 +455,17 @@ do_else()
|
||||||
|
|
||||||
do_endif()
|
do_endif()
|
||||||
{
|
{
|
||||||
if (SkipToNewLine()) {
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
strict("garbage following #endif");
|
strict("garbage following #endif");
|
||||||
}
|
}
|
||||||
if (nestlevel <= svnestlevel[nestcount]) {
|
if (nestlevel <= svnestlevel[nestcount])
|
||||||
|
{
|
||||||
error("#endif without corresponding #if");
|
error("#endif without corresponding #if");
|
||||||
}
|
}
|
||||||
else nestlevel--;
|
else
|
||||||
|
nestlevel--;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_if()
|
do_if()
|
||||||
|
@ -442,17 +483,20 @@ do_ifdef(how)
|
||||||
/* how == 1 : ifdef; how == 0 : ifndef
|
/* how == 1 : ifdef; how == 0 : ifndef
|
||||||
*/
|
*/
|
||||||
push_if();
|
push_if();
|
||||||
if (!(str = GetIdentifier(1))) {
|
if (!(str = GetIdentifier(1)))
|
||||||
|
{
|
||||||
error("illegal #ifdef construction");
|
error("illegal #ifdef construction");
|
||||||
id = (struct idf*)0;
|
id = (struct idf*)0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
id = findidf(str);
|
id = findidf(str);
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
if (SkipToNewLine()) {
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
if (str && !options['o'])
|
if (str && !options['o'])
|
||||||
strict("garbage following #%s <identifier>",
|
strict("garbage following #%s <identifier>", how ? "ifdef" : "ifndef");
|
||||||
how ? "ifdef" : "ifndef");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The next test is a shorthand for:
|
/* The next test is a shorthand for:
|
||||||
|
@ -463,26 +507,32 @@ do_ifdef(how)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* argstr != NULL when the undef came from a -U option */
|
/* argstr != NULL when the undef came from a -U option */
|
||||||
do_undef(argstr)
|
do_undef(argstr) char* argstr;
|
||||||
char *argstr;
|
|
||||||
{
|
{
|
||||||
register struct idf* id;
|
register struct idf* id;
|
||||||
register char* str = argstr;
|
register char* str = argstr;
|
||||||
|
|
||||||
/* Forget a macro definition. */
|
/* Forget a macro definition. */
|
||||||
if (str || (str = GetIdentifier(1))) {
|
if (str || (str = GetIdentifier(1)))
|
||||||
if ((id = findidf(str)) && id->id_macro) {
|
{
|
||||||
if (id->id_macro->mc_flag & NOUNDEF) {
|
if ((id = findidf(str)) && id->id_macro)
|
||||||
|
{
|
||||||
|
if (id->id_macro->mc_flag & NOUNDEF)
|
||||||
|
{
|
||||||
error("it is not allowed to #undef %s", str);
|
error("it is not allowed to #undef %s", str);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
free(id->id_macro->mc_text);
|
free(id->id_macro->mc_text);
|
||||||
free_macro(id->id_macro);
|
free_macro(id->id_macro);
|
||||||
id->id_macro = (struct macro*)0;
|
id->id_macro = (struct macro*)0;
|
||||||
}
|
}
|
||||||
} /* else: don't complain */
|
} /* else: don't complain */
|
||||||
if (!argstr){
|
if (!argstr)
|
||||||
|
{
|
||||||
free(str);
|
free(str);
|
||||||
if (SkipToNewLine()) {
|
if (SkipToNewLine())
|
||||||
|
{
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
strict("garbage following #undef");
|
strict("garbage following #undef");
|
||||||
}
|
}
|
||||||
|
@ -503,9 +553,7 @@ do_error()
|
||||||
LineNumber++;
|
LineNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int getparams(buf, parbuf) char* buf[];
|
||||||
getparams(buf, parbuf)
|
|
||||||
char *buf[];
|
|
||||||
char parbuf[];
|
char parbuf[];
|
||||||
{
|
{
|
||||||
/* getparams() reads the formal parameter list of a macro
|
/* getparams() reads the formal parameter list of a macro
|
||||||
|
@ -525,12 +573,15 @@ getparams(buf, parbuf)
|
||||||
|
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
c = skipspaces(c, 0);
|
c = skipspaces(c, 0);
|
||||||
if (c == ')') { /* no parameters: #define name() */
|
if (c == ')')
|
||||||
|
{ /* no parameters: #define name() */
|
||||||
*pbuf = (char*)0;
|
*pbuf = (char*)0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (;;) { /* eat the formal parameter list */
|
for (;;)
|
||||||
if (class(c) != STIDF && class(c) != STELL) {
|
{ /* eat the formal parameter list */
|
||||||
|
if (class(c) != STIDF && class(c) != STELL)
|
||||||
|
{
|
||||||
error("#define: bad formal parameter");
|
error("#define: bad formal parameter");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -538,7 +589,8 @@ getparams(buf, parbuf)
|
||||||
*ptr++ = c;
|
*ptr++ = c;
|
||||||
if (ptr >= &parbuf[PARBUFSIZE])
|
if (ptr >= &parbuf[PARBUFSIZE])
|
||||||
fatal("formal parameter buffer overflow");
|
fatal("formal parameter buffer overflow");
|
||||||
do { /* eat the identifier name */
|
do
|
||||||
|
{ /* eat the identifier name */
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
*ptr++ = c;
|
*ptr++ = c;
|
||||||
if (ptr >= &parbuf[PARBUFSIZE])
|
if (ptr >= &parbuf[PARBUFSIZE])
|
||||||
|
@ -549,20 +601,23 @@ getparams(buf, parbuf)
|
||||||
/* Check if this formal parameter is already used.
|
/* Check if this formal parameter is already used.
|
||||||
Usually, macros do not have many parameters, so ...
|
Usually, macros do not have many parameters, so ...
|
||||||
*/
|
*/
|
||||||
for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) {
|
for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--)
|
||||||
if (!strcmp(*pbuf2, *pbuf)) {
|
{
|
||||||
warning("formal parameter \"%s\" already used",
|
if (!strcmp(*pbuf2, *pbuf))
|
||||||
*pbuf);
|
{
|
||||||
|
warning("formal parameter \"%s\" already used", *pbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pbuf++;
|
pbuf++;
|
||||||
c = skipspaces(c, 0);
|
c = skipspaces(c, 0);
|
||||||
if (c == ')') { /* end of the formal parameter list */
|
if (c == ')')
|
||||||
|
{ /* end of the formal parameter list */
|
||||||
*pbuf = (char*)0;
|
*pbuf = (char*)0;
|
||||||
return pbuf - buf;
|
return pbuf - buf;
|
||||||
}
|
}
|
||||||
if (c != ',') {
|
if (c != ',')
|
||||||
|
{
|
||||||
error("#define: bad formal parameter list");
|
error("#define: bad formal parameter list");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -572,9 +627,7 @@ getparams(buf, parbuf)
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void macro_def(id, text, nformals, length, flags) register struct idf* id;
|
||||||
macro_def(id, text, nformals, length, flags)
|
|
||||||
register struct idf *id;
|
|
||||||
char* text;
|
char* text;
|
||||||
{
|
{
|
||||||
register struct macro* newdef = id->id_macro;
|
register struct macro* newdef = id->id_macro;
|
||||||
|
@ -584,17 +637,25 @@ macro_def(id, text, nformals, length, flags)
|
||||||
table entry belonging to the name of the macro.
|
table entry belonging to the name of the macro.
|
||||||
An error is given if there was already a definition
|
An error is given if there was already a definition
|
||||||
*/
|
*/
|
||||||
if (newdef) { /* is there a redefinition? */
|
if (newdef)
|
||||||
if (newdef->mc_flag & NOUNDEF) {
|
{ /* is there a redefinition? */
|
||||||
|
if (newdef->mc_flag & NOUNDEF)
|
||||||
|
{
|
||||||
error("it is not allowed to redefine %s", id->id_text);
|
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);
|
error("illegal redefine of \"%s\"", id->id_text);
|
||||||
free(text);
|
free(text);
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
#ifdef DOBITS
|
#ifdef DOBITS
|
||||||
register char* p = id->id_text;
|
register char* p = id->id_text;
|
||||||
#define setbit(bx) if (!*p) goto go_on; bits[*p++] |= (bx)
|
#define setbit(bx) \
|
||||||
|
if (!*p) \
|
||||||
|
goto go_on; \
|
||||||
|
bits[*p++] |= (bx)
|
||||||
setbit(bit0);
|
setbit(bit0);
|
||||||
setbit(bit1);
|
setbit(bit1);
|
||||||
setbit(bit2);
|
setbit(bit2);
|
||||||
|
@ -614,9 +675,7 @@ macro_def(id, text, nformals, length, flags)
|
||||||
newdef->mc_flag = flags; /* special flags */
|
newdef->mc_flag = flags; /* special flags */
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int find_name(nm, index) char *nm, *index[];
|
||||||
find_name(nm, index)
|
|
||||||
char *nm, *index[];
|
|
||||||
{
|
{
|
||||||
/* find_name() returns the index of "nm" in the namelist
|
/* find_name() returns the index of "nm" in the namelist
|
||||||
"index" if it can be found there. 0 is returned if it is
|
"index" if it can be found there. 0 is returned if it is
|
||||||
|
@ -633,9 +692,7 @@ find_name(nm, index)
|
||||||
|
|
||||||
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
|
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
|
||||||
|
|
||||||
char *
|
char* get_text(formals, length) char* formals[];
|
||||||
get_text(formals, length)
|
|
||||||
char *formals[];
|
|
||||||
int* length;
|
int* length;
|
||||||
{
|
{
|
||||||
/* get_text() copies the replacement text of a macro
|
/* get_text() copies the replacement text of a macro
|
||||||
|
@ -669,97 +726,124 @@ get_text(formals, length)
|
||||||
|
|
||||||
repl->r_ptr = repl->r_text = Malloc((unsigned)(repl->r_size = ITEXTSIZE));
|
repl->r_ptr = repl->r_text = Malloc((unsigned)(repl->r_size = ITEXTSIZE));
|
||||||
*repl->r_ptr = '\0';
|
*repl->r_ptr = '\0';
|
||||||
while ((c != EOI) && (class(c) != STNL)) {
|
while ((c != EOI) && (class(c) != STNL))
|
||||||
if (BLANK(c)) {
|
{
|
||||||
|
if (BLANK(c))
|
||||||
|
{
|
||||||
blank++;
|
blank++;
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == '\'' || c == '"') {
|
if (c == '\'' || c == '"')
|
||||||
|
{
|
||||||
register int delim = c;
|
register int delim = c;
|
||||||
|
|
||||||
if (blank) {
|
if (blank)
|
||||||
|
{
|
||||||
blank = 0;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
if (c == '\\') add2repl(repl, GetChar());
|
if (c == '\\')
|
||||||
|
add2repl(repl, GetChar());
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
} while (c != delim && c != EOI && class(c) != STNL);
|
} while (c != delim && c != EOI && class(c) != STNL);
|
||||||
if (c != delim) {
|
if (c != delim)
|
||||||
|
{
|
||||||
strict("unclosed opening %c", delim);
|
strict("unclosed opening %c", delim);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
} else if (c == '/') {
|
}
|
||||||
|
else if (c == '/')
|
||||||
|
{
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
if (c == '*') {
|
if (c == '*')
|
||||||
|
{
|
||||||
skipcomment();
|
skipcomment();
|
||||||
blank++;
|
blank++;
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (blank) {
|
if (blank)
|
||||||
|
{
|
||||||
blank = 0;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
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];
|
char id_buf[IDFSIZE + 1];
|
||||||
register char* idp = id_buf;
|
register char* idp = id_buf;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
/* read identifier: it may be a formal parameter */
|
/* read identifier: it may be a formal parameter */
|
||||||
*idp++ = c;
|
*idp++ = c;
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
if (idp <= &id_buf[IDFSIZE])
|
if (idp <= &id_buf[IDFSIZE])
|
||||||
*idp++ = c;
|
*idp++ = c;
|
||||||
} while (in_idf(c));
|
} while (in_idf(c));
|
||||||
*--idp = '\0';
|
*--idp = '\0';
|
||||||
|
|
||||||
if (blank) {
|
if (blank)
|
||||||
|
{
|
||||||
blank = 0;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
/* construct the formal parameter mark or identifier */
|
/* construct the formal parameter mark or identifier */
|
||||||
if (n = find_name(id_buf, formals))
|
if (n = find_name(id_buf, formals))
|
||||||
add2repl(repl, FORMALP | (char)n);
|
add2repl(repl, FORMALP | (char)n);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
idp = id_buf;
|
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;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
if (c == '.') {
|
if (c == '.')
|
||||||
|
{
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
if (class(c) != STNUM) {
|
if (class(c) != STNUM)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
}
|
}
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
while(in_idf(c) || c == '.') {
|
while (in_idf(c) || c == '.')
|
||||||
|
{
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
if((c = GetChar()) == 'e' || c == 'E') {
|
if ((c = GetChar()) == 'e' || c == 'E')
|
||||||
|
{
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
if (c == '+' || c == '-') {
|
if (c == '+' || c == '-')
|
||||||
|
{
|
||||||
add2repl(repl, c);
|
add2repl(repl, c);
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (blank) {
|
else
|
||||||
|
{
|
||||||
|
if (blank)
|
||||||
|
{
|
||||||
blank = 0;
|
blank = 0;
|
||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
|
@ -776,36 +860,42 @@ get_text(formals, length)
|
||||||
as strings, without taking care of the leading and trailing
|
as strings, without taking care of the leading and trailing
|
||||||
blanks (spaces and tabs).
|
blanks (spaces and tabs).
|
||||||
*/
|
*/
|
||||||
macroeq(s, t)
|
macroeq(s, t) register char* s, *t;
|
||||||
register char *s, *t;
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/* skip leading spaces */
|
/* skip leading spaces */
|
||||||
while (BLANK(*s)) s++;
|
while (BLANK(*s))
|
||||||
while (BLANK(*t)) t++;
|
s++;
|
||||||
|
while (BLANK(*t))
|
||||||
|
t++;
|
||||||
/* first non-blank encountered in both strings */
|
/* first non-blank encountered in both strings */
|
||||||
/* The actual comparison loop: */
|
/* The actual comparison loop: */
|
||||||
while (*s && *s == *t)
|
while (*s && *s == *t)
|
||||||
s++, t++;
|
s++, t++;
|
||||||
/* two cases are possible when arrived here: */
|
/* two cases are possible when arrived here: */
|
||||||
if (*s == '\0') { /* *s == '\0' */
|
if (*s == '\0')
|
||||||
while (BLANK(*t)) t++;
|
{ /* *s == '\0' */
|
||||||
|
while (BLANK(*t))
|
||||||
|
t++;
|
||||||
return *t == '\0';
|
return *t == '\0';
|
||||||
}
|
}
|
||||||
else { /* *s != *t */
|
else
|
||||||
while (BLANK(*s)) s++;
|
{ /* *s != *t */
|
||||||
while (BLANK(*t)) t++;
|
while (BLANK(*s))
|
||||||
|
s++;
|
||||||
|
while (BLANK(*t))
|
||||||
|
t++;
|
||||||
return (*s == '\0') && (*t == '\0');
|
return (*s == '\0') && (*t == '\0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_line(l)
|
do_line(l) unsigned int l;
|
||||||
unsigned int l;
|
|
||||||
{
|
{
|
||||||
struct token tk;
|
struct token tk;
|
||||||
int t = GetToken(&tk);
|
int t = GetToken(&tk);
|
||||||
|
|
||||||
if (t != EOF) SkipToNewLine();
|
if (t != EOF)
|
||||||
|
SkipToNewLine();
|
||||||
LineNumber = l; /* the number of the next input line */
|
LineNumber = l; /* the number of the next input line */
|
||||||
if (t == STRING) /* is there a filespecifier? */
|
if (t == STRING) /* is there a filespecifier? */
|
||||||
FileName = tk.tk_str;
|
FileName = tk.tk_str;
|
||||||
|
|
Loading…
Reference in a new issue