add dynamically generated section names
authorFelix Fietkau <nbd@openwrt.org>
Mon, 21 Jan 2008 01:02:23 +0000 (02:02 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 21 Jan 2008 01:02:23 +0000 (02:02 +0100)
cli.c
list.c
uci.h

diff --git a/cli.c b/cli.c
index ab0f9b8890251ece59cdc41c7899fd1f2612ec38..322d170d3a613e70c18483eb89ed0fb7fcf86378 100644 (file)
--- 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 0b3dd947049cd2ea9c8c30e47e231afd6bc68283..00fca3f074a5075ac4c81abe0b3c8d556b68af7c 100644 (file)
--- 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(&section->list);
        uci_list_init(&section->options);
        section->type = uci_strdup(ctx, type);
-       if (name)
+       if (name && name[0])
                section->name = uci_strdup(ctx, name);
+       else
+               asprintf(&section->name, "cfg%d", cfg->n_section);
        uci_list_add(&cfg->sections, &section->list);
        UCI_TRAP_RESTORE(ctx);
 
diff --git a/uci.h b/uci.h
index 65fb7d34cb1fb00a8804de0a2197ef5fb4a01725..c5594d8c1aebe4f9b2e9868054c743f807b99232 100644 (file)
--- 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