Browse Source

Plan 9 from Bell Labs 2005-12-06

David du Colombier 15 years ago
parent
commit
a81b2c672e

+ 13 - 13
dist/replica/_plan9.db

@@ -19,7 +19,7 @@
 386/bin/8l - 775 sys sys 1130384229 115712
 386/bin/9660srv - 775 sys sys 1130594690 104069
 386/bin/aan - 775 sys sys 1130594690 130742
-386/bin/acid - 775 sys sys 1132950492 400336
+386/bin/acid - 775 sys sys 1133814393 400982
 386/bin/acme - 775 sys sys 1133287400 429175
 386/bin/ape - 20000000775 sys sys 1016944144 0
 386/bin/ape/basename - 775 sys sys 1127360557 132862
@@ -404,8 +404,8 @@
 386/bin/srv - 775 sys sys 1132418764 82481
 386/bin/srvfs - 775 sys sys 1130384335 40083
 386/bin/srvold9p - 775 sys sys 1130594785 130225
-386/bin/ssh - 775 sys sys 1132506875 211313
-386/bin/sshnet - 775 sys sys 1133186785 283394
+386/bin/ssh - 775 sys sys 1133827764 211090
+386/bin/sshnet - 775 sys sys 1133820584 283148
 386/bin/stats - 775 sys sys 1132418765 190670
 386/bin/strings - 775 sys sys 1130594787 62147
 386/bin/strip - 775 sys sys 1131296676 80766
@@ -498,7 +498,7 @@
 386/bin/venti/write - 775 sys sys 1132506889 102575
 386/bin/vncs - 775 sys sys 1132506890 472364
 386/bin/vncv - 775 sys sys 1132506891 519422
-386/bin/vt - 775 sys sys 1133468806 178593
+386/bin/vt - 775 sys sys 1133820585 176212
 386/bin/vtdump - 775 sys sys 1132506892 159534
 386/bin/wc - 775 sys sys 1130384372 41174
 386/bin/webcookies - 775 sys sys 1133186787 161970
@@ -7379,7 +7379,7 @@ sys/man/1/uptime - 664 sys sys 1074733782 380
 sys/man/1/vac - 664 sys sys 1021579977 3227
 sys/man/1/vi - 664 sys sys 1101668051 2904
 sys/man/1/vnc - 664 sys sys 1045501432 4186
-sys/man/1/vt - 664 sys sys 1018386774 2210
+sys/man/1/vt - 664 sys sys 1133804098 2472
 sys/man/1/wc - 664 sys sys 1113743327 908
 sys/man/1/who - 664 sys sys 944959674 332
 sys/man/1/winwatch - 664 sys sys 1113252108 723
@@ -9268,7 +9268,7 @@ sys/src/cmd/9nfs/xfile.c - 664 sys sys 1131293680 1894
 sys/src/cmd/aan.c - 664 sys sys 1019856827 9758
 sys/src/cmd/acid - 20000000775 sys sys 944960739 0
 sys/src/cmd/acid/acid.h - 664 sys sys 1131289460 4273
-sys/src/cmd/acid/builtin.c - 664 sys sys 1131289462 20193
+sys/src/cmd/acid/builtin.c - 664 sys sys 1133802425 20958
 sys/src/cmd/acid/dbg.y - 664 sys sys 1131289463 5568
 sys/src/cmd/acid/dot.c - 664 sys sys 1131289462 2162
 sys/src/cmd/acid/exec.c - 664 sys sys 1132674180 8383
@@ -12916,13 +12916,13 @@ sys/src/cmd/ssh/cipherdes.c - 664 sys sys 1016466379 567
 sys/src/cmd/ssh/ciphernone.c - 664 sys sys 1016466379 317
 sys/src/cmd/ssh/cipherrc4.c - 664 sys sys 1016466379 674
 sys/src/cmd/ssh/ciphertwiddle.c - 664 sys sys 1016466379 380
-sys/src/cmd/ssh/cmsg.c - 664 sys sys 1071095546 8351
+sys/src/cmd/ssh/cmsg.c - 664 sys sys 1133814916 7906
 sys/src/cmd/ssh/mkfile - 664 sys sys 1048179592 1045
 sys/src/cmd/ssh/msg.c - 664 sys sys 1092516579 8102
 sys/src/cmd/ssh/pubkey.c - 664 sys sys 1019928902 3974
 sys/src/cmd/ssh/scp.c - 664 sys sys 1094156297 13889
 sys/src/cmd/ssh/smsg.c - 664 sys sys 1092516575 6374
-sys/src/cmd/ssh/ssh.c - 664 sys sys 1121977164 9671
+sys/src/cmd/ssh/ssh.c - 664 sys sys 1133821217 9671
 sys/src/cmd/ssh/ssh.h - 664 sys sys 1091904420 6086
 sys/src/cmd/ssh/sshnet.c - 664 sys sys 1078840016 17641
 sys/src/cmd/ssh/sshserve.c - 664 sys sys 1062091020 5786
@@ -13629,15 +13629,15 @@ sys/src/cmd/vnc/vncv.c - 664 sys sys 1082221235 3197
 sys/src/cmd/vnc/vncv.h - 664 sys sys 1044880750 643
 sys/src/cmd/vnc/wsys.c - 664 sys sys 1102429521 4052
 sys/src/cmd/vt - 20000000775 sys sys 954038635 0
-sys/src/cmd/vt/cons.h - 664 sys sys 1133463638 1776
+sys/src/cmd/vt/cons.h - 664 sys sys 1133808292 1792
 sys/src/cmd/vt/consctl.c - 664 sys sys 1127425716 1796
