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