comparison src/file-coding.c @ 647:b39c14581166

[xemacs-hg @ 2001-08-13 04:45:47 by ben] removal of unsigned, size_t, etc.
author ben
date Mon, 13 Aug 2001 04:46:48 +0000
parents 001628b7a5b3
children fdefd0186b75
comparison
equal deleted inserted replaced
646:00c54252fe4f 647:b39c14581166
172 #endif /* MULE */ 172 #endif /* MULE */
173 EXFUN (Fcopy_coding_system, 2); 173 EXFUN (Fcopy_coding_system, 2);
174 #ifdef MULE 174 #ifdef MULE
175 struct detection_state; 175 struct detection_state;
176 static int detect_coding_sjis (struct detection_state *st, 176 static int detect_coding_sjis (struct detection_state *st,
177 const Extbyte *src, Lstream_data_count n); 177 const Extbyte *src, Lstream_Data_Count n);
178 static void decode_coding_sjis (Lstream *decoding, const Extbyte *src, 178 static void decode_coding_sjis (Lstream *decoding, const Extbyte *src,
179 unsigned_char_dynarr *dst, Lstream_data_count n); 179 unsigned_char_dynarr *dst, Lstream_Data_Count n);
180 static void encode_coding_sjis (Lstream *encoding, const Bufbyte *src, 180 static void encode_coding_sjis (Lstream *encoding, const Bufbyte *src,
181 unsigned_char_dynarr *dst, Lstream_data_count n); 181 unsigned_char_dynarr *dst, Lstream_Data_Count n);
182 static int detect_coding_big5 (struct detection_state *st, 182 static int detect_coding_big5 (struct detection_state *st,
183 const Extbyte *src, Lstream_data_count n); 183 const Extbyte *src, Lstream_Data_Count n);
184 static void decode_coding_big5 (Lstream *decoding, const Extbyte *src, 184 static void decode_coding_big5 (Lstream *decoding, const Extbyte *src,
185 unsigned_char_dynarr *dst, Lstream_data_count n); 185 unsigned_char_dynarr *dst, Lstream_Data_Count n);
186 static void encode_coding_big5 (Lstream *encoding, const Bufbyte *src, 186 static void encode_coding_big5 (Lstream *encoding, const Bufbyte *src,
187 unsigned_char_dynarr *dst, Lstream_data_count n); 187 unsigned_char_dynarr *dst, Lstream_Data_Count n);
188 static int detect_coding_ucs4 (struct detection_state *st, 188 static int detect_coding_ucs4 (struct detection_state *st,
189 const Extbyte *src, Lstream_data_count n); 189 const Extbyte *src, Lstream_Data_Count n);
190 static void decode_coding_ucs4 (Lstream *decoding, const Extbyte *src, 190 static void decode_coding_ucs4 (Lstream *decoding, const Extbyte *src,
191 unsigned_char_dynarr *dst, Lstream_data_count n); 191 unsigned_char_dynarr *dst, Lstream_Data_Count n);
192 static void encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src, 192 static void encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src,
193 unsigned_char_dynarr *dst, Lstream_data_count n); 193 unsigned_char_dynarr *dst, Lstream_Data_Count n);
194 static int detect_coding_utf8 (struct detection_state *st, 194 static int detect_coding_utf8 (struct detection_state *st,
195 const Extbyte *src, Lstream_data_count n); 195 const Extbyte *src, Lstream_Data_Count n);
196 static void decode_coding_utf8 (Lstream *decoding, const Extbyte *src, 196 static void decode_coding_utf8 (Lstream *decoding, const Extbyte *src,
197 unsigned_char_dynarr *dst, Lstream_data_count n); 197 unsigned_char_dynarr *dst, Lstream_Data_Count n);
198 static void encode_coding_utf8 (Lstream *encoding, const Bufbyte *src, 198 static void encode_coding_utf8 (Lstream *encoding, const Bufbyte *src,
199 unsigned_char_dynarr *dst, Lstream_data_count n); 199 unsigned_char_dynarr *dst, Lstream_Data_Count n);
200 static int postprocess_iso2022_mask (int mask); 200 static int postprocess_iso2022_mask (int mask);
201 static void reset_iso2022 (Lisp_Object coding_system, 201 static void reset_iso2022 (Lisp_Object coding_system,
202 struct iso2022_decoder *iso); 202 struct iso2022_decoder *iso);
203 static int detect_coding_iso2022 (struct detection_state *st, 203 static int detect_coding_iso2022 (struct detection_state *st,
204 const Extbyte *src, Lstream_data_count n); 204 const Extbyte *src, Lstream_Data_Count n);
205 static void decode_coding_iso2022 (Lstream *decoding, const Extbyte *src, 205 static void decode_coding_iso2022 (Lstream *decoding, const Extbyte *src,
206 unsigned_char_dynarr *dst, Lstream_data_count n); 206 unsigned_char_dynarr *dst, Lstream_Data_Count n);
207 static void encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src, 207 static void encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src,
208 unsigned_char_dynarr *dst, Lstream_data_count n); 208 unsigned_char_dynarr *dst, Lstream_Data_Count n);
209 #endif /* MULE */ 209 #endif /* MULE */
210 static void decode_coding_no_conversion (Lstream *decoding, const Extbyte *src, 210 static void decode_coding_no_conversion (Lstream *decoding, const Extbyte *src,
211 unsigned_char_dynarr *dst, Lstream_data_count n); 211 unsigned_char_dynarr *dst, Lstream_Data_Count n);
212 static void encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src, 212 static void encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src,
213 unsigned_char_dynarr *dst, Lstream_data_count n); 213 unsigned_char_dynarr *dst, Lstream_Data_Count n);
214 static void mule_decode (Lstream *decoding, const Extbyte *src, 214 static void mule_decode (Lstream *decoding, const Extbyte *src,
215 unsigned_char_dynarr *dst, Lstream_data_count n); 215 unsigned_char_dynarr *dst, Lstream_Data_Count n);
216 static void mule_encode (Lstream *encoding, const Bufbyte *src, 216 static void mule_encode (Lstream *encoding, const Bufbyte *src,
217 unsigned_char_dynarr *dst, Lstream_data_count n); 217 unsigned_char_dynarr *dst, Lstream_Data_Count n);
218 218
219 typedef struct codesys_prop codesys_prop; 219 typedef struct codesys_prop codesys_prop;
220 struct codesys_prop 220 struct codesys_prop
221 { 221 {
222 Lisp_Object sym; 222 Lisp_Object sym;
1615 return (mask & (mask - 1)) == 0; 1615 return (mask & (mask - 1)) == 0;
1616 } 1616 }
1617 1617
1618 static eol_type_t 1618 static eol_type_t
1619 detect_eol_type (struct detection_state *st, const Extbyte *src, 1619 detect_eol_type (struct detection_state *st, const Extbyte *src,
1620 Lstream_data_count n) 1620 Lstream_Data_Count n)
1621 { 1621 {
1622 while (n--) 1622 while (n--)
1623 { 1623 {
1624 unsigned char c = *(unsigned char *)src++; 1624 unsigned char c = *(unsigned char *)src++;
1625 if (c == '\n') 1625 if (c == '\n')
1658 1 == definitive answers are here for both st->eol_type and st->mask 1658 1 == definitive answers are here for both st->eol_type and st->mask
1659 */ 1659 */
1660 1660
1661 static int 1661 static int
1662 detect_coding_type (struct detection_state *st, const Extbyte *src, 1662 detect_coding_type (struct detection_state *st, const Extbyte *src,
1663 Lstream_data_count n, int just_do_eol) 1663 Lstream_Data_Count n, int just_do_eol)
1664 { 1664 {
1665 if (st->eol_type == EOL_AUTODETECT) 1665 if (st->eol_type == EOL_AUTODETECT)
1666 st->eol_type = detect_eol_type (st, src, n); 1666 st->eol_type = detect_eol_type (st, src, n);
1667 1667
1668 if (just_do_eol) 1668 if (just_do_eol)
1789 || *eol_type_in_out == EOL_AUTODETECT) 1789 || *eol_type_in_out == EOL_AUTODETECT)
1790 { 1790 {
1791 Extbyte buf[4096]; 1791 Extbyte buf[4096];
1792 Lisp_Object coding_system = Qnil; 1792 Lisp_Object coding_system = Qnil;
1793 Extbyte *p; 1793 Extbyte *p;
1794 Lstream_data_count nread = Lstream_read (stream, buf, sizeof (buf)); 1794 Lstream_Data_Count nread = Lstream_read (stream, buf, sizeof (buf));
1795 Extbyte *scan_end; 1795 Extbyte *scan_end;
1796 1796
1797 /* Look for initial "-*-"; mode line prefix */ 1797 /* Look for initial "-*-"; mode line prefix */
1798 for (p = buf, 1798 for (p = buf,
1799 scan_end = buf + nread - LENGTH ("-*-coding:?-*-"); 1799 scan_end = buf + nread - LENGTH ("-*-coding:?-*-");
1923 decst.eol_type = EOL_AUTODETECT; 1923 decst.eol_type = EOL_AUTODETECT;
1924 decst.mask = ~0; 1924 decst.mask = ~0;
1925 while (1) 1925 while (1)
1926 { 1926 {
1927 Extbyte random_buffer[4096]; 1927 Extbyte random_buffer[4096];
1928 Lstream_data_count nread = Lstream_read (istr, random_buffer, sizeof (random_buffer)); 1928 Lstream_Data_Count nread = Lstream_read (istr, random_buffer, sizeof (random_buffer));
1929 1929
1930 if (!nread) 1930 if (!nread)
1931 break; 1931 break;
1932 if (detect_coding_type (&decst, random_buffer, nread, 0)) 1932 if (detect_coding_type (&decst, random_buffer, nread, 0))
1933 break; 1933 break;
2090 unsigned char counter; 2090 unsigned char counter;
2091 #endif 2091 #endif
2092 struct detection_state decst; 2092 struct detection_state decst;
2093 }; 2093 };
2094 2094
2095 static Lstream_data_count decoding_reader (Lstream *stream, 2095 static Lstream_Data_Count decoding_reader (Lstream *stream,
2096 unsigned char *data, Lstream_data_count size); 2096 unsigned char *data, Lstream_Data_Count size);
2097 static Lstream_data_count decoding_writer (Lstream *stream, 2097 static Lstream_Data_Count decoding_writer (Lstream *stream,
2098 const unsigned char *data, Lstream_data_count size); 2098 const unsigned char *data, Lstream_Data_Count size);
2099 static int decoding_rewinder (Lstream *stream); 2099 static int decoding_rewinder (Lstream *stream);
2100 static int decoding_seekable_p (Lstream *stream); 2100 static int decoding_seekable_p (Lstream *stream);
2101 static int decoding_flusher (Lstream *stream); 2101 static int decoding_flusher (Lstream *stream);
2102 static int decoding_closer (Lstream *stream); 2102 static int decoding_closer (Lstream *stream);
2103 2103
2125 } 2125 }
2126 2126
2127 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream 2127 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream
2128 so we read data from the other end, decode it, and store it into DATA. */ 2128 so we read data from the other end, decode it, and store it into DATA. */
2129 2129
2130 static Lstream_data_count 2130 static Lstream_Data_Count
2131 decoding_reader (Lstream *stream, unsigned char *data, Lstream_data_count size) 2131 decoding_reader (Lstream *stream, unsigned char *data, Lstream_Data_Count size)
2132 { 2132 {
2133 struct decoding_stream *str = DECODING_STREAM_DATA (stream); 2133 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
2134 unsigned char *orig_data = data; 2134 unsigned char *orig_data = data;
2135 Lstream_data_count read_size; 2135 Lstream_Data_Count read_size;
2136 int error_occurred = 0; 2136 int error_occurred = 0;
2137 2137
2138 /* We need to interface to mule_decode(), which expects to take some 2138 /* We need to interface to mule_decode(), which expects to take some
2139 amount of data and store the result into a Dynarr. We have 2139 amount of data and store the result into a Dynarr. We have
2140 mule_decode() store into str->runoff, and take data from there 2140 mule_decode() store into str->runoff, and take data from there
2146 { 2146 {
2147 /* Take data from the runoff if we can. Make sure to take at 2147 /* Take data from the runoff if we can. Make sure to take at
2148 most SIZE bytes, and delete the data from the runoff. */ 2148 most SIZE bytes, and delete the data from the runoff. */
2149 if (Dynarr_length (str->runoff) > 0) 2149 if (Dynarr_length (str->runoff) > 0)
2150 { 2150 {
2151 Lstream_data_count chunk = min (size, (Lstream_data_count) Dynarr_length (str->runoff)); 2151 Lstream_Data_Count chunk = min (size, (Lstream_Data_Count) Dynarr_length (str->runoff));
2152 memcpy (data, Dynarr_atp (str->runoff, 0), chunk); 2152 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
2153 Dynarr_delete_many (str->runoff, 0, chunk); 2153 Dynarr_delete_many (str->runoff, 0, chunk);
2154 data += chunk; 2154 data += chunk;
2155 size -= chunk; 2155 size -= chunk;
2156 } 2156 }
2187 return error_occurred ? -1 : 0; 2187 return error_occurred ? -1 : 0;
2188 else 2188 else
2189 return data - orig_data; 2189 return data - orig_data;
2190 } 2190 }
2191 2191
2192 static Lstream_data_count 2192 static Lstream_Data_Count
2193 decoding_writer (Lstream *stream, const unsigned char *data, Lstream_data_count size) 2193 decoding_writer (Lstream *stream, const unsigned char *data, Lstream_Data_Count size)
2194 { 2194 {
2195 struct decoding_stream *str = DECODING_STREAM_DATA (stream); 2195 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
2196 Lstream_data_count retval; 2196 Lstream_Data_Count retval;
2197 2197
2198 /* Decode all our data into the runoff, and then attempt to write 2198 /* Decode all our data into the runoff, and then attempt to write
2199 it all out to the other end. Remove whatever chunk we succeeded 2199 it all out to the other end. Remove whatever chunk we succeeded
2200 in writing. */ 2200 in writing. */
2201 mule_decode (stream, (Extbyte *) data, str->runoff, size); 2201 mule_decode (stream, (Extbyte *) data, str->runoff, size);
2349 or decoding_writer(). This allows the same functions to 2349 or decoding_writer(). This allows the same functions to
2350 be used for both reading and writing. */ 2350 be used for both reading and writing. */
2351 2351
2352 static void 2352 static void
2353 mule_decode (Lstream *decoding, const Extbyte *src, 2353 mule_decode (Lstream *decoding, const Extbyte *src,
2354 unsigned_char_dynarr *dst, Lstream_data_count n) 2354 unsigned_char_dynarr *dst, Lstream_Data_Count n)
2355 { 2355 {
2356 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 2356 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
2357 2357
2358 /* If necessary, do encoding-detection now. We do this when 2358 /* If necessary, do encoding-detection now. We do this when
2359 we're a writing stream or a non-seekable reading stream, 2359 we're a writing stream or a non-seekable reading stream,
2471 while (1) 2471 while (1)
2472 { 2472 {
2473 char tempbuf[1024]; /* some random amount */ 2473 char tempbuf[1024]; /* some random amount */
2474 Bufpos newpos, even_newer_pos; 2474 Bufpos newpos, even_newer_pos;
2475 Bufpos oldpos = lisp_buffer_stream_startpos (istr); 2475 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
2476 Lstream_data_count size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); 2476 Lstream_Data_Count size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
2477 2477
2478 if (!size_in_bytes) 2478 if (!size_in_bytes)
2479 break; 2479 break;
2480 newpos = lisp_buffer_stream_startpos (istr); 2480 newpos = lisp_buffer_stream_startpos (istr);
2481 Lstream_write (ostr, tempbuf, size_in_bytes); 2481 Lstream_write (ostr, tempbuf, size_in_bytes);
2556 used by the CCL encoder. */ 2556 used by the CCL encoder. */
2557 struct ccl_program ccl; 2557 struct ccl_program ccl;
2558 #endif /* MULE */ 2558 #endif /* MULE */
2559 }; 2559 };
2560 2560
2561 static Lstream_data_count encoding_reader (Lstream *stream, unsigned char *data, Lstream_data_count size); 2561 static Lstream_Data_Count encoding_reader (Lstream *stream, unsigned char *data, Lstream_Data_Count size);
2562 static Lstream_data_count encoding_writer (Lstream *stream, const unsigned char *data, 2562 static Lstream_Data_Count encoding_writer (Lstream *stream, const unsigned char *data,
2563 Lstream_data_count size); 2563 Lstream_Data_Count size);
2564 static int encoding_rewinder (Lstream *stream); 2564 static int encoding_rewinder (Lstream *stream);
2565 static int encoding_seekable_p (Lstream *stream); 2565 static int encoding_seekable_p (Lstream *stream);
2566 static int encoding_flusher (Lstream *stream); 2566 static int encoding_flusher (Lstream *stream);
2567 static int encoding_closer (Lstream *stream); 2567 static int encoding_closer (Lstream *stream);
2568 2568
2590 } 2590 }
2591 2591
2592 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream 2592 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream
2593 so we read data from the other end, encode it, and store it into DATA. */ 2593 so we read data from the other end, encode it, and store it into DATA. */
2594 2594
2595 static Lstream_data_count 2595 static Lstream_Data_Count
2596 encoding_reader (Lstream *stream, unsigned char *data, Lstream_data_count size) 2596 encoding_reader (Lstream *stream, unsigned char *data, Lstream_Data_Count size)
2597 { 2597 {
2598 struct encoding_stream *str = ENCODING_STREAM_DATA (stream); 2598 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
2599 unsigned char *orig_data = data; 2599 unsigned char *orig_data = data;
2600 Lstream_data_count read_size; 2600 Lstream_Data_Count read_size;
2601 int error_occurred = 0; 2601 int error_occurred = 0;
2602 2602
2603 /* We need to interface to mule_encode(), which expects to take some 2603 /* We need to interface to mule_encode(), which expects to take some
2604 amount of data and store the result into a Dynarr. We have 2604 amount of data and store the result into a Dynarr. We have
2605 mule_encode() store into str->runoff, and take data from there 2605 mule_encode() store into str->runoff, and take data from there
2652 return error_occurred ? -1 : 0; 2652 return error_occurred ? -1 : 0;
2653 else 2653 else
2654 return data - orig_data; 2654 return data - orig_data;
2655 } 2655 }
2656 2656
2657 static Lstream_data_count 2657 static Lstream_Data_Count
2658 encoding_writer (Lstream *stream, const unsigned char *data, Lstream_data_count size) 2658 encoding_writer (Lstream *stream, const unsigned char *data, Lstream_Data_Count size)
2659 { 2659 {
2660 struct encoding_stream *str = ENCODING_STREAM_DATA (stream); 2660 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
2661 Lstream_data_count retval; 2661 Lstream_Data_Count retval;
2662 2662
2663 /* Encode all our data into the runoff, and then attempt to write 2663 /* Encode all our data into the runoff, and then attempt to write
2664 it all out to the other end. Remove whatever chunk we succeeded 2664 it all out to the other end. Remove whatever chunk we succeeded
2665 in writing. */ 2665 in writing. */
2666 mule_encode (stream, data, str->runoff, size); 2666 mule_encode (stream, data, str->runoff, size);
2796 external format, according to the encoding stream ENCODING. 2796 external format, according to the encoding stream ENCODING.
2797 Store the encoded data into DST. */ 2797 Store the encoded data into DST. */
2798 2798
2799 static void 2799 static void
2800 mule_encode (Lstream *encoding, const Bufbyte *src, 2800 mule_encode (Lstream *encoding, const Bufbyte *src,
2801 unsigned_char_dynarr *dst, Lstream_data_count n) 2801 unsigned_char_dynarr *dst, Lstream_Data_Count n)
2802 { 2802 {
2803 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 2803 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
2804 2804
2805 switch (CODING_SYSTEM_TYPE (str->codesys)) 2805 switch (CODING_SYSTEM_TYPE (str->codesys))
2806 { 2806 {
2882 while (1) 2882 while (1)
2883 { 2883 {
2884 char tempbuf[1024]; /* some random amount */ 2884 char tempbuf[1024]; /* some random amount */
2885 Bufpos newpos, even_newer_pos; 2885 Bufpos newpos, even_newer_pos;
2886 Bufpos oldpos = lisp_buffer_stream_startpos (istr); 2886 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
2887 Lstream_data_count size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); 2887 Lstream_Data_Count size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
2888 2888
2889 if (!size_in_bytes) 2889 if (!size_in_bytes)
2890 break; 2890 break;
2891 newpos = lisp_buffer_stream_startpos (istr); 2891 newpos = lisp_buffer_stream_startpos (istr);
2892 Lstream_write (ostr, tempbuf, size_in_bytes); 2892 Lstream_write (ostr, tempbuf, size_in_bytes);
2945 2945
2946 #define BYTE_SJIS_KATAKANA_P(c) \ 2946 #define BYTE_SJIS_KATAKANA_P(c) \
2947 ((c) >= 0xA1 && (c) <= 0xDF) 2947 ((c) >= 0xA1 && (c) <= 0xDF)
2948 2948
2949 static int 2949 static int
2950 detect_coding_sjis (struct detection_state *st, const Extbyte *src, Lstream_data_count n) 2950 detect_coding_sjis (struct detection_state *st, const Extbyte *src, Lstream_Data_Count n)
2951 { 2951 {
2952 while (n--) 2952 while (n--)
2953 { 2953 {
2954 unsigned char c = *(unsigned char *)src++; 2954 unsigned char c = *(unsigned char *)src++;
2955 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) 2955 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
2968 2968
2969 /* Convert Shift-JIS data to internal format. */ 2969 /* Convert Shift-JIS data to internal format. */
2970 2970
2971 static void 2971 static void
2972 decode_coding_sjis (Lstream *decoding, const Extbyte *src, 2972 decode_coding_sjis (Lstream *decoding, const Extbyte *src,
2973 unsigned_char_dynarr *dst, Lstream_data_count n) 2973 unsigned_char_dynarr *dst, Lstream_Data_Count n)
2974 { 2974 {
2975 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 2975 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
2976 unsigned int flags = str->flags; 2976 unsigned int flags = str->flags;
2977 unsigned int ch = str->ch; 2977 unsigned int ch = str->ch;
2978 eol_type_t eol_type = str->eol_type; 2978 eol_type_t eol_type = str->eol_type;
3024 3024
3025 /* Convert internally-formatted data to Shift-JIS. */ 3025 /* Convert internally-formatted data to Shift-JIS. */
3026 3026
3027 static void 3027 static void
3028 encode_coding_sjis (Lstream *encoding, const Bufbyte *src, 3028 encode_coding_sjis (Lstream *encoding, const Bufbyte *src,
3029 unsigned_char_dynarr *dst, Lstream_data_count n) 3029 unsigned_char_dynarr *dst, Lstream_Data_Count n)
3030 { 3030 {
3031 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 3031 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3032 unsigned int flags = str->flags; 3032 unsigned int flags = str->flags;
3033 unsigned int ch = str->ch; 3033 unsigned int ch = str->ch;
3034 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys); 3034 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
3193 */ 3193 */
3194 3194
3195 #define DECODE_BIG5(b1, b2, lb, c1, c2) do \ 3195 #define DECODE_BIG5(b1, b2, lb, c1, c2) do \
3196 { \ 3196 { \
3197 int B1 = b1, B2 = b2; \ 3197 int B1 = b1, B2 = b2; \
3198 unsigned int I \ 3198 int I \
3199 = (B1 - 0xA1) * BIG5_SAME_ROW + B2 - (B2 < 0x7F ? 0x40 : 0x62); \ 3199 = (B1 - 0xA1) * BIG5_SAME_ROW + B2 - (B2 < 0x7F ? 0x40 : 0x62); \
3200 \ 3200 \
3201 if (B1 < 0xC9) \ 3201 if (B1 < 0xC9) \
3202 { \ 3202 { \
3203 lb = LEADING_BYTE_CHINESE_BIG5_1; \ 3203 lb = LEADING_BYTE_CHINESE_BIG5_1; \
3214 /* Convert the internal string representation of a Big5 character 3214 /* Convert the internal string representation of a Big5 character
3215 (lb, c1, c2) into Big5 code (b1, b2). */ 3215 (lb, c1, c2) into Big5 code (b1, b2). */
3216 3216
3217 #define ENCODE_BIG5(lb, c1, c2, b1, b2) do \ 3217 #define ENCODE_BIG5(lb, c1, c2, b1, b2) do \
3218 { \ 3218 { \
3219 unsigned int I = ((c1) - 0xA1) * (0xFF - 0xA1) + ((c2) - 0xA1); \ 3219 int I = ((c1) - 0xA1) * (0xFF - 0xA1) + ((c2) - 0xA1); \
3220 \ 3220 \
3221 if (lb == LEADING_BYTE_CHINESE_BIG5_2) \ 3221 if (lb == LEADING_BYTE_CHINESE_BIG5_2) \
3222 { \ 3222 { \
3223 I += BIG5_SAME_ROW * (0xC9 - 0xA1); \ 3223 I += BIG5_SAME_ROW * (0xC9 - 0xA1); \
3224 } \ 3224 } \
3226 b2 = I % BIG5_SAME_ROW; \ 3226 b2 = I % BIG5_SAME_ROW; \
3227 b2 += b2 < 0x3F ? 0x40 : 0x62; \ 3227 b2 += b2 < 0x3F ? 0x40 : 0x62; \
3228 } while (0) 3228 } while (0)
3229 3229
3230 static int 3230 static int
3231 detect_coding_big5 (struct detection_state *st, const Extbyte *src, Lstream_data_count n) 3231 detect_coding_big5 (struct detection_state *st, const Extbyte *src, Lstream_Data_Count n)
3232 { 3232 {
3233 while (n--) 3233 while (n--)
3234 { 3234 {
3235 unsigned char c = *(unsigned char *)src++; 3235 unsigned char c = *(unsigned char *)src++;
3236 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO || 3236 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO ||
3250 3250
3251 /* Convert Big5 data to internal format. */ 3251 /* Convert Big5 data to internal format. */
3252 3252
3253 static void 3253 static void
3254 decode_coding_big5 (Lstream *decoding, const Extbyte *src, 3254 decode_coding_big5 (Lstream *decoding, const Extbyte *src,
3255 unsigned_char_dynarr *dst, Lstream_data_count n) 3255 unsigned_char_dynarr *dst, Lstream_Data_Count n)
3256 { 3256 {
3257 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 3257 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3258 unsigned int flags = str->flags; 3258 unsigned int flags = str->flags;
3259 unsigned int ch = str->ch; 3259 unsigned int ch = str->ch;
3260 eol_type_t eol_type = str->eol_type; 3260 eol_type_t eol_type = str->eol_type;
3299 3299
3300 /* Convert internally-formatted data to Big5. */ 3300 /* Convert internally-formatted data to Big5. */
3301 3301
3302 static void 3302 static void
3303 encode_coding_big5 (Lstream *encoding, const Bufbyte *src, 3303 encode_coding_big5 (Lstream *encoding, const Bufbyte *src,
3304 unsigned_char_dynarr *dst, Lstream_data_count n) 3304 unsigned_char_dynarr *dst, Lstream_Data_Count n)
3305 { 3305 {
3306 unsigned char c; 3306 unsigned char c;
3307 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 3307 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3308 unsigned int flags = str->flags; 3308 unsigned int flags = str->flags;
3309 unsigned int ch = str->ch; 3309 unsigned int ch = str->ch;
3423 3423
3424 Return T on success, NIL on failure. 3424 Return T on success, NIL on failure.
3425 */ 3425 */
3426 (code, character)) 3426 (code, character))
3427 { 3427 {
3428 size_t c; 3428 EMACS_INT c;
3429 3429
3430 CHECK_CHAR (character); 3430 CHECK_CHAR (character);
3431 CHECK_NATNUM (code); 3431 CHECK_NATNUM (code);
3432 c = XINT (code); 3432 c = XINT (code);
3433 3433
3565 Dynarr_add (dst, (code >> 8) & 255); 3565 Dynarr_add (dst, (code >> 8) & 255);
3566 Dynarr_add (dst, code & 255); 3566 Dynarr_add (dst, code & 255);
3567 } 3567 }
3568 3568
3569 static int 3569 static int
3570 detect_coding_ucs4 (struct detection_state *st, const Extbyte *src, Lstream_data_count n) 3570 detect_coding_ucs4 (struct detection_state *st, const Extbyte *src, Lstream_Data_Count n)
3571 { 3571 {
3572 while (n--) 3572 while (n--)
3573 { 3573 {
3574 unsigned char c = *(unsigned char *)src++; 3574 unsigned char c = *(unsigned char *)src++;
3575 switch (st->ucs4.in_byte) 3575 switch (st->ucs4.in_byte)
3590 return CODING_CATEGORY_UCS4_MASK; 3590 return CODING_CATEGORY_UCS4_MASK;
3591 } 3591 }
3592 3592
3593 static void 3593 static void
3594 decode_coding_ucs4 (Lstream *decoding, const Extbyte *src, 3594 decode_coding_ucs4 (Lstream *decoding, const Extbyte *src,
3595 unsigned_char_dynarr *dst, Lstream_data_count n) 3595 unsigned_char_dynarr *dst, Lstream_Data_Count n)
3596 { 3596 {
3597 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 3597 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3598 unsigned int flags = str->flags; 3598 unsigned int flags = str->flags;
3599 unsigned int ch = str->ch; 3599 unsigned int ch = str->ch;
3600 unsigned char counter = str->counter; 3600 unsigned char counter = str->counter;
3626 str->counter = counter; 3626 str->counter = counter;
3627 } 3627 }
3628 3628
3629 static void 3629 static void
3630 encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src, 3630 encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src,
3631 unsigned_char_dynarr *dst, Lstream_data_count n) 3631 unsigned_char_dynarr *dst, Lstream_Data_Count n)
3632 { 3632 {
3633 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 3633 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3634 unsigned int flags = str->flags; 3634 unsigned int flags = str->flags;
3635 unsigned int ch = str->ch; 3635 unsigned int ch = str->ch;
3636 unsigned char char_boundary = str->iso2022.current_char_boundary; 3636 unsigned char char_boundary = str->iso2022.current_char_boundary;
3637 Lisp_Object charset = str->iso2022.current_charset; 3637 Lisp_Object charset = str->iso2022.current_charset;
3638 3638
3639 #ifdef ENABLE_COMPOSITE_CHARS 3639 #ifdef ENABLE_COMPOSITE_CHARS
3640 /* flags for handling composite chars. We do a little switcharoo 3640 /* flags for handling composite chars. We do a little switcharoo
3641 on the source while we're outputting the composite char. */ 3641 on the source while we're outputting the composite char. */
3642 unsigned int saved_n = 0; 3642 Lstream_Data_Count saved_n = 0;
3643 const unsigned char *saved_src = NULL; 3643 const unsigned char *saved_src = NULL;
3644 int in_composite = 0; 3644 int in_composite = 0;
3645 3645
3646 back_to_square_n: 3646 back_to_square_n:
3647 #endif 3647 #endif
3764 /************************************************************************/ 3764 /************************************************************************/
3765 /* UTF-8 methods */ 3765 /* UTF-8 methods */
3766 /************************************************************************/ 3766 /************************************************************************/
3767 3767
3768 static int 3768 static int
3769 detect_coding_utf8 (struct detection_state *st, const Extbyte *src, Lstream_data_count n) 3769 detect_coding_utf8 (struct detection_state *st, const Extbyte *src, Lstream_Data_Count n)
3770 { 3770 {
3771 while (n--) 3771 while (n--)
3772 { 3772 {
3773 unsigned char c = *(unsigned char *)src++; 3773 unsigned char c = *(unsigned char *)src++;
3774 switch (st->utf8.in_byte) 3774 switch (st->utf8.in_byte)
3799 return CODING_CATEGORY_UTF8_MASK; 3799 return CODING_CATEGORY_UTF8_MASK;
3800 } 3800 }
3801 3801
3802 static void 3802 static void
3803 decode_coding_utf8 (Lstream *decoding, const Extbyte *src, 3803 decode_coding_utf8 (Lstream *decoding, const Extbyte *src,
3804 unsigned_char_dynarr *dst, Lstream_data_count n) 3804 unsigned_char_dynarr *dst, Lstream_Data_Count n)
3805 { 3805 {
3806 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 3806 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3807 unsigned int flags = str->flags; 3807 unsigned int flags = str->flags;
3808 unsigned int ch = str->ch; 3808 unsigned int ch = str->ch;
3809 eol_type_t eol_type = str->eol_type; 3809 eol_type_t eol_type = str->eol_type;
3913 } 3913 }
3914 } 3914 }
3915 3915
3916 static void 3916 static void
3917 encode_coding_utf8 (Lstream *encoding, const Bufbyte *src, 3917 encode_coding_utf8 (Lstream *encoding, const Bufbyte *src,
3918 unsigned_char_dynarr *dst, Lstream_data_count n) 3918 unsigned_char_dynarr *dst, Lstream_Data_Count n)
3919 { 3919 {
3920 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 3920 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3921 unsigned int flags = str->flags; 3921 unsigned int flags = str->flags;
3922 unsigned int ch = str->ch; 3922 unsigned int ch = str->ch;
3923 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys); 3923 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
3925 Lisp_Object charset = str->iso2022.current_charset; 3925 Lisp_Object charset = str->iso2022.current_charset;
3926 3926
3927 #ifdef ENABLE_COMPOSITE_CHARS 3927 #ifdef ENABLE_COMPOSITE_CHARS
3928 /* flags for handling composite chars. We do a little switcharoo 3928 /* flags for handling composite chars. We do a little switcharoo
3929 on the source while we're outputting the composite char. */ 3929 on the source while we're outputting the composite char. */
3930 unsigned int saved_n = 0; 3930 Lstream_Data_Count saved_n = 0;
3931 const unsigned char *saved_src = NULL; 3931 const unsigned char *saved_src = NULL;
3932 int in_composite = 0; 3932 int in_composite = 0;
3933 3933
3934 back_to_square_n: 3934 back_to_square_n:
3935 #endif /* ENABLE_COMPOSITE_CHARS */ 3935 #endif /* ENABLE_COMPOSITE_CHARS */
4672 iso->switched_dir_and_no_valid_charset_yet = 0; 4672 iso->switched_dir_and_no_valid_charset_yet = 0;
4673 return 1; 4673 return 1;
4674 } 4674 }
4675 4675
4676 static int 4676 static int
4677 detect_coding_iso2022 (struct detection_state *st, const Extbyte *src, Lstream_data_count n) 4677 detect_coding_iso2022 (struct detection_state *st, const Extbyte *src, Lstream_Data_Count n)
4678 { 4678 {
4679 int mask; 4679 int mask;
4680 4680
4681 /* #### There are serious deficiencies in the recognition mechanism 4681 /* #### There are serious deficiencies in the recognition mechanism
4682 here. This needs to be much smarter if it's going to cut it. 4682 here. This needs to be much smarter if it's going to cut it.
4863 4863
4864 /* Convert ISO2022-format data to internal format. */ 4864 /* Convert ISO2022-format data to internal format. */
4865 4865
4866 static void 4866 static void
4867 decode_coding_iso2022 (Lstream *decoding, const Extbyte *src, 4867 decode_coding_iso2022 (Lstream *decoding, const Extbyte *src,
4868 unsigned_char_dynarr *dst, Lstream_data_count n) 4868 unsigned_char_dynarr *dst, Lstream_Data_Count n)
4869 { 4869 {
4870 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 4870 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
4871 unsigned int flags = str->flags; 4871 unsigned int flags = str->flags;
4872 unsigned int ch = str->ch; 4872 unsigned int ch = str->ch;
4873 eol_type_t eol_type = str->eol_type; 4873 eol_type_t eol_type = str->eol_type;
5105 iso2022_designate (Lisp_Object charset, unsigned char reg, 5105 iso2022_designate (Lisp_Object charset, unsigned char reg,
5106 struct encoding_stream *str, unsigned_char_dynarr *dst) 5106 struct encoding_stream *str, unsigned_char_dynarr *dst)
5107 { 5107 {
5108 static const char inter94[] = "()*+"; 5108 static const char inter94[] = "()*+";
5109 static const char inter96[] = ",-./"; 5109 static const char inter96[] = ",-./";
5110 unsigned int type; 5110 int type;
5111 unsigned char final; 5111 unsigned char final;
5112 Lisp_Object old_charset = str->iso2022.charset[reg]; 5112 Lisp_Object old_charset = str->iso2022.charset[reg];
5113 5113
5114 str->iso2022.charset[reg] = charset; 5114 str->iso2022.charset[reg] = charset;
5115 if (!CHARSETP (charset)) 5115 if (!CHARSETP (charset))
5189 5189
5190 /* Convert internally-formatted data to ISO2022 format. */ 5190 /* Convert internally-formatted data to ISO2022 format. */
5191 5191
5192 static void 5192 static void
5193 encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src, 5193 encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src,
5194 unsigned_char_dynarr *dst, Lstream_data_count n) 5194 unsigned_char_dynarr *dst, Lstream_Data_Count n)
5195 { 5195 {
5196 unsigned char charmask, c; 5196 unsigned char charmask, c;
5197 unsigned char char_boundary; 5197 unsigned char char_boundary;
5198 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 5198 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
5199 unsigned int flags = str->flags; 5199 unsigned int flags = str->flags;
5205 int half; 5205 int half;
5206 5206
5207 #ifdef ENABLE_COMPOSITE_CHARS 5207 #ifdef ENABLE_COMPOSITE_CHARS
5208 /* flags for handling composite chars. We do a little switcharoo 5208 /* flags for handling composite chars. We do a little switcharoo
5209 on the source while we're outputting the composite char. */ 5209 on the source while we're outputting the composite char. */
5210 unsigned int saved_n = 0; 5210 Lstream_Data_Count saved_n = 0;
5211 const unsigned char *saved_src = NULL; 5211 const unsigned char *saved_src = NULL;
5212 int in_composite = 0; 5212 int in_composite = 0;
5213 #endif /* ENABLE_COMPOSITE_CHARS */ 5213 #endif /* ENABLE_COMPOSITE_CHARS */
5214 5214
5215 char_boundary = str->iso2022.current_char_boundary; 5215 char_boundary = str->iso2022.current_char_boundary;
5498 /* This is used when reading in "binary" files -- i.e. files that may 5498 /* This is used when reading in "binary" files -- i.e. files that may
5499 contain all 256 possible byte values and that are not to be 5499 contain all 256 possible byte values and that are not to be
5500 interpreted as being in any particular decoding. */ 5500 interpreted as being in any particular decoding. */
5501 static void 5501 static void
5502 decode_coding_no_conversion (Lstream *decoding, const Extbyte *src, 5502 decode_coding_no_conversion (Lstream *decoding, const Extbyte *src,
5503 unsigned_char_dynarr *dst, Lstream_data_count n) 5503 unsigned_char_dynarr *dst, Lstream_Data_Count n)
5504 { 5504 {
5505 struct decoding_stream *str = DECODING_STREAM_DATA (decoding); 5505 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
5506 unsigned int flags = str->flags; 5506 unsigned int flags = str->flags;
5507 unsigned int ch = str->ch; 5507 unsigned int ch = str->ch;
5508 eol_type_t eol_type = str->eol_type; 5508 eol_type_t eol_type = str->eol_type;
5522 str->ch = ch; 5522 str->ch = ch;
5523 } 5523 }
5524 5524
5525 static void 5525 static void
5526 encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src, 5526 encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src,
5527 unsigned_char_dynarr *dst, Lstream_data_count n) 5527 unsigned_char_dynarr *dst, Lstream_Data_Count n)
5528 { 5528 {
5529 unsigned char c; 5529 unsigned char c;
5530 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding); 5530 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
5531 unsigned int flags = str->flags; 5531 unsigned int flags = str->flags;
5532 unsigned int ch = str->ch; 5532 unsigned int ch = str->ch;
5847 fcd->coding_category_system[CODING_CATEGORY_NO_CONVERSION] = 5847 fcd->coding_category_system[CODING_CATEGORY_NO_CONVERSION] =
5848 Fget_coding_system (Qraw_text); 5848 Fget_coding_system (Qraw_text);
5849 5849
5850 #ifdef MULE 5850 #ifdef MULE
5851 { 5851 {
5852 size_t i; 5852 int i;
5853 5853
5854 for (i = 0; i < countof (fcd->ucs_to_mule_table); i++) 5854 for (i = 0; i < countof (fcd->ucs_to_mule_table); i++)
5855 fcd->ucs_to_mule_table[i] = Qnil; 5855 fcd->ucs_to_mule_table[i] = Qnil;
5856 } 5856 }
5857 staticpro (&mule_to_ucs_table); 5857 staticpro (&mule_to_ucs_table);
5858 mule_to_ucs_table = Fmake_char_table(Qgeneric); 5858 mule_to_ucs_table = Fmake_char_table (Qgeneric);
5859 #endif /* MULE */ 5859 #endif /* MULE */
5860 } 5860 }