Panda3D
|
00001 /* Filename: panda_getopt_impl.h 00002 * Created by: drose (19Jul11) 00003 * 00004 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00005 * 00006 * PANDA 3D SOFTWARE 00007 * Copyright (c) Carnegie Mellon University. All rights reserved. 00008 * 00009 * All use of this software is subject to the terms of the revised BSD 00010 * license. You should have received a copy of this license along 00011 * with this source code in a file named "LICENSE." 00012 * 00013 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00014 00015 #ifndef PANDA_GETOPT_IMPL_H 00016 #define PANDA_GETOPT_IMPL_H 00017 00018 #include "dtoolbase.h" 00019 00020 /* This file defines a reimplementation of getopt(), getopt_long(), 00021 and getopt_long_only(), according to the LSB and Posix conventions. 00022 It is completely new code, contributed under the Panda3D license. */ 00023 00024 #if defined(HAVE_GETOPT) && defined(HAVE_GETOPT_LONG_ONLY) 00025 // If the system provides both of these functions, we don't need to 00026 // provide our own implementation, so in that case this file does 00027 // nothing. 00028 00029 #else 00030 // If the system does lack one or the other of these functions, then 00031 // we'll go ahead and provide it instead. 00032 00033 #define getopt panda_getopt 00034 #define optind panda_optind 00035 #define opterr panda_opterr 00036 #define optopt panda_optopt 00037 #define optarg panda_optarg 00038 #define getopt_long panda_getopt_long 00039 #define getopt_long_only panda_getopt_long_only 00040 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif 00044 00045 extern EXPCL_DTOOL char *optarg; 00046 extern EXPCL_DTOOL int optind, opterr, optopt; 00047 00048 struct option { 00049 const char *name; 00050 int has_arg; 00051 int *flag; 00052 int val; 00053 }; 00054 00055 #define no_argument 0 00056 #define required_argument 1 00057 #define optional_argument 2 00058 00059 extern EXPCL_DTOOL int 00060 getopt(int argc, char *const argv[], const char *optstring); 00061 extern EXPCL_DTOOL int 00062 getopt_long(int argc, char *const argv[], const char *optstring, 00063 const struct option *longopts, int *longindex); 00064 extern EXPCL_DTOOL int 00065 getopt_long_only(int argc, char *const argv[], const char *optstring, 00066 const struct option *longopts, int *longindex); 00067 00068 #ifdef __cplusplus 00069 } 00070 #endif 00071 00072 #endif // defined(HAVE_GETOPT) && defined(HAVE_GETOPT_LONG_ONLY) 00073 00074 #endif