summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-07 19:22:42 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-07 19:22:42 -0400
commita04f42637efa2a1ba380f9d35c1b8b5d573430a5 (patch)
tree3de900461523517f6383c0f8f6ccc7d2168628b7 /config.c
parent7c483e7f9f46d67579980db5e3424d9da702c92d (diff)
Added the `set_config_opt()` function.
This function takes the offset of a given member of a config option in a `config` struct, and sets the member to the value supplied by `val`, with the type of value being determined by `type`.
Diffstat (limited to 'config.c')
-rw-r--r--config.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/config.c b/config.c
index 3a6b54b..859b23c 100644
--- a/config.c
+++ b/config.c
@@ -87,6 +87,16 @@ config_val parse_option_value(const config_opt *opt, char *value) {
return val;
}
+void set_config_opt(config *conf, config_type type, size_t offset, config_val val) {
+ switch (type) {
+ case TYPE_INT : *(int *)(conf+offset) = val.i; break;
+ case TYPE_STRING: *(char **)(conf+offset) = val.str; break;
+ case TYPE_FLOAT : *(float *)(conf+offset) = val.f; break;
+ case TYPE_BOOL : *(int *)(conf+offset) = val.b; break;
+ default : break;
+ }
+}
+
config *parse_config(const char *filename) {
/* Size of the file, in bytes. */
long filesize = 0;
@@ -120,6 +130,7 @@ config *parse_config(const char *filename) {
/* Is the config option valid? */
if (opt->name != NULL) {
config_val val = parse_option_value(opt, value);
+ set_config_opt(cfg, opt->type, opt->offset, val);
}
}
}