summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-03 17:02:57 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-03 17:02:57 -0700
commitf2ad42777ddf96038e08a29cce81acc1b426ae1e (patch)
tree16ccbad5878899644449f93ed39b137b4d948485
parent595d5e8b54dde06d7f624d4e64458a2648477669 (diff)
til_settings: honor til_setting_t.nocheck in spec_check
Trivial refactor s/til_setting_spec_check/til_setting_check_spec/ so it operates on a til_setting_t as opposed to the bare value. With the containing til_setting_t onhand it can be responsible for bypassing the check when til_setting_t.nocheck is set. Adjusted callers in setup_interactively() and rkt_scener_update() accordingly.
-rw-r--r--src/modules/rkt/rkt_scener.c4
-rw-r--r--src/setup.c2
-rw-r--r--src/til_settings.c14
-rw-r--r--src/til_settings.h2
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);
© All Rights Reserved