summaryrefslogtreecommitdiff
path: root/pom.c
diff options
context:
space:
mode:
Diffstat (limited to 'pom.c')
-rw-r--r--pom.c112
1 files changed, 42 insertions, 70 deletions
diff --git a/pom.c b/pom.c
index 451d7b7..792c039 100644
--- a/pom.c
+++ b/pom.c
@@ -1,8 +1,3 @@
-/*
-TODO:
-- clean up read_conf.c example
-- interpretation tests
-*/
#include "pom.h"
#include <stdio.h> // still needed for sprintf, even if POM_NO_STDIO is defined.
@@ -1743,108 +1738,85 @@ parse_bool(const char *s, bool *val) {
return false;
}
-const char *
+
+pom_error *
pom_conf_get_uint(const pom_conf *conf, const char *key, uint64_t *value_uint) {
- check_conf(conf);
- if (!key) fatal_error("NULL key passed to %s", __func__);
- if (!value_uint) fatal_error("NULL value passed to %s", __func__);
*value_uint = 0;
- const char *value_str = pom_conf_get(conf, key);
- if (!value_str)
- return "";
- if (parse_uint(value_str, value_uint))
+ struct conf_item *item = conf_get_item(conf, key);
+ if (!item)
+ return make_error(&conf->main->settings, "", 0, ERROR_KEY_NOT_FOUND, key);
+ if (parse_uint(item->value, value_uint))
return NULL;
- return value_str;
+ return make_error(&conf->main->settings, item->file, item->line, ERROR_INVALID_UINT, item->value, item->key);
}
-const char *
+pom_error *
pom_conf_get_uint_or_default(const pom_conf *conf, const char *key, uint64_t *value_uint, uint64_t dflt) {
- check_conf(conf);
- if (!key) fatal_error("NULL key passed to %s", __func__);
- if (!value_uint) fatal_error("NULL value passed to %s", __func__);
*value_uint = dflt;
- const char *value_str = pom_conf_get(conf, key);
- if (!value_str || parse_uint(value_str, value_uint))
+ struct conf_item *item = conf_get_item(conf, key);
+ if (!item || parse_uint(item->value, value_uint))
return NULL;
- return value_str;
+ return make_error(&conf->main->settings, item->file, item->line, ERROR_INVALID_UINT, item->value, item->key);
}
-const char *
+pom_error *
pom_conf_get_int(const pom_conf *conf, const char *key, int64_t *value_int) {
- check_conf(conf);
- if (!key) fatal_error("NULL key passed to %s", __func__);
- if (!value_int) fatal_error("NULL value passed to %s", __func__);
*value_int = 0;
- const char *value_str = pom_conf_get(conf, key);
- if (!value_str)
- return "";
- if (parse_int(value_str, value_int))
+ struct conf_item *item = conf_get_item(conf, key);
+ if (!item)
+ return make_error(&conf->main->settings, "", 0, ERROR_KEY_NOT_FOUND, key);
+ if (parse_int(item->value, value_int))
return NULL;
- return value_str;
+ return make_error(&conf->main->settings, item->file, item->line, ERROR_INVALID_INT, item->value, item->key);
}
-const char *
+pom_error *
pom_conf_get_int_or_default(const pom_conf *conf, const char *key, int64_t *value_int, int64_t dflt) {
- check_conf(conf);
- if (!key) fatal_error("NULL key passed to %s", __func__);
- if (!value_int) fatal_error("NULL value passed to %s", __func__);
*value_int = dflt;
- const char *value_str = pom_conf_get(conf, key);
- if (!value_str || parse_int(value_str, value_int))
+ struct conf_item *item = conf_get_item(conf, key);
+ if (!item || parse_int(item->value, value_int))
return NULL;
- return value_str;
+ return make_error(&conf->main->settings, item->file, item->line, ERROR_INVALID_INT, item->value, item->key);
}
-const char *
+pom_error *
pom_conf_get_float(const pom_conf *conf, const char *key, double *value_double) {
- check_conf(conf);
- if (!key) fatal_error("NULL key passed to %s", __func__);
- if (!value_double) fatal_error("NULL value passed to %s", __func__);
- *value_double = 0;
- const char *value_str = pom_conf_get(conf, key);
- if (!value_str)
- return "";
- if (parse_double(value_str, value_double))
+ *value_double = 0.0;
+ struct conf_item *item = conf_get_item(conf, key);
+ if (!item)
+ return make_error(&conf->main->settings, "", 0, ERROR_KEY_NOT_FOUND, key);
+ if (parse_double(item->value, value_double))
return NULL;
- return value_str;
+ return make_error(&conf->main->settings, item->file, item->line, ERROR_INVALID_FLOAT, item->value, item->key);
}
-const char *
+pom_error *
pom_conf_get_float_or_default(const pom_conf *conf, const char *key, double *value_double, double dflt) {
- check_conf(conf);
- if (!key) fatal_error("NULL key passed to %s", __func__);
- if (!value_double) fatal_error("NULL value passed to %s", __func__);
*value_double = dflt;
- const char *value_str = pom_conf_get(conf, key);
- if (!value_str || parse_double(value_str, value_double))
+ struct conf_item *item = conf_get_item(conf, key);
+ if (!item || parse_double(item->value, value_double))
return NULL;
- return value_str;
+ return make_error(&conf->main->settings, item->file, item->line, ERROR_INVALID_FLOAT, item->value, item->key);
}
-const char *
+pom_error *
pom_conf_get_bool(const pom_conf *conf, const char *key, bool *value_bool) {
- check_conf(conf);
- if (!key) fatal_error("NULL key passed to %s", __func__);
- if (!value_bool) fatal_error("NULL value passed to %s", __func__);
*value_bool = false;
- const char *value_str = pom_conf_get(conf, key);
- if (!value_str)
- return "";
- if (parse_bool(value_str, value_bool))
+ struct conf_item *item = conf_get_item(conf, key);
+ if (!item)
+ return make_error(&conf->main->settings, "", 0, ERROR_KEY_NOT_FOUND, key);
+ if (parse_bool(item->value, value_bool))
return NULL;
- return value_str;
+ return make_error(&conf->main->settings, item->file, item->line, ERROR_INVALID_BOOL, item->value, item->key);
}
-const char *
+pom_error *
pom_conf_get_bool_or_default(const pom_conf *conf, const char *key, bool *value_bool, bool dflt) {
- check_conf(conf);
- if (!key) fatal_error("NULL key passed to %s", __func__);
- if (!value_bool) fatal_error("NULL value passed to %s", __func__);
*value_bool = dflt;
- const char *value_str = pom_conf_get(conf, key);
- if (!value_str || parse_bool(value_str, value_bool))
+ struct conf_item *item = conf_get_item(conf, key);
+ if (!item || parse_bool(item->value, value_bool))
return NULL;
- return value_str;
+ return make_error(&conf->main->settings, item->file, item->line, ERROR_INVALID_BOOL, item->value, item->key);
}
char **