retroforth/example/Cat.forth
crc 73493f92f4 complete renaming of words in the examples
FossilOrigin-Name: c9ea59275146e3ccddbcfc3c8e2aa12e0c1f51f6d54c9674cf7d9a3b0500bf7c
2018-05-07 16:36:37 +00:00

30 lines
604 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 [ s:put nl ] file:for-each-line
~~~