{MKOpen - Open a message area using a MsgAreaId
Copyright 1993 by Mark May (1:110/290;maym@dmapub.dma.org)
Changes (c) 1999-2000 by Andre Grueneberg (2:2411/525;andre@grueneberg.de)
Changes (c) 1999 by Vadim Rumyantsev (2:5030/48.4)
Changes (c) 1998-2000 by Bernhard R. Link (2:2476/841.64;brl@gmx.de)
Changes (c) 2001 by Oliver Kopp (2:2471/1464;olly98@users.sourceforge.net)
****************************************************************************
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
****************************************************************************}

(* $Id: mkopen.pas,v 1.3 2001/04/15 13:24:43 olly98 Exp $ *)

Unit MKOpen;

{$I platform.inc}
{$I mkglobal.inc}

Interface

Uses MKMsgAbs, aString;

Function OpenMsgArea(Var Msg: AbsMsgPtr; Const MsgAreaId: OpenString): Boolean;
Function OpenOrCreateMsgArea(Var Msg: AbsMsgPtr; Const MsgAreaId: OpenString; MaxMsg, MaxDays:Word): Boolean;
Function CloseMsgArea(Var Msg: AbsMsgPtr): Boolean;
Function InitMsgPtr(Var Msg: AbsMsgPtr; Const MsgAreaId: OpenString): Boolean;
Function DoneMsgPtr(Var Msg: AbsMsgPtr): Boolean;

Implementation


Uses MKMsgHud, MKMsgFid, MKMsgSqu, MKMsgJam, MKMsgEzy;

{ Area ids begin with identifier for msg base type }
{ The following characters are already reserved    }
{   B = PC-Board            }
{*  E = Ezycomm             }
{*  F = Fido *.Msg          }
{*  H = Hudson              }
{   I = ISR - msg fossil    }
{*  J = JAM                 }
{   M = MK-Merlin           }
{   P = *.PKT               }
{   Q = QWK/REP             }
{   R = Renegade            }
{*  S = Squish              }
{   W = Wildcat             }

{only those marked with a * are suppored}


Function OpenMsgArea(Var Msg: AbsMsgPtr; Const MsgAreaId: OpenString): Boolean;
  Begin
  If InitMsgPtr(Msg, MsgAreaId) Then
    Begin
    OpenMsgArea := True;
    If Msg^.OpenMsgBase <> 0 Then
      Begin
      OpenMsgArea := False;
      If DoneMsgPtr(Msg) Then;
      End;
    End
  Else
    OpenMsgArea := False;
  End;


Function OpenOrCreateMsgArea(Var Msg: AbsMsgPtr; Const MsgAreaId: OpenString; MaxMsg, MaxDays:word): Boolean;
  Begin
  If InitMsgPtr(Msg, MsgAreaId) Then
    Begin
    OpenOrCreateMsgArea := True;
    If Not Msg^.MsgBaseExists Then
      If Not Msg^.CreateMsgBase(MaxMsg, MaxDays) = 0 Then
        OpenOrCreateMsgArea := False;
    If Msg^.OpenMsgBase <> 0 Then
      Begin
      OpenOrCreateMsgArea := False;
      If DoneMsgPtr(Msg) Then;
      End;
    End;
  End;


Function CloseMsgArea(Var Msg: AbsMsgPtr): Boolean;
  Begin
  If Msg <> Nil Then
    Begin
    CloseMsgArea := (Msg^.CloseMsgBase = 0);
    If DoneMsgPtr(Msg) Then;
    End
  Else
    CloseMsgArea := False;
  End;


(*
  Todo:
    Check for maximum length of OpenString --> PathString could possibly be not long enough
*)

Function InitMsgPtr(Var Msg: AbsMsgPtr; Const MsgAreaId: OpenString): Boolean;
  Begin
  Msg := Nil;
  InitMsgPtr := True;
  Case UpCase(MsgAreaId[1]) of
    'H': Msg := New(HudsonMsgPtr, Init);
    'S': Msg := New(SqMsgPtr, Init);
    'F': Msg := New(FidoMsgPtr, Init);
    'J': Msg := New(JamMsgPtr, Init);
    'E': Msg := New(EzyMsgPtr, Init);
    Else
      InitMsgPtr := False;
    End;
  If Msg <> Nil Then
    Msg^.SetMsgBasePath(Copy(MsgAreaId, 2, Length(MsgAreaId)-1));
  End;


Function DoneMsgPtr(Var Msg: AbsMsgPtr): Boolean;
  Begin
  If Msg <> Nil Then
    Dispose(Msg, Done);
  Msg := Nil;
  DoneMsgPtr:=True;
  End;

End.




