[02/16] CMD.exe: Changed cmd.exe to support exit [/b] returncode

Ann & Jason Edmeades us at edmeades.me.uk
Tue Mar 20 19:55:41 CDT 2007


-------------- next part --------------
>From nobody Mon Sep 17 00:00:00 2001
From: Jason Edmeades <us at edmeades.me.uk>
Date: Thu Feb 15 22:01:48 2007 +0000
Subject: [PATCH] Changed cmd.exe to support exit [/b] returncode

---

 programs/cmd/batch.c    |    3 ++-
 programs/cmd/builtins.c |   23 +++++++++++++++++++++++
 programs/cmd/wcmd.h     |    2 ++
 programs/cmd/wcmdmain.c |    5 +++--
 4 files changed, 30 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

c4caa7ea685e9d6ef99c672c68ab42c3baf7bff3
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..c8c8adc 100755
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1159,3 +1159,26 @@ BOOL status;
   }
   return 1;
 }
+
+/**************************************************************************
+ * WCMD_exit
+ *
+ * Exit either the process, or just this batch program
+ *
+ */
+
+void WCMD_exit (void) {
+
+    long rc = 0;
+
+    rc = atol(param1); /* Note: atol 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);
     }
-- 
1.3.0



More information about the wine-patches mailing list