grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting support


From: Marco Gerards
Subject: Re: Scripting support
Date: Sat, 22 Oct 2005 18:33:17 +0200
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Marco Gerards <address@hidden> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]