Prep for 1.4.10
[monitoring-plugins.git] / gl / wctype_.h
blob1297c61e62b7492c498af106906f30713f03a84c
1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
3 Copyright (C) 2006, 2007 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 2, 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, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* Written by Bruno Haible and Paul Eggert. */
22 * ISO C 99 <wctype.h> for platforms that lack it.
23 * <http://www.opengroup.org/susv3xbd/wctype.h.html>
25 * iswctype, towctrans, towlower, towupper, wctrans, wctype,
26 * wctrans_t, and wctype_t are not yet implemented.
29 #ifndef _GL_WCTYPE_H
30 #define _GL_WCTYPE_H
32 #if @HAVE_WINT_T@
33 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
34 Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
35 <wchar.h>.
36 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
37 included before <wchar.h>. */
38 # include <stddef.h>
39 # include <stdio.h>
40 # include <time.h>
41 # include <wchar.h>
42 typedef wint_t __wctype_wint_t;
43 #else
44 typedef int __wctype_wint_t;
45 #endif
47 /* Include the original <wctype.h> if it exists.
48 BeOS 5 has the functions but no <wctype.h>. */
49 #if @HAVE_WCTYPE_H@
50 # include @ABSOLUTE_WCTYPE_H@
51 #endif
53 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
54 Assume all 12 functions are implemented the same way, or not at all. */
55 #if ! HAVE_ISWCNTRL
57 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
58 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
59 refer to system functions like _iswctype that are not in the
60 standard C library. Rather than try to get ancient buggy
61 implementations like this to work, just disable them. */
62 # undef iswalnum
63 # undef iswalpha
64 # undef iswblank
65 # undef iswcntrl
66 # undef iswdigit
67 # undef iswgraph
68 # undef iswlower
69 # undef iswprint
70 # undef iswpunct
71 # undef iswspace
72 # undef iswupper
73 # undef iswxdigit
75 static inline int
76 iswalnum (__wctype_wint_t wc)
78 return ((wc >= '0' && wc <= '9')
79 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
82 static inline int
83 iswalpha (__wctype_wint_t wc)
85 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
88 static inline int
89 iswblank (__wctype_wint_t wc)
91 return wc == ' ' || wc == '\t';
94 static inline int
95 iswcntrl (__wctype_wint_t wc)
97 return (wc & ~0x1f) == 0 || wc == 0x7f;
100 static inline int
101 iswdigit (__wctype_wint_t wc)
103 return wc >= '0' && wc <= '9';
106 static inline int
107 iswgraph (__wctype_wint_t wc)
109 return wc >= '!' && wc <= '~';
112 static inline int
113 iswlower (__wctype_wint_t wc)
115 return wc >= 'a' && wc <= 'z';
118 static inline int
119 iswprint (__wctype_wint_t wc)
121 return wc >= ' ' && wc <= '~';
124 static inline int
125 iswpunct (__wctype_wint_t wc)
127 return (wc >= '!' && wc <= '~'
128 && !((wc >= '0' && wc <= '9')
129 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
132 static inline int
133 iswspace (__wctype_wint_t wc)
135 return (wc == ' ' || wc == '\t'
136 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
139 static inline int
140 iswupper (__wctype_wint_t wc)
142 return wc >= 'A' && wc <= 'Z';
145 static inline int
146 iswxdigit (__wctype_wint_t wc)
148 return ((wc >= '0' && wc <= '9')
149 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
152 # endif /* ! HAVE_ISWCNTRL */
154 #endif /* _GL_WCTYPE_H */