not command (!) support
This commit is contained in:
parent
35ee15e09a
commit
1bce65c7b1
4 changed files with 93 additions and 5 deletions
|
@ -531,6 +531,12 @@ script = {
|
|||
common = tests/grub_script_expansion.in;
|
||||
};
|
||||
|
||||
script = {
|
||||
testcase;
|
||||
name = grub_script_not;
|
||||
common = tests/grub_script_not.in;
|
||||
};
|
||||
|
||||
program = {
|
||||
testcase;
|
||||
name = example_unit_test;
|
||||
|
|
|
@ -547,13 +547,32 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|||
grub_script_function_t func = 0;
|
||||
char errnobuf[18];
|
||||
char *cmdname;
|
||||
int argc;
|
||||
char **args;
|
||||
int invert;
|
||||
struct grub_script_argv argv = { 0, 0, 0 };
|
||||
|
||||
/* Lookup the command. */
|
||||
if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0])
|
||||
return grub_errno;
|
||||
|
||||
invert = 0;
|
||||
argc = argv.argc - 1;
|
||||
args = argv.args + 1;
|
||||
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);
|
||||
if (! grubcmd)
|
||||
{
|
||||
|
@ -594,13 +613,15 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|||
{
|
||||
if ((grubcmd->flags & GRUB_COMMAND_FLAG_BLOCKS) &&
|
||||
(grubcmd->flags & GRUB_COMMAND_FLAG_EXTCMD))
|
||||
ret = grub_extcmd_dispatcher (grubcmd, argv.argc - 1, argv.args + 1,
|
||||
argv.script);
|
||||
ret = grub_extcmd_dispatcher (grubcmd, argc, args, argv.script);
|
||||
else
|
||||
ret = (grubcmd->func) (grubcmd, argv.argc - 1, argv.args + 1);
|
||||
ret = (grubcmd->func) (grubcmd, argc, args);
|
||||
}
|
||||
else
|
||||
ret = grub_script_function_call (func, argv.argc - 1, argv.args + 1);
|
||||
ret = grub_script_function_call (func, argc, args);
|
||||
|
||||
if (invert)
|
||||
ret = ! ret;
|
||||
|
||||
/* Free arguments. */
|
||||
grub_script_argv_free (&argv);
|
||||
|
|
|
@ -155,7 +155,6 @@ MULTILINE {WORD}?((\"{DQCHR}*)|(\'{SQCHR}*)|(\\\n))
|
|||
">" { RECORD; return GRUB_PARSER_TOKEN_GT; }
|
||||
|
||||
/* Reserved words */
|
||||
"!" { RECORD; return GRUB_PARSER_TOKEN_NOT; }
|
||||
"{" { RECORD; return GRUB_PARSER_TOKEN_LBR; }
|
||||
"}" { RECORD; return GRUB_PARSER_TOKEN_RBR; }
|
||||
"[[" { 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