]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/script/execute.c (grub_script_execute_sourcecode): Split
authorAndrey Borzenkov <arvidjaar@gmail.com>
Fri, 7 Jun 2013 16:36:42 +0000 (18:36 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 7 Jun 2013 16:36:42 +0000 (18:36 +0200)
off new function grub_script_execute_new_scope. Change callers to use
either of them as appropriate.
* grub-core/commands/eval.c: New command eval.
* docs/grub.texi (Commands): Document it.

ChangeLog
docs/grub.texi
grub-core/Makefile.core.def
grub-core/normal/menu.c
grub-core/normal/menu_entry.c
grub-core/script/execute.c
include/grub/script_sh.h

index 4148be1864e03fa0626bcf859b7df94b6e13cbaf..4d8f34370b8bd03fbc95544aea9f6ff98420f15f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-06-07  Andrey Borzenkov <arvidjaar@gmail.com>
+
+       * grub-core/script/execute.c (grub_script_execute_sourcecode): Split
+       off new function grub_script_execute_new_scope. Change callers to use
+       either of them as appropriate.
+       * grub-core/commands/eval.c: New command eval.
+       * docs/grub.texi (Commands): Document it.
+
 2013-06-07  Andrey Borzenkov <arvidjaar@gmail.com>
 
        * grub-core/kern/corecmd.c (grub_core_cmd_set): Use grub_env_get
index 75a5ea4ce109b6c30f702c316157f9bc86b804e5..9dcfa2d40c5b988ee97afc277210b53d52df256a 100644 (file)
@@ -3435,6 +3435,7 @@ you forget a command, you can run the command @command{help}
 * date::                        Display or set current date and time
 * drivemap::                    Map a drive to another
 * echo::                        Display a line of text
+* eval::                        Evaluate agruments as GRUB commands
 * export::                      Export an environment variable
 * false::                       Do nothing, unsuccessfully
 * gettext::                     Translate a string
@@ -3812,6 +3813,15 @@ character will print that character.
 @end deffn
 
 
+@node eval
+@subsection eval
+
+@deffn Command eval string ...
+Concatenate arguments together using single space as separator and evaluate
+result as sequence of GRUB commands.
+@end deffn
+
+
 @node export
 @subsection export
 
index 6aeb79b596932b27b98bf03ffa72e5835a2159d6..ed4b727245b02141d96d79267f7d9dbf7434a1b6 100644 (file)
@@ -703,6 +703,11 @@ module = {
   common = commands/echo.c;
 };
 
+module = {
+  name = eval;
+  common = commands/eval.c;
+};
+
 module = {
   name = extcmd;
   common = commands/extcmd.c;
index fba19db992152847eb3c91b87e4952e0f0fe7847..9b88290cf8946648f6786c6d386a18fce1926c4a 100644 (file)
@@ -245,7 +245,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot)
   else
     grub_env_unset ("default");
 
-  grub_script_execute_sourcecode (entry->sourcecode, entry->argc, entry->args);
+  grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args);
 
   if (errs_before != grub_err_printed_errors)
     grub_wait_after_message ();
index a26a50616a49dc30192a6e1dba728d0b76e88e43..6aa33071c6172b75d2fc8d14a163a58e09c6621b 100644 (file)
@@ -1181,7 +1181,7 @@ run (struct screen *screen)
       }
     script[size] = '\0';
   }
-  grub_script_execute_sourcecode (script, 0, dummy);
+  grub_script_execute_new_scope (script, 0, dummy);
   grub_free (script);
 
   if (errs_before != grub_err_printed_errors)
index 9babbeee20bd0a1814aac8ad2990ea6d77365064..afd551320f70a8e064882e51a32388f7232d69c2 100644 (file)
@@ -856,19 +856,10 @@ grub_script_execute_sourcecode_getline (char **line,
 
 /* Execute a source script.  */
 grub_err_t
-grub_script_execute_sourcecode (const char *source, int argc, char **args)
+grub_script_execute_sourcecode (const char *source)
 {
   grub_err_t ret = 0;
   struct grub_script *parsed_script;
-  struct grub_script_scope new_scope;
-  struct grub_script_scope *old_scope;
-
-  new_scope.argv.argc = argc;
-  new_scope.argv.args = args;
-  new_scope.flags = 0;
-
-  old_scope = scope;
-  scope = &new_scope;
 
   while (source)
     {
@@ -880,13 +871,35 @@ grub_script_execute_sourcecode (const char *source, int argc, char **args)
       if (! parsed_script)
        {
          ret = grub_errno;
+         grub_free (line);
          break;
        }
 
       ret = grub_script_execute (parsed_script);
+      grub_script_free (parsed_script);
       grub_free (line);
     }
 
+  return ret;
+}
+
+/* Execute a source script in new scope.  */
+grub_err_t
+grub_script_execute_new_scope (const char *source, int argc, char **args)
+{
+  grub_err_t ret = 0;
+  struct grub_script_scope new_scope;
+  struct grub_script_scope *old_scope;
+
+  new_scope.argv.argc = argc;
+  new_scope.argv.args = args;
+  new_scope.flags = 0;
+
+  old_scope = scope;
+  scope = &new_scope;
+
+  ret = grub_script_execute_sourcecode (source);
+
   scope = old_scope;
   return ret;
 }
index 78602e4ad9df4ac46a4588354284ee2501dd7726..57bdd4d3ce4d66346562c38d1656c14f870d48bd 100644 (file)
@@ -329,7 +329,8 @@ grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
 
 /* Execute any GRUB pre-parsed command or script.  */
 grub_err_t grub_script_execute (struct grub_script *script);
-grub_err_t grub_script_execute_sourcecode (const char *source, int argc, char **args);
+grub_err_t grub_script_execute_sourcecode (const char *source);
+grub_err_t grub_script_execute_new_scope (const char *source, int argc, char **args);
 
 /* Break command for loops.  */
 grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);