]> mj.ucw.cz Git - libucw.git/commitdiff
cf_default_init() replaced by direct access to cfdeffile, the default value
authorRobert Spalek <robert@ucw.cz>
Mon, 5 Mar 2001 09:02:11 +0000 (09:02 +0000)
committerRobert Spalek <robert@ucw.cz>
Mon, 5 Mar 2001 09:02:11 +0000 (09:02 +0000)
is DEFAULT_CONFIG
cf_default_done() replaced by automatical call if getopt() returns -1

lib/conf.c
lib/conf.h

index f6a5f0ee9ed5cfabbcf9ab185c9edb71334f7bfd..a357cfeb25604dfb92aa92deaf9794dd78c130d3 100644 (file)
@@ -24,7 +24,7 @@
 static struct cfitem *cfsection;
 static struct mempool *cfpool;
 
-static byte *cfdeffile = NULL;
+byte *cfdeffile = DEFAULT_CONFIG;
 
 static void CONSTRUCTOR
 conf_init(void)
@@ -215,18 +215,6 @@ void cf_read(byte *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[],
                const char *shortopts,const struct option *longopts,
                int *longindex)
@@ -267,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;
                }
index 0e08ac84fbc2e022ff0bf605ea1b45c969b67998..81c10ce24ae7a2c864ecb17cc2a828fea5522d09 100644 (file)
@@ -48,9 +48,12 @@ 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.
+ * cfdeffile contains filename of config file automatically loaded before a
+ * first --set option is executed.  If none --set option occures, it will be
+ * loaded after getopt returns -1 (at the end of configuration options).  It
+ * will be ignored, if another config file is set by --config option at first.
+ * Its initial value is DEFAULT_CONFIG from config.h, but you can override it
+ * manually.
  */
 
 #define        CF_SHORT_OPTS   "S:C:"
@@ -59,8 +62,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);
+extern byte *cfdeffile;
+
 int cf_getopt(int argc,char * const argv[],
                const char *shortopts,const struct option *longopts,
                int *longindex);