]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/command.c
reset optind before executing command
[z180-stamp.git] / avr / command.c
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;