summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/til_settings.c38
-rw-r--r--src/til_settings.h2
2 files changed, 34 insertions, 6 deletions
diff --git a/src/til_settings.c b/src/til_settings.c
index 4a19788..0e59651 100644
--- a/src/til_settings.c
+++ b/src/til_settings.c
@@ -271,8 +271,8 @@ const char * til_settings_get_label(const til_settings_t *settings)
}
-/* 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)
+/* return setting matching key in settings, NULL if missing, optionally store setting @res_setting if found */
+til_setting_t * til_settings_get_setting_by_key(const til_settings_t *settings, const char *key, til_setting_t **res_setting)
{
assert(settings);
assert(key);
@@ -285,7 +285,7 @@ const char * til_settings_get_value_by_key(const til_settings_t *settings, const
if (res_setting)
*res_setting = settings->entries[i];
- return settings->entries[i]->value;
+ return settings->entries[i];
}
}
@@ -293,8 +293,21 @@ const char * til_settings_get_value_by_key(const til_settings_t *settings, const
}
-/* return positional value from settings, NULL if missing, optionally store setting @res_setting if found */
-const char * til_settings_get_value_by_idx(const til_settings_t *settings, unsigned idx, til_setting_t **res_setting)
+/* return value matching key in settings, 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)
+{
+ til_setting_t *s;
+
+ s = til_settings_get_setting_by_key(settings, key, res_setting);
+ if (!s)
+ return NULL;
+
+ return s->value;
+}
+
+
+/* return positional setting from settings, NULL if missing, optionally store setting @res_setting if found */
+til_setting_t * til_settings_get_setting_by_idx(const til_settings_t *settings, unsigned idx, til_setting_t **res_setting)
{
assert(settings);
@@ -302,13 +315,26 @@ const char * til_settings_get_value_by_idx(const til_settings_t *settings, unsig
if (res_setting)
*res_setting = settings->entries[idx];
- return settings->entries[idx]->value;
+ return settings->entries[idx];
}
return NULL;
}
+/* return positional value from settings, NULL if missing, optionally store setting @res_setting if found */
+const char * til_settings_get_value_by_idx(const til_settings_t *settings, unsigned idx, til_setting_t **res_setting)
+{
+ til_setting_t *s;
+
+ s = til_settings_get_setting_by_idx(settings, idx, res_setting);
+ if (!s)
+ return NULL;
+
+ return s->value;
+}
+
+
/* 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.
diff --git a/src/til_settings.h b/src/til_settings.h
index 0a72931..cbfc599 100644
--- a/src/til_settings.h
+++ b/src/til_settings.h
@@ -52,7 +52,9 @@ unsigned til_settings_get_count(const til_settings_t *settings);
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);
const char * til_settings_get_label(const til_settings_t *settings);
+til_setting_t * til_settings_get_setting_by_key(const til_settings_t *settings, const char *key, til_setting_t **res_setting);
const char * til_settings_get_value_by_key(const til_settings_t *settings, const char *key, til_setting_t **res_setting);
+til_setting_t * til_settings_get_setting_by_idx(const til_settings_t *settings, unsigned idx, til_setting_t **res_setting);
const char * til_settings_get_value_by_idx(const til_settings_t *settings, unsigned idx, til_setting_t **res_setting);
til_setting_t * til_settings_add_value(til_settings_t *settings, const char *key, const char *value);
void til_settings_reset_descs(til_settings_t *settings);
© All Rights Reserved