Lely core libraries 2.3.4
config.h
Go to the documentation of this file.
1
22#ifndef LELY_UTIL_CONFIG_H_
23#define LELY_UTIL_CONFIG_H_
24
25#include <lely/util/util.h>
26
27#include <stddef.h>
28
29struct __config;
30#ifndef __cplusplus
32typedef struct __config config_t;
33#endif
34
35enum {
37 CONFIG_CASE = 1 << 0
38};
39
40// The file location struct from <lely/util/diag.h>.
41struct floc;
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
56typedef void config_foreach_func_t(const char *section, const char *key,
57 const char *value, void *data);
58
59void *__config_alloc(void);
60void __config_free(void *ptr);
61struct __config *__config_init(struct __config *config, int flags);
62void __config_fini(struct __config *config);
63
74config_t *config_create(int flags);
75
77void config_destroy(config_t *config);
78
94 const config_t *config, size_t n, const char **sections);
95
111size_t config_get_keys(const config_t *config, const char *section, size_t n,
112 const char **keys);
113
124const char *config_get(
125 const config_t *config, const char *section, const char *key);
126
144const char *config_set(config_t *config, const char *section, const char *key,
145 const char *value);
146
155void config_foreach(const config_t *config, config_foreach_func_t *func,
156 void *data);
157
166size_t config_parse_ini_file(config_t *config, const char *filename);
167
184size_t config_parse_ini_text(config_t *config, const char *begin,
185 const char *end, struct floc *at);
186
195size_t config_print_ini_file(const config_t *config, const char *filename);
196
215size_t config_print_ini_text(const config_t *config, char **pbegin, char *end);
216
217#ifdef __cplusplus
218}
219#endif
220
221#endif // !LELY_UTIL_CONFIG_H_
size_t config_parse_ini_file(config_t *config, const char *filename)
Parses an INI file and adds the keys to a configuration struct.
Definition: config_ini.c:50
const char * config_set(config_t *config, const char *section, const char *key, const char *value)
Sets a key in or removes a key from a configuration struct.
Definition: config.c:218
size_t config_print_ini_file(const config_t *config, const char *filename)
Prints a configuration struct to an INI file.
Definition: config_ini.c:182
void config_foreach(const config_t *config, config_foreach_func_t *func, void *data)
Invokes a function for each key in a configuration struct.
Definition: config.c:238
size_t config_get_sections(const config_t *config, size_t n, const char **sections)
Retrieves a list of section names from a configuration struct.
Definition: config.c:149
void config_foreach_func_t(const char *section, const char *key, const char *value, void *data)
The type of a function called by config_foreach() for each key in a configuration struct.
Definition: config.h:56
size_t config_parse_ini_text(config_t *config, const char *begin, const char *end, struct floc *at)
Parses a string in INI-format and adds the keys to a configuration struct.
Definition: config_ini.c:78
config_t * config_create(int flags)
Creates a new configuration struct with an unnamed empty root section.
Definition: config.c:115
@ CONFIG_CASE
Section and key names are case-insensitive.
Definition: config.h:37
size_t config_print_ini_text(const config_t *config, char **pbegin, char *end)
Prints a configuration struct in INI-format to a memory buffer.
Definition: config_ini.c:216
size_t config_get_keys(const config_t *config, const char *section, size_t n, const char **keys)
Retrieves a list of key names from a section in a configuration struct.
Definition: config.c:166
const char * config_get(const config_t *config, const char *section, const char *key)
Retrieves a key from a configuration struct.
Definition: config.c:193
void config_destroy(config_t *config)
Destroys a configuration struct.
Definition: config.c:140
This is the public header file of the utilities library.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A configuration struct.
Definition: config.c:38
A location in a text file.
Definition: diag.h:39