allow DEBUGFILES to be overridden via getenv()
If getenv("DEBUGFILES") yields a value then it takes precedence over
sysconf.DEBUGFILES or sys.c's #define DEBUGFILES. (It probably should
only be controlled via environment since it is not a system-wide
attribute, but I haven't taken out the SYSCF handling for it.)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.5 sys.h $NHDT-Date: 1426496454 2015/03/16 09:00:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.12 $ */
|
||||
/* NetHack 3.5 sys.h $NHDT-Date: 1426544796 2015/03/16 22:26:36 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */
|
||||
/* NetHack 3.5 sys.h $Date: 2012/01/27 20:15:26 $ $Revision: 1.9 $ */
|
||||
/* Copyright (c) Kenneth Lorber, Kensington, Maryland, 2008. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -12,6 +12,11 @@ struct sysopt {
|
||||
char *wizards;
|
||||
char *shellers; /* like wizards, for ! command (-DSHELL) */
|
||||
char *debugfiles; /* files to show debugplines in. '*' is all. */
|
||||
int env_dbgfl; /* 1: debugfiles comes from getenv("DEBUGFILES")
|
||||
* so sysconf's DEBUGFILES shouldn't override it;
|
||||
* 0: getenv() hasn't been attempted yet;
|
||||
* -1: getenv() didn't find a value for DEBUGFILES.
|
||||
*/
|
||||
int maxplayers;
|
||||
/* record file */
|
||||
int persmax;
|
||||
|
||||
21
src/files.c
21
src/files.c
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.5 files.c $NHDT-Date: 1426465435 2015/03/16 00:23:55 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.133 $ */
|
||||
/* NetHack 3.5 files.c $NHDT-Date: 1426544796 2015/03/16 22:26:36 $ $NHDT-Branch: master $:$NHDT-Revision: 1.134 $ */
|
||||
/* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -2157,7 +2157,11 @@ int src;
|
||||
sysopt.shellers = dupstr(bufp);
|
||||
} else if (src == SET_IN_SYS && match_varname(buf, "DEBUGFILES", 5)) {
|
||||
if (sysopt.debugfiles) free(sysopt.debugfiles);
|
||||
sysopt.debugfiles = dupstr(bufp);
|
||||
/* if showdebug() has already been called (perhaps we've added
|
||||
some debugpline() calls to option processing) and has found
|
||||
a value for getenv("DEBUGFILES"), don't override that */
|
||||
if (sysopt.env_dbgfl == 0)
|
||||
sysopt.debugfiles = dupstr(bufp);
|
||||
} else if (src == SET_IN_SYS && match_varname(buf, "SUPPORT", 7)) {
|
||||
if (sysopt.support) free(sysopt.support);
|
||||
sysopt.support = dupstr(bufp);
|
||||
@@ -3207,6 +3211,19 @@ const char *filename;
|
||||
|
||||
if (!filename || !*filename) return FALSE; /* sanity precaution */
|
||||
|
||||
if (sysopt.env_dbgfl == 0) {
|
||||
/* check once for DEBUGFILES in the environment;
|
||||
if found, it supersedes the sysconf value
|
||||
[note: getenv() rather than nh_getenv() since a long value
|
||||
is valid and doesn't pose any sort of overflow risk here] */
|
||||
if ((p = getenv("DEBUGFILES")) != 0) {
|
||||
if (sysopt.debugfiles) free(sysopt.debugfiles);
|
||||
sysopt.debugfiles = dupstr(p);
|
||||
sysopt.env_dbgfl = 1;
|
||||
} else
|
||||
sysopt.env_dbgfl = -1;
|
||||
}
|
||||
|
||||
debugfiles = sysopt.debugfiles;
|
||||
/* usual case: sysopt.debugfiles will be empty */
|
||||
if (!debugfiles || !*debugfiles) return FALSE;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.5 sys.c $NHDT-Date: 1426496455 2015/03/16 09:00:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.17 $ */
|
||||
/* NetHack 3.5 sys.c $NHDT-Date: 1426544797 2015/03/16 22:26:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.18 $ */
|
||||
/* NetHack 3.5 sys.c $Date: 2012/03/10 02:22:07 $ $Revision: 1.12 $ */
|
||||
/* Copyright (c) Kenneth Lorber, Kensington, Maryland, 2008. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -10,6 +10,8 @@
|
||||
to enable debugging feedback for source files foo.c and bar.c;
|
||||
to activate debugpline(), set an appropriate value and uncomment */
|
||||
/* # define DEBUGFILES "*" */
|
||||
/* note: DEBUGFILES value here or in sysconf.DEBUGFILES can be overridden
|
||||
at runtime by setting up a value for "DEBUGFILES" in the environment */
|
||||
#endif
|
||||
|
||||
struct sysopt sysopt;
|
||||
@@ -29,6 +31,7 @@ sys_early_init()
|
||||
#else
|
||||
sysopt.debugfiles = dupstr(DEBUGFILES);
|
||||
#endif
|
||||
sysopt.env_dbgfl = 0; /* haven't checked getenv("DEBUGFILES") yet */
|
||||
sysopt.shellers = NULL;
|
||||
sysopt.maxplayers = 0; /* XXX eventually replace MAX_NR_OF_PLAYERS */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user