mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 00:09:26 +02:00
* fixes handling of typed files in iso mode
git-svn-id: trunk@26436 -
This commit is contained in:
parent
e6a9e385d3
commit
e841027a48
@ -1044,7 +1044,8 @@ implementation
|
|||||||
|
|
||||||
{Read/write for typed files.}
|
{Read/write for typed files.}
|
||||||
|
|
||||||
const procprefixes:array[boolean] of string[15]=('fpc_typed_write','fpc_typed_read');
|
const procprefixes:array[boolean,boolean] of string[19]=(('fpc_typed_write','fpc_typed_read'),
|
||||||
|
('fpc_typed_write','fpc_typed_read_iso'));
|
||||||
procnamesdisplay:array[boolean,boolean] of string[8] = (('Write','Read'),('WriteStr','ReadStr'));
|
procnamesdisplay:array[boolean,boolean] of string[8] = (('Write','Read'),('WriteStr','ReadStr'));
|
||||||
|
|
||||||
var found_error,do_read,is_rwstr:boolean;
|
var found_error,do_read,is_rwstr:boolean;
|
||||||
@ -1134,7 +1135,7 @@ implementation
|
|||||||
{ since the parameters are in the correct order, we have to insert }
|
{ since the parameters are in the correct order, we have to insert }
|
||||||
{ the statements always at the end of the current block }
|
{ the statements always at the end of the current block }
|
||||||
addstatement(Tstatementnode(newstatement),
|
addstatement(Tstatementnode(newstatement),
|
||||||
Ccallnode.createintern(procprefixes[do_read],para
|
Ccallnode.createintern(procprefixes[m_iso in current_settings.modeswitches,do_read],para
|
||||||
));
|
));
|
||||||
|
|
||||||
{ if we used a temp, free it }
|
{ if we used a temp, free it }
|
||||||
|
@ -1781,11 +1781,21 @@ implementation
|
|||||||
|
|
||||||
{ iso file buf access? }
|
{ iso file buf access? }
|
||||||
if (m_iso in current_settings.modeswitches) and
|
if (m_iso in current_settings.modeswitches) and
|
||||||
(p1.resultdef.typ=filedef) and
|
(p1.resultdef.typ=filedef) then
|
||||||
(tfiledef(p1.resultdef).filetyp=ft_text) then
|
|
||||||
begin
|
begin
|
||||||
p1:=cderefnode.create(ccallnode.createintern('fpc_getbuf',ccallparanode.create(p1,nil)));
|
case tfiledef(p1.resultdef).filetyp of
|
||||||
typecheckpass(p1);
|
ft_text:
|
||||||
|
begin
|
||||||
|
p1:=cderefnode.create(ccallnode.createintern('fpc_getbuf_text',ccallparanode.create(p1,nil)));
|
||||||
|
typecheckpass(p1);
|
||||||
|
end;
|
||||||
|
ft_typed:
|
||||||
|
begin
|
||||||
|
p1:=cderefnode.create(ctypeconvnode.create_internal(ccallnode.createintern('fpc_getbuf_typedfile',ccallparanode.create(p1,nil)),
|
||||||
|
getpointerdef(tfiledef(p1.resultdef).typedfiledef)));
|
||||||
|
typecheckpass(p1);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else if (p1.resultdef.typ<>pointerdef) then
|
else if (p1.resultdef.typ<>pointerdef) then
|
||||||
begin
|
begin
|
||||||
|
@ -2824,13 +2824,19 @@ implementation
|
|||||||
procedure tfiledef.setsize;
|
procedure tfiledef.setsize;
|
||||||
begin
|
begin
|
||||||
case filetyp of
|
case filetyp of
|
||||||
ft_text :
|
ft_text:
|
||||||
savesize:=search_system_type('TEXTREC').typedef.size;
|
savesize:=search_system_type('TEXTREC').typedef.size;
|
||||||
ft_typed,
|
ft_typed:
|
||||||
ft_untyped :
|
begin
|
||||||
|
savesize:=search_system_type('FILEREC').typedef.size;
|
||||||
|
{ allocate put/get buffer in iso mode }
|
||||||
|
if m_iso in current_settings.modeswitches then
|
||||||
|
inc(savesize,typedfiledef.size);
|
||||||
|
end;
|
||||||
|
ft_untyped:
|
||||||
savesize:=search_system_type('FILEREC').typedef.size;
|
savesize:=search_system_type('FILEREC').typedef.size;
|
||||||
else
|
else
|
||||||
internalerror(2013113001);
|
internalerror(2013113001);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -511,7 +511,8 @@ procedure fpc_Read_Text_Int64_Iso(var f : text; out i : int64); compilerproc;
|
|||||||
Procedure fpc_Read_Text_LongWord(var f : text; out q : longword); compilerproc;
|
Procedure fpc_Read_Text_LongWord(var f : text; out q : longword); compilerproc;
|
||||||
Procedure fpc_Read_Text_LongInt(var f : text; out i : longint); compilerproc;
|
Procedure fpc_Read_Text_LongInt(var f : text; out i : longint); compilerproc;
|
||||||
{$endif CPU16 or CPU8}
|
{$endif CPU16 or CPU8}
|
||||||
function fpc_GetBuf(var f : Text) : pchar; compilerproc;
|
function fpc_GetBuf_Text(var f : Text) : pchar; compilerproc;
|
||||||
|
function fpc_GetBuf_TypedFile(var f : TypedFile) : pointer; compilerproc;
|
||||||
{$endif FPC_HAS_FEATURE_TEXTIO}
|
{$endif FPC_HAS_FEATURE_TEXTIO}
|
||||||
|
|
||||||
{$ifdef FPC_INCLUDE_SOFTWARE_MOD_DIV}
|
{$ifdef FPC_INCLUDE_SOFTWARE_MOD_DIV}
|
||||||
@ -690,6 +691,7 @@ Procedure fpc_reset_typed_iso(var f : TypedFile;Size : Longint); compilerproc;
|
|||||||
Procedure fpc_rewrite_typed_iso(var f : TypedFile;Size : Longint); compilerproc;
|
Procedure fpc_rewrite_typed_iso(var f : TypedFile;Size : Longint); compilerproc;
|
||||||
Procedure fpc_typed_write(TypeSize : Longint;var f : TypedFile;const Buf); compilerproc;
|
Procedure fpc_typed_write(TypeSize : Longint;var f : TypedFile;const Buf); compilerproc;
|
||||||
Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;out Buf); compilerproc;
|
Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;out Buf); compilerproc;
|
||||||
|
Procedure fpc_typed_read_iso(TypeSize : Longint;var f : TypedFile;out Buf); compilerproc;
|
||||||
{$endif FPC_HAS_FEATURE_FILEIO}
|
{$endif FPC_HAS_FEATURE_FILEIO}
|
||||||
|
|
||||||
{$ifdef FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
|
{$ifdef FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
|
||||||
|
@ -40,6 +40,9 @@ unit iso7185;
|
|||||||
Procedure Get(Var t: Text);
|
Procedure Get(Var t: Text);
|
||||||
Procedure Put(Var t: Text);
|
Procedure Put(Var t: Text);
|
||||||
|
|
||||||
|
Procedure Get(Var f: TypedFile);
|
||||||
|
Procedure Put(Var f: TypedFile);
|
||||||
|
|
||||||
Function Eof(var f:TypedFile): Boolean;
|
Function Eof(var f:TypedFile): Boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -79,10 +82,17 @@ unit iso7185;
|
|||||||
var
|
var
|
||||||
OldCtrlZMarksEof : Boolean;
|
OldCtrlZMarksEof : Boolean;
|
||||||
Begin
|
Begin
|
||||||
OldCtrlZMarksEof:=CtrlZMarksEOF;
|
{ not sure if this is correct, but we are always at eof when
|
||||||
CtrlZMarksEof:=false;
|
writing to a file }
|
||||||
Eof:=System.Eof(t);
|
if TextRec(t).mode=fmOutput then
|
||||||
CtrlZMarksEof:=OldCtrlZMarksEOF;
|
Eof:=true
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
OldCtrlZMarksEof:=CtrlZMarksEOF;
|
||||||
|
CtrlZMarksEof:=false;
|
||||||
|
Eof:=System.Eof(t);
|
||||||
|
CtrlZMarksEof:=OldCtrlZMarksEOF;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -109,19 +119,19 @@ unit iso7185;
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
Procedure Page;
|
Procedure Page;[IOCheck];
|
||||||
begin
|
begin
|
||||||
Page(Output);
|
Page(Output);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Procedure Page(var t : Text);
|
Procedure Page(var t : Text);[IOCheck];
|
||||||
Begin
|
Begin
|
||||||
write(#12);
|
write(#12);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
procedure Get(var t : Text);
|
procedure Get(var t : Text);[IOCheck];
|
||||||
var
|
var
|
||||||
c : char;
|
c : char;
|
||||||
Begin
|
Begin
|
||||||
@ -129,7 +139,7 @@ unit iso7185;
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
Procedure Put(var t : Text);
|
Procedure Put(var t : Text);[IOCheck];
|
||||||
type
|
type
|
||||||
FileFunc = Procedure(var t : TextRec);
|
FileFunc = Procedure(var t : TextRec);
|
||||||
begin
|
begin
|
||||||
@ -139,7 +149,20 @@ unit iso7185;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function Eof(var f:TypedFile): Boolean;
|
procedure Get(var f:TypedFile);[IOCheck];
|
||||||
|
Begin
|
||||||
|
if not(eof(f)) then
|
||||||
|
BlockRead(f,(pbyte(@f)+sizeof(FileRec))^,1)
|
||||||
|
End;
|
||||||
|
|
||||||
|
|
||||||
|
Procedure Put(var f:TypedFile);[IOCheck];
|
||||||
|
begin
|
||||||
|
BlockWrite(f,(pbyte(@f)+sizeof(FileRec))^,1)
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Function Eof(var f:TypedFile): Boolean;[IOCheck];
|
||||||
Type
|
Type
|
||||||
UnTypedFile = File;
|
UnTypedFile = File;
|
||||||
Begin
|
Begin
|
||||||
@ -150,8 +173,7 @@ begin
|
|||||||
{ we shouldn't do this because it might confuse user programs, but for now it
|
{ we shouldn't do this because it might confuse user programs, but for now it
|
||||||
is good enough to get pretty unique tmp file names }
|
is good enough to get pretty unique tmp file names }
|
||||||
Randomize;
|
Randomize;
|
||||||
|
{ reset opens with read-only }
|
||||||
|
Filemode:=0;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1724,7 +1724,7 @@ end;
|
|||||||
procedure fpc_Read_Text_Char_intern(var f : Text; out c: char); iocheck; [external name 'FPC_READ_TEXT_CHAR'];
|
procedure fpc_Read_Text_Char_intern(var f : Text; out c: char); iocheck; [external name 'FPC_READ_TEXT_CHAR'];
|
||||||
|
|
||||||
|
|
||||||
function fpc_GetBuf(var f : Text) : pchar; iocheck; compilerproc;
|
function fpc_GetBuf_Text(var f : Text) : pchar; iocheck; compilerproc;
|
||||||
Begin
|
Begin
|
||||||
Result:=@TextRec(f).Bufptr^[TextRec(f).BufEnd];
|
Result:=@TextRec(f).Bufptr^[TextRec(f).BufEnd];
|
||||||
If not CheckRead(f) then
|
If not CheckRead(f) then
|
||||||
|
@ -97,6 +97,7 @@ Begin
|
|||||||
DoAssign(f);
|
DoAssign(f);
|
||||||
|
|
||||||
Reset(UnTypedFile(f),Size);
|
Reset(UnTypedFile(f),Size);
|
||||||
|
BlockRead(UntypedFile(f),(pbyte(@f)+sizeof(FileRec))^,1);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
@ -143,3 +144,19 @@ Begin
|
|||||||
end;
|
end;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
|
Procedure fpc_typed_read_iso(TypeSize : Longint;var f : TypedFile;out Buf);[IOCheck, Public, Alias :'FPC_TYPED_READ_ISO']; compilerproc;
|
||||||
|
var
|
||||||
|
Result : Longint;
|
||||||
|
Begin
|
||||||
|
move((pbyte(@f)+sizeof(TypedFile))^,Buf,TypeSize);
|
||||||
|
if not(eof(f)) then
|
||||||
|
BlockRead(f,(pbyte(@f)+sizeof(FileRec))^,1)
|
||||||
|
End;
|
||||||
|
|
||||||
|
|
||||||
|
function fpc_GetBuf_TypedFile(var f : TypedFile) : pointer; [IOCheck]; compilerproc;
|
||||||
|
Begin
|
||||||
|
Result:=pbyte(@f)+sizeof(TypedFile);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user