Fixed length records: Difference between revisions

Content added Content deleted
(→‎{{header|TXR}}: New section.)
(→‎{{header|TXR}}: Forth blocks task.)
Line 1,588: Line 1,588:


=={{header|TXR}}==
=={{header|TXR}}==

===80 Column Task===


At the shell prompt:
At the shell prompt:
Line 1,615: Line 1,617:


This handles a final bit that is shorter than 80. When <code>buf-set-length</code> sets the buffer size back to 80, zero padding is applied. The zero-padded record is reversed.
This handles a final bit that is shorter than 80. When <code>buf-set-length</code> sets the buffer size back to 80, zero padding is applied. The zero-padded record is reversed.

===Forth Blocks Task===

====Encoding====

The following program is called <code>forth-enblock.tl</code>:

<syntaxhighlight lang="txrlisp">(typedef forth-line (array 64 bchar))

(let ((lno 0)
(blanks (make-buf 64 #\space)))
(whilet ((line (get-line)))
(put-obj (fmt "~-64,64a" line) (ffi forth-line))
(inc lno))
(while (plusp (mod (pinc lno) 16))
(put-buf blanks)))</syntaxhighlight>

{{out}}

<pre>$ txr forth-enblock.tl < forth-enblock.tl > forth-enblock.blk
$ xxd forth-enblock.blk
00000000: 2874 7970 6564 6566 2066 6f72 7468 2d6c (typedef forth-l
00000010: 696e 6520 2861 7272 6179 2036 3420 6263 ine (array 64 bc
00000020: 6861 7229 2920 2020 2020 2020 2020 2020 har))
00000030: 2020 2020 2020 2020 2020 2020 2020 2020
00000040: 2020 2020 2020 2020 2020 2020 2020 2020
00000050: 2020 2020 2020 2020 2020 2020 2020 2020
00000060: 2020 2020 2020 2020 2020 2020 2020 2020
00000070: 2020 2020 2020 2020 2020 2020 2020 2020
00000080: 286c 6574 2028 286c 6e6f 2030 2920 2020 (let ((lno 0)
[... snip ...]
000003e0: 2020 2020 2020 2020 2020 2020 2020 2020
000003f0: 2020 2020 2020 2020 2020 2020 2020 2020</pre>

====Decoding====

This is <code>forth-deblock.tl</code>

<syntaxhighlight lang="txrlisp">(typedef forth-block (array 16 (array 64 bchar)))

(defsymacro fbsz (sizeof forth-block))

(let* ((buf (make-buf fbsz))
(block-view (carray-buf buf (ffi forth-block)))
(nread fbsz))
(while (eql fbsz nread)
(set nread (fill-buf-adjust buf))
(when (plusp nread)
(buf-set-length buf fbsz #\space)
(each ((row [block-view 0]))
(put-line (trim-right #/ +/ row))))))</syntaxhighlight>

{{out}}

<pre>$ txr forth-deblock.tl < forth-enblock.blk
(typedef forth-line (array 64 bchar))

(let ((lno 0)
(blanks (make-buf 64 #\space)))
(whilet ((line (get-line)))
(put-obj (fmt "~-64,64a" line) (ffi forth-line))
(inc lno))
(while (plusp (mod (pinc lno) 16))
(put-buf blanks)))







</pre>


=={{header|Wren}}==
=={{header|Wren}}==