Begin cleanup. Rewrote lastread stuff

This commit is contained in:
mysticbbs 2012-09-26 16:49:06 -04:00
parent 3790e66463
commit 987ec8a430
1 changed files with 608 additions and 642 deletions

View File

@ -1,7 +1,7 @@
{$I M_OPS.PAS}
Unit BBS_MsgBase_Squish; Unit BBS_MsgBase_Squish;
{$I M_OPS.PAS}
Interface Interface
Uses Uses
@ -318,15 +318,16 @@ Destructor TMsgBaseSquish.Done;
Begin Begin
If SqInfo^.SqdOpened Then SqdClose; If SqInfo^.SqdOpened Then SqdClose;
If SqInfo^.SqiOpened Then SqiClose; If SqInfo^.SqiOpened Then SqiClose;
If SqInfo^.SqIAlloc > 0 Then If SqInfo^.SqIAlloc > 0 Then
If SqIdx <> Nil Then If SqIdx <> Nil Then
FreeMem(SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType)); FreeMem (SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType));
Dispose(FreeArray); Dispose (FreeArray);
Dispose(SqInfo); Dispose (SqInfo);
End; End;
Procedure TMsgBaseSquish.SetMsgPath(FN: String); Procedure TMsgBaseSquish.SetMsgPath (FN: String);
Begin Begin
SqInfo^.FN := FExpand(FN); SqInfo^.FN := FExpand(FN);
@ -379,8 +380,8 @@ End;
Function TMsgBaseSquish.SqiOpen: Boolean; Function TMsgBaseSquish.SqiOpen: Boolean;
Begin Begin
If Not SqInfo^.SqiOpened Then Begin If Not SqInfo^.SqiOpened Then Begin
Assign(SqInfo^.SqiFile, SqInfo^.FN + '.sqi'); Assign (SqInfo^.SqiFile, SqInfo^.FN + '.sqi');
// FileMode := 66; {fmReadWrite + fmDenyNone;}
If Not ioReset(SqInfo^.SqiFile, SizeOf(SqIdxType), fmReadWrite + fmDenyNone) Then If Not ioReset(SqInfo^.SqiFile, SizeOf(SqIdxType), fmReadWrite + fmDenyNone) Then
SqiOpen := False SqiOpen := False
Else Begin Else Begin
@ -389,7 +390,7 @@ Begin
End; End;
End Else End Else
SqiOpen := True; SqiOpen := True;
End; End;
Procedure TMsgBaseSquish.CloseMsgBase; Procedure TMsgBaseSquish.CloseMsgBase;
Begin Begin
@ -399,7 +400,7 @@ Begin
FileMode := fmRWDN; { shouldn't be needed... } FileMode := fmRWDN; { shouldn't be needed... }
End; End;
Function TMsgBaseSquish.CreateMsgBase(MaxMsg: Word; MaxDays: Word): Boolean; Function TMsgBaseSquish.CreateMsgBase (MaxMsg: Word; MaxDays: Word): Boolean;
Begin Begin
If Not SqInfo^.SqdOpened Then Begin If Not SqInfo^.SqdOpened Then Begin
FillChar(SqInfo^.SqBase, SizeOf(SqInfo^.SqBase), 0); FillChar(SqInfo^.SqBase, SizeOf(SqInfo^.SqBase), 0);
@ -667,28 +668,29 @@ End;
Procedure TMsgBaseSquish.LoadFree; Procedure TMsgBaseSquish.LoadFree;
Var Var
i : Word; Count : Word;
TmpFrame : SqFrameHdrType; TmpFrame : SqFrameHdrType;
TmpPos : LongInt; TmpPos : LongInt;
Begin Begin
For i := 1 to MaxFree Do Begin For Count := 1 to MaxFree Do Begin
FreeArray^[i].FreePos := 0; FreeArray^[Count].FreePos := 0;
FreeArray^[i].FreeSize := 0; FreeArray^[Count].FreeSize := 0;
End; End;
SqInfo^.FreeLoaded := True; SqInfo^.FreeLoaded := True;
i := 0; Count := 0;
TmpPos := SqInfo^.SqBase.FirstFree; TmpPos := SqInfo^.SqBase.FirstFree;
While ((TmpPos <> 0) and (i < MaxFree)) Do Begin While ((TmpPos <> 0) and (Count < MaxFree)) Do Begin
ReadVarFrame(TmpFrame, TmpPos); ReadVarFrame (TmpFrame, TmpPos);
Inc(i); Inc (Count);
FreeArray^[i].FreeSize := TmpFrame.FrameLength;
FreeArray^[i].FreePos := TmpPos; FreeArray^[Count].FreeSize := TmpFrame.FrameLength;
FreeArray^[Count].FreePos := TmpPos;
TmpPos := TmpFrame.NextFrame; TmpPos := TmpFrame.NextFrame;
End; End;
SqInfo^.HighestFree := i; SqInfo^.HighestFree := Count;
End; End;
Procedure TMsgBaseSquish.FindFrame (Var FL: LongInt; Var FramePos: LongInt); Procedure TMsgBaseSquish.FindFrame (Var FL: LongInt; Var FramePos: LongInt);
@ -750,36 +752,46 @@ Begin
End; End;
End; End;
Procedure TMsgBaseSquish.KillMsg(MsgNum: LongInt); Procedure TMsgBaseSquish.KillMsg (MsgNum: LongInt);
Var Var
i: Word; i : Word;
KillPos: LongInt; KillPos : LongInt;
IndexPos: LongInt; IndexPos : LongInt;
KillFrame: SqFrameHdrType; KillFrame : SqFrameHdrType;
TmpFrame: SqFrameHdrType; TmpFrame : SqFrameHdrType;
CurrMove: LongInt; CurrMove : LongInt;
AlreadyLocked: Boolean; AlreadyLocked : Boolean;
FreeCtr: Word; FreeCtr : Word;
Begin Begin
AlreadyLocked := SqInfo^.Locked; AlreadyLocked := SqInfo^.Locked;
If Not AlreadyLocked Then If Not AlreadyLocked Then
If LockMsgBase Then; If LockMsgBase Then;
If SqIdx = Nil Then If SqIdx = Nil Then
SqInfo^.Error := 999 SqInfo^.Error := 999
Else Begin Else Begin
i := 1; i := 1;
While ((i <= SqInfo^.SqBase.NumMsg) and (MsgNum <> SqIdx^[i].UMsgId)) Do While ((i <= SqInfo^.SqBase.NumMsg) and (MsgNum <> SqIdx^[i].UMsgId)) Do
Inc(i); Inc(i);
If MsgNum = SqIdx^[i].UMsgId Then Begin If MsgNum = SqIdx^[i].UMsgId Then Begin
IndexPos := i; IndexPos := i;
KillPos := SqIdx^[i].Ofs; KillPos := SqIdx^[i].Ofs;
ReadVarFrame(KillFrame, KillPos);
ReadVarFrame (KillFrame, KillPos);
If KillFrame.PrevFrame = 0 Then If KillFrame.PrevFrame = 0 Then
SqInfo^.SqBase.BeginFrame := KillFrame.NextFrame; SqInfo^.SqBase.BeginFrame := KillFrame.NextFrame;
If KillFrame.NextFrame = 0 Then If KillFrame.NextFrame = 0 Then
SqInfo^.SqBase.LastFrame := KillFrame.PrevFrame; SqInfo^.SqBase.LastFrame := KillFrame.PrevFrame;
KillFrame.FrameType := sqFrameFree; KillFrame.FrameType := sqFrameFree;
UnLinkFrame(KillFrame);
UnLinkFrame (KillFrame);
If ((SqInfo^.SqBase.FirstFree = 0) or (SqInfo^.SqBase.LastFree = 0)) Then Begin If ((SqInfo^.SqBase.FirstFree = 0) or (SqInfo^.SqBase.LastFree = 0)) Then Begin
SqInfo^.SqBase.FirstFree := KillPos; SqInfo^.SqBase.FirstFree := KillPos;
SqInfo^.SqBase.LastFree := KillPos; SqInfo^.SqBase.LastFree := KillPos;
@ -788,30 +800,43 @@ Begin
End Else Begin End Else Begin
KillFrame.NextFrame := 0; KillFrame.NextFrame := 0;
KillFrame.PrevFrame := SqInfo^.SqBase.LastFree; KillFrame.PrevFrame := SqInfo^.SqBase.LastFree;
ReadVarFrame(TmpFrame, SqInfo^.SqBase.LastFree);
ReadVarFrame (TmpFrame, SqInfo^.SqBase.LastFree);
TmpFrame.NextFrame := KillPos; TmpFrame.NextFrame := KillPos;
WriteVarFrame(TmpFrame, SqInfo^.SqBase.LastFree); WriteVarFrame(TmpFrame, SqInfo^.SqBase.LastFree);
SqInfo^.SqBase.LastFree := KillPos; SqInfo^.SqBase.LastFree := KillPos;
End; End;
WriteVarFrame(KillFrame, KillPos); WriteVarFrame(KillFrame, KillPos);
FreeCtr := 1; FreeCtr := 1;
While ((FreeCtr < MaxFree) and (FreeArray^[FreeCtr].FreePos <> 0)) Do While ((FreeCtr < MaxFree) and (FreeArray^[FreeCtr].FreePos <> 0)) Do
Inc(FreeCtr); Inc(FreeCtr);
If FreeArray^[FreeCtr].FreePos = 0 Then Begin If FreeArray^[FreeCtr].FreePos = 0 Then Begin
FreeArray^[FreeCtr].FreePos := KillPos; FreeArray^[FreeCtr].FreePos := KillPos;
FreeArray^[FreeCtr].FreeSize := KillFrame.FrameLength; FreeArray^[FreeCtr].FreeSize := KillFrame.FrameLength;
End; End;
If FreeCtr > SqInfo^.HighestFree Then If FreeCtr > SqInfo^.HighestFree Then
SqInfo^.HighestFree := FreeCtr; SqInfo^.HighestFree := FreeCtr;
Dec(SqInfo^.SqBase.NumMsg);
Dec(SqInfo^.SqBase.HighMsg); Dec (SqInfo^.SqBase.NumMsg);
Dec (SqInfo^.SqBase.HighMsg);
CurrMove := IndexPos; CurrMove := IndexPos;
While CurrMove <= SqInfo^.SqBase.NumMsg Do Begin While CurrMove <= SqInfo^.SqBase.NumMsg Do Begin
SqIdx^[CurrMove] := SqIdx^[CurrMove + 1]; SqIdx^[CurrMove] := SqIdx^[CurrMove + 1];
Inc(CurrMove); Inc (CurrMove);
End; End;
End; End;
End; End;
If Not AlreadyLocked Then If Not AlreadyLocked Then
If UnlockMsgBase Then; If UnlockMsgBase Then;
End; End;
@ -820,8 +845,10 @@ Procedure TMsgBaseSquish.ReadMsgHdr(FPos: LongInt); {Read msg hdr for frame at F
Var Var
NumRead: LongInt; NumRead: LongInt;
Begin Begin
Seek(SqInfo^.SqdFile, FPos + SqFSize); Seek (SqInfo^.SqdFile, FPos + SqFSize);
SqInfo^.Error := IoResult; SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then Begin If SqInfo^.Error = 0 Then Begin
If Not ioBlockRead(SqInfo^.SqdFile, SqInfo^.MsgHdr, SizeOf(SqMsgHdrType), NumRead) Then If Not ioBlockRead(SqInfo^.SqdFile, SqInfo^.MsgHdr, SizeOf(SqMsgHdrType), NumRead) Then
SqInfo^.Error := ioCode; SqInfo^.Error := ioCode;
@ -832,8 +859,10 @@ Procedure TMsgBaseSquish.WriteMsgHdr(FPos: LongInt); {Read msg hdr for frame at
Var Var
Res : LongInt; Res : LongInt;
Begin Begin
Seek(SqInfo^.SqdFile, FPos + SqFSize); Seek (SqInfo^.SqdFile, FPos + SqFSize);
SqInfo^.Error := IoResult; SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then Begin If SqInfo^.Error = 0 Then Begin
If Not ioBlockWrite(SqInfo^.SqdFile, SqInfo^.MsgHdr, SizeOf(SqMsgHdrType), Res) Then If Not ioBlockWrite(SqInfo^.SqdFile, SqInfo^.MsgHdr, SizeOf(SqMsgHdrType), Res) Then
SqInfo^.Error := ioCode; SqInfo^.Error := ioCode;
@ -844,8 +873,10 @@ Procedure TMsgBaseSquish.WriteText(FPos: LongInt); {Write text buffer for frame
Var Var
Res : LongInt; Res : LongInt;
Begin Begin
Seek(SqInfo^.SqdFile, FPos + SqFSize + SqMSize); Seek (SqInfo^.SqdFile, FPos + SqFSize + SqMSize);
SqInfo^.Error := IoResult; SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then Begin If SqInfo^.Error = 0 Then Begin
If Not ioBlockWrite(SqInfo^.SqdFile, SqInfo^.MsgChars, SqInfo^.TxtCtr, Res) Then If Not ioBlockWrite(SqInfo^.SqdFile, SqInfo^.MsgChars, SqInfo^.TxtCtr, Res) Then
SqInfo^.Error := ioCode; SqInfo^.Error := ioCode;
@ -865,14 +896,18 @@ End;
Procedure TMsgBaseSquish.ReadText(FPos: LongInt); Procedure TMsgBaseSquish.ReadText(FPos: LongInt);
Begin Begin
Seek(SqInfo^.SqdFile, FPos + SqFSize + SqMSize); Seek(SqInfo^.SqdFile, FPos + SqFSize + SqMSize);
SqInfo^.Error := IoResult; SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then Begin If SqInfo^.Error = 0 Then Begin
If SqInfo^.Frame.MsgLength > SqTxtBufferSize Then If SqInfo^.Frame.MsgLength > SqTxtBufferSize Then
BlockRead(SqInfo^.SqdFile, SqInfo^.MsgChars, SqTxtBufferSize) BlockRead(SqInfo^.SqdFile, SqInfo^.MsgChars, SqTxtBufferSize)
Else Else
BlockRead(SqInfo^.SqdFile, SqInfo^.MsgChars, SqInfo^.Frame.MsgLength); BlockRead(SqInfo^.SqdFile, SqInfo^.MsgChars, SqInfo^.Frame.MsgLength);
SqInfo^.Error := IoResult; SqInfo^.Error := IoResult;
End; End;
SqInfo^.TxtCtr := 1 + SqInfo^.Frame.ControlLength; SqInfo^.TxtCtr := 1 + SqInfo^.Frame.ControlLength;
SqInfo^.MsgDone := False; SqInfo^.MsgDone := False;
LastSoft := False; LastSoft := False;
@ -883,29 +918,27 @@ Begin
SqInfo^.TxtCtr := 0; SqInfo^.TxtCtr := 0;
End; End;
Procedure TMsgBaseSquish.DoString (Str: String); {Add string to message text} Procedure TMsgBaseSquish.DoString (Str: String);
Var Var
i: Word; Count : Word;
Begin Begin
i := 1; For Count := 1 to Length(Str) Do
While i <= Length(Str) Do Begin DoChar(Str[Count]);
DoChar(Str[i]);
Inc(i);
End;
End; End;
Procedure TMsgBaseSquish.DoChar (Ch: Char); {Add character to message text} Procedure TMsgBaseSquish.DoChar (Ch: Char); {Add character to message text}
Begin Begin
If SqInfo^.TxtCtr < SqTxtBufferSize Then Begin If SqInfo^.TxtCtr < SqTxtBufferSize Then Begin
Inc(SqInfo^.TxtCtr); Inc (SqInfo^.TxtCtr);
SqInfo^.MsgChars[SqInfo^.TxtCtr] := Ch; SqInfo^.MsgChars[SqInfo^.TxtCtr] := Ch;
End; End;
End; End;
Procedure TMsgBaseSquish.DoStringLn(Str: String); {Add string and newline to msg text} Procedure TMsgBaseSquish.DoStringLn(Str: String); {Add string and newline to msg text}
Begin Begin
DoString(Str); DoString (Str);
DoChar(#13); DoChar (#13);
End; End;
Procedure TMsgBaseSquish.KillExcess; Procedure TMsgBaseSquish.KillExcess;
@ -940,35 +973,49 @@ Var
AlreadyLocked : Boolean; AlreadyLocked : Boolean;
Begin Begin
DoChar(#0); DoChar(#0);
TmpDT.Year := strS2I(Copy(SqInfo^.StrDate,7,2)); TmpDT.Year := strS2I(Copy(SqInfo^.StrDate,7,2));
If TmpDT.Year > 79 Then If TmpDT.Year > 79 Then
Inc(TmpDT.Year, 1900) Inc (TmpDT.Year, 1900)
Else Else
Inc(TmpDT.Year, 2000); Inc (TmpDT.Year, 2000);
TmpDT.Month := strS2I(Copy(SqInfo^.StrDate,1,2)); TmpDT.Month := strS2I(Copy(SqInfo^.StrDate,1,2));
TmpDT.Day := strS2I(Copy(SqInfo^.StrDate,4,2)); TmpDT.Day := strS2I(Copy(SqInfo^.StrDate,4,2));
TmpDt.Hour := strS2I(Copy(SqInfo^.StrTime,1,2)); TmpDt.Hour := strS2I(Copy(SqInfo^.StrTime,1,2));
TmpDt.Min := strS2I(Copy(SqInfo^.StrTime, 4,2)); TmpDt.Min := strS2I(Copy(SqInfo^.StrTime, 4,2));
TmpDt.Sec := 0; TmpDt.Sec := 0;
TmpStr := FormattedDate(TmpDT, 'DD NNN YY ') + Copy(SqInfo^.StrTime, 1, 5) + ':00'; TmpStr := FormattedDate(TmpDT, 'DD NNN YY ') + Copy(SqInfo^.StrTime, 1, 5) + ':00';
PackTime(TmpDT, TmpDate);
PackTime (TmpDT, TmpDate);
SqInfo^.MsgHdr.DateWritten := (TmpDate shr 16) + ((TmpDate and $ffff) shl 16); SqInfo^.MsgHdr.DateWritten := (TmpDate shr 16) + ((TmpDate and $ffff) shl 16);
TmpDate := CurDateDos; TmpDate := CurDateDos;
SqInfo^.MsgHdr.DateArrived := (TmpDate shr 16) + ((TmpDate and $ffff) shl 16); SqInfo^.MsgHdr.DateArrived := (TmpDate shr 16) + ((TmpDate and $ffff) shl 16);
Str2AZ(TmpStr, 20, SqInfo^.MsgHdr.AZDate); Str2AZ(TmpStr, 20, SqInfo^.MsgHdr.AZDate);
AlreadyLocked := SqInfo^.Locked; AlreadyLocked := SqInfo^.Locked;
If Not AlreadyLocked Then If Not AlreadyLocked Then
If LockMsgBase Then; If LockMsgBase Then;
If SqInfo^.Locked Then Begin If SqInfo^.Locked Then Begin
MsgSize := SqInfo^.TxtCtr + SqMSize; MsgSize := SqInfo^.TxtCtr + SqMSize;
FrameSize := MsgSize; FrameSize := MsgSize;
FindFrame(FrameSize, FramePos); FindFrame (FrameSize, FramePos);
If SqInfo^.SqBase.LastFrame <> 0 Then Begin If SqInfo^.SqBase.LastFrame <> 0 Then Begin
ReadVarFrame(TmpFrame, SqInfo^.SqBase.LastFrame); ReadVarFrame (TmpFrame, SqInfo^.SqBase.LastFrame);
TmpFrame.NextFrame := FramePos; TmpFrame.NextFrame := FramePos;
WriteVarFrame(TmpFrame, SqInfo^.SqBase.LastFrame); WriteVarFrame(TmpFrame, SqInfo^.SqBase.LastFrame);
TmpFrame.PrevFrame := SqInfo^.SqBase.LastFrame; TmpFrame.PrevFrame := SqInfo^.SqBase.LastFrame;
End Else Begin End Else Begin
SqInfo^.SqBase.BeginFrame := FramePos; SqInfo^.SqBase.BeginFrame := FramePos;
@ -997,11 +1044,11 @@ Begin
SqInfo^.Error := 999; SqInfo^.Error := 999;
WriteMsg := 999; WriteMsg := 999;
End Else Begin End Else Begin
WriteVarFrame(TmpFrame, FramePos); WriteVarFrame (TmpFrame, FramePos);
WriteMsgHdr(FramePos); WriteMsgHdr (FramePos);
WriteText(FramePos); WriteText (FramePos);
Inc(SqInfo^.SqBase.NumMsg); Inc (SqInfo^.SqBase.NumMsg);
SqIdx^[SqInfo^.SqBase.NumMsg].Ofs := FramePos; SqIdx^[SqInfo^.SqBase.NumMsg].Ofs := FramePos;
SqIdx^[SqInfo^.SqBase.NumMsg].UMsgId := SqInfo^.SqBase.UID; SqIdx^[SqInfo^.SqBase.NumMsg].UMsgId := SqInfo^.SqBase.UID;
@ -1017,81 +1064,32 @@ Begin
WriteMsg := 0; WriteMsg := 0;
End; End;
If Not AlreadyLocked Then If Not AlreadyLocked Then
If UnLockMsgBase Then; If UnLockMsgBase Then;
End Else End Else
WriteMsg := 5; WriteMsg := 5;
End; End;
(* Function TMsgBaseSquish.GetString (MaxLen: Word): String;
Function TMsgBaseSquish.GetString (MaxLen : Word) : String;
Var
StartSoft : Boolean;
Str : String;
Ch : Char;
WLen : Byte;
WPos : Word;
Begin
StartSoft := LastSoft;
LastSoft := True;
WLen := 0;
WPos := 0;
Str := '';
While (Length(Str) < MaxLen) and (not SqInfo^.MsgDone) Do Begin
Ch := GetChar;
Case Ch of
#00,
#13 : Begin
LastSoft := True;
Break;
End;
#10,
#141: ;
#32 : If (Str <> '') or (Not StartSoft) Then Begin
Str := Str + Ch;
WLen := Length(Str);
WPos := SqInfo^.TxtCtr;
End Else
StartSoft := False;
Else
Str := Str + Ch;
End;
End;
If (Not (Ch in [#00, #13])) and (Not SqInfo^.MsgDone) Then
If WLen = 0 Then
Dec(SqInfo^.TxtCtr)
Else Begin
Str[0] := Chr(WLen);
SqInfo^.TxtCtr := WPos;
End;
GetString := Str;
End;
*)
Function TMsgBaseSquish.GetString(MaxLen: Word): String;
Var Var
WPos : Word; WPos : Word;
WLen : Byte; WLen : Byte;
StrDone : Boolean; StrDone : Boolean;
// TxtOver : Boolean;
StartSoft : Boolean; StartSoft : Boolean;
CurrLen : Word; CurrLen : Word;
// PPos : Word;
TmpCh : Char; TmpCh : Char;
Begin Begin
StrDone := False; StrDone := False;
CurrLen := 0; CurrLen := 0;
// PPos := SqInfo^.TxtCtr;
WPos := 0; WPos := 0;
WLen := 0; WLen := 0;
StartSoft := LastSoft; StartSoft := LastSoft;
LastSoft := True; LastSoft := True;
{ TmpCh := GetChar;}
While ((Not StrDone) And (CurrLen < MaxLen) And (Not SqInfo^.MsgDone)) Do Begin While ((Not StrDone) And (CurrLen < MaxLen) And (Not SqInfo^.MsgDone)) Do Begin
TmpCh := GetChar; TmpCh := GetChar;
Case TmpCh of Case TmpCh of
#00, #00,
#13 : Begin #13 : Begin
@ -1102,7 +1100,7 @@ Begin
#141: ; #141: ;
#32 : Begin #32 : Begin
If ((CurrLen <> 0) or (Not StartSoft)) Then Begin If ((CurrLen <> 0) or (Not StartSoft)) Then Begin
Inc(CurrLen); Inc (CurrLen);
WLen := CurrLen; WLen := CurrLen;
GetString[CurrLen] := TmpCh; GetString[CurrLen] := TmpCh;
WPos := SqInfo^.TxtCtr; WPos := SqInfo^.TxtCtr;
@ -1113,7 +1111,6 @@ Begin
Inc(CurrLen); Inc(CurrLen);
GetString[CurrLen] := TmpCh; GetString[CurrLen] := TmpCh;
End; End;
{ If Not StrDone Then TmpCh := GetChar;}
End; End;
If StrDone Then Begin If StrDone Then Begin
@ -1137,13 +1134,6 @@ Begin
EOM := (SqInfo^.TxtCtr >= SqInfo^.Frame.MsgLength) or (SqInfo^.MsgChars[SqInfo^.TxtCtr] = #0); EOM := (SqInfo^.TxtCtr >= SqInfo^.Frame.MsgLength) or (SqInfo^.MsgChars[SqInfo^.TxtCtr] = #0);
End; End;
(*
Function TMsgBaseSquish.WasWrap: Boolean;
Begin
WasWrap := LastSoft;
End;
*)
Function TMsgBaseSquish.GetChar: Char; Function TMsgBaseSquish.GetChar: Char;
Begin Begin
If (SqInfo^.TxtCtr >= SqInfo^.Frame.MsgLength) or (SqInfo^.MsgChars[SqInfo^.TxtCtr] = #0) Then Begin If (SqInfo^.TxtCtr >= SqInfo^.Frame.MsgLength) or (SqInfo^.MsgChars[SqInfo^.TxtCtr] = #0) Then Begin
@ -1151,11 +1141,11 @@ Begin
SqInfo^.MsgDone := True; SqInfo^.MsgDone := True;
End Else Begin End Else Begin
GetChar := SqInfo^.MsgChars[SqInfo^.TxtCtr]; GetChar := SqInfo^.MsgChars[SqInfo^.TxtCtr];
Inc(SqInfo^.TxtCtr); Inc(SqInfo^.TxtCtr);
End; End;
End; End;
Function TMsgBaseSquish.GetHighWater: LongInt; {Get high water umsgid} Function TMsgBaseSquish.GetHighWater: LongInt; {Get high water umsgid}
Begin Begin
GetHighWater := LongInt(SqInfo^.SqBase.HighWater); GetHighWater := LongInt(SqInfo^.SqBase.HighWater);
@ -1173,14 +1163,19 @@ Begin
If SqInfo^.SqiAlloc > 0 Then If SqInfo^.SqiAlloc > 0 Then
If SqIdx <> Nil Then If SqIdx <> Nil Then
FreeMem(SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType)); FreeMem(SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType));
SqInfo^.SqiAlloc := FileSize(SqInfo^.SqiFile) + 100; SqInfo^.SqiAlloc := FileSize(SqInfo^.SqiFile) + 100;
If SqInfo^.SqiAlloc > SqIdxArraySize Then If SqInfo^.SqiAlloc > SqIdxArraySize Then
SqInfo^.SqiAlloc := SqIdxArraySize ; SqInfo^.SqiAlloc := SqIdxArraySize;
GetMem(SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType));
GetMem (SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType));
If SqIdx = nil Then If SqIdx = nil Then
SqInfo^.Error := 999 SqInfo^.Error := 999
Else Begin Else Begin
Seek(SqInfo^.SqiFile, 0); Seek(SqInfo^.SqiFile, 0);
If IoResult = 0 Then Begin If IoResult = 0 Then Begin
If Not ioBlockRead(SqInfo^.SqiFile, SqIdx^, SqInfo^.SqiAlloc, NumRead) Then If Not ioBlockRead(SqInfo^.SqiFile, SqIdx^, SqInfo^.SqiAlloc, NumRead) Then
SqInfo^.Error := ioCode; SqInfo^.Error := ioCode;
@ -1196,8 +1191,9 @@ Begin
If SqIdx = nil Then If SqIdx = nil Then
SqInfo^.Error := 999 SqInfo^.Error := 999
Else Begin Else Begin
Seek(SqInfo^.SqiFile, 0); Seek (SqInfo^.SqiFile, 0);
Truncate(SqInfo^.SqiFile); Truncate (SqInfo^.SqiFile);
If IoResult = 0 Then Begin If IoResult = 0 Then Begin
If Not ioBlockWrite(SqInfo^.SqiFile, SqIdx^, SqInfo^.SqBase.NumMsg, Res) Then If Not ioBlockWrite(SqInfo^.SqiFile, SqIdx^, SqInfo^.SqBase.NumMsg, Res) Then
SqInfo^.Error := ioCode; SqInfo^.Error := ioCode;
@ -1209,30 +1205,32 @@ End;
Procedure TMsgBaseSquish.SeekFirst(MsgNum: LongInt); Procedure TMsgBaseSquish.SeekFirst(MsgNum: LongInt);
Begin Begin
SqInfo^.CurrIdx := 1; SqInfo^.CurrIdx := 1;
ReadIdx; ReadIdx;
While ((SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg) and
(MsgNum > LongInt(SqIdx^[SqInfo^.CurrIdx].UMsgId))) Do While ((SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg) and (MsgNum > LongInt(SqIdx^[SqInfo^.CurrIdx].UMsgId))) Do
SeekNext; SeekNext;
End; End;
Function TMsgBaseSquish.IdxHighest: LongInt; Function TMsgBaseSquish.IdxHighest: LongInt;
Var Var
i: Word; i : Word;
Tmp: LongInt; Tmp : LongInt;
Begin Begin
Tmp := 0; Tmp := 0;
i := 1; i := 1;
While i <= SqInfo^.SqBase.NumMsg Do Begin While i <= SqInfo^.SqBase.NumMsg Do Begin
If SqIdx^[i].UMsgId > Tmp Then Tmp := SqIdx^[i].UMsgId; If SqIdx^[i].UMsgId > Tmp Then Tmp := SqIdx^[i].UMsgId;
Inc(i); Inc(i);
End; End;
IdxHighest := Tmp; IdxHighest := Tmp;
End; End;
Function TMsgBaseSquish.GetMsgNum: LongInt; Function TMsgBaseSquish.GetMsgNum: LongInt;
Begin Begin
If ((SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg) and If ((SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg) and (SqInfo^.CurrIdx > 0)) Then
(SqInfo^.CurrIdx > 0)) Then
GetMsgNum := LongInt(SqIdx^[SqInfo^.CurrIdx].UMsgId) GetMsgNum := LongInt(SqIdx^[SqInfo^.CurrIdx].UMsgId)
Else Else
GetMsgNum := -1; GetMsgNum := -1;
@ -1244,33 +1242,33 @@ Begin
End; End;
Procedure TMsgBaseSquish.SeekPrior; Procedure TMsgBaseSquish.SeekPrior;
Begin Begin
If SqInfo^.CurrIdx > 1 Then If SqInfo^.CurrIdx > 1 Then
Dec(SqInfo^.CurrIdx) Dec(SqInfo^.CurrIdx)
Else Else
SqInfo^.CurrIdx := 0; SqInfo^.CurrIdx := 0;
End; End;
Function TMsgBaseSquish.SeekFound: Boolean; Function TMsgBaseSquish.SeekFound: Boolean;
Begin Begin
SeekFound := GetMsgNum >= 0; SeekFound := GetMsgNum >= 0;
End; End;
Function TMsgBaseSquish.GetIdxFramePos: LongInt; Function TMsgBaseSquish.GetIdxFramePos: LongInt;
Begin Begin
If SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg Then If SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg Then
GetIdxFramePos := SqIdx^[SqInfo^.CurrIdx].Ofs GetIdxFramePos := SqIdx^[SqInfo^.CurrIdx].Ofs
Else Else
GetIdxFramePos := -1; GetIdxFramePos := -1;
End; End;
Function TMsgBaseSquish.GetIdxHash: LongInt; Function TMsgBaseSquish.GetIdxHash: LongInt;
Begin Begin
If SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg Then If SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg Then
GetIdxHash := SqIdx^[SqInfo^.CurrIdx].Hash GetIdxHash := SqIdx^[SqInfo^.CurrIdx].Hash
Else Else
GetIdxHash := 0; GetIdxHash := 0;
End; End;
Function TMsgBaseSquish.IsLocal: Boolean; {Is current msg local} Function TMsgBaseSquish.IsLocal: Boolean; {Is current msg local}
Begin Begin
@ -1297,21 +1295,6 @@ Begin
IsFAttach := ((SqInfo^.MsgHdr.Attr and SqMsgFile) <> 0); IsFAttach := ((SqInfo^.MsgHdr.Attr and SqMsgFile) <> 0);
End; End;
//Function TMsgBaseSquish.IsReqRct: Boolean; {Is current msg request receipt}
//Begin
// IsReqRct := ((SqInfo^.MsgHdr.Attr and SqMsgRRQ) <> 0);
//End;
//Function TMsgBaseSquish.IsReqAud: Boolean; {Is current msg request audit}
//Begin
// IsReqAud := ((SqInfo^.MsgHdr.Attr and SqMsgArq) <> 0);
//End;
//Function TMsgBaseSquish.IsRetRct: Boolean; {Is current msg a return receipt}
//Begin
// IsRetRct := ((SqInfo^.MsgHdr.Attr and SqMsgCpt) <> 0);
//End;
Function TMsgBaseSquish.IsFileReq: Boolean; {Is current msg a file request} Function TMsgBaseSquish.IsFileReq: Boolean; {Is current msg a file request}
Begin Begin
IsFileReq := ((SqInfo^.MsgHdr.Attr and SqMsgFreq) <> 0); IsFileReq := ((SqInfo^.MsgHdr.Attr and SqMsgFreq) <> 0);
@ -1434,13 +1417,12 @@ Procedure TMsgBaseSquish.MsgStartUp;
Begin Begin
SqInfo^.CurrentFramePos := GetIdxFramePos; SqInfo^.CurrentFramePos := GetIdxFramePos;
SqInfo^.CurrentUID := SqIdx^[SqInfo^.CurrIdx].UMsgId; SqInfo^.CurrentUID := SqIdx^[SqInfo^.CurrIdx].UMsgId;
ReadFrame(SqInfo^.CurrentFramePos);
ReadMsgHdr(SqInfo^.CurrentFramePos); ReadFrame (SqInfo^.CurrentFramePos);
ReadMsgHdr (SqInfo^.CurrentFramePos);
End; End;
Procedure TMsgBaseSquish.MsgTxtStartUp; Procedure TMsgBaseSquish.MsgTxtStartUp;
//Var
// CFrame: LongInt;
Begin Begin
ReadText(SqInfo^.CurrentFramePos); ReadText(SqInfo^.CurrentFramePos);
End; End;
@ -1449,11 +1431,6 @@ Procedure TMsgBaseSquish.SetMailType(MT: MsgMailType);
Begin Begin
End; End;
//Function TMsgBaseSquish.GetSubArea: Word;
//Begin
// GetSubArea := 0;
//End;
Procedure TMsgBaseSquish.ReWriteHdr; Procedure TMsgBaseSquish.ReWriteHdr;
Var Var
AlreadyLocked : Boolean; AlreadyLocked : Boolean;
@ -1464,8 +1441,8 @@ Begin
If Not AlreadyLocked Then If Not AlreadyLocked Then
If LockMsgBase Then; If LockMsgBase Then;
WriteFrame(SqInfo^.CurrentFramePos); WriteFrame (SqInfo^.CurrentFramePos);
WriteMsgHdr(SqInfo^.CurrentFramePos); WriteMsgHdr (SqInfo^.CurrentFramePos);
i := 1; i := 1;
@ -1498,33 +1475,18 @@ Begin
NumberOfMsgs := 0; NumberOfMsgs := 0;
End; End;
Function TMsgBaseSquish.GetLastRead(UNum: LongInt): LongInt; Function TMsgBaseSquish.GetLastRead (UNum: LongInt) : LongInt;
Var
LRec: LongInt;
Begin Begin
If ((UNum + 1) * SizeOf(LRec)) > GetFileSize(SqInfo^.FN + '.sql') Then If LoadFilePos(SqInfo^.FN + '.sql', Result, 4, UNum * 4) <> 0 Then
GetLastRead := 0 Result := 0;
Else Begin
If LoadFilePos(SqInfo^.FN + '.sql', LRec, SizeOf(LRec), UNum * SizeOf(LRec)) = 0 Then
GetLastRead := LRec
Else
GetLastRead := 0;
End;
End; End;
Procedure TMsgBaseSquish.SetLastRead(UNum: LongInt; LR: LongInt); Procedure TMsgBaseSquish.SetLastRead (UNum: LongInt; LR: LongInt);
Var
LRec : LongInt;
Status : Word;
Begin Begin
Status := 0; If ((UNum + 1) * SizeOf(LR)) > GetFileSize(SqInfo^.FN + '.sql') Then
If ((UNum + 1) * SizeOf(LRec)) > GetFileSize(SqInfo^.FN + '.sql') Then Begin ExtendFile (SqInfo^.FN + '.sql', (UNum + 1) * SizeOf(LR));
Status := ExtendFile(SqInfo^.FN + '.sql', (UNum + 1) * SizeOf(LRec));
End; SaveFilePos (SqInfo^.FN + '.sql', LR, SizeOf(LR), UNum * SizeOf(LR));
LRec := LR;
If Status = 0 Then
Status := SaveFilePos(SqInfo^.FN + '.sql', LRec, SizeOf(LRec),
UNum * SizeOf(LRec));
End; End;
Function TMsgBaseSquish.GetMsgLoc: LongInt; Function TMsgBaseSquish.GetMsgLoc: LongInt;
@ -1537,14 +1499,17 @@ Begin
SeekFirst(ML); SeekFirst(ML);
End; End;
Procedure TMsgBaseSquish.YoursFirst(Name: String; Handle: String); Procedure TMsgBaseSquish.YoursFirst (Name: String; Handle: String);
Begin Begin
SqInfo^.CurrIdx := 0; SqInfo^.CurrIdx := 0;
ReadIdx; ReadIdx;
SqInfo^.SName := strUpper(Name); SqInfo^.SName := strUpper(Name);
SqInfo^.SHandle := strUpper(Handle); SqInfo^.SHandle := strUpper(Handle);
SqInfo^.HName := SqHashName(Name); SqInfo^.HName := SqHashName(Name);
SqInfo^.HHandle := SqHashName(Handle); SqInfo^.HHandle := SqHashName(Handle);
YoursNext; YoursNext;
End; End;
@ -1553,19 +1518,20 @@ Var
WasFound: Boolean; WasFound: Boolean;
Begin Begin
WasFound := False; WasFound := False;
Inc(SqInfo^.CurrIdx);
Inc (SqInfo^.CurrIdx);
While ((SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg) and (Not WasFound)) Do Begin While ((SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg) and (Not WasFound)) Do Begin
While ((SqIdx^[SqInfo^.CurrIdx].Hash <> SqInfo^.HName) And While ((SqIdx^[SqInfo^.CurrIdx].Hash <> SqInfo^.HName) And (SqIdx^[SqInfo^.CurrIdx].Hash <> SqInfo^.HHandle) And (SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg)) Do
(SqIdx^[SqInfo^.CurrIdx].Hash <> SqInfo^.HHandle) And
(SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg)) Do
Inc(SqInfo^.CurrIdx); Inc(SqInfo^.CurrIdx);
If SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg Then Begin If SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg Then Begin
MsgStartUp; MsgStartUp;
If ((Not IsRcvd) and
((strUpper(GetTo) = SqInfo^.SName) or (strUpper(GetTo) = SqInfo^.SHandle))) Then If ((Not IsRcvd) and ((strUpper(GetTo) = SqInfo^.SName) or (strUpper(GetTo) = SqInfo^.SHandle))) Then
WasFound := True WasFound := True
Else Else
Inc(SqInfo^.CurrIdx); Inc (SqInfo^.CurrIdx);
End; End;
End; End;
End; End;
@ -1605,7 +1571,7 @@ Begin
WriteMsg; WriteMsg;
*) *)
rewritehdr; ReWriteHdr;
End; End;
End. End.