ctype.h revision 14813
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 *	@(#)ctype.h	8.4 (Berkeley) 1/21/94
42 */
43
44#ifndef _CTYPE_H_
45#define	_CTYPE_H_
46
47/*
48 * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
49 * member names).
50 */
51#include <runetype.h>
52
53#define	_A	0x00000100L		/* Alpha */
54#define	_C	0x00000200L		/* Control */
55#define	_D	0x00000400L		/* Digit */
56#define	_G	0x00000800L		/* Graph */
57#define	_L	0x00001000L		/* Lower */
58#define	_P	0x00002000L		/* Punct */
59#define	_S	0x00004000L		/* Space */
60#define	_U	0x00008000L		/* Upper */
61#define	_X	0x00010000L		/* X digit */
62#define	_B	0x00020000L		/* Blank */
63#define	_R	0x00040000L		/* Print */
64#define	_I	0x00080000L		/* Ideogram */
65#define	_T	0x00100000L		/* Special */
66#define	_Q	0x00200000L		/* Phonogram */
67
68__BEGIN_DECLS
69int	isalnum __P((int));
70int	isalpha __P((int));
71int	iscntrl __P((int));
72int	isdigit __P((int));
73int	isgraph __P((int));
74int	islower __P((int));
75int	isprint __P((int));
76int	ispunct __P((int));
77int	isspace __P((int));
78int	isupper __P((int));
79int	isxdigit __P((int));
80int	tolower __P((int));
81int	toupper __P((int));
82
83#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
84int	isascii __P((int));
85int	isblank __P((int));
86int	toascii __P((int));
87#endif
88__END_DECLS
89
90#define	isalnum(c)      __istype((c), (_A|_D))
91#define	isalpha(c)      __istype((c),     _A)
92#define	iscntrl(c)      __istype((c),     _C)
93#define	isdigit(c)      __isctype((c),    _D)	/* ANSI -- locale independent */
94#define	isgraph(c)      __istype((c),     _G)
95#define	islower(c)      __istype((c),     _L)
96#define	isprint(c)      __istype((c),     _R)
97#define	ispunct(c)      __istype((c),     _P)
98#define	isspace(c)      __istype((c),     _S)
99#define	isupper(c)      __istype((c),     _U)
100#define	isxdigit(c)     __isctype((c),    _X)	/* ANSI -- locale independent */
101#define	tolower(c)	__tolower(c)
102#define	toupper(c)	__toupper(c)
103
104#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
105#define	isascii(c)	(((c) & ~0x7F) == 0)
106#define	isblank(c)	__istype((c), _B)
107#define	toascii(c)	((c) & 0x7F)
108
109/* XXX the following macros are not backed up by functions. */
110#define	digittoint(c)	__istype((c), 0xFF)
111#define	ishexnumber(c)	__istype((c), _X)
112#define	isideogram(c)	__istype((c), _I)
113#define	isnumber(c)	__istype((c), _D)
114#define isphonogram(c)  __istype((c), _Q)
115#define	isrune(c)	__istype((c), 0xFFFFFF00L)
116#define isspecial(c)    __istype((c), _T)
117#endif
118
119/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
120__BEGIN_DECLS
121unsigned long	___runetype __P((_BSD_RUNE_T_));
122_BSD_RUNE_T_	___tolower __P((_BSD_RUNE_T_));
123_BSD_RUNE_T_	___toupper __P((_BSD_RUNE_T_));
124__END_DECLS
125
126/*
127 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
128 * to generate code for extern versions of all our inline functions.
129 */
130#ifdef _EXTERNALIZE_CTYPE_INLINES_
131#define	_USE_CTYPE_INLINE_
132#define	static
133#define	__inline
134#endif
135
136/*
137 * Use inline functions if we are allowed to and the compiler supports them.
138 */
139#if !defined(_DONT_USE_CTYPE_INLINE_) && \
140    (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
141static __inline int
142__istype(_BSD_RUNE_T_ _c, unsigned long _f)
143{
144	return (_c < 0 || _c >= _CACHED_RUNES) ? !!(___runetype(_c) & _f) :
145	       !!(_CurrentRuneLocale->runetype[_c] & _f);
146}
147
148static __inline int
149__isctype(_BSD_RUNE_T_ _c, unsigned long _f)
150{
151	return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
152	       !!(_DefaultRuneLocale.runetype[_c] & _f);
153}
154
155static __inline _BSD_RUNE_T_
156__toupper(_BSD_RUNE_T_ _c)
157{
158	return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
159	       _CurrentRuneLocale->mapupper[_c];
160}
161
162static __inline _BSD_RUNE_T_
163__tolower(_BSD_RUNE_T_ _c)
164{
165	return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
166	       _CurrentRuneLocale->maplower[_c];
167}
168
169#else /* not using inlines */
170
171__BEGIN_DECLS
172int		__istype __P((_BSD_RUNE_T_, unsigned long));
173int		__isctype __P((_BSD_RUNE_T_, unsigned long));
174_BSD_RUNE_T_	__toupper __P((_BSD_RUNE_T_));
175_BSD_RUNE_T_	__tolower __P((_BSD_RUNE_T_));
176__END_DECLS
177#endif /* using inlines */
178
179#endif /* !_CTYPE_H_ */
180