Jason Edmeades : cmd.exe: Support exit [/b] returncode.
Alexandre Julliard
julliard at wine.codeweavers.com
Wed Feb 21 06:01:06 CST 2007
Module: wine
Branch: master
Commit: c36664891cdc48728a1fdddeda27335830115ef6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=c36664891cdc48728a1fdddeda27335830115ef6
Author: Jason Edmeades <us at edmeades.me.uk>
Date: Tue Feb 20 17:49:08 2007 +0000
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(-)
diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
old mode 100644
new mode 100755
index 8beef16..ec27489
--- 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 8715835..e61ad8e 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 de9d317..263412e
--- 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 e2fb450..8077fb8
--- 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);
}
More information about the wine-cvs
mailing list