diff options
| author | Paul Eggert | 2011-09-03 16:03:38 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-09-03 16:03:38 -0700 |
| commit | b49e353d9d01adbe60bc5d0b1658b4ef978b0b06 (patch) | |
| tree | 9f2ffa6f7a6562abf661a4951012b488ad8b1ae7 /src/term.c | |
| parent | 74b880cbc18bd0194c7b1fc44c4a983ee05adae2 (diff) | |
| parent | bc3200871917d5c54c8c4299a06bf8f8ba2ea02d (diff) | |
| download | emacs-b49e353d9d01adbe60bc5d0b1658b4ef978b0b06.tar.gz emacs-b49e353d9d01adbe60bc5d0b1658b4ef978b0b06.zip | |
Merge from trunk.
Diffstat (limited to 'src/term.c')
| -rw-r--r-- | src/term.c | 175 |
1 files changed, 49 insertions, 126 deletions
diff --git a/src/term.c b/src/term.c index 22056451cb9..837ab399152 100644 --- a/src/term.c +++ b/src/term.c | |||
| @@ -136,10 +136,6 @@ enum no_color_bit | |||
| 136 | 136 | ||
| 137 | static int max_frame_cols; | 137 | static int max_frame_cols; |
| 138 | 138 | ||
| 139 | /* The largest frame height in any call to calculate_costs. */ | ||
| 140 | |||
| 141 | static int max_frame_lines; | ||
| 142 | |||
| 143 | /* Non-zero if we have dropped our controlling tty and therefore | 139 | /* Non-zero if we have dropped our controlling tty and therefore |
| 144 | should not open a frame on stdout. */ | 140 | should not open a frame on stdout. */ |
| 145 | static int no_controlling_tty; | 141 | static int no_controlling_tty; |
| @@ -497,8 +493,8 @@ tty_clear_end_of_line (struct frame *f, int first_unused_hpos) | |||
| 497 | static unsigned char *encode_terminal_src; | 493 | static unsigned char *encode_terminal_src; |
| 498 | static unsigned char *encode_terminal_dst; | 494 | static unsigned char *encode_terminal_dst; |
| 499 | /* Allocated sizes of the above buffers. */ | 495 | /* Allocated sizes of the above buffers. */ |
| 500 | static int encode_terminal_src_size; | 496 | static ptrdiff_t encode_terminal_src_size; |
| 501 | static int encode_terminal_dst_size; | 497 | static ptrdiff_t encode_terminal_dst_size; |
| 502 | 498 | ||
| 503 | /* Encode SRC_LEN glyphs starting at SRC to terminal output codes. | 499 | /* Encode SRC_LEN glyphs starting at SRC to terminal output codes. |
| 504 | Set CODING->produced to the byte-length of the resulting byte | 500 | Set CODING->produced to the byte-length of the resulting byte |
| @@ -509,8 +505,8 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi | |||
| 509 | { | 505 | { |
| 510 | struct glyph *src_end = src + src_len; | 506 | struct glyph *src_end = src + src_len; |
| 511 | unsigned char *buf; | 507 | unsigned char *buf; |
| 512 | int nchars, nbytes, required; | 508 | ptrdiff_t nchars, nbytes, required; |
| 513 | register int tlen = GLYPH_TABLE_LENGTH; | 509 | ptrdiff_t tlen = GLYPH_TABLE_LENGTH; |
| 514 | register Lisp_Object *tbase = GLYPH_TABLE_BASE; | 510 | register Lisp_Object *tbase = GLYPH_TABLE_BASE; |
| 515 | Lisp_Object charset_list; | 511 | Lisp_Object charset_list; |
| 516 | 512 | ||
| @@ -518,13 +514,13 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi | |||
| 518 | multibyte-form. But, it may be enlarged on demand if | 514 | multibyte-form. But, it may be enlarged on demand if |
| 519 | Vglyph_table contains a string or a composite glyph is | 515 | Vglyph_table contains a string or a composite glyph is |
| 520 | encountered. */ | 516 | encountered. */ |
| 521 | required = MAX_MULTIBYTE_LENGTH * src_len; | 517 | if (min (PTRDIFF_MAX, SIZE_MAX) / MAX_MULTIBYTE_LENGTH < src_len) |
| 518 | memory_full (SIZE_MAX); | ||
| 519 | required = src_len; | ||
| 520 | required *= MAX_MULTIBYTE_LENGTH; | ||
| 522 | if (encode_terminal_src_size < required) | 521 | if (encode_terminal_src_size < required) |
| 523 | { | 522 | { |
| 524 | if (encode_terminal_src) | 523 | encode_terminal_src = xrealloc (encode_terminal_src, required); |
| 525 | encode_terminal_src = xrealloc (encode_terminal_src, required); | ||
| 526 | else | ||
| 527 | encode_terminal_src = xmalloc (required); | ||
| 528 | encode_terminal_src_size = required; | 524 | encode_terminal_src_size = required; |
| 529 | } | 525 | } |
| 530 | 526 | ||
| @@ -544,19 +540,21 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi | |||
| 544 | if (src->u.cmp.automatic) | 540 | if (src->u.cmp.automatic) |
| 545 | { | 541 | { |
| 546 | gstring = composition_gstring_from_id (src->u.cmp.id); | 542 | gstring = composition_gstring_from_id (src->u.cmp.id); |
| 547 | required = src->slice.cmp.to + 1 - src->slice.cmp.from; | 543 | required = src->slice.cmp.to - src->slice.cmp.from + 1; |
| 548 | } | 544 | } |
| 549 | else | 545 | else |
| 550 | { | 546 | { |
| 551 | cmp = composition_table[src->u.cmp.id]; | 547 | cmp = composition_table[src->u.cmp.id]; |
| 552 | required = MAX_MULTIBYTE_LENGTH * cmp->glyph_len; | 548 | required = cmp->glyph_len; |
| 549 | required *= MAX_MULTIBYTE_LENGTH; | ||
| 553 | } | 550 | } |
| 554 | 551 | ||
| 555 | if (encode_terminal_src_size < nbytes + required) | 552 | if (encode_terminal_src_size - nbytes < required) |
| 556 | { | 553 | { |
| 557 | encode_terminal_src_size = nbytes + required; | 554 | encode_terminal_src = |
| 558 | encode_terminal_src = xrealloc (encode_terminal_src, | 555 | xpalloc (encode_terminal_src, &encode_terminal_src_size, |
| 559 | encode_terminal_src_size); | 556 | required - (encode_terminal_src_size - nbytes), |
| 557 | -1, 1); | ||
| 560 | buf = encode_terminal_src + nbytes; | 558 | buf = encode_terminal_src + nbytes; |
| 561 | } | 559 | } |
| 562 | 560 | ||
| @@ -627,11 +625,11 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi | |||
| 627 | if (NILP (string)) | 625 | if (NILP (string)) |
| 628 | { | 626 | { |
| 629 | nbytes = buf - encode_terminal_src; | 627 | nbytes = buf - encode_terminal_src; |
| 630 | if (encode_terminal_src_size < nbytes + MAX_MULTIBYTE_LENGTH) | 628 | if (encode_terminal_src_size - nbytes < MAX_MULTIBYTE_LENGTH) |
| 631 | { | 629 | { |
| 632 | encode_terminal_src_size = nbytes + MAX_MULTIBYTE_LENGTH; | 630 | encode_terminal_src = |
| 633 | encode_terminal_src = xrealloc (encode_terminal_src, | 631 | xpalloc (encode_terminal_src, &encode_terminal_src_size, |
| 634 | encode_terminal_src_size); | 632 | MAX_MULTIBYTE_LENGTH, -1, 1); |
| 635 | buf = encode_terminal_src + nbytes; | 633 | buf = encode_terminal_src + nbytes; |
| 636 | } | 634 | } |
| 637 | if (CHAR_BYTE8_P (c) | 635 | if (CHAR_BYTE8_P (c) |
| @@ -659,11 +657,13 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi | |||
| 659 | if (! STRING_MULTIBYTE (string)) | 657 | if (! STRING_MULTIBYTE (string)) |
| 660 | string = string_to_multibyte (string); | 658 | string = string_to_multibyte (string); |
| 661 | nbytes = buf - encode_terminal_src; | 659 | nbytes = buf - encode_terminal_src; |
| 662 | if (encode_terminal_src_size < nbytes + SBYTES (string)) | 660 | if (encode_terminal_src_size - nbytes < SBYTES (string)) |
| 663 | { | 661 | { |
| 664 | encode_terminal_src_size = nbytes + SBYTES (string); | 662 | encode_terminal_src = |
| 665 | encode_terminal_src = xrealloc (encode_terminal_src, | 663 | xpalloc (encode_terminal_src, &encode_terminal_src_size, |
| 666 | encode_terminal_src_size); | 664 | (SBYTES (string) |
| 665 | - (encode_terminal_src_size - nbytes)), | ||
| 666 | -1, 1); | ||
| 667 | buf = encode_terminal_src + nbytes; | 667 | buf = encode_terminal_src + nbytes; |
| 668 | } | 668 | } |
| 669 | memcpy (buf, SDATA (string), SBYTES (string)); | 669 | memcpy (buf, SDATA (string), SBYTES (string)); |
| @@ -684,12 +684,9 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi | |||
| 684 | coding->source = encode_terminal_src; | 684 | coding->source = encode_terminal_src; |
| 685 | if (encode_terminal_dst_size == 0) | 685 | if (encode_terminal_dst_size == 0) |
| 686 | { | 686 | { |
| 687 | encode_terminal_dst = xrealloc (encode_terminal_dst, | ||
| 688 | encode_terminal_src_size); | ||
| 687 | encode_terminal_dst_size = encode_terminal_src_size; | 689 | encode_terminal_dst_size = encode_terminal_src_size; |
| 688 | if (encode_terminal_dst) | ||
| 689 | encode_terminal_dst = xrealloc (encode_terminal_dst, | ||
| 690 | encode_terminal_dst_size); | ||
| 691 | else | ||
| 692 | encode_terminal_dst = xmalloc (encode_terminal_dst_size); | ||
| 693 | } | 690 | } |
| 694 | coding->destination = encode_terminal_dst; | 691 | coding->destination = encode_terminal_dst; |
| 695 | coding->dst_bytes = encode_terminal_dst_size; | 692 | coding->dst_bytes = encode_terminal_dst_size; |
| @@ -1156,21 +1153,17 @@ calculate_costs (struct frame *frame) | |||
| 1156 | char_ins_del_vector (i.e., char_ins_del_cost) isn't used because | 1153 | char_ins_del_vector (i.e., char_ins_del_cost) isn't used because |
| 1157 | X turns off char_ins_del_ok. */ | 1154 | X turns off char_ins_del_ok. */ |
| 1158 | 1155 | ||
| 1159 | max_frame_lines = max (max_frame_lines, FRAME_LINES (frame)); | ||
| 1160 | max_frame_cols = max (max_frame_cols, FRAME_COLS (frame)); | 1156 | max_frame_cols = max (max_frame_cols, FRAME_COLS (frame)); |
| 1157 | if ((min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) - 1) / 2 | ||
| 1158 | < max_frame_cols) | ||
| 1159 | memory_full (SIZE_MAX); | ||
| 1161 | 1160 | ||
| 1162 | if (char_ins_del_vector != 0) | 1161 | char_ins_del_vector = |
| 1163 | char_ins_del_vector | 1162 | xrealloc (char_ins_del_vector, |
| 1164 | = (int *) xrealloc (char_ins_del_vector, | 1163 | (sizeof (int) + 2 * sizeof (int) * max_frame_cols)); |
| 1165 | (sizeof (int) | ||
| 1166 | + 2 * max_frame_cols * sizeof (int))); | ||
| 1167 | else | ||
| 1168 | char_ins_del_vector | ||
| 1169 | = (int *) xmalloc (sizeof (int) | ||
| 1170 | + 2 * max_frame_cols * sizeof (int)); | ||
| 1171 | 1164 | ||
| 1172 | memset (char_ins_del_vector, 0, | 1165 | memset (char_ins_del_vector, 0, |
| 1173 | (sizeof (int) + 2 * max_frame_cols * sizeof (int))); | 1166 | (sizeof (int) + 2 * sizeof (int) * max_frame_cols)); |
| 1174 | 1167 | ||
| 1175 | 1168 | ||
| 1176 | if (f && (!tty->TS_ins_line && !tty->TS_del_line)) | 1169 | if (f && (!tty->TS_ins_line && !tty->TS_del_line)) |
| @@ -1447,7 +1440,6 @@ term_get_fkeys_1 (void) | |||
| 1447 | Character Display Information | 1440 | Character Display Information |
| 1448 | ***********************************************************************/ | 1441 | ***********************************************************************/ |
| 1449 | static void append_glyph (struct it *); | 1442 | static void append_glyph (struct it *); |
| 1450 | static void produce_stretch_glyph (struct it *); | ||
| 1451 | static void append_composite_glyph (struct it *); | 1443 | static void append_composite_glyph (struct it *); |
| 1452 | static void produce_composite_glyph (struct it *); | 1444 | static void produce_composite_glyph (struct it *); |
| 1453 | static void append_glyphless_glyph (struct it *, int, const char *); | 1445 | static void append_glyphless_glyph (struct it *, int, const char *); |
| @@ -1519,6 +1511,14 @@ append_glyph (struct it *it) | |||
| 1519 | } | 1511 | } |
| 1520 | } | 1512 | } |
| 1521 | 1513 | ||
| 1514 | /* For external use. */ | ||
| 1515 | void | ||
| 1516 | tty_append_glyph (struct it *it) | ||
| 1517 | { | ||
| 1518 | append_glyph (it); | ||
| 1519 | } | ||
| 1520 | |||
| 1521 | |||
| 1522 | /* Produce glyphs for the display element described by IT. *IT | 1522 | /* Produce glyphs for the display element described by IT. *IT |
| 1523 | specifies what we want to produce a glyph for (character, image, ...), | 1523 | specifies what we want to produce a glyph for (character, image, ...), |
| 1524 | and where in the glyph matrix we currently are (glyph row and hpos). | 1524 | and where in the glyph matrix we currently are (glyph row and hpos). |
| @@ -1645,83 +1645,6 @@ produce_glyphs (struct it *it) | |||
| 1645 | it->descent = it->max_descent = it->phys_descent = it->max_phys_descent = 1; | 1645 | it->descent = it->max_descent = it->phys_descent = it->max_phys_descent = 1; |
| 1646 | } | 1646 | } |
| 1647 | 1647 | ||
| 1648 | |||
| 1649 | /* Produce a stretch glyph for iterator IT. IT->object is the value | ||
| 1650 | of the glyph property displayed. The value must be a list | ||
| 1651 | `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs | ||
| 1652 | being recognized: | ||
| 1653 | |||
| 1654 | 1. `:width WIDTH' specifies that the space should be WIDTH * | ||
| 1655 | canonical char width wide. WIDTH may be an integer or floating | ||
| 1656 | point number. | ||
| 1657 | |||
| 1658 | 2. `:align-to HPOS' specifies that the space should be wide enough | ||
| 1659 | to reach HPOS, a value in canonical character units. */ | ||
| 1660 | |||
| 1661 | static void | ||
| 1662 | produce_stretch_glyph (struct it *it) | ||
| 1663 | { | ||
| 1664 | /* (space :width WIDTH ...) */ | ||
| 1665 | Lisp_Object prop, plist; | ||
| 1666 | int width = 0, align_to = -1; | ||
| 1667 | int zero_width_ok_p = 0; | ||
| 1668 | double tem; | ||
| 1669 | |||
| 1670 | /* List should start with `space'. */ | ||
| 1671 | xassert (CONSP (it->object) && EQ (XCAR (it->object), Qspace)); | ||
| 1672 | plist = XCDR (it->object); | ||
| 1673 | |||
| 1674 | /* Compute the width of the stretch. */ | ||
| 1675 | if ((prop = Fplist_get (plist, QCwidth), !NILP (prop)) | ||
| 1676 | && calc_pixel_width_or_height (&tem, it, prop, 0, 1, 0)) | ||
| 1677 | { | ||
| 1678 | /* Absolute width `:width WIDTH' specified and valid. */ | ||
| 1679 | zero_width_ok_p = 1; | ||
| 1680 | width = (int)(tem + 0.5); | ||
| 1681 | } | ||
| 1682 | else if ((prop = Fplist_get (plist, QCalign_to), !NILP (prop)) | ||
| 1683 | && calc_pixel_width_or_height (&tem, it, prop, 0, 1, &align_to)) | ||
| 1684 | { | ||
| 1685 | if (it->glyph_row == NULL || !it->glyph_row->mode_line_p) | ||
| 1686 | align_to = (align_to < 0 | ||
| 1687 | ? 0 | ||
| 1688 | : align_to - window_box_left_offset (it->w, TEXT_AREA)); | ||
| 1689 | else if (align_to < 0) | ||
| 1690 | align_to = window_box_left_offset (it->w, TEXT_AREA); | ||
| 1691 | width = max (0, (int)(tem + 0.5) + align_to - it->current_x); | ||
| 1692 | zero_width_ok_p = 1; | ||
| 1693 | } | ||
| 1694 | else | ||
| 1695 | /* Nothing specified -> width defaults to canonical char width. */ | ||
| 1696 | width = FRAME_COLUMN_WIDTH (it->f); | ||
| 1697 | |||
| 1698 | if (width <= 0 && (width < 0 || !zero_width_ok_p)) | ||
| 1699 | width = 1; | ||
| 1700 | |||
| 1701 | if (width > 0 && it->line_wrap != TRUNCATE | ||
| 1702 | && it->current_x + width > it->last_visible_x) | ||
| 1703 | width = it->last_visible_x - it->current_x - 1; | ||
| 1704 | |||
| 1705 | if (width > 0 && it->glyph_row) | ||
| 1706 | { | ||
| 1707 | Lisp_Object o_object = it->object; | ||
| 1708 | Lisp_Object object = it->stack[it->sp - 1].string; | ||
| 1709 | int n = width; | ||
| 1710 | |||
| 1711 | if (!STRINGP (object)) | ||
| 1712 | object = it->w->buffer; | ||
| 1713 | it->object = object; | ||
| 1714 | it->char_to_display = ' '; | ||
| 1715 | it->pixel_width = it->len = 1; | ||
| 1716 | while (n--) | ||
| 1717 | append_glyph (it); | ||
| 1718 | it->object = o_object; | ||
| 1719 | } | ||
| 1720 | it->pixel_width = width; | ||
| 1721 | it->nglyphs = width; | ||
| 1722 | } | ||
| 1723 | |||
| 1724 | |||
| 1725 | /* Append glyphs to IT's glyph_row for the composition IT->cmp_id. | 1648 | /* Append glyphs to IT's glyph_row for the composition IT->cmp_id. |
| 1726 | Called from produce_composite_glyph for terminal frames if | 1649 | Called from produce_composite_glyph for terminal frames if |
| 1727 | IT->glyph_row != NULL. IT->face_id contains the character's | 1650 | IT->glyph_row != NULL. IT->face_id contains the character's |
| @@ -3145,11 +3068,6 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) | |||
| 3145 | encode_terminal_src_size = 0; | 3068 | encode_terminal_src_size = 0; |
| 3146 | encode_terminal_dst_size = 0; | 3069 | encode_terminal_dst_size = 0; |
| 3147 | 3070 | ||
| 3148 | #ifdef HAVE_GPM | ||
| 3149 | terminal->mouse_position_hook = term_mouse_position; | ||
| 3150 | tty->mouse_highlight.mouse_face_window = Qnil; | ||
| 3151 | #endif | ||
| 3152 | |||
| 3153 | 3071 | ||
| 3154 | #ifndef DOS_NT | 3072 | #ifndef DOS_NT |
| 3155 | set_tty_hooks (terminal); | 3073 | set_tty_hooks (terminal); |
| @@ -3409,6 +3327,11 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ | |||
| 3409 | tty->TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */ | 3327 | tty->TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */ |
| 3410 | #endif /* DOS_NT */ | 3328 | #endif /* DOS_NT */ |
| 3411 | 3329 | ||
| 3330 | #ifdef HAVE_GPM | ||
| 3331 | terminal->mouse_position_hook = term_mouse_position; | ||
| 3332 | tty->mouse_highlight.mouse_face_window = Qnil; | ||
| 3333 | #endif | ||
| 3334 | |||
| 3412 | terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); | 3335 | terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); |
| 3413 | init_kboard (terminal->kboard); | 3336 | init_kboard (terminal->kboard); |
| 3414 | KVAR (terminal->kboard, Vwindow_system) = Qnil; | 3337 | KVAR (terminal->kboard, Vwindow_system) = Qnil; |