!insertmacro allows macro recursion (RFE #497)

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6511 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2014-07-04 23:27:04 +00:00
parent 7ee1a114a9
commit 0a8c72c950
4 changed files with 38 additions and 45 deletions

View file

@ -107,7 +107,8 @@ class CEXEBuild {
~CEXEBuild();
enum {
MAX_LINELENGTH = 16384 // NSI/NSH line limit, in TCHARs (including \0)
MAX_LINELENGTH = 16384, // NSI/NSH line limit, in TCHARs (including \0)
MAX_MACRORECURSION = 50
};
void warning(const TCHAR *s, ...); // to add a warning to the compiler's warning list.

View file

@ -1256,22 +1256,20 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
macroname,npr,line.getnumtokens()-2);
return PS_ERROR;
}
int lp=0;
TCHAR str[1024];
if (m_macro_entry.find(macroname,0)>=0)
static unsigned char insertmacrorecursion=0;
if (++insertmacrorecursion > MAX_MACRORECURSION)
{
ERROR_MSG(_T("!insertmacro: macro \"%") NPRIs _T("\" already being inserted!\n"),macroname);
ERROR_MSG(_T("!insertmacro: insert depth is limited to %u macros!\n"),MAX_MACRORECURSION);
return PS_ERROR;
}
int npos=m_macro_entry.add(macroname,0);
const bool oldparserinsidecomment=inside_comment;
inside_comment=false; // "!insertmacro foo /*" does not mean that the macro body is a comment
TCHAR str[1024];
wsprintf(str,_T("macro:%") NPRIs,macroname);
const TCHAR* oldmacroname=m_currentmacroname;
const TCHAR *oldmacroname=m_currentmacroname;
m_currentmacroname=macroname;
definedlist.set(_T("__MACRO__"),m_currentmacroname);
int lp=0;
while (*t)
{
lp++;
@ -1291,7 +1289,6 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
}
t+=_tcslen(t)+1;
}
m_macro_entry.delbypos(npos);
{
TCHAR *p=(TCHAR*)l_define_names.get();
while (*p)
@ -1304,8 +1301,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
}
definedlist.del(_T("__MACRO__"));
m_currentmacroname=oldmacroname;
inside_comment=oldparserinsidecomment;
if (oldmacroname) definedlist.add(_T("__MACRO__"),oldmacroname);
inside_comment=oldparserinsidecomment;
--insertmacrorecursion;
SCRIPT_MSG(_T("!insertmacro: end of %") NPRIs _T("\n"),macroname);
}
return PS_OK;