Blame lib/getopt.c

Packit 15a96c
/* Getopt for GNU.
Packit 15a96c
   NOTE: getopt is now part of the C library, so if you don't know what
Packit 15a96c
   "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
Packit 15a96c
   before changing it!
Packit 15a96c
Packit 15a96c
   Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97
Packit 15a96c
   	Free Software Foundation, Inc.
Packit 15a96c
Packit 15a96c
   This file is part of the GNU C Library.  Its master source is NOT part of
Packit 15a96c
   the C library, however.  The master source lives in /gd/gnu/lib.
Packit 15a96c
Packit 15a96c
   The GNU C Library is free software; you can redistribute it and/or
Packit 15a96c
   modify it under the terms of the GNU Library General Public License as
Packit 15a96c
   published by the Free Software Foundation; either version 2 of the
Packit 15a96c
   License, or (at your option) any later version.
Packit 15a96c
Packit 15a96c
   The GNU C Library is distributed in the hope that it will be useful,
Packit 15a96c
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 15a96c
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 15a96c
   Library General Public License for more details.
Packit 15a96c
Packit 15a96c
   You should have received a copy of the GNU Library General Public
Packit 15a96c
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
Packit 15a96c
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 15a96c
   Boston, MA 02111-1307, USA.  */
Packit 15a96c

Packit 15a96c
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
Packit 15a96c
   Ditto for AIX 3.2 and <stdlib.h>.  */
Packit 15a96c
#ifndef _NO_PROTO
Packit 15a96c
#define _NO_PROTO
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
#ifdef HAVE_CONFIG_H
Packit 15a96c
#include <config.h>
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
#if !defined (__STDC__) || !__STDC__
Packit 15a96c
/* This is a separate conditional since some stdc systems
Packit 15a96c
   reject `defined (const)'.  */
Packit 15a96c
#ifndef const
Packit 15a96c
#define const
Packit 15a96c
#endif
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
#include <stdio.h>
Packit 15a96c
Packit 15a96c
/* Comment out all this code if we are using the GNU C Library, and are not
Packit 15a96c
   actually compiling the library itself.  This code is part of the GNU C
Packit 15a96c
   Library, but also included in many other GNU distributions.  Compiling
Packit 15a96c
   and linking in this code is a waste when using the GNU C library
Packit 15a96c
   (especially if it is a shared library).  Rather than having every GNU
Packit 15a96c
   program understand `configure --with-gnu-libc' and omit the object files,
Packit 15a96c
   it is simpler to just do this in the source for each such file.  */
Packit 15a96c
Packit 15a96c
#define GETOPT_INTERFACE_VERSION 2
Packit 15a96c
#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
Packit 15a96c
#include <gnu-versions.h>
Packit 15a96c
#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
Packit 15a96c
#define ELIDE_CODE
Packit 15a96c
#endif
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
#ifndef ELIDE_CODE
Packit 15a96c
Packit 15a96c
Packit 15a96c
/* This needs to come after some library #include
Packit 15a96c
   to get __GNU_LIBRARY__ defined.  */
Packit 15a96c
#ifdef	__GNU_LIBRARY__
Packit 15a96c
/* Don't include stdlib.h for non-GNU C libraries because some of them
Packit 15a96c
   contain conflicting prototypes for getopt.  */
Packit 15a96c
#include <stdlib.h>
Packit 15a96c
#include <unistd.h>
Packit 15a96c
#endif	/* GNU C library.  */
Packit 15a96c
Packit 15a96c
#ifdef VMS
Packit 15a96c
#include <unixlib.h>
Packit 15a96c
#if HAVE_STRING_H - 0
Packit 15a96c
#include <string.h>
Packit 15a96c
#endif
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
#if defined (WIN32) && !defined (__CYGWIN32__)
Packit 15a96c
/* It's not Unix, really.  See?  Capital letters.  */
Packit 15a96c
#include <windows.h>
Packit 15a96c
#define getpid() GetCurrentProcessId()
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
#ifndef _
Packit 15a96c
/* This is for other GNU distributions with internationalized messages.
Packit 15a96c
   When compiling libc, the _ macro is predefined.  */
Packit 15a96c
#ifdef HAVE_LIBINTL_H
Packit 15a96c
# include <libintl.h>
Packit 15a96c
# define _(msgid)	gettext (msgid)
Packit 15a96c
#else
Packit 15a96c
# define _(msgid)	(msgid)
Packit 15a96c
#endif
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
/* This version of `getopt' appears to the caller like standard Unix `getopt'
Packit 15a96c
   but it behaves differently for the user, since it allows the user
Packit 15a96c
   to intersperse the options with the other arguments.
Packit 15a96c
Packit 15a96c
   As `getopt' works, it permutes the elements of ARGV so that,
Packit 15a96c
   when it is done, all the options precede everything else.  Thus
Packit 15a96c
   all application programs are extended to handle flexible argument order.
Packit 15a96c
Packit 15a96c
   Setting the environment variable POSIXLY_CORRECT disables permutation.
Packit 15a96c
   Then the behavior is completely standard.
Packit 15a96c
Packit 15a96c
   GNU application programs can use a third alternative mode in which
Packit 15a96c
   they can distinguish the relative order of options and other arguments.  */
Packit 15a96c
Packit 15a96c
#include "getopt.h"
Packit 15a96c
Packit 15a96c
/* For communication from `getopt' to the caller.
Packit 15a96c
   When `getopt' finds an option that takes an argument,
Packit 15a96c
   the argument value is returned here.
Packit 15a96c
   Also, when `ordering' is RETURN_IN_ORDER,
Packit 15a96c
   each non-option ARGV-element is returned here.  */
Packit 15a96c
Packit 15a96c
char *optarg = NULL;
Packit 15a96c
Packit 15a96c
/* Index in ARGV of the next element to be scanned.
Packit 15a96c
   This is used for communication to and from the caller
Packit 15a96c
   and for communication between successive calls to `getopt'.
Packit 15a96c
Packit 15a96c
   On entry to `getopt', zero means this is the first call; initialize.
Packit 15a96c
Packit 15a96c
   When `getopt' returns -1, this is the index of the first of the
Packit 15a96c
   non-option elements that the caller should itself scan.
Packit 15a96c
Packit 15a96c
   Otherwise, `optind' communicates from one call to the next
Packit 15a96c
   how much of ARGV has been scanned so far.  */
