summaryrefslogtreecommitdiff
path: root/src/cat/TPTScriptInterface.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2013-04-07 11:46:09 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2013-04-07 11:46:09 (GMT)
commit8d312ecdfadb7c68d00caf01effe0c1e0a45cb76 (patch)
tree4c9f891c6fb3d4a7cdf58339139dc1359e85b528 /src/cat/TPTScriptInterface.cpp
parent9b5b85f9b01cbda7ef9a7ec2a15b2a35630a5b9d (diff)
parentf7dd658a301bf22802b72f0d338c6a769e28ed0a (diff)
downloadpowder-8d312ecdfadb7c68d00caf01effe0c1e0a45cb76.zip
powder-8d312ecdfadb7c68d00caf01effe0c1e0a45cb76.tar.gz
Merge branch 'master' of github.com:FacialTurd/The-Powder-Toy
Diffstat (limited to 'src/cat/TPTScriptInterface.cpp')
-rw-r--r--src/cat/TPTScriptInterface.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/cat/TPTScriptInterface.cpp b/src/cat/TPTScriptInterface.cpp
index 601c228..d1a7588 100644
--- a/src/cat/TPTScriptInterface.cpp
+++ b/src/cat/TPTScriptInterface.cpp
@@ -85,10 +85,22 @@ ValueType TPTScriptInterface::testType(std::string word)
{
if(rawWord[i] == ',' && rawWord[i+1] >= '0' && rawWord[i+1] <= '9')
goto parsePoint;
+ else if((rawWord[i] == '#' || rawWord[i] == 'x') &&
+ ((rawWord[i+1] >= '0' && rawWord[i+1] <= '9')
+ || (rawWord[i+1] >= 'a' && rawWord[i+1] <= 'f')
+ || (rawWord[i+1] >= 'A' && rawWord[i+1] <= 'F')))
+ goto parseNumberHex;
else
goto parseString;
}
}
+ parseNumberHex:
+ i++;
+ for(; i < word.length(); i++)
+ if(!((rawWord[i] >= '0' && rawWord[i] <= '9') || (rawWord[i] >= 'a' && rawWord[i] <= 'f') || (rawWord[i] >= 'A' && rawWord[i] <= 'F')))
+ {
+ goto parseString;
+ }
return TypeNumber;
parsePoint:
i++;
@@ -102,6 +114,50 @@ ValueType TPTScriptInterface::testType(std::string word)
return TypeString;
}
+int TPTScriptInterface::parseNumber(char * stringData)
+{
+ char cc;
+ int base = 10;
+ int currentNumber = 0;
+ if(stringData[0] == '#')
+ {
+ stringData++;
+ base = 16;
+ }
+ else if(stringData[0] == '0' && stringData[1] == 'x')
+ {
+ stringData+=2;
+ base = 16;
+ }
+ if(base == 16)
+ {
+ while(cc = *(stringData++))
+ {
+ currentNumber *= base;
+ if(cc >= '0' && cc <= '9')
+ currentNumber += cc - '0';
+ else if(cc >= 'a' && cc <= 'f')
+ currentNumber += (cc - 'A') + 10;
+ else if(cc >= 'A' && cc <= 'F')
+ currentNumber += (cc - 'A') + 10;
+ else
+ break;
+ }
+ }
+ else
+ {
+ while(cc = *(stringData++))
+ {
+ currentNumber *= base;
+ if(cc >= '0' && cc <= '9')
+ currentNumber += cc - '0';
+ else
+ break;
+ }
+ }
+ return currentNumber;
+}
+
AnyType TPTScriptInterface::eval(std::deque<std::string> * words)
{
if(words->size() < 1)
@@ -128,7 +184,7 @@ AnyType TPTScriptInterface::eval(std::deque<std::string> * words)
return tptS_quit(words);
break;
case TypeNumber:
- return NumberType(atoi(rawWord));
+ return NumberType(parseNumber(rawWord));
case TypePoint:
{
int pointX, pointY;