mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-05 16:49:26 +01:00
+ tppufile.tempclose and tempopen added
* some changes so that nothing is writtedn to disk while
calculating CRC only
This commit is contained in:
parent
03263b9285
commit
3d12f8119a
121
compiler/ppu.pas
121
compiler/ppu.pas
@ -169,7 +169,10 @@ type
|
|||||||
{$ifdef Test_Double_checksum}
|
{$ifdef Test_Double_checksum}
|
||||||
crcindex : longint;
|
crcindex : longint;
|
||||||
crc_index : longint;
|
crc_index : longint;
|
||||||
crc_test : pcrc_array;
|
crcindex2 : longint;
|
||||||
|
crc_index2 : longint;
|
||||||
|
crc_test,crc_test2 : pcrc_array;
|
||||||
|
|
||||||
{$endif def Test_Double_checksum}
|
{$endif def Test_Double_checksum}
|
||||||
interface_crc : longint;
|
interface_crc : longint;
|
||||||
do_interface_crc : boolean;
|
do_interface_crc : boolean;
|
||||||
@ -186,7 +189,8 @@ type
|
|||||||
entryidx : longint;
|
entryidx : longint;
|
||||||
entry : tppuentry;
|
entry : tppuentry;
|
||||||
entrytyp : byte;
|
entrytyp : byte;
|
||||||
|
closed : boolean;
|
||||||
|
closepos : longint;
|
||||||
constructor init(fn:string);
|
constructor init(fn:string);
|
||||||
destructor done;
|
destructor done;
|
||||||
procedure flush;
|
procedure flush;
|
||||||
@ -226,6 +230,8 @@ type
|
|||||||
procedure putstring(s:string);
|
procedure putstring(s:string);
|
||||||
procedure putnormalset(var b);
|
procedure putnormalset(var b);
|
||||||
procedure putsmallset(var b);
|
procedure putsmallset(var b);
|
||||||
|
procedure tempclose;
|
||||||
|
function tempopen:boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -331,6 +337,7 @@ begin
|
|||||||
Mode:=0;
|
Mode:=0;
|
||||||
NewHeader;
|
NewHeader;
|
||||||
Error:=false;
|
Error:=false;
|
||||||
|
closed:=true;
|
||||||
getmem(buf,ppubufsize);
|
getmem(buf,ppubufsize);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -361,6 +368,7 @@ begin
|
|||||||
{$I+}
|
{$I+}
|
||||||
i:=ioresult;
|
i:=ioresult;
|
||||||
Mode:=0;
|
Mode:=0;
|
||||||
|
closed:=true;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -424,6 +432,7 @@ begin
|
|||||||
filemode:=ofmode;
|
filemode:=ofmode;
|
||||||
if ioresult<>0 then
|
if ioresult<>0 then
|
||||||
exit;
|
exit;
|
||||||
|
closed:=false;
|
||||||
{read ppuheader}
|
{read ppuheader}
|
||||||
fsize:=filesize(f);
|
fsize:=filesize(f);
|
||||||
if fsize<sizeof(tppuheader) then
|
if fsize<sizeof(tppuheader) then
|
||||||
@ -691,15 +700,18 @@ end;
|
|||||||
function tppufile.create:boolean;
|
function tppufile.create:boolean;
|
||||||
begin
|
begin
|
||||||
create:=false;
|
create:=false;
|
||||||
assign(f,fname);
|
if not crc_only then
|
||||||
{$I-}
|
begin
|
||||||
rewrite(f,1);
|
assign(f,fname);
|
||||||
{$I+}
|
{$I-}
|
||||||
if ioresult<>0 then
|
rewrite(f,1);
|
||||||
exit;
|
{$I+}
|
||||||
Mode:=2;
|
if ioresult<>0 then
|
||||||
{write header for sure}
|
exit;
|
||||||
blockwrite(f,header,sizeof(tppuheader));
|
Mode:=2;
|
||||||
|
{write header for sure}
|
||||||
|
blockwrite(f,header,sizeof(tppuheader));
|
||||||
|
end;
|
||||||
bufsize:=ppubufsize;
|
bufsize:=ppubufsize;
|
||||||
bufstart:=sizeof(tppuheader);
|
bufstart:=sizeof(tppuheader);
|
||||||
bufidx:=0;
|
bufidx:=0;
|
||||||
@ -735,7 +747,8 @@ end;
|
|||||||
|
|
||||||
procedure tppufile.writebuf;
|
procedure tppufile.writebuf;
|
||||||
begin
|
begin
|
||||||
blockwrite(f,buf^,bufidx);
|
if not crc_only then
|
||||||
|
blockwrite(f,buf^,bufidx);
|
||||||
inc(bufstart,bufidx);
|
inc(bufstart,bufidx);
|
||||||
bufidx:=0;
|
bufidx:=0;
|
||||||
end;
|
end;
|
||||||
@ -747,6 +760,8 @@ var
|
|||||||
left,
|
left,
|
||||||
idx : longint;
|
idx : longint;
|
||||||
begin
|
begin
|
||||||
|
if crc_only then
|
||||||
|
exit;
|
||||||
p:=pchar(@b);
|
p:=pchar(@b);
|
||||||
idx:=0;
|
idx:=0;
|
||||||
while len>0 do
|
while len>0 do
|
||||||
@ -798,13 +813,16 @@ begin
|
|||||||
{it's already been sent to disk ?}
|
{it's already been sent to disk ?}
|
||||||
if entrybufstart<>bufstart then
|
if entrybufstart<>bufstart then
|
||||||
begin
|
begin
|
||||||
{flush to be sure}
|
if not crc_only then
|
||||||
WriteBuf;
|
begin
|
||||||
{write entry}
|
{flush to be sure}
|
||||||
opos:=filepos(f);
|
WriteBuf;
|
||||||
seek(f,entrystart);
|
{write entry}
|
||||||
blockwrite(f,entry,sizeof(tppuentry));
|
opos:=filepos(f);
|
||||||
seek(f,opos);
|
seek(f,entrystart);
|
||||||
|
blockwrite(f,entry,sizeof(tppuentry));
|
||||||
|
seek(f,opos);
|
||||||
|
end;
|
||||||
entrybufstart:=bufstart;
|
entrybufstart:=bufstart;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -820,6 +838,27 @@ begin
|
|||||||
if do_crc then
|
if do_crc then
|
||||||
begin
|
begin
|
||||||
crc:=UpdateCrc32(crc,b,len);
|
crc:=UpdateCrc32(crc,b,len);
|
||||||
|
{$ifdef Test_Double_checksum}
|
||||||
|
if crc_only then
|
||||||
|
begin
|
||||||
|
crc_test2^[crc_index2]:=crc;
|
||||||
|
{$ifdef Test_Double_checksum_write}
|
||||||
|
Writeln(CRCFile,crc);
|
||||||
|
{$endif Test_Double_checksum_write}
|
||||||
|
if crc_index2<crc_array_size then
|
||||||
|
inc(crc_index2);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if (crcindex2<crc_array_size) and (crcindex2<crc_index2) and
|
||||||
|
(crc_test2^[crcindex2]<>crc) then
|
||||||
|
Def_comment(V_Warning,'impl CRC changed');
|
||||||
|
{$ifdef Test_Double_checksum_write}
|
||||||
|
Writeln(CRCFile,crc);
|
||||||
|
{$endif Test_Double_checksum_write}
|
||||||
|
inc(crcindex2);
|
||||||
|
end;
|
||||||
|
{$endif def Test_Double_checksum}
|
||||||
if do_interface_crc then
|
if do_interface_crc then
|
||||||
begin
|
begin
|
||||||
interface_crc:=UpdateCrc32(interface_crc,b,len);
|
interface_crc:=UpdateCrc32(interface_crc,b,len);
|
||||||
@ -901,10 +940,52 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure tppufile.tempclose;
|
||||||
|
var
|
||||||
|
i : word;
|
||||||
|
begin
|
||||||
|
if not closed then
|
||||||
|
begin
|
||||||
|
closepos:=filepos(f);
|
||||||
|
{$I-}
|
||||||
|
system.close(f);
|
||||||
|
{$I+}
|
||||||
|
i:=ioresult;
|
||||||
|
closed:=true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function tppufile.tempopen:boolean;
|
||||||
|
var
|
||||||
|
ofm : byte;
|
||||||
|
begin
|
||||||
|
tempopen:=false;
|
||||||
|
if not closed then
|
||||||
|
exit;
|
||||||
|
ofm:=filemode;
|
||||||
|
filemode:=0;
|
||||||
|
{$I-}
|
||||||
|
reset(f,1);
|
||||||
|
{$I+}
|
||||||
|
filemode:=ofm;
|
||||||
|
if ioresult<>0 then
|
||||||
|
exit;
|
||||||
|
closed:=false;
|
||||||
|
{ restore state }
|
||||||
|
seek(f,closepos);
|
||||||
|
tempopen:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.39 1999-08-24 12:01:36 michael
|
Revision 1.40 1999-08-27 10:48:40 pierre
|
||||||
|
+ tppufile.tempclose and tempopen added
|
||||||
|
* some changes so that nothing is writtedn to disk while
|
||||||
|
calculating CRC only
|
||||||
|
|
||||||
|
Revision 1.39 1999/08/24 12:01:36 michael
|
||||||
+ changes for resourcestrings
|
+ changes for resourcestrings
|
||||||
|
|
||||||
Revision 1.38 1999/08/15 10:47:48 peter
|
Revision 1.38 1999/08/15 10:47:48 peter
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user