+ initial implementation of a FullName field in file records to overcome length limitions of the name field

git-svn-id: trunk@47263 -
This commit is contained in:
florian 2020-10-31 19:54:40 +00:00
parent 3d049a3309
commit 408fc819b3
5 changed files with 94 additions and 3 deletions

View File

@ -35,8 +35,16 @@ Begin
InitFile(F); InitFile(F);
{$ifdef FPC_ANSI_TEXTFILEREC} {$ifdef FPC_ANSI_TEXTFILEREC}
FileRec(f).Name:=ToSingleByteFileSystemEncodedFileName(Name); FileRec(f).Name:=ToSingleByteFileSystemEncodedFileName(Name);
{$ifdef USE_FILEREC_FULLNAME}
if Length(Name)>255 then
RawByteString(FileRec(f).FullName):=Name;
{$endif USE_FILEREC_FULLNAME}
{$else FPC_ANSI_TEXTFILEREC} {$else FPC_ANSI_TEXTFILEREC}
FileRec(f).Name:=Name; FileRec(f).Name:=Name;
{$ifdef USE_FILEREC_FULLNAME}
if Length(Name)>255 then
UnicodeString(FileRec(f).FullName):=Name;
{$endif USE_FILEREC_FULLNAME}
{$endif FPC_ANSI_TEXTFILEREC} {$endif FPC_ANSI_TEXTFILEREC}
{ null terminate, since the name array is regularly used as p(wide)char } { null terminate, since the name array is regularly used as p(wide)char }
FileRec(f).Name[high(FileRec(f).Name)]:=#0; FileRec(f).Name[high(FileRec(f).Name)]:=#0;
@ -54,8 +62,16 @@ Begin
{$ifdef FPC_ANSI_TEXTFILEREC} {$ifdef FPC_ANSI_TEXTFILEREC}
{ ensure the characters in the record's filename are encoded correctly } { ensure the characters in the record's filename are encoded correctly }
FileRec(f).Name:=ToSingleByteFileSystemEncodedFileName(Name); FileRec(f).Name:=ToSingleByteFileSystemEncodedFileName(Name);
{$ifdef USE_FILEREC_FULLNAME}
if Length(Name)>255 then
RawbyteString(FileRec(f).FullName):=Name;
{$endif USE_FILEREC_FULLNAME}
{$else FPC_ANSI_TEXTFILEREC} {$else FPC_ANSI_TEXTFILEREC}
FileRec(f).Name:=Name; FileRec(f).Name:=Name;
{$ifdef USE_FILEREC_FULLNAME}
if Length(Name)>255 then
UnicodeString(FileRec(f).FullName):=Name;
{$endif USE_FILEREC_FULLNAME}
{$endif FPC_ANSI_TEXTFILEREC} {$endif FPC_ANSI_TEXTFILEREC}
{ null terminate, since the name array is regularly used as p(wide)char } { null terminate, since the name array is regularly used as p(wide)char }
FileRec(f).Name[high(FileRec(f).Name)]:=#0; FileRec(f).Name[high(FileRec(f).Name)]:=#0;
@ -119,7 +135,12 @@ Begin
else else
Begin Begin
{ Reopen with filemode 2, to be Tp compatible (PFV) } { Reopen with filemode 2, to be Tp compatible (PFV) }
Do_Open(f,PFileTextRecChar(@FileRec(f).Name),$1002,false); {$ifdef USE_FILEREC_FULLNAME}
if Assigned(FileRec(f).FullName) then
Do_Open(f,FileRec(f).FullName,$1002,false)
else
{$endif USE_FILEREC_FULLNAME}
Do_Open(f,PFileTextRecChar(@FileRec(f).Name),$1002,false);
FileRec(f).RecSize:=l; FileRec(f).RecSize:=l;
End; End;
End; End;
@ -145,7 +166,12 @@ Begin
InOutRes:=2 InOutRes:=2
else else
Begin Begin
Do_Open(f,PFileTextRecChar(@FileRec(f).Name),Filemode,false); {$ifdef USE_FILEREC_FULLNAME}
if Assigned(FileRec(f).FullName) then
Do_Open(f,FileRec(f).FullName,Filemode,false)
else
{$endif USE_FILEREC_FULLNAME}
Do_Open(f,PFileTextRecChar(@FileRec(f).Name),Filemode,false);
FileRec(f).RecSize:=l; FileRec(f).RecSize:=l;
End; End;
End; End;
@ -493,6 +519,9 @@ Begin
end end
else InOutRes:=103; else InOutRes:=103;
end; end;
{$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
UnicodeString(FileRec(f).FullName):='';
{$endif FPC_HAS_FEATURE_ANSISTRINGS}
End; End;
@ -650,3 +679,13 @@ Begin
End; End;
{$endif FPC_HAS_FEATURE_ANSISTRINGS} {$endif FPC_HAS_FEATURE_ANSISTRINGS}
Function GetFullName(var f:File) : UnicodeString;
begin
{$ifdef USE_FILEREC_FULLNAME}
if Assigned(FileRec(f).FullName) then
Result:=UnicodeString(FileRec(f).FullName)
else
{$endif USE_FILEREC_FULLNAME}
Result:=PFileTextRecChar(@FileRec(f).Name);
end;

View File

@ -40,5 +40,8 @@ type
_private : array[1..3 * SizeOf(SizeInt) + 5 * SizeOf (pointer)] of byte; _private : array[1..3 * SizeOf(SizeInt) + 5 * SizeOf (pointer)] of byte;
UserData : array[1..32] of byte; UserData : array[1..32] of byte;
name : array[0..filerecnamelength] of TFileTextRecChar; name : array[0..filerecnamelength] of TFileTextRecChar;
{$ifdef USE_FILEREC_FULLNAME}
FullName : Pointer;
{$endif USE_FILEREC_FULLNAME}
End; End;

View File

@ -87,6 +87,13 @@
{$define FPC_HAS_FEATURE_UNICODESTRINGS} {$define FPC_HAS_FEATURE_UNICODESTRINGS}
{$endif VER2_6} {$endif VER2_6}
{ for now, the presence of unicode strings is just an approximation,
USE_FILEREC_FULLNAME can be also enabled for other targets if
they need file names longer than 255 chars }
{$if defined(FPC_HAS_FEATURE_UNICODESTRINGS)}
{$define USE_FILEREC_FULLNAME}
{$endif defined(FPC_HAS_FEATURE_UNICODESTRINGS)}
{**************************************************************************** {****************************************************************************
Global Types and Constants Global Types and Constants
****************************************************************************} ****************************************************************************}
@ -1372,6 +1379,7 @@ Procedure Seek(var f:File;Pos:Int64);
Function EOF(var f:File):Boolean; Function EOF(var f:File):Boolean;
Procedure Erase(var f:File); Procedure Erase(var f:File);
Procedure Truncate (var F:File); Procedure Truncate (var F:File);
Function GetFullName(var f:File) : UnicodeString;
{$endif FPC_HAS_FEATURE_FILEIO} {$endif FPC_HAS_FEATURE_FILEIO}
@ -1431,6 +1439,7 @@ Procedure SetTextBuf(var f:Text; var Buf; Size:SizeInt);
Procedure SetTextLineEnding(var f:Text; Ending:string); Procedure SetTextLineEnding(var f:Text; Ending:string);
function GetTextCodePage(var T: Text): TSystemCodePage; function GetTextCodePage(var T: Text): TSystemCodePage;
procedure SetTextCodePage(var T: Text; CodePage: TSystemCodePage); procedure SetTextCodePage(var T: Text; CodePage: TSystemCodePage);
Function GetFullName(var T:Text) : UnicodeString;
{$endif FPC_HAS_FEATURE_TEXTIO} {$endif FPC_HAS_FEATURE_TEXTIO}
{**************************************************************************** {****************************************************************************

View File

@ -57,7 +57,12 @@ Begin
exit; exit;
end; end;
End; End;
Do_Open(t,PFileTextRecChar(@t.Name),Flags,False); {$ifdef USE_FILEREC_FULLNAME}
if Assigned(t.FullName) then
Do_Open(t,PFileTextRecChar(t.FullName),Flags,False)
else
{$endif USE_FILEREC_FULLNAME}
Do_Open(t,PFileTextRecChar(@t.Name),Flags,False);
t.CloseFunc:=@FileCloseFunc; t.CloseFunc:=@FileCloseFunc;
t.FlushFunc:=nil; t.FlushFunc:=nil;
if t.Mode=fmInput then if t.Mode=fmInput then
@ -98,8 +103,16 @@ begin
InitText(t); InitText(t);
{$ifdef FPC_ANSI_TEXTFILEREC} {$ifdef FPC_ANSI_TEXTFILEREC}
TextRec(t).Name:=ToSingleByteFileSystemEncodedFileName(S); TextRec(t).Name:=ToSingleByteFileSystemEncodedFileName(S);
{$ifdef USE_FILEREC_FULLNAME}
if length(s)>255 then
RawByteString(TextRec(t).FullName):=ToSingleByteFileSystemEncodedFileName(S);
{$endif USE_FILEREC_FULLNAME}
{$else FPC_ANSI_TEXTFILEREC} {$else FPC_ANSI_TEXTFILEREC}
TextRec(t).Name:=S; TextRec(t).Name:=S;
{$ifdef USE_FILEREC_FULLNAME}
if length(s)>255 then
UnicodeString(TextRec(t).FullName):=S;
{$endif USE_FILEREC_FULLNAME}
{$endif FPC_ANSI_TEXTFILEREC} {$endif FPC_ANSI_TEXTFILEREC}
{ null terminate, since the name array is regularly used as p(wide)char } { null terminate, since the name array is regularly used as p(wide)char }
TextRec(t).Name[high(TextRec(t).Name)]:=#0; TextRec(t).Name[high(TextRec(t).Name)]:=#0;
@ -114,8 +127,16 @@ Begin
{$ifdef FPC_ANSI_TEXTFILEREC} {$ifdef FPC_ANSI_TEXTFILEREC}
{ ensure the characters in the record's filename are encoded correctly } { ensure the characters in the record's filename are encoded correctly }
TextRec(t).Name:=ToSingleByteFileSystemEncodedFileName(S); TextRec(t).Name:=ToSingleByteFileSystemEncodedFileName(S);
{$ifdef USE_FILEREC_FULLNAME}
if length(s)>255 then
RawByteString(TextRec(t).FullName:=ToSingleByteFileSystemEncodedFileName(S);
{$endif USE_FILEREC_FULLNAME}
{$else FPC_ANSI_TEXTFILEREC} {$else FPC_ANSI_TEXTFILEREC}
TextRec(t).Name:=S; TextRec(t).Name:=S;
{$ifdef USE_FILEREC_FULLNAME}
if length(s)>255 then
UnicodeString(TextRec(t).FullName):=S;
{$endif USE_FILEREC_FULLNAME}
{$endif FPC_ANSI_TEXTFILEREC} {$endif FPC_ANSI_TEXTFILEREC}
{ null terminate, since the name array is regularly used as p(wide)char } { null terminate, since the name array is regularly used as p(wide)char }
TextRec(t).Name[high(TextRec(t).Name)]:=#0; TextRec(t).Name[high(TextRec(t).Name)]:=#0;
@ -183,6 +204,13 @@ Begin
End End
else inOutRes := 103; else inOutRes := 103;
End; End;
{$ifdef USE_FILEREC_FULLNAME}
{$ifdef FPC_ANSI_TEXTFILEREC}
RawByteString(TextRec(t).FullName):='';
{$else FPC_ANSI_TEXTFILEREC}
UnicodeString(TextRec(t).FullName):='';
{$endif FPC_ANSI_TEXTFILEREC}
{$endif USE_FILEREC_FULLNAME}
End; End;
@ -2618,6 +2646,15 @@ begin
end; end;
{$endif FPC_WIDESTRING_EQUAL_UNICODESTRING} {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
Function GetFullName(var t:Text) : UnicodeString;
begin
{$ifdef USE_FILEREC_FULLNAME}
if Assigned(TextRec(t).FullName) then
Result:=UnicodeString(TextRec(t).FullName)
else
{$endif USE_FILEREC_FULLNAME}
Result:=PFileTextRecChar(@TextRec(t).Name);
end;
{***************************************************************************** {*****************************************************************************
Initializing Initializing

View File

@ -57,5 +57,8 @@ type
{$ifdef FPC_HAS_CPSTRING} {$ifdef FPC_HAS_CPSTRING}
CodePage : TSystemCodePage; CodePage : TSystemCodePage;
{$endif} {$endif}
{$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
FullName : Pointer;
{$endif FPC_HAS_FEATURE_UNICODESTRINGS}
End; End;