summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-05-24 23:16:58 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-24 23:16:58 -0700
commit3c64aca2f08387437ce886c09534061fb0b180b1 (patch)
treec38499fc0b74904b41321a05fbc51ac4e4e7a992
parent51f3b575ee50b3c1ecf04e86ab0c30a08b499d86 (diff)
til_settings: til_setting_t,til_settings_t get parent pointers
Preparatory for constructing unique paths from a given setting/settings instance by walking up the tree
-rw-r--r--src/main.c4
-rw-r--r--src/setup.c2
-rw-r--r--src/til.c17
-rw-r--r--src/til_settings.c18
-rw-r--r--src/til_settings.h3
5 files changed, 31 insertions, 13 deletions
diff --git a/src/main.c b/src/main.c
index f99c74e..f291221 100644
--- a/src/main.c
+++ b/src/main.c
@@ -220,11 +220,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("module", args->module);
+ setup.module_settings = til_settings_new(NULL, "module", args->module);
if (!setup.module_settings)
goto _err;
- setup.video_settings = til_settings_new("video", args->video);
+ setup.video_settings = til_settings_new(NULL, "video", args->video);
if (!setup.video_settings)
goto _err;
diff --git a/src/setup.c b/src/setup.c
index aeea763..dd626a2 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -46,7 +46,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->spec.key ? : label, setting->value);
+ setting->value_as_nested_settings = til_settings_new(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 c00cf93..38daac8 100644
--- a/src/til.c
+++ b/src/til.c
@@ -330,7 +330,20 @@ int til_module_randomize_setup(const til_module_t *module, unsigned seed, til_se
if (!module->setup)
return 0;
- settings = til_settings_new(module->name, NULL);
+ /* FIXME TODO:
+ * This seems wrong for two reasons:
+ * 1. There's no parent settings to attach this to, and there really shouldn't be such
+ * orphaned settings instances as we're supposed ot be able to influence their values
+ * externally via settings. At the very least this seems like it should be part of a
+ * heirarchy somewhere... which leads to #2
+ *
+ * 2. Not only does lacking a parent suggest a problem, but there should be an incoming
+ * settings instance to randomize which may contain some values already set which we
+ * would skip randomizing. The settings don't currently have any kind of attributes or
+ * 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);
if (!settings)
return -ENOMEM;
@@ -367,7 +380,7 @@ int til_module_randomize_setup(const til_module_t *module, unsigned seed, til_se
return r;
}
- setting->value_as_nested_settings = til_settings_new(desc->spec.key ? : label, setting->value);
+ setting->value_as_nested_settings = til_settings_new(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 2c3d3be..7bd39c3 100644
--- a/src/til_settings.c
+++ b/src/til_settings.c
@@ -31,9 +31,10 @@ char * strndup(const char *s, size_t n)
/* Split form of key=value[,key=value...] settings string */
typedef struct til_settings_t {
- const char *label;
- unsigned num;
- til_setting_t **entries;
+ const til_settings_t *parent;
+ const char *label;
+ unsigned num;
+ til_setting_t **entries;
} til_settings_t;
typedef enum til_settings_fsm_state_t {
@@ -57,6 +58,11 @@ static til_setting_t * add_setting(til_settings_t *settings, const char *key, co
if (!s)
return NULL;
+ s->parent = settings;
+ s->key = key;
+ s->value = value;
+ s->desc = desc;
+
new_entries = realloc(settings->entries, (settings->num + 1) * sizeof(til_setting_t *));
if (!new_entries) {
free(s);
@@ -65,9 +71,6 @@ static til_setting_t * add_setting(til_settings_t *settings, const char *key, co
settings->entries = new_entries;
settings->entries[settings->num] = s;
- settings->entries[settings->num]->key = key;
- settings->entries[settings->num]->value = value;
- settings->entries[settings->num]->desc = desc;
settings->num++;
return s;
@@ -75,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 char *label, const char *settings_string)
+til_settings_t * til_settings_new(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;
@@ -90,6 +93,7 @@ til_settings_t * til_settings_new(const char *label, const char *settings_string
if (!settings)
goto _err;
+ settings->parent = parent;
settings->label = strdup(label);
if (!settings->label)
goto _err;
diff --git a/src/til_settings.h b/src/til_settings.h
index c3abcb5..e86f06e 100644
--- a/src/til_settings.h
+++ b/src/til_settings.h
@@ -34,6 +34,7 @@ typedef struct til_setting_desc_generator_t {
/* Encapsulates a single til_settings_t.entries[] entry */
struct til_setting_t {
+ til_settings_t *parent;
til_settings_t *value_as_nested_settings; /* XXX: non-NULL when setup turned this setting's value into a nested settings instance */
const char *key;
const char *value;
@@ -41,7 +42,7 @@ struct til_setting_t {
void *user_data;
};
-til_settings_t * til_settings_new(const char *label, const char *settings);
+til_settings_t * til_settings_new(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