comparison src/coding.c @ 109423:ae5ef13849d8

Merge from mainline.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Sun, 04 Jul 2010 22:11:22 +0000
parents aec1143e8d85
children 6175ebc3b6ce
comparison
equal deleted inserted replaced
109422:bcedeeedc5fb 109423:ae5ef13849d8
894 EMIT_TWO_BYTES (c3, c4); \ 894 EMIT_TWO_BYTES (c3, c4); \
895 } while (0) 895 } while (0)
896 896
897 897
898 /* Prototypes for static functions. */ 898 /* Prototypes for static functions. */
899 static void record_conversion_result P_ ((struct coding_system *coding, 899 static void record_conversion_result (struct coding_system *coding,
900 enum coding_result_code result)); 900 enum coding_result_code result);
901 static int detect_coding_utf_8 P_ ((struct coding_system *, 901 static int detect_coding_utf_8 (struct coding_system *,
902 struct coding_detection_info *info)); 902 struct coding_detection_info *info);
903 static void decode_coding_utf_8 P_ ((struct coding_system *)); 903 static void decode_coding_utf_8 (struct coding_system *);
904 static int encode_coding_utf_8 P_ ((struct coding_system *)); 904 static int encode_coding_utf_8 (struct coding_system *);
905 905
906 static int detect_coding_utf_16 P_ ((struct coding_system *, 906 static int detect_coding_utf_16 (struct coding_system *,
907 struct coding_detection_info *info)); 907 struct coding_detection_info *info);
908 static void decode_coding_utf_16 P_ ((struct coding_system *)); 908 static void decode_coding_utf_16 (struct coding_system *);
909 static int encode_coding_utf_16 P_ ((struct coding_system *)); 909 static int encode_coding_utf_16 (struct coding_system *);
910 910
911 static int detect_coding_iso_2022 P_ ((struct coding_system *, 911 static int detect_coding_iso_2022 (struct coding_system *,
912 struct coding_detection_info *info)); 912 struct coding_detection_info *info);
913 static void decode_coding_iso_2022 P_ ((struct coding_system *)); 913 static void decode_coding_iso_2022 (struct coding_system *);
914 static int encode_coding_iso_2022 P_ ((struct coding_system *)); 914 static int encode_coding_iso_2022 (struct coding_system *);
915 915
916 static int detect_coding_emacs_mule P_ ((struct coding_system *, 916 static int detect_coding_emacs_mule (struct coding_system *,
917 struct coding_detection_info *info)); 917 struct coding_detection_info *info);
918 static void decode_coding_emacs_mule P_ ((struct coding_system *)); 918 static void decode_coding_emacs_mule (struct coding_system *);
919 static int encode_coding_emacs_mule P_ ((struct coding_system *)); 919 static int encode_coding_emacs_mule (struct coding_system *);
920 920
921 static int detect_coding_sjis P_ ((struct coding_system *, 921 static int detect_coding_sjis (struct coding_system *,
922 struct coding_detection_info *info)); 922 struct coding_detection_info *info);
923 static void decode_coding_sjis P_ ((struct coding_system *)); 923 static void decode_coding_sjis (struct coding_system *);
924 static int encode_coding_sjis P_ ((struct coding_system *)); 924 static int encode_coding_sjis (struct coding_system *);
925 925
926 static int detect_coding_big5 P_ ((struct coding_system *, 926 static int detect_coding_big5 (struct coding_system *,
927 struct coding_detection_info *info)); 927 struct coding_detection_info *info);
928 static void decode_coding_big5 P_ ((struct coding_system *)); 928 static void decode_coding_big5 (struct coding_system *);
929 static int encode_coding_big5 P_ ((struct coding_system *)); 929 static int encode_coding_big5 (struct coding_system *);
930 930
931 static int detect_coding_ccl P_ ((struct coding_system *, 931 static int detect_coding_ccl (struct coding_system *,
932 struct coding_detection_info *info)); 932 struct coding_detection_info *info);
933 static void decode_coding_ccl P_ ((struct coding_system *)); 933 static void decode_coding_ccl (struct coding_system *);
934 static int encode_coding_ccl P_ ((struct coding_system *)); 934 static int encode_coding_ccl (struct coding_system *);
935 935
936 static void decode_coding_raw_text P_ ((struct coding_system *)); 936 static void decode_coding_raw_text (struct coding_system *);
937 static int encode_coding_raw_text P_ ((struct coding_system *)); 937 static int encode_coding_raw_text (struct coding_system *);
938 938
939 static void coding_set_source P_ ((struct coding_system *)); 939 static void coding_set_source (struct coding_system *);
940 static void coding_set_destination P_ ((struct coding_system *)); 940 static void coding_set_destination (struct coding_system *);
941 static void coding_alloc_by_realloc P_ ((struct coding_system *, EMACS_INT)); 941 static void coding_alloc_by_realloc (struct coding_system *, EMACS_INT);
942 static void coding_alloc_by_making_gap P_ ((struct coding_system *, 942 static void coding_alloc_by_making_gap (struct coding_system *,
943 EMACS_INT, EMACS_INT)); 943 EMACS_INT, EMACS_INT);
944 static unsigned char *alloc_destination P_ ((struct coding_system *, 944 static unsigned char *alloc_destination (struct coding_system *,
945 EMACS_INT, unsigned char *)); 945 EMACS_INT, unsigned char *);
946 static void setup_iso_safe_charsets P_ ((Lisp_Object)); 946 static void setup_iso_safe_charsets (Lisp_Object);
947 static unsigned char *encode_designation_at_bol P_ ((struct coding_system *, 947 static unsigned char *encode_designation_at_bol (struct coding_system *,
948 int *, int *, 948 int *, int *,
949 unsigned char *)); 949 unsigned char *);
950 static int detect_eol P_ ((const unsigned char *, 950 static int detect_eol (const unsigned char *,
951 EMACS_INT, enum coding_category)); 951 EMACS_INT, enum coding_category);
952 static Lisp_Object adjust_coding_eol_type P_ ((struct coding_system *, int)); 952 static Lisp_Object adjust_coding_eol_type (struct coding_system *, int);
953 static void decode_eol P_ ((struct coding_system *)); 953 static void decode_eol (struct coding_system *);
954 static Lisp_Object get_translation_table P_ ((Lisp_Object, int, int *)); 954 static Lisp_Object get_translation_table (Lisp_Object, int, int *);
955 static Lisp_Object get_translation P_ ((Lisp_Object, int *, int *)); 955 static Lisp_Object get_translation (Lisp_Object, int *, int *);
956 static int produce_chars P_ ((struct coding_system *, Lisp_Object, int)); 956 static int produce_chars (struct coding_system *, Lisp_Object, int);
957 static INLINE void produce_charset P_ ((struct coding_system *, int *, 957 static INLINE void produce_charset (struct coding_system *, int *,
958 EMACS_INT)); 958 EMACS_INT);
959 static void produce_annotation P_ ((struct coding_system *, EMACS_INT)); 959 static void produce_annotation (struct coding_system *, EMACS_INT);
960 static int decode_coding P_ ((struct coding_system *)); 960 static int decode_coding (struct coding_system *);
961 static INLINE int *handle_composition_annotation P_ ((EMACS_INT, EMACS_INT, 961 static INLINE int *handle_composition_annotation (EMACS_INT, EMACS_INT,
962 struct coding_system *, 962 struct coding_system *,
963 int *, EMACS_INT *)); 963 int *, EMACS_INT *);
964 static INLINE int *handle_charset_annotation P_ ((EMACS_INT, EMACS_INT, 964 static INLINE int *handle_charset_annotation (EMACS_INT, EMACS_INT,
965 struct coding_system *, 965 struct coding_system *,
966 int *, EMACS_INT *)); 966 int *, EMACS_INT *);
967 static void consume_chars P_ ((struct coding_system *, Lisp_Object, int)); 967 static void consume_chars (struct coding_system *, Lisp_Object, int);
968 static int encode_coding P_ ((struct coding_system *)); 968 static int encode_coding (struct coding_system *);
969 static Lisp_Object make_conversion_work_buffer P_ ((int)); 969 static Lisp_Object make_conversion_work_buffer (int);
970 static Lisp_Object code_conversion_restore P_ ((Lisp_Object)); 970 static Lisp_Object code_conversion_restore (Lisp_Object);
971 static INLINE int char_encodable_p P_ ((int, Lisp_Object)); 971 static INLINE int char_encodable_p (int, Lisp_Object);
972 static Lisp_Object make_subsidiaries P_ ((Lisp_Object)); 972 static Lisp_Object make_subsidiaries (Lisp_Object);
973 973
974 static void 974 static void
975 record_conversion_result (struct coding_system *coding, 975 record_conversion_result (struct coding_system *coding,
976 enum coding_result_code result) 976 enum coding_result_code result)
977 { 977 {
1104 | (((p)[-2] & 0x3F) << 6) \ 1104 | (((p)[-2] & 0x3F) << 6) \
1105 | ((p)[-1] & 0x3F)))) 1105 | ((p)[-1] & 0x3F))))
1106 1106
1107 1107
1108 static void 1108 static void
1109 coding_set_source (coding) 1109 coding_set_source (struct coding_system *coding)
1110 struct coding_system *coding;
1111 { 1110 {
1112 if (BUFFERP (coding->src_object)) 1111 if (BUFFERP (coding->src_object))
1113 { 1112 {
1114 struct buffer *buf = XBUFFER (coding->src_object); 1113 struct buffer *buf = XBUFFER (coding->src_object);
1115 1114
1127 automatically. Thus we don't have to update anything. */ 1126 automatically. Thus we don't have to update anything. */
1128 ; 1127 ;
1129 } 1128 }
1130 1129
1131 static void 1130 static void
1132 coding_set_destination (coding) 1131 coding_set_destination (struct coding_system *coding)
1133 struct coding_system *coding;
1134 { 1132 {
1135 if (BUFFERP (coding->dst_object)) 1133 if (BUFFERP (coding->dst_object))
1136 { 1134 {
1137 if (coding->src_pos < 0) 1135 if (coding->src_pos < 0)
1138 { 1136 {
1157 ; 1155 ;
1158 } 1156 }
1159 1157
1160 1158
1161 static void 1159 static void
1162 coding_alloc_by_realloc (coding, bytes) 1160 coding_alloc_by_realloc (struct coding_system *coding, EMACS_INT bytes)
1163 struct coding_system *coding;
1164 EMACS_INT bytes;
1165 { 1161 {
1166 coding->destination = (unsigned char *) xrealloc (coding->destination, 1162 coding->destination = (unsigned char *) xrealloc (coding->destination,
1167 coding->dst_bytes + bytes); 1163 coding->dst_bytes + bytes);
1168 coding->dst_bytes += bytes; 1164 coding->dst_bytes += bytes;
1169 } 1165 }
1170 1166
1171 static void 1167 static void
1172 coding_alloc_by_making_gap (coding, gap_head_used, bytes) 1168 coding_alloc_by_making_gap (struct coding_system *coding, EMACS_INT gap_head_used, EMACS_INT bytes)
1173 struct coding_system *coding;
1174 EMACS_INT gap_head_used, bytes;
1175 { 1169 {
1176 if (EQ (coding->src_object, coding->dst_object)) 1170 if (EQ (coding->src_object, coding->dst_object))
1177 { 1171 {
1178 /* The gap may contain the produced data at the head and not-yet 1172 /* The gap may contain the produced data at the head and not-yet
1179 consumed data at the tail. To preserve those data, we at 1173 consumed data at the tail. To preserve those data, we at
1198 } 1192 }
1199 } 1193 }
1200 1194
1201 1195
1202 static unsigned char * 1196 static unsigned char *
1203 alloc_destination (coding, nbytes, dst) 1197 alloc_destination (struct coding_system *coding, EMACS_INT nbytes, unsigned char *dst)
1204 struct coding_system *coding;
1205 EMACS_INT nbytes;
1206 unsigned char *dst;
1207 { 1198 {
1208 EMACS_INT offset = dst - coding->destination; 1199 EMACS_INT offset = dst - coding->destination;
1209 1200
1210 if (BUFFERP (coding->dst_object)) 1201 if (BUFFERP (coding->dst_object))
1211 { 1202 {
1299 #define UTF_8_BOM_1 0xEF 1290 #define UTF_8_BOM_1 0xEF
1300 #define UTF_8_BOM_2 0xBB 1291 #define UTF_8_BOM_2 0xBB
1301 #define UTF_8_BOM_3 0xBF 1292 #define UTF_8_BOM_3 0xBF
1302 1293
1303 static int 1294 static int
1304 detect_coding_utf_8 (coding, detect_info) 1295 detect_coding_utf_8 (struct coding_system *coding, struct coding_detection_info *detect_info)
1305 struct coding_system *coding;
1306 struct coding_detection_info *detect_info;
1307 { 1296 {
1308 const unsigned char *src = coding->source, *src_base; 1297 const unsigned char *src = coding->source, *src_base;
1309 const unsigned char *src_end = coding->source + coding->src_bytes; 1298 const unsigned char *src_end = coding->source + coding->src_bytes;
1310 int multibytep = coding->src_multibyte; 1299 int multibytep = coding->src_multibyte;
1311 int consumed_chars = 0; 1300 int consumed_chars = 0;
1384 return 1; 1373 return 1;
1385 } 1374 }
1386 1375
1387 1376
1388 static void 1377 static void
1389 decode_coding_utf_8 (coding) 1378 decode_coding_utf_8 (struct coding_system *coding)
1390 struct coding_system *coding;
1391 { 1379 {
1392 const unsigned char *src = coding->source + coding->consumed; 1380 const unsigned char *src = coding->source + coding->consumed;
1393 const unsigned char *src_end = coding->source + coding->src_bytes; 1381 const unsigned char *src_end = coding->source + coding->src_bytes;
1394 const unsigned char *src_base; 1382 const unsigned char *src_base;
1395 int *charbuf = coding->charbuf + coding->charbuf_used; 1383 int *charbuf = coding->charbuf + coding->charbuf_used;
1541 coding->charbuf_used = charbuf - coding->charbuf; 1529 coding->charbuf_used = charbuf - coding->charbuf;
1542 } 1530 }
1543 1531
1544 1532
1545 static int 1533 static int
1546 encode_coding_utf_8 (coding) 1534 encode_coding_utf_8 (struct coding_system *coding)
1547 struct coding_system *coding;
1548 { 1535 {
1549 int multibytep = coding->dst_multibyte; 1536 int multibytep = coding->dst_multibyte;
1550 int *charbuf = coding->charbuf; 1537 int *charbuf = coding->charbuf;
1551 int *charbuf_end = charbuf + coding->charbuf_used; 1538 int *charbuf_end = charbuf + coding->charbuf_used;
1552 unsigned char *dst = coding->destination + coding->produced; 1539 unsigned char *dst = coding->destination + coding->produced;
1621 || ((val) == 0xFFFF) \ 1608 || ((val) == 0xFFFF) \
1622 || UTF_16_LOW_SURROGATE_P (val)) 1609 || UTF_16_LOW_SURROGATE_P (val))
1623 1610
1624 1611
1625 static int 1612 static int
1626 detect_coding_utf_16 (coding, detect_info) 1613 detect_coding_utf_16 (struct coding_system *coding, struct coding_detection_info *detect_info)
1627 struct coding_system *coding;
1628 struct coding_detection_info *detect_info;
1629 { 1614 {
1630 const unsigned char *src = coding->source, *src_base = src; 1615 const unsigned char *src = coding->source, *src_base = src;
1631 const unsigned char *src_end = coding->source + coding->src_bytes; 1616 const unsigned char *src_end = coding->source + coding->src_bytes;
1632 int multibytep = coding->src_multibyte; 1617 int multibytep = coding->src_multibyte;
1633 int consumed_chars = 0; 1618 int consumed_chars = 0;
1706 no_more_source: 1691 no_more_source:
1707 return 1; 1692 return 1;
1708 } 1693 }
1709 1694
1710 static void 1695 static void
1711 decode_coding_utf_16 (coding) 1696 decode_coding_utf_16 (struct coding_system *coding)
1712 struct coding_system *coding;
1713 { 1697 {
1714 const unsigned char *src = coding->source + coding->consumed; 1698 const unsigned char *src = coding->source + coding->consumed;
1715 const unsigned char *src_end = coding->source + coding->src_bytes; 1699 const unsigned char *src_end = coding->source + coding->src_bytes;
1716 const unsigned char *src_base; 1700 const unsigned char *src_base;
1717 int *charbuf = coding->charbuf + coding->charbuf_used; 1701 int *charbuf = coding->charbuf + coding->charbuf_used;
1835 coding->consumed = src_base - coding->source; 1819 coding->consumed = src_base - coding->source;
1836 coding->charbuf_used = charbuf - coding->charbuf; 1820 coding->charbuf_used = charbuf - coding->charbuf;
1837 } 1821 }
1838 1822
1839 static int 1823 static int
1840 encode_coding_utf_16 (coding) 1824 encode_coding_utf_16 (struct coding_system *coding)
1841 struct coding_system *coding;
1842 { 1825 {
1843 int multibytep = coding->dst_multibyte; 1826 int multibytep = coding->dst_multibyte;
1844 int *charbuf = coding->charbuf; 1827 int *charbuf = coding->charbuf;
1845 int *charbuf_end = charbuf + coding->charbuf_used; 1828 int *charbuf_end = charbuf + coding->charbuf_used;
1846 unsigned char *dst = coding->destination + coding->produced; 1829 unsigned char *dst = coding->destination + coding->produced;
1977 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". 1960 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
1978 Check if a text is encoded in `emacs-mule'. If it is, return 1, 1961 Check if a text is encoded in `emacs-mule'. If it is, return 1,
1979 else return 0. */ 1962 else return 0. */
1980 1963
1981 static int 1964 static int
1982 detect_coding_emacs_mule (coding, detect_info) 1965 detect_coding_emacs_mule (struct coding_system *coding, struct coding_detection_info *detect_info)
1983 struct coding_system *coding;
1984 struct coding_detection_info *detect_info;
1985 { 1966 {
1986 const unsigned char *src = coding->source, *src_base; 1967 const unsigned char *src = coding->source, *src_base;
1987 const unsigned char *src_end = coding->source + coding->src_bytes; 1968 const unsigned char *src_end = coding->source + coding->src_bytes;
1988 int multibytep = coding->src_multibyte; 1969 int multibytep = coding->src_multibyte;
1989 int consumed_chars = 0; 1970 int consumed_chars = 0;
2067 RULE described above, decode it and return the negative value of 2048 RULE described above, decode it and return the negative value of
2068 the decoded character or rule. If an invalid byte is found, return 2049 the decoded character or rule. If an invalid byte is found, return
2069 -1. If SRC is too short, return -2. */ 2050 -1. If SRC is too short, return -2. */
2070 2051
2071 int 2052 int
2072 emacs_mule_char (coding, src, nbytes, nchars, id, cmp_status) 2053 emacs_mule_char (struct coding_system *coding, const unsigned char *src, int *nbytes, int *nchars, int *id, struct composition_status *cmp_status)
2073 struct coding_system *coding;
2074 const unsigned char *src;
2075 int *nbytes, *nchars, *id;
2076 struct composition_status *cmp_status;
2077 { 2054 {
2078 const unsigned char *src_end = coding->source + coding->src_bytes; 2055 const unsigned char *src_end = coding->source + coding->src_bytes;
2079 const unsigned char *src_base = src; 2056 const unsigned char *src_base = src;
2080 int multibytep = coding->src_multibyte; 2057 int multibytep = coding->src_multibyte;
2081 struct charset *charset; 2058 struct charset *charset;
2389 cmp_status->state = COMPOSING_NO; \ 2366 cmp_status->state = COMPOSING_NO; \
2390 } while (0) 2367 } while (0)
2391 2368
2392 2369
2393 static int 2370 static int
2394 emacs_mule_finish_composition (charbuf, cmp_status) 2371 emacs_mule_finish_composition (int *charbuf, struct composition_status *cmp_status)
2395 int *charbuf;
2396 struct composition_status *cmp_status;
2397 { 2372 {
2398 int idx = - cmp_status->length; 2373 int idx = - cmp_status->length;
2399 int new_chars; 2374 int new_chars;
2400 2375
2401 if (cmp_status->old_form && cmp_status->nchars > 0) 2376 if (cmp_status->old_form && cmp_status->nchars > 0)
2446 char_offset += emacs_mule_finish_composition (charbuf, cmp_status); \ 2421 char_offset += emacs_mule_finish_composition (charbuf, cmp_status); \
2447 } while (0) 2422 } while (0)
2448 2423
2449 2424
2450 static void 2425 static void
2451 decode_coding_emacs_mule (coding) 2426 decode_coding_emacs_mule (struct coding_system *coding)
2452 struct coding_system *coding;
2453 { 2427 {
2454 const unsigned char *src = coding->source + coding->consumed; 2428 const unsigned char *src = coding->source + coding->consumed;
2455 const unsigned char *src_end = coding->source + coding->src_bytes; 2429 const unsigned char *src_end = coding->source + coding->src_bytes;
2456 const unsigned char *src_base; 2430 const unsigned char *src_base;
2457 int *charbuf = coding->charbuf + coding->charbuf_used; 2431 int *charbuf = coding->charbuf + coding->charbuf_used;
2711 codes[0] = 0x9D, codes[1] = id; \ 2685 codes[0] = 0x9D, codes[1] = id; \
2712 } while (0); 2686 } while (0);
2713 2687
2714 2688
2715 static int 2689 static int
2716 encode_coding_emacs_mule (coding) 2690 encode_coding_emacs_mule (struct coding_system *coding)
2717 struct coding_system *coding;
2718 { 2691 {
2719 int multibytep = coding->dst_multibyte; 2692 int multibytep = coding->dst_multibyte;
2720 int *charbuf = coding->charbuf; 2693 int *charbuf = coding->charbuf;
2721 int *charbuf_end = charbuf + coding->charbuf_used; 2694 int *charbuf_end = charbuf + coding->charbuf_used;
2722 unsigned char *dst = coding->destination + coding->produced; 2695 unsigned char *dst = coding->destination + coding->produced;
3005 2978
3006 #define SHIFT_OUT_OK(category) \ 2979 #define SHIFT_OUT_OK(category) \
3007 (CODING_ISO_INITIAL (&coding_categories[category], 1) >= 0) 2980 (CODING_ISO_INITIAL (&coding_categories[category], 1) >= 0)
3008 2981
3009 static void 2982 static void
3010 setup_iso_safe_charsets (attrs) 2983 setup_iso_safe_charsets (Lisp_Object attrs)
3011 Lisp_Object attrs;
3012 { 2984 {
3013 Lisp_Object charset_list, safe_charsets; 2985 Lisp_Object charset_list, safe_charsets;
3014 Lisp_Object request; 2986 Lisp_Object request;
3015 Lisp_Object reg_usage; 2987 Lisp_Object reg_usage;
3016 Lisp_Object tail; 2988 Lisp_Object tail;
3074 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". 3046 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
3075 Check if a text is encoded in one of ISO-2022 based codig systems. 3047 Check if a text is encoded in one of ISO-2022 based codig systems.
3076 If it is, return 1, else return 0. */ 3048 If it is, return 1, else return 0. */
3077 3049
3078 static int 3050 static int
3079 detect_coding_iso_2022 (coding, detect_info) 3051 detect_coding_iso_2022 (struct coding_system *coding, struct coding_detection_info *detect_info)
3080 struct coding_system *coding;
3081 struct coding_detection_info *detect_info;
3082 { 3052 {
3083 const unsigned char *src = coding->source, *src_base = src; 3053 const unsigned char *src = coding->source, *src_base = src;
3084 const unsigned char *src_end = coding->source + coding->src_bytes; 3054 const unsigned char *src_end = coding->source + coding->src_bytes;
3085 int multibytep = coding->src_multibyte; 3055 int multibytep = coding->src_multibyte;
3086 int single_shifting = 0; 3056 int single_shifting = 0;
3440 } \ 3410 } \
3441 } while (0) 3411 } while (0)
3442 3412
3443 /* Finish the current composition as invalid. */ 3413 /* Finish the current composition as invalid. */
3444 3414
3445 static int finish_composition P_ ((int *, struct composition_status *)); 3415 static int finish_composition (int *, struct composition_status *);
3446 3416
3447 static int 3417 static int
3448 finish_composition (charbuf, cmp_status) 3418 finish_composition (int *charbuf, struct composition_status *cmp_status)
3449 int *charbuf;
3450 struct composition_status *cmp_status;
3451 { 3419 {
3452 int idx = - cmp_status->length; 3420 int idx = - cmp_status->length;
3453 int new_chars; 3421 int new_chars;
3454 3422
3455 /* Recover the original ESC sequence */ 3423 /* Recover the original ESC sequence */
3582 3550
3583 3551
3584 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ 3552 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */
3585 3553
3586 static void 3554 static void
3587 decode_coding_iso_2022 (coding) 3555 decode_coding_iso_2022 (struct coding_system *coding)
3588 struct coding_system *coding;
3589 { 3556 {
3590 const unsigned char *src = coding->source + coding->consumed; 3557 const unsigned char *src = coding->source + coding->consumed;
3591 const unsigned char *src_end = coding->source + coding->src_bytes; 3558 const unsigned char *src_end = coding->source + coding->src_bytes;
3592 const unsigned char *src_base; 3559 const unsigned char *src_base;
3593 int *charbuf = coding->charbuf + coding->charbuf_used; 3560 int *charbuf = coding->charbuf + coding->charbuf_used;
4329 /* Produce designation and invocation codes at a place pointed by DST 4296 /* Produce designation and invocation codes at a place pointed by DST
4330 to use CHARSET. The element `spec.iso_2022' of *CODING is updated. 4297 to use CHARSET. The element `spec.iso_2022' of *CODING is updated.
4331 Return new DST. */ 4298 Return new DST. */
4332 4299
4333 unsigned char * 4300 unsigned char *
4334 encode_invocation_designation (charset, coding, dst, p_nchars) 4301 encode_invocation_designation (struct charset *charset, struct coding_system *coding, unsigned char *dst, int *p_nchars)
4335 struct charset *charset;
4336 struct coding_system *coding;
4337 unsigned char *dst;
4338 int *p_nchars;
4339 { 4302 {
4340 int multibytep = coding->dst_multibyte; 4303 int multibytep = coding->dst_multibyte;
4341 int produced_chars = *p_nchars; 4304 int produced_chars = *p_nchars;
4342 int reg; /* graphic register number */ 4305 int reg; /* graphic register number */
4343 int id = CHARSET_ID (charset); 4306 int id = CHARSET_ID (charset);
4445 4408
4446 If the current block ends before any end-of-line, we may fail to 4409 If the current block ends before any end-of-line, we may fail to
4447 find all the necessary designations. */ 4410 find all the necessary designations. */
4448 4411
4449 static unsigned char * 4412 static unsigned char *
4450 encode_designation_at_bol (coding, charbuf, charbuf_end, dst) 4413 encode_designation_at_bol (struct coding_system *coding, int *charbuf, int *charbuf_end, unsigned char *dst)
4451 struct coding_system *coding;
4452 int *charbuf, *charbuf_end;
4453 unsigned char *dst;
4454 { 4414 {
4455 struct charset *charset; 4415 struct charset *charset;
4456 /* Table of charsets to be designated to each graphic register. */ 4416 /* Table of charsets to be designated to each graphic register. */
4457 int r[4]; 4417 int r[4];
4458 int c, found = 0, reg; 4418 int c, found = 0, reg;
4498 } 4458 }
4499 4459
4500 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */ 4460 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */
4501 4461
4502 static int 4462 static int
4503 encode_coding_iso_2022 (coding) 4463 encode_coding_iso_2022 (struct coding_system *coding)
4504 struct coding_system *coding;
4505 { 4464 {
4506 int multibytep = coding->dst_multibyte; 4465 int multibytep = coding->dst_multibyte;
4507 int *charbuf = coding->charbuf; 4466 int *charbuf = coding->charbuf;
4508 int *charbuf_end = charbuf + coding->charbuf_used; 4467 int *charbuf_end = charbuf + coding->charbuf_used;
4509 unsigned char *dst = coding->destination + coding->produced; 4468 unsigned char *dst = coding->destination + coding->produced;
4689 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". 4648 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
4690 Check if a text is encoded in SJIS. If it is, return 4649 Check if a text is encoded in SJIS. If it is, return
4691 CATEGORY_MASK_SJIS, else return 0. */ 4650 CATEGORY_MASK_SJIS, else return 0. */
4692 4651
4693 static int 4652 static int
4694 detect_coding_sjis (coding, detect_info) 4653 detect_coding_sjis (struct coding_system *coding, struct coding_detection_info *detect_info)
4695 struct coding_system *coding;
4696 struct coding_detection_info *detect_info;
4697 { 4654 {
4698 const unsigned char *src = coding->source, *src_base; 4655 const unsigned char *src = coding->source, *src_base;
4699 const unsigned char *src_end = coding->source + coding->src_bytes; 4656 const unsigned char *src_end = coding->source + coding->src_bytes;
4700 int multibytep = coding->src_multibyte; 4657 int multibytep = coding->src_multibyte;
4701 int consumed_chars = 0; 4658 int consumed_chars = 0;
4747 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". 4704 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
4748 Check if a text is encoded in BIG5. If it is, return 4705 Check if a text is encoded in BIG5. If it is, return
4749 CATEGORY_MASK_BIG5, else return 0. */ 4706 CATEGORY_MASK_BIG5, else return 0. */
4750 4707
4751 static int 4708 static int
4752 detect_coding_big5 (coding, detect_info) 4709 detect_coding_big5 (struct coding_system *coding, struct coding_detection_info *detect_info)
4753 struct coding_system *coding;
4754 struct coding_detection_info *detect_info;
4755 { 4710 {
4756 const unsigned char *src = coding->source, *src_base; 4711 const unsigned char *src = coding->source, *src_base;
4757 const unsigned char *src_end = coding->source + coding->src_bytes; 4712 const unsigned char *src_end = coding->source + coding->src_bytes;
4758 int multibytep = coding->src_multibyte; 4713 int multibytep = coding->src_multibyte;
4759 int consumed_chars = 0; 4714 int consumed_chars = 0;
4795 4750
4796 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". 4751 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions".
4797 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */ 4752 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */
4798 4753
4799 static void 4754 static void
4800 decode_coding_sjis (coding) 4755 decode_coding_sjis (struct coding_system *coding)
4801 struct coding_system *coding;
4802 { 4756 {
4803 const unsigned char *src = coding->source + coding->consumed; 4757 const unsigned char *src = coding->source + coding->consumed;
4804 const unsigned char *src_end = coding->source + coding->src_bytes; 4758 const unsigned char *src_end = coding->source + coding->src_bytes;
4805 const unsigned char *src_base; 4759 const unsigned char *src_base;
4806 int *charbuf = coding->charbuf + coding->charbuf_used; 4760 int *charbuf = coding->charbuf + coding->charbuf_used;
4914 coding->consumed = src_base - coding->source; 4868 coding->consumed = src_base - coding->source;
4915 coding->charbuf_used = charbuf - coding->charbuf; 4869 coding->charbuf_used = charbuf - coding->charbuf;
4916 } 4870 }
4917 4871
4918 static void 4872 static void
4919 decode_coding_big5 (coding) 4873 decode_coding_big5 (struct coding_system *coding)
4920 struct coding_system *coding;
4921 { 4874 {
4922 const unsigned char *src = coding->source + coding->consumed; 4875 const unsigned char *src = coding->source + coding->consumed;
4923 const unsigned char *src_end = coding->source + coding->src_bytes; 4876 const unsigned char *src_end = coding->source + coding->src_bytes;
4924 const unsigned char *src_base; 4877 const unsigned char *src_base;
4925 int *charbuf = coding->charbuf + coding->charbuf_used; 4878 int *charbuf = coding->charbuf + coding->charbuf_used;
5019 (i.e. do not have extended leading-codes). Characters of other 4972 (i.e. do not have extended leading-codes). Characters of other
5020 charsets are produced without any encoding. If SJIS_P is 1, encode 4973 charsets are produced without any encoding. If SJIS_P is 1, encode
5021 SJIS text, else encode BIG5 text. */ 4974 SJIS text, else encode BIG5 text. */
5022 4975
5023 static int 4976 static int
5024 encode_coding_sjis (coding) 4977 encode_coding_sjis (struct coding_system *coding)
5025 struct coding_system *coding;
5026 { 4978 {
5027 int multibytep = coding->dst_multibyte; 4979 int multibytep = coding->dst_multibyte;
5028 int *charbuf = coding->charbuf; 4980 int *charbuf = coding->charbuf;
5029 int *charbuf_end = charbuf + coding->charbuf_used; 4981 int *charbuf_end = charbuf + coding->charbuf_used;
5030 unsigned char *dst = coding->destination + coding->produced; 4982 unsigned char *dst = coding->destination + coding->produced;
5112 coding->produced = dst - coding->destination; 5064 coding->produced = dst - coding->destination;
5113 return 0; 5065 return 0;
5114 } 5066 }
5115 5067
5116 static int 5068 static int
5117 encode_coding_big5 (coding) 5069 encode_coding_big5 (struct coding_system *coding)
5118 struct coding_system *coding;
5119 { 5070 {
5120 int multibytep = coding->dst_multibyte; 5071 int multibytep = coding->dst_multibyte;
5121 int *charbuf = coding->charbuf; 5072 int *charbuf = coding->charbuf;
5122 int *charbuf_end = charbuf + coding->charbuf_used; 5073 int *charbuf_end = charbuf + coding->charbuf_used;
5123 unsigned char *dst = coding->destination + coding->produced; 5074 unsigned char *dst = coding->destination + coding->produced;
5191 Check if a text is encoded in a coding system of which 5142 Check if a text is encoded in a coding system of which
5192 encoder/decoder are written in CCL program. If it is, return 5143 encoder/decoder are written in CCL program. If it is, return
5193 CATEGORY_MASK_CCL, else return 0. */ 5144 CATEGORY_MASK_CCL, else return 0. */
5194 5145
5195 static int 5146 static int
5196 detect_coding_ccl (coding, detect_info) 5147 detect_coding_ccl (struct coding_system *coding, struct coding_detection_info *detect_info)
5197 struct coding_system *coding;
5198 struct coding_detection_info *detect_info;
5199 { 5148 {
5200 const unsigned char *src = coding->source, *src_base; 5149 const unsigned char *src = coding->source, *src_base;
5201 const unsigned char *src_end = coding->source + coding->src_bytes; 5150 const unsigned char *src_end = coding->source + coding->src_bytes;
5202 int multibytep = coding->src_multibyte; 5151 int multibytep = coding->src_multibyte;
5203 int consumed_chars = 0; 5152 int consumed_chars = 0;
5232 detect_info->found |= found; 5181 detect_info->found |= found;
5233 return 1; 5182 return 1;
5234 } 5183 }
5235 5184
5236 static void 5185 static void
5237 decode_coding_ccl (coding) 5186 decode_coding_ccl (struct coding_system *coding)
5238 struct coding_system *coding;
5239 { 5187 {
5240 const unsigned char *src = coding->source + coding->consumed; 5188 const unsigned char *src = coding->source + coding->consumed;
5241 const unsigned char *src_end = coding->source + coding->src_bytes; 5189 const unsigned char *src_end = coding->source + coding->src_bytes;
5242 int *charbuf = coding->charbuf + coding->charbuf_used; 5190 int *charbuf = coding->charbuf + coding->charbuf_used;
5243 int *charbuf_end = coding->charbuf + coding->charbuf_size; 5191 int *charbuf_end = coding->charbuf + coding->charbuf_size;
5302 coding->consumed = src - coding->source; 5250 coding->consumed = src - coding->source;
5303 coding->charbuf_used = charbuf - coding->charbuf; 5251 coding->charbuf_used = charbuf - coding->charbuf;
5304 } 5252 }
5305 5253
5306 static int 5254 static int
5307 encode_coding_ccl (coding) 5255 encode_coding_ccl (struct coding_system *coding)
5308 struct coding_system *coding;
5309 { 5256 {
5310 struct ccl_program *ccl = &coding->spec.ccl->ccl; 5257 struct ccl_program *ccl = &coding->spec.ccl->ccl;
5311 int multibytep = coding->dst_multibyte; 5258 int multibytep = coding->dst_multibyte;
5312 int *charbuf = coding->charbuf; 5259 int *charbuf = coding->charbuf;
5313 int *charbuf_end = charbuf + coding->charbuf_used; 5260 int *charbuf_end = charbuf + coding->charbuf_used;
5372 /*** 10, 11. no-conversion handlers ***/ 5319 /*** 10, 11. no-conversion handlers ***/
5373 5320
5374 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ 5321 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */
5375 5322
5376 static void 5323 static void
5377 decode_coding_raw_text (coding) 5324 decode_coding_raw_text (struct coding_system *coding)
5378 struct coding_system *coding;
5379 { 5325 {
5380 int eol_crlf = 5326 int eol_crlf =
5381 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 5327 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
5382 5328
5383 coding->chars_at_source = 1; 5329 coding->chars_at_source = 1;
5392 else 5338 else
5393 record_conversion_result (coding, CODING_RESULT_SUCCESS); 5339 record_conversion_result (coding, CODING_RESULT_SUCCESS);
5394 } 5340 }
5395 5341
5396 static int 5342 static int
5397 encode_coding_raw_text (coding) 5343 encode_coding_raw_text (struct coding_system *coding)
5398 struct coding_system *coding;
5399 { 5344 {
5400 int multibytep = coding->dst_multibyte; 5345 int multibytep = coding->dst_multibyte;
5401 int *charbuf = coding->charbuf; 5346 int *charbuf = coding->charbuf;
5402 int *charbuf_end = coding->charbuf + coding->charbuf_used; 5347 int *charbuf_end = coding->charbuf + coding->charbuf_used;
5403 unsigned char *dst = coding->destination + coding->produced; 5348 unsigned char *dst = coding->destination + coding->produced;
5476 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". 5421 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
5477 Check if a text is encoded in a charset-based coding system. If it 5422 Check if a text is encoded in a charset-based coding system. If it
5478 is, return 1, else return 0. */ 5423 is, return 1, else return 0. */
5479 5424
5480 static int 5425 static int
5481 detect_coding_charset (coding, detect_info) 5426 detect_coding_charset (struct coding_system *coding, struct coding_detection_info *detect_info)
5482 struct coding_system *coding;
5483 struct coding_detection_info *detect_info;
5484 { 5427 {
5485 const unsigned char *src = coding->source, *src_base; 5428 const unsigned char *src = coding->source, *src_base;
5486 const unsigned char *src_end = coding->source + coding->src_bytes; 5429 const unsigned char *src_end = coding->source + coding->src_bytes;
5487 int multibytep = coding->src_multibyte; 5430 int multibytep = coding->src_multibyte;
5488 int consumed_chars = 0; 5431 int consumed_chars = 0;
5580 detect_info->found |= found; 5523 detect_info->found |= found;
5581 return 1; 5524 return 1;
5582 } 5525 }
5583 5526
5584 static void 5527 static void
5585 decode_coding_charset (coding) 5528 decode_coding_charset (struct coding_system *coding)
5586 struct coding_system *coding;
5587 { 5529 {
5588 const unsigned char *src = coding->source + coding->consumed; 5530 const unsigned char *src = coding->source + coding->consumed;
5589 const unsigned char *src_end = coding->source + coding->src_bytes; 5531 const unsigned char *src_end = coding->source + coding->src_bytes;
5590 const unsigned char *src_base; 5532 const unsigned char *src_base;
5591 int *charbuf = coding->charbuf + coding->charbuf_used; 5533 int *charbuf = coding->charbuf + coding->charbuf_used;
5709 coding->consumed = src_base - coding->source; 5651 coding->consumed = src_base - coding->source;
5710 coding->charbuf_used = charbuf - coding->charbuf; 5652 coding->charbuf_used = charbuf - coding->charbuf;
5711 } 5653 }
5712 5654
5713 static int 5655 static int
5714 encode_coding_charset (coding) 5656 encode_coding_charset (struct coding_system *coding)
5715 struct coding_system *coding;
5716 { 5657 {
5717 int multibytep = coding->dst_multibyte; 5658 int multibytep = coding->dst_multibyte;
5718 int *charbuf = coding->charbuf; 5659 int *charbuf = coding->charbuf;
5719 int *charbuf_end = charbuf + coding->charbuf_used; 5660 int *charbuf_end = charbuf + coding->charbuf_used;
5720 unsigned char *dst = coding->destination + coding->produced; 5661 unsigned char *dst = coding->destination + coding->produced;
5780 /* Setup coding context CODING from information about CODING_SYSTEM. 5721 /* Setup coding context CODING from information about CODING_SYSTEM.
5781 If CODING_SYSTEM is nil, `no-conversion' is assumed. If 5722 If CODING_SYSTEM is nil, `no-conversion' is assumed. If
5782 CODING_SYSTEM is invalid, signal an error. */ 5723 CODING_SYSTEM is invalid, signal an error. */
5783 5724
5784 void 5725 void
5785 setup_coding_system (coding_system, coding) 5726 setup_coding_system (Lisp_Object coding_system, struct coding_system *coding)
5786 Lisp_Object coding_system;
5787 struct coding_system *coding;
5788 { 5727 {
5789 Lisp_Object attrs; 5728 Lisp_Object attrs;
5790 Lisp_Object eol_type; 5729 Lisp_Object eol_type;
5791 Lisp_Object coding_type; 5730 Lisp_Object coding_type;
5792 Lisp_Object val; 5731 Lisp_Object val;
5985 } 5924 }
5986 5925
5987 /* Return a list of charsets supported by CODING. */ 5926 /* Return a list of charsets supported by CODING. */
5988 5927
5989 Lisp_Object 5928 Lisp_Object
5990 coding_charset_list (coding) 5929 coding_charset_list (struct coding_system *coding)
5991 struct coding_system *coding;
5992 { 5930 {
5993 Lisp_Object attrs, charset_list; 5931 Lisp_Object attrs, charset_list;
5994 5932
5995 CODING_GET_INFO (coding, attrs, charset_list); 5933 CODING_GET_INFO (coding, attrs, charset_list);
5996 if (EQ (CODING_ATTR_TYPE (attrs), Qiso_2022)) 5934 if (EQ (CODING_ATTR_TYPE (attrs), Qiso_2022))
6009 5947
6010 5948
6011 /* Return a list of charsets supported by CODING-SYSTEM. */ 5949 /* Return a list of charsets supported by CODING-SYSTEM. */
6012 5950
6013 Lisp_Object 5951 Lisp_Object
6014 coding_system_charset_list (coding_system) 5952 coding_system_charset_list (Lisp_Object coding_system)
6015 Lisp_Object coding_system;
6016 { 5953 {
6017 int id; 5954 int id;
6018 Lisp_Object attrs, charset_list; 5955 Lisp_Object attrs, charset_list;
6019 5956
6020 CHECK_CODING_SYSTEM_GET_ID (coding_system, id); 5957 CHECK_CODING_SYSTEM_GET_ID (coding_system, id);
6043 5980
6044 /* Return raw-text or one of its subsidiaries that has the same 5981 /* Return raw-text or one of its subsidiaries that has the same
6045 eol_type as CODING-SYSTEM. */ 5982 eol_type as CODING-SYSTEM. */
6046 5983
6047 Lisp_Object 5984 Lisp_Object
6048 raw_text_coding_system (coding_system) 5985 raw_text_coding_system (Lisp_Object coding_system)
6049 Lisp_Object coding_system;
6050 { 5986 {
6051 Lisp_Object spec, attrs; 5987 Lisp_Object spec, attrs;
6052 Lisp_Object eol_type, raw_text_eol_type; 5988 Lisp_Object eol_type, raw_text_eol_type;
6053 5989
6054 if (NILP (coding_system)) 5990 if (NILP (coding_system))
6075 PARENT. Otherwise, return CODING_SYSTEM. If PARENT is nil, 6011 PARENT. Otherwise, return CODING_SYSTEM. If PARENT is nil,
6076 inherit end-of-line format from the system's setting 6012 inherit end-of-line format from the system's setting
6077 (system_eol_type). */ 6013 (system_eol_type). */
6078 6014
6079 Lisp_Object 6015 Lisp_Object
6080 coding_inherit_eol_type (coding_system, parent) 6016 coding_inherit_eol_type (Lisp_Object coding_system, Lisp_Object parent)
6081 Lisp_Object coding_system, parent;
6082 { 6017 {
6083 Lisp_Object spec, eol_type; 6018 Lisp_Object spec, eol_type;
6084 6019
6085 if (NILP (coding_system)) 6020 if (NILP (coding_system))
6086 coding_system = Qraw_text; 6021 coding_system = Qraw_text;
6231 Return one of EOL_SEEN_XXX. */ 6166 Return one of EOL_SEEN_XXX. */
6232 6167
6233 #define MAX_EOL_CHECK_COUNT 3 6168 #define MAX_EOL_CHECK_COUNT 3
6234 6169
6235 static int 6170 static int
6236 detect_eol (source, src_bytes, category) 6171 detect_eol (const unsigned char *source, EMACS_INT src_bytes, enum coding_category category)
6237 const unsigned char *source;
6238 EMACS_INT src_bytes;
6239 enum coding_category category;
6240 { 6172 {
6241 const unsigned char *src = source, *src_end = src + src_bytes; 6173 const unsigned char *src = source, *src_end = src + src_bytes;
6242 unsigned char c; 6174 unsigned char c;
6243 int total = 0; 6175 int total = 0;
6244 int eol_seen = EOL_SEEN_NONE; 6176 int eol_seen = EOL_SEEN_NONE;
6332 return eol_seen; 6264 return eol_seen;
6333 } 6265 }
6334 6266
6335 6267
6336 static Lisp_Object 6268 static Lisp_Object
6337 adjust_coding_eol_type (coding, eol_seen) 6269 adjust_coding_eol_type (struct coding_system *coding, int eol_seen)
6338 struct coding_system *coding;
6339 int eol_seen;
6340 { 6270 {
6341 Lisp_Object eol_type; 6271 Lisp_Object eol_type;
6342 6272
6343 eol_type = CODING_ID_EOL_TYPE (coding->id); 6273 eol_type = CODING_ID_EOL_TYPE (coding->id);
6344 if (eol_seen & EOL_SEEN_LF) 6274 if (eol_seen & EOL_SEEN_LF)
6362 /* Detect how a text specified in CODING is encoded. If a coding 6292 /* Detect how a text specified in CODING is encoded. If a coding
6363 system is detected, update fields of CODING by the detected coding 6293 system is detected, update fields of CODING by the detected coding
6364 system. */ 6294 system. */
6365 6295
6366 void 6296 void
6367 detect_coding (coding) 6297 detect_coding (struct coding_system *coding)
6368 struct coding_system *coding;
6369 { 6298 {
6370 const unsigned char *src, *src_end; 6299 const unsigned char *src, *src_end;
6371 int saved_mode = coding->mode; 6300 int saved_mode = coding->mode;
6372 6301
6373 coding->consumed = coding->consumed_char = 0; 6302 coding->consumed = coding->consumed_char = 0;
6542 coding->mode = saved_mode; 6471 coding->mode = saved_mode;
6543 } 6472 }
6544 6473
6545 6474
6546 static void 6475 static void
6547 decode_eol (coding) 6476 decode_eol (struct coding_system *coding)
6548 struct coding_system *coding;
6549 { 6477 {
6550 Lisp_Object eol_type; 6478 Lisp_Object eol_type;
6551 unsigned char *p, *pbeg, *pend; 6479 unsigned char *p, *pbeg, *pend;
6552 6480
6553 eol_type = CODING_ID_EOL_TYPE (coding->id); 6481 eol_type = CODING_ID_EOL_TYPE (coding->id);
6645 /* Return a translation table (or list of them) from coding system 6573 /* Return a translation table (or list of them) from coding system
6646 attribute vector ATTRS for encoding (ENCODEP is nonzero) or 6574 attribute vector ATTRS for encoding (ENCODEP is nonzero) or
6647 decoding (ENCODEP is zero). */ 6575 decoding (ENCODEP is zero). */
6648 6576
6649 static Lisp_Object 6577 static Lisp_Object
6650 get_translation_table (attrs, encodep, max_lookup) 6578 get_translation_table (Lisp_Object attrs, int encodep, int *max_lookup)
6651 Lisp_Object attrs;
6652 int encodep, *max_lookup;
6653 { 6579 {
6654 Lisp_Object standard, translation_table; 6580 Lisp_Object standard, translation_table;
6655 Lisp_Object val; 6581 Lisp_Object val;
6656 6582
6657 if (NILP (Venable_character_translation)) 6583 if (NILP (Venable_character_translation))
6749 The return value is TO-CHAR or ([FROM-CHAR ...] . TO) if a 6675 The return value is TO-CHAR or ([FROM-CHAR ...] . TO) if a
6750 translation is found, and Qnil if not found.. 6676 translation is found, and Qnil if not found..
6751 If BUF is too short to lookup characters in FROM, return Qt. */ 6677 If BUF is too short to lookup characters in FROM, return Qt. */
6752 6678
6753 static Lisp_Object 6679 static Lisp_Object
6754 get_translation (trans, buf, buf_end) 6680 get_translation (Lisp_Object trans, int *buf, int *buf_end)
6755 Lisp_Object trans;
6756 int *buf, *buf_end;
6757 { 6681 {
6758 6682
6759 if (INTEGERP (trans)) 6683 if (INTEGERP (trans))
6760 return trans; 6684 return trans;
6761 for (; CONSP (trans); trans = XCDR (trans)) 6685 for (; CONSP (trans); trans = XCDR (trans))
6778 return Qnil; 6702 return Qnil;
6779 } 6703 }
6780 6704
6781 6705
6782 static int 6706 static int
6783 produce_chars (coding, translation_table, last_block) 6707 produce_chars (struct coding_system *coding, Lisp_Object translation_table, int last_block)
6784 struct coding_system *coding;
6785 Lisp_Object translation_table;
6786 int last_block;
6787 { 6708 {
6788 unsigned char *dst = coding->destination + coding->produced; 6709 unsigned char *dst = coding->destination + coding->produced;
6789 unsigned char *dst_end = coding->destination + coding->dst_bytes; 6710 unsigned char *dst_end = coding->destination + coding->dst_bytes;
6790 EMACS_INT produced; 6711 EMACS_INT produced;
6791 EMACS_INT produced_chars = 0; 6712 EMACS_INT produced_chars = 0;
6979 CHARBUF. CHARBUF is an array: 6900 CHARBUF. CHARBUF is an array:
6980 [ -LENGTH ANNOTATION_MASK NCHARS NBYTES METHOD [ COMPONENTS... ] ] 6901 [ -LENGTH ANNOTATION_MASK NCHARS NBYTES METHOD [ COMPONENTS... ] ]
6981 */ 6902 */
6982 6903
6983 static INLINE void 6904 static INLINE void
6984 produce_composition (coding, charbuf, pos) 6905 produce_composition (struct coding_system *coding, int *charbuf, EMACS_INT pos)
6985 struct coding_system *coding;
6986 int *charbuf;
6987 EMACS_INT pos;
6988 { 6906 {
6989 int len; 6907 int len;
6990 EMACS_INT to; 6908 EMACS_INT to;
6991 enum composition_method method; 6909 enum composition_method method;
6992 Lisp_Object components; 6910 Lisp_Object components;
7026 the annotation data at CHARBUF. CHARBUF is an array: 6944 the annotation data at CHARBUF. CHARBUF is an array:
7027 [ -LENGTH ANNOTATION_MASK NCHARS CHARSET-ID ] 6945 [ -LENGTH ANNOTATION_MASK NCHARS CHARSET-ID ]
7028 */ 6946 */
7029 6947
7030 static INLINE void 6948 static INLINE void
7031 produce_charset (coding, charbuf, pos) 6949 produce_charset (struct coding_system *coding, int *charbuf, EMACS_INT pos)
7032 struct coding_system *coding;
7033 int *charbuf;
7034 EMACS_INT pos;
7035 { 6950 {
7036 EMACS_INT from = pos - charbuf[2]; 6951 EMACS_INT from = pos - charbuf[2];
7037 struct charset *charset = CHARSET_FROM_ID (charbuf[3]); 6952 struct charset *charset = CHARSET_FROM_ID (charbuf[3]);
7038 6953
7039 Fput_text_property (make_number (from), make_number (pos), 6954 Fput_text_property (make_number (from), make_number (pos),
7064 coding->charbuf_size = size; \ 6979 coding->charbuf_size = size; \
7065 } while (0) 6980 } while (0)
7066 6981
7067 6982
7068 static void 6983 static void
7069 produce_annotation (coding, pos) 6984 produce_annotation (struct coding_system *coding, EMACS_INT pos)
7070 struct coding_system *coding;
7071 EMACS_INT pos;
7072 { 6985 {
7073 int *charbuf = coding->charbuf; 6986 int *charbuf = coding->charbuf;
7074 int *charbuf_end = charbuf + coding->charbuf_used; 6987 int *charbuf_end = charbuf + coding->charbuf_used;
7075 6988
7076 if (NILP (coding->dst_object)) 6989 if (NILP (coding->dst_object))
7121 The decoded data is inserted at the current point of the buffer 7034 The decoded data is inserted at the current point of the buffer
7122 CODING->dst_object. 7035 CODING->dst_object.
7123 */ 7036 */
7124 7037
7125 static int 7038 static int
7126 decode_coding (coding) 7039 decode_coding (struct coding_system *coding)
7127 struct coding_system *coding;
7128 { 7040 {
7129 Lisp_Object attrs; 7041 Lisp_Object attrs;
7130 Lisp_Object undo_list; 7042 Lisp_Object undo_list;
7131 Lisp_Object translation_table; 7043 Lisp_Object translation_table;
7132 struct ccl_spec cclspec; 7044 struct ccl_spec cclspec;
7260 If such an annotation is not found, set *STOP to a starting 7172 If such an annotation is not found, set *STOP to a starting
7261 position of a composition after POS (if any) or to LIMIT, and 7173 position of a composition after POS (if any) or to LIMIT, and
7262 return BUF. */ 7174 return BUF. */
7263 7175
7264 static INLINE int * 7176 static INLINE int *
7265 handle_composition_annotation (pos, limit, coding, buf, stop) 7177 handle_composition_annotation (EMACS_INT pos, EMACS_INT limit, struct coding_system *coding, int *buf, EMACS_INT *stop)
7266 EMACS_INT pos, limit;
7267 struct coding_system *coding;
7268 int *buf;
7269 EMACS_INT *stop;
7270 { 7178 {
7271 EMACS_INT start, end; 7179 EMACS_INT start, end;
7272 Lisp_Object prop; 7180 Lisp_Object prop;
7273 7181
7274 if (! find_composition (pos, limit, &start, &end, &prop, coding->src_object) 7182 if (! find_composition (pos, limit, &start, &end, &prop, coding->src_object)
7345 7253
7346 If the property value is nil, set *STOP to the position where the 7254 If the property value is nil, set *STOP to the position where the
7347 property value is non-nil (limiting by LIMIT), and return BUF. */ 7255 property value is non-nil (limiting by LIMIT), and return BUF. */
7348 7256
7349 static INLINE int * 7257 static INLINE int *
7350 handle_charset_annotation (pos, limit, coding, buf, stop) 7258 handle_charset_annotation (EMACS_INT pos, EMACS_INT limit, struct coding_system *coding, int *buf, EMACS_INT *stop)
7351 EMACS_INT pos, limit;
7352 struct coding_system *coding;
7353 int *buf;
7354 EMACS_INT *stop;
7355 { 7259 {
7356 Lisp_Object val, next; 7260 Lisp_Object val, next;
7357 int id; 7261 int id;
7358 7262
7359 val = Fget_text_property (make_number (pos), Qcharset, coding->src_object); 7263 val = Fget_text_property (make_number (pos), Qcharset, coding->src_object);
7369 return buf; 7273 return buf;
7370 } 7274 }
7371 7275
7372 7276
7373 static void 7277 static void
7374 consume_chars (coding, translation_table, max_lookup) 7278 consume_chars (struct coding_system *coding, Lisp_Object translation_table, int max_lookup)
7375 struct coding_system *coding;
7376 Lisp_Object translation_table;
7377 int max_lookup;
7378 { 7279 {
7379 int *buf = coding->charbuf; 7280 int *buf = coding->charbuf;
7380 int *buf_end = coding->charbuf + coding->charbuf_size; 7281 int *buf_end = coding->charbuf + coding->charbuf_size;
7381 const unsigned char *src = coding->source + coding->consumed; 7282 const unsigned char *src = coding->source + coding->consumed;
7382 const unsigned char *src_end = coding->source + coding->src_bytes; 7283 const unsigned char *src_end = coding->source + coding->src_bytes;
7528 7429
7529 If CODING->dst_object is nil, the encoded data is placed at the 7430 If CODING->dst_object is nil, the encoded data is placed at the
7530 memory area specified by CODING->destination. */ 7431 memory area specified by CODING->destination. */
7531 7432
7532 static int 7433 static int
7533 encode_coding (coding) 7434 encode_coding (struct coding_system *coding)
7534 struct coding_system *coding;
7535 { 7435 {
7536 Lisp_Object attrs; 7436 Lisp_Object attrs;
7537 Lisp_Object translation_table; 7437 Lisp_Object translation_table;
7538 int max_lookup; 7438 int max_lookup;
7539 struct ccl_spec cclspec; 7439 struct ccl_spec cclspec;
7593 7493
7594 /* Return a working buffer of code convesion. MULTIBYTE specifies the 7494 /* Return a working buffer of code convesion. MULTIBYTE specifies the
7595 multibyteness of returning buffer. */ 7495 multibyteness of returning buffer. */
7596 7496
7597 static Lisp_Object 7497 static Lisp_Object
7598 make_conversion_work_buffer (multibyte) 7498 make_conversion_work_buffer (int multibyte)
7599 int multibyte;
7600 { 7499 {
7601 Lisp_Object name, workbuf; 7500 Lisp_Object name, workbuf;
7602 struct buffer *current; 7501 struct buffer *current;
7603 7502
7604 if (reused_workbuf_in_use++) 7503 if (reused_workbuf_in_use++)
7626 return workbuf; 7525 return workbuf;
7627 } 7526 }
7628 7527
7629 7528
7630 static Lisp_Object 7529 static Lisp_Object
7631 code_conversion_restore (arg) 7530 code_conversion_restore (Lisp_Object arg)
7632 Lisp_Object arg;
7633 { 7531 {
7634 Lisp_Object current, workbuf; 7532 Lisp_Object current, workbuf;
7635 struct gcpro gcpro1; 7533 struct gcpro gcpro1;
7636 7534
7637 GCPRO1 (arg); 7535 GCPRO1 (arg);
7648 UNGCPRO; 7546 UNGCPRO;
7649 return Qnil; 7547 return Qnil;
7650 } 7548 }
7651 7549
7652 Lisp_Object 7550 Lisp_Object
7653 code_conversion_save (with_work_buf, multibyte) 7551 code_conversion_save (int with_work_buf, int multibyte)
7654 int with_work_buf, multibyte;
7655 { 7552 {
7656 Lisp_Object workbuf = Qnil; 7553 Lisp_Object workbuf = Qnil;
7657 7554
7658 if (with_work_buf) 7555 if (with_work_buf)
7659 workbuf = make_conversion_work_buffer (multibyte); 7556 workbuf = make_conversion_work_buffer (multibyte);
7661 Fcons (Fcurrent_buffer (), workbuf)); 7558 Fcons (Fcurrent_buffer (), workbuf));
7662 return workbuf; 7559 return workbuf;
7663 } 7560 }
7664 7561
7665 int 7562 int
7666 decode_coding_gap (coding, chars, bytes) 7563 decode_coding_gap (struct coding_system *coding, EMACS_INT chars, EMACS_INT bytes)
7667 struct coding_system *coding;
7668 EMACS_INT chars, bytes;
7669 { 7564 {
7670 int count = specpdl_ptr - specpdl; 7565 int count = specpdl_ptr - specpdl;
7671 Lisp_Object attrs; 7566 Lisp_Object attrs;
7672 7567
7673 code_conversion_save (0, 0); 7568 code_conversion_save (0, 0);
7708 unbind_to (count, Qnil); 7603 unbind_to (count, Qnil);
7709 return coding->result; 7604 return coding->result;
7710 } 7605 }
7711 7606
7712 int 7607 int
7713 encode_coding_gap (coding, chars, bytes) 7608 encode_coding_gap (struct coding_system *coding, EMACS_INT chars, EMACS_INT bytes)
7714 struct coding_system *coding;
7715 EMACS_INT chars, bytes;
7716 { 7609 {
7717 int count = specpdl_ptr - specpdl; 7610 int count = specpdl_ptr - specpdl;
7718 7611
7719 code_conversion_save (0, 0); 7612 code_conversion_save (0, 0);
7720 7613
8163 unbind_to (count, Qnil); 8056 unbind_to (count, Qnil);
8164 } 8057 }
8165 8058
8166 8059
8167 Lisp_Object 8060 Lisp_Object
8168 preferred_coding_system () 8061 preferred_coding_system (void)
8169 { 8062 {
8170 int id = coding_categories[coding_priorities[0]].id; 8063 int id = coding_categories[coding_priorities[0]].id;
8171 8064
8172 return CODING_ID_NAME (id); 8065 return CODING_ID_NAME (id);
8173 } 8066 }
8641 Qnil); 8534 Qnil);
8642 } 8535 }
8643 8536
8644 8537
8645 static INLINE int 8538 static INLINE int
8646 char_encodable_p (c, attrs) 8539 char_encodable_p (int c, Lisp_Object attrs)
8647 int c;
8648 Lisp_Object attrs;
8649 { 8540 {
8650 Lisp_Object tail; 8541 Lisp_Object tail;
8651 struct charset *charset; 8542 struct charset *charset;
8652 Lisp_Object translation_table; 8543 Lisp_Object translation_table;
8653 8544
9029 return list; 8920 return list;
9030 } 8921 }
9031 8922
9032 8923
9033 Lisp_Object 8924 Lisp_Object
9034 code_convert_region (start, end, coding_system, dst_object, encodep, norecord) 8925 code_convert_region (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object dst_object, int encodep, int norecord)
9035 Lisp_Object start, end, coding_system, dst_object;
9036 int encodep, norecord;
9037 { 8926 {
9038 struct coding_system coding; 8927 struct coding_system coding;
9039 EMACS_INT from, from_byte, to, to_byte; 8928 EMACS_INT from, from_byte, to, to_byte;
9040 Lisp_Object src_object; 8929 Lisp_Object src_object;
9041 8930
9170 9059
9171 This function is called only from macros DECODE_FILE and 9060 This function is called only from macros DECODE_FILE and
9172 ENCODE_FILE, thus we ignore character composition. */ 9061 ENCODE_FILE, thus we ignore character composition. */
9173 9062
9174 Lisp_Object 9063 Lisp_Object
9175 code_convert_string_norecord (string, coding_system, encodep) 9064 code_convert_string_norecord (Lisp_Object string, Lisp_Object coding_system, int encodep)
9176 Lisp_Object string, coding_system;
9177 int encodep;
9178 { 9065 {
9179 return code_convert_string (string, coding_system, Qt, encodep, 0, 1); 9066 return code_convert_string (string, coding_system, Qt, encodep, 0, 1);
9180 } 9067 }
9181 9068
9182 9069
9654 } 9541 }
9655 9542
9656 static const char *const suffixes[] = { "-unix", "-dos", "-mac" }; 9543 static const char *const suffixes[] = { "-unix", "-dos", "-mac" };
9657 9544
9658 static Lisp_Object 9545 static Lisp_Object
9659 make_subsidiaries (base) 9546 make_subsidiaries (Lisp_Object base)
9660 Lisp_Object base;
9661 { 9547 {
9662 Lisp_Object subsidiaries; 9548 Lisp_Object subsidiaries;
9663 int base_name_len = SBYTES (SYMBOL_NAME (base)); 9549 int base_name_len = SBYTES (SYMBOL_NAME (base));
9664 char *buf = (char *) alloca (base_name_len + 6); 9550 char *buf = (char *) alloca (base_name_len + 6);
9665 int i; 9551 int i;
10383 10269
10384 10270
10385 /*** 9. Post-amble ***/ 10271 /*** 9. Post-amble ***/
10386 10272
10387 void 10273 void
10388 init_coding_once () 10274 init_coding_once (void)
10389 { 10275 {
10390 int i; 10276 int i;
10391 10277
10392 for (i = 0; i < coding_category_max; i++) 10278 for (i = 0; i < coding_category_max; i++)
10393 { 10279 {
10425 } 10311 }
10426 10312
10427 #ifdef emacs 10313 #ifdef emacs
10428 10314
10429 void 10315 void
10430 syms_of_coding () 10316 syms_of_coding (void)
10431 { 10317 {
10432 staticpro (&Vcoding_system_hash_table); 10318 staticpro (&Vcoding_system_hash_table);
10433 { 10319 {
10434 Lisp_Object args[2]; 10320 Lisp_Object args[2];
10435 args[0] = QCtest; 10321 args[0] = QCtest;
10975 #endif 10861 #endif
10976 staticpro (&system_eol_type); 10862 staticpro (&system_eol_type);
10977 } 10863 }
10978 10864
10979 char * 10865 char *
10980 emacs_strerror (error_number) 10866 emacs_strerror (int error_number)
10981 int error_number;
10982 { 10867 {
10983 char *str; 10868 char *str;
10984 10869
10985 synchronize_system_messages_locale (); 10870 synchronize_system_messages_locale ();
10986 str = strerror (error_number); 10871 str = strerror (error_number);