Anonymous user
ASCII art diagram converter: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section, used a better glyph for echoed output.
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Make grammar more tolerant of whitespace, add some whitespace to demo; rearrange to make more modular) |
m (→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section, used a better glyph for echoed output.) |
||
Line 691:
=={{header|REXX}}==
Some code was added to validate the input file.
<lang rexx>/*REXX
parse arg iFID test . /*obtain optional input─FID & test─data*/
if
if test=='' | test=="," then test= 'cafe8050800000808080000a' /* " " " data.*/
p.=0; p.0=1 /*P.α
do j=1 while lines(iFID)\==0; q=linein(iFID); say '
if q=='' then iterate /*skip if this is a blank record. */
if _L=='+' then do /*is this record an "in-between" ? */
if verify(q, '+-')\==0 then say e
iterate /*skip this record, it's a single "+". */
end
if _L\=='|' | _R\==
do until q=='|' /* [↓] parse a record for names. */
parse var q '|' n
if n=='' then leave /*Is N
if words(n)\==1 then do; say e'(invalid name): ' n; iterate j; end
/* [↑] add more name validations. */
$$=$; nn=n; upper $$
if wordpos(nn, $$)\==0 then do; say e '(dup name):' n; iterate j; end
$=$ n /*add the N (name) to the $ list. */
#=words($); !.#= (length(x) + 1) % 3 /*assign the number of bits for N. */
wb=max(wb, !.#) /*find the maximum number of bits. */
prev= # - 1 /*
p.#= p.prev + !.prev /*calculate the structure bit
end /*until
end /*j*/
if j==1 then do; say e '(file not found): ' iFID; exit 12; end
say
do k=1 for words($)
say right( word($, k), w)right(!.k, 4) "bits, bit position:"right(p.k, 5)
end /*k*/
say /* [↓] Any (hex) data to test? */
if test=='' then exit /*stick a fork in it, we're all done. */
bits=x2b(test); L=length(test)
wm=length( x2d( b2x( copies(1, wb) ) ) ) + 1 /*used for displaying maximum
say 'test (hex)=' test " length="L 'hexadecimal digits.'
say
do r=1 by 8+8 to L*4
_1=substr(bits, r, 8, 0); _2=substr(bits, r+8, 8, 0)
say 'test (bit)=' _1 _2
end /*r*/
say
do m=1 for words($) /* [↓]
_=translate( b2x( substr( bits, p.m, !.m) ), 'abcdef', "ABCDEF" )
say right( word($, m), w+2) ' decimal='right( x2d(_), wm) ' hex=' _
end /*m*/ /*stick a fork in it, we're all done. */</lang>
▲ /*stick a fork in it, we're done.*/</lang>
▲'''output''' when using the default input file:
<pre>
■■■■■text►
■■■■■text►
■■■■■text►
■■■■■text►
ID 16 bits, bit position: 1
QR 1 bits, bit position: 17
AA 1 bits, bit position: 22
TC 1 bits, bit position: 23
Line 793:
ID decimal= 51966 hex= cafe
QR decimal= 1 hex= 1
AA decimal= 0 hex= 0
TC decimal= 0 hex= 0
Line 803:
ANCOUNT decimal= 128 hex= 0080
NSCOUNT decimal= 32896 hex= 8080
</pre>
|