home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gtak212.zip / 1.10 / getopt.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  20KB  |  705 lines

  1. /*****************************************************************************
  2.  * $Id: getopt.c,v 1.2 1992/09/02 20:08:02 ak Exp $
  3.  *****************************************************************************
  4.  * $Log: getopt.c,v $
  5.  * Revision 1.2  1992/09/02  20:08:02  ak
  6.  * Version AK200
  7.  * - Tape access
  8.  * - Quick file access
  9.  * - OS/2 extended attributes
  10.  * - Some OS/2 fixes
  11.  * - Some fixes of Kai Uwe Rommel
  12.  *
  13.  * Revision 1.1.1.1  1992/09/02  19:21:31  ak
  14.  * Original GNU Tar 1.10 with some filenames changed for FAT compatibility.
  15.  *
  16.  * Revision 1.1  1992/09/02  19:21:29  ak
  17.  * Initial revision
  18.  *
  19.  *****************************************************************************/
  20.  
  21. static char *rcsid = "$Id: getopt.c,v 1.2 1992/09/02 20:08:02 ak Exp $";
  22.  
  23. /* Getopt for GNU.
  24.    NOTE: getopt is now part of the C library, so if you don't know what
  25.    "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
  26.    before changing it!
  27.  
  28.    Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
  29.  
  30.    This program is free software; you can redistribute it and/or modify
  31.    it under the terms of the GNU General Public License as published by
  32.    the Free Software Foundation; either version 2, or (at your option)
  33.    any later version.
  34.  
  35.    This program is distributed in the hope that it will be useful,
  36.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  37.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38.    GNU General Public License for more details.
  39.  
  40.    You should have received a copy of the GNU General Public License
  41.    along with this program; if not, write to the Free Software
  42.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  43.  
  44. /* AIX requires this to be the first thing in the file. */
  45. #ifdef __GNUC__
  46. #define alloca __builtin_alloca
  47. #else /* not __GNUC__ */
  48. #ifdef sparc
  49. #include <alloca.h>
  50. #else
  51. #ifdef _AIX
  52.  #pragma alloca
  53. #else
  54. #ifdef MSDOS
  55. #include <malloc.h>
  56. #else
  57. char *alloca ();
  58. #endif
  59. #endif
  60. #endif /* sparc */
  61. #endif /* not __GNUC__ */
  62.  
  63. #ifdef    LIBC
  64. /* For when compiled as part of the GNU C library.  */
  65. #include <ansidecl.h>
  66. #endif
  67.  
  68. #include <stdio.h>
  69.  
  70. /* This needs to come after some library #include
  71.    to get __GNU_LIBRARY__ defined.  */
  72. #ifdef    __GNU_LIBRARY__
  73. #undef    alloca
  74. #include <stdlib.h>
  75. #else    /* Not GNU C library.  */
  76. #define    __alloca    alloca
  77. #endif    /* GNU C library.  */
  78.  
  79.  
  80. #ifndef __STDC__
  81. #define const
  82. #endif
  83.  
  84. /* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
  85.    long-named option.  Because this is not POSIX.2 compliant, it is
  86.    being phased out. */
  87. #define GETOPT_COMPAT
  88.  
  89. /* This version of `getopt' appears to the caller like standard Unix `getopt'
  90.    but it behaves differently for the user, since it allows the user
  91.    to intersperse the options with the other arguments.
  92.  
  93.    As `getopt' works, it permutes the elements of ARGV so that,
  94.    when it is done, all the options precede everything else.  Thus
  95.    all application programs are extended to handle flexible argument order.
  96.  
  97.    Setting the environment variable POSIXLY_CORRECT disables permutation.
  98.    Then the behavior is completely standard.
  99.  
  100.    GNU application programs can use a third alternative mode in which
  101.    they can distinguish the relative order of options and other arguments.  */
  102.  
  103. #include "getopt.h"
  104.  
  105. static void exchange (char **);
  106.  
  107. /* For communication from `getopt' to the caller.
  108.    When `getopt' finds an option that takes an argument,
  109.    the argument value is returned here.
  110.    Also, when `ordering' is RETURN_IN_ORDER,
  111.    each non-option ARGV-element is returned here.  */
  112.  
  113. char *optarg = 0;
  114.  
  115. /* Index in ARGV of the next element to be scanned.
  116.    This is used for communication to and from the caller
  117.    and for communication between successive calls to `getopt'.
  118.  
  119.    On entry to `getopt', zero means this is the first call; initialize.
  120.  
  121.    When `getopt' returns EOF, this is the index of the first of the
  122.    non-option elements that the caller should itself scan.
  123.  
  124.    Otherwise, `optind' communicates from one call to the next
  125.    how much of ARGV has been scanned so far.  */
  126.  
  127. int optind = 0;
  128.  
  129. /* The next char to be scanned in the option-element
  130.    in which the last option character we returned was found.
  131.    This allows us to pick up the scan where we left off.
  132.  
  133.    If this is zero, or a null string, it means resume the scan
  134.    by advancing to the next ARGV-element.  */
  135.  
  136. static char *nextchar;
  137.  
  138. /* Callers store zero here to inhibit the error message
  139.    for unrecognized options.  */
  140.  
  141. int opterr = 1;
  142.  
  143. /* Describe how to deal with options that follow non-option ARGV-elements.
  144.  
  145.    If the caller did not specify anything,
  146.    the default is REQUIRE_ORDER if the environment variable
  147.    POSIXLY_CORRECT is defined, PERMUTE otherwise.
  148.  
  149.    REQUIRE_ORDER means don't recognize them as options;
  150.    stop option processing when the first non-option is seen.
  151.    This is what Unix does.
  152.    This mode of operation is selected by either setting the environment
  153.    variable POSIXLY_CORRECT, or using `+' as the first character
  154.    of the list of option characters.
  155.  
  156.    PERMUTE is the default.  We permute the contents of ARGV as we scan,
  157.    so that eventually all the non-options are at the end.  This allows options
  158.    to be given in any order, even with programs that were not written to
  159.    expect this.
  160.  
  161.    RETURN_IN_ORDER is an option available to programs that were written
  162.    to expect options and other ARGV-elements in any order and that care about
  163.    the ordering of the two.  We describe each non-option ARGV-element
  164.    as if it were the argument of an option with character code 1.
  165.    Using `-' as the first character of the list of option characters
  166.    selects this mode of operation.
  167.  
  168.    The special argument `--' forces an end of option-scanning regardless
  169.    of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
  170.    `--' can cause `getopt' to return EOF with `optind' != ARGC.  */
  171.  
  172. static enum
  173. {
  174.   REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
  175. } ordering;
  176.  
  177. #if defined(__GNU_LIBRARY__) || defined(__STDC__)
  178. #include <stdlib.h>
  179. #include <string.h>
  180. #define    my_index    strchr
  181. #define    my_bcopy(src, dst, n)    memcpy ((dst), (src), (n))
  182. #else
  183.  
  184. /* Avoid depending on library functions or files
  185.    whose names are inconsistent.  */
  186.  
  187. char *getenv ();
  188.  
  189. static char *
  190. my_index (string, chr)
  191.      char *string;
  192.      int chr;
  193. {
  194.   while (*string)
  195.     {
  196.       if (*string == (char) chr)
  197.     return string;
  198.       string++;
  199.     }
  200.   return 0;
  201. }
  202.  
  203. static void
  204. my_bcopy (from, to, size)
  205.      char *from, *to;
  206.      int size;
  207. {
  208.   int i;
  209.   for (i = 0; i < size; i++)
  210.     to[i] = from[i];
  211. }
  212. #endif                /* GNU C library.  */
  213.  
  214. /* Handle permutation of arguments.  */
  215.  
  216. /* Describe the part of ARGV that contains non-options that have
  217.    been skipped.  `first_nonopt' is the index in ARGV of the first of them;
  218.    `last_nonopt' is the index after the last of them.  */
  219.  
  220. static int first_nonopt;
  221. static int last_nonopt;
  222.  
  223. /* Exchange two adjacent subsequences of ARGV.
  224.    One subsequence is elements [first_nonopt,last_nonopt)
  225.    which contains all the non-options that have been skipped so far.
  226.    The other is elements [last_nonopt,optind), which contains all
  227.    the options processed since those non-options were skipped.
  228.  
  229.    `first_nonopt' and `last_nonopt' are relocated so that they describe
  230.    the new indices of the non-options in ARGV after they are moved.  */
  231.  
  232. static void
  233. exchange (argv)
  234.      char **argv;
  235. {
  236.   int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
  237.   char **temp = (char **) __alloca (nonopts_size);
  238.  
  239.   /* Interchange the two blocks of data in ARGV.  */
  240.  
  241.   my_bcopy (&argv[first_nonopt], temp, nonopts_size);
  242.   my_bcopy (&argv[last_nonopt], &argv[first_nonopt],
  243.         (optind - last_nonopt) * sizeof (char *));
  244.   my_bcopy (temp, &argv[first_nonopt + optind - last_nonopt], nonopts_size);
  245.  
  246.   /* Update records for the slots the non-options now occupy.  */
  247.  
  248.   first_nonopt += (optind - last_nonopt);
  249.   last_nonopt = optind;
  250. }
  251.  
  252. /* Scan elements of ARGV (whose length is ARGC) for option characters
  253.    given in OPTSTRING.
  254.  
  255.    If an element of ARGV starts with '-', and is not exactly "-" or "--",
  256.    then it is an option element.  The characters of this element
  257.    (aside from the initial '-') are option characters.  If `getopt'
  258.    is called repeatedly, it returns successively each of the option characters
  259.    from each of the option elements.
  260.  
  261.    If `getopt' finds another option character, it returns that character,
  262.    updating `optind' and `nextchar' so that the next call to `getopt' can
  263.    resume the scan with the following option character or ARGV-element.
  264.  
  265.    If there are no more option characters, `getopt' returns `EOF'.
  266.    Then `optind' is the index in ARGV of the first ARGV-element
  267.    that is not an option.  (The ARGV-elements have been permuted
  268.    so that those that are not options now come last.)
  269.  
  270.    OPTSTRING is a string containing the legitimate option characters.
  271.    If an option character is seen that is not listed in OPTSTRING,
  272.    return '?' after printing an error message.  If you set `opterr' to
  273.    zero, the error message is suppressed but we still return '?'.
  274.  
  275.    If a char in OPTSTRING is followed by a colon, that means it wants an arg,
  276.    so the following text in the same ARGV-element, or the text of the following
  277.    ARGV-element, is returned in `optarg'.  Two colons mean an option that
  278.    wants an optional arg; if there is text in the current ARGV-element,
  279.    it is returned in `optarg', otherwise `optarg' is set to zero.
  280.  
  281.    If OPTSTRING starts with `-' or `+', it requests different methods of
  282.    handling the non-option ARGV-elements.
  283.    See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
  284.  
  285.    Long-named options begin with `--' instead of `-'.
  286.    Their names may be abbreviated as long as the abbreviation is unique
  287.    or is an exact match for some defined option.  If they have an
  288.    argument, it follows the option name in the same ARGV-element, separated
  289.    from the option name by a `=', or else the in next ARGV-element.
  290.    When `getopt' finds a long-named option, it returns 0 if that option's
  291.    `flag' field is nonzero, the value of the option's `val' field
  292.    if the `flag' field is zero.
  293.  
  294.    The elements of ARGV aren't really const, because we permute them.
  295.    But we pretend they're const in the prototype to be compatible
  296.    with other systems.
  297.  
  298.    LONGOPTS is a vector of `struct option' terminated by an
  299.    element containing a name which is zero.
  300.  
  301.    LONGIND returns the index in LONGOPT of the long-named option found.
  302.    It is only valid when a long-named option has been found by the most
  303.    recent call.
  304.  
  305.    If LONG_ONLY is nonzero, '-' as well as '--' can introduce
  306.    long-named options.  */
  307.  
  308. int
  309. _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
  310.      int argc;
  311.      char *const *argv;
  312.      const char *optstring;
  313.      const struct option *longopts;
  314.      int *longind;
  315.      int long_only;
  316. {
  317.   int option_index;
  318.  
  319.   optarg = 0;
  320.  
  321.   /* Initialize the internal data when the first call is made.
  322.      Start processing options with ARGV-element 1 (since ARGV-element 0
  323.      is the program name); the sequence of previously skipped
  324.      non-option ARGV-elements is empty.  */
  325.  
  326.   if (optind == 0)
  327.     {
  328.       first_nonopt = last_nonopt = optind = 1;
  329.  
  330.       nextchar = NULL;
  331.  
  332.       /* Determine how to handle the ordering of options and nonoptions.  */
  333.  
  334.       if (optstring[0] == '-')
  335.     {
  336.       ordering = RETURN_IN_ORDER;
  337.       ++optstring;
  338.     }
  339.       else if (optstring[0] == '+')
  340.     {
  341.       ordering = REQUIRE_ORDER;
  342.       ++optstring;
  343.     }
  344.       else if (getenv ("POSIXLY_CORRECT") != NULL)
  345.     ordering = REQUIRE_ORDER;
  346.       else
  347.     ordering = PERMUTE;
  348.     }
  349.  
  350.   if (nextchar == NULL || *nextchar == '\0')
  351.     {
  352.       if (ordering == PERMUTE)
  353.     {
  354.       /* If we have just processed some options following some non-options,
  355.          exchange them so that the options come first.  */
  356.  
  357.       if (first_nonopt != last_nonopt && last_nonopt != optind)
  358.         exchange ((char **) argv);
  359.       else if (last_nonopt != optind)
  360.         first_nonopt = optind;
  361.  
  362.       /* Now skip any additional non-options
  363.          and extend the range of non-options previously skipped.  */
  364.  
  365.       while (optind < argc
  366.          && (argv[optind][0] != '-' || argv[optind][1] == '\0')
  367. #ifdef GETOPT_COMPAT
  368.          && (longopts == NULL
  369.              || argv[optind][0] != '+' || argv[optind][1] == '\0')
  370. #endif                /* GETOPT_COMPAT */
  371.          )
  372.         optind++;
  373.       last_nonopt = optind;
  374.     }
  375.  
  376.       /* Special ARGV-element `--' means premature end of options.
  377.      Skip it like a null option,
  378.      then exchange with previous non-options as if it were an option,
  379.      then skip everything else like a non-option.  */
  380.  
  381.       if (optind != argc && !strcmp (argv[optind], "--"))
  382.     {
  383.       optind++;
  384.  
  385.       if (first_nonopt != last_nonopt && last_nonopt != optind)
  386.         exchange ((char **) argv);
  387.       else if (first_nonopt == last_nonopt)
  388.         first_nonopt = optind;
  389.       last_nonopt = argc;
  390.  
  391.       optind = argc;
  392.     }
  393.  
  394.       /* If we have done all the ARGV-elements, stop the scan
  395.      and back over any non-options that we skipped and permuted.  */
  396.  
  397.       if (optind == argc)
  398.     {
  399.       /* Set the next-arg-index to point at the non-options
  400.          that we previously skipped, so the caller will digest them.  */
  401.       if (first_nonopt != last_nonopt)
  402.         optind = first_nonopt;
  403.       return EOF;
  404.     }
  405.  
  406.       /* If we have come to a non-option and did not permute it,
  407.      either stop the scan or describe it to the caller and pass it by.  */
  408.  
  409.       if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
  410. #ifdef GETOPT_COMPAT
  411.       && (longopts == NULL
  412.           || argv[optind][0] != '+' || argv[optind][1] == '\0')
  413. #endif                /* GETOPT_COMPAT */
  414.       )
  415.     {
  416.       if (ordering == REQUIRE_ORDER)
  417.         return EOF;
  418.       optarg = argv[optind++];
  419.       return 1;
  420.     }
  421.  
  422.       /* We have found another option-ARGV-element.
  423.      Start decoding its characters.  */
  424.  
  425.       nextchar = (argv[optind] + 1
  426.           + (longopts != NULL && argv[optind][1] == '-'));
  427.     }
  428.  
  429.   if (longopts != NULL
  430.       && ((argv[optind][0] == '-'
  431.        && (argv[optind][1] == '-' || long_only))
  432. #ifdef GETOPT_COMPAT
  433.       || argv[optind][0] == '+'
  434. #endif                /* GETOPT_COMPAT */
  435.       ))
  436.     {
  437.       const struct option *p;
  438.       char *s = nextchar;
  439.       int exact = 0;
  440.       int ambig = 0;
  441.       const struct option *pfound = NULL;
  442.       int indfound;
  443.  
  444.       while (*s && *s != '=')
  445.     s++;
  446.  
  447.       /* Test all options for either exact match or abbreviated matches.  */
  448.       for (p = longopts, option_index = 0; p->name;
  449.        p++, option_index++)
  450.     if (!strncmp (p->name, nextchar, s - nextchar))
  451.       {
  452.         if (s - nextchar == (int) strlen (p->name))
  453.           {
  454.         /* Exact match found.  */
  455.         pfound = p;
  456.         indfound = option_index;
  457.         exact = 1;
  458.         break;
  459.           }
  460.         else if (pfound == NULL)
  461.           {
  462.         /* First nonexact match found.  */
  463.         pfound = p;
  464.         indfound = option_index;
  465.           }
  466.         else
  467.           /* Second nonexact match found.  */
  468.           ambig = 1;
  469.       }
  470.  
  471.       if (ambig && !exact)
  472.     {
  473.       if (opterr)
  474.         fprintf (stderr, "%s: option `%s' is ambiguous\n",
  475.              argv[0], argv[optind]);
  476.       nextchar += strlen (nextchar);
  477.       optind++;
  478.       return '?';
  479.     }
  480.  
  481.       if (pfound != NULL)
  482.     {
  483.       option_index = indfound;
  484.       optind++;
  485.       if (*s)
  486.         {
  487.           if (pfound->has_arg > 0)
  488.         optarg = s + 1;
  489.           else
  490.         {
  491.           if (opterr)
  492.             {
  493.               if (argv[optind - 1][1] == '-')
  494.             /* --option */
  495.             fprintf (stderr,
  496.                  "%s: option `--%s' doesn't allow an argument\n",
  497.                  argv[0], pfound->name);
  498.               else
  499.             /* +option or -option */
  500.             fprintf (stderr,
  501.                  "%s: option `%c%s' doesn't allow an argument\n",
  502.                  argv[0], argv[optind - 1][0], pfound->name);
  503.             }
  504.           nextchar += strlen (nextchar);
  505.           return '?';
  506.         }
  507.         }
  508.       else if (pfound->has_arg == 1)
  509.         {
  510.           if (optind < argc)
  511.         optarg = argv[optind++];
  512.           else
  513.         {
  514.           if (opterr)
  515.             fprintf (stderr, "%s: option `%s' requires an argument\n",
  516.                  argv[0], argv[optind - 1]);
  517.           nextchar += strlen (nextchar);
  518.           return '?';
  519.         }
  520.         }
  521.       nextchar += strlen (nextchar);
  522.       if (longind != NULL)
  523.         *longind = option_index;
  524.       if (pfound->flag)
  525.         {
  526.           *(pfound->flag) = pfound->val;
  527.           return 0;
  528.         }
  529.       return pfound->val;
  530.     }
  531.       /* Can't find it as a long option.  If this is not getopt_long_only,
  532.      or the option starts with '--' or is not a valid short
  533.      option, then it's an error.
  534.      Otherwise interpret it as a short option. */
  535.       if (!long_only || argv[optind][1] == '-'
  536. #ifdef GETOPT_COMPAT
  537.       || argv[optind][0] == '+'
  538. #endif                /* GETOPT_COMPAT */
  539.       || my_index (optstring, *nextchar) == NULL)
  540.     {
  541.       if (opterr)
  542.         {
  543.           if (argv[optind][1] == '-')
  544.         /* --option */
  545.         fprintf (stderr, "%s: unrecognized option `--%s'\n",
  546.              argv[0], nextchar);
  547.           else
  548.         /* +option or -option */
  549.         fprintf (stderr, "%s: unrecognized option `%c%s'\n",
  550.              argv[0], argv[optind][0], nextchar);
  551.         }
  552.       nextchar += strlen (nextchar);
  553.       optind++;
  554.       return '?';
  555.     }
  556.     }
  557.  
  558.   /* Look at and handle the next option-character.  */
  559.  
  560.   {
  561.     char c = *nextchar++;
  562.     char *temp = my_index (optstring, c);
  563.  
  564.     /* Increment `optind' when we start to process its last character.  */
  565.     if (*nextchar == '\0')
  566.       optind++;
  567.  
  568.     if (temp == NULL || c == ':')
  569.       {
  570.     if (opterr)
  571.       {
  572.         if (c < 040 || c >= 0177)
  573.           fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
  574.                argv[0], c);
  575.         else
  576.           fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
  577.       }
  578.     return '?';
  579.       }
  580.     if (temp[1] == ':')
  581.       {
  582.     if (temp[2] == ':')
  583.       {
  584.         /* This is an option that accepts an argument optionally.  */
  585.         if (*nextchar != '\0')
  586.           {
  587.         optarg = nextchar;
  588.         optind++;
  589.           }
  590.         else
  591.           optarg = 0;
  592.         nextchar = NULL;
  593.       }
  594.     else
  595.       {
  596.         /* This is an option that requires an argument.  */
  597.         if (*nextchar != 0)
  598.           {
  599.         optarg = nextchar;
  600.         /* If we end this ARGV-element by taking the rest as an arg,
  601.            we must advance to the next element now.  */
  602.         optind++;
  603.           }
  604.         else if (optind == argc)
  605.           {
  606.         if (opterr)
  607.           fprintf (stderr, "%s: option `-%c' requires an argument\n",
  608.                argv[0], c);
  609.         c = '?';
  610.           }
  611.         else
  612.           /* We already incremented `optind' once;
  613.          increment it again when taking next ARGV-elt as argument.  */
  614.           optarg = argv[optind++];
  615.         nextchar = NULL;
  616.       }
  617.       }
  618.     return c;
  619.   }
  620. }
  621.  
  622. int
  623. getopt (argc, argv, optstring)
  624.      int argc;
  625.      char *const *argv;
  626.      const char *optstring;
  627. {
  628.   return _getopt_internal (argc, argv, optstring,
  629.                (const struct option *) 0,
  630.                (int *) 0,
  631.                0);
  632. }
  633.  
  634. #ifdef TEST
  635.  
  636. /* Compile with -DTEST to make an executable for use in testing
  637.    the above definition of `getopt'.  */
  638.  
  639. int
  640. main (argc, argv)
  641.      int argc;
  642.      char **argv;
  643. {
  644.   int c;
  645.   int digit_optind = 0;
  646.  
  647.   while (1)
  648.     {
  649.       int this_option_optind = optind ? optind : 1;
  650.  
  651.       c = getopt (argc, argv, "abc:d:0123456789");
  652.       if (c == EOF)
  653.     break;
  654.  
  655.       switch (c)
  656.     {
  657.     case '0':
  658.     case '1':
  659.     case '2':
  660.     case '3':
  661.     case '4':
  662.     case '5':
  663.     case '6':
  664.     case '7':
  665.     case '8':
  666.     case '9':
  667.       if (digit_optind != 0 && digit_optind != this_option_optind)
  668.         printf ("digits occur in two different argv-elements.\n");
  669.       digit_optind = this_option_optind;
  670.       printf ("option %c\n", c);
  671.       break;
  672.  
  673.     case 'a':
  674.       printf ("option a\n");
  675.       break;
  676.  
  677.     case 'b':
  678.       printf ("option b\n");
  679.       break;
  680.  
  681.     case 'c':
  682.       printf ("option c with value `%s'\n", optarg);
  683.       break;
  684.  
  685.     case '?':
  686.       break;
  687.  
  688.     default:
  689.       printf ("?? getopt returned character code 0%o ??\n", c);
  690.     }
  691.     }
  692.  
  693.   if (optind < argc)
  694.     {
  695.       printf ("non-option ARGV-elements: ");
  696.       while (optind < argc)
  697.     printf ("%s ", argv[optind++]);
  698.       printf ("\n");
  699.     }
  700.  
  701.   exit (0);
  702. }
  703.  
  704. #endif /* TEST */
  705.