Browse Source

Adding vnc, Fixing snap/take.c

Signed-off-by: Álvaro Jurado <elbingmiss@gmail.com>
Álvaro Jurado 6 years ago
parent
commit
fac8ba5227

+ 1 - 0
sys/src/cmd/build.json

@@ -71,6 +71,7 @@
 			"units/build.json",
 			"usb/build.json",
 			"venti/venti.json",
+			"vnc/build.json",
 			"zenith/build.json"
 		]
 	}

+ 1 - 1
sys/src/cmd/snap/take.c

@@ -91,7 +91,7 @@ readsection(int32_t pid, char *sec)
 		return nil;
 
 	tot = 0;
-	hdr = (int)(intptr_t)((Data*)0)->data;
+	hdr = offsetof(Data, data);
 	while((n = read(fd, buf, sizeof buf)) > 0) {
 		d = erealloc(d, tot+n+hdr);
 		memmove(d->data+tot, buf, n);

+ 1 - 1
sys/src/cmd/vnc/auth.c

@@ -109,7 +109,7 @@ readln(char *prompt, char *line, int len)
 			p++;
 		}
 		if(nr == len){
-			fprint(fd, "line too long; try again\n%s", prompt);
+			fprint(fd, "line too int32_t; try again\n%s", prompt);
 			nr = 0;
 			p = line;
 		}

+ 31 - 0
sys/src/cmd/vnc/build.json

@@ -0,0 +1,31 @@
+{
+	"vnc": {
+		"Include": [
+			"../cmd.json"
+		],
+		"Install": "/$ARCH/bin/",
+		"Projects":
+		[
+			"vncv.json"
+		],
+		"Program": "vncs",
+		"SourceFiles": [
+			"vncs.c",
+			"devdraw.c",
+			"devmouse.c",
+			"devcons.c",
+			"screen.c",
+			"exporter.c",
+			"dev.c",
+			"chan.c",
+			"compat.c",
+			"exportfs.c",
+			"kbds.c",
+			"latin1.c",
+			"rre.c",
+			"rlist.c",
+			"proto.c",
+			"auth.c"
+		]
+	}
+}

+ 11 - 11
sys/src/cmd/vnc/chan.c

@@ -23,7 +23,7 @@ newchan(void)
 	   close calls rootclose, a nop */
 	c->type = 0;
 	c->flag = 0;
-	c->ref = 1;
+	c->ref.ref = 1;
 	c->dev = 0;
 	c->offset = 0;
 	c->iounit = 0;
@@ -45,8 +45,8 @@ void
 cclose(Chan *c)
 {
 	if(c->flag&CFREE)
-		panic("cclose %#p", getcallerpc(&c));
-	if(decref(c))
+		panic("cclose %#p", getcallerpc());
+	if(decref(&c->ref))
 		return;
 
 	if(!waserror()){
@@ -70,7 +70,7 @@ cclone(Chan *c)
 	free(wq);
 	nc->name = c->name;
 	if(c->name)
-		incref(c->name);
+		incref(&c->name->ref);
 	return nc;
 }
 
@@ -94,9 +94,9 @@ incref(Ref *r)
 {
 	int x;
 
-	lock(r);
+	lock(&r->lock);
 	x = ++r->ref;
-	unlock(r);
+	unlock(&r->lock);
 	return x;
 }
 
@@ -105,9 +105,9 @@ decref(Ref *r)
 {
 	int x;
 
-	lock(r);
+	lock(&r->lock);
 	x = --r->ref;
-	unlock(r);
+	unlock(&r->lock);
 	if(x < 0)
 		panic("decref");
 
@@ -126,7 +126,7 @@ newcname(char *s)
 	n->alen = i+CNAMESLOP;
 	n->s = smalloc(n->alen);
 	memmove(n->s, s, i+1);
-	n->ref = 1;
+	n->ref.ref = 1;
 	incref(&ncname);
 	return n;
 }
@@ -136,7 +136,7 @@ cnameclose(Cname *n)
 {
 	if(n == nil)
 		return;
-	if(decref(n))
+	if(decref(&n->ref))
 		return;
 	decref(&ncname);
 	free(n->s);
@@ -153,7 +153,7 @@ addelem(Cname *n, char *s)
 	if(s[0]=='.' && s[1]=='\0')
 		return n;
 
-	if(n->ref > 1){
+	if(n->ref.ref > 1){
 		/* copy on write */
 		new = newcname(n->s);
 		cnameclose(n);

+ 8 - 8
sys/src/cmd/vnc/color.c

@@ -157,22 +157,22 @@ choosecolor(Vnc *v)
 		}
 	}
 
-	v->bpp = bpp;
-	v->depth = depth;
-	v->truecolor = 1;
-	v->bigendian = 0;
-	chan2fmt(v, chan);
-	if(v->red.max == 0 || v->green.max == 0 || v->blue.max == 0)
+	v->pixfmt.bpp = bpp;
+	v->pixfmt.depth = depth;
+	v->pixfmt.truecolor = 1;
+	v->pixfmt.bigendian = 0;
+	chan2fmt(&v->pixfmt, chan);
+	if(v->pixfmt.red.max == 0 || v->pixfmt.green.max == 0 || v->pixfmt.blue.max == 0)
 		sysfatal("screen not supported");
 
 	if(verbose)
 		fprint(2, "%d bpp, %d depth, 0x%lx chan, %d truecolor, %d bigendian\n",
-			v->bpp, v->depth, screen->chan, v->truecolor, v->bigendian);
+			v->pixfmt.bpp, v->pixfmt.depth, screen->chan, v->pixfmt.truecolor, v->pixfmt.bigendian);
 
 	/* send information to server */
 	vncwrchar(v, MPixFmt);
 	vncwrchar(v, 0);	/* padding */
 	vncwrshort(v, 0);
-	vncwrpixfmt(v, &v->Pixfmt);
+	vncwrpixfmt(v, &v->pixfmt);
 	vncflush(v);
 }

+ 11 - 7
sys/src/cmd/vnc/compat.c

@@ -20,7 +20,7 @@ char	*eve;
 extern void *mainmem;
 
 void
-_assert(char *fmt)
+_assert(const char *fmt)
 {
 	panic("assert failed: %s", fmt);
 }
@@ -73,7 +73,11 @@ void
 initcompat(void)
 {
 	rfork(RFREND);
-	privup = privalloc();
+	/* I just don't know how to fix this, because
+	 * in harvey up is Mach *mah()->externup and
+	 * this emulation through the proc seems so weird for me.
+	 */
+	privup = (Proc **)privalloc();
 	kerndate = seconds();
 	eve = getuser();
 	newup("main");
@@ -186,13 +190,13 @@ rendsleep(Rendez *r, int (*f)(void*), void *arg)
 	up->r = r;
 	unlock(&up->rlock);
 
-	lock(r);
+	lock(&r->lock);
 
 	/*
 	 * if condition happened, never mind
 	 */
 	if(up->intr || f(arg)){
-		unlock(r);
+		unlock(&r->lock);
 		goto Done;
 	}
 
@@ -203,7 +207,7 @@ rendsleep(Rendez *r, int (*f)(void*), void *arg)
 	if(r->p)
 		panic("double sleep");
 	r->p = up;
-	unlock(r);
+	unlock(&r->lock);
 
 	_rendsleep(r);
 
@@ -224,7 +228,7 @@ rendwakeup(Rendez *r)
 	Proc *p;
 	int rv;
 
-	lock(r);
+	lock(&r->lock);
 	p = r->p;
 	rv = 0;
 	if(p){
@@ -232,7 +236,7 @@ rendwakeup(Rendez *r)
 		_rendwakeup(r);
 		rv = 1;
 	}
-	unlock(r);
+	unlock(&r->lock);
 	return rv;
 }
 

+ 24 - 24
sys/src/cmd/vnc/compat.h

