summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Variables/src/help.cpp20
-rw-r--r--plugins/Variables/src/parse_alias.cpp175
-rw-r--r--plugins/Variables/src/parse_alias.h7
-rw-r--r--plugins/Variables/src/parse_external.cpp116
-rw-r--r--plugins/Variables/src/parse_inet.cpp77
-rw-r--r--plugins/Variables/src/parse_logic.cpp253
-rw-r--r--plugins/Variables/src/parse_math.cpp118
-rw-r--r--plugins/Variables/src/parse_miranda.cpp17
-rw-r--r--plugins/Variables/src/parse_regexp.cpp83
-rw-r--r--plugins/Variables/src/parse_str.cpp418
-rw-r--r--plugins/Variables/src/parse_system.cpp401
-rw-r--r--plugins/Variables/src/variables.cpp137
-rw-r--r--plugins/Variables/src/variables.h59
13 files changed, 797 insertions, 1084 deletions
diff --git a/plugins/Variables/src/help.cpp b/plugins/Variables/src/help.cpp
index 2d787e5c09..9e3ca13989 100644
--- a/plugins/Variables/src/help.cpp
+++ b/plugins/Variables/src/help.cpp
@@ -257,9 +257,9 @@ static TCHAR *getTokenCategory(TOKENREGISTEREX *tr) {
return NULL;
}
cur = helpText;
- while (*cur != _T('\0')) {
- if (*cur == _T('\t')) {
- *cur = _T('\0');
+ while (*cur != 0) {
+ if (*cur == '\t') {
+ *cur = 0;
helpText = ( char* )mir_realloc(helpText, strlen(helpText)+1);
res = mir_a2t(helpText);
@@ -283,7 +283,7 @@ static TCHAR *getHelpDescription(TOKENREGISTEREX *tr)
char *cur = tr->szHelpText + strlen(tr->szHelpText);
while (cur > tr->szHelpText) {
- if (*cur == _T('\t')) {
+ if (*cur == '\t') {
cur = mir_strdup(cur+1);
TCHAR *res = mir_a2t(cur);
@@ -316,8 +316,8 @@ static TCHAR *getTokenDescription(TOKENREGISTEREX *tr)
char *cur = helpText;
first = second = NULL;
- while (*cur != _T('\0')) {
- if (*cur == _T('\t')) {
+ while (*cur != 0) {
+ if (*cur == '\t') {
if (first == NULL)
first = cur;
else if (second == NULL)
@@ -327,7 +327,7 @@ static TCHAR *getTokenDescription(TOKENREGISTEREX *tr)
}
if ((first != NULL) && (second != NULL)) {
- *second = _T('\0');
+ *second = 0;
args = first+1;
}
else args = NULL;
@@ -338,12 +338,12 @@ static TCHAR *getTokenDescription(TOKENREGISTEREX *tr)
return NULL;
if (tr->flags&TRF_FIELD)
- mir_sntprintf(desc, len, _T("%c%s%c"), _T(FIELD_CHAR), tr->szTokenString, _T(FIELD_CHAR));
+ mir_sntprintf(desc, len, _T("%c%s%c"), FIELD_CHAR, tr->szTokenString, FIELD_CHAR);
else {
if (args != NULL)
tArgs = mir_a2t(args);
- mir_sntprintf(desc, len, _T("%c%s%s"), _T(FUNC_CHAR), tr->tszTokenString, (tArgs!=NULL?tArgs:_T("")));
+ mir_sntprintf(desc, len, _T("%c%s%s"), FUNC_CHAR, tr->tszTokenString, (tArgs!=NULL?tArgs:_T("")));
}
if (tArgs != NULL)
mir_free(tArgs);
@@ -540,7 +540,7 @@ static BOOL CALLBACK processTokenListMessage(HWND hwndDlg,UINT msg,WPARAM wParam
break;
}
ZeroMemory(tokenString, (len+1)*sizeof(TCHAR));
- mir_sntprintf(tokenString, len + 1, _T("%c%s%c"), (tr->flags & TRF_FIELD ? _T(FIELD_CHAR) : _T(FUNC_CHAR)), tr->tszTokenString, (tr->flags & TRF_FIELD ? _T(FIELD_CHAR) : _T('(')));
+ mir_sntprintf(tokenString, len + 1, _T("%c%s%c"), (tr->flags & TRF_FIELD) ? FIELD_CHAR : FUNC_CHAR, tr->tszTokenString, (tr->flags & TRF_FIELD) ? FIELD_CHAR : '(');
SendDlgItemMessage(hwndInputDlg, IDC_TESTSTRING, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)tokenString);
mir_free(tokenString);
SetFocus(GetDlgItem(hwndInputDlg, IDC_TESTSTRING));
diff --git a/plugins/Variables/src/parse_alias.cpp b/plugins/Variables/src/parse_alias.cpp
index 87a95567ff..485b028634 100644
--- a/plugins/Variables/src/parse_alias.cpp
+++ b/plugins/Variables/src/parse_alias.cpp
@@ -19,47 +19,42 @@
#include "variables.h"
+struct ALIASREGISTER
+{
+ TCHAR *szAlias;
+ unsigned int argc;
+ TCHAR **argv;
+ TCHAR *szTranslation;
+};
+
+static LIST<ALIASREGISTER> arAliases(5);
static CRITICAL_SECTION csAliasRegister;
-static ALIASREGISTER *ar = NULL;
-static unsigned int arCount = 0;
-static ALIASREGISTER *searchAliasRegister(TCHAR *szAlias) {
+static ALIASREGISTER *searchAliasRegister(TCHAR *szAlias)
+{
+ if (szAlias == NULL || *szAlias == 0)
+ return NULL;
- ALIASREGISTER *res;
- unsigned int i;
+ mir_cslock lck(csAliasRegister);
+ for (int i=0; i < arAliases.getCount(); i++)
+ if (!_tcscmp(arAliases[i]->szAlias, szAlias))
+ return arAliases[i];
- res = NULL;
- if ((szAlias == NULL) || (_tcslen(szAlias) == 0)) {
- return NULL;
- }
- EnterCriticalSection(&csAliasRegister);
- for (i=0;i<arCount;i++) {
- if (!_tcscmp(ar[i].szAlias, szAlias)) {
- /* TODO: make a copy here? */
- res = &ar[i];
- LeaveCriticalSection(&csAliasRegister);
- return res;
- }
- }
- LeaveCriticalSection(&csAliasRegister);
-
return NULL;
}
-static TCHAR *replaceArguments(TCHAR *res, TCHAR *tArg, TCHAR *rArg) {
-
- unsigned int cur, ecur;
-
+static TCHAR *replaceArguments(TCHAR *res, TCHAR *tArg, TCHAR *rArg)
+{
if ( _tcslen(tArg) == 0)
return res;
- cur = ecur = 0;
- while (*(res+cur) != _T('\0')) {
- if ((*(res+cur) == _T('(')) || (*(res+cur) == _T(','))) {
+ unsigned int cur = 0, ecur = 0;
+ while (*(res+cur) != 0) {
+ if ((*(res+cur) == '(') || (*(res+cur) == ',')) {
ecur = ++cur;
- while ( (*(res+ecur) != _T(')')) && (*(res+ecur) != _T(','))) {
+ while ( (*(res+ecur) != ')') && (*(res+ecur) != ','))
ecur++;
- }
+
if (((signed int)_tcslen(tArg) == (ecur-cur)) && (!_tcsncmp(tArg, res+cur, _tcslen(tArg)))) {
if ( _tcslen(rArg) > _tcslen(tArg)) {
res = (TCHAR*)mir_realloc(res, (_tcslen(res) + (_tcslen(rArg)-_tcslen(tArg)) + 1)*sizeof(TCHAR));
@@ -76,87 +71,73 @@ static TCHAR *replaceArguments(TCHAR *res, TCHAR *tArg, TCHAR *rArg) {
return res;
}
-static TCHAR *parseTranslateAlias(ARGUMENTSINFO *ai) {
-
- unsigned int i;
- TCHAR *res;
- ALIASREGISTER *areg;
-
- areg = searchAliasRegister(ai->targv[0]);
- if ((areg == NULL) || (areg->argc != ai->argc-1)) {
+static TCHAR *parseTranslateAlias(ARGUMENTSINFO *ai)
+{
+ ALIASREGISTER *areg = searchAliasRegister(ai->targv[0]);
+ if (areg == NULL || areg->argc != ai->argc-1)
return NULL;
- }
- res = mir_tstrdup(areg->szTranslation);
- for (i=0;i<areg->argc;i++) {
+
+ TCHAR *res = mir_tstrdup(areg->szTranslation);
+ for (unsigned i=0; i < areg->argc; i++) {
res = replaceArguments(res, areg->argv[i], ai->targv[i+1]);
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
}
return res;
}
-static int addToAliasRegister(TCHAR *szAlias, unsigned int argc, TCHAR** argv, TCHAR *szTranslation) {
-
- unsigned int i, j;
-
+static int addToAliasRegister(TCHAR *szAlias, unsigned int argc, TCHAR** argv, TCHAR *szTranslation)
+{
if (szAlias == NULL || szTranslation == NULL || _tcslen(szAlias) == 0 )
return -1;
- EnterCriticalSection(&csAliasRegister);
- for (i=0;i<arCount;i++) {
- if (!_tcscmp(ar[i].szAlias, szAlias)) {
- mir_free(ar[i].szTranslation);
- ar[i].szTranslation = mir_tstrdup(szTranslation);
- for (j=0;j<ar[i].argc;j++) {
- if (ar[i].argv[j] != NULL) {
- mir_free(ar[i].argv[j]);
- }
- }
- ar[i].argc = argc;
- ar[i].argv = ( TCHAR** )mir_realloc(ar[i].argv, argc * sizeof(TCHAR*));
- if (ar[i].argv == NULL) {
- LeaveCriticalSection(&csAliasRegister);
- return -1;
- }
- for (j=0;j<argc;j++) {
- if (argv[j] != NULL)
- ar[i].argv[j] = mir_tstrdup(argv[j]);
- else
- ar[i].argv[j] = NULL;
- }
- LeaveCriticalSection(&csAliasRegister);
- return 0;
+ mir_cslock lck(csAliasRegister);
+ for (int i=0; i < arAliases.getCount(); i++) {
+ ALIASREGISTER *p = arAliases[i];
+ if ( _tcscmp(p->szAlias, szAlias))
+ continue;
+
+ mir_free(p->szTranslation);
+ p->szTranslation = mir_tstrdup(szTranslation);
+ for (unsigned j=0; j < p->argc; j++)
+ if (p->argv[j] != NULL)
+ mir_free(p->argv[j]);
+
+ p->argc = argc;
+ p->argv = (TCHAR**)mir_realloc(p->argv, argc * sizeof(TCHAR*));
+ if (p->argv == NULL)
+ return -1;
+
+ for (unsigned j=0; j < argc; j++) {
+ if (argv[j] != NULL)
+ p->argv[j] = mir_tstrdup(argv[j]);
+ else
+ p->argv[j] = NULL;
}
+ return 0;
}
- ar = ( ALIASREGISTER* )mir_realloc(ar, (arCount+1)*sizeof(ALIASREGISTER));
- if (ar == NULL) {
- LeaveCriticalSection(&csAliasRegister);
- return -1;
- }
- ar[arCount].szAlias = mir_tstrdup(szAlias);
- ar[arCount].szTranslation = mir_tstrdup(szTranslation);
- ar[arCount].argc = argc;
- ar[arCount].argv = ( TCHAR** )mir_alloc(argc * sizeof(TCHAR*));
- if (ar[arCount].argv == NULL) {
- LeaveCriticalSection(&csAliasRegister);
+
+ ALIASREGISTER *p = new ALIASREGISTER;
+ p->szAlias = mir_tstrdup(szAlias);
+ p->szTranslation = mir_tstrdup(szTranslation);
+ p->argc = argc;
+ p->argv = (TCHAR**)mir_alloc(argc * sizeof(TCHAR*));
+ if (p->argv == NULL)
return -1;
- }
- for (j=0;j<ar[arCount].argc;j++) {
+
+ for (unsigned j=0; j < p->argc; j++) {
if (argv[j] != NULL)
- ar[arCount].argv[j] = mir_tstrdup(argv[j]);
+ p->argv[j] = mir_tstrdup(argv[j]);
else
- ar[arCount].argv[j] = NULL;
+ p->argv[j] = NULL;
}
- arCount += 1;
- LeaveCriticalSection(&csAliasRegister);
-
+ arAliases.insert(p);
return 0;
}
-static TCHAR *parseAddAlias(ARGUMENTSINFO *ai) {
-
+static TCHAR *parseAddAlias(ARGUMENTSINFO *ai)
+{
int res;
int argc, i;
TCHAR **argv;
@@ -189,8 +170,7 @@ static TCHAR *parseAddAlias(ARGUMENTSINFO *ai) {
_tcscat(szArgs, _T(","));
}
if ((szArgs != NULL) && (argc > 0)) {
-
- szArgsA = mir_t2a(szArgs);
+ szArgsA = mir_t2a(szArgs);
size_t size = 32 + strlen(szArgsA);
szHelp = (char *)mir_alloc(size);
@@ -220,5 +200,14 @@ int registerAliasTokens()
void unregisterAliasTokens()
{
DeleteCriticalSection(&csAliasRegister);
-}
+ for (int i=0; i < arAliases.getCount(); i++) {
+ ALIASREGISTER *p = arAliases[i];
+ mir_free(p->argv);
+ mir_free(p->szAlias);
+ mir_free(p->szTranslation);
+ delete p;
+ }
+
+ arAliases.destroy();
+}
diff --git a/plugins/Variables/src/parse_alias.h b/plugins/Variables/src/parse_alias.h
index 0d867f9e54..7297fec1d0 100644
--- a/plugins/Variables/src/parse_alias.h
+++ b/plugins/Variables/src/parse_alias.h
@@ -17,13 +17,6 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-typedef struct {
- TCHAR *szAlias;
- unsigned int argc;
- TCHAR **argv;
- TCHAR *szTranslation;
-} ALIASREGISTER;
-
#define ADDALIAS "alias"
int isValidTokenChar(TCHAR tc);
diff --git a/plugins/Variables/src/parse_external.cpp b/plugins/Variables/src/parse_external.cpp
index 2a0ade2768..2cb408c777 100644
--- a/plugins/Variables/src/parse_external.cpp
+++ b/plugins/Variables/src/parse_external.cpp
@@ -26,7 +26,8 @@ static void (WINAPI *acUninit)() = NULL;
static unsigned int lastAMIPFailure = -1;
-static TCHAR *getFullWinampTitleText() {
+static TCHAR *getFullWinampTitleText()
+{
HWND hwndWinamp = FindWindow(_T("STUDIO"), NULL);
if (hwndWinamp == NULL)
hwndWinamp = FindWindow(_T("Winamp v1.x"),NULL);
@@ -54,16 +55,17 @@ static TCHAR *getFullWinampTitleText() {
return szTitle;
}
-static TCHAR *parseWinampSong(ARGUMENTSINFO *ai) {
- if (ai->argc != 1) {
+static TCHAR *parseWinampSong(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 1)
return NULL;
- }
+
TCHAR *res = NULL;
TCHAR *szTitle = getFullWinampTitleText();
- if (szTitle == NULL) {
+ if (szTitle == NULL)
return NULL;
- }
- TCHAR *scur = _tcschr(szTitle, _T('.'));
+
+ TCHAR *scur = _tcschr(szTitle, '.');
TCHAR *cur = _tcsstr(scur, _T(" - Winamp"));
if ((scur == NULL) || (cur == NULL) || (scur >= cur) || (scur > (szTitle + _tcslen(szTitle) - 2)) || (cur > (szTitle + _tcslen(szTitle)))) {
mir_free(szTitle);
@@ -79,16 +81,17 @@ static TCHAR *parseWinampSong(ARGUMENTSINFO *ai) {
return res;
}
-static TCHAR *parseWinampState(ARGUMENTSINFO *ai) {
- if (ai->argc != 1) {
+static TCHAR *parseWinampState(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 1)
return NULL;
- }
+
TCHAR *res = NULL;
TCHAR *szTitle = getFullWinampTitleText();
- if (szTitle == NULL) {
+ if (szTitle == NULL)
return NULL;
- }
- TCHAR *scur = _tcschr(szTitle, _T('.'));
+
+ TCHAR *scur = _tcschr(szTitle, '.');
TCHAR *cur = _tcsstr(scur, _T(" - Winamp"));
if ((scur == NULL) || (cur == NULL)) {
mir_free(szTitle);
@@ -106,8 +109,8 @@ static TCHAR *parseWinampState(ARGUMENTSINFO *ai) {
return mir_tstrdup(_T("Playing"));
}
-static unsigned int checkAMIP() {
-
+static unsigned int checkAMIP()
+{
if (lastAMIPFailure == 0) {
log_debugA("AMIP initialized");
return 0;
@@ -119,76 +122,63 @@ static unsigned int checkAMIP() {
if (acInitClient("127.0.0.1", 60333, 1000, 5, 1)) {
lastAMIPFailure = 0;
log_debugA("AMIP now initialized");
-
return 0; // success
}
log_debugA("AMIP failed to initialized");
- if (lastAMIPFailure == 0) {
- /* if this is the first failure after a succesful init, call uninit for a cleanup (maybe it'll help for the next try ;)) */
+
+ /* if this is the first failure after a succesful init, call uninit for a cleanup (maybe it'll help for the next try ;)) */
+ if (lastAMIPFailure == 0)
acUninit();
- }
+
lastAMIPFailure = GetTickCount();
-
return -1;
}
-static TCHAR *parseAMIPEval(ARGUMENTSINFO *ai) {
- char szRes[AC_BUFFER_SIZE];
-
- TCHAR *tszRes = NULL;
- if (ai->argc != 2) {
+static TCHAR *parseAMIPEval(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
char *cmd = mir_t2a(ai->targv[1]);
-
if (checkAMIP() != 0) {
log_debugA("checkAMIP failed");
-
return NULL;
}
- ZeroMemory(&szRes, sizeof(szRes));
- if (AC_ERR_NOERROR == acEval(cmd, szRes)) {
+ TCHAR *tszRes = NULL;
+ char szRes[AC_BUFFER_SIZE];
+ ZeroMemory(&szRes, sizeof(szRes));
+ if (AC_ERR_NOERROR == acEval(cmd, szRes))
tszRes = mir_a2t(szRes);
-
- }
- else {
+ else
lastAMIPFailure = GetTickCount();
- }
- mir_free(cmd);
+ mir_free(cmd);
return tszRes;
}
-static TCHAR *parseAMIPFormat(ARGUMENTSINFO *ai) {
- char szRes[AC_BUFFER_SIZE];
-
- TCHAR *tszRes = NULL;
- if (ai->argc != 2) {
+static TCHAR *parseAMIPFormat(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
- char *cmd = mir_t2a(ai->targv[1]);
-
- if (checkAMIP() != 0) {
-
+ char *cmd = mir_t2a(ai->targv[1]);
+ if (checkAMIP() != 0)
return NULL;
- }
- if (AC_ERR_NOERROR == acFormat(cmd, szRes)) {
+ TCHAR *tszRes = NULL;
+ char szRes[AC_BUFFER_SIZE];
+ if (AC_ERR_NOERROR == acFormat(cmd, szRes))
tszRes = mir_a2t(szRes);
-
- }
- else {
+ else
lastAMIPFailure = GetTickCount();
- }
- mir_free(cmd);
+ mir_free(cmd);
return tszRes;
}
-static int initAMIP() {
+static int initAMIP()
+{
HMODULE hModule = LoadLibrary(_T("ac.dll"));
if (hModule == NULL) {
TCHAR path[MAX_PATH];
@@ -200,37 +190,33 @@ static int initAMIP() {
_tcscpy(cur, _T("ac.dll"));
hModule = LoadLibrary(path);
}
- if (hModule == NULL) {
+ if (hModule == NULL)
return -1;
- }
+
acInitClient = (int (__stdcall *)(const char *,int ,int ,int ,int ))GetProcAddress(hModule, "ac_init_client");
acEval = (int (__stdcall *)(const char *,char *))GetProcAddress(hModule, "ac_eval");
acFormat = (int (__stdcall *)(const char *,char *))GetProcAddress(hModule, "ac_format");
acUninit = (void (__stdcall *)())GetProcAddress(hModule, "ac_uninit");
-
return 0;
}
-int registerExternalTokens() {
-
+int registerExternalTokens()
+{
registerIntToken(_T(WINAMPSONG), parseWinampSong, TRF_FIELD, LPGEN("External Applications")"\t"LPGEN("retrieves song name of the song currently playing in Winamp"));
registerIntToken(_T(WINAMPSTATE), parseWinampState, TRF_FIELD, LPGEN("External Applications")"\t"LPGEN("retrieves current Winamp state (Playing/Paused/Stopped)"));
if (!initAMIP()) {
registerIntToken(_T(AMIPEVAL), parseAMIPEval, TRF_FUNCTION, LPGEN("External Applications")"\t(x)\t"LPGEN("retrieves info from AMIP (x is var_<variable> with any AMIP variable)"));
registerIntToken(_T(AMIPFORMAT), parseAMIPFormat, TRF_FUNCTION|TRF_UNPARSEDARGS, LPGEN("External Applications")"\t(x)\t"LPGEN("retrieves info from AMIP (x is AMIP format string)"));
}
- else {
- log_infoA("Variables: ac.dll for AMIP not found");
- }
+ else log_infoA("Variables: ac.dll for AMIP not found");
return 0;
}
-int deInitExternal() {
-
- if (acUninit != NULL) {
+int deInitExternal()
+{
+ if (acUninit != NULL)
acUninit();
- }
return 0;
} \ No newline at end of file
diff --git a/plugins/Variables/src/parse_inet.cpp b/plugins/Variables/src/parse_inet.cpp
index 856af28d14..dfa92ba7f1 100644
--- a/plugins/Variables/src/parse_inet.cpp
+++ b/plugins/Variables/src/parse_inet.cpp
@@ -19,18 +19,15 @@
#include "variables.h"
-static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai) {
- char hex[8];
-
- if (ai->argc != 2) {
+static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
char *res = mir_t2a(ai->targv[1]);
-
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
+
size_t cur = 0;
while (cur < strlen(res)) {
if (( (*(res+cur) >= '0') && (*(res+cur) <= '9')) || ( (*(res+cur) >= 'a') && (*(res+cur) <= 'z')) || ( (*(res+cur) >= 'A') && (*(res+cur) <= 'Z')) ) {
@@ -41,6 +38,7 @@ static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai) {
if (res == NULL)
return NULL;
+ char hex[8];
MoveMemory(res+cur+3, res+cur+1, strlen(res+cur+1)+1);
mir_snprintf(hex, sizeof(hex), "%%%x", *(res+cur));
strncpy(res+cur, hex, strlen(hex));
@@ -48,27 +46,23 @@ static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai) {
}
TCHAR *tres = mir_a2t(res);
-
mir_free(res);
-
return tres;
}
-static TCHAR *parseUrlDec(ARGUMENTSINFO *ai) {
- char hex[8];
-
- if (ai->argc != 2) {
+static TCHAR *parseUrlDec(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
char *res = mir_t2a(ai->targv[1]);
-
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
+
unsigned int cur = 0;
while (cur < strlen(res)) {
if ((*(res+cur) == '%') && (strlen(res+cur) >= 3)) {
+ char hex[8];
memset(hex, '\0', sizeof(hex));
strncpy(hex, res+cur+1, 2);
*(res+cur) = (char)strtol(hex, NULL, 16);
@@ -76,57 +70,38 @@ static TCHAR *parseUrlDec(ARGUMENTSINFO *ai) {
}
cur++;
}
- res = ( char* )mir_realloc(res, strlen(res)+1);
+ res = ( char* )mir_realloc(res, strlen(res)+1);
TCHAR *tres = mir_a2t(res);
-
mir_free(res);
-
return tres;
}
-static TCHAR *parseNToA(ARGUMENTSINFO *ai) {
- struct in_addr in;
-
- if (ai->argc != 2) {
+static TCHAR *parseNToA(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
+ struct in_addr in;
in.s_addr = ttoi(ai->targv[1]);
- char *res = inet_ntoa(in);
- if (res != NULL) {
-
- return mir_a2t(res);
-
- }
-
- return NULL;
+ return mir_a2t( inet_ntoa(in));
}
-static TCHAR *parseHToA(ARGUMENTSINFO *ai) {
- struct in_addr in;
-
- if (ai->argc != 2) {
+static TCHAR *parseHToA(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
+ struct in_addr in;
in.s_addr = htonl(ttoi(ai->targv[1]));
- char *res = inet_ntoa(in);
- if (res != NULL) {
-
- return mir_a2t(res);
-
- }
-
- return NULL;
+ return mir_a2t( inet_ntoa(in));
}
-int registerInetTokens() {
-
+int registerInetTokens()
+{
registerIntToken(_T(URLENC), parseUrlEnc, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts each non-html character into hex format"));
registerIntToken(_T(URLDEC), parseUrlDec, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts each hex value into non-html character"));
registerIntToken(_T(NTOA), parseNToA, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts a 32-bit number to IPv4 dotted notation"));
registerIntToken(_T(HTOA), parseHToA, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts a 32-bit number (in host byte order) to IPv4 dotted notation"));
-
- return 0;
+ return 0;
}
diff --git a/plugins/Variables/src/parse_logic.cpp b/plugins/Variables/src/parse_logic.cpp
index f0d33e7c79..bc0264caea 100644
--- a/plugins/Variables/src/parse_logic.cpp
+++ b/plugins/Variables/src/parse_logic.cpp
@@ -19,22 +19,17 @@
#include "variables.h"
-static TCHAR *parseAnd(ARGUMENTSINFO *ai) {
+static TCHAR *parseAnd(ARGUMENTSINFO *ai)
+{
+ if (ai->argc < 3)
+ return NULL;
FORMATINFO fi;
- TCHAR *szCondition;
- unsigned int i;
-
- if (ai->argc < 3) {
- return NULL;
- }
- ZeroMemory(&fi, sizeof(fi));
memcpy(&fi, ai->fi, sizeof(fi));
- for (i=1;i<ai->argc;i++) {
+ for (unsigned i=1; i < ai->argc; i++) {
fi.tszFormat = ai->targv[i];
- szCondition = formatString(&fi);
- mir_free(szCondition);
- //if (fi.pCount <= 0) {
+ mir_free( formatString(&fi));
+
if (fi.eCount > 0) {
ai->flags |= AIF_FALSE;
return mir_tstrdup(_T(""));
@@ -44,80 +39,58 @@ static TCHAR *parseAnd(ARGUMENTSINFO *ai) {
return mir_tstrdup(_T(""));
}
-static TCHAR *parseFalse(ARGUMENTSINFO *ai) {
-
- if (ai->argc != 1) {
+static TCHAR *parseFalse(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 1)
return NULL;
- }
- ai->flags |= AIF_FALSE;
+ ai->flags |= AIF_FALSE;
return mir_tstrdup(_T(""));
}
-static TCHAR *parseIf(ARGUMENTSINFO *ai) {
- if (ai->argc != 4) {
+static TCHAR *parseIf(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 4)
return NULL;
- }
+
FORMATINFO fi;
- ZeroMemory(&fi, sizeof(fi));
memcpy(&fi, ai->fi, sizeof(fi));
fi.eCount = fi.pCount = 0;
fi.tszFormat = ai->targv[1];
- TCHAR *szCondition = formatString(&fi);
- mir_free(szCondition);
- //if (fi.pCount > 0) {
- if (fi.eCount == 0) {
- return mir_tstrdup(ai->targv[2]);
- }
- else {
- return mir_tstrdup(ai->targv[3]);
- }
+ mir_free( formatString(&fi));
+
+ return mir_tstrdup((fi.eCount == 0) ? ai->targv[2] : ai->targv[3]);
}
-static TCHAR *parseIf2(ARGUMENTSINFO *ai) {
- if (ai->argc != 3) {
+static TCHAR *parseIf2(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 3)
return NULL;
- }
FORMATINFO fi;
- ZeroMemory(&fi, sizeof(fi));
memcpy(&fi, ai->fi, sizeof(fi));
fi.eCount = fi.pCount = 0;
fi.tszFormat = ai->targv[1];
TCHAR *szCondition = formatString(&fi);
- //if (fi.pCount > 0) {
- if (fi.eCount == 0) {
+ if (fi.eCount == 0)
return szCondition;
- }
- else {
- if (szCondition != NULL) {
-// ai->flags |= AIF_DONTPARSE;
- mir_free(szCondition);
- }
- return mir_tstrdup(ai->targv[2]);
- }
-}
-static TCHAR *parseIf3(ARGUMENTSINFO *ai) {
+ mir_free(szCondition);
+ return mir_tstrdup(ai->targv[2]);
+}
+static TCHAR *parseIf3(ARGUMENTSINFO *ai)
+{
FORMATINFO fi;
- TCHAR *szCondition;
- unsigned int i;
-
- ZeroMemory(&fi, sizeof(fi));
memcpy(&fi, ai->fi, sizeof(fi));
- for (i=1;i<ai->argc;i++) {
+ for (unsigned i=1; i < ai->argc; i++) {
fi.eCount = fi.pCount = 0;
fi.tszFormat = ai->targv[i];
- szCondition = formatString(&fi);
- //if (fi.pCount > 0) {
- if (fi.eCount == 0) {
-// ai->flags |= AIF_DONTPARSE;
+ TCHAR *szCondition = formatString(&fi);
+ if (fi.eCount == 0)
return szCondition;
- }
- if (szCondition != NULL) {
- mir_free(szCondition);
- }
+
+ mir_free(szCondition);
}
return NULL;
@@ -128,93 +101,57 @@ static TCHAR *parseIfequal(ARGUMENTSINFO *ai)
if (ai->argc != 5)
return NULL;
- FORMATINFO fi = { 0 };
+ FORMATINFO fi;
memcpy(&fi, ai->fi, sizeof(fi));
fi.szFormat = ai->argv[1];
- TCHAR *tszFirst = formatString(&fi);
+ ptrT tszFirst( formatString(&fi));
fi.szFormat = ai->argv[2];
- TCHAR *tszSecond = formatString(&fi);
- if ((tszFirst == NULL) || (tszSecond == NULL)) {
- if (tszFirst != NULL)
- mir_free(tszFirst);
-
- if (tszSecond != NULL)
- mir_free(tszSecond);
-
+ ptrT tszSecond( formatString(&fi));
+ if (tszFirst == NULL || tszSecond == NULL)
return NULL;
- }
- if ((ttoi(tszFirst)) == (ttoi(tszSecond))) {
- mir_free(tszFirst);
- mir_free(tszSecond);
+
+ if ( ttoi(tszFirst) == ttoi(tszSecond))
return mir_tstrdup(ai->targv[3]);
- }
- mir_free(tszFirst);
- mir_free(tszSecond);
return mir_tstrdup(ai->targv[4]);
}
-static TCHAR *parseIfgreater(ARGUMENTSINFO *ai) {
- if (ai->argc != 5) {
+static TCHAR *parseIfgreater(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 5)
return NULL;
- }
FORMATINFO fi;
- //ai->flags |= AIF_DONTPARSE;
- ZeroMemory(&fi, sizeof(fi));
memcpy(&fi, ai->fi, sizeof(fi));
fi.szFormat = ai->argv[1];
- TCHAR *tszFirst = formatString(&fi);
+ ptrT tszFirst( formatString(&fi));
fi.szFormat = ai->argv[2];
- TCHAR *tszSecond = formatString(&fi);
- if ((tszFirst == NULL) || (tszSecond == NULL)) {
- if (tszFirst != NULL) {
- mir_free(tszFirst);
- }
- if (tszSecond != NULL) {
- mir_free(tszSecond);
- }
+ ptrT tszSecond( formatString(&fi));
+ if (tszFirst == NULL || tszSecond == NULL)
return NULL;
- }
- if ((ttoi(tszFirst)) > (ttoi(tszSecond))) {
- mir_free(tszFirst);
- mir_free(tszSecond);
+
+ if ( ttoi(tszFirst) > ttoi(tszSecond))
return mir_tstrdup(ai->targv[3]);
- }
- mir_free(tszFirst);
- mir_free(tszSecond);
return mir_tstrdup(ai->targv[4]);
}
-static TCHAR *parseIflonger(ARGUMENTSINFO *ai) {
- if (ai->argc != 5) {
+static TCHAR *parseIflonger(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 5)
return NULL;
- }
FORMATINFO fi;
- ZeroMemory(&fi, sizeof(fi));
memcpy(&fi, ai->fi, sizeof(fi));
fi.szFormat = ai->argv[1];
- TCHAR *tszFirst = formatString(&fi);
+ ptrT tszFirst( formatString(&fi));
fi.szFormat = ai->argv[2];
- TCHAR *tszSecond = formatString(&fi);
- if ((tszFirst == NULL) || (tszSecond == NULL)) {
- if (tszFirst != NULL) {
- mir_free(tszFirst);
- }
- if (tszSecond != NULL) {
- mir_free(tszSecond);
- }
+ ptrT tszSecond( formatString(&fi));
+ if (tszFirst == NULL || tszSecond == NULL)
return NULL;
- }
- if ( _tcslen(tszFirst) > _tcslen(tszSecond)) {
- mir_free(tszFirst);
- mir_free(tszSecond);
+
+ if ( _tcslen(tszFirst) > _tcslen(tszSecond))
return mir_tstrdup(ai->targv[3]);
- }
- mir_free(tszFirst);
- mir_free(tszSecond);
return mir_tstrdup(ai->targv[4]);
}
@@ -224,17 +161,15 @@ static TCHAR *parseIflonger(ARGUMENTSINFO *ai) {
?for(init, cond, incr, show)
*/
-static TCHAR *parseFor(ARGUMENTSINFO *ai) {
- if (ai->argc != 5) {
+static TCHAR *parseFor(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 5)
return NULL;
- }
TCHAR *parsed;
- FORMATINFO fi;
-
TCHAR *res = mir_tstrdup(_T(""));
-// ai->flags |= AIF_DONTPARSE;
- ZeroMemory(&fi, sizeof(fi));
+
+ FORMATINFO fi;
CopyMemory(&fi, ai->fi, sizeof(fi));
fi.eCount = fi.pCount = 0;
fi.tszFormat = ai->targv[1];
@@ -303,83 +238,66 @@ static TCHAR *parseNot(ARGUMENTSINFO *ai) {
}
FORMATINFO fi;
- ZeroMemory(&fi, sizeof(fi));
memcpy(&fi, ai->fi, sizeof(fi));
fi.tszFormat = ai->targv[1];
- TCHAR *szCondition = formatString(&fi);
- mir_free(szCondition);
- //if (fi.pCount > 0) {
- if (fi.eCount == 0) {
+ mir_free( formatString(&fi));
+
+ if (fi.eCount == 0)
ai->flags |= AIF_FALSE;
- }
return mir_tstrdup(_T(""));
}
-static TCHAR *parseOr(ARGUMENTSINFO *ai) {
+static TCHAR *parseOr(ARGUMENTSINFO *ai)
+{
+ if (ai->argc < 2)
+ return NULL;
- unsigned int i;
FORMATINFO fi;
- TCHAR *szCondition;
-
- if (ai->argc < 2) {
- return NULL;
- }
- ZeroMemory(&fi, sizeof(fi));
memcpy(&fi, ai->fi, sizeof(fi));
ai->flags |= AIF_FALSE;
- for(i=1;(i<ai->argc)&&(ai->flags&AIF_FALSE);i++) {
+ for(unsigned i=1; (i<ai->argc) && (ai->flags&AIF_FALSE); i++) {
fi.tszFormat = ai->targv[i];
fi.eCount = 0;
- szCondition = formatString(&fi);
- mir_free(szCondition);
- //if (fi.pCount > 0) {
- if (fi.eCount == 0) {
+ mir_free( formatString(&fi));
+
+ if (fi.eCount == 0)
ai->flags &= ~AIF_FALSE;
- }
}
return mir_tstrdup(_T(""));
}
-static TCHAR *parseTrue(ARGUMENTSINFO *ai) {
-
- if (ai->argc != 1) {
+static TCHAR *parseTrue(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 1)
return NULL;
- }
return mir_tstrdup(_T(""));
}
-static TCHAR *parseXor(ARGUMENTSINFO *ai) {
+static TCHAR *parseXor(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 3)
+ return NULL;
- int val1, val2;
FORMATINFO fi;
- TCHAR *szCondition;
-
- if (ai->argc != 3) {
- return NULL;
- }
- ZeroMemory(&fi, sizeof(fi));
memcpy(&fi, ai->fi, sizeof(fi));
ai->flags = AIF_FALSE;
fi.tszFormat = ai->targv[0];
- szCondition = formatString(&fi);
- mir_free(szCondition);
- //val1 = fi.pCount > 0;
- val1 = fi.eCount == 0;
+ mir_free( formatString(&fi));
+ int val1 = fi.eCount == 0;
+
fi.tszFormat = ai->targv[1];
- szCondition = formatString(&fi);
- mir_free(szCondition);
- //val2 = fi.pCount > 0;
- val2 = fi.eCount == 0;
- ai->flags |= ((val1&AIF_FALSE)==!(val2&AIF_FALSE))?0:AIF_FALSE;
+ mir_free( formatString(&fi));
+ int val2 = fi.eCount == 0;
+ ai->flags |= ((val1 & AIF_FALSE) == !(val2 & AIF_FALSE)) ? 0 : AIF_FALSE;
return mir_tstrdup(_T(""));
}
-int registerLogicTokens() {
-
+int registerLogicTokens()
+{
registerIntToken(_T(AND), parseAnd, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y, ...)\t"LPGEN("performs logical AND (x && y && ...)"));
registerIntToken(_T(STR_FALSE), parseFalse, TRF_FIELD, LPGEN("Logical Expressions")"\t"LPGEN("Boolean FALSE"));
registerIntToken(_T(FOR), parseFor, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(w,x,y,z)\t"LPGEN("performs w, then shows z and performs y while x is TRUE"));
@@ -396,6 +314,5 @@ int registerLogicTokens() {
registerIntToken(_T(OR), parseOr, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y,...)\t"LPGEN("performs logical OR (x || y || ...)"));
registerIntToken(_T(STR_TRUE), parseTrue, TRF_FIELD, LPGEN("Logical Expressions")"\t"LPGEN("Boolean TRUE"));
registerIntToken(_T(XOR), parseXor, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("performs logical XOR (x ^ y)"));
-
return 0;
}
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;i<ai->argc;i++) {
+ for (unsigned int i=1;i<ai->argc;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;i<zeros;i++)
- *(res+2+i) = _T('0');
+ for (i=0; i < zeros; i++)
+ *(res+2+i) = '0';
_tcscat(res, szVal);
return res;
}
-static TCHAR *parseMod(ARGUMENTSINFO *ai) {
- if (ai->argc != 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;i<ai->argc;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;i<ai->argc;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;i<ai->argc;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;i<zeros;i++)
- *cur++ = _T('0');
+ for (unsigned i=0; i < zeros; i++)
+ *cur++ = '0';
_tcscat(res, szVal);
mir_free(szVal);
@@ -162,27 +156,25 @@ static TCHAR *parseNum(ARGUMENTSINFO *ai) {
return res;
}
-static TCHAR *parseRand(ARGUMENTSINFO *ai) {
-
+static TCHAR *parseRand(ARGUMENTSINFO *ai)
+{
return itot(rand());
}
-static TCHAR *parseSub(ARGUMENTSINFO *ai) {
- unsigned int i;
-
- if (ai->argc < 3) {
+static TCHAR *parseSub(ARGUMENTSINFO *ai)
+{
+ if (ai->argc < 3)
return NULL;
- }
+
int result = ttoi(ai->targv[1]);
- for (i=2;i<ai->argc;i++) {
+ for (unsigned i=2;i<ai->argc;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"));
diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp
index 88fc767e6c..2e687a1fbf 100644
--- a/plugins/Variables/src/parse_miranda.cpp
+++ b/plugins/Variables/src/parse_miranda.cpp
@@ -82,7 +82,7 @@ static TCHAR *parseContact(ARGUMENTSINFO *ai)
return NULL;
int n = 0;
- if (ai->argc == 4 && *ai->targv[3] != _T('r'))
+ if (ai->argc == 4 && *ai->targv[3] != 'r')
n = ttoi(ai->targv[3]) - 1;
CONTACTSINFO ci = { 0 };
@@ -93,7 +93,7 @@ static TCHAR *parseContact(ARGUMENTSINFO *ai)
if (count == 0 || ci.hContacts == NULL)
return NULL;
- if (ai->argc == 4 && *ai->targv[3] == _T('r'))
+ if (ai->argc == 4 && *ai->targv[3] == 'r')
n = rand() % count;
if (count != 1 && ai->argc != 4 ) {
@@ -641,7 +641,7 @@ static TCHAR *parseDbEvent(ARGUMENTSINFO *ai)
int flags = DBE_MESSAGE;
switch (*ai->targv[2]) {
- case _T('f'):
+ case 'f':
flags |= DBE_FIRST;
break;
default:
@@ -649,10 +649,10 @@ static TCHAR *parseDbEvent(ARGUMENTSINFO *ai)
break;
}
switch (*ai->targv[3]) {
- case _T('s'):
+ case 's':
flags |= DBE_SENT;
break;
- case _T('r'):
+ case 'r':
flags |= DBE_RCVD;
break;
default:
@@ -660,10 +660,10 @@ static TCHAR *parseDbEvent(ARGUMENTSINFO *ai)
break;
}
switch (*ai->targv[4]) {
- case _T('r'):
+ case 'r':
flags |= DBE_READ;
break;
- case _T('u'):
+ case 'u':
flags |= DBE_UNREAD;
break;
default:
@@ -689,8 +689,7 @@ static TCHAR *parseDbEvent(ARGUMENTSINFO *ai)
if (hDbEvent == NULL)
return NULL;
- DBEVENTINFO dbe = { 0 };
- dbe.cbSize = sizeof(DBEVENTINFO);
+ DBEVENTINFO dbe = { sizeof(dbe) };
dbe.cbBlob = db_event_getBlobSize(hDbEvent);
dbe.pBlob = (PBYTE)mir_calloc(dbe.cbBlob);
if (db_event_get(hDbEvent, &dbe)) {
diff --git a/plugins/Variables/src/parse_regexp.cpp b/plugins/Variables/src/parse_regexp.cpp
index d8ea5c31b3..3b8679de6b 100644
--- a/plugins/Variables/src/parse_regexp.cpp
+++ b/plugins/Variables/src/parse_regexp.cpp
@@ -22,38 +22,31 @@
/*
pattern, subject
*/
-static TCHAR *parseRegExpCheck(ARGUMENTSINFO *ai) {
-
+static TCHAR *parseRegExpCheck(ARGUMENTSINFO *ai)
+{
const char *err;
int erroffset;
- char szVal[34], *arg1, *arg2;
+ char szVal[34];
int offsets[99];
- if (ai->argc != 3) {
+ if (ai->argc != 3)
return NULL;
- }
+
ai->flags = AIF_FALSE;
- arg1 = mir_t2a(ai->targv[1]);
- arg2 = mir_t2a(ai->targv[2]);
+ ptrA arg1( mir_t2a(ai->targv[1]));
+ ptrA arg2( mir_t2a(ai->targv[2]));
pcre *ppat = pcre_compile(arg1, 0, &err, &erroffset, NULL);
- if (ppat == NULL) {
- mir_free(arg1);
- mir_free(arg2);
+ if (ppat == NULL)
return NULL;
- }
+
pcre_extra *extra = pcre_study(ppat, 0, &err);
int nmat = pcre_exec(ppat, extra, arg2, (int)strlen(arg2), 0, 0, offsets, 99);
- mir_free(arg1);
- mir_free(arg2);
if (nmat > 0) {
ai->flags &= ~AIF_FALSE;
_ltoa(nmat, szVal, 10);
-
- TCHAR *res = mir_a2t(szVal);
-
- return res;
+ return mir_a2t(szVal);
}
return mir_tstrdup(_T("0"));
@@ -62,71 +55,47 @@ static TCHAR *parseRegExpCheck(ARGUMENTSINFO *ai) {
/*
pattern, subject, substring no (== PCRE string no (starting at 0))
*/
-static TCHAR *parseRegExpSubstr(ARGUMENTSINFO *ai) {
-
+static TCHAR *parseRegExpSubstr(ARGUMENTSINFO *ai)
+{
const char *err, *substring;
- char *res, *arg1, *arg2, *arg3;
int erroffset, number;
int offsets[99];
- TCHAR *tres;
- if (ai->argc != 4) {
+ if (ai->argc != 4)
return NULL;
- }
- arg1 = mir_t2a(ai->targv[1]);
- arg2 = mir_t2a(ai->targv[2]);
- arg3 = mir_t2a(ai->targv[3]);
+ ptrA arg1 = mir_t2a(ai->targv[1]);
+ ptrA arg2 = mir_t2a(ai->targv[2]);
+ ptrA arg3 = mir_t2a(ai->targv[3]);
number = atoi(arg3);
- if (number < 0) {
- mir_free(arg1);
- mir_free(arg2);
- mir_free(arg3);
+ if (number < 0)
return NULL;
- }
+
ai->flags = AIF_FALSE;
pcre *ppat = pcre_compile(arg1, 0, &err, &erroffset, NULL);
- if (ppat == NULL) {
- mir_free(arg1);
- mir_free(arg2);
- mir_free(arg3);
+ if (ppat == NULL)
return NULL;
- }
+
pcre_extra *extra = pcre_study(ppat, 0, &err);
int nmat = pcre_exec(ppat, extra, arg2, (int)strlen(arg2), 0, 0, offsets, 99);
- if (nmat >= 0) {
+ if (nmat >= 0)
ai->flags &= ~AIF_FALSE;
- }
- if (pcre_get_substring(arg2, offsets, nmat, number, &substring) < 0) {
+
+ if (pcre_get_substring(arg2, offsets, nmat, number, &substring) < 0)
ai->flags |= AIF_FALSE;
- }
else {
- res = mir_strdup(substring);
+ TCHAR *tres = mir_a2t(substring);
pcre_free_substring(substring);
-
-
- tres = mir_a2t(res);
-
- mir_free(res);
- mir_free(arg1);
- mir_free(arg2);
- mir_free(arg3);
-
return tres;
}
- mir_free(arg1);
- mir_free(arg2);
- mir_free(arg3);
return mir_tstrdup(_T(""));
}
-int registerRegExpTokens() {
-
+int registerRegExpTokens()
+{
registerIntToken(_T(REGEXPCHECK), parseRegExpCheck, TRF_FUNCTION, LPGEN("Regular Expressions")"\t(x,y)\t"LPGEN("(ANSI input only) the number of substring matches found in y with pattern x"));
registerIntToken(_T(REGEXPSUBSTR), parseRegExpSubstr, TRF_FUNCTION, LPGEN("Regular Expressions")"\t(x,y,z)\t"LPGEN("(ANSI input only) substring match number z found in subject y with pattern x"));
-
-
return 0;
} \ No newline at end of file
diff --git a/plugins/Variables/src/parse_str.cpp b/plugins/Variables/src/parse_str.cpp
index 3061ae7bf6..5509277224 100644
--- a/plugins/Variables/src/parse_str.cpp
+++ b/plugins/Variables/src/parse_str.cpp
@@ -29,8 +29,8 @@ static TCHAR *parseCaps(ARGUMENTSINFO *ai)
CharLower(res);
*cur = (TCHAR)CharUpper((LPTSTR)*cur);
cur++;
- while (*cur != _T('\0')) {
- if ((*cur == _T(' ')) && (*(cur+1) != _T('\0'))) {
+ while (*cur != 0) {
+ if ((*cur == ' ') && (*(cur+1) != 0)) {
cur++;
if (IsCharLower(*cur))
*cur = (TCHAR)CharUpper((LPTSTR)*cur);
@@ -53,8 +53,8 @@ static TCHAR *parseCaps2(ARGUMENTSINFO *ai)
TCHAR *cur = res;
*cur = (TCHAR)CharUpper((LPTSTR)*cur);
cur++;
- while (*cur != _T('\0')) {
- if ((*cur == _T(' ')) && (*(cur+1) != _T('\0'))) {
+ while (*cur != 0) {
+ if ((*cur == ' ') && (*(cur+1) != 0)) {
cur++;
if (IsCharLower(*cur))
*cur = (TCHAR)CharUpper((LPTSTR)*cur);
@@ -78,7 +78,7 @@ static TCHAR *parseEolToCrlf(ARGUMENTSINFO *ai)
TCHAR *res = mir_tstrdup(ai->targv[1]);
TCHAR *cur = res;
do {
- cur = _tcschr(cur, _T('\n'));
+ cur = _tcschr(cur, '\n');
if ((cur == NULL) || ((cur > res) && (*(cur-1) == '\r')))
continue;
@@ -106,7 +106,7 @@ static TCHAR *parseFixeol(ARGUMENTSINFO *ai)
return NULL;
TCHAR *cur = ai->targv[1];
- while ( (_tcscmp(cur, _T("\r\n"))) && (*cur != _T('\n')) && (*cur != _T('\0')))
+ while ( _tcscmp(cur, _T("\r\n")) && *cur != '\n' && *cur != 0)
cur++;
if (*cur == '\0')
@@ -139,7 +139,7 @@ static TCHAR *parseFixeol2(ARGUMENTSINFO *ai)
if (!_tcsncmp(cur, _T("\r\n"), _tcslen(_T("\r\n"))))
szEol = _T("\r\n");
- if (*cur == _T('\n'))
+ if (*cur == '\n')
szEol = _T("\n");
if (szEol != NULL) {
@@ -214,7 +214,7 @@ static TCHAR *parseLineCount(ARGUMENTSINFO *ai)
count += 1;
cur++;
}
- else if (*cur == _T('\n'))
+ else if (*cur == '\n')
count++;
cur++;
@@ -260,7 +260,7 @@ static TCHAR *parsePad(ARGUMENTSINFO *ai)
{
TCHAR padchar;
switch( ai->argc ) {
- case 3: padchar = _T(' '); break;
+ case 3: padchar = ' '; break;
case 4: padchar = *ai->targv[3]; break;
default: return NULL;
}
@@ -287,7 +287,7 @@ static TCHAR *parsePadright(ARGUMENTSINFO *ai)
{
TCHAR padchar;
switch (ai->argc ) {
- case 3: padchar = _T(' '); break;
+ case 3: padchar = ' '; break;
case 4: padchar = *ai->targv[3]; break;
default: return NULL;
}
@@ -314,7 +314,7 @@ static TCHAR *parsePadcut(ARGUMENTSINFO *ai)
{
TCHAR padchar;
switch( ai->argc ) {
- case 3: padchar = _T(' '); break;
+ case 3: padchar = ' '; break;
case 4: padchar = *ai->targv[3]; break;
default: return NULL;
}
@@ -343,7 +343,7 @@ static TCHAR *parsePadcutright(ARGUMENTSINFO *ai)
{
TCHAR padchar;
switch( ai->argc ) {
- case 3: padchar = _T(' '); break;
+ case 3: padchar = ' '; break;
case 4: padchar = *ai->targv[3]; break;
default: return NULL;
}
@@ -370,41 +370,37 @@ static TCHAR *parsePadcutright(ARGUMENTSINFO *ai)
static TCHAR *parseRepeat(ARGUMENTSINFO *ai)
{
- TCHAR *res;
- unsigned int i, count;
-
- if (ai->argc != 3) {
+ if (ai->argc != 3)
return NULL;
- }
- count = ttoi(ai->targv[2]);
- if (count < 0) {
+
+ int count = ttoi(ai->targv[2]);
+ if (count < 0)
return NULL;
- }
- res = (TCHAR*)mir_alloc((count * _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR));
- if (res == NULL) {
+
+ TCHAR *res = (TCHAR*)mir_alloc((count * _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR));
+ if (res == NULL)
return NULL;
- }
+
ZeroMemory(res, (count * _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR));
- for (i=0;i<count;i++) {
+ for (int i=0; i < count; i++)
_tcscat(res, ai->targv[1]);
- }
return res;
}
static TCHAR *parseReplace(ARGUMENTSINFO *ai)
{
- if ((ai->argc < 4) || (ai->argc%2 != 0)) {
+ if ((ai->argc < 4) || (ai->argc%2 != 0))
return NULL;
- }
+
TCHAR *cur;
size_t pos = 0;
TCHAR *res = mir_tstrdup(ai->targv[1]);
- for (size_t i=2;i<ai->argc;i+=2) {
- if ( _tcslen(ai->targv[i]) == 0) {
+ for (size_t i=2; i < ai->argc; i += 2) {
+ if ( _tcslen(ai->targv[i]) == 0)
continue;
- }
+
for (pos=0;pos<_tcslen(res);pos++) {
cur = res+pos;
if (!_tcsncmp(cur, ai->targv[i], _tcslen(ai->targv[i]))) {
@@ -425,49 +421,40 @@ static TCHAR *parseReplace(ARGUMENTSINFO *ai)
static TCHAR *parseRight(ARGUMENTSINFO *ai)
{
-
- int len;
- TCHAR *res;
-
- if (ai->argc != 3) {
+ if (ai->argc != 3)
return NULL;
- }
- len = ttoi(ai->targv[2]);
- if (len < 0) {
+
+ int len = ttoi(ai->targv[2]);
+ if (len < 0)
return NULL;
- }
+
len = min(len, (signed int)_tcslen(ai->targv[1]));
- res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
- if (res == NULL) {
+ TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
+ if (res == NULL)
return NULL;
- }
+
ZeroMemory(res, (len+1)*sizeof(TCHAR));
_tcsncpy(res, ai->targv[1]+_tcslen(ai->targv[1])-len, len);
-
return res;
}
/*
string, display size, scroll amount
*/
-static TCHAR *parseScroll(ARGUMENTSINFO *ai) {
-
- unsigned int display, move;
- TCHAR *res;
-
- if (ai->argc != 4) {
+static TCHAR *parseScroll(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 4)
return NULL;
- }
- if ( _tcslen(ai->targv[1]) == 0) {
-
+
+ if ( _tcslen(ai->targv[1]) == 0)
return mir_tstrdup(ai->targv[1]);
- }
- move = ttoi(ai->targv[3])%_tcslen(ai->targv[1]);
- display = ttoi(ai->targv[2]);
+
+ size_t move = ttoi(ai->targv[3])%_tcslen(ai->targv[1]);
+ size_t display = ttoi(ai->targv[2]);
if (display > _tcslen(ai->targv[1]))
display = (unsigned)_tcslen(ai->targv[1]);
- res = (TCHAR*)mir_alloc((2*_tcslen(ai->targv[1])+1)*sizeof(TCHAR));
+ TCHAR *res = (TCHAR*)mir_alloc((2*_tcslen(ai->targv[1])+1)*sizeof(TCHAR));
if (res == NULL)
return NULL;
@@ -475,67 +462,57 @@ static TCHAR *parseScroll(ARGUMENTSINFO *ai) {
_tcscpy(res, ai->targv[1]);
_tcscat(res, ai->targv[1]);
MoveMemory(res, res+move, (_tcslen(res+move)+1)*sizeof(TCHAR));
- *(res + display) = _T('\0');
+ *(res + display) = 0;
res = (TCHAR*)mir_realloc(res, (_tcslen(res)+1)*sizeof(TCHAR));
return res;
}
-static TCHAR *parseShortest(ARGUMENTSINFO *ai) {
-
- unsigned int i, iShort;
-
- if (ai->argc <= 1) {
+static TCHAR *parseShortest(ARGUMENTSINFO *ai)
+{
+ if (ai->argc <= 1)
return NULL;
- }
- iShort = 1;
- for (i=2;i<ai->argc;i++) {
- if ( _tcslen(ai->targv[i]) < _tcslen(ai->targv[iShort])) {
+
+ int iShort = 1;
+ for (unsigned i=2; i < ai->argc; i++)
+ if ( _tcslen(ai->targv[i]) < _tcslen(ai->targv[iShort]))
iShort = i;
- }
- }
return mir_tstrdup(ai->targv[iShort]);
}
-static TCHAR *parseStrchr(ARGUMENTSINFO *ai) {
+static TCHAR *parseStrchr(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 3)
+ return NULL;
- TCHAR *c;
char *szVal[34];
-
- if (ai->argc != 3) {
- return NULL;
- }
ZeroMemory(szVal, sizeof(szVal));
- c = _tcschr(ai->targv[1], *ai->targv[2]);
- if ((c == NULL) || (*c == _T('\0'))) {
+ TCHAR *c = _tcschr(ai->targv[1], *ai->targv[2]);
+ if (c == NULL || *c == 0)
return mir_tstrdup(_T("0"));
- }
return itot(c-ai->targv[1]+1);
}
-static TCHAR *parseStrcmp(ARGUMENTSINFO *ai) {
-
- if (ai->argc != 3) {
+static TCHAR *parseStrcmp(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 3)
return NULL;
- }
- if ( _tcscmp(ai->targv[1], ai->targv[2])) {
+
+ if ( _tcscmp(ai->targv[1], ai->targv[2]))
ai->flags |= AIF_FALSE;
- }
return mir_tstrdup(_T(""));
}
-static TCHAR *parseStrmcmp(ARGUMENTSINFO *ai) {
-
- unsigned int i;
-
- if (ai->argc < 3) {
+static TCHAR *parseStrmcmp(ARGUMENTSINFO *ai)
+{
+ if (ai->argc < 3)
return NULL;
- }
+
ai->flags |= AIF_FALSE;
- for (i=2;i<ai->argc;i++) {
+ for (unsigned i=2; i < ai->argc; i++) {
if (!_tcscmp(ai->targv[1], ai->targv[i])) {
ai->flags &= ~AIF_FALSE;
break;
@@ -545,94 +522,77 @@ static TCHAR *parseStrmcmp(ARGUMENTSINFO *ai) {
return mir_tstrdup(_T(""));
}
-static TCHAR *parseStrncmp(ARGUMENTSINFO *ai) {
-
- int n;
-
- if (ai->argc != 4) {
+static TCHAR *parseStrncmp(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 4)
return NULL;
- }
- n = ttoi(ai->targv[3]);
- if (n <= 0) {
+
+ int n = ttoi(ai->targv[3]);
+ if (n <= 0)
return NULL;
- }
- if ( _tcsncmp(ai->targv[1], ai->targv[2], n)) {
+
+ if ( _tcsncmp(ai->targv[1], ai->targv[2], n))
ai->flags |= AIF_FALSE;
- }
return mir_tstrdup(_T(""));
}
-static TCHAR *parseStricmp(ARGUMENTSINFO *ai) {
-
- if (ai->argc != 3) {
+static TCHAR *parseStricmp(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 3)
return NULL;
- }
- if ( _tcsicmp(ai->targv[1], ai->targv[2])) {
+ if ( _tcsicmp(ai->targv[1], ai->targv[2]))
ai->flags |= AIF_FALSE;
- }
return mir_tstrdup(_T(""));
}
-static TCHAR *parseStrnicmp(ARGUMENTSINFO *ai) {
-
- int n;
-
- if (ai->argc != 4) {
+static TCHAR *parseStrnicmp(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 4)
return NULL;
- }
- n = ttoi(ai->targv[3]);
- if (n <= 0) {
+
+ int n = ttoi(ai->targv[3]);
+ if (n <= 0)
return NULL;
- }
- if ( _tcsnicmp(ai->targv[1], ai->targv[2], n)) {
+
+ if ( _tcsnicmp(ai->targv[1], ai->targv[2], n))
ai->flags |= AIF_FALSE;
- }
return mir_tstrdup(_T(""));
}
-static TCHAR *parseStrrchr(ARGUMENTSINFO *ai) {
-
- TCHAR *c;
-
- if (ai->argc != 3) {
+static TCHAR *parseStrrchr(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 3)
return NULL;
- }
- c = _tcsrchr(ai->targv[1], *ai->targv[2]);
- if ((c == NULL) || (*c == _T('\0'))) {
+
+ TCHAR *c = _tcsrchr(ai->targv[1], *ai->targv[2]);
+ if ((c == NULL) || (*c == 0))
return mir_tstrdup(_T("0"));
- }
return itot(c-ai->targv[1]+1);
}
-static TCHAR *parseStrstr(ARGUMENTSINFO *ai) {
-
- TCHAR *c;
-
- if (ai->argc != 3) {
+static TCHAR *parseStrstr(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 3)
return NULL;
- }
- c = _tcsstr(ai->targv[1], ai->targv[2]);
- if ((c == NULL) || (*c == _T('\0'))) {
+
+ TCHAR *c = _tcsstr(ai->targv[1], ai->targv[2]);
+ if ((c == NULL) || (*c == 0))
return mir_tstrdup(_T("0"));
- }
return itot(c-ai->targv[1]+1);
}
-static TCHAR *parseSubstr(ARGUMENTSINFO *ai) {
-
- int from, to;
- TCHAR *res;
-
- if (ai->argc < 3) {
+static TCHAR *parseSubstr(ARGUMENTSINFO *ai)
+{
+ if (ai->argc < 3)
return NULL;
- }
- from = max(ttoi(ai->targv[2])-1, 0);
+
+ int to, from = max(ttoi(ai->targv[2])-1, 0);
if (ai->argc > 3)
to = min(ttoi(ai->targv[3]), (int)_tcslen(ai->targv[1]));
else
@@ -641,163 +601,139 @@ static TCHAR *parseSubstr(ARGUMENTSINFO *ai) {
if (to < from)
return NULL;
- res = (TCHAR*)mir_alloc((to-from+1)*sizeof(TCHAR));
+ TCHAR *res = (TCHAR*)mir_alloc((to-from+1)*sizeof(TCHAR));
ZeroMemory(res, (to-from+1)*sizeof(TCHAR));
_tcsncpy(res, ai->targv[1]+from, to-from);
-
return res;
}
-static TCHAR *parseSelect(ARGUMENTSINFO *ai) {
-
- int n;
-
- if (ai->argc <= 1) {
+static TCHAR *parseSelect(ARGUMENTSINFO *ai)
+{
+ if (ai->argc <= 1)
return NULL;
- }
- n = ttoi(ai->targv[1]);
- if ((n > (signed int)ai->argc-2) || (n <= 0)) {
+
+ int n = ttoi(ai->targv[1]);
+ if ((n > (signed int)ai->argc-2) || n <= 0)
return NULL;
- }
return mir_tstrdup(ai->targv[n+1]);
}
-static TCHAR *parseSwitch(ARGUMENTSINFO *ai) {
-
- unsigned int i;
-
- if (ai->argc%2 != 0) {
+static TCHAR *parseSwitch(ARGUMENTSINFO *ai)
+{
+ if (ai->argc%2 != 0)
return NULL;
- }
- for (i=2;i<ai->argc;i+=2) {
- if (!_tcscmp(ai->targv[1], ai->targv[i])) {
+
+ for (unsigned i=2; i < ai->argc; i += 2)
+ if (!_tcscmp(ai->targv[1], ai->targv[i]))
return mir_tstrdup(ai->targv[i+1]);
- }
- }
+
return NULL;
}
-static TCHAR *parseTrim(ARGUMENTSINFO *ai) {
-
- TCHAR *scur, *ecur, *res;
-
- if (ai->argc != 2) {
+static TCHAR *parseTrim(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
- scur = ai->targv[1];
- while (*scur == _T(' ')) {
+
+ TCHAR *scur = ai->targv[1];
+ while (*scur == ' ')
scur++;
- }
- ecur = ai->targv[1] + _tcslen(ai->targv[1])-1;
- while ( (*ecur == _T(' ')) && (ecur > ai->targv[1])) {
+
+ TCHAR *ecur = ai->targv[1] + _tcslen(ai->targv[1])-1;
+ while ( (*ecur == ' ') && (ecur > ai->targv[1]))
ecur--;
- }
- if (scur >= ecur) {
+
+ if (scur >= ecur)
return mir_tstrdup(_T(""));
- }
- res = (TCHAR*)mir_alloc((ecur-scur+2)*sizeof(TCHAR));
- if (res == NULL) {
+
+ TCHAR *res = (TCHAR*)mir_alloc((ecur-scur+2)*sizeof(TCHAR));
+ if (res == NULL)
return NULL;
- }
+
ZeroMemory(res, (ecur-scur+2)*sizeof(TCHAR));
_tcsncpy(res, scur, ecur-scur+1);
return res;
}
-static TCHAR *parseTab(ARGUMENTSINFO *ai) {
-
- int count, i;
- TCHAR *res, *cur;
-
- count = 1;
- if ((ai->argc == 2) && (_tcslen(ai->targv[1]) > 0)) {
+static TCHAR *parseTab(ARGUMENTSINFO *ai)
+{
+ int count = 1;
+ if ((ai->argc == 2) && (_tcslen(ai->targv[1]) > 0))
count = ttoi(ai->targv[1]);
- }
- if (count < 0) {
+
+ if (count < 0)
return NULL;
- }
- res = (TCHAR*)mir_alloc((count+1)*sizeof(TCHAR));
- if (res == NULL) {
+
+ TCHAR *res = (TCHAR*)mir_alloc((count+1)*sizeof(TCHAR));
+ if (res == NULL)
return NULL;
- }
- memset(res, _T('\0'), (count+1)*sizeof(TCHAR));
- cur = res;
- for (i=0;i<count;i++) {
- *cur++ = _T('\t');
- }
+
+ memset(res, 0, (count+1)*sizeof(TCHAR));
+ TCHAR *cur = res;
+ for (int i=0; i < count; i++)
+ *cur++ = '\t';
return res;
}
-static TCHAR *parseUpper(ARGUMENTSINFO *ai) {
-
- TCHAR *res;
-
- if (ai->argc != 2) {
+static TCHAR *parseUpper(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
- res = mir_tstrdup(ai->targv[1]);
- if (res == NULL) {
+
+ TCHAR *res = mir_tstrdup(ai->targv[1]);
+ if (res == NULL)
return NULL;
- }
return CharUpper(res);
}
-static TCHAR *getNthWord(TCHAR *szString, int w) {
-
- int count;
- TCHAR *res, *scur, *ecur;
-
- if (szString == NULL) {
+static TCHAR *getNthWord(TCHAR *szString, int w)
+{
+ if (szString == NULL)
return NULL;
- }
- count = 0;
- scur = szString;
- while (*scur == _T(' ')) {
+
+ int count = 0;
+ TCHAR *scur = szString;
+ while (*scur == ' ')
scur++;
- }
- count+=1;
+
+ count += 1;
while ( (count < w) && (scur < szString+_tcslen(szString))) {
- if (*scur == _T(' ')) {
- while (*scur == _T(' ')) {
+ if (*scur == ' ') {
+ while (*scur == ' ')
scur++;
- }
- count+=1;
+
+ count += 1;
}
- if (count < w) {
+ if (count < w)
scur++;
- }
}
- if (count != w) {
+ if (count != w)
return NULL;
- }
- ecur = scur;
- while ( (*ecur != _T(' ')) && (*ecur != _T('\0'))) {
+
+ TCHAR *ecur = scur;
+ while ( (*ecur != ' ') && (*ecur != 0))
ecur++;
- }
- res = (TCHAR*)mir_alloc((ecur-scur+1)*sizeof(TCHAR));
+
+ TCHAR *res = (TCHAR*)mir_alloc((ecur-scur+1)*sizeof(TCHAR));
if (res == NULL)
return NULL;
ZeroMemory(res, (ecur-scur+1)*sizeof(TCHAR));
_tcsncpy(res, scur, ecur-scur);
-
return res;
}
static TCHAR *parseWord(ARGUMENTSINFO *ai)
{
- int i, from, to;
- TCHAR *res, *szWord;
-
if (ai->argc < 3 || ai->argc > 4 )
return NULL;
- res = NULL;
- from = ttoi(ai->targv[2]);
+ TCHAR *res = NULL;
+ int to, from = ttoi(ai->targv[2]);
if (ai->argc == 4) {
if ( _tcslen(ai->targv[3]) > 0)
to = ttoi(ai->targv[3]);
@@ -809,8 +745,8 @@ static TCHAR *parseWord(ARGUMENTSINFO *ai)
if ((from == 0) || (to == 0) || (from > to))
return NULL;
- for (i=from;i<=to;i++) {
- szWord = getNthWord(ai->targv[1], i);
+ for (int i=from; i <= to; i++) {
+ TCHAR *szWord = getNthWord(ai->targv[1], i);
if (szWord == NULL)
return res;
diff --git a/plugins/Variables/src/parse_system.cpp b/plugins/Variables/src/parse_system.cpp
index 8cf00a28af..a5d8180e46 100644
--- a/plugins/Variables/src/parse_system.cpp
+++ b/plugins/Variables/src/parse_system.cpp
@@ -114,7 +114,8 @@ static TCHAR *parseCpuLoad(ARGUMENTSINFO *ai) {
}
#endif
-static TCHAR *parseCurrentDate(ARGUMENTSINFO *ai) {
+static TCHAR *parseCurrentDate(ARGUMENTSINFO *ai)
+{
TCHAR *szFormat;
if (ai->argc == 1 || (ai->argc > 1 && _tcslen(ai->targv[1]) == 0 ))
szFormat = NULL;
@@ -123,9 +124,9 @@ static TCHAR *parseCurrentDate(ARGUMENTSINFO *ai) {
int len = GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, szFormat, NULL, 0);
TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
+
if (GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, szFormat, res, len) == 0) {
mir_free(res);
return NULL;
@@ -134,7 +135,8 @@ static TCHAR *parseCurrentDate(ARGUMENTSINFO *ai) {
return res;
}
-static TCHAR *parseCurrentTime(ARGUMENTSINFO *ai) {
+static TCHAR *parseCurrentTime(ARGUMENTSINFO *ai)
+{
TCHAR *szFormat;
if (ai->argc == 1 || (ai->argc > 1) && (_tcslen(ai->targv[1]) == 0))
szFormat = NULL;
@@ -154,38 +156,35 @@ static TCHAR *parseCurrentTime(ARGUMENTSINFO *ai) {
return res;
}
-static TCHAR *parseDirectory(ARGUMENTSINFO *ai) {
-
- int depth, bi, ei;
- TCHAR *res;
-
+static TCHAR *parseDirectory(ARGUMENTSINFO *ai)
+{
if (ai->argc < 2 || ai->argc > 3 )
return NULL;
- depth = 0;
+ int depth = 0;
if (ai->argc == 3)
depth = ttoi(ai->targv[2]);
if (depth <= 0)
return mir_tstrdup(ai->targv[1]);
- for (ei = 0; ei < _tcslen(ai->targv[1]); ei++)
- {
+ size_t bi, ei;
+ for (ei = 0; ei < _tcslen(ai->targv[1]); ei++) {
if (ai->targv[1][ei] == '\\')
depth--;
- if (!depth) break;
+ if (!depth)
+ break;
}
if (ei >= _tcslen(ai->targv[1]))
return ai->targv[1];
- for (bi = ei - 1; bi > 0; bi--)
- {
- if (ai->targv[1][bi - 1] == '\\') break;
- }
- res = (TCHAR*)mir_alloc((ei - bi + 1) * sizeof(TCHAR));
+ for (bi = ei-1; bi > 0; bi--)
+ if (ai->targv[1][bi - 1] == '\\')
+ break;
+
+ TCHAR *res = (TCHAR*)mir_alloc((ei - bi + 1) * sizeof(TCHAR));
_tcsncpy(res, ai->targv[1] + bi, ei - bi);
res[ei - bi] = 0;
-
return res;
}
@@ -207,10 +206,10 @@ static TCHAR *parseDirectory2(ARGUMENTSINFO *ai)
TCHAR *ecur = ai->targv[1]+_tcslen(ai->targv[1]);
while (depth > 0) {
- while ( (*ecur != _T('\\')) && (ecur > ai->targv[1]))
+ while ( (*ecur != '\\') && (ecur > ai->targv[1]))
ecur--;
- if (*ecur != _T('\\'))
+ if (*ecur != '\\')
return NULL;
depth -= 1;
@@ -224,7 +223,8 @@ static TCHAR *parseDirectory2(ARGUMENTSINFO *ai)
return res;
}
-static int getTime(TCHAR *szTime, struct tm *date) {
+static int getTime(TCHAR *szTime, struct tm *date)
+{
// do some extra checks here
TCHAR *cur = szTime;
if (cur >= szTime+_tcslen(szTime))
@@ -232,46 +232,41 @@ static int getTime(TCHAR *szTime, struct tm *date) {
date->tm_mon = _tcstoul(cur, &cur, 10)-1;
cur++;
- if (cur >= szTime+_tcslen(szTime)) {
+ if (cur >= szTime+_tcslen(szTime))
return -1;
- }
+
date->tm_mday = _tcstoul(cur, &cur, 10);
cur++;
- if (cur >= szTime+_tcslen(szTime)) {
+ if (cur >= szTime+_tcslen(szTime))
return -1;
- }
+
date->tm_year = _tcstoul(cur, &cur, 10);
- if (date->tm_year > 2000) {
+ if (date->tm_year > 2000)
date->tm_year -= 2000;
- }
- else if (date->tm_year > 1900) {
+ else if (date->tm_year > 1900)
date->tm_year -= 1900;
- }
+
date->tm_year = date->tm_year<38?date->tm_year+100:date->tm_year;
cur++;
- if (cur >= szTime+_tcslen(szTime)) {
+ if (cur >= szTime+_tcslen(szTime))
return -1;
- }
+
date->tm_hour = _tcstoul(cur, &cur, 10);
cur++;
- if (cur >= szTime+_tcslen(szTime)) {
+ if (cur >= szTime+_tcslen(szTime))
return -1;
- }
+
date->tm_min = _tcstoul(cur, &cur, 10);
cur++;
- if (cur >= szTime+_tcslen(szTime)) {
+ if (cur >= szTime+_tcslen(szTime))
return -1;
- }
- date->tm_sec = _tcstoul(cur, &cur, 10);
+ date->tm_sec = _tcstoul(cur, &cur, 10);
return 0;
}
-/*
- date,date
- M/d/yy H:m:s
-*/
-static TCHAR *parseDiffTime(ARGUMENTSINFO *ai) {
-
+
+static TCHAR *parseDiffTime(ARGUMENTSINFO *ai)
+{
struct tm t0, t1;
TCHAR szTime[32];
double diff;
@@ -293,33 +288,33 @@ static TCHAR *parseDiffTime(ARGUMENTSINFO *ai) {
return mir_tstrdup(szTime);
}
-static TCHAR *parseDirExists(ARGUMENTSINFO *ai) {
- if (ai->argc != 2) {
+static TCHAR *parseDirExists(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
+
HANDLE hFile = CreateFile(ai->targv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
- if (hFile == INVALID_HANDLE_VALUE) {
+ if (hFile == INVALID_HANDLE_VALUE)
ai->flags |= AIF_FALSE;
- }
- else {
+ else
CloseHandle(hFile);
- }
return mir_tstrdup(_T(""));
}
-static TCHAR *parseEnvironmentVariable(ARGUMENTSINFO *ai) {
- if (ai->argc != 2) {
+static TCHAR *parseEnvironmentVariable(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
+
DWORD len = ExpandEnvironmentStrings(ai->targv[1], NULL, 0);
- if (len <= 0) {
+ if (len <= 0)
return NULL;
- }
+
TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
+
ZeroMemory(res, (len+1)*sizeof(TCHAR));
if (ExpandEnvironmentStrings(ai->targv[1], res, len) == 0) {
mir_free(res);
@@ -328,7 +323,8 @@ static TCHAR *parseEnvironmentVariable(ARGUMENTSINFO *ai) {
return res;
}
-static TCHAR *parseFileExists(ARGUMENTSINFO *ai) {
+static TCHAR *parseFileExists(ARGUMENTSINFO *ai)
+{
if (ai->argc != 2)
return NULL;
@@ -341,7 +337,8 @@ static TCHAR *parseFileExists(ARGUMENTSINFO *ai) {
return mir_tstrdup(_T(""));
}
-static TCHAR *parseFindWindow(ARGUMENTSINFO *ai) {
+static TCHAR *parseFindWindow(ARGUMENTSINFO *ai)
+{
if (ai->argc != 2)
return NULL;
@@ -350,56 +347,54 @@ static TCHAR *parseFindWindow(ARGUMENTSINFO *ai) {
return NULL;
int len = SendMessage(hWin, WM_GETTEXTLENGTH, 0, 0);
- if (len >= 0) {
- TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
- ZeroMemory(res, (len+1)*sizeof(TCHAR));
- GetWindowText(hWin, res, len+1);
- return res;
- }
- return NULL;
+ if (len == 0)
+ return NULL;
+
+ TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
+ ZeroMemory(res, (len+1)*sizeof(TCHAR));
+ GetWindowText(hWin, res, len+1);
+ return res;
}
// 1 = dir
// 2 = filter
// 3 = sperator
// 4 = [f]iles, [d]irs
-static TCHAR *parseListDir(ARGUMENTSINFO *ai) {
- BOOL bFiles, bDirs;
- WIN32_FIND_DATA ffd;
- TCHAR tszFirst[MAX_PATH], *tszRes, *tszSeperator, *tszFilter;
-
+static TCHAR *parseListDir(ARGUMENTSINFO *ai)
+{
if (ai->argc < 2)
return NULL;
+ TCHAR tszFirst[MAX_PATH], *tszRes, *tszSeperator, *tszFilter;
tszFirst[0] = 0;
tszSeperator = _T("\r\n");
tszFilter = _T("*");
tszRes = NULL;
- bFiles = bDirs = TRUE;
- if (ai->argc > 1) {
+
+ if (ai->argc > 1)
_tcsncpy(tszFirst, ai->targv[1], SIZEOF(tszFirst)-1);
- }
- if (ai->argc > 2) {
+
+ if (ai->argc > 2)
tszFilter = ai->targv[2];
- }
- if (ai->argc > 3) {
+
+ if (ai->argc > 3)
tszSeperator = ai->targv[3];
- }
+
+ BOOL bFiles = TRUE, bDirs = TRUE;
if (ai->argc > 4) {
- if (*ai->targv[4] == _T('f')) {
+ if (*ai->targv[4] == 'f')
bDirs = FALSE;
- }
- if (*ai->targv[4] == _T('d')) {
+ if (*ai->targv[4] == 'd')
bFiles = FALSE;
- }
}
- if (tszFirst[_tcslen(tszFirst)-1] == _T('\\')) {
+ if (tszFirst[_tcslen(tszFirst)-1] == '\\')
_tcsncat(tszFirst, tszFilter, SIZEOF(tszFirst) - _tcslen(tszFirst) - 1);
- }
else {
_tcsncat(tszFirst, _T("\\"), SIZEOF(tszFirst) - _tcslen(tszFirst) - 1);
_tcsncat(tszFirst, tszFilter, SIZEOF(tszFirst) - _tcslen(tszFirst) - 1);
}
+
+ WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(tszFirst, &ffd);
if (hFind == INVALID_HANDLE_VALUE) {
return NULL;
@@ -427,79 +422,73 @@ static TCHAR *parseListDir(ARGUMENTSINFO *ai) {
}
#ifndef WINE
-static BOOL CALLBACK MyProcessEnumerator(DWORD dwPID, WORD wTask, char *szProcess, LPARAM lParam) {
-
+static BOOL CALLBACK MyProcessEnumerator(DWORD dwPID, WORD wTask, char *szProcess, LPARAM lParam)
+{
char **szProc = (char **)lParam;
- if ((*szProc != NULL) && (!_stricmp(*szProc, szProcess))) {
+ if ((*szProc != NULL) && (!_stricmp(*szProc, szProcess)))
*szProc = NULL;
- }
return TRUE;
}
-static TCHAR *parseProcessRunning(ARGUMENTSINFO *ai) {
- if (ai->argc != 2) {
+static TCHAR *parseProcessRunning(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
char *szProc, *ref;
szProc = ref = mir_u2a(ai->targv[1]);
EnumProcs((PROCENUMPROC) MyProcessEnumerator, (LPARAM)&szProc);
- if (szProc != NULL) {
+ if (szProc != NULL)
ai->flags |= AIF_FALSE;
- }
+
mir_free(ref);
return mir_tstrdup(_T(""));
}
#endif
-static TCHAR *parseRegistryValue(ARGUMENTSINFO *ai) {
- if (ai->argc != 3) {
+static TCHAR *parseRegistryValue(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 3)
return NULL;
- }
HKEY hKey;
- TCHAR *subKey, *res;
DWORD len, type;
int err;
- TCHAR *key = subKey = mir_tstrdup(ai->targv[1]);
- if (subKey == NULL) {
+ TCHAR *key = mir_tstrdup(ai->targv[1]);
+ if (key == NULL)
return NULL;
- }
- TCHAR *cur = _tcschr(subKey, _T('\\'));
- if (cur == NULL) {
+
+ TCHAR *cur = _tcschr(key, '\\');
+ if (cur == NULL)
return NULL;
- }
- *cur = _T('\0');
- if (!_tcscmp(subKey, _T("HKEY_CLASSES_ROOT"))) {
+
+ *cur = 0;
+ if (!_tcscmp(key, _T("HKEY_CLASSES_ROOT")))
hKey = HKEY_CLASSES_ROOT;
- }
- else if (!_tcscmp(subKey, _T("HKEY_CURRENT_USER"))) {
+ else if (!_tcscmp(key, _T("HKEY_CURRENT_USER")))
hKey = HKEY_CURRENT_USER;
- }
- else if (!_tcscmp(subKey, _T("HKEY_LOCAL_MACHINE"))) {
+ else if (!_tcscmp(key, _T("HKEY_LOCAL_MACHINE")))
hKey = HKEY_LOCAL_MACHINE;
- }
- else if (!_tcscmp(subKey, _T("HKEY_USERS"))) {
+ else if (!_tcscmp(key, _T("HKEY_USERS")))
hKey = HKEY_USERS;
- }
else {
mir_free(key);
return NULL;
}
- subKey = cur+1;
+ TCHAR *subKey = cur+1;
if (RegOpenKeyEx(hKey, subKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS) {
mir_free(key);
return NULL;
}
mir_free(key);
len = MAX_REGVALUE_LENGTH+1;
- res = (TCHAR*)mir_alloc(len*sizeof(TCHAR));
- if (res == NULL) {
+ TCHAR *res = (TCHAR*)mir_alloc(len*sizeof(TCHAR));
+ if (res == NULL)
return NULL;
- }
+
ZeroMemory(res, len);
err = RegQueryValueEx(hKey, ai->targv[2], NULL, &type, (BYTE*)res, &len);
if ((err != ERROR_SUCCESS) || (type != REG_SZ)) {
@@ -512,11 +501,12 @@ static TCHAR *parseRegistryValue(ARGUMENTSINFO *ai) {
return res;
}
-static int TsToSystemTime(SYSTEMTIME *sysTime, time_t timestamp) {
+static int TsToSystemTime(SYSTEMTIME *sysTime, time_t timestamp)
+{
struct tm *pTime = localtime(&timestamp);
- if (pTime == NULL) {
+ if (pTime == NULL)
return -1;
- }
+
ZeroMemory(sysTime, sizeof(SYSTEMTIME));
sysTime->wDay = pTime->tm_mday;
sysTime->wDayOfWeek = pTime->tm_wday;
@@ -529,31 +519,30 @@ static int TsToSystemTime(SYSTEMTIME *sysTime, time_t timestamp) {
return 0;
}
-static TCHAR *parseTimestamp2Date(ARGUMENTSINFO *ai) {
- if (ai->argc <= 1) {
+static TCHAR *parseTimestamp2Date(ARGUMENTSINFO *ai)
+{
+ if (ai->argc <= 1)
return NULL;
- }
SYSTEMTIME sysTime;
TCHAR *szFormat;
time_t timestamp = ttoi(ai->targv[1]);
- if (timestamp == 0) {
+ if (timestamp == 0)
return NULL;
- }
- if ((ai->argc == 2) || ((ai->argc > 2) && (_tcslen(ai->targv[2]) == 0))) {
+
+ if ((ai->argc == 2) || ((ai->argc > 2) && (_tcslen(ai->targv[2]) == 0)))
szFormat = NULL;
- }
- else {
+ else
szFormat = ai->targv[2];
- }
- if (TsToSystemTime(&sysTime, timestamp) != 0) {
+
+ if (TsToSystemTime(&sysTime, timestamp) != 0)
return NULL;
- }
+
int len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &sysTime, szFormat, NULL, 0);
TCHAR *res = (TCHAR*)mir_calloc((len+1) * sizeof(TCHAR));
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
+
if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &sysTime, szFormat, res, len) == 0) {
mir_free(res);
return NULL;
@@ -562,31 +551,30 @@ static TCHAR *parseTimestamp2Date(ARGUMENTSINFO *ai) {
return res;
}
-static TCHAR *parseTimestamp2Time(ARGUMENTSINFO *ai) {
- if (ai->argc <= 1) {
+static TCHAR *parseTimestamp2Time(ARGUMENTSINFO *ai)
+{
+ if (ai->argc <= 1)
return NULL;
- }
SYSTEMTIME sysTime;
time_t timestamp = ttoi(ai->targv[1]);
- if (timestamp == 0) {
+ if (timestamp == 0)
return NULL;
- }
+
TCHAR *szFormat;
- if ((ai->argc == 2) || ((ai->argc > 2) && (_tcslen(ai->targv[2]) == 0))) {
+ if ((ai->argc == 2) || ((ai->argc > 2) && (_tcslen(ai->targv[2]) == 0)))
szFormat = NULL;
- }
- else {
+ else
szFormat = ai->targv[2];
- }
- if (TsToSystemTime(&sysTime, timestamp) != 0) {
+
+ if (TsToSystemTime(&sysTime, timestamp) != 0)
return NULL;
- }
+
int len = GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, szFormat, NULL, 0);
TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
+
if (GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, szFormat, res, len) == 0) {
mir_free(res);
return NULL;
@@ -595,8 +583,8 @@ static TCHAR *parseTimestamp2Time(ARGUMENTSINFO *ai) {
return res;
}
-static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
-
+static TCHAR *parseTextFile(ARGUMENTSINFO *ai)
+{
int lineNo, lineCount, csz;
unsigned int icur, bufSz;
DWORD fileSz, readSz, totalReadSz;
@@ -604,14 +592,14 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
TCHAR tUC, *res;
BYTE *pBuf, *pCur;
- if (ai->argc != 3) {
+ if (ai->argc != 3)
return NULL;
- }
+
lineNo = ttoi(ai->targv[2]);
HANDLE hFile = CreateFile(ai->targv[1], GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
- if (hFile == INVALID_HANDLE_VALUE) {
+ if (hFile == INVALID_HANDLE_VALUE)
return NULL;
- }
+
fileSz = GetFileSize(hFile, NULL);
if (fileSz == INVALID_FILE_SIZE) {
CloseHandle(hFile);
@@ -623,14 +611,11 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
csz = sizeof(char);
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
}
- else {
-
- csz = sizeof(TCHAR);
+ else csz = sizeof(TCHAR);
- }
totalReadSz = 0;
lineCount = 1;
- if (*ai->targv[2] == _T('0')) {
+ if (*ai->targv[2] == '0') {
// complete file
bufSz = fileSz + csz;
pBuf = (PBYTE)mir_calloc(bufSz);
@@ -644,9 +629,8 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
}
CloseHandle(hFile);
- if (tUC) {
+ if (tUC)
res = (TCHAR*)pBuf;
- }
else {
res = mir_a2t((char *)pBuf);
mir_free(pBuf);
@@ -657,9 +641,9 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
}
bufSz = TXTFILEBUFSZ*csz;
pBuf = (PBYTE)mir_calloc(bufSz);
- if (pBuf == NULL) {
+ if (pBuf == NULL)
return NULL;
- }
+
// count number of lines
do {
ZeroMemory(pBuf, bufSz);
@@ -675,27 +659,26 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
lineCount += 1;
pCur += csz;
}
- else if (*(TCHAR*)pCur == _T('\n')) {
+ else if (*(TCHAR*)pCur == '\n')
lineCount += 1;
- }
}
else {
if (!strncmp((char *)pCur, "\r\n", 2)) {
lineCount += 1;
pCur += csz;
}
- else if (*(char *)pCur == '\n') {
+ else if (*(char *)pCur == '\n')
lineCount += 1;
- }
}
}
- } while ( (totalReadSz < fileSz) && (readSz > 0));
- if (lineNo < 0) {
- lineNo = lineCount + lineNo + 1;
}
- else if (*ai->targv[2] == _T('r')) {
+ while ( (totalReadSz < fileSz) && (readSz > 0));
+
+ if (lineNo < 0)
+ lineNo = lineCount + lineNo + 1;
+ else if (*ai->targv[2] == 'r')
lineNo = (rand()%lineCount)+1;
- }
+
totalReadSz = 0;
lineCount = 1;
linePos = 0xFFFFFFFF;
@@ -708,34 +691,34 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
}
totalReadSz += readSz;
for (pCur = pBuf;((pCur < pBuf+bufSz) && (linePos == 0xFFFFFFFF));pCur+=csz) {
- if (lineCount == lineNo) {
+ if (lineCount == lineNo)
linePos = (tUC?csz:0) + totalReadSz - readSz + pCur - pBuf;
- }
+
if (tUC) {
if (!_tcsncmp((TCHAR*)pCur, _T("\r\n"), 2)) {
lineCount += 1;
pCur += csz;
}
- else if (*(TCHAR*)pCur == _T('\n')) {
+ else if (*(TCHAR*)pCur == '\n')
lineCount += 1;
- }
}
else {
if (!strncmp((char *)pCur, "\r\n", 2)) {
lineCount += 1;
pCur += csz;
}
- else if (*(char *)pCur == '\n') {
+ else if (*(char *)pCur == '\n')
lineCount += 1;
- }
}
}
- if (((tUC) && (*(TCHAR*)pCur == _T('\r'))) || ((!tUC) && (*(char *)pCur == '\r'))) {
+ if (((tUC) && (*(TCHAR*)pCur == '\r')) || ((!tUC) && (*(char *)pCur == '\r'))) {
// in case the \r was at the end of the buffer, \n could be next
SetFilePointer(hFile, -1*csz, NULL, FILE_CURRENT);
totalReadSz -= csz;
}
- } while ( (totalReadSz < fileSz) && (readSz > 0));
+ }
+ while ( (totalReadSz < fileSz) && (readSz > 0));
+
if (linePos < 0) {
CloseHandle(hFile);
mir_free(pBuf);
@@ -755,20 +738,17 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
CloseHandle(hFile);
return NULL;
}
- for (pCur = pBuf;(pCur < pBuf+readSz);pCur+=csz) {
- if ((tUC) && ((!_tcsncmp((TCHAR*)pCur, _T("\r\n"), 2)) || (*(TCHAR*)pCur == _T('\n'))) ||
+ for (pCur = pBuf;(pCur < pBuf+readSz); pCur += csz) {
+ if ((tUC) && ((!_tcsncmp((TCHAR*)pCur, _T("\r\n"), 2)) || (*(TCHAR*)pCur == '\n')) ||
((!tUC) && (((!strncmp((char *)pCur, "\r\n", 2)) || (*(char *)pCur == '\n'))))) {
CloseHandle(hFile);
- if (tUC) {
- *(TCHAR*)pCur = _T('\0');
- }
- else {
+ if (tUC)
+ *(TCHAR*)pCur = 0;
+ else
*(char *)pCur = '\0';
- }
- if (tUC) {
+ if (tUC)
res = (TCHAR*)pBuf;
- }
else {
res = mir_a2t((char *)pBuf);
mir_free(pBuf);
@@ -793,7 +773,7 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
if (readSz == bufSz-csz) {
// buffer must be increased
bufSz += TXTFILEBUFSZ*csz;
- if (((tUC) && (*(TCHAR*)pCur == _T('\r'))) || ((!tUC) && (*(char *)pCur == '\r'))) {
+ if (((tUC) && (*(TCHAR*)pCur == '\r')) || ((!tUC) && (*(char *)pCur == '\r'))) {
pCur -= csz;
}
icur = pCur - pBuf;
@@ -801,63 +781,63 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) {
pCur = pBuf+icur;
ZeroMemory(pCur+1, TXTFILEBUFSZ*csz);
}
- } while (readSz > 0);
+ }
+ while (readSz > 0);
CloseHandle(hFile);
return NULL;
}
#if _WIN32_WINNT>=0x0500
-static TCHAR *parseUpTime(ARGUMENTSINFO *ai) {
-
- HQUERY hQuery;
- PDH_FMT_COUNTERVALUE cValue;
- HCOUNTER hCounter;
- TCHAR szVal[32];
-
- if (ai->argc != 1) {
+static TCHAR *parseUpTime(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 1)
return NULL;
- }
+ HQUERY hQuery;
PDH_STATUS pdhStatus = PdhOpenQuery (NULL, 0, &hQuery);
- if (pdhStatus != ERROR_SUCCESS) {
+ if (pdhStatus != ERROR_SUCCESS)
return NULL;
- }
+
+ HCOUNTER hCounter;
pdhStatus = PdhAddCounter(hQuery, _T("\\System\\System Up Time"), 0, &hCounter);
if (pdhStatus != ERROR_SUCCESS) {
- pdhStatus = PdhCloseQuery(hQuery);
+ PdhCloseQuery(hQuery);
return NULL;
}
pdhStatus = PdhCollectQueryData(hQuery);
if (pdhStatus != ERROR_SUCCESS) {
PdhRemoveCounter(hCounter);
- pdhStatus = PdhCloseQuery(hQuery);
+ PdhCloseQuery(hQuery);
return NULL;
}
+
+ PDH_FMT_COUNTERVALUE cValue;
pdhStatus = PdhGetFormattedCounterValue(hCounter, PDH_FMT_LARGE, (LPDWORD)NULL, &cValue);
if (pdhStatus != ERROR_SUCCESS) {
PdhRemoveCounter(hCounter);
- pdhStatus = PdhCloseQuery(hQuery);
+ PdhCloseQuery(hQuery);
return NULL;
}
+
+ TCHAR szVal[32];
mir_sntprintf(szVal, SIZEOF(szVal), _T("%u"), cValue.largeValue);
PdhRemoveCounter(hCounter);
- pdhStatus = PdhCloseQuery(hQuery);
-
+ PdhCloseQuery(hQuery);
return mir_tstrdup(szVal);
}
#endif
static TCHAR *parseUserName(ARGUMENTSINFO *ai) {
- if (ai->argc != 1) {
+ if (ai->argc != 1)
return NULL;
- }
+
ai->flags |= AIF_DONTPARSE;
DWORD len = UNLEN;
TCHAR *res = (TCHAR*)mir_alloc(len + 1);
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
+
ZeroMemory(res, len + 1);
if (!GetUserName(res, &len)) {
mir_free(res);
@@ -883,11 +863,12 @@ static TCHAR *parseClipboard(ARGUMENTSINFO *ai) {
size_t len = _tcslen(tszText);
res = (TCHAR*)mir_alloc((len + 1) * sizeof(TCHAR));
_tcscpy(res, tszText);
- res[len] = _T('\0');
+ res[len] = 0;
GlobalUnlock(hData);
}
CloseClipboard();
- } }
+ }
+ }
return res;
}
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;
}
diff --git a/plugins/Variables/src/variables.h b/plugins/Variables/src/variables.h
index bd92fa74cb..e76387924a 100644
--- a/plugins/Variables/src/variables.h
+++ b/plugins/Variables/src/variables.h
@@ -77,43 +77,44 @@
#include "parse_variables.h"
#include "parse_xml.h"
-#define MODULENAME "Variables"
-
-#define SETTING_STARTUPTEXT "StartupText"
-#define SETTING_STRIPCRLF "StripCRLF"
-#define SETTING_STRIPWS "StripWS"
-#define SETTING_STRIPALL "StripAll"
-#define SETTING_PARSEATSTARTUP "ParseAtStartup"
-#define SETTING_SPLITTERPOS "SplitterPos"
-#define SETTING_SUBJECT "LastSubject"
-
-#define FIELD_CHAR '%'
-#define FUNC_CHAR '?'
-#define FUNC_ONCE_CHAR '!'
-#define DONTPARSE_CHAR '`'
-#define TRYPARSE_CHAR_OPEN '['
-#define TRYPARSE_CHAR_CLOSE ']'
-#define COMMENT_STRING "#"
+#define MODULENAME "Variables"
+
+#define SETTING_STARTUPTEXT "StartupText"
+#define SETTING_STRIPCRLF "StripCRLF"
+#define SETTING_STRIPWS "StripWS"
+#define SETTING_STRIPALL "StripAll"
+#define SETTING_PARSEATSTARTUP "ParseAtStartup"
+#define SETTING_SPLITTERPOS "SplitterPos"
+#define SETTING_SUBJECT "LastSubject"
+
+#define FIELD_CHAR '%'
+#define FUNC_CHAR '?'
+#define FUNC_ONCE_CHAR '!'
+#define DONTPARSE_CHAR '`'
+#define TRYPARSE_CHAR_OPEN '['
+#define TRYPARSE_CHAR_CLOSE ']'
+#define COMMENT_STRING "#"
// special tokens
-#define SUBJECT "subject"
-#define MIR_EXTRATEXT "extratext"
+#define SUBJECT "subject"
+#define MIR_EXTRATEXT "extratext"
// options
-#define IDT_PARSE 1
+#define IDT_PARSE 1
+
#define DM_SPLITTERMOVED (WM_USER+15)
// Messages you can send to the help window:
-#define VARM_PARSE (WM_APP+11) // wParam=lParam=0
-#define VARM_SETINPUTTEXT (WM_APP+12)
-#define VARM_GETINPUTTEXT (WM_APP+13)
-#define VARM_GETINPUTTEXTLENGTH (WM_APP+14)
-#define VARM_SETSUBJECT (WM_APP+15)
-#define VARM_GETSUBJECT (WM_APP+16) // wParam=HANDLE hContact
-#define VARM_SETEXTRATEXT (WM_APP+17)
-#define VARM_GETEXTRATEXT (WM_APP+18)
+#define VARM_PARSE (WM_APP+11) // wParam=lParam=0
+#define VARM_SETINPUTTEXT (WM_APP+12)
+#define VARM_GETINPUTTEXT (WM_APP+13)
+#define VARM_GETINPUTTEXTLENGTH (WM_APP+14)
+#define VARM_SETSUBJECT (WM_APP+15)
+#define VARM_GETSUBJECT (WM_APP+16) // wParam=HANDLE hContact
+#define VARM_SETEXTRATEXT (WM_APP+17)
+#define VARM_GETEXTRATEXT (WM_APP+18)
#define VARM_GETEXTRATEXTLENGTH (WM_APP+19)
-#define VARM_GETDIALOG (WM_APP+20)
+#define VARM_GETDIALOG (WM_APP+20)
// if a different struct internally is used, we can use TOKENREGISTEREX
#define TOKENREGISTEREX TOKENREGISTER