From 976cb8fd61be3e0eef1267bf8a509388fe9977ab Mon Sep 17 00:00:00 2001 From: Dmitry Yakovlev Date: Wed, 25 Nov 2020 21:23:55 +0800 Subject: [PATCH] tools: idf_exe: add Ctrl+C processing --- tools/windows/idf_exe/idf_main.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/windows/idf_exe/idf_main.c b/tools/windows/idf_exe/idf_main.c index 3a8e6dcfbb..cbfcf7990f 100644 --- a/tools/windows/idf_exe/idf_main.c +++ b/tools/windows/idf_exe/idf_main.c @@ -32,6 +32,17 @@ static void fail(LPCSTR message, ...) ExitProcess(1); } +BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) +{ + switch (fdwCtrlType) { + // Handle the CTRL-C signal. + case CTRL_C_EVENT: + return TRUE; + default: + return FALSE; + } +} + int main(int argc, LPTSTR argv[]) { /* Print the version of this wrapper tool, but only if invoked as "idf.exe". @@ -42,8 +53,8 @@ int main(int argc, LPTSTR argv[]) int cmdname_length = strlen(cmdname); if (argc == 2 && - cmdname_length > 4 && - StrCmp(cmdname + cmdname_length - 4, TEXT(".exe")) == 0 && + cmdname_length > 4 && + StrCmp(cmdname + cmdname_length - 4, TEXT(".exe")) == 0 && (StrCmp(argv[1], TEXT("--version")) == 0 || StrCmp(argv[1], TEXT("-v")) == 0)) { LPCSTR msg = VERSION "\n"; @@ -79,6 +90,9 @@ int main(int argc, LPTSTR argv[]) SetEnvironmentVariable(TEXT("IDF_PY_PROGRAM_NAME"), idfpy_script_name); + // Add processing for Ctrl+C + SetConsoleCtrlHandler(CtrlHandler, TRUE); + /* Reuse the standard streams of this process */ STARTUPINFO start_info = { .cb = sizeof(STARTUPINFO),