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