8ed18b6667
scheme while I'm at it.
201 lines
4.2 KiB
Plaintext
201 lines
4.2 KiB
Plaintext
$OpenBSD: patch-icb_unix_c,v 1.1 2001/05/14 16:42:54 millert Exp $
|
|
--- icb/unix.c.orig Fri Feb 24 14:20:31 1995
|
|
+++ icb/unix.c Mon May 14 10:33:04 2001
|
|
@@ -9,11 +9,35 @@
|
|
#include "externs.h"
|
|
#include <pwd.h>
|
|
#include <sys/dir.h>
|
|
+#include <sys/types.h>
|
|
+#include <sys/stat.h>
|
|
+#include <unistd.h>
|
|
|
|
#undef stty
|
|
#undef gtty
|
|
|
|
-#ifndef SYSV
|
|
+#ifdef SYSV
|
|
+
|
|
+#define USE_TERMIO
|
|
+#include <termio.h>
|
|
+#define TTYSTRUCT termio
|
|
+#define stty(fd,buf) ioctl((fd),TCSETA,(buf))
|
|
+#define gtty(fd,buf) ioctl((fd),TCGETA,(buf))
|
|
+
|
|
+#else /* SYSV */
|
|
+
|
|
+# ifdef BSD4_4
|
|
+# define USE_TERMIO
|
|
+# include <termios.h>
|
|
+# define TTYSTRUCT termios
|
|
+# define stty(fd,buf) ioctl((fd),TIOCSETA,(buf))
|
|
+# define gtty(fd,buf) ioctl((fd),TIOCGETA,(buf))
|
|
+
|
|
+# endif /* BSD4_4 */
|
|
+
|
|
+#endif /* SYSV */
|
|
+
|
|
+#ifndef USE_TERMIO /* neither case above (SYSV or BSD4_4) */
|
|
|
|
#ifdef linux
|
|
#include <bsd/sgtty.h>
|
|
@@ -22,18 +46,15 @@
|
|
#endif
|
|
|
|
#define TTYSTRUCT sgttyb
|
|
-#define stty(fd,buf) ioctl((fd),TIOCSETN,(buf))
|
|
+#define stty(fd,buf) ioctl((fd),TIOCSETP,(buf))
|
|
#define gtty(fd,buf) ioctl((fd),TIOCGETP,(buf))
|
|
-#else /* SYSV */
|
|
-#include <termio.h>
|
|
-#define TTYSTRUCT termio
|
|
-#define stty(fd,buf) ioctl((fd),TCSETA,(buf))
|
|
-#define gtty(fd,buf) ioctl((fd),TCGETA,(buf))
|
|
-#endif /* SYSV */
|
|
+#endif
|
|
|
|
char *getlogin();
|
|
|
|
struct TTYSTRUCT origtty; /* holds the user's original term settings */
|
|
+struct stat origtty_stats; /* holds termainal stats */
|
|
+char *mytty = NULL; /* holds terminal name */
|
|
|
|
int badttyinfo = 0; /* used when running under some weird modes */
|
|
|
|
@@ -79,13 +100,13 @@ FILE *fp;
|
|
pushback(c)
|
|
char c;
|
|
{
|
|
-#ifndef SYSV
|
|
+#ifndef USE_TERMIO
|
|
if (ioctl(0, TIOCSTI, &c) < 0)
|
|
perror("TIOCSTI ioctl failed");
|
|
-#else /* SYSV */
|
|
+#else /* USE_TERMIO */
|
|
if (ungetc(c,stdin) == EOF)
|
|
perror("ungetc() failed");
|
|
-#endif /* SYSV */
|
|
+#endif /* USE_TERMIO */
|
|
}
|
|
|
|
|
|
@@ -94,25 +115,30 @@ char c;
|
|
|
|
getterm()
|
|
{
|
|
-#ifndef SYSV
|
|
+ /* get terminal stats */
|
|
+ if ((mytty = ttyname(STDERR_FILENO))) {
|
|
+ if (stat(mytty, &origtty_stats)) mytty = NULL;
|
|
+ }
|
|
+
|
|
+#ifndef USE_TERMIO
|
|
struct ltchars lt;
|
|
-#endif /* SYSV */
|
|
+#endif /* USE_TERMIO */
|
|
/* get tty settings */
|
|
if (gtty(0,&origtty) < 0) {
|
|
badttyinfo++;
|
|
ttyinfo.erase = '\b'; /* ^H */
|
|
ttyinfo.kill = '\025'; /* ^U */
|
|
} else {
|
|
-#ifndef SYSV
|
|
+#ifndef USE_TERMIO
|
|
ttyinfo.erase = origtty.sg_erase;
|
|
ttyinfo.kill = origtty.sg_kill;
|
|
-#else /* SYSV */
|
|
+#else /* USE_TERMIO */
|
|
ttyinfo.erase = origtty.c_cc[VERASE];
|
|
ttyinfo.kill = origtty.c_cc[VKILL];
|
|
-#endif /* SYSV */
|
|
+#endif /* USE_TERMIO */
|
|
}
|
|
|
|
-#ifndef SYSV
|
|
+#ifndef USE_TERMIO
|
|
/* get local special chars */
|
|
if (ioctl(0, TIOCGLTC, <) < 0) {
|
|
ttyinfo.redraw = '\022'; /* ^R */
|
|
@@ -121,10 +147,10 @@ getterm()
|
|
ttyinfo.redraw = lt.t_rprntc;
|
|
ttyinfo.werase = lt.t_werasc;
|
|
}
|
|
-#else /* SYSV */
|
|
+#else /* USE_TERMIO */
|
|
ttyinfo.redraw = '\022'; /* ^R */
|
|
ttyinfo.werase = '\027'; /* ^W */
|
|
-#endif /* SYSV */
|
|
+#endif /* USE_TERMIO */
|
|
|
|
/* get the current window size */
|
|
getwinsize();
|
|
@@ -138,21 +164,24 @@ icbterm()
|
|
{
|
|
struct TTYSTRUCT tty;
|
|
|
|
+ /* disable biff/mesg */
|
|
+ if (mytty)
|
|
+ chmod(mytty, origtty_stats.st_mode & ~(S_IXUSR | S_IWGRP));
|
|
+
|
|
if (badttyinfo)
|
|
return;
|
|
|
|
-
|
|
bcopy((char *)&origtty, (char *)&tty, (unsigned)sizeof(struct TTYSTRUCT));
|
|
|
|
/* turn on cbreak - turn off echo */
|
|
-#ifndef SYSV
|
|
+#ifndef USE_TERMIO
|
|
tty.sg_flags |= CBREAK;
|
|
tty.sg_flags &= ~ECHO;
|
|
-#else /* SYSV */
|
|
+#else /* USE_TERMIO */
|
|
tty.c_lflag &= ~ICANON;
|
|
tty.c_cc[VEOF] = 1;
|
|
tty.c_lflag &= ~ECHO;
|
|
-#endif /* SYSV */
|
|
+#endif /* USE_TERMIO */
|
|
|
|
echomode = 0;
|
|
/* set the new flags */
|
|
@@ -167,6 +196,10 @@ icbterm()
|
|
|
|
restoreterm()
|
|
{
|
|
+ /* restore terminal stats */
|
|
+ if (mytty)
|
|
+ chmod(mytty, origtty_stats.st_mode);
|
|
+
|
|
if (badttyinfo)
|
|
return;
|
|
|
|
@@ -258,11 +291,11 @@ echo()
|
|
}
|
|
|
|
/* turn on echo */
|
|
-#ifndef SYSV
|
|
+#ifndef USE_TERMIO
|
|
tty.sg_flags |= ECHO;
|
|
-#else /* SYSV */
|
|
+#else /* USE_TERMIO */
|
|
tty.c_lflag |= ECHO;
|
|
-#endif /* SYSV */
|
|
+#endif /* USE_TERMIO */
|
|
|
|
echomode = 1;
|
|
|
|
@@ -287,11 +320,11 @@ noecho()
|
|
}
|
|
|
|
/* turn off echo */
|
|
-#ifndef SYSV
|
|
+#ifndef USE_TERMIO
|
|
tty.sg_flags &= ~ECHO;
|
|
-#else /* SYSV */
|
|
+#else /* USE_TERMIO */
|
|
tty.c_lflag &= ~ECHO;
|
|
-#endif /* SYSV */
|
|
+#endif /* USE_TERMIO */
|
|
|
|
echomode = 0;
|
|
|