summaryrefslogtreecommitdiff
path: root/compiler/ppu.pas
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/ppu.pas')
-rw-r--r--compiler/ppu.pas111
1 files changed, 70 insertions, 41 deletions
diff --git a/compiler/ppu.pas b/compiler/ppu.pas
index 1e7f04252f..3e873f1c6f 100644
--- a/compiler/ppu.pas
+++ b/compiler/ppu.pas
@@ -26,7 +26,7 @@ unit ppu;
interface
uses
- globtype,constexp;
+ globtype,constexp,cstreams;
{ Also write the ppu if only crc if done, this can be used with ppudump to
see the differences between the intf and implementation }
@@ -186,9 +186,11 @@ type
nr : byte;
end;
+ { tppufile }
+
tppufile=class
private
- f : file;
+ f : TCCustomFileStream;
mode : byte; {0 - Closed, 1 - Reading, 2 - Writing}
fname : string;
fsize : integer;
@@ -260,6 +262,7 @@ type
function getaword:aword;
function getreal:ppureal;
function getstring:string;
+ function getansistring:ansistring;
procedure getnormalset(var b);
procedure getsmallset(var b);
function skipuntilentry(untilb:byte):boolean;
@@ -280,10 +283,11 @@ type
procedure putaword(i:aword);
procedure putreal(d:ppureal);
procedure putstring(const s:string);
+ procedure putansistring(const s:ansistring);
procedure putnormalset(const b);
procedure putsmallset(const b);
- procedure tempclose;
- function tempopen:boolean;
+ procedure tempclose; // MG: not used, obsolete?
+ function tempopen:boolean; // MG: not used, obsolete?
end;
implementation
@@ -356,10 +360,7 @@ begin
if Mode<>0 then
begin
Flush;
- {$I-}
- system.close(f);
- {$I+}
- if ioresult<>0 then;
+ f.Free;
Mode:=0;
closed:=true;
end;
@@ -415,21 +416,17 @@ var
i : integer;
begin
openfile:=false;
- assign(f,fname);
- ofmode:=filemode;
- filemode:=$0;
- {$I-}
- reset(f,1);
- {$I+}
- filemode:=ofmode;
- if ioresult<>0 then
- exit;
+ try
+ f:=CFileStreamClass.Create(fname,fmOpenRead)
+ except
+ exit;
+ end;
closed:=false;
{read ppuheader}
- fsize:=filesize(f);
+ fsize:=f.Size;
if fsize<sizeof(tppuheader) then
exit;
- blockread(f,header,sizeof(tppuheader),i);
+ i:=f.Read(header,sizeof(tppuheader));
{ The header is always stored in little endian order }
{ therefore swap if on a big endian machine }
{$IFDEF ENDIAN_BIG}
@@ -478,7 +475,7 @@ end;
procedure tppufile.reloadbuf;
begin
inc(bufstart,bufsize);
- blockread(f,buf^,ppubufsize,bufsize);
+ bufsize:=f.Read(buf^,ppubufsize);
bufidx:=0;
end;
@@ -789,6 +786,22 @@ begin
end;
+function tppufile.getansistring: ansistring;
+var
+ l : longint;
+begin
+ l:=getlongint;
+ if entryidx+l>entry.size then
+ begin
+ error:=true;
+ exit;
+ end;
+ SetLength(Result,l);
+ ReadData(result[1],l);
+ inc(entryidx,l);
+end;
+
+
procedure tppufile.getsmallset(var b);
var
i : longint;
@@ -827,6 +840,8 @@ end;
*****************************************************************************}
function tppufile.createfile:boolean;
+var
+ ok: boolean;
begin
createfile:=false;
{$ifdef INTFPPU}
@@ -838,24 +853,26 @@ begin
{$endif}
if not crc_only then
begin
- assign(f,fname);
{$ifdef MACOS}
{FPas is FreePascal's creator code on MacOS. See systems/mac_crea.txt}
SetDefaultMacOSCreator('FPas');
SetDefaultMacOSFiletype('FPPU');
{$endif}
- {$I-}
- rewrite(f,1);
- {$I+}
+ ok:=false;
+ try
+ f:=CFileStreamClass.Create(fname,fmCreate);
+ ok:=true;
+ except
+ end;
{$ifdef MACOS}
SetDefaultMacOSCreator('MPS ');
SetDefaultMacOSFiletype('TEXT');
{$endif}
- if ioresult<>0 then
+ if not ok then
exit;
Mode:=2;
{write header for sure}
- blockwrite(f,header,sizeof(tppuheader));
+ f.Write(header,sizeof(tppuheader));
end;
bufsize:=ppubufsize;
bufstart:=sizeof(tppuheader);
@@ -904,10 +921,10 @@ begin
header.symlistsize:=swapendian(header.symlistsize);
{$endif not FPC_BIG_ENDIAN}
{ write header and restore filepos after it }
- opos:=filepos(f);
- seek(f,0);
- blockwrite(f,header,sizeof(tppuheader));
- seek(f,opos);
+ opos:=f.Position;
+ f.Position:=0;
+ f.Write(header,sizeof(tppuheader));
+ f.Position:=opos;
end;
@@ -915,7 +932,7 @@ procedure tppufile.writebuf;
begin
if not crc_only and
(bufidx <> 0) then
- blockwrite(f,buf^,bufidx);
+ f.Write(buf^,bufidx);
inc(bufstart,bufidx);
bufidx:=0;
end;
@@ -985,10 +1002,10 @@ begin
{flush to be sure}
WriteBuf;
{write entry}
- opos:=filepos(f);
- seek(f,entrystart);
- blockwrite(f,entry,sizeof(tppuentry));
- seek(f,opos);
+ opos:=f.Position;
+ f.Position:=entrystart;
+ f.write(entry,sizeof(tppuentry));
+ f.Position:=opos;
end;
entrybufstart:=bufstart;
end
@@ -1131,6 +1148,16 @@ procedure tppufile.putstring(const s:string);
end;
+procedure tppufile.putansistring(const s: ansistring);
+ var
+ l : longint;
+ begin
+ l:=length(s);
+ putdata(l,4);
+ putdata(s[1],l);
+ end;
+
+
procedure tppufile.putsmallset(const b);
var
l : longint;
@@ -1152,11 +1179,8 @@ procedure tppufile.tempclose;
begin
if not closed then
begin
- closepos:=filepos(f);
- {$I-}
- system.close(f);
- {$I+}
- if ioresult<>0 then;
+ closepos:=f.Position;
+ f.Free;
closed:=true;
tempclosed:=true;
end;
@@ -1170,6 +1194,10 @@ function tppufile.tempopen:boolean;
tempopen:=false;
if not closed or not tempclosed then
exit;
+ // MG: not sure, if this is correct
+
+ f.Position:=0;
+ (*
ofm:=filemode;
filemode:=0;
{$I-}
@@ -1178,11 +1206,12 @@ function tppufile.tempopen:boolean;
filemode:=ofm;
if ioresult<>0 then
exit;
+ *)
closed:=false;
tempclosed:=false;
{ restore state }
- seek(f,closepos);
+ f.Position:=closepos;
tempopen:=true;
end;