Browse Source

* addpath fixed with list of paths when inserting at the beginning
* if exepath=currentdir then it's not inserted in path list
* searchpaths in ppc386.cfg are now added at the beginning of the
list instead of at the end. (commandline is not changed)
* check paths before inserting in list

peter 25 years ago
parent
commit
5aec5872b6
2 changed files with 76 additions and 39 deletions
  1. 61 33
      compiler/globals.pas
  2. 15 6
      compiler/options.pas

+ 61 - 33
compiler/globals.pas

@@ -243,7 +243,7 @@ unit globals;
     function filetimestring( t : longint) : string;
     function filetimestring( t : longint) : string;
 
 
     procedure DefaultReplacements(var s:string);
     procedure DefaultReplacements(var s:string);
-
+    function  GetCurrentDir:string;
     function  path_absolute(const s : string) : boolean;
     function  path_absolute(const s : string) : boolean;
     Function  PathExists ( F : String) : Boolean;
     Function  PathExists ( F : String) : Boolean;
     Function  FileExists ( Const F : String) : Boolean;
     Function  FileExists ( Const F : String) : Boolean;
@@ -756,6 +756,7 @@ implementation
        filetimestring:=L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
        filetimestring:=L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
      end;
      end;
 
 
+
 {****************************************************************************
 {****************************************************************************
                           Default Macro Handling
                           Default Macro Handling
 ****************************************************************************}
 ****************************************************************************}
@@ -777,6 +778,15 @@ implementation
                                File Handling
                                File Handling
 ****************************************************************************}
 ****************************************************************************}
 
 
