* lib/wctype_.h (_ctmp_) [HAVE_WCTYPE_CTMP_BUG]: Now of type wchar_t,
[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 bugs: its isw* macros refer to an undefined variable
53    _ctmp_ and to <ctype.h> macros like _P.  */
54 #if @HAVE_WCTYPE_CTMP_BUG@
55 # include <ctype.h>
56 wchar_t _ctmp_;
57 #endif
58
59 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
60    Assume all 12 functions are implemented the same way, or not at all.  */
61
62 #if !defined iswalnum && !HAVE_ISWCNTRL
63 static inline int
64 iswalnum (__wctype_wint_t wc)
65 {
66   return ((wc >= '0' && wc <= '9')
67           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
68 }
69 # define iswalnum iswalnum
70 #endif
71
72 #if !defined iswalpha && !HAVE_ISWCNTRL
73 static inline int
74 iswalpha (__wctype_wint_t wc)
75 {
76   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
77 }
78 # define iswalpha iswalpha
79 #endif
80
81 #if !defined iswblank && !HAVE_ISWCNTRL
82 static inline int
83 iswblank (__wctype_wint_t wc)
84 {
85   return wc == ' ' || wc == '\t';
86 }
87 # define iswblank iswblank
88 #endif
89
90 #if !defined iswcntrl && !HAVE_ISWCNTRL
91 static inline int
92 iswcntrl (__wctype_wint_t wc)
93 {
94   return (wc & ~0x1f) == 0 || wc == 0x7f;
95 }
96 # define iswcntrl iswcntrl
97 #endif
98
99 #if !defined iswdigit && !HAVE_ISWCNTRL
100 static inline int
101 iswdigit (__wctype_wint_t wc)
102 {
103   return wc >= '0' && wc <= '9';
104 }
105 # define iswdigit iswdigit
106 #endif
107
108 #if !defined iswgraph && !HAVE_ISWCNTRL
109 static inline int
110 iswgraph (__wctype_wint_t wc)
111 {
112   return wc >= '!' && wc <= '~';
113 }
114 # define iswgraph iswgraph
115 #endif
116
117 #if !defined iswlower && !HAVE_ISWCNTRL
118 static inline int
119 iswlower (__wctype_wint_t wc)
120 {
121   return wc >= 'a' && wc <= 'z';
122 }
123 # define iswlower iswlower
124 #endif
125
126 #if !defined iswprint && !HAVE_ISWCNTRL
127 static inline int
128 iswprint (__wctype_wint_t wc)
129 {
130   return wc >= ' ' && wc <= '~';
131 }
132 # define iswprint iswprint
133 #endif
134
135 #if !defined iswpunct && !HAVE_ISWCNTRL
136 static inline int
137 iswpunct (__wctype_wint_t wc)
138 {
139   return (wc >= '!' && wc <= '~'
140           && !((wc >= '0' && wc <= '9')
141                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
142 }
143 # define iswpunct iswpunct
144 #endif
145
146 #if !defined iswspace && !HAVE_ISWCNTRL
147 static inline int
148 iswspace (__wctype_wint_t wc)
149 {
150   return (wc == ' ' || wc == '\t'
151           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
152 }
153 # define iswspace iswspace
154 #endif
155
156 #if !defined iswupper && !HAVE_ISWCNTRL
157 static inline int
158 iswupper (__wctype_wint_t wc)
159 {
160   return wc >= 'A' && wc <= 'Z';
161 }
162 # define iswupper iswupper
163 #endif
164
165 #if !defined iswxdigit && !HAVE_ISWCNTRL
166 static inline int
167 iswxdigit (__wctype_wint_t wc)
168 {
169   return ((wc >= '0' && wc <= '9')
170           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
171 }
172 # define iswxdigit iswxdigit
173 #endif
174
175
176 #endif /* _GL_WCTYPE_H */