Browse Source

Plan 9 from Bell Labs 2013-09-27

David du Colombier 10 years ago
parent
commit
f1bf8b3cb7
47 changed files with 504 additions and 650 deletions
  1. 8 0
      sys/man/1/pcc
  2. 1 1
      sys/src/cmd/awk/mkfile
  3. 42 16
      sys/src/cmd/compress/compress.c
  4. 1 1
      sys/src/cmd/compress/mkfile
  5. 1 1
      sys/src/cmd/eqn/mkfile
  6. 3 0
      sys/src/cmd/eqn/tuning.c
  7. 1 0
      sys/src/cmd/grap/frame.c
  8. 1 1
      sys/src/cmd/grap/mkfile
  9. 156 167
      sys/src/cmd/join.c
  10. 1 3
      sys/src/cmd/lp/lpsend.c
  11. 1 1
      sys/src/cmd/lp/mkfile
  12. 1 1
      sys/src/cmd/lp/tonet.c
  13. 6 1
      sys/src/cmd/pic/input.c
  14. 1 1
      sys/src/cmd/pic/mkfile
  15. 3 3
      sys/src/cmd/pic/print.c
  16. 37 84
      sys/src/cmd/postscript/common/bbox.c
  17. 6 12
      sys/src/cmd/postscript/common/ext.h
  18. 0 3
      sys/src/cmd/postscript/common/gen.h
  19. 8 1
      sys/src/cmd/postscript/common/getopt.c
  20. 43 102
      sys/src/cmd/postscript/common/misc.c
  21. 1 1
      sys/src/cmd/postscript/common/mkfile
  22. 27 52
      sys/src/cmd/postscript/common/request.c
  23. 3 0
      sys/src/cmd/postscript/common/tempnam.c
  24. 50 97
      sys/src/cmd/postscript/download/download.c
  25. 1 1
      sys/src/cmd/postscript/download/mkfile
  26. 2 2
      sys/src/cmd/postscript/p9bitpost/mkfile
  27. 2 2
      sys/src/cmd/postscript/p9bitpost/pslib.c
  28. 2 2
      sys/src/cmd/postscript/postprint/postprint.c
  29. 10 24
      sys/src/cmd/postscript/postreverse/postreverse.c
  30. 6 0
      sys/src/cmd/postscript/tcpostio/dial.c
  31. 1 1
      sys/src/cmd/postscript/tcpostio/mkfile
  32. 34 24
      sys/src/cmd/postscript/tcpostio/tcpostio.c
  33. 0 4
      sys/src/cmd/troff/fns.h
  34. 1 1
      sys/src/cmd/troff/mkfile
  35. 3 5
      sys/src/cmd/troff/n1.c
  36. 5 5
      sys/src/cmd/troff/n10.c
  37. 0 1
      sys/src/cmd/troff/n2.c
  38. 5 6
      sys/src/cmd/troff/n3.c
  39. 3 2
      sys/src/cmd/troff/n5.c
  40. 3 3
      sys/src/cmd/troff/n6.c
  41. 3 1
      sys/src/cmd/troff/n7.c
  42. 3 4
      sys/src/cmd/troff/n8.c
  43. 5 7
      sys/src/cmd/troff/n9.c
  44. 3 3
      sys/src/cmd/troff/t10.c
  45. 1 0
      sys/src/cmd/troff/t11.c
  46. 5 3
      sys/src/cmd/troff/t6.c
  47. 4 0
      sys/src/cmd/troff/tdef.h

+ 8 - 0
sys/man/1/pcc

@@ -129,6 +129,14 @@ Don't optimize compiled code.
 Print an assembly language version of the object code
 on standard output.
 .TP
+.B -T
+Pass type signatures on all external and global entities.
+The signature is based on the C
+.B signof
+operator.
+See
+.IR dynld (2).
+.TP
 .B -a
 Instead of compiling, print on standard output acid functions (see
 .IR acid (1))

+ 1 - 1
sys/src/cmd/awk/mkfile

@@ -28,7 +28,7 @@ UPDATE=\
 	${TARG:%=/386/bin/%}\
 
 </sys/src/cmd/mkone
-CFLAGS=-c -D_REGEXP_EXTENSION -D_RESEARCH_SOURCE -D_BSD_EXTENSION -DUTF
+CFLAGS=-FTV -c -D_REGEXP_EXTENSION -D_RESEARCH_SOURCE -D_BSD_EXTENSION -DUTF
 YFLAGS=-S -d -v
 CC=pcc
 LD=pcc

+ 42 - 16
sys/src/cmd/compress/compress.c

@@ -37,13 +37,17 @@
  *		Joe Orost		(decvax!vax135!petsd!joe)
  */
 #define _PLAN9_SOURCE
+#define _BSD_EXTENSION
+#define _POSIX_SOURCE
 
 #include <u.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <string.h>
 #include <signal.h>
+#include <utime.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -70,9 +74,6 @@ uchar magic_header[] = { 0x1F, 0x9D };	/* 1F 9D */
 */
 #define INIT_BITS 9			/* initial number of bits/code */
 
-void onintr(int);
-void oops(int);
-
 #define ARGVAL() (*++(*argv) || (--argc && *++argv))
 
 int n_bits;				/* number of bits/code */
@@ -107,9 +108,22 @@ count_int fsize;
 code_int free_ent = 0;			/* first unused entry */
 int exit_stat = 0;
 
-code_int getcode();
+void	cl_block(void);
+void	cl_hash(count_int);
+void	compress(void);
+void	copystat(char *, char *);
+void	decompress(void);
+int	foreground(void);
+code_int getcode(void);
+void	onintr(int);
+void	oops(int);
+void	output(code_int);
+void	prratio(FILE *, long, long);
+void	version(void);
+void	writeerr(void);
 
-Usage()
+void
+Usage(void)
 {
 #ifdef DEBUG
 	fprintf(stderr,"Usage: compress [-cdfDV] [-b maxbits] [file ...]\n");
@@ -443,6 +457,7 @@ nextarg:
 	}
 	}
 	exit(exit_stat);
+	return 0;
 }
 
 static int offset;
@@ -465,10 +480,11 @@ long out_count = 0;		/* # of codes output (for debugging) */
  * file size for noticeable speed improvement on small files.  Please direct
  * questions about this implementation to ames!jaw.
  */
