1/* A substitute for ISO C99 <wctype.h>, for platforms that lack it. 2 3 Copyright (C) 2006, 2007 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2, or (at your option) 8 any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software Foundation, 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 19/* Written by Bruno Haible and Paul Eggert. */ 20 21/* 22 * ISO C 99 <wctype.h> for platforms that lack it. 23 * <http://www.opengroup.org/susv3xbd/wctype.h.html> 24 * 25 * iswctype, towctrans, towlower, towupper, wctrans, wctype, 26 * wctrans_t, and wctype_t are not yet implemented. 27 */ 28 29#ifndef _GL_WCTYPE_H 30 31#if @HAVE_WINT_T@ 32/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. 33 Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 34 <wchar.h>. 35 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be 36 included before <wchar.h>. */ 37# include <stddef.h> 38# include <stdio.h> 39# include <time.h> 40# include <wchar.h> 41#endif 42 43/* Include the original <wctype.h> if it exists. 44 BeOS 5 has the functions but no <wctype.h>. */ 45/* The include_next requires a split double-inclusion guard. */ 46#if @HAVE_WCTYPE_H@ 47# if @HAVE_INCLUDE_NEXT@ 48# include_next <wctype.h> 49# else 50# include @ABSOLUTE_WCTYPE_H@ 51# endif 52#endif 53 54#ifndef _GL_WCTYPE_H 55#define _GL_WCTYPE_H 56 57#if @HAVE_WINT_T@ 58typedef wint_t __wctype_wint_t; 59#else 60typedef int __wctype_wint_t; 61#endif 62 63/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions. 64 Assume all 12 functions are implemented the same way, or not at all. */ 65#if ! @HAVE_ISWCNTRL@ 66 67/* IRIX 5.3 has macros but no functions, its isw* macros refer to an 68 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they 69 refer to system functions like _iswctype that are not in the 70 standard C library. Rather than try to get ancient buggy 71 implementations like this to work, just disable them. */ 72# undef iswalnum 73# undef iswalpha 74# undef iswblank 75# undef iswcntrl 76# undef iswdigit 77# undef iswgraph 78# undef iswlower 79# undef iswprint 80# undef iswpunct 81# undef iswspace 82# undef iswupper 83# undef iswxdigit 84 85static inline int 86iswalnum (__wctype_wint_t wc) 87{ 88 return ((wc >= '0' && wc <= '9') 89 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); 90} 91 92static inline int 93iswalpha (__wctype_wint_t wc) 94{ 95 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'; 96} 97 98static inline int 99iswblank (__wctype_wint_t wc) 100{ 101 return wc == ' ' || wc == '\t'; 102} 103 104static inline int 105iswcntrl (__wctype_wint_t wc) 106{ 107 return (wc & ~0x1f) == 0 || wc == 0x7f; 108} 109 110static inline int 111iswdigit (__wctype_wint_t wc) 112{ 113 return wc >= '0' && wc <= '9'; 114} 115 116static inline int 117iswgraph (__wctype_wint_t wc) 118{ 119 return wc >= '!' && wc <= '~'; 120} 121 122static inline int 123iswlower (__wctype_wint_t wc) 124{ 125 return wc >= 'a' && wc <= 'z'; 126} 127 128static inline int 129iswprint (__wctype_wint_t wc) 130{ 131 return wc >= ' ' && wc <= '~'; 132} 133 134static inline int 135iswpunct (__wctype_wint_t wc) 136{ 137 return (wc >= '!' && wc <= '~' 138 && !((wc >= '0' && wc <= '9') 139 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); 140} 141 142static inline int 143iswspace (__wctype_wint_t wc) 144{ 145 return (wc == ' ' || wc == '\t' 146 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); 147} 148 149static inline int 150iswupper (__wctype_wint_t wc) 151{ 152 return wc >= 'A' && wc <= 'Z'; 153} 154 155static inline int 156iswxdigit (__wctype_wint_t wc) 157{ 158 return ((wc >= '0' && wc <= '9') 159 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); 160} 161 162# endif /* ! HAVE_ISWCNTRL */ 163 164#endif /* _GL_WCTYPE_H */ 165#endif /* _GL_WCTYPE_H */ 166