comparison src/coding.c @ 18650:aa3f2820e2ac

(Qemacs_mule, inhibit_eol_conversion): New variables. (setup_coding_system): If inhibit_eol_conversion is 0, set coding->eol_type to CODING_EOL_LF. (syms_of_coding): Initialize and staticpro Qemacs_mule. Change error-message property of coding-system-error. Declare inhibit-eol-conversion as Lisp variable. (system_eol_type): New variable. (init_coding_once): Initialize it. (ENCODE_SJIS_BIG5_CHARACTER): Bug in encoding a BIG5 character fixed.
author Kenichi Handa <handa@m17n.org>
date Mon, 07 Jul 1997 00:59:44 +0000
parents 614b916ff5bf
children 17039a6e64cf
comparison
equal deleted inserted replaced
18649:b0b06137ebfb 18650:aa3f2820e2ac
258 int eol_mnemonic_unix, eol_mnemonic_dos, eol_mnemonic_mac; 258 int eol_mnemonic_unix, eol_mnemonic_dos, eol_mnemonic_mac;
259 /* Mnemonic character to indicate format of end-of-line is not yet 259 /* Mnemonic character to indicate format of end-of-line is not yet
260 decided. */ 260 decided. */
261 int eol_mnemonic_undecided; 261 int eol_mnemonic_undecided;
262 262
263 /* Format of end-of-line decided by system. This is CODING_EOL_LF on
264 Unix, CODING_EOL_CRLF on DOS/Windows, and CODING_EOL_CR on Mac. */
265 int system_eol_type;
266
263 #ifdef emacs 267 #ifdef emacs
264 268
265 Lisp_Object Qcoding_system_spec, Qcoding_system_p, Qcoding_system_error; 269 Lisp_Object Qcoding_system_spec, Qcoding_system_p, Qcoding_system_error;
270
271 /* Coding system emacs-mule is for converting only end-of-line format. */
272 Lisp_Object Qemacs_mule;
266 273
267 /* Coding-systems are handed between Emacs Lisp programs and C internal 274 /* Coding-systems are handed between Emacs Lisp programs and C internal
268 routines by the following three variables. */ 275 routines by the following three variables. */
269 /* Coding-system for reading files and receiving data from process. */ 276 /* Coding-system for reading files and receiving data from process. */
270 Lisp_Object Vcoding_system_for_read; 277 Lisp_Object Vcoding_system_for_read;
271 /* Coding-system for writing files and sending data to process. */ 278 /* Coding-system for writing files and sending data to process. */
272 Lisp_Object Vcoding_system_for_write; 279 Lisp_Object Vcoding_system_for_write;
273 /* Coding-system actually used in the latest I/O. */ 280 /* Coding-system actually used in the latest I/O. */
274 Lisp_Object Vlast_coding_system_used; 281 Lisp_Object Vlast_coding_system_used;
282
283 /* Flag to inhibit code conversion of end-of-line format. */
284 int inhibit_eol_conversion;
275 285
276 /* Coding-system of what terminal accept for displaying. */ 286 /* Coding-system of what terminal accept for displaying. */
277 struct coding_system terminal_coding; 287 struct coding_system terminal_coding;
278 288
279 /* Coding-system of what is sent from terminal keyboard. */ 289 /* Coding-system of what is sent from terminal keyboard. */
1661 && (charset_alt == charset_big5_1 \ 1671 && (charset_alt == charset_big5_1 \
1662 || charset_alt == charset_big5_2)) \ 1672 || charset_alt == charset_big5_2)) \
1663 { \ 1673 { \
1664 unsigned char b1, b2; \ 1674 unsigned char b1, b2; \
1665 \ 1675 \
1666 ENCODE_BIG5 (c1, c2, c3, b1, b2); \ 1676 ENCODE_BIG5 (charset_alt, c1, c2, b1, b2); \
1667 *dst++ = b1, *dst++ = b2; \ 1677 *dst++ = b1, *dst++ = b2; \
1668 } \ 1678 } \
1669 else \ 1679 else \
1670 *dst++ = charset_alt, *dst++ = c1, *dst++ = c2; \ 1680 *dst++ = charset_alt, *dst++ = c1, *dst++ = c2; \
1671 } \ 1681 } \
2181 coding->post_read_conversion = Fget (coding_system, 2191 coding->post_read_conversion = Fget (coding_system,
2182 Qpost_read_conversion); 2192 Qpost_read_conversion);
2183 if (NILP (coding->pre_write_conversion)) 2193 if (NILP (coding->pre_write_conversion))
2184 coding->pre_write_conversion = Fget (coding_system, 2194 coding->pre_write_conversion = Fget (coding_system,
2185 Qpre_write_conversion); 2195 Qpre_write_conversion);
2186 if (NILP (eol_type)) 2196 if (!inhibit_eol_conversion && NILP (eol_type))
2187 eol_type = Fget (coding_system, Qeol_type); 2197 eol_type = Fget (coding_system, Qeol_type);
2188 2198
2189 if (NILP (coding->character_unification_table_for_decode)) 2199 if (NILP (coding->character_unification_table_for_decode))
2190 coding->character_unification_table_for_decode 2200 coding->character_unification_table_for_decode
2191 = Fget (coding_system, Qcharacter_unification_table_for_decode); 2201 = Fget (coding_system, Qcharacter_unification_table_for_decode);
3467 3477
3468 3478
3469 DEFUN ("find-operation-coding-system", Ffind_operation_coding_system, 3479 DEFUN ("find-operation-coding-system", Ffind_operation_coding_system,
3470 Sfind_operation_coding_system, 1, MANY, 0, 3480 Sfind_operation_coding_system, 1, MANY, 0,
3471 "Choose a coding system for an operation based on the target name.\n\ 3481 "Choose a coding system for an operation based on the target name.\n\
3472 The value names a pair of coding systems: (ENCODING-SYSTEM DECODING-SYSTEM).\n\ 3482 The value names a pair of coding systems: (DECODING-SYSTEM ENCODING-SYSTEM).\n\
3473 ENCODING-SYSTEM is the coding system to use for encoding\n\ 3483 DECODING-SYSTEM is the coding system to use for decoding\n\
3474 \(in case OPERATION does encoding), and DECODING-SYSTEM is the coding system\n\ 3484 \(in case OPERATION does decoding), and ENCODING-SYSTEM is the coding system\n\
3475 for decoding (in case OPERATION does decoding).\n\ 3485 for encoding (in case OPERATION does encoding).\n\
3476 \n\ 3486 \n\
3477 The first argument OPERATION specifies an I/O primitive:\n\ 3487 The first argument OPERATION specifies an I/O primitive:\n\
3478 For file I/O, `insert-file-contents' or `write-region'.\n\ 3488 For file I/O, `insert-file-contents' or `write-region'.\n\
3479 For process I/O, `call-process', `call-process-region', or `start-process'.\n\ 3489 For process I/O, `call-process', `call-process-region', or `start-process'.\n\
3480 For network I/O, `open-network-stream'.\n\ 3490 For network I/O, `open-network-stream'.\n\
3493 `file-coding-system-alist', `process-coding-system-alist',\n\ 3503 `file-coding-system-alist', `process-coding-system-alist',\n\
3494 or `network-coding-system-alist' depending on OPERATION.\n\ 3504 or `network-coding-system-alist' depending on OPERATION.\n\
3495 They may specify a coding system, a cons of coding systems,\n\ 3505 They may specify a coding system, a cons of coding systems,\n\
3496 or a function symbol to call.\n\ 3506 or a function symbol to call.\n\
3497 In the last case, we call the function with one argument,\n\ 3507 In the last case, we call the function with one argument,\n\
3498 which is a list of all the arguments given to `find-coding-system'.") 3508 which is a list of all the arguments given to this function.")
3499 (nargs, args) 3509 (nargs, args)
3500 int nargs; 3510 int nargs;
3501 Lisp_Object *args; 3511 Lisp_Object *args;
3502 { 3512 {
3503 Lisp_Object operation, target_idx, target, val; 3513 Lisp_Object operation, target_idx, target, val;
3599 conversion_buffer_size = MINIMUM_CONVERSION_BUFFER_SIZE; 3609 conversion_buffer_size = MINIMUM_CONVERSION_BUFFER_SIZE;
3600 conversion_buffer = (char *) xmalloc (MINIMUM_CONVERSION_BUFFER_SIZE); 3610 conversion_buffer = (char *) xmalloc (MINIMUM_CONVERSION_BUFFER_SIZE);
3601 3611
3602 setup_coding_system (Qnil, &keyboard_coding); 3612 setup_coding_system (Qnil, &keyboard_coding);
3603 setup_coding_system (Qnil, &terminal_coding); 3613 setup_coding_system (Qnil, &terminal_coding);
3614
3615 #if defined (MSDOS) || defined (WINDOWSNT)
3616 system_eol_type = CODING_EOL_CRLF;
3617 #else
3618 system_eol_type = CODING_EOL_LF;
3619 #endif
3604 } 3620 }
3605 3621
3606 #ifdef emacs 3622 #ifdef emacs
3607 3623
3608 syms_of_coding () 3624 syms_of_coding ()
3609 { 3625 {
3610 Qtarget_idx = intern ("target-idx"); 3626 Qtarget_idx = intern ("target-idx");
3611 staticpro (&Qtarget_idx); 3627 staticpro (&Qtarget_idx);
3612 3628
3629 /* Target FILENAME is the first argument. */
3613 Fput (Qinsert_file_contents, Qtarget_idx, make_number (0)); 3630 Fput (Qinsert_file_contents, Qtarget_idx, make_number (0));
3631 /* Target FILENAME is the third argument. */
3614 Fput (Qwrite_region, Qtarget_idx, make_number (2)); 3632 Fput (Qwrite_region, Qtarget_idx, make_number (2));
3615 3633
3616 Qcall_process = intern ("call-process"); 3634 Qcall_process = intern ("call-process");
3617 staticpro (&Qcall_process); 3635 staticpro (&Qcall_process);
3636 /* Target PROGRAM is the first argument. */
3618 Fput (Qcall_process, Qtarget_idx, make_number (0)); 3637 Fput (Qcall_process, Qtarget_idx, make_number (0));
3619 3638
3620 Qcall_process_region = intern ("call-process-region"); 3639 Qcall_process_region = intern ("call-process-region");
3621 staticpro (&Qcall_process_region); 3640 staticpro (&Qcall_process_region);
3641 /* Target PROGRAM is the third argument. */
3622 Fput (Qcall_process_region, Qtarget_idx, make_number (2)); 3642 Fput (Qcall_process_region, Qtarget_idx, make_number (2));
3623 3643
3624 Qstart_process = intern ("start-process"); 3644 Qstart_process = intern ("start-process");
3625 staticpro (&Qstart_process); 3645 staticpro (&Qstart_process);
3646 /* Target PROGRAM is the third argument. */
3626 Fput (Qstart_process, Qtarget_idx, make_number (2)); 3647 Fput (Qstart_process, Qtarget_idx, make_number (2));
3627 3648
3628 Qopen_network_stream = intern ("open-network-stream"); 3649 Qopen_network_stream = intern ("open-network-stream");
3629 staticpro (&Qopen_network_stream); 3650 staticpro (&Qopen_network_stream);
3651 /* Target SERVICE is the fourth argument. */
3630 Fput (Qopen_network_stream, Qtarget_idx, make_number (3)); 3652 Fput (Qopen_network_stream, Qtarget_idx, make_number (3));
3631 3653
3632 Qcoding_system = intern ("coding-system"); 3654 Qcoding_system = intern ("coding-system");
3633 staticpro (&Qcoding_system); 3655 staticpro (&Qcoding_system);
3634 3656
3654 staticpro (&Qcoding_system_error); 3676 staticpro (&Qcoding_system_error);
3655 3677
3656 Fput (Qcoding_system_error, Qerror_conditions, 3678 Fput (Qcoding_system_error, Qerror_conditions,
3657 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil))); 3679 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil)));
3658 Fput (Qcoding_system_error, Qerror_message, 3680 Fput (Qcoding_system_error, Qerror_message,
3659 build_string ("Coding-system error")); 3681 build_string ("Invalid coding system"));
3660 3682
3661 Qcoding_category_index = intern ("coding-category-index"); 3683 Qcoding_category_index = intern ("coding-category-index");
3662 staticpro (&Qcoding_category_index); 3684 staticpro (&Qcoding_category_index);
3663 3685
3664 { 3686 {
3682 staticpro (&Qcharacter_unification_table_for_decode); 3704 staticpro (&Qcharacter_unification_table_for_decode);
3683 3705
3684 Qcharacter_unification_table_for_encode 3706 Qcharacter_unification_table_for_encode
3685 = intern ("character-unification-table-for-encode"); 3707 = intern ("character-unification-table-for-encode");
3686 staticpro (&Qcharacter_unification_table_for_encode); 3708 staticpro (&Qcharacter_unification_table_for_encode);
3709
3710 Qemacs_mule = intern ("emacs-mule");
3711 staticpro (&Qemacs_mule);
3687 3712
3688 defsubr (&Scoding_system_spec); 3713 defsubr (&Scoding_system_spec);
3689 defsubr (&Scoding_system_p); 3714 defsubr (&Scoding_system_p);
3690 defsubr (&Sread_coding_system); 3715 defsubr (&Sread_coding_system);
3691 defsubr (&Sread_non_nil_coding_system); 3716 defsubr (&Sread_non_nil_coding_system);
3730 3755
3731 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, 3756 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used,
3732 "Coding-system used in the latest file or process I/O."); 3757 "Coding-system used in the latest file or process I/O.");
3733 Vlast_coding_system_used = Qnil; 3758 Vlast_coding_system_used = Qnil;
3734 3759
3760 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion,
3761 "*Non-nil inhibit code conversion of end-of-line format in any cases.");
3762 inhibit_eol_conversion = 0;
3763
3735 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, 3764 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist,
3736 "Alist to decide a coding system to use for a file I/O operation.\n\ 3765 "Alist to decide a coding system to use for a file I/O operation.\n\
3737 The format is ((PATTERN . VAL) ...),\n\ 3766 The format is ((PATTERN . VAL) ...),\n\
3738 where PATTERN is a regular expression matching a file name,\n\ 3767 where PATTERN is a regular expression matching a file name,\n\
3739 VAL is a coding system, a cons of coding systems, or a function symbol.\n\ 3768 VAL is a coding system, a cons of coding systems, or a function symbol.\n\
3742 If VAL is a cons of coding systems, the car part is used for decoding,\n\ 3771 If VAL is a cons of coding systems, the car part is used for decoding,\n\
3743 and the cdr part is used for encoding.\n\ 3772 and the cdr part is used for encoding.\n\
3744 If VAL is a function symbol, the function must return a coding system\n\ 3773 If VAL is a function symbol, the function must return a coding system\n\
3745 or a cons of coding systems which are used as above.\n\ 3774 or a cons of coding systems which are used as above.\n\
3746 \n\ 3775 \n\
3747 See also the function `find-coding-system'."); 3776 See also the function `find-operation-coding-system'.");
3748 Vfile_coding_system_alist = Qnil; 3777 Vfile_coding_system_alist = Qnil;
3749 3778
3750 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, 3779 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist,
3751 "Alist to decide a coding system to use for a process I/O operation.\n\ 3780 "Alist to decide a coding system to use for a process I/O operation.\n\
3752 The format is ((PATTERN . VAL) ...),\n\ 3781 The format is ((PATTERN . VAL) ...),\n\
3757 If VAL is a cons of coding systems, the car part is used for decoding,\n\ 3786 If VAL is a cons of coding systems, the car part is used for decoding,\n\
3758 and the cdr part is used for encoding.\n\ 3787 and the cdr part is used for encoding.\n\
3759 If VAL is a function symbol, the function must return a coding system\n\ 3788 If VAL is a function symbol, the function must return a coding system\n\
3760 or a cons of coding systems which are used as above.\n\ 3789 or a cons of coding systems which are used as above.\n\
3761 \n\ 3790 \n\
3762 See also the function `find-coding-system'."); 3791 See also the function `find-operation-coding-system'.");
3763 Vprocess_coding_system_alist = Qnil; 3792 Vprocess_coding_system_alist = Qnil;
3764 3793
3765 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, 3794 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist,
3766 "Alist to decide a coding system to use for a network I/O operation.\n\ 3795 "Alist to decide a coding system to use for a network I/O operation.\n\
3767 The format is ((PATTERN . VAL) ...),\n\ 3796 The format is ((PATTERN . VAL) ...),\n\
3773 If VAL is a cons of coding systems, the car part is used for decoding,\n\ 3802 If VAL is a cons of coding systems, the car part is used for decoding,\n\
3774 and the cdr part is used for encoding.\n\ 3803 and the cdr part is used for encoding.\n\
3775 If VAL is a function symbol, the function must return a coding system\n\ 3804 If VAL is a function symbol, the function must return a coding system\n\
3776 or a cons of coding systems which are used as above.\n\ 3805 or a cons of coding systems which are used as above.\n\
3777 \n\ 3806 \n\
3778 See also the function `find-coding-system'."); 3807 See also the function `find-operation-coding-system'.");
3779 Vnetwork_coding_system_alist = Qnil; 3808 Vnetwork_coding_system_alist = Qnil;
3780 3809
3781 DEFVAR_INT ("eol-mnemonic-unix", &eol_mnemonic_unix, 3810 DEFVAR_INT ("eol-mnemonic-unix", &eol_mnemonic_unix,
3782 "Mnemonic character indicating UNIX-like end-of-line format (i.e. LF) ."); 3811 "Mnemonic character indicating UNIX-like end-of-line format (i.e. LF) .");
3783 eol_mnemonic_unix = ':'; 3812 eol_mnemonic_unix = ':';