[TUHS] Article on the history of cat(1)

Rob Pike robpike at gmail.com
Wed Nov 14 09:21:37 AEST 2018


I was offended by the -u flag in v7 cat, which was a necessary but
unfortunate consequence of preserving the original's semantics while
converting it to use the new standard I/O library. Dennis felt it was
important as a proof of the value of stdio; to me it was an indication that
stdio couldn't do everything. I rewrote cat to use just read and write, as
nature intended. I don't recall if my version is in any of v8 v9 v10 but
it, or something very like it, is in Plan 9:

% cat cat.c

#include <u.h>

#include <libc.h>


void

cat(int f, char *s)

{

char buf[8192];

long n;


while((n=read(f, buf, (long)sizeof buf))>0)

if(write(1, buf, n)!=n)

sysfatal("write error copying %s: %r", s);

if(n < 0)

sysfatal("error reading %s: %r", s);

}


void

main(int argc, char *argv[])

{

int f, i;


argv0 = "cat";

if(argc == 1)

cat(0, "<stdin>");

else for(i=1; i<argc; i++){

f = open(argv[i], OREAD);

if(f < 0)

sysfatal("can't open %s: %r", argv[i]);

else{

cat(f, argv[i]);

close(f);

}

}

exits(0);

}


%

-rob

P.S. I learned today that cat.c has a spurious trailing newline.

On Wed, Nov 14, 2018 at 10:15 AM Dave Horsfall <dave at horsfall.org> wrote:

> On Wed, 14 Nov 2018, Warren Toomey wrote:
>
> >> Didn't know that cat(1) was still written in assembly on Edition 6...
> >
> > https://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/s1/cat.s
>
> Thanks; then again, I never had a reason to poke around cat(1) (but I do
> remember adding a "-h" flag to pr(1) for a sub-header or something).
>
> In fact, the only assembler stuff I remember modifying was deep in the
> kernel, to take advantage of Unibus timing (on the /40 at least), where
> the "obvious" code was sub-optimal; can't remember the details, but it
> saved a bus cycle or two.
>
> Hell, I wish I still had that "CSU Tape"; it was Edition 6 with as much of
> Edition 7 (and AUSAM) that I could shoe-horn in, such as XON/XOFF for the
> TTY driver.  I was known as "Mr Unix 6-1/2" at the time...
>
> Completely rewrote the 200-UT driver so that it actually worked (IanJ's
> driver was a horrible mess) and worked around an egregious bug on the
> Kronos side which they said was baked-in so deep that it couldn't be
> fixed.
>
> Rewrote the plotter driver and Versatec LV-11 driver to use the buffer
> pool instead of the character queues, so they went like a bat out of hell.
>
> Etc.
>
> -- Dave
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20181114/60090dfa/attachment.html>


More information about the TUHS mailing list