2 * IRC - Internet Relay Chat, include/common.c
3 * Copyright (C) 1998 Andrea Cocito
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 1, or (at your option)
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.
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
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * CODERS WARNING: DO _NOT_ EDIT THE TABLES IN THIS FILE
23 * a) Edit the table generator below, specifically the makeTables() function
24 * b) Recreate the common.c tables with 'make ctables'.
28 /*=============================================================================
29 * Actual source of the library stuff, not generated when making the tables
34 /*=============================================================================
35 * Headers needed in this source file
40 /*=============================================================================
41 * Functions eventually inlined or visible externally
46 NTL_HDR_strChattr { NTL_SRC_strChattr }
47 NTL_HDR_strCasediff { NTL_SRC_strCasediff }
49 #endif /* !FORCEINLINE */
51 /*=============================================================================
52 * Other functions visible externally
55 int strnChattr(const char *s, const size_t n)
57 register const char *rs = s;
61 x &= NTL_char_attrib[*rs++ - CHAR_MIN];
65 int strCasecmp(const char *a, const char *b)
67 register const char *ra = a;
68 register const char *rb = b;
69 while (toLower(*ra) == toLower(*rb))
77 int strnCasecmp(const char *a, const char *b, const size_t n)
79 register const char *ra = a;
80 register const char *rb = b;
81 register int left = n;
84 while (toLower(*ra) == toLower(*rb))
85 if ((!(*(ra++))) || (!(left--)))
92 /*=============================================================================
93 * Automatically generated tables, don't touch these by hand !
98 * DO not touch anything below this line !
101 const char NTL_tolower_tab[] = {
103 /* x80-x87 */ '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87',
104 /* x88-x8f */ '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f',
105 /* x90-x97 */ '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97',
106 /* x98-x9f */ '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f',
107 /* xa0-xa7 */ '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7',
108 /* xa8-xaf */ '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf',
109 /* xb0-xb7 */ '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', '\xb6', '\xb7',
110 /* xb8-xbf */ '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf',
111 /* xc0-xc7 */ '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7',
112 /* xc8-xcf */ '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef',
113 /* xd0-xd7 */ '\xd0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xd7',
114 /* xd8-xdf */ '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xdf',
115 /* xe0-xe7 */ '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7',
116 /* xe8-xef */ '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef',
117 /* xf0-xf7 */ '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7',
118 /* xf8-xff */ '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff'
120 #endif /* (CHAR_MIN<0) */
121 /* x00-x07 */ '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
122 /* x08-x0f */ '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f',
123 /* x10-x17 */ '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
124 /* x18-x1f */ '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f',
125 /* ' '-x27 */ ' ', '!', '"', '#', '$', '%', '&', '\x27',
126 /* '('-'/' */ '(', ')', '*', '+', ',', '-', '.', '/',
127 /* '0'-'7' */ '0', '1', '2', '3', '4', '5', '6', '7',
128 /* '8'-'?' */ '8', '9', ':', ';', '<', '=', '>', '?',
129 /* '@'-'G' */ '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
130 /* 'H'-'O' */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
131 /* 'P'-'W' */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
132 /* 'X'-'_' */ 'x', 'y', 'z', '{', '|', '}', '~', '_',
133 /* '`'-'g' */ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
134 /* 'h'-'o' */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
135 /* 'p'-'w' */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
136 /* 'x'-x7f */ 'x', 'y', 'z', '{', '|', '}', '~', '\x7f'
139 /* x80-x87 */ '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87',
140 /* x88-x8f */ '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f',
141 /* x90-x97 */ '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97',
142 /* x98-x9f */ '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f',
143 /* xa0-xa7 */ '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7',
144 /* xa8-xaf */ '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf',
145 /* xb0-xb7 */ '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', '\xb6', '\xb7',
146 /* xb8-xbf */ '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf',
147 /* xc0-xc7 */ '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7',
148 /* xc8-xcf */ '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef',
149 /* xd0-xd7 */ '\xd0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xd7',
150 /* xd8-xdf */ '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xdf',
151 /* xe0-xe7 */ '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7',
152 /* xe8-xef */ '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef',
153 /* xf0-xf7 */ '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7',
154 /* xf8-xff */ '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff'
155 #endif /* (!(CHAR_MIN<0)) */
158 const char NTL_toupper_tab[] = {
160 /* x80-x87 */ '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87',
161 /* x88-x8f */ '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f',
162 /* x90-x97 */ '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97',
163 /* x98-x9f */ '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f',
164 /* xa0-xa7 */ '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7',
165 /* xa8-xaf */ '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf',
166 /* xb0-xb7 */ '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', '\xb6', '\xb7',
167 /* xb8-xbf */ '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf',
168 /* xc0-xc7 */ '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7',
169 /* xc8-xcf */ '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf',
170 /* xd0-xd7 */ '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7',
171 /* xd8-xdf */ '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf',
172 /* xe0-xe7 */ '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7',
173 /* xe8-xef */ '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf',
174 /* xf0-xf7 */ '\xf0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xf7',
175 /* xf8-xff */ '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xff'
177 #endif /* (CHAR_MIN<0) */
178 /* x00-x07 */ '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
179 /* x08-x0f */ '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f',
180 /* x10-x17 */ '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
181 /* x18-x1f */ '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f',
182 /* ' '-x27 */ ' ', '!', '"', '#', '$', '%', '&', '\x27',
183 /* '('-'/' */ '(', ')', '*', '+', ',', '-', '.', '/',
184 /* '0'-'7' */ '0', '1', '2', '3', '4', '5', '6', '7',
185 /* '8'-'?' */ '8', '9', ':', ';', '<', '=', '>', '?',
186 /* '@'-'G' */ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
187 /* 'H'-'O' */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
188 /* 'P'-'W' */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
189 /* 'X'-'_' */ 'X', 'Y', 'Z', '[', '\x5c', ']', '^', '_',
190 /* '`'-'g' */ '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
191 /* 'h'-'o' */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
192 /* 'p'-'w' */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
193 /* 'x'-x7f */ 'X', 'Y', 'Z', '[', '\x5c', ']', '^', '\x7f'
196 /* x80-x87 */ '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87',
197 /* x88-x8f */ '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f',
198 /* x90-x97 */ '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97',
199 /* x98-x9f */ '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f',
200 /* xa0-xa7 */ '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7',
201 /* xa8-xaf */ '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf',
202 /* xb0-xb7 */ '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', '\xb6', '\xb7',
203 /* xb8-xbf */ '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf',
204 /* xc0-xc7 */ '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7',
205 /* xc8-xcf */ '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf',
206 /* xd0-xd7 */ '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7',
207 /* xd8-xdf */ '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf',
208 /* xe0-xe7 */ '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7',
209 /* xe8-xef */ '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf',
210 /* xf0-xf7 */ '\xf0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xf7',
211 /* xf8-xff */ '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xff'
212 #endif /* (!(CHAR_MIN<0)) */
215 const unsigned int NTL_char_attrib[] = {
217 /* x80-x87 */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
218 /* x88-x8f */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
219 /* x90-x97 */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
220 /* x98-x9f */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
221 /* xa0-xa7 */ 0x0000, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
222 /* xa8-xaf */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
223 /* xb0-xb7 */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
224 /* xb8-xbf */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
225 /* xc0-xc7 */ 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00,
226 /* xc8-xcf */ 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00,
227 /* xd0-xd7 */ 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x0400,
228 /* xd8-xdf */ 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x0400,
229 /* xe0-xe7 */ 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400,
230 /* xe8-xef */ 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400,
231 /* xf0-xf7 */ 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x0400,
232 /* xf8-xff */ 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x0400
234 #endif /* (CHAR_MIN<0) */
235 /* x00-x07 */ 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0004,
236 /* x08-x0f */ 0x0404, 0x0504, 0x10504, 0x0504, 0x0504, 0x10504, 0x0404, 0x0404,
237 /* x10-x17 */ 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404,
238 /* x18-x1f */ 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404,
239 /* ' '-x27 */ 0x0140, 0x04d0, 0x04d0, 0x04d0, 0x04d0, 0x04d0, 0x04d0, 0x24d0,
240 /* '('-'/' */ 0x04d0, 0x04d0, 0x04d0, 0x04d0, 0x00d0, 0x74d0, 0xe4d0, 0x04d0,
241 /* '0'-'7' */ 0xf459, 0xf459, 0xf459, 0xf459, 0xf459, 0xf459, 0xf459, 0xf459,
242 /* '8'-'?' */ 0xf459, 0xf459, 0x04d0, 0x04d0, 0x04d0, 0x04d0, 0x04d0, 0x04d0,
243 /* '@'-'G' */ 0x04d0, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653,
244 /* 'H'-'O' */ 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653,
245 /* 'P'-'W' */ 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653,
246 /* 'X'-'_' */ 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x7653, 0x74d0,
247 /* '`'-'g' */ 0x34d0, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473,
248 /* 'h'-'o' */ 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473,
249 /* 'p'-'w' */ 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473,
250 /* 'x'-x7f */ 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x7473, 0x0400
253 /* x80-x87 */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
254 /* x88-x8f */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
255 /* x90-x97 */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
256 /* x98-x9f */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
257 /* xa0-xa7 */ 0x0000, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
258 /* xa8-xaf */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
259 /* xb0-xb7 */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
260 /* xb8-xbf */ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
261 /* xc0-xc7 */ 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00,
262 /* xc8-xcf */ 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00,
263 /* xd0-xd7 */ 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x0400,
264 /* xd8-xdf */ 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x2c00, 0x0400,
265 /* xe0-xe7 */ 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400,
266 /* xe8-xef */ 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400,
267 /* xf0-xf7 */ 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x0400,
268 /* xf8-xff */ 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x2400, 0x0400
269 #endif /* (!(CHAR_MIN<0)) */
274 * DO not touch anything above this line !
278 #endif /* !MAKETABLES */
280 /*=============================================================================
282 * The following part of code is NOT included in the actual server's
283 * or library source, it's just used to build the above tables
285 * This should rebuild the actual tables and automatically place them
286 * into this source file, note that this part of code is for developers
287 * only, it's supposed to work on both signed and unsigned chars but I
288 * actually tested it only on signed-char architectures, the code and
289 * macros actually used by the server instead DO work and have been tested
290 * on platforms where0 char is both signed or unsigned, this is true as long
291 * as the <limits.h> macros are set properly and without any need to rebuild
292 * the tables (wich as said an admin should NEVER do, tables need to be rebuilt
293 * only when one wants to really change the results or when one has to
294 * compile on architectures where a char is NOT eight bits [?!], yes
295 * it all is supposed to work in that case too... but I can't test it
296 * because I've not found a machine in the world where this happes).
298 * NEVER -f[un]signed-char on gcc since that does NOT fix the named macros
299 * and you end up in a non-ANSI environment where CHAR_MIN and CHAR_MAX
300 * are _not_ the real limits of a default 'char' type. This is true for
301 * both admins and coders.
313 static void zeroTables(void);
314 static void markString(int macro, const char *s);
315 static void unMarkString(int macro, const char *s);
316 static void markRange(int macro, char from, char to);
317 static void moveMacro(int from, int to);
318 static void setLowHi(const char firstlow, const char lastlow,
321 char NTL_tolower_tab[1 + CHAR_MAX - CHAR_MIN]; /* 256 bytes */
322 char NTL_toupper_tab[1 + CHAR_MAX - CHAR_MIN]; /* 256 bytes */
323 int NTL_char_attrib[1 + CHAR_MAX - CHAR_MIN]; /* 256 ints = 0.5 to 2 kilobytes */
327 * Where we make the tables, edit ONLY this to change the tables.
330 static void makeTables(void)
333 /* Start from a known status */
336 /* Make the very elementary sets */
337 markRange(NTL_LOWER, 'a', 'z');
338 markString(NTL_LOWER, "{|}~");
340 markRange(NTL_UPPER, 'A', 'Z');
341 markString(NTL_UPPER, "[\\]^");
343 markRange(NTL_DIGIT, '0', '9');
345 markRange(NTL_CNTRL, '\000', '\037');
347 markString(NTL_PUNCT, "!\"#$%&'()*+,-./:;<=>?@_`");
349 markString(NTL_SPACE, "\011\012\013\014\015\040");
351 /* Make the derived sets,
352 * WARNING: The order of these calls is important, some depend on
353 * the results of the previous ones ! */
355 moveMacro(NTL_LOWER | NTL_UPPER, NTL_ALPHA);
356 moveMacro(NTL_ALPHA | NTL_DIGIT, NTL_ALNUM);
357 moveMacro(NTL_ALNUM | NTL_PUNCT, NTL_GRAPH);
359 moveMacro(NTL_GRAPH, NTL_PRINT);
360 markString(NTL_PRINT, " ");
362 markRange(NTL_IRCCH, 0, UCHAR_MAX);
363 unMarkString(NTL_IRCCH, "\007\040\054\240");
365 markRange(NTL_IRCCL, '\300', '\326');
366 markRange(NTL_IRCCL, '\330', '\336');
368 moveMacro(NTL_ALNUM, NTL_IRCHN);
369 markString(NTL_IRCHN, "-_."); /* Some DNS might allow '_' per RFC 1033 ! */
371 moveMacro(NTL_DIGIT, NTL_IRCIP);
372 markString(NTL_IRCIP, ".");
374 moveMacro(NTL_DIGIT | NTL_ALPHA, NTL_IRCNK);
375 markString(NTL_IRCNK, "-_`");
377 moveMacro(NTL_ALNUM, NTL_IRCUI);
378 markRange(NTL_IRCUI, '\xe0', '\xf6');
379 markRange(NTL_IRCUI, '\xf8', '\xfe');
380 markRange(NTL_IRCUI, '\xc0', '\xd6');
381 markRange(NTL_IRCUI, '\xd8', '\xde');
382 markString(NTL_IRCUI, ".-_^'`~");
383 markString(NTL_EOL, "\n\r");
385 /* And finally let's take care of the toLower/toUpper stuff */
387 setLowHi('a', 'z', 'A');
388 setLowHi('\xe0', '\xf6', '\xc0');
389 setLowHi('\xf8', '\xfe', '\xd8');
390 setLowHi('{', '~', '[');
392 #ifndef FIXME /* Just to remember that this is to be removed in u10.06 */
393 setLowHi('\xd0', '\xd0', '\xd0'); /* Freeze the 0xD0 lower/upper */
394 setLowHi('\xf0', '\xf0', '\xf0'); /* Freeze the 0xF0 lower/upper */
402 * This is the main program to be executed for -DMAKETABLES
405 static void dumphw(int *p, int beg);
406 static void dumphb(char *p, int beg);
413 /* Make the tables */
416 /* Dump them as ANSI C source to be included below */
418 /* NTL_tolower_tab */
419 printf("const char NTL_tolower_tab[] = {\n");
420 printf("#if (CHAR_MIN<0)\n");
421 i = (int)((char)SCHAR_MIN);
422 dumphb(NTL_tolower_tab, i);
424 printf("#endif /* (CHAR_MIN<0) */\n");
426 dumphb(NTL_tolower_tab, i);
427 printf("#if (!(CHAR_MIN<0))\n");
429 i = (int)((char)SCHAR_MIN);
430 dumphb(NTL_tolower_tab, i);
431 printf("#endif /* (!(CHAR_MIN<0)) */\n");
434 /* NTL_toupper_tab */
435 printf("const char NTL_toupper_tab[] = {\n");
436 printf("#if (CHAR_MIN<0)\n");
437 i = (int)((char)SCHAR_MIN);
438 dumphb(NTL_toupper_tab, i);
440 printf("#endif /* (CHAR_MIN<0) */\n");
442 dumphb(NTL_toupper_tab, i);
443 printf("#if (!(CHAR_MIN<0))\n");
445 i = (int)((char)SCHAR_MIN);
446 dumphb(NTL_toupper_tab, i);
447 printf("#endif /* (!(CHAR_MIN<0)) */\n");
450 /* NTL_char_attrib */
451 printf("const unsigned int NTL_char_attrib[] = {\n");
452 printf("#if (CHAR_MIN<0)\n");
453 i = (int)((char)SCHAR_MIN);
454 dumphw(NTL_char_attrib, i);
456 printf("#endif /* (CHAR_MIN<0) */\n");
458 dumphw(NTL_char_attrib, i);
459 printf("#if (!(CHAR_MIN<0))\n");
461 i = (int)((char)SCHAR_MIN);
462 dumphw(NTL_char_attrib, i);
463 printf("#endif /* (!(CHAR_MIN<0)) */\n");
470 /* A few utility functions for makeTables() */
472 static void zeroTables(void)
475 for (i = CHAR_MIN; i <= CHAR_MAX; i++)
477 NTL_tolower_tab[i - CHAR_MIN] = (char)i; /* Unchanged */
478 NTL_toupper_tab[i - CHAR_MIN] = (char)i; /* Unchanged */
479 NTL_char_attrib[i - CHAR_MIN] = 0x0000; /* Nothing */
483 static void markString(int macro, const char *s)
486 NTL_char_attrib[*(s++) - CHAR_MIN] |= macro;
489 static void unMarkString(int macro, const char *s)
492 NTL_char_attrib[*(s++) - CHAR_MIN] &= ~macro;
495 static void markRange(int macro, char from, char to)
498 for (i = CHAR_MIN; i <= CHAR_MAX; i++)
499 if (((unsigned char)i >= (unsigned char)from)
500 && ((unsigned char)i <= (unsigned char)to))
501 NTL_char_attrib[(char)i - CHAR_MIN] |= macro;
504 static void moveMacro(int from, int to)
507 for (i = CHAR_MIN; i <= CHAR_MAX; i++)
508 if (NTL_char_attrib[i - CHAR_MIN] & from)
509 NTL_char_attrib[i - CHAR_MIN] |= to;
512 static void setLowHi(const char firstlow, const char lastlow,
516 for (i = CHAR_MIN; i <= CHAR_MAX; i++)
517 if (((unsigned char)i >= (unsigned char)firstlow)
518 && ((unsigned char)i <= (unsigned char)lastlow))
520 j = ((int)((char)(i + (int)(firsthi - firstlow))));
521 NTL_tolower_tab[((char)j) - CHAR_MIN] = (char)i;
522 NTL_toupper_tab[((char)i) - CHAR_MIN] = (char)j;
526 /* These are used in main() to actually dump the tables, each function
527 dumps half table as hex/char constants... */
531 static void dumphb(char *tbl, int beg)
534 char *p = &tbl[beg - CHAR_MIN];
536 for (i = 0; i <= SCHAR_MAX; i += ROWSIZE)
544 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c != '\\')
548 printf(" x%02x", ((int)((unsigned char)c)));
552 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c != '\\')
556 printf("x%02x", ((int)((unsigned char)c)));
559 for (j = i; j <= k; j++)
562 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c != '\\')
566 printf(" '\\x%02x'", ((int)((unsigned char)c)));
574 static void dumphw(int *tbl, int beg)
577 int *p = &tbl[beg - CHAR_MIN];
579 for (i = 0; i <= SCHAR_MAX; i += ROWSIZE)
587 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c != '\\')
591 printf(" x%02x", ((int)((unsigned char)c)));
595 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c != '\\')
599 printf("x%02x", ((int)((unsigned char)c)));
602 for (j = i; j <= k; j++)
604 printf(" 0x%04x", p[j] & 0xffffffff);
612 #endif /* MAKETABLES */