Packit 15a96c
Packit 15a96c
/* 1003.2 says this must be 1 before any call.  */
Packit 15a96c
int optind = 1;
Packit 15a96c
Packit 15a96c
/* Formerly, initialization of getopt depended on optind==0, which
Packit 15a96c
   causes problems with re-calling getopt as programs generally don't
Packit 15a96c
   know that. */
Packit 15a96c
Packit 15a96c
int __getopt_initialized = 0;
Packit 15a96c
Packit 15a96c
/* The next char to be scanned in the option-element
Packit 15a96c
   in which the last option character we returned was found.
Packit 15a96c
   This allows us to pick up the scan where we left off.
Packit 15a96c
Packit 15a96c
   If this is zero, or a null string, it means resume the scan
Packit 15a96c
   by advancing to the next ARGV-element.  */
Packit 15a96c
Packit 15a96c
static char *nextchar;
Packit 15a96c
Packit 15a96c
/* Callers store zero here to inhibit the error message
Packit 15a96c
   for unrecognized options.  */
Packit 15a96c
Packit 15a96c
int opterr = 1;
Packit 15a96c
Packit 15a96c
/* Set to an option character which was unrecognized.
Packit 15a96c
   This must be initialized on some systems to avoid linking in the
Packit 15a96c
   system's own getopt implementation.  */
Packit 15a96c
Packit 15a96c
int optopt = '?';
Packit 15a96c
Packit 15a96c
/* Describe how to deal with options that follow non-option ARGV-elements.
Packit 15a96c
Packit 15a96c
   If the caller did not specify anything,
Packit 15a96c
   the default is REQUIRE_ORDER if the environment variable
Packit 15a96c
   POSIXLY_CORRECT is defined, PERMUTE otherwise.
Packit 15a96c
Packit 15a96c
   REQUIRE_ORDER means don't recognize them as options;
Packit 15a96c
   stop option processing when the first non-option is seen.
Packit 15a96c
   This is what Unix does.
Packit 15a96c
   This mode of operation is selected by either setting the environment
Packit 15a96c
   variable POSIXLY_CORRECT, or using `+' as the first character
Packit 15a96c
   of the list of option characters.
Packit 15a96c
Packit 15a96c
   PERMUTE is the default.  We permute the contents of ARGV as we scan,
Packit 15a96c
   so that eventually all the non-options are at the end.  This allows options
Packit 15a96c
   to be given in any order, even with programs that were not written to
Packit 15a96c
   expect this.
Packit 15a96c
Packit 15a96c
   RETURN_IN_ORDER is an option available to programs that were written
Packit 15a96c
   to expect options and other ARGV-elements in any order and that care about
Packit 15a96c
   the ordering of the two.  We describe each non-option ARGV-element
Packit 15a96c
   as if it were the argument of an option with character code 1.
Packit 15a96c
   Using `-' as the first character of the list of option characters
Packit 15a96c
   selects this mode of operation.
Packit 15a96c
Packit 15a96c
   The special argument `--' forces an end of option-scanning regardless
Packit 15a96c
   of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
Packit 15a96c
   `--' can cause `getopt' to return -1 with `optind' != ARGC.  */
Packit 15a96c
Packit 15a96c
static enum
Packit 15a96c
{
Packit 15a96c
  REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
Packit 15a96c
} ordering;
Packit 15a96c
Packit 15a96c
/* Value of POSIXLY_CORRECT environment variable.  */
Packit 15a96c
static char *posixly_correct;
Packit 15a96c

Packit 15a96c
#ifdef	__GNU_LIBRARY__
Packit 15a96c
/* We want to avoid inclusion of string.h with non-GNU libraries
Packit 15a96c
   because there are many ways it can cause trouble.
Packit 15a96c
   On some systems, it contains special magic macros that don't work
Packit 15a96c
   in GCC.  */
Packit 15a96c
#include <string.h>
Packit 15a96c
#define	my_index	strchr
Packit 15a96c
#else
Packit 15a96c
Packit 15a96c
/* Avoid depending on library functions or files
Packit 15a96c
   whose names are inconsistent.  */
Packit 15a96c
Packit 15a96c
char *getenv ();
Packit 15a96c
Packit 15a96c
static char *
Packit 15a96c
my_index (str, chr)
Packit 15a96c
     const char *str;
Packit 15a96c
     int chr;
Packit 15a96c
{
Packit 15a96c
  while (*str)
Packit 15a96c
    {
Packit 15a96c
      if (*str == chr)
Packit 15a96c
	return (char *) str;
Packit 15a96c
      str++;
Packit 15a96c
    }
Packit 15a96c
  return 0;
Packit 15a96c
}
Packit 15a96c
Packit 15a96c
/* If using GCC, we can safely declare strlen this way.
Packit 15a96c
   If not using GCC, it is ok not to declare it.  */
Packit 15a96c
#ifdef __GNUC__
Packit 15a96c
/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
Packit 15a96c
   That was relevant to code that was here before.  */
Packit 15a96c
#if !defined (__STDC__) || !__STDC__
Packit 15a96c
/* gcc with -traditional declares the built-in strlen to return int,
Packit 15a96c
   and has done so at least since version 2.4.5. -- rms.  */
Packit 15a96c
extern int strlen (const char *);
Packit 15a96c
#endif /* not __STDC__ */
Packit 15a96c
#endif /* __GNUC__ */
Packit 15a96c
Packit 15a96c
#endif /* not __GNU_LIBRARY__ */
Packit 15a96c

Packit 15a96c
/* Handle permutation of arguments.  */
Packit 15a96c
Packit 15a96c
/* Describe the part of ARGV that contains non-options that have
Packit 15a96c
   been skipped.  `first_nonopt' is the index in ARGV of the first of them;
Packit 15a96c
   `last_nonopt' is the index after the last of them.  */
Packit 15a96c
Packit 15a96c
static int first_nonopt;
Packit 15a96c
static int last_nonopt;
Packit 15a96c
Packit 15a96c
#ifdef _LIBC
Packit 15a96c
/* Bash 2.0 gives us an environment variable containing flags
Packit 15a96c
   indicating ARGV elements that should not be considered arguments.  */
Packit 15a96c
Packit 15a96c
static const char *nonoption_flags;
Packit 15a96c
static int nonoption_flags_len;
Packit 15a96c
Packit 15a96c
static int original_argc;
Packit 15a96c
static char *const *original_argv;
Packit 15a96c
Packit 15a96c
/* Make sure the environment variable bash 2.0 puts in the environment
Packit 15a96c
   is valid for the getopt call we must make sure that the ARGV passed
Packit 15a96c
   to getopt is that one passed to the process.  */
Packit 15a96c
static void store_args (int argc, char *const *argv) __attribute__ ((unused));
Packit 15a96c
static void
Packit 15a96c
store_args (int argc, char *const *argv)
Packit 15a96c
{
Packit 15a96c
  /* XXX This is no good solution.  We should rather copy the args so
Packit 15a96c
     that we can compare them later.  But we must not use malloc(3).  */
Packit 15a96c
  original_argc = argc;
Packit 15a96c
  original_argv = argv;
Packit 15a96c
}
Packit 15a96c
text_set_element (__libc_subinit, store_args);
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
/* Exchange two adjacent subsequences of ARGV.
Packit 15a96c
   One subsequence is elements [first_nonopt,last_nonopt)
Packit 15a96c
   which contains all the non-options that have been skipped so far.
Packit 15a96c
   The other is elements [last_nonopt,optind), which contains all
Packit 15a96c
   the options processed since those non-options were skipped.
Packit 15a96c
Packit 15a96c
   `first_nonopt' and `last_nonopt' are relocated so that they describe
Packit 15a96c
   the new indices of the non-options in ARGV after they are moved.  */
Packit 15a96c
Packit 15a96c
#if defined (__STDC__) && __STDC__
Packit 15a96c
static void exchange (char **);
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
static void
Packit 15a96c
exchange (argv)
Packit 15a96c
     char **argv;
Packit 15a96c
{
Packit 15a96c
  int bottom = first_nonopt;
Packit 15a96c
  int middle = last_nonopt;
Packit 15a96c
  int top = optind;
Packit 15a96c
  char *tem;
Packit 15a96c
Packit 15a96c
  /* Exchange the shorter segment with the far end of the longer segment.
Packit 15a96c
     That puts the shorter segment into the right place.
Packit 15a96c
     It leaves the longer segment in the right place overall,
Packit 15a96c
     but it consists of two parts that need to be swapped next.  */
Packit 15a96c
Packit 15a96c
  while (top > middle && middle > bottom)
Packit 15a96c
    {
Packit 15a96c
      if (top - middle > middle - bottom)
Packit 15a96c
	{
Packit 15a96c
	  /* Bottom segment is the short one.  */
Packit 15a96c
	  int len = middle - bottom;
Packit 15a96c
	  register int i;
Packit 15a96c
Packit 15a96c
	  /* Swap it with the top part of the top segment.  */
Packit 15a96c
	  for (i = 0; i < len; i++)
Packit 15a96c
	    {
Packit 15a96c
	      tem = argv[bottom + i];
Packit 15a96c
	      argv[bottom + i] = argv[top - (middle - bottom) + i];
Packit 15a96c
	      argv[top - (middle - bottom) + i] = tem;
Packit 15a96c
	    }
Packit 15a96c
	  /* Exclude the moved bottom segment from further swapping.  */
Packit 15a96c
	  top -= len;
Packit 15a96c
	}
Packit 15a96c
      else
Packit 15a96c
	{
Packit 15a96c
	  /* Top segment is the short one.  */
Packit 15a96c
	  int len = top - middle;
Packit 15a96c
	  register int i;
Packit 15a96c
Packit 15a96c
	  /* Swap it with the bottom part of the bottom segment.  */
Packit 15a96c
	  for (i = 0; i < len; i++)
Packit 15a96c
	    {
Packit 15a96c
	      tem = argv[bottom + i];
Packit 15a96c
	      argv[bottom + i] = argv[middle + i];
Packit 15a96c
	      argv[middle + i] = tem;
Packit 15a96c
	    }
Packit 15a96c
	  /* Exclude the moved top segment from further swapping.  */
Packit 15a96c
	  bottom += len;
Packit 15a96c
	}
Packit 15a96c
    }
Packit 15a96c
Packit 15a96c
  /* Update records for the slots the non-options now occupy.  */
Packit 15a96c
Packit 15a96c
  first_nonopt += (optind - last_nonopt);
Packit 15a96c
  last_nonopt = optind;
Packit 15a96c
}
Packit 15a96c
Packit 15a96c
/* Initialize the internal data when the first call is made.  */
Packit 15a96c
Packit 15a96c
#if defined (__STDC__) && __STDC__
Packit 15a96c
static const char *_getopt_initialize (int, char *const *, const char *);
Packit 15a96c
#endif
Packit 15a96c
static const char *
Packit 15a96c
_getopt_initialize (argc, argv, optstring)
Packit 15a96c
     int argc;
Packit 15a96c
     char *const *argv;
Packit 15a96c
     const char *optstring;
