ctype.h revision 7655
11539Srgrimes/*
21539Srgrimes * Copyright (c) 1989, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes * (c) UNIX System Laboratories, Inc.
51539Srgrimes * All or some portions of this file are derived from material licensed
61539Srgrimes * to the University of California by American Telephone and Telegraph
71539Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81539Srgrimes * the permission of UNIX System Laboratories, Inc.
91539Srgrimes *
101539Srgrimes * This code is derived from software contributed to Berkeley by
111539Srgrimes * Paul Borman at Krystal Technologies.
121539Srgrimes *
131539Srgrimes * Redistribution and use in source and binary forms, with or without
141539Srgrimes * modification, are permitted provided that the following conditions
151539Srgrimes * are met:
161539Srgrimes * 1. Redistributions of source code must retain the above copyright
171539Srgrimes *    notice, this list of conditions and the following disclaimer.
181539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
191539Srgrimes *    notice, this list of conditions and the following disclaimer in the
201539Srgrimes *    documentation and/or other materials provided with the distribution.
211539Srgrimes * 3. All advertising materials mentioning features or use of this software
221539Srgrimes *    must display the following acknowledgement:
231539Srgrimes *	This product includes software developed by the University of
241539Srgrimes *	California, Berkeley and its contributors.
251539Srgrimes * 4. Neither the name of the University nor the names of its contributors
261539Srgrimes *    may be used to endorse or promote products derived from this software
271539Srgrimes *    without specific prior written permission.
281539Srgrimes *
291539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
301539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
311539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
321539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
331539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
341539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
351539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
361539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
371539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
381539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
391539Srgrimes * SUCH DAMAGE.
401539Srgrimes *
411539Srgrimes *	@(#)ctype.h	8.4 (Berkeley) 1/21/94
421539Srgrimes */
431539Srgrimes
447655Sbde#ifndef _CTYPE_H_
457655Sbde#define	_CTYPE_H_
461539Srgrimes
477655Sbde/*
487655Sbde * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
497655Sbde * member names).
507655Sbde */
511539Srgrimes#include <runetype.h>
521539Srgrimes
531539Srgrimes#define	_A	0x00000100L		/* Alpha */
541539Srgrimes#define	_C	0x00000200L		/* Control */
551539Srgrimes#define	_D	0x00000400L		/* Digit */
561539Srgrimes#define	_G	0x00000800L		/* Graph */
571539Srgrimes#define	_L	0x00001000L		/* Lower */
581539Srgrimes#define	_P	0x00002000L		/* Punct */
591539Srgrimes#define	_S	0x00004000L		/* Space */
601539Srgrimes#define	_U	0x00008000L		/* Upper */
611539Srgrimes#define	_X	0x00010000L		/* X digit */
621539Srgrimes#define	_B	0x00020000L		/* Blank */
631539Srgrimes#define	_R	0x00040000L		/* Print */
641539Srgrimes#define	_I	0x00080000L		/* Ideogram */
651539Srgrimes#define	_T	0x00100000L		/* Special */
661539Srgrimes#define	_Q	0x00200000L		/* Phonogram */
671539Srgrimes
687655Sbde__BEGIN_DECLS
697655Sbdeint	isalnum __P((int));
707655Sbdeint	isalpha __P((int));
717655Sbdeint	iscntrl __P((int));
727655Sbdeint	isdigit __P((int));
737655Sbdeint	isgraph __P((int));
747655Sbdeint	islower __P((int));
757655Sbdeint	isprint __P((int));
767655Sbdeint	ispunct __P((int));
777655Sbdeint	isspace __P((int));
787655Sbdeint	isupper __P((int));
797655Sbdeint	isxdigit __P((int));
807655Sbdeint	tolower __P((int));
817655Sbdeint	toupper __P((int));
821539Srgrimes
831539Srgrimes#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
847655Sbdeint	isascii __P((int));
857655Sbdeint	isblank __P((int));
867655Sbdeint	toascii __P((int));
877655Sbde#endif
887655Sbde__END_DECLS
897655Sbde
907655Sbde#define	isalnum(c)      __istype((c), (_A|_D))
917655Sbde#define	isalpha(c)      __istype((c),     _A)
927655Sbde#define	iscntrl(c)      __istype((c),     _C)
937655Sbde#define	isdigit(c)      __isctype((c),    _D)	/* ANSI -- locale independent */
947655Sbde#define	isgraph(c)      __istype((c),     _G)
957655Sbde#define	islower(c)      __istype((c),     _L)
967655Sbde#define	isprint(c)      __istype((c),     _R)
977655Sbde#define	ispunct(c)      __istype((c),     _P)
987655Sbde#define	isspace(c)      __istype((c),     _S)
997655Sbde#define	isupper(c)      __istype((c),     _U)
1007655Sbde#define	isxdigit(c)     __isctype((c),    _X)	/* ANSI -- locale independent */
1017655Sbde#define	tolower(c)	__tolower(c)
1027655Sbde#define	toupper(c)	__toupper(c)
1037655Sbde
1047655Sbde#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
1057655Sbde#define	isascii(c)	(((c) & ~0x7F) == 0)
1067655Sbde#define	isblank(c)	__istype((c), _B)
1077655Sbde#define	toascii(c)	((c) & 0x7F)
1087655Sbde
1097655Sbde/* XXX the following macros are not backed up by functions. */
1101539Srgrimes#define	digittoint(c)	__istype((c), 0xFF)
1117655Sbde#define	ishexnumber(c)	__istype((c), _X)
1121539Srgrimes#define	isideogram(c)	__istype((c), _I)
1137655Sbde#define	isnumber(c)	__istype((c), _D)
1141539Srgrimes#define	isphonogram(c)	__istype((c), _T)
1157655Sbde#define	isrune(c)	__istype((c), 0xFFFFFF00L)
1161539Srgrimes#define	isspecial(c)	__istype((c), _Q)
1171539Srgrimes#endif
1181539Srgrimes
1191539Srgrimes/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
1201539Srgrimes__BEGIN_DECLS
1211539Srgrimesunsigned long	___runetype __P((_BSD_RUNE_T_));
1221539Srgrimes_BSD_RUNE_T_	___tolower __P((_BSD_RUNE_T_));
1231539Srgrimes_BSD_RUNE_T_	___toupper __P((_BSD_RUNE_T_));
1241539Srgrimes__END_DECLS
1251539Srgrimes
1261539Srgrimes/*
1277655Sbde * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
1287655Sbde * to generate code for extern versions of all our inline functions.
1291539Srgrimes */
1307655Sbde#ifdef _EXTERNALIZE_CTYPE_INLINES_
1317655Sbde#define	_USE_CTYPE_INLINE_
1327655Sbde#define	static
1337655Sbde#define	__inline
1341539Srgrimes#endif
1351539Srgrimes
1367655Sbde/*
1377655Sbde * Use inline functions if we are allowed to and the compiler supports them.
1387655Sbde */
1397655Sbde#if !defined(_DONT_USE_CTYPE_INLINE_) && \
1407655Sbde    (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
1411539Srgrimesstatic __inline int
1427655Sbde__istype(_BSD_RUNE_T_ _c, unsigned long _f)
1431539Srgrimes{
1447655Sbde	if (_c < 0)
1457655Sbde		_c = (unsigned char) _c;
1467655Sbde	return((((_c & _CRMASK) ? ___runetype(_c) :
1477655Sbde	    _CurrentRuneLocale->runetype[_c]) & _f) ? 1 : 0);
1481539Srgrimes}
1491539Srgrimes
1501539Srgrimesstatic __inline int
1517655Sbde__isctype(_BSD_RUNE_T_ _c, unsigned long _f)
1521539Srgrimes{
1537655Sbde	if (_c < 0)
1547655Sbde		_c = (unsigned char) _c;
1557655Sbde	return((((_c & _CRMASK) ? 0 :
1567655Sbde	    _DefaultRuneLocale.runetype[_c]) & _f) ? 1 : 0);
1571539Srgrimes}
1581539Srgrimes
1591539Srgrimesstatic __inline _BSD_RUNE_T_
1607655Sbde__toupper(_BSD_RUNE_T_ _c)
1611539Srgrimes{
1627655Sbde	if (_c < 0)
1637655Sbde		_c = (unsigned char) _c;
1647655Sbde	return((_c & _CRMASK) ?
1657655Sbde	    ___toupper(_c) : _CurrentRuneLocale->mapupper[_c]);
1661539Srgrimes}
1671539Srgrimes
1681539Srgrimesstatic __inline _BSD_RUNE_T_
1697655Sbde__tolower(_BSD_RUNE_T_ _c)
1701539Srgrimes{
1717655Sbde	if (_c < 0)
1727655Sbde		_c = (unsigned char) _c;
1737655Sbde	return((_c & _CRMASK) ?
1747655Sbde	    ___tolower(_c) : _CurrentRuneLocale->maplower[_c]);
1751539Srgrimes}
1761539Srgrimes
1777655Sbde#else /* not using inlines */
1781539Srgrimes
1791539Srgrimes__BEGIN_DECLS
1801539Srgrimesint		__istype __P((_BSD_RUNE_T_, unsigned long));
1811539Srgrimesint		__isctype __P((_BSD_RUNE_T_, unsigned long));
1827655Sbde_BSD_RUNE_T_	__toupper __P((_BSD_RUNE_T_));
1837655Sbde_BSD_RUNE_T_	__tolower __P((_BSD_RUNE_T_));
1841539Srgrimes__END_DECLS
1857655Sbde#endif /* using inlines */
1861539Srgrimes
1871539Srgrimes#endif /* !_CTYPE_H_ */
188