Browse Source

Plan 9 from Bell Labs 2013-09-26

David du Colombier 10 years ago
parent
commit
9b7eff63fc

+ 1 - 0
sys/games/lib/fortunes

@@ -4313,3 +4313,4 @@ qemu: could not open serial device 'dev': Success
 DSM Terminator [ ABORT ] Finished [ 0 request(s) + 0 call(s) distributed in 5ms]
 Microsoft Office PowerPoint has encountered a problem and cannot exit.  We are sorry for the inconvenience.
 dd: argument 18446744073709551615 out of range
+A policeman's job is only easy in a police state. - Orson Welles

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

@@ -14,7 +14,7 @@ HFILES=$COMMONDIR/comments.h\
 BIN=$POSTBIN
 </sys/src/cmd/mkone
 
-CFLAGS=-D'PROGRAMVERSION="0.1"' -D'DOROUND=1' -I$COMMONDIR
+CFLAGS=$CFLAGS -D'PROGRAMVERSION="0.1"' -D'DOROUND=1' -I$COMMONDIR
 
 install:V:	$POSTLIB/pjw.char.ps
 

+ 166 - 191
sys/src/cmd/postscript/text2post/text2post.c

@@ -9,33 +9,34 @@
 
 char	*optnames = "a:c:f:l:m:n:o:p:s:t:x:y:P:";
 
