confuse  3.2.1
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 };
255 union cfg_value_t {
256  long int number;
257  double fpnumber;
258  cfg_bool_t boolean;
259  char *string;
260  cfg_t *section;
261  void *ptr;
262 };
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;
281  cfg_bool_t boolean;
282  const char *string;
283  char *parsed;
286 };
287 
292 struct cfg_opt_t {
293  const char *name;
294  char *comment;
295  cfg_type_t type;
296  unsigned int nvalues;
297  cfg_value_t **values;
298  cfg_flag_t flags;
299  cfg_opt_t *subopts;
301  cfg_func_t func;
302  cfg_simple_t simple_value;
305  cfg_callback_t parsecb;
306  cfg_validate_callback_t validcb;
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)
328 #define CFG_STR_LIST(name, def, flags) \
329  __CFG_STR_LIST(name, def, flags, 0, 0)
333 #define CFG_STR_CB(name, def, flags, cb) \
334  __CFG_STR(name, def, flags, 0, cb)
338 #define CFG_STR_LIST_CB(name, def, flags, cb) \
339  __CFG_STR_LIST(name, def, flags, 0, cb)
393 #define CFG_SIMPLE_STR(name, svalue) \
394  __CFG_STR(name, 0, CFGF_NONE, svalue, 0)
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)
409 #define CFG_INT_LIST(name, def, flags) \
410  __CFG_INT_LIST(name, def, flags, 0, 0)
414 #define CFG_INT_CB(name, def, flags, cb) \
415  __CFG_INT(name, def, flags, 0, cb)
419 #define CFG_INT_LIST_CB(name, def, flags, cb) \
420  __CFG_INT_LIST(name, def, flags, 0, cb)
428 #define CFG_SIMPLE_INT(name, svalue) \
429  __CFG_INT(name, 0, CFGF_NONE, svalue, 0)
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)
445 #define CFG_FLOAT_LIST(name, def, flags) \
446  __CFG_FLOAT_LIST(name, def, flags, 0, 0)
450 #define CFG_FLOAT_CB(name, def, flags, cb) \
451  __CFG_FLOAT(name, def, flags, 0, cb)
455 #define CFG_FLOAT_LIST_CB(name, def, flags, cb) \
456  __CFG_FLOAT_LIST(name, def, flags, 0, cb)
461 #define CFG_SIMPLE_FLOAT(name, svalue) \
462  __CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0)
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)
478 #define CFG_BOOL_LIST(name, def, flags) \
479  __CFG_BOOL_LIST(name, def, flags, 0, 0)
483 #define CFG_BOOL_CB(name, def, flags, cb) \
484  __CFG_BOOL(name, def, flags, 0, cb)
488 #define CFG_BOOL_LIST_CB(name, def, flags, cb) \
489  __CFG_BOOL_LIST(name, def, flags, 0, cb)
494 #define CFG_SIMPLE_BOOL(name, svalue) \
495  __CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0)
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}
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}
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)
547 #define CFG_PTR_LIST_CB(name, def, flags, parsecb, freecb) \
548  __CFG_PTR(name, def, flags | CFGF_LIST, 0, parsecb, freecb)
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}
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 
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 
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
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
floating point number
Definition: confuse.h:71
cfg_bool_t
Boolean values.
Definition: confuse.h:229
Data structure holding information about an option.
Definition: confuse.h:294
int(* cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt)
Validating callback prototype.
Definition: confuse.h:200
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
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
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:1575
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
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
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
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
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
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
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
Data structure holding the default value given by the initialization macros.
Definition: confuse.h:280
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:2093
DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt)
Return the number of values this option has.
Definition: confuse.c:241
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:520
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
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
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
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
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
int line
Line number in the config file.
Definition: confuse.h:248
void(* cfg_free_func_t)(void *value)
User-defined memory release function for CFG_PTR values.
Definition: confuse.h:226
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
DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name)
Return the number of values this option has.
Definition: confuse.c:248
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
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
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
void(* cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap)
Error reporting function.
Definition: confuse.h:232
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
DLLIMPORT char *__export cfg_opt_getcomment(cfg_opt_t *opt)
Returns the option comment.
Definition: confuse.c:253
function
Definition: confuse.h:75
DLLIMPORT char *__export cfg_getcomment(cfg_t *cfg, const char *name)
Returns the option comment.
Definition: confuse.c:261
Data structure holding information about a "section".
Definition: confuse.h:238
char * name
The name of this section, the root section returned from cfg_init() is always named "root"...
Definition: confuse.h:240
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
DLLIMPORT cfg_t * cfg_addtsec(cfg_t *cfg, const char *name, const char *title)
Create a new titled config section.
Definition: confuse.c:2039
DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp)
Print the options and values to a file.
Definition: confuse.c:2287
DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name)
Returns the value of a boolean option.
Definition: confuse.c:336
boolean value
Definition: confuse.h:73
comment/annotation
Definition: confuse.h:77
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
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
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
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
DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name)
Return an option given it&#39;s name.
Definition: confuse.c:168
DLLIMPORT int __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Set values for a list option.
Definition: confuse.c:2004
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_searchpath_t * path
Linked list of directories to search.
Definition: confuse.h:252
DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name)
Returns the value of a floating point option.
Definition: confuse.c:311
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
cfg_flag_t flags
Any flags passed to cfg_init()
Definition: confuse.h:239
DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename)
Parse a configuration file.
Definition: confuse.c:1505
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
int(* cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
Value parsing callback prototype.
Definition: confuse.h:185
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
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
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
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
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
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
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
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
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
DLLIMPORT int __export cfg_setcomment(cfg_t *cfg, const char *name, char *comment)
Annotate an option given its name.
Definition: confuse.c:1821
char * comment
Optional annotation/comment.
Definition: confuse.h:243
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
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
string
Definition: confuse.h:72
Data structure holding the value of a fundamental option value.
Definition: confuse.h:257
DLLIMPORT int __export cfg_opt_setcomment(cfg_opt_t *opt, char *comment)
Annotate an option.
Definition: confuse.c:1799
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:2292
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
DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name)
Returns the value of an integer option.
Definition: confuse.c:286
char * title
Optional title for this section, only set if CFGF_TITLE flag is set.
Definition: confuse.h:245
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_errfunc_t errfunc
This function (if set with cfg_set_error_function) is called for any error message.
Definition: confuse.h:249
DLLIMPORT int __export cfg_free(cfg_t *cfg)
Free a cfg_t context.
Definition: confuse.c:1721
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
DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name)
Returns the value of a section option.
Definition: confuse.c:449
DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt)
Return the name of an option.
Definition: confuse.c:234
DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name)
Returns the value of a string option.
Definition: confuse.c:361
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
char * filename
Name of the file being parsed.
Definition: confuse.h:247
DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name)
Removes and frees a config section.
Definition: confuse.c:2098
Data structure holding the pointer to a user provided variable defined with CFG_SIMPLE_*.
Definition: confuse.h:269
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
DLLIMPORT const char *__export cfg_title(cfg_t *cfg)
Return the title of a section.
Definition: confuse.c:220
DLLIMPORT const char *__export cfg_name(cfg_t *cfg)
Return the name of a section.
Definition: confuse.c:227
DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
Predefined include-function.
Definition: confuse.c:1756
DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt,...)
Show a parser error.
Definition: confuse.c:984
int(* cfg_validate_callback2_t)(cfg_t *cfg, cfg_opt_t *opt, void *value)
Validating callback2 prototype.
Definition: confuse.h:216
DLLIMPORT int __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp)
Default value print function.
Definition: confuse.c:2141
DLLIMPORT char *__export cfg_tilde_expand(const char *filename)
Does tilde expansion (~ -> $HOME) on the filename.
Definition: confuse.c:1610
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_opt_t * opts
Array of options.
Definition: confuse.h:244