00001 /* Declarations for getopt. 00002 Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc. 00003 00004 NOTE: The canonical source of this file is maintained with the GNU C Library. 00005 Bugs can be reported to bug-glibc@gnu.org. 00006 00007 This program is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 2, or (at your option) any 00010 later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00020 USA. */ 00021 00022 #ifndef _GETOPT_H 00023 #define _GETOPT_H 1 00024 00025 #if HAVE_CONFIG_H 00026 #include <config.h> 00027 #endif 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00033 /* For communication from `getopt' to the caller. 00034 When `getopt' finds an option that takes an argument, 00035 the argument value is returned here. 00036 Also, when `ordering' is RETURN_IN_ORDER, 00037 each non-option ARGV-element is returned here. */ 00038 00039 extern char *optarg; 00040 00041 /* Index in ARGV of the next element to be scanned. 00042 This is used for communication to and from the caller 00043 and for communication between successive calls to `getopt'. 00044 00045 On entry to `getopt', zero means this is the first call; initialize. 00046 00047 When `getopt' returns -1, this is the index of the first of the 00048 non-option elements that the caller should itself scan. 00049 00050 Otherwise, `optind' communicates from one call to the next 00051 how much of ARGV has been scanned so far. */ 00052 00053 extern int optind; 00054 00055 /* Callers store zero here to inhibit the error message `getopt' prints 00056 for unrecognized options. */ 00057 00058 extern int opterr; 00059 00060 /* Set to an option character which was unrecognized. */ 00061 00062 extern int optopt; 00063 00064 /* Describe the long-named options requested by the application. 00065 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 00066 of `struct option' terminated by an element containing a name which is 00067 zero. 00068 00069 The field `has_arg' is: 00070 no_argument (or 0) if the option does not take an argument, 00071 required_argument (or 1) if the option requires an argument, 00072 optional_argument (or 2) if the option takes an optional argument. 00073 00074 If the field `flag' is not NULL, it points to a variable that is set 00075 to the value given in the field `val' when the option is found, but 00076 left unchanged if the option is not found. 00077 00078 To have a long-named option do something other than set an `int' to 00079 a compiled-in constant, such as set a value from `optarg', set the 00080 option's `flag' field to zero and its `val' field to a nonzero 00081 value (the equivalent single-letter option character, if there is 00082 one). For long options that have a zero `flag' field, `getopt' 00083 returns the contents of the `val' field. */ 00084 00085 struct option 00086 { 00087 #if defined (__STDC__) && __STDC__ 00088 const char *name; 00089 #else 00090 char *name; 00091 #endif 00092 /* has_arg can't be an enum because some compilers complain about 00093 type mismatches in all the code that assumes it is an int. */ 00094 int has_arg; 00095 int *flag; 00096 int val; 00097 }; 00098 00099 /* Names for the values of the `has_arg' field of `struct option'. */ 00100 00101 #define no_argument 0 00102 #define required_argument 1 00103 #define optional_argument 2 00104 00105 #if defined (__STDC__) && __STDC__ 00106 #if defined (__GNU_LIBRARY__) || defined (HPUX) || defined (SUNOS) 00107 /* Many other libraries have conflicting prototypes for getopt, with 00108 differences in the consts, in stdlib.h. To avoid compilation 00109 errors, only prototype getopt for the GNU C library. */ 00110 extern int getopt (int argc, char *const *argv, const char *shortopts); 00111 #else /* not __GNU_LIBRARY__ */ 00112 extern int getopt (); 00113 #endif /* __GNU_LIBRARY__ */ 00114 extern int getopt_long (int argc, char *const *argv, const char *shortopts, 00115 const struct option *longopts, int *longind); 00116 extern int getopt_long_only (int argc, char *const *argv, 00117 const char *shortopts, 00118 const struct option *longopts, int *longind); 00119 00120 /* Internal only. Users should not call this directly. */ 00121 extern int _getopt_internal (int argc, char *const *argv, 00122 const char *shortopts, 00123 const struct option *longopts, int *longind, 00124 int long_only); 00125 #else /* not __STDC__ */ 00126 extern int getopt (); 00127 extern int getopt_long (); 00128 extern int getopt_long_only (); 00129 00130 extern int _getopt_internal (); 00131 #endif /* __STDC__ */ 00132 00133 #ifdef __cplusplus 00134 } 00135 #endif 00136 00137 #endif /* getopt.h */