Browse Source

* config.[ch] : f2b_config_append() now returns pointer to added/found section

master
Alex 'AdUser' Z 9 years ago
parent
commit
12216b4d07
  1. 17
      src/config.c
  2. 6
      src/config.h

17
src/config.c

@ -191,7 +191,7 @@ f2b_config_load(const char *path) {
section = f2b_config_section_create(p);
if (section) {
skip_section = false;
f2b_config_append(config, section);
section = f2b_config_append(config, section);
} else {
skip_section = true;
f2b_log_msg(log_error, "unknown section at line %d: %s", linenum, p);
@ -240,9 +240,11 @@ f2b_config_free(f2b_config_t *config) {
FREE(config);
}
void
f2b_config_section_t *
f2b_config_append(f2b_config_t *config, f2b_config_section_t *section) {
f2b_config_section_t **s = NULL;
f2b_config_section_t *prev = NULL;
f2b_config_section_t **s = NULL;
assert(config != NULL);
assert(section != NULL);
@ -256,6 +258,15 @@ f2b_config_append(f2b_config_t *config, f2b_config_section_t *section) {
abort();
break;
}
if ((prev = f2b_config_section_find(*s, section->name)) != NULL) {
/* found section with this name */
free(section);
return prev;
}
/* not found, append */
section->next = *s;
*s = section;
return section;
}

6
src/config.h

@ -42,7 +42,7 @@ f2b_config_section_t * f2b_config_section_create(const char *line);
f2b_config_section_t * f2b_config_section_find (f2b_config_section_t *s, const char *name);
f2b_config_section_t * f2b_config_section_append(f2b_config_section_t *s, f2b_config_param_t *p);
f2b_config_t * f2b_config_load (const char *path);
void f2b_config_free (f2b_config_t *c);
void f2b_config_append(f2b_config_t *c, f2b_config_section_t *s);
f2b_config_t * f2b_config_load (const char *path);
void f2b_config_free (f2b_config_t *c);
f2b_config_section_t * f2b_config_append(f2b_config_t *c, f2b_config_section_t *s);
#endif /* CONFIG_H_ */

Loading…
Cancel
Save