9term manages to turn off echo at the right times under SunOS ?

This commit is contained in:
rsc 2004-04-15 02:04:30 +00:00
parent aeb54c0efe
commit 4dcd9af228
9 changed files with 173 additions and 10 deletions

View file

@ -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;
}