https://git.reactos.org/?p=reactos.git;a=commitdiff;h=87a5403318f4b64f2d8b0c...
commit 87a5403318f4b64f2d8b0c56ebc69b89889ad6c8 Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Sat Jul 18 23:41:56 2020 +0200 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Wed Sep 23 00:22:47 2020 +0200
[CMD] Add a MSCMD_BATCH_ECHO define for enabling Windows' CMD.EXE way of preserving/restoring the echo flag across batch calls.
Observation shows that this is done only when the top-level batch file is being run (and then terminates); the echo flag is not restored to its previous state when a child batch file terminates and gives main back to its parent batch. --- base/shell/cmd/batch.c | 20 ++++++++++++++++++++ base/shell/cmd/batch.h | 10 ++++++++++ 2 files changed, 30 insertions(+)
diff --git a/base/shell/cmd/batch.c b/base/shell/cmd/batch.c index 5015bd338ea..1876b84deab 100644 --- a/base/shell/cmd/batch.c +++ b/base/shell/cmd/batch.c @@ -66,6 +66,10 @@ BATCH_TYPE BatType = NONE; PBATCH_CONTEXT bc = NULL;
+#ifdef MSCMD_BATCH_ECHO +BOOL bBcEcho = TRUE; +#endif + BOOL bEcho = TRUE; /* The echo flag */
/* Buffer for reading Batch file lines */ @@ -195,8 +199,10 @@ VOID ExitBatch(VOID) UndoRedirection(bc->RedirList, NULL); FreeRedirection(bc->RedirList);
+#ifndef MSCMD_BATCH_ECHO /* Preserve echo state across batch calls */ bEcho = bc->bEcho; +#endif
while (bc->setlocal) cmd_endlocal(_T("")); @@ -213,6 +219,10 @@ VOID ExitBatch(VOID) { CheckCtrlBreak(BREAK_OUTOFBATCH); BatType = NONE; + +#ifdef MSCMD_BATCH_ECHO + bEcho = bBcEcho; +#endif } }
@@ -352,7 +362,9 @@ INT Batch(LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd) }
bc->mempos = 0; /* Go to the beginning of the batch file */ +#ifndef MSCMD_BATCH_ECHO bc->bEcho = bEcho; /* Preserve echo across batch calls */ +#endif for (i = 0; i < 10; i++) bc->shiftlevel[i] = i;
@@ -381,6 +393,10 @@ INT Batch(LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd) { BatType = CMD_TYPE; } + +#ifdef MSCMD_BATCH_ECHO + bBcEcho = bEcho; +#endif }
/* Check if this is a "CALL :label" */ @@ -424,6 +440,10 @@ INT Batch(LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd) { /* Reset the top-level batch context type */ BatType = NONE; + +#ifdef MSCMD_BATCH_ECHO + bEcho = bBcEcho; +#endif }
/* Restore the FOR variables */ diff --git a/base/shell/cmd/batch.h b/base/shell/cmd/batch.h index 25b8857b1c3..982965c794a 100644 --- a/base/shell/cmd/batch.h +++ b/base/shell/cmd/batch.h @@ -19,6 +19,10 @@ typedef enum _BATCH_TYPE CMD_TYPE /* New-style NT OS/2 batch file */ } BATCH_TYPE;
+ +/* Enable this define for Windows' CMD batch-echo behaviour compatibility */ +#define MSCMD_BATCH_ECHO + typedef struct _BATCH_CONTEXT { struct _BATCH_CONTEXT *prev; @@ -30,7 +34,9 @@ typedef struct _BATCH_CONTEXT LPTSTR params; LPTSTR raw_params; /* Holds the raw params given by the input */ INT shiftlevel[10]; +#ifndef MSCMD_BATCH_ECHO BOOL bEcho; /* Preserve echo flag across batch calls */ +#endif REDIRECTION *RedirList; PARSED_COMMAND *current; struct _SETLOCAL *setlocal; @@ -53,6 +59,10 @@ extern BATCH_TYPE BatType; extern PBATCH_CONTEXT bc; extern PFOR_CONTEXT fc;
+#ifdef MSCMD_BATCH_ECHO +extern BOOL bBcEcho; +#endif + extern BOOL bEcho; /* The echo flag */
#define BATCH_BUFFSIZE 8192