From: ceriel Date: Thu, 5 Feb 1987 17:00:14 +0000 (+0000) Subject: Added another structure for improved recursion detection X-Git-Tag: release-5-5~4751 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=a40ec688836c22112a0724ffeb147ee2730110b0;p=ack.git Added another structure for improved recursion detection --- diff --git a/util/cpp/macro.h b/util/cpp/macro.h index b04953a7f..ffa70b378 100644 --- a/util/cpp/macro.h +++ b/util/cpp/macro.h @@ -36,6 +36,24 @@ extern char *std_alloc(); #endif #define free_macro(p) st_free(p, &h_macro, sizeof(struct macro)) +struct mlist { + struct mlist *next; + struct macro *m_mac; + char *m_repl; +}; + +/* allocation definitions of struct mlist */ +extern char *st_alloc(); +extern struct mlist *h_mlist; +#ifdef DEBUG +extern int cnt_mlist; +extern char *std_alloc(); +#define new_mlist() ((struct mlist *) std_alloc((char **)&h_mlist, sizeof(struct mlist), 20, &cnt_mlist)) +#else +#define new_mlist() ((struct mlist *) st_alloc((char **)&h_mlist, sizeof(struct mlist), 20)) +#endif +#define free_mlist(p) st_free(p, &h_mlist, sizeof(struct mlist)) + /* `token' numbers of keywords of command-line processor */ diff --git a/util/cpp/replace.c b/util/cpp/replace.c index 846cadf5a..7bc959cec 100644 --- a/util/cpp/replace.c +++ b/util/cpp/replace.c @@ -17,7 +17,7 @@ char *strcpy(), *strcat(); char *long2str(); -PRIVATE struct macro *ReplaceList; /* list of currently active macros */ +PRIVATE struct mlist *ReplaceList; /* list of currently active macros */ EXPORT int replace(idef) @@ -36,6 +36,7 @@ replace(idef) register char c; char **actpars, **getactuals(); char *reptext, *macro2buffer(); + register struct mlist *repl; int size; if (mac->mc_flag & NOREPLACE) { @@ -70,27 +71,36 @@ replace(idef) if (mac->mc_flag & FUNC) { struct idf *param = findidf(*actpars); + repl = new_mlist(); if (param && param->id_macro) reptext = "1"; else reptext = "0"; InsertText(reptext, 1); - mac->next = ReplaceList; - ReplaceList = mac; + + repl->next = ReplaceList; + ReplaceList = repl; + repl->m_mac = mac; return 1; } } + + repl = new_mlist(); + repl->m_mac = mac; if (mac->mc_flag & FUNC) /* this macro leads to special action */ macro_func(idef); if (mac->mc_nps <= 0) { - mac->mc_flag |= NOREPLACE; reptext = mac->mc_text; size = mac->mc_length; + mac->mc_flag |= NOREPLACE; /* a file called __FILE__ ??? */ + } + else { + reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ + repl->m_repl = reptext; } - else reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ InsertText(reptext, size); - mac->next = ReplaceList; - ReplaceList = mac; + repl->next = ReplaceList; + ReplaceList = repl; return 1; } @@ -182,14 +192,18 @@ DoUnstack() EXPORT EnableMacros() { - register struct macro *p = ReplaceList; + register struct mlist *p = ReplaceList; assert(Unstacked > 0); while (Unstacked > 0) { + struct mlist *nxt = p->next; + assert(p != 0); - p->mc_flag &= ~NOREPLACE; - p->mc_count = 0; - p = p->next; + p->m_mac->mc_flag &= ~NOREPLACE; + if (p->m_mac->mc_count) p->m_mac->mc_count--; + if (p->m_repl) free(p->m_repl); + free_mlist(p); + p = nxt; Unstacked--; } ReplaceList = p;