shithub: riscv

Download patch

ref: c650a7db0cb5a60286c4dbd0d24423eddcb7e0e3
parent: 27921a1ba0e70a9f6c01f174d69749c689f625b5
author: BurnZeZ <devnull@localhost>
date: Tue Dec 25 23:47:22 EST 2018

tcs: clean up old port code, and avoid writing 0 to stdout

--- a/sys/src/cmd/tcs/conv.h
+++ b/sys/src/cmd/tcs/conv.h
@@ -15,6 +15,7 @@
 void uksc_out(Rune *base, int n, long *notused);
 void html_in(int fd, long *notused, struct convert *out);
 void html_out(Rune *base, int n, long *notused);
+void unhtml_in(int fd, long *notused, struct convert *out);
 void tune_in(int fd, long *notused, struct convert *out);
 void tune_out(Rune *base, int n, long *notused);
 
--- a/sys/src/cmd/tcs/conv_big5.c
+++ b/sys/src/cmd/tcs/conv_big5.c
@@ -1,12 +1,6 @@
-#ifdef	PLAN9
 #include	<u.h>
 #include	<libc.h>
 #include	<bio.h>
-#else
-#include	<stdio.h>
-#include	<unistd.h>
-#include	"plan9.h"
-#endif
 #include	"hdr.h"
 #include	"conv.h"
 #include	"big5.h"
@@ -44,8 +38,8 @@
 		else {
 			nerrors++;
 			if(squawk)
-				EPR "%s: bad big5 glyph (from 0x%x,0x%lx) near byte %ld in %s\n",
-					argv0, lastc, cold, input_loc, file);
+				warn("bad big5 glyph (from 0x%x,0x%lx) near byte %ld in %s",
+					lastc, cold, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 			state = state0;
@@ -56,8 +50,8 @@
 		else {
 			nerrors++;
 			if(squawk)
-				EPR "%s: bad big5 font %d (from 0x%x,0x%lx) near byte %ld in %s\n",
-					argv0, lastc-161, lastc, cold, input_loc, file);
+				warn("bad big5 font %d (from 0x%x,0x%lx) near byte %ld in %s",
+					lastc-161, lastc, cold, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 			state = state0;
@@ -71,8 +65,8 @@
 		if(ch < 0){
 			nerrors++;
 			if(squawk)
-				EPR "%s: unknown big5 %ld (from 0x%x,0x%lx) near byte %ld in %s\n",
-					argv0, n, lastc, cold, input_loc, file);
+				warn("unknown big5 %ld (from 0x%x,0x%lx) near byte %ld in %s",
+					n, lastc, cold, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 		} else
@@ -151,7 +145,7 @@
 				}
 			}
 			if(squawk)
-				EPR "%s: rune 0x%x not in output cs\n", argv0, r);
+				warn("rune 0x%x not in output cs", r);
 			nerrors++;
 			if(clean)
 				continue;
--- a/sys/src/cmd/tcs/conv_gb.c
+++ b/sys/src/cmd/tcs/conv_gb.c
@@ -1,12 +1,6 @@
-#ifdef	PLAN9
 #include	<u.h>
 #include	<libc.h>
 #include	<bio.h>
-#else
-#include	<stdio.h>
-#include	<unistd.h>
-#include	"plan9.h"
-#endif
 #include	"hdr.h"
 #include	"conv.h"
 #include	"gb.h"
@@ -40,7 +34,7 @@
 		else {
 			nerrors++;
 			if(squawk)
-				EPR "%s: bad gb glyph %d (from 0x%x,0x%lx) near byte %ld in %s\n", argv0, c-0xA0, lastc, cold, input_loc, file);
+				warn("bad gb glyph %d (from 0x%x,0x%lx) near byte %ld in %s", c-0xA0, lastc, cold, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 			state = state0;
@@ -50,7 +44,7 @@
 		if(ch < 0){
 			nerrors++;
 			if(squawk)
-				EPR "%s: unknown gb %ld (from 0x%x,0x%lx) near byte %ld in %s\n", argv0, n, lastc, cold, input_loc, file);
+				warn("unknown gb %ld (from 0x%x,0x%lx) near byte %ld in %s", n, lastc, cold, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 		} else
@@ -120,7 +114,7 @@
 				continue;
 			}
 			if(squawk)
-				EPR "%s: rune 0x%x not in output cs\n", argv0, r);
+				warn("rune 0x%x not in output cs", r);
 			nerrors++;
 			if(clean)
 				continue;
--- a/sys/src/cmd/tcs/conv_gbk.c
+++ b/sys/src/cmd/tcs/conv_gbk.c
@@ -1,12 +1,6 @@
-#ifdef	PLAN9
 #include	<u.h>
 #include	<libc.h>
 #include	<bio.h>
-#else
-#include	<stdio.h>
-#include	<unistd.h>
-#include	"plan9.h"
-#endif
 #include	"hdr.h"
 #include	"conv.h"
 #include	"gbk.h"
@@ -39,7 +33,7 @@
 		if(ch < 0){
 			nerrors++;
 			if(squawk)
-				EPR "%s: bad gbk glyph %d (from 0x%x,0x%lx) near byte %ld in %s\n", argv0, (c & 0xFF), lastc, cold, input_loc, file);
+				warn("bad gbk glyph %d (from 0x%x,0x%lx) near byte %ld in %s", (c & 0xFF), lastc, cold, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 			state = state0;
@@ -111,7 +105,7 @@
 				continue;
 			}
 			if(squawk)
-				EPR "%s: rune 0x%x not in output cs\n", argv0, r);
+				warn("rune 0x%x not in output cs", r);
 			nerrors++;
 			if(clean)
 				continue;
--- a/sys/src/cmd/tcs/conv_jis.c
+++ b/sys/src/cmd/tcs/conv_jis.c
@@ -1,12 +1,6 @@
-#ifdef	PLAN9
 #include	<u.h>
 #include	<libc.h>
 #include	<bio.h>
-#else
-#include	<stdio.h>
-#include	<unistd.h>
-#include	"plan9.h"
-#endif
 #include	"hdr.h"
 #include	"conv.h"
 #include	"kuten208.h"
@@ -47,7 +41,7 @@
 		}
 		if(c < 0x21){	/* guard against bogus characters in JIS mode */
 			if(squawk)
-				EPR "%s: non-JIS character %02x in %s near byte %ld\n", argv0, c, file, input_loc);
+				warn("non-JIS character %02x in %s near byte %ld", c, file, input_loc);
 			emit(c);
 			return;
 		}
