xref: /dragonfly/include/ctype.h (revision 17b61719)
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  *      $FreeBSD: src/include/ctype.h,v 1.16 2000/02/08 07:43:23 obrien Exp $
43  *      $DragonFly: src/include/ctype.h,v 1.4 2003/11/14 01:01:43 dillon Exp $
44  */
45 
46 #ifndef _CTYPE_H_
47 #define	_CTYPE_H_
48 
49 #ifndef _SYS_STDINT_H_
50 #include <sys/stdint.h>	/* __ct_rune_t and friends */
51 #endif
52 
53 /*
54  * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
55  * member names).
56  */
57 #include <runetype.h>
58 
59 #define	_CTYPE_A	0x00000100L		/* Alpha */
60 #define	_CTYPE_C	0x00000200L		/* Control */
61 #define	_CTYPE_D	0x00000400L		/* Digit */
62 #define	_CTYPE_G	0x00000800L		/* Graph */
63 #define	_CTYPE_L	0x00001000L		/* Lower */
64 #define	_CTYPE_P	0x00002000L		/* Punct */
65 #define	_CTYPE_S	0x00004000L		/* Space */
66 #define	_CTYPE_U	0x00008000L		/* Upper */
67 #define	_CTYPE_X	0x00010000L		/* X digit */
68 #define	_CTYPE_B	0x00020000L		/* Blank */
69 #define	_CTYPE_R	0x00040000L		/* Print */
70 #define	_CTYPE_I	0x00080000L		/* Ideogram */
71 #define	_CTYPE_T	0x00100000L		/* Special */
72 #define	_CTYPE_Q	0x00200000L		/* Phonogram */
73 
74 __BEGIN_DECLS
75 int	isalnum (int);
76 int	isalpha (int);
77 int	iscntrl (int);
78 int	isdigit (int);
79 int	isgraph (int);
80 int	islower (int);
81 int	isprint (int);
82 int	ispunct (int);
83 int	isspace (int);
84 int	isupper (int);
85 int	isxdigit (int);
86 int	tolower (int);
87 int	toupper (int);
88 
89 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
90 int	digittoint (int);
91 int	isascii (int);
92 int	isblank (int);
93 int	ishexnumber (int);
94 int	isideogram (int);
95 int	isnumber (int);
96 int	isphonogram (int);
97 int	isrune (int);
98 int	isspecial (int);
99 int	toascii (int);
100 #endif
101 __END_DECLS
102 
103 #define	__istype(c,f)	(!!__maskrune((c),(f)))
104 
105 #define	isalnum(c)	__istype((c), _CTYPE_A|_CTYPE_D)
106 #define	isalpha(c)	__istype((c), _CTYPE_A)
107 #define	iscntrl(c)	__istype((c), _CTYPE_C)
108 #define	isdigit(c)	__isctype((c), _CTYPE_D) /* ANSI -- locale independent */
109 #define	isgraph(c)	__istype((c), _CTYPE_G)
110 #define	islower(c)	__istype((c), _CTYPE_L)
111 #define	isprint(c)	__istype((c), _CTYPE_R)
112 #define	ispunct(c)	__istype((c), _CTYPE_P)
113 #define	isspace(c)	__istype((c), _CTYPE_S)
114 #define	isupper(c)	__istype((c), _CTYPE_U)
115 #define	isxdigit(c)	__isctype((c), _CTYPE_X) /* ANSI -- locale independent */
116 #define	tolower(c)	__tolower(c)
117 #define	toupper(c)	__toupper(c)
118 
119 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
120 #define	digittoint(c)	__maskrune((c), 0xFF)
121 #define	isascii(c)	(((c) & ~0x7F) == 0)
122 #define	isblank(c)	__istype((c), _CTYPE_B)
123 #define	ishexnumber(c)	__istype((c), _CTYPE_X)
124 #define	isideogram(c)	__istype((c), _CTYPE_I)
125 #define	isnumber(c)	__istype((c), _CTYPE_D)
126 #define	isphonogram(c)	__istype((c), _CTYPE_Q)
127 #define	isrune(c)	__istype((c), 0xFFFFFF00L)
128 #define	isspecial(c)	__istype((c), _CTYPE_T)
129 #define	toascii(c)	((c) & 0x7F)
130 #endif
131 
132 __BEGIN_DECLS
133 unsigned long	___runetype (__ct_rune_t);
134 __ct_rune_t	___tolower (__ct_rune_t);
135 __ct_rune_t	___toupper (__ct_rune_t);
136 __END_DECLS
137 
138 /*
139  * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
140  * to generate code for extern versions of all our inline functions.
141  */
142 #ifdef _EXTERNALIZE_CTYPE_INLINES_
143 #define	_USE_CTYPE_INLINE_
144 #define	static
145 #define	__inline
146 #endif
147 
148 /*
149  * Use inline functions if we are allowed to and the compiler supports them.
150  */
151 #if !defined(_DONT_USE_CTYPE_INLINE_) && \
152     (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
153 static __inline int
154 __maskrune(__ct_rune_t _c, unsigned long _f)
155 {
156 	return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
157 		_CurrentRuneLocale->runetype[_c]) & _f;
158 }
159 
160 static __inline int
161 __isctype(__ct_rune_t _c, unsigned long _f)
162 {
163 	return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
164 	       !!(_DefaultRuneLocale.runetype[_c] & _f);
165 }
166 
167 static __inline __ct_rune_t
168 __toupper(__ct_rune_t _c)
169 {
170 	return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
171 	       _CurrentRuneLocale->mapupper[_c];
172 }
173 
174 static __inline __ct_rune_t
175 __tolower(__ct_rune_t _c)
176 {
177 	return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
178 	       _CurrentRuneLocale->maplower[_c];
179 }
180 
181 #else /* not using inlines */
182 
183 __BEGIN_DECLS
184 int		__maskrune (__ct_rune_t, unsigned long);
185 int		__isctype (__ct_rune_t, unsigned long);
186 __ct_rune_t	__toupper (__ct_rune_t);
187 __ct_rune_t	__tolower (__ct_rune_t);
188 __END_DECLS
189 #endif /* using inlines */
190 
191 #endif /* !_CTYPE_H_ */
192