]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
reset optind before executing command
authorLeo C <erbl259-lmu@yahoo.de>
Mon, 1 Oct 2018 13:18:33 +0000 (15:18 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Mon, 1 Oct 2018 13:18:33 +0000 (15:18 +0200)
avr/cmd_attach.c
avr/cmd_boot.c
avr/cmd_cpu.c
avr/cmd_gpio.c
avr/cmd_mem.c
avr/cmd_misc.c
avr/command.c
avr/env.c
avr/getopt-min.c

index 09496875c3bf28f0b3ce034f419659c263b2d6db..651404f83eb073236fb45f704baa5c1aeaaea0dd 100644 (file)
@@ -49,9 +49,6 @@ command_ret_t do_attach(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * co
                return CMD_RET_SUCCESS;
        }
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("darwo:"))) != -1) {
                switch (opt) {
index e26a8b1b3340226aa0730bd871a9a653a49b575a..dcf834d7532eef4f667ecbcf92ddc653f11c1444 100644 (file)
@@ -106,9 +106,6 @@ command_ret_t do_bootcf(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int a
        memcpy_P(&boot_param, cfboot, sizeof boot_param);
        default_stages = boot_param.stages;
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("vna:s:c:t:i:"))) != -1) {
                switch (opt) {
@@ -256,9 +253,6 @@ command_ret_t do_go(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc,
        uint32_t addr;
        bool hold = 0;
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("h"))) != -1) {
                switch (opt) {
index 6f50a2a628fc57b6878cbbc8e4f07ed02a9e3e9c..d69221100e25ab3efe5c208e3f5f613b1df36bd0 100644 (file)
@@ -204,9 +204,6 @@ command_ret_t do_cpu_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int
 
        uint32_t pulsewidth = 10; /* ms */
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("t:"))) != -1) {
                switch (opt) {
@@ -237,8 +234,6 @@ command_ret_t do_bus_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int
        char ch;
 
 #if 0
-       /* reset getopt() */
-       optind = 0;
        int opt;
        while ((opt = getopt(argc, argv, PSTR("t:"))) != -1) {
                switch (opt) {
@@ -331,9 +326,6 @@ command_ret_t do_cpu_freq(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int
        uint8_t eimsk_save;
        uint8_t mem_save[cpuinfo_length];
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("swnuc:t:"))) != -1) {
                switch (opt) {
index 65a71bec864687ae1d24672b0d7fc096683ce162..549654fdf1c6e24da59512d87bff73ab2d71ba11 100644 (file)
@@ -173,9 +173,6 @@ command_ret_t do_gpio(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int arg
        uint_fast8_t pinarg[GPIO_MAX];
        uint_fast8_t pinargc;
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("s"))) != -1) {
                switch (opt) {
index d641410639e3abcba368f99fbd0d3806cf335b80..3e187701bb19e66968dc49caadbcd1186fe409df 100644 (file)
@@ -204,9 +204,6 @@ command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * co
 
        (void) cmdtp; (void) flag;
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("bwl"))) != -1) {
                switch (opt) {
@@ -261,7 +258,6 @@ command_ret_t do_mem_mdc ( cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char *
        (void) cmdtp;
        (void) flag;
 
-       optind = 0;
        if (argv[0][1] != 'd') {
                int opt;
                while ((opt = getopt(argc, argv, PSTR("bwl"))) != -1)
index a88ba7292e57d71c541a4fa4cc2a6cb0c7f9949e..72102c66c46e82788cd314a9a85a18a4585e5904 100644 (file)
@@ -22,9 +22,6 @@ command_ret_t do_echo(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * cons
 
        (void) cmdtp; (void) flag;
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("n"))) != -1) {
                switch (opt) {
index ff3a685831a51bf31da2b11ec63d4f22745d89b2..8eb5bb74f91cf40cf68753717f30c9e5faf77d90 100644 (file)
@@ -262,9 +262,6 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char
 #define OPT_USAGE              0x08
 #define OPT_LONG               0x10
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("afk"))) != -1) {
                switch (opt) {
@@ -708,7 +705,7 @@ static cmd_tbl_t *cmd_invocation_ptr;
  * @param argv         Arguments
  * @return 0 if command succeeded, else non-zero (CMD_RET_...)
  */
-command_ret_t cmd_call(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
+static command_ret_t cmd_call(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
 {
        command_ret_t result;
 
@@ -770,6 +767,7 @@ command_ret_t cmd_process(uint_fast8_t flag, int argc, char * const argv[],
 
        /* If OK so far, then do the command */
        if (!rc) {
+               optind = 0;                     /* reset getopt() */
                cmd_invocation_ptr = cmdtp;
                rc = cmd_call(cmdtp, flag, argc, argv);
                *repeatable &= (cmdtp->flags & CTBL_RPT) != 0;
index add281c26e36c64d922329930e4b1d7ca8526cc1..3bb04c28fbd64a46e771b916dd1568bb1804feab 100644 (file)
--- a/avr/env.c
+++ b/avr/env.c
@@ -693,9 +693,6 @@ command_ret_t do_env_print(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED,
        bool mode = 0;
        command_ret_t rc = CMD_RET_SUCCESS;
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("s"))) != -1) {
                switch (opt) {
index 8508f401a725329c5aeb35766efaa06392c43d79..401beedfc1b40333494ef213fc338bd96cba726f 100644 (file)
@@ -13,7 +13,7 @@
 #include "common.h"            /* definition of FLASH */
 #include <string.h>
 
-int    optind = 0;                     /* next argv[] index */
+int    optind;                 /* next argv[] index */
 char *optarg;          /* option parameter if any */