summaryrefslogtreecommitdiff
path: root/src/til_settings.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-06-03 14:33:31 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-06-03 14:33:31 -0700
commit2c58bc3a9821faa454dcd270815f9e001f825b6a (patch)
tree67d8e3a0bf0783895cc36bfcebb05cbcb70a64df /src/til_settings.c
parentb533125a1c4a951b941bf6983e0b4d6973718758 (diff)
til_settings: add an optional til_settings_t.prefix
Preparatory commit for bridging the gap separating a baked til_setup_t from a runtime-populated descendant til_settings_t like modules::rtv produces for its channels via til_module_setup_randomize(). For these currently orphaned til_settings_t instances we don't readily have access to the logical ancestor til_settings_t that was used to produce the module_context's bound til_setup_t. But we don't really need the ancestor til_settings_t, all we _really_ want is the ancestral path to prefix the orphan til_settings_t instances. So this commit introduces supplying a prefix which gets prepended to paths printed via the settings instance. A later commit will make use of this in modules::rtv when producing the settings instance passed to til_module_setup_randomize()
Diffstat (limited to 'src/til_settings.c')
-rw-r--r--src/til_settings.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/til_settings.c b/src/til_settings.c
index b6f277c..9fe57e6 100644
--- a/src/til_settings.c
+++ b/src/til_settings.c
@@ -32,6 +32,7 @@ char * strndup(const char *s, size_t n)
/* Split form of key=value[,key=value...] settings string */
typedef struct til_settings_t {
const til_settings_t *parent;
+ const char *prefix;
const char *label;
unsigned num;
til_setting_t **entries;
@@ -77,7 +78,7 @@ static til_setting_t * add_setting(til_settings_t *settings, const char *key, co
/* split settings_string into a data structure */
-til_settings_t * til_settings_new(const til_settings_t *parent, const char *label, const char *settings_string)
+til_settings_t * til_settings_new(const char *prefix, const til_settings_t *parent, const char *label, const char *settings_string)
{
til_settings_fsm_state_t state = TIL_SETTINGS_FSM_STATE_COMMA;
const char *p;
@@ -92,6 +93,12 @@ til_settings_t * til_settings_new(const til_settings_t *parent, const char *labe
if (!settings)
goto _err;
+ if (prefix) {
+ settings->prefix = strdup(prefix);
+ if (!settings->prefix)
+ goto _err;
+ }
+
settings->parent = parent;
settings->label = strdup(label);
if (!settings->label)
@@ -199,6 +206,7 @@ til_settings_t * til_settings_free(til_settings_t *settings)
free((void *)settings->entries);
free((void *)settings->label);
+ free((void *)settings->prefix);
free(settings);
}
@@ -636,6 +644,12 @@ int til_settings_print_path(const til_settings_t *settings, FILE *out)
for (i = 0; i < n_parents; i++) {
int r;
+ if (parents[i]->prefix) {
+ r = fprintf(out, "%s", parents[i]->prefix);
+ if (r < 0)
+ return r;
+ }
+
r = fprintf(out, "/%s", parents[i]->label);
if (r < 0)
return r;
© All Rights Reserved