]> granicus.if.org Git - nethack/commitdiff
add msghandler support for win32
authorSHIRAKATA Kentaro <argrath@ub32.org>
Thu, 4 Nov 2021 20:16:28 +0000 (05:16 +0900)
committerPatR <rankin@nethack.org>
Tue, 3 May 2022 21:39:24 +0000 (14:39 -0700)
include/config.h
src/pline.c

index ac08772abfc6b8bda0d61335002fcbc906ffd8ac..d44f4b9f89af076cd00307e2eec7f225a9a0fa17 100644 (file)
@@ -554,7 +554,7 @@ typedef unsigned char uchar;
 /* NetHack will execute an external program whenever a new message-window
  * message is shown.  The program to execute is given in environment variable
  * NETHACK_MSGHANDLER.  It will get the message as the only parameter.
- * Only available with POSIX_TYPES or GNU C */
+ * Only available with POSIX_TYPES, GNU C, or WIN32 */
 /* #define MSGHANDLER */
 
 /* enable status highlighting via STATUS_HILITE directives in run-time
index 617d743b5fedfb648c7a3c98c266bd3ed0535e98..88b33c756e2cbdfdeb482f45ef484e6b5502e48e 100644 (file)
@@ -11,7 +11,7 @@
 
 static void putmesg(const char *);
 static char *You_buf(int);
-#if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__))
+#if defined(MSGHANDLER)
 static void execplinehandler(const char *);
 #endif
 #ifdef USER_SOUNDS
@@ -187,7 +187,7 @@ vpline(const char *line, va_list the_args)
 
     putmesg(line);
 
-#if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__))
+#if defined(MSGHANDLER)
     execplinehandler(line);
 #endif
 
@@ -486,7 +486,7 @@ vraw_printf(const char *line, va_list the_args)
         pbuf[BUFSZ - 1] = '\0'; /* terminate strncpy or truncate vsprintf */
     }
     raw_print(line);
-#if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__))
+#if defined(MSGHANDLER)
     execplinehandler(line);
 #endif
 }
@@ -528,7 +528,7 @@ impossible(const char *s, ...)
 
 RESTORE_WARNING_FORMAT_NONLITERAL
 
-#if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__))
+#if defined(MSGHANDLER)
 static boolean use_pline_handler = TRUE;
 
 static void
@@ -546,6 +546,7 @@ execplinehandler(const char *line)
         return;
     }
 
+#if defined(POSIX_TYPES) || defined(__GNUC__)
     f = fork();
     if (f == 0) { /* child */
         args[0] = env;
@@ -566,8 +567,19 @@ execplinehandler(const char *line)
         use_pline_handler = FALSE;
         pline("%s", "Fork to message handler failed.");
     }
+#elif defined(WIN32)
+    {
+        intptr_t ret;
+        args[0] = env;
+        args[1] = line;
+        args[2] = NULL;
+        ret = _spawnv(_P_NOWAIT, env, args);
+    }
+#else
+#error MSGHANDLER is not implemented on this sysytem.
+#endif
 }
-#endif /* MSGHANDLER && (POSIX_TYPES || __GNUC__) */
+#endif /* MSGHANDLER */
 
 /*
  * varargs handling for files.c