comparison src/term.c @ 83127:5182815e0ee1

Make terminal_coding and keyboard_coding display-local. src/coding.c: Include frame.h and termhooks.h. (terminal_coding, keyboard_coding): Remove. (Fset_terminal_coding_system_internal, Fterminal_coding_system): Use the selected frame's terminal coding system. (Fset_safe_terminal_coding_system_internal): Fix typo. (Fset_keyboard_coding_system_internal, Fkeyboard_coding_system): Use the selected frame's keyboard coding system. (init_coding_once): Don't initialize keyboard_coding and terminal_coding. src/coding.h (terminal_coding, keyboard_coding): Remove. src/termhooks.h (terminal_coding, keyboard_coding): New members of struct display. (FRAME_TERMINAL_CODING, FRAME_KEYBOARD_CODING): New macros. src/termchar.h (kboard): Cosmetic change. src/term.c (encode_terminal_code): Add coding parameter. (tty_write_glyphs): Use the display-local terminal coding system. (create_display): Allocate and initialize coding systems. (delete_display): Free coding systems. src/xdisp.c (decode_mode_spec): Use display-local coding systems. src/Makefile.in: Fix dependencies for termchar.h and termhooks.h. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-167
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 23 May 2004 01:53:23 +0000
parents a330cf2446ad
children 9b7814160efe
comparison
equal deleted inserted replaced
83126:14e5707213a6 83127:5182815e0ee1
617 617
618 We store the number of glyphs actually converted in *CONSUMED. The 618 We store the number of glyphs actually converted in *CONSUMED. The
619 return value is the number of bytes store in DST. */ 619 return value is the number of bytes store in DST. */
620 620
621 int 621 int
622 encode_terminal_code (src, dst, src_len, dst_len, consumed) 622 encode_terminal_code (coding, src, dst, src_len, dst_len, consumed)
623 struct coding_system *coding;
623 struct glyph *src; 624 struct glyph *src;
624 int src_len; 625 int src_len;
625 unsigned char *dst; 626 unsigned char *dst;
626 int dst_len, *consumed; 627 int dst_len, *consumed;
627 { 628 {
632 const unsigned char *buf; 633 const unsigned char *buf;
633 int len; 634 int len;
634 register int tlen = GLYPH_TABLE_LENGTH; 635 register int tlen = GLYPH_TABLE_LENGTH;
635 register Lisp_Object *tbase = GLYPH_TABLE_BASE; 636 register Lisp_Object *tbase = GLYPH_TABLE_BASE;
636 int result; 637 int result;
637 struct coding_system *coding; 638
638 639 /* If the specified coding does any conversion, use it, otherwise use
639 /* If terminal_coding does any conversion, use it, otherwise use
640 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here 640 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
641 because it always return 1 if the member src_multibyte is 1. */ 641 because it always returns 1 if the member src_multibyte is 1. */
642 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK 642 coding = (coding->common_flags & CODING_REQUIRE_ENCODING_MASK
643 ? &terminal_coding 643 ? coding
644 : &safe_terminal_coding); 644 : &safe_terminal_coding);
645 645
646 while (src < src_end) 646 while (src < src_end)
647 { 647 {
648 /* We must skip glyphs to be padded for a wide character. */ 648 /* We must skip glyphs to be padded for a wide character. */
755 755
756 cmplus (tty, len); 756 cmplus (tty, len);
757 757
758 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at 758 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
759 the tail. */ 759 the tail. */
760 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK; 760 FRAME_TERMINAL_CODING (f)->mode &= ~CODING_MODE_LAST_BLOCK;
761 761
762 while (len > 0) 762 while (len > 0)
763 { 763 {
764 /* Identify a run of glyphs with the same face. */ 764 /* Identify a run of glyphs with the same face. */
765 int face_id = string->face_id; 765 int face_id = string->face_id;
776 while (n > 0) 776 while (n > 0)
777 { 777 {
778 /* We use a fixed size (1024 bytes) of conversion buffer. 778 /* We use a fixed size (1024 bytes) of conversion buffer.
779 Usually it is sufficient, but if not, we just repeat the 779 Usually it is sufficient, but if not, we just repeat the
780 loop. */ 780 loop. */
781 produced = encode_terminal_code (string, conversion_buffer, 781 produced = encode_terminal_code (FRAME_TERMINAL_CODING (f),
782 string, conversion_buffer,
782 n, conversion_buffer_size, 783 n, conversion_buffer_size,
783 &consumed); 784 &consumed);
784 if (produced > 0) 785 if (produced > 0)
785 { 786 {
786 fwrite (conversion_buffer, 1, produced, 787 fwrite (conversion_buffer, 1, produced,
800 turn_off_face (f, face_id); 801 turn_off_face (f, face_id);
801 turn_off_highlight (tty); 802 turn_off_highlight (tty);
802 } 803 }
803 804
804 /* We may have to output some codes to terminate the writing. */ 805 /* We may have to output some codes to terminate the writing. */
805 if (CODING_REQUIRE_FLUSHING (&terminal_coding)) 806 if (CODING_REQUIRE_FLUSHING (FRAME_TERMINAL_CODING (f)))
806 { 807 {
807 terminal_coding.mode |= CODING_MODE_LAST_BLOCK; 808 FRAME_TERMINAL_CODING (f)->mode |= CODING_MODE_LAST_BLOCK;
808 encode_coding (&terminal_coding, "", conversion_buffer, 809 encode_coding (FRAME_TERMINAL_CODING (f), "",
809 0, conversion_buffer_size); 810 conversion_buffer, 0, conversion_buffer_size);
810 if (terminal_coding.produced > 0) 811 if (FRAME_TERMINAL_CODING (f)->produced > 0)
811 { 812 {
812 fwrite (conversion_buffer, 1, terminal_coding.produced, 813 fwrite (conversion_buffer, 1,
814 FRAME_TERMINAL_CODING (f)->produced,
813 tty->output); 815 tty->output);
814 if (ferror (tty->output)) 816 if (ferror (tty->output))
815 clearerr (tty->output); 817 clearerr (tty->output);
816 if (tty->termscript) 818 if (tty->termscript)
817 fwrite (conversion_buffer, 1, terminal_coding.produced, 819 fwrite (conversion_buffer, 1,
820 FRAME_TERMINAL_CODING (f)->produced,
818 tty->termscript); 821 tty->termscript);
819 } 822 }
820 } 823 }
821 824
822 cmcheckmagic (tty); 825 cmcheckmagic (tty);
857 } 860 }
858 861
859 turn_on_insert (tty); 862 turn_on_insert (tty);
860 cmplus (tty, len); 863 cmplus (tty, len);
861 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */ 864 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */
862 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK; 865 FRAME_TERMINAL_CODING (f)->mode &= ~CODING_MODE_LAST_BLOCK;
863 while (len-- > 0) 866 while (len-- > 0)
864 { 867 {
865 int produced, consumed; 868 int produced, consumed;
866 unsigned char conversion_buffer[1024]; 869 unsigned char conversion_buffer[1024];
867 int conversion_buffer_size = sizeof conversion_buffer; 870 int conversion_buffer_size = sizeof conversion_buffer;
886 start++, len--; 889 start++, len--;
887 } 890 }
888 891
889 if (len <= 0) 892 if (len <= 0)
890 /* This is the last glyph. */ 893 /* This is the last glyph. */
891 terminal_coding.mode |= CODING_MODE_LAST_BLOCK; 894 FRAME_TERMINAL_CODING (f)->mode |= CODING_MODE_LAST_BLOCK;
892 895
893 /* The size of conversion buffer (1024 bytes) is surely 896 /* The size of conversion buffer (1024 bytes) is surely
894 sufficient for just one glyph. */ 897 sufficient for just one glyph. */
895 produced = encode_terminal_code (glyph, conversion_buffer, 1, 898 produced = encode_terminal_code (glyph, conversion_buffer, 1,
896 conversion_buffer_size, &consumed); 899 conversion_buffer_size, &consumed);
3103 /* Create a new display object and add it to the display list. */ 3106 /* Create a new display object and add it to the display list. */
3104 3107
3105 struct display * 3108 struct display *
3106 create_display (void) 3109 create_display (void)
3107 { 3110 {
3108 struct display *dev = (struct display *) xmalloc (sizeof (struct display)); 3111 struct display *display = (struct display *) xmalloc (sizeof (struct display));
3109 3112
3110 bzero (dev, sizeof (struct display)); 3113 bzero (display, sizeof (struct display));
3111 dev->next_display = display_list; 3114 display->next_display = display_list;
3112 display_list = dev; 3115 display_list = display;
3113 3116
3114 return dev; 3117 display->keyboard_coding =
3118 (struct coding_system *) xmalloc (sizeof (struct coding_system));
3119 display->terminal_coding =
3120 (struct coding_system *) xmalloc (sizeof (struct coding_system));
3121
3122 setup_coding_system (Qnil, display->keyboard_coding);
3123 setup_coding_system (Qnil, display->terminal_coding);
3124
3125 return display;
3115 } 3126 }
3116 3127
3117 /* Remove a display from the display list and free its memory. */ 3128 /* Remove a display from the display list and free its memory. */
3118 3129
3119 void 3130 void
3120 delete_display (struct display *dev) 3131 delete_display (struct display *display)
3121 { 3132 {
3122 struct display **dp; 3133 struct display **dp;
3123 Lisp_Object tail, frame; 3134 Lisp_Object tail, frame;
3124 3135
3125 /* Check for and close live frames that are still on this 3136 /* Check for and close live frames that are still on this
3126 display. */ 3137 display. */
3127 FOR_EACH_FRAME (tail, frame) 3138 FOR_EACH_FRAME (tail, frame)
3128 { 3139 {
3129 struct frame *f = XFRAME (frame); 3140 struct frame *f = XFRAME (frame);
3130 if (FRAME_LIVE_P (f) && f->display == dev) 3141 if (FRAME_LIVE_P (f) && f->display == display)
3131 { 3142 {
3132 Fdelete_frame (frame, Qt); 3143 Fdelete_frame (frame, Qt);
3133 } 3144 }
3134 } 3145 }
3135 3146
3136 for (dp = &display_list; *dp != dev; dp = &(*dp)->next_display) 3147 for (dp = &display_list; *dp != display; dp = &(*dp)->next_display)
3137 if (! *dp) 3148 if (! *dp)
3138 abort (); 3149 abort ();
3139 *dp = dev->next_display; 3150 *dp = display->next_display;
3140 3151
3141 bzero (dev, sizeof (struct display)); 3152 if (display->keyboard_coding)
3142 xfree (dev); 3153 xfree (display->keyboard_coding);
3154 if (display->terminal_coding)
3155 xfree (display->terminal_coding);
3156
3157 bzero (display, sizeof (struct display));
3158 xfree (display);
3143 } 3159 }
3144 3160
3145 3161
3146 3162
3147 DEFUN ("suspend-tty", Fsuspend_tty, Ssuspend_tty, 0, 1, 0, 3163 DEFUN ("suspend-tty", Fsuspend_tty, Ssuspend_tty, 0, 1, 0,