Received: from list by lists.gnu.org with archive (Exim 4.71) id 1WnMjy-0008N1-Oj for mharc-grub-devel@gnu.org; Thu, 22 May 2014 02:44:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WnMjq-0008MS-80 for grub-devel@gnu.org; Thu, 22 May 2014 02:44:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WnMji-0007xt-Nj for grub-devel@gnu.org; Thu, 22 May 2014 02:44:26 -0400 Received: from mail-ob0-f174.google.com ([209.85.214.174]:64871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WnMji-0007wM-JC for grub-devel@gnu.org; Thu, 22 May 2014 02:44:18 -0400 Received: by mail-ob0-f174.google.com with SMTP id uz6so3364905obc.33 for ; Wed, 21 May 2014 23:44:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-transfer-encoding; bh=hdVL+/E2g6Os3gr85pPVatfOnctOx8BePeu5UmiM9Ok=; b=DzPv8fz6WB8uS5OxZydoLcK1Vqi3UdNLhBFPl4ws53DfiYz3iGjCHpagYxrgjutwbK 6D40ia+KGkJi88ybkyf/g9G65r8xpxgXUJax/blJ5Fwptn5hneFfG3OTGrYWmpwiPZ0a 0TuURiisYMVVmmIe89iDZLFXmn2ILap/W+vS3ncn1kFbXxDJrXkjYYzSIqBAmtokiXWy 2ePZHuyS10z0ZO45CwhzADTSYacYVyDswX9CGsmtZKhFjpHjm3Tb1+MYcrQZe8ox2GOL N6UGbVdkRy4BF6z52TPvwlrPuOOvtAaSp+2oMkoJHWR0Mtq+scupU9HG4DqJFZP75EOc knHw== X-Gm-Message-State: ALoCoQkSmbtu45Etf2Q2k7ssftXtPPVmQnE7oxe0DmoJJwmZ/8h6Hd4LlynG/SX129OhW1JJoYL3 X-Received: by 10.60.131.40 with SMTP id oj8mr56046196oeb.14.1400741056898; Wed, 21 May 2014 23:44:16 -0700 (PDT) Received: from crass-Ideapad-Z570 (cpe-70-117-77-21.austin.res.rr.com. [70.117.77.21]) by mx.google.com with ESMTPSA id f9sm47963029obm.2.2014.05.21.23.44.15 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 21 May 2014 23:44:16 -0700 (PDT) Date: Thu, 22 May 2014 01:44:12 -0500 From: Glenn Washburn To: The development of GNU GRUB Subject: [PATCH 1/2] Allow user-defined functions to override builtins. [take 2] Message-ID: <20140522014412.1919b6b3@crass-Ideapad-Z570> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.20; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.214.174 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 May 2014 06:44:33 -0000 Thanks for suggestions from Michel and Ben, I've added a pseudo-command called "builtin" which will allow access to builtins that have been overridden by functions. Any help in getting this functionality committed would be much appreciated. --- grub-core/script/execute.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index afd5513..857f8c6 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -941,14 +941,15 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) args = argv.args + 2; cmdname = argv.args[1]; } - grubcmd = grub_command_find (cmdname); - if (! grubcmd) + /* Allow user functions to override built in commands. */ + func = grub_script_function_find (cmdname); + if (! func) { grub_errno = GRUB_ERR_NONE; - /* It's not a GRUB command, try all functions. */ - func = grub_script_function_find (cmdname); - if (! func) + /* It's not a function, check if GRUB command. */ + grubcmd = grub_command_find (cmdname); + if (! grubcmd) { /* As a last resort, try if it is an assignment. */ char *assign = grub_strdup (cmdname); @@ -977,7 +978,9 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) } /* Execute the GRUB command or function. */ - if (grubcmd) + if (func) + ret = grub_script_function_call (func, argc, args); + else { if (grub_extractor_level && !(grubcmd->flags & GRUB_COMMAND_FLAG_EXTRACTOR)) @@ -990,8 +993,6 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) else ret = (grubcmd->func) (grubcmd, argc, args); } - else - ret = grub_script_function_call (func, argc, args); if (invert) { -- 1.8.3.2