cmd.exe: Support SHIFT /n option.
diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 4624ea9..0824c27 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -89,7 +89,7 @@
context = (BATCH_CONTEXT *)LocalAlloc (LMEM_FIXED, sizeof (BATCH_CONTEXT));
context -> h = h;
context -> command = command;
- context -> shift_count = 0;
+ memset(context -> shift_count, 0x00, sizeof(context -> shift_count));
context -> prev_context = prev_context;
context -> skip_rest = FALSE;
@@ -386,7 +386,7 @@
/* Extract the parameter to play with */
if ((*lastModifier >= '0' && *lastModifier <= '9')) {
strcpy(outputparam, WCMD_parameter (context -> command,
- *lastModifier-'0' + context -> shift_count, NULL));
+ *lastModifier-'0' + context -> shift_count[*lastModifier-'0'], NULL));
} else {
/* FIXME: Retrieve 'for' variable %c\n", *lastModifier); */
/* Need to get 'for' loop variable into outputparam */
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 2721cb5..d8c3967 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1388,11 +1388,32 @@
* WCMD_shift
*
* Shift batch parameters.
+ * Optional /n says where to start shifting (n=0-8)
*/
-void WCMD_shift (void) {
+void WCMD_shift (char *command) {
+ int start;
- if (context != NULL) context -> shift_count++;
+ if (context != NULL) {
+ char *pos = strchr(command, '/');
+ int i;
+
+ if (pos == NULL) {
+ start = 0;
+ } else if (*(pos+1)>='0' && *(pos+1)<='8') {
+ start = (*(pos+1) - '0');
+ } else {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ WCMD_print_error();
+ return;
+ }
+
+ WINE_TRACE("Shifting variables, starting at %d\n", start);
+ for (i=start;i<=8;i++) {
+ context -> shift_count[i] = context -> shift_count[i+1] + 1;
+ }
+ context -> shift_count[9] = context -> shift_count[9] + 1;
+ }
}
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index e7ffa94..d43e1cd 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -68,7 +68,7 @@
void WCMD_setshow_path (char *command);
void WCMD_setshow_prompt (void);
void WCMD_setshow_time (void);
-void WCMD_shift (void);
+void WCMD_shift (char *command);
void WCMD_show_prompt (void);
void WCMD_title (char *);
void WCMD_type (void);
@@ -91,7 +91,7 @@
typedef struct {
char *command; /* The command which invoked the batch file */
HANDLE h; /* Handle to the open batch file */
- int shift_count; /* Number of SHIFT commands executed */
+ int shift_count[10]; /* Offset in terms of shifts for %0 - %9 */
void *prev_context; /* Pointer to the previous context block */
BOOL skip_rest; /* Skip the rest of the batch program and exit */
} BATCH_CONTEXT;
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index de6aa6d..1dcf1e5 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -411,7 +411,7 @@
/* Replace use of %0...%9 if in batch program*/
} else if (context && (i >= 0) && (i <= 9)) {
s = strdup (p+2);
- t = WCMD_parameter (context -> command, i + context -> shift_count, NULL);
+ t = WCMD_parameter (context -> command, i + context -> shift_count[i], NULL);
strcpy (p, t);
strcat (p, s);
free (s);
@@ -629,7 +629,7 @@
WCMD_setshow_env (p);
break;
case WCMD_SHIFT:
- WCMD_shift ();
+ WCMD_shift (p);
break;
case WCMD_TIME:
WCMD_setshow_time ();