1 | /* Character handling in C locale. |
---|
2 | |
---|
3 | These functions work like the corresponding functions in <ctype.h>, |
---|
4 | except that they have the C (POSIX) locale hardwired, whereas the |
---|
5 | <ctype.h> functions' behaviour depends on the current locale set via |
---|
6 | setlocale. |
---|
7 | |
---|
8 | Copyright (C) 2000, 2001 Free Software Foundation, Inc. |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify |
---|
11 | it under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 2 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with this program; if not, write to the Free Software |
---|
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
---|
23 | |
---|
24 | #ifndef C_CTYPE_H |
---|
25 | #define C_CTYPE_H |
---|
26 | |
---|
27 | #ifndef PARAMS |
---|
28 | # if defined (__GNUC__) || __STDC__ |
---|
29 | # define PARAMS(args) args |
---|
30 | # else |
---|
31 | # define PARAMS(args) () |
---|
32 | # endif |
---|
33 | #endif |
---|
34 | |
---|
35 | |
---|
36 | /* Check whether the ASCII optimizations apply. */ |
---|
37 | |
---|
38 | #if ('0' <= '9') \ |
---|
39 | && ('0' + 1 == '1') && ('1' + 1 == '2') && ('2' + 1 == '3') \ |
---|
40 | && ('3' + 1 == '4') && ('4' + 1 == '5') && ('5' + 1 == '6') \ |
---|
41 | && ('6' + 1 == '7') && ('7' + 1 == '8') && ('8' + 1 == '9') |
---|
42 | #define C_CTYPE_CONSECUTIVE_DIGITS 1 |
---|
43 | #endif |
---|
44 | |
---|
45 | #if ('A' <= 'Z') \ |
---|
46 | && ('A' + 1 == 'B') && ('B' + 1 == 'C') && ('C' + 1 == 'D') \ |
---|
47 | && ('D' + 1 == 'E') && ('E' + 1 == 'F') && ('F' + 1 == 'G') \ |
---|
48 | && ('G' + 1 == 'H') && ('H' + 1 == 'I') && ('I' + 1 == 'J') \ |
---|
49 | && ('J' + 1 == 'K') && ('K' + 1 == 'L') && ('L' + 1 == 'M') \ |
---|
50 | && ('M' + 1 == 'N') && ('N' + 1 == 'O') && ('O' + 1 == 'P') \ |
---|
51 | && ('P' + 1 == 'Q') && ('Q' + 1 == 'R') && ('R' + 1 == 'S') \ |
---|
52 | && ('S' + 1 == 'T') && ('T' + 1 == 'U') && ('U' + 1 == 'V') \ |
---|
53 | && ('V' + 1 == 'W') && ('W' + 1 == 'X') && ('X' + 1 == 'Y') \ |
---|
54 | && ('Y' + 1 == 'Z') |
---|
55 | #define C_CTYPE_CONSECUTIVE_UPPERCASE 1 |
---|
56 | #endif |
---|
57 | |
---|
58 | #if ('a' <= 'z') \ |
---|
59 | && ('a' + 1 == 'b') && ('b' + 1 == 'c') && ('c' + 1 == 'd') \ |
---|
60 | && ('d' + 1 == 'e') && ('e' + 1 == 'f') && ('f' + 1 == 'g') \ |
---|
61 | && ('g' + 1 == 'h') && ('h' + 1 == 'i') && ('i' + 1 == 'j') \ |
---|
62 | && ('j' + 1 == 'k') && ('k' + 1 == 'l') && ('l' + 1 == 'm') \ |
---|
63 | && ('m' + 1 == 'n') && ('n' + 1 == 'o') && ('o' + 1 == 'p') \ |
---|
64 | && ('p' + 1 == 'q') && ('q' + 1 == 'r') && ('r' + 1 == 's') \ |
---|
65 | && ('s' + 1 == 't') && ('t' + 1 == 'u') && ('u' + 1 == 'v') \ |
---|
66 | && ('v' + 1 == 'w') && ('w' + 1 == 'x') && ('x' + 1 == 'y') \ |
---|
67 | && ('y' + 1 == 'z') |
---|
68 | #define C_CTYPE_CONSECUTIVE_LOWERCASE 1 |
---|
69 | #endif |
---|
70 | |
---|
71 | #if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ |
---|
72 | && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ |
---|
73 | && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ |
---|
74 | && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ |
---|
75 | && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ |
---|
76 | && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ |
---|
77 | && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ |
---|
78 | && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ |
---|
79 | && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ |
---|
80 | && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ |
---|
81 | && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ |
---|
82 | && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ |
---|
83 | && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ |
---|
84 | && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ |
---|
85 | && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ |
---|
86 | && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ |
---|
87 | && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ |
---|
88 | && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ |
---|
89 | && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ |
---|
90 | && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ |
---|
91 | && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ |
---|
92 | && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ |
---|
93 | && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126) |
---|
94 | /* The character set is ISO-646, not EBCDIC. */ |
---|
95 | #define C_CTYPE_ASCII 1 |
---|
96 | #endif |
---|
97 | |
---|
98 | |
---|
99 | /* Function declarations. */ |
---|
100 | |
---|
101 | extern int c_isascii PARAMS ((int c)); /* not locale dependent */ |
---|
102 | |
---|
103 | extern int c_isalnum PARAMS ((int c)); |
---|
104 | extern int c_isalpha PARAMS ((int c)); |
---|
105 | extern int c_isblank PARAMS ((int c)); |
---|
106 | extern int c_iscntrl PARAMS ((int c)); |
---|
107 | extern int c_isdigit PARAMS ((int c)); |
---|
108 | extern int c_islower PARAMS ((int c)); |
---|
109 | extern int c_isgraph PARAMS ((int c)); |
---|
110 | extern int c_isprint PARAMS ((int c)); |
---|
111 | extern int c_ispunct PARAMS ((int c)); |
---|
112 | extern int c_isspace PARAMS ((int c)); |
---|
113 | extern int c_isupper PARAMS ((int c)); |
---|
114 | extern int c_isxdigit PARAMS ((int c)); |
---|
115 | |
---|
116 | extern int c_tolower PARAMS ((int c)); |
---|
117 | extern int c_toupper PARAMS ((int c)); |
---|
118 | |
---|
119 | |
---|
120 | #if defined __GNUC__ && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ |
---|
121 | |
---|
122 | /* ASCII optimizations. */ |
---|
123 | |
---|
124 | #define c_isascii(c) \ |
---|
125 | ({ int __c = (c); \ |
---|
126 | ((__c & ~0x7f) == 0); \ |
---|
127 | }) |
---|
128 | |
---|
129 | #if C_CTYPE_CONSECUTIVE_DIGITS \ |
---|
130 | && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE |
---|
131 | #define c_isalnum(c) \ |
---|
132 | ({ int __c = (c); \ |
---|
133 | ((__c >= '0' && __c <= '9') \ |
---|
134 | || (__c >= 'A' && __c <= 'Z') \ |
---|
135 | || (__c >= 'a' && __c <= 'z')); \ |
---|
136 | }) |
---|
137 | #endif |
---|
138 | |
---|
139 | #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE |
---|
140 | #define c_isalpha(c) \ |
---|
141 | ({ int __c = (c); \ |
---|
142 | ((__c >= 'A' && __c <= 'Z') || (__c >= 'a' && __c <= 'z')); \ |
---|
143 | }) |
---|
144 | #endif |
---|
145 | |
---|
146 | #define c_isblank(c) \ |
---|
147 | ({ int __c = (c); \ |
---|
148 | (__c == ' ' || __c == '\t'); \ |
---|
149 | }) |
---|
150 | |
---|
151 | #if C_CTYPE_ASCII |
---|
152 | #define c_iscntrl(c) \ |
---|
153 | ({ int __c = (c); \ |
---|
154 | ((__c & ~0x1f) == 0 || __c == 0x7f); \ |
---|
155 | }) |
---|
156 | #endif |
---|
157 | |
---|
158 | #if C_CTYPE_CONSECUTIVE_DIGITS |
---|
159 | #define c_isdigit(c) \ |
---|
160 | ({ int __c = (c); \ |
---|
161 | (__c >= '0' && __c <= '9'); \ |
---|
162 | }) |
---|
163 | #endif |
---|
164 | |
---|
165 | #if C_CTYPE_CONSECUTIVE_LOWERCASE |
---|
166 | #define c_islower(c) \ |
---|
167 | ({ int __c = (c); \ |
---|
168 | (__c >= 'a' && __c <= 'z'); \ |
---|
169 | }) |
---|
170 | #endif |
---|
171 | |
---|
172 | #if C_CTYPE_ASCII |
---|
173 | #define c_isgraph(c) \ |
---|
174 | ({ int __c = (c); \ |
---|
175 | (__c >= '!' && __c <= '~'); \ |
---|
176 | }) |
---|
177 | #endif |
---|
178 | |
---|
179 | #if C_CTYPE_ASCII |
---|
180 | #define c_isprint(c) \ |
---|
181 | ({ int __c = (c); \ |
---|
182 | (__c >= ' ' && __c <= '~'); \ |
---|
183 | }) |
---|
184 | #endif |
---|
185 | |
---|
186 | #if C_CTYPE_ASCII |
---|
187 | #define c_ispunct(c) \ |
---|
188 | ({ int _c = (c); \ |
---|
189 | (c_isgraph (_c) && ! c_isalnum (_c)); \ |
---|
190 | }) |
---|
191 | #endif |
---|
192 | |
---|
193 | #define c_isspace(c) \ |
---|
194 | ({ int __c = (c); \ |
---|
195 | (__c == ' ' || __c == '\t' \ |
---|
196 | || __c == '\n' || __c == '\v' || __c == '\f' || __c == '\r'); \ |
---|
197 | }) |
---|
198 | |
---|
199 | #if C_CTYPE_CONSECUTIVE_UPPERCASE |
---|
200 | #define c_isupper(c) \ |
---|
201 | ({ int __c = (c); \ |
---|
202 | (__c >= 'A' && __c <= 'Z'); \ |
---|
203 | }) |
---|
204 | #endif |
---|
205 | |
---|
206 | #if C_CTYPE_CONSECUTIVE_DIGITS \ |
---|
207 | && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE |
---|
208 | #define c_isxdigit(c) \ |
---|
209 | ({ int __c = (c); \ |
---|
210 | ((__c >= '0' && __c <= '9') \ |
---|
211 | || (__c >= 'A' && __c <= 'F') \ |
---|
212 | || (__c >= 'a' && __c <= 'f')); \ |
---|
213 | }) |
---|
214 | #endif |
---|
215 | |
---|
216 | #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE |
---|
217 | #define c_tolower(c) \ |
---|
218 | ({ int __c = (c); \ |
---|
219 | (__c >= 'A' && __c <= 'Z' ? __c - 'A' + 'a' : __c); \ |
---|
220 | }) |
---|
221 | #define c_toupper(c) \ |
---|
222 | ({ int __c = (c); \ |
---|
223 | (__c >= 'a' && __c <= 'z' ? __c - 'a' + 'A' : __c); \ |
---|
224 | }) |
---|
225 | #endif |
---|
226 | |
---|
227 | #endif /* optimizing for speed */ |
---|
228 | |
---|
229 | #endif /* C_CTYPE_H */ |
---|