ctype.h revision 3433
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 */ 43 44#ifndef _CTYPE_H_ 45#define _CTYPE_H_ 46 47#include <runetype.h> 48 49#define _A 0x00000100L /* Alpha */ 50#define _C 0x00000200L /* Control */ 51#define _D 0x00000400L /* Digit */ 52#define _G 0x00000800L /* Graph */ 53#define _L 0x00001000L /* Lower */ 54#define _P 0x00002000L /* Punct */ 55#define _S 0x00004000L /* Space */ 56#define _U 0x00008000L /* Upper */ 57#define _X 0x00010000L /* X digit */ 58#define _B 0x00020000L /* Blank */ 59#define _R 0x00040000L /* Print */ 60#define _I 0x00080000L /* Ideogram */ 61#define _T 0x00100000L /* Special */ 62#define _Q 0x00200000L /* Phonogram */ 63 64#define isalnum(c) __istype((c), (_A|_D)) 65#define isalpha(c) __istype((c), _A) 66#define iscntrl(c) __istype((c), _C) 67#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */ 68#define isgraph(c) __istype((c), _G) 69#define islower(c) __istype((c), _L) 70#define isprint(c) __istype((c), _R) 71#define ispunct(c) __istype((c), _P) 72#define isspace(c) __istype((c), _S) 73#define isupper(c) __istype((c), _U) 74#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */ 75 76#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 77#define isascii(c) ((c & ~0x7F) == 0) 78#define toascii(c) ((c) & 0x7F) 79#define digittoint(c) __istype((c), 0xFF) 80#define isideogram(c) __istype((c), _I) 81#define isphonogram(c) __istype((c), _T) 82#define isspecial(c) __istype((c), _Q) 83#define isblank(c) __istype((c), _B) 84#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_) 106 107#ifndef EOF 108#define EOF (-1) 109#endif 110 111static __inline int 112__istype(_BSD_RUNE_T_ c, unsigned long f) 113{ 114 if (c == EOF) 115 return 0; 116 if (c < 0) 117 c = (unsigned char) c; 118 return((((c & _CRMASK) ? ___runetype(c) : 119 _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0); 120} 121 122static __inline int 123__isctype(_BSD_RUNE_T_ c, unsigned long f) 124{ 125 if (c == EOF) 126 return 0; 127 if (c < 0) 128 c = (unsigned char) c; 129 return((((c & _CRMASK) ? 0 : 130 _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0); 131} 132 133/* _ANSI_LIBRARY is defined by lib/libc/gen/isctype.c. */ 134#if !defined(_ANSI_LIBRARY) 135static __inline _BSD_RUNE_T_ 136toupper(_BSD_RUNE_T_ c) 137{ 138 if (c == EOF) 139 return EOF; 140 if (c < 0) 141 c = (unsigned char) c; 142 return((c & _CRMASK) ? 143 ___toupper(c) : _CurrentRuneLocale->mapupper[c]); 144} 145 146static __inline _BSD_RUNE_T_ 147tolower(_BSD_RUNE_T_ c) 148{ 149 if (c == EOF) 150 return EOF; 151 if (c < 0) 152 c = (unsigned char) c; 153 return((c & _CRMASK) ? 154 ___tolower(c) : _CurrentRuneLocale->maplower[c]); 155} 156#endif /* !_ANSI_LIBRARY */ 157 158#else /* !_USE_CTYPE_INLINE_ */ 159 160__BEGIN_DECLS 161int __istype __P((_BSD_RUNE_T_, unsigned long)); 162int __isctype __P((_BSD_RUNE_T_, unsigned long)); 163_BSD_RUNE_T_ toupper __P((_BSD_RUNE_T_)); 164_BSD_RUNE_T_ tolower __P((_BSD_RUNE_T_)); 165__END_DECLS 166#endif /* _USE_CTYPE_INLINE_ */ 167 168#endif /* !_CTYPE_H_ */ 169