!****************************************************************
!*                                                              *
!*      COMPACT:    Program reads an uncompressed IFF image     *
!*                  and writes it out compressed (RL-encoded)   *
!*                                                              *
!*                  Version 1.1    6 Apr 1988                   *
!*                                                              *
!****************************************************************

%include "iff:iffinc.imp"
%include "inc:util.imp"
%begin
%record (iffhdr fm) iffh
%string (255) infile, outfile
%integer rc, ad, insize, outsize

infile = cli param %and outfile=infile %unless cli param -> infile.("/").outfile
iffh=0; ad=0
rc = iff readin(infile, iffh, ad)
printline("Problem with reading ".infile) %and %stop %if rc#0
printline("Image is compacted already") %and %stop %if iffh_datatype & 16_C0 # 0
infile = infile.".iff" %unless exists(infile)
insize = filesize(infile)
iffh_datatype = iffh_datatype ! 16_C0 ;!Set compress bits
rc = iff writeout(outfile, iffh, ad)
printline("Problem with writing ".outfile) %and %stop %if rc#0
outfile = outfile.".iff" %unless exists(outfile)
outsize = filesize(outfile)
%if outsize > insize %start
   printline("Compaction algorithm fails - output file larger than input file")
%else
   printstring("Compacted "); write(insize,-1); printstring(" bytes to ")
   write(outsize,-1); newline
%finish
%endofprogram

