Mercurial > emacs
comparison src/coding.c @ 89759:d11866e9fbf4
(QCmnemonic, QCdefalut_char)
(QCdecode_translation_table, QCencode_translation_table)
(QCpost_read_conversion, QCpre_write_conversion): New variables.
(get_translation_table): Return a list of translation tables if
necessary.
(decode_coding): Call get_translation_table with ENCODEP 0.
(char_encodable_p): If translation_table is non-nil, always call
translate_char.
(Fdefine_coding_system_internal): Accept list of translation
tables as :encode-translation-table and :decode-translation-table.
(Fcoding_system_put): New function.
(syms_of_coding): Declare new symbols. Defsubr
Scoding_system_put.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 27 Jan 2004 02:21:37 +0000 |
parents | 78c1fd14ed42 |
children | e3d26232ab78 |
comparison
equal
deleted
inserted
replaced
89758:b07ce3d8fc4e | 89759:d11866e9fbf4 |
---|---|
309 Lisp_Object Qno_conversion, Qundecided; | 309 Lisp_Object Qno_conversion, Qundecided; |
310 Lisp_Object Qcharset, Qiso_2022, Qutf_8, Qutf_16, Qshift_jis, Qbig5; | 310 Lisp_Object Qcharset, Qiso_2022, Qutf_8, Qutf_16, Qshift_jis, Qbig5; |
311 Lisp_Object Qbig, Qlittle; | 311 Lisp_Object Qbig, Qlittle; |
312 Lisp_Object Qcoding_system_history; | 312 Lisp_Object Qcoding_system_history; |
313 Lisp_Object Qvalid_codes; | 313 Lisp_Object Qvalid_codes; |
314 Lisp_Object QCcategory; | 314 Lisp_Object QCcategory, QCmnemonic, QCdefalut_char; |
315 Lisp_Object QCdecode_translation_table, QCencode_translation_table; | |
316 Lisp_Object QCpost_read_conversion, QCpre_write_conversion; | |
315 | 317 |
316 extern Lisp_Object Qinsert_file_contents, Qwrite_region; | 318 extern Lisp_Object Qinsert_file_contents, Qwrite_region; |
317 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; | 319 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; |
318 Lisp_Object Qstart_process, Qopen_network_stream; | 320 Lisp_Object Qstart_process, Qopen_network_stream; |
319 Lisp_Object Qtarget_idx; | 321 Lisp_Object Qtarget_idx; |
5482 coding->produced_char -= n; | 5484 coding->produced_char -= n; |
5483 } | 5485 } |
5484 } | 5486 } |
5485 | 5487 |
5486 | 5488 |
5487 /* Return a translation table from coding system attribute vector ATTRS | 5489 /* Return a translation table (or list of them) from coding system |
5488 for encoding (ENCODEP is nonzero) or decoding (ENCODEP is zeor). */ | 5490 attribute vector ATTRS for encoding (ENCODEP is nonzero) or |
5491 decoding (ENCODEP is zero). */ | |
5489 | 5492 |
5490 static INLINE | 5493 static INLINE |
5491 get_translation_table (attrs, encodep) | 5494 get_translation_table (attrs, encodep) |
5492 { | 5495 { |
5493 Lisp_Object standard, translation_table; | 5496 Lisp_Object standard, translation_table; |
5496 translation_table = CODING_ATTR_ENCODE_TBL (attrs), | 5499 translation_table = CODING_ATTR_ENCODE_TBL (attrs), |
5497 standard = Vstandard_translation_table_for_encode; | 5500 standard = Vstandard_translation_table_for_encode; |
5498 else | 5501 else |
5499 translation_table = CODING_ATTR_DECODE_TBL (attrs), | 5502 translation_table = CODING_ATTR_DECODE_TBL (attrs), |
5500 standard = Vstandard_translation_table_for_decode; | 5503 standard = Vstandard_translation_table_for_decode; |
5501 if (! NILP (translation_table) && SYMBOLP (translation_table)) | 5504 if (NILP (translation_table)) |
5505 return standard; | |
5506 if (SYMBOLP (translation_table)) | |
5502 translation_table = Fget (translation_table, Qtranslation_table); | 5507 translation_table = Fget (translation_table, Qtranslation_table); |
5503 if (NILP (translation_table)) | 5508 else if (CONSP (translation_table)) |
5504 translation_table = standard; | 5509 { |
5505 if (! CHAR_TABLE_P (translation_table)) | 5510 Lisp_Object val; |
5506 translation_table = Qnil; | 5511 |
5512 translation_table = Fcopy_sequence (translation_table); | |
5513 for (val = translation_table; CONSP (val); val = XCDR (val)) | |
5514 if (SYMBOLP (XCAR (val))) | |
5515 XSETCAR (val, Fget (XCAR (val), Qtranslation_table)); | |
5516 } | |
5517 if (! NILP (standard)) | |
5518 { | |
5519 if (CONSP (translation_table)) | |
5520 translation_table = nconc2 (translation_table, Fcons (standard, Qnil)); | |
5521 else | |
5522 translation_table = Fcons (translation_table, Fcons (standard, Qnil)); | |
5523 } | |
5507 return translation_table; | 5524 return translation_table; |
5508 } | 5525 } |
5509 | 5526 |
5510 | 5527 |
5511 static void | 5528 static void |
5890 coding->errors = 0; | 5907 coding->errors = 0; |
5891 | 5908 |
5892 ALLOC_CONVERSION_WORK_AREA (coding); | 5909 ALLOC_CONVERSION_WORK_AREA (coding); |
5893 | 5910 |
5894 attrs = CODING_ID_ATTRS (coding->id); | 5911 attrs = CODING_ID_ATTRS (coding->id); |
5895 translation_table = get_translation_table (attrs, 1); | 5912 translation_table = get_translation_table (attrs, 0); |
5896 | 5913 |
5897 do | 5914 do |
5898 { | 5915 { |
5899 coding_set_source (coding); | 5916 coding_set_source (coding); |
5900 coding->annotated = 0; | 5917 coding->annotated = 0; |
7097 Lisp_Object tail; | 7114 Lisp_Object tail; |
7098 struct charset *charset; | 7115 struct charset *charset; |
7099 Lisp_Object translation_table; | 7116 Lisp_Object translation_table; |
7100 | 7117 |
7101 translation_table = CODING_ATTR_TRANS_TBL (attrs); | 7118 translation_table = CODING_ATTR_TRANS_TBL (attrs); |
7102 if (CHAR_TABLE_P (translation_table)) | 7119 if (! NILP (translation_table)) |
7103 c = translate_char (translation_table, c); | 7120 c = translate_char (translation_table, c); |
7104 for (tail = CODING_ATTR_CHARSET_LIST (attrs); | 7121 for (tail = CODING_ATTR_CHARSET_LIST (attrs); |
7105 CONSP (tail); tail = XCDR (tail)) | 7122 CONSP (tail); tail = XCDR (tail)) |
7106 { | 7123 { |
7107 charset = CHARSET_FROM_ID (XINT (XCAR (tail))); | 7124 charset = CHARSET_FROM_ID (XINT (XCAR (tail))); |
8164 CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; | 8181 CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; |
8165 | 8182 |
8166 CODING_ATTR_ASCII_COMPAT (attrs) = args[coding_arg_ascii_compatible_p]; | 8183 CODING_ATTR_ASCII_COMPAT (attrs) = args[coding_arg_ascii_compatible_p]; |
8167 | 8184 |
8168 val = args[coding_arg_decode_translation_table]; | 8185 val = args[coding_arg_decode_translation_table]; |
8169 if (! CHAR_TABLE_P (val)) | 8186 if (! CHAR_TABLE_P (val) && ! CONSP (val)) |
8170 CHECK_SYMBOL (val); | 8187 CHECK_SYMBOL (val); |
8171 CODING_ATTR_DECODE_TBL (attrs) = val; | 8188 CODING_ATTR_DECODE_TBL (attrs) = val; |
8172 | 8189 |
8173 val = args[coding_arg_encode_translation_table]; | 8190 val = args[coding_arg_encode_translation_table]; |
8174 if (! CHAR_TABLE_P (val)) | 8191 if (! CHAR_TABLE_P (val) && ! CONSP (val)) |
8175 CHECK_SYMBOL (val); | 8192 CHECK_SYMBOL (val); |
8176 CODING_ATTR_ENCODE_TBL (attrs) = val; | 8193 CODING_ATTR_ENCODE_TBL (attrs) = val; |
8177 | 8194 |
8178 val = args[coding_arg_post_read_conversion]; | 8195 val = args[coding_arg_post_read_conversion]; |
8179 CHECK_SYMBOL (val); | 8196 CHECK_SYMBOL (val); |
8579 Fcons (intern ("define-coding-system-internal"), | 8596 Fcons (intern ("define-coding-system-internal"), |
8580 make_number (nargs))); | 8597 make_number (nargs))); |
8581 } | 8598 } |
8582 | 8599 |
8583 | 8600 |
8601 DEFUN ("coding-system-put", Fcoding_system_put, Scoding_system_put, | |
8602 3, 3, 0, | |
8603 doc: /* Change value in CODING-SYSTEM's property list PROP to VAL. */) | |
8604 (coding_system, prop, val) | |
8605 Lisp_Object coding_system, prop, val; | |
8606 { | |
8607 Lisp_Object spec, attrs, plist; | |
8608 | |
8609 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
8610 attrs = AREF (spec, 0); | |
8611 if (EQ (prop, QCmnemonic)) | |
8612 { | |
8613 if (! STRINGP (val)) | |
8614 CHECK_CHARACTER (val); | |
8615 CODING_ATTR_MNEMONIC (attrs) = val; | |
8616 } | |
8617 else if (EQ (prop, QCdefalut_char)) | |
8618 { | |
8619 if (NILP (val)) | |
8620 val = make_number (' '); | |
8621 else | |
8622 CHECK_CHARACTER (val); | |
8623 CODING_ATTR_DEFAULT_CHAR (attrs) = val; | |
8624 } | |
8625 else if (EQ (prop, QCdecode_translation_table)) | |
8626 { | |
8627 if (! CHAR_TABLE_P (val) && ! CONSP (val)) | |
8628 CHECK_SYMBOL (val); | |
8629 CODING_ATTR_DECODE_TBL (attrs) = val; | |
8630 } | |
8631 else if (EQ (prop, QCencode_translation_table)) | |
8632 { | |
8633 if (! CHAR_TABLE_P (val) && ! CONSP (val)) | |
8634 CHECK_SYMBOL (val); | |
8635 CODING_ATTR_ENCODE_TBL (attrs) = val; | |
8636 } | |
8637 else if (EQ (prop, QCpost_read_conversion)) | |
8638 { | |
8639 CHECK_SYMBOL (val); | |
8640 CODING_ATTR_POST_READ (attrs) = val; | |
8641 } | |
8642 else if (EQ (prop, QCpre_write_conversion)) | |
8643 { | |
8644 CHECK_SYMBOL (val); | |
8645 CODING_ATTR_PRE_WRITE (attrs) = val; | |
8646 } | |
8647 | |
8648 CODING_ATTR_PLIST (attrs) | |
8649 = Fplist_put (CODING_ATTR_PLIST (attrs), prop, val); | |
8650 return val; | |
8651 } | |
8652 | |
8653 | |
8584 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, | 8654 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, |
8585 Sdefine_coding_system_alias, 2, 2, 0, | 8655 Sdefine_coding_system_alias, 2, 2, 0, |
8586 doc: /* Define ALIAS as an alias for CODING-SYSTEM. */) | 8656 doc: /* Define ALIAS as an alias for CODING-SYSTEM. */) |
8587 (alias, coding_system) | 8657 (alias, coding_system) |
8588 Lisp_Object alias, coding_system; | 8658 Lisp_Object alias, coding_system; |
8841 DEFSYM (Qvalid_codes, "valid-codes"); | 8911 DEFSYM (Qvalid_codes, "valid-codes"); |
8842 | 8912 |
8843 DEFSYM (Qemacs_mule, "emacs-mule"); | 8913 DEFSYM (Qemacs_mule, "emacs-mule"); |
8844 | 8914 |
8845 DEFSYM (QCcategory, ":category"); | 8915 DEFSYM (QCcategory, ":category"); |
8916 DEFSYM (QCmnemonic, ":mnemonic"); | |
8917 DEFSYM (QCdefalut_char, ":default-char"); | |
8918 DEFSYM (QCdecode_translation_table, ":decode-translation-table"); | |
8919 DEFSYM (QCencode_translation_table, ":encode-translation-table"); | |
8920 DEFSYM (QCpost_read_conversion, ":post-read-conversion"); | |
8921 DEFSYM (QCpre_write_conversion, ":pre-write-conversion"); | |
8846 | 8922 |
8847 Vcoding_category_table | 8923 Vcoding_category_table |
8848 = Fmake_vector (make_number (coding_category_max), Qnil); | 8924 = Fmake_vector (make_number (coding_category_max), Qnil); |
8849 staticpro (&Vcoding_category_table); | 8925 staticpro (&Vcoding_category_table); |
8850 /* Followings are target of code detection. */ | 8926 /* Followings are target of code detection. */ |
8918 defsubr (&Skeyboard_coding_system); | 8994 defsubr (&Skeyboard_coding_system); |
8919 defsubr (&Sfind_operation_coding_system); | 8995 defsubr (&Sfind_operation_coding_system); |
8920 defsubr (&Sset_coding_system_priority); | 8996 defsubr (&Sset_coding_system_priority); |
8921 defsubr (&Sdefine_coding_system_internal); | 8997 defsubr (&Sdefine_coding_system_internal); |
8922 defsubr (&Sdefine_coding_system_alias); | 8998 defsubr (&Sdefine_coding_system_alias); |
8999 defsubr (&Scoding_system_put); | |
8923 defsubr (&Scoding_system_base); | 9000 defsubr (&Scoding_system_base); |
8924 defsubr (&Scoding_system_plist); | 9001 defsubr (&Scoding_system_plist); |
8925 defsubr (&Scoding_system_aliases); | 9002 defsubr (&Scoding_system_aliases); |
8926 defsubr (&Scoding_system_eol_type); | 9003 defsubr (&Scoding_system_eol_type); |
8927 defsubr (&Scoding_system_priority_list); | 9004 defsubr (&Scoding_system_priority_list); |