From cf8c5c53a8831fa7c7e0c7d2fb929b76708d66e1 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 23 Aug 2022 20:22:17 -0700 Subject: 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. --- src/setup.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/setup.c') 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; } -- cgit v1.2.1