From eacc63d1fe3c0a5f6b982575867258650f98119b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 13 Sep 2013 19:26:02 +0000 Subject: code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@6056 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Variables/src/parse_math.cpp | 118 ++++++++++++++++------------------- 1 file changed, 55 insertions(+), 63 deletions(-) (limited to 'plugins/Variables/src/parse_math.cpp') diff --git a/plugins/Variables/src/parse_math.cpp b/plugins/Variables/src/parse_math.cpp index 63e11fe8f5..14e2ec6f46 100644 --- a/plugins/Variables/src/parse_math.cpp +++ b/plugins/Variables/src/parse_math.cpp @@ -19,31 +19,33 @@ #include "variables.h" -static TCHAR *parseAdd(ARGUMENTSINFO *ai) { - if (ai->argc < 3) { +static TCHAR *parseAdd(ARGUMENTSINFO *ai) +{ + if (ai->argc < 3) return NULL; - } + int result = 0; - for (unsigned int i=1;iargc;i++) { + for (unsigned int i=1;iargc;i++) result += ttoi(ai->targv[i]); - } + return itot(result); } -static TCHAR *parseDiv(ARGUMENTSINFO *ai) { - if (ai->argc != 3) { +static TCHAR *parseDiv(ARGUMENTSINFO *ai) +{ + if (ai->argc != 3) return NULL; - } int val1 = ttoi(ai->targv[1]); int val2 = ttoi(ai->targv[2]); - if (val2 == 0) { + if (val2 == 0) return NULL; - } + return itot(val1/val2); } -static TCHAR *parseHex(ARGUMENTSINFO *ai) { +static TCHAR *parseHex(ARGUMENTSINFO *ai) +{ unsigned int i; TCHAR szVal[34]; @@ -60,83 +62,75 @@ static TCHAR *parseHex(ARGUMENTSINFO *ai) { ZeroMemory(res, (zeros + _tcslen(szVal) + 3)*sizeof(TCHAR)); _tcscpy(res, _T("0x")); - for (i=0;iargc != 3) { +static TCHAR *parseMod(ARGUMENTSINFO *ai) +{ + if (ai->argc != 3) return NULL; - } + int val1 = ttoi(ai->targv[1]); int val2 = ttoi(ai->targv[2]); - if (val2 == 0) { + if (val2 == 0) return NULL; - } - return itot(val1%val2); + return itot(val1 % val2); } -static TCHAR *parseMul(ARGUMENTSINFO *ai) { - unsigned int i; - - if (ai->argc < 3) { +static TCHAR *parseMul(ARGUMENTSINFO *ai) +{ + if (ai->argc < 3) return NULL; - } + int result = ttoi(ai->targv[1]); - for (i=2;iargc;i++) { + for (unsigned i=2; i < ai->argc; i++) result *= ttoi(ai->targv[i]); - } return itot(result); } -static TCHAR *parseMuldiv(ARGUMENTSINFO *ai) { - - if (ai->argc != 4) { +static TCHAR *parseMuldiv(ARGUMENTSINFO *ai) +{ + if (ai->argc != 4) return NULL; - } - if (ttoi(ai->targv[3]) == 0) { + + if (ttoi(ai->targv[3]) == 0) return NULL; - } return itot((ttoi(ai->targv[1])*ttoi(ai->targv[2]))/ttoi(ai->targv[3])); } -static TCHAR *parseMin(ARGUMENTSINFO *ai) { - unsigned int i; - - if (ai->argc < 2) { +static TCHAR *parseMin(ARGUMENTSINFO *ai) +{ + if (ai->argc < 2) return NULL; - } + int minVal = ttoi(ai->targv[1]); - for (i=2;iargc;i++) { + for (unsigned i=2; i < ai->argc; i++) minVal = min(ttoi(ai->targv[i]), minVal); - } return itot(minVal); } -static TCHAR *parseMax(ARGUMENTSINFO *ai) { - unsigned int i; - - if (ai->argc < 2) { +static TCHAR *parseMax(ARGUMENTSINFO *ai) +{ + if (ai->argc < 2) return NULL; - } + int maxVal = ttoi(ai->targv[1]); - for (i=2;iargc;i++) { + for (unsigned i=2; i < ai->argc; i++) maxVal = max(ttoi(ai->targv[i]), maxVal); - } return itot(maxVal); } -static TCHAR *parseNum(ARGUMENTSINFO *ai) { - unsigned int zeros, i; - +static TCHAR *parseNum(ARGUMENTSINFO *ai) +{ if (ai->argc != 3) return NULL; @@ -146,15 +140,15 @@ static TCHAR *parseNum(ARGUMENTSINFO *ai) { if (szVal == NULL) return NULL; - zeros = max(padding - (signed int)_tcslen(szVal), 0); + unsigned zeros = max(padding - (signed int)_tcslen(szVal), 0); TCHAR *res = (TCHAR*)mir_alloc((zeros + _tcslen(szVal) + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; ZeroMemory(res, (zeros + _tcslen(szVal) + 1)*sizeof(TCHAR)); TCHAR *cur = res; - for (i=0;iargc < 3) { +static TCHAR *parseSub(ARGUMENTSINFO *ai) +{ + if (ai->argc < 3) return NULL; - } + int result = ttoi(ai->targv[1]); - for (i=2;iargc;i++) { + for (unsigned i=2;iargc;i++) result -= ttoi(ai->targv[i]); - } return itot(result); } -int registerMathTokens() { - +int registerMathTokens() +{ registerIntToken(_T(ADD), parseAdd, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y ,...)\t"LPGEN("x + y + ...")); registerIntToken(_T(DIV), parseDiv, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("x divided by y")); registerIntToken(_T(HEX), parseHex, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("converts decimal value x to hex value and padds to length y")); -- cgit v1.2.3