Mercurial > emacs
comparison src/coding.c @ 55964:49894995b543
(find_safe_codings): Check NILP (safe_codings) only at
the necessary places.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Sun, 06 Jun 2004 23:59:19 +0000 |
| parents | 8f316e69dd4b |
| children | 32381d1c4eab cf8f0a3b5cb4 |
comparison
equal
deleted
inserted
replaced
| 55963:e2a4206075f9 | 55964:49894995b543 |
|---|---|
| 6568 Return a list of coding systems that safely encode the multibyte | 6568 Return a list of coding systems that safely encode the multibyte |
| 6569 text between P and PEND. SAFE_CODINGS, if non-nil, is an alist of | 6569 text between P and PEND. SAFE_CODINGS, if non-nil, is an alist of |
| 6570 possible coding systems. If it is nil, it means that we have not | 6570 possible coding systems. If it is nil, it means that we have not |
| 6571 yet found any coding systems. | 6571 yet found any coding systems. |
| 6572 | 6572 |
| 6573 WORK_TABLE is a copy of the char-table Vchar_coding_system_table. An | 6573 WORK_TABLE a char-table of which element is set to t once the |
| 6574 element of WORK_TABLE is set to t once the element is looked up. | 6574 element is looked up. |
| 6575 | 6575 |
| 6576 If a non-ASCII single byte char is found, set | 6576 If a non-ASCII single byte char is found, set |
| 6577 *single_byte_char_found to 1. */ | 6577 *single_byte_char_found to 1. */ |
| 6578 | 6578 |
| 6579 static Lisp_Object | 6579 static Lisp_Object |
| 6584 { | 6584 { |
| 6585 int c, len; | 6585 int c, len; |
| 6586 Lisp_Object val, ch; | 6586 Lisp_Object val, ch; |
| 6587 Lisp_Object prev, tail; | 6587 Lisp_Object prev, tail; |
| 6588 | 6588 |
| 6589 if (NILP (safe_codings)) | |
| 6590 goto done_safe_codings; | |
| 6589 while (p < pend) | 6591 while (p < pend) |
| 6590 { | 6592 { |
| 6591 c = STRING_CHAR_AND_LENGTH (p, pend - p, len); | 6593 c = STRING_CHAR_AND_LENGTH (p, pend - p, len); |
| 6592 p += len; | 6594 p += len; |
| 6593 if (ASCII_BYTE_P (c)) | 6595 if (ASCII_BYTE_P (c)) |
| 6594 /* We can ignore ASCII characters here. */ | 6596 /* We can ignore ASCII characters here. */ |
| 6595 continue; | 6597 continue; |
| 6596 if (SINGLE_BYTE_CHAR_P (c)) | 6598 if (SINGLE_BYTE_CHAR_P (c)) |
| 6597 *single_byte_char_found = 1; | 6599 *single_byte_char_found = 1; |
| 6598 if (NILP (safe_codings)) | |
| 6599 /* Already all coding systems are excluded. But, we can't | |
| 6600 terminate the loop here because non-ASCII single-byte char | |
| 6601 must be found. */ | |
| 6602 continue; | |
| 6603 /* Check the safe coding systems for C. */ | 6600 /* Check the safe coding systems for C. */ |
| 6604 ch = make_number (c); | 6601 ch = make_number (c); |
| 6605 val = Faref (work_table, ch); | 6602 val = Faref (work_table, ch); |
| 6606 if (EQ (val, Qt)) | 6603 if (EQ (val, Qt)) |
| 6607 /* This element was already checked. Ignore it. */ | 6604 /* This element was already checked. Ignore it. */ |
| 6675 prev = tail; | 6672 prev = tail; |
| 6676 else | 6673 else |
| 6677 { | 6674 { |
| 6678 /* Exclude this coding system from SAFE_CODINGS. */ | 6675 /* Exclude this coding system from SAFE_CODINGS. */ |
| 6679 if (EQ (tail, safe_codings)) | 6676 if (EQ (tail, safe_codings)) |
| 6680 safe_codings = XCDR (safe_codings); | 6677 { |
| 6678 safe_codings = XCDR (safe_codings); | |
| 6679 if (NILP (safe_codings)) | |
| 6680 goto done_safe_codings; | |
| 6681 } | |
| 6681 else | 6682 else |
| 6682 XSETCDR (prev, XCDR (tail)); | 6683 XSETCDR (prev, XCDR (tail)); |
| 6683 } | 6684 } |
| 6684 } | 6685 } |
| 6685 } | 6686 } |
| 6687 | |
| 6688 done_safe_codings: | |
| 6689 /* If the above loop was terminated before P reaches PEND, it means | |
| 6690 SAFE_CODINGS was set to nil. If we have not yet found an | |
| 6691 non-ASCII single-byte char, check it now. */ | |
| 6692 if (! *single_byte_char_found) | |
| 6693 while (p < pend) | |
| 6694 { | |
| 6695 c = STRING_CHAR_AND_LENGTH (p, pend - p, len); | |
| 6696 p += len; | |
| 6697 if (! ASCII_BYTE_P (c) | |
| 6698 && SINGLE_BYTE_CHAR_P (c)) | |
| 6699 { | |
| 6700 *single_byte_char_found = 1; | |
| 6701 break; | |
| 6702 } | |
| 6703 } | |
| 6686 return safe_codings; | 6704 return safe_codings; |
| 6687 } | 6705 } |
| 6688 | 6706 |
| 6689 DEFUN ("find-coding-systems-region-internal", | 6707 DEFUN ("find-coding-systems-region-internal", |
| 6690 Ffind_coding_systems_region_internal, | 6708 Ffind_coding_systems_region_internal, |
