Blame src/getopt.h

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