From 6ef82224faa2c3c44f4ef18950d3286ef1d4b8ae Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Mon, 5 Mar 2001 09:02:11 +0000 Subject: [PATCH] cf_default_init() replaced by direct access to cfdeffile, the default value is DEFAULT_CONFIG cf_default_done() replaced by automatical call if getopt() returns -1 --- lib/conf.c | 17 ++++------------- lib/conf.h | 13 ++++++++----- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/conf.c b/lib/conf.c index f6a5f0ee..a357cfeb 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -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; } diff --git a/lib/conf.h b/lib/conf.h index 0e08ac84..81c10ce2 100644 --- a/lib/conf.h +++ b/lib/conf.h @@ -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); -- 2.39.5