Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
opt_types.cpp
Go to the documentation of this file.
1
29// expand _TEST_EXPORT macros
30#define _RWSTD_TEST_SRC
31
32#include "opt_types.h"
33
34#include <rw_cmdopt.h>
35#include <rw_driver.h>
36
37#include <string.h>
38
39enum {
43};
44
45
46static int
47_rw_disabled_types = 0;
48
49static int
50_rw_enabled_types = 0;
51
52
53static int
54_rw_enable_type (int bit, int enable)
55{
56 const int set_mask = 1 << bit;
57
58 if (enable)
59 _rw_enabled_types |= set_mask;
60 else
61 _rw_disabled_types |= set_mask;
62
63 return 0;
64}
65
66
67#define DEFINE_HANDLERS(T) \
68 static int _rw_no_ ## T (int, char *[]) { \
69 return _rw_enable_type (rw_ ## T, false); \
70 } \
71 static int _rw_en_ ## T (int, char *[]) { \
72 return _rw_enable_type (rw_ ## T, true); \
73 } \
74 typedef void unused_type /* allow a semicolon */
75
93
94
97{
98 const int result =
99 rw_setopts (// options to disable fundamental types
100 "|-no-bool |-no-char |-no-schar |-no-uchar "
101 "|-no-shrt |-no-ushrt "
102 "|-no-int |-no-uint "
103 "|-no-long |-no-ulong "
104 "|-no-llong |-no-ullong "
105 "|-no-flt |-no-dbl |-no-ldbl "
106 "|-no-wchar |-no-pvoid "
107 // options to enable fundamental types
108 "|-enable-bool |-enable-char |-enable-schar |-enable-uchar "
109 "|-enable-shrt |-enable-ushrt "
110 "|-enable-int |-enable-uint "
111 "|-enable-long |-enable-ulong "
112 "|-enable-llong |-enable-ullong "
113 "|-enable-flt |-enable-dbl |-enable-ldbl "
114 "|-enable-wchar |-enable-pvoid",
115 // handlers to disable fundamental types
116 _rw_no_bool, _rw_no_char, _rw_no_schar, _rw_no_uchar,
117 _rw_no_shrt, _rw_no_ushrt,
118 _rw_no_int, _rw_no_uint,
119 _rw_no_long, _rw_no_ulong,
120 _rw_no_llong, _rw_no_ullong,
121 _rw_no_flt, _rw_no_dbl, _rw_no_ldbl,
122 _rw_no_wchar, _rw_no_pvoid,
123 // handlers to enable fundamental types
124 _rw_en_bool, _rw_en_char, _rw_en_schar, _rw_en_uchar,
125 _rw_en_shrt, _rw_en_ushrt,
126 _rw_en_int, _rw_en_uint,
127 _rw_en_long, _rw_en_ulong,
128 _rw_en_llong, _rw_en_ullong,
129 _rw_en_flt, _rw_en_dbl, _rw_en_ldbl,
130 _rw_en_wchar, _rw_en_pvoid);
131
132 return result;
133}
134
135
137_TEST_EXPORT int
138rw_enabled (const char *name)
139{
140 int enabled = -1;
141
142 static const struct {
143 int bit;
144 const char *name;
145 } types[] = {
146 { rw_bool, "bool" },
147
148 { rw_char, "char" },
149
150 { rw_schar, "schar" },
151 { rw_schar, "signed char" },
152 { rw_uchar, "uchar" },
153 { rw_uchar, "unsigned char" },
154
155 { rw_shrt, "shrt" },
156 { rw_shrt, "short" },
157 { rw_shrt, "signed short" },
158 { rw_ushrt, "ushrt" },
159 { rw_ushrt, "unsigned short" },
160
161 { rw_int, "int" },
162 { rw_int, "signed int" },
163 { rw_uint, "uint" },
164 { rw_uint, "unsigned int" },
165
166 { rw_long, "long" },
167 { rw_long, "signed long" },
168 { rw_ulong, "ulong" },
169 { rw_ulong, "unsigned long" },
170
171 { rw_llong, "llong" },
172 { rw_llong, "long long" },
173 { rw_llong, "signed long long" },
174 { rw_ullong, "ullong" },
175 { rw_ullong, "unsigned long long" },
176
177 { rw_flt, "flt" },
178 { rw_flt, "float" },
179
180 { rw_dbl, "dbl" },
181 { rw_dbl, "double" },
182
183 { rw_ldbl, "ldbl" },
184 { rw_ldbl, "long double" },
185
186 { rw_wchar, "wchar" },
187 { rw_wchar, "wchar_t" },
188
189 { rw_pvoid, "pvoid" },
190 { rw_pvoid, "void*" }
191 };
192
193 for (size_t i = 0; i != sizeof types / sizeof *types; ++i) {
194 if (0 == strcmp (types [i].name, name)) {
195 const int mask = 1 << types [i].bit;
196
197 enabled = !(_rw_disabled_types & mask);
198
199 if (_rw_enabled_types)
200 enabled = enabled && (_rw_enabled_types & mask);
201
202 break;
203 }
204 }
205
206 return enabled;
207}
#define i
Definition 17.names.cpp:126
volatile int result
const char * name
Definition codecvt1.cpp:72
_TEST_EXPORT int rw_enabled(const char *name)
#define DEFINE_HANDLERS(T)
Definition opt_types.cpp:67
@ rw_int
Definition opt_types.cpp:41
@ rw_char
Definition opt_types.cpp:40
@ rw_shrt
Definition opt_types.cpp:40
@ rw_pvoid
Definition opt_types.cpp:42
@ rw_wchar
Definition opt_types.cpp:42
@ rw_dbl
Definition opt_types.cpp:42
@ rw_schar
Definition opt_types.cpp:40
@ rw_ldbl
Definition opt_types.cpp:42
@ rw_uint
Definition opt_types.cpp:41
@ rw_ulong
Definition opt_types.cpp:41
@ rw_flt
Definition opt_types.cpp:42
@ rw_uchar
Definition opt_types.cpp:40
@ rw_llong
Definition opt_types.cpp:41
@ rw_ullong
Definition opt_types.cpp:41
@ rw_long
Definition opt_types.cpp:41
@ rw_bool
Definition opt_types.cpp:40
@ rw_ushrt
Definition opt_types.cpp:40
int _rw_setopts_types()
Definition opt_types.cpp:96
_TEST_EXPORT int rw_setopts(const char *optspec,...)
Definition cmdopt.cpp:652
#define _TEST_EXPORT
Definition rw_testdefs.h:55