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. --- include/parcini.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/parcini.h b/include/parcini.h index 3bcaf59..d485ffd 100644 --- a/include/parcini.h +++ b/include/parcini.h @@ -93,6 +93,21 @@ struct parcini_line { struct parcini_value value; }; +/* + * Helper function to handle a value that was parsed by parcini. Pass a pointer + * of a parcini_value, and the expected type. If the parcini_value typematches + * the expected type, then *dst is set to the provided value casting it to the + * correct type. + * + * IMPORTANT: in the case of "string" values, you need to pass a pointer to a + * char pointer (i.e. char **), and the memory in the string value is copied + * over to the char *. That means, that if some memory was already allocated in + * the passed pointer, there could be a memory leak if you don't free that + * memory before, unless you have another pointer to that same memory elsewhere. + */ +bool parcini_value_handle(const struct parcini_value *, + const enum parcini_value_type expected, void *dst); + /* * Parse the next line in the stream returning the kind of result/error of * parsing and filling the parcini_line structure with the information that was @@ -115,7 +130,7 @@ parcini_t *parcini_init(FILE *stream); /* * Helper function to open a file and then initialize a parcini_t object with - * said as the source stream. + * said as the source stream. Returns NULL if the file couldn't be opened. */ parcini_t *parcini_from_file(const char *fpath); -- cgit v1.2.3