ntdll: Implemented serial IOCTL for status: GET_COMM_STATUS.
[wine/multimedia.git] / dlls / msvcrt / ctype.c
blob1cbf80fc50ae289730b2453bfdf4ced3ed93802f
1 /*
2 * msvcrt.dll ctype functions
4 * Copyright 2000 Jon Griffiths
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "msvcrt.h"
21 #include "wine/debug.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
25 /* Some abbreviations to make the following table readable */
26 #define _C_ MSVCRT__CONTROL
27 #define _S_ MSVCRT__SPACE
28 #define _P_ MSVCRT__PUNCT
29 #define _D_ MSVCRT__DIGIT
30 #define _H_ MSVCRT__HEX
31 #define _U_ MSVCRT__UPPER
32 #define _L_ MSVCRT__LOWER
34 WORD MSVCRT__ctype [257] = {
35 0, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_C_, _S_|_C_,
36 _S_|_C_, _S_|_C_, _S_|_C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_,
37 _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|MSVCRT__BLANK,
38 _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_,
39 _P_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_,
40 _D_|_H_, _D_|_H_, _D_|_H_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _U_|_H_,
41 _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_, _U_, _U_, _U_, _U_,
42 _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_,
43 _U_, _P_, _P_, _P_, _P_, _P_, _P_, _L_|_H_, _L_|_H_, _L_|_H_, _L_|_H_,
44 _L_|_H_, _L_|_H_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_,
45 _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _P_, _P_, _P_, _P_,
46 _C_, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
54 /* Internal: Current ctype table for locale */
55 WORD MSVCRT_current_ctype[257];
57 /* pctype is used by macros in the Win32 headers. It must point
58 * To a table of flags exactly like ctype. To allow locale
59 * changes to affect ctypes (i.e. isleadbyte), we use a second table
60 * and update its flags whenever the current locale changes.
62 WORD* MSVCRT__pctype = MSVCRT_current_ctype + 1;
64 /* mbctype data */
65 extern int MSVCRT___mb_cur_max;
66 extern LCID MSVCRT_current_lc_all_lcid;
68 /*********************************************************************
69 * __p__pctype (MSVCRT.@)
71 WORD** __p__pctype(void)
73 return &MSVCRT__pctype;
76 /*********************************************************************
77 * _isctype (MSVCRT.@)
79 int _isctype(int c, int type)
81 if (c >= -1 && c <= 255)
82 return MSVCRT__pctype[c] & type;
84 if (MSVCRT___mb_cur_max != 1 && c > 0)
86 /* FIXME: Is there a faster way to do this? */
87 WORD typeInfo;
88 char convert[3], *pconv = convert;
90 if (MSVCRT__pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE)
91 *pconv++ = (UINT)c >> 8;
92 *pconv++ = c & 0xff;
93 *pconv = 0;
94 /* FIXME: Use ctype LCID, not lc_all */
95 if (GetStringTypeExA(MSVCRT_current_lc_all_lcid, CT_CTYPE1,
96 convert, convert[1] ? 2 : 1, &typeInfo))
97 return typeInfo & type;
99 return 0;
102 /*********************************************************************
103 * isalnum (MSVCRT.@)
105 int MSVCRT_isalnum(int c)
107 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT );
110 /*********************************************************************
111 * isalpha (MSVCRT.@)
113 int MSVCRT_isalpha(int c)
115 return _isctype( c, MSVCRT__ALPHA );
118 /*********************************************************************
119 * iscntrl (MSVCRT.@)
121 int MSVCRT_iscntrl(int c)
123 return _isctype( c, MSVCRT__CONTROL );
126 /*********************************************************************
127 * isdigit (MSVCRT.@)
129 int MSVCRT_isdigit(int c)
131 return _isctype( c, MSVCRT__DIGIT );
134 /*********************************************************************
135 * isgraph (MSVCRT.@)
137 int MSVCRT_isgraph(int c)
139 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__PUNCT );
142 /*********************************************************************
143 * isleadbyte (MSVCRT.@)
145 int MSVCRT_isleadbyte(int c)
147 return _isctype( c, MSVCRT__LEADBYTE );
150 /*********************************************************************
151 * islower (MSVCRT.@)
153 int MSVCRT_islower(int c)
155 return _isctype( c, MSVCRT__LOWER );
158 /*********************************************************************
159 * isprint (MSVCRT.@)
161 int MSVCRT_isprint(int c)
163 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__BLANK | MSVCRT__PUNCT );
166 /*********************************************************************
167 * ispunct (MSVCRT.@)
169 int MSVCRT_ispunct(int c)
171 return _isctype( c, MSVCRT__PUNCT );
174 /*********************************************************************
175 * isspace (MSVCRT.@)
177 int MSVCRT_isspace(int c)
179 return _isctype( c, MSVCRT__SPACE );
182 /*********************************************************************
183 * isupper (MSVCRT.@)
185 int MSVCRT_isupper(int c)
187 return _isctype( c, MSVCRT__UPPER );
190 /*********************************************************************
191 * isxdigit (MSVCRT.@)
193 int MSVCRT_isxdigit(int c)
195 return _isctype( c, MSVCRT__HEX );
198 /*********************************************************************
199 * __isascii (MSVCRT.@)
201 int MSVCRT___isascii(int c)
203 return isascii((unsigned)c);
206 /*********************************************************************
207 * __toascii (MSVCRT.@)
209 int MSVCRT___toascii(int c)
211 return (unsigned)c & 0x7f;
214 /*********************************************************************
215 * iswascii (MSVCRT.@)
218 int MSVCRT_iswascii(MSVCRT_wchar_t c)
220 return ((unsigned)c < 0x80);
223 /*********************************************************************
224 * __iscsym (MSVCRT.@)
226 int MSVCRT___iscsym(int c)
228 return (c < 127 && (isalnum(c) || c == '_'));
231 /*********************************************************************
232 * __iscsymf (MSVCRT.@)
234 int MSVCRT___iscsymf(int c)
236 return (c < 127 && (isalpha(c) || c == '_'));
239 /*********************************************************************
240 * _toupper (MSVCRT.@)
242 int MSVCRT__toupper(int c)
244 return c - 0x20; /* sic */
247 /*********************************************************************
248 * _tolower (MSVCRT.@)
250 int MSVCRT__tolower(int c)
252 return c + 0x20; /* sic */