From bcb27264ba737778e5d3edad36088bacf74f0236 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 9 Apr 2013 20:03:46 +0000 Subject: - short function names allows to write database loops in one string; - 'continue' operator can be used then; - multiple bugs fixed in clists; - code becomes much more compact; git-svn-id: http://svn.miranda-ng.org/main/trunk@4403 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/CmdLine/src/mimcmd_handlers.cpp | 65 +++++++++------------------------ plugins/CmdLine/src/utils.cpp | 17 +++------ 2 files changed, 23 insertions(+), 59 deletions(-) (limited to 'plugins/CmdLine/src') diff --git a/plugins/CmdLine/src/mimcmd_handlers.cpp b/plugins/CmdLine/src/mimcmd_handlers.cpp index 12d3dc78b7..18c39570e7 100644 --- a/plugins/CmdLine/src/mimcmd_handlers.cpp +++ b/plugins/CmdLine/src/mimcmd_handlers.cpp @@ -1829,17 +1829,13 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r { if (_stricmp(argv[2], "list") == 0) { - HANDLE hContact = NULL; char buffer[1024]; char protocol[128]; - - hContact = db_find_first(); + int count = 0; reply->code = MIMRES_SUCCESS; - while (hContact) - { - + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { GetContactProto(hContact, protocol, sizeof(protocol)); char *contact = GetContactName(hContact, protocol); @@ -1869,8 +1865,6 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r free(contact); free(id); - - hContact = db_find_next(hContact); } } else{ @@ -1878,14 +1872,11 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r { if (argc > 3) { - HANDLE hContact = NULL; char protocol[128]; - hContact = db_find_first(); reply->code = MIMRES_SUCCESS; *reply->message = 0; - while (hContact) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { GetContactProto(hContact, protocol, sizeof(protocol)); char *contact = GetContactName(hContact, protocol); @@ -1898,42 +1889,26 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r free(contact); free(id); - - hContact = db_find_next(hContact); } } - else{ - if (argc == 3) - { - HANDLE hContact = NULL; - hContact = db_find_first(); - - reply->code = MIMRES_SUCCESS; - *reply->message = 0; - - while (hContact) { - HANDLE hUnreadEvent = db_event_firstUnread(hContact); - if (hUnreadEvent != NULL) { - DWORD threadID; - HANDLE thread = CreateThread(NULL, NULL, OpenMessageWindowThread, hContact, NULL, &threadID); - } + else if (argc == 3) { + reply->code = MIMRES_SUCCESS; + *reply->message = 0; - hContact = db_find_next(hContact); + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + HANDLE hUnreadEvent = db_event_firstUnread(hContact); + if (hUnreadEvent != NULL) { + DWORD threadID; + HANDLE thread = CreateThread(NULL, NULL, OpenMessageWindowThread, hContact, NULL, &threadID); } } - else { - HandleWrongParametersCount(command, reply); - } } + else HandleWrongParametersCount(command, reply); } - else{ - HandleUnknownParameter(command, argv[2], reply); - } + else HandleUnknownParameter(command, argv[2], reply); } } - else{ - HandleWrongParametersCount(command, reply); - } + else HandleWrongParametersCount(command, reply); } void AddHistoryEvent(DBEVENTINFO *dbEvent, char *contact, PReply reply) @@ -1996,8 +1971,7 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re reply->code = MIMRES_SUCCESS; mir_snprintf(reply->message, reply->cMessage, Translate("No unread messages found.")); - HANDLE hContact = db_find_first(); - while (hContact) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { HANDLE hEvent = db_event_firstUnread(hContact); if (hEvent != NULL) { count = 0; @@ -2024,18 +1998,13 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re free(contact); } - - hContact = db_find_next(hContact); } } - else{ + else { if (_stricmp(cmd, "show") == 0) - { HandleWrongParametersCount(command, reply); - } - else{ + else HandleUnknownParameter(command, cmd, reply); - } } break; diff --git a/plugins/CmdLine/src/utils.cpp b/plugins/CmdLine/src/utils.cpp index 626141e68f..1dddb04310 100644 --- a/plugins/CmdLine/src/utils.cpp +++ b/plugins/CmdLine/src/utils.cpp @@ -337,32 +337,27 @@ TCHAR *GetContactID(HANDLE hContact, char *szProto) #pragma warning (disable: 4312) HANDLE GetContactFromID(TCHAR *szID, char *szProto) { - HANDLE hContact = db_find_first(); - TCHAR *szHandle; TCHAR dispName[1024]; char cProtocol[256]; char *tmp; int found = 0; - while (hContact) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { GetContactProto(hContact, cProtocol, sizeof(cProtocol)); - szHandle = GetContactID(hContact, cProtocol); + TCHAR *szHandle = GetContactID(hContact, cProtocol); tmp = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, 0); STRNCPY(dispName, tmp, sizeof(dispName)); if ((szHandle) && ((_tcsicmp(szHandle, szID) == 0) || (_tcsicmp(dispName, szID) == 0)) && ((szProto == NULL) || (_stricmp(szProto, cProtocol) == 0))) - { found = 1; - } - if (szHandle) { free(szHandle); } + + if (szHandle) free(szHandle); - if (found) { break; } - hContact = db_find_next(hContact); + if (found) return hContact; } - return hContact; + return NULL; } #pragma warning (default: 4312) -- cgit v1.2.3