Skip to contentSkip to conversation

Option to set title of submenus

PATCH Avnish Chouhan 2 participants 2 messages May 27, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 79 lines

Message: 2
Date: Mon, 26 May 2025 20:18:26 +0200
From: Jiří Wolker <[email protected]>
To: [email protected]
Cc: Jiří 'bindiff' Wolker <[email protected]>
Subject: [PATCH 2/3] Option to set title of submenus
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

---
 grub-core/commands/menuentry.c | 50 ++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
grub-core/commands/menuentry.c +3 -0
index 720e6d8ea..c40b27d8b 100644
@@ -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}
   };
grub-core/commands/menuentry.c +34 -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);
+    }
+
+  result = grub_malloc (old_len + len + 2);
+  if (! 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)

grub-core/commands/menuentry.c grub_cmd_menuentry (grub_extcmd_context_t ctxt, · line 347

Quoted 10 lines
grub-core/commands/menuentry.c +8 -0
     return grub_errno;
 
+  /* 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]);

Hi Jiří,

Something like this below might be better here!

prefix = menutitle_prefix (old_prefix, (ctxt->state[6].arg

                           && grub_strlen(ctxt->state[6].arg) > 0)
                           ? ctxt->state[6].arg : args[0]);

grub-core/commands/menuentry.c grub_cmd_menuentry (grub_extcmd_context_t ctxt, · line 349

Quoted 2 lines
grub-core/commands/menuentry.c +2 -0
+      if (! prefix)
+	return grub_errno;

Indention seems off!

grub-core/commands/menuentry.c grub_cmd_menuentry (grub_extcmd_context_t ctxt, · line 350

Quoted 1 line
grub-core/commands/menuentry.c +1 -0
+      grub_free(old_prefix);

grub_free (old_prefix);

Thank you,

Regards,
Avnish Chouhan

Quoted 11 lines
grub-core/commands/menuentry.c +2 -0
+    }
+
   r = grub_normal_add_menu_entry (argc - 1, (const char **) args,
 				  ctxt->state[0].args, ctxt->state[4].arg,

users,
--
2.45.3

Quoted 1 line

------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 5 lines

Hi Jiří,

Something like this below might be better here!

[… source code fixes …]

Hi Avnish,

Thanks for you fix suggestions.

I did not write anything in the GNU coding style for a long time. Also, using my default mail client was absolutely wrong (and lazy) decision – it did corrupt whitespace in the patches.

I'm sorry and I'll send reviewed patches in a few minutes.

Thanks.
bindiff

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel