xref: /openbmc/u-boot/cmd/echo.c (revision cd71b1d5)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2000-2009
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6 
7 #include <common.h>
8 #include <command.h>
9 
10 static int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
11 {
12 	int i;
13 	int putnl = 1;
14 
15 	for (i = 1; i < argc; i++) {
16 		char *p = argv[i];
17 		char *nls; /* new-line suppression */
18 
19 		if (i > 1)
20 			putc(' ');
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");
37 			}
38 			puts(prenls);
39 		} else {
40 			puts(p);
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 );
56