Lines Matching defs:config
10 #include "config.h"
27 static void config_parse(FILE *fp, config_t *config);
31 static section_t *section_find(const config_t *config, const char *section);
35 static entry_t *entry_find(const config_t *config, const char *section, const char *key);
46 config_t *config = calloc(1, sizeof(config_t));
47 if (!config) {
53 config->sections = list_new(section_free);
54 config_parse(fp, config);
58 return config;
61 void config_free(config_t *config) {
62 if (!config)
65 list_free(config->sections);
66 free(config);
69 bool config_has_section(const config_t *config, const char *section) {
70 assert(config != NULL);
73 return (section_find(config, section) != NULL);
76 bool config_has_key(const config_t *config, const char *section, const char *key) {
77 assert(config != NULL);
81 return (entry_find(config, section, key) != NULL);
84 int config_get_int(const config_t *config, const char *section, const char *key, int def_value) {
85 assert(config != NULL);
89 entry_t *entry = entry_find(config, section, key);
98 bool config_get_bool(const config_t *config, const char *section, const char *key, bool def_value) {
99 assert(config != NULL);
103 entry_t *entry = entry_find(config, section, key);
115 const char *config_get_string(const config_t *config, const char *section, const char *key, const char *def_value) {
116 assert(config != NULL);
120 entry_t *entry = entry_find(config, section, key);
127 void config_set_int(config_t *config, const char *section, const char *key, int value) {
128 assert(config != NULL);
134 config_set_string(config, section, key, value_str);
137 void config_set_bool(config_t *config, const char *section, const char *key, bool value) {
138 assert(config != NULL);
142 config_set_string(config, section, key, value ? "true" : "false");
145 void config_set_string(config_t *config, const char *section, const char *key, const char *value) {
146 section_t *sec = section_find(config, section);
149 list_append(config->sections, sec);
180 static void config_parse(FILE *fp, config_t *config) {
182 assert(config != NULL);
213 config_set_string(config, section, trim(line_ptr), trim(split + 1));
237 static section_t *section_find(const config_t *config, const char *section) {
238 for (const list_node_t *node = list_begin(config->sections); node != list_end(config->sections); node = list_next(node)) {
266 static entry_t *entry_find(const config_t *config, const char *section, const char *key) {
267 section_t *sec = section_find(config, section);