diff ini.h @ 82:c8bbdbedcf07

Added a little convenient API for ini
author David Demelier <markand@malikania.fr>
date Wed, 16 Nov 2011 21:28:35 +0100
parents f42bcb9e7b4a
children d27a6fd446ea
line wrap: on
line diff
--- a/ini.h	Wed Nov 16 20:41:36 2011 +0100
+++ b/ini.h	Wed Nov 16 21:28:35 2011 +0100
@@ -26,6 +26,16 @@
 struct ini_config;
 struct ini_section;
 
+struct ini_handler {
+	const char	*section;	/* section to query */
+	const char	*option;	/* option to check */
+	void		*dst;		/* where to store */
+
+	/* Conversion function */
+	void (*handler)(void *, const char *, void *);
+	void		*userdata;	/* optional user data */
+};
+
 /* --------------------------------------------------------
  * struct ini_config functions.
  * -------------------------------------------------------- */
@@ -61,4 +71,48 @@
 char *
 ini_get_option(const struct ini_section *, const char *key);
 
+/* --------------------------------------------------------
+ * convenient api to query and convert data
+ * -------------------------------------------------------- */
+
+/*
+ * For the config, read all available value and store them in
+ * the array ini_handler.
+ */
+
+void
+ini_value_dispatch(struct ini_config *, struct ini_handler *, int);
+
+/*
+ * Convert to bool. dst must be (char *).
+ * It converts "yes" "true" "1" or opposites. Only lower
+ * case is supported right now.
+ */
+
+void
+ini_convert_bool(void *, const char *, void *);
+
+/*
+ * Convert to a int. dst must be (int *).
+ */
+
+void
+ini_convert_int(void *, const char *, void *);
+
+/*
+ * Convert to a short. dst must be (short *).
+ */
+
+void
+ini_convert_short(void *, const char *, void *);
+
+/*
+ * Convert to a char *. dst must be (char **). This
+ * function use strdup() you need to free the dst
+ * pointer.
+ */
+
+void
+ini_convert_string(void *, const char *, void *);
+
 #endif /* _INI_H_ */