summaryrefslogtreecommitdiff
path: root/src/setup.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-05-08 00:11:09 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-11 15:18:02 -0700
commit1a8abe80dabd6b723897fc507808db30b126b3a4 (patch)
treed60a084d6b6b44b9fffe76864e00ed6d7176f2ad /src/setup.c
parenta409d9fd5d861d52dca0e4ed33416a49b00ae2d9 (diff)
til_settings: rework setting get/add for bare values
The core thing here is rather than turning a bare value into a key as I was doing before - we just leave the bare value as a bare value and its setting must be located positionally via get_value_by_idx since there's no key. Existing callers that used to get_key() positionally now get_value_by_idx() positionally all the same, except it's the value instead of the key. This is mostly done for things like the module or fb name at the front of a settings instance. The impetus for this change is partially just cosmetic/ergonomics, but it's also rather strange for what's really a key-less value to be treated as a value-less key. It was also awkward to talk/reason about on the road to recursive settings where bare values would be supported as a standalone settings instance if properly escaped... This also adds unescaping of keys, and adds a dependency on the somewhat linux-specific open_memstream() which may need changing in the future (see comments).
Diffstat (limited to 'src/setup.c')
-rw-r--r--src/setup.c21
1 files changed, 3 insertions, 18 deletions
diff --git a/src/setup.c b/src/setup.c
index f85ac10..7c13ea0 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -6,21 +6,6 @@
#include "til_setup.h"
#include "til_util.h"
-/* add key=value, but if key is NULL, use value as key. */
-static int add_value(til_settings_t *settings, const char *key, const char *value)
-{
- assert(settings);
-
- if (!key) {
- key = value;
- value = NULL;
- }
-
- assert(key);
-
- return til_settings_add_value(settings, key, value, NULL);
-}
-
/* returns negative on error, otherwise number of additions made to settings */
int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup), int defaults, til_setup_t **res_setup, const til_setting_desc_t **res_failed_desc)
@@ -115,7 +100,7 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se
if (*buf == '\n') {
/* accept preferred */
- add_value(settings, desc->key, desc->preferred);
+ til_settings_add_value(settings, desc->key, desc->preferred, NULL);
} else {
buf[strlen(buf) - 1] = '\0';
@@ -131,7 +116,7 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se
for (found = i = 0; desc->values[i]; i++) {
if (i == j) {
- add_value(settings, desc->key, desc->values[i]);
+ til_settings_add_value(settings, desc->key, desc->values[i], NULL);
found = 1;
break;
}
@@ -146,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 */
- add_value(settings, desc->key, buf);
+ til_settings_add_value(settings, desc->key, buf, NULL);
}
}
_next:
© All Rights Reserved