00001 /* 00002 Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin 00003 Copyright (C) 2005- The University of Notre Dame 00004 This software is distributed under a BSD-style license. 00005 See the file COPYING for details. 00006 */ 00007 /* Declarations for getopt. 00008 Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. 00009 This file is part of the GNU C Library. 00010 00011 The GNU C Library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Lesser General Public 00013 License as published by the Free Software Foundation; either 00014 version 2.1 of the License, or (at your option) any later version. 00015 00016 The GNU C Library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public 00022 License along with the GNU C Library; if not, write to the Free 00023 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00024 02111-1307 USA. */ 00025 00026 #ifndef _GETOPT_H 00027 00028 #ifndef __need_getopt 00029 # define _GETOPT_H 1 00030 #endif 00031 00032 /* If __GNU_LIBRARY__ is not already defined, either we are being used 00033 standalone, or this is the first header included in the source file. 00034 If we are being used with glibc, we need to include <features.h>, but 00035 that does not exist if we are standalone. So: if __GNU_LIBRARY__ is 00036 not defined, include <ctype.h>, which will pull in <features.h> for us 00037 if it's from glibc. (Why ctype.h? It's guaranteed to exist and it 00038 doesn't flood the namespace with stuff the way some other headers do.) */ 00039 #if !defined __GNU_LIBRARY__ 00040 # include <ctype.h> 00041 #endif 00042 00043 #ifdef __cplusplus 00044 extern "C" { 00045 #endif 00046 00047 /* For communication from `getopt' to the caller. 00048 When `getopt' finds an option that takes an argument, 00049 the argument value is returned here. 00050 Also, when `ordering' is RETURN_IN_ORDER, 00051 each non-option ARGV-element is returned here. */ 00052 00053 extern char *optarg; 00054 00055 /* Index in ARGV of the next element to be scanned. 00056 This is used for communication to and from the caller 00057 and for communication between successive calls to `getopt'. 00058 00059 On entry to `getopt', zero means this is the first call; initialize. 00060 00061 When `getopt' returns -1, this is the index of the first of the 00062 non-option elements that the caller should itself scan. 00063 00064 Otherwise, `optind' communicates from one call to the next 00065 how much of ARGV has been scanned so far. */ 00066 00067 extern int optind; 00068 00069 /* Callers store zero here to inhibit the error message `getopt' prints 00070 for unrecognized options. */ 00071 00072 extern int opterr; 00073 00074 /* Set to an option character which was unrecognized. */ 00075 00076 extern int optopt; 00077 00078 #ifndef __need_getopt 00079 /* Describe the long-named options requested by the application. 00080 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 00081 of `struct option' terminated by an element containing a name which is 00082 zero. 00083 00084 The field `has_arg' is: 00085 no_argument (or 0) if the option does not take an argument, 00086 required_argument (or 1) if the option requires an argument, 00087 optional_argument (or 2) if the option takes an optional argument. 00088 00089 If the field `flag' is not NULL, it points to a variable that is set 00090 to the value given in the field `val' when the option is found, but 00091 left unchanged if the option is not found. 00092 00093 To have a long-named option do something other than set an `int' to 00094 a compiled-in constant, such as set a value from `optarg', set the 00095 option's `flag' field to zero and its `val' field to a nonzero 00096 value (the equivalent single-letter option character, if there is 00097 one). For long options that have a zero `flag' field, `getopt' 00098 returns the contents of the `val' field. */ 00099 00100 struct option 00101 { 00102 # if (defined __STDC__ && __STDC__) || defined __cplusplus 00103 const char *name; 00104 # else 00105 char *name; 00106 # endif 00107 /* has_arg can't be an enum because some compilers complain about 00108 type mismatches in all the code that assumes it is an int. */ 00109 int has_arg; 00110 int *flag; 00111 int val; 00112 }; 00113 00114 /* Names for the values of the `has_arg' field of `struct option'. */ 00115 00116 # define no_argument 0 00117 # define required_argument 1 00118 # define optional_argument 2 00119 #endif /* need getopt */ 00120 00121 00122 /* Get definitions and prototypes for functions to process the 00123 arguments in ARGV (ARGC of them, minus the program name) for 00124 options given in OPTS. 00125 00126 Return the option character from OPTS just read. Return -1 when 00127 there are no more options. For unrecognized options, or options 00128 missing arguments, `optopt' is set to the option letter, and '?' is 00129 returned. 00130 00131 The OPTS string is a list of characters which are recognized option 00132 letters, optionally followed by colons, specifying that that letter 00133 takes an argument, to be placed in `optarg'. 00134 00135 If a letter in OPTS is followed by two colons, its argument is 00136 optional. This behavior is specific to the GNU `getopt'. 00137 00138 The argument `--' causes premature termination of argument 00139 scanning, explicitly telling `getopt' that there are no more 00140 options. 00141 00142 If OPTS begins with `--', then non-option arguments are treated as 00143 arguments to the option '\0'. This behavior is specific to the GNU 00144 `getopt'. */ 00145 00146 #if (defined __STDC__ && __STDC__) || defined __cplusplus 00147 # ifdef __GNU_LIBRARY__ 00148 /* Many other libraries have conflicting prototypes for getopt, with 00149 differences in the consts, in stdlib.h. To avoid compilation 00150 errors, only prototype getopt for the GNU C library. */ 00151 extern int getopt (int __argc, char *const *__argv, const char *__shortopts); 00152 # else /* not __GNU_LIBRARY__ */ 00153 extern int getopt (); 00154 # endif /* __GNU_LIBRARY__ */ 00155 00156 # ifndef __need_getopt 00157 extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, 00158 const struct option *__longopts, int *__longind); 00159 extern int getopt_long_only (int __argc, char *const *__argv, 00160 const char *__shortopts, 00161 const struct option *__longopts, int *__longind); 00162 00163 /* Internal only. Users should not call this directly. */ 00164 extern int _getopt_internal (int __argc, char *const *__argv, 00165 const char *__shortopts, 00166 const struct option *__longopts, int *__longind, 00167 int __long_only); 00168 # endif 00169 #else /* not __STDC__ */ 00170 extern int getopt (); 00171 # ifndef __need_getopt 00172 extern int getopt_long (); 00173 extern int getopt_long_only (); 00174 00175 extern int _getopt_internal (); 00176 # endif 00177 #endif /* __STDC__ */ 00178 00179 #ifdef __cplusplus 00180 } 00181 #endif 00182 00183 /* Make sure we later can get all the definitions and declarations. */ 00184 #undef __need_getopt 00185 00186 #endif /* getopt.h */