_ctype.h revision 7655
11553Srgrimes/* 21553Srgrimes * Copyright (c) 1989, 1993 31553Srgrimes * The Regents of the University of California. All rights reserved. 41553Srgrimes * (c) UNIX System Laboratories, Inc. 51553Srgrimes * All or some portions of this file are derived from material licensed 61553Srgrimes * to the University of California by American Telephone and Telegraph 71553Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81553Srgrimes * the permission of UNIX System Laboratories, Inc. 91553Srgrimes * 101553Srgrimes * This code is derived from software contributed to Berkeley by 111553Srgrimes * Paul Borman at Krystal Technologies. 121553Srgrimes * 131553Srgrimes * Redistribution and use in source and binary forms, with or without 141553Srgrimes * modification, are permitted provided that the following conditions 151553Srgrimes * are met: 161553Srgrimes * 1. Redistributions of source code must retain the above copyright 171553Srgrimes * notice, this list of conditions and the following disclaimer. 181553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 191553Srgrimes * notice, this list of conditions and the following disclaimer in the 201553Srgrimes * documentation and/or other materials provided with the distribution. 211553Srgrimes * 3. All advertising materials mentioning features or use of this software 221553Srgrimes * must display the following acknowledgement: 231553Srgrimes * This product includes software developed by the University of 241553Srgrimes * California, Berkeley and its contributors. 251553Srgrimes * 4. Neither the name of the University nor the names of its contributors 261553Srgrimes * may be used to endorse or promote products derived from this software 271553Srgrimes * without specific prior written permission. 281553Srgrimes * 291553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 301553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 311553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 321553Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 331553Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 341553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 351553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 361553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 371553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 381553Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39117541Sgad * SUCH DAMAGE. 40117592Sgad * 4115648Sjoerg * @(#)ctype.h 8.4 (Berkeley) 1/21/94 42117592Sgad */ 43117541Sgad 44117592Sgad#ifndef _CTYPE_H_ 45117541Sgad#define _CTYPE_H_ 46117541Sgad 471553Srgrimes/* 481553Srgrimes * XXX <runetype.h> brings massive namespace pollution (rune_t and struct 491553Srgrimes * member names). 5015648Sjoerg */ 5168253Sgad#include <runetype.h> 521553Srgrimes 53139464Sgad#define _A 0x00000100L /* Alpha */ 541553Srgrimes#define _C 0x00000200L /* Control */ 5598152Sgad#define _D 0x00000400L /* Digit */ 5668253Sgad#define _G 0x00000800L /* Graph */ 5731492Swollman#define _L 0x00001000L /* Lower */ 581553Srgrimes#define _P 0x00002000L /* Punct */ 591553Srgrimes#define _S 0x00004000L /* Space */ 6031492Swollman#define _U 0x00008000L /* Upper */ 6131492Swollman#define _X 0x00010000L /* X digit */ 621553Srgrimes#define _B 0x00020000L /* Blank */ 6331492Swollman#define _R 0x00040000L /* Print */ 641553Srgrimes#define _I 0x00080000L /* Ideogram */ 651553Srgrimes#define _T 0x00100000L /* Special */ 661553Srgrimes#define _Q 0x00200000L /* Phonogram */ 671553Srgrimes 681553Srgrimes__BEGIN_DECLS 691553Srgrimesint isalnum __P((int)); 7078280Sgadint isalpha __P((int)); 711553Srgrimesint iscntrl __P((int)); 7227618Simpint isdigit __P((int)); 7327618Simpint isgraph __P((int)); 7478146Sgadint islower __P((int)); 751553Srgrimesint isprint __P((int)); 761553Srgrimesint ispunct __P((int)); 77139464Sgadint isspace __P((int)); 78139464Sgadint isupper __P((int)); 79139464Sgadint isxdigit __P((int)); 80139464Sgadint tolower __P((int)); 81139464Sgadint toupper __P((int)); 82139464Sgad 83139464Sgad#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 841553Srgrimesint isascii __P((int)); 851553Srgrimesint isblank __P((int)); 861553Srgrimesint toascii __P((int)); 871553Srgrimes#endif 881553Srgrimes__END_DECLS 8978146Sgad 901553Srgrimes#define isalnum(c) __istype((c), (_A|_D)) 911553Srgrimes#define isalpha(c) __istype((c), _A) 921553Srgrimes#define iscntrl(c) __istype((c), _C) 9339084Swollman#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */ 941553Srgrimes#define isgraph(c) __istype((c), _G) 9580172Sgad#define islower(c) __istype((c), _L) 961553Srgrimes#define isprint(c) __istype((c), _R) 971553Srgrimes#define ispunct(c) __istype((c), _P) 981553Srgrimes#define isspace(c) __istype((c), _S) 991553Srgrimes#define isupper(c) __istype((c), _U) 1001553Srgrimes#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */ 1011553Srgrimes#define tolower(c) __tolower(c) 10280172Sgad#define toupper(c) __toupper(c) 10380172Sgad 1041553Srgrimes#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 1051553Srgrimes#define isascii(c) (((c) & ~0x7F) == 0) 1061553Srgrimes#define isblank(c) __istype((c), _B) 1071553Srgrimes#define toascii(c) ((c) & 0x7F) 1081553Srgrimes 1091553Srgrimes/* XXX the following macros are not backed up by functions. */ 1101553Srgrimes#define digittoint(c) __istype((c), 0xFF) 1111553Srgrimes#define ishexnumber(c) __istype((c), _X) 1121553Srgrimes#define isideogram(c) __istype((c), _I) 1131553Srgrimes#define isnumber(c) __istype((c), _D) 1141553Srgrimes#define isphonogram(c) __istype((c), _T) 1151553Srgrimes#define isrune(c) __istype((c), 0xFFFFFF00L) 1161553Srgrimes#define isspecial(c) __istype((c), _Q) 1171553Srgrimes#endif 1181553Srgrimes 11978146Sgad/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */ 1201553Srgrimes__BEGIN_DECLS 1211553Srgrimesunsigned long ___runetype __P((_BSD_RUNE_T_)); 12268401Sgad_BSD_RUNE_T_ ___tolower __P((_BSD_RUNE_T_)); 12399842Sgad_BSD_RUNE_T_ ___toupper __P((_BSD_RUNE_T_)); 1241553Srgrimes__END_DECLS 1251553Srgrimes 12680172Sgad/* 1271553Srgrimes * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us 12827618Simp * to generate code for extern versions of all our inline functions. 12968740Sgad */ 13068740Sgad#ifdef _EXTERNALIZE_CTYPE_INLINES_ 13168739Sgad#define _USE_CTYPE_INLINE_ 13268740Sgad#define static 133235647Sgleb#define __inline 1341553Srgrimes#endif 13527618Simp 1361553Srgrimes/* 1371553Srgrimes * Use inline functions if we are allowed to and the compiler supports them. 1381553Srgrimes */ 13927618Simp#if !defined(_DONT_USE_CTYPE_INLINE_) && \ 1401553Srgrimes (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) 1411553Srgrimesstatic __inline int 14268401Sgad__istype(_BSD_RUNE_T_ _c, unsigned long _f) 1431553Srgrimes{ 1441553Srgrimes if (_c < 0) 1451553Srgrimes _c = (unsigned char) _c; 1461553Srgrimes return((((_c & _CRMASK) ? ___runetype(_c) : 1471553Srgrimes _CurrentRuneLocale->runetype[_c]) & _f) ? 1 : 0); 1481553Srgrimes} 1491553Srgrimes 15027618Simpstatic __inline int 15175253Sgad__isctype(_BSD_RUNE_T_ _c, unsigned long _f) 15275253Sgad{ 15375253Sgad if (_c < 0) 1541553Srgrimes _c = (unsigned char) _c; 15599842Sgad return((((_c & _CRMASK) ? 0 : 15699842Sgad _DefaultRuneLocale.runetype[_c]) & _f) ? 1 : 0); 15799842Sgad} 1581553Srgrimes 1591553Srgrimesstatic __inline _BSD_RUNE_T_ 16099842Sgad__toupper(_BSD_RUNE_T_ _c) 16199842Sgad{ 16268401Sgad if (_c < 0) 16368401Sgad _c = (unsigned char) _c; 1641553Srgrimes return((_c & _CRMASK) ? 1651553Srgrimes ___toupper(_c) : _CurrentRuneLocale->mapupper[_c]); 1661553Srgrimes} 1671553Srgrimes 1681553Srgrimesstatic __inline _BSD_RUNE_T_ 16915648Sjoerg__tolower(_BSD_RUNE_T_ _c) 17068401Sgad{ 17168739Sgad if (_c < 0) 1721553Srgrimes _c = (unsigned char) _c; 1731553Srgrimes return((_c & _CRMASK) ? 1741553Srgrimes ___tolower(_c) : _CurrentRuneLocale->maplower[_c]); 1751553Srgrimes} 1761553Srgrimes 1771553Srgrimes#else /* not using inlines */ 1781553Srgrimes 17968401Sgad__BEGIN_DECLS 1801553Srgrimesint __istype __P((_BSD_RUNE_T_, unsigned long)); 1811553Srgrimesint __isctype __P((_BSD_RUNE_T_, unsigned long)); 1821553Srgrimes_BSD_RUNE_T_ __toupper __P((_BSD_RUNE_T_)); 1831553Srgrimes_BSD_RUNE_T_ __tolower __P((_BSD_RUNE_T_)); 1841553Srgrimes__END_DECLS 18568740Sgad#endif /* using inlines */ 18668739Sgad 1871553Srgrimes#endif /* !_CTYPE_H_ */ 1881553Srgrimes