Commit Diff


commit - 5a82f26e50fbfbb3090b4cf839decf012637a00e
commit + 669250d159e93a6933afa4cd25f410af801515ec
blob - a8351675f4133ce116603c7b1b855a0aceac3eca
blob + 411bcef2dc8dcdafbe7c838331f4b424d064f9e6
--- bin/B
+++ bin/B
@@ -2,7 +2,7 @@
 
 if [ $# -eq 0 ]
 then
-	echo 'usage: B cmd...' 2>&1
+	echo 'usage: B file...' 2>&1
 	exit 1
 fi
 
@@ -10,6 +10,10 @@ if [ "x$DISPLAY" = "x" ]
 then
 	sam="/tmp/.sam.$USER"
 else
+	if [ "$DISPLAY" = ":0" ]
+	then
+		DISPLAY=:0.0
+	fi
 	sam="/tmp/.sam.$USER.$DISPLAY"
 fi
 
blob - 473389a750bee4963700659b89b3b5579270ef11
blob + bdf00302563fdaf86701af962de39c8206b6629b
--- include/bio.h
+++ include/bio.h
@@ -30,7 +30,7 @@ struct	Biobuf
 	int	icount;		/* neg num of bytes at eob */
 	int	ocount;		/* num of bytes at bob */
 	int	rdline;		/* num of bytes after rdline */
-	int	runesize;		/* num of bytes of last getrune */
+	int	runesize;	/* num of bytes of last getrune */
 	int	state;		/* r/w/inactive */
 	int	fid;		/* open file */
 	int	flag;		/* magic if malloc'ed */
@@ -59,6 +59,8 @@ struct	Biobuf
 
 int	Bbuffered(Biobuf*);
 Biobuf*	Bfdopen(int, int);
+int	Bfmtinit(Fmt*, Biobuf*);
+int	Bfmtflush(Fmt*);
 int	Bfildes(Biobuf*);
 int	Bflush(Biobuf*);
 int	Bgetc(Biobuf*);
blob - 1386c1588ba611207c67d7ff54b9d7659125c612
blob + 89b609e0fdd7deb83041f7a3bcfc18b15651bdd3
--- src/cmd/9term/9term.c
+++ src/cmd/9term/9term.c
@@ -108,7 +108,6 @@ threadmain(int argc, char *argv[])
 
 	draw(screen, screen->r, cols[BACK], nil, ZP);
 	geom();
-
 	loop();
 }
 
@@ -118,7 +117,7 @@ hangupnote(void *a, char *msg)
 	if(getpid() != mainpid)
 		noted(NDFLT);
 	if(strcmp(msg, "hangup") == 0 && rcpid != 0){
-		postnote(PNPROC, rcpid, "hangup");
+		postnote(PNGROUP, rcpid, "hangup");
 		noted(NDFLT);
 	}
 	noted(NDFLT);
@@ -206,9 +205,13 @@ doreshape(void)
 	scrdraw();
 }
 
+struct winsize ows;
+
 void
 geom(void)
 {
+	struct winsize ws;
+	Point p;
 	Rectangle r;
 
 	r = screen->r;
@@ -223,6 +226,18 @@ geom(void)
 	t.f->maxtab = maxtab*stringwidth(font, "0");
 	fill();
 	updatesel();
+
+	p = stringsize(font, "0");
+	if(p.x == 0 || p.y == 0)
+		return;
+
+	ws.ws_row = Dy(r)/p.y;
+	ws.ws_col = Dx(r)/p.x;
+	ws.ws_xpixel = Dx(r);
+	ws.ws_ypixel = Dy(r);
+	if(ws.ws_row != ows.ws_row || ws.ws_col != ows.ws_col)
+	if(ioctl(rcfd[0], TIOCSWINSZ, &ws) < 0)
+		fprint(2, "ioctl: %r\n");
 }
 
 void
