All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix for echo command on unrecognized options
@ 2010-08-25  4:35 BVK Chaitanya
  2010-08-25 10:14 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 4+ messages in thread
From: BVK Chaitanya @ 2010-08-25  4:35 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 687 bytes --]

Hi,


Attached patch fixes echo command behavior for unrecognized options.
On BASH echo command passes all unrecognized options to the output,
this patch makes GRUB version to behave similarly.  This bug has been
reported by Yves Blusseau (JrCs).


--- ChangeLog	2010-08-23 17:56:24 +0000
+++ ChangeLog	2010-08-25 04:19:18 +0000
@@ -1,3 +1,14 @@
+2010-08-25  BVK Chaitanya  <bvk.groups@gmail.com>
+
+	Fix echo command output for unrecognized options (bug reported by
+	Yves Blusseau)
+
+	* tests/grub_cmd_echo.in: New testcase.
+	* Makefile.util.def: Rules for new testcase.
+
+	* grub-core/commands/echo.c: Use custom option parsing instead of
+	extcmd framework.
+


-- 
bvk.chaitanya

[-- Attachment #2: echo-fix.patch --]
[-- Type: text/x-diff, Size: 7338 bytes --]

# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: bvk@dbook-20100825041918-mbuvbtmu000n4m9n
# target_branch: ../mainline/
# testament_sha1: 96b80c166d1cec9c6b8b9f130fad3c9b3e562827
# timestamp: 2010-08-25 09:54:00 +0530
# base_revision_id: bvk@dbook-20100823175624-z6uj4h4yjuyit29l
# 
# Begin patch
=== modified file 'ChangeLog'
--- ChangeLog	2010-08-23 17:56:24 +0000
+++ ChangeLog	2010-08-25 04:19:18 +0000
@@ -1,3 +1,14 @@
+2010-08-25  BVK Chaitanya  <bvk.groups@gmail.com>
+
+	Fix echo command output for unrecognized options (bug reported by
+	Yves Blusseau)
+
+	* tests/grub_cmd_echo.in: New testcase.
+	* Makefile.util.def: Rules for new testcase.
+
+	* grub-core/commands/echo.c: Use custom option parsing instead of
+	extcmd framework.
+
 2010-08-23  BVK Chaitanya  <bvk.groups@gmail.com>
 
 	New Automake based build system for GRUB.

=== modified file 'Makefile.util.def'
--- Makefile.util.def	2010-08-23 15:53:39 +0000
+++ Makefile.util.def	2010-08-25 04:19:18 +0000
@@ -496,6 +496,12 @@
   common = tests/grub_script_shift.in;
 };
 
