diff options
author | George Hazan <george.hazan@gmail.com> | 2014-03-12 13:40:35 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-03-12 13:40:35 +0000 |
commit | 8d371aa2b1fa5a7bfe835dee9b60d1407b33047b (patch) | |
tree | 66de3db76891d5676ce504d84b844e7912caa144 /plugins/TipperYM/src/subst.cpp | |
parent | 19862a932141daf02cb0ab5cae0f1222315ff49d (diff) |
db_event_next/db_event_prev: first parameter hContact added
git-svn-id: http://svn.miranda-ng.org/main/trunk@8576 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TipperYM/src/subst.cpp')
-rw-r--r-- | plugins/TipperYM/src/subst.cpp | 342 |
1 files changed, 107 insertions, 235 deletions
diff --git a/plugins/TipperYM/src/subst.cpp b/plugins/TipperYM/src/subst.cpp index ad64b02afe..8bb06815d4 100644 --- a/plugins/TipperYM/src/subst.cpp +++ b/plugins/TipperYM/src/subst.cpp @@ -28,10 +28,8 @@ bool DBGetContactSettingAsString(MCONTACT hContact, const char *szModuleName, co if (!szModuleName || !szSettingName)
return false;
- if (!db_get(hContact, szModuleName, szSettingName, &dbv))
- {
- switch(dbv.type)
- {
+ if (!db_get(hContact, szModuleName, szSettingName, &dbv)) {
+ switch (dbv.type) {
case DBVT_BYTE:
_itot(dbv.bVal, buff, 10);
break;
@@ -54,7 +52,6 @@ bool DBGetContactSettingAsString(MCONTACT hContact, const char *szModuleName, co if (dbv.pwszVal) wcsncpy(buff, dbv.pwszVal, bufflen);
buff[bufflen - 1] = 0;
break;
-
}
db_free(&dbv);
@@ -90,10 +87,8 @@ void StripBBCodesInPlace(TCHAR *swzText) size_t iRead = 0, iWrite = 0;
size_t iLen = _tcslen(swzText);
- while(iRead <= iLen) // copy terminating null too
- {
- while(iRead <= iLen && swzText[iRead] != '[')
- {
+ while(iRead <= iLen) { // copy terminating null too
+ while (iRead <= iLen && swzText[iRead] != '[') {
if (swzText[iRead] != swzText[iWrite]) swzText[iWrite] = swzText[iRead];
iRead++; iWrite++;
}
@@ -105,22 +100,19 @@ void StripBBCodesInPlace(TCHAR *swzText) iRead += 3;
else if (iLen - iRead >= 4 && (_tcsnicmp(swzText + iRead, _T("[/b]"), 4) == 0 || _tcsnicmp(swzText + iRead, _T("[/i]"), 4) == 0))
iRead += 4;
- else if (iLen - iRead >= 6 && (_tcsnicmp(swzText + iRead, _T("[color"), 6) == 0))
- {
- while(iRead < iLen && swzText[iRead] != ']') iRead++;
+ else if (iLen - iRead >= 6 && (_tcsnicmp(swzText + iRead, _T("[color"), 6) == 0)) {
+ while (iRead < iLen && swzText[iRead] != ']') iRead++;
iRead++;// skip the ']'
}
else if (iLen - iRead >= 8 && (_tcsnicmp(swzText + iRead, _T("[/color]"), 8) == 0))
iRead += 8;
- else if (iLen - iRead >= 5 && (_tcsnicmp(swzText + iRead, _T("[size"), 5) == 0))
- {
- while(iRead < iLen && swzText[iRead] != ']') iRead++;
+ else if (iLen - iRead >= 5 && (_tcsnicmp(swzText + iRead, _T("[size"), 5) == 0)) {
+ while (iRead < iLen && swzText[iRead] != ']') iRead++;
iRead++;// skip the ']'
}
else if (iLen - iRead >= 7 && (_tcsnicmp(swzText + iRead, _T("[/size]"), 7) == 0))
iRead += 7;
- else
- {
+ else {
if (swzText[iRead] != swzText[iWrite]) swzText[iWrite] = swzText[iRead];
iRead++; iWrite++;
}
@@ -129,14 +121,11 @@ void StripBBCodesInPlace(TCHAR *swzText) DWORD LastMessageTimestamp(MCONTACT hContact)
{
- HANDLE hDbEvent = db_event_last(hContact);
- while (hDbEvent) {
+ for (HANDLE hDbEvent = db_event_last(hContact); hDbEvent; hDbEvent = db_event_prev(hContact, hDbEvent)) {
DBEVENTINFO dbei = { sizeof(dbei) };
db_event_get(hDbEvent, &dbei);
if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_SENT))
return dbei.timestamp;
-
- hDbEvent = db_event_prev(hDbEvent);
}
return 0;
@@ -155,14 +144,9 @@ void FormatTimestamp(DWORD ts, char *szFormat, TCHAR *buff, int bufflen) bool Uid(MCONTACT hContact, char *szProto, TCHAR *buff, int bufflen)
{
- char *tmpProto = NULL;
-
- if (hContact) tmpProto = GetContactProto(hContact);
- else tmpProto = szProto;
-
- if (tmpProto)
- {
- char *szUid = ( char* )CallProtoService(tmpProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ char *tmpProto = (hContact) ? tmpProto = GetContactProto(hContact) : szProto;
+ if (tmpProto) {
+ char *szUid = (char*)CallProtoService(tmpProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
if (szUid && (INT_PTR)szUid != CALLSERVICE_NOTFOUND)
return DBGetContactSettingAsString(hContact, tmpProto, szUid, buff, bufflen);
}
@@ -172,11 +156,9 @@ bool Uid(MCONTACT hContact, char *szProto, TCHAR *buff, int bufflen) bool UidName(char *szProto, TCHAR *buff, int bufflen)
{
- if (szProto)
- {
- char *szUidName = ( char* )CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDTEXT, 0);
- if (szUidName && (INT_PTR)szUidName != CALLSERVICE_NOTFOUND)
- {
+ if (szProto) {
+ char *szUidName = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDTEXT, 0);
+ if (szUidName && (INT_PTR)szUidName != CALLSERVICE_NOTFOUND) {
a2t(szUidName, buff, bufflen);
return true;
}
@@ -186,8 +168,7 @@ bool UidName(char *szProto, TCHAR *buff, int bufflen) TCHAR *GetLastMessageText(MCONTACT hContact)
{
- HANDLE hDbEvent = db_event_last(hContact);
- while (hDbEvent) {
+ for (HANDLE hDbEvent = db_event_last(hContact); hDbEvent; hDbEvent = db_event_prev(hContact, hDbEvent)) {
DBEVENTINFO dbei = { sizeof(dbei) };
db_event_get(hDbEvent, &dbei);
if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_SENT)) {
@@ -203,8 +184,6 @@ TCHAR *GetLastMessageText(MCONTACT hContact) StripBBCodesInPlace(swzMsg);
return swzMsg;
}
-
- hDbEvent = db_event_prev(hDbEvent);
}
return 0;
@@ -212,37 +191,26 @@ TCHAR *GetLastMessageText(MCONTACT hContact) bool CanRetrieveStatusMsg(MCONTACT hContact, char *szProto)
{
- if (opt.bGetNewStatusMsg)
- {
+ if (opt.bGetNewStatusMsg) {
int iFlags = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_3, 0);
WORD wStatus = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE);
- if ((CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND) && (iFlags & Proto_Status2Flag(wStatus)))
- {
+ if ((CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND) && (iFlags & Proto_Status2Flag(wStatus))) {
iFlags = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & (PF1_VISLIST | PF1_INVISLIST);
- if (opt.bDisableIfInvisible && iFlags)
- {
+ if (opt.bDisableIfInvisible && iFlags) {
int iVisMode = db_get_w(hContact, szProto, "ApparentMode", 0);
int wProtoStatus = CallProtoService(szProto, PS_GETSTATUS, 0, 0);
if ((iVisMode == ID_STATUS_OFFLINE) || (wProtoStatus == ID_STATUS_INVISIBLE && iVisMode != ID_STATUS_ONLINE))
return false;
- else
- return true;
- }
- else
- {
return true;
}
- }
- else
- {
- return false;
+ return true;
}
}
return false;
}
-TCHAR *GetStatusMessageText(MCONTACT hContact)
+TCHAR* GetStatusMessageText(MCONTACT hContact)
{
TCHAR *swzMsg = 0;
DBVARIANT dbv;
@@ -263,16 +231,12 @@ TCHAR *GetStatusMessageText(MCONTACT hContact) }
}
- if (!swzMsg)
- {
+ if (!swzMsg) {
if (CanRetrieveStatusMsg(hContact, szProto))
- {
if (CallContactService(hContact, PSS_GETAWAYMSG, 0, 0))
return NULL;
- }
- if (!db_get_ts(hContact, "CList", "StatusMsg", &dbv))
- {
+ if (!db_get_ts(hContact, "CList", "StatusMsg", &dbv)) {
if (dbv.ptszVal && _tcslen(dbv.ptszVal) != 0)
swzMsg = mir_tstrdup(dbv.ptszVal);
db_free(&dbv);
@@ -289,30 +253,23 @@ TCHAR *GetStatusMessageText(MCONTACT hContact) bool GetSysSubstText(MCONTACT hContact, TCHAR *swzRawSpec, TCHAR *buff, int bufflen)
{
if (!_tcscmp(swzRawSpec, _T("uid")))
- {
return Uid(hContact, 0, buff, bufflen);
- }
- else if (!_tcscmp(swzRawSpec, _T("proto")))
- {
+
+ if (!_tcscmp(swzRawSpec, _T("proto"))) {
char *szProto = GetContactProto(hContact);
- if (szProto)
- {
+ if (szProto) {
a2t(szProto, buff, bufflen);
return true;
}
}
- else if (!_tcscmp(swzRawSpec, _T("account")))
- {
- char *szProto = ( char* )CallService(MS_PROTO_GETCONTACTBASEACCOUNT, hContact, 0);
- if ((INT_PTR)szProto == CALLSERVICE_NOTFOUND)
- {
+ else if (!_tcscmp(swzRawSpec, _T("account"))) {
+ char *szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEACCOUNT, hContact, 0);
+ if ((INT_PTR)szProto == CALLSERVICE_NOTFOUND) {
return GetSysSubstText(hContact, _T("proto"), buff, bufflen);
}
- else if (szProto)
- {
+ else if (szProto) {
PROTOACCOUNT *pa = ProtoGetAccount(szProto);
- if (pa && pa->tszAccountName)
- {
+ if (pa && pa->tszAccountName) {
_tcsncpy(buff, pa->tszAccountName, bufflen);
return true;
}
@@ -320,90 +277,77 @@ bool GetSysSubstText(MCONTACT hContact, TCHAR *swzRawSpec, TCHAR *buff, int buff return GetSysSubstText(hContact, _T("proto"), buff, bufflen);
}
}
- else if (!_tcscmp(swzRawSpec, _T("time")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("time"))) {
if (tmi.printDateTime && !tmi.printDateTimeByContact(hContact, _T("t"), buff, bufflen, TZF_KNOWNONLY))
return true;
}
- else if (!_tcscmp(swzRawSpec, _T("uidname")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("uidname"))) {
char *szProto = GetContactProto(hContact);
return UidName(szProto, buff, bufflen);
}
- else if (!_tcscmp(swzRawSpec, _T("status_msg")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("status_msg"))) {
TCHAR *swzMsg = GetStatusMessageText(hContact);
- if (swzMsg)
- {
+ if (swzMsg) {
_tcsncpy(buff, swzMsg, bufflen);
mir_free(swzMsg);
return true;
}
}
- else if (!_tcscmp(swzRawSpec, _T("last_msg")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("last_msg"))) {
TCHAR *swzMsg = GetLastMessageText(hContact);
- if (swzMsg)
- {
+ if (swzMsg) {
_tcsncpy(buff, swzMsg, bufflen);
mir_free(swzMsg);
return true;
}
}
- else if (!_tcscmp(swzRawSpec, _T("meta_subname")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("meta_subname"))) {
// get contact list name of active subcontact
HANDLE hSubContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, hContact, 0);
if (!hSubContact || (INT_PTR)hSubContact == CALLSERVICE_NOTFOUND) return false;
- TCHAR *swzNick = (TCHAR *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hSubContact, GCDNF_TCHAR);
+ TCHAR *swzNick = (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hSubContact, GCDNF_TCHAR);
if (swzNick) _tcsncpy(buff, swzNick, bufflen);
return true;
}
- else if (!_tcscmp(swzRawSpec, _T("meta_subuid")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("meta_subuid"))) {
MCONTACT hSubContact = (MCONTACT)CallService(MS_MC_GETMOSTONLINECONTACT, hContact, 0);
if (!hSubContact || (INT_PTR)hSubContact == CALLSERVICE_NOTFOUND)
return false;
return Uid(hSubContact, 0, buff, bufflen);
}
- else if (!_tcscmp(swzRawSpec, _T("meta_subproto")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("meta_subproto"))) {
// get protocol of active subcontact
MCONTACT hSubContact = (MCONTACT)CallService(MS_MC_GETMOSTONLINECONTACT, hContact, 0);
if (!hSubContact || (INT_PTR)hSubContact == CALLSERVICE_NOTFOUND)
return false;
return GetSysSubstText(hSubContact, _T("account"), buff, bufflen);
}
- else if (!_tcscmp(swzRawSpec, _T("last_msg_time")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("last_msg_time"))) {
DWORD ts = LastMessageTimestamp(hContact);
if (ts == 0) return false;
FormatTimestamp(ts, "t", buff, bufflen);
return true;
}
- else if (!_tcscmp(swzRawSpec, _T("last_msg_date")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("last_msg_date"))) {
DWORD ts = LastMessageTimestamp(hContact);
if (ts == 0) return false;
FormatTimestamp(ts, "d", buff, bufflen);
return true;
}
- else if (!_tcscmp(swzRawSpec, _T("last_msg_reltime")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("last_msg_reltime"))) {
DWORD ts = LastMessageTimestamp(hContact);
if (ts == 0) return false;
DWORD t = (DWORD)time(0);
DWORD diff = (t - ts);
int d = (diff / 60 / 60 / 24);
int h = (diff - d * 60 * 60 * 24) / 60 / 60;
- int m = (diff - d * 60 * 60 * 24 - h * 60 * 60) / 60;
+ int m = (diff - d * 60 * 60 * 24 - h * 60 * 60) / 60;
if (d > 0) mir_sntprintf(buff, bufflen, TranslateT("%dd %dh %dm"), d, h, m);
else if (h > 0) mir_sntprintf(buff, bufflen, TranslateT("%dh %dm"), h, m);
else mir_sntprintf(buff, bufflen, TranslateT("%dm"), m);
return true;
}
- else if (!_tcscmp(swzRawSpec, _T("msg_count_all")) || !_tcscmp(swzRawSpec, _T("msg_count_out")) || !_tcscmp(swzRawSpec, _T("msg_count_in")))
- {
+ else if (!_tcscmp(swzRawSpec, _T("msg_count_all")) || !_tcscmp(swzRawSpec, _T("msg_count_out")) || !_tcscmp(swzRawSpec, _T("msg_count_in"))) {
DWORD dwCountOut, dwCountIn;
DWORD dwMetaCountOut = 0, dwMetaCountIn = 0;
DWORD dwLastTs, dwNewTs, dwRecountTs;
@@ -448,7 +392,7 @@ bool GetSysSubstText(MCONTACT hContact, TCHAR *swzRawSpec, TCHAR *buff, int buff else break;
}
}
- dbe = db_event_prev(dbe);
+ dbe = db_event_prev(hTmpContact, dbe);
}
if (dwNewTs > dwLastTs) {
@@ -477,33 +421,25 @@ bool GetSubstText(MCONTACT hContact, const DISPLAYSUBST &ds, TCHAR *buff, int bu {
TranslateFunc *transFunc = 0;
for (int i = 0; i < iTransFuncsCount; i++)
- {
- if (translations[i].id == (DWORD)ds.iTranslateFuncId)
- {
+ if (translations[i].id == (DWORD)ds.iTranslateFuncId) {
transFunc = translations[i].transFunc;
break;
}
- }
if (!transFunc)
return false;
- switch (ds.type)
- {
- case DVT_DB:
- return transFunc(hContact, ds.szModuleName, ds.szSettingName, buff, bufflen) != 0;
- case DVT_PROTODB:
- {
- char *szProto = GetContactProto(hContact);
- if (szProto)
- {
- if (transFunc(hContact, szProto, ds.szSettingName, buff, bufflen) != 0)
- return true;
- else
- return transFunc(hContact, "UserInfo", ds.szSettingName, buff, bufflen) != 0;
- }
- break;
+ switch (ds.type) {
+ case DVT_DB:
+ return transFunc(hContact, ds.szModuleName, ds.szSettingName, buff, bufflen) != 0;
+ case DVT_PROTODB:
+ char *szProto = GetContactProto(hContact);
+ if (szProto) {
+ if (transFunc(hContact, szProto, ds.szSettingName, buff, bufflen) != 0)
+ return true;
+ return transFunc(hContact, "UserInfo", ds.szSettingName, buff, bufflen) != 0;
}
+ break;
}
return false;
}
@@ -511,30 +447,19 @@ bool GetSubstText(MCONTACT hContact, const DISPLAYSUBST &ds, TCHAR *buff, int bu bool GetRawSubstText(MCONTACT hContact, char *szRawSpec, TCHAR *buff, int bufflen)
{
size_t lenght = strlen(szRawSpec);
- for (size_t i = 0; i < lenght; i++)
- {
- if (szRawSpec[i] == '/')
- {
+ for (size_t i = 0; i < lenght; i++) {
+ if (szRawSpec[i] == '/') {
szRawSpec[i] = 0;
- if (strlen(szRawSpec) == 0)
- {
+ if (strlen(szRawSpec) == 0) {
char *szProto = GetContactProto(hContact);
- if (szProto)
- {
+ if (szProto) {
if (translations[0].transFunc(hContact, szProto, &szRawSpec[i + 1], buff, bufflen) != 0)
return true;
- else
- return translations[0].transFunc(hContact, "UserInfo", &szRawSpec[i + 1], buff, bufflen) != 0;
+ return translations[0].transFunc(hContact, "UserInfo", &szRawSpec[i + 1], buff, bufflen) != 0;
}
- else
- {
- return false;
- }
- }
- else
- {
- return translations[0].transFunc(hContact, szRawSpec, &szRawSpec[i + 1], buff, bufflen) != 0;
+ return false;
}
+ return translations[0].transFunc(hContact, szRawSpec, &szRawSpec[i + 1], buff, bufflen) != 0;
}
}
return false;
@@ -560,30 +485,20 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF TCHAR swzVName[LABEL_LEN];
TCHAR swzRep[VALUE_LEN], swzAlt[VALUE_LEN];
- while (si < iSourceLen && di < (size_t)iDestLen - 1)
- {
- if (swzVarSrc[si] == _T('%'))
- {
+ while (si < iSourceLen && di < (size_t)iDestLen - 1) {
+ if (swzVarSrc[si] == _T('%')) {
si++;
v = 0;
- while (si < iSourceLen && v < LABEL_LEN)
- {
+ while (si < iSourceLen && v < LABEL_LEN) {
if (swzVarSrc[si] == _T('%'))
- {
- // two %'s in a row in variable name disabled: e.g. %a%%b% - this is atbbguous]
- //if (si + 1 < iSourceLen && swzVarSrc[si + 1] == _T('%')) {
- // si++; // skip first %, allow following code to add the second one to the variable name
- //} else
- break;
- }
+ break;
+
swzVName[v] = swzVarSrc[si];
v++; si++;
}
if (v == 0) // bSubst len is 0 - just a % symbol
- {
swzDest[di] = _T('%');
- }
else if (si < iSourceLen) // we found end %
{
swzVName[v] = 0;
@@ -593,18 +508,14 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF // apply only to specific protocols
TCHAR *p = _tcsrchr(swzVName, _T('^')); // use last '^', so if you want a ^ in swzAlt text, you can just put a '^' on the end
- if (p)
- {
+ if (p) {
*p = 0;
p++;
- if (*p)
- {
+ if (*p) {
char *cp = GetContactProto(hContact);
- if (cp != NULL)
- {
+ if (cp != NULL) {
PROTOACCOUNT *acc = ProtoGetAccount(cp);
- if (acc != NULL)
- {
+ if (acc != NULL) {
cp = acc->szProtoName;
}
}
@@ -613,8 +524,7 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF goto empty;
bool negate = false;
- if (*p == _T('!'))
- {
+ if (*p == _T('!')) {
p++;
if (*p == 0) goto error;
negate = true;
@@ -627,15 +537,13 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF TCHAR *last = _tcsrchr(p, _T(','));
if (!last) last = p;
- while (p <= last + 1)
- {
+ while (p <= last + 1) {
len = (int)_tcscspn(p, _T(","));
t2a(p, sproto, len);
sproto[len] = 0;
p += len + 1;
- if (_stricmp(cp, sproto) == 0)
- {
+ if (_stricmp(cp, sproto) == 0) {
spec = true;
break;
}
@@ -649,28 +557,23 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF // get alternate text, if bSubst fails
swzAlt[0] = 0;
p = _tcschr(swzVName, _T('|')); // use first '|' - so you can use the '|' symbol in swzAlt text
- if (p)
- {
+ if (p) {
*p = 0; // clip swzAlt from swzVName
p++;
- if (_tcslen(p) > 4 && _tcsncmp(p, _T("raw:"), 4) == 0) // raw db substitution
- {
+ if (_tcslen(p) > 4 && _tcsncmp(p, _T("raw:"), 4) == 0) { // raw db substitution
char raw_spec[LABEL_LEN];
p += 4;
t2a(p, raw_spec, LABEL_LEN);
GetRawSubstText(hContact, raw_spec, swzAlt, VALUE_LEN);
}
- else if (_tcslen(p) > 4 && _tcsncmp(p, _T("sys:"), 4) == 0) // 'system' substitution
- {
+ else if (_tcslen(p) > 4 && _tcsncmp(p, _T("sys:"), 4) == 0) { // 'system' substitution
p += 4;
GetSysSubstText(hContact, p, swzAlt, VALUE_LEN);
}
- else
- {
+ else {
// see if we can find the bSubst
DSListNode *ds_node = opt.dsList;
- while(ds_node)
- {
+ while (ds_node) {
if (_tcscmp(ds_node->ds.swzName, p) == 0)
break;
@@ -678,11 +581,8 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF }
if (ds_node)
- {
GetSubstText(hContact, ds_node->ds, swzAlt, VALUE_LEN);
- }
- else
- {
+ else {
_tcsncpy(swzAlt, p, VALUE_LEN);
bAltSubst = true;
}
@@ -703,12 +603,10 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF {
bSubst = GetSysSubstText(hContact, &swzVName[4], swzRep, VALUE_LEN);
}
- else
- {
+ else {
// see if we can find the bSubst
DSListNode *ds_node = opt.dsList;
- while(ds_node)
- {
+ while (ds_node) {
if (_tcscmp(ds_node->ds.swzName, swzVName) == 0)
break;
@@ -721,33 +619,22 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF bSubst = GetSubstText(hContact, ds_node->ds, swzRep, VALUE_LEN);
}
- if (bSubst)
- {
+ if (bSubst) {
size_t rep_len = _tcslen(swzRep);
_tcsncpy(&swzDest[di], swzRep, min(rep_len, iDestLen - di));
di += rep_len - 1; // -1 because we inc at bottom of loop
}
- else if (bAltSubst)
- {
+ else if (bAltSubst) {
size_t alt_len = _tcslen(swzAlt);
_tcsncpy(&swzDest[di], swzAlt, min(alt_len, iDestLen - di));
di += alt_len - 1; // -1 because we inc at bottom of loop
}
- else
- {
- goto empty; // empty value
- }
-
+ else goto empty; // empty value
}
else // no end % - error
- {
goto error;
- }
- }
- else
- {
- swzDest[di] = swzVarSrc[si];
}
+ else swzDest[di] = swzVarSrc[si];
si++;
di++;
@@ -756,8 +643,7 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF mir_free(swzVarSrc);
swzDest[di] = 0;
- if (parseTipperVarsFirst)
- {
+ if (parseTipperVarsFirst) {
swzVarSrc = variables_parsedup((TCHAR *)swzDest, 0, hContact);
_tcscpy(swzDest, swzVarSrc);
mir_free(swzVarSrc);
@@ -765,8 +651,7 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF // check for a 'blank' string - just spaces etc
- for (si = 0; si <= di; si++)
- {
+ for (si = 0; si <= di; si++) {
if (swzDest[si] != 0 && swzDest[si] != _T(' ') && swzDest[si] != _T('\t') && swzDest[si] != _T('\r') && swzDest[si] != _T('\n'))
return true;
}
@@ -796,10 +681,8 @@ bool GetValueText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, int buf void TruncateString(TCHAR *swzText)
{
- if (swzText && opt.iLimitCharCount > 3)
- {
- if ((int)_tcslen(swzText) > opt.iLimitCharCount)
- {
+ if (swzText && opt.iLimitCharCount > 3) {
+ if ((int)_tcslen(swzText) > opt.iLimitCharCount) {
swzText[opt.iLimitCharCount - 3] = 0;
_tcscat(swzText, _T("..."));
}
@@ -818,24 +701,19 @@ TCHAR *GetProtoStatusMessage(char *szProto, WORD wStatus) TCHAR *swzText = (TCHAR *)CallProtoService(szProto, PS_GETMYAWAYMSG, 0, SGMA_TCHAR);
if ((INT_PTR)swzText == CALLSERVICE_NOTFOUND)
- {
swzText = (TCHAR*)CallService(MS_AWAYMSG_GETSTATUSMSGT, wStatus, 0);
- }
- else if (swzText == NULL)
- {
+ else if (swzText == NULL) {
// try to use service without SGMA_TCHAR
char *tmpMsg = (char *)CallProtoService(szProto, PS_GETMYAWAYMSG, 0, 0);
- if (tmpMsg && (INT_PTR)tmpMsg != CALLSERVICE_NOTFOUND)
- {
+ if (tmpMsg && (INT_PTR)tmpMsg != CALLSERVICE_NOTFOUND) {
swzText = mir_a2t(tmpMsg);
mir_free(tmpMsg);
}
}
- if (swzText && !swzText[0])
- {
+ if (swzText && !swzText[0]) {
mir_free(swzText);
swzText = NULL;
}
@@ -854,15 +732,13 @@ TCHAR *GetProtoExtraStatusTitle(char *szProto) if (!szProto)
return NULL;
- if (!db_get_ts(0, szProto, "XStatusName", &dbv))
- {
+ if (!db_get_ts(0, szProto, "XStatusName", &dbv)) {
if (_tcslen(dbv.ptszVal) != 0)
swzText = mir_tstrdup(dbv.ptszVal);
db_free(&dbv);
}
- if (!swzText)
- {
+ if (!swzText) {
TCHAR buff[256];
if (EmptyXStatusToDefaultName(0, szProto, 0, buff, 256))
swzText = mir_tstrdup(buff);
@@ -876,12 +752,11 @@ TCHAR *GetProtoExtraStatusTitle(char *szProto) TCHAR *GetProtoExtraStatusMessage(char *szProto)
{
- DBVARIANT dbv;
- TCHAR *swzText = NULL;
-
if (!szProto)
return NULL;
+ TCHAR *swzText = NULL;
+ DBVARIANT dbv;
if (!db_get_ts(0, szProto, "XStatusMsg", &dbv)) {
if (_tcslen(dbv.ptszVal) != 0)
swzText = mir_tstrdup(dbv.ptszVal);
@@ -890,7 +765,7 @@ TCHAR *GetProtoExtraStatusMessage(char *szProto) if (ServiceExists(MS_VARS_FORMATSTRING)) {
MCONTACT hContact = db_find_first();
char *proto = GetContactProto(hContact);
- while(!proto) {
+ while (!proto) {
hContact = db_find_next(hContact);
if (hContact)
proto = GetContactProto(hContact);
@@ -920,8 +795,7 @@ TCHAR *GetListeningTo(char *szProto) if (!szProto)
return NULL;
- if (!db_get_ts(0, szProto, "ListeningTo", &dbv))
- {
+ if (!db_get_ts(0, szProto, "ListeningTo", &dbv)) {
if (_tcslen(dbv.ptszVal) != 0)
swzText = mir_tstrdup(dbv.ptszVal);
db_free(&dbv);
@@ -937,14 +811,13 @@ TCHAR *GetJabberAdvStatusText(char *szProto, const char *szSlot, const char *szV {
DBVARIANT dbv;
TCHAR *swzText = NULL;
- char szSetting[128];
if (!szProto)
return NULL;
+ char szSetting[128];
mir_snprintf(szSetting, SIZEOF(szSetting), "%s/%s/%s", szProto, szSlot, szValue);
- if (!db_get_ts(0, "AdvStatus", szSetting, &dbv))
- {
+ if (!db_get_ts(0, "AdvStatus", szSetting, &dbv)) {
if (_tcslen(dbv.ptszVal) != 0)
swzText = mir_tstrdup(dbv.ptszVal);
db_free(&dbv);
@@ -960,14 +833,13 @@ HICON GetJabberActivityIcon(MCONTACT hContact, char *szProto) {
DBVARIANT dbv;
HICON hIcon = NULL;
- char szSetting[128];
if (!szProto)
return NULL;
+ char szSetting[128];
mir_snprintf(szSetting, SIZEOF(szSetting), "%s/%s/%s", szProto, "activity", "icon");
- if (!db_get_s(hContact, "AdvStatus", szSetting, &dbv))
- {
+ if (!db_get_s(hContact, "AdvStatus", szSetting, &dbv)) {
hIcon = Skin_GetIcon(dbv.pszVal);
db_free(&dbv);
}
|