aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKaroly Lorentey2004-01-11 01:18:45 +0000
committerKaroly Lorentey2004-01-11 01:18:45 +0000
commit8f1ce42333b410e736053a7c5cbbf102032c84f2 (patch)
treed0a7fa64f0e9085286fbff86efc45963ee38f1a0 /src
parentb80bf66eabbf9e132e767b1421b2307e8c50afc1 (diff)
downloademacs-8f1ce42333b410e736053a7c5cbbf102032c84f2.tar.gz
emacs-8f1ce42333b410e736053a7c5cbbf102032c84f2.zip
Changed tty input code to use read_socket_hook.
src/keyboard.c (read_avail_input): Removed tty-related code. (tty_read_avail_input): New function. src/keyboard.h (tty_read_avail_input): New prototype. src/term.c (term_init): Set read_socket_hook. Removed bogus baud rate initialization. src/termhooks.h (read_socket_hook): Added display parameter. src/xterm.c (XTread_socket): Added display parameter (unused). git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-51
Diffstat (limited to 'src')
-rw-r--r--src/keyboard.c300
-rw-r--r--src/keyboard.h3
-rw-r--r--src/sysdep.c2
-rw-r--r--src/term.c7
-rw-r--r--src/termhooks.h2
-rw-r--r--src/xterm.c7
6 files changed, 162 insertions, 159 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index d43f660396a..7b9ee4513d5 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -6611,196 +6611,198 @@ read_avail_input (expected)
6611{ 6611{
6612 struct input_event buf[KBD_BUFFER_SIZE]; 6612 struct input_event buf[KBD_BUFFER_SIZE];
6613 register int i; 6613 register int i;
6614 struct display *d;
6614 int nread = 0; 6615 int nread = 0;
6615 6616
6616 for (i = 0; i < KBD_BUFFER_SIZE; i++) 6617 for (i = 0; i < KBD_BUFFER_SIZE; i++)
6617 EVENT_INIT (buf[i]); 6618 EVENT_INIT (buf[i]);
6618 6619
6619 { 6620 for (d = display_list; d; d = d->next_display)
6620 struct display *d; 6621 {
6622 if (d->read_socket_hook)
6623 /* No need for FIONREAD or fcntl; just say don't wait. */
6624 nread = (*d->read_socket_hook) (d, buf, KBD_BUFFER_SIZE, expected);
6621 6625
6622 for (d = display_list; d; d = d->next_display) 6626 if (nread > 0)
6623 { 6627 break;
6624 if (d->read_socket_hook) 6628 }
6625 /* No need for FIONREAD or fcntl; just say don't wait. */
6626 nread = (*d->read_socket_hook) (buf, KBD_BUFFER_SIZE, expected);
6627
6628 if (nread > 0)
6629 break;
6630 }
6631 }
6632 6629
6633 if (nread <= 0 && tty_list) 6630 /* Scan the chars for C-g and store them in kbd_buffer. */
6631 for (i = 0; i < nread; i++)
6634 { 6632 {
6635 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than 6633 kbd_buffer_store_event (&buf[i]);
6636 the kbd_buffer can really hold. That may prevent loss 6634 /* Don't look at input that follows a C-g too closely.
6637 of characters on some systems when input is stuffed at us. */ 6635 This reduces lossage due to autorepeat on C-g. */
6638 unsigned char cbuf[KBD_BUFFER_SIZE - 1]; 6636 if (buf[i].kind == ASCII_KEYSTROKE_EVENT
6639 int n_to_read; 6637 && buf[i].code == quit_char)
6640 struct tty_display_info *tty; 6638 break;
6641 Lisp_Object frame; 6639 }
6642 6640
6641 return nread;
6642}
6643
6644/* This is the tty way of reading available input.
6645
6646 Note that each terminal device has its own `struct display' object,
6647 and so this function is called once for each individual termcap
6648 display. The first parameter indicates which device to read from. */
6649int
6650tty_read_avail_input (struct display *display,
6651 struct input_event *buf,
6652 int numchars, int expected)
6653{
6654 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
6655 the kbd_buffer can really hold. That may prevent loss
6656 of characters on some systems when input is stuffed at us. */
6657 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
6658 int n_to_read, i;
6659 struct tty_display_info *tty = display->display_info.tty;
6660 Lisp_Object frame;
6661 int nread = 0;
6662
6663 if (display->type != output_termcap)
6664 abort ();
6665
6666 /* XXX I think the following code should be moved to separate
6667 functions in system-dependent files. */
6643#ifdef WINDOWSNT 6668#ifdef WINDOWSNT
6644 return 0; 6669 return 0;
6645#else /* not WINDOWSNT */ 6670#else /* not WINDOWSNT */
6646#ifdef MSDOS 6671#ifdef MSDOS
6647 n_to_read = dos_keysns (); 6672 n_to_read = dos_keysns ();
6648 if (n_to_read == 0) 6673 if (n_to_read == 0)
6649 return 0; 6674 return 0;
6650 6675
6651 cbuf[0] = dos_keyread (); 6676 cbuf[0] = dos_keyread ();
6652 nread = 1; 6677 nread = 1;
6653 6678
6654#else /* not MSDOS */ 6679#else /* not MSDOS */
6655 6680
6656 nread = 0; 6681 if (! tty->term_initted)
6657 6682 return 0;
6658 /* Try to read from each available tty, until one succeeds. */
6659 for (tty = tty_list; tty; tty = tty->next) {
6660
6661 if (! tty->term_initted)
6662 continue;
6663 6683
6664 /* Determine how many characters we should *try* to read. */ 6684 /* Determine how many characters we should *try* to read. */
6665#ifdef FIONREAD 6685#ifdef FIONREAD
6666 /* Find out how much input is available. */ 6686 /* Find out how much input is available. */
6667 if (ioctl (fileno (TTY_INPUT (tty)), FIONREAD, &n_to_read) < 0) 6687 if (ioctl (fileno (TTY_INPUT (tty)), FIONREAD, &n_to_read) < 0)
6668 { 6688 {
6669 /* Formerly simply reported no input, but that sometimes led to 6689 if (! noninteractive)
6670 a failure of Emacs to terminate. 6690 {
6671 SIGHUP seems appropriate if we can't reach the terminal. */ 6691 delete_tty (tty); /* XXX I wonder if this is safe here. */
6672 /* ??? Is it really right to send the signal just to this process 6692
6673 rather than to the whole process group? 6693 /* Formerly simply reported no input, but that sometimes led to
6674 Perhaps on systems with FIONREAD Emacs is alone in its group. */ 6694 a failure of Emacs to terminate.
6675 /* It appears to be the case, see narrow_foreground_group. */ 6695 SIGHUP seems appropriate if we can't reach the terminal. */
6676 if (! noninteractive) 6696 /* ??? Is it really right to send the signal just to this process
6677 { 6697 rather than to the whole process group?
6678 if (! tty_list->next) 6698 Perhaps on systems with FIONREAD Emacs is alone in its group. */
6679 kill (getpid (), SIGHUP); /* This was the last terminal. */ 6699 /* It appears to be the case, see narrow_foreground_group. */
6680 else 6700 if (! tty_list->next)
6681 n_to_read = 0; /* XXX tty should be closed here. */ 6701 kill (getpid (), SIGHUP); /* This was the last terminal. */
6682 } 6702 }
6683 else 6703 else
6684 { 6704 {
6685 n_to_read = 0; 6705 n_to_read = 0;
6686 } 6706 }
6687 } 6707 }
6688 if (n_to_read == 0) 6708 if (n_to_read == 0)
6689 continue; 6709 return 0;
6690 if (n_to_read > sizeof cbuf) 6710 if (n_to_read > sizeof cbuf)
6691 n_to_read = sizeof cbuf; 6711 n_to_read = sizeof cbuf;
6692#else /* no FIONREAD */ 6712#else /* no FIONREAD */
6693#if defined (USG) || defined (DGUX) || defined(CYGWIN) 6713#if defined (USG) || defined (DGUX) || defined(CYGWIN)
6694 /* Read some input if available, but don't wait. */ 6714 /* Read some input if available, but don't wait. */
6695 n_to_read = sizeof cbuf; 6715 n_to_read = sizeof cbuf;
6696 fcntl (fileno (TTY_INPUT (tty)), F_SETFL, O_NDELAY); 6716 fcntl (fileno (TTY_INPUT (tty)), F_SETFL, O_NDELAY);
6697#else 6717#else
6698 you lose; 6718 you lose;
6699#endif 6719#endif
6700#endif 6720#endif
6701 6721
6702 /* Now read; for one reason or another, this will not block. 6722 /* Now read; for one reason or another, this will not block.
6703 NREAD is set to the number of chars read. */ 6723 NREAD is set to the number of chars read. */
6704 do 6724 do
6705 { 6725 {
6706 nread = emacs_read (fileno (TTY_INPUT (tty)), cbuf, n_to_read); 6726 nread = emacs_read (fileno (TTY_INPUT (tty)), cbuf, n_to_read);
6707 /* POSIX infers that processes which are not in the session leader's 6727 /* POSIX infers that processes which are not in the session leader's
6708 process group won't get SIGHUP's at logout time. BSDI adheres to 6728 process group won't get SIGHUP's at logout time. BSDI adheres to
6709 this part standard and returns -1 from read (0) with errno==EIO 6729 this part standard and returns -1 from read (0) with errno==EIO
6710 when the control tty is taken away. 6730 when the control tty is taken away.
6711 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */ 6731 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6712 if (nread == -1 && errno == EIO) 6732 if (nread == -1 && errno == EIO)
6713 { 6733 {
6714 if (! tty_list->next) 6734 if (! tty_list->next)
6715 kill (0, SIGHUP); /* This was the last terminal. */ 6735 kill (0, SIGHUP); /* This was the last terminal. */
6716 else 6736 else
6717 delete_tty (tty); /* XXX I wonder if this is safe here. */ 6737 delete_tty (tty); /* XXX I wonder if this is safe here. */
6718 } 6738 }
6719#if defined (AIX) && (! defined (aix386) && defined (_BSD)) 6739#if defined (AIX) && (! defined (aix386) && defined (_BSD))
6720 /* The kernel sometimes fails to deliver SIGHUP for ptys. 6740 /* The kernel sometimes fails to deliver SIGHUP for ptys.
6721 This looks incorrect, but it isn't, because _BSD causes 6741 This looks incorrect, but it isn't, because _BSD causes
6722 O_NDELAY to be defined in fcntl.h as O_NONBLOCK, 6742 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6723 and that causes a value other than 0 when there is no input. */ 6743 and that causes a value other than 0 when there is no input. */
6724 if (nread == 0) 6744 if (nread == 0)
6725 { 6745 {
6726 if (! tty_list->next) 6746 if (! tty_list->next)
6727 kill (0, SIGHUP); /* This was the last terminal. */ 6747 kill (0, SIGHUP); /* This was the last terminal. */
6728 else 6748 else
6729 delete_tty (tty); /* XXX I wonder if this is safe here. */ 6749 delete_tty (tty); /* XXX I wonder if this is safe here. */
6730 } 6750 }
6731#endif 6751#endif
6732 } 6752 }
6733 while ( 6753 while (
6734 /* We used to retry the read if it was interrupted. 6754 /* We used to retry the read if it was interrupted.
6735 But this does the wrong thing when O_NDELAY causes 6755 But this does the wrong thing when O_NDELAY causes
6736 an EAGAIN error. Does anybody know of a situation 6756 an EAGAIN error. Does anybody know of a situation
6737 where a retry is actually needed? */ 6757 where a retry is actually needed? */
6738#if 0 6758#if 0
6739 nread < 0 && (errno == EAGAIN 6759 nread < 0 && (errno == EAGAIN
6740#ifdef EFAULT 6760#ifdef EFAULT
6741 || errno == EFAULT 6761 || errno == EFAULT
6742#endif 6762#endif
6743#ifdef EBADSLT 6763#ifdef EBADSLT
6744 || errno == EBADSLT 6764 || errno == EBADSLT
6745#endif 6765#endif
6746 ) 6766 )
6747#else 6767#else
6748 0 6768 0
6749#endif 6769#endif
6750 ); 6770 );
6751 6771
6752#ifndef FIONREAD 6772#ifndef FIONREAD
6753#if defined (USG) || defined (DGUX) || defined (CYGWIN) 6773#if defined (USG) || defined (DGUX) || defined (CYGWIN)
6754 fcntl (fileno (TTY_INPUT (tty)), F_SETFL, 0); 6774 fcntl (fileno (TTY_INPUT (tty)), F_SETFL, 0);
6755#endif /* USG or DGUX or CYGWIN */ 6775#endif /* USG or DGUX or CYGWIN */
6756#endif /* no FIONREAD */ 6776#endif /* no FIONREAD */
6757 6777
6758 if (nread > 0) 6778 if (nread <= 0)
6759 break; 6779 return nread;
6760 } /* for each tty */ 6780
6761
6762 if (nread <= 0)
6763 return 0;
6764
6765#endif /* not MSDOS */ 6781#endif /* not MSDOS */
6766#endif /* not WINDOWSNT */ 6782#endif /* not WINDOWSNT */
6767 6783
6768 if (!tty) 6784 /* Select the frame corresponding to the active tty. Note that the
6769 abort (); 6785 value of selected_frame is not reliable here, redisplay tends to
6770 6786 temporarily change it. */
6771 /* Select frame corresponding to the active tty. Note that the 6787 frame = tty->top_frame;
6772 value of selected_frame is not reliable here, redisplay tends 6788
6773 to temporarily change it. But tty should always be non-NULL. */
6774 frame = tty->top_frame;
6775
6776 for (i = 0; i < nread; i++)
6777 {
6778 buf[i].kind = ASCII_KEYSTROKE_EVENT;
6779 buf[i].modifiers = 0;
6780 if (tty->meta_key == 1 && (cbuf[i] & 0x80))
6781 buf[i].modifiers = meta_modifier;
6782 if (tty->meta_key != 2)
6783 cbuf[i] &= ~0x80;
6784
6785 buf[i].code = cbuf[i];
6786 buf[i].frame_or_window = frame;
6787 buf[i].arg = Qnil;
6788 }
6789 }
6790
6791 /* Scan the chars for C-g and store them in kbd_buffer. */
6792 for (i = 0; i < nread; i++) 6789 for (i = 0; i < nread; i++)
6793 { 6790 {
6794 kbd_buffer_store_event (&buf[i]); 6791 buf[i].kind = ASCII_KEYSTROKE_EVENT;
6795 /* Don't look at input that follows a C-g too closely. 6792 buf[i].modifiers = 0;
6796 This reduces lossage due to autorepeat on C-g. */ 6793 if (tty->meta_key == 1 && (cbuf[i] & 0x80))
6797 if (buf[i].kind == ASCII_KEYSTROKE_EVENT 6794 buf[i].modifiers = meta_modifier;
6798 && buf[i].code == quit_char) 6795 if (tty->meta_key != 2)
6799 break; 6796 cbuf[i] &= ~0x80;
6797
6798 buf[i].code = cbuf[i];
6799 buf[i].frame_or_window = frame;
6800 buf[i].arg = Qnil;
6800 } 6801 }
6801 6802
6802 return nread; 6803 return nread;
6803} 6804}
6805
6804#endif /* not VMS */ 6806#endif /* not VMS */
6805 6807
6806#ifdef SIGIO /* for entire page */ 6808#ifdef SIGIO /* for entire page */
diff --git a/src/keyboard.h b/src/keyboard.h
index 1144b794dd3..a084efa7791 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -340,5 +340,8 @@ extern void kbd_buffer_store_help_event P_ ((Lisp_Object, Lisp_Object));
340extern Lisp_Object menu_item_eval_property P_ ((Lisp_Object)); 340extern Lisp_Object menu_item_eval_property P_ ((Lisp_Object));
341extern int kbd_buffer_events_waiting P_ ((int)); 341extern int kbd_buffer_events_waiting P_ ((int));
342 342
343extern int tty_read_avail_input P_ ((struct display *,
344 struct input_event *, int, int));
345
343/* arch-tag: 769cbade-1ba9-4950-b886-db265b061aa3 346/* arch-tag: 769cbade-1ba9-4950-b886-db265b061aa3
344 (do not change this comment) */ 347 (do not change this comment) */
diff --git a/src/sysdep.c b/src/sysdep.c
index fbbc20c2e72..c3d9ef80b3e 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2694,6 +2694,8 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2694void 2694void
2695read_input_waiting () 2695read_input_waiting ()
2696{ 2696{
2697 /* XXX This needs to be updated for multi-tty support. Does
2698 anybody need to emulate select these days? */
2697 int nread, i; 2699 int nread, i;
2698 extern int quit_char; 2700 extern int quit_char;
2699 2701
diff --git a/src/term.c b/src/term.c
index 753067430f2..a988b7d92e8 100644
--- a/src/term.c
+++ b/src/term.c
@@ -2273,7 +2273,7 @@ term_init (char *name, char *terminal_type, int must_succeed)
2273 display->redeem_scroll_bar_hook = 0; /* Not needed. */ 2273 display->redeem_scroll_bar_hook = 0; /* Not needed. */
2274 display->judge_scroll_bars_hook = 0; /* Not needed. */ 2274 display->judge_scroll_bars_hook = 0; /* Not needed. */
2275 2275
2276 display->read_socket_hook = 0; /* Not needed. */ 2276 display->read_socket_hook = &tty_read_avail_input; /* keyboard.c */
2277 display->frame_up_to_date_hook = 0; /* Not needed. */ 2277 display->frame_up_to_date_hook = 0; /* Not needed. */
2278 2278
2279 display->delete_frame_hook = &delete_tty_output; 2279 display->delete_frame_hook = &delete_tty_output;
@@ -2707,11 +2707,6 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2707 2707
2708 init_baud_rate (fileno (TTY_INPUT (tty))); 2708 init_baud_rate (fileno (TTY_INPUT (tty)));
2709 2709
2710 /* XXX This condition sounds bogus. */
2711 if (display->read_socket_hook) /* Baudrate is somewhat
2712 meaningless in this case */
2713 baud_rate = 9600;
2714
2715#ifdef AIXHFT 2710#ifdef AIXHFT
2716 /* The HFT system on AIX doesn't optimize for scrolling, so it's 2711 /* The HFT system on AIX doesn't optimize for scrolling, so it's
2717 really ugly at times. */ 2712 really ugly at times. */
diff --git a/src/termhooks.h b/src/termhooks.h
index 7114621b042..7dda9e2ef07 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -473,7 +473,7 @@ struct display
473 473
474 474
475 /* Called to read input events. */ 475 /* Called to read input events. */
476 int (*read_socket_hook) P_ ((struct input_event *, int, int)); 476 int (*read_socket_hook) P_ ((struct display *, struct input_event *, int, int));
477 477
478 /* Called when a frame's display becomes entirely up to date. */ 478 /* Called when a frame's display becomes entirely up to date. */
479 void (*frame_up_to_date_hook) P_ ((struct frame *)); 479 void (*frame_up_to_date_hook) P_ ((struct frame *));
diff --git a/src/xterm.c b/src/xterm.c
index 0de8ce18f0a..f03f99d0246 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -7066,9 +7066,10 @@ x_dispatch_event (event, display)
7066 EXPECTED is nonzero if the caller knows input is available. */ 7066 EXPECTED is nonzero if the caller knows input is available. */
7067 7067
7068static int 7068static int
7069XTread_socket (bufp, numchars, expected) 7069XTread_socket (display, bufp, numchars, expected)
7070 /* register */ struct input_event *bufp; 7070 struct display *display;
7071 /* register */ int numchars; 7071 struct input_event *bufp;
7072 int numchars;
7072 int expected; 7073 int expected;
7073{ 7074{
7074 int count = 0; 7075 int count = 0;