[pure-lang-svn] SF.net SVN: pure-lang:[744] pure/trunk/pure.cc
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-09-08 14:24:37
|
Revision: 744
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=744&view=rev
Author: agraef
Date: 2008-09-08 14:24:48 +0000 (Mon, 08 Sep 2008)
Log Message:
-----------
Windows kludges.
Modified Paths:
--------------
pure/trunk/pure.cc
Modified: pure/trunk/pure.cc
===================================================================
--- pure/trunk/pure.cc 2008-09-07 09:41:18 UTC (rev 743)
+++ pure/trunk/pure.cc 2008-09-08 14:24:48 UTC (rev 744)
@@ -171,6 +171,9 @@
static void sig_handler(int sig)
{
interpreter::brkflag = sig;
+#ifdef MUST_REINSTALL_SIGHANDLERS
+ signal(sig, sig_handler);
+#endif
}
static const char *histfile = 0;
@@ -180,6 +183,51 @@
if (histfile) write_history(histfile);
}
+#ifdef _WIN32
+
+/* Crappy Windoze doesn't have kill, so we need to set up a special kind of
+ "console" event handler for Ctrl+C. That at least enables PurePad to signal
+ us. */
+
+#include <windows.h>
+
+static HANDLE hSigInt, hSigTerm, hSignalHandler;
+
+static DWORD WINAPI SignalHandler(LPVOID dummy)
+{
+ HANDLE hEvents[2] = { hSigInt, hSigTerm };
+ while (1) {
+ DWORD ev = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
+ switch (ev) {
+ case WAIT_OBJECT_0:
+ raise(SIGINT);
+ break;
+ case WAIT_OBJECT_0+1:
+ raise(SIGTERM);
+ break;
+ default:
+ ExitProcess(0);
+ }
+ }
+}
+
+int InstallSignalHandler()
+{
+ TCHAR szSigInt[MAX_PATH], szSigTerm[MAX_PATH];
+ DWORD dwSignalHandler;
+ sprintf(szSigInt, "PURE_SIGINT-%u", GetCurrentProcessId());
+ sprintf(szSigTerm, "PURE_SIGTERM-%u", GetCurrentProcessId());
+ hSigInt = OpenEvent(EVENT_ALL_ACCESS, FALSE, szSigInt);
+ hSigTerm = OpenEvent(EVENT_ALL_ACCESS, FALSE, szSigTerm);
+ if (hSigInt != NULL && hSigTerm != NULL) {
+ hSignalHandler = CreateThread(NULL, 0, SignalHandler, NULL,
+ 0, &dwSignalHandler);
+ return hSignalHandler != NULL;
+ } else
+ return hSigInt == hSigTerm;
+}
+#endif
+
static inline bool chkfile(const string& s)
{
struct stat st;
@@ -259,6 +307,9 @@
#ifdef SIGUSR2
signal(SIGUSR2, sig_handler);
#endif
+#ifdef _WIN32
+ InstallSignalHandler();
+#endif
// set up an exit function which saves the history if needed
atexit(exit_handler);
// set the system locale
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|