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.
This commit is contained in:
Pasi Kallinen
2015-12-24 11:24:09 +02:00
parent ad838c7e79
commit cc7d5c31b4
2 changed files with 19 additions and 1 deletions

View 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

View 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 */