From 6e20bab8f5fcfbe4fe816425704f9edd8ad88444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Thu, 19 Aug 2021 01:42:49 +0300 Subject: 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. --- src/parcini.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src') 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) { -- cgit v1.2.3