This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: getopt_long


2005/11/28, Shaun Jackman <sjackman@gmail.com>:
> Thanks, Greg!
>
> I haven't tried it out yet, but on the theory that `something's almost
> certainly better than nothing', I'd be all for checking this in and
> debugging it through many public eyes.
>
> I'll give it a go tomorrow days.

I still haven't had a chance to run it. The embedded system I want to
use this is in a state of disarray at the moment. However, it compiles
nicely in newlib -- using the current getopt.h even -- with this
slight modification.

Cheers,
Shaun

--- libc/stdlib/getopt.c.orig	2005-11-29 14:18:47.000000000 -0700
+++ libc/stdlib/getopt.c	2005-11-29 14:26:47.000000000 -0700
@@ -30,8 +30,8 @@
  --arg value

  It takes the additional arguments longopts which is a pointer to the first
-element of an array of type GETOPT_LONG_OPTION_T.  The last element of the
-array has to be filled with NULL for the name field.
+element of an array of type struct option.  The last element of the array
+has to be filled with NULL for the name field.

  The longind pointer points to the index of the current long option relative
  to longopts if it is non-NULL.
@@ -143,8 +143,8 @@

 /* getopt_internal:  the function that does all the dirty work */
 static int
-getopt_internal (int argc, char **argv, char *shortopts,
-                 GETOPT_LONG_OPTION_T * longopts, int *longind, int only)
+getopt_internal (int argc, char **argv, const char *shortopts,
+                 struct option *longopts, int *longind, int only)
 {
   GETOPT_ORDERING_T ordering = PERMUTE;
   static size_t optwhere = 0;
@@ -157,6 +157,7 @@
   int has_arg = -1;
   char *cp;
   int arg_next = 0;
+  enum { NO_ARG, REQUIRED_ARG, OPTIONAL_ARG };

   /* first, deal with silly parameters and easy stuff */
   if (argc == 0 || argv == NULL || (shortopts == NULL && longopts == NULL))
@@ -386,21 +387,21 @@
 }

 int
-getopt (int argc, char **argv, char *optstring)
+getopt (int argc, char *const argv[], const char *optstring)
 {
   return getopt_internal (argc, argv, optstring, NULL, NULL, 0);
 }

 int
-getopt_long (int argc, char **argv, char *shortopts,
-             GETOPT_LONG_OPTION_T * longopts, int *longind)
+getopt_long (int argc, char *const argv[], const char *shortopts,
+             const struct option *longopts, int *longind)
 {
   return getopt_internal (argc, argv, shortopts, longopts, longind, 0);
 }

 int
-getopt_long_only (int argc, char **argv, char *shortopts,
-                  GETOPT_LONG_OPTION_T * longopts, int *longind)
+getopt_long_only (int argc, char *const argv[], const char *shortopts,
+                  const struct option *longopts, int *longind)
 {
   return getopt_internal (argc, argv, shortopts, longopts, longind, 1);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]