comparison src/sysdep.c @ 2656:93eda11d38de

* 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.
author Jim Blandy <jimb@redhat.com>
date Tue, 04 May 1993 02:36:03 +0000
parents 5f41134610a6
children f1cd54cf1b67
comparison
equal deleted inserted replaced
2655:594a33ffed85 2656:93eda11d38de
688 } 688 }
689 689
690 #endif /* STRIDE */ 690 #endif /* STRIDE */
691 #endif /* FASYNC */ 691 #endif /* FASYNC */
692 #endif /* F_SETFL */ 692 #endif /* F_SETFL */
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
693 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
697 int term_initted; /* 1 if outer tty status has been recorded */ 835 int term_initted; /* 1 if outer tty status has been recorded */