/* Declarations for getopt.1Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.2This file is part of the GNU C Library.34This program is free software; you can redistribute it and/or modify5it under the terms of the GNU General Public License as published by6the Free Software Foundation; either version 2, or (at your option)7any later version.89This program is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12GNU General Public License for more details.1314You should have received a copy of the GNU General Public License15along with this program; if not, write to the Free Software Foundation,16Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */1718#ifndef _GETOPT_H1920#ifndef __need_getopt21# define _GETOPT_H 122#endif2324/* If __GNU_LIBRARY__ is not already defined, either we are being used25standalone, or this is the first header included in the source file.26If we are being used with glibc, we need to include <features.h>, but27that does not exist if we are standalone. So: if __GNU_LIBRARY__ is28not defined, include <ctype.h>, which will pull in <features.h> for us29if it's from glibc. (Why ctype.h? It's guaranteed to exist and it30doesn't flood the namespace with stuff the way some other headers do.) */31#if !defined __GNU_LIBRARY__32# include <ctype.h>33#endif3435#ifdef __cplusplus36extern "C" {37#endif3839/* For communication from `getopt' to the caller.40When `getopt' finds an option that takes an argument,41the argument value is returned here.42Also, when `ordering' is RETURN_IN_ORDER,43each non-option ARGV-element is returned here. */4445extern char *optarg;4647/* Index in ARGV of the next element to be scanned.48This is used for communication to and from the caller49and for communication between successive calls to `getopt'.5051On entry to `getopt', zero means this is the first call; initialize.5253When `getopt' returns -1, this is the index of the first of the54non-option elements that the caller should itself scan.5556Otherwise, `optind' communicates from one call to the next57how much of ARGV has been scanned so far. */5859extern int optind;6061/* Callers store zero here to inhibit the error message `getopt' prints62for unrecognized options. */6364extern int opterr;6566/* Set to an option character which was unrecognized. */6768extern int optopt;6970#ifndef __need_getopt71/* Describe the long-named options requested by the application.72The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector73of `struct option' terminated by an element containing a name which is74zero.7576The field `has_arg' is:77no_argument (or 0) if the option does not take an argument,78required_argument (or 1) if the option requires an argument,79optional_argument (or 2) if the option takes an optional argument.8081If the field `flag' is not NULL, it points to a variable that is set82to the value given in the field `val' when the option is found, but83left unchanged if the option is not found.8485To have a long-named option do something other than set an `int' to86a compiled-in constant, such as set a value from `optarg', set the87option's `flag' field to zero and its `val' field to a nonzero88value (the equivalent single-letter option character, if there is89one). For long options that have a zero `flag' field, `getopt'90returns the contents of the `val' field. */9192struct option93{94# if (defined __STDC__ && __STDC__) || defined __cplusplus95const char *name;96# else97char *name;98# endif99/* has_arg can't be an enum because some compilers complain about100type mismatches in all the code that assumes it is an int. */101int has_arg;102int *flag;103int val;104};105106/* Names for the values of the `has_arg' field of `struct option'. */107108# define no_argument 0109# define required_argument 1110# define optional_argument 2111#endif /* need getopt */112113114/* Get definitions and prototypes for functions to process the115arguments in ARGV (ARGC of them, minus the program name) for116options given in OPTS.117118Return the option character from OPTS just read. Return -1 when119there are no more options. For unrecognized options, or options120missing arguments, `optopt' is set to the option letter, and '?' is121returned.122123The OPTS string is a list of characters which are recognized option124letters, optionally followed by colons, specifying that that letter125takes an argument, to be placed in `optarg'.126127If a letter in OPTS is followed by two colons, its argument is128optional. This behavior is specific to the GNU `getopt'.129130The argument `--' causes premature termination of argument131scanning, explicitly telling `getopt' that there are no more132options.133134If OPTS begins with `--', then non-option arguments are treated as135arguments to the option '\0'. This behavior is specific to the GNU136`getopt'. */137138#if (defined __STDC__ && __STDC__) || defined __cplusplus139# ifdef __GNU_LIBRARY__140/* Many other libraries have conflicting prototypes for getopt, with141differences in the consts, in stdlib.h. To avoid compilation142errors, only prototype getopt for the GNU C library. */143extern int getopt (int __argc, char *const *__argv, const char *__shortopts);144# else /* not __GNU_LIBRARY__ */145extern int getopt ();146# endif /* __GNU_LIBRARY__ */147148# ifndef __need_getopt149extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,150const struct option *__longopts, int *__longind);151extern int getopt_long_only (int __argc, char *const *__argv,152const char *__shortopts,153const struct option *__longopts, int *__longind);154155/* Internal only. Users should not call this directly. */156extern int _getopt_internal (int __argc, char *const *__argv,157const char *__shortopts,158const struct option *__longopts, int *__longind,159int __long_only);160# endif161#else /* not __STDC__ */162extern int getopt ();163# ifndef __need_getopt164extern int getopt_long ();165extern int getopt_long_only ();166167extern int _getopt_internal ();168# endif169#endif /* __STDC__ */170171#ifdef __cplusplus172}173#endif174175/* Make sure we later can get all the definitions and declarations. */176#undef __need_getopt177178#endif /* getopt.h */179180181