confuse  3.2.2
confuse.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2017 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,
78 };
79 typedef enum cfg_type_t cfg_type_t;
80 
82 #define CFGF_NONE 0
83 #define CFGF_MULTI 1
84 #define CFGF_LIST 2
85 #define CFGF_NOCASE 4
86 #define CFGF_TITLE 8
87 #define CFGF_NODEFAULT 16
88 #define CFGF_NO_TITLE_DUPES 32
92 #define CFGF_RESET 64
93 #define CFGF_DEFINIT 128
94 #define CFGF_IGNORE_UNKNOWN 256
95 #define CFGF_DEPRECATED 512
96 #define CFGF_DROP 1024
97 #define CFGF_COMMENTS 2048
100 #define CFG_SUCCESS 0
101 #define CFG_FAIL -1
102 #define CFG_FILE_ERROR -1
103 #define CFG_PARSE_ERROR 1
104 
105 typedef union cfg_value_t cfg_value_t;
106 typedef union cfg_simple_t cfg_simple_t;
107 typedef struct cfg_opt_t cfg_opt_t;
108 typedef struct cfg_t cfg_t;
109 typedef struct cfg_defvalue_t cfg_defvalue_t;
110 typedef int cfg_flag_t;
111 typedef struct cfg_searchpath_t cfg_searchpath_t;
112 
138 typedef int (*cfg_func_t)(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv);
139 
160 typedef void (*cfg_print_func_t)(cfg_opt_t *opt, unsigned int index, FILE *fp);
161 
183 typedef int (*cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result);
184 
198 typedef int (*cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt);
199 
214 typedef int (*cfg_validate_callback2_t)(cfg_t *cfg, cfg_opt_t *opt, void *value);
215 
224 typedef void (*cfg_free_func_t)(void *value);
225 
227 typedef enum { cfg_false, cfg_true } cfg_bool_t;
228 
230 typedef void (*cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap);
231 
236 struct cfg_t {
237  cfg_flag_t flags;
238  char *name;
241  char *comment;
242  cfg_opt_t *opts;
243  char *title;
245  char *filename;
246  int line;
250  cfg_searchpath_t *path;
251 };
252 
255 union cfg_value_t {
256  long int number;
257  double fpnumber;
259  char *string;
261  void *ptr;
262 };
263 
267 union cfg_simple_t {
268  long int *number;
269  double *fpnumber;
270  cfg_bool_t *boolean;
271  char **string;
272  void **ptr;
273 };
274 
278 struct cfg_defvalue_t {
279  long int number;
280  double fpnumber;
282  const char *string;
283  char *parsed;
286 };
287 
292 struct cfg_opt_t {
293  const char *name;
294  char *comment;
296  unsigned int nvalues;
298  cfg_flag_t flags;
309  cfg_free_func_t freecb; /***< user-defined memory release function */
310 };
311 
312 extern const char __export confuse_copyright[];
313 extern const char __export confuse_version[];
314 extern const char __export confuse_author[];
315 
316 #define __CFG_STR(name, def, flags, svalue, cb) \
317  {name,0,CFGT_STR,0,0,flags,0,{0,0,cfg_false,def,0},0,{.string=svalue},cb,0,0,0,0}
318 #define __CFG_STR_LIST(name, def, flags, svalue, cb) \
319  {name,0,CFGT_STR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.string=svalue},cb,0,0,0,0}
320 
323 #define CFG_STR(name, def, flags) \
324  __CFG_STR(name, def, flags, 0, 0)
325 
328 #define CFG_STR_LIST(name, def, flags) \
329  __CFG_STR_LIST(name, def, flags, 0, 0)
330 
333 #define CFG_STR_CB(name, def, flags, cb) \
334  __CFG_STR(name, def, flags, 0, cb)
335 
338 #define CFG_STR_LIST_CB(name, def, flags, cb) \
339  __CFG_STR_LIST(name, def, flags, 0, cb)
340 
393 #define CFG_SIMPLE_STR(name, svalue) \
394  __CFG_STR(name, 0, CFGF_NONE, svalue, 0)
395 
396 
397 #define __CFG_INT(name, def, flags, svalue, cb) \
398  {name,0,CFGT_INT,0,0,flags,0,{def,0,cfg_false,0,0},0,{.number=svalue},cb,0,0,0,0}
399 #define __CFG_INT_LIST(name, def, flags, svalue, cb) \
400  {name,0,CFGT_INT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.number=svalue},cb,0,0,0,0}
401 
404 #define CFG_INT(name, def, flags) \
405  __CFG_INT(name, def, flags, 0, 0)
406 
409 #define CFG_INT_LIST(name, def, flags) \
410  __CFG_INT_LIST(name, def, flags, 0, 0)
411 
414 #define CFG_INT_CB(name, def, flags, cb) \
415  __CFG_INT(name, def, flags, 0, cb)
416 
419 #define CFG_INT_LIST_CB(name, def, flags, cb) \
420  __CFG_INT_LIST(name, def, flags, 0, cb)
421 
428 #define CFG_SIMPLE_INT(name, svalue) \
429  __CFG_INT(name, 0, CFGF_NONE, svalue, 0)
430 
431 
432 
433 #define __CFG_FLOAT(name, def, flags, svalue, cb) \
434  {name,0,CFGT_FLOAT,0,0,flags,0,{0,def,cfg_false,0,0},0,{.fpnumber=svalue},cb,0,0,0,0}
435 #define __CFG_FLOAT_LIST(name, def, flags, svalue, cb) \
436  {name,0,CFGT_FLOAT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.fpnumber=svalue},cb,0,0,0,0}
437 
440 #define CFG_FLOAT(name, def, flags) \
441  __CFG_FLOAT(name, def, flags, 0, 0)
442 
445 #define CFG_FLOAT_LIST(name, def, flags) \
446  __CFG_FLOAT_LIST(name, def, flags, 0, 0)
447 
450 #define CFG_FLOAT_CB(name, def, flags, cb) \
451  __CFG_FLOAT(name, def, flags, 0, cb)
452 
455 #define CFG_FLOAT_LIST_CB(name, def, flags, cb) \
456  __CFG_FLOAT_LIST(name, def, flags, 0, cb)
457 
461 #define CFG_SIMPLE_FLOAT(name, svalue) \
462  __CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0)
463 
464 
465 
466 #define __CFG_BOOL(name, def, flags, svalue, cb) \
467  {name,0,CFGT_BOOL,0,0,flags,0,{0,0,def,0,0},0,{.boolean=svalue},cb,0,0,0,0}
468 #define __CFG_BOOL_LIST(name, def, flags, svalue, cb) \
469  {name,0,CFGT_BOOL,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.boolean=svalue},cb,0,0,0,0}
470 
473 #define CFG_BOOL(name, def, flags) \
474  __CFG_BOOL(name, def, flags, 0, 0)
475 
478 #define CFG_BOOL_LIST(name, def, flags) \
479  __CFG_BOOL_LIST(name, def, flags, 0, 0)
480 
483 #define CFG_BOOL_CB(name, def, flags, cb) \
484  __CFG_BOOL(name, def, flags, 0, cb)
485 
488 #define CFG_BOOL_LIST_CB(name, def, flags, cb) \
489  __CFG_BOOL_LIST(name, def, flags, 0, cb)
490 
494 #define CFG_SIMPLE_BOOL(name, svalue) \
495  __CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0)
496 
497 
498 
510 #define CFG_SEC(name, opts, flags) \
511  {name,0,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,{0},0,0,0,0,0}
512 
513 
514 
521 #define CFG_FUNC(name, func) \
522  {name,0,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,{0},0,0,0,0,0}
523 
524 
525 #define __CFG_PTR(name, def, flags, svalue, parsecb, freecb) \
526  {name,0,CFGT_PTR,0,0,flags,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,0,freecb}
527 #define __CFG_PTR_LIST(name, def, flags, svalue, parsecb, freecb) \
528  {name,0,CFGT_PTR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,0,freecb}
529 
542 #define CFG_PTR_CB(name, def, flags, parsecb, freecb) \
543  __CFG_PTR(name, def, flags, 0, parsecb, freecb)
544 
547 #define CFG_PTR_LIST_CB(name, def, flags, parsecb, freecb) \
548  __CFG_PTR(name, def, flags | CFGF_LIST, 0, parsecb, freecb)
549 
550 /*#define CFG_SIMPLE_PTR(name, svalue, cb) \
551  __CFG_PTR(name, 0, 0, svalue, cb)*/
552 
553 
557 #define CFG_END() \
558  {0,0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,{0},0,0,0,0,0}
559 
560 
561 
589 DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags);
590 
607 DLLIMPORT int __export cfg_add_searchpath(cfg_t *cfg, const char *dir);
608 
620 DLLIMPORT char *__export cfg_searchpath(cfg_searchpath_t *path, const char *file);
621 
635 DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename);
636 
649 DLLIMPORT int __export cfg_parse_fp(cfg_t *cfg, FILE *fp);
650 
661 DLLIMPORT int __export cfg_parse_buf(cfg_t *cfg, const char *buf);
662 
670 DLLIMPORT int __export cfg_free_value(cfg_opt_t *opt);
671 
677 DLLIMPORT int __export cfg_free(cfg_t *cfg);
678 
682 DLLIMPORT cfg_errfunc_t __export cfg_set_error_function(cfg_t *cfg, cfg_errfunc_t errfunc);
683 
687 DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt, ...);
688 
693 DLLIMPORT char * __export cfg_opt_getcomment(cfg_opt_t *opt);
694 
705 DLLIMPORT char * __export cfg_getcomment(cfg_t *cfg, const char *name);
706 
712 DLLIMPORT signed long __export cfg_opt_getnint(cfg_opt_t *opt, unsigned int index);
713 
720 DLLIMPORT long int __export cfg_getnint(cfg_t *cfg, const char *name, unsigned int index);
721 
731 DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name);
732 
738 DLLIMPORT double __export cfg_opt_getnfloat(cfg_opt_t *opt, unsigned int index);
739 
746 DLLIMPORT double __export cfg_getnfloat(cfg_t *cfg, const char *name, unsigned int index);
747 
756 DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name);
757 
763 DLLIMPORT char *__export cfg_opt_getnstr(cfg_opt_t *opt, unsigned int index);
764 
771 DLLIMPORT char *__export cfg_getnstr(cfg_t *cfg, const char *name, unsigned int index);
772 
781 DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name);
782 
788 DLLIMPORT cfg_bool_t __export cfg_opt_getnbool(cfg_opt_t *opt, unsigned int index);
789 
797 DLLIMPORT cfg_bool_t __export cfg_getnbool(cfg_t *cfg, const char *name, unsigned int index);
798 
807 DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name);
808 
809 
810 DLLIMPORT void *__export cfg_opt_getnptr(cfg_opt_t *opt, unsigned int index);
811 DLLIMPORT void *__export cfg_getnptr(cfg_t *cfg, const char *name, unsigned int indx);
812 
821 DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name);
822 
823 
829 DLLIMPORT cfg_t *__export cfg_opt_getnsec(cfg_opt_t *opt, unsigned int index);
830 
839 DLLIMPORT cfg_t *__export cfg_getnsec(cfg_t *cfg, const char *name, unsigned int index);
840 
848 DLLIMPORT cfg_t *__export cfg_opt_gettsec(cfg_opt_t *opt, const char *title);
849 
859 DLLIMPORT cfg_t *__export cfg_gettsec(cfg_t *cfg, const char *name, const char *title);
860 
871 DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name);
872 
878 DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt);
879 
892 DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name);
893 
900 DLLIMPORT const char *__export cfg_title(cfg_t *cfg);
901 
908 DLLIMPORT const char *__export cfg_name(cfg_t *cfg);
909 
916 DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt);
917 
923 DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv);
924 
931 DLLIMPORT char *__export cfg_tilde_expand(const char *filename);
932 
940 DLLIMPORT int __export cfg_parse_boolean(const char *s);
941 
950 DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name);
951 
960 DLLIMPORT cfg_value_t *cfg_setopt(cfg_t *cfg, cfg_opt_t *opt, const char *value);
961 
968 DLLIMPORT int __export cfg_opt_setcomment(cfg_opt_t *opt, char *comment);
969 
988 DLLIMPORT int __export cfg_setcomment(cfg_t *cfg, const char *name, char *comment);
989 
1000 DLLIMPORT int __export cfg_opt_setnint(cfg_opt_t *opt, long int value, unsigned int index);
1001 
1011 DLLIMPORT int __export cfg_setint(cfg_t *cfg, const char *name, long int value);
1012 
1024 DLLIMPORT int __export cfg_setnint(cfg_t *cfg, const char *name, long int value, unsigned int index);
1025 
1036 DLLIMPORT int __export cfg_opt_setnfloat(cfg_opt_t *opt, double value, unsigned int index);
1037 
1047 DLLIMPORT int __export cfg_setfloat(cfg_t *cfg, const char *name, double value);
1048 
1060 DLLIMPORT int __export cfg_setnfloat(cfg_t *cfg, const char *name, double value, unsigned int index);
1061 
1072 DLLIMPORT int __export cfg_opt_setnbool(cfg_opt_t *opt, cfg_bool_t value, unsigned int index);
1073 
1083 DLLIMPORT int __export cfg_setbool(cfg_t *cfg, const char *name, cfg_bool_t value);
1084 
1096 DLLIMPORT int __export cfg_setnbool(cfg_t *cfg, const char *name, cfg_bool_t value, unsigned int index);
1097 
1109 DLLIMPORT int __export cfg_opt_setnstr(cfg_opt_t *opt, const char *value, unsigned int index);
1110 
1121 DLLIMPORT int __export cfg_setstr(cfg_t *cfg, const char *name, const char *value);
1122 
1135 DLLIMPORT int __export cfg_setnstr(cfg_t *cfg, const char *name, const char *value, unsigned int index);
1136 
1149 DLLIMPORT int __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues, ...);
1150 
1151 DLLIMPORT int __export cfg_numopts(cfg_opt_t *opts);
1152 
1165 DLLIMPORT int __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues, ...);
1166 
1176 DLLIMPORT int cfg_opt_setmulti(cfg_t *cfg, cfg_opt_t *opt, unsigned int nvalues, char **values);
1177 
1187 DLLIMPORT int cfg_setmulti(cfg_t *cfg, const char *name, unsigned int nvalues, char **values);
1188 
1199 DLLIMPORT cfg_t *cfg_addtsec(cfg_t *cfg, const char *name, const char *title);
1200 
1208 DLLIMPORT int __export cfg_opt_rmnsec(cfg_opt_t *opt, unsigned int index);
1209 
1218 DLLIMPORT int __export cfg_rmnsec(cfg_t *cfg, const char *name, unsigned int index);
1219 
1227 DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name);
1228 
1238 DLLIMPORT int __export cfg_opt_rmtsec(cfg_opt_t *opt, const char *title);
1239 
1251 DLLIMPORT int __export cfg_rmtsec(cfg_t *cfg, const char *name, const char *title);
1252 
1267 DLLIMPORT int __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp);
1268 
1275 DLLIMPORT int __export cfg_opt_print_indent(cfg_opt_t *opt, FILE *fp, int indent);
1276 
1289 DLLIMPORT int __export cfg_opt_print(cfg_opt_t *opt, FILE *fp);
1290 
1297 DLLIMPORT int __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent);
1298 
1314 DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp);
1315 
1324 
1333 DLLIMPORT cfg_print_func_t __export cfg_set_print_func(cfg_t *cfg, const char *name, cfg_print_func_t pf);
1334 
1343 DLLIMPORT cfg_validate_callback_t __export cfg_set_validate_func(cfg_t *cfg, const char *name, cfg_validate_callback_t vf);
1344 
1358 DLLIMPORT cfg_validate_callback2_t __export cfg_set_validate_func2(cfg_t *cfg, const char *name, cfg_validate_callback2_t vf);
1359 
1360 #ifdef __cplusplus
1361 }
1362 #endif
1363 #endif /* CONFUSE_H_ */
1364 
CFGF_NOCASE
#define CFGF_NOCASE
configuration file is case insensitive
Definition: confuse.h:85
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:1826
cfg_defvalue_t::number
long int number
default integer value
Definition: confuse.h:281
cfg_rmsec
DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name)
Removes and frees a config section.
Definition: confuse.c:2098
cfg_opt_t::type
cfg_type_t type
Type of option.
Definition: confuse.h:297
cfg_defvalue_t::boolean
cfg_bool_t boolean
default boolean value
Definition: confuse.h:283
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:1575
CFGF_LIST
#define CFGF_LIST
option is a list
Definition: confuse.h:84
cfg_value_t
Data structure holding the value of a fundamental option value.
Definition: confuse.h:257
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:2272
CFGF_NODEFAULT
#define CFGF_NODEFAULT
option has no default value
Definition: confuse.h:87
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:1878
cfg_validate_callback_t
int(* cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt)
Validating callback prototype.
Definition: confuse.h:200
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:1756
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:1912
cfg_t::filename
char * filename
Name of the file being parsed.
Definition: confuse.h:247
cfg_validate_callback2_t
int(* cfg_validate_callback2_t)(cfg_t *cfg, cfg_opt_t *opt, void *value)
Validating callback2 prototype.
Definition: confuse.h:216
cfg_type_t
cfg_type_t
Fundamental option types.
Definition: confuse.h:68
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:2141
cfg_defvalue_t
Data structure holding the default value given by the initialization macros.
Definition: confuse.h:280
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:2022
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:248
cfg_parse_boolean
DLLIMPORT int __export cfg_parse_boolean(const char *s)
Parse a boolean option string.
Definition: confuse.c:520
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:1965
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:1844
CFG_STR
#define CFG_STR(name, def, flags)
Initialize a string option.
Definition: confuse.h:325
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:2277
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:1855
cfg_opt_t::def
cfg_defvalue_t def
Default value.
Definition: confuse.h:302
CFGF_COMMENTS
#define CFGF_COMMENTS
Enable option annotation/comments support.
Definition: confuse.h:99
cfg_free_func_t
void(* cfg_free_func_t)(void *value)
User-defined memory release function for CFG_PTR values.
Definition: confuse.h:226
confuse.h
A configuration file parser library.
CFGT_BOOL
boolean value
Definition: confuse.h:73
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:241
CFGF_TITLE
#define CFGF_TITLE
option has a title (only applies to sections)
Definition: confuse.h:86
cfg_opt_t::parsecb
cfg_callback_t parsecb
Value parsing callback function.
Definition: confuse.h:307
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:915
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:1917
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:410
cfg_opt_t::name
const char * name
The name of the option.
Definition: confuse.h:295
cfg_opt_t::validcb2
cfg_validate_callback2_t validcb2
Value validating set callback function.
Definition: confuse.h:309
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:2093
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:2136
CFGT_PTR
pointer to user-defined value
Definition: confuse.h:76
cfg_t::flags
cfg_flag_t flags
Any flags passed to cfg_init()
Definition: confuse.h:239
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:1536
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:266
cfg_t::title
char * title
Optional title for this section, only set if CFGF_TITLE flag is set.
Definition: confuse.h:245
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:306
cfg_defvalue_t::fpnumber
double fpnumber
default floating point value
Definition: confuse.h:282
cfg_t::opts
cfg_opt_t * opts
Array of options.
Definition: confuse.h:244
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:2103
CFGF_DEPRECATED
#define CFGF_DEPRECATED
option is deprecated and should be ignored.
Definition: confuse.h:97
cfg_value_t::ptr
void * ptr
user-defined value
Definition: confuse.h:263
cfg_defvalue_t::string
const char * string
default string value
Definition: confuse.h:284
cfg_opt_getcomment
DLLIMPORT char *__export cfg_opt_getcomment(cfg_opt_t *opt)
Returns the option comment.
Definition: confuse.c:253
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:341
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:2004
cfg_title
const DLLIMPORT char *__export cfg_title(cfg_t *cfg)
Return the title of a section.
Definition: confuse.c:220
cfg_opt_t::nvalues
unsigned int nvalues
Number of values parsed.
Definition: confuse.h:298
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:391
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:665
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:281
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:2039
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:1657
cfg_errfunc_t
void(* cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap)
Error reporting function.
Definition: confuse.h:232
cfg_getfloat
DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name)
Returns the value of a floating point option.
Definition: confuse.c:311
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:2307
CFGT_COMMENT
comment/annotation
Definition: confuse.h:77
CFGF_IGNORE_UNKNOWN
#define CFGF_IGNORE_UNKNOWN
ignore unknown options in configuration files
Definition: confuse.h:96
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:2376
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:331
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:405
cfg_setcomment
DLLIMPORT int __export cfg_setcomment(cfg_t *cfg, const char *name, char *comment)
Annotate an option given its name.
Definition: confuse.c:1821
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:356
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:942
cfg_getcomment
DLLIMPORT char *__export cfg_getcomment(cfg_t *cfg, const char *name)
Returns the option comment.
Definition: confuse.c:261
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:168
cfg_value_t::number
long int number
integer value
Definition: confuse.h:258
cfg_opt_t::validcb
cfg_validate_callback_t validcb
Value validating parsing callback function.
Definition: confuse.h:308
cfg_opt_t::subopts
cfg_opt_t * subopts
Suboptions (only applies to sections)
Definition: confuse.h:301
cfg_opt_t::flags
cfg_flag_t flags
Flags.
Definition: confuse.h:300
CFGT_STR
string
Definition: confuse.h:72
cfg_print
DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp)
Print the options and values to a file.
Definition: confuse.c:2287
cfg_value_t::section
cfg_t * section
section value
Definition: confuse.h:262
cfg_parse
DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename)
Parse a configuration file.
Definition: confuse.c:1505
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:2063
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:336
cfg_opt_t
Data structure holding information about an option.
Definition: confuse.h:294
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:1474
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:316
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:185
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:140
CFGF_DROP
#define CFGF_DROP
option should be dropped after parsing
Definition: confuse.h:98
CFGT_FUNC
function
Definition: confuse.h:75
cfg_t::line
int line
Line number in the config file.
Definition: confuse.h:248
cfg_defvalue_t::parsed
char * parsed
default value that is parsed by libConfuse, used for lists and functions
Definition: confuse.h:285
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:2195
cfg_value_t::boolean
cfg_bool_t boolean
boolean value
Definition: confuse.h:260
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:2292
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:386
cfg_opt_name
const DLLIMPORT char *__export cfg_opt_name(cfg_opt_t *opt)
Return the name of an option.
Definition: confuse.c:234
cfg_t::comment
char * comment
Optional annotation/comment.
Definition: confuse.h:243
cfg_value_t::fpnumber
double fpnumber
floating point value
Definition: confuse.h:259
cfg_opt_t::values
cfg_value_t ** values
Array of found values.
Definition: confuse.h:299
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:162
cfg_simple_t
Data structure holding the pointer to a user provided variable defined with CFG_SIMPLE_*.
Definition: confuse.h:269
cfg_name
const DLLIMPORT char *__export cfg_name(cfg_t *cfg)
Return the name of a section.
Definition: confuse.c:227
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:969
cfg_t::path
cfg_searchpath_t * path
Linked list of directories to search.
Definition: confuse.h:252
CFGF_MULTI
#define CFGF_MULTI
option may be specified multiple times (only applies to sections)
Definition: confuse.h:83
cfg_opt_t::func
cfg_func_t func
Function callback for CFGT_FUNC options.
Definition: confuse.h:303
CFGF_NO_TITLE_DUPES
#define CFGF_NO_TITLE_DUPES
multiple section titles must be unique (duplicates raises an error, only applies to sections)
Definition: confuse.h:88
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:1894
cfg_t
Data structure holding information about a "section".
Definition: confuse.h:238
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:1860
cfg_getint
DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name)
Returns the value of an integer option.
Definition: confuse.c:286
cfg_t::name
char * name
The name of this section, the root section returned from cfg_init() is always named "root".
Definition: confuse.h:240
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:249
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:2391
cfg_free
DLLIMPORT int __export cfg_free(cfg_t *cfg)
Free a cfg_t context.
Definition: confuse.c:1721
CFG_SUCCESS
#define CFG_SUCCESS
Return codes from cfg_parse(), cfg_parse_boolean(), and cfg_set*() functions.
Definition: confuse.h:102
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:1954
cfg_getstr
DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name)
Returns the value of a string option.
Definition: confuse.c:361
cfg_opt_setcomment
DLLIMPORT int __export cfg_opt_setcomment(cfg_opt_t *opt, char *comment)
Annotate an option.
Definition: confuse.c:1799
cfg_value_t::string
char * string
string value
Definition: confuse.h:261
CFGT_SEC
section
Definition: confuse.h:74
cfg_tilde_expand
DLLIMPORT char *__export cfg_tilde_expand(const char *filename)
Does tilde expansion (~ -> $HOME) on the filename.
Definition: confuse.c:1610
cfg_opt_t::comment
char * comment
Optional comment/annotation.
Definition: confuse.h:296
cfg_opt_t::pf
cfg_print_func_t pf
print callback function
Definition: confuse.h:310
CFGT_INT
integer
Definition: confuse.h:70
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:1889
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:291
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:304
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:444
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:884
cfg_getsec
DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name)
Returns the value of a section option.
Definition: confuse.c:449
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:1421
cfg_bool_t
cfg_bool_t
Boolean values.
Definition: confuse.h:229
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:1922
cfg_error
DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt,...)
Show a parser error.
Definition: confuse.c:984
CFGT_FLOAT
floating point number
Definition: confuse.h:71