]> git.saurik.com Git - apple/xnu.git/blame - bsd/include/ctype.h
xnu-123.5.tar.gz
[apple/xnu.git] / bsd / include / ctype.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright (c) 1989, 1993
24 * The Regents of the University of California. All rights reserved.
25 * (c) UNIX System Laboratories, Inc.
26 * All or some portions of this file are derived from material licensed
27 * to the University of California by American Telephone and Telegraph
28 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
29 * the permission of UNIX System Laboratories, Inc.
30 *
31 * This code is derived from software contributed to Berkeley by
32 * Paul Borman at Krystal Technologies.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)ctype.h 8.4 (Berkeley) 1/21/94
63 */
64
65#ifndef _CTYPE_H_
66#define _CTYPE_H_
67
68#include <runetype.h>
69
70#define _A 0x00000100L /* Alpha */
71#define _C 0x00000200L /* Control */
72#define _D 0x00000400L /* Digit */
73#define _G 0x00000800L /* Graph */
74#define _L 0x00001000L /* Lower */
75#define _P 0x00002000L /* Punct */
76#define _S 0x00004000L /* Space */
77#define _U 0x00008000L /* Upper */
78#define _X 0x00010000L /* X digit */
79#define _B 0x00020000L /* Blank */
80#define _R 0x00040000L /* Print */
81#define _I 0x00080000L /* Ideogram */
82#define _T 0x00100000L /* Special */
83#define _Q 0x00200000L /* Phonogram */
84
85#define isalnum(c) __istype((c), (_A|_D))
86#define isalpha(c) __istype((c), _A)
87#define iscntrl(c) __istype((c), _C)
88#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */
89#define isgraph(c) __istype((c), _G)
90#define islower(c) __istype((c), _L)
91#define isprint(c) __istype((c), _R)
92#define ispunct(c) __istype((c), _P)
93#define isspace(c) __istype((c), _S)
94#define isupper(c) __istype((c), _U)
95#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */
96
97#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
98#define isascii(c) ((c & ~0x7F) == 0)
99#define toascii(c) ((c) & 0x7F)
100#define digittoint(c) __istype((c), 0xFF)
101#define isideogram(c) __istype((c), _I)
102#define isphonogram(c) __istype((c), _T)
103#define isspecial(c) __istype((c), _Q)
104#define isblank(c) __istype((c), _B)
105#define isrune(c) __istype((c), 0xFFFFFF00L)
106#define isnumber(c) __istype((c), _D)
107#define ishexnumber(c) __istype((c), _X)
108#endif
109
110/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
111__BEGIN_DECLS
112unsigned long ___runetype __P((_BSD_RUNE_T_));
113_BSD_RUNE_T_ ___tolower __P((_BSD_RUNE_T_));
114_BSD_RUNE_T_ ___toupper __P((_BSD_RUNE_T_));
115__END_DECLS
116
117/*
118 * If your compiler supports prototypes and inline functions,
119 * #define _USE_CTYPE_INLINE_. Otherwise, use the C library
120 * functions.
121 */
122#if !defined(_USE_CTYPE_CLIBRARY_) && defined(__GNUC__) || defined(__cplusplus)
123#define _USE_CTYPE_INLINE_ 1
124#endif
125
126#if defined(_USE_CTYPE_INLINE_)
127static __inline int
128__istype(_BSD_RUNE_T_ c, unsigned long f)
129{
130 return((((c & _CRMASK) ? ___runetype(c) :
131 _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0);
132}
133
134static __inline int
135__isctype(_BSD_RUNE_T_ c, unsigned long f)
136{
137 return((((c & _CRMASK) ? 0 :
138 _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0);
139}
140
141/* _ANSI_LIBRARY is defined by lib/libc/gen/isctype.c. */
142#if !defined(_ANSI_LIBRARY)
143static __inline _BSD_RUNE_T_
144toupper(_BSD_RUNE_T_ c)
145{
146 return((c & _CRMASK) ?
147 ___toupper(c) : _CurrentRuneLocale->mapupper[c]);
148}
149
150static __inline _BSD_RUNE_T_
151tolower(_BSD_RUNE_T_ c)
152{
153 return((c & _CRMASK) ?
154 ___tolower(c) : _CurrentRuneLocale->maplower[c]);
155}
156#endif /* !_ANSI_LIBRARY */
157
158#else /* !_USE_CTYPE_INLINE_ */
159
160__BEGIN_DECLS
161int __istype __P((_BSD_RUNE_T_, unsigned long));
162int __isctype __P((_BSD_RUNE_T_, unsigned long));
163_BSD_RUNE_T_ toupper __P((_BSD_RUNE_T_));
164_BSD_RUNE_T_ tolower __P((_BSD_RUNE_T_));
165__END_DECLS
166#endif /* _USE_CTYPE_INLINE_ */
167
168#endif /* !_CTYPE_H_ */