From 48540940b6c28bb4378abfeb500ec45a625b37b6 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Tue, 15 May 2012 10:38:20 +0000 Subject: initial commit git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/variables/parse_alias.cpp | 226 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 plugins/variables/parse_alias.cpp (limited to 'plugins/variables/parse_alias.cpp') diff --git a/plugins/variables/parse_alias.cpp b/plugins/variables/parse_alias.cpp new file mode 100644 index 0000000000..49d7df3310 --- /dev/null +++ b/plugins/variables/parse_alias.cpp @@ -0,0 +1,226 @@ +/* + Variables Plugin for Miranda-IM (www.miranda-im.org) + Copyright 2003-2006 P. Boon + + 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. + + 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 +*/ +#include "variables.h" +#include "parse_alias.h" + +static CRITICAL_SECTION csAliasRegister; +static ALIASREGISTER *ar = NULL; +static unsigned int arCount = 0; + +static ALIASREGISTER *searchAliasRegister(TCHAR *szAlias) { + + ALIASREGISTER *res; + unsigned int i; + + res = NULL; + if ( (szAlias == NULL) || (_tcslen(szAlias) == 0) ) { + return NULL; + } + EnterCriticalSection(&csAliasRegister); + for (i=0;i _tcslen(tArg)) { + res = ( TCHAR* )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)); + } + } + cur++; + } + + return res; +} + +static TCHAR *parseTranslateAlias(ARGUMENTSINFO *ai) { + + unsigned int i; + TCHAR *res; + ALIASREGISTER *areg; + + areg = searchAliasRegister(ai->targv[0]); + if ( (areg == NULL) || (areg->argc != ai->argc-1) ) { + return NULL; + } + res = _tcsdup(areg->szTranslation); + for (i=0;iargc;i++) { + res = replaceArguments(res, areg->argv[i], ai->targv[i+1]); + if (res == NULL) { + return NULL; + } + } + + return res; +} + +static int addToAliasRegister(TCHAR *szAlias, unsigned int argc, TCHAR** argv, TCHAR *szTranslation) { + + unsigned int i, j; + + if ( szAlias == NULL || szTranslation == NULL || _tcslen(szAlias) == 0 ) + return -1; + + EnterCriticalSection(&csAliasRegister); + for (i=0;iargc != 3) + return NULL; + + cur = ai->targv[1]; + while (isValidTokenChar(*cur)) + cur++; + + alias = ( TCHAR* )calloc(((cur-ai->targv[1])+1), sizeof(TCHAR)); + if (alias == NULL) + return NULL; + + _tcsncpy(alias, ai->targv[1], (cur-ai->targv[1])); + getArguments(cur, &argv, &argc); + deRegisterToken(alias); + addToAliasRegister(alias, argc, argv, ai->targv[2]); + szArgs = NULL; + for (i=0;i 0) ) { +#ifdef UNICODE + szArgsA = u2a(szArgs); +#else + szArgsA = _strdup(szArgs); +#endif + szHelp = ( char* )malloc(32 + strlen(szArgsA)); + memset(szHelp, '\0', 32 + strlen(szArgsA)); + sprintf(szHelp, "Alias\t(%s)\tuser defined", szArgsA); + res = registerIntToken(alias, parseTranslateAlias, TRF_FUNCTION|TRF_UNPARSEDARGS, szHelp); + free(szArgsA); + } + else { + szHelp = ( char* )malloc(32); + memset(szHelp, '\0', 32); + sprintf(szHelp, "Alias\t\tuser defined"); + res = registerIntToken(alias, parseTranslateAlias, TRF_FIELD|TRF_UNPARSEDARGS, szHelp); + } + free(szArgs); + free(szHelp); + + return res==0?_tcsdup(_T("")):NULL; +} + +int registerAliasTokens() +{ + registerIntToken(_T(ADDALIAS), parseAddAlias, TRF_FUNCTION|TRF_UNPARSEDARGS, "Variables\t(x,y)\tstores y as alias named x");//TRF_UNPARSEDARGS); + InitializeCriticalSection(&csAliasRegister); + return 0; +} + +void unregisterAliasTokens() +{ + DeleteCriticalSection(&csAliasRegister); +} + -- cgit v1.2.3