From fd97f5275ed5f18651c4cb7d7de397fbd5edf226 Mon Sep 17 00:00:00 2001 From: Vlad Mironov Date: Wed, 4 Jul 2012 12:03:37 +0000 Subject: =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20=3Fdirect?= =?UTF-8?q?ory()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.miranda-ng.org/main/trunk@754 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Variables/parse_system.cpp | 42 ++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) (limited to 'plugins') diff --git a/plugins/Variables/parse_system.cpp b/plugins/Variables/parse_system.cpp index 28dc3d4224..e5db6af03e 100644 --- a/plugins/Variables/parse_system.cpp +++ b/plugins/Variables/parse_system.cpp @@ -179,42 +179,36 @@ static TCHAR *parseCurrentTime(ARGUMENTSINFO *ai) { static TCHAR *parseDirectory(ARGUMENTSINFO *ai) { - int depth; - TCHAR *res, *ecur, *scur; + int depth, bi, ei; + TCHAR *res; if (ai->argc < 2 || ai->argc > 3 ) return NULL; - depth = 1; + depth = 0; if (ai->argc == 3) depth = ttoi(ai->targv[2]); if (depth <= 0) - return NULL; - - ecur = ai->targv[1]+_tcslen(ai->targv[1]); - while (depth > 0) { - while ( (*ecur != _T('\\')) && (ecur > ai->targv[1])) - ecur--; + return ai->targv[1]; - if (*ecur != _T('\\')) - return NULL; - - depth -= 1; - ecur--; + for (ei = 0; ei < _tcslen(ai->targv[1]); ei++) + { + if (ai->targv[1][ei] == '\\') + depth--; + if (!depth) break; + } + if (ei >= _tcslen(ai->targv[1])) + return ai->targv[1]; + for (bi = ei - 1; bi > 0; bi--) + { + if (ai->targv[1][bi - 1] == '\\') break; } - scur = ecur; - while ( (*scur != _T('\\')) && (scur > ai->targv[1])) - scur--; - - if (*scur == _T('\\')) - scur++; - res = (TCHAR*)mir_alloc((ecur-scur+2) * sizeof(TCHAR)); - if (res == NULL) - return NULL; + res = (TCHAR*)mir_alloc((ei - bi + 1) * sizeof(TCHAR)); + _tcsncpy(res, ai->targv[1] + bi, ei - bi); + res[ei - bi] = 0; - _tcsncpy(res, scur, (ecur-scur)+1); return res; } -- cgit v1.2.3