comparison src/coding.c @ 20680:dd46027e8412

(code_convert_region): Always count chars inserted in accord with value of enable-multilibyte-characters. (Fcoding_system_p): Doc fix. (Fcheck_coding_system): Doc fix. (Fterminal_coding_system): Doc fix. (Fkeyboard_coding_system): Doc fix.
author Richard M. Stallman <rms@gnu.org>
date Mon, 19 Jan 1998 19:45:53 +0000
parents 84032a5b04a9
children ed9ed828415e
comparison
equal deleted inserted replaced
20679:a9d566444dd4 20680:dd46027e8412
3123 #ifdef emacs 3123 #ifdef emacs
3124 /*** 7. Emacs Lisp library functions ***/ 3124 /*** 7. Emacs Lisp library functions ***/
3125 3125
3126 DEFUN ("coding-system-p", Fcoding_system_p, Scoding_system_p, 1, 1, 0, 3126 DEFUN ("coding-system-p", Fcoding_system_p, Scoding_system_p, 1, 1, 0,
3127 "Return t if OBJECT is nil or a coding-system.\n\ 3127 "Return t if OBJECT is nil or a coding-system.\n\
3128 See document of make-coding-system for coding-system object.") 3128 See the documentation of `make-coding-system' for information\n\
3129 about coding-system objects.")
3129 (obj) 3130 (obj)
3130 Lisp_Object obj; 3131 Lisp_Object obj;
3131 { 3132 {
3132 if (NILP (obj)) 3133 if (NILP (obj))
3133 return Qt; 3134 return Qt;
3171 } 3172 }
3172 3173
3173 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, 3174 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system,
3174 1, 1, 0, 3175 1, 1, 0,
3175 "Check validity of CODING-SYSTEM.\n\ 3176 "Check validity of CODING-SYSTEM.\n\
3176 If valid, return CODING-SYSTEM, else `coding-system-error' is signaled.\n\ 3177 If valid, return CODING-SYSTEM, else signal a `coding-system-error' error.\n\
3177 CODING-SYSTEM is valid if it is a symbol and has \"coding-system\" property.\n\ 3178 It is valid if it is a symbol with a non-nil `coding-system' property.\n\
3178 The value of property should be a vector of length 5.") 3179 The value of property should be a vector of length 5.")
3179 (coding_system) 3180 (coding_system)
3180 Lisp_Object coding_system; 3181 Lisp_Object coding_system;
3181 { 3182 {
3182 CHECK_SYMBOL (coding_system, 0); 3183 CHECK_SYMBOL (coding_system, 0);
3183 if (!NILP (Fcoding_system_p (coding_system))) 3184 if (!NILP (Fcoding_system_p (coding_system)))
3184 return coding_system; 3185 return coding_system;
3185 while (1) 3186 while (1)
3186 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); 3187 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil));
3187 } 3188 }
3188 3189
3189 DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region, 3190 DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region,
3190 2, 2, 0, 3191 2, 2, 0,
3191 "Detect coding system of the text in the region between START and END.\n\ 3192 "Detect coding system of the text in the region between START and END.\n\
3192 Return a list of possible coding systems ordered by priority.\n\ 3193 Return a list of possible coding systems ordered by priority.\n\
3193 If only ASCII characters are found, it returns `undecided'\n\ 3194 If only ASCII characters are found, it returns `undecided'\n\
3274 } 3275 }
3275 } 3276 }
3276 3277
3277 return val; 3278 return val;
3278 } 3279 }
3279 3280
3280 /* Scan text in the region between *BEGP and *ENDP, skip characters 3281 /* Scan text in the region between *BEGP and *ENDP, skip characters
3281 which we never have to encode to (iff ENCODEP is 1) or decode from 3282 which we never have to encode to (iff ENCODEP is 1) or decode from
3282 coding system CODING at the head and tail, then set BEGP and ENDP 3283 coding system CODING at the head and tail, then set BEGP and ENDP
3283 to the addresses of start and end of the text we actually convert. */ 3284 to the addresses of start and end of the text we actually convert. */
3284 3285
3381 } 3382 }
3382 *begp = beg_addr; 3383 *begp = beg_addr;
3383 *endp = end_addr; 3384 *endp = end_addr;
3384 return; 3385 return;
3385 } 3386 }
3386 3387
3387 /* Encode into or decode from (according to ENCODEP) coding system CODING 3388 /* Encode into or decode from (according to ENCODEP) coding system CODING
3388 the text between char positions B and E. */ 3389 the text between char positions B and E. */
3389 3390
3390 Lisp_Object 3391 Lisp_Object
3391 code_convert_region (b, e, coding, encodep) 3392 code_convert_region (b, e, coding, encodep)
3465 : decode_coding (coding, begp, buf, shrunk_len_byte, buflen, 3466 : decode_coding (coding, begp, buf, shrunk_len_byte, buflen,
3466 &consumed)); 3467 &consumed));
3467 3468
3468 TEMP_SET_PT_BOTH (shrunk_beg, shrunk_beg_byte); 3469 TEMP_SET_PT_BOTH (shrunk_beg, shrunk_beg_byte);
3469 3470
3470 if (encodep) 3471 /* We let the number of characters in the result
3471 /* If we just encoded, treat the result as single-byte. */ 3472 be computed in accord with enable-multilibyte-characters
3472 insert_1_both (buf, produced, produced, 0, 1, 0); 3473 even when encoding. Otherwise the buffer contents
3473 else 3474 will be inconsistent. */
3474 insert (buf, produced); 3475 insert (buf, produced);
3475 3476
3476 del_range_byte (PT_BYTE, PT_BYTE + shrunk_len_byte, 1); 3477 del_range_byte (PT_BYTE, PT_BYTE + shrunk_len_byte, 1);
3477 3478
3478 if (opoint >= end) 3479 if (opoint >= end)
3479 { 3480 {
3518 } 3519 }
3519 3520
3520 return make_number (len); 3521 return make_number (len);
3521 } 3522 }
3522 3523
3524 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region,
3525 3, 3, "r\nzCoding system: ",
3526 "Decode current region by specified coding system.\n\
3527 When called from a program, takes three arguments:\n\
3528 START, END, and CODING-SYSTEM. START END are buffer positions.\n\
3529 Return length of decoded text.")
3530 (b, e, coding_system)
3531 Lisp_Object b, e, coding_system;
3532 {
3533 struct coding_system coding;
3534
3535 CHECK_NUMBER_COERCE_MARKER (b, 0);
3536 CHECK_NUMBER_COERCE_MARKER (e, 1);
3537 CHECK_SYMBOL (coding_system, 2);
3538
3539 if (NILP (coding_system))
3540 return make_number (XFASTINT (e) - XFASTINT (b));
3541 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0)
3542 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data);
3543
3544 return code_convert_region (b, e, &coding, 0);
3545 }
3546
3547 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region,
3548 3, 3, "r\nzCoding system: ",
3549 "Encode current region by specified coding system.\n\
3550 When called from a program, takes three arguments:\n\
3551 START, END, and CODING-SYSTEM. START END are buffer positions.\n\
3552 Return length of encoded text.")
3553 (b, e, coding_system)
3554 Lisp_Object b, e, coding_system;
3555 {
3556 struct coding_system coding;
3557
3558 CHECK_NUMBER_COERCE_MARKER (b, 0);
3559 CHECK_NUMBER_COERCE_MARKER (e, 1);
3560 CHECK_SYMBOL (coding_system, 2);
3561
3562 if (NILP (coding_system))
3563 return make_number (XFASTINT (e) - XFASTINT (b));
3564 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0)
3565 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data);
3566
3567 return code_convert_region (b, e, &coding, 1);
3568 }
3569
3523 /* Encode or decode (according to ENCODEP) the text of string STR 3570 /* Encode or decode (according to ENCODEP) the text of string STR
3524 using coding CODING. If NOCOPY is nil, we never return STR 3571 using coding CODING. If NOCOPY is nil, we never return STR
3525 itself, but always a copy. If NOCOPY is non-nil, we return STR 3572 itself, but always a copy. If NOCOPY is non-nil, we return STR
3526 if no change is needed. */ 3573 if no change is needed. */
3527 3574
3599 3646
3600 /* When decoding, count properly the number of chars in the string. */ 3647 /* When decoding, count properly the number of chars in the string. */
3601 return make_string (buf, head_skip + produced + tail_skip); 3648 return make_string (buf, head_skip + produced + tail_skip);
3602 } 3649 }
3603 3650
3604 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region,
3605 3, 3, "r\nzCoding system: ",
3606 "Decode current region by specified coding system.\n\
3607 When called from a program, takes three arguments:\n\
3608 START, END, and CODING-SYSTEM. START END are buffer positions.\n\
3609 Return length of decoded text.")
3610 (b, e, coding_system)
3611 Lisp_Object b, e, coding_system;
3612 {
3613 struct coding_system coding;
3614
3615 CHECK_NUMBER_COERCE_MARKER (b, 0);
3616 CHECK_NUMBER_COERCE_MARKER (e, 1);
3617 CHECK_SYMBOL (coding_system, 2);
3618
3619 if (NILP (coding_system))
3620 return make_number (XFASTINT (e) - XFASTINT (b));
3621 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0)
3622 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data);
3623
3624 return code_convert_region (b, e, &coding, 0);
3625 }
3626
3627 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region,
3628 3, 3, "r\nzCoding system: ",
3629 "Encode current region by specified coding system.\n\
3630 When called from a program, takes three arguments:\n\
3631 START, END, and CODING-SYSTEM. START END are buffer positions.\n\
3632 Return length of encoded text.")
3633 (b, e, coding_system)
3634 Lisp_Object b, e, coding_system;
3635 {
3636 struct coding_system coding;
3637
3638 CHECK_NUMBER_COERCE_MARKER (b, 0);
3639 CHECK_NUMBER_COERCE_MARKER (e, 1);
3640 CHECK_SYMBOL (coding_system, 2);
3641
3642 if (NILP (coding_system))
3643 return make_number (XFASTINT (e) - XFASTINT (b));
3644 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0)
3645 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data);
3646
3647 return code_convert_region (b, e, &coding, 1);
3648 }
3649
3650 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, 3651 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string,
3651 2, 3, 0, 3652 2, 3, 0,
3652 "Decode STRING which is encoded in CODING-SYSTEM, and return the result.\n\ 3653 "Decode STRING which is encoded in CODING-SYSTEM, and return the result.\n\
3653 Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\ 3654 Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\
3654 if the decoding operation is trivial.") 3655 if the decoding operation is trivial.")
3686 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) 3687 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0)
3687 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data); 3688 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data);
3688 3689
3689 return code_convert_string (string, &coding, 1, nocopy); 3690 return code_convert_string (string, &coding, 1, nocopy);
3690 } 3691 }
3691 3692
3692 DEFUN ("decode-sjis-char", Fdecode_sjis_char, Sdecode_sjis_char, 1, 1, 0, 3693 DEFUN ("decode-sjis-char", Fdecode_sjis_char, Sdecode_sjis_char, 1, 1, 0,
3693 "Decode a JISX0208 character of shift-jis encoding.\n\ 3694 "Decode a JISX0208 character of shift-jis encoding.\n\
3694 CODE is the character code in SJIS.\n\ 3695 CODE is the character code in SJIS.\n\
3695 Return the corresponding character.") 3696 Return the corresponding character.")
3696 (code) 3697 (code)
3763 } 3764 }
3764 else 3765 else
3765 XSETFASTINT (val, 0); 3766 XSETFASTINT (val, 0);
3766 return val; 3767 return val;
3767 } 3768 }
3768 3769
3769 DEFUN ("set-terminal-coding-system-internal", 3770 DEFUN ("set-terminal-coding-system-internal",
3770 Fset_terminal_coding_system_internal, 3771 Fset_terminal_coding_system_internal,
3771 Sset_terminal_coding_system_internal, 1, 1, 0, "") 3772 Sset_terminal_coding_system_internal, 1, 1, 0, "")
3772 (coding_system) 3773 (coding_system)
3773 Lisp_Object coding_system; 3774 Lisp_Object coding_system;
3792 return Qnil; 3793 return Qnil;
3793 } 3794 }
3794 3795
3795 DEFUN ("terminal-coding-system", 3796 DEFUN ("terminal-coding-system",
3796 Fterminal_coding_system, Sterminal_coding_system, 0, 0, 0, 3797 Fterminal_coding_system, Sterminal_coding_system, 0, 0, 0,
3797 "Return coding-system of your terminal.") 3798 "Return coding system specified for terminal output.")
3798 () 3799 ()
3799 { 3800 {
3800 return terminal_coding.symbol; 3801 return terminal_coding.symbol;
3801 } 3802 }
3802 3803
3811 return Qnil; 3812 return Qnil;
3812 } 3813 }
3813 3814
3814 DEFUN ("keyboard-coding-system", 3815 DEFUN ("keyboard-coding-system",
3815 Fkeyboard_coding_system, Skeyboard_coding_system, 0, 0, 0, 3816 Fkeyboard_coding_system, Skeyboard_coding_system, 0, 0, 0,
3816 "Return coding-system of what is sent from terminal keyboard.") 3817 "Return coding system specified for decoding keyboard input.")
3817 () 3818 ()
3818 { 3819 {
3819 return keyboard_coding.symbol; 3820 return keyboard_coding.symbol;
3820 } 3821 }
3821 3822