-sys/src/cmd/vt/event.c - 664 sys sys 1133463638 1245
+sys/src/cmd/vt/event.c - 664 sys sys 1133808292 1071
 sys/src/cmd/vt/event.h - 664 sys sys 944961620 192
-sys/src/cmd/vt/hp.c - 664 sys sys 1133463638 3361
-sys/src/cmd/vt/main.c - 664 sys sys 1133463639 16737
+sys/src/cmd/vt/hp.c - 664 sys sys 1133808292 3362
+sys/src/cmd/vt/main.c - 664 sys sys 1133814920 14466
 sys/src/cmd/vt/mkfile - 664 sys sys 944961620 159
 sys/src/cmd/vt/termcap - 664 sys sys 944961620 278
-sys/src/cmd/vt/vt.c - 664 sys sys 1133463639 20180
+sys/src/cmd/vt/vt.c - 664 sys sys 1133808291 19606
 sys/src/cmd/wc.c - 664 sys sys 984717764 12652
 sys/src/cmd/webcookies.c - 664 sys sys 1132449468 23687
 sys/src/cmd/webfs - 20000000775 sys sys 1015015823 0

+ 13 - 13
dist/replica/plan9.db

@@ -19,7 +19,7 @@
 386/bin/8l - 775 sys sys 1130384229 115712
 386/bin/9660srv - 775 sys sys 1130594690 104069
 386/bin/aan - 775 sys sys 1130594690 130742
-386/bin/acid - 775 sys sys 1132950492 400336
+386/bin/acid - 775 sys sys 1133814393 400982
 386/bin/acme - 775 sys sys 1133287400 429175
 386/bin/ape - 20000000775 sys sys 1016944144 0
 386/bin/ape/basename - 775 sys sys 1127360557 132862
@@ -404,8 +404,8 @@
 386/bin/srv - 775 sys sys 1132418764 82481
 386/bin/srvfs - 775 sys sys 1130384335 40083
 386/bin/srvold9p - 775 sys sys 1130594785 130225
-386/bin/ssh - 775 sys sys 1132506875 211313
-386/bin/sshnet - 775 sys sys 1133186785 283394
+386/bin/ssh - 775 sys sys 1133827764 211090
+386/bin/sshnet - 775 sys sys 1133820584 283148
 386/bin/stats - 775 sys sys 1132418765 190670
 386/bin/strings - 775 sys sys 1130594787 62147
 386/bin/strip - 775 sys sys 1131296676 80766
@@ -498,7 +498,7 @@
 386/bin/venti/write - 775 sys sys 1132506889 102575
 386/bin/vncs - 775 sys sys 1132506890 472364
 386/bin/vncv - 775 sys sys 1132506891 519422
-386/bin/vt - 775 sys sys 1133468806 178593
+386/bin/vt - 775 sys sys 1133820585 176212
 386/bin/vtdump - 775 sys sys 1132506892 159534
 386/bin/wc - 775 sys sys 1130384372 41174
 386/bin/webcookies - 775 sys sys 1133186787 161970
@@ -7379,7 +7379,7 @@ sys/man/1/uptime - 664 sys sys 1074733782 380
 sys/man/1/vac - 664 sys sys 1021579977 3227
 sys/man/1/vi - 664 sys sys 1101668051 2904
 sys/man/1/vnc - 664 sys sys 1045501432 4186
-sys/man/1/vt - 664 sys sys 1018386774 2210
+sys/man/1/vt - 664 sys sys 1133804098 2472
 sys/man/1/wc - 664 sys sys 1113743327 908
 sys/man/1/who - 664 sys sys 944959674 332
 sys/man/1/winwatch - 664 sys sys 1113252108 723
@@ -9268,7 +9268,7 @@ sys/src/cmd/9nfs/xfile.c - 664 sys sys 1131293680 1894
 sys/src/cmd/aan.c - 664 sys sys 1019856827 9758
 sys/src/cmd/acid - 20000000775 sys sys 944960739 0
 sys/src/cmd/acid/acid.h - 664 sys sys 1131289460 4273
-sys/src/cmd/acid/builtin.c - 664 sys sys 1131289462 20193
+sys/src/cmd/acid/builtin.c - 664 sys sys 1133802425 20958
 sys/src/cmd/acid/dbg.y - 664 sys sys 1131289463 5568
 sys/src/cmd/acid/dot.c - 664 sys sys 1131289462 2162
 sys/src/cmd/acid/exec.c - 664 sys sys 1132674180 8383
@@ -12916,13 +12916,13 @@ sys/src/cmd/ssh/cipherdes.c - 664 sys sys 1016466379 567
 sys/src/cmd/ssh/ciphernone.c - 664 sys sys 1016466379 317
 sys/src/cmd/ssh/cipherrc4.c - 664 sys sys 1016466379 674
 sys/src/cmd/ssh/ciphertwiddle.c - 664 sys sys 1016466379 380
-sys/src/cmd/ssh/cmsg.c - 664 sys sys 1071095546 8351
+sys/src/cmd/ssh/cmsg.c - 664 sys sys 1133814916 7906
 sys/src/cmd/ssh/mkfile - 664 sys sys 1048179592 1045
 sys/src/cmd/ssh/msg.c - 664 sys sys 1092516579 8102
 sys/src/cmd/ssh/pubkey.c - 664 sys sys 1019928902 3974
 sys/src/cmd/ssh/scp.c - 664 sys sys 1094156297 13889
 sys/src/cmd/ssh/smsg.c - 664 sys sys 1092516575 6374
-sys/src/cmd/ssh/ssh.c - 664 sys sys 1121977164 9671
+sys/src/cmd/ssh/ssh.c - 664 sys sys 1133821217 9671
 sys/src/cmd/ssh/ssh.h - 664 sys sys 1091904420 6086
 sys/src/cmd/ssh/sshnet.c - 664 sys sys 1078840016 17641
 sys/src/cmd/ssh/sshserve.c - 664 sys sys 1062091020 5786
