summaryrefslogtreecommitdiff
path: root/externals/getopt/getopt.h
diff options
context:
space:
mode:
Diffstat (limited to 'externals/getopt/getopt.h')
-rw-r--r--externals/getopt/getopt.h136
1 files changed, 136 insertions, 0 deletions
diff --git a/externals/getopt/getopt.h b/externals/getopt/getopt.h
new file mode 100644
index 000000000..87e2ca396
--- /dev/null
+++ b/externals/getopt/getopt.h
@@ -0,0 +1,136 @@
1/* Getopt for Microsoft C
2This code is a modification of the Free Software Foundation, Inc.
3Getopt library for parsing command line argument the purpose was
4to provide a Microsoft Visual C friendly derivative. This code
5provides functionality for both Unicode and Multibyte builds.
6
7Date: 02/03/2011 - Ludvik Jerabek - Initial Release
8Version: 1.0
9Comment: Supports getopt, getopt_long, and getopt_long_only
10and POSIXLY_CORRECT environment flag
11License: LGPL
12
13Revisions:
14
1502/03/2011 - Ludvik Jerabek - Initial Release
1602/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
1707/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
1808/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
1908/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
2002/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
2108/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
2210/15/2012 - Ludvik Jerabek - Modified to match latest GNU features
2306/19/2015 - Ludvik Jerabek - Fixed maximum option limitation caused by option_a (255) and option_w (65535) structure val variable
24
25**DISCLAIMER**
26THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
27EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
28IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
29PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
30EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
31APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
32DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
33USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
34PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
35YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
36EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37*/
38#ifndef __GETOPT_H_
39#define __GETOPT_H_
40
41#ifdef _GETOPT_API
42#undef _GETOPT_API
43#endif
44
45#if defined(EXPORTS_GETOPT) && defined(STATIC_GETOPT)
46#error "The preprocessor definitions of EXPORTS_GETOPT and STATIC_GETOPT can only be used individually"
47#elif defined(STATIC_GETOPT)
48#pragma message("Warning static builds of getopt violate the Lesser GNU Public License")
49#define _GETOPT_API
50#elif defined(EXPORTS_GETOPT)
51#pragma message("Exporting getopt library")
52#define _GETOPT_API __declspec(dllexport)
53#else
54#pragma message("Importing getopt library")
55#define _GETOPT_API __declspec(dllimport)
56#endif
57
58// Change behavior for C\C++
59#ifdef __cplusplus
60#define _BEGIN_EXTERN_C extern "C" {
61#define _END_EXTERN_C }
62#define _GETOPT_THROW throw()
63#else
64#define _BEGIN_EXTERN_C
65#define _END_EXTERN_C
66#define _GETOPT_THROW
67#endif
68
69// Standard GNU options
70#define null_argument 0
71#define no_argument 0
72#define required_argument 1
73#define optional_argument 2
74
75// Shorter Options
76#define ARG_NULL 0
77#define ARG_NONE 0
78#define ARG_REQ 1
79#define ARG_OPT 2
80
81#include <string.h>
82#include <wchar.h>
83
84_BEGIN_EXTERN_C
85
86extern _GETOPT_API int optind;
87extern _GETOPT_API int opterr;
88extern _GETOPT_API int optopt;
89
90// Ansi
91struct option_a
92{
93 const char* name;
94 int has_arg;
95 int *flag;
96 int val;
97};
98extern _GETOPT_API char *optarg_a;
99extern _GETOPT_API int getopt_a(int argc, char *const *argv, const char *optstring) _GETOPT_THROW;
100extern _GETOPT_API int getopt_long_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
101extern _GETOPT_API int getopt_long_only_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
102
103// Unicode
104struct option_w
105{
106 const wchar_t* name;
107 int has_arg;
108 int *flag;
109 int val;
110};
111extern _GETOPT_API wchar_t *optarg_w;
112extern _GETOPT_API int getopt_w(int argc, wchar_t *const *argv, const wchar_t *optstring) _GETOPT_THROW;
113extern _GETOPT_API int getopt_long_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index) _GETOPT_THROW;
114extern _GETOPT_API int getopt_long_only_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index) _GETOPT_THROW;
115
116_END_EXTERN_C
117
118#undef _BEGIN_EXTERN_C
119#undef _END_EXTERN_C
120#undef _GETOPT_THROW
121#undef _GETOPT_API
122
123#ifdef _UNICODE
124#define getopt getopt_w
125#define getopt_long getopt_long_w
126#define getopt_long_only getopt_long_only_w
127#define option option_w
128#define optarg optarg_w
129#else
130#define getopt getopt_a
131#define getopt_long getopt_long_a
132#define getopt_long_only getopt_long_only_a
133#define option option_a
134#define optarg optarg_a
135#endif
136#endif // __GETOPT_H_