Diff of /repl/getopt.c [bfb799] .. [416990]  Maximize  Restore

Switch to side-by-side view

--- a/repl/getopt.c
+++ b/repl/getopt.c
@@ -9,7 +9,7 @@
  * This file is part of the MinGW32 package set.
  *
  * Contributed by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Last modification: 27-Dec-2007
+ * Last modification: 11-Jan-2008
  *
  * THIS SOFTWARE IS NOT COPYRIGHTED
  *
@@ -49,7 +49,7 @@
 
 /* Initialise the public variables. */
 
-int optind = 0;				/* index for first non-option arg     */
+int optind = 1;				/* index for first non-option arg     */
 int opterr = 1;				/* enable built-in error messages     */
 
 char *optarg = NULL;			/* pointer to current option argument */
@@ -305,6 +305,19 @@
   static int argind = 0;
   static const CHAR *nextchar = NULL;
   static int optmark = 0;
+
+  if( (argind == 0) || (optind == 0) )
+  {
+    /* POSIX wants `optind' to have an initial value of one, but we want
+     * it to be initialised to zero, when we are called for the first time,
+     * (as indicated by `argind' having a value of zero).  We also want to
+     * allow the caller to reset the `getopt' parser, causing it to scan
+     * the arguments again, (or to scan a new set of arguments); this
+     * may be achieved by the caller resetting `optind' to zero.
+     */
+    optmark = optind = argind = 0;
+    nextchar = NULL;
+  }
 
   if( nextchar && *nextchar )
   {
@@ -633,4 +646,4 @@
 __weak_alias( getopt_long_only, _getopt_long_only )
 #endif
 
-/* $RCSfile$Revision$: end of file */
+/* $RCSfile$Revision: 1.1 $: end of file */

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks