I have been toying with SuperForth for some days, I am fairly new to the language, just learning its grammar.
Interesting concept is that of files being stored in 1024B blocks, supplied Editor displays one block a time allowing to browse trough the file displaying [CTRL] [F3] next or [SHIFT] [F3] previous block.
There is a utility Word SAVE_FILE provided in BLK4, accepting start + end blocks to create a single named file.
A named file can be executed by LOAD_FILE.
I was thinking of a reverse Word, that would take a named file and recreate blocks suitable to display in the Editor. As is not present in the dictionary, here's my first attempt to define READ_FILE ...
Code: Select all
2VARIABLE #TEMP
VARIABLE #EOF
: READ_FILE ( first_block "filename" --- )
#IN 2@ #TEMP 2! 0 OPEN #IN 2!
BEGIN DUP BUFFER
L/B 0 DO
DUP QUERY 10 WORD DUP C@ 0= #EOF !
COUNT ROT SWAP CMOVE
SPAN @ + C/L SPAN @ - +
LOOP DROP
UPDATE SAVE-BUFFERS
1+ #EOF @ UNTIL DROP
#IN 2@ CLOSE
#TEMP 2@ #IN 2!
;
END_FILE
I use "QUERY 10 WORD" to read a line of input file, but using "TIB C/L EXPECT 10 WORD" would be better as C/L reflects curent system settings of characters per line, but I discovered that the latter only reads 29 chars of each line.
Tom