Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/iFabio/Chameleon/i386/include/ctype.h

Source at commit 296 created 12 years 10 months ago.
By ifabio, add i386 folder
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.h8.4 (Berkeley) 1/21/94
64 */
65
66//Begin-Libc
67//#include "xlocale_private.h"
68//End-Libc
69#ifndef_CTYPE_H_
70#define _CTYPE_H_
71
72#include <runetype.h>
73
74#define_CTYPE_A0x00000100L/* Alpha */
75#define_CTYPE_C0x00000200L/* Control */
76#define_CTYPE_D0x00000400L/* Digit */
77#define_CTYPE_G0x00000800L/* Graph */
78#define_CTYPE_L0x00001000L/* Lower */
79#define_CTYPE_P0x00002000L/* Punct */
80#define_CTYPE_S0x00004000L/* Space */
81#define_CTYPE_U0x00008000L/* Upper */
82#define_CTYPE_X0x00010000L/* X digit */
83#define_CTYPE_B0x00020000L/* Blank */
84#define_CTYPE_R0x00040000L/* Print */
85#define_CTYPE_I0x00080000L/* Ideogram */
86#define_CTYPE_T0x00100000L/* Special */
87#define_CTYPE_Q0x00200000L/* Phonogram */
88#define_CTYPE_SW00x20000000L/* 0 width character */
89#define_CTYPE_SW10x40000000L/* 1 width character */
90#define_CTYPE_SW20x80000000L/* 2 width character */
91#define_CTYPE_SW30xc0000000L/* 3 width character */
92#define_CTYPE_SWM0xe0000000L/* Mask for screen width data */
93#define_CTYPE_SWS30/* Bits to shift to get width */
94
95#ifdef _NONSTD_SOURCE
96/*
97 * Backward compatibility
98 */
99#define_A_CTYPE_A/* Alpha */
100#define_C_CTYPE_C/* Control */
101#define_D_CTYPE_D/* Digit */
102#define_G_CTYPE_G/* Graph */
103#define_L_CTYPE_L/* Lower */
104#define_P_CTYPE_P/* Punct */
105#define_S_CTYPE_S/* Space */
106#define_U_CTYPE_U/* Upper */
107#define_X_CTYPE_X/* X digit */
108#define_B_CTYPE_B/* Blank */
109#define_R_CTYPE_R/* Print */
110#define_I_CTYPE_I/* Ideogram */
111#define_T_CTYPE_T/* Special */
112#define_Q_CTYPE_Q/* Phonogram */
113#define_SW0_CTYPE_SW0/* 0 width character */
114#define_SW1_CTYPE_SW1/* 1 width character */
115#define_SW2_CTYPE_SW2/* 2 width character */
116#define_SW3_CTYPE_SW3/* 3 width character */
117#endif /* _NONSTD_SOURCE */
118
119/*
120 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
121 * to generate code for extern versions of all intermediate inline functions.
122 */
123#ifdef _EXTERNALIZE_CTYPE_INLINES_
124#define _USE_CTYPE_INLINE_
125#define __DARWIN_CTYPE_static_inline
126#else /* !_EXTERNALIZE_CTYPE_INLINES_ */
127#define __DARWIN_CTYPE_static_inlinestatic __inline
128#endif /* !_EXTERNALIZE_CTYPE_INLINES_ */
129
130/*
131 * _EXTERNALIZE_CTYPE_INLINES_TOP_ is defined in locale/isctype.c to tell us
132 * to generate code for extern versions of all top-level inline functions.
133 */
134#ifdef _EXTERNALIZE_CTYPE_INLINES_TOP_
135#define _USE_CTYPE_INLINE_
136#define __DARWIN_CTYPE_TOP_static_inline
137#else /* !_EXTERNALIZE_CTYPE_INLINES_TOP_ */
138#define __DARWIN_CTYPE_TOP_static_inlinestatic __inline
139#endif /* _EXTERNALIZE_CTYPE_INLINES_TOP_ */
140
141/*
142 * Use inline functions if we are allowed to and the compiler supports them.
143 */
144#if !defined(_DONT_USE_CTYPE_INLINE_) && \
145 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
146
147/* See comments in <machine/_type.h> about __darwin_ct_rune_t. */
148__BEGIN_DECLS
149unsigned long___runetype(__darwin_ct_rune_t);
150__darwin_ct_rune_t___tolower(__darwin_ct_rune_t);
151__darwin_ct_rune_t___toupper(__darwin_ct_rune_t);
152__END_DECLS
153
154__DARWIN_CTYPE_TOP_static_inline int
155isascii(int _c)
156{
157return ((_c & ~0x7F) == 0);
158}
159
160#ifdef USE_ASCII
161__DARWIN_CTYPE_static_inline int
162__maskrune(__darwin_ct_rune_t _c, unsigned long _f)
163{
164return _DefaultRuneLocale.__runetype[_c & 0xff] & _f;
165}
166//Begin-Libc
167#elif defined(__LIBC__)
168__DARWIN_CTYPE_static_inline int
169__maskrune(__darwin_ct_rune_t _c, unsigned long _f)
170{
171return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
172__current_locale()->__lc_ctype->_CurrentRuneLocale.__runetype[_c]) & _f;
173}
174//End-Libc
175#else /* !USE_ASCII */
176__BEGIN_DECLS
177int __maskrune(__darwin_ct_rune_t, unsigned long);
178__END_DECLS
179#endif /* USE_ASCII */
180
181__DARWIN_CTYPE_static_inline int
182__istype(__darwin_ct_rune_t _c, unsigned long _f)
183{
184#ifdef USE_ASCII
185return !!(__maskrune(_c, _f));
186#else /* USE_ASCII */
187return (isascii(_c) ? !!(_DefaultRuneLocale.__runetype[_c] & _f)
188: !!__maskrune(_c, _f));
189#endif /* USE_ASCII */
190}
191
192__DARWIN_CTYPE_static_inline __darwin_ct_rune_t
193__isctype(__darwin_ct_rune_t _c, unsigned long _f)
194{
195#ifdef USE_ASCII
196return !!(__maskrune(_c, _f));
197#else /* USE_ASCII */
198return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
199!!(_DefaultRuneLocale.__runetype[_c] & _f);
200#endif /* USE_ASCII */
201}
202
203#ifdef USE_ASCII
204__DARWIN_CTYPE_static_inline __darwin_ct_rune_t
205__toupper(__darwin_ct_rune_t _c)
206{
207return _DefaultRuneLocale.__mapupper[_c & 0xff];
208}
209
210__DARWIN_CTYPE_static_inline __darwin_ct_rune_t
211__tolower(__darwin_ct_rune_t _c)
212{
213return _DefaultRuneLocale.__maplower[_c & 0xff];
214}
215//Begin-Libc
216#elif defined(__LIBC__)
217/*
218 * We can't do what we do for __toupper_l() (check for ASCII first, then call
219 * ___toupper_l() otherwise) because versions of ___toupper() before Tiger
220 * assume c >= _CACHED_RUNES. So we are stuck making __toupper() a routine
221 * to hide the extended locale details, outside of Libc.
222 */
223__DARWIN_CTYPE_static_inline __darwin_ct_rune_t
224__toupper(__darwin_ct_rune_t _c)
225{
226return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
227__current_locale()->__lc_ctype->_CurrentRuneLocale.__mapupper[_c];
228}
229
230__DARWIN_CTYPE_static_inline __darwin_ct_rune_t
231__tolower(__darwin_ct_rune_t _c)
232{
233return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
234__current_locale()->__lc_ctype->_CurrentRuneLocale.__maplower[_c];
235}
236//End-Libc
237#else /* !USE_ASCII */
238__BEGIN_DECLS
239__darwin_ct_rune_t__toupper(__darwin_ct_rune_t);
240__darwin_ct_rune_t__tolower(__darwin_ct_rune_t);
241__END_DECLS
242#endif /* USE_ASCII */
243
244__DARWIN_CTYPE_static_inline int
245__wcwidth(__darwin_ct_rune_t _c)
246{
247unsigned int _x;
248
249if (_c == 0)
250return (0);
251_x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R);
252if ((_x & _CTYPE_SWM) != 0)
253return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
254return ((_x & _CTYPE_R) != 0 ? 1 : -1);
255}
256
257#ifndef _EXTERNALIZE_CTYPE_INLINES_
258
259#define_tolower(c)__tolower(c)
260#define_toupper(c)__toupper(c)
261
262__DARWIN_CTYPE_TOP_static_inline int
263isalnum(int _c)
264{
265return (__istype(_c, _CTYPE_A|_CTYPE_D));
266}
267
268__DARWIN_CTYPE_TOP_static_inline int
269isalpha(int _c)
270{
271return (__istype(_c, _CTYPE_A));
272}
273
274__DARWIN_CTYPE_TOP_static_inline int
275isblank(int _c)
276{
277return (__istype(_c, _CTYPE_B));
278}
279
280__DARWIN_CTYPE_TOP_static_inline int
281iscntrl(int _c)
282{
283return (__istype(_c, _CTYPE_C));
284}
285
286/* ANSI -- locale independent */
287__DARWIN_CTYPE_TOP_static_inline int
288isdigit(int _c)
289{
290return (__isctype(_c, _CTYPE_D));
291}
292
293__DARWIN_CTYPE_TOP_static_inline int
294isgraph(int _c)
295{
296return (__istype(_c, _CTYPE_G));
297}
298
299__DARWIN_CTYPE_TOP_static_inline int
300islower(int _c)
301{
302return (__istype(_c, _CTYPE_L));
303}
304
305__DARWIN_CTYPE_TOP_static_inline int
306isprint(int _c)
307{
308return (__istype(_c, _CTYPE_R));
309}
310
311__DARWIN_CTYPE_TOP_static_inline int
312ispunct(int _c)
313{
314return (__istype(_c, _CTYPE_P));
315}
316
317__DARWIN_CTYPE_TOP_static_inline int
318isspace(int _c)
319{
320return (__istype(_c, _CTYPE_S));
321}
322
323__DARWIN_CTYPE_TOP_static_inline int
324isupper(int _c)
325{
326return (__istype(_c, _CTYPE_U));
327}
328
329/* ANSI -- locale independent */
330__DARWIN_CTYPE_TOP_static_inline int
331isxdigit(int _c)
332{
333return (__isctype(_c, _CTYPE_X));
334}
335
336__DARWIN_CTYPE_TOP_static_inline int
337toascii(int _c)
338{
339return (_c & 0x7F);
340}
341
342__DARWIN_CTYPE_TOP_static_inline int
343tolower(int _c)
344{
345 return (__tolower(_c));
346}
347
348__DARWIN_CTYPE_TOP_static_inline int
349toupper(int _c)
350{
351 return (__toupper(_c));
352}
353
354#if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
355__DARWIN_CTYPE_TOP_static_inline int
356digittoint(int _c)
357{
358return (__maskrune(_c, 0x0F));
359}
360
361__DARWIN_CTYPE_TOP_static_inline int
362ishexnumber(int _c)
363{
364return (__istype(_c, _CTYPE_X));
365}
366
367__DARWIN_CTYPE_TOP_static_inline int
368isideogram(int _c)
369{
370return (__istype(_c, _CTYPE_I));
371}
372
373__DARWIN_CTYPE_TOP_static_inline int
374isnumber(int _c)
375{
376return (__istype(_c, _CTYPE_D));
377}
378
379__DARWIN_CTYPE_TOP_static_inline int
380isphonogram(int _c)
381{
382return (__istype(_c, _CTYPE_Q));
383}
384
385__DARWIN_CTYPE_TOP_static_inline int
386isrune(int _c)
387{
388return (__istype(_c, 0xFFFFFFF0L));
389}
390
391__DARWIN_CTYPE_TOP_static_inline int
392isspecial(int _c)
393{
394return (__istype(_c, _CTYPE_T));
395}
396#endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
397#endif /* _EXTERNALIZE_CTYPE_INLINES_ */
398
399#else /* not using inlines */
400
401__BEGIN_DECLS
402int isalnum(int);
403int isalpha(int);
404int isblank(int);
405int iscntrl(int);
406int isdigit(int);
407int isgraph(int);
408int islower(int);
409int isprint(int);
410int ispunct(int);
411int isspace(int);
412int isupper(int);
413int isxdigit(int);
414int tolower(int);
415int toupper(int);
416int isascii(int);
417int toascii(int);
418
419#if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
420int _tolower(int);
421int _toupper(int);
422int digittoint(int);
423int ishexnumber(int);
424int isideogram(int);
425int isnumber(int);
426int isphonogram(int);
427int isrune(int);
428int isspecial(int);
429#endif
430__END_DECLS
431
432#endif /* using inlines */
433
434#ifdef _USE_EXTENDED_LOCALES_
435#include <xlocale/_ctype.h>
436#endif /* _USE_EXTENDED_LOCALES_ */
437
438#endif /* !_CTYPE_H_ */
439

Archive Download this file

Revision: 296