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