cannam@86: /* cannam@86: NOTE: cannam@86: I cannot get the vanilla getopt code to work (i.e. compile only what cannam@86: is needed and not duplicate symbols found in the standard library) cannam@86: on all the platforms that FLAC supports. In particular the gating cannam@86: of code with the ELIDE_CODE #define is not accurate enough on systems cannam@86: that are POSIX but not glibc. If someone has a patch that works on cannam@86: GNU/Linux, Darwin, AND Solaris please submit it on the project page: cannam@86: http://sourceforge.net/projects/flac cannam@86: cannam@86: In the meantime I have munged the global symbols and removed gates cannam@86: around code, while at the same time trying to touch the original as cannam@86: little as possible. cannam@86: */ cannam@86: /* Declarations for getopt. cannam@86: Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. cannam@86: This file is part of the GNU C Library. cannam@86: cannam@86: The GNU C Library is free software; you can redistribute it and/or cannam@86: modify it under the terms of the GNU Library General Public License as cannam@86: published by the Free Software Foundation; either version 2 of the cannam@86: License, or (at your option) any later version. cannam@86: cannam@86: The GNU C Library is distributed in the hope that it will be useful, cannam@86: but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@86: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU cannam@86: Library General Public License for more details. cannam@86: cannam@86: You should have received a copy of the GNU Library General Public cannam@86: License along with the GNU C Library; see the file COPYING.LIB. If not, cannam@86: write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, cannam@86: Boston, MA 02111-1307, USA. */ cannam@86: cannam@86: #ifndef SHARE__GETOPT_H cannam@86: #define SHARE__GETOPT_H cannam@86: cannam@86: /*[JEC] was:#ifndef __need_getopt*/ cannam@86: /*[JEC] was:# define _GETOPT_H 1*/ cannam@86: /*[JEC] was:#endif*/ cannam@86: cannam@86: #ifdef __cplusplus cannam@86: extern "C" { cannam@86: #endif cannam@86: cannam@86: /* For communication from `share__getopt' to the caller. cannam@86: When `share__getopt' finds an option that takes an argument, cannam@86: the argument value is returned here. cannam@86: Also, when `ordering' is RETURN_IN_ORDER, cannam@86: each non-option ARGV-element is returned here. */ cannam@86: cannam@86: extern char *share__optarg; cannam@86: cannam@86: /* Index in ARGV of the next element to be scanned. cannam@86: This is used for communication to and from the caller cannam@86: and for communication between successive calls to `share__getopt'. cannam@86: cannam@86: On entry to `share__getopt', zero means this is the first call; initialize. cannam@86: cannam@86: When `share__getopt' returns -1, this is the index of the first of the cannam@86: non-option elements that the caller should itself scan. cannam@86: cannam@86: Otherwise, `share__optind' communicates from one call to the next cannam@86: how much of ARGV has been scanned so far. */ cannam@86: cannam@86: extern int share__optind; cannam@86: cannam@86: /* Callers store zero here to inhibit the error message `share__getopt' prints cannam@86: for unrecognized options. */ cannam@86: cannam@86: extern int share__opterr; cannam@86: cannam@86: /* Set to an option character which was unrecognized. */ cannam@86: cannam@86: extern int share__optopt; cannam@86: cannam@86: /*[JEC] was:#ifndef __need_getopt */ cannam@86: /* Describe the long-named options requested by the application. cannam@86: The LONG_OPTIONS argument to share__getopt_long or share__getopt_long_only is a vector cannam@86: of `struct share__option' terminated by an element containing a name which is cannam@86: zero. cannam@86: cannam@86: The field `has_arg' is: cannam@86: share__no_argument (or 0) if the option does not take an argument, cannam@86: share__required_argument (or 1) if the option requires an argument, cannam@86: share__optional_argument (or 2) if the option takes an optional argument. cannam@86: cannam@86: If the field `flag' is not NULL, it points to a variable that is set cannam@86: to the value given in the field `val' when the option is found, but cannam@86: left unchanged if the option is not found. cannam@86: cannam@86: To have a long-named option do something other than set an `int' to cannam@86: a compiled-in constant, such as set a value from `share__optarg', set the cannam@86: option's `flag' field to zero and its `val' field to a nonzero cannam@86: value (the equivalent single-letter option character, if there is cannam@86: one). For long options that have a zero `flag' field, `share__getopt' cannam@86: returns the contents of the `val' field. */ cannam@86: cannam@86: struct share__option cannam@86: { cannam@86: # if defined __STDC__ && __STDC__ cannam@86: const char *name; cannam@86: # else cannam@86: char *name; cannam@86: # endif cannam@86: /* has_arg can't be an enum because some compilers complain about cannam@86: type mismatches in all the code that assumes it is an int. */ cannam@86: int has_arg; cannam@86: int *flag; cannam@86: int val; cannam@86: }; cannam@86: cannam@86: /* Names for the values of the `has_arg' field of `struct share__option'. */ cannam@86: cannam@86: # define share__no_argument 0 cannam@86: # define share__required_argument 1 cannam@86: # define share__optional_argument 2 cannam@86: /*[JEC] was:#endif*/ /* need getopt */ cannam@86: cannam@86: cannam@86: /* Get definitions and prototypes for functions to process the cannam@86: arguments in ARGV (ARGC of them, minus the program name) for cannam@86: options given in OPTS. cannam@86: cannam@86: Return the option character from OPTS just read. Return -1 when cannam@86: there are no more options. For unrecognized options, or options cannam@86: missing arguments, `share__optopt' is set to the option letter, and '?' is cannam@86: returned. cannam@86: cannam@86: The OPTS string is a list of characters which are recognized option cannam@86: letters, optionally followed by colons, specifying that that letter cannam@86: takes an argument, to be placed in `share__optarg'. cannam@86: cannam@86: If a letter in OPTS is followed by two colons, its argument is cannam@86: optional. This behavior is specific to the GNU `share__getopt'. cannam@86: cannam@86: The argument `--' causes premature termination of argument cannam@86: scanning, explicitly telling `share__getopt' that there are no more cannam@86: options. cannam@86: cannam@86: If OPTS begins with `--', then non-option arguments are treated as cannam@86: arguments to the option '\0'. This behavior is specific to the GNU cannam@86: `share__getopt'. */ cannam@86: cannam@86: /*[JEC] was:#if defined __STDC__ && __STDC__*/ cannam@86: /*[JEC] was:# ifdef __GNU_LIBRARY__*/ cannam@86: /* Many other libraries have conflicting prototypes for getopt, with cannam@86: differences in the consts, in stdlib.h. To avoid compilation cannam@86: errors, only prototype getopt for the GNU C library. */ cannam@86: extern int share__getopt (int argc, char *const *argv, const char *shortopts); cannam@86: /*[JEC] was:# else*/ /* not __GNU_LIBRARY__ */ cannam@86: /*[JEC] was:extern int getopt ();*/ cannam@86: /*[JEC] was:# endif*/ /* __GNU_LIBRARY__ */ cannam@86: cannam@86: /*[JEC] was:# ifndef __need_getopt*/ cannam@86: extern int share__getopt_long (int argc, char *const *argv, const char *shortopts, cannam@86: const struct share__option *longopts, int *longind); cannam@86: extern int share__getopt_long_only (int argc, char *const *argv, cannam@86: const char *shortopts, cannam@86: const struct share__option *longopts, int *longind); cannam@86: cannam@86: /* Internal only. Users should not call this directly. */ cannam@86: extern int share___getopt_internal (int argc, char *const *argv, cannam@86: const char *shortopts, cannam@86: const struct share__option *longopts, int *longind, cannam@86: int long_only); cannam@86: /*[JEC] was:# endif*/ cannam@86: /*[JEC] was:#else*/ /* not __STDC__ */ cannam@86: /*[JEC] was:extern int getopt ();*/ cannam@86: /*[JEC] was:# ifndef __need_getopt*/ cannam@86: /*[JEC] was:extern int getopt_long ();*/ cannam@86: /*[JEC] was:extern int getopt_long_only ();*/ cannam@86: cannam@86: /*[JEC] was:extern int _getopt_internal ();*/ cannam@86: /*[JEC] was:# endif*/ cannam@86: /*[JEC] was:#endif*/ /* __STDC__ */ cannam@86: cannam@86: #ifdef __cplusplus cannam@86: } cannam@86: #endif cannam@86: cannam@86: /* Make sure we later can get all the definitions and declarations. */ cannam@86: /*[JEC] was:#undef __need_getopt*/ cannam@86: cannam@86: #endif /* getopt.h */