@@ -422,6 +437,7 @@ void
 key(Rune r)
 {
 	char buf[1];
+	uint sig;
 
 	if(r == 0)
 		return;
@@ -472,12 +488,9 @@ key(Rune r)
 	case 0x7F:	/* DEL: send interrupt */
 		t.qh = t.q0 = t.q1 = t.nr;
 		show(t.q0);
-		buf[0] = 0x7f;
-		if(write(rcfd[1], buf, 1) < 0)
-			exits(0);
-		/* get rc to print prompt */
-//		r = '\n';
-//		paste(&r, 1, 1);
+		sig = 2; /* SIGINT */
+		if(ioctl(rcfd[0], TIOCSIG, &sig) < 0)
+			fprint(2, "sending interrupt: %r\n");
 		break;
 	case 0x08:	/* ^H: erase character */
 	case 0x15:	/* ^U: erase line */
@@ -543,7 +556,10 @@ consready(void)
 	for(i=t.qh; i<t.nr; i++){
 		c = t.r[i];
 		if(c=='\n' || c=='\004')
+{
+fprint(2, "ready %d\n", c);
 			return 1;
+}
 	}
 	return 0;
 }
@@ -561,6 +577,7 @@ consread(void)
 
 		n = sizeof(buf);
 		p = buf;
+		c = 0;
 		while(n >= UTFmax && (t.qh<t.nr || t.nraw > 0)) {
 			if(t.qh == t.nr){
 				width = runetochar(p, &t.raw[0]);
@@ -571,18 +588,17 @@ consread(void)
 			c = *p;
 			p += width;
 			n -= width;
-			if(!rawon && (c == '\n' || c == '\004')) {
-				if(c == '\004')
-					p--;
+			if(!rawon && (c == '\n' || c == '\004'))
 				break;
-			}
 		}
-		if(n < UTFmax && t.qh<t.nr && t.r[t.qh]=='\004')
-			t.qh++;
-		/* put in control-d when doing a zero length write */
-		if(p == buf)
-			*p++ = '\004';
-		if(write(rcfd[1], buf, p-buf) < 0)
+		/* take out control-d when not doing a zero length write */
+		n = p-buf;
+		if(n > 1 && c == '\004')
+{
+fprint(2, "remove 004\n");
+			n--;
+}
+		if(write(rcfd[1], buf, n) < 0)
 			exits(0);
 /*		mallocstats(); */
 	}
@@ -1138,19 +1154,32 @@ rcstart(int fd[2])
 	argv[1] = "-i";
 	argv[2] = 0;
 
