comparison cfgparser.c @ 2621:169d97f8aeaf

fixed subconfig, exiting on error, supporting flags
author alex
date Fri, 02 Nov 2001 02:02:52 +0000
parents b66f42e9ec2d
children 0d8f8d313f9c
comparison
equal deleted inserted replaced
2620:e2f600293621 2621:169d97f8aeaf
60 long tmp_int; 60 long tmp_int;
61 double tmp_float; 61 double tmp_float;
62 int ret = -1; 62 int ret = -1;
63 char *endptr; 63 char *endptr;
64 64
65 // printf("read_option: conf=%p optnr=%d opt='%s' param='%s'\n", 65 #ifdef DEBUG
66 // conf, conf_optnr, opt, param); 66 printf("read_option: conf=%p optnr=%d opt='%s' param='%s'\n",
67 67 conf, conf_optnr, opt, param);
68 #endif
68 for (i = 0; i < conf_optnr; i++) { 69 for (i = 0; i < conf_optnr; i++) {
69 int namelength; 70 int namelength;
70 /* allow 'aa*' in config.name */ 71 /* allow 'aa*' in config.name */
71 namelength=strlen(conf[i].name); 72 namelength=strlen(conf[i].name);
72 if ( (conf[i].name[namelength-1]=='*') && 73 if ( (conf[i].name[namelength-1]=='*') &&
81 if (parser_mode == CONFIG_FILE) 82 if (parser_mode == CONFIG_FILE)
82 printf("invalid option:\n"); 83 printf("invalid option:\n");
83 ret = ERR_NOT_AN_OPTION; 84 ret = ERR_NOT_AN_OPTION;
84 goto out; 85 goto out;
85 } 86 }
86 // printf("read_option: name='%s' p=%p type=%d\n", 87 #ifdef DEBUG
87 // conf[i].name, conf[i].p, conf[i].type); 88 printf("read_option: name='%s' p=%p type=%d\n",
89 conf[i].name, conf[i].p, conf[i].type);
90 #endif
88 if (conf[i].flags & CONF_NOCFG && parser_mode == CONFIG_FILE) { 91 if (conf[i].flags & CONF_NOCFG && parser_mode == CONFIG_FILE) {
89 printf("this option can only be used on command line:\n"); 92 printf("this option can only be used on command line:\n");
90 ret = ERR_NOT_AN_OPTION; 93 ret = ERR_NOT_AN_OPTION;
91 goto out; 94 goto out;
92 } 95 }
258 /* NOTHING */; 261 /* NOTHING */;
259 262
260 token = strtok(param, (char *)&(":")); 263 token = strtok(param, (char *)&(":"));
261 while(token) 264 while(token)
262 { 265 {
263 int i; 266 int ret;
267 int err;
264 268
265 if ((i = sscanf(token, "%[^=]=%s", subopt, subparam)) == 2) 269 ret = sscanf(token, "%[^=]=%s", subopt, subparam);
266 read_option(&conf[i].p, subconf_optnr, subopt, subparam); 270 switch(ret)
271 {
272 case 1:
273 case 2:
274 if ((err = read_option((struct config *)subconf, subconf_optnr, subopt, subparam)) < 0)
275 {
276 printf("Subconfig parsing returned error: %d in token: %s\n",
277 err, token);
278 return(err);
279 }
280 break;
281 default:
282 printf("Invalid subconfig argument! ('%s')\n", token);
283 return(ERR_NOT_AN_OPTION);
284 }
267 // printf("token: '%s', i=%d, subopt='%s, subparam='%s'\n", token, i, subopt, subparam); 285 // printf("token: '%s', i=%d, subopt='%s, subparam='%s'\n", token, i, subopt, subparam);
268 token = strtok(NULL, (char *)&(":")); 286 token = strtok(NULL, (char *)&(":"));
269 } 287 }
270 288
271 free(subparam); 289 free(subparam);
525 case ERR_OUT_OF_RANGE: 543 case ERR_OUT_OF_RANGE:
526 case ERR_FUNC_ERR: 544 case ERR_FUNC_ERR:
527 printf("Error %d while parsing option: '%s'!\n", 545 printf("Error %d while parsing option: '%s'!\n",
528 tmp, opt); 546 tmp, opt);
529 goto err_out; 547 goto err_out;
530 /* break; */
531 default: 548 default:
532 i += tmp; 549 i += tmp;
533 break; 550 break;
534 } 551 }
535 } 552 }