netinet{,6}: Assert in{,6}_inithead() are only used for system routing tables.
[dragonfly.git] / include / ctype.h
CommitLineData
984263bc 1/*
0d5acd74
JM
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
984263bc
MD
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 *
0d5acd74
JM
10 * This code is derived from software contributed to Berkeley by
11 * Paul Borman at Krystal Technologies.
12 *
984263bc
MD
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.
32a7b49a 21 * 3. Neither the name of the University nor the names of its contributors
984263bc
MD
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
0d5acd74
JM
37 * @(#)ctype.h 8.4 (Berkeley) 1/21/94
38 * $FreeBSD: head/include/ctype.h 233600 2012-03-28 12:11:54Z theraven $
984263bc
MD
39 */
40
41#ifndef _CTYPE_H_
32a7b49a 42#define _CTYPE_H_
984263bc 43
32a7b49a 44#include <sys/cdefs.h>
0d5acd74
JM
45#include <sys/types.h>
46
47#define _CTYPE_A 0x00000100L /* Alpha */
48#define _CTYPE_C 0x00000200L /* Control */
49#define _CTYPE_D 0x00000400L /* Digit */
50#define _CTYPE_G 0x00000800L /* Graph */
51#define _CTYPE_L 0x00001000L /* Lower */
52#define _CTYPE_P 0x00002000L /* Punct */
53#define _CTYPE_S 0x00004000L /* Space */
54#define _CTYPE_U 0x00008000L /* Upper */
55#define _CTYPE_X 0x00010000L /* X digit */
56#define _CTYPE_B 0x00020000L /* Blank */
57#define _CTYPE_R 0x00040000L /* Print */
58#define _CTYPE_I 0x00080000L /* Ideogram */
59#define _CTYPE_T 0x00100000L /* Special */
60#define _CTYPE_Q 0x00200000L /* Phonogram */
61#define _CTYPE_SW0 0x20000000L /* 0 width character */
62#define _CTYPE_SW1 0x40000000L /* 1 width character */
63#define _CTYPE_SW2 0x80000000L /* 2 width character */
64#define _CTYPE_SW3 0xc0000000L /* 3 width character */
65#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */
66#define _CTYPE_SWS 30 /* Bits to shift to get width */
67
68/* See comments in <sys/_types.h> about __ct_rune_t. */
69__BEGIN_DECLS
70unsigned long ___runetype(__ct_rune_t) __pure;
71__ct_rune_t ___tolower(__ct_rune_t) __pure;
72__ct_rune_t ___toupper(__ct_rune_t) __pure;
73__END_DECLS
74
75/*
76 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
77 * to generate code for extern versions of all our inline functions.
78 */
79#ifdef _EXTERNALIZE_CTYPE_INLINES_
80#define _USE_CTYPE_INLINE_
81#define static
82#define __inline
83#endif
84
85extern int __mb_sb_limit;
86
87/*
88 * Use inline functions if we are allowed to and the compiler supports them.
89 */
90#if !defined(_DONT_USE_CTYPE_INLINE_) && \
91 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
92
93#include <runetype.h>
94
95static __inline int
96__maskrune(__ct_rune_t _c, unsigned long _f)
97{
98 return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
99 _CurrentRuneLocale->__runetype[_c]) & _f;
100}
101
102static __inline int
103__sbmaskrune(__ct_rune_t _c, unsigned long _f)
104{
105 return (_c < 0 || _c >= __mb_sb_limit) ? 0 :
106 _CurrentRuneLocale->__runetype[_c] & _f;
107}
108
109static __inline int
110__istype(__ct_rune_t _c, unsigned long _f)
111{
112 return (!!__maskrune(_c, _f));
113}
114
115static __inline int
116__sbistype(__ct_rune_t _c, unsigned long _f)
117{
118 return (!!__sbmaskrune(_c, _f));
119}
120
121static __inline int
122__isctype(__ct_rune_t _c, unsigned long _f)
123{
124 return (_c < 0 || _c >= 128) ? 0 :
125 !!(_DefaultRuneLocale.__runetype[_c] & _f);
126}
127
128static __inline __ct_rune_t
129__toupper(__ct_rune_t _c)
130{
131 return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
132 _CurrentRuneLocale->__mapupper[_c];
133}
134
135static __inline __ct_rune_t
136__sbtoupper(__ct_rune_t _c)
137{
138 return (_c < 0 || _c >= __mb_sb_limit) ? _c :
139 _CurrentRuneLocale->__mapupper[_c];
140}
141
142static __inline __ct_rune_t
143__tolower(__ct_rune_t _c)
144{
145 return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
146 _CurrentRuneLocale->__maplower[_c];
147}
148
149static __inline __ct_rune_t
150__sbtolower(__ct_rune_t _c)
151{
152 return (_c < 0 || _c >= __mb_sb_limit) ? _c :
153 _CurrentRuneLocale->__maplower[_c];
154}
155
156static __inline int
157__wcwidth(__ct_rune_t _c)
158{
159 unsigned int _x;
160
161 if (_c == 0)
162 return (0);
163 _x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R);
164 if ((_x & _CTYPE_SWM) != 0)
165 return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
166 return ((_x & _CTYPE_R) != 0 ? 1 : -1);
167}
168
169#else /* not using inlines */
170
171__BEGIN_DECLS
172int __maskrune(__ct_rune_t, unsigned long);
173int __sbmaskrune(__ct_rune_t, unsigned long);
174int __istype(__ct_rune_t, unsigned long);
175int __sbistype(__ct_rune_t, unsigned long);
176int __isctype(__ct_rune_t, unsigned long);
177__ct_rune_t __toupper(__ct_rune_t);
178__ct_rune_t __sbtoupper(__ct_rune_t);
179__ct_rune_t __tolower(__ct_rune_t);
180__ct_rune_t __sbtolower(__ct_rune_t);
181int __wcwidth(__ct_rune_t);
182__END_DECLS
183#endif /* using inlines */
184
984263bc
MD
185
186__BEGIN_DECLS
32a7b49a
JS
187int isalnum(int);
188int isalpha(int);
189int iscntrl(int);
190int isdigit(int);
191int isgraph(int);
192int islower(int);
193int isprint(int);
194int ispunct(int);
195int isspace(int);
196int isupper(int);
197int isxdigit(int);
198int tolower(int);
199int toupper(int);
200
0d5acd74 201#if __XSI_VISIBLE
32a7b49a
JS
202int isascii(int);
203int toascii(int);
984263bc 204#endif
984263bc 205
0d5acd74 206#if __ISO_C_VISIBLE >= 1999
32a7b49a 207int isblank(int);
984263bc 208#endif
984263bc 209
0d5acd74
JM
210#if __BSD_VISIBLE
211int digittoint(int);
212int ishexnumber(int);
213int isideogram(int);
214int isnumber(int);
215int isphonogram(int);
216int isrune(int);
217int isspecial(int);
b30a327b
MD
218#endif
219
0d5acd74
JM
220#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
221#include <xlocale/_ctype.h>
222#endif
223__END_DECLS
b30a327b 224
0d5acd74
JM
225#ifndef __cplusplus
226#define isalnum(c) __sbistype((c), _CTYPE_A|_CTYPE_D)
227#define isalpha(c) __sbistype((c), _CTYPE_A)
228#define iscntrl(c) __sbistype((c), _CTYPE_C)
229#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */
230#define isgraph(c) __sbistype((c), _CTYPE_G)
231#define islower(c) __sbistype((c), _CTYPE_L)
232#define isprint(c) __sbistype((c), _CTYPE_R)
233#define ispunct(c) __sbistype((c), _CTYPE_P)
234#define isspace(c) __sbistype((c), _CTYPE_S)
235#define isupper(c) __sbistype((c), _CTYPE_U)
236#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */
237#define tolower(c) __sbtolower(c)
238#define toupper(c) __sbtoupper(c)
239#endif /* !__cplusplus */
b30a327b 240
0d5acd74
JM
241#if __XSI_VISIBLE
242/*
243 * POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to
244 * tolower() and toupper() respectively, minus extra checking to ensure that
245 * the argument is a lower or uppercase letter respectively. We've chosen to
246 * implement these macros with the same error checking as tolower() and
247 * toupper() since this doesn't violate the specification itself, only its
248 * intent. We purposely leave _tolower() and _toupper() undocumented to
249 * discourage their use.
250 *
251 * XXX isascii() and toascii() should similarly be undocumented.
252 */
253#define _tolower(c) __sbtolower(c)
254#define _toupper(c) __sbtoupper(c)
255#define isascii(c) (((c) & ~0x7F) == 0)
256#define toascii(c) ((c) & 0x7F)
b30a327b
MD
257#endif
258
0d5acd74
JM
259#if __ISO_C_VISIBLE >= 1999 && !defined(__cplusplus)
260#define isblank(c) __sbistype((c), _CTYPE_B)
984263bc
MD
261#endif
262
0d5acd74
JM
263#if __BSD_VISIBLE
264#define digittoint(c) __sbmaskrune((c), 0xFF)
265#define ishexnumber(c) __sbistype((c), _CTYPE_X)
266#define isideogram(c) __sbistype((c), _CTYPE_I)
267#define isnumber(c) __sbistype((c), _CTYPE_D)
268#define isphonogram(c) __sbistype((c), _CTYPE_Q)
269#define isrune(c) __sbistype((c), 0xFFFFFF00L)
270#define isspecial(c) __sbistype((c), _CTYPE_T)
32a7b49a 271#endif
984263bc
MD
272
273#endif /* !_CTYPE_H_ */