summaryrefslogtreecommitdiff
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorJim Blandy <jimb@redhat.com>1993-05-04 02:36:03 +0000
committerJim Blandy <jimb@redhat.com>1993-05-04 02:36:03 +0000
commit68936329c2d560a52f59cecfd898a61613380213 (patch)
tree0afbb8979756d7a8e13a4c03f8a96d018df3d3c7 /src/sysdep.c
parent9a76659df20b0425a58d1cf3a0e69c5979fcbe5a (diff)
downloademacs-68936329c2d560a52f59cecfd898a61613380213.tar.gz
* 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/sysdep.c')
-rw-r--r--src/sysdep.c138
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 ()
#endif /* FASYNC */
#endif /* F_SETFL */
+/* Getting and setting emacs_tty structures. */
+
+/* Set *TC to the parameters associated with the terminal FD.
+ Return zero if all's well, or -1 if we ran into an error we
+ couldn't deal with. */
+int
+emacs_get_tty (fd, settings)
+ int fd;
+ struct emacs_tty *settings;
+{
+ /* Retrieve the primary parameters - baud rate, character size, etcetera. */
+#ifdef HAVE_TCATTR
+ /* We have those nifty POSIX tcmumbleattr functions. */
+ if (tcgetattr (fd, &settings->main) < 0)
+ return -1;
+
+#else
+#ifdef HAVE_TERMIO
+ /* The SYSV-style interface? */
+ if (ioctl (fd, TCGETA, &settings->main) < 0)
+ return -1;
+
+#else
+#ifdef VMS
+ /* Vehemently Monstrous System? :-) */
+ if (! (SYS$QIOW (0, fd, IO$_SENSEMODE, settings, 0, 0,
+ &settings->main.class, 12, 0, 0, 0, 0)
+ & 1))
+ return -1;
+
+#else
+ /* I give up - I hope you have the BSD ioctls. */
+ if (ioctl (fd, TIOCGETP, &settings->main) < 0)
+ return -1;
+
+#endif
+#endif
+#endif
+
+ /* Suivant - Do we have to get struct ltchars data? */
+#ifdef TIOCGLTC
+ if (ioctl (fd, TIOCGLTC, &settings->ltchars) < 0)
+ return -1;
+#endif
+
+ /* How about a struct tchars and a wordful of lmode bits? */
+#ifdef TIOCGETC
+ if (ioctl (fd, TIOCGETC, &settings->tchars) < 0
+ || ioctl (fd, TIOCLGET, &settings->lmode) < 0)
+ return -1;
+#endif
+
+ /* We have survived the tempest. */
+ return 0;
+}
+
+
+/* Set the parameters of the tty on FD according to the contents of
+ *SETTINGS. If WAITP is non-zero, we wait for all queued output to
+ be written before making the change; otherwise, we forget any
+ queued input and make the change immediately.
+ Return 0 if all went well, and -1 if anything failed. */
+int
+emacs_set_tty (fd, settings, waitp)
+ int fd;
+ struct emacs_tty *settings;
+ int waitp;
+{
+ /* Set the primary parameters - baud rate, character size, etcetera. */
+#ifdef HAVE_TCATTR
+ /* We have those nifty POSIX tcmumbleattr functions.
+ William J. Smith <wjs@wiis.wang.com> writes:
+ "POSIX 1003.1 defines tcsetattr() to return success if it was
+ able to perform any of the requested actions, even if some
+ of the requested actions could not be performed.
+ We must read settings back to ensure tty setup properly.
+ AIX requires this to keep tty from hanging occasionally." */
+ for (;;)
+ if (tcsetattr (fd, waitp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0)
+ {
+ if (errno == EINTR)
+ continue;
+ else
+ return -1;
+ }
+ else
+ {
+ struct termios new;
+
+ /* Get the current settings, and see if they're what we asked for. */
+ tcgetattr (fd, &new);
+ if (memcmp (&new, &settings->main, sizeof (new)))
+ continue;
+ else
+ break;
+ }
+
+#else
+#ifdef HAVE_TERMIO
+ /* The SYSV-style interface? */
+ if (ioctl (fd, waitp ? TCSETAW : TCSETAF, &settings->main) < 0)
+ return -1;
+
+#else
+#ifdef VMS
+ /* Vehemently Monstrous System? :-) */
+ if (! (SYS$QIOW (0, fd, IO$_SETMODE, &input_iosb, 0, 0,
+ &settings->main.class, 12, 0, 0, 0, 0)
+ & 1))
+ return -1;
+
+#else
+ /* I give up - I hope you have the BSD ioctls. */
+ if (ioctl (fd, (waitp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
+ return -1;
+
+#endif
+#endif
+#endif
+
+ /* Suivant - Do we have to get struct ltchars data? */
+#ifdef TIOCGLTC
+ if (ioctl (fd, TIOCSLTC, &settings->ltchars) < 0)
+ return -1;
+#endif
+
+ /* How about a struct tchars and a wordful of lmode bits? */
+#ifdef TIOCGETC
+ if (ioctl (fd, TIOCSETC, &settings->tchars) < 0
+ || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
+ return -1;
+#endif
+
+ /* We have survived the tempest. */
+ return 0;
+}
+
+
/* The initial tty mode bits */
struct emacs_tty old_tty;