_ctype.h revision 7655
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 3217987Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3350471Speter * 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 381556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 391556Srgrimes * SUCH DAMAGE. 4046684Skris * 411556Srgrimes * @(#)ctype.h 8.4 (Berkeley) 1/21/94 421556Srgrimes */ 431556Srgrimes 441556Srgrimes#ifndef _CTYPE_H_ 451556Srgrimes#define _CTYPE_H_ 461556Srgrimes 4738521Scracauer/* 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 */ 5438530Scracauer#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 */ 6020425Ssteve#define _U 0x00008000L /* Upper */ 611556Srgrimes#define _X 0x00010000L /* X digit */ 621556Srgrimes#define _B 0x00020000L /* Blank */ 631556Srgrimes#define _R 0x00040000L /* Print */ 641556Srgrimes#define _I 0x00080000L /* Ideogram */ 651556Srgrimes#define _T 0x00100000L /* Special */ 661556Srgrimes#define _Q 0x00200000L /* Phonogram */ 671556Srgrimes 681556Srgrimes__BEGIN_DECLS 691556Srgrimesint isalnum __P((int)); 7038521Scracauerint isalpha __P((int)); 7138521Scracauerint iscntrl __P((int)); 721556Srgrimesint isdigit __P((int)); 731556Srgrimesint isgraph __P((int)); 7417987Speterint islower __P((int)); 75199660Sjillesint isprint __P((int)); 76199660Sjillesint ispunct __P((int)); 771556Srgrimesint isspace __P((int)); 781556Srgrimesint isupper __P((int)); 791556Srgrimesint isxdigit __P((int)); 801556Srgrimesint tolower __P((int)); 81200967Sjillesint toupper __P((int)); 8290111Simp 83216622Sjilles#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 84200967Sjillesint isascii __P((int)); 85200967Sjillesint isblank __P((int)); 861556Srgrimesint toascii __P((int)); 871556Srgrimes#endif 881556Srgrimes__END_DECLS 891556Srgrimes 901556Srgrimes#define isalnum(c) __istype((c), (_A|_D)) 911556Srgrimes#define isalpha(c) __istype((c), _A) 921556Srgrimes#define iscntrl(c) __istype((c), _C) 931556Srgrimes#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */ 941556Srgrimes#define isgraph(c) __istype((c), _G) 95#define islower(c) __istype((c), _L) 96#define isprint(c) __istype((c), _R) 97#define ispunct(c) __istype((c), _P) 98#define isspace(c) __istype((c), _S) 99#define isupper(c) __istype((c), _U) 100#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */ 101#define tolower(c) __tolower(c) 102#define toupper(c) __toupper(c) 103 104#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 105#define isascii(c) (((c) & ~0x7F) == 0) 106#define isblank(c) __istype((c), _B) 107#define toascii(c) ((c) & 0x7F) 108 109/* XXX the following macros are not backed up by functions. */ 110#define digittoint(c) __istype((c), 0xFF) 111#define ishexnumber(c) __istype((c), _X) 112#define isideogram(c) __istype((c), _I) 113#define isnumber(c) __istype((c), _D) 114#define isphonogram(c) __istype((c), _T) 115#define isrune(c) __istype((c), 0xFFFFFF00L) 116#define isspecial(c) __istype((c), _Q) 117#endif 118 119/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */ 120__BEGIN_DECLS 121unsigned long ___runetype __P((_BSD_RUNE_T_)); 122_BSD_RUNE_T_ ___tolower __P((_BSD_RUNE_T_)); 123_BSD_RUNE_T_ ___toupper __P((_BSD_RUNE_T_)); 124__END_DECLS 125 126/* 127 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us 128 * to generate code for extern versions of all our inline functions. 129 */ 130#ifdef _EXTERNALIZE_CTYPE_INLINES_ 131#define _USE_CTYPE_INLINE_ 132#define static 133#define __inline 134#endif 135 136/* 137 * Use inline functions if we are allowed to and the compiler supports them. 138 */ 139#if !defined(_DONT_USE_CTYPE_INLINE_) && \ 140 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) 141static __inline int 142__istype(_BSD_RUNE_T_ _c, unsigned long _f) 143{ 144 if (_c < 0) 145 _c = (unsigned char) _c; 146 return((((_c & _CRMASK) ? ___runetype(_c) : 147 _CurrentRuneLocale->runetype[_c]) & _f) ? 1 : 0); 148} 149 150static __inline int 151__isctype(_BSD_RUNE_T_ _c, unsigned long _f) 152{ 153 if (_c < 0) 154 _c = (unsigned char) _c; 155 return((((_c & _CRMASK) ? 0 : 156 _DefaultRuneLocale.runetype[_c]) & _f) ? 1 : 0); 157} 158 159static __inline _BSD_RUNE_T_ 160__toupper(_BSD_RUNE_T_ _c) 161{ 162 if (_c < 0) 163 _c = (unsigned char) _c; 164 return((_c & _CRMASK) ? 165 ___toupper(_c) : _CurrentRuneLocale->mapupper[_c]); 166} 167 168static __inline _BSD_RUNE_T_ 169__tolower(_BSD_RUNE_T_ _c) 170{ 171 if (_c < 0) 172 _c = (unsigned char) _c; 173 return((_c & _CRMASK) ? 174 ___tolower(_c) : _CurrentRuneLocale->maplower[_c]); 175} 176 177#else /* not using inlines */ 178 179__BEGIN_DECLS 180int __istype __P((_BSD_RUNE_T_, unsigned long)); 181int __isctype __P((_BSD_RUNE_T_, unsigned long)); 182_BSD_RUNE_T_ __toupper __P((_BSD_RUNE_T_)); 183_BSD_RUNE_T_ __tolower __P((_BSD_RUNE_T_)); 184__END_DECLS 185#endif /* using inlines */ 186 187#endif /* !_CTYPE_H_ */ 188