diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-06 13:29:50 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-06 13:29:50 -0400 |
commit | a27bd3293a00e2a00fedfda5bffedb03a87f591b (patch) | |
tree | 976f93f6e31d12fb985dcc0ce720b4dc319a8b2d /config.c | |
parent | 39a9e3942cef811f52993c702f1f69b1d28fc7cd (diff) |
Added the config option value parser.
This function, called `parse_option_value()`, parses
the supplied `value` string, and based on the value
type supplied by `opt`, sets a given member of `val`
for that value type.
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -73,6 +73,20 @@ char *get_line(char **str) { return s; } +config_val parse_option_value(const config_opt *opt, char *value) { + config_val val = {0}; + + switch (opt->type) { + case TYPE_INT : (long)val.i = strtol(value, NULL, 0); break; + case TYPE_STRING: val.str = value; break; + case TYPE_FLOAT : val.f = strtof(value, NULL); break; + case TYPE_BOOL : (long)val.b = strtol(value, NULL, 0); break; + default : break; + } + + return val; +} + config *parse_config(const char *filename) { /* Size of the file, in bytes. */ long filesize = 0; |