git.asbjorn.biz
/
swftools.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d403c5b
)
added multiplication and division to expression parser
author
kramm
<kramm>
Thu, 22 May 2008 13:58:40 +0000
(13:58 +0000)
committer
kramm
<kramm>
Thu, 22 May 2008 13:58:40 +0000
(13:58 +0000)
src/swfc.c
patch
|
blob
|
history
diff --git
a/src/swfc.c
b/src/swfc.c
index
0601ed1
..
b1b5952
100644
(file)
--- 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;
/* TODO: make this a proper expression parser */
char*p = str;
int val = 0;
- int add = 1;
+ char ex = 0;
char*lastpos = str;
while(*p) {
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++;
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;
char save = *p;
*p = 0;
@@
-2429,9
+2427,18
@@
int parseTwip(char*str)
v = parseRawTwip(lastpos);
}
*p = save;
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;
lastpos = 0;
- add = 1;
}
}
return val;
}
}
return val;