henry@utzoo.UUCP (Henry Spencer) (03/02/85)
> > "cat"'s function is to concatenate files. Period. > > > > The day this fails to be true is the day "cat" is no longer > > a UNIX utility. > > Yarbles! Great boolshy yarblockles to you!!! This is the kind of > thinking that keeps SYS V from being as good as 4.2BSD. I hate to tell you this, but the latest SysV cat(1) is every bit as brain-damaged as the 4.2BSD one, in the same putrid ways. > `Cat' is alive > and well in spite of what DMR said in the BSTJ. Yes, on V7 and V8 systems. The one on 4.2BSD and SysV is dead and already rotting. > Even he can be wrong. But not this time. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry
keith@reed.UUCP (Keith Packard) (03/14/85)
To all of you who hate the 4.2 cat program, here is a fix (at least for those on vaxen). I, too, didn't like it when I typed cat -n and mysterious numbers appeared in the output. What follows is a *very* simplistic cat program. It is also fast. I don't believe I have ever seen it take *any* user time at all. (this includes catting 30 or 40 copies of /usr/dict/words). If the file name is - it reads standard input at that point. Anything else starting with a - is ignored (this eliminated much frustration with man). Also, when run with cat door it properly respondes with: cat: cannot open door instead of the silly 4.2 cat that says door: No such file or directory. keith packard ...!tektronix!reed!keith (school) or ...!tektronix!reed!motel6!keith (home) or ...!tektronix!azure!keithp (work) --------------------------- cut me here --------------------------- /* * cat.s * * to make me, type * * as -o cat cat.s * chmod +x cat * * rapidly catenate files to stdout */ .align 1 .set bufsiz,49152 /* * define system call values */ .set exit,1 .set read,3 .set write,4 .set open,5 .set close,6 /* * callg frames for system routines */ .data 1 error: .ascii "cat: could not open " errors: .int 3 .int 2 .int error .int 20 errorf: .int 3 .int 2 errorn: .int 0 errorl: .int 0 opens: .int 2 fname: .int 0 .int 0 closes: .int 1 cdes: .int 0 exits: .int 1 status: .int 0 .text start: .word 0x000 cmpl (sp),$1 # > 1 arg ? jneq mult # yup, do files clrl r0 # copy stdin jsb cat done: movl $exits,ap chmk $exit mult: addl3 sp,$8,r10 # set r10 as arg pointer floop: movl (r10)+,r8 # get file name jeql done # at end? cmpb (r8),$45 # - opt, read stdin bneq real # no, real file tstb 1(r8) # check second char bneq floop # unknown option, skip clrl r0 # copy stdin jsb cat brb floop # back for more real: movl r8,fname # save pointer in callg frame movl $opens,ap # set ap to start of frame chmk $open # interupt to open routine bcs badfile # couldn't open file movl r0,cdes # save file des in close frame jsb cat # cat file movl $closes,ap # close file chmk $close brb floop # back for more badfile: movl $errors,ap # write out error message chmk $write movl r8,errorn movl $1,r0 badlen: tstb (r8)+ beql badend incl r0 brb badlen badend: movl r0,errorl movb $10,-(r8) movl $errorf,ap chmk $write incl status brb floop .align 1 .lcomm buf,bufsiz .data /* * callg frames for read and write */ reads: .int 3 indes: .int 0 .int buf .int bufsiz writes: .int 3 .int 1 .int buf outlen: .int bufsiz .text cat: movl r0,indes # save file des in read frame jbr cgo cloop: movl $writes,ap chmk $write cgo: movl $reads,ap chmk $read movl r0,outlen # save num chars in write frame jgtr cloop rsb