comparison src/charset.c @ 88475:9d54c1d6cd0a

(load_charset_map): Fix previous change. (read_hex): Don't treat SPC as a comment starter. (decode_char): If CODE_POINT_TO_INDEX retruns -1, always return -1. (Fdecode_char): Fix typo. (CODE_POINT_TO_INDEX): Utilize `code_space_mask' member to check if CODE is valid or not. (Fdefine_charset_internal): Initialize `code_space_mask' member. (encode_char): Before calling CODE_POINT_TO_INDEX, check if CODE is within the range of charset->min_code and carset->max_code.
author Kenichi Handa <handa@m17n.org>
date Fri, 10 May 2002 03:54:48 +0000
parents bae0bd953f61
children 9c3255b975cc
comparison
equal deleted inserted replaced
88474:fcc1029dcac2 88475:9d54c1d6cd0a
116 116
117 Lisp_Object Vcharset_map_directory; 117 Lisp_Object Vcharset_map_directory;
118 118
119 Lisp_Object Vchar_unified_charset_table; 119 Lisp_Object Vchar_unified_charset_table;
120 120
121 #define CODE_POINT_TO_INDEX(charset, code) \ 121 #define CODE_POINT_TO_INDEX(charset, code) \
122 ((charset)->code_linear_p \ 122 ((charset)->code_linear_p \
123 ? (code) - (charset)->min_code \ 123 ? (code) - (charset)->min_code \
124 : ((((code) >> 24) <= (charset)->code_space[13]) \ 124 : (((charset)->code_space_mask[(code) >> 24] & 0x8) \
125 && ((((code) >> 16) & 0xFF) <= (charset)->code_space[9]) \ 125 && ((charset)->code_space_mask[((code) >> 16) & 0xFF] & 0x4) \
126 && ((((code) >> 8) & 0xFF) <= (charset)->code_space[5]) \ 126 && ((charset)->code_space_mask[((code) >> 8) & 0xFF] & 0x2) \
127 && (((code) & 0xFF) <= (charset)->code_space[1])) \ 127 && ((charset)->code_space_mask[(code) & 0xFF] & 0x1)) \
128 ? (((((code) >> 24) - (charset)->code_space[12]) \ 128 ? (((((code) >> 24) - (charset)->code_space[12]) \
129 * (charset)->code_space[11]) \ 129 * (charset)->code_space[11]) \
130 + (((((code) >> 16) & 0xFF) - (charset)->code_space[8]) \ 130 + (((((code) >> 16) & 0xFF) - (charset)->code_space[8]) \
131 * (charset)->code_space[7]) \ 131 * (charset)->code_space[7]) \
132 + (((((code) >> 8) & 0xFF) - (charset)->code_space[4]) \ 132 + (((((code) >> 8) & 0xFF) - (charset)->code_space[4]) \
133 * (charset)->code_space[3]) \ 133 * (charset)->code_space[3]) \
134 + (((code) & 0xFF) - (charset)->code_space[0])) \ 134 + (((code) & 0xFF) - (charset)->code_space[0])) \
135 : -1) 135 : -1)
136 136
137 137
138 /* Convert the character index IDX to code-point CODE for CHARSET. 138 /* Convert the character index IDX to code-point CODE for CHARSET.
139 It is assumed that IDX is in a valid range. */ 139 It is assumed that IDX is in a valid range. */
266 266
267 CHARSET_FAST_MAP_SET (c, fast_map); 267 CHARSET_FAST_MAP_SET (c, fast_map);
268 } 268 }
269 else 269 else
270 { 270 {
271 for (; from <= to; from++) 271 unsigned code = from;
272 int from_index, to_index;
273
274 from_index = CODE_POINT_TO_INDEX (charset, from);
275 if (from == to)
276 to_index = from_index;
277 else
278 to_index = CODE_POINT_TO_INDEX (charset, to);
279 if (from_index < 0 || to_index < 0)
280 continue;
281 while (1)
272 { 282 {
273 int c1 = DECODE_CHAR (charset, from); 283 int c1 = DECODE_CHAR (charset, code);
274 284
275 if (c1 >= 0) 285 if (c1 >= 0)
276 { 286 {
277 CHAR_TABLE_SET (table, c, make_number (c1)); 287 CHAR_TABLE_SET (table, c, make_number (c1));
278 CHAR_TABLE_SET (Vchar_unify_table, c1, c); 288 CHAR_TABLE_SET (Vchar_unify_table, c1, c);
279 if (CHAR_TABLE_P (Vchar_unified_charset_table)) 289 if (CHAR_TABLE_P (Vchar_unified_charset_table))
280 CHAR_TABLE_SET (Vchar_unified_charset_table, c1, 290 CHAR_TABLE_SET (Vchar_unified_charset_table, c1,
281 CHARSET_NAME (charset)); 291 CHARSET_NAME (charset));
282 } 292 }
293 if (from_index == to_index)
294 break;
295 from_index++, c++;
296 code = INDEX_TO_CODE_POINT (charset, from_index);
283 } 297 }
284 } 298 }
285 } 299 }
286 300
287 if (control_flag < 2) 301 if (control_flag < 2)
311 int c; 325 int c;
312 unsigned n; 326 unsigned n;
313 327
314 while ((c = getc (fp)) != EOF) 328 while ((c = getc (fp)) != EOF)
315 { 329 {
316 if (c == '#' || c == ' ') 330 if (c == '#')
317 { 331 {
318 while ((c = getc (fp)) != EOF && c != '\n'); 332 while ((c = getc (fp)) != EOF && c != '\n');
319 } 333 }
320 else if (c == '0') 334 else if (c == '0')
321 { 335 {
646 /* Charset attr vector. */ 660 /* Charset attr vector. */
647 Lisp_Object attrs; 661 Lisp_Object attrs;
648 Lisp_Object val; 662 Lisp_Object val;
649 unsigned hash_code; 663 unsigned hash_code;
650 struct Lisp_Hash_Table *hash_table = XHASH_TABLE (Vcharset_hash_table); 664 struct Lisp_Hash_Table *hash_table = XHASH_TABLE (Vcharset_hash_table);
651 int i; 665 int i, j;
652 struct charset charset; 666 struct charset charset;
653 int id; 667 int id;
654 int dimension; 668 int dimension;
655 int new_definition_p; 669 int new_definition_p;
656 int nchars; 670 int nchars;
699 || (charset.code_space[2] == 256 713 || (charset.code_space[2] == 256
700 && (charset.dimension == 2 714 && (charset.dimension == 2
701 || (charset.code_space[6] == 256 715 || (charset.code_space[6] == 256
702 && (charset.dimension == 3 716 && (charset.dimension == 3
703 || charset.code_space[10] == 256))))); 717 || charset.code_space[10] == 256)))));
718
719 if (! charset.code_linear_p)
720 {
721 charset.code_space_mask = (unsigned char *) xmalloc (256);
722 bzero (charset.code_space_mask, sizeof (charset.code_space_mask));
723 for (i = 0; i < 4; i++)
724 for (j = charset.code_space[i * 4]; j <= charset.code_space[i * 4 + 1];
725 j++)
726 charset.code_space_mask[j] |= (1 << i);
727 }
704 728
705 charset.iso_chars_96 = charset.code_space[2] == 96; 729 charset.iso_chars_96 = charset.code_space[2] == 96;
706 730
707 charset.min_code = (charset.code_space[0] 731 charset.min_code = (charset.code_space[0]
708 | (charset.code_space[4] << 8) 732 | (charset.code_space[4] << 8)
1275 } 1299 }
1276 } 1300 }
1277 else 1301 else
1278 { 1302 {
1279 char_index = CODE_POINT_TO_INDEX (charset, code); 1303 char_index = CODE_POINT_TO_INDEX (charset, code);
1304 if (char_index < 0)
1305 return -1;
1280 1306
1281 if (method == CHARSET_METHOD_MAP) 1307 if (method == CHARSET_METHOD_MAP)
1282 { 1308 {
1283 Lisp_Object decoder; 1309 Lisp_Object decoder;
1284 1310
1348 code = ENCODE_CHAR (this_charset, c); 1374 code = ENCODE_CHAR (this_charset, c);
1349 if (code != CHARSET_INVALID_CODE (this_charset) 1375 if (code != CHARSET_INVALID_CODE (this_charset)
1350 && (code_offset < 0 || code >= code_offset)) 1376 && (code_offset < 0 || code >= code_offset))
1351 { 1377 {
1352 code -= code_offset; 1378 code -= code_offset;
1353 if (CODE_POINT_TO_INDEX (charset, code) >= 0) 1379 if (code >= charset->min_code && code <= charset->max_code
1380 && CODE_POINT_TO_INDEX (charset, code) >= 0)
1354 return code; 1381 return code;
1355 } 1382 }
1356 } 1383 }
1357 return CHARSET_INVALID_CODE (charset); 1384 return CHARSET_INVALID_CODE (charset);
1358 } 1385 }
1404 CHECK_CHARSET_GET_ID (charset, id); 1431 CHECK_CHARSET_GET_ID (charset, id);
1405 if (CONSP (code_point)) 1432 if (CONSP (code_point))
1406 { 1433 {
1407 CHECK_NATNUM (XCAR (code_point)); 1434 CHECK_NATNUM (XCAR (code_point));
1408 CHECK_NATNUM (XCDR (code_point)); 1435 CHECK_NATNUM (XCDR (code_point));
1409 code = (XINT (XCAR (code_point)) << 16) | (XINT (XCAR (code_point))); 1436 code = (XINT (XCAR (code_point)) << 16) | (XINT (XCDR (code_point)));
1410 } 1437 }
1411 else 1438 else
1412 { 1439 {
1413 CHECK_NATNUM (code_point); 1440 CHECK_NATNUM (code_point);
1414 code = XINT (code_point); 1441 code = XINT (code_point);