@@ -74,7 +68,7 @@
 	case state4:	/* two part char */
 		if(c < 0){
 			if(squawk)
-				EPR "%s: unexpected EOF in %s\n", argv0, file);
+				warn("unexpected EOF in %s", file);
 			c = 0x21 | (lastc&0x80);
 		}
 		if(CANS2J(lastc, c)){	/* ms dos sjis */
@@ -86,7 +80,7 @@
 		if((n >= KUTEN208MAX) || ((l = tabkuten208[n]) == -1)){
 			nerrors++;
 			if(squawk)
-				EPR "%s: unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
+				warn("unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 		} else {
@@ -93,7 +87,7 @@
 			if(l < 0){
 				l = -l;
 				if(squawk)
-					EPR "%s: ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
+					warn("ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s", n, l, input_loc, file);
 			}
 			emit(l);
 		}
@@ -160,7 +154,7 @@
 	case state4:	/* two part char */
 		if(c < 0){
 			if(squawk)
-				EPR "%s: unexpected EOF in %s\n", argv0, file);
+				warn("unexpected EOF in %s", file);
 			c = 0x21 | (lastc&0x80);
 		}
 		if(CANS2J(lastc, c)){	/* ms dos sjis */
@@ -170,7 +164,7 @@
 		} else {
 			nerrors++;
 			if(squawk)
-				EPR "%s: illegal byte pair (0x%x,0x%x) near byte %ld in %s\n", argv0, lastc, c, input_loc, file);
+				warn("illegal byte pair (0x%x,0x%x) near byte %ld in %s", lastc, c, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 			state = state0;
@@ -179,7 +173,7 @@
 		if((n >= KUTEN208MAX) || ((l = tabkuten208[n]) == -1)){
 			nerrors++;
 			if(squawk)
-				EPR "%s: unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
+				warn("unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 		} else {
@@ -186,7 +180,7 @@
 			if(l < 0){
 				l = -l;
 				if(squawk)
-					EPR "%s: ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
+					warn("ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s", n, l, input_loc, file);
 			}
 			emit(l);
 		}
@@ -216,7 +210,7 @@
 		if(c == 0x8e){	/* codeset 2 */
 			nerrors++;
 			if(squawk)
-				EPR "%s: unknown codeset 2 near byte %ld in %s\n", argv0, input_loc, file);
+				warn("unknown codeset 2 near byte %ld in %s", input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 			return;
@@ -232,7 +226,7 @@
 	case state1:	/* two part char */
 		if(c < 0){
 			if(squawk)
-				EPR "%s: unexpected EOF in %s\n", argv0, file);
+				warn("unexpected EOF in %s", file);
 			c = 0xA1;
 		}
 		n = (lastc&0x7F)*100 + (c&0x7F) - 3232;	/* kuten208 */
@@ -239,7 +233,7 @@
 		if((n >= KUTEN208MAX) || ((l = tabkuten208[n]) == -1)){
 			nerrors++;
 			if(squawk)
-				EPR "%s: unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
+				warn("unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 		} else {
@@ -246,7 +240,7 @@
 			if(l < 0){
 				l = -l;
 				if(squawk)
-					EPR "%s: ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
+					warn("ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s", n, l, input_loc, file);
 			}
 			emit(l);
 		}
@@ -256,12 +250,12 @@
 	case state2:	/* three part char, part #2 */
 		if(c < 0){
 			if(squawk)
-				EPR "%s: unexpected EOF in %s\n", argv0, file);
+				warn("unexpected EOF in %s\n", argv0, file);
 			c = 0xA1;
 		}
 		if(c < 0xa1 || c > 0xfe){
 			if(squawk)
-				EPR "%s: invalid byte 0x%x in codeset 3\n", argv0, c);
+				warn("invalid byte 0x%x in codeset 3\n", argv0, c);
 			state = state0;
 		}else{
 			lastc = c;
@@ -272,12 +266,12 @@
 	case state3:	/* three part char, part #3 */
 		if(c < 0){
 			if(squawk)
-				EPR "%s: unexpected EOF in %s\n", argv0, file);
+				warn("unexpected EOF in %s\n", argv0, file);
 			c = 0xA1;
 		}
 		if(c < 0xa1 || c > 0xfe){
 			if(squawk)
-				EPR "%s: invalid byte 0x%x in codeset 3\n", argv0, c);
+				warn("invalid byte 0x%x in codeset 3\n", argv0, c);
 			state = state0;
 			return;
 		}
@@ -286,7 +280,7 @@
 		if((n >= KUTEN212MAX) || ((l = tabkuten212[n]) == -1)){
 			nerrors++;
 			if(squawk)
-				EPR "%s: unknown kuten212 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
+				warn("unknown kuten212 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 		} else {
@@ -293,7 +287,7 @@
 			if(l < 0){
 				l = -l;
 				if(squawk)
-					EPR "%s: ambiguous kuten212 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
+					warn("ambiguous kuten212 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
 			}
 			emit(l);
 		}
@@ -359,7 +353,7 @@
 	case state4:	/* two part char */
 		if(c < 0){
 			if(squawk)
-				EPR "%s: unexpected EOF in %s\n", argv0, file);
+				warn("unexpected EOF in %s", file);
 			c = 0x21 | (lastc&0x80);
 		}
 		if((lastc&0x80) != (c&0x80)){	/* guard against latin1 in jis */
@@ -371,7 +365,7 @@
 		if((n >= KUTEN208MAX) || ((l = tabkuten208[n]) == -1)){
 			nerrors++;
 			if(squawk)
-				EPR "%s: unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
+				warn("unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 		} else {
@@ -378,7 +372,7 @@
 			if(l < 0){
 				l = -l;
 				if(squawk)
-					EPR "%s: ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
+					warn("ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s", n, l, input_loc, file);
 			}
 			emit(l);
 		}
@@ -494,7 +488,7 @@
 				continue;
 			}
 			if(squawk)
-				EPR "%s: rune 0x%x not in output cs\n", argv0, r);
+				warn("rune 0x%x not in output cs", r);
 			nerrors++;
 			if(clean)
 				continue;
@@ -532,7 +526,7 @@
 				continue;
 			}
 			if(squawk)
-				EPR "%s: rune 0x%x not in output cs\n", argv0, r);
+				warn("rune 0x%x not in output cs", r);
 			nerrors++;
 			if(clean)
 				continue;