@@ -31,26 +31,26 @@ enum
 
 struct Ref
 {
-	Lock;
+	Lock lock;
 	int	ref;
 };
 
 struct Rendez
 {
-	Lock;
+	Lock lock;
 	Proc	*p;
 };
 
 struct Chan
 {
-	Ref;
+	Ref	ref;
 	Chan*	next;			/* allocation */
 	Chan*	link;
-	vlong	offset;			/* in file */
-	ushort	type;
+	int64_t	offset;			/* in file */
+	uint16_t	type;
 	uint32_t	dev;
-	ushort	mode;			/* read/write */
-	ushort	flag;
+	uint16_t	mode;			/* read/write */
+	uint16_t	flag;
 	Qid	qid;
 	int	fid;			/* for devmnt */
 	uint32_t	iounit;			/* chunk size for i/o; 0==default */
@@ -60,7 +60,7 @@ struct Chan
 
 struct Cname
 {
-	Ref;
+	Ref	ref;
 	int	alen;			/* allocated length */
 	int	len;			/* strlen(s) */
 	char	*s;
@@ -75,24 +75,24 @@ struct Dev
 	void	(*init)(void);
 	Chan*	(*attach)(char*);
 	Walkqid*	(*walk)(Chan*, Chan*, char**, int);
-	int	(*stat)(Chan*, uchar*, int);
+	int	(*stat)(Chan*, uint8_t*, int);
 	Chan*	(*open)(Chan*, int);
 	void	(*create)(Chan*, char*, int, uint32_t);
 	void	(*close)(Chan*);
-	long	(*read)(Chan*, void*, long, vlong);
-	Block*	(*bread)(Chan*, long, uint32_t);
-	long	(*write)(Chan*, void*, long, vlong);
-	long	(*bwrite)(Chan*, Block*, uint32_t);
+	int32_t	(*read)(Chan*, void*, int32_t, int64_t);
+	Block*	(*bread)(Chan*, int32_t, uint32_t);
+	int32_t	(*write)(Chan*, void*, int32_t, int64_t);
+	int32_t	(*bwrite)(Chan*, Block*, uint32_t);
 	void	(*remove)(Chan*);
-	int	(*wstat)(Chan*, uchar*, int);
+	int	(*wstat)(Chan*, uint8_t*, int);
 };
 
 struct Dirtab
 {
 	char	name[KNAMELEN];
 	Qid	qid;
-	vlong length;
-	long	perm;
+	int64_t length;
+	int32_t	perm;
 };
 
 struct Walkqid
@@ -128,31 +128,31 @@ void		cclose(Chan*);
 void		cnameclose(Cname*);
 int		decref(Ref*);
 Chan*		devattach(int, char*);
-Block*		devbread(Chan*, long, uint32_t);
-long		devbwrite(Chan*, Block*, uint32_t);
+Block*		devbread(Chan*, int32_t, uint32_t);
+int32_t		devbwrite(Chan*, Block*, uint32_t);
 void		devcreate(Chan*, char*, int, uint32_t);
-void		devdir(Chan*, Qid, char*, vlong, char*, long, Dir*);
-long		devdirread(Chan*, char*, long, Dirtab*, int, Devgen*);
+void		devdir(Chan*, Qid, char*, int64_t, char*, int32_t, Dir*);
+int32_t		devdirread(Chan*, char*, int32_t, Dirtab*, int, Devgen*);
 Devgen		devgen;
 void		devinit(void);
 Chan*		devopen(Chan*, int, Dirtab*, int, Devgen*);
 void		devremove(Chan*);
 void		devreset(void);
-int		devstat(Chan*, uchar*, int, Dirtab*, int, Devgen*);
+int		devstat(Chan*, uint8_t*, int, Dirtab*, int, Devgen*);
 Walkqid*		devwalk(Chan*, Chan*, char**, int, Dirtab*, int, Devgen*);
-int		devwstat(Chan*, uchar*, int);
+int		devwstat(Chan*, uint8_t*, int);
 void		error(char*);
 int		incref(Ref*);
 void		isdir(Chan*);
 void		kproc(char*, void(*)(void*), void*);
-void		mkqid(Qid*, vlong, uint32_t, int);
+void		mkqid(Qid*, int64_t, uint32_t, int);
 void		nexterror(void);
 Chan*		newchan(void);
 Cname*		newcname(char*);
 int		openmode(uint32_t);
 void		panic(char*, ...);
 int		readstr(uint32_t, char*, uint32_t, char*);
-long		seconds(void);
+int32_t		seconds(void);
 void*		smalloc(uint32_t);
 
 #define		poperror()	up->nerrlab--

+ 8 - 8
sys/src/cmd/vnc/dev.c

@@ -237,13 +237,13 @@ devdirread(Chan *c, char *d, int32_t n, Dirtab *tab, int ntab,
 {
 	int32_t k, m, dsz;
 	struct{
-		Dir;
+		Dir	dir;
 		char slop[100];
 	}dir;
 
 	k = c->offset;
 	for(m=0; m<n; k++){
-		switch((*gen)(c, tab, ntab, k, &dir)){
+		switch((*gen)(c, tab, ntab, k, &dir.dir)){
 		case -1:
 			return m;
 
@@ -252,7 +252,7 @@ devdirread(Chan *c, char *d, int32_t n, Dirtab *tab, int ntab,
 			break;
 
 		case 1:
-			dsz = convD2M(&dir, (uint8_t*)d, n-m);
+			dsz = convD2M(&dir.dir, (uint8_t*)d, n-m);
 			if(dsz <= BIT16SZ){	/* <= not < because this isn't stat; read is stuck */
 				if(m == 0)
 					return -1;
@@ -319,33 +319,33 @@ Return:
 }
 
 void
-devcreate(Chan*, char*, int, uint32_t)
+devcreate(Chan *c, char *r, int i, uint32_t u)
 {
 	error(Eperm);
 }
 
 Block*
-devbread(Chan *, int32_t, uint32_t)
+devbread(Chan *c, int32_t i, uint32_t u)
 {
 	panic("no block read");
 	return nil;
 }
 
 int32_t
-devbwrite(Chan *, Block *, uint32_t)
+devbwrite(Chan *c, Block *b, uint32_t u)
 {
 	panic("no block write");
 	return 0;
 }
 
 void
-devremove(Chan*)
+devremove(Chan *c)
 {
 	error(Eperm);
 }
 
 int
-devwstat(Chan*, uint8_t*, int)
+devwstat(Chan *c, uint8_t *u, int i)
 {
 	error(Eperm);
 	return 0;

+ 19 - 19
sys/src/cmd/vnc/devcons.c

@@ -35,7 +35,7 @@ Snarf	snarf = {
 
 static struct
 {
-	QLock;
+	QLock	qlock;
 	int	raw;		/* true if we shouldn't process input */
 	int	ctl;		/* number of opens to the control file */
 	int	x;		/* index into line */
@@ -196,11 +196,11 @@ enum{
 };
 
 static Dirtab consdir[]={
-	".",		{Qdir, 0, QTDIR},	0,		DMDIR|0555,
-	"cons",		{Qcons},	0,		0660,
-	"consctl",	{Qconsctl},	0,		0220,
-	"snarf",	{Qsnarf},	0,		0600,
-	"winname",	{Qwinname},	0,		0000,
+	{".",		{Qdir, 0, QTDIR},	0,		DMDIR|0555},
+	{"cons",		{Qcons},	0,		0660},
+	{"consctl",	{Qconsctl},	0,		0220},
+	{"snarf",	{Qsnarf},	0,		0600},
+	{"winname",	{Qwinname},	0,		0000},
 };
 
 static void
@@ -234,9 +234,9 @@ consopen(Chan *c, int omode)
 	c = devopen(c, omode, consdir, nelem(consdir), devgen);
 	switch((uint32_t)c->qid.path){
 	case Qconsctl:
-		qlock(&kbd);
+		qlock(&kbd.qlock);
 		kbd.ctl++;
-		qunlock(&kbd);
+		qunlock(&kbd.qlock);
 		break;
 	case Qsnarf:
 		if((c->mode&3) == OWRITE || (c->mode&3) == ORDWR)
@@ -251,7 +251,7 @@ setsnarf(char *buf, int n, int *vers)
 {
 	int i;
 
-	qlock(&snarf);
+	qlock(&snarf.qlock);
 	snarf.vers++;
 	if(vers)
 		*vers = snarf.vers;
@@ -264,7 +264,7 @@ setsnarf(char *buf, int n, int *vers)
 	free(snarf.buf);
 	snarf.n = n;
 	snarf.buf = buf;
-	qunlock(&snarf);
+	qunlock(&snarf.qlock);
 }
 
 static void
@@ -276,10 +276,10 @@ consclose(Chan *c)
 	/* last close of control file turns off raw */
 	case Qconsctl:
 		if(c->flag&COPEN){
-			qlock(&kbd);
+			qlock(&kbd.qlock);
 			if(--kbd.ctl == 0)
 				kbd.raw = 0;
-			qunlock(&kbd);
+			qunlock(&kbd.qlock);
 		}
 		break;
 	/* odd behavior but really ok: replace snarf buffer when /dev/snarf is closed */
@@ -305,23 +305,23 @@ consread(Chan *c, void *buf, int32_t n, int64_t off)
 		return n;
 	switch((uint32_t)c->qid.path){
 	case Qsnarf:
-		qlock(&snarf);
+		qlock(&snarf.qlock);
 		if(off < snarf.n){
 			if(off + n > snarf.n)
 				n = snarf.n - off;
 			memmove(buf, snarf.buf+off, n);
 		}else
 			n = 0;
-		qunlock(&snarf);
+		qunlock(&snarf.qlock);
 		return n;
 
 	case Qdir:
 		return devdirread(c, buf, n, consdir, nelem(consdir), devgen);
 
 	case Qcons:
-		qlock(&kbd);
+		qlock(&kbd.qlock);
 		if(waserror()){
-			qunlock(&kbd);
+			qunlock(&kbd.qlock);
 			nexterror();
 		}
 		while(!qcanread(lineq)){
@@ -358,7 +358,7 @@ consread(Chan *c, void *buf, int32_t n, int64_t off)
 			}
 		}
 		n = qread(lineq, buf, n);
-		qunlock(&kbd);
+		qunlock(&kbd.qlock);
 		poperror();
 		return n;
 
@@ -370,7 +370,7 @@ consread(Chan *c, void *buf, int32_t n, int64_t off)
 }
 
 static int32_t
-conswrite(Chan *c, void *va, int32_t n, int64_t)
+conswrite(Chan *c, void *va, int32_t n, int64_t u)
 {
 	Snarf *t;
 	char buf[256], *a;
@@ -395,7 +395,7 @@ conswrite(Chan *c, void *va, int32_t n, int64_t)
 			} else if(strncmp(a, "rawoff", 6) == 0){
 				kbd.raw = 0;
 			}
-			if(a = strchr(a, ' '))
+			if((a = strchr(a, ' ')))
 				a++;
 		}
 		break;

+ 36 - 37
sys/src/cmd/vnc/devdraw.c

@@ -38,7 +38,7 @@ enum
  */
 #define	QSHIFT	4	/* location in qid of client # */
 
-#define	QID(q)		((((ulong)(q).path)&0x0000000F)>>0)
+#define	QID(q)		((((uint32_t)(q).path)&0x0000000F)>>0)
 #define	CLIENTPATH(q)	((((uint32_t)q)&0x7FFFFFF0)>>QSHIFT)
 #define	CLIENT(q)	CLIENTPATH((q).path)
 
@@ -59,7 +59,7 @@ uint32_t blanktime = 30;	/* in minutes; a half hour */
 
 struct Draw
 {
-	QLock;
+	QLock	qlock;
 	int		clientid;
 	int		nclient;
 	Client**	client;
@@ -68,8 +68,8 @@ struct Draw
 	int		vers;
 	int		softscreen;
 	int		blanked;	/* screen turned off */
-	ulong		blanktime;	/* time of last operation */
-	ulong		savemap[3*256];
+	uint32_t		blanktime;	/* time of last operation */
+	uint32_t		savemap[3*256];
 };
 
 struct Client
@@ -116,7 +116,7 @@ struct FChar
 	int		maxx;	/* right edge of bits */
 	uint8_t		miny;	/* first non-zero scan-line */
 	uint8_t		maxy;	/* last non-zero scan-line + 1 */
-	schar		left;	/* offset of baseline */
+	char		left;	/* offset of baseline */
 	uint8_t		width;	/* width of baseline */
 };
 
@@ -183,7 +183,6 @@ static	char Ewriteoutside[] =	"writeimage outside image";
 static	char Enotfont[] =	"image not a font";
 static	char Eindex[] =		"character index out of range";
 static	char Enoclient[] =	"no such draw client";
-static	char Edepth[] =	"image has bad depth";
 static	char Enameused[] =	"image name in use";
 static	char Enoname[] =	"no image with that name";
 static	char Eoldname[] =	"named image no longer valid";
@@ -193,23 +192,23 @@ static	char Ewrongname[] = 	"wrong name for image";
 void
 drawlock(void)
 {
-	qlock(&sdraw);
+	qlock(&sdraw.qlock);
 }
 
 void
 drawunlock(void)
 {
-	qunlock(&sdraw);
+	qunlock(&sdraw.qlock);
 }
 
 int
 candrawlock(void)
 {
-	return canqlock(&sdraw);
+	return canqlock(&sdraw.qlock);
 }
 
 static int
-drawgen(Chan *c, Dirtab*, int, int s, Dir *dp)
+drawgen(Chan *c, Dirtab *d, int i, int s, Dir *dp)
 {
 	int t;
 	Qid q;
@@ -917,23 +916,23 @@ fprint(2, "bad memimaged: %r\n");
 void
 deletescreenimage(void)
 {
-	qlock(&sdraw);
+	qlock(&sdraw.qlock);
 	/* RSC: BUG: detach screen */
 	if(screenimage)
 		freememimage(screenimage);
 	screenimage = nil;
-	qunlock(&sdraw);
+	qunlock(&sdraw.qlock);
 }
 
 Chan*
 drawattach(char *spec)
 {
-	qlock(&sdraw);
+	qlock(&sdraw.qlock);
 	if(!initscreenimage()){
-		qunlock(&sdraw);
+		qunlock(&sdraw.qlock);
 		error("no frame buffer");
 	}
-	qunlock(&sdraw);
+	qunlock(&sdraw.qlock);
 	return devattach('i', spec);
 }
 
@@ -959,9 +958,9 @@ drawopen(Chan *c, int omode)
 	if(c->qid.type & QTDIR)
 		return devopen(c, omode, 0, 0, drawgen);
 
-	qlock(&sdraw);
+	qlock(&sdraw.qlock);
 	if(waserror()){
-		qunlock(&sdraw);
+		qunlock(&sdraw.qlock);
 		nexterror();
 	}
 
@@ -992,7 +991,7 @@ drawopen(Chan *c, int omode)
 		incref(&cl->r);
 		break;
 	}
-	qunlock(&sdraw);
+	qunlock(&sdraw.qlock);
 	poperror();
 	c->mode = openmode(omode);
 	c->flag |= COPEN;
@@ -1010,9 +1009,9 @@ drawclose(Chan *c)
 
 	if(c->qid.type & QTDIR)
 		return;
-	qlock(&sdraw);
+	qlock(&sdraw.qlock);
 	if(waserror()){
-		qunlock(&sdraw);
+		qunlock(&sdraw.qlock);
 		nexterror();
 	}
 
@@ -1045,7 +1044,7 @@ drawclose(Chan *c)
 		drawflush();	/* to erase visible, now dead windows */
 		free(cl);
 	}
-	qunlock(&sdraw);
+	qunlock(&sdraw.qlock);
 	poperror();
 }
 
@@ -1066,9 +1065,9 @@ drawread(Chan *c, void *a, int32_t n, int64_t off)
 	if(c->qid.type & QTDIR)
 		return devdirread(c, a, n, 0, 0, drawgen);
 	cl = drawclient(c);
-	qlock(&sdraw);
+	qlock(&sdraw.qlock);
 	if(waserror()){
-		qunlock(&sdraw);
+		qunlock(&sdraw.qlock);
 		nexterror();
 	}
 	switch(QID(c->qid)){
@@ -1127,14 +1126,14 @@ drawread(Chan *c, void *a, int32_t n, int64_t off)
 		for(;;){
 			if(cl->refreshme || cl->refresh)
 				break;
-			qunlock(&sdraw);
+			qunlock(&sdraw.qlock);
 			if(waserror()){
-				qlock(&sdraw);	/* restore lock for waserror() above */
+				qlock(&sdraw.qlock);	/* restore lock for waserror() above */
 				nexterror();
 			}
 			rendsleep(&cl->refrend, drawrefactive, cl);
 			poperror();
-			qlock(&sdraw);
+			qlock(&sdraw.qlock);
 		}
 		p = a;
 		while(cl->refresh && n>=5*4){
@@ -1152,7 +1151,7 @@ drawread(Chan *c, void *a, int32_t n, int64_t off)
 		cl->refreshme = 0;
 		n = p-(uint8_t*)a;
 	}
-	qunlock(&sdraw);
+	qunlock(&sdraw.qlock);
 	poperror();
 	return n;
 }
@@ -1182,10 +1181,10 @@ drawwrite(Chan *c, void *a, int32_t n, int64_t off)
 	if(c->qid.type & QTDIR)
 		error(Eisdir);
 	cl = drawclient(c);
-	qlock(&sdraw);
+	qlock(&sdraw.qlock);
 	if(waserror()){
 		drawwakeall();
-		qunlock(&sdraw);
+		qunlock(&sdraw.qlock);
 		nexterror();
 	}
 	switch(QID(c->qid)){
@@ -1239,7 +1238,7 @@ drawwrite(Chan *c, void *a, int32_t n, int64_t off)
 	default:
 		error(Ebadusefd);
 	}
-	qunlock(&sdraw);
+	qunlock(&sdraw.qlock);
 	poperror();
 	return n;
 }
@@ -1259,10 +1258,10 @@ drawcoord(uint8_t *p, uint8_t *maxp, int oldx, int *newx)
 		x |= *p++ << 7;
 		x |= *p++ << 15;
 		if(x & (1<<22))
-			x |= ~0<<23;
+			x |= (uint32_t)~0<<23;
 	}else{
 		if(b & 0x40)
-			x |= ~0<<7;
+			x |= (uint32_t)~0<<7;
 		x += oldx;
 	}
 	*newx = x;
@@ -1277,8 +1276,8 @@ printmesg(char *fmt, uint8_t *a, int plsprnt)
 	int s;
 
 	if(1|| plsprnt==0){
-		SET(s,q,p);
-		USED(fmt, a, buf, p, q, s);
+		SET(s), SET(q), SET(p);
+		USED(fmt), USED(a), USED(buf), USED(p), USED(q), USED(s);
 		return;
 	}
 	q = buf;
@@ -2054,10 +2053,10 @@ drawblankscreen(int blank)
 
 	if(blank == sdraw.blanked)
 		return;
-	if(!canqlock(&sdraw))
+	if(!canqlock(&sdraw.qlock))
 		return;
 	if(!initscreenimage()){
-		qunlock(&sdraw);
+		qunlock(&sdraw.qlock);
 		return;
 	}
 	p = sdraw.savemap;
@@ -2080,7 +2079,7 @@ drawblankscreen(int blank)
 		}
 	}
 	sdraw.blanked = blank;
-	qunlock(&sdraw);
+	qunlock(&sdraw.qlock);
 }
 
 /*

+ 43 - 116
sys/src/cmd/vnc/devmouse.c

@@ -31,22 +31,22 @@ struct Mousestate
 
 struct Mouseinfo
 {
-	Mousestate;
+	Mousestate	mst;
 	int	dx;
 	int	dy;
 	int	track;		/* dx & dy updated */
 	int	redraw;		/* update cursor on screen */
-	ulong	lastcounter;	/* value when /dev/mouse read */
+	uint32_t	lastcounter;	/* value when /dev/mouse read */
 	Rendez	r;
-	Ref;
-	QLock;
+	Ref	ref;
+	QLock	qlock;
 	int	open;
 	int	acceleration;
 	int	maxacc;
 	Mousestate 	queue[16];	/* circular buffer of click events */
 	int	ri;	/* read index into queue */
 	int	wi;	/* write index into queue */
-	uchar	qfull;	/* queue is full */
+	uint8_t	qfull;	/* queue is full */
 };
 
 Mouseinfo	mouse;
