retroforth/example/Cat.forth
crc 183c5bae38 Initial checkin (from 58fa921 in the old git repo)
FossilOrigin-Name: d2b8467883db80cb179089e1db1b1ed4dff1f11b4bee7086ee46d83f3ee0136e
2017-10-16 16:09:39 +00:00

30 lines
603 B
Forth
Executable file

#!/usr/bin/env rre
~~~
{{
'FID var
'FSize var
'Action var
'Buffer var
:-eof? (-f) @FID file:tell @FSize lt? ;
---reveal---
:file:read-line (f-s)
!FID
[ s:empty dup !Buffer buffer:set
[ @FID file:read dup buffer:add
[ ASCII:CR eq? ] [ ASCII:LF eq? ] [ ASCII:NUL eq? ] tri or or ] until
buffer:get drop ] buffer:preserve
@Buffer ;
:file:for-each-line (sq-)
!Action
file:R file:open !FID
@FID file:size !FSize
[ @FID file:read-line @Action call -eof? ] while
@FID file:close ;
}}
~~~
~~~
#0 sys:argv [ puts nl ] file:for-each-line
~~~