]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
block argument support
authorBVK Chaitanya <bvk.groups@gmail.com>
Fri, 30 Apr 2010 06:39:31 +0000 (12:09 +0530)
committerBVK Chaitanya <bvk.groups@gmail.com>
Fri, 30 Apr 2010 06:39:31 +0000 (12:09 +0530)
include/grub/script_sh.h
script/execute.c
script/parser.y
script/yylex.l

index 17b1c5a5a79ddf0e7092727c6f888d559a897098..e1bf6f22e054f9341ffccd18aa0b64deba6a76ab 100644 (file)
@@ -49,7 +49,8 @@ typedef enum
   GRUB_SCRIPT_ARG_TYPE_TEXT,
   GRUB_SCRIPT_ARG_TYPE_DQVAR,
   GRUB_SCRIPT_ARG_TYPE_DQSTR,
-  GRUB_SCRIPT_ARG_TYPE_SQSTR
+  GRUB_SCRIPT_ARG_TYPE_SQSTR,
+  GRUB_SCRIPT_ARG_TYPE_BLOCK
 } grub_script_arg_type_t;
 
 /* A part of an argument.  */
@@ -59,6 +60,9 @@ struct grub_script_arg
 
   char *str;
 
+  /* Parsed block argument.  */
+  struct grub_script_cmd *block;
+
   /* Next argument part.  */
   struct grub_script_arg *next;
 };
index 40f1612678f880f95f0d9cc07a9cc59c305e0a8b..31fce554cda65567ab9cc9e2ebe02b241f6b8db3 100644 (file)
@@ -152,6 +152,7 @@ grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *c
                }
              break;
 
+           case GRUB_SCRIPT_ARG_TYPE_BLOCK:
            case GRUB_SCRIPT_ARG_TYPE_TEXT:
              if (grub_strlen (arg->str) > 0)
                {
index e5de35cf453892967b5767ef17c5311170235dde..9d256a15342ba9ad2d87206267af0c86c9d9012b 100644 (file)
@@ -74,7 +74,7 @@
 %token <arg> GRUB_PARSER_TOKEN_NAME      "name"
 %token <arg> GRUB_PARSER_TOKEN_WORD      "word"
 
-%type <arglist> word argument arguments0 arguments1
+%type <arglist> word argument block parameters0 parameters1 arguments0 arguments1
 
 %type <cmd> script_init script
 %type <cmd> grubcmd ifclause ifcmd forcmd whilecmd untilcmd
@@ -147,6 +147,27 @@ argument : "case"      { $$ = grub_script_add_arglist (state, 0, $1); }
          | word { $$ = $1; }
 ;
 
+block: "{" 
+       {
+         grub_script_lexer_ref (state->lexerstate);
+         $<offset>$ = grub_script_lexer_record_start (state);
+       }
+       commands1 delimiters0 "}"
+       {
+         char *p;
+         struct grub_script_arg *arg;
+
+         grub_script_lexer_deref (state->lexerstate);
+         if (p = grub_script_lexer_record_stop (state, $<offset>2))
+          *grub_strrchr (p, '}') = '\0';
+
+         if (arg = grub_script_arg_add (state, 0, GRUB_SCRIPT_ARG_TYPE_BLOCK, p))
+          arg->block = $3;
+
+         $$ = grub_script_add_arglist (state, 0, arg);
+       }
+;
+
 arguments0: /* Empty */ { $$ = 0; }
           | arguments1  { $$ = $1; }
 ;
@@ -162,7 +183,32 @@ arguments1: argument arguments0
             }
 ;
 
-grubcmd: word arguments0
+parameters1: argument parameters0
+             {
+               if ($1 && $2)
+                 {
+                   $1->next = $2;
+                   $1->argcount += $2->argcount;
+                   $2->argcount = 0;
+                 }
+               $$ = $1;
+             }
+           | block parameters0
+             {
+               if ($1 && $2)
+                 {
+                   $1->next = $2;
+                   $1->argcount += $2->argcount;
+                   $2->argcount = 0;
+                 }
+               $$ = $1;
+             }
+;
+parameters0: /* Empty */ { $$ = 0; }
+           | parameters1 { $$ = $1; }
+;
+
+grubcmd: word parameters0
          {
            if ($1 && $2) {
              $1->next = $2;
index 29aa5c2e3a73fd56486acb12d23ecbe9fb990a55..585f818cb2d0da844ec0d1dfc0ddf4499cc6c96d 100644 (file)
@@ -114,7 +114,7 @@ typedef size_t yy_size_t;
 BLANK           [ \t]
 COMMENT         ^[ \t]*#.*$
 
-CHAR            [^|&$;<> \t\n\'\"\\]
+CHAR            [^{}|&$;<> \t\n\'\"\\]
 DIGITS          [[:digit:]]+
 NAME            [[:alpha:]_][[:alnum:][:digit:]_]*