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 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 _cfg_h_
37 #define _cfg_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 
95 #define CFG_SUCCESS 0
96 #define CFG_FILE_ERROR -1
97 #define CFG_PARSE_ERROR 1
98 
99 typedef union cfg_value_t cfg_value_t;
100 typedef struct cfg_opt_t cfg_opt_t;
101 typedef struct cfg_t cfg_t;
102 typedef struct cfg_defvalue_t cfg_defvalue_t;
103 typedef int cfg_flag_t;
104 
130 typedef int (*cfg_func_t)(cfg_t *cfg, cfg_opt_t *opt,
131  int argc, const char **argv);
153 typedef void (*cfg_print_func_t)(cfg_opt_t *opt, unsigned int index, FILE *fp);
154 
176 typedef int (*cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt,
177  const char *value, void *result);
192 typedef int (*cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt);
193 
202 typedef void (*cfg_free_func_t)(void *value);
203 
205 typedef enum {cfg_false, cfg_true} cfg_bool_t;
206 
208 typedef void (*cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap);
209 
214 struct cfg_t {
215  cfg_flag_t flags;
216  char *name;
219  cfg_opt_t *opts;
220  char *title;
222  char *filename;
223  int line;
227 };
228 
231 union cfg_value_t {
232  long int number;
233  double fpnumber;
235  char *string;
237  void *ptr;
238 };
243 struct cfg_defvalue_t {
244  long int number;
245  double fpnumber;
247  char *string;
248  char *parsed;
251 };
252 
257 struct cfg_opt_t {
258  char *name;
259  cfg_type_t type;
260  unsigned int nvalues;
262  cfg_flag_t flags;
266  void *simple_value;
272  cfg_free_func_t freecb; /***< user-defined memory release function */
273 };
274 
275 extern const char __export confuse_copyright[];
276 extern const char __export confuse_version[];
277 extern const char __export confuse_author[];
278 
279 #define __CFG_STR(name, def, flags, svalue, cb) \
280  {name,CFGT_STR,0,0,flags,0,{0,0,cfg_false,def,0},0,svalue,cb,0,0,0}
281 #define __CFG_STR_LIST(name, def, flags, svalue, cb) \
282  {name,CFGT_STR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,svalue,cb,0,0,0}
283 
286 #define CFG_STR(name, def, flags) \
287  __CFG_STR(name, def, flags, 0, 0)
291 #define CFG_STR_LIST(name, def, flags) \
292  __CFG_STR_LIST(name, def, flags, 0, 0)
296 #define CFG_STR_CB(name, def, flags, cb) \
297  __CFG_STR(name, def, flags, 0, cb)
301 #define CFG_STR_LIST_CB(name, def, flags, cb) \
302  __CFG_STR_LIST(name, def, flags, 0, cb)
356 #define CFG_SIMPLE_STR(name, svalue) \
357  __CFG_STR(name, 0, CFGF_NONE, svalue, 0)
359 
360 #define __CFG_INT(name, def, flags, svalue, cb) \
361  {name,CFGT_INT,0,0,flags,0,{def,0,cfg_false,0,0},0,svalue,cb,0,0,0}
362 #define __CFG_INT_LIST(name, def, flags, svalue, cb) \
363  {name,CFGT_INT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,svalue,cb,0,0,0}
364 
367 #define CFG_INT(name, def, flags) \
368  __CFG_INT(name, def, flags, 0, 0)
372 #define CFG_INT_LIST(name, def, flags) \
373  __CFG_INT_LIST(name, def, flags, 0, 0)
377 #define CFG_INT_CB(name, def, flags, cb) \
378  __CFG_INT(name, def, flags, 0, cb)
382 #define CFG_INT_LIST_CB(name, def, flags, cb) \
383  __CFG_INT_LIST(name, def, flags, 0, cb)
388 #define CFG_SIMPLE_INT(name, svalue) \
389  __CFG_INT(name, 0, CFGF_NONE, svalue, 0)
391 
392 
393 #define __CFG_FLOAT(name, def, flags, svalue, cb) \
394  {name,CFGT_FLOAT,0,0,flags,0,{0,def,cfg_false,0,0},0,svalue,cb,0,0,0}
395 #define __CFG_FLOAT_LIST(name, def, flags, svalue, cb) \
396  {name,CFGT_FLOAT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,svalue,cb,0,0,0}
397 
400 #define CFG_FLOAT(name, def, flags) \
401  __CFG_FLOAT(name, def, flags, 0, 0)
405 #define CFG_FLOAT_LIST(name, def, flags) \
406  __CFG_FLOAT_LIST(name, def, flags, 0, 0)
410 #define CFG_FLOAT_CB(name, def, flags, cb) \
411  __CFG_FLOAT(name, def, flags, 0, cb)
415 #define CFG_FLOAT_LIST_CB(name, def, flags, cb) \
416  __CFG_FLOAT_LIST(name, def, flags, 0, cb)
421 #define CFG_SIMPLE_FLOAT(name, svalue) \
422  __CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0)
424 
425 
426 #define __CFG_BOOL(name, def, flags, svalue, cb) \
427  {name,CFGT_BOOL,0,0,flags,0,{0,0,def,0,0},0,svalue,cb,0,0,0}
428 #define __CFG_BOOL_LIST(name, def, flags, svalue, cb) \
429  {name,CFGT_BOOL,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,svalue,cb,0,0,0}
430 
433 #define CFG_BOOL(name, def, flags) \
434  __CFG_BOOL(name, def, flags, 0, 0)
438 #define CFG_BOOL_LIST(name, def, flags) \
439  __CFG_BOOL_LIST(name, def, flags, 0, 0)
443 #define CFG_BOOL_CB(name, def, flags, cb) \
444  __CFG_BOOL(name, def, flags, 0, cb)
448 #define CFG_BOOL_LIST_CB(name, def, flags, cb) \
449  __CFG_BOOL_LIST(name, def, flags, 0, cb)
454 #define CFG_SIMPLE_BOOL(name, svalue) \
455  __CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0)
457 
458 
470 #define CFG_SEC(name, opts, flags) \
471  {name,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,0,0,0,0,0}
473 
474 
481 #define CFG_FUNC(name, func) \
482  {name,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,0,0,0,0,0}
484 
485 #define __CFG_PTR(name, def, flags, svalue, parsecb, freecb) \
486  {name,CFGT_PTR,0,0,flags,0,{0,0,cfg_false,0,def},0,svalue,parsecb,0,0,freecb}
487 #define __CFG_PTR_LIST(name, def, flags, svalue, parsecb, freecb) \
488  {name,CFGT_PTR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,svalue,parsecb,0,0,freecb}
489 
502 #define CFG_PTR_CB(name, def, flags, parsecb, freecb) \
503  __CFG_PTR(name, def, flags, 0, parsecb, freecb)
507 #define CFG_PTR_LIST_CB(name, def, flags, parsecb, freecb) \
508  __CFG_PTR(name, def, flags | CFGF_LIST, 0, parsecb, freecb)
510 /*#define CFG_SIMPLE_PTR(name, svalue, cb) \
511  __CFG_PTR(name, 0, 0, svalue, cb)*/
512 
513 
517 #define CFG_END() \
518  {0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,0,0,0,0,0}
520 
521 
538 DLLIMPORT cfg_t * __export cfg_init(cfg_opt_t *opts, cfg_flag_t flags);
539 
553 DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename);
554 
565 DLLIMPORT int __export cfg_parse_fp(cfg_t *cfg, FILE *fp);
566 
575 DLLIMPORT int __export cfg_parse_buf(cfg_t *cfg, const char *buf);
576 
582 DLLIMPORT void __export cfg_free_value(cfg_opt_t *opt);
583 
587 DLLIMPORT void __export cfg_free(cfg_t *cfg);
588 
592 DLLIMPORT cfg_errfunc_t __export cfg_set_error_function(cfg_t *cfg,
593  cfg_errfunc_t errfunc);
594 
598 DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt, ...);
599 
605 DLLIMPORT signed long __export cfg_opt_getnint(cfg_opt_t *opt, unsigned int index);
606 
613 DLLIMPORT long int __export cfg_getnint(cfg_t *cfg, const char *name,
614  unsigned int index);
615 
625 DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name);
626 
632 DLLIMPORT double __export cfg_opt_getnfloat(cfg_opt_t *opt, unsigned int index);
633 
640 DLLIMPORT double __export cfg_getnfloat(cfg_t *cfg, const char *name,
641  unsigned int index);
642 
651 DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name);
652 
658 DLLIMPORT char * __export cfg_opt_getnstr(cfg_opt_t *opt, unsigned int index);
659 
666 DLLIMPORT char * __export cfg_getnstr(cfg_t *cfg, const char *name,
667  unsigned int index);
668 
677 DLLIMPORT char * __export cfg_getstr(cfg_t *cfg, const char *name);
678 
684 DLLIMPORT cfg_bool_t __export cfg_opt_getnbool(cfg_opt_t *opt, unsigned int index);
685 
693 DLLIMPORT cfg_bool_t __export cfg_getnbool(cfg_t *cfg, const char *name,
694  unsigned int index);
695 
704 DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name);
705 
706 
707 DLLIMPORT void * __export cfg_opt_getnptr(cfg_opt_t *opt, unsigned int index);
708 DLLIMPORT void * __export cfg_getnptr(cfg_t *cfg, const char *name, unsigned int indx);
709 
718 DLLIMPORT void * __export cfg_getptr(cfg_t *cfg, const char *name);
719 
720 
726 DLLIMPORT cfg_t * __export cfg_opt_getnsec(cfg_opt_t *opt, unsigned int index);
727 
736 DLLIMPORT cfg_t * __export cfg_getnsec(cfg_t *cfg, const char *name,
737  unsigned int index);
738 
746 DLLIMPORT cfg_t * __export cfg_opt_gettsec(cfg_opt_t *opt, const char *title);
747 
757 DLLIMPORT cfg_t * __export cfg_gettsec(cfg_t *cfg, const char *name,
758  const char *title);
759 
770 DLLIMPORT cfg_t * __export cfg_getsec(cfg_t *cfg, const char *name);
771 
777 DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt);
778 
791 DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name);
792 
799 DLLIMPORT const char * __export cfg_title(cfg_t *cfg);
800 
807 DLLIMPORT const char * __export cfg_name(cfg_t *cfg);
808 
815 DLLIMPORT const char * __export cfg_opt_name(cfg_opt_t *opt);
816 
822 DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc,
823  const char **argv);
824 
831 DLLIMPORT char * __export cfg_tilde_expand(const char *filename);
832 
840 DLLIMPORT int __export cfg_parse_boolean(const char *s);
841 
850 DLLIMPORT cfg_opt_t * __export cfg_getopt(cfg_t *cfg, const char *name);
851 
860 DLLIMPORT cfg_value_t *cfg_setopt(cfg_t *cfg, cfg_opt_t *opt, char *value);
861 
870 DLLIMPORT void __export cfg_opt_setnint(cfg_opt_t *opt,
871  long int value, unsigned int index);
872 
880 DLLIMPORT void __export cfg_setint(cfg_t *cfg, const char *name,
881  long int value);
882 
892 DLLIMPORT void __export cfg_setnint(cfg_t *cfg, const char *name,
893  long int value, unsigned int index);
894 
903 DLLIMPORT void __export cfg_opt_setnfloat(cfg_opt_t *opt,
904  double value, unsigned int index);
905 
913 DLLIMPORT void __export cfg_setfloat(cfg_t *cfg, const char *name,
914  double value);
915 
925 DLLIMPORT void __export cfg_setnfloat(cfg_t *cfg, const char *name,
926  double value, unsigned int index);
927 
936 DLLIMPORT void __export cfg_opt_setnbool(cfg_opt_t *opt,
937  cfg_bool_t value, unsigned int index);
938 
946 DLLIMPORT void __export cfg_setbool(cfg_t *cfg, const char *name,
947  cfg_bool_t value);
948 
958 DLLIMPORT void __export cfg_setnbool(cfg_t *cfg, const char *name,
959  cfg_bool_t value, unsigned int index);
960 
970 DLLIMPORT void __export cfg_opt_setnstr(cfg_opt_t *opt,
971  const char *value, unsigned int index);
972 
981 DLLIMPORT void __export cfg_setstr(cfg_t *cfg, const char *name,
982  const char *value);
983 
994 DLLIMPORT void __export cfg_setnstr(cfg_t *cfg, const char *name,
995  const char *value, unsigned int index);
996 
1007 DLLIMPORT void __export cfg_setlist(cfg_t *cfg, const char *name,
1008  unsigned int nvalues, ...);
1009 
1010 DLLIMPORT int __export cfg_numopts(cfg_opt_t *opts);
1011 
1022 DLLIMPORT void __export cfg_addlist(cfg_t *cfg, const char *name,
1023  unsigned int nvalues, ...);
1024 
1037 DLLIMPORT void __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index,
1038  FILE *fp);
1039 
1044 DLLIMPORT void __export cfg_opt_print_indent(cfg_opt_t *opt, FILE *fp, int indent);
1045 
1056 DLLIMPORT void __export cfg_opt_print(cfg_opt_t *opt, FILE *fp);
1057 
1062 DLLIMPORT void __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent);
1063 
1077 DLLIMPORT void __export cfg_print(cfg_t *cfg, FILE *fp);
1078 
1086 DLLIMPORT cfg_print_func_t __export cfg_opt_set_print_func(cfg_opt_t *opt,
1087  cfg_print_func_t pf);
1088 
1097 DLLIMPORT cfg_print_func_t __export cfg_set_print_func(cfg_t *cfg, const char *name,
1098  cfg_print_func_t pf);
1099 
1108 DLLIMPORT cfg_validate_callback_t __export cfg_set_validate_func(cfg_t *cfg,
1109  const char *name,
1111 
1112 #ifdef __cplusplus
1113 }
1114 #endif
1115 
1116 #endif
1117 
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:231
floating point number
Definition: confuse.h:71
DLLIMPORT void __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:1300
cfg_bool_t
Boolean values.
Definition: confuse.h:207
Data structure holding information about an option.
Definition: confuse.h:259
DLLIMPORT void __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:1336
DLLIMPORT cfg_value_t * cfg_setopt(cfg_t *cfg, cfg_opt_t *opt, char *value)
Set an option (create an instance of an option).
Definition: confuse.c:531
integer
Definition: confuse.h:70
int(* cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt)
Validating callback prototype.
Definition: confuse.h:194
DLLIMPORT void __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp)
Default value print function.
Definition: confuse.c:1399
DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags)
Create and initialize a cfg_t structure.
Definition: confuse.c:1093
cfg_bool_t boolean
default boolean value
Definition: confuse.h:248
void * ptr
user-defined value
Definition: confuse.h:239
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:330
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:1038
unsigned int nvalues
Number of values parsed.
Definition: confuse.h:262
Data structure holding the default value given by the initialization macros.
Definition: confuse.h:245
char * name
The name of the option.
Definition: confuse.h:260
char * string
default string value
Definition: confuse.h:249
cfg_type_t
Fundamental option types.
Definition: confuse.h:68
DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt)
Return the number of values this option has.
Definition: confuse.c:197
void(* cfg_free_func_t)(void *value)
User-defined memory release function for CFG_PTR values.
Definition: confuse.h:204
void(* cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap)
Error reporting function.
Definition: confuse.h:210
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:409
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:242
DLLIMPORT void __export cfg_setbool(cfg_t *cfg, const char *name, cfg_bool_t value)
Set the value of a boolean option given its name.
Definition: confuse.c:1315
DLLIMPORT void __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:1275
DLLIMPORT void __export cfg_opt_setnint(cfg_opt_t *opt, long int value, unsigned int index)
Set a value of an integer option.
Definition: confuse.c:1260
int line
Line number in the config file.
Definition: confuse.h:225
cfg_type_t type
Type of option.
Definition: confuse.h:261
DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name)
Return the number of values this option has.
Definition: confuse.c:204
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:1073
DLLIMPORT void __export cfg_opt_setnfloat(cfg_opt_t *opt, double value, unsigned int index)
Set a value of a floating point option.
Definition: confuse.c:1280
DLLIMPORT void __export cfg_free_value(cfg_opt_t *opt)
Free the memory allocated for the values of a given option.
Definition: confuse.c:1163
DLLIMPORT void __export cfg_free(cfg_t *cfg)
Free a cfg_t context.
Definition: confuse.c:1205
cfg_print_func_t pf
print callback function
Definition: confuse.h:273
cfg_opt_t * subopts
Suboptions (only applies to sections)
Definition: confuse.h:265
cfg_value_t ** values
Array of found values.
Definition: confuse.h:263
char * string
string value
Definition: confuse.h:237
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:264
function
Definition: confuse.h:75
DLLIMPORT void __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent)
Print the options and values to a file.
Definition: confuse.c:1531
Data structure holding information about a "section".
Definition: confuse.h:216
char * name
The name of this section, the root section returned from cfg_init() is always named "root"...
Definition: confuse.h:218
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:317
double fpnumber
default floating point value
Definition: confuse.h:247
int(* cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
Value parsing callback prototype.
Definition: confuse.h:178
DLLIMPORT void __export cfg_setnint(cfg_t *cfg, const char *name, long int value, unsigned int index)
Set a value of an integer option given its name and index.
Definition: confuse.c:1269
DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name)
Returns the value of a boolean option.
Definition: confuse.c:270
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:253
DLLIMPORT void __export cfg_setnbool(cfg_t *cfg, const char *name, cfg_bool_t value, unsigned int index)
Set a value of a boolean option given its name and index.
Definition: confuse.c:1309
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:209
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:155
DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name)
Return an option given it's name.
Definition: confuse.c:131
cfg_callback_t parsecb
Value parsing callback function.
Definition: confuse.h:271
DLLIMPORT void __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:1444
DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name)
Returns the value of a floating point option.
Definition: confuse.c:248
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:1556
cfg_flag_t flags
Any flags passed to cfg_init()
Definition: confuse.h:217
DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename)
Parse a configuration file.
Definition: confuse.c:1056
DLLIMPORT void __export cfg_setnfloat(cfg_t *cfg, const char *name, double value, unsigned int index)
Set a value of a floating point option given its name and index.
Definition: confuse.c:1289
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:719
long int number
integer value
Definition: confuse.h:234
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:275
DLLIMPORT void __export cfg_setnstr(cfg_t *cfg, const char *name, const char *value, unsigned int index)
Set a value of a boolean option given its name and index.
Definition: confuse.c:1330
DLLIMPORT void __export cfg_print(cfg_t *cfg, FILE *fp)
Print the options and values to a file.
Definition: confuse.c:1539
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:220
cfg_defvalue_t def
Default value.
Definition: confuse.h:266
DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name)
Returns the value of a user-defined option (void pointer).
Definition: confuse.c:312
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:132
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:1627
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:325
cfg_validate_callback_t validcb
Value validating callback function.
Definition: confuse.h:272
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:286
string
Definition: confuse.h:72
Data structure holding the value of a fundamental option value.
Definition: confuse.h:233
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:1544
void * simple_value
Pointer to user-specified variable to store simple values (created with the CFG_SIMPLE_* initializers...
Definition: confuse.h:268
cfg_bool_t boolean
boolean value
Definition: confuse.h:236
DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name)
Returns the value of an integer option.
Definition: confuse.c:226
char * title
Optional title for this section, only set if CFGF_TITLE flag is set.
Definition: confuse.h:222
cfg_errfunc_t errfunc
This function (if set with cfg_set_error_function) is called for any error message.
Definition: confuse.h:226
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:356
DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name)
Returns the value of a section option.
Definition: confuse.c:361
double fpnumber
floating point value
Definition: confuse.h:235
DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt)
Return the name of an option.
Definition: confuse.c:190
char * parsed
default value that is parsed by libConfuse, used for lists and functions
Definition: confuse.h:250
DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name)
Returns the value of a string option.
Definition: confuse.c:291
DLLIMPORT void __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:1295
DLLIMPORT void __export cfg_opt_setnstr(cfg_opt_t *opt, const char *value, unsigned int index)
Set a value of a string option.
Definition: confuse.c:1320
cfg_func_t func
Function callback for CFGT_FUNC options.
Definition: confuse.h:267
long int number
default integer value
Definition: confuse.h:246
DLLIMPORT void __export cfg_opt_print(cfg_opt_t *opt, FILE *fp)
Print an option and its value to a file.
Definition: confuse.c:1526
char * filename
Name of the file being parsed.
Definition: confuse.h:224
DLLIMPORT void __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Add values for a list option.
Definition: confuse.c:1386
DLLIMPORT void __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Set values for a list option.
Definition: confuse.c:1372
DLLIMPORT const char *__export cfg_title(cfg_t *cfg)
Return the title of a section.
Definition: confuse.c:176
DLLIMPORT const char *__export cfg_name(cfg_t *cfg)
Return the name of a section.
Definition: confuse.c:183
DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
Predefined include-function.
Definition: confuse.c:1224
DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt,...)
Show a parser error.
Definition: confuse.c:730
cfg_flag_t flags
Flags.
Definition: confuse.h:264
DLLIMPORT char *__export cfg_tilde_expand(const char *filename)
Does tilde expansion (~ -> $HOME) on the filename.
Definition: confuse.c:1118
cfg_t * section
section value
Definition: confuse.h:238
cfg_opt_t * opts
Array of options.
Definition: confuse.h:221