aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2004-12-11 02:11:33 +0000
committerKenichi Handa2004-12-11 02:11:33 +0000
commit288d51326a25b066e192195cf90aa187ec9b58cb (patch)
tree65a6fb1bc29233bd5e166159f1da0077861a70a4 /src
parent75403d053f70b8753dc54d0b9c0d083c3cd3fd11 (diff)
downloademacs-288d51326a25b066e192195cf90aa187ec9b58cb.tar.gz
emacs-288d51326a25b066e192195cf90aa187ec9b58cb.zip
Sync to the change in HEAD on 2004-11-30.
Diffstat (limited to 'src')
-rw-r--r--src/term.c230
1 files changed, 124 insertions, 106 deletions
diff --git a/src/term.c b/src/term.c
index 1520a96babd..6beac594ddf 100644
--- a/src/term.c
+++ b/src/term.c
@@ -793,75 +793,64 @@ clear_end_of_line (first_unused_hpos)
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. */ 797static unsigned char *encode_terminal_src;
798unsigned char *terminal_encode_buffer; 798static unsigned char *encode_terminal_dst;
799/* Size of terminal_encode_buffer. */ 799/* Allocated sizes of the above buffers. */
800static int terminal_encode_buf_size; 800static int encode_terminal_src_size;
801 801static 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. 807unsigned char *
808 808encode_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
820int
821encode_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;
836 820
837#if 1 821 /* Allocate sufficient size of buffer to store all characters in
838 /* GLYPH-TABLE is not supported anymore in xdisp.c. */ 822 multibyte-form. But, it may be enlarged on demand if
839 tlen = 0; 823 Vglyph_table contains a string. */
840#endif 824 required = MAX_MULTIBYTE_LENGTH * src_len;
825 if (encode_terminal_src_size < required)
826 {
827 if (encode_terminal_src_size == 0)
828 encode_terminal_src = xmalloc (required);
829 else
830 encode_terminal_src = xrealloc (encode_terminal_src, required);
831 encode_terminal_src_size = required;
832 }
841 833
842 /* If terminal_coding does any conversion, use it, otherwise use 834 charset_list = coding_charset_list (coding);
843 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
844 because it always return 1 if the member src_multibyte is 1. */
845 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK
846 ? &terminal_coding
847 : &safe_terminal_coding);
848 coding->destination = terminal_encode_buffer;
849 coding->dst_bytes = terminal_encode_buf_size;
850 coding->mode |= CODING_MODE_LAST_BLOCK;
851 attrs = CODING_ID_ATTRS (coding->id);
852 charset_list = CODING_ATTR_CHARSET_LIST (attrs);
853 835
854 workbuf = buf = alloca (MAX_MULTIBYTE_LENGTH * src_len); 836 buf = encode_terminal_src;
855 for (nchars = 0; src < src_end; src++) 837 nchars = 0;
838 while (src < src_end)
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 {
860 g = GLYPH_FROM_CHAR_GLYPH (src[0]); 843 int c;
844 Lisp_Object string;
845
861 string = Qnil; 846 string = Qnil;
847 g = GLYPH_FROM_CHAR_GLYPH (src[0]);
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,
@@ -879,47 +868,68 @@ encode_terminal_code (src, src_len, consumed)
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 { 872 {
884 /* C is not encodable. */ 873 /* Store the multibyte form of C at BUF. */
885 int i; 874 buf += CHAR_STRING (c, buf);
886 875 nchars++;
887 for (i = CHAR_WIDTH (c) - 1; i >= 0; i--, nchars++)
888 *buf++ = '?';
889 } 876 }
890 else 877 else
891 { 878 {
892 /* Store the multibyte form of C at BUF. */ 879 /* C is not encodable. */
893 buf += CHAR_STRING (c, buf); 880 *buf++ = '?';
894 nchars++; 881 nchars++;
882 while (src + 1 < src_end && CHAR_GLYPH_PADDING_P (src[1]))
883 {
884 *buf++ = '?';
885 nchars++;
886 src++;
887 }
895 } 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 }
909 src++;
910 }
911
912 if (nchars == 0)
913 {
914 coding->produced = 0;
915 return NULL;
908 } 916 }
909 917
910 if (nchars > 0) 918 nbytes = buf - encode_terminal_src;
919 coding->source = encode_terminal_src;
920 if (encode_terminal_dst_size == 0)
911 { 921 {
912 coding->source = workbuf; 922 encode_terminal_dst_size = encode_terminal_src_size;
913 encode_coding_object (coding, Qnil, 0, 0, nchars, 923 encode_terminal_dst = xmalloc (encode_terminal_dst_size);
914 buf - workbuf, Qnil);
915 } 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;
920 931
921 *consumed = src - src_start; 932 return (encode_terminal_dst);
922 return (coding->produced);
923} 933}
924 934
925 935
@@ -931,6 +941,8 @@ write_glyphs (string, len)
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))
@@ -977,21 +989,20 @@ write_glyphs (string, len)
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);
@@ -1039,17 +1050,26 @@ insert_glyphs (start, len)
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 {
@@ -1064,16 +1084,21 @@ insert_glyphs (start, len)
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);
@@ -2247,7 +2272,8 @@ term_init (terminal_type)
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 ();
@@ -2642,14 +2668,6 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
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);