@@ -13629,15 +13629,15 @@ sys/src/cmd/vnc/vncv.c - 664 sys sys 1082221235 3197
 sys/src/cmd/vnc/vncv.h - 664 sys sys 1044880750 643
 sys/src/cmd/vnc/wsys.c - 664 sys sys 1102429521 4052
 sys/src/cmd/vt - 20000000775 sys sys 954038635 0
-sys/src/cmd/vt/cons.h - 664 sys sys 1133463638 1776
+sys/src/cmd/vt/cons.h - 664 sys sys 1133808292 1792
 sys/src/cmd/vt/consctl.c - 664 sys sys 1127425716 1796
-sys/src/cmd/vt/event.c - 664 sys sys 1133463638 1245
+sys/src/cmd/vt/event.c - 664 sys sys 1133808292 1071
 sys/src/cmd/vt/event.h - 664 sys sys 944961620 192
-sys/src/cmd/vt/hp.c - 664 sys sys 1133463638 3361
-sys/src/cmd/vt/main.c - 664 sys sys 1133463639 16737
+sys/src/cmd/vt/hp.c - 664 sys sys 1133808292 3362
+sys/src/cmd/vt/main.c - 664 sys sys 1133814920 14466
 sys/src/cmd/vt/mkfile - 664 sys sys 944961620 159
 sys/src/cmd/vt/termcap - 664 sys sys 944961620 278
-sys/src/cmd/vt/vt.c - 664 sys sys 1133463639 20180
+sys/src/cmd/vt/vt.c - 664 sys sys 1133808291 19606
 sys/src/cmd/wc.c - 664 sys sys 984717764 12652
 sys/src/cmd/webcookies.c - 664 sys sys 1132449468 23687
 sys/src/cmd/webfs - 20000000775 sys sys 1015015823 0

+ 19 - 0
dist/replica/plan9.log

@@ -23345,3 +23345,22 @@
 1133632844 0 c sys/man/8/smtp - 664 sys sys 1133631990 4507
 1133715667 0 c lib/face/48x48x4/.dict - 664 sys sys 1133715253 2561
 1133715667 1 a lib/face/48x48x4/u/uriel.1 - 664 sys sys 1133715222 833
+1133800288 0 c sys/man/1/vt - 664 sys sys 1133798750 2404
+1133803888 0 c sys/src/cmd/acid/builtin.c - 664 sys sys 1133802425 20958
+1133805689 0 c sys/man/1/vt - 664 sys sys 1133804098 2472
+1133805689 1 c sys/src/cmd/vt/main.c - 664 sys sys 1133804921 16094
+1133809290 0 c sys/src/cmd/vt/cons.h - 664 sys sys 1133808292 1792
+1133809290 1 c sys/src/cmd/vt/event.c - 664 sys sys 1133808292 1071
+1133809290 2 c sys/src/cmd/vt/hp.c - 664 sys sys 1133808292 3362
+1133809290 3 c sys/src/cmd/vt/main.c - 664 sys sys 1133808291 14515
+1133809290 4 c sys/src/cmd/vt/vt.c - 664 sys sys 1133808291 19606
+1133814692 0 c 386/bin/acid - 775 sys sys 1133814393 400982
+1133814692 1 c 386/bin/vt - 775 sys sys 1133814394 175780
+1133816491 0 c sys/src/cmd/ssh/cmsg.c - 664 sys sys 1133814916 7906
+1133816491 1 c sys/src/cmd/ssh/ssh.c - 664 sys sys 1133814917 9672
+1133816491 2 c sys/src/cmd/vt/main.c - 664 sys sys 1133814920 14466
+1133821894 0 c 386/bin/ssh - 775 sys sys 1133820583 211090
+1133821894 1 c 386/bin/sshnet - 775 sys sys 1133820584 283148
+1133821894 2 c 386/bin/vt - 775 sys sys 1133820585 176212
+1133821894 3 c sys/src/cmd/ssh/ssh.c - 664 sys sys 1133821217 9671
+1133829096 0 c 386/bin/ssh - 775 sys sys 1133827764 211090

+ 33 - 11
sys/man/1/vt

@@ -4,7 +4,11 @@ vt \- emulate a VT-100 or VT-220 terminal
 .SH SYNOPSIS
 .B vt
 [
-.B -2sa
+.B -2aswx
+]
+[
+.B -f
+.I font
 ]
 .SH DESCRIPTION
 .I Vt
@@ -12,16 +16,32 @@ replaces a rio window with a fresh instance of the shell
 .IR rc (1)
 running within an emulation of a DEC VT-100 terminal.
 The
-.B -2
-and
+.BR -2 ,
 .B -a
-options configure
+and
+.B -x
+options change
 .I vt
-to emulate a VT-220 and Ansi terminal respectively.
+to emulate a VT-220, ANSI, or XTerm terminal respectively.
+.PP
 The
 .B -s
-options forces a saner color scheme, i.e, black text on white
-background.
+option changes the color scheme to black text on a white background.
+.PP
+The
+.B -w
+option causes
+.I vt
+to provide a 
+.B /dev/wctl
+file that can be read to learn about window size changes.
+In particular,
+.IR ssh (1)
+will read this file and inform the remote system about size changes.
+.PP
+The
+.B -f
+option sets the font.
 .PP
 The right button has a menu with the following entries to provide
 the sort of character processing expected by non-Plan 9 systems:
@@ -51,7 +71,7 @@ Enter raw (no echo, no interpretation) character mode for input.
 Leave raw mode.
 .TP
 .B exit
