X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/35edb766593d019b89a3f40b6d6cdd2b50f18032..122660398b4c99ebad726a80a76e281cb55fe5dc:/avr/cmd_misc.c diff --git a/avr/cmd_misc.c b/avr/cmd_misc.c index b29aedd..9061b5a 100644 --- a/avr/cmd_misc.c +++ b/avr/cmd_misc.c @@ -1,54 +1,51 @@ /* - * (C) Copyright 2014 Leo C. + * (C) Copyright 2014,2016 Leo C. * * Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ #include "common.h" -#include +#include "eval_arg.h" +#include #include "command.h" #include "timer.h" #include "con-utils.h" +#include "getopt-min.h" command_ret_t do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - uint_fast8_t putnl = 1; + bool put_newline = true; (void) cmdtp; (void) flag; - for (uint_fast8_t i = 1; i < argc; i++) { + /* reset getopt() */ + optind = 0; + + int opt; + while ((opt = getopt(argc, argv, PSTR("n"))) != -1) { + switch (opt) { + case 'n': + put_newline = false; + break; + default: /* '?' */ + return CMD_RET_USAGE; + } + } - uint_fast8_t backslash = 0; - char *p = argv[i]; - char c; + for (uint_fast8_t i = optind; i < argc; i++) { - if (i != 1) + if (i != optind) 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); - } + + my_puts(argv[i]); } - if (putnl) + if (put_newline) putchar('\n'); return CMD_RET_SUCCESS; @@ -67,7 +64,7 @@ command_ret_t do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] if (argc != 2) return CMD_RET_USAGE; - delay = strtoul(argv[1], &sp, 10); + delay = eval_arg(argv[1], &sp); if (*sp == 'm') { millisec = 1;