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