From c566c01f8d12588937ca428f79bc4b6c3618bc5c Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 9 Nov 2019 10:57:25 -0500 Subject: [PATCH] add command line option --showpaths Add --showpaths early option to show where NetHack is expecting to find certain files without starting up a game. It exits afterwards. Windows sample (for illustration only, locations may differ for you): Variable playground locations: [hackdir ]="C:\Users\JohnDoe\NetHack\3.6\" [leveldir ]="C:\Users\JohnDoe\AppData\Local\NetHack\3.6\" [savedir ]="C:\Users\JohnDoe\AppData\Local\NetHack\3.6\" [bonesdir ]="C:\ProgramData\NetHack\3.6\" [datadir ]="C:\personal\nhdev\363\test\binary\" [scoredir ]="C:\ProgramData\NetHack\3.6\" [lockdir ]="C:\ProgramData\NetHack\3.6\" [sysconfdir]="C:\ProgramData\NetHack\3.6\" [configdir ]="C:\Users\JohnDoe\NetHack\3.6\" [troubledir]="C:\Users\JohnDoe\NetHack\3.6\" Your system configuration file (in sysconfdir): "C:\Users\JohnDoe\NetHack\3.6\sysconf" Your system symbols file (in sysconfdir): "C:\Users\JohnDoe\NetHack\3.6\symbols" Your personal configuration file (in configdir): "C:\Users\JohnDoe\NetHack\3.6\.nethackrc" Linux (for illustration only, locations may differ for you): Your system configuration file: "/home/johndoe/nh/install/games/lib/nethackdir/sysconf" Your system symbols file: "/home/johndoe/nh/install/games/lib/nethackdir/symbols" Your personal configuration file: "/home/johndoe/.nethackrc" --- doc/nethack.6 | 7 +++ include/decl.h | 2 +- include/extern.h | 1 + src/allmain.c | 4 ++ src/files.c | 100 ++++++++++++++++++++++++++++++++++++++++++- sys/unix/unixmain.c | 6 ++- sys/winnt/windmain.c | 5 +++ 7 files changed, 122 insertions(+), 3 deletions(-) diff --git a/doc/nethack.6 b/doc/nethack.6 index ea704bb2f..dda4c89f4 100644 --- a/doc/nethack.6 +++ b/doc/nethack.6 @@ -47,6 +47,9 @@ nethack \- Exploring The Mazes of Menace .B \-ibm ] [ +.BR \-\-showpaths +] +[ .BR \-\-version [ :paste ] ] .PP @@ -223,6 +226,10 @@ the list of top scorers, and a subdirectory .I save where games are saved. .PP +.B \-\-showpaths +can be used to cause NetHack to show where it is expecting +to find various configuration files. +.PP .B \-\-version can be used to cause NetHack to show the version information it was compiled with, then exit. That will include the diff --git a/include/decl.h b/include/decl.h index 974af0f10..d5a2fe8cc 100644 --- a/include/decl.h +++ b/include/decl.h @@ -447,7 +447,7 @@ struct breadcrumbs { E const char *ARGV0; #endif -enum earlyarg {ARG_DEBUG, ARG_VERSION +enum earlyarg {ARG_DEBUG, ARG_VERSION, ARG_SHOWPATHS #ifdef WIN32 ,ARG_WINDOWS #endif diff --git a/include/extern.h b/include/extern.h index 989f07f50..ecef02aac 100644 --- a/include/extern.h +++ b/include/extern.h @@ -846,6 +846,7 @@ E void NDECL(really_close); #ifdef DEBUG E boolean FDECL(debugcore, (const char *, BOOLEAN_P)); #endif +E void NDECL(reveal_paths); E boolean FDECL(read_tribute, (const char *, const char *, int, char *, int, unsigned)); E boolean FDECL(Death_quote, (char *, int)); diff --git a/src/allmain.c b/src/allmain.c index 57170b66c..5111c69a7 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -767,6 +767,7 @@ const char *msg; static struct early_opt earlyopts[] = { {ARG_DEBUG, "debug", 5, TRUE}, {ARG_VERSION, "version", 4, TRUE}, + {ARG_SHOWPATHS, "showpaths", 9, FALSE}, #ifdef WIN32 {ARG_WINDOWS, "windows", 4, TRUE}, #endif @@ -845,6 +846,9 @@ enum earlyarg e_arg; early_version_info(insert_into_pastebuf); return 2; } + case ARG_SHOWPATHS: { + return 2; + } #ifdef WIN32 case ARG_WINDOWS: { if (extended_opt) { diff --git a/src/files.c b/src/files.c index c8bdb8ce1..48c9d37b4 100644 --- a/src/files.c +++ b/src/files.c @@ -3197,7 +3197,13 @@ fopen_sym_file() { FILE *fp; - fp = fopen_datafile(SYMBOLS, "r", HACKPREFIX); + fp = fopen_datafile(SYMBOLS, "r", +#ifdef WIN32 + SYSCONFPREFIX +#else + HACKPREFIX +#endif + ); return fp; } @@ -3966,6 +3972,98 @@ boolean wildcards; #endif /*DEBUG*/ +void +reveal_paths(VOID_ARGS) +{ + int i; +#define PATHBUFSZ 1024 + char buf[PATHBUFSZ]; +#ifdef UNIX + char *envp, *slash, nhpath[PATHBUFSZ]; +#endif + + /* write out path details */ +#ifdef PREFIXES_IN_USE + raw_print("Variable playground locations:"); + for (i = 0; i < PREFIX_COUNT; i++) + raw_printf(" [%-10s]=\"%s\"", fqn_prefix_names[i], + fqn_prefix[i] + ? fqn_prefix[i] + : "not set"); +#endif + /* sysconf file */ +#ifdef PREFIXES_IN_USE + Sprintf(buf, " (in %s)", + fqn_prefix_names[SYSCONFPREFIX]); +#else + buf[0] = '\0'; +#endif + raw_printf("Your system configuration file%s:", buf); + set_configfile_name(fqname(SYSCF_FILE, SYSCONFPREFIX, 0)); + raw_printf(" \"%s\"", configfile); +#ifdef UNIX + Strcpy(nhpath, configfile); + slash = rindex(nhpath, '/'); + if (slash) + *slash = '\0'; +#endif + + /* symbols file */ +#ifdef PREFIXES_IN_USE + Sprintf(buf, " (in %s)", +#ifdef WIN32 + fqn_prefix_names[SYSCONFPREFIX]); +#else + fqn_prefix_names[HACKPREFIX]); +#endif /* WIN32 */ +#else /* PREFIXES_IN_USE */ + buf[0] = '\0'; +#endif + + raw_printf("Your system symbols file%s:", buf); +#ifdef UNIX + Sprintf(buf, "%s/%s", nhpath, SYMBOLS); +#else +#ifdef PREFIXES_IN_USE + Sprintf(buf, "%s", + fqname(SYMBOLS, +#ifdef WIN32 + SYSCONFPREFIX, 2)); +#else + HACKPREFIX, 2)); +#endif +#endif /* PREFIXES_IN_USE */ +#endif /* UNIX */ + raw_printf(" \"%s\"", buf); + + /* configuration file */ +#ifdef PREFIXES_IN_USE + Sprintf(buf, " (in %s)", + fqn_prefix_names[CONFIGPREFIX]); +#else /* PREFIXES_IN_USE */ + buf[0] = '\0'; +#endif + raw_printf("Your personal configuration file%s:", buf); +#ifdef UNIX + envp = nh_getenv("HOME"); + if (!envp) + Strcpy(nhpath, ".nethackrc"); + else + Sprintf(nhpath, "%s/%s", envp, default_configfile); +#endif + raw_printf(" \"%s\"", +#ifdef UNIX + nhpath); +#else +#ifdef PREFIXES_IN_USE + fqname(default_configfile, CONFIGPREFIX, 3)); +#else + default_configfile); +#endif /* PREFIXES_IN_USE */ +#endif /* UNIX */ + raw_print(""); +} + /* ---------- BEGIN TRIBUTE ----------- */ /* 3.6 tribute code diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index 7e0fcd94a..90f07d63a 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -114,11 +114,15 @@ char *argv[]; if (argcheck(argc, argv, ARG_VERSION) == 2) exit(EXIT_SUCCESS); + if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) { + initoptions(); + reveal_paths(); + exit(EXIT_SUCCESS); + } if (argcheck(argc, argv, ARG_DEBUG) == 1) { argc--; argv++; } - if (argc > 1 && !strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { /* avoid matching "-dec" for DECgraphics; since the man page * says -d directory, hope nobody's using -desomething_else diff --git a/sys/winnt/windmain.c b/sys/winnt/windmain.c index 14ccd0089..950706b28 100644 --- a/sys/winnt/windmain.c +++ b/sys/winnt/windmain.c @@ -580,6 +580,11 @@ char *argv[]; if (argcheck(argc, argv, ARG_VERSION) == 2) nethack_exit(EXIT_SUCCESS); + if (argcheck(argc, argv, ARG_SHOWPATHS) == 2) { + initoptions(); + reveal_paths(); + nethack_exit(EXIT_SUCCESS); + } if (argcheck(argc, argv, ARG_DEBUG) == 1) { argc--; argv++;