add http/1.1 transfer codings to the NEWS
[bpt/guile.git] / lib / wctype.in.h
CommitLineData
eb4a14ed
LC
1/* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
2
3 Copyright (C) 2006-2012 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 Lesser 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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 _@GUARD_PREFIX@_WCTYPE_H
30
31#if __GNUC__ >= 3
32@PRAGMA_SYSTEM_HEADER@
33#endif
34@PRAGMA_COLUMNS@
35
36#if @HAVE_WINT_T@
37/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
38 Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
39 <wchar.h>.
40 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
41 included before <wchar.h>. */
42# include <stddef.h>
43# include <stdio.h>
44# include <time.h>
45# include <wchar.h>
46#endif
47
48/* Include the original <wctype.h> if it exists.
49 BeOS 5 has the functions but no <wctype.h>. */
50/* The include_next requires a split double-inclusion guard. */
51#if @HAVE_WCTYPE_H@
52# @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
53#endif
54
55#ifndef _@GUARD_PREFIX@_WCTYPE_H
56#define _@GUARD_PREFIX@_WCTYPE_H
57
58/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
59
60/* The definition of _GL_WARN_ON_USE is copied here. */
61
62/* Solaris 2.6 <wctype.h> includes <widec.h> which includes <euc.h> which
63 #defines a number of identifiers in the application namespace. Revert
64 these #defines. */
65#ifdef __sun
66# undef multibyte
67# undef eucw1
68# undef eucw2
69# undef eucw3
70# undef scrw1
71# undef scrw2
72# undef scrw3
73#endif
74
75/* Define wint_t and WEOF. (Also done in wchar.in.h.) */
76#if !@HAVE_WINT_T@ && !defined wint_t
77# define wint_t int
78# ifndef WEOF
79# define WEOF -1
80# endif
81#else
82/* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>.
83 This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
84 "unchanged by default argument promotions". Override it. */
85# if defined _MSC_VER
86# if !GNULIB_defined_wint_t
87# include <crtdefs.h>
88typedef unsigned int rpl_wint_t;
89# undef wint_t
90# define wint_t rpl_wint_t
91# define GNULIB_defined_wint_t 1
92# endif
93# endif
94# ifndef WEOF
95# define WEOF ((wint_t) -1)
96# endif
97#endif
98
99
100#if !GNULIB_defined_wctype_functions
101
102/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
103 Linux libc5 has <wctype.h> and the functions but they are broken.
104 Assume all 11 functions (all isw* except iswblank) are implemented the
105 same way, or not at all. */
106# if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
107
108/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
109 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
110 refer to system functions like _iswctype that are not in the
111 standard C library. Rather than try to get ancient buggy
112 implementations like this to work, just disable them. */
113# undef iswalnum
114# undef iswalpha
115# undef iswblank
116# undef iswcntrl
117# undef iswdigit
118# undef iswgraph
119# undef iswlower
120# undef iswprint
121# undef iswpunct
122# undef iswspace
123# undef iswupper
124# undef iswxdigit
125# undef towlower
126# undef towupper
127
128/* Linux libc5 has <wctype.h> and the functions but they are broken. */
129# if @REPLACE_ISWCNTRL@
130# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
131# define iswalnum rpl_iswalnum
132# define iswalpha rpl_iswalpha
133# define iswblank rpl_iswblank
134# define iswcntrl rpl_iswcntrl
135# define iswdigit rpl_iswdigit
136# define iswgraph rpl_iswgraph
137# define iswlower rpl_iswlower
138# define iswprint rpl_iswprint
139# define iswpunct rpl_iswpunct
140# define iswspace rpl_iswspace
141# define iswupper rpl_iswupper
142# define iswxdigit rpl_iswxdigit
143# endif
144# endif
145# if @REPLACE_TOWLOWER@
146# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
147# define towlower rpl_towlower
148# define towupper rpl_towupper
149# endif
150# endif
151
152static inline int
153# if @REPLACE_ISWCNTRL@
154rpl_iswalnum
155# else
156iswalnum
157# endif
158 (wint_t wc)
159{
160 return ((wc >= '0' && wc <= '9')
161 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
162}
163
164static inline int
165# if @REPLACE_ISWCNTRL@
166rpl_iswalpha
167# else
168iswalpha
169# endif
170 (wint_t wc)
171{
172 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
173}
174
175static inline int
176# if @REPLACE_ISWCNTRL@
177rpl_iswblank
178# else
179iswblank
180# endif
181 (wint_t wc)
182{
183 return wc == ' ' || wc == '\t';
184}
185
186static inline int
187# if @REPLACE_ISWCNTRL@
188rpl_iswcntrl
189# else
190iswcntrl
191# endif
192 (wint_t wc)
193{
194 return (wc & ~0x1f) == 0 || wc == 0x7f;
195}
196
197static inline int
198# if @REPLACE_ISWCNTRL@
199rpl_iswdigit
200# else
201iswdigit
202# endif
203 (wint_t wc)
204{
205 return wc >= '0' && wc <= '9';
206}
207
208static inline int
209# if @REPLACE_ISWCNTRL@
210rpl_iswgraph
211# else
212iswgraph
213# endif
214 (wint_t wc)
215{
216 return wc >= '!' && wc <= '~';
217}
218
219static inline int
220# if @REPLACE_ISWCNTRL@
221rpl_iswlower
222# else
223iswlower
224# endif
225 (wint_t wc)
226{
227 return wc >= 'a' && wc <= 'z';
228}
229
230static inline int
231# if @REPLACE_ISWCNTRL@
232rpl_iswprint
233# else
234iswprint
235# endif
236 (wint_t wc)
237{
238 return wc >= ' ' && wc <= '~';
239}
240
241static inline int
242# if @REPLACE_ISWCNTRL@
243rpl_iswpunct
244# else
245iswpunct
246# endif
247 (wint_t wc)
248{
249 return (wc >= '!' && wc <= '~'
250 && !((wc >= '0' && wc <= '9')
251 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
252}
253
254static inline int
255# if @REPLACE_ISWCNTRL@
256rpl_iswspace
257# else
258iswspace
259# endif
260 (wint_t wc)
261{
262 return (wc == ' ' || wc == '\t'
263 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
264}
265
266static inline int
267# if @REPLACE_ISWCNTRL@
268rpl_iswupper
269# else
270iswupper
271# endif
272 (wint_t wc)
273{
274 return wc >= 'A' && wc <= 'Z';
275}
276
277static inline int
278# if @REPLACE_ISWCNTRL@
279rpl_iswxdigit
280# else
281iswxdigit
282# endif
283 (wint_t wc)
284{
285 return ((wc >= '0' && wc <= '9')
286 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
287}
288
289static inline wint_t
290# if @REPLACE_TOWLOWER@
291rpl_towlower
292# else
293towlower
294# endif
295 (wint_t wc)
296{
297 return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
298}
299
300static inline wint_t
301# if @REPLACE_TOWLOWER@
302rpl_towupper
303# else
304towupper
305# endif
306 (wint_t wc)
307{
308 return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
309}
310
311# elif @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@)
312/* Only the iswblank function is missing. */
313
314# if @REPLACE_ISWBLANK@
315# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
316# define iswblank rpl_iswblank
317# endif
318_GL_FUNCDECL_RPL (iswblank, int, (wint_t wc));
319# else
320_GL_FUNCDECL_SYS (iswblank, int, (wint_t wc));
321# endif
322
323# endif
324
325# if defined __MINGW32__
326
327/* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
328 The functions towlower and towupper are implemented in the MSVCRT library
329 to take a wchar_t argument and return a wchar_t result. mingw declares
330 these functions to take a wint_t argument and return a wint_t result.
331 This means that:
332 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
333 function will look only at the lower 16 bits. This is allowed according
334 to POSIX.
335 2. The return value is returned in the lower 16 bits of the result register.
336 The upper 16 bits are random: whatever happened to be in that part of the
337 result register. We need to fix this by adding a zero-extend from
338 wchar_t to wint_t after the call. */
339
340static inline wint_t
341rpl_towlower (wint_t wc)
342{
343 return (wint_t) (wchar_t) towlower (wc);
344}
345# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
346# define towlower rpl_towlower
347# endif
348
349static inline wint_t
350rpl_towupper (wint_t wc)
351{
352 return (wint_t) (wchar_t) towupper (wc);
353}
354# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
355# define towupper rpl_towupper
356# endif
357
358# endif /* __MINGW32__ */
359
360# define GNULIB_defined_wctype_functions 1
361#endif
362
363#if @REPLACE_ISWCNTRL@
364_GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
365_GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
366_GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
367_GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
368_GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
369_GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
370_GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
371_GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
372_GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
373_GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
374_GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
375#else
376_GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
377_GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
378_GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
379_GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
380_GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
381_GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
382_GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
383_GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
384_GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
385_GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
386_GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
387#endif
388_GL_CXXALIASWARN (iswalnum);
389_GL_CXXALIASWARN (iswalpha);
390_GL_CXXALIASWARN (iswcntrl);
391_GL_CXXALIASWARN (iswdigit);
392_GL_CXXALIASWARN (iswgraph);
393_GL_CXXALIASWARN (iswlower);
394_GL_CXXALIASWARN (iswprint);
395_GL_CXXALIASWARN (iswpunct);
396_GL_CXXALIASWARN (iswspace);
397_GL_CXXALIASWARN (iswupper);
398_GL_CXXALIASWARN (iswxdigit);
399
400#if @GNULIB_ISWBLANK@
401# if @REPLACE_ISWCNTRL@ || @REPLACE_ISWBLANK@
402_GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
403# else
404_GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
405# endif
406_GL_CXXALIASWARN (iswblank);
407#endif
408
409#if !@HAVE_WCTYPE_T@
410# if !GNULIB_defined_wctype_t
411typedef void * wctype_t;
412# define GNULIB_defined_wctype_t 1
413# endif
414#endif
415
416/* Get a descriptor for a wide character property. */
417#if @GNULIB_WCTYPE@
418# if !@HAVE_WCTYPE_T@
419_GL_FUNCDECL_SYS (wctype, wctype_t, (const char *name));
420# endif
421_GL_CXXALIAS_SYS (wctype, wctype_t, (const char *name));
422_GL_CXXALIASWARN (wctype);
423#elif defined GNULIB_POSIXCHECK
424# undef wctype
425# if HAVE_RAW_DECL_WCTYPE
426_GL_WARN_ON_USE (wctype, "wctype is unportable - "
427 "use gnulib module wctype for portability");
428# endif
429#endif
430
431/* Test whether a wide character has a given property.
432 The argument WC must be either a wchar_t value or WEOF.
433 The argument DESC must have been returned by the wctype() function. */
434#if @GNULIB_ISWCTYPE@
435# if !@HAVE_WCTYPE_T@
436_GL_FUNCDECL_SYS (iswctype, int, (wint_t wc, wctype_t desc));
437# endif
438_GL_CXXALIAS_SYS (iswctype, int, (wint_t wc, wctype_t desc));
439_GL_CXXALIASWARN (iswctype);
440#elif defined GNULIB_POSIXCHECK
441# undef iswctype
442# if HAVE_RAW_DECL_ISWCTYPE
443_GL_WARN_ON_USE (iswctype, "iswctype is unportable - "
444 "use gnulib module iswctype for portability");
445# endif
446#endif
447
448#if @REPLACE_TOWLOWER@ || defined __MINGW32__
449_GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
450_GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
451#else
452_GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
453_GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
454#endif
455_GL_CXXALIASWARN (towlower);
456_GL_CXXALIASWARN (towupper);
457
458#if !@HAVE_WCTRANS_T@
459# if !GNULIB_defined_wctrans_t
460typedef void * wctrans_t;
461# define GNULIB_defined_wctrans_t 1
462# endif
463#endif
464
465/* Get a descriptor for a wide character case conversion. */
466#if @GNULIB_WCTRANS@
467# if !@HAVE_WCTRANS_T@
468_GL_FUNCDECL_SYS (wctrans, wctrans_t, (const char *name));
469# endif
470_GL_CXXALIAS_SYS (wctrans, wctrans_t, (const char *name));
471_GL_CXXALIASWARN (wctrans);
472#elif defined GNULIB_POSIXCHECK
473# undef wctrans
474# if HAVE_RAW_DECL_WCTRANS
475_GL_WARN_ON_USE (wctrans, "wctrans is unportable - "
476 "use gnulib module wctrans for portability");
477# endif
478#endif
479
480/* Perform a given case conversion on a wide character.
481 The argument WC must be either a wchar_t value or WEOF.
482 The argument DESC must have been returned by the wctrans() function. */
483#if @GNULIB_TOWCTRANS@
484# if !@HAVE_WCTRANS_T@
485_GL_FUNCDECL_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
486# endif
487_GL_CXXALIAS_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
488_GL_CXXALIASWARN (towctrans);
489#elif defined GNULIB_POSIXCHECK
490# undef towctrans
491# if HAVE_RAW_DECL_TOWCTRANS
492_GL_WARN_ON_USE (towctrans, "towctrans is unportable - "
493 "use gnulib module towctrans for portability");
494# endif
495#endif
496
497
498#endif /* _@GUARD_PREFIX@_WCTYPE_H */
499#endif /* _@GUARD_PREFIX@_WCTYPE_H */