/*ProfiPacket - packet radio terminal program
  Copyright (C) 1999  Alexander Feigl

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

  Author:

  Alexander Feigl
  Burachstraße 51

  D-88250 Weingarten

  Mail : Alexander.Feigl@gmx.de
*/



/*       MailGetVersion.c       Version 1.00

         Get the version of the bbs index file and return it in the 
         return code         

         Functions of this programme :

         - get the version of a bbs index
         - deleting #?.fwd files, which are now longer needed

         Arguments:
      
         MailGetVersion [BoxDataDir]

         Return Codes:

         20 - no valid index found
          0 - index version 0
          1 - index version 1
*/


#include <stdlib.h>
#include <string.h>
#include <stdio.h>


#include <exec/memory.h>
#include <exec/ports.h>
#include <exec/devices.h>
#include <exec/io.h>
#include <exec/semaphores.h>
#include <dos/exall.h>
#include <utility/tagitem.h>
 
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>

#include "Mail.h"


struct MailBase bbs_mailbase;


int main(int argc,char **argv)
{
 unsigned char path[512];
 unsigned char fname[512];
 
 BPTR oldindex;

 if (argc!=2) return (20);
 strcpy(path,argv[1]);
 
 strcpy(fname,path);
 AddPart(fname,"bbs.idx",512);
 oldindex=Open(fname,MODE_OLDFILE);
 if (oldindex==NULL) return(20);
 
 if (Read(oldindex,&bbs_mailbase,sizeof(struct MailBase))!=sizeof(struct MailBase))
  {
   Close(oldindex);
   return(20);
  }
 
 if (strncmp(bbs_mailbase.IDString,"BBSINDEX",8)!=0)
  {
   Close(oldindex);
   return(20);
  }

 if (bbs_mailbase.SizeofMail==sizeof(struct MailOld))
  {
   Close(oldindex);
   return(0);
  }
 Close(oldindex);
 return(bbs_mailbase.IndexVersion);
}

