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. 21203964Simp * 3. Neither the name of the University nor the names of its contributors 221539Srgrimes * may be used to endorse or promote products derived from this software 231539Srgrimes * without specific prior written permission. 241539Srgrimes * 251539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 261539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 271539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 281539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 321539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 331539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 341539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 351539Srgrimes * SUCH DAMAGE. 361539Srgrimes * 37133559Stjr * From @(#)ctype.h 8.4 (Berkeley) 1/21/94 38133559Stjr * From FreeBSD: src/include/ctype.h,v 1.27 2004/06/23 07:11:39 tjr Exp 39133559Stjr * $FreeBSD$ 401539Srgrimes */ 411539Srgrimes 42133559Stjr#ifndef __CTYPE_H_ 43133559Stjr#define __CTYPE_H_ 441539Srgrimes 45103113Smike#include <sys/cdefs.h> 46103113Smike#include <sys/_types.h> 471539Srgrimes 4857035Sobrien#define _CTYPE_A 0x00000100L /* Alpha */ 4957035Sobrien#define _CTYPE_C 0x00000200L /* Control */ 5057035Sobrien#define _CTYPE_D 0x00000400L /* Digit */ 5157035Sobrien#define _CTYPE_G 0x00000800L /* Graph */ 5257035Sobrien#define _CTYPE_L 0x00001000L /* Lower */ 5357035Sobrien#define _CTYPE_P 0x00002000L /* Punct */ 5457035Sobrien#define _CTYPE_S 0x00004000L /* Space */ 5557035Sobrien#define _CTYPE_U 0x00008000L /* Upper */ 5657035Sobrien#define _CTYPE_X 0x00010000L /* X digit */ 5757035Sobrien#define _CTYPE_B 0x00020000L /* Blank */ 5857035Sobrien#define _CTYPE_R 0x00040000L /* Print */ 5957035Sobrien#define _CTYPE_I 0x00080000L /* Ideogram */ 6057035Sobrien#define _CTYPE_T 0x00100000L /* Special */ 6157035Sobrien#define _CTYPE_Q 0x00200000L /* Phonogram */ 62101984Skeichii#define _CTYPE_SW0 0x20000000L /* 0 width character */ 63102093Sache#define _CTYPE_SW1 0x40000000L /* 1 width character */ 64101984Skeichii#define _CTYPE_SW2 0x80000000L /* 2 width character */ 65101984Skeichii#define _CTYPE_SW3 0xc0000000L /* 3 width character */ 66133564Stjr#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */ 67133564Stjr#define _CTYPE_SWS 30 /* Bits to shift to get width */ 681539Srgrimes 69102998Smike/* See comments in <sys/_types.h> about __ct_rune_t. */ 701539Srgrimes__BEGIN_DECLS 71134101Stjrunsigned long ___runetype(__ct_rune_t) __pure; 72134101Stjr__ct_rune_t ___tolower(__ct_rune_t) __pure; 73134101Stjr__ct_rune_t ___toupper(__ct_rune_t) __pure; 741539Srgrimes__END_DECLS 751539Srgrimes 761539Srgrimes/* 777655Sbde * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us 787655Sbde * to generate code for extern versions of all our inline functions. 791539Srgrimes */ 807655Sbde#ifdef _EXTERNALIZE_CTYPE_INLINES_ 817655Sbde#define _USE_CTYPE_INLINE_ 827655Sbde#define static 837655Sbde#define __inline 841539Srgrimes#endif 851539Srgrimes 86172619Sacheextern int __mb_sb_limit; 87172619Sache 887655Sbde/* 897655Sbde * Use inline functions if we are allowed to and the compiler supports them. 907655Sbde */ 917655Sbde#if !defined(_DONT_USE_CTYPE_INLINE_) && \ 927655Sbde (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) 93103113Smike 94103113Smike#include <runetype.h> 95103113Smike 961539Srgrimesstatic __inline int 97102227Smike__maskrune(__ct_rune_t _c, unsigned long _f) 981539Srgrimes{ 9929855Sache return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : 100130961Stjr _CurrentRuneLocale->__runetype[_c]) & _f; 1011539Srgrimes} 1021539Srgrimes 1031539Srgrimesstatic __inline int 104172619Sache__sbmaskrune(__ct_rune_t _c, unsigned long _f) 105172619Sache{ 106172619Sache return (_c < 0 || _c >= __mb_sb_limit) ? 0 : 107172619Sache _CurrentRuneLocale->__runetype[_c] & _f; 108172619Sache} 109172619Sache 110172619Sachestatic __inline int 111102227Smike__istype(__ct_rune_t _c, unsigned long _f) 11290231Sbbraun{ 11390231Sbbraun return (!!__maskrune(_c, _f)); 11490231Sbbraun} 11590231Sbbraun 11690231Sbbraunstatic __inline int 117172619Sache__sbistype(__ct_rune_t _c, unsigned long _f) 118172619Sache{ 119172619Sache return (!!__sbmaskrune(_c, _f)); 120172619Sache} 121172619Sache 122172619Sachestatic __inline int 123102227Smike__isctype(__ct_rune_t _c, unsigned long _f) 1241539Srgrimes{ 125173244Sache return (_c < 0 || _c >= 128) ? 0 : 126130961Stjr !!(_DefaultRuneLocale.__runetype[_c] & _f); 1271539Srgrimes} 1281539Srgrimes 129102227Smikestatic __inline __ct_rune_t 130102227Smike__toupper(__ct_rune_t _c) 1311539Srgrimes{ 13214813Sache return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : 133130961Stjr _CurrentRuneLocale->__mapupper[_c]; 1341539Srgrimes} 1351539Srgrimes 136102227Smikestatic __inline __ct_rune_t 137172619Sache__sbtoupper(__ct_rune_t _c) 138172619Sache{ 139172619Sache return (_c < 0 || _c >= __mb_sb_limit) ? _c : 140172619Sache _CurrentRuneLocale->__mapupper[_c]; 141172619Sache} 142172619Sache 143172619Sachestatic __inline __ct_rune_t 144102227Smike__tolower(__ct_rune_t _c) 1451539Srgrimes{ 14614813Sache return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : 147130961Stjr _CurrentRuneLocale->__maplower[_c]; 1481539Srgrimes} 1491539Srgrimes 150172619Sachestatic __inline __ct_rune_t 151172619Sache__sbtolower(__ct_rune_t _c) 152172619Sache{ 153172619Sache return (_c < 0 || _c >= __mb_sb_limit) ? _c : 154172619Sache _CurrentRuneLocale->__maplower[_c]; 155172619Sache} 156172619Sache 157133564Stjrstatic __inline int 158133564Stjr__wcwidth(__ct_rune_t _c) 159133564Stjr{ 160133564Stjr unsigned int _x; 161133564Stjr 162133564Stjr if (_c == 0) 163133564Stjr return (0); 164133564Stjr _x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R); 165133564Stjr if ((_x & _CTYPE_SWM) != 0) 166133564Stjr return ((_x & _CTYPE_SWM) >> _CTYPE_SWS); 167133564Stjr return ((_x & _CTYPE_R) != 0 ? 1 : -1); 168133564Stjr} 169133564Stjr 1707655Sbde#else /* not using inlines */ 1711539Srgrimes 1721539Srgrimes__BEGIN_DECLS 173102227Smikeint __maskrune(__ct_rune_t, unsigned long); 174172619Sacheint __sbmaskrune(__ct_rune_t, unsigned long); 175102227Smikeint __istype(__ct_rune_t, unsigned long); 176172619Sacheint __sbistype(__ct_rune_t, unsigned long); 177102227Smikeint __isctype(__ct_rune_t, unsigned long); 178102227Smike__ct_rune_t __toupper(__ct_rune_t); 179172619Sache__ct_rune_t __sbtoupper(__ct_rune_t); 180102227Smike__ct_rune_t __tolower(__ct_rune_t); 181172619Sache__ct_rune_t __sbtolower(__ct_rune_t); 182133564Stjrint __wcwidth(__ct_rune_t); 1831539Srgrimes__END_DECLS 1847655Sbde#endif /* using inlines */ 1851539Srgrimes 186133559Stjr#endif /* !__CTYPE_H_ */ 187