confuse.h
Go to the documentation of this file.
/*
* Copyright (c) 2002-2017 Martin Hedenfalk <martin@bzero.se>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef CONFUSE_H_
#define CONFUSE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdarg.h>
#if defined(_WIN32) && !defined(__GNUC__)
# ifdef HAVE__FILENO
# define fileno _fileno
# endif
# include <io.h>
# ifdef HAVE__ISATTY
# define isatty _isatty
# endif
# ifdef BUILDING_STATIC
# define DLLIMPORT
# else /* ! BUILDING_STATIC */
# ifdef BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
# else /* ! BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
# endif /* BUILDING_DLL */
# endif /* BUILDING_STATIC */
#else /* ! _WIN32 || __GNUC__ */
# define DLLIMPORT
#endif /* _WIN32 */
#ifndef __BORLANDC__
# define __export
#endif
enum cfg_type_t {
CFGT_NONE,
CFGT_INT,
CFGT_FLOAT,
CFGT_STR,
CFGT_BOOL,
CFGT_SEC,
CFGT_FUNC,
CFGT_PTR,
CFGT_COMMENT
};
typedef enum cfg_type_t cfg_type_t;
#define CFGF_NONE (0)
#define CFGF_MULTI (1 << 0)
#define CFGF_LIST (1 << 1)
#define CFGF_NOCASE (1 << 2)
#define CFGF_TITLE (1 << 3)
#define CFGF_NODEFAULT (1 << 4)
#define CFGF_NO_TITLE_DUPES (1 << 5)
#define CFGF_RESET (1 << 6)
#define CFGF_DEFINIT (1 << 7)
#define CFGF_IGNORE_UNKNOWN (1 << 8)
#define CFGF_DEPRECATED (1 << 9)
#define CFGF_DROP (1 << 10)
#define CFGF_COMMENTS (1 << 11)
#define CFGF_MODIFIED (1 << 12)
#define CFGF_KEYSTRVAL (1 << 13)
#define CFG_SUCCESS 0
#define CFG_FAIL -1
#define CFG_FILE_ERROR -1
#define CFG_PARSE_ERROR 1
typedef union cfg_value_t cfg_value_t;
typedef union cfg_simple_t cfg_simple_t;
typedef struct cfg_opt_t cfg_opt_t;
typedef struct cfg_t cfg_t;
typedef struct cfg_defvalue_t cfg_defvalue_t;
typedef int cfg_flag_t;
typedef struct cfg_searchpath_t cfg_searchpath_t;
typedef int (*cfg_func_t)(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv);
typedef void (*cfg_print_func_t)(cfg_opt_t *opt, unsigned int index, FILE *fp);
typedef int (*cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result);
typedef int (*cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt);
typedef int (*cfg_validate_callback2_t)(cfg_t *cfg, cfg_opt_t *opt, void *value);
typedef void (*cfg_free_func_t)(void *value);
typedef enum { cfg_false, cfg_true } cfg_bool_t;
typedef void (*cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap);
typedef int (*cfg_print_filter_func_t)(cfg_t *cfg, cfg_opt_t *opt);
struct cfg_t {
cfg_flag_t flags;
char *name;
char *comment;
cfg_opt_t *opts;
char *title;
char *filename;
int line;
cfg_errfunc_t errfunc;
cfg_searchpath_t *path;
cfg_print_filter_func_t pff;
};
union cfg_value_t {
long int number;
double fpnumber;
cfg_bool_t boolean;
char *string;
cfg_t *section;
void *ptr;
};
union cfg_simple_t {
long int *number;
double *fpnumber;
cfg_bool_t *boolean;
char **string;
void **ptr;
};
struct cfg_defvalue_t {
long int number;
double fpnumber;
cfg_bool_t boolean;
const char *string;
char *parsed;
};
struct cfg_opt_t {
const char *name;
char *comment;
cfg_type_t type;
unsigned int nvalues;
cfg_value_t **values;
cfg_flag_t flags;
cfg_opt_t *subopts;
cfg_defvalue_t def;
cfg_func_t func;
cfg_simple_t simple_value;
cfg_callback_t parsecb;
cfg_validate_callback_t validcb;
cfg_validate_callback2_t validcb2;
cfg_print_func_t pf;
cfg_free_func_t freecb; /***< user-defined memory release function */
};
extern const char __export confuse_copyright[];
extern const char __export confuse_version[];
extern const char __export confuse_author[];
#define __CFG_STR(name, def, flags, svalue, cb) \
{name,0,CFGT_STR,0,0,flags,0,{0,0,cfg_false,def,0},0,{.string=svalue},cb,0,0,0,0}
#define __CFG_STR_LIST(name, def, flags, svalue, cb) \
{name,0,CFGT_STR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.string=svalue},cb,0,0,0,0}
#define CFG_STR(name, def, flags) \
__CFG_STR(name, def, flags, 0, 0)
#define CFG_STR_LIST(name, def, flags) \
__CFG_STR_LIST(name, def, flags, 0, 0)
#define CFG_STR_CB(name, def, flags, cb) \
__CFG_STR(name, def, flags, 0, cb)
#define CFG_STR_LIST_CB(name, def, flags, cb) \
__CFG_STR_LIST(name, def, flags, 0, cb)
#define CFG_SIMPLE_STR(name, svalue) \
__CFG_STR(name, 0, CFGF_NONE, svalue, 0)
#define __CFG_INT(name, def, flags, svalue, cb) \
{name,0,CFGT_INT,0,0,flags,0,{def,0,cfg_false,0,0},0,{.number=svalue},cb,0,0,0,0}
#define __CFG_INT_LIST(name, def, flags, svalue, cb) \
{name,0,CFGT_INT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.number=svalue},cb,0,0,0,0}
#define CFG_INT(name, def, flags) \
__CFG_INT(name, def, flags, 0, 0)
#define CFG_INT_LIST(name, def, flags) \
__CFG_INT_LIST(name, def, flags, 0, 0)
#define CFG_INT_CB(name, def, flags, cb) \
__CFG_INT(name, def, flags, 0, cb)
#define CFG_INT_LIST_CB(name, def, flags, cb) \
__CFG_INT_LIST(name, def, flags, 0, cb)
#define CFG_SIMPLE_INT(name, svalue) \
__CFG_INT(name, 0, CFGF_NONE, svalue, 0)
#define __CFG_FLOAT(name, def, flags, svalue, cb) \
{name,0,CFGT_FLOAT,0,0,flags,0,{0,def,cfg_false,0,0},0,{.fpnumber=svalue},cb,0,0,0,0}
#define __CFG_FLOAT_LIST(name, def, flags, svalue, cb) \
{name,0,CFGT_FLOAT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.fpnumber=svalue},cb,0,0,0,0}
#define CFG_FLOAT(name, def, flags) \
__CFG_FLOAT(name, def, flags, 0, 0)
#define CFG_FLOAT_LIST(name, def, flags) \
__CFG_FLOAT_LIST(name, def, flags, 0, 0)
#define CFG_FLOAT_CB(name, def, flags, cb) \
__CFG_FLOAT(name, def, flags, 0, cb)
#define CFG_FLOAT_LIST_CB(name, def, flags, cb) \
__CFG_FLOAT_LIST(name, def, flags, 0, cb)
#define CFG_SIMPLE_FLOAT(name, svalue) \
__CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0)
#define __CFG_BOOL(name, def, flags, svalue, cb) \
{name,0,CFGT_BOOL,0,0,flags,0,{0,0,def,0,0},0,{.boolean=svalue},cb,0,0,0,0}
#define __CFG_BOOL_LIST(name, def, flags, svalue, cb) \
{name,0,CFGT_BOOL,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.boolean=svalue},cb,0,0,0,0}
#define CFG_BOOL(name, def, flags) \
__CFG_BOOL(name, def, flags, 0, 0)
#define CFG_BOOL_LIST(name, def, flags) \
__CFG_BOOL_LIST(name, def, flags, 0, 0)
#define CFG_BOOL_CB(name, def, flags, cb) \
__CFG_BOOL(name, def, flags, 0, cb)
#define CFG_BOOL_LIST_CB(name, def, flags, cb) \
__CFG_BOOL_LIST(name, def, flags, 0, cb)
#define CFG_SIMPLE_BOOL(name, svalue) \
__CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0)
#define CFG_SEC(name, opts, flags) \
{name,0,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,{0},0,0,0,0,0}
#define CFG_FUNC(name, func) \
{name,0,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,{0},0,0,0,0,0}
#define __CFG_PTR(name, def, flags, svalue, parsecb, freecb) \
{name,0,CFGT_PTR,0,0,flags,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,0,freecb}
#define __CFG_PTR_LIST(name, def, flags, svalue, parsecb, freecb) \
{name,0,CFGT_PTR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,0,freecb}
#define CFG_PTR_CB(name, def, flags, parsecb, freecb) \
__CFG_PTR(name, def, flags, 0, parsecb, freecb)
#define CFG_PTR_LIST_CB(name, def, flags, parsecb, freecb) \
__CFG_PTR(name, def, flags | CFGF_LIST, 0, parsecb, freecb)
/*#define CFG_SIMPLE_PTR(name, svalue, cb) \
__CFG_PTR(name, 0, 0, svalue, cb)*/
#define CFG_END() \
{0,0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,{0},0,0,0,0,0}
DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags);
DLLIMPORT int __export cfg_add_searchpath(cfg_t *cfg, const char *dir);
DLLIMPORT char *__export cfg_searchpath(cfg_searchpath_t *path, const char *file);
DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename);
DLLIMPORT int __export cfg_parse_fp(cfg_t *cfg, FILE *fp);
DLLIMPORT int __export cfg_parse_buf(cfg_t *cfg, const char *buf);
DLLIMPORT int __export cfg_free_value(cfg_opt_t *opt);
DLLIMPORT int __export cfg_free(cfg_t *cfg);
DLLIMPORT cfg_errfunc_t __export cfg_set_error_function(cfg_t *cfg, cfg_errfunc_t errfunc);
DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt, ...);
DLLIMPORT char * __export cfg_opt_getcomment(cfg_opt_t *opt);
DLLIMPORT char * __export cfg_getcomment(cfg_t *cfg, const char *name);
DLLIMPORT signed long __export cfg_opt_getnint(cfg_opt_t *opt, unsigned int index);
DLLIMPORT long int __export cfg_getnint(cfg_t *cfg, const char *name, unsigned int index);
DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name);
DLLIMPORT double __export cfg_opt_getnfloat(cfg_opt_t *opt, unsigned int index);
DLLIMPORT double __export cfg_getnfloat(cfg_t *cfg, const char *name, unsigned int index);
DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name);
DLLIMPORT char *__export cfg_opt_getnstr(cfg_opt_t *opt, unsigned int index);
DLLIMPORT char *__export cfg_getnstr(cfg_t *cfg, const char *name, unsigned int index);
DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name);
DLLIMPORT cfg_bool_t __export cfg_opt_getnbool(cfg_opt_t *opt, unsigned int index);
DLLIMPORT cfg_bool_t __export cfg_getnbool(cfg_t *cfg, const char *name, unsigned int index);
DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name);
DLLIMPORT void *__export cfg_opt_getnptr(cfg_opt_t *opt, unsigned int index);
DLLIMPORT void *__export cfg_getnptr(cfg_t *cfg, const char *name, unsigned int indx);
DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name);
DLLIMPORT cfg_t *__export cfg_opt_getnsec(cfg_opt_t *opt, unsigned int index);
DLLIMPORT cfg_t *__export cfg_getnsec(cfg_t *cfg, const char *name, unsigned int index);
DLLIMPORT cfg_t *__export cfg_opt_gettsec(cfg_opt_t *opt, const char *title);
DLLIMPORT cfg_t *__export cfg_gettsec(cfg_t *cfg, const char *name, const char *title);
DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name);
DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt);
DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name);
DLLIMPORT const char *__export cfg_title(cfg_t *cfg);
DLLIMPORT const char *__export cfg_name(cfg_t *cfg);
DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt);
DLLIMPORT const char *cfg_opt_getstr(cfg_opt_t *opt);
DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv);
DLLIMPORT char *__export cfg_tilde_expand(const char *filename);
DLLIMPORT int __export cfg_parse_boolean(const char *s);
DLLIMPORT cfg_opt_t *cfg_getnopt(cfg_t *cfg, unsigned int index);
DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name);
DLLIMPORT cfg_value_t *cfg_setopt(cfg_t *cfg, cfg_opt_t *opt, const char *value);
DLLIMPORT int __export cfg_opt_setcomment(cfg_opt_t *opt, char *comment);
DLLIMPORT int __export cfg_setcomment(cfg_t *cfg, const char *name, char *comment);
DLLIMPORT int __export cfg_opt_setnint(cfg_opt_t *opt, long int value, unsigned int index);
DLLIMPORT int __export cfg_setint(cfg_t *cfg, const char *name, long int value);
DLLIMPORT int __export cfg_setnint(cfg_t *cfg, const char *name, long int value, unsigned int index);
DLLIMPORT int __export cfg_opt_setnfloat(cfg_opt_t *opt, double value, unsigned int index);
DLLIMPORT int __export cfg_setfloat(cfg_t *cfg, const char *name, double value);
DLLIMPORT int __export cfg_setnfloat(cfg_t *cfg, const char *name, double value, unsigned int index);
DLLIMPORT int __export cfg_opt_setnbool(cfg_opt_t *opt, cfg_bool_t value, unsigned int index);
DLLIMPORT int __export cfg_setbool(cfg_t *cfg, const char *name, cfg_bool_t value);
DLLIMPORT int __export cfg_setnbool(cfg_t *cfg, const char *name, cfg_bool_t value, unsigned int index);
DLLIMPORT int __export cfg_opt_setnstr(cfg_opt_t *opt, const char *value, unsigned int index);
DLLIMPORT int __export cfg_setstr(cfg_t *cfg, const char *name, const char *value);
DLLIMPORT int __export cfg_setnstr(cfg_t *cfg, const char *name, const char *value, unsigned int index);
DLLIMPORT int __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues, ...);
DLLIMPORT int __export cfg_numopts(cfg_opt_t *opts);
DLLIMPORT unsigned int __export cfg_num(cfg_t *cfg);
DLLIMPORT int __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues, ...);
DLLIMPORT int cfg_opt_setmulti(cfg_t *cfg, cfg_opt_t *opt, unsigned int nvalues, char **values);
DLLIMPORT int cfg_setmulti(cfg_t *cfg, const char *name, unsigned int nvalues, char **values);
DLLIMPORT cfg_t *cfg_addtsec(cfg_t *cfg, const char *name, const char *title);
DLLIMPORT int __export cfg_opt_rmnsec(cfg_opt_t *opt, unsigned int index);
DLLIMPORT int __export cfg_rmnsec(cfg_t *cfg, const char *name, unsigned int index);
DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name);
DLLIMPORT int __export cfg_opt_rmtsec(cfg_opt_t *opt, const char *title);
DLLIMPORT int __export cfg_rmtsec(cfg_t *cfg, const char *name, const char *title);
DLLIMPORT int __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp);
DLLIMPORT int __export cfg_opt_print_indent(cfg_opt_t *opt, FILE *fp, int indent);
DLLIMPORT int __export cfg_opt_print(cfg_opt_t *opt, FILE *fp);
DLLIMPORT int __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent);
DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp);
DLLIMPORT cfg_print_func_t __export cfg_opt_set_print_func(cfg_opt_t *opt, cfg_print_func_t pf);
DLLIMPORT cfg_print_func_t __export cfg_set_print_func(cfg_t *cfg, const char *name, cfg_print_func_t pf);
DLLIMPORT cfg_print_filter_func_t __export cfg_set_print_filter_func(cfg_t *cfg, cfg_print_filter_func_t pff);
DLLIMPORT cfg_validate_callback_t __export cfg_set_validate_func(cfg_t *cfg, const char *name, cfg_validate_callback_t vf);
DLLIMPORT cfg_validate_callback2_t __export cfg_set_validate_func2(cfg_t *cfg, const char *name, cfg_validate_callback2_t vf);
#ifdef __cplusplus
}
#endif
#endif /* CONFUSE_H_ */
cfg_setfloat
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:2133
cfg_set_print_func
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:2568
cfg_parse
DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename)
Parse a configuration file.
Definition: confuse.c:1746
cfg_opt_size
DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt)
Return the number of values this option has.
Definition: confuse.c:399
cfg_validate_callback_t
int(* cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt)
Validating callback prototype.
Definition: confuse.h:203
cfg_free_func_t
void(* cfg_free_func_t)(void *value)
User-defined memory release function for CFG_PTR values.
Definition: confuse.h:229
cfg_print_func_t
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:165
cfg_opt_print_indent
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:2518
cfg_setmulti
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:1127
cfg_errfunc_t
void(* cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap)
Error reporting function.
Definition: confuse.h:235
cfg_setint
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:2098
cfg_rmtsec
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:2386
cfg_opt_set_print_func
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:2553
cfg_searchpath
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:1715
cfg_getopt
DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name)
Return an option given it's name.
Definition: confuse.c:368
cfg_opt_setnstr
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:2167
cfg_opt_getcomment
DLLIMPORT char *__export cfg_opt_getcomment(cfg_opt_t *opt)
Returns the option comment.
Definition: confuse.c:411
cfg_rmnsec
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:2339
cfg_setnint
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:2087
cfg_getfloat
DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name)
Returns the value of a floating point option.
Definition: confuse.c:469
cfg_opt_getnsec
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:549
cfg_opt_setnfloat
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:2103
cfg_getstr
DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name)
Returns the value of a string option.
Definition: confuse.c:519
cfg_free_value
DLLIMPORT int __export cfg_free_value(cfg_opt_t *opt)
Free the memory allocated for the values of a given option.
Definition: confuse.c:1898
cfg_bool_t
cfg_bool_t
Boolean values.
Definition: confuse.h:232
cfg_addlist
DLLIMPORT int __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Add values for a list option.
Definition: confuse.c:2268
cfg_setstr
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:2211
cfg_parse_boolean
DLLIMPORT int __export cfg_parse_boolean(const char *s)
Parse a boolean option string.
Definition: confuse.c:721
cfg_validate_callback2_t
int(* cfg_validate_callback2_t)(cfg_t *cfg, cfg_opt_t *opt, void *value)
Validating callback2 prototype.
Definition: confuse.h:219
cfg_error
DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt,...)
Show a parser error.
Definition: confuse.c:1211
cfg_setnstr
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:2200
cfg_set_print_filter_func
DLLIMPORT cfg_print_filter_func_t __export cfg_set_print_filter_func(cfg_t *cfg, cfg_print_filter_func_t pff)
Install a user-defined print filter function.
Definition: confuse.c:1196
cfg_opt_name
DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt)
Return the name of an option.
Definition: confuse.c:387
cfg_add_searchpath
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:1154
cfg_parse_buf
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:1777
cfg_setopt
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:867
cfg_callback_t
int(* cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
Value parsing callback prototype.
Definition: confuse.h:188
cfg_getcomment
DLLIMPORT char *__export cfg_getcomment(cfg_t *cfg, const char *name)
Returns the option comment.
Definition: confuse.c:419
cfg_include
DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
Predefined include-function.
Definition: confuse.c:1997
cfg_opt_setmulti
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:1093
cfg_func_t
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:143
cfg_setnfloat
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:2122
cfg_opt_setnbool
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:2138
cfg_parse_fp
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:1662
cfg_addtsec
DLLIMPORT cfg_t * cfg_addtsec(cfg_t *cfg, const char *name, const char *title)
Create a new titled config section.
Definition: confuse.c:2285
cfg_getnbool
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:489
cfg_opt_rmnsec
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:2309
cfg_set_validate_func
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:2637
cfg_setlist
DLLIMPORT int __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Set values for a list option.
Definition: confuse.c:2250
cfg_set_validate_func2
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:2652
cfg_opt_nprint_var
DLLIMPORT int __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp)
Default value print function.
Definition: confuse.c:2391
cfg_opt_getnstr
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:499
cfg_getnopt
DLLIMPORT cfg_opt_t * cfg_getnopt(cfg_t *cfg, unsigned int index)
Return the nth option in a file or section.
Definition: confuse.c:353
cfg_type_t
cfg_type_t
Fundamental option types.
Definition: confuse.h:72
CFGT_PTR
@ CFGT_PTR
pointer to user-defined value
Definition: confuse.h:80
CFGT_COMMENT
@ CFGT_COMMENT
comment/annotation
Definition: confuse.h:81
CFGT_FUNC
@ CFGT_FUNC
function
Definition: confuse.h:79
CFGT_BOOL
@ CFGT_BOOL
boolean value
Definition: confuse.h:77
CFGT_SEC
@ CFGT_SEC
section
Definition: confuse.h:78
CFGT_FLOAT
@ CFGT_FLOAT
floating point number
Definition: confuse.h:75
CFGT_STR
@ CFGT_STR
string
Definition: confuse.h:76
CFGT_INT
@ CFGT_INT
integer
Definition: confuse.h:74
cfg_rmsec
DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name)
Removes and frees a config section.
Definition: confuse.c:2344
cfg_getsec
DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name)
Returns the value of a section option.
Definition: confuse.c:595
cfg_opt_getstr
DLLIMPORT const char * cfg_opt_getstr(cfg_opt_t *opt)
Return the string value of a key=value pair.
Definition: confuse.c:394
cfg_num
DLLIMPORT unsigned int __export cfg_num(cfg_t *cfg)
Return number of options in a file or section.
Definition: confuse.c:656
cfg_opt_getnfloat
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:449
cfg_getint
DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name)
Returns the value of an integer option.
Definition: confuse.c:444
cfg_getnstr
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:514
cfg_print_indent
DLLIMPORT int __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent)
Print the options and values to a file.
Definition: confuse.c:2543
cfg_free
DLLIMPORT int __export cfg_free(cfg_t *cfg)
Free a cfg_t context.
Definition: confuse.c:1962
cfg_name
DLLIMPORT const char *__export cfg_name(cfg_t *cfg)
Return the name of a section.
Definition: confuse.c:380
cfg_getnfloat
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:464
cfg_getbool
DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name)
Returns the value of a boolean option.
Definition: confuse.c:494
cfg_opt_rmtsec
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:2353
cfg_setnbool
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:2157
cfg_opt_getnint
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:424
cfg_setcomment
DLLIMPORT int __export cfg_setcomment(cfg_t *cfg, const char *name, char *comment)
Annotate an option given its name.
Definition: confuse.c:2063
cfg_print_filter_func_t
int(* cfg_print_filter_func_t)(cfg_t *cfg, cfg_opt_t *opt)
Print filter function.
Definition: confuse.h:246
cfg_gettsec
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:590
cfg_print
DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp)
Print the options and values to a file.
Definition: confuse.c:2548
cfg_setbool
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:2162
cfg_opt_print
DLLIMPORT int __export cfg_opt_print(cfg_opt_t *opt, FILE *fp)
Print an option and its value to a file.
Definition: confuse.c:2523
cfg_size
DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name)
Return the number of values this option has.
Definition: confuse.c:406
cfg_tilde_expand
DLLIMPORT char *__export cfg_tilde_expand(const char *filename)
Does tilde expansion (~ -> $HOME) on the filename.
Definition: confuse.c:1851
cfg_getptr
DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name)
Returns the value of a user-defined option (void pointer).
Definition: confuse.c:544
cfg_getnsec
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:563
cfg_opt_setnint
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:2068
cfg_getnint
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:439
cfg_opt_gettsec
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:568
cfg_title
DLLIMPORT const char *__export cfg_title(cfg_t *cfg)
Return the title of a section.
Definition: confuse.c:373
cfg_set_error_function
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:1181
cfg_init
DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags)
Create and initialize a cfg_t structure.
Definition: confuse.c:1816
cfg_opt_setcomment
DLLIMPORT int __export cfg_opt_setcomment(cfg_opt_t *opt, char *comment)
Annotate an option.
Definition: confuse.c:2040
cfg_opt_getnbool
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:474
cfg_defvalue_t
Data structure holding the default value given by the initialization macros.
Definition: confuse.h:295
cfg_defvalue_t::number
long int number
default integer value
Definition: confuse.h:296
cfg_defvalue_t::string
const char * string
default string value
Definition: confuse.h:299
cfg_defvalue_t::parsed
char * parsed
default value that is parsed by libConfuse, used for lists and functions
Definition: confuse.h:300
cfg_defvalue_t::boolean
cfg_bool_t boolean
default boolean value
Definition: confuse.h:298
cfg_defvalue_t::fpnumber
double fpnumber
default floating point value
Definition: confuse.h:297
cfg_opt_t
Data structure holding information about an option.
Definition: confuse.h:309
cfg_opt_t::name
const char * name
The name of the option.
Definition: confuse.h:310
cfg_opt_t::type
cfg_type_t type
Type of option.
Definition: confuse.h:312
cfg_opt_t::def
cfg_defvalue_t def
Default value.
Definition: confuse.h:317
cfg_opt_t::parsecb
cfg_callback_t parsecb
Value parsing callback function.
Definition: confuse.h:322
cfg_opt_t::simple_value
cfg_simple_t simple_value
Pointer to user-specified variable to store simple values (created with the CFG_SIMPLE_* initializers...
Definition: confuse.h:319
cfg_opt_t::func
cfg_func_t func
Function callback for CFGT_FUNC options.
Definition: confuse.h:318
cfg_opt_t::validcb2
cfg_validate_callback2_t validcb2
Value validating set callback function.
Definition: confuse.h:324
cfg_opt_t::comment
char * comment
Optional comment/annotation.
Definition: confuse.h:311
cfg_opt_t::validcb
cfg_validate_callback_t validcb
Value validating parsing callback function.
Definition: confuse.h:323
cfg_opt_t::subopts
cfg_opt_t * subopts
Suboptions (only applies to sections)
Definition: confuse.h:316
cfg_opt_t::pf
cfg_print_func_t pf
print callback function
Definition: confuse.h:325
cfg_opt_t::flags
cfg_flag_t flags
Flags.
Definition: confuse.h:315
cfg_opt_t::values
cfg_value_t ** values
Array of found values.
Definition: confuse.h:314
cfg_opt_t::nvalues
unsigned int nvalues
Number of values parsed.
Definition: confuse.h:313
cfg_t
Data structure holding information about a "section".
Definition: confuse.h:252
cfg_t::opts
cfg_opt_t * opts
Array of options.
Definition: confuse.h:258
cfg_t::line
int line
Line number in the config file.
Definition: confuse.h:262
cfg_t::errfunc
cfg_errfunc_t errfunc
This function (if set with cfg_set_error_function) is called for any error message.
Definition: confuse.h:263
cfg_t::name
char * name
The name of this section, the root section returned from cfg_init() is always named "root".
Definition: confuse.h:254
cfg_t::title
char * title
Optional title for this section, only set if CFGF_TITLE flag is set.
Definition: confuse.h:259
cfg_t::pff
cfg_print_filter_func_t pff
Printing filter function.
Definition: confuse.h:267
cfg_t::flags
cfg_flag_t flags
Any flags passed to cfg_init()
Definition: confuse.h:253
cfg_t::comment
char * comment
Optional annotation/comment.
Definition: confuse.h:257
cfg_t::filename
char * filename
Name of the file being parsed.
Definition: confuse.h:261
cfg_t::path
cfg_searchpath_t * path
Linked list of directories to search.
Definition: confuse.h:266
cfg_simple_t
Data structure holding the pointer to a user provided variable defined with CFG_SIMPLE_*.
Definition: confuse.h:284
cfg_value_t
Data structure holding the value of a fundamental option value.
Definition: confuse.h:272
cfg_value_t::ptr
void * ptr
user-defined value
Definition: confuse.h:278
cfg_value_t::section
cfg_t * section
section value
Definition: confuse.h:277
cfg_value_t::string
char * string
string value
Definition: confuse.h:276
cfg_value_t::boolean
cfg_bool_t boolean
boolean value
Definition: confuse.h:275
cfg_value_t::number
long int number
integer value
Definition: confuse.h:273
cfg_value_t::fpnumber
double fpnumber
floating point value
Definition: confuse.h:274