/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1989, 19934* The Regents of the University of California. All rights reserved.5* (c) UNIX System Laboratories, Inc.6* All or some portions of this file are derived from material licensed7* to the University of California by American Telephone and Telegraph8* Co. or Unix System Laboratories, Inc. and are reproduced herein with9* the permission of UNIX System Laboratories, Inc.10*11* This code is derived from software contributed to Berkeley by12* Paul Borman at Krystal Technologies.13*14* Redistribution and use in source and binary forms, with or without15* modification, are permitted provided that the following conditions16* are met:17* 1. Redistributions of source code must retain the above copyright18* notice, this list of conditions and the following disclaimer.19* 2. Redistributions in binary form must reproduce the above copyright20* notice, this list of conditions and the following disclaimer in the21* documentation and/or other materials provided with the distribution.22* 3. Neither the name of the University nor the names of its contributors23* may be used to endorse or promote products derived from this software24* without specific prior written permission.25*26* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND27* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE29* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE30* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL31* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS32* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)33* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT34* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY35* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF36* SUCH DAMAGE.37* From FreeBSD: src/include/ctype.h,v 1.27 2004/06/23 07:11:39 tjr Exp38*/3940#ifndef __CTYPE_H_41#define __CTYPE_H_4243#include <sys/cdefs.h>44#include <sys/_types.h>4546#define _CTYPE_A 0x00000100L /* Alpha */47#define _CTYPE_C 0x00000200L /* Control */48#define _CTYPE_D 0x00000400L /* Digit */49#define _CTYPE_G 0x00000800L /* Graph */50#define _CTYPE_L 0x00001000L /* Lower */51#define _CTYPE_P 0x00002000L /* Punct */52#define _CTYPE_S 0x00004000L /* Space */53#define _CTYPE_U 0x00008000L /* Upper */54#define _CTYPE_X 0x00010000L /* X digit */55#define _CTYPE_B 0x00020000L /* Blank */56#define _CTYPE_R 0x00040000L /* Print */57#define _CTYPE_I 0x00080000L /* Ideogram */58#define _CTYPE_T 0x00100000L /* Special */59#define _CTYPE_Q 0x00200000L /* Phonogram */60#define _CTYPE_N 0x00400000L /* Number (superset of digit) */61#define _CTYPE_SW0 0x20000000L /* 0 width character */62#define _CTYPE_SW1 0x40000000L /* 1 width character */63#define _CTYPE_SW2 0x80000000L /* 2 width character */64#define _CTYPE_SW3 0xc0000000L /* 3 width character */65#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */66#define _CTYPE_SWS 30 /* Bits to shift to get width */6768/* See comments in <sys/_types.h> about __ct_rune_t. */69__BEGIN_DECLS70unsigned long ___runetype(__ct_rune_t) __pure;71__ct_rune_t ___tolower(__ct_rune_t) __pure;72__ct_rune_t ___toupper(__ct_rune_t) __pure;73__END_DECLS7475/*76* _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us77* to generate code for extern versions of all our inline functions.78*/79#ifdef _EXTERNALIZE_CTYPE_INLINES_80#define _USE_CTYPE_INLINE_81#define static82#define __inline83#endif8485extern int __mb_sb_limit;8687/*88* Use inline functions if we are allowed to and the compiler supports them.89*/90#if !defined(_DONT_USE_CTYPE_INLINE_) && \91(defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))9293#include <runetype.h>9495static __inline int96__maskrune(__ct_rune_t _c, unsigned long _f)97{98return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :99_CurrentRuneLocale->__runetype[_c]) & _f;100}101102static __inline int103__sbmaskrune(__ct_rune_t _c, unsigned long _f)104{105return (_c < 0 || _c >= __mb_sb_limit) ? 0 :106_CurrentRuneLocale->__runetype[_c] & _f;107}108109static __inline int110__istype(__ct_rune_t _c, unsigned long _f)111{112return (!!__maskrune(_c, _f));113}114115static __inline int116__sbistype(__ct_rune_t _c, unsigned long _f)117{118return (!!__sbmaskrune(_c, _f));119}120121static __inline int122__isctype(__ct_rune_t _c, unsigned long _f)123{124return (_c < 0 || _c >= 128) ? 0 :125!!(_DefaultRuneLocale.__runetype[_c] & _f);126}127128static __inline __ct_rune_t129__toupper(__ct_rune_t _c)130{131return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :132_CurrentRuneLocale->__mapupper[_c];133}134135static __inline __ct_rune_t136__sbtoupper(__ct_rune_t _c)137{138return (_c < 0 || _c >= __mb_sb_limit) ? _c :139_CurrentRuneLocale->__mapupper[_c];140}141142static __inline __ct_rune_t143__tolower(__ct_rune_t _c)144{145return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :146_CurrentRuneLocale->__maplower[_c];147}148149static __inline __ct_rune_t150__sbtolower(__ct_rune_t _c)151{152return (_c < 0 || _c >= __mb_sb_limit) ? _c :153_CurrentRuneLocale->__maplower[_c];154}155156static __inline int157__wcwidth(__ct_rune_t _c)158{159unsigned int _x;160161if (_c == 0)162return (0);163_x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R);164if ((_x & _CTYPE_SWM) != 0)165return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);166return ((_x & _CTYPE_R) != 0 ? 1 : -1);167}168169#else /* not using inlines */170171__BEGIN_DECLS172int __maskrune(__ct_rune_t, unsigned long);173int __sbmaskrune(__ct_rune_t, unsigned long);174int __istype(__ct_rune_t, unsigned long);175int __sbistype(__ct_rune_t, unsigned long);176int __isctype(__ct_rune_t, unsigned long);177__ct_rune_t __toupper(__ct_rune_t);178__ct_rune_t __sbtoupper(__ct_rune_t);179__ct_rune_t __tolower(__ct_rune_t);180__ct_rune_t __sbtolower(__ct_rune_t);181int __wcwidth(__ct_rune_t);182__END_DECLS183#endif /* using inlines */184185#endif /* !__CTYPE_H_ */186187188