diff options
Diffstat (limited to 'plugins/Variables/src/variables.cpp')
-rw-r--r-- | plugins/Variables/src/variables.cpp | 137 |
1 files changed, 56 insertions, 81 deletions
diff --git a/plugins/Variables/src/variables.cpp b/plugins/Variables/src/variables.cpp index 7341259e7d..1b94664d1a 100644 --- a/plugins/Variables/src/variables.cpp +++ b/plugins/Variables/src/variables.cpp @@ -50,63 +50,53 @@ TCHAR *getArguments(TCHAR *string, TCHAR ***aargv, int *aargc) { argc = brackets = 0;
argv = NULL;
cur = string;
- while (*cur == _T(' ')) {
+ while (*cur == ' ')
cur++;
- }
- if (*cur != _T('(')) {
+
+ if (*cur != '(')
return NULL;
- }
+
cur++;
scur = cur-1;
bDontParse = bNewArg = bDone = FALSE;
- while ( (!bDone) && (*cur != _T('\0'))) {
+ while ( (!bDone) && (*cur != 0)) {
switch (*cur) {
- case _T(DONTPARSE_CHAR):
- if (bDontParse) {
- bDontParse = FALSE;
- }
- else {
- bDontParse = TRUE;
- }
+ case DONTPARSE_CHAR:
+ bDontParse = !bDontParse;
break;
- case _T(','):
- if ((!bDontParse) && (brackets == 0)) {
+ case ',':
+ if ((!bDontParse) && (brackets == 0))
bNewArg = TRUE;
- }
break;
- case _T('('):
- if (!bDontParse) {
+ case '(':
+ if (!bDontParse)
brackets += 1;
- }
break;
- case _T(')'):
- if ((brackets == 0) && (!bDontParse)) {
+ case ')':
+ if ((brackets == 0) && (!bDontParse))
bDone = bNewArg = TRUE;
- }
- else if ((brackets > 0) && (!bDontParse)) {
+ else if ((brackets > 0) && (!bDontParse))
brackets -= 1;
- }
break;
}
if (bNewArg) {
argv = ( TCHAR** )mir_realloc(argv, (argc+1)*sizeof(TCHAR*));
- if (argv == NULL) {
+ if (argv == NULL)
return NULL;
- }
+
if (cur > scur) {
argv[argc] = (TCHAR*)mir_alloc((cur-scur+2)*sizeof(TCHAR));
- if (argv[argc] == NULL) {
+ if (argv[argc] == NULL)
return NULL;
- }
+
memset(argv[argc], '\0', (cur-(scur+1)+1)*sizeof(TCHAR));
_tcsncpy(argv[argc], scur+1, cur-(scur+1));
}
- else {
- argv[argc] = mir_tstrdup(_T(""));
- }
+ else argv[argc] = mir_tstrdup(_T(""));
+
argc += 1;
bNewArg = FALSE;
scur = cur;
@@ -114,7 +104,7 @@ TCHAR *getArguments(TCHAR *string, TCHAR ***aargv, int *aargc) { cur++;
}
// set args
- if (*(cur-1) == _T(')')) {
+ if (*(cur-1) == ')') {
*aargv = argv;
*aargc = argc;
}
@@ -135,16 +125,15 @@ TCHAR *getArguments(TCHAR *string, TCHAR ***aargv, int *aargc) { int isValidTokenChar(TCHAR tc) {
- return (
- (tc != _T('(')) &&
- (tc != _T(',')) &&
- (tc != _T(')')) &&
- (tc != _T(FIELD_CHAR)) &&
- (tc != _T(FUNC_CHAR)) &&
- (tc != _T(FUNC_ONCE_CHAR)) &&
- (tc != _T('/')) &&
- (tc != _T('\0'))
- );
+ return
+ (tc != '(') &&
+ (tc != ',') &&
+ (tc != ')') &&
+ (tc != FIELD_CHAR) &&
+ (tc != FUNC_CHAR) &&
+ (tc != FUNC_ONCE_CHAR) &&
+ (tc != '/') &&
+ (tc != 0);
}
/* pretty much the main loop */
@@ -159,7 +148,7 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) **argv, // arguments (dyn alloc)
**pargv, // dyn alloc
*token; // variable name (pnt only)
- int argc = 0, i, tokenLen = 0, scurPos, curPos, tmpVarPos;
+ int argc = 0, i, scurPos, curPos, tmpVarPos;
size_t pos;
FORMATINFO afi;
TOKENREGISTEREX *tr;
@@ -187,16 +176,16 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) if (argv != NULL)
mir_free(argv);
- argc = tokenLen = 0;
+ argc = 0;
tcur = scur = token = parsedToken = NULL;
pargv = argv = NULL;
// new round
- if (*cur == _T(DONTPARSE_CHAR)) {
+ if (*cur == DONTPARSE_CHAR) {
MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR));
- if (*cur == _T(DONTPARSE_CHAR))
+ if (*cur == DONTPARSE_CHAR)
continue;
- while ( (*cur != _T(DONTPARSE_CHAR)) && (*cur != _T('\0')))
+ while ( (*cur != DONTPARSE_CHAR) && (*cur != 0))
cur++;
MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR));
@@ -209,7 +198,7 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) pos = cur-string-1;
continue;
}
- else if (((*cur == _T('\n')) && (gParseOpts.bStripEOL)) || ((*cur == _T(' ')) && (gParseOpts.bStripWS))) {
+ else if ((*cur == '\n' && gParseOpts.bStripEOL) || (*cur == ' ' && gParseOpts.bStripWS)) {
MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR));
pos = cur - string - 1;
continue;
@@ -217,11 +206,11 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) // remove comments
else if (!_tcsncmp(cur, _T(COMMENT_STRING), _tcslen(_T(COMMENT_STRING)))) {
scur = cur;
- while ( (_tcsncmp(cur, _T("\r\n"), 2)) && (*cur != _T('\n')) && (*cur != _T('\0')))
+ while ( _tcsncmp(cur, _T("\r\n"), 2) && *cur != '\n' && *cur != 0)
cur++;
- if (*cur == _T('\0')) {
- *scur = _T('\0');
+ if (*cur == 0) {
+ *scur = 0;
string = (TCHAR*)mir_realloc(string, (_tcslen(string)+1)*sizeof(TCHAR));
continue;
}
@@ -229,7 +218,7 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) pos = scur-string-1;
continue;
}
- else if ((*cur != _T(FIELD_CHAR)) && (*cur != _T(FUNC_CHAR)) && (*cur != _T(FUNC_ONCE_CHAR))) {
+ else if ((*cur != FIELD_CHAR) && (*cur != FUNC_CHAR) && (*cur != FUNC_ONCE_CHAR)) {
if (gParseOpts.bStripAll) {
MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR));
pos = cur - string - 1;
@@ -254,7 +243,7 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) // cur points to FIELD_CHAR or FUNC_CHAR
tmpVarPos = -1;
tr = NULL;
- if (*cur==_T(FIELD_CHAR)) {
+ if (*cur==FIELD_CHAR) {
for(i = 0; i < fi->cbTemporaryVarsSize; i += 2) {
if (lstrcmp(fi->tszaTemporaryVars[i], token) == 0) {
tmpVarPos = i;
@@ -263,7 +252,7 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) }
}
if (tmpVarPos < 0)
- tr = searchRegister(token, (*cur==_T(FIELD_CHAR))?TRF_FIELD:TRF_FUNCTION);
+ tr = searchRegister(token, (*cur==FIELD_CHAR)?TRF_FIELD:TRF_FUNCTION);
mir_free(token);
if (tmpVarPos < 0 && tr == NULL) {
fi->eCount += 1;
@@ -271,16 +260,16 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) continue;
}
scur = cur; // store this pointer for later use
- if (*cur == _T(FIELD_CHAR)) {
+ if (*cur == FIELD_CHAR) {
size_t len = _tcslen(tr != NULL ? tr->tszTokenString : fi->tszaTemporaryVars[tmpVarPos]);
cur++;
- if (*(cur + len) != _T(FIELD_CHAR)) { // the next char after the token should be %
+ if (*(cur + len) != FIELD_CHAR) { // the next char after the token should be %
fi->eCount += 1;
continue;
}
cur += len+1;
}
- else if ((*cur == _T(FUNC_CHAR)) || (*cur == _T(FUNC_ONCE_CHAR))) {
+ else if ((*cur == FUNC_CHAR) || (*cur == FUNC_ONCE_CHAR)) {
TCHAR *argcur;
cur += _tcslen(tr->tszTokenString)+1;
@@ -323,7 +312,7 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) ai.argc = argc+1;
ai.targv = pargv;
ai.fi = fi;
- if ((*scur == _T(FUNC_ONCE_CHAR)) || (*scur == _T(FIELD_CHAR)))
+ if ((*scur == FUNC_ONCE_CHAR) || (*scur == FIELD_CHAR))
ai.flags |= AIF_DONTPARSE;
parsedToken = parseFromRegister(&ai);
@@ -358,7 +347,7 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) size_t parsedTokenLen = _tcslen(parsedToken);
size_t initStrLen = _tcslen(string);
- tokenLen = cur-scur;
+ size_t tokenLen = cur-scur;
scurPos = scur-string;
curPos = cur-string;
if (tokenLen < parsedTokenLen) {
@@ -390,7 +379,7 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) for ( i=0; i < argc; i++ )
if (argv[i] != NULL)
- mir_free( argv[i] );
+ mir_free(argv[i]);
if (argv != NULL)
mir_free(argv);
@@ -401,8 +390,8 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) /*
MS_VARS_FORMATSTRING
*/
-static INT_PTR formatStringService(WPARAM wParam, LPARAM lParam) {
-
+static INT_PTR formatStringService(WPARAM wParam, LPARAM lParam)
+{
INT_PTR res;
int i;
BOOL copied;
@@ -457,25 +446,14 @@ static INT_PTR formatStringService(WPARAM wParam, LPARAM lParam) { res = (INT_PTR)mir_u2a(tRes);
mir_free(tRes);
}
- else {
- res = (INT_PTR)tRes;
- }
+ else res = (INT_PTR)tRes;
if (copied) {
- if (tszFormat != NULL) {
- mir_free(tszFormat);
- }
- if (tszSource != NULL) {
- mir_free(tszSource);
- }
- for(i = 0; i < fi->cbTemporaryVarsSize; i++) {
- if (fi->tszaTemporaryVars != NULL) {
- mir_free(fi->tszaTemporaryVars);
- }
- }
+ mir_free(tszFormat);
+ mir_free(tszSource);
+ for(i = 0; i < fi->cbTemporaryVarsSize; i++)
+ mir_free(fi->tszaTemporaryVars);
}
- //fi->tszFormat = orgFormat;
- //fi->tszExtraText = orgSource;
if (((FORMATINFO *)wParam)->cbSize == sizeof(FORMATINFOV1)) {
((FORMATINFOV1 *)wParam)->eCount = fi->eCount;
@@ -485,7 +463,6 @@ static INT_PTR formatStringService(WPARAM wParam, LPARAM lParam) { ((FORMATINFO *)wParam)->eCount = fi->eCount;
((FORMATINFO *)wParam)->pCount = fi->pCount;
}
-// clearVariableRegister();?
return res;
}
@@ -519,9 +496,7 @@ int setParseOptions(struct ParseOptions *po) po->bStripEOL = db_get_b(NULL, MODULENAME, SETTING_STRIPCRLF, 0);
po->bStripWS = db_get_b(NULL, MODULENAME, SETTING_STRIPWS, 0);
}
- else {
- po->bStripAll = TRUE;
- }
+ else po->bStripAll = TRUE;
return 0;
}
|