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:
Jeffrey Morlan 2009-01-25 16:39:06 +00:00
parent 931eb2e0b0
commit 4d6bf5e49a

View file

@ -295,7 +295,6 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
LPTSTR q;
INT ac;
INT len;
BOOL bQuoted = FALSE;
arg = cmd_alloc (sizeof (LPTSTR));
if (!arg)
@ -305,17 +304,12 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
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 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
++s;
/* 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('/')))
++s;
}
else
{
while (_istprint (*s) && !_istspace (*s) && (*s != _T('/')))
++s;
/* if quote (") then set bQuoted */
bQuoted ^= (*s == _T('\"'));
++s;
}
/* a word was found */
@ -344,6 +334,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
}
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 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
}
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 *splitspace (LPTSTR s, LPINT args)
LPTSTR q;
INT ac;
INT len;
BOOL bQuoted = FALSE;
arg = cmd_alloc (sizeof (LPTSTR));
if (!arg)
@ -406,29 +383,20 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
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;
/* skip to next word delimiter or start of next option */
if (bQuoted)
while (_istprint(*s) && (bQuoted || !_istspace(*s)))
{
while (_istprint (*s) && (*s != _T('\"')))
++s;
}
else
{
while (_istprint (*s) && !_istspace (*s))
++s;
/* if quote (") then set bQuoted */
bQuoted ^= (*s == _T('\"'));
++s;
}
/* a word was found */
@ -441,6 +409,7 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
}
memcpy (q, start, len * sizeof (TCHAR));
q[len] = _T('\0');
StripQuotes(q);
if (! add_entry(&ac, &arg, q))
{
cmd_free (q);
@ -449,19 +418,6 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
}
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;