dump-file

Description of the page content

Forth word to dump the content of a file.

Tags:

dump-file is a simple Forth word to dump the content of a file.

Source code

\ dump-file

\ (c) 2006,2012 Marcos Cruz (programandala.net)
\ License: http://programandala.net/license

\ Simple word to inspect the content of a file.

\ Programa escrito en ANS Forth. Probado en Gforth.
\ Programo verkita en ANS-Fortho. Gforth-e provita.
\ Program written in ANS Forth. Tested with Gforth.

\ --------------------------------------------------------

\ 2006-03-16 First version.
\ 2012-02-07 Source edited. Some words renamed. Fixed the end of the loop.

\ --------------------------------------------------------


64 value df-piece
create df-buffer df-piece chars allot
variable file-id

: df-there  ( -- a-addr u )
  df-buffer df-piece
  ;

: df-open  ( c-addr u -- )
  \ c-addr u = file name
  r/o open-file  abort" open file error"  file-id !
  ;

: df-close  ( -- )
  file-id @ close-file  abort" close file error"
  ;

: dump-file ( c-addr u -- )
  \ c-addr u = file name
  df-open
  begin
    df-there erase  df-there file-id @ read-file
    0= over 0<> and
  while
    df-buffer swap dump  cr ." press any key" key drop cr
  repeat
  df-close
  ;

Downloads