]>
Commit | Line | Data |
---|---|---|
d684c216 L |
1 | /* |
2 | * Copyright 2000-2009 | |
3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
4 | * | |
5 | * SPDX-License-Identifier: GPL-2.0+ | |
6 | */ | |
7 | ||
8 | #include "common.h" | |
8a7decea L |
9 | #include <stdlib.h> |
10 | ||
d684c216 | 11 | #include "command.h" |
8a7decea L |
12 | #include "timer.h" |
13 | #include "con-utils.h" | |
d684c216 L |
14 | |
15 | ||
d0581f88 | 16 | command_ret_t do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
d684c216 L |
17 | { |
18 | uint_fast8_t putnl = 1; | |
8a7decea | 19 | |
d684c216 L |
20 | (void) cmdtp; (void) flag; |
21 | ||
22 | for (uint_fast8_t i = 1; i < argc; i++) { | |
23 | ||
24 | uint_fast8_t backslash = 0; | |
25 | char *p = argv[i]; | |
26 | char c; | |
8a7decea | 27 | |
d684c216 L |
28 | if (i != 1) |
29 | putchar(' '); | |
30 | while ((c = *p++) != '\0') { | |
8a7decea | 31 | |
d684c216 L |
32 | if(backslash) { |
33 | backslash = 0; | |
34 | if (c == 'c') { | |
35 | putnl = 0; | |
36 | continue; | |
37 | } else | |
38 | putchar('\\'); | |
39 | } else { | |
40 | if (c == '\\') { | |
41 | backslash = 1; | |
42 | continue; | |
43 | } | |
44 | } | |
45 | putchar(c); | |
46 | } | |
8a7decea L |
47 | } |
48 | ||
d684c216 L |
49 | if (putnl) |
50 | putchar('\n'); | |
51 | ||
d0581f88 | 52 | return CMD_RET_SUCCESS; |
d684c216 L |
53 | } |
54 | ||
8a7decea L |
55 | |
56 | command_ret_t do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
57 | { | |
58 | unsigned long start = get_timer(0); | |
59 | unsigned long delay; | |
60 | char *sp; | |
61 | uint_fast8_t millisec = 0; | |
62 | ||
63 | (void) cmdtp; (void) flag; | |
64 | ||
65 | if (argc != 2) | |
66 | return CMD_RET_USAGE; | |
67 | ||
68 | delay = strtoul(argv[1], &sp, 10); | |
69 | ||
70 | if (*sp == 'm') { | |
71 | millisec = 1; | |
72 | sp++; | |
73 | } | |
74 | if (*sp == 's') | |
75 | sp++; | |
76 | if (*sp != '\0') | |
77 | return CMD_RET_USAGE; | |
78 | ||
79 | if (!millisec) | |
80 | delay *= 1000; | |
81 | ||
82 | while (get_timer(start) < delay) { | |
83 | if (ctrlc()) | |
84 | return CMD_RET_FAILURE; | |
85 | ||
86 | udelay(100); | |
87 | } | |
88 | ||
89 | return CMD_RET_SUCCESS; | |
90 | } | |
91 |