mirror of
https://github.com/reactos/reactos.git
synced 2025-04-26 16:40:27 +00:00
split, splitspace: Allow quotation marks anywhere in an argument, not just the start and end. (Bug 4054)
svn path=/trunk/; revision=39095
This commit is contained in:
parent
931eb2e0b0
commit
4d6bf5e49a
1 changed files with 14 additions and 58 deletions
|
@ -295,7 +295,6 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
|
||||||
LPTSTR q;
|
LPTSTR q;
|
||||||
INT ac;
|
INT ac;
|
||||||
INT len;
|
INT len;
|
||||||
BOOL bQuoted = FALSE;
|
|
||||||
|
|
||||||
arg = cmd_alloc (sizeof (LPTSTR));
|
arg = cmd_alloc (sizeof (LPTSTR));
|
||||||
if (!arg)
|
if (!arg)
|
||||||
|
@ -305,17 +304,12 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
|
||||||
ac = 0;
|
ac = 0;
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
|
BOOL bQuoted = FALSE;
|
||||||
|
|
||||||
/* skip leading spaces */
|
/* skip leading spaces */
|
||||||
while (*s && (_istspace (*s) || _istcntrl (*s)))
|
while (*s && (_istspace (*s) || _istcntrl (*s)))
|
||||||
++s;
|
++s;
|
||||||
|
|
||||||
/* if quote (") then set bQuoted */
|
|
||||||
if (*s == _T('\"'))
|
|
||||||
{
|
|
||||||
++s;
|
|
||||||
bQuoted = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
start = s;
|
start = s;
|
||||||
|
|
||||||
/* the first character can be '/' */
|
/* the first character can be '/' */
|
||||||
|
@ -323,14 +317,10 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
|
||||||
++s;
|
++s;
|
||||||
|
|
||||||
/* skip to next word delimiter or start of next option */
|
/* skip to next word delimiter or start of next option */
|
||||||
if (bQuoted)
|
while (_istprint(*s) && (bQuoted || (!_istspace(*s) && *s != _T('/'))))
|
||||||
{
|
{
|
||||||
while (_istprint (*s) && (*s != _T('\"')) && (*s != _T('/')))
|
/* if quote (") then set bQuoted */
|
||||||
++s;
|
bQuoted ^= (*s == _T('\"'));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (_istprint (*s) && !_istspace (*s) && (*s != _T('/')))
|
|
||||||
++s;
|
++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +334,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
|
||||||
}
|
}
|
||||||
memcpy (q, start, len * sizeof (TCHAR));
|
memcpy (q, start, len * sizeof (TCHAR));
|
||||||
q[len] = _T('\0');
|
q[len] = _T('\0');
|
||||||
|
StripQuotes(q);
|
||||||
if (expand_wildcards && _T('/') != *start &&
|
if (expand_wildcards && _T('/') != *start &&
|
||||||
(NULL != _tcschr(q, _T('*')) || NULL != _tcschr(q, _T('?'))))
|
(NULL != _tcschr(q, _T('*')) || NULL != _tcschr(q, _T('?'))))
|
||||||
{
|
{
|
||||||
|
@ -365,19 +356,6 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
|
||||||
}
|
}
|
||||||
cmd_free (q);
|
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;
|
*args = ac;
|
||||||
|
@ -396,7 +374,6 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
|
||||||
LPTSTR q;
|
LPTSTR q;
|
||||||
INT ac;
|
INT ac;
|
||||||
INT len;
|
INT len;
|
||||||
BOOL bQuoted = FALSE;
|
|
||||||
|
|
||||||
arg = cmd_alloc (sizeof (LPTSTR));
|
arg = cmd_alloc (sizeof (LPTSTR));
|
||||||
if (!arg)
|
if (!arg)
|
||||||
|
@ -406,28 +383,19 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
|
||||||
ac = 0;
|
ac = 0;
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
|
BOOL bQuoted = FALSE;
|
||||||
|
|
||||||
/* skip leading spaces */
|
/* skip leading spaces */
|
||||||
while (*s && (_istspace (*s) || _istcntrl (*s)))
|
while (*s && (_istspace (*s) || _istcntrl (*s)))
|
||||||
++s;
|
++s;
|
||||||
|
|
||||||
/* if quote (") then set bQuoted */
|
|
||||||
if (*s == _T('\"'))
|
|
||||||
{
|
|
||||||
++s;
|
|
||||||
bQuoted = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
start = s;
|
start = s;
|
||||||
|
|
||||||
/* skip to next word delimiter or start of next option */
|
/* skip to next word delimiter or start of next option */
|
||||||
if (bQuoted)
|
while (_istprint(*s) && (bQuoted || !_istspace(*s)))
|
||||||
{
|
{
|
||||||
while (_istprint (*s) && (*s != _T('\"')))
|
/* if quote (") then set bQuoted */
|
||||||
++s;
|
bQuoted ^= (*s == _T('\"'));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (_istprint (*s) && !_istspace (*s))
|
|
||||||
++s;
|
++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,6 +409,7 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
|
||||||
}
|
}
|
||||||
memcpy (q, start, len * sizeof (TCHAR));
|
memcpy (q, start, len * sizeof (TCHAR));
|
||||||
q[len] = _T('\0');
|
q[len] = _T('\0');
|
||||||
|
StripQuotes(q);
|
||||||
if (! add_entry(&ac, &arg, q))
|
if (! add_entry(&ac, &arg, q))
|
||||||
{
|
{
|
||||||
cmd_free (q);
|
cmd_free (q);
|
||||||
|
@ -449,19 +418,6 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
|
||||||
}
|
}
|
||||||
cmd_free (q);
|
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;
|
*args = ac;
|
||||||
|
|
Loading…
Reference in a new issue