8. Functions

libConfuse supports functions to parse options that does not fit well in the general syntax. Functions can be called with a variable number of arguments. No data from the function or any arguments are stored by libConfuse after the function has run. It is up to the caller to process and/or save the data.

A function is defined with a CFG_FUNC macro. It takes two arguments: the name of the function and a function callback. The callback is defined as:

typedef int (*cfg_func_t)(cfg_t *cfg, cfg_opt_t *opt,
                          int argc, const char **argv);
        

8.1. Predefined functions

Currently there is only one pre-defined function: cfg_include(). This function includes another configuration file. Configuration data is immediately read from the included file, and is returned to the position right after the include() statement upon end of file.

To use this function, include a CFG_FUNC() entry in your options:

cfg_opt_t opts[] = {
    CFG_FUNC("include", cfg_include),
    CFG_END()
};
            

In the configuration file, it is used in the following way:

include("included.conf")