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