Jason Edmeades : cmd.exe: Support SHIFT /n option.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu Mar 8 07:17:11 CST 2007
Module: wine
Branch: master
Commit: 612dc9d35d9f8e4d7e1faaf992c442e596a49f7c
URL: http://source.winehq.org/git/wine.git/?a=commit;h=612dc9d35d9f8e4d7e1faaf992c442e596a49f7c
Author: Jason Edmeades <us at edmeades.me.uk>
Date: Thu Mar 8 00:50:37 2007 +0000
cmd.exe: Support SHIFT /n option.
---
programs/cmd/batch.c | 4 ++--
programs/cmd/builtins.c | 25 +++++++++++++++++++++++--
programs/cmd/wcmd.h | 4 ++--
programs/cmd/wcmdmain.c | 4 ++--
4 files changed, 29 insertions(+), 8 deletions(-)
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 @@ void WCMD_batch (char *file, char *command, int called, char *startLabel, HANDLE
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 @@ void WCMD_HandleTildaModifiers(char **start, char *forVariable) {
/* 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 @@ void WCMD_setshow_time (void) {
* 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_env (char *command);
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 @@ void WCMD_splitpath(const CHAR* path, CHAR* drv, CHAR* dir, CHAR* name, CHAR* ex
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 @@ void WCMD_process_command (char *command)
/* 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 @@ void WCMD_process_command (char *command)
WCMD_setshow_env (p);
break;
case WCMD_SHIFT:
- WCMD_shift ();
+ WCMD_shift (p);
break;
case WCMD_TIME:
WCMD_setshow_time ();
More information about the wine-cvs
mailing list