Error message hygiene in tr(1) - started when I found "write error" unhelpfull (no %r) and escalated to tweeks to all the messages. -Steve Reference: /n/sources/patch/applied/tr-errmsgs Date: Wed Feb 18 11:20:05 CET 2009 Signed-off-by: steve@quintile.net --- /sys/src/cmd/tr.c Wed Feb 18 11:15:19 2009 +++ /sys/src/cmd/tr.c Wed Feb 18 11:15:17 2009 @@ -32,7 +32,6 @@ void delete(void); void squeeze(void); void translit(void); -void error(char*); long canon(Pcb*); char *getrune(char*, Rune*); void Pinit(Pcb*, char*); @@ -48,21 +47,21 @@ case 's': sflag++; break; case 'd': dflag++; break; case 'c': cflag++; break; - default: error("bad option"); + default: sysfatal("unknown option"); }ARGEND if(argc>0) Pinit(&pfrom, argv[0]); if(argc>1) Pinit(&pto, argv[1]); if(argc>2) - error("arg count"); + sysfatal("insufficent args"); if(dflag) { if ((sflag && argc != 2) || (!sflag && argc != 1)) - error("arg count"); + sysfatal("incorrect arg count"); delete(); } else { if (argc != 2) - error("arg count"); + sysfatal("incorrect arg count"); if (cflag) complement(); else translit(); @@ -117,7 +116,7 @@ } Prewind(&pto); if ((p = (Rune *) malloc((high+1)*sizeof(Rune))) == 0) - error("can't allocate memory"); + sysfatal("no memory"); for (i = 0; i <= high; i++){ if (!BITSET(f,i)) { if ((to = canon(&pto)) < 0) @@ -165,7 +164,7 @@ if (from > high) high = from; Prewind(&pfrom); if ((p = (Rune *) malloc((high+1)*sizeof(Rune))) == 0) - error("can't allocate memory"); + sysfatal("no memory"); for (i = 0; i <= high; i++) p[i] = i; while ((from = canon(&pfrom)) >= 0) { @@ -173,7 +172,7 @@ to = lastc; else lastc = to; if (BITSET(f,from) && p[from] != to) - error("ambiguous translation"); + sysfatal("ambiguous translation"); SETBIT(f,from); p[from] = to; SETBIT(t,to); @@ -219,7 +218,7 @@ i = n-j; n = read(fd, &buf[i], sizeof(buf)-i); if (n < 0) - error("read error"); + sysfatal("read failed - %r"); if (n == 0) return 0; j = 0; @@ -254,7 +253,7 @@ { if (wptr && wptr > wbuf) if (write(fd, wbuf, wptr-wbuf) != wptr-wbuf) - error("write error"); + sysfatal("write failed - %r"); wptr = wbuf; } @@ -303,7 +302,7 @@ } } if(n > 0377) - error("char>0377"); + sysfatal("character > 0377"); } *rp = n; } @@ -325,7 +324,7 @@ if(*p->current == '-' && p->last >= 0 && p->current[1]){ p->current = getrune(p->current+1, &r); if (r < p->last) - error ("Invalid range specification"); + sysfatal("invalid range specification"); if (r > p->last) { p->final = r; return ++p->last; @@ -347,10 +346,4 @@ { p->current = p->base; p->last = p->final = -1; -} -void -error(char *s) -{ - fprint(2, "%s: %s\n", argv0, s); - exits(s); }