8604550b2b8d488e425661493c00d41f7e941307 — crc 1 year, 8 months ago 4de6b1b
add retro implementation of block_import
2 files changed, 43 insertions(+), 0 deletions(-)

A block_import.retro
M README.md => README.md +6 -0
@@ 23,12 23,18 @@ This takes a block file as input and converts it to a plain text
file format. Each line gets a line number, and horizontal rules
are provided as a visual aid.

A RetroForth implementation is also provided as

### block_import.py

This takes a plain text file (as created by `block_export.py`)
and converts it into a block file. The horizontal rules and line
numbers are stripped in the process.

A RetroForth implementation is also provided as

### block_merge.py

This takes in two exported block sets, and allows you to select

A block_import.retro => block_import.retro +37 -0
@@ 0,0 1,37 @@
#!/usr/bin/env retro

Begin by opening the input and output files, and setting up a
couple of variables.

'ilo.blocks     file:W file:open 'OUT const
'ilo.blocks.txt file:R file:open 'IN  const

Displaying the block is a matter of:

- reading in and discarding the horizontal rules
- reading in 16 lines per block
- writing the lines (with trailing padding to 64 characters
  added) to the output

:discard-ruler IN file:read-line drop ;
:s:put/padded #3 n:add dup s:put s:length #64 swap - n:abs [ sp ] times ;
:display-block #16 [ IN file:read-line s:put/padded ] times ;

This overrides `c:put` to write the output to file.

[ OUT file:write ] &c:put set-hook
#4096 [ discard-ruler display-block ] times
&c:put unhook

Final cleanup is just closing the input and output files.

IN file:close
OUT file:close