]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/getopt-min.c
Enable expression evaluation for numeric command line args
[z180-stamp.git] / avr / getopt-min.c
index 571c14f8c6407854172ae352ca23c919c7de79d8..8508f401a725329c5aeb35766efaa06392c43d79 100644 (file)
@@ -1,7 +1,3 @@
-#include "common.h"
-#include <avr/pgmspace.h>
-
-
 /*
  *     Minimum getopt, original version was:
  */
 */
 /* $Id: getopt.c,v 1.2 1992/12/07 11:12:52 nickc Exp $ */
 
-#include       <string.h>
+#include "common.h"            /* definition of FLASH */
+#include <string.h>
 
-int    optind = 1;                     /* next argv[] index */
+int    optind = 0;                     /* next argv[] index */
 char *optarg;          /* option parameter if any */
 
 
@@ -26,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 */
        {
@@ -41,7 +42,7 @@ getopt(                               /* returns letter, '?', EOF */
                   )
                        return -1;
        }
-       
+
        c = argv[optind][sp];           /* option letter */
        osp = sp++;                     /* get ready for next letter */
 
@@ -73,4 +74,3 @@ getopt(                               /* returns letter, '?', EOF */
 
        return c;
 }
-