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 ab0f9b8..322d170 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;
 
        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);
        }
        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 (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);
        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);
        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);
                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);
 
        uci_list_add(&cfg->sections, &section->list);
        UCI_TRAP_RESTORE(ctx);
 
diff --git a/uci.h b/uci.h
index 65fb7d3..c5594d8 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;
        struct uci_list sections;
        struct uci_context *ctx;
        char *name;
+       /* private: */
+       int n_section;
 };
 
 struct uci_section
 };
 
 struct uci_section