-Exits
+Exit
 .IR vt .
 .PD
 .PP
@@ -93,9 +113,9 @@ The down arrow key advances a page without sending the character to the host.
 .PP
 To exit
 .IR vt ,
-exit its
+exit the
 .B rc
-session by, for example, typing EOT (control-D).
+it starts.
 .SH SOURCE
 .B /sys/src/cmd/vt
 .SH BUGS
@@ -105,5 +125,7 @@ as rich an emulation as its equivalent in other environments.
 .PP
 Use care in setting raw and newline modes when connecting to Unix systems
 via
-.IR con .
+.IR con (1)
+or
+.IR ssh (1).
 It may also be necessary to set the emulator into raw mode.

+ 55 - 8
sys/src/cmd/acid/builtin.c

@@ -83,6 +83,8 @@ struct Btab
 	0
 };
 
+char vfmt[] = "aBbcCdDfFgGiIoOqQrRsSuUVWxXYZ";
+
 void
 mkprint(Lsym *s)
 {
@@ -678,31 +680,78 @@ cvtatoi(Node *r, Node *args)
 	r->fmt = 'V';
 }
 
+static char *fmtflags = "-0123456789. #,u";
+static char *fmtverbs = "bdox";
+
+static int
+acidfmt(char *fmt, char *buf, int blen)
+{
+	char *r, *w, *e;
+	
+	w = buf;
+	e = buf+blen;
+	for(r=fmt; *r; r++){
+		if(w >= e)
+			return -1;
+		if(*r != '%'){
+			*w++ = *r;
+			continue;
+		}
+		if(*r == '%'){
+			*w++ = *r++;
+			if(*r == '%'){
+				if(w >= e)
+					return -1;
+				*w++ = *r;
+				continue;
+			}
+			while(*r && strchr(fmtflags, *r)){
+				if(w >= e)
+					return -1;
+				*w++ = *r++;
+			}
+			if(*r == 0 || strchr(fmtverbs, *r) == nil)
+				return -1;
+			if(w+3 > e)
+				return -1;
+			*w++ = 'l';
+			*w++ = 'l';
+			*w++ = *r;
+		}
+	}
+	if(w >= e)
+		return -1;
+	*w = 0;
+
+	return 0;
+}
+
 void
 cvtitoa(Node *r, Node *args)
 {
 	Node res;
 	Node *av[Maxarg];
 	vlong ival;
-	char buf[128], *fmt;
+	char buf[128], fmt[32];
 
 	if(args == 0)
 err:
-		error("itoa(number [, printformat]): arg count");
+		error("itoa(number [, fmt]): arg count");
 	na = 0;
 	flatten(av, args);
 	if(na == 0 || na > 2)
 		goto err;
 	expr(av[0], &res);
 	if(res.type != TINT)
-		error("itoa(integer): arg type");
+		error("itoa(number [, fmt]): arg type");
 	ival = res.ival;
-	fmt = "%lld";
+	strncpy(fmt, "%lld", sizeof(fmt));
 	if(na == 2){
 		expr(av[1], &res);
 		if(res.type != TSTRING)
-			error("itoa(integer, string): arg type");
-		fmt = res.string->string;
+			error("itoa(number [, fmt]): fmt type");
+		if(acidfmt(res.string->string, fmt, sizeof(buf)))
+			error("itoa(number [, fmt]): malformed fmt");
 	}
 
 	snprint(buf, sizeof(buf), fmt, ival);
@@ -896,8 +945,6 @@ regexp(Node *r, Node *args)
 	free(rp);
 }
 
-char vfmt[] = "aBbcCdDfFgGiIoOqQrRsSuUVWxXYZ";
-
 void
 fmt(Node *r, Node *args)
 {

+ 13 - 40
sys/src/cmd/ssh/cmsg.c

@@ -252,52 +252,25 @@ intgetenv(char *name, int def)
 }
 
 /*
- * clumsy hack -- rather than open the font and fetch
- * the real character width and height, we assume that
- * LINES and COLS are initially correct and use them to 
- * derive cwidth, cheight.  this is definitely a mistake,
- * but i don't care.  if you do, fix it.
+ * assumes that if you care, you're running under vt
+ * and therefore these are set.
  */
 int
 readgeom(int *nrow, int *ncol, int *width, int *height)
 {
-	int ret;
-	static int first=1;
 	static int fd = -1;
-	static int cwidth, cheight;
 	char buf[64];
-	int n;
-
-	ret = 0;
-	/* defaults */
-	*width = 640;
-	*height = 480;
-
-	if(fd < 0)
-		fd = open("/dev/wctl", OREAD);
-	if(fd >= 0){
-		n = read(fd, buf, sizeof(buf));
-		if(n < 48){
-			close(fd);
-			fd = -1;
-			ret = -1;
-			goto Out;
-		}
-	}
-	*width = atoi(&buf[2*12]) - atoi(&buf[0*12]);
-	*height = atoi(&buf[3*12]) - atoi(&buf[1*12]);
-
-Out:
-	*nrow = intgetenv("LINES", 0);
-	*ncol = intgetenv("COLS", 0);
-	if(first){
-		first = 0;
-		if(*nrow)
-			cwidth = *width/(*nrow);
-		if(*ncol)
-			cheight = *height/(*ncol);
-	}
-	return ret;
+
+	if(fd < 0 && (fd = open("/dev/wctl", OREAD)) < 0)
+		return -1;
+	/* wait for event, but don't care what it says */
+	if(read(fd, buf, sizeof buf) < 0)
+		return -1;
+	*nrow = intgetenv("LINES", 24);
+	*ncol = intgetenv("COLS", 80);
+	*width = intgetenv("XPIXELS", 640);
+	*height = intgetenv("YPIXELS", 480);
+	return 0;
 }
 
 void

