From 69656a0b0716dbbd88a4881246d3c73990b7df29 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 29 Mar 2002 11:06:19 +0000 Subject: [PATCH] Added CT_INCOMPLETE_SECTION which is equivalent to CT_SECTION except that unknown variables in such sections are not reported as errors. --- lib/conf.c | 9 ++++++--- lib/conf.h | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/conf.c b/lib/conf.c index 98c34b56..c37bb98b 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -49,8 +49,8 @@ cfg_stralloc(byte *s) void cf_register(struct cfitem *items) { - if(items[0].type!=CT_SECTION) - die("Invalid configuration section, first item must be of type CT_SECTION"); + if(items[0].type!=CT_SECTION && items[0].type!=CT_INCOMPLETE_SECTION) + die("cf_register: Invalid section type"); items[0].var=cfsection; cfsection=items; } @@ -67,15 +67,18 @@ int cf_item_count(void) struct cfitem *cf_get_item(byte *sect, byte *name) { - struct cfitem *item; + struct cfitem *item, *section; item=cfsection; while(item && strcasecmp(item->name,sect)) item=item->var; if(!item) /* unknown section */ return NULL; + section = item; for(item++; item->type && strcasecmp(item->name,name); item++); + if (!item->type && section->type == CT_INCOMPLETE_SECTION) + return NULL; return item; /* item->type == 0 if not found */ } diff --git a/lib/conf.h b/lib/conf.h index b225053c..b58224d3 100644 --- a/lib/conf.h +++ b/lib/conf.h @@ -22,11 +22,14 @@ byte *cfg_stralloc(byte *s); * the name of the section. The configuration sections are registered by * calling cf_register(). * + * CT_INCOMPLETE_SECTION is identical to CT_SECTION, but when an unknown variable + * is spotted, we ignore it instead of bailing out with an error message. + * * item->var is a pointer to the destination variable or to the special parsing * function. */ -enum cftype { CT_STOP, CT_SECTION, CT_INT, CT_STRING, CT_FUNCTION }; +enum cftype { CT_STOP, CT_SECTION, CT_INCOMPLETE_SECTION, CT_INT, CT_STRING, CT_FUNCTION }; struct cfitem { byte *name; -- 2.39.2