diff options
| author | Joakim Verona | 2012-07-27 02:22:03 +0200 |
|---|---|---|
| committer | Joakim Verona | 2012-07-27 02:22:03 +0200 |
| commit | 5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f (patch) | |
| tree | 5c55f1096a656a9759f0b53a0b5d1a2289bd366f /src/term.c | |
| parent | 0c5c85cf2b350c965bb1ffa5b2d77c2adebc406b (diff) | |
| parent | 562157c814037dcba58a20cd6908a95992c22283 (diff) | |
| download | emacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.tar.gz emacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.zip | |
upstream
Diffstat (limited to 'src/term.c')
| -rw-r--r-- | src/term.c | 125 |
1 files changed, 34 insertions, 91 deletions
diff --git a/src/term.c b/src/term.c index 5f807181199..4d73f896d21 100644 --- a/src/term.c +++ b/src/term.c | |||
| @@ -24,6 +24,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 24 | #include <ctype.h> | 24 | #include <ctype.h> |
| 25 | #include <errno.h> | 25 | #include <errno.h> |
| 26 | #include <sys/file.h> | 26 | #include <sys/file.h> |
| 27 | #include <sys/time.h> | ||
| 27 | #include <unistd.h> | 28 | #include <unistd.h> |
| 28 | #include <signal.h> | 29 | #include <signal.h> |
| 29 | #include <setjmp.h> | 30 | #include <setjmp.h> |
| @@ -85,11 +86,11 @@ static void clear_tty_hooks (struct terminal *terminal); | |||
| 85 | static void set_tty_hooks (struct terminal *terminal); | 86 | static void set_tty_hooks (struct terminal *terminal); |
| 86 | static void dissociate_if_controlling_tty (int fd); | 87 | static void dissociate_if_controlling_tty (int fd); |
| 87 | static void delete_tty (struct terminal *); | 88 | static void delete_tty (struct terminal *); |
| 88 | static void maybe_fatal (int must_succeed, struct terminal *terminal, | 89 | static _Noreturn void maybe_fatal (int must_succeed, struct terminal *terminal, |
| 89 | const char *str1, const char *str2, ...) | 90 | const char *str1, const char *str2, ...) |
| 90 | NO_RETURN ATTRIBUTE_FORMAT_PRINTF (3, 5) ATTRIBUTE_FORMAT_PRINTF (4, 5); | 91 | ATTRIBUTE_FORMAT_PRINTF (3, 5) ATTRIBUTE_FORMAT_PRINTF (4, 5); |
| 91 | static void vfatal (const char *str, va_list ap) | 92 | static _Noreturn void vfatal (const char *str, va_list ap) |
| 92 | NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 0); | 93 | ATTRIBUTE_FORMAT_PRINTF (1, 0); |
| 93 | 94 | ||
| 94 | 95 | ||
| 95 | #define OUTPUT(tty, a) \ | 96 | #define OUTPUT(tty, a) \ |
| @@ -1458,7 +1459,7 @@ append_glyph (struct it *it) | |||
| 1458 | struct glyph *glyph, *end; | 1459 | struct glyph *glyph, *end; |
| 1459 | int i; | 1460 | int i; |
| 1460 | 1461 | ||
| 1461 | xassert (it->glyph_row); | 1462 | eassert (it->glyph_row); |
| 1462 | glyph = (it->glyph_row->glyphs[it->area] | 1463 | glyph = (it->glyph_row->glyphs[it->area] |
| 1463 | + it->glyph_row->used[it->area]); | 1464 | + it->glyph_row->used[it->area]); |
| 1464 | end = it->glyph_row->glyphs[1 + it->area]; | 1465 | end = it->glyph_row->glyphs[1 + it->area]; |
| @@ -1545,7 +1546,7 @@ produce_glyphs (struct it *it) | |||
| 1545 | /* If a hook is installed, let it do the work. */ | 1546 | /* If a hook is installed, let it do the work. */ |
| 1546 | 1547 | ||
| 1547 | /* Nothing but characters are supported on terminal frames. */ | 1548 | /* Nothing but characters are supported on terminal frames. */ |
| 1548 | xassert (it->what == IT_CHARACTER | 1549 | eassert (it->what == IT_CHARACTER |
| 1549 | || it->what == IT_COMPOSITION | 1550 | || it->what == IT_COMPOSITION |
| 1550 | || it->what == IT_STRETCH | 1551 | || it->what == IT_STRETCH |
| 1551 | || it->what == IT_GLYPHLESS); | 1552 | || it->what == IT_GLYPHLESS); |
| @@ -1632,7 +1633,7 @@ produce_glyphs (struct it *it) | |||
| 1632 | { | 1633 | { |
| 1633 | Lisp_Object acronym = lookup_glyphless_char_display (-1, it); | 1634 | Lisp_Object acronym = lookup_glyphless_char_display (-1, it); |
| 1634 | 1635 | ||
| 1635 | xassert (it->what == IT_GLYPHLESS); | 1636 | eassert (it->what == IT_GLYPHLESS); |
| 1636 | produce_glyphless_glyph (it, 1, acronym); | 1637 | produce_glyphless_glyph (it, 1, acronym); |
| 1637 | } | 1638 | } |
| 1638 | } | 1639 | } |
| @@ -1656,7 +1657,7 @@ append_composite_glyph (struct it *it) | |||
| 1656 | { | 1657 | { |
| 1657 | struct glyph *glyph; | 1658 | struct glyph *glyph; |
| 1658 | 1659 | ||
| 1659 | xassert (it->glyph_row); | 1660 | eassert (it->glyph_row); |
| 1660 | glyph = it->glyph_row->glyphs[it->area] + it->glyph_row->used[it->area]; | 1661 | glyph = it->glyph_row->glyphs[it->area] + it->glyph_row->used[it->area]; |
| 1661 | if (glyph < it->glyph_row->glyphs[1 + it->area]) | 1662 | if (glyph < it->glyph_row->glyphs[1 + it->area]) |
| 1662 | { | 1663 | { |
| @@ -1748,7 +1749,7 @@ append_glyphless_glyph (struct it *it, int face_id, const char *str) | |||
| 1748 | struct glyph *glyph, *end; | 1749 | struct glyph *glyph, *end; |
| 1749 | int i; | 1750 | int i; |
| 1750 | 1751 | ||
| 1751 | xassert (it->glyph_row); | 1752 | eassert (it->glyph_row); |
| 1752 | glyph = it->glyph_row->glyphs[it->area] + it->glyph_row->used[it->area]; | 1753 | glyph = it->glyph_row->glyphs[it->area] + it->glyph_row->used[it->area]; |
| 1753 | end = it->glyph_row->glyphs[1 + it->area]; | 1754 | end = it->glyph_row->glyphs[1 + it->area]; |
| 1754 | 1755 | ||
| @@ -1850,8 +1851,7 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym) | |||
| 1850 | len = 1; | 1851 | len = 1; |
| 1851 | else if (len > 4) | 1852 | else if (len > 4) |
| 1852 | len = 4; | 1853 | len = 4; |
| 1853 | sprintf (buf, "[%.*s]", len, str); | 1854 | len = sprintf (buf, "[%.*s]", len, str); |
| 1854 | len += 2; | ||
| 1855 | str = buf; | 1855 | str = buf; |
| 1856 | } | 1856 | } |
| 1857 | else | 1857 | else |
| @@ -1871,7 +1871,7 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym) | |||
| 1871 | } | 1871 | } |
| 1872 | else | 1872 | else |
| 1873 | { | 1873 | { |
| 1874 | xassert (it->glyphless_method == GLYPHLESS_DISPLAY_HEX_CODE); | 1874 | eassert (it->glyphless_method == GLYPHLESS_DISPLAY_HEX_CODE); |
| 1875 | len = (it->c < 0x10000 ? sprintf (buf, "\\u%04X", it->c) | 1875 | len = (it->c < 0x10000 ? sprintf (buf, "\\u%04X", it->c) |
| 1876 | : it->c <= MAX_UNICODE_CHAR ? sprintf (buf, "\\U%06X", it->c) | 1876 | : it->c <= MAX_UNICODE_CHAR ? sprintf (buf, "\\U%06X", it->c) |
| 1877 | : sprintf (buf, "\\x%06X", it->c)); | 1877 | : sprintf (buf, "\\x%06X", it->c)); |
| @@ -1885,67 +1885,6 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym) | |||
| 1885 | append_glyphless_glyph (it, face_id, str); | 1885 | append_glyphless_glyph (it, face_id, str); |
| 1886 | } | 1886 | } |
| 1887 | 1887 | ||
| 1888 | |||
| 1889 | /* Get information about special display element WHAT in an | ||
| 1890 | environment described by IT. WHAT is one of IT_TRUNCATION or | ||
| 1891 | IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a | ||
| 1892 | non-null glyph_row member. This function ensures that fields like | ||
| 1893 | face_id, c, len of IT are left untouched. */ | ||
| 1894 | |||
| 1895 | void | ||
| 1896 | produce_special_glyphs (struct it *it, enum display_element_type what) | ||
| 1897 | { | ||
| 1898 | struct it temp_it; | ||
| 1899 | Lisp_Object gc; | ||
| 1900 | GLYPH glyph; | ||
| 1901 | |||
| 1902 | temp_it = *it; | ||
| 1903 | temp_it.dp = NULL; | ||
| 1904 | temp_it.what = IT_CHARACTER; | ||
| 1905 | temp_it.len = 1; | ||
| 1906 | temp_it.object = make_number (0); | ||
| 1907 | memset (&temp_it.current, 0, sizeof temp_it.current); | ||
| 1908 | |||
| 1909 | if (what == IT_CONTINUATION) | ||
| 1910 | { | ||
| 1911 | /* Continuation glyph. For R2L lines, we mirror it by hand. */ | ||
| 1912 | if (it->bidi_it.paragraph_dir == R2L) | ||
| 1913 | SET_GLYPH_FROM_CHAR (glyph, '/'); | ||
| 1914 | else | ||
| 1915 | SET_GLYPH_FROM_CHAR (glyph, '\\'); | ||
| 1916 | if (it->dp | ||
| 1917 | && (gc = DISP_CONTINUE_GLYPH (it->dp), GLYPH_CODE_P (gc))) | ||
| 1918 | { | ||
| 1919 | /* FIXME: Should we mirror GC for R2L lines? */ | ||
| 1920 | SET_GLYPH_FROM_GLYPH_CODE (glyph, gc); | ||
| 1921 | spec_glyph_lookup_face (XWINDOW (it->window), &glyph); | ||
| 1922 | } | ||
| 1923 | } | ||
| 1924 | else if (what == IT_TRUNCATION) | ||
| 1925 | { | ||
| 1926 | /* Truncation glyph. */ | ||
| 1927 | SET_GLYPH_FROM_CHAR (glyph, '$'); | ||
| 1928 | if (it->dp | ||
| 1929 | && (gc = DISP_TRUNC_GLYPH (it->dp), GLYPH_CODE_P (gc))) | ||
| 1930 | { | ||
| 1931 | /* FIXME: Should we mirror GC for R2L lines? */ | ||
| 1932 | SET_GLYPH_FROM_GLYPH_CODE (glyph, gc); | ||
| 1933 | spec_glyph_lookup_face (XWINDOW (it->window), &glyph); | ||
| 1934 | } | ||
| 1935 | } | ||
| 1936 | else | ||
| 1937 | abort (); | ||
| 1938 | |||
| 1939 | temp_it.c = temp_it.char_to_display = GLYPH_CHAR (glyph); | ||
| 1940 | temp_it.face_id = GLYPH_FACE (glyph); | ||
| 1941 | temp_it.len = CHAR_BYTES (temp_it.c); | ||
| 1942 | |||
| 1943 | produce_glyphs (&temp_it); | ||
| 1944 | it->pixel_width = temp_it.pixel_width; | ||
| 1945 | it->nglyphs = temp_it.pixel_width; | ||
| 1946 | } | ||
| 1947 | |||
| 1948 | |||
| 1949 | 1888 | ||
| 1950 | /*********************************************************************** | 1889 | /*********************************************************************** |
| 1951 | Faces | 1890 | Faces |
| @@ -2067,7 +2006,7 @@ turn_off_face (struct frame *f, int face_id) | |||
| 2067 | struct face *face = FACE_FROM_ID (f, face_id); | 2006 | struct face *face = FACE_FROM_ID (f, face_id); |
| 2068 | struct tty_display_info *tty = FRAME_TTY (f); | 2007 | struct tty_display_info *tty = FRAME_TTY (f); |
| 2069 | 2008 | ||
| 2070 | xassert (face != NULL); | 2009 | eassert (face != NULL); |
| 2071 | 2010 | ||
| 2072 | if (tty->TS_exit_attribute_mode) | 2011 | if (tty->TS_exit_attribute_mode) |
| 2073 | { | 2012 | { |
| @@ -2611,6 +2550,18 @@ term_mouse_movement (FRAME_PTR frame, Gpm_Event *event) | |||
| 2611 | return 0; | 2550 | return 0; |
| 2612 | } | 2551 | } |
| 2613 | 2552 | ||
| 2553 | /* Return the Time that corresponds to T. Wrap around on overflow. */ | ||
| 2554 | static Time | ||
| 2555 | timeval_to_Time (struct timeval const *t) | ||
| 2556 | { | ||
| 2557 | Time s_1000, ms; | ||
| 2558 | |||
| 2559 | s_1000 = t->tv_sec; | ||
| 2560 | s_1000 *= 1000; | ||
| 2561 | ms = t->tv_usec / 1000; | ||
| 2562 | return s_1000 + ms; | ||
| 2563 | } | ||
| 2564 | |||
| 2614 | /* Return the current position of the mouse. | 2565 | /* Return the current position of the mouse. |
| 2615 | 2566 | ||
| 2616 | Set *f to the frame the mouse is in, or zero if the mouse is in no | 2567 | Set *f to the frame the mouse is in, or zero if the mouse is in no |
| @@ -2630,7 +2581,6 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, | |||
| 2630 | Lisp_Object *y, Time *timeptr) | 2581 | Lisp_Object *y, Time *timeptr) |
| 2631 | { | 2582 | { |
| 2632 | struct timeval now; | 2583 | struct timeval now; |
| 2633 | Time sec, usec; | ||
| 2634 | 2584 | ||
| 2635 | *fp = SELECTED_FRAME (); | 2585 | *fp = SELECTED_FRAME (); |
| 2636 | (*fp)->mouse_moved = 0; | 2586 | (*fp)->mouse_moved = 0; |
| @@ -2641,9 +2591,7 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, | |||
| 2641 | XSETINT (*x, last_mouse_x); | 2591 | XSETINT (*x, last_mouse_x); |
| 2642 | XSETINT (*y, last_mouse_y); | 2592 | XSETINT (*y, last_mouse_y); |
| 2643 | gettimeofday(&now, 0); | 2593 | gettimeofday(&now, 0); |
| 2644 | sec = now.tv_sec; | 2594 | *timeptr = timeval_to_Time (&now); |
| 2645 | usec = now.tv_usec; | ||
| 2646 | *timeptr = (sec * 1000) + (usec / 1000); | ||
| 2647 | } | 2595 | } |
| 2648 | 2596 | ||
| 2649 | /* Prepare a mouse-event in *RESULT for placement in the input queue. | 2597 | /* Prepare a mouse-event in *RESULT for placement in the input queue. |
| @@ -2667,7 +2615,7 @@ term_mouse_click (struct input_event *result, Gpm_Event *event, | |||
| 2667 | } | 2615 | } |
| 2668 | } | 2616 | } |
| 2669 | gettimeofday(&now, 0); | 2617 | gettimeofday(&now, 0); |
| 2670 | result->timestamp = (now.tv_sec * 1000) + (now.tv_usec / 1000); | 2618 | result->timestamp = timeval_to_Time (&now); |
| 2671 | 2619 | ||
| 2672 | if (event->type & GPM_UP) | 2620 | if (event->type & GPM_UP) |
| 2673 | result->modifiers = up_modifier; | 2621 | result->modifiers = up_modifier; |
| @@ -2849,14 +2797,11 @@ DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop, Sgpm_mouse_stop, | |||
| 2849 | void | 2797 | void |
| 2850 | create_tty_output (struct frame *f) | 2798 | create_tty_output (struct frame *f) |
| 2851 | { | 2799 | { |
| 2852 | struct tty_output *t; | 2800 | struct tty_output *t = xzalloc (sizeof *t); |
| 2853 | 2801 | ||
| 2854 | if (! FRAME_TERMCAP_P (f)) | 2802 | if (! FRAME_TERMCAP_P (f)) |
| 2855 | abort (); | 2803 | abort (); |
| 2856 | 2804 | ||
| 2857 | t = xmalloc (sizeof (struct tty_output)); | ||
| 2858 | memset (t, 0, sizeof (struct tty_output)); | ||
| 2859 | |||
| 2860 | t->display_info = FRAME_TERMINAL (f)->display_info.tty; | 2805 | t->display_info = FRAME_TERMINAL (f)->display_info.tty; |
| 2861 | 2806 | ||
| 2862 | f->output_data.tty = t; | 2807 | f->output_data.tty = t; |
| @@ -3056,9 +3001,8 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) | |||
| 3056 | been_here = 1; | 3001 | been_here = 1; |
| 3057 | tty = &the_only_display_info; | 3002 | tty = &the_only_display_info; |
| 3058 | #else | 3003 | #else |
| 3059 | tty = (struct tty_display_info *) xmalloc (sizeof (struct tty_display_info)); | 3004 | tty = xzalloc (sizeof *tty); |
| 3060 | #endif | 3005 | #endif |
| 3061 | memset (tty, 0, sizeof (struct tty_display_info)); | ||
| 3062 | tty->next = tty_list; | 3006 | tty->next = tty_list; |
| 3063 | tty_list = tty; | 3007 | tty_list = tty; |
| 3064 | 3008 | ||
| @@ -3066,7 +3010,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) | |||
| 3066 | terminal->display_info.tty = tty; | 3010 | terminal->display_info.tty = tty; |
| 3067 | tty->terminal = terminal; | 3011 | tty->terminal = terminal; |
| 3068 | 3012 | ||
| 3069 | tty->Wcm = (struct cm *) xmalloc (sizeof (struct cm)); | 3013 | tty->Wcm = xmalloc (sizeof *tty->Wcm); |
| 3070 | Wcm_clear (tty); | 3014 | Wcm_clear (tty); |
| 3071 | 3015 | ||
| 3072 | encode_terminal_src_size = 0; | 3016 | encode_terminal_src_size = 0; |
| @@ -3127,7 +3071,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) | |||
| 3127 | 3071 | ||
| 3128 | Wcm_clear (tty); | 3072 | Wcm_clear (tty); |
| 3129 | 3073 | ||
| 3130 | tty->termcap_term_buffer = (char *) xmalloc (buffer_size); | 3074 | tty->termcap_term_buffer = xmalloc (buffer_size); |
| 3131 | 3075 | ||
| 3132 | /* On some systems, tgetent tries to access the controlling | 3076 | /* On some systems, tgetent tries to access the controlling |
| 3133 | terminal. */ | 3077 | terminal. */ |
| @@ -3168,7 +3112,7 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ | |||
| 3168 | abort (); | 3112 | abort (); |
| 3169 | buffer_size = strlen (tty->termcap_term_buffer); | 3113 | buffer_size = strlen (tty->termcap_term_buffer); |
| 3170 | #endif | 3114 | #endif |
| 3171 | tty->termcap_strings_buffer = area = (char *) xmalloc (buffer_size); | 3115 | tty->termcap_strings_buffer = area = xmalloc (buffer_size); |
| 3172 | tty->TS_ins_line = tgetstr ("al", address); | 3116 | tty->TS_ins_line = tgetstr ("al", address); |
| 3173 | tty->TS_ins_multi_lines = tgetstr ("AL", address); | 3117 | tty->TS_ins_multi_lines = tgetstr ("AL", address); |
| 3174 | tty->TS_bell = tgetstr ("bl", address); | 3118 | tty->TS_bell = tgetstr ("bl", address); |
| @@ -3336,7 +3280,7 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ | |||
| 3336 | tty->mouse_highlight.mouse_face_window = Qnil; | 3280 | tty->mouse_highlight.mouse_face_window = Qnil; |
| 3337 | #endif | 3281 | #endif |
| 3338 | 3282 | ||
| 3339 | terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); | 3283 | terminal->kboard = xmalloc (sizeof *terminal->kboard); |
| 3340 | init_kboard (terminal->kboard); | 3284 | init_kboard (terminal->kboard); |
| 3341 | KVAR (terminal->kboard, Vwindow_system) = Qnil; | 3285 | KVAR (terminal->kboard, Vwindow_system) = Qnil; |
| 3342 | terminal->kboard->next_kboard = all_kboards; | 3286 | terminal->kboard->next_kboard = all_kboards; |
| @@ -3596,7 +3540,6 @@ delete_tty (struct terminal *terminal) | |||
| 3596 | xfree (tty->termcap_strings_buffer); | 3540 | xfree (tty->termcap_strings_buffer); |
| 3597 | xfree (tty->termcap_term_buffer); | 3541 | xfree (tty->termcap_term_buffer); |
| 3598 | 3542 | ||
| 3599 | memset (tty, 0, sizeof (struct tty_display_info)); | ||
| 3600 | xfree (tty); | 3543 | xfree (tty); |
| 3601 | } | 3544 | } |
| 3602 | 3545 | ||