On Wed, 31 Jul 2002 21:02:04 +0900
Florian Frank <flori / eavesdrop.ping.de> wrote:

> I could try to document a little more in the best english I'm capable
> of. That is, it will probably be quite awful. ;)

A couple of suggestions:

	- Check for rotation by checking for changes in the inode number

	- Allow tailing from arbitrary points in the file by lines, e.g

		log.wind(10)    # skip 10 lines from the beginning, print
				# the rest of the file, then tail -f
		log.rewind(-10) # print last 10 lines, then tail -f

Something like this:

    def wind(lines)

        seek(0, IO::SEEK_SET)

        numlines = 0
        0.upto(stat.size) { |filepos|
            seek(filepos, IO::SEEK_SET)
            return if (numlines == lines)
            i = getc
            c = sprintf("%c", i)
            numlines += 1 if (c == "\n")
        }

    end

    def rewind(lines)

        seek(0, IO::SEEK_END)

        lines = lines.abs
        numlines = 0
        size = stat.size - 1

        size.downto(0) { |filepos|
            next if (size == filepos)
            seek(filepos, IO::SEEK_SET)
            i = getc
            c = sprintf("%c", i)
            numlines += 1 if (c == "\n")
            return if (numlines == lines)
        }
    end

----------------------------------------------------------------------
| Jim Hranicky, Senior SysAdmin                   UF/CISE Department |
| E314D CSE Building                            Phone (352) 392-1499 |
| jfh / cise.ufl.edu                      http://www.cise.ufl.edu/~jfh |
----------------------------------------------------------------------

"Given a choice between a complex, difficult-to-understand, disconcerting
 explanation and a simplistic, comforting one, many prefer simplistic
 comfort if it's remotely plausible, especially if it involves blaming
 someone else for their problems."
                                                -- Bob Lewis, _Infoworld_