_ctype.h revision 102227
111394Sswallace/*
2139799Simp * Copyright (c) 1989, 1993
311394Sswallace *	The Regents of the University of California.  All rights reserved.
4139799Simp * (c) UNIX System Laboratories, Inc.
511394Sswallace * All or some portions of this file are derived from material licensed
611394Sswallace * to the University of California by American Telephone and Telegraph
711394Sswallace * Co. or Unix System Laboratories, Inc. and are reproduced herein with
811394Sswallace * the permission of UNIX System Laboratories, Inc.
911394Sswallace *
1011394Sswallace * This code is derived from software contributed to Berkeley by
1111394Sswallace * Paul Borman at Krystal Technologies.
1211394Sswallace *
1311394Sswallace * Redistribution and use in source and binary forms, with or without
1411394Sswallace * modification, are permitted provided that the following conditions
1511394Sswallace * are met:
1611394Sswallace * 1. Redistributions of source code must retain the above copyright
1711394Sswallace *    notice, this list of conditions and the following disclaimer.
1811394Sswallace * 2. Redistributions in binary form must reproduce the above copyright
1911394Sswallace *    notice, this list of conditions and the following disclaimer in the
2011394Sswallace *    documentation and/or other materials provided with the distribution.
2111394Sswallace * 3. All advertising materials mentioning features or use of this software
2211394Sswallace *    must display the following acknowledgement:
2311394Sswallace *	This product includes software developed by the University of
2411394Sswallace *	California, Berkeley and its contributors.
2511394Sswallace * 4. Neither the name of the University nor the names of its contributors
2611394Sswallace *    may be used to endorse or promote products derived from this software
2711394Sswallace *    without specific prior written permission.
2811394Sswallace *
2911394Sswallace * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3011394Sswallace * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3111394Sswallace * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3211394Sswallace * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3311394Sswallace * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3411394Sswallace * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3511394Sswallace * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3611394Sswallace * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3711394Sswallace * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3811394Sswallace * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3911394Sswallace * SUCH DAMAGE.
4011394Sswallace *
4111394Sswallace *	@(#)ctype.h	8.4 (Berkeley) 1/21/94
4211394Sswallace *      $FreeBSD: head/include/_ctype.h 102227 2002-08-21 16:20:02Z mike $
43 */
44
45#ifndef _CTYPE_H_
46#define	_CTYPE_H_
47
48/*
49 * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
50 * member names).
51 */
52#include <runetype.h>
53
54#define	_CTYPE_A	0x00000100L		/* Alpha */
55#define	_CTYPE_C	0x00000200L		/* Control */
56#define	_CTYPE_D	0x00000400L		/* Digit */
57#define	_CTYPE_G	0x00000800L		/* Graph */
58#define	_CTYPE_L	0x00001000L		/* Lower */
59#define	_CTYPE_P	0x00002000L		/* Punct */
60#define	_CTYPE_S	0x00004000L		/* Space */
61#define	_CTYPE_U	0x00008000L		/* Upper */
62#define	_CTYPE_X	0x00010000L		/* X digit */
63#define	_CTYPE_B	0x00020000L		/* Blank */
64#define	_CTYPE_R	0x00040000L		/* Print */
65#define	_CTYPE_I	0x00080000L		/* Ideogram */
66#define	_CTYPE_T	0x00100000L		/* Special */
67#define	_CTYPE_Q	0x00200000L		/* Phonogram */
68#define	_CTYPE_SW0	0x20000000L		/* 0 width character */
69#define	_CTYPE_SW1	0x40000000L		/* 1 width character */
70#define	_CTYPE_SW2	0x80000000L		/* 2 width character */
71#define	_CTYPE_SW3	0xc0000000L		/* 3 width character */
72
73__BEGIN_DECLS
74int	isalnum(int);
75int	isalpha(int);
76int	iscntrl(int);
77int	isdigit(int);
78int	isgraph(int);
79int	islower(int);
80int	isprint(int);
81int	ispunct(int);
82int	isspace(int);
83int	isupper(int);
84int	isxdigit(int);
85int	tolower(int);
86int	toupper(int);
87
88#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
89int	digittoint(int);
90int	isascii(int);
91int	isblank(int);
92int	ishexnumber(int);
93int	isideogram(int);
94int	isnumber(int);
95int	isphonogram(int);
96int	isrune(int);
97int	isspecial(int);
98int	toascii(int);
99#endif
100__END_DECLS
101
102#define	isalnum(c)	__istype((c), _CTYPE_A|_CTYPE_D)
103#define	isalpha(c)	__istype((c), _CTYPE_A)
104#define	iscntrl(c)	__istype((c), _CTYPE_C)
105#define	isdigit(c)	__isctype((c), _CTYPE_D) /* ANSI -- locale independent */
106#define	isgraph(c)	__istype((c), _CTYPE_G)
107#define	islower(c)	__istype((c), _CTYPE_L)
108#define	isprint(c)	__istype((c), _CTYPE_R)
109#define	ispunct(c)	__istype((c), _CTYPE_P)
110#define	isspace(c)	__istype((c), _CTYPE_S)
111#define	isupper(c)	__istype((c), _CTYPE_U)
112#define	isxdigit(c)	__isctype((c), _CTYPE_X) /* ANSI -- locale independent */
113#define	tolower(c)	__tolower(c)
114#define	toupper(c)	__toupper(c)
115
116#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
117#define	digittoint(c)	__maskrune((c), 0xFF)
118#define	isascii(c)	(((c) & ~0x7F) == 0)
119#define	isblank(c)	__istype((c), _CTYPE_B)
120#define	ishexnumber(c)	__istype((c), _CTYPE_X)
121#define	isideogram(c)	__istype((c), _CTYPE_I)
122#define	isnumber(c)	__istype((c), _CTYPE_D)
123#define	isphonogram(c)	__istype((c), _CTYPE_Q)
124#define	isrune(c)	__istype((c), 0xFFFFFF00L)
125#define	isspecial(c)	__istype((c), _CTYPE_T)
126#define	toascii(c)	((c) & 0x7F)
127#endif
128
129/* See comments in <machine/_types.h> about __ct_rune_t. */
130__BEGIN_DECLS
131unsigned long	___runetype(__ct_rune_t);
132__ct_rune_t	___tolower(__ct_rune_t);
133__ct_rune_t	___toupper(__ct_rune_t);
134__END_DECLS
135
136/*
137 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
138 * to generate code for extern versions of all our inline functions.
139 */
140#ifdef _EXTERNALIZE_CTYPE_INLINES_
141#define	_USE_CTYPE_INLINE_
142#define	static
143#define	__inline
144#endif
145
146/*
147 * Use inline functions if we are allowed to and the compiler supports them.
148 */
149#if !defined(_DONT_USE_CTYPE_INLINE_) && \
150    (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
151static __inline int
152__maskrune(__ct_rune_t _c, unsigned long _f)
153{
154	return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
155		_CurrentRuneLocale->runetype[_c]) & _f;
156}
157
158static __inline int
159__istype(__ct_rune_t _c, unsigned long _f)
160{
161	return (!!__maskrune(_c, _f));
162}
163
164static __inline int
165__isctype(__ct_rune_t _c, unsigned long _f)
166{
167	return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
168	       !!(_DefaultRuneLocale.runetype[_c] & _f);
169}
170
171static __inline __ct_rune_t
172__toupper(__ct_rune_t _c)
173{
174	return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
175	       _CurrentRuneLocale->mapupper[_c];
176}
177
178static __inline __ct_rune_t
179__tolower(__ct_rune_t _c)
180{
181	return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
182	       _CurrentRuneLocale->maplower[_c];
183}
184
185#else /* not using inlines */
186
187__BEGIN_DECLS
188int		__maskrune(__ct_rune_t, unsigned long);
189int		__istype(__ct_rune_t, unsigned long);
190int		__isctype(__ct_rune_t, unsigned long);
191__ct_rune_t	__toupper(__ct_rune_t);
192__ct_rune_t	__tolower(__ct_rune_t);
193__END_DECLS
194#endif /* using inlines */
195
196#endif /* !_CTYPE_H_ */
197