Avoid gcc warnings because of #pragma GCC system_header on older gcc.
[gnulib.git] / 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 2, 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 __GNUC__ >= 3
32 @PRAGMA_SYSTEM_HEADER@
33 #endif
34
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
46
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
53
54 #ifndef _GL_WCTYPE_H
55 #define _GL_WCTYPE_H
56
57 /* Define wint_t.  (Also done in wchar.in.h.)  */
58 #if !@HAVE_WINT_T@ && !defined wint_t
59 # define wint_t int
60 #endif
61
62 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
63    Linux libc5 has <wctype.h> and the functions but they are broken.
64    Assume all 12 functions are implemented the same way, or not at all.  */
65 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
66
67 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
68    undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
69    refer to system functions like _iswctype that are not in the
70    standard C library.  Rather than try to get ancient buggy
71    implementations like this to work, just disable them.  */
72 #  undef iswalnum
73 #  undef iswalpha
74 #  undef iswblank
75 #  undef iswcntrl
76 #  undef iswdigit
77 #  undef iswgraph
78 #  undef iswlower
79 #  undef iswprint
80 #  undef iswpunct
81 #  undef iswspace
82 #  undef iswupper
83 #  undef iswxdigit
84
85 /* Linux libc5 has <wctype.h> and the functions but they are broken.  */
86 #  if @REPLACE_ISWCNTRL@
87 #   define iswalnum rpl_iswalnum
88 #   define iswalpha rpl_iswalpha
89 #   define iswblank rpl_iswblank
90 #   define iswcntrl rpl_iswcntrl
91 #   define iswdigit rpl_iswdigit
92 #   define iswgraph rpl_iswgraph
93 #   define iswlower rpl_iswlower
94 #   define iswprint rpl_iswprint
95 #   define iswpunct rpl_iswpunct
96 #   define iswspace rpl_iswspace
97 #   define iswupper rpl_iswupper
98 #   define iswxdigit rpl_iswxdigit
99 #  endif
100
101 static inline int
102 iswalnum (wint_t wc)
103 {
104   return ((wc >= '0' && wc <= '9')
105           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
106 }
107
108 static inline int
109 iswalpha (wint_t wc)
110 {
111   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
112 }
113
114 static inline int
115 iswblank (wint_t wc)
116 {
117   return wc == ' ' || wc == '\t';
118 }
119
120 static inline int
121 iswcntrl (wint_t wc)
122 {
123   return (wc & ~0x1f) == 0 || wc == 0x7f;
124 }
125
126 static inline int
127 iswdigit (wint_t wc)
128 {
129   return wc >= '0' && wc <= '9';
130 }
131
132 static inline int
133 iswgraph (wint_t wc)
134 {
135   return wc >= '!' && wc <= '~';
136 }
137
138 static inline int
139 iswlower (wint_t wc)
140 {
141   return wc >= 'a' && wc <= 'z';
142 }
143
144 static inline int
145 iswprint (wint_t wc)
146 {
147   return wc >= ' ' && wc <= '~';
148 }
149
150 static inline int
151 iswpunct (wint_t wc)
152 {
153   return (wc >= '!' && wc <= '~'
154           && !((wc >= '0' && wc <= '9')
155                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
156 }
157
158 static inline int
159 iswspace (wint_t wc)
160 {
161   return (wc == ' ' || wc == '\t'
162           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
163 }
164
165 static inline int
166 iswupper (wint_t wc)
167 {
168   return wc >= 'A' && wc <= 'Z';
169 }
170
171 static inline int
172 iswxdigit (wint_t wc)
173 {
174   return ((wc >= '0' && wc <= '9')
175           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
176 }
177
178 # endif /* ! HAVE_ISWCNTRL */
179
180 #endif /* _GL_WCTYPE_H */
181 #endif /* _GL_WCTYPE_H */