diff options
| author | Tom Tromey | 2012-12-17 07:56:22 -0700 |
|---|---|---|
| committer | Tom Tromey | 2012-12-17 07:56:22 -0700 |
| commit | 3d6eced1ae51ffd0a782130e7c334052277e2724 (patch) | |
| tree | 5d1d2ad7cd3374f922886c4a72062511a035c168 /src/term.c | |
| parent | bf69f522a9e135f9aa483cedd53e71e915f2bf75 (diff) | |
| parent | 7c3d167f48d6262ee4e5512aa50a07ee96bc1509 (diff) | |
| download | emacs-3d6eced1ae51ffd0a782130e7c334052277e2724.tar.gz emacs-3d6eced1ae51ffd0a782130e7c334052277e2724.zip | |
merge from trunk
Diffstat (limited to 'src/term.c')
| -rw-r--r-- | src/term.c | 128 |
1 files changed, 42 insertions, 86 deletions
diff --git a/src/term.c b/src/term.c index f1a09b39cf9..241875de52f 100644 --- a/src/term.c +++ b/src/term.c | |||
| @@ -20,17 +20,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 20 | /* New redisplay, TTY faces by Gerd Moellmann <gerd@gnu.org>. */ | 20 | /* New redisplay, TTY faces by Gerd Moellmann <gerd@gnu.org>. */ |
| 21 | 21 | ||
| 22 | #include <config.h> | 22 | #include <config.h> |
| 23 | #include <stdio.h> | ||
| 24 | #include <errno.h> | 23 | #include <errno.h> |
| 24 | #include <fcntl.h> | ||
| 25 | #include <stdio.h> | ||
| 25 | #include <sys/file.h> | 26 | #include <sys/file.h> |
| 26 | #include <sys/time.h> | 27 | #include <sys/time.h> |
| 27 | #include <unistd.h> | 28 | #include <unistd.h> |
| 28 | #include <signal.h> | ||
| 29 | #include <setjmp.h> | ||
| 30 | 29 | ||
| 31 | #include "lisp.h" | 30 | #include "lisp.h" |
| 32 | #include "termchar.h" | 31 | #include "termchar.h" |
| 33 | #include "termopts.h" | ||
| 34 | #include "tparam.h" | 32 | #include "tparam.h" |
| 35 | #include "character.h" | 33 | #include "character.h" |
| 36 | #include "buffer.h" | 34 | #include "buffer.h" |
| @@ -58,17 +56,10 @@ static int been_here = -1; | |||
| 58 | #include "xterm.h" | 56 | #include "xterm.h" |
| 59 | #endif | 57 | #endif |
| 60 | 58 | ||
| 61 | #ifndef O_RDWR | ||
| 62 | #define O_RDWR 2 | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #ifndef O_NOCTTY | ||
| 66 | #define O_NOCTTY 0 | ||
| 67 | #endif | ||
| 68 | |||
| 69 | /* The name of the default console device. */ | 59 | /* The name of the default console device. */ |
| 70 | #ifdef WINDOWSNT | 60 | #ifdef WINDOWSNT |
| 71 | #define DEV_TTY "CONOUT$" | 61 | #define DEV_TTY "CONOUT$" |
| 62 | #include "w32term.h" | ||
| 72 | #else | 63 | #else |
| 73 | #define DEV_TTY "/dev/tty" | 64 | #define DEV_TTY "/dev/tty" |
| 74 | #endif | 65 | #endif |
| @@ -135,10 +126,6 @@ enum no_color_bit | |||
| 135 | 126 | ||
| 136 | static int max_frame_cols; | 127 | static int max_frame_cols; |
| 137 | 128 | ||
| 138 | /* Non-zero if we have dropped our controlling tty and therefore | ||
| 139 | should not open a frame on stdout. */ | ||
| 140 | static int no_controlling_tty; | ||
| 141 | |||
| 142 | 129 | ||
| 143 | 130 | ||
| 144 | #ifdef HAVE_GPM | 131 | #ifdef HAVE_GPM |
| @@ -755,13 +742,13 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len) | |||
| 755 | conversion_buffer = encode_terminal_code (string, n, coding); | 742 | conversion_buffer = encode_terminal_code (string, n, coding); |
| 756 | if (coding->produced > 0) | 743 | if (coding->produced > 0) |
| 757 | { | 744 | { |
| 758 | BLOCK_INPUT; | 745 | block_input (); |
| 759 | fwrite (conversion_buffer, 1, coding->produced, tty->output); | 746 | fwrite (conversion_buffer, 1, coding->produced, tty->output); |
| 760 | if (ferror (tty->output)) | 747 | if (ferror (tty->output)) |
| 761 | clearerr (tty->output); | 748 | clearerr (tty->output); |
| 762 | if (tty->termscript) | 749 | if (tty->termscript) |
| 763 | fwrite (conversion_buffer, 1, coding->produced, tty->termscript); | 750 | fwrite (conversion_buffer, 1, coding->produced, tty->termscript); |
| 764 | UNBLOCK_INPUT; | 751 | unblock_input (); |
| 765 | } | 752 | } |
| 766 | string += n; | 753 | string += n; |
| 767 | 754 | ||
| @@ -816,13 +803,13 @@ tty_write_glyphs_with_face (register struct frame *f, register struct glyph *str | |||
| 816 | conversion_buffer = encode_terminal_code (string, len, coding); | 803 | conversion_buffer = encode_terminal_code (string, len, coding); |
| 817 | if (coding->produced > 0) | 804 | if (coding->produced > 0) |
| 818 | { | 805 | { |
| 819 | BLOCK_INPUT; | 806 | block_input (); |
| 820 | fwrite (conversion_buffer, 1, coding->produced, tty->output); | 807 | fwrite (conversion_buffer, 1, coding->produced, tty->output); |
| 821 | if (ferror (tty->output)) | 808 | if (ferror (tty->output)) |
| 822 | clearerr (tty->output); | 809 | clearerr (tty->output); |
| 823 | if (tty->termscript) | 810 | if (tty->termscript) |
| 824 | fwrite (conversion_buffer, 1, coding->produced, tty->termscript); | 811 | fwrite (conversion_buffer, 1, coding->produced, tty->termscript); |
| 825 | UNBLOCK_INPUT; | 812 | unblock_input (); |
| 826 | } | 813 | } |
| 827 | 814 | ||
| 828 | /* Turn appearance modes off. */ | 815 | /* Turn appearance modes off. */ |
| @@ -902,13 +889,13 @@ tty_insert_glyphs (struct frame *f, struct glyph *start, int len) | |||
| 902 | 889 | ||
| 903 | if (coding->produced > 0) | 890 | if (coding->produced > 0) |
| 904 | { | 891 | { |
| 905 | BLOCK_INPUT; | 892 | block_input (); |
| 906 | fwrite (conversion_buffer, 1, coding->produced, tty->output); | 893 | fwrite (conversion_buffer, 1, coding->produced, tty->output); |
| 907 | if (ferror (tty->output)) | 894 | if (ferror (tty->output)) |
| 908 | clearerr (tty->output); | 895 | clearerr (tty->output); |
| 909 | if (tty->termscript) | 896 | if (tty->termscript) |
| 910 | fwrite (conversion_buffer, 1, coding->produced, tty->termscript); | 897 | fwrite (conversion_buffer, 1, coding->produced, tty->termscript); |
| 911 | UNBLOCK_INPUT; | 898 | unblock_input (); |
| 912 | } | 899 | } |
| 913 | 900 | ||
| 914 | OUTPUT1_IF (tty, tty->TS_pad_inserted_char); | 901 | OUTPUT1_IF (tty, tty->TS_pad_inserted_char); |
| @@ -1498,7 +1485,7 @@ append_glyph (struct it *it) | |||
| 1498 | { | 1485 | { |
| 1499 | glyph->resolved_level = it->bidi_it.resolved_level; | 1486 | glyph->resolved_level = it->bidi_it.resolved_level; |
| 1500 | if ((it->bidi_it.type & 7) != it->bidi_it.type) | 1487 | if ((it->bidi_it.type & 7) != it->bidi_it.type) |
| 1501 | abort (); | 1488 | emacs_abort (); |
| 1502 | glyph->bidi_type = it->bidi_it.type; | 1489 | glyph->bidi_type = it->bidi_it.type; |
| 1503 | } | 1490 | } |
| 1504 | else | 1491 | else |
| @@ -1695,7 +1682,7 @@ append_composite_glyph (struct it *it) | |||
| 1695 | { | 1682 | { |
| 1696 | glyph->resolved_level = it->bidi_it.resolved_level; | 1683 | glyph->resolved_level = it->bidi_it.resolved_level; |
| 1697 | if ((it->bidi_it.type & 7) != it->bidi_it.type) | 1684 | if ((it->bidi_it.type & 7) != it->bidi_it.type) |
| 1698 | abort (); | 1685 | emacs_abort (); |
| 1699 | glyph->bidi_type = it->bidi_it.type; | 1686 | glyph->bidi_type = it->bidi_it.type; |
| 1700 | } | 1687 | } |
| 1701 | else | 1688 | else |
| @@ -1780,7 +1767,7 @@ append_glyphless_glyph (struct it *it, int face_id, const char *str) | |||
| 1780 | { | 1767 | { |
| 1781 | glyph->resolved_level = it->bidi_it.resolved_level; | 1768 | glyph->resolved_level = it->bidi_it.resolved_level; |
| 1782 | if ((it->bidi_it.type & 7) != it->bidi_it.type) | 1769 | if ((it->bidi_it.type & 7) != it->bidi_it.type) |
| 1783 | abort (); | 1770 | emacs_abort (); |
| 1784 | glyph->bidi_type = it->bidi_it.type; | 1771 | glyph->bidi_type = it->bidi_it.type; |
| 1785 | } | 1772 | } |
| 1786 | else | 1773 | else |
| @@ -2250,7 +2237,7 @@ get_named_tty (const char *name) | |||
| 2250 | struct terminal *t; | 2237 | struct terminal *t; |
| 2251 | 2238 | ||
| 2252 | if (!name) | 2239 | if (!name) |
| 2253 | abort (); | 2240 | emacs_abort (); |
| 2254 | 2241 | ||
| 2255 | for (t = terminal_list; t; t = t->next_terminal) | 2242 | for (t = terminal_list; t; t = t->next_terminal) |
| 2256 | { | 2243 | { |
| @@ -2798,7 +2785,7 @@ create_tty_output (struct frame *f) | |||
| 2798 | struct tty_output *t = xzalloc (sizeof *t); | 2785 | struct tty_output *t = xzalloc (sizeof *t); |
| 2799 | 2786 | ||
| 2800 | if (! FRAME_TERMCAP_P (f)) | 2787 | if (! FRAME_TERMCAP_P (f)) |
| 2801 | abort (); | 2788 | emacs_abort (); |
| 2802 | 2789 | ||
| 2803 | t->display_info = FRAME_TERMINAL (f)->display_info.tty; | 2790 | t->display_info = FRAME_TERMINAL (f)->display_info.tty; |
| 2804 | 2791 | ||
| @@ -2811,7 +2798,7 @@ static void | |||
| 2811 | tty_free_frame_resources (struct frame *f) | 2798 | tty_free_frame_resources (struct frame *f) |
| 2812 | { | 2799 | { |
| 2813 | if (! FRAME_TERMCAP_P (f)) | 2800 | if (! FRAME_TERMCAP_P (f)) |
| 2814 | abort (); | 2801 | emacs_abort (); |
| 2815 | 2802 | ||
| 2816 | if (FRAME_FACE_CACHE (f)) | 2803 | if (FRAME_FACE_CACHE (f)) |
| 2817 | free_frame_faces (f); | 2804 | free_frame_faces (f); |
| @@ -2827,7 +2814,7 @@ static void | |||
| 2827 | tty_free_frame_resources (struct frame *f) | 2814 | tty_free_frame_resources (struct frame *f) |
| 2828 | { | 2815 | { |
| 2829 | if (! FRAME_TERMCAP_P (f) && ! FRAME_MSDOS_P (f)) | 2816 | if (! FRAME_TERMCAP_P (f) && ! FRAME_MSDOS_P (f)) |
| 2830 | abort (); | 2817 | emacs_abort (); |
| 2831 | 2818 | ||
| 2832 | if (FRAME_FACE_CACHE (f)) | 2819 | if (FRAME_FACE_CACHE (f)) |
| 2833 | free_frame_faces (f); | 2820 | free_frame_faces (f); |
| @@ -2920,34 +2907,9 @@ set_tty_hooks (struct terminal *terminal) | |||
| 2920 | static void | 2907 | static void |
| 2921 | dissociate_if_controlling_tty (int fd) | 2908 | dissociate_if_controlling_tty (int fd) |
| 2922 | { | 2909 | { |
| 2923 | #ifndef DOS_NT | 2910 | pid_t pgid = tcgetpgrp (fd); /* If tcgetpgrp succeeds, fd is the ctty. */ |
| 2924 | int pgid = tcgetpgrp (fd); /* If tcgetpgrp succeeds, fd is the ctty. */ | 2911 | if (0 <= pgid) |
| 2925 | if (pgid != -1) | 2912 | setsid (); |
| 2926 | { | ||
| 2927 | #if defined (USG5) | ||
| 2928 | setpgrp (); | ||
| 2929 | no_controlling_tty = 1; | ||
| 2930 | #elif defined (CYGWIN) | ||
| 2931 | setsid (); | ||
| 2932 | no_controlling_tty = 1; | ||
| 2933 | #else | ||
| 2934 | #ifdef TIOCNOTTY /* Try BSD ioctls. */ | ||
| 2935 | sigblock (sigmask (SIGTTOU)); | ||
| 2936 | fd = emacs_open (DEV_TTY, O_RDWR, 0); | ||
| 2937 | if (fd != -1 && ioctl (fd, TIOCNOTTY, 0) != -1) | ||
| 2938 | { | ||
| 2939 | no_controlling_tty = 1; | ||
| 2940 | } | ||
| 2941 | if (fd != -1) | ||
| 2942 | emacs_close (fd); | ||
| 2943 | sigunblock (sigmask (SIGTTOU)); | ||
| 2944 | #else | ||
| 2945 | /* Unknown system. */ | ||
| 2946 | croak (); | ||
| 2947 | #endif /* ! TIOCNOTTY */ | ||
| 2948 | #endif /* ! USG */ | ||
| 2949 | } | ||
| 2950 | #endif /* !DOS_NT */ | ||
| 2951 | } | 2913 | } |
| 2952 | 2914 | ||
| 2953 | /* Create a termcap display on the tty device with the given name and | 2915 | /* Create a termcap display on the tty device with the given name and |
| @@ -3020,22 +2982,18 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) | |||
| 3020 | set_tty_hooks (terminal); | 2982 | set_tty_hooks (terminal); |
| 3021 | 2983 | ||
| 3022 | { | 2984 | { |
| 3023 | int fd; | 2985 | /* Open the terminal device. */ |
| 3024 | FILE *file; | 2986 | FILE *file; |
| 3025 | 2987 | ||
| 3026 | #ifdef O_IGNORE_CTTY | 2988 | /* If !ctty, don't recognize it as our controlling terminal, and |
| 3027 | if (!ctty) | 2989 | don't make it the controlling tty if we don't have one now. |
| 3028 | /* Open the terminal device. Don't recognize it as our | 2990 | |
| 3029 | controlling terminal, and don't make it the controlling tty | 2991 | Alas, O_IGNORE_CTTY is a GNU extension that seems to be only |
| 3030 | if we don't have one at the moment. */ | 2992 | defined on Hurd. On other systems, we need to explicitly |
| 3031 | fd = emacs_open (name, O_RDWR | O_IGNORE_CTTY | O_NOCTTY, 0); | 2993 | dissociate ourselves from the controlling tty when we want to |
| 3032 | else | 2994 | open a frame on the same terminal. */ |
| 3033 | #endif /* O_IGNORE_CTTY */ | 2995 | int flags = O_RDWR | O_NOCTTY | (ctty ? 0 : O_IGNORE_CTTY); |
| 3034 | /* Alas, O_IGNORE_CTTY is a GNU extension that seems to be only | 2996 | int fd = emacs_open (name, flags, 0); |
| 3035 | defined on Hurd. On other systems, we need to explicitly | ||
| 3036 | dissociate ourselves from the controlling tty when we want to | ||
| 3037 | open a frame on the same terminal. */ | ||
| 3038 | fd = emacs_open (name, O_RDWR | O_NOCTTY, 0); | ||
| 3039 | 2997 | ||
| 3040 | tty->name = xstrdup (name); | 2998 | tty->name = xstrdup (name); |
| 3041 | terminal->name = xstrdup (name); | 2999 | terminal->name = xstrdup (name); |
| @@ -3054,10 +3012,8 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) | |||
| 3054 | name); | 3012 | name); |
| 3055 | } | 3013 | } |
| 3056 | 3014 | ||
| 3057 | #ifndef O_IGNORE_CTTY | 3015 | if (!O_IGNORE_CTTY && !ctty) |
| 3058 | if (!ctty) | ||
| 3059 | dissociate_if_controlling_tty (fd); | 3016 | dissociate_if_controlling_tty (fd); |
| 3060 | #endif | ||
| 3061 | 3017 | ||
| 3062 | file = fdopen (fd, "w+"); | 3018 | file = fdopen (fd, "w+"); |
| 3063 | tty->input = file; | 3019 | tty->input = file; |
| @@ -3074,9 +3030,14 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) | |||
| 3074 | 3030 | ||
| 3075 | /* On some systems, tgetent tries to access the controlling | 3031 | /* On some systems, tgetent tries to access the controlling |
| 3076 | terminal. */ | 3032 | terminal. */ |
| 3077 | sigblock (sigmask (SIGTTOU)); | 3033 | { |
| 3078 | status = tgetent (tty->termcap_term_buffer, terminal_type); | 3034 | sigset_t blocked; |
| 3079 | sigunblock (sigmask (SIGTTOU)); | 3035 | sigemptyset (&blocked); |
| 3036 | sigaddset (&blocked, SIGTTOU); | ||
| 3037 | pthread_sigmask (SIG_BLOCK, &blocked, 0); | ||
| 3038 | status = tgetent (tty->termcap_term_buffer, terminal_type); | ||
| 3039 | pthread_sigmask (SIG_UNBLOCK, &blocked, 0); | ||
| 3040 | } | ||
| 3080 | 3041 | ||
| 3081 | if (status < 0) | 3042 | if (status < 0) |
| 3082 | { | 3043 | { |
| @@ -3108,7 +3069,7 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ | |||
| 3108 | 3069 | ||
| 3109 | #ifndef TERMINFO | 3070 | #ifndef TERMINFO |
| 3110 | if (strlen (tty->termcap_term_buffer) >= buffer_size) | 3071 | if (strlen (tty->termcap_term_buffer) >= buffer_size) |
| 3111 | abort (); | 3072 | emacs_abort (); |
| 3112 | buffer_size = strlen (tty->termcap_term_buffer); | 3073 | buffer_size = strlen (tty->termcap_term_buffer); |
| 3113 | #endif | 3074 | #endif |
| 3114 | tty->termcap_strings_buffer = area = xmalloc (buffer_size); | 3075 | tty->termcap_strings_buffer = area = xmalloc (buffer_size); |
| @@ -3230,7 +3191,6 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ | |||
| 3230 | FrameCols (tty) = FRAME_COLS (f); | 3191 | FrameCols (tty) = FRAME_COLS (f); |
| 3231 | tty->specified_window = FRAME_LINES (f); | 3192 | tty->specified_window = FRAME_LINES (f); |
| 3232 | 3193 | ||
| 3233 | FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; | ||
| 3234 | FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; | 3194 | FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; |
| 3235 | terminal->char_ins_del_ok = 1; | 3195 | terminal->char_ins_del_ok = 1; |
| 3236 | baud_rate = 19200; | 3196 | baud_rate = 19200; |
| @@ -3402,10 +3362,6 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ | |||
| 3402 | = tty->TS_delete_mode && tty->TS_insert_mode | 3362 | = tty->TS_delete_mode && tty->TS_insert_mode |
| 3403 | && !strcmp (tty->TS_delete_mode, tty->TS_insert_mode); | 3363 | && !strcmp (tty->TS_delete_mode, tty->TS_insert_mode); |
| 3404 | 3364 | ||
| 3405 | tty->se_is_so = (tty->TS_standout_mode | ||
| 3406 | && tty->TS_end_standout_mode | ||
| 3407 | && !strcmp (tty->TS_standout_mode, tty->TS_end_standout_mode)); | ||
| 3408 | |||
| 3409 | UseTabs (tty) = tabs_safe_p (fileno (tty->input)) && TabWidth (tty) == 8; | 3365 | UseTabs (tty) = tabs_safe_p (fileno (tty->input)) && TabWidth (tty) == 8; |
| 3410 | 3366 | ||
| 3411 | terminal->scroll_region_ok | 3367 | terminal->scroll_region_ok |
| @@ -3467,7 +3423,7 @@ maybe_fatal (int must_succeed, struct terminal *terminal, | |||
| 3467 | verror (str1, ap); | 3423 | verror (str1, ap); |
| 3468 | 3424 | ||
| 3469 | va_end (ap); | 3425 | va_end (ap); |
| 3470 | abort (); | 3426 | emacs_abort (); |
| 3471 | } | 3427 | } |
| 3472 | 3428 | ||
| 3473 | void | 3429 | void |
| @@ -3494,7 +3450,7 @@ delete_tty (struct terminal *terminal) | |||
| 3494 | return; | 3450 | return; |
| 3495 | 3451 | ||
| 3496 | if (terminal->type != output_termcap) | 3452 | if (terminal->type != output_termcap) |
| 3497 | abort (); | 3453 | emacs_abort (); |
| 3498 | 3454 | ||
| 3499 | tty = terminal->display_info.tty; | 3455 | tty = terminal->display_info.tty; |
| 3500 | 3456 | ||
| @@ -3508,7 +3464,7 @@ delete_tty (struct terminal *terminal) | |||
| 3508 | 3464 | ||
| 3509 | if (! p) | 3465 | if (! p) |
| 3510 | /* This should not happen. */ | 3466 | /* This should not happen. */ |
| 3511 | abort (); | 3467 | emacs_abort (); |
| 3512 | 3468 | ||
| 3513 | p->next = tty->next; | 3469 | p->next = tty->next; |
| 3514 | tty->next = 0; | 3470 | tty->next = 0; |