X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/35edb766593d019b89a3f40b6d6cdd2b50f18032..4912667be3154f62d3206a47b6e748b0b6281ae3:/avr/getopt-min.c diff --git a/avr/getopt-min.c b/avr/getopt-min.c index f5ad912..8508f40 100644 --- a/avr/getopt-min.c +++ b/avr/getopt-min.c @@ -13,7 +13,7 @@ #include "common.h" /* definition of FLASH */ #include -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 */ {