2006-01-17 Marco Gerards <marco@gnu.org>
* include/grub/normal.h: Include <grub/script.h>. (grub_command_list): Removed struct. (grub_command_list_t): Removed type. (grub_menu_entry): Remove members `num' and `command_list'. Add members `commands' and `sourcecode'. * include/grub/script.h: Add inclusion guards. (grub_script_cmd_menuentry): New struct. (grub_script_execute_menuentry): New prototype. (grub_script_lexer_record_start): Likewise. (grub_script_lexer_record_stop): Likewise. * normal/execute.c (grub_script_execute_menuentry): New function. * normal/lexer.c (record, recording, recordpos, recordlen): New variables. (grub_script_lexer_record_start): New function. (grub_script_lexer_record_stop): Likewise. (recordchar): Likewise. (nextchar): Likewise. (grub_script_yylex): Use `nextchar' to fetch new characters. Use 2048 as the buffer size. Add the tokens `menuentry' and `@'. * normal/main.c: Include <grub/parser.h> and <grub/script.h> (current_menu): New variable. (free_menu): Mainly rewritten. (grub_normal_menu_addentry): New function. (read_config_file): Rewritten. * normal/menu.c (run_menu_entry): Mainly rewritten. * normal/menu_entry.c (make_screen): Rewritten te code to insert the menu entry. (run): Mainly rewritten. * normal/parser.y (menu_entry): New variable. (GRUB_PARSER_TOKEN_MENUENTRY): New token. (menuentry): New rule. (command): Add `menuentry'. (if_statement): Allow additional returns before `fi'. * normal/script.c (grub_script_create_cmdmenu): New function.
This commit is contained in:
parent
144f1f986f
commit
77c4a3939d
10 changed files with 378 additions and 221 deletions
|
@ -28,6 +28,8 @@
|
|||
/* Keep track of the memory allocated for this specific function. */
|
||||
static struct grub_script_mem *func_mem = 0;
|
||||
|
||||
static char *menu_entry = 0;
|
||||
|
||||
%}
|
||||
|
||||
%union {
|
||||
|
@ -40,12 +42,13 @@ static struct grub_script_mem *func_mem = 0;
|
|||
%token GRUB_PARSER_TOKEN_IF "if"
|
||||
%token GRUB_PARSER_TOKEN_WHILE "while"
|
||||
%token GRUB_PARSER_TOKEN_FUNCTION "function"
|
||||
%token GRUB_PARSER_TOKEN_MENUENTRY "menuentry"
|
||||
%token GRUB_PARSER_TOKEN_ELSE "else"
|
||||
%token GRUB_PARSER_TOKEN_THEN "then"
|
||||
%token GRUB_PARSER_TOKEN_FI "fi"
|
||||
%token GRUB_PARSER_TOKEN_NAME
|
||||
%token GRUB_PARSER_TOKEN_VAR
|
||||
%type <cmd> script grubcmd command commands if
|
||||
%type <cmd> script grubcmd command commands menuentry if
|
||||
%type <arglist> arguments;
|
||||
%type <arg> argument;
|
||||
%type <string> "if" "while" "function" "else" "then" "fi"
|
||||
|
@ -53,7 +56,7 @@ static struct grub_script_mem *func_mem = 0;
|
|||
|
||||
%%
|
||||
/* It should be possible to do this in a clean way... */
|
||||
script: commands '\n'
|
||||
script: commands returns
|
||||
{
|
||||
grub_script_parsed = $1;
|
||||
}
|
||||
|
@ -127,6 +130,7 @@ grubcmd: ws GRUB_PARSER_TOKEN_NAME ' ' arguments ws
|
|||
command: grubcmd { $$ = $1; }
|
||||
| if { $$ = $1; }
|
||||
| function { $$ = 0; }
|
||||
| menuentry { $$ = $1; }
|
||||
;
|
||||
|
||||
/* A block of commands. */
|
||||
|
@ -172,6 +176,24 @@ function: "function" ' ' GRUB_PARSER_TOKEN_NAME
|
|||
}
|
||||
;
|
||||
|
||||
/* A menu entry. Carefully save the memory that is allocated. */
|
||||
menuentry: "menuentry" ' ' argument
|
||||
{
|
||||
grub_script_lexer_ref ();
|
||||
} ws '{' returns
|
||||
{
|
||||
/* Record sourcecode of the menu entry. It can be
|
||||
parsed multiple times if it is part of a
|
||||
loop. */
|
||||
grub_script_lexer_record_start ();
|
||||
} commands returns '}'
|
||||
{
|
||||
menu_entry = grub_script_lexer_record_stop ();
|
||||
$$ = grub_script_create_cmdmenu ($3, menu_entry, 0);
|
||||
grub_script_lexer_deref ();
|
||||
}
|
||||
;
|
||||
|
||||
/* The first part of the if statement. It's used to switch the lexer
|
||||
to a state in which it demands more tokens. */
|
||||
if_statement: "if" { grub_script_lexer_ref (); }
|
||||
|
@ -183,7 +205,7 @@ if: if_statement grubcmd ';' ws "then" returns commands returns "fi"
|
|||
$$ = grub_script_create_cmdif ($2, $7, 0);
|
||||
grub_script_lexer_deref ();
|
||||
}
|
||||
| if_statement grubcmd ';' ws "then" returns commands returns "else" returns commands "fi"
|
||||
| if_statement grubcmd ';' ws "then" returns commands returns "else" returns commands returns "fi"
|
||||
{
|
||||
$$ = grub_script_create_cmdif ($2, $7, $11);
|
||||
grub_script_lexer_deref ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue