]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Bugfix: reset getopt vars on start of a new argument line
authorLeo C <erbl259-lmu@yahoo.de>
Sat, 4 Jun 2016 13:48:50 +0000 (15:48 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Sat, 4 Jun 2016 13:48:50 +0000 (15:48 +0200)
avr/cmd_attach.c
avr/cmd_gpio.c
avr/cmd_mem.c
avr/cmd_misc.c
avr/getopt-min.c

index 9fbfa1e68fbdeda9d98643cb20909df98c384c45..d7bcafd60bdf7e602be46c40a4109b0b984f020a 100644 (file)
@@ -80,7 +80,7 @@ command_ret_t do_attach(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
        }
 
        /* reset getopt() */
-       optind = 1;
+       optind = 0;
 
        int opt;
        while ((opt = getopt(argc, argv, PSTR("darwo:"))) != -1) {
index 6b7b3f7b069c9a6b5ef8d4391d84992d6f8ed728..d3ef716f0e10ed98bbfe4ccbe796abbb68a719ba 100644 (file)
@@ -185,7 +185,7 @@ command_ret_t do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
        (void) cmdtp; (void) flag;
 
        /* reset getopt() */
-       optind = 1;
+       optind = 0;
 
        int opt;
        while ((opt = getopt(argc, argv, PSTR("s"))) != -1) {
index 9adee72e7cace6501cf89341c083df8010b5970d..ded514669f1a6122f54c3b53bcd810d031cae4a4 100644 (file)
@@ -202,7 +202,7 @@ command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
        (void) cmdtp; (void) flag;
 
        /* reset getopt() */
-       optind = 1;
+       optind = 0;
 
        int opt;
        while ((opt = getopt(argc, argv, PSTR("bwl"))) != -1) {
index c9a3c4529e255957940bb9f699237d25c1838004..1ff6f5d2a34e6c6622140c79a90a79207eccb82b 100644 (file)
@@ -24,7 +24,7 @@ command_ret_t do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        (void) cmdtp; (void) flag;
 
        /* reset getopt() */
-       optind = 1;
+       optind = 0;
 
        int opt;
        while ((opt = getopt(argc, argv, PSTR("n"))) != -1) {
index f5ad912f281e1a73085160f6282e9754e04d1bea..8508f401a725329c5aeb35766efaa06392c43d79 100644 (file)
@@ -13,7 +13,7 @@
 #include "common.h"            /* definition of FLASH */
 #include <string.h>
 
-int    optind = 1;                     /* next argv[] index */
+int    optind = 0;                     /* next argv[] index */
 char *optarg;          /* option parameter if any */
 
 
@@ -23,12 +23,16 @@ getopt(                             /* returns letter, '?', EOF */
        char    *const argv[],  /* argument vector from main */
        const FLASH char *optstring )           /* allowed args, e.g. "ab:c" */
 {
-       static int      sp = 1;         /* position within argument */
+       static int      sp;             /* position within argument */
        int             osp;            /* saved `sp' for param test */
        int             c;              /* option letter */
        const FLASH char *cp;           /* -> option in `optstring' */
 
        optarg = NULL;
+       if (optind == 0) {              /* start a new argument scan */
+               optind = 1;
+               sp = 1;
+       }
 
        if ( sp == 1 )                  /* fresh argument */
        {