2 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
17 static struct uci_context *ctx;
19 static void uci_usage(int argc, char **argv)
22 "Usage: %s [options] <command> [arguments]\n\n"
24 "\tshow [<config>[.<section>[.<option>]]]\n"
31 static void uci_show_section(struct uci_section *p)
34 const char *cname, *sname;
36 cname = p->config->name;
38 uci_foreach_entry(option, &p->options, o) {
39 printf("%s.%s.%s=%s\n", cname, sname, o->name, o->value);
43 static void uci_show_file(const char *name)
45 struct uci_config *cfg;
46 struct uci_section *p;
48 if (uci_load(ctx, name, &cfg) != UCI_OK) {
49 uci_perror(ctx, "uci_load");
53 uci_list_empty(&cfg->sections);
54 uci_foreach_entry(section, &cfg->sections, p) {
57 uci_unload(ctx, name);
60 static int uci_show(int argc, char **argv)
62 char **configs = uci_list_configs();
68 for (p = configs; *p; p++) {
69 fprintf(stderr, "# config: %s\n", *p);
76 static int uci_cmd(int argc, char **argv)
78 if (!strcasecmp(argv[0], "show"))
83 int main(int argc, char **argv)
89 uci_usage(argc, argv);
90 ret = uci_cmd(argc - 1, argv + 1);