[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.
This commit is contained in:
Hermès Bélusca-Maïto 2020-07-18 23:41:56 +02:00
parent 141378cfc8
commit 87a5403318
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 30 additions and 0 deletions

View file

@ -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 */

View file

@ -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