00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef XAPIAN_INCLUDED_GNU_GETOPT_H
00024 #define XAPIAN_INCLUDED_GNU_GETOPT_H
00025
00026
00027
00028 #include <ctype.h>
00029
00030 #define GNU_GETOPT_INTERFACE_VERSION 2
00031 #if defined __GLIBC__ && __GLIBC__ >= 2
00032 # include <gnu-versions.h>
00033 # if _GNU_GETOPT_INTERFACE_VERSION == GNU_GETOPT_INTERFACE_VERSION
00034 # define USE_GLIBC_GNUGETOPT
00035 # endif
00036 #endif
00037
00038 #ifdef USE_GLIBC_GNUGETOPT
00039
00040 #include <getopt.h>
00041
00042 inline int
00043 gnu_getopt(int argc_, char *const *argv_, const char *shortopts_) {
00044 return getopt(argc_, argv_, shortopts_);
00045 }
00046
00047 inline int
00048 gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_,
00049 const struct option *longopts_, int *optind_) {
00050 return getopt_long(argc_, argv_, shortopts_, longopts_, optind_);
00051 }
00052
00053 inline int
00054 gnu_getopt_long_only(int argc_, char *const *argv_, const char *shortopts_,
00055 const struct option *longopts_, int *optind_) {
00056 return getopt_long_only(argc_, argv_, shortopts_, longopts_, optind_);
00057 }
00058
00059 #else
00060
00061 #ifdef __CYGWIN__
00062
00063
00064 # include <getopt.h>
00065 #else
00066 extern "C" {
00067 extern char *optarg;
00068 extern int optind;
00069 extern int opterr;
00070 extern int optopt;
00071 }
00072
00073 struct option {
00074 const char *name;
00075 int has_arg;
00076 int * flag;
00077 int val;
00078 };
00079
00080 # define no_argument 0
00081 # define required_argument 1
00082 # define optional_argument 2
00083 #endif
00084
00085
00086 int
00087 gnu_getopt_internal_(int, char *const *, const char *, const struct option *,
00088 int *, int);
00089
00090 inline int
00091 gnu_getopt(int argc_, char *const *argv_, const char *shortopts_) {
00092 return gnu_getopt_internal_(argc_, argv_, shortopts_,
00093 reinterpret_cast<const struct option *>(0),
00094 reinterpret_cast<int *>(0), 0);
00095 }
00096
00097 inline int
00098 gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_,
00099 const struct option *longopts_, int *optind_) {
00100 return gnu_getopt_internal_(argc_, argv_, shortopts_, longopts_, optind_, 0);
00101 }
00102
00103 inline int
00104 gnu_getopt_long_only(int argc_, char *const *argv_, const char *shortopts_,
00105 const struct option *longopts_, int *optind_) {
00106 return gnu_getopt_internal_(argc_, argv_, shortopts_, longopts_, optind_, 1);
00107 }
00108 #endif
00109
00110 #endif