-compress()
+void
+compress(void)
 {
 	code_int ent, hsize_reg;
-	code_int i = 0;
+	code_int i;
 	int c, disp, hshift;
 	long fcode;
 
@@ -584,6 +600,7 @@ static char buf[BITS];
 uchar lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
 uchar rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
 
+void
 output( code )
 code_int  code;
 {
@@ -695,7 +712,8 @@ code_int  code;
  * be stored in the compressed file.  The tables used herein are shared
  * with those of the compress() routine.  See the definitions above.
  */
-decompress()
+void
+decompress(void)
 {
 	int finchar;
 	code_int code, oldcode, incode;
@@ -948,18 +966,20 @@ in_stack(int c, int stack_top)
 }
 #endif /* DEBUG */
 
-writeerr()
+void
+writeerr(void)
 {
 	perror(ofname);
 	unlink(ofname);
 	exit(1);
 }
 
+void
 copystat(ifname, ofname)
 char *ifname, *ofname;
 {
 	int mode;
-	time_t timep[2];
+	time_t timep[2];			/* should be struct utimbuf */
 	struct stat statbuf;
 
 	fclose(stdout);
@@ -986,7 +1006,7 @@ char *ifname, *ofname;
 		timep[0] = statbuf.st_atime;
 		timep[1] = statbuf.st_mtime;
 		/* Update last accessed and modified times */
-		utime(ofname, timep);
+		utime(ofname, (struct utimbuf *)timep);
 //		if (unlink(ifname))	/* Remove input file */
 //			perror(ifname);
 		return;			/* success */
@@ -1001,7 +1021,8 @@ char *ifname, *ofname;
  * This routine returns 1 if we are running in the foreground and stderr
  * is a tty.
  */
-foreground()
+int
+foreground(void)
 {
 	if(bgnd_flag)			/* background? */
 		return 0;
@@ -1012,6 +1033,7 @@ foreground()
 void
 onintr(int x)
 {
+	USED(x);
 	unlink(ofname);
 	exit(1);
 }
@@ -1019,13 +1041,15 @@ onintr(int x)
 void
 oops(int x)		/* wild pointer -- assume bad input */
 {
+	USED(x);
 	if (do_decomp == 1)
 		fprintf(stderr, "uncompress: corrupt input\n");
 	unlink(ofname);
 	exit(1);
 }
 
-cl_block ()		/* table clear for block compress */
+void
+cl_block(void)		/* table clear for block compress */
 {
 	long rat;
 
@@ -1065,8 +1089,8 @@ cl_block ()		/* table clear for block compress */
 	}
 }
 
-cl_hash(hsize)		/* reset code table */
-count_int hsize;
+void
+cl_hash(count_int hsize)		/* reset code table */
 {
 	count_int *htab_p = htab+hsize;
 	long i;
@@ -1096,6 +1120,7 @@ count_int hsize;
 		*--htab_p = m1;
 }
 
+void
 prratio(stream, num, den)
 FILE *stream;
 long num, den;
@@ -1113,7 +1138,8 @@ long num, den;
 	fprintf(stream, "%d.%02d%%", q / 100, q % 100);
 }
 
-version()
+void
+version(void)
 {
 	fprintf(stderr, "%s\n", rcs_ident);
 	fprintf(stderr, "Options: ");

+ 1 - 1
sys/src/cmd/compress/mkfile

@@ -7,4 +7,4 @@ BIN=/$objtype/bin
 </sys/src/cmd/mkone
 CC=pcc
 LD=pcc
-CFLAGS=-B -c
+CFLAGS=-FTV -c

+ 1 - 1
sys/src/cmd/eqn/mkfile

@@ -35,7 +35,7 @@ BIN=/$objtype/bin
 CC=pcc
 LD=pcc
 YFLAGS=-d -S
-CFLAGS=-c
+CFLAGS=-FTV -c
 
 eqn.c:	y.tab.c prevy.tab.h
 	mv y.tab.c $target

+ 3 - 0
sys/src/cmd/eqn/tuning.c

@@ -137,6 +137,7 @@ void init_tune(void)
 
 void ftune(char *s, char *t)	/* brute force for now */
 {
+	double dummy;
 	double f = atof(t);
 	double *target;
 
@@ -146,6 +147,8 @@ void ftune(char *s, char *t)	/* brute force for now */
 		target = &Subbase;
 	else if (eq(s, "Supshift"))
 		target = &Supshift;
+	else
+		target = &dummy;
 	if (t[0] == '+' || t[0] == '-')
 		*target += f;
 	else

+ 1 - 0
sys/src/cmd/grap/frame.c

@@ -54,6 +54,7 @@ void frameside(int type, Attr *desc)	/* create and remember sides */
 	char buf[100];
 
 	nsides++;
+	n = 0;
 	switch (type) {
 	case 0:		/* no side specified; kludge up all */
 		frameside(TOP, desc);

+ 1 - 1
sys/src/cmd/grap/mkfile

@@ -27,7 +27,7 @@ BIN=/$objtype/bin
 CC=pcc
 LD=pcc
 YFLAGS = -d -S
-CFLAGS=-c
+CFLAGS=-FTV -c
 
 grap.c:	y.tab.c
 	mv $prereq $target

+ 156 - 167
sys/src/cmd/join.c

@@ -1,45 +1,57 @@
 /*	join F1 F2 on stuff */
 #include <u.h>
 #include <libc.h>
-#include <stdio.h>
+#include <bio.h>
 #include <ctype.h>
 
-#define F1 0
-#define F2 1
-#define F0 3
+enum {
+	F1,
+	F2,
+	NIN,
+	F0,
+};
+
 #define	NFLD	100	/* max field per line */
-#define comp() runecmp(ppi[F1][j1],ppi[F2][j2])
+#define comp() runestrcmp(ppi[F1][j1], ppi[F2][j2])
 
-FILE *f[2];
-Rune buf[2][BUFSIZ];	/*input lines */
-Rune *ppi[2][NFLD+1];	/* pointers to fields in lines */
-Rune *s1,*s2;
-int	j1	= 1;	/* join of this field of file 1 */
-int	j2	= 1;	/* join of this field of file 2 */
-int	olist[2*NFLD];	/* output these fields */
-int	olistf[2*NFLD];	/* from these files */
-int	no;		/* number of entries in olist */
+Biobuf *f[NIN];
+Rune buf[NIN][Bsize];	/* input lines */
+Rune *ppi[NIN][NFLD+1];	/* pointers to fields in lines */
 Rune	sep1	= ' ';	/* default field separator */
 Rune	sep2	= '\t';
-char *sepstr=" ";
-int	discard;	/* count of truncated lines */
-Rune	null[BUFSIZ]	= L"";
+int	j1	= 1;	/* join of this field of file 1 */
+int	j2	= 1;	/* join of this field of file 2 */
 int	a1;
 int 	a2;
 
-char *getoptarg(int*, char***);
-void output(int, int);
-int input(int);
-void oparse(char*);
-void error(char*, char*);
-void seek1(void), seek2(void);
-Rune *strtorune(Rune *, char *);
+int	olist[NIN*NFLD];  /* output these fields */
+int	olistf[NIN*NFLD]; /* from these files */
+int	no;		/* number of entries in olist */
+char *sepstr	= " ";
+int	discard;	/* count of truncated lines */
+Rune	null[Bsize]	= L"";
+Biobuf binbuf, boutbuf;
+Biobuf *bin, *bout;
+
+char	*getoptarg(int*, char***);
+int	input(int);
+void	join(int);
+void	oparse(char*);
+void	output(int, int);
+Rune	*strtorune(Rune *, char *);
 
 void
 main(int argc, char **argv)
 {
 	int i;
+	vlong off1, off2;
+
+	bin = &binbuf;
+	bout = &boutbuf;
+	Binit(bin, 0, OREAD);
+	Binit(bout, 1, OWRITE);
 
+	argv0 = argv[0];
 	while (argc > 1 && argv[1][0] == '-') {
 		if (argv[1][1] == '\0')
 			break;
@@ -57,7 +69,7 @@ main(int argc, char **argv)
 				a2++;
 				break;
 			default:
-				error("incomplete option -a","");
+				sysfatal("incomplete option -a");
 			}
 			break;
 		case 'e':
@@ -112,49 +124,41 @@ main(int argc, char **argv)
 proceed:
 	for (i = 0; i < no; i++)
 		if (olist[i]-- > NFLD)	/* 0 origin */
-			error("field number too big in -o","");
-	if (argc != 3)
-		error("usage: join [-1 x -2 y] [-o list] file1 file2","");
+			sysfatal("field number too big in -o");
+	if (argc != 3) {
+		fprint(2, "usage: join [-1 x -2 y] [-o list] file1 file2\n");
+		exits("usage");
+	}
 	if (j1 < 1  || j2 < 1)
-		error("invalid field indices", "");
+		sysfatal("invalid field indices");
 	j1--;
 	j2--;	/* everyone else believes in 0 origin */
-	s1 = ppi[F1][j1];
-	s2 = ppi[F2][j2];
+
 	if (strcmp(argv[1], "-") == 0)
-		f[F1] = stdin;
-	else if ((f[F1] = fopen(argv[1], "r")) == 0)
-		error("can't open %s", argv[1]);
-	if(strcmp(argv[2], "-") == 0) {
-		f[F2] = stdin;
-	} else if ((f[F2] = fopen(argv[2], "r")) == 0)
-		error("can't open %s", argv[2]);
+		f[F1] = bin;
+	else if ((f[F1] = Bopen(argv[1], OREAD)) == 0)
+		sysfatal("can't open %s: %r", argv[1]);
+	if(strcmp(argv[2], "-") == 0)
+		f[F2] = bin;
+	else if ((f[F2] = Bopen(argv[2], OREAD)) == 0)
+		sysfatal("can't open %s: %r", argv[2]);
 
-	if(ftell(f[F2]) >= 0)
-		seek2();
-	else if(ftell(f[F1]) >= 0)
-		seek1();
-	else
-		error("neither file is randomly accessible","");
+	off1 = Boffset(f[F1]);
+	off2 = Boffset(f[F2]);
+	if(Bseek(f[F2], 0, 2) >= 0){
+		Bseek(f[F2], off2, 0);
+		join(F2);
+	}else if(Bseek(f[F1], 0, 2) >= 0){
+		Bseek(f[F1], off1, 0);
+		Bseek(f[F2], off2, 0);
+		join(F1);
+	}else
+		sysfatal("neither file is randomly accessible");
 	if (discard)
-		error("some input line was truncated", "");
+		sysfatal("some input line was truncated");
 	exits("");
 }
 
-int
-runecmp(Rune *a, Rune *b)
-{
-	while(*a == *b) {
-		if(*a == '\0')
-			return 0;
-		a++;
-		b++;
-	}
-	if(*a < *b)
-		return -1;
-	return 1;
-}
-
 char *
 runetostr(char *buf, Rune *r)
 {
@@ -177,90 +181,71 @@ strtorune(Rune *buf, char *s)
 	return buf;
 }
 
-/* lazy.  there ought to be a clean way to combine seek1 & seek2 */
-#define get1() n1=input(F1)
-#define get2() n2=input(F2)
+void
+readboth(int n[])
+{
+	n[F1] = input(F1);
+	n[F2] = input(F2);
+}
 
 void
-seek2()
+seekbotreadboth(int seekf, vlong bot, int n[])
 {
-	int n1, n2;
-	int top2=0;
-	int bot2 = ftell(f[F2]);
-	get1();
-	get2();
-	while(n1>0 && n2>0 || (a1||a2) && n1+n2>0) {
-		if(n1>0 && n2>0 && comp()>0 || n1==0) {
-			if(a2) output(0, n2);
-			bot2 = ftell(f[F2]);
-			get2();
-		} else if(n1>0 && n2>0 && comp()<0 || n2==0) {
-			if(a1) output(n1, 0);
-			get1();
-		} else /*(n1>0 && n2>0 && comp()==0)*/ {
-			while(n2>0 && comp()==0) {
-				output(n1, n2);
-				top2 = ftell(f[F2]);
-				get2();
-			}
-			fseek(f[F2], bot2, 0);
-			get2();
-			get1();
-			for(;;) {
-				if(n1>0 && n2>0 && comp()==0) {
-					output(n1, n2);
-					get2();
-				} else if(n1>0 && n2>0 && comp()<0 || n2==0) {
-					fseek(f[F2], bot2, 0);
-					get2();
-					get1();
-				} else /*(n1>0 && n2>0 && comp()>0 || n1==0)*/{
-					fseek(f[F2], top2, 0);
-					bot2 = top2;
-					get2();
-					break;
-				}
-			}
-		}
-	}
+	Bseek(f[seekf], bot, 0);
+	readboth(n);
 }
+
 void
-seek1()
+join(int seekf)
 {
-	int n1, n2;
-	int top1=0;
-	int bot1 = ftell(f[F1]);
-	get1();
-	get2();
-	while(n1>0 && n2>0 || (a1||a2) && n1+n2>0) {
-		if(n1>0 && n2>0 && comp()>0 || n1==0) {
-			if(a2) output(0, n2);
-			get2();
-		} else if(n1>0 && n2>0 && comp()<0 || n2==0) {
-			if(a1) output(n1, 0);
-			bot1 = ftell(f[F1]);
-			get1();
-		} else /*(n1>0 && n2>0 && comp()==0)*/ {
-			while(n2>0 && comp()==0) {
-				output(n1, n2);
-				top1 = ftell(f[F1]);
-				get1();
+	int cmp, less;
+	int n[NIN];
+	vlong top, bot;
+
+	less = seekf == F2;
+	top = 0;
+	bot = Boffset(f[seekf]);
+	readboth(n);
+	while(n[F1]>0 && n[F2]>0 || (a1||a2) && n[F1]+n[F2]>0) {
+		cmp = comp();
+		if(n[F1]>0 && n[F2]>0 && cmp>0 || n[F1]==0) {
+			if(a2)
+				output(0, n[F2]);
+			if (seekf == F2)
+				bot = Boffset(f[seekf]);
+			n[F2] = input(F2);
+		} else if(n[F1]>0 && n[F2]>0 && cmp<0 || n[F2]==0) {
+			if(a1)
+				output(n[F1], 0);
+			if (seekf == F1)
+				bot = Boffset(f[seekf]);
+			n[F1] = input(F1);
+		} else {
+			/* n[F1]>0 && n[F2]>0 && cmp==0 */
+			while(n[F2]>0 && cmp==0) {
+				output(n[F1], n[F2]);
+				top = Boffset(f[seekf]);
+				n[seekf] = input(seekf);
+				cmp = comp();
 			}
-			fseek(f[F1], bot1, 0);
-			get2();
-			get1();
+			seekbotreadboth(seekf, bot, n);
 			for(;;) {
-				if(n1>0 && n2>0 && comp()==0) {
-					output(n1, n2);
-					get1();
-				} else if(n1>0 && n2>0 && comp()>0 || n1==0) {
-					fseek(f[F1], bot1, 0);
-					get2();
-					get1();
-				} else /*(n1>0 && n2>0 && comp()<0 || n2==0)*/{
-					fseek(f[F1], top1, 0);
-					bot1 = top1;
-					get1();
+				cmp = comp();
+				if(n[F1]>0 && n[F2]>0 && cmp==0) {
+					output(n[F1], n[F2]);
+					n[seekf] = input(seekf);
+				} else if(n[F1]>0 && n[F2]>0 &&
+				    (less? cmp<0 :cmp>0) || n[seekf]==0)
+					seekbotreadboth(seekf, bot, n);
+				else {
+					/*
+					 * n[F1]>0 && n[F2]>0 &&
+					 * (less? cmp>0 :cmp<0) ||
+					 * n[seekf==F1? F2: F1]==0
+					 */
+					Bseek(f[seekf], top, 0);
+					bot = top;
+					n[seekf] = input(seekf);
 					break;
 				}
 			}
@@ -271,50 +256,63 @@ seek1()
 int
 input(int n)		/* get input line and split into fields */
 {
-	int i, c;
+	int c, i, len;
+	char *line;
 	Rune *bp;
 	Rune **pp;
-	char line[BUFSIZ];
 
 	bp = buf[n];
 	pp = ppi[n];
-	if (fgets(line, BUFSIZ, f[n]) == 0)
+	line = Brdline(f[n], '\n');
+	if (line == nil)
 		return(0);
+	len = Blinelen(f[n]) - 1;
+	c = line[len];
+	line[len] = '\0';
 	strtorune(bp, line);
+	line[len] = c;			/* restore delimiter */
+	if (c != '\n')
+		discard++;
+
 	i = 0;
 	do {
 		i++;
 		if (sep1 == ' ')	/* strip multiples */
 			while ((c = *bp) == sep1 || c == sep2)
 				bp++;	/* skip blanks */
-		*pp++ = bp;	/* record beginning */
-		while ((c = *bp) != sep1 && c != '\n' && c != sep2 && c != '\0')
+		*pp++ = bp;		/* record beginning */
+		while ((c = *bp) != sep1 && c != sep2 && c != '\0')
 			bp++;
-		*bp++ = '\0';	/* mark end by overwriting blank */
-	} while (c != '\n' && c != '\0' && i < NFLD-1);
-	if (c != '\n')
-		discard++;
+		*bp++ = '\0';		/* mark end by overwriting blank */
+	} while (c != '\0' && i < NFLD-1);
 
 	*pp = 0;
 	return(i);
 }
 
+void
+prfields(int f, int on, int jn)
+{
+	int i;
+	char buf[Bsize];
+
+	for (i = 0; i < on; i++)
+		if (i != jn)
+			Bprint(bout, "%s%s", sepstr, runetostr(buf, ppi[f][i]));
+}
+
 void
 output(int on1, int on2)	/* print items from olist */
 {
 	int i;
 	Rune *temp;
-	char buf[BUFSIZ];
+	char buf[Bsize];
 
 	if (no <= 0) {	/* default case */
-		printf("%s", runetostr(buf, on1? ppi[F1][j1]: ppi[F2][j2]));
-		for (i = 0; i < on1; i++)
-			if (i != j1)
-				printf("%s%s", sepstr, runetostr(buf, ppi[F1][i]));
-		for (i = 0; i < on2; i++)
-			if (i != j2)
-				printf("%s%s", sepstr, runetostr(buf, ppi[F2][i]));
-		printf("\n");
+		Bprint(bout, "%s", runetostr(buf, on1? ppi[F1][j1]: ppi[F2][j2]));
+		prfields(F1, on1, j1);
+		prfields(F2, on2, j2);
+		Bputc(bout, '\n');
 	} else {
 		for (i = 0; i < no; i++) {
 			if (olistf[i]==F0 && on1>j1)
@@ -328,24 +326,15 @@ output(int on1, int on2)	/* print items from olist */
 				   *temp==0)
 					temp = null;
 			}
-			printf("%s", runetostr(buf, temp));
+			Bprint(bout, "%s", runetostr(buf, temp));
 			if (i == no - 1)
-				printf("\n");
+				Bputc(bout, '\n');
 			else
-				printf("%s", sepstr);
+				Bprint(bout, "%s", sepstr);
 		}
 	}
 }
 
-void
-error(char *s1, char *s2)
-{
-	fprintf(stderr, "join: ");
-	fprintf(stderr, s1, s2);
-	fprintf(stderr, "\n");
-	exits(s1);
-}
-
 char *
 getoptarg(int *argcp, char ***argvp)
 {
@@ -354,7 +343,7 @@ getoptarg(int *argcp, char ***argvp)
 	if(argv[1][2] != 0)
 		return &argv[1][2];
 	if(argc<=2 || argv[2][0]=='-')
-		error("incomplete option %s", argv[1]);
+		sysfatal("incomplete option %s", argv[1]);
 	*argcp = argc-1;
 	*argvp = ++argv;
 	return argv[1];
@@ -379,7 +368,7 @@ oparse(char *s)
 			}
 			/* fall thru */
 		default:
-			error("invalid -o list", "");
+			sysfatal("invalid -o list");
 		}
 		if(s[1] == ',')
 			s++;

+ 1 - 3
sys/src/cmd/lp/lpsend.c

@@ -138,8 +138,7 @@ char jobbuf[RDSIZE];
 int
 pass(int inpfd, int outfd, int bsize)
 {
-	int bcnt = 0;
-	int rv = 0;
+	int rv, bcnt;
 
 	for(bcnt=bsize; bcnt > 0; bcnt -= rv) {
 		alarm(WRNETIMEOUT);	/* to break hanging */
@@ -227,7 +226,6 @@ recvACK(int netfd)
 void
 main(int argc, char *argv[])
 {
-	char *devdir;
 	int i, rv, netfd, bsize, datafd;
 #ifndef plan9
 	void (*oldhandler)();

+ 1 - 1
sys/src/cmd/lp/mkfile

@@ -12,7 +12,7 @@ HFILES=
 
 BIN=/$objtype/bin/aux
 </sys/src/cmd/mkmany
-CFLAGS=-Dplan9
+CFLAGS=$CFLAGS -Dplan9
 
 installall:V:	/sys/lib/lp/bin/lpsend.rc
 

+ 1 - 1
sys/src/cmd/lp/tonet.c

@@ -17,7 +17,7 @@ alarmhandler(void *, char *note)
 void
 pass(int in, int out)
 {
-	int rv = 0;
+	int rv;
 	static char buf[4096];
 
 	for(;;) {

+ 6 - 1
sys/src/cmd/pic/input.c

@@ -252,6 +252,7 @@ nextchar(void)
 {
 	register int c;
 
+	c = 0;
   loop:
 	switch (srcp->type) {
 	case Free:	/* free string */
@@ -482,7 +483,11 @@ void eprint(void)	/* try to print context around error */
 	ep = ebuf;
 }
 
-void yywrap(void) {}
+int
+yywrap(void)
+{
+	return 1;		/* read eof; did not switch inputs */
+}
 
 char	*newfile = 0;		/* filename for file copy */
 char	*untilstr = 0;		/* string that terminates a thru */

+ 1 - 1
sys/src/cmd/pic/mkfile

@@ -27,7 +27,7 @@ BIN=/$objtype/bin
 </sys/src/cmd/mkone
 CC=pcc
 LD=pcc
-CFLAGS=-c
+CFLAGS=-FTV -c
 YFLAGS=-S -d
 
 picy.c:	y.tab.c

+ 3 - 3
sys/src/cmd/pic/print.c

@@ -51,11 +51,11 @@ void print(void)
 				move(x0, y0);
 				fillstart(p->o_fillval);
 			}
-			if (p->o_type == BLOCK)
+			if (p->o_type == BLOCK){
 				;	/* nothing at all */
-			else if (invis && !fill)
+			}else if (invis && !fill){
 				;	/* nothing at all */
-			else if (p->o_attr & (DOTBIT|DASHBIT))
+			}else if (p->o_attr & (DOTBIT|DASHBIT))
 				dotbox(x0, y0, x1, y1, p->o_attr, p->o_ddval);
 			else
 				box(x0, y0, x1, y1);

+ 37 - 84
sys/src/cmd/postscript/common/bbox.c

@@ -1,5 +1,4 @@
 /*
- *
  * Boundingbox code for PostScript translators. The boundingbox for each page
  * is accumulated in bbox - the one for the whole document goes in docbbox. A
  * call to writebbox() puts out an appropriate comment, updates docbbox, and
@@ -7,10 +6,13 @@
  * is that we're really printing the current page only if output is now going
  * to stdout - a valid assumption for all supplied translators. Needs the math
  * library.
- *
  */
 
+#define _RESEARCH_SOURCE
+
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <ctype.h>
 #include <sys/types.h>
 #include <fcntl.h>
@@ -32,19 +34,20 @@ Bbox	docbbox = {FALSE, 0.0, 0.0, 0.0, 0.0};
 double	ctm[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
 double	matrix1[6], matrix2[6];
 
-/*****************************************************************************/
+void	concat(double []);
+void	resetbbox(int);
+void	rotate(double);
+void	scale(double, double);
+void	translate(double, double);
+void	writebbox(FILE *, char *, int);
 
+void
 cover(x, y)
-
     double	x, y;
-
 {
-
 /*
- *
  * Adds point (x, y) to bbox. Coordinates are in user space - the transformation
  * to default coordinates happens in writebbox().
- *
  */
 
     if ( bbox.set == FALSE ) {
@@ -60,30 +63,23 @@ cover(x, y)
 	    bbox.urx = x;
 	if ( y > bbox.ury )
 	    bbox.ury = y;
-    }	/* End else */
-
-}   /* End of cover */
-
-/*****************************************************************************/
+    }
+}
 
+void
 writebbox(fp, keyword, slop)
-
     FILE	*fp;			/* the comment is written here */
     char	*keyword;		/* the boundingbox comment string */
     int		slop;			/* expand (or contract?) the box a bit */
-
 {
-
     Bbox	ubbox;			/* user space bounding box */
     double	x, y;
 
 /*
- *
  * Transforms the numbers in the bbox[] using ctm[], adjusts the corners a bit
  * (depending on slop) and then writes comment. If *keyword is BoundingBox use
  * whatever's been saved in docbbox, otherwise assume the comment is just for
  * the current page.
- *
  */
 
     if ( strcmp(keyword, BOUNDINGBOX) == 0 )
@@ -108,55 +104,39 @@ writebbox(fp, keyword, slop)
 	bbox.lly -= slop + 0.5;
 	bbox.urx += slop + 0.5;
 	bbox.ury += slop + 0.5;
-	fprintf(fp, "%s %d %d %d %d\n", keyword, (int)bbox.llx, (int)bbox.lly,(int)bbox.urx, (int)bbox.ury);
+	fprintf(fp, "%s %d %d %d %d\n", keyword, (int)bbox.llx, (int)bbox.lly,
+		(int)bbox.urx, (int)bbox.ury);
 	bbox = ubbox;
-    }	/* End if */
-
-    resetbbox((fp == stdout) ? TRUE : FALSE);
-
-}   /* End of writebbox */
-
-/*****************************************************************************/
-
-resetbbox(output)
-
-    int		output;
+    }
+    resetbbox(fp == stdout);
+}
 
+void
+resetbbox(int output)
 {
-
 /*
- *
  * Adds bbox to docbbox and resets bbox for the next page. Only update docbbox
  * if we really did output on the last page.
- *
  */
 
     if ( docbbox.set == TRUE ) {
 	cover(docbbox.llx, docbbox.lly);
 	cover(docbbox.urx, docbbox.ury);
-    }	/* End if */
+    }
 
     if ( output == TRUE ) {
 	docbbox = bbox;
 	docbbox.set = TRUE;
-    }	/* End if */
+    }
 
     bbox.set = FALSE;
+}
 
-}   /* End of resetbbox */
-
-/*****************************************************************************/
-
-scale(sx, sy)
-
-    double	sx, sy;
-
+void
+scale(double sx, double sy)
 {
-
 /*
- *
  * Scales the default matrix.
- *
  */
 
     matrix1[0] = sx;
@@ -167,21 +147,13 @@ scale(sx, sy)
     matrix1[5] = 0;
 
     concat(matrix1);
+}
 
-}   /* End of scale */
-
-/*****************************************************************************/
-
-translate(tx, ty)
-
-    double	tx, ty;
-
+void
+translate(double tx, double ty)
 {
-
 /*
- *
  * Translates the default matrix.
- *
  */
 
     matrix1[0] = 1.0;
@@ -192,24 +164,17 @@ translate(tx, ty)
     matrix1[5] = ty;
 
     concat(matrix1);
+}
 
-}   /* End of translate */
-
-/*****************************************************************************/
-
-rotate(angle)
-
-    double	angle;
-
+void
+rotate(double angle)
 {
 
 /*
- *
  * Rotates by angle degrees.
- *
  */
 
-    angle *= 3.1416 / 180;
+    angle *= M_PI / 180;
 
     matrix1[0] = matrix1[3] = cos(angle);
     matrix1[1] = sin(angle);
@@ -218,23 +183,15 @@ rotate(angle)
     matrix1[5] = 0.0;
 
     concat(matrix1);
+}
 
-}   /* End of rotate */
-
-/*****************************************************************************/
-
-concat(m1)
-
-    double	m1[];
-
+void
+concat(double m1[])
 {
-
     double	m2[6];
 
 /*
- *
  * Replaces the ctm[] by the result of the matrix multiplication m1[] x ctm[].
- *
  */
 
     m2[0] = ctm[0];
@@ -250,8 +207,4 @@ concat(m1)
     ctm[3] = m1[2] * m2[1] + m1[3] * m2[3];
     ctm[4] = m1[4] * m2[0] + m1[5] * m2[2] + m2[4];
     ctm[5] = m1[4] * m2[1] + m1[5] * m2[3] + m2[5];
-
-}   /* End of concat */
-
-/*****************************************************************************/
-
+}

+ 6 - 12
sys/src/cmd/postscript/common/ext.h

@@ -1,7 +1,5 @@
 /*
- *
  * External varibles - most are in glob.c.
- *
  */
 
 extern char	**argv;			/* global so everyone can use them */
@@ -27,14 +25,10 @@ extern int	writing;		/* and output encoding */
 extern char	*optarg;		/* for getopt() */
 extern int	optind;
 
-extern void	interrupt();
+extern int	cat(char *);
+extern void	error(int, char *, ...);
+extern int	in_olist(int);
+extern void	interrupt(int);
+extern int	out_list(char *);
+extern int	setencoding(char *);
 extern char	*tempnam(char*,char*);
-/* 
- * extern char	*malloc();
- * extern char	*calloc();
- * extern char	*strtok();
- * extern long	ftell();
- * extern double	atof();
- * extern double	sqrt();
- * extern double	atan2();
- */

+ 0 - 3
sys/src/cmd/postscript/common/gen.h

@@ -1,8 +1,6 @@
 /*
- *
  * A few definitions that shouldn't have to change. Used by most programs in
  * this package.
- *
  */
 
 #define PROGRAMVERSION	"3.3.2"
@@ -62,4 +60,3 @@
 #define ABS(A)		((A) >= 0 ? (A) : -(A))
 #define MIN(A, B)	((A) < (B) ? (A) : (B))
 #define MAX(A, B)	((A) > (B) ? (A) : (B))
-

+ 8 - 1
sys/src/cmd/postscript/common/getopt.c

@@ -1,14 +1,21 @@
 #ifndef _POSIX_SOURCE
 #include <u.h>
 #include <libc.h>
+#else
+#define _BSD_EXTENSION
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
 #endif
+
 #include	<stdio.h>
+
 #define ERR(str, chr)       if(opterr){fprintf(stderr, "%s%s%c\n", argv[0], str, chr);}
+
 int     opterr = 1;
 int     optind = 1;
 int	optopt;
 char    *optarg;
-char    *strchr();
 
 int
 getopt (argc, argv, opts)

+ 43 - 102
sys/src/cmd/postscript/common/misc.c

@@ -1,10 +1,13 @@
 /*
- *
  * General purpose routines.
- *
  */
 
+#define _BSD_EXTENSION
+
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 #include <ctype.h>
 #include <sys/types.h>
 #include <fcntl.h>
@@ -16,21 +19,15 @@
 int	nolist = 0;			/* number of specified ranges */
 int	olist[50];			/* processing range pairs */
 
-/*****************************************************************************/
-
+int
 out_list(str)
-
     char	*str;
-
 {
-
     int		start, stop;
 
 /*
- *
  * Grab page ranges from str, save them in olist[], and update the nolist
  * count. Range syntax matches nroff/troff syntax.
- *
  */
 
     while ( *str && nolist < sizeof(olist) - 2 ) {
@@ -40,33 +37,25 @@ out_list(str)
 	    stop = str_convert(&str, 9999);
 
 	if ( start > stop )
-	    error(FATAL, "illegal range %d-%d", start, stop);
+	    error(FATAL, "illegal range %d-%d", start, stop, 0);
 
 	olist[nolist++] = start;
 	olist[nolist++] = stop;
 
 	if ( *str != '\0' ) str++;
-    }	/* End while */
-
+    }
     olist[nolist] = 0;
-
-}   /* End of out_list */
-
-/*****************************************************************************/
+    return 0;
+}
 
 in_olist(num)
