confuse.h File Reference
A configuration file parser library. More...
#include <stdio.h>
#include <stdarg.h>
Go to the source code of this file.
Data Structures | |
struct | cfg_opt_t |
Data structure holding information about an option. More... | |
struct | cfg_t |
Data structure holding information about a "section". More... | |
union | cfg_value_t |
Data structure holding the value of a fundamental option value. More... | |
Defines | |
#define | CFGF_NONE 0 |
Flags. | |
#define | CFGF_MULTI 1 |
option may be specified multiple times | |
#define | CFGF_LIST 2 |
option is a list | |
#define | CFGF_NOCASE 4 |
configuration file is case insensitive | |
#define | CFGF_TITLE 8 |
option has a title (only applies to section) | |
#define | CFG_SUCCESS 0 |
Return codes from cfg_parse(). | |
#define | CFG_STR(name, def, flags) __CFG_STR(name, def, flags, 0, 0) |
Initialize a string option. | |
#define | CFG_STR_LIST(name, def, flags) __CFG_STR_LIST(name, def, flags, 0, 0) |
Initialize a string list option. | |
#define | CFG_STR_CB(name, def, flags, cb) __CFG_STR(name, def, flags, 0, cb) |
Initialize a string option with a value parsing callback. | |
#define | CFG_STR_LIST_CB(name, def, flags, cb) __CFG_STR_LIST(name, def, flags, 0, cb) |
Initialize a string list option with a value parsing callback. | |
#define | CFG_SIMPLE_STR(name, svalue) __CFG_STR(name, 0, CFGF_NONE, svalue, 0) |
Initialize a "simple" string option. | |
#define | CFG_INT(name, def, flags) __CFG_INT(name, def, flags, 0, 0) |
Initialize an integer option. | |
#define | CFG_INT_LIST(name, def, flags) __CFG_INT_LIST(name, def, flags, 0, 0) |
Initialize an integer list option. | |
#define | CFG_INT_CB(name, def, flags, cb) __CFG_INT(name, def, flags, 0, cb) |
Initialize an integer option with a value parsing callback. | |
#define | CFG_INT_LIST_CB(name, def, flags, cb) __CFG_INT_LIST(name, def, flags, 0, cb) |
Initialize an integer list option with a value parsing callback. | |
#define | CFG_SIMPLE_INT(name, svalue) __CFG_INT(name, 0, CFGF_NONE, svalue, 0) |
Initialize a "simple" integer option (see documentation for CFG_SIMPLE_STR for more information). | |
#define | CFG_FLOAT(name, def, flags) __CFG_FLOAT(name, def, flags, 0, 0) |
Initialize a floating point option. | |
#define | CFG_FLOAT_LIST(name, def, flags) __CFG_FLOAT_LIST(name, def, flags, 0, 0) |
Initialize a floating point list option. | |
#define | CFG_FLOAT_CB(name, def, flags, cb) __CFG_FLOAT(name, def, flags, 0, cb) |
Initialize a floating point option with a value parsing callback. | |
#define | CFG_FLOAT_LIST_CB(name, def, flags, cb) __CFG_FLOAT_LIST(name, def, flags, 0, cb) |
Initialize a floating point list option with a value parsing callback. | |
#define | CFG_SIMPLE_FLOAT(name, svalue) __CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0) |
Initialize a "simple" floating point option (see documentation for CFG_SIMPLE_STR for more information). | |
#define | CFG_BOOL(name, def, flags) __CFG_BOOL(name, def, flags, 0, 0) |
Initialize a boolean option. | |
#define | CFG_BOOL_LIST(name, def, flags) __CFG_BOOL_LIST(name, def, flags, 0, 0) |
Initialize a boolean list option. | |
#define | CFG_BOOL_CB(name, def, flags, cb) __CFG_BOOL(name, def, flags, 0, cb) |
Initialize a boolean option with a value parsing callback. | |
#define | CFG_BOOL_LIST_CB(name, def, flags, cb) __CFG_BOOL_LIST(name, def, flags, 0, cb) |
Initialize a boolean list option with a value parsing callback. | |
#define | CFG_SIMPLE_BOOL(name, svalue) __CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0) |
Initialize a "simple" boolean option (see documentation for CFG_SIMPLE_STR for more information). | |
#define | CFG_SEC(name, opts, flags) {name,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,0,0} |
Initialize a section. | |
#define | CFG_FUNC(name, func) {name,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,0,0} |
Initialize a function. | |
#define | CFG_END() {0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,0,0} |
Terminate list of options. | |
Typedefs | |
typedef int(* | cfg_func_t )(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv) |
Function prototype used by CFGT_FUNC options. | |
typedef int(* | cfg_callback_t )(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result) |
Value parsing callback prototype. | |
typedef void(* | cfg_errfunc_t )(cfg_t *cfg, const char *fmt, va_list ap) |
Error reporting function. | |
Enumerations | |
enum | cfg_type_t { , CFGT_INT, CFGT_FLOAT, CFGT_STR, CFGT_BOOL, CFGT_SEC, CFGT_FUNC } |
Fundamental option types. More... | |
enum | cfg_bool_t |
Boolean values. | |
Functions | |
DLLIMPORT cfg_t *__export | cfg_init (cfg_opt_t *opts, cfg_flag_t flags) |
Create and initialize a cfg_t structure. | |
DLLIMPORT int __export | cfg_parse (cfg_t *cfg, const char *filename) |
Parse a configuration file. | |
DLLIMPORT int __export | cfg_parse_fp (cfg_t *cfg, FILE *fp) |
Same as cfg_parse() above, but takes an already opened file as argument. | |
DLLIMPORT int __export | cfg_parse_buf (cfg_t *cfg, const char *buf) |
Same as cfg_parse() above, but takes a character buffer as argument. | |
DLLIMPORT void __export | cfg_free_value (cfg_opt_t *opt) |
Free the memory allocated for the values of a given option. | |
DLLIMPORT void __export | cfg_free (cfg_t *cfg) |
Free a cfg_t context. | |
DLLIMPORT cfg_errfunc_t __export | cfg_set_error_function (cfg_t *cfg, cfg_errfunc_t errfunc) |
Install a user-defined error reporting function. | |
DLLIMPORT void __export | cfg_error (cfg_t *cfg, const char *fmt,...) |
Show a parser error. | |
DLLIMPORT long int __export | cfg_getint (cfg_t *cfg, const char *name) |
Returns the value of an integer option. | |
DLLIMPORT double __export | cfg_getfloat (cfg_t *cfg, const char *name) |
Returns the value of a floating point option. | |
DLLIMPORT char *__export | cfg_getstr (cfg_t *cfg, const char *name) |
Returns the value of a string option. | |
DLLIMPORT cfg_bool_t __export | cfg_getbool (cfg_t *cfg, const char *name) |
Returns the value of a boolean option. | |
DLLIMPORT cfg_t *__export | cfg_getsec (cfg_t *cfg, const char *name) |
Returns the value of a section option. | |
DLLIMPORT unsigned int __export | cfg_size (cfg_t *cfg, const char *name) |
Return the number of values this option has. | |
DLLIMPORT long int __export | cfg_getnint (cfg_t *cfg, const char *name, unsigned int index) |
Indexed version of cfg_getint(). | |
DLLIMPORT double __export | cfg_getnfloat (cfg_t *cfg, const char *name, unsigned int index) |
Indexed version of cfg_getfloat(). | |
DLLIMPORT char *__export | cfg_getnstr (cfg_t *cfg, const char *name, unsigned int index) |
Indexed version of cfg_getstr(). | |
DLLIMPORT cfg_bool_t __export | cfg_getnbool (cfg_t *cfg, const char *name, unsigned int index) |
Indexed version of cfg_getbool(). | |
DLLIMPORT cfg_t *__export | cfg_getnsec (cfg_t *cfg, const char *name, unsigned int index) |
Indexed version of cfg_getsec(). | |
DLLIMPORT cfg_t *__export | cfg_gettsec (cfg_t *cfg, const char *name, const char *title) |
Return a section given the title. | |
DLLIMPORT const char *__export | cfg_title (cfg_t *cfg) |
Return the title of a section. | |
DLLIMPORT int __export | cfg_include (cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv) |
Predefined include-function. | |
DLLIMPORT char *__export | cfg_tilde_expand (const char *filename) |
Does tilde expansion (~ -> $HOME) on the filename. | |
DLLIMPORT int __export | cfg_parse_boolean (const char *s) |
Parse a boolean option string. | |
DLLIMPORT cfg_opt_t *__export | cfg_getopt (cfg_t *cfg, const char *name) |
Return an option given it's name. | |
DLLIMPORT void __export | cfg_opt_setnint (cfg_t *cfg, cfg_opt_t *opt, long int value, unsigned int index) |
Set a value of an integer option. | |
DLLIMPORT void __export | cfg_setint (cfg_t *cfg, const char *name, long int value) |
Set the value of an integer option given its name. | |
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. | |
DLLIMPORT void __export | cfg_opt_setnfloat (cfg_t *cfg, cfg_opt_t *opt, double value, unsigned int index) |
Set a value of a floating point option. | |
DLLIMPORT void __export | cfg_setfloat (cfg_t *cfg, const char *name, double value) |
Set the value of a floating point option given its name. | |
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. | |
DLLIMPORT void __export | cfg_opt_setnbool (cfg_t *cfg, cfg_opt_t *opt, cfg_bool_t value, unsigned int index) |
Set a value of a boolean option. | |
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. | |
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. | |
DLLIMPORT void __export | cfg_opt_setnstr (cfg_t *cfg, cfg_opt_t *opt, const char *value, unsigned int index) |
Set a value of a string option. | |
DLLIMPORT void __export | cfg_setstr (cfg_t *cfg, const char *name, const char *value) |
Set the value of a string option given its name. | |
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. |
Detailed Description
A configuration file parser library.
Define Documentation
|
Terminate list of options. This must be the last initializer in the option list. |
|
Initialize a function.
|
|
Initialize a section.
|
|
Initialize a "simple" string option. "Simple" options (in lack of a better expression) does not support lists of values or multiple sections. LibConfuse will store the value of a simple option in the user-defined location specified by the value parameter in the initializer. Simple options are not stored in the cfg_t context (you can thus not use the cfg_get* functions to get the value). Sections can not be initialized as a "simple" option.
char *user = strdup("joe"); ... cfg_opt_t opts[] = { CFG_SIMPLE_STR("user", &user), ...
|
Typedef Documentation
|
Value parsing callback prototype. This is a callback function (different from the one registered with the CFG_FUNC initializer) used to parse a value. This can be used to override the internal parsing of a value. Suppose you want an integer option that only can have certain values, for example 1, 2 and 3, and these should be written in the configuration file as "yes", "no" and "maybe". The callback function would be called with the found value ("yes", "no" or "maybe") as a string, and the result should be stored in the result parameter.
|
|
Function prototype used by CFGT_FUNC options. This is a callback function, registered with the CFG_FUNC initializer. Each time libConfuse finds a function, the registered callback function is called (parameters are passed as strings, any conversion to other types should be made in the callback function). libConfuse does not support any storage of the data found; these are passed as parameters to the callback, and it's the responsibility of the callback function to do whatever it should do with the data.
|
Enumeration Type Documentation
|
Fundamental option types.
|
Function Documentation
|
Show a parser error. Any user-defined error reporting function is called.
|
|
Free a cfg_t context. All memory allocated by the cfg_t context structure are freed, and can't be used in any further cfg_* calls. |
|
Free the memory allocated for the values of a given option. Only the values are freed, not the option itself (it is often statically initialized). |
|
Returns the value of a boolean option.
|
|
Returns the value of a floating point option.
|
|
Returns the value of an integer option. This is the same as calling cfg_getnint with index 0.
|
|
Indexed version of cfg_getbool().
|
|
Indexed version of cfg_getfloat().
|
|
Indexed version of cfg_getint().
|
|
Indexed version of cfg_getsec().
|
|
Indexed version of cfg_getstr().
|
|
Return an option given it's name.
|
|
Returns the value of a section option. The returned value is another cfg_t structure that can be used in following calls to cfg_getint, cfg_getstr or other get-functions.
|
|
Returns the value of a string option.
|
|
Return a section given the title.
|
|
Predefined include-function. This function can be used in the options passed to cfg_init() to specify a function for including other configuration files in the parsing. For example: CFG_FUNC("include", &cfg_include) |
|
Create and initialize a cfg_t structure. This should be the first function called when setting up the parsing of a configuration file. The options passed in the first parameter is typically statically initialized, using the CFG_* initializers. The last option in the option array must be CFG_END(), unless you like segmentation faults. The options must also be defined in the same scope as where the cfg_xxx functions are used. This means that you should either define the option array in main(), statically in another function, as global variables or dynamically using malloc(). The option array is used in nearly all calls.
|
|
Set a value of a boolean option.
|
|
Set a value of a floating point option.
|
|
Set a value of an integer option.
|
|
Set a value of a string option.
|
|
Parse a configuration file. Tilde expansion is performed on the filename before it is opened. After a configuration file has been initialized (with cfg_init()) and parsed (with cfg_parse()), the values can be read with the cfg_getXXX functions.
|
|
Parse a boolean option string. Accepted "true" values are "true", "on" and "yes", and accepted "false" values are "false", "off" and "no".
|
|
Same as cfg_parse() above, but takes a character buffer as argument.
|
|
Same as cfg_parse() above, but takes an already opened file as argument. Reading begins at the current position. After parsing, the position is not reset. The caller is responsible for closing the file.
|
|
Install a user-defined error reporting function.
|
|
Set the value of a boolean option given its name.
|
|
Set the value of a floating point option given its name.
|
|
Set the value of an integer option given its name.
|
|
Set a value of a boolean option given its name.
|
|
Set a value of a floating point option given its name.
|
|
Set a value of an integer option given its name.
|
|
Set a value of a boolean option given its name.
|
|
Set the value of a string option given its name.
|
|
Return the number of values this option has. If no default value is given for the option and no value was found in the config file, 0 will be returned (ie, the option value is not set at all). It that case, calling cfg_getXXX will abort.
|
|
Does tilde expansion (~ -> $HOME) on the filename.
|
|
Return the title of a section.
|