Commit b6924112 authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

cmd.exe: Expand for variables at last with tilda modifications.

parent dc372175
......@@ -19,6 +19,9 @@
*/
#include "wcmd.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(cmd);
extern int echo_mode;
extern WCHAR quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH];
......@@ -301,7 +304,7 @@ void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHA
* Hence search forwards until find an invalid modifier, and then
* backwards until find for variable or 0-9
*/
void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable) {
void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable, WCHAR *forValue, BOOL justFors) {
#define NUMMODIFIERS 11
static const WCHAR validmodifiers[NUMMODIFIERS] = {
......@@ -324,10 +327,10 @@ void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable) {
BOOL skipFileParsing = FALSE;
BOOL doneModifier = FALSE;
/* Search forwards until find invalid WCHARacter modifier */
/* Search forwards until find invalid character modifier */
while (!finished) {
/* Work on the previous WCHARacter */
/* Work on the previous character */
if (lastModifier != NULL) {
for (i=0; i<NUMMODIFIERS; i++) {
......@@ -355,27 +358,30 @@ void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable) {
}
}
/* Now make sure the position we stopped at is a valid parameter */
if (!(*lastModifier >= '0' || *lastModifier <= '9') &&
(forVariable != NULL) &&
(toupperW(*lastModifier) != toupperW(*forVariable))) {
while (lastModifier > firstModifier) {
WINE_TRACE("Looking backwards for parameter id: %s / %s\n",
wine_dbgstr_w(lastModifier), wine_dbgstr_w(forVariable));
if (!justFors && context && (*lastModifier >= '0' || *lastModifier <= '9')) {
/* Its a valid parameter identifier - OK */
break;
/* Its not... Step backwards until it matches or we get to the start */
while (toupperW(*lastModifier) != toupperW(*forVariable) &&
lastModifier > firstModifier) {
} else if (forVariable && *lastModifier == *(forVariable+1)) {
/* Its a valid parameter identifier - OK */
break;
} else {
lastModifier--;
}
if (lastModifier == firstModifier) return; /* Invalid syntax */
}
if (lastModifier == firstModifier) return; /* Invalid syntax */
/* Extract the parameter to play with */
if ((*lastModifier >= '0' && *lastModifier <= '9')) {
strcpyW(outputparam, WCMD_parameter (context -> command,
*lastModifier-'0' + context -> shift_count[*lastModifier-'0'], NULL));
} else {
/* FIXME: Retrieve 'for' variable %c\n", *lastModifier); */
/* Need to get 'for' loop variable into outputparam */
return;
strcpyW(outputparam, forValue);
}
/* So now, firstModifier points to beginning of modifiers, lastModifier
......
......@@ -992,40 +992,6 @@ void WCMD_part_execute(CMD_LIST **cmdList, WCHAR *firstcmd, WCHAR *variable,
return;
}
/*****************************************************************************
* WCMD_Execute
*
* Execute a command after substituting variable text for the supplied parameter
*/
void WCMD_execute (WCHAR *orig_cmd, WCHAR *param, WCHAR *subst, CMD_LIST **cmdList) {
WCHAR *new_cmd, *p, *s, *dup;
int size;
if (param) {
size = (strlenW (orig_cmd) + 1) * sizeof(WCHAR);
new_cmd = (WCHAR *) LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, size);
dup = s = WCMD_strdupW(orig_cmd);
while ((p = strstrW (s, param))) {
*p = '\0';
size += strlenW (subst) * sizeof(WCHAR);
new_cmd = (WCHAR *) LocalReAlloc ((HANDLE)new_cmd, size, 0);
strcatW (new_cmd, s);
strcatW (new_cmd, subst);
s = p + strlenW (param);
}
strcatW (new_cmd, s);
WCMD_process_command (new_cmd, cmdList);
free (dup);
LocalFree ((HANDLE)new_cmd);
} else {
WCMD_process_command (orig_cmd, cmdList);
}
}
/**************************************************************************
* WCMD_give_help
*
......@@ -1067,7 +1033,7 @@ void WCMD_goto (CMD_LIST **cmdList) {
WCHAR string[MAX_PATH];
/* Do not process any more parts of a processed multipart or multilines command */
*cmdList = NULL;
if (cmdList) *cmdList = NULL;
if (param1[0] == 0x00) {
WCMD_output (WCMD_LoadMessage(WCMD_NOARG));
......
......@@ -65,7 +65,6 @@ void WCMD_pause (void);
void WCMD_pipe (CMD_LIST **command, WCHAR *var, WCHAR *val);
void WCMD_popd (void);
void WCMD_print_error (void);
void WCMD_process_command (WCHAR *command, CMD_LIST **cmdList);
void WCMD_pushd (WCHAR *);
int WCMD_read_console (WCHAR *string, int str_len);
void WCMD_remove_dir (WCHAR *command);
......@@ -92,7 +91,7 @@ WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where);
WCHAR *WCMD_strtrim_leading_spaces (WCHAR *string);
void WCMD_strtrim_trailing_spaces (WCHAR *string);
void WCMD_opt_s_strip_quotes(WCHAR *cmd);
void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable);
void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable, WCHAR *forValue, BOOL justFors);
BOOL WCMD_ask_confirm (WCHAR *message, BOOL showSureText, BOOL *optionAll);
void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment