summaryrefslogtreecommitdiff
path: root/plugins/Variables/parse_system.cpp
diff options
context:
space:
mode:
authorVlad Mironov <mironych@googlemail.com>2012-07-04 12:03:37 +0000
committerVlad Mironov <mironych@googlemail.com>2012-07-04 12:03:37 +0000
commitfd97f5275ed5f18651c4cb7d7de397fbd5edf226 (patch)
tree99b140b0605a55867ae75c083c6ffdc3c62a9fe8 /plugins/Variables/parse_system.cpp
parent103919b61281ed54c859021bea7aefba8e9ac023 (diff)
Исправлена функция ?directory()
git-svn-id: http://svn.miranda-ng.org/main/trunk@754 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Variables/parse_system.cpp')
-rw-r--r--plugins/Variables/parse_system.cpp42
1 files changed, 18 insertions, 24 deletions
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;
}