-	getpts(fd, slave);
+	/*
+	 * fd0 is slave (tty), fd1 is master (pty)
+	 */
+	fd[0] = fd[1] = -1;
+	if(getpts(fd, slave) < 0)
+		fprint(2, "getpts: %r\n");
+
         switch(pid = fork()) {
 	case 0:
 		putenv("TERM=9term");
 		close(fd[1]);
 		setsid();
+	//	tcsetpgrp(0, pid);
 		sfd = open(slave, ORDWR);
+		fprint(2, "slave %s\n", slave);
+		if(sfd < 0)
+			fprint(2, "open %s: %r\n", slave);
+		if(ioctl(sfd, TIOCSCTTY, 0) < 0)
+			fprint(2, "ioctl TIOCSCTTY: %r\n");
 	//	ioctl(sfd, I_PUSH, "ptem");
 	//	ioctl(sfd, I_PUSH, "ldterm");
 		dup(sfd, 0);
 		dup(sfd, 1);
 		dup(sfd, 2);
 		execvp(argv[0], argv);
+		_exits("oops");
 		break;
 	case -1:
 		fatal("proc failed: %r");
blob - f59977e16fd519e63fe86fb30403f1c5234d8e78
blob + e8b894dc83698fd802a3df51fef6c87a8d32cc60
--- src/cmd/9term/FreeBSD.c
+++ src/cmd/9term/FreeBSD.c
@@ -13,6 +13,5 @@ getchildwd(int pid, char *wdir, int bufn)
 int
 getpts(int fd[], char *slave)
 {
-	openpty(&fd[1], &fd[0], slave, 0, 0);
-	return 0;
+	return openpty(&fd[1], &fd[0], slave, 0, 0);
 }
blob - 0c3076ec4fe810c9f236842fc5c7569bc47b1c14
blob + 1b250ba1143f27c911cda5237b0dec98887fffb0
--- src/cmd/rc/plan9ish.c
+++ src/cmd/rc/plan9ish.c
@@ -392,10 +392,12 @@ void
 notifyf(void *unused0, char *s)
 {
 	int i;
-	for(i=0;syssigname[i];i++) if(strncmp(s, syssigname[i], strlen(syssigname[i]))==0){
-		if(strncmp(s, "sys: ", 5)!=0) interrupted=1;
-		goto Out;
-	}
+	for(i=0;syssigname[i];i++)
+		if(strncmp(s, syssigname[i], strlen(syssigname[i]))==0){
+			if(strncmp(s, "sys: ", 5)!=0) interrupted=1;
+			goto Out;
+		}
+
 	pfmt(err, "rc: note: %s\n", s);
 	noted(NDFLT);
 	return;
@@ -423,7 +425,11 @@ long Write(int fd, char *buf, long cnt)
 }
 long Read(int fd, char *buf, long cnt)
 {
-	return read(fd, buf, cnt);
+	int i;
+
+	i = read(fd, buf, cnt);
+	if(ntrap) dotrap();
+	return i;
 }
 long Seek(int fd, long cnt, long whence)
 {
blob - 4375222281322960243235122f2878bc6790b13d
blob + af2a16c4dc6699d12d1b8a9aacad1b8084b90f21
--- src/lib9/_p9dir.c
+++ src/lib9/_p9dir.c
@@ -10,6 +10,36 @@
 
 #if defined(__FreeBSD__)
 #include <sys/disklabel.h>
+static int diskdev[] = {
+	151,	/* aacd */
+	116,	/* ad */
+	157,	/* ar */
+	118,	/* afd */
+	133,	/* amrd */
+	13,	/* da */
+	102,	/* fla */
+	109,	/* idad */
+	95,	/* md */
+	131,	/* mlxd */
+	168,	/* pst */
+	147,	/* twed */
+	43,	/* vn */
+	3,	/* wd */
+	87,	/* wfd */
+};
+static int
+isdisk(struct stat *st)
+{
+	int i, dev;
+
+	if(!S_ISCHR(st->st_mode))
+		return 0;
+	dev = major(st->st_rdev);
+	for(i=0; i<nelem(diskdev); i++)
+		if(diskdev[i] == dev)
+			return 1;
+	return 0;
+}
 #define _HAVEDISKLABEL
 #endif
 
@@ -108,7 +138,7 @@ _p9dir(struct stat *st, char *name, Dir *d, char **str
 
 		/* fetch real size for disks */
 #ifdef _HAVEDISKLABEL
-		if(S_ISCHR(st->st_mode)){
+		if(isdisk(st)){
 			int fd, n;
 			struct disklabel lab;
 
blob - 1e479fe438af9a85b4b1c493464e7285d5f65c3b
blob + 5aa5c449efbc10d123d6222e15dbd796caca607e
--- src/lib9/dirread.c
+++ src/lib9/dirread.c
@@ -10,7 +10,6 @@ extern int _p9dir(struct stat*, char*, Dir*, char**, c
 static int
 mygetdents(int fd, struct dirent *buf, int n)
 {
-	ssize_t nn;
 	off_t off;
 
 	off = p9seek(fd, 0, 1);
@@ -23,14 +22,8 @@ mygetdents(int fd, struct dirent *buf, int n)
 static int
 mygetdents(int fd, struct dirent *buf, int n)
 {
-	ssize_t nn;
 	long off;
-
-	off = p9seek(fd, 0, 1);
-	nn = getdirentries(fd, (void*)buf, n, &off);
-	if(nn > 0)
-		p9seek(fd, off, 0);
-	return nn;
+	return getdirentries(fd, (void*)buf, n, &off);
 }
 #elif defined(__sun__)
 static int
@@ -38,7 +31,7 @@ mygetdents(int fd, struct dirent *buf, int n)
 {
 	return getdents(fd, (void*)buf, n);
 }
-#endif	
+#endif
 
 static int
 countde(char *p, int n)
blob - 7e3c04f72b58b2c87ca33d0cf58861a8f383d14c
blob + 460eabfe40a1407a1cf68ac3c00879cf7f7c0532
--- src/lib9/notify.c
+++ src/lib9/notify.c
@@ -13,7 +13,7 @@ static int sigs[] = {
 	SIGQUIT,
 	SIGILL,
 	SIGTRAP,
-	SIGABRT,
+/*	SIGABRT,	*/
 #ifdef SIGEMT
 	SIGEMT,
 #endif
@@ -63,16 +63,17 @@ int
 notify(void (*f)(void*, char*))
 {
 	int i;
-	void (*sf)(int);
+	struct sigaction sa;
 
+	memset(&sa, 0, sizeof sa);
 	if(f == nil)
-		sf = SIG_DFL;
+		sa.sa_handler = SIG_DFL;
 	else{
 		notifyf = f;
-		sf = notifysigf;
+		sa.sa_handler = notifysigf;
 	}
 	for(i=0; i<nelem(sigs); i++)
-		signal(sigs[i], sf);
+		sigaction(sigs[i], &sa, 0);
 	return 0;
 }
 
blob - dea346a55c2125e7bbbe53fac960fc917fef5839
blob + 7c9b39e9325fb6d422448fca06aed9a86a23bd1c
--- src/libbio/bcat.c
+++ src/libbio/bcat.c
@@ -22,8 +22,12 @@ main(int argc, char **argv)
 {
 	int i;
 	Biobuf b, *bp;
+	Fmt fmt;
 
 	Binit(&bout, 1, O_WRONLY);
+	Bfmtinit(&fmt, &bout);
+	fmtprint(&fmt, "hello, world\n");
+	Bfmtflush(&fmt);
 
 	if(argc == 1){
 		Binit(&b, 0, O_RDONLY);
blob - 81e71e5ec8a53a1f808e8e17b71b1f307f255761
blob + 2b66605ce5ed5a352c2aac24ae4a51dd5eba944b
--- src/libbio/bprint.c
+++ src/libbio/bprint.c
@@ -4,25 +4,17 @@
 int
 Bprint(Biobuf *bp, char *fmt, ...)
 {
-	va_list	ap;
-	char *ip, *ep, *out;
+	va_list args;
+	Fmt f;
 	int n;
 
-	ep = (char*)bp->ebuf;
-	ip = ep + bp->ocount;
-	va_start(ap, fmt);
-	out = vseprint(ip, ep, fmt, ap);
-	va_end(ap);
-	if(out == 0 || out >= ep-5) {
-		Bflush(bp);
-		ip = ep + bp->ocount;
-		va_start(ap, fmt);
-		out = vseprint(ip, ep, fmt, ap);
-		va_end(ap);
-		if(out >= ep-5)
-			return Beof;
-	}
-	n = out-ip;
-	bp->ocount += n;
+	if(Bfmtinit(&f, bp) < 0)
+		return -1;
+	va_start(args, fmt);
+	f.args = args;
+	n = dofmt(&f, fmt);
+	va_end(args);
+	if(n > 0 && Bfmtflush(&f) < 0)
+		return -1;
 	return n;
 }
blob - 2c64b257214d8305b7d1820c557c0e802c0ac940
blob + e808b17869d586553ccf5db1a90891c9f44a6210
--- src/libbio/mkfile
+++ src/libbio/mkfile
@@ -7,6 +7,7 @@ OFILES=\
 	bbuffered.$O\
 	bfildes.$O\
 	bflush.$O\
+	bfmt.$O\
 	bgetc.$O\
 	bgetd.$O\
 	binit.$O\
@@ -26,6 +27,6 @@ HFILES=\
 
 <$PLAN9/src/mksyslib
 
-bcat: bcat.$O $LIB
-	$CC -o bcat bcat.$O -L$PLAN9/lib -lbio -lfmt -lutf
+bcat: bcat.$O $PLAN9/lib/$LIB
+	$LD -o bcat bcat.$O -lbio -lfmt -lutf