From ddfcceee879947e62e3482313ad81b04085917ed Mon Sep 17 00:00:00 2001 From: kramm Date: Thu, 22 May 2008 13:58:40 +0000 Subject: [PATCH] added multiplication and division to expression parser --- src/swfc.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/swfc.c b/src/swfc.c index 0601ed1..b1b5952 100644 --- a/src/swfc.c +++ b/src/swfc.c @@ -2404,17 +2404,15 @@ int parseTwip(char*str) /* TODO: make this a proper expression parser */ char*p = str; int val = 0; - int add = 1; + char ex = 0; char*lastpos = str; while(*p) { - if(*p == '+') - add = 1; - else if(*p == '-') - add = -1; + if(*p == '+' || *p == '-' || *p == '/' || *p == '*') + ex = *p; else if(!lastpos) lastpos = p; p++; - if((*p == '+' || *p == '-' || *p == 0) && lastpos) { + if((*p == '+' || *p == '-' || *p == '/' || *p == '*' || *p == 0) && lastpos) { char save = *p; *p = 0; @@ -2429,9 +2427,18 @@ int parseTwip(char*str) v = parseRawTwip(lastpos); } *p = save; - val += v*add; + if(ex == '+') + val += v; + else if(ex == '-') + val -= v; + else if(ex == '/') + val = (val*20) / v; + else if(ex == '*') + val = (val*v) / 20; + else + val += v; + ex = 0; lastpos = 0; - add = 1; } } return val; -- 1.7.10.4