diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-08-19 01:42:49 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-08-19 01:42:49 +0300 |
commit | 6e20bab8f5fcfbe4fe816425704f9edd8ad88444 (patch) | |
tree | 5f11825e1afc4dbc75ed9778afcdd9e12cddcb05 /src | |
parent | 5ed7b33fa8ce0c91af1a58bc17636d6bf0406d24 (diff) | |
download | parcini-6e20bab8f5fcfbe4fe816425704f9edd8ad88444.tar.gz parcini-6e20bab8f5fcfbe4fe816425704f9edd8ad88444.zip |
Example and new helper funcion
* Added an example program an ini file to example/
* Added a new helper function `parcini_value_handle` to handle and copy
parsed values, depending on the expected value type.
Diffstat (limited to 'src')
-rw-r--r-- | src/parcini.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/parcini.c b/src/parcini.c index 6c19d7a..83b5de4 100644 --- a/src/parcini.c +++ b/src/parcini.c @@ -74,6 +74,33 @@ slicecpy(char *start, char *end, char **dst, size_t *dstn) return *dst; } +bool +parcini_value_handle(const struct parcini_value *value, + const enum parcini_value_type expected, void *dst) +{ + + if (value->type != expected) { + return false; + } + if(expected == PARCINI_VALUE_STRING) { + char **string = (char **)dst; + *string = strdup(value->value.string); + return true; + } + if(expected == PARCINI_VALUE_INTEGER) { + long int *integer = (long int *)dst; + *integer = value->value.integer; + return true; + } + if(expected == PARCINI_VALUE_BOOLEAN) { + bool *boolean = (bool *)dst; + *boolean = value->value.boolean; + return true; + } + + return false; +} + enum parcini_result parcini_parse_next_line(parcini_t *parser, struct parcini_line *parsed) { |