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