Hi,

Attached patch adds "not" command (!) support to GRUB script.  Adding
this feature to GRUB script core, interestingly, *reduced* normal.mod
size by a few bytes :)  This is because I removed special handling of
"!" character from flex's lexical analyzer.  It seems we can save
2-3KB further by removing unnecessary regex rules ino
grub-core/script/yylex.l, but we can revisit it later when normal.mod
size really becomes critical.



bvk.chaitanya
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: b...@dbook-20100905092728-mve59u63rj7xl9xm
# target_branch: ../mainline/
# testament_sha1: 0603fbd94ec9aec98a975dc1dde3aa3ce4aa4b4d
# timestamp: 2010-09-05 14:57:40 +0530
# base_revision_id: b...@dbook-20100904171534-lhkj52sppwdqhrwe
# 
# Begin patch
=== modified file 'Makefile.util.def'
--- Makefile.util.def	2010-09-04 17:04:32 +0000
+++ Makefile.util.def	2010-09-05 09:27:28 +0000
@@ -531,6 +531,12 @@
   common = tests/grub_script_expansion.in;
 };
 
+script = {
+  testcase;
+  name = grub_script_not;
+  common = tests/grub_script_not.in;
+};
+
 program = {
   testcase;
   name = example_unit_test;

=== modified file 'grub-core/script/execute.c'
--- grub-core/script/execute.c	2010-09-04 17:04:32 +0000
+++ grub-core/script/execute.c	2010-09-05 09:27:28 +0000
@@ -547,13 +547,32 @@
   grub_script_function_t func = 0;
   char errnobuf[18];
   char *cmdname;
+  int argc;
+  char **args;
+  int invert;
   struct grub_script_argv argv = { 0, 0, 0 };
 
   /* Lookup the command.  */
   if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0])
     return grub_errno;
 
+  invert = 0;
+  argc = argv.argc - 1;
+  args = argv.args + 1;
   cmdname = argv.args[0];
