mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-27 06:53:33 +01:00
* optimize fixpath, findfile to not require temp ansistrings
* check for verbosity for V_Tried level messages, patches from Sergei Gorelkin git-svn-id: trunk@9297 -
This commit is contained in:
parent
cb24c78d4d
commit
241c65d5ec
@ -117,12 +117,12 @@ interface
|
|||||||
Function FileExists (const F : TCmdStr;allowcache:boolean) : Boolean;
|
Function FileExists (const F : TCmdStr;allowcache:boolean) : Boolean;
|
||||||
function FileExistsNonCase(const path,fn:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
|
function FileExistsNonCase(const path,fn:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
|
||||||
Function RemoveDir(d:TCmdStr):boolean;
|
Function RemoveDir(d:TCmdStr):boolean;
|
||||||
Function FixPath(s:TCmdStr;allowdot:boolean):TCmdStr;
|
Function FixPath(const s:TCmdStr;allowdot:boolean):TCmdStr;
|
||||||
function FixFileName(const s:TCmdStr):TCmdStr;
|
function FixFileName(const s:TCmdStr):TCmdStr;
|
||||||
function TargetFixPath(s:TCmdStr;allowdot:boolean):TCmdStr;
|
function TargetFixPath(s:TCmdStr;allowdot:boolean):TCmdStr;
|
||||||
function TargetFixFileName(const s:TCmdStr):TCmdStr;
|
function TargetFixFileName(const s:TCmdStr):TCmdStr;
|
||||||
procedure SplitBinCmd(const s:TCmdStr;var bstr: TCmdStr;var cstr:TCmdStr);
|
procedure SplitBinCmd(const s:TCmdStr;var bstr: TCmdStr;var cstr:TCmdStr);
|
||||||
function FindFile(const f : TCmdStr;path : TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
|
function FindFile(const f : TCmdStr; const path : TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
|
||||||
{ function FindFilePchar(const f : TCmdStr;path : pchar;allowcache:boolean;var foundfile:TCmdStr):boolean;}
|
{ function FindFilePchar(const f : TCmdStr;path : pchar;allowcache:boolean;var foundfile:TCmdStr):boolean;}
|
||||||
function FindExe(const bin:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
|
function FindExe(const bin:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
|
||||||
function GetShortName(const n:TCmdStr):TCmdStr;
|
function GetShortName(const n:TCmdStr):TCmdStr;
|
||||||
@ -523,7 +523,7 @@ implementation
|
|||||||
else
|
else
|
||||||
{$endif usedircache}
|
{$endif usedircache}
|
||||||
Result:=SysUtils.FileExists(F);
|
Result:=SysUtils.FileExists(F);
|
||||||
if assigned(do_comment) then
|
if do_checkverbosity(V_Tried) then
|
||||||
begin
|
begin
|
||||||
if Result then
|
if Result then
|
||||||
do_comment(V_Tried,'Searching file '+F+'... found')
|
do_comment(V_Tried,'Searching file '+F+'... found')
|
||||||
@ -652,27 +652,37 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function FixPath(s:TCmdStr;allowdot:boolean):TCmdStr;
|
Function FixPath(const s:TCmdStr;allowdot:boolean):TCmdStr;
|
||||||
var
|
var
|
||||||
i : longint;
|
i, L : longint;
|
||||||
|
P: PChar;
|
||||||
begin
|
begin
|
||||||
|
Result := s;
|
||||||
|
L := Length(Result);
|
||||||
|
if L=0 then
|
||||||
|
exit;
|
||||||
{ Fix separator }
|
{ Fix separator }
|
||||||
for i:=1 to length(s) do
|
P := @Result[1];
|
||||||
if s[i] in ['/','\'] then
|
for i:=0 to L-1 do
|
||||||
s[i]:=source_info.DirSep;
|
begin
|
||||||
|
if p^ in ['/','\'] then
|
||||||
|
p^:=source_info.DirSep;
|
||||||
|
inc(p);
|
||||||
|
end;
|
||||||
{ Fix ending / }
|
{ Fix ending / }
|
||||||
if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
|
if (L>0) and (Result[L]<>source_info.DirSep) and
|
||||||
(s[length(s)]<>DriveSeparator) then
|
(Result[L]<>DriveSeparator) then
|
||||||
s:=s+source_info.DirSep;
|
Result:=Result+source_info.DirSep; { !still results in temp AnsiString }
|
||||||
{ Remove ./ }
|
{ Remove ./ }
|
||||||
if (not allowdot) and (s='.'+source_info.DirSep) then
|
if (not allowdot) and ((Length(Result)=2) and (Result[1]='.') and (Result[2] = source_info.DirSep)) then
|
||||||
s:='';
|
begin
|
||||||
|
Result:='';
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
{ return }
|
{ return }
|
||||||
if (tf_files_case_aware in source_info.flags) or
|
if not ((tf_files_case_aware in source_info.flags) or
|
||||||
(tf_files_case_sensitive in source_info.flags) then
|
(tf_files_case_sensitive in source_info.flags)) then
|
||||||
FixPath:=s
|
Result := lower(Result);
|
||||||
else
|
|
||||||
FixPath:=Lower(s);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{Actually the version in macutils.pp could be used,
|
{Actually the version in macutils.pp could be used,
|
||||||
@ -945,7 +955,7 @@ implementation
|
|||||||
|
|
||||||
procedure WarnNonExistingPath(const path : TCmdStr);
|
procedure WarnNonExistingPath(const path : TCmdStr);
|
||||||
begin
|
begin
|
||||||
if assigned(do_comment) then
|
if do_checkverbosity(V_Tried) then
|
||||||
do_comment(V_Tried,'Path "'+path+'" not found');
|
do_comment(V_Tried,'Path "'+path+'" not found');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1134,26 +1144,22 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function FindFile(const f : TCmdStr;path : TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
|
function FindFile(const f : TCmdStr; const path : TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
|
||||||
Var
|
Var
|
||||||
singlepathstring : TCmdStr;
|
StartPos, EndPos, L: LongInt;
|
||||||
i : longint;
|
|
||||||
begin
|
begin
|
||||||
if PathSeparator <> ';' then
|
Result:=False;
|
||||||
for i:=1 to length(path) do
|
StartPos := 1;
|
||||||
if path[i]=PathSeparator then
|
L := Length(Path);
|
||||||
path[i]:=';';
|
|
||||||
FindFile:=false;
|
|
||||||
repeat
|
repeat
|
||||||
i:=pos(';',path);
|
EndPos := StartPos;
|
||||||
if i=0 then
|
while (EndPos <= L) and ((Path[EndPos] <> PathSeparator) and (Path[EndPos] <> ';')) do
|
||||||
i:=Succ (Length (Path));
|
Inc(EndPos);
|
||||||
singlepathstring:=FixPath(copy(path,1,i-1),false);
|
Result := FileExistsNonCase(FixPath(Copy(Path, StartPos, EndPos-StartPos), False), f, allowcache, FoundFile);
|
||||||
delete(path,1,i);
|
if Result then
|
||||||
result:=FileExistsNonCase(singlepathstring,f,allowcache,FoundFile);
|
Exit;
|
||||||
if result then
|
StartPos := EndPos + 1;
|
||||||
exit;
|
until StartPos > L;
|
||||||
until path='';
|
|
||||||
FoundFile:=f;
|
FoundFile:=f;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@ -383,7 +383,7 @@ begin
|
|||||||
if hp=nil then
|
if hp=nil then
|
||||||
Get:='msg nr '+tostr(nr)
|
Get:='msg nr '+tostr(nr)
|
||||||
else
|
else
|
||||||
Get:=MsgReplace(strpas(hp),args);
|
Get:=MsgReplace(system.strpas(hp),args);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|||||||
@ -124,6 +124,7 @@ var
|
|||||||
Function def_status:boolean;
|
Function def_status:boolean;
|
||||||
Function def_comment(Level:Longint;const s:ansistring):boolean;
|
Function def_comment(Level:Longint;const s:ansistring):boolean;
|
||||||
function def_internalerror(i:longint):boolean;
|
function def_internalerror(i:longint):boolean;
|
||||||
|
function def_CheckVerbosity(v:longint):boolean;
|
||||||
procedure def_initsymbolinfo;
|
procedure def_initsymbolinfo;
|
||||||
procedure def_donesymbolinfo;
|
procedure def_donesymbolinfo;
|
||||||
procedure def_extractsymbolinfo;
|
procedure def_extractsymbolinfo;
|
||||||
@ -135,6 +136,7 @@ type
|
|||||||
tstatusfunction = function:boolean;
|
tstatusfunction = function:boolean;
|
||||||
tcommentfunction = function(Level:Longint;const s:ansistring):boolean;
|
tcommentfunction = function(Level:Longint;const s:ansistring):boolean;
|
||||||
tinternalerrorfunction = function(i:longint):boolean;
|
tinternalerrorfunction = function(i:longint):boolean;
|
||||||
|
tcheckverbosityfunction = function(i:longint):boolean;
|
||||||
|
|
||||||
tinitsymbolinfoproc = procedure;
|
tinitsymbolinfoproc = procedure;
|
||||||
tdonesymbolinfoproc = procedure;
|
tdonesymbolinfoproc = procedure;
|
||||||
@ -146,6 +148,7 @@ const
|
|||||||
do_status : tstatusfunction = @def_status;
|
do_status : tstatusfunction = @def_status;
|
||||||
do_comment : tcommentfunction = @def_comment;
|
do_comment : tcommentfunction = @def_comment;
|
||||||
do_internalerror : tinternalerrorfunction = @def_internalerror;
|
do_internalerror : tinternalerrorfunction = @def_internalerror;
|
||||||
|
do_checkverbosity : tcheckverbosityfunction = @def_checkverbosity;
|
||||||
|
|
||||||
do_initsymbolinfo : tinitsymbolinfoproc = @def_initsymbolinfo;
|
do_initsymbolinfo : tinitsymbolinfoproc = @def_initsymbolinfo;
|
||||||
do_donesymbolinfo : tdonesymbolinfoproc = @def_donesymbolinfo;
|
do_donesymbolinfo : tdonesymbolinfoproc = @def_donesymbolinfo;
|
||||||
@ -369,6 +372,12 @@ begin
|
|||||||
def_internalerror:=true;
|
def_internalerror:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function def_CheckVerbosity(v:longint):boolean;
|
||||||
|
begin
|
||||||
|
result:=status.use_bugreport or
|
||||||
|
((status.verbosity and (v and V_LevelMask))=(v and V_LevelMask));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure def_initsymbolinfo;
|
procedure def_initsymbolinfo;
|
||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
|||||||
@ -265,6 +265,7 @@ uses
|
|||||||
|
|
||||||
Function UnitExists(const ext:string;var foundfile:TCmdStr):boolean;
|
Function UnitExists(const ext:string;var foundfile:TCmdStr):boolean;
|
||||||
begin
|
begin
|
||||||
|
if CheckVerbosity(V_Tried) then
|
||||||
Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
|
Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
|
||||||
UnitExists:=FindFile(FileName+ext,Singlepathstring,true,foundfile);
|
UnitExists:=FindFile(FileName+ext,Singlepathstring,true,foundfile);
|
||||||
end;
|
end;
|
||||||
@ -382,15 +383,18 @@ uses
|
|||||||
begin
|
begin
|
||||||
{ the full filename is specified so we can't use here the
|
{ the full filename is specified so we can't use here the
|
||||||
searchpath (PFV) }
|
searchpath (PFV) }
|
||||||
|
if CheckVerbosity(V_Tried) then
|
||||||
Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,sourceext));
|
Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,sourceext));
|
||||||
fnd:=FindFile(ChangeFileExt(sourcefn^,sourceext),'',true,hs);
|
fnd:=FindFile(ChangeFileExt(sourcefn^,sourceext),'',true,hs);
|
||||||
if not fnd then
|
if not fnd then
|
||||||
begin
|
begin
|
||||||
|
if CheckVerbosity(V_Tried) then
|
||||||
Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pasext));
|
Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pasext));
|
||||||
fnd:=FindFile(ChangeFileExt(sourcefn^,pasext),'',true,hs);
|
fnd:=FindFile(ChangeFileExt(sourcefn^,pasext),'',true,hs);
|
||||||
end;
|
end;
|
||||||
if not fnd and ((m_mac in current_settings.modeswitches) or (tf_p_ext_support in target_info.flags)) then
|
if not fnd and ((m_mac in current_settings.modeswitches) or (tf_p_ext_support in target_info.flags)) then
|
||||||
begin
|
begin
|
||||||
|
if CheckVerbosity(V_Tried) then
|
||||||
Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pext));
|
Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pext));
|
||||||
fnd:=FindFile(ChangeFileExt(sourcefn^,pext),'',true,hs);
|
fnd:=FindFile(ChangeFileExt(sourcefn^,pext),'',true,hs);
|
||||||
end;
|
end;
|
||||||
|
|||||||
@ -180,8 +180,7 @@ implementation
|
|||||||
|
|
||||||
function CheckVerbosity(v:longint):boolean;
|
function CheckVerbosity(v:longint):boolean;
|
||||||
begin
|
begin
|
||||||
CheckVerbosity:=status.use_bugreport or
|
result:=do_checkverbosity(v);
|
||||||
((status.verbosity and (v and V_LevelMask))=(v and V_LevelMask));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user