Packit 15a96c
{
Packit 15a96c
  /* Start processing options with ARGV-element 1 (since ARGV-element 0
Packit 15a96c
     is the program name); the sequence of previously skipped
Packit 15a96c
     non-option ARGV-elements is empty.  */
Packit 15a96c
Packit 15a96c
  first_nonopt = last_nonopt = optind = 1;
Packit 15a96c
Packit 15a96c
  nextchar = NULL;
Packit 15a96c
Packit 15a96c
  posixly_correct = getenv ("POSIXLY_CORRECT");
Packit 15a96c
Packit 15a96c
  /* Determine how to handle the ordering of options and nonoptions.  */
Packit 15a96c
Packit 15a96c
  if (optstring[0] == '-')
Packit 15a96c
    {
Packit 15a96c
      ordering = RETURN_IN_ORDER;
Packit 15a96c
      ++optstring;
Packit 15a96c
    }
Packit 15a96c
  else if (optstring[0] == '+')
Packit 15a96c
    {
Packit 15a96c
      ordering = REQUIRE_ORDER;
Packit 15a96c
      ++optstring;
Packit 15a96c
    }
Packit 15a96c
  else if (posixly_correct != NULL)
Packit 15a96c
    ordering = REQUIRE_ORDER;
Packit 15a96c
  else
Packit 15a96c
    ordering = PERMUTE;
Packit 15a96c
Packit 15a96c
#ifdef _LIBC
Packit 15a96c
  if (posixly_correct == NULL
Packit 15a96c
      && argc == original_argc && argv == original_argv)
Packit 15a96c
    {
Packit 15a96c
      /* Bash 2.0 puts a special variable in the environment for each
Packit 15a96c
	 command it runs, specifying which ARGV elements are the results of
Packit 15a96c
	 file name wildcard expansion and therefore should not be
Packit 15a96c
	 considered as options.  */
Packit 15a96c
      char var[100];
Packit 15a96c
      sprintf (var, "_%d_GNU_nonoption_argv_flags_", getpid ());
Packit 15a96c
      nonoption_flags = getenv (var);
Packit 15a96c
      if (nonoption_flags == NULL)
Packit 15a96c
	nonoption_flags_len = 0;
Packit 15a96c
      else
Packit 15a96c
	nonoption_flags_len = strlen (nonoption_flags);
Packit 15a96c
    }
Packit 15a96c
  else
Packit 15a96c
    nonoption_flags_len = 0;
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
  return optstring;
Packit 15a96c
}
Packit 15a96c

Packit 15a96c
/* Scan elements of ARGV (whose length is ARGC) for option characters
Packit 15a96c
   given in OPTSTRING.
Packit 15a96c
Packit 15a96c
   If an element of ARGV starts with '-', and is not exactly "-" or "--",
Packit 15a96c
   then it is an option element.  The characters of this element
Packit 15a96c
   (aside from the initial '-') are option characters.  If `getopt'
Packit 15a96c
   is called repeatedly, it returns successively each of the option characters
Packit 15a96c
   from each of the option elements.
Packit 15a96c
Packit 15a96c
   If `getopt' finds another option character, it returns that character,
Packit 15a96c
   updating `optind' and `nextchar' so that the next call to `getopt' can
Packit 15a96c
   resume the scan with the following option character or ARGV-element.
Packit 15a96c
Packit 15a96c
   If there are no more option characters, `getopt' returns -1.
Packit 15a96c
   Then `optind' is the index in ARGV of the first ARGV-element
Packit 15a96c
   that is not an option.  (The ARGV-elements have been permuted
Packit 15a96c
   so that those that are not options now come last.)
Packit 15a96c
Packit 15a96c
   OPTSTRING is a string containing the legitimate option characters.
Packit 15a96c
   If an option character is seen that is not listed in OPTSTRING,
Packit 15a96c
   return '?' after printing an error message.  If you set `opterr' to
Packit 15a96c
   zero, the error message is suppressed but we still return '?'.
Packit 15a96c
Packit 15a96c
   If a char in OPTSTRING is followed by a colon, that means it wants an arg,
Packit 15a96c
   so the following text in the same ARGV-element, or the text of the following
Packit 15a96c
   ARGV-element, is returned in `optarg'.  Two colons mean an option that
Packit 15a96c
   wants an optional arg; if there is text in the current ARGV-element,
Packit 15a96c
   it is returned in `optarg', otherwise `optarg' is set to zero.
Packit 15a96c
Packit 15a96c
   If OPTSTRING starts with `-' or `+', it requests different methods of
Packit 15a96c
   handling the non-option ARGV-elements.
Packit 15a96c
   See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
Packit 15a96c
Packit 15a96c
   Long-named options begin with `--' instead of `-'.
Packit 15a96c
   Their names may be abbreviated as long as the abbreviation is unique
Packit 15a96c
   or is an exact match for some defined option.  If they have an
Packit 15a96c
   argument, it follows the option name in the same ARGV-element, separated
Packit 15a96c
   from the option name by a `=', or else the in next ARGV-element.
Packit 15a96c
   When `getopt' finds a long-named option, it returns 0 if that option's
Packit 15a96c
   `flag' field is nonzero, the value of the option's `val' field
Packit 15a96c
   if the `flag' field is zero.
Packit 15a96c
Packit 15a96c
   The elements of ARGV aren't really const, because we permute them.
Packit 15a96c
   But we pretend they're const in the prototype to be compatible
Packit 15a96c
   with other systems.
Packit 15a96c
Packit 15a96c
   LONGOPTS is a vector of `struct option' terminated by an
Packit 15a96c
   element containing a name which is zero.
Packit 15a96c
Packit 15a96c
   LONGIND returns the index in LONGOPT of the long-named option found.
Packit 15a96c
   It is only valid when a long-named option has been found by the most
Packit 15a96c
   recent call.
Packit 15a96c
Packit 15a96c
   If LONG_ONLY is nonzero, '-' as well as '--' can introduce
Packit 15a96c
   long-named options.  */
Packit 15a96c
Packit 15a96c
int
Packit 15a96c
_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
Packit 15a96c
     int argc;
Packit 15a96c
     char *const *argv;
Packit 15a96c
     const char *optstring;
Packit 15a96c
     const struct option *longopts;
Packit 15a96c
     int *longind;
Packit 15a96c
     int long_only;
Packit 15a96c
{
Packit 15a96c
  optarg = NULL;
Packit 15a96c
Packit 15a96c
  if (!__getopt_initialized || optind == 0)
Packit 15a96c
    {
Packit 15a96c
      optstring = _getopt_initialize (argc, argv, optstring);
Packit 15a96c
      optind = 1;		/* Don't scan ARGV[0], the program name.  */
Packit 15a96c
      __getopt_initialized = 1;
Packit 15a96c
    }
Packit 15a96c
Packit 15a96c
  /* Test whether ARGV[optind] points to a non-option argument.
Packit 15a96c
     Either it does not have option syntax, or there is an environment flag
Packit 15a96c
     from the shell indicating it is not an option.  The later information
Packit 15a96c
     is only used when the used in the GNU libc.  */
Packit 15a96c
#ifdef _LIBC
Packit 15a96c
#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0'	      \
Packit 15a96c
		     || (optind < nonoption_flags_len			      \
Packit 15a96c
			 && nonoption_flags[optind] == '1'))