@@ -65,15 +65,14 @@ enum{
 };
 
 static Dirtab mousedir[]={
-	".",	{Qdir, 0, QTDIR},	0,			DMDIR|0555,
-	"cursor",	{Qcursor},	0,			0666,
-	"mouse",	{Qmouse},	0,			0666,
+	{".",	{Qdir, 0, QTDIR},	0,			DMDIR|0555},
+	{"cursor",	{Qcursor},	0,			0666},
+	{"mouse",	{Qmouse},	0,			0666},
 };
 
 static uint8_t buttonmap[8] = {
 	0, 1, 2, 3, 4, 5, 6, 7,
 };
-static int mouseswap;
 
 extern	Memimage*	gscreen;
 extern	void mousewarpnote(Point);
@@ -104,7 +103,7 @@ mousewalk(Chan *c, Chan *nc, char **name, int nname)
 
 	wq = devwalk(c, nc, name, nname, mousedir, nelem(mousedir), devgen);
 	if(wq != nil && wq->clone != c && (wq->clone->qid.type&QTDIR)==0)
-		incref(&mouse);
+		incref(&mouse.ref);
 	return wq;
 }
 
@@ -123,17 +122,17 @@ mouseopen(Chan *c, int omode)
 			error(Eperm);
 		break;
 	case Qmouse:
-		lock(&mouse);
+		lock(&mouse.ref.lock);
 		if(mouse.open){
-			unlock(&mouse);
+			unlock(&mouse.ref.lock);
 			error(Einuse);
 		}
 		mouse.open = 1;
-		mouse.ref++;
-		unlock(&mouse);
+		mouse.ref.ref++;
+		unlock(&mouse.ref.lock);
 		break;
 	default:
-		incref(&mouse);
+		incref(&mouse.ref);
 	}
 	c->mode = openmode(omode);
 	c->flag |= COPEN;
@@ -142,7 +141,7 @@ mouseopen(Chan *c, int omode)
 }
 
 static void
-mousecreate(Chan*, char*, int, uint32_t)
+mousecreate(Chan *c, char *a, int i, uint32_t u)
 {
 	error(Eperm);
 }
@@ -151,16 +150,16 @@ static void
 mouseclose(Chan *c)
 {
 	if((c->qid.type&QTDIR)==0 && (c->flag&COPEN)){
-		lock(&mouse);
+		lock(&mouse.ref.lock);
 		if(c->qid.path == Qmouse)
 			mouse.open = 0;
-		if(--mouse.ref == 0){
+		if(--mouse.ref.ref == 0){
 			cursoroff(1);
 			curs = arrow;
 			Cursortocursor(&arrow);
 			cursoron(1);
 		}
-		unlock(&mouse);
+		unlock(&mouse.ref.lock);
 	}
 }
 
@@ -170,7 +169,6 @@ mouseread(Chan *c, void *va, int32_t n, int64_t off)
 {
 	char buf[4*12+1];
 	uint8_t *p;
-	static int map[8] = {0, 4, 2, 6, 1, 5, 3, 7 };
 	uint32_t offset = off;
 	Mousestate m;
 	int b;
@@ -186,12 +184,12 @@ mouseread(Chan *c, void *va, int32_t n, int64_t off)
 		if(n < 2*4+2*2*16)
 			error(Eshort);
 		n = 2*4+2*2*16;
-		lock(&cursor);
+		lock(&cursor.lock);
 		BPLONG(p+0, curs.offset.x);
 		BPLONG(p+4, curs.offset.y);
 		memmove(p+8, curs.clr, 2*16);
 		memmove(p+40, curs.set, 2*16);
-		unlock(&cursor);
+		unlock(&cursor.lock);
 		return n;
 
 	case Qmouse:
@@ -213,10 +211,10 @@ mouseread(Chan *c, void *va, int32_t n, int64_t off)
 			if(++mouse.ri == nelem(mouse.queue))
 				mouse.ri = 0;
 		} else {
-			lock(&cursor);
+			lock(&cursor.lock);
 
-			m = mouse.Mousestate;
-			unlock(&cursor);
+			m = mouse.mst;
+			unlock(&cursor.lock);
 		}
 
 		b = buttonmap[m.buttons&7];
@@ -235,51 +233,8 @@ mouseread(Chan *c, void *va, int32_t n, int64_t off)
 	return 0;
 }
 
-static void
-setbuttonmap(char* map)
-{
-	int i, x, one, two, three;
-
-	one = two = three = 0;
-	for(i = 0; i < 3; i++){
-		if(map[i] == 0)
-			error(Ebadarg);
-		if(map[i] == '1'){
-			if(one)
-				error(Ebadarg);
-			one = 1<<i;
-		}
-		else if(map[i] == '2'){
-			if(two)
-				error(Ebadarg);
-			two = 1<<i;
-		}
-		else if(map[i] == '3'){
-			if(three)
-				error(Ebadarg);
-			three = 1<<i;
-		}
-		else
-			error(Ebadarg);
-	}
-	if(map[i])
-		error(Ebadarg);
-
-	memset(buttonmap, 0, 8);
-	for(i = 0; i < 8; i++){
-		x = 0;
-		if(i & 1)
-			x |= one;
-		if(i & 2)
-			x |= two;
-		if(i & 4)
-			x |= three;
-		buttonmap[x] = i;
-	}
-}
-
 static int32_t
-mousewrite(Chan *c, void *va, int32_t n, int64_t)
+mousewrite(Chan *c, void *va, int32_t n, int64_t m)
 {
 	char *p;
 	Point pt;
@@ -303,10 +258,10 @@ mousewrite(Chan *c, void *va, int32_t n, int64_t)
 			memmove(curs.set, p+40, 2*16);
 			Cursortocursor(&curs);
 		}
-		qlock(&mouse);
+		qlock(&mouse.qlock);
 		mouse.redraw = 1;
 		mouseclock();
-		qunlock(&mouse);
+		qunlock(&mouse.qlock);
 		cursoron(1);
 		return n;
 
@@ -320,12 +275,12 @@ mousewrite(Chan *c, void *va, int32_t n, int64_t)
 		if(p == 0)
 			error(Eshort);
 		pt.y = strtoul(p, 0, 0);
-		qlock(&mouse);
+		qlock(&mouse.qlock);
 		if(ptinrect(pt, gscreen->r)){
-			mousetrack(pt.x, pt.y, mouse.buttons, nsec()/(1000*1000LL));
+			mousetrack(pt.x, pt.y, mouse.mst.buttons, nsec()/(1000*1000LL));
 			mousewarpnote(pt);
 		}
-		qunlock(&mouse);
+		qunlock(&mouse.qlock);
 		return n;
 	}
 
@@ -356,50 +311,22 @@ Dev mousedevtab = {
 void
 Cursortocursor(Cursor *c)
 {
-	lock(&cursor);
-	memmove(&cursor.Cursor, c, sizeof(Cursor));
+	lock(&cursor.lock);
+	memmove(&cursor.cursor, c, sizeof(Cursor));
 	setcursor(c);
-	unlock(&cursor);
-}
-
-static int
-scale(int x)
-{
-	int sign = 1;
-
-	if(x < 0){
-		sign = -1;
-		x = -x;
-	}
-	switch(x){
-	case 0:
-	case 1:
-	case 2:
-	case 3:
-		break;
-	case 4:
-		x = 6 + (mouse.acceleration>>2);
-		break;
-	case 5:
-		x = 9 + (mouse.acceleration>>1);
-		break;
-	default:
-		x *= mouse.maxacc;
-		break;
-	}
-	return sign*x;
+	unlock(&cursor.lock);
 }
 
 static void
 mouseclock(void)
 {
-	lock(&cursor);
+	lock(&cursor.lock);
 	if(mouse.redraw){
 		mouse.redraw = 0;
 		cursoroff(0);
 		mouse.redraw = cursoron(0);
 	}
-	unlock(&cursor);
+	unlock(&cursor.lock);
 }
 
 /*
@@ -411,19 +338,19 @@ mousetrack(int x, int y, int b, int msec)
 {
 	int lastb;
 
-	lastb = mouse.buttons;
-	mouse.xy = Pt(x, y);
-	mouse.buttons = b;
+	lastb = mouse.mst.buttons;
+	mouse.mst.xy = Pt(x, y);
+	mouse.mst.buttons = b;
 	mouse.redraw = 1;
-	mouse.counter++;
-	mouse.msec = msec;
+	mouse.mst.counter++;
+	mouse.mst.msec = msec;
 
 	/*
 	 * if the queue fills, we discard the entire queue and don't
 	 * queue any more events until a reader polls the mouse.
 	 */
 	if(!mouse.qfull && lastb != b){	/* add to ring */
-		mouse.queue[mouse.wi] = mouse.Mousestate;
+		mouse.queue[mouse.wi] = mouse.mst;
 		if(++mouse.wi == nelem(mouse.queue))
 			mouse.wi = 0;
 		if(mouse.wi == mouse.ri)
@@ -434,15 +361,15 @@ mousetrack(int x, int y, int b, int msec)
 }
 
 int
-mousechanged(void*)
+mousechanged(void *v)
 {
-	return mouse.lastcounter != mouse.counter;
+	return mouse.lastcounter != mouse.mst.counter;
 }
 
 Point
 mousexy(void)
 {
-	return mouse.xy;
+	return mouse.mst.xy;
 }
 
 void

+ 7 - 7
sys/src/cmd/vnc/draw.c

@@ -14,12 +14,12 @@ static struct {
 	char	*name;
 	int	num;
 } enctab[] = {
-	"copyrect",	EncCopyRect,
-	"corre",	EncCorre,
-	"hextile",	EncHextile,
-	"raw",		EncRaw,
-	"rre",		EncRre,
-	"mousewarp",	EncMouseWarp,
+	{"copyrect",	EncCopyRect},
+	{"corre",	EncCorre},
+	{"hextile",	EncHextile},
+	{"raw",		EncRaw},
+	{"rre",		EncRre},
+	{"mousewarp",	EncMouseWarp},
 };
 
 static	uint8_t	*pixbuf;
@@ -346,7 +346,7 @@ readfromserver(Vnc *v)
 	uint8_t junk[100];
 	int32_t n;
 
-	vpixb = calcpixb(v->bpp);
+	vpixb = calcpixb(v->pixfmt.bpp);
 	pixb = calcpixb(screen->depth);
 	switch(pixb){
 	case 1:

+ 20 - 23
sys/src/cmd/vnc/exportfs.c

@@ -91,7 +91,6 @@ static char*	Exversion(Export*, Fcall*, uint8_t*);
 static char*	Exopen(Export*, Fcall*, uint8_t*);
 static char*	Exread(Export*, Fcall*, uint8_t*);
 static char*	Exremove(Export*, Fcall*, uint8_t*);
-static char*	Exsession(Export*, Fcall*, uint8_t*);
 static char*	Exstat(Export*, Fcall*, uint8_t*);
 static char*	Exwalk(Export*, Fcall*, uint8_t*);
 static char*	Exwrite(Export*, Fcall*, uint8_t*);
@@ -100,8 +99,6 @@ static char*	Exwstat(Export*, Fcall*, uint8_t*);
 static char	*(*fcalls[Tmax])(Export*, Fcall*, uint8_t*);
 
 static char	Enofid[]   = "no such fid";
-static char	Eseekdir[] = "can't seek on a directory";
-static char	Ereaddir[] = "unaligned read of a directory";
 static int	exdebug = 0;
 
 int
@@ -221,7 +218,7 @@ exflush(Export *fs, int flushtag, int tag)
 	unlock(&exq.l);
 
 	/* in progress? */
-	lock(&fs->r);
+	lock(&fs->r.lock);
 	for(q = fs->work; q != nil; q = q->next){
 		if(q->rpc.tag == tag){
 			lock(&q->lk);
@@ -232,7 +229,7 @@ exflush(Export *fs, int flushtag, int tag)
 			break;
 		}
 	}
-	unlock(&fs->r);
+	unlock(&fs->r.lock);
 
 Respond:
 	fc.type = Rflush;
@@ -273,7 +270,7 @@ exshutdown(Export *fs)
 	/*
 	 * kick any sleepers
 	 */
-	lock(&fs->r);
+	lock(&fs->r.lock);
 	for(q = fs->work; q != nil; q = q->next){
 		lock(&q->lk);
 		q->noresponse = 1;
@@ -281,7 +278,7 @@ exshutdown(Export *fs)
 			rendintr(q->slave);
 		unlock(&q->lk);
 	}
-	unlock(&fs->r);
+	unlock(&fs->r.lock);
 }
 
 static void
@@ -304,7 +301,7 @@ exfree(Export *fs)
 }
 
 static int
