Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peter Tyser | 6b8f5ad | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2000-2009 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Peter Tyser | 6b8f5ad | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
| 9 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 10 | static int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Peter Tyser | 6b8f5ad | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 11 | { |
| 12 | int i; |
| 13 | int putnl = 1; |
| 14 | |
| 15 | for (i = 1; i < argc; i++) { |
Joe Hershberger | bb64d1c | 2012-10-03 13:09:15 +0000 | [diff] [blame] | 16 | char *p = argv[i]; |
| 17 | char *nls; /* new-line suppression */ |
Peter Tyser | 6b8f5ad | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 18 | |
| 19 | if (i > 1) |
| 20 | putc(' '); |
Joe Hershberger | bb64d1c | 2012-10-03 13:09:15 +0000 | [diff] [blame] | 21 | |
| 22 | nls = strstr(p, "\\c"); |
| 23 | if (nls) { |
| 24 | char *prenls = p; |
| 25 | |
| 26 | putnl = 0; |
| 27 | /* |
| 28 | * be paranoid and guess that someone might |
| 29 | * say \c more than once |
| 30 | */ |
| 31 | while (nls) { |
| 32 | *nls = '\0'; |
| 33 | puts(prenls); |
| 34 | *nls = '\\'; |
| 35 | prenls = nls + 2; |
| 36 | nls = strstr(prenls, "\\c"); |
Peter Tyser | 6b8f5ad | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 37 | } |
Joe Hershberger | bb64d1c | 2012-10-03 13:09:15 +0000 | [diff] [blame] | 38 | puts(prenls); |
| 39 | } else { |
| 40 | puts(p); |
Peter Tyser | 6b8f5ad | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | if (putnl) |
| 45 | putc('\n'); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | U_BOOT_CMD( |
| 51 | echo, CONFIG_SYS_MAXARGS, 1, do_echo, |
| 52 | "echo args to console", |
| 53 | "[args..]\n" |
| 54 | " - echo args to console; \\c suppresses newline" |
| 55 | ); |