]> git.proxmox.com Git - grub2.git/commitdiff
simplify cmdblock with cmdlist
authorBVK Chaitanya <bvk.groups@gmail.com>
Wed, 5 May 2010 08:35:06 +0000 (14:05 +0530)
committerBVK Chaitanya <bvk.groups@gmail.com>
Wed, 5 May 2010 08:35:06 +0000 (14:05 +0530)
include/grub/script_sh.h
script/execute.c
script/parser.y
script/script.c
util/grub-script-check.c

index b55b6a806bdf338c41ec67df6b3b62975dc98051..53f4f13bb30232081316731bda28faccbd1bda36 100644 (file)
@@ -82,15 +82,6 @@ struct grub_script_cmdline
   struct grub_script_arglist *arglist;
 };
 
-/* A block of commands, this can be used to group commands.  */
-struct grub_script_cmdblock
-{
-  struct grub_script_cmd cmd;
-
-  /* A chain of commands.  */
-  struct grub_script_cmd *cmdlist;
-};
-
 /* An if statement.  */
 struct grub_script_cmdif
 {
@@ -234,8 +225,6 @@ grub_script_add_arglist (struct grub_parser_param *state,
 struct grub_script_cmd *
 grub_script_create_cmdline (struct grub_parser_param *state,
                            struct grub_script_arglist *arglist);
-struct grub_script_cmd *
-grub_script_create_cmdblock (struct grub_parser_param *state);
 
 struct grub_script_cmd *
 grub_script_create_cmdif (struct grub_parser_param *state,
@@ -262,9 +251,9 @@ grub_script_create_cmdmenu (struct grub_parser_param *state,
                            int options);
 
 struct grub_script_cmd *
-grub_script_add_cmd (struct grub_parser_param *state,
-                    struct grub_script_cmdblock *cmdblock,
-                    struct grub_script_cmd *cmd);
+grub_script_append_cmd (struct grub_parser_param *state,
+                       struct grub_script_cmd *list,
+                       struct grub_script_cmd *last);
 struct grub_script_arg *
 grub_script_arg_add (struct grub_parser_param *state,
                     struct grub_script_arg *arg,
@@ -301,7 +290,7 @@ void grub_script_yyerror (struct grub_parser_param *, char const *);
 
 /* Commands to execute, don't use these directly.  */
 grub_err_t grub_script_execute_cmdline (struct grub_script_cmd *cmd);
-grub_err_t grub_script_execute_cmdblock (struct grub_script_cmd *cmd);
+grub_err_t grub_script_execute_cmdlist (struct grub_script_cmd *cmd);
 grub_err_t grub_script_execute_cmdif (struct grub_script_cmd *cmd);
 grub_err_t grub_script_execute_cmdfor (struct grub_script_cmd *cmd);
 grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
index 40f1612678f880f95f0d9cc07a9cc59c305e0a8b..e10558b4d55b2ebac71221d2e3373bf9e44f82f1 100644 (file)
@@ -269,13 +269,13 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
 
 /* Execute a block of one or more commands.  */
 grub_err_t
-grub_script_execute_cmdblock (struct grub_script_cmd *cmd)
+grub_script_execute_cmdlist (struct grub_script_cmd *list)
 {
   int ret = 0;
-  struct grub_script_cmdblock *cmdblock = (struct grub_script_cmdblock *) cmd;
+  struct grub_script_cmd *cmd;
 
   /* Loop over every command and execute it.  */
-  for (cmd = cmdblock->cmdlist; cmd; cmd = cmd->next)
+  for (cmd = list->next; cmd; cmd = cmd->next)
     ret = grub_script_execute_cmd (cmd);
 
   return ret;
index b5815ea8de809e076b5e3a67087c83ca639eadbf..cc08af37a9ed4ec3f9e061a7b1ef52b8b8d31cb0 100644 (file)
@@ -96,9 +96,7 @@ script: newlines0
         }
       | script statement delimiter newlines0
         {
-          struct grub_script_cmdblock *cmdblock;
-          cmdblock = (struct grub_script_cmdblock *) $1;
-          $$ = grub_script_add_cmd (state, cmdblock, $2);
+          $$ = grub_script_append_cmd (state, $1, $2);
         }
       | error
         {
@@ -183,13 +181,11 @@ command: grubcmd  { $$ = $1; }
 /* A list of commands. */
 commands1: newlines0 command
            {
-             $$ = grub_script_add_cmd (state, 0, $2);
+             $$ = grub_script_append_cmd (state, 0, $2);
            }
          | commands1 delimiters1 command
            {
-             struct grub_script_cmdblock *cmdblock;
-            cmdblock = (struct grub_script_cmdblock *) $1;
-            $$ = grub_script_add_cmd (state, cmdblock, $3);
+            $$ = grub_script_append_cmd (state, $1, $3);
            }
 ;
 
index 4c87d94911a1e7eb35ed7d4f4f56bfdc10c0d142..9cee40dcb81ef51210539813cfb9e78cfa5a1167 100644 (file)
@@ -291,46 +291,40 @@ grub_script_create_cmdmenu (struct grub_parser_param *state,
   return (struct grub_script_cmd *) cmd;
 }
 
-/* Create a block of commands.  CMD contains the command that should
-   be added at the end of CMDBLOCK's list.  If CMDBLOCK is zero, a new
-   cmdblock will be created.  */
+/* Create a chain of commands.  LAST contains the command that should
+   be added at the end of LIST's list.  If LIST is zero, a new list
+   will be created.  */
 struct grub_script_cmd *
-grub_script_add_cmd (struct grub_parser_param *state,
-                    struct grub_script_cmdblock *cmdblock,
-                    struct grub_script_cmd *cmd)
+grub_script_append_cmd (struct grub_parser_param *state,
+                       struct grub_script_cmd *list,
+                       struct grub_script_cmd *last)
 {
   struct grub_script_cmd *ptr;
 
-  grub_dprintf ("scripting", "cmdblock\n");
+  grub_dprintf ("scripting", "append command\n");
 
-  if (!cmd)
-    return (struct grub_script_cmd *) cmdblock;
+  if (! last)
+    return list;
 
-  if (!cmdblock)
+  if (! list)
     {
-      cmdblock = grub_script_malloc (state, sizeof (*cmdblock));
-      if (!cmdblock)
+      list = grub_script_malloc (state, sizeof (*list));
+      if (! list)
        return 0;
 
-      cmdblock->cmd.exec = grub_script_execute_cmdblock;
-      cmdblock->cmd.next = 0;
-      cmdblock->cmdlist = cmd;
-      cmd->next = 0;
+      list->exec = grub_script_execute_cmdlist;
+      list->next = last;
     }
   else
     {
-      if (!cmdblock->cmdlist)
-       cmdblock->cmdlist = cmd;
-      else
-       {
-         ptr = cmdblock->cmdlist;
-         while (ptr->next)
-           ptr = ptr->next;
-         ptr->next = cmd;
-       }
+      ptr = list;
+      while (ptr->next)
+       ptr = ptr->next;
+
+      ptr->next = last;
     }
 
-  return (struct grub_script_cmd *) cmdblock;
+  return list;
 }
 \f
 
index dc732aa017ab66598ed11991bd11a3746a0602dc..3b7ab295d9e9feb8f9642fc7e71c8091f9929cc0 100644 (file)
@@ -70,7 +70,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd __attribute__ ((unused)
 }
 
 grub_err_t
-grub_script_execute_cmdblock (struct grub_script_cmd *cmd __attribute__ ((unused)))
+grub_script_execute_cmdlist (struct grub_script_cmd *cmd __attribute__ ((unused)))
 {
   return 0;
 }