]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/ctype.h
Rip out the nastiness I cribbed from the EISA bus code and actually
[FreeBSD/FreeBSD.git] / include / ctype.h
1 /*
2  * Copyright (c) 1989, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * This code is derived from software contributed to Berkeley by
11  * Paul Borman at Krystal Technologies.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  *    must display the following acknowledgement:
23  *      This product includes software developed by the University of
24  *      California, Berkeley and its contributors.
25  * 4. Neither the name of the University nor the names of its contributors
26  *    may be used to endorse or promote products derived from this software
27  *    without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  *
41  *      @(#)ctype.h     8.4 (Berkeley) 1/21/94
42  */
43
44 #ifndef _CTYPE_H_
45 #define _CTYPE_H_
46
47 /*
48  * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
49  * member names).
50  */
51 #include <runetype.h>
52
53 #define _A      0x00000100L             /* Alpha */
54 #define _C      0x00000200L             /* Control */
55 #define _D      0x00000400L             /* Digit */
56 #define _G      0x00000800L             /* Graph */
57 #define _L      0x00001000L             /* Lower */
58 #define _P      0x00002000L             /* Punct */
59 #define _S      0x00004000L             /* Space */
60 #define _U      0x00008000L             /* Upper */
61 #define _X      0x00010000L             /* X digit */
62 #define _B      0x00020000L             /* Blank */
63 #define _R      0x00040000L             /* Print */
64 #define _I      0x00080000L             /* Ideogram */
65 #define _T      0x00100000L             /* Special */
66 #define _Q      0x00200000L             /* Phonogram */
67
68 __BEGIN_DECLS
69 int     isalnum __P((int));
70 int     isalpha __P((int));
71 int     iscntrl __P((int));
72 int     isdigit __P((int));
73 int     isgraph __P((int));
74 int     islower __P((int));
75 int     isprint __P((int));
76 int     ispunct __P((int));
77 int     isspace __P((int));
78 int     isupper __P((int));
79 int     isxdigit __P((int));
80 int     tolower __P((int));
81 int     toupper __P((int));
82
83 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
84 int     isascii __P((int));
85 int     isblank __P((int));
86 int     toascii __P((int));
87 int     digittoint __P((int));
88 #endif
89 __END_DECLS
90
91 #define __istype(c,f)   (!!__maskrune((c),(f)))
92
93 #define isalnum(c)      __istype((c), _A|_D)
94 #define isalpha(c)      __istype((c), _A)
95 #define iscntrl(c)      __istype((c), _C)
96 #define isdigit(c)      __isctype((c), _D) /* ANSI -- locale independent */
97 #define isgraph(c)      __istype((c), _G)
98 #define islower(c)      __istype((c), _L)
99 #define isprint(c)      __istype((c), _R)
100 #define ispunct(c)      __istype((c), _P)
101 #define isspace(c)      __istype((c), _S)
102 #define isupper(c)      __istype((c), _U)
103 #define isxdigit(c)     __isctype((c), _X) /* ANSI -- locale independent */
104 #define tolower(c)      __tolower(c)
105 #define toupper(c)      __toupper(c)
106
107 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
108 #define isascii(c)      (((c) & ~0x7F) == 0)
109 #define isblank(c)      __istype((c), _B)
110 #define toascii(c)      ((c) & 0x7F)
111 #define digittoint(c)   __maskrune((c), 0xFF)
112
113 /* XXX the following macros are not backed up by functions. */
114 #define ishexnumber(c)  __istype((c), _X)
115 #define isideogram(c)   __istype((c), _I)
116 #define isnumber(c)     __istype((c), _D)
117 #define isphonogram(c)  __istype((c), _Q)
118 #define isrune(c)       __istype((c), 0xFFFFFF00L)
119 #define isspecial(c)    __istype((c), _T)
120 #endif
121
122 /* See comments in <machine/ansi.h> about _BSD_CT_RUNE_T_. */
123 __BEGIN_DECLS
124 unsigned long   ___runetype __P((_BSD_CT_RUNE_T_));
125 _BSD_CT_RUNE_T_ ___tolower __P((_BSD_CT_RUNE_T_));
126 _BSD_CT_RUNE_T_ ___toupper __P((_BSD_CT_RUNE_T_));
127 __END_DECLS
128
129 /*
130  * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
131  * to generate code for extern versions of all our inline functions.
132  */
133 #ifdef _EXTERNALIZE_CTYPE_INLINES_
134 #define _USE_CTYPE_INLINE_
135 #define static
136 #define __inline
137 #endif
138
139 /*
140  * Use inline functions if we are allowed to and the compiler supports them.
141  */
142 #if !defined(_DONT_USE_CTYPE_INLINE_) && \
143     (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
144 static __inline int
145 __maskrune(_BSD_CT_RUNE_T_ _c, unsigned long _f)
146 {
147         return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
148                 _CurrentRuneLocale->runetype[_c]) & _f;
149 }
150
151 static __inline int
152 __isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
153 {
154         return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
155                !!(_DefaultRuneLocale.runetype[_c] & _f);
156 }
157
158 static __inline _BSD_CT_RUNE_T_
159 __toupper(_BSD_CT_RUNE_T_ _c)
160 {
161         return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
162                _CurrentRuneLocale->mapupper[_c];
163 }
164
165 static __inline _BSD_CT_RUNE_T_
166 __tolower(_BSD_CT_RUNE_T_ _c)
167 {
168         return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
169                _CurrentRuneLocale->maplower[_c];
170 }
171
172 #else /* not using inlines */
173
174 __BEGIN_DECLS
175 int             __maskrune __P((_BSD_CT_RUNE_T_, unsigned long));
176 int             __isctype __P((_BSD_CT_RUNE_T_, unsigned long));
177 _BSD_CT_RUNE_T_ __toupper __P((_BSD_CT_RUNE_T_));
178 _BSD_CT_RUNE_T_ __tolower __P((_BSD_CT_RUNE_T_));
179 __END_DECLS
180 #endif /* using inlines */
181
182 #endif /* !_CTYPE_H_ */