try harder to have --showpaths succeed

This helps avoid a potential chicken-and-egg scenario
with the system configuration file (sysconf).

If sysconf wasn't accessible at the expected location, it
caused an immediate exit, without relaying any helpful
information. That happened even when using:
    'nethack --showpaths'

That's particularly unhelpful, because the --showpaths
output might have been useful towards understanding where
NetHack was looking for such things.

That left you without an easy recourse to identify where
the game is looking for the sysconf file. That might be
especially troublesome if you didn't build the game
yourself.
This commit is contained in:
nhmall
2024-12-22 19:58:52 -05:00
parent 8b11bda6cb
commit 57f86662fd
9 changed files with 70 additions and 46 deletions

View File

@@ -339,6 +339,8 @@ static const struct instance_globals_d g_init_d = {
/* pickup.c */
FALSE, /* decor_fumble_override */
FALSE, /* decor_levitate_override */
FALSE, /* deferred_showpaths */
NULL, /* deferred_showpaths_dir */
TRUE, /* havestate*/
IVMAGIC /* d_magic to validate that structure layout has been preserved */
};

View File

@@ -4467,6 +4467,8 @@ assure_syscf_file(void)
close(fd);
return;
}
if (gd.deferred_showpaths)
do_deferred_showpaths(1); /* does not return */
raw_printf("Unable to open SYSCF_FILE.\n");
exit(EXIT_FAILURE);
}
@@ -4474,6 +4476,26 @@ assure_syscf_file(void)
#endif /* SYSCF_FILE */
#endif /* SYSCF */
ATTRNORETURN void
do_deferred_showpaths(int code)
{
gd.deferred_showpaths = FALSE;
reveal_paths(code);
#ifdef UNIX
after_opt_showpaths(gd.deferred_showpaths_dir);
#else
#ifdef CHDIR
chdirx(gd.deferred_showpaths_dir, 0);
#endif
#if defined(WIN32) || defined(MICRO) || defined(OS2)
nethack_exit(EXIT_SUCCESS);
#else
exit(EXIT_SUCCESS);
#endif
#endif
}
#ifdef DEBUG
/* used by debugpline() to decide whether to issue a message
* from a particular source file; caller passes __FILE__ and we check
@@ -4534,9 +4556,11 @@ debugcore(const char *filename, boolean wildcards)
#endif
void
reveal_paths(void)
reveal_paths(int code)
{
const char *fqn, *nodumpreason;
const char *fqn, *nodumpreason,
*sysconffile = "system configuration file";
char buf[BUFSZ];
#if defined(SYSCF) || !defined(UNIX) || defined(DLB)
const char *filep;
@@ -4570,7 +4594,8 @@ reveal_paths(void)
#else
buf[0] = '\0';
#endif
raw_printf("%s system configuration file%s:", s_suffix(gamename), buf);
raw_printf("%s %s%s:",
s_suffix(gamename), sysconffile, buf);
#ifdef SYSCF_FILE
filep = SYSCF_FILE;
#else
@@ -4582,6 +4607,10 @@ reveal_paths(void)
filep = configfile;
}
raw_printf(" \"%s\"", filep);
if (code == 1) {
raw_printf("NOTE: The %s above is missing or inaccessible!",
sysconffile);
}
#else /* !SYSCF */
raw_printf("No system configuration file.");
#endif /* ?SYSCF */

View File

@@ -6942,6 +6942,11 @@ initoptions(void)
*/
#endif
#endif /* SYSCF */
/* Carry out options that got deferred from early_options */
if (gd.deferred_showpaths)
do_deferred_showpaths(0); /* does not return */
initoptions_finish();
}