46 #if defined(_WIN32) && !defined(__GNUC__)
48 # define fileno _fileno
52 # define isatty _isatty
55 # define DLLIMPORT __declspec (dllexport)
57 # define DLLIMPORT __declspec (dllimport)
86 #define CFGF_NODEFAULT 16
87 #define CFGF_NO_TITLE_DUPES 32
92 #define CFGF_DEFINIT 128
96 #define CFG_FILE_ERROR -1
97 #define CFG_PARSE_ERROR 1
104 typedef int cfg_flag_t;
105 typedef struct cfg_searchpath_t cfg_searchpath_t;
133 int argc,
const char **argv);
179 const char *value,
void *result);
207 typedef enum {cfg_false, cfg_true}
cfg_bool_t;
229 cfg_searchpath_t *
path;
289 extern const char __export confuse_copyright[];
290 extern const char __export confuse_version[];
291 extern const char __export confuse_author[];
293 #define __CFG_STR(name, def, flags, svalue, cb) \
294 {name,CFGT_STR,0,0,flags,0,{0,0,cfg_false,def,0},0,{.string=svalue},cb,0,0,0}
295 #define __CFG_STR_LIST(name, def, flags, svalue, cb) \
296 {name,CFGT_STR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.string=svalue},cb,0,0,0}
300 #define CFG_STR(name, def, flags) \
301 __CFG_STR(name, def, flags, 0, 0)
305 #define CFG_STR_LIST(name, def, flags) \
306 __CFG_STR_LIST(name, def, flags, 0, 0)
310 #define CFG_STR_CB(name, def, flags, cb) \
311 __CFG_STR(name, def, flags, 0, cb)
315 #define CFG_STR_LIST_CB(name, def, flags, cb) \
316 __CFG_STR_LIST(name, def, flags, 0, cb)
370 #define CFG_SIMPLE_STR(name, svalue) \
371 __CFG_STR(name, 0, CFGF_NONE, svalue, 0)
374 #define __CFG_INT(name, def, flags, svalue, cb) \
375 {name,CFGT_INT,0,0,flags,0,{def,0,cfg_false,0,0},0,{.number=svalue},cb,0,0,0}
376 #define __CFG_INT_LIST(name, def, flags, svalue, cb) \
377 {name,CFGT_INT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.number=svalue},cb,0,0,0}
381 #define CFG_INT(name, def, flags) \
382 __CFG_INT(name, def, flags, 0, 0)
386 #define CFG_INT_LIST(name, def, flags) \
387 __CFG_INT_LIST(name, def, flags, 0, 0)
391 #define CFG_INT_CB(name, def, flags, cb) \
392 __CFG_INT(name, def, flags, 0, cb)
396 #define CFG_INT_LIST_CB(name, def, flags, cb) \
397 __CFG_INT_LIST(name, def, flags, 0, cb)
405 #define CFG_SIMPLE_INT(name, svalue) \
406 __CFG_INT(name, 0, CFGF_NONE, svalue, 0)
410 #define __CFG_FLOAT(name, def, flags, svalue, cb) \
411 {name,CFGT_FLOAT,0,0,flags,0,{0,def,cfg_false,0,0},0,{.fpnumber=svalue},cb,0,0,0}
412 #define __CFG_FLOAT_LIST(name, def, flags, svalue, cb) \
413 {name,CFGT_FLOAT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.fpnumber=svalue},cb,0,0,0}
417 #define CFG_FLOAT(name, def, flags) \
418 __CFG_FLOAT(name, def, flags, 0, 0)
422 #define CFG_FLOAT_LIST(name, def, flags) \
423 __CFG_FLOAT_LIST(name, def, flags, 0, 0)
427 #define CFG_FLOAT_CB(name, def, flags, cb) \
428 __CFG_FLOAT(name, def, flags, 0, cb)
432 #define CFG_FLOAT_LIST_CB(name, def, flags, cb) \
433 __CFG_FLOAT_LIST(name, def, flags, 0, cb)
438 #define CFG_SIMPLE_FLOAT(name, svalue) \
439 __CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0)
443 #define __CFG_BOOL(name, def, flags, svalue, cb) \
444 {name,CFGT_BOOL,0,0,flags,0,{0,0,def,0,0},0,{.boolean=svalue},cb,0,0,0}
445 #define __CFG_BOOL_LIST(name, def, flags, svalue, cb) \
446 {name,CFGT_BOOL,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.boolean=svalue},cb,0,0,0}
450 #define CFG_BOOL(name, def, flags) \
451 __CFG_BOOL(name, def, flags, 0, 0)
455 #define CFG_BOOL_LIST(name, def, flags) \
456 __CFG_BOOL_LIST(name, def, flags, 0, 0)
460 #define CFG_BOOL_CB(name, def, flags, cb) \
461 __CFG_BOOL(name, def, flags, 0, cb)
465 #define CFG_BOOL_LIST_CB(name, def, flags, cb) \
466 __CFG_BOOL_LIST(name, def, flags, 0, cb)
471 #define CFG_SIMPLE_BOOL(name, svalue) \
472 __CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0)
487 #define CFG_SEC(name, opts, flags) \
488 {name,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,{0},0,0,0,0}
498 #define CFG_FUNC(name, func) \
499 {name,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,{0},0,0,0,0}
502 #define __CFG_PTR(name, def, flags, svalue, parsecb, freecb) \
503 {name,CFGT_PTR,0,0,flags,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,freecb}
504 #define __CFG_PTR_LIST(name, def, flags, svalue, parsecb, freecb) \
505 {name,CFGT_PTR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,freecb}
519 #define CFG_PTR_CB(name, def, flags, parsecb, freecb) \
520 __CFG_PTR(name, def, flags, 0, parsecb, freecb)
524 #define CFG_PTR_LIST_CB(name, def, flags, parsecb, freecb) \
525 __CFG_PTR(name, def, flags | CFGF_LIST, 0, parsecb, freecb)
535 {0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,{0},0,0,0,0}
602 DLLIMPORT
int __export
cfg_parse(
cfg_t *cfg,
const char *filename);
647 DLLIMPORT
void __export
cfg_error(
cfg_t *cfg,
const char *fmt, ...);
756 DLLIMPORT
void * __export cfg_opt_getnptr(
cfg_opt_t *opt,
unsigned int index);
757 DLLIMPORT
void * __export cfg_getnptr(
cfg_t *cfg,
const char *name,
unsigned int indx);
840 DLLIMPORT
unsigned int __export
cfg_size(
cfg_t *cfg,
const char *name);
920 long int value,
unsigned int index);
942 long int value,
unsigned int index);
953 double value,
unsigned int index);
975 double value,
unsigned int index);
1020 const char *value,
unsigned int index);
1044 const char *value,
unsigned int index);
1057 unsigned int nvalues, ...);
1059 DLLIMPORT
int __export cfg_numopts(
cfg_opt_t *opts);
1072 unsigned int nvalues, ...);
DLLIMPORT double __export cfg_opt_getnfloat(cfg_opt_t *opt, unsigned int index)
Returns the value of a floating point option, given a cfg_opt_t pointer.
Definition: confuse.c:261
floating point number
Definition: confuse.h:71
DLLIMPORT void __export cfg_opt_setnbool(cfg_opt_t *opt, cfg_bool_t value, unsigned int index)
Set a value of a boolean option.
Definition: confuse.c:1446
cfg_bool_t
Boolean values.
Definition: confuse.h:209
Data structure holding information about an option.
Definition: confuse.h:273
DLLIMPORT void __export cfg_setstr(cfg_t *cfg, const char *name, const char *value)
Set the value of a string option given its name.
Definition: confuse.c:1482
int(* cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt)
Validating callback prototype.
Definition: confuse.h:196
DLLIMPORT cfg_value_t * cfg_setopt(cfg_t *cfg, cfg_opt_t *opt, char *value)
Set an option (create an instance of an option).
Definition: confuse.c:561
const char * name
The name of the option.
Definition: confuse.h:274
integer
Definition: confuse.h:70
DLLIMPORT void __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp)
Default value print function.
Definition: confuse.c:1545
DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags)
Create and initialize a cfg_t structure.
Definition: confuse.c:1226
cfg_bool_t boolean
default boolean value
Definition: confuse.h:262
void * ptr
user-defined value
Definition: confuse.h:242
DLLIMPORT cfg_t *__export cfg_opt_gettsec(cfg_opt_t *opt, const char *title)
Returns the value of a section option, given a cfg_opt_t pointer and the title.
Definition: confuse.c:360
DLLIMPORT int __export cfg_parse_fp(cfg_t *cfg, FILE *fp)
Same as cfg_parse() above, but takes an already opened file as argument.
Definition: confuse.c:1103
unsigned int nvalues
Number of values parsed.
Definition: confuse.h:276
Data structure holding the default value given by the initialization macros.
Definition: confuse.h:259
cfg_type_t
Fundamental option types.
Definition: confuse.h:68
DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt)
Return the number of values this option has.
Definition: confuse.c:227
pointer to user-defined value
Definition: confuse.h:76
DLLIMPORT int __export cfg_parse_boolean(const char *s)
Parse a boolean option string.
Definition: confuse.c:439
DLLIMPORT double __export cfg_getnfloat(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getfloat(), used for lists.
Definition: confuse.c:272
DLLIMPORT void __export cfg_setbool(cfg_t *cfg, const char *name, cfg_bool_t value)
Set the value of a boolean option given its name.
Definition: confuse.c:1461
DLLIMPORT void __export cfg_setint(cfg_t *cfg, const char *name, long int value)
Set the value of an integer option given its name.
Definition: confuse.c:1421
DLLIMPORT void __export cfg_opt_setnint(cfg_opt_t *opt, long int value, unsigned int index)
Set a value of an integer option.
Definition: confuse.c:1406
int line
Line number in the config file.
Definition: confuse.h:227
cfg_type_t type
Type of option.
Definition: confuse.h:275
void(* cfg_free_func_t)(void *value)
User-defined memory release function for CFG_PTR values.
Definition: confuse.h:206
DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name)
Return the number of values this option has.
Definition: confuse.c:234
DLLIMPORT int __export cfg_parse_buf(cfg_t *cfg, const char *buf)
Same as cfg_parse() above, but takes a character buffer as argument.
Definition: confuse.c:1206
DLLIMPORT void __export cfg_opt_setnfloat(cfg_opt_t *opt, double value, unsigned int index)
Set a value of a floating point option.
Definition: confuse.c:1426
DLLIMPORT void __export cfg_free_value(cfg_opt_t *opt)
Free the memory allocated for the values of a given option.
Definition: confuse.c:1296
DLLIMPORT void __export cfg_free(cfg_t *cfg)
Free a cfg_t context.
Definition: confuse.c:1350
cfg_print_func_t pf
print callback function
Definition: confuse.h:287
void(* cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap)
Error reporting function.
Definition: confuse.h:212
cfg_opt_t * subopts
Suboptions (only applies to sections)
Definition: confuse.h:279
cfg_value_t ** values
Array of found values.
Definition: confuse.h:277
char * string
string value
Definition: confuse.h:240
DLLIMPORT cfg_bool_t __export cfg_getnbool(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getbool(), used for lists.
Definition: confuse.c:294
function
Definition: confuse.h:75
DLLIMPORT void __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent)
Print the options and values to a file.
Definition: confuse.c:1677
Data structure holding information about a "section".
Definition: confuse.h:218
char * name
The name of this section, the root section returned from cfg_init() is always named "root"...
Definition: confuse.h:220
DLLIMPORT cfg_t *__export cfg_opt_getnsec(cfg_opt_t *opt, unsigned int index)
Returns the value of a section option, given a cfg_opt_t pointer.
Definition: confuse.c:347
double fpnumber
default floating point value
Definition: confuse.h:261
DLLIMPORT void __export cfg_setnint(cfg_t *cfg, const char *name, long int value, unsigned int index)
Set a value of an integer option given its name and index.
Definition: confuse.c:1415
DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name)
Returns the value of a boolean option.
Definition: confuse.c:300
boolean value
Definition: confuse.h:73
DLLIMPORT cfg_bool_t __export cfg_opt_getnbool(cfg_opt_t *opt, unsigned int index)
Returns the value of a boolean option, given a cfg_opt_t pointer.
Definition: confuse.c:283
DLLIMPORT void __export cfg_setnbool(cfg_t *cfg, const char *name, cfg_bool_t value, unsigned int index)
Set a value of a boolean option given its name and index.
Definition: confuse.c:1455
DLLIMPORT signed long __export cfg_opt_getnint(cfg_opt_t *opt, unsigned int index)
Returns the value of an integer option, given a cfg_opt_t pointer.
Definition: confuse.c:239
int(* cfg_func_t)(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
Function prototype used by CFGT_FUNC options.
Definition: confuse.h:134
DLLIMPORT int __export cfg_add_searchpath(cfg_t *cfg, const char *dir)
Add a searchpath directory to the configuration context, the const char* argument will be duplicated ...
Definition: confuse.c:760
DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name)
Return an option given it's name.
Definition: confuse.c:161
cfg_callback_t parsecb
Value parsing callback function.
Definition: confuse.h:285
DLLIMPORT void __export cfg_opt_print_indent(cfg_opt_t *opt, FILE *fp, int indent)
Print an option and its value to a file.
Definition: confuse.c:1590
cfg_simple_t simple_value
Pointer to user-specified variable to store simple values (created with the CFG_SIMPLE_* initializers...
Definition: confuse.h:282
cfg_searchpath_t * path
Linked list of directories to search.
Definition: confuse.h:231
DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name)
Returns the value of a floating point option.
Definition: confuse.c:278
DLLIMPORT cfg_print_func_t __export cfg_set_print_func(cfg_t *cfg, const char *name, cfg_print_func_t pf)
Set a print callback function for an option given its name.
Definition: confuse.c:1702
cfg_flag_t flags
Any flags passed to cfg_init()
Definition: confuse.h:219
DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename)
Parse a configuration file.
Definition: confuse.c:1173
DLLIMPORT void __export cfg_setnfloat(cfg_t *cfg, const char *name, double value, unsigned int index)
Set a value of a floating point option given its name and index.
Definition: confuse.c:1435
int(* cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
Value parsing callback prototype.
Definition: confuse.h:180
const char * string
default string value
Definition: confuse.h:263
DLLIMPORT cfg_errfunc_t __export cfg_set_error_function(cfg_t *cfg, cfg_errfunc_t errfunc)
Install a user-defined error reporting function.
Definition: confuse.c:783
long int number
integer value
Definition: confuse.h:237
DLLIMPORT char *__export cfg_opt_getnstr(cfg_opt_t *opt, unsigned int index)
Returns the value of a string option, given a cfg_opt_t pointer.
Definition: confuse.c:305
DLLIMPORT void __export cfg_setnstr(cfg_t *cfg, const char *name, const char *value, unsigned int index)
Set a value of a boolean option given its name and index.
Definition: confuse.c:1476
DLLIMPORT void __export cfg_print(cfg_t *cfg, FILE *fp)
Print the options and values to a file.
Definition: confuse.c:1685
DLLIMPORT long int __export cfg_getnint(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getint(), used for lists.
Definition: confuse.c:250
cfg_defvalue_t def
Default value.
Definition: confuse.h:280
DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name)
Returns the value of a user-defined option (void pointer).
Definition: confuse.c:342
DLLIMPORT cfg_validate_callback_t __export cfg_set_validate_func(cfg_t *cfg, const char *name, cfg_validate_callback_t vf)
Register a validating callback function for an option.
Definition: confuse.c:1773
DLLIMPORT cfg_t *__export cfg_getnsec(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getsec(), used for sections with the CFGF_MULTI flag set.
Definition: confuse.c:355
DLLIMPORT char *__export cfg_searchpath(cfg_searchpath_t *path, const char *file)
Search the linked-list of cfg_searchpath_t for the specified file.
Definition: confuse.c:1144
cfg_validate_callback_t validcb
Value validating callback function.
Definition: confuse.h:286
DLLIMPORT char *__export cfg_getnstr(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getstr(), used for lists.
Definition: confuse.c:316
string
Definition: confuse.h:72
Data structure holding the value of a fundamental option value.
Definition: confuse.h:236
section
Definition: confuse.h:74
DLLIMPORT cfg_print_func_t __export cfg_opt_set_print_func(cfg_opt_t *opt, cfg_print_func_t pf)
Set a print callback function for an option.
Definition: confuse.c:1690
cfg_bool_t boolean
boolean value
Definition: confuse.h:239
DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name)
Returns the value of an integer option.
Definition: confuse.c:256
char * title
Optional title for this section, only set if CFGF_TITLE flag is set.
Definition: confuse.h:224
void(* cfg_print_func_t)(cfg_opt_t *opt, unsigned int index, FILE *fp)
Function prototype used by the cfg_print_ functions.
Definition: confuse.h:157
cfg_errfunc_t errfunc
This function (if set with cfg_set_error_function) is called for any error message.
Definition: confuse.h:228
DLLIMPORT cfg_t *__export cfg_gettsec(cfg_t *cfg, const char *name, const char *title)
Return a section given the title, used for section with the CFGF_TITLE flag set.
Definition: confuse.c:386
DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name)
Returns the value of a section option.
Definition: confuse.c:391
double fpnumber
floating point value
Definition: confuse.h:238
DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt)
Return the name of an option.
Definition: confuse.c:220
char * parsed
default value that is parsed by libConfuse, used for lists and functions
Definition: confuse.h:264
DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name)
Returns the value of a string option.
Definition: confuse.c:321
DLLIMPORT void __export cfg_setfloat(cfg_t *cfg, const char *name, double value)
Set the value of a floating point option given its name.
Definition: confuse.c:1441
DLLIMPORT void __export cfg_opt_setnstr(cfg_opt_t *opt, const char *value, unsigned int index)
Set a value of a string option.
Definition: confuse.c:1466
cfg_func_t func
Function callback for CFGT_FUNC options.
Definition: confuse.h:281
long int number
default integer value
Definition: confuse.h:260
DLLIMPORT void __export cfg_opt_print(cfg_opt_t *opt, FILE *fp)
Print an option and its value to a file.
Definition: confuse.c:1672
char * filename
Name of the file being parsed.
Definition: confuse.h:226
DLLIMPORT void __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Add values for a list option.
Definition: confuse.c:1532
Data structure holding the pointer to a user provided variable defined with CFG_SIMPLE_*.
Definition: confuse.h:248
DLLIMPORT void __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Set values for a list option.
Definition: confuse.c:1518
DLLIMPORT const char *__export cfg_title(cfg_t *cfg)
Return the title of a section.
Definition: confuse.c:206
DLLIMPORT const char *__export cfg_name(cfg_t *cfg)
Return the name of a section.
Definition: confuse.c:213
DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
Predefined include-function.
Definition: confuse.c:1370
DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt,...)
Show a parser error.
Definition: confuse.c:794
cfg_flag_t flags
Flags.
Definition: confuse.h:278
DLLIMPORT char *__export cfg_tilde_expand(const char *filename)
Does tilde expansion (~ -> $HOME) on the filename.
Definition: confuse.c:1251
cfg_t * section
section value
Definition: confuse.h:241
cfg_opt_t * opts
Array of options.
Definition: confuse.h:223