From ca8edb3b65ae2be88278efac6ca7da1de964be88 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 23 Sep 2013 00:41:22 +0200 Subject: add menutree command Creating menus from the shell using the regular 'menu' command is rather complicated. This adds a 'menutree' command which creates a menu from a directory structure. In the directory structure each directory corresponds to a single menu entry. The directory contains the following files: title - A file containing the title of the entry as shown in the menu box - If present, the entry is a 'bool' entry. The file contains a variable name from which the current state of the bool is taken from and saved to. action - if present this file contains a shell script which is executed when when the entry is selected. If neither 'box' or 'action' are present this entry is considered a submenu containing more entries. Signed-off-by: Sascha Hauer --- commands/menutree.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 commands/menutree.c (limited to 'commands/menutree.c') diff --git a/commands/menutree.c b/commands/menutree.c new file mode 100644 index 0000000000..3b1a263584 --- /dev/null +++ b/commands/menutree.c @@ -0,0 +1,60 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include +#include +#include +#include + +static int do_menutree(int argc, char *argv[]) +{ + int opt, ret; + char *path = "/env/menu"; + + while ((opt = getopt(argc, argv, "m:")) > 0) { + switch (opt) { + case 'm': + path = optarg; + break; + } + } + + ret = menutree(path, 1); + + return ret; +} + +BAREBOX_CMD_HELP_START(menutree) +BAREBOX_CMD_HELP_USAGE("menutree [OPTIONS]\n") +"\n" +"Create a menu from a directory structure\n" +"Each menu entry is described by a subdirectory. Each subdirectory\n" +"can contain the following files which further describe the entry:\n" +"\n" +"title - A file containing the title of the entry as shown in the menu\n" +"box - If present, the entry is a 'bool' entry. The file contains a variable\n" +" name from which the current state of the bool is taken from and saved\n" +" to.\n" +"action - if present this file contains a shell script which is executed when\n" +" when the entry is selected.\n" +"If neither 'box' or 'action' are present this entry is considered a submenu\n" +"containing more entries.\n" +"\n" +"Options:\n" +" -m directory where the menu starts (/env/menu)\n" + +BAREBOX_CMD_HELP_END + + +BAREBOX_CMD_START(menutree) + .cmd = do_menutree, + .usage = "create a menu from a directory structure", + BAREBOX_CMD_HELP(cmd_menutree_help) +BAREBOX_CMD_END -- cgit v1.2.3