1 : /*
2 : * Copyright (c) 2000, 2005, 2008 Apple Inc. All rights reserved.
3 : *
4 : * @APPLE_LICENSE_HEADER_START@
5 : *
6 : * This file contains Original Code and/or Modifications of Original Code
7 : * as defined in and that are subject to the Apple Public Source License
8 : * Version 2.0 (the 'License'). You may not use this file except in
9 : * compliance with the License. Please obtain a copy of the License at
10 : * http://www.opensource.apple.com/apsl/ and read it before using this
11 : * file.
12 : *
13 : * The Original Code and all software distributed under the License are
14 : * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 : * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 : * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 : * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 : * Please see the License for the specific language governing rights and
19 : * limitations under the License.
20 : *
21 : * @APPLE_LICENSE_HEADER_END@
22 : */
23 : /*
24 : * Copyright (c) 1989, 1993
25 : * The Regents of the University of California. All rights reserved.
26 : * (c) UNIX System Laboratories, Inc.
27 : * All or some portions of this file are derived from material licensed
28 : * to the University of California by American Telephone and Telegraph
29 : * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 : * the permission of UNIX System Laboratories, Inc.
31 : *
32 : * This code is derived from software contributed to Berkeley by
33 : * Paul Borman at Krystal Technologies.
34 : *
35 : * Redistribution and use in source and binary forms, with or without
36 : * modification, are permitted provided that the following conditions
37 : * are met:
38 : * 1. Redistributions of source code must retain the above copyright
39 : * notice, this list of conditions and the following disclaimer.
40 : * 2. Redistributions in binary form must reproduce the above copyright
41 : * notice, this list of conditions and the following disclaimer in the
42 : * documentation and/or other materials provided with the distribution.
43 : * 3. All advertising materials mentioning features or use of this software
44 : * must display the following acknowledgement:
45 : * This product includes software developed by the University of
46 : * California, Berkeley and its contributors.
47 : * 4. Neither the name of the University nor the names of its contributors
48 : * may be used to endorse or promote products derived from this software
49 : * without specific prior written permission.
50 : *
51 : * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 : * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 : * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 : * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 : * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 : * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 : * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 : * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 : * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 : * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 : * SUCH DAMAGE.
62 : *
63 : * @(#)ctype.h 8.4 (Berkeley) 1/21/94
64 : */
65 :
66 : #ifndef _CTYPE_H_
67 : #define _CTYPE_H_
68 :
69 : #include <runetype.h>
70 :
71 : #define _CTYPE_A 0x00000100L /* Alpha */
72 : #define _CTYPE_C 0x00000200L /* Control */
73 : #define _CTYPE_D 0x00000400L /* Digit */
74 : #define _CTYPE_G 0x00000800L /* Graph */
75 : #define _CTYPE_L 0x00001000L /* Lower */
76 : #define _CTYPE_P 0x00002000L /* Punct */
77 : #define _CTYPE_S 0x00004000L /* Space */
78 : #define _CTYPE_U 0x00008000L /* Upper */
79 : #define _CTYPE_X 0x00010000L /* X digit */
80 : #define _CTYPE_B 0x00020000L /* Blank */
81 : #define _CTYPE_R 0x00040000L /* Print */
82 : #define _CTYPE_I 0x00080000L /* Ideogram */
83 : #define _CTYPE_T 0x00100000L /* Special */
84 : #define _CTYPE_Q 0x00200000L /* Phonogram */
85 : #define _CTYPE_SW0 0x20000000L /* 0 width character */
86 : #define _CTYPE_SW1 0x40000000L /* 1 width character */
87 : #define _CTYPE_SW2 0x80000000L /* 2 width character */
88 : #define _CTYPE_SW3 0xc0000000L /* 3 width character */
89 : #define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */
90 : #define _CTYPE_SWS 30 /* Bits to shift to get width */
91 :
92 : #ifdef _NONSTD_SOURCE
93 : /*
94 : * Backward compatibility
95 : */
96 : #define _A _CTYPE_A /* Alpha */
97 : #define _C _CTYPE_C /* Control */
98 : #define _D _CTYPE_D /* Digit */
99 : #define _G _CTYPE_G /* Graph */
100 : #define _L _CTYPE_L /* Lower */
101 : #define _P _CTYPE_P /* Punct */
102 : #define _S _CTYPE_S /* Space */
103 : #define _U _CTYPE_U /* Upper */
104 : #define _X _CTYPE_X /* X digit */
105 : #define _B _CTYPE_B /* Blank */
106 : #define _R _CTYPE_R /* Print */
107 : #define _I _CTYPE_I /* Ideogram */
108 : #define _T _CTYPE_T /* Special */
109 : #define _Q _CTYPE_Q /* Phonogram */
110 : #define _SW0 _CTYPE_SW0 /* 0 width character */
111 : #define _SW1 _CTYPE_SW1 /* 1 width character */
112 : #define _SW2 _CTYPE_SW2 /* 2 width character */
113 : #define _SW3 _CTYPE_SW3 /* 3 width character */
114 : #endif /* _NONSTD_SOURCE */
115 :
116 : /*
117 : * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
118 : * to generate code for extern versions of all intermediate inline functions.
119 : */
120 : #ifdef _EXTERNALIZE_CTYPE_INLINES_
121 : #define _USE_CTYPE_INLINE_
122 : #define __DARWIN_CTYPE_static_inline
123 : #else /* !_EXTERNALIZE_CTYPE_INLINES_ */
124 : #define __DARWIN_CTYPE_static_inline static __inline
125 : #endif /* !_EXTERNALIZE_CTYPE_INLINES_ */
126 :
127 : /*
128 : * _EXTERNALIZE_CTYPE_INLINES_TOP_ is defined in locale/isctype.c to tell us
129 : * to generate code for extern versions of all top-level inline functions.
130 : */
131 : #ifdef _EXTERNALIZE_CTYPE_INLINES_TOP_
132 : #define _USE_CTYPE_INLINE_
133 : #define __DARWIN_CTYPE_TOP_static_inline
134 : #else /* !_EXTERNALIZE_CTYPE_INLINES_TOP_ */
135 : #define __DARWIN_CTYPE_TOP_static_inline static __inline
136 : #endif /* _EXTERNALIZE_CTYPE_INLINES_TOP_ */
137 :
138 : /*
139 : * Use inline functions if we are allowed to and the compiler supports them.
140 : */
141 : #if !defined(_DONT_USE_CTYPE_INLINE_) && \
142 : (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
143 :
144 : /* See comments in <machine/_type.h> about __darwin_ct_rune_t. */
145 : __BEGIN_DECLS
146 : unsigned long ___runetype(__darwin_ct_rune_t);
147 : __darwin_ct_rune_t ___tolower(__darwin_ct_rune_t);
148 : __darwin_ct_rune_t ___toupper(__darwin_ct_rune_t);
149 : __END_DECLS
150 :
151 : __DARWIN_CTYPE_TOP_static_inline int
152 7361 : isascii(int _c)
153 : {
154 7361 : return ((_c & ~0x7F) == 0);
155 : }
156 :
157 : #ifdef USE_ASCII
158 : __DARWIN_CTYPE_static_inline int
159 : __maskrune(__darwin_ct_rune_t _c, unsigned long _f)
160 : {
161 : return _DefaultRuneLocale.__runetype[_c & 0xff] & _f;
162 : }
163 : #else /* !USE_ASCII */
164 : __BEGIN_DECLS
165 : int __maskrune(__darwin_ct_rune_t, unsigned long);
166 : __END_DECLS
167 : #endif /* USE_ASCII */
168 :
169 : __DARWIN_CTYPE_static_inline int
170 7361 : __istype(__darwin_ct_rune_t _c, unsigned long _f)
171 : {
172 : #ifdef USE_ASCII
173 : return !!(__maskrune(_c, _f));
174 : #else /* USE_ASCII */
175 14722 : return (isascii(_c) ? !!(_DefaultRuneLocale.__runetype[_c] & _f)
176 7361 : : !!__maskrune(_c, _f));
177 : #endif /* USE_ASCII */
178 : }
179 :
180 : __DARWIN_CTYPE_static_inline __darwin_ct_rune_t
181 1088 : __isctype(__darwin_ct_rune_t _c, unsigned long _f)
182 : {
183 : #ifdef USE_ASCII
184 : return !!(__maskrune(_c, _f));
185 : #else /* USE_ASCII */
186 4352 : return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
187 : !!(_DefaultRuneLocale.__runetype[_c] & _f);
188 : #endif /* USE_ASCII */
189 : }
190 :
191 : #ifdef USE_ASCII
192 : __DARWIN_CTYPE_static_inline __darwin_ct_rune_t
193 : __toupper(__darwin_ct_rune_t _c)
194 : {
195 : return _DefaultRuneLocale.__mapupper[_c & 0xff];
196 : }
197 :
198 : __DARWIN_CTYPE_static_inline __darwin_ct_rune_t
199 : __tolower(__darwin_ct_rune_t _c)
200 : {
201 : return _DefaultRuneLocale.__maplower[_c & 0xff];
202 : }
203 : #else /* !USE_ASCII */
204 : __BEGIN_DECLS
205 : __darwin_ct_rune_t __toupper(__darwin_ct_rune_t);
206 : __darwin_ct_rune_t __tolower(__darwin_ct_rune_t);
207 : __END_DECLS
208 : #endif /* USE_ASCII */
209 :
210 : __DARWIN_CTYPE_static_inline int
211 : __wcwidth(__darwin_ct_rune_t _c)
212 : {
213 : unsigned int _x;
214 :
215 : if (_c == 0)
216 : return (0);
217 : _x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R);
218 : if ((_x & _CTYPE_SWM) != 0)
219 : return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
220 : return ((_x & _CTYPE_R) != 0 ? 1 : -1);
221 : }
222 :
223 : #ifndef _EXTERNALIZE_CTYPE_INLINES_
224 :
225 : #define _tolower(c) __tolower(c)
226 : #define _toupper(c) __toupper(c)
227 :
228 : __DARWIN_CTYPE_TOP_static_inline int
229 : isalnum(int _c)
230 : {
231 : return (__istype(_c, _CTYPE_A|_CTYPE_D));
232 : }
233 :
234 : __DARWIN_CTYPE_TOP_static_inline int
235 0 : isalpha(int _c)
236 : {
237 0 : return (__istype(_c, _CTYPE_A));
238 : }
239 :
240 : __DARWIN_CTYPE_TOP_static_inline int
241 : isblank(int _c)
242 : {
243 : return (__istype(_c, _CTYPE_B));
244 : }
245 :
246 : __DARWIN_CTYPE_TOP_static_inline int
247 : iscntrl(int _c)
248 : {
249 : return (__istype(_c, _CTYPE_C));
250 : }
251 :
252 : /* ANSI -- locale independent */
253 : __DARWIN_CTYPE_TOP_static_inline int
254 1088 : isdigit(int _c)
255 : {
256 1088 : return (__isctype(_c, _CTYPE_D));
257 : }
258 :
259 : __DARWIN_CTYPE_TOP_static_inline int
260 : isgraph(int _c)
261 : {
262 : return (__istype(_c, _CTYPE_G));
263 : }
264 :
265 : __DARWIN_CTYPE_TOP_static_inline int
266 : islower(int _c)
267 : {
268 : return (__istype(_c, _CTYPE_L));
269 : }
270 :
271 : __DARWIN_CTYPE_TOP_static_inline int
272 0 : isprint(int _c)
273 : {
274 0 : return (__istype(_c, _CTYPE_R));
275 : }
276 :
277 : __DARWIN_CTYPE_TOP_static_inline int
278 : ispunct(int _c)
279 : {
280 : return (__istype(_c, _CTYPE_P));
281 : }
282 :
283 : __DARWIN_CTYPE_TOP_static_inline int
284 7361 : isspace(int _c)
285 : {
286 7361 : return (__istype(_c, _CTYPE_S));
287 : }
288 :
289 : __DARWIN_CTYPE_TOP_static_inline int
290 0 : isupper(int _c)
291 : {
292 0 : return (__istype(_c, _CTYPE_U));
293 : }
294 :
295 : /* ANSI -- locale independent */
296 : __DARWIN_CTYPE_TOP_static_inline int
297 0 : isxdigit(int _c)
298 : {
299 0 : return (__isctype(_c, _CTYPE_X));
300 : }
301 :
302 : __DARWIN_CTYPE_TOP_static_inline int
303 : toascii(int _c)
304 : {
305 : return (_c & 0x7F);
306 : }
307 :
308 : __DARWIN_CTYPE_TOP_static_inline int
309 68070 : tolower(int _c)
310 : {
311 68070 : return (__tolower(_c));
312 : }
313 :
314 : __DARWIN_CTYPE_TOP_static_inline int
315 72112 : toupper(int _c)
316 : {
317 72112 : return (__toupper(_c));
318 : }
319 :
320 : #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
321 : __DARWIN_CTYPE_TOP_static_inline int
322 : digittoint(int _c)
323 : {
324 : return (__maskrune(_c, 0x0F));
325 : }
326 :
327 : __DARWIN_CTYPE_TOP_static_inline int
328 : ishexnumber(int _c)
329 : {
330 : return (__istype(_c, _CTYPE_X));
331 : }
332 :
333 : __DARWIN_CTYPE_TOP_static_inline int
334 : isideogram(int _c)
335 : {
336 : return (__istype(_c, _CTYPE_I));
337 : }
338 :
339 : __DARWIN_CTYPE_TOP_static_inline int
340 : isnumber(int _c)
341 : {
342 : return (__istype(_c, _CTYPE_D));
343 : }
344 :
345 : __DARWIN_CTYPE_TOP_static_inline int
346 : isphonogram(int _c)
347 : {
348 : return (__istype(_c, _CTYPE_Q));
349 : }
350 :
351 : __DARWIN_CTYPE_TOP_static_inline int
352 : isrune(int _c)
353 : {
354 : return (__istype(_c, 0xFFFFFFF0L));
355 : }
356 :
357 : __DARWIN_CTYPE_TOP_static_inline int
358 : isspecial(int _c)
359 : {
360 : return (__istype(_c, _CTYPE_T));
361 : }
362 : #endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
363 : #endif /* _EXTERNALIZE_CTYPE_INLINES_ */
364 :
365 : #else /* not using inlines */
366 :
367 : __BEGIN_DECLS
368 : int isalnum(int);
369 : int isalpha(int);
370 : int isblank(int);
371 : int iscntrl(int);
372 : int isdigit(int);
373 : int isgraph(int);
374 : int islower(int);
375 : int isprint(int);
376 : int ispunct(int);
377 : int isspace(int);
378 : int isupper(int);
379 : int isxdigit(int);
380 : int tolower(int);
381 : int toupper(int);
382 : int isascii(int);
383 : int toascii(int);
384 :
385 : #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
386 : int _tolower(int);
387 : int _toupper(int);
388 : int digittoint(int);
389 : int ishexnumber(int);
390 : int isideogram(int);
391 : int isnumber(int);
392 : int isphonogram(int);
393 : int isrune(int);
394 : int isspecial(int);
395 : #endif
396 : __END_DECLS
397 :
398 : #endif /* using inlines */
399 :
400 : #ifdef _USE_EXTENDED_LOCALES_
401 : #include <xlocale/_ctype.h>
402 : #endif /* _USE_EXTENDED_LOCALES_ */
403 :
404 : #endif /* !_CTYPE_H_ */
|