46 #if defined(_WIN32) && !defined(__GNUC__) 48 # define fileno _fileno 52 # define isatty _isatty 55 # define DLLIMPORT __declspec (dllexport) 57 # define DLLIMPORT __declspec (dllimport) 87 #define CFGF_NODEFAULT 16 88 #define CFGF_NO_TITLE_DUPES 32 93 #define CFGF_DEFINIT 128 94 #define CFGF_IGNORE_UNKNOWN 256 95 #define CFGF_DEPRECATED 512 96 #define CFGF_DROP 1024 97 #define CFGF_COMMENTS 2048 100 #define CFG_SUCCESS 0 102 #define CFG_FILE_ERROR -1 103 #define CFG_PARSE_ERROR 1 110 typedef int cfg_flag_t;
111 typedef struct cfg_searchpath_t cfg_searchpath_t;
227 typedef enum { cfg_false, cfg_true }
cfg_bool_t;
250 cfg_searchpath_t *
path;
296 unsigned int nvalues;
312 extern const char __export confuse_copyright[];
313 extern const char __export confuse_version[];
314 extern const char __export confuse_author[];
316 #define __CFG_STR(name, def, flags, svalue, cb) \ 317 {name,0,CFGT_STR,0,0,flags,0,{0,0,cfg_false,def,0},0,{.string=svalue},cb,0,0,0,0} 318 #define __CFG_STR_LIST(name, def, flags, svalue, cb) \ 319 {name,0,CFGT_STR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.string=svalue},cb,0,0,0,0} 323 #define CFG_STR(name, def, flags) \ 324 __CFG_STR(name, def, flags, 0, 0) 328 #define CFG_STR_LIST(name, def, flags) \ 329 __CFG_STR_LIST(name, def, flags, 0, 0) 333 #define CFG_STR_CB(name, def, flags, cb) \ 334 __CFG_STR(name, def, flags, 0, cb) 338 #define CFG_STR_LIST_CB(name, def, flags, cb) \ 339 __CFG_STR_LIST(name, def, flags, 0, cb) 393 #define CFG_SIMPLE_STR(name, svalue) \ 394 __CFG_STR(name, 0, CFGF_NONE, svalue, 0) 397 #define __CFG_INT(name, def, flags, svalue, cb) \ 398 {name,0,CFGT_INT,0,0,flags,0,{def,0,cfg_false,0,0},0,{.number=svalue},cb,0,0,0,0} 399 #define __CFG_INT_LIST(name, def, flags, svalue, cb) \ 400 {name,0,CFGT_INT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.number=svalue},cb,0,0,0,0} 404 #define CFG_INT(name, def, flags) \ 405 __CFG_INT(name, def, flags, 0, 0) 409 #define CFG_INT_LIST(name, def, flags) \ 410 __CFG_INT_LIST(name, def, flags, 0, 0) 414 #define CFG_INT_CB(name, def, flags, cb) \ 415 __CFG_INT(name, def, flags, 0, cb) 419 #define CFG_INT_LIST_CB(name, def, flags, cb) \ 420 __CFG_INT_LIST(name, def, flags, 0, cb) 428 #define CFG_SIMPLE_INT(name, svalue) \ 429 __CFG_INT(name, 0, CFGF_NONE, svalue, 0) 433 #define __CFG_FLOAT(name, def, flags, svalue, cb) \ 434 {name,0,CFGT_FLOAT,0,0,flags,0,{0,def,cfg_false,0,0},0,{.fpnumber=svalue},cb,0,0,0,0} 435 #define __CFG_FLOAT_LIST(name, def, flags, svalue, cb) \ 436 {name,0,CFGT_FLOAT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.fpnumber=svalue},cb,0,0,0,0} 440 #define CFG_FLOAT(name, def, flags) \ 441 __CFG_FLOAT(name, def, flags, 0, 0) 445 #define CFG_FLOAT_LIST(name, def, flags) \ 446 __CFG_FLOAT_LIST(name, def, flags, 0, 0) 450 #define CFG_FLOAT_CB(name, def, flags, cb) \ 451 __CFG_FLOAT(name, def, flags, 0, cb) 455 #define CFG_FLOAT_LIST_CB(name, def, flags, cb) \ 456 __CFG_FLOAT_LIST(name, def, flags, 0, cb) 461 #define CFG_SIMPLE_FLOAT(name, svalue) \ 462 __CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0) 466 #define __CFG_BOOL(name, def, flags, svalue, cb) \ 467 {name,0,CFGT_BOOL,0,0,flags,0,{0,0,def,0,0},0,{.boolean=svalue},cb,0,0,0,0} 468 #define __CFG_BOOL_LIST(name, def, flags, svalue, cb) \ 469 {name,0,CFGT_BOOL,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.boolean=svalue},cb,0,0,0,0} 473 #define CFG_BOOL(name, def, flags) \ 474 __CFG_BOOL(name, def, flags, 0, 0) 478 #define CFG_BOOL_LIST(name, def, flags) \ 479 __CFG_BOOL_LIST(name, def, flags, 0, 0) 483 #define CFG_BOOL_CB(name, def, flags, cb) \ 484 __CFG_BOOL(name, def, flags, 0, cb) 488 #define CFG_BOOL_LIST_CB(name, def, flags, cb) \ 489 __CFG_BOOL_LIST(name, def, flags, 0, cb) 494 #define CFG_SIMPLE_BOOL(name, svalue) \ 495 __CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0) 510 #define CFG_SEC(name, opts, flags) \ 511 {name,0,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,{0},0,0,0,0,0} 521 #define CFG_FUNC(name, func) \ 522 {name,0,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,{0},0,0,0,0,0} 525 #define __CFG_PTR(name, def, flags, svalue, parsecb, freecb) \ 526 {name,0,CFGT_PTR,0,0,flags,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,0,freecb} 527 #define __CFG_PTR_LIST(name, def, flags, svalue, parsecb, freecb) \ 528 {name,0,CFGT_PTR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,0,freecb} 542 #define CFG_PTR_CB(name, def, flags, parsecb, freecb) \ 543 __CFG_PTR(name, def, flags, 0, parsecb, freecb) 547 #define CFG_PTR_LIST_CB(name, def, flags, parsecb, freecb) \ 548 __CFG_PTR(name, def, flags | CFGF_LIST, 0, parsecb, freecb) 558 {0,0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,{0},0,0,0,0,0} 687 DLLIMPORT
void __export
cfg_error(
cfg_t *cfg,
const char *fmt, ...);
810 DLLIMPORT
void *__export cfg_opt_getnptr(
cfg_opt_t *opt,
unsigned int index);
811 DLLIMPORT
void *__export cfg_getnptr(
cfg_t *cfg,
const char *
name,
unsigned int indx);
1024 DLLIMPORT
int __export
cfg_setnint(
cfg_t *cfg,
const char *
name,
long int value,
unsigned int index);
1096 DLLIMPORT
int __export
cfg_setnbool(
cfg_t *cfg,
const char *
name, cfg_bool_t value,
unsigned int index);
1135 DLLIMPORT
int __export
cfg_setnstr(
cfg_t *cfg,
const char *
name,
const char *value,
unsigned int index);
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:291
DLLIMPORT int __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:1889
floating point number
Definition: confuse.h:71
cfg_bool_t
Boolean values.
Definition: confuse.h:229
Data structure holding information about an option.
Definition: confuse.h:294
int(* cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt)
Validating callback prototype.
Definition: confuse.h:200
DLLIMPORT int __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:1912
DLLIMPORT int __export cfg_opt_setnint(cfg_opt_t *opt, long int value, unsigned int index)
Set a value of an integer option.
Definition: confuse.c:1826
integer
Definition: confuse.h:70
DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags)
Create and initialize a cfg_t structure.
Definition: confuse.c:1575
DLLIMPORT int __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:1844
DLLIMPORT int __export cfg_opt_print(cfg_opt_t *opt, FILE *fp)
Print an option and its value to a file.
Definition: confuse.c:2272
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:410
DLLIMPORT int cfg_opt_setmulti(cfg_t *cfg, cfg_opt_t *opt, unsigned int nvalues, char **values)
Set an option (create an instance of an option).
Definition: confuse.c:884
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:1421
DLLIMPORT int __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:1878
DLLIMPORT int __export cfg_opt_setnstr(cfg_opt_t *opt, const char *value, unsigned int index)
Set a value of a string option.
Definition: confuse.c:1922
Data structure holding the default value given by the initialization macros.
Definition: confuse.h:280
cfg_type_t
Fundamental option types.
Definition: confuse.h:68
DLLIMPORT int __export cfg_rmnsec(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_rmsec(), used for CFGF_MULTI sections.
Definition: confuse.c:2093
DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt)
Return the number of values this option has.
Definition: confuse.c:241
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:520
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:306
DLLIMPORT int __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:1917
DLLIMPORT int __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent)
Print the options and values to a file.
Definition: confuse.c:2277
DLLIMPORT int __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:1855
DLLIMPORT int __export cfg_opt_rmtsec(cfg_opt_t *opt, const char *title)
Removes and frees a config section, given a cfg_opt_t pointer and the title.
Definition: confuse.c:2103
int line
Line number in the config file.
Definition: confuse.h:248
void(* cfg_free_func_t)(void *value)
User-defined memory release function for CFG_PTR values.
Definition: confuse.h:226
DLLIMPORT int __export cfg_rmtsec(cfg_t *cfg, const char *name, const char *title)
Removes and frees a section given the title, used for section with the CFGF_TITLE flag set...
Definition: confuse.c:2136
DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name)
Return the number of values this option has.
Definition: confuse.c:248
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:1536
DLLIMPORT int __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:1965
DLLIMPORT int cfg_setmulti(cfg_t *cfg, const char *name, unsigned int nvalues, char **values)
Set an option (create an instance of an option).
Definition: confuse.c:915
void(* cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap)
Error reporting function.
Definition: confuse.h:232
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:331
DLLIMPORT char *__export cfg_opt_getcomment(cfg_opt_t *opt)
Returns the option comment.
Definition: confuse.c:253
function
Definition: confuse.h:75
DLLIMPORT char *__export cfg_getcomment(cfg_t *cfg, const char *name)
Returns the option comment.
Definition: confuse.c:261
Data structure holding information about a "section".
Definition: confuse.h:238
char * name
The name of this section, the root section returned from cfg_init() is always named "root"...
Definition: confuse.h:240
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:391
DLLIMPORT cfg_t * cfg_addtsec(cfg_t *cfg, const char *name, const char *title)
Create a new titled config section.
Definition: confuse.c:2039
DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp)
Print the options and values to a file.
Definition: confuse.c:2287
DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name)
Returns the value of a boolean option.
Definition: confuse.c:336
boolean value
Definition: confuse.h:73
comment/annotation
Definition: confuse.h:77
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:316
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:266
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:140
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:942
DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name)
Return an option given it's name.
Definition: confuse.c:168
DLLIMPORT int __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Set values for a list option.
Definition: confuse.c:2004
DLLIMPORT int __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:2195
cfg_searchpath_t * path
Linked list of directories to search.
Definition: confuse.h:252
DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name)
Returns the value of a floating point option.
Definition: confuse.c:311
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:2307
cfg_flag_t flags
Any flags passed to cfg_init()
Definition: confuse.h:239
DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename)
Parse a configuration file.
Definition: confuse.c:1505
DLLIMPORT int __export cfg_opt_rmnsec(cfg_opt_t *opt, unsigned int index)
Removes and frees a config section, given a cfg_opt_t pointer.
Definition: confuse.c:2063
int(* cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
Value parsing callback prototype.
Definition: confuse.h:185
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:969
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:341
DLLIMPORT cfg_value_t * cfg_setopt(cfg_t *cfg, cfg_opt_t *opt, const char *value)
Set an option (create an instance of an option).
Definition: confuse.c:665
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:281
DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name)
Returns the value of a user-defined option (void pointer).
Definition: confuse.c:386
DLLIMPORT int __export cfg_free_value(cfg_opt_t *opt)
Free the memory allocated for the values of a given option.
Definition: confuse.c:1657
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:2376
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:405
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:1474
DLLIMPORT int __export cfg_setcomment(cfg_t *cfg, const char *name, char *comment)
Annotate an option given its name.
Definition: confuse.c:1821
char * comment
Optional annotation/comment.
Definition: confuse.h:243
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:356
DLLIMPORT int __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:1954
string
Definition: confuse.h:72
Data structure holding the value of a fundamental option value.
Definition: confuse.h:257
DLLIMPORT int __export cfg_opt_setcomment(cfg_opt_t *opt, char *comment)
Annotate an option.
Definition: confuse.c:1799
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:2292
DLLIMPORT int __export cfg_opt_setnfloat(cfg_opt_t *opt, double value, unsigned int index)
Set a value of a floating point option.
Definition: confuse.c:1860
DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name)
Returns the value of an integer option.
Definition: confuse.c:286
char * title
Optional title for this section, only set if CFGF_TITLE flag is set.
Definition: confuse.h:245
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:162
cfg_errfunc_t errfunc
This function (if set with cfg_set_error_function) is called for any error message.
Definition: confuse.h:249
DLLIMPORT int __export cfg_free(cfg_t *cfg)
Free a cfg_t context.
Definition: confuse.c:1721
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:444
DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name)
Returns the value of a section option.
Definition: confuse.c:449
DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt)
Return the name of an option.
Definition: confuse.c:234
DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name)
Returns the value of a string option.
Definition: confuse.c:361
DLLIMPORT int __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:1894
char * filename
Name of the file being parsed.
Definition: confuse.h:247
DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name)
Removes and frees a config section.
Definition: confuse.c:2098
Data structure holding the pointer to a user provided variable defined with CFG_SIMPLE_*.
Definition: confuse.h:269
DLLIMPORT cfg_validate_callback2_t __export cfg_set_validate_func2(cfg_t *cfg, const char *name, cfg_validate_callback2_t vf)
Register a validating callback function for an option.
Definition: confuse.c:2391
DLLIMPORT const char *__export cfg_title(cfg_t *cfg)
Return the title of a section.
Definition: confuse.c:220
DLLIMPORT const char *__export cfg_name(cfg_t *cfg)
Return the name of a section.
Definition: confuse.c:227
DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
Predefined include-function.
Definition: confuse.c:1756
DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt,...)
Show a parser error.
Definition: confuse.c:984
int(* cfg_validate_callback2_t)(cfg_t *cfg, cfg_opt_t *opt, void *value)
Validating callback2 prototype.
Definition: confuse.h:216
DLLIMPORT int __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp)
Default value print function.
Definition: confuse.c:2141
DLLIMPORT char *__export cfg_tilde_expand(const char *filename)
Does tilde expansion (~ -> $HOME) on the filename.
Definition: confuse.c:1610
DLLIMPORT int __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Add values for a list option.
Definition: confuse.c:2022
cfg_opt_t * opts
Array of options.
Definition: confuse.h:244