{= IMPORT.PAS ===========================================================
|
| Import - Sample Import Program for HyperMail<>WAMFormat, Version 0.0
|
| Jonathan Gillies, Code Masters, Inc.
|
|========================================================================
|
|========================================================================}
PROGRAM Import;

USES
  Crt, Dos;

CONST
  ProgramName  = 'IMPORT';
  ProgramDesc  = 'Sample Import Program for HyperMail<>WAMFromat';
  ProgramVers  = '0.0';

  ImportFileName : String[10] = 'IMPORT.TXT';
  WAMVersionSupported = '01.00';

{$I COMMON.INC}    { Common Functions/Procedures }
{$I WAM.TYP}       { WAM Format type declarations }
{$I TOOLS.INC}     { Tools used by WAM-IO.INC }
{$I WAM-IO.INC}    { WAM Format Utilities }

VAR
  ConversionTable : ConversionTableType;
  ConversionCount : Byte;
  SystemType      : Char;
  SystemId        : String[8];
  Junk            : String;
  WamMessage      : WamMessagePointer;
  WAMFile         : Text;
  AreaNumber      : Byte;
  MatchFound      : Boolean;

{$I NATIVE.INC}    { Native Message/File Declarations/Procs }

{ Variable declarations based on NATIVE.INC }
VAR
  NativeFile      : NativeFileType;
  NativeMessage   : NativeMessageType;
  NativeAreaPath  : NativeAreaPathType;
  NumberOfAreas   : Byte;
  MessagePointer  : PointerArrayType;

{------------------------------------------------------------------------
|
|
|------------------------------------------------------------------------}
PROCEDURE CheckDisk;
BEGIN
  IF IOResult = 0 THEN Exit;
  Writeln ('Disk error!');
  Halt(255);
END;

{------------------------------------------------------------------------
|
|
|------------------------------------------------------------------------}
PROCEDURE PositionMessagePointer (VAR NativeFile    : NativeFileType;
                                      MessageNumber : Word);
BEGIN
END;

{------------------------------------------------------------------------
|
|
|------------------------------------------------------------------------}
PROCEDURE WriteNativeFormatMessage (VAR NativeFile     : NativeFileType;
                                    VAR NativeMessage  : NativeMessageType);
BEGIN
END;

{------------------------------------------------------------------------
|
|
|------------------------------------------------------------------------}
PROCEDURE ConvertWAMToNative (VAR NativeMessage     : NativeMessageType;
                              VAR WAMFormatMessage  : WAMMessagePointer);
BEGIN
END;

{========================================================================
 ==========                         Main                         ========
 ========================================================================}
BEGIN
  Writeln;
  Writeln (ProgramName,' - ',ProgramDesc,', V',ProgramVers);
  Writeln;

  SystemId:= ParamStr(1);
  Junk:= ParamStr(2);
  SystemType:= UpCase(Junk[1]);
  IF (SystemId = '') OR (SystemType <> 'H') OR (SystemType <> 'N') THEN BEGIN
    Writeln ('Invalid command line parameters!');
    Writeln;
    Writeln ('Usage:  Import SystemId SystemType');
    Halt(255);
  END;

  { Read the Conversion Table }
  IF NOT ReadConversionTable (ConversionTable, ConversionCount,
                       SystemId, SystemType) THEN BEGIN
    Writeln (^g^g'Error reading conversion table!');
    Halt (255);
  END; { IF }

  { Read information about the native message bases }
  GetNativeInformation (NativeAreaPath, NumberOfAreas);

  { Open the IMPORT.TXT file for write }
  Assign (WAMFile, ImportFileName);
  {$I-} Reset (WAMFile); {$I+} CheckDisk;

  New (WAMMessage);

  WHILE NOT Eof(WAMFile) DO BEGIN
    ReadWAMMessage (WAMFile, WAMVersionSupported, WAMMessage);

    LocalAreaNumber (MatchFound, AreaNumber, WAMMessage^.Area,
                     SystemType, ConversionTable, ConversionCount);

    IF MatchFound THEN BEGIN
      ConvertWAMToNative (NativeMessage, WAMMessage);

      Assign (NativeFile, NativeAreapath[WAMMessage^.Area]);

      {$I-} Reset (NativeFile); {$I-} CheckDisk;
      {$I-} Seek (NativeFile, FileSize(NativeFile)); {$I-} CheckDisk;

      WriteNativeFormatMessage (NativeFile, NativeMessage);

      {$I-} Close (NativeFile); {$I-} CheckDisk;
    END; { IF }

  END; { WHILE }

  Dispose (WAMMessage);

  {$I-} Close (WAMFile); {$I+} CheckDisk;

END.

