While and until loops support to GRUB script
PATCH 1/1 While and until loops support to GRUB script
Hi,
Attached patch adds while and until commands support to GRUB script.
It is also available in people/bvk/while-loop-support branch. This
doesn't have any unit tests yet -- i am still thinking of how to break out of the loop, after few iterations. Also, i am not sure how to handle Ctrl-C to break out of the loop, if at all we want to support it :-(
thanks,
Signature · 1 line
bvk.chaitanya
=== modified file 'ChangeLog.scripting'
ChangeLog.scripting +14 -0
@@ -1,3 +1,17 @@ +2009-12-26 BVK Chaitanya <[email protected]> + + * include/grub/script_sh.h: New function prototypes for + grub_script_create_cmdwhile and grub_script_execute_cmdwhile. + * script/parser.y ("whilecmd"): New grammar rule for while + command. + ("untilcmd"): New grammar rule for until command. + * script/script.c (grub_script_create_cmdwhile): Creates a + while/until command object. + * script/execute.c (grub_script_execute_cmdwhile): Executes a + while/until command object. + * util/grub-script-check.c (grub_script_execute_cmdwhile): Dummy + stub for syntax checking while/until statements. + 2009-12-25 BVK Chaitanya <[email protected]> * include/grub/script_sh.h (grub_script_arg_type_t): New types
=== modified file 'include/grub/script_sh.h'
grub/script_sh.h +22 -0
@@ -121,6 +121,21 @@struct grub_script_cmd *list; }; +/* A while/until command. */ +struct grub_script_cmdwhile +{ +struct grub_script_cmd cmd; + +/* The command list used as condition. */ +struct grub_script_cmd *cond; + +/* The command list executed in each loop. */ +struct grub_script_cmd *list; + +/* The flag to indicate this as "until" loop. */ +int until; +}; +/* A menu entry generate statement. */ struct grub_script_cmd_menuentry {
@@ -236,6 +251,12 @@ struct grub_script_cmd *list);struct grub_script_cmd * +grub_script_create_cmdwhile (struct grub_parser_param *state, +struct grub_script_cmd *cond, +struct grub_script_cmd *list, +int is_an_until_loop); + +struct grub_script_cmd * grub_script_create_cmdmenu (struct grub_parser_param *state, struct grub_script_arglist *arglist, char *sourcecode,
@@ -284,6 +305,7 @@grub_err_t grub_script_execute_cmdblock (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);grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd);/* Execute any GRUB pre-parsed command or script. */
=== modified file 'script/execute.c'
execute.c +20 -0
@@ -296,6 +296,26 @@return result; } +/* Execute a "while" or "until" command. */ +grub_err_t +grub_script_execute_cmdwhile (struct grub_script_cmd *cmd) +{ +int cond; +int result; +struct grub_script_cmdwhile *cmdwhile = (struct grub_script_cmdwhile *) cmd; + + result =0 ; +do { + cond =grub_script_execute_cmd (cmdwhile->cond); +if ((cmdwhile->until && !cond) || (!cmdwhile->until && cond)) +break ; + + result =grub_script_execute_cmd (cmdwhile->list); + }while (1 );/* XXX Put a check for ^C here */ + +return result; +} +/* Execute the menu entry generate statement. */ grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd)
=== modified file 'script/parser.y'
parser.y +30 -5
@@ -76,8 +76,9 @@ %token <arg> GRUB_PARSER_TOKEN_WORD "word" %type <arglist> word argument arguments0 arguments1 -%type <cmd> script_init script grubcmd ifcmd forcmd command -%type <cmd> commands1 menuentry statement +%type <cmd> script_init script +%type <cmd> grubcmd ifcmd forcmd whilecmd untilcmd +%type <cmd> command commands1 menuentry statement %pure-parser %error-verbose
@@ -179,9 +180,11 @@ ; /* A single command. */ -command: grubcmd { $$ = $1; } - | ifcmd { $$ = $1; } - | forcmd { $$ = $1; } +command: grubcmd { $$ = $1; } + | ifcmd { $$ = $1; } + | forcmd { $$ = $1; } + | whilecmd { $$ = $1; } + | untilcmd { $$ = $1; } ; /* A list of commands. */
@@ -261,3 +264,25 @@ grub_script_lexer_deref (state->lexerstate); } ; + +whilecmd: "while" + { + grub_script_lexer_ref (state->lexerstate); + } + commands1 delimiters1 "do" commands1 delimiters1 "done" + { + $$ = grub_script_create_cmdwhile (state, $3, $6, 0); + grub_script_lexer_deref (state->lexerstate); + } +; + +untilcmd: "until" + { + grub_script_lexer_ref (state->lexerstate); + } + commands1 delimiters1 "do" commands1 delimiters1 "done" + { + $$ = grub_script_create_cmdwhile (state, $3, $6, 1); + grub_script_lexer_deref (state->lexerstate); + } +;
=== modified file 'script/script.c'
script.c +22 -0
@@ -230,6 +230,28 @@return (struct grub_script_cmd *) cmd; } +/* Create a "while" or "until" command. */ +struct grub_script_cmd * +grub_script_create_cmdwhile (struct grub_parser_param *state, +struct grub_script_cmd *cond, +struct grub_script_cmd *list, +int is_an_until_loop) +{ +struct grub_script_cmdwhile *cmd; + + cmd =grub_script_malloc (state,sizeof (*cmd)); +if (! cmd) +return 0 ; + + cmd->cmd.exec = grub_script_execute_cmdwhile; + cmd->cmd.next =0 ; + cmd->cond = cond; + cmd->list = list; + cmd->until = is_an_until_loop; + +return (struct grub_script_cmd *) cmd; +} +/* Create a command that adds a menu entry to the menu. Title is an argument that is parsed to generate a string that can be used as the title. The sourcecode for this entry is passed in SOURCECODE.
=== modified file 'util/grub-script-check.c'
grub-script-check.c +6 -0
@@ -84,6 +84,12 @@ }grub_err_t +grub_script_execute_cmdwhile (struct grub_script_cmd *cmd __attribute__ ((unused))) +{ +return 0 ; +} + +grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd) {struct grub_script_cmd_menuentry *menu;
Hi,
Attached patch implements while and until loops support to GRUB script. Its been pushed into branches/while-until-loops as well. Let me know your comments.
Signature · 1 line
bvk.chaitanya
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email protected] # target_branch: file:///home/bvk/Work/grub2/for-loop/
# testament_sha1: 765eb235c266725c213c934ee0086cdd9cac5e53 # timestamp: 2010-01-26 09:40:09 +0530
# base_revision_id: [email protected]\
# ukj4s8lpltdoslue
#
# Begin patch
=== added file 'ChangeLog.while-until-loops'
ChangeLog.while-until-loops +15 -0
@@ -0,0 +1,15 @@ +2010-01-26 BVK Chaitanya <[email protected]> + + While and until loops support to GRUB script. + + * include/grub/script_sh.h (grub_script_cmdwhile): New struct. + (grub_script_create_cmdwhile): New function prototype. + (grub_script_execute_cmdwhile): New function prototype. + * script/execute.c (grub_script_execute_cmdwhile): New function. + * script/parser.y (command): New commands. + (whilecmd): New grammar rule. + (untilcmd): New grammar rule. + * script/script.c (grub_script_create_cmdwhile): New function. + * util/grub-script-check.c (grub_script_execute_cmdwhile): New + function. +
=== modified file 'include/grub/script_sh.h'
grub/script_sh.h +22 -0
@@ -121,6 +121,21 @@struct grub_script_cmd *list; }; +/* A while/until command. */ +struct grub_script_cmdwhile +{ +struct grub_script_cmd cmd; + +/* The command list used as condition. */ +struct grub_script_cmd *cond; + +/* The command list executed in each loop. */ +struct grub_script_cmd *list; + +/* The flag to indicate this as "until" loop. */ +int until; +}; +/* A menu entry generate statement. */ struct grub_script_cmd_menuentry {
@@ -235,6 +250,12 @@ struct grub_script_cmd *list);struct grub_script_cmd * +grub_script_create_cmdwhile (struct grub_parser_param *state, +struct grub_script_cmd *cond, +struct grub_script_cmd *list, +int is_an_until_loop); + +struct grub_script_cmd * grub_script_create_cmdmenu (struct grub_parser_param *state, struct grub_script_arglist *arglist, char *sourcecode,
@@ -283,6 +304,7 @@grub_err_t grub_script_execute_cmdblock (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);grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd);/* Execute any GRUB pre-parsed command or script. */
=== modified file 'script/execute.c'
execute.c +20 -0
@@ -308,6 +308,26 @@return result; } +/* Execute a "while" or "until" command. */ +grub_err_t +grub_script_execute_cmdwhile (struct grub_script_cmd *cmd) +{ +int cond; +int result; +struct grub_script_cmdwhile *cmdwhile = (struct grub_script_cmdwhile *) cmd; + + result =0 ; +do { + cond =grub_script_execute_cmd (cmdwhile->cond); +if ((cmdwhile->until && !cond) || (!cmdwhile->until && cond)) +break ; + + result =grub_script_execute_cmd (cmdwhile->list); + }while (1 );/* XXX Put a check for ^C here */ + +return result; +} +/* Execute the menu entry generate statement. */ grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd)
=== modified file 'script/parser.y'
parser.y +30 -5
@@ -76,8 +76,9 @@ %token <arg> GRUB_PARSER_TOKEN_WORD "word" %type <arglist> word argument arguments0 arguments1 -%type <cmd> script_init script grubcmd ifcmd forcmd command -%type <cmd> commands1 menuentry statement +%type <cmd> script_init script +%type <cmd> grubcmd ifcmd forcmd whilecmd untilcmd +%type <cmd> command commands1 menuentry statement %pure-parser %lex-param { struct grub_parser_param *state };
@@ -173,9 +174,11 @@ ; /* A single command. */ -command: grubcmd { $$ = $1; } - | ifcmd { $$ = $1; } - | forcmd { $$ = $1; } +command: grubcmd { $$ = $1; } + | ifcmd { $$ = $1; } + | forcmd { $$ = $1; } + | whilecmd { $$ = $1; } + | untilcmd { $$ = $1; } ; /* A list of commands. */
@@ -250,3 +253,25 @@ grub_script_lexer_deref (state->lexerstate); } ; + +whilecmd: "while" + { + grub_script_lexer_ref (state->lexerstate); + } + commands1 delimiters1 "do" commands1 delimiters1 "done" + { + $$ = grub_script_create_cmdwhile (state, $3, $6, 0); + grub_script_lexer_deref (state->lexerstate); + } +; + +untilcmd: "until" + { + grub_script_lexer_ref (state->lexerstate); + } + commands1 delimiters1 "do" commands1 delimiters1 "done" + { + $$ = grub_script_create_cmdwhile (state, $3, $6, 1); + grub_script_lexer_deref (state->lexerstate); + } +;
=== modified file 'script/script.c'
script.c +22 -0
@@ -245,6 +245,28 @@return (struct grub_script_cmd *) cmd; } +/* Create a "while" or "until" command. */ +struct grub_script_cmd * +grub_script_create_cmdwhile (struct grub_parser_param *state, +struct grub_script_cmd *cond, +struct grub_script_cmd *list, +int is_an_until_loop) +{ +struct grub_script_cmdwhile *cmd; + + cmd =grub_script_malloc (state,sizeof (*cmd)); +if (! cmd) +return 0 ; + + cmd->cmd.exec = grub_script_execute_cmdwhile; + cmd->cmd.next =0 ; + cmd->cond = cond; + cmd->list = list; + cmd->until = is_an_until_loop; + +return (struct grub_script_cmd *) cmd; +} +/* Create a command that adds a menu entry to the menu. Title is an argument that is parsed to generate a string that can be used as the title. The sourcecode for this entry is passed in SOURCECODE.
=== modified file 'util/grub-script-check.c'
grub-script-check.c +6 -0
@@ -88,6 +88,12 @@ }grub_err_t +grub_script_execute_cmdwhile (struct grub_script_cmd *cmd __attribute__ ((unused))) +{ +return 0 ; +} + +grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd __attribute__ ((unused))) {return 0 ;
# Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWbxZFYYAB/7fgHkwd3f//3qN 18G////+YAy+s+32+7y++33roxKhRQL7vtfPV973OvtqGcYKKUKosJJE0aTKPVPUMekxNPTVDbRp EB6mgAB6h6CaCSIRk0BMTSE0Q2U0aNAaAB6gAAAyJpMpijag9I9T1NGmmh6gAAABoANAJNSUap+o ageptE8kZNMQ9RiaMgAZBkDQYIlEEKP1J6j0g2o08iaaZNNNGjQNAA0DIyCKJAmTIBMmmjSY0k1P 0aUaeUZA9TQABtReC3jeMGDFco/40kOmUNULYE5abUs6CAVyuxZszZZyWON0WkDczNtsM9ttp8zq Hb0JpmKn7xVzfLuKC4IkUMKTbwIM45A8NdN683qaKO7g+WEGteccpIRRkKxDvjbz0MNX8zWqt7tX a2V8I24uTa7icSDI/CNgdoInaVwEO6RlSewZfplIIgQlcP5uENO46nYDIjnRaH7M/c32bgwn+2/p d6A6UKOdmK8pchKlCTnLTL4iaENiCLFFBZEary8j/IHnXYZBb5UPPwuOdVdAl8yJ8iSqCrNSiPVA 4PcCGQRYLRWcs8JCWxS4ItC1usj2AKNu8QbXhbPSTsWv62qp2Mh+k54mYw+ZxLdZv79YU2SUC3N/ UfPWHsrEU0gvBmOmnhhdcHTriqFJDY6+fc1gB1sLUuud1BBEj4YLP2Npo24LgWV3HIdtnv9PhKVT m9zNj1IcvgNSuLVfouvaBSNkkaWDonBl0GJtSjs2615emB2brs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A26g9Q2Q5lr1Ad68H4D2jgIkPWjRcPQ3o/aB1ifYQiPaDoF0Mg0DlAiWELXClcNofIMG4J3Ef NnHi4TDfVaaLyhEEhoA8EbQ8gLnXpAwNaKfNFM/AA5L+UuAQtHTp5vUJc4C2EMNCpDNMEFRMCcEC ELW8YFuVLCqQkY1RlGkoMTcrUNVphCQhYAwhMCzKFQdfedzt0uWan1g1lYq3okKWn6GsG7QmKxLA 6TExRhDmjwaIXgWWlCBElNyfaMgZt5vZGAfX1iKi9DjS9ucoGDlauQtaiJHMotlS5HiRyRseDHBD WQhU0RqORrChXPx4DQ1lqJo98MQaHwZQs323KLguoKqtiZCJWjaucYFCMqoNwJjKtINuaXvV6oRN 1A0j3lsHzAtES5v8XP2PgT20iJdaARCUpEdZsdpg6x33BDeREJI8zJWRz5G2FiCI3AZ2wCG8Oh6L dgjJxID3lUEFKS2hBX6Y6Y3/p9hw3Wz3KFtHVqmsL0lskChcXtEArGBLwbXEEFqXAZL1YFzGgQJC Qx0zOIMAbXuFZrdtrnEzQMQBoHJL7jJGtC4zzQEmOA3OTKHIvO4zeS1Ase2aEDIoOeAmzWwBdjyA rOrk6ghPe89xzDaZgp2MHLtipb3qET3HELdP/uScIEyr8W1bUNCtoibkCsfa+g1occ0Kd+DInwo1 Ug2bazgdw5vpAoVcgjoRoPWDMmnZAveE1D3E1Am9Hl6ApYSQLRldIu5IpwoSF4sisMA=
Adding a testcase for while and until loops caught several GRUB script bugs in handling return value ($?). Attached patch has these issues fixed along with the testcase. Its been pushed into branches/while-until-loops as well.
Signature · 1 line
bvk.chaitanya
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email protected] # target_branch: file:///home/bvk/Work/grub2/for-loop/
# testament_sha1: ab52b0aa586f2d8c04f5b84e8685bac20ce2d57c # timestamp: 2010-01-26 12:33:11 +0530
# base_revision_id: [email protected]\
# ukj4s8lpltdoslue
#
# Begin patch
=== added file 'ChangeLog.while-until-loops'
ChangeLog.while-until-loops +20 -0
@@ -0,0 +1,20 @@ +2010-01-26 BVK Chaitanya <[email protected]> + + While and until loops support to GRUB script. + + * include/grub/script_sh.h (grub_script_cmdwhile): New struct. + (grub_script_create_cmdwhile): New function prototype. + (grub_script_execute_cmdwhile): New function prototype. + * script/execute.c (grub_script_execute_cmdwhile): New function. + * script/parser.y (command): New commands. + (whilecmd): New grammar rule. + (untilcmd): New grammar rule. + * script/script.c (grub_script_create_cmdwhile): New function. + * util/grub-script-check.c (grub_script_execute_cmdwhile): New + function. + + * tests/grub_script_while1.in: New testcase. + * conf/tests.rmk: New testcase make rule. + + * commands/true.c (grub_cmd_false): Remove printing error message. + * commands/test.c (grub_cmd_test): Likewise.
=== modified file 'commands/test.c'
test.c +1 -2
@@ -412,8 +412,7 @@if (argc >=1 &&grub_strcmp (args[argc -1 ],"]" ) ==0 ) argc--; -return test_parse (args, &argn, argc) ?GRUB_ERR_NONE - :grub_error (GRUB_ERR_TEST_FAILURE ,"false" ); +return test_parse (args, &argn, argc) ?0 :1 ; }static grub_command_t cmd_1, cmd_2;
=== modified file 'commands/true.c'
true.c +1 -1
@@ -34,7 +34,7 @@ int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused))) { -return grub_error (GRUB_ERR_TEST_FAILURE ,"false" ); +return 1 ; }static grub_command_t cmd_true, cmd_false;
=== modified file 'conf/tests.rmk'
tests.rmk +4 -0
@@ -53,6 +53,9 @@ check_SCRIPTS += grub_script_for1 grub_script_for1_SOURCES = tests/grub_script_for1.in +check_SCRIPTS += grub_script_while1 +grub_script_while1_SOURCES = tests/grub_script_while1.in + # List of tests to execute on "make check" # SCRIPTED_TESTS = example_scripted_test # SCRIPTED_TESTS += example_grub_script_test
@@ -63,6 +66,7 @@ SCRIPTED_TESTS += grub_script_echo_keywords SCRIPTED_TESTS += grub_script_vars1 SCRIPTED_TESTS += grub_script_for1 +SCRIPTED_TESTS += grub_script_while1 # dependencies between tests and testing-tools $(SCRIPTED_TESTS): grub-shell grub-shell-tester
=== modified file 'include/grub/script_sh.h'
grub/script_sh.h +22 -0
@@ -121,6 +121,21 @@struct grub_script_cmd *list; }; +/* A while/until command. */ +struct grub_script_cmdwhile +{ +struct grub_script_cmd cmd; + +/* The command list used as condition. */ +struct grub_script_cmd *cond; + +/* The command list executed in each loop. */ +struct grub_script_cmd *list; + +/* The flag to indicate this as "until" loop. */ +int until; +}; +/* A menu entry generate statement. */ struct grub_script_cmd_menuentry {
@@ -235,6 +250,12 @@ struct grub_script_cmd *list);struct grub_script_cmd * +grub_script_create_cmdwhile (struct grub_parser_param *state, +struct grub_script_cmd *cond, +struct grub_script_cmd *list, +int is_an_until_loop); + +struct grub_script_cmd * grub_script_create_cmdmenu (struct grub_parser_param *state, struct grub_script_arglist *arglist, char *sourcecode,
@@ -283,6 +304,7 @@grub_err_t grub_script_execute_cmdblock (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);grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd);/* Execute any GRUB pre-parsed command or script. */
=== modified file 'script/execute.c'
execute.c +36 -12
95 lines not on this page · raw message
=== modified file 'script/parser.y'
parser.y +30 -5
@@ -76,8 +76,9 @@ %token <arg> GRUB_PARSER_TOKEN_WORD "word" %type <arglist> word argument arguments0 arguments1 -%type <cmd> script_init script grubcmd ifcmd forcmd command -%type <cmd> commands1 menuentry statement +%type <cmd> script_init script +%type <cmd> grubcmd ifcmd forcmd whilecmd untilcmd +%type <cmd> command commands1 menuentry statement %pure-parser %lex-param { struct grub_parser_param *state };
@@ -173,9 +174,11 @@ ; /* A single command. */ -command: grubcmd { $$ = $1; } - | ifcmd { $$ = $1; } - | forcmd { $$ = $1; } +command: grubcmd { $$ = $1; } + | ifcmd { $$ = $1; } + | forcmd { $$ = $1; } + | whilecmd { $$ = $1; } + | untilcmd { $$ = $1; } ; /* A list of commands. */
@@ -250,3 +253,25 @@ grub_script_lexer_deref (state->lexerstate); } ; + +whilecmd: "while" + { + grub_script_lexer_ref (state->lexerstate); + } + commands1 delimiters1 "do" commands1 delimiters1 "done" + { + $$ = grub_script_create_cmdwhile (state, $3, $6, 0); + grub_script_lexer_deref (state->lexerstate); + } +; + +untilcmd: "until" + { + grub_script_lexer_ref (state->lexerstate); + } + commands1 delimiters1 "do" commands1 delimiters1 "done" + { + $$ = grub_script_create_cmdwhile (state, $3, $6, 1); + grub_script_lexer_deref (state->lexerstate); + } +;
=== modified file 'script/script.c'
script.c +22 -0
@@ -245,6 +245,28 @@return (struct grub_script_cmd *) cmd; } +/* Create a "while" or "until" command. */ +struct grub_script_cmd * +grub_script_create_cmdwhile (struct grub_parser_param *state, +struct grub_script_cmd *cond, +struct grub_script_cmd *list, +int is_an_until_loop) +{ +struct grub_script_cmdwhile *cmd; + + cmd =grub_script_malloc (state,sizeof (*cmd)); +if (! cmd) +return 0 ; + + cmd->cmd.exec = grub_script_execute_cmdwhile; + cmd->cmd.next =0 ; + cmd->cond = cond; + cmd->list = list; + cmd->until = is_an_until_loop; + +return (struct grub_script_cmd *) cmd; +} +/* Create a command that adds a menu entry to the menu. Title is an argument that is parsed to generate a string that can be used as the title. The sourcecode for this entry is passed in SOURCECODE.
=== added file 'tests/grub_script_while1.in'
grub_script_while1.in +32 -0
@@ -0,0 +1,32 @@ +#! @builddir@/grub-shell-tester + +echo one +foo="" +while test "$foo" != "1111"; do foo="${foo}1"; echo "$foo"; done + +echo two +foo="" +while test "$foo" != "aaaa" +do + foo="${foo}a" + echo $foo +done + +foo="" +until test "$foo" = "1111"; do foo="${foo}1"; echo $foo; done +foo="" +until test "$foo" = "aaaa" +do + foo="${foo}a" + echo $foo +done + +# check "$?" in condition gets its value from while body commands +foo="" +false +while test "$?" != "0" +do + echo $foo + foo="${foo}1" + test "$foo" = "111111" +done
=== modified file 'util/grub-script-check.c'
grub-script-check.c +6 -0
@@ -88,6 +88,12 @@ }grub_err_t +grub_script_execute_cmdwhile (struct grub_script_cmd *cmd __attribute__ ((unused))) +{ +return 0 ; +} + +grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd __attribute__ ((unused))) {return 0 ;
# Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWSANpQwADi1fgHkwf3////+v 38u////+YBSe871fPvHbXivO3fe6vdnS2edgAPT6OQAvvC7N93ut7ve+577zW7aHbmh1HTumAVGt QDYShFNpolPanpoaGjRQbSeUDNJo0aZANAAANASSATTETJoiZomimnpqDI0BoaANAAAAGpmkKYke KeoMgABoAAAAAAAABJqSAgmiYE0DRtGVPTJJmiaGjRtIBoYQ2kNBEomiARo0NU8SPUbUPU8KeSG1 DJo0AepkAPUbTUEUiAmQ0NAmp4TSYp6mFN6p+pNHqaaNBp6QAAGjzmsxokimMcYwYMBNQ9x4SF+g qa0vizzte+jc3/l46r7agef+ebbHqNvBrTst18ENGvR6bVFRl1ZVD8EU+/drTVhv30fWe+9/6Xcw nv5jxaNOdNYPOHBuceGw/jLv8GuJxE6yTmGQ8mOe1Gpx6o2aUXJBHhgQ1dvCaSR9ik24rhz7Kqio 4TUstZlqQmWpFqzyfNAPYsyBSe5JG63ZnDqogwzWd/qPBN2+d9OKjbW9L2JBoGiqyuFC1ikGipfP BVKPhGhQIuD6gllNBLCRLSTjYHaAD2lLAQm6QyBl+zos3uwkCVwlcIQVzkTufdt/vCdnf848A9Op zlgdUkQgEofgbe/11vmuaw+taa7g4+6oxVkgPeDGxU3InoLU4yVKEnvNXo/sX4T0+YJrIbSDBVgo LFFUWCwU/XzbDZH8IQ3c+OQchPnz7u6+n1p38vf3cBfRasR2bdWM0a6MNKGh7NVYulpmM1cV+OeG g5oJMXVkViRKis8wWAmRgyKIKWg5TFACiPUFFgozhnKV6kMiY08CDVha4Zlxtuuz6ePBd9RK0u/y UyHqaDu14Fak6rR8l9vxrVyfO1sZ1pfxHtzKzDs718eS789Wq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