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:
@@ -340,6 +340,10 @@ struct instance_globals_d {
|
|||||||
boolean decor_fumble_override;
|
boolean decor_fumble_override;
|
||||||
boolean decor_levitate_override;
|
boolean decor_levitate_override;
|
||||||
|
|
||||||
|
/* new */
|
||||||
|
boolean deferred_showpaths;
|
||||||
|
const char *deferred_showpaths_dir;
|
||||||
|
|
||||||
boolean havestate;
|
boolean havestate;
|
||||||
unsigned long magic; /* validate that structure layout is preserved */
|
unsigned long magic; /* validate that structure layout is preserved */
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-1
@@ -1072,11 +1072,12 @@ extern int nhclose(int);
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
extern boolean debugcore(const char *, boolean);
|
extern boolean debugcore(const char *, boolean);
|
||||||
#endif
|
#endif
|
||||||
extern void reveal_paths(void);
|
extern void reveal_paths(int);
|
||||||
extern boolean read_tribute(const char *, const char *, int, char *, int,
|
extern boolean read_tribute(const char *, const char *, int, char *, int,
|
||||||
unsigned);
|
unsigned);
|
||||||
extern boolean Death_quote(char *, int) NONNULLARG1;
|
extern boolean Death_quote(char *, int) NONNULLARG1;
|
||||||
extern void livelog_add(long ll_type, const char *) NONNULLARG2;
|
extern void livelog_add(long ll_type, const char *) NONNULLARG2;
|
||||||
|
ATTRNORETURN extern void do_deferred_showpaths(int) NORETURN;
|
||||||
|
|
||||||
/* ### fountain.c ### */
|
/* ### fountain.c ### */
|
||||||
|
|
||||||
@@ -3379,6 +3380,7 @@ extern void append_slash(char *) NONNULLARG1;
|
|||||||
extern boolean check_user_string(const char *) NONNULLARG1;
|
extern boolean check_user_string(const char *) NONNULLARG1;
|
||||||
extern char *get_login_name(void);
|
extern char *get_login_name(void);
|
||||||
extern unsigned long sys_random_seed(void);
|
extern unsigned long sys_random_seed(void);
|
||||||
|
ATTRNORETURN extern void after_opt_showpaths(const char *) NORETURN;
|
||||||
#endif /* UNIX */
|
#endif /* UNIX */
|
||||||
|
|
||||||
/* ### unixtty.c ### */
|
/* ### unixtty.c ### */
|
||||||
|
|||||||
@@ -339,6 +339,8 @@ static const struct instance_globals_d g_init_d = {
|
|||||||
/* pickup.c */
|
/* pickup.c */
|
||||||
FALSE, /* decor_fumble_override */
|
FALSE, /* decor_fumble_override */
|
||||||
FALSE, /* decor_levitate_override */
|
FALSE, /* decor_levitate_override */
|
||||||
|
FALSE, /* deferred_showpaths */
|
||||||
|
NULL, /* deferred_showpaths_dir */
|
||||||
TRUE, /* havestate*/
|
TRUE, /* havestate*/
|
||||||
IVMAGIC /* d_magic to validate that structure layout has been preserved */
|
IVMAGIC /* d_magic to validate that structure layout has been preserved */
|
||||||
};
|
};
|
||||||
|
|||||||
+32
-3
@@ -4467,6 +4467,8 @@ assure_syscf_file(void)
|
|||||||
close(fd);
|
close(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (gd.deferred_showpaths)
|
||||||
|
do_deferred_showpaths(1); /* does not return */
|
||||||
raw_printf("Unable to open SYSCF_FILE.\n");
|
raw_printf("Unable to open SYSCF_FILE.\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -4474,6 +4476,26 @@ assure_syscf_file(void)
|
|||||||
#endif /* SYSCF_FILE */
|
#endif /* SYSCF_FILE */
|
||||||
#endif /* SYSCF */
|
#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
|
#ifdef DEBUG
|
||||||
/* used by debugpline() to decide whether to issue a message
|
/* used by debugpline() to decide whether to issue a message
|
||||||
* from a particular source file; caller passes __FILE__ and we check
|
* from a particular source file; caller passes __FILE__ and we check
|
||||||
@@ -4534,9 +4556,11 @@ debugcore(const char *filename, boolean wildcards)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
reveal_paths(void)
|
reveal_paths(int code)
|
||||||
{
|
{
|
||||||
const char *fqn, *nodumpreason;
|
const char *fqn, *nodumpreason,
|
||||||
|
*sysconffile = "system configuration file";
|
||||||
|
|
||||||
char buf[BUFSZ];
|
char buf[BUFSZ];
|
||||||
#if defined(SYSCF) || !defined(UNIX) || defined(DLB)
|
#if defined(SYSCF) || !defined(UNIX) || defined(DLB)
|
||||||
const char *filep;
|
const char *filep;
|
||||||
@@ -4570,7 +4594,8 @@ reveal_paths(void)
|
|||||||
#else
|
#else
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
#endif
|
#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
|
#ifdef SYSCF_FILE
|
||||||
filep = SYSCF_FILE;
|
filep = SYSCF_FILE;
|
||||||
#else
|
#else
|
||||||
@@ -4582,6 +4607,10 @@ reveal_paths(void)
|
|||||||
filep = configfile;
|
filep = configfile;
|
||||||
}
|
}
|
||||||
raw_printf(" \"%s\"", filep);
|
raw_printf(" \"%s\"", filep);
|
||||||
|
if (code == 1) {
|
||||||
|
raw_printf("NOTE: The %s above is missing or inaccessible!",
|
||||||
|
sysconffile);
|
||||||
|
}
|
||||||
#else /* !SYSCF */
|
#else /* !SYSCF */
|
||||||
raw_printf("No system configuration file.");
|
raw_printf("No system configuration file.");
|
||||||
#endif /* ?SYSCF */
|
#endif /* ?SYSCF */
|
||||||
|
|||||||
@@ -6942,6 +6942,11 @@ initoptions(void)
|
|||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
#endif /* SYSCF */
|
#endif /* SYSCF */
|
||||||
|
|
||||||
|
/* Carry out options that got deferred from early_options */
|
||||||
|
if (gd.deferred_showpaths)
|
||||||
|
do_deferred_showpaths(0); /* does not return */
|
||||||
|
|
||||||
initoptions_finish();
|
initoptions_finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,14 +108,8 @@ nhmain(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
|
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
|
||||||
#ifdef CHDIR
|
gd.deferred_showpaths = TRUE;
|
||||||
chdirx((char *) 0, 0);
|
return;
|
||||||
#endif
|
|
||||||
iflags.initoptions_noterminate = TRUE;
|
|
||||||
initoptions();
|
|
||||||
iflags.initoptions_noterminate = FALSE;
|
|
||||||
reveal_paths();
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
}
|
||||||
if (argcheck(argc, argv, ARG_DEBUG) == 1) {
|
if (argcheck(argc, argv, ARG_DEBUG) == 1) {
|
||||||
argc--;
|
argc--;
|
||||||
|
|||||||
+8
-10
@@ -36,7 +36,6 @@ static void consume_two_args(int, int *, char ***);
|
|||||||
static void early_options(int *, char ***, char **);
|
static void early_options(int *, char ***, char **);
|
||||||
ATTRNORETURN static void opt_terminate(void) NORETURN;
|
ATTRNORETURN static void opt_terminate(void) NORETURN;
|
||||||
ATTRNORETURN static void opt_usage(const char *) 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;
|
ATTRNORETURN static void scores_only(int, char **, const char *) NORETURN;
|
||||||
#ifdef SND_LIB_INTEGRATED
|
#ifdef SND_LIB_INTEGRATED
|
||||||
uint32_t soundlibchoice = soundlib_nosound;
|
uint32_t soundlibchoice = soundlib_nosound;
|
||||||
@@ -702,9 +701,10 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p)
|
|||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
|
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
|
||||||
opt_showpaths(*hackdir_p);
|
gd.deferred_showpaths = TRUE;
|
||||||
opt_terminate();
|
gd.deferred_showpaths_dir = *hackdir_p;
|
||||||
/*NOTREACHED*/
|
config_error_done();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/* check for "-s" request to show scores */
|
/* check for "-s" request to show scores */
|
||||||
if (lopt(arg, ((ArgValDisallowed | ArgErrComplain)
|
if (lopt(arg, ((ArgValDisallowed | ArgErrComplain)
|
||||||
@@ -785,18 +785,16 @@ opt_usage(const char *hackdir)
|
|||||||
|
|
||||||
/* show the sysconf file name, playground directory, run-time configuration
|
/* show the sysconf file name, playground directory, run-time configuration
|
||||||
file name, dumplog file name if applicable, and some other things */
|
file name, dumplog file name if applicable, and some other things */
|
||||||
static void
|
ATTRNORETURN void
|
||||||
opt_showpaths(const char *dir)
|
after_opt_showpaths(const char *dir)
|
||||||
{
|
{
|
||||||
#ifdef CHDIR
|
#ifdef CHDIR
|
||||||
chdirx(dir, FALSE);
|
chdirx(dir, FALSE);
|
||||||
#else
|
#else
|
||||||
nhUse(dir);
|
nhUse(dir);
|
||||||
#endif
|
#endif
|
||||||
iflags.initoptions_noterminate = TRUE;
|
opt_terminate();
|
||||||
initoptions();
|
/*NOTREACHED*/
|
||||||
iflags.initoptions_noterminate = FALSE;
|
|
||||||
reveal_paths();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handle "-s <score options> [character-names]" to show all the entries
|
/* handle "-s <score options> [character-names]" to show all the entries
|
||||||
|
|||||||
+3
-9
@@ -80,15 +80,9 @@ main(int argc, char *argv[])
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
|
||||||
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
|
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
|
||||||
#ifdef CHDIR
|
gd.deferred_showpaths = TRUE;
|
||||||
chdirx((char *) 0, 0);
|
return;
|
||||||
#endif
|
}
|
||||||
iflags.initoptions_noterminate = TRUE;
|
|
||||||
initoptions();
|
|
||||||
iflags.initoptions_noterminate = FALSE;
|
|
||||||
reveal_paths();
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
if (argcheck(argc, argv, ARG_DEBUG) == 1) {
|
if (argcheck(argc, argv, ARG_DEBUG) == 1) {
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
|||||||
+11
-15
@@ -18,9 +18,9 @@
|
|||||||
#error You must #define SAFEPROCS to build windmain.c
|
#error You must #define SAFEPROCS to build windmain.c
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void process_options(int argc, char **argv);
|
|
||||||
static void nhusage(void);
|
static void nhusage(void);
|
||||||
static char *get_executable_path(void);
|
static char *get_executable_path(void);
|
||||||
|
static void early_options(int argc, char **argv);
|
||||||
char *translate_path_variables(const char *, char *);
|
char *translate_path_variables(const char *, char *);
|
||||||
char *exename(void);
|
char *exename(void);
|
||||||
boolean fakeconsole(void);
|
boolean fakeconsole(void);
|
||||||
@@ -242,6 +242,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
|||||||
iflags.windowtype_deferred = TRUE;
|
iflags.windowtype_deferred = TRUE;
|
||||||
copy_sysconf_content();
|
copy_sysconf_content();
|
||||||
copy_symbols_content();
|
copy_symbols_content();
|
||||||
|
early_options(argc, argv);
|
||||||
initoptions();
|
initoptions();
|
||||||
|
|
||||||
/* Now that sysconf has had a chance to set the TROUBLEPREFIX, don't
|
/* 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;
|
fqn_prefix_locked[TROUBLEPREFIX] = TRUE;
|
||||||
|
|
||||||
copy_config_content();
|
copy_config_content();
|
||||||
process_options(argc, argv);
|
|
||||||
|
|
||||||
/* did something earlier flag a need to exit without starting a game? */
|
/* did something earlier flag a need to exit without starting a game? */
|
||||||
if (windows_startup_state > 0) {
|
if (windows_startup_state > 0) {
|
||||||
@@ -462,23 +462,18 @@ attempt_restore:
|
|||||||
RESTORE_WARNING_UNREACHABLE_CODE
|
RESTORE_WARNING_UNREACHABLE_CODE
|
||||||
|
|
||||||
static void
|
static void
|
||||||
process_options(int argc, char * argv[])
|
early_options(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
|
||||||
* Process options.
|
|
||||||
*/
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
if (argcheck(argc, argv, ARG_VERSION) == 2)
|
if (argcheck(argc, argv, ARG_VERSION) == 2)
|
||||||
nethack_exit(EXIT_SUCCESS);
|
nethack_exit(EXIT_SUCCESS);
|
||||||
|
|
||||||
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
|
if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) {
|
||||||
iflags.initoptions_noterminate = TRUE;
|
gd.deferred_showpaths = TRUE;
|
||||||
initoptions();
|
/* gd.deferred_showpaths is not used by windows */
|
||||||
iflags.initoptions_noterminate = FALSE;
|
return;
|
||||||
reveal_paths();
|
|
||||||
nethack_exit(EXIT_SUCCESS);
|
|
||||||
}
|
}
|
||||||
#ifndef NODUMPENUMS
|
#ifndef NODUMPENUMS
|
||||||
if (argcheck(argc, argv, ARG_DUMPENUMS) == 2) {
|
if (argcheck(argc, argv, ARG_DUMPENUMS) == 2) {
|
||||||
@@ -509,7 +504,7 @@ process_options(int argc, char * argv[])
|
|||||||
*/
|
*/
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
const char * dir = argv[0] + 2;
|
const char *dir = argv[0] + 2;
|
||||||
if (*dir == '=' || *dir == ':')
|
if (*dir == '=' || *dir == ':')
|
||||||
dir++;
|
dir++;
|
||||||
if (!*dir && argc > 1) {
|
if (!*dir && argc > 1) {
|
||||||
@@ -578,7 +573,8 @@ process_options(int argc, char * argv[])
|
|||||||
#endif
|
#endif
|
||||||
case 'u':
|
case 'u':
|
||||||
if (argv[0][2])
|
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) {
|
else if (argc > 1) {
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
@@ -634,8 +630,8 @@ process_options(int argc, char * argv[])
|
|||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
raw_printf("\nUnknown switch: %s", argv[0]);
|
raw_printf("\nUnknown switch: %s", argv[0]);
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
/* FALLTHRU */
|
/* FALLTHRU */
|
||||||
case '?':
|
case '?':
|
||||||
nhusage();
|
nhusage();
|
||||||
nethack_exit(EXIT_SUCCESS);
|
nethack_exit(EXIT_SUCCESS);
|
||||||
|
|||||||
Reference in New Issue
Block a user