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