summaryrefslogtreecommitdiff
path: root/docview/src/docdump/docdump.lpr
blob: a642b0c0987c724bfd066503788852dec792eff1 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{
  Dumps the structure of an OS/2 IPF help file
}
program docdump;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, IPFFileFormatUnit, IPFEscapeCodes, CustApp, readheader,
  filestreamhelper, readextfiles, readstrings, iterator_intf, iterator_impl,
  readnlsdata, readfonts, readcontrols, readtoc, u_Tools, readdictionary;

type

  { TDocDump }

  TDocDump = class(TCustomApplication)
  private
    FIn: TFileStream;
    FOut: TFileTextStream;
  protected
    procedure DoRun; override;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    procedure WriteHelp; virtual;
  end;

{ TDocDump }

procedure TDocDump.DoRun;
var
  ErrorMsg: String;
begin
  // quick check parameters
  ErrorMsg:=CheckOptions('h','help');
  if ErrorMsg<>'' then begin
    ShowException(Exception.Create(ErrorMsg));
    Terminate;
    Exit;
  end;

  // parse parameters
  if HasOption('h','help') then begin
    WriteHelp;
    Terminate;
    Exit;
  end;

  FIn   := TFileStream.Create(ParamStr(1), fmOpenRead);
  FOut  := TFileTextStream.Create(ExtractFileName(ParamStr(1))+'.txt', fmCreate);
  try
    FOut.WriteLn(Format('File name: %s (%d bytes)', [ExtractFileName(ParamStr(1)), FIn.Size]));
    ProcessHeader(FIn, FOut);
    ProcessExtFiles(FIn, FOut);
    ProcessStringsTable(FIn, FOut);
    ProcessNLSData(FIn, FOut);
    ProcessFonts(FIn, FOut);
    ProcessControls(FIn, FOut);
    ProcessTOC(FIn, FOut);
    ProcessDictionary(FIn, FOut);
  finally
    FIn.Free;
    FOut.Free;
  end;
  // stop program loop
  Terminate;
end;

constructor TDocDump.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  StopOnException:=True;
end;

destructor TDocDump.Destroy;
begin
  inherited Destroy;
end;

procedure TDocDump.WriteHelp;
begin
  { add your help code here }
  writeln('Usage: ',ExeName,' -h');
end;

var
  Application: TDocDump;


begin
  Application:=TDocDump.Create(nil);
  Application.Run;
  Application.Free;
end.