From c36664891cdc48728a1fdddeda27335830115ef6 Mon Sep 17 00:00:00 2001 From: Jason Edmeades Date: Tue, 20 Feb 2007 17:49:08 +0000 Subject: [PATCH] cmd.exe: Support exit [/b] returncode. --- programs/cmd/batch.c | 3 ++- programs/cmd/builtins.c | 19 +++++++++++++++++++ programs/cmd/wcmd.h | 2 ++ programs/cmd/wcmdmain.c | 5 +++-- 4 files changed, 26 insertions(+), 3 deletions(-) mode change 100644 => 100755 programs/cmd/batch.c mode change 100644 => 100755 programs/cmd/wcmd.h mode change 100644 => 100755 programs/cmd/wcmdmain.c diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c old mode 100644 new mode 100755 index 8beef16f1e5..ec274895721 --- a/programs/cmd/batch.c +++ b/programs/cmd/batch.c @@ -87,13 +87,14 @@ BATCH_CONTEXT *prev_context; context -> command = command; context -> shift_count = 0; context -> prev_context = prev_context; + context -> skip_rest = FALSE; /* * Work through the file line by line. Specific batch commands are processed here, * the rest are handled by the main command processor. */ - while (WCMD_fgets (string, sizeof(string), h)) { + while (context -> skip_rest == FALSE && WCMD_fgets (string, sizeof(string), h)) { if (strlen(string) == MAXSTRING -1) { WCMD_output_asis( "Line in Batch processing possibly truncated. Using:\n"); WCMD_output_asis( string); diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 87158355d19..e61ad8e863f 100755 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -1159,3 +1159,22 @@ BOOL status; } return 1; } + +/************************************************************************** + * WCMD_exit + * + * Exit either the process, or just this batch program + * + */ + +void WCMD_exit (void) { + + int rc = atoi(param1); /* Note: atoi of empty parameter is 0 */ + + if (context && lstrcmpi(quals, "/B") == 0) { + errorlevel = rc; + context -> skip_rest = TRUE; + } else { + ExitProcess(rc); + } +} diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h old mode 100644 new mode 100755 index de9d31723ed..263412e0458 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -37,6 +37,7 @@ void WCMD_directory (void); void WCMD_echo (const char *); void WCMD_endlocal (void); void WCMD_enter_paged_mode(void); +void WCMD_exit (void); void WCMD_for (char *); void WCMD_give_help (char *command); void WCMD_goto (void); @@ -83,6 +84,7 @@ typedef struct { HANDLE h; /* Handle to the open batch file */ int shift_count; /* Number of SHIFT commands executed */ void *prev_context; /* Pointer to the previous context block */ + BOOL skip_rest; /* Skip the rest of the batch program and exit */ } BATCH_CONTEXT; #endif /* !RC_INVOKED */ diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c old mode 100644 new mode 100755 index e2fb45046ce..8077fb81a92 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -244,7 +244,7 @@ int main (int argc, char *argv[]) else WCMD_process_command(cmd); HeapFree(GetProcessHeap(), 0, cmd); - return 0; + return errorlevel; } SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_LINE_INPUT | @@ -504,7 +504,8 @@ void WCMD_process_command (char *command) WCMD_volume (0, p); break; case WCMD_EXIT: - ExitProcess (0); + WCMD_exit (); + break; default: WCMD_run_program (whichcmd, 0); } -- 2.11.4.GIT