+ 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_package *p = NULL;
+ struct uci_section *s = NULL;
+ struct uci_element *e = NULL;
+ struct uci_option *o = NULL;
+ char *section = NULL;
+ char *option = NULL;
+ char *value = NULL;
+ int ret = UCI_OK;
+
+ if (argc != 2)
+ return 255;
+
+ value = strchr(argv[1], '=');
+ if (value) {
+ *value = 0;
+ value++;
+ if (!uci_validate_text(value))
+ return 1;
+ }
+
+ if (value && (cmd != CMD_SET) && (cmd != CMD_ADD_LIST) && (cmd != CMD_RENAME))
+ return 1;
+
+ if (uci_lookup_ext(ctx, &e, argv[1]) != UCI_OK) {
+ cli_perror();
+ return 1;
+ }
+
+ switch(e->type) {
+ case UCI_TYPE_PACKAGE:
+ p = uci_to_package(e);
+ break;
+ 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;
+ }
+ if (s) {
+ section = s->e.name;
+ p = s->package;
+ }
+
+ switch(cmd) {
+ case CMD_GET:
+ switch(e->type) {
+ case UCI_TYPE_SECTION:
+ printf("%s\n", s->type);
+ break;
+ case UCI_TYPE_OPTION:
+ o = uci_to_option(e);
+ uci_show_value(o);
+ break;
+ default:
+ break;
+ }
+ /* throw the value to stdout */
+ break;
+ case CMD_RENAME:
+ ret = uci_rename(ctx, p, section, option, value);
+ break;
+ case CMD_REVERT:
+ ret = uci_revert(ctx, &p, section, option);
+ break;
+ case CMD_SET:
+ ret = uci_set(ctx, p, section, option, value, NULL);
+ break;
+ case CMD_ADD_LIST:
+ ret = uci_add_list(ctx, p, section, option, value, NULL);
+ break;
+ case CMD_DEL:
+ ret = uci_delete(ctx, p, section, option);
+ break;
+ }
+
+ /* no save necessary for get */
+ if ((cmd == CMD_GET) || (cmd == CMD_REVERT))