~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to ide/wvphelp.pas

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2005-05-30 11:59:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050530115910-x5pbzm4qqta4i94h
Tags: 2.0.0-2
debian/fp-compiler.postinst.in: forgot to reapply the patch that
correctly creates the slave link to pc(1).  (Closes: #310907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
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
 
5
 
 
6
    Help support for (.VPH) help files
 
7
 
 
8
    See the file COPYING.FPC, included in this distribution,
 
9
    for details about the copyright.
 
10
 
 
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.
 
14
 
 
15
 **********************************************************************}
 
16
{$R-}
 
17
unit WVPHelp;
 
18
 
 
19
interface
 
20
 
 
21
uses Objects,
 
22
     WUtils,WHelp;
 
23
 
 
24
const
 
25
      VPHFileSignature = 'HS';
 
26
 
 
27
type
 
28
      TVPHFileHeader = packed record
 
29
        SectionCount: byte; { #1 }
 
30
        TotalTopics : word;
 
31
      end;
 
32
 
 
33
      TVPHTopicEntry = packed record
 
34
        TopicOfs   : word;
 
35
        Dunno      : byte;
 
36
      end;
 
37
 
 
38
      PVPHTopicTable = ^TVPHTopicTable;
 
39
      TVPHTopicTable = packed array[0..(MaxBytes div sizeof(TVPHTopicEntry))-1] of TVPHTopicEntry;
 
40
 
 
41
      PVPHSectionTable = ^TVPHSectionTable;
 
42
      TVPHSectionTable = packed array[0..4095] of longint;
 
43
 
 
44
      PVPHHelpFile = ^TVPHHelpFile;
 
45
      TVPHHelpFile = object(THelpFile)
 
46
        constructor Init(AFileName: string; AID: word);
 
47
        destructor  Done; virtual;
 
48
      public
 
49
        function    LoadIndex: boolean; virtual;
 
50
        function    ReadTopic(T: PTopic): boolean; virtual;
 
51
      private
 
52
        F: PStream;
 
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;
 
62
      end;
 
63
 
 
64
      TVPHGetAttrColorProc = function(TextStyle, TextColor: byte; var Color: byte): boolean;
 
65
 
 
66
function DefVPHGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
 
67
 
 
68
const VPHGetAttrColor : TVPHGetAttrColorProc = {$ifdef fpc}@{$endif}DefVPHGetAttrColor;
 
69
 
 
70
procedure RegisterHelpType;
 
71
 
 
72
implementation
 
73
 
 
74
 
 
75
function DefVPHGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
 
76
begin
 
77
  DefVPHGetAttrColor:=false;
 
78
end;
 
79
 
 
80
constructor TVPHHelpFile.Init(AFileName: string; AID: word);
 
81
var OK: boolean;
 
82
begin
 
83
  if inherited Init(AID)=false then Fail;
 
84
  F:=New(PFastBufStream, Init(AFileName, stOpenRead, HelpStreamBufSize));
 
85
  OK:=F<>nil;
 
86
  if OK then OK:=(F^.Status=stOK);
 
87
  if OK then
 
88
  begin
 
89
    OK:=ReadHeader;
 
90
    if OK then
 
91
    begin
 
92
      SectionTableSize:=sizeof(SectionTable^[0])*Header.SectionCount;
 
93
      GetMem(SectionTable,SectionTableSize);
 
94
      F^.Read(SectionTable^,SectionTableSize);
 
95
      OK:=(F^.Status=stOK);
 
96
    end;
 
97
    if OK then
 
98
      OK:=ReadBlock(nil,2);
 
99
    if OK then
 
100
    begin
 
101
      TopicTableSize:=sizeof(TopicTable^[0])*Header.TotalTopics;
 
102
      GetMem(TopicTable,TopicTableSize);
 
103
      OK:=ReadTopicTable;
 
104
    end;
 
105
  end;
 
106
  if OK=false then
 
107
  begin
 
108
    Done;
 
109
    Fail;
 
110
  end;
 
111
end;
 
112
 
 
113
function TVPHHelpFile.ReadHeader: boolean;
 
114
var OK: boolean;
 
115
begin
 
116
  F^.Read(Header,sizeof(Header));
 
117
  OK:=(F^.Status=stOK);
 
118
  ReadHeader:=OK;
 
119
end;
 
120
 
 
121
function TVPHHelpFile.LoadIndex: boolean;
 
122
var OK: boolean;
 
123
begin
 
124
  OK:=false;
 
125
  LoadIndex:=OK;
 
126
end;
 
127
 
 
128
function TVPHHelpFile.ReadBlock(Data: pointer; DataSize: longint): boolean;
 
129
var OK: boolean;
 
130
    C: char;
 
131
begin
 
132
  F^.Read(C,sizeof(C));
 
133
  OK:=(F^.Status=stOK) and (C='�');
 
134
  if OK then
 
135
  begin
 
136
    if Assigned(Data) then
 
137
      F^.Read(Data^,DataSize)
 
138
    else
 
139
      F^.Seek(F^.GetPos+DataSize);
 
140
    OK:=(F^.Status=stOK);
 
141
  end;
 
142
  ReadBlock:=OK;
 
143
end;
 
144
 
 
145
function TVPHHelpFile.ReadTopicTable: boolean;
 
146
var OK: boolean;
 
147
begin
 
148
  OK:=ReadBlock(TopicTable,TopicTableSize);
 
149
  TopicBaseOfs:=F^.GetPos;
 
150
  ReadTopicTable:=OK;
 
151
end;
 
152
 
 
153
function TVPHHelpFile.ReadTopic(T: PTopic): boolean;
 
154
var OK: boolean;
 
155
begin
 
156
  OK:=false;
 
157
  ReadTopic:=OK;
 
158
end;
 
159
 
 
160
destructor TVPHHelpFile.Done;
 
161
begin
 
162
  if Assigned(TopicTable) and (TopicTableSize>0) then
 
163
      FreeMem(TopicTable{$ifndef FP},TopicTableSize{$endif});
 
164
  TopicTable:=nil;
 
165
  if Assigned(SectionTable) and (SectionTableSize>0) then
 
166
      FreeMem(SectionTable{$ifndef FP},SectionTableSize{$endif});
 
167
  SectionTable:=nil;
 
168
  if Assigned(F) then Dispose(F, Done); F:=nil;
 
169
  inherited Done;
 
170
end;
 
171
 
 
172
function CreateProc(const FileName,Param: string;Index : longint): PHelpFile; {$ifndef FPC}far;{$endif}
 
173
begin
 
174
  CreateProc:=New(PVPHHelpFile, Init(FileName,Index));
 
175
end;
 
176
 
 
177
procedure RegisterHelpType;
 
178
begin
 
179
  RegisterHelpFileType({$ifdef FPC}@{$endif}CreateProc);
 
180
end;
 
181
 
 
182
END.
 
183
{
 
184
  $Log: wvphelp.pas,v $
 
185
  Revision 1.5  2005/02/14 17:13:19  peter
 
186
    * truncate log
 
187
 
 
188
}