will be automatically readed if not overriden by command-line option
static struct cfitem *cfsection;
static struct mempool *cfpool;
static struct cfitem *cfsection;
static struct mempool *cfpool;
+static byte *cfdeffile = NULL;
+
static void CONSTRUCTOR
conf_init(void)
{
static void CONSTRUCTOR
conf_init(void)
{
{
if(!cf_subread(filename,0))
die("Reading config file %s failed",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[],
}
int cf_getopt(int argc,char * const argv[],
+ if (cfdeffile)
+ cf_read(cfdeffile);
msg=cf_set_item(sect,name,value);
}
if(msg)
msg=cf_set_item(sect,name,value);
}
if(msg)
/*
* When using cf_getopt, you must prefix your own short/long options by the
* CF_(SHORT|LONG)_OPTS.
/*
* 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:"
*/
#define CF_SHORT_OPTS "S:C:"
{"config", 1, 0, 'C'},
#define CF_NO_LONG_OPTS (const struct option []){ CF_LONG_OPTS { NULL, 0, 0, 0 } }
{"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);
int cf_getopt(int argc,char * const argv[],
const char *shortopts,const struct option *longopts,
int *longindex);