Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / gnulib / wctype.in.h
blob12c8975fecd22a329a65bd90b7430cf12212a84d
1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
3 Copyright (C) 2006-2010 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, 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
31 #if __GNUC__ >= 3
32 @PRAGMA_SYSTEM_HEADER@
33 #endif
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 /* Include the original <wctype.h> if it exists.
48 BeOS 5 has the functions but no <wctype.h>. */
49 /* The include_next requires a split double-inclusion guard. */
50 #if @HAVE_WCTYPE_H@
51 # @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
52 #endif
54 #ifndef _GL_WCTYPE_H
55 #define _GL_WCTYPE_H
57 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
59 /* The definition of _GL_WARN_ON_USE is copied here. */
61 /* Define wint_t and WEOF. (Also done in wchar.in.h.) */
62 #if !@HAVE_WINT_T@ && !defined wint_t
63 # define wint_t int
64 # ifndef WEOF
65 # define WEOF -1
66 # endif
67 #else
68 # ifndef WEOF
69 # define WEOF ((wint_t) -1)
70 # endif
71 #endif
74 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
75 Linux libc5 has <wctype.h> and the functions but they are broken.
76 Assume all 11 functions (all isw* except iswblank) are implemented the
77 same way, or not at all. */
78 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
80 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
81 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
82 refer to system functions like _iswctype that are not in the
83 standard C library. Rather than try to get ancient buggy
84 implementations like this to work, just disable them. */
85 # undef iswalnum
86 # undef iswalpha
87 # undef iswblank
88 # undef iswcntrl
89 # undef iswdigit
90 # undef iswgraph
91 # undef iswlower
92 # undef iswprint
93 # undef iswpunct
94 # undef iswspace
95 # undef iswupper
96 # undef iswxdigit
97 # undef towlower
98 # undef towupper
100 /* Linux libc5 has <wctype.h> and the functions but they are broken. */
101 # if @REPLACE_ISWCNTRL@
102 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
103 # define iswalnum rpl_iswalnum
104 # define iswalpha rpl_iswalpha
105 # define iswblank rpl_iswblank
106 # define iswcntrl rpl_iswcntrl
107 # define iswdigit rpl_iswdigit
108 # define iswgraph rpl_iswgraph
109 # define iswlower rpl_iswlower
110 # define iswprint rpl_iswprint
111 # define iswpunct rpl_iswpunct
112 # define iswspace rpl_iswspace
113 # define iswupper rpl_iswupper
114 # define iswxdigit rpl_iswxdigit
115 # define towlower rpl_towlower
116 # define towupper rpl_towupper
117 # endif
118 # endif
120 static inline int
121 # if @REPLACE_ISWCNTRL@
122 rpl_iswalnum
123 # else
124 iswalnum
125 # endif
126 (wint_t wc)
128 return ((wc >= '0' && wc <= '9')
129 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
132 static inline int
133 # if @REPLACE_ISWCNTRL@
134 rpl_iswalpha
135 # else
136 iswalpha
137 # endif
138 (wint_t wc)
140 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
143 static inline int
144 # if @REPLACE_ISWCNTRL@
145 rpl_iswblank
146 # else
147 iswblank
148 # endif
149 (wint_t wc)
151 return wc == ' ' || wc == '\t';
154 static inline int
155 # if @REPLACE_ISWCNTRL@
156 rpl_iswcntrl
157 # else
158 iswcntrl
159 # endif
160 (wint_t wc)
162 return (wc & ~0x1f) == 0 || wc == 0x7f;
165 static inline int
166 # if @REPLACE_ISWCNTRL@
167 rpl_iswdigit
168 # else
169 iswdigit
170 # endif
171 (wint_t wc)
173 return wc >= '0' && wc <= '9';
176 static inline int
177 # if @REPLACE_ISWCNTRL@
178 rpl_iswgraph
179 # else
180 iswgraph
181 # endif
182 (wint_t wc)
184 return wc >= '!' && wc <= '~';
187 static inline int
188 # if @REPLACE_ISWCNTRL@
189 rpl_iswlower
190 # else
191 iswlower
192 # endif
193 (wint_t wc)
195 return wc >= 'a' && wc <= 'z';
198 static inline int
199 # if @REPLACE_ISWCNTRL@
200 rpl_iswprint
201 # else
202 iswprint
203 # endif
204 (wint_t wc)
206 return wc >= ' ' && wc <= '~';
209 static inline int
210 # if @REPLACE_ISWCNTRL@
211 rpl_iswpunct
212 # else
213 iswpunct
214 # endif
215 (wint_t wc)
217 return (wc >= '!' && wc <= '~'
218 && !((wc >= '0' && wc <= '9')
219 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
222 static inline int
223 # if @REPLACE_ISWCNTRL@
224 rpl_iswspace
225 # else
226 iswspace
227 # endif
228 (wint_t wc)
230 return (wc == ' ' || wc == '\t'
231 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
234 static inline int
235 # if @REPLACE_ISWCNTRL@
236 rpl_iswupper
237 # else
238 iswupper
239 # endif
240 (wint_t wc)
242 return wc >= 'A' && wc <= 'Z';
245 static inline int
246 # if @REPLACE_ISWCNTRL@
247 rpl_iswxdigit
248 # else
249 iswxdigit
250 # endif
251 (wint_t wc)
253 return ((wc >= '0' && wc <= '9')
254 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
257 static inline wint_t
258 # if @REPLACE_ISWCNTRL@
259 rpl_towlower
260 # else
261 towlower
262 # endif
263 (wint_t wc)
265 return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
268 static inline wint_t
269 # if @REPLACE_ISWCNTRL@
270 rpl_towupper
271 # else
272 towupper
273 # endif
274 (wint_t wc)
276 return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
279 #elif ! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@
280 /* Only the iswblank function is missing. */
282 # if @REPLACE_ISWBLANK@
283 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
284 # define iswblank rpl_iswblank
285 # endif
286 # endif
288 static inline int
289 # if @REPLACE_ISWBLANK@
290 rpl_iswblank
291 # else
292 iswblank
293 # endif
294 (wint_t wc)
296 return wc == ' ' || wc == '\t';
299 #endif
301 #if defined __MINGW32__
303 /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
304 The functions towlower and towupper are implemented in the MSVCRT library
305 to take a wchar_t argument and return a wchar_t result. mingw declares
306 these functions to take a wint_t argument and return a wint_t result.
307 This means that:
308 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
309 function will look only at the lower 16 bits. This is allowed according
310 to POSIX.
311 2. The return value is returned in the lower 16 bits of the result register.
312 The upper 16 bits are random: whatever happened to be in that part of the
313 result register. We need to fix this by adding a zero-extend from
314 wchar_t to wint_t after the call. */
316 static inline wint_t
317 rpl_towlower (wint_t wc)
319 return (wint_t) (wchar_t) towlower (wc);
321 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
322 # define towlower rpl_towlower
323 # endif
325 static inline wint_t
326 rpl_towupper (wint_t wc)
328 return (wint_t) (wchar_t) towupper (wc);
330 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
331 # define towupper rpl_towupper
332 # endif
334 #endif /* __MINGW32__ */
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 (iswblank, int, (wint_t wc));
340 _GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
341 _GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
342 _GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
343 _GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
344 _GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
345 _GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
346 _GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
347 _GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
348 _GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
349 #else
350 _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
351 _GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
352 # if @REPLACE_ISWBLANK@
353 _GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
354 # else
355 _GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
356 # endif
357 _GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
358 _GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
359 _GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
360 _GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
361 _GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
362 _GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
363 _GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
364 _GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
365 _GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
366 #endif
367 _GL_CXXALIASWARN (iswalnum);
368 _GL_CXXALIASWARN (iswalpha);
369 _GL_CXXALIASWARN (iswblank);
370 _GL_CXXALIASWARN (iswcntrl);
371 _GL_CXXALIASWARN (iswdigit);
372 _GL_CXXALIASWARN (iswgraph);
373 _GL_CXXALIASWARN (iswlower);
374 _GL_CXXALIASWARN (iswprint);
375 _GL_CXXALIASWARN (iswpunct);
376 _GL_CXXALIASWARN (iswspace);
377 _GL_CXXALIASWARN (iswupper);
378 _GL_CXXALIASWARN (iswxdigit);
380 #if @REPLACE_ISWCNTRL@ || defined __MINGW32__
381 _GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
382 _GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
383 #else
384 _GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
385 _GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
386 #endif
387 _GL_CXXALIASWARN (towlower);
388 _GL_CXXALIASWARN (towupper);
391 #endif /* _GL_WCTYPE_H */
392 #endif /* _GL_WCTYPE_H */