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 extern char *optarg;
00062 extern int optind;
00063 extern int opterr;
00064 extern int optopt;
00065
00066 struct option {
00067 const char *name;
00068 int has_arg;
00069 int * flag;
00070 int val;
00071 };
00072
00073 #define no_argument 0
00074 #define required_argument 1
00075 #define optional_argument 2
00076
00077
00078 int
00079 gnu_getopt_internal_(int, char *const *, const char *, const struct option *,
00080 int *, int);
00081
00082 inline int
00083 gnu_getopt(int argc_, char *const *argv_, const char *shortopts_) {
00084 return gnu_getopt_internal_(argc_, argv_, shortopts_,
00085 reinterpret_cast<const struct option *>(0),
00086 reinterpret_cast<int *>(0), 0);
00087 }
00088
00089 inline int
00090 gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_,
00091 const struct option *longopts_, int *optind_) {
00092 return gnu_getopt_internal_(argc_, argv_, shortopts_, longopts_, optind_, 0);
00093 }
00094
00095 inline int
00096 gnu_getopt_long_only(int argc_, char *const *argv_, const char *shortopts_,
00097 const struct option *longopts_, int *optind_) {
00098 return gnu_getopt_internal_(argc_, argv_, shortopts_, longopts_, optind_, 1);
00099 }
00100 #endif
00101
00102 #endif