From 4455b4183dc418db0cc863ae416db5eee193fc40 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 18 Jul 2012 23:32:10 +0200 Subject: [PATCH] Config: Allow relative top-level sections --- ucw/conf-section.c | 10 ++++++++-- ucw/conf.h | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ucw/conf-section.c b/ucw/conf-section.c index c7bd3247..f25657d2 100644 --- a/ucw/conf-section.c +++ b/ucw/conf-section.c @@ -92,7 +92,7 @@ inspect_section(struct cf_section *sec) } void -cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown) +cf_declare_rel_section(const char *name, struct cf_section *sec, void *ptr, uns allow_unknown) { struct cf_context *cc = cf_obtain_context(); if (!cc->sections.cfg) @@ -106,7 +106,7 @@ cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown) ci->cls = CC_SECTION; ci->name = name; ci->number = 1; - ci->ptr = NULL; + ci->ptr = ptr; ci->u.sec = sec; inspect_section(sec); if (allow_unknown) @@ -120,6 +120,12 @@ cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown) } } +void +cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown) +{ + cf_declare_rel_section(name, sec, NULL, allow_unknown); +} + void cf_init_section(const char *name, struct cf_section *sec, void *ptr, uns do_bzero) { diff --git a/ucw/conf.h b/ucw/conf.h index 23c9c5cc..0ff99130 100644 --- a/ucw/conf.h +++ b/ucw/conf.h @@ -493,6 +493,12 @@ void cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj) * configuration contexts simultaneously. **/ void cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown); +/** + * Like @cf_declare_section(), but instead of item pointers, the section + * contains offsets relative to @ptr. In other words, it does the same + * as `CF_SECTION`, but for top-level sections. + **/ +void cf_declare_rel_section(const char *name, struct cf_section *sec, void *ptr, uns allow_unknown); /** * If you have a section in a structure and you want to initialize it * (eg. if you want a copy of default values outside the configuration), -- 2.39.5