Panda3D
 All Classes Functions Variables Enumerations
panda_getopt_impl.h
1 /* Filename: panda_getopt_impl.h
2  * Created by: drose (19Jul11)
3  *
4  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
5  *
6  * PANDA 3D SOFTWARE
7  * Copyright (c) Carnegie Mellon University. All rights reserved.
8  *
9  * All use of this software is subject to the terms of the revised BSD
10  * license. You should have received a copy of this license along
11  * with this source code in a file named "LICENSE."
12  *
13  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
14 
15 #ifndef PANDA_GETOPT_IMPL_H
16 #define PANDA_GETOPT_IMPL_H
17 
18 #include "dtoolbase.h"
19 
20 /* This file defines a reimplementation of getopt(), getopt_long(),
21  and getopt_long_only(), according to the LSB and Posix conventions.
22  It is completely new code, contributed under the Panda3D license. */
23 
24 #if defined(HAVE_GETOPT) && defined(HAVE_GETOPT_LONG_ONLY)
25 // If the system provides both of these functions, we don't need to
26 // provide our own implementation, so in that case this file does
27 // nothing.
28 
29 #else
30 // If the system does lack one or the other of these functions, then
31 // we'll go ahead and provide it instead.
32 
33 #define getopt panda_getopt
34 #define optind panda_optind
35 #define opterr panda_opterr
36 #define optopt panda_optopt
37 #define optarg panda_optarg
38 #define getopt_long panda_getopt_long
39 #define getopt_long_only panda_getopt_long_only
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 extern EXPCL_DTOOL char *optarg;
46 extern EXPCL_DTOOL int optind, opterr, optopt;
47 
48 struct option {
49  const char *name;
50  int has_arg;
51  int *flag;
52  int val;
53 };
54 
55 #define no_argument 0
56 #define required_argument 1
57 #define optional_argument 2
58 
59 extern EXPCL_DTOOL int
60 getopt(int argc, char *const argv[], const char *optstring);
61 extern EXPCL_DTOOL int
62 getopt_long(int argc, char *const argv[], const char *optstring,
63  const struct option *longopts, int *longindex);
64 extern EXPCL_DTOOL int
65 getopt_long_only(int argc, char *const argv[], const char *optstring,
66  const struct option *longopts, int *longindex);
67 
68 #ifdef __cplusplus
69 }
70 #endif
71 
72 #endif // defined(HAVE_GETOPT) && defined(HAVE_GETOPT_LONG_ONLY)
73 
74 #endif