diff options
author | Mataes <mataes2007@gmail.com> | 2020-04-04 00:32:54 +0300 |
---|---|---|
committer | Mataes <mataes2007@gmail.com> | 2020-04-04 00:33:19 +0300 |
commit | 067cd1176e7b6e57107e3926ddaba3a7e7880949 (patch) | |
tree | ed7938060d19f8ffe18ba5ec674142a9a9a4b3df /plugins/NewStory | |
parent | 43a10fea91545df9128f0792d3b6cee78f4fd3ec (diff) |
newstory: change some function to mir_*. Maybe create memleaks
Diffstat (limited to 'plugins/NewStory')
-rw-r--r-- | plugins/NewStory/src/history.cpp | 10 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.cpp | 12 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 10 | ||||
-rw-r--r-- | plugins/NewStory/src/options.cpp | 16 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.cpp | 285 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.h | 24 | ||||
-rw-r--r-- | plugins/NewStory/src/utils.cpp | 16 |
7 files changed, 172 insertions, 201 deletions
diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index 79d0a7678a..905d61602c 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -570,9 +570,9 @@ INT_PTR CALLBACK HistoryDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara WindowList_Add(hNewstoryWindows, hwnd, data->hContact); if (data->hContact && (data->hContact != INVALID_CONTACT_ID)) { - TCHAR *title = TplFormatString(TPL_TITLE, data->hContact, 0); + wchar_t *title = TplFormatString(TPL_TITLE, data->hContact, 0); SetWindowText(hwnd, title); - free(title); + mir_free(title); } else { if (data->hContact == INVALID_CONTACT_ID) @@ -676,7 +676,7 @@ INT_PTR CALLBACK HistoryDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara case WM_CHARTOITEM: if (!((GetKeyState(VK_CONTROL) & 0x80) || (GetKeyState(VK_MENU) & 0x80))) { - TCHAR s[] = { LOWORD(wParam), 0 }; + wchar_t s[] = { LOWORD(wParam), 0 }; SetWindowText(GetDlgItem(hwnd, IDC_SEARCHTEXT), s); SendMessage(GetDlgItem(hwnd, IDC_SEARCHTEXT), EM_SETSEL, 1, 1); SetFocus(GetDlgItem(hwnd, IDC_SEARCHTEXT)); @@ -923,7 +923,7 @@ INT_PTR CALLBACK HistoryDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara case IDC_FINDPREV: { int bufSize = GetWindowTextLength(GetDlgItem(hwnd, IDC_SEARCHTEXT)) + 1; - TCHAR *buf = new TCHAR[bufSize]; + wchar_t *buf = new wchar_t[bufSize]; GetWindowText(GetDlgItem(hwnd, IDC_SEARCHTEXT), buf, GetWindowTextLength(GetDlgItem(hwnd, IDC_SEARCHTEXT)) + 1); SendMessage(GetDlgItem(hwnd, IDC_ITEMS2), NSM_FINDPREV, (WPARAM)buf, 0); delete[] buf; @@ -934,7 +934,7 @@ INT_PTR CALLBACK HistoryDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara case IDC_FINDNEXT: { int bufSize = GetWindowTextLength(GetDlgItem(hwnd, IDC_SEARCHTEXT)) + 1; - TCHAR *buf = new TCHAR[bufSize]; + wchar_t *buf = new wchar_t[bufSize]; GetWindowText(GetDlgItem(hwnd, IDC_SEARCHTEXT), buf, GetWindowTextLength(GetDlgItem(hwnd, IDC_SEARCHTEXT)) + 1); SendMessage(GetDlgItem(hwnd, IDC_ITEMS2), NSM_FINDNEXT, (WPARAM)buf, 0); delete[] buf; diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 9676fdb6e9..0d8c870c6c 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -17,7 +17,7 @@ bool HistoryArray::ItemData::load(EventLoadMode mode) if ((mode == ELM_DATA) && (!dbeOk || !dbe.cbBlob)) { dbeOk = true; dbe.cbBlob = db_event_getBlobSize(hEvent); - dbe.pBlob = (PBYTE)calloc(dbe.cbBlob + 1, 1); + dbe.pBlob = (PBYTE)mir_calloc(dbe.cbBlob + 1); db_event_get(hEvent, &dbe); int aLength = 0; @@ -30,9 +30,9 @@ bool HistoryArray::ItemData::load(EventLoadMode mode) { atext = (char *)dbe.pBlob; atext_del = false; - aLength = lstrlenA(atext); + aLength = mir_strlen(atext); if (dbe.cbBlob > (DWORD)aLength + 1) { - wtext = (WCHAR *)(dbe.pBlob + aLength + 1); + wtext = (wchar_t *)(dbe.pBlob + aLength + 1); wtext_del = false; } break; @@ -48,7 +48,7 @@ bool HistoryArray::ItemData::load(EventLoadMode mode) else { mir_snprintf(atext, 512, ("%d requested authorization"), *(DWORD *)(dbe.pBlob)); } - aLength = lstrlenA(atext); + aLength = mir_strlen(atext); break; } @@ -62,7 +62,7 @@ bool HistoryArray::ItemData::load(EventLoadMode mode) else { mir_snprintf(atext, 512, ("%d added you to the contact list"), *(DWORD *)(dbe.pBlob)); } - aLength = lstrlenA(atext); + aLength = mir_strlen(atext); break; } } @@ -99,7 +99,7 @@ bool HistoryArray::ItemData::load(EventLoadMode mode) HistoryArray::ItemData::~ItemData() { if (dbeOk && dbe.pBlob) { - free(dbe.pBlob); + mir_free(dbe.pBlob); dbe.pBlob = 0; } if (wtext && wtext_del) delete[] wtext; diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 2d31fd9023..7b718e0421 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -261,12 +261,12 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM if (item->flags & HIF_SELECTED) { buf = TplFormatString(TPL_COPY_MESSAGE, item->hContact, item); res = appendString(res, buf); - free(buf); + mir_free(buf); } } CopyText(hwnd, res); - free(res); + mir_free(res); } // End of history list control messages case WM_SIZE: @@ -725,7 +725,7 @@ static void BeginEditItem(HWND hwnd, NewstoryListData *data, int index) SendMessage(data->hwndEditBox, EM_SETSEL, 0, (LPARAM)(-1)); ShowWindow(data->hwndEditBox, SW_SHOW); SetFocus(data->hwndEditBox); - free(text); + mir_free(text); break; } top += itemHeight; @@ -787,7 +787,7 @@ static int LayoutItem(HWND hwnd, HistoryArray *items, int index) if (!item->data) { TCHAR *buf = TplFormatString(tpl, item->hContact, item); item->data = MTextCreateW(htuLog, buf); - free(buf); + mir_free(buf); } SIZE sz; @@ -863,7 +863,7 @@ static int PaintItem(HDC hdc, HistoryArray *items, int index, int top, int width if (!item->data) { TCHAR *buf = TplFormatString(tpl, item->hContact, item); item->data = MTextCreateW(htuLog, buf); - free(buf); + mir_free(buf); if (!item->data) return 0; } diff --git a/plugins/NewStory/src/options.cpp b/plugins/NewStory/src/options.cpp index 2ec3b1ddd7..d534fbc4ab 100644 --- a/plugins/NewStory/src/options.cpp +++ b/plugins/NewStory/src/options.cpp @@ -75,10 +75,10 @@ static INT_PTR CALLBACK OptTemplatesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, case IDC_UPDATEPREVIEW: if (templates[CurrentTemplate].tmpValue) - free(templates[CurrentTemplate].tmpValue); + mir_free(templates[CurrentTemplate].tmpValue); { int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDITTEMPLATE)) + 1; - templates[CurrentTemplate].tmpValue = (TCHAR *)malloc(length * sizeof(TCHAR)); + templates[CurrentTemplate].tmpValue = (TCHAR *)mir_alloc(length * sizeof(TCHAR)); GetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[CurrentTemplate].tmpValue, length); HistoryArray::ItemData item; @@ -95,7 +95,7 @@ static INT_PTR CALLBACK OptTemplatesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, SetWindowText(GetDlgItem(hwnd, IDC_PREVIEW), preview); // SetWindowText(GetDlgItem(hwnd, IDC_GPREVIEW), preview); SetWindowText(GetDlgItem(hwnd, IDC_GPREVIEW), _T("$hit :)")); - free(preview); + mir_free(preview); } else { SetWindowText(GetDlgItem(hwnd, IDC_PREVIEW), _T("")); @@ -106,7 +106,7 @@ static INT_PTR CALLBACK OptTemplatesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, case IDC_DISCARD: if (templates[CurrentTemplate].tmpValue) - free(templates[CurrentTemplate].tmpValue); + mir_free(templates[CurrentTemplate].tmpValue); templates[CurrentTemplate].tmpValue = 0; if (templates[CurrentTemplate].value) SetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[CurrentTemplate].value); @@ -126,7 +126,7 @@ static INT_PTR CALLBACK OptTemplatesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, for (int i = 0; i < TPL_COUNT; i++) { if (templates[i].tmpValue) { if (templates[i].tmpValue) - free(templates[i].tmpValue); + mir_free(templates[i].tmpValue); } } return TRUE; @@ -135,7 +135,7 @@ static INT_PTR CALLBACK OptTemplatesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, for (int i = 0; i < TPL_COUNT; i++) { if (templates[i].tmpValue) { if (templates[i].value) - free(templates[i].value); + mir_free(templates[i].value); templates[i].value = templates[i].tmpValue; templates[i].tmpValue = 0; } @@ -183,9 +183,9 @@ static INT_PTR CALLBACK OptTemplatesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, if ((lpnmtv->itemOld.mask & TVIF_HANDLE) && lpnmtv->itemOld.hItem && (lpnmtv->itemOld.hItem != lpnmtv->itemNew.hItem) && (lpnmtv->itemOld.lParam >= 0) && (lpnmtv->itemOld.lParam < TPL_COUNT)) { if (templates[lpnmtv->itemOld.lParam].tmpValue) - free(templates[lpnmtv->itemOld.lParam].tmpValue); + mir_free(templates[lpnmtv->itemOld.lParam].tmpValue); int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDITTEMPLATE)) + 1; - templates[lpnmtv->itemOld.lParam].tmpValue = (TCHAR *)malloc(length * sizeof(TCHAR)); + templates[lpnmtv->itemOld.lParam].tmpValue = (TCHAR *)mir_alloc(length * sizeof(TCHAR)); GetWindowText(GetDlgItem(hwnd, IDC_EDITTEMPLATE), templates[lpnmtv->itemOld.lParam].tmpValue, length); } diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index 2c5ef19d76..abe7e34913 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -1,77 +1,77 @@ #include "stdafx.h" -void TplInitVars(TemplateVars *vars); -void TplCleanVars(TemplateVars *vars); -__forceinline TCHAR *TplGetVar(TemplateVars *vars, char id); -__forceinline void TplSetVar(TemplateVars *vars, char id, TCHAR *v, bool d); -int TplMeasureVars(TemplateVars *vars, TCHAR *str); - -void vfGlobal(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfContact(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfSystem(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfEvent(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfMessage(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfFile(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfUrl(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfSign(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfAuth(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfAdded(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfDeleted(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); -void vfOther(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); +void TplInitVars(TemplateVars* vars); +void TplCleanVars(TemplateVars* vars); +__forceinline wchar_t* TplGetVar(TemplateVars* vars, char id); +__forceinline void TplSetVar(TemplateVars* vars, char id, wchar_t* v, bool d); +int TplMeasureVars(TemplateVars* vars, wchar_t* str); + +void vfGlobal(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfContact(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfSystem(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfEvent(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfMessage(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfFile(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfUrl(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfSign(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfAuth(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfAdded(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfDeleted(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); +void vfOther(int mode, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData* item); TemplateInfo templates[TPL_COUNT] = { - { "tpl/interface/title", _T("Interface"), ICO_NEWSTORY, _T("Window Title"), - _T("%N's Newstory [%c messages total]"), 0, 0, + { "tpl/interface/title", L"Interface", ICO_NEWSTORY, L"Window Title", + L"%N's Newstory [%c messages total]", 0, 0, { vfGlobal, vfContact, 0, 0, 0 } }, - { "tpl/msglog/msg", _T("Message Log"), ICO_SENDMSG, _T("Messages"), - _T("%I%i[b]%N, %t:[/b]\x0d\x0a%M"), 0, 0, + { "tpl/msglog/msg", L"Message Log", ICO_SENDMSG, L"Messages", + L"%I%i[b]%N, %t:[/b]\x0d\x0a%M", 0, 0, { vfGlobal, vfContact, vfEvent, vfMessage, 0 } }, - { "tpl/msglog/file", _T("Message Log"), ICO_FILE, _T("Files"), - _T("%I%i[b]%N, %t:[/b]%n%M"), 0, 0, + { "tpl/msglog/file", L"Message Log", ICO_FILE, L"Files", + L"%I%i[b]%N, %t:[/b]%n%M", 0, 0, { vfGlobal, vfContact, vfEvent, vfFile, 0 } }, - { "tpl/msglog/status", _T("Message Log"), ICO_SIGNIN, _T("Status Changes"), - _T("%I%i[b]%N, %t:[/b]%n%M"), 0, 0, + { "tpl/msglog/status", L"Message Log", ICO_SIGNIN, L"Status Changes", + L"%I%i[b]%N, %t:[/b]%n%M", 0, 0, { vfGlobal, vfContact, vfEvent, vfSign, 0 } }, - { "tpl/msglog/other", _T("Message Log"), ICO_UNKNOWN, _T("Other Events"), - _T("%I%i[b]%N, %t:[/b]%n%M"), 0, 0, + { "tpl/msglog/other", L"Message Log", ICO_UNKNOWN, L"Other Events", + L"%I%i[b]%N, %t:[/b]%n%M", 0, 0, { vfGlobal, vfContact, vfEvent, vfOther, 0 } }, - { "tpl/msglog/authrq", _T("Message Log"), ICO_UNKNOWN, _T("Authorization Requests"), - _T("%I%i[b]%N, %t:[/b]%n%M"), 0, 0, + { "tpl/msglog/authrq", L"Message Log", ICO_UNKNOWN, L"Authorization Requests", + L"%I%i[b]%N, %t:[/b]%n%M", 0, 0, { vfGlobal, vfEvent, vfSystem, vfAuth, 0 } }, - { "tpl/msglog/added", _T("Message Log"), ICO_UNKNOWN, _T("'You were added' events"), - _T("%I%i[b]%N, %t:[/b]%n%M"), 0, 0, + { "tpl/msglog/added", L"Message Log", ICO_UNKNOWN, L"'You were added' events", + L"%I%i[b]%N, %t:[/b]%n%M", 0, 0, { vfGlobal, vfEvent, vfSystem, vfAdded, 0 } }, - { "tpl/msglog/deleted", _T("Message Log"), ICO_UNKNOWN, _T("'You were deleted' events"), - _T("%I%i[b]%N, %t:[/b]%n%M"), 0, 0, + { "tpl/msglog/deleted", L"Message Log", ICO_UNKNOWN, L"'You were deleted' events", + L"%I%i[b]%N, %t:[/b]%n%M", 0, 0, { vfGlobal, vfEvent, vfSystem, vfDeleted, 0 } }, - { "tpl/copy/msg", _T("Clipboard"), ICO_SENDMSG, _T("Messages"), - _T("%N, %t:\x0d\x0a%M%n"), 0, 0, + { "tpl/copy/msg", L"Clipboard", ICO_SENDMSG, L"Messages", + L"%N, %t:\x0d\x0a%M%n", 0, 0, { vfGlobal, vfContact, vfEvent, vfMessage, 0 } }, - { "tpl/copy/file", _T("Clipboard"), ICO_FILE, _T("Files"), - _T("%N, %t:\x0d\x0a%M%n"), 0, 0, + { "tpl/copy/file", L"Clipboard", ICO_FILE, L"Files", + L"%N, %t:\x0d\x0a%M%n", 0, 0, { vfGlobal, vfContact, vfEvent, vfFile, 0 } }, - { "tpl/copy/url", _T("Clipboard"), ICO_URL, _T("URLs"), - _T("%N, %t:\x0d\x0a%M%n"), 0, 0, + { "tpl/copy/url", L"Clipboard", ICO_URL, L"URLs", + L"%N, %t:\x0d\x0a%M%n", 0, 0, { vfGlobal, vfContact, vfEvent, vfUrl, 0 } }, - { "tpl/copy/status", _T("Clipboard"), ICO_SIGNIN, _T("Status Changes"), - _T("%N, %t:\x0d\x0a%M%n"), 0, 0, + { "tpl/copy/status", L"Clipboard", ICO_SIGNIN, L"Status Changes", + L"%N, %t:\x0d\x0a%M%n", 0, 0, { vfGlobal, vfContact, vfEvent, vfSign, 0 } }, - { "tpl/copy/other", _T("Clipboard"), ICO_UNKNOWN, _T("Other Events"), - _T("%N, %t:\x0d\x0a%M%n"), 0, 0, + { "tpl/copy/other", L"Clipboard", ICO_UNKNOWN, L"Other Events", + L"%N, %t:\x0d\x0a%M%n", 0, 0, { vfGlobal, vfContact, vfEvent, vfOther, 0 } }, - { "tpl/copy/authrq", _T("Clipboard"), ICO_UNKNOWN, _T("Authorization Requests"), - _T("%N, %t:\x0d\x0a%M%n"), 0, 0, + { "tpl/copy/authrq", L"Clipboard", ICO_UNKNOWN, L"Authorization Requests", + L"%N, %t:\x0d\x0a%M%n", 0, 0, { vfGlobal, vfEvent, vfSystem, vfAuth, 0 } }, - { "tpl/copy/added", _T("Clipboard"), ICO_UNKNOWN, _T("'You were added' events"), - _T("%N, %t:\x0d\x0a%M%n"), 0, 0, + { "tpl/copy/added", L"Clipboard", ICO_UNKNOWN, L"'You were added' events", + L"%N, %t:\x0d\x0a%M%n", 0, 0, { vfGlobal, vfEvent, vfSystem, vfAdded, 0 } }, - { "tpl/copy/deleted", _T("Clipboard"), ICO_UNKNOWN, _T("'You were deleted' events"), - _T("%N, %t:\x0d\x0a%M%n"), 0, 0, + { "tpl/copy/deleted", L"Clipboard", ICO_UNKNOWN, L"'You were deleted' events", + L"%N, %t:\x0d\x0a%M%n", 0, 0, { vfGlobal, vfEvent, vfSystem, vfDeleted, 0 } } }; @@ -81,9 +81,9 @@ void LoadTemplates() DBVARIANT dbv = { 0 }; db_get_ws(0, MODULENAME, templates[i].setting, &dbv); if (templates[i].value) - free(templates[i].value); + mir_free(templates[i].value); if (dbv.pwszVal) { - templates[i].value = _tcsdup(dbv.pwszVal); + templates[i].value = mir_wstrdup(dbv.pwszVal); } else { templates[i].value = 0; @@ -99,10 +99,10 @@ void SaveTemplates() db_set_ws(0, MODULENAME, templates[i].setting, templates[i].value); } -TCHAR *TplFormatStringEx(int tpl, TCHAR *sztpl, MCONTACT hContact, HistoryArray::ItemData *item) +wchar_t* TplFormatStringEx(int tpl, wchar_t* sztpl, MCONTACT hContact, HistoryArray::ItemData* item) { if ((tpl < 0) || (tpl >= TPL_COUNT) || !sztpl) - return _tcsdup(_T("")); + return mir_wstrdup(L""); int i; TemplateVars vars; @@ -110,19 +110,19 @@ TCHAR *TplFormatStringEx(int tpl, TCHAR *sztpl, MCONTACT hContact, HistoryArray: vars.del[i] = false; vars.val[i] = 0; } - + for (i = 0; i < TemplateInfo::VF_COUNT; i++) if (templates[tpl].vf[i]) templates[tpl].vf[i](VFM_VARS, &vars, hContact, item); - TCHAR *buf = (TCHAR *)malloc(sizeof(TCHAR)*(TplMeasureVars(&vars, sztpl) + 1)); - TCHAR *bufptr = buf; - for (TCHAR *p = sztpl; *p; p++) { + wchar_t* buf = (wchar_t*)mir_alloc(sizeof(wchar_t) * (TplMeasureVars(&vars, sztpl) + 1)); + wchar_t* bufptr = buf; + for (wchar_t* p = sztpl; *p; p++) { if (*p == '%') { - TCHAR *var = TplGetVar(&vars, (char)(p[1] & 0xff)); + wchar_t* var = TplGetVar(&vars, (char)(p[1] & 0xff)); if (var) { - lstrcpy(bufptr, var); - bufptr += lstrlen(var); + mir_wstrcpy(bufptr, var); + bufptr += mir_wstrlen(var); } p++; } @@ -132,13 +132,13 @@ TCHAR *TplFormatStringEx(int tpl, TCHAR *sztpl, MCONTACT hContact, HistoryArray: return buf; } -TCHAR *TplFormatString(int tpl, MCONTACT hContact, HistoryArray::ItemData *item) +wchar_t* TplFormatString(int tpl, MCONTACT hContact, HistoryArray::ItemData* item) { if ((tpl < 0) || (tpl >= TPL_COUNT)) - return _tcsdup(_T("")); + return mir_wstrdup(L""); if (!templates[tpl].value) - templates[tpl].value = _tcsdup(templates[tpl].defvalue); + templates[tpl].value = mir_wstrdup(templates[tpl].defvalue); int i; TemplateVars vars; @@ -151,14 +151,14 @@ TCHAR *TplFormatString(int tpl, MCONTACT hContact, HistoryArray::ItemData *item) if (templates[tpl].vf[i]) templates[tpl].vf[i](VFM_VARS, &vars, hContact, item); - TCHAR *buf = (TCHAR *)malloc(sizeof(TCHAR)*(TplMeasureVars(&vars, templates[tpl].value) + 1)); - TCHAR *bufptr = buf; - for (TCHAR *p = templates[tpl].value; *p; p++) { + wchar_t* buf = (wchar_t*)mir_alloc(sizeof(wchar_t) * (TplMeasureVars(&vars, templates[tpl].value) + 1)); + wchar_t* bufptr = buf; + for (wchar_t* p = templates[tpl].value; *p; p++) { if (*p == '%') { - TCHAR *var = TplGetVar(&vars, (char)(p[1] & 0xff)); + wchar_t* var = TplGetVar(&vars, (char)(p[1] & 0xff)); if (var) { - lstrcpy(bufptr, var); - bufptr += lstrlen(var); + mir_wstrcpy(bufptr, var); + bufptr += mir_wstrlen(var); } p++; } @@ -169,7 +169,7 @@ TCHAR *TplFormatString(int tpl, MCONTACT hContact, HistoryArray::ItemData *item) } // Variable management -void TplInitVars(TemplateVars *vars) +void TplInitVars(TemplateVars* vars) { for (int i = 0; i < 256; i++) { vars->val[i] = 0; @@ -177,36 +177,36 @@ void TplInitVars(TemplateVars *vars) } } -void TplCleanVars(TemplateVars *vars) +void TplCleanVars(TemplateVars* vars) { for (int i = 0; i < 256; i++) if (vars->val[i] && vars->del[i]) { - free(vars->val[i]); + mir_free(vars->val[i]); vars->val[i] = 0; vars->del[i] = false; } } -__forceinline TCHAR *TplGetVar(TemplateVars *vars, char id) +__forceinline wchar_t* TplGetVar(TemplateVars* vars, char id) { return vars->val[id]; } -__forceinline void TplSetVar(TemplateVars *vars, char id, TCHAR *v, bool d) +__forceinline void TplSetVar(TemplateVars* vars, char id, wchar_t* v, bool d) { if (vars->val[id] && vars->del[id]) - free(vars->val[id]); - vars->val[id] = v; + mir_free(vars->val[id]); + vars->val[id] = mir_wstrdup(v); vars->del[id] = d; } -int TplMeasureVars(TemplateVars *vars, TCHAR *str) +int TplMeasureVars(TemplateVars* vars, wchar_t* str) { int res = 0; - for (TCHAR *p = str; *p; p++) { + for (wchar_t* p = str; *p; p++) { if (*p == '%') { - TCHAR *var = TplGetVar(vars, (char)(p[1] & 0xff)); - if (var) res += lstrlen(var); + wchar_t* var = TplGetVar(vars, (char)(p[1] & 0xff)); + if (var) res += mir_wstrlen(var); p++; } else res++; @@ -215,57 +215,59 @@ int TplMeasureVars(TemplateVars *vars, TCHAR *str) } // Loading variables -void vfGlobal(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData*) +void vfGlobal(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData*) { // %%: simply % character - TplSetVar(vars, '%', _T("%"), false); + TplSetVar(vars, '%', L"%", false); // %n: line break - TplSetVar(vars, 'n', _T("\x0d\x0a"), false); + TplSetVar(vars, 'n', L"\x0d\x0a", false); // %M: my nick (not for messages) - wchar_t *buf = Clist_GetContactDisplayName(0, 0); + //todo: not working now + wchar_t* buf = Clist_GetContactDisplayName(0, 0); TplSetVar(vars, 'M', buf, false); } -void vfContact(int, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData*) +void vfContact(int, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData*) { // %N: buddy's nick (not for messages) - wchar_t *buff = Clist_GetContactDisplayName(hContact, 0); - TplSetVar(vars, 'N', buff, false); + wchar_t* nick = Clist_GetContactDisplayName(hContact, 0); + TplSetVar(vars, 'N', nick, false); + wchar_t buf[20]; // %c: event count - TCHAR *buf = new TCHAR[20]; - wsprintf(buf, _T("%d"), db_event_count(hContact)); + mir_snwprintf(buf, L"%d", db_event_count(hContact)); TplSetVar(vars, 'c', buf, false); } -void vfSystem(int, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData*) +void vfSystem(int, TemplateVars* vars, MCONTACT hContact, HistoryArray::ItemData*) { // %N: buddy's nick (not for messages) - TplSetVar(vars, 'N', /*TranslateTS*/_T("System Event"), false); + TplSetVar(vars, 'N', L"System Event", false); // %c: event count - TCHAR *buf = new TCHAR[20]; - wsprintf(buf, _T("%d"), db_event_count(hContact)); + wchar_t buf[20]; + mir_snwprintf(buf, L"%d", db_event_count(hContact)); TplSetVar(vars, 'c', buf, false); } -void vfEvent(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) +void vfEvent(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData* item) { HICON hIcon; - TCHAR *s; - wchar_t* nick; - - // %U: UIN (contextual, own uin for sent, buddys UIN for received messages) + wchar_t buf[100]; // %N: Nickname if (item->dbe.flags & DBEF_SENT) { char* proto = Proto_GetBaseAccountName(item->hContact); - nick = Contact_GetInfo(CNF_DISPLAY, 0, proto); - } else - nick = Clist_GetContactDisplayName(item->hContact, 0); - TplSetVar(vars, 'N', nick, false); + ptrW nick(Contact_GetInfo(CNF_DISPLAY, 0, proto)); + TplSetVar(vars, 'N', nick, false); + } + else { + wchar_t* nick = Clist_GetContactDisplayName(item->hContact, 0); + TplSetVar(vars, 'N', nick, false); + } + // %I: Icon switch (item->dbe.eventType) { @@ -282,9 +284,8 @@ void vfEvent(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) hIcon = g_plugin.getIcon(ICO_UNKNOWN); break; } - s = (TCHAR *)calloc(64, sizeof(TCHAR)); - wsprintf(s, _T("[$hicon=%d$]"), hIcon); - TplSetVar(vars, 'I', s, true); + mir_snwprintf(buf, L"[$hicon=%d$]", hIcon); + TplSetVar(vars, 'I', buf, true); // %i: Direction icon if (item->dbe.flags & DBEF_SENT) @@ -292,128 +293,104 @@ void vfEvent(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) else hIcon = g_plugin.getIcon(ICO_MSGIN); - s = (TCHAR *)calloc(64, sizeof(TCHAR)); - wsprintf(s, _T("[$hicon=%d$]"), hIcon); - TplSetVar(vars, 'i', s, true); + mir_snwprintf(buf, L"[$hicon=%d$]", hIcon); + TplSetVar(vars, 'i', buf, true); // %D: direction symbol if (item->dbe.flags & DBEF_SENT) - TplSetVar(vars, 'D', _T("<<"), false); + TplSetVar(vars, 'D', L"<<", false); else - TplSetVar(vars, 'D', _T(">>"), false); + TplSetVar(vars, 'D', L">>", false); // %t: timestamp - TCHAR *buf = (TCHAR *)calloc(100, sizeof(TCHAR)); - _tcsftime(buf, 100, _T("%d.%m.%Y, %H:%M"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%d.%m.%Y, %H:%M", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 't', buf, true); - // DBTIMETOSTRING tts; - // tts.cbDest = 100; - // tts.szFormat = "d, t"; - // tts.szDest = (char *)calloc(100, 1); - // CallService(MS_DB_TIME_TIMESTAMPTOSTRING, item->dbe.timestamp, (LPARAM)&tts); - // TplSetVar(vars, 't', tts.szDest, true); - - // tts.szFormat = ""; - // tts.szDest = (char *)calloc(100, 1); - // CallService(MS_DB_TIME_TIMESTAMPTOSTRING, item->dbe.timestamp, (LPARAM)&tts); - // TplSetVar(vars, 't', tts.szDest, true); - // %h: hour (24 hour format, 0-23) - buf = (TCHAR *)calloc(5, sizeof(TCHAR)); - _tcsftime(buf, 5, _T("%H"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%H", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 'h', buf, true); // %a: hour (12 hour format) - buf = (TCHAR *)calloc(5, sizeof(TCHAR)); - _tcsftime(buf, 5, _T("%h"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%h", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 'a', buf, true); // %m: minute - buf = (TCHAR *)calloc(5, sizeof(TCHAR)); - _tcsftime(buf, 5, _T("%M"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%M", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 'm', buf, true); // %s: second - buf = (TCHAR *)calloc(5, sizeof(TCHAR)); - _tcsftime(buf, 5, _T("%S"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%S", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 's', buf, true); // %o: month - buf = (TCHAR *)calloc(5, sizeof(TCHAR)); - _tcsftime(buf, 5, _T("%m"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%m", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 'o', buf, true); // %d: day of month - buf = (TCHAR *)calloc(5, sizeof(TCHAR)); - _tcsftime(buf, 5, _T("%d"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%d", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 'd', buf, true); // %y: year - buf = (TCHAR *)calloc(5, sizeof(TCHAR)); - _tcsftime(buf, 5, _T("%Y"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%Y", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 'y', buf, true); // %w: day of week (Sunday, Monday.. translateable) - buf = (TCHAR *)calloc(25, sizeof(TCHAR)); - _tcsftime(buf, 25, _T("%A"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%A", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 'w', TranslateW(buf), false); // %p: AM/PM symbol - buf = (TCHAR *)calloc(5, sizeof(TCHAR)); - _tcsftime(buf, 5, _T("%p"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%p", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 'p', buf, true); // %O: Name of month, translateable - buf = (TCHAR *)calloc(25, sizeof(TCHAR)); - _tcsftime(buf, 25, _T("%B"), _localtime32((__time32_t*)&item->dbe.timestamp)); + _tcsftime(buf, _countof(buf), L"%B", _localtime32((__time32_t*)&item->dbe.timestamp)); TplSetVar(vars, 'O', TranslateW(buf), false); } -void vfMessage(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) +void vfMessage(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData* item) { // %M: the message string itself TplSetVar(vars, 'M', item->getTBuf(), false); } -void vfFile(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) +void vfFile(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData* item) { // %M: the message string itself TplSetVar(vars, 'M', item->getTBuf(), false); } -void vfUrl(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) +void vfUrl(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData* item) { // %M: the message string itself TplSetVar(vars, 'M', item->getTBuf(), false); } -void vfSign(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) +void vfSign(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData* item) { // %M: the message string itself TplSetVar(vars, 'M', item->getTBuf(), false); } -void vfAuth(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) +void vfAuth(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData* item) { // %M: the message string itself TplSetVar(vars, 'M', item->getTBuf(), false); } -void vfAdded(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) +void vfAdded(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData* item) { // %M: the message string itself TplSetVar(vars, 'M', item->getTBuf(), false); } -void vfDeleted(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData *item) +void vfDeleted(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData* item) { // %M: the message string itself TplSetVar(vars, 'M', item->getTBuf(), false); } -void vfOther(int, TemplateVars *vars, MCONTACT, HistoryArray::ItemData*) +void vfOther(int, TemplateVars* vars, MCONTACT, HistoryArray::ItemData*) { // %M: the message string itself - TplSetVar(vars, 'M', _T("Unknown Event"), false); + TplSetVar(vars, 'M', L"Unknown Event", false); } diff --git a/plugins/NewStory/src/templates.h b/plugins/NewStory/src/templates.h index 8ac3cf7b07..71c41c5539 100644 --- a/plugins/NewStory/src/templates.h +++ b/plugins/NewStory/src/templates.h @@ -10,15 +10,9 @@ enum struct TemplateVars { bool del[256]; - TCHAR *val[256]; + wchar_t *val[256]; }; -/* -struct VFArgs -{ - HANDLE hContact; - DBEVENTINFO *event; -}; -*/ + typedef void(*VarFunc)(int mode, TemplateVars *vars, MCONTACT hContact, HistoryArray::ItemData *item); struct TemplateInfo @@ -26,12 +20,12 @@ struct TemplateInfo enum { VF_COUNT = 5 }; char *setting; - TCHAR *group; + wchar_t *group; int icon; - TCHAR *title; - TCHAR *defvalue; - TCHAR *value; - TCHAR *tmpValue; + wchar_t *title; + wchar_t *defvalue; + wchar_t *value; + wchar_t *tmpValue; VarFunc vf[VF_COUNT]; }; @@ -66,7 +60,7 @@ extern TemplateInfo templates[TPL_COUNT]; void LoadTemplates(); void SaveTemplates(); -TCHAR *TplFormatString(int tpl, MCONTACT hContact, HistoryArray::ItemData *args); -TCHAR *TplFormatStringEx(int tpl, TCHAR *sztpl, MCONTACT hContact, HistoryArray::ItemData *args); +wchar_t *TplFormatString(int tpl, MCONTACT hContact, HistoryArray::ItemData *args); +wchar_t *TplFormatStringEx(int tpl, wchar_t *sztpl, MCONTACT hContact, HistoryArray::ItemData *args); #endif // __templates_h__
\ No newline at end of file diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp index 6a875d1081..9e125ceeee 100644 --- a/plugins/NewStory/src/utils.cpp +++ b/plugins/NewStory/src/utils.cpp @@ -210,13 +210,13 @@ char *appendString(char *s1, char *s2) if (s1) { int l1 = lstrlenA(s1); int l2 = lstrlenA(s2); - char *buf = (char *)malloc(l1 + l2 + 1); - _snprintf(buf, l1 + l2 + 1, "%s%s", s1, s2); - free(s1); + char *buf = (char *)mir_alloc(l1 + l2 + 1); + mir_snprintf(buf, l1 + l2 + 1, "%s%s", s1, s2); + mir_free(s1); return buf; } else { - char *buf = (char *)malloc(lstrlenA(s2) + 1); + char *buf = (char *)mir_alloc(lstrlenA(s2) + 1); lstrcpyA(buf, s2); return buf; } @@ -227,13 +227,13 @@ WCHAR *appendString(WCHAR *s1, WCHAR *s2) if (s1) { int l1 = lstrlenW(s1); int l2 = lstrlenW(s2); - WCHAR *buf = (WCHAR *)malloc(sizeof(WCHAR)*(l1 + l2 + 1)); - _snwprintf(buf, l1 + l2 + 1, L"%s%s", s1, s2); - free(s1); + WCHAR *buf = (WCHAR *)mir_alloc(sizeof(WCHAR)*(l1 + l2 + 1)); + mir_snwprintf(buf, l1 + l2 + 1, L"%s%s", s1, s2); + mir_free(s1); return buf; } else { - WCHAR *buf = (WCHAR *)malloc(sizeof(WCHAR)*(lstrlenW(s2) + 1)); + WCHAR *buf = (WCHAR *)mir_alloc(sizeof(WCHAR)*(lstrlenW(s2) + 1)); lstrcpyW(buf, s2); return buf; } |