summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-08-23 20:22:17 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-11 15:17:56 -0700
commitcf8c5c53a8831fa7c7e0c7d2fb929b76708d66e1 (patch)
tree8b400dee4a79344a4cfb133022f93a079c5c7f6e
parente0e2ef79c1a44e241bc324abe242c397d1d0c6ac (diff)
til_settings: add til_setting_desc_t.as_nested_settings
When this is set, the setting is itself to be a settings instance that the frontend must create and place in the relevant til_setting_t.value_as_nested_settings. This commit implements that frontend portion in setup_interactively() for the rototiller frontend. No setup_func() yet attempts to make use of this stuff. There's probably more change needed before that can happen, specifically the setup_func() likely must always produce a til_settings_t* to indicate which settings instance is currently relevant to the frontend. Without setup_func() telling the frontend, the frontend has basically no other way of knowing when the backend setup_func() has moved up/down the heirarchy at the current iteration.
-rw-r--r--src/setup.c14
-rw-r--r--src/til_settings.h1
2 files changed, 12 insertions, 3 deletions
diff --git a/src/setup.c b/src/setup.c
index 6b8677f..7d413f9 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -46,14 +46,22 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(til_settings
/* XXX FIXME: this key as value exception is janky, make a helper to access the value or stop doing that. */
r = til_setting_desc_check(desc, setting->value ? : setting->key);
if (r < 0) {
- /* TODO: send back desc to caller, caller must free. */
*res_failed_desc = desc;
return r;
}
- /* XXX FIXME everything's constified necessitating this fuckery, revisit and cleanup later, prolly another til_settings helper */
- ((til_setting_t *)setting)->desc = desc;
+ if (desc->as_nested_settings && !setting->settings) {
+ setting->settings = til_settings_new(setting->key, setting->value);
+ if (!setting->settings) {
+ *res_failed_desc = desc;
+
+ /* FIXME: til_settings_new() seems like it should return an errno, since it can encounter parse errors too? */
+ return -ENOMEM;
+ };
+ }
+
+ setting->desc = desc;
continue;
}
diff --git a/src/til_settings.h b/src/til_settings.h
index d4822be..8911e6c 100644
--- a/src/til_settings.h
+++ b/src/til_settings.h
@@ -16,6 +16,7 @@ typedef struct til_setting_desc_t {
const char **values; /* if a set of values is provided, listed here */
const char **annotations; /* if a set of values is provided, annotations for those values may be listed here */
char * (*random)(unsigned seed);/* if set, returns a valid random value for this setting */
+ unsigned as_nested_settings:1; /* if set, this setting expects a settings string for its value and wants a nested til_setting_t.settings instance created for it */
} til_setting_desc_t;
/* For conveniently representing setting description generators */
© All Rights Reserved