From 4de6b1b2835349ff0e60681a2aa29bbdc5130eac Mon Sep 17 00:00:00 2001 From: crc Date: Wed, 30 Mar 2022 10:32:34 -0400 Subject: [PATCH] add a block_export tool in retro --- block_export.retro | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 block_export.retro diff --git a/block_export.retro b/block_export.retro new file mode 100644 index 0000000..5bfe760 --- /dev/null +++ b/block_export.retro @@ -0,0 +1,51 @@ +#!/usr/bin/env retro + +Begin by opening the input and output files, and setting up a +couple of variables. + +~~~ +'ilo.blocks.txt file:W file:open 'OUT const +'ilo.blocks file:R file:open 'IN const + +'Block var +'Line var +~~~ + +Draw the horizontal rule. This is intended to match that used in +the retro/ilo block editor, with the addition of the block +number at the end. + +~~~ +:rule '___ s:put #6 [ '+----5---- s:put ] times '+--- s:put ; +:id @Block $: c:put n:put nl ; +~~~ + +Displaying the block is a matter of reading in 16 lines of 64 +characters, outputting the line number, and then the text. +The output is setup to match that in `block_export.py` to keep +compatibility. + +~~~ +:n:put/padded dup #9 lteq? [ sp ] if n:put sp ; +:display @Line n:put/padded s:trim-right s:put nl &Line v:inc ; +:next s:empty dup buffer:set ; +:read-line #64 [ IN file:read buffer:add ] times ; +:read-block #0 !Line #16 [ next read-line display ] times ; +~~~ + +The top level loop just iterates over the blocks, displaying the +rules and then the block contents. This overrides `c:put` to +write the output to file. + +~~~ +[ OUT file:write ] &c:put set-hook +#4096 [ rule id read-block &Block v:inc ] times rule id ; +&c:put unhook +~~~ + +Final cleanup is just closing the input and output files. + +~~~ +IN file:close +OUT file:close +~~~ -- 2.45.2