confuse  3.0
confuse.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002,2003,2007 Martin Hedenfalk <martin@bzero.se>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
36 #ifndef CONFUSE_H_
37 #define CONFUSE_H_
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #include <stdio.h>
44 #include <stdarg.h>
45 
46 #if defined(_WIN32) && !defined(__GNUC__)
47 # ifdef HAVE__FILENO
48 # define fileno _fileno
49 # endif
50 # include <io.h>
51 # ifdef HAVE__ISATTY
52 # define isatty _isatty
53 # endif
54 # ifdef BUILDING_DLL
55 # define DLLIMPORT __declspec (dllexport)
56 # else /* ! BUILDING_DLL */
57 # define DLLIMPORT __declspec (dllimport)
58 # endif /* BUILDING_DLL */
59 #else /* ! _WIN32 || __GNUC__ */
60 # define DLLIMPORT
61 #endif /* _WIN32 */
62 
63 #ifndef __BORLANDC__
64 # define __export
65 #endif
66 
68 enum cfg_type_t {
69  CFGT_NONE,
77 };
78 typedef enum cfg_type_t cfg_type_t;
79 
81 #define CFGF_NONE 0
82 #define CFGF_MULTI 1
83 #define CFGF_LIST 2
84 #define CFGF_NOCASE 4
85 #define CFGF_TITLE 8
86 #define CFGF_NODEFAULT 16
87 #define CFGF_NO_TITLE_DUPES 32
91 #define CFGF_RESET 64
92 #define CFGF_DEFINIT 128
93 #define CFGF_IGNORE_UNKNOWN 256
94 #define CFGF_DEPRECATED 512
95 #define CFGF_DROP 1024
98 #define CFG_SUCCESS 0
99 #define CFG_FAIL -1
100 #define CFG_FILE_ERROR -1
101 #define CFG_PARSE_ERROR 1
102 
103 typedef union cfg_value_t cfg_value_t;
104 typedef union cfg_simple_t cfg_simple_t;
105 typedef struct cfg_opt_t cfg_opt_t;
106 typedef struct cfg_t cfg_t;
107 typedef struct cfg_defvalue_t cfg_defvalue_t;
108 typedef int cfg_flag_t;
109 typedef struct cfg_searchpath_t cfg_searchpath_t;
110 
136 typedef int (*cfg_func_t)(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv);
137 
158 typedef void (*cfg_print_func_t)(cfg_opt_t *opt, unsigned int index, FILE *fp);
159 
181 typedef int (*cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result);
182 
196 typedef int (*cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt);
197 
206 typedef void (*cfg_free_func_t)(void *value);
207 
209 typedef enum { cfg_false, cfg_true } cfg_bool_t;
210 
212 typedef void (*cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap);
213 
218 struct cfg_t {
219  cfg_flag_t flags;
220  char *name;
223  cfg_opt_t *opts;
224  char *title;
226  char *filename;
227  int line;
231  cfg_searchpath_t *path;
232 };
236 union cfg_value_t {
237  long int number;
238  double fpnumber;
240  char *string;
242  void *ptr;
243 };
248 union cfg_simple_t {
249  long int *number;
250  double *fpnumber;
251  cfg_bool_t *boolean;
252  char **string;
253  void **ptr;
254 };
255 
259 struct cfg_defvalue_t {
260  long int number;
261  double fpnumber;
263  const char *string;
264  char *parsed;
267 };
268 
273 struct cfg_opt_t {
274  const char *name;
275  cfg_type_t type;
276  unsigned int nvalues;
278  cfg_flag_t flags;
288  cfg_free_func_t freecb; /***< user-defined memory release function */
289 };
290 
291 extern const char __export confuse_copyright[];
292 extern const char __export confuse_version[];
293 extern const char __export confuse_author[];
294 
295 #define __CFG_STR(name, def, flags, svalue, cb) \
296  {name,CFGT_STR,0,0,flags,0,{0,0,cfg_false,def,0},0,{.string=svalue},cb,0,0,0}
297 #define __CFG_STR_LIST(name, def, flags, svalue, cb) \
298  {name,CFGT_STR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.string=svalue},cb,0,0,0}
299 
302 #define CFG_STR(name, def, flags) \
303  __CFG_STR(name, def, flags, 0, 0)
307 #define CFG_STR_LIST(name, def, flags) \
308  __CFG_STR_LIST(name, def, flags, 0, 0)
312 #define CFG_STR_CB(name, def, flags, cb) \
313  __CFG_STR(name, def, flags, 0, cb)
317 #define CFG_STR_LIST_CB(name, def, flags, cb) \
318  __CFG_STR_LIST(name, def, flags, 0, cb)
372 #define CFG_SIMPLE_STR(name, svalue) \
373  __CFG_STR(name, 0, CFGF_NONE, svalue, 0)
375 
376 #define __CFG_INT(name, def, flags, svalue, cb) \
377  {name,CFGT_INT,0,0,flags,0,{def,0,cfg_false,0,0},0,{.number=svalue},cb,0,0,0}
378 #define __CFG_INT_LIST(name, def, flags, svalue, cb) \
379  {name,CFGT_INT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.number=svalue},cb,0,0,0}
380 
383 #define CFG_INT(name, def, flags) \
384  __CFG_INT(name, def, flags, 0, 0)
388 #define CFG_INT_LIST(name, def, flags) \
389  __CFG_INT_LIST(name, def, flags, 0, 0)
393 #define CFG_INT_CB(name, def, flags, cb) \
394  __CFG_INT(name, def, flags, 0, cb)
398 #define CFG_INT_LIST_CB(name, def, flags, cb) \
399  __CFG_INT_LIST(name, def, flags, 0, cb)
407 #define CFG_SIMPLE_INT(name, svalue) \
408  __CFG_INT(name, 0, CFGF_NONE, svalue, 0)
410 
411 
412 #define __CFG_FLOAT(name, def, flags, svalue, cb) \
413  {name,CFGT_FLOAT,0,0,flags,0,{0,def,cfg_false,0,0},0,{.fpnumber=svalue},cb,0,0,0}
414 #define __CFG_FLOAT_LIST(name, def, flags, svalue, cb) \
415  {name,CFGT_FLOAT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.fpnumber=svalue},cb,0,0,0}
416 
419 #define CFG_FLOAT(name, def, flags) \
420  __CFG_FLOAT(name, def, flags, 0, 0)
424 #define CFG_FLOAT_LIST(name, def, flags) \
425  __CFG_FLOAT_LIST(name, def, flags, 0, 0)
429 #define CFG_FLOAT_CB(name, def, flags, cb) \
430  __CFG_FLOAT(name, def, flags, 0, cb)
434 #define CFG_FLOAT_LIST_CB(name, def, flags, cb) \
435  __CFG_FLOAT_LIST(name, def, flags, 0, cb)
440 #define CFG_SIMPLE_FLOAT(name, svalue) \
441  __CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0)
443 
444 
445 #define __CFG_BOOL(name, def, flags, svalue, cb) \
446  {name,CFGT_BOOL,0,0,flags,0,{0,0,def,0,0},0,{.boolean=svalue},cb,0,0,0}
447 #define __CFG_BOOL_LIST(name, def, flags, svalue, cb) \
448  {name,CFGT_BOOL,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.boolean=svalue},cb,0,0,0}
449 
452 #define CFG_BOOL(name, def, flags) \
453  __CFG_BOOL(name, def, flags, 0, 0)
457 #define CFG_BOOL_LIST(name, def, flags) \
458  __CFG_BOOL_LIST(name, def, flags, 0, 0)
462 #define CFG_BOOL_CB(name, def, flags, cb) \
463  __CFG_BOOL(name, def, flags, 0, cb)
467 #define CFG_BOOL_LIST_CB(name, def, flags, cb) \
468  __CFG_BOOL_LIST(name, def, flags, 0, cb)
473 #define CFG_SIMPLE_BOOL(name, svalue) \
474  __CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0)
476 
477 
489 #define CFG_SEC(name, opts, flags) \
490  {name,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,{0},0,0,0,0}
492 
493 
500 #define CFG_FUNC(name, func) \
501  {name,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,{0},0,0,0,0}
503 
504 #define __CFG_PTR(name, def, flags, svalue, parsecb, freecb) \
505  {name,CFGT_PTR,0,0,flags,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,freecb}
506 #define __CFG_PTR_LIST(name, def, flags, svalue, parsecb, freecb) \
507  {name,CFGT_PTR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,freecb}
508 
521 #define CFG_PTR_CB(name, def, flags, parsecb, freecb) \
522  __CFG_PTR(name, def, flags, 0, parsecb, freecb)
526 #define CFG_PTR_LIST_CB(name, def, flags, parsecb, freecb) \
527  __CFG_PTR(name, def, flags | CFGF_LIST, 0, parsecb, freecb)
529 /*#define CFG_SIMPLE_PTR(name, svalue, cb) \
530  __CFG_PTR(name, 0, 0, svalue, cb)*/
531 
532 
536 #define CFG_END() \
537  {0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,{0},0,0,0,0}
539 
540 
568 DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags);
569 
586 DLLIMPORT int __export cfg_add_searchpath(cfg_t *cfg, const char *dir);
587 
599 DLLIMPORT char *__export cfg_searchpath(cfg_searchpath_t *path, const char *file);
600 
614 DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename);
615 
628 DLLIMPORT int __export cfg_parse_fp(cfg_t *cfg, FILE *fp);
629 
640 DLLIMPORT int __export cfg_parse_buf(cfg_t *cfg, const char *buf);
641 
649 DLLIMPORT int __export cfg_free_value(cfg_opt_t *opt);
650 
656 DLLIMPORT int __export cfg_free(cfg_t *cfg);
657 
661 DLLIMPORT cfg_errfunc_t __export cfg_set_error_function(cfg_t *cfg, cfg_errfunc_t errfunc);
662 
666 DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt, ...);
667 
673 DLLIMPORT signed long __export cfg_opt_getnint(cfg_opt_t *opt, unsigned int index);
674 
681 DLLIMPORT long int __export cfg_getnint(cfg_t *cfg, const char *name, unsigned int index);
682 
692 DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name);
693 
699 DLLIMPORT double __export cfg_opt_getnfloat(cfg_opt_t *opt, unsigned int index);
700 
707 DLLIMPORT double __export cfg_getnfloat(cfg_t *cfg, const char *name, unsigned int index);
708 
717 DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name);
718 
724 DLLIMPORT char *__export cfg_opt_getnstr(cfg_opt_t *opt, unsigned int index);
725 
732 DLLIMPORT char *__export cfg_getnstr(cfg_t *cfg, const char *name, unsigned int index);
733 
742 DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name);
743 
749 DLLIMPORT cfg_bool_t __export cfg_opt_getnbool(cfg_opt_t *opt, unsigned int index);
750 
758 DLLIMPORT cfg_bool_t __export cfg_getnbool(cfg_t *cfg, const char *name, unsigned int index);
759 
768 DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name);
769 
770 
771 DLLIMPORT void *__export cfg_opt_getnptr(cfg_opt_t *opt, unsigned int index);
772 DLLIMPORT void *__export cfg_getnptr(cfg_t *cfg, const char *name, unsigned int indx);
773 
782 DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name);
783 
784 
790 DLLIMPORT cfg_t *__export cfg_opt_getnsec(cfg_opt_t *opt, unsigned int index);
791 
800 DLLIMPORT cfg_t *__export cfg_getnsec(cfg_t *cfg, const char *name, unsigned int index);
801 
809 DLLIMPORT cfg_t *__export cfg_opt_gettsec(cfg_opt_t *opt, const char *title);
810 
820 DLLIMPORT cfg_t *__export cfg_gettsec(cfg_t *cfg, const char *name, const char *title);
821 
832 DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name);
833 
839 DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt);
840 
853 DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name);
854 
861 DLLIMPORT const char *__export cfg_title(cfg_t *cfg);
862 
869 DLLIMPORT const char *__export cfg_name(cfg_t *cfg);
870 
877 DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt);
878 
884 DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv);
885 
892 DLLIMPORT char *__export cfg_tilde_expand(const char *filename);
893 
901 DLLIMPORT int __export cfg_parse_boolean(const char *s);
902 
911 DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name);
912 
921 DLLIMPORT cfg_value_t *cfg_setopt(cfg_t *cfg, cfg_opt_t *opt, const char *value);
922 
933 DLLIMPORT int __export cfg_opt_setnint(cfg_opt_t *opt, long int value, unsigned int index);
934 
944 DLLIMPORT int __export cfg_setint(cfg_t *cfg, const char *name, long int value);
945 
957 DLLIMPORT int __export cfg_setnint(cfg_t *cfg, const char *name, long int value, unsigned int index);
958 
969 DLLIMPORT int __export cfg_opt_setnfloat(cfg_opt_t *opt, double value, unsigned int index);
970 
980 DLLIMPORT int __export cfg_setfloat(cfg_t *cfg, const char *name, double value);
981 
993 DLLIMPORT int __export cfg_setnfloat(cfg_t *cfg, const char *name, double value, unsigned int index);
994 
1005 DLLIMPORT int __export cfg_opt_setnbool(cfg_opt_t *opt, cfg_bool_t value, unsigned int index);
1006 
1016 DLLIMPORT int __export cfg_setbool(cfg_t *cfg, const char *name, cfg_bool_t value);
1017 
1029 DLLIMPORT int __export cfg_setnbool(cfg_t *cfg, const char *name, cfg_bool_t value, unsigned int index);
1030 
1042 DLLIMPORT int __export cfg_opt_setnstr(cfg_opt_t *opt, const char *value, unsigned int index);
1043 
1054 DLLIMPORT int __export cfg_setstr(cfg_t *cfg, const char *name, const char *value);
1055 
1068 DLLIMPORT int __export cfg_setnstr(cfg_t *cfg, const char *name, const char *value, unsigned int index);
1069 
1082 DLLIMPORT int __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues, ...);
1083 
1084 DLLIMPORT int __export cfg_numopts(cfg_opt_t *opts);
1085 
1098 DLLIMPORT int __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues, ...);
1099 
1109 DLLIMPORT int cfg_opt_setmulti(cfg_t *cfg, cfg_opt_t *opt, unsigned int nvalues, char **values);
1110 
1120 DLLIMPORT int cfg_setmulti(cfg_t *cfg, const char *name, unsigned int nvalues, char **values);
1121 
1129 DLLIMPORT int __export cfg_opt_rmnsec(cfg_opt_t *opt, unsigned int index);
1130 
1139 DLLIMPORT int __export cfg_rmnsec(cfg_t *cfg, const char *name, unsigned int index);
1140 
1148 DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name);
1149 
1159 DLLIMPORT int __export cfg_opt_rmtsec(cfg_opt_t *opt, const char *title);
1160 
1172 DLLIMPORT int __export cfg_rmtsec(cfg_t *cfg, const char *name, const char *title);
1173 
1188 DLLIMPORT int __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp);
1189 
1196 DLLIMPORT int __export cfg_opt_print_indent(cfg_opt_t *opt, FILE *fp, int indent);
1197 
1210 DLLIMPORT int __export cfg_opt_print(cfg_opt_t *opt, FILE *fp);
1211 
1218 DLLIMPORT int __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent);
1219 
1235 DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp);
1236 
1245 
1254 DLLIMPORT cfg_print_func_t __export cfg_set_print_func(cfg_t *cfg, const char *name, cfg_print_func_t pf);
1255 
1264 DLLIMPORT cfg_validate_callback_t __export cfg_set_validate_func(cfg_t *cfg, const char *name, cfg_validate_callback_t vf);
1265 
1266 #ifdef __cplusplus
1267 }
1268 #endif
1269 #endif /* CONFUSE_H_ */
1270 
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:281
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:1680
floating point number
Definition: confuse.h:71
cfg_bool_t
Boolean values.
Definition: confuse.h:211
Data structure holding information about an option.
Definition: confuse.h:275
int(* cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt)
Validating callback prototype.
Definition: confuse.h:198
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:1703
const char * name
The name of the option.
Definition: confuse.h:276
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:1629
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:1421
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:1647
cfg_bool_t boolean
default boolean value
Definition: confuse.h:264
DLLIMPORT int __export cfg_opt_print(cfg_opt_t *opt, FILE *fp)
Print an option and its value to a file.
Definition: confuse.c:2027
void * ptr
user-defined value
Definition: confuse.h:244
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:400
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:863
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:1273
unsigned int nvalues
Number of values parsed.
Definition: confuse.h:278
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:1675
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:1713
Data structure holding the default value given by the initialization macros.
Definition: confuse.h:261
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:1854
DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt)
Return the number of values this option has.
Definition: confuse.c:244
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:518
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:296
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:1708
DLLIMPORT int __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent)
Print the options and values to a file.
Definition: confuse.c:2032
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:1652
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:1864
int line
Line number in the config file.
Definition: confuse.h:229
cfg_type_t type
Type of option.
Definition: confuse.h:277
void(* cfg_free_func_t)(void *value)
User-defined memory release function for CFG_PTR values.
Definition: confuse.h:208
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:1897
DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name)
Return the number of values this option has.
Definition: confuse.c:251
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:1393
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:1750
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:894
cfg_print_func_t pf
print callback function
Definition: confuse.h:289
void(* cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap)
Error reporting function.
Definition: confuse.h:214
cfg_opt_t * subopts
Suboptions (only applies to sections)
Definition: confuse.h:281
cfg_value_t ** values
Array of found values.
Definition: confuse.h:279
char * string
string value
Definition: confuse.h:242
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:321
function
Definition: confuse.h:75
Data structure holding information about a "section".
Definition: confuse.h:220
char * name
The name of this section, the root section returned from cfg_init() is always named "root"...
Definition: confuse.h:222
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:381
double fpnumber
default floating point value
Definition: confuse.h:263
DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp)
Print the options and values to a file.
Definition: confuse.c:2042
DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name)
Returns the value of a boolean option.
Definition: confuse.c:326
boolean value
Definition: confuse.h:73
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:306
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:256
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:138
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:921
DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name)
Return an option given it's name.
Definition: confuse.c:171
cfg_callback_t parsecb
Value parsing callback function.
Definition: confuse.h:287
DLLIMPORT int __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Set values for a list option.
Definition: confuse.c:1789
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:1955
cfg_simple_t simple_value
Pointer to user-specified variable to store simple values (created with the CFG_SIMPLE_* initializers...
Definition: confuse.h:284
cfg_searchpath_t * path
Linked list of directories to search.
Definition: confuse.h:233
DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name)
Returns the value of a floating point option.
Definition: confuse.c:301
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:2062
cfg_flag_t flags
Any flags passed to cfg_init()
Definition: confuse.h:221
DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename)
Parse a configuration file.
Definition: confuse.c:1357
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:1824
int(* cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
Value parsing callback prototype.
Definition: confuse.h:183
const char * string
default string value
Definition: confuse.h:265
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:949
long int number
integer value
Definition: confuse.h:239
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:331
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:646
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:271
cfg_defvalue_t def
Default value.
Definition: confuse.h:282
DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name)
Returns the value of a user-defined option (void pointer).
Definition: confuse.c:376
DLLIMPORT int __export cfg_free_value(cfg_opt_t *opt)
Free the memory allocated for the values of a given option.
Definition: confuse.c:1503
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:2131
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:395
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:1328
cfg_validate_callback_t validcb
Value validating callback function.
Definition: confuse.h:288
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:346
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:1745
string
Definition: confuse.h:72
Data structure holding the value of a fundamental option value.
Definition: confuse.h:238
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:2047
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:1657
cfg_bool_t boolean
boolean value
Definition: confuse.h:241
DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name)
Returns the value of an integer option.
Definition: confuse.c:276
char * title
Optional title for this section, only set if CFGF_TITLE flag is set.
Definition: confuse.h:226
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:160
cfg_errfunc_t errfunc
This function (if set with cfg_set_error_function) is called for any error message.
Definition: confuse.h:230
DLLIMPORT int __export cfg_free(cfg_t *cfg)
Free a cfg_t context.
Definition: confuse.c:1559
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:434
DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name)
Returns the value of a section option.
Definition: confuse.c:439
double fpnumber
floating point value
Definition: confuse.h:240
DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt)
Return the name of an option.
Definition: confuse.c:237
char * parsed
default value that is parsed by libConfuse, used for lists and functions
Definition: confuse.h:266
DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name)
Returns the value of a string option.
Definition: confuse.c:351
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:1685
cfg_func_t func
Function callback for CFGT_FUNC options.
Definition: confuse.h:283
long int number
default integer value
Definition: confuse.h:262
char * filename
Name of the file being parsed.
Definition: confuse.h:228
DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name)
Removes and frees a config section.
Definition: confuse.c:1859
Data structure holding the pointer to a user provided variable defined with CFG_SIMPLE_*.
Definition: confuse.h:250
DLLIMPORT const char *__export cfg_title(cfg_t *cfg)
Return the title of a section.
Definition: confuse.c:223
DLLIMPORT const char *__export cfg_name(cfg_t *cfg)
Return the name of a section.
Definition: confuse.c:230
DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
Predefined include-function.
Definition: confuse.c:1586
DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt,...)
Show a parser error.
Definition: confuse.c:964
cfg_flag_t flags
Flags.
Definition: confuse.h:280
DLLIMPORT int __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp)
Default value print function.
Definition: confuse.c:1902
DLLIMPORT char *__export cfg_tilde_expand(const char *filename)
Does tilde expansion (~ -> $HOME) on the filename.
Definition: confuse.c:1456
cfg_t * section
section value
Definition: confuse.h:243
DLLIMPORT int __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Add values for a list option.
Definition: confuse.c:1807
cfg_opt_t * opts
Array of options.
Definition: confuse.h:225