_ctype.h revision 1539
11539Srgrimes/* 21539Srgrimes * Copyright (c) 1989, 1993 31539Srgrimes * The Regents of the University of California. All rights reserved. 41539Srgrimes * (c) UNIX System Laboratories, Inc. 51539Srgrimes * All or some portions of this file are derived from material licensed 61539Srgrimes * to the University of California by American Telephone and Telegraph 71539Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81539Srgrimes * the permission of UNIX System Laboratories, Inc. 91539Srgrimes * 101539Srgrimes * This code is derived from software contributed to Berkeley by 111539Srgrimes * Paul Borman at Krystal Technologies. 121539Srgrimes * 131539Srgrimes * Redistribution and use in source and binary forms, with or without 141539Srgrimes * modification, are permitted provided that the following conditions 151539Srgrimes * are met: 161539Srgrimes * 1. Redistributions of source code must retain the above copyright 171539Srgrimes * notice, this list of conditions and the following disclaimer. 181539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 191539Srgrimes * notice, this list of conditions and the following disclaimer in the 201539Srgrimes * documentation and/or other materials provided with the distribution. 211539Srgrimes * 3. All advertising materials mentioning features or use of this software 221539Srgrimes * must display the following acknowledgement: 231539Srgrimes * This product includes software developed by the University of 241539Srgrimes * California, Berkeley and its contributors. 251539Srgrimes * 4. Neither the name of the University nor the names of its contributors 261539Srgrimes * may be used to endorse or promote products derived from this software 271539Srgrimes * without specific prior written permission. 281539Srgrimes * 291539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 301539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 311539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 321539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 331539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 341539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 351539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 361539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 371539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 381539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 391539Srgrimes * SUCH DAMAGE. 401539Srgrimes * 411539Srgrimes * @(#)ctype.h 8.4 (Berkeley) 1/21/94 421539Srgrimes */ 431539Srgrimes 441539Srgrimes#ifndef _CTYPE_H_ 451539Srgrimes#define _CTYPE_H_ 461539Srgrimes 471539Srgrimes#include <runetype.h> 481539Srgrimes 491539Srgrimes#define _A 0x00000100L /* Alpha */ 501539Srgrimes#define _C 0x00000200L /* Control */ 511539Srgrimes#define _D 0x00000400L /* Digit */ 521539Srgrimes#define _G 0x00000800L /* Graph */ 531539Srgrimes#define _L 0x00001000L /* Lower */ 541539Srgrimes#define _P 0x00002000L /* Punct */ 551539Srgrimes#define _S 0x00004000L /* Space */ 561539Srgrimes#define _U 0x00008000L /* Upper */ 571539Srgrimes#define _X 0x00010000L /* X digit */ 581539Srgrimes#define _B 0x00020000L /* Blank */ 591539Srgrimes#define _R 0x00040000L /* Print */ 601539Srgrimes#define _I 0x00080000L /* Ideogram */ 611539Srgrimes#define _T 0x00100000L /* Special */ 621539Srgrimes#define _Q 0x00200000L /* Phonogram */ 631539Srgrimes 641539Srgrimes#define isalnum(c) __istype((c), (_A|_D)) 651539Srgrimes#define isalpha(c) __istype((c), _A) 661539Srgrimes#define iscntrl(c) __istype((c), _C) 671539Srgrimes#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */ 681539Srgrimes#define isgraph(c) __istype((c), _G) 691539Srgrimes#define islower(c) __istype((c), _L) 701539Srgrimes#define isprint(c) __istype((c), _R) 711539Srgrimes#define ispunct(c) __istype((c), _P) 721539Srgrimes#define isspace(c) __istype((c), _S) 731539Srgrimes#define isupper(c) __istype((c), _U) 741539Srgrimes#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */ 751539Srgrimes 761539Srgrimes#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 771539Srgrimes#define isascii(c) ((c & ~0x7F) == 0) 781539Srgrimes#define toascii(c) ((c) & 0x7F) 791539Srgrimes#define digittoint(c) __istype((c), 0xFF) 801539Srgrimes#define isideogram(c) __istype((c), _I) 811539Srgrimes#define isphonogram(c) __istype((c), _T) 821539Srgrimes#define isspecial(c) __istype((c), _Q) 831539Srgrimes#define isblank(c) __istype((c), _B) 841539Srgrimes#define isrune(c) __istype((c), 0xFFFFFF00L) 851539Srgrimes#define isnumber(c) __istype((c), _D) 861539Srgrimes#define ishexnumber(c) __istype((c), _X) 871539Srgrimes#endif 881539Srgrimes 891539Srgrimes/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */ 901539Srgrimes__BEGIN_DECLS 911539Srgrimesunsigned long ___runetype __P((_BSD_RUNE_T_)); 921539Srgrimes_BSD_RUNE_T_ ___tolower __P((_BSD_RUNE_T_)); 931539Srgrimes_BSD_RUNE_T_ ___toupper __P((_BSD_RUNE_T_)); 941539Srgrimes__END_DECLS 951539Srgrimes 961539Srgrimes/* 971539Srgrimes * If your compiler supports prototypes and inline functions, 981539Srgrimes * #define _USE_CTYPE_INLINE_. Otherwise, use the C library 991539Srgrimes * functions. 1001539Srgrimes */ 1011539Srgrimes#if !defined(_USE_CTYPE_CLIBRARY_) && defined(__GNUC__) || defined(__cplusplus) 1021539Srgrimes#define _USE_CTYPE_INLINE_ 1 1031539Srgrimes#endif 1041539Srgrimes 1051539Srgrimes#if defined(_USE_CTYPE_INLINE_) 1061539Srgrimesstatic __inline int 1071539Srgrimes__istype(_BSD_RUNE_T_ c, unsigned long f) 1081539Srgrimes{ 1091539Srgrimes return((((c & _CRMASK) ? ___runetype(c) : 1101539Srgrimes _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0); 1111539Srgrimes} 1121539Srgrimes 1131539Srgrimesstatic __inline int 1141539Srgrimes__isctype(_BSD_RUNE_T_ c, unsigned long f) 1151539Srgrimes{ 1161539Srgrimes return((((c & _CRMASK) ? 0 : 1171539Srgrimes _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0); 1181539Srgrimes} 1191539Srgrimes 1201539Srgrimes/* _ANSI_LIBRARY is defined by lib/libc/gen/isctype.c. */ 1211539Srgrimes#if !defined(_ANSI_LIBRARY) 1221539Srgrimesstatic __inline _BSD_RUNE_T_ 1231539Srgrimestoupper(_BSD_RUNE_T_ c) 1241539Srgrimes{ 1251539Srgrimes return((c & _CRMASK) ? 1261539Srgrimes ___toupper(c) : _CurrentRuneLocale->mapupper[c]); 1271539Srgrimes} 1281539Srgrimes 1291539Srgrimesstatic __inline _BSD_RUNE_T_ 1301539Srgrimestolower(_BSD_RUNE_T_ c) 1311539Srgrimes{ 1321539Srgrimes return((c & _CRMASK) ? 1331539Srgrimes ___tolower(c) : _CurrentRuneLocale->maplower[c]); 1341539Srgrimes} 1351539Srgrimes#endif /* !_ANSI_LIBRARY */ 1361539Srgrimes 1371539Srgrimes#else /* !_USE_CTYPE_INLINE_ */ 1381539Srgrimes 1391539Srgrimes__BEGIN_DECLS 1401539Srgrimesint __istype __P((_BSD_RUNE_T_, unsigned long)); 1411539Srgrimesint __isctype __P((_BSD_RUNE_T_, unsigned long)); 1421539Srgrimes_BSD_RUNE_T_ toupper __P((_BSD_RUNE_T_)); 1431539Srgrimes_BSD_RUNE_T_ tolower __P((_BSD_RUNE_T_)); 1441539Srgrimes__END_DECLS 1451539Srgrimes#endif /* _USE_CTYPE_INLINE_ */ 1461539Srgrimes 1471539Srgrimes#endif /* !_CTYPE_H_ */ 148