DetailedDescription

A configuration file parser library.

DefineDocumentation

#defineCFG_END(){0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,0,0,0,0,0}
Terminate list of options.
This must be the last initializer in the option list.
Examples:ftpconf.c, reread.c, and simple.c.
#defineCFG_FUNC(name,func){name,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,0,0,0,0,0}
Initialize a function.
Parameters:name The name of the option
func The callback function.
Seealso:cfg_func_tExamples:ftpconf.c.
#defineCFG_PTR_CB(name,def,flags,parsecb,freecb)__CFG_PTR(name,def,flags,0,parsecb,freecb)
Initialize a user-defined option.
CFG_PTR options can only be used together with a value parsing
callback.
Parameters:name The name of the option
def Default value
flags Flags
parsecb Value parsing callback
freecb Memory release function
Seealso:cfg_callback_t, cfg_free_func_t#defineCFG_SEC(name,opts,flags){name,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,0,0,0,0,0}
Initialize a section.
Parameters:name The name of the option
opts Array of options that are valid within this section
flags Flags, specify CFGF_MULTI if it should be possible to have
multiples of the same section, and CFGF_TITLE if the section(s)
must have a title (which can be used in the cfg_gettsec() function)
Examples:ftpconf.c, and reread.c.
#defineCFG_SIMPLE_STR(name,svalue)__CFG_STR(name,0,CFGF_NONE,svalue,0)
Initialize a ’simple’ string option.
As of version 2.2, libConfuse can now return the values of simple
options with the cfg_get functions. This allows using the new cfg_print
function with simple options.
libConfuse doesn’t support handling default values for ’simple’
options. They are assumed to be set by the calling application before
cfg_parse is called.
Parameters:name name of the option
svalue pointer to a character pointer (a char **). This value must
be initalized either to NULL or to a malloc()’ed string. You can’t
use
char *user = ’joe’;
...
cfg_opt_t opts[] = {
CFG_SIMPLE_STR(’user’, &user),
...
since libConfuse will try to free the static string ’joe’ (which
is an error) when a ’user’ option is found. Rather, use the
following code snippet:
char *user = strdup(’joe’);
...
cfg_opt_t opts[] = {
CFG_SIMPLE_STR(’user’, &user),
...
Alternatively, the default value can be set after the opts struct
is defined, as in:
char *user = 0;
...
cfg_opt_t opts[] = {
CFG_SIMPLE_STR(’user’, &user),
...
user = strdup(’joe’);
cfg = cfg_init(opts, 0);
cfg_parse(cfg, filename);
Examples:simple.c.
#defineCFG_SUCCESS0
Return codes from cfg_parse().
Examples:ftpconf.c.
Referenced by cfg_parse_buf(), and cfg_parse_fp().
#defineCFGF_NONE0
Flags.
Examples:ftpconf.c, and reread.c.

TypedefDocumentation

typedefint(*cfg_callback_t)(cfg_t*cfg,cfg_opt_t*opt,constchar*value,void*result)
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.
Parameters:cfg The configuration file context.
opt The option.
value The value found in the configuration file.
result Pointer to storage for the result, cast to a void pointer.
Returns:
On success, 0 should be returned. All other values indicates an
error, and the parsing is aborted. The callback function should
notify the error itself, for example by calling cfg_error().
typedefvoid(*cfg_errfunc_t)(cfg_t*cfg,constchar*fmt,va_listap)
Error reporting function.
typedefvoid(*cfg_free_func_t)(void*value)
User-defined memory release function for CFG_PTR values.
This callback is used to free memory allocated in a value parsing
callback function. Especially useful for CFG_PTR options, since
libConfuse will not itself release such values. If the values are
simply allocated with a malloc(3), one can use the standard free(3)
function here.
typedefint(*cfg_func_t)(cfg_t*cfg,cfg_opt_t*opt,intargc,constchar**argv)
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.
Parameters:cfg The configuration file context.
opt The option.
argc Number of arguments passed. The callback function is
responsible for checking that the correct number of arguments are
passed.
argv Arguments as an array of character strings.
Returns:
On success, 0 should be returned. All other values indicates an
error, and the parsing is aborted. The callback function should
notify the error itself, for example by calling cfg_error().
Seealso:CFG_FUNCtypedefvoid(*cfg_print_func_t)(cfg_opt_t*opt,unsignedintindex,FILE*fp)
Function prototype used by the cfg_print_ functions.
This callback function is used to print option values. For options with
a value parsing callback, this is often required, especially if a
string is mapped to an integer by the callback. This print callback
must then map the integer back to the appropriate string.
Except for functions, the print callback function should only print the
value of the option, not the name and the equal sign (that is handled
by the cfg_opt_print function). For function options however, the name
and the parenthesis must be printed by this function. The value to
print can be accessed with the cfg_opt_get functions.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
index Index of the value to get. Zero based.
fp File stream to print to, use stdout to print to the screen.
Seealso:cfg_print, cfg_set_print_functypedefint(*cfg_validate_callback_t)(cfg_t*cfg,cfg_opt_t*opt)
Validating callback prototype.
This callback function is called after an option has been parsed and
set. The function is called for both fundamental values (strings,
integers etc) as well as lists and sections. This can for example be
used to validate that all required options in a section has been set to
sane values.
Returns:
On success, 0 should be returned. All other values indicates an
error, and the parsing is aborted. The callback function should
notify the error itself, for example by calling cfg_error().
Seealso:cfg_set_validate_func

FunctionDocumentation

DLLIMPORTvoid__exportcfg_addlist(cfg_t*cfg,constchar*name,unsignedintnvalues,...)
Add values for a list option.
The new values are appended to any current values in the list.
Parameters:cfg The configuration file context.
name The name of the option.
nvalues Number of values to add.
References CFGF_LIST, and cfg_opt_t::flags.
DLLIMPORTvoid__exportcfg_error(cfg_t*cfg,constchar*fmt,...)
Show a parser error.
Any user-defined error reporting function is called.
Seealso:cfg_set_error_functionExamples:ftpconf.c.
References cfg_t::errfunc, cfg_t::filename, and cfg_t::line.
DLLIMPORTvoid__exportcfg_free(cfg_t*cfg)
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.
Examples:ftpconf.c, reread.c, and simple.c.
References cfg_t::filename, cfg_t::name, cfg_opt_t::name, cfg_t::opts,
and cfg_t::title.
DLLIMPORTvoid__exportcfg_free_value(cfg_opt_t*opt)
Free the memory allocated for the values of a given option.
Only the values are freed, not the option itself (it is freed by
cfg_free()).
Seealso:cfg_free()
References CFGT_PTR, CFGT_SEC, CFGT_STR, cfg_opt_t::freecb,
cfg_opt_t::nvalues, cfg_value_t::ptr, cfg_value_t::section,
cfg_value_t::string, cfg_opt_t::type, and cfg_opt_t::values.
DLLIMPORTcfg_bool_t__exportcfg_getbool(cfg_t*cfg,constchar*name)
Returns the value of a boolean option.
Parameters:cfg The configuration file context.
name The name of the option.
Returns:
The requested value is returned. If the option was not set in the
configuration file, the default value given in the corresponding
cfg_opt_t structure is returned. It is an error to try to get an
option that isn’t declared.
Examples:ftpconf.c.
DLLIMPORTdouble__exportcfg_getfloat(cfg_t*cfg,constchar*name)
Returns the value of a floating point option.
Parameters:cfg The configuration file context.
name The name of the option.
Returns:
The requested value is returned. If the option was not set in the
configuration file, the default value given in the corresponding
cfg_opt_t structure is returned. It is an error to try to get an
option that isn’t declared.
DLLIMPORTlongint__exportcfg_getint(cfg_t*cfg,constchar*name)
Returns the value of an integer option.
This is the same as calling cfg_getnint with index 0.
Parameters:cfg The configuration file context.
name The name of the option.
Returns:
The requested value is returned. If the option was not set in the
configuration file, the default value given in the corresponding
cfg_opt_t structure is returned. It is an error to try to get an
option that isn’t declared.
Examples:ftpconf.c, and reread.c.
DLLIMPORTcfg_bool_t__exportcfg_getnbool(cfg_t*cfg,constchar*name,unsignedintindex)
Indexed version of cfg_getbool(), used for lists.
Parameters:cfg The configuration file context.
name The name of the option.
index Index of the value to get. Zero based.
Seealso:cfg_getboolDLLIMPORTdouble__exportcfg_getnfloat(cfg_t*cfg,constchar*name,unsignedintindex)
Indexed version of cfg_getfloat(), used for lists.
Parameters:cfg The configuration file context.
name The name of the option.
index Index of the value to get. Zero based.
Seealso:cfg_getfloatDLLIMPORTlongint__exportcfg_getnint(cfg_t*cfg,constchar*name,unsignedintindex)
Indexed version of cfg_getint(), used for lists.
Parameters:cfg The configuration file context.
name The name of the option.
index Index of the value to get. Zero based.
Seealso:cfg_getintDLLIMPORTcfg_t*__exportcfg_getnsec(cfg_t*cfg,constchar*name,unsignedintindex)
Indexed version of cfg_getsec(), used for sections with the CFGF_MULTI
flag set.
Parameters:cfg The configuration file context.
name The name of the option.
index Index of the section to get. Zero based.
Seealso:cfg_getsecExamples:ftpconf.c, and reread.c.
DLLIMPORTchar*__exportcfg_getnstr(cfg_t*cfg,constchar*name,unsignedintindex)
Indexed version of cfg_getstr(), used for lists.
Parameters:cfg The configuration file context.
name The name of the option.
index Index of the value to get. Zero based.
Seealso:cfg_getstrExamples:ftpconf.c.
DLLIMPORTcfg_opt_t*__exportcfg_getopt(cfg_t*cfg,constchar*name)
Return an option given it’s name.
Parameters:cfg The configuration file context.
name The name of the option.
Returns:
Returns a pointer to the option. If the option isn’t declared,
libConfuse will print an error message and return 0.
References CFGF_NOCASE, cfg_t::flags, cfg_opt_t::name, cfg_t::name, and
cfg_t::opts.
DLLIMPORTvoid*__exportcfg_getptr(cfg_t*cfg,constchar*name)
Returns the value of a user-defined option (void pointer).
Parameters:cfg The configuration file context.
name The name of the option.
Returns:
The requested value is returned. If the option was not set in the
configuration file, the default value given in the corresponding
cfg_opt_t structure is returned. It is an error to try to get an
option that isn’t declared.
DLLIMPORTcfg_t*__exportcfg_getsec(cfg_t*cfg,constchar*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.
Parameters:cfg The configuration file context.
name The name of the option.
Returns:
The requested section is returned. If no section is found with that
name, 0 is returned. There can only be default values for section
without the CFGF_MULTI flag set. It is an error to try to get a
section that isn’t declared.
DLLIMPORTchar*__exportcfg_getstr(cfg_t*cfg,constchar*name)
Returns the value of a string option.
Parameters:cfg The configuration file context.
name The name of the option.
Returns:
The requested value is returned. If the option was not set in the
configuration file, the default value given in the corresponding
cfg_opt_t structure is returned. It is an error to try to get an
option that isn’t declared.
Examples:ftpconf.c, and reread.c.
DLLIMPORTcfg_t*__exportcfg_gettsec(cfg_t*cfg,constchar*name,constchar*title)
Return a section given the title, used for section with the CFGF_TITLE
flag set.
Parameters:cfg The configuration file context.
name The name of the option.
title The title of this section. The CFGF_TITLE flag must have been
set for this option.
Seealso:cfg_getsecDLLIMPORTint__exportcfg_include(cfg_t*cfg,cfg_opt_t*opt,intargc,constchar**argv)
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)
Examples:ftpconf.c.
DLLIMPORTcfg_t*__exportcfg_init(cfg_opt_t*opts,cfg_flag_tflags)
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
initialized using the CFG_* initializers. The last option in the option
array must be CFG_END(), unless you like segmentation faults.
The options must no longer be defined in the same scope as where the
cfg_xxx functions are used (since version 2.3).
Parameters:opts An arrary of options
flags One or more flags (bitwise or’ed together). Currently only
CFGF_NOCASE is available. Use 0 if no flags are needed.
Returns:
A configuration context structure. This pointer is passed to almost
all other functions as the first parameter.
Examples:ftpconf.c, reread.c, and simple.c.
References cfg_t::errfunc, cfg_t::filename, cfg_t::flags, cfg_t::line,
cfg_t::name, and cfg_t::opts.
DLLIMPORTconstchar*__exportcfg_name(cfg_t*cfg)
Return the name of a section.
Parameters:cfg The configuration file context.
Returns:
Returns the title, or 0 if there is no title. This string should
not be modified.
Examples:ftpconf.c.
References cfg_t::name.
DLLIMPORTcfg_bool_t__exportcfg_opt_getnbool(cfg_opt_t*opt,unsignedintindex)
Returns the value of a boolean option, given a cfg_opt_t pointer.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
index Index of the value to get. Zero based.
Seealso:cfg_getnbool
References cfg_value_t::boolean, CFGT_BOOL, cfg_opt_t::simple_value,
cfg_opt_t::type, and cfg_opt_t::values.
DLLIMPORTdouble__exportcfg_opt_getnfloat(cfg_opt_t*opt,unsignedintindex)
Returns the value of a floating point option, given a cfg_opt_t
pointer.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
index Index of the value to get. Zero based.
Seealso:cfg_getnfloat
References CFGT_FLOAT, cfg_value_t::fpnumber, cfg_opt_t::simple_value,
cfg_opt_t::type, and cfg_opt_t::values.
DLLIMPORTsignedlong__exportcfg_opt_getnint(cfg_opt_t*opt,unsignedintindex)
Returns the value of an integer option, given a cfg_opt_t pointer.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
index Index of the value to get. Zero based.
Seealso:cfg_getnintExamples:ftpconf.c.
References CFGT_INT, cfg_value_t::number, cfg_opt_t::simple_value,
cfg_opt_t::type, and cfg_opt_t::values.
DLLIMPORTcfg_t*__exportcfg_opt_getnsec(cfg_opt_t*opt,unsignedintindex)
Returns the value of a section option, given a cfg_opt_t pointer.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
index Index of the value to get. Zero based.
Seealso:cfg_getnsecExamples:ftpconf.c.
References CFGT_SEC, cfg_value_t::section, cfg_opt_t::type, and
cfg_opt_t::values.
DLLIMPORTchar*__exportcfg_opt_getnstr(cfg_opt_t*opt,unsignedintindex)
Returns the value of a string option, given a cfg_opt_t pointer.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
index Index of the value to get. Zero based.
Seealso:cfg_getnstr
References CFGT_STR, cfg_opt_t::simple_value, cfg_value_t::string,
cfg_opt_t::type, and cfg_opt_t::values.
DLLIMPORTcfg_t*__exportcfg_opt_gettsec(cfg_opt_t*opt,constchar*title)
Returns the value of a section option, given a cfg_opt_t pointer and
the title.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
title The title of this section. The CFGF_TITLE flag must have been
set for this option.
Seealso:cfg_gettsec
References CFGF_NOCASE, CFGF_TITLE, cfg_opt_t::flags, and cfg_t::title.
DLLIMPORTconstchar*__exportcfg_opt_name(cfg_opt_t*opt)
Return the name of an option.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
Returns:
Returns the title, or 0 if there is no title. This string should
not be modified.
Examples:ftpconf.c.
References cfg_opt_t::name.
DLLIMPORTvoid__exportcfg_opt_nprint_var(cfg_opt_t*opt,unsignedintindex,FILE*fp)
Default value print function.
Print only the value of a given option. Does not handle sections or
functions. Use cfg_opt_print to print the whole assignment (’option =
value’), or cfg_print to print the whole config file.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
index The index in the option value array that should be printed
fp File stream to print to.
Seealso:cfg_print, cfg_opt_print
References CFGT_BOOL, CFGT_FLOAT, CFGT_FUNC, CFGT_INT, CFGT_PTR,
CFGT_SEC, CFGT_STR, and cfg_opt_t::type.
DLLIMPORTvoid__exportcfg_opt_print(cfg_opt_t*opt,FILE*fp)
Print an option and its value to a file.
If a print callback function is specified for the option, it is used
instead of cfg_opt_nprint_var.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
fp File stream to print to.
Seealso:cfg_print_func_tDLLIMPORTvoid__exportcfg_opt_print_indent(cfg_opt_t*opt,FILE*fp,intindent)
Print an option and its value to a file.
Same as cfg_opt_print, but with the indentation level specified.
Seealso:cfg_opt_print
References CFGF_LIST, CFGF_TITLE, CFGT_FUNC, CFGT_SEC, CFGT_STR,
cfg_opt_t::flags, cfg_opt_t::name, cfg_opt_t::nvalues, cfg_opt_t::pf,
cfg_opt_t::simple_value, cfg_value_t::string, cfg_opt_t::type, and
cfg_opt_t::values.
DLLIMPORTcfg_print_func_t__exportcfg_opt_set_print_func(cfg_opt_t*opt,cfg_print_func_tpf)
Set a print callback function for an option.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
pf The print function callback.
Seealso:cfg_print_func_t
References cfg_opt_t::pf.
DLLIMPORTvoid__exportcfg_opt_setnbool(cfg_opt_t*opt,cfg_bool_tvalue,unsignedintindex)
Set a value of a boolean option.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
value The value to set.
index The index in the option value array that should be modified.
It is an error to set values with indices larger than 0 for options
without the CFGF_LIST flag set.
References cfg_value_t::boolean, CFGT_BOOL, and cfg_opt_t::type.
DLLIMPORTvoid__exportcfg_opt_setnfloat(cfg_opt_t*opt,doublevalue,unsignedintindex)
Set a value of a floating point option.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
value The value to set.
index The index in the option value array that should be modified.
It is an error to set values with indices larger than 0 for options
without the CFGF_LIST flag set.
References CFGT_FLOAT, cfg_value_t::fpnumber, and cfg_opt_t::type.
DLLIMPORTvoid__exportcfg_opt_setnint(cfg_opt_t*opt,longintvalue,unsignedintindex)
Set a value of an integer option.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
value The value to set.
index The index in the option value array that should be modified.
It is an error to set values with indices larger than 0 for options
without the CFGF_LIST flag set.
References CFGT_INT, cfg_value_t::number, and cfg_opt_t::type.
DLLIMPORTvoid__exportcfg_opt_setnstr(cfg_opt_t*opt,constchar*value,unsignedintindex)
Set a value of a string option.
Parameters:opt The option structure (eg, as returned from cfg_getopt())
value The value to set. Memory for the string is allocated and the
value is copied. Any previous string value is freed.
index The index in the option value array that should be modified.
It is an error to set values with indices larger than 0 for options
without the CFGF_LIST flag set.
References CFGT_STR, cfg_value_t::string, and cfg_opt_t::type.
DLLIMPORTunsignedint__exportcfg_opt_size(cfg_opt_t*opt)
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).
Parameters:opt The option structure (eg, as returned from cfg_getopt())
Examples:ftpconf.c.
References cfg_opt_t::nvalues.
DLLIMPORTint__exportcfg_parse(cfg_t*cfg,constchar*filename)
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.
Parameters:cfg The configuration file context as returned from cfg_init().
filename The name of the file to parse.
Returns:
On success, CFG_SUCCESS is returned. If the file couldn’t be opened
for reading, CFG_FILE_ERROR is returned. On all other errors,
CFG_PARSE_ERROR is returned and cfg_error() was called with a
descriptive error message.
Examples:ftpconf.c, reread.c, and simple.c.
References cfg_t::filename.
DLLIMPORTint__exportcfg_parse_boolean(constchar*s)
Parse a boolean option string.
Accepted ’true’ values are ’true’, ’on’ and ’yes’, and accepted ’false’
values are ’false’, ’off’ and ’no’.
Returns:
Returns 1 or 0 (true/false) if the string was parsed correctly, or
-1 if an error occurred.
DLLIMPORTint__exportcfg_parse_buf(cfg_t*cfg,constchar*buf)
Same as cfg_parse() above, but takes a character buffer as argument.
Parameters:cfg The configuration file context as returned from cfg_init().
buf A zero-terminated string with configuration directives.
Seealso:cfg_parse()Examples:reread.c.
References CFG_SUCCESS, cfg_t::filename, and cfg_t::line.
DLLIMPORTint__exportcfg_parse_fp(cfg_t*cfg,FILE*fp)
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.
Parameters:cfg The configuration file context as returned from cfg_init().
fp An open file stream.
Seealso:cfg_parse()
References CFG_SUCCESS, cfg_t::filename, and cfg_t::line.
DLLIMPORTvoid__exportcfg_print(cfg_t*cfg,FILE*fp)
Print the options and values to a file.
Note that options in any included file are expanded and printed
directly to the file. Option values given with environment variables in
the parsed input are also printed expanded. This means that if you
parse a configuration file you can’t expect that the output from this
function is identical to the initial file.
Parameters:cfg The configuration file context.
fp File stream to print to, use stdout to print to the screen.
Seealso:cfg_print_func_t, cfg_set_print_funcExamples:simple.c.
DLLIMPORTvoid__exportcfg_print_indent(cfg_t*cfg,FILE*fp,intindent)
Print the options and values to a file.
Same as cfg_print, but with the indentation level specified.
Seealso:cfg_print
References cfg_opt_t::name, and cfg_t::opts.
DLLIMPORTcfg_errfunc_t__exportcfg_set_error_function(cfg_t*cfg,cfg_errfunc_terrfunc)
Install a user-defined error reporting function.
Returns:
The old error reporting function is returned.
References cfg_t::errfunc.
DLLIMPORTcfg_print_func_t__exportcfg_set_print_func(cfg_t*cfg,constchar*name,cfg_print_func_tpf)
Set a print callback function for an option given its name.
Parameters:cfg The configuration file context.
name The name of the option.
pf The print callback function.
Seealso:cfg_print_func_tDLLIMPORTcfg_validate_callback_t__exportcfg_set_validate_func(cfg_t*cfg,constchar*name,cfg_validate_callback_tvf)
Register a validating callback function for an option.
Parameters:cfg The configuration file context.
name The name of the option.
vf The validating callback function.
Seealso:cfg_validate_callback_tExamples:ftpconf.c.
References cfg_t::flags, cfg_t::opts, and cfg_opt_t::validcb.
DLLIMPORTvoid__exportcfg_setbool(cfg_t*cfg,constchar*name,cfg_bool_tvalue)
Set the value of a boolean option given its name.
Parameters:cfg The configuration file context.
name The name of the option.
value The value to set. If the option is a list (the CFGF_LIST flag
is set), only the first value (with index 0) is set.
DLLIMPORTvoid__exportcfg_setfloat(cfg_t*cfg,constchar*name,doublevalue)
Set the value of a floating point option given its name.
Parameters:cfg The configuration file context.
name The name of the option.
value The value to set. If the option is a list (the CFGF_LIST flag
is set), only the first value (with index 0) is set.
DLLIMPORTvoid__exportcfg_setint(cfg_t*cfg,constchar*name,longintvalue)
Set the value of an integer option given its name.
Parameters:cfg The configuration file context.
name The name of the option.
value The value to set. If the option is a list (the CFGF_LIST flag
is set), only the first value (with index 0) is set.
DLLIMPORTvoid__exportcfg_setlist(cfg_t*cfg,constchar*name,unsignedintnvalues,...)
Set values for a list option.
All existing values are replaced with the new ones.
Parameters:cfg The configuration file context.
name The name of the option.
nvalues Number of values to set.
References CFGF_LIST, and cfg_opt_t::flags.
DLLIMPORTvoid__exportcfg_setnbool(cfg_t*cfg,constchar*name,cfg_bool_tvalue,unsignedintindex)
Set a value of a boolean option given its name and index.
Parameters:cfg The configuration file context.
name The name of the option.
value The value to set.
index The index in the option value array that should be modified.
It is an error to set values with indices larger than 0 for options
without the CFGF_LIST flag set.
DLLIMPORTvoid__exportcfg_setnfloat(cfg_t*cfg,constchar*name,doublevalue,unsignedintindex)
Set a value of a floating point option given its name and index.
Parameters:cfg The configuration file context.
name The name of the option.
value The value to set.
index The index in the option value array that should be modified.
It is an error to set values with indices larger than 0 for options
without the CFGF_LIST flag set.
DLLIMPORTvoid__exportcfg_setnint(cfg_t*cfg,constchar*name,longintvalue,unsignedintindex)
Set a value of an integer option given its name and index.
Parameters:cfg The configuration file context.
name The name of the option.
value The value to set.
index The index in the option value array that should be modified.
It is an error to set values with indices larger than 0 for options
without the CFGF_LIST flag set.
DLLIMPORTvoid__exportcfg_setnstr(cfg_t*cfg,constchar*name,constchar*value,unsignedintindex)
Set a value of a boolean option given its name and index.
Parameters:cfg The configuration file context.
name The name of the option.
value The value to set. Memory for the string is allocated and the
value is copied. Any privious string value is freed.
index The index in the option value array that should be modified.
It is an error to set values with indices larger than 0 for options
without the CFGF_LIST flag set.
DLLIMPORTcfg_value_t*cfg_setopt(cfg_t*cfg,cfg_opt_t*opt,char*value)
Set an option (create an instance of an option).
Parameters:cfg The configuration file context.
opt The option definition.
value The initial value for the option.
Returns:
Returns a pointer to the value object.
References cfg_value_t::boolean, CFGF_LIST, CFGF_MULTI,
CFGF_NO_TITLE_DUPES, CFGF_NOCASE, CFGF_TITLE, CFGT_BOOL, CFGT_FLOAT,
CFGT_INT, CFGT_PTR, CFGT_SEC, CFGT_STR, cfg_t::errfunc,
cfg_t::filename, cfg_t::flags, cfg_opt_t::flags, cfg_value_t::fpnumber,
cfg_t::line, cfg_t::name, cfg_opt_t::name, cfg_value_t::number,
cfg_opt_t::nvalues, cfg_t::opts, cfg_opt_t::parsecb, cfg_value_t::ptr,
cfg_value_t::section, cfg_opt_t::simple_value, cfg_value_t::string,
cfg_opt_t::subopts, cfg_t::title, cfg_opt_t::type, and
cfg_opt_t::values.
DLLIMPORTvoid__exportcfg_setstr(cfg_t*cfg,constchar*name,constchar*value)
Set the value of a string option given its name.
Parameters:cfg The configuration file context.
name The name of the option.
value The value to set. Memory for the string is allocated and the
value is copied. Any previous string value is freed. If the option
is a list (the CFGF_LIST flag is set), only the first value (with
index 0) is set.
Examples:simple.c.
DLLIMPORTunsignedint__exportcfg_size(cfg_t*cfg,constchar*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).
Note that there is no way to *not* specify a default value for
integers, floats and booleans. Ie, they always have default values
(since 0 or NULL is a valid integer/float/boolean value). Only strings
and lists may have no default value.
Parameters:cfg The configuration file context.
name The name of the option.
Examples:ftpconf.c, and reread.c.
DLLIMPORTchar*__exportcfg_tilde_expand(constchar*filename)
Does tilde expansion (~ -> $HOME) on the filename.
Returns:
The expanded filename is returned. If a ~user was not found, the
original filename is returned. In any case, a dynamically allocated
string is returned, which should be free()’d by the caller.
DLLIMPORTconstchar*__exportcfg_title(cfg_t*cfg)
Return the title of a section.
Parameters:cfg The configuration file context.
Returns:
Returns the title, or 0 if there is no title. This string should
not be modified.
References cfg_t::title.