cmd: Add an output parameter to WCMD_parameter to point to the end of the extracted param, if requested.
This commit is contained in:
parent
191056ad5c
commit
3627c28958
|
@ -123,6 +123,8 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
|
||||||
* Starts at 0
|
* Starts at 0
|
||||||
* where [O] if non NULL, pointer to the start of the nth parameter in s,
|
* where [O] if non NULL, pointer to the start of the nth parameter in s,
|
||||||
* potentially a " character
|
* potentially a " character
|
||||||
|
* end [O] if non NULL, pointer to the last char of
|
||||||
|
* the nth parameter in s, potentially a " character
|
||||||
*
|
*
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* Success: Returns the nth delimited parameter found in s.
|
* Success: Returns the nth delimited parameter found in s.
|
||||||
|
@ -136,14 +138,14 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
|
||||||
* after each call.
|
* after each call.
|
||||||
* Doesn't include any potentially delimiting double quotes
|
* Doesn't include any potentially delimiting double quotes
|
||||||
*/
|
*/
|
||||||
|
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end) {
|
||||||
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) {
|
|
||||||
int curParamNb = 0;
|
int curParamNb = 0;
|
||||||
static WCHAR param[MAX_PATH];
|
static WCHAR param[MAX_PATH];
|
||||||
WCHAR *p = s, *q;
|
WCHAR *p = s, *q;
|
||||||
BOOL quotesDelimited;
|
BOOL quotesDelimited;
|
||||||
|
|
||||||
if (where != NULL) *where = NULL;
|
if (where != NULL) *where = NULL;
|
||||||
|
if (end != NULL) *end = NULL;
|
||||||
param[0] = '\0';
|
param[0] = '\0';
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
while (*p && ((*p == ' ') || (*p == ',') || (*p == '=') || (*p == '\t')))
|
while (*p && ((*p == ' ') || (*p == ',') || (*p == '=') || (*p == '\t')))
|
||||||
|
@ -164,6 +166,7 @@ WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) {
|
||||||
if (curParamNb == n) {
|
if (curParamNb == n) {
|
||||||
memcpy(param, q, (p - q) * sizeof(WCHAR));
|
memcpy(param, q, (p - q) * sizeof(WCHAR));
|
||||||
param[p-q] = '\0';
|
param[p-q] = '\0';
|
||||||
|
if (end) *end = p - 1 + quotesDelimited;
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
if (quotesDelimited && *p == '"') p++;
|
if (quotesDelimited && *p == '"') p++;
|
||||||
|
@ -360,8 +363,9 @@ void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable,
|
||||||
if (*lastModifier == '0') {
|
if (*lastModifier == '0') {
|
||||||
strcpyW(outputparam, context->batchfileW);
|
strcpyW(outputparam, context->batchfileW);
|
||||||
} else if ((*lastModifier >= '1' && *lastModifier <= '9')) {
|
} else if ((*lastModifier >= '1' && *lastModifier <= '9')) {
|
||||||
strcpyW(outputparam, WCMD_parameter (context -> command,
|
strcpyW(outputparam,
|
||||||
*lastModifier-'0' + context -> shift_count[*lastModifier-'0'], NULL));
|
WCMD_parameter (context -> command, *lastModifier-'0' + context -> shift_count[*lastModifier-'0'],
|
||||||
|
NULL, NULL));
|
||||||
} else {
|
} else {
|
||||||
strcpyW(outputparam, forValue);
|
strcpyW(outputparam, forValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -530,7 +530,7 @@ void WCMD_create_dir (WCHAR *command) {
|
||||||
}
|
}
|
||||||
/* Loop through all args */
|
/* Loop through all args */
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
WCHAR *thisArg = WCMD_parameter(command, argno++, &argN);
|
WCHAR *thisArg = WCMD_parameter(command, argno++, &argN, NULL);
|
||||||
if (!argN) break;
|
if (!argN) break;
|
||||||
if (!create_full_path(thisArg)) {
|
if (!create_full_path(thisArg)) {
|
||||||
WCMD_print_error ();
|
WCMD_print_error ();
|
||||||
|
@ -834,7 +834,7 @@ BOOL WCMD_delete (WCHAR *command) {
|
||||||
WCHAR *thisArg;
|
WCHAR *thisArg;
|
||||||
|
|
||||||
argN = NULL;
|
argN = NULL;
|
||||||
thisArg = WCMD_parameter (command, argno, &argN);
|
thisArg = WCMD_parameter (command, argno, &argN, NULL);
|
||||||
if (!argN)
|
if (!argN)
|
||||||
break; /* no more parameters */
|
break; /* no more parameters */
|
||||||
if (argN[0] == '/')
|
if (argN[0] == '/')
|
||||||
|
@ -1041,7 +1041,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
|
||||||
|
|
||||||
WINE_TRACE("Processing for set %p\n", thisSet);
|
WINE_TRACE("Processing for set %p\n", thisSet);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (*(item = WCMD_parameter (thisSet->command, i, &itemStart))) {
|
while (*(item = WCMD_parameter (thisSet->command, i, &itemStart, NULL))) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the parameter within the set has a wildcard then search for matching files
|
* If the parameter within the set has a wildcard then search for matching files
|
||||||
|
@ -1138,7 +1138,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
|
||||||
while (WCMD_fgets (buffer, sizeof(buffer)/sizeof(WCHAR), input)) {
|
while (WCMD_fgets (buffer, sizeof(buffer)/sizeof(WCHAR), input)) {
|
||||||
|
|
||||||
/* Skip blank lines*/
|
/* Skip blank lines*/
|
||||||
parm = WCMD_parameter (buffer, 0, &where);
|
parm = WCMD_parameter (buffer, 0, &where, NULL);
|
||||||
WINE_TRACE("Parsed parameter: %s from %s\n", wine_dbgstr_w(parm),
|
WINE_TRACE("Parsed parameter: %s from %s\n", wine_dbgstr_w(parm),
|
||||||
wine_dbgstr_w(buffer));
|
wine_dbgstr_w(buffer));
|
||||||
|
|
||||||
|
@ -1168,7 +1168,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
|
||||||
|
|
||||||
/* Skip blank lines, and re-extract parameter now string has quotes removed */
|
/* Skip blank lines, and re-extract parameter now string has quotes removed */
|
||||||
strcpyW(buffer, item);
|
strcpyW(buffer, item);
|
||||||
parm = WCMD_parameter (buffer, 0, &where);
|
parm = WCMD_parameter (buffer, 0, &where, NULL);
|
||||||
WINE_TRACE("Parsed parameter: %s from %s\n", wine_dbgstr_w(parm),
|
WINE_TRACE("Parsed parameter: %s from %s\n", wine_dbgstr_w(parm),
|
||||||
wine_dbgstr_w(buffer));
|
wine_dbgstr_w(buffer));
|
||||||
|
|
||||||
|
@ -1513,22 +1513,22 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
|
||||||
WINE_TRACE("Condition: %s\n", wine_dbgstr_w(condition));
|
WINE_TRACE("Condition: %s\n", wine_dbgstr_w(condition));
|
||||||
|
|
||||||
if (!lstrcmpiW (condition, errlvlW)) {
|
if (!lstrcmpiW (condition, errlvlW)) {
|
||||||
test = (errorlevel >= atoiW(WCMD_parameter(p, 1+negate, NULL)));
|
test = (errorlevel >= atoiW(WCMD_parameter(p, 1+negate, NULL, NULL)));
|
||||||
WCMD_parameter (p, 2+negate, &command);
|
WCMD_parameter(p, 2+negate, &command, NULL);
|
||||||
}
|
}
|
||||||
else if (!lstrcmpiW (condition, existW)) {
|
else if (!lstrcmpiW (condition, existW)) {
|
||||||
test = (GetFileAttributesW(WCMD_parameter(p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES);
|
test = (GetFileAttributesW(WCMD_parameter(p, 1+negate, NULL, NULL)) != INVALID_FILE_ATTRIBUTES);
|
||||||
WCMD_parameter (p, 2+negate, &command);
|
WCMD_parameter(p, 2+negate, &command, NULL);
|
||||||
}
|
}
|
||||||
else if (!lstrcmpiW (condition, defdW)) {
|
else if (!lstrcmpiW (condition, defdW)) {
|
||||||
test = (GetEnvironmentVariableW(WCMD_parameter(p, 1+negate, NULL), NULL, 0) > 0);
|
test = (GetEnvironmentVariableW(WCMD_parameter(p, 1+negate, NULL, NULL), NULL, 0) > 0);
|
||||||
WCMD_parameter (p, 2+negate, &command);
|
WCMD_parameter(p, 2+negate, &command, NULL);
|
||||||
}
|
}
|
||||||
else if ((s = strstrW (p, eqeqW))) {
|
else if ((s = strstrW (p, eqeqW))) {
|
||||||
s += 2;
|
s += 2;
|
||||||
test = caseInsensitive ? (!lstrcmpiW(condition, WCMD_parameter(s, 0, NULL)))
|
test = caseInsensitive ? (!lstrcmpiW(condition, WCMD_parameter(s, 0, NULL, NULL)))
|
||||||
: (!lstrcmpW (condition, WCMD_parameter(s, 0, NULL)));
|
: (!lstrcmpW (condition, WCMD_parameter(s, 0, NULL, NULL)));
|
||||||
WCMD_parameter (s, 1, &command);
|
WCMD_parameter(s, 1, &command, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR));
|
WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR));
|
||||||
|
@ -1708,7 +1708,7 @@ void WCMD_remove_dir (WCHAR *command) {
|
||||||
|
|
||||||
/* Loop through all args */
|
/* Loop through all args */
|
||||||
while (argN) {
|
while (argN) {
|
||||||
WCHAR *thisArg = WCMD_parameter (command, argno++, &argN);
|
WCHAR *thisArg = WCMD_parameter (command, argno++, &argN, NULL);
|
||||||
if (argN && argN[0] != '/') {
|
if (argN && argN[0] != '/') {
|
||||||
WINE_TRACE("rd: Processing arg %s (quals:%s)\n", wine_dbgstr_w(thisArg),
|
WINE_TRACE("rd: Processing arg %s (quals:%s)\n", wine_dbgstr_w(thisArg),
|
||||||
wine_dbgstr_w(quals));
|
wine_dbgstr_w(quals));
|
||||||
|
@ -2445,7 +2445,7 @@ void WCMD_type (WCHAR *command) {
|
||||||
/* Loop through all args */
|
/* Loop through all args */
|
||||||
errorlevel = 0;
|
errorlevel = 0;
|
||||||
while (argN) {
|
while (argN) {
|
||||||
WCHAR *thisArg = WCMD_parameter (command, argno++, &argN);
|
WCHAR *thisArg = WCMD_parameter (command, argno++, &argN, NULL);
|
||||||
|
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
WCHAR buffer[512];
|
WCHAR buffer[512];
|
||||||
|
@ -2539,7 +2539,7 @@ void WCMD_more (WCHAR *command) {
|
||||||
WCMD_enter_paged_mode(moreStrPage);
|
WCMD_enter_paged_mode(moreStrPage);
|
||||||
|
|
||||||
while (argN) {
|
while (argN) {
|
||||||
WCHAR *thisArg = WCMD_parameter (command, argno++, &argN);
|
WCHAR *thisArg = WCMD_parameter (command, argno++, &argN, NULL);
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
|
|
||||||
if (!argN) break;
|
if (!argN) break;
|
||||||
|
|
|
@ -839,7 +839,7 @@ void WCMD_directory (WCHAR *cmd) {
|
||||||
prevEntry = NULL;
|
prevEntry = NULL;
|
||||||
while (argN) {
|
while (argN) {
|
||||||
WCHAR fullname[MAXSTRING];
|
WCHAR fullname[MAXSTRING];
|
||||||
WCHAR *thisArg = WCMD_parameter (cmd, argno++, &argN);
|
WCHAR *thisArg = WCMD_parameter(cmd, argno++, &argN, NULL);
|
||||||
if (argN && argN[0] != '/') {
|
if (argN && argN[0] != '/') {
|
||||||
|
|
||||||
WINE_TRACE("Found parm '%s'\n", wine_dbgstr_w(thisArg));
|
WINE_TRACE("Found parm '%s'\n", wine_dbgstr_w(thisArg));
|
||||||
|
|
|
@ -97,7 +97,7 @@ void WCMD_version (void);
|
||||||
int WCMD_volume (int mode, const WCHAR *command);
|
int WCMD_volume (int mode, const WCHAR *command);
|
||||||
|
|
||||||
WCHAR *WCMD_fgets (WCHAR *s, int n, HANDLE stream);
|
WCHAR *WCMD_fgets (WCHAR *s, int n, HANDLE stream);
|
||||||
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where);
|
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end);
|
||||||
WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
|
WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
|
||||||
BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
|
BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
|
||||||
void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable, const WCHAR *forValue, BOOL justFors);
|
void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable, const WCHAR *forValue, BOOL justFors);
|
||||||
|
|
|
@ -832,13 +832,13 @@ static void handleExpansion(WCHAR *cmd, BOOL justFors,
|
||||||
|
|
||||||
/* Replace use of %0...%9 if in batch program*/
|
/* Replace use of %0...%9 if in batch program*/
|
||||||
} else if (!justFors && context && (i >= 0) && (i <= 9)) {
|
} else if (!justFors && context && (i >= 0) && (i <= 9)) {
|
||||||
t = WCMD_parameter (context -> command, i + context -> shift_count[i], NULL);
|
t = WCMD_parameter(context -> command, i + context -> shift_count[i], NULL, NULL);
|
||||||
WCMD_strsubstW(p, p+2, t, -1);
|
WCMD_strsubstW(p, p+2, t, -1);
|
||||||
|
|
||||||
/* Replace use of %* if in batch program*/
|
/* Replace use of %* if in batch program*/
|
||||||
} else if (!justFors && context && *(p+1)=='*') {
|
} else if (!justFors && context && *(p+1)=='*') {
|
||||||
WCHAR *startOfParms = NULL;
|
WCHAR *startOfParms = NULL;
|
||||||
t = WCMD_parameter (context -> command, 1, &startOfParms);
|
t = WCMD_parameter(context -> command, 1, &startOfParms, NULL);
|
||||||
if (startOfParms != NULL)
|
if (startOfParms != NULL)
|
||||||
WCMD_strsubstW(p, p+2, startOfParms, -1);
|
WCMD_strsubstW(p, p+2, startOfParms, -1);
|
||||||
else
|
else
|
||||||
|
@ -1356,8 +1356,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
|
||||||
|
|
||||||
/* Otherwise STDIN could come from a '<' redirect */
|
/* Otherwise STDIN could come from a '<' redirect */
|
||||||
} else if ((p = strchrW(new_redir,'<')) != NULL) {
|
} else if ((p = strchrW(new_redir,'<')) != NULL) {
|
||||||
h = CreateFileW(WCMD_parameter (++p, 0, NULL), GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING,
|
h = CreateFileW(WCMD_parameter(++p, 0, NULL, NULL), GENERIC_READ, FILE_SHARE_READ,
|
||||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
&sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
if (h == INVALID_HANDLE_VALUE) {
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
WCMD_print_error ();
|
WCMD_print_error ();
|
||||||
HeapFree( GetProcessHeap(), 0, cmd );
|
HeapFree( GetProcessHeap(), 0, cmd );
|
||||||
|
@ -1401,7 +1401,7 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
|
||||||
WINE_TRACE("Redirect %d (%p) to %d (%p)\n", handle, GetStdHandle(idx_stdhandles[idx]), idx, h);
|
WINE_TRACE("Redirect %d (%p) to %d (%p)\n", handle, GetStdHandle(idx_stdhandles[idx]), idx, h);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
WCHAR *param = WCMD_parameter (p, 0, NULL);
|
WCHAR *param = WCMD_parameter(p, 0, NULL, NULL);
|
||||||
h = CreateFileW(param, GENERIC_WRITE, 0, &sa, creationDisposition,
|
h = CreateFileW(param, GENERIC_WRITE, 0, &sa, creationDisposition,
|
||||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
if (h == INVALID_HANDLE_VALUE) {
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
|
|
Loading…
Reference in New Issue