options follow-up: fix up duplicate_option_detection and !pet
This commit is contained in:
@@ -251,8 +251,6 @@ struct instance_flags {
|
||||
int menuinvertmode; /* 0 = invert toggles every item;
|
||||
1 = invert skips 'all items' item */
|
||||
int menu_headings; /* ATR for menu headings */
|
||||
int *opt_booldup; /* for duplication of boolean opts in config file */
|
||||
int *opt_compdup; /* for duplication of compound opts in conf file */
|
||||
#ifdef ALTMETA
|
||||
boolean altmeta; /* Alt-c sends ESC c rather than M-c */
|
||||
#endif
|
||||
|
||||
@@ -33,7 +33,7 @@ struct allopt_t {
|
||||
const char *alias;
|
||||
const char *descr;
|
||||
const char *prefixgw;
|
||||
boolean initval, has_handler, unused;
|
||||
boolean initval, has_handler, dupdetected;
|
||||
};
|
||||
|
||||
#endif /* OPTLIST_H */
|
||||
@@ -352,7 +352,7 @@ pfx_##a,
|
||||
&iflags.perm_invent)
|
||||
NHOPTC(petattr, 88, opt_in, set_in_game, No, Yes, No, No, NoAlias,
|
||||
"attributes for highlighting pets")
|
||||
NHOPTC(pettype, 4, opt_in, set_gameview, Yes, Yes, No, No, NoAlias,
|
||||
NHOPTC(pettype, 4, opt_in, set_gameview, Yes, Yes, No, No, "pet",
|
||||
"your preferred initial pet type")
|
||||
NHOPTC(pickup_burden, 20, opt_in, set_in_game, No, Yes, No, Yes, NoAlias,
|
||||
"maximum burden picked up before prompt")
|
||||
@@ -408,10 +408,10 @@ pfx_##a,
|
||||
NHOPTB(showrace, 0, opt_in, set_in_game, Off, Yes, No, No, NoAlias,
|
||||
&flags.showrace)
|
||||
#ifdef SCORE_ON_BOTL
|
||||
NHOPTB(showscore, 0, opt_in, set_in_game, Off, No, No, No, NoAlias,
|
||||
NHOPTB(showscore, 0, opt_in, set_in_game, Off, Yes, No, No, NoAlias,
|
||||
&flags.showscore)
|
||||
#else
|
||||
NHOPTB(showscore, 0, opt_in, set_in_config, Off, No, No, No, NoAlias,
|
||||
NHOPTB(showscore, 0, opt_in, set_in_config, Off, Yes, No, No, NoAlias,
|
||||
(boolean *) 0)
|
||||
#endif
|
||||
NHOPTB(silent, 0, opt_out, set_in_game, On, Yes, No, No, NoAlias,
|
||||
@@ -516,6 +516,13 @@ pfx_##a,
|
||||
"video width")
|
||||
NHOPTC(video_height, 10, opt_in, set_gameview, No, Yes, No, No, NoAlias,
|
||||
"video height")
|
||||
#endif
|
||||
#ifdef TTY_TILES_ESCCODES
|
||||
NHOPTB(vt_tiledata, 0, opt_out, set_in_config, On, Yes, No, No, NoAlias,
|
||||
&iflags.vt_tiledata)
|
||||
#else
|
||||
NHOPTB(vt_tiledata, 0, opt_out, set_in_config, On, Yes, No, No, NoAlias,
|
||||
(boolean *) 0)
|
||||
#endif
|
||||
NHOPTC(warnings, 10, opt_in, set_in_config, No, Yes, No, No, NoAlias,
|
||||
"display characters for warnings")
|
||||
|
||||
105
src/options.c
105
src/options.c
@@ -230,8 +230,8 @@ static void FDECL(bad_negation, (const char *, BOOLEAN_P));
|
||||
static int FDECL(change_inv_order, (char *));
|
||||
static boolean FDECL(warning_opts, (char *, const char *));
|
||||
static int FDECL(feature_alert_opts, (char *, const char *));
|
||||
static boolean FDECL(duplicate_opt_detection, (const char *, int));
|
||||
static void FDECL(complain_about_duplicate, (const char *, int));
|
||||
static boolean FDECL(duplicate_opt_detection, (int));
|
||||
static void FDECL(complain_about_duplicate, (int));
|
||||
static int FDECL(length_without_val, (const char *, int len));
|
||||
static void NDECL(determine_ambiguities);
|
||||
static int FDECL(check_misc_menu_command, (char *, char *));
|
||||
@@ -247,7 +247,7 @@ static boolean FDECL(test_regex_pattern, (const char *, const char *));
|
||||
static boolean FDECL(add_menu_coloring_parsed, (char *, int, int));
|
||||
static void FDECL(free_one_menu_coloring, (int));
|
||||
static int NDECL(count_menucolors);
|
||||
static boolean FDECL(parse_role_opts, (BOOLEAN_P, const char *,
|
||||
static boolean FDECL(parse_role_opts, (int, BOOLEAN_P, const char *,
|
||||
char *, char **));
|
||||
static void FDECL(doset_add_menu, (winid, const char *, int, int));
|
||||
static void FDECL(opts_add_others, (winid, const char *, int,
|
||||
@@ -414,9 +414,9 @@ boolean tinitial, tfrom_file;
|
||||
g.program_state.in_parseoptions++;
|
||||
|
||||
if (got_match && matchidx >= 0) {
|
||||
duplicate = duplicate_opt_detection(opts, 1);
|
||||
duplicate = duplicate_opt_detection(matchidx);
|
||||
if (duplicate && !allopt[matchidx].dupeok)
|
||||
complain_about_duplicate(opts, 1);
|
||||
complain_about_duplicate(matchidx);
|
||||
|
||||
/* check for bad negation, so option functions don't have to */
|
||||
if (negated && !allopt[matchidx].negateok) {
|
||||
@@ -506,7 +506,7 @@ char *op;
|
||||
return optn_ok;
|
||||
}
|
||||
if (req == do_set) {
|
||||
if (parse_role_opts(negated, allopt[optidx].name, opts, &op)) {
|
||||
if (parse_role_opts(optidx, negated, allopt[optidx].name, opts, &op)) {
|
||||
if ((flags.initalign = str2align(op)) == ROLE_NONE) {
|
||||
config_error_add("Unknown %s '%s'", allopt[optidx].name, op);
|
||||
return optn_err;
|
||||
@@ -1312,7 +1312,7 @@ char *op;
|
||||
}
|
||||
if (req == do_set) {
|
||||
/* gender:string */
|
||||
if (parse_role_opts(negated, allopt[optidx].name, opts, &op)) {
|
||||
if (parse_role_opts(optidx, negated, allopt[optidx].name, opts, &op)) {
|
||||
if ((flags.initgend = str2gend(op)) == ROLE_NONE) {
|
||||
config_error_add("Unknown %s '%s'", allopt[optidx].name, op);
|
||||
return optn_err;
|
||||
@@ -2453,7 +2453,7 @@ char *op;
|
||||
|
||||
#ifndef WIN32
|
||||
if (duplicate)
|
||||
complain_about_duplicate(opts, 1);
|
||||
complain_about_duplicate(optidx);
|
||||
#endif
|
||||
#ifdef MAC
|
||||
if (match_optname(opts, "hicolor", 3, TRUE)) {
|
||||
@@ -3032,7 +3032,7 @@ char *op;
|
||||
}
|
||||
if (req == do_set) {
|
||||
/* race:string */
|
||||
if (parse_role_opts(negated, allopt[optidx].name, opts, &op)) {
|
||||
if (parse_role_opts(optidx, negated, allopt[optidx].name, opts, &op)) {
|
||||
if ((flags.initrace = str2race(op)) == ROLE_NONE) {
|
||||
config_error_add("Unknown %s '%s'", allopt[optidx].name, op);
|
||||
return optn_err;
|
||||
@@ -3107,7 +3107,7 @@ char *op;
|
||||
return optn_ok;
|
||||
}
|
||||
if (req == do_set) {
|
||||
if (parse_role_opts(negated, allopt[optidx].name, opts, &op)) {
|
||||
if (parse_role_opts(optidx, negated, allopt[optidx].name, opts, &op)) {
|
||||
if ((flags.initrole = str2role(op)) == ROLE_NONE) {
|
||||
config_error_add("Unknown %s '%s'", allopt[optidx].name, op);
|
||||
return optn_err;
|
||||
@@ -4381,7 +4381,7 @@ char *op;
|
||||
return optn_err;
|
||||
}
|
||||
if (duplicate)
|
||||
complain_about_duplicate(opts, 1);
|
||||
complain_about_duplicate(optidx);
|
||||
if (opttype > 0 && !negated
|
||||
&& (op = string_for_opt(opts, FALSE)) != empty_optstr) {
|
||||
switch (opttype) {
|
||||
@@ -4519,8 +4519,8 @@ char *op;
|
||||
return optn_err;
|
||||
|
||||
/* 0 means boolean opts */
|
||||
if (duplicate_opt_detection(allopt[optidx].name, 0))
|
||||
complain_about_duplicate(allopt[optidx].name, 0);
|
||||
if (duplicate_opt_detection(optidx))
|
||||
complain_about_duplicate(optidx);
|
||||
|
||||
op = string_for_opt(opts, TRUE);
|
||||
if (op != empty_optstr) {
|
||||
@@ -5791,72 +5791,24 @@ void
|
||||
set_duplicate_opt_detection(on_or_off)
|
||||
int on_or_off;
|
||||
{
|
||||
int k, *optptr;
|
||||
int k;
|
||||
|
||||
if (on_or_off != 0) {
|
||||
/*-- ON --*/
|
||||
if (iflags.opt_booldup)
|
||||
impossible("iflags.opt_booldup already on (memory leak)");
|
||||
iflags.opt_booldup = (int *) alloc(SIZE(allopt) * sizeof (int));
|
||||
optptr = iflags.opt_booldup;
|
||||
for (k = 0; k < SIZE(allopt); ++k)
|
||||
*optptr++ = 0;
|
||||
|
||||
if (iflags.opt_compdup)
|
||||
impossible("iflags.opt_compdup already on (memory leak)");
|
||||
iflags.opt_compdup = (int *) alloc(SIZE(allopt) * sizeof (int));
|
||||
optptr = iflags.opt_compdup;
|
||||
for (k = 0; k < SIZE(allopt); ++k)
|
||||
*optptr++ = 0;
|
||||
} else {
|
||||
/*-- OFF --*/
|
||||
if (iflags.opt_booldup)
|
||||
free((genericptr_t) iflags.opt_booldup);
|
||||
iflags.opt_booldup = (int *) 0;
|
||||
if (iflags.opt_compdup)
|
||||
free((genericptr_t) iflags.opt_compdup);
|
||||
iflags.opt_compdup = (int *) 0;
|
||||
}
|
||||
for (k = 0; k < OPTCOUNT; ++k)
|
||||
allopt[k].dupdetected = 0;
|
||||
}
|
||||
|
||||
static boolean
|
||||
duplicate_opt_detection(opts, iscompound)
|
||||
const char *opts;
|
||||
int iscompound; /* 0 == boolean option, 1 == compound */
|
||||
duplicate_opt_detection(optidx)
|
||||
int optidx;
|
||||
{
|
||||
int i, *optptr;
|
||||
|
||||
if (!iscompound && iflags.opt_booldup && g.opt_initial && g.opt_from_file) {
|
||||
for (i = 0; allopt[i].name; i++) {
|
||||
if (match_optname(opts, allopt[i].name, 3, FALSE)) {
|
||||
optptr = iflags.opt_booldup + i;
|
||||
*optptr += 1;
|
||||
if (*optptr > 1)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
} else if (iscompound && iflags.opt_compdup && g.opt_initial && g.opt_from_file) {
|
||||
for (i = 0; allopt[i].name; i++) {
|
||||
if (match_optname(opts, allopt[i].name, strlen(allopt[i].name),
|
||||
TRUE)) {
|
||||
optptr = iflags.opt_compdup + i;
|
||||
*optptr += 1;
|
||||
if (*optptr > 1)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (g.opt_initial && g.opt_from_file)
|
||||
return allopt[optidx].dupdetected;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
complain_about_duplicate(opts, iscompound)
|
||||
const char *opts;
|
||||
int iscompound; /* 0 == boolean option, 1 == compound */
|
||||
complain_about_duplicate(optidx)
|
||||
int optidx;
|
||||
{
|
||||
#ifdef MAC
|
||||
/* the Mac has trouble dealing with the output of messages while
|
||||
@@ -5865,7 +5817,8 @@ int iscompound; /* 0 == boolean option, 1 == compound */
|
||||
*/
|
||||
#else /* !MAC */
|
||||
config_error_add("%s option specified multiple times: %s",
|
||||
iscompound ? "compound" : "boolean", opts);
|
||||
(allopt[optidx].opttyp == CompOpt) ? "compound" : "boolean",
|
||||
allopt[optidx].name);
|
||||
#endif /* ?MAC */
|
||||
return;
|
||||
}
|
||||
@@ -6099,9 +6052,6 @@ initoptions_init()
|
||||
init_random(rn2);
|
||||
init_random(rn2_on_display_rng);
|
||||
|
||||
/* for detection of configfile options specified multiple times */
|
||||
iflags.opt_booldup = iflags.opt_compdup = (int *) 0;
|
||||
|
||||
for (i = 0; allopt[i].name; i++) {
|
||||
if (allopt[i].addr)
|
||||
*(allopt[i].addr) = allopt[i].initval;
|
||||
@@ -7099,7 +7049,8 @@ count_menucolors(VOID_ARGS)
|
||||
}
|
||||
|
||||
static boolean
|
||||
parse_role_opts(negated, fullname, opts, opp)
|
||||
parse_role_opts(optidx, negated, fullname, opts, opp)
|
||||
int optidx;
|
||||
boolean negated;
|
||||
const char *fullname;
|
||||
char *opts;
|
||||
@@ -7126,8 +7077,8 @@ char **opp;
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
if (duplicate_opt_detection(opts, 1))
|
||||
complain_about_duplicate(opts, 1);
|
||||
if (duplicate_opt_detection(optidx))
|
||||
complain_about_duplicate(optidx);
|
||||
*opp = op;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user