-
     int		num;
-
 {
-
     int		i;
 
 /*
- *
  * Return ON if num is in the current page range list. Print everything if
  * there's no list.
- *
  */
     if ( nolist == 0 )
 	return(ON);
@@ -74,27 +63,19 @@ in_olist(num)
     for ( i = 0; i < nolist; i += 2 )
 	if ( num >= olist[i] && num <= olist[i+1] )
 	    return(ON);
-
     return(OFF);
+}
 
-}   /* End of in_olist */
-
-/*****************************************************************************/
-
+int
 setencoding(name)
-
     char	*name;
-
 {
-
     char	path[150];
 
 /*
- *
  * Include the font encoding file selected by name. It's a full pathname if
  * it begins with /, otherwise append suffix ".enc" and look for the file in
  * ENCODINGDIR. Missing files are silently ignored.
- *
  */
 
     if ( name == NULL )
@@ -106,52 +87,35 @@ setencoding(name)
 
     if ( cat(path) == TRUE )
 	writing = strncmp(name, "UTF", 3) == 0;
-
-}   /* End of setencoding */
-
-/*****************************************************************************/
+    return 0;
+}
 
 cat(file)
-
     char	*file;
-
 {
-
     int		fd_in;
     int		fd_out;
     char	buf[512];
     int		count;
 
 /*
- *
  * Copy *file to stdout. Return FALSE is there was a problem.
- *
  */
 
     fflush(stdout);
-
     if ( (fd_in = open(file, O_RDONLY)) == -1 )
 	return(FALSE);
-
     fd_out = fileno(stdout);
     while ( (count = read(fd_in, buf, sizeof(buf))) > 0 )
 	write(fd_out, buf, count);
-
     close(fd_in);
-
     return(TRUE);
-
-}   /* End of cat */
-
-/*****************************************************************************/
+}
 
 str_convert(str, err)