Packit 15a96c
#else
Packit 15a96c
#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
Packit 15a96c
#endif
Packit 15a96c
Packit 15a96c
  if (nextchar == NULL || *nextchar == '\0')
Packit 15a96c
    {
Packit 15a96c
      /* Advance to the next ARGV-element.  */
Packit 15a96c
Packit 15a96c
      /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
Packit 15a96c
	 moved back by the user (who may also have changed the arguments).  */
Packit 15a96c
      if (last_nonopt > optind)
Packit 15a96c
	last_nonopt = optind;
Packit 15a96c
      if (first_nonopt > optind)
Packit 15a96c
	first_nonopt = optind;
Packit 15a96c
Packit 15a96c
      if (ordering == PERMUTE)
Packit 15a96c
	{
Packit 15a96c
	  /* If we have just processed some options following some non-options,
Packit 15a96c
	     exchange them so that the options come first.  */
Packit 15a96c
Packit 15a96c
	  if (first_nonopt != last_nonopt && last_nonopt != optind)
Packit 15a96c
	    exchange ((char **) argv);
Packit 15a96c
	  else if (last_nonopt != optind)
Packit 15a96c
	    first_nonopt = optind;
Packit 15a96c
Packit 15a96c
	  /* Skip any additional non-options
Packit 15a96c
	     and extend the range of non-options previously skipped.  */
Packit 15a96c
Packit 15a96c
	  while (optind < argc && NONOPTION_P)
Packit 15a96c
	    optind++;
Packit 15a96c
	  last_nonopt = optind;
Packit 15a96c
	}
Packit 15a96c
Packit 15a96c
      /* The special ARGV-element `--' means premature end of options.
Packit 15a96c
	 Skip it like a null option,
Packit 15a96c
	 then exchange with previous non-options as if it were an option,
Packit 15a96c
	 then skip everything else like a non-option.  */
Packit 15a96c
Packit 15a96c
      if (optind != argc && !strcmp (argv[optind], "--"))
Packit 15a96c
	{
Packit 15a96c
	  optind++;
Packit 15a96c
Packit 15a96c
	  if (first_nonopt != last_nonopt && last_nonopt != optind)
Packit 15a96c
	    exchange ((char **) argv);
Packit 15a96c
	  else if (first_nonopt == last_nonopt)
Packit 15a96c
	    first_nonopt = optind;
Packit 15a96c
	  last_nonopt = argc;
Packit 15a96c
Packit 15a96c
	  optind = argc;
Packit 15a96c
	}
Packit 15a96c
Packit 15a96c
      /* If we have done all the ARGV-elements, stop the scan
Packit 15a96c
	 and back over any non-options that we skipped and permuted.  */
Packit 15a96c
Packit 15a96c
      if (optind == argc)
Packit 15a96c
	{
Packit 15a96c
	  /* Set the next-arg-index to point at the non-options
Packit 15a96c
	     that we previously skipped, so the caller will digest them.  */
Packit 15a96c
	  if (first_nonopt != last_nonopt)
Packit 15a96c
	    optind = first_nonopt;
Packit 15a96c
	  return -1;
Packit 15a96c
	}
Packit 15a96c
Packit 15a96c
      /* If we have come to a non-option and did not permute it,
Packit 15a96c
	 either stop the scan or describe it to the caller and pass it by.  */
Packit 15a96c
Packit 15a96c
      if (NONOPTION_P)
Packit 15a96c
	{
Packit 15a96c
	  if (ordering == REQUIRE_ORDER)
Packit 15a96c
	    return -1;
Packit 15a96c
	  optarg = argv[optind++];
Packit 15a96c
	  return 1;
Packit 15a96c
	}
Packit 15a96c
Packit 15a96c
      /* We have found another option-ARGV-element.
Packit 15a96c
	 Skip the initial punctuation.  */
Packit 15a96c
Packit 15a96c
      nextchar = (argv[optind] + 1
Packit 15a96c
		  + (longopts != NULL && argv[optind][1] == '-'));
Packit 15a96c
    }
Packit 15a96c
Packit 15a96c
  /* Decode the current option-ARGV-element.  */
Packit 15a96c
Packit 15a96c
  /* Check whether the ARGV-element is a long option.
Packit 15a96c
Packit 15a96c
     If long_only and the ARGV-element has the form "-f", where f is
Packit 15a96c
     a valid short option, don't consider it an abbreviated form of
Packit 15a96c
     a long option that starts with f.  Otherwise there would be no
Packit 15a96c
     way to give the -f short option.
Packit 15a96c
Packit 15a96c
     On the other hand, if there's a long option "fubar" and
Packit 15a96c
     the ARGV-element is "-fu", do consider that an abbreviation of
Packit 15a96c
     the long option, just like "--fu", and not "-f" with arg "u".
Packit 15a96c
Packit 15a96c
     This distinction seems to be the most useful approach.  */
