From: SHIRAKATA Kentaro Date: Thu, 4 Nov 2021 20:16:28 +0000 (+0900) Subject: add msghandler support for win32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a361af0846dcd9e53acb93c6e641b392ab76541;p=nethack add msghandler support for win32 --- diff --git a/include/config.h b/include/config.h index ac08772ab..d44f4b9f8 100644 --- a/include/config.h +++ b/include/config.h @@ -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 diff --git a/src/pline.c b/src/pline.c index 617d743b5..88b33c756 100644 --- a/src/pline.c +++ b/src/pline.c @@ -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