Skip to contentSkip to conversation

Output strings from echo with puts where easy

PATCH Superseded Joe Hershberger 3 participants 4 messages Aug 17, 2012 – Oct 4, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Output strings from echo with puts where easy

Change echo to puts charachters together where it knows about them together. This improves netconsole performance by greatly reducing the number of packets that are sent.

---
 common/cmd_echo.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
common/cmd_echo.c +12 -8
index 43a6da5..e04738f 100644
@@ -28,19 +28,23 @@ int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	int i;
 	int putnl = 1;
+	char *nls; /* new-line suppression */
 
 	for (i = 1; i < argc; i++) {
-		char *p = argv[i], c;
+		char *p = argv[i];
 
 		if (i > 1)
 			putc(' ');
-		while ((c = *p++) != '\0') {
-			if (c == '\\' && *p == 'c') {
-				putnl = 0;
-				p++;
-			} else {
-				putc(c);
-			}
+
+		nls = strstr(p, "\\c");
+		if (nls) {
+			putnl = 0;
+			*nls = '\0';
+			puts(p);
+			puts(nls + 2);
+			*nls = '\\';
+		} else {
+			puts(p);
 		}
 	}
 
Signature · 1 line
1.7.11.5
#1 lore raw

PATCH 1/1 Output strings from echo with puts where easy

Quoted 12 lines · On Friday 17 August 2012 16:55:18 Joe Hershberger wrote:
common/cmd_echo.c +2 -7
 
-		while ((c = *p++) != '\0') {
-			if (c == '\\' && *p == 'c') {
-				putnl = 0;
-				p++;
-			} else {
-				putc(c);
-			}
+
+		nls = strstr(p, "\\c");

common/cmd_echo.c int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 49

Quoted 10 lines
common/cmd_echo.c +8 -0
+		if (nls) {
+			putnl = 0;
+			*nls = '\0';
+			puts(p);
+			puts(nls + 2);
+			*nls = '\\';
+		} else {
+			puts(p);
 		}
 	}

what if someone uses \c multiple times ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120817/a9ea0305/attachment.pgp>

#2 lore raw

PATCH v2 1/1 Output strings from echo with puts where easy

In reply to Joe Hershberger

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.

---
Changes in v2:
- Check for someone to specify "\c" more than once in each word

 common/cmd_echo.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
common/cmd_echo.c +21 -7
index 43a6da5..1e499fb 100644
@@ -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);
 		}
 	}
 
Signature · 1 line
1.7.11.5
#3 lore raw

PATCH v2 1/1 Output strings from echo with puts where easy

Quoted 5 lines · Joe Hershberger

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.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20121003/38a138d3/attachment.pgp>