diff options
author | LemonBoy <thatlemon@gmail.com> | 2016-06-13 14:03:00 +0200 |
---|---|---|
committer | LemonBoy <thatlemon@gmail.com> | 2016-06-13 14:03:00 +0200 |
commit | 9a30ab53df226acb4586a2f214f3994a7b8b32ea (patch) | |
tree | 60853f484c23b0accffa5befec474789ae685b7f /src | |
parent | 6f795f020d5c374023dc9ca647b267aef0a76950 (diff) | |
download | irssi-9a30ab53df226acb4586a2f214f3994a7b8b32ea.zip |
Move the validation of the CHOICE setting value
Also, use a FORMAT to show the error message.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/settings.c | 8 | ||||
-rw-r--r-- | src/fe-common/core/fe-settings.c | 10 | ||||
-rw-r--r-- | src/fe-common/core/module-formats.c | 1 | ||||
-rw-r--r-- | src/fe-common/core/module-formats.h | 1 |
4 files changed, 13 insertions, 7 deletions
diff --git a/src/core/settings.c b/src/core/settings.c index 8509a9ff..0716103a 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -387,15 +387,11 @@ gboolean settings_set_choice(const char *key, const char *value) rec = settings_get_record(key); - if (rec != NULL && strarray_find(rec->choices, value) < 0) { - char *msg = g_strjoinv(",", rec->choices); - g_warning("Invalid value for '%s', must be one of: %s", key, msg); - g_free(msg); - + if (rec != NULL && strarray_find(rec->choices, value) < 0) return FALSE; - } settings_set_str(key, value); + return TRUE; } diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c index ca1f871d..6f69d930 100644 --- a/src/fe-common/core/fe-settings.c +++ b/src/fe-common/core/fe-settings.c @@ -106,7 +106,15 @@ static void set_choice(const char *key, const char *value) stripped_value = g_strdup(value); g_strstrip(stripped_value); - settings_set_choice(key, stripped_value); + + if (settings_set_choice(key, stripped_value) == FALSE) { + SETTINGS_REC *rec = settings_get_record(key); + char *msg = g_strjoinv(",", rec->choices); + + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_CHOICE, msg); + g_free(msg); + } + g_free(stripped_value); } diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index b897b0c6..5c07f14c 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -221,6 +221,7 @@ FORMAT_REC fecommon_core_formats[] = { { "invalid_level", "Invalid message level", 0 }, { "invalid_size", "Invalid size", 0 }, { "invalid_charset", "Invalid charset: $0", 1, { 0 } }, + { "invalid_choice", "Invalid choice, must be one of $0", 1, { 0 } }, { "eval_max_recurse", "/eval hit maximum recursion limit", 0 }, { "program_not_found", "Could not find file or file is not executable", 0 }, { "no_server_defined", "No servers defined for this network, see /help server for how to add one", 0 }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index de1e13f2..2b45ff6b 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -190,6 +190,7 @@ enum { TXT_INVALID_LEVEL, TXT_INVALID_SIZE, TXT_INVALID_CHARSET, + TXT_INVALID_CHOICE, TXT_EVAL_MAX_RECURSE, TXT_PROGRAM_NOT_FOUND, TXT_NO_SERVER_DEFINED, |