+  if (grub_strcmp (cmdname, "!") == 0)
+    {
+      if (argv.argc < 2 || ! argv.args[1])
+	{
+	  grub_script_argv_free (&argv);
+	  return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing arguments");
+	}
+
+      invert = 1;
+      argc = argv.argc - 2;
+      args = argv.args + 2;
+      cmdname = argv.args[1];
+    }
   grubcmd = grub_command_find (cmdname);
   if (! grubcmd)
     {
@@ -594,13 +613,15 @@
     {
       if ((grubcmd->flags & GRUB_COMMAND_FLAG_BLOCKS) &&
 	  (grubcmd->flags & GRUB_COMMAND_FLAG_EXTCMD))
-	ret = grub_extcmd_dispatcher (grubcmd, argv.argc - 1, argv.args + 1,
-				      argv.script);
+	ret = grub_extcmd_dispatcher (grubcmd, argc, args, argv.script);
       else
-	ret = (grubcmd->func) (grubcmd, argv.argc - 1, argv.args + 1);
+	ret = (grubcmd->func) (grubcmd, argc, args);
     }
   else
-    ret = grub_script_function_call (func, argv.argc - 1, argv.args + 1);
+    ret = grub_script_function_call (func, argc, args);
+
+  if (invert)
+    ret = ! ret;
 
   /* Free arguments.  */
   grub_script_argv_free (&argv);

=== modified file 'grub-core/script/yylex.l'
--- grub-core/script/yylex.l	2010-09-04 16:43:45 +0000
+++ grub-core/script/yylex.l	2010-09-05 09:27:28 +0000
@@ -155,7 +155,6 @@
 ">"             { RECORD; return GRUB_PARSER_TOKEN_GT;      }
 
  /* Reserved words */
-"!"             { RECORD; return GRUB_PARSER_TOKEN_NOT;       }
 "{"             { RECORD; return GRUB_PARSER_TOKEN_LBR;       }
 "}"             { RECORD; return GRUB_PARSER_TOKEN_RBR;       }
 "[["            { RECORD; return GRUB_PARSER_TOKEN_RSQBR2;    }

=== added file 'tests/grub_script_not.in'
--- tests/grub_script_not.in	1970-01-01 00:00:00 +0000
+++ tests/grub_script_not.in	2010-09-05 09:27:28 +0000
@@ -0,0 +1,62 @@
+#! @builddir@/grub-shell-tester
+#
+# Copyright (C) 2010  Free Software Foundation, Inc.
+#
+# GRUB is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# GRUB is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+
+true
+echo $?
+
+! true
+echo $?
+
+false
+echo $?
+
+! false
+echo $?
+
+#
+# Negated forms (copied from grub_script_if.in)
+#
+
+#basic if, execute
+if ! true; then echo yes; fi
+
+#basic if, no execution
+if ! false; then echo no; fi
+
+#if else, execute if path
+if ! true; then echo yes; else echo no; fi
+
+#if else, execute else path
+if ! false; then echo no; else echo yes; fi
+
+#if elif, execute elif
+if ! false; then echo no; elif ! true; then echo yes; fi
+
+#if elif else, execute else
+if ! false; then echo no; elif ! false; then echo no; else echo yes; fi
+
+#if elif(1) elif(2), execute elif(2)
+if false; then echo no; elif ! false; then echo no; elif ! true; then echo yes; fi
+
+#if elif(1) elif(2) else, execute else
+if false; then echo no; elif false; then echo no; elif ! false; then echo no; else echo yes; fi
+
+#if {if elif else}, execute elif
+if true; then if false; then echo no; elif ! true; then echo yes; else echo no; fi; fi
+
+#if {if elif} else, execute elif. ofcourse no dangling-else problem due to "fi"
+if true; then if ! false; then echo no; elif true; then echo yes; fi; else echo no; fi

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWR5yFzEABL/fgFAwfX/////v
36q////+YAmu7ZTfd7b2eK3u6XaedBz3u1wOh27cp6DfCSSaaJponqeRTyaYRiaCNkIaaHpNGjEN
GgybSCSUMk1T/Qk/TQkyj2pHpGmj1AAyDQAAADQJRACGiU/JpT9U9TIDTQAGgDRoAAAAJTREEyan
op+pqbTRqGI9TIMjTQAANANAaBzCaMjQ0MhhGhkNNGgAxGTIBhAMAkiCnoEYRPSNqGSMRptUelNP
UwjTQAYQDT0PQPF44bZZceTZFY6xGK9tZSeUrNEwx+J8bdo1itt5MWSFYGW5w3HTpRBLmpIT4e9H
Kh9znM1QxkYxvfbfByGKoBQFhvqT39HKr3Pyna+eHw+itvXmvnSVGs2bqQnIKLg4NthM3lMBwsi7
hZg7aO/BDB/O/+vuQn2XxQcx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HEfN0EMta1JwwZkn17IG2rMtEqLR1EIVIqrLwUJ2M4wSRRJ0SZCZIbYr
SC47tLooZnailoHUq6UBMzX0SIgMAzJQpiScZreAN8YBPTkl3EZMxYjwGUUgc4wVhMwLf0a0gfa1
MG7E07c265K3ugHvDkSW0DDu+7Z/UhfC0zKtmjAws3JIsTXHYSUp7wWqE05AzD9QdAcls19lBut1
reAnrilBcKo0jmtN3AadI/3KM44S/hnRVSJKyBv6pAuIFSE8t9L6oY6gspRhQZvWkqhGigtIhmPS
cU3CifvIwQMQ69vLxMANXKsGYTYOk9rgs8d8ovsYKg1NjIrR6qJAL0OUsXd5KsVLESLRo92uxxQU
zwlf0QfVEbVObDSYOJGkJzJgwvaBLCppxrQmd6owv1mO10G3MJlkUJMPsrsxG2SOH7CrYlir3T9M
UDwLHFdu28FHsMB+wkcwVSS/oseuAzAeuyuI+bKBfeP9GTxo+5A7JuL/UViN/cCzy3KwYHSrSD5r
lLJZL0hoMT8+nrZrF3HQ6F4eYLrBQEXnaaTbkpS7gUHSHSQRTD+sMcF7arzSiwvLtu2tcrTz3uwS
C7kinChIDzkLmIA=
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to