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

@@ -36,7 +36,6 @@ static void consume_two_args(int, int *, char ***);
static void early_options(int *, char ***, char **);
ATTRNORETURN static void opt_terminate(void) NORETURN;
ATTRNORETURN static void opt_usage(const char *) NORETURN;
static void opt_showpaths(const char *);
ATTRNORETURN static void scores_only(int, char **, const char *) NORETURN;
#ifdef SND_LIB_INTEGRATED
uint32_t soundlibchoice = soundlib_nosound;
@@ -702,9 +701,10 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p)
break;
case 's':
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
opt_showpaths(*hackdir_p);
opt_terminate();
/*NOTREACHED*/
gd.deferred_showpaths = TRUE;
gd.deferred_showpaths_dir = *hackdir_p;
config_error_done();
return;
}
/* check for "-s" request to show scores */
if (lopt(arg, ((ArgValDisallowed | ArgErrComplain)
@@ -785,18 +785,16 @@ opt_usage(const char *hackdir)
/* show the sysconf file name, playground directory, run-time configuration
file name, dumplog file name if applicable, and some other things */
static void
opt_showpaths(const char *dir)
ATTRNORETURN void
after_opt_showpaths(const char *dir)
{
#ifdef CHDIR
chdirx(dir, FALSE);
#else
nhUse(dir);
#endif
iflags.initoptions_noterminate = TRUE;
initoptions();
iflags.initoptions_noterminate = FALSE;
reveal_paths();
opt_terminate();
/*NOTREACHED*/
}
/* handle "-s <score options> [character-names]" to show all the entries