]> granicus.if.org Git - nethack/commitdiff
allow DEBUGFILES to be overridden via getenv()
authorPatR <rankin@nethack.org>
Mon, 16 Mar 2015 22:28:01 +0000 (15:28 -0700)
committerPasi Kallinen <paxed@alt.org>
Tue, 17 Mar 2015 16:47:38 +0000 (18:47 +0200)
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.)

include/sys.h
src/files.c
src/sys.c

index 940e95a119cddc05adf3f8211f7a3deda1daaa59..b97f7ca807e794995b594b746718ab5caa093f45 100644 (file)
@@ -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;
index 9e9cea7464559270196b6a456bb7e011f2f46faf..a6f17b9063012c36eab9e22f8575e15d9676de68 100644 (file)
@@ -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;
index 52489135e4824eef83cb8b3678b1729d4913ce8b..35e46b7c809f31f6280655871dc55a6b4924e9d0 100644 (file)
--- a/src/sys.c
+++ b/src/sys.c
@@ -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 */