diff options
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 86 |
1 files changed, 64 insertions, 22 deletions
diff --git a/src/coding.c b/src/coding.c index 2353834b4ad..f4e4f27f7c1 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -5484,6 +5484,31 @@ decode_eol (coding) | |||
| 5484 | } | 5484 | } |
| 5485 | } | 5485 | } |
| 5486 | 5486 | ||
| 5487 | |||
| 5488 | /* Return a translation table from coding system attribute vector ATTRS | ||
| 5489 | for encoding (ENCODEP is nonzero) or decoding (ENCODEP is zeor). */ | ||
| 5490 | |||
| 5491 | static INLINE | ||
| 5492 | get_translation_table (attrs, encodep) | ||
| 5493 | { | ||
| 5494 | Lisp_Object standard, translation_table; | ||
| 5495 | |||
| 5496 | if (encodep) | ||
| 5497 | translation_table = CODING_ATTR_ENCODE_TBL (attrs), | ||
| 5498 | standard = Vstandard_translation_table_for_encode; | ||
| 5499 | else | ||
| 5500 | translation_table = CODING_ATTR_DECODE_TBL (attrs), | ||
| 5501 | standard = Vstandard_translation_table_for_decode; | ||
| 5502 | if (! NILP (translation_table) && SYMBOLP (translation_table)) | ||
| 5503 | translation_table = Fget (translation_table, Qtranslation_table); | ||
| 5504 | if (NILP (translation_table)) | ||
| 5505 | translation_table = standard; | ||
| 5506 | if (! CHAR_TABLE_P (translation_table)) | ||
| 5507 | translation_table = Qnil; | ||
| 5508 | return translation_table; | ||
| 5509 | } | ||
| 5510 | |||
| 5511 | |||
| 5487 | static void | 5512 | static void |
| 5488 | translate_chars (coding, table) | 5513 | translate_chars (coding, table) |
| 5489 | struct coding_system *coding; | 5514 | struct coding_system *coding; |
| @@ -5500,7 +5525,7 @@ translate_chars (coding, table) | |||
| 5500 | { | 5525 | { |
| 5501 | c = *charbuf; | 5526 | c = *charbuf; |
| 5502 | if (c < 0) | 5527 | if (c < 0) |
| 5503 | charbuf += c; | 5528 | charbuf += -c; |
| 5504 | else | 5529 | else |
| 5505 | *charbuf++ = translate_char (table, c); | 5530 | *charbuf++ = translate_char (table, c); |
| 5506 | } | 5531 | } |
| @@ -5840,6 +5865,7 @@ decode_coding (coding) | |||
| 5840 | { | 5865 | { |
| 5841 | Lisp_Object attrs; | 5866 | Lisp_Object attrs; |
| 5842 | Lisp_Object undo_list; | 5867 | Lisp_Object undo_list; |
| 5868 | Lisp_Object translation_table; | ||
| 5843 | 5869 | ||
| 5844 | if (BUFFERP (coding->src_object) | 5870 | if (BUFFERP (coding->src_object) |
| 5845 | && coding->src_pos > 0 | 5871 | && coding->src_pos > 0 |
| @@ -5867,16 +5893,15 @@ decode_coding (coding) | |||
| 5867 | ALLOC_CONVERSION_WORK_AREA (coding); | 5893 | ALLOC_CONVERSION_WORK_AREA (coding); |
| 5868 | 5894 | ||
| 5869 | attrs = CODING_ID_ATTRS (coding->id); | 5895 | attrs = CODING_ID_ATTRS (coding->id); |
| 5896 | translation_table = get_translation_table (attrs, 1); | ||
| 5870 | 5897 | ||
| 5871 | do | 5898 | do |
| 5872 | { | 5899 | { |
| 5873 | coding_set_source (coding); | 5900 | coding_set_source (coding); |
| 5874 | coding->annotated = 0; | 5901 | coding->annotated = 0; |
| 5875 | (*(coding->decoder)) (coding); | 5902 | (*(coding->decoder)) (coding); |
| 5876 | if (!NILP (CODING_ATTR_DECODE_TBL (attrs))) | 5903 | if (!NILP (translation_table)) |
| 5877 | translate_chars (coding, CODING_ATTR_DECODE_TBL (attrs)); | 5904 | translate_chars (coding, translation_table); |
| 5878 | else if (!NILP (Vstandard_translation_table_for_decode)) | ||
| 5879 | translate_chars (coding, Vstandard_translation_table_for_decode); | ||
| 5880 | coding_set_destination (coding); | 5905 | coding_set_destination (coding); |
| 5881 | produce_chars (coding); | 5906 | produce_chars (coding); |
| 5882 | if (coding->annotated) | 5907 | if (coding->annotated) |
| @@ -6167,8 +6192,10 @@ encode_coding (coding) | |||
| 6167 | struct coding_system *coding; | 6192 | struct coding_system *coding; |
| 6168 | { | 6193 | { |
| 6169 | Lisp_Object attrs; | 6194 | Lisp_Object attrs; |
| 6195 | Lisp_Object translation_table; | ||
| 6170 | 6196 | ||
| 6171 | attrs = CODING_ID_ATTRS (coding->id); | 6197 | attrs = CODING_ID_ATTRS (coding->id); |
| 6198 | translation_table = get_translation_table (attrs, 1); | ||
| 6172 | 6199 | ||
| 6173 | if (BUFFERP (coding->dst_object)) | 6200 | if (BUFFERP (coding->dst_object)) |
| 6174 | { | 6201 | { |
| @@ -6188,10 +6215,8 @@ encode_coding (coding) | |||
| 6188 | coding_set_source (coding); | 6215 | coding_set_source (coding); |
| 6189 | consume_chars (coding); | 6216 | consume_chars (coding); |
| 6190 | 6217 | ||
| 6191 | if (!NILP (CODING_ATTR_ENCODE_TBL (attrs))) | 6218 | if (!NILP (translation_table)) |
| 6192 | translate_chars (coding, CODING_ATTR_ENCODE_TBL (attrs)); | 6219 | translate_chars (coding, translation_table); |
| 6193 | else if (!NILP (Vstandard_translation_table_for_encode)) | ||
| 6194 | translate_chars (coding, Vstandard_translation_table_for_encode); | ||
| 6195 | 6220 | ||
| 6196 | coding_set_destination (coding); | 6221 | coding_set_destination (coding); |
| 6197 | (*(coding->encoder)) (coding); | 6222 | (*(coding->encoder)) (coding); |
| @@ -7072,7 +7097,11 @@ char_encodable_p (c, attrs) | |||
| 7072 | { | 7097 | { |
| 7073 | Lisp_Object tail; | 7098 | Lisp_Object tail; |
| 7074 | struct charset *charset; | 7099 | struct charset *charset; |
| 7100 | Lisp_Object translation_table; | ||
| 7075 | 7101 | ||
| 7102 | translation_table = CODING_ATTR_TRANS_TBL (attrs); | ||
| 7103 | if (CHAR_TABLE_P (translation_table)) | ||
| 7104 | c = translate_char (translation_table, c); | ||
| 7076 | for (tail = CODING_ATTR_CHARSET_LIST (attrs); | 7105 | for (tail = CODING_ATTR_CHARSET_LIST (attrs); |
| 7077 | CONSP (tail); tail = XCDR (tail)) | 7106 | CONSP (tail); tail = XCDR (tail)) |
| 7078 | { | 7107 | { |
| @@ -7143,7 +7172,11 @@ DEFUN ("find-coding-systems-region-internal", | |||
| 7143 | attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | 7172 | attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); |
| 7144 | if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | 7173 | if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) |
| 7145 | && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | 7174 | && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) |
| 7146 | coding_attrs_list = Fcons (attrs, coding_attrs_list); | 7175 | { |
| 7176 | ASET (attrs, coding_attr_trans_tbl, | ||
| 7177 | get_translation_table (attrs, 1)); | ||
| 7178 | coding_attrs_list = Fcons (attrs, coding_attrs_list); | ||
| 7179 | } | ||
| 7147 | } | 7180 | } |
| 7148 | 7181 | ||
| 7149 | if (STRINGP (start)) | 7182 | if (STRINGP (start)) |
| @@ -7224,7 +7257,7 @@ to the string. */) | |||
| 7224 | { | 7257 | { |
| 7225 | int n; | 7258 | int n; |
| 7226 | struct coding_system coding; | 7259 | struct coding_system coding; |
| 7227 | Lisp_Object attrs, charset_list; | 7260 | Lisp_Object attrs, charset_list, translation_table; |
| 7228 | Lisp_Object positions; | 7261 | Lisp_Object positions; |
| 7229 | int from, to; | 7262 | int from, to; |
| 7230 | const unsigned char *p, *stop, *pend; | 7263 | const unsigned char *p, *stop, *pend; |
| @@ -7236,6 +7269,7 @@ to the string. */) | |||
| 7236 | return Qnil; | 7269 | return Qnil; |
| 7237 | ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | 7270 | ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); |
| 7238 | charset_list = CODING_ATTR_CHARSET_LIST (attrs); | 7271 | charset_list = CODING_ATTR_CHARSET_LIST (attrs); |
| 7272 | translation_table = get_translation_table (attrs, 1); | ||
| 7239 | 7273 | ||
| 7240 | if (NILP (string)) | 7274 | if (NILP (string)) |
| 7241 | { | 7275 | { |
| @@ -7297,7 +7331,8 @@ to the string. */) | |||
| 7297 | 7331 | ||
| 7298 | c = STRING_CHAR_ADVANCE (p); | 7332 | c = STRING_CHAR_ADVANCE (p); |
| 7299 | if (! (ASCII_CHAR_P (c) && ascii_compatible) | 7333 | if (! (ASCII_CHAR_P (c) && ascii_compatible) |
| 7300 | && ! char_charset (c, charset_list, NULL)) | 7334 | && ! char_charset (translate_char (translation_table, c), |
| 7335 | charset_list, NULL)) | ||
| 7301 | { | 7336 | { |
| 7302 | positions = Fcons (make_number (from), positions); | 7337 | positions = Fcons (make_number (from), positions); |
| 7303 | n--; | 7338 | n--; |
| @@ -7338,7 +7373,7 @@ buffer positions. END is ignored. */) | |||
| 7338 | int pos; | 7373 | int pos; |
| 7339 | const unsigned char *p, *pbeg, *pend; | 7374 | const unsigned char *p, *pbeg, *pend; |
| 7340 | int c; | 7375 | int c; |
| 7341 | Lisp_Object tail, elt; | 7376 | Lisp_Object tail, elt, attrs; |
| 7342 | 7377 | ||
| 7343 | if (STRINGP (start)) | 7378 | if (STRINGP (start)) |
| 7344 | { | 7379 | { |
| @@ -7376,9 +7411,9 @@ buffer positions. END is ignored. */) | |||
| 7376 | for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) | 7411 | for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) |
| 7377 | { | 7412 | { |
| 7378 | elt = XCAR (tail); | 7413 | elt = XCAR (tail); |
| 7379 | list = Fcons (Fcons (elt, Fcons (AREF (CODING_SYSTEM_SPEC (elt), 0), | 7414 | attrs = AREF (CODING_SYSTEM_SPEC (elt), 0); |
| 7380 | Qnil)), | 7415 | ASET (attrs, coding_attr_trans_tbl, get_translation_table (attrs, 1)); |
| 7381 | list); | 7416 | list = Fcons (Fcons (elt, Fcons (attrs, Qnil)), list); |
| 7382 | } | 7417 | } |
| 7383 | 7418 | ||
| 7384 | if (STRINGP (start)) | 7419 | if (STRINGP (start)) |
| @@ -8133,13 +8168,13 @@ usage: (define-coding-system-internal ...) */) | |||
| 8133 | CODING_ATTR_ASCII_COMPAT (attrs) = args[coding_arg_ascii_compatible_p]; | 8168 | CODING_ATTR_ASCII_COMPAT (attrs) = args[coding_arg_ascii_compatible_p]; |
| 8134 | 8169 | ||
| 8135 | val = args[coding_arg_decode_translation_table]; | 8170 | val = args[coding_arg_decode_translation_table]; |
| 8136 | if (! NILP (val)) | 8171 | if (! CHAR_TABLE_P (val)) |
| 8137 | CHECK_CHAR_TABLE (val); | 8172 | CHECK_SYMBOL (val); |
| 8138 | CODING_ATTR_DECODE_TBL (attrs) = val; | 8173 | CODING_ATTR_DECODE_TBL (attrs) = val; |
| 8139 | 8174 | ||
| 8140 | val = args[coding_arg_encode_translation_table]; | 8175 | val = args[coding_arg_encode_translation_table]; |
| 8141 | if (! NILP (val)) | 8176 | if (! CHAR_TABLE_P (val)) |
| 8142 | CHECK_CHAR_TABLE (val); | 8177 | CHECK_SYMBOL (val); |
| 8143 | CODING_ATTR_ENCODE_TBL (attrs) = val; | 8178 | CODING_ATTR_ENCODE_TBL (attrs) = val; |
| 8144 | 8179 | ||
| 8145 | val = args[coding_arg_post_read_conversion]; | 8180 | val = args[coding_arg_post_read_conversion]; |
| @@ -8415,8 +8450,9 @@ usage: (define-coding-system-internal ...) */) | |||
| 8415 | 8450 | ||
| 8416 | struct charset *charset; | 8451 | struct charset *charset; |
| 8417 | 8452 | ||
| 8418 | if (XINT (Flength (charset_list)) != 3) | 8453 | if (XINT (Flength (charset_list)) != 3 |
| 8419 | error ("There should be just three charsets"); | 8454 | || XINT (Flength (charset_list)) != 4) |
| 8455 | error ("There should be three or four charsets"); | ||
| 8420 | 8456 | ||
| 8421 | charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | 8457 | charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); |
| 8422 | if (CHARSET_DIMENSION (charset) != 1) | 8458 | if (CHARSET_DIMENSION (charset) != 1) |
| @@ -8437,6 +8473,12 @@ usage: (define-coding-system-internal ...) */) | |||
| 8437 | error ("Dimension of charset %s is not two", | 8473 | error ("Dimension of charset %s is not two", |
| 8438 | SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); | 8474 | SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); |
| 8439 | 8475 | ||
| 8476 | charset_list = XCDR (charset_list); | ||
| 8477 | charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | ||
| 8478 | if (CHARSET_DIMENSION (charset) != 2) | ||
| 8479 | error ("Dimension of charset %s is not two", | ||
| 8480 | SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); | ||
| 8481 | |||
| 8440 | category = coding_category_sjis; | 8482 | category = coding_category_sjis; |
| 8441 | Vsjis_coding_system = name; | 8483 | Vsjis_coding_system = name; |
| 8442 | } | 8484 | } |