ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/utils/wingetopt.h
(Generate patch)

Comparing trunk/src/utils/wingetopt.h (file contents):
Revision 1942 by gezelter, Fri Sep 7 18:13:55 2012 UTC vs.
Revision 1943 by gezelter, Tue Nov 5 19:12:57 2013 UTC

# Line 1 | Line 1
1 < /* Getopt for Microsoft C  
2 < This code is a modification of the Free Software Foundation, Inc.
3 < Getopt library for parsing command line argument the purpose was
4 < to provide a Microsoft Visual C friendly derivative. This code
5 < provides functionality for both Unicode and Multibyte builds.
1 > /* Getopt for Microsoft C
2 >   This code is a modification of the Free Software Foundation, Inc.
3 >   Getopt library for parsing command line argument the purpose was
4 >   to provide a Microsoft Visual C friendly derivative. This code
5 >   provides functionality for both Unicode and Multibyte builds.
6  
7 < Date: 02/03/2011 - Ludvik Jerabek - Initial Release
8 < Version: 1.0
9 < Comment: Supports getopt, getopt_long, and getopt_long_only
10 < and POSIXLY_CORRECT environment flag
11 < License: LGPL
7 >   Date: 02/03/2011 - Ludvik Jerabek - Initial Release
8 >   Version: 1.0
9 >   Comment: Supports getopt, getopt_long, and getopt_long_only
10 >   and POSIXLY_CORRECT environment flag
11 >   License: LGPL
12  
13 < Revisions:
13 >   Revisions:
14  
15 < 02/03/2011 - Ludvik Jerabek - Initial Release
16 < 02/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
17 < 07/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
18 < 08/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
19 < 08/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
20 < 02/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
21 < 08/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
15 >   02/03/2011 - Ludvik Jerabek - Initial Release
16 >   02/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
17 >   07/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
18 >   08/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
19 >   08/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
20 >   02/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
21 >   08/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
22 >   10/15/2012 - Ludvik Jerabek - Modified to match latest GNU features
23  
24 < **DISCLAIMER**
25 < THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
26 < EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
27 < IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
28 < PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
29 < EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
30 < APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
31 < DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
32 < USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
33 < PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
34 < YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
35 < EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
24 >   **DISCLAIMER**
25 >   THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
26 >   EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
27 >   IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
28 >   PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
29 >   EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
30 >   APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
31 >   DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
32 >   USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
33 >   PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
34 >   YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
35 >   EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36   */
37   #ifndef __GETOPT_H_
38   #define __GETOPT_H_
# Line 47 | Line 48 | EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
48   #define _GETOPT_API
49   #elif defined(EXPORTS_GETOPT)
50   #pragma message("Exporting getopt library")
51 < #define _GETOPT_API __declspec(dllexport)      
51 > #define _GETOPT_API __declspec(dllexport)
52   #else
53   #pragma message("Importing getopt library")
54   #define _GETOPT_API __declspec(dllimport)
55   #endif
56  
56
57 #include <string.h>
58 #include <wchar.h>
59
60 // Standard GNU options
61 #define null_argument           0 /*Argument Null*/
62 #define no_argument                     0 /*Argument Switch Only*/
63 #define required_argument       1 /*Argument Required*/
64 #define optional_argument       2 /*Argument Optional*/
65
66 // Shorter Versions of options
67 #define ARG_NULL 0 /*Argument Null*/
68 #define ARG_NONE 0 /*Argument Switch Only*/
69 #define ARG_REQ 1  /*Argument Required*/
70 #define ARG_OPT 2  /*Argument Optional*/
71
57   // Change behavior for C\C++
58   #ifdef __cplusplus
59   #define _BEGIN_EXTERN_C extern "C" {
# Line 80 | Line 65 | EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
65   #define _GETOPT_THROW
66   #endif
67  
68 + // Standard GNU options
69 + #define null_argument           0       /*Argument Null*/
70 + #define no_argument                     0       /*Argument Switch Only*/
71 + #define required_argument       1       /*Argument Required*/
72 + #define optional_argument       2       /*Argument Optional*/  
73 +
74 + // Shorter Options
75 + #define ARG_NULL        0       /*Argument Null*/
76 + #define ARG_NONE        0       /*Argument Switch Only*/
77 + #define ARG_REQ         1       /*Argument Required*/
78 + #define ARG_OPT         2       /*Argument Optional*/
79 +
80 + #include <string.h>
81 + #include <wchar.h>
82 +
83   _BEGIN_EXTERN_C
84  
85 extern _GETOPT_API char *optarg_a;
86 extern _GETOPT_API wchar_t *optarg_w;
85   extern _GETOPT_API int optind;
86   extern _GETOPT_API int opterr;
87   extern _GETOPT_API int optopt;
# Line 91 | Line 89 | struct option_a
89   // Ansi
90   struct option_a
91   {
92 <        const char* name;
93 <        int has_arg;
94 <        int *flag;
95 <        char val;
92 >  const char* name;
93 >  int has_arg;
94 >  int *flag;
95 >  char val;
96   };
97 + extern _GETOPT_API char *optarg_a;
98 + extern _GETOPT_API int getopt_a(int argc, char *const *argv, const char *optstring) _GETOPT_THROW;
99 + extern _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;
100 + extern _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;
101  
102   // Unicode
103   struct option_w
104   {
105 <        const wchar_t* name;
106 <        int has_arg;
107 <        int *flag;
108 <        wchar_t val;
105 >  const wchar_t* name;
106 >  int has_arg;
107 >  int *flag;
108 >  wchar_t val;
109   };
110 <
109 < // Ansi
110 < extern _GETOPT_API int getopt_a(int argc, char *const *argv, const char *optstring) _GETOPT_THROW;
111 < extern _GETOPT_API int getopt_long_a(int ___argc, char *const *___argv, const char *__shortopts, const struct option_a *__longopts, int *__longind) _GETOPT_THROW;
112 < extern _GETOPT_API int getopt_long_only_a(int ___argc, char *const *___argv, const char *__shortopts, const struct option_a *__longopts, int *__longind) _GETOPT_THROW;
113 <
114 < // Unicode
110 > extern _GETOPT_API wchar_t *optarg_w;
111   extern _GETOPT_API int getopt_w(int argc, wchar_t *const *argv, const wchar_t *optstring) _GETOPT_THROW;
112 < extern _GETOPT_API int getopt_long_w(int ___argc, wchar_t *const *___argv, const wchar_t *__shortopts, const struct option_w *__longopts, int *__longind) _GETOPT_THROW;
113 < extern _GETOPT_API int getopt_long_only_w(int ___argc, wchar_t *const *___argv, const wchar_t *__shortopts, const struct option_w *__longopts, int *__longind) _GETOPT_THROW;
114 <
119 < #ifdef _UNICODE
120 <        #define getopt getopt_w
121 <        #define getopt_long getopt_long_w
122 <        #define getopt_long_only getopt_long_only_w
123 <        #define option option_w
124 <        #define optarg optarg_w
125 < #else
126 <        #define getopt getopt_a
127 <        #define getopt_long getopt_long_a
128 <        #define getopt_long_only getopt_long_only_a
129 <        #define option option_a
130 <        #define optarg optarg_a
131 < #endif
132 <
112 > extern _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;
113 > extern _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;  
114 >        
115   _END_EXTERN_C
116  
135 // Undefine so the macros are not included
117   #undef _BEGIN_EXTERN_C
118   #undef _END_EXTERN_C
119   #undef _GETOPT_THROW
120   #undef _GETOPT_API
121  
122 < #endif  // __GETOPT_H_
122 > #ifdef _UNICODE
123 > #define getopt getopt_w
124 > #define getopt_long getopt_long_w
125 > #define getopt_long_only getopt_long_only_w
126 > #define option option_w
127 > #define optarg optarg_w
128 > #else
129 > #define getopt getopt_a
130 > #define getopt_long getopt_long_a
131 > #define getopt_long_only getopt_long_only_a
132 > #define option option_a
133 > #define optarg optarg_a
134 > #endif
135 > #endif  // __GETOPT_H_

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines