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