diff options
| author | Jim Blandy | 1993-05-04 02:36:03 +0000 |
|---|---|---|
| committer | Jim Blandy | 1993-05-04 02:36:03 +0000 |
| commit | 68936329c2d560a52f59cecfd898a61613380213 (patch) | |
| tree | 0afbb8979756d7a8e13a4c03f8a96d018df3d3c7 /src | |
| parent | 9a76659df20b0425a58d1cf3a0e69c5979fcbe5a (diff) | |
| download | emacs-68936329c2d560a52f59cecfd898a61613380213.tar.gz emacs-68936329c2d560a52f59cecfd898a61613380213.zip | |
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
functions in sysdep.c.
* sysdep.c (emacs_get_tty, emacs_set_tty): Here they are.
* sysdep.c (emacs_set_tty): Call tcsetattr over and over again
until it does all of what we ask it to, or returns an error.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sysdep.c | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 7781e6264b5..c139eed5d8f 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -691,6 +691,144 @@ unrequest_sigio () | |||
| 691 | #endif /* FASYNC */ | 691 | #endif /* FASYNC */ |
| 692 | #endif /* F_SETFL */ | 692 | #endif /* F_SETFL */ |
| 693 | 693 | ||
| 694 | /* Getting and setting emacs_tty structures. */ | ||
| 695 | |||
| 696 | /* Set *TC to the parameters associated with the terminal FD. | ||
| 697 | Return zero if all's well, or -1 if we ran into an error we | ||
| 698 | couldn't deal with. */ | ||
| 699 | int | ||
| 700 | emacs_get_tty (fd, settings) | ||
| 701 | int fd; | ||
| 702 | struct emacs_tty *settings; | ||
| 703 | { | ||
| 704 | /* Retrieve the primary parameters - baud rate, character size, etcetera. */ | ||
| 705 | #ifdef HAVE_TCATTR | ||
| 706 | /* We have those nifty POSIX tcmumbleattr functions. */ | ||
| 707 | if (tcgetattr (fd, &settings->main) < 0) | ||
| 708 | return -1; | ||
| 709 | |||
| 710 | #else | ||
| 711 | #ifdef HAVE_TERMIO | ||
| 712 | /* The SYSV-style interface? */ | ||
| 713 | if (ioctl (fd, TCGETA, &settings->main) < 0) | ||
| 714 | return -1; | ||
| 715 | |||
| 716 | #else | ||
| 717 | #ifdef VMS | ||
| 718 | /* Vehemently Monstrous System? :-) */ | ||
| 719 | if (! (SYS$QIOW (0, fd, IO$_SENSEMODE, settings, 0, 0, | ||
| 720 | &settings->main.class, 12, 0, 0, 0, 0) | ||
| 721 | & 1)) | ||
| 722 | return -1; | ||
| 723 | |||
| 724 | #else | ||
| 725 | /* I give up - I hope you have the BSD ioctls. */ | ||
| 726 | if (ioctl (fd, TIOCGETP, &settings->main) < 0) | ||
| 727 | return -1; | ||
| 728 | |||
| 729 | #endif | ||
| 730 | #endif | ||
| 731 | #endif | ||
| 732 | |||
| 733 | /* Suivant - Do we have to get struct ltchars data? */ | ||
| 734 | #ifdef TIOCGLTC | ||
| 735 | if (ioctl (fd, TIOCGLTC, &settings->ltchars) < 0) | ||
| 736 | return -1; | ||
| 737 | #endif | ||
| 738 | |||
| 739 | /* How about a struct tchars and a wordful of lmode bits? */ | ||
| 740 | #ifdef TIOCGETC | ||
| 741 | if (ioctl (fd, TIOCGETC, &settings->tchars) < 0 | ||
| 742 | || ioctl (fd, TIOCLGET, &settings->lmode) < 0) | ||
| 743 | return -1; | ||
| 744 | #endif | ||
| 745 | |||
| 746 | /* We have survived the tempest. */ | ||
| 747 | return 0; | ||
| 748 | } | ||
| 749 | |||
| 750 | |||
| 751 | /* Set the parameters of the tty on FD according to the contents of | ||
| 752 | *SETTINGS. If WAITP is non-zero, we wait for all queued output to | ||
| 753 | be written before making the change; otherwise, we forget any | ||
| 754 | queued input and make the change immediately. | ||
| 755 | Return 0 if all went well, and -1 if anything failed. */ | ||
| 756 | int | ||
| 757 | emacs_set_tty (fd, settings, waitp) | ||
| 758 | int fd; | ||
| 759 | struct emacs_tty *settings; | ||
| 760 | int waitp; | ||
| 761 | { | ||
| 762 | /* Set the primary parameters - baud rate, character size, etcetera. */ | ||
| 763 | #ifdef HAVE_TCATTR | ||
| 764 | /* We have those nifty POSIX tcmumbleattr functions. | ||
| 765 | William J. Smith <wjs@wiis.wang.com> writes: | ||
| 766 | "POSIX 1003.1 defines tcsetattr() to return success if it was | ||
| 767 | able to perform any of the requested actions, even if some | ||
| 768 | of the requested actions could not be performed. | ||
| 769 | We must read settings back to ensure tty setup properly. | ||
| 770 | AIX requires this to keep tty from hanging occasionally." */ | ||
| 771 | for (;;) | ||
| 772 | if (tcsetattr (fd, waitp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0) | ||
| 773 | { | ||
| 774 | if (errno == EINTR) | ||
| 775 | continue; | ||
| 776 | else | ||
| 777 | return -1; | ||
| 778 | } | ||
| 779 | else | ||
| 780 | { | ||
| 781 | struct termios new; | ||
| 782 | |||
| 783 | /* Get the current settings, and see if they're what we asked for. */ | ||
| 784 | tcgetattr (fd, &new); | ||
| 785 | if (memcmp (&new, &settings->main, sizeof (new))) | ||
| 786 | continue; | ||
| 787 | else | ||
| 788 | break; | ||
| 789 | } | ||
| 790 | |||
| 791 | #else | ||
| 792 | #ifdef HAVE_TERMIO | ||
| 793 | /* The SYSV-style interface? */ | ||
| 794 | if (ioctl (fd, waitp ? TCSETAW : TCSETAF, &settings->main) < 0) | ||
| 795 | return -1; | ||
| 796 | |||
| 797 | #else | ||
| 798 | #ifdef VMS | ||
| 799 | /* Vehemently Monstrous System? :-) */ | ||
| 800 | if (! (SYS$QIOW (0, fd, IO$_SETMODE, &input_iosb, 0, 0, | ||
| 801 | &settings->main.class, 12, 0, 0, 0, 0) | ||
| 802 | & 1)) | ||
| 803 | return -1; | ||
| 804 | |||
| 805 | #else | ||
| 806 | /* I give up - I hope you have the BSD ioctls. */ | ||
| 807 | if (ioctl (fd, (waitp) ? TIOCSETP : TIOCSETN, &settings->main) < 0) | ||
| 808 | return -1; | ||
| 809 | |||
| 810 | #endif | ||
| 811 | #endif | ||
| 812 | #endif | ||
| 813 | |||
| 814 | /* Suivant - Do we have to get struct ltchars data? */ | ||
| 815 | #ifdef TIOCGLTC | ||
| 816 | if (ioctl (fd, TIOCSLTC, &settings->ltchars) < 0) | ||
| 817 | return -1; | ||
| 818 | #endif | ||
| 819 | |||
| 820 | /* How about a struct tchars and a wordful of lmode bits? */ | ||
| 821 | #ifdef TIOCGETC | ||
| 822 | if (ioctl (fd, TIOCSETC, &settings->tchars) < 0 | ||
| 823 | || ioctl (fd, TIOCLSET, &settings->lmode) < 0) | ||
| 824 | return -1; | ||
| 825 | #endif | ||
| 826 | |||
| 827 | /* We have survived the tempest. */ | ||
| 828 | return 0; | ||
| 829 | } | ||
| 830 | |||
| 831 | |||
| 694 | /* The initial tty mode bits */ | 832 | /* The initial tty mode bits */ |
| 695 | struct emacs_tty old_tty; | 833 | struct emacs_tty old_tty; |
| 696 | 834 | ||