comparison src/coding.c @ 50765:43076e9d9aaa

(coding_system_accept_latin_extra_p): Delete this function. (find_safe_codings): Pay attention to the property tranlsation-table-for-encode of each codings. (syms_of_coding): Give Qtranslation_table the extra slot number 2.
author Kenichi Handa <handa@m17n.org>
date Thu, 01 May 2003 04:34:57 +0000
parents db1e3303096f
children 0aba658cfdd2
comparison
equal deleted inserted replaced
50764:394622821e83 50765:43076e9d9aaa
6395 SBYTES (string) + 1, 6395 SBYTES (string) + 1,
6396 !NILP (highest), 6396 !NILP (highest),
6397 STRING_MULTIBYTE (string)); 6397 STRING_MULTIBYTE (string));
6398 } 6398 }
6399 6399
6400 static int coding_system_accept_latin_extra_p P_ ((Lisp_Object));
6401
6402 static int
6403 coding_system_accept_latin_extra_p (coding_system)
6404 Lisp_Object coding_system;
6405 {
6406 Lisp_Object coding_spec, coding_type, flags;
6407
6408 coding_spec = Fget (coding_system, Qcoding_system);
6409 if (! VECTORP (coding_spec)
6410 || ASIZE (coding_spec) != 5)
6411 return 0;
6412 coding_type = AREF (coding_spec, 0);
6413 if (! EQ (coding_type, make_number (2)))
6414 return 0;
6415 flags = AREF (coding_spec, 4);
6416 return (VECTORP (flags)
6417 && ! NILP (AREF (flags, CODING_FLAG_ISO_LATIN_EXTRA)));
6418 }
6419
6420 /* Subroutine for Fsafe_coding_systems_region_internal. 6400 /* Subroutine for Fsafe_coding_systems_region_internal.
6421 6401
6422 Return a list of coding systems that safely encode the multibyte 6402 Return a list of coding systems that safely encode the multibyte
6423 text between P and PEND. SAFE_CODINGS, if non-nil, is a list of 6403 text between P and PEND. SAFE_CODINGS, if non-nil, is an alist of
6424 possible coding systems. If it is nil, it means that we have not 6404 possible coding systems. If it is nil, it means that we have not
6425 yet found any coding systems. 6405 yet found any coding systems.
6426 6406
6427 WORK_TABLE is a copy of the char-table Vchar_coding_system_table. An 6407 WORK_TABLE is a copy of the char-table Vchar_coding_system_table. An
6428 element of WORK_TABLE is set to t once the element is looked up. 6408 element of WORK_TABLE is set to t once the element is looked up.
6448 /* We can ignore ASCII characters here. */ 6428 /* We can ignore ASCII characters here. */
6449 continue; 6429 continue;
6450 if (SINGLE_BYTE_CHAR_P (c)) 6430 if (SINGLE_BYTE_CHAR_P (c))
6451 *single_byte_char_found = 1; 6431 *single_byte_char_found = 1;
6452 if (NILP (safe_codings)) 6432 if (NILP (safe_codings))
6453 /* Already all coding systems are excluded. */ 6433 /* Already all coding systems are excluded. But, we can't
6434 terminate the loop here because non-ASCII single-byte char
6435 must be found. */
6454 continue; 6436 continue;
6455 /* Check the safe coding systems for C. */ 6437 /* Check the safe coding systems for C. */
6456 ch = make_number (c); 6438 ch = make_number (c);
6457 val = Faref (work_table, ch); 6439 val = Faref (work_table, ch);
6458 if (EQ (val, Qt)) 6440 if (EQ (val, Qt))
6461 /* Remember that we checked this element. */ 6443 /* Remember that we checked this element. */
6462 Faset (work_table, ch, Qt); 6444 Faset (work_table, ch, Qt);
6463 6445
6464 for (prev = tail = safe_codings; CONSP (tail); tail = XCDR (tail)) 6446 for (prev = tail = safe_codings; CONSP (tail); tail = XCDR (tail))
6465 { 6447 {
6466 val = XCAR (tail); 6448 Lisp_Object elt, translation_table, hash_table, accept_latin_extra;
6467 if (NILP (Faref (XCDR (val), ch)) 6449 int encodable;
6468 && !(SINGLE_BYTE_CHAR_P (c) 6450
6469 && VECTORP (Vlatin_extra_code_table) 6451 elt = XCAR (tail);
6470 && ! NILP (AREF (Vlatin_extra_code_table, c)) 6452 if (CONSP (XCDR (elt)))
6471 && coding_system_accept_latin_extra_p (XCAR (val)))) 6453 {
6454 /* This entry has this format now:
6455 ( CODING SAFE-CHARS TRANSLATION-TABLE HASH-TABLE
6456 ACCEPT-LATIN-EXTRA ) */
6457 val = XCDR (elt);
6458 encodable = ! NILP (Faref (XCAR (val), ch));
6459 if (! encodable)
6460 {
6461 val = XCDR (val);
6462 translation_table = XCAR (val);
6463 hash_table = XCAR (XCDR (val));
6464 accept_latin_extra = XCAR (XCDR (XCDR (val)));
6465 }
6466 }
6467 else
6468 {
6469 /* This entry has this format now: ( CODING . SAFE-CHARS) */
6470 encodable = ! NILP (Faref (XCDR (elt), ch));
6471 if (! encodable)
6472 {
6473 /* Transform the format to:
6474 ( CODING SAFE-CHARS TRANSLATION-TABLE HASH-TABLE
6475 ACCEPT-LATIN-EXTRA ) */
6476 val = Fget (XCAR (elt), Qcoding_system);
6477 translation_table
6478 = Fplist_get (AREF (val, 3),
6479 Qtranslation_table_for_encode);
6480 if (SYMBOLP (translation_table))
6481 translation_table = Fget (translation_table,
6482 Qtranslation_table);
6483 hash_table
6484 = (CHAR_TABLE_P (translation_table)
6485 ? XCHAR_TABLE (translation_table)->extras[1]
6486 : Qnil);
6487 accept_latin_extra
6488 = ((EQ (AREF (val, 0), make_number (2))
6489 && VECTORP (AREF (val, 4)))
6490 ? AREF (AREF (val, 4), CODING_FLAG_ISO_LATIN_EXTRA)
6491 : Qnil);
6492 XSETCAR (tail, list5 (XCAR (elt), XCDR (elt),
6493 translation_table, hash_table,
6494 accept_latin_extra));
6495 }
6496 }
6497
6498 if (! encodable
6499 && ((CHAR_TABLE_P (translation_table)
6500 && ! NILP (Faref (translation_table, ch)))
6501 || (HASH_TABLE_P (hash_table)
6502 && ! NILP (Fgethash (ch, hash_table, Qnil)))
6503 || (SINGLE_BYTE_CHAR_P (c)
6504 && ! NILP (accept_latin_extra)
6505 && VECTORP (Vlatin_extra_code_table)
6506 && ! NILP (AREF (Vlatin_extra_code_table, c)))))
6507 encodable = 1;
6508 if (encodable)
6509 prev = tail;
6510 else
6472 { 6511 {
6473 /* Exclued this coding system from SAFE_CODINGS. */ 6512 /* Exclued this coding system from SAFE_CODINGS. */
6474 if (EQ (tail, safe_codings)) 6513 if (EQ (tail, safe_codings))
6475 safe_codings = XCDR (safe_codings); 6514 safe_codings = XCDR (safe_codings);
6476 else 6515 else
6477 XSETCDR (prev, XCDR (tail)); 6516 XSETCDR (prev, XCDR (tail));
6478 } 6517 }
6479 else
6480 prev = tail;
6481 } 6518 }
6482 } 6519 }
6483 return safe_codings; 6520 return safe_codings;
6484 } 6521 }
6485 6522
7396 Vcoding_system_safe_chars = Fcons (Qnil, Qnil); 7433 Vcoding_system_safe_chars = Fcons (Qnil, Qnil);
7397 staticpro (&Vcoding_system_safe_chars); 7434 staticpro (&Vcoding_system_safe_chars);
7398 7435
7399 Qtranslation_table = intern ("translation-table"); 7436 Qtranslation_table = intern ("translation-table");
7400 staticpro (&Qtranslation_table); 7437 staticpro (&Qtranslation_table);
7401 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1)); 7438 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (2));
7402 7439
7403 Qtranslation_table_id = intern ("translation-table-id"); 7440 Qtranslation_table_id = intern ("translation-table-id");
7404 staticpro (&Qtranslation_table_id); 7441 staticpro (&Qtranslation_table_id);
7405 7442
7406 Qtranslation_table_for_decode = intern ("translation-table-for-decode"); 7443 Qtranslation_table_for_decode = intern ("translation-table-for-decode");