From b81ce648978e75bc7db4cc3b8aa7d1b9fcb9239b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 21 Jun 2015 22:00:16 +0000 Subject: MS_UTILS_REPLACEVARS -> Utils_ReplaceVars git-svn-id: http://svn.miranda-ng.org/main/trunk@14316 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_app/src/chat_tools.cpp | 52 ++++++++++++-------------- src/mir_app/src/mir_app.def | 2 + src/mir_app/src/mir_app64.def | 2 + src/mir_app/src/path.cpp | 84 ++++++++++++++++++++---------------------- src/mir_app/src/utils.cpp | 3 -- 5 files changed, 67 insertions(+), 76 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index fd72ed1ea1..6d2c7f0a66 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -707,38 +707,38 @@ TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) if (si->pszLogFileName[0] == 0) { REPLACEVARSARRAY rva[11]; - rva[0].lptzKey = _T("d"); - rva[0].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%#d"), tTime)); + rva[0].key.t = _T("d"); + rva[0].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%#d"), tTime)); // day 01-31 - rva[1].lptzKey = _T("dd"); - rva[1].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%d"), tTime)); + rva[1].key.t = _T("dd"); + rva[1].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%d"), tTime)); // month 1-12 - rva[2].lptzKey = _T("m"); - rva[2].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%#m"), tTime)); + rva[2].key.t = _T("m"); + rva[2].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%#m"), tTime)); // month 01-12 - rva[3].lptzKey = _T("mm"); - rva[3].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%m"), tTime)); + rva[3].key.t = _T("mm"); + rva[3].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%m"), tTime)); // month text short - rva[4].lptzKey = _T("mon"); - rva[4].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%b"), tTime)); + rva[4].key.t = _T("mon"); + rva[4].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%b"), tTime)); // month text - rva[5].lptzKey = _T("month"); - rva[5].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%B"), tTime)); + rva[5].key.t = _T("month"); + rva[5].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%B"), tTime)); // year 01-99 - rva[6].lptzKey = _T("yy"); - rva[6].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%y"), tTime)); + rva[6].key.t = _T("yy"); + rva[6].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%y"), tTime)); // year 1901-9999 - rva[7].lptzKey = _T("yyyy"); - rva[7].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%Y"), tTime)); + rva[7].key.t = _T("yyyy"); + rva[7].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%Y"), tTime)); // weekday short - rva[8].lptzKey = _T("wday"); - rva[8].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%a"), tTime)); + rva[8].key.t = _T("wday"); + rva[8].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%a"), tTime)); // weekday - rva[9].lptzKey = _T("weekday"); - rva[9].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%A"), tTime)); + rva[9].key.t = _T("weekday"); + rva[9].value.t = mir_tstrdup(ci.MakeTimeStamp(_T("%A"), tTime)); // end of array - rva[10].lptzKey = NULL; - rva[10].lptzValue = NULL; + rva[10].key.t = NULL; + rva[10].value.t = NULL; TCHAR tszTemp[MAX_PATH], *ptszVarPath; if (g_Settings->pszLogDir[mir_tstrlen(g_Settings->pszLogDir) - 1] == '\\') { @@ -747,11 +747,7 @@ TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) } else ptszVarPath = g_Settings->pszLogDir; - REPLACEVARSDATA dat = { sizeof(dat) }; - dat.dwFlags = RVF_TCHAR; - dat.hContact = si->hContact; - dat.variables = rva; - TCHAR *tszParsedName = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)ptszVarPath, (LPARAM)&dat); + TCHAR *tszParsedName = Utils_ReplaceVarsT(ptszVarPath, si->hContact, rva); if (ci.OnGetLogName) ci.OnGetLogName(si, tszParsedName); else @@ -759,7 +755,7 @@ TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) mir_free(tszParsedName); for (int i = 0; i < _countof(rva); i++) - mir_free(rva[i].lptzValue); + mir_free(rva[i].value.t); for (TCHAR *p = si->pszLogFileName + 2; *p; ++p) if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || *p == '<' || *p == '>' || *p == '|') diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 705b522454..0668cf9561 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -198,3 +198,5 @@ xmlToFile @195 xmlToString @196 xmlToStringWithFormatting @197 KillModuleMenus @198 +Utils_ReplaceVars @199 +Utils_ReplaceVarsW @200 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 414562cd74..69d189d5f2 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -198,3 +198,5 @@ xmlToFile @195 xmlToString @196 xmlToStringWithFormatting @197 KillModuleMenus @198 +Utils_ReplaceVars @199 +Utils_ReplaceVarsW @200 diff --git a/src/mir_app/src/path.cpp b/src/mir_app/src/path.cpp index ce9e92e4c8..058d9b4284 100644 --- a/src/mir_app/src/path.cpp +++ b/src/mir_app/src/path.cpp @@ -74,16 +74,16 @@ static __forceinline int _xcsncmp(const char *s1, const char *s2, size_t n) { re static __forceinline size_t _xcslen(const char *s1) { return strlen(s1); } static __forceinline char *_xcscpy(char *s1, const char *s2) { return strcpy(s1, s2); } static __forceinline char *_xcsncpy(char *s1, const char *s2, size_t n) { return strncpy(s1, s2, n); } -static __forceinline char *_xstrselect(char *, char *s1, TCHAR*) { return s1; } -static __forceinline char *_itox(char *, int a) { return itoa(a, (char *)mir_alloc(sizeof(char)*20), 10); } -static __forceinline char *mir_a2x(char *, char *s) { return mir_strdup(s); } +static __forceinline const char *_xstrselect(const char*, const char *s1, TCHAR*) { return s1; } +static __forceinline char *_itox(char*, int a) { return itoa(a, (char *)mir_alloc(sizeof(char)*20), 10); } +static __forceinline char *mir_a2x(const char*, const char *s) { return mir_strdup(s); } -static __forceinline char *GetContactNickX(char *, MCONTACT hContact) +static __forceinline char *GetContactNickX(const char*, MCONTACT hContact) { return mir_strdup((char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, 0)); } -static __forceinline char *GetContactIDX(char *, MCONTACT hContact) +static __forceinline char *GetContactIDX(const char*, MCONTACT hContact) { TCHAR *id = GetContactID(hContact); char* res = mir_t2a(id); @@ -91,7 +91,7 @@ static __forceinline char *GetContactIDX(char *, MCONTACT hContact) return res; } -static __forceinline char *GetEnvironmentVariableX(char *variable) +static __forceinline char *GetEnvironmentVariableX(const char *variable) { char result[512]; if (GetEnvironmentVariableA(variable, result, _countof(result))) @@ -99,7 +99,7 @@ static __forceinline char *GetEnvironmentVariableX(char *variable) return NULL; } -static __forceinline char *GetProfileDirX(char*) +static __forceinline char *GetProfileDirX(const char*) { return mir_t2a(g_profileDir); } @@ -112,7 +112,7 @@ static __forceinline char *SHGetSpecialFolderPathX(int iCSIDL, char*) return NULL; } -static __forceinline char *GetModulePathX(char *, HMODULE hModule) +static __forceinline char *GetModulePathX(const char*, HMODULE hModule) { char result[MAX_PATH]; GetModuleFileNameA(hModule, result, sizeof(result)); @@ -121,7 +121,7 @@ static __forceinline char *GetModulePathX(char *, HMODULE hModule) return mir_strdup(result); } -static __forceinline char *GetUserNameX(char *) +static __forceinline char *GetUserNameX(const char*) { char result[128]; DWORD size = _countof(result); @@ -130,12 +130,12 @@ static __forceinline char *GetUserNameX(char *) return NULL; } -static __forceinline char *GetProfileNameX(char *) +static __forceinline char *GetProfileNameX(const char*) { return mir_t2a(g_shortProfileName); } -static __forceinline char *GetPathVarX(char *, int code) +static __forceinline char* GetPathVarX(const char*, int code) { TCHAR szFullPath[MAX_PATH]; @@ -159,23 +159,23 @@ static __forceinline char *GetPathVarX(char *, int code) static __forceinline int _xcscmp(const TCHAR *s1, const TCHAR *s2) { return _tcscmp(s1, s2); } static __forceinline int _xcsncmp(const TCHAR *s1, const TCHAR *s2, size_t n) { return _tcsncmp(s1, s2, n); } static __forceinline size_t _xcslen(const TCHAR *s1) { return _tcslen(s1); } -static __forceinline TCHAR *_xcscpy(TCHAR *s1, const TCHAR *s2) { return _tcscpy(s1, s2); } -static __forceinline TCHAR *_xcsncpy(TCHAR *s1, const TCHAR *s2, size_t n) { return _tcsncpy(s1, s2, n); } -static __forceinline TCHAR *_xstrselect(TCHAR*, char*, TCHAR *s2) { return s2; } -static __forceinline TCHAR *_itox(TCHAR *, int a) { return _itot(a, (TCHAR *)mir_alloc(sizeof(TCHAR)*20), 10); } -static __forceinline TCHAR *mir_a2x(TCHAR *, char *s) { return mir_a2t(s); } +static __forceinline TCHAR* _xcscpy(TCHAR *s1, const TCHAR *s2) { return _tcscpy(s1, s2); } +static __forceinline TCHAR* _xcsncpy(TCHAR *s1, const TCHAR *s2, size_t n) { return _tcsncpy(s1, s2, n); } +static __forceinline const TCHAR* _xstrselect(const TCHAR*, const char*, const TCHAR *s2) { return s2; } +static __forceinline TCHAR* _itox(TCHAR *, int a) { return _itot(a, (TCHAR *)mir_alloc(sizeof(TCHAR)*20), 10); } +static __forceinline TCHAR* mir_a2x(const TCHAR *, const char *s) { return mir_a2t(s); } -static __forceinline TCHAR *GetContactNickX(TCHAR *, MCONTACT hContact) +static __forceinline TCHAR* GetContactNickX(const TCHAR*, MCONTACT hContact) { - return mir_tstrdup((TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR)); + return mir_tstrdup((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR)); } -static __forceinline TCHAR *GetContactIDX(TCHAR *, MCONTACT hContact) +static __forceinline TCHAR* GetContactIDX(const TCHAR*, MCONTACT hContact) { return GetContactID(hContact); } -static __forceinline TCHAR *GetEnvironmentVariableX(TCHAR *variable) +static __forceinline TCHAR* GetEnvironmentVariableX(const TCHAR *variable) { TCHAR result[512]; if (GetEnvironmentVariable(variable, result, _countof(result))) @@ -183,7 +183,7 @@ static __forceinline TCHAR *GetEnvironmentVariableX(TCHAR *variable) return NULL; } -static __forceinline TCHAR *SHGetSpecialFolderPathX(int iCSIDL, TCHAR*) +static __forceinline TCHAR* SHGetSpecialFolderPathX(int iCSIDL, TCHAR*) { TCHAR result[512]; if (SHGetSpecialFolderPath(NULL, result, iCSIDL, FALSE)) @@ -191,12 +191,12 @@ static __forceinline TCHAR *SHGetSpecialFolderPathX(int iCSIDL, TCHAR*) return NULL; } -static __forceinline TCHAR *GetProfileDirX(TCHAR*) +static __forceinline TCHAR* GetProfileDirX(const TCHAR*) { return mir_tstrdup(g_profileDir); } -static __forceinline TCHAR *GetModulePathX(TCHAR *, HMODULE hModule) +static __forceinline TCHAR* GetModulePathX(const TCHAR*, HMODULE hModule) { TCHAR result[MAX_PATH]; GetModuleFileName(hModule, result, _countof(result)); @@ -205,7 +205,7 @@ static __forceinline TCHAR *GetModulePathX(TCHAR *, HMODULE hModule) return mir_tstrdup(result); } -static __forceinline TCHAR *GetUserNameX(TCHAR *) +static __forceinline TCHAR* GetUserNameX(const TCHAR*) { TCHAR result[128]; DWORD size = _countof(result); @@ -214,12 +214,12 @@ static __forceinline TCHAR *GetUserNameX(TCHAR *) return NULL; } -static __forceinline TCHAR *GetProfileNameX(TCHAR *) +static __forceinline TCHAR* GetProfileNameX(const TCHAR*) { return mir_tstrdup(g_shortProfileName); } -static __forceinline TCHAR *GetPathVarX(TCHAR *, int code) +static __forceinline TCHAR* GetPathVarX(const TCHAR*, int code) { TCHAR szFullPath[MAX_PATH]; @@ -241,7 +241,7 @@ static __forceinline TCHAR *GetPathVarX(TCHAR *, int code) } template -XCHAR *GetInternalVariable(XCHAR *key, size_t keyLength, MCONTACT hContact) +XCHAR *GetInternalVariable(const XCHAR *key, size_t keyLength, MCONTACT hContact) { XCHAR *theValue = NULL; XCHAR *theKey = (XCHAR *)_alloca(sizeof(XCHAR) * (keyLength + 1)); @@ -292,25 +292,24 @@ XCHAR *GetInternalVariable(XCHAR *key, size_t keyLength, MCONTACT hContact) } template -XCHAR *GetVariableFromArray(REPLACEVARSARRAY *vars, XCHAR *key, size_t keyLength, MCONTACT hContact, bool *bFree) +XCHAR *GetVariableFromArray(REPLACEVARSARRAY *vars, const XCHAR *key, size_t keyLength, MCONTACT hContact, bool *bFree) { *bFree = false; - for (REPLACEVARSARRAY *var = vars; var && var->lptzKey; ++var) - if ((_xcslen((XCHAR *)var->lptzKey) == keyLength) && !_xcsncmp(key, (XCHAR *)var->lptzKey, keyLength)) - return (XCHAR *)var->lptzValue; + for (REPLACEVARSARRAY *var = vars; var && var->key.a; ++var) + if ((_xcslen((XCHAR *)var->key.a) == keyLength) && !_xcsncmp(key, (XCHAR *)var->key.a, keyLength)) + return (XCHAR *)var->value.a; *bFree = true; return GetInternalVariable(key, keyLength, hContact); } template -XCHAR *ReplaceVariables(XCHAR *str, REPLACEVARSDATA *data) +XCHAR *ReplaceVariables(const XCHAR *str, MCONTACT hContact, REPLACEVARSARRAY *variables) { if (!str) return NULL; - XCHAR *p; - XCHAR *varStart = 0; + const XCHAR *varStart = 0, *p; size_t length = 0; bool bFree; @@ -319,7 +318,7 @@ XCHAR *ReplaceVariables(XCHAR *str, REPLACEVARSDATA *data) if (varStart) { if (p == varStart) length++; - else if (XCHAR *value = GetVariableFromArray(data->variables, varStart, p-varStart, data->hContact, &bFree)) { + else if (XCHAR *value = GetVariableFromArray(variables, varStart, p-varStart, hContact, &bFree)) { length += _xcslen(value); if (bFree) mir_free(value); } @@ -345,7 +344,7 @@ XCHAR *ReplaceVariables(XCHAR *str, REPLACEVARSDATA *data) if (varStart) { if (p == varStart) *q++='%'; - else if (XCHAR *value = GetVariableFromArray(data->variables, varStart, p-varStart, data->hContact, &bFree)) { + else if (XCHAR *value = GetVariableFromArray(variables, varStart, p-varStart, hContact, &bFree)) { _xcscpy(q, value); q += _xcslen(value); if (bFree) mir_free(value); @@ -374,19 +373,14 @@ XCHAR *ReplaceVariables(XCHAR *str, REPLACEVARSDATA *data) return result; } -static INT_PTR replaceVars(WPARAM wParam, LPARAM lParam) +MIR_APP_DLL(char*) Utils_ReplaceVars(const char *szData, MCONTACT hContact, REPLACEVARSARRAY *vars) { - REPLACEVARSDATA *data = (REPLACEVARSDATA *)lParam; - if (data->dwFlags & RVF_UNICODE) - return (INT_PTR)ReplaceVariables((WCHAR *)wParam, data); - - return (INT_PTR)ReplaceVariables((char *)wParam, data); + return ReplaceVariables(szData, hContact, vars); } -int InitPathUtils(void) +MIR_APP_DLL(wchar_t*) Utils_ReplaceVarsW(const wchar_t *wszData, MCONTACT hContact, REPLACEVARSARRAY *vars) { - CreateServiceFunction(MS_UTILS_REPLACEVARS, replaceVars); - return 0; + return ReplaceVariables(wszData, hContact, vars); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/mir_app/src/utils.cpp b/src/mir_app/src/utils.cpp index f62f41f574..666fcf5be5 100644 --- a/src/mir_app/src/utils.cpp +++ b/src/mir_app/src/utils.cpp @@ -28,8 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. INT_PTR ResizeDialog(WPARAM wParam, LPARAM lParam); -int InitPathUtils(void); - int InitCrypt(void); void UninitCrypt(void); @@ -329,7 +327,6 @@ int LoadUtilsModule(void) CreateServiceFunction(MS_UTILS_ENTERSTRING, svcEnterString); - InitPathUtils(); InitCrypt(); return 0; } -- cgit v1.2.3