changeset 85:8cea08140a71

Fix comment issue and switch ini_value_dispatch to allow NULL values
author David Demelier <markand@malikania.fr>
date Sat, 19 Nov 2011 20:51:18 +0100
parents 89e4d8d63bfa
children ff1fcb6e385f
files ini.c
diffstat 1 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ini.c	Sat Nov 19 18:49:19 2011 +0100
+++ b/ini.c	Sat Nov 19 20:51:18 2011 +0100
@@ -83,9 +83,9 @@
 	if (I_VERBOSE((file)))						\
 		fprintf(stderr, fmt, __VA_ARGS__)
 
-/* -------------------------------------------------------- */
-/* public functions					    */
-/* -------------------------------------------------------- */
+/* --------------------------------------------------------
+ * public functions
+ * -------------------------------------------------------- */
 
 struct ini_config *
 ini_load(const char *path, int flags)
@@ -302,8 +302,8 @@
 		if (section == NULL)
 			continue;
 
-		if ((value = ini_get_option(section, hdrs[i].option)) != NULL)
-			hdrs[i].handler(hdrs[i].dst, value, hdrs[i].userdata);
+		value = ini_get_option(section, hdrs[i].option);
+		hdrs[i].handler(hdrs[i].dst, value, hdrs[i].userdata);
 	}
 }
 
@@ -312,6 +312,9 @@
 {
 	char *p = dst;
 
+	if (value == NULL)
+		return ;
+
 	if (strcmp(value, "yes") == 0 ||
 	    strcmp(value, "true") == 0 ||
 	    strcmp(value, "1") == 0)
@@ -327,6 +330,9 @@
 {
 	int *p = dst;
 
+	if (value == NULL)
+		return ;
+
 	*p = (int) strtol(value, NULL, 10);
 	(void)dummy;
 }
@@ -336,6 +342,9 @@
 {
 	short *p = dst;
 
+	if (value == NULL)
+		return ;
+
 	*p = (short) strtol(value, NULL, 10);
 	(void)dummy;
 }
@@ -345,7 +354,11 @@
 {
 	char **p = dst;
 
-	*p = strdup(value);
+	if (value == NULL)
+		*p = NULL;
+	else
+		*p = strdup(value);
+
 	(void)dummy;
 }
 
@@ -602,7 +615,8 @@
 	/* Find end of option value */
 	token = *endValue;
 	if (token == '\'' || token == '"') {
-		for (*lp = ++endValue; *endValue != token && *endValue != '\0'; ++endValue)
+		for (*lp = ++endValue; *endValue != token &&
+		    *endValue != '\0'; ++endValue)
 			continue;
 
 		length = endValue - *lp;
@@ -613,7 +627,8 @@
 		else
 			WARN(conf, "line %d: missing '%c'\n", conf->lineno, token);
 	} else {
-		for (*lp = endValue; !isspace(*endValue) && *endValue != '\0'; ++endValue)
+		for (*lp = endValue; !isspace(*endValue) && *endValue != '\0' && 
+		    *endValue != '#' && *endValue != ';'; ++endValue)
 			continue;
 
 		length = endValue - *lp;