From a4d52bcd363ee185ff20c74b3c97de96e314d381 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 9 May 2023 14:57:10 -0700 Subject: til_settings: make use of til_setting_desc_t.container This commit pivots everything over to using desc->container as the target settings instance when adding settings, as well as actually assigning the settings container @ desc create. Given nothing is actually triggering settings heirarchies yet (no specs set as_nested_settings) this shouldn't actually result in any realized functional difference, yet. The settings pointer being placed in desc->container should be identical to what was getting used before. --- src/setup.c | 6 +++--- src/til.c | 6 +++--- src/til_settings.c | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/setup.c b/src/setup.c index 8f9c5c1..5d99178 100644 --- a/src/setup.c +++ b/src/setup.c @@ -100,7 +100,7 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se if (*buf == '\n') { /* accept preferred */ - til_settings_add_value(settings, desc->spec.key, desc->spec.preferred, NULL); + til_settings_add_value(desc->container, desc->spec.key, desc->spec.preferred, NULL); } else { buf[strlen(buf) - 1] = '\0'; @@ -116,7 +116,7 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se for (found = i = 0; desc->spec.values[i]; i++) { if (i == j) { - til_settings_add_value(settings, desc->spec.key, desc->spec.values[i], NULL); + til_settings_add_value(desc->container, desc->spec.key, desc->spec.values[i], NULL); found = 1; break; } @@ -131,7 +131,7 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se } else { /* use typed input as setting, TODO: apply regex */ - til_settings_add_value(settings, desc->spec.key, buf, NULL); + til_settings_add_value(desc->container, desc->spec.key, buf, NULL); } } _next: diff --git a/src/til.c b/src/til.c index e1b4907..f5c2e8f 100644 --- a/src/til.c +++ b/src/til.c @@ -337,7 +337,7 @@ int til_module_randomize_setup(const til_module_t *module, unsigned seed, til_se char *value; value = desc->spec.random(rand_r(&seed)); - til_settings_add_value(settings, desc->spec.key, value, desc); + til_settings_add_value(desc->container, desc->spec.key, value, desc); free(value); } else if (desc->spec.values) { int n; @@ -346,9 +346,9 @@ int til_module_randomize_setup(const til_module_t *module, unsigned seed, til_se n = rand_r(&seed) % n; - til_settings_add_value(settings, desc->spec.key, desc->spec.values[n], desc); + til_settings_add_value(desc->container, desc->spec.key, desc->spec.values[n], desc); } else { - til_settings_add_value(settings, desc->spec.key, desc->spec.preferred, desc); + til_settings_add_value(desc->container, desc->spec.key, desc->spec.preferred, desc); } } diff --git a/src/til_settings.c b/src/til_settings.c index 4749372..4631849 100644 --- a/src/til_settings.c +++ b/src/til_settings.c @@ -363,6 +363,8 @@ int til_setting_desc_new(const til_settings_t *settings, const til_setting_spec_ if (!d) return -ENOMEM; + /* XXX: intentionally casting away the const here, since the purpose of desc->container is to point where to actually put the setting for the front-end setup code */ + d->container = (til_settings_t *)settings; if (spec->name) d->spec.name = strdup(spec->name); -- cgit v1.2.3