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