From 3db626873b642dcff2059d4ef3d1488f8b70346d Mon Sep 17 00:00:00 2001 From: Tomas Hajny Date: Mon, 17 Sep 2007 21:20:37 +0000 Subject: [PATCH] * first part of cfileutl cleanup git-svn-id: trunk@8533 - --- compiler/cfileutl.pas | 40 ++++++++++++++-------------------------- compiler/globals.pas | 7 ++----- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/compiler/cfileutl.pas b/compiler/cfileutl.pas index d318a2f407..bd0bb18c5c 100644 --- a/compiler/cfileutl.pas +++ b/compiler/cfileutl.pas @@ -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; diff --git a/compiler/globals.pas b/compiler/globals.pas index a4c4607305..9543efb4d2 100644 --- a/compiler/globals.pas +++ b/compiler/globals.pas @@ -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}