ctype.h revision 29854
197403Sobrien/*
297403Sobrien * Copyright (c) 1989, 1993
3169691Skan *	The Regents of the University of California.  All rights reserved.
4169691Skan * (c) UNIX System Laboratories, Inc.
597403Sobrien * All or some portions of this file are derived from material licensed
697403Sobrien * to the University of California by American Telephone and Telegraph
797403Sobrien * Co. or Unix System Laboratories, Inc. and are reproduced herein with
897403Sobrien * the permission of UNIX System Laboratories, Inc.
997403Sobrien *
1097403Sobrien * This code is derived from software contributed to Berkeley by
1197403Sobrien * Paul Borman at Krystal Technologies.
1297403Sobrien *
1397403Sobrien * Redistribution and use in source and binary forms, with or without
1497403Sobrien * modification, are permitted provided that the following conditions
1597403Sobrien * are met:
1697403Sobrien * 1. Redistributions of source code must retain the above copyright
1797403Sobrien *    notice, this list of conditions and the following disclaimer.
1897403Sobrien * 2. Redistributions in binary form must reproduce the above copyright
19169691Skan *    notice, this list of conditions and the following disclaimer in the
2097403Sobrien *    documentation and/or other materials provided with the distribution.
2197403Sobrien * 3. All advertising materials mentioning features or use of this software
2297403Sobrien *    must display the following acknowledgement:
2397403Sobrien *	This product includes software developed by the University of
2497403Sobrien *	California, Berkeley and its contributors.
2597403Sobrien * 4. Neither the name of the University nor the names of its contributors
2697403Sobrien *    may be used to endorse or promote products derived from this software
2797403Sobrien *    without specific prior written permission.
2897403Sobrien *
2997403Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3097403Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3197403Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3297403Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3397403Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3497403Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3597403Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3697403Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3797403Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3897403Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3997403Sobrien * SUCH DAMAGE.
4097403Sobrien *
4197403Sobrien *	@(#)ctype.h	8.4 (Berkeley) 1/21/94
4297403Sobrien */
4397403Sobrien
4497403Sobrien#ifndef _CTYPE_H_
4597403Sobrien#define	_CTYPE_H_
4697403Sobrien
4797403Sobrien/*
4897403Sobrien * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
4997403Sobrien * member names).
5097403Sobrien */
5197403Sobrien#include <runetype.h>
5297403Sobrien
5397403Sobrien#define	_A	0x00000100L		/* Alpha */
5497403Sobrien#define	_C	0x00000200L		/* Control */
5597403Sobrien#define	_D	0x00000400L		/* Digit */
5697403Sobrien#define	_G	0x00000800L		/* Graph */
5797403Sobrien#define	_L	0x00001000L		/* Lower */
5897403Sobrien#define	_P	0x00002000L		/* Punct */
5997403Sobrien#define	_S	0x00004000L		/* Space */
6097403Sobrien#define	_U	0x00008000L		/* Upper */
6197403Sobrien#define	_X	0x00010000L		/* X digit */
62132720Skan#define	_B	0x00020000L		/* Blank */
63132720Skan#define	_R	0x00040000L		/* Print */
6497403Sobrien#define	_I	0x00080000L		/* Ideogram */
65169691Skan#define	_T	0x00100000L		/* Special */
6697403Sobrien#define	_Q	0x00200000L		/* Phonogram */
6797403Sobrien
68169691Skan__BEGIN_DECLS
69169691Skanint	isalnum __P((int));
7097403Sobrienint	isalpha __P((int));
71117397Skanint	iscntrl __P((int));
72117397Skanint	isdigit __P((int));
7397403Sobrienint	isgraph __P((int));
74117397Skanint	islower __P((int));
75117397Skanint	isprint __P((int));
7697403Sobrienint	ispunct __P((int));
77117397Skanint	isspace __P((int));
78117397Skanint	isupper __P((int));
79117397Skanint	isxdigit __P((int));
80117397Skanint	tolower __P((int));
81117397Skanint	toupper __P((int));
8297403Sobrien
83117397Skan#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
8497403Sobrienint	isascii __P((int));
85117397Skanint	isblank __P((int));
86117397Skanint	toascii __P((int));
87117397Skanint	digittoint __P((int));
88117397Skan#endif
89117397Skan__END_DECLS
9097403Sobrien
91169691Skan#define	__istype(c,f)	(__runeflags((c)) & (f))
92169691Skan
93117397Skan#define	isalnum(c)      __istype((c), (_A|_D))
94132720Skan#define	isalpha(c)      __istype((c),     _A)
95169691Skan#define	iscntrl(c)      __istype((c),     _C)
96169691Skan#define	isdigit(c)      __isctype((c),    _D)	/* ANSI -- locale independent */
97169691Skan#define	isgraph(c)      __istype((c),     _G)
98169691Skan#define	islower(c)      __istype((c),     _L)
99169691Skan#define	isprint(c)      __istype((c),     _R)
100169691Skan#define	ispunct(c)      __istype((c),     _P)
101169691Skan#define	isspace(c)      __istype((c),     _S)
102169691Skan#define	isupper(c)      __istype((c),     _U)
103132720Skan#define	isxdigit(c)     __isctype((c),    _X)	/* ANSI -- locale independent */
104169691Skan#define	tolower(c)	__tolower(c)
105132720Skan#define	toupper(c)	__toupper(c)
106132720Skan
107132720Skan#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
108169691Skan#define	isascii(c)	(((c) & ~0x7F) == 0)
109132720Skan#define	isblank(c)	__istype((c), _B)
110132720Skan#define	toascii(c)	((c) & 0x7F)
111132720Skan#define	digittoint(c)	__runeflags((c))
112169691Skan
113117397Skan/* XXX the following macros are not backed up by functions. */
114169691Skan#define	ishexnumber(c)	__istype((c), _X)
115117397Skan#define	isideogram(c)	__istype((c), _I)
116132720Skan#define	isnumber(c)	__istype((c), _D)
117132720Skan#define isphonogram(c)  __istype((c), _Q)
118132720Skan#define	isrune(c)	__istype((c), 0xFFFFFF00L)
119132720Skan#define isspecial(c)    __istype((c), _T)
120132720Skan#endif
121117397Skan
122132720Skan/* See comments in <machine/ansi.h> about _BSD_CT_RUNE_T_. */
123132720Skan__BEGIN_DECLS
124117397Skanunsigned long	___runetype __P((_BSD_CT_RUNE_T_));
125132720Skan_BSD_CT_RUNE_T_	___tolower __P((_BSD_CT_RUNE_T_));
126132720Skan_BSD_CT_RUNE_T_	___toupper __P((_BSD_CT_RUNE_T_));
127132720Skan__END_DECLS
128169691Skan
129169691Skan/*
130169691Skan * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
131169691Skan * to generate code for extern versions of all our inline functions.
132169691Skan */
133169691Skan#ifdef _EXTERNALIZE_CTYPE_INLINES_
134132720Skan#define	_USE_CTYPE_INLINE_
135132720Skan#define	static
136132720Skan#define	__inline
137132720Skan#endif
138132720Skan
139132720Skan/*
140169691Skan * Use inline functions if we are allowed to and the compiler supports them.
141169691Skan */
142169691Skan#if !defined(_DONT_USE_CTYPE_INLINE_) && \
143169691Skan    (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
144132720Skanstatic __inline int
145132720Skan__runeflags(_BSD_CT_RUNE_T_ _c)
146132720Skan{
147132720Skan	return (_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
148132720Skan	       _CurrentRuneLocale->runetype[_c];
149132720Skan}
150132720Skan
151132720Skanstatic __inline int
152132720Skan__isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
153132720Skan{
154132720Skan	return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
155132720Skan	       (_DefaultRuneLocale.runetype[_c]	& _f);
156132720Skan}
157132720Skan
158236829Spfgstatic __inline _BSD_CT_RUNE_T_
159132720Skan__toupper(_BSD_CT_RUNE_T_ _c)
160132720Skan{
161132720Skan	return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
162132720Skan	       _CurrentRuneLocale->mapupper[_c];
163132720Skan}
164132720Skan
165132720Skanstatic __inline _BSD_CT_RUNE_T_
166117397Skan__tolower(_BSD_CT_RUNE_T_ _c)
167132720Skan{
168132720Skan	return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
169132720Skan	       _CurrentRuneLocale->maplower[_c];
170132720Skan}
171132720Skan
172132720Skan#else /* not using inlines */
173132720Skan
174132720Skan__BEGIN_DECLS
175132720Skanint		__runeflags __P((_BSD_CT_RUNE_T_));
176117397Skanint		__isctype __P((_BSD_CT_RUNE_T_, unsigned long));
177132720Skan_BSD_CT_RUNE_T_	__toupper __P((_BSD_CT_RUNE_T_));
178132720Skan_BSD_CT_RUNE_T_	__tolower __P((_BSD_CT_RUNE_T_));
179132720Skan__END_DECLS
180132720Skan#endif /* using inlines */
181132720Skan
182132720Skan#endif /* !_CTYPE_H_ */
183132720Skan