comparison src/file-coding.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 8efd647ea9ca
children 70ad99077275
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
140 designation. We didn't output the direction switch 140 designation. We didn't output the direction switch
141 literally because we didn't know about the invalid designation; 141 literally because we didn't know about the invalid designation;
142 but we have to do so now. */ 142 but we have to do so now. */
143 unsigned int output_direction_sequence :1; 143 unsigned int output_direction_sequence :1;
144 }; 144 };
145 #endif 145 #endif /* MULE */
146 Lisp_Object Fcopy_coding_system (Lisp_Object old_coding_system, 146 EXFUN (Fcopy_coding_system, 2);
147 Lisp_Object new_name);
148 #ifdef MULE 147 #ifdef MULE
149 struct detection_state; 148 struct detection_state;
150 static int detect_coding_sjis (struct detection_state *st, 149 static int detect_coding_sjis (struct detection_state *st,
151 CONST unsigned char *src, 150 CONST unsigned char *src,
152 unsigned int n); 151 unsigned int n);
271 270
272 case CODESYS_CCL: 271 case CODESYS_CCL:
273 (markobj) (CODING_SYSTEM_CCL_DECODE (codesys)); 272 (markobj) (CODING_SYSTEM_CCL_DECODE (codesys));
274 (markobj) (CODING_SYSTEM_CCL_ENCODE (codesys)); 273 (markobj) (CODING_SYSTEM_CCL_ENCODE (codesys));
275 break; 274 break;
276 #endif 275 #endif /* MULE */
277 default: 276 default:
278 break; 277 break;
279 } 278 }
280 279
281 (markobj) (CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys)); 280 (markobj) (CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys));
318 { 317 {
319 Dynarr_free (c->iso2022.output_conv); 318 Dynarr_free (c->iso2022.output_conv);
320 c->iso2022.output_conv = 0; 319 c->iso2022.output_conv = 0;
321 } 320 }
322 break; 321 break;
323 #endif 322 #endif /* MULE */
324 default: 323 default:
325 break; 324 break;
326 } 325 }
327 } 326 }
328 } 327 }
354 } 353 }
355 354
356 static void 355 static void
357 setup_eol_coding_systems (struct Lisp_Coding_System *codesys) 356 setup_eol_coding_systems (struct Lisp_Coding_System *codesys)
358 { 357 {
359 Lisp_Object codesys_obj = Qnil; 358 Lisp_Object codesys_obj;
360 int len = string_length (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name); 359 int len = string_length (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name);
361 char *codesys_name = (char *) alloca (len + 7); 360 char *codesys_name = (char *) alloca (len + 7);
362 int mlen = -1; 361 int mlen = -1;
363 char *codesys_mnemonic=0; 362 char *codesys_mnemonic=0;
364 363
371 memcpy (codesys_name, 370 memcpy (codesys_name,
372 string_data (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name), len); 371 string_data (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name), len);
373 372
374 if (STRINGP (CODING_SYSTEM_MNEMONIC (codesys))) 373 if (STRINGP (CODING_SYSTEM_MNEMONIC (codesys)))
375 { 374 {
376 mlen = XSTRING_LENGTH(CODING_SYSTEM_MNEMONIC (codesys)); 375 mlen = XSTRING_LENGTH (CODING_SYSTEM_MNEMONIC (codesys));
377 codesys_mnemonic = (char *) alloca (mlen + 7); 376 codesys_mnemonic = (char *) alloca (mlen + 7);
378 memcpy (codesys_mnemonic, 377 memcpy (codesys_mnemonic,
379 XSTRING_DATA (CODING_SYSTEM_MNEMONIC (codesys)), mlen); 378 XSTRING_DATA (CODING_SYSTEM_MNEMONIC (codesys)), mlen);
380 } 379 }
381 380
382 #define DEFINE_SUB_CODESYS(op_sys, op_sys_abbr, Type) do { \ 381 #define DEFINE_SUB_CODESYS(op_sys, op_sys_abbr, Type) do { \
383 strcpy (codesys_name + len, "-" op_sys); \ 382 strcpy (codesys_name + len, "-" op_sys); \
384 if (mlen != -1) \ 383 if (mlen != -1) \
385 strcpy (codesys_mnemonic + mlen, op_sys_abbr); \ 384 strcpy (codesys_mnemonic + mlen, op_sys_abbr); \
386 codesys_name_sym = intern (codesys_name); \ 385 codesys_name_sym = intern (codesys_name); \
387 sub_codesys_obj = Fcopy_coding_system (codesys_obj, codesys_name_sym); \ 386 sub_codesys_obj = Fcopy_coding_system (codesys_obj, codesys_name_sym); \
388 XCODING_SYSTEM_EOL_TYPE (sub_codesys_obj) = Type; \ 387 XCODING_SYSTEM_EOL_TYPE (sub_codesys_obj) = Type; \
389 if (mlen != -1) \ 388 if (mlen != -1) \
390 XCODING_SYSTEM_MNEMONIC(sub_codesys_obj) = \ 389 XCODING_SYSTEM_MNEMONIC(sub_codesys_obj) = \
391 build_string(codesys_mnemonic); \ 390 build_string (codesys_mnemonic); \
392 CODING_SYSTEM_##Type (codesys) = sub_codesys_obj; \ 391 CODING_SYSTEM_##Type (codesys) = sub_codesys_obj; \
393 } while (0) 392 } while (0)
394 393
395 DEFINE_SUB_CODESYS("unix", "", EOL_LF); 394 DEFINE_SUB_CODESYS("unix", "", EOL_LF);
396 DEFINE_SUB_CODESYS("dos", ":T", EOL_CRLF); 395 DEFINE_SUB_CODESYS("dos", ":T", EOL_CRLF);
397 DEFINE_SUB_CODESYS("mac", ":t", EOL_CR); 396 DEFINE_SUB_CODESYS("mac", ":t", EOL_CR);
398 } 397 }
399 398
400 DEFUN ("coding-system-p", Fcoding_system_p, 1, 1, 0, /* 399 DEFUN ("coding-system-p", Fcoding_system_p, 1, 1, 0, /*
401 T if OBJECT is a coding system. 400 Return t if OBJECT is a coding system.
402 A coding system is an object that defines how text containing multiple 401 A coding system is an object that defines how text containing multiple
403 character sets is encoded into a stream of (typically 8-bit) bytes. 402 character sets is encoded into a stream of (typically 8-bit) bytes.
404 The coding system is used to decode the stream into a series of 403 The coding system is used to decode the stream into a series of
405 characters (which may be from multiple charsets) when the text is read 404 characters (which may be from multiple charsets) when the text is read
406 from a file or process, and is used to encode the text back into the 405 from a file or process, and is used to encode the text back into the
430 If there is no such coding system, nil is returned. Otherwise the 429 If there is no such coding system, nil is returned. Otherwise the
431 associated coding system object is returned. 430 associated coding system object is returned.
432 */ 431 */
433 (coding_system_or_name)) 432 (coding_system_or_name))
434 { 433 {
434 if (CODING_SYSTEMP (coding_system_or_name))
435 return coding_system_or_name;
436
435 if (NILP (coding_system_or_name)) 437 if (NILP (coding_system_or_name))
436 coding_system_or_name = Qbinary; 438 coding_system_or_name = Qbinary;
437 if (CODING_SYSTEMP (coding_system_or_name)) 439 else
438 return coding_system_or_name; 440 CHECK_SYMBOL (coding_system_or_name);
439 CHECK_SYMBOL (coding_system_or_name);
440 441
441 return Fgethash (coding_system_or_name, Vcoding_system_hashtable, Qnil); 442 return Fgethash (coding_system_or_name, Vcoding_system_hashtable, Qnil);
442 } 443 }
443 444
444 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /* 445 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /*
533 else if (type == CODESYS_CCL) 534 else if (type == CODESYS_CCL)
534 { 535 {
535 CODING_SYSTEM_CCL_DECODE (codesys) = Qnil; 536 CODING_SYSTEM_CCL_DECODE (codesys) = Qnil;
536 CODING_SYSTEM_CCL_ENCODE (codesys) = Qnil; 537 CODING_SYSTEM_CCL_ENCODE (codesys) = Qnil;
537 } 538 }
538 #endif 539 #endif /* MULE */
539 CODING_SYSTEM_NAME (codesys) = name; 540 CODING_SYSTEM_NAME (codesys) = name;
540 541
541 return codesys; 542 return codesys;
542 } 543 }
543 544
579 580
580 static Lisp_Object 581 static Lisp_Object
581 unparse_charset_conversion_specs (charset_conversion_spec_dynarr *load_here) 582 unparse_charset_conversion_specs (charset_conversion_spec_dynarr *load_here)
582 { 583 {
583 int i; 584 int i;
584 Lisp_Object result = Qnil; 585 Lisp_Object result;
585 586
586 if (!load_here) 587 if (!load_here)
587 return Qnil; 588 return Qnil;
588 for (i = 0; i < Dynarr_length (load_here); i++) 589 for (i = 0, result = Qnil; i < Dynarr_length (load_here); i++)
589 { 590 {
590 struct charset_conversion_spec *ccs = 591 struct charset_conversion_spec *ccs = Dynarr_atp (load_here, i);
591 Dynarr_atp (load_here, i);
592 result = Fcons (list2 (ccs->from_charset, ccs->to_charset), result); 592 result = Fcons (list2 (ccs->from_charset, ccs->to_charset), result);
593 } 593 }
594 594
595 return Fnreverse (result); 595 return Fnreverse (result);
596 } 596 }
597 597
598 #endif 598 #endif /* MULE */
599 599
600 DEFUN ("make-coding-system", Fmake_coding_system, 2, 4, 0, /* 600 DEFUN ("make-coding-system", Fmake_coding_system, 2, 4, 0, /*
601 Register symbol NAME as a coding system. 601 Register symbol NAME as a coding system.
602 602
603 TYPE describes the conversion method used and should be one of 603 TYPE describes the conversion method used and should be one of
1000 static 1000 static
1001 Lisp_Object coding_system_charset (Lisp_Object coding_system, int gnum) 1001 Lisp_Object coding_system_charset (Lisp_Object coding_system, int gnum)
1002 { 1002 {
1003 Lisp_Object cs 1003 Lisp_Object cs
1004 = XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, gnum); 1004 = XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, gnum);
1005 1005
1006 if (CHARSETP(cs)){ 1006 return CHARSETP (cs) ? XCHARSET_NAME (cs) : Qnil;
1007 return XCHARSET_NAME(cs);
1008 }
1009 else {
1010 return Qnil;
1011 }
1012 } 1007 }
1013 1008
1014 DEFUN ("coding-system-charset", Fcoding_system_charset, 2, 2, 0, /* 1009 DEFUN ("coding-system-charset", Fcoding_system_charset, 2, 2, 0, /*
1015 Return initial charset of CODING-SYSTEM designated to GNUM. 1010 Return initial charset of CODING-SYSTEM designated to GNUM.
1016 GNUM allows 0 .. 3. 1011 GNUM allows 0 .. 3.
1018 (coding_system, gnum)) 1013 (coding_system, gnum))
1019 { 1014 {
1020 coding_system = Fget_coding_system (coding_system); 1015 coding_system = Fget_coding_system (coding_system);
1021 CHECK_INT (gnum); 1016 CHECK_INT (gnum);
1022 1017
1023 return coding_system_charset(coding_system, XINT (gnum)); 1018 return coding_system_charset (coding_system, XINT (gnum));
1024 } 1019 }
1025 #endif 1020 #endif /* MULE */
1026 1021
1027 DEFUN ("coding-system-property", Fcoding_system_property, 2, 2, 0, /* 1022 DEFUN ("coding-system-property", Fcoding_system_property, 2, 2, 0, /*
1028 Return the PROP property of CODING-SYSTEM. 1023 Return the PROP property of CODING-SYSTEM.
1029 */ 1024 */
1030 (coding_system, prop)) 1025 (coding_system, prop))
1499 struct detection_state decst; 1494 struct detection_state decst;
1500 1495
1501 if (*eol_type_in_out == EOL_AUTODETECT) 1496 if (*eol_type_in_out == EOL_AUTODETECT)
1502 *eol_type_in_out = XCODING_SYSTEM_EOL_TYPE (*codesys_in_out); 1497 *eol_type_in_out = XCODING_SYSTEM_EOL_TYPE (*codesys_in_out);
1503 1498
1504 memset (&decst, 0, sizeof (decst)); 1499 xzero (decst);
1505 decst.eol_type = *eol_type_in_out; 1500 decst.eol_type = *eol_type_in_out;
1506 decst.mask = ~0; 1501 decst.mask = ~0;
1507 1502
1508 /* If autodetection is called for, do it now. */ 1503 /* If autodetection is called for, do it now. */
1509 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT || 1504 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT ||
1557 lb_instream = make_lisp_buffer_input_stream (buf, b, e, 0); 1552 lb_instream = make_lisp_buffer_input_stream (buf, b, e, 0);
1558 lb_istr = XLSTREAM (lb_instream); 1553 lb_istr = XLSTREAM (lb_instream);
1559 instream = make_encoding_input_stream (lb_istr, Fget_coding_system (Qbinary)); 1554 instream = make_encoding_input_stream (lb_istr, Fget_coding_system (Qbinary));
1560 istr = XLSTREAM (instream); 1555 istr = XLSTREAM (instream);
1561 GCPRO2 (instream, lb_instream); 1556 GCPRO2 (instream, lb_instream);
1562 memset (&decst, 0, sizeof (decst)); 1557 xzero (decst);
1563 decst.eol_type = EOL_AUTODETECT; 1558 decst.eol_type = EOL_AUTODETECT;
1564 decst.mask = ~0; 1559 decst.mask = ~0;
1565 while (1) 1560 while (1)
1566 { 1561 {
1567 unsigned char random_buffer[4096]; 1562 unsigned char random_buffer[4096];
1725 struct ccl_program ccl; 1720 struct ccl_program ccl;
1726 #endif 1721 #endif
1727 struct detection_state decst; 1722 struct detection_state decst;
1728 }; 1723 };
1729 1724
1730 static int decoding_reader (Lstream *stream, unsigned char *data, int size); 1725 static int decoding_reader (Lstream *stream, unsigned char *data, size_t size);
1731 static int decoding_writer (Lstream *stream, CONST unsigned char *data, int size); 1726 static int decoding_writer (Lstream *stream, CONST unsigned char *data, size_t size);
1732 static int decoding_rewinder (Lstream *stream); 1727 static int decoding_rewinder (Lstream *stream);
1733 static int decoding_seekable_p (Lstream *stream); 1728 static int decoding_seekable_p (Lstream *stream);
1734 static int decoding_flusher (Lstream *stream); 1729 static int decoding_flusher (Lstream *stream);
1735 static int decoding_closer (Lstream *stream); 1730 static int decoding_closer (Lstream *stream);
1736 1731
1760 1755
1761 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream 1756 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream
1762 so we read data from the other end, decode it, and store it into DATA. */ 1757 so we read data from the other end, decode it, and store it into DATA. */
1763 1758
1764 static int 1759 static int
1765 decoding_reader (Lstream *stream, unsigned char *data, int size) 1760 decoding_reader (Lstream *stream, unsigned char *data, size_t size)
1766 { 1761 {
1767 struct decoding_stream *str = DECODING_STREAM_DATA (stream); 1762 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
1768 unsigned char *orig_data = data; 1763 unsigned char *orig_data = data;
1769 int read_size; 1764 int read_size;
1770 int error_occurred = 0; 1765 int error_occurred = 0;
1780 { 1775 {
1781 /* Take data from the runoff if we can. Make sure to take at 1776 /* Take data from the runoff if we can. Make sure to take at
1782 most SIZE bytes, and delete the data from the runoff. */ 1777 most SIZE bytes, and delete the data from the runoff. */
1783 if (Dynarr_length (str->runoff) > 0) 1778 if (Dynarr_length (str->runoff) > 0)
1784 { 1779 {
1785 int chunk = min (size, Dynarr_length (str->runoff)); 1780 size_t chunk = min (size, (size_t) Dynarr_length (str->runoff));
1786 memcpy (data, Dynarr_atp (str->runoff, 0), chunk); 1781 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
1787 Dynarr_delete_many (str->runoff, 0, chunk); 1782 Dynarr_delete_many (str->runoff, 0, chunk);
1788 data += chunk; 1783 data += chunk;
1789 size -= chunk; 1784 size -= chunk;
1790 } 1785 }
1822 else 1817 else
1823 return data - orig_data; 1818 return data - orig_data;
1824 } 1819 }
1825 1820
1826 static int 1821 static int
1827 decoding_writer (Lstream *stream, CONST unsigned char *data, int size) 1822 decoding_writer (Lstream *stream, CONST unsigned char *data, size_t size)
1828 { 1823 {
1829 struct decoding_stream *str = DECODING_STREAM_DATA (stream); 1824 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
1830 int retval; 1825 int retval;
1831 1826
1832 /* Decode all our data into the runoff, and then attempt to write 1827 /* Decode all our data into the runoff, and then attempt to write
1847 reset_decoding_stream (struct decoding_stream *str) 1842 reset_decoding_stream (struct decoding_stream *str)
1848 { 1843 {
1849 #ifdef MULE 1844 #ifdef MULE
1850 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_ISO2022) 1845 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_ISO2022)
1851 { 1846 {
1852 Lisp_Object coding_system = Qnil; 1847 Lisp_Object coding_system;
1853 XSETCODING_SYSTEM (coding_system, str->codesys); 1848 XSETCODING_SYSTEM (coding_system, str->codesys);
1854 reset_iso2022 (coding_system, &str->iso2022); 1849 reset_iso2022 (coding_system, &str->iso2022);
1855 } 1850 }
1856 else if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_CCL) 1851 else if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_CCL)
1857 { 1852 {
1858 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_DECODE (str->codesys)); 1853 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_DECODE (str->codesys));
1859 } 1854 }
1860 #endif 1855 #endif /* MULE */
1861 str->flags = str->ch = 0; 1856 str->flags = str->ch = 0;
1862 } 1857 }
1863 1858
1864 static int 1859 static int
1865 decoding_rewinder (Lstream *stream) 1860 decoding_rewinder (Lstream *stream)
1902 } 1897 }
1903 1898
1904 Lisp_Object 1899 Lisp_Object
1905 decoding_stream_coding_system (Lstream *stream) 1900 decoding_stream_coding_system (Lstream *stream)
1906 { 1901 {
1907 Lisp_Object coding_system = Qnil; 1902 Lisp_Object coding_system;
1908 struct decoding_stream *str = DECODING_STREAM_DATA (stream); 1903 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
1909 1904
1910 XSETCODING_SYSTEM (coding_system, str->codesys); 1905 XSETCODING_SYSTEM (coding_system, str->codesys);
1911 return subsidiary_coding_system (coding_system, str->eol_type); 1906 return subsidiary_coding_system (coding_system, str->eol_type);
1912 } 1907 }
1935 { 1930 {
1936 Lstream *lstr = Lstream_new (lstream_decoding, mode); 1931 Lstream *lstr = Lstream_new (lstream_decoding, mode);
1937 struct decoding_stream *str = DECODING_STREAM_DATA (lstr); 1932 struct decoding_stream *str = DECODING_STREAM_DATA (lstr);
1938 Lisp_Object obj; 1933 Lisp_Object obj;
1939 1934
1940 memset (str, 0, sizeof (*str)); 1935 xzero (*str);
1941 str->other_end = stream; 1936 str->other_end = stream;
1942 str->runoff = (unsigned_char_dynarr *) Dynarr_new (unsigned_char); 1937 str->runoff = (unsigned_char_dynarr *) Dynarr_new (unsigned_char);
1943 str->eol_type = EOL_AUTODETECT; 1938 str->eol_type = EOL_AUTODETECT;
1944 if (!strcmp (mode, "r") 1939 if (!strcmp (mode, "r")
1945 && Lstream_seekable_p (stream)) 1940 && Lstream_seekable_p (stream))
1985 rewind, and start over. */ 1980 rewind, and start over. */
1986 1981
1987 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT || 1982 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT ||
1988 str->eol_type == EOL_AUTODETECT) 1983 str->eol_type == EOL_AUTODETECT)
1989 { 1984 {
1990 Lisp_Object codesys = Qnil; 1985 Lisp_Object codesys;
1991 1986
1992 XSETCODING_SYSTEM (codesys, str->codesys); 1987 XSETCODING_SYSTEM (codesys, str->codesys);
1993 detect_coding_type (&str->decst, src, n, 1988 detect_coding_type (&str->decst, src, n,
1994 CODING_SYSTEM_TYPE (str->codesys) != 1989 CODING_SYSTEM_TYPE (str->codesys) !=
1995 CODESYS_AUTODETECT); 1990 CODESYS_AUTODETECT);
2035 ccl_driver (&str->ccl, src, dst, n, 0); 2030 ccl_driver (&str->ccl, src, dst, n, 0);
2036 break; 2031 break;
2037 case CODESYS_ISO2022: 2032 case CODESYS_ISO2022:
2038 decode_coding_iso2022 (decoding, src, dst, n); 2033 decode_coding_iso2022 (decoding, src, dst, n);
2039 break; 2034 break;
2040 #endif 2035 #endif /* MULE */
2041 default: 2036 default:
2042 abort (); 2037 abort ();
2043 } 2038 }
2044 } 2039 }
2045 2040
2167 } iso2022; 2162 } iso2022;
2168 2163
2169 /* Additional information (the state of the running CCL program) 2164 /* Additional information (the state of the running CCL program)
2170 used by the CCL encoder. */ 2165 used by the CCL encoder. */
2171 struct ccl_program ccl; 2166 struct ccl_program ccl;
2172 #endif 2167 #endif /* MULE */
2173 }; 2168 };
2174 2169
2175 static int encoding_reader (Lstream *stream, unsigned char *data, int size); 2170 static int encoding_reader (Lstream *stream, unsigned char *data, size_t size);
2176 static int encoding_writer (Lstream *stream, CONST unsigned char *data, 2171 static int encoding_writer (Lstream *stream, CONST unsigned char *data,
2177 int size); 2172 size_t size);
2178 static int encoding_rewinder (Lstream *stream); 2173 static int encoding_rewinder (Lstream *stream);
2179 static int encoding_seekable_p (Lstream *stream); 2174 static int encoding_seekable_p (Lstream *stream);
2180 static int encoding_flusher (Lstream *stream); 2175 static int encoding_flusher (Lstream *stream);
2181 static int encoding_closer (Lstream *stream); 2176 static int encoding_closer (Lstream *stream);
2182 2177
2206 2201
2207 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream 2202 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream
2208 so we read data from the other end, encode it, and store it into DATA. */ 2203 so we read data from the other end, encode it, and store it into DATA. */
2209 2204
2210 static int 2205 static int
2211 encoding_reader (Lstream *stream, unsigned char *data, int size) 2206 encoding_reader (Lstream *stream, unsigned char *data, size_t size)
2212 { 2207 {
2213 struct encoding_stream *str = ENCODING_STREAM_DATA (stream); 2208 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
2214 unsigned char *orig_data = data; 2209 unsigned char *orig_data = data;
2215 int read_size; 2210 int read_size;
2216 int error_occurred = 0; 2211 int error_occurred = 0;
2226 { 2221 {
2227 /* Take data from the runoff if we can. Make sure to take at 2222 /* Take data from the runoff if we can. Make sure to take at
2228 most SIZE bytes, and delete the data from the runoff. */ 2223 most SIZE bytes, and delete the data from the runoff. */
2229 if (Dynarr_length (str->runoff) > 0) 2224 if (Dynarr_length (str->runoff) > 0)
2230 { 2225 {
2231 int chunk = min (size, Dynarr_length (str->runoff)); 2226 int chunk = min ((int) size, Dynarr_length (str->runoff));
2232 memcpy (data, Dynarr_atp (str->runoff, 0), chunk); 2227 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
2233 Dynarr_delete_many (str->runoff, 0, chunk); 2228 Dynarr_delete_many (str->runoff, 0, chunk);
2234 data += chunk; 2229 data += chunk;
2235 size -= chunk; 2230 size -= chunk;
2236 } 2231 }
2268 else 2263 else
2269 return data - orig_data; 2264 return data - orig_data;
2270 } 2265 }
2271 2266
2272 static int 2267 static int
2273 encoding_writer (Lstream *stream, CONST unsigned char *data, int size) 2268 encoding_writer (Lstream *stream, CONST unsigned char *data, size_t size)
2274 { 2269 {
2275 struct encoding_stream *str = ENCODING_STREAM_DATA (stream); 2270 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
2276 int retval; 2271 int retval;
2277 2272
2278 /* Encode all our data into the runoff, and then attempt to write 2273 /* Encode all our data into the runoff, and then attempt to write
2290 } 2285 }
2291 2286
2292 static void 2287 static void
2293 reset_encoding_stream (struct encoding_stream *str) 2288 reset_encoding_stream (struct encoding_stream *str)
2294 { 2289 {
2290 #ifdef MULE
2295 switch (CODING_SYSTEM_TYPE (str->codesys)) 2291 switch (CODING_SYSTEM_TYPE (str->codesys))
2296 { 2292 {
2297 #ifdef MULE
2298 case CODESYS_ISO2022: 2293 case CODESYS_ISO2022:
2299 { 2294 {
2300 int i; 2295 int i;
2301 2296
2302 for (i = 0; i < 4; i++) 2297 for (i = 0; i < 4; i++)
2314 break; 2309 break;
2315 } 2310 }
2316 case CODESYS_CCL: 2311 case CODESYS_CCL:
2317 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_ENCODE (str->codesys)); 2312 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_ENCODE (str->codesys));
2318 break; 2313 break;
2319 #endif
2320 default: 2314 default:
2321 break; 2315 break;
2322 } 2316 }
2317 #endif /* MULE */
2323 2318
2324 str->flags = str->ch = 0; 2319 str->flags = str->ch = 0;
2325 } 2320 }
2326 2321
2327 static int 2322 static int
2361 } 2356 }
2362 2357
2363 Lisp_Object 2358 Lisp_Object
2364 encoding_stream_coding_system (Lstream *stream) 2359 encoding_stream_coding_system (Lstream *stream)
2365 { 2360 {
2366 Lisp_Object coding_system = Qnil; 2361 Lisp_Object coding_system;
2367 struct encoding_stream *str = ENCODING_STREAM_DATA (stream); 2362 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
2368 2363
2369 XSETCODING_SYSTEM (coding_system, str->codesys); 2364 XSETCODING_SYSTEM (coding_system, str->codesys);
2370 return coding_system; 2365 return coding_system;
2371 } 2366 }
2385 { 2380 {
2386 Lstream *lstr = Lstream_new (lstream_encoding, mode); 2381 Lstream *lstr = Lstream_new (lstream_encoding, mode);
2387 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr); 2382 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr);
2388 Lisp_Object obj; 2383 Lisp_Object obj;
2389 2384
2390 memset (str, 0, sizeof (*str)); 2385 xzero (*str);
2391 str->runoff = Dynarr_new (unsigned_char); 2386 str->runoff = Dynarr_new (unsigned_char);
2392 str->other_end = stream; 2387 str->other_end = stream;
2393 set_encoding_stream_coding_system (lstr, codesys); 2388 set_encoding_stream_coding_system (lstr, codesys);
2394 XSETLSTREAM (obj, lstr); 2389 XSETLSTREAM (obj, lstr);
2395 return obj; 2390 return obj;
3787 { 3782 {
3788 unsigned char c; 3783 unsigned char c;
3789 unsigned int flags, ch; 3784 unsigned int flags, ch;
3790 enum eol_type eol_type; 3785 enum eol_type eol_type;
3791 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 3786 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3792 Lisp_Object coding_system = Qnil; 3787 Lisp_Object coding_system;
3793 unsigned_char_dynarr *real_dst = dst; 3788 unsigned_char_dynarr *real_dst = dst;
3794 3789
3795 CODING_STREAM_DECOMPOSE (str, flags, ch); 3790 CODING_STREAM_DECOMPOSE (str, flags, ch);
3796 eol_type = str->eol_type; 3791 eol_type = str->eol_type;
3797 XSETCODING_SYSTEM (coding_system, str->codesys); 3792 XSETCODING_SYSTEM (coding_system, str->codesys);
4016 static void 4011 static void
4017 iso2022_designate (Lisp_Object charset, unsigned char reg, 4012 iso2022_designate (Lisp_Object charset, unsigned char reg,
4018 struct encoding_stream *str, unsigned_char_dynarr *dst) 4013 struct encoding_stream *str, unsigned_char_dynarr *dst)
4019 { 4014 {
4020 CONST char *inter94 = "()*+", *inter96= ",-./"; 4015 CONST char *inter94 = "()*+", *inter96= ",-./";
4021 int type; 4016 unsigned int type;
4022 unsigned char final; 4017 unsigned char final;
4023 Lisp_Object old_charset = str->iso2022.charset[reg]; 4018 Lisp_Object old_charset = str->iso2022.charset[reg];
4024 4019
4025 str->iso2022.charset[reg] = charset; 4020 str->iso2022.charset[reg] = charset;
4026 if (!CHARSETP (charset)) 4021 if (!CHARSETP (charset))
4506 (((fmt) == FORMAT_FILENAME) ? FILE_NAME_CODING_SYSTEM : \ 4501 (((fmt) == FORMAT_FILENAME) ? FILE_NAME_CODING_SYSTEM : \
4507 ((fmt) == FORMAT_TERMINAL) ? FILE_NAME_CODING_SYSTEM : \ 4502 ((fmt) == FORMAT_TERMINAL) ? FILE_NAME_CODING_SYSTEM : \
4508 Qnil) 4503 Qnil)
4509 #endif 4504 #endif
4510 4505
4511 extern CONST Extbyte * 4506 Extbyte *
4512 convert_to_external_format (CONST Bufbyte *ptr, 4507 convert_to_external_format (CONST Bufbyte *ptr,
4513 Bytecount len, 4508 Bytecount len,
4514 Extcount *len_out, 4509 Extcount *len_out,
4515 enum external_data_format fmt) 4510 enum external_data_format fmt)
4516 { 4511 {
4574 *len_out = Dynarr_length (conversion_out_dynarr); 4569 *len_out = Dynarr_length (conversion_out_dynarr);
4575 Dynarr_add (conversion_out_dynarr, 0); /* remember to zero-terminate! */ 4570 Dynarr_add (conversion_out_dynarr, 0); /* remember to zero-terminate! */
4576 return Dynarr_atp (conversion_out_dynarr, 0); 4571 return Dynarr_atp (conversion_out_dynarr, 0);
4577 } 4572 }
4578 4573
4579 extern CONST Bufbyte * 4574 Bufbyte *
4580 convert_from_external_format (CONST Extbyte *ptr, 4575 convert_from_external_format (CONST Extbyte *ptr,
4581 Extcount len, 4576 Extcount len,
4582 Bytecount *len_out, 4577 Bytecount *len_out,
4583 enum external_data_format fmt) 4578 enum external_data_format fmt)
4584 { 4579 {
4705 defsymbol (&Qforce_g2_on_output, "force-g2-on-output"); 4700 defsymbol (&Qforce_g2_on_output, "force-g2-on-output");
4706 defsymbol (&Qforce_g3_on_output, "force-g3-on-output"); 4701 defsymbol (&Qforce_g3_on_output, "force-g3-on-output");
4707 defsymbol (&Qno_iso6429, "no-iso6429"); 4702 defsymbol (&Qno_iso6429, "no-iso6429");
4708 defsymbol (&Qinput_charset_conversion, "input-charset-conversion"); 4703 defsymbol (&Qinput_charset_conversion, "input-charset-conversion");
4709 defsymbol (&Qoutput_charset_conversion, "output-charset-conversion"); 4704 defsymbol (&Qoutput_charset_conversion, "output-charset-conversion");
4705
4710 defsymbol (&Qshort, "short"); 4706 defsymbol (&Qshort, "short");
4711 defsymbol (&Qno_ascii_eol, "no-ascii-eol"); 4707 defsymbol (&Qno_ascii_eol, "no-ascii-eol");
4712 defsymbol (&Qno_ascii_cntl, "no-ascii-cntl"); 4708 defsymbol (&Qno_ascii_cntl, "no-ascii-cntl");
4713 defsymbol (&Qseven, "seven"); 4709 defsymbol (&Qseven, "seven");
4714 defsymbol (&Qlock_shift, "lock-shift"); 4710 defsymbol (&Qlock_shift, "lock-shift");
4715 defsymbol (&Qescape_quoted, "escape-quoted"); 4711 defsymbol (&Qescape_quoted, "escape-quoted");
4716 #endif 4712 #endif /* MULE */
4717 defsymbol (&Qencode, "encode"); 4713 defsymbol (&Qencode, "encode");
4718 defsymbol (&Qdecode, "decode"); 4714 defsymbol (&Qdecode, "decode");
4719 4715
4720 #ifdef MULE 4716 #ifdef MULE
4721 defsymbol (&Qctext, "ctext"); 4717 defsymbol (&Qctext, "ctext");
4731 "iso-8-1"); 4727 "iso-8-1");
4732 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_2], 4728 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_2],
4733 "iso-8-2"); 4729 "iso-8-2");
4734 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_LOCK_SHIFT], 4730 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_LOCK_SHIFT],
4735 "iso-lock-shift"); 4731 "iso-lock-shift");
4736 #endif /* MULE */ 4732 #endif /* MULE */
4737 defsymbol (&coding_category_symbol[CODING_CATEGORY_NO_CONVERSION], 4733 defsymbol (&coding_category_symbol[CODING_CATEGORY_NO_CONVERSION],
4738 "no-conversion"); 4734 "no-conversion");
4739 } 4735 }
4740 4736
4741 void 4737 void