_ctype.h revision 102093
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
4254746Sphantom *      $FreeBSD: head/include/_ctype.h 102093 2002-08-19 08:50:41Z ache $
431539Srgrimes */
441539Srgrimes
457655Sbde#ifndef _CTYPE_H_
467655Sbde#define	_CTYPE_H_
471539Srgrimes
487655Sbde/*
497655Sbde * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
507655Sbde * member names).
517655Sbde */
521539Srgrimes#include <runetype.h>
531539Srgrimes
5457035Sobrien#define	_CTYPE_A	0x00000100L		/* Alpha */
5557035Sobrien#define	_CTYPE_C	0x00000200L		/* Control */
5657035Sobrien#define	_CTYPE_D	0x00000400L		/* Digit */
5757035Sobrien#define	_CTYPE_G	0x00000800L		/* Graph */
5857035Sobrien#define	_CTYPE_L	0x00001000L		/* Lower */
5957035Sobrien#define	_CTYPE_P	0x00002000L		/* Punct */
6057035Sobrien#define	_CTYPE_S	0x00004000L		/* Space */
6157035Sobrien#define	_CTYPE_U	0x00008000L		/* Upper */
6257035Sobrien#define	_CTYPE_X	0x00010000L		/* X digit */
6357035Sobrien#define	_CTYPE_B	0x00020000L		/* Blank */
6457035Sobrien#define	_CTYPE_R	0x00040000L		/* Print */
6557035Sobrien#define	_CTYPE_I	0x00080000L		/* Ideogram */
6657035Sobrien#define	_CTYPE_T	0x00100000L		/* Special */
6757035Sobrien#define	_CTYPE_Q	0x00200000L		/* Phonogram */
68101984Skeichii#define	_CTYPE_SWM	0xe0000000L		/* Mask to get screen width data */
69101984Skeichii#define	_CTYPE_SWS	30			/* Bits to shift to get width */
70102093Sache#define	_CTYPE_SWA	0x00000000L		/* autowidth / default */
71101984Skeichii#define	_CTYPE_SW0	0x20000000L		/* 0 width character */
72102093Sache#define	_CTYPE_SW1	0x40000000L		/* 1 width character */
73101984Skeichii#define	_CTYPE_SW2	0x80000000L		/* 2 width character */
74101984Skeichii#define	_CTYPE_SW3	0xc0000000L		/* 3 width character */
751539Srgrimes
767655Sbde__BEGIN_DECLS
7793032Simpint	isalnum(int);
7893032Simpint	isalpha(int);
7993032Simpint	iscntrl(int);
8093032Simpint	isdigit(int);
8193032Simpint	isgraph(int);
8293032Simpint	islower(int);
8393032Simpint	isprint(int);
8493032Simpint	ispunct(int);
8593032Simpint	isspace(int);
8693032Simpint	isupper(int);
8793032Simpint	isxdigit(int);
8893032Simpint	tolower(int);
8993032Simpint	toupper(int);
901539Srgrimes
911539Srgrimes#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
9293032Simpint	digittoint(int);
9393032Simpint	isascii(int);
9493032Simpint	isblank(int);
9593032Simpint	ishexnumber(int);
9693032Simpint	isideogram(int);
9793032Simpint	isnumber(int);
9893032Simpint	isphonogram(int);
9993032Simpint	isrune(int);
10093032Simpint	isspecial(int);
10193032Simpint	toascii(int);
1027655Sbde#endif
1037655Sbde__END_DECLS
1047655Sbde
10557035Sobrien#define	isalnum(c)	__istype((c), _CTYPE_A|_CTYPE_D)
10657035Sobrien#define	isalpha(c)	__istype((c), _CTYPE_A)
10757035Sobrien#define	iscntrl(c)	__istype((c), _CTYPE_C)
10857035Sobrien#define	isdigit(c)	__isctype((c), _CTYPE_D) /* ANSI -- locale independent */
10957035Sobrien#define	isgraph(c)	__istype((c), _CTYPE_G)
11057035Sobrien#define	islower(c)	__istype((c), _CTYPE_L)
11157035Sobrien#define	isprint(c)	__istype((c), _CTYPE_R)
11257035Sobrien#define	ispunct(c)	__istype((c), _CTYPE_P)
11357035Sobrien#define	isspace(c)	__istype((c), _CTYPE_S)
11457035Sobrien#define	isupper(c)	__istype((c), _CTYPE_U)
11557035Sobrien#define	isxdigit(c)	__isctype((c), _CTYPE_X) /* ANSI -- locale independent */
1167655Sbde#define	tolower(c)	__tolower(c)
1177655Sbde#define	toupper(c)	__toupper(c)
1187655Sbde
1197655Sbde#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
12054746Sphantom#define	digittoint(c)	__maskrune((c), 0xFF)
1217655Sbde#define	isascii(c)	(((c) & ~0x7F) == 0)
12257035Sobrien#define	isblank(c)	__istype((c), _CTYPE_B)
12357035Sobrien#define	ishexnumber(c)	__istype((c), _CTYPE_X)
12457035Sobrien#define	isideogram(c)	__istype((c), _CTYPE_I)
12557035Sobrien#define	isnumber(c)	__istype((c), _CTYPE_D)
12657035Sobrien#define	isphonogram(c)	__istype((c), _CTYPE_Q)
1277655Sbde#define	isrune(c)	__istype((c), 0xFFFFFF00L)
12857035Sobrien#define	isspecial(c)	__istype((c), _CTYPE_T)
12954746Sphantom#define	toascii(c)	((c) & 0x7F)
1301539Srgrimes#endif
1311539Srgrimes
13215483Sbde/* See comments in <machine/ansi.h> about _BSD_CT_RUNE_T_. */
1331539Srgrimes__BEGIN_DECLS
13493032Simpunsigned long	___runetype(_BSD_CT_RUNE_T_);
13593032Simp_BSD_CT_RUNE_T_	___tolower(_BSD_CT_RUNE_T_);
13693032Simp_BSD_CT_RUNE_T_	___toupper(_BSD_CT_RUNE_T_);
1371539Srgrimes__END_DECLS
1381539Srgrimes
1391539Srgrimes/*
1407655Sbde * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
1417655Sbde * to generate code for extern versions of all our inline functions.
1421539Srgrimes */
1437655Sbde#ifdef _EXTERNALIZE_CTYPE_INLINES_
1447655Sbde#define	_USE_CTYPE_INLINE_
1457655Sbde#define	static
1467655Sbde#define	__inline
1471539Srgrimes#endif
1481539Srgrimes
1497655Sbde/*
1507655Sbde * Use inline functions if we are allowed to and the compiler supports them.
1517655Sbde */
1527655Sbde#if !defined(_DONT_USE_CTYPE_INLINE_) && \
1537655Sbde    (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
1541539Srgrimesstatic __inline int
15529883Sache__maskrune(_BSD_CT_RUNE_T_ _c, unsigned long _f)
1561539Srgrimes{
15729855Sache	return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
15829855Sache		_CurrentRuneLocale->runetype[_c]) & _f;
1591539Srgrimes}
1601539Srgrimes
1611539Srgrimesstatic __inline int
16290231Sbbraun__istype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
16390231Sbbraun{
16490231Sbbraun	return (!!__maskrune(_c, _f));
16590231Sbbraun}
16690231Sbbraun
16790231Sbbraunstatic __inline int
16815483Sbde__isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
1691539Srgrimes{
17012028Sache	return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
17129883Sache	       !!(_DefaultRuneLocale.runetype[_c] & _f);
1721539Srgrimes}
1731539Srgrimes
17415483Sbdestatic __inline _BSD_CT_RUNE_T_
17515483Sbde__toupper(_BSD_CT_RUNE_T_ _c)
1761539Srgrimes{
17714813Sache	return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
17812028Sache	       _CurrentRuneLocale->mapupper[_c];
1791539Srgrimes}
1801539Srgrimes
18115483Sbdestatic __inline _BSD_CT_RUNE_T_
18215483Sbde__tolower(_BSD_CT_RUNE_T_ _c)
1831539Srgrimes{
18414813Sache	return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
18512028Sache	       _CurrentRuneLocale->maplower[_c];
1861539Srgrimes}
1871539Srgrimes
1887655Sbde#else /* not using inlines */
1891539Srgrimes
1901539Srgrimes__BEGIN_DECLS
19193032Simpint		__maskrune(_BSD_CT_RUNE_T_, unsigned long);
19293032Simpint		__istype(_BSD_CT_RUNE_T_, unsigned long);
19393032Simpint		__isctype(_BSD_CT_RUNE_T_, unsigned long);
19493032Simp_BSD_CT_RUNE_T_	__toupper(_BSD_CT_RUNE_T_);
19593032Simp_BSD_CT_RUNE_T_	__tolower(_BSD_CT_RUNE_T_);
1961539Srgrimes__END_DECLS
1977655Sbde#endif /* using inlines */
1981539Srgrimes
1991539Srgrimes#endif /* !_CTYPE_H_ */
200