-exwork(void *)
+exwork(void *v)
 {
 	int work;
 
@@ -315,7 +312,7 @@ exwork(void *)
 }
 
 static void
-exslave(void *)
+exslave(void *v)
 {
 	Export *fs;
 	Exq *q, *t, **last;
@@ -364,10 +361,10 @@ exslave(void *)
 		q->responding = 0;
 		rendclearintr();
 		fs = q->export;
-		lock(&fs->r);
+		lock(&fs->r.lock);
 		q->next = fs->work;
 		fs->work = q;
-		unlock(&fs->r);
+		unlock(&fs->r.lock);
 
 		unlock(&exq.l);
 
@@ -411,7 +408,7 @@ exslave(void *)
 		if(exdebug > 1)
 			print("exslave %d written %d\n", getpid(), q->rpc.tag);
 
-		lock(&fs->r);
+		lock(&fs->r.lock);
 		last = &fs->work;
 		for(t = fs->work; t != nil; t = t->next){
 			if(t == q){
@@ -420,7 +417,7 @@ exslave(void *)
 			}
 			last = &t->next;
 		}
-		unlock(&fs->r);
+		unlock(&fs->r.lock);
 
 		exfree(q->export);
 		free(q);
@@ -510,7 +507,7 @@ Exputfid(Export *fs, Fid *f)
 }
 
 static char*
-Exversion(Export *fs, Fcall *rpc, uint8_t *)
+Exversion(Export *fs, Fcall *rpc, uint8_t *u)
 {
 	if(rpc->msize > Maxrpc)
 		rpc->msize = Maxrpc;
@@ -525,13 +522,13 @@ Exversion(Export *fs, Fcall *rpc, uint8_t *)
 }
 
 static char*
-Exauth(Export *, Fcall *, uint8_t *)
+Exauth(Export *fs, Fcall *rpc, uint8_t *u)
 {
 	return "vnc: authentication not required";
 }
 
 static char*
-Exattach(Export *fs, Fcall *rpc, uint8_t *)
+Exattach(Export *fs, Fcall *rpc, uint8_t *u)
 {
 	Fid *f;
 	int w;
@@ -557,7 +554,7 @@ Exattach(Export *fs, Fcall *rpc, uint8_t *)
 }
 
 static char*
-Exclunk(Export *fs, Fcall *rpc, uint8_t *)
+Exclunk(Export *fs, Fcall *rpc, uint8_t *u)
 {
 	Fid *f;
 
@@ -570,7 +567,7 @@ Exclunk(Export *fs, Fcall *rpc, uint8_t *)
 }
 
 static char*
-Exwalk(Export *fs, Fcall *rpc, uint8_t *)
+Exwalk(Export *fs, Fcall *rpc, uint8_t *u)
 {
 	Fid *volatile f, *volatile nf;
 	Walkqid *wq;
@@ -636,7 +633,7 @@ Exwalk(Export *fs, Fcall *rpc, uint8_t *)
 }
 
 static char*
-Exopen(Export *fs, Fcall *rpc, uint8_t *)
+Exopen(Export *fs, Fcall *rpc, uint8_t *u)
 {
 	Fid *volatile f;
 	Chan *c;
@@ -665,7 +662,7 @@ Exopen(Export *fs, Fcall *rpc, uint8_t *)
 }
 
 static char*
-Excreate(Export *fs, Fcall *rpc, uint8_t *)
+Excreate(Export *fs, Fcall *rpc, uint8_t *u)
 {
 	Fid *f;
 	Chan *c;
@@ -720,7 +717,7 @@ Exread(Export *fs, Fcall *rpc, uint8_t *buf)
 }
 
 static char*
-Exwrite(Export *fs, Fcall *rpc, uint8_t *)
+Exwrite(Export *fs, Fcall *rpc, uint8_t *u)
 {
 	Fid *f;
 	Chan *c;
@@ -763,7 +760,7 @@ Exstat(Export *fs, Fcall *rpc, uint8_t *buf)
 }
 
 static char*
-Exwstat(Export *fs, Fcall *rpc, uint8_t *)
+Exwstat(Export *fs, Fcall *rpc, uint8_t *u)
 {
 	Fid *f;
 	Chan *c;
@@ -783,7 +780,7 @@ Exwstat(Export *fs, Fcall *rpc, uint8_t *)
 }
 
 static char*
-Exremove(Export *fs, Fcall *rpc, uint8_t *)
+Exremove(Export *fs, Fcall *rpc, uint8_t *v)
 {
 	Fid *f;
 	Chan *c;

+ 2 - 2
sys/src/cmd/vnc/kbd.h

@@ -11,7 +11,7 @@ typedef struct	Snarf	Snarf;
 
 struct Snarf
 {
-	QLock;
+	QLock	qlock;
 	int		vers;
 	int		n;
 	char		*buf;
@@ -24,7 +24,7 @@ enum
 
 extern	Snarf		snarf;
 
-long			latin1(Rune *k, int n);
+int32_t			latin1(Rune *k, int n);
 void			kbdputc(int c);
 void			screenputs(char*, int);
 void			vncputc(int, int);

+ 33 - 33
sys/src/cmd/vnc/kbds.c

@@ -53,38 +53,38 @@ enum
 
 static Rune vnckeys[] =
 {
-[0x00]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x08]	'\b',	'\t',	'\r',	No,	No,	'\n',	No,	No,
-[0x10]	No,	No,	No,	No,	Scroll,	No,	No,	No,
-[0x18]	No,	No,	No,	Esc,	No,	No,	No,	No,
-[0x20]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x28]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x30]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x38]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x40]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x48]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x50]	Home,	Left,	Up,	Right,	Down,	Pgup,	Pgdown,	No,
-[0x58]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x60]	No,	Print,	No,	Ins,	No,	No,	No,	No,
-[0x68]	No,	No,	No,	Break,	No,	No,	No,	No,
-[0x70]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x78]	No,	No,	No,	No,	No,	No,	No,	Num,
-[0x80]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x88]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x90]	No,	No,	No,	No,	No,	No,	No,	No,
-[0x98]	No,	No,	No,	No,	No,	No,	No,	No,
-[0xa0]	No,	No,	No,	No,	No,	No,	No,	No,
-[0xa8]	No,	No,	'*',	'+',	No,	'-',	'.',	'/',
-[0xb0]	'0',	'1',	'2',	'3',	'4',	'5',	'6',	'7',
-[0xb8]	'8',	'9',	No,	No,	No,	'=',	No,	No,
-[0xc0]	No,	No,	No,	No,	No,	No,	No,	No,
-[0xc8]	No,	No,	No,	No,	No,	No,	No,	No,
-[0xd0]	No,	No,	No,	No,	No,	No,	No,	No,
-[0xd8]	No,	No,	No,	No,	No,	No,	No,	No,
-[0xe0]	No,	Shift,	Shift,	Ctrl,	Ctrl,	Caps,	Caps,	No,
-[0xe8]	No,	Latin,	Latin,	No,	No,	No,	No,	No,
-[0xf0]	No,	No,	No,	No,	No,	No,	No,	No,
-[0xf8]	No,	No,	No,	No,	No,	No,	No,	Delete,
+	[0x00]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x08]=	'\b',	'\t',	'\r',	No,	No,	'\n',	No,	No,
+	[0x10]=	No,	No,	No,	No,	Scroll,	No,	No,	No,
+	[0x18]=	No,	No,	No,	Esc,	No,	No,	No,	No,
+	[0x20]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x28]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x30]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x38]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x40]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x48]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x50]=	Home,	Left,	Up,	Right,	Down,	Pgup,	Pgdown,	No,
+	[0x58]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x60]=	No,	Print,	No,	Ins,	No,	No,	No,	No,
+	[0x68]=	No,	No,	No,	Break,	No,	No,	No,	No,
+	[0x70]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x78]=	No,	No,	No,	No,	No,	No,	No,	Num,
+	[0x80]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x88]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x90]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0x98]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0xa0]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0xa8]=	No,	No,	'*',	'+',	No,	'-',	'.',	'/',
+	[0xb0]=	'0',	'1',	'2',	'3',	'4',	'5',	'6',	'7',
+	[0xb8]=	'8',	'9',	No,	No,	No,	'=',	No,	No,
+	[0xc0]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0xc8]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0xd0]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0xd8]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0xe0]=	No,	Shift,	Shift,	Ctrl,	Ctrl,	Caps,	Caps,	No,
+	[0xe8]=	No,	Latin,	Latin,	No,	No,	No,	No,	No,
+	[0xf0]=	No,	No,	No,	No,	No,	No,	No,	No,
+	[0xf8]=	No,	No,	No,	No,	No,	No,	No,	Delete,
 };
 
 /*
@@ -94,7 +94,6 @@ void
 vncputc(int keyup, int c)
 {
 	int i;
-	static int esc1, esc2;
 	static int alt, caps, ctl, num, shift;
 	static int collecting, nk;
 	static Rune kc[5];
@@ -178,5 +177,6 @@ vncputc(int keyup, int c)
 			return;
 		}
 	}
+	USED(shift), USED(alt);
 	kbdputc(c);
 }

+ 2 - 2
sys/src/cmd/vnc/ksym2utf.h

@@ -11,7 +11,7 @@
  * VNC uses X11's keysyms defined in X11/keysym.h, this is a converter
  * to unicode characters
  */
