Backport echo command
authorPiotr Dymacz <pepe2k@gmail.com>
Wed, 31 Aug 2016 20:06:39 +0000 (22:06 +0200)
committerPiotr Dymacz <pepe2k@gmail.com>
Wed, 31 Aug 2016 20:06:39 +0000 (22:06 +0200)
u-boot/common/command.c

index ac5cd966d1a08e51f811ed7052928946a667d93a..005d1af0a4e69651352feaffe8919c6b59dc028b 100644 (file)
@@ -41,21 +41,35 @@ U_BOOT_CMD(version, 1, 1, do_version, "print U-Boot version\n", NULL);
 #if defined(CONFIG_CMD_ECHO)
 int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-       int i, putnl = 1;
+       int i;
+       int putnl = 1;
 
        for (i = 1; i < argc; i++) {
-               char *p = argv[i], c;
+               char *p = argv[i];
+               char *nls; /* new-line suppression */
 
                if (i > 1)
                        putc(' ');
 
-               while ((c = *p++) != '\0') {
-                       if (c == '\\' && *p == 'c') {
-                               putnl = 0;
-                               p++;
-                       } else {
-                               putc(c);
+               nls = strstr(p, "\\c");
+               if (nls) {
+                       char *prenls = p;
+
+                       putnl = 0;
+                       /*
+                        * be paranoid and guess that someone might
+                        * say \c more than once
+                        */
+                       while (nls) {
+                               *nls = '\0';
+                               puts(prenls);
+                               *nls = '\\';
+                               prenls = nls + 2;
+                               nls = strstr(prenls, "\\c");
                        }
+                       puts(prenls);
+               } else {
+                       puts(p);
                }
        }