Lely core libraries  2.2.5
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 
29 struct __config;
30 #ifndef __cplusplus
32 typedef struct __config config_t;
33 #endif
34 
35 enum {
37  CONFIG_CASE = 1 << 0
38 };
39 
40 // The file location struct from <lely/util/diag.h>.
41 struct floc;
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
56 typedef void config_foreach_func_t(const char *section, const char *key,
57  const char *value, void *data);
58 
59 void *__config_alloc(void);
60 void __config_free(void *ptr);
61 struct __config *__config_init(struct __config *config, int flags);
62 void __config_fini(struct __config *config);
63 
74 config_t *config_create(int flags);
75 
77 void config_destroy(config_t *config);
78 
93 size_t config_get_sections(
94  const config_t *config, size_t n, const char **sections);
95 
111 size_t config_get_keys(const config_t *config, const char *section, size_t n,
112  const char **keys);
113 
124 const char *config_get(
125  const config_t *config, const char *section, const char *key);
126 
144 const char *config_set(config_t *config, const char *section, const char *key,
145  const char *value);
146 
155 void config_foreach(const config_t *config, config_foreach_func_t *func,
156  void *data);
157 
166 size_t config_parse_ini_file(config_t *config, const char *filename);
167 
184 size_t config_parse_ini_text(config_t *config, const char *begin,
185  const char *end, struct floc *at);
186 
195 size_t config_print_ini_file(const config_t *config, const char *filename);
196 
215 size_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_
const char * config_get(const config_t *config, const char *section, const char *key)
Retrieves a key from a configuration struct.
Definition: config.c:188
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:47
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:179
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:233
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:213
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:144
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:75
@ CONFIG_CASE
Section and key names are case-insensitive.
Definition: config.h:37
config_t * config_create(int flags)
Creates a new configuration struct with an unnamed empty root section.
Definition: config.c:110
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:213
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:161
void config_destroy(config_t *config)
Destroys a configuration struct.
Definition: config.c:135
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:35
A location in a text file.
Definition: diag.h:31