xref: /freebsd/include/_ctype.h (revision a316b26e50bbed7cf655fbba726ab87d8ab7599d)
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 #include <runetype.h>
48 
49 #define	_A	0x00000100L		/* Alpha */
50 #define	_C	0x00000200L		/* Control */
51 #define	_D	0x00000400L		/* Digit */
52 #define	_G	0x00000800L		/* Graph */
53 #define	_L	0x00001000L		/* Lower */
54 #define	_P	0x00002000L		/* Punct */
55 #define	_S	0x00004000L		/* Space */
56 #define	_U	0x00008000L		/* Upper */
57 #define	_X	0x00010000L		/* X digit */
58 #define	_B	0x00020000L		/* Blank */
59 #define	_R	0x00040000L		/* Print */
60 #define	_I	0x00080000L		/* Ideogram */
61 #define	_T	0x00100000L		/* Special */
62 #define	_Q	0x00200000L		/* Phonogram */
63 
64 #define isalnum(c)      __istype((c), (_A|_D))
65 #define isalpha(c)      __istype((c),     _A)
66 #define iscntrl(c)      __istype((c),     _C)
67 #define isdigit(c)      __isctype((c),    _D)	/* ANSI -- locale independent */
68 #define isgraph(c)      __istype((c),     _G)
69 #define islower(c)      __istype((c),     _L)
70 #define isprint(c)      __istype((c),     _R)
71 #define ispunct(c)      __istype((c),     _P)
72 #define isspace(c)      __istype((c),     _S)
73 #define isupper(c)      __istype((c),     _U)
74 #define isxdigit(c)     __isctype((c),    _X)	/* ANSI -- locale independent */
75 
76 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
77 #define	isascii(c)	((c & ~0x7F) == 0)
78 #define toascii(c)	((c) & 0x7F)
79 #define	digittoint(c)	__istype((c), 0xFF)
80 #define	isideogram(c)	__istype((c), _I)
81 #define	isphonogram(c)	__istype((c), _T)
82 #define	isspecial(c)	__istype((c), _Q)
83 #define isblank(c)	__istype((c), _B)
84 #define	isrune(c)	__istype((c),  0xFFFFFF00L)
85 #define	isnumber(c)	__istype((c), _D)
86 #define	ishexnumber(c)	__istype((c), _X)
87 #endif
88 
89 /* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
90 __BEGIN_DECLS
91 unsigned long	___runetype __P((_BSD_RUNE_T_));
92 _BSD_RUNE_T_	___tolower __P((_BSD_RUNE_T_));
93 _BSD_RUNE_T_	___toupper __P((_BSD_RUNE_T_));
94 __END_DECLS
95 
96 /*
97  * If your compiler supports prototypes and inline functions,
98  * #define _USE_CTYPE_INLINE_.  Otherwise, use the C library
99  * functions.
100  */
101 #if !defined(_USE_CTYPE_CLIBRARY_) && defined(__GNUC__) || defined(__cplusplus)
102 #define	_USE_CTYPE_INLINE_	1
103 #endif
104 
105 #if defined(_USE_CTYPE_INLINE_)
106 static __inline int
107 __istype(_BSD_RUNE_T_ c, unsigned long f)
108 {
109 	if (c < 0)
110 		c = (unsigned char) c;
111 	return((((c & _CRMASK) ? ___runetype(c) :
112 	    _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0);
113 }
114 
115 static __inline int
116 __isctype(_BSD_RUNE_T_ c, unsigned long f)
117 {
118 	if (c < 0)
119 		c = (unsigned char) c;
120 	return((((c & _CRMASK) ? 0 :
121 	    _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0);
122 }
123 
124 /* _ANSI_LIBRARY is defined by lib/libc/gen/isctype.c. */
125 #if !defined(_ANSI_LIBRARY)
126 static __inline _BSD_RUNE_T_
127 toupper(_BSD_RUNE_T_ c)
128 {
129 	if (c < 0)
130 		c = (unsigned char) c;
131 	return((c & _CRMASK) ?
132 	    ___toupper(c) : _CurrentRuneLocale->mapupper[c]);
133 }
134 
135 static __inline _BSD_RUNE_T_
136 tolower(_BSD_RUNE_T_ c)
137 {
138 	if (c < 0)
139 		c = (unsigned char) c;
140 	return((c & _CRMASK) ?
141 	    ___tolower(c) : _CurrentRuneLocale->maplower[c]);
142 }
143 #endif /* !_ANSI_LIBRARY */
144 
145 #else /* !_USE_CTYPE_INLINE_ */
146 
147 __BEGIN_DECLS
148 int		__istype __P((_BSD_RUNE_T_, unsigned long));
149 int		__isctype __P((_BSD_RUNE_T_, unsigned long));
150 _BSD_RUNE_T_	toupper __P((_BSD_RUNE_T_));
151 _BSD_RUNE_T_	tolower __P((_BSD_RUNE_T_));
152 __END_DECLS
153 #endif /* _USE_CTYPE_INLINE_ */
154 
155 #endif /* !_CTYPE_H_ */
156