Code

f008d8ffd6b1d53f877808fd8123330ddc4b237d
[nagiosplug.git] / gl / wctype.in.h
1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
3    Copyright (C) 2006-2008 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.  */
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  */
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 /* Define wint_t.  (Also done in wchar.in.h.)  */
58 #if !@HAVE_WINT_T@ && !defined wint_t
59 # define wint_t int
60 # ifndef WEOF
61 #  define WEOF -1
62 # endif
63 #endif
65 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
66    Linux libc5 has <wctype.h> and the functions but they are broken.
67    Assume all 12 functions are implemented the same way, or not at all.  */
68 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
70 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
71    undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
72    refer to system functions like _iswctype that are not in the
73    standard C library.  Rather than try to get ancient buggy
74    implementations like this to work, just disable them.  */
75 #  undef iswalnum
76 #  undef iswalpha
77 #  undef iswblank
78 #  undef iswcntrl
79 #  undef iswdigit
80 #  undef iswgraph
81 #  undef iswlower
82 #  undef iswprint
83 #  undef iswpunct
84 #  undef iswspace
85 #  undef iswupper
86 #  undef iswxdigit
88 /* Linux libc5 has <wctype.h> and the functions but they are broken.  */
89 #  if @REPLACE_ISWCNTRL@
90 #   define iswalnum rpl_iswalnum
91 #   define iswalpha rpl_iswalpha
92 #   define iswblank rpl_iswblank
93 #   define iswcntrl rpl_iswcntrl
94 #   define iswdigit rpl_iswdigit
95 #   define iswgraph rpl_iswgraph
96 #   define iswlower rpl_iswlower
97 #   define iswprint rpl_iswprint
98 #   define iswpunct rpl_iswpunct
99 #   define iswspace rpl_iswspace
100 #   define iswupper rpl_iswupper
101 #   define iswxdigit rpl_iswxdigit
102 #  endif
104 static inline int
105 iswalnum (wint_t wc)
107   return ((wc >= '0' && wc <= '9')
108           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
111 static inline int
112 iswalpha (wint_t wc)
114   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
117 static inline int
118 iswblank (wint_t wc)
120   return wc == ' ' || wc == '\t';
123 static inline int
124 iswcntrl (wint_t wc)
126   return (wc & ~0x1f) == 0 || wc == 0x7f;
129 static inline int
130 iswdigit (wint_t wc)
132   return wc >= '0' && wc <= '9';
135 static inline int
136 iswgraph (wint_t wc)
138   return wc >= '!' && wc <= '~';
141 static inline int
142 iswlower (wint_t wc)
144   return wc >= 'a' && wc <= 'z';
147 static inline int
148 iswprint (wint_t wc)
150   return wc >= ' ' && wc <= '~';
153 static inline int
154 iswpunct (wint_t wc)
156   return (wc >= '!' && wc <= '~'
157           && !((wc >= '0' && wc <= '9')
158                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
161 static inline int
162 iswspace (wint_t wc)
164   return (wc == ' ' || wc == '\t'
165           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
168 static inline int
169 iswupper (wint_t wc)
171   return wc >= 'A' && wc <= 'Z';
174 static inline int
175 iswxdigit (wint_t wc)
177   return ((wc >= '0' && wc <= '9')
178           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
181 # endif /* ! HAVE_ISWCNTRL */
183 #endif /* _GL_WCTYPE_H */
184 #endif /* _GL_WCTYPE_H */