LZW compression: Difference between revisions
Content deleted Content added
m →version 2: corrected a misspelling. |
m →version 2: change type of compare (for input), added/changed comments and whitespace. |
||
Line 4,415:
This REXX version can execute on '''ASCII''' or '''EBCDIC''' systems.
<lang rexx>/*REXX program compresses text using the LZW (Lempel─Ziv─Welch), and reconstitutes it.*/
parse arg x; if x
x= '"There is nothing permanent except change." ─── Heraclitus [540-475 BC]'
say 'original text=' x /* [↑] Not specified? Then use default*/
Line 4,427:
do k=1 for length(y)+1; z= w || substr(y, k, 1)
if @.z=='' then do; $= $ @.w; @.z= #; #= # + 1; w= substr(y, k, 1); end
else w= z /*#: the dictionary size.*/
end /*k*/;
/*──────────────────────────────────────────────────────────────────────────────────────*/
LZWd: procedure; parse arg x y,,@.; #= 256 /*LZW decompress algorithm.*/
do j=0 for #; @.j= d2c(j); end /*j*/
$= @.x; w= $
do k=1 for words(y); z= word(y, k)
if @.z\=='' | @.k==" " then ?= @.z
else if z==# then ?= w || left(w, 1)
$= $ || ?
@.#= w || left(?, 1); #= # + 1; w= ?
end /*k*/; return $</lang>
{{out|output|text= when using the default input:}}
<pre>
|