From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1ETMJ9-0001BJ-DB for mharc-grub-devel@gnu.org; Sat, 22 Oct 2005 12:33:23 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ETMJ7-000199-4K for grub-devel@gnu.org; Sat, 22 Oct 2005 12:33:21 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ETMJ5-00017P-BP for grub-devel@gnu.org; Sat, 22 Oct 2005 12:33:20 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ETMJ5-00017K-5e for grub-devel@gnu.org; Sat, 22 Oct 2005 12:33:19 -0400 Received: from [145.74.66.11] (helo=mail-cn.han.nl) by monty-python.gnu.org with esmtp (Exim 4.34) id 1ETMJ4-0004kK-Vi for grub-devel@gnu.org; Sat, 22 Oct 2005 12:33:19 -0400 Received: from vscan-cn.han.nl (venus.han.nl [145.74.65.6]) by mail-cn.han.nl (Postfix) with ESMTP id 13BBC8569 for ; Sat, 22 Oct 2005 18:33:18 +0200 (CEST) Received: from mail-cn.han.nl ([145.74.66.11]) by vscan-cn.han.nl (venus.han.nl [145.74.65.6]) (amavisd-new, port 10024) with ESMTP id 02521-01; Sat, 22 Oct 2005 18:33:17 +0200 (CEST) Received: from mail1.han.nl (mail1.han.nl [145.74.103.11]) by mail-cn.han.nl (Postfix) with ESMTP id 4DB8282AA; Sat, 22 Oct 2005 18:33:17 +0200 (CEST) Received: from localhost.localdomain (mgerards.xs4all.nl [82.92.27.129]) by mail1.han.nl (Postfix) with ESMTP id 05392C045; Sat, 22 Oct 2005 18:33:17 +0200 (CEST) Mail-Copies-To: metgerards@student.han.nl To: The development of GRUB 2 References: <87pspxtzyu.fsf@student.han.nl> <435A50BE.5030801@gmail.com> <87hdb9twr9.fsf@student.han.nl> <435A5CAF.40103@gmail.com> <87d5lxtuyt.fsf@student.han.nl> From: Marco Gerards Date: Sat, 22 Oct 2005 18:33:17 +0200 In-Reply-To: <87d5lxtuyt.fsf@student.han.nl> (Marco Gerards's message of "Sat, 22 Oct 2005 17:47:06 +0200") Message-ID: <878xwltstu.fsf@student.han.nl> User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new (2.2.0) at vscan-cn.han.nl Cc: Subject: Re: Scripting support X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Oct 2005 16:33:21 -0000 Marco Gerards 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