Added another structure for improved recursion detection

This commit is contained in:
ceriel 1987-02-05 17:00:14 +00:00
parent d0d5c84689
commit a40ec68883
2 changed files with 43 additions and 11 deletions

View file

@ -36,6 +36,24 @@ extern char *std_alloc();
#endif #endif
#define free_macro(p) st_free(p, &h_macro, sizeof(struct macro)) #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 /* `token' numbers of keywords of command-line processor
*/ */

View file

@ -17,7 +17,7 @@
char *strcpy(), *strcat(); char *strcpy(), *strcat();
char *long2str(); char *long2str();
PRIVATE struct macro *ReplaceList; /* list of currently active macros */ PRIVATE struct mlist *ReplaceList; /* list of currently active macros */
EXPORT int EXPORT int
replace(idef) replace(idef)
@ -36,6 +36,7 @@ replace(idef)
register char c; register char c;
char **actpars, **getactuals(); char **actpars, **getactuals();
char *reptext, *macro2buffer(); char *reptext, *macro2buffer();
register struct mlist *repl;
int size; int size;
if (mac->mc_flag & NOREPLACE) { if (mac->mc_flag & NOREPLACE) {
@ -70,27 +71,36 @@ replace(idef)
if (mac->mc_flag & FUNC) { if (mac->mc_flag & FUNC) {
struct idf *param = findidf(*actpars); struct idf *param = findidf(*actpars);
repl = new_mlist();
if (param && param->id_macro) if (param && param->id_macro)
reptext = "1"; reptext = "1";
else else
reptext = "0"; reptext = "0";
InsertText(reptext, 1); InsertText(reptext, 1);
mac->next = ReplaceList;
ReplaceList = mac; repl->next = ReplaceList;
ReplaceList = repl;
repl->m_mac = mac;
return 1; return 1;
} }
} }
repl = new_mlist();
repl->m_mac = mac;
if (mac->mc_flag & FUNC) /* this macro leads to special action */ if (mac->mc_flag & FUNC) /* this macro leads to special action */
macro_func(idef); macro_func(idef);
if (mac->mc_nps <= 0) { if (mac->mc_nps <= 0) {
mac->mc_flag |= NOREPLACE;
reptext = mac->mc_text; reptext = mac->mc_text;
size = mac->mc_length; 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); InsertText(reptext, size);
mac->next = ReplaceList; repl->next = ReplaceList;
ReplaceList = mac; ReplaceList = repl;
return 1; return 1;
} }
@ -182,14 +192,18 @@ DoUnstack()
EXPORT EXPORT
EnableMacros() EnableMacros()
{ {
register struct macro *p = ReplaceList; register struct mlist *p = ReplaceList;
assert(Unstacked > 0); assert(Unstacked > 0);
while (Unstacked > 0) { while (Unstacked > 0) {
struct mlist *nxt = p->next;
assert(p != 0); assert(p != 0);
p->mc_flag &= ~NOREPLACE; p->m_mac->mc_flag &= ~NOREPLACE;
p->mc_count = 0; if (p->m_mac->mc_count) p->m_mac->mc_count--;
p = p->next; if (p->m_repl) free(p->m_repl);
free_mlist(p);
p = nxt;
Unstacked--; Unstacked--;
} }
ReplaceList = p; ReplaceList = p;