Use free Windows DDK and compile with latest MinGW releases.
[reactos.git] / reactos / ntoskrnl / rtl / ctype.c
1 /* $Id: ctype.c,v 1.9 2002/09/07 15:13:05 chorns Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/rtl/ctype.c
6 * PURPOSE: Character type and conversion functions
7 * PROGRAMMERS: ???
8 * Eric Kohl
9 * HISTORY: ???: Created
10 * 10/01/2000: Added missing functions and changed
11 * all functions to use ctype table
12 */
13
14 #include <ntoskrnl.h>
15
16 #define NDEBUG
17 #include <internal/debug.h>
18
19 #undef _pctype
20
21 #define upalpha ('A' - 'a')
22
23
24 unsigned short _ctype[] = {
25 0, /* <EOF>, 0xFFFF */
26 _CONTROL, /* CTRL+@, 0x00 */
27 _CONTROL, /* CTRL+A, 0x01 */
28 _CONTROL, /* CTRL+B, 0x02 */
29 _CONTROL, /* CTRL+C, 0x03 */
30 _CONTROL, /* CTRL+D, 0x04 */
31 _CONTROL, /* CTRL+E, 0x05 */
32 _CONTROL, /* CTRL+F, 0x06 */
33 _CONTROL, /* CTRL+G, 0x07 */
34 _CONTROL, /* CTRL+H, 0x08 */
35 _CONTROL | _SPACE, /* CTRL+I, 0x09 */
36 _CONTROL | _SPACE, /* CTRL+J, 0x0a */
37 _CONTROL | _SPACE, /* CTRL+K, 0x0b */
38 _CONTROL | _SPACE, /* CTRL+L, 0x0c */
39 _CONTROL | _SPACE, /* CTRL+M, 0x0d */
40 _CONTROL, /* CTRL+N, 0x0e */
41 _CONTROL, /* CTRL+O, 0x0f */
42 _CONTROL, /* CTRL+P, 0x10 */
43 _CONTROL, /* CTRL+Q, 0x11 */
44 _CONTROL, /* CTRL+R, 0x12 */
45 _CONTROL, /* CTRL+S, 0x13 */
46 _CONTROL, /* CTRL+T, 0x14 */
47 _CONTROL, /* CTRL+U, 0x15 */
48 _CONTROL, /* CTRL+V, 0x16 */
49 _CONTROL, /* CTRL+W, 0x17 */
50 _CONTROL, /* CTRL+X, 0x18 */
51 _CONTROL, /* CTRL+Y, 0x19 */
52 _CONTROL, /* CTRL+Z, 0x1a */
53 _CONTROL, /* CTRL+[, 0x1b */
54 _CONTROL, /* CTRL+\, 0x1c */
55 _CONTROL, /* CTRL+], 0x1d */
56 _CONTROL, /* CTRL+^, 0x1e */
57 _CONTROL, /* CTRL+_, 0x1f */
58 _SPACE | _BLANK, /* ` ', 0x20 */
59 _PUNCT, /* `!', 0x21 */
60 _PUNCT, /* 0x22 */
61 _PUNCT, /* `#', 0x23 */
62 _PUNCT, /* `$', 0x24 */
63 _PUNCT, /* `%', 0x25 */
64 _PUNCT, /* `&', 0x26 */
65 _PUNCT, /* 0x27 */
66 _PUNCT, /* `(', 0x28 */
67 _PUNCT, /* `)', 0x29 */
68 _PUNCT, /* `*', 0x2a */
69 _PUNCT, /* `+', 0x2b */
70 _PUNCT, /* `,', 0x2c */
71 _PUNCT, /* `-', 0x2d */
72 _PUNCT, /* `.', 0x2e */
73 _PUNCT, /* `/', 0x2f */
74 _DIGIT | _HEX, /* `0', 0x30 */
75 _DIGIT | _HEX, /* `1', 0x31 */
76 _DIGIT | _HEX, /* `2', 0x32 */
77 _DIGIT | _HEX, /* `3', 0x33 */
78 _DIGIT | _HEX, /* `4', 0x34 */
79 _DIGIT | _HEX, /* `5', 0x35 */
80 _DIGIT | _HEX, /* `6', 0x36 */
81 _DIGIT | _HEX, /* `7', 0x37 */
82 _DIGIT | _HEX, /* `8', 0x38 */
83 _DIGIT | _HEX, /* `9', 0x39 */
84 _PUNCT, /* `:', 0x3a */
85 _PUNCT, /* `;', 0x3b */
86 _PUNCT, /* `<', 0x3c */
87 _PUNCT, /* `=', 0x3d */
88 _PUNCT, /* `>', 0x3e */
89 _PUNCT, /* `?', 0x3f */
90 _PUNCT, /* `@', 0x40 */
91 _UPPER | _HEX, /* `A', 0x41 */
92 _UPPER | _HEX, /* `B', 0x42 */
93 _UPPER | _HEX, /* `C', 0x43 */
94 _UPPER | _HEX, /* `D', 0x44 */
95 _UPPER | _HEX, /* `E', 0x45 */
96 _UPPER | _HEX, /* `F', 0x46 */
97 _UPPER, /* `G', 0x47 */
98 _UPPER, /* `H', 0x48 */
99 _UPPER, /* `I', 0x49 */
100 _UPPER, /* `J', 0x4a */
101 _UPPER, /* `K', 0x4b */
102 _UPPER, /* `L', 0x4c */
103 _UPPER, /* `M', 0x4d */
104 _UPPER, /* `N', 0x4e */
105 _UPPER, /* `O', 0x4f */
106 _UPPER, /* `P', 0x50 */
107 _UPPER, /* `Q', 0x51 */
108 _UPPER, /* `R', 0x52 */
109 _UPPER, /* `S', 0x53 */
110 _UPPER, /* `T', 0x54 */
111 _UPPER, /* `U', 0x55 */
112 _UPPER, /* `V', 0x56 */
113 _UPPER, /* `W', 0x57 */
114 _UPPER, /* `X', 0x58 */
115 _UPPER, /* `Y', 0x59 */
116 _UPPER, /* `Z', 0x5a */
117 _PUNCT, /* `[', 0x5b */
118 _PUNCT, /* 0x5c */
119 _PUNCT, /* `]', 0x5d */
120 _PUNCT, /* `^', 0x5e */
121 _PUNCT, /* `_', 0x5f */
122 _PUNCT, /* 0x60 */
123 _LOWER | _HEX, /* `a', 0x61 */
124 _LOWER | _HEX, /* `b', 0x62 */
125 _LOWER | _HEX, /* `c', 0x63 */
126 _LOWER | _HEX, /* `d', 0x64 */
127 _LOWER | _HEX, /* `e', 0x65 */
128 _LOWER | _HEX, /* `f', 0x66 */
129 _LOWER, /* `g', 0x67 */
130 _LOWER, /* `h', 0x68 */
131 _LOWER, /* `i', 0x69 */
132 _LOWER, /* `j', 0x6a */
133 _LOWER, /* `k', 0x6b */
134 _LOWER, /* `l', 0x6c */
135 _LOWER, /* `m', 0x6d */
136 _LOWER, /* `n', 0x6e */
137 _LOWER, /* `o', 0x6f */
138 _LOWER, /* `p', 0x70 */
139 _LOWER, /* `q', 0x71 */
140 _LOWER, /* `r', 0x72 */
141 _LOWER, /* `s', 0x73 */
142 _LOWER, /* `t', 0x74 */
143 _LOWER, /* `u', 0x75 */
144 _LOWER, /* `v', 0x76 */
145 _LOWER, /* `w', 0x77 */
146 _LOWER, /* `x', 0x78 */
147 _LOWER, /* `y', 0x79 */
148 _LOWER, /* `z', 0x7a */
149 _PUNCT, /* `{', 0x7b */
150 _PUNCT, /* `|', 0x7c */
151 _PUNCT, /* `}', 0x7d */
152 _PUNCT, /* `~', 0x7e */
153 _CONTROL, /* 0x7f */
154 0, /* 0x80 */
155 0, /* 0x81 */
156 0, /* 0x82 */
157 0, /* 0x83 */
158 0, /* 0x84 */
159 0, /* 0x85 */
160 0, /* 0x86 */
161 0, /* 0x87 */
162 0, /* 0x88 */
163 0, /* 0x89 */
164 0, /* 0x8a */
165 0, /* 0x8b */
166 0, /* 0x8c */
167 0, /* 0x8d */
168 0, /* 0x8e */
169 0, /* 0x8f */
170 0, /* 0x90 */
171 0, /* 0x91 */
172 0, /* 0x92 */
173 0, /* 0x93 */
174 0, /* 0x94 */
175 0, /* 0x95 */
176 0, /* 0x96 */
177 0, /* 0x97 */
178 0, /* 0x98 */
179 0, /* 0x99 */
180 0, /* 0x9a */
181 0, /* 0x9b */
182 0, /* 0x9c */
183 0, /* 0x9d */
184 0, /* 0x9e */
185 0, /* 0x9f */
186 0, /* 0xa0 */
187 0, /* 0xa1 */
188 0, /* 0xa2 */
189 0, /* 0xa3 */
190 0, /* 0xa4 */
191 0, /* 0xa5 */
192 0, /* 0xa6 */
193 0, /* 0xa7 */
194 0, /* 0xa8 */
195 0, /* 0xa9 */
196 0, /* 0xaa */
197 0, /* 0xab */
198 0, /* 0xac */
199 0, /* 0xad */
200 0, /* 0xae */
201 0, /* 0xaf */
202 0, /* 0xb0 */
203 0, /* 0xb1 */
204 0, /* 0xb2 */
205 0, /* 0xb3 */
206 0, /* 0xb4 */
207 0, /* 0xb5 */
208 0, /* 0xb6 */
209 0, /* 0xb7 */
210 0, /* 0xb8 */
211 0, /* 0xb9 */
212 0, /* 0xba */
213 0, /* 0xbb */
214 0, /* 0xbc */
215 0, /* 0xbd */
216 0, /* 0xbe */
217 0, /* 0xbf */
218 0, /* 0xc0 */
219 0, /* 0xc1 */
220 0, /* 0xc2 */
221 0, /* 0xc3 */
222 0, /* 0xc4 */
223 0, /* 0xc5 */
224 0, /* 0xc6 */
225 0, /* 0xc7 */
226 0, /* 0xc8 */
227 0, /* 0xc9 */
228 0, /* 0xca */
229 0, /* 0xcb */
230 0, /* 0xcc */
231 0, /* 0xcd */
232 0, /* 0xce */
233 0, /* 0xcf */
234 0, /* 0xd0 */
235 0, /* 0xd1 */
236 0, /* 0xd2 */
237 0, /* 0xd3 */
238 0, /* 0xd4 */
239 0, /* 0xd5 */
240 0, /* 0xd6 */
241 0, /* 0xd7 */
242 0, /* 0xd8 */
243 0, /* 0xd9 */
244 0, /* 0xda */
245 0, /* 0xdb */
246 0, /* 0xdc */
247 0, /* 0xdd */
248 0, /* 0xde */
249 0, /* 0xdf */
250 0, /* 0xe0 */
251 0, /* 0xe1 */
252 0, /* 0xe2 */
253 0, /* 0xe3 */
254 0, /* 0xe4 */
255 0, /* 0xe5 */
256 0, /* 0xe6 */
257 0, /* 0xe7 */
258 0, /* 0xe8 */
259 0, /* 0xe9 */
260 0, /* 0xea */
261 0, /* 0xeb */
262 0, /* 0xec */
263 0, /* 0xed */
264 0, /* 0xee */
265 0, /* 0xef */
266 0, /* 0xf0 */
267 0, /* 0xf1 */
268 0, /* 0xf2 */
269 0, /* 0xf3 */
270 0, /* 0xf4 */
271 0, /* 0xf5 */
272 0, /* 0xf6 */
273 0, /* 0xf7 */
274 0, /* 0xf8 */
275 0, /* 0xf9 */
276 0, /* 0xfa */
277 0, /* 0xfb */
278 0, /* 0xfc */
279 0, /* 0xfd */
280 0, /* 0xfe */
281 0 /* 0xff */
282 };
283
284 unsigned short *_pctype = _ctype + 1;
285 unsigned short *_pwctype = _ctype + 1;
286
287 int _isctype (int c, int ctypeFlags)
288 {
289 return (_pctype[(unsigned char)(c & 0xFF)] & ctypeFlags);
290 }
291
292 int iswctype(wint_t wc, wctype_t wctypeFlags)
293 {
294 return (_pwctype[(unsigned char)(wc & 0xFF)] & wctypeFlags);
295 }
296
297
298 int isalpha(int c)
299 {
300 return(_isctype(c, _ALPHA));
301 }
302
303 /*
304 int isalnum(int c)
305 {
306 return(_isctype(c, _ALPHA | _DIGIT));
307 }
308
309 int __isascii(int c)
310 {
311 return ((unsigned char)c <= 0x7f);
312 }
313
314 int iscntrl(int c)
315 {
316 return(_isctype(c, _CONTROL));
317 }
318
319 int __iscsym(int c)
320 {
321 return(isalnum(c)||(c == '_'));
322 }
323
324 int __iscsymf(int c)
325 {
326 return(isalpha(c)||(c == '_'));
327 }
328 */
329
330 int isdigit(int c)
331 {
332 return(_isctype(c, _DIGIT));
333 }
334
335 /*
336 int isgraph(int c)
337 {
338 return (_isctype (c, _PUNCT | _ALPHA | _DIGIT));
339 }
340 */
341
342 int islower(int c)
343 {
344 return (_isctype (c, _LOWER));
345 }
346
347 int isprint(int c)
348 {
349 return (_isctype (c, _BLANK | _PUNCT | _ALPHA | _DIGIT));
350 }
351
352 /*
353 int ispunct(int c)
354 {
355 return (_isctype (c, _PUNCT));
356 }
357 */
358
359 int isspace(int c)
360 {
361 return (_isctype (c, _SPACE));
362 }
363
364 int isupper(int c)
365 {
366 return (_isctype (c, _UPPER));
367 }
368
369 int isxdigit(int c)
370 {
371 return (_isctype (c, _HEX));
372 }
373
374 /*
375 int iswalpha(wint_t c)
376 {
377 return (iswctype (c, _ALPHA));
378 }
379 */
380
381 int iswdigit(wint_t c)
382 {
383 return (iswctype (c, _DIGIT));
384 }
385
386 int iswlower(wint_t c)
387 {
388 return (iswctype (c, _LOWER));
389 }
390
391 int iswxdigit(wint_t c)
392 {
393 return (iswctype (c, _HEX));
394 }
395
396
397 /*
398 int __toascii(int c)
399 {
400 return((unsigned)(c) & 0x7f);
401 }
402
403 int _tolower(int c)
404 {
405 if (_isctype (c, _UPPER))
406 return (c - upalpha);
407 return(c);
408 }
409
410 int _toupper(int c)
411 {
412 if (_isctype (c, _LOWER))
413 return (c + upalpha);
414 return(c);
415 }
416 */
417
418 int tolower(int c)
419 {
420 if (_isctype (c, _UPPER))
421 return (c - upalpha);
422 return(c);
423 }
424
425 int toupper(int c)
426 {
427 if (_isctype (c, _LOWER))
428 return (c + upalpha);
429 return(c);
430 }
431
432 wchar_t towlower(wchar_t c)
433 {
434 if (iswctype (c, _UPPER))
435 return (c - upalpha);
436 return(c);
437 }
438
439 wchar_t towupper(wchar_t c)
440 {
441 if (iswctype (c, _LOWER))
442 return (c + upalpha);
443 return(c);
444 }
445
446 /* EOF */