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
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
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;
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;
}
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]);
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;
}
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)
--- /dev/null
+#! @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/>.
+
+# 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
+