diff options
author | George Hazan <george.hazan@gmail.com> | 2016-04-08 10:49:29 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2016-04-08 10:49:29 +0000 |
commit | 017b7066ab8c82880a62f9208e25c36c43c76a03 (patch) | |
tree | ec1c940848a51bfd77b0ac1c87a53d8e99f9ae7a /plugins/Variables/src/parse_miranda.cpp | |
parent | 6cb46f5857189fc42e05981ca2c01bb00e65e59f (diff) |
Variables:
- massive code simplification;
- old shit removed and replaced with lists;
- version bump.
git-svn-id: http://svn.miranda-ng.org/main/trunk@16613 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Variables/src/parse_miranda.cpp')
-rw-r--r-- | plugins/Variables/src/parse_miranda.cpp | 129 |
1 files changed, 24 insertions, 105 deletions
diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp index 598fc4dd6d..4e3251e123 100644 --- a/plugins/Variables/src/parse_miranda.cpp +++ b/plugins/Variables/src/parse_miranda.cpp @@ -70,7 +70,6 @@ static int getContactInfoFlags(TCHAR *tszDesc) if (flags != 0)
flags |= CI_CNFINFO;
}
- flags |= CI_TCHAR;
return flags;
}
@@ -81,28 +80,18 @@ static TCHAR* parseContact(ARGUMENTSINFO *ai) return NULL;
int n = 0;
- if (ai->argc == 4 && *ai->targv[3] != 'r')
- n = ttoi(ai->targv[3]) - 1;
+ if (ai->argc == 4) {
+ if (*ai->targv[3] != 'r') // random contact
+ n = -1;
+ else
+ n = ttoi(ai->targv[3]) - 1;
+ }
- CONTACTSINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.tszContact = ai->targv[1];
- ci.flags = getContactInfoFlags(ai->targv[2]);
- int count = getContactFromString(&ci);
- if (count == 0 || ci.hContacts == NULL)
+ MCONTACT hContact = getContactFromString(ai->targv[1], getContactInfoFlags(ai->targv[2]), n);
+ if (hContact == INVALID_CONTACT_ID)
return NULL;
- if (ai->argc == 4 && *ai->targv[3] == 'r')
- n = rand() % count;
-
- if (count != 1 && ai->argc != 4) {
- mir_free(ci.hContacts);
- return NULL;
- }
- MCONTACT hContact = ci.hContacts[n];
log_debugA("contact: %x", hContact);
- mir_free(ci.hContacts);
-
return encodeContactToString(hContact);
}
@@ -111,14 +100,7 @@ static TCHAR* parseContactCount(ARGUMENTSINFO *ai) if (ai->argc != 3)
return NULL;
- CONTACTSINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.tszContact = ai->targv[1];
- ci.flags = getContactInfoFlags(ai->targv[2]);
- int count = getContactFromString(&ci);
- if (count != 0 && ci.hContacts != NULL)
- mir_free(ci.hContacts);
-
+ int count = getContactFromString(ai->targv[1], CI_NEEDCOUNT | getContactInfoFlags(ai->targv[2]));
return itot(count);
}
@@ -127,20 +109,10 @@ static TCHAR* parseContactInfo(ARGUMENTSINFO *ai) if (ai->argc != 3)
return NULL;
- MCONTACT hContact = NULL;
- CONTACTSINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.tszContact = ai->targv[1];
- ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
- int count = getContactFromString(&ci);
- if (count == 1 && ci.hContacts != NULL) {
- hContact = ci.hContacts[0];
- mir_free(ci.hContacts);
- }
- else {
- mir_free(ci.hContacts);
+ MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF);
+ if (hContact == INVALID_CONTACT_ID)
return NULL;
- }
+
BYTE type = getContactInfoType(ai->targv[2]);
if (type == 0)
return NULL;
@@ -211,19 +183,9 @@ static TCHAR* parseDBSetting(ARGUMENTSINFO *ai) MCONTACT hContact = NULL;
if (mir_tstrlen(ai->targv[1]) > 0) {
- CONTACTSINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.tszContact = ai->targv[1];
- ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
- int count = getContactFromString(&ci);
- if (count == 1 && ci.hContacts != NULL) {
- hContact = ci.hContacts[0];
- mir_free(ci.hContacts);
- }
- else {
- mir_free(ci.hContacts);
+ hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF);
+ if (hContact == INVALID_CONTACT_ID)
return NULL;
- }
}
char *szModule = mir_t2a(ai->targv[2]);
@@ -249,20 +211,9 @@ static TCHAR* parseLastSeenDate(ARGUMENTSINFO *ai) if (ai->argc <= 1)
return NULL;
- MCONTACT hContact = NULL;
- CONTACTSINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.tszContact = ai->targv[1];
- ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
- int count = getContactFromString(&ci);
- if (count == 1 && ci.hContacts != NULL) {
- hContact = ci.hContacts[0];
- mir_free(ci.hContacts);
- }
- else {
- mir_free(ci.hContacts);
+ MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF);
+ if (hContact == INVALID_CONTACT_ID)
return NULL;
- }
TCHAR *szFormat;
if (ai->argc == 2 || (ai->argc > 2 && mir_tstrlen(ai->targv[2]) == 0))
@@ -302,21 +253,9 @@ static TCHAR* parseLastSeenTime(ARGUMENTSINFO *ai) if (ai->argc <= 1)
return NULL;
- MCONTACT hContact = NULL;
-
- CONTACTSINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.tszContact = ai->targv[1];
- ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
- int count = getContactFromString(&ci);
- if (count == 1 && ci.hContacts != NULL) {
- hContact = ci.hContacts[0];
- mir_free(ci.hContacts);
- }
- else {
- mir_free(ci.hContacts);
+ MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF);
+ if (hContact == INVALID_CONTACT_ID)
return NULL;
- }
TCHAR *szFormat;
if (ai->argc == 2 || (ai->argc > 2 && mir_tstrlen(ai->targv[2]) == 0))
@@ -357,20 +296,10 @@ static TCHAR* parseLastSeenStatus(ARGUMENTSINFO *ai) if (ai->argc != 2)
return NULL;
- MCONTACT hContact = NULL;
- CONTACTSINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.tszContact = ai->targv[1];
- ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
- int count = getContactFromString(&ci);
- if ((count == 1) && (ci.hContacts != NULL)) {
- hContact = ci.hContacts[0];
- mir_free(ci.hContacts);
- }
- else {
- mir_free(ci.hContacts);
+ MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF);
+ if (hContact == INVALID_CONTACT_ID)
return NULL;
- }
+
char *szModule = SEEN_MODULE;
int status = db_get_w(hContact, szModule, "Status", 0);
if (status == 0)
@@ -641,19 +570,9 @@ static TCHAR* parseDbEvent(ARGUMENTSINFO *ai) break;
}
- MCONTACT hContact = NULL;
-
- CONTACTSINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.tszContact = ai->targv[1];
- ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
- int count = getContactFromString(&ci);
- if ((count == 1) && (ci.hContacts != NULL)) {
- hContact = ci.hContacts[0];
- mir_free(ci.hContacts);
- }
- else if (ci.hContacts != NULL)
- mir_free(ci.hContacts);
+ MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF);
+ if (hContact == INVALID_CONTACT_ID)
+ return NULL;
MEVENT hDbEvent = findDbEvent(hContact, NULL, flags);
if (hDbEvent == NULL)
|