All of lore.kernel.org
 help / color / mirror / Atom feed
From: sudhakar <sudhakar@linux.ibm.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: "Jiří Wolker" <projects@jwo.cz>
Subject: Re: [PATCH 2/3] Option to set title of submenus
Date: Tue, 27 May 2025 16:13:10 +0530	[thread overview]
Message-ID: <0259e0252612fd758fe18cb966158775@linux.ibm.com> (raw)
In-Reply-To: <87cybvdyml.fsf@gnat.mail-host-address-is-not-set>

On 2025-05-26 23:48, Jiří Wolker via Grub-devel wrote:
> ---
>  grub-core/commands/menuentry.c | 50 ++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/grub-core/commands/menuentry.c 
> b/grub-core/commands/menuentry.c
> index 720e6d8ea..c40b27d8b 100644
> --- a/grub-core/commands/menuentry.c
> +++ b/grub-core/commands/menuentry.c
> @@ -43,6 +43,9 @@ static const struct grub_arg_option options[] =
>         anyone can boot it.  */
>      {"unrestricted", 0, 0, N_("This entry can be booted by any 
> user."),
>       0, ARG_TYPE_NONE},
> +    {"menutitle", 0, 0,
> +     N_("Use STRING as menu title. When omitted, use the entry 
> label."),
> +     N_("TITLE"), ARG_TYPE_STRING},
>      {0, 0, 0, 0, 0, 0}
>    };
> 
> @@ -252,12 +255,46 @@ setparams_prefix (int argc, char **args)
>    return result;
>  }
> 
> +static char *
> +menutitle_prefix (char *old_prefix, const char *title)
> +{
> +  const char *t;
> +  char *p;
> +  char *result;
> +  grub_size_t len = 22;
> +  grub_size_t old_len = grub_strlen (old_prefix);
> +
> +  /* Count resulting string length. */
> +  for (t = title; *t; t++)
> +    {
> +      len += (*t++ == '\'' ? 4 : 1);
> +    }
> +

remove the brackets in one liner For loop

> +  result = grub_malloc (old_len + len + 2);
> +  if (! result)

s/! result/!result

> +    return 0;
> +
> +  p = result;
> +  grub_strcpy (p, old_prefix);
> +  p = result + old_len;
> +  grub_strcpy (p, "set grub_menu_title='");
> +  p += 21;
> +
> +  p = grub_strchrsub (p, title, '\'', "'\\''");
> +  *p++ = '\'';
> +  *p++ = '\n';
> +  *p = '\0';
> +
> +  return result;
> +}
> +
>  static grub_err_t
>  grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args)
>  {
>    char ch;
>    char *src;
>    char *prefix;
> +  char *old_prefix;
>    unsigned len;
>    grub_err_t r;
>    const char *users;
> @@ -299,6 +336,19 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt,
> int argc, char **args)
>    if (! prefix)
>      return grub_errno;
> 
s/! prefix/!prefix

> +  /* Prepend the menu title line. */
> +  if (ctxt->state[6].arg)
> +    {
> +      old_prefix = prefix;
> +      prefix = menutitle_prefix (old_prefix,
> +				 (ctxt->state[6].arg
> +				  && grub_strlen(ctxt->state[6].arg) > 0)
> +				 ? ctxt->state[6].arg : args[0]);
> +      if (! prefix)

ditto

> +	return grub_errno;
> +      grub_free(old_prefix);
> +    }
> +
>    r = grub_normal_add_menu_entry (argc - 1, (const char **) args,
>  				  ctxt->state[0].args, ctxt->state[4].arg,
>  				  users,

Indentation looks off in couple of places. Please fix it.

Thanks,
Sudhakar

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

  reply	other threads:[~2025-05-27 10:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-26 17:50 [PATCH 0/3] Allow script-configurable GRUB menu title Jiří 'bindiff' Wolker via Grub-devel
2025-05-26 17:53 ` [PATCH 1/3] Customization of " Jiří 'bindiff' Wolker via Grub-devel
2025-05-26 18:16 ` Jiří Wolker via Grub-devel
2025-05-26 18:18 ` [PATCH 2/3] Option to set title of submenus Jiří Wolker via Grub-devel
2025-05-27 10:43   ` sudhakar [this message]
2025-05-26 18:19 ` [PATCH 3/3] Documentation for the --menutitle option Jiří Wolker via Grub-devel
     [not found] <mailman.5394.1748289237.3672.grub-devel@gnu.org>
2025-05-27 11:00 ` [PATCH 2/3] Option to set title of submenus Avnish Chouhan
2025-05-27 12:01   ` Jiří 'bindiff' Wolker via Grub-devel

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=0259e0252612fd758fe18cb966158775@linux.ibm.com \
    --to=sudhakar@linux.ibm.com \
    --cc=grub-devel@gnu.org \
    --cc=projects@jwo.cz \
    /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.