#include <proto/dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlg/user.h>
#include <dlg/file.h>

#include <link/io.h>

#include <proto/dlg.h>

#include <pragmas/dlg.h>

extern struct Library  *DLGBase;
extern struct USER_DATA UserDat;
extern char           **SA;

BYTE CheckBatch(char *batchname,char *ext)

{ULONG         size;
 long          max;
 struct Batch *entry;
 char          current;
 char          filename[86];

 if (FileSize(batchname, &size)==-1)         return(-1);
 if (!(entry=(struct Batch *)malloc(size)))  return(-1);

 if (GetFirstStruct(batchname,(char *)entry,size)==-1)
    {free(entry);
     return(-1);
    }

 max = size / sizeof(struct Batch);

 for(current=0;current<max;current++)
    {ASPrintf(&UserDat,filename,"%s%s",(entry+current)->path,(entry+current)->filename);
     if (Exists(filename))  continue;
     AFPrintf(&UserDat,Output(),SA[3589],(entry+current)->filename);
     movmem(entry+current+1,entry+current,(max-current-1)*sizeof(struct Batch));
     max--;
     current--;
    }

 if (max != size/sizeof(struct Batch))
    {DeleteFile(batchname);
     AddStruct(batchname,(char *)entry,max*(sizeof(struct Batch)),1);
    }

 free(entry);
 return(0);
}
