codetools: added example for parsing ppu files

git-svn-id: trunk@15583 -
This commit is contained in:
mattias 2008-06-27 10:27:06 +00:00
parent eed06a0312
commit 26812face7
4 changed files with 74 additions and 10 deletions

View File

@ -24,6 +24,7 @@ uses
CodeCache, KeywordFuncLists, SourceLog, ExprEval, DefineTemplates, FileProcs,
CodeToolsStrConsts, DirectoryCacher, CCodeParserTool, H2PasTool,
MultiKeyWordListTool, ResourceCodeTool, CodeToolsStructs, CacheCodeTools,
PPUParser,
// fast xml units, changes not merged in current fpc
Laz_DOM, Laz_XMLCfg, Laz_XMLRead, Laz_XMLWrite, Laz_XMLStreaming;

View File

@ -6,6 +6,7 @@
<General>
<SessionStorage Value="InIDEConfig"/>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=""/>
</General>
<VersionInfo>
@ -23,6 +24,11 @@
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="CodeTools"/>
</Item1>
</RequiredPackages>
<Units Count="1">
<Unit0>
<Filename Value="ppudependencies.lpr"/>

View File

@ -28,12 +28,26 @@ program PPUDependencies;
{$mode objfpc}{$H+}
uses
Classes, SysUtils;
Classes, SysUtils, PPUParser;
const
ConfigFilename = 'codetools.config';
var
PPU: TPPU;
Filename: String;
begin
CodeToolBoss.SimpleInit(ConfigFilename);
if (Paramcount<1) then begin
writeln('Usage:');
writeln(' ',ParamStr(0),' <ppu filename>');
Halt;
end;
Filename:=ParamStr(1);
PPU:=TPPU.Create;
try
PPU.LoadFromFile(Filename);
PPU.Dump('');
finally
PPU.Free;
end;
end.

View File

@ -35,7 +35,7 @@ unit PPUParser;
interface
uses
Classes, SysUtils;
Classes, SysUtils, FileProcs;
const
PPUIsEndianBig = {$IFDEF ENDIAN_BIG}True{$ELSE}False{$ENDIF};
@ -178,13 +178,16 @@ type
FHeader: tppuheader;
procedure ReadHeader;
procedure InitInput(s: TStream);
procedure ReadBuf(Buf; Count: longint);
procedure ReadBuf(var Buf; Count: longint);
procedure ReadWord(out w: word);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure LoadFromStream(s: TStream);
procedure LoadFromFile(const Filename: string);
procedure Dump(const Prefix: string = '');
procedure DumpHeader(const Prefix: string = '');
property InputStream: TStream read FInputStream;
end;
@ -217,10 +220,10 @@ end;
procedure TPPU.InitInput(s: TStream);
begin
FInputStream:=s;
fChangeEndian:=not PPUIsEndianBig;
fChangeEndian:=PPUIsEndianBig;
end;
procedure TPPU.ReadBuf(Buf; Count: longint);
procedure TPPU.ReadBuf(var Buf; Count: longint);
begin
FInputStream.Read(Buf,Count);
end;
@ -244,7 +247,7 @@ end;
procedure TPPU.Clear;
begin
FillByte(FHeader,SizeOf(FHeader),0);
end;
procedure TPPU.LoadFromStream(s: TStream);
@ -252,6 +255,46 @@ begin
Clear;
InitInput(s);
ReadHeader;
FInputStream:=nil;
end;
procedure TPPU.LoadFromFile(const Filename: string);
var
ms: TMemoryStream;
fs: TFileStream;
begin
fs:=TFileStream.Create(Filename,fmOpenRead);
ms:=TMemoryStream.Create;
try
ms.CopyFrom(fs,fs.Size);
ms.Position:=0;
LoadFromStream(ms);
finally
ms.Free;
fs.Free;
end;
end;
procedure TPPU.Dump(const Prefix: string);
begin
DebugLn([Prefix+'TPPU.Dump ']);
DumpHeader(Prefix+' ');
end;
procedure TPPU.DumpHeader(const Prefix: string);
begin
DebugLn([Prefix,'Header']);
DebugLn([Prefix,' ID=',String(FHeader.ID)]);
DebugLn([Prefix,' Ver=',String(FHeader.ver)]);
DebugLn([Prefix,' Compiler=',FHeader.compiler]);
DebugLn([Prefix,' CPU=',FHeader.cpu]);
DebugLn([Prefix,' Target=',FHeader.target]);
DebugLn([Prefix,' Flags=',FHeader.flags]);
DebugLn([Prefix,' Size=',FHeader.size]);
DebugLn([Prefix,' Checksum=',FHeader.checksum]);
DebugLn([Prefix,' Interface_CheckSum=',FHeader.interface_checksum]);
DebugLn([Prefix,' deflistsize=',FHeader.deflistsize]);
DebugLn([Prefix,' symlistsize=',FHeader.symlistsize]);
end;
end.