]> mj.ucw.cz Git - libucw.git/commitdiff
added cf_default_{init,done} for setting the default config filename, that
authorRobert Spalek <robert@ucw.cz>
Sun, 4 Mar 2001 15:19:26 +0000 (15:19 +0000)
committerRobert Spalek <robert@ucw.cz>
Sun, 4 Mar 2001 15:19:26 +0000 (15:19 +0000)
will be automatically readed if not overriden by command-line option

lib/conf.c
lib/conf.h

index 223ff666f77e222a1dc85f7482939338db506208..f6a5f0ee9ed5cfabbcf9ab185c9edb71334f7bfd 100644 (file)
@@ -24,6 +24,8 @@
 static struct cfitem *cfsection;
 static struct mempool *cfpool;
 
+static byte *cfdeffile = NULL;
+
 static void CONSTRUCTOR
 conf_init(void)
 {
@@ -210,6 +212,19 @@ void cf_read(byte *filename)
 {
        if(!cf_subread(filename,0))
                die("Reading config file %s failed",filename);
+       cfdeffile = NULL;
+}
+
+void
+cf_default_init(byte *filename)
+{
+       cfdeffile = filename;
+}
+
+void cf_default_done(void)
+{
+       if (cfdeffile)
+               cf_read(cfdeffile);
 }
 
 int cf_getopt(int argc,char * const argv[],
@@ -243,6 +258,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)
index b01cba3bd9207b5d9bd498243b45c3b71c9e24c9..0e08ac84fbc2e022ff0bf605ea1b45c969b67998 100644 (file)
@@ -47,6 +47,10 @@ void cf_read(byte *filename);
 /*
  * When using cf_getopt, you must prefix your own short/long options by the
  * CF_(SHORT|LONG)_OPTS.
+ *
+ * If you want to automatically load default config file before first option is
+ * overriden, register it by cf_default_init and call cf_default_done after
+ * parsing is done.  It will not be loaded if another config file is specified.
  */
 
 #define        CF_SHORT_OPTS   "S:C:"
@@ -55,6 +59,8 @@ void cf_read(byte *filename);
        {"config",      1, 0, 'C'},
 #define CF_NO_LONG_OPTS (const struct option []){ CF_LONG_OPTS { NULL, 0, 0, 0 } }
 
+void cf_default_init(byte *filename);
+void cf_default_done(void);
 int cf_getopt(int argc,char * const argv[],
                const char *shortopts,const struct option *longopts,
                int *longindex);