diff options
Diffstat (limited to 'plugins/Variables/src/parse_str.cpp')
-rw-r--r-- | plugins/Variables/src/parse_str.cpp | 257 |
1 files changed, 128 insertions, 129 deletions
diff --git a/plugins/Variables/src/parse_str.cpp b/plugins/Variables/src/parse_str.cpp index 002c02d99d..a92e54a6cc 100644 --- a/plugins/Variables/src/parse_str.cpp +++ b/plugins/Variables/src/parse_str.cpp @@ -2,7 +2,7 @@ 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
+ This program is 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.
@@ -30,7 +30,7 @@ static TCHAR *parseCaps(ARGUMENTSINFO *ai) *cur = (TCHAR)CharUpper((LPTSTR)*cur);
cur++;
while (*cur != 0) {
- if ((*cur == ' ') && (*(cur+1) != 0)) {
+ if ((*cur == ' ') && (*(cur + 1) != 0)) {
cur++;
if (IsCharLower(*cur))
*cur = (TCHAR)CharUpper((LPTSTR)*cur);
@@ -54,7 +54,7 @@ static TCHAR *parseCaps2(ARGUMENTSINFO *ai) *cur = (TCHAR)CharUpper((LPTSTR)*cur);
cur++;
while (*cur != 0) {
- if ((*cur == ' ') && (*(cur+1) != 0)) {
+ if ((*cur == ' ') && (*(cur + 1) != 0)) {
cur++;
if (IsCharLower(*cur))
*cur = (TCHAR)CharUpper((LPTSTR)*cur);
@@ -79,18 +79,18 @@ static TCHAR *parseEolToCrlf(ARGUMENTSINFO *ai) TCHAR *cur = res;
do {
cur = _tcschr(cur, '\n');
- if ((cur == NULL) || ((cur > res) && (*(cur-1) == '\r')))
+ if ((cur == NULL) || ((cur > res) && (*(cur - 1) == '\r')))
continue;
-
+
log_debug(cur);
int loc = cur - res;
- res = (TCHAR*)mir_realloc(res, (_tcslen(res)+2)*sizeof(TCHAR));
+ res = (TCHAR*)mir_realloc(res, (_tcslen(res) + 2)*sizeof(TCHAR));
cur = res + loc;
- MoveMemory(cur+2, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR));
- CopyMemory(cur, _T("\r\n"), 2*sizeof(TCHAR));
+ MoveMemory(cur + 2, cur + 1, (_tcslen(cur + 1) + 1)*sizeof(TCHAR));
+ CopyMemory(cur, _T("\r\n"), 2 * sizeof(TCHAR));
cur += 2;
}
- while (cur != NULL);
+ while (cur != NULL);
return res;
}
@@ -106,19 +106,19 @@ static TCHAR *parseFixeol(ARGUMENTSINFO *ai) return NULL;
TCHAR *cur = ai->targv[1];
- while ( _tcscmp(cur, _T("\r\n")) && *cur != '\n' && *cur != 0)
+ while (_tcscmp(cur, _T("\r\n")) && *cur != '\n' && *cur != 0)
cur++;
if (*cur == '\0')
return mir_tstrdup(ai->targv[1]);
cur--;
- TCHAR *res = (TCHAR*)mir_alloc((cur-ai->targv[1] + _tcslen(szReplacement) + 1)*sizeof(TCHAR));
+ TCHAR *res = (TCHAR*)mir_alloc((cur - ai->targv[1] + _tcslen(szReplacement) + 1)*sizeof(TCHAR));
if (res == NULL)
return res;
ZeroMemory(res, ((cur - ai->targv[1]) + 1)*sizeof(TCHAR));
- _tcsncpy(res, ai->targv[1], cur-ai->targv[1]);
+ _tcsncpy(res, ai->targv[1], cur - ai->targv[1]);
_tcscat(res, szReplacement);
return res;
}
@@ -126,15 +126,15 @@ static TCHAR *parseFixeol(ARGUMENTSINFO *ai) static TCHAR *parseFixeol2(ARGUMENTSINFO *ai)
{
TCHAR *szReplacement;
- switch( ai->argc ) {
- case 2: szReplacement = _T(" "); break;
- case 3: szReplacement = ai->targv[2]; break;
- default: return NULL;
+ switch (ai->argc) {
+ case 2: szReplacement = _T(" "); break;
+ case 3: szReplacement = ai->targv[2]; break;
+ default: return NULL;
}
TCHAR *res = mir_tstrdup(ai->targv[1]);
- for (size_t pos=0; pos < _tcslen(res); pos++ ) {
- TCHAR *cur = res+pos;
+ for (size_t pos = 0; pos < _tcslen(res); pos++) {
+ TCHAR *cur = res + pos;
TCHAR *szEol = NULL;
if (!_tcsncmp(cur, _T("\r\n"), _tcslen(_T("\r\n"))))
szEol = _T("\r\n");
@@ -143,16 +143,16 @@ static TCHAR *parseFixeol2(ARGUMENTSINFO *ai) szEol = _T("\n");
if (szEol != NULL) {
- if ( _tcslen(szReplacement) > _tcslen(szEol)) {
+ if (_tcslen(szReplacement) > _tcslen(szEol)) {
res = (TCHAR*)mir_realloc(res, (_tcslen(res) + _tcslen(szReplacement) - _tcslen(szEol) + 1)*sizeof(TCHAR));
- cur = res+pos;
+ cur = res + pos;
}
- MoveMemory(cur+_tcslen(szReplacement), cur+_tcslen(szEol), (_tcslen(cur+_tcslen(szEol))+1)*sizeof(TCHAR));
+ MoveMemory(cur + _tcslen(szReplacement), cur + _tcslen(szEol), (_tcslen(cur + _tcslen(szEol)) + 1)*sizeof(TCHAR));
CopyMemory(cur, szReplacement, _tcslen(szReplacement)*sizeof(TCHAR));
pos += _tcslen(szReplacement) - 1;
}
}
- return (TCHAR*)mir_realloc(res, (_tcslen(res)+1)*sizeof(TCHAR));
+ return (TCHAR*)mir_realloc(res, (_tcslen(res) + 1)*sizeof(TCHAR));
}
static TCHAR *parseInsert(ARGUMENTSINFO *ai)
@@ -171,7 +171,7 @@ static TCHAR *parseInsert(ARGUMENTSINFO *ai) ZeroMemory(res, (_tcslen(ai->targv[1]) + _tcslen(ai->targv[2]) + 1)*sizeof(TCHAR));
_tcsncpy(res, ai->targv[1], pos);
_tcscpy(res + pos, ai->targv[2]);
- _tcscpy(res+pos+_tcslen(ai->targv[2]), ai->targv[1]+pos);
+ _tcscpy(res + pos + _tcslen(ai->targv[2]), ai->targv[1] + pos);
return res;
}
@@ -189,7 +189,7 @@ static TCHAR *parseLeft(ARGUMENTSINFO *ai) if (res == NULL)
return NULL;
- ZeroMemory(res, (len+1)*sizeof(TCHAR));
+ ZeroMemory(res, (len + 1)*sizeof(TCHAR));
_tcsncpy(res, ai->targv[1], len);
return res;
}
@@ -199,7 +199,7 @@ static TCHAR *parseLen(ARGUMENTSINFO *ai) if (ai->argc != 2)
return NULL;
- return itot((int)_tcslen( ai->targv[1] ));
+ return itot((int)_tcslen(ai->targv[1]));
}
static TCHAR *parseLineCount(ARGUMENTSINFO *ai)
@@ -231,7 +231,7 @@ static TCHAR *parseLower(ARGUMENTSINFO *ai) TCHAR *res = mir_tstrdup(ai->targv[1]);
if (res == NULL)
return NULL;
-
+
return CharLower(res);
}
@@ -241,28 +241,28 @@ static TCHAR *parseLongest(ARGUMENTSINFO *ai) return NULL;
unsigned int iLong = 1;
- for (unsigned int i=2; i < ai->argc; i++)
- if ( _tcslen(ai->targv[i]) > _tcslen(ai->targv[iLong]))
- iLong = i;
+ for (unsigned int i = 2; i < ai->argc; i++)
+ if (_tcslen(ai->targv[i]) > _tcslen(ai->targv[iLong]))
+ iLong = i;
- return mir_tstrdup( ai->targv[iLong] );
+ return mir_tstrdup(ai->targv[iLong]);
}
static TCHAR *parseNoOp(ARGUMENTSINFO *ai)
{
if (ai->argc != 2)
return NULL;
-
- return mir_tstrdup( ai->targv[1] );
+
+ return mir_tstrdup(ai->targv[1]);
}
static TCHAR *parsePad(ARGUMENTSINFO *ai)
{
TCHAR padchar;
- switch( ai->argc ) {
- case 3: padchar = ' '; break;
- case 4: padchar = *ai->targv[3]; break;
- default: return NULL;
+ switch (ai->argc) {
+ case 3: padchar = ' '; break;
+ case 4: padchar = *ai->targv[3]; break;
+ default: return NULL;
}
int padding = ttoi(ai->targv[2]);
@@ -276,20 +276,20 @@ static TCHAR *parsePad(ARGUMENTSINFO *ai) ZeroMemory(res, (addcount + _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR));
TCHAR *cur = res;
- for ( unsigned int i=0; i < addcount; i++ )
+ for (unsigned int i = 0; i < addcount; i++)
*cur++ = padchar;
_tcscat(res, ai->targv[1]);
return res;
}
-
+
static TCHAR *parsePadright(ARGUMENTSINFO *ai)
{
TCHAR padchar;
- switch (ai->argc ) {
- case 3: padchar = ' '; break;
- case 4: padchar = *ai->targv[3]; break;
- default: return NULL;
+ switch (ai->argc) {
+ case 3: padchar = ' '; break;
+ case 4: padchar = *ai->targv[3]; break;
+ default: return NULL;
}
int padding = ttoi(ai->targv[2]);
@@ -304,19 +304,19 @@ static TCHAR *parsePadright(ARGUMENTSINFO *ai) ZeroMemory(res, (addcount + _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR));
_tcscpy(res, ai->targv[1]);
TCHAR *cur = res + _tcslen(ai->targv[1]);
- for (unsigned int i=0; i < addcount; i++)
+ for (unsigned int i = 0; i < addcount; i++)
*cur++ = padchar;
-
+
return res;
}
static TCHAR *parsePadcut(ARGUMENTSINFO *ai)
{
TCHAR padchar;
- switch( ai->argc ) {
- case 3: padchar = ' '; break;
- case 4: padchar = *ai->targv[3]; break;
- default: return NULL;
+ switch (ai->argc) {
+ case 3: padchar = ' '; break;
+ case 4: padchar = *ai->targv[3]; break;
+ default: return NULL;
}
int padding = ttoi(ai->targv[2]);
@@ -330,22 +330,22 @@ static TCHAR *parsePadcut(ARGUMENTSINFO *ai) ZeroMemory(res, (padding + 1)*sizeof(TCHAR));
TCHAR *cur = res;
- for (int i=0; i < addcount; i++)
+ for (int i = 0; i < addcount; i++)
*cur++ = padchar;
if (padding > addcount)
- _tcsncpy(res+addcount, ai->targv[1], padding-addcount);
-
+ _tcsncpy(res + addcount, ai->targv[1], padding - addcount);
+
return res;
}
static TCHAR *parsePadcutright(ARGUMENTSINFO *ai)
{
TCHAR padchar;
- switch( ai->argc ) {
- case 3: padchar = ' '; break;
- case 4: padchar = *ai->targv[3]; break;
- default: return NULL;
+ switch (ai->argc) {
+ case 3: padchar = ' '; break;
+ case 4: padchar = *ai->targv[3]; break;
+ default: return NULL;
}
int padding = ttoi(ai->targv[2]);
@@ -359,11 +359,11 @@ static TCHAR *parsePadcutright(ARGUMENTSINFO *ai) ZeroMemory(res, (padding + 1)*sizeof(TCHAR));
TCHAR *cur = res + padding - addcount;
- for (int i=0; i < addcount; i++ )
+ for (int i = 0; i < addcount; i++)
*cur++ = padchar;
- if (padding > addcount )
- _tcsncpy(res, ai->targv[1], padding-addcount);
+ if (padding > addcount)
+ _tcsncpy(res, ai->targv[1], padding - addcount);
return res;
}
@@ -382,7 +382,7 @@ static TCHAR *parseRepeat(ARGUMENTSINFO *ai) return NULL;
ZeroMemory(res, (count * _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR));
- for (int i=0; i < count; i++)
+ for (int i = 0; i < count; i++)
_tcscat(res, ai->targv[1]);
return res;
@@ -390,30 +390,30 @@ static TCHAR *parseRepeat(ARGUMENTSINFO *ai) 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;
+ for (pos = 0; pos<_tcslen(res); pos++) {
+ cur = res + pos;
if (!_tcsncmp(cur, ai->targv[i], _tcslen(ai->targv[i]))) {
- if ( _tcslen(ai->targv[i+1]) > _tcslen(ai->targv[i])) {
- res = (TCHAR*)mir_realloc(res, (_tcslen(res) + _tcslen(ai->targv[i+1]) - _tcslen(ai->targv[i]) + 1)*sizeof(TCHAR));
- cur = res+pos;
+ if (_tcslen(ai->targv[i + 1]) > _tcslen(ai->targv[i])) {
+ res = (TCHAR*)mir_realloc(res, (_tcslen(res) + _tcslen(ai->targv[i + 1]) - _tcslen(ai->targv[i]) + 1)*sizeof(TCHAR));
+ cur = res + pos;
}
- MoveMemory(cur+_tcslen(ai->targv[i+1]), cur+_tcslen(ai->targv[i]), (_tcslen(cur+_tcslen(ai->targv[i]))+1)*sizeof(TCHAR));
- CopyMemory(cur, ai->targv[i+1], _tcslen(ai->targv[i+1])*sizeof(TCHAR));
- pos += _tcslen(ai->targv[i+1]) - 1;
+ MoveMemory(cur + _tcslen(ai->targv[i + 1]), cur + _tcslen(ai->targv[i]), (_tcslen(cur + _tcslen(ai->targv[i])) + 1)*sizeof(TCHAR));
+ CopyMemory(cur, ai->targv[i + 1], _tcslen(ai->targv[i + 1])*sizeof(TCHAR));
+ pos += _tcslen(ai->targv[i + 1]) - 1;
}
}
- res = (TCHAR*)mir_realloc(res, (_tcslen(res)+1)*sizeof(TCHAR));
+ res = (TCHAR*)mir_realloc(res, (_tcslen(res) + 1)*sizeof(TCHAR));
}
return res;
@@ -429,44 +429,44 @@ static TCHAR *parseRight(ARGUMENTSINFO *ai) return NULL;
len = min(len, (signed int)_tcslen(ai->targv[1]));
- TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
+ 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);
+ ZeroMemory(res, (len + 1)*sizeof(TCHAR));
+ _tcsncpy(res, ai->targv[1] + _tcslen(ai->targv[1]) - len, len);
return res;
}
/*
- string, display size, scroll amount
-*/
+ string, display size, scroll amount
+ */
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]);
- size_t move = ttoi(ai->targv[3])%_tcslen(ai->targv[1]);
+ 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]);
- TCHAR *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;
- ZeroMemory(res, (2*_tcslen(ai->targv[1])+1)*sizeof(TCHAR));
+ ZeroMemory(res, (2 * _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR));
_tcscpy(res, ai->targv[1]);
_tcscat(res, ai->targv[1]);
- MoveMemory(res, res+move, (_tcslen(res+move)+1)*sizeof(TCHAR));
- *(res + display) = 0;
- res = (TCHAR*)mir_realloc(res, (_tcslen(res)+1)*sizeof(TCHAR));
-
+ MoveMemory(res, res + move, (_tcslen(res + move) + 1)*sizeof(TCHAR));
+ *(res + display) = 0;
+ res = (TCHAR*)mir_realloc(res, (_tcslen(res) + 1)*sizeof(TCHAR));
+
return res;
-}
+}
static TCHAR *parseShortest(ARGUMENTSINFO *ai)
{
@@ -474,9 +474,9 @@ static TCHAR *parseShortest(ARGUMENTSINFO *ai) return NULL;
int iShort = 1;
- for (unsigned i=2; i < ai->argc; i++)
- if ( _tcslen(ai->targv[i]) < _tcslen(ai->targv[iShort]))
- iShort = i;
+ 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]);
}
@@ -492,7 +492,7 @@ static TCHAR *parseStrchr(ARGUMENTSINFO *ai) if (c == NULL || *c == 0)
return mir_tstrdup(_T("0"));
- return itot(c-ai->targv[1]+1);
+ return itot(c - ai->targv[1] + 1);
}
static TCHAR *parseStrcmp(ARGUMENTSINFO *ai)
@@ -500,7 +500,7 @@ 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(""));
@@ -512,7 +512,7 @@ static TCHAR *parseStrmcmp(ARGUMENTSINFO *ai) return NULL;
ai->flags |= AIF_FALSE;
- for (unsigned 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;
@@ -531,7 +531,7 @@ static TCHAR *parseStrncmp(ARGUMENTSINFO *ai) 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(""));
@@ -542,7 +542,7 @@ 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(""));
@@ -557,12 +557,12 @@ static TCHAR *parseStrnicmp(ARGUMENTSINFO *ai) 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)
{
if (ai->argc != 3)
@@ -572,7 +572,7 @@ static TCHAR *parseStrrchr(ARGUMENTSINFO *ai) if ((c == NULL) || (*c == 0))
return mir_tstrdup(_T("0"));
- return itot(c-ai->targv[1]+1);
+ return itot(c - ai->targv[1] + 1);
}
static TCHAR *parseStrstr(ARGUMENTSINFO *ai)
@@ -584,7 +584,7 @@ static TCHAR *parseStrstr(ARGUMENTSINFO *ai) if ((c == NULL) || (*c == 0))
return mir_tstrdup(_T("0"));
- return itot(c-ai->targv[1]+1);
+ return itot(c - ai->targv[1] + 1);
}
static TCHAR *parseSubstr(ARGUMENTSINFO *ai)
@@ -592,7 +592,7 @@ static TCHAR *parseSubstr(ARGUMENTSINFO *ai) if (ai->argc < 3)
return NULL;
- int to, 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
@@ -601,9 +601,9 @@ static TCHAR *parseSubstr(ARGUMENTSINFO *ai) if (to < from)
return NULL;
- 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);
+ 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;
}
@@ -613,20 +613,20 @@ static TCHAR *parseSelect(ARGUMENTSINFO *ai) return NULL;
int n = ttoi(ai->targv[1]);
- if ((n > (signed int)ai->argc-2) || n <= 0)
+ if ((n > (signed int)ai->argc - 2) || n <= 0)
return NULL;
-
- return mir_tstrdup(ai->targv[n+1]);
+
+ return mir_tstrdup(ai->targv[n + 1]);
}
static TCHAR *parseSwitch(ARGUMENTSINFO *ai)
{
- if (ai->argc%2 != 0)
+ if (ai->argc % 2 != 0)
return NULL;
- for (unsigned i=2; i < ai->argc; i += 2)
- if (!_tcscmp(ai->targv[1], ai->targv[i]))
- return mir_tstrdup(ai->targv[i+1]);
+ 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;
}
@@ -640,19 +640,19 @@ static TCHAR *parseTrim(ARGUMENTSINFO *ai) while (*scur == ' ')
scur++;
- TCHAR *ecur = ai->targv[1] + _tcslen(ai->targv[1])-1;
- while ( (*ecur == ' ') && (ecur > ai->targv[1]))
+ TCHAR *ecur = ai->targv[1] + _tcslen(ai->targv[1]) - 1;
+ while ((*ecur == ' ') && (ecur > ai->targv[1]))
ecur--;
if (scur >= ecur)
return mir_tstrdup(_T(""));
- TCHAR *res = (TCHAR*)mir_alloc((ecur-scur+2)*sizeof(TCHAR));
+ 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);
+ ZeroMemory(res, (ecur - scur + 2)*sizeof(TCHAR));
+ _tcsncpy(res, scur, ecur - scur + 1);
return res;
}
@@ -666,15 +666,15 @@ static TCHAR *parseTab(ARGUMENTSINFO *ai) if (count < 0)
return NULL;
- TCHAR *res = (TCHAR*)mir_alloc((count+1)*sizeof(TCHAR));
+ TCHAR *res = (TCHAR*)mir_alloc((count + 1)*sizeof(TCHAR));
if (res == NULL)
return NULL;
- memset(res, 0, (count+1)*sizeof(TCHAR));
+ memset(res, 0, (count + 1)*sizeof(TCHAR));
TCHAR *cur = res;
- for (int i=0; i < count; i++)
+ for (int i = 0; i < count; i++)
*cur++ = '\t';
-
+
return res;
}
@@ -686,7 +686,7 @@ static TCHAR *parseUpper(ARGUMENTSINFO *ai) TCHAR *res = mir_tstrdup(ai->targv[1]);
if (res == NULL)
return NULL;
-
+
return CharUpper(res);
}
@@ -701,7 +701,7 @@ static TCHAR *getNthWord(TCHAR *szString, int w) scur++;
count += 1;
- while ( (count < w) && (scur < szString+_tcslen(szString))) {
+ while ((count < w) && (scur < szString + _tcslen(szString))) {
if (*scur == ' ') {
while (*scur == ' ')
scur++;
@@ -715,27 +715,27 @@ static TCHAR *getNthWord(TCHAR *szString, int w) return NULL;
TCHAR *ecur = scur;
- while ( (*ecur != ' ') && (*ecur != 0))
+ while ((*ecur != ' ') && (*ecur != 0))
ecur++;
- TCHAR *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);
+ ZeroMemory(res, (ecur - scur + 1)*sizeof(TCHAR));
+ _tcsncpy(res, scur, ecur - scur);
return res;
}
static TCHAR *parseWord(ARGUMENTSINFO *ai)
{
- if (ai->argc < 3 || ai->argc > 4 )
+ if (ai->argc < 3 || ai->argc > 4)
return NULL;
TCHAR *res = NULL;
int to, from = ttoi(ai->targv[2]);
if (ai->argc == 4) {
- if ( _tcslen(ai->targv[3]) > 0)
+ if (_tcslen(ai->targv[3]) > 0)
to = ttoi(ai->targv[3]);
else
to = 100000; // rework
@@ -745,7 +745,7 @@ static TCHAR *parseWord(ARGUMENTSINFO *ai) if ((from == 0) || (to == 0) || (from > to))
return NULL;
- for (int i=from; i <= to; i++) {
+ for (int i = from; i <= to; i++) {
TCHAR *szWord = getNthWord(ai->targv[1], i);
if (szWord == NULL)
return res;
@@ -777,8 +777,8 @@ static TCHAR *parseExtratext(ARGUMENTSINFO *ai) return NULL;
}
-int registerStrTokens() {
-
+int registerStrTokens()
+{
registerIntToken(_T(MIR_CAPS), parseCaps, TRF_FUNCTION, LPGEN("String Functions")"\t(x)\t"LPGEN("converts each first letter of a word to uppercase, all others to lowercase"));
registerIntToken(_T(MIR_CAPS2), parseCaps2, TRF_FUNCTION, LPGEN("String Functions")"\t(x)\t"LPGEN("converts each first letter of a word to uppercase"));
registerIntToken(_T(MIR_CRLF), parseCrlf, TRF_FUNCTION, LPGEN("String Functions")"\t()\t"LPGEN("inserts 'end of line' character"));
@@ -817,6 +817,5 @@ int registerStrTokens() { registerIntToken(_T(MIR_TAB), parseTab, TRF_FUNCTION, LPGEN("String Functions")"\t(x)\t"LPGEN("inserts x tab characters (x is optional)"));
registerIntToken(_T(MIR_UPPER), parseUpper, TRF_FUNCTION, LPGEN("String Functions")"\t(x)\t"LPGEN("converts x to upper case"));
registerIntToken(_T(MIR_WORD), parseWord, TRF_FUNCTION, LPGEN("String Functions")"\t(x,y,z)\t"LPGEN("words (separated by white spaces) number y to z from string x (z is optional)"));
-
return 0;
}
|