From: Hugh McMaster Subject: [PATCH] cmd: Add basic handling of Ctrl-C Message-Id: Date: Thu, 26 Mar 2015 22:32:44 +1100 --- 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..6a7ae2e 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 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((PHANDLER_ROUTINE)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