-static ulong
+static uint32_t
 ksym2utf [] = {
 	[0x1a1] =	L'Ą',
 	[0x1a2] =	L'˘',
@@ -924,7 +924,7 @@ ksym2utf [] = {
 	[0x14fc] =	L'Ֆ',
 	[0x14fd] =	L'ֆ',
 	[0x14fe] =	L'’',
-	[0x14ff] =	L''',
+	[0x14ff] =	L'\'',
 	[0x15d0] =	L'ა',
 	[0x15d1] =	L'ბ',
 	[0x15d2] =	L'გ',

+ 3 - 2
sys/src/cmd/vnc/latin1.c

@@ -20,7 +20,7 @@ struct cvlist
 	Rune	*so;		/* the corresponding Rune for each si entry */
 } latintab[] = {
 #include "latin1.h"
-	0,	0,		0
+	{0,	0,		0}
 };
 
 /*
@@ -59,11 +59,12 @@ latin1(Rune *k, int n)
 	int c;
 	char* p;
 
-	if(k[0] == 'X')
+	if(k[0] == 'X'){
 		if(n>=5)
 			return unicode(k);
 		else
 			return -5;
+	}
 	for(l=latintab; l->ld!=0; l++)
 		if(k[0] == l->ld[0]){
 			if(n == 1)

+ 99 - 99
sys/src/cmd/vnc/latin1.h

@@ -7,102 +7,102 @@
  * in the LICENSE file.
  */
 
-	" ", " i",	L"␣ı",
-	"!~", "-=~",	L"≄≇≉",
-	"!", "!<=>?bmp",	L"¡≮≠≯‽⊄∉⊅",
-	"\"*", "IUiu",	L"ΪΫϊϋ",
-	"\"", "\"AEIOUYaeiouy",	L"¨ÄËÏÖÜŸäëïöüÿ",
-	"$*", "fhk",	L"ϕϑϰ",
-	"$", "BEFHILMRVaefglopv",	L"ℬℰℱℋℐℒℳℛƲɑℯƒℊℓℴ℘ʋ",
-	"\'\"", "Uu",	L"Ǘǘ",
-	"\'", "\'ACEILNORSUYZacegilnorsuyz",	L"´ÁĆÉÍĹŃÓŔŚÚÝŹáćéģíĺńóŕśúýź",
-	"*", "*ABCDEFGHIKLMNOPQRSTUWXYZabcdefghiklmnopqrstuwxyz",	L"∗ΑΒΞΔΕΦΓΘΙΚΛΜΝΟΠΨΡΣΤΥΩΧΗΖαβξδεφγθικλμνοπψρστυωχηζ",
-	"+", "-O",	L"±⊕",
-	",", ",ACEGIKLNORSTUacegiklnorstu",	L"¸ĄÇĘĢĮĶĻŅǪŖŞŢŲąçęģįķļņǫŗşţų",
-	"-*", "l",	L"ƛ",
-	"-", "+-2:>DGHILOTZbdghiltuz~",	L"∓­ƻ÷→ÐǤĦƗŁ⊖ŦƵƀðǥℏɨłŧʉƶ≂",
-	".", ".CEGILOZceglz",	L"·ĊĖĠİĿ⊙Żċėġŀż",
-	"/", "Oo",	L"Øø",
-	"1", "234568",	L"½⅓¼⅕⅙⅛",
-	"2", "-35",	L"ƻ⅔⅖",
-	"3", "458",	L"¾⅗⅜",
-	"4", "5",	L"⅘",
-	"5", "68",	L"⅚⅝",
-	"7", "8",	L"⅞",
-	":", ")-=",	L"☺÷≔",
-	"<!", "=~",	L"≨⋦",
-	"<", "-<=>~",	L"←«≤≶≲",
-	"=", ":<=>OV",	L"≕⋜≡⋝⊜⇒",
-	">!", "=~",	L"≩⋧",
-	">", "<=>~",	L"≷≥»≳",
-	"?", "!?",	L"‽¿",
-	"@\'", "\'",	L"ъ",
-	"@@", "\'EKSTYZekstyz",	L"ьЕКСТЫЗекстыз",
-	"@C", "Hh",	L"ЧЧ",
-	"@E", "Hh",	L"ЭЭ",
-	"@K", "Hh",	L"ХХ",
-	"@S", "CHch",	L"ЩШЩШ",
-	"@T", "Ss",	L"ЦЦ",
-	"@Y", "AEOUaeou",	L"ЯЕЁЮЯЕЁЮ",
-	"@Z", "Hh",	L"ЖЖ",
-	"@c", "h",	L"ч",
-	"@e", "h",	L"э",
-	"@k", "h",	L"х",
-	"@s", "ch",	L"щш",
-	"@t", "s",	L"ц",
-	"@y", "aeou",	L"яеёю",
-	"@z", "h",	L"ж",
-	"@", "ABDFGIJLMNOPRUVXabdfgijlmnopruvx",	L"АБДФГИЙЛМНОПРУВХабдфгийлмнопрувх",
-	"A", "E",	L"Æ",
-	"C", "ACU",	L"⋂ℂ⋃",
-	"Dv", "Zz",	L"DŽDž",
-	"D", "-e",	L"Ð∆",
-	"G", "-",	L"Ǥ",
-	"H", "-H",	L"Ħℍ",
-	"I", "-J",	L"ƗIJ",
-	"L", "&-Jj|",	L"⋀ŁLJLj⋁",
-	"N", "JNj",	L"NJℕNj",
-	"O", "*+-./=EIcoprx",	L"⊛⊕⊖⊙⊘⊜ŒƢ©⊚℗®⊗",
-	"P", "P",	L"ℙ",
-	"Q", "Q",	L"ℚ",
-	"R", "R",	L"ℝ",
-	"S", "123S",	L"¹²³§",
-	"T", "-u",	L"Ŧ⊨",
-	"V", "=",	L"⇐",
-	"Y", "R",	L"Ʀ",
-	"Z", "-ACSZ",	L"Ƶℤ",
-	"^", "ACEGHIJOSUWYaceghijosuwy",	L"ÂĈÊĜĤÎĴÔŜÛŴŶâĉêĝĥîĵôŝûŵŷ",
-	"_\"", "AUau",	L"ǞǕǟǖ",
-	"_,", "Oo",	L"Ǭǭ",
-	"_.", "Aa",	L"Ǡǡ",
-	"_", "AEIOU_aeiou",	L"ĀĒĪŌŪ¯āēīōū",
-	"`\"", "Uu",	L"Ǜǜ",
-	"`", "AEIOUaeiou",	L"ÀÈÌÒÙàèìòù",
-	"a", "ben",	L"↔æ∠",
-	"b", "()+-0123456789=bknpqru",	L"₍₎₊₋₀₁₂₃₄₅₆₇₈₉₌♝♚♞♟♛♜•",
-	"c", "$Oagu",	L"¢©∩≅∪",
-	"dv", "z",	L"dž",
-	"d", "-adegz",	L"ð↓‡°†ʣ",
-	"e", "$lmns",	L"€⋯—–∅",
-	"f", "a",	L"∀",
-	"g", "$-r",	L"¤ǥ∇",
-	"h", "-v",	L"ℏƕ",
-	"i", "-bfjps",	L"ɨ⊆∞ij⊇∫",
-	"l", "\"$&\'-jz|",	L"“£∧‘łlj⋄∨",
-	"m", "iou",	L"µ∈×",
-	"n", "jo",	L"nj¬",
-	"o", "AOUaeiu",	L"Å⊚Ůåœƣů",
-	"p", "Odgrt",	L"℗∂¶∏∝",
-	"r", "\"\'O",	L"”’®",
-	"s", "()+-0123456789=abnoprstu",	L"⁽⁾⁺⁻⁰ⁱ⁲⁳⁴⁵⁶⁷⁸⁹⁼ª⊂ⁿº⊃√ß∍∑",
-	"t", "-efmsu",	L"ŧ∃∴™ς⊢",
-	"u", "-AEGIOUaegiou",	L"ʉĂĔĞĬŎŬ↑ĕğĭŏŭ",
-	"v\"", "Uu",	L"Ǚǚ",
-	"v", "ACDEGIKLNORSTUZacdegijklnorstuz",	L"ǍČĎĚǦǏǨĽŇǑŘŠŤǓŽǎčďěǧǐǰǩľňǒřšťǔž",
-	"w", "bknpqr",	L"♗♔♘♙♕♖",
-	"x", "O",	L"⊗",
-	"y", "$",	L"¥",
-	"z", "-",	L"ƶ",
-	"|", "Pp|",	L"Þþ¦",
-	"~!", "=",	L"≆",
-	"~", "-=AINOUainou~",	L"≃≅ÃĨÑÕŨãĩñõũ≈",
+	{" ", " i",	(Rune *)L"␣ı"},
+	{"!~", "-=~",	(Rune *)L"≄≇≉"},
+	{"!", "!<=>?bmp",	(Rune *)L"¡≮≠≯‽⊄∉⊅"},
+	{"\"*", "IUiu",	(Rune *)L"ΪΫϊϋ"},
+	{"\"", "\"AEIOUYaeiouy",	(Rune *)L"¨ÄËÏÖÜŸäëïöüÿ"},
+	{"$*", "fhk",	(Rune *)L"ϕϑϰ"},
+	{"$", "BEFHILMRVaefglopv",	(Rune *)L"ℬℰℱℋℐℒℳℛƲɑℯƒℊℓℴ℘ʋ"},
+	{"\'\"", "Uu",	(Rune *)L"Ǘǘ"},
+	{"\'", "\'ACEILNORSUYZacegilnorsuyz",	(Rune *)L"´ÁĆÉÍĹŃÓŔŚÚÝŹáćéģíĺńóŕśúýź"},
+	{"*", "*ABCDEFGHIKLMNOPQRSTUWXYZabcdefghiklmnopqrstuwxyz",	(Rune *)L"∗ΑΒΞΔΕΦΓΘΙΚΛΜΝΟΠΨΡΣΤΥΩΧΗΖαβξδεφγθικλμνοπψρστυωχηζ"},
+	{"+", "-O",	(Rune *)L"±⊕"},
+	{"},", "},ACEGIKLNORSTUacegiklnorstu",	(Rune *)L"¸ĄÇĘĢĮĶĻŅǪŖŞŢŲąçęģįķļņǫŗşţų"},
+	{"-*", "l",	(Rune *)L"ƛ"},
+	{"-", "+-2:>DGHILOTZbdghiltuz~",	(Rune *)L"∓­ƻ÷→ÐǤĦƗŁ⊖ŦƵƀðǥℏɨłŧʉƶ≂"},
+	{".", ".CEGILOZceglz",	(Rune *)L"·ĊĖĠİĿ⊙Żċėġŀż"},
+	{"/", "Oo",	(Rune *)L"Øø"},
+	{"1", "234568",	(Rune *)L"½⅓¼⅕⅙⅛"},
+	{"2", "-35",	(Rune *)L"ƻ⅔⅖"},
+	{"3", "458",	(Rune *)L"¾⅗⅜"},
+	{"4", "5",	(Rune *)L"⅘"},
+	{"5", "68",	(Rune *)L"⅚⅝"},
+	{"7", "8",	(Rune *)L"⅞"},
+	{":", ")-=",	(Rune *)L"☺÷≔"},
+	{"<!", "=~",	(Rune *)L"≨⋦"},
+	{"<", "-<=>~",	(Rune *)L"←«≤≶≲"},
+	{"=", ":<=>OV",	(Rune *)L"≕⋜≡⋝⊜⇒"},
+	{">!", "=~",	(Rune *)L"≩⋧"},
+	{">", "<=>~",	(Rune *)L"≷≥»≳"},
+	{"?", "!?",	(Rune *)L"‽¿"},
+	{"@\'", "\'",	(Rune *)L"ъ"},
+	{"@@", "\'EKSTYZekstyz",	(Rune *)L"ьЕКСТЫЗекстыз"},
+	{"@C", "Hh",	(Rune *)L"ЧЧ"},
+	{"@E", "Hh",	(Rune *)L"ЭЭ"},
+	{"@K", "Hh",	(Rune *)L"ХХ"},
+	{"@S", "CHch",	(Rune *)L"ЩШЩШ"},
+	{"@T", "Ss",	(Rune *)L"ЦЦ"},
+	{"@Y", "AEOUaeou",	(Rune *)L"ЯЕЁЮЯЕЁЮ"},
+	{"@Z", "Hh",	(Rune *)L"ЖЖ"},
+	{"@c", "h",	(Rune *)L"ч"},
+	{"@e", "h",	(Rune *)L"э"},
+	{"@k", "h",	(Rune *)L"х"},
+	{"@s", "ch",	(Rune *)L"щш"},
+	{"@t", "s",	(Rune *)L"ц"},
+	{"@y", "aeou",	(Rune *)L"яеёю"},
+	{"@z", "h",	(Rune *)L"ж"},
+	{"@", "ABDFGIJLMNOPRUVXabdfgijlmnopruvx",	(Rune *)L"АБДФГИЙЛМНОПРУВХабдфгийлмнопрувх"},
+	{"A", "E",	(Rune *)L"Æ"},
+	{"C", "ACU",	(Rune *)L"⋂ℂ⋃"},
+	{"Dv", "Zz",	(Rune *)L"DŽDž"},
+	{"D", "-e",	(Rune *)L"Ð∆"},
+	{"G", "-",	(Rune *)L"Ǥ"},
+	{"H", "-H",	(Rune *)L"Ħℍ"},
+	{"I", "-J",	(Rune *)L"ƗIJ"},
+	{"(Rune *)L", "&-Jj|",	(Rune *)L"⋀ŁLJLj⋁"},
+	{"N", "JNj",	(Rune *)L"NJℕNj"},
+	{"O", "*+-./=EIcoprx",	(Rune *)L"⊛⊕⊖⊙⊘⊜ŒƢ©⊚℗®⊗"},
+	{"P", "P",	(Rune *)L"ℙ"},
+	{"Q", "Q",	(Rune *)L"ℚ"},
+	{"R", "R",	(Rune *)L"ℝ"},
+	{"S", "123S",	(Rune *)L"¹²³§"},
+	{"T", "-u",	(Rune *)L"Ŧ⊨"},
+	{"V", "=",	(Rune *)L"⇐"},
+	{"Y", "R",	(Rune *)L"Ʀ"},
+	{"Z", "-ACSZ",	(Rune *)L"Ƶℤ"},
+	{"^", "ACEGHIJOSUWYaceghijosuwy",	(Rune *)L"ÂĈÊĜĤÎĴÔŜÛŴŶâĉêĝĥîĵôŝûŵŷ"},
+	{"_\"", "AUau",	(Rune *)L"ǞǕǟǖ"},
+	{"_,", "Oo",	(Rune *)L"Ǭǭ"},
+	{"_.", "Aa",	(Rune *)L"Ǡǡ"},
+	{"_", "AEIOU_aeiou",	(Rune *)L"ĀĒĪŌŪ¯āēīōū"},
+	{"`\"", "Uu",	(Rune *)L"Ǜǜ"},
+	{"`", "AEIOUaeiou",	(Rune *)L"ÀÈÌÒÙàèìòù"},
+	{"a", "ben",	(Rune *)L"↔æ∠"},
+	{"b", "()+-0123456789=bknpqru",	(Rune *)L"₍₎₊₋₀₁₂₃₄₅₆₇₈₉₌♝♚♞♟♛♜•"},
+	{"c", "$Oagu",	(Rune *)L"¢©∩≅∪"},
+	{"dv", "z",	(Rune *)L"dž"},
+	{"d", "-adegz",	(Rune *)L"ð↓‡°†ʣ"},
+	{"e", "$lmns",	(Rune *)L"€⋯—–∅"},
+	{"f", "a",	(Rune *)L"∀"},
+	{"g", "$-r",	(Rune *)L"¤ǥ∇"},
+	{"h", "-v",	(Rune *)L"ℏƕ"},
+	{"i", "-bfjps",	(Rune *)L"ɨ⊆∞ij⊇∫"},
+	{"l", "\"$&\'-jz|",	(Rune *)L"“£∧‘łlj⋄∨"},
+	{"m", "iou",	(Rune *)L"µ∈×"},
+	{"n", "jo",	(Rune *)L"nj¬"},
+	{"o", "AOUaeiu",	(Rune *)L"Å⊚Ůåœƣů"},
+	{"p", "Odgrt",	(Rune *)L"℗∂¶∏∝"},
+	{"r", "\"\'O",	(Rune *)L"”’®"},
+	{"s", "()+-0123456789=abnoprstu",	(Rune *)L"⁽⁾⁺⁻⁰ⁱ⁲⁳⁴⁵⁶⁷⁸⁹⁼ª⊂ⁿº⊃√ß∍∑"},
+	{"t", "-efmsu",	(Rune *)L"ŧ∃∴™ς⊢"},
+	{"u", "-AEGIOUaegiou",	(Rune *)L"ʉĂĔĞĬŎŬ↑ĕğĭŏŭ"},
+	{"v\"", "Uu",	(Rune *)L"Ǚǚ"},
+	{"v", "ACDEGIKLNORSTUZacdegijklnorstuz",	(Rune *)L"ǍČĎĚǦǏǨĽŇǑŘŠŤǓŽǎčďěǧǐǰǩľňǒřšťǔž"},
+	{"w", "bknpqr",	(Rune *)L"♗♔♘♙♕♖"},
+	{"x", "O",	(Rune *)L"⊗"},
+	{"y", "$",	(Rune *)L"¥"},
+	{"z", "-",	(Rune *)L"ƶ"},
+	{"|", "Pp|",	(Rune *)L"Þþ¦"},
+	{"~!", "=",	(Rune *)L"≆"},
+	{"~", "-=AINOUainou~",	(Rune *)L"≃≅ÃĨÑÕŨãĩñõũ≈"},

+ 0 - 62
sys/src/cmd/vnc/mkfile

@@ -1,62 +0,0 @@
-</$objtype/mkfile
-
-TARG=vncs vncv
-BIN=/$objtype/bin
-
-OFILES=\
-	proto.$O\
-	auth.$O\
-
-SOFILES=\
-	devdraw.$O\
-	devmouse.$O\
-	devcons.$O\
-	screen.$O\
-	exporter.$O\
-	dev.$O\
-	chan.$O\
-	compat.$O\
-	exportfs.$O\
-	kbds.$O\
-	latin1.$O\
-	rre.$O\
-	rlist.$O\
-
-COFILES=\
-	draw.$O\
-	kbdv.$O\
-	color.$O\
-	wsys.$O\
-
-HFILES=\
-	vnc.h\
-	screen.h\
-	compat.h\
-	errstr.h\
-	kbd.h\
-	latin1.h\
-	vncv.h\
-	vncs.h\
-
-UPDATE=\
-	mkfile\
-	$HFILES\
-	${OFILES:%.$O=%.c}\
-	${SOFILES:%.$O=%.c}\
-	${COFILES:%.$O=%.c}\
-	${TARG:%=%.c}\
-
-
-default:V:	all
-
-</sys/src/cmd/mkmany
-
-$O.vncs:	$SOFILES
-
-$O.vncv:	$COFILES
-
-errstr.h:	error.h
-	sed 's/extern //;s,;.*/\* (.*) \*/, = "\1";,' < error.h > errstr.h
-
-kbds.$O:	ksym2utf.h
-kbdv.$O:	utf2ksym.h

+ 2 - 2
sys/src/cmd/vnc/proto.c

@@ -265,13 +265,13 @@ vncwrpoint(Vnc *v, Point p)
 void
 vnclock(Vnc *v)
 {
-	qlock(v);
+	qlock(&v->qlock);
 }
 
 void
 vncunlock(Vnc *v)
 {
-	qunlock(v);
+	qunlock(&v->qlock);
 }
 
 void

+ 35 - 35
sys/src/cmd/vnc/rre.c

@@ -61,24 +61,24 @@ sendraw(Vncs *v, Rectangle r)
 	if(!rectinrect(r, v->image->r))
 		sysfatal("sending bad rectangle");
 
-	pixb = v->bpp >> 3;
-	if((pixb << 3) != v->bpp)
+	pixb = v->vnc.pixfmt.bpp >> 3;
+	if((pixb << 3) != v->vnc.pixfmt.bpp)
 		sysfatal("bad pixel math in sendraw");
-	stride = v->image->width*sizeof(ulong);
+	stride = v->image->width*sizeof(uint32_t);
 	if(((stride / pixb) * pixb) != stride)
 		sysfatal("bad pixel math in sendraw");
 	stride /= pixb;
 
 	raw = byteaddr(v->image, r.min);
 
-	vncwrrect(v, r);
-	vncwrlong(v, EncRaw);
-	sendtraw(v, raw, pixb, stride, Dx(r), Dy(r));
+	vncwrrect(&v->vnc, r);
+	vncwrlong(&v->vnc, EncRaw);
+	sendtraw(&v->vnc, raw, pixb, stride, Dx(r), Dy(r));
 	return 1;
 }
 
 int
-countraw(Vncs*, Rectangle)
+countraw(Vncs *v, Rectangle r)
 {
 	return 1;
 }
@@ -102,7 +102,7 @@ sendhextile(Vncs *v, Rectangle r)
 	if(h == 0 || w == 0 || !rectinrect(r, v->image->r))
 		sysfatal("bad rectangle %R in sendhextile %R", r, v->image->r);
 
-	switch(v->bpp){
+	switch(v->vnc.pixfmt.bpp){
 	case  8:	pixlg = 0;	eq = eqpix8;	break;
 	case 16:	pixlg = 1;	eq = eqpix16;	break;
 	case 32:	pixlg = 2;	eq = eqpix32;	break;
@@ -111,7 +111,7 @@ sendhextile(Vncs *v, Rectangle r)
 		return 1;
 	}
 	pixb = 1 << pixlg;
-	stride = v->image->width*sizeof(ulong);
+	stride = v->image->width*sizeof(uint32_t);
 	if(((stride >> pixlg) << pixlg) != stride){
 		sendraw(v, r);
 		return 1;
@@ -128,8 +128,8 @@ sendhextile(Vncs *v, Rectangle r)
 	}
 	raw = byteaddr(v->image, r.min);
 
-	vncwrrect(v, r);
-	vncwrlong(v, EncHextile);
+	vncwrrect(&v->vnc, r);
+	vncwrlong(&v->vnc, EncHextile);
 	oback = -1;
 	ofore = -1;
 	for(sy = 0; sy < h; sy += HextileDim){
@@ -149,10 +149,10 @@ sendhextile(Vncs *v, Rectangle r)
 			if(oback < 0 || !(*eq)(raw, back + ((traw - raw) >> pixlg), oback))
 				k |= HextileBack;
 			if(nc == 1){
-				vncwrchar(v, k);
+				vncwrchar(&v->vnc, k);
 				if(k & HextileBack){
 					oback = back + ((traw - raw) >> pixlg);
-					putpix(v, raw, oback, pixb);
+					putpix(&v->vnc, raw, oback, pixb);
 				}
 				continue;
 			}
@@ -179,23 +179,23 @@ sendhextile(Vncs *v, Rectangle r)
 			memset(done, 0, HextileDim * HextileDim);
 			nr = encrre(traw, stride, tw, th, back, pixb, buf, nr, done, eq, putr);
 			if(nr < 0){
-				vncwrchar(v, HextileRaw);
-				sendtraw(v, traw, pixb, stride, tw, th);
+				vncwrchar(&v->vnc, HextileRaw);
+				sendtraw(&v->vnc, traw, pixb, stride, tw, th);
 				/* stupid vnc clients smash colors in this case */
 				ofore = -1;
 				oback = -1;
 			}else{
-				vncwrchar(v, k);
+				vncwrchar(&v->vnc, k);
 				if(k & HextileBack){
 					oback = back + ((traw - raw) >> pixlg);
-					putpix(v, raw, oback, pixb);
+					putpix(&v->vnc, raw, oback, pixb);
 				}
 				if(k & HextileFore){
 					ofore = fore + ((traw - raw) >> pixlg);
-					putpix(v, raw, ofore, pixb);
+					putpix(&v->vnc, raw, ofore, pixb);
 				}
-				vncwrchar(v, nr);
-				vncwrbytes(v, buf, nr * bpr);
+				vncwrchar(&v->vnc, nr);
+				vncwrbytes(&v->vnc, buf, nr * bpr);
 			}
 		}
 	}
@@ -205,7 +205,7 @@ sendhextile(Vncs *v, Rectangle r)
 }
 
 int
-counthextile(Vncs*, Rectangle)
+counthextile(Vncs *v, Rectangle r)
 {
 	return 1;
 }
@@ -250,7 +250,7 @@ puthexcol(uint8_t *buf, uint8_t *raw, int p, int pixb, int x, int y,
 }
 
 static uint8_t*
-puthexfore(uint8_t *buf, uint8_t*, int, int, int x, int y, int w, int h)
+puthexfore(uint8_t *buf, uint8_t *c, int i, int n, int x, int y, int w, int h)
 {
 	*buf++ = (x << 4) | y;
 	*buf++ = (w - 1) << 4 | (h - 1);
@@ -279,13 +279,13 @@ enum
 };
 
 int
-countrre(Vncs*, Rectangle r)
+countrre(Vncs *v, Rectangle r)
 {
 	return rrerects(r, MaxRreDim);
 }
 
 int
-countcorre(Vncs*, Rectangle r)
+countcorre(Vncs *v, Rectangle r)
 {
 	return rrerects(r, MaxCorreDim);
 }
@@ -319,7 +319,7 @@ _sendrre(Vncs *v, Rectangle r, int split, int compact)
 	if(h == 0 || w == 0 || !rectinrect(r, v->image->r))
 		sysfatal("bad rectangle in sendrre");
 
-	switch(v->bpp){
+	switch(v->vnc.pixfmt.bpp){
 	case  8:	pixlg = 0;	eq = eqpix8;	break;
 	case 16:	pixlg = 1;	eq = eqpix16;	break;
 	case 32:	pixlg = 2;	eq = eqpix32;	break;
@@ -328,7 +328,7 @@ _sendrre(Vncs *v, Rectangle r, int split, int compact)
 		return totr + 1;
 	}
 	pixb = 1 << pixlg;
-	stride = v->image->width*sizeof(ulong);
+	stride = v->image->width*sizeof(uint32_t);
 	if(((stride >> pixlg) << pixlg) != stride){
 		sendraw(v, r);
 		return totr + 1;
@@ -359,18 +359,18 @@ _sendrre(Vncs *v, Rectangle r, int split, int compact)
 	else
 		nr = encrre(raw, stride, w, h, back, pixb, buf, nr, done, eq, putrre);
 	if(nr < 0){
-		vncwrrect(v, r);
-		vncwrlong(v, EncRaw);
-		sendtraw(v, raw, pixb, stride, w, h);
+		vncwrrect(&v->vnc, r);
+		vncwrlong(&v->vnc, EncRaw);
+		sendtraw(&v->vnc, raw, pixb, stride, w, h);
 	}else{
-		vncwrrect(v, r);
+		vncwrrect(&v->vnc, r);
 		if(compact)
-			vncwrlong(v, EncCorre);
+			vncwrlong(&v->vnc, EncCorre);
 		else
-			vncwrlong(v, EncRre);
-		vncwrlong(v, nr);
-		putpix(v, raw, back, pixb);
-		vncwrbytes(v, buf, nr * bpr);
+			vncwrlong(&v->vnc, EncRre);
+		vncwrlong(&v->vnc, nr);
+		putpix(&v->vnc, raw, back, pixb);
+		vncwrbytes(&v->vnc, buf, nr * bpr);
 	}
 	free(buf);
 	free(done);

+ 20 - 14
sys/src/cmd/vnc/screen.c

@@ -43,10 +43,8 @@ static Rectangle	cursorr;
 static Point		offscreen;
 static uint8_t		cursset[CURSORDIM*CURSORDIM/8];
 static uint8_t		cursclr[CURSORDIM*CURSORDIM/8];
-static int		cursdrawvers = -1;
 static Memimage		*cursorset;
 static Memimage		*cursorclear;
-static Cursor		screencursor;
 
 Cursor	arrow = {
 	{ -1, -1 },
@@ -152,6 +150,7 @@ screeninit(int x, int y, char *chanstr)
 	drawunlock();
 
 	setcursor(&arrow);
+	USED(q);
 }
 
 uint8_t*
@@ -168,7 +167,7 @@ attachscreen(Rectangle* r, uint32_t* chan, int* d, int* width,
 }
 
 void
-getcolor(uint32_t , uint32_t* pr, uint32_t* pg, uint32_t* pb)
+getcolor(uint32_t i, uint32_t* pr, uint32_t* pg, uint32_t* pb)
 {
 	*pr = 0;
 	*pg = 0;
@@ -176,7 +175,7 @@ getcolor(uint32_t , uint32_t* pr, uint32_t* pg, uint32_t* pb)
 }
 
 int
-setcolor(uint32_t , uint32_t , uint32_t , uint32_t )
+setcolor(uint32_t i, uint32_t n, uint32_t t, uint32_t u)
 {
 	return 0;
 }
@@ -191,7 +190,7 @@ cursordraw(Memimage *dst, Rectangle r)
 	static int ver = -1;
 	int i, j, n;
 
-	lock(&cursor);
+	lock(&cursor.lock);
 	if(ver != cursorver){
 		n = 0;
 		for(i = 0; i < CURSORDIM*CURSORDIM/8; i += CURSORDIM/8){
@@ -205,11 +204,11 @@ cursordraw(Memimage *dst, Rectangle r)
 		}
 		memmove(clr, cursclr, CURSORDIM*CURSORDIM/8);
 		ver = cursorver;
-		unlock(&cursor);
+		unlock(&cursor.lock);
 		loadmemimage(cursorset, cursorr, set, CURSORDIM*CURSORDIM);
 		loadmemimage(cursorclear, cursorr, clr, CURSORDIM*CURSORDIM/8);
 	}else
-		unlock(&cursor);
+		unlock(&cursor.lock);
 	memimagedraw(dst, r, memwhite, ZP, cursorclear, ZP, SoverD);
 	memimagedraw(dst, r, curscol, ZP, cursorset, ZP, SoverD);
 }
@@ -222,8 +221,8 @@ cursorrect(void)
 {
 	Rectangle r;
 
-	r.min.x = cursorpos.x + cursor.offset.x;
-	r.min.y = cursorpos.y + cursor.offset.y;
+	r.min.x = cursorpos.x + cursor.cursor.offset.x;
+	r.min.y = cursorpos.y + cursor.cursor.offset.y;
 	r.max.x = r.min.x + CURSORDIM;
 	r.max.y = r.min.y + CURSORDIM;
 	return r;
@@ -244,10 +243,10 @@ int
 cursoron(int dolock)
 {
 	if(dolock)
-		lock(&cursor);
+		lock(&cursor.lock);
 	cursorpos = mousexy();
 	if(dolock)
-		unlock(&cursor);
+		unlock(&cursor.lock);
 
 	return 0;
 }
@@ -256,10 +255,10 @@ void
 cursoroff(int dolock)
 {
 	if(dolock)
-		lock(&cursor);
+		lock(&cursor.lock);
 	cursorpos = offscreen;
 	if(dolock)
-		unlock(&cursor);
+		unlock(&cursor.lock);
 }
 
 void
@@ -311,7 +310,14 @@ screenputc(char *buf)
 	static int *xp;
 	static int xbuf[256];
 
-	if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
+/* This just hasn't any sense, checking if it's smaller
+ * or more or equal to the size of an array guessing it's full.
+ * I think there was an age in what the size of an array was the number
+ * of its elements...
+ * Compiler: error: array index 1024 is past the end of the array
+ * if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
+ */
+	if(xp < xbuf || xp >= xbuf)
 		xp = xbuf;
 
 	switch(buf[0]){

+ 5 - 5
sys/src/cmd/vnc/screen.h

@@ -10,8 +10,8 @@
 typedef struct Cursor Cursor;
 typedef struct Cursorinfo Cursorinfo;
 struct Cursorinfo {
-	Cursor;
-	Lock;
+	Cursor	cursor;
+	Lock	lock;
 };
 
 extern Cursorinfo	cursor;
@@ -32,12 +32,12 @@ void		drawactive(int);
 void		drawlock(void);
 void		drawunlock(void);
 int		candrawlock(void);
-void		getcolor(ulong, uint32_t*, uint32_t*, uint32_t*);
-int		setcolor(ulong, ulong, ulong, ulong);
+void		getcolor(uint32_t, uint32_t*, uint32_t*, uint32_t*);
+int		setcolor(uint32_t, uint32_t, uint32_t, uint32_t);
 #define		TK2SEC(x)	0
 extern void	blankscreen(int);
 void		screeninit(int x, int y, char *chanstr);
 void		mousetrack(int x, int y, int b, int msec);
-uchar		*attachscreen(Rectangle*, uint32_t*, int*, int*, int*);
+uint8_t		*attachscreen(Rectangle*, uint32_t*, int*, int*, int*);
 
 void		fsinit(char *mntpt, int x, int y, char *chanstr);

+ 2 - 2
sys/src/cmd/vnc/utf2ksym.h

@@ -11,7 +11,7 @@
  * VNC uses X11's keysyms defined in X11/keysym.h, this is a converter
  * from unicode characters to ksyms that other servers use.
  */
-static ulong
+static uint32_t
 utf2ksym [] = {
 	[L'Ą'] =	0x1a1,
 	[L'˘'] =	0x1a2,
@@ -901,7 +901,7 @@ utf2ksym [] = {
 	[L'օ'] =	0x14fb,
 	[L'Ֆ'] =	0x14fc,
 	[L'ֆ'] =	0x14fd,
-	[L'''] =	0x14ff,
+	[L'\''] =	0x14ff,
 	[L'ა'] =	0x15d0,
 	[L'ბ'] =	0x15d1,
 	[L'გ'] =	0x15d2,

+ 8 - 8
sys/src/cmd/vnc/vnc.h

@@ -33,7 +33,7 @@ struct Pixfmt {
 };
 
 struct Vnc {
-	QLock;
+	QLock	qlock;
 	int		datafd;			/* for network connection */
 	int		ctlfd;			/* control for network connection */
 
@@ -41,7 +41,7 @@ struct Vnc {
 	Biobuf		out;
 
 	Point		dim;
-	Pixfmt;
+	Pixfmt	pixfmt;
 	char		*name;	/* client only */
 };
 
@@ -94,7 +94,7 @@ enum {
 };
 
 /*
- * we're only using the ulong as a place to store bytes,
+ * we're only using the uint32_t as a place to store bytes,
  * and as something to compare against.
  * the bytes are stored in little-endian format.
  */
@@ -108,8 +108,8 @@ extern	int		vncsrvhandshake(Vnc*);
 
 /* proto.c */
 extern	Vnc*		vncinit(int, int, Vnc*);
-extern	uchar		vncrdchar(Vnc*);
-extern	ushort		vncrdshort(Vnc*);
+extern	uint8_t		vncrdchar(Vnc*);
+extern	uint16_t		vncrdshort(Vnc*);
 extern	uint32_t		vncrdlong(Vnc*);
 extern	Point		vncrdpoint(Vnc*);
 extern	Rectangle	vncrdrect(Vnc*);
@@ -119,14 +119,14 @@ extern	void		vncrdbytes(Vnc*, void*, int);
 extern	char*		vncrdstring(Vnc*);
 extern	char*	vncrdstringx(Vnc*);
 extern	void		vncwrstring(Vnc*, char*);
-extern  void    	vncgobble(Vnc*, long);
+extern  void    	vncgobble(Vnc*, int32_t);
 
 extern	void		vncflush(Vnc*);
 extern	void		vncterm(Vnc*);
 extern	void		vncwrbytes(Vnc*, void*, int);
 extern	void		vncwrlong(Vnc*, uint32_t);
-extern	void		vncwrshort(Vnc*, ushort);
-extern	void		vncwrchar(Vnc*, uchar);
+extern	void		vncwrshort(Vnc*, uint16_t);
+extern	void		vncwrchar(Vnc*, uint8_t);
 extern	void		vncwrpixfmt(Vnc*, Pixfmt*);
 extern	void		vncwrrect(Vnc*, Rectangle);
 extern	void		vncwrpoint(Vnc*, Point);

+ 111 - 134
sys/src/cmd/vnc/vncs.c

@@ -30,34 +30,11 @@ Dev	*devtab[] =
 	nil
 };
 
-static char *msgname[] = {
-	[MPixFmt] = "MPixFmt",
-	[MFixCmap] = "MFixCmap",
-	[MSetEnc] = "MSetEnc",
-	[MFrameReq] = "MFrameReq",
-	[MKey] = "MKey",
-	[MMouse] = "MMouse",
-	[MCCut] = "MCCut",
-};
-
-static char *encname[] = {
-	[EncRaw] = "raw",
-	[EncCopyRect] = "copy rect",
-	[EncRre] = "rre",
-	[EncCorre] = "corre",
-	[EncHextile] = "hextile",
-	[EncZlib]	= "zlib",
-	[EncTight]	= "zlibtight",
-	[EncZHextile]	= "zhextile",
-	[EncMouseWarp]	= "mousewarp",
-
-};
-
 /*
  * list head. used to hold the list, the lock, dim, and pixelfmt
  */
 struct {
-	QLock;
+	QLock	qlock;
 	Vncs *head;
 } clients;
 
@@ -176,7 +153,7 @@ main(int argc, char **argv)
 		break;
 	}
 
