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