/* Declarations for getopt.1Copyright (C) 1989-1994,1996-1999,2001,2003,20042Free Software Foundation, Inc.3This file is part of the GNU C Library.45This program is free software; you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation; either version 2, or (at your option)8any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License along16with this program; if not, write to the Free Software Foundation,17Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */1819#ifndef _GETOPT_H2021#ifndef __need_getopt22# define _GETOPT_H 123#endif2425/* If __GNU_LIBRARY__ is not already defined, either we are being used26standalone, or this is the first header included in the source file.27If we are being used with glibc, we need to include <features.h>, but28that does not exist if we are standalone. So: if __GNU_LIBRARY__ is29not defined, include <ctype.h>, which will pull in <features.h> for us30if it's from glibc. (Why ctype.h? It's guaranteed to exist and it31doesn't flood the namespace with stuff the way some other headers do.) */32#if !defined __GNU_LIBRARY__33# include <ctype.h>34#endif3536#ifndef __THROW37# ifndef __GNUC_PREREQ38# define __GNUC_PREREQ(maj, min) (0)39# endif40# if defined __cplusplus && __GNUC_PREREQ (2,8)41# define __THROW throw ()42# else43# define __THROW44# endif45#endif4647#ifdef __cplusplus48extern "C" {49#endif5051/* For communication from `getopt' to the caller.52When `getopt' finds an option that takes an argument,53the argument value is returned here.54Also, when `ordering' is RETURN_IN_ORDER,55each non-option ARGV-element is returned here. */5657extern char *optarg;5859/* Index in ARGV of the next element to be scanned.60This is used for communication to and from the caller61and for communication between successive calls to `getopt'.6263On entry to `getopt', zero means this is the first call; initialize.6465When `getopt' returns -1, this is the index of the first of the66non-option elements that the caller should itself scan.6768Otherwise, `optind' communicates from one call to the next69how much of ARGV has been scanned so far. */7071extern int optind;7273/* Callers store zero here to inhibit the error message `getopt' prints74for unrecognized options. */7576extern int opterr;7778/* Set to an option character which was unrecognized. */7980extern int optopt;8182#ifndef __need_getopt83/* Describe the long-named options requested by the application.84The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector85of `struct option' terminated by an element containing a name which is86zero.8788The field `has_arg' is:89no_argument (or 0) if the option does not take an argument,90required_argument (or 1) if the option requires an argument,91optional_argument (or 2) if the option takes an optional argument.9293If the field `flag' is not NULL, it points to a variable that is set94to the value given in the field `val' when the option is found, but95left unchanged if the option is not found.9697To have a long-named option do something other than set an `int' to98a compiled-in constant, such as set a value from `optarg', set the99option's `flag' field to zero and its `val' field to a nonzero100value (the equivalent single-letter option character, if there is101one). For long options that have a zero `flag' field, `getopt'102returns the contents of the `val' field. */103104struct option105{106const char *name;107/* has_arg can't be an enum because some compilers complain about108type mismatches in all the code that assumes it is an int. */109int has_arg;110int *flag;111int val;112};113114/* Names for the values of the `has_arg' field of `struct option'. */115116# define no_argument 0117# define required_argument 1118# define optional_argument 2119#endif /* need getopt */120121122/* Get definitions and prototypes for functions to process the123arguments in ARGV (ARGC of them, minus the program name) for124options given in OPTS.125126Return the option character from OPTS just read. Return -1 when127there are no more options. For unrecognized options, or options128missing arguments, `optopt' is set to the option letter, and '?' is129returned.130131The OPTS string is a list of characters which are recognized option132letters, optionally followed by colons, specifying that that letter133takes an argument, to be placed in `optarg'.134135If a letter in OPTS is followed by two colons, its argument is136optional. This behavior is specific to the GNU `getopt'.137138The argument `--' causes premature termination of argument139scanning, explicitly telling `getopt' that there are no more140options.141142If OPTS begins with `--', then non-option arguments are treated as143arguments to the option '\0'. This behavior is specific to the GNU144`getopt'. */145146#ifdef __GNU_LIBRARY__147/* Many other libraries have conflicting prototypes for getopt, with148differences in the consts, in stdlib.h. To avoid compilation149errors, only prototype getopt for the GNU C library. */150extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)151__THROW;152#else /* not __GNU_LIBRARY__ */153extern int getopt ();154#endif /* __GNU_LIBRARY__ */155156#ifndef __need_getopt157extern int getopt_long (int ___argc, char *const *___argv,158const char *__shortopts,159const struct option *__longopts, int *__longind)160__THROW;161extern int getopt_long_only (int ___argc, char *const *___argv,162const char *__shortopts,163const struct option *__longopts, int *__longind)164__THROW;165166#endif167168#ifdef __cplusplus169}170#endif171172/* Make sure we later can get all the definitions and declarations. */173#undef __need_getopt174175#endif /* getopt.h */176177178