]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
Output strings from echo with puts where easy
authorJoe Hershberger <joe.hershberger@ni.com>
Wed, 3 Oct 2012 13:09:15 +0000 (13:09 +0000)
committerTom Rini <trini@ti.com>
Wed, 3 Oct 2012 23:13:34 +0000 (16:13 -0700)
Change echo to puts characters together where it knows about them
together.  This improves netconsole performance by greatly reducing
the number of packets that are sent.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
common/cmd_echo.c

index 43a6da57226f5696a5de0824807793521763226c..1e499fb0db93116b41c6ca7922bf78cee2ab71c5 100644 (file)
@@ -30,17 +30,31 @@ int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        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);
                }
        }