_ctype.h revision 29843
1248842Ssbruno/*
2248842Ssbruno * Copyright (c) 1989, 1993
3248842Ssbruno *	The Regents of the University of California.  All rights reserved.
4248842Ssbruno * (c) UNIX System Laboratories, Inc.
5248842Ssbruno * All or some portions of this file are derived from material licensed
6248842Ssbruno * to the University of California by American Telephone and Telegraph
7248842Ssbruno * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8248842Ssbruno * the permission of UNIX System Laboratories, Inc.
9248842Ssbruno *
10248842Ssbruno * This code is derived from software contributed to Berkeley by
11248842Ssbruno * Paul Borman at Krystal Technologies.
12248842Ssbruno *
13248842Ssbruno * Redistribution and use in source and binary forms, with or without
14248842Ssbruno * modification, are permitted provided that the following conditions
15248842Ssbruno * are met:
16248842Ssbruno * 1. Redistributions of source code must retain the above copyright
17248842Ssbruno *    notice, this list of conditions and the following disclaimer.
18248842Ssbruno * 2. Redistributions in binary form must reproduce the above copyright
19248842Ssbruno *    notice, this list of conditions and the following disclaimer in the
20248842Ssbruno *    documentation and/or other materials provided with the distribution.
21248842Ssbruno * 3. All advertising materials mentioning features or use of this software
22248842Ssbruno *    must display the following acknowledgement:
23248842Ssbruno *	This product includes software developed by the University of
24248842Ssbruno *	California, Berkeley and its contributors.
25248842Ssbruno * 4. Neither the name of the University nor the names of its contributors
26248842Ssbruno *    may be used to endorse or promote products derived from this software
27248842Ssbruno *    without specific prior written permission.
28248842Ssbruno *
29248842Ssbruno * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30248842Ssbruno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31248842Ssbruno * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32248842Ssbruno * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33248842Ssbruno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34248842Ssbruno * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35248842Ssbruno * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36248842Ssbruno * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37248842Ssbruno * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38248842Ssbruno * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39248842Ssbruno * SUCH DAMAGE.
40248842Ssbruno *
41248842Ssbruno *	@(#)ctype.h	8.4 (Berkeley) 1/21/94
42248842Ssbruno */
43248842Ssbruno
44248842Ssbruno#ifndef _CTYPE_H_
45248842Ssbruno#define	_CTYPE_H_
46248842Ssbruno
47248842Ssbruno/*
48248842Ssbruno * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
49248842Ssbruno * member names).
50248842Ssbruno */
51248842Ssbruno#include <runetype.h>
52248842Ssbruno
53248842Ssbruno#define	_A	0x00000100L		/* Alpha */
54248842Ssbruno#define	_C	0x00000200L		/* Control */
55248842Ssbruno#define	_D	0x00000400L		/* Digit */
56248842Ssbruno#define	_G	0x00000800L		/* Graph */
57248842Ssbruno#define	_L	0x00001000L		/* Lower */
58248842Ssbruno#define	_P	0x00002000L		/* Punct */
59248842Ssbruno#define	_S	0x00004000L		/* Space */
60248842Ssbruno#define	_U	0x00008000L		/* Upper */
61248842Ssbruno#define	_X	0x00010000L		/* X digit */
62248842Ssbruno#define	_B	0x00020000L		/* Blank */
63248842Ssbruno#define	_R	0x00040000L		/* Print */
64248842Ssbruno#define	_I	0x00080000L		/* Ideogram */
65248842Ssbruno#define	_T	0x00100000L		/* Special */
66248842Ssbruno#define	_Q	0x00200000L		/* Phonogram */
67248842Ssbruno
68248842Ssbruno__BEGIN_DECLS
69248842Ssbrunoint	isalnum __P((int));
70248842Ssbrunoint	isalpha __P((int));
71248842Ssbrunoint	iscntrl __P((int));
72248842Ssbrunoint	isdigit __P((int));
73248842Ssbrunoint	isgraph __P((int));
74248842Ssbrunoint	islower __P((int));
75248842Ssbrunoint	isprint __P((int));
76248842Ssbrunoint	ispunct __P((int));
77248842Ssbrunoint	isspace __P((int));
78248842Ssbrunoint	isupper __P((int));
79248842Ssbrunoint	isxdigit __P((int));
80248842Ssbrunoint	tolower __P((int));
81248842Ssbrunoint	toupper __P((int));
82248842Ssbruno
83248842Ssbruno#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
84248842Ssbrunoint	isascii __P((int));
85248842Ssbrunoint	isblank __P((int));
86248842Ssbrunoint	toascii __P((int));
87248842Ssbrunoint	digittoint __P((int));
88248842Ssbruno#endif
89248842Ssbruno__END_DECLS
90248842Ssbruno
91248842Ssbruno#define	isalnum(c)      __istype((c), (_A|_D))
92248842Ssbruno#define	isalpha(c)      __istype((c),     _A)
93248842Ssbruno#define	iscntrl(c)      __istype((c),     _C)
94248842Ssbruno#define	isdigit(c)      __isctype((c),    _D)	/* ANSI -- locale independent */
95248842Ssbruno#define	isgraph(c)      __istype((c),     _G)
96248842Ssbruno#define	islower(c)      __istype((c),     _L)
97248842Ssbruno#define	isprint(c)      __istype((c),     _R)
98248842Ssbruno#define	ispunct(c)      __istype((c),     _P)
99248842Ssbruno#define	isspace(c)      __istype((c),     _S)
100248842Ssbruno#define	isupper(c)      __istype((c),     _U)
101248842Ssbruno#define	isxdigit(c)     __isctype((c),    _X)	/* ANSI -- locale independent */
102248842Ssbruno#define	tolower(c)	__tolower(c)
103248842Ssbruno#define	toupper(c)	__toupper(c)
104248842Ssbruno
105248842Ssbruno#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
106248842Ssbruno#define	isascii(c)	(((c) & ~0x7F) == 0)
107248842Ssbruno#define	isblank(c)	__istype((c), _B)
108248842Ssbruno#define	toascii(c)	((c) & 0x7F)
109248842Ssbruno#define	digittoint(c)	(__maskrune((c), 0xFF))
110248842Ssbruno
111248842Ssbruno/* XXX the following macros are not backed up by functions. */
112248842Ssbruno#define	ishexnumber(c)	__istype((c), _X)
113248842Ssbruno#define	isideogram(c)	__istype((c), _I)
114248842Ssbruno#define	isnumber(c)	__istype((c), _D)
115248842Ssbruno#define isphonogram(c)  __istype((c), _Q)
116248842Ssbruno#define	isrune(c)	__istype((c), 0xFFFFFF00L)
117248842Ssbruno#define isspecial(c)    __istype((c), _T)
118248842Ssbruno#endif
119248842Ssbruno
120248842Ssbruno/* See comments in <machine/ansi.h> about _BSD_CT_RUNE_T_. */
121248842Ssbruno__BEGIN_DECLS
122248842Ssbrunounsigned long	___runetype __P((_BSD_CT_RUNE_T_));
123248842Ssbruno_BSD_CT_RUNE_T_	___tolower __P((_BSD_CT_RUNE_T_));
124248842Ssbruno_BSD_CT_RUNE_T_	___toupper __P((_BSD_CT_RUNE_T_));
125248842Ssbruno__END_DECLS
126248842Ssbruno
127248842Ssbruno/*
128248842Ssbruno * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
129248842Ssbruno * to generate code for extern versions of all our inline functions.
130248842Ssbruno */
131248842Ssbruno#ifdef _EXTERNALIZE_CTYPE_INLINES_
132248842Ssbruno#define	_USE_CTYPE_INLINE_
133248842Ssbruno#define	static
134248842Ssbruno#define	__inline
135248842Ssbruno#endif
136248842Ssbruno
137248842Ssbruno/*
138248842Ssbruno * Use inline functions if we are allowed to and the compiler supports them.
139248842Ssbruno */
140248842Ssbruno#if !defined(_DONT_USE_CTYPE_INLINE_) && \
141248842Ssbruno    (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
142248842Ssbrunostatic __inline int
143248842Ssbruno__istype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
144248842Ssbruno{
145248842Ssbruno	return (_c < 0 || _c >= _CACHED_RUNES) ? !!(___runetype(_c) & _f) :
146248842Ssbruno	       !!(_CurrentRuneLocale->runetype[_c] & _f);
147248842Ssbruno}
148248842Ssbruno
149248842Ssbrunostatic __inline int
150248842Ssbruno__isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
151248842Ssbruno{
152248842Ssbruno	return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
153248842Ssbruno	       !!(_DefaultRuneLocale.runetype[_c] & _f);
154248842Ssbruno}
155248842Ssbruno
156248842Ssbrunostatic __inline _BSD_CT_RUNE_T_
157248842Ssbruno__toupper(_BSD_CT_RUNE_T_ _c)
158248842Ssbruno{
159248842Ssbruno	return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
160248842Ssbruno	       _CurrentRuneLocale->mapupper[_c];
161248842Ssbruno}
162248842Ssbruno
163248842Ssbrunostatic __inline _BSD_CT_RUNE_T_
164248842Ssbruno__tolower(_BSD_CT_RUNE_T_ _c)
165248842Ssbruno{
166248842Ssbruno	return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
167248842Ssbruno	       _CurrentRuneLocale->maplower[_c];
168248842Ssbruno}
169248842Ssbruno
170248842Ssbrunostatic __inline int
171248842Ssbruno__maskrune(_BSD_CT_RUNE_T_ _c, unsigned long f)
172248842Ssbruno{
173248842Ssbruno	return(((_c & _CRMASK)
174248842Ssbruno		? ___runetype(_c) : _CurrentRuneLocale->runetype[_c]) & f);
175248842Ssbruno}
176248842Ssbruno
177248842Ssbruno#else /* not using inlines */
178248842Ssbruno
179248842Ssbruno__BEGIN_DECLS
180248842Ssbrunoint		__istype __P((_BSD_CT_RUNE_T_, unsigned long));
181248842Ssbrunoint		__isctype __P((_BSD_CT_RUNE_T_, unsigned long));
182248842Ssbrunoint		__maskrune __P((_BSD_CT_RUNE_T_, unsigned long));
183248842Ssbruno_BSD_CT_RUNE_T_	__toupper __P((_BSD_CT_RUNE_T_));
184248842Ssbruno_BSD_CT_RUNE_T_	__tolower __P((_BSD_CT_RUNE_T_));
185248842Ssbruno__END_DECLS
186248842Ssbruno#endif /* using inlines */
187248842Ssbruno
188248842Ssbruno#endif /* !_CTYPE_H_ */
189248842Ssbruno