//
//
//             NODE DATA MAKER!!!!
//
//


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

struct NodeData NodeData;

struct OldSystemData SD;
struct SystemExtra SE;
struct SystemInternal SI;


main()
{
 char s[255];
 printf("This program will create your new master NodeData.data\n");
 printf("to be used in the new master setup directory.\n");

 printf("Where's your Setup directory kept?: ");
 gets(s);
 if(Doit(s))
  {
   printf("\n\n\n");
   printf("Here's what to do next:\n");
   printf(" 1) Make a back up of your entire setup directory\n",s);
   printf(" 2) Copy the file [Ram:NodeDatax.data] over to your new master setup dir\n");
  }
 else printf("An Error occured....\n");
}


int Doit(char PATH [])
{
 int in1,in2,in3,out;
 char in1file[255],in2file[255],in3file[255],outfile[255];
 int stat,x=0;

 sprintf(in1file,"%sSETUP/Config.data",PATH);
 in1=Open(in1file,MODE_OLDFILE);
 if(in1==0)
  {
   printf("** ERROR, loading config.data\n");
   return(0);
  }

 sprintf(in2file,"%sSETUP/Custom.data",PATH);
 in2=Open(in2file,MODE_OLDFILE);
 if(in2==0)
  {
   printf("** ERROR, loading custom.data\n");
   return(0);
  }

 sprintf(in3file,"%sSETUP/Internal.data",PATH);
 in3=Open(in3file,MODE_OLDFILE);
 if(in3==0)
  {
   printf("** ERROR, loading internal.data\n");
   return(0);
  }

 stat=Read(in1,(char *)&SD,sizeof(struct OldSystemData));  // Old System Data  / Config.data
 if(stat!=sizeof(struct OldSystemData)) { Close(in1); return(0); }

 stat=Read(in2,(char *)&SE,sizeof(struct SystemExtra));  // Old System Extra / custom.data
 if(stat!=sizeof(struct SystemExtra)) { Close(in2); return(0); }

 stat=Read(in3,(char *)&SI,sizeof(struct SystemInternal));  // Old System Internal / Internal.data
 if(stat!=sizeof(struct SystemInternal)) { Close(in3); return(0); }

 sprintf(outfile,"RAM:NodeData-%d.data",SI.Door_Number,PATH);
 out=Open(outfile,MODE_NEWFILE);
 if(out==0)
  {
   printf("** ERROR, creating RAM:NodeDatax.Data\n");
   return(0);
  }

 setmem(&NodeData,sizeof(struct NodeData),NULL);

 strcpy(NodeData.TempULWorkPath      ,SD.TempWork);
 strcpy(NodeData.TextDirPath         ,SI.TextDir);
 strcpy(NodeData.DescribeDirPath     ,SI.DescribeDir);

 strcpy(NodeData.IconSize            ,SD.ICONSIZE);
 strcpy(NodeData.DeviceName          ,SD.DeviceName);
 strcpy(NodeData.Open                ,SD.Open);
 strcpy(NodeData.Reset               ,"");
 strcpy(NodeData.Ring                ,SD.Ring);
 strcpy(NodeData.Answer              ,SD.Answer);
 strcpy(NodeData.Busy                ,SD.Busy);
 strcpy(NodeData.OnHook              ,SD.OnHook);
 strcpy(NodeData.Escape              ,SD.Escape);

 strcpy(NodeData.LogOffScript        ,SD.Script);
 strcpy(NodeData.UploadScript        ,SI.UploadScript);

 NodeData.LocalMode                 = SI.LocalMode;
 NodeData.Serial_Shared             = SI.Serial_Shared;
 NodeData.Auto_Iconify              = SI.Auto_Iconify;
 NodeData.Hide_Node                 = SI.Hide_Node;
 NodeData.DTR                       = SI.DTR;
 NodeData.Wire_Mode                 = SI.Wire_Mode;
 NodeData.XON                       = SI.XON;
 NodeData.RAD_BOG                   = SI.RAD_BOG;
 NodeData.BackGround                = SI.BackGround;
 NodeData.FORCE                     = SI.FORCE;
 NodeData.Parse                     = SI.Parse;
 NodeData.FILEPROMPT                = SI.FILEPROMPT;
 NodeData.FLUSH                     = SI.FLUSH;
 NodeData.FUNCTION                  = SI.FUNCTION;
 NodeData.TIMEOT                    = SI.TIMEOT;

 NodeData.CallersLogStatus          = SD.Log;
 NodeData.CaptureLogStatus          = SD.Extra1;
 NodeData.DoorsLogStatus            = SD.Log;
 NodeData.DebugLogStatus            = SD.Extra2;
 NodeData.SysopLogStatus            = SD.Log;

 NodeData.CurrentNode               = SI.Door_Number;

 NodeData.SerialDeviceNumber        = SD.Unit;
 NodeData.BitPlanes                 = SD.Planes;
 NodeData.BBSPriority               = SD.NormalP;
 NodeData.FileTransferPriority      = SD.FileP;
 NodeData.Fixed_Link                = SD.Fixed_Link;

 NodeData.HighestBaudRate           = SD.L_Baud;
 NodeData.Sleeplogoff               = SE.Define[41];

  for(x=0;x<45;x++)
   {
    NodeData.Define[x]=SE.Define[x];
   }

 Write(out,(char *)&NodeData,sizeof(struct NodeData));
 Close(in1);
 Close(in2);
 Close(in3);
 Close(out);
 return(1);
}
