_ctype.h revision 29818
11556Srgrimes/* 21556Srgrimes * Copyright (c) 1989, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * (c) UNIX System Laboratories, Inc. 51556Srgrimes * All or some portions of this file are derived from material licensed 61556Srgrimes * to the University of California by American Telephone and Telegraph 71556Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81556Srgrimes * the permission of UNIX System Laboratories, Inc. 91556Srgrimes * 101556Srgrimes * This code is derived from software contributed to Berkeley by 111556Srgrimes * Paul Borman at Krystal Technologies. 121556Srgrimes * 131556Srgrimes * Redistribution and use in source and binary forms, with or without 141556Srgrimes * modification, are permitted provided that the following conditions 151556Srgrimes * are met: 161556Srgrimes * 1. Redistributions of source code must retain the above copyright 171556Srgrimes * notice, this list of conditions and the following disclaimer. 181556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 191556Srgrimes * notice, this list of conditions and the following disclaimer in the 201556Srgrimes * documentation and/or other materials provided with the distribution. 211556Srgrimes * 3. All advertising materials mentioning features or use of this software 221556Srgrimes * must display the following acknowledgement: 231556Srgrimes * This product includes software developed by the University of 241556Srgrimes * California, Berkeley and its contributors. 251556Srgrimes * 4. Neither the name of the University nor the names of its contributors 261556Srgrimes * may be used to endorse or promote products derived from this software 271556Srgrimes * without specific prior written permission. 281556Srgrimes * 291556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 301556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 311556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 321556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 331556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 341556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 351556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 361556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 371556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3836150Scharnier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3936150Scharnier * SUCH DAMAGE. 4036150Scharnier * 4136150Scharnier * @(#)ctype.h 8.4 (Berkeley) 1/21/94 4250471Speter */ 431556Srgrimes 441556Srgrimes#ifndef _CTYPE_H_ 4517987Speter#define _CTYPE_H_ 4617987Speter 471556Srgrimes/* 481556Srgrimes * XXX <runetype.h> brings massive namespace pollution (rune_t and struct 491556Srgrimes * member names). 501556Srgrimes */ 511556Srgrimes#include <runetype.h> 521556Srgrimes 531556Srgrimes#define _A 0x00000100L /* Alpha */ 541556Srgrimes#define _C 0x00000200L /* Control */ 551556Srgrimes#define _D 0x00000400L /* Digit */ 561556Srgrimes#define _G 0x00000800L /* Graph */ 571556Srgrimes#define _L 0x00001000L /* Lower */ 581556Srgrimes#define _P 0x00002000L /* Punct */ 591556Srgrimes#define _S 0x00004000L /* Space */ 601556Srgrimes#define _U 0x00008000L /* Upper */ 6117987Speter#define _X 0x00010000L /* X digit */ 6259436Scracauer#define _B 0x00020000L /* Blank */ 6317987Speter#define _R 0x00040000L /* Print */ 641556Srgrimes#define _I 0x00080000L /* Ideogram */ 6517987Speter#define _T 0x00100000L /* Special */ 661556Srgrimes#define _Q 0x00200000L /* Phonogram */ 671556Srgrimes 681556Srgrimes__BEGIN_DECLS 691556Srgrimesint isalnum __P((int)); 701556Srgrimesint isalpha __P((int)); 711556Srgrimesint iscntrl __P((int)); 721556Srgrimesint isdigit __P((int)); 731556Srgrimesint isgraph __P((int)); 7417987Speterint islower __P((int)); 751556Srgrimesint isprint __P((int)); 761556Srgrimesint ispunct __P((int)); 771556Srgrimesint isspace __P((int)); 781556Srgrimesint isupper __P((int)); 791556Srgrimesint isxdigit __P((int)); 801556Srgrimesint tolower __P((int)); 811556Srgrimesint toupper __P((int)); 821556Srgrimes 831556Srgrimes#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 841556Srgrimesint isascii __P((int)); 851556Srgrimesint isblank __P((int)); 861556Srgrimesint toascii __P((int)); 871556Srgrimesint digittoint __P((int)); 881556Srgrimes#endif 891556Srgrimes__END_DECLS 901556Srgrimes 911556Srgrimes#define isalnum(c) __istype((c), (_A|_D)) 921556Srgrimes#define isalpha(c) __istype((c), _A) 931556Srgrimes#define iscntrl(c) __istype((c), _C) 941556Srgrimes#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */ 951556Srgrimes#define isgraph(c) __istype((c), _G) 961556Srgrimes#define islower(c) __istype((c), _L) 971556Srgrimes#define isprint(c) __istype((c), _R) 981556Srgrimes#define ispunct(c) __istype((c), _P) 991556Srgrimes#define isspace(c) __istype((c), _S) 1001556Srgrimes#define isupper(c) __istype((c), _U) 10118018Speter#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */ 10218018Speter#define tolower(c) __tolower(c) 1031556Srgrimes#define toupper(c) __toupper(c) 1041556Srgrimes 1051556Srgrimes#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 1061556Srgrimes#define isascii(c) (((c) & ~0x7F) == 0) 1071556Srgrimes#define isblank(c) __istype((c), _B) 1081556Srgrimes#define toascii(c) ((c) & 0x7F) 1091556Srgrimes#define digittoint(c) (__maskrune((c), 0xFF)) 1101556Srgrimes 1111556Srgrimes/* XXX the following macros are not backed up by functions. */ 1121556Srgrimes#define ishexnumber(c) __istype((c), _X) 1131556Srgrimes#define isideogram(c) __istype((c), _I) 1141556Srgrimes#define isnumber(c) __istype((c), _D) 1151556Srgrimes#define isphonogram(c) __istype((c), _Q) 11617987Speter#define isrune(c) __istype((c), 0xFFFFFF00L) 1171556Srgrimes#define isspecial(c) __istype((c), _T) 1181556Srgrimes#endif 11917987Speter 1201556Srgrimes/* See comments in <machine/ansi.h> about _BSD_CT_RUNE_T_. */ 12117987Speter__BEGIN_DECLS 1221556Srgrimesunsigned long ___runetype __P((_BSD_CT_RUNE_T_)); 1231556Srgrimes_BSD_CT_RUNE_T_ ___tolower __P((_BSD_CT_RUNE_T_)); 1241556Srgrimes_BSD_CT_RUNE_T_ ___toupper __P((_BSD_CT_RUNE_T_)); 1251556Srgrimes__END_DECLS 12620425Ssteve 1271556Srgrimes/* 12817987Speter * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us 1291556Srgrimes * to generate code for extern versions of all our inline functions. 1301556Srgrimes */ 1311556Srgrimes#ifdef _EXTERNALIZE_CTYPE_INLINES_ 1321556Srgrimes#define _USE_CTYPE_INLINE_ 1331556Srgrimes#define static 1341556Srgrimes#define __inline 13520425Ssteve#endif 13617987Speter 13717987Speter/* 1381556Srgrimes * Use inline functions if we are allowed to and the compiler supports them. 1391556Srgrimes */ 14060593Scracauer#if !defined(_DONT_USE_CTYPE_INLINE_) && \ 1411556Srgrimes (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) 1421556Srgrimesstatic __inline int 1431556Srgrimes__istype(_BSD_CT_RUNE_T_ _c, unsigned long _f) 1441556Srgrimes{ 1451556Srgrimes return (_c < 0 || _c >= _CACHED_RUNES) ? !!(___runetype(_c) & _f) : 1461556Srgrimes !!(_CurrentRuneLocale->runetype[_c] & _f); 1471556Srgrimes} 1481556Srgrimes 1491556Srgrimesstatic __inline int 1501556Srgrimes__isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f) 1511556Srgrimes{ 1521556Srgrimes return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : 1531556Srgrimes !!(_DefaultRuneLocale.runetype[_c] & _f); 1541556Srgrimes} 1551556Srgrimes 1561556Srgrimesstatic __inline _BSD_CT_RUNE_T_ 1571556Srgrimes__toupper(_BSD_CT_RUNE_T_ _c) 15820425Ssteve{ 15917987Speter return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : 16017987Speter _CurrentRuneLocale->mapupper[_c]; 1611556Srgrimes} 16217987Speter 1631556Srgrimesstatic __inline _BSD_CT_RUNE_T_ 1641556Srgrimes__tolower(_BSD_CT_RUNE_T_ _c) 1651556Srgrimes{ 1661556Srgrimes return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : 16717987Speter _CurrentRuneLocale->maplower[_c]; 1681556Srgrimes} 16917987Speter 17017987Speterstatic __inline int 17117987Speter__maskrune(_BSD_RUNE_T_ c, unsigned long f) 17217987Speter{ 17317987Speter return(((c & _CRMASK) 17417987Speter ? ___runetype(c) : _CurrentRuneLocale->runetype[c]) & f); 17517987Speter} 17617987Speter 17717987Speter#else /* not using inlines */ 17817987Speter 17917987Speter__BEGIN_DECLS 18017987Speterint __istype __P((_BSD_CT_RUNE_T_, unsigned long)); 18117987Speterint __isctype __P((_BSD_CT_RUNE_T_, unsigned long)); 18217987Speterint __maskrune __P((_BSD_CT_RUNE_T_, unsigned long)); 18317987Speter_BSD_CT_RUNE_T_ __toupper __P((_BSD_CT_RUNE_T_)); 18417987Speter_BSD_CT_RUNE_T_ __tolower __P((_BSD_CT_RUNE_T_)); 18517987Speter__END_DECLS 18617987Speter#endif /* using inlines */ 18717987Speter 18817987Speter#endif /* !_CTYPE_H_ */ 18917987Speter