From 8193e73b315f648ed2dc6650f6eff5583a0ed924 Mon Sep 17 00:00:00 2001 From: anders_k Date: Fri, 9 May 2014 18:21:21 +0000 Subject: [PATCH] Added MASM style 0n and 0y radix prefix support for preprocessor numbers git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6469 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/history.but | 2 ++ Source/lineparse.cpp | 42 ++++++++++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Docs/src/history.but b/Docs/src/history.but index 237f7b4d..95de8b17 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -28,6 +28,8 @@ Released on ?, 2014 \b !execute supports comparing the exit code with the same syntax as !system +\b Preprocessor supports MASM style 0n and 0y radix prefix on numbers + \H{v3.0a2} 3.0 Alpha 2 Released on December 24th, 2013 diff --git a/Source/lineparse.cpp b/Source/lineparse.cpp index 0f82dcf8..3d33af8b 100644 --- a/Source/lineparse.cpp +++ b/Source/lineparse.cpp @@ -107,22 +107,44 @@ int LineParser::gettoken_int(int token, int *success/*=0*/) const if (success) *success=0; return 0; } - TCHAR *tmp; - int l; - if (_T('-') == m_tokens[token][0]) - l=_tcstol(m_tokens[token],&tmp,0); - else - l=(int)_tcstoul(m_tokens[token],&tmp,0); - if (success) *success=! (int)(*tmp); - return l; + const TCHAR *p=m_tokens[token], *parse=p; + TCHAR *end; + int neg=0, base=0, num; + if (_T('+') == *p) + ++p; + else if (_T('-') == *p) + ++p, ++neg; + if (_T('0') == p[0]) + { + // Special support for 0n and 0y MASM style radix prefix: + if (_T('n') == (p[1]|32)) parse=&p[2], base=10; + if (_T('y') == (p[1]|32)) parse=&p[2], base=2; + } + if (neg) + { + num=_tcstol(parse,&end,base); + if (base) num*=-1; // Input was "-0n012" but we have only parsed "012" and need to fix the sign + } + else + { + num=(int)_tcstoul(parse,&end,base); + } + if (success) *success=! (int)(*end); + return num; } double LineParser::gettoken_number(int token, int *success/*=0*/) const { const TCHAR*str=gettoken_str(token); if (_T('-') == *str || _T('+') == *str) ++str; - if (_T('0') == str[0] && _T('x') == (str[1]|32)) return gettoken_int(token,success); - return gettoken_float(token,success); + bool forceint = false; + if (_T('0') == str[0]) + { + if (_T('x') == (str[1]|32)) ++forceint; + if (_T('n') == (str[1]|32)) ++forceint; + if (_T('y') == (str[1]|32)) ++forceint; + } + return forceint ? gettoken_int(token,success) : gettoken_float(token,success); } TCHAR* LineParser::gettoken_str(int token) const