[PATCH] cmd: Add basic handling of Ctrl-C (try 2)
Hugh McMaster
hugh.mcmaster at outlook.com
Fri Mar 27 05:53:14 CDT 2015
Changes in this version:
* PHANDLER_ROUTINE cast has been removed.
* Control handler is now BOOL WINAPI.
---
programs/cmd/wcmdmain.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index bc9b216..adaaaab 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -45,6 +45,7 @@ BOOL delayedsubst = FALSE; /* The current delayed substitution setting */
int defaultColor = 7;
BOOL echo_mode = TRUE;
+static CMD_LIST *toExecute = NULL; /* Commands left to be executed */
WCHAR anykey[100], version_string[100];
const WCHAR newlineW[] = {'\r','\n','\0'};
@@ -2318,6 +2319,14 @@ void WCMD_free_commands(CMD_LIST *cmds) {
}
}
+static BOOL WINAPI console_ctrl_handler(DWORD type)
+{
+ if (type == CTRL_C_EVENT) {
+ if (interactive && !toExecute)
+ return TRUE;
+ }
+ return FALSE;
+}
/*****************************************************************************
* Main entry point. This is a console application so we have a main() not a
@@ -2337,7 +2346,6 @@ int wmain (int argc, WCHAR *argvW[])
static const WCHAR offW[] = {'O','F','F','\0'};
static const WCHAR promptW[] = {'P','R','O','M','P','T','\0'};
static const WCHAR defaultpromptW[] = {'$','P','$','G','\0'};
- CMD_LIST *toExecute = NULL; /* Commands left to be executed */
OSVERSIONINFOW osv;
char osver[50];
@@ -2356,6 +2364,12 @@ int wmain (int argc, WCHAR *argvW[])
LocalFree(cmd);
cmd = NULL;
+ /* Enable handling of Ctrl-C signals */
+ if (SetConsoleCtrlHandler(console_ctrl_handler, TRUE))
+ WINE_TRACE("cmd: Ctrl handler was installed.\n");
+ else
+ WINE_ERR("cmd: Unable to install Ctrl handler.\n");
+
/* Can't use argc/argv as it will have stripped quotes from parameters
* meaning cmd.exe /C echo "quoted string" is impossible
*/
--
1.9.1
More information about the wine-patches
mailing list