Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/dtoolutil/gnu_getopt.c

Go to the documentation of this file.
00001 /* Getopt for GNU.
00002    NOTE: getopt is now part of the C library, so if you don't know what
00003    "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
00004    before changing it!
00005 
00006    Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94
00007         Free Software Foundation, Inc.
00008 
00009    This program is free software; you can redistribute it and/or modify it
00010    under the terms of the GNU General Public License as published by the
00011    Free Software Foundation; either version 2, or (at your option) any
00012    later version.
00013 
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.  */
00018 
00019 
00020 #include <dtoolbase.h>
00021 
00022 #if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_LONG_ONLY)
00023 
00024 #ifdef WIN32_VC
00025 /* This file seems particularly egregious with this particular warning,
00026    but it's not clear why.  Disable. */
00027 /* C4028: formal parameter N different from declaration */
00028 #pragma warning (disable : 4028)
00029 #endif
00030 
00031 /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
00032    Ditto for AIX 3.2 and <stdlib.h>.  */
00033 #ifndef _NO_PROTO
00034 #define _NO_PROTO
00035 #endif
00036 
00037 #ifndef __STDC__
00038 /* This is a separate conditional since some stdc systems
00039    reject `defined (const)'.  */
00040 #ifndef const
00041 #define const
00042 #endif
00043 #endif
00044 
00045 #include <stdio.h>
00046 #include <string.h>
00047 
00048 /* Comment out all this code if we are using the GNU C Library, and are not
00049    actually compiling the library itself.  This code is part of the GNU C
00050    Library, but also included in many other GNU distributions.  Compiling
00051    and linking in this code is a waste when using the GNU C library
00052    (especially if it is a shared library).  Rather than having every GNU
00053    program understand `configure --with-gnu-libc' and omit the object files,
00054    it is simpler to just do this in the source for each such file.  */
00055 
00056 #if defined (_LIBC) || !defined (__GNU_LIBRARY__)
00057 
00058 
00059 /* This needs to come after some library #include
00060    to get __GNU_LIBRARY__ defined.  */
00061 #ifdef  __GNU_LIBRARY__
00062 /* Don't include stdlib.h for non-GNU C libraries because some of them
00063    contain conflicting prototypes for getopt.  */
00064 #include <stdlib.h>
00065 #endif  /* GNU C library.  */
00066 
00067 /* This version of `getopt' appears to the caller like standard Unix `getopt'
00068    but it behaves differently for the user, since it allows the user
00069    to intersperse the options with the other arguments.
00070 
00071    As `getopt' works, it permutes the elements of ARGV so that,
00072    when it is done, all the options precede everything else.  Thus
00073    all application programs are extended to handle flexible argument order.
00074 
00075    Setting the environment variable POSIXLY_CORRECT disables permutation.
00076    Then the behavior is completely standard.
00077 
00078    GNU application programs can use a third alternative mode in which
00079    they can distinguish the relative order of options and other arguments.  */
00080 
00081 #include "gnu_getopt.h"
00082 
00083 /* For communication from `getopt' to the caller.
00084    When `getopt' finds an option that takes an argument,
00085    the argument value is returned here.
00086    Also, when `ordering' is RETURN_IN_ORDER,
00087    each non-option ARGV-element is returned here.  */
00088 
00089 char *optarg = NULL;
00090 
00091 /* Index in ARGV of the next element to be scanned.
00092    This is used for communication to and from the caller
00093    and for communication between successive calls to `getopt'.
00094 
00095    On entry to `getopt', zero means this is the first call; initialize.
00096 
00097    When `getopt' returns EOF, this is the index of the first of the
00098    non-option elements that the caller should itself scan.
00099 
00100    Otherwise, `optind' communicates from one call to the next
00101    how much of ARGV has been scanned so far.  */
00102 
00103 /* XXX 1003.2 says this must be 1 before any call.  */
00104 int optind = 0;
00105 
00106 /* The next char to be scanned in the option-element
00107    in which the last option character we returned was found.
00108    This allows us to pick up the scan where we left off.
00109 
00110    If this is zero, or a null string, it means resume the scan
00111    by advancing to the next ARGV-element.  */
00112 
00113 static char *nextchar;
00114 
00115 /* Callers store zero here to inhibit the error message
00116    for unrecognized options.  */
00117 
00118 int opterr = 1;
00119 
00120 /* Set to an option character which was unrecognized.
00121    This must be initialized on some systems to avoid linking in the
00122    system's own getopt implementation.  */
00123 
00124 int optopt = '?';
00125 
00126 /* Describe how to deal with options that follow non-option ARGV-elements.
00127 
00128    If the caller did not specify anything,
00129    the default is REQUIRE_ORDER if the environment variable
00130    POSIXLY_CORRECT is defined, PERMUTE otherwise.
00131 
00132    REQUIRE_ORDER means don't recognize them as options;
00133    stop option processing when the first non-option is seen.
00134    This is what Unix does.
00135    This mode of operation is selected by either setting the environment
00136    variable POSIXLY_CORRECT, or using `+' as the first character
00137    of the list of option characters.
00138 
00139    PERMUTE is the default.  We permute the contents of ARGV as we scan,
00140    so that eventually all the non-options are at the end.  This allows options
00141    to be given in any order, even with programs that were not written to
00142    expect this.
00143 
00144    RETURN_IN_ORDER is an option available to programs that were written
00145    to expect options and other ARGV-elements in any order and that care about
00146    the ordering of the two.  We describe each non-option ARGV-element
00147    as if it were the argument of an option with character code 1.
00148    Using `-' as the first character of the list of option characters
00149    selects this mode of operation.
00150 
00151    The special argument `--' forces an end of option-scanning regardless
00152    of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
00153    `--' can cause `getopt' to return EOF with `optind' != ARGC.  */
00154 
00155 static enum
00156 {
00157   REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
00158 } ordering;
00159 
00160 /* Value of POSIXLY_CORRECT environment variable.  */
00161 static char *posixly_correct;
00162 
00163 #ifdef  __GNU_LIBRARY__
00164 /* We want to avoid inclusion of string.h with non-GNU libraries
00165    because there are many ways it can cause trouble.
00166    On some systems, it contains special magic macros that don't work
00167    in GCC.  */
00168 #include <string.h>
00169 #define my_index        strchr
00170 #else
00171 
00172 /* Avoid depending on library functions or files
00173    whose names are inconsistent.  */
00174 
00175 char *getenv ();
00176 
00177 static char *
00178 my_index (str, chr)
00179      const char *str;
00180      int chr;
00181 {
00182   while (*str)
00183     {
00184       if (*str == chr)
00185         return (char *) str;
00186       str++;
00187     }
00188   return 0;
00189 }
00190 
00191 /* If using GCC, we can safely declare strlen this way.
00192    If not using GCC, it is ok not to declare it.  */
00193 #ifdef __GNUC__
00194 /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
00195    That was relevant to code that was here before.  */
00196 #ifndef __STDC__
00197 /* gcc with -traditional declares the built-in strlen to return int,
00198    and has done so at least since version 2.4.5. -- rms.  */
00199 extern int strlen (const char *);
00200 #endif /* not __STDC__ */
00201 #endif /* __GNUC__ */
00202 
00203 #endif /* not __GNU_LIBRARY__ */
00204 
00205 /* Handle permutation of arguments.  */
00206 
00207 /* Describe the part of ARGV that contains non-options that have
00208    been skipped.  `first_nonopt' is the index in ARGV of the first of them;
00209    `last_nonopt' is the index after the last of them.  */
00210 
00211 static int first_nonopt;
00212 static int last_nonopt;
00213 
00214 /* Exchange two adjacent subsequences of ARGV.
00215    One subsequence is elements [first_nonopt,last_nonopt)
00216    which contains all the non-options that have been skipped so far.
00217    The other is elements [last_nonopt,optind), which contains all
00218    the options processed since those non-options were skipped.
00219 
00220    `first_nonopt' and `last_nonopt' are relocated so that they describe
00221    the new indices of the non-options in ARGV after they are moved.  */
00222 
00223 static void
00224 exchange (argv)
00225      char **argv;
00226 {
00227   int bottom = first_nonopt;
00228   int middle = last_nonopt;
00229   int top = optind;
00230   char *tem;
00231 
00232   /* Exchange the shorter segment with the far end of the longer segment.
00233      That puts the shorter segment into the right place.
00234      It leaves the longer segment in the right place overall,
00235      but it consists of two parts that need to be swapped next.  */
00236 
00237   while (top > middle && middle > bottom)
00238     {
00239       if (top - middle > middle - bottom)
00240         {
00241           /* Bottom segment is the short one.  */
00242           int len = middle - bottom;
00243           register int i;
00244 
00245           /* Swap it with the top part of the top segment.  */
00246           for (i = 0; i < len; i++)
00247             {
00248               tem = argv[bottom + i];
00249               argv[bottom + i] = argv[top - (middle - bottom) + i];
00250               argv[top - (middle - bottom) + i] = tem;
00251             }
00252           /* Exclude the moved bottom segment from further swapping.  */
00253           top -= len;
00254         }
00255       else
00256         {
00257           /* Top segment is the short one.  */
00258           int len = top - middle;
00259           register int i;
00260 
00261           /* Swap it with the bottom part of the bottom segment.  */
00262           for (i = 0; i < len; i++)
00263             {
00264               tem = argv[bottom + i];
00265               argv[bottom + i] = argv[middle + i];
00266               argv[middle + i] = tem;
00267             }
00268           /* Exclude the moved top segment from further swapping.  */
00269           bottom += len;
00270         }
00271     }
00272 
00273   /* Update records for the slots the non-options now occupy.  */
00274 
00275   first_nonopt += (optind - last_nonopt);
00276   last_nonopt = optind;
00277 }
00278 
00279 /* Initialize the internal data when the first call is made.  */
00280 
00281 static const char *
00282 _getopt_initialize (optstring)
00283      const char *optstring;
00284 {
00285   /* Start processing options with ARGV-element 1 (since ARGV-element 0
00286      is the program name); the sequence of previously skipped
00287      non-option ARGV-elements is empty.  */
00288 
00289   first_nonopt = last_nonopt = optind = 1;
00290 
00291   nextchar = NULL;
00292 
00293   posixly_correct = getenv ("POSIXLY_CORRECT");
00294 
00295   /* Determine how to handle the ordering of options and nonoptions.  */
00296 
00297   if (optstring[0] == '-')
00298     {
00299       ordering = RETURN_IN_ORDER;
00300       ++optstring;
00301     }
00302   else if (optstring[0] == '+')
00303     {
00304       ordering = REQUIRE_ORDER;
00305       ++optstring;
00306     }
00307   else if (posixly_correct != NULL)
00308     ordering = REQUIRE_ORDER;
00309   else
00310     ordering = PERMUTE;
00311 
00312   return optstring;
00313 }
00314 
00315 /* Scan elements of ARGV (whose length is ARGC) for option characters
00316    given in OPTSTRING.
00317 
00318    If an element of ARGV starts with '-', and is not exactly "-" or "--",
00319    then it is an option element.  The characters of this element
00320    (aside from the initial '-') are option characters.  If `getopt'
00321    is called repeatedly, it returns successively each of the option characters
00322    from each of the option elements.
00323 
00324    If `getopt' finds another option character, it returns that character,
00325    updating `optind' and `nextchar' so that the next call to `getopt' can
00326    resume the scan with the following option character or ARGV-element.
00327 
00328    If there are no more option characters, `getopt' returns `EOF'.
00329    Then `optind' is the index in ARGV of the first ARGV-element
00330    that is not an option.  (The ARGV-elements have been permuted
00331    so that those that are not options now come last.)
00332 
00333    OPTSTRING is a string containing the legitimate option characters.
00334    If an option character is seen that is not listed in OPTSTRING,
00335    return '?' after printing an error message.  If you set `opterr' to
00336    zero, the error message is suppressed but we still return '?'.
00337 
00338    If a char in OPTSTRING is followed by a colon, that means it wants an arg,
00339    so the following text in the same ARGV-element, or the text of the following
00340    ARGV-element, is returned in `optarg'.  Two colons mean an option that
00341    wants an optional arg; if there is text in the current ARGV-element,
00342    it is returned in `optarg', otherwise `optarg' is set to zero.
00343 
00344    If OPTSTRING starts with `-' or `+', it requests different methods of
00345    handling the non-option ARGV-elements.
00346    See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
00347 
00348    Long-named options begin with `--' instead of `-'.
00349    Their names may be abbreviated as long as the abbreviation is unique
00350    or is an exact match for some defined option.  If they have an
00351    argument, it follows the option name in the same ARGV-element, separated
00352    from the option name by a `=', or else the in next ARGV-element.
00353    When `getopt' finds a long-named option, it returns 0 if that option's
00354    `flag' field is nonzero, the value of the option's `val' field
00355    if the `flag' field is zero.
00356 
00357    The elements of ARGV aren't really const, because we permute them.
00358    But we pretend they're const in the prototype to be compatible
00359    with other systems.
00360 
00361    LONGOPTS is a vector of `struct option' terminated by an
00362    element containing a name which is zero.
00363 
00364    LONGIND returns the index in LONGOPT of the long-named option found.
00365    It is only valid when a long-named option has been found by the most
00366    recent call.
00367 
00368    If LONG_ONLY is nonzero, '-' as well as '--' can introduce
00369    long-named options.  */
00370 
00371 int
00372 _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
00373      int argc;
00374      char *const *argv;
00375      const char *optstring;
00376      const struct option *longopts;
00377      int *longind;
00378      int long_only;
00379 {
00380   optarg = NULL;
00381 
00382   if (optind == 0)
00383     optstring = _getopt_initialize (optstring);
00384 
00385   if (nextchar == NULL || *nextchar == '\0')
00386     {
00387       /* Advance to the next ARGV-element.  */
00388 
00389       if (ordering == PERMUTE)
00390         {
00391           /* If we have just processed some options following some non-options,
00392              exchange them so that the options come first.  */
00393 
00394           if (first_nonopt != last_nonopt && last_nonopt != optind)
00395             exchange ((char **) argv);
00396           else if (last_nonopt != optind)
00397             first_nonopt = optind;
00398 
00399           /* Skip any additional non-options
00400              and extend the range of non-options previously skipped.  */
00401 
00402           while (optind < argc
00403                  && (argv[optind][0] != '-' || argv[optind][1] == '\0'))
00404             optind++;
00405           last_nonopt = optind;
00406         }
00407 
00408       /* The special ARGV-element `--' means premature end of options.
00409          Skip it like a null option,
00410          then exchange with previous non-options as if it were an option,
00411          then skip everything else like a non-option.  */
00412 
00413       if (optind != argc && !strcmp (argv[optind], "--"))
00414         {
00415           optind++;
00416 
00417           if (first_nonopt != last_nonopt && last_nonopt != optind)
00418             exchange ((char **) argv);
00419           else if (first_nonopt == last_nonopt)
00420             first_nonopt = optind;
00421           last_nonopt = argc;
00422 
00423           optind = argc;
00424         }
00425 
00426       /* If we have done all the ARGV-elements, stop the scan
00427          and back over any non-options that we skipped and permuted.  */
00428 
00429       if (optind == argc)
00430         {
00431           /* Set the next-arg-index to point at the non-options
00432              that we previously skipped, so the caller will digest them.  */
00433           if (first_nonopt != last_nonopt)
00434             optind = first_nonopt;
00435           return EOF;
00436         }
00437 
00438       /* If we have come to a non-option and did not permute it,
00439          either stop the scan or describe it to the caller and pass it by.  */
00440 
00441       if ((argv[optind][0] != '-' || argv[optind][1] == '\0'))
00442         {
00443           if (ordering == REQUIRE_ORDER)
00444             return EOF;
00445           optarg = argv[optind++];
00446           return 1;
00447         }
00448 
00449       /* We have found another option-ARGV-element.
00450          Skip the initial punctuation.  */
00451 
00452       nextchar = (argv[optind] + 1
00453                   + (longopts != NULL && argv[optind][1] == '-'));
00454     }
00455 
00456   /* Decode the current option-ARGV-element.  */
00457 
00458   /* Check whether the ARGV-element is a long option.
00459 
00460      If long_only and the ARGV-element has the form "-f", where f is
00461      a valid short option, don't consider it an abbreviated form of
00462      a long option that starts with f.  Otherwise there would be no
00463      way to give the -f short option.
00464 
00465      On the other hand, if there's a long option "fubar" and
00466      the ARGV-element is "-fu", do consider that an abbreviation of
00467      the long option, just like "--fu", and not "-f" with arg "u".
00468 
00469      This distinction seems to be the most useful approach.  */
00470 
00471   if (longopts != NULL
00472       && (argv[optind][1] == '-'
00473           || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
00474     {
00475       char *nameend;
00476       const struct option *p;
00477       const struct option *pfound = NULL;
00478       int exact = 0;
00479       int ambig = 0;
00480       int indfound;
00481       int option_index;
00482 
00483       for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
00484         /* Do nothing.  */ ;
00485 
00486       /* Test all long options for either exact match
00487          or abbreviated matches.  */
00488       for (p = longopts, option_index = 0; p->name; p++, option_index++)
00489         if (!strncmp (p->name, nextchar, nameend - nextchar))
00490           {
00491             if (nameend - nextchar == (int) strlen (p->name))
00492               {
00493                 /* Exact match found.  */
00494                 pfound = p;
00495                 indfound = option_index;
00496                 exact = 1;
00497                 break;
00498               }
00499             else if (pfound == NULL)
00500               {
00501                 /* First nonexact match found.  */
00502                 pfound = p;
00503                 indfound = option_index;
00504               }
00505             else
00506               /* Second or later nonexact match found.  */
00507               ambig = 1;
00508           }
00509 
00510       if (ambig && !exact)
00511         {
00512           if (opterr)
00513             fprintf (stderr, "%s: option `%s' is ambiguous\n",
00514                      argv[0], argv[optind]);
00515           nextchar += strlen (nextchar);
00516           optind++;
00517           return '?';
00518         }
00519 
00520       if (pfound != NULL)
00521         {
00522           option_index = indfound;
00523           optind++;
00524           if (*nameend)
00525             {
00526               /* Don't test has_arg with >, because some C compilers don't
00527                  allow it to be used on enums.  */
00528               if (pfound->has_arg)
00529                 optarg = nameend + 1;
00530               else
00531                 {
00532                   if (opterr)
00533                     {
00534                       if (argv[optind - 1][1] == '-')
00535                         /* --option */
00536                         fprintf (stderr,
00537                                  "%s: option `--%s' doesn't allow an argument\n",
00538                                  argv[0], pfound->name);
00539                       else
00540                         /* +option or -option */
00541                         fprintf (stderr,
00542                              "%s: option `%c%s' doesn't allow an argument\n",
00543                              argv[0], argv[optind - 1][0], pfound->name);
00544                     }
00545                   nextchar += strlen (nextchar);
00546                   return '?';
00547                 }
00548             }
00549           else if (pfound->has_arg == 1)
00550             {
00551               if (optind < argc)
00552                 optarg = argv[optind++];
00553               else
00554                 {
00555                   if (opterr)
00556                     fprintf (stderr, "%s: option `%s' requires an argument\n",
00557                              argv[0], argv[optind - 1]);
00558                   nextchar += strlen (nextchar);
00559                   return optstring[0] == ':' ? ':' : '?';
00560                 }
00561             }
00562           nextchar += strlen (nextchar);
00563           if (longind != NULL)
00564             *longind = option_index;
00565           if (pfound->flag)
00566             {
00567               *(pfound->flag) = pfound->val;
00568               return 0;
00569             }
00570           return pfound->val;
00571         }
00572 
00573       /* Can't find it as a long option.  If this is not getopt_long_only,
00574          or the option starts with '--' or is not a valid short
00575          option, then it's an error.
00576          Otherwise interpret it as a short option.  */
00577       if (!long_only || argv[optind][1] == '-'
00578           || my_index (optstring, *nextchar) == NULL)
00579         {
00580           if (opterr)
00581             {
00582               if (argv[optind][1] == '-')
00583                 /* --option */
00584                 fprintf (stderr, "%s: unrecognized option `--%s'\n",
00585                          argv[0], nextchar);
00586               else
00587                 /* +option or -option */
00588                 fprintf (stderr, "%s: unrecognized option `%c%s'\n",
00589                          argv[0], argv[optind][0], nextchar);
00590             }
00591           nextchar = (char *) "";
00592           optind++;
00593           return '?';
00594         }
00595     }
00596 
00597   /* Look at and handle the next short option-character.  */
00598 
00599   {
00600     char c = *nextchar++;
00601     char *temp = my_index (optstring, c);
00602 
00603     /* Increment `optind' when we start to process its last character.  */
00604     if (*nextchar == '\0')
00605       ++optind;
00606 
00607     if (temp == NULL || c == ':')
00608       {
00609         if (opterr)
00610           {
00611             if (posixly_correct)
00612               /* 1003.2 specifies the format of this message.  */
00613               fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
00614             else
00615               fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c);
00616           }
00617         optopt = c;
00618         return '?';
00619       }
00620     if (temp[1] == ':')
00621       {
00622         if (temp[2] == ':')
00623           {
00624             /* This is an option that accepts an argument optionally.  */
00625             if (*nextchar != '\0')
00626               {
00627                 optarg = nextchar;
00628                 optind++;
00629               }
00630             else
00631               optarg = NULL;
00632             nextchar = NULL;
00633           }
00634         else
00635           {
00636             /* This is an option that requires an argument.  */
00637             if (*nextchar != '\0')
00638               {
00639                 optarg = nextchar;
00640                 /* If we end this ARGV-element by taking the rest as an arg,
00641                    we must advance to the next element now.  */
00642                 optind++;
00643               }
00644             else if (optind == argc)
00645               {
00646                 if (opterr)
00647                   {
00648                     /* 1003.2 specifies the format of this message.  */
00649                     fprintf (stderr, "%s: option requires an argument -- %c\n",
00650                              argv[0], c);
00651                   }
00652                 optopt = c;
00653                 if (optstring[0] == ':')
00654                   c = ':';
00655                 else
00656                   c = '?';
00657               }
00658             else
00659               /* We already incremented `optind' once;
00660                  increment it again when taking next ARGV-elt as argument.  */
00661               optarg = argv[optind++];
00662             nextchar = NULL;
00663           }
00664       }
00665     return c;
00666   }
00667 }
00668 
00669 int
00670 getopt (argc, argv, optstring)
00671      int argc;
00672      char *const *argv;
00673      const char *optstring;
00674 {
00675   return _getopt_internal (argc, argv, optstring,
00676                            (const struct option *) 0,
00677                            (int *) 0,
00678                            0);
00679 }
00680 
00681 #endif  /* _LIBC or not __GNU_LIBRARY__.  */
00682 
00683 #ifdef TEST
00684 
00685 /* Compile with -DTEST to make an executable for use in testing
00686    the above definition of `getopt'.  */
00687 
00688 int
00689 main (argc, argv)
00690      int argc;
00691      char **argv;
00692 {
00693   int c;
00694   int digit_optind = 0;
00695 
00696   while (1)
00697     {
00698       int this_option_optind = optind ? optind : 1;
00699 
00700       c = getopt (argc, argv, "abc:d:0123456789");
00701       if (c == EOF)
00702         break;
00703 
00704       switch (c)
00705         {
00706         case '0':
00707         case '1':
00708         case '2':
00709         case '3':
00710         case '4':
00711         case '5':
00712         case '6':
00713         case '7':
00714         case '8':
00715         case '9':
00716           if (digit_optind != 0 && digit_optind != this_option_optind)
00717             printf ("digits occur in two different argv-elements.\n");
00718           digit_optind = this_option_optind;
00719           printf ("option %c\n", c);
00720           break;
00721 
00722         case 'a':
00723           printf ("option a\n");
00724           break;
00725 
00726         case 'b':
00727           printf ("option b\n");
00728           break;
00729 
00730         case 'c':
00731           printf ("option c with value `%s'\n", optarg);
00732           break;
00733 
00734         case '?':
00735           break;
00736 
00737         default:
00738           printf ("?? getopt returned character code 0%o ??\n", c);
00739         }
00740     }
00741 
00742   if (optind < argc)
00743     {
00744       printf ("non-option ARGV-elements: ");
00745       while (optind < argc)
00746         printf ("%s ", argv[optind++]);
00747       printf ("\n");
00748     }
00749 
00750   exit (0);
00751 }
00752 
00753 #endif /* TEST */
00754 
00755 #endif /* HAVE_GETOPT */

Generated on Thu May 1 22:13:00 2003 for DTool by doxygen1.3