summaryrefslogtreecommitdiff
path: root/avr/cmd_echo.c
blob: 7ab8fef0349e323aa7aad19171a9544c26835379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright 2000-2009
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include "common.h"
#include "command.h"


command_ret_t do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	uint_fast8_t putnl = 1;
	
	(void) cmdtp; (void) flag;

	for (uint_fast8_t i = 1; i < argc; i++) {

		uint_fast8_t backslash = 0;
		char *p = argv[i];
		char c;
		
		if (i != 1)
			putchar(' ');
		while ((c = *p++) != '\0') {
		
			if(backslash) {
				backslash = 0;
				if (c == 'c') {
					putnl = 0;
					continue;
				} else
					putchar('\\');
			} else {
				if (c == '\\') {
					backslash = 1;
					continue;
				}
			}
			putchar(c);
		}
	}			
					
	if (putnl)
		putchar('\n');

	return CMD_RET_SUCCESS;
}

#if 0
U_BOOT_CMD(
	echo,	CONFIG_SYS_MAXARGS,	1,	do_echo,
	"echo args to console",
	"[args..]\n"
	"    - echo args to console; \\c suppresses newline"
);
#endif