getopt_.h

00001 /* Declarations for getopt.
00002    Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU Lesser General Public License as published by
00008    the Free Software Foundation; either version 2.1, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public License along
00017    with this program; if not, write to the Free Software Foundation,
00018    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00019 
00020 #ifndef _GETOPT_H
00021 
00022 #ifndef __need_getopt
00023 # define _GETOPT_H 1
00024 #endif
00025 
00026 /* Standalone applications should #define __GETOPT_PREFIX to an
00027    identifier that prefixes the external functions and variables
00028    defined in this header.  When this happens, include the
00029    headers that might declare getopt so that they will not cause
00030    confusion if included after this file.  Then systematically rename
00031    identifiers so that they do not collide with the system functions
00032    and variables.  Renaming avoids problems with some compilers and
00033    linkers.  */
00034 #if defined __GETOPT_PREFIX && !defined __need_getopt
00035 # include <stdlib.h>
00036 # include <stdio.h>
00037 # include <unistd.h>
00038 # undef __need_getopt
00039 # undef getopt
00040 # undef getopt_long
00041 # undef getopt_long_only
00042 # undef optarg
00043 # undef opterr
00044 # undef optind
00045 # undef optopt
00046 # define __GETOPT_CONCAT(x, y) x ## y
00047 # define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
00048 # define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
00049 # define getopt __GETOPT_ID (getopt)
00050 # define getopt_long __GETOPT_ID (getopt_long)
00051 # define getopt_long_only __GETOPT_ID (getopt_long_only)
00052 # define optarg __GETOPT_ID (optarg)
00053 # define opterr __GETOPT_ID (opterr)
00054 # define optind __GETOPT_ID (optind)
00055 # define optopt __GETOPT_ID (optopt)
00056 #endif
00057 
00058 /* Standalone applications get correct prototypes for getopt_long and
00059    getopt_long_only; they declare "char **argv".  libc uses prototypes
00060    with "char *const *argv" that are incorrect because getopt_long and
00061    getopt_long_only can permute argv; this is required for backward
00062    compatibility (e.g., for LSB 2.0.1).
00063 
00064    This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt',
00065    but it caused redefinition warnings if both unistd.h and getopt.h were
00066    included, since unistd.h includes getopt.h having previously defined
00067    __need_getopt.
00068 
00069    The only place where __getopt_argv_const is used is in definitions
00070    of getopt_long and getopt_long_only below, but these are visible
00071    only if __need_getopt is not defined, so it is quite safe to rewrite
00072    the conditional as follows:
00073 */
00074 #if !defined __need_getopt
00075 # if defined __GETOPT_PREFIX
00076 #  define __getopt_argv_const /* empty */
00077 # else
00078 #  define __getopt_argv_const const
00079 # endif
00080 #endif
00081 
00082 /* If __GNU_LIBRARY__ is not already defined, either we are being used
00083    standalone, or this is the first header included in the source file.
00084    If we are being used with glibc, we need to include <features.h>, but
00085    that does not exist if we are standalone.  So: if __GNU_LIBRARY__ is
00086    not defined, include <ctype.h>, which will pull in <features.h> for us
00087    if it's from glibc.  (Why ctype.h?  It's guaranteed to exist and it
00088    doesn't flood the namespace with stuff the way some other headers do.)  */
00089 #if !defined __GNU_LIBRARY__
00090 # include <ctype.h>
00091 #endif
00092 
00093 #ifndef __THROW
00094 # ifndef __GNUC_PREREQ
00095 #  define __GNUC_PREREQ(maj, min) (0)
00096 # endif
00097 # if defined __cplusplus && __GNUC_PREREQ (2,8)
00098 #  define __THROW       throw ()
00099 # else
00100 #  define __THROW
00101 # endif
00102 #endif
00103 
00104 #ifdef  __cplusplus
00105 extern "C" {
00106 #endif
00107 
00108 /* For communication from `getopt' to the caller.
00109    When `getopt' finds an option that takes an argument,
00110    the argument value is returned here.
00111    Also, when `ordering' is RETURN_IN_ORDER,
00112    each non-option ARGV-element is returned here.  */
00113 
00114 extern char *optarg;
00115 
00116 /* Index in ARGV of the next element to be scanned.
00117    This is used for communication to and from the caller
00118    and for communication between successive calls to `getopt'.
00119 
00120    On entry to `getopt', zero means this is the first call; initialize.
00121 
00122    When `getopt' returns -1, this is the index of the first of the
00123    non-option elements that the caller should itself scan.
00124 
00125    Otherwise, `optind' communicates from one call to the next
00126    how much of ARGV has been scanned so far.  */
00127 
00128 extern int optind;
00129 
00130 /* Callers store zero here to inhibit the error message `getopt' prints
00131    for unrecognized options.  */
00132 
00133 extern int opterr;
00134 
00135 /* Set to an option character which was unrecognized.  */
00136 
00137 extern int optopt;
00138 
00139 #ifndef __need_getopt
00140 /* Describe the long-named options requested by the application.
00141    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
00142    of `struct option' terminated by an element containing a name which is
00143    zero.
00144 
00145    The field `has_arg' is:
00146    no_argument          (or 0) if the option does not take an argument,
00147    required_argument    (or 1) if the option requires an argument,
00148    optional_argument    (or 2) if the option takes an optional argument.
00149 
00150    If the field `flag' is not NULL, it points to a variable that is set
00151    to the value given in the field `val' when the option is found, but
00152    left unchanged if the option is not found.
00153 
00154    To have a long-named option do something other than set an `int' to
00155    a compiled-in constant, such as set a value from `optarg', set the
00156    option's `flag' field to zero and its `val' field to a nonzero
00157    value (the equivalent single-letter option character, if there is
00158    one).  For long options that have a zero `flag' field, `getopt'
00159    returns the contents of the `val' field.  */
00160 
00161 struct option
00162 {
00163   const char *name;
00164   /* has_arg can't be an enum because some compilers complain about
00165      type mismatches in all the code that assumes it is an int.  */
00166   int has_arg;
00167   int *flag;
00168   int val;
00169 };
00170 
00171 /* Names for the values of the `has_arg' field of `struct option'.  */
00172 
00173 # define no_argument            0
00174 # define required_argument      1
00175 # define optional_argument      2
00176 #endif  /* need getopt */
00177 
00178 
00179 /* Get definitions and prototypes for functions to process the
00180    arguments in ARGV (ARGC of them, minus the program name) for
00181    options given in OPTS.
00182 
00183    Return the option character from OPTS just read.  Return -1 when
00184    there are no more options.  For unrecognized options, or options
00185    missing arguments, `optopt' is set to the option letter, and '?' is
00186    returned.
00187 
00188    The OPTS string is a list of characters which are recognized option
00189    letters, optionally followed by colons, specifying that that letter
00190    takes an argument, to be placed in `optarg'.
00191 
00192    If a letter in OPTS is followed by two colons, its argument is
00193    optional.  This behavior is specific to the GNU `getopt'.
00194 
00195    The argument `--' causes premature termination of argument
00196    scanning, explicitly telling `getopt' that there are no more
00197    options.
00198 
00199    If OPTS begins with `--', then non-option arguments are treated as
00200    arguments to the option '\0'.  This behavior is specific to the GNU
00201    `getopt'.  */
00202 
00203 extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
00204        __THROW;
00205 
00206 #ifndef __need_getopt
00207 extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
00208                         const char *__shortopts,
00209                         const struct option *__longopts, int *__longind)
00210        __THROW;
00211 extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
00212                              const char *__shortopts,
00213                              const struct option *__longopts, int *__longind)
00214        __THROW;
00215 
00216 #endif
00217 
00218 #ifdef  __cplusplus
00219 }
00220 #endif
00221 
00222 /* Make sure we later can get all the definitions and declarations.  */
00223 #undef __need_getopt
00224 
00225 #endif /* getopt.h */

Generated on Sun Sep 24 20:10:47 2006 for WvStreams by  doxygen 1.4.7