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
This commit is contained in:
anders_k 2014-05-09 18:21:21 +00:00
parent a03795783a
commit 8193e73b31
2 changed files with 34 additions and 10 deletions

View file

@ -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

View file

@ -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