789 |
} |
} |
790 |
} |
} |
791 |
|
|
792 |
|
/* Buffer to store the result of terminal codes. It is initialized in |
793 |
|
term_init and, if necessary, enlarged in encode_terminal_code. */ |
794 |
|
static unsigned char *terminal_encode_buffer; |
795 |
|
/* Size of terminal_encode_buffer. */ |
796 |
|
static int terminal_encode_buf_size; |
797 |
|
|
798 |
/* Encode SRC_LEN glyphs starting at SRC to terminal output codes and |
/* Encode SRC_LEN glyphs starting at SRC to terminal output codes and |
799 |
store them at DST. Do not write more than DST_LEN bytes. That may |
store them in terminal_encode_buffer. |
|
require stopping before all SRC_LEN input glyphs have been |
|
|
converted. |
|
800 |
|
|
801 |
We store the number of glyphs actually converted in *CONSUMED. The |
We store the number of glyphs actually converted in *CONSUMED. The |
802 |
return value is the number of bytes store in DST. */ |
return value is the number of bytes stored in |
803 |
|
terminal_encode_buffer. |
804 |
|
|
805 |
|
This function will stop before encoding all glyphs in these two |
806 |
|
cases. |
807 |
|
|
808 |
|
(1) If the first glyph doesn't have a string entry in Vglyph_table, |
809 |
|
it stops at encountering a glyph that has a string entry in |
810 |
|
Vglyph_table.n |
811 |
|
|
812 |
|
(2) If the first has a string entry in Vglyph_table, it stops after |
813 |
|
encoding that string. |
814 |
|
*/ |
815 |
|
|
816 |
int |
int |
817 |
encode_terminal_code (src, dst, src_len, dst_len, consumed) |
encode_terminal_code (src, src_len, consumed) |
818 |
struct glyph *src; |
struct glyph *src; |
819 |
int src_len; |
int src_len; |
820 |
unsigned char *dst; |
int *consumed; |
|
int dst_len, *consumed; |
|
821 |
{ |
{ |
822 |
struct glyph *src_start = src, *src_end = src + src_len; |
struct glyph *src_start = src, *src_end = src + src_len; |
|
unsigned char *dst_start = dst, *dst_end = dst + dst_len; |
|
823 |
register GLYPH g; |
register GLYPH g; |
824 |
unsigned char workbuf[MAX_MULTIBYTE_LENGTH]; |
register int c; |
825 |
const unsigned char *buf; |
Lisp_Object string; |
826 |
int len; |
unsigned char *workbuf, *buf; |
827 |
|
int nchars; |
828 |
register int tlen = GLYPH_TABLE_LENGTH; |
register int tlen = GLYPH_TABLE_LENGTH; |
829 |
register Lisp_Object *tbase = GLYPH_TABLE_BASE; |
register Lisp_Object *tbase = GLYPH_TABLE_BASE; |
830 |
struct coding_system *coding; |
struct coding_system *coding; |
835 |
coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK |
coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK |
836 |
? &terminal_coding |
? &terminal_coding |
837 |
: &safe_terminal_coding); |
: &safe_terminal_coding); |
838 |
|
coding->destination = terminal_encode_buffer; |
839 |
|
coding->dst_bytes = terminal_encode_buf_size; |
840 |
|
coding->mode |= CODING_MODE_LAST_BLOCK; |
841 |
|
|
842 |
while (src < src_end) |
workbuf = buf = alloca (MAX_MULTIBYTE_LENGTH * src_len); |
843 |
|
for (nchars = 0; src < src_end; src++) |
844 |
{ |
{ |
845 |
/* We must skip glyphs to be padded for a wide character. */ |
/* We must skip glyphs to be padded for a wide character. */ |
846 |
if (! CHAR_GLYPH_PADDING_P (*src)) |
if (! CHAR_GLYPH_PADDING_P (*src)) |
847 |
{ |
{ |
848 |
g = GLYPH_FROM_CHAR_GLYPH (src[0]); |
g = GLYPH_FROM_CHAR_GLYPH (src[0]); |
849 |
|
string = Qnil; |
850 |
|
|
851 |
if (g < 0 || g >= tlen) |
if (g < 0 || g >= tlen) |
852 |
{ |
c = src->u.ch; |
|
/* This glyph doesn't have an entry in Vglyph_table. */ |
|
|
if (! CHAR_VALID_P (src->u.ch, 0)) |
|
|
{ |
|
|
len = 1; |
|
|
buf = " "; |
|
|
coding->src_multibyte = 0; |
|
|
} |
|
|
else |
|
|
{ |
|
|
len = CHAR_STRING (src->u.ch, workbuf); |
|
|
buf = workbuf; |
|
|
coding->src_multibyte = 1; |
|
|
} |
|
|
} |
|
853 |
else |
else |
854 |
{ |
{ |
855 |
/* This glyph has an entry in Vglyph_table, |
/* This glyph has an entry in Vglyph_table, |
857 |
GLYPH_FOLLOW_ALIASES (tbase, tlen, g); |
GLYPH_FOLLOW_ALIASES (tbase, tlen, g); |
858 |
|
|
859 |
if (GLYPH_SIMPLE_P (tbase, tlen, g)) |
if (GLYPH_SIMPLE_P (tbase, tlen, g)) |
860 |
{ |
/* We set the multi-byte form of a character in G |
861 |
/* We set the multi-byte form of a character in G |
(that should be an ASCII character) at WORKBUF. */ |
862 |
(that should be an ASCII character) at |
c = FAST_GLYPH_CHAR (g); |
|
WORKBUF. */ |
|
|
workbuf[0] = FAST_GLYPH_CHAR (g); |
|
|
len = 1; |
|
|
buf = workbuf; |
|
|
coding->src_multibyte = 0; |
|
|
} |
|
863 |
else |
else |
864 |
{ |
/* We have a string in Vglyph_table. */ |
865 |
/* We have a string in Vglyph_table. */ |
string = tbase[g]; |
|
len = GLYPH_LENGTH (tbase, g); |
|
|
buf = GLYPH_STRING (tbase, g); |
|
|
coding->src_multibyte = STRING_MULTIBYTE (tbase[g]); |
|
|
} |
|
866 |
} |
} |
867 |
|
|
868 |
coding->source = buf; |
if (NILP (string)) |
|
coding->destination = dst; |
|
|
coding->dst_bytes = dst_end - dst; |
|
|
encode_coding_object (coding, Qnil, 0, 0, 1, len, Qnil); |
|
|
len -= coding->consumed; |
|
|
dst += coding->produced; |
|
|
if (coding->result == CODING_RESULT_INSUFFICIENT_DST) |
|
|
/* The remaining output buffer is too short. We must |
|
|
break the loop here without increasing SRC so that the |
|
|
next call of this function starts from the same glyph. */ |
|
|
break; |
|
|
|
|
|
if (len > 0) |
|
869 |
{ |
{ |
870 |
/* This is the case that a code of the range 0200..0237 |
/* Store the multibyte form of C at BUF. */ |
871 |
exists in buf. We must just write out such a code. */ |
buf += CHAR_STRING (c, buf); |
872 |
buf += coding->consumed; |
nchars++; |
873 |
while (len--) |
} |
874 |
*dst++ = *buf++; |
else |
875 |
|
{ |
876 |
|
if (nchars == 0) |
877 |
|
{ |
878 |
|
encode_coding_object (coding, string, 0, 0, SCHARS (string), |
879 |
|
SBYTES (string), Qnil); |
880 |
|
src++; |
881 |
|
} |
882 |
|
break; |
883 |
} |
} |
884 |
} |
} |
|
src++; |
|
885 |
} |
} |
886 |
|
|
887 |
|
if (nchars > 0) |
888 |
|
{ |
889 |
|
coding->source = workbuf; |
890 |
|
encode_coding_object (coding, Qnil, 0, 0, nchars, |
891 |
|
buf - workbuf, Qnil); |
892 |
|
} |
893 |
|
terminal_encode_buffer = coding->destination; |
894 |
|
terminal_encode_buf_size = coding->dst_bytes; |
895 |
|
|
896 |
*consumed = src - src_start; |
*consumed = src - src_start; |
897 |
return (dst - dst_start); |
return (coding->produced); |
898 |
} |
} |
899 |
|
|
900 |
|
|
906 |
int produced, consumed; |
int produced, consumed; |
907 |
struct frame *sf = XFRAME (selected_frame); |
struct frame *sf = XFRAME (selected_frame); |
908 |
struct frame *f = updating_frame ? updating_frame : sf; |
struct frame *f = updating_frame ? updating_frame : sf; |
|
unsigned char conversion_buffer[1024]; |
|
|
int conversion_buffer_size = sizeof conversion_buffer; |
|
909 |
|
|
910 |
if (write_glyphs_hook |
if (write_glyphs_hook |
911 |
&& ! FRAME_TERMCAP_P (f)) |
&& ! FRAME_TERMCAP_P (f)) |
949 |
|
|
950 |
while (n > 0) |
while (n > 0) |
951 |
{ |
{ |
952 |
/* We use a fixed size (1024 bytes) of conversion buffer. |
produced = encode_terminal_code (string, n, &consumed); |
|
Usually it is sufficient, but if not, we just repeat the |
|
|
loop. */ |
|
|
produced = encode_terminal_code (string, conversion_buffer, |
|
|
n, conversion_buffer_size, |
|
|
&consumed); |
|
953 |
if (produced > 0) |
if (produced > 0) |
954 |
{ |
{ |
955 |
fwrite (conversion_buffer, 1, produced, stdout); |
fwrite (terminal_encode_buffer, 1, produced, stdout); |
956 |
if (ferror (stdout)) |
if (ferror (stdout)) |
957 |
clearerr (stdout); |
clearerr (stdout); |
958 |
if (termscript) |
if (termscript) |
959 |
fwrite (conversion_buffer, 1, produced, termscript); |
fwrite (terminal_encode_buffer, 1, produced, termscript); |
960 |
} |
} |
961 |
len -= consumed; |
len -= consumed; |
962 |
n -= consumed; |
n -= consumed; |
968 |
turn_off_highlight (); |
turn_off_highlight (); |
969 |
} |
} |
970 |
|
|
|
/* We may have to output some codes to terminate the writing. */ |
|
|
if (CODING_REQUIRE_FLUSHING (&terminal_coding)) |
|
|
{ |
|
|
terminal_coding.mode |= CODING_MODE_LAST_BLOCK; |
|
|
terminal_coding.source = (unsigned char *) ""; |
|
|
terminal_coding.destination = conversion_buffer; |
|
|
terminal_coding.dst_bytes = conversion_buffer_size; |
|
|
encode_coding_object (&terminal_coding, Qnil, 0, 0, 0, 0, Qnil); |
|
|
if (terminal_coding.produced > 0) |
|
|
{ |
|
|
fwrite (conversion_buffer, 1, terminal_coding.produced, stdout); |
|
|
if (ferror (stdout)) |
|
|
clearerr (stdout); |
|
|
if (termscript) |
|
|
fwrite (conversion_buffer, 1, terminal_coding.produced, |
|
|
termscript); |
|
|
} |
|
|
} |
|
|
|
|
971 |
cmcheckmagic (); |
cmcheckmagic (); |
972 |
} |
} |
973 |
|
|
1011 |
while (len-- > 0) |
while (len-- > 0) |
1012 |
{ |
{ |
1013 |
int produced, consumed; |
int produced, consumed; |
|
unsigned char conversion_buffer[1024]; |
|
|
int conversion_buffer_size = sizeof conversion_buffer; |
|
1014 |
|
|
1015 |
OUTPUT1_IF (TS_ins_char); |
OUTPUT1_IF (TS_ins_char); |
1016 |
if (!start) |
if (!start) |
1017 |
{ |
{ |
1018 |
conversion_buffer[0] = SPACEGLYPH; |
terminal_encode_buffer[0] = SPACEGLYPH; |
1019 |
produced = 1; |
produced = 1; |
1020 |
} |
} |
1021 |
else |
else |
1031 |
OUTPUT1_IF (TS_ins_char); |
OUTPUT1_IF (TS_ins_char); |
1032 |
start++, len--; |
start++, len--; |
1033 |
} |
} |
1034 |
|
produced = encode_terminal_code (glyph, 1, &consumed); |
|
if (len <= 0) |
|
|
/* This is the last glyph. */ |
|
|
terminal_coding.mode |= CODING_MODE_LAST_BLOCK; |
|
|
|
|
|
/* The size of conversion buffer (1024 bytes) is surely |
|
|
sufficient for just one glyph. */ |
|
|
produced = encode_terminal_code (glyph, conversion_buffer, 1, |
|
|
conversion_buffer_size, &consumed); |
|
1035 |
} |
} |
1036 |
|
|
1037 |
if (produced > 0) |
if (produced > 0) |
1038 |
{ |
{ |
1039 |
fwrite (conversion_buffer, 1, produced, stdout); |
fwrite (terminal_encode_buffer, 1, produced, stdout); |
1040 |
if (ferror (stdout)) |
if (ferror (stdout)) |
1041 |
clearerr (stdout); |
clearerr (stdout); |
1042 |
if (termscript) |
if (termscript) |
1043 |
fwrite (conversion_buffer, 1, produced, termscript); |
fwrite (terminal_encode_buffer, 1, produced, termscript); |
1044 |
} |
} |
1045 |
|
|
1046 |
OUTPUT1_IF (TS_pad_inserted_char); |
OUTPUT1_IF (TS_pad_inserted_char); |
2521 |
|
|
2522 |
FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; |
FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; |
2523 |
FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; |
FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; |
2524 |
|
|
2525 |
|
if (! terminal_encode_buffer) |
2526 |
|
{ |
2527 |
|
terminal_encode_buffer = xmalloc (1024); |
2528 |
|
if (! terminal_encode_buffer) |
2529 |
|
abort (); |
2530 |
|
terminal_encode_buf_size = 1024; |
2531 |
|
} |
2532 |
#endif /* WINDOWSNT */ |
#endif /* WINDOWSNT */ |
2533 |
} |
} |
2534 |
|
|