]> granicus.if.org Git - nethack/commitdiff
Allow optional parameter for boolean config options
authorPasi Kallinen <paxed@alt.org>
Thu, 24 Dec 2015 09:24:09 +0000 (11:24 +0200)
committerPasi Kallinen <paxed@alt.org>
Thu, 24 Dec 2015 09:24:13 +0000 (11:24 +0200)
Some people try to set boolean options in the config file
by giving the option a parameter, so allow that:

OPTIONS=color:true

Allowed parameters are "true", "yes", "false", and "no".
Negating an option and giving it a parameter is an error.

doc/fixes36.1
src/options.c

index 4c55bc6806be490c2c6c10afa73bbd8bd93dd3f4..92e097380215220cb24d68cd45458707502e317b 100644 (file)
@@ -55,6 +55,7 @@ make travel walk up to a trap and stop when the trap blocks the only
 travel will displace pets rather than stop
 do not autopickup unpaid items in shops
 death due an unseen gas spore's explosion resulted in "killed by a died"
+allow optional parameter "true", "yes", "false", or "no" for boolean options
 
 
 Platform- and/or Interface-Specific Fixes
index 37675c3d9ae3efdd074c9aab27c2d186074d6991..2f74c3564eab6e896b3c717690948e43b7a02cb7 100644 (file)
@@ -3298,7 +3298,7 @@ boolean tinitial, tfrom_file;
      * options list
      */
     for (i = 0; boolopt[i].name; i++) {
-        if (match_optname(opts, boolopt[i].name, 3, FALSE)) {
+        if (match_optname(opts, boolopt[i].name, 3, TRUE)) {
             /* options that don't exist */
             if (!boolopt[i].addr) {
                 if (!initial && !negated)
@@ -3312,6 +3312,23 @@ boolean tinitial, tfrom_file;
                 return;
             }
 
+            op = string_for_opt(opts, TRUE);
+
+            if (op) {
+                if (negated) {
+                    badoption(opts);
+                    return;
+                }
+                if (!strcmp(op, "true") || !strcmp(op, "yes"))
+                    negated = FALSE;
+                else if (!strcmp(op, "false") || !strcmp(op, "no"))
+                    negated = TRUE;
+                else {
+                    badoption(opts);
+                    return;
+                }
+            }
+
             *(boolopt[i].addr) = !negated;
 
             /* 0 means boolean opts */