@@ -567,7 +561,7 @@
 				continue;
 			}
 			if(squawk)
-				EPR "%s: rune 0x%x not in output cs\n", argv0, r);
+				warn("rune 0x%x not in output cs", r);
 			nerrors++;
 			if(clean)
 				continue;
--- a/sys/src/cmd/tcs/conv_ksc.c
+++ b/sys/src/cmd/tcs/conv_ksc.c
@@ -1,12 +1,6 @@
-#ifdef	PLAN9
 #include	<u.h>
 #include	<libc.h>
 #include	<bio.h>
-#else
-#include	<stdio.h>
-#include	<unistd.h>
-#include	"plan9.h"
-#endif
 #include	"hdr.h"
 #include	"conv.h"
 #include	"ksc.h"
@@ -58,7 +52,7 @@
 	case cs1last: /* 2nd byte of codeset 1 (KSC 5601) */
 		if(c < 0){
 			if(squawk)
-				EPR "%s: unexpected EOF in %s\n", argv0, file);
+				warn("unexpected EOF in %s", file);
 			c = 0x21 | (lastc&0x80);
 		}
 		n = ((lastc&0x7f)-33)*94 + (c&0x7f)-33;
@@ -65,7 +59,7 @@
  		if((n >= ksc5601max) || ((l = tabksc5601[n]) < 0)){
 			nerrors++;
 			if(squawk)
-				EPR "%s: unknown ksc5601 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
+				warn("unknown ksc5601 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
 			if(!clean)
 				emit(BADMAP);
 		} else {
@@ -75,8 +69,7 @@
 		return;
 	default:
 		if(squawk)
-			EPR "%s: ukscproc: unknown state %d\n",
-				argv0, init);
+			warn("ukscproc: unknown state %d", init);
 	}
 }
 
@@ -145,7 +138,7 @@
 				continue;
 			}
 			if(squawk)
-				EPR "%s: rune 0x%x not in output cs\n", argv0, r);
+				warn("rune 0x%x not in output cs", r);
 			nerrors++;
 			if(clean)
 				continue;
--- a/sys/src/cmd/tcs/hdr.h
+++ b/sys/src/cmd/tcs/hdr.h
@@ -37,10 +37,4 @@
 #define		BYTEBADMAP	('?')		/* badmap but has to fit in a byte */
 #define		ESC		033
 
