]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_echo.c
Merge branch 'master' of git://git.denx.de/u-boot-video
[karo-tx-uboot.git] / common / cmd_echo.c
index 43a6da57226f5696a5de0824807793521763226c..52123fee2afc6e07f40b820548f060ce9bc05ffc 100644 (file)
 #include <common.h>
 #include <command.h>
 
-int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        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);
                }
        }