summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-08-21 20:09:51 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-08-30 21:06:02 +0200
commit0d35c3c8a0c2a1f1ff06eac20a12af0186753bc4 (patch)
treea3a82df9c3b83f36b2fecbd9faadb6b55fd19efd /commands
parentc0477d8233369aed15a48239886ffa679802c48a (diff)
downloadbarebox-0d35c3c8a0c2a1f1ff06eac20a12af0186753bc4.tar.gz
barebox-0d35c3c8a0c2a1f1ff06eac20a12af0186753bc4.tar.xz
menu: simplify usage for clients
Clients now only have to call menu_add_submenu or menu_add_command_entry instead of allocating many strings. This also fixes some problems in the menu code. The priv field in struct menu_entry was a pointer to struct menu or a pointer to an allocated string. It was never freed, only had to be freed when it was an allocated string. The reference to a submenu is now kept as a string and not to the menu itself. The code checked the existence of the submenu when creating it, but crashed when the submenu was removed and referenced afterwards. Now the code hapily allows references to nonexistant menus but complains during runtime when the menu is not there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/menu.c48
1 files changed, 7 insertions, 41 deletions
diff --git a/commands/menu.c b/commands/menu.c
index f3bd78de72..f734db3874 100644
--- a/commands/menu.c
+++ b/commands/menu.c
@@ -26,6 +26,7 @@
#include <menu.h>
#include <getopt.h>
#include <errno.h>
+#include <linux/err.h>
typedef enum {
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
@@ -66,8 +67,7 @@ struct cmd_menu {
static int do_menu_entry_add(struct cmd_menu *cm)
{
struct menu_entry *me;
- struct menu *m, *sm;
- int ret = -ENOMEM;
+ struct menu *m;
if (!cm->menu || (!cm->command && !cm->submenu) || !cm->description)
return -EINVAL;
@@ -79,50 +79,16 @@ static int do_menu_entry_add(struct cmd_menu *cm)
return -EINVAL;
}
- me = menu_entry_alloc();
+ if (cm->submenu)
+ me = menu_add_submenu(m, cm->submenu, cm->description);
+ else
+ me = menu_add_command_entry(m, cm->description, cm->command);
if (!me)
- return -ENOMEM;
-
- if (cm->submenu) {
- me->action = menu_action_show;
-
- sm = menu_get_by_name(cm->submenu);
-
- if (!sm) {
- eprintf("SubMenu '%s' not found\n", cm->menu);
- goto free;
- }
-
- me->priv = sm;
- } else {
- me->action = menu_action_run;
-
- me->priv = strdup(cm->command);
- if (!me->priv)
- goto free;
- }
-
- me->display = strdup(cm->description);
- if (!me->display)
- goto free;
-
- ret = menu_add_entry(m, me);
-
- if (ret)
- goto free;
+ return PTR_ERR(me);
me->non_re_ent = !cm->re_entrant;
return 0;
-
-free:
- eputs("Entry add fail\n");
-
- free(me->priv);
-
- menu_entry_free(me);
-
- return ret;
}
/*