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