[CMD] Don't reset bCtrlBreak too early.

This allows to break commands such as:

C:\ReactOS\system32> for %f in (*.*) do dir

as one would expect: stop the currently running 'dir' and the 'for'.
"bCtrlBreak" doesn't need to be volatile too.
This commit is contained in:
Hermès Bélusca-Maïto 2018-04-29 00:53:49 +02:00
parent 6dd27bd467
commit a3b36f8d3e
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 14 additions and 7 deletions

View file

@ -151,7 +151,7 @@ typedef NTSTATUS (WINAPI *NtReadVirtualMemoryProc)(HANDLE, PVOID, PVOID, ULONG,
BOOL bExit = FALSE; /* indicates EXIT was typed */ BOOL bExit = FALSE; /* indicates EXIT was typed */
BOOL bCanExit = TRUE; /* indicates if this shell is exitable */ BOOL bCanExit = TRUE; /* indicates if this shell is exitable */
volatile BOOL bCtrlBreak = FALSE; /* Ctrl-Break or Ctrl-C hit */ BOOL bCtrlBreak = FALSE; /* Ctrl-Break or Ctrl-C hit */
BOOL bIgnoreEcho = FALSE; /* Set this to TRUE to prevent a newline, when executing a command */ BOOL bIgnoreEcho = FALSE; /* Set this to TRUE to prevent a newline, when executing a command */
static BOOL bWaitForCommand = FALSE; /* When we are executing something passed on the commandline after /c or /k */ static BOOL bWaitForCommand = FALSE; /* When we are executing something passed on the commandline after /c or /k */
INT nErrorLevel = 0; /* Errorlevel of last launched external program */ INT nErrorLevel = 0; /* Errorlevel of last launched external program */
@ -1448,6 +1448,9 @@ ProcessInput(VOID)
while (!bCanExit || !bExit) while (!bCanExit || !bExit)
{ {
/* Reset the Ctrl-Break / Ctrl-C state */
bCtrlBreak = FALSE;
Cmd = ParseCommand(NULL); Cmd = ParseCommand(NULL);
if (!Cmd) if (!Cmd)
continue; continue;
@ -1500,7 +1503,7 @@ BOOL WINAPI BreakHandler(DWORD dwCtrlType)
/* FIXME: Handle batch files */ /* FIXME: Handle batch files */
//ConOutPrintf(_T("^C")); // ConOutPrintf(_T("^C"));
return TRUE; return TRUE;
} }

View file

@ -47,7 +47,7 @@
extern LPTSTR lpOriginalEnvironment; extern LPTSTR lpOriginalEnvironment;
extern WORD wColor; extern WORD wColor;
extern WORD wDefColor; extern WORD wDefColor;
extern volatile BOOL bCtrlBreak; extern BOOL bCtrlBreak;
extern BOOL bIgnoreEcho; extern BOOL bIgnoreEcho;
extern BOOL bExit; extern BOOL bExit;
extern BOOL bDisableBatchEcho; extern BOOL bDisableBatchEcho;

View file

@ -129,7 +129,7 @@ VOID GetPathCase( TCHAR * Path, TCHAR * OutPath)
* Check if Ctrl-Break was pressed during the last calls * Check if Ctrl-Break was pressed during the last calls
*/ */
BOOL CheckCtrlBreak (INT mode) BOOL CheckCtrlBreak(INT mode)
{ {
static BOOL bLeaveAll = FALSE; /* leave all batch files */ static BOOL bLeaveAll = FALSE; /* leave all batch files */
TCHAR options[4]; /* Yes, No, All */ TCHAR options[4]; /* Yes, No, All */
@ -138,10 +138,11 @@ BOOL CheckCtrlBreak (INT mode)
switch (mode) switch (mode)
{ {
case BREAK_OUTOFBATCH: case BREAK_OUTOFBATCH:
bLeaveAll = 0; bLeaveAll = FALSE;
return FALSE; return FALSE;
case BREAK_BATCHFILE: case BREAK_BATCHFILE:
{
if (bLeaveAll) if (bLeaveAll)
return TRUE; return TRUE;
@ -160,11 +161,15 @@ BOOL CheckCtrlBreak (INT mode)
ConOutChar(_T('\n')); ConOutChar(_T('\n'));
if (c == options[1]) if (c == options[1])
return bCtrlBreak = FALSE; /* ignore */ {
bCtrlBreak = FALSE; /* ignore */
return FALSE;
}
/* leave all batch files */ /* leave all batch files */
bLeaveAll = ((c == options[2]) || (c == _T('\3'))); bLeaveAll = ((c == options[2]) || (c == _T('\3')));
break; break;
}
case BREAK_INPUT: case BREAK_INPUT:
if (!bCtrlBreak) if (!bCtrlBreak)
@ -173,7 +178,6 @@ BOOL CheckCtrlBreak (INT mode)
} }
/* state processed */ /* state processed */
bCtrlBreak = FALSE;
return TRUE; return TRUE;
} }