From 9395431a6fe57538cb6e7d9900a37e8d737bc80e Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 5 Apr 2010 19:07:46 +0300 Subject: dos2unix string termination --- utilities.cpp | 330 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 165 insertions(+), 165 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 4910b00..d935cae 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1,165 +1,165 @@ -#include "headers.h" - -tstring DBGetContactSettingStringPAN(HANDLE hContact, char const * szModule, char const * szSetting, tstring errorValue) -{ - DBVARIANT dbv; - //if(DBGetContactSetting(hContact, szModule, szSetting, &dbv)) - if(DBGetContactSettingTString(hContact, szModule, szSetting, &dbv)) - return errorValue; -// if(DBVT_TCHAR == dbv.type ) - errorValue = dbv.ptszVal; - DBFreeVariant(&dbv); - return errorValue; -} - -std::string DBGetContactSettingStringPAN_A(HANDLE hContact, char const * szModule, char const * szSetting, std::string errorValue) -{ - DBVARIANT dbv; - //if(DBGetContactSetting(hContact, szModule, szSetting, &dbv)) - if(DBGetContactSettingString(hContact, szModule, szSetting, &dbv)) - return errorValue; -// if(DBVT_ASCIIZ == dbv.type ) - errorValue = dbv.pszVal; - DBFreeVariant(&dbv); - return errorValue; -} - -tstring &GetDlgItemString(HWND hwnd, int id) -{ - HWND h = GetDlgItem(hwnd, id); - int len = GetWindowTextLength(h); - TCHAR * buf = new TCHAR[len + 1]; - GetWindowText(h, buf, len + 1); - static tstring s; - s = buf; - delete []buf; - return s; -} - -std::string &GetProtoList() -{ - static std::string s; - return s = DBGetContactSettingStringPAN_A(NULL, pluginName, "protoList", "ICQ\r\n"); -} - - -bool ProtoInList(std::string proto) -{ - return std::string::npos != GetProtoList().find(proto + "\r\n"); -} - -int CreateCListGroup(TCHAR* szGroupName) -{ - int hGroup; - CLIST_INTERFACE *clint = NULL; - - if (ServiceExists(MS_CLIST_RETRIEVE_INTERFACE)) - clint = (CLIST_INTERFACE*)CallService(MS_CLIST_RETRIEVE_INTERFACE, 0, 0); - - hGroup = CallService(MS_CLIST_GROUPCREATE, 0, 0); - - TCHAR* usTmp = szGroupName; - - clint->pfnRenameGroup(hGroup, usTmp); - - return hGroup; -} - - -void RemoveExcludedUsers() -{ - HANDLE hContact; - HANDLE ToRemove[4096]; - int i = 0,a = 0; - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); - if(hContact) - { - do - { - if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) && DBGetContactSettingByte(hContact, pluginName, "Excluded", 0)) - { - ToRemove[i] = hContact; - i++; - } - } - while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact, 0)); - ToRemove[i] = INVALID_HANDLE_VALUE; - while(ToRemove[a] != INVALID_HANDLE_VALUE) - { - CallService(MS_DB_CONTACT_DELETE, (WPARAM)ToRemove[a], 0); - a++; - } - } -} - -void RemoveTemporaryUsers() -{ - HANDLE hContact; - HANDLE ToRemove[4096]; - int i = 0, a= 0; - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); - if(hContact) - { - do - { - if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)) - { - ToRemove[i] = hContact; - i++; - } - } - while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact, 0)); - ToRemove[i] = INVALID_HANDLE_VALUE; - while(ToRemove[a] != INVALID_HANDLE_VALUE) - { - CallService(MS_DB_CONTACT_DELETE, (WPARAM)ToRemove[a], 0); - a++; - } - } -} -int RemoveTmp(WPARAM,LPARAM) -{ - RemoveTemporaryUsers(); - return 0; -} -tstring variables_parse(tstring const &tstrFormat, HANDLE hContact){ - if (gbVarsServiceExist) { - FORMATINFO fi; - TCHAR *tszParsed; - tstring tstrResult; - - ZeroMemory(&fi, sizeof(fi)); - fi.cbSize = sizeof(fi); - fi.tszFormat = _tcsdup(tstrFormat.c_str()); - fi.hContact = hContact; - fi.flags |= FIF_TCHAR; - tszParsed = (TCHAR *)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0); - free(fi.tszFormat); - if (tszParsed) { - tstrResult = tszParsed; - CallService(MS_VARS_FREEMEMORY, (WPARAM)tszParsed, 0); - return tstrResult; - } - } - return tstrFormat; -} - -// case-insensitive _tcsstr -//by nullbie as i remember... -#define NEWTSTR_MALLOC(A) (A==NULL)?NULL:_tcscpy((TCHAR*)malloc(sizeof(TCHAR)*(_tcslen(A)+1)),A) -const int Stricmp(const TCHAR *str, const TCHAR *substr) -{ - int i; - TCHAR *str_up = NEWTSTR_MALLOC(str); - TCHAR *substr_up = NEWTSTR_MALLOC(substr); - - CharUpperBuff(str_up, lstrlen(str_up)); - CharUpperBuff(substr_up, lstrlen(substr_up)); - - i = _tcscmp(str_up, substr_up); - - mir_free(str_up); - mir_free(substr_up); - - return i; -} +#include "headers.h" + +tstring DBGetContactSettingStringPAN(HANDLE hContact, char const * szModule, char const * szSetting, tstring errorValue) +{ + DBVARIANT dbv; + //if(DBGetContactSetting(hContact, szModule, szSetting, &dbv)) + if(DBGetContactSettingTString(hContact, szModule, szSetting, &dbv)) + return errorValue; +// if(DBVT_TCHAR == dbv.type ) + errorValue = dbv.ptszVal; + DBFreeVariant(&dbv); + return errorValue; +} + +std::string DBGetContactSettingStringPAN_A(HANDLE hContact, char const * szModule, char const * szSetting, std::string errorValue) +{ + DBVARIANT dbv; + //if(DBGetContactSetting(hContact, szModule, szSetting, &dbv)) + if(DBGetContactSettingString(hContact, szModule, szSetting, &dbv)) + return errorValue; +// if(DBVT_ASCIIZ == dbv.type ) + errorValue = dbv.pszVal; + DBFreeVariant(&dbv); + return errorValue; +} + +tstring &GetDlgItemString(HWND hwnd, int id) +{ + HWND h = GetDlgItem(hwnd, id); + int len = GetWindowTextLength(h); + TCHAR * buf = new TCHAR[len + 1]; + GetWindowText(h, buf, len + 1); + static tstring s; + s = buf; + delete []buf; + return s; +} + +std::string &GetProtoList() +{ + static std::string s; + return s = DBGetContactSettingStringPAN_A(NULL, pluginName, "protoList", "ICQ\r\n"); +} + + +bool ProtoInList(std::string proto) +{ + return std::string::npos != GetProtoList().find(proto + "\r\n"); +} + +int CreateCListGroup(TCHAR* szGroupName) +{ + int hGroup; + CLIST_INTERFACE *clint = NULL; + + if (ServiceExists(MS_CLIST_RETRIEVE_INTERFACE)) + clint = (CLIST_INTERFACE*)CallService(MS_CLIST_RETRIEVE_INTERFACE, 0, 0); + + hGroup = CallService(MS_CLIST_GROUPCREATE, 0, 0); + + TCHAR* usTmp = szGroupName; + + clint->pfnRenameGroup(hGroup, usTmp); + + return hGroup; +} + + +void RemoveExcludedUsers() +{ + HANDLE hContact; + HANDLE ToRemove[4096]; + int i = 0,a = 0; + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + if(hContact) + { + do + { + if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) && DBGetContactSettingByte(hContact, pluginName, "Excluded", 0)) + { + ToRemove[i] = hContact; + i++; + } + } + while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact, 0)); + ToRemove[i] = INVALID_HANDLE_VALUE; + while(ToRemove[a] != INVALID_HANDLE_VALUE) + { + CallService(MS_DB_CONTACT_DELETE, (WPARAM)ToRemove[a], 0); + a++; + } + } +} + +void RemoveTemporaryUsers() +{ + HANDLE hContact; + HANDLE ToRemove[4096]; + int i = 0, a= 0; + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + if(hContact) + { + do + { + if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)) + { + ToRemove[i] = hContact; + i++; + } + } + while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact, 0)); + ToRemove[i] = INVALID_HANDLE_VALUE; + while(ToRemove[a] != INVALID_HANDLE_VALUE) + { + CallService(MS_DB_CONTACT_DELETE, (WPARAM)ToRemove[a], 0); + a++; + } + } +} +int RemoveTmp(WPARAM,LPARAM) +{ + RemoveTemporaryUsers(); + return 0; +} +tstring variables_parse(tstring const &tstrFormat, HANDLE hContact){ + if (gbVarsServiceExist) { + FORMATINFO fi; + TCHAR *tszParsed; + tstring tstrResult; + + ZeroMemory(&fi, sizeof(fi)); + fi.cbSize = sizeof(fi); + fi.tszFormat = _tcsdup(tstrFormat.c_str()); + fi.hContact = hContact; + fi.flags |= FIF_TCHAR; + tszParsed = (TCHAR *)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0); + free(fi.tszFormat); + if (tszParsed) { + tstrResult = tszParsed; + CallService(MS_VARS_FREEMEMORY, (WPARAM)tszParsed, 0); + return tstrResult; + } + } + return tstrFormat; +} + +// case-insensitive _tcsstr +//by nullbie as i remember... +#define NEWTSTR_MALLOC(A) (A==NULL)?NULL:_tcscpy((TCHAR*)malloc(sizeof(TCHAR)*(_tcslen(A)+1)),A) +const int Stricmp(const TCHAR *str, const TCHAR *substr) +{ + int i; + TCHAR *str_up = NEWTSTR_MALLOC(str); + TCHAR *substr_up = NEWTSTR_MALLOC(substr); + + CharUpperBuff(str_up, lstrlen(str_up)); + CharUpperBuff(substr_up, lstrlen(substr_up)); + + i = _tcscmp(str_up, substr_up); + + mir_free(str_up); + mir_free(substr_up); + + return i; +} -- cgit v1.2.3