_ctype.h revision 7654
1179237Sjb/*
2179237Sjb * Copyright (c) 1989, 1993
3179237Sjb *	The Regents of the University of California.  All rights reserved.
4179237Sjb * (c) UNIX System Laboratories, Inc.
5179237Sjb * All or some portions of this file are derived from material licensed
6179237Sjb * to the University of California by American Telephone and Telegraph
7179237Sjb * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8179237Sjb * the permission of UNIX System Laboratories, Inc.
9179237Sjb *
10179237Sjb * This code is derived from software contributed to Berkeley by
11179237Sjb * Paul Borman at Krystal Technologies.
12179237Sjb *
13179237Sjb * Redistribution and use in source and binary forms, with or without
14179237Sjb * modification, are permitted provided that the following conditions
15179237Sjb * are met:
16179237Sjb * 1. Redistributions of source code must retain the above copyright
17179237Sjb *    notice, this list of conditions and the following disclaimer.
18179237Sjb * 2. Redistributions in binary form must reproduce the above copyright
19179237Sjb *    notice, this list of conditions and the following disclaimer in the
20179237Sjb *    documentation and/or other materials provided with the distribution.
21179237Sjb * 3. All advertising materials mentioning features or use of this software
22179237Sjb *    must display the following acknowledgement:
23179237Sjb *	This product includes software developed by the University of
24179237Sjb *	California, Berkeley and its contributors.
25179237Sjb * 4. Neither the name of the University nor the names of its contributors
26179237Sjb *    may be used to endorse or promote products derived from this software
27179237Sjb *    without specific prior written permission.
28179237Sjb *
29179237Sjb * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30179237Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31179237Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32179237Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33179237Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34179237Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35179237Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36179237Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37179237Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38179237Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39179237Sjb * SUCH DAMAGE.
40179237Sjb *
41179237Sjb *	@(#)ctype.h	8.4 (Berkeley) 1/21/94
42179237Sjb */
43179237Sjb
44179237Sjb#ifndef	_CTYPE_H_
45179237Sjb#define _CTYPE_H_
46179237Sjb
47179237Sjb#include <runetype.h>
48179237Sjb
49179237Sjb#define	_A	0x00000100L		/* Alpha */
50179237Sjb#define	_C	0x00000200L		/* Control */
51179237Sjb#define	_D	0x00000400L		/* Digit */
52179237Sjb#define	_G	0x00000800L		/* Graph */
53179237Sjb#define	_L	0x00001000L		/* Lower */
54179237Sjb#define	_P	0x00002000L		/* Punct */
55179237Sjb#define	_S	0x00004000L		/* Space */
56179237Sjb#define	_U	0x00008000L		/* Upper */
57179237Sjb#define	_X	0x00010000L		/* X digit */
58179237Sjb#define	_B	0x00020000L		/* Blank */
59179237Sjb#define	_R	0x00040000L		/* Print */
60179237Sjb#define	_I	0x00080000L		/* Ideogram */
61179237Sjb#define	_T	0x00100000L		/* Special */
62179237Sjb#define	_Q	0x00200000L		/* Phonogram */
63179237Sjb
64179237Sjb#define isalnum(c)      __istype((c), (_A|_D))
65179237Sjb#define isalpha(c)      __istype((c),     _A)
66179237Sjb#define iscntrl(c)      __istype((c),     _C)
67179237Sjb#define isdigit(c)      __isctype((c),    _D)	/* ANSI -- locale independent */
68179237Sjb#define isgraph(c)      __istype((c),     _G)
69179237Sjb#define islower(c)      __istype((c),     _L)
70179237Sjb#define isprint(c)      __istype((c),     _R)
71179237Sjb#define ispunct(c)      __istype((c),     _P)
72179237Sjb#define isspace(c)      __istype((c),     _S)
73179237Sjb#define isupper(c)      __istype((c),     _U)
74179237Sjb#define isxdigit(c)     __isctype((c),    _X)	/* ANSI -- locale independent */
75179237Sjb
76179237Sjb#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
77179237Sjb#define	isascii(c)	((c & ~0x7F) == 0)
78179237Sjb#define toascii(c)	((c) & 0x7F)
79179237Sjb#define	digittoint(c)	__istype((c), 0xFF)
80179237Sjb#define	isideogram(c)	__istype((c), _I)
81179237Sjb#define	isphonogram(c)	__istype((c), _T)
82179237Sjb#define	isspecial(c)	__istype((c), _Q)
83179237Sjb#define isblank(c)	__istype((c), _B)
84179237Sjb#define	isrune(c)	__istype((c),  0xFFFFFF00L)
85#define	isnumber(c)	__istype((c), _D)
86#define	ishexnumber(c)	__istype((c), _X)
87#endif
88
89/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
90__BEGIN_DECLS
91unsigned long	___runetype __P((_BSD_RUNE_T_));
92_BSD_RUNE_T_	___tolower __P((_BSD_RUNE_T_));
93_BSD_RUNE_T_	___toupper __P((_BSD_RUNE_T_));
94__END_DECLS
95
96/*
97 * If your compiler supports prototypes and inline functions,
98 * #define _USE_CTYPE_INLINE_.  Otherwise, use the C library
99 * functions.
100 */
101#if !defined(_USE_CTYPE_CLIBRARY_) && defined(__GNUC__) || defined(__cplusplus)
102#define	_USE_CTYPE_INLINE_	1
103#endif
104
105#if defined(_USE_CTYPE_INLINE_)
106static __inline int
107__istype(_BSD_RUNE_T_ __c, unsigned long __f)
108{
109	if (__c < 0)
110		__c = (unsigned char) __c;
111	return((((__c & _CRMASK) ? ___runetype(__c) :
112	    _CurrentRuneLocale->runetype[__c]) & __f) ? 1 : 0);
113}
114
115static __inline int
116__isctype(_BSD_RUNE_T_ __c, unsigned long __f)
117{
118	if (__c < 0)
119		__c = (unsigned char) __c;
120	return((((__c & _CRMASK) ? 0 :
121	    _DefaultRuneLocale.runetype[__c]) & __f) ? 1 : 0);
122}
123
124/* _ANSI_LIBRARY is defined by lib/libc/gen/isctype.c. */
125#if !defined(_ANSI_LIBRARY)
126static __inline _BSD_RUNE_T_
127toupper(_BSD_RUNE_T_ __c)
128{
129	if (__c < 0)
130		__c = (unsigned char) __c;
131	return((__c & _CRMASK) ?
132	    ___toupper(__c) : _CurrentRuneLocale->mapupper[__c]);
133}
134
135static __inline _BSD_RUNE_T_
136tolower(_BSD_RUNE_T_ __c)
137{
138	if (__c < 0)
139		__c = (unsigned char) __c;
140	return((__c & _CRMASK) ?
141	    ___tolower(__c) : _CurrentRuneLocale->maplower[__c]);
142}
143#endif /* !_ANSI_LIBRARY */
144
145#else /* !_USE_CTYPE_INLINE_ */
146
147__BEGIN_DECLS
148int		__istype __P((_BSD_RUNE_T_, unsigned long));
149int		__isctype __P((_BSD_RUNE_T_, unsigned long));
150_BSD_RUNE_T_	toupper __P((_BSD_RUNE_T_));
151_BSD_RUNE_T_	tolower __P((_BSD_RUNE_T_));
152__END_DECLS
153#endif /* _USE_CTYPE_INLINE_ */
154
155#endif /* !_CTYPE_H_ */
156