From fde7b0b847aeb4f0c62abcc4bc7206ac858902eb Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 2 Jul 2023 16:00:38 -0700 Subject: til_settings: add way to change the settings label In rkt_scener it's desirable to fully construct a new settings instance *before* wiring it into the parent rkt/scenes settings. But the way these positional settings labels get constructed depends on the parent's settings entries. So it becomes a chicken-egg problem to require the proper label @ creation before its containing setting is even added in the parent's entries. With this change a temporary WIP label can be used while constructing the settings instance, then amend it once we know the settings instance is complete and ready to join the party. --- src/til_settings.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/til_settings.c') diff --git a/src/til_settings.c b/src/til_settings.c index cdb5cd7..c546360 100644 --- a/src/til_settings.c +++ b/src/til_settings.c @@ -227,6 +227,24 @@ const til_settings_t * til_settings_get_parent(const til_settings_t *settings) } +int til_settings_set_label(til_settings_t *settings, const char *label) +{ + char *t; + + assert(settings); + assert(label); + + t = strdup(label); + if (!t) + return -ENOMEM; + + free((void *)settings->label); + settings->label = t; + + return 0; +} + + /* find key= in settings, return value NULL if missing, optionally store setting @res_setting if found */ const char * til_settings_get_value_by_key(const til_settings_t *settings, const char *key, til_setting_t **res_setting) { -- cgit v1.2.1