summaryrefslogtreecommitdiff
path: root/src/til_settings.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-05-26 18:11:58 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-26 18:11:58 -0700
commit1a89d30e76d2bdb8268c17073d8a780b5adf3049 (patch)
treed567bfdf09c97bd05dc2e65df4f476ba438577a7 /src/til_settings.h
parentb9123bbb0b09cb0b30dd0a08f48caecfbb15f9c2 (diff)
til_settings: add til_setting_spec_t.as_label
Currently settings instances get labels from three sources: 1. explicitly labeled by a root-level til_settings_new() call, like main.c::til_settings_new(NULL, "video", args->video); 2. implicitly labeled in a spec.as_nested_settings w/spec.key 3. positionally labeled in a spec.as_nested_settings w/o spec.key But when constructing setting/desc paths, using strictly these settings instance labels as the "directory name path component" equivalent, leaves something to be desired. Take this hypothetical module setting path for example: /module/layers/[0]/viscosity Strictly using settings instance labels as-is, the above is what you'd get for the drizzle::viscosity setting in something like: --module=compose,layers=drizzle Which is really awkward. What's really desired is more like: /module/compose/layers/[0]/drizzle/viscosity Now one way to achieve that is to just create more settings instances to hold these module names as labels and things would Just Work more or less. But that would be rather annoying and heavyweight, when what's _really_ wanted is a way to turn the first entry's value of a given setting instance into a sort of synthetic directory component in the path. So that's what this commit does. When a spec has .as_label specified, it's saying that path construction should treat this setting's value as if it were a label on a settings instance. But it's special cased to only apply to descs hanging off the first entry of a settings instance, as that's the only scenario we're making use of, and it avoids having to do crazy things like search all the entries for specs w/.as_label set. It feels a bit janky but it does achieve what's needed with little pain/churn.
Diffstat (limited to 'src/til_settings.h')
-rw-r--r--src/til_settings.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/til_settings.h b/src/til_settings.h
index e86f06e..2e2afe9 100644
--- a/src/til_settings.h
+++ b/src/til_settings.h
@@ -17,6 +17,7 @@ typedef struct til_setting_spec_t {
const char **annotations; /* if a set of values is provided, annotations for those values may be listed here */
char * (*random)(unsigned seed);/* if set, returns a valid random value for this setting */
unsigned as_nested_settings:1; /* if set, this setting expects a settings string for its value and wants a til_setting_t.value_as_nested_settings instance created for it */
+ unsigned as_label:1; /* if set, this setting's value is to be used as a label component in path construction - only applies to the first setting entry in an instance (til_settings_t.entries[0]) */
} til_setting_spec_t;
/* a setting_desc is a setting_spec that's been described to a specific containing settings instance via desc_new(), though desc_new() takes a const settings it's cast away when placed into the allocated desc. */
© All Rights Reserved