Flame Re: pussyfooting
Keith Packard
keith at reed.UUCP
Thu Mar 14 08:19:58 AEST 1985
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
More information about the Comp.unix.wizards
mailing list