[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.
This commit is contained in:
Hermès Bélusca-Maïto 2020-05-18 02:05:53 +02:00
parent 7f8792e005
commit 6eb1cae348
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
9 changed files with 119 additions and 33 deletions

View file

@ -195,6 +195,24 @@ VOID ExitBatch(VOID)
cmd_endlocal(_T(""));
bc = bc->prev;
#if 0
/* Do not process any more parts of a compound command */
bc->current = NULL;
#endif
/* If there is no more batch contexts, notify the signal handler */
if (!bc)
CheckCtrlBreak(BREAK_OUTOFBATCH);
}
/*
* Exit all the nested batch calls.
*/
VOID ExitAllBatches(VOID)
{
while (bc)
ExitBatch();
}
/*
@ -343,7 +361,23 @@ INT Batch(LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
{
Cmd = ParseCommand(NULL);
if (!Cmd)
continue;
{
if (!bParseError)
continue;
/* Echo the pre-parsed batch file line on error */
if (bEcho && !bDisableBatchEcho)
{
if (!bIgnoreEcho)
ConOutChar(_T('\n'));
PrintPrompt();
ConOutPuts(ParseLine);
ConOutChar(_T('\n'));
}
/* Stop all execution */
ExitAllBatches();
break;
}
/* JPP 19980807 */
/* Echo the command and execute it */
@ -441,8 +475,7 @@ LPTSTR ReadBatchLine(VOID)
/* User halt */
if (CheckCtrlBreak(BREAK_BATCHFILE))
{
while (bc)
ExitBatch();
ExitAllBatches();
return NULL;
}