Mercurial > emacs
comparison src/coding.c @ 18180:5f4c4da24e75
(Vcoding_system_alist): Deleted.
(Qcoding_system_spec): Renamed from Qcoding_system_vector.
(Vdefault_process_coding_system, Vfile_coding_system_alist,
Vprocess_coding_system_alist, Vnetwork_coding_system_alist): New
variables.
(Ffind_coding_system): Adjusted for the above change.
(syms_of_coding): Declare them as lisp variables.
(Fcheck_coding_system): Pass list as DATA argument to Fsignal.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Mon, 09 Jun 1997 12:59:12 +0000 |
| parents | a14261786239 |
| children | 888bfd80db2c |
comparison
equal
deleted
inserted
replaced
| 18179:371736608f2f | 18180:5f4c4da24e75 |
|---|---|
| 261 decided. */ | 261 decided. */ |
| 262 int eol_mnemonic_undecided; | 262 int eol_mnemonic_undecided; |
| 263 | 263 |
| 264 #ifdef emacs | 264 #ifdef emacs |
| 265 | 265 |
| 266 Lisp_Object Qcoding_system_vector, Qcoding_system_p, Qcoding_system_error; | 266 Lisp_Object Qcoding_system_spec, Qcoding_system_p, Qcoding_system_error; |
| 267 | 267 |
| 268 /* Coding-systems are handed between Emacs Lisp programs and C internal | 268 /* Coding-systems are handed between Emacs Lisp programs and C internal |
| 269 routines by the following three variables. */ | 269 routines by the following three variables. */ |
| 270 /* Coding-system for reading files and receiving data from process. */ | 270 /* Coding-system for reading files and receiving data from process. */ |
| 271 Lisp_Object Vcoding_system_for_read; | 271 Lisp_Object Vcoding_system_for_read; |
| 278 struct coding_system terminal_coding; | 278 struct coding_system terminal_coding; |
| 279 | 279 |
| 280 /* Coding-system of what is sent from terminal keyboard. */ | 280 /* Coding-system of what is sent from terminal keyboard. */ |
| 281 struct coding_system keyboard_coding; | 281 struct coding_system keyboard_coding; |
| 282 | 282 |
| 283 Lisp_Object Vcoding_system_alist; | 283 Lisp_Object Vfile_coding_system_alist; |
| 284 Lisp_Object Vprocess_coding_system_alist; | |
| 285 Lisp_Object Vnetwork_coding_system_alist; | |
| 284 | 286 |
| 285 #endif /* emacs */ | 287 #endif /* emacs */ |
| 286 | 288 |
| 287 Lisp_Object Qcoding_category_index; | 289 Lisp_Object Qcoding_category_index; |
| 288 | 290 |
| 314 | 316 |
| 315 Lisp_Object Qcharacter_unification_table; | 317 Lisp_Object Qcharacter_unification_table; |
| 316 | 318 |
| 317 /* Alist of charsets vs revision number. */ | 319 /* Alist of charsets vs revision number. */ |
| 318 Lisp_Object Vcharset_revision_alist; | 320 Lisp_Object Vcharset_revision_alist; |
| 321 | |
| 322 /* Default coding systems used for process I/O. */ | |
| 323 Lisp_Object Vdefault_process_coding_system; | |
| 319 | 324 |
| 320 | 325 |
| 321 /*** 2. Emacs internal format (emacs-mule) handlers ***/ | 326 /*** 2. Emacs internal format (emacs-mule) handlers ***/ |
| 322 | 327 |
| 323 /* Emacs' internal format for encoding multiple character sets is a | 328 /* Emacs' internal format for encoding multiple character sets is a |
| 2769 | 2774 |
| 2770 | 2775 |
| 2771 #ifdef emacs | 2776 #ifdef emacs |
| 2772 /*** 7. Emacs Lisp library functions ***/ | 2777 /*** 7. Emacs Lisp library functions ***/ |
| 2773 | 2778 |
| 2774 DEFUN ("coding-system-vector", Fcoding_system_vector, Scoding_system_vector, | 2779 DEFUN ("coding-system-spec", Fcoding_system_spec, Scoding_system_spec, |
| 2775 1, 1, 0, | 2780 1, 1, 0, |
| 2776 "Return coding-vector of CODING-SYSTEM.\n\ | 2781 "Return coding-spec of CODING-SYSTEM.\n\ |
| 2777 If CODING-SYSTEM is not a valid coding-system, return nil.") | 2782 If CODING-SYSTEM is not a valid coding-system, return nil.") |
| 2778 (obj) | 2783 (obj) |
| 2779 Lisp_Object obj; | 2784 Lisp_Object obj; |
| 2780 { | 2785 { |
| 2781 while (SYMBOLP (obj) && !NILP (obj)) | 2786 while (SYMBOLP (obj) && !NILP (obj)) |
| 2788 "Return t if OBJECT is nil or a coding-system.\n\ | 2793 "Return t if OBJECT is nil or a coding-system.\n\ |
| 2789 See document of make-coding-system for coding-system object.") | 2794 See document of make-coding-system for coding-system object.") |
| 2790 (obj) | 2795 (obj) |
| 2791 Lisp_Object obj; | 2796 Lisp_Object obj; |
| 2792 { | 2797 { |
| 2793 return ((NILP (obj) || !NILP (Fcoding_system_vector (obj))) ? Qt : Qnil); | 2798 return ((NILP (obj) || !NILP (Fcoding_system_spec (obj))) ? Qt : Qnil); |
| 2794 } | 2799 } |
| 2795 | 2800 |
| 2796 DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, | 2801 DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, |
| 2797 Sread_non_nil_coding_system, 1, 1, 0, | 2802 Sread_non_nil_coding_system, 1, 1, 0, |
| 2798 "Read a coding system from the minibuffer, prompting with string PROMPT.") | 2803 "Read a coding system from the minibuffer, prompting with string PROMPT.") |
| 2800 Lisp_Object prompt; | 2805 Lisp_Object prompt; |
| 2801 { | 2806 { |
| 2802 Lisp_Object val; | 2807 Lisp_Object val; |
| 2803 do | 2808 do |
| 2804 { | 2809 { |
| 2805 val = Fcompleting_read (prompt, Vobarray, Qcoding_system_vector, | 2810 val = Fcompleting_read (prompt, Vobarray, Qcoding_system_spec, |
| 2806 Qt, Qnil, Qnil, Qnil); | 2811 Qt, Qnil, Qnil, Qnil); |
| 2807 } | 2812 } |
| 2808 while (XSTRING (val)->size == 0); | 2813 while (XSTRING (val)->size == 0); |
| 2809 return (Fintern (val, Qnil)); | 2814 return (Fintern (val, Qnil)); |
| 2810 } | 2815 } |
| 2830 { | 2835 { |
| 2831 CHECK_SYMBOL (coding_system, 0); | 2836 CHECK_SYMBOL (coding_system, 0); |
| 2832 if (!NILP (Fcoding_system_p (coding_system))) | 2837 if (!NILP (Fcoding_system_p (coding_system))) |
| 2833 return coding_system; | 2838 return coding_system; |
| 2834 while (1) | 2839 while (1) |
| 2835 Fsignal (Qcoding_system_error, coding_system); | 2840 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
| 2836 } | 2841 } |
| 2837 | 2842 |
| 2838 DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region, | 2843 DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region, |
| 2839 2, 2, 0, | 2844 2, 2, 0, |
| 2840 "Detect coding-system of the text in the region between START and END.\n\ | 2845 "Detect coding-system of the text in the region between START and END.\n\ |
| 3396 TARGET has a meaning which depends on OPERATION:\n\ | 3401 TARGET has a meaning which depends on OPERATION:\n\ |
| 3397 For file I/O, TARGET is a file name.\n\ | 3402 For file I/O, TARGET is a file name.\n\ |
| 3398 For process I/O, TARGET is a process name.\n\ | 3403 For process I/O, TARGET is a process name.\n\ |
| 3399 For network I/O, TARGET is a service name or a port number\n\ | 3404 For network I/O, TARGET is a service name or a port number\n\ |
| 3400 \n\ | 3405 \n\ |
| 3401 This function looks up what `coding-system-alist' specifies for\n\ | 3406 This function looks up what specified for TARGET in,\n\ |
| 3402 OPERATION and TARGET. It may specify a cons cell which represents\n\ | 3407 `file-coding-system-alist', `process-coding-system-alist',\n\ |
| 3403 a particular coding system or it may have a function to call.\n\ | 3408 or `network-coding-system-alist' depending on OPERATION.\n\ |
| 3404 In the latter case, we call the function with one argument,\n\ | 3409 They may specify a coding system, a cons of coding systems,\n\ |
| 3410 or a function symbol to call.\n\ | |
| 3411 In the last case, we call the function with one argument,\n\ | |
| 3405 which is a list of all the arguments given to `find-coding-system'.") | 3412 which is a list of all the arguments given to `find-coding-system'.") |
| 3406 (nargs, args) | 3413 (nargs, args) |
| 3407 int nargs; | 3414 int nargs; |
| 3408 Lisp_Object *args; | 3415 Lisp_Object *args; |
| 3409 { | 3416 { |
| 3422 target = args[XINT (target_idx) + 1]; | 3429 target = args[XINT (target_idx) + 1]; |
| 3423 if (!(STRINGP (target) | 3430 if (!(STRINGP (target) |
| 3424 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) | 3431 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) |
| 3425 error ("Invalid %dth argument", XINT (target_idx) + 1); | 3432 error ("Invalid %dth argument", XINT (target_idx) + 1); |
| 3426 | 3433 |
| 3427 chain = Fassq (operation, Vcoding_system_alist); | 3434 chain = (operation == Qinsert_file_contents || operation == Qwrite_region |
| 3435 ? Vfile_coding_system_alist | |
| 3436 : (operation == Qopen_network_stream | |
| 3437 ? Vnetwork_coding_system_alist | |
| 3438 : Vprocess_coding_system_alist)); | |
| 3428 if (NILP (chain)) | 3439 if (NILP (chain)) |
| 3429 return Qnil; | 3440 return Qnil; |
| 3430 | 3441 |
| 3431 for (chain = XCONS (chain)->cdr; CONSP (chain); chain = XCONS (chain)->cdr) | 3442 for (; CONSP (chain); chain = XCONS (chain)->cdr) |
| 3432 { | 3443 { |
| 3433 Lisp_Object elt = XCONS (chain)->car; | 3444 Lisp_Object elt = XCONS (chain)->car; |
| 3434 | 3445 |
| 3435 if (CONSP (elt) | 3446 if (CONSP (elt) |
| 3436 && ((STRINGP (target) | 3447 && ((STRINGP (target) |
| 3437 && STRINGP (XCONS (elt)->car) | 3448 && STRINGP (XCONS (elt)->car) |
| 3438 && fast_string_match (XCONS (elt)->car, target) >= 0) | 3449 && fast_string_match (XCONS (elt)->car, target) >= 0) |
| 3439 || (INTEGERP (target) && EQ (target, XCONS (elt)->car)))) | 3450 || (INTEGERP (target) && EQ (target, XCONS (elt)->car)))) |
| 3440 return (val = XCONS (elt)->cdr, CONSP (val) | 3451 { |
| 3441 ? val | 3452 val = XCONS (elt)->cdr; |
| 3442 : ((SYMBOLP (val) && !NILP (Fboundp (val)) | 3453 if (CONSP (val)) |
| 3443 ? call2 (val, Flist (nargs, args)) | 3454 return val; |
| 3444 : Qnil))); | 3455 if (! SYMBOLP (val)) |
| 3456 return Qnil; | |
| 3457 if (! NILP (Fcoding_system_p (val))) | |
| 3458 return Fcons (val, val); | |
| 3459 if (!NILP (Fboundp (val))) | |
| 3460 return call2 (val, Flist (nargs, args)); | |
| 3461 return Qnil; | |
| 3462 } | |
| 3445 } | 3463 } |
| 3446 return Qnil; | 3464 return Qnil; |
| 3447 } | 3465 } |
| 3448 | 3466 |
| 3449 #endif /* emacs */ | 3467 #endif /* emacs */ |
| 3537 staticpro (&Qpost_read_conversion); | 3555 staticpro (&Qpost_read_conversion); |
| 3538 | 3556 |
| 3539 Qpre_write_conversion = intern ("pre-write-conversion"); | 3557 Qpre_write_conversion = intern ("pre-write-conversion"); |
| 3540 staticpro (&Qpre_write_conversion); | 3558 staticpro (&Qpre_write_conversion); |
| 3541 | 3559 |
| 3542 Qcoding_system_vector = intern ("coding-system-vector"); | 3560 Qcoding_system_spec = intern ("coding-system-spec"); |
| 3543 staticpro (&Qcoding_system_vector); | 3561 staticpro (&Qcoding_system_spec); |
| 3544 | 3562 |
| 3545 Qcoding_system_p = intern ("coding-system-p"); | 3563 Qcoding_system_p = intern ("coding-system-p"); |
| 3546 staticpro (&Qcoding_system_p); | 3564 staticpro (&Qcoding_system_p); |
| 3547 | 3565 |
| 3548 Qcoding_system_error = intern ("coding-system-error"); | 3566 Qcoding_system_error = intern ("coding-system-error"); |
| 3570 Qcharacter_unification_table = intern ("character-unification-table"); | 3588 Qcharacter_unification_table = intern ("character-unification-table"); |
| 3571 staticpro (&Qcharacter_unification_table); | 3589 staticpro (&Qcharacter_unification_table); |
| 3572 Fput (Qcharacter_unification_table, Qchar_table_extra_slots, | 3590 Fput (Qcharacter_unification_table, Qchar_table_extra_slots, |
| 3573 make_number (0)); | 3591 make_number (0)); |
| 3574 | 3592 |
| 3575 defsubr (&Scoding_system_vector); | 3593 defsubr (&Scoding_system_spec); |
| 3576 defsubr (&Scoding_system_p); | 3594 defsubr (&Scoding_system_p); |
| 3577 defsubr (&Sread_coding_system); | 3595 defsubr (&Sread_coding_system); |
| 3578 defsubr (&Sread_non_nil_coding_system); | 3596 defsubr (&Sread_non_nil_coding_system); |
| 3579 defsubr (&Scheck_coding_system); | 3597 defsubr (&Scheck_coding_system); |
| 3580 defsubr (&Sdetect_coding_region); | 3598 defsubr (&Sdetect_coding_region); |
| 3617 | 3635 |
| 3618 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, | 3636 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, |
| 3619 "Coding-system used in the latest file or process I/O."); | 3637 "Coding-system used in the latest file or process I/O."); |
| 3620 Vlast_coding_system_used = Qnil; | 3638 Vlast_coding_system_used = Qnil; |
| 3621 | 3639 |
| 3622 DEFVAR_LISP ("coding-system-alist", &Vcoding_system_alist, | 3640 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
| 3623 "Nested alist to decide a coding system for a specific I/O operation.\n\ | 3641 "Alist to decide a coding system to use for a file I/O operation.\n\ |
| 3624 The format is ((OPERATION . ((REGEXP . CODING-SYSTEMS) ...)) ...).\n\ | 3642 The format is ((PATTERN . VAL) ...),\n\ |
| 3643 where PATTERN is a regular expression matching a file name,\n\ | |
| 3644 VAL is a coding system, a cons of coding systems, or a function symbol.\n\ | |
| 3645 If VAL is a coding system, it is used for both decoding and encoding\n\ | |
| 3646 the file contents.\n\ | |
| 3647 If VAL is a cons of coding systems, the car part is used for decoding,\n\ | |
| 3648 and the cdr part is used for encoding.\n\ | |
| 3649 If VAL is a function symbol, the function must return a coding system\n\ | |
| 3650 or a cons of coding systems which are used as above.\n\ | |
| 3625 \n\ | 3651 \n\ |
| 3626 OPERATION is one of the following Emacs I/O primitives:\n\ | 3652 See also the function `find-coding-system'."); |
| 3627 For file I/O, insert-file-contents and write-region.\n\ | 3653 Vfile_coding_system_alist = Qnil; |
| 3628 For process I/O, call-process, call-process-region, and start-process.\n\ | 3654 |
| 3629 For network I/O, open-network-stream.\n\ | 3655 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
| 3630 In addition, for process I/O, `process-argument' can be specified for\n\ | 3656 "Alist to decide a coding system to use for a process I/O operation.\n\ |
| 3631 encoding arguments of the process.\n\ | 3657 The format is ((PATTERN . VAL) ...),\n\ |
| 3658 where PATTERN is a regular expression matching a program name,\n\ | |
| 3659 VAL is a coding system, a cons of coding systems, or a function symbol.\n\ | |
| 3660 If VAL is a coding system, it is used for both decoding what received\n\ | |
| 3661 from the program and encoding what sent to the program.\n\ | |
| 3662 If VAL is a cons of coding systems, the car part is used for decoding,\n\ | |
| 3663 and the cdr part is used for encoding.\n\ | |
| 3664 If VAL is a function symbol, the function must return a coding system\n\ | |
| 3665 or a cons of coding systems which are used as above.\n\ | |
| 3632 \n\ | 3666 \n\ |
| 3633 REGEXP is a regular expression matching a target of OPERATION, where\n\ | 3667 See also the function `find-coding-system'."); |
| 3634 target is a file name for file I/O operations, a process name for\n\ | 3668 Vprocess_coding_system_alist = Qnil; |
| 3635 process I/O operations, or a service name for network I/O\n\ | 3669 |
| 3636 operations. REGEXP might be a port number for network I/O operation.\n\ | 3670 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
| 3671 "Alist to decide a coding system to use for a network I/O operation.\n\ | |
| 3672 The format is ((PATTERN . VAL) ...),\n\ | |
| 3673 where PATTERN is a regular expression matching a network service name\n\ | |
| 3674 or is a port number to connect to,\n\ | |
| 3675 VAL is a coding system, a cons of coding systems, or a function symbol.\n\ | |
| 3676 If VAL is a coding system, it is used for both decoding what received\n\ | |
| 3677 from the network stream and encoding what sent to the network stream.\n\ | |
| 3678 If VAL is a cons of coding systems, the car part is used for decoding,\n\ | |
| 3679 and the cdr part is used for encoding.\n\ | |
| 3680 If VAL is a function symbol, the function must return a coding system\n\ | |
| 3681 or a cons of coding systems which are used as above.\n\ | |
| 3637 \n\ | 3682 \n\ |
| 3638 CODING-SYSTEMS is a cons of coding systems to encode and decode\n\ | 3683 See also the function `find-coding-system'."); |
| 3639 character code on OPERATION, or a function symbol returning the cons.\n\ | 3684 Vnetwork_coding_system_alist = Qnil; |
| 3640 See the documentation of `find-coding-system' for more detail."); | |
| 3641 Vcoding_system_alist = Qnil; | |
| 3642 | 3685 |
| 3643 DEFVAR_INT ("eol-mnemonic-unix", &eol_mnemonic_unix, | 3686 DEFVAR_INT ("eol-mnemonic-unix", &eol_mnemonic_unix, |
| 3644 "Mnemonic character indicating UNIX-like end-of-line format (i.e. LF) ."); | 3687 "Mnemonic character indicating UNIX-like end-of-line format (i.e. LF) ."); |
| 3645 eol_mnemonic_unix = '.'; | 3688 eol_mnemonic_unix = '.'; |
| 3646 | 3689 |
| 3673 DEFVAR_LISP ("charset-revision-table", &Vcharset_revision_alist, | 3716 DEFVAR_LISP ("charset-revision-table", &Vcharset_revision_alist, |
| 3674 "Alist of charsets vs revision numbers.\n\ | 3717 "Alist of charsets vs revision numbers.\n\ |
| 3675 While encoding, if a charset (car part of an element) is found,\n\ | 3718 While encoding, if a charset (car part of an element) is found,\n\ |
| 3676 designate it with the escape sequence identifing revision (cdr part of the element)."); | 3719 designate it with the escape sequence identifing revision (cdr part of the element)."); |
| 3677 Vcharset_revision_alist = Qnil; | 3720 Vcharset_revision_alist = Qnil; |
| 3721 | |
| 3722 DEFVAR_LISP ("default-process-coding-system", | |
| 3723 &Vdefault_process_coding_system, | |
| 3724 "Cons of coding systems used for process I/O by default.\n\ | |
| 3725 The car part is used for decoding a process output,\n\ | |
| 3726 the cdr part is used for encoding a text to be sent to a process."); | |
| 3727 Vdefault_process_coding_system = Qnil; | |
| 3678 } | 3728 } |
| 3679 | 3729 |
| 3680 #endif /* emacs */ | 3730 #endif /* emacs */ |
