xref: /illumos-gate/usr/src/boot/include/_ctype.h (revision 199767f8)
1*199767f8SToomas Soome /*
2*199767f8SToomas Soome  * Copyright (c) 1989, 1993
3*199767f8SToomas Soome  *	The Regents of the University of California.  All rights reserved.
4*199767f8SToomas Soome  * (c) UNIX System Laboratories, Inc.
5*199767f8SToomas Soome  * All or some portions of this file are derived from material licensed
6*199767f8SToomas Soome  * to the University of California by American Telephone and Telegraph
7*199767f8SToomas Soome  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8*199767f8SToomas Soome  * the permission of UNIX System Laboratories, Inc.
9*199767f8SToomas Soome  *
10*199767f8SToomas Soome  * This code is derived from software contributed to Berkeley by
11*199767f8SToomas Soome  * Paul Borman at Krystal Technologies.
12*199767f8SToomas Soome  *
13*199767f8SToomas Soome  * Redistribution and use in source and binary forms, with or without
14*199767f8SToomas Soome  * modification, are permitted provided that the following conditions
15*199767f8SToomas Soome  * are met:
16*199767f8SToomas Soome  * 1. Redistributions of source code must retain the above copyright
17*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer.
18*199767f8SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
19*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
20*199767f8SToomas Soome  *    documentation and/or other materials provided with the distribution.
21*199767f8SToomas Soome  * 3. Neither the name of the University nor the names of its contributors
22*199767f8SToomas Soome  *    may be used to endorse or promote products derived from this software
23*199767f8SToomas Soome  *    without specific prior written permission.
24*199767f8SToomas Soome  *
25*199767f8SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26*199767f8SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27*199767f8SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28*199767f8SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29*199767f8SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30*199767f8SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31*199767f8SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32*199767f8SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33*199767f8SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34*199767f8SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35*199767f8SToomas Soome  * SUCH DAMAGE.
36*199767f8SToomas Soome  *
37*199767f8SToomas Soome  * From @(#)ctype.h	8.4 (Berkeley) 1/21/94
38*199767f8SToomas Soome  * From FreeBSD: src/include/ctype.h,v 1.27 2004/06/23 07:11:39 tjr Exp
39*199767f8SToomas Soome  * $FreeBSD$
40*199767f8SToomas Soome  */
41*199767f8SToomas Soome 
42*199767f8SToomas Soome #ifndef __CTYPE_H_
43*199767f8SToomas Soome #define	__CTYPE_H_
44*199767f8SToomas Soome 
45*199767f8SToomas Soome #include <sys/cdefs.h>
46*199767f8SToomas Soome #include <sys/_types.h>
47*199767f8SToomas Soome 
48*199767f8SToomas Soome #define	_CTYPE_A	0x00000100L		/* Alpha */
49*199767f8SToomas Soome #define	_CTYPE_C	0x00000200L		/* Control */
50*199767f8SToomas Soome #define	_CTYPE_D	0x00000400L		/* Digit */
51*199767f8SToomas Soome #define	_CTYPE_G	0x00000800L		/* Graph */
52*199767f8SToomas Soome #define	_CTYPE_L	0x00001000L		/* Lower */
53*199767f8SToomas Soome #define	_CTYPE_P	0x00002000L		/* Punct */
54*199767f8SToomas Soome #define	_CTYPE_S	0x00004000L		/* Space */
55*199767f8SToomas Soome #define	_CTYPE_U	0x00008000L		/* Upper */
56*199767f8SToomas Soome #define	_CTYPE_X	0x00010000L		/* X digit */
57*199767f8SToomas Soome #define	_CTYPE_B	0x00020000L		/* Blank */
58*199767f8SToomas Soome #define	_CTYPE_R	0x00040000L		/* Print */
59*199767f8SToomas Soome #define	_CTYPE_I	0x00080000L		/* Ideogram */
60*199767f8SToomas Soome #define	_CTYPE_T	0x00100000L		/* Special */
61*199767f8SToomas Soome #define	_CTYPE_Q	0x00200000L		/* Phonogram */
62*199767f8SToomas Soome #define	_CTYPE_N 	0x00400000L		/* Number (superset of digit) */
63*199767f8SToomas Soome #define	_CTYPE_SW0	0x20000000L		/* 0 width character */
64*199767f8SToomas Soome #define	_CTYPE_SW1	0x40000000L		/* 1 width character */
65*199767f8SToomas Soome #define	_CTYPE_SW2	0x80000000L		/* 2 width character */
66*199767f8SToomas Soome #define	_CTYPE_SW3	0xc0000000L		/* 3 width character */
67*199767f8SToomas Soome #define	_CTYPE_SWM	0xe0000000L		/* Mask for screen width data */
68*199767f8SToomas Soome #define	_CTYPE_SWS	30			/* Bits to shift to get width */
69*199767f8SToomas Soome 
70*199767f8SToomas Soome /* See comments in <sys/_types.h> about __ct_rune_t. */
71*199767f8SToomas Soome __BEGIN_DECLS
72*199767f8SToomas Soome unsigned long	___runetype(__ct_rune_t) __pure;
73*199767f8SToomas Soome __ct_rune_t	___tolower(__ct_rune_t) __pure;
74*199767f8SToomas Soome __ct_rune_t	___toupper(__ct_rune_t) __pure;
75*199767f8SToomas Soome __END_DECLS
76*199767f8SToomas Soome 
77*199767f8SToomas Soome /*
78*199767f8SToomas Soome  * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
79*199767f8SToomas Soome  * to generate code for extern versions of all our inline functions.
80*199767f8SToomas Soome  */
81*199767f8SToomas Soome #ifdef _EXTERNALIZE_CTYPE_INLINES_
82*199767f8SToomas Soome #define	_USE_CTYPE_INLINE_
83*199767f8SToomas Soome #define	static
84*199767f8SToomas Soome #define	__inline
85*199767f8SToomas Soome #endif
86*199767f8SToomas Soome 
87*199767f8SToomas Soome extern int __mb_sb_limit;
88*199767f8SToomas Soome 
89*199767f8SToomas Soome /*
90*199767f8SToomas Soome  * Use inline functions if we are allowed to and the compiler supports them.
91*199767f8SToomas Soome  */
92*199767f8SToomas Soome #if !defined(_DONT_USE_CTYPE_INLINE_) && \
93*199767f8SToomas Soome     (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
94*199767f8SToomas Soome 
95*199767f8SToomas Soome #include <runetype.h>
96*199767f8SToomas Soome 
97*199767f8SToomas Soome static __inline int
__maskrune(__ct_rune_t _c,unsigned long _f)98*199767f8SToomas Soome __maskrune(__ct_rune_t _c, unsigned long _f)
99*199767f8SToomas Soome {
100*199767f8SToomas Soome 	return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
101*199767f8SToomas Soome 		_CurrentRuneLocale->__runetype[_c]) & _f;
102*199767f8SToomas Soome }
103*199767f8SToomas Soome 
104*199767f8SToomas Soome static __inline int
__sbmaskrune(__ct_rune_t _c,unsigned long _f)105*199767f8SToomas Soome __sbmaskrune(__ct_rune_t _c, unsigned long _f)
106*199767f8SToomas Soome {
107*199767f8SToomas Soome 	return (_c < 0 || _c >= __mb_sb_limit) ? 0 :
108*199767f8SToomas Soome 	       _CurrentRuneLocale->__runetype[_c] & _f;
109*199767f8SToomas Soome }
110*199767f8SToomas Soome 
111*199767f8SToomas Soome static __inline int
__istype(__ct_rune_t _c,unsigned long _f)112*199767f8SToomas Soome __istype(__ct_rune_t _c, unsigned long _f)
113*199767f8SToomas Soome {
114*199767f8SToomas Soome 	return (!!__maskrune(_c, _f));
115*199767f8SToomas Soome }
116*199767f8SToomas Soome 
117*199767f8SToomas Soome static __inline int
__sbistype(__ct_rune_t _c,unsigned long _f)118*199767f8SToomas Soome __sbistype(__ct_rune_t _c, unsigned long _f)
119*199767f8SToomas Soome {
120*199767f8SToomas Soome 	return (!!__sbmaskrune(_c, _f));
121*199767f8SToomas Soome }
122*199767f8SToomas Soome 
123*199767f8SToomas Soome static __inline int
__isctype(__ct_rune_t _c,unsigned long _f)124*199767f8SToomas Soome __isctype(__ct_rune_t _c, unsigned long _f)
125*199767f8SToomas Soome {
126*199767f8SToomas Soome 	return (_c < 0 || _c >= 128) ? 0 :
127*199767f8SToomas Soome 	       !!(_DefaultRuneLocale.__runetype[_c] & _f);
128*199767f8SToomas Soome }
129*199767f8SToomas Soome 
130*199767f8SToomas Soome static __inline __ct_rune_t
__toupper(__ct_rune_t _c)131*199767f8SToomas Soome __toupper(__ct_rune_t _c)
132*199767f8SToomas Soome {
133*199767f8SToomas Soome 	return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
134*199767f8SToomas Soome 	       _CurrentRuneLocale->__mapupper[_c];
135*199767f8SToomas Soome }
136*199767f8SToomas Soome 
137*199767f8SToomas Soome static __inline __ct_rune_t
__sbtoupper(__ct_rune_t _c)138*199767f8SToomas Soome __sbtoupper(__ct_rune_t _c)
139*199767f8SToomas Soome {
140*199767f8SToomas Soome 	return (_c < 0 || _c >= __mb_sb_limit) ? _c :
141*199767f8SToomas Soome 	       _CurrentRuneLocale->__mapupper[_c];
142*199767f8SToomas Soome }
143*199767f8SToomas Soome 
144*199767f8SToomas Soome static __inline __ct_rune_t
__tolower(__ct_rune_t _c)145*199767f8SToomas Soome __tolower(__ct_rune_t _c)
146*199767f8SToomas Soome {
147*199767f8SToomas Soome 	return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
148*199767f8SToomas Soome 	       _CurrentRuneLocale->__maplower[_c];
149*199767f8SToomas Soome }
150*199767f8SToomas Soome 
151*199767f8SToomas Soome static __inline __ct_rune_t
__sbtolower(__ct_rune_t _c)152*199767f8SToomas Soome __sbtolower(__ct_rune_t _c)
153*199767f8SToomas Soome {
154*199767f8SToomas Soome 	return (_c < 0 || _c >= __mb_sb_limit) ? _c :
155*199767f8SToomas Soome 	       _CurrentRuneLocale->__maplower[_c];
156*199767f8SToomas Soome }
157*199767f8SToomas Soome 
158*199767f8SToomas Soome static __inline int
__wcwidth(__ct_rune_t _c)159*199767f8SToomas Soome __wcwidth(__ct_rune_t _c)
160*199767f8SToomas Soome {
161*199767f8SToomas Soome 	unsigned int _x;
162*199767f8SToomas Soome 
163*199767f8SToomas Soome 	if (_c == 0)
164*199767f8SToomas Soome 		return (0);
165*199767f8SToomas Soome 	_x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R);
166*199767f8SToomas Soome 	if ((_x & _CTYPE_SWM) != 0)
167*199767f8SToomas Soome 		return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
168*199767f8SToomas Soome 	return ((_x & _CTYPE_R) != 0 ? 1 : -1);
169*199767f8SToomas Soome }
170*199767f8SToomas Soome 
171*199767f8SToomas Soome #else /* not using inlines */
172*199767f8SToomas Soome 
173*199767f8SToomas Soome __BEGIN_DECLS
174*199767f8SToomas Soome int		__maskrune(__ct_rune_t, unsigned long);
175*199767f8SToomas Soome int		__sbmaskrune(__ct_rune_t, unsigned long);
176*199767f8SToomas Soome int		__istype(__ct_rune_t, unsigned long);
177*199767f8SToomas Soome int		__sbistype(__ct_rune_t, unsigned long);
178*199767f8SToomas Soome int		__isctype(__ct_rune_t, unsigned long);
179*199767f8SToomas Soome __ct_rune_t	__toupper(__ct_rune_t);
180*199767f8SToomas Soome __ct_rune_t	__sbtoupper(__ct_rune_t);
181*199767f8SToomas Soome __ct_rune_t	__tolower(__ct_rune_t);
182*199767f8SToomas Soome __ct_rune_t	__sbtolower(__ct_rune_t);
183*199767f8SToomas Soome int		__wcwidth(__ct_rune_t);
184*199767f8SToomas Soome __END_DECLS
185*199767f8SToomas Soome #endif /* using inlines */
186*199767f8SToomas Soome 
187*199767f8SToomas Soome #endif /* !__CTYPE_H_ */
188