Program index;

const cl=#13#10;
h1= cl+
'index <input file with marked positions>'+cl+
                                                     +cl+
' writes 70 characters after chr207 to a *.ind file'+cl;
h2=
''+cl;
h3= cl+
'Jan Hollan (hollan@ped.muni.cz) made for his needs in June, 1995'+cl;


const
 Size_of_Buf=30000;
 NoEsc:boolean=true;
var
  bi,bo: array[1..Size_of_Buf] of byte;
  ci: array [1..Size_of_Buf] of char absolute bi;
  co: array [1..Size_of_Buf] of char absolute bo;
  w,x,NumRead,NumWritten: word;
  inp,out: file;
  aux_s:string;

procedure help(message:string);
  begin
   writeln(message);
   write(h1); write(h2); write(h3); HALT
  end;


begin
 IF pARAMCOUNT<1 THEN HELP('');
{$I-}
 assign(inp,paramstr(1));
 reset(inp,1);
 if IORESULT<>0 THEN
  begin
   aux_s:=ParamStr(1);
   if not ((aux_s[2]='/') or (aux_s[2]='?')) then
    help('There is no file >'+ParamStr(1)+'< in this directory!')
   else help('')
  end;
 assign(out,'m.ind');
 rewrite(out,1);
 if IORESULT<>0 THEN
  begin
   aux_s:=ParamStr(2);
   if not ((aux_s[1]='/') or (aux_s[1]='?')) then
    help('Cannot open an output file >'+ParamStr(2)+'< !')
   else help('')
  end;
{$I+}
 BlockRead(inp,bi,Size_of_Buf,NumRead);
 x:=71;
 while NumRead>0 do
  begin
   for w:=1 to NumRead do
     begin
      if bi[w]=207 then x:=1;
      if x<70 then begin bo[x]:=bi[w]; inc(x) end;
      if x=70 then begin bo[71]:=13; bo[72]:=10; BlockWrite(out,bo,72,NumWritten) end;  
     end;
   if NumWritten<72 then help('Disk full, cannot write the ouptut file!');
   BlockRead(inp,bi,Size_of_Buf,NumRead);
  end;
 if (x<>71) and (x<70) then
  begin
   inc(x); bo[x]:=13; inc(x); bo[x]:=10; BlockWrite(out,bo,x,NumWritten)
  end;

 close(inp);
 close(out)
end.
