wvphelp.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 2000 by Berczi Gabor
  4. Help support for (.VPH) help files
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$R-}
  12. {$H-}
  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. function DefVPHGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
  57. begin
  58. DefVPHGetAttrColor:=false;
  59. end;
  60. constructor TVPHHelpFile.Init(AFileName: string; AID: word);
  61. var OK: boolean;
  62. begin
  63. if inherited Init(AID)=false then Fail;
  64. F:=New(PFastBufStream, Init(AFileName, stOpenRead, HelpStreamBufSize));
  65. OK:=F<>nil;
  66. if OK then OK:=(F^.Status=stOK);
  67. if OK then
  68. begin
  69. OK:=ReadHeader;
  70. if OK then
  71. begin
  72. SectionTableSize:=sizeof(SectionTable^[0])*Header.SectionCount;
  73. GetMem(SectionTable,SectionTableSize);
  74. F^.Read(SectionTable^,SectionTableSize);
  75. OK:=(F^.Status=stOK);
  76. end;
  77. if OK then
  78. OK:=ReadBlock(nil,2);
  79. if OK then
  80. begin
  81. TopicTableSize:=sizeof(TopicTable^[0])*Header.TotalTopics;
  82. GetMem(TopicTable,TopicTableSize);
  83. OK:=ReadTopicTable;
  84. end;
  85. end;
  86. if OK=false then
  87. begin
  88. Done;
  89. Fail;
  90. end;
  91. end;
  92. function TVPHHelpFile.ReadHeader: boolean;
  93. var OK: boolean;
  94. begin
  95. F^.Read(Header,sizeof(Header));
  96. OK:=(F^.Status=stOK);
  97. ReadHeader:=OK;
  98. end;
  99. function TVPHHelpFile.LoadIndex: boolean;
  100. var OK: boolean;
  101. begin
  102. OK:=false;
  103. LoadIndex:=OK;
  104. end;
  105. function TVPHHelpFile.ReadBlock(Data: pointer; DataSize: longint): boolean;
  106. var OK: boolean;
  107. C: AnsiChar;
  108. begin
  109. F^.Read(C,sizeof(C));
  110. OK:=(F^.Status=stOK) and (C='þ');
  111. if OK then
  112. begin
  113. if Assigned(Data) then
  114. F^.Read(Data^,DataSize)
  115. else
  116. F^.Seek(F^.GetPos+DataSize);
  117. OK:=(F^.Status=stOK);
  118. end;
  119. ReadBlock:=OK;
  120. end;
  121. function TVPHHelpFile.ReadTopicTable: boolean;
  122. var OK: boolean;
  123. begin
  124. OK:=ReadBlock(TopicTable,TopicTableSize);
  125. TopicBaseOfs:=F^.GetPos;
  126. ReadTopicTable:=OK;
  127. end;
  128. function TVPHHelpFile.ReadTopic(T: PTopic): boolean;
  129. var OK: boolean;
  130. begin
  131. OK:=false;
  132. ReadTopic:=OK;
  133. end;
  134. destructor TVPHHelpFile.Done;
  135. begin
  136. if Assigned(TopicTable) and (TopicTableSize>0) then
  137. FreeMem(TopicTable{$ifndef FP},TopicTableSize{$endif});
  138. TopicTable:=nil;
  139. if Assigned(SectionTable) and (SectionTableSize>0) then
  140. FreeMem(SectionTable{$ifndef FP},SectionTableSize{$endif});
  141. SectionTable:=nil;
  142. if Assigned(F) then Dispose(F, Done); F:=nil;
  143. inherited Done;
  144. end;
  145. function CreateProc(const FileName,Param: string;Index : longint): PHelpFile;
  146. begin
  147. CreateProc:=New(PVPHHelpFile, Init(FileName,Index));
  148. end;
  149. procedure RegisterHelpType;
  150. begin
  151. RegisterHelpFileType({$ifdef FPC}@{$endif}CreateProc);
  152. end;
  153. END.