From: Eric Pouech epouech@codeweavers.com
Replace skip_rest field in batch context structure usng file position after EOF instead.
Signed-off-by: Eric Pouech epouech@codeweavers.com --- programs/cmd/batch.c | 14 ++++++-------- programs/cmd/builtins.c | 6 +++--- programs/cmd/wcmd.h | 3 ++- programs/cmd/wcmdmain.c | 19 +++++++++---------- 4 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c index c5a0763c81f..16860993540 100644 --- a/programs/cmd/batch.c +++ b/programs/cmd/batch.c @@ -27,16 +27,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(cmd); static RETURN_CODE WCMD_batch_main_loop(void) { RETURN_CODE return_code = NO_ERROR; + enum read_parse_line rpl; + CMD_NODE *node; + /* Work through the file line by line until an exit is called. */ - while (!context->skip_rest) + while ((rpl = WCMD_ReadAndParseLine(NULL, &node)) != RPL_EOF) { - CMD_NODE *node; - - switch (WCMD_ReadAndParseLine(NULL, &node)) + switch (rpl) { - case RPL_EOF: - context->skip_rest = TRUE; - break; + case RPL_EOF: break; /* never reached; get rid of warning */ case RPL_SUCCESS: if (node) { @@ -95,7 +94,6 @@ static struct batch_context *push_batch_context(WCHAR *command, struct batch_fil context->command = command; memset(context->shift_count, 0x00, sizeof(context->shift_count)); context->prev_context = prev; - context->skip_rest = FALSE; context->batch_file = batch_file; batch_file->ref_count++;
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 21f15c32c4a..1532b94746c 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -1749,7 +1749,7 @@ RETURN_CODE WCMD_goto(void) /* Handle special :EOF label */ if (lstrcmpiW(L":eof", param1) == 0) { - context->skip_rest = TRUE; + context->file_position.QuadPart = WCMD_FILE_POSITION_EOF; return RETURN_CODE_ABORTED; } h = CreateFileW(context->batch_file->path_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, @@ -1770,7 +1770,7 @@ RETURN_CODE WCMD_goto(void) CloseHandle(h); if (ret) return RETURN_CODE_ABORTED; WCMD_output_stderr(WCMD_LoadMessage(WCMD_NOTARGET)); - context->skip_rest = TRUE; + context->file_position.QuadPart = WCMD_FILE_POSITION_EOF; } return ERROR_INVALID_FUNCTION; } @@ -3754,7 +3754,7 @@ RETURN_CODE WCMD_exit(void) if (context && lstrcmpiW(quals, L"/B") == 0) { errorlevel = rc; - context -> skip_rest = TRUE; + context->file_position.QuadPart = WCMD_FILE_POSITION_EOF; return RETURN_CODE_ABORTED; } ExitProcess(rc); diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index f8ea742ee1c..dfc50147536 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -279,10 +279,11 @@ struct batch_context LARGE_INTEGER file_position; int shift_count[10]; /* Offset in terms of shifts for %0 - %9 */ struct batch_context *prev_context; /* Pointer to the previous context block */ - BOOL skip_rest; /* Skip the rest of the batch program and exit */ struct batch_file *batch_file; /* Reference to the file itself */ };
+#define WCMD_FILE_POSITION_EOF (~(DWORD64)0) + /* Data structure to handle building lists during recursive calls */
struct env_stack diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 5b029b6a1ed..e0f2dd32555 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -1779,15 +1779,17 @@ static RETURN_CODE run_full_path(const WCHAR *file, WCHAR *full_cmdline, BOOL ca if (ext && (!wcsicmp(ext, L".bat") || !wcsicmp(ext, L".cmd"))) { RETURN_CODE return_code; - BOOL oldinteractive = interactive; + BOOL prev_interactive = interactive; + BOOL prev_echo_mode = echo_mode;
interactive = FALSE; return_code = WCMD_call_batch(file, full_cmdline); - interactive = oldinteractive; + if ((interactive = prev_interactive)) + echo_mode = prev_echo_mode; if (context && !called) { TRACE("Batch completed, but was not 'called' so skipping outer batch too\n"); - context->skip_rest = TRUE; + context->file_position.QuadPart = WCMD_FILE_POSITION_EOF; } return return_code; } @@ -2351,10 +2353,8 @@ static RETURN_CODE execute_single_command(const WCHAR *command) return_code = WCMD_run_builtin_command(sc.cmd_index, cmd); else { - BOOL prev_echo_mode = echo_mode; if (*sc.path) return_code = run_full_path(sc.path, cmd, FALSE); - echo_mode = prev_echo_mode; } free(cmd); return return_code; @@ -2368,11 +2368,8 @@ RETURN_CODE WCMD_call_command(WCHAR *command) return_code = search_command(command, &sc, FALSE); if (return_code == NO_ERROR) { - unsigned old_echo_mode = echo_mode; if (!*sc.path) return NO_ERROR; - return_code = run_full_path(sc.path, command, TRUE); - if (interactive) echo_mode = old_echo_mode; - return return_code; + return run_full_path(sc.path, command, TRUE); }
if (sc.cmd_index <= WCMD_EXIT) @@ -4581,16 +4578,18 @@ int __cdecl wmain (int argc, WCHAR *argvW[])
if (opt_k) { + RETURN_CODE return_code = NO_ERROR; rpl_status = WCMD_ReadAndParseLine(cmd, &toExecute); /* Parse the command string, without reading any more input */ if (rpl_status == RPL_SUCCESS && toExecute) { - node_execute(toExecute); + return_code = node_execute(toExecute); node_dispose_tree(toExecute); } else if (rpl_status == RPL_SYNTAXERROR) errorlevel = RETURN_CODE_SYNTAX_ERROR; free(cmd); + if (return_code == RETURN_CODE_ABORTED) return errorlevel; }
/*