confuse  3.3
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
40extern "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_STATIC
55# define DLLIMPORT
56# else /* ! BUILDING_STATIC */
57# ifdef BUILDING_DLL
58# define DLLIMPORT __declspec (dllexport)
59# else /* ! BUILDING_DLL */
60# define DLLIMPORT __declspec (dllimport)
61# endif /* BUILDING_DLL */
62# endif /* BUILDING_STATIC */
63#else /* ! _WIN32 || __GNUC__ */
64# define DLLIMPORT
65#endif /* _WIN32 */
66
67#ifndef __BORLANDC__
68# define __export
69#endif
70
73 CFGT_NONE,
82};
83typedef enum cfg_type_t cfg_type_t;
84
86#define CFGF_NONE (0)
87#define CFGF_MULTI (1 << 0)
88#define CFGF_LIST (1 << 1)
89#define CFGF_NOCASE (1 << 2)
90#define CFGF_TITLE (1 << 3)
91#define CFGF_NODEFAULT (1 << 4)
92#define CFGF_NO_TITLE_DUPES (1 << 5)
95#define CFGF_RESET (1 << 6)
96#define CFGF_DEFINIT (1 << 7)
97#define CFGF_IGNORE_UNKNOWN (1 << 8)
98#define CFGF_DEPRECATED (1 << 9)
99#define CFGF_DROP (1 << 10)
100#define CFGF_COMMENTS (1 << 11)
101#define CFGF_MODIFIED (1 << 12)
102#define CFGF_KEYSTRVAL (1 << 13)
105#define CFG_SUCCESS 0
106#define CFG_FAIL -1
107#define CFG_FILE_ERROR -1
108#define CFG_PARSE_ERROR 1
109
110typedef union cfg_value_t cfg_value_t;
111typedef union cfg_simple_t cfg_simple_t;
112typedef struct cfg_opt_t cfg_opt_t;
113typedef struct cfg_t cfg_t;
114typedef struct cfg_defvalue_t cfg_defvalue_t;
115typedef int cfg_flag_t;
116typedef struct cfg_searchpath_t cfg_searchpath_t;
117
143typedef int (*cfg_func_t)(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv);
144
165typedef void (*cfg_print_func_t)(cfg_opt_t *opt, unsigned int index, FILE *fp);
166
188typedef int (*cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result);
189
203typedef int (*cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt);
204
219typedef int (*cfg_validate_callback2_t)(cfg_t *cfg, cfg_opt_t *opt, void *value);
220
229typedef void (*cfg_free_func_t)(void *value);
230
232typedef enum { cfg_false, cfg_true } cfg_bool_t;
233
235typedef void (*cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap);
236
246typedef int (*cfg_print_filter_func_t)(cfg_t *cfg, cfg_opt_t *opt);
247
252struct cfg_t {
253 cfg_flag_t flags;
254 char *name;
257 char *comment;
259 char *title;
261 char *filename;
262 int line;
266 cfg_searchpath_t *path;
268};
269
273 long int number;
274 double fpnumber;
276 char *string;
278 void *ptr;
279};
280
285 long int *number;
286 double *fpnumber;
287 cfg_bool_t *boolean;
288 char **string;
289 void **ptr;
290};
291
296 long int number;
297 double fpnumber;
299 const char *string;
300 char *parsed;
303};
304
309struct cfg_opt_t {
310 const char *name;
311 char *comment;
313 unsigned int nvalues;
315 cfg_flag_t flags;
326 cfg_free_func_t freecb; /***< user-defined memory release function */
327};
328
329extern const char __export confuse_copyright[];
330extern const char __export confuse_version[];
331extern const char __export confuse_author[];
332
333#define __CFG_STR(name, def, flags, svalue, cb) \
334 {name,0,CFGT_STR,0,0,flags,0,{0,0,cfg_false,def,0},0,{.string=svalue},cb,0,0,0,0}
335#define __CFG_STR_LIST(name, def, flags, svalue, cb) \
336 {name,0,CFGT_STR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.string=svalue},cb,0,0,0,0}
337
340#define CFG_STR(name, def, flags) \
341 __CFG_STR(name, def, flags, 0, 0)
342
345#define CFG_STR_LIST(name, def, flags) \
346 __CFG_STR_LIST(name, def, flags, 0, 0)
347
350#define CFG_STR_CB(name, def, flags, cb) \
351 __CFG_STR(name, def, flags, 0, cb)
352
355#define CFG_STR_LIST_CB(name, def, flags, cb) \
356 __CFG_STR_LIST(name, def, flags, 0, cb)
357
410#define CFG_SIMPLE_STR(name, svalue) \
411 __CFG_STR(name, 0, CFGF_NONE, svalue, 0)
412
413
414#define __CFG_INT(name, def, flags, svalue, cb) \
415 {name,0,CFGT_INT,0,0,flags,0,{def,0,cfg_false,0,0},0,{.number=svalue},cb,0,0,0,0}
416#define __CFG_INT_LIST(name, def, flags, svalue, cb) \
417 {name,0,CFGT_INT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.number=svalue},cb,0,0,0,0}
418
421#define CFG_INT(name, def, flags) \
422 __CFG_INT(name, def, flags, 0, 0)
423
426#define CFG_INT_LIST(name, def, flags) \
427 __CFG_INT_LIST(name, def, flags, 0, 0)
428
431#define CFG_INT_CB(name, def, flags, cb) \
432 __CFG_INT(name, def, flags, 0, cb)
433
436#define CFG_INT_LIST_CB(name, def, flags, cb) \
437 __CFG_INT_LIST(name, def, flags, 0, cb)
438
445#define CFG_SIMPLE_INT(name, svalue) \
446 __CFG_INT(name, 0, CFGF_NONE, svalue, 0)
447
448
449
450#define __CFG_FLOAT(name, def, flags, svalue, cb) \
451 {name,0,CFGT_FLOAT,0,0,flags,0,{0,def,cfg_false,0,0},0,{.fpnumber=svalue},cb,0,0,0,0}
452#define __CFG_FLOAT_LIST(name, def, flags, svalue, cb) \
453 {name,0,CFGT_FLOAT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.fpnumber=svalue},cb,0,0,0,0}
454
457#define CFG_FLOAT(name, def, flags) \
458 __CFG_FLOAT(name, def, flags, 0, 0)
459
462#define CFG_FLOAT_LIST(name, def, flags) \
463 __CFG_FLOAT_LIST(name, def, flags, 0, 0)
464
467#define CFG_FLOAT_CB(name, def, flags, cb) \
468 __CFG_FLOAT(name, def, flags, 0, cb)
469
472#define CFG_FLOAT_LIST_CB(name, def, flags, cb) \
473 __CFG_FLOAT_LIST(name, def, flags, 0, cb)
474
478#define CFG_SIMPLE_FLOAT(name, svalue) \
479 __CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0)
480
481
482
483#define __CFG_BOOL(name, def, flags, svalue, cb) \
484 {name,0,CFGT_BOOL,0,0,flags,0,{0,0,def,0,0},0,{.boolean=svalue},cb,0,0,0,0}
485#define __CFG_BOOL_LIST(name, def, flags, svalue, cb) \
486 {name,0,CFGT_BOOL,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.boolean=svalue},cb,0,0,0,0}
487
490#define CFG_BOOL(name, def, flags) \
491 __CFG_BOOL(name, def, flags, 0, 0)
492
495#define CFG_BOOL_LIST(name, def, flags) \
496 __CFG_BOOL_LIST(name, def, flags, 0, 0)
497
500#define CFG_BOOL_CB(name, def, flags, cb) \
501 __CFG_BOOL(name, def, flags, 0, cb)
502
505#define CFG_BOOL_LIST_CB(name, def, flags, cb) \
506 __CFG_BOOL_LIST(name, def, flags, 0, cb)
507
511#define CFG_SIMPLE_BOOL(name, svalue) \
512 __CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0)
513
514
515
527#define CFG_SEC(name, opts, flags) \
528 {name,0,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,{0},0,0,0,0,0}
529
530
531
538#define CFG_FUNC(name, func) \
539 {name,0,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,{0},0,0,0,0,0}
540
541
542#define __CFG_PTR(name, def, flags, svalue, parsecb, freecb) \
543 {name,0,CFGT_PTR,0,0,flags,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,0,freecb}
544#define __CFG_PTR_LIST(name, def, flags, svalue, parsecb, freecb) \
545 {name,0,CFGT_PTR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,{.ptr=svalue},parsecb,0,0,0,freecb}
546
559#define CFG_PTR_CB(name, def, flags, parsecb, freecb) \
560 __CFG_PTR(name, def, flags, 0, parsecb, freecb)
561
564#define CFG_PTR_LIST_CB(name, def, flags, parsecb, freecb) \
565 __CFG_PTR(name, def, flags | CFGF_LIST, 0, parsecb, freecb)
566
567/*#define CFG_SIMPLE_PTR(name, svalue, cb) \
568 __CFG_PTR(name, 0, 0, svalue, cb)*/
569
570
574#define CFG_END() \
575 {0,0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,{0},0,0,0,0,0}
576
577
578
606DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags);
607
624DLLIMPORT int __export cfg_add_searchpath(cfg_t *cfg, const char *dir);
625
637DLLIMPORT char *__export cfg_searchpath(cfg_searchpath_t *path, const char *file);
638
652DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename);
653
666DLLIMPORT int __export cfg_parse_fp(cfg_t *cfg, FILE *fp);
667
678DLLIMPORT int __export cfg_parse_buf(cfg_t *cfg, const char *buf);
679
687DLLIMPORT int __export cfg_free_value(cfg_opt_t *opt);
688
694DLLIMPORT int __export cfg_free(cfg_t *cfg);
695
699DLLIMPORT cfg_errfunc_t __export cfg_set_error_function(cfg_t *cfg, cfg_errfunc_t errfunc);
700
704DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt, ...);
705
710DLLIMPORT char * __export cfg_opt_getcomment(cfg_opt_t *opt);
711
722DLLIMPORT char * __export cfg_getcomment(cfg_t *cfg, const char *name);
723
729DLLIMPORT signed long __export cfg_opt_getnint(cfg_opt_t *opt, unsigned int index);
730
737DLLIMPORT long int __export cfg_getnint(cfg_t *cfg, const char *name, unsigned int index);
738
748DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name);
749
755DLLIMPORT double __export cfg_opt_getnfloat(cfg_opt_t *opt, unsigned int index);
756
763DLLIMPORT double __export cfg_getnfloat(cfg_t *cfg, const char *name, unsigned int index);
764
773DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name);
774
780DLLIMPORT char *__export cfg_opt_getnstr(cfg_opt_t *opt, unsigned int index);
781
788DLLIMPORT char *__export cfg_getnstr(cfg_t *cfg, const char *name, unsigned int index);
789
798DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name);
799
805DLLIMPORT cfg_bool_t __export cfg_opt_getnbool(cfg_opt_t *opt, unsigned int index);
806
814DLLIMPORT cfg_bool_t __export cfg_getnbool(cfg_t *cfg, const char *name, unsigned int index);
815
824DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name);
825
826
827DLLIMPORT void *__export cfg_opt_getnptr(cfg_opt_t *opt, unsigned int index);
828DLLIMPORT void *__export cfg_getnptr(cfg_t *cfg, const char *name, unsigned int indx);
829
838DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name);
839
840
846DLLIMPORT cfg_t *__export cfg_opt_getnsec(cfg_opt_t *opt, unsigned int index);
847
856DLLIMPORT cfg_t *__export cfg_getnsec(cfg_t *cfg, const char *name, unsigned int index);
857
865DLLIMPORT cfg_t *__export cfg_opt_gettsec(cfg_opt_t *opt, const char *title);
866
876DLLIMPORT cfg_t *__export cfg_gettsec(cfg_t *cfg, const char *name, const char *title);
877
888DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name);
889
895DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt);
896
909DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name);
910
917DLLIMPORT const char *__export cfg_title(cfg_t *cfg);
918
925DLLIMPORT const char *__export cfg_name(cfg_t *cfg);
926
933DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt);
934
942DLLIMPORT const char *cfg_opt_getstr(cfg_opt_t *opt);
943
949DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv);
950
957DLLIMPORT char *__export cfg_tilde_expand(const char *filename);
958
966DLLIMPORT int __export cfg_parse_boolean(const char *s);
967
974DLLIMPORT cfg_opt_t *cfg_getnopt(cfg_t *cfg, unsigned int index);
975
984DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name);
985
994DLLIMPORT cfg_value_t *cfg_setopt(cfg_t *cfg, cfg_opt_t *opt, const char *value);
995
1002DLLIMPORT int __export cfg_opt_setcomment(cfg_opt_t *opt, char *comment);
1003
1022DLLIMPORT int __export cfg_setcomment(cfg_t *cfg, const char *name, char *comment);
1023
1034DLLIMPORT int __export cfg_opt_setnint(cfg_opt_t *opt, long int value, unsigned int index);
1035
1045DLLIMPORT int __export cfg_setint(cfg_t *cfg, const char *name, long int value);
1046
1058DLLIMPORT int __export cfg_setnint(cfg_t *cfg, const char *name, long int value, unsigned int index);
1059
1070DLLIMPORT int __export cfg_opt_setnfloat(cfg_opt_t *opt, double value, unsigned int index);
1071
1081DLLIMPORT int __export cfg_setfloat(cfg_t *cfg, const char *name, double value);
1082
1094DLLIMPORT int __export cfg_setnfloat(cfg_t *cfg, const char *name, double value, unsigned int index);
1095
1106DLLIMPORT int __export cfg_opt_setnbool(cfg_opt_t *opt, cfg_bool_t value, unsigned int index);
1107
1117DLLIMPORT int __export cfg_setbool(cfg_t *cfg, const char *name, cfg_bool_t value);
1118
1130DLLIMPORT int __export cfg_setnbool(cfg_t *cfg, const char *name, cfg_bool_t value, unsigned int index);
1131
1143DLLIMPORT int __export cfg_opt_setnstr(cfg_opt_t *opt, const char *value, unsigned int index);
1144
1155DLLIMPORT int __export cfg_setstr(cfg_t *cfg, const char *name, const char *value);
1156
1169DLLIMPORT int __export cfg_setnstr(cfg_t *cfg, const char *name, const char *value, unsigned int index);
1170
1183DLLIMPORT int __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues, ...);
1184
1185DLLIMPORT int __export cfg_numopts(cfg_opt_t *opts);
1186
1196DLLIMPORT unsigned int __export cfg_num(cfg_t *cfg);
1197
1210DLLIMPORT int __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues, ...);
1211
1221DLLIMPORT int cfg_opt_setmulti(cfg_t *cfg, cfg_opt_t *opt, unsigned int nvalues, char **values);
1222
1232DLLIMPORT int cfg_setmulti(cfg_t *cfg, const char *name, unsigned int nvalues, char **values);
1233
1244DLLIMPORT cfg_t *cfg_addtsec(cfg_t *cfg, const char *name, const char *title);
1245
1253DLLIMPORT int __export cfg_opt_rmnsec(cfg_opt_t *opt, unsigned int index);
1254
1263DLLIMPORT int __export cfg_rmnsec(cfg_t *cfg, const char *name, unsigned int index);
1264
1272DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name);
1273
1283DLLIMPORT int __export cfg_opt_rmtsec(cfg_opt_t *opt, const char *title);
1284
1296DLLIMPORT int __export cfg_rmtsec(cfg_t *cfg, const char *name, const char *title);
1297
1312DLLIMPORT int __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp);
1313
1320DLLIMPORT int __export cfg_opt_print_indent(cfg_opt_t *opt, FILE *fp, int indent);
1321
1334DLLIMPORT int __export cfg_opt_print(cfg_opt_t *opt, FILE *fp);
1335
1342DLLIMPORT int __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent);
1343
1359DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp);
1360
1369
1378DLLIMPORT cfg_print_func_t __export cfg_set_print_func(cfg_t *cfg, const char *name, cfg_print_func_t pf);
1379
1394
1403DLLIMPORT cfg_validate_callback_t __export cfg_set_validate_func(cfg_t *cfg, const char *name, cfg_validate_callback_t vf);
1404
1418DLLIMPORT cfg_validate_callback2_t __export cfg_set_validate_func2(cfg_t *cfg, const char *name, cfg_validate_callback2_t vf);
1419
1420#ifdef __cplusplus
1421}
1422#endif
1423#endif /* CONFUSE_H_ */
1424
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:2135
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:2570
DLLIMPORT char *__export cfg_opt_getcomment(cfg_opt_t *opt)
Returns the option comment.
Definition: confuse.c:411
DLLIMPORT char *__export cfg_getnstr(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getstr(), used for lists.
Definition: confuse.c:514
DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename)
Parse a configuration file.
Definition: confuse.c:1746
DLLIMPORT unsigned int __export cfg_opt_size(cfg_opt_t *opt)
Return the number of values this option has.
Definition: confuse.c:399
int(* cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt)
Validating callback prototype.
Definition: confuse.h:203
void(* cfg_free_func_t)(void *value)
User-defined memory release function for CFG_PTR values.
Definition: confuse.h:229
DLLIMPORT const char *__export cfg_opt_name(cfg_opt_t *opt)
Return the name of an option.
Definition: confuse.c:387
void(* cfg_print_func_t)(cfg_opt_t *opt, unsigned int index, FILE *fp)
Function prototype used by the cfg_print_ functions.
Definition: confuse.h:165
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:2520
DLLIMPORT int cfg_setmulti(cfg_t *cfg, const char *name, unsigned int nvalues, char **values)
Set an option (create an instance of an option).
Definition: confuse.c:1127
void(* cfg_errfunc_t)(cfg_t *cfg, const char *fmt, va_list ap)
Error reporting function.
Definition: confuse.h:235
DLLIMPORT cfg_t *__export cfg_gettsec(cfg_t *cfg, const char *name, const char *title)
Return a section given the title, used for section with the CFGF_TITLE flag set.
Definition: confuse.c:590
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:2100
DLLIMPORT cfg_opt_t *__export cfg_getopt(cfg_t *cfg, const char *name)
Return an option given it's name.
Definition: confuse.c:368
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:2388
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:2555
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:2169
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:2341
DLLIMPORT char *__export cfg_searchpath(cfg_searchpath_t *path, const char *file)
Search the linked-list of cfg_searchpath_t for the specified file.
Definition: confuse.c:1715
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:2089
DLLIMPORT void *__export cfg_getptr(cfg_t *cfg, const char *name)
Returns the value of a user-defined option (void pointer).
Definition: confuse.c:544
DLLIMPORT double __export cfg_getfloat(cfg_t *cfg, const char *name)
Returns the value of a floating point option.
Definition: confuse.c:469
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:2105
DLLIMPORT int __export cfg_free_value(cfg_opt_t *opt)
Free the memory allocated for the values of a given option.
Definition: confuse.c:1900
cfg_bool_t
Boolean values.
Definition: confuse.h:232
DLLIMPORT char *__export cfg_getcomment(cfg_t *cfg, const char *name)
Returns the option comment.
Definition: confuse.c:419
DLLIMPORT int __export cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Add values for a list option.
Definition: confuse.c:2270
DLLIMPORT cfg_value_t * cfg_setopt(cfg_t *cfg, cfg_opt_t *opt, const char *value)
Set an option (create an instance of an option).
Definition: confuse.c:867
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:2213
DLLIMPORT int __export cfg_parse_boolean(const char *s)
Parse a boolean option string.
Definition: confuse.c:721
int(* cfg_validate_callback2_t)(cfg_t *cfg, cfg_opt_t *opt, void *value)
Validating callback2 prototype.
Definition: confuse.h:219
DLLIMPORT void __export cfg_error(cfg_t *cfg, const char *fmt,...)
Show a parser error.
Definition: confuse.c:1211
DLLIMPORT cfg_opt_t * cfg_getnopt(cfg_t *cfg, unsigned int index)
Return the nth option in a file or section.
Definition: confuse.c:353
DLLIMPORT cfg_t *__export cfg_getsec(cfg_t *cfg, const char *name)
Returns the value of a section option.
Definition: confuse.c:595
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:2202
DLLIMPORT cfg_print_filter_func_t __export cfg_set_print_filter_func(cfg_t *cfg, cfg_print_filter_func_t pff)
Install a user-defined print filter function.
Definition: confuse.c:1196
DLLIMPORT int __export cfg_add_searchpath(cfg_t *cfg, const char *dir)
Add a searchpath directory to the configuration context, the const char* argument will be duplicated ...
Definition: confuse.c:1154
DLLIMPORT cfg_t *__export cfg_opt_getnsec(cfg_opt_t *opt, unsigned int index)
Returns the value of a section option, given a cfg_opt_t pointer.
Definition: confuse.c:549
DLLIMPORT int __export cfg_parse_buf(cfg_t *cfg, const char *buf)
Same as cfg_parse() above, but takes a character buffer as argument.
Definition: confuse.c:1777
DLLIMPORT char *__export cfg_getstr(cfg_t *cfg, const char *name)
Returns the value of a string option.
Definition: confuse.c:519
int(* cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
Value parsing callback prototype.
Definition: confuse.h:188
DLLIMPORT int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
Predefined include-function.
Definition: confuse.c:1999
DLLIMPORT int cfg_opt_setmulti(cfg_t *cfg, cfg_opt_t *opt, unsigned int nvalues, char **values)
Set an option (create an instance of an option).
Definition: confuse.c:1093
DLLIMPORT char *__export cfg_tilde_expand(const char *filename)
Does tilde expansion (~ -> $HOME) on the filename.
Definition: confuse.c:1851
int(* cfg_func_t)(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
Function prototype used by CFGT_FUNC options.
Definition: confuse.h:143
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:2124
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:2140
DLLIMPORT int __export cfg_parse_fp(cfg_t *cfg, FILE *fp)
Same as cfg_parse() above, but takes an already opened file as argument.
Definition: confuse.c:1662
DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags)
Create and initialize a cfg_t structure.
Definition: confuse.c:1816
DLLIMPORT cfg_bool_t __export cfg_getnbool(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getbool(), used for lists.
Definition: confuse.c:489
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:2311
DLLIMPORT const char *__export cfg_title(cfg_t *cfg)
Return the title of a section.
Definition: confuse.c:373
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:2639
DLLIMPORT int __export cfg_setlist(cfg_t *cfg, const char *name, unsigned int nvalues,...)
Set values for a list option.
Definition: confuse.c:2252
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:2654
DLLIMPORT int __export cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp)
Default value print function.
Definition: confuse.c:2393
cfg_type_t
Fundamental option types.
Definition: confuse.h:72
@ CFGT_PTR
pointer to user-defined value
Definition: confuse.h:80
@ CFGT_COMMENT
comment/annotation
Definition: confuse.h:81
@ CFGT_FUNC
function
Definition: confuse.h:79
@ CFGT_BOOL
boolean value
Definition: confuse.h:77
@ CFGT_SEC
section
Definition: confuse.h:78
@ CFGT_FLOAT
floating point number
Definition: confuse.h:75
@ CFGT_STR
string
Definition: confuse.h:76
@ CFGT_INT
integer
Definition: confuse.h:74
DLLIMPORT int __export cfg_rmsec(cfg_t *cfg, const char *name)
Removes and frees a config section.
Definition: confuse.c:2346
DLLIMPORT unsigned int __export cfg_num(cfg_t *cfg)
Return number of options in a file or section.
Definition: confuse.c:656
DLLIMPORT double __export cfg_opt_getnfloat(cfg_opt_t *opt, unsigned int index)
Returns the value of a floating point option, given a cfg_opt_t pointer.
Definition: confuse.c:449
DLLIMPORT long int __export cfg_getint(cfg_t *cfg, const char *name)
Returns the value of an integer option.
Definition: confuse.c:444
DLLIMPORT char *__export cfg_opt_getnstr(cfg_opt_t *opt, unsigned int index)
Returns the value of a string option, given a cfg_opt_t pointer.
Definition: confuse.c:499
DLLIMPORT int __export cfg_print_indent(cfg_t *cfg, FILE *fp, int indent)
Print the options and values to a file.
Definition: confuse.c:2545
DLLIMPORT cfg_t *__export cfg_opt_gettsec(cfg_opt_t *opt, const char *title)
Returns the value of a section option, given a cfg_opt_t pointer and the title.
Definition: confuse.c:568
DLLIMPORT int __export cfg_free(cfg_t *cfg)
Free a cfg_t context.
Definition: confuse.c:1964
DLLIMPORT double __export cfg_getnfloat(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getfloat(), used for lists.
Definition: confuse.c:464
DLLIMPORT const char * cfg_opt_getstr(cfg_opt_t *opt)
Return the string value of a key=value pair.
Definition: confuse.c:394
DLLIMPORT cfg_bool_t __export cfg_getbool(cfg_t *cfg, const char *name)
Returns the value of a boolean option.
Definition: confuse.c:494
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:2355
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:2159
DLLIMPORT signed long __export cfg_opt_getnint(cfg_opt_t *opt, unsigned int index)
Returns the value of an integer option, given a cfg_opt_t pointer.
Definition: confuse.c:424
DLLIMPORT int __export cfg_setcomment(cfg_t *cfg, const char *name, char *comment)
Annotate an option given its name.
Definition: confuse.c:2065
int(* cfg_print_filter_func_t)(cfg_t *cfg, cfg_opt_t *opt)
Print filter function.
Definition: confuse.h:246
DLLIMPORT const char *__export cfg_name(cfg_t *cfg)
Return the name of a section.
Definition: confuse.c:380
DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp)
Print the options and values to a file.
Definition: confuse.c:2550
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:2164
DLLIMPORT int __export cfg_opt_print(cfg_opt_t *opt, FILE *fp)
Print an option and its value to a file.
Definition: confuse.c:2525
DLLIMPORT unsigned int __export cfg_size(cfg_t *cfg, const char *name)
Return the number of values this option has.
Definition: confuse.c:406
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:2070
DLLIMPORT long int __export cfg_getnint(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getint(), used for lists.
Definition: confuse.c:439
DLLIMPORT cfg_errfunc_t __export cfg_set_error_function(cfg_t *cfg, cfg_errfunc_t errfunc)
Install a user-defined error reporting function.
Definition: confuse.c:1181
DLLIMPORT cfg_t *__export cfg_getnsec(cfg_t *cfg, const char *name, unsigned int index)
Indexed version of cfg_getsec(), used for sections with the CFGF_MULTI flag set.
Definition: confuse.c:563
DLLIMPORT int __export cfg_opt_setcomment(cfg_opt_t *opt, char *comment)
Annotate an option.
Definition: confuse.c:2042
DLLIMPORT cfg_bool_t __export cfg_opt_getnbool(cfg_opt_t *opt, unsigned int index)
Returns the value of a boolean option, given a cfg_opt_t pointer.
Definition: confuse.c:474
DLLIMPORT cfg_t * cfg_addtsec(cfg_t *cfg, const char *name, const char *title)
Create a new titled config section.
Definition: confuse.c:2287
Data structure holding the default value given by the initialization macros.
Definition: confuse.h:295
long int number
default integer value
Definition: confuse.h:296
const char * string
default string value
Definition: confuse.h:299
char * parsed
default value that is parsed by libConfuse, used for lists and functions
Definition: confuse.h:300
cfg_bool_t boolean
default boolean value
Definition: confuse.h:298
double fpnumber
default floating point value
Definition: confuse.h:297
Data structure holding information about an option.
Definition: confuse.h:309
const char * name
The name of the option.
Definition: confuse.h:310
cfg_type_t type
Type of option.
Definition: confuse.h:312
cfg_defvalue_t def
Default value.
Definition: confuse.h:317
cfg_callback_t parsecb
Value parsing callback function.
Definition: confuse.h:322
cfg_simple_t simple_value
Pointer to user-specified variable to store simple values (created with the CFG_SIMPLE_* initializers...
Definition: confuse.h:319
cfg_func_t func
Function callback for CFGT_FUNC options.
Definition: confuse.h:318
cfg_validate_callback2_t validcb2
Value validating set callback function.
Definition: confuse.h:324
char * comment
Optional comment/annotation.
Definition: confuse.h:311
cfg_validate_callback_t validcb
Value validating parsing callback function.
Definition: confuse.h:323
cfg_opt_t * subopts
Suboptions (only applies to sections)
Definition: confuse.h:316
cfg_print_func_t pf
print callback function
Definition: confuse.h:325
cfg_flag_t flags
Flags.
Definition: confuse.h:315
cfg_value_t ** values
Array of found values.
Definition: confuse.h:314
unsigned int nvalues
Number of values parsed.
Definition: confuse.h:313
Data structure holding information about a "section".
Definition: confuse.h:252
cfg_opt_t * opts
Array of options.
Definition: confuse.h:258
int line
Line number in the config file.
Definition: confuse.h:262
cfg_errfunc_t errfunc
This function (if set with cfg_set_error_function) is called for any error message.
Definition: confuse.h:263
char * name
The name of this section, the root section returned from cfg_init() is always named "root".
Definition: confuse.h:254
char * title
Optional title for this section, only set if CFGF_TITLE flag is set.
Definition: confuse.h:259
cfg_print_filter_func_t pff
Printing filter function.
Definition: confuse.h:267
cfg_flag_t flags
Any flags passed to cfg_init()
Definition: confuse.h:253
char * comment
Optional annotation/comment.
Definition: confuse.h:257
char * filename
Name of the file being parsed.
Definition: confuse.h:261
cfg_searchpath_t * path
Linked list of directories to search.
Definition: confuse.h:266
Data structure holding the pointer to a user provided variable defined with CFG_SIMPLE_*.
Definition: confuse.h:284
Data structure holding the value of a fundamental option value.
Definition: confuse.h:272
void * ptr
user-defined value
Definition: confuse.h:278
cfg_t * section
section value
Definition: confuse.h:277
char * string
string value
Definition: confuse.h:276
cfg_bool_t boolean
boolean value
Definition: confuse.h:275
long int number
integer value
Definition: confuse.h:273
double fpnumber
floating point value
Definition: confuse.h:274