aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/9term/SunOS.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-04-16 15:27:29 +0000
committerrsc <devnull@localhost>2004-04-16 15:27:29 +0000
commita2705f207ff006c07c72081897ec4a6ca22ef269 (patch)
tree32babd989cd836072be4bb1ef526340fd0186d82 /src/cmd/9term/SunOS.c
parentaba09191af8012bc7d6a1b998ac937875f728d0c (diff)
downloadplan9port-a2705f207ff006c07c72081897ec4a6ca22ef269.tar.gz
plan9port-a2705f207ff006c07c72081897ec4a6ca22ef269.tar.bz2
plan9port-a2705f207ff006c07c72081897ec4a6ca22ef269.zip
make echoing work.
Diffstat (limited to 'src/cmd/9term/SunOS.c')
-rw-r--r--src/cmd/9term/SunOS.c80
1 files changed, 22 insertions, 58 deletions
diff --git a/src/cmd/9term/SunOS.c b/src/cmd/9term/SunOS.c
index 25228344..efc2a979 100644
--- a/src/cmd/9term/SunOS.c
+++ b/src/cmd/9term/SunOS.c
@@ -4,6 +4,8 @@
#include <libc.h>
#include "term.h"
+#define debug 0
+
int
getpts(int fd[], char *slave)
{
@@ -55,72 +57,34 @@ updatewinsize(int row, int col, int dx, int dy)
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 ;
+ if(tcgetattr(fd, &ttmode) < 0)
+ fprint(2, "tcgetattr: %r\n");
+ if(debug) fprint(2, "israw %c%c\n",
+ ttmode.c_lflag&ICANON ? 'c' : '-',
+ ttmode.c_lflag&ECHO ? 'e' : '-');
+ return !(ttmode.c_lflag&(ICANON|ECHO));
}
-
int
-setecho(int fd, int on)
+setecho(int fd, int newe)
{
- 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);
+ int old;
+
+ if(tcgetattr(fd, &ttmode) < 0)
+ fprint(2, "tcgetattr: %r\n");
+ old = (ttmode.c_lflag&ECHO)==ECHO;
+ if(old != newe){
+ if(newe)
+ ttmode.c_lflag |= ECHO;
+ else
+ ttmode.c_lflag &= ~ECHO;
+ if(tcsetattr(fd, TCSANOW, &ttmode) < 0)
+ fprint(2, "tcsetattr: %r\n");
}
-
- return oldecho;
+ return old;
}
-