From 8736141f680ecb6f2acfa79377b7fef2351061a0 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Thu, 31 Jan 2019 10:46:41 +0200 Subject: [PATCH] Option handling return values and errors Fix some options not stopping when encountering an error, some didn't show up any errors, and other minor fixes. --- src/options.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/options.c b/src/options.c index 77d6d6338..b7ec363a2 100644 --- a/src/options.c +++ b/src/options.c @@ -3301,8 +3301,10 @@ boolean tinitial, tfrom_file; } else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { return FALSE; } - if (!assign_videocolors(opts)) /* TODO: error msg */ + if (!assign_videocolors(opts)) { + config_error_add("Unknown error handling '%s'", fullname); return FALSE; + } return retval; } /* videoshades:string */ @@ -3316,8 +3318,10 @@ boolean tinitial, tfrom_file; } else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { return FALSE; } - if (!assign_videoshades(opts)) /* TODO: error msg */ + if (!assign_videoshades(opts)) { + config_error_add("Unknown error handling '%s'", fullname); return FALSE; + } return retval; } #endif /* VIDEOSHADES */ @@ -3334,8 +3338,10 @@ boolean tinitial, tfrom_file; } else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { return FALSE; } - if (!assign_video(opts)) /* TODO: error msg */ + if (!assign_video(opts)) { + config_error_add("Unknown error handling '%s'", fullname); return FALSE; + } return retval; } #endif /* NO_TERMS */ @@ -3350,8 +3356,10 @@ boolean tinitial, tfrom_file; } else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { return FALSE; } - if (!assign_soundcard(opts)) /* TODO: error msg */ + if (!assign_soundcard(opts)) { + config_error_add("Unknown error handling '%s'", fullname); return FALSE; + } return retval; } #endif /* MSDOS */ @@ -3575,10 +3583,14 @@ boolean tinitial, tfrom_file; if (duplicate) complain_about_duplicate(opts, 1); if ((op = string_for_opt(opts, FALSE)) != 0) { - if (!wc_set_window_colors(op)) /* TODO: error msg*/ + if (!wc_set_window_colors(op)) { + config_error_add("Could not set %s '%s'", fullname, op); return FALSE; - } else if (negated) + } + } else if (negated) { bad_negation(fullname, TRUE); + return FALSE; + } return retval; } #ifdef CURSES_GRAPHICS @@ -3588,8 +3600,10 @@ boolean tinitial, tfrom_file; if (match_optname(opts, fullname, sizeof "term_cols" - 1, TRUE)) { op = string_for_opt(opts, negated); iflags.wc2_term_cols = atoi(op); - if (negated) - bad_negation(fullname, FALSE); + if (negated) { + bad_negation(fullname, FALSE); + return FALSE; + } return retval; } @@ -3599,8 +3613,10 @@ boolean tinitial, tfrom_file; if (match_optname(opts, fullname, sizeof "term_rows" - 1, TRUE)) { op = string_for_opt(opts, negated); iflags.wc2_term_rows = atoi(op); - if (negated) + if (negated) { bad_negation(fullname, FALSE); + return FALSE; + } return retval; } @@ -3612,16 +3628,20 @@ boolean tinitial, tfrom_file; if (op && !negated) { #ifdef CURSES_GRAPHICS iflags.wc2_petattr = curses_read_attrs(op); - if (!curses_read_attrs(op)) + if (!curses_read_attrs(op)) { config_error_add("Unknown %s parameter '%s'", fullname, opts); return FALSE; + } #else /* non-curses windowports will not use this flag anyway * but the above will not compile if we don't have curses. * Just set it to a sensible default: */ iflags.wc2_petattr = ATR_INVERSE #endif - } else if (negated) bad_negation(fullname, TRUE); + } else if (negated) { + bad_negation(fullname, TRUE); + return FALSE; + } return retval; } @@ -3630,9 +3650,10 @@ boolean tinitial, tfrom_file; fullname = "windowborders"; if (match_optname(opts, fullname, sizeof "windowborders" - 1, TRUE)) { op = string_for_opt(opts, negated); - if (negated && op) + if (negated && op) { bad_negation(fullname, TRUE); - else { + return FALSE; + } else { if (negated) iflags.wc2_windowborders = 2; /* Off */ else if (!op) @@ -3643,6 +3664,7 @@ boolean tinitial, tfrom_file; || (iflags.wc2_windowborders < 1)) { iflags.wc2_windowborders = 0; config_error_add("Badoption - windowborders %s.", opts); + return FALSE; } } return retval;