From 52ef24e4020adcb773adcb0d82b1c2c385610461 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 1 Oct 2018 15:18:33 +0200 Subject: [PATCH] reset optind before executing command --- avr/cmd_attach.c | 3 --- avr/cmd_boot.c | 6 ------ avr/cmd_cpu.c | 8 -------- avr/cmd_gpio.c | 3 --- avr/cmd_mem.c | 4 ---- avr/cmd_misc.c | 3 --- avr/command.c | 6 ++---- avr/env.c | 3 --- avr/getopt-min.c | 2 +- 9 files changed, 3 insertions(+), 35 deletions(-) diff --git a/avr/cmd_attach.c b/avr/cmd_attach.c index 0949687..651404f 100644 --- a/avr/cmd_attach.c +++ b/avr/cmd_attach.c @@ -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) { diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c index e26a8b1..dcf834d 100644 --- a/avr/cmd_boot.c +++ b/avr/cmd_boot.c @@ -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) { diff --git a/avr/cmd_cpu.c b/avr/cmd_cpu.c index 6f50a2a..d692211 100644 --- a/avr/cmd_cpu.c +++ b/avr/cmd_cpu.c @@ -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) { diff --git a/avr/cmd_gpio.c b/avr/cmd_gpio.c index 65a71be..549654f 100644 --- a/avr/cmd_gpio.c +++ b/avr/cmd_gpio.c @@ -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) { diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c index d641410..3e18770 100644 --- a/avr/cmd_mem.c +++ b/avr/cmd_mem.c @@ -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) diff --git a/avr/cmd_misc.c b/avr/cmd_misc.c index a88ba72..72102c6 100644 --- a/avr/cmd_misc.c +++ b/avr/cmd_misc.c @@ -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) { diff --git a/avr/command.c b/avr/command.c index ff3a685..8eb5bb7 100644 --- a/avr/command.c +++ b/avr/command.c @@ -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; diff --git a/avr/env.c b/avr/env.c index add281c..3bb04c2 100644 --- 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) { diff --git a/avr/getopt-min.c b/avr/getopt-min.c index 8508f40..401beed 100644 --- a/avr/getopt-min.c +++ b/avr/getopt-min.c @@ -13,7 +13,7 @@ #include "common.h" /* definition of FLASH */ #include -int optind = 0; /* next argv[] index */ +int optind; /* next argv[] index */ char *optarg; /* option parameter if any */ -- 2.39.2