options and config file handling
With SYSCF, the SYSCF_FILE name was overwriting the default config file name making it unavailable for subsequent user config file options handling. - Keep the name of the last config file successfully opened. - Do it without orphaning the default config file name needed for the next pass.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.5 decl.h $NHDT-Date: 1425081976 2015/02/28 00:06:16 $ $NHDT-Branch: master $:$NHDT-Revision: 1.50 $ */
|
/* NetHack 3.5 decl.h $NHDT-Date: 1427035422 2015/03/22 14:43:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.56 $ */
|
||||||
/* NetHack 3.5 decl.h $Date: 2011/12/29 20:06:27 $ $Revision: 1.44 $ */
|
/* NetHack 3.5 decl.h $Date: 2011/12/29 20:06:27 $ $Revision: 1.44 $ */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
@@ -184,6 +184,7 @@ E NEARDATA struct kinfo {
|
|||||||
|
|
||||||
E long done_money;
|
E long done_money;
|
||||||
E const char *configfile;
|
E const char *configfile;
|
||||||
|
E char lastconfigfile[BUFSZ]; /* used for messaging */
|
||||||
E NEARDATA char plname[PL_NSIZ];
|
E NEARDATA char plname[PL_NSIZ];
|
||||||
E NEARDATA char dogname[];
|
E NEARDATA char dogname[];
|
||||||
E NEARDATA char catname[];
|
E NEARDATA char catname[];
|
||||||
|
|||||||
55
src/files.c
55
src/files.c
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.5 files.c $NHDT-Date: 1426969026 2015/03/21 20:17:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.137 $ */
|
/* NetHack 3.5 files.c $NHDT-Date: 1427035432 2015/03/22 14:43:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.138 $ */
|
||||||
/* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */
|
/* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
@@ -1811,6 +1811,8 @@ const char *configfile =
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* used for messaging */
|
||||||
|
char lastconfigfile[BUFSZ];
|
||||||
|
|
||||||
#ifdef MSDOS
|
#ifdef MSDOS
|
||||||
/* conflict with speed-dial under windows
|
/* conflict with speed-dial under windows
|
||||||
@@ -1857,10 +1859,9 @@ int src;
|
|||||||
/* fall through to standard names */
|
/* fall through to standard names */
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if ((fp = fopenp(filename, "r")) != (FILE *)0) {
|
(void) strncpy(lastconfigfile, filename, BUFSZ-1);
|
||||||
#ifndef WIN32
|
lastconfigfile[BUFSZ-1] = '\0';
|
||||||
configfile = filename;
|
if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) {
|
||||||
#endif
|
|
||||||
return(fp);
|
return(fp);
|
||||||
#if defined(UNIX) || defined(VMS)
|
#if defined(UNIX) || defined(VMS)
|
||||||
} else {
|
} else {
|
||||||
@@ -1874,24 +1875,32 @@ int src;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MICRO) || defined(MAC) || defined(__BEOS__) || defined(WIN32)
|
#if defined(MICRO) || defined(MAC) || defined(__BEOS__) || defined(WIN32)
|
||||||
if ((fp = fopenp(fqname(configfile, CONFIGPREFIX, 0), "r"))
|
(void) strncpy(lastconfigfile,
|
||||||
!= (FILE *)0)
|
fqname(configfile, CONFIGPREFIX, 0), BUFSZ-1);
|
||||||
|
lastconfigfile[BUFSZ-1] = '\0';
|
||||||
|
if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) {
|
||||||
return(fp);
|
return(fp);
|
||||||
|
}
|
||||||
# ifdef MSDOS
|
# ifdef MSDOS
|
||||||
else if ((fp = fopenp(fqname(backward_compat_configfile,
|
(void) strncpy(lastconfigfile,
|
||||||
CONFIGPREFIX, 0), "r")) != (FILE *)0)
|
fqname(backward_compat_configfile, CONFIGPREFIX, 0),
|
||||||
|
BUFSZ-1);
|
||||||
|
lastconfigfile[BUFSZ-1] = '\0';
|
||||||
|
else if ((fp = fopenp(fqname(lastconfigfile, "r")) != (FILE *)0)
|
||||||
return(fp);
|
return(fp);
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
/* constructed full path names don't need fqname() */
|
/* constructed full path names don't need fqname() */
|
||||||
# ifdef VMS
|
# ifdef VMS
|
||||||
if ((fp = fopenp(fqname("nethackini", CONFIGPREFIX, 0), "r"))
|
(void) strncpy(lastconfigfile, fqname("nethackini", CONFIGPREFIX, 0),
|
||||||
!= (FILE *)0) {
|
BUFSZ-1);
|
||||||
configfile = "nethackini";
|
lastconfigfile[BUFSZ-1] = '\0';
|
||||||
|
if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) {
|
||||||
return(fp);
|
return(fp);
|
||||||
}
|
}
|
||||||
if ((fp = fopenp("sys$login:nethack.ini", "r")) != (FILE *)0) {
|
(void) strncpy(lastconfigfile,"sys$login:nethack.ini", BUFSZ-1);
|
||||||
configfile = "nethack.ini";
|
lastconfigfile[BUFSZ-1] = '\0';
|
||||||
|
if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) {
|
||||||
return(fp);
|
return(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1900,6 +1909,9 @@ int src;
|
|||||||
Strcpy(tmp_config, "NetHack.cnf");
|
Strcpy(tmp_config, "NetHack.cnf");
|
||||||
else
|
else
|
||||||
Sprintf(tmp_config, "%s%s", envp, "NetHack.cnf");
|
Sprintf(tmp_config, "%s%s", envp, "NetHack.cnf");
|
||||||
|
|
||||||
|
(void) strncpy(lastconfigfile, tmp_config, BUFSZ-1);
|
||||||
|
lastconfigfile[BUFSZ-1] = '\0';
|
||||||
if ((fp = fopenp(tmp_config, "r")) != (FILE *)0)
|
if ((fp = fopenp(tmp_config, "r")) != (FILE *)0)
|
||||||
return(fp);
|
return(fp);
|
||||||
# else /* should be only UNIX left */
|
# else /* should be only UNIX left */
|
||||||
@@ -1908,18 +1920,25 @@ int src;
|
|||||||
Strcpy(tmp_config, ".nethackrc");
|
Strcpy(tmp_config, ".nethackrc");
|
||||||
else
|
else
|
||||||
Sprintf(tmp_config, "%s/%s", envp, ".nethackrc");
|
Sprintf(tmp_config, "%s/%s", envp, ".nethackrc");
|
||||||
if ((fp = fopenp(tmp_config, "r")) != (FILE *)0)
|
|
||||||
|
(void) strncpy(lastconfigfile, tmp_config, BUFSZ-1);
|
||||||
|
lastconfigfile[BUFSZ-1] = '\0';
|
||||||
|
if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0)
|
||||||
return(fp);
|
return(fp);
|
||||||
# if defined(__APPLE__)
|
# if defined(__APPLE__)
|
||||||
/* try an alternative */
|
/* try an alternative */
|
||||||
if (envp) {
|
if (envp) {
|
||||||
Sprintf(tmp_config, "%s/%s", envp,
|
Sprintf(tmp_config, "%s/%s", envp,
|
||||||
"Library/Preferences/NetHack Defaults");
|
"Library/Preferences/NetHack Defaults");
|
||||||
if ((fp = fopenp(tmp_config, "r")) != (FILE *)0)
|
(void) strncpy(lastconfigfile, tmp_config, BUFSZ-1);
|
||||||
|
lastconfigfile[BUFSZ-1] = '\0';
|
||||||
|
if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0)
|
||||||
return(fp);
|
return(fp);
|
||||||
Sprintf(tmp_config, "%s/%s", envp,
|
Sprintf(tmp_config, "%s/%s", envp,
|
||||||
"Library/Preferences/NetHack Defaults.txt");
|
"Library/Preferences/NetHack Defaults.txt");
|
||||||
if ((fp = fopenp(tmp_config, "r")) != (FILE *)0)
|
(void) strncpy(lastconfigfile, tmp_config, BUFSZ-1);
|
||||||
|
lastconfigfile[BUFSZ-1] = '\0';
|
||||||
|
if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0)
|
||||||
return(fp);
|
return(fp);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
@@ -1934,7 +1953,7 @@ int src;
|
|||||||
# endif
|
# endif
|
||||||
details = "";
|
details = "";
|
||||||
raw_printf("Couldn't open default config file %s %s(%d).",
|
raw_printf("Couldn't open default config file %s %s(%d).",
|
||||||
tmp_config, details, errno);
|
lastconfigfile, details, errno);
|
||||||
wait_synch();
|
wait_synch();
|
||||||
}
|
}
|
||||||
# endif /* Unix */
|
# endif /* Unix */
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.5 options.c $NHDT-Date: 1425083082 2015/02/28 00:24:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.158 $ */
|
/* NetHack 3.5 options.c $NHDT-Date: 1427035440 2015/03/22 14:44:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.163 $ */
|
||||||
/* NetHack 3.5 options.c $Date: 2012/04/09 02:56:30 $ $Revision: 1.153 $ */
|
/* NetHack 3.5 options.c $Date: 2012/04/09 02:56:30 $ $Revision: 1.153 $ */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
@@ -798,10 +798,10 @@ rejectoption(optname)
|
|||||||
const char *optname;
|
const char *optname;
|
||||||
{
|
{
|
||||||
#ifdef MICRO
|
#ifdef MICRO
|
||||||
pline("\"%s\" settable only from %s.", optname, configfile);
|
pline("\"%s\" settable only from %s.", optname, lastconfigfile);
|
||||||
#else
|
#else
|
||||||
pline("%s can be set only from NETHACKOPTIONS or %s.", optname,
|
pline("%s can be set only from NETHACKOPTIONS or %s.", optname,
|
||||||
configfile);
|
lastconfigfile);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,7 +821,7 @@ const char *opts;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(from_file)
|
if(from_file)
|
||||||
raw_printf("Bad syntax in OPTIONS in %s: %s.", configfile, opts);
|
raw_printf("Bad syntax in OPTIONS in %s: %s.", lastconfigfile, opts);
|
||||||
else
|
else
|
||||||
raw_printf("Bad syntax in NETHACKOPTIONS: %s.", opts);
|
raw_printf("Bad syntax in NETHACKOPTIONS: %s.", opts);
|
||||||
|
|
||||||
@@ -4070,7 +4070,7 @@ option_help()
|
|||||||
winid datawin;
|
winid datawin;
|
||||||
|
|
||||||
datawin = create_nhwindow(NHW_TEXT);
|
datawin = create_nhwindow(NHW_TEXT);
|
||||||
Sprintf(buf, "Set options as OPTIONS=<options> in %s", configfile);
|
Sprintf(buf, "Set options as OPTIONS=<options> in %s", lastconfigfile);
|
||||||
opt_intro[CONFIG_SLOT] = (const char *) buf;
|
opt_intro[CONFIG_SLOT] = (const char *) buf;
|
||||||
for (i = 0; opt_intro[i]; i++)
|
for (i = 0; opt_intro[i]; i++)
|
||||||
putstr(datawin, 0, opt_intro[i]);
|
putstr(datawin, 0, opt_intro[i]);
|
||||||
|
|||||||
Reference in New Issue
Block a user