00001 /* Declarations for getopt. 00002 00003 Gaim is the legal property of its developers, whose names are too numerous 00004 to list here. Please refer to the COPYRIGHT file distributed with this 00005 source distribution. 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, 675 Mass Ave, Cambridge, MA 02139, USA. */ 00020 00021 #ifndef _GETOPT_H 00022 #define _GETOPT_H 1 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 /* For communication from `getopt' to the caller. 00029 When `getopt' finds an option that takes an argument, 00030 the argument value is returned here. 00031 Also, when `ordering' is RETURN_IN_ORDER, 00032 each non-option ARGV-element is returned here. */ 00033 00034 extern char *optarg; 00035 00036 /* Index in ARGV of the next element to be scanned. 00037 This is used for communication to and from the caller 00038 and for communication between successive calls to `getopt'. 00039 00040 On entry to `getopt', zero means this is the first call; initialize. 00041 00042 When `getopt' returns EOF, this is the index of the first of the 00043 non-option elements that the caller should itself scan. 00044 00045 Otherwise, `optind' communicates from one call to the next 00046 how much of ARGV has been scanned so far. */ 00047 00048 extern int optind; 00049 00050 /* Callers store zero here to inhibit the error message `getopt' prints 00051 for unrecognized options. */ 00052 00053 extern int opterr; 00054 00055 /* Set to an option character which was unrecognized. */ 00056 00057 extern int optopt; 00058 00059 /* Describe the long-named options requested by the application. 00060 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 00061 of `struct option' terminated by an element containing a name which is 00062 zero. 00063 00064 The field `has_arg' is: 00065 no_argument (or 0) if the option does not take an argument, 00066 required_argument (or 1) if the option requires an argument, 00067 optional_argument (or 2) if the option takes an optional argument. 00068 00069 If the field `flag' is not NULL, it points to a variable that is set 00070 to the value given in the field `val' when the option is found, but 00071 left unchanged if the option is not found. 00072 00073 To have a long-named option do something other than set an `int' to 00074 a compiled-in constant, such as set a value from `optarg', set the 00075 option's `flag' field to zero and its `val' field to a nonzero 00076 value (the equivalent single-letter option character, if there is 00077 one). For long options that have a zero `flag' field, `getopt' 00078 returns the contents of the `val' field. */ 00079 00080 struct option 00081 { 00082 #if __STDC__ 00083 const char *name; 00084 #else 00085 char *name; 00086 #endif 00087 /* has_arg can't be an enum because some compilers complain about 00088 type mismatches in all the code that assumes it is an int. */ 00089 int has_arg; 00090 int *flag; 00091 int val; 00092 }; 00093 00094 /* Names for the values of the `has_arg' field of `struct option'. */ 00095 00096 #define no_argument 0 00097 #define required_argument 1 00098 #define optional_argument 2 00099 00100 #if __STDC__ 00101 #if defined(__GNU_LIBRARY__) 00102 /* Many other libraries have conflicting prototypes for getopt, with 00103 differences in the consts, in stdlib.h. To avoid compilation 00104 errors, only prototype getopt for the GNU C library. */ 00105 extern int getopt (int argc, char *const *argv, const char *shortopts); 00106 #else /* not __GNU_LIBRARY__ */ 00107 extern int getopt (); 00108 #endif /* not __GNU_LIBRARY__ */ 00109 extern int getopt_long (int argc, char *const *argv, const char *shortopts, 00110 const struct option *longopts, int *longind); 00111 extern int getopt_long_only (int argc, char *const *argv, 00112 const char *shortopts, 00113 const struct option *longopts, int *longind); 00114 00115 /* Internal only. Users should not call this directly. */ 00116 extern int _getopt_internal (int argc, char *const *argv, 00117 const char *shortopts, 00118 const struct option *longopts, int *longind, 00119 int long_only); 00120 #else /* not __STDC__ */ 00121 extern int getopt (); 00122 extern int getopt_long (); 00123 extern int getopt_long_only (); 00124 00125 extern int _getopt_internal (); 00126 #endif /* not __STDC__ */ 00127 00128 #ifdef __cplusplus 00129 } 00130 #endif 00131 00132 #endif /* _GETOPT_H */