]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_misc.c
commandtable, flags: int --> uint8_t/uint_fast8_t. Macro UNUSED for Parameters/Variables
[z180-stamp.git] / avr / cmd_misc.c
index 7ab8fef0349e323aa7aad19171a9544c26835379..a0ee26e7afedafd9e91b59f3a273d072bc66007f 100644 (file)
@@ -1,58 +1,89 @@
 /*
+ * (C) Copyright 2014,2016 Leo C. <erbl259-lmu@yahoo.de>
+ *
  * 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 "eval_arg.h"
+#include <stdbool.h>
+
 #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[])
+command_ret_t do_echo(cmd_tbl_t *cmdtp, uint_fast8_t 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;
 
-               uint_fast8_t backslash = 0;
-               char *p = argv[i];
-               char c;
-               
-               if (i != 1)
-                       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);
+       int opt;
+       while ((opt = getopt(argc, argv, PSTR("n"))) != -1) {
+               switch (opt) {
+               case 'n':
+                       put_newline = false;
+                       break;
+               default: /* '?' */
+                       return CMD_RET_USAGE;
                }
-       }                       
-                                       
-       if (putnl)
+       }
+
+       for (uint_fast8_t i = optind; i < argc; i++) {
+
+               if (i != optind)
+                       putchar(' ');
+
+               my_puts(argv[i]);
+       }
+
+       if (put_newline)
                putchar('\n');
 
        return CMD_RET_SUCCESS;
 }
 
-#if 0
-U_BOOT_CMD(
-       echo,   CONFIG_SYS_MAXARGS,     1,      do_echo,
-       "echo args to console",
-       "[args..]\n"
-       "    - echo args to console; \\c suppresses newline"
-);
-#endif
+
+command_ret_t do_sleep(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
+{
+       unsigned long start = get_timer(0);
+       unsigned long delay;
+       char *sp;
+       uint_fast8_t millisec = 0;
+
+       (void) cmdtp; (void) flag;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       delay = eval_arg(argv[1], &sp);
+
+       if (*sp == 'm') {
+               millisec = 1;
+               sp++;
+       }
+       if (*sp == 's')
+               sp++;
+       if (*sp != '\0')
+               return CMD_RET_USAGE;
+
+       if (!millisec)
+               delay *= 1000;
+
+       while (get_timer(start) < delay) {
+               if (ctrlc())
+                       return CMD_RET_FAILURE;
+
+               udelay(100);
+       }
+
+       return CMD_RET_SUCCESS;
+}