#include <stdio.h>
#include <stdlib.h>
#include <dlg/user.h>

#include <proto/dos.h>
#include <proto/dlg.h>

#include <link/io.h>

#include <pragmas/dlg.h>

extern struct Library *DLGBase;

BOOL RemoveCredit(char *from,LONG size,struct USER_DATA *user,char *curname)

{char             filename[54];
 struct USER_DATA tempuser;

 /* If it is the current user just */
 if (curname && !(Stricmp(from, curname)))
    {if (user->Bytes_Uploaded > size)
         user->Bytes_Uploaded -= size;
       else
         user->Bytes_Uploaded =   0;

     if (user->Files_Uploaded)
         user->Files_Uploaded--;

     return(TRUE);
    }

 ASPrintf(NULL, filename, "USER:%s/User.data", from);
 UnderScore(filename);

 if (GetFirstStruct(filename,(char *)&tempuser,sizeof(tempuser))==-1)
     return(FALSE);

 if (tempuser.Bytes_Uploaded >=size)
     tempuser.Bytes_Uploaded -= size;
   else
     tempuser.Bytes_Uploaded  =  0;

 if (tempuser.Files_Uploaded)
     tempuser.Files_Uploaded--;

 DeleteFile(filename);
 if (AddStruct(filename,(char *)&tempuser,sizeof(struct USER_DATA),1)==-1)
     return(FALSE);

 return(TRUE);
}
