All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vesa Jääskeläinen" <chaac@nic.fi>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] GSoC #05 Menu entry class attribute
Date: Sun, 05 Oct 2008 13:07:32 +0300	[thread overview]
Message-ID: <48E891E4.1000507@nic.fi> (raw)
In-Reply-To: <20080830235254.7cc5ad80@gamma.lan>

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

Colin D Bennett wrote:
> This patch adds support for a 'class' attribute on menu entries.  It is
> somewhat of a kludge, however since currently you just append
> "|class=this,that" to the menu entry title to specify the classes.
> 
> Classes are used to provide a simple and flexible way for the best
> available icon to be used in a graphical menu, but there are other
> possible uses for them as well.  The idea originates from the CSS
> (cascading style sheets) and HTML 'class' concept.

Here is the patch snipped for using menuentry --class foo "title" { }.

Please try it out and see if it fits.


[-- Attachment #2: grub2-menuarguments.patch --]
[-- Type: text/plain, Size: 6455 bytes --]

Index: normal/parser.y
===================================================================
--- normal/parser.y	(revision 1885)
+++ normal/parser.y	(working copy)
@@ -204,7 +204,7 @@
 ;
 
 /* A menu entry.  Carefully save the memory that is allocated.  */
-menuentry:	"menuentry" argument
+menuentry:	"menuentry" arguments
 		  {
 		    grub_script_lexer_ref (state->lexerstate);
 		  } newlines '{'
Index: normal/main.c
===================================================================
--- normal/main.c	(revision 1885)
+++ normal/main.c	(working copy)
@@ -148,13 +148,15 @@
 }
 
 grub_err_t
