!****************************************************************
!*                                                              *
!*      IFFLP: Program displays JHB-modded IFF files to LP      *
!*                                                              *
!*                  Version 1.2   12 Dec 1986                   *
!*                                                              *
!****************************************************************

%include "fractl:iffutils"

!Takes a run-length encoded IFF' file, expands it, rearranges it and displays it
!to line printer.

!J. Butler Dec 86

%begin
%string (255) param,infile,outfile
%bytearray a(0:688*688-1)
%owninteger i,j,k,r,c,b,d
%integer wid,ht,rc
%record (iffhdr fm) iffhdr

%bytefn char(%integer ch)
   !Generate characters with appropriate darkness
   %result=' ' %if ch<64
   %result='.' %if ch<128
   %result='+' %if ch<192
   %result='@'
%end

infile=cliparam
printline("Parameter?") %and %stop %unless infile-> infile.("/").outfile

rc = iff open file(infile, iffhdr, iff read)
rc = iff read header(iffhdr)

iff show header(iffhdr, 0)
rc = iff read image(iffhdr, addr(a(0)))
iff close file(iffhdr)

%if iffhdr_wid&1#0 %then wid=iffhdr_wid %else wid=iffhdr_wid-1
wid=iffhdr_wid-1; wid=wid-1 %if wid&1#0
ht =iffhdr_ht -1; ht=ht-1 %while ht&3#0

openoutput(1, outfile); selectoutput(1)
%for i=ht,-4,0 %cycle
   %for j=wid,-2,0 %cycle
      printsymbol(char(a(i*iffhdr_wid+j)))
   %repeat
   newline
%repeat
close output
%endofprogram
      
