changeset 2621:169d97f8aeaf

fixed subconfig, exiting on error, supporting flags
author alex
date Fri, 02 Nov 2001 02:02:52 +0000
parents e2f600293621
children fb7220c79b69
files cfgparser.c
diffstat 1 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/cfgparser.c	Fri Nov 02 01:35:27 2001 +0000
+++ b/cfgparser.c	Fri Nov 02 02:02:52 2001 +0000
@@ -62,9 +62,10 @@
 	int ret = -1;
 	char *endptr;
 
-//	printf("read_option: conf=%p optnr=%d opt='%s' param='%s'\n",
-//	    conf, conf_optnr, opt, param);
-
+#ifdef DEBUG
+	printf("read_option: conf=%p optnr=%d opt='%s' param='%s'\n",
+	    conf, conf_optnr, opt, param);
+#endif
 	for (i = 0; i < conf_optnr; i++) {
 		int namelength;
 		/* allow 'aa*' in config.name */
@@ -83,8 +84,10 @@
 		ret = ERR_NOT_AN_OPTION;
 		goto out;
 	}
-//	printf("read_option: name='%s' p=%p type=%d\n",
-//	    conf[i].name, conf[i].p, conf[i].type);
+#ifdef DEBUG
+	printf("read_option: name='%s' p=%p type=%d\n",
+	    conf[i].name, conf[i].p, conf[i].type);
+#endif
 	if (conf[i].flags & CONF_NOCFG && parser_mode == CONFIG_FILE) {
 		printf("this option can only be used on command line:\n");
 		ret = ERR_NOT_AN_OPTION;
@@ -260,10 +263,25 @@
 			token = strtok(param, (char *)&(":"));
 			while(token)
 			{
-			    int i;
+			    int ret;
+			    int err;
 			    
-			    if ((i = sscanf(token, "%[^=]=%s", subopt, subparam)) == 2)
-				read_option(&conf[i].p, subconf_optnr, subopt, subparam);
+			    ret = sscanf(token, "%[^=]=%s", subopt, subparam);
+			    switch(ret)
+			    {
+				case 1:
+				case 2:
+				    if ((err = read_option((struct config *)subconf, subconf_optnr, subopt, subparam)) < 0)
+				    {
+					printf("Subconfig parsing returned error: %d in token: %s\n",
+					    err, token);
+					return(err);
+				    }
+				    break;
+				default:
+				    printf("Invalid subconfig argument! ('%s')\n", token);
+				    return(ERR_NOT_AN_OPTION);
+			    }
 //			    printf("token: '%s', i=%d, subopt='%s, subparam='%s'\n", token, i, subopt, subparam);
 			    token = strtok(NULL, (char *)&(":"));
 			}
@@ -527,7 +545,6 @@
 			printf("Error %d while parsing option: '%s'!\n",
 			    tmp, opt);
 			goto err_out;
-			/* break; */
 		    default:
 			i += tmp;
 			break;