comparison src/coding.c @ 21744:64c815fe1bdc

(shrink_decoding_region): Do not consider LF as ascii if preceded by CR, since that confuses eol decoding. (code_convert_region): When conversion fails with CODING_FINISH_INSUFFICIENT_SRC, was overwriting src with garbage from dst instead of copying from src to dst.
author Richard M. Stallman <rms@gnu.org>
date Fri, 24 Apr 1998 01:05:25 +0000
parents 4097e558fa19
children 376ce06ab12d
comparison
equal deleted inserted replaced
21743:8def83521606 21744:64c815fe1bdc
3780 case coding_type_raw_text: 3780 case coding_type_raw_text:
3781 if (eol_conversion) 3781 if (eol_conversion)
3782 { 3782 {
3783 if (coding->heading_ascii < 0) 3783 if (coding->heading_ascii < 0)
3784 while (begp < endp && *begp != '\r' && *begp < 0x80) begp++; 3784 while (begp < endp && *begp != '\r' && *begp < 0x80) begp++;
3785 while (begp < endp && *(endp - 1) != '\r' && *(endp - 1) < 0x80) 3785 while (begp < endp && endp[-1] != '\r' && endp[-1] < 0x80)
3786 endp--; 3786 endp--;
3787 /* Do not consider LF as ascii if preceded by CR, since that
3788 confuses eol decoding. */
3789 if (begp < endp && endp < endp_orig && endp[-1] == '\r' && endp[0] == '\n')
3790 endp++;
3787 } 3791 }
3788 else 3792 else
3789 begp = endp; 3793 begp = endp;
3790 break; 3794 break;
3791 3795
3803 second byte of SJIS or BIG5 code. */ 3807 second byte of SJIS or BIG5 code. */
3804 if (eol_conversion) 3808 if (eol_conversion)
3805 while (begp < endp && endp[-1] < 0x80 && endp[-1] != '\r') endp--; 3809 while (begp < endp && endp[-1] < 0x80 && endp[-1] != '\r') endp--;
3806 else 3810 else
3807 while (begp < endp && endp[-1] < 0x80) endp--; 3811 while (begp < endp && endp[-1] < 0x80) endp--;
3812 /* Do not consider LF as ascii if preceded by CR, since that
3813 confuses eol decoding. */
3814 if (begp < endp && endp < endp_orig && endp[-1] == '\r' && endp[0] == '\n')
3815 endp++;
3808 if (begp < endp && endp < endp_orig && endp[-1] >= 0x80) 3816 if (begp < endp && endp < endp_orig && endp[-1] >= 0x80)
3809 endp++; 3817 endp++;
3810 break; 3818 break;
3811 3819
3812 default: /* i.e. case coding_type_iso2022: */ 3820 default: /* i.e. case coding_type_iso2022: */
3827 /* We can skip all ASCII characters at the tail. */ 3835 /* We can skip all ASCII characters at the tail. */
3828 if (eol_conversion) 3836 if (eol_conversion)
3829 while (begp < endp && (c = endp[-1]) < 0x80 && c != '\r') endp--; 3837 while (begp < endp && (c = endp[-1]) < 0x80 && c != '\r') endp--;
3830 else 3838 else
3831 while (begp < endp && endp[-1] < 0x80) endp--; 3839 while (begp < endp && endp[-1] < 0x80) endp--;
3840 /* Do not consider LF as ascii if preceded by CR, since that
3841 confuses eol decoding. */
3842 if (begp < endp && endp < endp_orig && endp[-1] == '\r' && endp[0] == '\n')
3843 endp++;
3832 break; 3844 break;
3833 3845
3834 case CODING_CATEGORY_IDX_ISO_7: 3846 case CODING_CATEGORY_IDX_ISO_7:
3835 case CODING_CATEGORY_IDX_ISO_7_TIGHT: 3847 case CODING_CATEGORY_IDX_ISO_7_TIGHT:
3836 /* We can skip all charactes at the tail except for ESC and 3848 /* We can skip all charactes at the tail except for ESC and
3841 endp--; 3853 endp--;
3842 else 3854 else
3843 while (begp < endp 3855 while (begp < endp
3844 && (c = endp[-1]) < 0x80 && c != ISO_CODE_ESC) 3856 && (c = endp[-1]) < 0x80 && c != ISO_CODE_ESC)
3845 endp--; 3857 endp--;
3858 /* Do not consider LF as ascii if preceded by CR, since that
3859 confuses eol decoding. */
3860 if (begp < endp && endp < endp_orig && endp[-1] == '\r' && endp[0] == '\n')
3861 endp++;
3846 if (begp < endp && endp[-1] == ISO_CODE_ESC) 3862 if (begp < endp && endp[-1] == ISO_CODE_ESC)
3847 { 3863 {
3848 if (endp + 1 < endp_orig && end[0] == '(' && end[1] == 'B') 3864 if (endp + 1 < endp_orig && end[0] == '(' && end[1] == 'B')
3849 /* This is an ASCII designation sequence. We can 3865 /* This is an ASCII designation sequence. We can
3850 surely skip the tail. */ 3866 surely skip the tail. */
4220 /* The source text ends in invalid codes. Let's just 4236 /* The source text ends in invalid codes. Let's just
4221 make them valid buffer contents, and finish conversion. */ 4237 make them valid buffer contents, and finish conversion. */
4222 inserted += len_byte; 4238 inserted += len_byte;
4223 inserted_byte += len_byte; 4239 inserted_byte += len_byte;
4224 while (len_byte--) 4240 while (len_byte--)
4225 *src++ = *dst++; 4241 *dst++ = *src++;
4226 fake_multibyte = 1; 4242 fake_multibyte = 1;
4227 break; 4243 break;
4228 } 4244 }
4229 if (first) 4245 if (first)
4230 { 4246 {