"shift" command support to GRUB script.
* include/grub/script_sh.h (grub_script_shift): New prototype. * script/execute.c (grub_script_shift): New function. * script/main.c (grub_script_init): Register shift command. (grub_script_fini): Unregister shift command. * util/grub-script-check.c (grub_script_cmd_shift): New function. * tests/grub_script_shift.in: New testcase. * conf/tests.rmk: Rules for new testcase.
This commit is contained in:
commit
ab8ba50d75
7 changed files with 152 additions and 2 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2010-08-12 BVK Chaitanya <bvk.groups@gmail.com>
|
||||||
|
|
||||||
|
"shift" command support to GRUB script.
|
||||||
|
|
||||||
|
* include/grub/script_sh.h (grub_script_shift): New prototype.
|
||||||
|
* script/execute.c (grub_script_shift): New function.
|
||||||
|
* script/main.c (grub_script_init): Register shift command.
|
||||||
|
(grub_script_fini): Unregister shift command.
|
||||||
|
* util/grub-script-check.c (grub_script_cmd_shift): New function.
|
||||||
|
|
||||||
|
* tests/grub_script_shift.in: New testcase.
|
||||||
|
* conf/tests.rmk: Rules for new testcase.
|
||||||
|
|
||||||
2010-08-12 BVK Chaitanya <bvk.groups@gmail.com>
|
2010-08-12 BVK Chaitanya <bvk.groups@gmail.com>
|
||||||
|
|
||||||
"continue" command support to GRUB script.
|
"continue" command support to GRUB script.
|
||||||
|
|
|
@ -80,6 +80,9 @@ grub_script_break_SOURCES = tests/grub_script_break.in
|
||||||
check_SCRIPTS += grub_script_continue
|
check_SCRIPTS += grub_script_continue
|
||||||
grub_script_continue_SOURCES = tests/grub_script_continue.in
|
grub_script_continue_SOURCES = tests/grub_script_continue.in
|
||||||
|
|
||||||
|
check_SCRIPTS += grub_script_shift
|
||||||
|
grub_script_shift_SOURCES = tests/grub_script_shift.in
|
||||||
|
|
||||||
# List of tests to execute on "make check"
|
# List of tests to execute on "make check"
|
||||||
# SCRIPTED_TESTS = example_scripted_test
|
# SCRIPTED_TESTS = example_scripted_test
|
||||||
# SCRIPTED_TESTS += example_grub_script_test
|
# SCRIPTED_TESTS += example_grub_script_test
|
||||||
|
@ -99,6 +102,7 @@ SCRIPTED_TESTS += grub_script_comments
|
||||||
SCRIPTED_TESTS += grub_script_functions
|
SCRIPTED_TESTS += grub_script_functions
|
||||||
SCRIPTED_TESTS += grub_script_break
|
SCRIPTED_TESTS += grub_script_break
|
||||||
SCRIPTED_TESTS += grub_script_continue
|
SCRIPTED_TESTS += grub_script_continue
|
||||||
|
SCRIPTED_TESTS += grub_script_shift
|
||||||
|
|
||||||
# dependencies between tests and testing-tools
|
# dependencies between tests and testing-tools
|
||||||
$(SCRIPTED_TESTS): grub-shell grub-shell-tester
|
$(SCRIPTED_TESTS): grub-shell grub-shell-tester
|
||||||
|
|
|
@ -318,6 +318,9 @@ grub_err_t grub_script_execute (struct grub_script *script);
|
||||||
/* Break command for loops. */
|
/* Break command for loops. */
|
||||||
grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);
|
grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);
|
||||||
|
|
||||||
|
/* SHIFT command for GRUB script. */
|
||||||
|
grub_err_t grub_script_shift (grub_command_t cmd, int argc, char *argv[]);
|
||||||
|
|
||||||
/* This variable points to the parsed command. This is used to
|
/* This variable points to the parsed command. This is used to
|
||||||
communicate with the bison code. */
|
communicate with the bison code. */
|
||||||
extern struct grub_script_cmd *grub_script_parsed;
|
extern struct grub_script_cmd *grub_script_parsed;
|
||||||
|
|
|
@ -59,6 +59,37 @@ grub_script_break (grub_command_t cmd, int argc, char *argv[])
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grub_err_t
|
||||||
|
grub_script_shift (grub_command_t cmd __attribute__((unused)),
|
||||||
|
int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *p = 0;
|
||||||
|
unsigned long n = 0;
|
||||||
|
|
||||||
|
if (! scope)
|
||||||
|
return GRUB_ERR_NONE;
|
||||||
|
|
||||||
|
if (argc == 0)
|
||||||
|
n = 1;
|
||||||
|
|
||||||
|
else if (argc > 1)
|
||||||
|
return GRUB_ERR_BAD_ARGUMENT;
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n = grub_strtoul (argv[0], &p, 10);
|
||||||
|
if (*p != '\0')
|
||||||
|
return GRUB_ERR_BAD_ARGUMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > scope->argv.argc)
|
||||||
|
return GRUB_ERR_BAD_ARGUMENT;
|
||||||
|
|
||||||
|
scope->argv.argc -= n;
|
||||||
|
scope->argv.args += n;
|
||||||
|
return GRUB_ERR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
grub_env_special (const char *name)
|
grub_env_special (const char *name)
|
||||||
{
|
{
|
||||||
|
@ -327,7 +358,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
||||||
grub_free (assign);
|
grub_free (assign);
|
||||||
|
|
||||||
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
|
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
|
||||||
grub_env_set ("?", errnobuf);
|
grub_script_env_set ("?", errnobuf);
|
||||||
|
|
||||||
grub_script_argv_free (&argv);
|
grub_script_argv_free (&argv);
|
||||||
grub_print_error ();
|
grub_print_error ();
|
||||||
|
|
|
@ -43,6 +43,7 @@ grub_normal_parse_line (char *line, grub_reader_getline_t getline)
|
||||||
|
|
||||||
static grub_command_t cmd_break;
|
static grub_command_t cmd_break;
|
||||||
static grub_command_t cmd_continue;
|
static grub_command_t cmd_continue;
|
||||||
|
static grub_command_t cmd_shift;
|
||||||
|
|
||||||
void
|
void
|
||||||
grub_script_init (void)
|
grub_script_init (void)
|
||||||
|
@ -50,7 +51,9 @@ grub_script_init (void)
|
||||||
cmd_break = grub_register_command ("break", grub_script_break,
|
cmd_break = grub_register_command ("break", grub_script_break,
|
||||||
N_("[n]"), N_("Exit from loops"));
|
N_("[n]"), N_("Exit from loops"));
|
||||||
cmd_continue = grub_register_command ("continue", grub_script_break,
|
cmd_continue = grub_register_command ("continue", grub_script_break,
|
||||||
N_("[n]"), N_("Coninue loops"));
|
N_("[n]"), N_("Continue loops"));
|
||||||
|
cmd_shift = grub_register_command ("shift", grub_script_shift,
|
||||||
|
N_("[n]"), N_("Shift positional parameters."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -64,4 +67,7 @@ grub_script_fini (void)
|
||||||
grub_unregister_command (cmd_continue);
|
grub_unregister_command (cmd_continue);
|
||||||
cmd_continue = 0;
|
cmd_continue = 0;
|
||||||
|
|
||||||
|
if (cmd_shift)
|
||||||
|
grub_unregister_command (cmd_shift);
|
||||||
|
cmd_shift = 0;
|
||||||
}
|
}
|
||||||
|
|
85
tests/grub_script_shift.in
Normal file
85
tests/grub_script_shift.in
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
#! @builddir@/grub-shell-tester
|
||||||
|
|
||||||
|
# Run GRUB script in a Qemu instance
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
function f1 {
|
||||||
|
echo f1 '$@' $@
|
||||||
|
echo f1 '$*' $*
|
||||||
|
echo f1 $# $1 $2 $3
|
||||||
|
shift
|
||||||
|
echo f1 '$@' $@
|
||||||
|
echo f1 '$*' $*
|
||||||
|
echo f1 $# $1 $2 $3
|
||||||
|
}
|
||||||
|
|
||||||
|
f1
|
||||||
|
f1 a
|
||||||
|
f1 a b
|
||||||
|
f1 a b c
|
||||||
|
f1 a b c d
|
||||||
|
f1 a b c d e
|
||||||
|
|
||||||
|
function f2 {
|
||||||
|
echo f1 '$@' $@
|
||||||
|
echo f1 '$*' $*
|
||||||
|
echo f2 $# $1 $2 $3
|
||||||
|
shift 1
|
||||||
|
echo f1 '$@' $@
|
||||||
|
echo f1 '$*' $*
|
||||||
|
echo f2 $# $1 $2 $3
|
||||||
|
}
|
||||||
|
|
||||||
|
f2
|
||||||
|
f2 a
|
||||||
|
f2 a b
|
||||||
|
f2 a b c
|
||||||
|
f2 a b c d
|
||||||
|
f2 a b c d e
|
||||||
|
|
||||||
|
function f3 {
|
||||||
|
echo f1 '$@' $@
|
||||||
|
echo f1 '$*' $*
|
||||||
|
echo f3 $# $1 $2 $3
|
||||||
|
shift 3
|
||||||
|
echo f1 '$@' $@
|
||||||
|
echo f1 '$*' $*
|
||||||
|
echo f3 $# $1 $2 $3
|
||||||
|
}
|
||||||
|
|
||||||
|
f3
|
||||||
|
f3 a
|
||||||
|
f3 a b
|
||||||
|
f3 a b c
|
||||||
|
f3 a b c d
|
||||||
|
f3 a b c d e
|
||||||
|
|
||||||
|
function f4 {
|
||||||
|
echo f1 '$@' $@
|
||||||
|
echo f1 '$*' $*
|
||||||
|
echo f4 $# $1 $2 $3
|
||||||
|
shift 100
|
||||||
|
echo f1 '$@' $@
|
||||||
|
echo f1 '$*' $*
|
||||||
|
echo f4 $# $1 $2 $3
|
||||||
|
}
|
||||||
|
|
||||||
|
f4
|
||||||
|
f4 a
|
||||||
|
f4 a b
|
||||||
|
f4 a b c
|
||||||
|
f4 a b c d
|
||||||
|
f4 a b c d e
|
|
@ -65,6 +65,14 @@ grub_script_break (grub_command_t cmd __attribute__((unused)),
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grub_err_t
|
||||||
|
grub_script_shift (grub_command_t cmd __attribute__((unused)),
|
||||||
|
int argc __attribute__((unused)),
|
||||||
|
char *argv[] __attribute__((unused)))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
grub_script_execute_argument_to_string (struct grub_script_arg *arg __attribute__ ((unused)))
|
grub_script_execute_argument_to_string (struct grub_script_arg *arg __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue