2
$Id: wvphelp.pas,v 1.5 2005/02/14 17:13:19 peter Exp $
3
This file is part of the Free Pascal Integrated Development Environment
4
Copyright (c) 2000 by Berczi Gabor
6
Help support for (.VPH) help files
8
See the file COPYING.FPC, included in this distribution,
9
for details about the copyright.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
**********************************************************************}
25
VPHFileSignature = 'HS';
28
TVPHFileHeader = packed record
29
SectionCount: byte; { #1 }
33
TVPHTopicEntry = packed record
38
PVPHTopicTable = ^TVPHTopicTable;
39
TVPHTopicTable = packed array[0..(MaxBytes div sizeof(TVPHTopicEntry))-1] of TVPHTopicEntry;
41
PVPHSectionTable = ^TVPHSectionTable;
42
TVPHSectionTable = packed array[0..4095] of longint;
44
PVPHHelpFile = ^TVPHHelpFile;
45
TVPHHelpFile = object(THelpFile)
46
constructor Init(AFileName: string; AID: word);
47
destructor Done; virtual;
49
function LoadIndex: boolean; virtual;
50
function ReadTopic(T: PTopic): boolean; virtual;
53
Header: TVPHFileHeader;
54
TopicTable: PVPHTopicTable;
55
TopicTableSize: longint;
56
SectionTable: PVPHSectionTable;
57
SectionTableSize: longint;
58
TopicBaseOfs: longint;
59
function ReadHeader: boolean;
60
function ReadTopicTable: boolean;
61
function ReadBlock(Data: pointer; DataSize: longint): boolean;
64
TVPHGetAttrColorProc = function(TextStyle, TextColor: byte; var Color: byte): boolean;
66
function DefVPHGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
68
const VPHGetAttrColor : TVPHGetAttrColorProc = {$ifdef fpc}@{$endif}DefVPHGetAttrColor;
70
procedure RegisterHelpType;
75
function DefVPHGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
77
DefVPHGetAttrColor:=false;
80
constructor TVPHHelpFile.Init(AFileName: string; AID: word);
83
if inherited Init(AID)=false then Fail;
84
F:=New(PFastBufStream, Init(AFileName, stOpenRead, HelpStreamBufSize));
86
if OK then OK:=(F^.Status=stOK);
92
SectionTableSize:=sizeof(SectionTable^[0])*Header.SectionCount;
93
GetMem(SectionTable,SectionTableSize);
94
F^.Read(SectionTable^,SectionTableSize);
101
TopicTableSize:=sizeof(TopicTable^[0])*Header.TotalTopics;
102
GetMem(TopicTable,TopicTableSize);
113
function TVPHHelpFile.ReadHeader: boolean;
116
F^.Read(Header,sizeof(Header));
117
OK:=(F^.Status=stOK);
121
function TVPHHelpFile.LoadIndex: boolean;
128
function TVPHHelpFile.ReadBlock(Data: pointer; DataSize: longint): boolean;
132
F^.Read(C,sizeof(C));
133
OK:=(F^.Status=stOK) and (C='�');
136
if Assigned(Data) then
137
F^.Read(Data^,DataSize)
139
F^.Seek(F^.GetPos+DataSize);
140
OK:=(F^.Status=stOK);
145
function TVPHHelpFile.ReadTopicTable: boolean;
148
OK:=ReadBlock(TopicTable,TopicTableSize);
149
TopicBaseOfs:=F^.GetPos;
153
function TVPHHelpFile.ReadTopic(T: PTopic): boolean;
160
destructor TVPHHelpFile.Done;
162
if Assigned(TopicTable) and (TopicTableSize>0) then
163
FreeMem(TopicTable{$ifndef FP},TopicTableSize{$endif});
165
if Assigned(SectionTable) and (SectionTableSize>0) then
166
FreeMem(SectionTable{$ifndef FP},SectionTableSize{$endif});
168
if Assigned(F) then Dispose(F, Done); F:=nil;
172
function CreateProc(const FileName,Param: string;Index : longint): PHelpFile; {$ifndef FPC}far;{$endif}
174
CreateProc:=New(PVPHHelpFile, Init(FileName,Index));
177
procedure RegisterHelpType;
179
RegisterHelpFileType({$ifdef FPC}@{$endif}CreateProc);
184
$Log: wvphelp.pas,v $
185
Revision 1.5 2005/02/14 17:13:19 peter