From 5e0c012d677635e13cbfcf6730f2deafdc38c025 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 3 Jan 2014 15:57:52 +0000 Subject: - memory leak fixes - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@7479 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Variables/src/contact.cpp | 5 +- plugins/Variables/src/contact.h | 2 +- plugins/Variables/src/enumprocs.cpp | 2 +- plugins/Variables/src/enumprocs.h | 2 +- plugins/Variables/src/help.cpp | 702 +++++++++++++-------------- plugins/Variables/src/parse_alias.cpp | 78 ++- plugins/Variables/src/parse_alias.h | 2 +- plugins/Variables/src/parse_external.cpp | 18 +- plugins/Variables/src/parse_external.h | 2 +- plugins/Variables/src/parse_inet.cpp | 34 +- plugins/Variables/src/parse_inet.h | 2 +- plugins/Variables/src/parse_logic.cpp | 79 +-- plugins/Variables/src/parse_logic.h | 2 +- plugins/Variables/src/parse_math.cpp | 34 +- plugins/Variables/src/parse_math.h | 2 +- plugins/Variables/src/parse_metacontacts.cpp | 38 +- plugins/Variables/src/parse_metacontacts.h | 2 +- plugins/Variables/src/parse_miranda.cpp | 152 +++--- plugins/Variables/src/parse_miranda.h | 2 +- plugins/Variables/src/parse_regexp.cpp | 16 +- plugins/Variables/src/parse_regexp.h | 2 +- plugins/Variables/src/parse_str.cpp | 257 +++++----- plugins/Variables/src/parse_str.h | 2 +- plugins/Variables/src/parse_system.cpp | 140 +++--- plugins/Variables/src/parse_system.h | 2 +- plugins/Variables/src/parse_variables.cpp | 147 +++--- plugins/Variables/src/parse_variables.h | 2 +- plugins/Variables/src/tokenregister.cpp | 271 +++++------ plugins/Variables/src/variables.h | 4 +- 29 files changed, 937 insertions(+), 1066 deletions(-) (limited to 'plugins/Variables') diff --git a/plugins/Variables/src/contact.cpp b/plugins/Variables/src/contact.cpp index bc9340ee16..b4d3a2de8c 100644 --- a/plugins/Variables/src/contact.cpp +++ b/plugins/Variables/src/contact.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -431,8 +431,7 @@ HANDLE *decodeContactFromString(TCHAR *tszContact) ci.flags = CI_PROTOID|CI_TCHAR; int count = getContactFromString( &ci ); if (count != 1) { - if (ci.hContacts != NULL) - mir_free(ci.hContacts); + mir_free(ci.hContacts); return (HANDLE*)hContact; } diff --git a/plugins/Variables/src/contact.h b/plugins/Variables/src/contact.h index 3a9b456d27..3c203baba4 100644 --- a/plugins/Variables/src/contact.h +++ b/plugins/Variables/src/contact.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/enumprocs.cpp b/plugins/Variables/src/enumprocs.cpp index dc8fabdec4..7ae68ed978 100644 --- a/plugins/Variables/src/enumprocs.cpp +++ b/plugins/Variables/src/enumprocs.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/enumprocs.h b/plugins/Variables/src/enumprocs.h index 78374a02a6..ceb7c461c3 100644 --- a/plugins/Variables/src/enumprocs.h +++ b/plugins/Variables/src/enumprocs.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/help.cpp b/plugins/Variables/src/help.cpp index f1463c9c78..b2ec3dae58 100644 --- a/plugins/Variables/src/help.cpp +++ b/plugins/Variables/src/help.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -265,7 +265,6 @@ static TCHAR *getTokenCategory(TOKENREGISTEREX *tr) { res = mir_a2t(helpText); mir_free(helpText); return res; - } cur++; } @@ -345,200 +344,169 @@ static TCHAR *getTokenDescription(TOKENREGISTEREX *tr) mir_sntprintf(desc, len, _T("%c%s%s"), FUNC_CHAR, tr->tszTokenString, (tArgs!=NULL?tArgs:_T(""))); } - if (tArgs != NULL) - mir_free(tArgs); - - if (helpText != NULL) - mir_free(helpText); + mir_free(tArgs); + mir_free(helpText); return desc; } -static int CALLBACK compareTokenHelp(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { - - TOKENREGISTEREX *tr1, *tr2; - TCHAR *cat1, *cat2; - int res; - - res = 0; - tr1 = (TOKENREGISTEREX *)lParam1; - tr2 = (TOKENREGISTEREX *)lParam2; +static int CALLBACK compareTokenHelp(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) +{ + TOKENREGISTEREX *tr1 = (TOKENREGISTEREX *)lParam1; + TOKENREGISTEREX *tr2 = (TOKENREGISTEREX *)lParam2; if (tr1 == NULL || tr2 == NULL) return 0; - cat1 = getTokenCategory(tr1); - cat2 = getTokenCategory(tr2); - if (cat1 != NULL && cat2 != NULL) { - res = _tcscmp(cat1, cat2); - mir_free(cat1); - mir_free(cat2); - cat1 = cat2 = NULL; - if (res != 0) - return res; - - if (tr1->tszTokenString == NULL || tr2->tszTokenString == NULL) - return 0; - - return _tcscmp(tr1->tszTokenString, tr2->tszTokenString); - } + ptrT cat1(getTokenCategory(tr1)); + ptrT cat2(getTokenCategory(tr2)); + if (cat1 == NULL || cat2 == NULL) + return 0; - if (cat1 != NULL) - mir_free(cat1); + int res = _tcscmp(cat1, cat2); + if (res != 0) + return res; - if (cat2 != NULL) - mir_free(cat2); + if (tr1->tszTokenString == NULL || tr2->tszTokenString == NULL) + return 0; - return 0; + return _tcscmp(tr1->tszTokenString, tr2->tszTokenString); } -static BOOL CALLBACK processTokenListMessage(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) { - +static BOOL CALLBACK processTokenListMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ /* hwndDlg must be a child of the help dialog */ switch(msg) { - case WM_INITDIALOG: { - HELPDLGDATA *hdd; - TOKENREGISTEREX *tr; - HWND hList; - LVCOLUMN lvCol; - LVITEM lvItem; - TCHAR *tszTokenDesc, *tszHelpDesc, *last, *cat, *text; - int i; - - // token list things - hList = GetDlgItem(hwndDlg, IDC_TOKENLIST); - memset(&lvCol,0,sizeof(lvCol)); - lvCol.mask = LVCF_TEXT; - lvCol.pszText=TranslateT("Token"); - ListView_InsertColumn(hList, 0, &lvCol); - lvCol.pszText=TranslateT("Description"); - ListView_InsertColumn(hList, 1, &lvCol); - - hdd = (HELPDLGDATA *)GetWindowLongPtr(GetParent(hwndDlg), GWLP_USERDATA); - i = -1; - do { - i += 1; - tszHelpDesc = tszTokenDesc = NULL; - tr = getTokenRegister(i); - if ((tr == NULL) || (tr->tszTokenString == NULL)) { - continue; - } - else if (hdd != NULL) { - if (!_tcscmp(tr->tszTokenString, _T(SUBJECT))) { - if (hdd->vhs->flags&VHF_HIDESUBJECTTOKEN) { - continue; - } - else if (hdd->vhs->szSubjectDesc != NULL) { + case WM_INITDIALOG: + { + TOKENREGISTEREX *tr; + TCHAR *tszTokenDesc, *tszHelpDesc, *last, *cat, *text; - tszHelpDesc = mir_a2t(hdd->vhs->szSubjectDesc); + // token list things + HWND hList = GetDlgItem(hwndDlg, IDC_TOKENLIST); + LVCOLUMN lvCol = { 0 }; + lvCol.mask = LVCF_TEXT; + lvCol.pszText = TranslateT("Token"); + ListView_InsertColumn(hList, 0, &lvCol); + + lvCol.pszText = TranslateT("Description"); + ListView_InsertColumn(hList, 1, &lvCol); + + HELPDLGDATA *hdd = (HELPDLGDATA *)GetWindowLongPtr(GetParent(hwndDlg), GWLP_USERDATA); + int i = -1; + do { + i += 1; + tszHelpDesc = tszTokenDesc = NULL; + tr = getTokenRegister(i); + if ((tr == NULL) || (tr->tszTokenString == NULL)) + continue; + + else if (hdd != NULL) { + if (!_tcscmp(tr->tszTokenString, _T(SUBJECT))) { + if (hdd->vhs->flags&VHF_HIDESUBJECTTOKEN) + continue; + + if (hdd->vhs->szSubjectDesc != NULL) + tszHelpDesc = mir_a2t(hdd->vhs->szSubjectDesc); } - } - if (!_tcscmp(tr->tszTokenString, _T(MIR_EXTRATEXT))) { - if (hdd->vhs->flags&VHF_HIDEEXTRATEXTTOKEN) { - continue; - } - else if (hdd->vhs->szExtraTextDesc != NULL) { - - tszHelpDesc = mir_a2t(hdd->vhs->szExtraTextDesc); + if (!_tcscmp(tr->tszTokenString, _T(MIR_EXTRATEXT))) { + if (hdd->vhs->flags & VHF_HIDEEXTRATEXTTOKEN) + continue; + if (hdd->vhs->szExtraTextDesc != NULL) + tszHelpDesc = mir_a2t(hdd->vhs->szExtraTextDesc); } } - } - memset(&lvItem,0,sizeof(lvItem)); - lvItem.mask = LVIF_TEXT|LVIF_PARAM; - lvItem.iItem = ListView_GetItemCount(hList); - lvItem.iSubItem = 0; - lvItem.lParam = (LPARAM)tr; - tszTokenDesc = getTokenDescription(tr); - if (tszTokenDesc == NULL) { - continue; - } - lvItem.pszText = tszTokenDesc; - ListView_InsertItem(hList, &lvItem); - mir_free(tszTokenDesc); - lvItem.mask = LVIF_TEXT; - if (tszHelpDesc == NULL) { - tszHelpDesc = getHelpDescription(tr); - } - if (tszHelpDesc == NULL) { - tszHelpDesc = mir_tstrdup(_T("unknown")); - } - lvItem.iSubItem = 1; - lvItem.pszText = TranslateTS(tszHelpDesc); - ListView_SetItem(hList, &lvItem); - mir_free(tszHelpDesc); - } while (tr != NULL); - ListView_SetColumnWidth(hList, 0, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hList, 1, LVSCW_AUTOSIZE); - ListView_SortItems(hList, compareTokenHelp, 0); - last = text = NULL; - for (i=0;iidFrom == IDC_TOKENLIST) && (((NMHDR*)lParam)->code == NM_DBLCLK)) { HWND hwndInputDlg = (HWND)SendMessage(GetParent(hwndDlg), VARM_GETDIALOG, (WPARAM)VHF_INPUT, 0); - if (hwndInputDlg == NULL) { + if (hwndInputDlg == NULL) break; - } + HWND hList = GetDlgItem(hwndDlg, IDC_TOKENLIST); int item = ListView_GetNextItem(hList, -1, LVNI_SELECTED|LVNI_FOCUSED); - LVITEM lvItem; - ZeroMemory(&lvItem, sizeof(lvItem)); + LVITEM lvItem = { 0 }; lvItem.mask = LVIF_PARAM; - lvItem.iSubItem = 0; lvItem.iItem = item; - if (ListView_GetItem(hList, &lvItem) == FALSE) { + if (ListView_GetItem(hList, &lvItem) == FALSE) break; - } + TOKENREGISTER *tr = (TOKENREGISTER *)lvItem.lParam; - if (tr == NULL) { + if (tr == NULL) break; - } + size_t len = _tcslen(tr->tszTokenString) + 2; - if (len < 0) { + if (len < 0) break; - } + TCHAR *tokenString = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); - if (tokenString == NULL) { + if (tokenString == NULL) break; - } + ZeroMemory(tokenString, (len+1)*sizeof(TCHAR)); mir_sntprintf(tokenString, len + 1, _T("%c%s%c"), (tr->flags & TRF_FIELD) ? FIELD_CHAR : FUNC_CHAR, tr->tszTokenString, (tr->flags & TRF_FIELD) ? FIELD_CHAR : '('); SendDlgItemMessage(hwndInputDlg, IDC_TESTSTRING, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)tokenString); @@ -552,16 +520,16 @@ static BOOL CALLBACK processTokenListMessage(HWND hwndDlg,UINT msg,WPARAM wParam } // "token only" dialog proc -static INT_PTR CALLBACK tokenHelpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +static INT_PTR CALLBACK tokenHelpDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { processTokenListMessage(hwndDlg, msg, wParam, lParam); - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); break; case WM_SIZE: - if (!IsIconic( hwndDlg )) { + if (!IsIconic(hwndDlg)) { UTILRESIZEDIALOG urd = { 0 }; urd.cbSize = sizeof(urd); urd.hInstance = hInst; @@ -582,29 +550,28 @@ static INT_PTR CALLBACK tokenHelpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPA // from SRMM static LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { + RECT rc; + switch (msg) { case WM_NCHITTEST: return HTCLIENT; case WM_SETCURSOR: - { - RECT rc; GetClientRect(hwnd, &rc); //SetCursor(rc.right > rc.bottom ? hCurSplitNS : hCurSplitWE); if (rc.right > rc.bottom) SetCursor(hCurSplitNS); return TRUE; - } + case WM_LBUTTONDOWN: SetCapture(hwnd); return 0; case WM_MOUSEMOVE: if (GetCapture() == hwnd) { - RECT rc; GetClientRect(hwnd, &rc); - SendMessage(GetParent(hwnd), DM_SPLITTERMOVED, rc.right > rc.bottom ? (short) HIWORD(GetMessagePos()) + rc.bottom / 2 : (short) LOWORD(GetMessagePos()) + rc.right / 2, (LPARAM) hwnd); + SendMessage(GetParent(hwnd), DM_SPLITTERMOVED, rc.right > rc.bottom ? (short)HIWORD(GetMessagePos()) + rc.bottom / 2 : (short)LOWORD(GetMessagePos()) + rc.right / 2, (LPARAM)hwnd); } return 0; @@ -630,9 +597,9 @@ static int inputDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc { INPUTDLGDATA *dat = (INPUTDLGDATA *)lParam; - switch(urc->wId) { + switch (urc->wId) { case IDC_TOKENLIST: - return RD_ANCHORX_WIDTH|RD_ANCHORY_TOP; + return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP; case IDC_TESTSTRING: urc->rcItem.bottom -= dat->splitterPos - dat->originalSplitterPos; @@ -645,10 +612,10 @@ static int inputDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc case IDC_RESULT: urc->rcItem.top -= dat->splitterPos - dat->originalSplitterPos; - return RD_ANCHORX_WIDTH|RD_ANCHORY_BOTTOM; + return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; } - return RD_ANCHORX_LEFT|RD_ANCHORY_TOP; + return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; } static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) @@ -656,10 +623,10 @@ static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM static INPUTDLGDATA *dat = (INPUTDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); processTokenListMessage(hwndDlg, msg, wParam, lParam); - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); - dat = ( INPUTDLGDATA* )mir_alloc(sizeof(INPUTDLGDATA)); + dat = (INPUTDLGDATA*)mir_alloc(sizeof(INPUTDLGDATA)); ZeroMemory(dat, sizeof(INPUTDLGDATA)); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); // splitter things @@ -677,7 +644,7 @@ static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM dat->splitterPos = dat->originalSplitterPos; GetWindowRect(GetDlgItem(hwndDlg, IDC_SHOWHELP), &rc); - mir_subclassWindow( GetDlgItem(hwndDlg, IDC_SPLITTER), SplitterSubclassProc); + mir_subclassWindow(GetDlgItem(hwndDlg, IDC_SPLITTER), SplitterSubclassProc); GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rc); dat->minInputSize.x = rc.right - rc.left; @@ -695,23 +662,23 @@ static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM break; case DM_SPLITTERMOVED: - { - POINT pt; - RECT rc, rcTeststring, rcResult; - int oldSplitterY; - - if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SPLITTER)) { - GetClientRect(hwndDlg, &rc); - pt.x = 0; - pt.y = wParam; - ScreenToClient(hwndDlg, &pt); - oldSplitterY = dat->splitterPos; - dat->splitterPos = rc.bottom - pt.y + 223; - GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rcTeststring); - GetWindowRect(GetDlgItem(hwndDlg, IDC_RESULT), &rcResult); - if ((((rcTeststring.bottom - rcTeststring.top) - (dat->splitterPos - oldSplitterY)) < dat->minInputSize.y) || (((rcResult.bottom - rcResult.top) + (dat->splitterPos - oldSplitterY)) < dat->minResultSize.y)) - dat->splitterPos = oldSplitterY; - } } + { + POINT pt; + RECT rc, rcTeststring, rcResult; + int oldSplitterY; + + if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SPLITTER)) { + GetClientRect(hwndDlg, &rc); + pt.x = 0; + pt.y = wParam; + ScreenToClient(hwndDlg, &pt); + oldSplitterY = dat->splitterPos; + dat->splitterPos = rc.bottom - pt.y + 223; + GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rcTeststring); + GetWindowRect(GetDlgItem(hwndDlg, IDC_RESULT), &rcResult); + if ((((rcTeststring.bottom - rcTeststring.top) - (dat->splitterPos - oldSplitterY)) < dat->minInputSize.y) || (((rcResult.bottom - rcResult.top) + (dat->splitterPos - oldSplitterY)) < dat->minResultSize.y)) + dat->splitterPos = oldSplitterY; + } } SendMessage(hwndDlg, WM_SIZE, 0, 0); break; @@ -725,17 +692,17 @@ static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM } break; - case WM_GETMINMAXINFO: - { - RECT rc, rcTeststring; - GetWindowRect(GetParent(hwndDlg), &rc); - GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rcTeststring); - ((MINMAXINFO*)lParam)->ptMinTrackSize.y = (rc.bottom - rc.top) - (((rcTeststring.bottom - rcTeststring.top) - dat->minResultSize.y)); - } + case WM_GETMINMAXINFO: + { + RECT rc, rcTeststring; + GetWindowRect(GetParent(hwndDlg), &rc); + GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rcTeststring); + ((MINMAXINFO*)lParam)->ptMinTrackSize.y = (rc.bottom - rc.top) - (((rcTeststring.bottom - rcTeststring.top) - dat->minResultSize.y)); + } break; case WM_SIZE: - if (!IsIconic( hwndDlg )) { + if (!IsIconic(hwndDlg)) { UTILRESIZEDIALOG urd = { 0 }; urd.cbSize = sizeof(urd); urd.hInstance = hInst; @@ -761,8 +728,8 @@ static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM TCHAR *string = Hlp_GetDlgItemText(hwndDlg, IDC_TESTSTRING), *extraText; int len = SendMessage(GetParent(hwndDlg), VARM_GETEXTRATEXTLENGTH, 0, 0); if (len > 0) { - extraText = (TCHAR*)mir_calloc((len+1)* sizeof(TCHAR)); - SendMessage(GetParent(hwndDlg), VARM_GETEXTRATEXT, (WPARAM)len+1, (LPARAM)extraText); + extraText = (TCHAR*)mir_calloc((len + 1)* sizeof(TCHAR)); + SendMessage(GetParent(hwndDlg), VARM_GETEXTRATEXT, (WPARAM)len + 1, (LPARAM)extraText); } else extraText = NULL; @@ -778,7 +745,8 @@ static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM mir_free(oldString); } mir_free(string); - } } + } + } break; case VARM_SETINPUTTEXT: @@ -792,7 +760,7 @@ static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM return TRUE; case VARM_GETINPUTTEXT: - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, SendMessage(GetDlgItem(hwndDlg, IDC_TESTSTRING), WM_GETTEXT, wParam, lParam)); return TRUE; @@ -879,144 +847,140 @@ static INT_PTR CALLBACK helpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM l HELPDLGDATA *dat = (HELPDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch(msg) { - case WM_INITDIALOG: { - int tabCount; - HWND hTab, hShow, hPage; - TCITEM tci; - RECT rcTabs, rcParent; - - hwndHelpDialog = hwndDlg; + case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); - dat = ( HELPDLGDATA* )mir_alloc(sizeof(HELPDLGDATA)); - ZeroMemory(dat, sizeof(HELPDLGDATA)); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - dat->vhs = (VARHELPINFO *)lParam; - // set tabs - tabCount = 0; - hTab = GetDlgItem(hwndDlg, IDC_TABS); - GetWindowRect(hTab, &rcTabs); - GetWindowRect(hwndDlg, &rcParent); - ZeroMemory(&tci, sizeof(TCITEM)); - hShow = 0; - if (dat->vhs->flags&VHF_TOKENS) { - // token tab - tci.mask = TCIF_TEXT|TCIF_PARAM; - tci.pszText = TranslateT("Tokens"); - hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_TOKENS_DIALOG), hwndDlg, tokenHelpDlgProc, (LPARAM)GetParent(hwndDlg)); - EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); - - tci.lParam = (LPARAM)hPage; - MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2*iFrameX, (rcTabs.bottom - rcTabs.top) - 2*iFrameY, TRUE); - ShowWindow(hPage, SW_HIDE); - TabCtrl_InsertItem(hTab, tabCount++, &tci); - hShow = hShow==0?hPage:hShow; - } - if (dat->vhs->flags&VHF_INPUT) { - // input tab - tci.mask = TCIF_TEXT|TCIF_PARAM; - tci.pszText = TranslateT("Input"); - dat->hwndInputDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_INPUT_DIALOG), hwndDlg, inputDlgProc, (LPARAM)GetParent(hwndDlg)); - EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); - - tci.lParam = (LPARAM)hPage; - MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2*iFrameX, (rcTabs.bottom - rcTabs.top) - 2*iFrameY, TRUE); - ShowWindow(hPage, SW_HIDE); - TabCtrl_InsertItem(hTab, tabCount++, &tci); - hShow = hShow==0?hPage:hShow; - if ((dat->vhs->fi != NULL) && (dat->vhs->fi->szFormat != NULL)) { - if (dat->vhs->fi->flags & FIF_UNICODE) - SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)dat->vhs->fi->tszFormat); - else { - - WCHAR *wszFormatString = mir_a2t(dat->vhs->fi->szFormat); - SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)wszFormatString); - mir_free(wszFormatString); + { + hwndHelpDialog = hwndDlg; + dat = (HELPDLGDATA*)mir_calloc(sizeof(HELPDLGDATA)); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); + dat->vhs = (VARHELPINFO *)lParam; + + // set tabs + int tabCount = 0; + RECT rcTabs, rcParent; + HWND hTab = GetDlgItem(hwndDlg, IDC_TABS); + GetWindowRect(hTab, &rcTabs); + GetWindowRect(hwndDlg, &rcParent); - } - } - else if (dat->vhs->hwndCtrl != NULL) { - TCHAR *tszText; + TCITEM tci = { 0 }; + HWND hPage, hShow = 0; + if (dat->vhs->flags&VHF_TOKENS) { + // token tab + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("Tokens"); + hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_TOKENS_DIALOG), hwndDlg, tokenHelpDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); - tszText = Hlp_GetWindowText(dat->vhs->hwndCtrl); - if (tszText != NULL) { - SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)tszText); - mir_free(tszText); - } - } - if (dat->vhs->fi != NULL || dat->vhs->hwndCtrl != NULL) { - SetWindowText(GetDlgItem(hwndDlg, IDC_CANCEL), TranslateT("Cancel")); - ShowWindow(GetDlgItem(hwndDlg, IDC_OK), SW_SHOW); + tci.lParam = (LPARAM)hPage; + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); + TabCtrl_InsertItem(hTab, tabCount++, &tci); + hShow = hShow == 0 ? hPage : hShow; } - } - if ((dat->vhs->flags&VHF_SUBJECT) || - ((dat->vhs->flags&VHF_INPUT) && (((dat->vhs->fi != NULL) && (dat->vhs->fi->hContact != NULL)) || (dat->vhs->flags&VHF_SETLASTSUBJECT)))) { - // subject window is created, but not necessarily shown - dat->hwndSubjectDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CLIST_DIALOG), hwndDlg, clistDlgProc, (LPARAM)GetParent(hwndDlg)); - EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); - - MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2*iFrameX, (rcTabs.bottom - rcTabs.top) - 2*iFrameY, TRUE); - ShowWindow(hPage, SW_HIDE); - - if ((dat->vhs->fi != NULL) && (dat->vhs->fi->hContact != NULL)) - SendMessage(hwndDlg, VARM_SETSUBJECT, (WPARAM)dat->vhs->fi->hContact, 0); - else if (dat->vhs->flags&VHF_SETLASTSUBJECT) - SendMessage(hwndDlg, VARM_SETSUBJECT, (WPARAM)INVALID_HANDLE_VALUE, 0); - - if (dat->vhs->flags&VHF_SUBJECT) { - // create subject tab + if (dat->vhs->flags&VHF_INPUT) { + // input tab + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("Input"); + dat->hwndInputDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_INPUT_DIALOG), hwndDlg, inputDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); + tci.lParam = (LPARAM)hPage; - tci.mask = TCIF_TEXT|TCIF_PARAM; - tci.pszText = TranslateT("%subject%"); + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); TabCtrl_InsertItem(hTab, tabCount++, &tci); - hShow = hShow==0?hPage:hShow; + hShow = hShow == 0 ? hPage : hShow; + if ((dat->vhs->fi != NULL) && (dat->vhs->fi->szFormat != NULL)) { + if (dat->vhs->fi->flags & FIF_UNICODE) + SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)dat->vhs->fi->tszFormat); + else { + + WCHAR *wszFormatString = mir_a2t(dat->vhs->fi->szFormat); + SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)wszFormatString); + mir_free(wszFormatString); + + } + } + else if (dat->vhs->hwndCtrl != NULL) { + TCHAR *tszText = Hlp_GetWindowText(dat->vhs->hwndCtrl); + if (tszText != NULL) { + SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)tszText); + mir_free(tszText); + } + } + if (dat->vhs->fi != NULL || dat->vhs->hwndCtrl != NULL) { + SetWindowText(GetDlgItem(hwndDlg, IDC_CANCEL), TranslateT("Cancel")); + ShowWindow(GetDlgItem(hwndDlg, IDC_OK), SW_SHOW); + } } - } - if ((dat->vhs->flags&VHF_EXTRATEXT) || - ((dat->vhs->flags&VHF_INPUT) && (dat->vhs->fi != NULL) && (dat->vhs->fi->tszExtraText != NULL))) { - // extratext window is created, but not necessarily shown - dat->hwndExtraTextDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EXTRATEXT_DIALOG), hwndDlg, extratextDlgProc, (LPARAM)GetParent(hwndDlg)); - EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); - - MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2*iFrameX, (rcTabs.bottom - rcTabs.top) - 2*iFrameY, TRUE); - ShowWindow(hPage, SW_HIDE); - if ((dat->vhs->fi != NULL) && (dat->vhs->fi->tszExtraText != NULL)) { - if (dat->vhs->fi->flags & FIF_UNICODE) - SendMessage(hwndDlg, VARM_SETEXTRATEXT, 0, (LPARAM)dat->vhs->fi->tszExtraText); - else { - - WCHAR *wszSource = mir_a2t(dat->vhs->fi->szExtraText); - SendMessage(hwndDlg, VARM_SETEXTRATEXT, 0, (LPARAM)wszSource); - mir_free(wszSource); + if ((dat->vhs->flags&VHF_SUBJECT) || + ((dat->vhs->flags&VHF_INPUT) && (((dat->vhs->fi != NULL) && (dat->vhs->fi->hContact != NULL)) || (dat->vhs->flags&VHF_SETLASTSUBJECT)))) { + // subject window is created, but not necessarily shown + dat->hwndSubjectDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CLIST_DIALOG), hwndDlg, clistDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); + + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); + + if ((dat->vhs->fi != NULL) && (dat->vhs->fi->hContact != NULL)) + SendMessage(hwndDlg, VARM_SETSUBJECT, (WPARAM)dat->vhs->fi->hContact, 0); + else if (dat->vhs->flags&VHF_SETLASTSUBJECT) + SendMessage(hwndDlg, VARM_SETSUBJECT, (WPARAM)INVALID_HANDLE_VALUE, 0); + + if (dat->vhs->flags&VHF_SUBJECT) { + // create subject tab + tci.lParam = (LPARAM)hPage; + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("%subject%"); + TabCtrl_InsertItem(hTab, tabCount++, &tci); + hShow = hShow == 0 ? hPage : hShow; + } + } + if ((dat->vhs->flags&VHF_EXTRATEXT) || + ((dat->vhs->flags&VHF_INPUT) && (dat->vhs->fi != NULL) && (dat->vhs->fi->tszExtraText != NULL))) { + // extratext window is created, but not necessarily shown + dat->hwndExtraTextDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EXTRATEXT_DIALOG), hwndDlg, extratextDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); + + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); + if ((dat->vhs->fi != NULL) && (dat->vhs->fi->tszExtraText != NULL)) { + if (dat->vhs->fi->flags & FIF_UNICODE) + SendMessage(hwndDlg, VARM_SETEXTRATEXT, 0, (LPARAM)dat->vhs->fi->tszExtraText); + else { + WCHAR *wszSource = mir_a2t(dat->vhs->fi->szExtraText); + SendMessage(hwndDlg, VARM_SETEXTRATEXT, 0, (LPARAM)wszSource); + mir_free(wszSource); + + } + } + if (dat->vhs->flags&VHF_EXTRATEXT) { + // create extratext tab + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("%extratext%"); + tci.lParam = (LPARAM)hPage; + TabCtrl_InsertItem(hTab, tabCount++, &tci); + hShow = hShow == 0 ? hPage : hShow; } } - if (dat->vhs->flags&VHF_EXTRATEXT) { - // create extratext tab - tci.mask = TCIF_TEXT|TCIF_PARAM; - tci.pszText = TranslateT("%extratext%"); + if (dat->vhs->flags&VHF_HELP) { + // helpinfo tab + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("Help"); + hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_HELPINFO_DIALOG), hwndDlg, helpInfoDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); + tci.lParam = (LPARAM)hPage; + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); TabCtrl_InsertItem(hTab, tabCount++, &tci); - hShow = hShow==0?hPage:hShow; + hShow = hShow == 0 ? hPage : hShow; } + Utils_RestoreWindowPositionNoMove(hwndDlg, NULL, MODULENAME, "help"); + SetWindowText(hwndDlg, TranslateT("Variables Help")); + ShowWindow(hShow, SW_SHOW); + break; } - if (dat->vhs->flags&VHF_HELP) { - // helpinfo tab - tci.mask = TCIF_TEXT|TCIF_PARAM; - tci.pszText = TranslateT("Help"); - hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_HELPINFO_DIALOG), hwndDlg, helpInfoDlgProc, (LPARAM)GetParent(hwndDlg)); - EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); - - tci.lParam = (LPARAM)hPage; - MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2*iFrameX, (rcTabs.bottom - rcTabs.top) - 2*iFrameY, TRUE); - ShowWindow(hPage, SW_HIDE); - TabCtrl_InsertItem(hTab, tabCount++, &tci); - hShow = hShow==0?hPage:hShow; - } - Utils_RestoreWindowPositionNoMove(hwndDlg, NULL, MODULENAME, "help"); - SetWindowText(hwndDlg, TranslateT("Variables Help")); - ShowWindow(hShow, SW_SHOW); - break; - } case WM_COMMAND: switch (LOWORD(wParam)) { @@ -1026,12 +990,12 @@ static INT_PTR CALLBACK helpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM l if (len > 0) { if ((dat->vhs->fi != NULL) && (!(dat->vhs->flags&VHF_DONTFILLSTRUCT))) { if (dat->vhs->fi->flags&FIF_UNICODE) { - dat->vhs->fi->tszFormat = (TCHAR*)mir_calloc((len+1)*sizeof(WCHAR)); - SendMessage(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len+1, (LPARAM)dat->vhs->fi->tszFormat); + dat->vhs->fi->tszFormat = (TCHAR*)mir_calloc((len + 1)*sizeof(WCHAR)); + SendMessage(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->tszFormat); } else { - dat->vhs->fi->szFormat = ( char* )mir_calloc(len+1); - SendMessageA(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len+1, (LPARAM)dat->vhs->fi->szFormat); + dat->vhs->fi->szFormat = (char*)mir_calloc(len + 1); + SendMessageA(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->szFormat); } } } @@ -1042,9 +1006,9 @@ static INT_PTR CALLBACK helpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM l if (len > 0) { TCHAR *tszText; - tszText = (TCHAR*)mir_calloc((len+1)*sizeof(TCHAR)); + tszText = (TCHAR*)mir_calloc((len + 1)*sizeof(TCHAR)); if (tszText != NULL) { - SendMessage(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len+1, (LPARAM)tszText); + SendMessage(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len + 1, (LPARAM)tszText); SetWindowText(dat->vhs->hwndCtrl, tszText); mir_free(tszText); } @@ -1060,12 +1024,12 @@ static INT_PTR CALLBACK helpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM l int len = SendMessage(hwndDlg, VARM_GETEXTRATEXTLENGTH, 0, 0); if (len > 0) { if (dat->vhs->fi->flags&FIF_UNICODE) { - dat->vhs->fi->tszExtraText = (TCHAR*)mir_calloc((len+1)*sizeof(WCHAR)); - SendMessage(hwndDlg, VARM_GETEXTRATEXT, (WPARAM)len+1, (LPARAM)dat->vhs->fi->tszExtraText); + dat->vhs->fi->tszExtraText = (TCHAR*)mir_calloc((len + 1)*sizeof(WCHAR)); + SendMessage(hwndDlg, VARM_GETEXTRATEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->tszExtraText); } else { - dat->vhs->fi->szExtraText = ( char* )mir_calloc(len+1); - SendMessageA(hwndDlg, VARM_GETEXTRATEXT, (WPARAM)len+1, (LPARAM)dat->vhs->fi->szExtraText); + dat->vhs->fi->szExtraText = (char*)mir_calloc(len + 1); + SendMessageA(hwndDlg, VARM_GETEXTRATEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->szExtraText); } } dat->vhs->fi->hContact = (HANDLE)SendMessage(hwndDlg, VARM_GETSUBJECT, 0, 0); @@ -1145,7 +1109,7 @@ static INT_PTR CALLBACK helpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM l tci.mask = TCIF_PARAM; count = TabCtrl_GetItemCount(hTab); // return the largest of all pages - for (i=0;iidFrom == IDC_TABS)) { @@ -1216,17 +1176,17 @@ static INT_PTR CALLBACK helpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM l case WM_DESTROY: Utils_SaveWindowPosition(hwndDlg, NULL, MODULENAME, "help"); - { - HWND hTab = GetDlgItem(hwndDlg, IDC_TABS); - - TCITEM tci; - tci.mask = TCIF_PARAM; - int count = TabCtrl_GetItemCount(hTab); - for ( int i=0; i < count; i++ ) { - TabCtrl_GetItem(hTab, i, &tci); - if (((HWND)tci.lParam != dat->hwndSubjectDlg) && ((HWND)tci.lParam != dat->hwndExtraTextDlg)) - DestroyWindow((HWND)tci.lParam); - } } + + HWND hTab = GetDlgItem(hwndDlg, IDC_TABS); + + TCITEM tci; + tci.mask = TCIF_PARAM; + int count = TabCtrl_GetItemCount(hTab); + for (int i = 0; i < count; i++) { + TabCtrl_GetItem(hTab, i, &tci); + if (((HWND)tci.lParam != dat->hwndSubjectDlg) && ((HWND)tci.lParam != dat->hwndExtraTextDlg)) + DestroyWindow((HWND)tci.lParam); + } // these windows might have been created, but not inserted as tabs if (IsWindow(dat->hwndSubjectDlg)) @@ -1270,19 +1230,19 @@ INT_PTR showHelpService(WPARAM wParam, LPARAM lParam) static FORMATINFO *fi = NULL; if (fi == NULL) - fi = ( FORMATINFO* )mir_alloc(sizeof(FORMATINFO)); + fi = (FORMATINFO*)mir_alloc(sizeof(FORMATINFO)); ZeroMemory(fi, sizeof(FORMATINFO)); fi->cbSize = sizeof(FORMATINFO); fi->szFormat = (char *)lParam; if (vhs == NULL) - vhs = ( VARHELPINFO* )mir_alloc(sizeof(VARHELPINFO)); + vhs = (VARHELPINFO*)mir_alloc(sizeof(VARHELPINFO)); ZeroMemory(vhs, sizeof(VARHELPINFO)); vhs->cbSize = sizeof(VARHELPINFO); vhs->fi = fi; vhs->hwndCtrl = (HWND)wParam; - vhs->flags = VHF_FULLDLG|VHF_DONTFILLSTRUCT; + vhs->flags = VHF_FULLDLG | VHF_DONTFILLSTRUCT; return showHelpExService(0, (LPARAM)vhs); } diff --git a/plugins/Variables/src/parse_alias.cpp b/plugins/Variables/src/parse_alias.cpp index 403bc2a7a0..848a91b3d0 100644 --- a/plugins/Variables/src/parse_alias.cpp +++ b/plugins/Variables/src/parse_alias.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -36,33 +36,33 @@ static ALIASREGISTER *searchAliasRegister(TCHAR *szAlias) return NULL; mir_cslock lck(csAliasRegister); - for (int i=0; i < arAliases.getCount(); i++) - if (!_tcscmp(arAliases[i]->szAlias, szAlias)) - return arAliases[i]; + for (int i = 0; i < arAliases.getCount(); i++) + if (!_tcscmp(arAliases[i]->szAlias, szAlias)) + return arAliases[i]; return NULL; } static TCHAR *replaceArguments(TCHAR *res, TCHAR *tArg, TCHAR *rArg) { - if ( _tcslen(tArg) == 0) + if (_tcslen(tArg) == 0) return res; unsigned int cur = 0, ecur = 0; - while (*(res+cur) != 0) { - if ((*(res+cur) == '(') || (*(res+cur) == ',')) { + while (*(res + cur) != 0) { + if ((*(res + cur) == '(') || (*(res + cur) == ',')) { ecur = ++cur; - while ( (*(res+ecur) != ')') && (*(res+ecur) != ',')) + while ((*(res + ecur) != ')') && (*(res + ecur) != ',')) ecur++; - if (((signed int)_tcslen(tArg) == (ecur-cur)) && (!_tcsncmp(tArg, res+cur, _tcslen(tArg)))) { - if ( _tcslen(rArg) > _tcslen(tArg)) { - res = (TCHAR*)mir_realloc(res, (_tcslen(res) + (_tcslen(rArg)-_tcslen(tArg)) + 1)*sizeof(TCHAR)); + if (((signed int)_tcslen(tArg) == (ecur - cur)) && (!_tcsncmp(tArg, res + cur, _tcslen(tArg)))) { + if (_tcslen(rArg) > _tcslen(tArg)) { + res = (TCHAR*)mir_realloc(res, (_tcslen(res) + (_tcslen(rArg) - _tcslen(tArg)) + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; } - MoveMemory(res+ecur+(_tcslen(rArg)-_tcslen(tArg)), res+ecur, (_tcslen(res+ecur)+1)*sizeof(TCHAR)); - _tcsncpy(res+cur, rArg, _tcslen(rArg)); + MoveMemory(res + ecur + (_tcslen(rArg) - _tcslen(tArg)), res + ecur, (_tcslen(res + ecur) + 1)*sizeof(TCHAR)); + _tcsncpy(res + cur, rArg, _tcslen(rArg)); } } cur++; @@ -74,12 +74,12 @@ static TCHAR *replaceArguments(TCHAR *res, TCHAR *tArg, TCHAR *rArg) static TCHAR *parseTranslateAlias(ARGUMENTSINFO *ai) { ALIASREGISTER *areg = searchAliasRegister(ai->targv[0]); - if (areg == NULL || areg->argc != ai->argc-1) + if (areg == NULL || areg->argc != ai->argc - 1) return NULL; TCHAR *res = mir_tstrdup(areg->szTranslation); - for (unsigned i=0; i < areg->argc; i++) { - res = replaceArguments(res, areg->argv[i], ai->targv[i+1]); + for (unsigned i = 0; i < areg->argc; i++) { + res = replaceArguments(res, areg->argv[i], ai->targv[i + 1]); if (res == NULL) return NULL; } @@ -89,27 +89,26 @@ static TCHAR *parseTranslateAlias(ARGUMENTSINFO *ai) static int addToAliasRegister(TCHAR *szAlias, unsigned int argc, TCHAR** argv, TCHAR *szTranslation) { - if (szAlias == NULL || szTranslation == NULL || _tcslen(szAlias) == 0 ) + if (szAlias == NULL || szTranslation == NULL || _tcslen(szAlias) == 0) return -1; mir_cslock lck(csAliasRegister); - for (int i=0; i < arAliases.getCount(); i++) { + for (int i = 0; i < arAliases.getCount(); i++) { ALIASREGISTER *p = arAliases[i]; - if ( _tcscmp(p->szAlias, szAlias)) + if (_tcscmp(p->szAlias, szAlias)) continue; mir_free(p->szTranslation); p->szTranslation = mir_tstrdup(szTranslation); - for (unsigned j=0; j < p->argc; j++) - if (p->argv[j] != NULL) - mir_free(p->argv[j]); + for (unsigned j = 0; j < p->argc; j++) + mir_free(p->argv[j]); p->argc = argc; p->argv = (TCHAR**)mir_realloc(p->argv, argc * sizeof(TCHAR*)); if (p->argv == NULL) return -1; - for (unsigned j=0; j < argc; j++) { + for (unsigned j = 0; j < argc; j++) { if (argv[j] != NULL) p->argv[j] = mir_tstrdup(argv[j]); else @@ -126,7 +125,7 @@ static int addToAliasRegister(TCHAR *szAlias, unsigned int argc, TCHAR** argv, T if (p->argv == NULL) return -1; - for (unsigned j=0; j < p->argc; j++) { + for (unsigned j = 0; j < p->argc; j++) { if (argv[j] != NULL) p->argv[j] = mir_tstrdup(argv[j]); else @@ -139,8 +138,6 @@ static int addToAliasRegister(TCHAR *szAlias, unsigned int argc, TCHAR** argv, T static TCHAR *parseAddAlias(ARGUMENTSINFO *ai) { int res; - int argc, i; - TCHAR **argv; char *szHelp, *szArgsA; if (ai->argc != 3) @@ -150,40 +147,39 @@ static TCHAR *parseAddAlias(ARGUMENTSINFO *ai) while (isValidTokenChar(*cur)) cur++; - TCHAR *alias = (TCHAR*)mir_calloc(((cur-ai->targv[1])+1)*sizeof(TCHAR)); - if (alias == NULL) - return NULL; + ptrT alias(mir_tstrndup(ai->targv[1], cur - ai->targv[1])); - _tcsncpy(alias, ai->targv[1], (cur-ai->targv[1])); + int argc; + TCHAR **argv; getArguments(cur, &argv, &argc); deRegisterToken(alias); addToAliasRegister(alias, argc, argv, ai->targv[2]); TCHAR *szArgs = NULL; - for (i=0; i < argc; i++) { + for (int i = 0; i < argc; i++) { if (i == 0) - szArgs = (TCHAR*)mir_calloc(( _tcslen(argv[i])+2)*sizeof(TCHAR)); + szArgs = (TCHAR*)mir_calloc((_tcslen(argv[i]) + 2)*sizeof(TCHAR)); else szArgs = (TCHAR*)mir_realloc(szArgs, (_tcslen(szArgs) + _tcslen(argv[i]) + 2)*sizeof(TCHAR)); _tcscat(szArgs, argv[i]); - if (i != argc-1) + if (i != argc - 1) _tcscat(szArgs, _T(",")); } - if ((szArgs != NULL) && (argc > 0)) { - szArgsA = mir_t2a(szArgs); + if (szArgs != NULL && argc > 0) { + szArgsA = mir_t2a(szArgs); size_t size = 32 + strlen(szArgsA); szHelp = (char *)mir_alloc(size); memset(szHelp, '\0', 32 + strlen(szArgsA)); mir_snprintf(szHelp, size, LPGEN("Alias")"\t(%s)\t"LPGEN("user defined"), szArgsA); - res = registerIntToken(alias, parseTranslateAlias, TRF_FUNCTION|TRF_UNPARSEDARGS, szHelp); + res = registerIntToken(alias, parseTranslateAlias, TRF_FUNCTION | TRF_UNPARSEDARGS, szHelp); mir_free(szArgsA); } else { - szHelp = ( char* )mir_alloc(32); + szHelp = (char*)mir_alloc(32); memset(szHelp, '\0', 32); mir_snprintf(szHelp, 32, LPGEN("Alias")"\t\t"LPGEN("user defined")); - res = registerIntToken(alias, parseTranslateAlias, TRF_FIELD|TRF_UNPARSEDARGS, szHelp); + res = registerIntToken(alias, parseTranslateAlias, TRF_FIELD | TRF_UNPARSEDARGS, szHelp); } mir_free(szArgs); mir_free(szHelp); @@ -192,7 +188,7 @@ static TCHAR *parseAddAlias(ARGUMENTSINFO *ai) int registerAliasTokens() { - registerIntToken(_T(ADDALIAS), parseAddAlias, TRF_FUNCTION|TRF_UNPARSEDARGS, LPGEN("Variables")"\t(x,y)\t"LPGEN("stores y as alias named x"));//TRF_UNPARSEDARGS); + registerIntToken(_T(ADDALIAS), parseAddAlias, TRF_FUNCTION | TRF_UNPARSEDARGS, LPGEN("Variables")"\t(x,y)\t"LPGEN("stores y as alias named x"));//TRF_UNPARSEDARGS); InitializeCriticalSection(&csAliasRegister); return 0; } @@ -201,8 +197,10 @@ void unregisterAliasTokens() { DeleteCriticalSection(&csAliasRegister); - for (int i=0; i < arAliases.getCount(); i++) { + for (int i = 0; i < arAliases.getCount(); i++) { ALIASREGISTER *p = arAliases[i]; + for (unsigned j = 0; j < p->argc; j++) + mir_free(p->argv[j]); mir_free(p->argv); mir_free(p->szAlias); mir_free(p->szTranslation); diff --git a/plugins/Variables/src/parse_alias.h b/plugins/Variables/src/parse_alias.h index 7297fec1d0..14ad03ac88 100644 --- a/plugins/Variables/src/parse_alias.h +++ b/plugins/Variables/src/parse_alias.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_external.cpp b/plugins/Variables/src/parse_external.cpp index 152684dc5b..8ad844b0e7 100644 --- a/plugins/Variables/src/parse_external.cpp +++ b/plugins/Variables/src/parse_external.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -23,7 +23,7 @@ static TCHAR *getFullWinampTitleText() { HWND hwndWinamp = FindWindow(_T("STUDIO"), NULL); if (hwndWinamp == NULL) - hwndWinamp = FindWindow(_T("Winamp v1.x"),NULL); + hwndWinamp = FindWindow(_T("Winamp v1.x"), NULL); if (hwndWinamp == NULL) return NULL; @@ -32,17 +32,17 @@ static TCHAR *getFullWinampTitleText() if (szWinText == NULL) return NULL; - if (GetWindowText(hwndWinamp, szWinText, GetWindowTextLength(hwndWinamp)+1) == 0) { + if (GetWindowText(hwndWinamp, szWinText, GetWindowTextLength(hwndWinamp) + 1) == 0) { mir_free(szWinText); return NULL; } - TCHAR *szTitle = (TCHAR*)mir_alloc((2*_tcslen(szWinText)+1)*sizeof(TCHAR)); + TCHAR *szTitle = (TCHAR*)mir_alloc((2 * _tcslen(szWinText) + 1)*sizeof(TCHAR)); if (szTitle == NULL) { mir_free(szWinText); return NULL; } _tcscpy(szTitle, szWinText); - _tcscpy(szTitle+_tcslen(szTitle), szWinText); + _tcscpy(szTitle + _tcslen(szTitle), szWinText); mir_free(szWinText); return szTitle; @@ -70,7 +70,7 @@ static TCHAR *parseWinampSong(ARGUMENTSINFO *ai) res = mir_tstrdup(scur); mir_free(szTitle); ai->flags |= AIF_DONTPARSE; - + return res; } @@ -86,15 +86,15 @@ static TCHAR *parseWinampState(ARGUMENTSINFO *ai) TCHAR *scur = _tcschr(szTitle, '.'); TCHAR *cur = _tcsstr(scur, _T(" - Winamp")); - if ((scur == NULL) || (cur == NULL)) { + if (scur == NULL || cur == NULL) { mir_free(szTitle); return mir_tstrdup(TranslateT("Stopped")); } - if ((!_tcsncmp(cur+10, _T("[Stopped]"), 9))) { + if ((!_tcsncmp(cur + 10, _T("[Stopped]"), 9))) { mir_free(szTitle); return mir_tstrdup(TranslateT("Stopped")); } - if ((!_tcsncmp(cur+10, _T("[Paused]"), 8))) { + if ((!_tcsncmp(cur + 10, _T("[Paused]"), 8))) { mir_free(szTitle); return mir_tstrdup(TranslateT("Paused")); } diff --git a/plugins/Variables/src/parse_external.h b/plugins/Variables/src/parse_external.h index 463aa73ecc..d881cf04b8 100644 --- a/plugins/Variables/src/parse_external.h +++ b/plugins/Variables/src/parse_external.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_inet.cpp b/plugins/Variables/src/parse_inet.cpp index dfa92ba7f1..126642eddf 100644 --- a/plugins/Variables/src/parse_inet.cpp +++ b/plugins/Variables/src/parse_inet.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -30,19 +30,19 @@ static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai) size_t cur = 0; while (cur < strlen(res)) { - if (( (*(res+cur) >= '0') && (*(res+cur) <= '9')) || ( (*(res+cur) >= 'a') && (*(res+cur) <= 'z')) || ( (*(res+cur) >= 'A') && (*(res+cur) <= 'Z')) ) { + if (((*(res + cur) >= '0') && (*(res + cur) <= '9')) || ((*(res + cur) >= 'a') && (*(res + cur) <= 'z')) || ((*(res + cur) >= 'A') && (*(res + cur) <= 'Z'))) { cur++; continue; } - res = ( char* )mir_realloc(res, strlen(res)+4); + res = (char*)mir_realloc(res, strlen(res) + 4); if (res == NULL) return NULL; char hex[8]; - MoveMemory(res+cur+3, res+cur+1, strlen(res+cur+1)+1); - mir_snprintf(hex, sizeof(hex), "%%%x", *(res+cur)); - strncpy(res+cur, hex, strlen(hex)); - cur+=strlen(hex); + MoveMemory(res + cur + 3, res + cur + 1, strlen(res + cur + 1) + 1); + mir_snprintf(hex, sizeof(hex), "%%%x", *(res + cur)); + strncpy(res + cur, hex, strlen(hex)); + cur += strlen(hex); } TCHAR *tres = mir_a2t(res); @@ -61,17 +61,17 @@ static TCHAR *parseUrlDec(ARGUMENTSINFO *ai) unsigned int cur = 0; while (cur < strlen(res)) { - if ((*(res+cur) == '%') && (strlen(res+cur) >= 3)) { + if ((*(res + cur) == '%') && (strlen(res + cur) >= 3)) { char hex[8]; memset(hex, '\0', sizeof(hex)); - strncpy(hex, res+cur+1, 2); - *(res+cur) = (char)strtol(hex, NULL, 16); - MoveMemory(res+cur+1, res+cur+3, strlen(res+cur+3)+1); + strncpy(hex, res + cur + 1, 2); + *(res + cur) = (char)strtol(hex, NULL, 16); + MoveMemory(res + cur + 1, res + cur + 3, strlen(res + cur + 3) + 1); } cur++; } - res = ( char* )mir_realloc(res, strlen(res)+1); + res = (char*)mir_realloc(res, strlen(res) + 1); TCHAR *tres = mir_a2t(res); mir_free(res); return tres; @@ -81,20 +81,20 @@ static TCHAR *parseNToA(ARGUMENTSINFO *ai) { if (ai->argc != 2) return NULL; - + struct in_addr in; in.s_addr = ttoi(ai->targv[1]); - return mir_a2t( inet_ntoa(in)); + return mir_a2t(inet_ntoa(in)); } static TCHAR *parseHToA(ARGUMENTSINFO *ai) { if (ai->argc != 2) return NULL; - + struct in_addr in; in.s_addr = htonl(ttoi(ai->targv[1])); - return mir_a2t( inet_ntoa(in)); + return mir_a2t(inet_ntoa(in)); } int registerInetTokens() @@ -103,5 +103,5 @@ int registerInetTokens() registerIntToken(_T(URLDEC), parseUrlDec, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts each hex value into non-html character")); registerIntToken(_T(NTOA), parseNToA, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts a 32-bit number to IPv4 dotted notation")); registerIntToken(_T(HTOA), parseHToA, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts a 32-bit number (in host byte order) to IPv4 dotted notation")); - return 0; + return 0; } diff --git a/plugins/Variables/src/parse_inet.h b/plugins/Variables/src/parse_inet.h index dc9faf4b10..788d208d66 100644 --- a/plugins/Variables/src/parse_inet.h +++ b/plugins/Variables/src/parse_inet.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_logic.cpp b/plugins/Variables/src/parse_logic.cpp index bc0264caea..211ef15e94 100644 --- a/plugins/Variables/src/parse_logic.cpp +++ b/plugins/Variables/src/parse_logic.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -26,9 +26,9 @@ static TCHAR *parseAnd(ARGUMENTSINFO *ai) FORMATINFO fi; memcpy(&fi, ai->fi, sizeof(fi)); - for (unsigned i=1; i < ai->argc; i++) { + for (unsigned i = 1; i < ai->argc; i++) { fi.tszFormat = ai->targv[i]; - mir_free( formatString(&fi)); + mir_free(formatString(&fi)); if (fi.eCount > 0) { ai->flags |= AIF_FALSE; @@ -57,7 +57,7 @@ static TCHAR *parseIf(ARGUMENTSINFO *ai) memcpy(&fi, ai->fi, sizeof(fi)); fi.eCount = fi.pCount = 0; fi.tszFormat = ai->targv[1]; - mir_free( formatString(&fi)); + mir_free(formatString(&fi)); return mir_tstrdup((fi.eCount == 0) ? ai->targv[2] : ai->targv[3]); } @@ -83,7 +83,7 @@ static TCHAR *parseIf3(ARGUMENTSINFO *ai) { FORMATINFO fi; memcpy(&fi, ai->fi, sizeof(fi)); - for (unsigned i=1; i < ai->argc; i++) { + for (unsigned i = 1; i < ai->argc; i++) { fi.eCount = fi.pCount = 0; fi.tszFormat = ai->targv[i]; TCHAR *szCondition = formatString(&fi); @@ -92,7 +92,7 @@ static TCHAR *parseIf3(ARGUMENTSINFO *ai) mir_free(szCondition); } - + return NULL; } @@ -104,13 +104,13 @@ static TCHAR *parseIfequal(ARGUMENTSINFO *ai) FORMATINFO fi; memcpy(&fi, ai->fi, sizeof(fi)); fi.szFormat = ai->argv[1]; - ptrT tszFirst( formatString(&fi)); + ptrT tszFirst(formatString(&fi)); fi.szFormat = ai->argv[2]; - ptrT tszSecond( formatString(&fi)); + ptrT tszSecond(formatString(&fi)); if (tszFirst == NULL || tszSecond == NULL) return NULL; - if ( ttoi(tszFirst) == ttoi(tszSecond)) + if (ttoi(tszFirst) == ttoi(tszSecond)) return mir_tstrdup(ai->targv[3]); return mir_tstrdup(ai->targv[4]); @@ -124,13 +124,13 @@ static TCHAR *parseIfgreater(ARGUMENTSINFO *ai) FORMATINFO fi; memcpy(&fi, ai->fi, sizeof(fi)); fi.szFormat = ai->argv[1]; - ptrT tszFirst( formatString(&fi)); + ptrT tszFirst(formatString(&fi)); fi.szFormat = ai->argv[2]; - ptrT tszSecond( formatString(&fi)); + ptrT tszSecond(formatString(&fi)); if (tszFirst == NULL || tszSecond == NULL) return NULL; - if ( ttoi(tszFirst) > ttoi(tszSecond)) + if (ttoi(tszFirst) > ttoi(tszSecond)) return mir_tstrdup(ai->targv[3]); return mir_tstrdup(ai->targv[4]); @@ -144,13 +144,13 @@ static TCHAR *parseIflonger(ARGUMENTSINFO *ai) FORMATINFO fi; memcpy(&fi, ai->fi, sizeof(fi)); fi.szFormat = ai->argv[1]; - ptrT tszFirst( formatString(&fi)); + ptrT tszFirst(formatString(&fi)); fi.szFormat = ai->argv[2]; - ptrT tszSecond( formatString(&fi)); + ptrT tszSecond(formatString(&fi)); if (tszFirst == NULL || tszSecond == NULL) return NULL; - if ( _tcslen(tszFirst) > _tcslen(tszSecond)) + if (_tcslen(tszFirst) > _tcslen(tszSecond)) return mir_tstrdup(ai->targv[3]); return mir_tstrdup(ai->targv[4]); @@ -181,11 +181,11 @@ static TCHAR *parseFor(ARGUMENTSINFO *ai) parsed = formatString(&fi); if (parsed != NULL) { if (res == NULL) { - res = (TCHAR*)mir_alloc( _tcslen(parsed)+1 * sizeof(TCHAR)); + res = (TCHAR*)mir_alloc(_tcslen(parsed) + 1 * sizeof(TCHAR)); if (res == NULL) return NULL; } - else res = (TCHAR*)mir_realloc(res, (_tcslen(res)+_tcslen(parsed)+1)*sizeof(TCHAR)); + else res = (TCHAR*)mir_realloc(res, (_tcslen(res) + _tcslen(parsed) + 1)*sizeof(TCHAR)); _tcscat(res, parsed); } @@ -204,7 +204,7 @@ static TCHAR *parseEqual(ARGUMENTSINFO *ai) if (ai->argc != 3) return NULL; - if (ttoi(ai->targv[1]) != ttoi( ai->targv[2] )) + if (ttoi(ai->targv[1]) != ttoi(ai->targv[2])) ai->flags |= AIF_FALSE; return mir_tstrdup(_T("")); @@ -215,7 +215,7 @@ static TCHAR *parseGreater(ARGUMENTSINFO *ai) if (ai->argc != 3) return NULL; - if (ttoi(ai->targv[1]) <= ttoi(ai->targv[2] )) + if (ttoi(ai->targv[1]) <= ttoi(ai->targv[2])) ai->flags |= AIF_FALSE; return mir_tstrdup(_T("")); @@ -226,13 +226,14 @@ static TCHAR *parseLonger(ARGUMENTSINFO *ai) if (ai->argc != 3) return NULL; - if ( _tcslen(ai->targv[1]) <= _tcslen(ai->targv[2])) + if (_tcslen(ai->targv[1]) <= _tcslen(ai->targv[2])) ai->flags |= AIF_FALSE; return mir_tstrdup(_T("")); } -static TCHAR *parseNot(ARGUMENTSINFO *ai) { +static TCHAR *parseNot(ARGUMENTSINFO *ai) +{ if (ai->argc != 2) { return NULL; } @@ -240,7 +241,7 @@ static TCHAR *parseNot(ARGUMENTSINFO *ai) { FORMATINFO fi; memcpy(&fi, ai->fi, sizeof(fi)); fi.tszFormat = ai->targv[1]; - mir_free( formatString(&fi)); + mir_free(formatString(&fi)); if (fi.eCount == 0) ai->flags |= AIF_FALSE; @@ -256,10 +257,10 @@ static TCHAR *parseOr(ARGUMENTSINFO *ai) FORMATINFO fi; memcpy(&fi, ai->fi, sizeof(fi)); ai->flags |= AIF_FALSE; - for(unsigned i=1; (iargc) && (ai->flags&AIF_FALSE); i++) { + for (unsigned i = 1; (i < ai->argc) && (ai->flags&AIF_FALSE); i++) { fi.tszFormat = ai->targv[i]; fi.eCount = 0; - mir_free( formatString(&fi)); + mir_free(formatString(&fi)); if (fi.eCount == 0) ai->flags &= ~AIF_FALSE; @@ -285,11 +286,11 @@ static TCHAR *parseXor(ARGUMENTSINFO *ai) memcpy(&fi, ai->fi, sizeof(fi)); ai->flags = AIF_FALSE; fi.tszFormat = ai->targv[0]; - mir_free( formatString(&fi)); + mir_free(formatString(&fi)); int val1 = fi.eCount == 0; fi.tszFormat = ai->targv[1]; - mir_free( formatString(&fi)); + mir_free(formatString(&fi)); int val2 = fi.eCount == 0; ai->flags |= ((val1 & AIF_FALSE) == !(val2 & AIF_FALSE)) ? 0 : AIF_FALSE; @@ -298,21 +299,21 @@ static TCHAR *parseXor(ARGUMENTSINFO *ai) int registerLogicTokens() { - registerIntToken(_T(AND), parseAnd, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y, ...)\t"LPGEN("performs logical AND (x && y && ...)")); + registerIntToken(_T(AND), parseAnd, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y, ...)\t"LPGEN("performs logical AND (x && y && ...)")); registerIntToken(_T(STR_FALSE), parseFalse, TRF_FIELD, LPGEN("Logical Expressions")"\t"LPGEN("Boolean FALSE")); - registerIntToken(_T(FOR), parseFor, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(w,x,y,z)\t"LPGEN("performs w, then shows z and performs y while x is TRUE")); - registerIntToken(_T(IF), parseIf, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y,z)\t"LPGEN("shows y if x is TRUE, otherwise it shows z")); - registerIntToken(_T(IF2), parseIf2, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("shows x if x is TRUE, otherwise it shows y (if(x,x,y))")); - registerIntToken(_T(IF3), parseIf3, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y, ...)\t"LPGEN("the first argument parsed successfully")); - registerIntToken(_T(IFEQUAL), parseIfequal, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(w,x,y,z)\t"LPGEN("y if w = x, else z")); - registerIntToken(_T(IFGREATER), parseIfgreater, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(w,x,y,z)\t"LPGEN("y if w > x, else z")); - registerIntToken(_T(IFLONGER), parseIflonger, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(w,x,y,z)\t"LPGEN("y if string length of w > x, else z")); - registerIntToken(_T(EQUAL), parseEqual, TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("TRUE if x = y")); - registerIntToken(_T(GREATER), parseGreater, TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("TRUE if x > y")); + registerIntToken(_T(FOR), parseFor, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(w,x,y,z)\t"LPGEN("performs w, then shows z and performs y while x is TRUE")); + registerIntToken(_T(IF), parseIf, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y,z)\t"LPGEN("shows y if x is TRUE, otherwise it shows z")); + registerIntToken(_T(IF2), parseIf2, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("shows x if x is TRUE, otherwise it shows y (if(x,x,y))")); + registerIntToken(_T(IF3), parseIf3, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y, ...)\t"LPGEN("the first argument parsed successfully")); + registerIntToken(_T(IFEQUAL), parseIfequal, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(w,x,y,z)\t"LPGEN("y if w = x, else z")); + registerIntToken(_T(IFGREATER), parseIfgreater, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(w,x,y,z)\t"LPGEN("y if w > x, else z")); + registerIntToken(_T(IFLONGER), parseIflonger, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(w,x,y,z)\t"LPGEN("y if string length of w > x, else z")); + registerIntToken(_T(EQUAL), parseEqual, TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("TRUE if x = y")); + registerIntToken(_T(GREATER), parseGreater, TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("TRUE if x > y")); registerIntToken(_T(LONGER), parseLonger, TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("TRUE if x is longer than y")); - registerIntToken(_T(NOT), parseNot, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x)\t"LPGEN("performs logical NOT (!x)")); - registerIntToken(_T(OR), parseOr, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y,...)\t"LPGEN("performs logical OR (x || y || ...)")); + registerIntToken(_T(NOT), parseNot, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x)\t"LPGEN("performs logical NOT (!x)")); + registerIntToken(_T(OR), parseOr, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y,...)\t"LPGEN("performs logical OR (x || y || ...)")); registerIntToken(_T(STR_TRUE), parseTrue, TRF_FIELD, LPGEN("Logical Expressions")"\t"LPGEN("Boolean TRUE")); - registerIntToken(_T(XOR), parseXor, TRF_UNPARSEDARGS|TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("performs logical XOR (x ^ y)")); + registerIntToken(_T(XOR), parseXor, TRF_UNPARSEDARGS | TRF_FUNCTION, LPGEN("Logical Expressions")"\t(x,y)\t"LPGEN("performs logical XOR (x ^ y)")); return 0; } diff --git a/plugins/Variables/src/parse_logic.h b/plugins/Variables/src/parse_logic.h index 5ce1c4c786..adc79d1626 100644 --- a/plugins/Variables/src/parse_logic.h +++ b/plugins/Variables/src/parse_logic.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_math.cpp b/plugins/Variables/src/parse_math.cpp index 14e2ec6f46..cb8335f764 100644 --- a/plugins/Variables/src/parse_math.cpp +++ b/plugins/Variables/src/parse_math.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -25,7 +25,7 @@ static TCHAR *parseAdd(ARGUMENTSINFO *ai) return NULL; int result = 0; - for (unsigned int i=1;iargc;i++) + for (unsigned int i = 1; i < ai->argc; i++) result += ttoi(ai->targv[i]); return itot(result); @@ -41,7 +41,7 @@ static TCHAR *parseDiv(ARGUMENTSINFO *ai) if (val2 == 0) return NULL; - return itot(val1/val2); + return itot(val1 / val2); } static TCHAR *parseHex(ARGUMENTSINFO *ai) @@ -62,8 +62,8 @@ static TCHAR *parseHex(ARGUMENTSINFO *ai) ZeroMemory(res, (zeros + _tcslen(szVal) + 3)*sizeof(TCHAR)); _tcscpy(res, _T("0x")); - for (i=0; i < zeros; i++) - *(res+2+i) = '0'; + for (i = 0; i < zeros; i++) + *(res + 2 + i) = '0'; _tcscat(res, szVal); return res; @@ -88,7 +88,7 @@ static TCHAR *parseMul(ARGUMENTSINFO *ai) return NULL; int result = ttoi(ai->targv[1]); - for (unsigned i=2; i < ai->argc; i++) + for (unsigned i = 2; i < ai->argc; i++) result *= ttoi(ai->targv[i]); return itot(result); @@ -102,7 +102,7 @@ static TCHAR *parseMuldiv(ARGUMENTSINFO *ai) if (ttoi(ai->targv[3]) == 0) return NULL; - return itot((ttoi(ai->targv[1])*ttoi(ai->targv[2]))/ttoi(ai->targv[3])); + return itot((ttoi(ai->targv[1])*ttoi(ai->targv[2])) / ttoi(ai->targv[3])); } static TCHAR *parseMin(ARGUMENTSINFO *ai) @@ -111,7 +111,7 @@ static TCHAR *parseMin(ARGUMENTSINFO *ai) return NULL; int minVal = ttoi(ai->targv[1]); - for (unsigned i=2; i < ai->argc; i++) + for (unsigned i = 2; i < ai->argc; i++) minVal = min(ttoi(ai->targv[i]), minVal); return itot(minVal); @@ -123,7 +123,7 @@ static TCHAR *parseMax(ARGUMENTSINFO *ai) return NULL; int maxVal = ttoi(ai->targv[1]); - for (unsigned i=2; i < ai->argc; i++) + for (unsigned i = 2; i < ai->argc; i++) maxVal = max(ttoi(ai->targv[i]), maxVal); return itot(maxVal); @@ -147,7 +147,7 @@ static TCHAR *parseNum(ARGUMENTSINFO *ai) ZeroMemory(res, (zeros + _tcslen(szVal) + 1)*sizeof(TCHAR)); TCHAR *cur = res; - for (unsigned i=0; i < zeros; i++) + for (unsigned i = 0; i < zeros; i++) *cur++ = '0'; _tcscat(res, szVal); @@ -167,7 +167,7 @@ static TCHAR *parseSub(ARGUMENTSINFO *ai) return NULL; int result = ttoi(ai->targv[1]); - for (unsigned i=2;iargc;i++) + for (unsigned i = 2; i < ai->argc; i++) result -= ttoi(ai->targv[i]); return itot(result); @@ -176,14 +176,14 @@ static TCHAR *parseSub(ARGUMENTSINFO *ai) int registerMathTokens() { registerIntToken(_T(ADD), parseAdd, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y ,...)\t"LPGEN("x + y + ...")); - registerIntToken(_T(DIV), parseDiv, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("x divided by y")); - registerIntToken(_T(HEX), parseHex, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("converts decimal value x to hex value and padds to length y")); + registerIntToken(_T(DIV), parseDiv, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("x divided by y")); + registerIntToken(_T(HEX), parseHex, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("converts decimal value x to hex value and padds to length y")); registerIntToken(_T(MOD), parseMod, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("x modulo y (remainder of x divided by y)")); - registerIntToken(_T(MUL), parseMul, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("x times y")); + registerIntToken(_T(MUL), parseMul, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("x times y")); registerIntToken(_T(MULDIV), parseMuldiv, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y,z)\t"LPGEN("x times y divided by z")); - registerIntToken(_T(MIN), parseMin, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y,...)\t"LPGEN("minimum value of (decimal) arguments")); - registerIntToken(_T(MAX), parseMax, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y,...)\t"LPGEN("maximum value of (decimal) arguments")); - registerIntToken(_T(NUM), parseNum, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("pads decimal value x to length y with zeros")); + registerIntToken(_T(MIN), parseMin, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y,...)\t"LPGEN("minimum value of (decimal) arguments")); + registerIntToken(_T(MAX), parseMax, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y,...)\t"LPGEN("maximum value of (decimal) arguments")); + registerIntToken(_T(NUM), parseNum, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y)\t"LPGEN("pads decimal value x to length y with zeros")); registerIntToken(_T(RAND), parseRand, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t()\t"LPGEN("random number")); registerIntToken(_T(SUB), parseSub, TRF_FUNCTION, LPGEN("Mathematical Functions")"\t(x,y,...)\t"LPGEN("x - y - ...")); srand((unsigned int)GetTickCount()); diff --git a/plugins/Variables/src/parse_math.h b/plugins/Variables/src/parse_math.h index d24cc31a62..f11bca68fc 100644 --- a/plugins/Variables/src/parse_math.h +++ b/plugins/Variables/src/parse_math.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_metacontacts.cpp b/plugins/Variables/src/parse_metacontacts.cpp index e20c2833cf..4312d100d3 100644 --- a/plugins/Variables/src/parse_metacontacts.cpp +++ b/plugins/Variables/src/parse_metacontacts.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -19,7 +19,7 @@ #include "variables.h" -static TCHAR *parseGetParent(ARGUMENTSINFO *ai) +static TCHAR *parseGetParent(ARGUMENTSINFO *ai) { if (ai->argc != 2) return NULL; @@ -30,14 +30,13 @@ static TCHAR *parseGetParent(ARGUMENTSINFO *ai) ci.cbSize = sizeof(ci); ci.tszContact = ai->targv[1]; ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString( &ci ); + 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); + mir_free(ci.hContacts); return NULL; } @@ -50,8 +49,7 @@ static TCHAR *parseGetParent(ARGUMENTSINFO *ai) if (szProto != NULL) szUniqueID = getContactInfoT(CNF_UNIQUEID, hContact); - if (szUniqueID == NULL) - { + if (szUniqueID == NULL) { szProto = PROTOID_HANDLE; szUniqueID = (TCHAR *)mir_alloc(32); mir_sntprintf(szUniqueID, 32, _T("%p"), hContact); @@ -76,7 +74,7 @@ static TCHAR *parseGetParent(ARGUMENTSINFO *ai) return res; } -static TCHAR *parseGetDefault(ARGUMENTSINFO *ai) +static TCHAR *parseGetDefault(ARGUMENTSINFO *ai) { if (ai->argc != 2) return NULL; @@ -87,14 +85,13 @@ static TCHAR *parseGetDefault(ARGUMENTSINFO *ai) ci.cbSize = sizeof(ci); ci.tszContact = ai->targv[1]; ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString( &ci ); + 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); + mir_free(ci.hContacts); return NULL; } @@ -132,7 +129,7 @@ static TCHAR *parseGetDefault(ARGUMENTSINFO *ai) return res; } -static TCHAR *parseGetMostOnline(ARGUMENTSINFO *ai) +static TCHAR *parseGetMostOnline(ARGUMENTSINFO *ai) { if (ai->argc != 2) return NULL; @@ -143,14 +140,13 @@ static TCHAR *parseGetMostOnline(ARGUMENTSINFO *ai) ci.cbSize = sizeof(ci); ci.tszContact = ai->targv[1]; ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString( &ci ); + int count = getContactFromString(&ci); if (count == 1 && ci.hContacts != NULL) { hContact = ci.hContacts[0]; - mir_free( ci.hContacts ); + mir_free(ci.hContacts); } else { - if (ci.hContacts != NULL) - mir_free( ci.hContacts ); + mir_free(ci.hContacts); return NULL; } @@ -188,12 +184,12 @@ static TCHAR *parseGetMostOnline(ARGUMENTSINFO *ai) return res; } -int registerMetaContactsTokens() +int registerMetaContactsTokens() { - if (ServiceExists( MS_MC_GETPROTOCOLNAME )) { - registerIntToken( _T(MC_GETPARENT), parseGetParent, TRF_FUNCTION, LPGEN("MetaContacts")"\t(x)\t"LPGEN("get parent metacontact of contact x")); - registerIntToken( _T(MC_GETDEFAULT), parseGetDefault, TRF_FUNCTION, LPGEN("MetaContacts")"\t(x)\t"LPGEN("get default subcontact x")); - registerIntToken( _T(MC_GETMOSTONLINE), parseGetMostOnline, TRF_FUNCTION, LPGEN("MetaContacts")"\t(x)\t"LPGEN("get the 'most online' subcontact x")); + if (ServiceExists(MS_MC_GETPROTOCOLNAME)) { + registerIntToken(_T(MC_GETPARENT), parseGetParent, TRF_FUNCTION, LPGEN("MetaContacts")"\t(x)\t"LPGEN("get parent metacontact of contact x")); + registerIntToken(_T(MC_GETDEFAULT), parseGetDefault, TRF_FUNCTION, LPGEN("MetaContacts")"\t(x)\t"LPGEN("get default subcontact x")); + registerIntToken(_T(MC_GETMOSTONLINE), parseGetMostOnline, TRF_FUNCTION, LPGEN("MetaContacts")"\t(x)\t"LPGEN("get the 'most online' subcontact x")); } return 0; diff --git a/plugins/Variables/src/parse_metacontacts.h b/plugins/Variables/src/parse_metacontacts.h index 8015d40413..d808213915 100644 --- a/plugins/Variables/src/parse_metacontacts.h +++ b/plugins/Variables/src/parse_metacontacts.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp index d22b206534..b87dd9a500 100644 --- a/plugins/Variables/src/parse_miranda.cpp +++ b/plugins/Variables/src/parse_miranda.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -35,33 +35,33 @@ static TCHAR* parseCodeToStatus(ARGUMENTSINFO *ai) static int getContactInfoFlags(TCHAR *tszDesc) { int flags = 0; - for (TCHAR *cur=tszDesc;(cur < (tszDesc+_tcslen(tszDesc))); cur++) { + for (TCHAR *cur = tszDesc; (cur < (tszDesc + _tcslen(tszDesc))); cur++) { if (!_tcsnicmp(cur, _T(STR_PROTOID), _tcslen(_T(STR_PROTOID)))) { - flags|=CI_PROTOID; + flags |= CI_PROTOID; cur += _tcslen(_T(STR_PROTOID)) - 1; } else if (!_tcsnicmp(cur, _T(STR_NICK), _tcslen(_T(STR_NICK)))) { - flags|=CI_NICK; + flags |= CI_NICK; cur += _tcslen(_T(STR_NICK)) - 1; } else if (!_tcsnicmp(cur, _T(STR_FIRSTNAME), _tcslen(_T(STR_FIRSTNAME)))) { - flags|=CI_FIRSTNAME; + flags |= CI_FIRSTNAME; cur += _tcslen(_T(STR_FIRSTNAME)) - 1; } else if (!_tcsnicmp(cur, _T(STR_LASTNAME), _tcslen(_T(STR_LASTNAME)))) { - flags|=CI_LASTNAME; + flags |= CI_LASTNAME; cur += _tcslen(_T(STR_LASTNAME)) - 1; } else if (!_tcsnicmp(cur, _T(STR_DISPLAY), _tcslen(_T(STR_DISPLAY)))) { - flags|=CI_LISTNAME; + flags |= CI_LISTNAME; cur += _tcslen(_T(STR_DISPLAY)) - 1; } else if (!_tcsnicmp(cur, _T(STR_EMAIL), _tcslen(_T(STR_EMAIL)))) { - flags|=CI_EMAIL; + flags |= CI_EMAIL; cur += _tcslen(_T(STR_EMAIL)) - 1; } else if (!_tcsnicmp(cur, _T(STR_UNIQUEID), _tcslen(_T(STR_UNIQUEID)))) { - flags|=CI_UNIQUEID; + flags |= CI_UNIQUEID; cur += _tcslen(_T(STR_UNIQUEID)) - 1; } } @@ -77,7 +77,7 @@ static int getContactInfoFlags(TCHAR *tszDesc) static TCHAR* parseContact(ARGUMENTSINFO *ai) { - if (ai->argc < 3 || ai->argc > 4 ) + if (ai->argc < 3 || ai->argc > 4) return NULL; int n = 0; @@ -88,14 +88,14 @@ static TCHAR* parseContact(ARGUMENTSINFO *ai) ci.cbSize = sizeof(ci); ci.tszContact = ai->targv[1]; ci.flags = getContactInfoFlags(ai->targv[2]); - int count = getContactFromString( &ci ); + int count = getContactFromString(&ci); if (count == 0 || ci.hContacts == NULL) return NULL; if (ai->argc == 4 && *ai->targv[3] == 'r') n = rand() % count; - if (count != 1 && ai->argc != 4 ) { + if (count != 1 && ai->argc != 4) { mir_free(ci.hContacts); return NULL; } @@ -115,7 +115,7 @@ static TCHAR* parseContactCount(ARGUMENTSINFO *ai) ci.cbSize = sizeof(ci); ci.tszContact = ai->targv[1]; ci.flags = getContactInfoFlags(ai->targv[2]); - int count = getContactFromString( &ci ); + int count = getContactFromString(&ci); if (count != 0 && ci.hContacts != NULL) mir_free(ci.hContacts); @@ -132,7 +132,7 @@ static TCHAR* parseContactInfo(ARGUMENTSINFO *ai) ci.cbSize = sizeof(ci); ci.tszContact = ai->targv[1]; ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString( &ci ); + int count = getContactFromString(&ci); if (count == 1 && ci.hContacts != NULL) { hContact = ci.hContacts[0]; mir_free(ci.hContacts); @@ -168,7 +168,7 @@ static TCHAR* parseDBProfilePath(ARGUMENTSINFO *ai) TCHAR path[MAX_PATH]; if (CallService(MS_DB_GETPROFILEPATHT, SIZEOF(path), (LPARAM)path)) return NULL; - + return mir_tstrdup(path); } @@ -211,13 +211,13 @@ static TCHAR* parseDBSetting(ARGUMENTSINFO *ai) TCHAR *res = NULL, *szDefaultValue = NULL; HANDLE hContact = NULL; - - if ( _tcslen(ai->targv[1]) > 0) { + + if (_tcslen(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 ); + 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); @@ -251,15 +251,14 @@ static TCHAR* parseLastSeenDate(ARGUMENTSINFO *ai) 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 ); + 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); + mir_free(ci.hContacts); return NULL; } @@ -284,7 +283,7 @@ static TCHAR* parseLastSeenDate(ARGUMENTSINFO *ai) lsTime.wMonth = db_get_w(hContact, szModule, "Month", 0); int len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &lsTime, szFormat, NULL, 0); - TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; @@ -306,8 +305,8 @@ static TCHAR* parseLastSeenTime(ARGUMENTSINFO *ai) 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 ); + 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); @@ -339,7 +338,7 @@ static TCHAR* parseLastSeenTime(ARGUMENTSINFO *ai) lsTime.wYear = db_get_w(hContact, szModule, "Year", 0); int len = GetTimeFormat(LOCALE_USER_DEFAULT, 0, &lsTime, szFormat, NULL, 0); - TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; @@ -360,8 +359,8 @@ static TCHAR* parseLastSeenStatus(ARGUMENTSINFO *ai) 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 ); + 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); @@ -404,7 +403,7 @@ static TCHAR* parseMyStatus(ARGUMENTSINFO *ai) if (ai->argc == 1 || _tcslen(ai->targv[1]) == 0) status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0); else - status = CallProtoService( _T2A(ai->targv[1]), PS_GETSTATUS, 0, 0); + status = CallProtoService(_T2A(ai->targv[1]), PS_GETSTATUS, 0, 0); TCHAR *szStatus = (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)status, GSMDF_UNICODE); if (szStatus != NULL) @@ -490,14 +489,14 @@ static BOOL isValidDbEvent(DBEVENTINFO *dbe, int flags) BOOL bEventType, bEventFlags; bEventType = ((dbe->eventType == EVENTTYPE_MESSAGE) && (flags & DBE_MESSAGE)) || - ((dbe->eventType == EVENTTYPE_URL) && (flags & DBE_URL)) || - ((dbe->eventType == EVENTTYPE_CONTACTS) && (flags & DBE_CONTACTS)) || - ((dbe->eventType == EVENTTYPE_ADDED) && (flags & DBE_ADDED)) || - ((dbe->eventType == EVENTTYPE_AUTHREQUEST) && (flags & DBE_AUTHREQUEST)) || - ((dbe->eventType == EVENTTYPE_FILE) && (flags & DBE_FILE)) || - ((flags & DBE_OTHER)); - bEventFlags = (dbe->flags&DBEF_SENT)?(flags&DBE_SENT):(flags&DBE_RCVD); - bEventFlags = (bEventFlags && ((dbe->flags&DBEF_READ)?(flags&DBE_READ):(flags&DBE_UNREAD))); + ((dbe->eventType == EVENTTYPE_URL) && (flags & DBE_URL)) || + ((dbe->eventType == EVENTTYPE_CONTACTS) && (flags & DBE_CONTACTS)) || + ((dbe->eventType == EVENTTYPE_ADDED) && (flags & DBE_ADDED)) || + ((dbe->eventType == EVENTTYPE_AUTHREQUEST) && (flags & DBE_AUTHREQUEST)) || + ((dbe->eventType == EVENTTYPE_FILE) && (flags & DBE_FILE)) || + ((flags & DBE_OTHER)); + bEventFlags = (dbe->flags&DBEF_SENT) ? (flags&DBE_SENT) : (flags&DBE_RCVD); + bEventFlags = (bEventFlags && ((dbe->flags&DBEF_READ) ? (flags&DBE_READ) : (flags&DBE_UNREAD))); return (bEventType && bEventFlags); } @@ -609,7 +608,7 @@ static HANDLE findDbEvent(HANDLE hContact, HANDLE hDbEvent, int flags) } } } - while ( (!bEventOk) && (hDbEvent != NULL)); + while ((!bEventOk) && (hDbEvent != NULL)); return hDbEvent; } @@ -637,7 +636,7 @@ static TCHAR* parseDbEvent(ARGUMENTSINFO *ai) flags |= DBE_RCVD; break; default: - flags |= DBE_RCVD|DBE_SENT; + flags |= DBE_RCVD | DBE_SENT; break; } switch (*ai->targv[4]) { @@ -648,17 +647,17 @@ static TCHAR* parseDbEvent(ARGUMENTSINFO *ai) flags |= DBE_UNREAD; break; default: - flags |= DBE_READ|DBE_UNREAD; + flags |= DBE_READ | DBE_UNREAD; break; } - + HANDLE 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 ); + 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); @@ -707,31 +706,31 @@ static TCHAR* parseVersionString(ARGUMENTSINFO *ai) static TCHAR *parseContactNameString(ARGUMENTSINFO *ai) { - if (ai->argc != 1 || ai->fi->hContact == NULL) - return NULL; - - ai->flags |= AIF_DONTPARSE; - TCHAR *ret = (TCHAR*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) ai->fi->hContact, GCDNF_TCHAR); - if (ret == NULL) - return NULL; + if (ai->argc != 1 || ai->fi->hContact == NULL) + return NULL; + + ai->flags |= AIF_DONTPARSE; + TCHAR *ret = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ai->fi->hContact, GCDNF_TCHAR); + if (ret == NULL) + return NULL; return mir_tstrdup(ret); } static TCHAR *parseMirDateString(ARGUMENTSINFO *ai) { - if (ai->argc != 1) - return NULL; + if (ai->argc != 1) + return NULL; - ai->flags |= AIF_DONTPARSE; + ai->flags |= AIF_DONTPARSE; - TCHAR ret[128]; - DBTIMETOSTRINGT tst = {0}; - tst.szFormat = _T("d s"); - tst.szDest = ret; - tst.cbDest = 128; - if (CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM) time(NULL), (LPARAM) &tst)) - return NULL; + TCHAR ret[128]; + DBTIMETOSTRINGT tst = { 0 }; + tst.szFormat = _T("d s"); + tst.szDest = ret; + tst.cbDest = 128; + if (CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)time(NULL), (LPARAM)&tst)) + return NULL; return mir_tstrdup(ret); } @@ -744,36 +743,37 @@ static TCHAR *parseMirandaCoreVar(ARGUMENTSINFO *ai) ai->flags |= AIF_DONTPARSE; TCHAR corevar[MAX_PATH]; - mir_sntprintf(corevar, MAX_PATH,_T("%%%s%%"), ai->targv[0]); + mir_sntprintf(corevar, MAX_PATH, _T("%%%s%%"), ai->targv[0]); return Utils_ReplaceVarsT(corevar); } static TCHAR *parseMirSrvExists(ARGUMENTSINFO *ai) { - if (ai->argc != 2 ) + if (ai->argc != 2) return NULL; - if (!ServiceExists( _T2A( ai->targv[1] ))) + if (!ServiceExists(_T2A(ai->targv[1]))) ai->flags |= AIF_FALSE; return mir_tstrdup(_T("")); } -int registerMirandaTokens() { +int registerMirandaTokens() +{ if (ServiceExists(MS_UTILS_REPLACEVARS)) { // global vars - registerIntToken(_T("miranda_path"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("path to Miranda root folder")); - registerIntToken(_T("miranda_profile"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("path to current Miranda profile")); - registerIntToken(_T("miranda_profilename"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("name of current Miranda profile (filename, without extension)")); - registerIntToken(_T("miranda_userdata"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("will return parsed string %miranda_profile%\\Profiles\\%miranda_profilename%")); - registerIntToken(_T("miranda_avatarcache"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("will return parsed string %miranda_profile%\\Profiles\\%miranda_profilename%\\AvatarCache")); - registerIntToken(_T("miranda_logpath"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("will return parsed string %miranda_profile%\\Profiles\\%miranda_profilename%\\Logs")); + registerIntToken(_T("miranda_path"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("path to Miranda root folder")); + registerIntToken(_T("miranda_profile"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("path to current Miranda profile")); + registerIntToken(_T("miranda_profilename"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("name of current Miranda profile (filename, without extension)")); + registerIntToken(_T("miranda_userdata"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("will return parsed string %miranda_profile%\\Profiles\\%miranda_profilename%")); + registerIntToken(_T("miranda_avatarcache"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("will return parsed string %miranda_profile%\\Profiles\\%miranda_profilename%\\AvatarCache")); + registerIntToken(_T("miranda_logpath"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core Global")"\t"LPGEN("will return parsed string %miranda_profile%\\Profiles\\%miranda_profilename%\\Logs")); // OS vars - registerIntToken(_T("appdata"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core OS")"\t"LPGEN("same as environment variable %APPDATA% for currently logged-on Windows user")); - registerIntToken(_T("username"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core OS")"\t"LPGEN("username for currently logged-on Windows user")); - registerIntToken(_T("mydocuments"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core OS")"\t"LPGEN("\"My Documents\" folder for currently logged-on Windows user")); - registerIntToken(_T("desktop"), parseMirandaCoreVar , TRF_FIELD, LPGEN("Miranda Core OS")"\t"LPGEN("\"Desktop\" folder for currently logged-on Windows user")); + registerIntToken(_T("appdata"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core OS")"\t"LPGEN("same as environment variable %APPDATA% for currently logged-on Windows user")); + registerIntToken(_T("username"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core OS")"\t"LPGEN("username for currently logged-on Windows user")); + registerIntToken(_T("mydocuments"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core OS")"\t"LPGEN("\"My Documents\" folder for currently logged-on Windows user")); + registerIntToken(_T("desktop"), parseMirandaCoreVar, TRF_FIELD, LPGEN("Miranda Core OS")"\t"LPGEN("\"Desktop\" folder for currently logged-on Windows user")); } registerIntToken(_T(CODETOSTATUS), parseCodeToStatus, TRF_FUNCTION, LPGEN("Miranda Related")"\t(x)\t"LPGEN("translates status code x into a status description")); registerIntToken(_T(CONTACT), parseContact, TRF_FUNCTION, LPGEN("Miranda Related")"\t(x,y,z)\t"LPGEN("zth contact with property y described by x, example: (unregistered,nick) (z is optional)")); @@ -794,7 +794,7 @@ int registerMirandaTokens() { registerIntToken(_T(VERSIONSTRING), parseVersionString, TRF_FIELD, LPGEN("Miranda Related")"\t"LPGEN("get the version of Miranda")); registerIntToken(_T(CONTACT_NAME), parseContactNameString, TRF_FIELD, LPGEN("Miranda Related")"\t"LPGEN("get the contact display name")); registerIntToken(_T(MIR_DATE), parseMirDateString, TRF_FIELD, LPGEN("Miranda Related")"\t"LPGEN("get the date and time (using Miranda format)")); - registerIntToken(_T(SRVEXISTS), parseMirSrvExists, TRF_FUNCTION, LPGEN("Miranda Related")"\t(x)\t"LPGEN("TRUE if service function exists")); + registerIntToken(_T(SRVEXISTS), parseMirSrvExists, TRF_FUNCTION, LPGEN("Miranda Related")"\t(x)\t"LPGEN("TRUE if service function exists")); return 0; } diff --git a/plugins/Variables/src/parse_miranda.h b/plugins/Variables/src/parse_miranda.h index d945e93ce8..6e4485d8cc 100644 --- a/plugins/Variables/src/parse_miranda.h +++ b/plugins/Variables/src/parse_miranda.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_regexp.cpp b/plugins/Variables/src/parse_regexp.cpp index 2792cf05e5..7f5bff1925 100644 --- a/plugins/Variables/src/parse_regexp.cpp +++ b/plugins/Variables/src/parse_regexp.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -34,8 +34,8 @@ static TCHAR *parseRegExpCheck(ARGUMENTSINFO *ai) ai->flags = AIF_FALSE; - ptrA arg1( mir_t2a(ai->targv[1])); - ptrA arg2( mir_t2a(ai->targv[2])); + ptrA arg1(mir_t2a(ai->targv[1])); + ptrA arg2(mir_t2a(ai->targv[2])); pcre *ppat = pcre_compile(arg1, 0, &err, &erroffset, NULL); if (ppat == NULL) @@ -54,7 +54,7 @@ static TCHAR *parseRegExpCheck(ARGUMENTSINFO *ai) /* pattern, subject, substring no (== PCRE string no (starting at 0)) -*/ + */ static TCHAR *parseRegExpSubstr(ARGUMENTSINFO *ai) { const char *err, *substring; @@ -64,15 +64,15 @@ static TCHAR *parseRegExpSubstr(ARGUMENTSINFO *ai) if (ai->argc != 4) return NULL; - ptrA arg1( mir_t2a(ai->targv[1])); - ptrA arg2( mir_t2a(ai->targv[2])); - ptrA arg3( mir_t2a(ai->targv[3])); + ptrA arg1(mir_t2a(ai->targv[1])); + ptrA arg2(mir_t2a(ai->targv[2])); + ptrA arg3(mir_t2a(ai->targv[3])); number = atoi(arg3); if (number < 0) return NULL; - ai->flags = AIF_FALSE; + ai->flags = AIF_FALSE; pcre *ppat = pcre_compile(arg1, 0, &err, &erroffset, NULL); if (ppat == NULL) return NULL; diff --git a/plugins/Variables/src/parse_regexp.h b/plugins/Variables/src/parse_regexp.h index 28183e7f79..6844dd4036 100644 --- a/plugins/Variables/src/parse_regexp.h +++ b/plugins/Variables/src/parse_regexp.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_str.cpp b/plugins/Variables/src/parse_str.cpp index 002c02d99d..a92e54a6cc 100644 --- a/plugins/Variables/src/parse_str.cpp +++ b/plugins/Variables/src/parse_str.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -30,7 +30,7 @@ static TCHAR *parseCaps(ARGUMENTSINFO *ai) *cur = (TCHAR)CharUpper((LPTSTR)*cur); cur++; while (*cur != 0) { - if ((*cur == ' ') && (*(cur+1) != 0)) { + if ((*cur == ' ') && (*(cur + 1) != 0)) { cur++; if (IsCharLower(*cur)) *cur = (TCHAR)CharUpper((LPTSTR)*cur); @@ -54,7 +54,7 @@ static TCHAR *parseCaps2(ARGUMENTSINFO *ai) *cur = (TCHAR)CharUpper((LPTSTR)*cur); cur++; while (*cur != 0) { - if ((*cur == ' ') && (*(cur+1) != 0)) { + if ((*cur == ' ') && (*(cur + 1) != 0)) { cur++; if (IsCharLower(*cur)) *cur = (TCHAR)CharUpper((LPTSTR)*cur); @@ -79,18 +79,18 @@ static TCHAR *parseEolToCrlf(ARGUMENTSINFO *ai) TCHAR *cur = res; do { cur = _tcschr(cur, '\n'); - if ((cur == NULL) || ((cur > res) && (*(cur-1) == '\r'))) + if ((cur == NULL) || ((cur > res) && (*(cur - 1) == '\r'))) continue; - + log_debug(cur); int loc = cur - res; - res = (TCHAR*)mir_realloc(res, (_tcslen(res)+2)*sizeof(TCHAR)); + res = (TCHAR*)mir_realloc(res, (_tcslen(res) + 2)*sizeof(TCHAR)); cur = res + loc; - MoveMemory(cur+2, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR)); - CopyMemory(cur, _T("\r\n"), 2*sizeof(TCHAR)); + MoveMemory(cur + 2, cur + 1, (_tcslen(cur + 1) + 1)*sizeof(TCHAR)); + CopyMemory(cur, _T("\r\n"), 2 * sizeof(TCHAR)); cur += 2; } - while (cur != NULL); + while (cur != NULL); return res; } @@ -106,19 +106,19 @@ static TCHAR *parseFixeol(ARGUMENTSINFO *ai) return NULL; TCHAR *cur = ai->targv[1]; - while ( _tcscmp(cur, _T("\r\n")) && *cur != '\n' && *cur != 0) + while (_tcscmp(cur, _T("\r\n")) && *cur != '\n' && *cur != 0) cur++; if (*cur == '\0') return mir_tstrdup(ai->targv[1]); cur--; - TCHAR *res = (TCHAR*)mir_alloc((cur-ai->targv[1] + _tcslen(szReplacement) + 1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((cur - ai->targv[1] + _tcslen(szReplacement) + 1)*sizeof(TCHAR)); if (res == NULL) return res; ZeroMemory(res, ((cur - ai->targv[1]) + 1)*sizeof(TCHAR)); - _tcsncpy(res, ai->targv[1], cur-ai->targv[1]); + _tcsncpy(res, ai->targv[1], cur - ai->targv[1]); _tcscat(res, szReplacement); return res; } @@ -126,15 +126,15 @@ static TCHAR *parseFixeol(ARGUMENTSINFO *ai) static TCHAR *parseFixeol2(ARGUMENTSINFO *ai) { TCHAR *szReplacement; - switch( ai->argc ) { - case 2: szReplacement = _T(" "); break; - case 3: szReplacement = ai->targv[2]; break; - default: return NULL; + switch (ai->argc) { + case 2: szReplacement = _T(" "); break; + case 3: szReplacement = ai->targv[2]; break; + default: return NULL; } TCHAR *res = mir_tstrdup(ai->targv[1]); - for (size_t pos=0; pos < _tcslen(res); pos++ ) { - TCHAR *cur = res+pos; + for (size_t pos = 0; pos < _tcslen(res); pos++) { + TCHAR *cur = res + pos; TCHAR *szEol = NULL; if (!_tcsncmp(cur, _T("\r\n"), _tcslen(_T("\r\n")))) szEol = _T("\r\n"); @@ -143,16 +143,16 @@ static TCHAR *parseFixeol2(ARGUMENTSINFO *ai) szEol = _T("\n"); if (szEol != NULL) { - if ( _tcslen(szReplacement) > _tcslen(szEol)) { + if (_tcslen(szReplacement) > _tcslen(szEol)) { res = (TCHAR*)mir_realloc(res, (_tcslen(res) + _tcslen(szReplacement) - _tcslen(szEol) + 1)*sizeof(TCHAR)); - cur = res+pos; + cur = res + pos; } - MoveMemory(cur+_tcslen(szReplacement), cur+_tcslen(szEol), (_tcslen(cur+_tcslen(szEol))+1)*sizeof(TCHAR)); + MoveMemory(cur + _tcslen(szReplacement), cur + _tcslen(szEol), (_tcslen(cur + _tcslen(szEol)) + 1)*sizeof(TCHAR)); CopyMemory(cur, szReplacement, _tcslen(szReplacement)*sizeof(TCHAR)); pos += _tcslen(szReplacement) - 1; } } - return (TCHAR*)mir_realloc(res, (_tcslen(res)+1)*sizeof(TCHAR)); + return (TCHAR*)mir_realloc(res, (_tcslen(res) + 1)*sizeof(TCHAR)); } static TCHAR *parseInsert(ARGUMENTSINFO *ai) @@ -171,7 +171,7 @@ static TCHAR *parseInsert(ARGUMENTSINFO *ai) ZeroMemory(res, (_tcslen(ai->targv[1]) + _tcslen(ai->targv[2]) + 1)*sizeof(TCHAR)); _tcsncpy(res, ai->targv[1], pos); _tcscpy(res + pos, ai->targv[2]); - _tcscpy(res+pos+_tcslen(ai->targv[2]), ai->targv[1]+pos); + _tcscpy(res + pos + _tcslen(ai->targv[2]), ai->targv[1] + pos); return res; } @@ -189,7 +189,7 @@ static TCHAR *parseLeft(ARGUMENTSINFO *ai) if (res == NULL) return NULL; - ZeroMemory(res, (len+1)*sizeof(TCHAR)); + ZeroMemory(res, (len + 1)*sizeof(TCHAR)); _tcsncpy(res, ai->targv[1], len); return res; } @@ -199,7 +199,7 @@ static TCHAR *parseLen(ARGUMENTSINFO *ai) if (ai->argc != 2) return NULL; - return itot((int)_tcslen( ai->targv[1] )); + return itot((int)_tcslen(ai->targv[1])); } static TCHAR *parseLineCount(ARGUMENTSINFO *ai) @@ -231,7 +231,7 @@ static TCHAR *parseLower(ARGUMENTSINFO *ai) TCHAR *res = mir_tstrdup(ai->targv[1]); if (res == NULL) return NULL; - + return CharLower(res); } @@ -241,28 +241,28 @@ static TCHAR *parseLongest(ARGUMENTSINFO *ai) return NULL; unsigned int iLong = 1; - for (unsigned int i=2; i < ai->argc; i++) - if ( _tcslen(ai->targv[i]) > _tcslen(ai->targv[iLong])) - iLong = i; + for (unsigned int i = 2; i < ai->argc; i++) + if (_tcslen(ai->targv[i]) > _tcslen(ai->targv[iLong])) + iLong = i; - return mir_tstrdup( ai->targv[iLong] ); + return mir_tstrdup(ai->targv[iLong]); } static TCHAR *parseNoOp(ARGUMENTSINFO *ai) { if (ai->argc != 2) return NULL; - - return mir_tstrdup( ai->targv[1] ); + + return mir_tstrdup(ai->targv[1]); } static TCHAR *parsePad(ARGUMENTSINFO *ai) { TCHAR padchar; - switch( ai->argc ) { - case 3: padchar = ' '; break; - case 4: padchar = *ai->targv[3]; break; - default: return NULL; + switch (ai->argc) { + case 3: padchar = ' '; break; + case 4: padchar = *ai->targv[3]; break; + default: return NULL; } int padding = ttoi(ai->targv[2]); @@ -276,20 +276,20 @@ static TCHAR *parsePad(ARGUMENTSINFO *ai) ZeroMemory(res, (addcount + _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR)); TCHAR *cur = res; - for ( unsigned int i=0; i < addcount; i++ ) + for (unsigned int i = 0; i < addcount; i++) *cur++ = padchar; _tcscat(res, ai->targv[1]); return res; } - + static TCHAR *parsePadright(ARGUMENTSINFO *ai) { TCHAR padchar; - switch (ai->argc ) { - case 3: padchar = ' '; break; - case 4: padchar = *ai->targv[3]; break; - default: return NULL; + switch (ai->argc) { + case 3: padchar = ' '; break; + case 4: padchar = *ai->targv[3]; break; + default: return NULL; } int padding = ttoi(ai->targv[2]); @@ -304,19 +304,19 @@ static TCHAR *parsePadright(ARGUMENTSINFO *ai) ZeroMemory(res, (addcount + _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR)); _tcscpy(res, ai->targv[1]); TCHAR *cur = res + _tcslen(ai->targv[1]); - for (unsigned int i=0; i < addcount; i++) + for (unsigned int i = 0; i < addcount; i++) *cur++ = padchar; - + return res; } static TCHAR *parsePadcut(ARGUMENTSINFO *ai) { TCHAR padchar; - switch( ai->argc ) { - case 3: padchar = ' '; break; - case 4: padchar = *ai->targv[3]; break; - default: return NULL; + switch (ai->argc) { + case 3: padchar = ' '; break; + case 4: padchar = *ai->targv[3]; break; + default: return NULL; } int padding = ttoi(ai->targv[2]); @@ -330,22 +330,22 @@ static TCHAR *parsePadcut(ARGUMENTSINFO *ai) ZeroMemory(res, (padding + 1)*sizeof(TCHAR)); TCHAR *cur = res; - for (int i=0; i < addcount; i++) + for (int i = 0; i < addcount; i++) *cur++ = padchar; if (padding > addcount) - _tcsncpy(res+addcount, ai->targv[1], padding-addcount); - + _tcsncpy(res + addcount, ai->targv[1], padding - addcount); + return res; } static TCHAR *parsePadcutright(ARGUMENTSINFO *ai) { TCHAR padchar; - switch( ai->argc ) { - case 3: padchar = ' '; break; - case 4: padchar = *ai->targv[3]; break; - default: return NULL; + switch (ai->argc) { + case 3: padchar = ' '; break; + case 4: padchar = *ai->targv[3]; break; + default: return NULL; } int padding = ttoi(ai->targv[2]); @@ -359,11 +359,11 @@ static TCHAR *parsePadcutright(ARGUMENTSINFO *ai) ZeroMemory(res, (padding + 1)*sizeof(TCHAR)); TCHAR *cur = res + padding - addcount; - for (int i=0; i < addcount; i++ ) + for (int i = 0; i < addcount; i++) *cur++ = padchar; - if (padding > addcount ) - _tcsncpy(res, ai->targv[1], padding-addcount); + if (padding > addcount) + _tcsncpy(res, ai->targv[1], padding - addcount); return res; } @@ -382,7 +382,7 @@ static TCHAR *parseRepeat(ARGUMENTSINFO *ai) return NULL; ZeroMemory(res, (count * _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR)); - for (int i=0; i < count; i++) + for (int i = 0; i < count; i++) _tcscat(res, ai->targv[1]); return res; @@ -390,30 +390,30 @@ static TCHAR *parseRepeat(ARGUMENTSINFO *ai) static TCHAR *parseReplace(ARGUMENTSINFO *ai) { - if ((ai->argc < 4) || (ai->argc%2 != 0)) + if ((ai->argc < 4) || (ai->argc % 2 != 0)) return NULL; TCHAR *cur; size_t pos = 0; TCHAR *res = mir_tstrdup(ai->targv[1]); - for (size_t i=2; i < ai->argc; i += 2) { - if ( _tcslen(ai->targv[i]) == 0) + for (size_t i = 2; i < ai->argc; i += 2) { + if (_tcslen(ai->targv[i]) == 0) continue; - for (pos=0;pos<_tcslen(res);pos++) { - cur = res+pos; + for (pos = 0; pos<_tcslen(res); pos++) { + cur = res + pos; if (!_tcsncmp(cur, ai->targv[i], _tcslen(ai->targv[i]))) { - if ( _tcslen(ai->targv[i+1]) > _tcslen(ai->targv[i])) { - res = (TCHAR*)mir_realloc(res, (_tcslen(res) + _tcslen(ai->targv[i+1]) - _tcslen(ai->targv[i]) + 1)*sizeof(TCHAR)); - cur = res+pos; + if (_tcslen(ai->targv[i + 1]) > _tcslen(ai->targv[i])) { + res = (TCHAR*)mir_realloc(res, (_tcslen(res) + _tcslen(ai->targv[i + 1]) - _tcslen(ai->targv[i]) + 1)*sizeof(TCHAR)); + cur = res + pos; } - MoveMemory(cur+_tcslen(ai->targv[i+1]), cur+_tcslen(ai->targv[i]), (_tcslen(cur+_tcslen(ai->targv[i]))+1)*sizeof(TCHAR)); - CopyMemory(cur, ai->targv[i+1], _tcslen(ai->targv[i+1])*sizeof(TCHAR)); - pos += _tcslen(ai->targv[i+1]) - 1; + MoveMemory(cur + _tcslen(ai->targv[i + 1]), cur + _tcslen(ai->targv[i]), (_tcslen(cur + _tcslen(ai->targv[i])) + 1)*sizeof(TCHAR)); + CopyMemory(cur, ai->targv[i + 1], _tcslen(ai->targv[i + 1])*sizeof(TCHAR)); + pos += _tcslen(ai->targv[i + 1]) - 1; } } - res = (TCHAR*)mir_realloc(res, (_tcslen(res)+1)*sizeof(TCHAR)); + res = (TCHAR*)mir_realloc(res, (_tcslen(res) + 1)*sizeof(TCHAR)); } return res; @@ -429,44 +429,44 @@ static TCHAR *parseRight(ARGUMENTSINFO *ai) return NULL; len = min(len, (signed int)_tcslen(ai->targv[1])); - TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; - ZeroMemory(res, (len+1)*sizeof(TCHAR)); - _tcsncpy(res, ai->targv[1]+_tcslen(ai->targv[1])-len, len); + ZeroMemory(res, (len + 1)*sizeof(TCHAR)); + _tcsncpy(res, ai->targv[1] + _tcslen(ai->targv[1]) - len, len); return res; } /* - string, display size, scroll amount -*/ + string, display size, scroll amount + */ static TCHAR *parseScroll(ARGUMENTSINFO *ai) { if (ai->argc != 4) return NULL; - if ( _tcslen(ai->targv[1]) == 0) + if (_tcslen(ai->targv[1]) == 0) return mir_tstrdup(ai->targv[1]); - size_t move = ttoi(ai->targv[3])%_tcslen(ai->targv[1]); + size_t move = ttoi(ai->targv[3]) % _tcslen(ai->targv[1]); size_t display = ttoi(ai->targv[2]); if (display > _tcslen(ai->targv[1])) display = (unsigned)_tcslen(ai->targv[1]); - TCHAR *res = (TCHAR*)mir_alloc((2*_tcslen(ai->targv[1])+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((2 * _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; - ZeroMemory(res, (2*_tcslen(ai->targv[1])+1)*sizeof(TCHAR)); + ZeroMemory(res, (2 * _tcslen(ai->targv[1]) + 1)*sizeof(TCHAR)); _tcscpy(res, ai->targv[1]); _tcscat(res, ai->targv[1]); - MoveMemory(res, res+move, (_tcslen(res+move)+1)*sizeof(TCHAR)); - *(res + display) = 0; - res = (TCHAR*)mir_realloc(res, (_tcslen(res)+1)*sizeof(TCHAR)); - + MoveMemory(res, res + move, (_tcslen(res + move) + 1)*sizeof(TCHAR)); + *(res + display) = 0; + res = (TCHAR*)mir_realloc(res, (_tcslen(res) + 1)*sizeof(TCHAR)); + return res; -} +} static TCHAR *parseShortest(ARGUMENTSINFO *ai) { @@ -474,9 +474,9 @@ static TCHAR *parseShortest(ARGUMENTSINFO *ai) return NULL; int iShort = 1; - for (unsigned i=2; i < ai->argc; i++) - if ( _tcslen(ai->targv[i]) < _tcslen(ai->targv[iShort])) - iShort = i; + for (unsigned i = 2; i < ai->argc; i++) + if (_tcslen(ai->targv[i]) < _tcslen(ai->targv[iShort])) + iShort = i; return mir_tstrdup(ai->targv[iShort]); } @@ -492,7 +492,7 @@ static TCHAR *parseStrchr(ARGUMENTSINFO *ai) if (c == NULL || *c == 0) return mir_tstrdup(_T("0")); - return itot(c-ai->targv[1]+1); + return itot(c - ai->targv[1] + 1); } static TCHAR *parseStrcmp(ARGUMENTSINFO *ai) @@ -500,7 +500,7 @@ static TCHAR *parseStrcmp(ARGUMENTSINFO *ai) if (ai->argc != 3) return NULL; - if ( _tcscmp(ai->targv[1], ai->targv[2])) + if (_tcscmp(ai->targv[1], ai->targv[2])) ai->flags |= AIF_FALSE; return mir_tstrdup(_T("")); @@ -512,7 +512,7 @@ static TCHAR *parseStrmcmp(ARGUMENTSINFO *ai) return NULL; ai->flags |= AIF_FALSE; - for (unsigned i=2; i < ai->argc; i++) { + for (unsigned i = 2; i < ai->argc; i++) { if (!_tcscmp(ai->targv[1], ai->targv[i])) { ai->flags &= ~AIF_FALSE; break; @@ -531,7 +531,7 @@ static TCHAR *parseStrncmp(ARGUMENTSINFO *ai) if (n <= 0) return NULL; - if ( _tcsncmp(ai->targv[1], ai->targv[2], n)) + if (_tcsncmp(ai->targv[1], ai->targv[2], n)) ai->flags |= AIF_FALSE; return mir_tstrdup(_T("")); @@ -542,7 +542,7 @@ static TCHAR *parseStricmp(ARGUMENTSINFO *ai) if (ai->argc != 3) return NULL; - if ( _tcsicmp(ai->targv[1], ai->targv[2])) + if (_tcsicmp(ai->targv[1], ai->targv[2])) ai->flags |= AIF_FALSE; return mir_tstrdup(_T("")); @@ -557,12 +557,12 @@ static TCHAR *parseStrnicmp(ARGUMENTSINFO *ai) if (n <= 0) return NULL; - if ( _tcsnicmp(ai->targv[1], ai->targv[2], n)) + if (_tcsnicmp(ai->targv[1], ai->targv[2], n)) ai->flags |= AIF_FALSE; return mir_tstrdup(_T("")); } - + static TCHAR *parseStrrchr(ARGUMENTSINFO *ai) { if (ai->argc != 3) @@ -572,7 +572,7 @@ static TCHAR *parseStrrchr(ARGUMENTSINFO *ai) if ((c == NULL) || (*c == 0)) return mir_tstrdup(_T("0")); - return itot(c-ai->targv[1]+1); + return itot(c - ai->targv[1] + 1); } static TCHAR *parseStrstr(ARGUMENTSINFO *ai) @@ -584,7 +584,7 @@ static TCHAR *parseStrstr(ARGUMENTSINFO *ai) if ((c == NULL) || (*c == 0)) return mir_tstrdup(_T("0")); - return itot(c-ai->targv[1]+1); + return itot(c - ai->targv[1] + 1); } static TCHAR *parseSubstr(ARGUMENTSINFO *ai) @@ -592,7 +592,7 @@ static TCHAR *parseSubstr(ARGUMENTSINFO *ai) if (ai->argc < 3) return NULL; - int to, from = max(ttoi(ai->targv[2])-1, 0); + int to, from = max(ttoi(ai->targv[2]) - 1, 0); if (ai->argc > 3) to = min(ttoi(ai->targv[3]), (int)_tcslen(ai->targv[1])); else @@ -601,9 +601,9 @@ static TCHAR *parseSubstr(ARGUMENTSINFO *ai) if (to < from) return NULL; - TCHAR *res = (TCHAR*)mir_alloc((to-from+1)*sizeof(TCHAR)); - ZeroMemory(res, (to-from+1)*sizeof(TCHAR)); - _tcsncpy(res, ai->targv[1]+from, to-from); + TCHAR *res = (TCHAR*)mir_alloc((to - from + 1)*sizeof(TCHAR)); + ZeroMemory(res, (to - from + 1)*sizeof(TCHAR)); + _tcsncpy(res, ai->targv[1] + from, to - from); return res; } @@ -613,20 +613,20 @@ static TCHAR *parseSelect(ARGUMENTSINFO *ai) return NULL; int n = ttoi(ai->targv[1]); - if ((n > (signed int)ai->argc-2) || n <= 0) + if ((n > (signed int)ai->argc - 2) || n <= 0) return NULL; - - return mir_tstrdup(ai->targv[n+1]); + + return mir_tstrdup(ai->targv[n + 1]); } static TCHAR *parseSwitch(ARGUMENTSINFO *ai) { - if (ai->argc%2 != 0) + if (ai->argc % 2 != 0) return NULL; - for (unsigned i=2; i < ai->argc; i += 2) - if (!_tcscmp(ai->targv[1], ai->targv[i])) - return mir_tstrdup(ai->targv[i+1]); + for (unsigned i = 2; i < ai->argc; i += 2) + if (!_tcscmp(ai->targv[1], ai->targv[i])) + return mir_tstrdup(ai->targv[i + 1]); return NULL; } @@ -640,19 +640,19 @@ static TCHAR *parseTrim(ARGUMENTSINFO *ai) while (*scur == ' ') scur++; - TCHAR *ecur = ai->targv[1] + _tcslen(ai->targv[1])-1; - while ( (*ecur == ' ') && (ecur > ai->targv[1])) + TCHAR *ecur = ai->targv[1] + _tcslen(ai->targv[1]) - 1; + while ((*ecur == ' ') && (ecur > ai->targv[1])) ecur--; if (scur >= ecur) return mir_tstrdup(_T("")); - TCHAR *res = (TCHAR*)mir_alloc((ecur-scur+2)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((ecur - scur + 2)*sizeof(TCHAR)); if (res == NULL) return NULL; - ZeroMemory(res, (ecur-scur+2)*sizeof(TCHAR)); - _tcsncpy(res, scur, ecur-scur+1); + ZeroMemory(res, (ecur - scur + 2)*sizeof(TCHAR)); + _tcsncpy(res, scur, ecur - scur + 1); return res; } @@ -666,15 +666,15 @@ static TCHAR *parseTab(ARGUMENTSINFO *ai) if (count < 0) return NULL; - TCHAR *res = (TCHAR*)mir_alloc((count+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((count + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; - memset(res, 0, (count+1)*sizeof(TCHAR)); + memset(res, 0, (count + 1)*sizeof(TCHAR)); TCHAR *cur = res; - for (int i=0; i < count; i++) + for (int i = 0; i < count; i++) *cur++ = '\t'; - + return res; } @@ -686,7 +686,7 @@ static TCHAR *parseUpper(ARGUMENTSINFO *ai) TCHAR *res = mir_tstrdup(ai->targv[1]); if (res == NULL) return NULL; - + return CharUpper(res); } @@ -701,7 +701,7 @@ static TCHAR *getNthWord(TCHAR *szString, int w) scur++; count += 1; - while ( (count < w) && (scur < szString+_tcslen(szString))) { + while ((count < w) && (scur < szString + _tcslen(szString))) { if (*scur == ' ') { while (*scur == ' ') scur++; @@ -715,27 +715,27 @@ static TCHAR *getNthWord(TCHAR *szString, int w) return NULL; TCHAR *ecur = scur; - while ( (*ecur != ' ') && (*ecur != 0)) + while ((*ecur != ' ') && (*ecur != 0)) ecur++; - TCHAR *res = (TCHAR*)mir_alloc((ecur-scur+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((ecur - scur + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; - ZeroMemory(res, (ecur-scur+1)*sizeof(TCHAR)); - _tcsncpy(res, scur, ecur-scur); + ZeroMemory(res, (ecur - scur + 1)*sizeof(TCHAR)); + _tcsncpy(res, scur, ecur - scur); return res; } static TCHAR *parseWord(ARGUMENTSINFO *ai) { - if (ai->argc < 3 || ai->argc > 4 ) + if (ai->argc < 3 || ai->argc > 4) return NULL; TCHAR *res = NULL; int to, from = ttoi(ai->targv[2]); if (ai->argc == 4) { - if ( _tcslen(ai->targv[3]) > 0) + if (_tcslen(ai->targv[3]) > 0) to = ttoi(ai->targv[3]); else to = 100000; // rework @@ -745,7 +745,7 @@ static TCHAR *parseWord(ARGUMENTSINFO *ai) if ((from == 0) || (to == 0) || (from > to)) return NULL; - for (int i=from; i <= to; i++) { + for (int i = from; i <= to; i++) { TCHAR *szWord = getNthWord(ai->targv[1], i); if (szWord == NULL) return res; @@ -777,8 +777,8 @@ static TCHAR *parseExtratext(ARGUMENTSINFO *ai) return NULL; } -int registerStrTokens() { - +int registerStrTokens() +{ registerIntToken(_T(MIR_CAPS), parseCaps, TRF_FUNCTION, LPGEN("String Functions")"\t(x)\t"LPGEN("converts each first letter of a word to uppercase, all others to lowercase")); registerIntToken(_T(MIR_CAPS2), parseCaps2, TRF_FUNCTION, LPGEN("String Functions")"\t(x)\t"LPGEN("converts each first letter of a word to uppercase")); registerIntToken(_T(MIR_CRLF), parseCrlf, TRF_FUNCTION, LPGEN("String Functions")"\t()\t"LPGEN("inserts 'end of line' character")); @@ -817,6 +817,5 @@ int registerStrTokens() { registerIntToken(_T(MIR_TAB), parseTab, TRF_FUNCTION, LPGEN("String Functions")"\t(x)\t"LPGEN("inserts x tab characters (x is optional)")); registerIntToken(_T(MIR_UPPER), parseUpper, TRF_FUNCTION, LPGEN("String Functions")"\t(x)\t"LPGEN("converts x to upper case")); registerIntToken(_T(MIR_WORD), parseWord, TRF_FUNCTION, LPGEN("String Functions")"\t(x,y,z)\t"LPGEN("words (separated by white spaces) number y to z from string x (z is optional)")); - return 0; } diff --git a/plugins/Variables/src/parse_str.h b/plugins/Variables/src/parse_str.h index 53fcd78300..69a475fba3 100644 --- a/plugins/Variables/src/parse_str.h +++ b/plugins/Variables/src/parse_str.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_system.cpp b/plugins/Variables/src/parse_system.cpp index dd4efbf10a..d8acc94430 100644 --- a/plugins/Variables/src/parse_system.cpp +++ b/plugins/Variables/src/parse_system.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -41,7 +41,8 @@ static TCHAR *parseComputerName(ARGUMENTSINFO *ai) #include #include -static TCHAR *parseCpuLoad(ARGUMENTSINFO *ai) { +static TCHAR *parseCpuLoad(ARGUMENTSINFO *ai) +{ HQUERY hQuery; PDH_FMT_COUNTERVALUE cValue; @@ -51,7 +52,7 @@ static TCHAR *parseCpuLoad(ARGUMENTSINFO *ai) { if (ai->argc != 2) return NULL; - if ( _tcslen(ai->targv[1]) == 0) + if (_tcslen(ai->targv[1]) == 0) szCounter = mir_tstrdup(_T("\\Processor(_Total)\\% Processor Time")); else { int size = (int)_tcslen(ai->targv[1]) + 32; @@ -109,7 +110,7 @@ static TCHAR *parseCpuLoad(ARGUMENTSINFO *ai) { //PdhRemoveCounter(*hCounter); PdhCloseQuery(hQuery); mir_free(szCounter); - + return mir_tstrdup(szVal); } #endif @@ -117,13 +118,13 @@ static TCHAR *parseCpuLoad(ARGUMENTSINFO *ai) { static TCHAR *parseCurrentDate(ARGUMENTSINFO *ai) { TCHAR *szFormat; - if (ai->argc == 1 || (ai->argc > 1 && _tcslen(ai->targv[1]) == 0 )) + if (ai->argc == 1 || (ai->argc > 1 && _tcslen(ai->targv[1]) == 0)) szFormat = NULL; else szFormat = ai->targv[1]; int len = GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, szFormat, NULL, 0); - TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; @@ -144,7 +145,7 @@ static TCHAR *parseCurrentTime(ARGUMENTSINFO *ai) szFormat = ai->targv[1]; int len = GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, szFormat, NULL, 0); - TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; @@ -158,7 +159,7 @@ static TCHAR *parseCurrentTime(ARGUMENTSINFO *ai) static TCHAR *parseDirectory(ARGUMENTSINFO *ai) { - if (ai->argc < 2 || ai->argc > 3 ) + if (ai->argc < 2 || ai->argc > 3) return NULL; int depth = 0; @@ -178,9 +179,9 @@ static TCHAR *parseDirectory(ARGUMENTSINFO *ai) if (ei >= _tcslen(ai->targv[1])) return ai->targv[1]; - for (bi = ei-1; bi > 0; bi--) - if (ai->targv[1][bi - 1] == '\\') - break; + for (bi = ei - 1; bi > 0; bi--) + if (ai->targv[1][bi - 1] == '\\') + break; TCHAR *res = (TCHAR*)mir_alloc((ei - bi + 1) * sizeof(TCHAR)); _tcsncpy(res, ai->targv[1] + bi, ei - bi); @@ -191,10 +192,10 @@ static TCHAR *parseDirectory(ARGUMENTSINFO *ai) /* path, depth returns complete path up to "path depth - depth" -*/ + */ static TCHAR *parseDirectory2(ARGUMENTSINFO *ai) { - if (ai->argc < 2 || ai->argc > 3 ) + if (ai->argc < 2 || ai->argc > 3) return NULL; int depth = 1; @@ -204,9 +205,9 @@ static TCHAR *parseDirectory2(ARGUMENTSINFO *ai) if (depth <= 0) return NULL; - TCHAR *ecur = ai->targv[1]+_tcslen(ai->targv[1]); + TCHAR *ecur = ai->targv[1] + _tcslen(ai->targv[1]); while (depth > 0) { - while ( (*ecur != '\\') && (ecur > ai->targv[1])) + while ((*ecur != '\\') && (ecur > ai->targv[1])) ecur--; if (*ecur != '\\') @@ -215,11 +216,11 @@ static TCHAR *parseDirectory2(ARGUMENTSINFO *ai) depth -= 1; ecur--; } - TCHAR *res = (TCHAR*)mir_calloc((ecur-ai->targv[1]+2) * sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_calloc((ecur - ai->targv[1] + 2) * sizeof(TCHAR)); if (res == NULL) return NULL; - _tcsncpy(res, ai->targv[1], (ecur-ai->targv[1])+1); + _tcsncpy(res, ai->targv[1], (ecur - ai->targv[1]) + 1); return res; } @@ -227,17 +228,17 @@ static int getTime(TCHAR *szTime, struct tm *date) { // do some extra checks here TCHAR *cur = szTime; - if (cur >= szTime+_tcslen(szTime)) + if (cur >= szTime + _tcslen(szTime)) return -1; - date->tm_mon = _tcstoul(cur, &cur, 10)-1; + date->tm_mon = _tcstoul(cur, &cur, 10) - 1; cur++; - if (cur >= szTime+_tcslen(szTime)) + if (cur >= szTime + _tcslen(szTime)) return -1; date->tm_mday = _tcstoul(cur, &cur, 10); cur++; - if (cur >= szTime+_tcslen(szTime)) + if (cur >= szTime + _tcslen(szTime)) return -1; date->tm_year = _tcstoul(cur, &cur, 10); @@ -246,19 +247,19 @@ static int getTime(TCHAR *szTime, struct tm *date) else if (date->tm_year > 1900) date->tm_year -= 1900; - date->tm_year = date->tm_year<38?date->tm_year+100:date->tm_year; + date->tm_year = date->tm_year < 38 ? date->tm_year + 100 : date->tm_year; cur++; - if (cur >= szTime+_tcslen(szTime)) + if (cur >= szTime + _tcslen(szTime)) return -1; date->tm_hour = _tcstoul(cur, &cur, 10); cur++; - if (cur >= szTime+_tcslen(szTime)) + if (cur >= szTime + _tcslen(szTime)) return -1; date->tm_min = _tcstoul(cur, &cur, 10); cur++; - if (cur >= szTime+_tcslen(szTime)) + if (cur >= szTime + _tcslen(szTime)) return -1; date->tm_sec = _tcstoul(cur, &cur, 10); @@ -266,7 +267,7 @@ static int getTime(TCHAR *szTime, struct tm *date) } static TCHAR *parseDiffTime(ARGUMENTSINFO *ai) -{ +{ struct tm t0, t1; TCHAR szTime[32]; double diff; @@ -311,11 +312,11 @@ static TCHAR *parseEnvironmentVariable(ARGUMENTSINFO *ai) if (len <= 0) return NULL; - TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; - ZeroMemory(res, (len+1)*sizeof(TCHAR)); + ZeroMemory(res, (len + 1)*sizeof(TCHAR)); if (ExpandEnvironmentStrings(ai->targv[1], res, len) == 0) { mir_free(res); return NULL; @@ -331,7 +332,7 @@ static TCHAR *parseFileExists(ARGUMENTSINFO *ai) HANDLE hFile = CreateFile(ai->targv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) ai->flags |= AIF_FALSE; - else + else CloseHandle(hFile); return mir_tstrdup(_T("")); @@ -350,9 +351,9 @@ static TCHAR *parseFindWindow(ARGUMENTSINFO *ai) if (len == 0) return NULL; - TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); - ZeroMemory(res, (len+1)*sizeof(TCHAR)); - GetWindowText(hWin, res, len+1); + TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR)); + ZeroMemory(res, (len + 1)*sizeof(TCHAR)); + GetWindowText(hWin, res, len + 1); return res; } @@ -372,7 +373,7 @@ static TCHAR *parseListDir(ARGUMENTSINFO *ai) tszRes = NULL; if (ai->argc > 1) - _tcsncpy(tszFirst, ai->targv[1], SIZEOF(tszFirst)-1); + _tcsncpy(tszFirst, ai->targv[1], SIZEOF(tszFirst) - 1); if (ai->argc > 2) tszFilter = ai->targv[2]; @@ -387,7 +388,7 @@ static TCHAR *parseListDir(ARGUMENTSINFO *ai) if (*ai->targv[4] == 'd') bFiles = FALSE; } - if (tszFirst[_tcslen(tszFirst)-1] == '\\') + if (tszFirst[_tcslen(tszFirst) - 1] == '\\') _tcsncat(tszFirst, tszFilter, SIZEOF(tszFirst) - _tcslen(tszFirst) - 1); else { _tcsncat(tszFirst, _T("\\"), SIZEOF(tszFirst) - _tcslen(tszFirst) - 1); @@ -439,7 +440,7 @@ static TCHAR *parseProcessRunning(ARGUMENTSINFO *ai) char *szProc, *ref; szProc = ref = mir_u2a(ai->targv[1]); - EnumProcs((PROCENUMPROC) MyProcessEnumerator, (LPARAM)&szProc); + EnumProcs((PROCENUMPROC)MyProcessEnumerator, (LPARAM)&szProc); if (szProc != NULL) ai->flags |= AIF_FALSE; @@ -478,13 +479,13 @@ static TCHAR *parseRegistryValue(ARGUMENTSINFO *ai) mir_free(key); return NULL; } - TCHAR *subKey = cur+1; + TCHAR *subKey = cur + 1; if (RegOpenKeyEx(hKey, subKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS) { mir_free(key); return NULL; } mir_free(key); - len = MAX_REGVALUE_LENGTH+1; + len = MAX_REGVALUE_LENGTH + 1; TCHAR *res = (TCHAR*)mir_alloc(len*sizeof(TCHAR)); if (res == NULL) return NULL; @@ -539,7 +540,7 @@ static TCHAR *parseTimestamp2Date(ARGUMENTSINFO *ai) return NULL; int len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &sysTime, szFormat, NULL, 0); - TCHAR *res = (TCHAR*)mir_calloc((len+1) * sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_calloc((len + 1) * sizeof(TCHAR)); if (res == NULL) return NULL; @@ -571,7 +572,7 @@ static TCHAR *parseTimestamp2Time(ARGUMENTSINFO *ai) return NULL; int len = GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, szFormat, NULL, 0); - TCHAR *res = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); + TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR)); if (res == NULL) return NULL; @@ -596,7 +597,7 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) return NULL; lineNo = ttoi(ai->targv[2]); - HANDLE hFile = CreateFile(ai->targv[1], GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + HANDLE hFile = CreateFile(ai->targv[1], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) return NULL; @@ -622,7 +623,7 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) if (pBuf == NULL) return NULL; - if (ReadFile(hFile, pBuf, bufSz-csz, &readSz, NULL) == 0) { + if (ReadFile(hFile, pBuf, bufSz - csz, &readSz, NULL) == 0) { CloseHandle(hFile); mir_free(pBuf); return NULL; @@ -647,13 +648,13 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) // count number of lines do { ZeroMemory(pBuf, bufSz); - if (ReadFile(hFile, pBuf, bufSz-csz, &readSz, NULL) == 0) { + if (ReadFile(hFile, pBuf, bufSz - csz, &readSz, NULL) == 0) { CloseHandle(hFile); mir_free(pBuf); return NULL; } totalReadSz += readSz; - for (pCur = pBuf;*pCur != '\0';pCur += csz) { + for (pCur = pBuf; *pCur != '\0'; pCur += csz) { if (tUC) { if (!_tcsncmp((TCHAR*)pCur, _T("\r\n"), 2)) { lineCount += 1; @@ -672,27 +673,27 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) } } } - while ( (totalReadSz < fileSz) && (readSz > 0)); + while ((totalReadSz < fileSz) && (readSz > 0)); if (lineNo < 0) lineNo = lineCount + lineNo + 1; else if (*ai->targv[2] == 'r') - lineNo = (rand()%lineCount)+1; + lineNo = (rand() % lineCount) + 1; totalReadSz = 0; lineCount = 1; linePos = 0xFFFFFFFF; - SetFilePointer(hFile, tUC?csz:0, NULL, FILE_BEGIN); + SetFilePointer(hFile, tUC ? csz : 0, NULL, FILE_BEGIN); // find the position in the file where the requested line starts do { - if (ReadFile(hFile, pBuf, bufSz-csz, &readSz, NULL) == 0) { + if (ReadFile(hFile, pBuf, bufSz - csz, &readSz, NULL) == 0) { CloseHandle(hFile); return NULL; } totalReadSz += readSz; - for (pCur = pBuf;((pCur < pBuf+bufSz) && (linePos == 0xFFFFFFFF));pCur+=csz) { + for (pCur = pBuf; ((pCur < pBuf + bufSz) && (linePos == 0xFFFFFFFF)); pCur += csz) { if (lineCount == lineNo) - linePos = (tUC?csz:0) + totalReadSz - readSz + pCur - pBuf; + linePos = (tUC ? csz : 0) + totalReadSz - readSz + pCur - pBuf; if (tUC) { if (!_tcsncmp((TCHAR*)pCur, _T("\r\n"), 2)) { @@ -713,11 +714,11 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) } if (((tUC) && (*(TCHAR*)pCur == '\r')) || ((!tUC) && (*(char *)pCur == '\r'))) { // in case the \r was at the end of the buffer, \n could be next - SetFilePointer(hFile, -1*csz, NULL, FILE_CURRENT); + SetFilePointer(hFile, -1 * csz, NULL, FILE_CURRENT); totalReadSz -= csz; } } - while ( (totalReadSz < fileSz) && (readSz > 0)); + while ((totalReadSz < fileSz) && (readSz > 0)); if (linePos < 0) { CloseHandle(hFile); @@ -733,13 +734,13 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) pCur = pBuf; do { icur = 0; - if (ReadFile(hFile, pBuf, bufSz-csz, &readSz, NULL) == 0) { + if (ReadFile(hFile, pBuf, bufSz - csz, &readSz, NULL) == 0) { mir_free(pBuf); CloseHandle(hFile); return NULL; } - for (pCur = pBuf;(pCur < pBuf+readSz); pCur += csz) { - if ((tUC) && ((!_tcsncmp((TCHAR*)pCur, _T("\r\n"), 2)) || (*(TCHAR*)pCur == '\n')) || + for (pCur = pBuf; (pCur < pBuf + readSz); pCur += csz) { + if ((tUC) && ((!_tcsncmp((TCHAR*)pCur, _T("\r\n"), 2)) || (*(TCHAR*)pCur == '\n')) || ((!tUC) && (((!strncmp((char *)pCur, "\r\n", 2)) || (*(char *)pCur == '\n'))))) { CloseHandle(hFile); if (tUC) @@ -757,7 +758,7 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) return res; } } - if (((DWORD)(linePos+(pCur-pBuf)) == fileSz)) { // eof + if (((DWORD)(linePos + (pCur - pBuf)) == fileSz)) { // eof CloseHandle(hFile); if (tUC) { @@ -770,7 +771,7 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) return res; } - if (readSz == bufSz-csz) { + if (readSz == bufSz - csz) { // buffer must be increased bufSz += TXTFILEBUFSZ*csz; if (((tUC) && (*(TCHAR*)pCur == '\r')) || ((!tUC) && (*(char *)pCur == '\r'))) { @@ -778,11 +779,11 @@ static TCHAR *parseTextFile(ARGUMENTSINFO *ai) } icur = pCur - pBuf; pBuf = (PBYTE)mir_realloc(pBuf, bufSz); - pCur = pBuf+icur; - ZeroMemory(pCur+1, TXTFILEBUFSZ*csz); + pCur = pBuf + icur; + ZeroMemory(pCur + 1, TXTFILEBUFSZ*csz); } } - while (readSz > 0); + while (readSz > 0); CloseHandle(hFile); return NULL; @@ -795,7 +796,7 @@ static TCHAR *parseUpTime(ARGUMENTSINFO *ai) return NULL; HQUERY hQuery; - PDH_STATUS pdhStatus = PdhOpenQuery (NULL, 0, &hQuery); + PDH_STATUS pdhStatus = PdhOpenQuery(NULL, 0, &hQuery); if (pdhStatus != ERROR_SUCCESS) return NULL; @@ -828,7 +829,8 @@ static TCHAR *parseUpTime(ARGUMENTSINFO *ai) } #endif -static TCHAR *parseUserName(ARGUMENTSINFO *ai) { +static TCHAR *parseUserName(ARGUMENTSINFO *ai) +{ if (ai->argc != 1) return NULL; @@ -847,7 +849,8 @@ static TCHAR *parseUserName(ARGUMENTSINFO *ai) { } // clipboard support -static TCHAR *parseClipboard(ARGUMENTSINFO *ai) { +static TCHAR *parseClipboard(ARGUMENTSINFO *ai) +{ if (ai->argc != 1) return NULL; @@ -873,8 +876,8 @@ static TCHAR *parseClipboard(ARGUMENTSINFO *ai) { return res; } -int registerSystemTokens() { - +int registerSystemTokens() +{ registerIntToken(_T(COMPUTERNAME), parseComputerName, TRF_FIELD, LPGEN("System Functions")"\t"LPGEN("computer name")); #if _WIN32_WINNT>=0x0500 registerIntToken(_T(CPULOAD), parseCpuLoad, TRF_FUNCTION, LPGEN("System Functions")"\t(x)\t"LPGEN("cpu load of process x (without extension) (x is optional)")); @@ -898,16 +901,15 @@ int registerSystemTokens() { #if _WIN32_WINNT>=0x0500 registerIntToken(_T(UPTIME), parseUpTime, TRF_FIELD, LPGEN("System Functions")"\t"LPGEN("uptime in seconds")); #endif - if (!ServiceExists( MS_UTILS_REPLACEVARS )) - registerIntToken(_T(ENVIRONMENTVARIABLE), parseEnvironmentVariable, TRF_FUNCTION , LPGEN("Miranda Core OS")"\t(%xxxxxxx%)\t"LPGEN("any environment variable defined in current Windows session (like %systemroot%, %allusersprofile%, etc.)")); + if (!ServiceExists(MS_UTILS_REPLACEVARS)) + registerIntToken(_T(ENVIRONMENTVARIABLE), parseEnvironmentVariable, TRF_FUNCTION, LPGEN("Miranda Core OS")"\t(%xxxxxxx%)\t"LPGEN("any environment variable defined in current Windows session (like %systemroot%, %allusersprofile%, etc.)")); else { - registerIntToken(_T(ENVIRONMENTVARIABLE), parseEnvironmentVariable, TRF_FUNCTION , LPGEN("System Functions")"\t(x)\t"LPGEN("expand environment variable x")); - registerIntToken(_T(USERNAME), parseUserName, TRF_FIELD , LPGEN("System Functions")"\t"LPGEN("user name")); + registerIntToken(_T(ENVIRONMENTVARIABLE), parseEnvironmentVariable, TRF_FUNCTION, LPGEN("System Functions")"\t(x)\t"LPGEN("expand environment variable x")); + registerIntToken(_T(USERNAME), parseUserName, TRF_FIELD, LPGEN("System Functions")"\t"LPGEN("user name")); } srand((unsigned int)GetTickCount()); registerIntToken(_T(CLIPBOARD), parseClipboard, TRF_FIELD, LPGEN("System Functions")"\t"LPGEN("text from clipboard")); - return 0; } diff --git a/plugins/Variables/src/parse_system.h b/plugins/Variables/src/parse_system.h index 24bf78ef60..d7d069432f 100644 --- a/plugins/Variables/src/parse_system.h +++ b/plugins/Variables/src/parse_system.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/parse_variables.cpp b/plugins/Variables/src/parse_variables.cpp index 2563d0e954..432d4eb0fd 100644 --- a/plugins/Variables/src/parse_variables.cpp +++ b/plugins/Variables/src/parse_variables.cpp @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -24,137 +24,106 @@ static CRITICAL_SECTION csVarRegister; static VARIABLEREGISTER *vr = NULL; static int vrCount = 0; -static int addToVariablesRegister(TCHAR *szName, TCHAR *szText) { - - int i; - - if ((szName == NULL) || (szText == NULL) || (_tcslen(szName) <= 0)) { +static int addToVariablesRegister(TCHAR *szName, TCHAR *szText) +{ + if ((szName == NULL) || (szText == NULL) || (_tcslen(szName) <= 0)) return -1; - } - EnterCriticalSection(&csVarRegister); - for (i=0;i 1) { - memcpy(&vr[i], &vr[vrCount-1], sizeof(VARIABLEREGISTER)); - vr = ( VARIABLEREGISTER* )mir_realloc(vr, (vrCount-1)*sizeof(VARIABLEREGISTER)); - if (vr == NULL) { - LeaveCriticalSection(&csVarRegister); - return -1; - } - vrCount -= 1; - } - else { - mir_free(vr); - vr = NULL; - vrCount = 0; - } - count += 1; +int clearVariableRegister(bool bAll) +{ + int count = 0; + mir_cslock lck(csVarRegister); + for (int i = 0; i < vrCount; i++) { + if (!bAll && vr[i].dwOwnerThread != GetCurrentThreadId()) + continue; + + mir_free(vr[i].szName); + mir_free(vr[i].szText); + if (vrCount > 1) { + memcpy(&vr[i], &vr[vrCount-1], sizeof(VARIABLEREGISTER)); + vr = (VARIABLEREGISTER*)mir_realloc(vr, (vrCount-1)*sizeof(VARIABLEREGISTER)); + if (vr == NULL) + return -1; + + vrCount--; } + else { + mir_free(vr); + vr = NULL; + vrCount = 0; + } + count += 1; } - LeaveCriticalSection(&csVarRegister); return count; } -static TCHAR *parsePut(ARGUMENTSINFO *ai) { - +static TCHAR *parsePut(ARGUMENTSINFO *ai) +{ FORMATINFO fi; - if (ai->argc != 3) { + if (ai->argc != 3) return NULL; - } -// ai->flags |= AIF_DONTPARSE; - if (addToVariablesRegister(ai->targv[1], ai->targv[2])) { + + // ai->flags |= AIF_DONTPARSE; + if (addToVariablesRegister(ai->targv[1], ai->targv[2])) return NULL; - } memcpy(&fi, ai->fi, sizeof(fi)); fi.tszFormat = ai->targv[2]; fi.flags |= FIF_TCHAR; - return formatString(&fi); } -static TCHAR *parsePuts(ARGUMENTSINFO *ai) { - - if (ai->argc != 3) { +static TCHAR *parsePuts(ARGUMENTSINFO *ai) +{ + if (ai->argc != 3) return NULL; - } -// ai->flags |= AIF_DONTPARSE; - if (addToVariablesRegister(ai->targv[1], ai->targv[2])) { + + if (addToVariablesRegister(ai->targv[1], ai->targv[2])) return NULL; - } return mir_tstrdup(_T("")); } - -static TCHAR *parseGet(ARGUMENTSINFO *ai) { - TCHAR *szText; - - if (ai->argc != 2) { - return NULL; - } -// ai->flags |= AIF_DONTPARSE; - szText = searchVariableRegister(ai->targv[1]); - if (szText == NULL) { +static TCHAR *parseGet(ARGUMENTSINFO *ai) +{ + if (ai->argc != 2) return NULL; - } - return szText; + return searchVariableRegister(ai->targv[1]); } int registerVariablesTokens() @@ -163,11 +132,11 @@ int registerVariablesTokens() registerIntToken(_T(PUT), parsePut, TRF_FUNCTION, LPGEN("Variables")"\t(x,y)\t"LPGEN("x, and stores y as variable named x"));//TRF_UNPARSEDARGS); registerIntToken(_T(PUTS), parsePuts, TRF_FUNCTION, LPGEN("Variables")"\t(x,y)\t"LPGEN("only stores y as variables x"));//TRF_UNPARSEDARGS); InitializeCriticalSection(&csVarRegister); - return 0; } void unregisterVariablesTokens() { + clearVariableRegister(true); DeleteCriticalSection(&csVarRegister); } diff --git a/plugins/Variables/src/parse_variables.h b/plugins/Variables/src/parse_variables.h index b46ede4351..b21b35a987 100644 --- a/plugins/Variables/src/parse_variables.h +++ b/plugins/Variables/src/parse_variables.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. diff --git a/plugins/Variables/src/tokenregister.cpp b/plugins/Variables/src/tokenregister.cpp index ad0d25635d..f4865e84e5 100644 --- a/plugins/Variables/src/tokenregister.cpp +++ b/plugins/Variables/src/tokenregister.cpp @@ -1,37 +1,39 @@ /* - Variables Plugin for Miranda-IM (www.miranda-im.org) - Copyright 2003-2006 P. Boon + Variables Plugin for Miranda-IM (www.miranda-im.org) + Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is mir_free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #include "variables.h" -typedef struct { +struct TokenRegisterEntry +{ TOKENREGISTEREX tr; DWORD nameHash; -} - TokenRegisterEntry; +}; -struct +static int CompareTokens(const TokenRegisterEntry* p1, const TokenRegisterEntry* p2) { - TokenRegisterEntry** items; - int count, limit, increment; - FSortFunc sortFunc; + if (p1->nameHash == p2->nameHash) + return 0; + + return (p1->nameHash < p2->nameHash) ? -1 : 1; } -static tokens; + +static LIST tokens(100, CompareTokens); static CRITICAL_SECTION csRegister; @@ -44,20 +46,16 @@ static DWORD NameHashFunction(TCHAR *tszStr) static TokenRegisterEntry* FindTokenRegisterByName(TCHAR *name) { - int idx; TokenRegisterEntry temp; - temp.nameHash = NameHashFunction( name ); - if (List_GetIndex(( SortedList* )&tokens, &temp, &idx )) - return tokens.items[ idx ]; - - return NULL; + temp.nameHash = NameHashFunction(name); + return tokens.find(&temp); } int registerIntToken(TCHAR *szToken, TCHAR *(*parseFunction)(ARGUMENTSINFO *ai), int extraFlags, char* szHelpText) { TOKENREGISTEREX tr = { 0 }; tr.cbSize = sizeof(tr); - tr.flags = TRF_FREEMEM|TRF_TCHAR|TRF_PARSEFUNC|extraFlags; + tr.flags = TRF_FREEMEM | TRF_TCHAR | TRF_PARSEFUNC | extraFlags; //tr.memType = TR_MEM_VARIABLES; tr.memType = TR_MEM_MIRANDA; tr.szHelpText = szHelpText; @@ -69,34 +67,32 @@ int registerIntToken(TCHAR *szToken, TCHAR *(*parseFunction)(ARGUMENTSINFO *ai), int deRegisterToken(TCHAR *token) { - TokenRegisterEntry *tre; - if (token == NULL) return -1; - EnterCriticalSection(&csRegister); - tre = FindTokenRegisterByName( token ); - if (tre == NULL) { - LeaveCriticalSection(&csRegister); - return -1; - } + TokenRegisterEntry *tre; + { + mir_cslock lck(csRegister); + tre = FindTokenRegisterByName(token); + if (tre == NULL) + return -1; - List_RemovePtr(( SortedList* )&tokens, tre ); - LeaveCriticalSection(&csRegister); + List_RemovePtr((SortedList*)&tokens, tre); + } - if (!( tre->tr.flags & TRF_PARSEFUNC ) && tre->tr.szService != NULL) - mir_free( tre->tr.szService ); + if (!(tre->tr.flags & TRF_PARSEFUNC) && tre->tr.szService != NULL) + mir_free(tre->tr.szService); if (tre->tr.tszTokenString != NULL) - mir_free( tre->tr.tszTokenString ); + mir_free(tre->tr.tszTokenString); if (tre->tr.szHelpText != NULL) - mir_free( tre->tr.szHelpText ); + mir_free(tre->tr.szHelpText); - if ((tre->tr.flags & TRF_CLEANUP ) && !( tre->tr.flags & TRF_CLEANUPFUNC ) && tre->tr.szCleanupService != NULL) - mir_free( tre->tr.szCleanupService ); + if ((tre->tr.flags & TRF_CLEANUP) && !(tre->tr.flags & TRF_CLEANUPFUNC) && tre->tr.szCleanupService != NULL) + mir_free(tre->tr.szCleanupService); - mir_free( tre ); + mir_free(tre); return 0; } @@ -104,77 +100,62 @@ INT_PTR registerToken(WPARAM wParam, LPARAM lParam) { DWORD hash; int idx; - TokenRegisterEntry *tre; - TOKENREGISTEREX *newVr = ( TOKENREGISTEREX* )lParam; - if (newVr == NULL || newVr->szTokenString == NULL || newVr->cbSize <= 0 ) + TOKENREGISTEREX *newVr = (TOKENREGISTEREX*)lParam; + if (newVr == NULL || newVr->szTokenString == NULL || newVr->cbSize <= 0) return -1; - if (newVr->flags & TRF_TCHAR ) { - deRegisterToken( newVr->tszTokenString ); - hash = NameHashFunction( newVr->tszTokenString ); + if (newVr->flags & TRF_TCHAR) { + deRegisterToken(newVr->tszTokenString); + hash = NameHashFunction(newVr->tszTokenString); } else { - - WCHAR *wtoken; - - wtoken = mir_a2t( newVr->szTokenString ); - deRegisterToken( wtoken ); - hash = NameHashFunction( wtoken ); - mir_free( wtoken ); - + WCHAR *wtoken = mir_a2t(newVr->szTokenString); + deRegisterToken(wtoken); + hash = NameHashFunction(wtoken); + mir_free(wtoken); } - tre = ( TokenRegisterEntry* )mir_alloc( sizeof( TokenRegisterEntry )); + TokenRegisterEntry *tre = (TokenRegisterEntry*)mir_alloc(sizeof(TokenRegisterEntry)); if (tre == NULL) return -1; - memcpy( &tre->tr, newVr, newVr->cbSize ); + memcpy(&tre->tr, newVr, newVr->cbSize); tre->nameHash = hash; - if (!_tcscmp( newVr->tszTokenString, _T("alias"))) + if (!_tcscmp(newVr->tszTokenString, _T("alias"))) log_debugA("alias"); - if (!( newVr->flags & TRF_PARSEFUNC ) && newVr->szService != NULL) - tre->tr.szService = mir_strdup( newVr->szService ); + if (!(newVr->flags & TRF_PARSEFUNC) && newVr->szService != NULL) + tre->tr.szService = mir_strdup(newVr->szService); - if (newVr->flags & TRF_TCHAR ) - tre->tr.tszTokenString = mir_tstrdup( newVr->tszTokenString ); + if (newVr->flags & TRF_TCHAR) + tre->tr.tszTokenString = mir_tstrdup(newVr->tszTokenString); else - - tre->tr.tszTokenString = mir_a2t( newVr->szTokenString ); - + tre->tr.tszTokenString = mir_a2t(newVr->szTokenString); if (newVr->szHelpText != NULL) - tre->tr.szHelpText = mir_strdup( newVr->szHelpText ); + tre->tr.szHelpText = mir_strdup(newVr->szHelpText); - if (( newVr->flags & TRF_CLEANUP ) && !( newVr->flags & TRF_CLEANUPFUNC ) && newVr->szCleanupService != NULL) - tre->tr.szCleanupService = mir_strdup( newVr->szCleanupService ); - - EnterCriticalSection(&csRegister); - List_GetIndex(( SortedList* )&tokens, tre, &idx ); - List_Insert(( SortedList* )&tokens, tre, idx ); - LeaveCriticalSection(&csRegister); + if ((newVr->flags & TRF_CLEANUP) && !(newVr->flags & TRF_CLEANUPFUNC) && newVr->szCleanupService != NULL) + tre->tr.szCleanupService = mir_strdup(newVr->szCleanupService); + mir_cslock lck(csRegister); + List_GetIndex((SortedList*)&tokens, tre, &idx); + List_Insert((SortedList*)&tokens, tre, idx); return 0; } TOKENREGISTEREX *searchRegister(TCHAR *tvar, int type) { - TokenRegisterEntry *tre; - TOKENREGISTEREX *retVr; - if (tvar == NULL) return 0; - EnterCriticalSection( &csRegister ); - tre = FindTokenRegisterByName( tvar ); - if (tre == NULL || ( type != 0 && (tre->tr.flags & ( TRF_FIELD | TRF_FUNCTION )) != 0 && !( tre->tr.flags & type ))) - retVr = NULL; - else - retVr = &tre->tr; + mir_cslock lck(csRegister); + TokenRegisterEntry *tre = FindTokenRegisterByName(tvar); + if (tre == NULL || (type != 0 && (tre->tr.flags & (TRF_FIELD | TRF_FUNCTION)) != 0 && !(tre->tr.flags & type))) + return NULL; - LeaveCriticalSection(&csRegister); - return retVr; + return &tre->tr; } TCHAR *parseFromRegister(ARGUMENTSINFO *ai) @@ -185,133 +166,99 @@ TCHAR *parseFromRegister(ARGUMENTSINFO *ai) INT_PTR callRes = 0; TCHAR *temp = NULL, *res = NULL; - EnterCriticalSection(&csRegister); + mir_cslock lck(csRegister); /* note the following limitation: you cannot add/remove tokens during a call from a different thread */ - TOKENREGISTEREX *thisVr = searchRegister( ai->targv[0], 0 ); - if (thisVr == NULL) { - LeaveCriticalSection(&csRegister); + TOKENREGISTEREX *thisVr = searchRegister(ai->targv[0], 0); + if (thisVr == NULL) return NULL; - } TOKENREGISTEREX trCopy = *thisVr; // ai contains WCHARs, convert to chars because the tr doesn't support WCHARs - if (!( thisVr->flags & TRF_TCHAR )) { + if (!(thisVr->flags & TRF_TCHAR)) { // unicode variables calls a non-unicode plugin - unsigned int j; ARGUMENTSINFO cAi; - memcpy(&cAi, ai, sizeof(ARGUMENTSINFO)); - cAi.argv = ( char** )mir_alloc(ai->argc*sizeof(char *)); - for ( j=0; j < ai->argc; j++ ) - cAi.argv[j] = mir_t2a( ai->targv[j] ); + cAi.argv = (char**)mir_alloc(ai->argc*sizeof(char *)); + for (unsigned j = 0; j < ai->argc; j++) + cAi.argv[j] = mir_t2a(ai->targv[j]); - if (thisVr->flags & TRF_PARSEFUNC ) - callRes = (INT_PTR)thisVr->parseFunction( &cAi ); + if (thisVr->flags & TRF_PARSEFUNC) + callRes = (INT_PTR)thisVr->parseFunction(&cAi); else if (thisVr->szService != NULL) - callRes = CallService(thisVr->szService, 0, (LPARAM)&cAi ); + callRes = CallService(thisVr->szService, 0, (LPARAM)&cAi); - for ( j=0; j < cAi.argc; j++ ) - if (cAi.argv[j] != NULL) - mir_free( cAi.argv[j] ); + for (unsigned j = 0; j < cAi.argc; j++) + mir_free(cAi.argv[j]); if ((char *)callRes != NULL) - res = mir_a2t(( char* )callRes ); + res = mir_a2t((char*)callRes); } else { // unicode variables calls unicode plugin - if (thisVr->flags & TRF_PARSEFUNC ) - callRes = (INT_PTR)thisVr->parseFunctionT( ai ); + if (thisVr->flags & TRF_PARSEFUNC) + callRes = (INT_PTR)thisVr->parseFunctionT(ai); else if (thisVr->szService != NULL) - callRes = CallService(thisVr->szService, 0, (LPARAM)ai ); + callRes = CallService(thisVr->szService, 0, (LPARAM)ai); if ((TCHAR*)callRes != NULL) - res = mir_tstrdup((TCHAR*)callRes ); + res = mir_tstrdup((TCHAR*)callRes); } - - if (( void* )callRes != NULL) { - if (trCopy.flags & TRF_CLEANUP ) { - if (trCopy.flags & TRF_CLEANUPFUNC ) - trCopy.cleanupFunctionT((TCHAR*)callRes ); + if (callRes != NULL) { + if (trCopy.flags & TRF_CLEANUP) { + if (trCopy.flags & TRF_CLEANUPFUNC) + trCopy.cleanupFunctionT((TCHAR*)callRes); else if (trCopy.szCleanupService != NULL) - CallService(trCopy.szCleanupService, 0, (LPARAM)callRes ); + CallService(trCopy.szCleanupService, 0, (LPARAM)callRes); } - if (trCopy.flags & TRF_FREEMEM) - if (trCopy.memType == TR_MEM_MIRANDA) - mir_free(( void* )callRes ); + if ((trCopy.flags & TRF_FREEMEM) && trCopy.memType == TR_MEM_MIRANDA) + mir_free((void*)callRes); } - LeaveCriticalSection(&csRegister); return res; } -TOKENREGISTEREX* getTokenRegister( int i ) +TOKENREGISTEREX* getTokenRegister(int i) { - TOKENREGISTEREX *retVr; - - EnterCriticalSection(&csRegister); - retVr = ( i >= tokens.count || i < 0 ) ? NULL : &tokens.items[i]->tr; - LeaveCriticalSection( &csRegister ); - // beware! a pointer is returned here, no copy - return retVr; + mir_cslock lck(csRegister); + return (i >= tokens.getCount() || i < 0) ? NULL : &tokens[i]->tr; } int getTokenRegisterCount() { - int retVal; - - EnterCriticalSection(&csRegister); - retVal = tokens.count; - LeaveCriticalSection(&csRegister); - - return retVal; + mir_cslock lck(csRegister); + return tokens.getCount(); } ///////////////////////////////////////////////////////////////////////////////////////// -static int CompareTokens( const TokenRegisterEntry* p1, const TokenRegisterEntry* p2 ) -{ - if (p1->nameHash == p2->nameHash ) - return 0; - - return ( p1->nameHash < p2->nameHash ) ? -1 : 1; -} - int initTokenRegister() { InitializeCriticalSection(&csRegister); - - tokens.sortFunc = ( FSortFunc )CompareTokens; - tokens.increment = 100; return 0; } int deinitTokenRegister() { - int i; - EnterCriticalSection(&csRegister); - - for ( i=0; i < tokens.count; i++ ) { - TokenRegisterEntry *tre = tokens.items[ i ]; - if (!( tre->tr.flags & TRF_PARSEFUNC ) && tre->tr.szService != NULL) - mir_free( tre->tr.szService ); + for (int i = 0; i < tokens.getCount(); i++) { + TokenRegisterEntry *tre = tokens[i]; + if (!(tre->tr.flags & TRF_PARSEFUNC) && tre->tr.szService != NULL) + mir_free(tre->tr.szService); if (tre->tr.tszTokenString != NULL) - mir_free( tre->tr.tszTokenString ); + mir_free(tre->tr.tszTokenString); if (tre->tr.szHelpText != NULL) - mir_free( tre->tr.szHelpText ); + mir_free(tre->tr.szHelpText); - if (( tre->tr.flags & TRF_CLEANUP ) && !( tre->tr.flags & TRF_CLEANUPFUNC ) && tre->tr.szCleanupService != NULL) - mir_free( tre->tr.szCleanupService ); + if ((tre->tr.flags & TRF_CLEANUP) && !(tre->tr.flags & TRF_CLEANUPFUNC) && tre->tr.szCleanupService != NULL) + mir_free(tre->tr.szCleanupService); - mir_free( tre ); + mir_free(tre); } - List_Destroy(( SortedList* )&tokens ); + tokens.destroy(); - LeaveCriticalSection(&csRegister); DeleteCriticalSection(&csRegister); - return 0; } diff --git a/plugins/Variables/src/variables.h b/plugins/Variables/src/variables.h index d74a602034..ea8b5057ae 100644 --- a/plugins/Variables/src/variables.h +++ b/plugins/Variables/src/variables.h @@ -2,7 +2,7 @@ Variables Plugin for Miranda-IM (www.miranda-im.org) Copyright 2003-2006 P. Boon - This program is mir_free software; you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -166,7 +166,7 @@ int registerStrTokens(); // variables int registerVariablesTokens(); void unregisterVariablesTokens(); -int clearVariableRegister(); +int clearVariableRegister(bool bAll); // logic int registerLogicTokens(); // math -- cgit v1.2.3