From: Felix Fietkau Date: Mon, 21 Jan 2008 01:02:23 +0000 (+0100) Subject: add dynamically generated section names X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=commitdiff_plain;h=508525c69e08a96031ed24f2d09e3bc2d1d33fca add dynamically generated section names --- diff --git a/cli.c b/cli.c index ab0f9b8..322d170 100644 --- a/cli.c +++ b/cli.c @@ -35,6 +35,7 @@ static void uci_show_section(struct uci_section *p) cname = p->config->name; sname = p->name; + printf("%s.%s=%s\n", cname, sname, p->type); uci_foreach_entry(option, &p->options, o) { printf("%s.%s.%s=%s\n", cname, sname, o->name, o->value); } diff --git a/list.c b/list.c index 0b3dd94..00fca3f 100644 --- a/list.c +++ b/list.c @@ -104,13 +104,16 @@ static struct uci_section *uci_add_section(struct uci_config *cfg, const char *t struct uci_context *ctx = cfg->ctx; UCI_TRAP_SAVE(ctx, error); + cfg->n_section++; section = (struct uci_section *) uci_malloc(ctx, sizeof(struct uci_section)); section->config = cfg; uci_list_init(§ion->list); uci_list_init(§ion->options); section->type = uci_strdup(ctx, type); - if (name) + if (name && name[0]) section->name = uci_strdup(ctx, name); + else + asprintf(§ion->name, "cfg%d", cfg->n_section); uci_list_add(&cfg->sections, §ion->list); UCI_TRAP_RESTORE(ctx); diff --git a/uci.h b/uci.h index 65fb7d3..c5594d8 100644 --- a/uci.h +++ b/uci.h @@ -125,6 +125,8 @@ struct uci_config struct uci_list sections; struct uci_context *ctx; char *name; + /* private: */ + int n_section; }; struct uci_section