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