[comp.sys.amiga.tech] Unix like 'tail -f'

dave@cs.arizona.edu (Dave P. Schaumann) (01/17/91)

In article <1991Jan17.034047.18447@eecs.wsu.edu> rnelson@yoda.UUCP (Roger Nelson - Grad Student) writes:
>------
>
>Am I correct in my observation that Amiga DOS does not allow you to access
>a file in any way until it is fully closed? 

Assuming the file is opened for writing.  A file may be opened for reading any
number of times.

>Does there exist a UNIX like tail utility?  
>Could similar functionality be achieved using something like Matt Dillon's
>fifodev (which I intend to look at)?
>
>IRNTK (I really need to know).

The functionality of 'tail' can be achieved quite easily.
  1) Define N == the # of lines to be displayed.
  2) Create an array of N strings, all initially the empty string.
  3) Read in the file line by line, filling in the array in a circular
     fashion (ie, the N+1 line would over-write the 1st entry of the array).
  4) When EOF is reached, print out the array, from oldest to newest.

This general outline will give a solution that only needs to read the file
once, and is reasonably economical in space.

There probably is an implementation of 'tail' out there somewhere, given that
it wouldn't be hard at all to hack together a reasonably robust implementation
of it.

>Thanks,
>____  | ^          |    Roger Nelson          rnelson@yoda.eecs.wsu.edu

Dave Schaumann		|  And then -- what then?  Then, future...
dave@cs.arizona.edu	|  		-Weather Report

jesup@cbmvax.commodore.com (Randell Jesup) (01/17/91)

In article <1991Jan17.034047.18447@eecs.wsu.edu> rnelson@yoda.UUCP (Roger Nelson - Grad Student) writes:
>------
>
>Am I correct in my observation that Amiga DOS does not allow you to access
>a file in any way until it is fully closed? 
>
>Does there exist a UNIX like tail utility?  
>Could similar functionality be achieved using something like Matt Dillon's
>fifodev (which I intend to look at)?

	If it was opened MODE_OLDFILE, you can read it while it's being
extended.  If it was opened MODE_NEWFILE (which truncates it), an exclusive
lock on the file is obtained, and no one else can open the file until it's
closed.  Many standard programs use MODE_NEWFILE, since it creates the file
if it doesn't exist.  In 2.0, MODE_UPDATE will open a file, creating it
if it doesn't exist, and only gets a shared lock.

-- 
Randell Jesup, Keeper of AmigaDos, Commodore Engineering.
{uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.commodore.com  BIX: rjesup  
The compiler runs
Like a swift-flowing river
I wait in silence.  (From "The Zen of Programming")  ;-)

bruce@zuhause.MN.ORG (Bruce Albrecht) (01/21/91)

>In article <685@caslon.cs.arizona.edu> dave@cs.arizona.edu (Dave P. Schaumann) writes:
>The functionality of 'tail' can be achieved quite easily.
>  1) Define N == the # of lines to be displayed.
>  2) Create an array of N strings, all initially the empty string.
>  3) Read in the file line by line, filling in the array in a circular
>     fashion (ie, the N+1 line would over-write the 1st entry of the array).
>  4) When EOF is reached, print out the array, from oldest to newest.
>
>This general outline will give a solution that only needs to read the file
>once, and is reasonably economical in space.

There's a tail program in the SKsh package.  It can be used independently of SKsh.
The above implementation may not work will if the file has lines over a an arbitary
size.  If you know that the input file is seekable, it's probably faster to seek
to the end of the file, and read backwards, especially if the file is very big,
and the tail line count is small. 
--


bruce@zuhause.mn.org