Mercurial > hg > xemacs-beta
comparison src/mule-coding.c @ 185:3d6bfa290dbd r20-3b19
Import from CVS: tag r20-3b19
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:55:28 +0200 |
parents | e121b013d1f0 |
children | acd284d43ca1 |
comparison
equal
deleted
inserted
replaced
184:bcd2674570bf | 185:3d6bfa290dbd |
---|---|
185 static void mule_decode (Lstream *decoding, CONST unsigned char *src, | 185 static void mule_decode (Lstream *decoding, CONST unsigned char *src, |
186 unsigned_char_dynarr *dst, unsigned int n); | 186 unsigned_char_dynarr *dst, unsigned int n); |
187 static void mule_encode (Lstream *encoding, CONST unsigned char *src, | 187 static void mule_encode (Lstream *encoding, CONST unsigned char *src, |
188 unsigned_char_dynarr *dst, unsigned int n); | 188 unsigned_char_dynarr *dst, unsigned int n); |
189 | 189 |
190 typedef struct codesys_prop codesys_prop; | |
190 struct codesys_prop | 191 struct codesys_prop |
191 { | 192 { |
192 Lisp_Object sym; | 193 Lisp_Object sym; |
193 int prop_type; | 194 int prop_type; |
194 }; | 195 }; |
195 | 196 |
196 typedef struct codesys_prop_dynarr_type | 197 typedef struct |
197 { | 198 { |
198 Dynarr_declare (struct codesys_prop); | 199 Dynarr_declare (codesys_prop); |
199 } codesys_prop_dynarr; | 200 } codesys_prop_dynarr; |
200 | 201 |
201 codesys_prop_dynarr *the_codesys_prop_dynarr; | 202 codesys_prop_dynarr *the_codesys_prop_dynarr; |
202 | 203 |
203 enum codesys_prop_enum | 204 enum codesys_prop_enum |
381 same format when it is written out to a file or process. | 382 same format when it is written out to a file or process. |
382 | 383 |
383 For example, many ISO2022-compliant coding systems (such as Compound | 384 For example, many ISO2022-compliant coding systems (such as Compound |
384 Text, which is used for inter-client data under the X Window System) | 385 Text, which is used for inter-client data under the X Window System) |
385 use escape sequences to switch between different charsets -- Japanese | 386 use escape sequences to switch between different charsets -- Japanese |
386 Kanji, for example, is invoked with \"ESC $ ( B\"; ASCII is invoked | 387 Kanji, for example, is invoked with "ESC $ ( B"; ASCII is invoked |
387 with \"ESC ( B\"; and Cyrillic is invoked with \"ESC - L\". See | 388 with "ESC ( B"; and Cyrillic is invoked with "ESC - L". See |
388 `make-coding-system' for more information. | 389 `make-coding-system' for more information. |
389 | 390 |
390 Coding systems are normally identified using a symbol, and the | 391 Coding systems are normally identified using a symbol, and the |
391 symbol is accepted in place of the actual coding system object whenever | 392 symbol is accepted in place of the actual coding system object whenever |
392 a coding system is called for. (This is similar to how faces work.) | 393 a coding system is called for. (This is similar to how faces work.) |
442 void *coding_system_list_closure) | 443 void *coding_system_list_closure) |
443 { | 444 { |
444 /* This function can GC */ | 445 /* This function can GC */ |
445 Lisp_Object key, contents; | 446 Lisp_Object key, contents; |
446 Lisp_Object *coding_system_list; | 447 Lisp_Object *coding_system_list; |
447 struct coding_system_list_closure *chcl = coding_system_list_closure; | 448 struct coding_system_list_closure *cscl = |
449 (struct coding_system_list_closure *) coding_system_list_closure; | |
448 CVOID_TO_LISP (key, hash_key); | 450 CVOID_TO_LISP (key, hash_key); |
449 VOID_TO_LISP (contents, hash_contents); | 451 VOID_TO_LISP (contents, hash_contents); |
450 coding_system_list = chcl->coding_system_list; | 452 coding_system_list = cscl->coding_system_list; |
451 | 453 |
452 *coding_system_list = Fcons (XCODING_SYSTEM (contents)->name, | 454 *coding_system_list = Fcons (XCODING_SYSTEM (contents)->name, |
453 *coding_system_list); | 455 *coding_system_list); |
454 } | 456 } |
455 | 457 |
481 } | 483 } |
482 | 484 |
483 static struct Lisp_Coding_System * | 485 static struct Lisp_Coding_System * |
484 allocate_coding_system (enum coding_system_type type, Lisp_Object name) | 486 allocate_coding_system (enum coding_system_type type, Lisp_Object name) |
485 { | 487 { |
486 struct Lisp_Coding_System *codesys; | 488 struct Lisp_Coding_System *codesys = |
487 | 489 alloc_lcrecord_type (struct Lisp_Coding_System, lrecord_coding_system); |
488 codesys = (struct Lisp_Coding_System *) | |
489 alloc_lcrecord (sizeof (struct Lisp_Coding_System), lrecord_coding_system); | |
490 | 490 |
491 zero_lcrecord (codesys); | 491 zero_lcrecord (codesys); |
492 CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = Qnil; | 492 CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = Qnil; |
493 CODING_SYSTEM_POST_READ_CONVERSION (codesys) = Qnil; | 493 CODING_SYSTEM_POST_READ_CONVERSION (codesys) = Qnil; |
494 CODING_SYSTEM_EOL_TYPE (codesys) = EOL_AUTODETECT; | 494 CODING_SYSTEM_EOL_TYPE (codesys) = EOL_AUTODETECT; |
674 'force-g2-on-output | 674 'force-g2-on-output |
675 If non-nil, send an explicit designation sequence on output before | 675 If non-nil, send an explicit designation sequence on output before |
676 using the specified register. | 676 using the specified register. |
677 | 677 |
678 'short | 678 'short |
679 If non-nil, use the short forms \"ESC $ @\", \"ESC $ A\", and | 679 If non-nil, use the short forms "ESC $ @", "ESC $ A", and |
680 \"ESC $ B\" on output in place of the full designation sequences | 680 "ESC $ B" on output in place of the full designation sequences |
681 \"ESC $ ( @\", \"ESC $ ( A\", and \"ESC $ ( B\". | 681 "ESC $ ( @", "ESC $ ( A", and "ESC $ ( B". |
682 | 682 |
683 'no-ascii-eol | 683 'no-ascii-eol |
684 If non-nil, don't designate ASCII to G0 at each end of line on output. | 684 If non-nil, don't designate ASCII to G0 at each end of line on output. |
685 Setting this to non-nil also suppresses other state-resetting that | 685 Setting this to non-nil also suppresses other state-resetting that |
686 normally happens at the end of a line. | 686 normally happens at the end of a line. |
701 | 701 |
702 'escape-quoted | 702 'escape-quoted |
703 If non-nil, literal control characters that are the same as | 703 If non-nil, literal control characters that are the same as |
704 the beginning of a recognized ISO2022 or ISO6429 escape sequence | 704 the beginning of a recognized ISO2022 or ISO6429 escape sequence |
705 (in particular, ESC (0x1B), SO (0x0E), SI (0x0F), SS2 (0x8E), | 705 (in particular, ESC (0x1B), SO (0x0E), SI (0x0F), SS2 (0x8E), |
706 SS3 (0x8F), and CSI (0x9B)) are \"quoted\" with an escape character | 706 SS3 (0x8F), and CSI (0x9B)) are "quoted" with an escape character |
707 so that they can be properly distinguished from an escape sequence. | 707 so that they can be properly distinguished from an escape sequence. |
708 (Note that doing this results in a non-portable encoding.) This | 708 (Note that doing this results in a non-portable encoding.) This |
709 encoding flag is used for byte-compiled files. Note that ESC | 709 encoding flag is used for byte-compiled files. Note that ESC |
710 is a good choice for a quoting character because there are no | 710 is a good choice for a quoting character because there are no |
711 escape sequences whose second byte is a character from the Control-0 | 711 escape sequences whose second byte is a character from the Control-0 |
736 */ | 736 */ |
737 (name, type, doc_string, props)) | 737 (name, type, doc_string, props)) |
738 { | 738 { |
739 struct Lisp_Coding_System *codesys; | 739 struct Lisp_Coding_System *codesys; |
740 Lisp_Object rest, key, value; | 740 Lisp_Object rest, key, value; |
741 int ty; | 741 enum coding_system_type ty; |
742 int need_to_setup_eol_systems = 1; | 742 int need_to_setup_eol_systems = 1; |
743 | 743 |
744 /* Convert type to constant */ | 744 /* Convert type to constant */ |
745 if (NILP (type) || EQ (type, Qautomatic_conversion)) | 745 if (NILP (type) || EQ (type, Qautomatic_conversion)) |
746 { ty = CODESYS_AUTODETECT; } | 746 { ty = CODESYS_AUTODETECT; } |
815 else if (EQ (key, Qescape_quoted)) FROB_BOOLEAN_PROPERTY (ESCAPE_QUOTED); | 815 else if (EQ (key, Qescape_quoted)) FROB_BOOLEAN_PROPERTY (ESCAPE_QUOTED); |
816 | 816 |
817 else if (EQ (key, Qinput_charset_conversion)) | 817 else if (EQ (key, Qinput_charset_conversion)) |
818 { | 818 { |
819 codesys->iso2022.input_conv = | 819 codesys->iso2022.input_conv = |
820 Dynarr_new (struct charset_conversion_spec); | 820 Dynarr_new (charset_conversion_spec); |
821 parse_charset_conversion_specs (codesys->iso2022.input_conv, | 821 parse_charset_conversion_specs (codesys->iso2022.input_conv, |
822 value); | 822 value); |
823 } | 823 } |
824 else if (EQ (key, Qoutput_charset_conversion)) | 824 else if (EQ (key, Qoutput_charset_conversion)) |
825 { | 825 { |
826 codesys->iso2022.output_conv = | 826 codesys->iso2022.output_conv = |
827 Dynarr_new (struct charset_conversion_spec); | 827 Dynarr_new (charset_conversion_spec); |
828 parse_charset_conversion_specs (codesys->iso2022.output_conv, | 828 parse_charset_conversion_specs (codesys->iso2022.output_conv, |
829 value); | 829 value); |
830 } | 830 } |
831 else | 831 else |
832 signal_simple_error ("Unrecognized property", key); | 832 signal_simple_error ("Unrecognized property", key); |
1478 (start, end, buffer)) | 1478 (start, end, buffer)) |
1479 { | 1479 { |
1480 Lisp_Object val = Qnil; | 1480 Lisp_Object val = Qnil; |
1481 struct buffer *buf = decode_buffer (buffer, 0); | 1481 struct buffer *buf = decode_buffer (buffer, 0); |
1482 Bufpos b, e; | 1482 Bufpos b, e; |
1483 Lisp_Object instream; | 1483 Lisp_Object instream, lb_instream; |
1484 Lstream *istr, *lb_istr; | |
1484 struct detection_state decst; | 1485 struct detection_state decst; |
1486 struct gcpro gcpro1, gcpro2; | |
1485 | 1487 |
1486 get_buffer_range_char (buf, start, end, &b, &e, 0); | 1488 get_buffer_range_char (buf, start, end, &b, &e, 0); |
1487 instream = make_lisp_buffer_input_stream (buf, b, e, 0); | 1489 lb_instream = make_lisp_buffer_input_stream (buf, b, e, 0); |
1488 instream = make_encoding_input_stream (XLSTREAM (instream), | 1490 lb_istr = XLSTREAM (lb_instream); |
1489 Fget_coding_system (Qbinary)); | 1491 instream = make_encoding_input_stream (lb_istr, Fget_coding_system (Qbinary)); |
1492 istr = XLSTREAM (instream); | |
1493 GCPRO2 (instream, lb_instream); | |
1490 memset (&decst, 0, sizeof (decst)); | 1494 memset (&decst, 0, sizeof (decst)); |
1491 decst.eol_type = EOL_AUTODETECT; | 1495 decst.eol_type = EOL_AUTODETECT; |
1492 decst.mask = ~0; | 1496 decst.mask = ~0; |
1493 while (1) | 1497 while (1) |
1494 { | 1498 { |
1495 unsigned char random_buffer[4096]; | 1499 unsigned char random_buffer[4096]; |
1496 int nread; | 1500 int nread = Lstream_read (istr, random_buffer, sizeof (random_buffer)); |
1497 | 1501 |
1498 nread = Lstream_read (XLSTREAM (instream), random_buffer, | |
1499 sizeof (random_buffer)); | |
1500 if (!nread) | 1502 if (!nread) |
1501 break; | 1503 break; |
1502 if (detect_coding_type (&decst, random_buffer, nread, 0)) | 1504 if (detect_coding_type (&decst, random_buffer, nread, 0)) |
1503 break; | 1505 break; |
1504 } | 1506 } |
1524 codesys = subsidiary_coding_system (codesys, decst.eol_type); | 1526 codesys = subsidiary_coding_system (codesys, decst.eol_type); |
1525 val = Fcons (codesys, val); | 1527 val = Fcons (codesys, val); |
1526 } | 1528 } |
1527 } | 1529 } |
1528 } | 1530 } |
1531 Lstream_close (istr); | |
1532 UNGCPRO; | |
1533 Lstream_delete (istr); | |
1534 Lstream_delete (lb_istr); | |
1529 return val; | 1535 return val; |
1530 } | 1536 } |
1531 | 1537 |
1532 | 1538 |
1533 /************************************************************************/ | 1539 /************************************************************************/ |
1860 struct decoding_stream *str = DECODING_STREAM_DATA (lstr); | 1866 struct decoding_stream *str = DECODING_STREAM_DATA (lstr); |
1861 Lisp_Object obj; | 1867 Lisp_Object obj; |
1862 | 1868 |
1863 memset (str, 0, sizeof (*str)); | 1869 memset (str, 0, sizeof (*str)); |
1864 str->other_end = stream; | 1870 str->other_end = stream; |
1865 str->runoff = (unsigned_char_dynarr *) Dynarr_new (unsigned char); | 1871 str->runoff = (unsigned_char_dynarr *) Dynarr_new (unsigned_char); |
1866 str->eol_type = EOL_AUTODETECT; | 1872 str->eol_type = EOL_AUTODETECT; |
1867 if (!strcmp (mode, "r") | 1873 if (!strcmp (mode, "r") |
1868 && Lstream_seekable_p (stream)) | 1874 && Lstream_seekable_p (stream)) |
1869 /* We can determine the coding system now. */ | 1875 /* We can determine the coding system now. */ |
1870 determine_real_coding_system (stream, &codesys, &str->eol_type); | 1876 determine_real_coding_system (stream, &codesys, &str->eol_type); |
1962 default: | 1968 default: |
1963 abort (); | 1969 abort (); |
1964 } | 1970 } |
1965 } | 1971 } |
1966 | 1972 |
1967 static Lisp_Object | |
1968 close_both_streams (Lisp_Object cons) | |
1969 { | |
1970 Lisp_Object instream = XCAR (cons); | |
1971 Lisp_Object outstream = XCDR (cons); | |
1972 Lstream_close (XLSTREAM (outstream)); | |
1973 Lstream_close (XLSTREAM (instream)); | |
1974 return Qnil; | |
1975 } | |
1976 | |
1977 DEFUN ("decode-coding-region", Fdecode_coding_region, 3, 4, 0, /* | 1973 DEFUN ("decode-coding-region", Fdecode_coding_region, 3, 4, 0, /* |
1978 Decode the text between START and END which is encoded in CODING-SYSTEM. | 1974 Decode the text between START and END which is encoded in CODING-SYSTEM. |
1979 This is useful if you've read in encoded text from a file without decoding | 1975 This is useful if you've read in encoded text from a file without decoding |
1980 it (e.g. you read in a JIS-formatted file but used the `binary' or | 1976 it (e.g. you read in a JIS-formatted file but used the `binary' or |
1981 `no-conversion' coding system, so that it shows up as \"^[$B!<!+^[(B\"). | 1977 `no-conversion' coding system, so that it shows up as "^[$B!<!+^[(B"). |
1982 Return length of decoded text. | 1978 Return length of decoded text. |
1983 BUFFER defaults to the current buffer if unspecified. | 1979 BUFFER defaults to the current buffer if unspecified. |
1984 */ | 1980 */ |
1985 (start, end, coding_system, buffer)) | 1981 (start, end, coding_system, buffer)) |
1986 { | 1982 { |
1987 Bufpos b, e; | 1983 Bufpos b, e; |
1988 struct buffer *buf = decode_buffer (buffer, 0); | 1984 struct buffer *buf = decode_buffer (buffer, 0); |
1989 Lisp_Object instream, outstream; | 1985 Lisp_Object instream, lb_outstream, de_outstream, outstream; |
1990 int speccount = specpdl_depth (); | 1986 Lstream *istr, *ostr; |
1991 struct gcpro gcpro1, gcpro2; | 1987 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
1992 | 1988 |
1993 get_buffer_range_char (buf, start, end, &b, &e, 0); | 1989 get_buffer_range_char (buf, start, end, &b, &e, 0); |
1994 | 1990 |
1995 barf_if_buffer_read_only (buf, b, e); | 1991 barf_if_buffer_read_only (buf, b, e); |
1996 | 1992 |
1997 coding_system = Fget_coding_system (coding_system); | 1993 coding_system = Fget_coding_system (coding_system); |
1998 instream = make_lisp_buffer_input_stream (buf, b, e, 0); | 1994 instream = make_lisp_buffer_input_stream (buf, b, e, 0); |
1999 outstream = make_lisp_buffer_output_stream (buf, b, 0); | 1995 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0); |
2000 outstream = make_decoding_output_stream (XLSTREAM (outstream), | 1996 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream), |
2001 coding_system); | 1997 coding_system); |
2002 outstream = make_encoding_output_stream (XLSTREAM (outstream), | 1998 outstream = make_encoding_output_stream (XLSTREAM (de_outstream), |
2003 Fget_coding_system (Qbinary)); | 1999 Fget_coding_system (Qbinary)); |
2004 GCPRO2 (instream, outstream); | 2000 istr = XLSTREAM (instream); |
2005 record_unwind_protect (close_both_streams, Fcons (instream, outstream)); | 2001 ostr = XLSTREAM (outstream); |
2002 GCPRO4 (instream, lb_outstream, de_outstream, outstream); | |
2006 | 2003 |
2007 /* The chain of streams looks like this: | 2004 /* The chain of streams looks like this: |
2008 | 2005 |
2009 [BUFFER] <----- send through | 2006 [BUFFER] <----- send through |
2010 ------> [ENCODE AS BINARY] | 2007 ------> [ENCODE AS BINARY] |
2011 ------> [DECODE AS SPECIFIED] | 2008 ------> [DECODE AS SPECIFIED] |
2012 ------> [BUFFER] | 2009 ------> [BUFFER] |
2013 */ | 2010 */ |
2014 | 2011 |
2015 { | 2012 while (1) |
2016 char tempbuf[1024]; /* some random amount */ | 2013 { |
2017 Lstream *in = XLSTREAM(instream); | 2014 char tempbuf[1024]; /* some random amount */ |
2018 Lstream *out = XLSTREAM(outstream); | 2015 Bufpos newpos, even_newer_pos; |
2019 Bufpos newpos, even_newer_pos; | 2016 Bufpos oldpos = lisp_buffer_stream_startpos (istr); |
2020 | 2017 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); |
2021 while (1) | 2018 |
2022 { | 2019 if (!size_in_bytes) |
2023 Bufpos oldpos = lisp_buffer_stream_startpos (in); | 2020 break; |
2024 int size_in_bytes = Lstream_read (in, tempbuf, sizeof (tempbuf)); | 2021 newpos = lisp_buffer_stream_startpos (istr); |
2025 if (!size_in_bytes) | 2022 Lstream_write (ostr, tempbuf, size_in_bytes); |
2026 break; | 2023 even_newer_pos = lisp_buffer_stream_startpos (istr); |
2027 newpos = lisp_buffer_stream_startpos (in); | 2024 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos), |
2028 Lstream_write (out, tempbuf, size_in_bytes); | 2025 even_newer_pos, 0); |
2029 even_newer_pos = lisp_buffer_stream_startpos (in); | 2026 } |
2030 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos), | 2027 Lstream_close (istr); |
2031 even_newer_pos, 0); | 2028 Lstream_close (ostr); |
2032 } | |
2033 } | |
2034 | |
2035 unbind_to (speccount, Qnil); | |
2036 UNGCPRO; | 2029 UNGCPRO; |
2030 Lstream_delete (istr); | |
2031 Lstream_delete (ostr); | |
2032 Lstream_delete (XLSTREAM (de_outstream)); | |
2033 Lstream_delete (XLSTREAM (lb_outstream)); | |
2037 return Qnil; | 2034 return Qnil; |
2038 } | 2035 } |
2039 | 2036 |
2040 | 2037 |
2041 /************************************************************************/ | 2038 /************************************************************************/ |
2312 Lstream *lstr = Lstream_new (lstream_encoding, mode); | 2309 Lstream *lstr = Lstream_new (lstream_encoding, mode); |
2313 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr); | 2310 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr); |
2314 Lisp_Object obj; | 2311 Lisp_Object obj; |
2315 | 2312 |
2316 memset (str, 0, sizeof (*str)); | 2313 memset (str, 0, sizeof (*str)); |
2317 str->runoff = (unsigned_char_dynarr *) Dynarr_new (unsigned char); | 2314 str->runoff = Dynarr_new (unsigned_char); |
2318 str->other_end = stream; | 2315 str->other_end = stream; |
2319 set_encoding_stream_coding_system (lstr, codesys); | 2316 set_encoding_stream_coding_system (lstr, codesys); |
2320 XSETLSTREAM (obj, lstr); | 2317 XSETLSTREAM (obj, lstr); |
2321 return obj; | 2318 return obj; |
2322 } | 2319 } |
2374 } | 2371 } |
2375 | 2372 |
2376 DEFUN ("encode-coding-region", Fencode_coding_region, 3, 4, 0, /* | 2373 DEFUN ("encode-coding-region", Fencode_coding_region, 3, 4, 0, /* |
2377 Encode the text between START and END using CODING-SYSTEM. | 2374 Encode the text between START and END using CODING-SYSTEM. |
2378 This will, for example, convert Japanese characters into stuff such as | 2375 This will, for example, convert Japanese characters into stuff such as |
2379 \"^[$B!<!+^[(B\" if you use the JIS encoding. Return length of encoded | 2376 "^[$B!<!+^[(B" if you use the JIS encoding. Return length of encoded |
2380 text. BUFFER defaults to the current buffer if unspecified. | 2377 text. BUFFER defaults to the current buffer if unspecified. |
2381 */ | 2378 */ |
2382 (start, end, coding_system, buffer)) | 2379 (start, end, coding_system, buffer)) |
2383 { | 2380 { |
2384 Bufpos b, e; | 2381 Bufpos b, e; |
2385 struct buffer *buf = decode_buffer (buffer, 0); | 2382 struct buffer *buf = decode_buffer (buffer, 0); |
2386 Lisp_Object instream, outstream; | 2383 Lisp_Object instream, lb_outstream, de_outstream, outstream; |
2387 char tempbuf[1024]; /* some random amount */ | 2384 Lstream *istr, *ostr; |
2388 int speccount = specpdl_depth (); | 2385 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
2389 struct gcpro gcpro1, gcpro2; | |
2390 | 2386 |
2391 get_buffer_range_char (buf, start, end, &b, &e, 0); | 2387 get_buffer_range_char (buf, start, end, &b, &e, 0); |
2392 | 2388 |
2393 barf_if_buffer_read_only (buf, b, e); | 2389 barf_if_buffer_read_only (buf, b, e); |
2394 | 2390 |
2395 coding_system = Fget_coding_system (coding_system); | 2391 coding_system = Fget_coding_system (coding_system); |
2396 instream = make_lisp_buffer_input_stream (buf, b, e, 0); | 2392 instream = make_lisp_buffer_input_stream (buf, b, e, 0); |
2397 outstream = make_lisp_buffer_output_stream (buf, b, 0); | 2393 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0); |
2398 outstream = make_decoding_output_stream (XLSTREAM (outstream), | 2394 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream), |
2399 Fget_coding_system (Qbinary)); | 2395 Fget_coding_system (Qbinary)); |
2400 outstream = make_encoding_output_stream (XLSTREAM (outstream), | 2396 outstream = make_encoding_output_stream (XLSTREAM (de_outstream), |
2401 coding_system); | 2397 coding_system); |
2402 GCPRO2 (instream, outstream); | 2398 istr = XLSTREAM (instream); |
2403 record_unwind_protect (close_both_streams, Fcons (instream, outstream)); | 2399 ostr = XLSTREAM (outstream); |
2400 GCPRO4 (instream, outstream, de_outstream, lb_outstream); | |
2404 /* The chain of streams looks like this: | 2401 /* The chain of streams looks like this: |
2405 | 2402 |
2406 [BUFFER] <----- send through | 2403 [BUFFER] <----- send through |
2407 ------> [ENCODE AS SPECIFIED] | 2404 ------> [ENCODE AS SPECIFIED] |
2408 ------> [DECODE AS BINARY] | 2405 ------> [DECODE AS BINARY] |
2409 ------> [BUFFER] | 2406 ------> [BUFFER] |
2410 */ | 2407 */ |
2411 while (1) | 2408 while (1) |
2412 { | 2409 { |
2413 int size_in_bytes; | 2410 char tempbuf[1024]; /* some random amount */ |
2414 Bufpos oldpos, newpos, even_newer_pos; | 2411 Bufpos newpos, even_newer_pos; |
2415 | 2412 Bufpos oldpos = lisp_buffer_stream_startpos (istr); |
2416 oldpos = lisp_buffer_stream_startpos (XLSTREAM (instream)); | 2413 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); |
2417 size_in_bytes = Lstream_read (XLSTREAM (instream), tempbuf, | 2414 |
2418 sizeof (tempbuf)); | |
2419 if (!size_in_bytes) | 2415 if (!size_in_bytes) |
2420 break; | 2416 break; |
2421 newpos = lisp_buffer_stream_startpos (XLSTREAM (instream)); | 2417 newpos = lisp_buffer_stream_startpos (istr); |
2422 Lstream_write (XLSTREAM (outstream), tempbuf, size_in_bytes); | 2418 Lstream_write (ostr, tempbuf, size_in_bytes); |
2423 even_newer_pos = lisp_buffer_stream_startpos (XLSTREAM (instream)); | 2419 even_newer_pos = lisp_buffer_stream_startpos (istr); |
2424 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos), | 2420 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos), |
2425 even_newer_pos, 0); | 2421 even_newer_pos, 0); |
2426 } | 2422 } |
2427 | 2423 |
2428 { | 2424 { |
2429 Charcount retlen = | 2425 Charcount retlen = |
2430 lisp_buffer_stream_startpos (XLSTREAM (instream)) - b; | 2426 lisp_buffer_stream_startpos (XLSTREAM (instream)) - b; |
2431 unbind_to (speccount, Qnil); | 2427 Lstream_close (istr); |
2428 Lstream_close (ostr); | |
2432 UNGCPRO; | 2429 UNGCPRO; |
2430 Lstream_delete (istr); | |
2431 Lstream_delete (ostr); | |
2432 Lstream_delete (XLSTREAM (de_outstream)); | |
2433 Lstream_delete (XLSTREAM (lb_outstream)); | |
2433 return make_int (retlen); | 2434 return make_int (retlen); |
2434 } | 2435 } |
2435 } | 2436 } |
2436 | 2437 |
2437 | 2438 |
3769 { | 3770 { |
3770 case ISO_ESC_START_COMPOSITE: | 3771 case ISO_ESC_START_COMPOSITE: |
3771 if (str->iso2022.composite_chars) | 3772 if (str->iso2022.composite_chars) |
3772 Dynarr_reset (str->iso2022.composite_chars); | 3773 Dynarr_reset (str->iso2022.composite_chars); |
3773 else | 3774 else |
3774 str->iso2022.composite_chars = Dynarr_new (unsigned char); | 3775 str->iso2022.composite_chars = Dynarr_new (unsigned_char); |
3775 dst = str->iso2022.composite_chars; | 3776 dst = str->iso2022.composite_chars; |
3776 break; | 3777 break; |
3777 case ISO_ESC_END_COMPOSITE: | 3778 case ISO_ESC_END_COMPOSITE: |
3778 { | 3779 { |
3779 Bufbyte comstr[MAX_EMCHAR_LEN]; | 3780 Bufbyte comstr[MAX_EMCHAR_LEN]; |
4438 | 4439 |
4439 /************************************************************************/ | 4440 /************************************************************************/ |
4440 /* Simple internal/external functions */ | 4441 /* Simple internal/external functions */ |
4441 /************************************************************************/ | 4442 /************************************************************************/ |
4442 | 4443 |
4443 static extbyte_dynarr *conversion_out_dynarr; | 4444 static Extbyte_dynarr *conversion_out_dynarr; |
4444 static bufbyte_dynarr *conversion_in_dynarr; | 4445 static Bufbyte_dynarr *conversion_in_dynarr; |
4445 | 4446 |
4446 /* Determine coding system from coding format */ | 4447 /* Determine coding system from coding format */ |
4447 | 4448 |
4448 #define PATHNAME_CODING_SYSTEM \ | 4449 #define PATHNAME_CODING_SYSTEM \ |
4449 ((NILP (Vpathname_coding_system) || \ | 4450 ((NILP (Vpathname_coding_system) || \ |
4490 assert (ptr == end); | 4491 assert (ptr == end); |
4491 #endif | 4492 #endif |
4492 } | 4493 } |
4493 else | 4494 else |
4494 { | 4495 { |
4495 Lisp_Object instream = | 4496 Lisp_Object instream, outstream, da_outstream; |
4496 make_fixed_buffer_input_stream ((unsigned char *) ptr, len); | 4497 Lstream *istr, *ostr; |
4497 Lisp_Object outstream = make_dynarr_output_stream | 4498 struct gcpro gcpro1, gcpro2, gcpro3; |
4499 char tempbuf[1024]; /* some random amount */ | |
4500 | |
4501 instream = make_fixed_buffer_input_stream ((unsigned char *) ptr, len); | |
4502 da_outstream = make_dynarr_output_stream | |
4498 ((unsigned_char_dynarr *) conversion_out_dynarr); | 4503 ((unsigned_char_dynarr *) conversion_out_dynarr); |
4499 struct gcpro gcpro1, gcpro2; | |
4500 char tempbuf[1024]; /* some random amount */ | |
4501 | |
4502 outstream = | 4504 outstream = |
4503 make_encoding_output_stream (XLSTREAM (outstream), coding_system); | 4505 make_encoding_output_stream (XLSTREAM (da_outstream), coding_system); |
4504 GCPRO2 (instream, outstream); /* Necessary?? */ | 4506 istr = XLSTREAM (instream); |
4507 ostr = XLSTREAM (outstream); | |
4508 GCPRO3 (instream, outstream, da_outstream); | |
4505 while (1) | 4509 while (1) |
4506 { | 4510 { |
4507 int size_in_bytes = Lstream_read (XLSTREAM (instream), | 4511 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); |
4508 tempbuf, sizeof (tempbuf)); | |
4509 if (!size_in_bytes) | 4512 if (!size_in_bytes) |
4510 break; | 4513 break; |
4511 Lstream_write (XLSTREAM (outstream), tempbuf, size_in_bytes); | 4514 Lstream_write (ostr, tempbuf, size_in_bytes); |
4512 } | 4515 } |
4513 Lstream_close (XLSTREAM (instream)); | 4516 Lstream_close (istr); |
4514 Lstream_close (XLSTREAM (outstream)); | 4517 Lstream_close (ostr); |
4515 UNGCPRO; | 4518 UNGCPRO; |
4519 Lstream_delete (istr); | |
4520 Lstream_delete (ostr); | |
4521 Lstream_delete (XLSTREAM (da_outstream)); | |
4516 } | 4522 } |
4517 | 4523 |
4518 *len_out = Dynarr_length (conversion_out_dynarr); | 4524 *len_out = Dynarr_length (conversion_out_dynarr); |
4519 Dynarr_add (conversion_out_dynarr, 0); /* remember to zero-terminate! */ | 4525 Dynarr_add (conversion_out_dynarr, 0); /* remember to zero-terminate! */ |
4520 return Dynarr_atp (conversion_out_dynarr, 0); | 4526 return Dynarr_atp (conversion_out_dynarr, 0); |
4542 DECODE_ADD_BINARY_CHAR (c, conversion_in_dynarr); | 4548 DECODE_ADD_BINARY_CHAR (c, conversion_in_dynarr); |
4543 } | 4549 } |
4544 } | 4550 } |
4545 else | 4551 else |
4546 { | 4552 { |
4547 Lisp_Object instream = | 4553 Lisp_Object instream, outstream, da_outstream; |
4548 make_fixed_buffer_input_stream ((unsigned char *) ptr, len); | 4554 Lstream *istr, *ostr; |
4549 Lisp_Object outstream = make_dynarr_output_stream | 4555 struct gcpro gcpro1, gcpro2, gcpro3; |
4556 char tempbuf[1024]; /* some random amount */ | |
4557 | |
4558 instream = make_fixed_buffer_input_stream ((unsigned char *) ptr, len); | |
4559 da_outstream = make_dynarr_output_stream | |
4550 ((unsigned_char_dynarr *) conversion_in_dynarr); | 4560 ((unsigned_char_dynarr *) conversion_in_dynarr); |
4551 struct gcpro gcpro1, gcpro2; | |
4552 char tempbuf[1024]; /* some random amount */ | |
4553 | |
4554 outstream = | 4561 outstream = |
4555 make_decoding_output_stream (XLSTREAM (outstream), coding_system); | 4562 make_decoding_output_stream (XLSTREAM (da_outstream), coding_system); |
4556 GCPRO2 (instream, outstream); /* Necessary?? */ | 4563 istr = XLSTREAM (instream); |
4564 ostr = XLSTREAM (outstream); | |
4565 GCPRO3 (instream, outstream, da_outstream); | |
4557 while (1) | 4566 while (1) |
4558 { | 4567 { |
4559 int size_in_bytes = Lstream_read (XLSTREAM (instream), | 4568 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); |
4560 tempbuf, sizeof (tempbuf)); | |
4561 if (!size_in_bytes) | 4569 if (!size_in_bytes) |
4562 break; | 4570 break; |
4563 Lstream_write (XLSTREAM (outstream), tempbuf, size_in_bytes); | 4571 Lstream_write (ostr, tempbuf, size_in_bytes); |
4564 } | 4572 } |
4565 Lstream_close (XLSTREAM (instream)); | 4573 Lstream_close (istr); |
4566 Lstream_close (XLSTREAM (outstream)); | 4574 Lstream_close (ostr); |
4567 UNGCPRO; | 4575 UNGCPRO; |
4576 Lstream_delete (istr); | |
4577 Lstream_delete (ostr); | |
4578 Lstream_delete (XLSTREAM (da_outstream)); | |
4568 } | 4579 } |
4569 | 4580 |
4570 *len_out = Dynarr_length (conversion_in_dynarr); | 4581 *len_out = Dynarr_length (conversion_in_dynarr); |
4571 Dynarr_add (conversion_in_dynarr, 0); /* remember to zero-terminate! */ | 4582 Dynarr_add (conversion_in_dynarr, 0); /* remember to zero-terminate! */ |
4572 return Dynarr_atp (conversion_in_dynarr, 0); | 4583 return Dynarr_atp (conversion_in_dynarr, 0); |
4757 { | 4768 { |
4758 staticpro (&Vcoding_system_hashtable); | 4769 staticpro (&Vcoding_system_hashtable); |
4759 Vcoding_system_hashtable = make_lisp_hashtable (50, HASHTABLE_NONWEAK, | 4770 Vcoding_system_hashtable = make_lisp_hashtable (50, HASHTABLE_NONWEAK, |
4760 HASHTABLE_EQ); | 4771 HASHTABLE_EQ); |
4761 | 4772 |
4762 the_codesys_prop_dynarr = Dynarr_new (struct codesys_prop); | 4773 the_codesys_prop_dynarr = Dynarr_new (codesys_prop); |
4763 | 4774 |
4764 #define DEFINE_CODESYS_PROP(Prop_Type, Sym) do \ | 4775 #define DEFINE_CODESYS_PROP(Prop_Type, Sym) do \ |
4765 { \ | 4776 { \ |
4766 struct codesys_prop csp; \ | 4777 struct codesys_prop csp; \ |
4767 csp.sym = (Sym); \ | 4778 csp.sym = (Sym); \ |