From a7152ad54e362b5c53d6ef17cf9fc71f0d2b2d0a Mon Sep 17 00:00:00 2001 From: nhmall Date: Sun, 5 Jan 2025 05:42:24 -0500 Subject: [PATCH] CROSS_TO_WASM build fix A couple of option processing functions, one of which was called in file.c, were recently added to sys/unix/unixmain.c, but the wasm build does not include unixmain.c, it uses sys/libnh/libnhmain.c. Transcribe the functions into sys/libnh/libnhmain.c. Also, do not #include "wintty.h" for NOTTYGRAPHICS builds. --- sys/libnh/libnhmain.c | 27 +++++++++++++++++++++++++++ sys/share/unixtty.c | 2 ++ 2 files changed, 29 insertions(+) diff --git a/sys/libnh/libnhmain.c b/sys/libnh/libnhmain.c index 289ee2c5f..562de1c78 100644 --- a/sys/libnh/libnhmain.c +++ b/sys/libnh/libnhmain.c @@ -51,6 +51,7 @@ extern void init_linux_cons(void); static void wd_message(void); static struct passwd *get_unix_pw(void); +ATTRNORETURN static void opt_terminate(void) NORETURN; #ifdef __EMSCRIPTEN__ /* if WebAssembly, export this API and don't optimize it out */ @@ -768,6 +769,32 @@ sys_random_seed(void) return seed; } +/* for command-line options that perform some immediate action and then + terminate the program without starting play, like 'nethack --version' + or 'nethack -s Zelda'; do some cleanup before that termination */ +ATTRNORETURN static void +opt_terminate(void) +{ + config_error_done(); /* free memory allocated by config_error_init() */ + + nh_terminate(EXIT_SUCCESS); + /*NOTREACHED*/ +} + +/* show the sysconf file name, playground directory, run-time configuration + file name, dumplog file name if applicable, and some other things */ +ATTRNORETURN void +after_opt_showpaths(const char *dir) +{ +#ifdef CHDIR + chdirx(dir, FALSE); +#else + nhUse(dir); +#endif + opt_terminate(); + /*NOTREACHED*/ +} + #ifdef __EMSCRIPTEN__ /*** * Helpers diff --git a/sys/share/unixtty.c b/sys/share/unixtty.c index c5f849e5c..3dce02269 100644 --- a/sys/share/unixtty.c +++ b/sys/share/unixtty.c @@ -11,7 +11,9 @@ #define NEED_VARARGS #include "hack.h" +#if defined(TTY_GRAPHICS) && !defined(NOTTYGRAPHICS) #include "wintty.h" +#endif /* * The distinctions here are not BSD - rest but rather USG - rest, as