Packit 15a96c
Packit 15a96c
  if (longopts != NULL
Packit 15a96c
      && (argv[optind][1] == '-'
Packit 15a96c
	  || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
Packit 15a96c
    {
Packit 15a96c
      char *nameend;
Packit 15a96c
      const struct option *p;
Packit 15a96c
      const struct option *pfound = NULL;
Packit 15a96c
      int exact = 0;
Packit 15a96c
      int ambig = 0;
Packit 15a96c
      int indfound = -1;
Packit 15a96c
      int option_index;
Packit 15a96c
Packit 15a96c
      for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
Packit 15a96c
	/* Do nothing.  */ ;
Packit 15a96c
Packit 15a96c
      /* Test all long options for either exact match
Packit 15a96c
	 or abbreviated matches.  */
Packit 15a96c
      for (p = longopts, option_index = 0; p->name; p++, option_index++)
Packit 15a96c
	if (!strncmp (p->name, nextchar, nameend - nextchar))
Packit 15a96c
	  {
Packit 15a96c
	    if ((unsigned int) (nameend - nextchar)
Packit 15a96c
		== (unsigned int) strlen (p->name))
Packit 15a96c
	      {
Packit 15a96c
		/* Exact match found.  */
Packit 15a96c
		pfound = p;
Packit 15a96c
		indfound = option_index;
Packit 15a96c
		exact = 1;
Packit 15a96c
		break;
Packit 15a96c
	      }
Packit 15a96c
	    else if (pfound == NULL)
Packit 15a96c
	      {
Packit 15a96c
		/* First nonexact match found.  */
Packit 15a96c
		pfound = p;
Packit 15a96c
		indfound = option_index;
Packit 15a96c
	      }
Packit 15a96c
	    else
Packit 15a96c
	      /* Second or later nonexact match found.  */
Packit 15a96c
	      ambig = 1;
Packit 15a96c
	  }
Packit 15a96c
Packit 15a96c
      if (ambig && !exact)
Packit 15a96c
	{
Packit 15a96c
	  if (opterr)
Packit 15a96c
	    fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
Packit 15a96c
		     argv[0], argv[optind]);
Packit 15a96c
	  nextchar += strlen (nextchar);
Packit 15a96c
	  optind++;
Packit 15a96c
	  optopt = 0;
Packit 15a96c
	  return '?';
Packit 15a96c
	}
Packit 15a96c
Packit 15a96c
      if (pfound != NULL)
Packit 15a96c
	{
Packit 15a96c
	  option_index = indfound;
Packit 15a96c
	  optind++;
Packit 15a96c
	  if (*nameend)
Packit 15a96c
	    {
Packit 15a96c
	      /* Don't test has_arg with >, because some C compilers don't
Packit 15a96c
		 allow it to be used on enums.  */
Packit 15a96c
	      if (pfound->has_arg)
Packit 15a96c
		optarg = nameend + 1;
Packit 15a96c
	      else
Packit 15a96c
		{
Packit 15a96c
		  if (opterr)
Packit 15a96c
		   if (argv[optind - 1][1] == '-')
Packit 15a96c
		    /* --option */
Packit 15a96c
		    fprintf (stderr,
Packit 15a96c
		     _("%s: option `--%s' doesn't allow an argument\n"),
Packit 15a96c
		     argv[0], pfound->name);
Packit 15a96c
		   else
Packit 15a96c
		    /* +option or -option */
Packit 15a96c
		    fprintf (stderr,
Packit 15a96c
		     _("%s: option `%c%s' doesn't allow an argument\n"),
Packit 15a96c
		     argv[0], argv[optind - 1][0], pfound->name);
Packit 15a96c
Packit 15a96c
		  nextchar += strlen (nextchar);
Packit 15a96c
Packit 15a96c
		  optopt = pfound->val;
Packit 15a96c
		  return '?';
Packit 15a96c
		}
Packit 15a96c
	    }
Packit 15a96c
	  else if (pfound->has_arg == 1)
Packit 15a96c
	    {
Packit 15a96c
	      if (optind < argc)
Packit 15a96c
		optarg = argv[optind++];
Packit 15a96c
	      else
Packit 15a96c
		{
Packit 15a96c
		  if (opterr)
Packit 15a96c
		    fprintf (stderr,
Packit 15a96c
			   _("%s: option `%s' requires an argument\n"),
Packit 15a96c
			   argv[0], argv[optind - 1]);
Packit 15a96c
		  nextchar += strlen (nextchar);
Packit 15a96c
		  optopt = pfound->val;
Packit 15a96c
		  return optstring[0] == ':' ? ':' : '?';
Packit 15a96c
		}
Packit 15a96c
	    }
Packit 15a96c
	  nextchar += strlen (nextchar);
Packit 15a96c
	  if (longind != NULL)
Packit 15a96c
	    *longind = option_index;
Packit 15a96c
	  if (pfound->flag)
Packit 15a96c
	    {
Packit 15a96c
	      *(pfound->flag) = pfound->val;
Packit 15a96c
	      return 0;
Packit 15a96c
	    }
Packit 15a96c
	  return pfound->val;
Packit 15a96c
	}
Packit 15a96c
Packit 15a96c
      /* Can't find it as a long option.  If this is not getopt_long_only,
Packit 15a96c
	 or the option starts with '--' or is not a valid short
Packit 15a96c
	 option, then it's an error.
Packit 15a96c
	 Otherwise interpret it as a short option.  */
Packit 15a96c
      if (!long_only || argv[optind][1] == '-'
Packit 15a96c
	  || my_index (optstring, *nextchar) == NULL)
Packit 15a96c
	{
Packit 15a96c
	  if (opterr)
Packit 15a96c
	    {
Packit 15a96c
	      if (argv[optind][1] == '-')
Packit 15a96c
		/* --option */
Packit 15a96c
		fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
Packit 15a96c
			 argv[0], nextchar);
Packit 15a96c
	      else
Packit 15a96c
		/* +option or -option */
Packit 15a96c
		fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
Packit 15a96c
			 argv[0], argv[optind][0], nextchar);
Packit 15a96c
	    }
Packit 15a96c
	  nextchar = (char *) "";
Packit 15a96c
	  optind++;
Packit 15a96c
	  optopt = 0;
Packit 15a96c
	  return '?';
Packit 15a96c
	}
Packit 15a96c
    }
Packit 15a96c
Packit 15a96c
  /* Look at and handle the next short option-character.  */