+ 3 - 4
sys/src/cmd/ssh/ssh.c

@@ -59,7 +59,7 @@ findauth(char *name, Auth **list, int nlist)
 void
 usage(void)
 {
-	fprint(2, "usage: ssh [-CiImPpRrw] [-A authlist] [-c cipherlist] [user@]hostname [cmd [args]]\n");
+	fprint(2, "usage: ssh [-CiImPpRr] [-A authlist] [-c cipherlist] [user@]hostname [cmd [args]]\n");
 	exits("usage");
 }
 
@@ -78,6 +78,8 @@ main(int argc, char **argv)
 	atexitkill(getpid());
 
 	dowinchange = 0;
+	if(getenv("LINES"))
+		dowinchange = 1;
 	usepty = -1;
 	user = nil;
 	ARGBEGIN{
@@ -128,9 +130,6 @@ main(int argc, char **argv)
 	case 'r':
 		crstrip = 1;
 		break;
-	case 'w':
-		dowinchange = 1;
-		break;
 	default:
 		usage();
 	}ARGEND

+ 10 - 8
sys/src/cmd/vt/cons.h

@@ -70,15 +70,17 @@ extern void	drawstring(Point, char*, int);
 
 extern int	debug;
 extern int	yscrmin, yscrmax;
-extern int	attribute;
-extern int	attdefault;
-extern int	frgcolor;
-extern int	bckcolor;
-extern int	frgdefault;
-extern int	bckdefault;
+extern int	attr;
+extern int	defattr;
+
+extern Image *fgcolor;
+extern Image *bgcolor;
+extern Image *colors[];
+extern Image *hicolors[];
+extern Image *bgdefault;
+extern Image *fgdefault;
+
 extern int cursoron;
-extern Font *fnt;
-extern int	wflag;
 
 extern void curson(int);
 extern void cursoff(void);

+ 0 - 8
sys/src/cmd/vt/event.c

@@ -7,7 +7,6 @@
 #define	BUFSIZ	4000
 
 extern int	outfd;
-extern int	wctlout;
 
 int	hostpid;
 
@@ -32,15 +31,8 @@ start_host(void)
 		exits("consctl");
 	}
 
-	if(wflag){
-		bind("#|", "/mnt/temp", MREPL);
-		wctlout = open("/mnt/temp/data", OWRITE);
-	}
-
 	switch((hostpid = rfork(RFPROC|RFNAMEG|RFFDG|RFNOTEG))) {
 	case 0:
-		if(wflag)
-			bind("/mnt/temp/data1", "/dev/wctl", MREPL);
 		fd = open("/dev/cons", OREAD);
 		dup(fd,0);
 		if(fd != 0)

+ 1 - 1
sys/src/cmd/vt/hp.c

@@ -199,7 +199,7 @@ emulate(void)
 					Rpt(pt(x, y), pt(xmax-n+1, y+1)), S);
 			}
 			xtipple(Rpt(pt(x,y), pt(x+n, y+1)));
-			string(&screen, pt(x, y), fnt, buf, DxorS);
+			string(&screen, pt(x, y), font, buf, DxorS);
 			if (standout)
 				rectf(&screen,
 				      Rpt(pt(x,y),pt(x+n,y+1)),

+ 87 - 159
sys/src/cmd/vt/main.c

@@ -48,31 +48,40 @@ Menu	menu3;
 char	*histp;
 char	hist[HISTSIZ];
 int	yscrmin, yscrmax;
-int	bckcolor, frgcolor, bckdefault, frgdefault;
-int	attribute, attdefault;
+int	attr, defattr;
 int	wctlout;
-int	wflag;
 
 Image	*bordercol;
 Image	*cursback;
-Image	*black;
+Image	*colors[8];
+Image	*hicolors[8];
 Image	*red;
-Image	*green;
-Image	*blue;
-Image	*cyan;
-Image	*purple;
-Image	*brown;
-Image	*grey;
-Image	*hiblack;
-Image	*hired;
-Image	*higreen;
-Image	*hiblue;
-Image	*hicyan;
-Image	*hipurple;
-Image	*hibrown;
-Image	*higrey;
-Image	*colortab[8];
-Image	*hicolortab[8];
+Image	*fgcolor;
+Image	*bgcolor;
+Image	*fgdefault;
+Image	*bgdefault;
+
+uint rgbacolors[8] = {
+	0x000000FF,	/* black */
+	0xAA0000FF,	/* red */
+	0x00AA00FF,	/* green */
+	0xFF5500FF,	/* brown */
+	0x0000FFFF,	/* blue */
+	0xAA00AAFF,	/* purple */
+	0x00AAAAFF,	/* cyan */
+	0x7F7F7FFF,	/* white */
+};
+
+ulong rgbahicolors[8] = {
+	0x555555FF,	/* light black aka grey */
+	0xFF5555FF,	/* light red */
+	0x55FF55FF,	/* light green */
+	0xFFFF55FF,	/* light brown aka yellow */
+	0x5555FFFF,	/* light blue */
+	0xFF55FFFF,	/* light purple */
+	0x55FFFFFF,	/* light cyan */
+	0xFFFFFFFF,	/* light grey aka white */
+};
 
 /* terminal control */
 struct ttystate ttystate[2] = { {0, 1}, {0, 1} };
@@ -85,7 +94,6 @@ Mouse	mouse;
 int	outfd = -1;
 Biobuf	*snarffp = 0;
 
-Font	*fnt;
 char	*host_buf;
 char	*hostp;			/* input from host */
 int	host_bsize = 2*BSIZE;
@@ -122,7 +130,7 @@ main(int argc, char **argv)
 }
 
 void
