changeset 138:b3b67829e001

[project @ 1993-09-29 21:24:21 by jwe] (raw_mode): If termios.h is available, use that terminal driver interface.
author jwe
date Wed, 29 Sep 1993 21:24:21 +0000
parents 5df24be56562
children d80376609fd1
files src/utils.cc
diffstat 1 files changed, 59 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/utils.cc	Wed Sep 29 21:06:27 1993 +0000
+++ b/src/utils.cc	Wed Sep 29 21:24:21 1993 +0000
@@ -59,20 +59,20 @@
 
 #define NLENGTH(dirent) (strlen((dirent)->d_name))
 
-#ifdef HAVE_TERMIO_H
+extern "C"
+{
+#if defined (HAVE_TERMIOS_H)
+#include <termios.h>
+#elif defined (HAVE_TERMIO_H)
 #include <termio.h>
-#else
-#ifdef HAVE_SGTTY_H
+#elif defined (HAVE_SGTTY_H)
 #include <sgtty.h>
 #else
 LOSE! LOSE!
 #endif
-#endif
 
-extern "C"
-{
-  extern int ioctl (int, int, ...);
-  char *tilde_expand (char *s); /* From readline's tilde.c */
+extern int ioctl (int, int, ...);
+char *tilde_expand (char *s); /* From readline's tilde.c */
 }
 
 #include "SLStack.h"
@@ -91,6 +91,10 @@
 #include "unwind-prot.h"
 #include "octave-hist.h"
 
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 1
+#endif
+
 // Top level context (?)
 extern jmp_buf toplevel;
 
@@ -211,23 +215,26 @@
 {
   static int curr_on = 0;
 
-// HACK! HACK!
-
-  int tty_fd = 1;
+  int tty_fd = STDIN_FILENO;
+  if (! isatty (tty_fd))
+    {
+      error ("stdin is not a tty!");
+      return;
+    }
 
   if (on == curr_on)
     return;
 
-#ifdef HAVE_TERMIO_H
+#if defined (HAVE_TERMIOS_H)
   {
-    struct termio s;
-    static struct termio save_term;
+    struct termios s;
+    static struct termios save_term;
 
     if (on)
       {
 // Get terminal modes.
 
-	ioctl(tty_fd, TCGETA, &s);
+	tcgetattr (tty_fd, &s);
 
 // Save modes and set certain variables dependent on modes.
 
@@ -249,10 +256,42 @@
 // Restore saved modes.
 	s = save_term;
       }
-    ioctl(tty_fd, TCSETAW, &s);
+    tcsetattr (tty_fd, TCSAFLUSH, &s);
   }
-#else
-#ifdef HAVE_SGTTY_H
+#elif defined (HAVE_TERMIO_H)
+  {
+    struct termio s;
+    static struct termio save_term;
+
+    if (on)
+      {
+// Get terminal modes.
+
+	ioctl (tty_fd, TCGETA, &s);
+
+// Save modes and set certain variables dependent on modes.
+
+	save_term = s;
+//	ospeed = s.c_cflag & CBAUD;
+//	erase_char = s.c_cc[VERASE];
+//	kill_char = s.c_cc[VKILL];
+
+// Set the modes to the way we want them.
+
+	s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
+	s.c_oflag |=  (OPOST|ONLCR|TAB3);
+	s.c_oflag &= ~(OCRNL|ONOCR|ONLRET);
+	s.c_cc[VMIN] = 1;
+	s.c_cc[VTIME] = 0;
+      }      
+    else
+      {
+// Restore saved modes.
+	s = save_term;
+      }
+    ioctl (tty_fd, TCSETAW, &s);
+  }
+#elif defined (HAVE_SGTTY_H)
   {
     struct sgttyb s;
     static struct sgttyb save_term;
@@ -261,7 +300,7 @@
       {
 // Get terminal modes.
 
-	ioctl(tty_fd, TIOCGETP, &s);
+	ioctl (tty_fd, TIOCGETP, &s);
 
 // Save modes and set certain variables dependent on modes.
 
@@ -280,12 +319,11 @@
 // Restore saved modes.
 	s = save_term;
       }
-    ioctl(tty_fd, TIOCSETN, &s);
+    ioctl (tty_fd, TIOCSETN, &s);
   }
 #else
 LOSE! LOSE!
 #endif
-#endif
 
   curr_on = on;
 }