2 * echo.c - echo arguments to stdout or into a file
4 * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 static int do_echo(struct command
*cmdtp
, int argc
, char *argv
[])
33 int fd
= stdout
, opt
, newline
= 1;
35 int oflags
= O_WRONLY
| O_CREAT
;
36 #ifdef CONFIG_CMD_ECHO_E
37 char str
[CONFIG_CBSIZE
];
38 int process_escape
= 0;
40 /* We can't use getopt() here because we want to
41 * echo all things we don't understand.
43 while (optind
< argc
&& *argv
[optind
] == '-') {
44 if (!*(argv
[optind
] + 1) || *(argv
[optind
] + 2))
47 opt
= *(argv
[optind
] + 1);
54 if (optind
+ 1 < argc
)
55 file
= argv
[optind
+ 1];
62 file
= argv
[optind
+ 1];
63 if (optind
+ 1 < argc
)
64 file
= argv
[optind
+ 1];
69 #ifdef CONFIG_CMD_ECHO_E
82 fd
= open(file
, oflags
);
89 for (i
= optind
; i
< argc
; i
++) {
92 #ifdef CONFIG_CMD_ECHO_E
94 process_escape_sequence(argv
[i
], str
, CONFIG_CBSIZE
);
110 printf("option requires an argument -- %c\n", opt
);
114 BAREBOX_CMD_START(echo
)
116 .usage
= "echo args to console",