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 | { |
Heinrich Schuchardt | a2f472d | 2021-01-20 12:13:30 +0100 | [diff] [blame] | 13 | int i = 1; |
| 14 | bool space = false; |
| 15 | bool newline = true; |
Peter Tyser | eabe6d9 | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 16 | |
Heinrich Schuchardt | a2f472d | 2021-01-20 12:13:30 +0100 | [diff] [blame] | 17 | if (argc > 1) { |
| 18 | if (!strcmp(argv[1], "-n")) { |
| 19 | newline = false; |
| 20 | ++i; |
| 21 | } |
| 22 | } |
Peter Tyser | eabe6d9 | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 23 | |
Heinrich Schuchardt | a2f472d | 2021-01-20 12:13:30 +0100 | [diff] [blame] | 24 | for (; i < argc; ++i) { |
| 25 | if (space) { |
Peter Tyser | eabe6d9 | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 26 | putc(' '); |
Peter Tyser | eabe6d9 | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 27 | } |
Heinrich Schuchardt | a2f472d | 2021-01-20 12:13:30 +0100 | [diff] [blame] | 28 | puts(argv[i]); |
| 29 | space = true; |
Peter Tyser | eabe6d9 | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Heinrich Schuchardt | a2f472d | 2021-01-20 12:13:30 +0100 | [diff] [blame] | 32 | if (newline) |
Peter Tyser | eabe6d9 | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 33 | putc('\n'); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | U_BOOT_CMD( |
Heinrich Schuchardt | a2f472d | 2021-01-20 12:13:30 +0100 | [diff] [blame] | 39 | echo, CONFIG_SYS_MAXARGS, 1, do_echo, |
Peter Tyser | eabe6d9 | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 40 | "echo args to console", |
Heinrich Schuchardt | a2f472d | 2021-01-20 12:13:30 +0100 | [diff] [blame] | 41 | "[-n] [args..]\n" |
| 42 | " - echo args to console; -n suppresses newline" |
Peter Tyser | eabe6d9 | 2009-10-16 17:36:25 -0500 | [diff] [blame] | 43 | ); |