confuse.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00041
#ifndef _cfg_h_
00042
#define _cfg_h_
00043
00044
#ifdef __cplusplus
00045
extern "C" {
00046
#endif
00047
00048
#include <stdio.h>
00049
#include <stdarg.h>
00050
00051
#ifdef _WIN32
00052
00053
# ifdef HAVE__FILENO
00054
# define fileno _fileno
00055
# endif
00056
# include <io.h>
00057
# ifdef HAVE__ISATTY
00058
# define isatty _isatty
00059
# endif
00060
00061
# ifdef BUILDING_DLL
00062
# define DLLIMPORT __declspec (dllexport)
00063
# else
00064
# define DLLIMPORT __declspec (dllimport)
00065
# endif
00066
00067
#else
00068
# define DLLIMPORT
00069
00070
#endif
00071
00072
#ifndef __BORLANDC__
00073
# define __export
00074
#endif
00075
00077 enum cfg_type_t {
00078 CFGT_NONE,
00079
CFGT_INT,
00080
CFGT_FLOAT,
00081
CFGT_STR,
00082
CFGT_BOOL,
00083
CFGT_SEC,
00084
CFGT_FUNC
00085 };
00086
typedef enum cfg_type_t cfg_type_t;
00087
00089 #define CFGF_NONE 0
00090 #define CFGF_MULTI 1
00091 #define CFGF_LIST 2
00092 #define CFGF_NOCASE 4
00093 #define CFGF_TITLE 8
00094
#define CFGF_RESET 32
00095
#define CFGF_DEFINIT 64
00096
00098 #define CFG_SUCCESS 0
00099
#define CFG_FILE_ERROR -1
00100
#define CFG_PARSE_ERROR 1
00101
00102
typedef union cfg_value_t cfg_value_t;
00103
typedef struct cfg_opt_t cfg_opt_t;
00104
typedef struct cfg_t cfg_t;
00105
typedef struct cfg_defvalue_t cfg_defvalue_t;
00106
typedef int cfg_flag_t;
00107
00133 typedef int (*
cfg_func_t)(cfg_t *cfg, cfg_opt_t *opt,
00134
int argc,
const char **argv);
00135
00156 typedef void (*cfg_print_func_t)(cfg_opt_t *opt,
unsigned int index, FILE *fp);
00157
00179 typedef int (*
cfg_callback_t)(cfg_t *cfg, cfg_opt_t *opt,
00180
const char *value,
void *result);
00181
00195 typedef int (*cfg_validate_callback_t)(cfg_t *cfg, cfg_opt_t *opt);
00196
00198 typedef enum {cfg_false, cfg_true}
cfg_bool_t;
00199
00201 typedef void (*
cfg_errfunc_t)(cfg_t *cfg,
const char *fmt, va_list ap);
00202
00207 struct cfg_t {
00208 cfg_flag_t
flags;
00209 char *
name;
00212 cfg_opt_t *
opts;
00213 char *
title;
00215 char *
filename;
00216 int line;
00217 cfg_errfunc_t errfunc;
00220 };
00221
00224 union cfg_value_t {
00225 long int number;
00226 double fpnumber;
00227 cfg_bool_t boolean;
00228 char *
string;
00229 cfg_t *
section;
00230 };
00231
00235 struct cfg_defvalue_t {
00236 long int number;
00237 double fpnumber;
00238 cfg_bool_t boolean;
00239 char *
string;
00240 char *
parsed;
00243 };
00244
00249 struct cfg_opt_t {
00250 char *
name;
00251 cfg_type_t
type;
00252 unsigned int nvalues;
00253 cfg_value_t **
values;
00254 cfg_flag_t
flags;
00255 cfg_opt_t *
subopts;
00256 cfg_defvalue_t
def;
00257 cfg_func_t func;
00258 void *
simple_value;
00261 cfg_callback_t parsecb;
00262 cfg_validate_callback_t validcb;
00263 cfg_print_func_t pf;
00264 };
00265
00266
extern const char __export confuse_copyright[];
00267
extern const char __export confuse_version[];
00268
extern const char __export confuse_author[];
00269
00270
#define __CFG_STR(name, def, flags, svalue, cb) \
00271
{name,CFGT_STR,0,0,flags,0,{0,0,cfg_false,def,0},0,svalue,cb,0,0}
00272
#define __CFG_STR_LIST(name, def, flags, svalue, cb) \
00273
{name,CFGT_STR,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,svalue,cb,0,0}
00274
00277 #define CFG_STR(name, def, flags) \
00278
__CFG_STR(name, def, flags, 0, 0)
00279
00282 #define CFG_STR_LIST(name, def, flags) \
00283
__CFG_STR_LIST(name, def, flags, 0, 0)
00284
00287 #define CFG_STR_CB(name, def, flags, cb) \
00288
__CFG_STR(name, def, flags, 0, cb)
00289
00292 #define CFG_STR_LIST_CB(name, def, flags, cb) \
00293
__CFG_STR_LIST(name, def, flags, 0, cb)
00294
00347 #define CFG_SIMPLE_STR(name, svalue) \
00348
__CFG_STR(name, 0, CFGF_NONE, svalue, 0)
00349
00350
00351
#define __CFG_INT(name, def, flags, svalue, cb) \
00352
{name,CFGT_INT,0,0,flags,0,{def,0,cfg_false,0,0},0,svalue,cb,0,0}
00353
#define __CFG_INT_LIST(name, def, flags, svalue, cb) \
00354
{name,CFGT_INT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,svalue,cb,0,0}
00355
00358 #define CFG_INT(name, def, flags) \
00359
__CFG_INT(name, def, flags, 0, 0)
00360
00363 #define CFG_INT_LIST(name, def, flags) \
00364
__CFG_INT_LIST(name, def, flags, 0, 0)
00365
00368 #define CFG_INT_CB(name, def, flags, cb) \
00369
__CFG_INT(name, def, flags, 0, cb)
00370
00373 #define CFG_INT_LIST_CB(name, def, flags, cb) \
00374
__CFG_INT_LIST(name, def, flags, 0, cb)
00375
00379 #define CFG_SIMPLE_INT(name, svalue) \
00380
__CFG_INT(name, 0, CFGF_NONE, svalue, 0)
00381
00382
00383
00384
#define __CFG_FLOAT(name, def, flags, svalue, cb) \
00385
{name,CFGT_FLOAT,0,0,flags,0,{0,def,cfg_false,0,0},0,svalue,cb,0,0}
00386
#define __CFG_FLOAT_LIST(name, def, flags, svalue, cb) \
00387
{name,CFGT_FLOAT,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,svalue,cb,0,0}
00388
00391 #define CFG_FLOAT(name, def, flags) \
00392
__CFG_FLOAT(name, def, flags, 0, 0)
00393
00396 #define CFG_FLOAT_LIST(name, def, flags) \
00397
__CFG_FLOAT_LIST(name, def, flags, 0, 0)
00398
00401 #define CFG_FLOAT_CB(name, def, flags, cb) \
00402
__CFG_FLOAT(name, def, flags, 0, cb)
00403
00406 #define CFG_FLOAT_LIST_CB(name, def, flags, cb) \
00407
__CFG_FLOAT_LIST(name, def, flags, 0, cb)
00408
00412 #define CFG_SIMPLE_FLOAT(name, svalue) \
00413
__CFG_FLOAT(name, 0, CFGF_NONE, svalue, 0)
00414
00415
00416
00417
#define __CFG_BOOL(name, def, flags, svalue, cb) \
00418
{name,CFGT_BOOL,0,0,flags,0,{0,0,def,0,0},0,svalue,cb,0,0}
00419
#define __CFG_BOOL_LIST(name, def, flags, svalue, cb) \
00420
{name,CFGT_BOOL,0,0,flags | CFGF_LIST,0,{0,0,cfg_false,0,def},0,svalue,cb,0,0}
00421
00424 #define CFG_BOOL(name, def, flags) \
00425
__CFG_BOOL(name, def, flags, 0, 0)
00426
00429 #define CFG_BOOL_LIST(name, def, flags) \
00430
__CFG_BOOL_LIST(name, def, flags, 0, 0)
00431
00434 #define CFG_BOOL_CB(name, def, flags, cb) \
00435
__CFG_BOOL(name, def, flags, 0, cb)
00436
00439 #define CFG_BOOL_LIST_CB(name, def, flags, cb) \
00440
__CFG_BOOL_LIST(name, def, flags, 0, cb)
00441
00445 #define CFG_SIMPLE_BOOL(name, svalue) \
00446
__CFG_BOOL(name, cfg_false, CFGF_NONE, svalue, 0)
00447
00448
00449
00461 #define CFG_SEC(name, opts, flags) \
00462
{name,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,0,0,0,0}
00463
00464
00465
00472 #define CFG_FUNC(name, func) \
00473
{name,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,0,0,0,0}
00474
00475
00476
00480 #define CFG_END() \
00481
{0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,0,0,0,0}
00482
00483
00484
00501 DLLIMPORT cfg_t * __export cfg_init(cfg_opt_t *opts, cfg_flag_t flags);
00502
00516 DLLIMPORT
int __export cfg_parse(cfg_t *cfg,
const char *filename);
00517
00528 DLLIMPORT
int __export cfg_parse_fp(cfg_t *cfg, FILE *fp);
00529
00538 DLLIMPORT
int __export cfg_parse_buf(cfg_t *cfg,
const char *buf);
00539
00545 DLLIMPORT
void __export cfg_free_value(cfg_opt_t *opt);
00546
00550 DLLIMPORT
void __export cfg_free(cfg_t *cfg);
00551
00555 DLLIMPORT
cfg_errfunc_t __export cfg_set_error_function(cfg_t *cfg,
00556 cfg_errfunc_t errfunc);
00557
00561 DLLIMPORT
void __export cfg_error(cfg_t *cfg,
const char *fmt, ...);
00562
00568 DLLIMPORT
signed long cfg_opt_getnint(cfg_opt_t *opt,
unsigned int index);
00569
00576 DLLIMPORT
long int __export cfg_getnint(cfg_t *cfg,
const char *name,
00577
unsigned int index);
00578
00588 DLLIMPORT
long int __export cfg_getint(cfg_t *cfg,
const char *name);
00589
00595 DLLIMPORT
double cfg_opt_getnfloat(cfg_opt_t *opt,
unsigned int index);
00596
00603 DLLIMPORT
double __export cfg_getnfloat(cfg_t *cfg,
const char *name,
00604
unsigned int index);
00605
00614 DLLIMPORT
double __export cfg_getfloat(cfg_t *cfg,
const char *name);
00615
00621 DLLIMPORT
char *cfg_opt_getnstr(cfg_opt_t *opt,
unsigned int index);
00622
00629 DLLIMPORT
char * __export cfg_getnstr(cfg_t *cfg,
const char *name,
00630
unsigned int index);
00631
00640 DLLIMPORT
char * __export cfg_getstr(cfg_t *cfg,
const char *name);
00641
00647 DLLIMPORT
cfg_bool_t cfg_opt_getnbool(cfg_opt_t *opt,
unsigned int index);
00648
00656 DLLIMPORT
cfg_bool_t __export cfg_getnbool(cfg_t *cfg,
const char *name,
00657
unsigned int index);
00658
00667 DLLIMPORT
cfg_bool_t __export cfg_getbool(cfg_t *cfg,
const char *name);
00668
00674 DLLIMPORT cfg_t *cfg_opt_getnsec(cfg_opt_t *opt,
unsigned int index);
00675
00684 DLLIMPORT cfg_t * __export cfg_getnsec(cfg_t *cfg,
const char *name,
00685
unsigned int index);
00686
00694 DLLIMPORT cfg_t *cfg_opt_gettsec(cfg_opt_t *opt,
const char *title);
00695
00705 DLLIMPORT cfg_t * __export cfg_gettsec(cfg_t *cfg,
const char *name,
00706
const char *title);
00707
00718 DLLIMPORT cfg_t * __export cfg_getsec(cfg_t *cfg,
const char *name);
00719
00725 DLLIMPORT
unsigned int cfg_opt_size(cfg_opt_t *opt);
00726
00739 DLLIMPORT
unsigned int __export cfg_size(cfg_t *cfg,
const char *name);
00740
00747 DLLIMPORT
const char * __export cfg_title(cfg_t *cfg);
00748
00754 DLLIMPORT
int __export cfg_include(cfg_t *cfg, cfg_opt_t *opt,
int argc,
00755
const char **argv);
00756
00763 DLLIMPORT
char * __export cfg_tilde_expand(
const char *filename);
00764
00772 DLLIMPORT
int __export cfg_parse_boolean(
const char *s);
00773
00782 DLLIMPORT cfg_opt_t * __export cfg_getopt(cfg_t *cfg,
const char *name);
00783
00792 DLLIMPORT
void __export cfg_opt_setnint(cfg_opt_t *opt,
00793
long int value,
unsigned int index);
00794
00802 DLLIMPORT
void __export cfg_setint(cfg_t *cfg,
const char *name,
00803
long int value);
00804
00814 DLLIMPORT
void __export cfg_setnint(cfg_t *cfg,
const char *name,
00815
long int value,
unsigned int index);
00816
00825 DLLIMPORT
void __export cfg_opt_setnfloat(cfg_opt_t *opt,
00826
double value,
unsigned int index);
00827
00835 DLLIMPORT
void __export cfg_setfloat(cfg_t *cfg,
const char *name,
00836
double value);
00837
00847 DLLIMPORT
void __export cfg_setnfloat(cfg_t *cfg,
const char *name,
00848
double value,
unsigned int index);
00849
00858 DLLIMPORT
void __export cfg_opt_setnbool(cfg_opt_t *opt,
00859 cfg_bool_t value,
unsigned int index);
00860
00868 DLLIMPORT
void __export cfg_setbool(cfg_t *cfg,
const char *name,
00869 cfg_bool_t value);
00870
00880 DLLIMPORT
void __export cfg_setnbool(cfg_t *cfg,
const char *name,
00881 cfg_bool_t value,
unsigned int index);
00882
00892 DLLIMPORT
void __export cfg_opt_setnstr(cfg_opt_t *opt,
00893
const char *value,
unsigned int index);
00894
00903 DLLIMPORT
void __export cfg_setstr(cfg_t *cfg,
const char *name,
00904
const char *value);
00905
00916 DLLIMPORT
void __export cfg_setnstr(cfg_t *cfg,
const char *name,
00917
const char *value,
unsigned int index);
00918
00929 DLLIMPORT
void __export cfg_setlist(cfg_t *cfg,
const char *name,
00930
unsigned int nvalues, ...);
00931
00932
00943 DLLIMPORT
void __export cfg_addlist(cfg_t *cfg,
const char *name,
00944
unsigned int nvalues, ...);
00945
00958 DLLIMPORT
void cfg_opt_nprint_var(cfg_opt_t *opt,
unsigned int index,
00959 FILE *fp);
00960
00965 DLLIMPORT
void cfg_opt_print_indent(cfg_opt_t *opt, FILE *fp,
int indent);
00966
00977 DLLIMPORT
void cfg_opt_print(cfg_opt_t *opt, FILE *fp);
00978
00983 DLLIMPORT
void cfg_print_indent(cfg_t *cfg, FILE *fp,
int indent);
00984
00998 DLLIMPORT
void cfg_print(cfg_t *cfg, FILE *fp);
00999
01007 DLLIMPORT
cfg_print_func_t cfg_opt_set_print_func(cfg_opt_t *opt,
01008 cfg_print_func_t pf);
01009
01018 DLLIMPORT
cfg_print_func_t cfg_set_print_func(cfg_t *cfg,
const char *name,
01019 cfg_print_func_t pf);
01020
01029 DLLIMPORT
cfg_validate_callback_t cfg_set_validate_func(cfg_t *cfg,
01030
const char *name,
01031 cfg_validate_callback_t vf);
01032
01033
#ifdef __cplusplus
01034
}
01035
#endif
01036
01037
#endif
01038