rlm@1: /* Declarations for getopt. rlm@1: Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 2000 rlm@1: Free Software Foundation, Inc. rlm@1: rlm@1: NOTE: The canonical source of this file is maintained with the GNU C Library. rlm@1: Bugs can be reported to bug-glibc@gnu.org. rlm@1: rlm@1: This program is free software; you can redistribute it and/or modify it rlm@1: under the terms of the GNU General Public License as published by the rlm@1: Free Software Foundation; either version 2, or (at your option) any rlm@1: later version. rlm@1: rlm@1: This program is distributed in the hope that it will be useful, rlm@1: but WITHOUT ANY WARRANTY; without even the implied warranty of rlm@1: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the rlm@1: GNU General Public License for more details. rlm@1: rlm@1: You should have received a copy of the GNU General Public License rlm@1: along with this program; if not, write to the Free Software rlm@1: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, rlm@1: USA. */ rlm@1: rlm@1: #ifndef _GETOPT_H rlm@1: #define _GETOPT_H 1 rlm@1: rlm@1: #ifdef __cplusplus rlm@1: extern "C" { rlm@1: #endif rlm@1: rlm@1: /* For communication from `getopt' to the caller. rlm@1: When `getopt' finds an option that takes an argument, rlm@1: the argument value is returned here. rlm@1: Also, when `ordering' is RETURN_IN_ORDER, rlm@1: each non-option ARGV-element is returned here. */ rlm@1: rlm@1: extern char *optarg; rlm@1: rlm@1: /* Index in ARGV of the next element to be scanned. rlm@1: This is used for communication to and from the caller rlm@1: and for communication between successive calls to `getopt'. rlm@1: rlm@1: On entry to `getopt', zero means this is the first call; initialize. rlm@1: rlm@1: When `getopt' returns -1, this is the index of the first of the rlm@1: non-option elements that the caller should itself scan. rlm@1: rlm@1: Otherwise, `optind' communicates from one call to the next rlm@1: how much of ARGV has been scanned so far. */ rlm@1: rlm@1: extern int optind; rlm@1: rlm@1: /* Callers store zero here to inhibit the error message `getopt' prints rlm@1: for unrecognized options. */ rlm@1: rlm@1: extern int opterr; rlm@1: rlm@1: /* Set to an option character which was unrecognized. */ rlm@1: rlm@1: extern int optopt; rlm@1: rlm@1: /* Describe the long-named options requested by the application. rlm@1: The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector rlm@1: of `struct option' terminated by an element containing a name which is rlm@1: zero. rlm@1: rlm@1: The field `has_arg' is: rlm@1: no_argument (or 0) if the option does not take an argument, rlm@1: required_argument (or 1) if the option requires an argument, rlm@1: optional_argument (or 2) if the option takes an optional argument. rlm@1: rlm@1: If the field `flag' is not NULL, it points to a variable that is set rlm@1: to the value given in the field `val' when the option is found, but rlm@1: left unchanged if the option is not found. rlm@1: rlm@1: To have a long-named option do something other than set an `int' to rlm@1: a compiled-in constant, such as set a value from `optarg', set the rlm@1: option's `flag' field to zero and its `val' field to a nonzero rlm@1: value (the equivalent single-letter option character, if there is rlm@1: one). For long options that have a zero `flag' field, `getopt' rlm@1: returns the contents of the `val' field. */ rlm@1: rlm@1: struct option rlm@1: { rlm@1: #if defined (__STDC__) && __STDC__ rlm@1: const char *name; rlm@1: #else rlm@1: char *name; rlm@1: #endif rlm@1: /* has_arg can't be an enum because some compilers complain about rlm@1: type mismatches in all the code that assumes it is an int. */ rlm@1: int has_arg; rlm@1: int *flag; rlm@1: int val; rlm@1: }; rlm@1: rlm@1: /* Names for the values of the `has_arg' field of `struct option'. */ rlm@1: rlm@1: #define no_argument 0 rlm@1: #define required_argument 1 rlm@1: #define optional_argument 2 rlm@1: rlm@1: #if defined (__STDC__) && __STDC__ rlm@1: /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is rlm@1: undefined, we haven't run the autoconf check so provide the rlm@1: declaration without arguments. If it is 0, we checked and failed rlm@1: to find the declaration so provide a fully prototyped one. If it rlm@1: is 1, we found it so don't provide any declaration at all. */ rlm@1: #if defined (__GNU_LIBRARY__) || (defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT) rlm@1: /* Many other libraries have conflicting prototypes for getopt, with rlm@1: differences in the consts, in stdlib.h. To avoid compilation rlm@1: errors, only prototype getopt for the GNU C library. */ rlm@1: extern int getopt (int argc, char *const *argv, const char *shortopts); rlm@1: #else /* not __GNU_LIBRARY__ */ rlm@1: # if !defined (HAVE_DECL_GETOPT) rlm@1: extern int getopt (); rlm@1: # endif rlm@1: #endif /* __GNU_LIBRARY__ */ rlm@1: extern int getopt_long (int argc, char *const *argv, const char *shortopts, rlm@1: const struct option *longopts, int *longind); rlm@1: extern int getopt_long_only (int argc, char *const *argv, rlm@1: const char *shortopts, rlm@1: const struct option *longopts, int *longind); rlm@1: rlm@1: /* Internal only. Users should not call this directly. */ rlm@1: extern int _getopt_internal (int argc, char *const *argv, rlm@1: const char *shortopts, rlm@1: const struct option *longopts, int *longind, rlm@1: int long_only); rlm@1: #else /* not __STDC__ */ rlm@1: extern int getopt (); rlm@1: extern int getopt_long (); rlm@1: extern int getopt_long_only (); rlm@1: rlm@1: extern int _getopt_internal (); rlm@1: #endif /* __STDC__ */ rlm@1: rlm@1: #ifdef __cplusplus rlm@1: } rlm@1: #endif rlm@1: rlm@1: #endif /* getopt.h */