]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_misc.c
fatfs f_mount now allways done globally at start up
[z180-stamp.git] / avr / cmd_misc.c
index b29aedddce4c3dee0bd39db617ad822e802127fe..c9a3c4529e255957940bb9f699237d25c1838004 100644 (file)
@@ -9,46 +9,43 @@
 
 #include "common.h"
 #include <stdlib.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[])
 {
-       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 = 1;
+
+       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;