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