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. 15
      src/config.c
  2. 2
      src/config.h

15
src/config.c

@ -191,7 +191,7 @@ f2b_config_load(const char *path) {
section = f2b_config_section_create(p); section = f2b_config_section_create(p);
if (section) { if (section) {
skip_section = false; skip_section = false;
f2b_config_append(config, section); section = f2b_config_append(config, section);
} else { } else {
skip_section = true; skip_section = true;
f2b_log_msg(log_error, "unknown section at line %d: %s", linenum, p); 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); FREE(config);
} }
void f2b_config_section_t *
f2b_config_append(f2b_config_t *config, f2b_config_section_t *section) { f2b_config_append(f2b_config_t *config, f2b_config_section_t *section) {
f2b_config_section_t *prev = NULL;
f2b_config_section_t **s = NULL; f2b_config_section_t **s = NULL;
assert(config != NULL); assert(config != NULL);
assert(section != NULL); assert(section != NULL);
@ -256,6 +258,15 @@ f2b_config_append(f2b_config_t *config, f2b_config_section_t *section) {
abort(); abort();
break; 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; section->next = *s;
*s = section; *s = section;
return section;
} }

2
src/config.h

@ -44,5 +44,5 @@ f2b_config_section_t * f2b_config_section_append(f2b_config_section_t *s, f2b_co
f2b_config_t * f2b_config_load (const char *path); f2b_config_t * f2b_config_load (const char *path);
void f2b_config_free (f2b_config_t *c); void f2b_config_free (f2b_config_t *c);
void f2b_config_append(f2b_config_t *c, f2b_config_section_t *s); f2b_config_section_t * f2b_config_append(f2b_config_t *c, f2b_config_section_t *s);
#endif /* CONFIG_H_ */ #endif /* CONFIG_H_ */

Loading…
Cancel
Save