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