--showpaths wasn't returning the paths if there was an error in a config file
Also, Windows only: Introduces some environment variable substitution for paths specified in a config file
This commit is contained in:
@@ -268,6 +268,8 @@ struct instance_flags {
|
||||
boolean mon_polycontrol; /* debug: control monster polymorphs */
|
||||
boolean in_dumplog; /* doing the dumplog right now? */
|
||||
boolean in_parse; /* is a command being parsed? */
|
||||
/* suppress terminate during options parsing, for --showpaths */
|
||||
boolean initoptions_noterminate;
|
||||
|
||||
/* stuff that is related to options and/or user or platform preferences
|
||||
*/
|
||||
|
||||
17
src/files.c
17
src/files.c
@@ -151,6 +151,10 @@ static int lockptr;
|
||||
#ifndef WIN_CE
|
||||
#define DeleteFile unlink
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
/*from windmain.c */
|
||||
extern char *FDECL(translate_path_variables, (const char *, char *));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MAC
|
||||
@@ -350,6 +354,10 @@ const char *basenam;
|
||||
int whichprefix UNUSED_if_not_PREFIXES_IN_USE;
|
||||
int buffnum UNUSED_if_not_PREFIXES_IN_USE;
|
||||
{
|
||||
#ifdef WIN32
|
||||
char tmpbuf[BUFSZ];
|
||||
|
||||
#endif
|
||||
#ifndef PREFIXES_IN_USE
|
||||
return basenam;
|
||||
#else
|
||||
@@ -367,9 +375,16 @@ int buffnum UNUSED_if_not_PREFIXES_IN_USE;
|
||||
basenam);
|
||||
return basenam; /* XXX */
|
||||
}
|
||||
#ifdef WIN32
|
||||
if (strchr(fqn_prefix[whichprefix], '%') ||
|
||||
strchr(fqn_prefix[whichprefix], '~'))
|
||||
Strcpy(fqn_filename_buffer[buffnum],
|
||||
translate_path_variables(fqn_prefix[whichprefix], tmpbuf));
|
||||
else
|
||||
#endif
|
||||
Strcpy(fqn_filename_buffer[buffnum], fqn_prefix[whichprefix]);
|
||||
return strcat(fqn_filename_buffer[buffnum], basenam);
|
||||
#endif
|
||||
#endif /* !PREFIXES_IN_USE */
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -673,7 +673,7 @@ initoptions()
|
||||
|
||||
/* ... and _must_ parse correctly. */
|
||||
if (!read_config_file(SYSCF_FILE, SET_IN_SYS)) {
|
||||
if (config_error_done())
|
||||
if (config_error_done() && !iflags.initoptions_noterminate)
|
||||
nh_terminate(EXIT_FAILURE);
|
||||
}
|
||||
config_error_done();
|
||||
|
||||
@@ -118,7 +118,9 @@ char *argv[];
|
||||
#ifdef CHDIR
|
||||
chdirx((char *) 0, 0);
|
||||
#endif
|
||||
iflags.initoptions_noterminate = TRUE;
|
||||
initoptions();
|
||||
iflags.initoptions_noterminate = FALSE;
|
||||
reveal_paths();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
static void FDECL(process_options, (int argc, char **argv));
|
||||
static void NDECL(nhusage);
|
||||
static char *NDECL(get_executable_path);
|
||||
char *FDECL(translate_path_variables, (char *, char *));
|
||||
char *NDECL(exename);
|
||||
boolean NDECL(fakeconsole);
|
||||
void NDECL(freefakeconsole);
|
||||
@@ -62,8 +63,7 @@ char default_window_sys[] = "mswin";
|
||||
static struct stat hbuf;
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#if defined(WIN32) || defined(MSDOS)
|
||||
#endif
|
||||
|
||||
|
||||
extern char orgdir[];
|
||||
|
||||
@@ -548,7 +548,9 @@ char *argv[];
|
||||
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);
|
||||
}
|
||||
@@ -853,6 +855,61 @@ get_executable_path()
|
||||
return path_buffer;
|
||||
}
|
||||
|
||||
char *
|
||||
translate_path_variables(str, buf)
|
||||
const char *str;
|
||||
char *buf;
|
||||
{
|
||||
const char *src;
|
||||
char evar[BUFSZ], *dest, *envp, *eptr = (char *) 0;
|
||||
boolean in_evar;
|
||||
size_t ccount, ecount, destcount, slen = str ? strlen(str) : 0;
|
||||
|
||||
if (!slen || !buf) {
|
||||
if (buf)
|
||||
*buf = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
dest = buf;
|
||||
src = str;
|
||||
in_evar = FALSE;
|
||||
destcount = ecount = 0;
|
||||
for (ccount = 0; ccount < slen && destcount < (BUFSZ - 1) &&
|
||||
ecount < (BUFSZ - 1); ++ccount, ++src) {
|
||||
if (*src == '%') {
|
||||
if (in_evar) {
|
||||
*eptr = '\0';
|
||||
envp = nh_getenv(evar);
|
||||
if (envp) {
|
||||
size_t elen = strlen(envp);
|
||||
|
||||
if ((elen + destcount) < (size_t) (BUFSZ - 1)) {
|
||||
Strcpy(dest, envp);
|
||||
dest += elen;
|
||||
destcount += elen;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eptr = evar;
|
||||
ecount = 0;
|
||||
}
|
||||
in_evar = !in_evar;
|
||||
continue;
|
||||
}
|
||||
if (in_evar) {
|
||||
*eptr++ = *src;
|
||||
ecount++;
|
||||
} else {
|
||||
*dest++ = *src;
|
||||
destcount++;
|
||||
}
|
||||
}
|
||||
*dest = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
windows_raw_print(str)
|
||||
|
||||
Reference in New Issue
Block a user