Added an unknown VxD error code.
[wine] / dlls / msvcrt / ctype.c
1 /*
2  * msvcrt.dll ctype functions
3  *
4  * Copyright 2000 Jon Griffiths
5  */
6 #include "msvcrt.h"
7
8 #include "msvcrt/ctype.h"
9
10 DEFAULT_DEBUG_CHANNEL(msvcrt);
11
12 /* Some abbreviations to make the following table readable */
13 #define _C_ _CONTROL
14 #define _S_ _SPACE
15 #define _P_ _PUNCT
16 #define _D_ _DIGIT
17 #define _H_ _HEX
18 #define _U_ _UPPER
19 #define _L_ _LOWER
20
21 WORD MSVCRT__ctype [257] = {
22   0, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_C_, _S_|_C_,
23   _S_|_C_, _S_|_C_, _S_|_C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_,
24   _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_BLANK,
25   _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_,
26   _P_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_,
27   _D_|_H_, _D_|_H_, _D_|_H_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _U_|_H_,
28   _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_, _U_, _U_, _U_, _U_,
29   _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_,
30   _U_, _P_, _P_, _P_, _P_, _P_, _P_, _L_|_H_, _L_|_H_, _L_|_H_, _L_|_H_,
31   _L_|_H_, _L_|_H_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_,
32   _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _P_, _P_, _P_, _P_,
33   _C_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
39 };
40
41 /* Internal: Current ctype table for locale */
42 WORD MSVCRT_current_ctype[257];
43
44 /* pctype is used by macros in the Win32 headers. It must point
45  * To a table of flags exactly like ctype. To allow locale
46  * changes to affect ctypes (i.e. isleadbyte), we use a second table
47  * and update its flags whenever the current locale changes.
48  */
49 WORD* MSVCRT__pctype = MSVCRT_current_ctype + 1;
50
51 /* mbctype data */
52 extern int MSVCRT___mb_cur_max;
53 extern LCID MSVCRT_current_lc_all_lcid;
54
55 /*********************************************************************
56  *              __p__pctype (MSVCRT.@)
57  */
58 WORD** __p__pctype(void)
59 {
60   return &MSVCRT__pctype;
61 }
62
63 /*********************************************************************
64  *              _isctype (MSVCRT.@)
65  */
66 int _isctype(int c, int type)
67 {
68   if (c >= -1 && c <= 255)
69     return MSVCRT__pctype[c] & type;
70
71   if (MSVCRT___mb_cur_max != 1 && c > 0)
72   {
73     /* FIXME: Is there a faster way to do this? */
74     WORD typeInfo;
75     char convert[3], *pconv = convert;
76
77     if (MSVCRT__pctype[(UINT)c >> 8] & _LEADBYTE)
78       *pconv++ = (UINT)c >> 8;
79     *pconv++ = c & 0xff;
80     *pconv = 0;
81     /* FIXME: Use ctype LCID, not lc_all */
82     if (GetStringTypeExA(MSVCRT_current_lc_all_lcid, CT_CTYPE1,
83                          convert, convert[1] ? 2 : 1, &typeInfo))
84       return typeInfo & type;
85   }
86   return 0;
87 }
88
89 /*********************************************************************
90  *              isalnum (MSVCRT.@)
91  */
92 int MSVCRT_isalnum(int c)
93 {
94   return _isctype( c, _ALPHA | _DIGIT );
95 }
96
97 /*********************************************************************
98  *              isalpha (MSVCRT.@)
99  */
100 int MSVCRT_isalpha(int c)
101 {
102   return _isctype( c, _ALPHA );
103 }
104
105 /*********************************************************************
106  *              iscntrl (MSVCRT.@)
107  */
108 int MSVCRT_iscntrl(int c)
109 {
110   return _isctype( c, _CONTROL );
111 }
112
113 /*********************************************************************
114  *              isdigit (MSVCRT.@)
115  */
116 int MSVCRT_isdigit(int c)
117 {
118   return _isctype( c, _DIGIT );
119 }
120
121 /*********************************************************************
122  *              isgraph (MSVCRT.@)
123  */
124 int MSVCRT_isgraph(int c)
125 {
126   return _isctype( c, _ALPHA | _DIGIT | _PUNCT );
127 }
128
129 /*********************************************************************
130  *              isleadbyte (MSVCRT.@)
131  */
132 int MSVCRT_isleadbyte(int c)
133 {
134   return _isctype( c, _LEADBYTE );
135 }
136
137 /*********************************************************************
138  *              islower (MSVCRT.@)
139  */
140 int MSVCRT_islower(int c)
141 {
142   return _isctype( c, _LOWER );
143 }
144
145 /*********************************************************************
146  *              isprint (MSVCRT.@)
147  */
148 int MSVCRT_isprint(int c)
149 {
150   return _isctype( c, _ALPHA | _DIGIT | _BLANK | _PUNCT );
151 }
152
153 /*********************************************************************
154  *              ispunct (MSVCRT.@)
155  */
156 int MSVCRT_ispunct(int c)
157 {
158   return _isctype( c, _PUNCT );
159 }
160
161 /*********************************************************************
162  *              isspace (MSVCRT.@)
163  */
164 int MSVCRT_isspace(int c)
165 {
166   return _isctype( c, _SPACE );
167 }
168
169 /*********************************************************************
170  *              isupper (MSVCRT.@)
171  */
172 int MSVCRT_isupper(int c)
173 {
174   return _isctype( c, _UPPER );
175 }
176
177 /*********************************************************************
178  *              isxdigit (MSVCRT.@)
179  */
180 int MSVCRT_isxdigit(int c)
181 {
182   return _isctype( c, _HEX );
183 }
184
185 /*********************************************************************
186  *              __isascii (MSVCRT.@)
187  */
188 int MSVCRT___isascii(int c)
189 {
190   return isascii((unsigned)c);
191 }
192
193 /*********************************************************************
194  *              __toascii (MSVCRT.@)
195  */
196 int MSVCRT___toascii(int c)
197 {
198   return (unsigned)c & 0x7f;
199 }
200
201 /*********************************************************************
202  *              iswascii (MSVCRT.@)
203  *
204  */
205 int MSVCRT_iswascii(WCHAR c)
206 {
207   return ((unsigned)c < 0x80);
208 }
209
210 /*********************************************************************
211  *              __iscsym (MSVCRT.@)
212  */
213 int MSVCRT___iscsym(int c)
214 {
215   return (c < 127 && (isalnum(c) || c == '_'));
216 }
217
218 /*********************************************************************
219  *              __iscsymf (MSVCRT.@)
220  */
221 int MSVCRT___iscsymf(int c)
222 {
223   return (c < 127 && (isalpha(c) || c == '_'));
224 }
225
226 /*********************************************************************
227  *              _toupper (MSVCRT.@)
228  */
229 int MSVCRT__toupper(int c)
230 {
231     return c - 0x20;  /* sic */
232 }
233
234 /*********************************************************************
235  *              _tolower (MSVCRT.@)
236  */
237 int MSVCRT__tolower(int c)
238 {
239     return c + 0x20;  /* sic */
240 }