%%s 3/3/96 %%d D 1.2 29-Jul-82 07:50:21 j 2 1 %%c Modified tail.w`tail.r`defns to double the size of the line buffer %%c (from 3000 to 6000) to handle a larger number of lines. %%s 0/0/0 %%d D 1.1 25-Mar-82 12:15:23 v1.1 1 0 %%c Version 1.1 is the Spring 1982 Distribution of the LBL/Hughes release %%c of the Software Tools Virtual Operating System software and documentation. %%T %%I 1 %%D 2 #-h- tail.r 2051 asc 25-mar-82 08:55:42 v1.1 (sw-tools v1.1) #-h- defns 160 asc 25-mar-82 08:55:18 v1.1 (sw-tools v1.1) %%E 2 %%I 2 #-h- tail.r 2044 asc 29-jul-82 07:22:55 j (sventek j) #-h- defns 160 asc 29-jul-82 07:18:25 j (sventek j) %%E 2 # include standard symbol definitions # include ratdef %%D 2 define(MAXBUF,3000) # line buffer size %%E 2 %%I 2 define(MAXBUF,6000) # line buffer size %%E 2 define(DEFAULT,23) # default if no argument #-h- main 971 asc 25-mar-82 08:55:19 v1.1 (sw-tools v1.1) # tail - print tail portion of a file DRIVER(tail) character arg(MAXLINE) integer n, i, fd integer ctoi, getarg, open call query("usage: tail [-n] [file] ...") n = DEFAULT fd = ERR for (i=1; getarg(i, arg, MAXLINE) != EOF; i=i+1) { if (arg(1) == '-' & arg(2) != EOS) { j = 2 n = ctoi(arg, j) if (n <= 0) call error ("invalid size.") } else if (arg(1) == '-' & arg(2) == EOS) { fd = STDIN call ptail (n, fd) } else { fd = open(arg, READ) if (fd == ERR) call cant(arg) call ptail (n, fd) call close(fd) } } if (fd == ERR) #no files specified, read STDIN call ptail (n, STDIN) DRETURN end #-h- ptail 701 asc 25-mar-82 08:55:21 v1.1 (sw-tools v1.1) ## ptail - print last 'n' lines of file 'fd' subroutine ptail (nlins, fd) integer n, fd, nlins character buf(MAXBUF) character getch integer head, tail, i head = 1 tail = 1 n = nlins while (getch(buf(tail), fd) != EOF) { tail = mod(tail, MAXBUF) + 1 if (tail == head) head = mod(head, MAXBUF) + 1 } for (i = tail; i != head; ) { i = i - 1 if (i == 0) i = MAXBUF if (buf(i) == '@n') { n = n - 1 if (n < 0) { i = mod(i, MAXBUF) + 1 break } } } for (head = i; head != tail; head = mod(head, MAXBUF) + 1) call putch(buf(head), STDOUT) return end #-h- tail.fmt 641 asc 25-mar-82 08:55:44 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Tail (1) 26-Aug-79 print last lines of a file .sy tail [-n] [file] ... .ds Tail prints the last "n" lines of the indicated file. If 'n' is omitted, the last 23 lines are printed. If "file" is omitted or is "-", tail reads the standard input. .sa split .au David Hanson and friends (U. of Arizona) .bu An internal buffer of MAXBUF characters is kept. If the value of "n" would require buffering more characters than the buffer can hold, tail prints the last MAXBUF characters of the file. In this case, the first line of output may not be an entire line. MAXBUF is a definition in the source code which may be adjusted. %%E 1