[prev in list] [next in list] [prev in thread] [next in thread] 

List:       grub-devel
Subject:    Re: [PATCH 2/2] Allow user-defined functions to override builtins. [take 2]
From:       Michel Hermier <michel.hermier () gmail ! com>
Date:       2014-05-22 13:59:58
Message-ID: CAAZ5spCL2e73g1psb=Cf23ysyaOFBKBT2JPP=n4-gDmkfChh3g () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I don't know the code much, but i think your change looks like a hack.
I fell missing an internal command registration in main.c, a small function
to handle the command, and an extra parameter in
grub_script_execute_cmdline to allow/exclude user defined commands so that
it can be called from builtin, and a change in the documentation to
advertise about builtin command.
Cheers
Le 22 mai 2014 08:46, "Glenn Washburn" <development@efficientek.com> a
écrit :

> This is implements the builtin pseudo-command.
>
> ---
>  grub-core/script/execute.c | 25 +++++++++++++++++++++----
>  1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
> index 857f8c6..2dbc17f 100644
> --- a/grub-core/script/execute.c
> +++ b/grub-core/script/execute.c
> @@ -917,6 +917,7 @@ grub_script_execute_cmdline (struct grub_script_cmd
> *cmd) int argc;
>    char **args;
>    int invert;
> +  int builtin;
>    struct grub_script_argv argv = { 0, 0, 0 };
>
>    /* Lookup the command.  */
> @@ -924,6 +925,7 @@ grub_script_execute_cmdline (struct grub_script_cmd
> *cmd) return grub_errno;
>
>    invert = 0;
> +  builtin = 0;
>    argc = argv.argc - 1;
>    args = argv.args + 1;
>    cmdname = argv.args[0];
> @@ -937,12 +939,27 @@ grub_script_execute_cmdline (struct
> grub_script_cmd *cmd) }
>
>        invert = 1;
> -      argc = argv.argc - 2;
> -      args = argv.args + 2;
> -      cmdname = argv.args[1];
> +      cmdname = args[0];
> +      argc--;
> +      args++;
> +    }
> +  if (grub_strcmp (cmdname, "builtin") == 0)
> +    {
> +      if (argv.argc < 2 || ! argv.args[1])
> +       {
> +         grub_script_argv_free (&argv);
> +         return grub_error (GRUB_ERR_BAD_ARGUMENT,
> +                            N_("no command is specified"));
> +       }
> +
> +      builtin = 1;
> +      cmdname = args[0];
> +      argc--;
> +      args++;
>      }
>    /* Allow user functions to override built in commands. */
> -  func = grub_script_function_find (cmdname);
> +  if (! builtin)
> +    func = grub_script_function_find (cmdname);
>    if (! func)
>      {
>        grub_errno = GRUB_ERR_NONE;
> --
> 1.8.3.2
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[Attachment #5 (text/html)]

<p dir="ltr">I don&#39;t know the code much, but i think your change looks like a \
hack.<br> I fell missing an internal command registration in main.c, a small function \
to handle the command, and an extra parameter in grub_script_execute_cmdline to \
allow/exclude user defined commands so that it can be called from builtin, and a \
change in the documentation to advertise about builtin command.<br>

Cheers</p>
<div class="gmail_quote">Le 22 mai 2014 08:46, &quot;Glenn Washburn&quot; &lt;<a \
href="mailto:development@efficientek.com">development@efficientek.com</a>&gt; a \
écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"> This is implements the builtin \
pseudo-command.<br> <br>
---<br>
  grub-core/script/execute.c | 25 +++++++++++++++++++++----<br>
  1 file changed, 21 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c<br>
index 857f8c6..2dbc17f 100644<br>
--- a/grub-core/script/execute.c<br>
+++ b/grub-core/script/execute.c<br>
@@ -917,6 +917,7 @@ grub_script_execute_cmdline (struct grub_script_cmd<br>
*cmd) int argc;<br>
     char **args;<br>
     int invert;<br>
+   int builtin;<br>
     struct grub_script_argv argv = { 0, 0, 0 };<br>
<br>
     /* Lookup the command.   */<br>
@@ -924,6 +925,7 @@ grub_script_execute_cmdline (struct grub_script_cmd<br>
*cmd) return grub_errno;<br>
<br>
     invert = 0;<br>
+   builtin = 0;<br>
     argc = argv.argc - 1;<br>
     args = argv.args + 1;<br>
     cmdname = argv.args[0];<br>
@@ -937,12 +939,27 @@ grub_script_execute_cmdline (struct<br>
grub_script_cmd *cmd) }<br>
<br>
           invert = 1;<br>
-         argc = argv.argc - 2;<br>
-         args = argv.args + 2;<br>
-         cmdname = argv.args[1];<br>
+         cmdname = args[0];<br>
+         argc--;<br>
+         args++;<br>
+      }<br>
+   if (grub_strcmp (cmdname, &quot;builtin&quot;) == 0)<br>
+      {<br>
+         if (argv.argc &lt; 2 || ! argv.args[1])<br>
+          {<br>
+             grub_script_argv_free (&amp;argv);<br>
+             return grub_error (GRUB_ERR_BAD_ARGUMENT,<br>
+                                          N_(&quot;no command is \
specified&quot;));<br> +          }<br>
+<br>
+         builtin = 1;<br>
+         cmdname = args[0];<br>
+         argc--;<br>
+         args++;<br>
        }<br>
     /* Allow user functions to override built in commands. */<br>
-   func = grub_script_function_find (cmdname);<br>
+   if (! builtin)<br>
+      func = grub_script_function_find (cmdname);<br>
     if (! func)<br>
        {<br>
           grub_errno = GRUB_ERR_NONE;<br>
--<br>
1.8.3.2<br>
<br>
<br>
_______________________________________________<br>
Grub-devel mailing list<br>
<a href="mailto:Grub-devel@gnu.org">Grub-devel@gnu.org</a><br>
<a href="https://lists.gnu.org/mailman/listinfo/grub-devel" \
target="_blank">https://lists.gnu.org/mailman/listinfo/grub-devel</a><br> \
</blockquote></div>



_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic