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

@@ -108,14 +108,8 @@ nhmain(int argc, char *argv[])
#endif
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
#ifdef CHDIR
chdirx((char *) 0, 0);
#endif
iflags.initoptions_noterminate = TRUE;
initoptions();
iflags.initoptions_noterminate = FALSE;
reveal_paths();
exit(EXIT_SUCCESS);
gd.deferred_showpaths = TRUE;
return;
}
if (argcheck(argc, argv, ARG_DEBUG) == 1) {
argc--;

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

View File

@@ -80,15 +80,9 @@ main(int argc, char *argv[])
exit(EXIT_SUCCESS);
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
#ifdef CHDIR
chdirx((char *) 0, 0);
#endif
iflags.initoptions_noterminate = TRUE;
initoptions();
iflags.initoptions_noterminate = FALSE;
reveal_paths();
exit(EXIT_SUCCESS);
}
gd.deferred_showpaths = TRUE;
return;
}
if (argcheck(argc, argv, ARG_DEBUG) == 1) {
argc--;
argv++;

View File

@@ -18,9 +18,9 @@
#error You must #define SAFEPROCS to build windmain.c
#endif
static void process_options(int argc, char **argv);
static void nhusage(void);
static char *get_executable_path(void);
static void early_options(int argc, char **argv);
char *translate_path_variables(const char *, char *);
char *exename(void);
boolean fakeconsole(void);
@@ -242,6 +242,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
iflags.windowtype_deferred = TRUE;
copy_sysconf_content();
copy_symbols_content();
early_options(argc, argv);
initoptions();
/* Now that sysconf has had a chance to set the TROUBLEPREFIX, don't
@@ -249,7 +250,6 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
fqn_prefix_locked[TROUBLEPREFIX] = TRUE;
copy_config_content();
process_options(argc, argv);
/* did something earlier flag a need to exit without starting a game? */
if (windows_startup_state > 0) {
@@ -462,23 +462,18 @@ attempt_restore:
RESTORE_WARNING_UNREACHABLE_CODE
static void
process_options(int argc, char * argv[])
early_options(int argc, char *argv[])
{
int i;
/*
* Process options.
*/
if (argc > 1) {
if (argcheck(argc, argv, ARG_VERSION) == 2)
nethack_exit(EXIT_SUCCESS);
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
iflags.initoptions_noterminate = TRUE;
initoptions();
iflags.initoptions_noterminate = FALSE;
reveal_paths();
nethack_exit(EXIT_SUCCESS);
gd.deferred_showpaths = TRUE;
/* gd.deferred_showpaths is not used by windows */
return;
}
#ifndef NODUMPENUMS
if (argcheck(argc, argv, ARG_DUMPENUMS) == 2) {
@@ -509,7 +504,7 @@ process_options(int argc, char * argv[])
*/
argc--;
argv++;
const char * dir = argv[0] + 2;
const char *dir = argv[0] + 2;
if (*dir == '=' || *dir == ':')
dir++;
if (!*dir && argc > 1) {
@@ -578,7 +573,8 @@ process_options(int argc, char * argv[])
#endif
case 'u':
if (argv[0][2])
(void) strncpy(svp.plname, argv[0] + 2, sizeof(svp.plname) - 1);
(void) strncpy(svp.plname, argv[0] + 2,
sizeof(svp.plname) - 1);
else if (argc > 1) {
argc--;
argv++;
@@ -634,8 +630,8 @@ process_options(int argc, char * argv[])
break;
} else
raw_printf("\nUnknown switch: %s", argv[0]);
FALLTHROUGH;
/* FALLTHRU */
FALLTHROUGH;
/* FALLTHRU */
case '?':
nhusage();
nethack_exit(EXIT_SUCCESS);