Blame support/getopt.h

Packit 575503
/* Declarations for getopt.
Packit 575503
   Copyright (C) 1989-2016 Free Software Foundation, Inc.
Packit 575503
   This file is part of the GNU C Library.
Packit 575503
Packit 575503
   The GNU C Library is free software; you can redistribute it and/or
Packit 575503
   modify it under the terms of the GNU Lesser General Public
Packit 575503
   License as published by the Free Software Foundation; either
Packit 575503
   version 2.1 of the License, or (at your option) any later version.
Packit 575503
Packit 575503
   The GNU C Library is distributed in the hope that it will be useful,
Packit 575503
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 575503
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 575503
   Lesser General Public License for more details.
Packit 575503
Packit 575503
   You should have received a copy of the GNU Lesser General Public
Packit 575503
   License along with the GNU C Library; if not, see
Packit 575503
   <http://www.gnu.org/licenses/>.  */
Packit 575503
Packit 575503
#ifndef _GETOPT_H
Packit 575503
Packit 575503
#ifndef __need_getopt
Packit 575503
# define _GETOPT_H 1
Packit 575503
#endif
Packit 575503
Packit 575503
/* If __GNU_LIBRARY__ is not already defined, either we are being used
Packit 575503
   standalone, or this is the first header included in the source file.
Packit 575503
   If we are being used with glibc, we need to include <features.h>, but
Packit 575503
   that does not exist if we are standalone.  So: if __GNU_LIBRARY__ is
Packit 575503
   not defined, include <ctype.h>, which will pull in <features.h> for us
Packit 575503
   if it's from glibc.  (Why ctype.h?  It's guaranteed to exist and it
Packit 575503
   doesn't flood the namespace with stuff the way some other headers do.)  */
