From 44ff24f085af08fc1fed5346257cc516aad964ec Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Oct 1989 14:23:08 +0000 Subject: [PATCH] Also recognize 'defined' without parentheses --- lang/cem/cemcom/domacro.c | 2 +- lang/cem/cemcom/replace.c | 30 ++++++++++++++++++++++-------- util/cpp/domacro.c | 2 +- util/cpp/replace.c | 28 +++++++++++++++++++++------- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index 4e080f0f2..d427d516f 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -34,7 +34,7 @@ PRIVATE char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ int nestlevel = -1; -PRIVATE struct idf * +struct idf * GetIdentifier() { /* returns a pointer to the descriptor of the identifier that is diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 1aed93cae..d1d577fe1 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -69,19 +69,32 @@ replace(idef) return 0; } LoadChar(c); - c = skipspaces(c,1); + c = skipspaces(c,! (mac->mc_flag & FUNC)); if (c != '(') { /* no replacement if no () */ - lexerror("(warning) macro %s needs arguments", - idef->id_text); PushBack(); - return 0; + if (! (mac->mc_flag & FUNC)) { + lexerror("(warning) macro %s needs arguments", + idef->id_text); + return 0; + } } - actpars = getactuals(idef); /* get act.param. list */ if (mac->mc_flag & FUNC) { - struct idf *param = str2idf(*actpars); - + struct idf *param; + extern struct idf *GetIdentifier(); + + UnknownIdIsZero = 0; + param = GetIdentifier(); + UnknownIdIsZero = 1; + if (c == '(') { + LoadChar(c); + c = skipspaces(c,0); + if (c != ')') error(") missing"); + } + if (! param) { + error("identifier missing"); + } repl = new_mlist(); - if (param->id_macro) + if (param && param->id_macro) reptext = "1"; else reptext = "0"; @@ -93,6 +106,7 @@ replace(idef) repl->m_mac = mac; return 1; } + actpars = getactuals(idef); /* get act.param. list */ } repl = new_mlist(); repl->m_mac = mac; diff --git a/util/cpp/domacro.c b/util/cpp/domacro.c index fc57ab333..63b9901aa 100644 --- a/util/cpp/domacro.c +++ b/util/cpp/domacro.c @@ -34,7 +34,7 @@ int nestlevel = -1; int svnestlevel[30] = {-1}; int nestcount; -PRIVATE char * +char * GetIdentifier() { /* returns a pointer to the descriptor of the identifier that is diff --git a/util/cpp/replace.c b/util/cpp/replace.c index 4c5320397..a8bccb1ac 100644 --- a/util/cpp/replace.c +++ b/util/cpp/replace.c @@ -65,17 +65,30 @@ replace(idef) return 0; } LoadChar(c); - c = skipspaces(c,1); + c = skipspaces(c,! (mac->mc_flag & FUNC)); if (c != '(') { /* no replacement if no () */ - warning("macro %s needs arguments", - idef->id_text); PushBack(); - return 0; + if (! (mac->mc_flag & FUNC)) { + warning("macro %s needs arguments", + idef->id_text); + return 0; + } } - actpars = getactuals(idef); /* get act.param. list */ if (mac->mc_flag & FUNC) { - struct idf *param = findidf(*actpars); - + struct idf *param; + extern struct idf *GetIdentifier(); + + UnknownIdIsZero = 0; + param = GetIdentifier(); + UnknownIdIsZero = 1; + if (c == '(') { + LoadChar(c); + c = skipspaces(c, 0); + if (c != ')') error(") missing"); + } + if (! param) { + error("identifier missing"); + } repl = new_mlist(); if (param && param->id_macro) reptext = "1"; @@ -90,6 +103,7 @@ replace(idef) repl->m_mac = mac; return 1; } + actpars = getactuals(idef); /* get act.param. list */ } repl = new_mlist(); -- 2.34.1