; 
; 
; (c) 2000 Cyborg 

    {* Include sys:coder/preass/Options.p *}
    {* Include sys:coder/preass/Prozeduren.p *}

    {* String: Version="$VER: (C) CYBORG 2000"*}
    
    {* IncBlock: Seekpattern,250*}


LastSign[a0]:
    cmpi.b #0,(a0)+
    bne LastSign
    lea -2(a0),a0
    cmpi.b #"/",(a0)
    bne .rts
    move.l #"/ind",(a0)+
    move.l #"ex.h",(a0)+
    move.l #$746d6c00,(a0)+
.rts:
    rts


CopyFile[a0,a1]:
    {* StackFrame in,out,anz,InName=a0,Outname=a1*}
    movea.l a1,a2
    moveq.l #0,d7
.l0:
    cmpi.b #0,(a2)
    beq .l1
    cmpi.b #":",(a2)
    beq .l02
    cmpi.b #"?",(a2)
    beq .l02
    cmpi.b #"/",(a2)
    bne .l01
    addq.l #1,d7
.l01:
    lea 1(a2),a2
    bra .l0
.l02:
    move.b #"_",(a2)
    bra .l0
.l1:
    cmpi.l #0,d7
    beq .ende
;    subq.l #1,d7
    moveq.l #0,d6
.l2:
    addq.l #1,d6
    cmpi.l d6,d7
    beq .Copy
    moveq.l #0,d5
    move.l Buffer2,a3
    move.l a1,a2
    cmpi.l #"http",(a2)
    bne .ftp
    move.l #"p__/",3(a2)
    bra .los
.ftp:
    move.l #"p__/",2(a2)
.los:
    cmpi.b #"/",(a2)
    bne .l3
    addq.l #1,d5
    cmp.l d5,d6
    beq .makedir
.l3:
    move.b (a2)+,(a3)+
    bra .los
.makedir:
    move.b #0,(a3)+
    push d0-a5
    If Createdir(buffer2)#0
     {
       unlock(d1)
     }
    pop d0-a5
    bra .l2
.copy:
    Printf("%s\n",*OutName)
    lastsign(outname)
    If (in=open(InName,mode_old))#0
     {
      if (out=open(OutName,mode_new))#0
        {
          anz==10000
          While anz=10000
           {
            anz=Read(in,Filebuffer,10000)
            Write(out,Filebuffer,anz)
           }
          Close(out)
        }
      close(in)
     }
.ende:
    {* Unframereturn *}

ceol[a0]:
    cmpi.b #$0a,(a0)
    bne .l1
    move.b #0,(a0)
.l1:cmpi.b #0,(a0)+
    bne ceol
    rts
    

Start:
;    copymem("www.garfield.com",&Filename,?)
    buffer=malloc(1024)
    buffer1=malloc(1024)
    Buffer2=malloc(200)
    If Getfilename()#0 
     {
       grep==1
       Copymem(&Filename,&Seekpattern,250)        
     }
    FileBuffer=malloc(10000)
    If (Filehandle=Open("env:Aweb3/network",mode_old))#0
     {
       While Fgets(Filehandle,Buffer,1024)#0
        {
          Wort=.l0(Buffer)
          if Wort=#"CAPA" 
           {
             Copymem(Buffer+5,&Filename,240)
             ceol(&Filename)
           }
        }
       Close(Filehandle)
       FIB=malloc(400)
       FIB1=malloc(400)
       FillBuffer(FIB,0,400)
       FillBuffer(FIB1,0,400)
       FillBuffer(Buffer,0,1024)
       If (Dirlock=Lock(&Filename,Access_read))#0 
        {
          OK=Examine(Dirlock,FIB)
          While Exnext(Dirlock,FIB)#0
           {
             type=.l4(FIB)
             if type>0 
              {
               zeiger=8(FIB)
               Copymem(&Filename,Buffer,250)
               addpart(buffer,zeiger,1024)
               FillBuffer(Buffer1,0,1024)
               If (Dirlock1=Lock(Buffer,Access_read))#0
                {
                  FillBuffer(Buffer1,0,1024)
                  OK=Examine(Dirlock1,FIB1)
                  While Exnext(Dirlock1,FIB1)#0
                   {
                    zeiger=8(FIB1)
                    Copymem(Buffer,Buffer1,250)
                    addpart(buffer1,zeiger,1024)
                    zeiger=144(FIB1)
                    If Grep=0 
                     {
                      CopyFile(Buffer1,Zeiger)
                     }
                    If grep=1 and Stringfind(Zeiger,&Seekpattern)#0
                     {
                      CopyFile(Buffer1,Zeiger)
                     }
                   }
                  UnLock(Dirlock1)
                }
              }
            }
          UnLock(Dirlock)
        }
     }
    {* Return *}
