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