reactos/base/shell/cmd/batch.h
Hermès Bélusca-Maïto 6eb1cae348
[CMD] Fixes for Batch error execution control flow.
CORE-13713 CORE-13736

- In case execution of all batch contexts is stopped (by selecting "All"
  at the Ctrl-C/Ctrl-Break prompt), notify as well the CheckCtrlBreak()
  signal handler once there are no more batch contexts (this in effect
  resets the internal 'bLeaveAll' static flag in CheckCtrlBreak).
  This is an adaptation of the fix present in FreeCOM 1.5, first
  described in https://gcfl.net/FreeDOS/command.com/bugs074g.html .

- Introduce a ParseErrorEx() helper that sets the 'bParseError' flag and
  displays a customized syntax-error message, only for the first syntax
  error encountered. Implement ParseError() around the *Ex function.

- In batch mode, echo the original pre-parsed batch file line if a parse
  error has been encountered.

- When running a compound command - including IF, FOR, command blocks -,
  and that control flow is modified by any CALL/GOTO/EXIT command,
  detect this while running the compound command so as to stop it and go
  back to the main batch execution loop, that will then set up the actual
  new command to run.

- In GOTO, do not process any more parts of a compound command only when
  we have found a valid label.
2020-08-19 20:35:58 +02:00

54 lines
1.4 KiB
C

/*
* BATCH.H - A structure to preserve the context of a batch file
*/
#pragma once
typedef struct _BATCH_CONTEXT
{
struct _BATCH_CONTEXT *prev;
char *mem; /* batchfile content in memory */
DWORD memsize; /* size of batchfile */
DWORD mempos; /* current position to read from */
BOOL memfree; /* true if it need to be freed when exitbatch is called */
TCHAR BatchFilePath[MAX_PATH];
LPTSTR params;
LPTSTR raw_params; /* Holds the raw params given by the input */
INT shiftlevel[10];
BOOL bEcho; /* Preserve echo flag across batch calls */
REDIRECTION *RedirList;
PARSED_COMMAND *current;
struct _SETLOCAL *setlocal;
} BATCH_CONTEXT, *PBATCH_CONTEXT;
typedef struct _FOR_CONTEXT
{
struct _FOR_CONTEXT *prev;
TCHAR firstvar;
UINT varcount;
LPTSTR *values;
} FOR_CONTEXT, *PFOR_CONTEXT;
/*
* The stack of current batch contexts.
* NULL when no batch is active.
*/
extern PBATCH_CONTEXT bc;
extern PFOR_CONTEXT fc;
extern BOOL bEcho; /* The echo flag */
#define BATCH_BUFFSIZE 8192
extern TCHAR textline[BATCH_BUFFSIZE]; /* Buffer for reading Batch file lines */
LPTSTR FindArg(TCHAR, BOOL *);
VOID ExitBatch(VOID);
VOID ExitAllBatches(VOID);
INT Batch(LPTSTR, LPTSTR, LPTSTR, PARSED_COMMAND *);
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength);
LPTSTR ReadBatchLine(VOID);
VOID AddBatchRedirection(REDIRECTION **);