-
     char	**str;
     int		err;
-
 {
-
     int		i;
 
 /*
@@ -168,63 +132,40 @@ str_convert(str, err)
 	i = 10 * i + **str - '0';
 
     return(i);
+}
 
-}   /* End of str_convert */
-
-/*****************************************************************************/
-
-error(kind, mesg, a1, a2, a3)
-
-    int		kind;
-    char	*mesg;
-    unsigned	a1, a2, a3;
-
+void
+error(int kind, char *fmt, ...)
 {
+	char buf[256];
+	va_list arg;
+
+	if (fmt) {
+		va_start(arg, fmt);
+		vsnprintf(buf, sizeof buf, fmt, arg);
+		va_end(arg);
+		fprintf(stderr, "%s: %s", prog_name, buf);
+		if (lineno > 0)
+			fprintf(stderr, " (line %d)", lineno);
+		if (position > 0)
+			fprintf(stderr, " (near byte %d)", position);
+		putc('\n', stderr);
+	}
+	if (kind == FATAL && ignore == OFF) {
+		if (temp_file != NULL)
+			unlink(temp_file);
+		exit(x_stat | 01);
+	}
+}
 
 /*
- *
- * Print an error message and quit if kind is FATAL.
- *
- */
-
-    if ( mesg != NULL && *mesg != '\0' ) {
-	fprintf(stderr, "%s: ", prog_name);
-	fprintf(stderr, mesg, a1, a2, a3);
-	if ( lineno > 0 )
-	    fprintf(stderr, " (line %d)", lineno);
-	if ( position > 0 )
-	    fprintf(stderr, " (near byte %d)", position);
-	putc('\n', stderr);
-    }	/* End if */
-
-    if ( kind == FATAL && ignore == OFF ) {
-	if ( temp_file != NULL )
-	    unlink(temp_file);
-	exit(x_stat | 01);
-    }	/* End if */
-
-}   /* End of error */
-
-/*****************************************************************************/
-
-void interrupt(sig)
-
-    int		sig;
-
-{
-
-/*
- *
  * Signal handler for translators.
- *
  */
-
+void
+interrupt(int sig)
+{
+    USED(sig);
     if ( temp_file != NULL )
 	unlink(temp_file);
-
     exit(1);
-
-}   /* End of interrupt */
-
-/*****************************************************************************/
-
+}

