]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
merge with mainline
authorBVK Chaitanya <bvk@dbook>
Sat, 4 Sep 2010 15:14:44 +0000 (20:44 +0530)
committerBVK Chaitanya <bvk@dbook>
Sat, 4 Sep 2010 15:14:44 +0000 (20:44 +0530)
1  2 
Makefile.util.def
grub-core/script/execute.c
grub-core/script/main.c
include/grub/script_sh.h

index a0ab3d3d94d438343d95bc97305e8cb09cebe463,45c2f9761c37855b47a2f3c2dcc8dbf06e00cbef..79541b5edf228f9606be8d94c90afd0dc6aa9a3a
@@@ -507,12 -507,12 +507,18 @@@ script = 
    common = tests/grub_script_blockarg.in;
  };
  
+ script = {
+   testcase;
+   name = grub_script_setparams;
+   common = tests/grub_script_setparams.in;
+ };
 +script = {
 +  testcase;
 +  name = grub_script_return;
 +  common = tests/grub_script_return.in;
 +};
 +
  program = {
    testcase;
    name = example_unit_test;
index e71c5345a48bc6bdf30835305600baae40328346,8e3c97434756f2fcea56a9c2772ee9862f2b996c..88057d44e77a9bdca24d1bbcb9f5f57b40d72c0b
  static unsigned long is_continue;
  static unsigned long active_loops;
  static unsigned long active_breaks;
 +static unsigned long function_return;
  
+ #define GRUB_SCRIPT_SCOPE_MALLOCED      1
+ #define GRUB_SCRIPT_SCOPE_ARGS_MALLOCED 2
  /* Scope for grub script functions.  */
  struct grub_script_scope
  {
@@@ -92,30 -114,35 +115,59 @@@ grub_script_shift (grub_command_t cmd _
    return GRUB_ERR_NONE;
  }
  
+ grub_err_t
+ grub_script_setparams (grub_command_t cmd __attribute__((unused)),
+                      int argc, char **args)
+ {
+   struct grub_script_scope *new_scope;
+   struct grub_script_argv argv = { 0, 0, 0 };
+   if (! scope)
+     return GRUB_ERR_INVALID_COMMAND;
+   new_scope = grub_malloc (sizeof (*new_scope));
+   if (! new_scope)
+     return grub_errno;
+   if (grub_script_argv_make (&argv, argc, args))
+     {
+       grub_free (new_scope);
+       return grub_errno;
+     }
+   new_scope->shifts = 0;
+   new_scope->argv = argv;
+   new_scope->flags = GRUB_SCRIPT_SCOPE_MALLOCED |
+     GRUB_SCRIPT_SCOPE_ARGS_MALLOCED;
+   replace_scope (new_scope);
+   return GRUB_ERR_NONE;
+ }
 +grub_err_t
 +grub_script_return (grub_command_t cmd __attribute__((unused)),
 +                  int argc, char *argv[])
 +{
 +  char *p;
 +  unsigned long n;
 +
 +  if (! scope || argc > 1)
 +    return grub_error (GRUB_ERR_BAD_ARGUMENT, "not in function scope");
 +
 +  if (argc == 0)
 +    {
 +      function_return = 1;
 +      return grub_strtoul (grub_env_get ("?"), NULL, 10);
 +    }
 +
 +  n = grub_strtoul (argv[0], &p, 10);
 +  if (*p != '\0')
 +    return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad argument");
 +
 +  function_return = 1;
 +  return n ? grub_error (GRUB_ERR_TEST_FAILURE, "false") : GRUB_ERR_NONE;
 +}
 +
  static int
  grub_env_special (const char *name)
  {
@@@ -344,9 -370,8 +395,9 @@@ grub_script_function_call (grub_script_
  
    ret = grub_script_execute (func->func);
  
 +  function_return = 0;
    active_loops = loops;
-   scope = old_scope;
+   replace_scope (old_scope); /* free any scopes by setparams */
    return ret;
  }
  
index 6daace287dac9c2cb0efa6d79ac6a5185bd93e1d,4984848f0d60c95b1ddb401ac770de3a0a1365a9..482bb3fef02560052757eb5c9f85554abe2177e7
@@@ -44,7 -44,7 +44,8 @@@ grub_normal_parse_line (char *line, gru
  static grub_command_t cmd_break;
  static grub_command_t cmd_continue;
  static grub_command_t cmd_shift;
+ static grub_command_t cmd_setparams;
 +static grub_command_t cmd_return;
  
  void
  grub_script_init (void)
                                        N_("[n]"), N_("Continue loops"));
    cmd_shift = grub_register_command ("shift", grub_script_shift,
                                     N_("[n]"), N_("Shift positional parameters."));
+   cmd_setparams = grub_register_command ("setparams", grub_script_setparams,
+                                        N_("[VALUE]..."),
+                                        N_("Set positional parameters."));
 +  cmd_return = grub_register_command ("return", grub_script_return,
 +                                    N_("[n]"), N_("Return from a function."));
  }
  
  void
@@@ -74,7 -75,7 +78,11 @@@ grub_script_fini (void
      grub_unregister_command (cmd_shift);
    cmd_shift = 0;
  
+   if (cmd_setparams)
+     grub_unregister_command (cmd_setparams);
+   cmd_setparams = 0;
++
 +  if (cmd_return)
 +    grub_unregister_command (cmd_return);
 +  cmd_return = 0;
  }
index 172856e8a8114943c655603f2c2ad084a7dd2e72,b371e49f18080d5070897d88054574b10ed9e884..848e55411a364f9d5000487a2d49b1fff2b35cfa
@@@ -342,9 -343,9 +343,12 @@@ grub_err_t grub_script_break (grub_comm
  /* SHIFT command for GRUB script.  */
  grub_err_t grub_script_shift (grub_command_t cmd, int argc, char *argv[]);
  
+ /* SETPARAMS command for GRUB script functions.  */
+ grub_err_t grub_script_setparams (grub_command_t cmd, int argc, char *argv[]);
 +/* RETURN command for functions.  */
 +grub_err_t grub_script_return (grub_command_t cmd, int argc, char *argv[]);
 +
  /* This variable points to the parsed command.  This is used to
     communicate with the bison code.  */
  extern struct grub_script_cmd *grub_script_parsed;