fixed a problem with recursive macros: this was not always detected
This commit is contained in:
parent
b07825aee3
commit
09a52b8cf2
6 changed files with 21 additions and 20 deletions
|
@ -38,6 +38,8 @@ getwdir(fn)
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int InputLevel;
|
||||||
#endif NOPP
|
#endif NOPP
|
||||||
|
|
||||||
int NoUnstack;
|
int NoUnstack;
|
||||||
|
@ -47,6 +49,7 @@ AtEoIT()
|
||||||
#ifndef NOPP
|
#ifndef NOPP
|
||||||
/* if (NoUnstack) lexwarning("unexpected EOF"); ??? */
|
/* if (NoUnstack) lexwarning("unexpected EOF"); ??? */
|
||||||
DoUnstack();
|
DoUnstack();
|
||||||
|
InputLevel--;
|
||||||
#endif NOPP
|
#endif NOPP
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct mlist {
|
||||||
struct mlist *next;
|
struct mlist *next;
|
||||||
struct macro *m_mac;
|
struct macro *m_mac;
|
||||||
char *m_repl;
|
char *m_repl;
|
||||||
char m_unstack;
|
int m_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ALLOCDEF "mlist" 20 */
|
/* ALLOCDEF "mlist" 20 */
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
char *strcpy(), *strcat();
|
char *strcpy(), *strcat();
|
||||||
char *long2str();
|
char *long2str();
|
||||||
|
extern int InputLevel;
|
||||||
|
|
||||||
PRIVATE struct mlist *ReplaceList; /* list of currently active macros */
|
PRIVATE struct mlist *ReplaceList; /* list of currently active macros */
|
||||||
|
|
||||||
|
@ -85,6 +86,8 @@ replace(idef)
|
||||||
else
|
else
|
||||||
reptext = "0";
|
reptext = "0";
|
||||||
InsertText(reptext, 1);
|
InsertText(reptext, 1);
|
||||||
|
InputLevel++;
|
||||||
|
repl->m_level = InputLevel;
|
||||||
repl->next = ReplaceList;
|
repl->next = ReplaceList;
|
||||||
ReplaceList = repl;
|
ReplaceList = repl;
|
||||||
repl->m_mac = mac;
|
repl->m_mac = mac;
|
||||||
|
@ -105,6 +108,8 @@ replace(idef)
|
||||||
repl->m_repl = reptext;
|
repl->m_repl = reptext;
|
||||||
}
|
}
|
||||||
InsertText(reptext, size);
|
InsertText(reptext, size);
|
||||||
|
InputLevel++;
|
||||||
|
repl->m_level = InputLevel;
|
||||||
repl->next = ReplaceList;
|
repl->next = ReplaceList;
|
||||||
ReplaceList = repl;
|
ReplaceList = repl;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -191,36 +196,29 @@ macro2buffer(idef, actpars, siztext)
|
||||||
EXPORT
|
EXPORT
|
||||||
DoUnstack()
|
DoUnstack()
|
||||||
{
|
{
|
||||||
register struct mlist *p = ReplaceList;
|
Unstacked = 1;
|
||||||
|
|
||||||
while (p->m_unstack) p = p->next;
|
|
||||||
p->m_unstack = 1;
|
|
||||||
Unstacked++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT
|
EXPORT
|
||||||
EnableMacros()
|
EnableMacros()
|
||||||
{
|
{
|
||||||
register struct mlist *p = ReplaceList, *prev = 0;
|
register struct mlist *p = ReplaceList, *prev = 0;
|
||||||
int cnt = 0;
|
|
||||||
|
|
||||||
ASSERT(Unstacked > 0);
|
ASSERT(Unstacked > 0);
|
||||||
while (p) {
|
while (p) {
|
||||||
struct mlist *nxt = p->next;
|
struct mlist *nxt = p->next;
|
||||||
|
|
||||||
if (p->m_unstack) {
|
if (p->m_level > InputLevel) {
|
||||||
p->m_mac->mc_flag &= ~NOREPLACE;
|
p->m_mac->mc_flag &= ~NOREPLACE;
|
||||||
if (p->m_mac->mc_count) p->m_mac->mc_count--;
|
if (p->m_mac->mc_count) p->m_mac->mc_count--;
|
||||||
if (p->m_repl) free(p->m_repl);
|
if (p->m_repl) free(p->m_repl);
|
||||||
if (! prev) ReplaceList = nxt;
|
if (! prev) ReplaceList = nxt;
|
||||||
else prev->next = nxt;
|
else prev->next = nxt;
|
||||||
free_mlist(p);
|
free_mlist(p);
|
||||||
cnt++;
|
|
||||||
}
|
}
|
||||||
else prev = p;
|
else prev = p;
|
||||||
p = nxt;
|
p = nxt;
|
||||||
}
|
}
|
||||||
ASSERT(cnt == Unstacked);
|
|
||||||
Unstacked = 0;
|
Unstacked = 0;
|
||||||
}
|
}
|
||||||
#endif NOPP
|
#endif NOPP
|
||||||
|
|
|
@ -37,10 +37,12 @@ getwdir(fn)
|
||||||
|
|
||||||
int NoUnstack;
|
int NoUnstack;
|
||||||
int Unstacked;
|
int Unstacked;
|
||||||
|
int InputLevel;
|
||||||
|
|
||||||
AtEoIT()
|
AtEoIT()
|
||||||
{
|
{
|
||||||
if (NoUnstack) warning("unexpected EOF");
|
if (NoUnstack) warning("unexpected EOF");
|
||||||
|
InputLevel--;
|
||||||
DoUnstack();
|
DoUnstack();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct mlist {
|
||||||
struct mlist *next;
|
struct mlist *next;
|
||||||
struct macro *m_mac;
|
struct macro *m_mac;
|
||||||
char *m_repl;
|
char *m_repl;
|
||||||
char m_unstack;
|
int m_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* allocation definitions of struct mlist */
|
/* allocation definitions of struct mlist */
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
char *strcpy(), *strcat();
|
char *strcpy(), *strcat();
|
||||||
char *long2str();
|
char *long2str();
|
||||||
|
extern int InputLevel;
|
||||||
|
|
||||||
PRIVATE struct mlist *ReplList; /* list of currently active macros */
|
PRIVATE struct mlist *ReplList; /* list of currently active macros */
|
||||||
|
|
||||||
|
@ -81,6 +82,8 @@ replace(idef)
|
||||||
else
|
else
|
||||||
reptext = "0";
|
reptext = "0";
|
||||||
InsertText(reptext, 1);
|
InsertText(reptext, 1);
|
||||||
|
InputLevel++;
|
||||||
|
repl->m_level = InputLevel;
|
||||||
|
|
||||||
repl->next = ReplList;
|
repl->next = ReplList;
|
||||||
ReplList = repl;
|
ReplList = repl;
|
||||||
|
@ -103,6 +106,8 @@ replace(idef)
|
||||||
repl->m_repl = reptext;
|
repl->m_repl = reptext;
|
||||||
}
|
}
|
||||||
InsertText(reptext, size);
|
InsertText(reptext, size);
|
||||||
|
InputLevel++;
|
||||||
|
repl->m_level = InputLevel;
|
||||||
repl->next = ReplList;
|
repl->next = ReplList;
|
||||||
ReplList = repl;
|
ReplList = repl;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -190,35 +195,28 @@ macro2buffer(idef, actpars, siztext)
|
||||||
EXPORT
|
EXPORT
|
||||||
DoUnstack()
|
DoUnstack()
|
||||||
{
|
{
|
||||||
register struct mlist *p = ReplList;
|
Unstacked = 1;
|
||||||
|
|
||||||
while (p->m_unstack) p = p->next;
|
|
||||||
p->m_unstack = 1;
|
|
||||||
Unstacked++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT
|
EXPORT
|
||||||
EnableMacros()
|
EnableMacros()
|
||||||
{
|
{
|
||||||
register struct mlist *p = ReplList, *prev = 0;
|
register struct mlist *p = ReplList, *prev = 0;
|
||||||
int cnt = 0;
|
|
||||||
|
|
||||||
assert(Unstacked > 0);
|
assert(Unstacked > 0);
|
||||||
while (p) {
|
while (p) {
|
||||||
struct mlist *nxt = p->next;
|
struct mlist *nxt = p->next;
|
||||||
|
|
||||||
if (p->m_unstack) {
|
if (p->m_level > InputLevel) {
|
||||||
p->m_mac->mc_flag &= ~NOREPLACE;
|
p->m_mac->mc_flag &= ~NOREPLACE;
|
||||||
if (p->m_mac->mc_count) p->m_mac->mc_count--;
|
if (p->m_mac->mc_count) p->m_mac->mc_count--;
|
||||||
if (p->m_repl) free(p->m_repl);
|
if (p->m_repl) free(p->m_repl);
|
||||||
if (! prev) ReplList = nxt;
|
if (! prev) ReplList = nxt;
|
||||||
else prev->next = nxt;
|
else prev->next = nxt;
|
||||||
free_mlist(p);
|
free_mlist(p);
|
||||||
cnt++;
|
|
||||||
}
|
}
|
||||||
else prev = p;
|
else prev = p;
|
||||||
p = nxt;
|
p = nxt;
|
||||||
}
|
}
|
||||||
assert(cnt == Unstacked);
|
|
||||||
Unstacked = 0;
|
Unstacked = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue