]> mj.ucw.cz Git - libucw.git/blobdiff - lib/conf.c
cf_default_init() replaced by direct access to cfdeffile, the default value
[libucw.git] / lib / conf.c
index b899b55e98bc19b1c75271b4ccba2e5fe0e83887..a357cfeb25604dfb92aa92deaf9794dd78c130d3 100644 (file)
@@ -24,6 +24,8 @@
 static struct cfitem *cfsection;
 static struct mempool *cfpool;
 
+byte *cfdeffile = DEFAULT_CONFIG;
+
 static void CONSTRUCTOR
 conf_init(void)
 {
@@ -53,6 +55,16 @@ void cf_register(struct cfitem *items)
        cfsection=items;
 }
 
+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;
@@ -200,6 +212,7 @@ void cf_read(byte *filename)
 {
        if(!cf_subread(filename,0))
                die("Reading config file %s failed",filename);
+       cfdeffile = NULL;
 }
 
 int cf_getopt(int argc,char * const argv[],
@@ -233,6 +246,8 @@ int cf_getopt(int argc,char * const argv[],
                                        name=c;
                                }
 
+                               if (cfdeffile)
+                                       cf_read(cfdeffile);
                                msg=cf_set_item(sect,name,value);
                        }
                        if(msg)
@@ -240,6 +255,9 @@ int cf_getopt(int argc,char * const argv[],
 
                }else if(res=='C'){
                        cf_read(optarg);
+               }else if(res==-1){
+                       if(cfdeffile)
+                               cf_read(cfdeffile);
                }else{  /* unhandled option */
                        return res;
                }