Anonymous user
LZW compression: Difference between revisions
m
→version 2: changed whitespace and comments, simplified some code.
m (→version 2: changed whitespace and comments, simplified some code.) |
|||
Line 4,898:
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='' then x= ,
say 'original text=' x /* [↑] Not specified? Then use default*/
cypher= LZWc(x) /*compress text using the LZW algorithm*/
say 'reconstituted=' LZWd(cypher) /*display the reconstituted string. */
say ' LZW integers=' cypher /* " " LZW integers used. */
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
do j=0 for #; _= d2c(j); @._= j; end /*j*/▼
end /*k*/; return substr($, 2) /*elide a leading blank. */▼
/*──────────────────────────────────────────────────────────────────────────────────────*/
do k=1 for length(y)+1;
else w= z
end /*k*/;
/*──────────────────────────────────────────────────────────────────────────────────────*/
else if z==# then ?= w || left(w, 1)▼
LZWd: procedure; parse arg x y; call LZWi 1; $= @.x;
do
if @.z\=='' |
$= $ || ?
{{out|output|text= when using the default input:}}
<pre>
|