2010-08-20 08:22:47 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2009-2010 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; version 2 of
|
|
|
|
* the License.
|
|
|
|
*
|
|
|
|
* 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 <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <environment.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <menu.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <xfuncs.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <readkey.h>
|
2010-09-17 13:45:53 +00:00
|
|
|
#include <clock.h>
|
2010-08-21 18:09:51 +00:00
|
|
|
#include <linux/err.h>
|
2012-04-07 03:00:15 +00:00
|
|
|
#include <libbb.h>
|
2010-08-20 08:22:47 +00:00
|
|
|
|
2010-08-21 16:49:55 +00:00
|
|
|
static LIST_HEAD(menus);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
struct menu* menu_get_menus(void)
|
|
|
|
{
|
2010-08-21 16:49:55 +00:00
|
|
|
if (list_empty(&menus))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return list_entry(&menus, struct menu, list);
|
2010-08-20 08:22:47 +00:00
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_get_menus);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
void menu_free(struct menu *m)
|
|
|
|
{
|
2010-08-21 15:03:20 +00:00
|
|
|
struct menu_entry *me, *tmp;
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
if (!m)
|
|
|
|
return;
|
|
|
|
free(m->name);
|
|
|
|
free(m->display);
|
2010-09-17 13:45:53 +00:00
|
|
|
free(m->auto_display);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
2010-08-21 16:04:33 +00:00
|
|
|
list_for_each_entry_safe(me, tmp, &m->entries, list)
|
2010-08-21 15:03:20 +00:00
|
|
|
menu_entry_free(me);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
free(m);
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_free);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
int menu_add(struct menu *m)
|
|
|
|
{
|
|
|
|
if (!m || !m->name)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (menu_get_by_name(m->name))
|
|
|
|
return -EEXIST;
|
|
|
|
|
2010-08-21 16:49:55 +00:00
|
|
|
list_add_tail(&m->list, &menus);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_add);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
void menu_remove(struct menu *m)
|
|
|
|
{
|
|
|
|
if (!m)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_del(&m->list);
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_remove);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
int menu_add_entry(struct menu *m, struct menu_entry *me)
|
|
|
|
{
|
|
|
|
if (!m || !me || !me->display)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
m->nb_entries++;
|
|
|
|
me->num = m->nb_entries;
|
2010-08-21 16:04:33 +00:00
|
|
|
list_add_tail(&me->list, &m->entries);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_add_entry);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
void menu_remove_entry(struct menu *m, struct menu_entry *me)
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
if (!m || !me)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m->nb_entries--;
|
|
|
|
list_del(&me->list);
|
|
|
|
|
2010-08-21 16:27:31 +00:00
|
|
|
list_for_each_entry(me, &m->entries, list)
|
2010-08-20 08:22:47 +00:00
|
|
|
me->num = i++;
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_remove_entry);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
struct menu* menu_get_by_name(char *name)
|
|
|
|
{
|
|
|
|
struct menu* m;
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
return NULL;
|
|
|
|
|
2010-08-21 16:49:55 +00:00
|
|
|
list_for_each_entry(m, &menus, list) {
|
2010-08-20 08:22:47 +00:00
|
|
|
if(strcmp(m->name, name) == 0)
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_get_by_name);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
struct menu_entry* menu_entry_get_by_num(struct menu* m, int num)
|
|
|
|
{
|
|
|
|
struct menu_entry* me;
|
|
|
|
|
|
|
|
if (!m || num < 1 || num > m->nb_entries)
|
|
|
|
return NULL;
|
|
|
|
|
2010-08-21 16:27:31 +00:00
|
|
|
list_for_each_entry(me, &m->entries, list) {
|
2010-08-20 08:22:47 +00:00
|
|
|
if(me->num == num)
|
|
|
|
return me;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_entry_get_by_num);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
void menu_entry_free(struct menu_entry *me)
|
|
|
|
{
|
|
|
|
if (!me)
|
|
|
|
return;
|
|
|
|
|
2010-08-21 18:09:51 +00:00
|
|
|
me->free(me);
|
2010-08-20 08:22:47 +00:00
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_entry_free);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
2012-06-27 18:43:05 +00:00
|
|
|
static void __print_entry(const char *str)
|
|
|
|
{
|
|
|
|
static char outstr[256];
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_SHELL_HUSH)) {
|
|
|
|
process_escape_sequence(str, outstr, 256);
|
|
|
|
puts(outstr);
|
|
|
|
} else {
|
|
|
|
puts(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 13:45:54 +00:00
|
|
|
static void print_menu_entry(struct menu *m, struct menu_entry *me,
|
|
|
|
int selected)
|
2010-08-20 08:22:47 +00:00
|
|
|
{
|
2013-06-17 22:23:57 +00:00
|
|
|
gotoXY(3, me->num + 1);
|
2010-09-17 13:45:54 +00:00
|
|
|
|
|
|
|
if (me->type == MENU_ENTRY_BOX) {
|
|
|
|
if (me->box_state)
|
|
|
|
puts("[*]");
|
|
|
|
else
|
|
|
|
puts("[ ]");
|
|
|
|
} else {
|
|
|
|
puts(" ");
|
|
|
|
}
|
|
|
|
|
2013-06-17 05:32:59 +00:00
|
|
|
printf(" %2d: ", me->num);
|
2012-04-07 03:00:15 +00:00
|
|
|
if (selected)
|
|
|
|
puts("\e[7m");
|
2012-06-27 18:43:05 +00:00
|
|
|
|
|
|
|
__print_entry(me->display);
|
2010-09-17 13:45:54 +00:00
|
|
|
|
|
|
|
if (selected)
|
2012-04-07 03:00:15 +00:00
|
|
|
puts("\e[m");
|
2010-08-20 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int menu_set_selected_entry(struct menu *m, struct menu_entry* me)
|
|
|
|
{
|
|
|
|
struct menu_entry* tmp;
|
|
|
|
|
|
|
|
if (!m || !me)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-08-21 16:27:31 +00:00
|
|
|
list_for_each_entry(tmp, &m->entries, list) {
|
2010-08-20 08:22:47 +00:00
|
|
|
if(me == tmp) {
|
|
|
|
m->selected = me;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_set_selected_entry);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
int menu_set_selected(struct menu *m, int num)
|
|
|
|
{
|
|
|
|
struct menu_entry *me;
|
|
|
|
|
|
|
|
me = menu_entry_get_by_num(m, num);
|
|
|
|
|
|
|
|
if (!me)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
m->selected = me;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_set_selected);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
2010-09-17 13:45:53 +00:00
|
|
|
int menu_set_auto_select(struct menu *m, int delay)
|
|
|
|
{
|
|
|
|
if (!m)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
m->auto_select = delay;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_set_auto_select);
|
2010-09-17 13:45:53 +00:00
|
|
|
|
2010-08-20 08:22:47 +00:00
|
|
|
static void print_menu(struct menu *m)
|
|
|
|
{
|
|
|
|
struct menu_entry *me;
|
|
|
|
|
|
|
|
clear();
|
2013-06-17 22:23:57 +00:00
|
|
|
gotoXY(2, 1);
|
2010-08-20 08:22:47 +00:00
|
|
|
if(m->display) {
|
2012-06-27 18:43:05 +00:00
|
|
|
__print_entry(m->display);
|
2010-08-20 08:22:47 +00:00
|
|
|
} else {
|
|
|
|
puts("Menu : ");
|
|
|
|
puts(m->name);
|
|
|
|
}
|
|
|
|
|
2010-08-21 16:27:31 +00:00
|
|
|
list_for_each_entry(me, &m->entries, list) {
|
2010-08-20 08:22:47 +00:00
|
|
|
if(m->selected != me)
|
|
|
|
print_menu_entry(m, me, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m->selected) {
|
2010-08-21 16:04:33 +00:00
|
|
|
m->selected = list_first_entry(&m->entries,
|
2010-08-20 08:22:47 +00:00
|
|
|
struct menu_entry, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_menu_entry(m, m->selected, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_show(struct menu *m)
|
|
|
|
{
|
2012-04-23 11:12:31 +00:00
|
|
|
int ch, ch_previous = 0;
|
2010-09-17 13:45:53 +00:00
|
|
|
int countdown;
|
|
|
|
int auto_display_len = 16;
|
|
|
|
uint64_t start, second;
|
2010-08-20 08:22:47 +00:00
|
|
|
|
2010-08-21 16:04:33 +00:00
|
|
|
if(!m || list_empty(&m->entries))
|
2010-08-20 08:22:47 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
print_menu(m);
|
|
|
|
|
2010-09-17 13:45:53 +00:00
|
|
|
countdown = m->auto_select;
|
|
|
|
if (m->auto_select >= 0) {
|
2013-06-17 22:23:57 +00:00
|
|
|
gotoXY(3, m->nb_entries + 2);
|
2010-09-17 13:45:53 +00:00
|
|
|
if (!m->auto_display) {
|
|
|
|
printf("Auto Select in");
|
|
|
|
} else {
|
|
|
|
auto_display_len = strlen(m->auto_display);
|
2013-02-25 16:46:48 +00:00
|
|
|
printf("%s", m->auto_display);
|
2010-09-17 13:45:53 +00:00
|
|
|
}
|
|
|
|
printf(" %2d", countdown--);
|
|
|
|
}
|
|
|
|
|
|
|
|
start = get_time_ns();
|
|
|
|
second = start;
|
|
|
|
while (m->auto_select > 0 && !is_timeout(start, m->auto_select * SECOND)) {
|
|
|
|
if (tstc()) {
|
|
|
|
m->auto_select = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_timeout(second, SECOND)) {
|
|
|
|
printf("\b\b%2d", countdown--);
|
|
|
|
second += SECOND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 22:23:57 +00:00
|
|
|
gotoXY(3, m->nb_entries + 2);
|
2010-09-17 13:45:53 +00:00
|
|
|
printf("%*c", auto_display_len + 4, ' ');
|
|
|
|
|
2013-06-17 22:23:57 +00:00
|
|
|
gotoXY(3, m->selected->num + 1);
|
2010-09-17 13:45:53 +00:00
|
|
|
|
2010-08-20 08:22:47 +00:00
|
|
|
do {
|
2012-06-24 12:53:10 +00:00
|
|
|
struct menu_entry *old_selected = m->selected;
|
|
|
|
int repaint = 0;
|
|
|
|
|
2010-09-17 13:45:53 +00:00
|
|
|
if (m->auto_select >= 0)
|
2014-02-14 10:23:57 +00:00
|
|
|
ch = BB_KEY_RETURN;
|
2010-09-17 13:45:53 +00:00
|
|
|
else
|
2012-06-24 12:45:55 +00:00
|
|
|
ch = read_key();
|
2010-09-17 13:45:53 +00:00
|
|
|
|
|
|
|
m->auto_select = -1;
|
|
|
|
|
2012-06-24 12:45:55 +00:00
|
|
|
switch (ch) {
|
2012-08-05 05:06:00 +00:00
|
|
|
case '0' ... '9': {
|
|
|
|
struct menu_entry *me;
|
|
|
|
int num = ch - '0';
|
|
|
|
int next_num = m->selected->num + 10;
|
|
|
|
if (!num)
|
|
|
|
num = 10;
|
|
|
|
|
|
|
|
if (ch_previous == ch && next_num <= m->nb_entries)
|
|
|
|
num = next_num;
|
|
|
|
|
|
|
|
me = menu_entry_get_by_num(m, num);
|
|
|
|
if (me) {
|
|
|
|
m->selected = me;
|
|
|
|
repaint = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_UP:
|
2010-08-20 08:22:47 +00:00
|
|
|
m->selected = list_entry(m->selected->list.prev, struct menu_entry,
|
|
|
|
list);
|
2010-08-21 16:04:33 +00:00
|
|
|
if (&(m->selected->list) == &(m->entries)) {
|
2010-08-20 08:22:47 +00:00
|
|
|
m->selected = list_entry(m->selected->list.prev, struct menu_entry,
|
|
|
|
list);
|
|
|
|
}
|
2012-06-24 12:53:10 +00:00
|
|
|
repaint = 1;
|
2010-08-20 08:22:47 +00:00
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_DOWN:
|
2010-08-20 08:22:47 +00:00
|
|
|
m->selected = list_entry(m->selected->list.next, struct menu_entry,
|
|
|
|
list);
|
2010-08-21 16:04:33 +00:00
|
|
|
if (&(m->selected->list) == &(m->entries)) {
|
2010-08-20 08:22:47 +00:00
|
|
|
m->selected = list_entry(m->selected->list.next, struct menu_entry,
|
|
|
|
list);
|
|
|
|
}
|
2012-06-24 12:53:10 +00:00
|
|
|
repaint = 1;
|
2010-08-20 08:22:47 +00:00
|
|
|
break;
|
2010-09-17 13:45:54 +00:00
|
|
|
case ' ':
|
|
|
|
if (m->selected->type != MENU_ENTRY_BOX)
|
|
|
|
break;
|
|
|
|
m->selected->box_state = !m->selected->box_state;
|
|
|
|
if (m->selected->action)
|
|
|
|
m->selected->action(m, m->selected);
|
2012-06-24 12:53:10 +00:00
|
|
|
repaint = 1;
|
2010-09-17 13:45:54 +00:00
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_ENTER:
|
|
|
|
if (ch_previous == BB_KEY_RETURN)
|
2012-04-23 11:12:31 +00:00
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_RETURN:
|
|
|
|
if (ch_previous == BB_KEY_ENTER)
|
2012-04-23 11:12:31 +00:00
|
|
|
break;
|
2010-08-20 08:22:47 +00:00
|
|
|
clear();
|
|
|
|
gotoXY(1,1);
|
2013-06-17 22:24:16 +00:00
|
|
|
if (m->selected->action)
|
|
|
|
m->selected->action(m, m->selected);
|
2010-08-20 08:22:47 +00:00
|
|
|
if (m->selected->non_re_ent)
|
|
|
|
return m->selected->num;
|
|
|
|
else
|
|
|
|
print_menu(m);
|
2012-06-24 12:47:34 +00:00
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_HOME:
|
2012-06-24 12:47:34 +00:00
|
|
|
m->selected = list_first_entry(&m->entries, struct menu_entry, list);
|
|
|
|
repaint = 1;
|
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_END:
|
2012-06-24 12:47:34 +00:00
|
|
|
m->selected = list_last_entry(&m->entries, struct menu_entry, list);
|
|
|
|
repaint = 1;
|
|
|
|
break;
|
2010-08-20 08:22:47 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-06-24 12:53:10 +00:00
|
|
|
|
|
|
|
if (repaint) {
|
|
|
|
print_menu_entry(m, old_selected, 0);
|
|
|
|
print_menu_entry(m, m->selected, 1);
|
|
|
|
}
|
|
|
|
|
2012-04-23 11:12:31 +00:00
|
|
|
ch_previous = ch;
|
2010-08-20 08:22:47 +00:00
|
|
|
} while(1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_show);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
void menu_action_exit(struct menu *m, struct menu_entry *me) {}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_action_exit);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
2010-08-21 18:09:51 +00:00
|
|
|
struct submenu {
|
|
|
|
char *submenu;
|
|
|
|
struct menu_entry entry;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void menu_action_show(struct menu *m, struct menu_entry *me)
|
2010-08-20 08:22:47 +00:00
|
|
|
{
|
2010-08-21 18:09:51 +00:00
|
|
|
struct submenu *s = container_of(me, struct submenu, entry);
|
|
|
|
struct menu *sm;
|
|
|
|
|
2010-09-17 13:45:54 +00:00
|
|
|
if (me->type == MENU_ENTRY_BOX && !me->box_state)
|
|
|
|
return;
|
|
|
|
|
2010-08-21 18:09:51 +00:00
|
|
|
sm = menu_get_by_name(s->submenu);
|
|
|
|
if (sm)
|
|
|
|
menu_show(sm);
|
|
|
|
else
|
|
|
|
eprintf("no such menu: %s\n", s->submenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void submenu_free(struct menu_entry *me)
|
|
|
|
{
|
|
|
|
struct submenu *s = container_of(me, struct submenu, entry);
|
|
|
|
|
|
|
|
free(s->entry.display);
|
|
|
|
free(s->submenu);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct menu_entry *menu_add_submenu(struct menu *parent, char *submenu, char *display)
|
|
|
|
{
|
|
|
|
struct submenu *s = calloc(1, sizeof(*s));
|
2010-08-20 08:22:47 +00:00
|
|
|
int ret;
|
2010-08-21 18:09:51 +00:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
s->submenu = strdup(submenu);
|
|
|
|
s->entry.action = menu_action_show;
|
|
|
|
s->entry.free = submenu_free;
|
|
|
|
s->entry.display = strdup(display);
|
|
|
|
if (!s->entry.display || !s->submenu) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = menu_add_entry(parent, &s->entry);
|
|
|
|
if (ret)
|
|
|
|
goto err_free;
|
|
|
|
|
|
|
|
return &s->entry;
|
|
|
|
|
|
|
|
err_free:
|
|
|
|
submenu_free(&s->entry);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_add_submenu);
|
2010-08-21 18:09:51 +00:00
|
|
|
|
|
|
|
struct action_entry {
|
|
|
|
char *command;
|
|
|
|
struct menu_entry entry;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void menu_action_command(struct menu *m, struct menu_entry *me)
|
|
|
|
{
|
|
|
|
struct action_entry *e = container_of(me, struct action_entry, entry);
|
|
|
|
int ret;
|
|
|
|
const char *s = getenv(e->command);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
/* can be a command as boot */
|
|
|
|
if (!s)
|
2010-08-21 18:09:51 +00:00
|
|
|
s = e->command;
|
2010-08-20 08:22:47 +00:00
|
|
|
|
2014-02-27 11:23:29 +00:00
|
|
|
ret = run_command(s);
|
2010-08-20 08:22:47 +00:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
udelay(1000000);
|
|
|
|
}
|
|
|
|
|
2010-08-21 18:09:51 +00:00
|
|
|
static void menu_command_free(struct menu_entry *me)
|
|
|
|
{
|
|
|
|
struct action_entry *e = container_of(me, struct action_entry, entry);
|
|
|
|
|
|
|
|
free(e->entry.display);
|
|
|
|
free(e->command);
|
|
|
|
|
|
|
|
free(e);
|
|
|
|
}
|
|
|
|
|
2010-09-17 13:45:54 +00:00
|
|
|
struct menu_entry *menu_add_command_entry(struct menu *m, char *display,
|
|
|
|
char *command, menu_entry_type type)
|
Menu/cmd: add sub menu entry command support
this will simplify the creation of navigation link
as this
menu -a -m boot -d "Boot Menu"
menu -a -m network -d "Network settings"
menu -e -a -m network -u boot -d "Back"
menu -e -a -m boot -u network -d "Network settings ->"
menu -e -a -m boot -c reset -R -d "Reset"
menu -e -a -m boot -c clear -d "Exit"
menu -s -m boot
in C
struct menu m_boot = {
.name = "boot",
.display = "Boot Menu",
};
struct menu m_network = {
.name = "network",
.display = "Network settings",
};
struct menu_entry e_to_network = {
.display = "Network settings ->",
.action = menu_action_show,
.priv = &m_network,
};
struct menu_entry e_to_boot = {
.display = "Back",
.action = menu_action_show,
.priv = &m_boot,
};
struct menu_entry e_reset = {
.display = "Reset",
.action = menu_action_run,
.priv = "reset",
};
struct menu_entry e_exit = {
.display = "Exit",
.action = menu_action_run,
.non_re_ent = 1,
.priv = "clear",
};
void menu_test(void)
{
menu_add(&m_boot);
menu_add(&m_network);
menu_add_entry(&m_boot, &e_to_network);
menu_add_entry(&m_boot, &e_reset);
menu_add_entry(&m_boot, &e_exit);
menu_add_entry(&m_network, &e_to_boot);
menu_show(&m_boot);
}
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2010-08-20 08:22:48 +00:00
|
|
|
{
|
2010-08-21 18:09:51 +00:00
|
|
|
struct action_entry *e = calloc(1, sizeof(*e));
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!e)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
e->command = strdup(command);
|
|
|
|
e->entry.action = menu_action_command;
|
|
|
|
e->entry.free = menu_command_free;
|
2010-09-17 13:45:54 +00:00
|
|
|
e->entry.type = type;
|
2010-08-21 18:09:51 +00:00
|
|
|
e->entry.display = strdup(display);
|
Menu/cmd: add sub menu entry command support
this will simplify the creation of navigation link
as this
menu -a -m boot -d "Boot Menu"
menu -a -m network -d "Network settings"
menu -e -a -m network -u boot -d "Back"
menu -e -a -m boot -u network -d "Network settings ->"
menu -e -a -m boot -c reset -R -d "Reset"
menu -e -a -m boot -c clear -d "Exit"
menu -s -m boot
in C
struct menu m_boot = {
.name = "boot",
.display = "Boot Menu",
};
struct menu m_network = {
.name = "network",
.display = "Network settings",
};
struct menu_entry e_to_network = {
.display = "Network settings ->",
.action = menu_action_show,
.priv = &m_network,
};
struct menu_entry e_to_boot = {
.display = "Back",
.action = menu_action_show,
.priv = &m_boot,
};
struct menu_entry e_reset = {
.display = "Reset",
.action = menu_action_run,
.priv = "reset",
};
struct menu_entry e_exit = {
.display = "Exit",
.action = menu_action_run,
.non_re_ent = 1,
.priv = "clear",
};
void menu_test(void)
{
menu_add(&m_boot);
menu_add(&m_network);
menu_add_entry(&m_boot, &e_to_network);
menu_add_entry(&m_boot, &e_reset);
menu_add_entry(&m_boot, &e_exit);
menu_add_entry(&m_network, &e_to_boot);
menu_show(&m_boot);
}
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2010-08-20 08:22:48 +00:00
|
|
|
|
2010-08-21 18:09:51 +00:00
|
|
|
if (!e->entry.display || !e->command) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = menu_add_entry(m, &e->entry);
|
|
|
|
if (ret)
|
|
|
|
goto err_free;
|
|
|
|
|
|
|
|
return &e->entry;
|
|
|
|
err_free:
|
|
|
|
menu_command_free(&e->entry);
|
|
|
|
return ERR_PTR(ret);
|
Menu/cmd: add sub menu entry command support
this will simplify the creation of navigation link
as this
menu -a -m boot -d "Boot Menu"
menu -a -m network -d "Network settings"
menu -e -a -m network -u boot -d "Back"
menu -e -a -m boot -u network -d "Network settings ->"
menu -e -a -m boot -c reset -R -d "Reset"
menu -e -a -m boot -c clear -d "Exit"
menu -s -m boot
in C
struct menu m_boot = {
.name = "boot",
.display = "Boot Menu",
};
struct menu m_network = {
.name = "network",
.display = "Network settings",
};
struct menu_entry e_to_network = {
.display = "Network settings ->",
.action = menu_action_show,
.priv = &m_network,
};
struct menu_entry e_to_boot = {
.display = "Back",
.action = menu_action_show,
.priv = &m_boot,
};
struct menu_entry e_reset = {
.display = "Reset",
.action = menu_action_run,
.priv = "reset",
};
struct menu_entry e_exit = {
.display = "Exit",
.action = menu_action_run,
.non_re_ent = 1,
.priv = "clear",
};
void menu_test(void)
{
menu_add(&m_boot);
menu_add(&m_network);
menu_add_entry(&m_boot, &e_to_network);
menu_add_entry(&m_boot, &e_reset);
menu_add_entry(&m_boot, &e_exit);
menu_add_entry(&m_network, &e_to_boot);
menu_show(&m_boot);
}
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2010-08-20 08:22:48 +00:00
|
|
|
}
|
2011-07-05 05:55:55 +00:00
|
|
|
EXPORT_SYMBOL(menu_add_command_entry);
|