fixed a problem with recursive macros: this was not always detected

This commit is contained in:
ceriel
1989-07-14 09:51:02 +00:00
parent b07825aee3
commit 09a52b8cf2
6 changed files with 21 additions and 20 deletions

View File

@@ -37,10 +37,12 @@ getwdir(fn)
int NoUnstack;
int Unstacked;
int InputLevel;
AtEoIT()
{
if (NoUnstack) warning("unexpected EOF");
InputLevel--;
DoUnstack();
return 0;
}

View File

@@ -45,7 +45,7 @@ struct mlist {
struct mlist *next;
struct macro *m_mac;
char *m_repl;
char m_unstack;
int m_level;
};
/* allocation definitions of struct mlist */

View File

@@ -20,6 +20,7 @@
char *strcpy(), *strcat();
char *long2str();
extern int InputLevel;
PRIVATE struct mlist *ReplList; /* list of currently active macros */
@@ -81,6 +82,8 @@ replace(idef)
else
reptext = "0";
InsertText(reptext, 1);
InputLevel++;
repl->m_level = InputLevel;
repl->next = ReplList;
ReplList = repl;
@@ -103,6 +106,8 @@ replace(idef)
repl->m_repl = reptext;
}
InsertText(reptext, size);
InputLevel++;
repl->m_level = InputLevel;
repl->next = ReplList;
ReplList = repl;
return 1;
@@ -190,35 +195,28 @@ macro2buffer(idef, actpars, siztext)
EXPORT
DoUnstack()
{
register struct mlist *p = ReplList;
while (p->m_unstack) p = p->next;
p->m_unstack = 1;
Unstacked++;
Unstacked = 1;
}
EXPORT
EnableMacros()
{
register struct mlist *p = ReplList, *prev = 0;
int cnt = 0;
assert(Unstacked > 0);
while (p) {
struct mlist *nxt = p->next;
if (p->m_unstack) {
if (p->m_level > InputLevel) {
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);
if (! prev) ReplList = nxt;
else prev->next = nxt;
free_mlist(p);
cnt++;
}
else prev = p;
p = nxt;
}
assert(cnt == Unstacked);
Unstacked = 0;
}