!****************************************************************
!*                                                              *
!*      DUMP        Program analyses JHB-modded IFF files       *
!*                                                              *
!*                  Version 1.3   16 Feb 1987                   *
!*                                                              *
!****************************************************************

%include "inc:util.imp"
{%include "src:util.imp} {FS-D}
%include "iff:iffinc.imp"
{%include "demo:iff:iffinc.imp} {FS-D}

%begin
%record (iffhdr fm) iffhdr
%integerarray tot(0:255)
%owninteger i,k,l,rc,max,a,img,textcol

%integerfn iff dump image(%record (iffhdr fm) %name iffh)
%record (context fm) %name context
%integer filptr,filstart,next,no,nlc

%routine get(%integername no)
   filptr=filptr+1 %if byteinteger(filptr)=10
   no=byteinteger(filptr); filptr=filptr+1
%end

%routine testnlc(%integer increment)
   nlc=nlc+increment
   %if nlc>=80 %start
      newline
      phex4(filptr-filstart); printstring(": "); nlc=6
   %finish
%end

context == iffh_context
filptr = context_filptr; filstart = filptr
printstring("Image length: 16_"); phex(context_filelen-iffh_hlen*2); newline
%if iffh_datatype&16_c0 # 0 %start
   phex4(filptr-filstart); printstring(": "); nlc=6
   %cycle
      get(no)
      %if no=0 %start
         get(next)
         %if next=0 %start
            printstring("[00]"); testnlc(4)
         %elseif next=1
            printstring("[0A]"); testnlc(4)
         %elseif next=2
            printstring("[Error-2]"); %exit
         %elseif next=3
            printstring("[EOF]"); %exit
         %elseif next<=127
            printstring("*[");phex2(next); printstring("]"); newline
            phex4(filptr-filstart); printstring(": "); nlc=6
         %else
            get(no)
            next=(next&127)<<8+no
            printstring("*[");phex4(next); printstring("]"); newline
            phex4(filptr-filstart); printstring(": "); nlc=6
         %finish
      %else
         phex2(no); testnlc(2)
      %finish
   %repeat 
%else
   printline("uncompressed")
%finish
%result=0   
%end


rc = iff open file(cli param, iffhdr, iff read)
%if rc=0 %start

   rc = iff read header(iffhdr)
   %if rc=0 %start
      iff show header(iffhdr, 1)
      %for img=0,1,iffhdr_stereo %cycle
         rc = iff dump image(iffhdr)
      %repeat
   %finishelse printline(iff error(rc))
   iff close file(iffhdr)
%finishelse printline(iff error(rc))
%endofprogram
         
   
