+ package_cmd(cmd, *p);
+ }
+
+ ret = 0;
+out:
+ free(configs);
+ return ret;
+}
+
+static int uci_do_add(int argc, char **argv)
+{
+ struct uci_package *p = NULL;
+ struct uci_section *s = NULL;
+ int ret;
+
+ if (argc != 3)
+ return 255;
+
+ ret = uci_load(ctx, argv[1], &p);
+ if (ret != UCI_OK)
+ goto done;
+
+ ret = uci_add_section(ctx, p, argv[2], &s);
+ if (ret != UCI_OK)
+ goto done;
+
+ ret = uci_save(ctx, p);
+
+done:
+ if (ret != UCI_OK)
+ cli_perror();
+ else if (s)
+ fprintf(stdout, "%s\n", s->e.name);
+
+ return ret;
+}
+
+static int uci_do_section_cmd(int cmd, int argc, char **argv)
+{
+ struct uci_element *e;
+ struct uci_ptr ptr;
+ int ret = UCI_OK;
+ int dummy;
+
+ if (argc != 2)
+ return 255;
+
+ if (uci_lookup_ptr(ctx, &ptr, argv[1], true) != UCI_OK) {
+ cli_perror();
+ return 1;
+ }
+
+ if (ptr.value && (cmd != CMD_SET) && (cmd != CMD_DEL) &&
+ (cmd != CMD_ADD_LIST) && (cmd != CMD_DEL_LIST) &&
+ (cmd != CMD_RENAME) && (cmd != CMD_REORDER))
+ return 1;
+
+ e = ptr.last;
+ switch(cmd) {
+ case CMD_GET:
+ if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
+ ctx->err = UCI_ERR_NOTFOUND;
+ cli_perror();
+ return 1;
+ }
+ switch(e->type) {
+ case UCI_TYPE_SECTION:
+ printf("%s\n", ptr.s->type);
+ break;
+ case UCI_TYPE_OPTION:
+ uci_show_value(ptr.o, false);
+ break;
+ default:
+ break;
+ }
+ /* throw the value to stdout */
+ break;
+ case CMD_RENAME:
+ ret = uci_rename(ctx, &ptr);
+ break;
+ case CMD_REVERT:
+ ret = uci_revert(ctx, &ptr);
+ break;
+ case CMD_SET:
+ ret = uci_set(ctx, &ptr);
+ break;
+ case CMD_ADD_LIST:
+ ret = uci_add_list(ctx, &ptr);
+ break;
+ case CMD_DEL_LIST:
+ ret = uci_del_list(ctx, &ptr);
+ break;
+ case CMD_REORDER:
+ if (!ptr.s || !ptr.value) {
+ ctx->err = UCI_ERR_NOTFOUND;
+ cli_perror();
+ return 1;
+ }
+ ret = uci_reorder_section(ctx, ptr.s, strtoul(ptr.value, NULL, 10));
+ break;
+ case CMD_DEL:
+ if (ptr.value && !sscanf(ptr.value, "%d", &dummy))
+ return 1;
+ ret = uci_delete(ctx, &ptr);
+ break;
+ }
+
+ /* no save necessary for get */
+ if ((cmd == CMD_GET) || (cmd == CMD_REVERT))
+ return 0;
+
+ /* save changes, but don't commit them yet */
+ if (ret == UCI_OK)
+ ret = uci_save(ctx, ptr.p);
+
+ if (ret != UCI_OK) {
+ cli_perror();
+ return 1;