comparison src/file-coding.c @ 462:0784d089fdc9 r21-2-46

Import from CVS: tag r21-2-46
author cvs
date Mon, 13 Aug 2007 11:44:37 +0200
parents 3d3049ae1304
children ef4d2466a29c
comparison
equal deleted inserted replaced
461:120ed4009e51 462:0784d089fdc9
174 #endif /* MULE */ 174 #endif /* MULE */
175 EXFUN (Fcopy_coding_system, 2); 175 EXFUN (Fcopy_coding_system, 2);
176 #ifdef MULE 176 #ifdef MULE
177 struct detection_state; 177 struct detection_state;
178 static int detect_coding_sjis (struct detection_state *st, 178 static int detect_coding_sjis (struct detection_state *st,
179 const Extbyte *src, size_t n); 179 const Extbyte *src, Lstream_data_count n);
180 static void decode_coding_sjis (Lstream *decoding, const Extbyte *src, 180 static void decode_coding_sjis (Lstream *decoding, const Extbyte *src,
181 unsigned_char_dynarr *dst, size_t n); 181 unsigned_char_dynarr *dst, Lstream_data_count n);
182 static void encode_coding_sjis (Lstream *encoding, const Bufbyte *src, 182 static void encode_coding_sjis (Lstream *encoding, const Bufbyte *src,
183 unsigned_char_dynarr *dst, size_t n); 183 unsigned_char_dynarr *dst, Lstream_data_count n);
184 static int detect_coding_big5 (struct detection_state *st, 184 static int detect_coding_big5 (struct detection_state *st,
185 const Extbyte *src, size_t n); 185 const Extbyte *src, Lstream_data_count n);
186 static void decode_coding_big5 (Lstream *decoding, const Extbyte *src, 186 static void decode_coding_big5 (Lstream *decoding, const Extbyte *src,
187 unsigned_char_dynarr *dst, size_t n); 187 unsigned_char_dynarr *dst, Lstream_data_count n);
188 static void encode_coding_big5 (Lstream *encoding, const Bufbyte *src, 188 static void encode_coding_big5 (Lstream *encoding, const Bufbyte *src,
189 unsigned_char_dynarr *dst, size_t n); 189 unsigned_char_dynarr *dst, Lstream_data_count n);
190 static int detect_coding_ucs4 (struct detection_state *st, 190 static int detect_coding_ucs4 (struct detection_state *st,
191 const Extbyte *src, size_t n); 191 const Extbyte *src, Lstream_data_count n);
192 static void decode_coding_ucs4 (Lstream *decoding, const Extbyte *src, 192 static void decode_coding_ucs4 (Lstream *decoding, const Extbyte *src,
193 unsigned_char_dynarr *dst, size_t n); 193 unsigned_char_dynarr *dst, Lstream_data_count n);
194 static void encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src, 194 static void encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src,
195 unsigned_char_dynarr *dst, size_t n); 195 unsigned_char_dynarr *dst, Lstream_data_count n);
196 static int detect_coding_utf8 (struct detection_state *st, 196 static int detect_coding_utf8 (struct detection_state *st,
197 const Extbyte *src, size_t n); 197 const Extbyte *src, Lstream_data_count n);
198 static void decode_coding_utf8 (Lstream *decoding, const Extbyte *src, 198 static void decode_coding_utf8 (Lstream *decoding, const Extbyte *src,
199 unsigned_char_dynarr *dst, size_t n); 199 unsigned_char_dynarr *dst, Lstream_data_count n);
200 static void encode_coding_utf8 (Lstream *encoding, const Bufbyte *src, 200 static void encode_coding_utf8 (Lstream *encoding, const Bufbyte *src,
201 unsigned_char_dynarr *dst, size_t n); 201 unsigned_char_dynarr *dst, Lstream_data_count n);
202 static int postprocess_iso2022_mask (int mask); 202 static int postprocess_iso2022_mask (int mask);
203 static void reset_iso2022 (Lisp_Object coding_system, 203 static void reset_iso2022 (Lisp_Object coding_system,
204 struct iso2022_decoder *iso); 204 struct iso2022_decoder *iso);
205 static int detect_coding_iso2022 (struct detection_state *st, 205 static int detect_coding_iso2022 (struct detection_state *st,
206 const Extbyte *src, size_t n); 206 const Extbyte *src, Lstream_data_count n);
207 static void decode_coding_iso2022 (Lstream *decoding, const Extbyte *src, 207 static void decode_coding_iso2022 (Lstream *decoding, const Extbyte *src,
208 unsigned_char_dynarr *dst, size_t n); 208 unsigned_char_dynarr *dst, Lstream_data_count n);
209 static void encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src, 209 static void encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src,
210 unsigned_char_dynarr *dst, size_t n); 210 unsigned_char_dynarr *dst, Lstream_data_count n);
211 #endif /* MULE */ 211 #endif /* MULE */
212 static void decode_coding_no_conversion (Lstream *decoding, const Extbyte *src, 212 static void decode_coding_no_conversion (Lstream *decoding, const Extbyte *src,
213 unsigned_char_dynarr *dst, size_t n); 213 unsigned_char_dynarr *dst, Lstream_data_count n);
214 static void encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src, 214 static void encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src,
215 unsigned_char_dynarr *dst, size_t n); 215 unsigned_char_dynarr *dst, Lstream_data_count n);
216 static void mule_decode (Lstream *decoding, const Extbyte *src, 216 static void mule_decode (Lstream *decoding, const Extbyte *src,
217 unsigned_char_dynarr *dst, size_t n); 217 unsigned_char_dynarr *dst, Lstream_data_count n);
218 static void mule_encode (Lstream *encoding, const Bufbyte *src, 218 static void mule_encode (Lstream *encoding, const Bufbyte *src,
219 unsigned_char_dynarr *dst, size_t n); 219 unsigned_char_dynarr *dst, Lstream_data_count n);
220 220
221 typedef struct codesys_prop codesys_prop; 221 typedef struct codesys_prop codesys_prop;
222 struct codesys_prop 222 struct codesys_prop
223 { 223 {
224 Lisp_Object sym; 224 Lisp_Object sym;
1630 return (mask & (mask - 1)) == 0; 1630 return (mask & (mask - 1)) == 0;
1631 } 1631 }
1632 1632
1633 static eol_type_t 1633 static eol_type_t
1634 detect_eol_type (struct detection_state *st, const Extbyte *src, 1634 detect_eol_type (struct detection_state *st, const Extbyte *src,
1635 size_t n) 1635 Lstream_data_count n)
1636 { 1636 {
1637 while (n--) 1637 while (n--)
1638 { 1638 {
1639 unsigned char c = *(unsigned char *)src++; 1639 unsigned char c = *(unsigned char *)src++;
1640 if (c == '\n') 1640 if (c == '\n')
1673 1 == definitive answers are here for both st->eol_type and st->mask 1673 1 == definitive answers are here for both st->eol_type and st->mask
1674 */ 1674 */
1675 1675
1676 static int 1676 static int
1677 detect_coding_type (struct detection_state *st, const Extbyte *src, 1677 detect_coding_type (struct detection_state *st, const Extbyte *src,
1678 size_t n, int just_do_eol) 1678 Lstream_data_count n, int just_do_eol)
1679 { 1679 {
1680 if (st->eol_type == EOL_AUTODETECT) 1680 if (st->eol_type == EOL_AUTODETECT)
1681 st->eol_type = detect_eol_type (st, src, n); 1681 st->eol_type = detect_eol_type (st, src, n);
1682 1682
1683 if (just_do_eol) 1683 if (just_do_eol)
1804 || *eol_type_in_out == EOL_AUTODETECT) 1804 || *eol_type_in_out == EOL_AUTODETECT)
1805 { 1805 {
1806 Extbyte buf[4096]; 1806 Extbyte buf[4096];
1807 Lisp_Object coding_system = Qnil; 1807 Lisp_Object coding_system = Qnil;
1808 Extbyte *p; 1808 Extbyte *p;
1809 ssize_t nread = Lstream_read (stream, buf, sizeof (buf)); 1809 Lstream_data_count nread = Lstream_read (stream, buf, sizeof (buf));
1810 Extbyte *scan_end; 1810 Extbyte *scan_end;
1811 1811
1812 /* Look for initial "-*-"; mode line prefix */ 1812 /* Look for initial "-*-"; mode line prefix */
1813 for (p = buf, 1813 for (p = buf,
1814 scan_end = buf + nread - LENGTH ("-*-coding:?-*-"); 1814 scan_end = buf + nread - LENGTH ("-*-coding:?-*-");
1938 decst.eol_type = EOL_AUTODETECT; 1938 decst.eol_type = EOL_AUTODETECT;
1939 decst.mask = ~0; 1939 decst.mask = ~0;
1940 while (1) 1940 while (1)
1941 { 1941 {
1942 Extbyte random_buffer[4096]; 1942 Extbyte random_buffer[4096];
1943 ssize_t nread = Lstream_read (istr, random_buffer, sizeof (random_buffer)); 1943 Lstream_data_count nread = Lstream_read (istr, random_buffer, sizeof (random_buffer));
1944 1944
1945 if (!nread) 1945 if (!nread)
1946 break; 1946 break;
1947 if (detect_coding_type (&decst, random_buffer, nread, 0)) 1947 if (detect_coding_type (&decst, random_buffer, nread, 0))
1948 break; 1948 break;
2105 unsigned char counter; 2105 unsigned char counter;
2106 #endif 2106 #endif
2107 struct detection_state decst; 2107 struct detection_state decst;
2108 }; 2108 };
2109 2109
2110 static ssize_t decoding_reader (Lstream *stream, 2110 static Lstream_data_count decoding_reader (Lstream *stream,
2111 unsigned char *data, size_t size); 2111 unsigned char *data, Lstream_data_count size);
2112 static ssize_t decoding_writer (Lstream *stream, 2112 static Lstream_data_count decoding_writer (Lstream *stream,
2113 const unsigned char *data, size_t size); 2113 const unsigned char *data, Lstream_data_count size);
2114 static int decoding_rewinder (Lstream *stream); 2114 static int decoding_rewinder (Lstream *stream);
2115 static int decoding_seekable_p (Lstream *stream); 2115 static int decoding_seekable_p (Lstream *stream);
2116 static int decoding_flusher (Lstream *stream); 2116 static int decoding_flusher (Lstream *stream);
2117 static int decoding_closer (Lstream *stream); 2117 static int decoding_closer (Lstream *stream);
2118 2118
2140 } 2140 }
2141 2141
2142 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream 2142 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream
2143 so we read data from the other end, decode it, and store it into DATA. */ 2143 so we read data from the other end, decode it, and store it into DATA. */
2144 2144
2145 static ssize_t 2145 static Lstream_data_count
2146 decoding_reader (Lstream *stream, unsigned char *data, size_t size) 2146 decoding_reader (Lstream *stream, unsigned char *data, Lstream_data_count size)
2147 { 2147 {
2148 struct decoding_stream *str = DECODING_STREAM_DATA (stream); 2148 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
2149 unsigned char *orig_data = data; 2149 unsigned char *orig_data = data;
2150 ssize_t read_size; 2150 Lstream_data_count read_size;
2151 int error_occurred = 0; 2151 int error_occurred = 0;
2152 2152
2153 /* We need to interface to mule_decode(), which expects to take some 2153 /* We need to interface to mule_decode(), which expects to take some
2154 amount of data and store the result into a Dynarr. We have 2154 amount of data and store the result into a Dynarr. We have
2155 mule_decode() store into str->runoff, and take data from there 2155 mule_decode() store into str->runoff, and take data from there
2161 { 2161 {
2162 /* Take data from the runoff if we can. Make sure to take at 2162 /* Take data from the runoff if we can. Make sure to take at
2163 most SIZE bytes, and delete the data from the runoff. */ 2163 most SIZE bytes, and delete the data from the runoff. */
2164 if (Dynarr_length (str->runoff) > 0) 2164 if (Dynarr_length (str->runoff) > 0)
2165 { 2165 {
2166 size_t chunk = min (size, (size_t) Dynarr_length (str->runoff)); 2166 Lstream_data_count chunk = min (size, (Lstream_data_count) Dynarr_length (str->runoff));
2167 memcpy (data, Dynarr_atp (str->runoff, 0), chunk); 2167 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
2168 Dynarr_delete_many (str->runoff, 0, chunk); 2168 Dynarr_delete_many (str->runoff, 0, chunk);
2169 data += chunk; 2169 data += chunk;
2170 size -= chunk; 2170 size -= chunk;
2171 } 2171 }
2202 return error_occurred ? -1 : 0; 2202 return error_occurred ? -1 : 0;
2203 else 2203 else
2204 return data - orig_data; 2204 return data - orig_data;
2205 } 2205 }
2206 2206
2207 static ssize_t 2207 static Lstream_data_count
2208 decoding_writer (Lstream *stream, const unsigned char *data, size_t size) 2208 decoding_writer (Lstream *stream, const unsigned char *data, Lstream_data_count size)
2209 { 2209 {
2210 struct decoding_stream *str = DECODING_STREAM_DATA (stream); 2210 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
2211 ssize_t retval; 2211 Lstream_data_count retval;
2212 2212
2213 /* Decode all our data into the runoff, and then attempt to write 2213 /* Decode all our data into the runoff, and then attempt to write
2214 it all out to the other end. Remove whatever chunk we succeeded 2214 it all out to the other end. Remove whatever chunk we succeeded
2215 in writing. */ 2215 in writing. */
2216 mule_decode (stream, (Extbyte *) data, str->runoff, size); 2216 mule_decode (stream, (Extbyte *) data, str->runoff, size);
2364 or decoding_writer(). This allows the same functions to 2364 or decoding_writer(). This allows the same functions to
2365 be used for both reading and writing. */ 2365 be used for both reading and writing. */
2366 2366
2367 static void 2367 static void
2368 mule_decode (Lstream *decoding, const Extbyte *src, 2368 mule_decode (Lstream *decoding, const Extbyte *src,
2369 unsigned_char_dynarr *dst, size_t n) 2369 unsigned_char_dynarr *dst, Lstream_data_count n)
2370 { 2370 {
2371 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 2371 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
2372 2372
2373 /* If necessary, do encoding-detection now. We do this when 2373 /* If necessary, do encoding-detection now. We do this when
2374 we're a writing stream or a non-seekable reading stream, 2374 we're a writing stream or a non-seekable reading stream,
2486 while (1) 2486 while (1)
2487 { 2487 {
2488 char tempbuf[1024]; /* some random amount */ 2488 char tempbuf[1024]; /* some random amount */
2489 Bufpos newpos, even_newer_pos; 2489 Bufpos newpos, even_newer_pos;
2490 Bufpos oldpos = lisp_buffer_stream_startpos (istr); 2490 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
2491 ssize_t size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); 2491 Lstream_data_count size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
2492 2492
2493 if (!size_in_bytes) 2493 if (!size_in_bytes)
2494 break; 2494 break;
2495 newpos = lisp_buffer_stream_startpos (istr); 2495 newpos = lisp_buffer_stream_startpos (istr);
2496 Lstream_write (ostr, tempbuf, size_in_bytes); 2496 Lstream_write (ostr, tempbuf, size_in_bytes);
2571 used by the CCL encoder. */ 2571 used by the CCL encoder. */
2572 struct ccl_program ccl; 2572 struct ccl_program ccl;
2573 #endif /* MULE */ 2573 #endif /* MULE */
2574 }; 2574 };
2575 2575
2576 static ssize_t encoding_reader (Lstream *stream, unsigned char *data, size_t size); 2576 static Lstream_data_count encoding_reader (Lstream *stream, unsigned char *data, Lstream_data_count size);
2577 static ssize_t encoding_writer (Lstream *stream, const unsigned char *data, 2577 static Lstream_data_count encoding_writer (Lstream *stream, const unsigned char *data,
2578 size_t size); 2578 Lstream_data_count size);
2579 static int encoding_rewinder (Lstream *stream); 2579 static int encoding_rewinder (Lstream *stream);
2580 static int encoding_seekable_p (Lstream *stream); 2580 static int encoding_seekable_p (Lstream *stream);
2581 static int encoding_flusher (Lstream *stream); 2581 static int encoding_flusher (Lstream *stream);
2582 static int encoding_closer (Lstream *stream); 2582 static int encoding_closer (Lstream *stream);
2583 2583
2605 } 2605 }
2606 2606
2607 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream 2607 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream
2608 so we read data from the other end, encode it, and store it into DATA. */ 2608 so we read data from the other end, encode it, and store it into DATA. */
2609 2609
2610 static ssize_t 2610 static Lstream_data_count
2611 encoding_reader (Lstream *stream, unsigned char *data, size_t size) 2611 encoding_reader (Lstream *stream, unsigned char *data, Lstream_data_count size)
2612 { 2612 {
2613 struct encoding_stream *str = ENCODING_STREAM_DATA (stream); 2613 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
2614 unsigned char *orig_data = data; 2614 unsigned char *orig_data = data;
2615 ssize_t read_size; 2615 Lstream_data_count read_size;
2616 int error_occurred = 0; 2616 int error_occurred = 0;
2617 2617
2618 /* We need to interface to mule_encode(), which expects to take some 2618 /* We need to interface to mule_encode(), which expects to take some
2619 amount of data and store the result into a Dynarr. We have 2619 amount of data and store the result into a Dynarr. We have
2620 mule_encode() store into str->runoff, and take data from there 2620 mule_encode() store into str->runoff, and take data from there
2667 return error_occurred ? -1 : 0; 2667 return error_occurred ? -1 : 0;
2668 else 2668 else
2669 return data - orig_data; 2669 return data - orig_data;
2670 } 2670 }
2671 2671
2672 static ssize_t 2672 static Lstream_data_count
2673 encoding_writer (Lstream *stream, const unsigned char *data, size_t size) 2673 encoding_writer (Lstream *stream, const unsigned char *data, Lstream_data_count size)
2674 { 2674 {
2675 struct encoding_stream *str = ENCODING_STREAM_DATA (stream); 2675 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
2676 ssize_t retval; 2676 Lstream_data_count retval;
2677 2677
2678 /* Encode all our data into the runoff, and then attempt to write 2678 /* Encode all our data into the runoff, and then attempt to write
2679 it all out to the other end. Remove whatever chunk we succeeded 2679 it all out to the other end. Remove whatever chunk we succeeded
2680 in writing. */ 2680 in writing. */
2681 mule_encode (stream, data, str->runoff, size); 2681 mule_encode (stream, data, str->runoff, size);
2811 external format, according to the encoding stream ENCODING. 2811 external format, according to the encoding stream ENCODING.
2812 Store the encoded data into DST. */ 2812 Store the encoded data into DST. */
2813 2813
2814 static void 2814 static void
2815 mule_encode (Lstream *encoding, const Bufbyte *src, 2815 mule_encode (Lstream *encoding, const Bufbyte *src,
2816 unsigned_char_dynarr *dst, size_t n) 2816 unsigned_char_dynarr *dst, Lstream_data_count n)
2817 { 2817 {
2818 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 2818 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
2819 2819
2820 switch (CODING_SYSTEM_TYPE (str->codesys)) 2820 switch (CODING_SYSTEM_TYPE (str->codesys))
2821 { 2821 {
2897 while (1) 2897 while (1)
2898 { 2898 {
2899 char tempbuf[1024]; /* some random amount */ 2899 char tempbuf[1024]; /* some random amount */
2900 Bufpos newpos, even_newer_pos; 2900 Bufpos newpos, even_newer_pos;
2901 Bufpos oldpos = lisp_buffer_stream_startpos (istr); 2901 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
2902 ssize_t size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); 2902 Lstream_data_count size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
2903 2903
2904 if (!size_in_bytes) 2904 if (!size_in_bytes)
2905 break; 2905 break;
2906 newpos = lisp_buffer_stream_startpos (istr); 2906 newpos = lisp_buffer_stream_startpos (istr);
2907 Lstream_write (ostr, tempbuf, size_in_bytes); 2907 Lstream_write (ostr, tempbuf, size_in_bytes);
2960 2960
2961 #define BYTE_SJIS_KATAKANA_P(c) \ 2961 #define BYTE_SJIS_KATAKANA_P(c) \
2962 ((c) >= 0xA1 && (c) <= 0xDF) 2962 ((c) >= 0xA1 && (c) <= 0xDF)
2963 2963
2964 static int 2964 static int
2965 detect_coding_sjis (struct detection_state *st, const Extbyte *src, size_t n) 2965 detect_coding_sjis (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
2966 { 2966 {
2967 while (n--) 2967 while (n--)
2968 { 2968 {
2969 unsigned char c = *(unsigned char *)src++; 2969 unsigned char c = *(unsigned char *)src++;
2970 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) 2970 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
2983 2983
2984 /* Convert Shift-JIS data to internal format. */ 2984 /* Convert Shift-JIS data to internal format. */
2985 2985
2986 static void 2986 static void
2987 decode_coding_sjis (Lstream *decoding, const Extbyte *src, 2987 decode_coding_sjis (Lstream *decoding, const Extbyte *src,
2988 unsigned_char_dynarr *dst, size_t n) 2988 unsigned_char_dynarr *dst, Lstream_data_count n)
2989 { 2989 {
2990 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 2990 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
2991 unsigned int flags = str->flags; 2991 unsigned int flags = str->flags;
2992 unsigned int ch = str->ch; 2992 unsigned int ch = str->ch;
2993 eol_type_t eol_type = str->eol_type; 2993 eol_type_t eol_type = str->eol_type;
3039 3039
3040 /* Convert internally-formatted data to Shift-JIS. */ 3040 /* Convert internally-formatted data to Shift-JIS. */
3041 3041
3042 static void 3042 static void
3043 encode_coding_sjis (Lstream *encoding, const Bufbyte *src, 3043 encode_coding_sjis (Lstream *encoding, const Bufbyte *src,
3044 unsigned_char_dynarr *dst, size_t n) 3044 unsigned_char_dynarr *dst, Lstream_data_count n)
3045 { 3045 {
3046 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 3046 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3047 unsigned int flags = str->flags; 3047 unsigned int flags = str->flags;
3048 unsigned int ch = str->ch; 3048 unsigned int ch = str->ch;
3049 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys); 3049 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
3241 b2 = I % BIG5_SAME_ROW; \ 3241 b2 = I % BIG5_SAME_ROW; \
3242 b2 += b2 < 0x3F ? 0x40 : 0x62; \ 3242 b2 += b2 < 0x3F ? 0x40 : 0x62; \
3243 } while (0) 3243 } while (0)
3244 3244
3245 static int 3245 static int
3246 detect_coding_big5 (struct detection_state *st, const Extbyte *src, size_t n) 3246 detect_coding_big5 (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
3247 { 3247 {
3248 while (n--) 3248 while (n--)
3249 { 3249 {
3250 unsigned char c = *(unsigned char *)src++; 3250 unsigned char c = *(unsigned char *)src++;
3251 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO || 3251 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO ||
3265 3265
3266 /* Convert Big5 data to internal format. */ 3266 /* Convert Big5 data to internal format. */
3267 3267
3268 static void 3268 static void
3269 decode_coding_big5 (Lstream *decoding, const Extbyte *src, 3269 decode_coding_big5 (Lstream *decoding, const Extbyte *src,
3270 unsigned_char_dynarr *dst, size_t n) 3270 unsigned_char_dynarr *dst, Lstream_data_count n)
3271 { 3271 {
3272 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 3272 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3273 unsigned int flags = str->flags; 3273 unsigned int flags = str->flags;
3274 unsigned int ch = str->ch; 3274 unsigned int ch = str->ch;
3275 eol_type_t eol_type = str->eol_type; 3275 eol_type_t eol_type = str->eol_type;
3314 3314
3315 /* Convert internally-formatted data to Big5. */ 3315 /* Convert internally-formatted data to Big5. */
3316 3316
3317 static void 3317 static void
3318 encode_coding_big5 (Lstream *encoding, const Bufbyte *src, 3318 encode_coding_big5 (Lstream *encoding, const Bufbyte *src,
3319 unsigned_char_dynarr *dst, size_t n) 3319 unsigned_char_dynarr *dst, Lstream_data_count n)
3320 { 3320 {
3321 unsigned char c; 3321 unsigned char c;
3322 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 3322 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3323 unsigned int flags = str->flags; 3323 unsigned int flags = str->flags;
3324 unsigned int ch = str->ch; 3324 unsigned int ch = str->ch;
3580 Dynarr_add (dst, (code >> 8) & 255); 3580 Dynarr_add (dst, (code >> 8) & 255);
3581 Dynarr_add (dst, code & 255); 3581 Dynarr_add (dst, code & 255);
3582 } 3582 }
3583 3583
3584 static int 3584 static int
3585 detect_coding_ucs4 (struct detection_state *st, const Extbyte *src, size_t n) 3585 detect_coding_ucs4 (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
3586 { 3586 {
3587 while (n--) 3587 while (n--)
3588 { 3588 {
3589 unsigned char c = *(unsigned char *)src++; 3589 unsigned char c = *(unsigned char *)src++;
3590 switch (st->ucs4.in_byte) 3590 switch (st->ucs4.in_byte)
3605 return CODING_CATEGORY_UCS4_MASK; 3605 return CODING_CATEGORY_UCS4_MASK;
3606 } 3606 }
3607 3607
3608 static void 3608 static void
3609 decode_coding_ucs4 (Lstream *decoding, const Extbyte *src, 3609 decode_coding_ucs4 (Lstream *decoding, const Extbyte *src,
3610 unsigned_char_dynarr *dst, size_t n) 3610 unsigned_char_dynarr *dst, Lstream_data_count n)
3611 { 3611 {
3612 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 3612 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3613 unsigned int flags = str->flags; 3613 unsigned int flags = str->flags;
3614 unsigned int ch = str->ch; 3614 unsigned int ch = str->ch;
3615 unsigned char counter = str->counter; 3615 unsigned char counter = str->counter;
3641 str->counter = counter; 3641 str->counter = counter;
3642 } 3642 }
3643 3643
3644 static void 3644 static void
3645 encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src, 3645 encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src,
3646 unsigned_char_dynarr *dst, size_t n) 3646 unsigned_char_dynarr *dst, Lstream_data_count n)
3647 { 3647 {
3648 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 3648 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3649 unsigned int flags = str->flags; 3649 unsigned int flags = str->flags;
3650 unsigned int ch = str->ch; 3650 unsigned int ch = str->ch;
3651 unsigned char char_boundary = str->iso2022.current_char_boundary; 3651 unsigned char char_boundary = str->iso2022.current_char_boundary;
3779 /************************************************************************/ 3779 /************************************************************************/
3780 /* UTF-8 methods */ 3780 /* UTF-8 methods */
3781 /************************************************************************/ 3781 /************************************************************************/
3782 3782
3783 static int 3783 static int
3784 detect_coding_utf8 (struct detection_state *st, const Extbyte *src, size_t n) 3784 detect_coding_utf8 (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
3785 { 3785 {
3786 while (n--) 3786 while (n--)
3787 { 3787 {
3788 unsigned char c = *(unsigned char *)src++; 3788 unsigned char c = *(unsigned char *)src++;
3789 switch (st->utf8.in_byte) 3789 switch (st->utf8.in_byte)
3814 return CODING_CATEGORY_UTF8_MASK; 3814 return CODING_CATEGORY_UTF8_MASK;
3815 } 3815 }
3816 3816
3817 static void 3817 static void
3818 decode_coding_utf8 (Lstream *decoding, const Extbyte *src, 3818 decode_coding_utf8 (Lstream *decoding, const Extbyte *src,
3819 unsigned_char_dynarr *dst, size_t n) 3819 unsigned_char_dynarr *dst, Lstream_data_count n)
3820 { 3820 {
3821 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 3821 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3822 unsigned int flags = str->flags; 3822 unsigned int flags = str->flags;
3823 unsigned int ch = str->ch; 3823 unsigned int ch = str->ch;
3824 eol_type_t eol_type = str->eol_type; 3824 eol_type_t eol_type = str->eol_type;
3928 } 3928 }
3929 } 3929 }
3930 3930
3931 static void 3931 static void
3932 encode_coding_utf8 (Lstream *encoding, const Bufbyte *src, 3932 encode_coding_utf8 (Lstream *encoding, const Bufbyte *src,
3933 unsigned_char_dynarr *dst, size_t n) 3933 unsigned_char_dynarr *dst, Lstream_data_count n)
3934 { 3934 {
3935 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 3935 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3936 unsigned int flags = str->flags; 3936 unsigned int flags = str->flags;
3937 unsigned int ch = str->ch; 3937 unsigned int ch = str->ch;
3938 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys); 3938 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
4687 iso->switched_dir_and_no_valid_charset_yet = 0; 4687 iso->switched_dir_and_no_valid_charset_yet = 0;
4688 return 1; 4688 return 1;
4689 } 4689 }
4690 4690
4691 static int 4691 static int
4692 detect_coding_iso2022 (struct detection_state *st, const Extbyte *src, size_t n) 4692 detect_coding_iso2022 (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
4693 { 4693 {
4694 int mask; 4694 int mask;
4695 4695
4696 /* #### There are serious deficiencies in the recognition mechanism 4696 /* #### There are serious deficiencies in the recognition mechanism
4697 here. This needs to be much smarter if it's going to cut it. 4697 here. This needs to be much smarter if it's going to cut it.
4878 4878
4879 /* Convert ISO2022-format data to internal format. */ 4879 /* Convert ISO2022-format data to internal format. */
4880 4880
4881 static void 4881 static void
4882 decode_coding_iso2022 (Lstream *decoding, const Extbyte *src, 4882 decode_coding_iso2022 (Lstream *decoding, const Extbyte *src,
4883 unsigned_char_dynarr *dst, size_t n) 4883 unsigned_char_dynarr *dst, Lstream_data_count n)
4884 { 4884 {
4885 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 4885 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
4886 unsigned int flags = str->flags; 4886 unsigned int flags = str->flags;
4887 unsigned int ch = str->ch; 4887 unsigned int ch = str->ch;
4888 eol_type_t eol_type = str->eol_type; 4888 eol_type_t eol_type = str->eol_type;
5204 5204
5205 /* Convert internally-formatted data to ISO2022 format. */ 5205 /* Convert internally-formatted data to ISO2022 format. */
5206 5206
5207 static void 5207 static void
5208 encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src, 5208 encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src,
5209 unsigned_char_dynarr *dst, size_t n) 5209 unsigned_char_dynarr *dst, Lstream_data_count n)
5210 { 5210 {
5211 unsigned char charmask, c; 5211 unsigned char charmask, c;
5212 unsigned char char_boundary; 5212 unsigned char char_boundary;
5213 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 5213 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
5214 unsigned int flags = str->flags; 5214 unsigned int flags = str->flags;
5513 /* This is used when reading in "binary" files -- i.e. files that may 5513 /* This is used when reading in "binary" files -- i.e. files that may
5514 contain all 256 possible byte values and that are not to be 5514 contain all 256 possible byte values and that are not to be
5515 interpreted as being in any particular decoding. */ 5515 interpreted as being in any particular decoding. */
5516 static void 5516 static void
5517 decode_coding_no_conversion (Lstream *decoding, const Extbyte *src, 5517 decode_coding_no_conversion (Lstream *decoding, const Extbyte *src,
5518 unsigned_char_dynarr *dst, size_t n) 5518 unsigned_char_dynarr *dst, Lstream_data_count n)
5519 { 5519 {
5520 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 5520 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
5521 unsigned int flags = str->flags; 5521 unsigned int flags = str->flags;
5522 unsigned int ch = str->ch; 5522 unsigned int ch = str->ch;
5523 eol_type_t eol_type = str->eol_type; 5523 eol_type_t eol_type = str->eol_type;
5537 str->ch = ch; 5537 str->ch = ch;
5538 } 5538 }
5539 5539
5540 static void 5540 static void
5541 encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src, 5541 encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src,
5542 unsigned_char_dynarr *dst, size_t n) 5542 unsigned_char_dynarr *dst, Lstream_data_count n)
5543 { 5543 {
5544 unsigned char c; 5544 unsigned char c;
5545 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 5545 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
5546 unsigned int flags = str->flags; 5546 unsigned int flags = str->flags;
5547 unsigned int ch = str->ch; 5547 unsigned int ch = str->ch;