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

@ -38,6 +38,8 @@ getwdir(fn)
}
return "";
}
int InputLevel;
#endif NOPP
int NoUnstack;
@ -47,6 +49,7 @@ AtEoIT()
#ifndef NOPP
/* if (NoUnstack) lexwarning("unexpected EOF"); ??? */
DoUnstack();
InputLevel--;
#endif NOPP
return 0;
}

View file

@ -37,7 +37,7 @@ struct mlist {
struct mlist *next;
struct macro *m_mac;
char *m_repl;
char m_unstack;
int m_level;
};
/* ALLOCDEF "mlist" 20 */

View file

@ -24,6 +24,7 @@
char *strcpy(), *strcat();
char *long2str();
extern int InputLevel;
PRIVATE struct mlist *ReplaceList; /* list of currently active macros */
@ -85,6 +86,8 @@ replace(idef)
else
reptext = "0";
InsertText(reptext, 1);
InputLevel++;
repl->m_level = InputLevel;
repl->next = ReplaceList;
ReplaceList = repl;
repl->m_mac = mac;
@ -105,6 +108,8 @@ replace(idef)
repl->m_repl = reptext;
}
InsertText(reptext, size);
InputLevel++;
repl->m_level = InputLevel;
repl->next = ReplaceList;
ReplaceList = repl;
return 1;
@ -191,36 +196,29 @@ macro2buffer(idef, actpars, siztext)
EXPORT
DoUnstack()
{
register struct mlist *p = ReplaceList;
while (p->m_unstack) p = p->next;
p->m_unstack = 1;
Unstacked++;
Unstacked = 1;
}
EXPORT
EnableMacros()
{
register struct mlist *p = ReplaceList, *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) ReplaceList = nxt;
else prev->next = nxt;
free_mlist(p);
cnt++;
}
else prev = p;
p = nxt;
}
ASSERT(cnt == Unstacked);
Unstacked = 0;
}
#endif NOPP

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;
}