diff options
-rw-r--r-- | src/modules/rkt/rkt_scener.c | 4 | ||||
-rw-r--r-- | src/setup.c | 2 | ||||
-rw-r--r-- | src/til_settings.c | 14 | ||||
-rw-r--r-- | src/til_settings.h | 2 |
4 files changed, 15 insertions, 7 deletions
diff --git a/src/modules/rkt/rkt_scener.c b/src/modules/rkt/rkt_scener.c index 25650c8..c491531 100644 --- a/src/modules/rkt/rkt_scener.c +++ b/src/modules/rkt/rkt_scener.c @@ -1061,8 +1061,8 @@ int rkt_scener_update(rkt_context_t *ctxt) } } - if (!setting->nocheck && til_setting_spec_check(&desc->spec, setting->value) < 0) { - /* setting invalid! go back to prompting for input */ + r = til_setting_check_spec(setting, &desc->spec); + if (r < 0) { /* setting invalid! go back to prompting for input */ scener->new_scene.cur_invalid = setting; return rkt_scener_send_error(scener, EINVAL, RKT_SCENER_FSM_SEND_NEWSCENE_SETUP_PROMPT); diff --git a/src/setup.c b/src/setup.c index c607f13..715708a 100644 --- a/src/setup.c +++ b/src/setup.c @@ -74,7 +74,7 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se } } - r = til_setting_spec_check(&desc->spec, setting->value); + r = til_setting_check_spec(setting, &desc->spec); if (r < 0) return setup_ret_failed_desc_path(desc, r, res_failed_desc_path); diff --git a/src/til_settings.c b/src/til_settings.c index eca937b..228a430 100644 --- a/src/til_settings.c +++ b/src/til_settings.c @@ -574,16 +574,24 @@ int til_setting_desc_fprint_path(const til_setting_desc_t *desc, FILE *out) /* TODO: spec checking in general needs refinement and to be less intolerant of * creative experimentation. */ -int til_setting_spec_check(const til_setting_spec_t *spec, const char *value) +/* Check's setting's value against the provided spec. + * If setting->nocheck is set the check is skipped. + * If spec->as_nested_settings is set, no check is performed, as it's not really applicable until leaf settings + */ +int til_setting_check_spec(const til_setting_t *setting, const til_setting_spec_t *spec) { assert(spec); - assert(value); + assert(setting); + assert(setting->value); + + if (setting->nocheck) + return 0; /* XXX: this check can't really be performed on anything but "leaf" settings. */ if (spec->values && !spec->as_nested_settings) { for (int i = 0; spec->values[i]; i++) { - if (!strcasecmp(spec->values[i], value)) + if (!strcasecmp(spec->values[i], setting->value)) return 0; } diff --git a/src/til_settings.h b/src/til_settings.h index 95b2ac4..0a72931 100644 --- a/src/til_settings.h +++ b/src/til_settings.h @@ -65,7 +65,7 @@ int til_setting_desc_new(const til_settings_t *settings, const til_setting_spec_ til_setting_desc_t * til_setting_desc_free(const til_setting_desc_t *desc); int til_setting_desc_strprint_path(const til_setting_desc_t *desc, til_str_t *str); int til_setting_desc_fprint_path(const til_setting_desc_t *desc, FILE *out); -int til_setting_spec_check(const til_setting_spec_t *spec, const char *value); +int til_setting_check_spec(const til_setting_t *setting, const til_setting_spec_t *spec); int til_setting_set_raw_value(til_setting_t *setting, const char *value); const char * til_setting_get_raw_value(til_setting_t *setting); int til_settings_label_setting(const til_settings_t *settings, const til_setting_t *setting, char **res_label); |