]> git.cworth.org Git - tar/blob - gnu/wctype.in.h
099351b648f09ec5b7c828e6e6bc9cd7f815bc58
[tar] / gnu / 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 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
60
61 /* The definition of _GL_WARN_ON_USE is copied here.  */
62
63 /* Define wint_t.  (Also done in wchar.in.h.)  */
64 #if !@HAVE_WINT_T@ && !defined wint_t
65 # define wint_t int
66 # ifndef WEOF
67 #  define WEOF -1
68 # endif
69 #endif
70
71
72 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
73    Linux libc5 has <wctype.h> and the functions but they are broken.
74    Assume all 12 functions are implemented the same way, or not at all.  */
75 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
76
77 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
78    undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
79    refer to system functions like _iswctype that are not in the
80    standard C library.  Rather than try to get ancient buggy
81    implementations like this to work, just disable them.  */
82 # undef iswalnum
83 # undef iswalpha
84 # undef iswblank
85 # undef iswcntrl
86 # undef iswdigit
87 # undef iswgraph
88 # undef iswlower
89 # undef iswprint
90 # undef iswpunct
91 # undef iswspace
92 # undef iswupper
93 # undef iswxdigit
94 # undef towlower
95 # undef towupper
96
97 /* Linux libc5 has <wctype.h> and the functions but they are broken.  */
98 # if @REPLACE_ISWCNTRL@
99 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
100 #   define iswalnum rpl_iswalnum
101 #   define iswalpha rpl_iswalpha
102 #   define iswblank rpl_iswblank
103 #   define iswcntrl rpl_iswcntrl
104 #   define iswdigit rpl_iswdigit
105 #   define iswgraph rpl_iswgraph
106 #   define iswlower rpl_iswlower
107 #   define iswprint rpl_iswprint
108 #   define iswpunct rpl_iswpunct
109 #   define iswspace rpl_iswspace
110 #   define iswupper rpl_iswupper
111 #   define iswxdigit rpl_iswxdigit
112 #   define towlower rpl_towlower
113 #   define towupper rpl_towupper
114 #  endif
115 # endif
116
117 static inline int
118 # if @REPLACE_ISWCNTRL@
119 rpl_iswalnum
120 # else
121 iswalnum
122 # endif
123          (wint_t wc)
124 {
125   return ((wc >= '0' && wc <= '9')
126           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
127 }
128
129 static inline int
130 # if @REPLACE_ISWCNTRL@
131 rpl_iswalpha
132 # else
133 iswalpha
134 # endif
135          (wint_t wc)
136 {
137   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
138 }
139
140 static inline int
141 # if @REPLACE_ISWCNTRL@
142 rpl_iswblank
143 # else
144 iswblank
145 # endif
146          (wint_t wc)
147 {
148   return wc == ' ' || wc == '\t';
149 }
150
151 static inline int
152 # if @REPLACE_ISWCNTRL@
153 rpl_iswcntrl
154 # else
155 iswcntrl
156 # endif
157         (wint_t wc)
158 {
159   return (wc & ~0x1f) == 0 || wc == 0x7f;
160 }
161
162 static inline int
163 # if @REPLACE_ISWCNTRL@
164 rpl_iswdigit
165 # else
166 iswdigit
167 # endif
168          (wint_t wc)
169 {
170   return wc >= '0' && wc <= '9';
171 }
172
173 static inline int
174 # if @REPLACE_ISWCNTRL@
175 rpl_iswgraph
176 # else
177 iswgraph
178 # endif
179          (wint_t wc)
180 {
181   return wc >= '!' && wc <= '~';
182 }
183
184 static inline int
185 # if @REPLACE_ISWCNTRL@
186 rpl_iswlower
187 # else
188 iswlower
189 # endif
190          (wint_t wc)
191 {
192   return wc >= 'a' && wc <= 'z';
193 }
194
195 static inline int
196 # if @REPLACE_ISWCNTRL@
197 rpl_iswprint
198 # else
199 iswprint
200 # endif
201          (wint_t wc)
202 {
203   return wc >= ' ' && wc <= '~';
204 }
205
206 static inline int
207 # if @REPLACE_ISWCNTRL@
208 rpl_iswpunct
209 # else
210 iswpunct
211 # endif
212          (wint_t wc)
213 {
214   return (wc >= '!' && wc <= '~'
215           && !((wc >= '0' && wc <= '9')
216                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
217 }
218
219 static inline int
220 # if @REPLACE_ISWCNTRL@
221 rpl_iswspace
222 # else
223 iswspace
224 # endif
225          (wint_t wc)
226 {
227   return (wc == ' ' || wc == '\t'
228           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
229 }
230
231 static inline int
232 # if @REPLACE_ISWCNTRL@
233 rpl_iswupper
234 # else
235 iswupper
236 # endif
237          (wint_t wc)
238 {
239   return wc >= 'A' && wc <= 'Z';
240 }
241
242 static inline int
243 # if @REPLACE_ISWCNTRL@
244 rpl_iswxdigit
245 # else
246 iswxdigit
247 # endif
248           (wint_t wc)
249 {
250   return ((wc >= '0' && wc <= '9')
251           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
252 }
253
254 static inline wint_t
255 # if @REPLACE_ISWCNTRL@
256 rpl_towlower
257 # else
258 towlower
259 # endif
260          (wint_t wc)
261 {
262   return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
263 }
264
265 static inline wint_t
266 # if @REPLACE_ISWCNTRL@
267 rpl_towupper
268 # else
269 towupper
270 # endif
271          (wint_t wc)
272 {
273   return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
274 }
275
276 #endif /* ! HAVE_ISWCNTRL || REPLACE_ISWCNTRL */
277
278 #if defined __MINGW32__
279
280 /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
281    The functions towlower and towupper are implemented in the MSVCRT library
282    to take a wchar_t argument and return a wchar_t result.  mingw declares
283    these functions to take a wint_t argument and return a wint_t result.
284    This means that:
285    1. When the user passes an argument outside the range 0x0000..0xFFFF, the
286       function will look only at the lower 16 bits.  This is allowed according
287       to POSIX.
288    2. The return value is returned in the lower 16 bits of the result register.
289       The upper 16 bits are random: whatever happened to be in that part of the
290       result register.  We need to fix this by adding a zero-extend from
291       wchar_t to wint_t after the call.  */
292
293 static inline wint_t
294 rpl_towlower (wint_t wc)
295 {
296   return (wint_t) (wchar_t) towlower (wc);
297 }
298 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
299 #  define towlower rpl_towlower
300 # endif
301
302 static inline wint_t
303 rpl_towupper (wint_t wc)
304 {
305   return (wint_t) (wchar_t) towupper (wc);
306 }
307 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
308 #  define towupper rpl_towupper
309 # endif
310
311 #endif /* __MINGW32__ */
312
313 #if @REPLACE_ISWCNTRL@
314 _GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
315 _GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
316 _GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
317 _GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
318 _GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
319 _GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
320 _GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
321 _GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
322 _GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
323 _GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
324 _GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
325 _GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
326 #else
327 _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
328 _GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
329 _GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
330 _GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
331 _GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
332 _GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
333 _GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
334 _GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
335 _GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
336 _GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
337 _GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
338 _GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
339 #endif
340 _GL_CXXALIASWARN (iswalnum);
341 _GL_CXXALIASWARN (iswalpha);
342 _GL_CXXALIASWARN (iswblank);
343 _GL_CXXALIASWARN (iswcntrl);
344 _GL_CXXALIASWARN (iswdigit);
345 _GL_CXXALIASWARN (iswgraph);
346 _GL_CXXALIASWARN (iswlower);
347 _GL_CXXALIASWARN (iswprint);
348 _GL_CXXALIASWARN (iswpunct);
349 _GL_CXXALIASWARN (iswspace);
350 _GL_CXXALIASWARN (iswupper);
351 _GL_CXXALIASWARN (iswxdigit);
352
353 #if @REPLACE_ISWCNTRL@ || defined __MINGW32__
354 _GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
355 _GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
356 #else
357 _GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
358 _GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
359 #endif
360 _GL_CXXALIASWARN (towlower);
361 _GL_CXXALIASWARN (towupper);
362
363
364 #endif /* _GL_WCTYPE_H */
365 #endif /* _GL_WCTYPE_H */