-Biobuf *bstdin, *bstdout, *bstderr;
-Biobufhdr *Bstdin, *Bstdout, *Bstderr;
-int char_no = 0;		/* character to be done on a line */
-int line_no = 0;		/* line number on a page */
-int page_no = 0;		/* page number in a document */
-int in_string;		/* Boolean, to know whether or not we are inside a Postscript string */
-int spaces = 0;
-int tabs = 0;
-int pages_printed;
-double aspectratio = 1.0;
-int copies = 1;
-double magnification = 1.0;
-int landscape = 0;
-int formsperpage = 1;
-int linesperpage = 66;
-int pointsize = 10;
-double xoffset = .25;
-double yoffset = .25;
-char *passthrough = 0;
-static int pplistmaxsize=0;
-
-unsigned char *pplist=0;	/* bitmap list for storing pages to print */
+double	aspectratio = 1.0;
+Biobuf	inbuf, outbuf;
+Biobuf	*bin, *bout;
+int	char_no = 0;		/* character to be done on a line */
+int	copies = 1;
+int	formsperpage = 1;
+int	in_string;		/* flag: we are inside a Postscript string */
+int	landscape = 0;
+int	line_no = 0;		/* line number on a page */
+int	linesperpage = 66;
+double	magnification = 1.0;
+int	page_no = 0;		/* page number in a document */
+int	pages_printed;
+char	*passthrough = 0;
+int	pointsize = 10;
+int	spaces = 0;
+int	tabs = 0;
+double	xoffset = .25;
+double	yoffset = .25;
+
+static int pplistmaxsize = 0;
+
+uchar *pplist = 0;		/* bitmap list for storing pages to print */
 
 struct strtab {
-	int size;
-	char *str;
-	int used;
+	int	size;
+	char	*str;
+	int	used;
 };
 
 struct strtab charcode[256] = {
@@ -153,28 +154,18 @@ struct strtab fontname[FONTABSIZE] = {
 
 int
 cat(char *filename) {
-	Biobuf *bfile;
-	Biobufhdr *Bfile;
 	int n;
-	static char buf[Bsize];
+	char buf[Bsize];
+	Biobuf *bfile;
 
-	bstdin = Bopen(filename, 0);
-	if (bstdin == 0) {
-		return(1);
-	}
-	Bstdin = &(bstdin->Biobufhdr);
-	if ((bfile = Bopen(filename, OREAD)) == 0) {
+	if ((bfile = Bopen(filename, OREAD)) == nil)
 		return(1);
-	}
-	Bfile = &(bfile->Biobufhdr);
-	while ((n=Bread(Bfile, buf, Bsize)) > 0) {
-		if (Bwrite(Bstdout, buf, n) != n) {
-			return(1);
-		}
-	}
-	if (n != 0) {
+	while ((n = Bread(bfile, buf, Bsize)) > 0)
+		if (Bwrite(bout, buf, n) != n)
+			break;
+	Bterm(bfile);
+	if (n != 0)
 		return(1);
-	}
 	return(0);
 }
 
@@ -183,16 +174,14 @@ prologues(void) {
 	char *ts;
 	int tabstop;
 
-	Bprint(Bstdout, "%s", CONFORMING);
-	Bprint(Bstdout, "%s %s\n", VERSION, PROGRAMVERSION);
-	Bprint(Bstdout, "%s %s\n", DOCUMENTFONTS, ATEND);
-	Bprint(Bstdout, "%s %s\n", PAGES, ATEND);
-	Bprint(Bstdout, "%s", ENDCOMMENTS);
+	Bprint(bout, "%s", CONFORMING);
+	Bprint(bout, "%s %s\n", VERSION, PROGRAMVERSION);
+	Bprint(bout, "%s %s\n", DOCUMENTFONTS, ATEND);
+	Bprint(bout, "%s %s\n", PAGES, ATEND);
+	Bprint(bout, "%s", ENDCOMMENTS);
 
-	if (cat(POSTPRINT)) {
-		Bprint(Bstderr, "can't read %s", POSTPRINT);
-		exits("prologue");
-	}
+	if (cat(POSTPRINT))
+		sysfatal("can't read %s: %r", POSTPRINT);
 
 	if (DOROUND)
 		cat(ROUNDPAGE);
@@ -203,45 +192,46 @@ prologues(void) {
 		tabstop = strtol(ts, nil, 0);
 	if(tabstop == 0)
 		tabstop = 8;
-	Bprint(Bstdout, "/f {findfont pointsize scalefont setfont} bind def\n");
-	Bprint(Bstdout, "/tabwidth /Courier f (");
+	Bprint(bout, "/f {findfont pointsize scalefont setfont} bind def\n");
+	Bprint(bout, "/tabwidth /Courier f (");
 	while(tabstop--)
-		Bputc(Bstdout, 'n');
-	Bprint(Bstdout, ") stringwidth pop def\n");
-	Bprint(Bstdout, "/tab {tabwidth 0 ne {currentpoint 3 1 roll exch tabwidth mul add tabwidth\n");
-	Bprint(Bstdout, "\tdiv truncate tabwidth mul exch moveto} if} bind def\n");
-	Bprint(Bstdout, "/spacewidth /%s f ( ) stringwidth pop def\n", fontname[0].str);
-	Bprint(Bstdout, "/sp {spacewidth mul 0 rmoveto} bind def\n");
-	Bprint(Bstdout, "%s", ENDPROLOG);
-	Bprint(Bstdout, "%s", BEGINSETUP);
-	Bprint(Bstdout, "mark\n");
+		Bputc(bout, 'n');
+	Bprint(bout, ") stringwidth pop def\n");
+	Bprint(bout, "/tab {tabwidth 0 ne {currentpoint 3 1 roll exch tabwidth mul add tabwidth\n");
+	Bprint(bout, "\tdiv truncate tabwidth mul exch moveto} if} bind def\n");
+	Bprint(bout, "/spacewidth /%s f ( ) stringwidth pop def\n", fontname[0].str);
+	Bprint(bout, "/sp {spacewidth mul 0 rmoveto} bind def\n");
+	Bprint(bout, "%s", ENDPROLOG);
+	Bprint(bout, "%s", BEGINSETUP);
+	Bprint(bout, "mark\n");
 
 	if (formsperpage > 1) {
-		Bprint(Bstdout, "%s %d\n", FORMSPERPAGE, formsperpage);
-		Bprint(Bstdout, "/formsperpage %d def\n", formsperpage);
+		Bprint(bout, "%s %d\n", FORMSPERPAGE, formsperpage);
+		Bprint(bout, "/formsperpage %d def\n", formsperpage);
 	}
-	if (aspectratio != 1) Bprint(Bstdout, "/aspectratio %g def\n", aspectratio);
-	if (copies != 1) Bprint(Bstdout, "/#copies %d store\n", copies);
-	if (landscape) Bprint(Bstdout, "/landscape true def\n");
-	if (magnification != 1) Bprint(Bstdout, "/magnification %s def\n", magnification);
-	if (pointsize != 10) Bprint(Bstdout, "/pointsize %d def\n", pointsize);
-	if (xoffset != .25) Bprint(Bstdout, "/xoffset %g def\n", xoffset);
-	if (yoffset != .25) Bprint(Bstdout, "/yoffset %g def\n", yoffset);
+	if (aspectratio != 1) Bprint(bout, "/aspectratio %g def\n", aspectratio);
+	if (copies != 1) Bprint(bout, "/#copies %d store\n", copies);
+	if (landscape) Bprint(bout, "/landscape true def\n");
+	if (magnification != 1) Bprint(bout, "/magnification %g def\n", magnification);
+	if (pointsize != 10) Bprint(bout, "/pointsize %d def\n", pointsize);
+	if (xoffset != .25) Bprint(bout, "/xoffset %g def\n", xoffset);
+	if (yoffset != .25) Bprint(bout, "/yoffset %g def\n", yoffset);
 	cat(ENCODINGDIR"/Latin1.enc");
-	if (passthrough != 0) Bprint(Bstdout, "%s\n", passthrough);
-	Bprint(Bstdout, "setup\n");
+	if (passthrough != 0) Bprint(bout, "%s\n", passthrough);
+	Bprint(bout, "setup\n");
 	if (formsperpage > 1) {
 		cat(FORMFILE);
-		Bprint(Bstdout, "%d setupforms \n", formsperpage);
+		Bprint(bout, "%d setupforms \n", formsperpage);
 	}
 	if (cat(UNKNOWNCHAR))
-		Bprint(Bstderr, "cannot open %s\n", UNKNOWNCHAR);
-	Bprint(Bstdout, "%s", ENDSETUP);
+		fprint(2, "cannot open %s: %r\n", UNKNOWNCHAR);
+	Bprint(bout, "%s", ENDSETUP);
 }
 
 int
 pageon(void) {
-	if (pplist == 0 && page_no != 0) return(1);	/* no page list, print all pages */
+	if (pplist == 0 && page_no != 0)
+		return(1);	/* no page list, print all pages */
 	if (page_no/8 < pplistmaxsize && (pplist[page_no/8] & 1<<(page_no%8)))
 		return(1);
 	else
@@ -255,10 +245,10 @@ startpage(void) {
 	++page_no;
 	if (pageon()) {
 		++pages_printed;
-		Bprint(Bstdout, "%s %d %d\n", PAGE, page_no, pages_printed);
-		Bprint(Bstdout, "/saveobj save def\n");
-		Bprint(Bstdout, "mark\n");
-		Bprint(Bstdout, "%d pagesetup\n", pages_printed);
+		Bprint(bout, "%s %d %d\n", PAGE, page_no, pages_printed);
+		Bprint(bout, "/saveobj save def\n");
+		Bprint(bout, "mark\n");
+		Bprint(bout, "%d pagesetup\n", pages_printed);
 	}
 }
 
@@ -267,17 +257,17 @@ endpage(void) {
 	line_no = 0;
 	char_no = 0;
 	if (pageon()) {
-		Bprint(Bstdout, "cleartomark\n");
-		Bprint(Bstdout, "showpage\n");
-		Bprint(Bstdout, "saveobj restore\n");
-		Bprint(Bstdout, "%s %d %d\n", ENDPAGE, page_no, pages_printed);
+		Bprint(bout, "cleartomark\n");
+		Bprint(bout, "showpage\n");
+		Bprint(bout, "saveobj restore\n");
+		Bprint(bout, "%s %d %d\n", ENDPAGE, page_no, pages_printed);
 	}
 }
 
 void
 startstring(void) {
 	if (!in_string) {
-		if (pageon()) Bprint(Bstdout, "(");
+		if (pageon()) Bprint(bout, "(");
 		in_string = 1;
 	}
 }
@@ -285,7 +275,7 @@ startstring(void) {
 void
 endstring(void) {
 	if (in_string) {
-		if (pageon()) Bprint(Bstdout, ") show ");
+		if (pageon()) Bprint(bout, ") show ");
 		in_string = 0;
 	}
 }
@@ -294,7 +284,7 @@ void
 prspace(void) {
 	if (spaces) {
 		endstring();
-		if (pageon()) Bprint(Bstdout, "%d sp ", spaces);
+		if (pageon()) Bprint(bout, "%d sp ", spaces);
 		spaces = 0;
 	}
 }
@@ -303,7 +293,7 @@ void
 prtab(void) {
 	if (tabs) {
 		endstring();
-		if (pageon()) Bprint(Bstdout, "%d tab ", tabs);
+		if (pageon()) Bprint(bout, "%d tab ", tabs);
 		tabs = 0;
 	}
 }
@@ -321,7 +311,7 @@ txt2post(void) {
 	page_no = 0;
 	spaces = 0;
 	fontname[0].used++;
-	while ((r=Bgetrune(Bstdin)) >= 0) {
+	while ((r = Bgetrune(bin)) >= 0) {
 		thischar = r & 0xff;
 		thisfont = (r>>8) & 0xff;
 
@@ -329,7 +319,7 @@ txt2post(void) {
 			startpage();
 
 		if (line_no == 1 && char_no == 1) {
-			if (pageon()) Bprint(Bstdout, " /%s f\n", fontname[thisfont].str);
+			if (pageon()) Bprint(bout, " /%s f\n", fontname[thisfont].str);
 			lastfont = thisfont;
 		}
 
@@ -344,14 +334,13 @@ txt2post(void) {
 		case '\n':
 		case '\f':
 			startstring();
-			if (pageon()) Bprint(Bstdout, ")l\n");
+			if (pageon()) Bprint(bout, ")l\n");
 			char_no = 1;
 			in_string = 0;
 			spaces = 0;
 			tabs = 0;
-			if (++line_no > linesperpage || r == '\f') {
+			if (++line_no > linesperpage || r == '\f')
 				endpage();
-			}
 			lastchar = -1;
 			continue;
 		case '\t':
@@ -364,7 +353,7 @@ txt2post(void) {
 			/* just toss out backspaces for now */
 			if (lastchar != -1) {
 				endstring();
-				if (pageon()) Bprint(Bstdout, "(%s) stringwidth pop neg 0 rmoveto ", charcode[lastchar].str);
+				if (pageon()) Bprint(bout, "(%s) stringwidth pop neg 0 rmoveto ", charcode[lastchar].str);
 			}
 			char_no++;
 			lastchar = -1;
@@ -376,7 +365,7 @@ txt2post(void) {
 			prspace();
 			prtab();
 			endstring();
-			Bprint(Bstdout, "pw ");
+			Bprint(bout, "pw ");
 			char_no++;
 			lastchar = -1;
 			continue;
@@ -385,24 +374,24 @@ txt2post(void) {
 		if (thisfont != lastfont) {
 			endstring();
 			if (pageon()) {
-				Bprint(Bstdout, "/%s f\n", fontname[thisfont].str);
+				Bprint(bout, "/%s f\n", fontname[thisfont].str);
 			}
 			fontname[thisfont].used++;
 		}
 		prspace();
 		prtab();
 		startstring();
-		if (pageon()) Bprint(Bstdout, "%s", charcode[thischar].str);
-/*		if (pageon()) Bprint(Bstdout, "%2.2x", thischar);	/* try hex strings*/
+		if (pageon()) Bprint(bout, "%s", charcode[thischar].str);
+/*		if (pageon()) Bprint(bout, "%2.2x", thischar); /* try hex strings*/
 		char_no++;
 		lastchar = thischar;
 		lastfont = thisfont;
 	}
 	if (line_no != 0 || char_no != 0) {
 		if (char_no != 1) {
-			Bprint(Bstderr, "premature EOF: newline appended\n");
+			fprint(2, "premature EOF: newline appended\n");
 			startstring();
-			if (pageon()) Bprint(Bstdout, ")l\n");
+			if (pageon()) Bprint(bout, ")l\n");
 		}
 		endpage();
 	}
@@ -411,10 +400,12 @@ txt2post(void) {
 void
 pagelist(char *list) {
 	char c;
-	int n, m;
-	int state, start, end;
+	int n, state, start;
+	unsigned m;
 
-	if (list == 0) return;
+	if (list == 0)
+		return;
+	start = 0;
 	state = 1;
 	while ((c=*list) != '\0') {
 		n = 0;
@@ -425,13 +416,12 @@ pagelist(char *list) {
 		switch (state) {
 		case 1:
 			start = n;
+			/* fall through */
 		case 2:
 			if (n/8+1 > pplistmaxsize) {
 				pplistmaxsize = n/8+1;
-				if ((pplist = realloc(pplist, n/8+1)) == 0) {
-					Bprint(Bstderr, "cannot allocate memory for page list\n");
-					exits("malloc");
-				}
+				if ((pplist = realloc(pplist, n/8+1)) == 0)
+					sysfatal("malloc");
 			}
 			for (m=start; m<=n; m++)
 				pplist[m/8] |= 1<<(m%8);
@@ -456,110 +446,95 @@ void
 finish(void) {
 	int i;
 
-	Bprint(Bstdout, "%s", TRAILER);
-	Bprint(Bstdout, "done\n");
-	Bprint(Bstdout, "%s", DOCUMENTFONTS);
+	Bprint(bout, "%s", TRAILER);
+	Bprint(bout, "done\n");
+	Bprint(bout, "%s", DOCUMENTFONTS);
 
 	for (i=0; i<FONTABSIZE; i++)
 		if (fontname[i].used)
-			Bprint(Bstdout, " %s", fontname[i].str);
-	Bprint(Bstdout, "\n");
-
-	Bprint(Bstdout, "%s %d\n", PAGES, pages_printed);
+			Bprint(bout, " %s", fontname[i].str);
+	Bprint(bout, "\n");
 
+	Bprint(bout, "%s %d\n", PAGES, pages_printed);
 }
 
 void
 main(int argc, char *argv[]) {
 	int i;
 	char *t;
-	Biobuf *input;
 
-	if ((bstderr = (Biobuf *)malloc(sizeof(Biobuf))) == nil)
-		exits("malloc");
-	if (Binit(bstderr, 2, OWRITE) == Beof)
-		exits("Binit");
-	Bstderr = &(bstderr->Biobufhdr);
-
-	if ((bstdout = (Biobuf *)malloc(sizeof(Biobuf))) == nil)
-		exits("malloc");
-	if (Binit(bstdout, 1, OWRITE) == Beof)
-		exits("Binit");
-	Bstdout = &(bstdout->Biobufhdr);
+	bin = &inbuf;
+	bout = &outbuf;
+	if (Binit(bout, 1, OWRITE) == Beof)
+		sysfatal("Binit");
 
 	ARGBEGIN{
-		case 'a':			/* aspect ratio */
-			aspectratio = atof(ARGF());
-			break;
-		case 'c':			/* copies */
-			copies = atoi(ARGF());
-			break;
-		case 'f':			/* primary font, for now */
-			t = ARGF();
-			fontname[0].str = malloc(strlen(t)+1);
-			strcpy(fontname[0].str, t);
-			break;
-		case 'l':			/* lines per page */
-			linesperpage = atoi(ARGF());
-			break;
-		case 'm':			/* magnification */
-			magnification = atof(ARGF());
-			break;
-		case 'n':			/* forms per page */
-			formsperpage = atoi(ARGF());
-			break;
-		case 'o':			/* output page list */
-			pagelist(ARGF());
-			break;
-		case 'p':			/* landscape or portrait mode */
-			if ( ARGF()[0] == 'l' )
-				landscape = 1;
-			else
-				landscape = 0;
-			break;
-		case 's':			/* point size */
-			pointsize = atoi(ARGF());
-			break;
-		case 'x':			/* shift things horizontally */
-			xoffset = atof(ARGF());
-			break;
-
-		case 'y':			/* and vertically on the page */
-			yoffset = atof(ARGF());
-			break;
-		case 'P':			/* PostScript pass through */
-			t = ARGF();
-			i = strlen(t) + 1;
-			passthrough = malloc(i);
-			if (passthrough == 0) {
-				Bprint(Bstderr, "cannot allocate memory for argument string\n");
-				exits("malloc");
-			}
-			strncpy(passthrough, t, i);
-			break;
-		default:			/* don't know what to do for ch */
-			Bprint(Bstderr, "unknown option %C\n", ARGC());
-			break;
+	case 'a':			/* aspect ratio */
+		aspectratio = atof(ARGF());
+		break;
+	case 'c':			/* copies */
+		copies = atoi(ARGF());
+		break;
+	case 'f':			/* primary font, for now */
+		t = ARGF();
+		fontname[0].str = malloc(strlen(t)+1);
+		strcpy(fontname[0].str, t);
+		break;
+	case 'l':			/* lines per page */
+		linesperpage = atoi(ARGF());
+		break;
+	case 'm':			/* magnification */
+		magnification = atof(ARGF());
+		break;
+	case 'n':			/* forms per page */
+		formsperpage = atoi(ARGF());
+		break;
+	case 'o':			/* output page list */
+		pagelist(ARGF());
+		break;
+	case 'p':			/* landscape or portrait mode */
+		if ( ARGF()[0] == 'l' )
+			landscape = 1;
+		else
+			landscape = 0;
+		break;
+	case 's':			/* point size */
+		pointsize = atoi(ARGF());
+		break;
+	case 'x':			/* shift things horizontally */
+		xoffset = atof(ARGF());
+		break;
+
+	case 'y':			/* and vertically on the page */
+		yoffset = atof(ARGF());
+		break;
+	case 'P':			/* PostScript pass through */
+		t = ARGF();
+		i = strlen(t) + 1;
+		passthrough = malloc(i);
+		if (passthrough == 0)
+			sysfatal("malloc");
+		strncpy(passthrough, t, i);
+		break;
+	default:
+		fprint(2, "unknown option %C\n", ARGC());
+		break;
 	}ARGEND;
+
 	prologues();
 	if (argc <= 0) {
-		if ((bstdin = (Biobuf *)malloc(sizeof(Biobuf))) == nil)
-			exits("malloc");
-		if (Binit(bstdin, 0, OREAD) == Beof) {
-			fprint(2, "cannot Binit stdin\n");
-			exits("Binit");
-		}
-		Bstdin = &(bstdin->Biobufhdr);
+		if (Binit(bin, 0, OREAD) == Beof)
+			sysfatal("cannot Binit stdin");
 		txt2post();
 	}
 	for (i=0; i<argc; i++) {
-		bstdin = Bopen(argv[i], 0);
-		if (bstdin == 0) {
-			fprint(2, "cannot open file %s\n", argv[i]);
+		bin = Bopen(argv[i], OREAD);
+		if (bin == nil) {
+			fprint(2, "cannot open %s: %r\n", argv[i]);
 			continue;
 		}
-		Bstdin = &(bstdin->Biobufhdr);
 		txt2post();
+		Bterm(bin);
 	}
 	finish();
 	exits("");

+ 49 - 35
sys/src/cmd/postscript/tr2post/Bgetfield.c

@@ -7,45 +7,47 @@
 int
 isspace(Rune r)
 {
-	return(r==' ' || r=='\t' || r=='\n' || r == '\r' || r=='\f');
+ 	return r==' ' || r=='\t' || r=='\n' || r=='\r' || r=='\f';
 }
 
 int
 Bskipws(Biobufhdr *bp) {
-	int r;
-	char c[UTFmax];
-	int sindex = 0;
+	int r, sindex = 0;
 
 	/* skip over initial white space */
 	do {
 		r = Bgetrune(bp);
-		if (r == '\n') inputlineno++;
-		sindex++;	
+		if (r == '\n')
+			inputlineno++;
+		sindex++;
 	} while (r>=0 && isspace(r));
-	if (r<0) {
+	if (r<0)
 		return(-1);
-	} else if (!isspace(r)) {
+	else if (!isspace(r)) {
 		Bungetrune(bp);
 		--sindex;
 	}
-	return(sindex);
+	return sindex;
 }
 
 int
 asc2dig(char c, int base) {
 	if (c >= '0' && c <= '9')
-		if (base == 8 && c > '7') return(-1);
-		else return(c - '0');
-
+		if (base == 8 && c > '7')
+			return(-1);
+		else
+			return(c - '0');
 	if (base == 16)
-		if (c >= 'a' && c <= 'f') return(10 + c - 'a');
-		else if (c >= 'A' && c <= 'F') return(10 + c - 'A');
-
+		if (c >= 'a' && c <= 'f')
+			return(10 + c - 'a');
+		else if (c >= 'A' && c <= 'F')
+			return(10 + c - 'A');
 	return(-1);
 }
 
-/* get a string of type: "d" for decimal integer, "u" for unsigned,
- * "s" for string", "c" for char, 
+/*
+ * get a string of type: "d" for decimal integer, "u" for unsigned,
+ * "s" for string", "c" for char,
  * return the number of characters gotten for the field.  If nothing
  * was gotten and the end of file was reached, a negative value
  * from the Bgetrune is returned.
@@ -53,20 +55,21 @@ asc2dig(char c, int base) {
 
 int
 Bgetfield(Biobufhdr *bp, int type, void *thing, int size) {
-	int r;
-	Rune R;
-	char c[UTFmax];
-	int sindex = 0, i, j, n = 0;
-	int negate = 0;
 	int base = 10;
-	BOOLEAN bailout = FALSE;
 	int dig;
-	unsigned int u = 0;
+	int negate = 0;
+	int sindex = 0, i, j, n = 0;
+	long r;
+	Rune R;
+	unsigned u = 0;
+	BOOLEAN bailout = FALSE;
+	char c[UTFmax];
 
 	/* skip over initial white space */
 	if (Bskipws(bp) < 0)
 		return(-1);
 
+	r = 0;
 	switch (type) {
 	case 'd':
 		while (!bailout && (r = Bgetrune(bp))>=0) {
@@ -81,7 +84,7 @@ Bgetfield(Biobufhdr *bp, int type, void *thing, int size) {
 				case '0':
 					base = 8;
 					continue;
-				default:	
+				default:
 					break;
 				}
 				break;
@@ -90,11 +93,15 @@ Bgetfield(Biobufhdr *bp, int type, void *thing, int size) {
 					base = 16;
 					continue;
 				}
+				break;
 			}
-			if ((dig = asc2dig(r, base)) == -1) bailout = TRUE;						
-			else n = dig + (n * base);
+			if ((dig = asc2dig(r, base)) == -1)
+				bailout = TRUE;
+			else
+				n = dig + (n * base);
 		}
-		if (r < 0) return(-1);
+		if (r < 0)
+			return(-1);
 		*(int *)thing = (negate)?-n:n;
 		Bungetrune(bp);
 		break;
@@ -112,24 +119,30 @@ Bgetfield(Biobufhdr *bp, int type, void *thing, int size) {
 					base = 16;
 					continue;
 				}
+				break;
 			}
-			if ((dig = asc2dig(r, base)) == -1) bailout = TRUE;						
-			else u = dig + (n * base);
+			if ((dig = asc2dig(r, base)) == -1)
+				bailout = TRUE;
+			else
+				u = dig + (n * base);
 		}
 		*(int *)thing = u;
-		if (r < 0) return(-1);
+		if (r < 0)
+			return(-1);
 		Bungetrune(bp);
 		break;
 	case 's':
 		j = 0;
-		while ((size>j+UTFmax) && (r = Bgetrune(bp))>=0 && !isspace(r)) {
+		while (size > j+UTFmax && (r = Bgetrune(bp)) >= 0 &&
+		    !isspace(r)) {
 			R = r;
 			i = runetochar(&(((char *)thing)[j]), &R);
 			j += i;
 			sindex++;
 		}
-		((char *)thing)[j++] = '\0';
-		if (r < 0) return(-1);
+		((char *)thing)[j] = '\0';
+		if (r < 0)
+			return(-1);
 		Bungetrune(bp);
 		break;
 	case 'r':
@@ -138,7 +151,8 @@ Bgetfield(Biobufhdr *bp, int type, void *thing, int size) {
 			sindex++;
 			return(sindex);
 		}
-		if (r <= 0) return(-1);
+		if (r <= 0)
+			return(-1);
 		Bungetrune(bp);
 		break;
 	default:

+ 76 - 64
sys/src/cmd/postscript/tr2post/chartab.c

@@ -39,7 +39,7 @@ void
 mountfont(int pos, char *fontname) {
 	int i;
 
-	if (debug) Bprint(Bstderr, "mountfont(%d, %s)\n", pos, fontname);
+	if (debug) fprint(2, "mountfont(%d, %s)\n", pos, fontname);
 	if (pos < 0 || pos >= fontmnt)
 		error(FATAL, "cannot mount a font at position %d,\n  can only mount into postions 0-%d\n",
 			pos, fontmnt-1);
@@ -58,7 +58,7 @@ settrfont(void) {
 		error(FATAL, "Font at position %d was not initialized, botch!\n", fontpos);
 
 	curtrofffontid = findtfn(fontmtab[fontpos], 1);
-	if (debug) Bprint(Bstderr, "settrfont()-> curtrofffontid=%d\n", curtrofffontid);
+	if (debug) fprint(2, "settrfont()-> curtrofffontid=%d\n", curtrofffontid);
 	curfontpos = fontpos;
 	if (curtrofffontid < 0) {
 		int i;
@@ -120,23 +120,23 @@ findpfn(char *fontname, int insflg) {
 	return(-1);
 }
 
-char postroffdirname[] = "/sys/lib/postscript/troff";		/* "/sys/lib/postscript/troff/"; */
-char troffmetricdirname[] = "/sys/lib/troff/font";	/* "/sys/lib/troff/font/devutf/"; */
+char postroffdirname[] = "/sys/lib/postscript/troff"; /* "/sys/lib/postscript/troff/"; */
+char troffmetricdirname[] = "/sys/lib/troff/font"; /* "/sys/lib/troff/font/devutf/"; */
 
 int
 readpsfontdesc(char *fontname, int trindex) {
-	static char *filename = 0;
-	Biobuf *bfd;
-	Biobufhdr *Bfd;
-	int warn = 0, errorflg = 0, line =1, rv;
-	int start, end, offset;
+	int errorflg = 0, line = 1, rv, start, end, offset;
 	int startfont, endfont, startchar, endchar, i, pfid;
 	char psfontnam[128];
 	struct troffont *tp;
-	struct charent *cp[];
+	Biobuf *bfd;
+	Biobufhdr *Bfd;
+	static char *filename = 0;
 
-	if (debug) Bprint(Bstderr, "readpsfontdesc(%s,%d)\n", fontname, trindex);
-	filename=galloc(filename, strlen(postroffdirname)+1+strlen(fontname)+1, "readpsfontdesc: cannot allocate memory\n");
+	if (debug)
+		fprint(2, "readpsfontdesc(%s,%d)\n", fontname, trindex);
+	filename = galloc(filename, strlen(postroffdirname)+1+strlen(fontname)+1,
+		"readpsfontdesc: cannot allocate memory\n");
 	sprint(filename, "%s/%s", postroffdirname, fontname);
 
 	bfd = Bopen(filename, OREAD);
@@ -144,7 +144,7 @@ readpsfontdesc(char *fontname, int trindex) {
 		error(WARNING, "cannot open file %s\n", filename);
 		return(0);
 	}
-	Bfd = &(bfd->Biobufhdr);
+	Bfd = &bfd->Biobufhdr;
 
 	do {
 		offset = 0;
@@ -156,14 +156,15 @@ readpsfontdesc(char *fontname, int trindex) {
 			errorflg = 1;
 			error(WARNING, "file %s:%d illegal end value\n", filename, line);
 		} else if (rv < 0) break;
-		if ((rv=Bgetfield(Bfd, 'd', &offset, 0)) < 0) {
+		if (Bgetfield(Bfd, 'd', &offset, 0) < 0) {
 			errorflg = 1;
 			error(WARNING, "file %s:%d illegal offset value\n", filename, line);
 		}
 		if ((rv=Bgetfield(Bfd, 's', psfontnam, 128)) == 0) {
 			errorflg = 1;
 			error(WARNING, "file %s:%d illegal fontname value\n", filename, line);
-		} else if (rv < 0) break;
+		} else if (rv < 0)
+			break;
 		Brdline(Bfd, '\n');
 		if (!errorflg) {
 			struct psfent *psfentp;
@@ -174,22 +175,25 @@ readpsfontdesc(char *fontname, int trindex) {
 			pfid = findpfn(psfontnam, 1);
 			if (startfont != endfont) {
 				error(WARNING, "font descriptions must not cross 256 glyph block boundary\n");
-				errorflg = 1;
 				break;
 			}
-			tp = &(troffontab[trindex]);
-			tp->psfmap = galloc(tp->psfmap, ++(tp->psfmapsize)*sizeof(struct psfent), "readpsfontdesc():psfmap");
+			tp = &troffontab[trindex];
+			tp->psfmap = galloc(tp->psfmap, ++tp->psfmapsize *
+				sizeof(struct psfent),
+				"readpsfontdesc():psfmap");
 			psfentp = &(tp->psfmap[tp->psfmapsize-1]);
 			psfentp->start = start;
 			psfentp->end = end;
 			psfentp->offset = offset;
 			psfentp->psftid = pfid;
 			if (debug) {
-				Bprint(Bstderr, "\tpsfmap->start=0x%x\n", start);
-				Bprint(Bstderr, "\tpsfmap->end=0x%x\n", end);
-				Bprint(Bstderr, "\tpsfmap->offset=0x%x\n", offset);
-				Bprint(Bstderr, "\tpsfmap->pfid=0x%x\n", pfid);
+				fprint(2, "\tpsfmap->start=0x%x\n", start);
+				fprint(2, "\tpsfmap->end=0x%x\n", end);
+				fprint(2, "\tpsfmap->offset=0x%x\n", offset);
+				fprint(2, "\tpsfmap->pfid=0x%x\n", pfid);
 			}
+			SET(i);
+			USED(i, startchar, endchar);
 /*
 			for (i=startchar; i<=endchar; i++) {
 				tp->charent[startfont][i].postfontid = pfid;
@@ -197,9 +201,10 @@ readpsfontdesc(char *fontname, int trindex) {
 			}
  */
 			if (debug) {
-				Bprint(Bstderr, "%x %x ", start, end);
-				if (offset) Bprint(Bstderr, "%x ", offset);
-				Bprint(Bstderr, "%s\n", psfontnam);
+				fprint(2, "%x %x ", start, end);
+				if (offset)
+					fprint(2, "%x ", offset);
+				fprint(2, "%s\n", psfontnam);
 			}
 			line++;
 		}
@@ -210,20 +215,21 @@ readpsfontdesc(char *fontname, int trindex) {
 
 int
 readtroffmetric(char *fontname, int trindex) {
-	static char *filename = 0;
+	int ntoken, errorflg = 0, line = 1, rv;
+	int width, flag, charnum, thisfont, thischar;
+	char stoken[128], *str;
+	struct charent **cp;
+	BOOLEAN specharflag;
 	Biobuf *bfd;
 	Biobufhdr *Bfd;
-	int warn = 0, errorflg = 0, line =1, rv;
-	struct troffont *tp;
-	struct charent **cp;
-	char stoken[128], *str;
-	int ntoken;
 	Rune troffchar, quote;
-	int width, flag, charnum, thisfont, thischar;
-	BOOLEAN specharflag;
+	static char *filename = 0;
 
-	if (debug) Bprint(Bstderr, "readtroffmetric(%s,%d)\n", fontname, trindex);
-	filename=galloc(filename, strlen(troffmetricdirname)+4+strlen(devname)+1+strlen(fontname)+1, "readtroffmetric():filename");
+	if (debug)
+		fprint(2, "readtroffmetric(%s,%d)\n", fontname, trindex);
+	filename = galloc(filename, strlen(troffmetricdirname) + 4 +
+		strlen(devname) + 1 + strlen(fontname) + 1,
+		"readtroffmetric():filename");
 	sprint(filename, "%s/dev%s/%s", troffmetricdirname, devname, fontname);
 
 	bfd = Bopen(filename, OREAD);
@@ -231,18 +237,19 @@ readtroffmetric(char *fontname, int trindex) {
 		error(WARNING, "cannot open file %s\n", filename);
 		return(0);
 	}
-	Bfd = &(bfd->Biobufhdr);
+	Bfd = &bfd->Biobufhdr;
 	do {
-		/* deal with the few lines at the beginning of the
+		/*
+		 * deal with the few lines at the beginning of the
 		 * troff font metric files.
 		 */
 		if ((rv=Bgetfield(Bfd, 's', stoken, 128)) == 0) {
 			errorflg = 1;
 			error(WARNING, "file %s:%d illegal token\n", filename, line);
-		} else if (rv < 0) break;
-		if (debug) {
-			Bprint(Bstderr, "%s\n", stoken);
-		}
+		} else if (rv < 0)
+			break;
+		if (debug)
+			fprint(2, "%s\n", stoken);
 
 		if (strcmp(stoken, "name") == 0) {
 			if ((rv=Bgetfield(Bfd, 's', stoken, 128)) == 0) {
@@ -271,7 +278,7 @@ readtroffmetric(char *fontname, int trindex) {
 
 			if (*cp == 0) *cp = galloc(0, sizeof(struct charent), "readtroffmetric:charent");
 			(*cp)->postfontid = thisfont;
-			(*cp)->postcharid = thischar; 
+			(*cp)->postcharid = thischar;
 			(*cp)->troffcharwidth = ntoken;
 			(*cp)->name = galloc(0, 2, "readtroffmetric: char name");
 			(*cp)->next = 0;
@@ -282,7 +289,7 @@ readtroffmetric(char *fontname, int trindex) {
 			line++;
 			break;
 		}
-		if (!errorflg) {		
+		if (!errorflg) {
 			line++;
 		}
 	} while(!errorflg && rv>=0);
@@ -296,15 +303,14 @@ readtroffmetric(char *fontname, int trindex) {
 		/* if this character is a quote we have to use the previous characters info */
 		if ((rv=Bgetfield(Bfd, 'r', &quote, 0)) == 0) {
 			errorflg = 1;
-			error(WARNING, "file %s:%d illegal width or quote token <0x%x> rv=%d\n", filename, line, quote, rv);
+			error(WARNING, "file %s:%d illegal width or quote token <0x%x> rv=%d\n",
+				filename, line, quote, rv);
 		} else if (rv < 0) break;
 		if (quote == '"') {
 			/* need some code here */
-
 			goto flush;
-		} else {
+		} else
 			Bungetrune(Bfd);
-		}
 
 		if ((rv=Bgetfield(Bfd, 'd', &width, 0)) == 0) {
 			errorflg = 1;
@@ -317,23 +323,24 @@ readtroffmetric(char *fontname, int trindex) {
 		if ((rv=Bgetfield(Bfd, 'd', &charnum, 0)) == 0) {
 			errorflg = 1;
 			error(WARNING, "file %s:%d illegal character number token <0x%x> rv=%d\n", filename, line, troffchar, rv);
-		} else if (rv < 0) break;
+		} else if (rv < 0)
+			break;
 flush:
 		str = Brdline(Bfd, '\n');
 		/* stash the crap from the end of the line for debugging */
 		if (debug) {
 			if (str == 0) {
-				Bprint(Bstderr, "premature EOF\n");
+				fprint(2, "premature EOF\n");
 				return(0);
 			}
 			str[Blinelen(Bfd)-1] = '\0';
 		}
 		line++;
 		chartorune(&troffchar, stoken);
-		if (specharflag) {
+		if (specharflag)
 			if (debug)
-				Bprint(Bstderr, "%s %d  %d 0x%x %s # special\n",stoken, width, flag, charnum, str);
-		}
+				fprint(2, "%s %d  %d 0x%x %s # special\n",
+					stoken, width, flag, charnum, str);
 		if (strcmp(stoken, "---") == 0) {
 			thisfont = RUNEGETGROUP(charnum);
 			thischar = RUNEGETCHAR(charnum);
@@ -342,25 +349,30 @@ flush:
 			thisfont = RUNEGETGROUP(troffchar);
 			thischar = RUNEGETCHAR(troffchar);
 		}
-		for (cp = &(troffontab[trindex].charent[thisfont][thischar]); *cp != 0; cp = &((*cp)->next))
+		for (cp = &troffontab[trindex].charent[thisfont][thischar];
+		    *cp != 0; cp = &(*cp)->next)
 			if ((*cp)->name) {
-				if (debug) Bprint(Bstderr, "installing <%s>, found <%s>\n", stoken, (*cp)->name);
+				if (debug)
+					fprint(2, "installing <%s>, found <%s>\n",
+						stoken, (*cp)->name);
 				if  (strcmp((*cp)->name, stoken) == 0)
 					break;
 			}
-		if (*cp == 0) *cp = galloc(0, sizeof(struct charent), "readtroffmetric:charent");
+		if (*cp == 0)
+			*cp = galloc(0, sizeof(struct charent),
+				"readtroffmetric:charent");
 		(*cp)->postfontid = RUNEGETGROUP(charnum);
-		(*cp)->postcharid = RUNEGETCHAR(charnum); 
+		(*cp)->postcharid = RUNEGETCHAR(charnum);
 		(*cp)->troffcharwidth = width;
 		(*cp)->name = galloc(0, strlen(stoken)+1, "readtroffmetric: char name");
 		(*cp)->next = 0;
 		strcpy((*cp)->name, stoken);
 		if (debug) {
 			if (specharflag)
-				Bprint(Bstderr, "%s", stoken);
+				fprint(2, "%s", stoken);
 			else
-				Bputrune(Bstderr, troffchar);
-			Bprint(Bstderr, " %d  %d 0x%x %s # psfontid=0x%x pscharid=0x%x thisfont=0x%x thischar=0x%x\n",
+				fprint(2, "%C", troffchar);
+			fprint(2, " %d  %d 0x%x %s # psfontid=0x%x pscharid=0x%x thisfont=0x%x thischar=0x%x\n",
 				width, flag, charnum, str,
 				(*cp)->postfontid,
 				(*cp)->postcharid,
@@ -384,10 +396,8 @@ findtfn(char *fontname, BOOLEAN insflg) {
 	struct troffont *tp;
 	int i, j;
 
-	if (debug) {
-		if (fontname==0) fprint(2, "findtfn(0x%x,%d)\n", fontname, insflg);
-		else fprint(2, "findtfn(%s,%d)\n", fontname, insflg);
-	}
+	if (debug)
+		fprint(2, "findtfn(%s,%d)\n", fontname, insflg);
 	for (i=0; i<troffontcnt; i++) {
 		if (troffontab[i].trfontid==0) {
 			error(WARNING, "findtfn:troffontab[%d].trfontid=0x%x, botch!\n",
@@ -398,7 +408,9 @@ findtfn(char *fontname, BOOLEAN insflg) {
 			return(i);
 	}
 	if (insflg) {
-		tp = (struct troffont *)galloc(troffontab, sizeof(struct troffont)*(troffontcnt+1), "findtfn: struct troffont:");
+		tp = (struct troffont *)galloc(troffontab,
+			sizeof(struct troffont)*(troffontcnt+1),
+			"findtfn: struct troffont:");
 		if (tp == 0)
 			return(-2);
 		troffontab = tp;

+ 7 - 6
sys/src/cmd/postscript/tr2post/conv.c

@@ -6,16 +6,15 @@
 
 void
 conv(Biobufhdr *Bp) {
-	long c, n;
+	long n;
 	int r;
 	char special[10];
 	int save;
 
 	inputlineno = 1;
-	if (debug) Bprint(Bstderr, "conv(Biobufhdr *Bp=0x%x)\n", Bp);
+	if (debug)
+		fprint(2, "conv(Biobufhdr *Bp=%#p)\n", Bp);
 	while ((r = Bgetrune(Bp)) >= 0) {
-/* Bprint(Bstderr, "r=<%c>,0x%x\n", r, r); */
-/*		Bflush(Bstderr); */
 		switch (r) {
 		case 's':	/* set point size */
 			Bgetfield(Bp, 'd', &fontsize, 0);
@@ -95,6 +94,8 @@ conv(Biobufhdr *Bp) {
 		}
 	}
 	endpage();
-	if (debug) Bprint(Bstderr, "r=0x%x\n", r);
-	if (debug) Bprint(Bstderr, "leaving conv\n");
+	if (debug) {
+		fprint(2, "r=%#ux\n", r);
+		fprint(2, "leaving conv\n");
+	}
 }

+ 10 - 10
sys/src/cmd/postscript/tr2post/devcntl.c

@@ -48,13 +48,12 @@ struct sjt specialjumptable[] = {
 	{"ExportPS", notavail("ExportPS")},
 	{NULL, NULL}
 };
-*/
+ */
 
 void
 devcntl(Biobufhdr *inp) {
-
 	char cmd[50], buf[256], str[MAXTOKENSIZE], *line;
-	int c, n, linelen;
+	int c, n;
 
 /*
  *
@@ -102,16 +101,18 @@ devcntl(Biobufhdr *inp) {
 		break;
 
 	case 'T':			/* device name */
-		Bgetfield(inp, 's', &devname, 16);
+		Bgetfield(inp, 's', devname, 16);
 		if (debug) Bprint(Bstderr, "devname=%s\n", devname);
 		break;
 
 	case 'E':			/* input encoding - not in troff yet */
-		Bgetfield(inp, 's', &str, 100);
-/*		if ( strcmp(str, "UTF") == 0 )
-		    reading = UTFENCODING;
-		else reading = ONEBYTE;
-  */
+		Bgetfield(inp, 's', str, 100);
+/*
+		if (strcmp(str, "UTF") == 0)
+			reading = UTFENCODING;
+		else
+			reading = ONEBYTE;
+ */
 		break;
 
 	case 'X':			/* copy through - from troff */
@@ -175,4 +176,3 @@ devcntl(Biobufhdr *inp) {
 	while ((c = Bgetc(inp)) != '\n' && c != Beof);
 	inputlineno++;
 }
-

+ 6 - 21
sys/src/cmd/postscript/tr2post/draw.c

@@ -6,10 +6,11 @@
 #include "tr2post.h"
 
 BOOLEAN drawflag = FALSE;
-BOOLEAN	inpath = FALSE;			/* TRUE if we're putting pieces together */
+BOOLEAN	inpath = FALSE;		/* TRUE if we're putting pieces together */
 
 void
 cover(double x, double y) {
+	USED(x, y);
 }
 
 void
@@ -17,30 +18,24 @@ drawspline(Biobufhdr *Bp, int flag) {	/* flag!=1 connect end points */
 	int x[100], y[100];
 	int i, N;
 /*
- *
  * Spline drawing routine for Postscript printers. The complicated stuff is
  * handled by procedure Ds, which should be defined in the library file. I've
  * seen wrong implementations of troff's spline drawing, so fo the record I'll
  * write down the parametric equations and the necessary conversions to Bezier
  * cubic splines (as used in Postscript).
  *
- *
  * Parametric equation (x coordinate only):
  *
- *
  *	    (x2 - 2 * x1 + x0)    2                    (x0 + x1)
  *	x = ------------------ * t   + (x1 - x0) * t + ---------
  *		    2					   2
  *
- *
  * The coefficients in the Bezier cubic are,
  *
- *
  *	A = 0
  *	B = (x2 - 2 * x1 + x0) / 2
  *	C = x1 - x0
  *
- *
  * while the current point is,
  *
  *	current-point = (x0 + x1) / 2
@@ -48,12 +43,10 @@ drawspline(Biobufhdr *Bp, int flag) {	/* flag!=1 connect end points */
  * Using the relationships given in the Postscript manual (page 121) it's easy to
  * see that the control points are given by,
  *
- *
  *	x0' = (x0 + 5 * x1) / 6
  *	x1' = (x2 + 5 * x1) / 6
  *	x2' = (x1 + x2) / 2
  *
- *
  * where the primed variables are the ones used by curveto. The calculations
  * shown above are done in procedure Ds using the coordinates set up in both
  * the x[] and y[] arrays.
@@ -61,9 +54,7 @@ drawspline(Biobufhdr *Bp, int flag) {	/* flag!=1 connect end points */
  * A simple test of whether your spline drawing is correct would be to use cip
  * to draw a spline and some tangent lines at appropriate points and then print
  * the file.
- *
  */
-
 	for (N=2; N<sizeof(x)/sizeof(x[0]); N++)
 		if (Bgetfield(Bp, 'd', &x[N], 0)<=0 || Bgetfield(Bp, 'd', &y[N], 0)<=0)
 			break;
@@ -229,17 +220,14 @@ drawpath(char *buf, int copy) {
 }
 
 
-/*****************************************************************************/
-
 static void
 parsebuf(char *buf)
 {
-	char	*p;			/* usually the next token */
+	char *p;			/* usually the next token */
 	char *q;
-	int		gsavelevel = 0;		/* non-zero if we've done a gsave */
+	int gsavelevel = 0;		/* non-zero if we've done a gsave */
 
 /*
- *
  * Simple minded attempt at parsing the string that followed an "x X DrawPath"
  * command. Everything not recognized here is simply ignored - there's absolutely
  * no error checking and what was originally in buf is clobbered by strtok().
@@ -274,13 +262,10 @@ parsebuf(char *buf)
  * quotes. Straight PostScript is only bracketed by the outermost gsave/grestore
  * pair (ie. the one from the initial "x X BeginPath") although that's probably
  * a mistake. Suspect I may have to change the double quote delimiters.
- *
  */
-
-	for( ; p != nil ; p = q ) {
-		if( q = strchr(p, ' ') ) {
+	for(p = buf; p != nil; p = q) {
+		if( q = strchr(p, ' ') )
 			*q++ = '\0';
-		}
 
 		if ( gsavelevel == 0 ) {
 			Bprint(Bstdout, "gsave\n");

+ 2 - 1
sys/src/cmd/postscript/tr2post/mkfile

@@ -29,7 +29,8 @@ BIN=$POSTBIN
 
 </sys/src/cmd/mkone
 
-CFLAGS=-c -D'PROGRAMVERSION="0.1"' -D'DOROUND=1' -I$COMMONDIR -D'PROGRAMNAME="troff, Plan 9 edition"'
+CFLAGS=$CFLAGS -D'PROGRAMVERSION="0.1"' -D'DOROUND=1' -I$COMMONDIR \
+ -D'PROGRAMNAME="troff, Plan 9 edition"'
 
 %.$O:	$COMMONDIR/%.c
 	$CC $CFLAGS $COMMONDIR/$stem.c

+ 20 - 47
sys/src/cmd/postscript/tr2post/pictures.c

@@ -1,5 +1,4 @@
 /*
- *
  * PostScript picture inclusion routines. Support for managing in-line pictures
  * has been added, and works in combination with the simple picpack pre-processor
  * that's supplied with this package. An in-line picture begins with a special
@@ -30,7 +29,6 @@
  * pictures included, doesn't fit the device independent language accepted by
  * important post-processors (like proff) and that means you won't be able to
  * reliably preview a packed file on your 5620 (or whatever).
- *
  */
 
 #include <u.h>
@@ -40,14 +38,10 @@
 #include "ext.h"
 #include "common.h"
 #include "tr2post.h"
-/* PostScript file structuring comments */
-#include "comments.h"
-/* general purpose definitions */
-/* #include "gen.h" */
-/* just for TEMPDIR definition */
-#include "path.h"
-/* external variable declarations */
-/* #include "ext.h" */
+#include "comments.h"		/* PostScript file structuring comments */
+/* #include "gen.h" */		/* general purpose definitions */
+#include "path.h"		/* just for TEMPDIR definition */
+/* #include "ext.h" */		/* external variable declarations */
 
 Biobuf	*bfp_pic = NULL;
 Biobufhdr	*Bfp_pic;
@@ -60,31 +54,28 @@ int nfields;
 extern int	devres, hpos, vpos;
 extern int	picflag;
 
-/*****************************************************************************/
-
 void
 picture(Biobufhdr *inp, char *buf) {
-	int	poffset;		/* page offset */
-	int	indent;		/* indent */
-	int	length;		/* line length  */
+	int	i;
+	int	indent;
+	int	length;		/* line length */
+	int	outline = 0;	/* draw a box around the picture? */
+	int	page = 1;	/* page number pulled from name[] */
+	int	poffset;	/* page offset */
+	int	scaleboth = 0;	/* scale both dimensions? */
 	int	totrap;		/* distance to next trap */
-	char	name[100];	/* picture file and page string */
+	int	whiteout = 0;	/* white out the box? */
+	char	flags[20];	/* miscellaneous stuff */
 	char	hwo[40], *p;	/* height, width and offset strings */
-	char	flags[20];		/* miscellaneous stuff */
-	int	page = 1;		/* page number pulled from name[] */
-	double	frame[4];	/* height, width, y, and x offsets from hwo[] */
+	char	name[100];	/* picture file and page string */
 	char	units;		/* scale indicator for frame dimensions */
-	int	whiteout = 0;	/* white out the box? */
-	int	outline = 0;	/* draw a box around the picture? */
-	int	scaleboth = 0;	/* scale both dimensions? */
 	double	adjx = 0.5;	/* left-right adjustment */
 	double	adjy = 0.5;	/* top-bottom adjustment */
+	double	frame[4];	/* height, width, y, and x offsets from hwo[] */
 	double	rot = 0;	/* rotation in clockwise degrees */
-	Biobufhdr	*fp_in;	/* for *name */
-	int	i;			/* loop index */
+	Biobufhdr *fp_in;	/* for *name */
 
 /*
- *
  * Called from devcntrl() after an 'x X PI' command is found. The syntax of that
  * command is:
  *
@@ -107,9 +98,8 @@ picture(Biobufhdr *inp, char *buf) {
  * clockwise degrees, is set by the a flag. If it's not followed by an angle
  * the current rotation angle is incremented by 90 degrees, otherwise the angle
  * is set by the number that immediately follows the a.
- *
  */
-
+	USED(inp);
 	if (!picflag)		/* skip it */
 		return;
 	endstring();
@@ -182,18 +172,15 @@ picture(Biobufhdr *inp, char *buf) {
 	Bprint(Bstdout, "/saveobj save def\n");
 	Bprint(Bstdout, "mark\n");
 	Bterm(fp_in);
-
 }
 
 /*
- *
  * Responsible for finding and opening the next picture file. If we've accumulated
  * any in-line pictures fp_pic won't be NULL and we'll look there first. If *path
  * is found in *fp_pic we create another temp file, open it for update, unlink it,
  * copy in the picture, seek back to the start of the new temp file, and return
  * the file pointer to the caller. If fp_pic is NULL or the lookup fails we just
  * open file *path and return the resulting file pointer to the caller.
- *
  */
 Biobufhdr *
 picopen(char *path) {
@@ -201,13 +188,11 @@ picopen(char *path) {
 /*	long	pos;			/* current position */
 /*	long	total;			/* and sizes - from *fp_pic */
 	Biobuf *bfp;
-	Biobufhdr	*Bfp;		/* and pointer for the new temp file */
-
 
 	if ((bfp = Bopen(path, OREAD)) == 0)
 		error(FATAL, "can't open %s\n", path);
-	Bfp = &(bfp->Biobufhdr);
-	return(Bfp);
+	return bfp;
+
 #ifdef UNDEF
 	if (Bfp_pic != NULL) {
 		Bseek(Bfp_pic, 0L, 0);
@@ -227,22 +212,16 @@ picopen(char *path) {
 			Bseek(Bfp_pic, total+pos, 0);
 		}
 	}
-	if ((bfp = Bopen(path, OREAD)) == 0)
-		Bfp = 0;
-	else
-		Bfp = &(bfp->Biobufhdr);
-	return(Bfp);
+	return Bopen(path, OREAD);
 #endif
 }
 
 /*
- *
  * Adds an in-line picture file to the end of temporary file *Bfp_pic. All pictures
  * grabbed from the input file are saved in the same temp file. Each is preceeded
  * by a one line header that includes the original picture file pathname and the
  * size of the picture in bytes. The in-line picture file is opened for update,
  * left open, and unlinked so it disappears when we do.
- *
  */
 /*	*fp;			/* current input file */
 /*	*buf;			/* whatever followed "x X InlinePicture" */
@@ -253,33 +232,27 @@ inlinepic(Biobufhdr *Bfp, char *buf) {
 	char	name[100];		/* picture file pathname */
 	long	total;			/* and size - both from *buf */
 
-
 	if (Bfp_pic == NULL ) {
 		tmpnam(pictmpname);
 		if ((bfp_pic = Bopen(pictmpname, ORDWR)) == 0)
 	    		error(FATAL, "can't open in-line picture file %s", ipictmpname);
 		unlink(pictmpname);
 	}
-
 	if ( sscanf(buf, "%s %ld", name, &total) != 2 )
 		error(FATAL, "in-line picture error");
-
 	fseek(Bfp_pic, 0L, 2);
 	fprintf(Bfp_pic, "%s %ld\n", name, total);
 	getc(fp);
 	fflush(fp_pic);
 	piccopy(fp, fp_pic, total);
 	ungetc('\n', fp);
-
 }
 #endif
 
 /*
- *
  * Copies total bytes from file fp_in to fp_out. Used to append picture files to
  * *fp_pic and then copy them to yet another temporary file immediately before
  * they're used (in picture()).
- *
  */
 /*	*fp_in;	input */
 /*	*fp_out;	and output file pointers */

+ 14 - 17
sys/src/cmd/postscript/tr2post/ps_include.c

@@ -13,7 +13,6 @@ static char *buf;
 
 static void
 copy(Biobufhdr *fin, Biobufhdr *fout, Section *s) {
-	int cond;
 	if (s->end <= s->start)
 		return;
 	Bseek(fin, s->start, 0);
@@ -34,7 +33,6 @@ copy(Biobufhdr *fin, Biobufhdr *fout, Section *s) {
 }
 
 /*
- *
  * Reads a PostScript file (*fin), and uses structuring comments to locate the
  * prologue, trailer, global definitions, and the requested page. After the whole
  * file is scanned, the  special ps_include PostScript definitions are copied to
@@ -44,7 +42,6 @@ copy(Biobufhdr *fin, Biobufhdr *fout, Section *s) {
  *
  * By default we assume the picture is 8.5 by 11 inches, but the BoundingBox
  * comment, if found, takes precedence.
- *
  */
 /*	*fin, *fout;		/* input and output files */
 /*	page_no;		/* physical page number from *fin */
@@ -60,25 +57,25 @@ void
 ps_include(Biobufhdr *fin, Biobufhdr *fout, int page_no, int whiteout,
 	int outline, int scaleboth, double cx, double cy, double sx, double sy,
 	double ax, double ay, double rot) {
-	char		**strp;
-	int		foundpage = 0;		/* found the page when non zero */
-	int		foundpbox = 0;		/* found the page bounding box */
-	int		nglobal = 0;		/* number of global defs so far */
-	int		maxglobal = 0;		/* and the number we've got room for */
-	Section	prolog, page, trailer;	/* prologue, page, and trailer offsets */
-	Section	*global;		/* offsets for all global definitions */
-	double	llx, lly;		/* lower left and */
-	double	urx, ury;		/* upper right corners - default coords */
-	double	w = whiteout != 0;	/* mostly for the var() macro */
-	double	o = outline != 0;
-	double	s = scaleboth != 0;
-	int		i;		/* loop index */
+	int foundpage = 0;		/* found the page when non zero */
+	int foundpbox = 0;		/* found the page bounding box */
+	int i;
+	int maxglobal = 0;		/* the number we've got room for */
+	int nglobal = 0;		/* number of global defs so far */
+	char **strp;
+	double llx, lly;		/* lower left and */
+	double o = outline != 0;
+	double s = scaleboth != 0;
+	double urx, ury;		/* upper right corners - default coords */
+	double w = whiteout != 0;	/* mostly for the var() macro */
+	Section *global;		/* offsets for all global definitions */
+	Section prolog, page, trailer;	/* prologue, page, and trailer offsets */
 
 #define has(word)	(strncmp(buf, word, strlen(word)) == 0)
 #define grab(n)		((Section *)(nglobal \
 			? realloc((char *)global, n*sizeof(Section)) \
 			: calloc(n, sizeof(Section))))
-
+	global = nil;
 	llx = lly = 0;		/* default BoundingBox - 8.5x11 inches */
 	urx = 72 * 8.5;
 	ury = 72 * 11.0;

+ 67 - 83
sys/src/cmd/postscript/tr2post/tr2post.c

@@ -26,7 +26,6 @@ int debug = 0;
 char tmpfilename[MAXTOKENSIZE];
 char copybuf[BUFSIZ];
 
-
 struct charent **build_char_list = 0;
 int build_char_cnt = 0;
 
@@ -43,13 +42,13 @@ prologues(void) {
 	Bprint(Bstdout, "%s", ENDCOMMENTS);
 
 	if (cat(DPOST)) {
-		Bprint(Bstderr, "can't read %s\n", DPOST);
+		fprint(2, "can't read %s\n", DPOST);
 		exits("dpost prologue");
 	}
 
 	if (drawflag) {
 		if (cat(DRAW)) {
-			Bprint(Bstderr, "can't read %s\n", DRAW);
+			fprint(2, "can't read %s\n", DRAW);
 			exits("draw prologue");
 		}
 	}
@@ -84,7 +83,7 @@ prologues(void) {
 	for (i=0; i<build_char_cnt; i++) {
 		sprint(charlibname, "%s/%s", CHARLIB, build_char_list[i]->name);
 		if (cat(charlibname))
-		Bprint(Bstderr, "cannot open %s\n", charlibname);
+		fprint(2, "cannot open %s\n", charlibname);
 	}
 
 	Bprint(Bstdout, "%s", ENDSETUP);
@@ -103,118 +102,103 @@ main(int argc, char *argv[]) {
 	char *t;
 
 	programname = argv[0];
-	if (Binit(&bstderr, 2, OWRITE) == Beof) {
-		exits("Binit");
-	}
+	if (Binit(&bstderr, 2, OWRITE) == Beof)
+		sysfatal("Binit");
 	Bstderr = &bstderr.Biobufhdr;
 
 	tmpnam(tmpfilename);
-	if ((bstdout=Bopen(tmpfilename, OWRITE)) == 0) {
-		Bprint(Bstderr, "cannot open temporary file %s\n", tmpfilename);
-		exits("Bopen");
-	}
+	if ((bstdout=Bopen(tmpfilename, OWRITE)) == 0)
+		sysfatal("cannot open temporary file %s: %r", tmpfilename);
 	atexit(cleanup);
 	Bstdout = &bstdout->Biobufhdr;
-	
+
 	ARGBEGIN{
-		case 'a':			/* aspect ratio */
-			aspectratio = atof(ARGF());
-			break;
-		case 'c':			/* copies */
-			copies = atoi(ARGF());
-			break;
-		case 'd':
-			debug = 1;
-			break;
-		case 'm':			/* magnification */
-			magnification = atof(ARGF());
-			break;
-		case 'n':			/* forms per page */
-			formsperpage = atoi(ARGF());
-			break;
-		case 'o':			/* output page list */
-			pagelist(ARGF());
-			break;
-		case 'p':			/* landscape or portrait mode */
-			if ( ARGF()[0] == 'l' )
-				landscape = 1;
-			else
-				landscape = 0;
-			break;
-		case 'x':			/* shift things horizontally */
-			xoffset = atof(ARGF());
-			break;
-		case 'y':			/* and vertically on the page */
-			yoffset = atof(ARGF());
-			break;
-		case 'P':			/* PostScript pass through */
-			t = ARGF();
-			i = strlen(t) + 1;
-			passthrough = malloc(i);
-			if (passthrough == 0) {
-				Bprint(Bstderr, "cannot allocate memory for argument string\n");
-				exits("malloc");
-			}
-			strncpy(passthrough, t, i);
-			break;
-		default:			/* don't know what to do for ch */
-			Bprint(Bstderr, "unknown option %C\n", ARGC());
-			break;
+	case 'a':			/* aspect ratio */
+		aspectratio = atof(ARGF());
+		break;
+	case 'c':			/* copies */
+		copies = atoi(ARGF());
+		break;
+	case 'd':
+		debug = 1;
+		break;
+	case 'm':			/* magnification */
+		magnification = atof(ARGF());
+		break;
+	case 'n':			/* forms per page */
+		formsperpage = atoi(ARGF());
+		break;
+	case 'o':			/* output page list */
+		pagelist(ARGF());
+		break;
+	case 'p':			/* landscape or portrait mode */
+		if ( ARGF()[0] == 'l' )
+			landscape = 1;
+		else
+			landscape = 0;
+		break;
+	case 'x':			/* shift things horizontally */
+		xoffset = atof(ARGF());
+		break;
+	case 'y':			/* and vertically on the page */
+		yoffset = atof(ARGF());
+		break;
+	case 'P':			/* PostScript pass through */
+		t = ARGF();
+		i = strlen(t) + 1;
+		passthrough = malloc(i);
+		if (passthrough == 0)
+			sysfatal("malloc");
+		strncpy(passthrough, t, i);
+		break;
+	default:			/* don't know what to do for ch */
+		fprint(2, "unknown option %C\n", ARGC());
+		break;
 	}ARGEND;
+
 	readDESC();
 	if (argc == 0) {
-		if ((binp = (Biobuf *)malloc(sizeof(Biobuf))) == nil) {
-			Bprint(Bstderr, "malloc failed.\n");
-			exits("malloc");
-		}
-		if (Binit(binp, 0, OREAD) == Beof) {
-			Bprint(Bstderr, "Binit of <stdin> failed.\n");
-			exits("Binit");
-		}
-		Binp = &(binp->Biobufhdr);
-		if (debug) Bprint(Bstderr, "using standard input\n");
+		if ((binp = (Biobuf *)malloc(sizeof(Biobuf))) == nil)
+			sysfatal("malloc");
+		if (Binit(binp, 0, OREAD) == Beof)
+			sysfatal("Binit of <stdin> failed.");
+		Binp = &binp->Biobufhdr;
+		if (debug) fprint(2, "using standard input\n");
 		conv(Binp);
 		Bterm(Binp);
 	}
 	for (i=0; i<argc; i++) {
 		if ((binp=Bopen(argv[i], OREAD)) == 0) {
-			Bprint(Bstderr, "cannot open file %s\n", argv[i]);
+			fprint(2, "cannot open file %s\n", argv[i]);
 			continue;
 		}
-		Binp = &(binp->Biobufhdr);
+		Binp = &binp->Biobufhdr;
 		inputfilename = argv[i];
 		conv(Binp);
 		Bterm(Binp);
 	}
 	Bterm(Bstdout);
 
-	if ((ifd=open(tmpfilename, OREAD)) < 0) {
-		Bprint(Bstderr, "open of %s failed.\n", tmpfilename);
-		exits("open");
-	}
+	if ((ifd=open(tmpfilename, OREAD)) < 0)
+		sysfatal("open of %s failed: %r", tmpfilename);
 
 	bstdout = galloc(0, sizeof(Biobuf), "bstdout");
-	if (Binit(bstdout, 1, OWRITE) == Beof) {
-		Bprint(Bstderr, "Binit of <stdout> failed.\n");
-		exits("Binit");
-	}
+	if (Binit(bstdout, 1, OWRITE) == Beof)
+		sysfatal("Binit of <stdout> failed.");
 	Bstdout = &(bstdout->Biobufhdr);
 	prologues();
 	Bflush(Bstdout);
-	tot = 0; i = 0;
+	tot = 0;
 	while ((i=read(ifd, copybuf, BUFSIZ)) > 0) {
 		if (write(1, copybuf, i) != i) {
-			Bprint(Bstderr, "write error on copying from temp file.\n");
+			fprint(2, "write error on copying from temp file.\n");
 			exits("write");
 		}
 		tot += i;
 	}
-	if (debug) Bprint(Bstderr, "copied %d bytes to final output i=%d\n", tot, i);
-	if (i < 0) {
-		Bprint(Bstderr, "read error on copying from temp file.\n");
-		exits("read");
-	}
+	if (debug) fprint(2, "copied %d bytes to final output i=%d\n", tot, i);
+	if (i < 0)
+		sysfatal("read error copying from temp file: %r");
 	finish();
-		
 	exits("");
 }

+ 67 - 45
sys/src/cmd/postscript/tr2post/utils.c

@@ -40,18 +40,22 @@ hmot(int x) {
 	if ((x<expecthmot-1) || (x>expecthmot+1)) {
 		delta = x - expecthmot;
 		if (curtrofffontid <0 || curtrofffontid >= troffontcnt) {
-			Bprint(Bstderr, "troffontcnt=%d curtrofffontid=%d\n", troffontcnt, curtrofffontid);
-			Bflush(Bstderr);
+			fprint(2, "troffontcnt=%d curtrofffontid=%d\n",
+				troffontcnt, curtrofffontid);
 			exits("");
 		}
-		if (delta == troffontab[curtrofffontid].spacewidth*fontsize/10 && isinstring()) {
-			if (pageon()) runeout(' ');
+		if (delta == troffontab[curtrofffontid].spacewidth*fontsize/10 &&
+		    isinstring()) {
+			if (pageon())
+				runeout(' ');
 		} else {
-			if (pageon()) {	
+			if (pageon()) {
 				endstring();
 				/* Bprint(Bstdout, " %d 0 rmoveto ", delta); */
 /*				Bprint(Bstdout, " %d %d m ", hpos+x, vpos); */
-				if (debug) Bprint(Bstderr, "x=%d expecthmot=%d\n", x, expecthmot);
+				if (debug)
+					fprint(2, "x=%d expecthmot=%d\n",
+						x, expecthmot);
 			}
 		}
 	}
@@ -72,7 +76,7 @@ findglyph(int trfid, Rune rune, char *stoken) {
 
 	for (cp = &(troffontab[trfid].charent[RUNEGETGROUP(rune)][RUNEGETCHAR(rune)]); *cp != 0; cp = &((*cp)->next)) {
 		if ((*cp)->name) {
-			if (debug) Bprint(Bstderr, "looking for <%s>, have <%s> in font %s\n", stoken, (*cp)->name, troffontab[trfid].trfontid);
+			if (debug) fprint(2, "looking for <%s>, have <%s> in font %s\n", stoken, (*cp)->name, troffontab[trfid].trfontid);
 			if (strcmp((*cp)->name, stoken) == 0)
 				break;
 		}
@@ -89,44 +93,56 @@ glyphout(Rune rune, char *stoken, BOOLEAN specialflag) {
 	struct charent **cp;
 	struct troffont *tfp;
 	struct psfent *psfp;
-	int i, t;
+	int i, t, mi, wid;
 	int fontid;	/* this is the troff font table index, not the mounted font table index */
-	int mi, fi, wid;
 	Rune r;
 
+	mi = 0;
 	settrfont();
 
 	/* check current font for the character, special or not */
 	fontid = curtrofffontid;
-if (debug) fprint(2, "	looking through current font: trying %s\n", troffontab[fontid].trfontid);
+	if (debug)
+		fprint(2, "\tlooking through current font: trying %s\n",
+			troffontab[fontid].trfontid);
 	cp = findglyph(fontid, rune, stoken);
-	if (*cp != 0) goto foundit;
+	if (*cp != 0)
+		goto foundit;
 
 	if (specialflag) {
-		if (expecthmot) hmot(0);
+		if (expecthmot)
+			hmot(0);
 
 		/* check special fonts for the special character */
 		/* cycle through the (troff) mounted fonts starting at the next font */
 		for (mi=0; mi<fontmnt; mi++) {
-			if (troffontab[fontid].trfontid==0) error(WARNING, "glyphout:troffontab[%d].trfontid=0x%x, botch!\n",
-				fontid, troffontab[fontid].trfontid);
+			if (troffontab[fontid].trfontid==0)
+				error(WARNING, "glyphout:troffontab[%d].trfontid=0x%x, botch!\n",
+					fontid, troffontab[fontid].trfontid);
 			if (fontmtab[mi]==0) {
-				if (debug) fprint(2, "fontmtab[%d]=0x%x, fontmnt=%d\n", mi, fontmtab[mi], fontmnt);
+				if (debug)
+					fprint(2, "fontmtab[%d]=%#p, fontmnt=%d\n",
+						mi, fontmtab[mi], fontmnt);
 				continue;
 			}
-			if (strcmp(troffontab[fontid].trfontid, fontmtab[mi])==0) break;
+			if (strcmp(troffontab[fontid].trfontid, fontmtab[mi])==0)
+				break;
 		}
-		if (mi==fontmnt) error(FATAL, "current troff font is not mounted, botch!\n");
+		if (mi==fontmnt)
+			error(FATAL, "current troff font is not mounted, botch!\n");
 		for (i=(mi+1)%fontmnt; i!=mi; i=(i+1)%fontmnt) {
 			if (fontmtab[i]==0) {
-				if (debug) fprint(2, "fontmtab[%d]=0x%x, fontmnt=%d\n", i, fontmtab[i], fontmnt);
+				if (debug)
+					fprint(2, "fontmtab[%d]=%#p, fontmnt=%d\n",
+						i, fontmtab[i], fontmnt);
 				continue;
 			}
 			fontid = findtfn(fontmtab[i], TRUE);
 if (debug) fprint(2, "	looking through special fonts: trying %s\n", troffontab[fontid].trfontid);
 			if (troffontab[fontid].special) {
 				cp = findglyph(fontid, rune, stoken);
-				if (*cp != 0) goto foundit;
+				if (*cp != 0)
+					goto foundit;
 			}
 		}
 
@@ -149,7 +165,7 @@ if (debug) fprint(2, "	looking through font at position 1: trying %s\n", troffon
 	rune = 'p';	stoken = "pw";
 	for (i=(mi+1)%fontmnt; i!=mi; i=(i+1)%fontmnt) {
 		if (fontmtab[i]==0) {
-			if (debug) fprint(2, "fontmtab[%d]=0x%x\n", i, fontmtab[i]);
+			if (debug) fprint(2, "fontmtab[%d]=%#p\n", i, fontmtab[i]);
 			continue;
 		}
 		fontid = findtfn(fontmtab[i], TRUE);
@@ -159,25 +175,27 @@ if (debug) fprint(2, "	looking through special fonts: trying %s\n", troffontab[f
 			if (*cp != 0) goto foundit;
 		}
 	}
-	
+
 	if (*cp == 0) {
-		error(WARNING, "cannot find glyph, rune=0x%x stoken=<%s> troff font %s\n", rune, stoken,
-			troffontab[curtrofffontid].trfontid);
+		error(WARNING, "cannot find glyph, rune=0x%x stoken=<%s> troff font %s\n",
+			rune, stoken, troffontab[curtrofffontid].trfontid);
 		expecthmot = 0;
 		return;
 	}
 
 foundit:
 	t = (((*cp)->postfontid&0xff)<<8) | ((*cp)->postcharid&0xff);
-	if (debug) {
-		Bprint(Bstderr, "runeout(0x%x)<%C> postfontid=0x%x postcharid=0x%x troffcharwidth=%d\n",
-			rune, rune, (*cp)->postfontid, (*cp)->postcharid, (*cp)->troffcharwidth);
-	}
-		
-	tfp = &(troffontab[fontid]);
+	if (debug)
+		fprint(2, "runeout(0x%x)<%C> postfontid=0x%x postcharid=0x%x troffcharwidth=%d\n",
+			rune, rune, (*cp)->postfontid, (*cp)->postcharid,
+			(*cp)->troffcharwidth);
+
+	tfp = &troffontab[fontid];
+	psfp = nil;
 	for (i=0; i<tfp->psfmapsize; i++) {
 		psfp = &(tfp->psfmap[i]);
-		if(t>=psfp->start && t<=psfp->end) break;
+		if(t>=psfp->start && t<=psfp->end)
+			break;
 	}
 	if (i >= tfp->psfmapsize)
 		error(FATAL, "character <0x%x> does not have a Postscript font defined.\n", rune);
@@ -187,44 +205,47 @@ foundit:
 	if (t == 0x0001) {	/* character is in charlib */
 		endstring();
 		if (pageon()) {
-			struct charent *tcp;
-
 			Bprint(Bstdout, "%d %d m ", hpos, vpos);
 			/* if char is unicode character rather than name, clean up for postscript */
 			wid = chartorune(&r, (*cp)->name);
 			if(' '<r && r<0x7F)
-				Bprint(Bstdout, "%d build_%s\n", (*cp)->troffcharwidth, (*cp)->name);
+				Bprint(Bstdout, "%d build_%s\n",
+					(*cp)->troffcharwidth, (*cp)->name);
 			else{
 				if((*cp)->name[wid] != 0)
 					error(FATAL, "character <%s> badly named\n", (*cp)->name);
-				Bprint(Bstdout, "%d build_X%.4x\n", (*cp)->troffcharwidth, r);
+				Bprint(Bstdout, "%d build_X%.4x\n",
+					(*cp)->troffcharwidth, r);
 			}
 
-			/* stash charent pointer in a list so that we can print these character definitions
-			 * in the prologue.
+			/*
+			 * stash charent pointer in a list so that we can
+			 * print these character definitions in the prologue.
 			 */
 			for (i=0; i<build_char_cnt; i++)
-				if (*cp == build_char_list[i]) break;
+				if (*cp == build_char_list[i])
+					break;
 			if (i == build_char_cnt) {
-				build_char_list = galloc(build_char_list, sizeof(struct charent *) * ++build_char_cnt,
-				"build_char_list");
+				build_char_list = galloc(build_char_list,
+					sizeof(struct charent *)*++build_char_cnt,
+					"build_char_list");
 				build_char_list[build_char_cnt-1] = *cp;
 			}
 		}
 		expecthmot = (*cp)->troffcharwidth * fontsize / unitwidth;
 	} else if (isinstring() || rune != ' ') {
 		startstring();
-		if (pageon()) {
+		if (pageon())
 			if (rune == ' ')
 				Bprint(Bstdout, " ");
 			else
 				Bprint(Bstdout, "%s", charcode[RUNEGETCHAR(t)].str);
-		}
 		expecthmot = (*cp)->troffcharwidth * fontsize / unitwidth;
 	}
 }
 
-/* runeout puts a symbol into a string (queue) to be output.
+/*
+ * runeout puts a symbol into a string (queue) to be output.
  * It also has to keep track of the current and last symbol
  * output to check that the spacing is correct by default
  * or needs to be adjusted with a spacing operation.
@@ -243,22 +264,23 @@ runeout(Rune rune) {
 void
 specialout(char *stoken) {
 	Rune rune;
-	int i;
 
-	i = chartorune(&rune, stoken);
+	chartorune(&rune, stoken);
 	glyphout(rune, stoken, TRUE);
 }
 
 void
 graphfunc(Biobufhdr *bp) {
+	USED(bp);
 }
 
 long
 nametorune(char *name) {
+	USED(name);
 	return(0);
 }
 
 void
 notavail(char *msg) {
-	Bprint(Bstderr, "%s is not available at this time.\n", msg);
+	fprint(2, "%s is not available at this time.\n", msg);
 }