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