+ 1 - 1
sys/src/cmd/postscript/common/mkfile

@@ -18,5 +18,5 @@ HFILES=comments.h\
 
 </sys/src/cmd/mklib
 
-CFLAGS=-c -D$SYSTEM -D_POSIX_SOURCE -B
+CFLAGS=$CFLAGS -c -D$SYSTEM -D_POSIX_SOURCE -B
 CC=pcc

+ 27 - 52
sys/src/cmd/postscript/common/request.c

@@ -1,5 +1,4 @@
 /*
- *
  * Things used to handle special requests (eg. manual feed) globally or on a per
  * page basis. Requests are passed through to the translator using the -R option.
  * The argument to -R can be "request", "request:page", or "request:page:file".
@@ -7,12 +6,13 @@
  * to the global environment. In all other cases it applies only to the selected
  * page. If a file is given, page must be supplied, and the lookup is in that file
  * rather than *requestfile.
- *
  */
 
 #include <stdio.h>
-
+#include <stdlib.h>
+#include <string.h>
 #include "gen.h"			/* general purpose definitions */
+#include "ext.h"
 #include "request.h"			/* a few special definitions */
 #include "path.h"			/* for the default request file */
 
@@ -20,27 +20,22 @@ Request	request[MAXREQUEST];		/* next page or global request */
 int	nextreq = 0;			/* goes in request[nextreq] */
 char	*requestfile = REQUESTFILE;	/* default lookup file */
 
-/*****************************************************************************/
-
-saverequest(want)
-
-    char	*want;			/* grab code for this stuff */
-
-{
-
-    char	*page;			/* and save it for this page */
-    char	*strtok();
+void	dumprequest(char *, char *, FILE *);
+void	writerequest(int, FILE *);
 
 /*
- *
  * Save the request until we get to appropriate page - don't even bother with
  * the lookup right now. Format of *want string is "request", "request:page", or
  * "request:page:file", and we assume we can change the string here as needed.
  * If page is omitted or given as 0 the request will be done globally. If *want
  * includes a file, request and page must also be given, and in that case *file
  * will be used for the lookup.
- *
  */
+void
+saverequest(want)
+    char	*want;			/* grab code for this stuff */
+{
+    char	*page;			/* and save it for this page */
 
     if ( nextreq < MAXREQUEST )  {
 	request[nextreq].want = strtok(want, ": ");
@@ -51,55 +46,39 @@ saverequest(want)
 	    request[nextreq].file = requestfile;
 	nextreq++;
     } else error(NON_FATAL, "too many requests - ignoring %s", want);
+}
 
-}   /* End of saverequest */
-
-/*****************************************************************************/
-
+/*
+ * Writes out all the requests that have been saved for page. Page 0 refers to
+ * the global environment and is done during initial setup.
+ */
+void
 writerequest(page, fp_out)
-
     int		page;			/* write everything for this page */
     FILE	*fp_out;		/* to this file */
-
 {
-
     int		i;			/* loop index */
 
-/*
- *
- * Writes out all the requests that have been saved for page. Page 0 refers to
- * the global environment and is done during initial setup.
- *
- */
-
     for ( i = 0; i < nextreq; i++ )
 	if ( request[i].page == page )
 	    dumprequest(request[i].want, request[i].file, fp_out);
-
-}   /* End of writerequest */
-
-/*****************************************************************************/
-
-dumprequest(want, file, fp_out)
-
-    char	*want;			/* look for this string */
-    char	*file;			/* in this file */
-    FILE	*fp_out;		/* and write the value out here */
-
-{
-
-    char	buf[100];		/* line buffer for reading *file */
-    FILE	*fp_in;
+}
 
 /*
- *
  * Looks for *want in the request file and if it's found the associated value
  * is copied to the output file. Keywords (ie. the *want strings) begin an @ in
  * the first column of file, while the values (ie. the stuff that's copied to
  * the output file) starts on the next line and extends to the next keyword or
  * to the end of file.
- *
  */
+void
+dumprequest(want, file, fp_out)
+    char	*want;			/* look for this string */
+    char	*file;			/* in this file */
+    FILE	*fp_out;		/* and write the value out here */
+{
+    char	buf[100];		/* line buffer for reading *file */
+    FILE	*fp_in;
 
     if ( (fp_in = fopen(file, "r")) != NULL )  {
 	while ( fgets(buf, sizeof(buf), fp_in) != NULL )
@@ -111,9 +90,5 @@ dumprequest(want, file, fp_out)
 			fprintf(fp_out, "%s", buf);
 		    else break;
 	fclose(fp_in);
-    }	/* End if */
-
-}   /* End of dumprequest */
-
-/*****************************************************************************/
-
+    }
+}

+ 3 - 0
sys/src/cmd/postscript/common/tempnam.c

@@ -1,7 +1,10 @@
 #if defined(V9) || defined(BSD4_2) || defined(plan9)
+#define _BSD_EXTENSION
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>

+ 50 - 97
sys/src/cmd/postscript/download/download.c

@@ -50,6 +50,8 @@
  * be a more general program (e.g. scan for other comments).
  */
 
+#define _BSD_EXTENSION
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -83,15 +85,20 @@ int	atend = FALSE;			/* TRUE only if a comment says so */
 FILE	*fp_in = stdin;			/* next input file */
 FILE	*fp_temp = NULL;		/* for copying stdin */
 
-/*****************************************************************************/
+void	arguments(void);
+void	copyfonts(char *);
+void	copyinput(void);
+void	done(void);
+void	download(void);
+void	init_signals(void);
+void	options(void);
+void	readmap(void);
+void	readresident(void);
 
 main(agc, agv)
-
     int		agc;
     char	*agv[];
-
 {
-
 /*
  *
  * Host resident font downloader. The input files are assumed to be part of a
@@ -111,19 +118,14 @@ main(agc, agv)
     arguments();			/* then process non-option arguments */
     done();				/* and clean things up */
     exit(x_stat);			/* not much could be wrong */
+    return 0;
+}
 
-}   /* End of main */
-
-/*****************************************************************************/
-
-init_signals()
-
+void
+init_signals(void)
 {
-
 /*
- *
  * Makes sure we handle interrupts properly.
- *
  */
 
     if ( signal(SIGINT, interrupt) == SIG_IGN ) {
@@ -133,18 +135,14 @@ init_signals()
     } else {
 	signal(SIGHUP, interrupt);
 	signal(SIGQUIT, interrupt);
-    }   /* End else */
+    }
 
     signal(SIGTERM, interrupt);
+}
 
-}   /* End of init_signals */
-
-/*****************************************************************************/
-
-options()
-
+void
+options(void)
 {
-
     int		ch;			/* return value from getopt() */
     char	*optnames = "c:fm:p:r:H:T:DI";
 
@@ -207,29 +205,23 @@ options()
 
     argc -= optind;			/* get ready for non-option args */
     argv += optind;
+}
 
-}   /* End of options */
-
-/*****************************************************************************/
-
-readmap()
-
+void
+readmap(void)
 {
-
     char	*path;
     char	*ptr;
     int		fd;
     struct stat	sbuf;
 
 /*
- *
  * Initializes the map table by reading an ASCII mapping file. If mapname begins
  * with a / it's the map table. Otherwise hostfontdir, mapname, and suffix are
  * combined to build the final pathname. If we can open the file we read it all
  * into memory, erase comments, and separate the font and file name pairs. When
  * we leave next points to the next free slot in the map[] array. If it's zero
  * nothing was in the file or we couldn't open it.
- *
  */
 
     if ( hostfontdir == NULL || mapname == NULL )
@@ -268,29 +260,23 @@ readmap()
 		break;
 	    if ( map[next].file == NULL )
 		error(FATAL, "map table format error - check %s", path);
-	}   /* End for */
-    }	/* End if */
-
-}   /* End of readmap */
-
-/*****************************************************************************/
-
-readresident()
+	}
+    }
+}
 
+void
+readresident(void)
 {
-
     FILE	*fp;
     char	*path;
     int		ch;
     int		n;
 
 /*
- *
  * Reads a file that lists the resident fonts for a particular printer and marks
  * each font as already downloaded. Nothing's done if the file can't be read or
  * there's no mapping file. Comments, as in the map file, begin with a % and
  * extend to the end of the line. Added for Unix 4.0 lp.
- *
  */
 
     if ( next == 0 || (printer == NULL && residentfonts == NULL) )
@@ -308,16 +294,12 @@ readresident()
 	    else if ( (n = lookup(buf)) < next )
 		map[n].downloaded = TRUE;
 	fclose(fp);
-    }	/* End if */
-
-}   /* End of readresident */
-
-/*****************************************************************************/
-
-arguments()
+    }
+}
 
+void
+arguments(void)
 {
-
 /*
  *
  * Makes sure all the non-option command line arguments are processed. If we get
@@ -343,34 +325,23 @@ arguments()
 		fclose(fp_temp);
 	    argc--;
 	    argv++;
-	}   /* End while */
-    }	/* End else */
-
-}   /* End of arguments */
-
-/*****************************************************************************/
-
-done()
+	}
+    }
+}
 
+void
+done(void)
 {
-
 /*
- *
  * Clean things up before we quit.
- *
  */
-
     if ( temp_file != NULL )
 	unlink(temp_file);
+}
 
-}   /* End of done */
-
-/*****************************************************************************/
-
-download()
-
+void
+download(void)
 {
-
     int		infontlist = FALSE;
 
 /*
@@ -407,32 +378,24 @@ download()
 	    } else if ( buf[2] == '+' && infontlist == TRUE )
 		copyfonts(buf);
 	    else infontlist = FALSE;
-	}   /* End while */
-    }	/* End if */
-
+	}
+    }
     copyinput();
+}
 
-}   /* End of download */
-
-/*****************************************************************************/
-
+void
 copyfonts(list)
-
     char	*list;
-
 {
-
     char	*font;
     char	*path;
     int		n;
 
 /*
- *
  * list points to a %%DocumentFonts: or continuation comment. What follows the
  * the keyword will be a list of fonts separated by white space (or (atend)).
  * Look for each font in the map table and if it's found copy the font file to
  * stdout (once only).
- *
  */
 
     strtok(list, " \n");		/* skip to the font list */
@@ -441,7 +404,7 @@ copyfonts(list)
 	if ( strcmp(font, ATEND) == 0 ) {
 	    atend = TRUE;
 	    break;
-	}   /* End if */
+	}
 	if ( (n = lookup(font)) < next ) {
 	    if ( *map[n].file != '/' ) {
 		if ( (path = malloc(strlen(hostfontdir)+strlen(map[n].file)+2)) == NULL )
@@ -451,17 +414,13 @@ copyfonts(list)
 		free(path);
 	    } else cat(map[n].file);
 	    map[n].downloaded = TRUE;
-	}   /* End if */
-    }	/* End while */
-
-}   /* End of copyfonts */
-
-/*****************************************************************************/
-
-copyinput()
+	}
+    }
+}
 
+void
+copyinput(void)
 {
-
 /*
  *
  * Copies the input file to stdout. If fp_temp isn't NULL seek to the start and
@@ -481,17 +440,11 @@ copyinput()
 
     while ( fgets(buf, sizeof(buf), fp_in) != NULL )
 	printf("%s", buf);
-
-}   /* End of copyinput */
-
-/*****************************************************************************/
+}
 
 lookup(font)
-
     char	*font;
-
 {
-
     int		i;
 
 /*

+ 1 - 1
sys/src/cmd/postscript/download/mkfile

@@ -19,7 +19,7 @@ BIN=$POSTBIN
 </sys/src/cmd/mkone
 CC=pcc
 LD=pcc
-CFLAGS=-c -D$SYSTEM -D_POSIX_SOURCE -I$COMMONDIR -B
+CFLAGS=$CFLAGS -c -D$SYSTEM -D_POSIX_SOURCE -I$COMMONDIR -B
 
 $LIB:
 	cd $COMMONDIR

+ 2 - 2
sys/src/cmd/postscript/p9bitpost/mkfile

@@ -11,7 +11,7 @@ OFILES=pslib.$O\
 
 BIN=$POSTBIN
 
-LIB=/$objtype/lib/libmemdraw.a
+LIB=
 < /sys/src/cmd/mkone
 
-CFLAGS=-w -I$COMMONDIR
+CFLAGS=$CFLAGS -I$COMMONDIR

+ 2 - 2
sys/src/cmd/postscript/p9bitpost/pslib.c

@@ -688,7 +688,7 @@ imagebits(Biobuf *ioutb, Memimage *im)
 	for (i = 0; i < n4; i += 4){
 		cmap2ascii85(data+i, c85);
 		lsf += strlen((char *)c85);
-		Bprint(ioutb, "%s", c85);
+		Bprint(ioutb, "%s", (char *)c85);
 		if (lsf > 74) {
 			Bprint(ioutb, "\n");
 			lsf = 0;
@@ -705,7 +705,7 @@ imagebits(Biobuf *ioutb, Memimage *im)
 		cmap2ascii85(foo, c85);
 		if (strcmp((char *)c85, "z") == 0 )
 			strcpy((char *)c85, "!!!!!");
-		Bprint(ioutb, "%.*s", nrest+1, c85);
+		Bprint(ioutb, "%.*s", nrest+1, (char *)c85);
 	}
 	Bprint(ioutb, "\n~>");
 	Bprint(ioutb, "\n");

+ 2 - 2
sys/src/cmd/postscript/postprint/postprint.c

@@ -1,5 +1,4 @@
 /*
- *
  * postprint - PostScript translator for ASCII files.
  *
  * A simple program that translates ASCII files into PostScript. All it really
@@ -75,10 +74,11 @@
  * The -P option passes arbitrary PostScript through to the output file. Among
  * other things it can be used to set (or change) values that can't be accessed by
  * other options.
- *
  */
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <signal.h>
 #include <ctype.h>
 #ifdef plan9

+ 10 - 24
sys/src/cmd/postscript/postreverse/postreverse.c

@@ -1,5 +1,4 @@
 /*
- *
  * postreverse - reverse the page order in certain PostScript files.
  *
  * Page reversal relies on being able to locate sections of a document using file
@@ -67,10 +66,15 @@
  * then processes that file. That means the input is read three times (rather than
  * two) whenever we handle stdin. That's expensive, and shouldn't be too difficult
  * to fix, but I haven't gotten around to it yet.
- *
  */
 
+#define _BSD_EXTENSION
+#define _POSIX_SOURCE
+
 #include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <fcntl.h>
@@ -101,23 +105,16 @@ char	buf[2048];			/* line buffer for input file */
 FILE	*fp_in;				/* stuff is read from this file */
 FILE	*fp_out = stdout;		/* and written here */
 
-/*****************************************************************************/
-
 main(agc, agv)
-
     int		agc;
     char	*agv[];
-
 {
-
 /*
- *
  * A simple program that reverses the pages in specially formatted PostScript
  * files. Will work with all the translators in this package, and should handle
  * any document that conforms to Adobe's version 1.0 or 2.0 file structuring
  * conventions. Only one input file is allowed, and it can either be a named (on
  * the command line) file or stdin.
- *
  */
 
     argc = agc;				/* other routines may want them */
@@ -131,19 +128,13 @@ main(agc, agv)
     done();				/* and clean things up */
 
     exit(x_stat);			/* not much could be wrong */
-
-}   /* End of main */
-
-/*****************************************************************************/
+    return 0;
+}
 
 init_signals()
