summaryrefslogtreecommitdiff
path: root/docview/src/docdump/readextfiles.pas
blob: 6ea979d9ec0901cb9f6245ca49e3f0fa388c89aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
  Dumps the names of external database (help) files referenced by this file
}
unit readextfiles;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, IPFFileFormatUnit, filestreamhelper;

procedure ProcessExtFiles(AIn: TFileStream; AOut: TFileTextStream);


implementation

uses
  readheader;

procedure ProcessExtFiles(AIn: TFileStream; AOut: TFileTextStream);
var
  count: integer;
  name: string;
  pData: pointer;
  p: pointer;
  pLength: pByte;
begin
  AOut.WriteLn('');
  AOut.WriteLn('External File References');

  if eHdr.NumDataBase > 0 then
  begin
    pData := nil;
    AIn.Seek(eHdr.DataBaseOffset, soBeginning);
    GetMem(pData, eHdr.DataBaseSize);     // allocate temp space for data
    AIn.Read(pData^, eHdr.DataBaseSize);  // read all data in one shot
    p := pData; // p is our incrementing position in the data
    for count := 0 to eHdr.NumDataBase-1 do
    begin
      pLength := p;       // length byte, including itself
      SetString(name, p+1, pLength^-1);   // use length value minus the length byte to get the string length
      AOut.WriteLn(Format('  File #%d: %s', [count, name]));
      inc(p, pLength^);   // skip to next entry using full length (including length byte)
    end;
    FreeMem(pData, eHdr.DataBaseSize);    // free allocated space
  end
  else
    AOut.WriteLn('  No external file references found');
end;

end.