]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/getopt-min.c
clean up includes
[z180-stamp.git] / avr / getopt-min.c
index f5ad912f281e1a73085160f6282e9754e04d1bea..4e67a9b4d0712a4c5e5a1d1a03318cc5ad65bf3b 100644 (file)
@@ -11,9 +11,8 @@
 /* $Id: getopt.c,v 1.2 1992/12/07 11:12:52 nickc Exp $ */
 
 #include "common.h"            /* definition of FLASH */
-#include <string.h>
 
-int    optind = 1;                     /* next argv[] index */
+int    optind;                 /* next argv[] index */
 char *optarg;          /* option parameter if any */
 
 
@@ -23,12 +22,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 */
        {