{----------------------------------------------------------------------------}
{                                                                            }
{ Program:    PANTHER.PAS                                                    }
{ Purpose:    Allow PCBOARD BBS to run WILDCAT! door programs                }
{ Language:   Borland's Turbo Pascal Version 3.01                            }
{                                                                            }
{ Author:     Carl M. Evans                                                  }
{             Vervan's War Board BBS                                         }
{             P.O. Box 1176, Cucamonga, CA 91730  Voice: 714-989-7824        }
{             2400/1200/300 Baud (8-N-1 only)      Data: 714-989-7596        }
{                                                                            }
{ Notice:     This program is placed in the public domain and may be         }
{             freely used by anyone for any purpose.  When using this        }
{             code, please give credit to the original author and to         }
{             anyone who has subsequently improved or modified it.           }
{                                                                            }
{ Narrative:  This Turbo Pascal program allows a PCBOARD BBS to run          }
{             "door" programs which were designed to run under the           }
{             WILDCAT! BBS program. This routine reads the PCBOARD.SYS       }
{             file and creates a "dummy" CALLINFO.BBS file which can         }
{             be used by a WILDCAT! specific door program. The proper        }
{             method of using this routine is to place it somewhere on       }
{             your DOS path and call the program from whatever default       }
{             directory that is used by your WILDCAT! door program.          }
{             This routine assumes certain default values for the            }
{             location of the PCBOARD.SYS file as well as the name and       }
{             location of the CALLINFO.BBS file. The defaults are:           }
{                           C:\PCB\PCBOARD.SYS                               }
{                           CALLINFO.BBS                                     }
{             but you may override the defaults by entering the new          }
{             values on the command line when you call the program.          }
{             For example:                                                   }
{             PANTHER D:\PCB\PCBOARD.SYS D:\CONQUEST\CALLINFO.BBS            }
{                                                                            }
{                                                                            }
{ History:    Version 1.00, 04/22/88 - Original by Carl M. Evans             }
{                                                                            }
{             Version 1.10, 05/05/88 - Added a routine to trim trailing      }
{                                      blanks from PASSWORD and USERNAME.    }
{                                                                            }
{             Version 2.0, 08/30/88 - Modified to handle PCBoard 14.0 door   }
{                                     interface changes. This version does   }
{                                     NOT support PCBoard 12.1!!!            }
{                                                                            }
{                     2.1, 09/07/88 - Removed "safety" routines which caused }
{                                     problems on single node BBS's          }
{                                                                            }
{                     2.2, 09/07/88 - Corrected bug in Baud Rate conversion  }
{                                                                            }
{                                                                            }
{                                                                            }
{                                                                            }
{                                                                            }
{                                                                            }
{                                                                            }
{                                                                            }
{                                                                            }
{                                                                            }
{                                                                            }
{----------------------------------------------------------------------------}
{.PA}
Program PANTHER;
{$U-}
{$R+}
{$C-}
{$V-}
{============================================================================}
{ Declarations                                                               }
{============================================================================}

Const
  PCBoardFileDef  = 'C:\PCB\PCBOARD.SYS';
  WildcatFileDef  = 'CALLINFO.BBS';
  VersionNumber   = '2.2';

Type
  Ascii2          = array[1.. 2] of char;
  Ascii4          = array[1.. 4] of char;
  Ascii5          = array[1.. 5] of char;
  Ascii8          = array[1.. 8] of char;
  Ascii12         = array[1..12] of char;
  Ascii15         = array[1..15] of char;
  Ascii25         = array[1..25] of char;
  String2         = String[2];
  String4         = String[4];
  String5         = String[5];
  String6         = String[6];
  String12        = String[12];
  String25        = String[25];
  String80        = String[80];
  FileNameType    = String[80];

  PCBoardSysFileType  = Record         { 128 Bytes for PCBOARD version 14.0  }
         Display  : Ascii2;            { Sysop's Display ON/OFF              }
         Printer  : Ascii2;            { Sysop's Printer ON/OFF              }
         PageBell : Ascii2;            { Sysop's Page Bell ON/OFF            }
         CallAlarm: Ascii2;            { Caller Alarm ON/OFF                 }
         SysopNext: Char;              { Sysop "Next On" Flag                }
         ModemType: Ascii2;            { Error Correcting Modem YES/NO       }
         Graphics : Char;              { Graphics Mode of Caller             }
         NodeChat : Char;              { Available for Node Chat YES/NO      }
         BaudOpen : Ascii5;            { Baud Rate to Open Modem at          }
         BaudRate : Ascii5;            { "CONNECT" Baud Rate of Caller       }
         RecordNum: Integer;           { User's Database Record Number (MKI$)}
         FirstName: Ascii15;           { First Name of Caller                }
         Password : Ascii12;           { Password of Caller                  }
         TimeLogOn: Integer;           { Time User Logged On   (MKI$ minutes)}
         TimeUsed : Integer;           { Time Used Today       (MKI$ minutes)}
         LogOnStr : Ascii5;            { Time User Logged On       (HH:MM:SS)}
         TimeLimit: Integer;           { Daily Time Limit      (MKI$ minutes)}
         ByteLmtDL: Integer;           { Daily Download Limit  (MKI$ K-bytes)}
         ConfExit : Char;              { Conference (Area) User Exited From  }
         ConfFlags: Ascii5;            { Areas User Has "Joined" Today       }
         ConfScan : Ascii5;            { Areas User Has Scanned for New Mail }
         ConfTime : Integer;           { Area "Bonus" Time     (MKI$ minutes)}
         TimeCred : Integer;           { Upload Time Credit    (MKI$ minutes)}
         Language : Ascii4;            { Language Version Being Used         }
         Name     : Ascii25;           { Full Name of Caller   (First & Last)}
         TimeLeft : Integer;           { Session Time Remaining(MKI$ minutes)}
         NodeNum  : Char;              { BBS Node Number That Caller is Using}
         EventTime: Ascii5;            { Scheduled EVENT Time         (HH:MM)}
         EventFlag: Ascii2;            { Is EVENT Time Active?               }
         EventMove: Ascii2;            { Delay EVENT Until User Logs Off?    }
         MsgRecall: Ascii4;            { "Memorized" Message Number    (MKS$)}
         ComPortID: Char;              { Com Port Number (0, 1, 2)           }
         Reserved : Ascii2;            { Reserved for Future Use             }
       end;

Type
  Regpack         = Record
    Case Integer of
      1 : (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer);
      2 : (AL,AH,BL,BH,CL,CH,DL,DH : Byte);
    End;

Var
{ Variables used by WildCats!'s CALLINFO.BBS                                 }
  UserName        : String25;          { PCBoard limits UserName to 25 bytes }
  BaudRate        : Char;              { 0=2400, 1=300, 2=1200, 3=9600 baud  }
  TimeLeftToday   : String4;           { PCBoard (mins) => Wildcat! (mins)   }
  DisplayType     : String5;           { COLOR or MONO                       }
  Password        : String12;          { PCBoard limits Password to 12 bytes }
  TimeEnteredDoor : String5;           { Get from DOS                 (HH:MM)}
  TimeLoggedOn    : String5;           { HH:MM                               }
  DataBits        : Char;              { 7 or 8                              }
  WhereFrom       : String6;           { REMOTE or LOCAL only                }
  ComPort         : String4;           { COM1 or COM2 only                   }

{ Variables used to define disk files                                        }
  PCBoardFile     : File of PCBoardSysFileType;
  PCBoardFileName : FileNameType;
  PCBoardSysData  : PCBoardSysFileType;
  WildcatFile     : Text;
  WildcatFileName : FileNameType;

{ Miscellaneous Variables                                                    }
  Reg             : RegPack;
  Error           : Integer;
  Temp            : Char;
  I               : Integer;

{============================================================================}
{ Function to "pad" a date/time number to a 2-byte string                    }
{============================================================================}
Function Pad2(NumS:String2) :String2;

Begin { Pad2 }
  Case Length(NumS) of
    0            : Pad2 := '00';
    1            : Pad2 := '0' + NumS;
    2            : Pad2 := NumS;
  Else             Begin
                     Pad2[1] := NumS[1];
                     Pad2[2] := NumS[2];
                   End;
  End; {endcase}
End;  { Pad2  }

{============================================================================}
{ Function to convert a number to a string                                   }
{============================================================================}
Function Num2StrF(RawNumber,FieldLength:Integer) :String25;

Var
  TempString   : String25;

Begin { Num2StrF }
  Str(RawNumber:FieldLength,TempString);
  Num2StrF := TempString;
End;  { Num2StrF }

{============================================================================}
{ Function to trim leading blanks from a string                              }
{============================================================================}
Function TrimL(InpStr: String80): String80;

Var
  Len   : Integer;

Begin { TrimL }
  Len := Length(InpStr);
  I := 1;
  While (I <= Len) and (InpStr[I] = ' ') do
    I := I + 1;
    TrimL := Copy(InpStr,I,Len-I+1)
End;  { TrimL }

{============================================================================}
{ Function to trim trailing blanks from a string                             }
{============================================================================}
Function TrimR(InpStr: String80): String80;

Begin { TrimR }
  I := Length(InpStr);
  While (I >= 1) and (InpStr[I] = ' ') do
    I := I - 1;
    TrimR := Copy(InpStr,1,I)
End;  { TrimR }

{============================================================================}
{ Function to convert a string to upper case characters                      }
{============================================================================}
Function UpperCase(InpStr: String80): String80;

Var
  I : Integer;

Begin { UpperCase }
   For I := 1 to Length(InpStr) do
       UpperCase[I] := UpCase(InpStr[I]);
   UpperCase[0] := InpStr[0]
End;  { UpperCase }

{============================================================================}
{ Function to get the current time of day from DOS                           }
{============================================================================}
Function TimeOfDay: String5;

Var
  Reg            : Regpack;            {assign record}
  AH,
  AL,
  CH,
  CL,
  DH             : Byte;
  Hour,
  Min            : String2;

Begin { TimeOfDay }
  With Reg do begin
    AH := $2C;                         {initialize correct registers}
    AX := AH shl 8 + AL;
  End; {endwith}
  Intr($21,Reg);                       {call interrupt}
  With Reg do begin
    Str(CX shr 8,Hour);                {convert to string}
    Str(CX mod 256,Min);                      { " }
  End; {endwith}
  TimeOfDay := Pad2(Hour) + ':' + Pad2(Min);
End; { TimeOfDay }

{============================================================================}
{ Procedure to make an annoying BEEP sound                                   }
{============================================================================}
Procedure Beep;

Begin { Beep }
  Sound(450);
  Delay(500);
  NoSound;
End;  { Beep }

{============================================================================}
{ Procedure to display command line syntax for sysop when error occurs       }
{============================================================================}
Procedure FatalError;

Begin { FatalError }
  Beep;
  Writeln(' ');
  Writeln('FIRST PARAMETER (optional) -');
  Writeln(' The default is:  C:\PCB\PCBOARD.SYS');
  Writeln(' If you wish to override the default path for PCBOARD.SYS,');
  Writeln(' then specify a new path as the first parameter.');
  Writeln(' NOTE: Include the file name with the path.');
  Writeln(' ');
  Writeln('SECOND PARAMETER (optional) -');
  Writeln(' The default is:  CALLINFO.BBS');
  Writeln(' If you wish to override the default path for CALLINFO.BBS,');
  Writeln(' then specify a new path as the second parameter.');
  Writeln(' NOTE: Include the file name with the path.');
  Writeln(' ');
  Writeln('For Example:');
  Writeln('PANTHER D:\PCB\PCBOARD.SYS E:\DOORS\CONQUEST\CALLINFO.BBS');
  HALT(1);
End;  { FatalError }

{============================================================================}
{ Procedure to parse the command line                                        }
{============================================================================}
Procedure ParseCommandLine;

Begin { ParseCommandLine }
  If ParamCount > 0 then begin
    PCBoardFileName := ParamStr(1);
    PCBoardFileName := TrimL(PCBoardFileName);
    PCBoardFileName := TrimR(PCBoardFileName);
    PCBoardFileName := UpperCase(PCBoardFileName);
  End else begin
    PCBoardFileName := PCBoardFileDef;
  End; {endif}

  If ParamCount > 1 then begin
    WildcatFileName := ParamStr(2);
    WildcatFileName := TrimL(WildcatFileName);
    WildcatFileName := TrimR(WildcatFileName);
    WildcatFileName := UpperCase(WildcatFileName);
  End else begin
    WildcatFileName := WildcatFileDef;
  End; {endif}
End;  { ParseCommandLine }

{============================================================================}
{ Procedure to read the PCBOARD.SYS file                                     }
{============================================================================}
Procedure ReadPCBoardSysFile;

Begin { ReadPCBoardSysFile }
  Assign(PCBoardFile,PCBoardFileName);
  {$I-} Reset(PCBoardFile); {$I+}
  Error := IOresult;
  If Error <> 0 then begin
    Close(PCBoardFile);
    Writeln(' ');
    Writeln('ERROR: Could not find PCBOARD.SYS');
    FatalError;
  End; {endif}
  Read(PCBoardFile,PCBoardSysData);
  Close(PCBoardFile);
End;  { ReadPCBoardSysFile }

{============================================================================}
{ Procedure to translate PCBOARD.SYS to CALLINFO.BBS                         }
{============================================================================}
Procedure TranslateUserData;

Var
  Temp1,
  Temp2          : String5;
  LT             : Integer;

Begin { TranslateUserData }
  For I := 1 to 5 do Temp1[I] := PCBoardSysData.BaudRate[I];
  Temp2 := Temp1;
  Val(Temp2,I,Error);
  WhereFrom      := 'REMOTE';
  Case I of
    300          : BaudRate := '1';
    1200         : BaudRate := '2';
    2400         : BaudRate := '0';
    9600         : BaudRate := '3';
    14400        : BaudRate := '4';
    19200        : BaudRate := '4';
    Else           Begin
                     BaudRate := '0';
                     WhereFrom := 'LOCAL';
                   End;
  End; {endcase}

  Case PCBoardSysData.Graphics of
    '7'          : Begin
                     DisplayType := 'MONO ';
                     DataBits    := '7';
                   End;
    'N'          : Begin
                     DisplayType := 'MONO ';
                     DataBits    := '8';
                   End;
    Else           Begin
                    DisplayType := 'COLOR';
                    DataBits    := '8';
                   End;
  End; {endcase}

  UserName     := TrimR(PCBoardSysData.Name);

  PassWord     := TrimR(PCBoardSysData.Password);

  TimeLoggedOn := PCBoardSysData.LogOnStr;

  TimeEnteredDoor := TimeOfDay;

  LT           := PCBoardSysData.TimeLeft;
  If LT > 240 then LT := 240;
  TimeLeftToday := Num2StrF(LT,04);
  TimeLeftToday := TrimL(TimeLeftToday);

  TEMP           := PCBoardSysData.ComPortID;
  Case TEMP of
    '2'          : ComPort     := 'COM2';
    '1'          : ComPort     := 'COM1';
    Else           Begin
                     ComPort   := 'COM1';
                     WhereFrom := 'LOCAL';
                   End;
  End; {endcase}
End;  { TranslateUserData }

{============================================================================}
{ Procedure to create CALLINFO.BBS file                                      }
{============================================================================}
Procedure WriteWildcatFile;

Begin { WriteWildcatFile }
  Assign(WildcatFile,WildcatFileName);
  {$I-} Rewrite(WildcatFile); {$I+}
  Error := IOresult;
  If Error <> 0 then begin
    Writeln(' ');
    Writeln('ERROR: Illegal file name specified for output file');
    Close(WildcatFile);
    FatalError;
  End; {endif}
  Writeln(Wildcatfile,UserName);       { Caller's logon name                 }
  Writeln(Wildcatfile,BaudRate);       { Caller's logon baud rate            }
  Writeln(Wildcatfile,'Cucamonga, CA');{ Caller's city and state             }
  Writeln(Wildcatfile,'1');            { Caller's security level             }
  Writeln(Wildcatfile,TimeLeftToday);  { Caller's remaining time on the BBS  }
  Writeln(Wildcatfile,DisplayType);    { Caller's display type:COLOR or MONO }
  Writeln(Wildcatfile,Password);       { Caller's password                   }
  Writeln(Wildcatfile,'13');           { Caller's record number              }
  Writeln(Wildcatfile,'1000');         { Minutes that Caller has been on BBS }
  Writeln(Wildcatfile,TimeEnteredDoor);{ Time that Caller exited to the door }
  Writeln(Wildcatfile,TimeLoggedOn);   { Time that Caller logged on the BBS  }
  Writeln(Wildcatfile,'ABCDEFGHYZ');   { Message folders Caller can access   }
  Writeln(Wildcatfile,'0');            { Number of files downloaded today    }
  Writeln(Wildcatfile,'1000');         { How many D/L files allowed this day }
  Writeln(Wildcatfile,'9999');         { Download Kbytes allowed this call   }
  Writeln(Wildcatfile,'9999');         { Download Kbytes allowed this day    }
  Writeln(Wildcatfile,'714-989-7596'); { Caller's home phone number          }
  Writeln(Wildcatfile,'08/30/88 07:15');{ Date/Time of last call             }
  Writeln(Wildcatfile,'NOVICE');       { Caller's default HELP level         }
  Writeln(Wildcatfile,'N');            { Caller's default transfer protocol  }
  Writeln(Wildcatfile,'08/30/88');     { Date of last search for NEW files   }
  Writeln(Wildcatfile,'333');          { Total time logged on                }
  Writeln(Wildcatfile,'23');           { Caller's lines per page setting     }
  Writeln(Wildcatfile,'13');           { Last message read by Caller         }
  Writeln(Wildcatfile,'3');            { Total uploads made by this Caller   }
  Writeln(Wildcatfile,'9999');         { Total downloads made by this Caller }
  Writeln(Wildcatfile,DataBits);       { Com setting: 7 or 8 databits/word   }
  Writeln(Wildcatfile,WhereFrom);      { REMOTE or LOCAL                     }
  Writeln(Wildcatfile,ComPort);        { Com port to use: COM1 or COM2       }
  Writeln(Wildcatfile,'01/03/87');     { Caller's birthdate                  }
  Close(WildcatFile);
End;  { WriteWildcatFile }

{============================================================================}
{ Main Program                                                               }
{============================================================================}

Begin
  Writeln('');
  Writeln('PANTHER version ' + VersionNumber +
   ' Converts PCBOARD.SYS 14.0 to CALLINFO.BBS');
  Writeln('');
  Writeln('[ A PCBoard 14.0 utility from Vervan' + Chr(39) +
    's War Board (714) 989-7596 ]');
  Writeln('');
  ParseCommandLine;
  ReadPCBoardSysFile;
  TranslateUserData;
  WriteWildcatFile;
End.

{===[ END OF PROGRAM ]=======================================================}
