diff --git a/Docs/src/defines.but b/Docs/src/defines.but index b090cbd6..08c0e82d 100644 --- a/Docs/src/defines.but +++ b/Docs/src/defines.but @@ -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 diff --git a/Source/script.cpp b/Source/script.cpp index 5b9d271d..070fc8ee 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -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); diff --git a/Source/tokens.cpp b/Source/tokens.cpp index f4a7f2ea..2764dc47 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -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},