All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Anatolij Gustschin <agust@denx.de>, Tom Rini <trini@konsulko.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH v3 06/25] menu: Update bootmenu_loop() to return the code
Date: Fri,  6 Jan 2023 08:52:24 -0600	[thread overview]
Message-ID: <20230106145243.411626-7-sjg@chromium.org> (raw)
In-Reply-To: <20230106145243.411626-1-sjg@chromium.org>

Use the return value to save having to pass around a pointer. This also
resolves any ambiguity about what *key contains when the function is
called.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 cmd/bootmenu.c  |  2 +-
 cmd/eficonfig.c |  4 ++--
 common/menu.c   | 30 ++++++++++++++++--------------
 include/menu.h  | 11 +++++------
 4 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 0e22f504fe4..573afe16609 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -96,7 +96,7 @@ static char *bootmenu_choice_entry(void *data)
 			key = bootmenu_autoboot_loop(menu, &esc);
 		} else {
 			/* Some key was pressed, so autoboot was stopped */
-			bootmenu_loop(menu, &key, &esc);
+			key = bootmenu_loop(menu, &esc);
 		}
 
 		switch (key) {
diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 8f246bc271f..96cb1a367f3 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -191,7 +191,7 @@ static char *eficonfig_choice_entry(void *data)
 	struct efimenu *efi_menu = data;
 
 	while (1) {
-		bootmenu_loop((struct bootmenu_data *)efi_menu, &key, &esc);
+		key = bootmenu_loop((struct bootmenu_data *)efi_menu, &esc);
 
 		switch (key) {
 		case BKEY_UP:
@@ -1868,7 +1868,7 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)
 	struct eficonfig_entry *entry, *tmp;
 
 	while (1) {
-		bootmenu_loop(NULL, &key, &esc);
+		key = bootmenu_loop(NULL, &esc);
 
 		switch (key) {
 		case BKEY_PLUS:
diff --git a/common/menu.c b/common/menu.c
index bafc8470d7d..6842f5409d6 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -476,9 +476,9 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc)
 	return key;
 }
 
-void bootmenu_loop(struct bootmenu_data *menu,
-		   enum bootmenu_key *key, int *esc)
+enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc)
 {
+	enum bootmenu_key key = BKEY_NONE;
 	int c;
 
 	if (*esc == 1) {
@@ -505,17 +505,17 @@ void bootmenu_loop(struct bootmenu_data *menu,
 		/* First char of ANSI escape sequence '\e' */
 		if (c == '\e') {
 			*esc = 1;
-			*key = BKEY_NONE;
+			key = BKEY_NONE;
 		}
 		break;
 	case 1:
 		/* Second char of ANSI '[' */
 		if (c == '[') {
 			*esc = 2;
-			*key = BKEY_NONE;
+			key = BKEY_NONE;
 		} else {
 		/* Alone ESC key was pressed */
-			*key = BKEY_QUIT;
+			key = BKEY_QUIT;
 			*esc = (c == '\e') ? 1 : 0;
 		}
 		break;
@@ -524,7 +524,7 @@ void bootmenu_loop(struct bootmenu_data *menu,
 		/* Third char of ANSI (number '1') - optional */
 		if (*esc == 2 && c == '1') {
 			*esc = 3;
-			*key = BKEY_NONE;
+			key = BKEY_NONE;
 			break;
 		}
 
@@ -532,31 +532,33 @@ void bootmenu_loop(struct bootmenu_data *menu,
 
 		/* ANSI 'A' - key up was pressed */
 		if (c == 'A')
-			*key = BKEY_UP;
+			key = BKEY_UP;
 		/* ANSI 'B' - key down was pressed */
 		else if (c == 'B')
-			*key = BKEY_DOWN;
+			key = BKEY_DOWN;
 		/* other key was pressed */
 		else
-			*key = BKEY_NONE;
+			key = BKEY_NONE;
 
 		break;
 	}
 
 	/* enter key was pressed */
 	if (c == '\r')
-		*key = BKEY_SELECT;
+		key = BKEY_SELECT;
 
 	/* ^C was pressed */
 	if (c == 0x3)
-		*key = BKEY_QUIT;
+		key = BKEY_QUIT;
 
 	if (c == '+')
-		*key = BKEY_PLUS;
+		key = BKEY_PLUS;
 
 	if (c == '-')
-		*key = BKEY_MINUS;
+		key = BKEY_MINUS;
 
 	if (c == ' ')
-		*key = BKEY_SPACE;
+		key = BKEY_SPACE;
+
+	return key;
 }
diff --git a/include/menu.h b/include/menu.h
index 9f30a3c1acd..8b9b36214f7 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -83,7 +83,10 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc);
  * character is recognised
  *
  * @menu: Menu being processed
- * @key: Returns the code for the key the user pressed:
+ * @esc: On input, a non-zero value indicates that an escape sequence has
+ *	resulted in that many characters so far. On exit this is updated to the
+ *	new number of characters
+ * Returns: code for the key the user pressed:
  *	enter: BKEY_SELECT
  *	Ctrl-C: BKEY_QUIT
  *	Up arrow: BKEY_UP
@@ -92,11 +95,7 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc);
  *	Plus: BKEY_PLUS
  *	Minus: BKEY_MINUS
  *	Space: BKEY_SPACE
- * @esc: On input, a non-zero value indicates that an escape sequence has
- *	resulted in that many characters so far. On exit this is updated to the
- *	new number of characters
  */
-void bootmenu_loop(struct bootmenu_data *menu,
-		   enum bootmenu_key *key, int *esc);
+enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc);
 
 #endif /* __MENU_H__ */
-- 
2.39.0.314.g84b9a713c41-goog


  parent reply	other threads:[~2023-01-06 14:55 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 14:52 [PATCH v3 00/25] bootstd: Add a boot menu Simon Glass
2023-01-06 14:52 ` [PATCH v3 01/25] sandbox: Enable mmc command and legacy images Simon Glass
2023-01-06 14:52 ` [PATCH v3 02/25] cli: Move readline character-processing to a state machine Simon Glass
2023-01-06 15:50   ` Heinrich Schuchardt
2023-01-07  0:13     ` Simon Glass
2023-01-07 22:31       ` Heinrich Schuchardt
2023-01-24 15:19   ` [BUG] " Heinrich Schuchardt
2023-01-28 22:01     ` Simon Glass
2023-01-06 14:52 ` [PATCH v3 03/25] bootmenu: Add a few comments Simon Glass
2023-01-06 15:53   ` Heinrich Schuchardt
2023-01-07  0:13     ` Simon Glass
2023-01-07 22:34       ` Heinrich Schuchardt
2023-01-07 22:54         ` Simon Glass
2023-01-06 14:52 ` [PATCH v3 04/25] menu: Rename KEY_... to BKEY_ Simon Glass
2023-01-06 14:52 ` [PATCH v3 05/25] menu: Update bootmenu_autoboot_loop() to return the code Simon Glass
2023-01-06 14:52 ` Simon Glass [this message]
2023-01-06 14:52 ` [PATCH v3 07/25] menu: Use a switch statement Simon Glass
2023-01-06 14:52 ` [PATCH v3 08/25] menu: Make use of CLI character processing Simon Glass
2023-04-11 20:19   ` Daniel Golle
2023-04-19  1:49     ` Simon Glass
2023-04-24  1:49       ` Tom Rini
2023-04-24 19:42         ` Simon Glass
2023-01-06 14:52 ` [PATCH v3 09/25] image: Add a function to find a script in an image Simon Glass
2023-01-06 14:52 ` [PATCH v3 10/25] image: Move common image code to image_board and command Simon Glass
2023-01-06 14:52 ` [PATCH v3 11/25] video: Enable VIDEO_ANSI by default only with EFI Simon Glass
2023-01-06 14:52 ` [PATCH v3 12/25] video: truetype: Rename the metrics function Simon Glass
2023-01-06 14:52 ` [PATCH v3 13/25] video: Fix unchnaged typo Simon Glass
2023-01-06 14:52 ` [PATCH v3 14/25] video: Add font functions to the vidconsole API Simon Glass
2023-01-06 14:52 ` [PATCH v3 15/25] bootstd: Read the Operating System name for distro/scripts Simon Glass
2023-01-06 14:52 ` [PATCH v3 16/25] bootstd: Allow reading a logo for the OS Simon Glass
2023-01-06 14:52 ` [PATCH v3 17/25] menu: Factor out menu-keypress decoding Simon Glass
2023-01-06 14:52 ` [PATCH v3 18/25] expo: Add basic implementation Simon Glass
2023-01-06 14:52 ` [PATCH v3 19/25] expo: Add support for scenes Simon Glass
2023-01-06 14:52 ` [PATCH v3 20/25] expo: Add support for scene menus Simon Glass
2023-01-06 14:52 ` [PATCH v3 21/25] expo: Add basic tests Simon Glass
2023-01-06 14:52 ` [PATCH v3 22/25] bootstd: Support creating a boot menu Simon Glass
2023-01-06 14:52 ` [PATCH v3 23/25] bootstd: Add a test for the bootstd menu Simon Glass
2023-01-06 14:52 ` [PATCH v3 24/25] bootstd: Support setting a theme for the menu Simon Glass
2023-01-06 14:52 ` [PATCH v3 25/25] expo: Add documentation Simon Glass
2023-01-17 13:57 ` [PATCH v3 00/25] bootstd: Add a boot menu Tom Rini

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=20230106145243.411626-7-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=agust@denx.de \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.