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

View File

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