#include <exec/exec.h>
#include <dos/dos.h>
#include <stdio.h>
#include <stdlib.h>
#include "sc:ae/CmodGlue/doorheader.h"
#include <string.h>
#include "sc:ae/CmodGlue/glue.h"
#define gu getuserstring
#define sm sendmessage
#define pm prompt
void end(void);
void LastCommand(void);
void sr(char *s);


char oldname[100];
char newname[100];
char string[100];
struct User {
 char    Name[31],Pass[9],Location[30],PhoneNumber[13];
 USHORT  Slot_Number;
 USHORT  Sec_Status,
     Sec_Board,                   /* File or Byte Ratio */
     Sec_Library,                 /* Ratio              */
     Sec_Bulletin,                /* Computer Type      */
     Messages_Posted;
 /* Note ConfYM = the last msg you actually read, ConfRead is the same ?? */
 ULONG   NewSinceDate, ConfRead1, ConfRead2, ConfRead3, ConfRead4,
         ConfRead5;
 UWORD   XferProtocol, Filler2;
 UWORD   Lcfiles,BadFiles; 
 ULONG   AccountDate;
 UWORD   ScreenType, Filler1;
 char    Conference_Access[10];
 USHORT  Uploads, Downloads, ConfRJoin, Times_Called;
 long    Time_Last_On, Time_Used, Time_Limit, Time_Total;
 ULONG   Bytes_Download, Bytes_Upload, Daily_Bytes_Limit, Daily_Bytes_Dld;
 char    Expert;
 ULONG   ConfYM1, ConfYM2, ConfYM3, ConfYM4, ConfYM5, ConfYM6, ConfYM7,
         ConfYM8, ConfYM9;
 long    BeginLogCall;
 UBYTE   Protocol, UUCPA, LineLength, New_User;
 };

struct UserKeys {                 /* changes to UserKeys (RTS) */
 char    UserName[31];
 long    Number;
 UBYTE   New_User;
 UWORD   UPcps;              /* highest upload cps rate */
 UWORD   DNcps;              /* highest dnload cps rate */
 UWORD   Userflags;          /*                         */
 UWORD   baud_rate;          /* last online baud rate   */
 char    Pad[9];             /* ?? should be 15         */
};

struct User u;
struct UserKeys uk;
char source[100]; 
char dest[100];
main(int argc,char *argv[])
{
   FILE *fi;
   register int i;
   if(argc!=2)
   {
      printf(".-------------------------------------------------------.\n",1);
      printf("| Ami-Express AREAMGR Version 1.1 Written by ByteMaster |\n");
      printf("|       /X Development Team - The Silent Achievers      |\n");
      printf("`-------------------------------------------------------'\n");
      printf("\n");
      printf(" This is a (XIM) for AmiExpress 3.00+\n");
      printf("\n");
      exit(0);
 
   }
   Register(argv[1][0]-'0');
   gu(source,BB_LOCAL);
   strcpy(dest,source);
  
   i=1;
   sm("",1);
      sm("[33m.-------------------------------------------------------.[0m",1);
      sm("[33m| [36mAmi-Express [35mAREAMGR [36mVersion 1.1 Written by ByteMaster |[0m",1);
      sm("[33m|       [44m[36m/X[0m[36m Development Team - [33mThe Silent Achievers      |[0m",1);
      sm("[33m`-------------------------------------------------------'[0m",1);
      sm("",1);
      sm("",1);
   pm("[32mEnter AreaName to Change [36m>: [0m",oldname,9);
   pm("[32mEnter NewArea            [36m>: [0m",newname,9);
   strcat(source,"Access/AREA.");
   strcat(dest,"Access/AREA.");
   strcat(source,oldname);
   strcat(dest,newname);
   strcat(source,".info");
   strcat(dest,".info");
   Rename(source,dest);
   sm("[33mSearching[34m.....[0m",1);
   
   while(Load_Account(i,&u,&uk))
   {
     if(!stricmp(u.Conference_Access,oldname))
     {
    
       sprintf(string,"changing areaname for %s",u.Name);
       sm(string,1);
       strcpy(u.Conference_Access,newname);
       Save_Account(i,&u,&uk);
     }
     
     i++;
   }
   ShutDown();
   end();
}
void end(void)
{
  exit(0);
}
void LastCommand(void)
{
  sm("",1);
}
void sr(char *s)
{
  register int i;
  i=strlen(s)-1;
  while(i>-1)
  {
    if(*(s+i)<=32) *(s+i)='\0'; else break;
    i--;
  }
}