msvcrt: Tests for [w]makepath.
[wine] / dlls / msvcrt / ctype.c
1 /*
2  * msvcrt.dll ctype functions
3  *
4  * Copyright 2000 Jon Griffiths
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "msvcrt.h"
22 #include "winnls.h"
23
24 /* Some abbreviations to make the following table readable */
25 #define _C_ MSVCRT__CONTROL
26 #define _S_ MSVCRT__SPACE
27 #define _P_ MSVCRT__PUNCT
28 #define _D_ MSVCRT__DIGIT
29 #define _H_ MSVCRT__HEX
30 #define _U_ MSVCRT__UPPER
31 #define _L_ MSVCRT__LOWER
32
33 WORD MSVCRT__ctype [257] = {
34   0, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_C_, _S_|_C_,
35   _S_|_C_, _S_|_C_, _S_|_C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_,
36   _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|MSVCRT__BLANK,
37   _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_,
38   _P_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_,
39   _D_|_H_, _D_|_H_, _D_|_H_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _U_|_H_,
40   _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_, _U_, _U_, _U_, _U_,
41   _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_,
42   _U_, _P_, _P_, _P_, _P_, _P_, _P_, _L_|_H_, _L_|_H_, _L_|_H_, _L_|_H_,
43   _L_|_H_, _L_|_H_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_,
44   _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _P_, _P_, _P_, _P_,
45   _C_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
51 };
52
53 /* Internal: Current ctype table for locale */
54 WORD MSVCRT_current_ctype[257];
55
56 /* pctype is used by macros in the Win32 headers. It must point
57  * To a table of flags exactly like ctype. To allow locale
58  * changes to affect ctypes (i.e. isleadbyte), we use a second table
59  * and update its flags whenever the current locale changes.
60  */
61 WORD* MSVCRT__pctype = MSVCRT_current_ctype + 1;
62
63 /* mbctype data */
64 extern int MSVCRT___mb_cur_max;
65 extern LCID MSVCRT_current_lc_all_lcid;
66
67 /*********************************************************************
68  *              __p__pctype (MSVCRT.@)
69  */
70 WORD** CDECL __p__pctype(void)
71 {
72   return &MSVCRT__pctype;
73 }
74
75 /*********************************************************************
76  *              _isctype (MSVCRT.@)
77  */
78 int CDECL _isctype(int c, int type)
79 {
80   if (c >= -1 && c <= 255)
81     return MSVCRT__pctype[c] & type;
82
83   if (MSVCRT___mb_cur_max != 1 && c > 0)
84   {
85     /* FIXME: Is there a faster way to do this? */
86     WORD typeInfo;
87     char convert[3], *pconv = convert;
88
89     if (MSVCRT__pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE)
90       *pconv++ = (UINT)c >> 8;
91     *pconv++ = c & 0xff;
92     *pconv = 0;
93     /* FIXME: Use ctype LCID, not lc_all */
94     if (GetStringTypeExA(MSVCRT_current_lc_all_lcid, CT_CTYPE1,
95                          convert, convert[1] ? 2 : 1, &typeInfo))
96       return typeInfo & type;
97   }
98   return 0;
99 }
100
101 /*********************************************************************
102  *              isalnum (MSVCRT.@)
103  */
104 int CDECL MSVCRT_isalnum(int c)
105 {
106   return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT );
107 }
108
109 /*********************************************************************
110  *              isalpha (MSVCRT.@)
111  */
112 int CDECL MSVCRT_isalpha(int c)
113 {
114   return _isctype( c, MSVCRT__ALPHA );
115 }
116
117 /*********************************************************************
118  *              iscntrl (MSVCRT.@)
119  */
120 int CDECL MSVCRT_iscntrl(int c)
121 {
122   return _isctype( c, MSVCRT__CONTROL );
123 }
124
125 /*********************************************************************
126  *              isdigit (MSVCRT.@)
127  */
128 int CDECL MSVCRT_isdigit(int c)
129 {
130   return _isctype( c, MSVCRT__DIGIT );
131 }
132
133 /*********************************************************************
134  *              isgraph (MSVCRT.@)
135  */
136 int CDECL MSVCRT_isgraph(int c)
137 {
138   return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__PUNCT );
139 }
140
141 /*********************************************************************
142  *              isleadbyte (MSVCRT.@)
143  */
144 int CDECL MSVCRT_isleadbyte(int c)
145 {
146   return _isctype( c, MSVCRT__LEADBYTE );
147 }
148
149 /*********************************************************************
150  *              islower (MSVCRT.@)
151  */
152 int CDECL MSVCRT_islower(int c)
153 {
154   return _isctype( c, MSVCRT__LOWER );
155 }
156
157 /*********************************************************************
158  *              isprint (MSVCRT.@)
159  */
160 int CDECL MSVCRT_isprint(int c)
161 {
162   return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__BLANK | MSVCRT__PUNCT );
163 }
164
165 /*********************************************************************
166  *              ispunct (MSVCRT.@)
167  */
168 int CDECL MSVCRT_ispunct(int c)
169 {
170   return _isctype( c, MSVCRT__PUNCT );
171 }
172
173 /*********************************************************************
174  *              isspace (MSVCRT.@)
175  */
176 int CDECL MSVCRT_isspace(int c)
177 {
178   return _isctype( c, MSVCRT__SPACE );
179 }
180
181 /*********************************************************************
182  *              isupper (MSVCRT.@)
183  */
184 int CDECL MSVCRT_isupper(int c)
185 {
186   return _isctype( c, MSVCRT__UPPER );
187 }
188
189 /*********************************************************************
190  *              isxdigit (MSVCRT.@)
191  */
192 int CDECL MSVCRT_isxdigit(int c)
193 {
194   return _isctype( c, MSVCRT__HEX );
195 }
196
197 /*********************************************************************
198  *              __isascii (MSVCRT.@)
199  */
200 int CDECL MSVCRT___isascii(int c)
201 {
202   return isascii((unsigned)c);
203 }
204
205 /*********************************************************************
206  *              __toascii (MSVCRT.@)
207  */
208 int CDECL MSVCRT___toascii(int c)
209 {
210   return (unsigned)c & 0x7f;
211 }
212
213 /*********************************************************************
214  *              iswascii (MSVCRT.@)
215  *
216  */
217 int CDECL MSVCRT_iswascii(MSVCRT_wchar_t c)
218 {
219   return ((unsigned)c < 0x80);
220 }
221
222 /*********************************************************************
223  *              __iscsym (MSVCRT.@)
224  */
225 int CDECL MSVCRT___iscsym(int c)
226 {
227   return (c < 127 && (isalnum(c) || c == '_'));
228 }
229
230 /*********************************************************************
231  *              __iscsymf (MSVCRT.@)
232  */
233 int CDECL MSVCRT___iscsymf(int c)
234 {
235   return (c < 127 && (isalpha(c) || c == '_'));
236 }
237
238 /*********************************************************************
239  *              _toupper (MSVCRT.@)
240  */
241 int CDECL MSVCRT__toupper(int c)
242 {
243     return c - 0x20;  /* sic */
244 }
245
246 /*********************************************************************
247  *              _tolower (MSVCRT.@)
248  */
249 int CDECL MSVCRT__tolower(int c)
250 {
251     return c + 0x20;  /* sic */
252 }