From: "Pali Rohár" <pali.rohar@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] menu: Added support to use user defined functions
Date: Sun, 27 May 2012 18:38:48 +0200 [thread overview]
Message-ID: <1338136729-3907-2-git-send-email-pali.rohar@gmail.com> (raw)
In-Reply-To: <1338136729-3907-1-git-send-email-pali.rohar@gmail.com>
* In menu_interactive_choice can be used user specified function
item_data_choice (instead hardcoded function which read input
from standard input)
* Added option to specify user data for menu
* menu_display_statusline will pass pointer to user data
(instead pointer to menu)
* This patch is needed for creating ANSI bootmenu
Signed-off-by: Pali Roh?r <pali.rohar@gmail.com>
---
board/ait/cam_enc_4xx/cam_enc_4xx.c | 5 ++--
common/cmd_pxe.c | 3 ++-
| 43 +++++++++++++++++++++++------------
| 6 +++--
4 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/board/ait/cam_enc_4xx/cam_enc_4xx.c b/board/ait/cam_enc_4xx/cam_enc_4xx.c
index 32b28f9..5078b01 100644
--- a/board/ait/cam_enc_4xx/cam_enc_4xx.c
+++ b/board/ait/cam_enc_4xx/cam_enc_4xx.c
@@ -561,7 +561,8 @@ static char *menu_handle(struct menu_display *display)
char *s;
char temp[6][200];
- m = menu_create(display->title, display->timeout, 1, ait_menu_print);
+ m = menu_create(display->title, display->timeout, 1, ait_menu_print,
+ NULL, NULL);
for (i = 0; display->menulist[i]; i++) {
sprintf(key, "%d", i + 1);
@@ -1097,7 +1098,7 @@ int menu_show(int bootdelay)
return MENU_EXIT;
}
-void menu_display_statusline(struct menu *m)
+void menu_display_statusline(void *data)
{
char *s1, *s2;
diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c
index b3c1f67..346e275 100644
--- a/common/cmd_pxe.c
+++ b/common/cmd_pxe.c
@@ -1198,7 +1198,8 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
/*
* Create a menu and add items for all the labels.
*/
- m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print);
+ m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print,
+ NULL, NULL);
if (!m)
return NULL;
--git a/common/menu.c b/common/menu.c
index aa16c9a..470eb9f 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -47,6 +47,8 @@ struct menu {
char *title;
int prompt;
void (*item_data_print)(void *);
+ char *(*item_data_choice)(void *);
+ void *data;
struct list_head items;
};
@@ -113,11 +115,11 @@ static inline void *menu_item_destroy(struct menu *m,
return NULL;
}
-void __menu_display_statusline(struct menu *m)
+void __menu_display_statusline(void *menu_data)
{
return;
}
-void menu_display_statusline(struct menu *m)
+void menu_display_statusline(void *menu_data)
__attribute__ ((weak, alias("__menu_display_statusline")));
/*
@@ -130,7 +132,7 @@ static inline void menu_display(struct menu *m)
puts(m->title);
putc('\n');
}
- menu_display_statusline(m);
+ menu_display_statusline(m->data);
menu_items_iter(m, menu_item_print, NULL);
}
@@ -230,20 +232,27 @@ static inline int menu_interactive_choice(struct menu *m, void **choice)
menu_display(m);
- readret = readline_into_buffer("Enter choice: ", cbuf,
- m->timeout);
-
- if (readret >= 0) {
- choice_item = menu_item_by_key(m, cbuf);
-
- if (!choice_item) {
- printf("%s not found\n", cbuf);
- m->timeout = 0;
+ if (!m->item_data_choice) {
+ readret = readline_into_buffer("Enter choice: ", cbuf,
+ m->timeout);
+
+ if (readret >= 0) {
+ choice_item = menu_item_by_key(m, cbuf);
+ if (!choice_item)
+ printf("%s not found\n", cbuf);
+ } else {
+ puts("^C\n");
+ return -EINTR;
}
} else {
- puts("^C\n");
- return -EINTR;
+ char *key = m->item_data_choice(m->data);
+ if (!key)
+ return -EINTR;
+ choice_item = menu_item_by_key(m, key);
}
+
+ if (!choice_item)
+ m->timeout = 0;
}
*choice = choice_item->data;
@@ -380,7 +389,9 @@ int menu_item_add(struct menu *m, char *item_key, void *item_data)
* insufficient memory available to create the menu.
*/
struct menu *menu_create(char *title, int timeout, int prompt,
- void (*item_data_print)(void *))
+ void (*item_data_print)(void *),
+ char *(*item_data_choice)(void *),
+ void *menu_data)
{
struct menu *m;
@@ -393,6 +404,8 @@ struct menu *menu_create(char *title, int timeout, int prompt,
m->prompt = prompt;
m->timeout = timeout;
m->item_data_print = item_data_print;
+ m->item_data_choice = item_data_choice;
+ m->data = menu_data;
if (title) {
m->title = strdup(title);
--git a/include/menu.h b/include/menu.h
index 7af5fdb..00e8975 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -21,12 +21,14 @@
struct menu;
struct menu *menu_create(char *title, int timeout, int prompt,
- void (*item_data_print)(void *));
+ void (*item_data_print)(void *),
+ char *(*item_data_choice)(void *),
+ void *menu_data);
int menu_default_set(struct menu *m, char *item_key);
int menu_get_choice(struct menu *m, void **choice);
int menu_item_add(struct menu *m, char *item_key, void *item_data);
int menu_destroy(struct menu *m);
-void menu_display_statusline(struct menu *m);
+void menu_display_statusline(void *menu_data);
#if defined(CONFIG_MENU_SHOW)
int menu_show(int bootdelay);
--
1.7.9.5
next prev parent reply other threads:[~2012-05-27 16:38 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-27 16:38 [U-Boot] [PATCH 0/2] ANSI terminal Bootmenu Pali Rohár
2012-05-27 16:38 ` Pali Rohár [this message]
2012-06-03 9:59 ` [U-Boot] [PATCH 1/2] menu: Added support to use user defined functions Marek Vasut
2012-06-03 10:05 ` Pali Rohár
2012-06-03 10:27 ` Marek Vasut
2012-05-27 16:38 ` [U-Boot] [PATCH 2/2] New command bootmenu: ANSI terminal Boot Menu support Pali Rohár
2012-06-03 10:06 ` Marek Vasut
2012-06-03 16:22 ` Luka Perkov
2012-06-03 18:27 ` Marek Vasut
2012-06-03 21:20 ` Luka Perkov
2012-11-01 11:39 ` [U-Boot] [PATCH v2 0/4] ANSI terminal Bootmenu Pali Rohár
2012-11-01 11:39 ` [U-Boot] [PATCH v2 1/4] menu: Added support to use user defined functions Pali Rohár
2012-11-01 11:39 ` [U-Boot] [PATCH v2 2/4] New command bootmenu: ANSI terminal Boot Menu support Pali Rohár
2012-11-13 8:27 ` Wolfgang Denk
2012-11-14 22:38 ` Pali Rohár
2012-11-01 11:39 ` [U-Boot] [PATCH v2 3/4] New command clear: Clear the ANSI terminal Pali Rohár
2012-11-13 8:09 ` Wolfgang Denk
2012-11-01 11:39 ` [U-Boot] [PATCH v2 4/4] RX-51: Add support for bootmenu Pali Rohár
2013-02-01 15:07 ` [U-Boot] [PATCH v3 0/4] ANSI terminal Bootmenu Pali Rohár
2013-02-01 15:07 ` [U-Boot] [PATCH v3 1/4] menu: Added support to use user defined functions Pali Rohár
2013-03-24 0:50 ` [U-Boot] [PATCH v4 1/4] menu: Add support for user defined item choice function Anatolij Gustschin
2013-03-24 0:52 ` [U-Boot] [PATCH] menu: export menu_default_choice() function Anatolij Gustschin
2013-03-28 15:26 ` Anatolij Gustschin
2013-03-28 15:26 ` [U-Boot] [PATCH v4 1/4] menu: Add support for user defined item choice function Anatolij Gustschin
2013-02-01 15:07 ` [U-Boot] [PATCH v3 2/4] New command bootmenu: ANSI terminal Boot Menu support Pali Rohár
2013-03-24 0:53 ` [U-Boot] [PATCH v4 2/4] New command bootmenu: ANSI terminal boot menu support Anatolij Gustschin
2013-03-25 19:29 ` Anatolij Gustschin
2013-03-26 15:19 ` Pali Rohár
2013-03-28 15:29 ` Anatolij Gustschin
2013-03-28 15:32 ` Anatolij Gustschin
2013-03-28 19:18 ` Pali Rohár
2013-03-28 23:13 ` Anatolij Gustschin
2013-03-29 6:51 ` Pali Rohár
2013-02-01 15:07 ` [U-Boot] [PATCH v3 3/4] New command clear: Clear the ANSI terminal Pali Rohár
2013-02-01 15:07 ` [U-Boot] [PATCH v3 4/4] RX-51: Add support for bootmenu Pali Rohár
2013-03-07 15:15 ` Pali Rohár
2013-03-28 23:26 ` Anatolij Gustschin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1338136729-3907-2-git-send-email-pali.rohar@gmail.com \
--to=pali.rohar@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox