Browse Source

Added sam into the build

Change-Id: Ia55b14eba9d6d74bfc3d62deff6763fc001ab37b
Signed-off-by: Keith Poole <keith.poole@gmail.com>
Keith Poole 8 years ago
parent
commit
fb294cd955

+ 2 - 0
sys/src/cmd/cmds.json

@@ -156,6 +156,8 @@
 			"ndb/ndb.json",
 			"rc/rc.json",
 			"rio/rio.json",
+			"sam/build.json",
+			"samterm/build.json",
 			"syscall/syscall.json",
 			"usb/build.json",
 			"venti/venti.json"

+ 93 - 0
sys/src/cmd/sam/build.json

@@ -0,0 +1,93 @@
+{
+	"sam": {
+		"Cflags": [
+			"-ffreestanding",
+			"-fno-builtin",
+			"-fno-omit-frame-pointer",
+			"-fplan9-extensions",
+			"-fvar-tracking",
+			"-fvar-tracking-assignments",
+			"-g",
+			"-gdwarf-2",
+			"-ggdb",
+			"-mcmodel=small",
+			"-mno-red-zone",
+			"-Wpedantic",
+			"-O0",
+			"-static",
+			"-Wall",
+			"-Wno-missing-braces",
+			"-Wno-parentheses",
+		    "-Wno-pointer-sign",
+			"-Wno-unknown-pragmas"
+		],
+		"Install": "/$ARCH/bin",
+		"Post": [
+			"rm *.o",
+			"OBJDUMP=objdump; $TOOLPREFIX$OBJDUMP -S $HARVEY/$ARCH/bin/sam > sam.asm" 
+		],
+		"Oflags": [
+			"-static",
+			"-e_main",
+			"-lavl",
+			"-lcomplete",
+			"-lcontrol",
+			"-ldisk",
+			"-lflate",
+			"-lframe",
+			"-lgeometry",
+			"-lhttpd",
+			"-lbin",
+			"-llex",
+			"-lmemdraw",
+			"-lmemlayer",
+			"-lmemdraw",
+			"-ldraw",
+			"-lplumb",
+			"-lregexp",
+			"-lstdio",
+			"-lString",
+			"-lsunrpc",
+			"-loventi",
+			"-l9p",
+			"-lauth",
+			"-lauthsrv",
+			"-lndb",
+			"-lip",
+			"-lventi",
+			"-lsec",
+			"-lauth",
+			"-lmp",
+			"-lthread",
+			"-lmach",
+			"-lbio",
+			"-lc"
+		],
+		"Pre": [
+			"rm -f *.tag.*"
+		],
+		"Program": "sam",
+	 	"SourceFiles": [
+			"address.c",
+			"buff.c",
+			"cmd.c",
+			"disk.c",
+			"error.c",
+			"file.c",
+			"io.c",
+			"list.c",
+			"mesg.c",
+			"moveto.c",
+			"multi.c",
+			"plan9.c",
+			"rasp.c",
+			"regexp.c",
+			"sam.c",
+			"shell.c",
+			"string.c",
+			"sys.c",
+			"util.c",
+			"xec.c"
+		]
+	}
+}

+ 4 - 4
sys/src/cmd/sam/file.c

@@ -24,8 +24,8 @@ typedef struct Merge Merge;
 
 struct Undo
 {
-	int16_t	type;		/* Delete, Insert, Filename, Dot, Mark */
-	int16_t	mod;		/* modify bit */
+	short	type;		/* Delete, Insert, Filename, Dot, Mark */
+	short	mod;		/* modify bit */
 	uint	seq;		/* sequence number */
 	uint	p0;		/* location of change (unused in f) */
 	uint	n;		/* # runes in string or file name */
@@ -438,7 +438,7 @@ fileupdate(File *f, int notrans, int toterm)
 	return TRUE;
 }
 
-int32_t
+long
 prevseq(Buffer *b)
 {
 	Undo u;
@@ -452,7 +452,7 @@ prevseq(Buffer *b)
 	return u.seq;
 }
 
-int32_t
+long
 undoseq(File *f, int isundo)
 {
 	if(isundo)

+ 7 - 7
sys/src/cmd/sam/io.c

@@ -34,9 +34,9 @@ writef(File *f)
 	Posn n;
 	char *name;
 	int i, samename, newfile;
-	uint32_t dev;
-	uint64_t qid;
-	int32_t mtime, appendonly, length;
+	ulong dev;
+	uvlong qid;
+	long mtime, appendonly, length;
 
 	newfile = 0;
 	samename = Strcmp(&genstr, &f->name) == 0;
@@ -88,9 +88,9 @@ readio(File *f, int *nulls, int setdate, int toterm)
 	Rune *r;
 	Posn nt;
 	Posn p = addr.r.p2;
-	uint32_t dev;
-	uint64_t qid;
-	int32_t mtime;
+	ulong dev;
+	uvlong qid;
+	long mtime;
 	char buf[BLOCKSIZE+1], *s;
 
 	*nulls = FALSE;
@@ -106,7 +106,7 @@ readio(File *f, int *nulls, int setdate, int toterm)
 			r = genbuf;
 			s = buf;
 			while(n > 0){
-				if((*r = *(uint8_t*)s) < Runeself){
+				if((*r = *(uchar*)s) < Runeself){
 					if(*r)
 						r++;
 					else

+ 1 - 1
sys/src/cmd/sam/list.c

@@ -15,7 +15,7 @@
 static void
 growlist(List *l, int esize)
 {
-	uint8_t *p;
+	uchar *p;
 
 	if(l->listptr == nil || l->nalloc == 0){
 		l->nalloc = INCR;

+ 28 - 31
sys/src/cmd/sam/mesg.c

@@ -10,11 +10,11 @@
 #include "sam.h"
 
 Header	h;
-uint8_t	indata[DATASIZE];
-uint8_t	outdata[2*DATASIZE+3];	/* room for overflow message */
-uint8_t	*inp;
-uint8_t	*outp;
-uint8_t	*outmsg = outdata;
+uchar	indata[DATASIZE];
+uchar	outdata[2*DATASIZE+3];	/* room for overflow message */
+uchar	*inp;
+uchar	*outp;
+uchar	*outmsg = outdata;
 Posn	cmdpt;
 Posn	cmdptadv;
 Buffer	snarfbuf;
@@ -23,13 +23,13 @@ int	outbuffered;
 int	tversion;
 
 int	inshort(void);
-int32_t	inlong(void);
-int64_t	invlong(void);
+long	inlong(void);
+vlong	invlong(void);
 int	inmesg(Tmesg);
 
 void	outshort(int);
-void	outlong(int32_t);
-void	outvlong(int64_t);
+void	outlong(long);
+void	outvlong(vlong);
 void	outcopy(int, void*);
 void	outsend(void);
 void	outstart(Hmesg);
@@ -103,7 +103,7 @@ journal(int out, char *s)
 }
 
 void
-journaln(int out, int32_t n)
+journaln(int out, long n)
 {
 	char buf[32];
 
@@ -112,7 +112,7 @@ journaln(int out, int32_t n)
 }
 
 void
-journalv(int out, int64_t v)
+journalv(int out, vlong v)
 {
 	char buf[32];
 
@@ -127,8 +127,8 @@ journalv(int out, int64_t v)
 
 int
 rcvchar(void){
-	static uint8_t buf[64];
-	static i, nleft = 0;
+	static uchar buf[64];
+	static int i, nleft = 0;
 
 	if(nleft <= 0){
 		nleft = read(0, (char *)buf, sizeof buf);
@@ -143,9 +143,9 @@ rcvchar(void){
 int
 rcv(void){
 	int c;
-	static state = 0;
-	static count = 0;
-	static i = 0;
+	static int state = 0;
+	static int count = 0;
+	static int i = 0;
 
 	while((c=rcvchar()) != -1)
 		switch(state){
@@ -201,9 +201,9 @@ inmesg(Tmesg type)
 	Rune buf[1025];
 	char cbuf[64];
 	int i, m;
-	int16_t s;
-	int32_t l, l1;
-	int64_t v;
+	short s;
+	long l, l1;
+	vlong v;
 	File *f;
 	Posn p0, p1, p;
 	Range r;
@@ -219,9 +219,6 @@ inmesg(Tmesg type)
 
 	inp = indata;
 	switch(type){
-	case -1:
-		panic("rcv error");
-
 	default:
 		fprint(2, "unknown type %d\n", type);
 		panic("rcv unknown");
@@ -604,27 +601,27 @@ snarf(File *f, Posn p1, Posn p2, Buffer *buf, int emptyok)
 int
 inshort(void)
 {
-	uint16_t n;
+	ushort n;
 
 	n = inp[0] | (inp[1]<<8);
 	inp += 2;
 	return n;
 }
 
-int32_t
+long
 inlong(void)
 {
-	uint32_t n;
+	ulong n;
 
 	n = inp[0] | (inp[1]<<8) | (inp[2]<<16) | (inp[3]<<24);
 	inp += 4;
 	return n;
 }
 
-int64_t
+vlong
 invlong(void)
 {
-	int64_t v;
+	vlong v;
 	
 	v = (inp[7]<<24) | (inp[6]<<16) | (inp[5]<<8) | inp[4];
 	v = (v<<16) | (inp[3]<<8) | inp[2];
@@ -663,7 +660,7 @@ outT0(Hmesg type)
 }
 
 void
-outTl(Hmesg type, int32_t l)
+outTl(Hmesg type, long l)
 {
 	outstart(type);
 	outlong(l);
@@ -760,7 +757,7 @@ outTsl(Hmesg type, int s, Posn l)
 }
 
 void
-outTsv(Hmesg type, int s, int64_t v)
+outTsv(Hmesg type, int s, vlong v)
 {
 	outstart(type);
 	outshort(s);
@@ -792,7 +789,7 @@ outshort(int s)
 }
 
 void
-outlong(int32_t l)
+outlong(long l)
 {
 	*outp++ = l;
 	*outp++ = l>>8;
@@ -801,7 +798,7 @@ outlong(int32_t l)
 }
 
 void
-outvlong(int64_t v)
+outvlong(vlong v)
 {
 	int i;
 

+ 1 - 1
sys/src/cmd/sam/multi.c

@@ -10,7 +10,7 @@
 #include "sam.h"
 
 List	file = { 'p' };
-uint16_t	tag;
+ushort	tag;
 
 File *
 newfile(void)

+ 3 - 1
sys/src/cmd/sam/parse.h

@@ -54,7 +54,9 @@ struct Cmdtab
 	uchar	count;		/* takes a count e.g. s2/// */
 	char	*token;		/* takes text terminated by one of these */
 	int	(*fn)(File*, Cmd*);	/* function to call with parse tree */
-}cmdtab[];
+};
+
+extern Cmdtab cmdtab[];
 
 enum Defaddr{	/* default addresses */
 	aNo,

+ 5 - 8
sys/src/cmd/sam/plan9.c

@@ -9,7 +9,7 @@
 
 #include "sam.h"
 
-Rune	samname[] = L"~~sam~~";
+Rune	*samname = L"~~sam~~";
 
 Rune *left[]= {
 	L"{[(<«",
@@ -59,9 +59,7 @@ print_s(char *s, String *a)
 }
 
 int
-statfile(char *name, uint32_t *dev, uint64_t *id, int32_t *time,
-	 int32_t *length,
-	 int32_t *appendonly)
+statfile(char *name, ulong *dev, uvlong *id, long *time, long *length, long *appendonly)
 {
 	Dir *dirb;
 
@@ -83,8 +81,7 @@ statfile(char *name, uint32_t *dev, uint64_t *id, int32_t *time,
 }
 
 int
-statfd(int fd, uint32_t *dev, uint64_t *id, int32_t *time, int32_t *length,
-       int32_t *appendonly)
+statfd(int fd, ulong *dev, uvlong *id, long *time, long *length, long *appendonly)
 {
 	Dir *dirb;
 
@@ -144,7 +141,7 @@ samerr(char *buf)
 }
 
 void*
-emalloc(uint32_t n)
+emalloc(ulong n)
 {
 	void *p;
 
@@ -156,7 +153,7 @@ emalloc(uint32_t n)
 }
 
 void*
-erealloc(void *p, uint32_t n)
+erealloc(void *p, ulong n)
 {
 	p = realloc(p, n);
 	if(p == 0)

+ 1 - 1
sys/src/cmd/sam/rasp.c

@@ -105,7 +105,7 @@ raspflush(File *f)
 void
 raspdelete(File *f, uint p1, uint p2, int toterm)
 {
-	int32_t n;
+	long n;
 
 	n = p2 - p1;
 	if(n == 0)

+ 3 - 3
sys/src/cmd/sam/regexp.c

@@ -18,7 +18,7 @@ typedef struct Inst Inst;
 
 struct Inst
 {
-	int32_t	type;	/* <= Runemax ==> literal, otherwise action */
+	long	type;	/* <= Runemax ==> literal, otherwise action */
 	union {
 		int rsid;
 		int rsubid;
@@ -461,7 +461,7 @@ lex(void){
 	return c;
 }
 
-int32_t
+long
 nextrec(void){
 	if(exprp[0]==0 || (exprp[0]=='\\' && exprp[1]==0))
 		regerror(Ebadclass);
@@ -479,7 +479,7 @@ nextrec(void){
 void
 bldcclass(void)
 {
-	int32_t c1, c2, n, na;
+	long c1, c2, n, na;
 	Rune *classp;
 
 	classp = emalloc(DCLASS*RUNESIZE);

+ 2 - 2
sys/src/cmd/sam/sam.c

@@ -36,7 +36,7 @@ char	*samterm = SAMTERM;
 char	*rsamname = RSAM;
 File	*lastfile;
 Disk	*disk;
-int32_t	seq;
+long	seq;
 
 Rune	baddir[] = { '<', 'b', 'a', 'd', 'd', 'i', 'r', '>', '\n'};
 
@@ -549,7 +549,7 @@ loadflist(String *s)
 		;
 	if((c==' ' || c=='\t') && s->s[i]!='\n'){
 		if(s->s[i]=='<'){
-			Strdelete(s, 0L, (int32_t)i+1);
+			Strdelete(s, 0L, (long)i+1);
 			readcmd(s);
 		}else{
 			Strzero(&genstr);

+ 12 - 5
sys/src/cmd/sam/sam.h

@@ -29,6 +29,13 @@
 #define	INCR		25
 #define	STRSIZE		(2*BLOCKSIZE)
 
+// Plan9 types
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef uint64_t uvlong;
+typedef uint32_t ulong;
+typedef int64_t vlong;
+
 typedef long		Posn;		/* file position or address */
 typedef	ushort		Mod;		/* modification number */
 
@@ -254,7 +261,7 @@ void	doubleclick(File*, Posn);
 void	dprint(char*, ...);
 void	edit(File*, int);
 void	*emalloc(ulong);
-void	*erealloc(void*, uint32_t);
+void	*erealloc(void*, ulong);
 void	error(Err);
 void	error_c(Err, int);
 void	error_r(Err, char*);
@@ -301,8 +308,8 @@ void	snarf(File*, Posn, Posn, Buffer*, int);
 void	sortname(File*);
 void	startup(char*, int, char**, char**);
 void	state(File*, int);
-int	statfd(int, uint32_t*, uvlong*, long*, long*, long*);
-int	statfile(char*, uint32_t*, uvlong*, long*, long*, long*);
+int	statfd(int, ulong*, uvlong*, long*, long*, long*);
+int	statfile(char*, ulong*, uvlong*, long*, long*, long*);
 void	Straddc(String*, int);
 void	Strclose(String*);
 int	Strcmp(String*, String*);
@@ -312,7 +319,7 @@ void	Strduplstr(String*, String*);
 void	Strinit(String*);
 void	Strinit0(String*);
 void	Strinsert(String*, String*, Posn);
-void	Strinsure(String*, uint32_t);
+void	Strinsure(String*, ulong);
 int	Strispre(String*, String*);
 void	Strzero(String*);
 int	Strlen(Rune*);
@@ -340,7 +347,7 @@ void	writef(File*);
 Posn	writeio(File*);
 Discdesc *Dstart(void);
 
-extern Rune	samname[];	/* compiler dependent */
+extern Rune	*samname;	/* compiler dependent */
 extern Rune	*left[];
 extern Rune	*right[];
 

+ 2 - 2
sys/src/cmd/sam/shell.c

@@ -20,7 +20,7 @@ void	checkerrs(void);
 int
 plan9(File *f, int type, String *s, int nest)
 {
-	int32_t l;
+	long l;
 	int m;
 	int pid, fd;
 	int retcode;
@@ -142,7 +142,7 @@ checkerrs(void)
 	char buf[256];
 	int f, n, nl;
 	char *p;
-	int32_t l;
+	long l;
 
 	if(statfile(errfile, 0, 0, 0, &l, 0) > 0 && l != 0){
 		if((f=open((char *)errfile, 0)) != -1){

+ 1 - 1
sys/src/cmd/sam/string.c

@@ -80,7 +80,7 @@ Straddc(String *p, int c)
 }
 
 void
-Strinsure(String *p, uint32_t n)
+Strinsure(String *p, ulong n)
 {
 	if(n > STRSIZE)
 		error(Etoolong);

+ 1 - 1
sys/src/cmd/sam/sys.c

@@ -62,7 +62,7 @@ Write(int f, void *a, int n)
 }
 
 void
-Seek(int f, int32_t n, int w)
+Seek(int f, long n, int w)
 {
 	if(seek(f, n, w)==-1)
 		syserror("seek");

+ 2 - 2
sys/src/cmd/sam/util.c

@@ -12,7 +12,7 @@
 void
 cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls)
 {
-	uint8_t *q;
+	uchar *q;
 	Rune *s;
 	int j, w;
 
@@ -23,7 +23,7 @@ cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls)
 	 * knows this.  If n is a firm limit, the caller should
 	 * set p[n] = 0.
 	 */
-	q = (uint8_t*)p;
+	q = (uchar*)p;
 	s = r;
 	for(j=0; j<n; j+=w){
 		if(*q < Runeself){

+ 82 - 0
sys/src/cmd/samterm/build.json

@@ -0,0 +1,82 @@
+{
+	"samterm": {
+		"Cflags": [
+			"-ffreestanding",
+			"-fno-builtin",
+			"-fno-omit-frame-pointer",
+			"-fplan9-extensions",
+			"-fvar-tracking",
+			"-fvar-tracking-assignments",
+			"-g",
+			"-gdwarf-2",
+			"-ggdb",
+			"-mcmodel=small",
+			"-mno-red-zone",
+			"-O2",
+			"-I../sam",
+			"-static",
+			"-Wall",
+			"-Wno-missing-braces",
+			"-Wno-parentheses",
+		    "-Wno-pointer-sign",
+			"-Wno-unknown-pragmas"
+		],
+		"Install": "/$ARCH/bin/aux",
+		"Post": [
+			"rm *.o",
+			"OBJDUMP=objdump; $TOOLPREFIX$OBJDUMP -S $HARVEY/$ARCH/bin/samterm > samterm.asm" 
+		],
+		"Oflags": [
+			"-static",
+			"-e_main",
+			"-lavl",
+			"-lcomplete",
+			"-lcontrol",
+			"-ldisk",
+			"-lflate",
+			"-lframe",
+			"-lgeometry",
+			"-lhttpd",
+			"-lbin",
+			"-llex",
+			"-lmemdraw",
+			"-lmemlayer",
+			"-lmemdraw",
+			"-ldraw",
+			"-lplumb",
+			"-lregexp",
+			"-lstdio",
+			"-lString",
+			"-lsunrpc",
+			"-loventi",
+			"-l9p",
+			"-lauth",
+			"-lauthsrv",
+			"-lndb",
+			"-lip",
+			"-lventi",
+			"-lsec",
+			"-lauth",
+			"-lmp",
+			"-lthread",
+			"-lmach",
+			"-lbio",
+			"-lc"
+		],
+		"Pre": [
+			"rm -f *.tag.*"
+		],
+		"Program": "samterm",
+	 	"SourceFiles": [
+			"flayer.c",
+			"icons.c",
+			"io.c",
+			"main.c",
+			"menu.c",
+			"mesg.c",
+			"plan9.c",
+			"rasp.c",
+			"scroll.c"
+		]
+	}
+}

+ 9 - 9
sys/src/cmd/samterm/flayer.c

@@ -53,7 +53,7 @@ flstart(Rectangle r)
 }
 
 void
-flnew(Flayer *l, Rune *(*fn)(Flayer*, int32_t, uint32_t*), int u0, void *u1)
+flnew(Flayer *l, Rune *(*fn)(Flayer*, long, ulong*), int u0, void *u1)
 {
 	if(nllist == nlalloc){
 		nlalloc += DELTA;
@@ -240,7 +240,7 @@ lldelete(Flayer *l)
 }
 
 void
-flinsert(Flayer *l, Rune *sp, Rune *ep, int32_t p0)
+flinsert(Flayer *l, Rune *sp, Rune *ep, long p0)
 {
 	if(flprepare(l)){
 		frinsert(&l->f, sp, ep, p0-l->origin);
@@ -251,7 +251,7 @@ flinsert(Flayer *l, Rune *sp, Rune *ep, int32_t p0)
 }
 
 void
-fldelete(Flayer *l, int32_t p0, int32_t p1)
+fldelete(Flayer *l, long p0, long p1)
 {
 	if(flprepare(l)){
 		p0 -= l->origin;
@@ -288,9 +288,9 @@ flselect(Flayer *l)
 }
 
 void
-flsetselect(Flayer *l, int32_t p0, int32_t p1)
+flsetselect(Flayer *l, long p0, long p1)
 {
-	uint32_t fp0, fp1;
+	ulong fp0, fp1;
 
 	l->click = 0;
 	if(l->visible==None || !flprepare(l)){
@@ -332,9 +332,9 @@ flsetselect(Flayer *l, int32_t p0, int32_t p1)
 }
 
 void
-flfp0p1(Flayer *l, uint32_t *pp0, uint32_t *pp1)
+flfp0p1(Flayer *l, ulong *pp0, ulong *pp1)
 {
-	int32_t p0 = l->p0-l->origin, p1 = l->p1-l->origin;
+	long p0 = l->p0-l->origin, p1 = l->p1-l->origin;
 
 	if(p0 < 0)
 		p0 = 0;
@@ -416,7 +416,7 @@ int
 flprepare(Flayer *l)
 {
 	Frame *f;
-	uint32_t n;
+	ulong n;
 	Rune *r;
 
 	if(l->visible == None)
@@ -435,7 +435,7 @@ flprepare(Flayer *l)
 		if(f->maxtab == 0)
 			fontbuggered(f->font->name);
 		r = (*l->textfn)(l, n, &n);
-		frinsert(f, r, r+n, (uint32_t)0);
+		frinsert(f, r, r+n, (ulong)0);
 		frdrawsel(f, frptofchar(f, f->p0), f->p0, f->p1, 0);
 		flfp0p1(l, &f->p0, &f->p1);
 		frdrawsel(f, frptofchar(f, f->p0), f->p0, f->p1, 1);

+ 11 - 4
sys/src/cmd/samterm/flayer.h

@@ -7,6 +7,14 @@
  * in the LICENSE file.
  */
 
+// Plan9 types
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef uint64_t uvlong;
+typedef uint32_t ulong;
+typedef int64_t vlong;
+
+
 typedef enum Vis{
 	None=0,
 	Some,
@@ -25,7 +33,7 @@ struct Flayer
 	long		origin;	/* offset of first char in flayer */
 	long		p0, p1;
 	long		click;	/* time at which selection click occurred, in HZ */
-	Rune		*(*textfn)(Flayer*, long, uint32_t*);
+	Rune		*(*textfn)(Flayer*, long, ulong*);
 	int		user0;
 	void		*user1;
 	Rectangle	entire;
@@ -37,11 +45,10 @@ struct Flayer
 void	flborder(Flayer*, int);
 void	flclose(Flayer*);
 void	fldelete(Flayer*, long, long);
-void	flfp0p1(Flayer*, uint32_t*, uint32_t*);
+void	flfp0p1(Flayer*, ulong*, ulong*);
 void	flinit(Flayer*, Rectangle, Font*, Image**);
 void	flinsert(Flayer*, Rune*, Rune*, long);
-void	flnew(Flayer*, Rune *(*fn)(Flayer*, long, uint32_t*), int,
-		  void*);
+void	flnew(Flayer*, Rune *(*fn)(Flayer*, long, ulong*), int, void*);
 int	flprepare(Flayer*);
 Rectangle flrect(Flayer*, Rectangle);
 void	flrefresh(Flayer*, Rectangle, int);

+ 14 - 6
sys/src/cmd/samterm/io.c

@@ -24,11 +24,11 @@ int	got;
 int	block;
 int	kbdc;
 int	resized;
-uint8_t	*hostp;
-uint8_t	*hoststop;
-uint8_t	*plumbbase;
-uint8_t	*plumbp;
-uint8_t	*plumbstop;
+uchar	*hostp;
+uchar	*hoststop;
+uchar	*plumbbase;
+uchar	*plumbp;
+uchar	*plumbstop;
 Channel	*plumbc;
 Channel	*hostc;
 Mousectl	*mousectl;
@@ -36,6 +36,13 @@ Mouse	*mousep;
 Keyboardctl *keyboardctl;
 void	panic(char*);
 
+void
+closeio(void)
+{
+	closekeyboard(keyboardctl);
+	closemouse(mousectl);
+}
+
 void
 initio(void)
 {
@@ -51,6 +58,7 @@ initio(void)
 		fprint(2, "samterm: keyboard init failed: %r\n");
 		threadexitsall("kbd");
 	}
+	atexit(closeio);
 	hoststart();
 	if(plumbstart() < 0)
 		extstart();
@@ -100,7 +108,7 @@ waitforio(void)
 	Alt alts[NRes+1];
 	Rune r;
 	int i;
-	uint32_t type;
+	ulong type;
 
 again:
 

+ 25 - 25
sys/src/cmd/samterm/main.c

@@ -22,15 +22,15 @@ int	mainstacksize = 16*1024;
 
 Text	cmd;
 Rune	*scratch;
-int32_t	nscralloc;
+long	nscralloc;
 Cursor	*cursor;
 Flayer	*which = 0;
 Flayer	*work = 0;
-int32_t	snarflen;
-int32_t	typestart = -1;
-int32_t	typeend = -1;
-int32_t	typeesc = -1;
-int32_t	modified = 0;		/* strange lookahead for menus */
+long	snarflen;
+long	typestart = -1;
+long	typeend = -1;
+long	typeesc = -1;
+long	modified = 0;		/* strange lookahead for menus */
 char	hostlock = 1;
 char	hasunlocked = 0;
 int	maxtab = 8;
@@ -169,7 +169,7 @@ closeup(Flayer *l)
 		work = 0;
 	if(--t->nwin == 0){
 		rclear(&t->rasp);
-		free((uint8_t *)t);
+		free((uchar *)t);
 		text[m] = 0;
 	}else if(l == &t->l[t->front]){
 		for(m=0; m<NL; m++)	/* find one; any one will do */
@@ -197,7 +197,7 @@ duplicate(Flayer *l, Rectangle r, Font *f, int close)
 	Text *t=(Text *)l->user1;
 	Flayer *nl = findl(t);
 	Rune *rp;
-	uint32_t n;
+	ulong n;
 
 	if(nl){
 		flnew(nl, gettext, l->user0, (char *)t);
@@ -265,7 +265,7 @@ snarf(Text *t, int w)
 void
 cut(Text *t, int w, int save, int check)
 {
-	int32_t p0, p1;
+	long p0, p1;
 	Flayer *l;
 
 	l = &t->l[w];
@@ -296,7 +296,7 @@ paste(Text *t, int w)
 }
 
 void
-scrorigin(Flayer *l, int but, int32_t p0)
+scrorigin(Flayer *l, int but, long p0)
 {
 	Text *t=(Text *)l->user1;
 
@@ -330,17 +330,17 @@ alnum(int c)
 }
 
 int
-raspc(Rasp *r, int32_t p)
+raspc(Rasp *r, long p)
 {
-	uint32_t n;
+	ulong n;
 	rload(r, p, p+1, &n);
 	if(n)
 		return scratch[0];
 	return 0;
 }
 
-int32_t
-ctlw(Rasp *r, int32_t o, int32_t p)
+long
+ctlw(Rasp *r, long o, long p)
 {
 	int c;
 
@@ -356,8 +356,8 @@ ctlw(Rasp *r, int32_t o, int32_t p)
 	return p>=o? p : o;
 }
 
-int32_t
-ctlu(Rasp *r, int32_t o, int32_t p)
+long
+ctlu(Rasp *r, long o, long p)
 {
 	if(--p < o)
 		return o;
@@ -369,7 +369,7 @@ ctlu(Rasp *r, int32_t o, int32_t p)
 }
 
 int
-center(Flayer *l, int32_t a)
+center(Flayer *l, long a)
 {
 	Text *t;
 
@@ -384,11 +384,11 @@ center(Flayer *l, int32_t a)
 }
 
 int
-onethird(Flayer *l, int32_t a)
+onethird(Flayer *l, long a)
 {
 	Text *t;
 	Rectangle s;
-	int32_t lines;
+	long lines;
 
 	t = l->user1;
 	if(!t->lock && (a<l->origin || l->origin+l->f.nchars<a)){
@@ -408,7 +408,7 @@ void
 flushtyping(int clearesc)
 {
 	Text *t;
-	uint32_t n;
+	ulong n;
 
 	if(clearesc)
 		typeesc = -1;	
@@ -469,7 +469,7 @@ type(Flayer *l, int res)	/* what a bloody mess this is */
 	Rune buf[100];
 	Rune *p = buf;
 	int c, backspacing;
-	int32_t a, a0;
+	long a, a0;
 	int scrollkey;
 
 	scrollkey = 0;
@@ -639,7 +639,7 @@ panic(char *s)
 }
 
 void
-panic1(Display*, char *s)
+panic1(Display* d, char *s)
 {
 	fprint(2, "samterm:panic: ");
 	perror(s);
@@ -647,7 +647,7 @@ panic1(Display*, char *s)
 }
 
 Rune*
-gettext(Flayer *l, int32_t n, uint32_t *np)
+gettext(Flayer *l, long n, ulong *np)
 {
 	Text *t;
 
@@ -656,14 +656,14 @@ gettext(Flayer *l, int32_t n, uint32_t *np)
 	return scratch;
 }
 
-int32_t
+long
 scrtotal(Flayer *l)
 {
 	return ((Text *)l->user1)->rasp.nrunes;
 }
 
 void*
-alloc(uint32_t n)
+alloc(ulong n)
 {
 	void *p;
 

+ 5 - 5
sys/src/cmd/samterm/menu.c

@@ -18,9 +18,9 @@
 #include "flayer.h"
 #include "samterm.h"
 
-uint8_t	**name;	/* first byte is ' ' or '\'': modified state */
+uchar	**name;	/* first byte is ' ' or '\'': modified state */
 Text	**text;	/* pointer to Text associated with file */
-uint16_t	*tag;		/* text[i].tag, even if text[i] not defined */
+ushort	*tag;		/* text[i].tag, even if text[i] not defined */
 int	nname;
 int	mname;
 int	mw;
@@ -245,7 +245,7 @@ whichmenu(int tg)
 }
 
 void
-menuins(int n, uint8_t *s, Text *t, int m, int tg)
+menuins(int n, uchar *s, Text *t, int m, int tg)
 {
 	int i;
 
@@ -295,12 +295,12 @@ setpat(char *s)
 }
 
 #define	NBUF	64
-static uint8_t buf[NBUF*UTFmax]={' ', ' ', ' ', ' '};
+static uchar buf[NBUF*UTFmax]={' ', ' ', ' ', ' '};
 
 char *
 paren(char *s)
 {
-	uint8_t *t = buf;
+	uchar *t = buf;
 
 	*t++ = '(';
 	do; while(*t++ = *s++);

+ 43 - 45
sys/src/cmd/samterm/mesg.c

@@ -21,18 +21,18 @@
 
 #define	HSIZE	3	/* Type + short count */
 Header	h;
-uint8_t	indata[DATASIZE+1];	/* room for NUL */
-uint8_t	outdata[DATASIZE];
-int16_t	outcount;
+uchar	indata[DATASIZE+1];	/* room for NUL */
+uchar	outdata[DATASIZE];
+short	outcount;
 int	hversion;
 int	exiting;
 
 void	inmesg(Hmesg, int);
 int	inshort(int);
-int32_t	inlong(int);
-int64_t	invlong(int);
-void	hsetdot(int, int32_t, int32_t);
-void	hmoveto(int, int32_t);
+long	inlong(int);
+vlong	invlong(int);
+void	hsetdot(int, long, long);
+void	hmoveto(int, long);
 void	hsetsnarf(int);
 void	hplumb(int);
 void	clrlock(void);
@@ -104,14 +104,12 @@ inmesg(Hmesg type, int count)
 {
 	Text *t;
 	int i, m;
-	int32_t l;
+	long l;
 	Flayer *lp;
 
 	m = inshort(0);
 	l = inlong(2);
 	switch(type){
-	case -1:
-		panic("rcv error");
 	default:
 		fprint(2, "type %d\n", type);
 		panic("rcv unknown");
@@ -179,7 +177,7 @@ inmesg(Hmesg type, int count)
 		break;
 
 	case Hnewname:
-		menuins(0, (uint8_t *)"", (Text *)0, ' ', m);
+		menuins(0, (uchar *)"", (Text *)0, ' ', m);
 		break;
 
 	case Hcheck0:
@@ -329,7 +327,7 @@ clrlock(void)
 void
 startfile(Text *t)
 {
-	outTsv(Tstartfile, t->tag, (int64_t)t);	/* for 64-bit pointers */
+	outTsv(Tstartfile, t->tag, (vlong)t);	/* for 64-bit pointers */
 	setlock();
 }
 
@@ -337,7 +335,7 @@ void
 startnewfile(int type, Text *t)
 {
 	t->tag = Untagged;
-	outTv(type, (int64_t)t);			/* for 64-bit pointers */
+	outTv(type, (vlong)t);			/* for 64-bit pointers */
 }
 
 int
@@ -346,17 +344,17 @@ inshort(int n)
 	return indata[n]|(indata[n+1]<<8);
 }
 
-int32_t
+long
 inlong(int n)
 {
 	return indata[n]|(indata[n+1]<<8)|
-		((int32_t)indata[n+2]<<16)|((int32_t)indata[n+3]<<24);
+		((long)indata[n+2]<<16)|((long)indata[n+3]<<24);
 }
 
-int64_t
+vlong
 invlong(int n)
 {
-	int64_t v;
+	vlong v;
 
 	v = (indata[n+7]<<24) | (indata[n+6]<<16) | (indata[n+5]<<8) | indata[n+4];
 	v = (v<<16) | (indata[n+3]<<8) | indata[n+2];
@@ -372,7 +370,7 @@ outT0(Tmesg type)
 }
 
 void
-outTl(Tmesg type, int32_t l)
+outTl(Tmesg type, long l)
 {
 	outstart(type);
 	outlong(l);
@@ -397,7 +395,7 @@ outTss(Tmesg type, int s1, int s2)
 }
 
 void
-outTsll(Tmesg type, int s1, int32_t l1, int32_t l2)
+outTsll(Tmesg type, int s1, long l1, long l2)
 {
 	outstart(type);
 	outshort(s1);
@@ -407,7 +405,7 @@ outTsll(Tmesg type, int s1, int32_t l1, int32_t l2)
 }
 
 void
-outTsl(Tmesg type, int s1, int32_t l1)
+outTsl(Tmesg type, int s1, long l1)
 {
 	outstart(type);
 	outshort(s1);
@@ -416,7 +414,7 @@ outTsl(Tmesg type, int s1, int32_t l1)
 }
 
 void
-outTsv(Tmesg type, int s1, int64_t v1)
+outTsv(Tmesg type, int s1, vlong v1)
 {
 	outstart(type);
 	outshort(s1);
@@ -425,7 +423,7 @@ outTsv(Tmesg type, int s1, int64_t v1)
 }
 
 void
-outTv(Tmesg type, int64_t v1)
+outTv(Tmesg type, vlong v1)
 {
 	outstart(type);
 	outvlong(v1);
@@ -433,7 +431,7 @@ outTv(Tmesg type, int64_t v1)
 }
 
 void
-outTslS(Tmesg type, int s1, int32_t l1, Rune *s)
+outTslS(Tmesg type, int s1, long l1, Rune *s)
 {
 	char buf[DATASIZE*3+1];
 	char *c;
@@ -445,12 +443,12 @@ outTslS(Tmesg type, int s1, int32_t l1, Rune *s)
 	while(*s)
 		c += runetochar(c, s++);
 	*c++ = 0;
-	outcopy(c-buf, (uint8_t *)buf);
+	outcopy(c-buf, (uchar *)buf);
 	outsend();
 }
 
 void
-outTsls(Tmesg type, int s1, int32_t l1, int s2)
+outTsls(Tmesg type, int s1, long l1, int s2)
 {
 	outstart(type);
 	outshort(s1);
@@ -467,7 +465,7 @@ outstart(Tmesg type)
 }
 
 void
-outcopy(int count, uint8_t *data)
+outcopy(int count, uchar *data)
 {
 	while(count--)
 		outdata[HSIZE+outcount++] = *data++;	
@@ -476,7 +474,7 @@ outcopy(int count, uint8_t *data)
 void
 outshort(int s)
 {
-	uint8_t buf[2];
+	uchar buf[2];
 
 	buf[0]=s;
 	buf[1]=s>>8;
@@ -484,9 +482,9 @@ outshort(int s)
 }
 
 void
-outlong(int32_t l)
+outlong(long l)
 {
-	uint8_t buf[4];
+	uchar buf[4];
 
 	buf[0]=l;
 	buf[1]=l>>8;
@@ -496,10 +494,10 @@ outlong(int32_t l)
 }
 
 void
-outvlong(int64_t v)
+outvlong(vlong v)
 {
 	int i;
-	uint8_t buf[8];
+	uchar buf[8];
 
 	for(i = 0; i < sizeof(buf); i++){
 		buf[i] = v;
@@ -522,7 +520,7 @@ outsend(void)
 
 
 void
-hsetdot(int m, int32_t p0, int32_t p1)
+hsetdot(int m, long p0, long p1)
 {
 	Text *t = whichtext(m);
 	Flayer *l = &t->l[t->front];
@@ -532,12 +530,12 @@ hsetdot(int m, int32_t p0, int32_t p1)
 }
 
 void
-horigin(int m, int32_t p0)
+horigin(int m, long p0)
 {
 	Text *t = whichtext(m);
 	Flayer *l = &t->l[t->front];
-	int32_t a;
-	uint32_t n;
+	long a;
+	ulong n;
 	Rune *r;
 
 	if(!flprepare(l)){
@@ -560,7 +558,7 @@ horigin(int m, int32_t p0)
 }
 
 void
-hmoveto(int m, int32_t p0)
+hmoveto(int m, long p0)
 {
 	Text *t = whichtext(m);
 	Flayer *l = &t->l[t->front];
@@ -575,7 +573,7 @@ hcheck(int m)
 	Flayer *l;
 	Text *t;
 	int reqd = 0, i;
-	int32_t n, nl, a;
+	long n, nl, a;
 	Rune *r;
 
 	if(m == Untagged)
@@ -693,12 +691,12 @@ hplumb(int nc)
 }
 
 void
-hgrow(int m, int32_t a, int32_t new, int req)
+hgrow(int m, long a, long new, int req)
 {
 	int i;
 	Flayer *l;
 	Text *t = whichtext(m);
-	int32_t o, b;
+	long o, b;
 
 	if(new <= 0)
 		panic("hgrow");
@@ -727,11 +725,11 @@ hgrow(int m, int32_t a, int32_t new, int req)
 }
 
 int
-hdata1(Text *t, int32_t a, Rune *r, int len)
+hdata1(Text *t, long a, Rune *r, int len)
 {
 	int i;
 	Flayer *l;
-	int32_t o, b;
+	long o, b;
 
 	for(l = &t->l[0], i=0; i<NL; i++, l++){
 		if(l->textfn==0)
@@ -749,7 +747,7 @@ hdata1(Text *t, int32_t a, Rune *r, int len)
 }
 
 int
-hdata(int m, int32_t a, uint8_t *s, int len)
+hdata(int m, long a, uchar *s, int len)
 {
 	int i, w;
 	Text *t = whichtext(m);
@@ -766,7 +764,7 @@ hdata(int m, int32_t a, uint8_t *s, int len)
 }
 
 int
-hdatarune(int m, int32_t a, Rune *r, int len)
+hdatarune(int m, long a, Rune *r, int len)
 {
 	Text *t = whichtext(m);
 
@@ -778,12 +776,12 @@ hdatarune(int m, int32_t a, Rune *r, int len)
 }
 
 void
-hcut(int m, int32_t a, int32_t old)
+hcut(int m, long a, long old)
 {
 	Flayer *l;
 	Text *t = whichtext(m);
 	int i;
-	int32_t o, b;
+	long o, b;
 
 	if(t->lock)
 		--t->lock;

+ 11 - 11
sys/src/cmd/samterm/rasp.c

@@ -89,7 +89,7 @@ rsdelete(Rasp *r, Section *s)
 }
 
 void
-splitsect(Rasp *r, Section *s, int32_t n0)
+splitsect(Rasp *r, Section *s, long n0)
 {
 	if(s == 0)
 		panic("splitsect");
@@ -106,7 +106,7 @@ splitsect(Rasp *r, Section *s, int32_t n0)
 }
 
 Section *
-findsect(Rasp *r, Section *s, int32_t p, int32_t q)	/* find sect containing q and put q on a sect boundary */
+findsect(Rasp *r, Section *s, long p, long q)	/* find sect containing q and put q on a sect boundary */
 {
 	if(s==0 && p!=q)
 		panic("findsect");
@@ -120,7 +120,7 @@ findsect(Rasp *r, Section *s, int32_t p, int32_t q)	/* find sect containing q an
 }
 
 void
-rresize(Rasp *r, int32_t a, int32_t old, int32_t new)
+rresize(Rasp *r, long a, long old, long new)
 {
 	Section *s, *t, *ns;
 
@@ -140,7 +140,7 @@ rresize(Rasp *r, int32_t a, int32_t old, int32_t new)
 }
 
 void
-rdata(Rasp *r, int32_t p0, int32_t p1, Rune *cp)
+rdata(Rasp *r, long p0, long p1, Rune *cp)
 {
 	Section *s, *t, *ns;
 
@@ -184,10 +184,10 @@ Strcpy(Rune *to, Rune *from)
 }
 
 Rune*
-rload(Rasp *r, uint32_t p0, uint32_t p1, uint32_t *nrp)
+rload(Rasp *r, ulong p0, ulong p1, ulong *nrp)
 {
 	Section *s;
-	int32_t p;
+	long p;
 	int n, nb;
 
 	nb = 0;
@@ -220,10 +220,10 @@ rload(Rasp *r, uint32_t p0, uint32_t p1, uint32_t *nrp)
 }
 
 int
-rmissing(Rasp *r, uint32_t p0, uint32_t p1)
+rmissing(Rasp *r, ulong p0, ulong p1)
 {
 	Section *s;
-	int32_t p;
+	long p;
 	int n, nm=0;
 
 	for(p=0,s=r->sect; s && p+s->nrunes<=p0; s=s->next)
@@ -243,10 +243,10 @@ rmissing(Rasp *r, uint32_t p0, uint32_t p1)
 }
 
 int
-rcontig(Rasp *r, uint32_t p0, uint32_t p1, int text)
+rcontig(Rasp *r, ulong p0, ulong p1, int text)
 {
 	Section *s;
-	int32_t p, n;
+	long p, n;
 	int np=0;
 
 	for(p=0,s=r->sect; s && p+s->nrunes<=p0; s=s->next)
@@ -264,7 +264,7 @@ rcontig(Rasp *r, uint32_t p0, uint32_t p1, int text)
 }
 
 void
-Strgrow(Rune **s, int32_t *n, int want)	/* can always toss the old data when called */
+Strgrow(Rune **s, long *n, int want)	/* can always toss the old data when called */
 {
 	if(*n >= want)
 		return;

+ 5 - 5
sys/src/cmd/samterm/samterm.h

@@ -96,8 +96,8 @@ extern int	plumbfd;
 extern int	exiting;
 extern int	autoindent;
 
-Rune	*gettext(Flayer*, long, uint32_t*);
-void	*alloc(uint32_t n);
+Rune	*gettext(Flayer*, long, ulong*);
+void	*alloc(ulong n);
 
 void	iconinit(void);
 void	getscreen(int, char**);
@@ -148,14 +148,14 @@ void	horigin(int, long);
 void	hgrow(int, long, long, int);
 int	hdata(int, long, uchar*, int);
 int	hdatarune(int, long, Rune*, int);
-Rune	*rload(Rasp*, uint32_t, uint32_t, uint32_t*);
+Rune	*rload(Rasp*, ulong, ulong, ulong*);
 void	menuins(int, uchar*, Text*, int, int);
 void	menudel(int);
 Text	*sweeptext(int, int);
 void	setpat(char*);
 void	scrdraw(Flayer*, long tot);
-int	rcontig(Rasp*, uint32_t, uint32_t, int);
-int	rmissing(Rasp*, uint32_t, uint32_t);
+int	rcontig(Rasp*, ulong, ulong, int);
+int	rmissing(Rasp*, ulong, ulong);
 void	rresize(Rasp *, long, long, long);
 void	rdata(Rasp*, long, long, Rune*);
 void	rclean(Rasp*);

+ 5 - 5
sys/src/cmd/samterm/scroll.c

@@ -36,7 +36,7 @@ scrtemps(void)
 }
 
 Rectangle
-scrpos(Rectangle r, int32_t p0, int32_t p1, int32_t tot)
+scrpos(Rectangle r, long p0, long p1, long tot)
 {
 	Rectangle q;
 	int h;
@@ -82,7 +82,7 @@ scrunmark(Flayer *l, Rectangle r)
 }
 
 void
-scrdraw(Flayer *l, int32_t tot)
+scrdraw(Flayer *l, long tot)
 {
 	Rectangle r, r1, r2;
 	Image *b;
@@ -115,10 +115,10 @@ void
 scroll(Flayer *l, int but)
 {
 	int in = 0, oin;
-	int32_t tot = scrtotal(l);
+	long tot = scrtotal(l);
 	Rectangle scr, r, s, rt;
 	int x, y, my, oy, h;
-	int32_t p0;
+	long p0;
 
 	s = l->scroll;
 	x = s.min.x+FLSCROLLWID/2;
@@ -167,7 +167,7 @@ scroll(Flayer *l, int but)
 		scrunmark(l, r);
 		p0 = 0;
 		if(but == 1)
-			p0 = (int32_t)(my-s.min.y)/l->f.font->height+1;
+			p0 = (long)(my-s.min.y)/l->f.font->height+1;
 		else if(but == 2){
 			if(tot > 1024L*1024L)
 				p0 = ((tot>>10)*(y-s.min.y)/h)<<10;