[PATCH 04/12] CMD.exe: Pass the command list through so it is available to built in commands

Jason Edmeades jason.edmeades at googlemail.com
Fri Jun 15 14:59:33 CDT 2007


As per the last patch, this sets the scene so an individual batch command
such as GOTO, IF, etc can see multiline parts (only if cares) or modify
what gets executed next
---
 programs/cmd/builtins.c |   18 +++++++++---------
 programs/cmd/wcmd.h     |    6 +++---
 programs/cmd/wcmdmain.c |   16 ++++++++--------
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index f5310b7..9a45bf8 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -40,7 +40,7 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(cmd);
 
-void WCMD_execute (WCHAR *orig_command, WCHAR *parameter, WCHAR *substitution);
+void WCMD_execute (WCHAR *orig_command, WCHAR *parameter, WCHAR *substitution, CMD_LIST **cmdList);
 
 struct env_stack *saved_environment;
 struct env_stack *pushd_directories;
@@ -575,7 +575,7 @@ void WCMD_echo (const WCHAR *command) {
  * will probably work here, but the reverse is not necessarily the case...
  */
 
-void WCMD_for (WCHAR *p) {
+void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
 
   WIN32_FIND_DATA fd;
   HANDLE hff;
@@ -609,12 +609,12 @@ void WCMD_for (WCHAR *p) {
 	return;
       }
       do {
-	WCMD_execute (cmd, param, fd.cFileName);
+	WCMD_execute (cmd, param, fd.cFileName, cmdList);
       } while (FindNextFile(hff, &fd) != 0);
       FindClose (hff);
-}
+    }
     else {
-      WCMD_execute (cmd, param, item);
+      WCMD_execute (cmd, param, item, cmdList);
     }
     i++;
   }
@@ -626,7 +626,7 @@ void WCMD_for (WCHAR *p) {
  *	Execute a command after substituting variable text for the supplied parameter
  */
 
-void WCMD_execute (WCHAR *orig_cmd, WCHAR *param, WCHAR *subst) {
+void WCMD_execute (WCHAR *orig_cmd, WCHAR *param, WCHAR *subst, CMD_LIST **cmdList) {
 
   WCHAR *new_cmd, *p, *s, *dup;
   int size;
@@ -644,7 +644,7 @@ void WCMD_execute (WCHAR *orig_cmd, WCHAR *param, WCHAR *subst) {
     s = p + strlenW (param);
   }
   strcatW (new_cmd, s);
-  WCMD_process_command (new_cmd);
+  WCMD_process_command (new_cmd, cmdList);
   free (dup);
   LocalFree ((HANDLE)new_cmd);
 }
@@ -790,7 +790,7 @@ void WCMD_popd (void) {
  * FIXME: Much more syntax checking needed!
  */
 
-void WCMD_if (WCHAR *p) {
+void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
 
   int negate = 0, test = 0;
   WCHAR condition[MAX_PATH], *command, *s;
@@ -834,7 +834,7 @@ void WCMD_if (WCHAR *p) {
   }
   if (test != negate) {
     command = WCMD_strdupW(command);
-    WCMD_process_command (command);
+    WCMD_process_command (command, cmdList);
     free (command);
   }
 }
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index fa8d785..b6258e5 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -51,10 +51,10 @@ void WCMD_echo (const WCHAR *);
 void WCMD_endlocal (void);
 void WCMD_enter_paged_mode(const WCHAR *);
 void WCMD_exit (void);
-void WCMD_for (WCHAR *);
+void WCMD_for (WCHAR *, CMD_LIST **cmdList);
 void WCMD_give_help (WCHAR *command);
 void WCMD_goto (void);
-void WCMD_if (WCHAR *);
+void WCMD_if (WCHAR *, CMD_LIST **cmdList);
 void WCMD_leave_paged_mode(void);
 void WCMD_more (WCHAR *);
 void WCMD_move (void);
@@ -65,7 +65,7 @@ void WCMD_pause (void);
 void WCMD_pipe (CMD_LIST **command);
 void WCMD_popd (void);
 void WCMD_print_error (void);
-void WCMD_process_command (WCHAR *command);
+void WCMD_process_command (WCHAR *command, CMD_LIST **cmdList);
 void WCMD_pushd (WCHAR *);
 int  WCMD_read_console (WCHAR *string, int str_len);
 void WCMD_remove_dir (WCHAR *command);
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index ba5f7df..fdb8089 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -463,7 +463,7 @@ int wmain (int argc, WCHAR *argvW[])
  */
 
 
-void WCMD_process_command (WCHAR *command)
+void WCMD_process_command (WCHAR *command, CMD_LIST **cmdList)
 {
     WCHAR *cmd, *p, *s, *t, *redir;
     int status, i;
@@ -709,7 +709,7 @@ void WCMD_process_command (WCHAR *command)
         WCMD_echo(&whichcmd[count]);
         break;
       case WCMD_FOR:
-        WCMD_for (p);
+        WCMD_for (p, cmdList);
         break;
       case WCMD_GOTO:
         WCMD_goto ();
@@ -718,7 +718,7 @@ void WCMD_process_command (WCHAR *command)
         WCMD_give_help (p);
 	break;
       case WCMD_IF:
-	WCMD_if (p);
+	WCMD_if (p, cmdList);
         break;
       case WCMD_LABEL:
         WCMD_volume (1, p);
@@ -1503,19 +1503,19 @@ void WCMD_pipe (CMD_LIST **cmdEntry) {
   p = strchrW(command, '|');
   *p++ = '\0';
   wsprintf (temp_cmd, redirOut, command, temp_file);
-  WCMD_process_command (temp_cmd);
+  WCMD_process_command (temp_cmd, cmdEntry);
   command = p;
   while ((p = strchrW(command, '|'))) {
     *p++ = '\0';
     GetTempFileName (temp_path, cmdW, 0, temp_file2);
     wsprintf (temp_cmd, redirBoth, command, temp_file, temp_file2);
-    WCMD_process_command (temp_cmd);
+    WCMD_process_command (temp_cmd, cmdEntry);
     DeleteFile (temp_file);
     strcpyW (temp_file, temp_file2);
     command = p;
   }
   wsprintf (temp_cmd, redirIn, command, temp_file);
-  WCMD_process_command (temp_cmd);
+  WCMD_process_command (temp_cmd, cmdEntry);
   DeleteFile (temp_file);
 }
 
@@ -2080,10 +2080,10 @@ void WCMD_process_commands(CMD_LIST *thisCmd) {
         if (strchrW(thisCmd->command,'|') != NULL) {
           WCMD_pipe (&thisCmd);
         } else {
-          WCMD_process_command (thisCmd->command);
+          WCMD_process_command (thisCmd->command, &thisCmd);
         }
       }
-      thisCmd = thisCmd->nextcommand;
+      if (thisCmd) thisCmd = thisCmd->nextcommand;
     }
 }
 
-- 
1.5.0




More information about the wine-patches mailing list