grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: "Vladimir 'phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH 1/2] Allow "fallback" to include entries by title, not just number.
Date: Mon, 22 Apr 2024 18:36:05 +0500	[thread overview]
Message-ID: <CAEaD8JOV56vuRaVd9uoXSuyre3SmHAwjEZL4105vnZjgJt7a2Q@mail.gmail.com> (raw)
In-Reply-To: <a60cb396060c3fea24c9f69b7996df0dae95fba5.1713790520.git-series.marmarek@invisiblethingslab.com>


[-- Attachment #1.1: Type: text/plain, Size: 4262 bytes --]

Selecting by title is deprecated and kept only for compatibility. Please
use id instead

Le lun. 22 avr. 2024, 17:56, Marek Marczykowski-Górecki <
marmarek@invisiblethingslab.com> a écrit :

> From: Peter Jones <pjones@redhat.com>
>
> Resolves: rhbz#1026084
>
> Signed-off-by: Peter Jones <pjones@redhat.com>
> ---
>  grub-core/normal/menu.c | 85 ++++++++++++++++++++++++++++--------------
>  1 file changed, 58 insertions(+), 27 deletions(-)
>
> diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
> index 6a90e09..6444ee6 100644
> --- a/grub-core/normal/menu.c
> +++ b/grub-core/normal/menu.c
> @@ -163,15 +163,40 @@ grub_menu_set_timeout (int timeout)
>      }
>  }
>
> +static int
> +menuentry_eq (const char *id, const char *spec)
> +{
> +  const char *ptr1, *ptr2;
> +  ptr1 = id;
> +  ptr2 = spec;
> +  while (1)
> +    {
> +      if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
> +       return ptr2 - spec;
> +      if (*ptr2 == '>' && ptr2[1] != '>')
> +       return 0;
> +      if (*ptr2 == '>')
> +       ptr2++;
> +      if (*ptr1 != *ptr2)
> +       return 0;
> +      if (*ptr1 == 0)
> +       return ptr1 - id;
> +      ptr1++;
> +      ptr2++;
> +    }
> +  return 0;
> +}
> +
>  /* Get the first entry number from the value of the environment variable
> NAME,
>     which is a space-separated list of non-negative integers.  The entry
> number
>     which is returned is stripped from the value of NAME.  If no entry
> number
>     can be found, -1 is returned.  */
>  static int
> -get_and_remove_first_entry_number (const char *name)
> +get_and_remove_first_entry_number (grub_menu_t menu, const char *name)
>  {
>    const char *val, *tail;
>    int entry;
> +  int sz = 0;
>
>    val = grub_env_get (name);
>    if (! val)
> @@ -181,9 +206,39 @@ get_and_remove_first_entry_number (const char *name)
>
>    entry = (int) grub_strtoul (val, &tail, 0);
>
> +  if (grub_errno == GRUB_ERR_BAD_NUMBER)
> +    {
> +      /* See if the variable matches the title of a menu entry.  */
> +      grub_menu_entry_t e = menu->entry_list;
> +      int i;
> +
> +      for (i = 0; e; i++)
> +       {
> +         sz = menuentry_eq (e->title, val);
> +         if (sz < 1)
> +           sz = menuentry_eq (e->id, val);
> +
> +         if (sz >= 1)
> +           {
> +             entry = i;
> +             break;
> +           }
> +         e = e->next;
> +       }
> +
> +      if (sz > 0)
> +       grub_errno = GRUB_ERR_NONE;
> +
> +      if (! e)
> +       entry = -1;
> +    }
> +
>    if (grub_errno == GRUB_ERR_NONE)
>      {
> -      /* Skip whitespace to find the next digit.  */
> +      if (sz > 0)
> +       tail += sz;
> +
> +      /* Skip whitespace to find the next entry.  */
>        while (*tail && grub_isspace (*tail))
>         tail++;
>        grub_env_set (name, tail);
> @@ -346,7 +401,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu,
>    grub_menu_execute_entry (entry, 1);
>
>    /* Deal with fallback entries.  */
> -  while ((fallback_entry = get_and_remove_first_entry_number ("fallback"))
> +  while ((fallback_entry = get_and_remove_first_entry_number (menu,
> "fallback"))
>          >= 0)
>      {
>        grub_print_error ();
> @@ -464,30 +519,6 @@ grub_menu_register_viewer (struct grub_menu_viewer
> *viewer)
>    viewers = viewer;
>  }
>
> -static int
> -menuentry_eq (const char *id, const char *spec)
> -{
> -  const char *ptr1, *ptr2;
> -  ptr1 = id;
> -  ptr2 = spec;
> -  while (1)
> -    {
> -      if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
> -       return 1;
> -      if (*ptr2 == '>' && ptr2[1] != '>')
> -       return 0;
> -      if (*ptr2 == '>')
> -       ptr2++;
> -      if (*ptr1 != *ptr2)
> -       return 0;
> -      if (*ptr1 == 0)
> -       return 1;
> -      ptr1++;
> -      ptr2++;
> -    }
> -}
> -
> -
>  /* Get the entry number from the variable NAME.  */
>  static int
>  get_entry_number (grub_menu_t menu, const char *name)
> --
> git-series 0.9.1
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #1.2: Type: text/html, Size: 5640 bytes --]

[-- Attachment #2: Type: text/plain, Size: 141 bytes --]

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  reply	other threads:[~2024-04-22 13:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22 12:55 [PATCH 0/2] Two patches related to menu entries selection Marek Marczykowski-Górecki
2024-04-22 12:55 ` [PATCH 1/2] Allow "fallback" to include entries by title, not just number Marek Marczykowski-Górecki
2024-04-22 13:36   ` Vladimir 'phcoder' Serbinenko [this message]
2024-04-22 12:55 ` [PATCH 2/2] Fix menu entry selection based on ID and title Marek Marczykowski-Górecki
2024-04-22 13:32   ` Vladimir 'phcoder' Serbinenko

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=CAEaD8JOV56vuRaVd9uoXSuyre3SmHAwjEZL4105vnZjgJt7a2Q@mail.gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).