ctype.h revision 29818
155714Skris/* 255714Skris * Copyright (c) 1989, 1993 355714Skris * The Regents of the University of California. All rights reserved. 455714Skris * (c) UNIX System Laboratories, Inc. 555714Skris * All or some portions of this file are derived from material licensed 655714Skris * to the University of California by American Telephone and Telegraph 755714Skris * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8296465Sdelphij * the permission of UNIX System Laboratories, Inc. 955714Skris * 1055714Skris * This code is derived from software contributed to Berkeley by 1155714Skris * Paul Borman at Krystal Technologies. 1255714Skris * 1355714Skris * Redistribution and use in source and binary forms, with or without 1455714Skris * modification, are permitted provided that the following conditions 15296465Sdelphij * are met: 1655714Skris * 1. Redistributions of source code must retain the above copyright 1755714Skris * notice, this list of conditions and the following disclaimer. 1855714Skris * 2. Redistributions in binary form must reproduce the above copyright 1955714Skris * notice, this list of conditions and the following disclaimer in the 2055714Skris * documentation and/or other materials provided with the distribution. 2155714Skris * 3. All advertising materials mentioning features or use of this software 22296465Sdelphij * must display the following acknowledgement: 2355714Skris * This product includes software developed by the University of 2455714Skris * California, Berkeley and its contributors. 2555714Skris * 4. Neither the name of the University nor the names of its contributors 2655714Skris * may be used to endorse or promote products derived from this software 2755714Skris * without specific prior written permission. 2855714Skris * 2955714Skris * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 3055714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3155714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3255714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3355714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3455714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3555714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3655714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37296465Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3855714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3955714Skris * SUCH DAMAGE. 40296465Sdelphij * 4155714Skris * @(#)ctype.h 8.4 (Berkeley) 1/21/94 4255714Skris */ 4355714Skris 4455714Skris#ifndef _CTYPE_H_ 4555714Skris#define _CTYPE_H_ 4655714Skris 4755714Skris/* 4855714Skris * XXX <runetype.h> brings massive namespace pollution (rune_t and struct 4955714Skris * member names). 5055714Skris */ 5155714Skris#include <runetype.h> 52296465Sdelphij 5355714Skris#define _A 0x00000100L /* Alpha */ 5455714Skris#define _C 0x00000200L /* Control */ 5555714Skris#define _D 0x00000400L /* Digit */ 5655714Skris#define _G 0x00000800L /* Graph */ 5755714Skris#define _L 0x00001000L /* Lower */ 5855714Skris#define _P 0x00002000L /* Punct */ 5955714Skris#define _S 0x00004000L /* Space */ 6055714Skris#define _U 0x00008000L /* Upper */ 61109998Smarkm#define _X 0x00010000L /* X digit */ 62296465Sdelphij#define _B 0x00020000L /* Blank */ 63296465Sdelphij#define _R 0x00040000L /* Print */ 6455714Skris#define _I 0x00080000L /* Ideogram */ 65296465Sdelphij#define _T 0x00100000L /* Special */ 6655714Skris#define _Q 0x00200000L /* Phonogram */ 6755714Skris 68296465Sdelphij__BEGIN_DECLS 6955714Skrisint isalnum __P((int)); 70296465Sdelphijint isalpha __P((int)); 7155714Skrisint iscntrl __P((int)); 72296465Sdelphijint isdigit __P((int)); 73296465Sdelphijint isgraph __P((int)); 7455714Skrisint islower __P((int)); 75296465Sdelphijint isprint __P((int)); 76296465Sdelphijint ispunct __P((int)); 77296465Sdelphijint isspace __P((int)); 78296465Sdelphijint isupper __P((int)); 79296465Sdelphijint isxdigit __P((int)); 80296465Sdelphijint tolower __P((int)); 81296465Sdelphijint toupper __P((int)); 82296465Sdelphij 83296465Sdelphij#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 84296465Sdelphijint isascii __P((int)); 85296465Sdelphijint isblank __P((int)); 86296465Sdelphijint toascii __P((int)); 8755714Skrisint digittoint __P((int)); 88296465Sdelphij#endif 89296465Sdelphij__END_DECLS 90296465Sdelphij 91296465Sdelphij#define isalnum(c) __istype((c), (_A|_D)) 92296465Sdelphij#define isalpha(c) __istype((c), _A) 93296465Sdelphij#define iscntrl(c) __istype((c), _C) 9455714Skris#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */ 95296465Sdelphij#define isgraph(c) __istype((c), _G) 96296465Sdelphij#define islower(c) __istype((c), _L) 97296465Sdelphij#define isprint(c) __istype((c), _R) 98296465Sdelphij#define ispunct(c) __istype((c), _P) 99296465Sdelphij#define isspace(c) __istype((c), _S) 100296465Sdelphij#define isupper(c) __istype((c), _U) 101296465Sdelphij#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */ 102296465Sdelphij#define tolower(c) __tolower(c) 103296465Sdelphij#define toupper(c) __toupper(c) 104296465Sdelphij 105296465Sdelphij#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 106296465Sdelphij#define isascii(c) (((c) & ~0x7F) == 0) 107296465Sdelphij#define isblank(c) __istype((c), _B) 108296465Sdelphij#define toascii(c) ((c) & 0x7F) 109296465Sdelphij#define digittoint(c) (__maskrune((c), 0xFF)) 110296465Sdelphij 11155714Skris/* XXX the following macros are not backed up by functions. */ 112296465Sdelphij#define ishexnumber(c) __istype((c), _X) 113296465Sdelphij#define isideogram(c) __istype((c), _I) 114296465Sdelphij#define isnumber(c) __istype((c), _D) 115296465Sdelphij#define isphonogram(c) __istype((c), _Q) 116296465Sdelphij#define isrune(c) __istype((c), 0xFFFFFF00L) 117296465Sdelphij#define isspecial(c) __istype((c), _T) 11855714Skris#endif 119296465Sdelphij 12055714Skris/* See comments in <machine/ansi.h> about _BSD_CT_RUNE_T_. */ 121296465Sdelphij__BEGIN_DECLS 122296465Sdelphijunsigned long ___runetype __P((_BSD_CT_RUNE_T_)); 123296465Sdelphij_BSD_CT_RUNE_T_ ___tolower __P((_BSD_CT_RUNE_T_)); 124296465Sdelphij_BSD_CT_RUNE_T_ ___toupper __P((_BSD_CT_RUNE_T_)); 125296465Sdelphij__END_DECLS 126296465Sdelphij 127296465Sdelphij/* 128296465Sdelphij * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us 129296465Sdelphij * to generate code for extern versions of all our inline functions. 130296465Sdelphij */ 131296465Sdelphij#ifdef _EXTERNALIZE_CTYPE_INLINES_ 132296465Sdelphij#define _USE_CTYPE_INLINE_ 133296465Sdelphij#define static 134296465Sdelphij#define __inline 135296465Sdelphij#endif 136296465Sdelphij 13755714Skris/* 138296465Sdelphij * Use inline functions if we are allowed to and the compiler supports them. 139296465Sdelphij */ 140296465Sdelphij#if !defined(_DONT_USE_CTYPE_INLINE_) && \ 141296465Sdelphij (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) 142296465Sdelphijstatic __inline int 143296465Sdelphij__istype(_BSD_CT_RUNE_T_ _c, unsigned long _f) 14455714Skris{ 145296465Sdelphij return (_c < 0 || _c >= _CACHED_RUNES) ? !!(___runetype(_c) & _f) : 14655714Skris !!(_CurrentRuneLocale->runetype[_c] & _f); 147296465Sdelphij} 148296465Sdelphij 149296465Sdelphijstatic __inline int 15055714Skris__isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f) 151296465Sdelphij{ 152296465Sdelphij return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : 153296465Sdelphij !!(_DefaultRuneLocale.runetype[_c] & _f); 154296465Sdelphij} 155296465Sdelphij 15655714Skrisstatic __inline _BSD_CT_RUNE_T_ 157109998Smarkm__toupper(_BSD_CT_RUNE_T_ _c) 158296465Sdelphij{ 159296465Sdelphij return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : 16055714Skris _CurrentRuneLocale->mapupper[_c]; 161296465Sdelphij} 16255714Skris 16355714Skrisstatic __inline _BSD_CT_RUNE_T_ 164296465Sdelphij__tolower(_BSD_CT_RUNE_T_ _c) 16555714Skris{ 166296465Sdelphij return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : 16755714Skris _CurrentRuneLocale->maplower[_c]; 168296465Sdelphij} 169296465Sdelphij 17055714Skrisstatic __inline int 171296465Sdelphij__maskrune(_BSD_RUNE_T_ c, unsigned long f) 172296465Sdelphij{ 173296465Sdelphij return(((c & _CRMASK) 174296465Sdelphij ? ___runetype(c) : _CurrentRuneLocale->runetype[c]) & f); 175296465Sdelphij} 176296465Sdelphij 177296465Sdelphij#else /* not using inlines */ 178296465Sdelphij 179296465Sdelphij__BEGIN_DECLS 180296465Sdelphijint __istype __P((_BSD_CT_RUNE_T_, unsigned long)); 18155714Skrisint __isctype __P((_BSD_CT_RUNE_T_, unsigned long)); 182296465Sdelphijint __maskrune __P((_BSD_CT_RUNE_T_, unsigned long)); 183296465Sdelphij_BSD_CT_RUNE_T_ __toupper __P((_BSD_CT_RUNE_T_)); 184296465Sdelphij_BSD_CT_RUNE_T_ __tolower __P((_BSD_CT_RUNE_T_)); 185296465Sdelphij__END_DECLS 186296465Sdelphij#endif /* using inlines */ 187296465Sdelphij 18855714Skris#endif /* !_CTYPE_H_ */ 189296465Sdelphij