-	vncpriv = privalloc();
+	vncpriv = (Vncs **)privalloc();
 	if(vncpriv == nil)
 		sysfatal("privalloc: %r");
 
@@ -246,16 +223,16 @@ main(int argc, char **argv)
 			close(fd);
 			continue;
 		}
-		v->ctlfd = cfd;
-		v->datafd = fd;
+		v->vnc.ctlfd = cfd;
+		v->vnc.datafd = fd;
 		v->nproc = 1;
 		v->ndead = 0;
 		getremote(ldir, v->remote);
 		strcpy(v->netpath, ldir);
-		qlock(&clients);
+		qlock(&clients.qlock);
 		v->next = clients.head;
 		clients.head = v;
-		qunlock(&clients);
+		qunlock(&clients.qlock);
 		vncaccept(v);
 	}
 	exits(0);
@@ -314,27 +291,27 @@ vncclose(Vncs *v)
 	Vncs **l;
 
 	/* remove self from client list if there */
-	qlock(&clients);
+	qlock(&clients.qlock);
 	for(l=&clients.head; *l; l=&(*l)->next)
 		if(*l == v){
 			*l = v->next;
 			break;
 		}
-	qunlock(&clients);
+	qunlock(&clients.qlock);
 
 	/* if last proc, free v */
