Deleted Added
full compact
_ctype.h (133559) _ctype.h (133564)
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 * From @(#)ctype.h 8.4 (Berkeley) 1/21/94
42 * From FreeBSD: src/include/ctype.h,v 1.27 2004/06/23 07:11:39 tjr Exp
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 * From @(#)ctype.h 8.4 (Berkeley) 1/21/94
42 * From FreeBSD: src/include/ctype.h,v 1.27 2004/06/23 07:11:39 tjr Exp
43 * $FreeBSD: head/include/_ctype.h 133559 2004-08-12 09:33:47Z tjr $
43 * $FreeBSD: head/include/_ctype.h 133564 2004-08-12 12:19:11Z tjr $
44 */
45
46#ifndef __CTYPE_H_
47#define __CTYPE_H_
48
49#include <sys/cdefs.h>
50#include <sys/_types.h>
51
52#define _CTYPE_A 0x00000100L /* Alpha */
53#define _CTYPE_C 0x00000200L /* Control */
54#define _CTYPE_D 0x00000400L /* Digit */
55#define _CTYPE_G 0x00000800L /* Graph */
56#define _CTYPE_L 0x00001000L /* Lower */
57#define _CTYPE_P 0x00002000L /* Punct */
58#define _CTYPE_S 0x00004000L /* Space */
59#define _CTYPE_U 0x00008000L /* Upper */
60#define _CTYPE_X 0x00010000L /* X digit */
61#define _CTYPE_B 0x00020000L /* Blank */
62#define _CTYPE_R 0x00040000L /* Print */
63#define _CTYPE_I 0x00080000L /* Ideogram */
64#define _CTYPE_T 0x00100000L /* Special */
65#define _CTYPE_Q 0x00200000L /* Phonogram */
66#define _CTYPE_SW0 0x20000000L /* 0 width character */
67#define _CTYPE_SW1 0x40000000L /* 1 width character */
68#define _CTYPE_SW2 0x80000000L /* 2 width character */
69#define _CTYPE_SW3 0xc0000000L /* 3 width character */
44 */
45
46#ifndef __CTYPE_H_
47#define __CTYPE_H_
48
49#include <sys/cdefs.h>
50#include <sys/_types.h>
51
52#define _CTYPE_A 0x00000100L /* Alpha */
53#define _CTYPE_C 0x00000200L /* Control */
54#define _CTYPE_D 0x00000400L /* Digit */
55#define _CTYPE_G 0x00000800L /* Graph */
56#define _CTYPE_L 0x00001000L /* Lower */
57#define _CTYPE_P 0x00002000L /* Punct */
58#define _CTYPE_S 0x00004000L /* Space */
59#define _CTYPE_U 0x00008000L /* Upper */
60#define _CTYPE_X 0x00010000L /* X digit */
61#define _CTYPE_B 0x00020000L /* Blank */
62#define _CTYPE_R 0x00040000L /* Print */
63#define _CTYPE_I 0x00080000L /* Ideogram */
64#define _CTYPE_T 0x00100000L /* Special */
65#define _CTYPE_Q 0x00200000L /* Phonogram */
66#define _CTYPE_SW0 0x20000000L /* 0 width character */
67#define _CTYPE_SW1 0x40000000L /* 1 width character */
68#define _CTYPE_SW2 0x80000000L /* 2 width character */
69#define _CTYPE_SW3 0xc0000000L /* 3 width character */
70#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */
71#define _CTYPE_SWS 30 /* Bits to shift to get width */
70
71/* See comments in <sys/_types.h> about __ct_rune_t. */
72__BEGIN_DECLS
73unsigned long ___runetype(__ct_rune_t);
74__ct_rune_t ___tolower(__ct_rune_t);
75__ct_rune_t ___toupper(__ct_rune_t);
76__END_DECLS
77
78/*
79 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
80 * to generate code for extern versions of all our inline functions.
81 */
82#ifdef _EXTERNALIZE_CTYPE_INLINES_
83#define _USE_CTYPE_INLINE_
84#define static
85#define __inline
86#endif
87
88/*
89 * Use inline functions if we are allowed to and the compiler supports them.
90 */
91#if !defined(_DONT_USE_CTYPE_INLINE_) && \
92 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
93
94#include <runetype.h>
95
96static __inline int
97__maskrune(__ct_rune_t _c, unsigned long _f)
98{
99 return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
100 _CurrentRuneLocale->__runetype[_c]) & _f;
101}
102
103static __inline int
104__istype(__ct_rune_t _c, unsigned long _f)
105{
106 return (!!__maskrune(_c, _f));
107}
108
109static __inline int
110__isctype(__ct_rune_t _c, unsigned long _f)
111{
112 return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
113 !!(_DefaultRuneLocale.__runetype[_c] & _f);
114}
115
116static __inline __ct_rune_t
117__toupper(__ct_rune_t _c)
118{
119 return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
120 _CurrentRuneLocale->__mapupper[_c];
121}
122
123static __inline __ct_rune_t
124__tolower(__ct_rune_t _c)
125{
126 return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
127 _CurrentRuneLocale->__maplower[_c];
128}
129
72
73/* See comments in <sys/_types.h> about __ct_rune_t. */
74__BEGIN_DECLS
75unsigned long ___runetype(__ct_rune_t);
76__ct_rune_t ___tolower(__ct_rune_t);
77__ct_rune_t ___toupper(__ct_rune_t);
78__END_DECLS
79
80/*
81 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
82 * to generate code for extern versions of all our inline functions.
83 */
84#ifdef _EXTERNALIZE_CTYPE_INLINES_
85#define _USE_CTYPE_INLINE_
86#define static
87#define __inline
88#endif
89
90/*
91 * Use inline functions if we are allowed to and the compiler supports them.
92 */
93#if !defined(_DONT_USE_CTYPE_INLINE_) && \
94 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
95
96#include <runetype.h>
97
98static __inline int
99__maskrune(__ct_rune_t _c, unsigned long _f)
100{
101 return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
102 _CurrentRuneLocale->__runetype[_c]) & _f;
103}
104
105static __inline int
106__istype(__ct_rune_t _c, unsigned long _f)
107{
108 return (!!__maskrune(_c, _f));
109}
110
111static __inline int
112__isctype(__ct_rune_t _c, unsigned long _f)
113{
114 return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
115 !!(_DefaultRuneLocale.__runetype[_c] & _f);
116}
117
118static __inline __ct_rune_t
119__toupper(__ct_rune_t _c)
120{
121 return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
122 _CurrentRuneLocale->__mapupper[_c];
123}
124
125static __inline __ct_rune_t
126__tolower(__ct_rune_t _c)
127{
128 return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
129 _CurrentRuneLocale->__maplower[_c];
130}
131
132static __inline int
133__wcwidth(__ct_rune_t _c)
134{
135 unsigned int _x;
136
137 if (_c == 0)
138 return (0);
139 _x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R);
140 if ((_x & _CTYPE_SWM) != 0)
141 return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
142 return ((_x & _CTYPE_R) != 0 ? 1 : -1);
143}
144
130#else /* not using inlines */
131
132__BEGIN_DECLS
133int __maskrune(__ct_rune_t, unsigned long);
134int __istype(__ct_rune_t, unsigned long);
135int __isctype(__ct_rune_t, unsigned long);
136__ct_rune_t __toupper(__ct_rune_t);
137__ct_rune_t __tolower(__ct_rune_t);
145#else /* not using inlines */
146
147__BEGIN_DECLS
148int __maskrune(__ct_rune_t, unsigned long);
149int __istype(__ct_rune_t, unsigned long);
150int __isctype(__ct_rune_t, unsigned long);
151__ct_rune_t __toupper(__ct_rune_t);
152__ct_rune_t __tolower(__ct_rune_t);
153int __wcwidth(__ct_rune_t);
138__END_DECLS
139#endif /* using inlines */
140
141#endif /* !__CTYPE_H_ */
154__END_DECLS
155#endif /* using inlines */
156
157#endif /* !__CTYPE_H_ */