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