aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/9term/SunOS.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-04-15 02:04:30 +0000
committerrsc <devnull@localhost>2004-04-15 02:04:30 +0000
commit4dcd9af228643d37bb63ab1642c5128b3b30f4bd (patch)
tree5fb7111b84b44aa4da4126f43d2545c45ce0e6e5 /src/cmd/9term/SunOS.c
parentaeb54c0efed03187235820c73b7feef2260951cf (diff)
downloadplan9port-4dcd9af228643d37bb63ab1642c5128b3b30f4bd.tar.gz
plan9port-4dcd9af228643d37bb63ab1642c5128b3b30f4bd.tar.bz2
plan9port-4dcd9af228643d37bb63ab1642c5128b3b30f4bd.zip
9term manages to turn off echo at the right times under SunOS ?
Diffstat (limited to 'src/cmd/9term/SunOS.c')
-rw-r--r--src/cmd/9term/SunOS.c84
1 files changed, 81 insertions, 3 deletions
diff --git a/src/cmd/9term/SunOS.c b/src/cmd/9term/SunOS.c
index d9104ed7..25228344 100644
--- a/src/cmd/9term/SunOS.c
+++ b/src/cmd/9term/SunOS.c
@@ -1,6 +1,6 @@
#include <u.h>
#include <termios.h>
-#include <sys/termios.h>
+#include <stropts.h>
#include <libc.h>
#include "term.h"
@@ -11,8 +11,17 @@ getpts(int fd[], char *slave)
if ((grantpt(fd[1]) < 0) || (unlockpt(fd[1]) < 0))
return -1;
fchmod(fd[1], 0622);
+
strcpy(slave, ptsname(fd[1]));
- fd[0] = open(slave, OREAD);
+
+ fd[0] = open(slave, ORDWR);
+ if(fd[0] < 0)
+ sysfatal("open %s: %r\n", slave);
+
+ /* set up the right streams modules for a tty */
+ ioctl(fd[0], I_PUSH, "ptem"); /* push ptem */
+ ioctl(fd[0], I_PUSH, "ldterm"); /* push ldterm */
+
return 0;
}
@@ -42,7 +51,76 @@ updatewinsize(int row, int col, int dx, int dy)
ws.ws_ypixel = dy;
if(ws.ws_row != ows.ws_row || ws.ws_col != ows.ws_col)
if(ioctl(rcfd, TIOCSWINSZ, &ws) < 0)
- fprint(2, "ioctl: %r\n");
+ fprint(2, "ioctl TIOCSWINSZ: %r\n");
ows = ws;
}
+/*
+ * israw has been inspired by Matty Farrow's 9term.
+ * The code below is probably a gross simplification --
+ * for the few cases tested it seems to be enough.
+ * However, for example, Matty's code also looks at ISIG,
+ * whereas, we do not (yet?). Axel.
+ *
+ *Note: I guess only the get/set terminal mode attribute
+ * code needs to be here; the logic around it could be
+ * elswhere (9term.c) - but if the code below is split,
+ * the question is what a nice interface would be. Axel.
+ */
+
+static struct termios ttmode;
+
+int
+israw(int fd)
+{
+ int e, c, i;
+
+ tcgetattr(fd, &ttmode);
+ c = (ttmode.c_lflag & ICANON) ? 1 : 0;
+ e = (ttmode.c_lflag & ECHO) ? 1 : 0;
+ i = (ttmode.c_lflag & ISIG) ? 1 : 0;
+
+ if(0) fprint(2, "israw: icanon=%d echo=%d isig=%d\n", c, e, i);
+
+ return !c || !e ;
+}
+
+
+int
+setecho(int fd, int on)
+{
+ int e, c, i;
+ int oldecho;
+
+ tcgetattr(fd, &ttmode);
+ c = (ttmode.c_lflag & ICANON) ? 1 : 0;
+ e = (ttmode.c_lflag & ECHO) ? 1 : 0;
+ i = (ttmode.c_lflag & ISIG) ? 1 : 0;
+
+ if(0) fprint(2, "setecho(%d) pre: icanon=%d echo=%d isig=%d\n", on, c, e, i);
+
+ oldecho = e;
+
+ if (oldecho == on)
+ return oldecho;
+
+ if (on) {
+ ttmode.c_lflag |= ECHO;
+ tcsetattr(fd, TCSANOW, &ttmode);
+ } else {
+ ttmode.c_lflag &= ~ECHO;
+ tcsetattr(fd, TCSANOW, &ttmode);
+ }
+
+ if (0){
+ tcgetattr(fd, &ttmode);
+ c = (ttmode.c_lflag & ICANON) ? 1 : 0;
+ e = (ttmode.c_lflag & ECHO) ? 1 : 0;
+ i = (ttmode.c_lflag & ISIG) ? 1 : 0;
+
+ fprint(2, "setecho(%d) post: icanon=%d echo=%d isig=%d\n", on, c, e, i);
+ }
+
+ return oldecho;
+}
+