implement handler for CTRL-C on windows.

This commit is contained in:
Axel Kohlmeyer
2020-10-04 16:42:29 -04:00
parent f3b33ea0c6
commit d500ffa784

View File

@ -29,7 +29,6 @@
#if !defined(_WIN32) #if !defined(_WIN32)
#include <signal.h> #include <signal.h>
#else
#endif #endif
#include <readline/history.h> #include <readline/history.h>
@ -206,12 +205,21 @@ extern "C" {
#if !defined(_WIN32) #if !defined(_WIN32)
static void ctrl_c_handler(int) static void ctrl_c_handler(int)
{
if (lmp)
if (lammps_is_running(lmp)) lammps_force_timeout(lmp);
}
#else #else
static BOOL WINAPI ctrl_c_handler(DWORD event)
#endif #endif
{
#if defined(_WIN32)
if (event == CTRL_C_EVENT) {
#endif
if (lmp)
if (lammps_is_running(lmp)) lammps_force_timeout(lmp);
#if defined(_WIN32)
return TRUE;
}
return FALSE;
#endif
}
static char *cmd_generator(const char *text, int state) static char *cmd_generator(const char *text, int state)
{ {
@ -473,6 +481,7 @@ static void init_commands()
#if !defined(_WIN32) #if !defined(_WIN32)
signal(SIGINT, ctrl_c_handler); signal(SIGINT, ctrl_c_handler);
#else #else
SetConsoleCtrlHandler(ctrl_c_handler, TRUE);
#endif #endif
} }
@ -493,6 +502,7 @@ static int shell_end()
{ {
write_history(".lammps_history"); write_history(".lammps_history");
if (lmp) lammps_close(lmp); if (lmp) lammps_close(lmp);
lammps_mpi_finalize();
lmp = nullptr; lmp = nullptr;
return 0; return 0;
} }