whtmlhlp.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1999-2000 by Berczi Gabor
  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. unit WHTMLHlp;
  12. interface
  13. uses Objects,WHTML,WHelp;
  14. const
  15. ListIndent = 2;
  16. DefIndent = 4;
  17. MaxTopicLinks = 5000; { maximum number of links on a single HTML page }
  18. type
  19. THTMLSection = (hsNone,hsHeading1,hsHeading2,hsHeading3,hsHeading4,hsHeading5,hsHeading6);
  20. PTopicLinkCollection = ^TTopicLinkCollection;
  21. TTopicLinkCollection = object(TStringCollection)
  22. procedure Insert(Item: Pointer); virtual;
  23. function At(Index: sw_Integer): PString;
  24. function AddItem(Item: string): integer;
  25. end;
  26. TParagraphAlign = (paLeft,paCenter,paRight);
  27. PHTMLTopicRenderer = ^THTMLTopicRenderer;
  28. THTMLTopicRenderer = object(THTMLParser)
  29. function BuildTopic(P: PTopic; AURL: string; HTMLFile: PTextFile; ATopicLinks: PTopicLinkCollection): boolean;
  30. public
  31. function DocAddTextChar(C: char): boolean; virtual;
  32. procedure DocSoftBreak; virtual;
  33. procedure DocTYPE; virtual;
  34. procedure DocHTML(Entered: boolean); virtual;
  35. procedure DocHEAD(Entered: boolean); virtual;
  36. procedure DocMETA; virtual;
  37. procedure DocTITLE(Entered: boolean); virtual;
  38. procedure DocBODY(Entered: boolean); virtual;
  39. procedure DocAnchor(Entered: boolean); virtual;
  40. procedure DocHeading(Level: integer; Entered: boolean); virtual;
  41. procedure DocParagraph(Entered: boolean); virtual;
  42. procedure DocBreak; virtual;
  43. procedure DocImage; virtual;
  44. procedure DocBold(Entered: boolean); virtual;
  45. procedure DocCite(Entered: boolean); virtual;
  46. procedure DocCode(Entered: boolean); virtual;
  47. procedure DocEmphasized(Entered: boolean); virtual;
  48. procedure DocItalic(Entered: boolean); virtual;
  49. procedure DocKbd(Entered: boolean); virtual;
  50. procedure DocPreformatted(Entered: boolean); virtual;
  51. procedure DocSample(Entered: boolean); virtual;
  52. procedure DocStrong(Entered: boolean); virtual;
  53. procedure DocTeleType(Entered: boolean); virtual;
  54. procedure DocVariable(Entered: boolean); virtual;
  55. procedure DocList(Entered: boolean); virtual;
  56. procedure DocOrderedList(Entered: boolean); virtual;
  57. procedure DocListItem; virtual;
  58. procedure DocDefList(Entered: boolean); virtual;
  59. procedure DocDefTerm; virtual;
  60. procedure DocDefExp; virtual;
  61. procedure DocTable(Entered: boolean); virtual;
  62. procedure DocTableRow(Entered: boolean); virtual;
  63. procedure DocTableItem(Entered: boolean); virtual;
  64. procedure DocHorizontalRuler; virtual;
  65. public
  66. function GetSectionColor(Section: THTMLSection; var Color: byte): boolean; virtual;
  67. private
  68. URL: string;
  69. Topic: PTopic;
  70. TopicLinks: PTopicLinkCollection;
  71. TextPtr: sw_word;
  72. InTitle: boolean;
  73. InBody: boolean;
  74. InAnchor: boolean;
  75. InParagraph: boolean;
  76. InPreformatted: boolean;
  77. TopicTitle: string;
  78. Indent: integer;
  79. AnyCharsInLine: boolean;
  80. CurHeadLevel: integer;
  81. PAlign: TParagraphAlign;
  82. LinkIndexes: array[0..MaxTopicLinks] of sw_integer;
  83. LinkPtr: sw_integer;
  84. LastTextChar: char;
  85. { Anchor: TAnchor;}
  86. procedure AddText(S: string);
  87. procedure AddChar(C: char);
  88. end;
  89. PCustomHTMLHelpFile = ^TCustomHTMLHelpFile;
  90. TCustomHTMLHelpFile = object(THelpFile)
  91. constructor Init(AID: word);
  92. destructor Done; virtual;
  93. public
  94. function SearchTopic(HelpCtx: THelpCtx): PTopic; virtual;
  95. function ReadTopic(T: PTopic): boolean; virtual;
  96. private
  97. Renderer: PHTMLTopicRenderer;
  98. DefaultFileName: string;
  99. CurFileName: string;
  100. TopicLinks: PTopicLinkCollection;
  101. end;
  102. PHTMLHelpFile = ^THTMLHelpFile;
  103. THTMLHelpFile = object(TCustomHTMLHelpFile)
  104. constructor Init(AFileName: string; AID: word; ATOCEntry: string);
  105. public
  106. function LoadIndex: boolean; virtual;
  107. private
  108. TOCEntry: string;
  109. end;
  110. PHTMLIndexHelpFile = ^THTMLIndexHelpFile;
  111. THTMLIndexHelpFile = object(TCustomHTMLHelpFile)
  112. constructor Init(AFileName: string; AID: word);
  113. function LoadIndex: boolean; virtual;
  114. private
  115. IndexFileName: string;
  116. end;
  117. THTMLGetSectionColorProc = function(Section: THTMLSection; var Color: byte): boolean;
  118. function DefHTMLGetSectionColor(Section: THTMLSection; var Color: byte): boolean;
  119. const HTMLGetSectionColor : THTMLGetSectionColorProc = DefHTMLGetSectionColor;
  120. implementation
  121. uses WConsts,WUtils,WViews,WHTMLScn;
  122. function DefHTMLGetSectionColor(Section: THTMLSection; var Color: byte): boolean;
  123. begin
  124. Color:=0;
  125. DefHTMLGetSectionColor:=false;
  126. end;
  127. function EncodeHTMLCtx(FileID: integer; LinkNo: word): longint;
  128. var Ctx: longint;
  129. begin
  130. Ctx:=(longint(FileID) shl 16)+LinkNo;
  131. EncodeHTMLCtx:=Ctx;
  132. end;
  133. procedure DecodeHTMLCtx(Ctx: longint; var FileID: word; var LinkNo: word);
  134. begin
  135. if (Ctx shr 16)=0 then
  136. begin
  137. FileID:=$ffff; LinkNo:=0;
  138. end
  139. else
  140. begin
  141. FileID:=Ctx shr 16; LinkNo:=Ctx and $ffff;
  142. end;
  143. end;
  144. function CharStr(C: char; Count: byte): string;
  145. var S: string;
  146. begin
  147. S[0]:=chr(Count);
  148. if Count>0 then FillChar(S[1],Count,C);
  149. CharStr:=S;
  150. end;
  151. procedure TTopicLinkCollection.Insert(Item: Pointer);
  152. begin
  153. AtInsert(Count,Item);
  154. end;
  155. function TTopicLinkCollection.At(Index: sw_Integer): PString;
  156. begin
  157. At:=inherited At(Index);
  158. end;
  159. function TTopicLinkCollection.AddItem(Item: string): integer;
  160. var Idx: sw_integer;
  161. begin
  162. if Item='' then Idx:=-1 else
  163. if Search(@Item,Idx)=false then
  164. begin
  165. AtInsert(Count,NewStr(Item));
  166. Idx:=Count-1;
  167. end;
  168. AddItem:=Idx;
  169. end;
  170. function THTMLTopicRenderer.DocAddTextChar(C: char): boolean;
  171. var Added: boolean;
  172. begin
  173. Added:=false;
  174. if InTitle then
  175. begin
  176. TopicTitle:=TopicTitle+C;
  177. Added:=true;
  178. end
  179. else
  180. if InBody then
  181. begin
  182. if (InPreFormatted) or (C<>#32) or (LastTextChar<>C) then
  183. if (C<>#32) or (AnyCharsInLine=true) or (InPreFormatted=true) then
  184. begin
  185. AddChar(C);
  186. LastTextChar:=C;
  187. Added:=true;
  188. end;
  189. end;
  190. DocAddTextChar:=Added;
  191. end;
  192. procedure THTMLTopicRenderer.DocSoftBreak;
  193. begin
  194. if InPreformatted then DocBreak else
  195. if AnyCharsInLine then
  196. begin
  197. AddChar(' ');
  198. LastTextChar:=' ';
  199. end;
  200. end;
  201. procedure THTMLTopicRenderer.DocTYPE;
  202. begin
  203. end;
  204. procedure THTMLTopicRenderer.DocHTML(Entered: boolean);
  205. begin
  206. end;
  207. procedure THTMLTopicRenderer.DocHEAD(Entered: boolean);
  208. begin
  209. end;
  210. procedure THTMLTopicRenderer.DocMETA;
  211. begin
  212. end;
  213. procedure THTMLTopicRenderer.DocTITLE(Entered: boolean);
  214. begin
  215. if Entered then
  216. begin
  217. TopicTitle:='';
  218. end
  219. else
  220. begin
  221. { render topic title here }
  222. if TopicTitle<>'' then
  223. begin
  224. AddText(' '+TopicTitle+' Ü'); DocBreak;
  225. AddText(' '+CharStr('ß',length(TopicTitle)+3)); DocBreak;
  226. end;
  227. end;
  228. InTitle:=Entered;
  229. end;
  230. procedure THTMLTopicRenderer.DocBODY(Entered: boolean);
  231. begin
  232. InBody:=Entered;
  233. end;
  234. procedure THTMLTopicRenderer.DocAnchor(Entered: boolean);
  235. var HRef,Name: string;
  236. begin
  237. if Entered and InAnchor then DocAnchor(false);
  238. if Entered then
  239. begin
  240. if DocGetTagParam('HREF',HRef)=false then HRef:='';
  241. if DocGetTagParam('NAME',Name)=false then Name:='';
  242. if Name<>'' then
  243. begin
  244. Topic^.NamedMarks^.InsertStr(Name);
  245. AddChar(hscNamedMark);
  246. end;
  247. if (HRef<>'') then
  248. begin
  249. InAnchor:=true;
  250. AddChar(hscLink);
  251. if LinkPtr<MaxTopicLinks then
  252. begin
  253. HRef:=CompleteURL(URL,HRef);
  254. LinkIndexes[LinkPtr]:=TopicLinks^.AddItem(HRef);
  255. Inc(LinkPtr);
  256. end;
  257. end;
  258. end
  259. else
  260. begin
  261. if InAnchor=true then AddChar(hscLink);
  262. InAnchor:=false;
  263. end;
  264. end;
  265. procedure DecodeAlign(Align: string; var PAlign: TParagraphAlign);
  266. begin
  267. Align:=UpcaseStr(Align);
  268. if Align='LEFT' then PAlign:=paLeft else
  269. if Align='CENTER' then PAlign:=paCenter else
  270. if Align='RIGHT' then PAlign:=paRight;
  271. end;
  272. procedure THTMLTopicRenderer.DocHeading(Level: integer; Entered: boolean);
  273. var Align: string;
  274. C: byte;
  275. SC: THTMLSection;
  276. begin
  277. if Entered then
  278. begin
  279. DocBreak;
  280. CurHeadLevel:=Level;
  281. PAlign:=paLeft;
  282. if DocGetTagParam('ALIGN',Align) then
  283. DecodeAlign(Align,PAlign);
  284. SC:=hsNone;
  285. case Level of
  286. 1: SC:=hsHeading1;
  287. 2: SC:=hsHeading2;
  288. 3: SC:=hsHeading3;
  289. 4: SC:=hsHeading4;
  290. 5: SC:=hsHeading5;
  291. 6: SC:=hsHeading6;
  292. end;
  293. if GetSectionColor(SC,C) then
  294. AddText(hscTextAttr+chr(C));
  295. end
  296. else
  297. begin
  298. AddChar(hscNormText);
  299. CurHeadLevel:=0;
  300. DocBreak;
  301. end;
  302. end;
  303. procedure THTMLTopicRenderer.DocParagraph(Entered: boolean);
  304. var Align: string;
  305. begin
  306. if Entered and InParagraph then DocParagraph(false);
  307. if Entered then
  308. begin
  309. if AnyCharsInLine then DocBreak;
  310. if DocGetTagParam('ALIGN',Align) then
  311. DecodeAlign(Align,PAlign);
  312. end
  313. else
  314. begin
  315. { if AnyCharsInLine then }DocBreak;
  316. PAlign:=paLeft;
  317. end;
  318. InParagraph:=Entered;
  319. end;
  320. procedure THTMLTopicRenderer.DocBreak;
  321. begin
  322. if (CurHeadLevel=1) or (PAlign=paCenter) then
  323. AddChar(hscCenter);
  324. if (PAlign=paRight) then
  325. AddChar(hscRight);
  326. AddChar(hscLineBreak);
  327. if Indent>0 then
  328. AddText(CharStr(#255,Indent)+hscLineStart);
  329. AnyCharsInLine:=false;
  330. end;
  331. procedure THTMLTopicRenderer.DocImage;
  332. var Alt: string;
  333. begin
  334. if DocGetTagParam('ALT',Alt)=false then Alt:='IMG';
  335. if Alt<>'' then
  336. begin
  337. AddText('['+Alt+']');
  338. end;
  339. end;
  340. procedure THTMLTopicRenderer.DocBold(Entered: boolean);
  341. begin
  342. end;
  343. procedure THTMLTopicRenderer.DocCite(Entered: boolean);
  344. begin
  345. end;
  346. procedure THTMLTopicRenderer.DocCode(Entered: boolean);
  347. begin
  348. if AnyCharsInLine then DocBreak;
  349. AddText(hscCode);
  350. DocBreak;
  351. end;
  352. procedure THTMLTopicRenderer.DocEmphasized(Entered: boolean);
  353. begin
  354. end;
  355. procedure THTMLTopicRenderer.DocItalic(Entered: boolean);
  356. begin
  357. end;
  358. procedure THTMLTopicRenderer.DocKbd(Entered: boolean);
  359. begin
  360. end;
  361. procedure THTMLTopicRenderer.DocPreformatted(Entered: boolean);
  362. begin
  363. if AnyCharsInLine then DocBreak;
  364. AddText(hscCode);
  365. DocBreak;
  366. InPreformatted:=Entered;
  367. end;
  368. procedure THTMLTopicRenderer.DocSample(Entered: boolean);
  369. begin
  370. end;
  371. procedure THTMLTopicRenderer.DocStrong(Entered: boolean);
  372. begin
  373. end;
  374. procedure THTMLTopicRenderer.DocTeleType(Entered: boolean);
  375. begin
  376. end;
  377. procedure THTMLTopicRenderer.DocVariable(Entered: boolean);
  378. begin
  379. end;
  380. procedure THTMLTopicRenderer.DocList(Entered: boolean);
  381. begin
  382. if Entered then
  383. begin
  384. Inc(Indent,ListIndent);
  385. DocBreak;
  386. end
  387. else
  388. begin
  389. Dec(Indent,ListIndent);
  390. if AnyCharsInLine then DocBreak;
  391. end;
  392. end;
  393. procedure THTMLTopicRenderer.DocOrderedList(Entered: boolean);
  394. begin
  395. DocList(Entered);
  396. end;
  397. procedure THTMLTopicRenderer.DocListItem;
  398. begin
  399. if AnyCharsInLine then
  400. DocBreak;
  401. AddText('þ'+hscLineStart);
  402. end;
  403. procedure THTMLTopicRenderer.DocDefList(Entered: boolean);
  404. begin
  405. if Entered then
  406. begin
  407. { if LastChar<>hscLineBreak then DocBreak;}
  408. end
  409. else
  410. begin
  411. if AnyCharsInLine then DocBreak;
  412. end;
  413. end;
  414. procedure THTMLTopicRenderer.DocDefTerm;
  415. begin
  416. DocBreak;
  417. end;
  418. procedure THTMLTopicRenderer.DocDefExp;
  419. begin
  420. Inc(Indent,DefIndent);
  421. DocBreak;
  422. Dec(Indent,DefIndent);
  423. end;
  424. procedure THTMLTopicRenderer.DocTable(Entered: boolean);
  425. begin
  426. if AnyCharsInLine then
  427. DocBreak;
  428. if Entered then
  429. DocBreak;
  430. end;
  431. procedure THTMLTopicRenderer.DocTableRow(Entered: boolean);
  432. begin
  433. if AnyCharsInLine then
  434. DocBreak;
  435. end;
  436. procedure THTMLTopicRenderer.DocTableItem(Entered: boolean);
  437. begin
  438. if Entered then
  439. AddText(' - ');
  440. end;
  441. procedure THTMLTopicRenderer.DocHorizontalRuler;
  442. var OAlign: TParagraphAlign;
  443. begin
  444. OAlign:=PAlign;
  445. if AnyCharsInLine then DocBreak;
  446. PAlign:=paCenter;
  447. DocAddText(' '+CharStr('Ä',60)+' ');
  448. DocBreak;
  449. PAlign:=OAlign;
  450. end;
  451. procedure THTMLTopicRenderer.AddChar(C: char);
  452. begin
  453. if (Topic=nil) or (TextPtr=MaxBytes) then Exit;
  454. Topic^.Text^[TextPtr]:=ord(C);
  455. Inc(TextPtr);
  456. if (C>#15) and ((C<>' ') or (InPreFormatted=true)) then
  457. AnyCharsInLine:=true;
  458. end;
  459. procedure THTMLTopicRenderer.AddText(S: string);
  460. var I: sw_integer;
  461. begin
  462. for I:=1 to length(S) do
  463. AddChar(S[I]);
  464. end;
  465. function THTMLTopicRenderer.GetSectionColor(Section: THTMLSection; var Color: byte): boolean;
  466. begin
  467. GetSectionColor:=HTMLGetSectionColor(Section,Color);
  468. end;
  469. function THTMLTopicRenderer.BuildTopic(P: PTopic; AURL: string; HTMLFile: PTextFile;
  470. ATopicLinks: PTopicLinkCollection): boolean;
  471. var OK: boolean;
  472. TP: pointer;
  473. I: sw_integer;
  474. begin
  475. URL:=AURL;
  476. Topic:=P; TopicLinks:=ATopicLinks;
  477. OK:=Assigned(Topic) and Assigned(HTMLFile) and Assigned(TopicLinks);
  478. if OK then
  479. begin
  480. if (Topic^.TextSize<>0) and Assigned(Topic^.Text) then
  481. begin
  482. FreeMem(Topic^.Text,Topic^.TextSize);
  483. Topic^.TextSize:=0; Topic^.Text:=nil;
  484. end;
  485. Topic^.TextSize:=MaxHelpTopicSize;
  486. GetMem(Topic^.Text,Topic^.TextSize);
  487. TopicTitle:='';
  488. InTitle:=false; InBody:={false}true; InAnchor:=false;
  489. InParagraph:=false; InPreformatted:=false;
  490. Indent:=0; CurHeadLevel:=0;
  491. PAlign:=paLeft;
  492. TextPtr:=0; LinkPtr:=0;
  493. AnyCharsInLine:=false;
  494. LastTextChar:=#0;
  495. OK:=Process(HTMLFile);
  496. if OK then
  497. begin
  498. { --- topic links --- }
  499. if (Topic^.Links<>nil) and (Topic^.LinkSize>0) then
  500. begin
  501. FreeMem(Topic^.Links,Topic^.LinkSize);
  502. Topic^.Links:=nil; Topic^.LinkCount:=0;
  503. end;
  504. Topic^.LinkCount:=LinkPtr{TopicLinks^.Count}; { <- eeeeeek! }
  505. GetMem(Topic^.Links,Topic^.LinkSize);
  506. if Topic^.LinkCount>0 then { FP causes numeric RTE 215 without this }
  507. for I:=0 to Min(Topic^.LinkCount-1,High(LinkIndexes)-1) do
  508. begin
  509. Topic^.Links^[I].FileID:=Topic^.FileID;
  510. Topic^.Links^[I].Context:=EncodeHTMLCtx(Topic^.FileID,LinkIndexes[I]+1);
  511. end;
  512. { --- topic text --- }
  513. GetMem(TP,TextPtr);
  514. Move(Topic^.Text^,TP^,TextPtr);
  515. FreeMem(Topic^.Text,Topic^.TextSize);
  516. Topic^.Text:=TP; Topic^.TextSize:=TextPtr;
  517. end
  518. else
  519. begin
  520. DisposeTopic(Topic);
  521. Topic:=nil;
  522. end;
  523. end;
  524. BuildTopic:=OK;
  525. end;
  526. constructor TCustomHTMLHelpFile.Init(AID: word);
  527. begin
  528. inherited Init(AID);
  529. New(Renderer, Init);
  530. New(TopicLinks, Init(50,500));
  531. end;
  532. function TCustomHTMLHelpFile.SearchTopic(HelpCtx: THelpCtx): PTopic;
  533. function MatchCtx(P: PTopic): boolean; {$ifndef FPC}far;{$endif}
  534. begin
  535. MatchCtx:=P^.HelpCtx=HelpCtx;
  536. end;
  537. var FileID,LinkNo: word;
  538. P: PTopic;
  539. FName: string;
  540. begin
  541. DecodeHTMLCtx(HelpCtx,FileID,LinkNo);
  542. if (HelpCtx<>0) and (FileID<>ID) then P:=nil else
  543. if (FileID=ID) and (LinkNo>TopicLinks^.Count) then P:=nil else
  544. begin
  545. P:=Topics^.FirstThat(@MatchCtx);
  546. if P=nil then
  547. begin
  548. if LinkNo=0 then
  549. FName:=DefaultFileName
  550. else
  551. FName:=TopicLinks^.At(LinkNo-1)^;
  552. P:=NewTopic(ID,HelpCtx,0,FName,nil,0);
  553. Topics^.Insert(P);
  554. end;
  555. end;
  556. SearchTopic:=P;
  557. end;
  558. function TCustomHTMLHelpFile.ReadTopic(T: PTopic): boolean;
  559. var OK: boolean;
  560. HTMLFile: PMemoryTextFile;
  561. Name: string;
  562. Link,Bookmark: string;
  563. P: sw_integer;
  564. begin
  565. Bookmark:='';
  566. OK:=T<>nil;
  567. if OK then
  568. begin
  569. if T^.HelpCtx=0 then Name:=DefaultFileName else
  570. begin
  571. Link:=TopicLinks^.At((T^.HelpCtx and $ffff)-1)^;
  572. Link:=FormatPath(Link);
  573. P:=Pos('#',Link);
  574. if P>0 then
  575. begin
  576. Bookmark:=copy(Link,P+1,length(Link));
  577. Link:=copy(Link,1,P-1);
  578. end;
  579. { if CurFileName='' then Name:=Link else
  580. Name:=CompletePath(CurFileName,Link);}
  581. Name:=Link;
  582. end;
  583. HTMLFile:=New(PDOSTextFile, Init(Name));
  584. if HTMLFile=nil then
  585. begin
  586. New(HTMLFile, Init);
  587. HTMLFile^.AddLine('<HEAD><TITLE>'+msg_pagenotavailable+'</TITLE></HEAD>');
  588. HTMLFile^.AddLine(
  589. '<BODY>'+
  590. FormatStrStr(msg_cantaccessurl,Name)+'<br><br>'+
  591. '</BODY>');
  592. end;
  593. OK:=Renderer^.BuildTopic(T,Name,HTMLFile,TopicLinks);
  594. if OK then CurFileName:=Name;
  595. if HTMLFile<>nil then Dispose(HTMLFile, Done);
  596. if BookMark='' then
  597. T^.StartNamedMark:=0
  598. else
  599. T^.StartNamedMark:=T^.GetNamedMarkIndex(BookMark)+1;
  600. end;
  601. ReadTopic:=OK;
  602. end;
  603. destructor TCustomHTMLHelpFile.Done;
  604. begin
  605. inherited Done;
  606. if Renderer<>nil then Dispose(Renderer, Done);
  607. if TopicLinks<>nil then Dispose(TopicLinks, Done);
  608. end;
  609. constructor THTMLHelpFile.Init(AFileName: string; AID: word; ATOCEntry: string);
  610. begin
  611. if inherited Init(AID)=false then Fail;
  612. DefaultFileName:=AFileName; TOCEntry:=ATOCEntry;
  613. if DefaultFileName='' then
  614. begin
  615. Done;
  616. Fail;
  617. end;
  618. end;
  619. function THTMLHelpFile.LoadIndex: boolean;
  620. begin
  621. IndexEntries^.Insert(NewIndexEntry(TOCEntry,ID,0));
  622. LoadIndex:=true;
  623. end;
  624. constructor THTMLIndexHelpFile.Init(AFileName: string; AID: word);
  625. begin
  626. inherited Init(AID);
  627. IndexFileName:=AFileName;
  628. end;
  629. function THTMLIndexHelpFile.LoadIndex: boolean;
  630. function FormatAlias(Alias: string): string;
  631. begin
  632. if Assigned(HelpFacility) then
  633. if length(Alias)>HelpFacility^.IndexTabSize-4 then
  634. Alias:=Trim(copy(Alias,1,HelpFacility^.IndexTabSize-4-2))+'..';
  635. FormatAlias:=Alias;
  636. end;
  637. (*procedure AddDoc(P: PHTMLLinkScanDocument); {$ifndef FPC}far;{$endif}
  638. var I: sw_integer;
  639. TLI: THelpCtx;
  640. begin
  641. for I:=1 to P^.GetAliasCount do
  642. begin
  643. TLI:=TopicLinks^.AddItem(P^.GetName);
  644. TLI:=EncodeHTMLCtx(ID,TLI+1);
  645. IndexEntries^.Insert(NewIndexEntry(FormatAlias(P^.GetAlias(I-1)),ID,TLI));
  646. end;
  647. end;*)
  648. var S: PBufStream;
  649. LS: PHTMLLinkScanner;
  650. OK: boolean;
  651. TLI: THelpCtx;
  652. I,J: sw_integer;
  653. begin
  654. New(S, Init(IndexFileName,stOpenRead,4096));
  655. OK:=Assigned(S);
  656. if OK then
  657. begin
  658. New(LS, LoadDocuments(S^));
  659. OK:=Assigned(LS);
  660. if OK then
  661. begin
  662. LS^.SetBaseDir(DirOf(IndexFileName));
  663. for I:=0 to LS^.GetDocumentCount-1 do
  664. for J:=0 to LS^.GetDocumentAliasCount(I)-1 do
  665. begin
  666. TLI:=TopicLinks^.AddItem(LS^.GetDocumentURL(I));
  667. TLI:=EncodeHTMLCtx(ID,TLI+1);
  668. IndexEntries^.Insert(NewIndexEntry(FormatAlias(LS^.GetDocumentAlias(I,J)),ID,TLI));
  669. end;
  670. Dispose(LS, Done);
  671. end;
  672. Dispose(S, Done);
  673. end;
  674. LoadIndex:=OK;
  675. end;
  676. END.
  677. {
  678. $Log$
  679. Revision 1.2 2000-10-31 22:35:56 pierre
  680. * New big merge from fixes branch
  681. Revision 1.1.2.2 2000/10/18 21:53:27 pierre
  682. * several Gabor fixes
  683. Revision 1.1.2.1 2000/09/18 13:20:56 pierre
  684. New bunch of Gabor changes
  685. Revision 1.1 2000/07/13 09:48:37 michael
  686. + Initial import
  687. Revision 1.15 2000/06/22 09:07:15 pierre
  688. * Gabor changes: see fixes.txt
  689. Revision 1.14 2000/06/16 08:50:45 pierre
  690. + new bunch of Gabor's changes
  691. }