summaryrefslogtreecommitdiff
path: root/cfg/cfgparse.c
diff options
context:
space:
mode:
Diffstat (limited to 'cfg/cfgparse.c')
-rw-r--r--cfg/cfgparse.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/cfg/cfgparse.c b/cfg/cfgparse.c
index 4dc6dbb..9ac8ec7 100644
--- a/cfg/cfgparse.c
+++ b/cfg/cfgparse.c
@@ -74,9 +74,18 @@ static void fill_prop_number(
const char* start,
int len
) {
- (void)len;
- p->type = cfg_type_int;
- p->as.num = (int)strtol(start, 0, 10);
+ int is_f = 0;
+ int i;
+ for (i = 0; i < len; i++)
+ if (start[i] == '.')
+ is_f = 1;
+ if (is_f) {
+ p->type = cfg_type_float;
+ p->as.num = (float)strtod(start, 0);
+ } else {
+ p->type = cfg_type_int;
+ p->as.num = (int)strtol(start, 0, 10);
+ }
}
static void fill_prop_data(
@@ -222,6 +231,36 @@ int find_int_default(
return def;
}
+float find_float_default(
+ const cfg_Object* obj,
+ const char* name,
+ float def
+) {
+ const cfg_Prop* prop;
+ prop = find_prop_of(obj, name, cfg_type_float);
+ if (prop) {
+ return prop->as.flt;
+ }
+ return def;
+}
+
+float find_num_default(
+ const cfg_Object* obj,
+ const char* name,
+ float def
+) {
+ const cfg_Prop* prop;
+ prop = find_prop_of(obj, name, cfg_type_float);
+ if (prop) {
+ return prop->as.flt;
+ }
+ prop = find_prop_of(obj, name, cfg_type_int);
+ if (prop) {
+ return prop->as.num;
+ }
+ return def;
+}
+
const char* find_string_default(
const cfg_Object* obj,
const char* name,
@@ -234,3 +273,12 @@ const char* find_string_default(
}
return def;
}
+
+unsigned find_colour_default(
+ const cfg_Object* obj,
+ const char* name,
+ const char* def
+) {
+ const char* s = find_string_default(obj, name, def);
+ return (unsigned)strtol(s, 0, 16);
+}