Not command (!) support to GRUB script.
* tests/grub_script_not.in: New test. * Makefile.util.def: Rules for new test. * grub-core/script/execute.c (grub_script_execute_cmdline): Handle ! command as a special case. * grub-core/script/yylex.l (GRUB_PARSER_TOKEN_NOT): Removed.
This commit is contained in:
commit
058e30ac09
5 changed files with 116 additions and 6 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,6 +1,18 @@
|
||||||
|
2010-09-08 BVK Chaitanya <bvk.groups@gmail.com>
|
||||||
|
|
||||||
|
Not command (!) support to GRUB script.
|
||||||
|
|
||||||
|
* tests/grub_script_not.in: New test.
|
||||||
|
* Makefile.util.def: Rules for new test.
|
||||||
|
|
||||||
|
* grub-core/script/execute.c (grub_script_execute_cmdline): Handle
|
||||||
|
! command as a special case.
|
||||||
|
* grub-core/script/yylex.l (GRUB_PARSER_TOKEN_NOT): Removed.
|
||||||
|
|
||||||
2010-09-07 BVK Chaitanya <bvk.groups@gmail.com>
|
2010-09-07 BVK Chaitanya <bvk.groups@gmail.com>
|
||||||
|
|
||||||
* grub-core/commands/wildcard.c (wildcard_expand): Fix wrong grub_free.
|
* grub-core/commands/wildcard.c (wildcard_expand): Fix wrong
|
||||||
|
grub_free.
|
||||||
|
|
||||||
2010-09-07 BVK Chaitanya <bvk.groups@gmail.com>
|
2010-09-07 BVK Chaitanya <bvk.groups@gmail.com>
|
||||||
|
|
||||||
|
|
|
@ -531,6 +531,12 @@ script = {
|
||||||
common = tests/grub_script_expansion.in;
|
common = tests/grub_script_expansion.in;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
script = {
|
||||||
|
testcase;
|
||||||
|
name = grub_script_not;
|
||||||
|
common = tests/grub_script_not.in;
|
||||||
|
};
|
||||||
|
|
||||||
program = {
|
program = {
|
||||||
testcase;
|
testcase;
|
||||||
name = example_unit_test;
|
name = example_unit_test;
|
||||||
|
|
|
@ -547,13 +547,32 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
||||||
grub_script_function_t func = 0;
|
grub_script_function_t func = 0;
|
||||||
char errnobuf[18];
|
char errnobuf[18];
|
||||||
char *cmdname;
|
char *cmdname;
|
||||||
|
int argc;
|
||||||
|
char **args;
|
||||||
|
int invert;
|
||||||
struct grub_script_argv argv = { 0, 0, 0 };
|
struct grub_script_argv argv = { 0, 0, 0 };
|
||||||
|
|
||||||
/* Lookup the command. */
|
/* Lookup the command. */
|
||||||
if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0])
|
if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0])
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
|
|
||||||
|
invert = 0;
|
||||||
|
argc = argv.argc - 1;
|
||||||
|
args = argv.args + 1;
|
||||||
cmdname = argv.args[0];
|
cmdname = argv.args[0];
|
||||||
|
if (grub_strcmp (cmdname, "!") == 0)
|
||||||
|
{
|
||||||
|
if (argv.argc < 2 || ! argv.args[1])
|
||||||
|
{
|
||||||
|
grub_script_argv_free (&argv);
|
||||||
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing arguments");
|
||||||
|
}
|
||||||
|
|
||||||
|
invert = 1;
|
||||||
|
argc = argv.argc - 2;
|
||||||
|
args = argv.args + 2;
|
||||||
|
cmdname = argv.args[1];
|
||||||
|
}
|
||||||
grubcmd = grub_command_find (cmdname);
|
grubcmd = grub_command_find (cmdname);
|
||||||
if (! grubcmd)
|
if (! grubcmd)
|
||||||
{
|
{
|
||||||
|
@ -594,13 +613,25 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
||||||
{
|
{
|
||||||
if ((grubcmd->flags & GRUB_COMMAND_FLAG_BLOCKS) &&
|
if ((grubcmd->flags & GRUB_COMMAND_FLAG_BLOCKS) &&
|
||||||
(grubcmd->flags & GRUB_COMMAND_FLAG_EXTCMD))
|
(grubcmd->flags & GRUB_COMMAND_FLAG_EXTCMD))
|
||||||
ret = grub_extcmd_dispatcher (grubcmd, argv.argc - 1, argv.args + 1,
|
ret = grub_extcmd_dispatcher (grubcmd, argc, args, argv.script);
|
||||||
argv.script);
|
|
||||||
else
|
else
|
||||||
ret = (grubcmd->func) (grubcmd, argv.argc - 1, argv.args + 1);
|
ret = (grubcmd->func) (grubcmd, argc, args);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret = grub_script_function_call (func, argv.argc - 1, argv.args + 1);
|
ret = grub_script_function_call (func, argc, args);
|
||||||
|
|
||||||
|
if (invert)
|
||||||
|
{
|
||||||
|
if (ret == GRUB_ERR_TEST_FAILURE)
|
||||||
|
grub_errno = ret = GRUB_ERR_NONE;
|
||||||
|
else if (ret == GRUB_ERR_NONE)
|
||||||
|
ret = grub_error (GRUB_ERR_TEST_FAILURE, "false");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
grub_print_error ();
|
||||||
|
ret = GRUB_ERR_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Free arguments. */
|
/* Free arguments. */
|
||||||
grub_script_argv_free (&argv);
|
grub_script_argv_free (&argv);
|
||||||
|
|
|
@ -155,7 +155,6 @@ MULTILINE {WORD}?((\"{DQCHR}*)|(\'{SQCHR}*)|(\\\n))
|
||||||
">" { RECORD; return GRUB_PARSER_TOKEN_GT; }
|
">" { RECORD; return GRUB_PARSER_TOKEN_GT; }
|
||||||
|
|
||||||
/* Reserved words */
|
/* Reserved words */
|
||||||
"!" { RECORD; return GRUB_PARSER_TOKEN_NOT; }
|
|
||||||
"{" { RECORD; return GRUB_PARSER_TOKEN_LBR; }
|
"{" { RECORD; return GRUB_PARSER_TOKEN_LBR; }
|
||||||
"}" { RECORD; return GRUB_PARSER_TOKEN_RBR; }
|
"}" { RECORD; return GRUB_PARSER_TOKEN_RBR; }
|
||||||
"[[" { RECORD; return GRUB_PARSER_TOKEN_RSQBR2; }
|
"[[" { RECORD; return GRUB_PARSER_TOKEN_RSQBR2; }
|
||||||
|
|
62
tests/grub_script_not.in
Normal file
62
tests/grub_script_not.in
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#! @builddir@/grub-shell-tester
|
||||||
|
#
|
||||||
|
# Copyright (C) 2010 Free Software Foundation, Inc.
|
||||||
|
#
|
||||||
|
# GRUB is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# GRUB is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
true
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
! true
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
false
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
! false
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
#
|
||||||
|
# Negated forms (copied from grub_script_if.in)
|
||||||
|
#
|
||||||
|
|
||||||
|
#basic if, execute
|
||||||
|
if ! true; then echo yes; fi
|
||||||
|
|
||||||
|
#basic if, no execution
|
||||||
|
if ! false; then echo no; fi
|
||||||
|
|
||||||
|
#if else, execute if path
|
||||||
|
if ! true; then echo yes; else echo no; fi
|
||||||
|
|
||||||
|
#if else, execute else path
|
||||||
|
if ! false; then echo no; else echo yes; fi
|
||||||
|
|
||||||
|
#if elif, execute elif
|
||||||
|
if ! false; then echo no; elif ! true; then echo yes; fi
|
||||||
|
|
||||||
|
#if elif else, execute else
|
||||||
|
if ! false; then echo no; elif ! false; then echo no; else echo yes; fi
|
||||||
|
|
||||||
|
#if elif(1) elif(2), execute elif(2)
|
||||||
|
if false; then echo no; elif ! false; then echo no; elif ! true; then echo yes; fi
|
||||||
|
|
||||||
|
#if elif(1) elif(2) else, execute else
|
||||||
|
if false; then echo no; elif false; then echo no; elif ! false; then echo no; else echo yes; fi
|
||||||
|
|
||||||
|
#if {if elif else}, execute elif
|
||||||
|
if true; then if false; then echo no; elif ! true; then echo yes; else echo no; fi; fi
|
||||||
|
|
||||||
|
#if {if elif} else, execute elif. ofcourse no dangling-else problem due to "fi"
|
||||||
|
if true; then if ! false; then echo no; elif true; then echo yes; fi; else echo no; fi
|
Loading…
Reference in a new issue