mirror of
https://github.com/reactos/reactos.git
synced 2024-09-30 22:47:28 +00:00
[CMD] Fix batch/CALL arguments initialization.
- Move initialization of bc->raw_params also in BatchParams(). - The bc->raw_params, i.e. the unparsed batch/CALL parameters obtained with %*, has any leading and trailing whitespace trimmed (since Windows 2000+).
This commit is contained in:
parent
37bda06eed
commit
f0fccb752f
|
@ -112,55 +112,85 @@ FindArg(
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Batch_params builds a parameter list in newly allocated memory.
|
* Builds the batch parameter list in newly allocated memory.
|
||||||
* The parameters consist of null terminated strings with a final
|
* The parameters consist of NULL terminated strings with a
|
||||||
* NULL character signalling the end of the parameters.
|
* final NULL character signalling the end of the parameters.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
static LPTSTR BatchParams(LPTSTR s1, LPTSTR s2)
|
static BOOL
|
||||||
|
BatchParams(
|
||||||
|
IN PCTSTR Arg0,
|
||||||
|
IN PCTSTR Args,
|
||||||
|
OUT PTSTR* RawParams,
|
||||||
|
OUT PTSTR* ParamList)
|
||||||
{
|
{
|
||||||
LPTSTR dp = (LPTSTR)cmd_alloc((_tcslen(s1) + _tcslen(s2) + 3) * sizeof (TCHAR));
|
PTSTR dp;
|
||||||
|
SIZE_T len;
|
||||||
|
|
||||||
/* JPP 20-Jul-1998 added error checking */
|
*RawParams = NULL;
|
||||||
if (dp == NULL)
|
*ParamList = NULL;
|
||||||
|
|
||||||
|
/* Make a raw copy of the parameters, but trim any leading and trailing whitespace */
|
||||||
|
// Args += _tcsspn(Args, _T(" \t"));
|
||||||
|
while (_istspace(*Args))
|
||||||
|
++Args;
|
||||||
|
dp = (PTSTR)Args + _tcslen(Args);
|
||||||
|
while ((dp > Args) && _istspace(*(dp - 1)))
|
||||||
|
--dp;
|
||||||
|
len = dp - Args;
|
||||||
|
*RawParams = (PTSTR)cmd_alloc((len + 1)* sizeof(TCHAR));
|
||||||
|
if (!*RawParams)
|
||||||
{
|
{
|
||||||
WARN("Cannot allocate memory for dp!\n");
|
WARN("Cannot allocate memory for RawParams!\n");
|
||||||
error_out_of_memory();
|
error_out_of_memory();
|
||||||
return NULL;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
_tcsncpy(*RawParams, Args, len);
|
||||||
|
(*RawParams)[len] = _T('\0');
|
||||||
|
|
||||||
if (s1 && *s1)
|
/* Parse the parameters as well */
|
||||||
|
Args = *RawParams;
|
||||||
|
|
||||||
|
*ParamList = (PTSTR)cmd_alloc((_tcslen(Arg0) + _tcslen(Args) + 3) * sizeof(TCHAR));
|
||||||
|
if (!*ParamList)
|
||||||
{
|
{
|
||||||
s1 = _stpcpy (dp, s1);
|
WARN("Cannot allocate memory for ParamList!\n");
|
||||||
*s1++ = _T('\0');
|
error_out_of_memory();
|
||||||
|
cmd_free(*RawParams);
|
||||||
|
*RawParams = NULL;
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
s1 = dp;
|
|
||||||
|
|
||||||
while (*s2)
|
dp = *ParamList;
|
||||||
|
|
||||||
|
if (Arg0 && *Arg0)
|
||||||
|
{
|
||||||
|
dp = _stpcpy(dp, Arg0);
|
||||||
|
*dp++ = _T('\0');
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*Args)
|
||||||
{
|
{
|
||||||
BOOL inquotes = FALSE;
|
BOOL inquotes = FALSE;
|
||||||
|
|
||||||
/* Find next parameter */
|
/* Find next parameter */
|
||||||
while (_istspace(*s2) || (*s2 && _tcschr(STANDARD_SEPS, *s2)))
|
while (_istspace(*Args) || (*Args && _tcschr(STANDARD_SEPS, *Args)))
|
||||||
s2++;
|
++Args;
|
||||||
if (!*s2)
|
if (!*Args)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Copy it */
|
/* Copy it */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!inquotes && (_istspace(*s2) || _tcschr(STANDARD_SEPS, *s2)))
|
if (!inquotes && (_istspace(*Args) || _tcschr(STANDARD_SEPS, *Args)))
|
||||||
break;
|
break;
|
||||||
inquotes ^= (*s2 == _T('"'));
|
inquotes ^= (*Args == _T('"'));
|
||||||
*s1++ = *s2++;
|
*dp++ = *Args++;
|
||||||
} while (*s2);
|
} while (*Args);
|
||||||
*s1++ = _T('\0');
|
*dp++ = _T('\0');
|
||||||
}
|
}
|
||||||
|
*dp = _T('\0');
|
||||||
|
|
||||||
*s1 = _T('\0');
|
return TRUE;
|
||||||
|
|
||||||
return dp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -368,14 +398,9 @@ INT Batch(LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < 10; i++)
|
||||||
bc->shiftlevel[i] = i;
|
bc->shiftlevel[i] = i;
|
||||||
|
|
||||||
/* Parse the parameters and make a raw copy of them without modifications */
|
/* Parse the batch parameters */
|
||||||
bc->params = BatchParams(firstword, param);
|
if (!BatchParams(firstword, param, &bc->raw_params, &bc->params))
|
||||||
bc->raw_params = cmd_dup(param);
|
|
||||||
if (bc->raw_params == NULL)
|
|
||||||
{
|
|
||||||
error_out_of_memory();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
/* If we are calling from inside a FOR, hide the FOR variables */
|
/* If we are calling from inside a FOR, hide the FOR variables */
|
||||||
saved_fc = fc;
|
saved_fc = fc;
|
||||||
|
|
Loading…
Reference in a new issue