remove uci_parse_tuple, preparation for adding a new api for lookups
[project/uci.git] / cli.c
diff --git a/cli.c b/cli.c
index cd82938..16306ff 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -155,14 +155,24 @@ static void uci_show_changes(struct uci_package *p)
 
        uci_foreach_element(&p->saved_history, e) {
                struct uci_history *h = uci_to_history(e);
+               char *prefix = "";
+               char *op = "=";
 
-               if (h->cmd == UCI_CMD_REMOVE)
-                       printf("-");
-               printf("%s.%s", p->e.name, h->section);
+               switch(h->cmd) {
+               case UCI_CMD_REMOVE:
+                       prefix = "-";
+                       break;
+               case UCI_CMD_LIST_ADD:
+                       op = "+=";
+                       break;
+               default:
+                       break;
+               }
+               printf("%s%s.%s", prefix, p->e.name, h->section);
                if (e->name)
                        printf(".%s", e->name);
                if (h->cmd != UCI_CMD_REMOVE)
-                       printf("=%s", h->value);
+                       printf("%s%s", op, h->value);
                printf("\n");
        }
 }
@@ -333,6 +343,7 @@ static int uci_do_section_cmd(int cmd, int argc, char **argv)
        char *option = NULL;
        char *value = NULL;
        int ret = UCI_OK;
+       char *str;
 
        if (argc != 2)
                return 255;
@@ -348,6 +359,21 @@ static int uci_do_section_cmd(int cmd, int argc, char **argv)
        if (value && (cmd != CMD_SET) && (cmd != CMD_ADD_LIST) && (cmd != CMD_RENAME))
                return 1;
 
+       do {
+               str = strchr(argv[1], '.'); /* look up section part */
+               if (!str)
+                       break;
+
+               str++;
+               str = strchr(str, '.'); /* look up option part */
+               if (!str)
+                       break;
+
+               /* separate option from the rest of the pointer */
+               *str = 0;
+               option = str + 1;
+       } while (0);
+
        if (uci_lookup_ext(ctx, &e, argv[1]) != UCI_OK) {
                cli_perror();
                return 1;
@@ -360,10 +386,6 @@ static int uci_do_section_cmd(int cmd, int argc, char **argv)
        case UCI_TYPE_SECTION:
                s = uci_to_section(e);
                break;
-       case UCI_TYPE_OPTION:
-               option = e->name;
-               s = uci_to_option(e)->section;
-               break;
        default:
                return 1;
        }