X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;ds=sidebyside;f=cli.c;h=61afa80ddfede1fbbe40eda65dcb97e116a30d95;hb=f18b4c6a13e288fae0fa0cdd92de63299e090dab;hp=9bdd5532b808dbecde909ee1e2b216783797626c;hpb=d0cd0868cd5e071df9f560455542f6df041056ad;p=project%2Fuci.git diff --git a/cli.c b/cli.c index 9bdd553..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, @@ -43,12 +45,73 @@ enum { CMD_EXPORT, CMD_COMMIT, /* other cmds */ + CMD_ADD, CMD_IMPORT, 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, @@ -58,13 +121,19 @@ static void uci_usage(void) "\texport []\n" "\timport []\n" "\tchanges []\n" + "\tcommit []\n" + "\tadd \n" + "\tadd_list .
.