r3852: port to mac os x which has getopt but not getopt_long
[ctsim.git] / getopt / getopt.c
index 4744e43390ac66c9d46ad35d38460627906c78be..f5632d7ccc420cf99ad48871391a5451d8e91e83 100644 (file)
@@ -28,7 +28,7 @@
 #endif
 
 #ifdef HAVE_CONFIG_H
-# include <config.h>
+//# include <config.h>
 #endif
 
 #if !defined __STDC__ || !__STDC__
    Also, when `ordering' is RETURN_IN_ORDER,
    each non-option ARGV-element is returned here.  */
 
+#if ! defined(HAVE_GETOPT) && ! defined(HAVE_GETOPT_LONG) 
 char *optarg;
+#endif
 
 /* Index in ARGV of the next element to be scanned.
    This is used for communication to and from the caller
@@ -124,13 +126,19 @@ char *optarg;
    how much of ARGV has been scanned so far.  */
 
 /* 1003.2 says this must be 1 before any call.  */
+#if ! defined(HAVE_GETOPT) && ! defined(HAVE_GETOPT_LONG) 
 int optind = 1;
+#endif
 
 /* Formerly, initialization of getopt depended on optind==0, which
    causes problems with re-calling getopt as programs generally don't
    know that. */
 
+#if ! defined(HAVE_GETOPT) && ! defined(HAVE_GETOPT_LONG) 
 int __getopt_initialized;
+#else
+extern int __getopt_initialized;
+#endif
 
 /* The next char to be scanned in the option-element
    in which the last option character we returned was found.
@@ -144,13 +152,17 @@ static char *nextchar;
 /* Callers store zero here to inhibit the error message
    for unrecognized options.  */
 
+#if ! defined(HAVE_GETOPT) && ! defined(HAVE_GETOPT_LONG) 
 int opterr = 1;
+#endif
 
 /* Set to an option character which was unrecognized.
    This must be initialized on some systems to avoid linking in the
    system's own getopt implementation.  */
 
+#if ! defined(HAVE_GETOPT) && ! defined(HAVE_GETOPT_LONG) 
 int optopt = '?';
+#endif
 
 /* Describe how to deal with options that follow non-option ARGV-elements.
 
@@ -968,6 +980,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
   }
 }
 
+#ifndef HAVE_GETOPT
 int
 getopt (argc, argv, optstring)
      int argc;
@@ -979,6 +992,7 @@ getopt (argc, argv, optstring)
                           (int *) 0,
                           0);
 }
+#endif
 
 #endif /* Not ELIDE_CODE.  */
 \f