+script = {
+  testcase;
+  name = grub_cmd_echo;
+  common = tests/grub_cmd_echo.in;
+};
+
 program = {
   testcase;
   name = example_unit_test;

=== modified file 'grub-core/commands/echo.c'
--- grub-core/commands/echo.c	2010-01-03 18:24:22 +0000
+++ grub-core/commands/echo.c	2010-08-25 04:19:18 +0000
@@ -19,36 +19,39 @@
 
 #include <grub/dl.h>
 #include <grub/misc.h>
-#include <grub/extcmd.h>
+#include <grub/command.h>
 #include <grub/i18n.h>
 
-static const struct grub_arg_option options[] =
-  {
-    {0, 'n', 0, N_("Do not output the trailing newline."), 0, 0},
-    {0, 'e', 0, N_("Enable interpretation of backslash escapes."), 0, 0},
-    {0, 0, 0, 0, 0, 0}
-  };
-
 static grub_err_t
-grub_cmd_echo (grub_extcmd_t cmd, int argc, char **args)
+grub_cmd_echo (grub_command_t cmd __attribute__ ((unused)),
+	       int argc, char **args)
 {
-  struct grub_arg_list *state = cmd->state;
+  int i;
+  int escape = 0;
   int newline = 1;
-  int i;
-
-  /* Check if `-n' was used.  */
-  if (state[0].set)
-    newline = 0;
+  int parseopt = 1;
 
   for (i = 0; i < argc; i++)
     {
       char *arg = *args;
       args++;
 
+      if (parseopt && grub_strcmp (arg, "-n") == 0)
+	{
+	  newline = 0;
+	  continue;
+	}
+      else if (parseopt && grub_strcmp (arg, "-e") == 0)
+	{
+	  escape = 1;
+	  continue;
+	}
+
+      parseopt = 0;
       while (*arg)
 	{
 	  /* In case `-e' is used, parse backslashes.  */
-	  if (*arg == '\\' && state[1].set)
+	  if (*arg == '\\' && escape)
 	    {
 	      arg++;
 	      if (*arg == '\0')
@@ -109,16 +112,15 @@
   return 0;
 }
 
-static grub_extcmd_t cmd;
+static grub_command_t cmd;
 \f
 GRUB_MOD_INIT(echo)
 {
-  cmd = grub_register_extcmd ("echo", grub_cmd_echo, GRUB_COMMAND_FLAG_BOTH,
-			      N_("[-e|-n] STRING"), N_("Display a line of text."),
-			      options);
+  cmd = grub_register_command ("echo", grub_cmd_echo, N_("[-e|-n] STRING"),
+			       N_("Display a line of text."));
 }
 
 GRUB_MOD_FINI(echo)
 {
-  grub_unregister_extcmd (cmd);
+  grub_unregister_command (cmd);
 }

=== added file 'tests/grub_cmd_echo.in'
--- tests/grub_cmd_echo.in	1970-01-01 00:00:00 +0000
+++ tests/grub_cmd_echo.in	2010-08-25 04:19:18 +0000
@@ -0,0 +1,33 @@
+#! @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/>.
+
+echo
+echo -n
+
+echo foo
+echo foo   bar
+
+echo -n foo
+
+echo -e "foo\nbar"
+
+echo -n -e "foo\nbar"
+
+echo foo -n
+echo foo -n -e
+
+echo -------

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWb+w1JMABFDfgBgweff//3/v
366////+YAk9u7trn3Z563m2dmOM71eeut1laG7c7rqASUgaRo1PU2RqnjTTJT1GnqaeoPKPE1Nq
YnoQZGnqACURNGhkE9EyhMnqZA0YQDQAAGmgZNPUEoRkFCTyNNNRkwnpNqA00AeoaAAABoCRITUa
aGQpP9EjyCZT0BNqBkBoxDZQ0GE0OMmTRoDRpiMjQxDAmjTEGI0GEABg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hV5H49iVouXYO1iosGefBDC+DAGMbzR
UWdyX/bSgoXgGknubud7c4NeHwF2wOPE9FoePrQGrV8/jRRRAQZHBJzlba3YtIYi/aDwzz5pz0MI
wVTgdBY+pdk9dUL6beapxD4kUPw1eHJ2gm5+cDQtgKSFYjhY5ozEY6fLB8yU0Tq6AXKWBCwc0n4t
QKOikNQHUfcCmTCjuR6D67bGhpMxTILL4EqTJultgeqPQFWiCoMKjKJSJDqEk4o1KMDDJA9nGWLF
QvA5vPtOUmIORyRbSwL6IuHiNLGILcvE5KEgN9rhRYCNKODTkfWtGUas83L38fqLjzslZIuUsRP5
WAwWg1OjUVDWVubK38M0ETGhSwLc8EjjRejWjDTdWGFsSkMg54WVk0mt3JluMhAuLni5yvJN0Qfj
NfjkhNLKYsCW29+IVIiM2l0IEsIbkgGs8tTe2yzyW7qqUjoJZnLtwsHcet5XmVnFrg7MNT2RbkGh
0oj2YUAuDBiiF1TXsq2gQrSpJE1K85NMKtmTIOQ6OZGyXimE5BIC3Cg6jU3MzsHOle4vDHuckZak
VvQMTuaus0F5iUDG4FcBBXyenM9lNwqsqdqhYPdmC0k0B7FdnlIwPMFlntkPeaVr6evTQVxs320X
WD18JBwLwKekOJtBZ7M4q84vSqSDU4y3KJUMeeg8se6w6ibvBu/SUpF1zY8+jHPvRAgWhoDIiuoK
b0rfV9JJ7js/8XckU4UJC/sNSTA=

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix for echo command on unrecognized options
  2010-08-25  4:35 [PATCH] Fix for echo command on unrecognized options BVK Chaitanya
@ 2010-08-25 10:14 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2010-08-25 11:16   ` BVK Chaitanya
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-08-25 10:14 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 1481 bytes --]

On 08/25/2010 06:35 AM, BVK Chaitanya wrote:
> Hi,
>
>
> Attached patch fixes echo command behavior for unrecognized options.
> On BASH echo command passes all unrecognized options to the output,
> this patch makes GRUB version to behave similarly.  This bug has been
> reported by Yves Blusseau (JrCs).
>
>   
This patch parses options manually but still fails to replicate the
'echo' behaviour.
1) echo erere -n outputs "erere -n"
2) We can still use extcmd, it just needs minor modifications to accept
flags GRUB_COMMAND_FLAG_ACCEPT_DASHARG (put -x and --xyz into args[])
and GRUB_COMMAND_FLAG_BSD_STYLE  (options precede arguments). As an
advantage the options are still listed in help and it may be useful for
other things as well (e.g. pending nounzip patch)
> --- ChangeLog	2010-08-23 17:56:24 +0000
> +++ ChangeLog	2010-08-25 04:19:18 +0000
> @@ -1,3 +1,14 @@
> +2010-08-25  BVK Chaitanya  <bvk.groups@gmail.com>
> +
> +	Fix echo command output for unrecognized options (bug reported by
> +	Yves Blusseau)
> +
> +	* tests/grub_cmd_echo.in: New testcase.
> +	* Makefile.util.def: Rules for new testcase.
> +
> +	* grub-core/commands/echo.c: Use custom option parsing instead of
> +	extcmd framework.
> +
>
>
>   
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>   


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix for echo command on unrecognized options
  2010-08-25 10:14 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-08-25 11:16   ` BVK Chaitanya
  2010-08-25 12:47     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 4+ messages in thread
From: BVK Chaitanya @ 2010-08-25 11:16 UTC (permalink / raw)
  To: The development of GNU GRUB

2010/8/25 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>:
> This patch parses options manually but still fails to replicate the
> 'echo' behaviour.
> 1) echo erere -n outputs "erere -n"

That is how echo in BASH seems to perform.  Attached testcase has this
case included.




-- 
bvk.chaitanya


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix for echo command on unrecognized options
  2010-08-25 11:16   ` BVK Chaitanya
@ 2010-08-25 12:47     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 4+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-08-25 12:47 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 528 bytes --]

On 08/25/2010 01:16 PM, BVK Chaitanya wrote:
> 2010/8/25 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>:
>   
>> This patch parses options manually but still fails to replicate the
>> 'echo' behaviour.
>> 1) echo erere -n outputs "erere -n"
>>     
> That is how echo in BASH seems to perform.  Attached testcase has this
> case included.
>
>   
Sorry. I misread your code then. What do you think of additional flags
for extcmd?
>
>
>   


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-25 12:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-25  4:35 [PATCH] Fix for echo command on unrecognized options BVK Chaitanya
2010-08-25 10:14 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-08-25 11:16   ` BVK Chaitanya
2010-08-25 12:47     ` Vladimir 'φ-coder/phcoder' Serbinenko

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.