-#ifdef	PLAN9
-#define	EPR		fprint(2,
-#define	EXIT(n,s)	exits(s)
-#else
-#define	EPR		fprintf(stderr,
-#define	EXIT(n,s)	exit(n)
-#endif
+void warn(char*, ...);
--- a/sys/src/cmd/tcs/plan9.h
+++ /dev/null
@@ -1,23 +1,0 @@
-typedef unsigned short Rune;		/* 16 bits */
-typedef unsigned char uchar;
-#define		Runeerror	0x80	/* decoding error in UTF */
-#define		Runeself	0x80	/* rune and UTF sequences are the same (<) */
-#define		UTFmax		6	/* maximum bytes per rune */
-
-/*
-	plan 9 argument parsing
-*/
-#define	ARGBEGIN	for((argv0? 0: (argv0= *argv)),argv++,argc--;\
-			    argv[0] && argv[0][0]=='-' && argv[0][1];\
-			    argc--, argv++) {\
-				char *_args, *_argt, _argc;\
-				_args = &argv[0][1];\
-				if(_args[0]=='-' && _args[1]==0){\
-					argc--; argv++; break;\
-				}\
-				_argc=0;while(*_args) switch(_argc= *_args++)
-#define	ARGEND		}
-#define	ARGF()		(_argt=_args, _args="",\
-				(*_argt? _argt: argv[1]? (argc--, *++argv): 0))
-#define	ARGC()		_argc
-extern char *argv0;
--- a/sys/src/cmd/tcs/tcs.c
+++ b/sys/src/cmd/tcs/tcs.c
@@ -1,17 +1,6 @@
-#ifndef PLAN9
-#include	<sys/types.h>
-#include	<stdio.h>
-#include	<unistd.h>
-#include	<stdlib.h>
-#include	<fcntl.h>
-#include	<string.h>
-#include	<errno.h>
-#include	"plan9.h"
-#else /* PLAN9 */
 #include	<u.h>
 #include	<libc.h>
 #include	<bio.h>
-#endif /* PLAN9 */
 #include	"cyrillic.h"
 #include	"misc.h"
 #include	"ms.h"
@@ -32,15 +21,12 @@
 Rune runes[N];
 char obuf[UTFmax*N];	/* maximum bloat from N runes */
 long tab[NRUNE];
-#ifndef	PLAN9
-extern char version[];
-#endif
 
 void intable(int, long *, struct convert *);
 void unicode_in(int, long *, struct convert *);
 void unicode_out(Rune *, int, long *);
 
-int
+void
 main(int argc, char **argv)
 {
 	char *from = "utf";
@@ -77,7 +63,7 @@
 		squawk = 1;
 	if(listem){
 		list();
-		EXIT(0, 0);
+		exits(nil);
 	}
 	if(!from || !to)
 		usage();
@@ -90,14 +76,8 @@
 	if(*argv){
 		while(*argv){
 			file = *argv;
-#ifndef PLAN9
-			if((fd = open(*argv, 0)) < 0){
-				EPR "%s: %s: %s\n", argv0, *argv, strerror(errno));
-#else /* PLAN9 */
 			if((fd = open(*argv, OREAD)) < 0){
-				EPR "%s: %s: %r\n", argv0, *argv);
-#endif /* PLAN9 */
-				EXIT(1, "open failure");
+				sysfatal("%s: %r", *argv);
 			}
 			PROC
 			close(fd);
@@ -108,19 +88,18 @@
 		PROC
 	}
 	if(verbose)
-		EPR "%s: %ld input bytes, %ld runes, %ld output bytes (%ld errors)\n", argv0,
+		warn("%ld input bytes, %ld runes, %ld output bytes (%ld errors)",
 			ninput, nrunes, noutput, nerrors);
-	EXIT(((nerrors && squawk)? 1:0), ((nerrors && squawk)? "conversion error":0));
-	return(0);	/* shut up compiler */
+	exits((nerrors && squawk)? "conversion error":nil);
 }
 
 void
 usage(void)
 {
-	EPR "Usage: %s [-slv] [-f cs] [-t cs] [file ...]\n", argv0);
+	fprint(2, "Usage: %s [-slv] [-f cs] [-t cs] [file ...]\n", argv0);
 	verbose = 1;
 	list();
-	EXIT(1, "usage");
+	exits("usage");
 }
 
 void