-useage(void)
+usage(void)
 {
 	fprint(2, "usage: %s [-2s] [-l logfile]\n", argv0);
 	exits("usage");
@@ -131,17 +139,17 @@ useage(void)
 void
 initialize(int argc, char **argv)
 {
-	int dayglo = 1;
-	char *p;
-	char *fname = 0;
+	int i;
+	char *fontname, *p;
 
-	rfork(RFENVG|RFNAMEG|RFNOTEG);
+	rfork(RFNAMEG|RFNOTEG);
 
+	fontname = nil;
 	term = "vt100";
 	fk = vt100fk;
 	ARGBEGIN{
 	case 'f':
-		fname = EARGF(useage());
+		fontname = EARGF(usage());
 		break;
 	case 'a':
 		term = "ansi";
@@ -155,105 +163,47 @@ initialize(int argc, char **argv)
 		fk = xtermfk;
 		term = "xterm";
 		break;
-	case 's': /* for sape */
-		dayglo = 0;
-		break;
 	case 'l':
-		p = ARGF();
-		if(p == 0)
-			useage();
+		p = EARGF(usage());
 		logfd = create(p, OWRITE, 0666);
 		if(logfd < 0)
 			sysfatal("could not create log file: %s: %r", p);
 		break;
-	case 'w':
-		wflag = 1;
-		break;
 	}ARGEND;
 
 	host_buf = malloc(host_bsize);
 	hostp = host_buf;
 	hostlength = 0;
 
-	if(initdraw(0,0,term) < 0){
+	if(initdraw(0, fontname, term) < 0){
 		fprint(2, "%s: initdraw failed: %r\n", term);
 		exits("initdraw");
 	}
 	ebegin(Ehost);
 
-	if(fname)
-		fnt = openfont(display, fname);
-	if(fnt == nil)
-		fnt = font;
-
 	histp = hist;
 	menu2.item = menutext2;
 	menu3.item = menutext3;
 	pagemode = 0;
 	blocked = 0;
-	NS = fnt->height;
-	CW = stringwidth(fnt, "m");
+	NS = font->height;
+	CW = stringwidth(font, "m");
 
+	red = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DRed);
 	bordercol = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xCCCCCCCC);
 	cursback = allocimage(display, Rect(0, 0, CW+1, NS+1), screen->chan, 0, DNofill);
 
-	black =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x000000FF);
-	red =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,   0xAA0000FF);
-	green =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x00AA00FF);
-	blue =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x0000FFFF);
-	cyan =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x00AAAAFF);
-	purple = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xAA00AAFF);
-	brown = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0xFF5500FF);
-	grey =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x7F7F7FFF);
-
-	hiblack =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x555555FF);
-	hired =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,   0xff5555FF);
-	higreen =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x55ff55FF);
-	hiblue =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x5555ffFF);
-	hicyan =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x55ffffFF);
-	hipurple = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xff55ffFF);
-	hibrown = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0xffff55FF);
-	higrey =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0xffffffFF);
-
-	bckdefault = bckcolor = 0;
-	frgdefault = frgcolor = 7;
-	if(dayglo){
-		colortab[0] = black;
-		colortab[1] = red;
-		colortab[2] = green;
-		colortab[3] = brown;
-		colortab[4] = blue;
-		colortab[5] = purple;
-		colortab[6] = cyan;
-		colortab[7] = grey;
-		hicolortab[0] = hiblack;
-		hicolortab[1] = hired;
-		hicolortab[2] = higreen;
-		hicolortab[3] = hibrown;
-		hicolortab[4] = hiblue;
-		hicolortab[5] = hipurple;
-		hicolortab[6] = hicyan;
-		hicolortab[7] = higrey;
-	} else {
-		hicolortab[0] = grey;
-		hicolortab[1] = red;
-		hicolortab[2] = green;
-		hicolortab[3] = brown;
-		hicolortab[4] = blue;
-		hicolortab[5] = purple;
-		hicolortab[6] = cyan;
-		hicolortab[7] = black;
-		colortab[0] = higrey;
-		colortab[1] = hired;
-		colortab[2] = higreen;
-		colortab[3] = hibrown;
-		colortab[4] = hiblue;
-		colortab[5] = hipurple;
-		colortab[6] = hicyan;
-		colortab[7] = hiblack;
+	for(i=0; i<8; i++){
+		colors[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, rgbacolors[i]);
+		hicolors[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, rgbahicolors[i]);
 	}
 
-	eresized(0);
+	bgdefault = display->white;
+	fgdefault = display->black;
+	bgcolor = bgdefault;
+	fgcolor = fgdefault;
+
+	resize();
 
 	if(argc > 0) {
 		sendnchars(strlen(argv[0]),argv[0]);
@@ -264,7 +214,7 @@ initialize(int argc, char **argv)
 void
 clear(Rectangle r)
 {
-	draw(screen, r, colortab[bckcolor], nil, ZP);
+	draw(screen, r, bgcolor, nil, ZP);
 }
 
 void
@@ -286,7 +236,8 @@ newline(void)
 void
 cursoff(void)
 {
-	draw(screen, Rpt(pt(x, y), addpt(pt(x, y), Pt(CW,NS))), cursback, nil, cursback->r.min);
+	draw(screen, Rpt(pt(x, y), addpt(pt(x, y), Pt(CW,NS))), 
+		cursback, nil, cursback->r.min);
 }
 
 void
@@ -294,11 +245,12 @@ curson(int bl)
 {
 	Image *col;
 
-	draw(cursback, cursback->r, screen, nil, pt(x, y));
-
-	if(!cursoron)
+	if(!cursoron){
+		cursoff();
 		return;
+	}
 
+	draw(cursback, cursback->r, screen, nil, pt(x, y));
 	if(bl)
 		col = red;
 	else
@@ -577,32 +529,27 @@ eresized(int new)
 }
 
 void
-exportsize(void)
+putenvint(char *name, int x)
 {
-	int	fd;
-	char	buf[10];
+	char buf[20];
 
-	if((fd = create("/env/LINES", OWRITE, 0644)) > 0) {
-		sprint(buf,"%d",ymax+1);
-		write(fd,buf,strlen(buf));
-		close(fd);
-	}
-	if((fd = create("/env/COLS", OWRITE, 0644)) > 0) {
-		sprint(buf,"%d",xmax+1);
-		write(fd,buf,strlen(buf));
-		close(fd);
-	}
-	if((fd = create("/env/TERM", OWRITE, 0644)) > 0) {
-		fprint(fd, "%s", term);
-		close(fd);
-	}
+	snprint(buf, sizeof buf, "%d", x);
+	putenv(name, buf);
+}
+
+void
+exportsize(void)
+{
+	putenvint("XPIXELS", Dx(screen->r)-2*XMARGIN);
+	putenvint("YPIXELS", Dy(screen->r)-2*XMARGIN);
+	putenvint("LINES", ymax+1);
+	putenvint("COLS", xmax+1);
+	putenv("TERM", term);
 }
 
 void
 resize(void)
 {
-	static int oldwt;
-	static int oldht;
 	if(resize_flag > 1 && getwindow(display, Refnone) < 0){
 		fprint(2, "can't reattach to window: %r\n");
 		exits("can't reattach to window");
@@ -618,11 +565,6 @@ resize(void)
 	olines = 0;
 	exportsize();
 	clear(screen->r);
-	fprint(wctlout, " %11d %11d %11d %11d",
-		screen->r.min.x, screen->r.min.y,
-		screen->r.max.x, screen->r.max.y);
-	oldwt = Dx(screen->r);
-	oldht = Dy(screen->r);
 	resize_flag = 0;
 }
 
@@ -758,7 +700,7 @@ scroll(int sy, int ly, int dy, int cy)	/* source, limit, dest, which line to cle
 {
 	draw(screen, Rpt(pt(0, dy), pt(xmax+1, dy+ly-sy)), screen, nil, pt(0, sy));
 	clear(Rpt(pt(0, cy), pt(xmax+1, cy+1)));
-	flushimage(display,1);
+	flushimage(display, 1);
 }
 
 void
@@ -894,38 +836,24 @@ funckey(int key)
 
 
 void
-drawstring(Point p, char *str, int attribute)
+drawstring(Point p, char *str, int attr)
 {
-	Image *txt, *bg;
-	Rune *rstr;
-	int i, n;
+	int i;
+	Image *txt, *bg, *tmp;
 	
-	if(!(attribute & TReverse)) {
-		if(attribute & THighIntensity || bckcolor){
-			txt = hicolortab[frgcolor];
-			bg = colortab[bckcolor];
-		}else{
-			txt = colortab[frgcolor];
-			bg = colortab[bckcolor];
-		}
-	} else {
-		if(attribute & THighIntensity || bckcolor){
-			txt = colortab[bckcolor];
-			bg = colortab[frgcolor];
-		}else{
-			txt = colortab[bckcolor];
-			bg = colortab[frgcolor];
-		}
+	txt = fgcolor;
+	bg = bgcolor;
+	if(attr & TReverse){
+		tmp = txt;
+		txt = bg;
+		bg = tmp;
+	}
+	if(attr & THighIntensity){
+		for(i=0; i<8; i++)
+			if(txt == colors[i])
+				txt = hicolors[i];
 	}
 
-	n = strlen(str) + 1;
-	rstr = malloc(n * sizeof(rstr[0]));
-
-	for(i = 0; i < n; ++i)
-		rstr[i] = (uchar)str[i];
-
-	draw(screen, Rpt(p, addpt(p, runestringsize(fnt, rstr))), bg, nil, p);
-	runestring(screen, p, txt, ZP, fnt, rstr);
-
-	free(rstr);
+	draw(screen, Rpt(p, addpt(p, stringsize(font, str))), bg, nil, p);
+	string(screen, p, txt, ZP, font, str);
 }

+ 23 - 35
sys/src/cmd/vt/vt.c

@@ -139,7 +139,7 @@ emulate(void)
 	int c;
 	int operand[10];
 	int noperand;
-	int savex, savey, saveattribute, saveisgraphics;
+	int savex, savey, saveattr, saveisgraphics;
 	int isgraphics;
 	int g0set, g1set;
 	int dch;
@@ -150,7 +150,7 @@ emulate(void)
 	savex = savey = 0;
 	yscrmin = 0;
 	yscrmax = ymax;
-	saveattribute = 0;
+	saveattr = 0;
 	saveisgraphics = 0;
 	/* set initial tab stops to DEC-standard 8-column spacing */
 	for(c=0; (c+=8)<nelem(tabcol);)
@@ -196,14 +196,12 @@ emulate(void)
 		case '\013':
 		case '\014':
 			newline();
-			//attribute = attdefault;
 			if (ttystate[cs->raw].nlcr)
 				x = 0;
 			break;
 
 		case '\015':		/* carriage return */
 			x = 0;
-			//attribute = attdefault;
 			if (ttystate[cs->raw].crnl)
 				newline();
 			break;
@@ -258,7 +256,7 @@ emulate(void)
 //print("save\n");
 				savex = x;
 				savey = y;
-				saveattribute = attribute;
+				saveattr = attr;
 				saveisgraphics = isgraphics;
 				break;
 
@@ -269,7 +267,7 @@ emulate(void)
 //print("restore\n");
 				x = savex;
 				y = savey;
-				attribute = saveattribute;
+				attr = saveattr;
 				isgraphics = saveisgraphics;
 				break;
 
@@ -431,7 +429,6 @@ print("resetterminal\n");
 						if(noperand == 1){
 							switch(operand[0]){	
 							case 20:	/* set line feed mode */
-print("linefeedmode\n");
 								ttystate[cs->raw].nlcr = 1;
 								break;
 							case 30:	/* screen invisible (? not supported through VT220) */
@@ -451,7 +448,6 @@ print("linefeedmode\n");
 							case 5:	/* set normal video on screen */
 								break;
 							case 6:	/* set origin to absolute */
-//print("OL\n");
 								originrelative = 0;
 								x = y = 0;
 								break;
@@ -479,14 +475,11 @@ print("linefeedmode\n");
 					 * h - set various options.
 					 */
 					case 'h':
-//print("h%d:%d,%d\n", noperand, operand[0], operand[1]);
 						if(noperand == 1){
 							switch(operand[0]){
 							default:
-//print("escape2 'h' unknown operand %d (n:%d)\n", operand[0], noperand-1);
 								break;
 							case 20:	/* set newline mode */
-print("newlinemode\n");
 								ttystate[cs->raw].nlcr = 0;
 								break;
 							case 30:	/* screen visible (? not supported through VT220) */
@@ -495,7 +488,6 @@ print("newlinemode\n");
 						}else while(--noperand > 0){
 							switch(operand[noperand]){
 							default:
-//print("escape2 'h' operand: %d (n:%d)\n", operand[noperand], noperand);
 								break;
 							case 1:	/* set cursor keys to send application function: ESC O A..D */
 								break;
@@ -509,7 +501,6 @@ print("newlinemode\n");
 							case 5:	/* set screen to reverse video (not implemented) */
 								break;
 							case 6:	/* set origin to relative */
-//print("origin relative\n");
 								originrelative = 1;
 								x = 0;
 								y = yscrmin;
@@ -529,7 +520,7 @@ print("newlinemode\n");
 						break;
 
 					/*
-					 * m - change character attributes.
+					 * m - change character attrs.
 					 */
 					case 'm':
 						setattr(noperand, operand);
@@ -544,7 +535,6 @@ print("newlinemode\n");
 							sendnchars2(4, "\033[0n");	/* terminal ok */
 							break;
 						case 6:	/* cursor position */
-//print("cursor pos\n");
 							sendnchars2(sprint(buf, "\033[%d;%dR",
 								originrelative ? y+1 - yscrmin : y+1, x+1), buf);
 							break;
@@ -555,7 +545,6 @@ print("newlinemode\n");
 					 * q - turn on list of LEDs; turn off others.
 					 */
 					case 'q':
-//print("LED\n");
 						break;
 
 					/*
@@ -564,7 +553,6 @@ print("newlinemode\n");
 					 * scrolling region.
 					 */
 					case 'r':
-//print("scrolling region: n:%d %d %d\n", noperand, operand[1], operand[0]);
 						yscrmin = 0;
 						yscrmax = ymax;
 						switch(noperand){
@@ -874,7 +862,7 @@ Default:
 			}
 			buf[n] = 0;
 //			clear(Rpt(pt(x,y), pt(x+n, y+1)));
-			drawstring(pt(x, y), buf, attribute);
+			drawstring(pt(x, y), buf, attr);
 			x += n;
 			peekc = c;
 			break;
@@ -890,39 +878,39 @@ setattr(int argc, int *argv)
 	for(i=0; i<argc; i++) {
 		switch(argv[i]) {
 		case 0:
-			attribute = attdefault;
-			frgcolor = frgdefault;
-			bckcolor = bckdefault;
+			attr = defattr;
+			fgcolor = fgdefault;
+			bgcolor = bgdefault;
 			break;
 		case 1:
-			attribute |= THighIntensity;
+			attr |= THighIntensity;
 			break;		
 		case 4:
-			attribute |= TUnderline;
+			attr |= TUnderline;
 			break;		
 		case 5:
-			attribute |= TBlink;
+			attr |= TBlink;
 			break;
 		case 7:
-			attribute |= TReverse;
+			attr |= TReverse;
 			break;
 		case 8:
-			attribute |= TInvisible;
+			attr |= TInvisible;
 			break;
 		case 22:
-			attribute &= ~THighIntensity;
+			attr &= ~THighIntensity;
 			break;		
 		case 24:
-			attribute &= ~TUnderline;
+			attr &= ~TUnderline;
 			break;		
 		case 25:
-			attribute &= ~TBlink;
+			attr &= ~TBlink;
 			break;
 		case 27:
-			attribute &= ~TReverse;
+			attr &= ~TReverse;
 			break;
 		case 28:
-			attribute &= ~TInvisible;
+			attr &= ~TInvisible;
 			break;
 		case 30:	/* black */
 		case 31:	/* red */
@@ -932,10 +920,10 @@ setattr(int argc, int *argv)
 		case 35:	/* purple */
 		case 36:	/* cyan */
 		case 37:	/* white */
-			frgcolor = argv[i]-30;
+			fgcolor = colors[argv[i]-30];
 			break;
 		case 39:
-			frgcolor = frgdefault;
+			fgcolor = fgdefault;
 			break;
 		case 40:	/* black */
 		case 41:	/* red */
@@ -945,10 +933,10 @@ setattr(int argc, int *argv)
 		case 45:	/* purple */
 		case 46:	/* cyan */
 		case 47:	/* white */
-			bckcolor = argv[i]-40;
+			bgcolor = colors[argv[i]-40];
 			break;
 		case 49:
-			bckcolor = bckdefault;
+			bgcolor = bgdefault;
 			break;
 		}
 	}