Ensure that wint_t gets defined on IRIX 5.3.
[gnulib.git] / lib / wctype.in.h
1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
2
3    Copyright (C) 2006-2008 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 @PRAGMA_SYSTEM_HEADER@
32
33 #if @HAVE_WINT_T@
34 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
35    Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
36    <wchar.h>.
37    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
38    included before <wchar.h>.  */
39 # include <stddef.h>
40 # include <stdio.h>
41 # include <time.h>
42 # include <wchar.h>
43 #endif
44
45 /* Include the original <wctype.h> if it exists.
46    BeOS 5 has the functions but no <wctype.h>.  */
47 /* The include_next requires a split double-inclusion guard.  */
48 #if @HAVE_WCTYPE_H@
49 # @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
50 #endif
51
52 #ifndef _GL_WCTYPE_H
53 #define _GL_WCTYPE_H
54
55 /* Define wint_t.  (Also done in wchar.in.h.)  */
56 #if !@HAVE_WINT_T@ && !defined wint_t
57 # define wint_t int
58 #endif
59
60 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
61    Linux libc5 has <wctype.h> and the functions but they are broken.
62    Assume all 12 functions are implemented the same way, or not at all.  */
63 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
64
65 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
66    undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
67    refer to system functions like _iswctype that are not in the
68    standard C library.  Rather than try to get ancient buggy
69    implementations like this to work, just disable them.  */
70 #  undef iswalnum
71 #  undef iswalpha
72 #  undef iswblank
73 #  undef iswcntrl
74 #  undef iswdigit
75 #  undef iswgraph
76 #  undef iswlower
77 #  undef iswprint
78 #  undef iswpunct
79 #  undef iswspace
80 #  undef iswupper
81 #  undef iswxdigit
82
83 /* Linux libc5 has <wctype.h> and the functions but they are broken.  */
84 #  if @REPLACE_ISWCNTRL@
85 #   define iswalnum rpl_iswalnum
86 #   define iswalpha rpl_iswalpha
87 #   define iswblank rpl_iswblank
88 #   define iswcntrl rpl_iswcntrl
89 #   define iswdigit rpl_iswdigit
90 #   define iswgraph rpl_iswgraph
91 #   define iswlower rpl_iswlower
92 #   define iswprint rpl_iswprint
93 #   define iswpunct rpl_iswpunct
94 #   define iswspace rpl_iswspace
95 #   define iswupper rpl_iswupper
96 #   define iswxdigit rpl_iswxdigit
97 #  endif
98
99 static inline int
100 iswalnum (wint_t wc)
101 {
102   return ((wc >= '0' && wc <= '9')
103           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
104 }
105
106 static inline int
107 iswalpha (wint_t wc)
108 {
109   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
110 }
111
112 static inline int
113 iswblank (wint_t wc)
114 {
115   return wc == ' ' || wc == '\t';
116 }
117
118 static inline int
119 iswcntrl (wint_t wc)
120 {
121   return (wc & ~0x1f) == 0 || wc == 0x7f;
122 }
123
124 static inline int
125 iswdigit (wint_t wc)
126 {
127   return wc >= '0' && wc <= '9';
128 }
129
130 static inline int
131 iswgraph (wint_t wc)
132 {
133   return wc >= '!' && wc <= '~';
134 }
135
136 static inline int
137 iswlower (wint_t wc)
138 {
139   return wc >= 'a' && wc <= 'z';
140 }
141
142 static inline int
143 iswprint (wint_t wc)
144 {
145   return wc >= ' ' && wc <= '~';
146 }
147
148 static inline int
149 iswpunct (wint_t wc)
150 {
151   return (wc >= '!' && wc <= '~'
152           && !((wc >= '0' && wc <= '9')
153                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
154 }
155
156 static inline int
157 iswspace (wint_t wc)
158 {
159   return (wc == ' ' || wc == '\t'
160           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
161 }
162
163 static inline int
164 iswupper (wint_t wc)
165 {
166   return wc >= 'A' && wc <= 'Z';
167 }
168
169 static inline int
170 iswxdigit (wint_t wc)
171 {
172   return ((wc >= '0' && wc <= '9')
173           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
174 }
175
176 # endif /* ! HAVE_ISWCNTRL */
177
178 #endif /* _GL_WCTYPE_H */
179 #endif /* _GL_WCTYPE_H */