static struct cfitem *cfsection;
static struct mempool *cfpool;
+byte *cfdeffile = DEFAULT_CONFIG;
+
static void CONSTRUCTOR
conf_init(void)
{
cfsection=items;
}
-byte *cf_set_item(byte *sect, byte *name, byte *value)
+int cf_item_count(void)
+{
+ struct cfitem *sect, *item;
+ int count = 0;
+ for (sect = cfsection; sect; sect = sect->var)
+ for (item = sect+1; sect->type; sect++)
+ count++;
+ return count;
+}
+
+struct cfitem *cf_get_item(byte *sect, byte *name)
{
struct cfitem *item;
- byte *msg=NULL;
item=cfsection;
while(item && strcasecmp(item->name,sect))
item=item->var;
- if(!item) /* ignore unknown section */
+ if(!item) /* unknown section */
return NULL;
for(item++; item->type && strcasecmp(item->name,name); item++);
+ return item; /* item->type == 0 if not found */
+}
+
+byte *cf_set_item(byte *sect, byte *name, byte *value)
+{
+ struct cfitem *item;
+ byte *msg=NULL;
+
+ item=cf_get_item(sect,name);
+ if(!item) /* ignore unknown section */
+ return NULL;
+
switch(item->type){
case CT_INT:
{
{
if(!cf_subread(filename,0))
die("Reading config file %s failed",filename);
+ cfdeffile = NULL;
}
int cf_getopt(int argc,char * const argv[],
name=c;
}
+ if (cfdeffile)
+ cf_read(cfdeffile);
msg=cf_set_item(sect,name,value);
}
if(msg)
}else if(res=='C'){
cf_read(optarg);
+ }else if(res==-1){
+ if(cfdeffile)
+ cf_read(cfdeffile);
+ return res;
}else{ /* unhandled option */
return res;
}