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