Even more config error handling

This commit is contained in:
Pasi Kallinen
2017-09-09 17:41:08 +03:00
parent 873590afc1
commit b9c52ff31c

View File

@@ -510,7 +510,7 @@ STATIC_DCL char *FDECL(string_for_opt, (char *, BOOLEAN_P));
STATIC_DCL char *FDECL(string_for_env_opt, (const char *, char *, BOOLEAN_P)); STATIC_DCL char *FDECL(string_for_env_opt, (const char *, char *, BOOLEAN_P));
STATIC_DCL void FDECL(bad_negation, (const char *, BOOLEAN_P)); STATIC_DCL void FDECL(bad_negation, (const char *, BOOLEAN_P));
STATIC_DCL int FDECL(change_inv_order, (char *)); STATIC_DCL int FDECL(change_inv_order, (char *));
STATIC_DCL void FDECL(warning_opts, (char *, const char *)); STATIC_DCL boolean FDECL(warning_opts, (char *, const char *));
STATIC_DCL int FDECL(feature_alert_opts, (char *, const char *)); STATIC_DCL int FDECL(feature_alert_opts, (char *, const char *));
STATIC_DCL boolean FDECL(duplicate_opt_detection, (const char *, int)); STATIC_DCL boolean FDECL(duplicate_opt_detection, (const char *, int));
STATIC_DCL void FDECL(complain_about_duplicate, (const char *, int)); STATIC_DCL void FDECL(complain_about_duplicate, (const char *, int));
@@ -1026,22 +1026,35 @@ char *op;
{ {
int oc_sym, num; int oc_sym, num;
char *sp, buf[QBUFSZ]; char *sp, buf[QBUFSZ];
int retval = 1;
num = 0; num = 0;
if (!index(op, GOLD_SYM)) if (!index(op, GOLD_SYM))
buf[num++] = COIN_CLASS; buf[num++] = COIN_CLASS;
for (sp = op; *sp; sp++) { for (sp = op; *sp; sp++) {
boolean fail = FALSE;
oc_sym = def_char_to_objclass(*sp); oc_sym = def_char_to_objclass(*sp);
/* reject bad or duplicate entries */ /* reject bad or duplicate entries */
if (oc_sym == MAXOCLASSES /* not an object class char */ if (oc_sym == MAXOCLASSES) { /* not an object class char */
config_error_add("Not an object class '%c'", *sp);
retval = 0;
fail = TRUE;
} else if (!index(flags.inv_order, oc_sym)) {
/* VENOM_CLASS, RANDOM_CLASS, and ILLOBJ_CLASS are excluded /* VENOM_CLASS, RANDOM_CLASS, and ILLOBJ_CLASS are excluded
because they aren't in def_inv_order[] so don't make it because they aren't in def_inv_order[] so don't make it
into flags.inv_order, hence always fail this index() test */ into flags.inv_order, hence always fail this index() test */
|| !index(flags.inv_order, oc_sym) || index(sp + 1, *sp)) config_error_add("Object class '%c' not allowed", *sp);
return 0; retval = 0;
fail = TRUE;
} else if (index(sp + 1, *sp)) {
config_error_add("Duplicate object class '%c'", *sp);
retval = 0;
fail = TRUE;
}
/* retain good ones */ /* retain good ones */
buf[num++] = (char) oc_sym; if (!fail)
buf[num++] = (char) oc_sym;
} }
buf[num] = '\0'; buf[num] = '\0';
@@ -1052,10 +1065,10 @@ char *op;
buf[MAXOCLASSES - 1] = '\0'; buf[MAXOCLASSES - 1] = '\0';
Strcpy(flags.inv_order, buf); Strcpy(flags.inv_order, buf);
return 1; return retval;
} }
STATIC_OVL void STATIC_OVL boolean
warning_opts(opts, optype) warning_opts(opts, optype)
register char *opts; register char *opts;
const char *optype; const char *optype;
@@ -1064,7 +1077,7 @@ const char *optype;
int length, i; int length, i;
if (!(opts = string_for_env_opt(optype, opts, FALSE))) if (!(opts = string_for_env_opt(optype, opts, FALSE)))
return; return FALSE;
escapes(opts, opts); escapes(opts, opts);
length = (int) strlen(opts); length = (int) strlen(opts);
@@ -1074,6 +1087,7 @@ const char *optype;
: opts[i] ? (uchar) opts[i] : opts[i] ? (uchar) opts[i]
: def_warnsyms[i].sym; : def_warnsyms[i].sym;
assign_warnings(translate); assign_warnings(translate);
return TRUE;
} }
void void
@@ -1970,9 +1984,10 @@ boolean tinitial, tfrom_file;
if (duplicate) if (duplicate)
complain_about_duplicate(opts, 1); complain_about_duplicate(opts, 1);
if ((op = string_for_env_opt(fullname, opts, negated)) != 0) { if ((op = string_for_env_opt(fullname, opts, negated)) != 0) {
if (negated) if (negated) {
bad_negation(fullname, TRUE); bad_negation(fullname, TRUE);
else return FALSE;
} else
switch (lowc(*op)) { switch (lowc(*op)) {
case 'd': /* dog */ case 'd': /* dog */
preferred_pet = 'd'; preferred_pet = 'd';
@@ -2010,8 +2025,10 @@ boolean tinitial, tfrom_file;
if (negated) { if (negated) {
bad_negation(fullname, FALSE); bad_negation(fullname, FALSE);
return FALSE; return FALSE;
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
nmcpy(catname, op, PL_PSIZ); nmcpy(catname, op, PL_PSIZ);
} else
return FALSE;
sanitize_name(catname); sanitize_name(catname);
return retval; return retval;
} }
@@ -2023,8 +2040,10 @@ boolean tinitial, tfrom_file;
if (negated) { if (negated) {
bad_negation(fullname, FALSE); bad_negation(fullname, FALSE);
return FALSE; return FALSE;
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
nmcpy(dogname, op, PL_PSIZ); nmcpy(dogname, op, PL_PSIZ);
} else
return FALSE;
sanitize_name(dogname); sanitize_name(dogname);
return retval; return retval;
} }
@@ -2036,8 +2055,10 @@ boolean tinitial, tfrom_file;
if (negated) { if (negated) {
bad_negation(fullname, FALSE); bad_negation(fullname, FALSE);
return FALSE; return FALSE;
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
nmcpy(horsename, op, PL_PSIZ); nmcpy(horsename, op, PL_PSIZ);
} else
return FALSE;
sanitize_name(horsename); sanitize_name(horsename);
return retval; return retval;
} }
@@ -2057,7 +2078,7 @@ boolean tinitial, tfrom_file;
iflags.num_pad_mode = 0; iflags.num_pad_mode = 0;
} }
} else if (negated) { } else if (negated) {
bad_negation("number_pad", TRUE); bad_negation(fullname, TRUE);
return FALSE; return FALSE;
} else { } else {
int mode = atoi(op); int mode = atoi(op);
@@ -2096,15 +2117,16 @@ boolean tinitial, tfrom_file;
symset[ROGUESET].name = dupstr(op); symset[ROGUESET].name = dupstr(op);
if (!read_sym_file(ROGUESET)) { if (!read_sym_file(ROGUESET)) {
clear_symsetentry(ROGUESET, TRUE); clear_symsetentry(ROGUESET, TRUE);
raw_printf("Unable to load symbol set \"%s\" from \"%s\".", config_error_add("Unable to load symbol set \"%s\" from \"%s\".",
op, SYMBOLS); op, SYMBOLS);
wait_synch(); return FALSE;
} else { } else {
if (!initial && Is_rogue_level(&u.uz)) if (!initial && Is_rogue_level(&u.uz))
assign_graphics(ROGUESET); assign_graphics(ROGUESET);
need_redraw = TRUE; need_redraw = TRUE;
} }
} } else
return FALSE;
return retval; return retval;
} }
@@ -2119,14 +2141,15 @@ boolean tinitial, tfrom_file;
symset[PRIMARY].name = dupstr(op); symset[PRIMARY].name = dupstr(op);
if (!read_sym_file(PRIMARY)) { if (!read_sym_file(PRIMARY)) {
clear_symsetentry(PRIMARY, TRUE); clear_symsetentry(PRIMARY, TRUE);
raw_printf("Unable to load symbol set \"%s\" from \"%s\".", config_error_add("Unable to load symbol set \"%s\" from \"%s\".",
op, SYMBOLS); op, SYMBOLS);
wait_synch(); return FALSE;
} else { } else {
switch_symbols(symset[PRIMARY].name != (char *) 0); switch_symbols(symset[PRIMARY].name != (char *) 0);
need_redraw = TRUE; need_redraw = TRUE;
} }
} } else
return FALSE;
return retval; return retval;
} }
@@ -2149,18 +2172,22 @@ boolean tinitial, tfrom_file;
config_error_add("Unknown %s parameter '%s'", fullname, op); config_error_add("Unknown %s parameter '%s'", fullname, op);
return FALSE; return FALSE;
} }
} } else
return FALSE;
return retval; return retval;
} }
/* menucolor:"regex_string"=color */ /* menucolor:"regex_string"=color */
fullname = "menucolor"; fullname = "menucolor";
if (match_optname(opts, fullname, 9, TRUE)) { if (match_optname(opts, fullname, 9, TRUE)) {
if (negated) if (negated) {
bad_negation(fullname, FALSE); bad_negation(fullname, FALSE);
else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) return FALSE;
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
if (!add_menu_coloring(op)) if (!add_menu_coloring(op))
return FALSE; return FALSE;
} else
return FALSE;
return retval; return retval;
} }
@@ -2454,7 +2481,8 @@ boolean tinitial, tfrom_file;
config_error_add("Unknown %s parameter '%s'", fullname, op); config_error_add("Unknown %s parameter '%s'", fullname, op);
return FALSE; return FALSE;
} }
} } else
return FALSE;
return retval; return retval;
} }
@@ -2483,7 +2511,8 @@ boolean tinitial, tfrom_file;
return FALSE; return FALSE;
} }
} }
} } else
return FALSE;
return retval; return retval;
} }
@@ -2494,9 +2523,8 @@ boolean tinitial, tfrom_file;
if (negated) { if (negated) {
bad_negation(fullname, FALSE); bad_negation(fullname, FALSE);
return FALSE; return FALSE;
} else }
warning_opts(opts, fullname); return warning_opts(opts, fullname);
return retval;
} }
#ifdef BACKWARD_COMPAT #ifdef BACKWARD_COMPAT
@@ -2549,8 +2577,10 @@ boolean tinitial, tfrom_file;
if (negated) { if (negated) {
bad_negation(fullname, FALSE); bad_negation(fullname, FALSE);
return FALSE; return FALSE;
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
nmcpy(plname, op, PL_NSIZ); nmcpy(plname, op, PL_NSIZ);
} else
return FALSE;
return retval; return retval;
} }
@@ -2567,7 +2597,8 @@ boolean tinitial, tfrom_file;
(void) strncpy(iflags.altkeyhandler, op, MAX_ALTKEYHANDLER - 5); (void) strncpy(iflags.altkeyhandler, op, MAX_ALTKEYHANDLER - 5);
load_keyboard_handler(); load_keyboard_handler();
#endif #endif
} } else
return FALSE;
return retval; return retval;
} }
@@ -2589,8 +2620,10 @@ boolean tinitial, tfrom_file;
config_error_add("Unknown %s parameter '%s'", fullname, op); config_error_add("Unknown %s parameter '%s'", fullname, op);
return FALSE; return FALSE;
} }
} else if (negated) } else if (negated) {
bad_negation(fullname, TRUE); bad_negation(fullname, TRUE);
return FALSE;
}
return retval; return retval;
} }
/* WINCAP /* WINCAP
@@ -2613,8 +2646,10 @@ boolean tinitial, tfrom_file;
config_error_add("Unknown %s parameter '%s'", fullname, op); config_error_add("Unknown %s parameter '%s'", fullname, op);
return FALSE; return FALSE;
} }
} else if (negated) } else if (negated) {
bad_negation(fullname, TRUE); bad_negation(fullname, TRUE);
return FALSE;
}
return retval; return retval;
} }
/* the order to list the pack */ /* the order to list the pack */