From dda199842106d6793c5b67f3325cdf00253fbfdc Mon Sep 17 00:00:00 2001 From: anders_k Date: Sat, 4 Nov 2017 17:59:37 +0000 Subject: [PATCH] Added ~, !, && and || !define /math operators git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6947 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/defines.but | 2 +- Docs/src/history.but | 2 ++ Source/scriptpp.cpp | 19 ++++++++++++++----- Source/tokens.cpp | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Docs/src/defines.but b/Docs/src/defines.but index 56ee6fa5..a63b2f55 100644 --- a/Docs/src/defines.but +++ b/Docs/src/defines.but @@ -16,7 +16,7 @@ This command will add \e{gflag} to the global define list. This will have a simi If \e{/date} or \e{/utcdate} are used, \e{value} will be passed to strftime() and the result will be used as the value of \e{gflag}. strftime converts special symbols into certain parts of the current time or date. For example, %H will be converted into the current hour in 24-hour format. For a complete list of available symbols, search for strftime on \W{http://msdn.microsoft.com/}{MSDN}. On POSIX, you can get the list by using \c{man strftime}. -If \e{/math} is used, the result of 'val1 OP val2', where OP may be +,-,*,&,|,^,/,<<,>>,>>> or % , will be used as the value of \e{gflag}. Note that val1 AND val2 MUST be integer values! +If \e{/math} is used, the result of 'val1 OP val2', where OP may be +,-,*,/,%,<<,>>,>>>,&,|,^,~,!,&& or ||, will be used as the value of \e{gflag}. Note that val1 AND val2 MUST be integer values! If \e{/file} is used, the entire text file specified (including whitespace and newlines) will be read and stuffed into \e{gflag}. diff --git a/Docs/src/history.but b/Docs/src/history.but index 40083e91..c34f266d 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -26,6 +26,8 @@ Released on ??? ??rd, 20?? \b Added IntOp and System::Int64Op >>> operator +\b Added more !define /math operators + \b Plug-ins now set the ASLR, DEP, LAA, NOSEH and TS PE flags (\W{http://sf.net/p/nsis/bugs/1188}{bug #1188}) \b MakeNSIS exits with code 0 for various information commands (\W{http://sf.net/p/nsis/bugs/1193}{bug #1193}) diff --git a/Source/scriptpp.cpp b/Source/scriptpp.cpp index 422f8227..8dc144b2 100644 --- a/Source/scriptpp.cpp +++ b/Source/scriptpp.cpp @@ -952,10 +952,10 @@ int CEXEBuild::pp_define(LineParser&line) } else if (!_tcsicmp(define, _T("/math"))) { - int value1, value2; + int value1, value2, tc = line.getnumtokens(), onlyval1 = 0; TCHAR *mathop; - if (line.getnumtokens() != 6) PRINTHELPEX(cmdnam) + if (tc != 5 && tc != 6) badmathsyntax: PRINTHELPEX(cmdnam) define = line.gettoken_str(2); value1 = line.gettoken_int(3); mathop = line.gettoken_str(4); @@ -974,6 +974,14 @@ int CEXEBuild::pp_define(LineParser&line) _stprintf(value, _T("%d"), value1 | value2); } else if (!_tcscmp(mathop, _T("^"))) { _stprintf(value, _T("%d"), value1 ^ value2); + } else if (!_tcscmp(mathop, _T("~"))) { + _stprintf(value, _T("%d"), ~ value1), ++onlyval1; + } else if (!_tcscmp(mathop, _T("!"))) { + _stprintf(value, _T("%d"), ! value1), ++onlyval1; + } else if (!_tcscmp(mathop, _T("&&"))) { + _stprintf(value, _T("%d"), value1 && value2); + } else if (!_tcscmp(mathop, _T("||"))) { + _stprintf(value, _T("%d"), value1 || value2); } else if (!_tcscmp(mathop, _T("<<")) || !_tcscmp(mathop, _T("<<<")) ) { _stprintf(value, _T("%d"), value1 << value2); } else if (!_tcscmp(mathop, _T(">>"))) { @@ -987,8 +995,7 @@ int CEXEBuild::pp_define(LineParser&line) return PS_ERROR; } _stprintf(value, _T("%d"), value1 / value2); - } else if (!_tcscmp(mathop, _T("%"))) - { + } else if (!_tcscmp(mathop, _T("%"))) { if (value2 == 0) { ERROR_MSG(_T("!define /math: division by zero! (\"%i %") NPRIs _T(" %i\")\n"),value1,mathop,value2); @@ -997,7 +1004,9 @@ int CEXEBuild::pp_define(LineParser&line) _stprintf(value, _T("%d"), value1 % value2); } else - PRINTHELPEX(cmdnam) + goto badmathsyntax; + + if (tc + onlyval1 != 6) goto badmathsyntax; } else { diff --git a/Source/tokens.cpp b/Source/tokens.cpp index a9735c76..1db94767 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -268,7 +268,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,5,_T("[/ifndef | /redef] ([/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,0,_T("symbol"),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},