uses hss_asl_requester,intuition;
{$incl "exec/exec.h"}
{$incl "intuition/intuitionbase.h"}
{$incl "libraries/Dos.h"}

type
        rec=string[1000000];
var
        buf:^rec;
        fname:string;

Procedure       check_uu;
var
        Mes:Array[1..5,1..3] of string;
        i,tst,part,Pack:long;
        j,errs,cr,oldcr,err,chunk:long;
        f,ff:file of char;
        s,t,last,last1:string[256];
        sss:string;
        ibase:^intuitionbase;
        time1,time2:long;
        time3,time4,len,pl:long;
        out:file of char;
        ending,alreadyfound:boolean;

begin
rewrite(output,"con:0/15/640/100/ShirUUExtractor:/close/Wait");
ending:=false;
rewrite(out,"ram:out");
ibase:=intbase;
s:=hss_filereq(nil,"net:","uu","Filname?");
{$i -}
reset(f,s);
err:=ioresult;
{$i +}
if err=0 then
        begin
        sss:=s+"_OK";
        fname:=sss;
        rewrite(ff,sss);
        errs:=0;
        chunk:=0;
        i:=0;
        cr:=0;
        last:="";
        t:="";
        buf:=ptr(alloc_mem(filesize(f),memf_public));
        blockread(f,buf,filesize(f));
        cr:=pos(char(10),buf^);
        len:=length(buf^);
        gotoxy(1,1);
        writeln("Filesize= ",filesize(f));
        oldcr:=1;
        tst:=0;
        part:=0;
        Pack:=1;
        pl:=0;
        alreadyfound:=false;
        while (cr>0) and (cr<len) do
                begin
                j:=0;
                while (buf^[oldcr+j]<>char(10)) and (oldcr+j<=len) do
                        begin
                        inc(j);
                        end;
                cr:=-1;
                if  (oldcr+j<=len) then if buf^[oldcr+j]=char(10) then cr:=oldcr+j;

                if cr>0 then
                   begin
                   inc(i);
                   last1:=last;
                   last:=t;
                   t:=copy(buf^,oldcr+1,cr-oldcr-1);
                   oldcr:=cr;
                   buf^[cr]:=char(1);
                   if i mod 239=0 then
                                 begin
                                 inc(chunk);
                                 gotoxy(1,2);
                                 write("Line:",i);
                                 end;
                   if pos("begin",t)=1 then
                                 begin
                                 {gotoxy(1,3);}
                                 writeln(ff,t)
                                 end else
                if (pos("  Re: [",t)=1) and (pos("From: IN:ftpmail@",last1)=1) then
                             begin
                             pl:=pl+tst;
                             if (alreadyfound) and (tst<239) and (part>1) and (part<5) and not ending then
                                           begin
                                           Writeln;
                                           Writeln;
                                           Writeln(out,"ERROR: Lost mails! at Pack: ",pack,"  Part=",Part," (pack lines=",pl,"  Part lines=",tst,")");
                                           Writeln("ERROR: Lost mails! at Pack: ",pack,"  Part=",Part," (pack lines=",pl,"  Part lines=",tst,")");
                                           Writeln(out,"You must get the mail after:");
                                           Writeln(out,Mes[part-1,1]);
                                           Writeln(out,Mes[part-1,2]);
                                           Writeln(out,Mes[part-1,3]);
                                           Writeln(out,">>>>> Part:", Part);
                                           Writeln("ERROR: Lost mails! at Pack: ",pack,"  pack lines=",pl,"  Part lines=",tst);
                                           Error("ERROR: Lost mails!");
                                           end;
                             alreadyfound:=true;
                             Writeln(out,"Part: ",part,"  tst=",tst,"   pl=",pl);
                             tst:=0;
                             if part=5 then
                                          begin
                                          {
                                          Writeln(out,"****** ");
                                          Writeln(ff,"---------Pack: ",pack,"  pack lines=",pl);
                                          }
                                          if pl<>958 then
                                                     begin
                                                     gotoxy(1,6);
                                                     Writeln(out,"ERROR: Lost mails! at Pack: ",pack,"  Part=",Part," (pack lines=",pl,"  Part lines=",tst,")");
                                                     Writeln("ERROR: Lost mails! at Pack: ",pack,"  Part=",Part," (pack lines=",pl,"  Part lines=",tst,")");
                                                     Error("ERROR: Lost mails!");
                                                     gotoxy(1,4);
                                                     end;
                                          gotoxy(1,3);
                                          writeln("Pack=",pack);
                                          part:=0;
                                          inc(pack);
                                          pl:=0;
                                          end;
                             inc(part);
                             Mes[part,1]:=last1;
                             Mes[part,2]:=last;
                             Mes[part,3]:=t;
                             gotoxy(1,4);
                             writeln("Part=",part);
                        end else
                   if (length(t)=61) and (pos("M",t)=1) then
                                 begin
                                 {inc(pl);}
                                 writeln(ff,t);
                                 inc(tst);
                                 end else
                if tst>239 then
                             begin
                             {
                             gotoxy(1,18);
                             writeln(out,"error!:",i,"    ");{delay(50);}
                             }
                             end else
                     if pos("end",t)=1 then
                                 begin
                                 ending:=true;
                                 if pos("M",last1)<>1 then writeln(ff,last1);
                                 if pos("M",last)<>1 then writeln(ff,last);
                                 writeln(ff,t)
                                 end else
                        if (length(t)<>61) and (pos('M',t)=1) then
                           begin
                           inc(errs);
                           writeln;
                           {
                           gotoxy(1,10);
                           writeln("Error at line:",i," at Part=",part,", Pack=",Pack,"     Errors:",errs);
                           }
                           writeln(out,"Error at line:",i," at Chunk=",chunk,"     Errors:",errs);
                           end;
                   end;
                end;
        free_mem(long(buf),filesize(f));
        close(f);
        close(ff);
        end;
Writeln;
Writeln;
Writeln("... Jub completed.");
close(out);
close(output);
end;

(*********************************************)
var
command:string;

Begin
        check_uu;
        command:="execute s:suux.s "+fname;
        if execute(command,0,0)=0 then;
{        make_uu;}
end.





























