wvphelp.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 2000 by Berczi Gabor
  5. Help support for (.VPH) help files
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$R-}
  13. unit WVPHelp;
  14. interface
  15. uses Objects,
  16. WUtils,WHelp;
  17. const
  18. VPHFileSignature = 'HS';
  19. type
  20. TVPHFileHeader = packed record
  21. SectionCount: byte; { #1 }
  22. TotalTopics : word;
  23. end;
  24. TVPHTopicEntry = packed record
  25. TopicOfs : word;
  26. Dunno : byte;
  27. end;
  28. PVPHTopicTable = ^TVPHTopicTable;
  29. TVPHTopicTable = packed array[0..(MaxBytes div sizeof(TVPHTopicEntry))-1] of TVPHTopicEntry;
  30. PVPHSectionTable = ^TVPHSectionTable;
  31. TVPHSectionTable = packed array[0..4095] of longint;
  32. PVPHHelpFile = ^TVPHHelpFile;
  33. TVPHHelpFile = object(THelpFile)
  34. constructor Init(AFileName: string; AID: word);
  35. destructor Done; virtual;
  36. public
  37. function LoadIndex: boolean; virtual;
  38. function ReadTopic(T: PTopic): boolean; virtual;
  39. private
  40. F: PStream;
  41. Header: TVPHFileHeader;
  42. TopicTable: PVPHTopicTable;
  43. TopicTableSize: longint;
  44. SectionTable: PVPHSectionTable;
  45. SectionTableSize: longint;
  46. TopicBaseOfs: longint;
  47. function ReadHeader: boolean;
  48. function ReadTopicTable: boolean;
  49. function ReadBlock(Data: pointer; DataSize: longint): boolean;
  50. end;
  51. TVPHGetAttrColorProc = function(TextStyle, TextColor: byte; var Color: byte): boolean;
  52. function DefVPHGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
  53. const VPHGetAttrColor : TVPHGetAttrColorProc = {$ifdef fpc}@{$endif}DefVPHGetAttrColor;
  54. procedure RegisterHelpType;
  55. implementation
  56. uses CallSpec;
  57. function DefVPHGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
  58. begin
  59. DefVPHGetAttrColor:=false;
  60. end;
  61. constructor TVPHHelpFile.Init(AFileName: string; AID: word);
  62. var OK: boolean;
  63. begin
  64. if inherited Init(AID)=false then Fail;
  65. F:=New(PFastBufStream, Init(AFileName, stOpenRead, HelpStreamBufSize));
  66. OK:=F<>nil;
  67. if OK then OK:=(F^.Status=stOK);
  68. if OK then
  69. begin
  70. OK:=ReadHeader;
  71. if OK then
  72. begin
  73. SectionTableSize:=sizeof(SectionTable^[0])*Header.SectionCount;
  74. GetMem(SectionTable,SectionTableSize);
  75. F^.Read(SectionTable^,SectionTableSize);
  76. OK:=(F^.Status=stOK);
  77. end;
  78. if OK then
  79. OK:=ReadBlock(nil,2);
  80. if OK then
  81. begin
  82. TopicTableSize:=sizeof(TopicTable^[0])*Header.TotalTopics;
  83. GetMem(TopicTable,TopicTableSize);
  84. OK:=ReadTopicTable;
  85. end;
  86. end;
  87. if OK=false then
  88. begin
  89. Done;
  90. Fail;
  91. end;
  92. end;
  93. function TVPHHelpFile.ReadHeader: boolean;
  94. var OK: boolean;
  95. begin
  96. F^.Read(Header,sizeof(Header));
  97. OK:=(F^.Status=stOK);
  98. ReadHeader:=OK;
  99. end;
  100. function TVPHHelpFile.LoadIndex: boolean;
  101. var OK: boolean;
  102. begin
  103. OK:=false;
  104. LoadIndex:=OK;
  105. end;
  106. function TVPHHelpFile.ReadBlock(Data: pointer; DataSize: longint): boolean;
  107. var OK: boolean;
  108. C: char;
  109. begin
  110. F^.Read(C,sizeof(C));
  111. OK:=(F^.Status=stOK) and (C='þ');
  112. if OK then
  113. begin
  114. if Assigned(Data) then
  115. F^.Read(Data^,DataSize)
  116. else
  117. F^.Seek(F^.GetPos+DataSize);
  118. OK:=(F^.Status=stOK);
  119. end;
  120. ReadBlock:=OK;
  121. end;
  122. function TVPHHelpFile.ReadTopicTable: boolean;
  123. var OK: boolean;
  124. begin
  125. OK:=ReadBlock(TopicTable,TopicTableSize);
  126. TopicBaseOfs:=F^.GetPos;
  127. ReadTopicTable:=OK;
  128. end;
  129. function TVPHHelpFile.ReadTopic(T: PTopic): boolean;
  130. var OK: boolean;
  131. begin
  132. OK:=false;
  133. ReadTopic:=OK;
  134. end;
  135. destructor TVPHHelpFile.Done;
  136. begin
  137. if Assigned(TopicTable) and (TopicTableSize>0) then
  138. FreeMem(TopicTable{$ifndef FP},TopicTableSize{$endif});
  139. TopicTable:=nil;
  140. if Assigned(SectionTable) and (SectionTableSize>0) then
  141. FreeMem(SectionTable{$ifndef FP},SectionTableSize{$endif});
  142. SectionTable:=nil;
  143. if Assigned(F) then Dispose(F, Done); F:=nil;
  144. inherited Done;
  145. end;
  146. function CreateProc(const FileName,Param: string;Index : longint): PHelpFile; {$ifndef FPC}far;{$endif}
  147. begin
  148. CreateProc:=New(PVPHHelpFile, Init(FileName,Index));
  149. end;
  150. procedure RegisterHelpType;
  151. begin
  152. RegisterHelpFileType({$ifdef FPC}@{$endif}CreateProc);
  153. end;
  154. END.
  155. {
  156. $Log$
  157. Revision 1.3 2002-09-07 15:40:50 peter
  158. * old logs removed and tabs fixed
  159. }