[PATCH 07/24] menu: Use a switch statement

Simon Glass sjg at chromium.org
Wed Oct 19 15:18:03 CEST 2022


Hi Heinrich,

On Mon, 17 Oct 2022 at 16:07, Heinrich Schuchardt <xypron.glpk at gmx.de> wrote:
>
> On 10/17/22 22:29, Simon Glass wrote:
> > Convert the long line of if() statements to a switch() since this makes
> > better use of the C language.
> >
> > Signed-off-by: Simon Glass <sjg at chromium.org>
> > ---
> >
> >   common/menu.c | 31 ++++++++++++++++++++-----------
> >   1 file changed, 20 insertions(+), 11 deletions(-)
> >
> > diff --git a/common/menu.c b/common/menu.c
> > index 22947f5d693..1aa78b762a4 100644
> > --- a/common/menu.c
> > +++ b/common/menu.c
> > @@ -543,22 +543,31 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc)
> >               break;
> >       }
> >
> > -     /* enter key was pressed */
> > -     if (c == '\r')
> > +     switch (c) {
> > +     case '\r':
> > +             /* enter key was pressed */
> >               key = BKEY_SELECT;
> > -
> > -     /* ^C was pressed */
> > -     if (c == 0x3)
> > +             break;
> > +     case CTL_CH('c'):
> > +             /* ^C was pressed */
> >               key = BKEY_QUIT;
> > -
> > -     if (c == '+')
> > +             break;
> > +     case CTL_CH('p'):
> > +             key = BKEY_UP;
> > +             break;
> > +     case CTL_CH('n'):
> > +             key = BKEY_DOWN;
> > +             break;
> > +     case '+':
> >               key = BKEY_PLUS;
> > -
> > -     if (c == '-')
> > +             break;
> > +     case '-':
> >               key = BKEY_MINUS;
> > -
> > -     if (c == ' ')
> > +             break;
> > +     case ' ':
> >               key = BKEY_SPACE;
> > +             break;
> > +     }
>
> The whole code is not well suited to parse all of the many different
> escape sequences that can be sent to convey modifier keys or
> non-character keys (think of <CTRL><ALT><F12> or <HOME>).
>
> We should move the of logic of efi_cin_read_key_stroke_ex() to a library
> function which is used both by bootmenu and UEFI and remove duplicate code.

Sorry I am not about to put effort into the EFI code :-)

Also I did create a library to handle keystrokes. See cli_getch.c

Regards,
Simon


More information about the U-Boot mailing list