]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
continue command support
authorBVK Chaitanya <bvk.groups@gmail.com>
Wed, 5 May 2010 10:49:31 +0000 (16:19 +0530)
committerBVK Chaitanya <bvk.groups@gmail.com>
Wed, 5 May 2010 10:49:31 +0000 (16:19 +0530)
conf/tests.rmk
script/execute.c
script/main.c
tests/grub_script_continue.in [new file with mode: 0644]

index 8af4207b77b8c1048528ba48cda66c59774c2a50..57cae95c55b77004cea663de37c41a28412e7d88 100644 (file)
@@ -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
index 1f639e00ba0d0a58a30b2a880c5f0aba2f3ac84d..88d15495cd676a9251affb67c1996d97ed6b267e 100644 (file)
    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;
 }
index c30df1f2ddf500d4067d7302bd77f1ce85d76233..401456e1dc5b6eecea3a778d32b2bde0a2b59f46 100644 (file)
@@ -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 (file)
index 0000000..4c28ce4
--- /dev/null
@@ -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 <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
+