https://git.reactos.org/?p=reactos.git;a=commitdiff;h=240f6737e95eee6e80bfc5b3f4dbac7b4da3b679

commit 240f6737e95eee6e80bfc5b3f4dbac7b4da3b679
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Mon May 18 02:03:15 2020 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Mon May 18 02:21:57 2020 +0200

    [CMD] Add a ExecuteCommandWithEcho() helper and use it in Batch() and as 
the implementation of RunInstance() FOR-loop helper.
---
 base/shell/cmd/batch.c | 13 ++-----------
 base/shell/cmd/cmd.c   | 21 ++++++++++++++++++++-
 base/shell/cmd/cmd.h   | 10 +++++++++-
 base/shell/cmd/for.c   | 16 +++-------------
 4 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/base/shell/cmd/batch.c b/base/shell/cmd/batch.c
index 3c384e279af..8d6afb222e5 100644
--- a/base/shell/cmd/batch.c
+++ b/base/shell/cmd/batch.c
@@ -353,18 +353,9 @@ INT Batch(LPTSTR fullname, LPTSTR firstword, LPTSTR param, 
PARSED_COMMAND *Cmd)
             continue;
 
         /* JPP 19980807 */
-        /* Echo batch file line */
-        if (bEcho && !bDisableBatchEcho && Cmd->Type != C_QUIET)
-        {
-            if (!bIgnoreEcho)
-                ConOutChar(_T('\n'));
-            PrintPrompt();
-            EchoCommand(Cmd);
-            ConOutChar(_T('\n'));
-        }
-
+        /* Echo the command and execute it */
         bc->current = Cmd;
-        ret = ExecuteCommand(Cmd);
+        ret = ExecuteCommandWithEcho(Cmd);
         FreeCommand(Cmd);
     }
 
diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c
index ed79b192339..bef99f272c4 100644
--- a/base/shell/cmd/cmd.c
+++ b/base/shell/cmd/cmd.c
@@ -769,7 +769,8 @@ failed:
 }
 
 INT
-ExecuteCommand(PARSED_COMMAND *Cmd)
+ExecuteCommand(
+    IN PARSED_COMMAND *Cmd)
 {
     PARSED_COMMAND *Sub;
     LPTSTR First, Rest;
@@ -830,6 +831,24 @@ ExecuteCommand(PARSED_COMMAND *Cmd)
     return Ret;
 }
 
+INT
+ExecuteCommandWithEcho(
+    IN PARSED_COMMAND *Cmd)
+{
+    /* Echo the reconstructed command line */
+    if (bEcho && !bDisableBatchEcho && Cmd->Type != C_QUIET)
+    {
+        if (!bIgnoreEcho)
+            ConOutChar(_T('\n'));
+        PrintPrompt();
+        EchoCommand(Cmd);
+        ConOutChar(_T('\n'));
+    }
+
+    /* Run the command */
+    return ExecuteCommand(Cmd);
+}
+
 LPTSTR
 GetEnvVar(LPCTSTR varName)
 {
diff --git a/base/shell/cmd/cmd.h b/base/shell/cmd/cmd.h
index 20f946463ca..875ce5ec113 100644
--- a/base/shell/cmd/cmd.h
+++ b/base/shell/cmd/cmd.h
@@ -80,7 +80,15 @@ INT ConvertULargeInteger(ULONGLONG num, LPTSTR des, UINT 
len, BOOL bPutSeparator
 HANDLE RunFile(DWORD, LPTSTR, LPTSTR, LPTSTR, INT);
 INT ParseCommandLine(LPTSTR);
 struct _PARSED_COMMAND;
-INT ExecuteCommand(struct _PARSED_COMMAND *Cmd);
+
+INT
+ExecuteCommand(
+    IN struct _PARSED_COMMAND *Cmd);
+
+INT
+ExecuteCommandWithEcho(
+    IN struct _PARSED_COMMAND *Cmd);
+
 LPCTSTR GetEnvVarOrSpecial ( LPCTSTR varName );
 VOID AddBreakHandler (VOID);
 VOID RemoveBreakHandler (VOID);
diff --git a/base/shell/cmd/for.c b/base/shell/cmd/for.c
index b8628145d47..0bfedb967bf 100644
--- a/base/shell/cmd/for.c
+++ b/base/shell/cmd/for.c
@@ -69,19 +69,9 @@ static BOOL GetNextElement(TCHAR **pStart, TCHAR **pEnd)
 }
 
 /* Execute a single instance of a FOR command */
-static INT RunInstance(PARSED_COMMAND *Cmd)
-{
-    if (bEcho && !bDisableBatchEcho && Cmd->Subcommands->Type != C_QUIET)
-    {
-        if (!bIgnoreEcho)
-            ConOutChar(_T('\n'));
-        PrintPrompt();
-        EchoCommand(Cmd->Subcommands);
-        ConOutChar(_T('\n'));
-    }
-    /* Just run the command (variable expansion is done in DoDelayedExpansion) 
*/
-    return ExecuteCommand(Cmd->Subcommands);
-}
+/* Just run the command (variable expansion is done in DoDelayedExpansion) */
+#define RunInstance(Cmd) \
+    ExecuteCommandWithEcho((Cmd)->Subcommands)
 
 /* Check if this FOR should be terminated early */
 static BOOL Exiting(PARSED_COMMAND *Cmd)

Reply via email to