comparison src/file-coding.c @ 337:fbbf69b4e8a7 r21-0-66

Import from CVS: tag r21-0-66
author cvs
date Mon, 13 Aug 2007 10:51:02 +0200
parents 70ad99077275
children 7c94d56991e1
comparison
equal deleted inserted replaced
336:fe0a93612022 337:fbbf69b4e8a7
101 unsigned char esc_bytes[8]; 101 unsigned char esc_bytes[8];
102 102
103 /* Index for next byte to store in ISO escape sequence. */ 103 /* Index for next byte to store in ISO escape sequence. */
104 int esc_bytes_index; 104 int esc_bytes_index;
105 105
106 #ifdef ENABLE_COMPOSITE_CHARS
106 /* Stuff seen so far when composing a string. */ 107 /* Stuff seen so far when composing a string. */
107 unsigned_char_dynarr *composite_chars; 108 unsigned_char_dynarr *composite_chars;
109 #endif
108 110
109 /* If we saw an invalid designation sequence for a particular 111 /* If we saw an invalid designation sequence for a particular
110 register, we flag it here and switch to ASCII. The next time we 112 register, we flag it here and switch to ASCII. The next time we
111 see a valid designation for this register, we turn off the flag 113 see a valid designation for this register, we turn off the flag
112 and do the designation normally, but pretend the sequence was 114 and do the designation normally, but pretend the sequence was
1888 str->flags |= CODING_STATE_END; 1890 str->flags |= CODING_STATE_END;
1889 decoding_writer (stream, 0, 0); 1891 decoding_writer (stream, 0, 0);
1890 } 1892 }
1891 Dynarr_free (str->runoff); 1893 Dynarr_free (str->runoff);
1892 #ifdef MULE 1894 #ifdef MULE
1895 #ifdef ENABLE_COMPOSITE_CHARS
1893 if (str->iso2022.composite_chars) 1896 if (str->iso2022.composite_chars)
1894 Dynarr_free (str->iso2022.composite_chars); 1897 Dynarr_free (str->iso2022.composite_chars);
1898 #endif
1895 #endif 1899 #endif
1896 return Lstream_close (str->other_end); 1900 return Lstream_close (str->other_end);
1897 } 1901 }
1898 1902
1899 Lisp_Object 1903 Lisp_Object
3193 iso->register_right = 1; 3197 iso->register_right = 1;
3194 iso->switched_dir_and_no_valid_charset_yet = 0; 3198 iso->switched_dir_and_no_valid_charset_yet = 0;
3195 iso->invalid_switch_dir = 0; 3199 iso->invalid_switch_dir = 0;
3196 iso->output_direction_sequence = 0; 3200 iso->output_direction_sequence = 0;
3197 iso->output_literally = 0; 3201 iso->output_literally = 0;
3202 #ifdef ENABLE_COMPOSITE_CHARS
3198 if (iso->composite_chars) 3203 if (iso->composite_chars)
3199 Dynarr_reset (iso->composite_chars); 3204 Dynarr_reset (iso->composite_chars);
3205 #endif
3200 } 3206 }
3201 3207
3202 static int 3208 static int
3203 fit_to_be_escape_quoted (unsigned char c) 3209 fit_to_be_escape_quoted (unsigned char c)
3204 { 3210 {
3324 reg = 3; half = 1; 3330 reg = 3; half = 1;
3325 goto locking_shift; 3331 goto locking_shift;
3326 3332
3327 /**** composite ****/ 3333 /**** composite ****/
3328 3334
3335 #ifdef ENABLE_COMPOSITE_CHARS
3329 case '0': 3336 case '0':
3330 iso->esc = ISO_ESC_START_COMPOSITE; 3337 iso->esc = ISO_ESC_START_COMPOSITE;
3331 *flags = (*flags & CODING_STATE_ISO2022_LOCK) | 3338 *flags = (*flags & CODING_STATE_ISO2022_LOCK) |
3332 CODING_STATE_COMPOSITE; 3339 CODING_STATE_COMPOSITE;
3333 return 1; 3340 return 1;
3335 case '1': 3342 case '1':
3336 iso->esc = ISO_ESC_END_COMPOSITE; 3343 iso->esc = ISO_ESC_END_COMPOSITE;
3337 *flags = (*flags & CODING_STATE_ISO2022_LOCK) & 3344 *flags = (*flags & CODING_STATE_ISO2022_LOCK) &
3338 ~CODING_STATE_COMPOSITE; 3345 ~CODING_STATE_COMPOSITE;
3339 return 1; 3346 return 1;
3347 #endif /* ENABLE_COMPOSITE_CHARS */
3340 3348
3341 /**** directionality ****/ 3349 /**** directionality ****/
3342 3350
3343 case '[': 3351 case '[':
3344 iso->esc = ISO_ESC_5_11; 3352 iso->esc = ISO_ESC_5_11;
3783 unsigned char c; 3791 unsigned char c;
3784 unsigned int flags, ch; 3792 unsigned int flags, ch;
3785 enum eol_type eol_type; 3793 enum eol_type eol_type;
3786 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 3794 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3787 Lisp_Object coding_system; 3795 Lisp_Object coding_system;
3796 #ifdef ENABLE_COMPOSITE_CHARS
3788 unsigned_char_dynarr *real_dst = dst; 3797 unsigned_char_dynarr *real_dst = dst;
3798 #endif
3789 3799
3790 CODING_STREAM_DECOMPOSE (str, flags, ch); 3800 CODING_STREAM_DECOMPOSE (str, flags, ch);
3791 eol_type = str->eol_type; 3801 eol_type = str->eol_type;
3792 XSETCODING_SYSTEM (coding_system, str->codesys); 3802 XSETCODING_SYSTEM (coding_system, str->codesys);
3793 3803
3804 #ifdef ENABLE_COMPOSITE_CHARS
3794 if (flags & CODING_STATE_COMPOSITE) 3805 if (flags & CODING_STATE_COMPOSITE)
3795 dst = str->iso2022.composite_chars; 3806 dst = str->iso2022.composite_chars;
3807 #endif /* ENABLE_COMPOSITE_CHARS */
3796 3808
3797 while (n--) 3809 while (n--)
3798 { 3810 {
3799 c = *src++; 3811 c = *src++;
3800 if (flags & CODING_STATE_ESCAPE) 3812 if (flags & CODING_STATE_ESCAPE)
3804 3816
3805 if (retval) 3817 if (retval)
3806 { 3818 {
3807 switch (str->iso2022.esc) 3819 switch (str->iso2022.esc)
3808 { 3820 {
3821 #ifdef ENABLE_COMPOSITE_CHARS
3809 case ISO_ESC_START_COMPOSITE: 3822 case ISO_ESC_START_COMPOSITE:
3810 if (str->iso2022.composite_chars) 3823 if (str->iso2022.composite_chars)
3811 Dynarr_reset (str->iso2022.composite_chars); 3824 Dynarr_reset (str->iso2022.composite_chars);
3812 else 3825 else
3813 str->iso2022.composite_chars = Dynarr_new (unsigned_char); 3826 str->iso2022.composite_chars = Dynarr_new (unsigned_char);
3822 dst = real_dst; 3835 dst = real_dst;
3823 len = set_charptr_emchar (comstr, emch); 3836 len = set_charptr_emchar (comstr, emch);
3824 Dynarr_add_many (dst, comstr, len); 3837 Dynarr_add_many (dst, comstr, len);
3825 break; 3838 break;
3826 } 3839 }
3840 #endif /* ENABLE_COMPOSITE_CHARS */
3827 3841
3828 case ISO_ESC_LITERAL: 3842 case ISO_ESC_LITERAL:
3829 DECODE_ADD_BINARY_CHAR (c, dst); 3843 DECODE_ADD_BINARY_CHAR (c, dst);
3830 break; 3844 break;
3831 3845
4107 struct Lisp_Coding_System *codesys = str->codesys; 4121 struct Lisp_Coding_System *codesys = str->codesys;
4108 int i; 4122 int i;
4109 Lisp_Object charset; 4123 Lisp_Object charset;
4110 int half; 4124 int half;
4111 4125
4126 #ifdef ENABLE_COMPOSITE_CHARS
4112 /* flags for handling composite chars. We do a little switcharoo 4127 /* flags for handling composite chars. We do a little switcharoo
4113 on the source while we're outputting the composite char. */ 4128 on the source while we're outputting the composite char. */
4114 unsigned int saved_n = 0; 4129 unsigned int saved_n = 0;
4115 CONST unsigned char *saved_src = NULL; 4130 CONST unsigned char *saved_src = NULL;
4116 int in_composite = 0; 4131 int in_composite = 0;
4132 #endif /* ENABLE_COMPOSITE_CHARS */
4117 4133
4118 CODING_STREAM_DECOMPOSE (str, flags, ch); 4134 CODING_STREAM_DECOMPOSE (str, flags, ch);
4119 eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys); 4135 eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
4120 char_boundary = str->iso2022.current_char_boundary; 4136 char_boundary = str->iso2022.current_char_boundary;
4121 charset = str->iso2022.current_charset; 4137 charset = str->iso2022.current_charset;
4122 half = str->iso2022.current_half; 4138 half = str->iso2022.current_half;
4123 4139
4140 #ifdef ENABLE_COMPOSITE_CHARS
4124 back_to_square_n: 4141 back_to_square_n:
4142 #endif
4125 while (n--) 4143 while (n--)
4126 { 4144 {
4127 c = *src++; 4145 c = *src++;
4128 4146
4129 if (BYTE_ASCII_P (c)) 4147 if (BYTE_ASCII_P (c))
4178 ch = 0; 4196 ch = 0;
4179 charset = CHARSET_BY_LEADING_BYTE (c); 4197 charset = CHARSET_BY_LEADING_BYTE (c);
4180 if (LEADING_BYTE_PREFIX_P(c)) 4198 if (LEADING_BYTE_PREFIX_P(c))
4181 ch = c; 4199 ch = c;
4182 else if (!EQ (charset, Vcharset_control_1) 4200 else if (!EQ (charset, Vcharset_control_1)
4183 && !EQ (charset, Vcharset_composite)) 4201 #ifdef ENABLE_COMPOSITE_CHARS
4202 && !EQ (charset, Vcharset_composite)
4203 #endif
4204 )
4184 { 4205 {
4185 int reg; 4206 int reg;
4186 4207
4187 ensure_correct_direction (XCHARSET_DIRECTION (charset), 4208 ensure_correct_direction (XCHARSET_DIRECTION (charset),
4188 codesys, dst, &flags, 0); 4209 codesys, dst, &flags, 0);
4298 Dynarr_add (dst, c & charmask); 4319 Dynarr_add (dst, c & charmask);
4299 ch = 0; 4320 ch = 0;
4300 } 4321 }
4301 else if (ch) 4322 else if (ch)
4302 { 4323 {
4324 #ifdef ENABLE_COMPOSITE_CHARS
4303 if (EQ (charset, Vcharset_composite)) 4325 if (EQ (charset, Vcharset_composite))
4304 { 4326 {
4305 if (in_composite) 4327 if (in_composite)
4306 { 4328 {
4307 /* #### Bother! We don't know how to 4329 /* #### Bother! We don't know how to
4321 Dynarr_add (dst, ISO_CODE_ESC); 4343 Dynarr_add (dst, ISO_CODE_ESC);
4322 Dynarr_add (dst, '0'); /* start composing */ 4344 Dynarr_add (dst, '0'); /* start composing */
4323 } 4345 }
4324 } 4346 }
4325 else 4347 else
4348 #endif /* ENABLE_COMPOSITE_CHARS */
4326 { 4349 {
4327 Dynarr_add (dst, ch & charmask); 4350 Dynarr_add (dst, ch & charmask);
4328 Dynarr_add (dst, c & charmask); 4351 Dynarr_add (dst, c & charmask);
4329 } 4352 }
4330 ch = 0; 4353 ch = 0;
4353 } 4376 }
4354 } 4377 }
4355 } 4378 }
4356 } 4379 }
4357 4380
4381 #ifdef ENABLE_COMPOSITE_CHARS
4358 if (in_composite) 4382 if (in_composite)
4359 { 4383 {
4360 n = saved_n; 4384 n = saved_n;
4361 src = saved_src; 4385 src = saved_src;
4362 in_composite = 0; 4386 in_composite = 0;
4363 Dynarr_add (dst, ISO_CODE_ESC); 4387 Dynarr_add (dst, ISO_CODE_ESC);
4364 Dynarr_add (dst, '1'); /* end composing */ 4388 Dynarr_add (dst, '1'); /* end composing */
4365 goto back_to_square_n; /* Wheeeeeeeee ..... */ 4389 goto back_to_square_n; /* Wheeeeeeeee ..... */
4366 } 4390 }
4391 #endif /* ENABLE_COMPOSITE_CHARS */
4367 4392
4368 if (char_boundary && flags & CODING_STATE_END) 4393 if (char_boundary && flags & CODING_STATE_END)
4369 { 4394 {
4370 restore_left_to_right_direction (codesys, dst, &flags, 0); 4395 restore_left_to_right_direction (codesys, dst, &flags, 0);
4371 ensure_normal_shift (str, dst); 4396 ensure_normal_shift (str, dst);
4487 #define FILE_NAME_CODING_SYSTEM \ 4512 #define FILE_NAME_CODING_SYSTEM \
4488 ((NILP (Vfile_name_coding_system) || \ 4513 ((NILP (Vfile_name_coding_system) || \
4489 (EQ ((Vfile_name_coding_system), Qbinary))) ? \ 4514 (EQ ((Vfile_name_coding_system), Qbinary))) ? \
4490 Qnil : Fget_coding_system (Vfile_name_coding_system)) 4515 Qnil : Fget_coding_system (Vfile_name_coding_system))
4491 4516
4492 /* #### not correct for all values of `fmt'! */
4493 #ifdef MULE
4494 #define FMT_CODING_SYSTEM(fmt) \
4495 (((fmt) == FORMAT_FILENAME) ? FILE_NAME_CODING_SYSTEM : \
4496 ((fmt) == FORMAT_CTEXT ) ? Fget_coding_system (Qctext) : \
4497 ((fmt) == FORMAT_TERMINAL) ? FILE_NAME_CODING_SYSTEM : \
4498 Qnil)
4499 #else
4500 #define FMT_CODING_SYSTEM(fmt) \
4501 (((fmt) == FORMAT_FILENAME) ? FILE_NAME_CODING_SYSTEM : \
4502 ((fmt) == FORMAT_TERMINAL) ? FILE_NAME_CODING_SYSTEM : \
4503 Qnil)
4504 #endif
4505
4506 Extbyte * 4517 Extbyte *
4507 convert_to_external_format (CONST Bufbyte *ptr, 4518 convert_to_external_format (CONST Bufbyte *ptr,
4508 Bytecount len, 4519 Bytecount len,
4509 Extcount *len_out, 4520 Extcount *len_out,
4510 enum external_data_format fmt) 4521 enum external_data_format fmt)
4511 { 4522 {
4512 Lisp_Object coding_system = FMT_CODING_SYSTEM (fmt); 4523 Lisp_Object coding_system;
4524
4525 /* #### not correct for all values of `fmt'! */
4526 if (fmt == FORMAT_FILENAME || fmt == FORMAT_TERMINAL)
4527 coding_system = FILE_NAME_CODING_SYSTEM;
4528 #ifdef MULE
4529 else if (fmt == FORMAT_CTEXT)
4530 coding_system = Fget_coding_system (Qctext);
4531 #endif
4532 else
4533 coding_system = Qnil;
4534
4535 /* Lisp_Object coding_system = FMT_CODING_SYSTEM (fmt); */
4513 4536
4514 if (!conversion_out_dynarr) 4537 if (!conversion_out_dynarr)
4515 conversion_out_dynarr = Dynarr_new (Extbyte); 4538 conversion_out_dynarr = Dynarr_new (Extbyte);
4516 else 4539 else
4517 Dynarr_reset (conversion_out_dynarr); 4540 Dynarr_reset (conversion_out_dynarr);
4575 convert_from_external_format (CONST Extbyte *ptr, 4598 convert_from_external_format (CONST Extbyte *ptr,
4576 Extcount len, 4599 Extcount len,
4577 Bytecount *len_out, 4600 Bytecount *len_out,
4578 enum external_data_format fmt) 4601 enum external_data_format fmt)
4579 { 4602 {
4580 Lisp_Object coding_system = FMT_CODING_SYSTEM (fmt); 4603 Lisp_Object coding_system;
4604
4605 /* #### not correct for all values of `fmt'! */
4606 if (fmt == FORMAT_FILENAME || fmt == FORMAT_TERMINAL)
4607 coding_system = FILE_NAME_CODING_SYSTEM;
4608 #ifdef MULE
4609 else if (fmt == FORMAT_CTEXT)
4610 coding_system = Fget_coding_system (Qctext);
4611 #endif
4612 else
4613 coding_system = Qnil;
4614
4615 /* Lisp_Object coding_system = FMT_CODING_SYSTEM (fmt); */
4581 4616
4582 if (!conversion_in_dynarr) 4617 if (!conversion_in_dynarr)
4583 conversion_in_dynarr = Dynarr_new (Bufbyte); 4618 conversion_in_dynarr = Dynarr_new (Bufbyte);
4584 else 4619 else
4585 Dynarr_reset (conversion_in_dynarr); 4620 Dynarr_reset (conversion_in_dynarr);