summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.c4
-rw-r--r--src/setup.c2
-rw-r--r--src/til.c4
-rw-r--r--src/til_settings.c16
-rw-r--r--src/til_settings.h2
5 files changed, 21 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 25ae4cd..240dab1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -221,11 +221,11 @@ static int setup_from_args(til_args_t *args, setup_t *res_setup, const til_setti
*/
srand(setup.seed);
- setup.module_settings = til_settings_new(NULL, "module", args->module);
+ setup.module_settings = til_settings_new(NULL, NULL, "module", args->module);
if (!setup.module_settings)
goto _err;
- setup.video_settings = til_settings_new(NULL, "video", args->video);
+ setup.video_settings = til_settings_new(NULL, NULL, "video", args->video);
if (!setup.video_settings)
goto _err;
diff --git a/src/setup.c b/src/setup.c
index fe5803a..f2b50e3 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -63,7 +63,7 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se
return r;
}
- setting->value_as_nested_settings = til_settings_new(desc->container, desc->spec.key ? : label, setting->value);
+ setting->value_as_nested_settings = til_settings_new(NULL, desc->container, desc->spec.key ? : label, setting->value);
free(label);
if (!setting->value_as_nested_settings) {
diff --git a/src/til.c b/src/til.c
index b9ccde0..6054014 100644
--- a/src/til.c
+++ b/src/til.c
@@ -374,7 +374,7 @@ int til_module_setup_randomize(const til_module_t *module, unsigned seed, til_se
* other state to indicate which ones should always be randomized vs. ones which were
* explicitly specified to stay fixed.
*/
- settings = til_settings_new(NULL, module->name, NULL);
+ settings = til_settings_new(NULL, NULL, module->name, NULL);
if (!settings)
return -ENOMEM;
@@ -442,7 +442,7 @@ int til_module_setup_randomize(const til_module_t *module, unsigned seed, til_se
break;
}
- setting->value_as_nested_settings = til_settings_new(desc->container, desc->spec.key ? : label, setting->value);
+ setting->value_as_nested_settings = til_settings_new(NULL, desc->container, desc->spec.key ? : label, setting->value);
free(label);
if (!setting->value_as_nested_settings) {
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;
diff --git a/src/til_settings.h b/src/til_settings.h
index e2653e4..6ff791c 100644
--- a/src/til_settings.h
+++ b/src/til_settings.h
@@ -44,7 +44,7 @@ struct til_setting_t {
void *user_data;
};
-til_settings_t * til_settings_new(const til_settings_t *parent, const char *label, const char *settings);
+til_settings_t * til_settings_new(const char *prefix, const til_settings_t *parent, const char *label, const char *settings);
til_settings_t * til_settings_free(til_settings_t *settings);
unsigned til_settings_get_count(const til_settings_t *settings);
const char * til_settings_get_value_by_key(const til_settings_t *settings, const char *key, til_setting_t **res_setting);
© All Rights Reserved