From eee25941042302c182be4732194c4e2570461490 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Wed, 5 May 2010 16:19:31 +0530 Subject: [PATCH] continue command support --- conf/tests.rmk | 4 ++ script/execute.c | 20 +++++--- script/main.c | 2 + tests/grub_script_continue.in | 86 +++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 tests/grub_script_continue.in diff --git a/conf/tests.rmk b/conf/tests.rmk index 8af4207b7..57cae95c5 100644 --- a/conf/tests.rmk +++ b/conf/tests.rmk @@ -77,6 +77,9 @@ grub_script_functions_SOURCES = tests/grub_script_functions.in check_SCRIPTS += grub_script_break grub_script_break_SOURCES = tests/grub_script_break.in +check_SCRIPTS += grub_script_continue +grub_script_continue_SOURCES = tests/grub_script_continue.in + # List of tests to execute on "make check" # SCRIPTED_TESTS = example_scripted_test # SCRIPTED_TESTS += example_grub_script_test @@ -95,6 +98,7 @@ SCRIPTED_TESTS += grub_script_dollar SCRIPTED_TESTS += grub_script_comments SCRIPTED_TESTS += grub_script_functions SCRIPTED_TESTS += grub_script_break +SCRIPTED_TESTS += grub_script_continue # dependencies between tests and testing-tools $(SCRIPTED_TESTS): grub-shell grub-shell-tester diff --git a/script/execute.c b/script/execute.c index 1f639e00b..88d15495c 100644 --- a/script/execute.c +++ b/script/execute.c @@ -30,13 +30,13 @@ is sizeof (int) * 3, and one extra for a possible -ve sign. */ #define ERRNO_DIGITS_MAX (sizeof (int) * 3 + 1) +static unsigned long is_continue; static unsigned long active_loops; static unsigned long active_breaks; static struct grub_script_scope *scope = 0; grub_err_t -grub_script_break (grub_command_t cmd __attribute__((unused)), - int argc, char *argv[]) +grub_script_break (grub_command_t cmd, int argc, char *argv[]) { char *p = 0; unsigned long count; @@ -50,6 +50,8 @@ grub_script_break (grub_command_t cmd __attribute__((unused)), return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad break"); active_breaks = count; + is_continue = grub_strcmp (cmd->name, "break") ? 1 : 0; + return GRUB_ERR_NONE; } @@ -408,6 +410,9 @@ grub_script_execute_cmdfor (struct grub_script_cmd *cmd) result = 0; for (i = 0; i < argcount; i++) { + if (is_continue && active_breaks == 1) + active_breaks = 0; + if (! active_breaks) { grub_script_env_set (cmdfor->name->str, args[i]); @@ -441,14 +446,17 @@ grub_script_execute_cmdwhile (struct grub_script_cmd *cmd) result = grub_script_execute_cmd (cmdwhile->list); + if (active_breaks == 1 && is_continue) + active_breaks = 0; + if (active_breaks) - { - active_breaks--; - break; - } + break; } while (1); /* XXX Put a check for ^C here */ + if (active_breaks) + active_breaks--; + active_loops--; return result; } diff --git a/script/main.c b/script/main.c index c30df1f2d..401456e1d 100644 --- a/script/main.c +++ b/script/main.c @@ -52,6 +52,8 @@ GRUB_MOD_INIT(sh) grub_parser_register ("grub", &grub_sh_parser); grub_register_command ("break", grub_script_break, N_("[n]"), N_("Exit from loops")); + grub_register_command ("continue", grub_script_break, + N_("[n]"), N_("Continue loops")); } GRUB_MOD_FINI(sh) diff --git a/tests/grub_script_continue.in b/tests/grub_script_continue.in new file mode 100644 index 000000000..4c28ce404 --- /dev/null +++ b/tests/grub_script_continue.in @@ -0,0 +1,86 @@ +#! @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 . + +# continue without any arguments +for i in 1 2 3 4 5 6 7 8 9 10 +do + if test "$i" = 5 + then + continue + fi + echo $i +done + +# continue with one +for i in 1 2 3 4 5 6 7 8 9 10 +do + if test "$i" = 5 + then + continue 1 + fi + echo $i +done + +# continue with loop count +for i in 1 2 3 4 5 +do + for j in a b c d e f + do + if test "$i" = 3 + then + if test "$j" = d + then + continue 2 + fi + echo "$i $j" + fi + done +done + +# continue into middle loop +for i in 1 2 3 4 5 +do + for j in a b c d e f + do + if test "$i" = 3 + then + if test "$j" = d + then + continue 1 + fi + echo "$i $j" + fi + done +done + +# while and until loops +a= +while test "$a" != "aaaaaaa" +do + a="a$a" + for i in 1 2 3 4 + do + b= + until test "$b" = "bbbbb" + do + b="b$b" + if test "$i" = 3; then echo "continue 2"; continue 2; fi + echo "$a $i $b" + done + done +done +