* first part of cfileutl cleanup

git-svn-id: trunk@8533 -
This commit is contained in:
Tomas Hajny 2007-09-17 21:20:37 +00:00
parent 573bc3b767
commit 3db626873b
2 changed files with 16 additions and 31 deletions

View File

@ -117,7 +117,7 @@ interface
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;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;
@ -597,7 +597,7 @@ implementation
s[i]:=source_info.DirSep; s[i]:=source_info.DirSep;
{ Fix ending / } { Fix ending / }
if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
(s[length(s)]<>':') then (s[length(s)]<>DriveSeparator) then
s:=s+source_info.DirSep; s:=s+source_info.DirSep;
{ Remove ./ } { Remove ./ }
if (not allowdot) and (s='.'+source_info.DirSep) then if (not allowdot) and (s='.'+source_info.DirSep) then
@ -1072,16 +1072,15 @@ implementation
singlepathstring : TCmdStr; singlepathstring : TCmdStr;
i : longint; i : longint;
begin begin
{$ifdef Unix} if PathSeparator <> ';' then
for i:=1 to length(path) do for i:=1 to length(path) do
if path[i]=':' then if path[i]=PathSeparator then
path[i]:=';'; path[i]:=';';
{$endif Unix}
FindFile:=false; FindFile:=false;
repeat repeat
i:=pos(';',path); i:=pos(';',path);
if i=0 then if i=0 then
i:=256; i:=Succ (Length (Path));
singlepathstring:=FixPath(copy(path,1,i-1),false); singlepathstring:=FixPath(copy(path,1,i-1),false);
delete(path,1,i); delete(path,1,i);
result:=FileExistsNonCase(singlepathstring,f,allowcache,FoundFile); result:=FileExistsNonCase(singlepathstring,f,allowcache,FoundFile);
@ -1091,29 +1090,19 @@ implementation
FoundFile:=f; FoundFile:=f;
end; end;
{
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;
Var Var
singlepathstring : TCmdStr; singlepathstring : TCmdStr;
startpc,pc : pchar; startpc,pc : pchar;
sepch : char;
begin begin
FindFilePchar:=false; FindFilePchar:=false;
if Assigned (Path) then if Assigned (Path) then
begin begin
{$ifdef Unix}
sepch:=':';
{$else}
{$ifdef macos}
sepch:=',';
{$else}
sepch:=';';
{$endif macos}
{$endif Unix}
pc:=path; pc:=path;
repeat repeat
startpc:=pc; startpc:=pc;
while (pc^<>sepch) and (pc^<>';') and (pc^<>#0) do while (pc^<>PathSeparator) and (pc^<>';') and (pc^<>#0) do
inc(pc); inc(pc);
SetLength(singlepathstring, pc-startpc); SetLength(singlepathstring, pc-startpc);
move(startpc^,singlepathstring[1],pc-startpc); move(startpc^,singlepathstring[1],pc-startpc);
@ -1128,23 +1117,22 @@ implementation
end; end;
foundfile:=f; foundfile:=f;
end; end;
}
function FindExe(const bin:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean; function FindExe(const bin:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
var var
p : pchar; Path : TCmdStr;
found : boolean; found : boolean;
begin begin
found:=FindFile(FixFileName(ChangeFileExt(bin,source_info.exeext)),'.;'+exepath,allowcache,foundfile); found:=FindFile(FixFileName(ChangeFileExt(bin,source_info.exeext)),'.;'+exepath,allowcache,foundfile);
if not found then if not found then
begin begin
{$ifdef macos} {$ifdef macos}
p:=GetEnvPchar('Commands'); Path:=GetEnvironmentVariable('Commands');
{$else} {$else}
p:=GetEnvPchar('PATH'); Path:=GetEnvironmentVariable('PATH');
{$endif} {$endif}
found:=FindFilePChar(FixFileName(ChangeFileExt(bin,source_info.exeext)),p,allowcache,foundfile); found:=FindFile(FixFileName(ChangeFileExt(bin,source_info.exeext)),Path,allowcache,foundfile);
FreeEnvPChar(p);
end; end;
FindExe:=found; FindExe:=found;
end; end;

View File

@ -1101,7 +1101,6 @@ implementation
exeName:TCmdStr; exeName:TCmdStr;
{$ifdef need_path_search} {$ifdef need_path_search}
hs1 : TPathStr; hs1 : TPathStr;
p : pchar;
{$endif need_path_search} {$endif need_path_search}
begin begin
localexepath:=GetEnvironmentVariable('PPC_EXEC_PATH'); localexepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
@ -1116,12 +1115,10 @@ implementation
hs1 := ExtractFileName(exeName); hs1 := ExtractFileName(exeName);
ChangeFileExt(hs1,source_info.exeext); ChangeFileExt(hs1,source_info.exeext);
{$ifdef macos} {$ifdef macos}
p:=GetEnvPchar('Commands'); FindFile(hs1,GetEnvironmentVariable('Commands'),false,localExepath);
{$else macos} {$else macos}
p:=GetEnvPchar('PATH'); FindFile(hs1,GetEnvironmentVariable('PATH'),false,localExepath);
{$endif macos} {$endif macos}
FindFilePChar(hs1,p,false,localExepath);
FreeEnvPChar(p);
localExepath:=ExtractFilePath(localExepath); localExepath:=ExtractFilePath(localExepath);
end; end;
{$endif need_path_search} {$endif need_path_search}