From: Robert Spalek Date: Sun, 4 Mar 2001 15:19:26 +0000 (+0000) Subject: added cf_default_{init,done} for setting the default config filename, that X-Git-Tag: holmes-import~1530 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=05945b74fb145f8eb22312cbd52fa9e5c660e5b6;p=libucw.git added cf_default_{init,done} for setting the default config filename, that will be automatically readed if not overriden by command-line option --- diff --git a/lib/conf.c b/lib/conf.c index 223ff666..f6a5f0ee 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -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) diff --git a/lib/conf.h b/lib/conf.h index b01cba3b..0e08ac84 100644 --- a/lib/conf.h +++ b/lib/conf.h @@ -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);