Program Convert; { Program Code: Hostile }
Uses CRT,DOS;
Var
{ WWIV variables + a few RBBS ones }
   Year,Mon,Day,DW, Hour, Min,Sec,S100 : Word;
   TC: Longint; {used in calculating TimeCalled}
{  UserNumber:       }
   UserAlias:  String[20];
   Username:   String[25];
{  UserCall:         }
{  UserAge:          }
{  UserSex:          }
{  UserGold:         }
{  UserLogonDate:    }
{  UserColumn:       }
{  UserWidth:        }
{  UserSecLev:       }
{  CoSysop:          }
{  Sysop:            }
{  RemoteLocal:      }
   UserTimeLeft: LongInt;
{  GFilesdir:        }
{  DataDir:          }
{  CallerLog:        }
   BaudRate: String[4];
   Comport: Shortint;
   BBSName: String[25];
   BBSSysop: String[25];
   TimeCalled: Longint;
{  TimeOn: Longint;  }
{  UploadK:          }
{  Uploads:          }
{  DownloadK:        }
{  Downloads:        }
   Parity: String[3];
{------}
{ RBBS Variables }
   FirstName,LastName: String[15];
   SecondsLeft: Real;
   DataSpeed: Integer; {Baud Rate, but that's used as a string}
   Line: String[30];
   ANSI: Boolean;
{------}
   ChainName, RBBSname: text; {Output and Input variables}
   Blank: String[1]; {used for skipping lines and reading single chars}
   I: Integer;
   Error: Integer; {Error Codes}

Procedure Copyright;
Begin
Clrscr;
HighVideo;
Write ('RBBS <---> WWIV');
Lowvideo;
Writeln (' File Converter');
Writeln;
Write ('Copyright 1989 ');
HighVideo;
Write ('Don Kitchen');
LowVideo;
Write (' c/o ');
HighVideo;
Writeln ('MiWare, Inc.');
LowVideo;
Writeln ('MiWare support BBS: ');
Writeln;
HighVideo;
Writeln ('RBBS Delta  /  (517) 631-2849');
LowVideo;
End;


Procedure FatalError;
Var Msg: String;
Begin
Msg := 'Unknown Error';
Case Error of
  2: Msg :=  'Input File Not Found';
  3: Msg :=  'Path Not Found';
  4,5,6,12: Msg :=  'Invalid Access 1)Too many files 2)Read only 3)Misc error';
  15: Msg := 'Invalid Drive';
  100,101: Msg := 'Disk Error';
  104,105: Msg := 'Invalid File Names';
End;
If (Error >= 150) and (Error <= 162) then msg := 'Check Device';
Writeln (Msg);
Halt (1);
End;

Procedure ReadRBBS;
Begin
{$I-} Reset (RBBSName); {$I+}
Error := IOResult;
If Error <> 0 then Fatalerror;
{ Read from DORINFO1.DEF }
Readln (RBBSName, BBSName);
Readln (RBBSName, BBSSysop);
Readln (RBBSName, UserName);
BBSSysop := BBSSysop + ' ' + UserName;
For I := 1 to 4 do Read (RBBSName, Blank);
  BaudRate := '';Blank := '';
  ComPort := ord(Blank[1]) - 48;
Readln (RBBSname, Blank);
For I := 1 to 4 do
Begin
  Read (RBBSName, Blank);
  BaudRate := BaudRate + Blank;
End;
For I := 1 to 7 do Read (RBBSName, Blank);
  Parity := Blank;
For I := 1 to 2 do Read (RBBSName, Blank);
  Parity := Blank + Parity;
For I := 1 to 2 do Read (RBBSName, Blank);
  Parity := Parity + Blank;
Readln (RBBSName, Blank);
Readln (RBBSName, Blank);
Readln (RBBSName, UserAlias);
Readln (RBBSName, UserName);
  UserName := UserAlias + ' ' + UserName;
For I := 1 to 3 do Readln (RBBSName, Blank);
Readln (RBBSname, UserTimeLeft);
  UserTimeLeft := UserTimeLeft * 60;
Close (RBBSName);
End;

Procedure WriteRBBS;
Begin
{$I-} Rewrite (RBBSName); {$I+}
Error := IOResult;
If Error <> 0 then Fatalerror;
Writeln (RBBSName,BBSName);
Begin
  I := 0;
  While (BBSSysop[I] <> ' ') and not (I > Length(BBSSysop)) do Inc(I);
Writeln (RBBSName,Copy(BBSSysop,1,I-1));
Writeln (RBBSName,Copy(BBSSysop,I+1,20));
Writeln (RBBSName,'COM',Comport);
Write (RBBSName,Dataspeed, ' BAUD,',Copy(Parity,2,1));
Writeln (RBBSName,',',Copy(Parity,1,1),',',Copy(Parity,3,1));
Writeln (RBBSName,' 7 ');
Writeln (RBBSName,FirstName);
Writeln (RBBSName,LastName);
Writeln (RBBSName, 'MIDLAND, MI             ');
Write (RBBSName,' ');
If ANSI then writeln (RBBSName,'3 ') else Writeln (RBBSName,'1 ');
Writeln (RBBSName,' 20 ');
Writeln (RBBSName,' ',Trunc(SecondsLeft/60),' ');
Writeln (RBBSName,' 0 ');
End;
Close (RBBSName);
End;

Procedure WriteChain;
Begin
{$I-} Rewrite (ChainName); {$I+}
Error := IOResult;
If Error <> 0 then FatalError;
{ Write CHAIN.TXT information }
Writeln (ChainName,'1');
Writeln (ChainName,UserAlias);
Writeln (ChainName,UserName);
Writeln (ChainName,'');
Writeln (ChainName,'21');
Writeln (ChainName,'M');
Writeln (ChainName,'  16097.00');
  GetDate (Year,Mon,Day,DW);
Writeln (ChainName,Mon,'/',Day,'/',Year-1900);
Writeln (ChainName,'80');
Writeln (ChainName,'25');
Writeln (ChainName,'20');
Writeln (ChainName,'0');
Writeln (ChainName,'0');
Writeln (ChainName,'0');
Writeln (ChainName,'1');
Writeln (ChainName,UserTimeLeft:7,'.00');
Writeln (ChainName,'E:\TEMP\');
Writeln (ChainName,'E:\TEMP\');
Writeln (ChainName,'Junk.log');
Writeln (ChainName, BaudRate);
Writeln (ChainName, ComPort);
Writeln (ChainName, BBSName);
Writeln (ChainName, BBSSysop);
  GetTime (Hour,Min,Sec,S100);
  TC := Hour;
  TC := TC * 3600;
  TimeCalled := TC + Sec - 120;
  TC := Min;
  TC := TC * 60;
  TimeCalled := TimeCalled + TC;
Writeln (ChainName, TimeCalled);
Writeln (ChainName, '120');
Writeln (ChainName, '0');
Writeln (ChainName, '0');
Writeln (ChainName, '0');
Writeln (ChainName, '0');
Writeln (ChainName, Parity);
Close (ChainName);
End;

Procedure ReadChain;
Begin
{$I-} Reset (ChainName); {$I+}
Error := IOResult;
If Error <> 0 then Fatalerror;
Readln (ChainName, Blank);
Readln (ChainName, Blank);
Readln (ChainName, Line);
Begin
  I := 1;
  While Line[I] <> ' ' do Inc(I);
  Firstname := Copy(Line,1,I-1);
  Lastname := Copy(Line,I+1,15);
End;
For I := 1 to 10 do Readln (ChainName, Blank);
Readln (ChainName, Blank);
If Blank = '1' then ANSI := True;
Readln (ChainName, Blank);
Readln (ChainName, SecondsLeft);
For I := 1 to 3 do Readln (ChainName, Blank);
Readln (ChainName, DataSpeed);
Readln (ChainName, ComPort);
Readln (ChainName, BBSName);
Readln (ChainName, BBSSysop);
For I := 1 to 6 do Readln (ChainName, Blank);
Readln (ChainName, Parity);
Close (ChainName);
End;

Begin
DirectVideo := False;
Ansi := False;
Copyright;
  Assign (RBBSName,'DORINFO1.DEF');
  Assign (ChainName, 'CHAIN.TXT');
Blank := Paramstr(1);
If Upcase(Blank[1]) = 'R' then
Begin
  ReadRBBS;
  WriteChain;
  Halt (0);
End;
If Upcase(Blank[1]) = 'W' then
Begin
  ReadChain;
  WriteRBBS;
  Halt (0);
End;
Begin
  Writeln;
  Writeln ('parameters-Host: R)BBS W)WIV');
  Halt (1);
End;
End.
