Blame portability/getopt.h

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