Fix bug reported by Bruno Haible in
[pspp] / lib / wctype_.h
1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
2
3    Copyright (C) 2006 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 #define _GL_WCTYPE_H
31
32 #if @HAVE_WINT_T@ - 0
33 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
34    Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
35    <wchar.h>.
36    BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
37    <wchar.h>.  */
38 # include <stdio.h>
39 # include <time.h>
40 # include <wchar.h>
41 typedef wint_t __wctype_wint_t;
42 #else
43 typedef int __wctype_wint_t;
44 #endif
45
46 /* Include the original <wctype.h> if it exists.
47    BeOS 5 has the functions but no <wctype.h>.  */
48 #if @HAVE_WCTYPE_H@
49 # include @ABSOLUTE_WCTYPE_H@
50 #endif
51
52 /* IRIX 5.3 has a bug: its isw* macros reference an undefined variable
53    _ctmp_.  */
54 #if @HAVE_WCTYPE_CTMP_BUG@
55 static wint_t _ctmp_;
56 #endif
57
58 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
59    Assume all 12 functions are implemented the same way, or not at all.  */
60
61 #if !defined iswalnum && !HAVE_ISWCNTRL
62 static inline int
63 iswalnum (__wctype_wint_t wc)
64 {
65   return ((wc >= '0' && wc <= '9')
66           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
67 }
68 # define iswalnum iswalnum
69 #endif
70
71 #if !defined iswalpha && !HAVE_ISWCNTRL
72 static inline int
73 iswalpha (__wctype_wint_t wc)
74 {
75   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
76 }
77 # define iswalpha iswalpha
78 #endif
79
80 #if !defined iswblank && !HAVE_ISWCNTRL
81 static inline int
82 iswblank (__wctype_wint_t wc)
83 {
84   return wc == ' ' || wc == '\t';
85 }
86 # define iswblank iswblank
87 #endif
88
89 #if !defined iswcntrl && !HAVE_ISWCNTRL
90 static inline int
91 iswcntrl (__wctype_wint_t wc)
92 {
93   return (wc & ~0x1f) == 0 || wc == 0x7f;
94 }
95 # define iswcntrl iswcntrl
96 #endif
97
98 #if !defined iswdigit && !HAVE_ISWCNTRL
99 static inline int
100 iswdigit (__wctype_wint_t wc)
101 {
102   return wc >= '0' && wc <= '9';
103 }
104 # define iswdigit iswdigit
105 #endif
106
107 #if !defined iswgraph && !HAVE_ISWCNTRL
108 static inline int
109 iswgraph (__wctype_wint_t wc)
110 {
111   return wc >= '!' && wc <= '~';
112 }
113 # define iswgraph iswgraph
114 #endif
115
116 #if !defined iswlower && !HAVE_ISWCNTRL
117 static inline int
118 iswlower (__wctype_wint_t wc)
119 {
120   return wc >= 'a' && wc <= 'z';
121 }
122 # define iswlower iswlower
123 #endif
124
125 #if !defined iswprint && !HAVE_ISWCNTRL
126 static inline int
127 iswprint (__wctype_wint_t wc)
128 {
129   return wc >= ' ' && wc <= '~';
130 }
131 # define iswprint iswprint
132 #endif
133
134 #if !defined iswpunct && !HAVE_ISWCNTRL
135 static inline int
136 iswpunct (__wctype_wint_t wc)
137 {
138   return (wc >= '!' && wc <= '~'
139           && !((wc >= '0' && wc <= '9')
140                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
141 }
142 # define iswpunct iswpunct
143 #endif
144
145 #if !defined iswspace && !HAVE_ISWCNTRL
146 static inline int
147 iswspace (__wctype_wint_t wc)
148 {
149   return (wc == ' ' || wc == '\t'
150           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
151 }
152 # define iswspace iswspace
153 #endif
154
155 #if !defined iswupper && !HAVE_ISWCNTRL
156 static inline int
157 iswupper (__wctype_wint_t wc)
158 {
159   return wc >= 'A' && wc <= 'Z';
160 }
161 # define iswupper iswupper
162 #endif
163
164 #if !defined iswxdigit && !HAVE_ISWCNTRL
165 static inline int
166 iswxdigit (__wctype_wint_t wc)
167 {
168   return ((wc >= '0' && wc <= '9')
169           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
170 }
171 # define iswxdigit iswxdigit
172 #endif
173
174
175 #endif /* _GL_WCTYPE_H */