_ctype.h revision 101984
1243730Srwatson/*
2243730Srwatson * Copyright (c) 1989, 1993
3243730Srwatson *	The Regents of the University of California.  All rights reserved.
4243730Srwatson * (c) UNIX System Laboratories, Inc.
5243730Srwatson * All or some portions of this file are derived from material licensed
6243730Srwatson * to the University of California by American Telephone and Telegraph
7243730Srwatson * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8243730Srwatson * the permission of UNIX System Laboratories, Inc.
9243730Srwatson *
10243730Srwatson * This code is derived from software contributed to Berkeley by
11243730Srwatson * Paul Borman at Krystal Technologies.
12243730Srwatson *
13243730Srwatson * Redistribution and use in source and binary forms, with or without
14243730Srwatson * modification, are permitted provided that the following conditions
15243730Srwatson * are met:
16243730Srwatson * 1. Redistributions of source code must retain the above copyright
17243730Srwatson *    notice, this list of conditions and the following disclaimer.
18243730Srwatson * 2. Redistributions in binary form must reproduce the above copyright
19243730Srwatson *    notice, this list of conditions and the following disclaimer in the
20243730Srwatson *    documentation and/or other materials provided with the distribution.
21243730Srwatson * 3. All advertising materials mentioning features or use of this software
22243730Srwatson *    must display the following acknowledgement:
23243730Srwatson *	This product includes software developed by the University of
24243730Srwatson *	California, Berkeley and its contributors.
25243730Srwatson * 4. Neither the name of the University nor the names of its contributors
26243730Srwatson *    may be used to endorse or promote products derived from this software
27243730Srwatson *    without specific prior written permission.
28243730Srwatson *
29243730Srwatson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30243730Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31243730Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32243730Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33243730Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34243730Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35243730Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36243730Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37243730Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38243730Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39243730Srwatson * SUCH DAMAGE.
40243730Srwatson *
41243730Srwatson *	@(#)ctype.h	8.4 (Berkeley) 1/21/94
42243730Srwatson *      $FreeBSD: head/include/_ctype.h 101984 2002-08-16 13:42:59Z keichii $
43243730Srwatson */
44243730Srwatson
45243730Srwatson#ifndef _CTYPE_H_
46243730Srwatson#define	_CTYPE_H_
47243730Srwatson
48243730Srwatson/*
49243730Srwatson * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
50243730Srwatson * member names).
51243730Srwatson */
52243730Srwatson#include <runetype.h>
53243730Srwatson
54243730Srwatson#define	_CTYPE_A	0x00000100L		/* Alpha */
55243730Srwatson#define	_CTYPE_C	0x00000200L		/* Control */
56243730Srwatson#define	_CTYPE_D	0x00000400L		/* Digit */
57243730Srwatson#define	_CTYPE_G	0x00000800L		/* Graph */
58243730Srwatson#define	_CTYPE_L	0x00001000L		/* Lower */
59243730Srwatson#define	_CTYPE_P	0x00002000L		/* Punct */
60243730Srwatson#define	_CTYPE_S	0x00004000L		/* Space */
61243730Srwatson#define	_CTYPE_U	0x00008000L		/* Upper */
62243730Srwatson#define	_CTYPE_X	0x00010000L		/* X digit */
63243730Srwatson#define	_CTYPE_B	0x00020000L		/* Blank */
64243730Srwatson#define	_CTYPE_R	0x00040000L		/* Print */
65243730Srwatson#define	_CTYPE_I	0x00080000L		/* Ideogram */
66243730Srwatson#define	_CTYPE_T	0x00100000L		/* Special */
67243730Srwatson#define	_CTYPE_Q	0x00200000L		/* Phonogram */
68243730Srwatson#define	_CTYPE_SWM	0xe0000000L		/* Mask to get screen width data */
69243730Srwatson#define	_CTYPE_SWS	30			/* Bits to shift to get width */
70243730Srwatson#define	_CTYPE_SW0	0x20000000L		/* 0 width character */
71243730Srwatson#define	_CTYPE_SW1	0x00000000L		/* 1 width character / default*/
72243730Srwatson#define	_CTYPE_SW2	0x80000000L		/* 2 width character */
73243730Srwatson#define	_CTYPE_SW3	0xc0000000L		/* 3 width character */
74243730Srwatson
75243730Srwatson__BEGIN_DECLS
76243730Srwatsonint	isalnum(int);
77243730Srwatsonint	isalpha(int);
78243730Srwatsonint	iscntrl(int);
79243730Srwatsonint	isdigit(int);
80243730Srwatsonint	isgraph(int);
81243730Srwatsonint	islower(int);
82243730Srwatsonint	isprint(int);
83243730Srwatsonint	ispunct(int);
84243730Srwatsonint	isspace(int);
85243730Srwatsonint	isupper(int);
86243730Srwatsonint	isxdigit(int);
87243730Srwatsonint	tolower(int);
88243730Srwatsonint	toupper(int);
89243730Srwatson
90243730Srwatson#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
91243730Srwatsonint	digittoint(int);
92243730Srwatsonint	isascii(int);
93243730Srwatsonint	isblank(int);
94243730Srwatsonint	ishexnumber(int);
95243730Srwatsonint	isideogram(int);
96243730Srwatsonint	isnumber(int);
97243730Srwatsonint	isphonogram(int);
98243730Srwatsonint	isrune(int);
99243730Srwatsonint	isspecial(int);
100243730Srwatsonint	toascii(int);
101243730Srwatson#endif
102243730Srwatson__END_DECLS
103243730Srwatson
104243730Srwatson#define	isalnum(c)	__istype((c), _CTYPE_A|_CTYPE_D)
105243730Srwatson#define	isalpha(c)	__istype((c), _CTYPE_A)
106243730Srwatson#define	iscntrl(c)	__istype((c), _CTYPE_C)
107243730Srwatson#define	isdigit(c)	__isctype((c), _CTYPE_D) /* ANSI -- locale independent */
108243730Srwatson#define	isgraph(c)	__istype((c), _CTYPE_G)
109243730Srwatson#define	islower(c)	__istype((c), _CTYPE_L)
110243730Srwatson#define	isprint(c)	__istype((c), _CTYPE_R)
111243730Srwatson#define	ispunct(c)	__istype((c), _CTYPE_P)
112243730Srwatson#define	isspace(c)	__istype((c), _CTYPE_S)
113243730Srwatson#define	isupper(c)	__istype((c), _CTYPE_U)
114243730Srwatson#define	isxdigit(c)	__isctype((c), _CTYPE_X) /* ANSI -- locale independent */
115243730Srwatson#define	tolower(c)	__tolower(c)
116243730Srwatson#define	toupper(c)	__toupper(c)
117243730Srwatson
118243730Srwatson#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
119243730Srwatson#define	digittoint(c)	__maskrune((c), 0xFF)
120243730Srwatson#define	isascii(c)	(((c) & ~0x7F) == 0)
121243730Srwatson#define	isblank(c)	__istype((c), _CTYPE_B)
122243730Srwatson#define	ishexnumber(c)	__istype((c), _CTYPE_X)
123243730Srwatson#define	isideogram(c)	__istype((c), _CTYPE_I)
124243730Srwatson#define	isnumber(c)	__istype((c), _CTYPE_D)
125243730Srwatson#define	isphonogram(c)	__istype((c), _CTYPE_Q)
126243730Srwatson#define	isrune(c)	__istype((c), 0xFFFFFF00L)
127243730Srwatson#define	isspecial(c)	__istype((c), _CTYPE_T)
128243730Srwatson#define	toascii(c)	((c) & 0x7F)
129243730Srwatson#endif
130243730Srwatson
131243730Srwatson/* See comments in <machine/ansi.h> about _BSD_CT_RUNE_T_. */
132243730Srwatson__BEGIN_DECLS
133243730Srwatsonunsigned long	___runetype(_BSD_CT_RUNE_T_);
134243730Srwatson_BSD_CT_RUNE_T_	___tolower(_BSD_CT_RUNE_T_);
135243730Srwatson_BSD_CT_RUNE_T_	___toupper(_BSD_CT_RUNE_T_);
136243730Srwatson__END_DECLS
137243730Srwatson
138243730Srwatson/*
139243730Srwatson * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
140243730Srwatson * to generate code for extern versions of all our inline functions.
141243730Srwatson */
142243730Srwatson#ifdef _EXTERNALIZE_CTYPE_INLINES_
143243730Srwatson#define	_USE_CTYPE_INLINE_
144243730Srwatson#define	static
145243730Srwatson#define	__inline
146243730Srwatson#endif
147243730Srwatson
148243730Srwatson/*
149243730Srwatson * Use inline functions if we are allowed to and the compiler supports them.
150243730Srwatson */
151243730Srwatson#if !defined(_DONT_USE_CTYPE_INLINE_) && \
152243730Srwatson    (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
153243730Srwatsonstatic __inline int
154243730Srwatson__maskrune(_BSD_CT_RUNE_T_ _c, unsigned long _f)
155243730Srwatson{
156243730Srwatson	return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
157243730Srwatson		_CurrentRuneLocale->runetype[_c]) & _f;
158243730Srwatson}
159243730Srwatson
160243730Srwatsonstatic __inline int
161243730Srwatson__istype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
162243730Srwatson{
163243730Srwatson	return (!!__maskrune(_c, _f));
164243730Srwatson}
165243730Srwatson
166243730Srwatsonstatic __inline int
167243730Srwatson__isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
168243730Srwatson{
169243730Srwatson	return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
170243730Srwatson	       !!(_DefaultRuneLocale.runetype[_c] & _f);
171243730Srwatson}
172243730Srwatson
173243730Srwatsonstatic __inline _BSD_CT_RUNE_T_
174243730Srwatson__toupper(_BSD_CT_RUNE_T_ _c)
175243730Srwatson{
176243730Srwatson	return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
177243730Srwatson	       _CurrentRuneLocale->mapupper[_c];
178243730Srwatson}
179243730Srwatson
180243730Srwatsonstatic __inline _BSD_CT_RUNE_T_
181243730Srwatson__tolower(_BSD_CT_RUNE_T_ _c)
182243730Srwatson{
183243730Srwatson	return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
184243730Srwatson	       _CurrentRuneLocale->maplower[_c];
185243730Srwatson}
186243730Srwatson
187243730Srwatson#else /* not using inlines */
188243730Srwatson
189243730Srwatson__BEGIN_DECLS
190243730Srwatsonint		__maskrune(_BSD_CT_RUNE_T_, unsigned long);
191243730Srwatsonint		__istype(_BSD_CT_RUNE_T_, unsigned long);
192243730Srwatsonint		__isctype(_BSD_CT_RUNE_T_, unsigned long);
193243730Srwatson_BSD_CT_RUNE_T_	__toupper(_BSD_CT_RUNE_T_);
194243730Srwatson_BSD_CT_RUNE_T_	__tolower(_BSD_CT_RUNE_T_);
195243730Srwatson__END_DECLS
196243730Srwatson#endif /* using inlines */
197243730Srwatson
198243730Srwatson#endif /* !_CTYPE_H_ */
199243730Srwatson