-	vnclock(v);
+	vnclock(&v->vnc);
 	if(++v->ndead < v->nproc){
-		vncunlock(v);
+		vncunlock(&v->vnc);
 		return;
 	}
 
 	freerlist(&v->rlist);
-	vncterm(v);
-	if(v->ctlfd >= 0)
-		close(v->ctlfd);
-	if(v->datafd >= 0)
-		close(v->datafd);
+	vncterm(&v->vnc);
+	if(v->vnc.ctlfd >= 0)
+		close(v->vnc.ctlfd);
+	if(v->vnc.datafd >= 0)
+		close(v->vnc.datafd);
 	if(v->image)
 		freememimage(v->image);
 	free(v);
@@ -363,19 +340,19 @@ killclients(Vncs *safe)
 {
 	Vncs *v;
 
-	qlock(&clients);
+	qlock(&clients.qlock);
 	for(v=clients.head; v; v=v->next){
 		if(v == safe)
 			continue;
-		if(v->ctlfd >= 0){
-			hangup(v->ctlfd);
-			close(v->ctlfd);
-			v->ctlfd = -1;
-			close(v->datafd);
-			v->datafd = -1;
+		if(v->vnc.ctlfd >= 0){
+			hangup(v->vnc.ctlfd);
+			close(v->vnc.ctlfd);
+			v->vnc.ctlfd = -1;
+			close(v->vnc.datafd);
+			v->vnc.datafd = -1;
 		}
 	}
-	qunlock(&clients);
+	qunlock(&clients.qlock);
 }
 
 /*
@@ -404,7 +381,7 @@ shutdown(void)
 }
 
 static void
-noteshutdown(void*, char *msg)
+noteshutdown(void *v, char *msg)
 {
 	if(strcmp(msg, killkin) == 0)	/* already shutting down */
 		noted(NDFLT);
@@ -523,7 +500,7 @@ vncaccept(Vncs *v)
 			fprint(2, "%V: could not read cert %s: %r; hanging up\n", v, cert);
 			exits(nil);
 		}
-		fd = tlsServer(v->datafd, &conn);
+		fd = tlsServer(v->vnc.datafd, &conn);
 		if(fd < 0){
 			fprint(2, "%V: tlsServer: %r; hanging up\n", v);
 			free(conn.cert);
@@ -531,50 +508,50 @@ vncaccept(Vncs *v)
 				free(conn.sessionID);
 			exits(nil);
 		}
-		close(v->datafd);
-		v->datafd = fd;
+		close(v->vnc.datafd);
+		v->vnc.datafd = fd;
 		free(conn.cert);
 		free(conn.sessionID);
 	}
-	vncinit(v->datafd, v->ctlfd, v);
+	vncinit(v->vnc.datafd, v->vnc.ctlfd, &v->vnc);
 
 	if(verbose)
 		fprint(2, "%V: handshake\n", v);