Packit 575503
#if !defined __GNU_LIBRARY__
Packit 575503
# include <ctype.h>
Packit 575503
#endif
Packit 575503
Packit 575503
#ifndef __THROW
Packit 575503
# ifndef __GNUC_PREREQ
Packit 575503
#  define __GNUC_PREREQ(maj, min) (0)
Packit 575503
# endif
Packit 575503
# if defined __cplusplus && __GNUC_PREREQ (2,8)
Packit 575503
#  define __THROW	throw ()
Packit 575503
# else
Packit 575503
#  define __THROW
Packit 575503
# endif
Packit 575503
#endif
Packit 575503
Packit 575503
#ifdef	__cplusplus
Packit 575503
extern "C" {
Packit 575503
#endif
Packit 575503
Packit 575503
#ifdef __KLIBC__
Packit 575503
/* OS/2 kLIBC has already getopt(). So to avoid name clash, rename
Packit 575503
   them here. */
Packit 575503
Packit 575503
# define optarg		gawk_optarg
Packit 575503
# define optind		gawk_optind
Packit 575503
# define opterr		gawk_opterr
Packit 575503
# define optopt		gawk_optopt
Packit 575503
Packit 575503
# define getopt				gawk_getopt
Packit 575503
# define getopt_long		gawk_getopt_long
Packit 575503
# define getopt_long_only	gawk_getopt_long_only
Packit 575503
#endif
Packit 575503
Packit 575503
Packit 575503
/* For communication from `getopt' to the caller.
Packit 575503
   When `getopt' finds an option that takes an argument,
Packit 575503
   the argument value is returned here.
Packit 575503
   Also, when `ordering' is RETURN_IN_ORDER,
Packit 575503
   each non-option ARGV-element is returned here.  */
Packit 575503
Packit 575503
extern char *optarg;
Packit 575503
Packit 575503
/* Index in ARGV of the next element to be scanned.
Packit 575503
   This is used for communication to and from the caller
Packit 575503
   and for communication between successive calls to `getopt'.
Packit 575503
Packit 575503
   On entry to `getopt', zero means this is the first call; initialize.
Packit 575503
Packit 575503
   When `getopt' returns -1, this is the index of the first of the
Packit 575503
   non-option elements that the caller should itself scan.
Packit 575503
Packit 575503
   Otherwise, `optind' communicates from one call to the next
Packit 575503
   how much of ARGV has been scanned so far.  */
Packit 575503
Packit 575503
extern int optind;
Packit 575503
Packit 575503
/* Callers store zero here to inhibit the error message `getopt' prints
Packit 575503
   for unrecognized options.  */
Packit 575503
Packit 575503
extern int opterr;
Packit 575503
Packit 575503
/* Set to an option character which was unrecognized.  */
Packit 575503
Packit 575503
extern int optopt;
Packit 575503
Packit 575503
#ifndef __need_getopt
Packit 575503
/* Describe the long-named options requested by the application.
Packit 575503
   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
Packit 575503
   of `struct option' terminated by an element containing a name which is
Packit 575503
   zero.
Packit 575503
Packit 575503
   The field `has_arg' is:
Packit 575503
   no_argument		(or 0) if the option does not take an argument,
Packit 575503
   required_argument	(or 1) if the option requires an argument,
Packit 575503
   optional_argument 	(or 2) if the option takes an optional argument.
Packit 575503
Packit 575503
   If the field `flag' is not NULL, it points to a variable that is set
Packit 575503
   to the value given in the field `val' when the option is found, but
Packit 575503
   left unchanged if the option is not found.
Packit 575503
Packit 575503
   To have a long-named option do something other than set an `int' to
Packit 575503
   a compiled-in constant, such as set a value from `optarg', set the
Packit 575503
   option's `flag' field to zero and its `val' field to a nonzero
Packit 575503
   value (the equivalent single-letter option character, if there is
Packit 575503
   one).  For long options that have a zero `flag' field, `getopt'
Packit 575503
   returns the contents of the `val' field.  */
Packit 575503
Packit 575503
struct option
Packit 575503
{
Packit 575503
  const char *name;
Packit 575503
  /* has_arg can't be an enum because some compilers complain about
Packit 575503
     type mismatches in all the code that assumes it is an int.  */
Packit 575503
  int has_arg;
Packit 575503
  int *flag;
Packit 575503
  int val;
Packit 575503
};
Packit 575503
Packit 575503
/* Names for the values of the `has_arg' field of `struct option'.  */
Packit 575503
Packit 575503
# define no_argument		0
Packit 575503
# define required_argument	1
Packit 575503
# define optional_argument	2
Packit 575503
#endif	/* need getopt */
Packit 575503
Packit 575503
Packit 575503
/* Get definitions and prototypes for functions to process the
Packit 575503
   arguments in ARGV (ARGC of them, minus the program name) for
Packit 575503
   options given in OPTS.
Packit 575503
Packit 575503
   Return the option character from OPTS just read.  Return -1 when
Packit 575503
   there are no more options.  For unrecognized options, or options
Packit 575503
   missing arguments, `optopt' is set to the option letter, and '?' is
Packit 575503
   returned.
Packit 575503
Packit 575503
   The OPTS string is a list of characters which are recognized option
Packit 575503
   letters, optionally followed by colons, specifying that that letter
Packit 575503
   takes an argument, to be placed in `optarg'.
Packit 575503
Packit 575503
   If a letter in OPTS is followed by two colons, its argument is
Packit 575503
   optional.  This behavior is specific to the GNU `getopt'.
Packit 575503
Packit 575503
   The argument `--' causes premature termination of argument
Packit 575503
   scanning, explicitly telling `getopt' that there are no more
Packit 575503
   options.
Packit 575503
Packit 575503
   If OPTS begins with `--', then non-option arguments are treated as
Packit 575503
   arguments to the option '\0'.  This behavior is specific to the GNU
Packit 575503
   `getopt'.  */
Packit 575503
Packit 575503
#ifdef __GNU_LIBRARY__
Packit 575503
/* Many other libraries have conflicting prototypes for getopt, with
Packit 575503
   differences in the consts, in stdlib.h.  To avoid compilation
Packit 575503
   errors, only prototype getopt for the GNU C library.  */
Packit 575503
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
Packit 575503
       __THROW;
Packit 575503
Packit 575503
# if defined __need_getopt && defined __USE_POSIX2 \
Packit 575503
  && !defined __USE_POSIX_IMPLICITLY && !defined __USE_GNU
Packit 575503
/* The GNU getopt has more functionality than the standard version.  The
Packit 575503
   additional functionality can be disable at runtime.  This redirection
Packit 575503
   helps to also do this at runtime.  */
Packit 575503
#  ifdef __REDIRECT
Packit 575503
  extern int __REDIRECT_NTH (getopt, (int ___argc, char *const *___argv,
Packit 575503
				      const char *__shortopts),
Packit 575503
			     __posix_getopt);
Packit 575503
#  else
Packit 575503
extern int __posix_getopt (int ___argc, char *const *___argv,
Packit 575503
			   const char *__shortopts) __THROW;
Packit 575503
#   define getopt __posix_getopt
Packit 575503
#  endif
Packit 575503
# endif
Packit 575503
#else /* not __GNU_LIBRARY__ */
Packit 575503
extern int getopt ();
Packit 575503
#endif /* __GNU_LIBRARY__ */
Packit 575503
Packit 575503
#ifndef __need_getopt
Packit 575503
extern int getopt_long (int ___argc, char *const *___argv,
Packit 575503
			const char *__shortopts,
Packit 575503
		        const struct option *__longopts, int *__longind)
Packit 575503
       __THROW;
Packit 575503
extern int getopt_long_only (int ___argc, char *const *___argv,
Packit 575503
			     const char *__shortopts,
Packit 575503
		             const struct option *__longopts, int *__longind)
Packit 575503
       __THROW;
Packit 575503
Packit 575503
#endif
Packit 575503
Packit 575503
#ifdef	__cplusplus
Packit 575503
}
Packit 575503
#endif
Packit 575503
Packit 575503
/* Make sure we later can get all the definitions and declarations.  */
Packit 575503
#undef __need_getopt
Packit 575503
Packit 575503
#endif /* getopt.h */