source: Daodan/MinGW/include/ctype.h@ 1088

Last change on this file since 1088 was 1046, checked in by alloc, 8 years ago

Daodan: Added Windows MinGW and build batch file

File size: 9.4 KB
Line 
1/*
2 * ctype.h
3 *
4 * Functions for character classification and conversion.
5 *
6 * $Id: ctype.h,v e38eed5e2087 2016/07/09 20:53:41 keithmarshall $
7 *
8 * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
9 * Copyright (C) 1997-2008, 2016, MinGW.org Project
10 *
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice, this permission notice, and the following
20 * disclaimer shall be included in all copies or substantial portions of
21 * the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
29 * DEALINGS IN THE SOFTWARE.
30 *
31 */
32#ifndef _CTYPE_H
33#pragma GCC system_header
34#define _CTYPE_H
35
36/* All MinGW headers must include <_mingw.h>
37 */
38#include <_mingw.h>
39
40/* Although conflicting with both ISO-C and POSIX, Microsoft say that,
41 * in addition to the single byte character classification API which is
42 * properly declared here, this file should also declare elements of the
43 * wide classification API, which is properly declared in <wctype.h>
44 *
45 * To avoid the burden of maintaining duplicate declarations, in two
46 * locations, we keep the wide character declarations where ISO-C and
47 * POSIX say they belong, in <wctype.h>, while accommodating Microsoft
48 * compatibility by providing for selective inclusion of the relevant
49 * elements of it here. (Note that we must do this early, because to
50 * avoid duplication, we delegate the definition of common character
51 * classification macros, with the exception of _LEADBYTE, which is
52 * not required in both headers, to <wctype.h>).
53 */
54#define __CTYPE_H_SOURCED__
55#include <wctype.h>
56
57/* This is the one character classification macro, for which definition
58 * is NOT delegated to <wctype.h>
59 */
60#define _LEADBYTE 0x8000
61
62#ifndef RC_INVOKED
63
64_BEGIN_C_DECLS
65
66_CRTIMP __cdecl __MINGW_NOTHROW int isalnum(int);
67_CRTIMP __cdecl __MINGW_NOTHROW int isalpha(int);
68_CRTIMP __cdecl __MINGW_NOTHROW int iscntrl(int);
69_CRTIMP __cdecl __MINGW_NOTHROW int isdigit(int);
70_CRTIMP __cdecl __MINGW_NOTHROW int isgraph(int);
71_CRTIMP __cdecl __MINGW_NOTHROW int islower(int);
72_CRTIMP __cdecl __MINGW_NOTHROW int isleadbyte (int);
73_CRTIMP __cdecl __MINGW_NOTHROW int isprint(int);
74_CRTIMP __cdecl __MINGW_NOTHROW int ispunct(int);
75_CRTIMP __cdecl __MINGW_NOTHROW int isspace(int);
76_CRTIMP __cdecl __MINGW_NOTHROW int isupper(int);
77_CRTIMP __cdecl __MINGW_NOTHROW int isxdigit(int);
78
79#if __STDC_VERSION__ >= 199901L || !defined __STRICT_ANSI__
80__cdecl __MINGW_NOTHROW int isblank (int);
81#endif
82
83#ifndef __STRICT_ANSI__
84_CRTIMP __cdecl __MINGW_NOTHROW int _isctype (int, int);
85#endif
86
87/* These are ISO-C conforming functions, with correct checking of
88 * argument; they are exported by MSVCRT.DLL, and by CRTDLL.DLL as
89 * such, and are NOT simply old-name mapped variants; however...
90 */
91_CRTIMP __cdecl __MINGW_NOTHROW int tolower (int);
92_CRTIMP __cdecl __MINGW_NOTHROW int toupper (int);
93
94#ifndef __STRICT_ANSI__
95/* ...Microsoft's beloved underscore decorated variants are also
96 * exported. These are cheap non-standard versions: their return
97 * values are undefined if the argument is not an ASCII character,
98 * or is not of appropriate case for the requested conversion.
99 *
100 * Note that these appear to be approximately equivalent to POSIX
101 * macros of the same names, (declared obsolescent in POSIX.1-2008),
102 * but are implemented as DLL functions, rather than macros.
103 */
104_CRTIMP __cdecl __MINGW_NOTHROW int _tolower (int);
105_CRTIMP __cdecl __MINGW_NOTHROW int _toupper (int);
106#endif
107
108#ifndef MB_CUR_MAX
109/* FIXME: also defined in stdlib.h; should be factored into ONE
110 * location ONLY, and included into the other.
111 */
112# ifdef __DECLSPEC_SUPPORTED
113# ifdef __MSVCRT__
114# define MB_CUR_MAX __mb_cur_max
115 __MINGW_IMPORT int __mb_cur_max;
116
117# else /* !__MSVCRT__ */
118# define MB_CUR_MAX __mb_cur_max_dll
119 __MINGW_IMPORT int __mb_cur_max_dll;
120# endif /* !__MSVCRT__ */
121
122# else /* !__DECLSPEC_SUPPORTED */
123# ifdef __MSVCRT__
124# define MB_CUR_MAX (*_imp____mb_cur_max)
125 extern int *_imp____mb_cur_max;
126
127# else /* !__MSVCRT__ */
128# define MB_CUR_MAX (*_imp____mb_cur_max_dll)
129 extern int *_imp____mb_cur_max_dll;
130# endif /* !__MSVCRT__ */
131# endif /* __DECLSPEC_SUPPORTED */
132#endif /* ! MB_CUR_MAX */
133
134#ifdef __DECLSPEC_SUPPORTED
135# if __MSVCRT_VERSION__ <= __MSVCR70_DLL
136 __MINGW_IMPORT unsigned short _ctype[];
137# endif
138
139# ifdef __MSVCRT__
140 __MINGW_IMPORT unsigned short *_pctype;
141
142# else /* !__MSVCRT__ (implies CRTDLL) */
143# define _pctype _pctype_dll
144 __MINGW_IMPORT unsigned short *_pctype_dll;
145# endif
146
147#else /* !__DECLSPEC_SUPPORTED */
148# if __MSVCRT_VERSION__ <= __MSVCR70_DLL
149# define _ctype (*_imp___ctype)
150 extern unsigned short **_imp___ctype;
151# endif
152
153# ifdef __MSVCRT__
154# define _pctype (*_imp___pctype)
155 extern unsigned short **_imp___pctype;
156
157# else /* !__MSVCRT__ (implies CRTDLL) */
158# define _pctype (*_imp___pctype_dll)
159 extern unsigned short **_imp___pctype_dll;
160# endif /* CRTDLL */
161#endif /* !__DECLSPEC_SUPPORTED */
162
163/* Use inlines here rather than macros, because macros will upset
164 * C++ usage (eg, ::isalnum), and so usually get undefined
165 *
166 * According to standard for SB chars, these function are defined only
167 * for input values representable by unsigned char or EOF.
168 * Thus, there is no range test.
169 * This reproduces behaviour of MSVCRT.dll lib implemention for SB chars.
170 *
171 * If no MB char support is needed, these can be simplified even
172 * more by command line define -DMB_CUR_MAX=1. The compiler will then
173 * optimise away the constant condition.
174 */
175
176#if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES) \
177 || defined (__STRICT_ANSI__))
178
179/* Use simple lookup in single byte locales, else _isctype()
180 */
181#define __ISCTYPE(c, mask) (MB_CUR_MAX == 1 ? (_pctype[c] & mask) : _isctype (c, mask))
182
183__CRT_INLINE __cdecl __MINGW_NOTHROW int isalnum (int c)
184{ return __ISCTYPE(c, (_ALPHA|_DIGIT)); }
185
186__CRT_INLINE __cdecl __MINGW_NOTHROW int isalpha (int c)
187{ return __ISCTYPE(c, _ALPHA); }
188
189__CRT_INLINE __cdecl __MINGW_NOTHROW int iscntrl (int c)
190{ return __ISCTYPE(c, _CONTROL); }
191
192__CRT_INLINE __cdecl __MINGW_NOTHROW int isdigit (int c)
193{ return __ISCTYPE(c, _DIGIT); }
194
195__CRT_INLINE __cdecl __MINGW_NOTHROW int isgraph (int c)
196{ return __ISCTYPE(c, (_PUNCT|_ALPHA|_DIGIT)); }
197
198__CRT_INLINE __cdecl __MINGW_NOTHROW int islower (int c)
199{ return __ISCTYPE(c, _LOWER); }
200
201__CRT_INLINE __cdecl __MINGW_NOTHROW int isprint (int c)
202{ return __ISCTYPE(c, (_BLANK|_PUNCT|_ALPHA|_DIGIT)); }
203
204__CRT_INLINE __cdecl __MINGW_NOTHROW int ispunct (int c)
205{ return __ISCTYPE(c, _PUNCT); }
206
207__CRT_INLINE __cdecl __MINGW_NOTHROW int isspace (int c)
208{ return __ISCTYPE(c, _SPACE); }
209
210__CRT_INLINE __cdecl __MINGW_NOTHROW int isupper (int c)
211{ return __ISCTYPE(c, _UPPER); }
212
213__CRT_INLINE __cdecl __MINGW_NOTHROW int isxdigit (int c)
214{ return __ISCTYPE(c, _HEX); }
215
216#if __STDC_VERSION__ >= 199901L || !defined __STRICT_ANSI__
217__CRT_INLINE __cdecl __MINGW_NOTHROW int isblank (int c)
218{ return (__ISCTYPE(c, _BLANK) || c == '\t'); }
219#endif
220
221/* These reproduce the behaviour of their DLL exported namesakes,
222 * and thus ARE the effective equivalents of the similarly named,
223 * and now-obsolescent, POSIX macros.
224 */
225__CRT_INLINE __cdecl __MINGW_NOTHROW int _tolower (int c)
226{ return (c - 'A' + 'a'); }
227
228__CRT_INLINE __cdecl __MINGW_NOTHROW int _toupper (int c)
229{ return (c - 'a' + 'A'); }
230
231/* TODO: is it worth inlining ANSI tolower(), and toupper()?
232 * Probably only if we only want C-locale.
233 */
234#endif /* _NO_CTYPE_INLINES */
235
236__CRT_INLINE __cdecl __MINGW_NOTHROW int isleadbyte (int c)
237{ return (_pctype[(unsigned char)(c)] & _LEADBYTE); }
238
239#ifndef __STRICT_ANSI__
240__cdecl __MINGW_NOTHROW int __isascii (int);
241__cdecl __MINGW_NOTHROW int __toascii (int);
242__cdecl __MINGW_NOTHROW int __iscsymf (int); /* Valid as first character in a C symbol */
243__cdecl __MINGW_NOTHROW int __iscsym (int); /* Valid character in C symbol (after first) */
244
245#if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES))
246
247__CRT_INLINE __cdecl __MINGW_NOTHROW int __isascii (int c)
248{ return ((c & ~0x7F) == 0); }
249
250__CRT_INLINE __cdecl __MINGW_NOTHROW int __toascii (int c)
251{ return (c & 0x7F); }
252
253__CRT_INLINE __cdecl __MINGW_NOTHROW int __iscsymf (int c)
254{ return (isalpha(c) || (c == '_')); }
255
256__CRT_INLINE __cdecl __MINGW_NOTHROW int __iscsym (int c)
257{ return (isalnum(c) || (c == '_')); }
258
259#endif /* !__NO_CTYPE_INLINES */
260
261#ifndef _NO_OLDNAMES
262/* Not _CRTIMP */
263__cdecl __MINGW_NOTHROW int isascii (int);
264__cdecl __MINGW_NOTHROW int toascii (int);
265__cdecl __MINGW_NOTHROW int iscsymf (int);
266__cdecl __MINGW_NOTHROW int iscsym (int);
267#endif /* !_NO_OLDNAMES */
268
269#endif /* !__STRICT_ANSI__ */
270
271_END_C_DECLS
272
273#endif /* ! RC_INVOKED */
274
275#undef __CTYPE_H_SOURCED__
276#endif /* !_CTYPE_H: $RCSfile: ctype.h,v $: end of file */
Note: See TracBrowser for help on using the repository browser.