chmls.lpr 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. { Copyright (C) <2005> <Andrew Haines> chmls.lpr
  2. This library is free software; you can redistribute it and/or modify it
  3. under the terms of the GNU Library General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or (at your
  5. option) any later version.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  9. for more details.
  10. You should have received a copy of the GNU Library General Public License
  11. along with this library; if not, write to the Free Software Foundation,
  12. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  13. }
  14. {
  15. See the file COPYING, included in this distribution,
  16. for details about the copyright.
  17. }
  18. program chmls;
  19. {$IFDEF MSWINDOWS}
  20. {$apptype console}
  21. {$ENDIF}
  22. {$mode objfpc}{$H+}
  23. uses
  24. Classes, chmreader, chmbase, Sysutils
  25. { add your units here };
  26. type
  27. { TJunkObject }
  28. TJunkObject = class
  29. procedure OnFileEntry(Name: String; Offset, UncompressedSize, ASection: Integer);
  30. end;
  31. var
  32. ITS: TITSFReader;
  33. Stream: TFileStream;
  34. I : Integer;
  35. Section: Integer = -1;
  36. JunkObject: TJunkObject;
  37. procedure WriteStr(Str: String; CharWidth: Integer);
  38. var
  39. OutString: String;
  40. Len: Integer;
  41. begin
  42. Len := Length(Str);
  43. SetLength(OutString, CharWidth-Len);
  44. FillChar(OutString[1], CharWidth-Len, ' ');
  45. Write(OutString + Str); // to sdtout
  46. end;
  47. { TJunkObject }
  48. procedure TJunkObject.OnFileEntry(Name: String; Offset, UncompressedSize,
  49. ASection: Integer);
  50. begin
  51. Inc(I);
  52. if (Section > -1) and (ASection <> Section) then Exit;
  53. if (I = 1) or (I mod 40 = 0) then
  54. WriteLn(StdErr, '<Section> <Offset> <UnCompSize> <Name>');
  55. Write(' ');
  56. Write(ASection);
  57. Write(' ');
  58. WriteStr(IntToStr(Offset), 10);
  59. Write(' ');
  60. WriteStr(IntToStr(UncompressedSize), 11);
  61. Write(' ');
  62. WriteLn(Name);
  63. end;
  64. // Start of program
  65. begin
  66. if Paramcount < 1 then begin
  67. WriteLn(' Usage: chmls filename.chm [section number]');
  68. exit;
  69. end;
  70. if ParamCount > 1 then Section := StrToInt(ParamStr(2));
  71. Stream := TFileStream.Create(ParamStr(1), fmOpenRead);
  72. JunkObject := TJunkObject.Create;
  73. ITS:= TITSFReader.Create(Stream, True);
  74. I := 0;
  75. ITS.GetCompleteFileList(@JunkObject.OnFileEntry);
  76. WriteLn('Total Files in chm: ', I);
  77. ITS.Free;
  78. JunkObject.Free;
  79. end.