@@ -129,30 +108,43 @@
 	struct convert *c;
 	char ch = verbose?'\t':' ';
 
-#ifndef	PLAN9
-	EPR "%s version = '%s'\n", argv0, version);
-#endif
 	if(verbose)
-		EPR "character sets:\n");
+		fprint(2, "character sets:\n");
 	else
-		EPR "cs:");
+		fprint(2, "cs:");
 	for(c = convert; c->name; c++){
 		if((c->flags&From) && c[1].name && (strcmp(c[1].name, c->name) == 0)){
-			EPR "%c%s", ch, c->name);
+			fprint(2, "%c%s", ch, c->name);
 			c++;
 		} else if(c->flags&Table)
-			EPR "%c%s", ch, c->name);
+			fprint(2, "%c%s", ch, c->name);
 		else if(c->flags&From)
-			EPR "%c%s(from)", ch, c->name);
+			fprint(2, "%c%s(from)", ch, c->name);
 		else
-			EPR "%c%s(to)", ch, c->name);
+			fprint(2, "%c%s(to)", ch, c->name);
 		if(verbose)
-			EPR "\t%s\n", c->chatter);
+			fprint(2, "\t%s\n", c->chatter);
 	}
 	if(!verbose)
-		EPR "\n");
+		fprint(2, "\n");
 }
 
+void
+warn(char *fmt, ...)
+{
+	va_list arg;
+	char buf[1024];	/* arbitrary */
+	int n;
+
+	if((n = snprint(buf, sizeof(buf), "%s: ", argv0)) < 0)
+		sysfatal("snprint: %r");
+	va_start(arg, fmt);
+	vseprint(buf+n, buf+sizeof(buf), fmt, arg);
+	va_end(arg);
+
+	fprint(2, "%s\n", buf);
+}
+
 char*
 aliasname(char *name)
 {
@@ -188,8 +180,7 @@
 		if(((c->flags&From) == 0) == (from == 0))
 			return(c);
 	}
-	EPR "%s: charset `%s' unknown\n", argv0, name);
-	EXIT(1, "unknown character set");
+	sysfatal("charset `%s' unknown", name);
 	return(0);	/* just shut the compiler up */
 }
 
@@ -320,7 +311,8 @@
 	nrunes += n;
 	n = p - (uchar*)base;
 	noutput += n;
-	write(1, (char *)base, n);
+	if(n > 0)
+		write(1, base, n);
 }
 
 void
@@ -347,7 +339,8 @@
 	nrunes += n;
 	n = p - (uchar*)base;
 	noutput += n;
-	write(1, (char *)base, n);
+	if(n > 0)
+		write(1, (char *)base, n);
 }
 
 void
@@ -378,7 +371,7 @@
 			c = table[*p];
 			if(c < 0){
 				if(squawk)
-					EPR "%s: bad char 0x%x near byte %zd in %s\n", argv0, *p, ninput+(p-e), file);
+					warn("bad char 0x%x near byte %zd in %s", *p, ninput+(p-e), file);
 				nerrors++;
 				if(clean)
 					continue;
@@ -389,14 +382,8 @@
 		OUT(out, runes, r-runes);
 	}
 	OUT(out, runes, 0);
-	if(n < 0){
-#ifdef	PLAN9
-		EPR "%s: input read: %r\n", argv0);
-#else
-		EPR "%s: input read: %s\n", argv0, strerror(errno));
-#endif
-		EXIT(1, "input read error");
-	}
+	if(n < 0)
+		sysfatal("input read: %r");
 }
 
 void
@@ -420,7 +407,7 @@
 			c = -1;
 		if(c < 0){
 			if(squawk)
-				EPR "%s: rune 0x%x not in output cs\n", argv0, base[i]);
+				warn("rune 0x%x not in output cs", base[i]);
 			nerrors++;
 			if(clean)
 				continue;
@@ -429,7 +416,8 @@
 		*p++ = c;
 	}
 	noutput += p-obuf;
