#include "SysUser.h"

#include <link/io.h>

BOOL Area_Clearance(long area, char *name, char mode)
{
   BPTR            fp;
   char            filename[80];
   char            breakflag = FALSE;
   struct Msg_Log  Log;
   struct Msg_Area Area;

   if ((fp = Open(areafile, MODE_OLDFILE)) == EOF)    return(1);

   while(Read(fp,&Area,sizeof(Area))==sizeof(Area))
   {
      if (Area.Number==area)
      {
         if (Area.Flag&AUTO_ACCESS_AREA && User.User_Level>=Area.llevel && User.User_Level<=Area.ulevel)
         {
            Close(fp);
            return(0);
         }

         breakflag = TRUE;
         break;
      }

      if (breakflag)  break;
   }

   Close(fp);
 
   if (mode==0 || mode==2)
   {
      ASPrintf(NULL, filename,"MSG:%ld/User.Msg",area);
   }
   else
   {
      ASPrintf(NULL, filename,"FILE:%ld/User.File",area);
   }

   UnderScore(filename);
   strcpy(Log.Name, name);
   Upper(Log.Name);

   if (GetStruct(filename, (char *)&Log, sizeof(Log), 36)==-1)  
      return(1);
   
   return(0);
}