-grub_normal_menu_addentry (const char *title, struct grub_script *script,
+grub_normal_menu_addentry (int argc, char **args, struct grub_script *script,
 			   const char *sourcecode)
 {
-  const char *menutitle;
+  const char *menutitle = 0;
   const char *menusourcecode;
   grub_menu_t menu;
   grub_menu_entry_t *last;
+  int failed = 0;
+  int i;
 
   menu = grub_env_get_data_slot("menu");
   if (! menu)
@@ -166,10 +168,59 @@
   if (! menusourcecode)
     return grub_errno;
 
-  menutitle = grub_strdup (title);
-  if (! menutitle)
+  /* Parse menu arguments.  */
+  for (i = 0; i < argc; i++)
     {
-      grub_free ((void *) menusourcecode);
+      /* Capture arguments.  */
+      if (grub_strncmp ("--", args[i], 2) == 0)
+	{
+	  char *arg = &args[i][2];
+	  char *value = 0;
+
+	  /* Handle menu class.  */
+	  if (grub_strcmp(arg, "class") == 0)
+	    {
+	      i++;
+	      value = args[i];
+	      continue;
+	    }
+	  else
+	    {
+	      /* Handle invalid argument.  */
+	      failed = 1;
+	      grub_error (GRUB_ERR_MENU, "invalid argument for menuentry: %s", args[i]);
+	      break;
+	    }
+
+	}
+
+      /* Capture title.  */
+      if (! menutitle)
+	{
+	  menutitle = grub_strdup (args[i]);
+	}
+      else
+	{
+	  failed = 1;
+	  grub_error (GRUB_ERR_MENU, "too many titles for menuentry: %s", args[i]);
+	  break;
+	}
+    }
+
+  /* Validate arguments.  */
+  if ((! failed) && (! menutitle))
+    {
+      grub_error (GRUB_ERR_MENU, "menuentry is missing title");
+      failed = 1;
+    }
+
+  /* If argument parsing failed, free any allocated resources.  */
+  if (failed)
+    {
+      grub_free ((void *)menutitle);
+      grub_free ((void *)menusourcecode);
+
+      /* Here we assume that grub_error has been used to specify failure details.  */
       return grub_errno;
     }
 
Index: normal/script.c
===================================================================
--- normal/script.c	(revision 1885)
+++ normal/script.c	(working copy)
@@ -206,7 +206,7 @@
    The options for this entry are passed in OPTIONS.  */
 struct grub_script_cmd *
 grub_script_create_cmdmenu (struct grub_parser_param *state,
-			    struct grub_script_arg *title,
+			    struct grub_script_arglist *arglist,
 			    char *sourcecode,
 			    int options)
 {
@@ -232,9 +232,9 @@
   cmd->cmd.next = 0;
   /* XXX: Check if this memory is properly freed.  */
   cmd->sourcecode = sourcecode;
-  cmd->title = title;
+  cmd->arglist = arglist;
   cmd->options = options;
- 
+
   return (struct grub_script_cmd *) cmd;
 }
 
Index: normal/execute.c
===================================================================
--- normal/execute.c	(revision 1885)
+++ normal/execute.c	(working copy)
@@ -216,16 +216,33 @@
 grub_script_execute_menuentry (struct grub_script_cmd *cmd)
 {
   struct grub_script_cmd_menuentry *cmd_menuentry;
-  char *title;
+  struct grub_script_arglist *arglist;
   struct grub_script *script;
+  char **args = 0;
+  int argcount = 0;
+  int i = 0;
 
   cmd_menuentry = (struct grub_script_cmd_menuentry *) cmd;
 
-  /* The title can contain variables, parse them and generate a string
-     from it.  */
-  title = grub_script_execute_argument_to_string (cmd_menuentry->title);
-  if (! title)
-    return grub_errno;
+  if (cmd_menuentry->arglist)
+    {
+      argcount = cmd_menuentry->arglist->argcount;
+
+      /* Create argv from the arguments.  */
+      args = grub_malloc (sizeof (char *) * argcount);
+
+      if (! args)
+	{
+	return grub_errno;
+	}
+
+      for (arglist = cmd_menuentry->arglist; arglist; arglist = arglist->next)
+	{
+	  char *str;
+	  str = grub_script_execute_argument_to_string (arglist->arg);
+	  args[i++] = str;
+	}
+    }
 
   /* Parse the menu entry *again*.  */
   script = grub_script_parse ((char *) cmd_menuentry->sourcecode, 0);
@@ -230,15 +247,19 @@
   /* Parse the menu entry *again*.  */
   script = grub_script_parse ((char *) cmd_menuentry->sourcecode, 0);
 
-  if (! script)
+  /* Add new menu entry.  */
+  if (script)
     {
-      grub_free (title);
-      return grub_errno;
+    grub_normal_menu_addentry (argcount, args,
+			       script, cmd_menuentry->sourcecode);
     }
 
-  /* XXX: When this fails, the memory should be freed?  */
-  return grub_normal_menu_addentry (title, script,
-				    cmd_menuentry->sourcecode);
+  /* Free arguments.  */
+  for (i = 0; i < argcount; i++)
+    grub_free (args[i]);
+  grub_free (args);
+
+  return grub_errno;
 }
 
 \f
Index: include/grub/script.h
===================================================================
--- include/grub/script.h	(revision 1885)
+++ include/grub/script.h	(working copy)
@@ -113,8 +113,8 @@
 {
   struct grub_script_cmd cmd;
 
-  /* The title of the menu entry.  */
-  struct grub_script_arg *title;
+  /* The arguments for this menu entry.  */
+  struct grub_script_arglist *arglist;
 
   /* The sourcecode the entry will be generated from.  */
   const char *sourcecode;
@@ -204,7 +204,7 @@
 
 struct grub_script_cmd *
 grub_script_create_cmdmenu (struct grub_parser_param *state,
-			    struct grub_script_arg *title,
+			    struct grub_script_arglist *arglist,
 			    char *sourcecode,
 			    int options);
 
Index: include/grub/normal.h
===================================================================
--- include/grub/normal.h	(revision 1885)
+++ include/grub/normal.h	(working copy)
@@ -152,7 +152,7 @@
 char *grub_normal_do_completion (char *buf, int *restore,
 				 void (*hook) (const char *item, grub_completion_type_t type, int count));
 grub_err_t grub_normal_print_device_info (const char *name);
-grub_err_t grub_normal_menu_addentry (const char *title,
+grub_err_t grub_normal_menu_addentry (int argc, char **args,
 				      struct grub_script *script,
 				      const char *sourcecode);
 char *grub_env_write_color_normal (struct grub_env_var *var, const char *val);

  reply	other threads:[~2008-10-05 10:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-31  6:52 [PATCH] GSoC #05 Menu entry class attribute Colin D Bennett
2008-10-05 10:07 ` Vesa Jääskeläinen [this message]
2008-10-13 16:35   ` [PATCH] GSoC #05 Menu entry class attribute (v2) Colin D Bennett
2009-01-31  9:19     ` Vesa Jääskeläinen
2009-01-31 17:49       ` Colin D Bennett

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=48E891E4.1000507@nic.fi \
    --to=chaac@nic.fi \
    --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 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.