X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=cli.c;h=61afa80ddfede1fbbe40eda65dcb97e116a30d95;hp=229352f3bf2124846cbf7d4511fbd6bb409ea5d2;hb=f18b4c6a13e288fae0fa0cdd92de63299e090dab;hpb=043baa606728c37cedf146c38a2bab0da0ae9f18 diff --git a/cli.c b/cli.c index 229352f..61afa80 100644 --- a/cli.c +++ b/cli.c @@ -19,6 +19,7 @@ #define MAX_ARGS 4 /* max command line arguments for batch mode */ +static const char *delimiter = " "; static const char *appname; static enum { CLI_FLAG_MERGE = (1 << 0), @@ -34,6 +35,7 @@ enum { /* section cmds */ CMD_GET, CMD_SET, + CMD_ADD_LIST, CMD_DEL, CMD_RENAME, CMD_REVERT, @@ -48,8 +50,68 @@ enum { CMD_HELP, }; +struct uci_type_list { + unsigned int idx; + const char *name; + struct uci_type_list *next; +}; + +static struct uci_type_list *type_list = NULL; +static char *typestr = NULL; +static const char *cur_section_ref = NULL; + static int uci_cmd(int argc, char **argv); +static void +uci_reset_typelist(void) +{ + struct uci_type_list *type; + while (type_list != NULL) { + type = type_list; + type_list = type_list->next; + free(type); + } + if (typestr) { + free(typestr); + typestr = NULL; + } + cur_section_ref = NULL; +} + +static char * +uci_lookup_section_ref(struct uci_section *s) +{ + struct uci_type_list *ti = type_list; + int maxlen; + + if (!s->anonymous) + return s->e.name; + + /* look up in section type list */ + while (ti) { + if (strcmp(ti->name, s->type) == 0) + break; + ti = ti->next; + } + if (!ti) { + ti = malloc(sizeof(struct uci_type_list)); + memset(ti, 0, sizeof(struct uci_type_list)); + ti->next = type_list; + type_list = ti; + ti->name = s->type; + } + + maxlen = strlen(s->type) + 1 + 2 + 10; + if (!typestr) { + typestr = malloc(maxlen); + } else { + typestr = realloc(typestr, maxlen); + } + sprintf(typestr, "@%s[%d]", ti->name, ti->idx); + ti->idx++; + return typestr; +} + static void uci_usage(void) { fprintf(stderr, @@ -61,13 +123,17 @@ static void uci_usage(void) "\tchanges []\n" "\tcommit []\n" "\tadd \n" + "\tadd_list .
.