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: src/include/ctype.h,v 1.16 2000/02/08 07:43:23 obrien Exp $ 43 * $DragonFly: src/include/ctype.h,v 1.2 2003/06/17 04:25:56 dillon Exp $ 44 */ 45 46 #ifndef _CTYPE_H_ 47 #define _CTYPE_H_ 48 49 /* 50 * XXX <runetype.h> brings massive namespace pollution (rune_t and struct 51 * member names). 52 */ 53 #include <runetype.h> 54 55 #define _CTYPE_A 0x00000100L /* Alpha */ 56 #define _CTYPE_C 0x00000200L /* Control */ 57 #define _CTYPE_D 0x00000400L /* Digit */ 58 #define _CTYPE_G 0x00000800L /* Graph */ 59 #define _CTYPE_L 0x00001000L /* Lower */ 60 #define _CTYPE_P 0x00002000L /* Punct */ 61 #define _CTYPE_S 0x00004000L /* Space */ 62 #define _CTYPE_U 0x00008000L /* Upper */ 63 #define _CTYPE_X 0x00010000L /* X digit */ 64 #define _CTYPE_B 0x00020000L /* Blank */ 65 #define _CTYPE_R 0x00040000L /* Print */ 66 #define _CTYPE_I 0x00080000L /* Ideogram */ 67 #define _CTYPE_T 0x00100000L /* Special */ 68 #define _CTYPE_Q 0x00200000L /* Phonogram */ 69 70 __BEGIN_DECLS 71 int isalnum __P((int)); 72 int isalpha __P((int)); 73 int iscntrl __P((int)); 74 int isdigit __P((int)); 75 int isgraph __P((int)); 76 int islower __P((int)); 77 int isprint __P((int)); 78 int ispunct __P((int)); 79 int isspace __P((int)); 80 int isupper __P((int)); 81 int isxdigit __P((int)); 82 int tolower __P((int)); 83 int toupper __P((int)); 84 85 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 86 int digittoint __P((int)); 87 int isascii __P((int)); 88 int isblank __P((int)); 89 int ishexnumber __P((int)); 90 int isideogram __P((int)); 91 int isnumber __P((int)); 92 int isphonogram __P((int)); 93 int isrune __P((int)); 94 int isspecial __P((int)); 95 int toascii __P((int)); 96 #endif 97 __END_DECLS 98 99 #define __istype(c,f) (!!__maskrune((c),(f))) 100 101 #define isalnum(c) __istype((c), _CTYPE_A|_CTYPE_D) 102 #define isalpha(c) __istype((c), _CTYPE_A) 103 #define iscntrl(c) __istype((c), _CTYPE_C) 104 #define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */ 105 #define isgraph(c) __istype((c), _CTYPE_G) 106 #define islower(c) __istype((c), _CTYPE_L) 107 #define isprint(c) __istype((c), _CTYPE_R) 108 #define ispunct(c) __istype((c), _CTYPE_P) 109 #define isspace(c) __istype((c), _CTYPE_S) 110 #define isupper(c) __istype((c), _CTYPE_U) 111 #define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */ 112 #define tolower(c) __tolower(c) 113 #define toupper(c) __toupper(c) 114 115 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 116 #define digittoint(c) __maskrune((c), 0xFF) 117 #define isascii(c) (((c) & ~0x7F) == 0) 118 #define isblank(c) __istype((c), _CTYPE_B) 119 #define ishexnumber(c) __istype((c), _CTYPE_X) 120 #define isideogram(c) __istype((c), _CTYPE_I) 121 #define isnumber(c) __istype((c), _CTYPE_D) 122 #define isphonogram(c) __istype((c), _CTYPE_Q) 123 #define isrune(c) __istype((c), 0xFFFFFF00L) 124 #define isspecial(c) __istype((c), _CTYPE_T) 125 #define toascii(c) ((c) & 0x7F) 126 #endif 127 128 /* See comments in <machine/ansi.h> about _BSD_CT_RUNE_T_. */ 129 __BEGIN_DECLS 130 unsigned long ___runetype __P((_BSD_CT_RUNE_T_)); 131 _BSD_CT_RUNE_T_ ___tolower __P((_BSD_CT_RUNE_T_)); 132 _BSD_CT_RUNE_T_ ___toupper __P((_BSD_CT_RUNE_T_)); 133 __END_DECLS 134 135 /* 136 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us 137 * to generate code for extern versions of all our inline functions. 138 */ 139 #ifdef _EXTERNALIZE_CTYPE_INLINES_ 140 #define _USE_CTYPE_INLINE_ 141 #define static 142 #define __inline 143 #endif 144 145 /* 146 * Use inline functions if we are allowed to and the compiler supports them. 147 */ 148 #if !defined(_DONT_USE_CTYPE_INLINE_) && \ 149 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) 150 static __inline int 151 __maskrune(_BSD_CT_RUNE_T_ _c, unsigned long _f) 152 { 153 return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : 154 _CurrentRuneLocale->runetype[_c]) & _f; 155 } 156 157 static __inline int 158 __isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f) 159 { 160 return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : 161 !!(_DefaultRuneLocale.runetype[_c] & _f); 162 } 163 164 static __inline _BSD_CT_RUNE_T_ 165 __toupper(_BSD_CT_RUNE_T_ _c) 166 { 167 return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : 168 _CurrentRuneLocale->mapupper[_c]; 169 } 170 171 static __inline _BSD_CT_RUNE_T_ 172 __tolower(_BSD_CT_RUNE_T_ _c) 173 { 174 return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : 175 _CurrentRuneLocale->maplower[_c]; 176 } 177 178 #else /* not using inlines */ 179 180 __BEGIN_DECLS 181 int __maskrune __P((_BSD_CT_RUNE_T_, unsigned long)); 182 int __isctype __P((_BSD_CT_RUNE_T_, unsigned long)); 183 _BSD_CT_RUNE_T_ __toupper __P((_BSD_CT_RUNE_T_)); 184 _BSD_CT_RUNE_T_ __tolower __P((_BSD_CT_RUNE_T_)); 185 __END_DECLS 186 #endif /* using inlines */ 187 188 #endif /* !_CTYPE_H_ */ 189