+ uci_foreach_element(&p->saved_delta, e) {
+ struct uci_delta *h = uci_to_delta(e);
+ char *prefix = "";
+ char *op = "=";
+
+ switch(h->cmd) {
+ case UCI_CMD_REMOVE:
+ prefix = "-";
+ break;
+ case UCI_CMD_LIST_ADD:
+ op = "+=";
+ break;
+ case UCI_CMD_LIST_DEL:
+ 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", op);
+ uci_print_value(stdout, h->value);
+ }
+ printf("\n");
+ }
+}
+
+static int package_cmd(int cmd, char *tuple)
+{
+ struct uci_element *e = NULL;
+ struct uci_ptr ptr;
+ int ret = 1;
+
+ if (uci_lookup_ptr(ctx, &ptr, tuple, true) != UCI_OK) {
+ cli_perror();
+ return 1;
+ }
+
+ e = ptr.last;
+ switch(cmd) {
+ case CMD_CHANGES:
+ uci_show_changes(ptr.p);
+ break;
+ case CMD_COMMIT:
+ if (flags & CLI_FLAG_NOCOMMIT) {
+ ret = 0;
+ goto out;
+ }
+ if (uci_commit(ctx, &ptr.p, false) != UCI_OK) {
+ cli_perror();
+ goto out;
+ }
+ break;
+ case CMD_EXPORT:
+ if (uci_export(ctx, stdout, ptr.p, true) != UCI_OK) {
+ goto out;
+ }
+ break;
+ case CMD_SHOW:
+ if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
+ ctx->err = UCI_ERR_NOTFOUND;
+ cli_perror();
+ goto out;
+ }
+ switch(e->type) {
+ case UCI_TYPE_PACKAGE:
+ uci_show_package(ptr.p);
+ break;
+ case UCI_TYPE_SECTION:
+ uci_show_section(ptr.s);
+ break;
+ case UCI_TYPE_OPTION:
+ uci_show_option(ptr.o, true);
+ break;
+ default:
+ /* should not happen */
+ goto out;
+ }
+ break;
+ }
+
+ ret = 0;
+
+out:
+ if (ptr.p)
+ uci_unload(ctx, ptr.p);
+ return ret;
+}
+
+static int uci_do_import(int argc, char **argv)
+{
+ struct uci_package *package = NULL;
+ char *name = NULL;
+ int ret = UCI_OK;
+ bool merge = false;
+
+ if (argc > 2)
+ return 255;
+
+ if (argc == 2)
+ name = argv[1];
+ else if (flags & CLI_FLAG_MERGE)
+ /* need a package to merge */
+ return 255;
+
+ if (flags & CLI_FLAG_MERGE) {
+ if (uci_load(ctx, name, &package) != UCI_OK)
+ package = NULL;
+ else
+ merge = true;
+ }
+ ret = uci_import(ctx, input, name, &package, (name != NULL));
+ if (ret == UCI_OK) {
+ if (merge) {
+ ret = uci_save(ctx, package);
+ } else {
+ struct uci_element *e;
+ /* loop through all config sections and overwrite existing data */
+ uci_foreach_element(&ctx->root, e) {
+ struct uci_package *p = uci_to_package(e);
+ ret = uci_commit(ctx, &p, true);
+ }
+ }