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