Browse Source

* Changed FileSearch to handle a set of options instead of boolean.
Options now include stripquotes
* Changed ExeSearch so dirlist is optional and PATH is used if omitted.
It uses stripQuotes on windows. (bug 19282)

git-svn-id: trunk@17717 -

michael 14 years ago
parent
commit
6b42ee69a9
2 changed files with 35 additions and 8 deletions
  1. 8 2
      rtl/objpas/sysutils/filutilh.inc
  2. 27 6
      rtl/objpas/sysutils/sysutils.inc

+ 8 - 2
rtl/objpas/sysutils/filutilh.inc

@@ -71,6 +71,10 @@ Const
   { File errors }
   { File errors }
   feInvalidHandle : THandle = THandle(-1);  //return value on FileOpen error
   feInvalidHandle : THandle = THandle(-1);  //return value on FileOpen error
 
 
+Type
+  TFileSearchOption = (sfoImplicitCurrentDir,sfoStripQuotes);
+  TFileSearchOptions = set of TFileSearchOption;
+
 Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
 Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
 Function FileCreate (Const FileName : String) : THandle;
 Function FileCreate (Const FileName : String) : THandle;
 Function FileCreate (Const FileName : String; Rights : Integer) : THandle;
 Function FileCreate (Const FileName : String; Rights : Integer) : THandle;
@@ -96,8 +100,10 @@ Function FileGetAttr (Const FileName : String) : Longint;
 Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
 Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
 Function DeleteFile (Const FileName : String) : Boolean;
 Function DeleteFile (Const FileName : String) : Boolean;
 Function RenameFile (Const OldName, NewName : String) : Boolean;
 Function RenameFile (Const OldName, NewName : String) : Boolean;
-Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean = True) : String;
-Function ExeSearch  (Const Name, DirList : String) : String;
+
+Function FileSearch (Const Name, DirList : String; Options : TFileSearchoptions = []) : String;
+Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean) : String;
+Function ExeSearch  (Const Name : String; Const DirList : String = '') : String;
 Function FileIsReadOnly(const FileName: String): Boolean;
 Function FileIsReadOnly(const FileName: String): Boolean;
 
 
 Function GetFileHandle(var f : File):THandle;
 Function GetFileHandle(var f : File):THandle;

+ 27 - 6
rtl/objpas/sysutils/sysutils.inc

@@ -18,7 +18,7 @@
   { variant error codes }
   { variant error codes }
   {$i varerror.inc}
   {$i varerror.inc}
 
 
-    Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean = True) : String;
+    Function FileSearch (Const Name, DirList : String; Options : TFileSearchoptions = []) : String;
     Var
     Var
       I : longint;
       I : longint;
       Temp : String;
       Temp : String;
@@ -27,7 +27,7 @@
       Result:=Name;
       Result:=Name;
       temp:=SetDirSeparators(DirList);
       temp:=SetDirSeparators(DirList);
       // Start with checking the file in the current directory
       // Start with checking the file in the current directory
-      If ImplicitCurrentDir and (Result <> '') and FileExists(Result) Then
+      If (sfoImplicitCurrentDir in Options) and (Result <> '') and FileExists(Result) Then
         exit;
         exit;
       while True do begin
       while True do begin
         If Temp = '' then
         If Temp = '' then
@@ -44,21 +44,42 @@
             Temp:='';
             Temp:='';
           end;
           end;
         If Result<>'' then
         If Result<>'' then
-          Result:=IncludeTrailingPathDelimiter(Result)+name;
+          begin
+          If (sfoStripQuotes in Options) and (Result[1]='"') and (Result[Length(Result)]='"') then
+            Result:=Copy(Result,2,Length(Result)-2);
+          if (Result<>'') then
+            Result:=IncludeTrailingPathDelimiter(Result)+name;
+          end;
         If (Result <> '') and FileExists(Result) Then
         If (Result <> '') and FileExists(Result) Then
           exit;
           exit;
       end;
       end;
       result:='';
       result:='';
     end;
     end;
 
 
-    Function ExeSearch (Const Name, DirList : String) : String;
+    Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean) : String;
 
 
     begin
     begin
+      if ImplicitCurrentDir then
+        Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
+      else  
+        Result:=FileSearch(Name,DirList,[]);
+    end;
+    
+    Function ExeSearch (Const Name : String; Const DirList : String ='' ) : String;
+    
+    Var
+      D : String;
+      O : TFileSearchOptions;
+    begin
+      D:=DirList;
+      if (D='') then
+        D:=GetEnvironmentVariable('PATH');
     {$ifdef unix}
     {$ifdef unix}
-      Result := FileSearch(Name, DirList, False);
+      O:=[];
     {$else unix}
     {$else unix}
-      Result := FileSearch(Name, DirList, True);
+      O:=(sfoImplicitCurrentDir,sfoStripQuotes);
     {$endif unix}
     {$endif unix}
+      Result := FileSearch(Name, D, False);
     end;
     end;
 
 
   {$ifndef OS_FILEISREADONLY}
   {$ifndef OS_FILEISREADONLY}