cmd.exe: Support SHIFT /n option.

This commit is contained in:
Jason Edmeades 2007-03-08 00:50:37 +00:00 committed by Alexandre Julliard
parent ffbaedef51
commit 612dc9d35d
4 changed files with 29 additions and 8 deletions

View File

@ -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 = (BATCH_CONTEXT *)LocalAlloc (LMEM_FIXED, sizeof (BATCH_CONTEXT));
context -> h = h; context -> h = h;
context -> command = command; context -> command = command;
context -> shift_count = 0; memset(context -> shift_count, 0x00, sizeof(context -> shift_count));
context -> prev_context = prev_context; context -> prev_context = prev_context;
context -> skip_rest = FALSE; context -> skip_rest = FALSE;
@ -386,7 +386,7 @@ void WCMD_HandleTildaModifiers(char **start, char *forVariable) {
/* Extract the parameter to play with */ /* Extract the parameter to play with */
if ((*lastModifier >= '0' && *lastModifier <= '9')) { if ((*lastModifier >= '0' && *lastModifier <= '9')) {
strcpy(outputparam, WCMD_parameter (context -> command, strcpy(outputparam, WCMD_parameter (context -> command,
*lastModifier-'0' + context -> shift_count, NULL)); *lastModifier-'0' + context -> shift_count[*lastModifier-'0'], NULL));
} else { } else {
/* FIXME: Retrieve 'for' variable %c\n", *lastModifier); */ /* FIXME: Retrieve 'for' variable %c\n", *lastModifier); */
/* Need to get 'for' loop variable into outputparam */ /* Need to get 'for' loop variable into outputparam */

View File

@ -1388,11 +1388,32 @@ void WCMD_setshow_time (void) {
* WCMD_shift * WCMD_shift
* *
* Shift batch parameters. * 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;
}
} }

View File

@ -68,7 +68,7 @@ void WCMD_setshow_env (char *command);
void WCMD_setshow_path (char *command); void WCMD_setshow_path (char *command);
void WCMD_setshow_prompt (void); void WCMD_setshow_prompt (void);
void WCMD_setshow_time (void); void WCMD_setshow_time (void);
void WCMD_shift (void); void WCMD_shift (char *command);
void WCMD_show_prompt (void); void WCMD_show_prompt (void);
void WCMD_title (char *); void WCMD_title (char *);
void WCMD_type (void); void WCMD_type (void);
@ -91,7 +91,7 @@ void WCMD_splitpath(const CHAR* path, CHAR* drv, CHAR* dir, CHAR* name, CHAR* ex
typedef struct { typedef struct {
char *command; /* The command which invoked the batch file */ char *command; /* The command which invoked the batch file */
HANDLE h; /* Handle to the open 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 */ void *prev_context; /* Pointer to the previous context block */
BOOL skip_rest; /* Skip the rest of the batch program and exit */ BOOL skip_rest; /* Skip the rest of the batch program and exit */
} BATCH_CONTEXT; } BATCH_CONTEXT;

View File

@ -411,7 +411,7 @@ void WCMD_process_command (char *command)
/* Replace use of %0...%9 if in batch program*/ /* Replace use of %0...%9 if in batch program*/
} else if (context && (i >= 0) && (i <= 9)) { } else if (context && (i >= 0) && (i <= 9)) {
s = strdup (p+2); 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); strcpy (p, t);
strcat (p, s); strcat (p, s);
free (s); free (s);
@ -629,7 +629,7 @@ void WCMD_process_command (char *command)
WCMD_setshow_env (p); WCMD_setshow_env (p);
break; break;
case WCMD_SHIFT: case WCMD_SHIFT:
WCMD_shift (); WCMD_shift (p);
break; break;
case WCMD_TIME: case WCMD_TIME:
WCMD_setshow_time (); WCMD_setshow_time ();