summaryrefslogtreecommitdiff
path: root/src/setup.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-05-09 11:43:22 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-11 15:18:34 -0700
commit31a0147a720f2f0ef30df41512f41f43734662dd (patch)
treec381b2905eaf5cde93b83b2ee93adc148400b488 /src/setup.c
parent1a8abe80dabd6b723897fc507808db30b126b3a4 (diff)
til_settings: introduce til_setting_spec_t concept vs. desc
For recursive settings the individual setting being described needs to get added to a potentially different settings instance than the one being operated on at the top of the current setup_func phase. The settings instance being passed around for a setup_func to operate on is constified, mainly to try ensure modules don't start directly mucking with the settings. They're supposed to just describe what they want next and iterate back and forth, with the front-end creating the settings from the returned descs however is appropriate, eventually building up the settings to completion. But since it's the setup_func that decides which settings instance is appropriate for containing the setting.. at some point it must associate a settings instance with the desc it's producing, one that is going to be necessarily written to. So here I'm just turning the existing til_setting_desc_t to a "spec", unchanged. And introducing a new til_setting_desc_t embedding the spec, accompanied by a non-const til_settings_t* "container". Now what setup_funcs use to express settings are a spec, otherwise identically to before. Instead of cloning a desc to allocate it for returning to the front-end, the desc is created from a spec with the target settings instance passed in. This turns the desc step where we take a constified settings instance and cast it into a non-const a more formal act of going from spec->desc, binding the spec to a specific settings instance. It will also serve to isolate that hacky cast to a til_settings function, and all the accessors of til_setting_desc_t needing to operate on the containing settings instance can just do so. As of this commit, the container pointer is just sitting in the desc_t but isn't being made use of or even assigned yet. This is just to minimize the amount of churn happening in this otherwise mostly mechanical and sprawling commit. There's also been some small changes surrounding the desc generators and plumbing of the settings instance where there previously wasn't any. It's unclear to me if desc generators will stay desc generators or turn into spec generators. For now those are mostly just used by the drm_fb stuff anyways, modules haven't made use of them, so they can stay a little crufty harmlessly for now.
Diffstat (limited to 'src/setup.c')
-rw-r--r--src/setup.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/setup.c b/src/setup.c
index 7c13ea0..8f9c5c1 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -29,16 +29,16 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se
*/
if (setting && !setting->desc) {
/* 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);
+ r = til_setting_spec_check(&desc->spec, setting->value ? : setting->key);
if (r < 0) {
*res_failed_desc = desc;
return r;
}
- if (desc->as_nested_settings && !setting->settings) {
- setting->settings = til_settings_new(setting->key, setting->value);
- if (!setting->settings) {
+ if (desc->spec.as_nested_settings && !setting->value_as_nested_settings) {
+ setting->value_as_nested_settings = til_settings_new(setting->key, setting->value);
+ if (!setting->value_as_nested_settings) {
*res_failed_desc = desc;
/* FIXME: til_settings_new() seems like it should return an errno, since it can encounter parse errors too? */
@@ -54,39 +54,39 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se
if (!defaults)
puts("");
- if (desc->values) {
+ if (desc->spec.values) {
unsigned i, preferred = 0;
int width = 0;
- for (i = 0; desc->values[i]; i++) {
+ for (i = 0; desc->spec.values[i]; i++) {
int len;
- len = strlen(desc->values[i]);
+ len = strlen(desc->spec.values[i]);
if (len > width)
width = len;
}
/* multiple choice */
if (!defaults)
- printf("%s:\n", desc->name);
+ printf("%s:\n", desc->spec.name);
- for (i = 0; desc->values[i]; i++) {
+ for (i = 0; desc->spec.values[i]; i++) {
if (!defaults)
- printf("%2u: %*s%s%s\n", i, width, desc->values[i],
- desc->annotations ? ": " : "",
- desc->annotations ? desc->annotations[i] : "");
+ printf("%2u: %*s%s%s\n", i, width, desc->spec.values[i],
+ desc->spec.annotations ? ": " : "",
+ desc->spec.annotations ? desc->spec.annotations[i] : "");
- if (!strcasecmp(desc->preferred, desc->values[i]))
+ if (!strcasecmp(desc->spec.preferred, desc->spec.values[i]))
preferred = i;
}
if (!defaults)
printf("Enter a value 0-%u [%u (%s)]: ",
- i - 1, preferred, desc->preferred);
+ i - 1, preferred, desc->spec.preferred);
} else {
/* arbitrarily typed input */
if (!defaults)
- printf("%s [%s]: ", desc->name, desc->preferred);
+ printf("%s [%s]: ", desc->spec.name, desc->spec.preferred);
}
if (!defaults) {
@@ -100,11 +100,11 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se
if (*buf == '\n') {
/* accept preferred */
- til_settings_add_value(settings, desc->key, desc->preferred, NULL);
+ til_settings_add_value(settings, desc->spec.key, desc->spec.preferred, NULL);
} else {
buf[strlen(buf) - 1] = '\0';
- if (desc->values) {
+ if (desc->spec.values) {
unsigned i, j, found;
/* multiple choice, map numeric input to values entry */
@@ -114,9 +114,9 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se
goto _next;
}
- for (found = i = 0; desc->values[i]; i++) {
+ for (found = i = 0; desc->spec.values[i]; i++) {
if (i == j) {
- til_settings_add_value(settings, desc->key, desc->values[i], NULL);
+ til_settings_add_value(settings, 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->key, buf, NULL);
+ til_settings_add_value(settings, desc->spec.key, buf, NULL);
}
}
_next:
© All Rights Reserved