mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 19:49:22 +02:00
+ Mac linebreak (#13) support for readln
This commit is contained in:
parent
99cf60d6a7
commit
1c7978a96b
@ -712,6 +712,7 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
Procedure ReadLn_End(var f : TextRec);[Public,Alias:'FPC_READLN_END'];
|
Procedure ReadLn_End(var f : TextRec);[Public,Alias:'FPC_READLN_END'];
|
||||||
|
var prev: char;
|
||||||
Begin
|
Begin
|
||||||
{ Check error and if file is open and load buf if empty }
|
{ Check error and if file is open and load buf if empty }
|
||||||
If (InOutRes<>0) then
|
If (InOutRes<>0) then
|
||||||
@ -724,20 +725,40 @@ Begin
|
|||||||
InOutRes:=104;
|
InOutRes:=104;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
If f.BufPos>=f.BufEnd Then
|
||||||
|
begin
|
||||||
|
FileFunc(f.InOutFunc)(f);
|
||||||
|
if (f.BufPos>=f.BufEnd) and
|
||||||
|
{ Flush if set }
|
||||||
|
(f.FlushFunc<>nil) then
|
||||||
|
FileFunc(f.FlushFunc)(f);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
repeat
|
repeat
|
||||||
If f.BufPos>=f.BufEnd Then
|
prev := f.BufPtr^[f.BufPos];
|
||||||
|
inc(f.BufPos);
|
||||||
|
{ no system uses #10#13 as line seperator (#10 = *nix, #13 = Mac, }
|
||||||
|
{ #13#10 = Dos), so if we've got #10, we can safely exit }
|
||||||
|
if prev = #10 then
|
||||||
|
exit;
|
||||||
|
If f.BufPos>=f.BufEnd Then
|
||||||
begin
|
begin
|
||||||
FileFunc(f.InOutFunc)(f);
|
FileFunc(f.InOutFunc)(f);
|
||||||
if f.BufPos>=f.BufEnd then
|
if (f.BufPos>=f.BufEnd) and
|
||||||
break;
|
{ Flush if set }
|
||||||
|
(f.FlushFunc<>nil) then
|
||||||
|
FileFunc(f.FlushFunc)(f);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
if (prev=#13) then
|
||||||
|
{ is there also a #10 after it? }
|
||||||
|
begin
|
||||||
|
if (f.BufPtr^[f.BufPos]=#10) then
|
||||||
|
{ yes, skip that one as well }
|
||||||
|
inc(f.BufPos);
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
inc(f.BufPos);
|
|
||||||
if (f.BufPtr^[f.BufPos-1]=#10) then
|
|
||||||
exit;
|
|
||||||
until false;
|
until false;
|
||||||
{ Flush if set }
|
|
||||||
if f.FlushFunc<>nil then
|
|
||||||
FileFunc(f.FlushFunc)(f);
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
@ -774,21 +795,17 @@ Begin
|
|||||||
maxp:=@f.Bufptr^[f.BufEnd];
|
maxp:=@f.Bufptr^[f.BufEnd];
|
||||||
startp:=p;
|
startp:=p;
|
||||||
{ search linefeed }
|
{ search linefeed }
|
||||||
while (p<maxp) and (P^<>#10) do
|
while (p<maxp) and not(P^ in [#10,#13]) do
|
||||||
inc(p);
|
inc(p);
|
||||||
{ calculate read bytes }
|
{ calculate read bytes }
|
||||||
len:=p-startp;
|
len:=p-startp;
|
||||||
inc(f.BufPos,Len);
|
inc(f.BufPos,Len);
|
||||||
Move(startp^,s[sPos],Len);
|
Move(startp^,s[sPos],Len);
|
||||||
inc(sPos,Len);
|
inc(sPos,Len);
|
||||||
{ was it a LF? then leave }
|
{ was it a LF or CR? then leave }
|
||||||
if (spos=MaxLen) or
|
if (spos=MaxLen) or
|
||||||
((p<maxp) and (p^=#10)) then
|
((p<maxp) and (p^ in [#10,#13])) then
|
||||||
begin
|
break;
|
||||||
if (p^=#10) and (spos>0) and (s[spos-1]=#13) then
|
|
||||||
dec(sPos);
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
until false;
|
until false;
|
||||||
ReadPCharLen:=spos;
|
ReadPCharLen:=spos;
|
||||||
End;
|
End;
|
||||||
@ -999,7 +1016,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.63 2000-01-07 16:41:36 daniel
|
Revision 1.64 2000-01-08 17:08:36 jonas
|
||||||
|
+ Mac linebreak (#13) support for readln
|
||||||
|
|
||||||
|
Revision 1.63 2000/01/07 16:41:36 daniel
|
||||||
* copyright 2000
|
* copyright 2000
|
||||||
|
|
||||||
Revision 1.62 2000/01/07 16:32:25 daniel
|
Revision 1.62 2000/01/07 16:32:25 daniel
|
||||||
|
Loading…
Reference in New Issue
Block a user