]>
Commit | Line | Data |
---|---|---|
ed5bcfbe LP |
1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
2 | ||
3 | #ifndef fooconfparserhfoo | |
4 | #define fooconfparserhfoo | |
5 | ||
6 | #include <stdio.h> | |
7 | ||
8 | /* An abstract parser for simple, line based, shallow configuration | |
9 | * files consisting of variable assignments only. */ | |
10 | ||
11 | typedef int (*config_parser_cb_t)(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); | |
12 | ||
13 | /* Wraps info for parsing a specific configuration variable */ | |
14 | typedef struct ConfigItem { | |
15 | const char *lvalue; /* name of the variable */ | |
16 | config_parser_cb_t parse; /* Function that is called to parse the variable's value */ | |
17 | void *data; /* Where to store the variable's data */ | |
18 | const char *section; | |
19 | } ConfigItem; | |
20 | ||
21 | /* The configuration file parsing routine. Expects a table of | |
22 | * config_items in *t that is terminated by an item where lvalue is | |
23 | * NULL */ | |
87f0e418 | 24 | int config_parse(const char *filename, FILE *f, const char* const * sections, const ConfigItem *t, void *userdata); |
ed5bcfbe LP |
25 | |
26 | /* Generic parsers */ | |
27 | int config_parse_int(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); | |
28 | int config_parse_unsigned(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); | |
29 | int config_parse_size(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); | |
30 | int config_parse_bool(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); | |
31 | int config_parse_string(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); | |
034c6ed7 | 32 | int config_parse_path(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); |
57d42a5f | 33 | int config_parse_strv(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); |
ed5bcfbe LP |
34 | |
35 | #endif |