mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 10/12] echo command: Add -e option
Date: Mon, 29 Mar 2010 11:36:21 +0200	[thread overview]
Message-ID: <1269855383-22716-11-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1269855383-22716-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/Kconfig |    6 +++++
 commands/echo.c  |   65 ++++++++++++-----------------------------------------
 2 files changed, 21 insertions(+), 50 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index 543ee71..0c09f91 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -118,6 +118,12 @@ config CMD_ECHO
 	default y
 	prompt "echo"
 
+config CMD_ECHO_E
+	bool
+	depends on CMD_ECHO
+	select PROCESS_ESCAPE_SEQUENCE
+	prompt "support -e option to echo"
+
 endmenu
 
 menu "memory                        "
diff --git a/commands/echo.c b/commands/echo.c
index 6f4f136..dfa14d6 100644
--- a/commands/echo.c
+++ b/commands/echo.c
@@ -25,52 +25,7 @@
 #include <fs.h>
 #include <fcntl.h>
 #include <errno.h>
-
-static int my_fputs(int fd, const char *s)
-{
-	int c;
-
-	while (*s) {
-		if (*s == '\\') {
-			switch (*(s + 1)) {
-			case 0:
-				return 0;
-			case '\\':
-				c = '\\';
-				break;
-			case 'a':
-				c = '\a';
-				break;
-			case 'b':
-				c = '\b';
-				break;
-			case 'n':
-				c = '\n';
-				break;
-			case 'r':
-				c = '\r';
-				break;
-			case 't':
-				c = '\t';
-				break;
-			case 'f':
-				c = '\f';
-				break;
-			case 'e':
-				c = 0x1b;
-				break;
-			default:
-				fputc(fd, '\\');
-				c = *(s + 1);
-			}
-			s++;
-			fputc(fd, c);
-		} else
-			fputc(fd, *s);
-		s++;
-	}
-	return 0;
-}
+#include <libbb.h>
 
 static int do_echo(struct command *cmdtp, int argc, char *argv[])
 {
@@ -78,8 +33,10 @@ static int do_echo(struct command *cmdtp, int argc, char *argv[])
 	int fd = stdout, opt, newline = 1;
 	char *file = NULL;
 	int oflags = O_WRONLY | O_CREAT;
-	int (*fputsfunc)(int, const char *) = fputs;
-
+#ifdef CONFIG_CMD_ECHO_E
+	char str[CONFIG_CBSIZE];
+	int process_escape = 0;
+#endif
 	/* We can't use getopt() here because we want to
 	 * echo all things we don't understand.
 	 */
@@ -109,9 +66,11 @@ static int do_echo(struct command *cmdtp, int argc, char *argv[])
 				goto no_optarg_out;
 			optind++;
 			break;
+#ifdef CONFIG_CMD_ECHO_E
 		case 'e':
-			fputsfunc = my_fputs;
+			process_escape = 1;
 			break;
+#endif
 		default:
 			goto exit_parse;
 		}
@@ -130,7 +89,13 @@ exit_parse:
 	for (i = optind; i < argc; i++) {
 		if (i > optind)
 			fputc(fd, ' ');
-		fputsfunc(fd, argv[i]);
+#ifdef CONFIG_CMD_ECHO_E
+		if (process_escape) {
+			process_escape_sequence(argv[i], str, CONFIG_CBSIZE);
+			fputs(fd, str);
+		} else
+#endif
+			fputs(fd, argv[i]);
 	}
 
 	if (newline)
-- 
1.7.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2010-03-29  9:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-29  9:36 Patches for next merge window Sascha Hauer
2010-03-29  9:36 ` [PATCH 01/12] ARM zImage: do memmap if possible Sascha Hauer
2010-03-29 18:47   ` Peter Korsgaard
2010-03-30  9:20     ` Sascha Hauer
2010-03-30 10:01       ` Peter Korsgaard
2010-03-30 12:18         ` Sascha Hauer
2010-03-29  9:36 ` [PATCH 02/12] nand_imx: use optimized memcpy Sascha Hauer
2010-03-29  9:36 ` [PATCH 03/12] nand_imx: Speed up sequential read Sascha Hauer
2010-03-29  9:36 ` [PATCH 04/12] imx_nand: use memcpy for copying from/to buffer Sascha Hauer
2010-03-29 10:42   ` Ivo Clarysse
2010-03-29  9:36 ` [PATCH 05/12] add unaligned access support Sascha Hauer
2010-03-29  9:36 ` [PATCH 06/12] add unlzo support Sascha Hauer
2010-03-30 11:04   ` Sascha Hauer
2010-03-29  9:36 ` [PATCH 07/12] add snprintf function Sascha Hauer
2010-03-29  9:36 ` [PATCH 08/12] echo: add -e option support Sascha Hauer
2010-03-30 11:45   ` Peter Korsgaard
2010-03-30 12:17     ` Sascha Hauer
2010-03-29  9:36 ` [PATCH 09/12] add process_escape_sequence function Sascha Hauer
2010-03-29  9:36 ` Sascha Hauer [this message]
2010-03-29  9:36 ` [PATCH 11/12] hush: only remove backslashes introduced from glob Sascha Hauer
2010-03-29 10:00   ` Sascha Hauer
2010-03-29  9:36 ` [PATCH 12/12] hush: allow fancy prompts Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1269855383-22716-11-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox