Added !define /ifndef and !define /redef optional arguments

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6097 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2010-06-10 20:42:50 +00:00
parent 74ffaada4e
commit d526c78d05
3 changed files with 19 additions and 2 deletions

View file

@ -10,7 +10,7 @@ Define/conditional compilation related commands:
\S1{define} !define
\c ([/date|/utcdate] gflag [value]) | (/math gflag val1 OP val2) | (/file gflag filename.txt)
\c [/ifndef | /redef] ([/date|/utcdate] gflag [value]) | (/math gflag val1 OP val2) | (/file gflag filename.txt)
This command will add \e{gflag} to the global define list. This will have a similar effect as using the /D switch on the command line (only the define only becomes effective after the !define command).
@ -26,6 +26,7 @@ If \e{/file} is used, the entire text file specified (including whitespace and n
\c !define /math RESULT 3 + 10
\c !define /math REST 15 % ${RESULT}
\c !define /file BUNCHASTUFF somesourcefile.cpp
\c !define /redef USE_SOMETHING ${RESULT} ;redefine USE_SOMETHING
\S1{undef} !undef

View file

@ -2799,6 +2799,21 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
GrowBuf file_buf;
TCHAR datebuf[256];
TCHAR mathbuf[256];
int dupemode=0;
if (!_tcsicmp(define,_T("/ifndef")))
dupemode=1;
else if (!_tcsicmp(define,_T("/redef")))
dupemode=2;
if (dupemode!=0)
{
line.eattoken();
define=line.gettoken_str(1);
if (dupemode==1 && definedlist.find(define))return PS_OK;
}
if (!_tcsicmp(define,_T("/date")) || !_tcsicmp(define,_T("/utcdate"))) {
if (line.getnumtokens()!=4) PRINTHELP()
@ -2903,6 +2918,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
value=line.gettoken_str(2);
}
if (dupemode==2)definedlist.del(define);
if (definedlist.add(define,value))
{
ERROR_MSG(_T("!define: \"%s\" already defined!\n"),define);

View file

@ -246,7 +246,7 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_P_IFDEF,_T("!ifdef"),1,-1,_T("symbol [| symbol2 [& symbol3 [...]]]"),TP_ALL},
{TOK_P_IFNDEF,_T("!ifndef"),1,-1,_T("symbol [| symbol2 [& symbol3 [...]]]"),TP_ALL},
{TOK_P_ENDIF,_T("!endif"),0,0,_T(""),TP_ALL},
{TOK_P_DEFINE,_T("!define"),1,4,_T("([/date|/utcdate] symbol [value]) | (/file symbol filename) | (/math symbol val1 OP val2)\n OP=(+ - * / % & | ^)"),TP_ALL},
{TOK_P_DEFINE,_T("!define"),1,5,_T("[/ifndef | /redef] ([/date|/utcdate] symbol [value]) | (/file symbol filename) | (/math symbol val1 OP val2)\n OP=(+ - * / % & | ^)"),TP_ALL},
{TOK_P_UNDEF,_T("!undef"),1,1,_T("symbol [value]"),TP_ALL},
{TOK_P_ELSE,_T("!else"),0,-1,_T("[if[macro][n][def] ...]"),TP_ALL},
{TOK_P_ECHO,_T("!echo"),1,0,_T("message"),TP_ALL},