Packit 15a96c
Packit 15a96c
  {
Packit 15a96c
    char c = *nextchar++;
Packit 15a96c
    char *temp = my_index (optstring, c);
Packit 15a96c
Packit 15a96c
    /* Increment `optind' when we start to process its last character.  */
Packit 15a96c
    if (*nextchar == '\0')
Packit 15a96c
      ++optind;
Packit 15a96c
Packit 15a96c
    if (temp == NULL || c == ':')
Packit 15a96c
      {
Packit 15a96c
	if (opterr)
Packit 15a96c
	  {
Packit 15a96c
	    if (posixly_correct)
Packit 15a96c
	      /* 1003.2 specifies the format of this message.  */
Packit 15a96c
	      fprintf (stderr, _("%s: illegal option -- %c\n"),
Packit 15a96c
		       argv[0], c);
Packit 15a96c
	    else
Packit 15a96c
	      fprintf (stderr, _("%s: invalid option -- %c\n"),
Packit 15a96c
		       argv[0], c);
Packit 15a96c
	  }
Packit 15a96c
	optopt = c;
Packit 15a96c
	return '?';
Packit 15a96c
      }
Packit 15a96c
    /* Convenience. Treat POSIX -W foo same as long option --foo */
Packit 15a96c
    if (temp[0] == 'W' && temp[1] == ';')
Packit 15a96c
      {
Packit 15a96c
	char *nameend;
Packit 15a96c
	const struct option *p;
Packit 15a96c
	const struct option *pfound = NULL;
Packit 15a96c
	int exact = 0;
Packit 15a96c
	int ambig = 0;
Packit 15a96c
	int indfound = 0;
Packit 15a96c
	int option_index;
Packit 15a96c
Packit 15a96c
	/* This is an option that requires an argument.  */
Packit 15a96c
	if (*nextchar != '\0')
Packit 15a96c
	  {
Packit 15a96c
	    optarg = nextchar;
Packit 15a96c
	    /* If we end this ARGV-element by taking the rest as an arg,
Packit 15a96c
	       we must advance to the next element now.  */
Packit 15a96c
	    optind++;
Packit 15a96c
	  }
Packit 15a96c
	else if (optind == argc)
Packit 15a96c
	  {
Packit 15a96c
	    if (opterr)
Packit 15a96c
	      {
Packit 15a96c
		/* 1003.2 specifies the format of this message.  */
Packit 15a96c
		fprintf (stderr, _("%s: option requires an argument -- %c\n"),
Packit 15a96c
			 argv[0], c);
Packit 15a96c
	      }
Packit 15a96c
	    optopt = c;
Packit 15a96c
	    if (optstring[0] == ':')
Packit 15a96c
	      c = ':';
Packit 15a96c
	    else
Packit 15a96c
	      c = '?';
Packit 15a96c
	    return c;
Packit 15a96c
	  }
Packit 15a96c
	else
Packit 15a96c
	  /* We already incremented `optind' once;
Packit 15a96c
	     increment it again when taking next ARGV-elt as argument.  */
Packit 15a96c
	  optarg = argv[optind++];
Packit 15a96c
Packit 15a96c
	/* optarg is now the argument, see if it's in the
Packit 15a96c
	   table of longopts.  */
Packit 15a96c
Packit 15a96c
	for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
Packit 15a96c
	  /* Do nothing.  */ ;
Packit 15a96c
Packit 15a96c
	/* Test all long options for either exact match
Packit 15a96c
	   or abbreviated matches.  */
Packit 15a96c
	for (p = longopts, option_index = 0; p->name; p++, option_index++)
Packit 15a96c
	  if (!strncmp (p->name, nextchar, nameend - nextchar))
Packit 15a96c
	    {
Packit 15a96c
	      if ((unsigned int) (nameend - nextchar) == strlen (p->name))
Packit 15a96c
		{
Packit 15a96c
		  /* Exact match found.  */
Packit 15a96c
		  pfound = p;
Packit 15a96c
		  indfound = option_index;
Packit 15a96c
		  exact = 1;
Packit 15a96c
		  break;
Packit 15a96c
		}
Packit 15a96c
	      else if (pfound == NULL)
Packit 15a96c
		{
Packit 15a96c
		  /* First nonexact match found.  */
Packit 15a96c
		  pfound = p;
Packit 15a96c
		  indfound = option_index;
Packit 15a96c
		}
Packit 15a96c
	      else
Packit 15a96c
		/* Second or later nonexact match found.  */
Packit 15a96c
		ambig = 1;
Packit 15a96c
	    }
Packit 15a96c
	if (ambig && !exact)
Packit 15a96c
	  {
Packit 15a96c
	    if (opterr)
Packit 15a96c
	      fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
Packit 15a96c
		       argv[0], argv[optind]);
Packit 15a96c
	    nextchar += strlen (nextchar);
Packit 15a96c
	    optind++;
Packit 15a96c
	    return '?';
Packit 15a96c
	  }
Packit 15a96c
	if (pfound != NULL)
Packit 15a96c
	  {
Packit 15a96c
	    option_index = indfound;
Packit 15a96c
	    if (*nameend)
Packit 15a96c
	      {
Packit 15a96c
		/* Don't test has_arg with >, because some C compilers don't
Packit 15a96c
		   allow it to be used on enums.  */
Packit 15a96c
		if (pfound->has_arg)
Packit 15a96c
		  optarg = nameend + 1;
Packit 15a96c
		else
Packit 15a96c
		  {
Packit 15a96c
		    if (opterr)
Packit 15a96c
		      fprintf (stderr, _("\
Packit 15a96c
%s: option `-W %s' doesn't allow an argument\n"),
Packit 15a96c
			       argv[0], pfound->name);
Packit 15a96c
Packit 15a96c
		    nextchar += strlen (nextchar);
Packit 15a96c
		    return '?';
Packit 15a96c
		  }
Packit 15a96c
	      }
Packit 15a96c
	    else if (pfound->has_arg == 1)
Packit 15a96c
	      {
Packit 15a96c
		if (optind < argc)
Packit 15a96c
		  optarg = argv[optind++];
Packit 15a96c
		else
Packit 15a96c
		  {
Packit 15a96c
		    if (opterr)
Packit 15a96c
		      fprintf (stderr,
Packit 15a96c
			       _("%s: option `%s' requires an argument\n"),
Packit 15a96c
			       argv[0], argv[optind - 1]);
Packit 15a96c
		    nextchar += strlen (nextchar);
Packit 15a96c
		    return optstring[0] == ':' ? ':' : '?';
Packit 15a96c
		  }
Packit 15a96c
	      }
Packit 15a96c
	    nextchar += strlen (nextchar);
Packit 15a96c
	    if (longind != NULL)
Packit 15a96c
	      *longind = option_index;
Packit 15a96c
	    if (pfound->flag)
Packit 15a96c
	      {
Packit 15a96c
		*(pfound->flag) = pfound->val;
Packit 15a96c
		return 0;
Packit 15a96c
	      }
Packit 15a96c
	    return pfound->val;
Packit 15a96c
	  }
Packit 15a96c
	  nextchar = NULL;
Packit 15a96c
	  return 'W';	/* Let the application handle it.   */
Packit 15a96c
      }
Packit 15a96c
    if (temp[1] == ':')
Packit 15a96c
      {
Packit 15a96c
	if (temp[2] == ':')
Packit 15a96c
	  {
Packit 15a96c
	    /* This is an option that accepts an argument optionally.  */
Packit 15a96c
	    if (*nextchar != '\0')
Packit 15a96c
	      {
Packit 15a96c
		optarg = nextchar;
Packit 15a96c
		optind++;
Packit 15a96c
	      }
Packit 15a96c
	    else
Packit 15a96c
	      optarg = NULL;
Packit 15a96c
	    nextchar = NULL;
Packit 15a96c
	  }
Packit 15a96c
	else
Packit 15a96c
	  {
Packit 15a96c
	    /* This is an option that requires an argument.  */
Packit 15a96c
	    if (*nextchar != '\0')
Packit 15a96c
	      {
Packit 15a96c
		optarg = nextchar;
Packit 15a96c
		/* If we end this ARGV-element by taking the rest as an arg,
Packit 15a96c
		   we must advance to the next element now.  */
Packit 15a96c
		optind++;
Packit 15a96c
	      }
Packit 15a96c
	    else if (optind == argc)
Packit 15a96c
	      {
Packit 15a96c
		if (opterr)
Packit 15a96c
		  {
Packit 15a96c
		    /* 1003.2 specifies the format of this message.  */
Packit 15a96c
		    fprintf (stderr,
Packit 15a96c
			   _("%s: option requires an argument -- %c\n"),
Packit 15a96c
			   argv[0], c);
Packit 15a96c
		  }
Packit 15a96c
		optopt = c;
Packit 15a96c
		if (optstring[0] == ':')
Packit 15a96c
		  c = ':';
Packit 15a96c
		else
Packit 15a96c
		  c = '?';
Packit 15a96c
	      }
Packit 15a96c
	    else
Packit 15a96c
	      /* We already incremented `optind' once;
Packit 15a96c
		 increment it again when taking next ARGV-elt as argument.  */
Packit 15a96c
	      optarg = argv[optind++];
Packit 15a96c
	    nextchar = NULL;
Packit 15a96c
	  }
Packit 15a96c
      }
Packit 15a96c
    return c;
Packit 15a96c
  }
