summaryrefslogtreecommitdiff
path: root/plugins/Popup/src/formula.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Popup/src/formula.cpp')
-rw-r--r--plugins/Popup/src/formula.cpp182
1 files changed, 71 insertions, 111 deletions
diff --git a/plugins/Popup/src/formula.cpp b/plugins/Popup/src/formula.cpp
index cbd59163fd..2448fbb1fd 100644
--- a/plugins/Popup/src/formula.cpp
+++ b/plugins/Popup/src/formula.cpp
@@ -31,30 +31,21 @@ static inline bool myisspace(char ch)
int Formula::eval_neq(TCHAR *&s, Args *args, bool *vars) const
{
int left = eval_sum(s, args, vars);
- while (*s)
- {
- if (myisspace(*s))
- {
+ while (*s) {
+ if (myisspace(*s)) {
++s;
}
- else
- if (*s == '<')
- {
- // this is needed due to side effects caused by min() macro...
- int tmp = eval_sum(++s, args, vars);
- left = min(left, tmp);
- }
- else
- if (*s == '>')
- {
- // this is needed due to side effects caused by max() macro...
- int tmp = eval_sum(++s, args, vars);
- left = max(left, tmp);
- }
- else
- {
- break;
- }
+ else if (*s == '<') {
+ // this is needed due to side effects caused by min() macro...
+ int tmp = eval_sum(++s, args, vars);
+ left = min(left, tmp);
+ }
+ else if (*s == '>') {
+ // this is needed due to side effects caused by max() macro...
+ int tmp = eval_sum(++s, args, vars);
+ left = max(left, tmp);
+ }
+ else break;
}
return left;
}
@@ -62,26 +53,17 @@ int Formula::eval_neq(TCHAR *&s, Args *args, bool *vars) const
int Formula::eval_sum(TCHAR *&s, Args *args, bool *vars) const
{
int left = eval_mul(s, args, vars);
- while (*s)
- {
- if (myisspace(*s))
- {
+ while (*s) {
+ if (myisspace(*s)) {
++s;
}
- else
- if (*s == '+')
- {
- left += eval_mul(++s, args, vars);
- }
- else
- if (*s == '-')
- {
- left -= eval_mul(++s, args, vars);
- }
- else
- {
- break;
- }
+ else if (*s == '+') {
+ left += eval_mul(++s, args, vars);
+ }
+ else if (*s == '-') {
+ left -= eval_mul(++s, args, vars);
+ }
+ else break;
}
return left;
}
@@ -89,87 +71,65 @@ int Formula::eval_sum(TCHAR *&s, Args *args, bool *vars) const
int Formula::eval_mul(TCHAR *&s, Args *args, bool *vars) const
{
int left = eval_atom(s, args, vars);
- while (*s)
- {
- if (myisspace(*s))
- {
+ while (*s) {
+ if (myisspace(*s)) {
++s;
}
- else
- if (*s == '*')
- {
- left *= eval_atom(++s, args, vars);
- }
- else
- if (*s == '/')
- {
- if (int right = eval_atom(++s, args, vars))
- left /= right;
- }
- else
- if (*s == '%')
- {
- if (int right = eval_atom(++s, args, vars))
- left %= right;
- }
- else
- {
- break;
- }
+ else if (*s == '*') {
+ left *= eval_atom(++s, args, vars);
+ }
+ else if (*s == '/') {
+ if (int right = eval_atom(++s, args, vars))
+ left /= right;
+ }
+ else if (*s == '%') {
+ if (int right = eval_atom(++s, args, vars))
+ left %= right;
+ }
+ else break;
}
return left;
}
int Formula::eval_atom(TCHAR *&s, Args *args, bool *vars) const
{
- while (*s)
- {
- if (myisspace(*s))
- {
+ while (*s) {
+ if (myisspace(*s)) {
++s;
}
- else
- if (*s == '(')
- {
- int res = eval_neq(++s, args, vars);
- if (*s == ')')
- ++s;
- return res;
- }
- else
- if ((*s == '+') || (*s == '-'))
- {
- int sign = 1;
- if (*s == '-')
- sign = -1;
- return sign * eval_neq(++s, args, vars);
- }
- else
- if (*s == '!')
- {
- return !eval_neq(++s, args, vars);
- }
- else
- if ((*s >= '0') && (*s <= '9'))
- {
- int res = 0;
- while ((*s >= '0') && (*s <= '9'))
- res = res * 10 + *s++ - '0';
- return res;
- }
- else
- {
- if (!args)
- return 0;
- char buf[1024];
- char *bufptr = buf;
- while (((*s >= '0') && (*s <= '9')) || ((*s >= 'a') && (*s <= 'z')) || ((*s >= 'A') && (*s <= 'A')) || (*s == '_') || (*s == '.'))
- *bufptr++ = *s++;
- *bufptr = 0;
- int res = args->get(buf);
- if (vars) *vars = true;
- return res;
- }
+ else if (*s == '(') {
+ int res = eval_neq(++s, args, vars);
+ if (*s == ')')
+ ++s;
+ return res;
+ }
+ else if ((*s == '+') || (*s == '-')) {
+ int sign = 1;
+ if (*s == '-')
+ sign = -1;
+ return sign * eval_neq(++s, args, vars);
+ }
+ else if (*s == '!') {
+ return !eval_neq(++s, args, vars);
+ }
+ else if ((*s >= '0') && (*s <= '9')) {
+ int res = 0;
+ while ((*s >= '0') && (*s <= '9'))
+ res = res * 10 + *s++ - '0';
+ return res;
+ }
+ else {
+ if (!args)
+ return 0;
+ char buf[1024];
+ char *bufptr = buf;
+ while (((*s >= '0') && (*s <= '9')) || ((*s >= 'a') && (*s <= 'z')) || ((*s >= 'A') && (*s <= 'A')) || (*s == '_') || (*s == '.'))
+ *bufptr++ = *s++;
+ *bufptr = 0;
+ int res = args->get(buf);
+ if (vars) *vars = true;
+ return res;
+ }
}
return 0;
}