_ctype.h revision 103113
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 4254746Sphantom * $FreeBSD: head/include/_ctype.h 103113 2002-09-09 05:38:05Z mike $ 431539Srgrimes */ 441539Srgrimes 457655Sbde#ifndef _CTYPE_H_ 467655Sbde#define _CTYPE_H_ 471539Srgrimes 48103113Smike#include <sys/cdefs.h> 49103113Smike#include <sys/_types.h> 501539Srgrimes 5157035Sobrien#define _CTYPE_A 0x00000100L /* Alpha */ 5257035Sobrien#define _CTYPE_C 0x00000200L /* Control */ 5357035Sobrien#define _CTYPE_D 0x00000400L /* Digit */ 5457035Sobrien#define _CTYPE_G 0x00000800L /* Graph */ 5557035Sobrien#define _CTYPE_L 0x00001000L /* Lower */ 5657035Sobrien#define _CTYPE_P 0x00002000L /* Punct */ 5757035Sobrien#define _CTYPE_S 0x00004000L /* Space */ 5857035Sobrien#define _CTYPE_U 0x00008000L /* Upper */ 5957035Sobrien#define _CTYPE_X 0x00010000L /* X digit */ 6057035Sobrien#define _CTYPE_B 0x00020000L /* Blank */ 6157035Sobrien#define _CTYPE_R 0x00040000L /* Print */ 6257035Sobrien#define _CTYPE_I 0x00080000L /* Ideogram */ 6357035Sobrien#define _CTYPE_T 0x00100000L /* Special */ 6457035Sobrien#define _CTYPE_Q 0x00200000L /* Phonogram */ 65101984Skeichii#define _CTYPE_SW0 0x20000000L /* 0 width character */ 66102093Sache#define _CTYPE_SW1 0x40000000L /* 1 width character */ 67101984Skeichii#define _CTYPE_SW2 0x80000000L /* 2 width character */ 68101984Skeichii#define _CTYPE_SW3 0xc0000000L /* 3 width character */ 691539Srgrimes 707655Sbde__BEGIN_DECLS 7193032Simpint isalnum(int); 7293032Simpint isalpha(int); 7393032Simpint iscntrl(int); 7493032Simpint isdigit(int); 7593032Simpint isgraph(int); 7693032Simpint islower(int); 7793032Simpint isprint(int); 7893032Simpint ispunct(int); 7993032Simpint isspace(int); 8093032Simpint isupper(int); 8193032Simpint isxdigit(int); 8293032Simpint tolower(int); 8393032Simpint toupper(int); 841539Srgrimes 85102998Smike#if __XSI_VISIBLE 86102998Smikeint _tolower(int); 87102998Smikeint _toupper(int); 88102998Smikeint isascii(int); 89102998Smikeint toascii(int); 90102998Smike#endif 91102998Smike 92102998Smike#if __BSD_VISIBLE 9393032Simpint digittoint(int); 9493032Simpint isblank(int); 9593032Simpint ishexnumber(int); 9693032Simpint isideogram(int); 9793032Simpint isnumber(int); 9893032Simpint isphonogram(int); 9993032Simpint isrune(int); 10093032Simpint isspecial(int); 1017655Sbde#endif 1027655Sbde__END_DECLS 1037655Sbde 10457035Sobrien#define isalnum(c) __istype((c), _CTYPE_A|_CTYPE_D) 10557035Sobrien#define isalpha(c) __istype((c), _CTYPE_A) 10657035Sobrien#define iscntrl(c) __istype((c), _CTYPE_C) 10757035Sobrien#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */ 10857035Sobrien#define isgraph(c) __istype((c), _CTYPE_G) 10957035Sobrien#define islower(c) __istype((c), _CTYPE_L) 11057035Sobrien#define isprint(c) __istype((c), _CTYPE_R) 11157035Sobrien#define ispunct(c) __istype((c), _CTYPE_P) 11257035Sobrien#define isspace(c) __istype((c), _CTYPE_S) 11357035Sobrien#define isupper(c) __istype((c), _CTYPE_U) 11457035Sobrien#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */ 1157655Sbde#define tolower(c) __tolower(c) 1167655Sbde#define toupper(c) __toupper(c) 1177655Sbde 118102998Smike#if __XSI_VISIBLE 119102998Smike/* 120102998Smike * POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to 121102998Smike * tolower() and toupper() respectively, minus extra checking to ensure that 122102998Smike * the argument is a lower or uppercase letter respectively. We've chosen to 123102998Smike * implement these macros with the same error checking as tolower() and 124102998Smike * toupper() since this doesn't violate the specification itself, only its 125102998Smike * intent. We purposely leave _tolower() and _toupper() undocumented to 126102998Smike * discourage their use. 127102998Smike * 128102998Smike * XXX isascii() and toascii() should similarly be undocumented. 129102998Smike */ 130102998Smike#define _tolower(c) __tolower(c) 131102998Smike#define _toupper(c) __toupper(c) 132102998Smike#define isascii(c) (((c) & ~0x7F) == 0) 133102998Smike#define toascii(c) ((c) & 0x7F) 134102998Smike#endif 135102998Smike 136102998Smike#if __BSD_VISIBLE 13754746Sphantom#define digittoint(c) __maskrune((c), 0xFF) 13857035Sobrien#define isblank(c) __istype((c), _CTYPE_B) 13957035Sobrien#define ishexnumber(c) __istype((c), _CTYPE_X) 14057035Sobrien#define isideogram(c) __istype((c), _CTYPE_I) 14157035Sobrien#define isnumber(c) __istype((c), _CTYPE_D) 14257035Sobrien#define isphonogram(c) __istype((c), _CTYPE_Q) 1437655Sbde#define isrune(c) __istype((c), 0xFFFFFF00L) 14457035Sobrien#define isspecial(c) __istype((c), _CTYPE_T) 1451539Srgrimes#endif 1461539Srgrimes 147102998Smike/* See comments in <sys/_types.h> about __ct_rune_t. */ 1481539Srgrimes__BEGIN_DECLS 149102227Smikeunsigned long ___runetype(__ct_rune_t); 150102227Smike__ct_rune_t ___tolower(__ct_rune_t); 151102227Smike__ct_rune_t ___toupper(__ct_rune_t); 1521539Srgrimes__END_DECLS 1531539Srgrimes 1541539Srgrimes/* 1557655Sbde * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us 1567655Sbde * to generate code for extern versions of all our inline functions. 1571539Srgrimes */ 1587655Sbde#ifdef _EXTERNALIZE_CTYPE_INLINES_ 1597655Sbde#define _USE_CTYPE_INLINE_ 1607655Sbde#define static 1617655Sbde#define __inline 1621539Srgrimes#endif 1631539Srgrimes 1647655Sbde/* 165103113Smike * <runetype.h> brings namespace pollution (struct member names). This prevents 166103113Smike * us from using the inline optimizations in the more strict __POSIX_VISIBLE and 167103113Smike * __XSI_VISIBLE namespaces. To fix this properly would require that we rename 168103113Smike * member names of long-standing structs, or something equally evil. 169103113Smike */ 170103113Smike#if !__BSD_VISIBLE && !defined(_USE_CTYPE_INLINE_) && \ 171103113Smike !defined(_DONT_USE_CTYPE_INLINE_) 172103113Smike#define _DONT_USE_CTYPE_INLINE_ 173103113Smike#endif 174103113Smike 175103113Smike/* 1767655Sbde * Use inline functions if we are allowed to and the compiler supports them. 1777655Sbde */ 1787655Sbde#if !defined(_DONT_USE_CTYPE_INLINE_) && \ 1797655Sbde (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) 180103113Smike 181103113Smike#include <runetype.h> 182103113Smike 1831539Srgrimesstatic __inline int 184102227Smike__maskrune(__ct_rune_t _c, unsigned long _f) 1851539Srgrimes{ 18629855Sache return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : 18729855Sache _CurrentRuneLocale->runetype[_c]) & _f; 1881539Srgrimes} 1891539Srgrimes 1901539Srgrimesstatic __inline int 191102227Smike__istype(__ct_rune_t _c, unsigned long _f) 19290231Sbbraun{ 19390231Sbbraun return (!!__maskrune(_c, _f)); 19490231Sbbraun} 19590231Sbbraun 19690231Sbbraunstatic __inline int 197102227Smike__isctype(__ct_rune_t _c, unsigned long _f) 1981539Srgrimes{ 19912028Sache return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : 20029883Sache !!(_DefaultRuneLocale.runetype[_c] & _f); 2011539Srgrimes} 2021539Srgrimes 203102227Smikestatic __inline __ct_rune_t 204102227Smike__toupper(__ct_rune_t _c) 2051539Srgrimes{ 20614813Sache return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : 20712028Sache _CurrentRuneLocale->mapupper[_c]; 2081539Srgrimes} 2091539Srgrimes 210102227Smikestatic __inline __ct_rune_t 211102227Smike__tolower(__ct_rune_t _c) 2121539Srgrimes{ 21314813Sache return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : 21412028Sache _CurrentRuneLocale->maplower[_c]; 2151539Srgrimes} 2161539Srgrimes 2177655Sbde#else /* not using inlines */ 2181539Srgrimes 2191539Srgrimes__BEGIN_DECLS 220102227Smikeint __maskrune(__ct_rune_t, unsigned long); 221102227Smikeint __istype(__ct_rune_t, unsigned long); 222102227Smikeint __isctype(__ct_rune_t, unsigned long); 223102227Smike__ct_rune_t __toupper(__ct_rune_t); 224102227Smike__ct_rune_t __tolower(__ct_rune_t); 2251539Srgrimes__END_DECLS 2267655Sbde#endif /* using inlines */ 2271539Srgrimes 2281539Srgrimes#endif /* !_CTYPE_H_ */ 229