https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a3b36f8d3ec420169ff5e…
commit a3b36f8d3ec420169ff5e7bde505ce3275ef1f9f
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Apr 29 00:53:49 2018 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Apr 29 00:53:49 2018 +0200
[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.
---
base/shell/cmd/cmd.c | 7 +++++--
base/shell/cmd/cmd.h | 2 +-
base/shell/cmd/misc.c | 12 ++++++++----
3 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c
index d8414e0043..25ddae0c6f 100644
--- a/base/shell/cmd/cmd.c
+++ b/base/shell/cmd/cmd.c
@@ -151,7 +151,7 @@ typedef NTSTATUS (WINAPI *NtReadVirtualMemoryProc)(HANDLE, PVOID,
PVOID, ULONG,
BOOL bExit = FALSE; /* indicates EXIT was typed */
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 */
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 */
@@ -1448,6 +1448,9 @@ ProcessInput(VOID)
while (!bCanExit || !bExit)
{
+ /* Reset the Ctrl-Break / Ctrl-C state */
+ bCtrlBreak = FALSE;
+
Cmd = ParseCommand(NULL);
if (!Cmd)
continue;
@@ -1500,7 +1503,7 @@ BOOL WINAPI BreakHandler(DWORD dwCtrlType)
/* FIXME: Handle batch files */
- //ConOutPrintf(_T("^C"));
+ // ConOutPrintf(_T("^C"));
return TRUE;
}
diff --git a/base/shell/cmd/cmd.h b/base/shell/cmd/cmd.h
index 285916c74c..6a2f680a68 100644
--- a/base/shell/cmd/cmd.h
+++ b/base/shell/cmd/cmd.h
@@ -47,7 +47,7 @@
extern LPTSTR lpOriginalEnvironment;
extern WORD wColor;
extern WORD wDefColor;
-extern volatile BOOL bCtrlBreak;
+extern BOOL bCtrlBreak;
extern BOOL bIgnoreEcho;
extern BOOL bExit;
extern BOOL bDisableBatchEcho;
diff --git a/base/shell/cmd/misc.c b/base/shell/cmd/misc.c
index d7d7af3133..a6d2f54559 100644
--- a/base/shell/cmd/misc.c
+++ b/base/shell/cmd/misc.c
@@ -129,7 +129,7 @@ VOID GetPathCase( TCHAR * Path, TCHAR * OutPath)
* 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 */
TCHAR options[4]; /* Yes, No, All */
@@ -138,10 +138,11 @@ BOOL CheckCtrlBreak (INT mode)
switch (mode)
{
case BREAK_OUTOFBATCH:
- bLeaveAll = 0;
+ bLeaveAll = FALSE;
return FALSE;
case BREAK_BATCHFILE:
+ {
if (bLeaveAll)
return TRUE;
@@ -160,11 +161,15 @@ BOOL CheckCtrlBreak (INT mode)
ConOutChar(_T('\n'));
if (c == options[1])
- return bCtrlBreak = FALSE; /* ignore */
+ {
+ bCtrlBreak = FALSE; /* ignore */
+ return FALSE;
+ }
/* leave all batch files */
bLeaveAll = ((c == options[2]) || (c == _T('\3')));
break;
+ }
case BREAK_INPUT:
if (!bCtrlBreak)
@@ -173,7 +178,6 @@ BOOL CheckCtrlBreak (INT mode)
}
/* state processed */
- bCtrlBreak = FALSE;
return TRUE;
}