-
 {
-
 /*
- *
  * Makes sure we handle interrupts properly.
- *
  */
 
     if ( signal(SIGINT, interrupt) == SIG_IGN )  {
@@ -153,18 +144,13 @@ init_signals()
     } else {
 	signal(SIGHUP, interrupt);
 	signal(SIGQUIT, interrupt);
-    }   /* End else */
+    }
 
     signal(SIGTERM, interrupt);
-
-}   /* End of init_signals */
-
-/*****************************************************************************/
+}
 
 options()
-
 {
-
     int		ch;			/* return value from getopt() */
     char	*optnames = "n:o:rvT:DI";
 

+ 6 - 0
sys/src/cmd/postscript/tcpostio/dial.c

@@ -1,5 +1,11 @@
+#define _BSD_EXTENSION
+#define _NET_EXTENSION
+#define _POSIX_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/socket.h>

+ 1 - 1
sys/src/cmd/postscript/tcpostio/mkfile

@@ -10,7 +10,7 @@ BIN=$POSTBIN
 
 </sys/src/cmd/mkone
 CC=pcc
-CFLAGS=-Bw -c -D_BSD_EXTENSION -D_NET_EXTENSION -Dplan9
+CFLAGS=$CFLAGS -c -Dplan9
 
 syms:V:
 	vc $CFLAGS -a tcpostio.c > syms

+ 34 - 24
sys/src/cmd/postscript/tcpostio/tcpostio.c

@@ -1,20 +1,23 @@
+#define _BSD_EXTENSION
+#define _NET_EXTENSION
+#define _POSIX_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
-
-#ifdef plan9
-#include <bsd.h>
-#endif
-
+#include <unistd.h>
+#include <fcntl.h>
 #include <string.h>
+#include <ctype.h>
 #include <signal.h>
 #include <errno.h>
+#include <select.h>
 #include <sys/types.h>
 #include <sys/time.h>
-
 #include <sys/socket.h>
+#include <sys/wait.h>
 
 extern	int dial_debug;
-extern	int	dial(char*, char*, char*, int*);
+extern	int dial(char*, char*, char*, int*);
 
 
 /* debug = 0 for no debugging */
@@ -346,7 +349,7 @@ dowait:
 		if (n > 0) {
 			fprintf(stderr, "more fds selected than requested!\n");
 			exit(1);
-		};	
+		};
 	} while ((progstate != FATAL_ERROR) && (progstate != OVER_AND_OUT));
 
 	if (progstate == FATAL_ERROR)
@@ -361,7 +364,7 @@ sendfile(int infd, int printerfd, int pipefd)
 	unsigned char proto;
 	int progstate = START;
 	int i, n, nfds;
-	int bytesread,  bytesent = 0; 
+	int bytesread,  bytesent = 0;
 
 	nfds = ((pipefd>printerfd)?pipefd:printerfd) + 1;
 
