diff options
author | George Hazan <george.hazan@gmail.com> | 2015-06-02 15:55:48 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-06-02 15:55:48 +0000 |
commit | ab53b72bf7067feb9dede0fd76b5a3cbc13863b9 (patch) | |
tree | 677a18bc997d1cf118379b288a7c2dd2c160d9b1 /plugins/Popup/src/formula.cpp | |
parent | 1c229f90bfc6c8032bd2d20e297e97f321eb4db7 (diff) |
- old PNG conversion code (png2dib, dib2png) removed;
- m_png.h also removed;
- all calls of LoadImage replaced with CallService(MS_IMG_LOAD);
- four invalid CloseHandle() calls removed;
- massive code cleaning for Popup, HistoryStats & SplashScreen plugins
git-svn-id: http://svn.miranda-ng.org/main/trunk@13974 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Popup/src/formula.cpp')
-rw-r--r-- | plugins/Popup/src/formula.cpp | 182 |
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;
}
|