summaryrefslogtreecommitdiff
path: root/fpcsrc/utils/fpmc/readmsg.pp
blob: 865bc2f4c18a4fa49b3a09135bfa2ef88d87365d (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
{
    This file is part of the Free Pascal run time library.
    Copyright (c) 1999-2000 by the Free Pascal development team

    reads and dumps a message file to screen.

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
{$mode objfpc}
{$h+}
program readmsg;

Type
  PCardinal = ^Cardinal;

Var
  F : File of Cardinal;
  PO,PI : PCardinal;
  I,J,Count,C,S : Cardinal;
  Buf : String;

begin
  Assign(F,Paramstr(1));
  Reset(F);
  Read(F,Count);
  Writeln('Message count: ',Count);
  S:=SizeOf(Cardinal)*Count+1;
  GetMem(PO,S);
  GetMem(PI,S);
  FillChar(PI^,S,0);
  FillChar(PO^,S,0);
  For I:=1 to Count do
    begin
    Read(F,C);
    PI[I]:=C;
    Read(F,C);
    If (C<>PI[I]) then
      Writeln('Error in ID: ',C,'<>ID',PI[I])
    else
      Writeln('Found ID ',C);
    Read(F,C);
    PO[I]:=C;
    Writeln('Found offset : ',C);
    end;
  For I:=1 to Count do
    begin
    Seek(F,PO[I] div 4);
    Read(F,S);
    Writeln('Found offset ',S,' at item ',i,' offset ',PO[I]);
    For J:=1 to (S div 4)-1 do
      begin
      Read(F,C);
      Move(C,Buf[J*4-3],4);
      end;
    J:=S-4;
    While Buf[J]=#0 do
      dec(J);
    SetLength(Buf,J);
    Writeln('String (',J,') : ',Buf);
    end;
  Writeln('Seqential read : ');
  Seek(F,PO[1] div 4);
  For I:=1 to Count do
    begin
    Read(F,S);
    Writeln('Found offset ',S,' at item ',i,' offset ',FilePos(F));
    For J:=1 to (S div 4)-1 do
      begin
      Read(F,C);
      Move(C,Buf[J*4-3],4);
      end;
    J:=S-4;
    While Buf[J]=#0 do
      dec(J);
    SetLength(Buf,J);
    Writeln('String (',J,') : ',Buf);
    end;
  Close(F);
end.