#include <exec/types.h>
#include <stdio.h>
#include <proto/all.h>

struct New
{
 char     FileName[13],
          Password[4],

          DateU[9],
          LastDateD[9],

          Uploader[31],
          Receiver[31]; // Only Used in F-Mail - Area 0.. Have 2 structs

 BYTE     Security;

 UBYTE    Access;
                  //  0x01  0x02   0x04   0x08  0x10   0x20    0x40  0x80
 BYTEBITS Flags;  // Active,Free,ExtDesc,DLock,ELock,Online --- 8 Togglable Bits

 ULONG Bytes;

 char     Line[12][45];
}New;

struct Old {
 char     FileName[13],
          Password[4],

          DateU[9],
          LastDateD[9],

          Uploader[31],
          Receiver[31]; // Only Used in F-Mail - Area 0.. Have 2 structs

 BYTE     Security;

 UBYTE    Access;
                  //  0x01  0x02  0x04
 BYTEBITS Flags;  // Active,Free,ExtDesc; --- 8 Togglable Bits

 ULONG Bytes;

 char     Line[8][45];
}Old;


main()
{
 char s[255];
 printf("This program will upgrade your catalog files\n");

 printf("Enter Path of catalog files?: ");
 gets(s);
 if( Doit(s) )
  {
   printf("\n\n\n");
  }
 else printf("Something happened, that wasn't suppose to....\n");
}


int Doit(char PATH [])
{
 int in,out;
 char FILEOUT[255];
 int stat,x=0,y;
 char FILEIN[255],date[255],string[255];


 for(y=0;y<40;y++)
  {
   sprintf(FILEIN,"%sCatalog.%d",PATH,y);
   if(access(FILEIN,0)==0)
    {
     in=Open(FILEIN,MODE_OLDFILE);
     if(in==0)
      {
       printf("*** Error, loading the catalog file\n");
       return 0;
      }
     sprintf(FILEOUT,"%sCatalog.%d-new",PATH,y);
     out=Open(FILEOUT,MODE_NEWFILE);
     if(out==0)
      {
       printf("*** Error, creating new catalog file.\n");
       Close(in);
       return 0;
      }
     while(1)
      {
       stat=Read(in,(char *)&Old,sizeof(struct Old));
       if(stat!=sizeof(struct Old)) break;
       setmem(&New,(LONG)sizeof(struct New),NULL);

       strcpy(New.FileName,Old.FileName);
       strcpy(New.Uploader,Old.Uploader);
       strcpy(New.Receiver,Old.Receiver);
       strcpy(New.Password,Old.Password);

       strcpy(New.DateU,Old.DateU);
       strcpy(New.LastDateD,Old.LastDateD);

       for(x=0;x<8;x++)
        {
         strcpy(New.Line[x],Old.Line[x]);
        }
       New.Access  =Old.Access;
       New.Security=Old.Security;
       New.Bytes   =Old.Bytes;

       New.Flags=Old.Flags;

       stat=Write(out,(char *)&New,sizeof(struct New));
      }
     Close(in);
     Close(out);
    }
  }
 exit(0);
}
