From cc7d5c31b4d776458ee75bb0c4077b3348a226b3 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Thu, 24 Dec 2015 11:24:09 +0200 Subject: [PATCH] Allow optional parameter for boolean config options 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 | 1 + src/options.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/fixes36.1 b/doc/fixes36.1 index 4c55bc680..92e097380 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -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 diff --git a/src/options.c b/src/options.c index 37675c3d9..2f74c3564 100644 --- a/src/options.c +++ b/src/options.c @@ -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 */