https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d7e71357dc01fd62eec0a…
commit d7e71357dc01fd62eec0a7ece04c76cdd643e822
Author: James Woodcock <james_woodcock(a)yahoo.co.uk>
AuthorDate: Fri Apr 27 16:15:38 2018 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Apr 28 22:16:58 2018 +0200
[CMD] Fix CTRL-C handling.
Using CTRL-C to cancel command line input would leave the prompt in
a state where the next command would be ignored. For example:
dir<CTRL-C>
dir
would cause cmd.exe to ignore the second dir command.
---
base/shell/cmd/cmd.c | 11 +++++++++--
base/shell/cmd/cmd.h | 2 +-
base/shell/cmd/cmdinput.c | 17 ++++++++++++++---
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c
index 89a2b1b699..90dc6f1806 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 */
-BOOL bCtrlBreak = FALSE; /* Ctrl-Break or Ctrl-C hit */
+volatile 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 */
@@ -1423,6 +1423,12 @@ ReadLine(TCHAR *commandline, BOOL bMore)
ConOutChar(_T('\n'));
return FALSE;
}
+
+ if (readline[0] == L'\0')
+ {
+ return FALSE;
+ }
+
ip = readline;
}
else
@@ -1476,6 +1482,8 @@ BOOL WINAPI BreakHandler(DWORD dwCtrlType)
LeaveCriticalSection(&ChildProcessRunningLock);
}
+ bCtrlBreak = TRUE;
+
rec.EventType = KEY_EVENT;
rec.Event.KeyEvent.bKeyDown = TRUE;
rec.Event.KeyEvent.wRepeatCount = 1;
@@ -1490,7 +1498,6 @@ BOOL WINAPI BreakHandler(DWORD dwCtrlType)
1,
&dwWritten);
- bCtrlBreak = TRUE;
/* FIXME: Handle batch files */
//ConOutPrintf(_T("^C"));
diff --git a/base/shell/cmd/cmd.h b/base/shell/cmd/cmd.h
index 6a2f680a68..285916c74c 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 BOOL bCtrlBreak;
+extern volatile BOOL bCtrlBreak;
extern BOOL bIgnoreEcho;
extern BOOL bExit;
extern BOOL bDisableBatchEcho;
diff --git a/base/shell/cmd/cmdinput.c b/base/shell/cmd/cmdinput.c
index 5276d0d8af..09e5853608 100644
--- a/base/shell/cmd/cmdinput.c
+++ b/base/shell/cmd/cmdinput.c
@@ -450,12 +450,23 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
break;
case _T('C'):
- bCharInput = TRUE;
- if (!(ir.Event.KeyEvent.dwControlKeyState &
+ if ((ir.Event.KeyEvent.dwControlKeyState &
(RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)))
{
- break;
+ /* A CTRL-C. Don't clear the the command line,
+ * but return an empty string in str. */
+ str[0] = L'\0';
+ curx = orgx;
+ cury = orgy;
+ current = charcount = 0;
+ bReturn = TRUE;
}
+ else
+ {
+ /* Just a normal 'C' character */
+ bCharInput = TRUE;
+ }
+ break;
case VK_RETURN:
/* end input, return to main */