]> sjero.net Git - wget/blob - lib/wctype.in.h
Automated merge.
[wget] / lib / wctype.in.h
1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
2
3    Copyright (C) 2006-2008 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 3, 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, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 /* Written by Bruno Haible and Paul Eggert.  */
20
21 /*
22  * ISO C 99 <wctype.h> for platforms that lack it.
23  * <http://www.opengroup.org/susv3xbd/wctype.h.html>
24  *
25  * iswctype, towctrans, towlower, towupper, wctrans, wctype,
26  * wctrans_t, and wctype_t are not yet implemented.
27  */
28
29 #ifndef _GL_WCTYPE_H
30
31 #if @HAVE_WINT_T@
32 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
33    Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
34    <wchar.h>.
35    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
36    included before <wchar.h>.  */
37 # include <stddef.h>
38 # include <stdio.h>
39 # include <time.h>
40 # include <wchar.h>
41 #endif
42
43 /* Include the original <wctype.h> if it exists.
44    BeOS 5 has the functions but no <wctype.h>.  */
45 /* The include_next requires a split double-inclusion guard.  */
46 #if @HAVE_WCTYPE_H@
47 # @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
48 #endif
49
50 #ifndef _GL_WCTYPE_H
51 #define _GL_WCTYPE_H
52
53 #if @HAVE_WINT_T@
54 typedef wint_t __wctype_wint_t;
55 #else
56 typedef int __wctype_wint_t;
57 #endif
58
59 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
60    Linux libc5 has <wctype.h> and the functions but they are broken.
61    Assume all 12 functions are implemented the same way, or not at all.  */
62 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
63
64 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
65    undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
66    refer to system functions like _iswctype that are not in the
67    standard C library.  Rather than try to get ancient buggy
68    implementations like this to work, just disable them.  */
69 #  undef iswalnum
70 #  undef iswalpha
71 #  undef iswblank
72 #  undef iswcntrl
73 #  undef iswdigit
74 #  undef iswgraph
75 #  undef iswlower
76 #  undef iswprint
77 #  undef iswpunct
78 #  undef iswspace
79 #  undef iswupper
80 #  undef iswxdigit
81
82 /* Linux libc5 has <wctype.h> and the functions but they are broken.  */
83 #  if @REPLACE_ISWCNTRL@
84 #   define iswalnum rpl_iswalnum
85 #   define iswalpha rpl_iswalpha
86 #   define iswblank rpl_iswblank
87 #   define iswcntrl rpl_iswcntrl
88 #   define iswdigit rpl_iswdigit
89 #   define iswgraph rpl_iswgraph
90 #   define iswlower rpl_iswlower
91 #   define iswprint rpl_iswprint
92 #   define iswpunct rpl_iswpunct
93 #   define iswspace rpl_iswspace
94 #   define iswupper rpl_iswupper
95 #   define iswxdigit rpl_iswxdigit
96 #  endif
97
98 static inline int
99 iswalnum (__wctype_wint_t wc)
100 {
101   return ((wc >= '0' && wc <= '9')
102           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
103 }
104
105 static inline int
106 iswalpha (__wctype_wint_t wc)
107 {
108   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
109 }
110
111 static inline int
112 iswblank (__wctype_wint_t wc)
113 {
114   return wc == ' ' || wc == '\t';
115 }
116
117 static inline int
118 iswcntrl (__wctype_wint_t wc)
119 {
120   return (wc & ~0x1f) == 0 || wc == 0x7f;
121 }
122
123 static inline int
124 iswdigit (__wctype_wint_t wc)
125 {
126   return wc >= '0' && wc <= '9';
127 }
128
129 static inline int
130 iswgraph (__wctype_wint_t wc)
131 {
132   return wc >= '!' && wc <= '~';
133 }
134
135 static inline int
136 iswlower (__wctype_wint_t wc)
137 {
138   return wc >= 'a' && wc <= 'z';
139 }
140
141 static inline int
142 iswprint (__wctype_wint_t wc)
143 {
144   return wc >= ' ' && wc <= '~';
145 }
146
147 static inline int
148 iswpunct (__wctype_wint_t wc)
149 {
150   return (wc >= '!' && wc <= '~'
151           && !((wc >= '0' && wc <= '9')
152                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
153 }
154
155 static inline int
156 iswspace (__wctype_wint_t wc)
157 {
158   return (wc == ' ' || wc == '\t'
159           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
160 }
161
162 static inline int
163 iswupper (__wctype_wint_t wc)
164 {
165   return wc >= 'A' && wc <= 'Z';
166 }
167
168 static inline int
169 iswxdigit (__wctype_wint_t wc)
170 {
171   return ((wc >= '0' && wc <= '9')
172           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
173 }
174
175 # endif /* ! HAVE_ISWCNTRL */
176
177 #endif /* _GL_WCTYPE_H */
178 #endif /* _GL_WCTYPE_H */