summaryrefslogtreecommitdiff
path: root/src/til_settings.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-30 19:53:04 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-30 19:55:27 -0700
commit5bbf4dff64f2b559540f47a9d8de99353004dce4 (patch)
tree4327e24aec0d9ec3437de42d4b057d683aa6dedb /src/til_settings.c
parent9400a8491265b984c14469e1d711f3737748637d (diff)
til_settings: add til_setting_t variant for get_and_describe
This is kinda icky copy-pasta vs. the previous commit. But this function is just an inherently crufty helper, hopefully the value-centric variant can be removed at some point.
Diffstat (limited to 'src/til_settings.c')
-rw-r--r--src/til_settings.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/til_settings.c b/src/til_settings.c
index 0e59651..fb21af7 100644
--- a/src/til_settings.c
+++ b/src/til_settings.c
@@ -338,6 +338,47 @@ const char * til_settings_get_value_by_idx(const til_settings_t *settings, unsig
/* helper for the common setup case of describing a setting when absent or not yet described.
* returns:
* -1 on error, res_* will be untouched in this case.
+ * 0 when setting is present and described, res_setting and res_setting_bis(optional) will be populated w/non-NULL, and res_desc NULL in this case.
+ * 1 when setting is either present but undescribed, or absent (and undescribed), res_* will be populated but res_setting{,_bis} may be NULL if absent and simply described.
+ */
+int til_settings_get_and_describe_setting(const til_settings_t *settings, const til_setting_spec_t *spec, til_setting_t **res_setting, til_setting_t **res_setting_bis, const til_setting_desc_t **res_desc)
+{
+ til_setting_t *setting;
+
+ assert(settings);
+ assert(spec);
+ assert(res_setting);
+
+ setting = til_settings_get_setting_by_key(settings, spec->key, NULL);
+ if (!setting || !setting->desc) {
+ int r;
+
+ assert(res_desc);
+
+ r = til_setting_desc_new(settings, spec, res_desc);
+ if (r < 0)
+ return r;
+
+ *res_setting = setting;
+ if (res_setting_bis)
+ *res_setting_bis = setting;
+
+ return 1;
+ }
+
+ *res_setting = setting;
+ if (res_setting_bis)
+ *res_setting_bis = setting;
+ if (res_desc)
+ *res_desc = NULL;
+
+ return 0;
+}
+
+
+/* helper for the common setup case of describing a setting when absent or not yet described.
+ * returns:
+ * -1 on error, res_* will be untouched in this case.
* 0 when setting is present and described, res_value and res_setting will be populated w/non-NULL, and res_desc NULL in this case.
* 1 when setting is either present but undescribed, or absent (and undescribed), res_* will be populated but res_{value,setting} may be NULL if absent and simply described.
*/
© All Rights Reserved