-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleconfig.h
54 lines (45 loc) · 1.48 KB
/
simpleconfig.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _SIMPLECONFIG_H
#define _SIMPLECONFIG_H
typedef void config_info_t;
typedef int (*config_get_t)(config_info_t *config, const char *key,
char *value, size_t valuesz);
typedef int (*config_set_t)(config_info_t *config, const char *key,
const char *value);
typedef int (*config_parse_t)(const char *filename, config_info_t **config);
typedef int (*config_free_t)(config_info_t *config);
typedef void (*config_dump_t)(config_info_t *config, FILE *fp);
/*
* We use an abstract object here so we do not have to link loadable
* modules against the configuration library.
*/
typedef struct {
config_get_t get;
config_set_t set;
config_parse_t parse;
config_free_t free;
config_dump_t dump;
config_info_t *info;
} config_object_t;
/*
* These macros may be called from within a loadable module
*/
#define sc_get(obj, key, value, valuesz) \
obj->get(obj->info, key, value, valuesz)
#define sc_set(obj, key, value) \
obj->set(obj->info, key, value)
#define sc_parse(obj, filename) \
obj->parse(filename, &obj->info)
#define sc_free(obj) \
obj->free(obj->info)
#define sc_dump(obj, fp) \
obj->dump(obj->info, fp)
/*
* Do not call the below functions from loadable modules. Doing so
* requires linking the configuration library in to the modules, which
* is what we want to avoid.
*/
/* Returns a copy of our simple config object */
config_object_t *sc_init(void);
/* Frees a previously-allocated copy of our simple config object */
void sc_release(config_object_t *c);
#endif