-	write(1, obuf, p-obuf);
+	if(p > obuf)
+		write(1, obuf, p-obuf);
 }
 
 int
--- a/sys/src/cmd/tcs/tune.c
+++ b/sys/src/cmd/tcs/tune.c
@@ -160,7 +160,7 @@
 			default: 
 				if(c >= 0xe200 && c <= 0xe3ff){
 					if(squawk)
-						EPR "%s: rune 0x%x not in output cs\n", argv0, c);
+						warn("rune 0x%x not in output cs", c);
 					nerrors++;
 					if(clean)
 						break;
@@ -221,7 +221,7 @@
 				}
 			}else if(lastr && lastr != Runeerror && (*r == 0x00b2/*²*/ || *r == 0x00b3/*³*/ || *r == 0x2074/*⁴*/)){
 				if(squawk)
-					EPR "%s: character <U+%.4X, U+%.4X> not in output cs\n", argv0, lastr, *r);
+					warn("character <U+%.4X, U+%.4X> not in output cs", lastr, *r);
 				lastr = clean ? 0 : Runeerror;
 				nerrors++;
 			}else{
@@ -302,5 +302,6 @@
 		state = 0;
 	}
 	noutput += p-obuf;
-	write(1, obuf, p-obuf);
+	if(p > obuf)
+		write(1, obuf, p-obuf);
 }
--- a/sys/src/cmd/tcs/utf.c
+++ b/sys/src/cmd/tcs/utf.c
@@ -1,16 +1,6 @@
-#ifdef PLAN9
 #include	<u.h>
 #include	<libc.h>
 #include	<bio.h>
-#else
-#include	<sys/types.h>
-#include	<stdio.h>
-#include	<stdlib.h>
-#include	<string.h>
-#include	<unistd.h>
-#include	<errno.h>
-#include	"plan9.h"
-#endif
 #include	"hdr.h"
 
 /*
@@ -40,7 +30,7 @@
 			c = our_mbtowc(&l, buf+i, tot-i);
 			if(c == -1){
 				if(squawk)
-					EPR "%s: bad UTF sequence near byte %ld in input\n", argv0, ninput+i);
+					warn("bad UTF sequence near byte %ld in input", ninput+i);
 				if(clean){
 					i++;
 					continue;
@@ -74,7 +64,8 @@
 		p += our_wctomb(p, *r);
 	}
 	noutput += p-obuf;
-	write(1, obuf, p-obuf);
+	if(p > obuf)
+		write(1, obuf, p-obuf);
 }
 
 void
@@ -92,7 +83,7 @@
 			c = isochartorune(&runes[j], buf+i);
 			if(runes[j] == Runeerror){
 				if(squawk)
-					EPR "%s: bad UTF sequence near byte %ld in input\n", argv0, ninput+i);
+					warn("bad UTF sequence near byte %ld in input", ninput+i);
 				if(clean){
 					i++;
 					continue;
@@ -123,7 +114,8 @@
 	for(r = base, p = obuf; n-- > 0; r++)
 		p += runetoisoutf(p, r);
 	noutput += p-obuf;
-	write(1, obuf, p-obuf);
+	if(p > obuf)
+		write(1, obuf, p-obuf);
 }
 
 
@@ -291,10 +283,6 @@
 	return 0;
 }
 
-#ifdef PLAN9
-int	errno;
-#endif
-
 enum
 {
 	T1	= 0x00,
@@ -326,10 +314,6 @@
 	Wchar3	= (1UL<<(Bit3+2*Bitx))-1,
 	Wchar4	= (1UL<<(Bit4+3*Bitx))-1,
 	Wchar5	= (1UL<<(Bit5+4*Bitx))-1,
-
-#ifndef	EILSEQ
-	EILSEQ	= 123,
-#endif /* EILSEQ */
 };
 
 int
@@ -478,6 +462,5 @@
 	return 1;
 
 bad:
-	errno = EILSEQ;
 	return -1;
 }