+   function GetCurrentDir:string;
+     var
+       CurrentDir : string;
+     begin
+       GetDir(0,CurrentDir);
+       GetCurrentDir:=FixPath(CurrentDir,false);
+     end;
+
+
    function path_absolute(const s : string) : boolean;
    function path_absolute(const s : string) : boolean;
    {
    {
      is path s an absolute path?
      is path s an absolute path?
@@ -803,31 +813,24 @@ implementation
       Begin
       Begin
       End;
       End;
 {$endif not FPC}
 {$endif not FPC}
-{$ifdef delphi}
-    Function FileExists ( Const F : String) : Boolean;
 
 
-      begin
-         FileExists:=sysutils.FileExists(f);
-      end;
 
 
-{$else}
     Function FileExists ( Const F : String) : Boolean;
     Function FileExists ( Const F : String) : Boolean;
+{$ifndef delphi}
       Var
       Var
-      {$ifdef linux}
-         Info : Stat;
-      {$else}
          Info : SearchRec;
          Info : SearchRec;
-      {$endif}
+{$endif}
       begin
       begin
-      {$ifdef linux}
-        FileExists:=FStat(F,info);
-      {$else}
+{$ifdef delphi}
+         FileExists:=sysutils.FileExists(f);
+{$else}
         findfirst(F,readonly+archive+hidden,info);
         findfirst(F,readonly+archive+hidden,info);
         FileExists:=(doserror=0);
         FileExists:=(doserror=0);
         findclose(Info);
         findclose(Info);
-      {$endif}
+{$endif delphi}
       end;
       end;
 
 
+
     Function PathExists ( F : String) : Boolean;
     Function PathExists ( F : String) : Boolean;
       Var
       Var
         Info : SearchRec;
         Info : SearchRec;
@@ -838,7 +841,6 @@ implementation
         PathExists:=(doserror=0) and ((info.attr and directory)=directory);
         PathExists:=(doserror=0) and ((info.attr and directory)=directory);
         findclose(Info);
         findclose(Info);
       end;
       end;
-{$endif}
 
 
 
 
     Function RemoveFile(const f:string):boolean;
     Function RemoveFile(const f:string):boolean;
@@ -1003,6 +1005,7 @@ implementation
        {$endif}
        {$endif}
      end;
      end;
 
 
+
    procedure SplitBinCmd(const s:string;var bstr,cstr:string);
    procedure SplitBinCmd(const s:string;var bstr,cstr:string);
      var
      var
        i : longint;
        i : longint;
@@ -1053,14 +1056,29 @@ implementation
      { Support default macro's }
      { Support default macro's }
        DefaultReplacements(s);
        DefaultReplacements(s);
      { get current dir }
      { get current dir }
-       GetDir(0,CurrentDir);
-       CurrentDir:=FixPath(CurrentDir,false);
+       CurrentDir:=GetCurrentDir;
        repeat
        repeat
-         j:=Pos(';',s);
-         if j=0 then
-          j:=255;
-       {Get Pathname}
-         CurrPath:=FixPath(Copy(s,1,j-1),false);
+         { get currpath }
+         if addfirst then
+          begin
+            j:=length(s);
+            while (j>0) and (s[j]<>';') do
+             dec(j);
+            CurrPath:=FixPath(Copy(s,j+1,length(s)-j),false);
+            if j=0 then
+             s:=''
+            else
+             System.Delete(s,j,length(s)-j+1);
+          end
+         else
+          begin
+            j:=Pos(';',s);
+            if j=0 then
+             j:=255;
+            CurrPath:=FixPath(Copy(s,1,j-1),false);
+            System.Delete(s,1,j);
+          end;
+         { fix pathname }
          if CurrPath='' then
          if CurrPath='' then
           CurrPath:='.'+DirSep
           CurrPath:='.'+DirSep
          else
          else
@@ -1069,7 +1087,7 @@ implementation
             if (Copy(CurrPath,1,length(CurrentDir))=CurrentDir) then
             if (Copy(CurrPath,1,length(CurrentDir))=CurrentDir) then
              CurrPath:='.'+DirSep+Copy(CurrPath,length(CurrentDir)+1,255);
              CurrPath:='.'+DirSep+Copy(CurrPath,length(CurrentDir)+1,255);
           end;
           end;
-         System.Delete(s,1,j);
+         { wildcard adding ? }
          if pos('*',currpath)>0 then
          if pos('*',currpath)>0 then
           begin
           begin
             if currpath[length(currpath)]=dirsep then
             if currpath[length(currpath)]=dirsep then
@@ -1091,15 +1109,13 @@ implementation
                 end;
                 end;
                findnext(dir);
                findnext(dir);
              end;
              end;
-{$ifdef Linux}
-            FindClose(dir);
-{$endif}
-{$ifdef Win32}
             FindClose(dir);
             FindClose(dir);
-{$endif}
           end
           end
          else
          else
-          addcurrpath;
+          begin
+            if PathExists(currpath) then
+             addcurrpath;
+          end;
        until (s='');
        until (s='');
      end;
      end;
 
 
@@ -1240,6 +1256,7 @@ implementation
       end;
       end;
    end;
    end;
 
 
+
    function FindFile(const f : string;path : string;var b : boolean) : string;
    function FindFile(const f : string;path : string;var b : boolean) : string;
       Var
       Var
         singlepathstring : string;
         singlepathstring : string;
@@ -1352,6 +1369,7 @@ implementation
       {$endif}
       {$endif}
       end;
       end;
 
 
+
     procedure FreeEnvPChar(p:pchar);
     procedure FreeEnvPChar(p:pchar);
       begin
       begin
       {$ifndef linux}
       {$ifndef linux}
@@ -1375,9 +1393,10 @@ implementation
       end;
       end;
       {$endif}
       {$endif}
 
 
- {****************************************************************************
+
+{****************************************************************************
                                     Init
                                     Init
- ****************************************************************************}
+****************************************************************************}
 
 
    procedure get_exepath;
    procedure get_exepath;
      var
      var
@@ -1391,10 +1410,12 @@ implementation
 {$endif delphi}
 {$endif delphi}
        if exepath='' then
        if exepath='' then
         fsplit(FixFileName(paramstr(0)),exepath,hs1,hs2);
         fsplit(FixFileName(paramstr(0)),exepath,hs1,hs2);
+{$ifndef VER0_99_15}
      {$ifdef linux}
      {$ifdef linux}
        if exepath='' then
        if exepath='' then
         fsearch(hs1,dos.getenv('PATH'));
         fsearch(hs1,dos.getenv('PATH'));
      {$endif}
      {$endif}
+{$endif}
        exepath:=FixPath(exepath,false);
        exepath:=FixPath(exepath,false);
      end;
      end;
 
 
@@ -1492,7 +1513,14 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.51  2000-02-09 13:22:53  peter
+  Revision 1.52  2000-02-10 11:45:48  peter
+    * addpath fixed with list of paths when inserting at the beginning
+    * if exepath=currentdir then it's not inserted in path list
+    * searchpaths in ppc386.cfg are now added at the beginning of the
+      list instead of at the end. (commandline is not changed)
+    * check paths before inserting in list
+
+  Revision 1.51  2000/02/09 13:22:53  peter
     * log truncated
     * log truncated
 
 
   Revision 1.50  2000/01/26 14:31:03  marco
   Revision 1.50  2000/01/26 14:31:03  marco

+ 15 - 6
compiler/options.pas

@@ -553,12 +553,12 @@ begin
                        'i' : if ispara then
                        'i' : if ispara then
                               ParaIncludePath.AddPath(More,false)
                               ParaIncludePath.AddPath(More,false)
                              else
                              else
-                              includesearchpath.AddPath(More,false);
+                              includesearchpath.AddPath(More,true);
                        'g' : Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
                        'g' : Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
                        'l' : if ispara then
                        'l' : if ispara then
                               ParaLibraryPath.AddPath(More,false)
                               ParaLibraryPath.AddPath(More,false)
                              else
                              else
-                              LibrarySearchPath.AddPath(More,false);
+                              LibrarySearchPath.AddPath(More,true);
                        'L' : if More<>'' then
                        'L' : if More<>'' then
                               ParaDynamicLinker:=More
                               ParaDynamicLinker:=More
                              else
                              else
@@ -566,12 +566,12 @@ begin
                        'o' : if ispara then
                        'o' : if ispara then
                               ParaObjectPath.AddPath(More,false)
                               ParaObjectPath.AddPath(More,false)
                              else
                              else
-                              ObjectSearchPath.AddPath(More,false);
+                              ObjectSearchPath.AddPath(More,true);
                        'r' : Msgfilename:=More;
                        'r' : Msgfilename:=More;
                        'u' : if ispara then
                        'u' : if ispara then
                               ParaUnitPath.AddPath(More,false)
                               ParaUnitPath.AddPath(More,false)
                              else
                              else
-                              unitsearchpath.AddPath(More,false);
+                              unitsearchpath.AddPath(More,true);
                        'U' : OutputUnitDir:=FixPath(More,true);
                        'U' : OutputUnitDir:=FixPath(More,true);
                       else
                       else
                         IllegalPara(opt);
                         IllegalPara(opt);
@@ -1396,7 +1396,9 @@ begin
      UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name),false);
      UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name),false);
      UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name)+'/rtl',false);
      UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name)+'/rtl',false);
    end;
    end;
-  UnitSearchPath.AddPath(ExePath,false);
+  { Add exepath if the exe is not in the current dir, because that is always searched already }
+  if ExePath<>GetCurrentDir then
+   UnitSearchPath.AddPath(ExePath,false);
   { Add unit dir to the object and library path }
   { Add unit dir to the object and library path }
   objectsearchpath.AddList(unitsearchpath,false);
   objectsearchpath.AddList(unitsearchpath,false);
   librarysearchpath.AddList(unitsearchpath,false);
   librarysearchpath.AddList(unitsearchpath,false);
@@ -1429,7 +1431,14 @@ end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.59  2000-02-09 13:22:54  peter
+  Revision 1.60  2000-02-10 11:45:48  peter
+    * addpath fixed with list of paths when inserting at the beginning
+    * if exepath=currentdir then it's not inserted in path list
+    * searchpaths in ppc386.cfg are now added at the beginning of the
+      list instead of at the end. (commandline is not changed)
+    * check paths before inserting in list
+
+  Revision 1.59  2000/02/09 13:22:54  peter
     * log truncated
     * log truncated
 
 
   Revision 1.58  2000/02/09 10:35:48  peter
   Revision 1.58  2000/02/09 10:35:48  peter