Author: jmorlan
Date: Sun Jan 25 10:39:06 2009
New Revision: 39095
URL:
http://svn.reactos.org/svn/reactos?rev=39095&view=rev
Log:
split, splitspace: Allow quotation marks anywhere in an argument, not just the start and
end. (Bug 4054)
Modified:
trunk/reactos/base/shell/cmd/misc.c
Modified: trunk/reactos/base/shell/cmd/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/misc.c?rev=…
==============================================================================
--- trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] Sun Jan 25 10:39:06 2009
@@ -295,7 +295,6 @@
LPTSTR q;
INT ac;
INT len;
- BOOL bQuoted = FALSE;
arg = cmd_alloc (sizeof (LPTSTR));
if (!arg)
@@ -305,17 +304,12 @@
ac = 0;
while (*s)
{
+ BOOL bQuoted = FALSE;
+
/* skip leading spaces */
while (*s && (_istspace (*s) || _istcntrl (*s)))
++s;
- /* if quote (") then set bQuoted */
- if (*s == _T('\"'))
- {
- ++s;
- bQuoted = TRUE;
- }
-
start = s;
/* the first character can be '/' */
@@ -323,15 +317,11 @@
++s;
/* skip to next word delimiter or start of next option */
- if (bQuoted)
- {
- while (_istprint (*s) && (*s != _T('\"')) && (*s !=
_T('/')))
- ++s;
- }
- else
- {
- while (_istprint (*s) && !_istspace (*s) && (*s != _T('/')))
- ++s;
+ while (_istprint(*s) && (bQuoted || (!_istspace(*s) && *s !=
_T('/'))))
+ {
+ /* if quote (") then set bQuoted */
+ bQuoted ^= (*s == _T('\"'));
+ ++s;
}
/* a word was found */
@@ -344,6 +334,7 @@
}
memcpy (q, start, len * sizeof (TCHAR));
q[len] = _T('\0');
+ StripQuotes(q);
if (expand_wildcards && _T('/') != *start &&
(NULL != _tcschr(q, _T('*')) || NULL != _tcschr(q, _T('?'))))
{
@@ -365,19 +356,6 @@
}
cmd_free (q);
}
-
- /* adjust string pointer if quoted (") */
- if (bQuoted)
- {
- /* Check to make sure if there is no ending "
- * we dont run over the null char */
- if(*s == _T('\0'))
- {
- break;
- }
- ++s;
- bQuoted = FALSE;
- }
}
*args = ac;
@@ -396,7 +374,6 @@
LPTSTR q;
INT ac;
INT len;
- BOOL bQuoted = FALSE;
arg = cmd_alloc (sizeof (LPTSTR));
if (!arg)
@@ -406,29 +383,20 @@
ac = 0;
while (*s)
{
+ BOOL bQuoted = FALSE;
+
/* skip leading spaces */
while (*s && (_istspace (*s) || _istcntrl (*s)))
++s;
- /* if quote (") then set bQuoted */
- if (*s == _T('\"'))
- {
+ start = s;
+
+ /* skip to next word delimiter or start of next option */
+ while (_istprint(*s) && (bQuoted || !_istspace(*s)))
+ {
+ /* if quote (") then set bQuoted */
+ bQuoted ^= (*s == _T('\"'));
++s;
- bQuoted = TRUE;
- }
-
- start = s;
-
- /* skip to next word delimiter or start of next option */
- if (bQuoted)
- {
- while (_istprint (*s) && (*s != _T('\"')))
- ++s;
- }
- else
- {
- while (_istprint (*s) && !_istspace (*s))
- ++s;
}
/* a word was found */
@@ -441,6 +409,7 @@
}
memcpy (q, start, len * sizeof (TCHAR));
q[len] = _T('\0');
+ StripQuotes(q);
if (! add_entry(&ac, &arg, q))
{
cmd_free (q);
@@ -448,19 +417,6 @@
return NULL;
}
cmd_free (q);
- }
-
- /* adjust string pointer if quoted (") */
- if (bQuoted)
- {
- /* Check to make sure if there is no ending "
- * we dont run over the null char */
- if(*s == _T('\0'))
- {
- break;
- }
- ++s;
- bQuoted = FALSE;
}
}