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