16981b6ac40af2d90e5621b9d00cf96aeed45ac1
[debian/gzip] / lib / wctype.in.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
4
5    Copyright (C) 2006-2010 Free Software Foundation, Inc.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3, or (at your option)
10    any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software Foundation,
19    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
20
21 /* Written by Bruno Haible and Paul Eggert.  */
22
23 /*
24  * ISO C 99 <wctype.h> for platforms that lack it.
25  * <http://www.opengroup.org/susv3xbd/wctype.h.html>
26  *
27  * iswctype, towctrans, towlower, towupper, wctrans, wctype,
28  * wctrans_t, and wctype_t are not yet implemented.
29  */
30
31 #ifndef _GL_WCTYPE_H
32
33 #if __GNUC__ >= 3
34 @PRAGMA_SYSTEM_HEADER@
35 #endif
36
37 #if @HAVE_WINT_T@
38 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
39    Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
40    <wchar.h>.
41    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
42    included before <wchar.h>.  */
43 # include <stddef.h>
44 # include <stdio.h>
45 # include <time.h>
46 # include <wchar.h>
47 #endif
48
49 /* Include the original <wctype.h> if it exists.
50    BeOS 5 has the functions but no <wctype.h>.  */
51 /* The include_next requires a split double-inclusion guard.  */
52 #if @HAVE_WCTYPE_H@
53 # @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
54 #endif
55
56 #ifndef _GL_WCTYPE_H
57 #define _GL_WCTYPE_H
58
59 /* Define wint_t.  (Also done in wchar.in.h.)  */
60 #if !@HAVE_WINT_T@ && !defined wint_t
61 # define wint_t int
62 # ifndef WEOF
63 #  define WEOF -1
64 # endif
65 #endif
66
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70
71 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
72    Linux libc5 has <wctype.h> and the functions but they are broken.
73    Assume all 12 functions are implemented the same way, or not at all.  */
74 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
75
76 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
77    undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
78    refer to system functions like _iswctype that are not in the
79    standard C library.  Rather than try to get ancient buggy
80    implementations like this to work, just disable them.  */
81 # undef iswalnum
82 # undef iswalpha
83 # undef iswblank
84 # undef iswcntrl
85 # undef iswdigit
86 # undef iswgraph
87 # undef iswlower
88 # undef iswprint
89 # undef iswpunct
90 # undef iswspace
91 # undef iswupper
92 # undef iswxdigit
93 # undef towlower
94 # undef towupper
95
96 /* Linux libc5 has <wctype.h> and the functions but they are broken.  */
97 # if @REPLACE_ISWCNTRL@
98 #  define iswalnum rpl_iswalnum
99 #  define iswalpha rpl_iswalpha
100 #  define iswblank rpl_iswblank
101 #  define iswcntrl rpl_iswcntrl
102 #  define iswdigit rpl_iswdigit
103 #  define iswgraph rpl_iswgraph
104 #  define iswlower rpl_iswlower
105 #  define iswprint rpl_iswprint
106 #  define iswpunct rpl_iswpunct
107 #  define iswspace rpl_iswspace
108 #  define iswupper rpl_iswupper
109 #  define iswxdigit rpl_iswxdigit
110 #  define towlower rpl_towlower
111 #  define towupper rpl_towupper
112 # endif
113
114 static inline int
115 iswalnum (wint_t wc)
116 {
117   return ((wc >= '0' && wc <= '9')
118           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
119 }
120
121 static inline int
122 iswalpha (wint_t wc)
123 {
124   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
125 }
126
127 static inline int
128 iswblank (wint_t wc)
129 {
130   return wc == ' ' || wc == '\t';
131 }
132
133 static inline int
134 iswcntrl (wint_t wc)
135 {
136   return (wc & ~0x1f) == 0 || wc == 0x7f;
137 }
138
139 static inline int
140 iswdigit (wint_t wc)
141 {
142   return wc >= '0' && wc <= '9';
143 }
144
145 static inline int
146 iswgraph (wint_t wc)
147 {
148   return wc >= '!' && wc <= '~';
149 }
150
151 static inline int
152 iswlower (wint_t wc)
153 {
154   return wc >= 'a' && wc <= 'z';
155 }
156
157 static inline int
158 iswprint (wint_t wc)
159 {
160   return wc >= ' ' && wc <= '~';
161 }
162
163 static inline int
164 iswpunct (wint_t wc)
165 {
166   return (wc >= '!' && wc <= '~'
167           && !((wc >= '0' && wc <= '9')
168                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
169 }
170
171 static inline int
172 iswspace (wint_t wc)
173 {
174   return (wc == ' ' || wc == '\t'
175           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
176 }
177
178 static inline int
179 iswupper (wint_t wc)
180 {
181   return wc >= 'A' && wc <= 'Z';
182 }
183
184 static inline int
185 iswxdigit (wint_t wc)
186 {
187   return ((wc >= '0' && wc <= '9')
188           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
189 }
190
191 static inline wint_t
192 towlower (wint_t wc)
193 {
194   return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
195 }
196
197 static inline wint_t
198 towupper (wint_t wc)
199 {
200   return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
201 }
202
203 #endif /* ! HAVE_ISWCNTRL || REPLACE_ISWCNTRL */
204
205 #if defined __MINGW32__
206
207 /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
208    The functions towlower and towupper are implemented in the MSVCRT library
209    to take a wchar_t argument and return a wchar_t result.  mingw declares
210    these functions to take a wint_t argument and return a wint_t result.
211    This means that:
212    1. When the user passes an argument outside the range 0x0000..0xFFFF, the
213       function will look only at the lower 16 bits.  This is allowed according
214       to POSIX.
215    2. The return value is returned in the lower 16 bits of the result register.
216       The upper 16 bits are random: whatever happened to be in that part of the
217       result register.  We need to fix this by adding a zero-extend from
218       wchar_t to wint_t after the call.  */
219
220 static inline wint_t
221 rpl_towlower (wint_t wc)
222 {
223   return (wint_t) (wchar_t) towlower (wc);
224 }
225 # define towlower rpl_towlower
226
227 static inline wint_t
228 rpl_towupper (wint_t wc)
229 {
230   return (wint_t) (wchar_t) towupper (wc);
231 }
232 # define towupper rpl_towupper
233
234 #endif /* __MINGW32__ */
235
236 #ifdef __cplusplus
237 }
238 #endif
239
240 #endif /* _GL_WCTYPE_H */
241 #endif /* _GL_WCTYPE_H */