From: Felix Fietkau Date: Sun, 27 Jan 2008 23:10:55 +0000 (+0100) Subject: implement uci get X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fuci.git;a=commitdiff_plain;h=e6279f87129e65c469a29d606a4b6afd7b7207b8 implement uci get --- diff --git a/cli.c b/cli.c index b7ddd51..4e0c5b7 100644 --- a/cli.c +++ b/cli.c @@ -94,12 +94,54 @@ static int uci_do_export(int argc, char **argv) return 0; } + + +static int uci_do_get(int argc, char **argv) +{ + char *package = NULL; + char *section = NULL; + char *option = NULL; + struct uci_package *p = NULL; + struct uci_element *e = NULL; + char *value = NULL; + + package = strtok(argv[1], "."); + if (!package) + return 1; + + section = strtok(NULL, "."); + if (section) + option = strtok(NULL, "."); + + if (uci_load(ctx, package, &p) != UCI_OK) { + uci_perror(ctx, "uci"); + return 1; + } + if (uci_lookup(ctx, &e, package, section, option) != UCI_OK) + return 1; + switch(e->type) { + case UCI_TYPE_SECTION: + value = uci_to_section(e)->type; + break; + case UCI_TYPE_OPTION: + value = uci_to_option(e)->value; + break; + default: + /* should not happen */ + return 1; + } + printf("%s\n", value); + return 0; +} + static int uci_cmd(int argc, char **argv) { if (!strcasecmp(argv[0], "show")) return uci_show(argc, argv); if (!strcasecmp(argv[0], "export")) return uci_do_export(argc, argv); + if (!strcasecmp(argv[0], "get")) + return uci_do_get(argc, argv); return 255; } diff --git a/uci.h b/uci.h index a6572c5..021e5b3 100644 --- a/uci.h +++ b/uci.h @@ -144,9 +144,9 @@ extern char **uci_list_configs(struct uci_context *ctx); /* UCI data structures */ enum uci_type { - uci_type_package = 0, - uci_type_section = 1, - uci_type_option = 2 + UCI_TYPE_PACKAGE = 0, + UCI_TYPE_SECTION = 1, + UCI_TYPE_OPTION = 2 }; struct uci_element @@ -290,6 +290,11 @@ struct uci_history /* returns true if a list is empty */ #define uci_list_empty(list) ((list)->next == (list)) +/* wrappers for dynamic type handling */ +#define uci_type_package UCI_TYPE_PACKAGE +#define uci_type_section UCI_TYPE_SECTION +#define uci_type_option UCI_TYPE_OPTION + /* element typecasting */ #ifdef UCI_DEBUG_TYPECAST static const char *uci_typestr[] = {