summaryrefslogtreecommitdiff
path: root/plugins/Variables
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Variables')
-rw-r--r--plugins/Variables/src/contact.cpp52
-rw-r--r--plugins/Variables/src/parse_alias.cpp18
-rw-r--r--plugins/Variables/src/parse_alias.h17
-rw-r--r--plugins/Variables/src/stdafx.h1
-rw-r--r--plugins/Variables/src/variables.cpp398
5 files changed, 206 insertions, 280 deletions
diff --git a/plugins/Variables/src/contact.cpp b/plugins/Variables/src/contact.cpp
index ecd0da1e65..e4b681c1dd 100644
--- a/plugins/Variables/src/contact.cpp
+++ b/plugins/Variables/src/contact.cpp
@@ -76,13 +76,8 @@ static builtinCnfs[] =
/* contact cache entry */
struct CONTACTCE
{
- ~CONTACTCE()
- {
- mir_free(tszContact);
- }
-
+ int flags;
TCHAR* tszContact;
- int flags;
MCONTACT hContact;
};
@@ -98,9 +93,7 @@ static int SortContactCache(const CONTACTCE *p1, const CONTACTCE *p2)
static OBJLIST<CONTACTCE> arContactCache(20, SortContactCache);
static mir_cs csContactCache;
-/*
- converts a string into a CNF_ type
-*/
+// converts a string into a CNF_ type
BYTE getContactInfoType(TCHAR* type)
{
if (type == NULL || mir_tstrlen(type) == 0)
@@ -113,9 +106,7 @@ BYTE getContactInfoType(TCHAR* type)
return 0;
}
-/*
- returns info about a contact as a string
-*/
+// returns info about a contact as a string
TCHAR* getContactInfoT(BYTE type, MCONTACT hContact)
{
/* returns dynamic allocated buffer with info, or NULL if failed */
@@ -138,12 +129,10 @@ TCHAR* getContactInfoT(BYTE type, MCONTACT hContact)
}
case CCNF_PROTOCOL:
- {
- char protoname[128];
- if (CallProtoService(szProto, PS_GETNAME, (WPARAM)sizeof(protoname), (LPARAM)protoname))
- return NULL;
- return mir_a2t(protoname);
- }
+ char protoname[128];
+ if (CallProtoService(szProto, PS_GETNAME, (WPARAM)sizeof(protoname), (LPARAM)protoname))
+ return NULL;
+ return mir_a2t(protoname);
case CCNF_STATUS:
return mir_tstrdup(pcli->pfnGetStatusModeDescription(db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE), 0));
@@ -152,13 +141,13 @@ TCHAR* getContactInfoT(BYTE type, MCONTACT hContact)
case CCNF_EXTERNALIP:
{
DWORD ip = db_get_dw(hContact, szProto, (type == CCNF_INTERNALIP) ? "RealIP" : "IP", 0);
- if (ip == 0)
- return NULL;
-
- struct in_addr in;
- in.s_addr = htonl(ip);
- return mir_a2t(inet_ntoa(in));
+ if (ip != 0) {
+ struct in_addr in;
+ in.s_addr = htonl(ip);
+ return mir_a2t(inet_ntoa(in));
+ }
}
+ return NULL;
case CCNF_GROUP:
if ((res = db_get_tsa(hContact, "CList", "Group")) != NULL)
@@ -203,9 +192,7 @@ TCHAR* getContactInfoT(BYTE type, MCONTACT hContact)
return NULL;
}
-/*
- MS_VARS_GETCONTACTFROMSTRING
-*/
+// MS_VARS_GETCONTACTFROMSTRING
MCONTACT getContactFromString(const TCHAR *tszContact, DWORD dwFlags, int nMatch)
{
/* service to retrieve a contact's HANDLE from a given string */
@@ -219,9 +206,9 @@ MCONTACT getContactFromString(const TCHAR *tszContact, DWORD dwFlags, int nMatch
}
else bReturnCount = false;
- /* search the cache */
+ // search the cache
{
- CONTACTCE tmp = { (TCHAR*)tszContact, dwFlags, 0 };
+ CONTACTCE tmp = { dwFlags, (TCHAR*)tszContact, 0 };
mir_cslock lck(csContactCache);
CONTACTCE *p = arContactCache.find(&tmp);
@@ -229,11 +216,11 @@ MCONTACT getContactFromString(const TCHAR *tszContact, DWORD dwFlags, int nMatch
return (bReturnCount) ? 1 : p->hContact; // found in cache
}
- /* contact was not in cache, do a search */
+ // contact was not in cache, do a search
CMString tmp;
int count = 0;
MCONTACT hContact;
- LIST<void> arResults(0);
+ LIST<void> arResults(1);
for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
// <_HANDLE_:hContact>
@@ -369,6 +356,7 @@ static int contactSettingChanged(WPARAM hContact, LPARAM lParam)
(isUid && (cce.flags & CI_UNIQUEID)))
{
/* remove from cache */
+ mir_free(cce.tszContact);
arContactCache.remove(i);
break;
}
@@ -384,6 +372,8 @@ int initContactModule()
int deinitContactModule()
{
+ for (int i = 0; i < arContactCache.getCount(); i++)
+ mir_free(arContactCache[i].tszContact);
arContactCache.destroy();
return 0;
}
diff --git a/plugins/Variables/src/parse_alias.cpp b/plugins/Variables/src/parse_alias.cpp
index c3c3b38282..f6f217dcbb 100644
--- a/plugins/Variables/src/parse_alias.cpp
+++ b/plugins/Variables/src/parse_alias.cpp
@@ -30,7 +30,7 @@ struct ALIASREGISTER
static LIST<ALIASREGISTER> arAliases(5);
static mir_cs csAliasRegister;
-static ALIASREGISTER *searchAliasRegister(TCHAR *szAlias)
+static ALIASREGISTER* searchAliasRegister(TCHAR *szAlias)
{
if (szAlias == NULL || *szAlias == 0)
return NULL;
@@ -148,24 +148,24 @@ static TCHAR *parseAddAlias(ARGUMENTSINFO *ai)
ptrT alias(mir_tstrndup(ai->targv[1], cur - ai->targv[1]));
- int argc;
- TCHAR **argv;
- getArguments(cur, &argv, &argc);
+ TArgList argv;
+ getArguments(cur, argv);
+
deRegisterToken(alias);
- addToAliasRegister(alias, argc, argv, ai->targv[2]);
+ addToAliasRegister(alias, argv.getCount(), argv.getArray(), ai->targv[2]);
TCHAR *szArgs = NULL;
- for (int i = 0; i < argc; i++) {
+ for (int i = 0; i < argv.getCount(); i++) {
if (i == 0)
szArgs = (TCHAR*)mir_calloc((mir_tstrlen(argv[i]) + 2)*sizeof(TCHAR));
else
szArgs = (TCHAR*)mir_realloc(szArgs, (mir_tstrlen(szArgs) + mir_tstrlen(argv[i]) + 2)*sizeof(TCHAR));
mir_tstrcat(szArgs, argv[i]);
- if (i != argc - 1)
+ if (i != argv.getCount() - 1)
mir_tstrcat(szArgs, _T(","));
}
int res;
- if (szArgs != NULL && argc > 0) {
+ if (szArgs != NULL && argv.getCount() > 0) {
szArgsA = mir_t2a(szArgs);
size_t size = 32 + mir_strlen(szArgsA);
@@ -183,7 +183,7 @@ static TCHAR *parseAddAlias(ARGUMENTSINFO *ai)
}
mir_free(szArgs);
mir_free(szHelp);
- mir_free(argv);
+ argv.destroy();
return (res == 0) ? mir_tstrdup(_T("")) : NULL;
}
diff --git a/plugins/Variables/src/parse_alias.h b/plugins/Variables/src/parse_alias.h
index 0ac0c09779..5e708b32be 100644
--- a/plugins/Variables/src/parse_alias.h
+++ b/plugins/Variables/src/parse_alias.h
@@ -20,4 +20,19 @@
#define ADDALIAS _T("alias")
int isValidTokenChar(TCHAR tc);
-TCHAR *getArguments(TCHAR *string, TCHAR ***aargv, int *aargc);
+
+struct TArgList : public LIST<TCHAR>
+{
+ TArgList() :
+ LIST<TCHAR>(1)
+ {}
+
+ void destroy()
+ {
+ for (int i = 0; i < count; i++)
+ mir_free(items[i]);
+ count = 0;
+ }
+};
+
+TCHAR* getArguments(TCHAR *string, TArgList &aargv);
diff --git a/plugins/Variables/src/stdafx.h b/plugins/Variables/src/stdafx.h
index 5968340da7..ef504b4e02 100644
--- a/plugins/Variables/src/stdafx.h
+++ b/plugins/Variables/src/stdafx.h
@@ -152,7 +152,6 @@ extern struct ParseOptions gParseOpts;
extern int hLangpack;
// variables.c
-//TCHAR *getArguments(char *string, char ***aargv, int *aargc);
//int isValidTokenChar(char c);
TCHAR *formatString(FORMATINFO *fi);
int setParseOptions(struct ParseOptions *po);
diff --git a/plugins/Variables/src/variables.cpp b/plugins/Variables/src/variables.cpp
index 7eac85270e..5d823b942e 100644
--- a/plugins/Variables/src/variables.cpp
+++ b/plugins/Variables/src/variables.cpp
@@ -1,21 +1,21 @@
/*
- Variables Plugin for Miranda-IM (www.miranda-im.org)
- Copyright 2003-2006 P. Boon
-
- This program is mir_free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
+ Variables Plugin for Miranda-IM (www.miranda-im.org)
+ Copyright 2003-2006 P. Boon
+
+ This program is mir_free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
#include "stdafx.h"
@@ -36,27 +36,20 @@ HCURSOR hCurSplitNS;
struct ParseOptions gParseOpts;
-TCHAR* getArguments(TCHAR *string, TCHAR ***aargv, int *aargc)
+TCHAR* getArguments(TCHAR *string, TArgList &argv)
{
- BOOL bDontParse, bNewArg, bDone;
- TCHAR *cur, *scur, **argv;
- int i, argc, brackets;
-
- *aargv = NULL;
- *aargc = 0;
- argc = brackets = 0;
- argv = NULL;
- cur = string;
+ TCHAR *cur = string;
while (*cur == ' ')
cur++;
if (*cur != '(')
return NULL;
+ TCHAR *scur = cur;
cur++;
- scur = cur-1;
- bDontParse = bNewArg = bDone = FALSE;
- while ( (!bDone) && (*cur != 0)) {
+ int brackets = 0;
+ bool bDontParse = false, bNewArg = false, bDone = false;
+ while (!bDone && *cur != 0) {
switch (*cur) {
case DONTPARSE_CHAR:
bDontParse = !bDontParse;
@@ -64,7 +57,7 @@ TCHAR* getArguments(TCHAR *string, TCHAR ***aargv, int *aargc)
case ',':
if ((!bDontParse) && (brackets == 0))
- bNewArg = TRUE;
+ bNewArg = true;
break;
case '(':
@@ -73,58 +66,40 @@ TCHAR* getArguments(TCHAR *string, TCHAR ***aargv, int *aargc)
break;
case ')':
- if ((brackets == 0) && (!bDontParse))
+ if (brackets == 0 && !bDontParse)
bDone = bNewArg = TRUE;
- else if ((brackets > 0) && (!bDontParse))
+ else if (brackets > 0 && !bDontParse)
brackets--;
break;
}
+
if (bNewArg) {
- argv = ( TCHAR** )mir_realloc(argv, (argc+1)*sizeof(TCHAR*));
- if (argv == NULL)
- return NULL;
-
- if (cur > scur) {
- argv[argc] = (TCHAR*)mir_alloc((cur-scur+2)*sizeof(TCHAR));
- if (argv[argc] == NULL) {
- mir_free(argv);
- 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(""));
-
- argc++;
- bNewArg = FALSE;
+ TCHAR *tszArg = NULL;
+ if (cur > scur)
+ tszArg = mir_tstrndup(scur + 1, cur - (scur + 1));
+ if (tszArg == NULL)
+ tszArg = mir_tstrdup(_T(""));
+ argv.insert(tszArg);
+
+ bNewArg = false;
scur = cur;
}
cur++;
}
+
// set args
- if (*(cur-1) == ')') {
- *aargv = argv;
- *aargc = argc;
- }
- else {
- for (i=0;i<argc;i++) {
- if (argv[i] != NULL) {
- mir_free(argv[i]);
- }
- }
- mir_free(argv);
- *aargv = NULL;
- *aargc = 0;
- cur = NULL;
+ if (cur[-1] != ')') {
+ argv.destroy();
+ return NULL;
}
return cur;
}
-int isValidTokenChar(TCHAR tc) {
+int isValidTokenChar(TCHAR tc)
+{
- return
+ return
(tc != '(') &&
(tc != ',') &&
(tc != ')') &&
@@ -136,90 +111,74 @@ int isValidTokenChar(TCHAR tc) {
}
/* pretty much the main loop */
-static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi)
+static TCHAR* replaceDynVars(FORMATINFO *fi)
{
- TCHAR
- *string,
- *cur, // current position (pnt only)
- *tcur, // temp cur (pnt only)
- *scur, // start of variable(pnt only)
- *parsedToken, // parsed result (dyn alloc)
- **argv, // arguments (dyn alloc)
- **pargv, // dyn alloc
- *token; // variable name (pnt only)
- int argc = 0, i, scurPos, curPos, tmpVarPos;
- size_t pos;
- FORMATINFO afi;
- TOKENREGISTEREX *tr;
- ARGUMENTSINFO ai = { 0 };
+ if (fi->tszFormat == NULL)
+ return NULL;
+
+ int i, scurPos, curPos, tmpVarPos;
- string = mir_tstrdup(szTemplate);
+ TCHAR *string = mir_tstrdup(fi->tszFormat);
if (string == NULL)
return NULL;
- cur = tcur = scur = token = parsedToken = NULL;
- pargv = argv = NULL;
- //fi->pCount = 0;
+ TArgList argv;
+
+ FORMATINFO afi;
memcpy(&afi, fi, sizeof(afi));
- for (pos = 0; pos < mir_tstrlen(string); pos++) {
+
+ for (size_t pos = 0; pos < mir_tstrlen(string); pos++) {
// string may move in memory, iterate by remembering the position in the string
- cur = string+pos;
- // mir_free memory from last iteration, this way we can bail out at any time in the loop
- mir_free(parsedToken);
-
- for (i = 0; i < argc; i ++)
- mir_free(argv[i]);
- mir_free(argv);
- argc = 0;
- tcur = scur = token = parsedToken = NULL;
- pargv = argv = NULL;
+ TCHAR *cur = string + pos;
+
// new round
if (*cur == DONTPARSE_CHAR) {
- memmove(cur, cur+1, (mir_tstrlen(cur+1)+1)*sizeof(TCHAR));
+ memmove(cur, cur + 1, (mir_tstrlen(cur + 1) + 1)*sizeof(TCHAR));
if (*cur == DONTPARSE_CHAR)
continue;
- while ( (*cur != DONTPARSE_CHAR) && (*cur != 0))
+ while ((*cur != DONTPARSE_CHAR) && (*cur != 0))
cur++;
- memmove(cur, cur+1, (mir_tstrlen(cur+1)+1)*sizeof(TCHAR));
- pos = cur-string-1;
+ memmove(cur, cur + 1, (mir_tstrlen(cur + 1) + 1)*sizeof(TCHAR));
+ pos = cur - string - 1;
continue;
}
// remove end of lines
else if ((!_tcsncmp(cur, _T("\r\n"), 2)) && (gParseOpts.bStripEOL)) {
- memmove(cur, cur+2, (mir_tstrlen(cur+2)+1)*sizeof(TCHAR));
- pos = cur-string-1;
+ memmove(cur, cur + 2, (mir_tstrlen(cur + 2) + 1)*sizeof(TCHAR));
+ pos = cur - string - 1;
continue;
}
else if ((*cur == '\n' && gParseOpts.bStripEOL) || (*cur == ' ' && gParseOpts.bStripWS)) {
- memmove(cur, cur+1, (mir_tstrlen(cur+1)+1)*sizeof(TCHAR));
+ memmove(cur, cur + 1, (mir_tstrlen(cur + 1) + 1)*sizeof(TCHAR));
pos = cur - string - 1;
continue;
}
// remove comments
else if (!_tcsncmp(cur, _T(COMMENT_STRING), mir_tstrlen(_T(COMMENT_STRING)))) {
- scur = cur;
- while ( _tcsncmp(cur, _T("\r\n"), 2) && *cur != '\n' && *cur != 0)
+ TCHAR *scur = cur;
+ while (_tcsncmp(cur, _T("\r\n"), 2) && *cur != '\n' && *cur != 0)
cur++;
if (*cur == 0) {
*scur = 0;
- string = (TCHAR*)mir_realloc(string, (mir_tstrlen(string)+1)*sizeof(TCHAR));
+ string = (TCHAR*)mir_realloc(string, (mir_tstrlen(string) + 1)*sizeof(TCHAR));
continue;
}
- memmove(scur, cur, (mir_tstrlen(cur)+1)*sizeof(TCHAR));
- pos = scur-string-1;
+ memmove(scur, cur, (mir_tstrlen(cur) + 1)*sizeof(TCHAR));
+ pos = scur - string - 1;
continue;
}
else if ((*cur != FIELD_CHAR) && (*cur != FUNC_CHAR) && (*cur != FUNC_ONCE_CHAR)) {
if (gParseOpts.bStripAll) {
- memmove(cur, cur+1, (mir_tstrlen(cur+1)+1)*sizeof(TCHAR));
+ memmove(cur, cur + 1, (mir_tstrlen(cur + 1) + 1)*sizeof(TCHAR));
pos = cur - string - 1;
}
continue;
}
- scur = tcur = cur+1;
+
+ TCHAR *scur = cur + 1, *tcur = scur;
while (isValidTokenChar(*tcur))
tcur++;
@@ -227,155 +186,123 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi)
fi->eCount++;
continue;
}
- token = (TCHAR*)mir_alloc((tcur-scur+1)*sizeof(TCHAR));
- if (token == NULL) {
- fi->eCount++;
- return NULL;
+
+ TOKENREGISTEREX *tr = NULL;
+ {
+ ptrT token(mir_tstrndup(cur + 1, tcur - scur));
+
+ // cur points to FIELD_CHAR or FUNC_CHAR
+ tmpVarPos = -1;
+ if (*cur == FIELD_CHAR) {
+ for (i = 0; i < fi->cbTemporaryVarsSize; i += 2) {
+ if (!mir_tstrcmp(fi->tszaTemporaryVars[i], token)) {
+ tmpVarPos = i;
+ break;
+ }
+ }
+ }
+
+ if (tmpVarPos < 0)
+ tr = searchRegister(token, (*cur == FIELD_CHAR) ? TRF_FIELD : TRF_FUNCTION);
}
- memset(token, '\0', (tcur-scur+1)*sizeof(TCHAR));
- _tcsncpy(token, cur+1, tcur-scur);
- // cur points to FIELD_CHAR or FUNC_CHAR
- tmpVarPos = -1;
- tr = NULL;
- if (*cur==FIELD_CHAR) {
- for(i = 0; i < fi->cbTemporaryVarsSize; i += 2) {
- if (mir_tstrcmp(fi->tszaTemporaryVars[i], token) == 0) {
- tmpVarPos = i;
- break;
- }
- }
- }
- if (tmpVarPos < 0)
- tr = searchRegister(token, (*cur==FIELD_CHAR)?TRF_FIELD:TRF_FUNCTION);
- mir_free(token);
- if (tmpVarPos < 0 && tr == NULL) {
+
+ if (tmpVarPos < 0 && tr == NULL) {
fi->eCount++;
// token not found, continue
continue;
}
+
scur = cur; // store this pointer for later use
if (*cur == FIELD_CHAR) {
- size_t len = mir_tstrlen(tr != NULL ? tr->tszTokenString : fi->tszaTemporaryVars[tmpVarPos]);
+ size_t len = mir_tstrlen(tr != NULL ? tr->tszTokenString : fi->tszaTemporaryVars[tmpVarPos]);
cur++;
- if (*(cur + len) != 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++;
continue;
}
- cur += len+1;
+ cur += len + 1;
}
else if ((*cur == FUNC_CHAR) || (*cur == FUNC_ONCE_CHAR)) {
- TCHAR *argcur;
-
- cur += mir_tstrlen(tr->tszTokenString)+1;
- argcur = getArguments(cur, &argv, &argc);
- if ((argcur == cur) || (argcur == NULL)) {
+ cur += mir_tstrlen(tr->tszTokenString) + 1;
+ TCHAR *argcur = getArguments(cur, argv);
+ if (argcur == cur || argcur == NULL) {
fi->eCount++;
// error getting arguments
continue;
}
cur = argcur;
// arguments
- for (i=0;i<argc;i++) {
- if (argv[i] != NULL) {
- if (!(tr->flags&TRF_UNPARSEDARGS)) {
- afi.tszFormat = argv[i];
- afi.eCount = afi.pCount = 0;
- argv[i] = formatString(&afi);
- fi->eCount += afi.eCount;
- fi->pCount += afi.pCount;
- mir_free(afi.szFormat);
- }
- }
- if (argv[i] == NULL)
- argv[i] = mir_tstrdup(_T(""));
+ for (i = 0; i < argv.getCount(); i++) {
+ if (tr->flags & TRF_UNPARSEDARGS)
+ continue;
+
+ afi.tszFormat = argv[i];
+ afi.eCount = afi.pCount = 0;
+ argv.put(i, formatString(&afi));
+ fi->eCount += afi.eCount;
+ fi->pCount += afi.pCount;
+ mir_free(afi.szFormat);
}
}
+
// cur should now point at the character after FIELD_CHAR or after the last ')'
- if (tr != NULL) {
- pargv = ( TCHAR** )mir_alloc((argc+1)*sizeof(TCHAR*));
- if (pargv == NULL) {
- fi->eCount++;
- return NULL;
- }
- for (i=0;i<argc;i++)
- pargv[i+1] = argv[i];
-
- pargv[0] = tr->tszTokenString;
- memset(&ai, 0, sizeof(ai));
- ai.cbSize = sizeof(ai);
- ai.argc = argc+1;
- ai.targv = pargv;
- ai.fi = fi;
- if ((*scur == FUNC_ONCE_CHAR) || (*scur == FIELD_CHAR))
- ai.flags |= AIF_DONTPARSE;
-
- parsedToken = parseFromRegister(&ai);
- mir_free(pargv);
- }
- else parsedToken = fi->tszaTemporaryVars[tmpVarPos + 1];
+ ARGUMENTSINFO ai = { 0 };
+ ptrT parsedToken;
+ if (tr != NULL) {
+ argv.insert(mir_tstrdup(tr->tszTokenString), 0);
+
+ ai.cbSize = sizeof(ai);
+ ai.argc = argv.getCount();
+ ai.targv = argv.getArray();
+ ai.fi = fi;
+ if ((*scur == FUNC_ONCE_CHAR) || (*scur == FIELD_CHAR))
+ ai.flags |= AIF_DONTPARSE;
+
+ parsedToken = parseFromRegister(&ai);
+ }
+ else parsedToken = mir_tstrdup(fi->tszaTemporaryVars[tmpVarPos + 1]);
+
+ argv.destroy();
if (parsedToken == NULL) {
fi->eCount++;
continue;
}
- //replaced a var
- if (ai.flags & AIF_FALSE )
+ // replaced a var
+ if (ai.flags & AIF_FALSE)
fi->eCount++;
else
fi->pCount++;
- // 'special' chars need to be taken care of (DONTPARSE, TRYPARSE, \r\n)
- // if the var contains the escape character, this character must be doubled, we don't want it to act as an esacpe char
- /*for (tcur=parsedToken;*tcur != '\0';tcur++) {
- if (*tcur == DONTPARSE_CHAR) {//|| (*(var+pos) == ')')) {
- parsedToken = mir_realloc(parsedToken, mir_strlen(parsedToken) + 2);
- if (parsedToken == NULL) {
- fi->err = EMEM;
- return NULL;
- }
- memcpy(tcur+1, tcur, mir_strlen(tcur)+1);
- tcur++;
- }
- }*/
-
size_t parsedTokenLen = mir_tstrlen(parsedToken);
size_t initStrLen = mir_tstrlen(string);
- size_t tokenLen = cur-scur;
- scurPos = scur-string;
- curPos = cur-string;
+ size_t tokenLen = cur - scur;
+ scurPos = scur - string;
+ curPos = cur - string;
if (tokenLen < parsedTokenLen) {
// string needs more memory
- string = (TCHAR*)mir_realloc(string, (initStrLen-tokenLen+parsedTokenLen+1)*sizeof(TCHAR));
+ string = (TCHAR*)mir_realloc(string, (initStrLen - tokenLen + parsedTokenLen + 1)*sizeof(TCHAR));
if (string == NULL) {
fi->eCount++;
return NULL;
}
}
- scur = string+scurPos;
- cur = string+curPos;
- memmove(scur + parsedTokenLen, cur, (mir_tstrlen(cur)+1)*sizeof(TCHAR));
+ scur = string + scurPos;
+ cur = string + curPos;
+ memmove(scur + parsedTokenLen, cur, (mir_tstrlen(cur) + 1)*sizeof(TCHAR));
memcpy(scur, parsedToken, parsedTokenLen*sizeof(TCHAR));
{
size_t len = mir_tstrlen(string);
- string = (TCHAR*)mir_realloc(string, (len+1)*sizeof(TCHAR));
+ string = (TCHAR*)mir_realloc(string, (len + 1)*sizeof(TCHAR));
}
- if (( ai.flags & AIF_DONTPARSE ) || tmpVarPos >= 0)
+ if ((ai.flags & AIF_DONTPARSE) || tmpVarPos >= 0)
pos += parsedTokenLen;
pos--; // parse the same pos again, it changed
-
- if (tr == NULL)
- parsedToken = NULL; // To avoid mir_free
}
- if (parsedToken != NULL)
- mir_free(parsedToken);
- for (i = 0; i < argc; i ++)
- mir_free(argv[i]);
- mir_free(argv);
-
- return (TCHAR*)mir_realloc(string, (mir_tstrlen(string)+1)*sizeof(TCHAR));
+ return (TCHAR*)mir_realloc(string, (mir_tstrlen(string) + 1)*sizeof(TCHAR));
}
/*
@@ -383,22 +310,22 @@ static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi)
*/
static INT_PTR formatStringService(WPARAM wParam, LPARAM)
{
- INT_PTR res;
- int i;
- BOOL copied;
+ INT_PTR res;
+ int i;
+ BOOL copied;
FORMATINFO *fi, tempFi;
TCHAR *tszFormat, *orgFormat, *tszSource, *orgSource, *tRes;
- if (((FORMATINFO *)wParam)->cbSize >= sizeof(FORMATINFO)) {
+ if (((FORMATINFO *)wParam)->cbSize >= sizeof(FORMATINFO)) {
memset(&tempFi, 0, sizeof(FORMATINFO));
memcpy(&tempFi, (FORMATINFO *)wParam, sizeof(FORMATINFO));
fi = &tempFi;
}
- else if (((FORMATINFO *)wParam)->cbSize == FORMATINFOV2_SIZE) {
- memset(&tempFi, 0, sizeof(FORMATINFO));
- memcpy(&tempFi, (FORMATINFO *)wParam, FORMATINFOV2_SIZE);
- fi = &tempFi;
- }
+ else if (((FORMATINFO *)wParam)->cbSize == FORMATINFOV2_SIZE) {
+ memset(&tempFi, 0, sizeof(FORMATINFO));
+ memcpy(&tempFi, (FORMATINFO *)wParam, FORMATINFOV2_SIZE);
+ fi = &tempFi;
+ }
else {
// old struct, must be ANSI
FORMATINFOV1 *fiv1 = (FORMATINFOV1 *)wParam;
@@ -413,18 +340,18 @@ static INT_PTR formatStringService(WPARAM wParam, LPARAM)
orgSource = fi->tszExtraText;
if (!(fi->flags&FIF_TCHAR)) {
- copied = TRUE;
+ copied = TRUE;
log_debugA("mir_a2t (%s)", fi->szExtraText);
- tszFormat = fi->szFormat!=NULL?mir_a2t(fi->szFormat):NULL;
- tszSource = fi->szExtraText!=NULL?mir_a2t(fi->szExtraText):NULL;
- for(i = 0; i < fi->cbTemporaryVarsSize; i++) {
- fi->tszaTemporaryVars[i] = fi->szaTemporaryVars[i]!=NULL?mir_a2t(fi->szaTemporaryVars[i]):NULL;
- }
+ tszFormat = fi->szFormat != NULL ? mir_a2t(fi->szFormat) : NULL;
+ tszSource = fi->szExtraText != NULL ? mir_a2t(fi->szExtraText) : NULL;
+ for (i = 0; i < fi->cbTemporaryVarsSize; i++) {
+ fi->tszaTemporaryVars[i] = fi->szaTemporaryVars[i] != NULL ? mir_a2t(fi->szaTemporaryVars[i]) : NULL;
+ }
}
else {
- copied = FALSE;
- tszFormat = fi->tszFormat;
- tszSource = fi->tszExtraText;
+ copied = FALSE;
+ tszFormat = fi->tszFormat;
+ tszSource = fi->tszExtraText;
}
fi->tszFormat = tszFormat;
@@ -438,12 +365,12 @@ static INT_PTR formatStringService(WPARAM wParam, LPARAM)
}
else res = (INT_PTR)tRes;
- if (copied) {
+ if (copied) {
mir_free(tszFormat);
mir_free(tszSource);
- for(i = 0; i < fi->cbTemporaryVarsSize; i++)
+ for (i = 0; i < fi->cbTemporaryVarsSize; i++)
mir_free(fi->tszaTemporaryVars);
- }
+ }
if (((FORMATINFO *)wParam)->cbSize == sizeof(FORMATINFOV1)) {
((FORMATINFOV1 *)wParam)->eCount = fi->eCount;
@@ -457,7 +384,7 @@ static INT_PTR formatStringService(WPARAM wParam, LPARAM)
return res;
}
-TCHAR *formatString(FORMATINFO *fi)
+TCHAR* formatString(FORMATINFO *fi)
{
if (fi == NULL)
return NULL;
@@ -468,13 +395,8 @@ TCHAR *formatString(FORMATINFO *fi)
log_debugA("Variables: Overflow protection; %d parses", (fi->eCount + fi->pCount));
return NULL;
}
- if (fi->tszFormat == NULL)
- return NULL;
- ptrT string( mir_tstrdup(fi->tszFormat));
- if (string == NULL)
- return NULL;
- return replaceDynVars(string, fi);
+ return replaceDynVars(fi);
}
int setParseOptions(struct ParseOptions *po)