Mercurial > emacs
comparison src/term.c @ 90059:9b0bfaaaec9c
Sync to the change in HEAD on 2004-11-30.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Sat, 11 Dec 2004 02:11:33 +0000 |
parents | f2ebccfa87d4 |
children | cb67264d6096 |
comparison
equal
deleted
inserted
replaced
90058:48f163b71dbf | 90059:9b0bfaaaec9c |
---|---|
791 } | 791 } |
792 cmplus (first_unused_hpos - curX); | 792 cmplus (first_unused_hpos - curX); |
793 } | 793 } |
794 } | 794 } |
795 | 795 |
796 /* Buffer to store the result of terminal codes. It is initialized in | 796 /* Buffers to store the source and result of code conversion for terminal. */ |
797 term_init and, if necessary, enlarged in encode_terminal_code. */ | 797 static unsigned char *encode_terminal_src; |
798 unsigned char *terminal_encode_buffer; | 798 static unsigned char *encode_terminal_dst; |
799 /* Size of terminal_encode_buffer. */ | 799 /* Allocated sizes of the above buffers. */ |
800 static int terminal_encode_buf_size; | 800 static int encode_terminal_src_size; |
801 | 801 static int encode_terminal_dst_size; |
802 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes and | 802 |
803 store them in terminal_encode_buffer. | 803 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes. |
804 | 804 Set CODING->produced to the byte-length of the resulting byte |
805 We store the number of glyphs actually converted in *CONSUMED. The | 805 sequence, and return a pointer to that byte sequence. */ |
806 return value is the number of bytes stored in | 806 |
807 terminal_encode_buffer. | 807 unsigned char * |
808 | 808 encode_terminal_code (src, src_len, coding) |
809 This function will stop before encoding all glyphs in these two | |
810 cases. | |
811 | |
812 (1) If the first glyph doesn't have a string entry in Vglyph_table, | |
813 it stops at encountering a glyph that has a string entry in | |
814 Vglyph_table.n | |
815 | |
816 (2) If the first has a string entry in Vglyph_table, it stops after | |
817 encoding that string. | |
818 */ | |
819 | |
820 int | |
821 encode_terminal_code (src, src_len, consumed) | |
822 struct glyph *src; | 809 struct glyph *src; |
823 int src_len; | 810 int src_len; |
824 int *consumed; | 811 struct coding_system *coding; |
825 { | 812 { |
826 struct glyph *src_start = src, *src_end = src + src_len; | 813 struct glyph *src_start = src, *src_end = src + src_len; |
827 register GLYPH g; | 814 register GLYPH g; |
828 register int c; | 815 unsigned char *buf; |
829 Lisp_Object string; | 816 int nchars, nbytes, required; |
830 unsigned char *workbuf, *buf; | |
831 int nchars; | |
832 register int tlen = GLYPH_TABLE_LENGTH; | 817 register int tlen = GLYPH_TABLE_LENGTH; |
833 register Lisp_Object *tbase = GLYPH_TABLE_BASE; | 818 register Lisp_Object *tbase = GLYPH_TABLE_BASE; |
834 struct coding_system *coding; | 819 Lisp_Object charset_list; |
835 Lisp_Object attrs, charset_list; | 820 |
836 | 821 /* Allocate sufficient size of buffer to store all characters in |
837 #if 1 | 822 multibyte-form. But, it may be enlarged on demand if |
838 /* GLYPH-TABLE is not supported anymore in xdisp.c. */ | 823 Vglyph_table contains a string. */ |
839 tlen = 0; | 824 required = MAX_MULTIBYTE_LENGTH * src_len; |
840 #endif | 825 if (encode_terminal_src_size < required) |
841 | 826 { |
842 /* If terminal_coding does any conversion, use it, otherwise use | 827 if (encode_terminal_src_size == 0) |
843 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here | 828 encode_terminal_src = xmalloc (required); |
844 because it always return 1 if the member src_multibyte is 1. */ | 829 else |
845 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK | 830 encode_terminal_src = xrealloc (encode_terminal_src, required); |
846 ? &terminal_coding | 831 encode_terminal_src_size = required; |
847 : &safe_terminal_coding); | 832 } |
848 coding->destination = terminal_encode_buffer; | 833 |
849 coding->dst_bytes = terminal_encode_buf_size; | 834 charset_list = coding_charset_list (coding); |
850 coding->mode |= CODING_MODE_LAST_BLOCK; | 835 |
851 attrs = CODING_ID_ATTRS (coding->id); | 836 buf = encode_terminal_src; |
852 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | 837 nchars = 0; |
853 | 838 while (src < src_end) |
854 workbuf = buf = alloca (MAX_MULTIBYTE_LENGTH * src_len); | |
855 for (nchars = 0; src < src_end; src++) | |
856 { | 839 { |
857 /* We must skip glyphs to be padded for a wide character. */ | 840 /* We must skip glyphs to be padded for a wide character. */ |
858 if (! CHAR_GLYPH_PADDING_P (*src)) | 841 if (! CHAR_GLYPH_PADDING_P (*src)) |
859 { | 842 { |
843 int c; | |
844 Lisp_Object string; | |
845 | |
846 string = Qnil; | |
860 g = GLYPH_FROM_CHAR_GLYPH (src[0]); | 847 g = GLYPH_FROM_CHAR_GLYPH (src[0]); |
861 string = Qnil; | |
862 | 848 |
863 if (g < 0 || g >= tlen) | 849 if (g < 0 || g >= tlen) |
864 c = src->u.ch; | 850 { |
851 /* This glyph doesn't has an entry in Vglyph_table. */ | |
852 c = src->u.ch; | |
853 } | |
865 else | 854 else |
866 { | 855 { |
867 /* This glyph has an entry in Vglyph_table, | 856 /* This glyph has an entry in Vglyph_table, |
868 so process any alias before testing for simpleness. */ | 857 so process any alias before testing for simpleness. */ |
869 GLYPH_FOLLOW_ALIASES (tbase, tlen, g); | 858 GLYPH_FOLLOW_ALIASES (tbase, tlen, g); |
877 string = tbase[g]; | 866 string = tbase[g]; |
878 } | 867 } |
879 | 868 |
880 if (NILP (string)) | 869 if (NILP (string)) |
881 { | 870 { |
882 if (! char_charset (c, charset_list, NULL)) | 871 if (char_charset (c, charset_list, NULL)) |
883 { | |
884 /* C is not encodable. */ | |
885 int i; | |
886 | |
887 for (i = CHAR_WIDTH (c) - 1; i >= 0; i--, nchars++) | |
888 *buf++ = '?'; | |
889 } | |
890 else | |
891 { | 872 { |
892 /* Store the multibyte form of C at BUF. */ | 873 /* Store the multibyte form of C at BUF. */ |
893 buf += CHAR_STRING (c, buf); | 874 buf += CHAR_STRING (c, buf); |
894 nchars++; | 875 nchars++; |
895 } | 876 } |
877 else | |
878 { | |
879 /* C is not encodable. */ | |
880 *buf++ = '?'; | |
881 nchars++; | |
882 while (src + 1 < src_end && CHAR_GLYPH_PADDING_P (src[1])) | |
883 { | |
884 *buf++ = '?'; | |
885 nchars++; | |
886 src++; | |
887 } | |
888 } | |
896 } | 889 } |
897 else | 890 else |
898 { | 891 { |
899 if (nchars == 0) | 892 unsigned char *p = SDATA (string), *pend = p + SBYTES (string); |
893 | |
894 if (! STRING_MULTIBYTE (string)) | |
895 string = string_to_multibyte (string); | |
896 nbytes = buf - encode_terminal_src; | |
897 if (nbytes + SBYTES (string) < encode_terminal_src_size) | |
900 { | 898 { |
901 encode_coding_object (coding, string, 0, 0, SCHARS (string), | 899 encode_terminal_src_size = nbytes + SBYTES (string); |
902 SBYTES (string), Qnil); | 900 encode_terminal_src = xrealloc (encode_terminal_src, |
903 src++; | 901 encode_terminal_src_size); |
902 buf = encode_terminal_src + nbytes; | |
904 } | 903 } |
905 break; | 904 bcopy (SDATA (string), buf, SBYTES (string)); |
905 buf += SBYTES (string); | |
906 nchars += SCHARS (string); | |
906 } | 907 } |
907 } | 908 } |
908 } | 909 src++; |
909 | 910 } |
910 if (nchars > 0) | 911 |
911 { | 912 if (nchars == 0) |
912 coding->source = workbuf; | 913 { |
913 encode_coding_object (coding, Qnil, 0, 0, nchars, | 914 coding->produced = 0; |
914 buf - workbuf, Qnil); | 915 return NULL; |
915 } | 916 } |
917 | |
918 nbytes = buf - encode_terminal_src; | |
919 coding->source = encode_terminal_src; | |
920 if (encode_terminal_dst_size == 0) | |
921 { | |
922 encode_terminal_dst_size = encode_terminal_src_size; | |
923 encode_terminal_dst = xmalloc (encode_terminal_dst_size); | |
924 } | |
925 coding->destination = encode_terminal_dst; | |
926 coding->dst_bytes = encode_terminal_dst_size; | |
927 encode_coding_object (coding, Qnil, 0, 0, nchars, nbytes, Qnil); | |
916 /* coding->destination may have been reallocated. */ | 928 /* coding->destination may have been reallocated. */ |
917 terminal_encode_buffer = coding->destination; | 929 encode_terminal_dst = coding->destination; |
918 if (terminal_encode_buf_size < coding->dst_bytes) | 930 encode_terminal_dst_size = coding->dst_bytes; |
919 terminal_encode_buf_size = coding->dst_bytes; | 931 |
920 | 932 return (encode_terminal_dst); |
921 *consumed = src - src_start; | |
922 return (coding->produced); | |
923 } | 933 } |
924 | 934 |
925 | 935 |
926 void | 936 void |
927 write_glyphs (string, len) | 937 write_glyphs (string, len) |
929 register int len; | 939 register int len; |
930 { | 940 { |
931 int produced, consumed; | 941 int produced, consumed; |
932 struct frame *sf = XFRAME (selected_frame); | 942 struct frame *sf = XFRAME (selected_frame); |
933 struct frame *f = updating_frame ? updating_frame : sf; | 943 struct frame *f = updating_frame ? updating_frame : sf; |
944 unsigned char *conversion_buffer; | |
945 struct coding_system *coding; | |
934 | 946 |
935 if (write_glyphs_hook | 947 if (write_glyphs_hook |
936 && ! FRAME_TERMCAP_P (f)) | 948 && ! FRAME_TERMCAP_P (f)) |
937 { | 949 { |
938 (*write_glyphs_hook) (string, len); | 950 (*write_glyphs_hook) (string, len); |
975 | 987 |
976 /* Turn appearance modes of the face of the run on. */ | 988 /* Turn appearance modes of the face of the run on. */ |
977 highlight_if_desired (); | 989 highlight_if_desired (); |
978 turn_on_face (f, face_id); | 990 turn_on_face (f, face_id); |
979 | 991 |
980 while (n > 0) | 992 if (n == len) |
993 /* This is the last run. */ | |
994 coding->mode |= CODING_MODE_LAST_BLOCK; | |
995 conversion_buffer = encode_terminal_code (string, n, coding); | |
996 if (coding->produced > 0) | |
981 { | 997 { |
982 produced = encode_terminal_code (string, n, &consumed); | 998 fwrite (conversion_buffer, 1, coding->produced, stdout); |
983 if (produced > 0) | 999 if (ferror (stdout)) |
984 { | 1000 clearerr (stdout); |
985 fwrite (terminal_encode_buffer, 1, produced, stdout); | 1001 if (termscript) |
986 if (ferror (stdout)) | 1002 fwrite (conversion_buffer, 1, coding->produced, termscript); |
987 clearerr (stdout); | |
988 if (termscript) | |
989 fwrite (terminal_encode_buffer, 1, produced, termscript); | |
990 } | |
991 len -= consumed; | |
992 n -= consumed; | |
993 string += consumed; | |
994 } | 1003 } |
1004 len -= n; | |
1005 string += n; | |
995 | 1006 |
996 /* Turn appearance modes off. */ | 1007 /* Turn appearance modes off. */ |
997 turn_off_face (f, face_id); | 1008 turn_off_face (f, face_id); |
998 turn_off_highlight (); | 1009 turn_off_highlight (); |
999 } | 1010 } |
1037 return; | 1048 return; |
1038 } | 1049 } |
1039 | 1050 |
1040 turn_on_insert (); | 1051 turn_on_insert (); |
1041 cmplus (len); | 1052 cmplus (len); |
1042 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */ | 1053 |
1043 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK; | 1054 if (! start) |
1055 space[0] = SPACEGLYPH; | |
1056 | |
1057 /* If terminal_coding does any conversion, use it, otherwise use | |
1058 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here | |
1059 because it always return 1 if the member src_multibyte is 1. */ | |
1060 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK | |
1061 ? &terminal_coding : &safe_terminal_coding); | |
1062 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at | |
1063 the tail. */ | |
1064 coding->mode &= ~CODING_MODE_LAST_BLOCK; | |
1065 | |
1044 while (len-- > 0) | 1066 while (len-- > 0) |
1045 { | 1067 { |
1046 int produced, consumed; | |
1047 | |
1048 OUTPUT1_IF (TS_ins_char); | 1068 OUTPUT1_IF (TS_ins_char); |
1049 if (!start) | 1069 if (!start) |
1050 { | 1070 { |
1051 terminal_encode_buffer[0] = SPACEGLYPH; | 1071 conversion_buffer = space; |
1052 produced = 1; | 1072 coding->produced = 1; |
1053 } | 1073 } |
1054 else | 1074 else |
1055 { | 1075 { |
1056 highlight_if_desired (); | 1076 highlight_if_desired (); |
1057 turn_on_face (f, start->face_id); | 1077 turn_on_face (f, start->face_id); |
1062 while (len && CHAR_GLYPH_PADDING_P (*start)) | 1082 while (len && CHAR_GLYPH_PADDING_P (*start)) |
1063 { | 1083 { |
1064 OUTPUT1_IF (TS_ins_char); | 1084 OUTPUT1_IF (TS_ins_char); |
1065 start++, len--; | 1085 start++, len--; |
1066 } | 1086 } |
1067 produced = encode_terminal_code (glyph, 1, &consumed); | 1087 |
1088 if (len <= 0) | |
1089 /* This is the last glyph. */ | |
1090 coding->mode |= CODING_MODE_LAST_BLOCK; | |
1091 | |
1092 conversion_buffer = encode_terminal_code (glyph, 1, coding); | |
1068 } | 1093 } |
1069 | 1094 |
1070 if (produced > 0) | 1095 if (coding->produced > 0) |
1071 { | 1096 { |
1072 fwrite (terminal_encode_buffer, 1, produced, stdout); | 1097 fwrite (conversion_buffer, 1, coding->produced, stdout); |
1073 if (ferror (stdout)) | 1098 if (ferror (stdout)) |
1074 clearerr (stdout); | 1099 clearerr (stdout); |
1075 if (termscript) | 1100 if (termscript) |
1076 fwrite (terminal_encode_buffer, 1, produced, termscript); | 1101 fwrite (conversion_buffer, 1, coding->produced, termscript); |
1077 } | 1102 } |
1078 | 1103 |
1079 OUTPUT1_IF (TS_pad_inserted_char); | 1104 OUTPUT1_IF (TS_pad_inserted_char); |
1080 if (start) | 1105 if (start) |
1081 { | 1106 { |
2245 int buffer_size = 4096; | 2270 int buffer_size = 4096; |
2246 register char *p; | 2271 register char *p; |
2247 int status; | 2272 int status; |
2248 struct frame *sf = XFRAME (selected_frame); | 2273 struct frame *sf = XFRAME (selected_frame); |
2249 | 2274 |
2250 encode_terminal_bufsize = 0; | 2275 encode_terminal_src_size = 0; |
2276 encode_terminal_dst_size = 0; | |
2251 | 2277 |
2252 #ifdef WINDOWSNT | 2278 #ifdef WINDOWSNT |
2253 initialize_w32_display (); | 2279 initialize_w32_display (); |
2254 | 2280 |
2255 Wcm_clear (); | 2281 Wcm_clear (); |
2640 /* meaningless in this case */ | 2666 /* meaningless in this case */ |
2641 baud_rate = 9600; | 2667 baud_rate = 9600; |
2642 | 2668 |
2643 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; | 2669 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; |
2644 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; | 2670 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; |
2645 | |
2646 if (! terminal_encode_buffer) | |
2647 { | |
2648 terminal_encode_buffer = xmalloc (1024); | |
2649 if (! terminal_encode_buffer) | |
2650 abort (); | |
2651 terminal_encode_buf_size = 1024; | |
2652 } | |
2653 #endif /* WINDOWSNT */ | 2671 #endif /* WINDOWSNT */ |
2654 | 2672 |
2655 xfree (buffer); | 2673 xfree (buffer); |
2656 } | 2674 } |
2657 | 2675 |