@@ -463,10 +466,10 @@ sendfile(int infd, int printerfd, int pipefd)
 
 void main(int argc, char *argv[]) {
 	int c, usgflg=0, infd, printerfd;
-	int cpid;
+	int cpid, sprv;
 	int pipefd[2];
 	char *dialstr;
-	unsigned long rprv, sprv;
+	unsigned long rprv;
 
 	dialstr = 0;
 
@@ -484,14 +487,15 @@ void main(int argc, char *argv[]) {
 		case '?':
 			fprintf(stderr, "unknown option %c\n", c);
 			usgflg++;
+			break;
 		}
 	if (optind < argc)
 		dialstr = argv[optind++];
-	else {
+	else
 		usgflg++;
-	}
 	if (usgflg) {
-		fprintf(stderr, "usage: %s [-b baudrate] net!host!service [infile]\n", argv[0]);
+		fprintf(stderr, "usage: %s [-b baudrate] net!host!service [infile]\n",
+			argv[0]);
 		exit (2);
 	}
 	if (optind < argc) {
@@ -504,10 +508,13 @@ void main(int argc, char *argv[]) {
 	} else
 		infd = 0;
 
-	if (debug & 02) fprintf(stderr, "blocksize=%d\n", blocksize);
-	if (debug) fprintf(stderr, "dialing address=%s\n", dialstr);
+	if (debug & 02)
+		fprintf(stderr, "blocksize=%d\n", blocksize);
+	if (debug)
+		fprintf(stderr, "dialing address=%s\n", dialstr);
 	printerfd = dial(dialstr, 0, 0, 0);
-	if (printerfd < 0) exit(1);
+	if (printerfd < 0)
+		exit(1);
 
 	fprintf(stderr, "printer startup\n");
 
@@ -519,16 +526,19 @@ void main(int argc, char *argv[]) {
 	case -1:
 		perror("fork error");
 		exit(1);
-	case 0:
+	case 0:				/* child - to printer */
 		close(pipefd[1]);
-		sprv = sendfile(infd, printerfd, pipefd[0]);	/* child - to printer */
-		if (debug) fprintf(stderr, "to remote - exiting\n");
+		sprv = sendfile(infd, printerfd, pipefd[0]);
+		if (debug)
+			fprintf(stderr, "to remote - exiting\n");
 		exit(sprv);
-	default:
+	default:			/* parent - from printer */
 		close(pipefd[0]);
-		rprv = readprinter(printerfd, pipefd[1]);	/* parent - from printer */
-		if (debug) fprintf(stderr, "from remote - exiting\n");
-		while(wait(&sprv) != cpid);
+		rprv = readprinter(printerfd, pipefd[1]);
+		if (debug)
+			fprintf(stderr, "from remote - exiting\n");
+		while(wait(&sprv) != cpid)
+			;
 		exit(rprv|sprv);
 	}
 }

+ 0 - 4
sys/src/cmd/troff/fns.h

@@ -3,10 +3,6 @@
  */
 int	pclose(FILE*);
 long	filesize(int fd);
-int	open(char *, int);
-int	read(int, char *, int);
-int	lseek(int, long, int);
-int	close(int);
 int	getpid(void);
 
 /*

+ 1 - 1
sys/src/cmd/troff/mkfile

@@ -27,7 +27,7 @@ HFILES=tdef.h\
 
 BIN=/$objtype/bin
 </sys/src/cmd/mkone
-CFLAGS=-c -DSTRICT -DUNICODE
+CFLAGS=-FTV -c -DSTRICT -DUNICODE
 CC=pcc
 
 TMACDIR='"sys/lib/tmac/tmac."'

+ 3 - 5
sys/src/cmd/troff/n1.c

@@ -193,7 +193,7 @@ loop:
 		while (cbits(i) != '\n')
 			pchar(i = getch());
 		tflg = 0;
-		copyf--;
+		copyf--;			/* pointless */
 		goto loop;
 	}
 	if (j == cc || j == c2) {
@@ -670,7 +670,6 @@ char	ifilt[32] = { 0, 001, 002, 003, 0, 005, 006, 007, 010, 011, 012 };
 
 Tchar getch0(void)
 {
-	int j;
 	Tchar i;
 
 again:
@@ -713,7 +712,6 @@ g0:
 			if (ip)
 				goto again;
 		}
-g2:
 		if (i >= 040)			/* zapped: && i < 0177 */
 			goto g4;
 		i = ifilt[i];
@@ -741,6 +739,7 @@ Tchar get1ch(FILE *fp)	/* get one "character" from input, figure out what alphab
 	char buf[100], *p;
 	int i, n, c;
 
+	n = c = 0;
 	for (i = 0, p = buf; i < MB_CUR_MAX; i++) {
 		if ((c = getc(fp)) == EOF)
 			return c;
@@ -911,7 +910,6 @@ void casenx(void)
 getname(void)
 {
 	int j, k;
-	Tchar i;
 
 	lgf++;
 	for (k = 0; k < NS - 1; k++) {
@@ -929,10 +927,10 @@ getname(void)
 void caseso(void)
 {
 	FILE *fp;
-	char *p, *q;
 
 	lgf++;
 	nextf[0] = 0;
+	fp = NULL;
 	if (skip() || !getname() || (fp = fopen(nextf, "r")) == NULL || ifi >= NSO) {
 		ERROR "can't open file %s", nextf WARN;
 		done(02);

+ 5 - 5
sys/src/cmd/troff/n10.c

@@ -39,7 +39,7 @@ static char *parse(char *s, int typeit)	/* convert \0, etc to nroff driving tabl
 	}
 	for (;;) {
 		if (quote && *s == '"') {
-			s++;
+			s++;			/* pointless */
 			break;
 		}
 		if (!quote && (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\0'))
@@ -74,14 +74,13 @@ static char *parse(char *s, int typeit)	/* convert \0, etc to nroff driving tabl
 
 static int getnrfont(FILE *fp)	/* read the nroff description file */
 {
-	FILE *fin;
 	Chwid chtemp[NCHARS];
 	static Chwid chinit;
 	int i, nw, n, wid, code, type;
-	char buf[100], ch[100], s1[100], s2[100], cmd[300];
+	char buf[100], ch[100], s1[100], s2[100];
 	wchar_t wc;
 
-
+	code = 0;			/* no idea what this should be */
 	chinit.wid = 1;
 	chinit.str = "";
 	for (i = 0; i < ALPHABET; i++) {
@@ -114,6 +113,7 @@ static int getnrfont(FILE *fp)	/* read the nroff description file */
 #endif	/*UNICODE*/
 		} else {
 			if (strcmp(ch, "---") == 0) { /* no name */
+				/* code used to be uninitialised here */
 				sprintf(ch, "%d", code);
 				type = Number;
 			} else
@@ -139,7 +139,7 @@ static int getnrfont(FILE *fp)	/* read the nroff description file */
 void n_ptinit(void)
 {
 	int i;
-	char *p, *cp;
+	char *p;
 	char opt[50], cmd[100];
 	FILE *fp;
 

+ 0 - 1
sys/src/cmd/troff/n2.c

@@ -137,7 +137,6 @@ void outweird(int k)	/* like ptchname() but ascii */
 
 void outascii(Tchar i)	/* print i in best-guess ascii */
 {
-	char *p;
 	int j = cbits(i);
 
 /* is this ever called with NROFF set? probably doesn't work at all. */

+ 5 - 6
sys/src/cmd/troff/n3.c

@@ -64,7 +64,7 @@ void blockinit(void)
 
 char *grow(char *ptr, int num, int size)	/* make array bigger */
 {
-	char *p, new;
+	char *p;
 
 	if (ptr == NULL)
 		p = (char *) calloc(num, size);
@@ -176,8 +176,7 @@ void mrehash(void)
 
 void caserm(void)
 {
-	int j;
-	int k = 0;
+	int j, k;
 
 	lgf++;
 g0:
@@ -249,7 +248,7 @@ void casede(void)
 		savoff = offset;
 		offset = apptr;
 		wbf((Tchar) IMP);
-		offset = savoff;
+		offset = savoff;	/* pointless */
 	}
 	offset = dip->op;
 	if (req != '.')
@@ -307,7 +306,6 @@ void growcontab(void)
 Offset finds(int mn)
 {
 	int i;
-	Tchar j = IMP;
 	Offset savip;
 
 	oldmn = findmn(mn);
@@ -383,6 +381,7 @@ int copyb(void)
 	flushi();
 	nlflg = 0;
 	state = 1;
+	savoff = 0;
 
 /* state 0	eat up
  * state 1	look for .
@@ -506,7 +505,7 @@ void wbf(Tchar i)	/* store i into offset, get ready for next one */
 	if (i == 0)
 		contabp[savslot].emx = offset;
 	off = boffset(offset);
-	blist[j].bp[off++] = i;
+	blist[j].bp[off] = i;
 	offset++;
 	if (pastend(offset)) {	/* off the end of this block */
 		if (blist[j].nextoff == -1) {

+ 3 - 2
sys/src/cmd/troff/n5.c

@@ -83,6 +83,7 @@ chget(int c)
 {
 	Tchar i;
 
+	i = 0;
 	if (skip() || ismot(i = getch()) || cbits(i) == ' ' || cbits(i) == '\n') {
 		ch = i;
 		return(c);
@@ -431,7 +432,7 @@ void casetm1(int ab, FILE *out)
 		else {
 			extern int error;
 			int savtrac = trace;
-			i = trace = 0;
+			trace = 0;
 			noscale++;
 			i = inumb(&trace);
 			noscale--;
@@ -472,7 +473,7 @@ void casetm1(int ab, FILE *out)
 				sprintf(&tmbuf[i], "\\N'%s'", p+1);
 				break;
 			case Troffchar:
-				if ((j = strlen(p+1)) == 2)
+				if (strlen(p+1) == 2)
 					sprintf(&tmbuf[i], "\\(%s", p+1);
 				else
 					sprintf(&tmbuf[i], "\\C'%s'", p+1);

+ 3 - 3
sys/src/cmd/troff/n6.c

@@ -83,9 +83,9 @@ void n_setps(void )
 	i = cbits(getch());
 	if (isdigit(i)) {		/* \sd or \sdd */
 		i -= '0';
-		if (i == 0)		/* \s0 */
+		if (i == 0) {		/* \s0 */
 			;
-		else if (i <= 3 && (ch=getch()) && isdigit(cbits(ch))) {	/* \sdd */
+		} else if (i <= 3 && (ch=getch()) && isdigit(cbits(ch))) {	/* \sdd */
 			ch = 0;
 		}
 	} else if (i == '(') {		/* \s(dd */
@@ -294,7 +294,7 @@ void n_casebd(void)
 {
 	int i, j, k;
 
-	k = 0;
+	j = k = 0;
 bd0:
 	if (skip() || !(i = getrq()) || (j = findft(i)) == -1) {
 		if (k)

+ 3 - 1
sys/src/cmd/troff/n7.c

@@ -4,6 +4,7 @@
 
 #ifdef STRICT
 	/* not in ANSI or POSIX */
+#undef  isascii
 #define	isascii(a) ((a) >= 0 && (a) <= 127)
 #endif
 
@@ -354,6 +355,7 @@ void newline(int a)
 	int i, j, nlss;
 	int opn;
 
+	nlss = 0;
 	if (a)
 		goto nl1;
 	if (dip != d) {
@@ -656,7 +658,7 @@ getword(int x)
 	int noword;
 	int obits;
 
-	noword = 0;
+	j = noword = 0;
 	if (x)
 		if (pendw) {
 			*pendw = 0;

+ 3 - 4
sys/src/cmd/troff/n8.c

@@ -306,12 +306,11 @@ Tchar *chkvow(Tchar *w)
 
 void digram(void)
 {
-	Tchar *w;
-	int val;
-	Tchar *nhyend, *maxw;
-	int maxval;
+	int maxval, val;
+	Tchar *nhyend, *maxw, *w;
 	extern char bxh[26][13], bxxh[26][13], xxh[26][13], xhx[26][13], hxx[26][13];
 
+	maxw = 0;
 again:
 	if (!(w = chkvow(hyend + 1)))
 		return;

+ 5 - 7
sys/src/cmd/troff/n9.c

@@ -331,20 +331,18 @@ void casefc(void)
 
 Tchar setfield(int x)
 {
-	Tchar ii, jj, *fp;
-	int i, j;
-	int length, ws, npad, temp, type;
+	Tchar rchar, ii, jj, *fp;
 	Tchar **pp, *padptr[NPP];
 	Tchar fbuf[FBUFSZ];
-	int savfc, savtc, savlc;
-	Tchar rchar;
-	int savepos;
+	int i, j, length, ws, npad, temp, type, savepos, savfc, savtc, savlc;
 	static Tchar wbuf[] = { WORDSP, 0};
 
 	if (x == tabch) 
 		rchar = tabc | chbits;
-	else if (x ==  ldrch) 
+	else if (x == ldrch) 
 		rchar = dotc | chbits;
+	else
+		rchar = 0;
 	temp = npad = ws = 0;
 	savfc = fc;
 	savtc = tabch;

+ 3 - 3
sys/src/cmd/troff/t10.c

@@ -156,11 +156,11 @@ void t_ptout(Tchar i)
 
 int ptout0(Tchar *pi)
 {
-	int j, k, w;
-	int z, dx, dy, dx2, dy2, n;
-	Tchar i;
+	int j, k, w, z, dx, dy, dx2, dy2, n;
 	int outsize;	/* size of object being printed */
+	Tchar i;
 
+	w = 0;
 	outsize = 1;	/* default */
 	i = *pi;
 	k = cbits(i);

+ 1 - 0
sys/src/cmd/troff/t11.c

@@ -103,6 +103,7 @@ getfont(char *name, int pos)	/* create width tab for font */
 		chtemp[i] = chinit;	/* zero out to begin with */
 	ftemp->specfont = ftemp->ligfont = 0;
 	ftemp->defaultwidth = ftemp->spacewidth = Inch * Unitwidth / 72 / 3; /* should be rounded */
+	nw = code = 0;
 	while (fscanf(fin, "%s", cmd) != EOF) {
 		if (strcmp(cmd, "name") == 0)
 			fscanf(fin, "%s", ftemp->longname);

+ 5 - 3
sys/src/cmd/troff/t6.c

@@ -214,7 +214,6 @@ void xbits(Tchar i, int bitf)
 
 Tchar t_setch(int c)
 {
-	int j;
 	char temp[50];
 	char *s;
 
@@ -232,6 +231,8 @@ Tchar t_setch(int c)
 	return chadd(temp, Troffchar, Install) | chbits; /* add name even if haven't seen it */
 #else
 	if (NROFF) {
+		int j;
+
 		j = chadd(temp, Troffchar, Lookup);
 		if ( j == -1)
 			return 0;
@@ -397,6 +398,7 @@ void t_setps(void)
 	int i, j;
 
 	i = cbits(getch());
+	j = i;				/* make compiler happy */
 	if (isdigit(i)) {		/* \sd or \sdd */
 		i -= '0';
 		if (i == 0)		/* \s0 */
@@ -705,7 +707,7 @@ char *strdupl(const char *s)	/* make a copy of s */
 
 setfp(int pos, int f, char *truename, int print)	/* mount font f at position pos[0...nfonts] */
 {
-	char pathname[NS], shortname[NS], *sl;
+	char pathname[NS], shortname[NS];
 
 	zapwcache(0);
 	if (truename)
@@ -785,7 +787,7 @@ void casebd(void)
 		return;
 	}
 	zapwcache(0);
-	k = 0;
+	j = k = 0;
 bd0:
 	if (skip() || !(i = getrq()) || (j = findft(i)) == -1) {
 		if (k)

+ 4 - 0
sys/src/cmd/troff/tdef.h

@@ -1,5 +1,9 @@
+#define _BSD_EXTENSION
+#define _POSIX_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <limits.h>
 #include <ctype.h>
 #include <string.h>