1 /*
2  *      cook - file construction tool
3  *      Copyright (C) 1997, 1998, 2006, 2007 Peter Miller;
4  *      All rights reserved.
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 3 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License
17  *      along with this program. If not, see
18  *      <http://www.gnu.org/licenses/>.
19  *
20  * The use of the long variable is to cope with the possibility of an
21  * unusual data type having been defined for wchar_t.  Unusual types
22  * have been observed, and often cause unnecessary warnings from
23  * compilers.  The long takes care of it.
24  *
25  * Also, the HAVE_ISWPRINT can be false (e.g. on Solaris) but iswprint
26  * is still available as a macro.  Hence, we need to test for the macro
27  * as well as the function.
28  */
29 
30 #include <common/ac/ctype.h>
31 #include <common/ac/wctype.h>
32 #include <common/ac/limits.h>
33 
34 
35 #ifndef HAVE_ISWPRINT
36 
37 #ifndef iswprint
38 
39 int
iswprint(wc)40 iswprint(wc)
41         wint_t          wc;
42 {
43         long            c;
44 
45         /*
46          * Assume characters over 256 are printable.  Assume characters
47          * under 256 are either ASCII or Latin-1.  These are dumb
48          * assumptions, but real i18n support will provide a real
49          * iswprint function.
50          */
51         c = wc;
52         return (c > UCHAR_MAX || (c >= 0 && isprint((unsigned char)c)));
53 }
54 
55 #endif
56 
57 #ifndef iswspace
58 
59 int
iswspace(wc)60 iswspace(wc)
61         wint_t          wc;
62 {
63         long            c;
64 
65         /*
66          * Assume characters over 256 are letters.  Assume characters
67          * under 256 are either ASCII or Latin-1.  These are dumb
68          * assumptions, but real i18n support will provide a real
69          * iswspace function.
70          */
71         c = wc;
72         return (c >= 0 && c <= UCHAR_MAX && isspace((unsigned char)c));
73 }
74 
75 #endif
76 
77 #ifndef iswpunct
78 
79 int
iswpunct(wc)80 iswpunct(wc)
81         wint_t          wc;
82 {
83         long            c;
84 
85         /*
86          * Assume characters over 256 are letters.  Assume characters
87          * under 256 are either ASCII or Latin-1.  These are dumb
88          * assumptions, but real i18n support will provide a real
89          * iswpunct function.
90          */
91         c = wc;
92         return (c >= 0 && c <= UCHAR_MAX && ispunct((unsigned char)c));
93 }
94 
95 #endif
96 
97 #ifndef iswupper
98 
99 int
iswupper(wc)100 iswupper(wc)
101         wint_t          wc;
102 {
103         long            c;
104 
105         c = wc;
106         return (c >= 0 && c <= UCHAR_MAX && isupper((unsigned char)c));
107 }
108 
109 #endif
110 
111 #ifndef iswlower
112 
113 int
iswlower(wc)114 iswlower(wc)
115         wint_t          wc;
116 {
117         long            c;
118 
119         c = wc;
120         return (c >= 0 && c <= UCHAR_MAX && islower((unsigned char)c));
121 }
122 
123 #endif
124 
125 #ifndef iswdigit
126 
127 int
iswdigit(wc)128 iswdigit(wc)
129         wint_t          wc;
130 {
131         long            c;
132 
133         c = wc;
134         return (c >= 0 && c <= UCHAR_MAX && isdigit((unsigned char)c));
135 }
136 
137 #endif
138 
139 #ifndef iswalnum
140 
141 int
iswalnum(wc)142 iswalnum(wc)
143         wint_t          wc;
144 {
145         long            c;
146 
147         c = wc;
148         return (c >= 0 && c <= UCHAR_MAX && isalnum((unsigned char)c));
149 }
150 
151 #endif
152 
153 #ifndef towupper
154 
155 wint_t
towupper(wc)156 towupper(wc)
157         wint_t          wc;
158 {
159         long            c;
160 
161         c = wc;
162         if (c >= 0 && c <= UCHAR_MAX && islower((unsigned char)c))
163                 return toupper((unsigned char)c);
164         return c;
165 }
166 
167 #endif
168 
169 #ifndef towlower
170 
171 wint_t
towlower(wc)172 towlower(wc)
173         wint_t          wc;
174 {
175         long            c;
176 
177         c = wc;
178         if (c >= 0 && c <= UCHAR_MAX && isupper((unsigned char)c))
179                 return tolower((unsigned char)c);
180         return c;
181 }
182 
183 #endif
184 
185 #endif /* !HAVE_ISWPRINT */
186