Packit 15a96c
}
Packit 15a96c
Packit 15a96c
int
Packit 15a96c
getopt (argc, argv, optstring)
Packit 15a96c
     int argc;
Packit 15a96c
     char *const *argv;
Packit 15a96c
     const char *optstring;
Packit 15a96c
{
Packit 15a96c
  return _getopt_internal (argc, argv, optstring,
Packit 15a96c
			   (const struct option *) 0,
Packit 15a96c
			   (int *) 0,
Packit 15a96c
			   0);
Packit 15a96c
}
Packit 15a96c
Packit 15a96c
#endif	/* Not ELIDE_CODE.  */
Packit 15a96c

Packit 15a96c
#ifdef TEST
Packit 15a96c
Packit 15a96c
/* Compile with -DTEST to make an executable for use in testing
Packit 15a96c
   the above definition of `getopt'.  */
Packit 15a96c
Packit 15a96c
int
Packit 15a96c
main (argc, argv)
Packit 15a96c
     int argc;
Packit 15a96c
     char **argv;
Packit 15a96c
{
Packit 15a96c
  int c;
Packit 15a96c
  int digit_optind = 0;
Packit 15a96c
Packit 15a96c
  while (1)
Packit 15a96c
    {
Packit 15a96c
      int this_option_optind = optind ? optind : 1;
Packit 15a96c
Packit 15a96c
      c = getopt (argc, argv, "abc:d:0123456789");
Packit 15a96c
      if (c == -1)
Packit 15a96c
	break;
Packit 15a96c
Packit 15a96c
      switch (c)
Packit 15a96c
	{
Packit 15a96c
	case '0':
Packit 15a96c
	case '1':
Packit 15a96c
	case '2':
Packit 15a96c
	case '3':
Packit 15a96c
	case '4':
Packit 15a96c
	case '5':
Packit 15a96c
	case '6':
Packit 15a96c
	case '7':
Packit 15a96c
	case '8':
Packit 15a96c
	case '9':
Packit 15a96c
	  if (digit_optind != 0 && digit_optind != this_option_optind)
Packit 15a96c
	    printf ("digits occur in two different argv-elements.\n");
Packit 15a96c
	  digit_optind = this_option_optind;
Packit 15a96c
	  printf ("option %c\n", c);
Packit 15a96c
	  break;
Packit 15a96c
Packit 15a96c
	case 'a':
Packit 15a96c
	  printf ("option a\n");
Packit 15a96c
	  break;
Packit 15a96c
Packit 15a96c
	case 'b':
Packit 15a96c
	  printf ("option b\n");
Packit 15a96c
	  break;
Packit 15a96c
Packit 15a96c
	case 'c':
Packit 15a96c
	  printf ("option c with value `%s'\n", optarg);
Packit 15a96c
	  break;
Packit 15a96c
Packit 15a96c
	case '?':
Packit 15a96c
	  break;
Packit 15a96c
Packit 15a96c
	default:
Packit 15a96c
	  printf ("?? getopt returned character code 0%o ??\n", c);
Packit 15a96c
	}
Packit 15a96c
    }
Packit 15a96c
Packit 15a96c
  if (optind < argc)
Packit 15a96c
    {
Packit 15a96c
      printf ("non-option ARGV-elements: ");
Packit 15a96c
      while (optind < argc)
Packit 15a96c
	printf ("%s ", argv[optind++]);
Packit 15a96c
      printf ("\n");
Packit 15a96c
    }
Packit 15a96c
Packit 15a96c
  exit (0);
Packit 15a96c
}
Packit 15a96c
Packit 15a96c
#endif /* TEST */