-	if(vncsrvhandshake(v) < 0){
+	if(vncsrvhandshake(&v->vnc) < 0){
 		fprint(2, "%V: handshake failed; hanging up\n", v);
 		exits(0);
 	}
 	if(verbose)
 		fprint(2, "%V: auth\n", v);
-	if(vncsrvauth(v) < 0){
+	if(vncsrvauth(&v->vnc) < 0){
 		fprint(2, "%V: auth failed; hanging up\n", v);
 		exits(0);
 	}
 
-	shared = vncrdchar(v);
+	shared = vncrdchar(&v->vnc);
 
 	if(verbose)
 		fprint(2, "%V: %sshared\n", v, shared ? "" : "not ");
 	if(!shared)
 		killclients(v);
 
-	v->dim = (Point){Dx(gscreen->r), Dy(gscreen->r)};
-	vncwrpoint(v, v->dim);
+	v->vnc.dim = (Point){Dx(gscreen->r), Dy(gscreen->r)};
+	vncwrpoint(&v->vnc, v->vnc.dim);
 	if(verbose)
-		fprint(2, "%V: send screen size %P (rect %R)\n", v, v->dim, gscreen->r);
+		fprint(2, "%V: send screen size %P (rect %R)\n", v, v->vnc.dim, gscreen->r);
 
-	v->bpp = gscreen->depth;
-	v->depth = gscreen->depth;
-	v->truecolor = 1;
-	v->bigendian = 0;
-	chan2fmt(v, gscreen->chan);
+	v->vnc.pixfmt.bpp = gscreen->depth;
+	v->vnc.pixfmt.depth = gscreen->depth;
+	v->vnc.pixfmt.truecolor = 1;
+	v->vnc.pixfmt.bigendian = 0;
+	chan2fmt(&v->vnc.pixfmt, gscreen->chan);
 	if(verbose)
 		fprint(2, "%V: bpp=%d, depth=%d, chan=%s\n", v,
-			v->bpp, v->depth, chantostr(buf, gscreen->chan));
-	vncwrpixfmt(v, v);
-	vncwrlong(v, 14);
-	vncwrbytes(v, "Plan9 Desktop", 14);
-	vncflush(v);
+			v->vnc.pixfmt.bpp, v->vnc.pixfmt.depth, chantostr(buf, gscreen->chan));
+	vncwrpixfmt(&v->vnc, &v->vnc.pixfmt);
+	vncwrlong(&v->vnc, 14);
+	vncwrbytes(&v->vnc, "Harvey Desktop", 14);
+	vncflush(&v->vnc);
 
 	if(verbose)
 		fprint(2, "%V: handshaking done\n", v);
@@ -582,7 +559,7 @@ vncaccept(Vncs *v)
 	switch(rfork(RFPROC|RFMEM)){
 	case -1:
 		fprint(2, "%V: cannot fork: %r; hanging up\n", v);
-		vnchungup(v);
+		vnchungup(&v->vnc);
 	default:
 		clientreadproc(v);
 		exits(nil);
@@ -628,12 +605,12 @@ setpixelfmt(Vncs *v)
 {
 	uint32_t chan;
 
-	vncgobble(v, 3);
-	v->Pixfmt = vncrdpixfmt(v);
-	chan = fmt2chan(v);
+	vncgobble(&v->vnc, 3);
+	v->vnc.pixfmt = vncrdpixfmt(&v->vnc);
+	chan = fmt2chan(&v->vnc.pixfmt);
 	if(chan == 0){
 		fprint(2, "%V: bad pixel format; hanging up\n", v);
-		vnchungup(v);
+		vnchungup(&v->vnc);
 	}
 	v->imagechan = chan;
 }
@@ -649,10 +626,10 @@ setencoding(Vncs *v)
 {
 	int n, x;
 
-	vncrdchar(v);
-	n = vncrdshort(v);
+	vncrdchar(&v->vnc);
+	n = vncrdshort(&v->vnc);
 	while(n-- > 0){
-		x = vncrdlong(v);
+		x = vncrdlong(&v->vnc);
 		switch(x){
 		case EncCopyRect:
 			v->copyrect = 1;
@@ -712,11 +689,11 @@ clientreadproc(Vncs *v)
 	vncname("read %V", v);
 
 	for(;;){
-		type = vncrdchar(v);
+		type = vncrdchar(&v->vnc);
 		switch(type){
 		default:
 			fprint(2, "%V: unknown vnc message type %d; hanging up\n", v, type);
-			vnchungup(v);
+			vnchungup(&v->vnc);
 
 		/* set pixel format */
 		case MPixFmt:
@@ -725,9 +702,9 @@ clientreadproc(Vncs *v)
 
 		/* ignore color map changes */
 		case MFixCmap:
-			vncgobble(v, 3);
-			n = vncrdshort(v);
-			vncgobble(v, n*6);
+			vncgobble(&v->vnc, 3);
+			n = vncrdshort(&v->vnc);
+			vncgobble(&v->vnc, n*6);
 			break;
 
 		/* set encoding list */
@@ -737,51 +714,51 @@ clientreadproc(Vncs *v)
 
 		/* request image update in rectangle */
 		case MFrameReq:
-			incremental = vncrdchar(v);
-			r = vncrdrect(v);
+			incremental = vncrdchar(&v->vnc);
+			r = vncrdrect(&v->vnc);
 			if(incremental){
-				vnclock(v);
+				vnclock(&v->vnc);
 				v->updaterequest = 1;
-				vncunlock(v);
+				vncunlock(&v->vnc);
 			}else{
 				drawlock();	/* protects rlist */
-				vnclock(v);	/* protects updaterequest */
+				vnclock(&v->vnc);	/* protects updaterequest */
 				v->updaterequest = 1;
 				addtorlist(&v->rlist, r);
-				vncunlock(v);
+				vncunlock(&v->vnc);
 				drawunlock();
 			}
 			break;
 
 		/* send keystroke */
 		case MKey:
-			keydown = vncrdchar(v);
-			vncgobble(v, 2);
-			key = vncrdlong(v);
+			keydown = vncrdchar(&v->vnc);
+			vncgobble(&v->vnc, 2);
+			key = vncrdlong(&v->vnc);
 			vncputc(!keydown, key);
 			break;
 
 		/* send mouse event */
 		case MMouse:
-			buttons = vncrdchar(v);
-			x = vncrdshort(v);
-			y = vncrdshort(v);
+			buttons = vncrdchar(&v->vnc);
+			x = vncrdshort(&v->vnc);
+			y = vncrdshort(&v->vnc);
 			mousetrack(x, y, buttons, nsec()/(1000*1000LL));
 			break;
 
 		/* send cut text */
 		case MCCut:
-			vncgobble(v, 3);
-			n = vncrdlong(v);
+			vncgobble(&v->vnc, 3);
+			n = vncrdlong(&v->vnc);
 			buf = malloc(n+1);
 			if(buf){
-				vncrdbytes(v, buf, n);
+				vncrdbytes(&v->vnc, buf, n);
 				buf[n] = 0;
-				vnclock(v);	/* for snarfvers */
+				vnclock(&v->vnc);	/* for snarfvers */
 				setsnarf(buf, n, &v->snarfvers);
-				vncunlock(v);
+				vncunlock(&v->vnc);
 			}else
-				vncgobble(v, n);
+				vncgobble(&v->vnc, n);
 			break;
 		}
 	}
@@ -891,10 +868,10 @@ flushmemscreen(Rectangle r)
 
 	if(!rectclip(&r, gscreen->r))
 		return;
-	qlock(&clients);
+	qlock(&clients.qlock);
 	for(v=clients.head; v; v=v->next)
 		addtorlist(&v->rlist, r);
-	qunlock(&clients);
+	qunlock(&clients.qlock);
 }
 
 /*
@@ -905,16 +882,16 @@ mousewarpnote(Point p)
 {
 	Vncs *v;
 
-	qlock(&clients);
+	qlock(&clients.qlock);
 	for(v=clients.head; v; v=v->next){
 		if(v->canwarp){
-			vnclock(v);
+			vnclock(&v->vnc);
 			v->needwarp = 1;
 			v->warppt = p;
-			vncunlock(v);
+			vncunlock(&v->vnc);
 		}
 	}
-	qunlock(&clients);
+	qunlock(&clients.qlock);
 }
 
 /*
@@ -940,7 +917,7 @@ updateimage(Vncs *v)
 	needwarp = v->canwarp && v->needwarp;
 	warppt = v->warppt;
 	v->needwarp = 0;
-	vncunlock(v);
+	vncunlock(&v->vnc);
 
 	/* copy the screen bits and then unlock the screen so updates can proceed */
 	drawlock();
@@ -948,7 +925,7 @@ updateimage(Vncs *v)
 	memset(&v->rlist, 0, sizeof v->rlist);
 
 	/* if the cursor has moved or changed shape, we need to redraw its square */
-	lock(&cursor);
+	lock(&cursor.lock);
 	if(v->cursorver != cursorver || !eqpt(v->cursorpos, cursorpos)){
 		docursor = 1;
 		v->cursorver = cursorver;
@@ -958,7 +935,7 @@ updateimage(Vncs *v)
 		docursor = 0;
 		cr = v->cursorr;
 	}
-	unlock(&cursor);
+	unlock(&cursor.lock);
 
 	if(docursor){
 		addtorlist(&rlist, v->cursorr);
@@ -982,11 +959,11 @@ updateimage(Vncs *v)
 
 	drawunlock();
 
-	ooffset = Boffset(&v->out);
+	ooffset = Boffset(&v->vnc.out);
 	/* no more locks are held; talk to the client */
 
 	if(rlist.nrect == 0 && needwarp == 0){
-		vnclock(v);
+		vnclock(&v->vnc);
 		return 0;
 	}
 
@@ -1005,9 +982,9 @@ updateimage(Vncs *v)
 		fprint(2, "sendupdate: rlist.nrect=%d, ncount=%d", rlist.nrect, ncount);
 
 	t1 = nsec();
-	vncwrchar(v, MFrameUpdate);
-	vncwrchar(v, 0);
-	vncwrshort(v, ncount+needwarp);
+	vncwrchar(&v->vnc, MFrameUpdate);
+	vncwrchar(&v->vnc, 0);
+	vncwrshort(&v->vnc, ncount+needwarp);
 
 	nsend = 0;
 	for(i=0; i<rlist.nrect; i++)
@@ -1015,20 +992,20 @@ updateimage(Vncs *v)
 
 	if(ncount != nsend){
 		fprint(2, "%V: ncount=%d, nsend=%d; hanging up\n", v, ncount, nsend);
-		vnchungup(v);
+		vnchungup(&v->vnc);
 	}
 
 	if(needwarp){
-		vncwrrect(v, Rect(warppt.x, warppt.y, warppt.x+1, warppt.y+1));
-		vncwrlong(v, EncMouseWarp);
+		vncwrrect(&v->vnc, Rect(warppt.x, warppt.y, warppt.x+1, warppt.y+1));
+		vncwrlong(&v->vnc, EncMouseWarp);
 	}
 
 	t1 = nsec() - t1;
 	if(verbose > 1)
-		fprint(2, " in %lldms, %lld bytes\n", t1/1000000, Boffset(&v->out) - ooffset);
+		fprint(2, " in %lldms, %lld bytes\n", t1/1000000, Boffset(&v->vnc.out) - ooffset);
 
 	freerlist(&rlist);
-	vnclock(v);
+	vnclock(&v->vnc);
 	return 1;
 }
 
@@ -1043,25 +1020,25 @@ updatesnarf(Vncs *v)
 
 	if(v->snarfvers == snarf.vers)
 		return;
-	vncunlock(v);
-	qlock(&snarf);
+	vncunlock(&v->vnc);
+	qlock(&snarf.qlock);
 	len = snarf.n;
 	buf = malloc(len);
 	if(buf == nil){
-		qunlock(&snarf);
-		vnclock(v);
+		qunlock(&snarf.qlock);
+		vnclock(&v->vnc);
 		return;
 	}
 	memmove(buf, snarf.buf, len);
 	v->snarfvers = snarf.vers;
-	qunlock(&snarf);
+	qunlock(&snarf.qlock);
 
-	vncwrchar(v, MSCut);
-	vncwrbytes(v, "pad", 3);
-	vncwrlong(v, len);
-	vncwrbytes(v, buf, len);
+	vncwrchar(&v->vnc, MSCut);
+	vncwrbytes(&v->vnc, "pad", 3);
+	vncwrlong(&v->vnc, len);
+	vncwrbytes(&v->vnc, buf, len);
 	free(buf);
-	vnclock(v);
+	vnclock(&v->vnc);
 }
 
 /*
@@ -1075,17 +1052,17 @@ clientwriteproc(Vncs *v)
 
 	vncname("write %V", v);
 	for(;;){
-		vnclock(v);
+		vnclock(&v->vnc);
 		if(v->ndead)
 			break;
 		if((v->image == nil && v->imagechan!=0)
 		|| (v->image && v->image->chan != v->imagechan)){
 			if(v->image)
 				freememimage(v->image);
-			v->image = allocmemimage(Rpt(ZP, v->dim), v->imagechan);
+			v->image = allocmemimage(Rpt(ZP, v->vnc.dim), v->imagechan);
 			if(v->image == nil){
 				fprint(2, "%V: allocmemimage: %r; hanging up\n", v);
-				vnchungup(v);
+				vnchungup(&v->vnc);
 			}
 			if(verbose)
 				fprint(2, "%V: translating image from chan=%s to chan=%s\n",
@@ -1099,11 +1076,11 @@ clientwriteproc(Vncs *v)
 			if(!sent)
 				v->updaterequest = 1;
 		}
-		vncunlock(v);
-		vncflush(v);
+		vncunlock(&v->vnc);
+		vncflush(&v->vnc);
 		if(!sent)
 			sleep(sleeptime);
 	}
-	vncunlock(v);
-	vnchungup(v);
+	vncunlock(&v->vnc);
+	vnchungup(&v->vnc);
 }

+ 2 - 2
sys/src/cmd/vnc/vncs.h

@@ -20,7 +20,7 @@ struct Rlist
 
 struct Vncs
 {
-	Vnc;
+	Vnc	vnc;
 
 	Vncs	*next;
 	char		remote[NETPATHLEN];
@@ -44,7 +44,7 @@ struct Vncs
 	int		snarfvers;
 
 	Memimage	*image;
-	ulong	imagechan;
+	uint32_t	imagechan;
 };
 
 /* rre.c */

+ 3 - 3
sys/src/cmd/vnc/vncv.c

@@ -62,7 +62,7 @@ netmkvncaddr(char *inserver)
 	port = 5900;
 	if(tls)
 		port = 35729;
-	if(p = strchr(server, ':')) {
+	if((p = strchr(server, ':'))) {
 		*p++ = '\0';
 		port += atoi(p);
 	}
@@ -74,7 +74,7 @@ netmkvncaddr(char *inserver)
 }
 
 void
-vnchungup(Vnc*)
+vnchungup(Vnc *v)
 {
 	sysfatal("connection closed");
 }
@@ -211,7 +211,7 @@ vncstart(Vnc *v, int shared)
 	vncwrchar(v, shared);
 	vncflush(v);
 	v->dim = vncrdpoint(v);
-	v->Pixfmt = vncrdpixfmt(v);
+	v->pixfmt = vncrdpixfmt(v);
 	v->name = vncrdstring(v);
 	return 0;
 }

+ 3 - 3
sys/src/cmd/vnc/vncv.h

@@ -9,7 +9,7 @@
 
 /* color.c */
 extern	void		choosecolor(Vnc*);
-extern	void		(*cvtpixels)(uchar*, uchar*, int);
+extern	void		(*cvtpixels)(uint8_t*, uint8_t*, int);
 extern  void            settranslation(Vnc*);
 
 /* draw.c */
@@ -17,7 +17,7 @@ extern	void		sendencodings(Vnc*);
 extern	void		requestupdate(Vnc*, int);
 extern	void		readfromserver(Vnc*);
 
-extern	uchar	zero[];
+extern	uint8_t	zero[];
 
 /* vncv.c */
 extern	char		*encodings;
@@ -31,5 +31,5 @@ extern	void		initmouse(void);
 extern	void		mousewarp(Point);
 extern	void		readmouse(Vnc*);
 extern  void            senddim(Vnc*);
-extern  void            writesnarf(Vnc*, long);
+extern  void            writesnarf(Vnc*, int32_t);
 extern  void            checksnarf(Vnc*);

+ 18 - 0
sys/src/cmd/vnc/vncv.json

@@ -0,0 +1,18 @@
+{
+	"vnc": {
+		"Include": [
+			"../cmd.json"
+		],
+		"Install": "/$ARCH/bin/",
+		"Program": "vncv",
+		"SourceFiles": [
+			"vncv.c",
+			"proto.c",
+			"auth.c",
+			"draw.c",
+			"kbdv.c",
+			"color.c",
+			"wsys.c"
+		]
+	}
+}