From grub-devel Thu May 22 13:59:58 2014 From: Michel Hermier Date: Thu, 22 May 2014 13:59:58 +0000 To: grub-devel Subject: Re: [PATCH 2/2] Allow user-defined functions to override builtins. [take 2] Message-Id: X-MARC-Message: https://marc.info/?l=grub-devel&m=140076721916163 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============4219986974574734285==" --===============4219986974574734285== Content-Type: multipart/alternative; boundary=001a11c2fd6c4458b104f9fd8716 --001a11c2fd6c4458b104f9fd8716 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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" a =C3=A9crit : > 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 =3D { 0, 0, 0 }; > > /* Lookup the command. */ > @@ -924,6 +925,7 @@ grub_script_execute_cmdline (struct grub_script_cmd > *cmd) return grub_errno; > > invert =3D 0; > + builtin =3D 0; > argc =3D argv.argc - 1; > args =3D argv.args + 1; > cmdname =3D argv.args[0]; > @@ -937,12 +939,27 @@ grub_script_execute_cmdline (struct > grub_script_cmd *cmd) } > > invert =3D 1; > - argc =3D argv.argc - 2; > - args =3D argv.args + 2; > - cmdname =3D argv.args[1]; > + cmdname =3D args[0]; > + argc--; > + args++; > + } > + if (grub_strcmp (cmdname, "builtin") =3D=3D 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 =3D 1; > + cmdname =3D args[0]; > + argc--; > + args++; > } > /* Allow user functions to override built in commands. */ > - func =3D grub_script_function_find (cmdname); > + if (! builtin) > + func =3D grub_script_function_find (cmdname); > if (! func) > { > grub_errno =3D GRUB_ERR_NONE; > -- > 1.8.3.2 > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > --001a11c2fd6c4458b104f9fd8716 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

I don't know the code much, but i think your change look= s 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_cmdli= ne to allow/exclude user defined commands so that it can be called from bui= ltin, and a change in the documentation to advertise about builtin command.=
Cheers

Le 22 mai 2014 08:46, "Glenn Washburn"= <development@efficientek= .com> a =C3=A9crit :
This is implements the builtin pseudo-command.

---
=C2=A0grub-core/script/execute.c | 25 +++++++++++++++++++++----
=C2=A01 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;
=C2=A0 =C2=A0char **args;
=C2=A0 =C2=A0int invert;
+ =C2=A0int builtin;
=C2=A0 =C2=A0struct grub_script_argv argv =3D { 0, 0, 0 };

=C2=A0 =C2=A0/* Lookup the command. =C2=A0*/
@@ -924,6 +925,7 @@ grub_script_execute_cmdline (struct grub_script_cmd
*cmd) return grub_errno;

=C2=A0 =C2=A0invert =3D 0;
+ =C2=A0builtin =3D 0;
=C2=A0 =C2=A0argc =3D argv.argc - 1;
=C2=A0 =C2=A0args =3D argv.args + 1;
=C2=A0 =C2=A0cmdname =3D argv.args[0];
@@ -937,12 +939,27 @@ grub_script_execute_cmdline (struct
grub_script_cmd *cmd) }

=C2=A0 =C2=A0 =C2=A0 =C2=A0invert =3D 1;
- =C2=A0 =C2=A0 =C2=A0argc =3D argv.argc - 2;
- =C2=A0 =C2=A0 =C2=A0args =3D argv.args + 2;
- =C2=A0 =C2=A0 =C2=A0cmdname =3D argv.args[1];
+ =C2=A0 =C2=A0 =C2=A0cmdname =3D args[0];
+ =C2=A0 =C2=A0 =C2=A0argc--;
+ =C2=A0 =C2=A0 =C2=A0args++;
+ =C2=A0 =C2=A0}
+ =C2=A0if (grub_strcmp (cmdname, "builtin") =3D=3D 0)
+ =C2=A0 =C2=A0{
+ =C2=A0 =C2=A0 =C2=A0if (argv.argc < 2 || ! argv.args[1])
+ =C2=A0 =C2=A0 =C2=A0 {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 grub_script_argv_free (&argv);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 return grub_error (GRUB_ERR_BAD_ARGUMENT,
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0N_("no command is specified"));
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0builtin =3D 1;
+ =C2=A0 =C2=A0 =C2=A0cmdname =3D args[0];
+ =C2=A0 =C2=A0 =C2=A0argc--;
+ =C2=A0 =C2=A0 =C2=A0args++;
=C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0/* Allow user functions to override built in commands. */
- =C2=A0func =3D grub_script_function_find (cmdname);
+ =C2=A0if (! builtin)
+ =C2=A0 =C2=A0func =3D grub_script_function_find (cmdname);
=C2=A0 =C2=A0if (! func)
=C2=A0 =C2=A0 =C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0grub_errno =3D GRUB_ERR_NONE;
--
1.8.3.2


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
--001a11c2fd6c4458b104f9fd8716-- --===============4219986974574734285== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel --===============4219986974574734285==--