%begin; !Wrap a file in STX and (ETX+checksum)

%include "inc:util.imp"
%string(31)infile,outfile=""
%constinteger stx=2,etx=3,cr=13,lf=nl
%integer sum=stx+etx,sym

%onevent 9 %start
  printsymbol(etx); phex4(sum); %stop
%finish

defineparam("Input file",infile,pammajor!pamnodefault)
defineparam("Output file",outfile,pamnewgroup!pammajor)
processparameters(cliparam)
outfile = infile %if outfile=""

openinput(1,infile); selectinput(1)
openoutput(1,outfile); selectoutput(1)
printsymbol(stx)
%cycle
  readsymbol(sym) %and sym = sym&127 %until sym#cr
  printsymbol(cr) %and sum = sum+cr %and sym = lf %if sym=nl
  printsymbol(sym)
  sum = sum+sym
%repeat

%endofprogram
