2
0

writeidx.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. {
  2. Help program to generate html help index
  3. This file is part of Free Pascal.
  4. Copyright (c) 1993-2005 by Florian Klaempfl
  5. member of the Free Pascal development team
  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. {$mode objfpc}
  13. uses
  14. insthelp,sysutils,dos,objects,WHTMLScn;
  15. type
  16. PFPHTMLFileLinkScanner = ^TFPHTMLFileLinkScanner;
  17. TFPHTMLFileLinkScanner = object(THTMLFileLinkScanner)
  18. function CheckURL(const URL: string): boolean; virtual;
  19. function CheckText(const Text: string): boolean; virtual;
  20. procedure ProcessDoc(Doc: PHTMLLinkScanFile); virtual;
  21. end;
  22. const
  23. HTMLIndexExt = '.htx';
  24. procedure TFPHTMLFileLinkScanner.ProcessDoc(Doc: PHTMLLinkScanFile);
  25. begin
  26. end;
  27. function TFPHTMLFileLinkScanner.CheckURL(const URL: string): boolean;
  28. var OK: boolean;
  29. const HTTPPrefix = 'http:';
  30. FTPPrefix = 'ftp:';
  31. begin
  32. OK:=inherited CheckURL(URL);
  33. if OK then OK:=DirAndNameOf(URL)<>'';
  34. if OK then OK:=CompareText(copy(ExtOf(URL),1,4),'.HTM')=0;
  35. if OK then OK:=CompareText(copy(URL,1,length(HTTPPrefix)),HTTPPrefix)<>0;
  36. if OK then OK:=CompareText(copy(URL,1,length(FTPPrefix)),FTPPrefix)<>0;
  37. CheckURL:=OK;
  38. end;
  39. function TFPHTMLFileLinkScanner.CheckText(const Text: string): boolean;
  40. var OK: boolean;
  41. S: string;
  42. begin
  43. S:=Trim(Text);
  44. OK:=(S<>'') and (copy(S,1,1)<>'[');
  45. CheckText:=OK;
  46. end;
  47. procedure doerror(const s : ansistring);
  48. begin
  49. writeln(s);
  50. writeln;
  51. writeln('Press ENTER to continue');
  52. readln;
  53. end;
  54. procedure writehlpindex(filename : ansistring);
  55. var
  56. LS : PFPHTMLFileLinkScanner;
  57. BS : PBufStream;
  58. Re : Word;
  59. params : array[0..0] of pointer;
  60. dir : searchrec;
  61. begin
  62. writeln('Creating HTML index file, please wait ...');
  63. New(LS, Init(DirOf(FileName)));
  64. LS^.ProcessDocument(FileName,[soSubDocsOnly]);
  65. if LS^.GetDocumentCount=0 then
  66. doerror(format('Problem creating help index %1, aborting',[filename]))
  67. else
  68. begin
  69. FileName:=DirAndNameOf(FileName)+HTMLIndexExt;
  70. begin
  71. New(BS, Init(FileName, stCreate, 4096));
  72. if not(Assigned(BS)) then
  73. doerror(format('Error while writing help index! '+
  74. 'No help index is created',[filename]))
  75. else
  76. begin
  77. LS^.StoreDocuments(BS^);
  78. if BS^.Status<>stOK then
  79. doerror(format('Error while writing help index! '+
  80. 'No help index is created',[filename]));
  81. Dispose(BS, Done);
  82. end;
  83. end;
  84. end;
  85. Dispose(LS, Done);
  86. end;
  87. begin
  88. if paramcount<>1 then
  89. writeln('Usage: writeidx <index name>')
  90. else
  91. writehlpindex(paramstr(1));
  92. end.