OSDN Git Service

e5bcbad3111794dc756004eca4677bbf5412904f
[mingw/mingw-get.git] / src / getopt.c
1 /* 
2  * getopt.c
3  *
4  * $Id$
5  *
6  * Implementation of the `getopt', `getopt_long' and `getopt_long_only'
7  * APIs, for inclusion in the MinGW runtime library.
8  *
9  * This file is part of the MinGW32 package set.
10  *
11  * Contributed by Keith Marshall <keithmarshall@users.sourceforge.net>
12  *
13  *
14  * THIS SOFTWARE IS NOT COPYRIGHTED
15  *
16  * This source code is offered for use in the public domain. You may
17  * use, modify or distribute it freely.
18  *
19  * This code is distributed in the hope that it will be useful but
20  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
21  * DISCLAIMED. This includes but is not limited to warranties of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23  *
24  * $Revision$
25  * $Author$
26  * $Date$
27  *
28  */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <getopt.h>
34
35 /* Identify how to get the calling program name, for use in messages...
36  */
37 #ifdef __CYGWIN__
38 /*
39  * CYGWIN uses this DLL reference...
40  */
41 # define PROGNAME  __progname
42 extern char __declspec(dllimport) *__progname;
43 #else
44 /*
45  * ...while elsewhere, we simply use the first argument passed.
46  */
47 # define PROGNAME  *argv
48 #endif
49
50 /* Initialise the public variables. */
51
52 int optind = 1;                         /* index for first non-option arg     */
53 int opterr = 1;                         /* enable built-in error messages     */
54
55 char *optarg = NULL;                    /* pointer to current option argument */
56
57 #define CHAR  char                      /* argument type selector */
58
59 #define getopt_switchar         '-'     /* option prefix character in argv    */
60 #define getopt_pluschar         '+'     /* prefix for POSIX mode in optstring */
61 #define getopt_takes_argument   ':'     /* marker for optarg in optstring     */
62 #define getopt_arg_assign       '='     /* longopt argument field separator   */
63 #define getopt_unknown          '?'     /* return code for unmatched option   */
64 #define getopt_ordered           1      /* return code for ordered non-option */
65
66 #define getopt_all_done         -1      /* return code to indicate completion */
67
68 enum
69 { /* All `getopt' API functions are implemented via calls to the
70    * common static function `getopt_parse()'; these `mode' selectors
71    * determine the behaviour of `getopt_parse()', to deliver the
72    * appropriate result in each case.
73    */
74   getopt_mode_standard = 0,     /* getopt()           */
75   getopt_mode_long,             /* getopt_long()      */
76   getopt_mode_long_only         /* getopt_long_only() */
77 };
78
79 enum
80 { /* When attempting to match a command line argument to a long form option,
81    * these indicate the status of the match.
82    */
83   getopt_no_match = 0,          /* no successful match                       */
84   getopt_abbreviated_match,     /* argument is an abbreviation for an option */
85   getopt_exact_match            /* argument matches the full option name     */
86 };
87
88 int optopt = getopt_unknown;    /* return value for option being evaluated   */
89
90 /* Some BSD applications expect to be able to reinitialise `getopt' parsing
91  * by setting a global variable called `optreset'.  We provide an obfuscated
92  * API, which allows applications to emulate this brain damage; however, any
93  * use of this is non-portable, and is strongly discouraged.
94  */
95 #define optreset  __mingw_optreset
96 int optreset = 0;
97
98 static __inline__
99 int getopt_missing_arg( const CHAR *optstring )
100 {
101   /* Helper function to determine the appropriate return value,
102    * for the case where a required option argument is missing.
103    */
104   if( (*optstring == getopt_pluschar) || (*optstring == getopt_switchar) )
105     ++optstring;
106   return (*optstring == getopt_takes_argument)
107     ? getopt_takes_argument
108     : getopt_unknown;
109 }
110
111 /* `complain' macro facilitates the generation of simple built-in
112  * error messages, displayed on various fault conditions, provided
113  * `opterr' is non-zero.
114  */
115 #define complain( MSG, ARG )  if( opterr ) \
116   fprintf( stderr, "%s: "MSG"\n", PROGNAME, ARG )
117
118 static __inline__
119 int getopt_argerror( int mode, char *fmt, CHAR *prog, struct option *opt, int retval )
120 {
121   /* Helper function, to generate more complex built-in error
122    * messages, for invalid arguments to long form options ...
123    */
124   if( opterr )
125   {
126     /* ... but, displayed only if `opterr' is non-zero.
127      */
128     char flag[] = "--";
129     if( mode != getopt_mode_long )
130       /*
131        * only display one hyphen, for implicit long form options,
132        * improperly resolved by `getopt_long_only()'.
133        */
134       flag[1] = 0;
135     /*
136      * always preface the program name ...
137      */
138     fprintf( stderr, "%s: ", prog );
139     /*
140      * to the appropriate, option specific message.
141      */
142     fprintf( stderr, fmt, flag, opt->name );
143   }
144   /* Whether displaying the message, or not, always set `optopt'
145    * to identify the faulty option ...
146    */
147   optopt = opt->val;
148   /*
149    * and return the `invalid option' indicator.
150    */
151   return retval;
152 }
153
154 /* `getopt_conventions' establish behavioural options, to control
155  * the operation of `getopt_parse()', e.g. to select between POSIX
156  * and GNU style argument parsing behaviour.
157  */
158 #define getopt_set_conventions  0x1000
159 #define getopt_posixly_correct  0x0010
160
161 static __inline__
162 int getopt_conventions( int flags )
163 {
164   static int conventions = 0;
165
166   if( (conventions == 0) && ((flags & getopt_set_conventions) == 0) )
167   {
168     /* default conventions have not yet been established;
169      * initialise them now!
170      */
171     conventions = getopt_set_conventions;
172     if( (flags == getopt_pluschar) || (getenv( "POSIXLY_CORRECT" ) != NULL) )
173       conventions |= getopt_posixly_correct;
174   }
175
176   else if( flags & getopt_set_conventions )
177     /*
178      * default conventions may have already been established,
179      * but this is a specific request to augment them.
180      */
181     conventions |= flags;
182
183   /* in any event, return the currently established conventions.
184    */
185   return conventions;
186 }
187
188 static __inline__
189 int is_switchar( CHAR flag )
190 {
191   /* A simple helper function, used to identify the switch character
192    * introducing an optional command line argument.
193    */
194   return flag == getopt_switchar;
195 }
196
197 static __inline__
198 const CHAR *getopt_match( CHAR lookup, const CHAR *opt_string )
199 {
200   /* Helper function, used to identify short form options.
201    */
202   if( (*opt_string == getopt_pluschar) || (*opt_string == getopt_switchar) )
203     ++opt_string;
204   if( *opt_string == getopt_takes_argument )
205     ++opt_string;
206   do if( lookup == *opt_string ) return opt_string;
207      while( *++opt_string );
208   return NULL;
209 }
210
211 static __inline__
212 int getopt_match_long( const CHAR *nextchar, const CHAR *optname )
213 {
214   /* Helper function, used to identify potential matches for
215    * long form options.
216    */
217   CHAR matchchar;
218   while( (matchchar = *nextchar++) && (matchchar == *optname) )
219     /*
220      * skip over initial substring which DOES match.
221      */
222     ++optname;
223
224   if( matchchar )
225   {
226     /* did NOT match the entire argument to an initial substring
227      * of a defined option name ...
228      */
229     if( matchchar != getopt_arg_assign )
230       /*
231        * ... and didn't stop at an `=' internal field separator,
232        * so this is NOT a possible match.
233        */
234       return getopt_no_match;
235
236     /* DID stop at an `=' internal field separator,
237      * so this IS a possible match, and what follows is an
238      * argument to the possibly matched option.
239      */
240     optarg = (char *)(nextchar);
241   }
242   return *optname
243     /*
244      * if we DIDN'T match the ENTIRE text of the option name,
245      * then it's a possible abbreviated match ...
246      */
247     ? getopt_abbreviated_match
248     /*
249      * but if we DID match the entire option name,
250      * then it's a DEFINITE EXACT match.
251      */
252     : getopt_exact_match;
253 }
254
255 static __inline__
256 int getopt_resolved( int mode, int argc, CHAR *const *argv, int *argind,
257 struct option *opt, int index, int *retindex, const CHAR *optstring )
258 {
259   /* Helper function to establish appropriate return conditions,
260    * on resolution of a long form option.
261    */
262   if( retindex != NULL )
263     *retindex = index;
264
265   /* On return, `optind' should normally refer to the argument, if any,
266    * which follows the current one; it is convenient to set this, before
267    * checking for the presence of any `optarg'.
268    */
269   optind = *argind + 1;
270
271   if( optarg && (opt[index].has_arg == no_argument) )
272     /*
273      * it is an error for the user to specify an option specific argument
274      * with an option which doesn't expect one!
275      */
276     return getopt_argerror( mode, "option `%s%s' doesn't accept an argument\n",
277         PROGNAME, opt + index, getopt_unknown );
278
279   else if( (optarg == NULL) && (opt[index].has_arg == required_argument) )
280   {
281     /* similarly, it is an error if no argument is specified
282      * with an option which requires one ...
283      */
284     if( optind < argc )
285       /*
286        * ... except that the requirement may be satisfied from
287        * the following command line argument, if any ...
288        */
289       optarg = argv[*argind = optind++];
290
291     else
292       /* so fail this case, only if no such argument exists!
293        */
294       return getopt_argerror( mode, "option `%s%s' requires an argument\n",
295           PROGNAME, opt + index, getopt_missing_arg( optstring ) );
296   }
297
298   /* when the caller has provided a return buffer ...
299    */
300   if( opt[index].flag != NULL )
301   {
302     /* ... then we place the proper return value there,
303      * and return a status code of zero ...
304      */
305     *(opt[index].flag) = opt[index].val;
306     return 0;
307   }
308   /* ... otherwise, the return value becomes the status code.
309    */
310   return opt[index].val;
311 }
312
313 static __inline__
314 int getopt_verify( const CHAR *nextchar, const CHAR *optstring )
315 {
316   /* Helper function, called by getopt_parse() when invoked
317    * by getopt_long_only(), to verify when an unmatched or an
318    * ambiguously matched long form option string is valid as
319    * a short form option specification.
320    */
321   if( ! (nextchar && *nextchar && optstring && *optstring) )
322     /*
323      * There are no characters to be matched, or there are no
324      * valid short form option characters to which they can be
325      * matched, so this can never be valid.
326      */
327     return 0;
328
329   while( *nextchar )
330   {
331     /* For each command line character in turn ...
332      */
333     const CHAR *test;
334     if( (test = getopt_match( *nextchar++, optstring )) == NULL )
335       /*
336        * ... there is no short form option to match the current
337        * candidate, so the entire argument fails.
338        */
339       return 0;
340
341     if( test[1] == getopt_takes_argument )
342       /*
343        * The current candidate is valid, and it matches an option
344        * which takes an argument, so this command line argument is
345        * a valid short form option specification; accept it.
346        */
347       return 1;
348   }
349   /* If we get to here, then every character in the command line
350    * argument was valid as a short form option; accept it.
351    */
352   return 1;
353 }
354
355 static
356 #define getopt_std_args int argc, CHAR *const argv[], const CHAR *optstring
357 int getopt_parse( int mode, getopt_std_args, ... )
358 {
359   /* Common core implementation for ALL `getopt' functions.
360    */
361   static int argind = 0;
362   static int optbase = 0;
363   static const CHAR *nextchar = NULL;
364   static int optmark = 0;
365
366   if( (optreset |= (optind < 1)) || (optind < optbase) )
367   {
368     /* POSIX does not prescribe any definitive mechanism for restarting
369      * a `getopt' scan, but some applications may require such capability.
370      * We will support it, by allowing the caller to adjust the value of
371      * `optind' downwards, (nominally setting it to zero).  Since POSIX
372      * wants `optind' to have an initial value of one, but we want all
373      * of our internal place holders to be initialised to zero, when we
374      * are called for the first time, we will handle such a reset by
375      * adjusting all of the internal place holders to one less than
376      * the adjusted `optind' value, (but never to less than zero).
377      */
378     if( optreset )
379     {
380       /* User has explicitly requested reinitialisation...
381        * We need to reset `optind' to it's normal initial value of 1,
382        * to avoid a potential infinitely recursive loop; by doing this
383        * up front, we also ensure that the remaining place holders
384        * will be correctly reinitialised to no less than zero.
385        */
386       optind = 1;
387
388       /* We also need to clear the `optreset' request...
389        */
390       optreset = 0;
391     }
392
393     /* Now, we may safely reinitialise the internal place holders, to
394      * one less than `optind', without fear of making them negative.
395      */
396     optmark = optbase = argind = optind - 1;
397     nextchar = NULL;
398   }
399   
400   /* From a POSIX perspective, the following is `undefined behaviour';
401    * we implement it thus, for compatibility with GNU and BSD getopt.
402    */
403   else if( optind > (argind + 1) )
404   {
405     /* Some applications expect to be able to manipulate `optind',
406      * causing `getopt' to skip over one or more elements of `argv';
407      * POSIX doesn't require us to support this brain-damaged concept;
408      * (indeed, POSIX defines no particular behaviour, in the event of
409      *  such usage, so it must be considered a bug for an application
410      *  to rely on any particular outcome); nonetheless, Mac-OS-X and
411      * BSD actually provide *documented* support for this capability,
412      * so we ensure that our internal place holders keep track of
413      * external `optind' increments; (`argind' must lag by one).
414      */
415     argind = optind - 1;
416
417     /* When `optind' is misused, in this fashion, we also abandon any
418      * residual text in the argument we had been parsing; this is done
419      * without any further processing of such abandoned text, assuming
420      * that the caller is equipped to handle it appropriately.
421      */
422     nextchar = NULL;
423   }
424
425   if( nextchar && *nextchar )
426   {
427     /* we are parsing a standard, or short format, option argument ...
428      */
429     const CHAR *optchar;
430     if( (optchar = getopt_match( optopt = *nextchar++, optstring )) != NULL )
431     {
432       /* we have identified it as valid ...
433        */
434       if( optchar[1] == getopt_takes_argument )
435       {
436         /* and determined that it requires an associated argument ...
437          */
438         if( ! *(optarg = (char *)(nextchar)) )
439         {
440           /* the argument is NOT attached ...
441            */
442           if( optchar[2] == getopt_takes_argument )
443             /*
444              * but this GNU extension marks it as optional,
445              * so we don't provide one on this occasion.
446              */
447             optarg = NULL;
448
449           /* otherwise this option takes a mandatory argument,
450            * so, provided there is one available ...
451            */
452           else if( (argc - argind) > 1 )
453             /*
454              * we take the following command line argument,
455              * as the appropriate option argument.
456              */
457             optarg = argv[++argind];
458
459           /* but if no further argument is available,
460            * then there is nothing we can do, except for
461            * issuing the requisite diagnostic message.
462            */
463           else
464           {
465             complain( "option requires an argument -- %c", optopt );
466             return getopt_missing_arg( optstring );
467           }
468         }
469         optind = argind + 1;
470         nextchar = NULL;
471       }
472       else
473         optarg = NULL;
474       optind = (nextchar && *nextchar) ? argind : argind + 1;
475       return optopt;
476     }
477     /* if we didn't find a valid match for the specified option character,
478      * then we fall through to here, so take appropriate diagnostic action.
479      */
480     if( mode == getopt_mode_long_only )
481     {
482       complain( "unrecognised option `-%s'", --nextchar );
483       nextchar = NULL;
484       optopt = 0;
485     }
486     else
487       complain( "invalid option -- %c", optopt );
488     optind = (nextchar && *nextchar) ? argind : argind + 1;
489     return getopt_unknown;
490   }
491
492   if( optmark > optbase )
493   {
494     /* This can happen, in GNU parsing mode ONLY, when we have
495      * skipped over non-option arguments, and found a subsequent
496      * option argument; in this case we permute the arguments.
497      */
498     int index;
499     /*
500      * `optspan' specifies the number of contiguous arguments
501      * which are spanned by the current option, and so must be
502      * moved together during permutation.
503      */
504     int optspan = argind - optmark + 1;
505     /*
506      * we use `this_arg' to store these temporarily.
507      */
508     CHAR *this_arg[optspan];
509     /*
510      * we cannot manipulate `argv' directly, since the `getopt'
511      * API prototypes it as `read-only'; this cast to `arglist'
512      * allows us to work around that restriction.
513      */
514     CHAR **arglist = (char **)(argv);
515
516     /* save temporary copies of the arguments which are associated
517      * with the current option ...
518      */
519     for( index = 0; index < optspan; ++index )
520       this_arg[index] = arglist[optmark + index];
521
522     /* move all preceding non-option arguments to the right,
523      * overwriting these saved arguments, while making space
524      * to replace them in their permuted location.
525      */
526     for( --optmark; optmark >= optbase; --optmark )
527       arglist[optmark + optspan] = arglist[optmark];
528
529     /* restore the temporarily saved option arguments to
530      * their permuted location.
531      */
532     for( index = 0; index < optspan; ++index )
533       arglist[optbase + index] = this_arg[index];
534
535     /* adjust `optbase', to account for the relocated option.
536      */
537     optbase += optspan;
538   }
539
540   else
541     /* no permutation occurred ...
542      * simply adjust `optbase' for all options parsed so far.
543      */
544     optbase = argind + 1;
545
546   /* enter main parsing loop ...
547    */
548   while( argc > ++argind )
549   {
550     /* inspect each argument in turn, identifying possible options ...
551      */
552     if( is_switchar( *(nextchar = argv[optmark = argind]) ) && *++nextchar )
553     {
554       /* we've found a candidate option argument ... */
555
556       if( is_switchar( *nextchar ) )
557       {
558         /* it's a double hyphen argument ... */
559
560         const CHAR *refchar = nextchar;
561         if( *++refchar )
562         {
563           /* and it looks like a long format option ...
564            * `getopt_long' mode must be active to accept it as such,
565            * `getopt_long_only' also qualifies, but we must downgrade
566            * it to force explicit handling as a long format option.
567            */
568           if( mode >= getopt_mode_long )
569           {
570             nextchar = refchar;
571             mode = getopt_mode_long;
572           }
573         }
574         else
575         {
576           /* this is an explicit `--' end of options marker, so wrap up now!
577            */
578           if( optmark > optbase )
579           {
580             /* permuting the argument list as necessary ...
581              * (note use of `this_arg' and `arglist', as above).
582              */
583             CHAR *this_arg = argv[optmark];
584             CHAR **arglist = (CHAR **)(argv);
585
586             /* move all preceding non-option arguments to the right ...
587              */
588             do arglist[optmark] = arglist[optmark - 1];
589                while( optmark-- > optbase );
590
591             /* reinstate the `--' marker, in its permuted location.
592              */
593             arglist[optbase] = this_arg;
594           }
595           /* ... before finally bumping `optbase' past the `--' marker,
596            * and returning the `all done' completion indicator.
597            */
598           optind = ++optbase;
599           return getopt_all_done;
600         }
601       }
602       else if( mode < getopt_mode_long_only )
603       {
604         /* it's not an explicit long option, and `getopt_long_only' isn't active,
605          * so we must explicitly try to match it as a short option.
606          */
607         mode = getopt_mode_standard;
608       }
609
610       if( mode >= getopt_mode_long )
611       {
612         /* the current argument is a long form option, (either explicitly,
613          * introduced by a double hyphen, or implicitly because we were called
614          * by `getopt_long_only'); this is where we parse it.
615          */
616         int lookup;
617         int matched = -1;
618
619         /* we need to fetch the `extra' function arguments, which are
620          * specified for the `getopt_long' APIs.
621          */
622         va_list refptr;
623         va_start( refptr, optstring );
624         struct option *longopts = va_arg( refptr, struct option * );
625         int *optindex = va_arg( refptr, int * );
626         va_end( refptr );
627
628         /* ensuring that `optarg' does not inherit any junk, from parsing
629          * preceding arguments ...
630          */
631         optarg = NULL;
632         for( lookup = 0; longopts && longopts[lookup].name; ++lookup )
633         {
634           /* scan the list of defined long form options ...
635            */
636           switch( getopt_match_long( nextchar, longopts[lookup].name ) )
637           {
638             /* looking for possible matches for the current argument.
639              */
640             case getopt_exact_match:
641               /*
642                * when an exact match is found,
643                * return it immediately, setting `nextchar' to NULL,
644                * to ensure we don't mistakenly try to match any
645                * subsequent characters as short form options.
646                */
647               nextchar = NULL;
648               return getopt_resolved( mode, argc, argv, &argind,
649                   longopts, lookup, optindex, optstring );
650
651             case getopt_abbreviated_match:
652               /*
653                * but, for a partial (initial substring) match ...
654                */
655               if( matched >= 0 )
656               {
657                 /* if this is not the first, then we have an ambiguity ...
658                  */
659                 if( (mode == getopt_mode_long_only)
660                   /*
661                    * However, in the case of getopt_long_only(), if
662                    * the entire ambiguously matched string represents
663                    * a valid short option specification, then we may
664                    * proceed to interpret it as such.
665                    */
666                 &&  getopt_verify( nextchar, optstring )  )
667                   return getopt_parse( mode, argc, argv, optstring );
668
669                 /* If we get to here, then the ambiguously matched
670                  * partial long option isn't valid for short option
671                  * evaluation; reset parser context to resume with
672                  * the following command line argument, diagnose
673                  * ambiguity, and bail out.
674                  */
675                 optopt = 0;
676                 nextchar = NULL;
677                 optind = argind + 1;
678                 complain( "option `%s' is ambiguous", argv[argind] );
679                 return getopt_unknown;
680               }
681               /* otherwise just note that we've found a possible match ...
682                */
683               matched = lookup;
684           }
685         }
686         if( matched >= 0 )
687         {
688           /* if we get to here, then we found exactly one partial match,
689            * so return it, as for an exact match.
690            */
691           nextchar = NULL;
692           return getopt_resolved( mode, argc, argv, &argind,
693               longopts, matched, optindex, optstring );
694         }
695         /* if here, then we had what SHOULD have been a long form option,
696          * but it is unmatched ...
697          */
698         if( (mode < getopt_mode_long_only)
699           /*
700            * ... although paradoxically, `mode == getopt_mode_long_only'
701            * allows us to still try to match it as a short form option.
702            */
703         ||  (getopt_verify( nextchar, optstring ) == 0)  )
704         {
705           /* When it cannot be matched, reset the parsing context to
706            * resume from the next argument, diagnose the failed match,
707            * and bail out.
708            */
709           optopt = 0;
710           nextchar = NULL;
711           optind = argind + 1;
712           complain( "unrecognised option `%s'", argv[argind] );
713           return getopt_unknown;
714         }
715       }
716       /* fall through to handle standard short form options...
717        * when the option argument format is neither explictly identified
718        * as long, nor implicitly matched as such, and the argument isn't
719        * just a bare hyphen, (which isn't an option), then we make one
720        * recursive call to explicitly interpret it as short format.
721        */
722       if( *nextchar )
723         return getopt_parse( mode, argc, argv, optstring );
724     }
725     /* if we get to here, then we've parsed a non-option argument ...
726      * in GNU compatibility mode, we step over it, so we can permute
727      * any subsequent option arguments, but ...
728      */
729     if( *optstring == getopt_switchar )
730     {
731       /* if `optstring' begins with a `-' character, this special
732        * GNU specific behaviour requires us to return the non-option
733        * arguments in strict order, as pseudo-arguments to a special
734        * option, with return value defined as `getopt_ordered'.
735        */
736       nextchar = NULL;
737       optind = argind + 1;
738       optarg = argv[argind];
739       return getopt_ordered;
740     }
741     if( getopt_conventions( *optstring ) & getopt_posixly_correct )
742       /*
743        * otherwise ...
744        * for POSIXLY_CORRECT behaviour, or if `optstring' begins with
745        * a `+' character, then we break out of the parsing loop, so that
746        * the scan ends at the current argument, with no permutation.
747        */
748       break;
749   }
750   /* fall through when all arguments have been evaluated,
751    */
752   optind = optbase;
753   return getopt_all_done;
754 }
755
756 /* All three public API entry points are trivially defined,
757  * in terms of the internal `getopt_parse' function.
758  */
759 int getopt( getopt_std_args )
760 {
761   return getopt_parse( getopt_mode_standard, argc, argv, optstring );
762 }
763
764 int getopt_long( getopt_std_args, const struct option *opts, int *index )
765 {
766   return getopt_parse( getopt_mode_long, argc, argv, optstring, opts, index );
767 }
768
769 int getopt_long_only( getopt_std_args, const struct option *opts, int *index )
770 {
771   return getopt_parse( getopt_mode_long_only, argc, argv, optstring, opts, index );
772 }
773
774 #ifdef __weak_alias
775 /*
776  * These Microsnot style uglified aliases are provided for compatibility
777  * with the previous MinGW implementation of the getopt API.
778  */
779 __weak_alias( getopt, _getopt )
780 __weak_alias( getopt_long, _getopt_long )
781 __weak_alias( getopt_long_only, _getopt_long_only )
782 #endif
783
784 /* $RCSfile$Revision: 1.9 $: end of file */