3125a52331/library/files.retro

User picture

Commiter: Charles Childers

Author: Charles Childers

Revision: 3125a52331


File Size: 548 Bytes

(March 10, 2010 18:31 UTC) About 2 years ago

fread now returns the character read, not stores it in an address

 
Show/hide line numbers
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Copyright [c] 2010, Charles Childers                      )
( License: ISC                                              )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
' files open

: fread! ( ha-f ) swap fread dup rot ! ;

: slurp ( a"- )
  :r fopen dup
  if
    swap repeat 2dup fread! 0 =if 0 swap ! fclose drop ;then 1+ again
  else
    drop 0 swap !
  then ;
: >file ( $h- )
  push repeat @+ dup 0 =if rdrop 2drop ;then
  r fwrite 0 =if rdrop 2drop ;then again ;