\ -*- mode: forth -*-
\ $Id: reversefile.bigforth,v 1.2 2001/06/24 22:53:06 doug Exp $
\ http://www.bagley.org/~doug/shootout/

\ Idea by albert@spenarnc.xs4all.nl (Albert van der Horst) in
\ news:<GFDtFA.Lwz.1.spenarn@spenarnc.xs4all.nl>

2000000 constant size \ maximum size of input
size allocate throw constant buf
4096 constant linesize
create line linesize 2 + allot

: revfile   >r
    line buf size + begin 
        1-
        line linesize r@ read-line throw
    while  \ !! handle line buf overflows
        >r #lf over c! 
        r@ - 2dup r> move 
    repeat
    drop nip 1+ buf size + over -  rdrop ;

stdin revfile type bye