_ctype.h revision 102998
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. 9 * 10 * This code is derived from software contributed to Berkeley by 11 * Paul Borman at Krystal Technologies. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. All advertising materials mentioning features or use of this software 22 * must display the following acknowledgement: 23 * This product includes software developed by the University of 24 * California, Berkeley and its contributors. 25 * 4. Neither the name of the University nor the names of its contributors 26 * may be used to endorse or promote products derived from this software 27 * without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * @(#)ctype.h 8.4 (Berkeley) 1/21/94 42 * $FreeBSD: head/include/_ctype.h 102998 2002-09-06 04:22:54Z mike $ 43 */ 44 45#ifndef _CTYPE_H_ 46#define _CTYPE_H_ 47 48/* 49 * XXX <runetype.h> brings namespace pollution (struct member names). 50 */ 51#include <runetype.h> 52 53#define _CTYPE_A 0x00000100L /* Alpha */ 54#define _CTYPE_C 0x00000200L /* Control */ 55#define _CTYPE_D 0x00000400L /* Digit */ 56#define _CTYPE_G 0x00000800L /* Graph */ 57#define _CTYPE_L 0x00001000L /* Lower */ 58#define _CTYPE_P 0x00002000L /* Punct */ 59#define _CTYPE_S 0x00004000L /* Space */ 60#define _CTYPE_U 0x00008000L /* Upper */ 61#define _CTYPE_X 0x00010000L /* X digit */ 62#define _CTYPE_B 0x00020000L /* Blank */ 63#define _CTYPE_R 0x00040000L /* Print */ 64#define _CTYPE_I 0x00080000L /* Ideogram */ 65#define _CTYPE_T 0x00100000L /* Special */ 66#define _CTYPE_Q 0x00200000L /* Phonogram */ 67#define _CTYPE_SW0 0x20000000L /* 0 width character */ 68#define _CTYPE_SW1 0x40000000L /* 1 width character */ 69#define _CTYPE_SW2 0x80000000L /* 2 width character */ 70#define _CTYPE_SW3 0xc0000000L /* 3 width character */ 71 72__BEGIN_DECLS 73int isalnum(int); 74int isalpha(int); 75int iscntrl(int); 76int isdigit(int); 77int isgraph(int); 78int islower(int); 79int isprint(int); 80int ispunct(int); 81int isspace(int); 82int isupper(int); 83int isxdigit(int); 84int tolower(int); 85int toupper(int); 86 87#if __XSI_VISIBLE 88int _tolower(int); 89int _toupper(int); 90int isascii(int); 91int toascii(int); 92#endif 93 94#if __BSD_VISIBLE 95int digittoint(int); 96int isblank(int); 97int ishexnumber(int); 98int isideogram(int); 99int isnumber(int); 100int isphonogram(int); 101int isrune(int); 102int isspecial(int); 103#endif 104__END_DECLS 105 106#define isalnum(c) __istype((c), _CTYPE_A|_CTYPE_D) 107#define isalpha(c) __istype((c), _CTYPE_A) 108#define iscntrl(c) __istype((c), _CTYPE_C) 109#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */ 110#define isgraph(c) __istype((c), _CTYPE_G) 111#define islower(c) __istype((c), _CTYPE_L) 112#define isprint(c) __istype((c), _CTYPE_R) 113#define ispunct(c) __istype((c), _CTYPE_P) 114#define isspace(c) __istype((c), _CTYPE_S) 115#define isupper(c) __istype((c), _CTYPE_U) 116#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */ 117#define tolower(c) __tolower(c) 118#define toupper(c) __toupper(c) 119 120#if __XSI_VISIBLE 121/* 122 * POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to 123 * tolower() and toupper() respectively, minus extra checking to ensure that 124 * the argument is a lower or uppercase letter respectively. We've chosen to 125 * implement these macros with the same error checking as tolower() and 126 * toupper() since this doesn't violate the specification itself, only its 127 * intent. We purposely leave _tolower() and _toupper() undocumented to 128 * discourage their use. 129 * 130 * XXX isascii() and toascii() should similarly be undocumented. 131 */ 132#define _tolower(c) __tolower(c) 133#define _toupper(c) __toupper(c) 134#define isascii(c) (((c) & ~0x7F) == 0) 135#define toascii(c) ((c) & 0x7F) 136#endif 137 138#if __BSD_VISIBLE 139#define digittoint(c) __maskrune((c), 0xFF) 140#define isblank(c) __istype((c), _CTYPE_B) 141#define ishexnumber(c) __istype((c), _CTYPE_X) 142#define isideogram(c) __istype((c), _CTYPE_I) 143#define isnumber(c) __istype((c), _CTYPE_D) 144#define isphonogram(c) __istype((c), _CTYPE_Q) 145#define isrune(c) __istype((c), 0xFFFFFF00L) 146#define isspecial(c) __istype((c), _CTYPE_T) 147#endif 148 149/* See comments in <sys/_types.h> about __ct_rune_t. */ 150__BEGIN_DECLS 151unsigned long ___runetype(__ct_rune_t); 152__ct_rune_t ___tolower(__ct_rune_t); 153__ct_rune_t ___toupper(__ct_rune_t); 154__END_DECLS 155 156/* 157 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us 158 * to generate code for extern versions of all our inline functions. 159 */ 160#ifdef _EXTERNALIZE_CTYPE_INLINES_ 161#define _USE_CTYPE_INLINE_ 162#define static 163#define __inline 164#endif 165 166/* 167 * Use inline functions if we are allowed to and the compiler supports them. 168 */ 169#if !defined(_DONT_USE_CTYPE_INLINE_) && \ 170 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) 171static __inline int 172__maskrune(__ct_rune_t _c, unsigned long _f) 173{ 174 return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : 175 _CurrentRuneLocale->runetype[_c]) & _f; 176} 177 178static __inline int 179__istype(__ct_rune_t _c, unsigned long _f) 180{ 181 return (!!__maskrune(_c, _f)); 182} 183 184static __inline int 185__isctype(__ct_rune_t _c, unsigned long _f) 186{ 187 return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : 188 !!(_DefaultRuneLocale.runetype[_c] & _f); 189} 190 191static __inline __ct_rune_t 192__toupper(__ct_rune_t _c) 193{ 194 return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : 195 _CurrentRuneLocale->mapupper[_c]; 196} 197 198static __inline __ct_rune_t 199__tolower(__ct_rune_t _c) 200{ 201 return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : 202 _CurrentRuneLocale->maplower[_c]; 203} 204 205#else /* not using inlines */ 206 207__BEGIN_DECLS 208int __maskrune(__ct_rune_t, unsigned long); 209int __istype(__ct_rune_t, unsigned long); 210int __isctype(__ct_rune_t, unsigned long); 211__ct_rune_t __toupper(__ct_rune_t); 212__ct_rune_t __tolower(__ct_rune_t); 213__END_DECLS 214#endif /* using inlines */ 215 216#endif /* !_CTYPE_H_ */ 217