From: Marco Gerards <metgerards@student.han.nl>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: Scripting support
Date: Sat, 22 Oct 2005 18:33:17 +0200 [thread overview]
Message-ID: <878xwltstu.fsf@student.han.nl> (raw)
In-Reply-To: <87d5lxtuyt.fsf@student.han.nl> (Marco Gerards's message of "Sat, 22 Oct 2005 17:47:06 +0200")
Marco Gerards <metgerards@student.han.nl> writes:
> I think we first have to determine:
>
> 1) Which commands should be supported.
> 2) The smallest subset of commands that should be generated.
>
> Did you have a look at how bash does this? Perhaps it even has a
> completely different approach...
I just had a look at bash. It was a quick look, so I might be
mistaken, but I think it works like this:
First bash parses the script (in parse.y). It uses a make_*_command
to generate stuff like if, for, case, etc (make_*command is in
make_cmd.c). After that it executes the commands (in execute_cmd.c).
We could parse this script:
for i in 1 2 3
do
echo foo
echo bar
echo $i
done
echo done!
into something like:
struct command
{
command_type_t type;
};
struct for_command
{
struct command command;
list_t list;
struct cmdlist_command *cmds;
}
/* A simple GRUB command. */
struct simple_command
{
struct command command;
char *command;
};
/* Lines of commands. */
struct cmdlist_command
{
struct command command;
struct command **cmdlist;
};
struct cmdlist_command script
{
grub_cmdtype_cmdlist,
{
{
cmd_type_for,
{1, 2, 3},
{
grub_cmdtype_cmdlist,
{
{ grub_cmdtype_simple, "echo foo" },
{ grub_cmdtype_simple, "echo bar" },
{ grub_cmdtype_simple, "echo $i" }
}
}
},
{
grub_cmdtype_simple, " echo done!"
}
}
This is of course not the code what is generated. And when
implementing it, you would use pointers. But logically it is nested
that way. After that you can execute it like this:
execute_cmd (struct command *cmd)
{
switch (cmd->type)
{
case grub_cmdtype_if:
{
struct if_command *cmd_if = (struct if_command *) cmd;
execute_if_cmd (cmd_if);
}
case grub_cmdtype_for:
...
}
}
This is quite ugly code, but I hope you get the idea. :)
Vladimir, if you want I could implement the framework like I have in
mind. It is not that much work. The hard part is "filling in" the
framework so you get scripting support. Please tell me what you
think, or we could talk about it on IRC.
Thanks,
Marco
next prev parent reply other threads:[~2005-10-22 16:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-22 13:59 Scripting support Marco Gerards
2005-10-22 14:46 ` Vladimir Serbinenko
2005-10-22 15:08 ` Marco Gerards
2005-10-22 15:37 ` Vladimir Serbinenko
2005-10-22 15:47 ` Marco Gerards
2005-10-22 16:03 ` Vladimir Serbinenko
2005-10-22 16:42 ` Marco Gerards
2005-10-22 16:33 ` Marco Gerards [this message]
2005-10-28 3:04 ` Yoshinori K. Okuji
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878xwltstu.fsf@student.han.nl \
--to=metgerards@student.han.nl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.