diff -cr pgsql.orig/src/bin/psql/common.c pgsql/src/bin/psql/common.c *** pgsql.orig/src/bin/psql/common.c Fri Jan 9 22:12:20 2004 --- pgsql/src/bin/psql/common.c Wed Jan 14 12:59:57 2004 *************** *** 197,206 **** volatile bool cancel_pressed = false; - #ifndef WIN32 - #define write_stderr(String) write(fileno(stderr), String, strlen(String)) void handle_sigint(SIGNAL_ARGS) { --- 197,232 ---- volatile bool cancel_pressed = false; #define write_stderr(String) write(fileno(stderr), String, strlen(String)) + #ifdef WIN32 + + BOOL WINAPI handle_ctrlc(DWORD dwCtrlType) + { + int save_errno = errno; + + if (dwCtrlType == CTRL_C_EVENT && !(prompt_state || cancelConn == NULL)) + { + cancel_pressed = true; + + if (PQrequestCancel(cancelConn)) + write_stderr("Cancel request sent\n"); + else + { + write_stderr("Could not send cancel request: "); + write_stderr(PQerrorMessage(cancelConn)); + } + errno = save_errno; /* just in case the write changed it */ + + return TRUE; + } + + return FALSE; + } + + + #else + void handle_sigint(SIGNAL_ARGS) { *************** *** 224,230 **** } errno = save_errno; /* just in case the write changed it */ } ! #endif /* not WIN32 */ --- 250,256 ---- } errno = save_errno; /* just in case the write changed it */ } ! #endif /* WIN32 */ diff -cr pgsql.orig/src/bin/psql/common.h pgsql/src/bin/psql/common.h *** pgsql.orig/src/bin/psql/common.h Fri Jan 9 22:12:20 2004 --- pgsql/src/bin/psql/common.h Wed Jan 14 12:59:57 2004 *************** *** 35,43 **** extern void ResetCancelConn(void); ! #ifndef WIN32 extern void handle_sigint(SIGNAL_ARGS); ! #endif /* not WIN32 */ extern PGresult *PSQLexec(const char *query, bool start_xact); --- 35,45 ---- extern void ResetCancelConn(void); ! #ifdef WIN32 ! extern BOOL WINAPI handle_ctrlc(DWORD dwCtrlType); ! #else extern void handle_sigint(SIGNAL_ARGS); ! #endif /* WIN32 */ extern PGresult *PSQLexec(const char *query, bool start_xact); diff -cr pgsql.orig/src/bin/psql/mainloop.c pgsql/src/bin/psql/mainloop.c *** pgsql.orig/src/bin/psql/mainloop.c Sat Nov 29 20:52:06 2003 --- pgsql/src/bin/psql/mainloop.c Wed Jan 14 12:59:57 2004 *************** *** 16,23 **** #include "common.h" #include "command.h" - #ifndef WIN32 #include sigjmp_buf main_loop_jmp; #endif --- 16,25 ---- #include "common.h" #include "command.h" #include + #ifdef WIN32 + jmp_buf main_loop_jmp; + #else sigjmp_buf main_loop_jmp; #endif *************** *** 106,113 **** fflush(stdout); } ! #ifndef WIN32 if (sigsetjmp(main_loop_jmp, 1) != 0) { /* got here with longjmp */ --- 108,118 ---- fflush(stdout); } ! #ifdef WIN32 ! if (setjmp(main_loop_jmp)) ! #else if (sigsetjmp(main_loop_jmp, 1) != 0) + #endif /* WIN32 */ { /* got here with longjmp */ *************** *** 135,142 **** * establish the control-C handler only after main_loop_jmp is * ready */ pqsignal(SIGINT, handle_sigint); /* control-C => cancel */ ! #endif /* not WIN32 */ if (slashCmdStatus == CMD_NEWEDIT) { --- 140,150 ---- * establish the control-C handler only after main_loop_jmp is * ready */ + #ifdef WIN32 + SetConsoleCtrlHandler(handle_ctrlc,TRUE); + #else pqsignal(SIGINT, handle_sigint); /* control-C => cancel */ ! #endif /* WIN32 */ if (slashCmdStatus == CMD_NEWEDIT) { *************** *** 517,523 **** * it will re-enable ^C catching as soon as it gets back to the top of * its loop and resets main_loop_jmp to point to itself. */ ! #ifndef WIN32 pqsignal(SIGINT, SIG_DFL); #endif --- 525,533 ---- * it will re-enable ^C catching as soon as it gets back to the top of * its loop and resets main_loop_jmp to point to itself. */ ! #ifdef WIN32 ! SetConsoleCtrlHandler(handle_ctrlc,FALSE); ! #else pqsignal(SIGINT, SIG_DFL); #endif