浏览代码

* Remove dos,strings units, use SysUtils instead
* replace split* functions with Extract* functions
* Add Directory caching

git-svn-id: trunk@5102 -

peter 19 年之前
父节点
当前提交
cb246eb781
共有 65 个文件被更改,包括 1714 次插入1740 次删除
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/aasmbase.pas
  3. 11 9
      compiler/aasmtai.pas
  4. 6 25
      compiler/aggas.pas
  5. 37 94
      compiler/assemble.pas
  6. 14 13
      compiler/browcol.pas
  7. 1 1
      compiler/browlog.pas
  8. 125 3
      compiler/cclasses.pas
  9. 1086 0
      compiler/cfileutils.pas
  10. 2 2
      compiler/cmsgs.pas
  11. 0 14
      compiler/comphook.pas
  12. 7 17
      compiler/compiler.pas
  13. 7 39
      compiler/comprsrc.pas
  14. 3 2
      compiler/cresstr.pas
  15. 18 30
      compiler/cutils.pas
  16. 5 11
      compiler/dbgdwarf.pas
  17. 21 16
      compiler/dbgstabs.pas
  18. 1 1
      compiler/export.pas
  19. 54 66
      compiler/finput.pas
  20. 9 20
      compiler/fmodule.pas
  21. 11 9
      compiler/fppu.pas
  22. 3 2
      compiler/gendef.pas
  23. 13 1029
      compiler/globals.pas
  24. 4 11
      compiler/globtype.pas
  25. 1 13
      compiler/impdef.pas
  26. 11 43
      compiler/link.pas
  27. 2 2
      compiler/m68k/ra68kmot.pas
  28. 2 2
      compiler/ncnv.pas
  29. 2 2
      compiler/nobj.pas
  30. 3 2
      compiler/ogbase.pas
  31. 4 3
      compiler/ogcoff.pas
  32. 2 2
      compiler/ogelf.pas
  33. 2 1
      compiler/ogmap.pas
  34. 44 87
      compiler/options.pas
  35. 8 10
      compiler/owar.pas
  36. 2 1
      compiler/owbase.pas
  37. 2 2
      compiler/parser.pas
  38. 3 3
      compiler/pdecsub.pas
  39. 2 1
      compiler/pdecvar.pas
  40. 3 2
      compiler/pmodules.pas
  41. 1 1
      compiler/ptconst.pas
  42. 1 1
      compiler/rautils.pas
  43. 6 5
      compiler/scandir.pas
  44. 23 23
      compiler/scanner.pas
  45. 4 3
      compiler/script.pas
  46. 2 2
      compiler/symbase.pas
  47. 10 9
      compiler/symdef.pas
  48. 4 4
      compiler/symsym.pas
  49. 1 1
      compiler/symtable.pas
  50. 1 1
      compiler/symtype.pas
  51. 3 3
      compiler/systems/t_beos.pas
  52. 13 21
      compiler/systems/t_bsd.pas
  53. 30 15
      compiler/systems/t_emx.pas
  54. 5 3
      compiler/systems/t_go32v2.pas
  55. 11 10
      compiler/systems/t_linux.pas
  56. 3 2
      compiler/systems/t_nwl.pas
  57. 1 1
      compiler/systems/t_nwm.pas
  58. 27 13
      compiler/systems/t_os2.pas
  59. 2 1
      compiler/systems/t_sunos.pas
  60. 2 1
      compiler/systems/t_watcom.pas
  61. 8 6
      compiler/systems/t_win.pas
  62. 8 8
      compiler/utils/fixtab.pp
  63. 4 4
      compiler/utils/ppufiles.pp
  64. 4 4
      compiler/utils/ppumove.pp
  65. 7 7
      compiler/x86/agx86int.pas

+ 1 - 0
.gitattributes

@@ -78,6 +78,7 @@ compiler/bsdcompile -text
 compiler/catch.pas svneol=native#text/plain
 compiler/cclasses.pas svneol=native#text/plain
 compiler/cfidwarf.pas svneol=native#text/plain
+compiler/cfileutils.pas svneol=native#text/plain
 compiler/cg64f32.pas svneol=native#text/plain
 compiler/cgbase.pas svneol=native#text/plain
 compiler/cgobj.pas svneol=native#text/plain

+ 1 - 1
compiler/aasmbase.pas

@@ -123,7 +123,7 @@ interface
 implementation
 
     uses
-      strings,
+      SysUtils,
       verbose;
 
 

+ 11 - 9
compiler/aasmtai.pas

@@ -322,7 +322,7 @@ interface
        end;
 
        tai_directive = class(tailineinfo)
-          name : pstring;
+          name : pshortstring;
           directive : TAsmDirective;
           constructor Create(_directive:TAsmDirective;const _name:string);
           destructor Destroy;override;
@@ -356,7 +356,7 @@ interface
           sectype  : TAsmSectiontype;
           secorder : TasmSectionorder;
           secalign : byte;
-          name     : pstring;
+          name     : pshortstring;
           sec      : TObjSection; { used in binary writer }
           constructor Create(Asectype:TAsmSectiontype;Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
           destructor Destroy;override;
@@ -475,7 +475,7 @@ interface
        end;
 
        tai_function_name = class(tai)
-          funcname : pstring;
+          funcname : pshortstring;
           constructor create(const s:string);
           destructor destroy;override;
        end;
@@ -501,7 +501,7 @@ interface
        tai_tempalloc = class(tai)
           allocation : boolean;
 {$ifdef EXTDEBUG}
-          problem : pstring;
+          problem : pshortstring;
 {$endif EXTDEBUG}
           temppos,
           tempsize   : longint;
@@ -648,7 +648,7 @@ interface
 implementation
 
     uses
-      strings,
+      SysUtils,
       verbose;
 
     const
@@ -1584,7 +1584,7 @@ implementation
     destructor tai_comment.destroy;
 
       begin
-         strdispose(str);
+         freemem(str);
          inherited Destroy;
       end;
 
@@ -1641,7 +1641,7 @@ implementation
 
     destructor tai_stab.destroy;
       begin
-         strdispose(str);
+         freemem(str);
          inherited destroy;
       end;
 
@@ -1890,13 +1890,15 @@ implementation
       begin
         inherited Create;
         typ:=ait_file;
-        str:=strpnew(_str);
+        getmem(str,length(_str)+1);
+        move(_str[1],str^,length(_str));
+        str[length(_str)]:=#0;
       end;
 
 
     destructor tai_file.destroy;
       begin
-         strdispose(str);
+         freemem(str);
          inherited Destroy;
       end;
 

+ 6 - 25
compiler/aggas.pas

@@ -29,11 +29,6 @@ unit aggas;
 interface
 
     uses
-{$IFDEF USE_SYSUTILS}
-      SysUtils,
-{$ELSE USE_SYSUTILS}
-      dos,
-{$ENDIF USE_SYSUTILS}
       cclasses,
       globtype,globals,
       aasmbase,aasmtai,aasmdata,aasmcpu,
@@ -90,7 +85,8 @@ interface
 implementation
 
     uses
-      cutils,systems,
+      SysUtils,
+      cutils,cfileutils,systems,
       fmodule,finput,verbose,
       itcpugas,cpubase
       ;
@@ -1031,9 +1027,7 @@ implementation
 
     procedure TGNUAssembler.WriteAsmList;
     var
-      p:dirstr;
-      n:namestr;
-      e:extstr;
+      n : string;
       hal : tasmlisttype;
     begin
 {$ifdef EXTDEBUG}
@@ -1046,23 +1040,10 @@ implementation
       LastInfile:=nil;
 
       if assigned(current_module.mainsource) then
-{$IFDEF USE_SYSUTILS}
-      begin
-       p := SplitPath(current_module.mainsource^);
-       n := SplitName(current_module.mainsource^);
-       e := SplitExtension(current_module.mainsource^);
-      end
-{$ELSE USE_SYSUTILS}
-       fsplit(current_module.mainsource^,p,n,e)
-{$ENDIF USE_SYSUTILS}
+        n:=ExtractFileName(current_module.mainsource^)
       else
-       begin
-         p:=inputdir;
-         n:=inputfile;
-         e:=inputextension;
-       end;
-    { to get symify to work }
-      AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
+        n:=InputFileName;
+      AsmWriteLn(#9'.file "'+FixFileName(n)+'"');
       WriteExtraHeader;
       AsmStartSize:=AsmSize;
       symendcount:=0;

+ 37 - 94
compiler/assemble.pas

@@ -32,12 +32,7 @@ interface
 
 
     uses
-{$IFDEF USE_SYSUTILS}
-      sysutils,
-{$ELSE USE_SYSUTILS}
-      strings,
-      dos,
-{$ENDIF USE_SYSUTILS}
+      SysUtils,
       systems,globtype,globals,aasmbase,aasmtai,aasmdata,ogbase;
 
     const
@@ -50,9 +45,8 @@ interface
       TAssembler=class(TAbstractAssembler)
       public
       {filenames}
-        path     : pathstr;
-        fname, name: namestr;  (* name for modulename given in source, fname
-                                  for base file name w/o path and extension  *)
+        path        : string;
+        name        : string;
         AsmFileName,         { current .s and .o file }
         ObjFileName,
         ppufilename  : string;
@@ -171,16 +165,13 @@ Implementation
 
     uses
 {$ifdef hasunix}
-  {$ifdef havelinuxrtl10}
-      linux,
-  {$else}
       unix,
-  {$endif}
 {$endif}
-      cutils,script,fmodule,verbose,
+      cutils,cfileutils,
 {$ifdef memdebug}
       cclasses,
 {$endif memdebug}
+      script,fmodule,verbose,
 {$ifdef m68k}
       cpuinfo,
 {$endif m68k}
@@ -199,10 +190,9 @@ Implementation
     Constructor TAssembler.Create(smart:boolean);
       begin
       { load start values }
-        AsmFileName:=current_module.get_AsmFilename;
+        AsmFileName:=current_module.AsmFilename^;
         ObjFileName:=current_module.ObjFileName^;
         name:=Lower(current_module.modulename^);
-        fname:=current_module.newfilename^;
         path:=current_module.outputpath^;
         asmprefix := current_module.asmprefix^;
         if not assigned(current_module.outputpath) then
@@ -263,7 +253,7 @@ Implementation
         inherited Create(smart);
         if SmartAsm then
          begin
-           path:=FixPath(path+FixFileName(fname)+target_info.smartext,false);
+           path:=FixPath(path+ChangeFileExt(AsmFileName,target_info.smartext),false);
            CreateSmartLinkPath(path);
          end;
         Outcnt:=0;
@@ -271,47 +261,29 @@ Implementation
 
 
     procedure TExternalAssembler.CreateSmartLinkPath(const s:string);
+
+        procedure DeleteFilesWithExt(const AExt:string);
+        var
+          dir : TSearchRec;
+        begin
+          if findfirst(s+source_info.dirsep+'*'+AExt,faAnyFile,dir) = 0 then
+            begin
+              repeat
+                DeleteFile(s+source_info.dirsep+dir.name);
+              until findnext(dir) <> 0;
+            end;
+          findclose(dir);
+        end;
+
       var
-{$IFDEF USE_SYSUTILS}
         dir : TSearchRec;
-{$ELSE USE_SYSUTILS}
-        dir : searchrec;
-{$ENDIF USE_SYSUTILS}
         hs  : string;
       begin
         if PathExists(s) then
          begin
            { the path exists, now we clean only all the .o and .s files }
-           { .o files }
-{$IFDEF USE_SYSUTILS}
-           if findfirst(s+source_info.dirsep+'*'+target_info.objext,faAnyFile,dir) = 0
-           then repeat
-              RemoveFile(s+source_info.dirsep+dir.name);
-           until findnext(dir) <> 0;
-{$ELSE USE_SYSUTILS}
-           findfirst(s+source_info.dirsep+'*'+target_info.objext,anyfile,dir);
-           while (doserror=0) do
-            begin
-              RemoveFile(s+source_info.dirsep+dir.name);
-              findnext(dir);
-            end;
-{$ENDIF USE_SYSUTILS}
-           findclose(dir);
-           { .s files }
-{$IFDEF USE_SYSUTILS}
-           if findfirst(s+source_info.dirsep+'*'+target_info.asmext,faAnyFile,dir) = 0
-           then repeat
-             RemoveFile(s+source_info.dirsep+dir.name);
-           until findnext(dir) <> 0;
-{$ELSE USE_SYSUTILS}
-           findfirst(s+source_info.dirsep+'*'+target_info.asmext,anyfile,dir);
-           while (doserror=0) do
-            begin
-              RemoveFile(s+source_info.dirsep+dir.name);
-              findnext(dir);
-            end;
-{$ENDIF USE_SYSUTILS}
-           findclose(dir);
+           DeleteFilesWithExt(target_info.objext);
+           DeleteFilesWithExt(target_info.asmext);
          end
         else
          begin
@@ -329,7 +301,7 @@ Implementation
     const
       lastas  : byte=255;
     var
-      LastASBin : pathstr;
+      LastASBin : string;
     Function TExternalAssembler.FindAssembler:string;
       var
         asfound : boolean;
@@ -339,11 +311,11 @@ Implementation
         if cs_link_on_target in current_settings.globalswitches then
          begin
            { If linking on target, don't add any path PM }
-           FindAssembler:=utilsprefix+AddExtension(target_asm.asmbin,target_info.exeext);
+           FindAssembler:=utilsprefix+ChangeFileExt(target_asm.asmbin,target_info.exeext);
            exit;
          end
         else
-         UtilExe:=utilsprefix+AddExtension(target_asm.asmbin,source_info.exeext);
+         UtilExe:=utilsprefix+ChangeFileExt(target_asm.asmbin,source_info.exeext);
         if lastas<>ord(target_asm.id) then
          begin
            lastas:=ord(target_asm.id);
@@ -365,51 +337,30 @@ Implementation
 
 
     Function TExternalAssembler.CallAssembler(const command:string; const para:TCmdStr):Boolean;
-{$IFDEF USE_SYSUTILS}
       var
-        DosExitCode:Integer;
-{$ENDIF USE_SYSUTILS}
+        DosExitCode : Integer;
       begin
-        callassembler:=true;
-        if not(cs_asm_extern in current_settings.globalswitches) then
-{$IFDEF USE_SYSUTILS}
+        result:=true;
+        if (cs_asm_extern in current_settings.globalswitches) then
+          begin
+            AsmRes.AddAsmCommand(command,para,name);
+            exit;
+          end;
         try
           FlushOutput;
           DosExitCode := ExecuteProcess(command,para);
           if DosExitCode <>0
           then begin
             Message1(exec_e_error_while_assembling,tostr(dosexitcode));
-            callassembler:=false;
+            result:=false;
           end;
         except on E:EOSError do
           begin
             Message1(exec_e_cant_call_assembler,tostr(E.ErrorCode));
             current_settings.globalswitches:=current_settings.globalswitches+[cs_asm_extern];
-            callassembler:=false;
-          end
-        end
-{$ELSE USE_SYSUTILS}
-         begin
-           FlushOutput;
-           swapvectors;
-           exec(maybequoted(command),para);
-           swapvectors;
-           if (doserror<>0) then
-            begin
-              Message1(exec_e_cant_call_assembler,tostr(doserror));
-              current_settings.globalswitches:=current_settings.globalswitches+[cs_asm_extern];
-              callassembler:=false;
-            end
-           else
-            if (dosexitcode<>0) then
-             begin
-              Message1(exec_e_error_while_assembling,tostr(dosexitcode));
-              callassembler:=false;
-             end;
-         end
-{$ENDIF USE_SYSUTILS}
-        else
-         AsmRes.AddAsmCommand(command,para,name);
+            result:=false;
+          end;
+        end;
       end;
 
 
@@ -632,18 +583,10 @@ Implementation
               {$I+}
               if ioresult=0 then
                begin
-{$IFDEF USE_SYSUTILS}
                  FileAge := FileGetDate(GetFileHandle(f));
-{$ELSE USE_SYSUTILS}
-                 GetFTime(f, FileAge);
-{$ENDIF USE_SYSUTILS}
                  close(f);
                  reset(outfile,1);
-{$IFDEF USE_SYSUTILS}
                  FileSetDate(GetFileHandle(outFile),FileAge);
-{$ELSE USE_SYSUTILS}
-                 SetFTime(f, FileAge);
-{$ENDIF USE_SYSUTILS}
                end;
             end;
            close(outfile);

+ 14 - 13
compiler/browcol.pas

@@ -24,8 +24,15 @@
   {$N+,E+}
 {$endif}
 unit browcol;
+
+{$i fpcdefs.inc}
+{$H-}
+
 interface
+
 uses
+  SysUtils,
+  CUtils,
   objects,
   cclasses,
   symconst,symtable;
@@ -218,7 +225,7 @@ type
       UsedUnits  : PSymbolCollection;
       DependentUnits: PSymbolCollection;
       MainSource: PString;
-      SourceFiles: PStringCollection;
+      SourceFiles: pstringCollection;
       constructor Init(const AName, AMainSource: string);
       procedure   SetLoadedFrom(const AModuleName: string);
       procedure   AddUsedUnit(P: PSymbol);
@@ -254,16 +261,10 @@ procedure RegisterSymbols;
 implementation
 
 uses
-{$IFDEF USE_SYSUTILS}
-  SysUtils,
-{$ELSE USE_SYSUTILS}
-  Dos,
-{$ENDIF USE_SYSUTILS}
+  globtype,globals,comphook,
 {$ifdef DEBUG}
   verbose,
 {$endif DEBUG}
-  CUtils,
-  globtype,globals,comphook,
   finput,fmodule,
   cpuinfo,cgbase,aasmbase,aasmtai,aasmdata,paramgr,
   symsym,symdef,symtype,symbase,defutil;
@@ -1841,7 +1842,7 @@ end;
 procedure BuildSourceList;
 var m: tmodule;
     s: tinputfile;
-    p: cutils.pstring;
+    p: pstring;
     ppu,obj: string;
     source: string;
 begin
@@ -1856,12 +1857,12 @@ begin
     m:=tmodule(loaded_units.first);
     while assigned(m) do
     begin
-      obj:=fexpand(m.objfilename^);
+      obj:=ExpandFileName(m.objfilename^);
       ppu:=''; source:='';
       if m.is_unit then
-        ppu:=fexpand(m.ppufilename^);
+        ppu:=ExpandFileName(m.ppufilename^);
       if (m.is_unit=false) and (m.islibrary=false) then
-        ppu:=fexpand(m.exefilename^);
+        ppu:=ExpandFileName(m.exefilename^);
       if assigned(m.sourcefiles) then
         begin
           s:=m.sourcefiles.files;
@@ -1874,7 +1875,7 @@ begin
             p:=s.name;
             if assigned(p) then
               source:=source+p^;
-            source:=fexpand(source);
+            source:=ExpandFileName(source);
 
             sourcefiles^.Insert(New(PSourceFile, Init(source,obj,ppu)));
             s:=s.ref_next;

+ 1 - 1
compiler/browlog.pas

@@ -71,7 +71,7 @@ var
 implementation
 
   uses
-    cutils,comphook,
+    cutils,cfileutils,comphook,
     globals,systems,
     ppu;
 

+ 125 - 3
compiler/cclasses.pas

@@ -235,7 +235,7 @@ type
   TFPHashObject = class
   private
     FOwner : TFPHashObjectList;
-    FCachedStr : pstring;
+    FCachedStr : pshortstring;
     FStrIndex  : Integer;
   protected
     function GetName:string;
@@ -348,7 +348,7 @@ type
 
        { string containerItem }
        TStringListItem = class(TLinkedListItem)
-          FPStr : PString;
+          FPStr : pshortstring;
        public
           constructor Create(const s:string);
           destructor  Destroy;override;
@@ -406,7 +406,7 @@ type
          FLeft,
          FRight      : TNamedIndexItem;
          FSpeedValue : cardinal;
-         FName       : Pstring;
+         FName       : pshortstring;
        protected
          function  GetName:string;virtual;
          procedure SetName(const n:string);virtual;
@@ -3487,5 +3487,127 @@ begin
     end;
 end;
 
+{****************************************************************************
+                           TDirectoryCache
+****************************************************************************}
+
+type
+      TCachedDirectory = class(TFPHashObject)
+      private
+        FDirectoryEntries : TFPHashList;
+      public
+        constructor Create(AList:TFPHashObjectList;const AName:string);
+        destructor  destroy;override;
+        procedure Reload;
+        function FileExists(const AName:string):boolean;
+        function DirectoryExists(const AName:string):boolean;
+        property DirectoryEntries:TFPHashList read FDirectoryEntries;
+      end;
+
+      TDirectoryCache = class
+      private
+        FDirectories : TFPHashObjectList;
+        function GetDirectory(const ADir:string):TCachedDirectory;
+      public
+        constructor Create;
+        destructor  destroy;override;
+        function FileExists(const AName:string):boolean;
+        function DirectoryExists(const AName:string):boolean;
+      end;
+
+
+    constructor TCachedDirectory.create(AList:TFPHashObjectList;const AName:string);
+      begin
+        inherited create(AList,AName);
+        FDirectoryEntries:=TFPHashList.Create;
+      end;
+
+
+    destructor TCachedDirectory.destroy;
+      begin
+        FDirectoryEntries.Free;
+        inherited destroy;
+      end;
+
+
+    procedure TCachedDirectory.Reload;
+      var
+        dir  : TSearchRec;
+        Attr : PtrInt;
+      begin
+        DirectoryEntries.Clear;
+        if findfirst(IncludeTrailingPathDelimiter(Name)+'*',faAnyFile or faDirectory,dir) = 0 then
+          begin
+            repeat
+              if ((dir.attr and faDirectory)<>0) then
+                Attr:=2
+              else
+                Attr:=1;
+              DirectoryEntries.Add(Dir.Name,Pointer(Attr));
+            until findnext(dir) <> 0;
+          end;
+      end;
+
+
+    function TCachedDirectory.FileExists(const AName:string):boolean;
+      begin
+        Result:=(PtrInt(DirectoryEntries.Find(AName))=1);
+      end;
+
+
+    function TCachedDirectory.DirectoryExists(const AName:string):boolean;
+      begin
+        Result:=(PtrInt(DirectoryEntries.Find(AName))=2);
+      end;
+
+
+    constructor TDirectoryCache.create;
+      begin
+        inherited create;
+        FDirectories:=TFPHashObjectList.Create(false);
+      end;
+
+
+    destructor TDirectoryCache.destroy;
+      begin
+        FDirectories.Free;
+        inherited destroy;
+      end;
+
+
+    function TDirectoryCache.GetDirectory(const ADir:string):TCachedDirectory;
+      var
+        CachedDir : TCachedDirectory;
+      begin
+        CachedDir:=TCachedDirectory(FDirectories.Find(ADir));
+        if not assigned(CachedDir) then
+          begin
+            CachedDir:=TCachedDirectory.Create(FDirectories,ADir);
+            CachedDir.Reload;
+          end;
+        Result:=CachedDir;
+      end;
+
+
+    function TDirectoryCache.FileExists(const AName:string):boolean;
+      var
+        CachedDir : TCachedDirectory;
+      begin
+        Result:=false;
+        CachedDir:=GetDirectory(ExtractFileDir(AName));
+        if assigned(CachedDir) then
+          Result:=CachedDir.FileExists(ExtractFileName(AName));
+      end;
+
+
+    function TDirectoryCache.DirectoryExists(const AName:string):boolean;
+      var
+        CachedDir : TCachedDirectory;
+      begin
+        Result:=false;
+        CachedDir:=GetDirectory(ExtractFilePath(AName));
+        if assigned(CachedDir) then
+          Result:=CachedDir.DirectoryExists(ExtractFileName(AName));
+      end;
 
 end.

+ 1086 - 0
compiler/cfileutils.pas

@@ -0,0 +1,1086 @@
+{
+    Copyright (c) 1998-2002 by Florian Klaempfl and Peter Vreman
+
+    This module provides some basic file/dir handling utils and classes
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit cfileutils;
+
+{$i fpcdefs.inc}
+
+{$define usedircache}
+
+interface
+
+    uses
+{$IFNDEF USE_FAKE_SYSUTILS}
+      SysUtils,
+{$ELSE}
+      fksysutl,
+{$ENDIF}
+      GlobType,
+      CUtils,CClasses,
+      Systems;
+
+    type
+      TCachedDirectory = class(TFPHashObject)
+      private
+        FDirectoryEntries : TFPHashList;
+      public
+        constructor Create(AList:TFPHashObjectList;const AName:string);
+        destructor  destroy;override;
+        procedure Reload;
+        function FileExists(const AName:string):boolean;
+        function DirectoryExists(const AName:string):boolean;
+        property DirectoryEntries:TFPHashList read FDirectoryEntries;
+      end;
+
+      TCachedSearchRec = record
+        Name       : string;
+        Attr       : byte;
+        Pattern    : string;
+        CachedDir  : TCachedDirectory;
+        EntryIndex : longint;
+      end;
+
+      TDirectoryCache = class
+      private
+        FDirectories : TFPHashObjectList;
+        function GetDirectory(const ADir:string):TCachedDirectory;
+      public
+        constructor Create;
+        destructor  destroy;override;
+        function FileExists(const AName:string):boolean;
+        function DirectoryExists(const AName:string):boolean;
+        function FindFirst(const APattern:string;var Res:TCachedSearchRec):boolean;
+        function FindNext(var Res:TCachedSearchRec):boolean;
+        function FindClose(var Res:TCachedSearchRec):boolean;
+      end;
+
+      TSearchPathList = class(TStringList)
+        procedure AddPath(s:string;addfirst:boolean);overload;
+        procedure AddPath(SrcPath,s:string;addfirst:boolean);overload;
+        procedure AddList(list:TSearchPathList;addfirst:boolean);
+        function  FindFile(const f : string;var foundfile:string):boolean;
+      end;
+
+    {Gives the absolute path to the current directory}
+    function  GetCurrentDir:string;
+    {Gives the relative path to the current directory,
+     with a trailing dir separator. E. g. on unix ./ }
+    function CurDirRelPath(systeminfo: tsysteminfo): string;
+    function  path_absolute(const s : string) : boolean;
+    Function  PathExists ( F : String) : Boolean;
+    Function  FileExists ( Const F : String) : Boolean;
+    function  FileExistsNonCase(const path,fn:string;var foundfile:string):boolean;
+    Function  RemoveFile(const f:string):boolean;
+    Function  RemoveDir(d:string):boolean;
+    Function  GetFileTime ( Var F : File) : Longint;
+    {Extracts the path without its filename, from a path.}
+    Function  FixPath(s:string;allowdot:boolean):string;
+    function  FixFileName(const s:string):string;
+    function  TargetFixPath(s:string;allowdot:boolean):string;
+    function  TargetFixFileName(const s:string):string;
+    procedure SplitBinCmd(const s:string;var bstr: String;var cstr:TCmdStr);
+    function  FindFile(const f : string;path : string;var foundfile:string):boolean;
+    function  FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
+    function  FindExe(const bin:string;var foundfile:string):boolean;
+    function  GetShortName(const n:string):string;
+
+    procedure InitFileUtils;
+    procedure DoneFileUtils;
+
+
+implementation
+
+    uses
+{$ifdef hasunix}
+      Baseunix,unix,
+{$endif}
+      Comphook,
+      Globals;
+
+    var
+      DirCache : TDirectoryCache;
+
+
+{****************************************************************************
+                           TCachedDirectory
+****************************************************************************}
+
+    constructor TCachedDirectory.create(AList:TFPHashObjectList;const AName:string);
+      begin
+        inherited create(AList,AName);
+        FDirectoryEntries:=TFPHashList.Create;
+      end;
+
+
+    destructor TCachedDirectory.destroy;
+      begin
+        FDirectoryEntries.Free;
+        inherited destroy;
+      end;
+
+
+    procedure TCachedDirectory.Reload;
+      var
+        dir  : TSearchRec;
+      begin
+        DirectoryEntries.Clear;
+        if findfirst(IncludeTrailingPathDelimiter(Name)+'*',faAnyFile or faDirectory,dir) = 0 then
+          begin
+            repeat
+              if ((dir.attr and faDirectory)<>faDirectory) or
+                 (dir.Name<>'.') or
+                 (dir.Name<>'..') then
+                DirectoryEntries.Add(Dir.Name,Pointer(Dir.Attr));
+            until findnext(dir) <> 0;
+          end;
+      end;
+
+
+    function TCachedDirectory.FileExists(const AName:string):boolean;
+      var
+        Attr : Longint;
+      begin
+        Attr:=PtrInt(DirectoryEntries.Find(AName));
+        if Attr<>0 then
+          Result:=((Attr and faDirectory)=0)
+        else
+          Result:=false;
+      end;
+
+
+    function TCachedDirectory.DirectoryExists(const AName:string):boolean;
+      var
+        Attr : Longint;
+      begin
+        Attr:=PtrInt(DirectoryEntries.Find(AName));
+        if Attr<>0 then
+          Result:=((Attr and faDirectory)=faDirectory)
+        else
+          Result:=false;
+      end;
+
+
+{****************************************************************************
+                           TDirectoryCache
+****************************************************************************}
+
+    constructor TDirectoryCache.create;
+      begin
+        inherited create;
+        FDirectories:=TFPHashObjectList.Create(false);
+      end;
+
+
+    destructor TDirectoryCache.destroy;
+      begin
+        FDirectories.Free;
+        inherited destroy;
+      end;
+
+
+    function TDirectoryCache.GetDirectory(const ADir:string):TCachedDirectory;
+      var
+        CachedDir : TCachedDirectory;
+        DirName   : string;
+      begin
+        if ADir='' then
+          DirName:='.'
+        else
+          DirName:=ADir;
+        CachedDir:=TCachedDirectory(FDirectories.Find(DirName));
+        if not assigned(CachedDir) then
+          begin
+            CachedDir:=TCachedDirectory.Create(FDirectories,DirName);
+            CachedDir.Reload;
+          end;
+        Result:=CachedDir;
+      end;
+
+
+    function TDirectoryCache.FileExists(const AName:string):boolean;
+      var
+        CachedDir : TCachedDirectory;
+      begin
+{$ifdef usedircache}
+        Result:=false;
+        CachedDir:=GetDirectory(ExtractFileDir(AName));
+        if assigned(CachedDir) then
+          Result:=CachedDir.FileExists(ExtractFileName(AName));
+{$else usedircache}
+        Result:=SysUtils.FileExists(AName);
+{$endif usedircache}
+      end;
+
+
+    function TDirectoryCache.DirectoryExists(const AName:string):boolean;
+      var
+        CachedDir : TCachedDirectory;
+      begin
+{$ifdef usedircache}
+        Result:=false;
+        CachedDir:=GetDirectory(ExtractFilePath(AName));
+        if assigned(CachedDir) then
+          Result:=CachedDir.DirectoryExists(ExtractFileName(AName));
+{$else usedircache}
+        Result:=SysUtils.DirectoryExists(AName);
+{$endif usedircache}
+      end;
+
+
+    function TDirectoryCache.FindFirst(const APattern:string;var Res:TCachedSearchRec):boolean;
+      begin
+        Res.Pattern:=ExtractFileName(APattern);
+        Res.CachedDir:=GetDirectory(ExtractFilePath(APattern));
+        Res.EntryIndex:=0;
+        if assigned(Res.CachedDir) then
+          Result:=FindNext(Res)
+        else
+          Result:=false;
+      end;
+
+
+    function TDirectoryCache.FindNext(var Res:TCachedSearchRec):boolean;
+      begin
+        if Res.EntryIndex<Res.CachedDir.DirectoryEntries.Count then
+          begin
+            Res.Name:=Res.CachedDir.DirectoryEntries.NameOfIndex(Res.EntryIndex);
+            Res.Attr:=PtrInt(Res.CachedDir.DirectoryEntries[Res.EntryIndex]);
+            inc(Res.EntryIndex);
+            Result:=true;
+          end
+        else
+          Result:=false;
+      end;
+
+
+    function TDirectoryCache.FindClose(var Res:TCachedSearchRec):boolean;
+      begin
+        { nothing todo }
+        result:=true;
+      end;
+
+
+{****************************************************************************
+                                   Utils
+****************************************************************************}
+
+    procedure WarnNonExistingPath(const path : string);
+      begin
+        if assigned(do_comment) then
+          do_comment(V_Tried,'Path "'+path+'" not found');
+      end;
+
+
+   {Gives the absolute path to the current directory}
+     var
+       CachedCurrentDir : string;
+   function GetCurrentDir:string;
+     begin
+       if CachedCurrentDir='' then
+         begin
+           GetDir(0,CachedCurrentDir);
+           CachedCurrentDir:=FixPath(CachedCurrentDir,false);
+         end;
+       result:=CachedCurrentDir;
+     end;
+
+   {Gives the relative path to the current directory,
+    with a trailing dir separator. E. g. on unix ./ }
+   function CurDirRelPath(systeminfo: tsysteminfo): string;
+
+   begin
+     if systeminfo.system <> system_powerpc_macos then
+       CurDirRelPath:= '.'+systeminfo.DirSep
+     else
+       CurDirRelPath:= ':'
+   end;
+
+
+   function path_absolute(const s : string) : boolean;
+   {
+     is path s an absolute path?
+   }
+     begin
+        result:=false;
+{$if defined(unix)}
+        if (length(s)>0) and (s[1]='/') then
+          result:=true;
+{$elseif defined(amiga)}
+        if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or (Pos(':',s) = length(s)) then
+          result:=true;
+{$elseif defined(macos)}
+        if IsMacFullPath(s) then
+          result:=true;
+        if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or
+           ((length(s)>2) and (s[2]=':') and ((s[3]='\') or (s[3]='/'))) then
+          result:=true;
+{$endif unix}
+     end;
+
+    Function FileExists ( Const F : String) : Boolean;
+      begin
+        Result:={$ifdef usedircache}DirCache.{$else}SysUtils.{$endif}FileExists(F);
+        if assigned(do_comment) then
+         begin
+           if Result then
+             do_comment(V_Tried,'Searching file '+F+'... found')
+           else
+             do_comment(V_Tried,'Searching file '+F+'... not found');
+         end;
+      end;
+
+
+    function FileExistsNonCase(const path,fn:string;var foundfile:string):boolean;
+      var
+        fn2 : string;
+      begin
+        result:=false;
+        if tf_files_case_sensitive in source_info.flags then
+          begin
+            {
+              Search order for case sensitive systems:
+               1. NormalCase
+               2. lowercase
+               3. UPPERCASE
+            }
+            FoundFile:=path+fn;
+            If FileExists(FoundFile) then
+             begin
+               result:=true;
+               exit;
+             end;
+            fn2:=Lower(fn);
+            if fn2<>fn then
+              begin
+                FoundFile:=path+fn2;
+                If FileExists(FoundFile) then
+                 begin
+                   result:=true;
+                   exit;
+                 end;
+              end;
+            fn2:=Upper(fn);
+            if fn2<>fn then
+              begin
+                FoundFile:=path+fn2;
+                If FileExists(FoundFile) then
+                 begin
+                   result:=true;
+                   exit;
+                 end;
+              end;
+          end
+        else
+          if tf_files_case_aware in source_info.flags then
+            begin
+              {
+                Search order for case aware systems:
+                 1. NormalCase
+              }
+              FoundFile:=path+fn;
+              If FileExists(FoundFile) then
+               begin
+                 result:=true;
+                 exit;
+               end;
+           end
+        else
+          begin
+            { None case sensitive only lowercase }
+            FoundFile:=path+Lower(fn);
+            If FileExists(FoundFile) then
+             begin
+               result:=true;
+               exit;
+             end;
+          end;
+        { Set foundfile to something usefull }
+        FoundFile:=fn;
+      end;
+
+
+    Function PathExists ( F : String) : Boolean;
+      Var
+        I: longint;
+      begin
+        if F = '' then
+          begin
+            result := true;
+            exit;
+          end;
+        F := ExpandFileName(F);
+        I := Pos (DriveSeparator, F);
+        if (F [Length (F)] = DirectorySeparator) and
+           (((I = 0) and (Length (F) > 1)) or (I <> Length (F) - 1)) then
+          Delete (F, Length (F), 1);
+        Result:=SysUtils.DirectoryExists(F);
+      end;
+
+
+    Function RemoveFile(const f:string):boolean;
+      var
+        g : file;
+      begin
+        assign(g,f);
+        {$I-}
+         erase(g);
+        {$I+}
+        RemoveFile:=(ioresult=0);
+      end;
+
+
+    Function RemoveDir(d:string):boolean;
+      begin
+        if d[length(d)]=source_info.DirSep then
+         Delete(d,length(d),1);
+        {$I-}
+         rmdir(d);
+        {$I+}
+        RemoveDir:=(ioresult=0);
+      end;
+
+
+    Function FixPath(s:string;allowdot:boolean):string;
+      var
+        i : longint;
+      begin
+        { Fix separator }
+        for i:=1 to length(s) do
+         if s[i] in ['/','\'] then
+          s[i]:=source_info.DirSep;
+        { Fix ending / }
+        if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
+           (s[length(s)]<>':') then
+         s:=s+source_info.DirSep;
+        { Remove ./ }
+        if (not allowdot) and (s='.'+source_info.DirSep) then
+         s:='';
+        { return }
+        if (tf_files_case_aware in source_info.flags) or
+           (tf_files_case_sensitive in source_info.flags) then
+         FixPath:=s
+        else
+         FixPath:=Lower(s);
+      end;
+
+  {Actually the version in macutils.pp could be used,
+   but that would not work for crosscompiling, so this is a slightly modified
+   version of it.}
+  function TranslatePathToMac (const path: string; mpw: Boolean): string;
+
+    function GetVolumeIdentifier: string;
+
+    begin
+      GetVolumeIdentifier := '{Boot}'
+      (*
+      if mpw then
+        GetVolumeIdentifier := '{Boot}'
+      else
+        GetVolumeIdentifier := macosBootVolumeName;
+      *)
+    end;
+
+    var
+      slashPos, oldpos, newpos, oldlen, maxpos: Longint;
+
+  begin
+    oldpos := 1;
+    slashPos := Pos('/', path);
+    if (slashPos <> 0) then   {its a unix path}
+      begin
+        if slashPos = 1 then
+          begin      {its a full path}
+            oldpos := 2;
+            TranslatePathToMac := GetVolumeIdentifier;
+          end
+        else     {its a partial path}
+          TranslatePathToMac := ':';
+      end
+    else
+      begin
+        slashPos := Pos('\', path);
+        if (slashPos <> 0) then   {its a dos path}
+          begin
+            if slashPos = 1 then
+              begin      {its a full path, without drive letter}
+                oldpos := 2;
+                TranslatePathToMac := GetVolumeIdentifier;
+              end
+            else if (Length(path) >= 2) and (path[2] = ':') then {its a full path, with drive letter}
+              begin
+                oldpos := 4;
+                TranslatePathToMac := GetVolumeIdentifier;
+              end
+            else     {its a partial path}
+              TranslatePathToMac := ':';
+          end;
+      end;
+
+    if (slashPos <> 0) then   {its a unix or dos path}
+      begin
+        {Translate "/../" to "::" , "/./" to ":" and "/" to ":" }
+        newpos := Length(TranslatePathToMac);
+        oldlen := Length(path);
+        SetLength(TranslatePathToMac, newpos + oldlen);  {It will be no longer than what is already}
+                                                                        {prepended plus length of path.}
+        maxpos := Length(TranslatePathToMac);          {Get real maxpos, can be short if String is ShortString}
+
+        {There is never a slash in the beginning, because either it was an absolute path, and then the}
+        {drive and slash was removed, or it was a relative path without a preceding slash.}
+        while oldpos <= oldlen do
+          begin
+            {Check if special dirs, ./ or ../ }
+            if path[oldPos] = '.' then
+              if (oldpos + 1 <= oldlen) and (path[oldPos + 1] = '.') then
+                begin
+                  if (oldpos + 2 > oldlen) or (path[oldPos + 2] in ['/', '\']) then
+                    begin
+                      {It is "../" or ".."  translates to ":" }
+                      if newPos = maxPos then
+                        begin {Shouldn't actually happen, but..}
+                          Exit('');
+                        end;
+                      newPos := newPos + 1;
+                      TranslatePathToMac[newPos] := ':';
+                      oldPos := oldPos + 3;
+                      continue;  {Start over again}
+                    end;
+                end
+              else if (oldpos + 1 > oldlen) or (path[oldPos + 1] in ['/', '\']) then
+                begin
+                  {It is "./" or "."  ignor it }
+                  oldPos := oldPos + 2;
+                  continue;  {Start over again}
+                end;
+
+            {Collect file or dir name}
+            while (oldpos <= oldlen) and not (path[oldPos] in ['/', '\']) do
+              begin
+                if newPos = maxPos then
+                  begin {Shouldn't actually happen, but..}
+                    Exit('');
+                  end;
+                newPos := newPos + 1;
+                TranslatePathToMac[newPos] := path[oldPos];
+                oldPos := oldPos + 1;
+              end;
+
+            {When we come here there is either a slash or we are at the end.}
+            if (oldpos <= oldlen) then
+              begin
+                if newPos = maxPos then
+                  begin {Shouldn't actually happen, but..}
+                    Exit('');
+                  end;
+                newPos := newPos + 1;
+                TranslatePathToMac[newPos] := ':';
+                oldPos := oldPos + 1;
+              end;
+          end;
+
+        SetLength(TranslatePathToMac, newpos);
+      end
+    else if (path = '.') then
+      TranslatePathToMac := ':'
+    else if (path = '..') then
+      TranslatePathToMac := '::'
+    else
+      TranslatePathToMac := path;  {its a mac path}
+  end;
+
+
+   function FixFileName(const s:string):string;
+     var
+       i      : longint;
+     begin
+       if source_info.system = system_powerpc_MACOS then
+         FixFileName:= TranslatePathToMac(s, true)
+       else
+        if (tf_files_case_aware in source_info.flags) or
+           (tf_files_case_sensitive in source_info.flags) then
+        begin
+          for i:=1 to length(s) do
+           begin
+             case s[i] of
+               '/','\' :
+                 FixFileName[i]:=source_info.dirsep;
+               else
+                 FixFileName[i]:=s[i];
+             end;
+           end;
+          FixFileName[0]:=s[0];
+        end
+       else
+        begin
+          for i:=1 to length(s) do
+           begin
+             case s[i] of
+               '/','\' :
+                  FixFileName[i]:=source_info.dirsep;
+               'A'..'Z' :
+                  FixFileName[i]:=char(byte(s[i])+32);
+                else
+                  FixFileName[i]:=s[i];
+             end;
+           end;
+          FixFileName[0]:=s[0];
+        end;
+     end;
+
+
+    Function TargetFixPath(s:string;allowdot:boolean):string;
+      var
+        i : longint;
+      begin
+        { Fix separator }
+        for i:=1 to length(s) do
+         if s[i] in ['/','\'] then
+          s[i]:=target_info.DirSep;
+        { Fix ending / }
+        if (length(s)>0) and (s[length(s)]<>target_info.DirSep) and
+           (s[length(s)]<>':') then
+         s:=s+target_info.DirSep;
+        { Remove ./ }
+        if (not allowdot) and (s='.'+target_info.DirSep) then
+         s:='';
+        { return }
+        if (tf_files_case_aware in target_info.flags) or
+           (tf_files_case_sensitive in target_info.flags) then
+         TargetFixPath:=s
+        else
+         TargetFixPath:=Lower(s);
+      end;
+
+
+   function TargetFixFileName(const s:string):string;
+     var
+       i : longint;
+     begin
+       if target_info.system = system_powerpc_MACOS then
+         TargetFixFileName:= TranslatePathToMac(s, true)
+       else
+        if (tf_files_case_aware in target_info.flags) or
+           (tf_files_case_sensitive in target_info.flags) then
+         begin
+           for i:=1 to length(s) do
+           begin
+             case s[i] of
+               '/','\' :
+                 TargetFixFileName[i]:=target_info.dirsep;
+               else
+                 TargetFixFileName[i]:=s[i];
+             end;
+           end;
+           TargetFixFileName[0]:=s[0];
+         end
+       else
+         begin
+           for i:=1 to length(s) do
+           begin
+             case s[i] of
+               '/','\' :
+                  TargetFixFileName[i]:=target_info.dirsep;
+               'A'..'Z' :
+                  TargetFixFileName[i]:=char(byte(s[i])+32);
+                else
+                  TargetFixFileName[i]:=s[i];
+             end;
+           end;
+           TargetFixFileName[0]:=s[0];
+         end;
+     end;
+
+
+   procedure SplitBinCmd(const s:string;var bstr:String;var cstr:TCmdStr);
+     var
+       i : longint;
+     begin
+       i:=pos(' ',s);
+       if i>0 then
+        begin
+          bstr:=Copy(s,1,i-1);
+          cstr:=Copy(s,i+1,length(s)-i);
+        end
+       else
+        begin
+          bstr:=s;
+          cstr:='';
+        end;
+     end;
+
+  procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
+    begin
+      AddPath('',s,AddFirst);
+    end;
+
+   procedure TSearchPathList.AddPath(SrcPath,s:string;addfirst:boolean);
+     var
+       staridx,
+       j        : longint;
+       prefix,
+       suffix,
+       CurrentDir,
+       currPath : string;
+       subdirfound : boolean;
+{$ifdef usedircache}
+       dir      : TCachedSearchRec;
+{$else usedircache}
+       dir      : TSearchRec;
+{$endif usedircache}
+       hp       : TStringListItem;
+
+       procedure AddCurrPath;
+       begin
+         if addfirst then
+          begin
+            Remove(currPath);
+            Insert(currPath);
+          end
+         else
+          begin
+            { Check if already in path, then we don't add it }
+            hp:=Find(currPath);
+            if not assigned(hp) then
+             Concat(currPath);
+          end;
+       end;
+
+     begin
+       if s='' then
+        exit;
+     { Support default macro's }
+       DefaultReplacements(s);
+     { get current dir }
+       CurrentDir:=GetCurrentDir;
+       repeat
+         { get currpath }
+         if addfirst then
+          begin
+            j:=length(s);
+            while (j>0) and (s[j]<>';') do
+             dec(j);
+            currPath:= TrimSpace(Copy(s,j+1,length(s)-j));
+            DePascalQuote(currPath);
+            currPath:=FixPath(currPath,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:= TrimSpace(Copy(s,1,j-1));
+            DePascalQuote(currPath);
+            currPath:=SrcPath+FixPath(currPath,false);
+            System.Delete(s,1,j);
+          end;
+
+         { fix pathname }
+         if currPath='' then
+           currPath:= CurDirRelPath(source_info)
+         else
+          begin
+            currPath:=FixPath(ExpandFileName(currpath),false);
+            if (CurrentDir<>'') and (Copy(currPath,1,length(CurrentDir))=CurrentDir) then
+             begin
+{$ifdef AMIGA}
+               currPath:= CurrentDir+Copy(currPath,length(CurrentDir)+1,255);
+{$else}
+               currPath:= CurDirRelPath(source_info)+Copy(currPath,length(CurrentDir)+1,255);
+{$endif}
+             end;
+          end;
+         { wildcard adding ? }
+         staridx:=pos('*',currpath);
+         if staridx>0 then
+          begin
+            prefix:=ExtractFilePath(Copy(currpath,1,staridx));
+            suffix:=Copy(currpath,staridx+1,length(currpath));
+            subdirfound:=false;
+{$ifdef usedircache}
+            if DirCache.FindFirst(Prefix+'*',dir) then
+              begin
+                repeat
+                  if (dir.attr and faDirectory)<>0 then
+                    begin
+                      subdirfound:=true;
+                      currpath:=prefix+dir.name+suffix;
+                      if (suffix='') or PathExists(currpath) then
+                        begin
+                          hp:=Find(currPath);
+                          if not assigned(hp) then
+                            AddCurrPath;
+                        end;
+                    end;
+                until not DirCache.FindNext(dir);
+              end;
+            DirCache.FindClose(dir);
+{$else usedircache}
+            if findfirst(prefix+'*',faDirectory,dir) = 0 then
+              begin
+                repeat
+                  if (dir.name<>'.') and
+                      (dir.name<>'..') and
+                      ((dir.attr and faDirectory)<>0) then
+                    begin
+                      subdirfound:=true;
+                      currpath:=prefix+dir.name+suffix;
+                      if (suffix='') or PathExists(currpath) then
+                        begin
+                          hp:=Find(currPath);
+                          if not assigned(hp) then
+                            AddCurrPath;
+                        end;
+                    end;
+                until findnext(dir) <> 0;
+              end;
+            FindClose(dir);
+{$endif usedircache}
+            if not subdirfound then
+              WarnNonExistingPath(currpath);
+          end
+         else
+          begin
+            if PathExists(currpath) then
+             AddCurrPath
+            else
+             WarnNonExistingPath(currpath);
+          end;
+       until (s='');
+     end;
+
+
+   procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
+     var
+       s : string;
+       hl : TSearchPathList;
+       hp,hp2 : TStringListItem;
+     begin
+       if list.empty then
+        exit;
+       { create temp and reverse the list }
+       if addfirst then
+        begin
+          hl:=TSearchPathList.Create;
+          hp:=TStringListItem(list.first);
+          while assigned(hp) do
+           begin
+             hl.insert(hp.Str);
+             hp:=TStringListItem(hp.next);
+           end;
+          while not hl.empty do
+           begin
+             s:=hl.GetFirst;
+             Remove(s);
+             Insert(s);
+           end;
+          hl.Free;
+        end
+       else
+        begin
+          hp:=TStringListItem(list.first);
+          while assigned(hp) do
+           begin
+             hp2:=Find(hp.Str);
+             { Check if already in path, then we don't add it }
+             if not assigned(hp2) then
+              Concat(hp.Str);
+             hp:=TStringListItem(hp.next);
+           end;
+        end;
+     end;
+
+
+   function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
+     Var
+       p : TStringListItem;
+     begin
+       FindFile:=false;
+       p:=TStringListItem(first);
+       while assigned(p) do
+        begin
+          result:=FileExistsNonCase(p.Str,f,FoundFile);
+          if result then
+            exit;
+          p:=TStringListItem(p.next);
+        end;
+       { Return original filename if not found }
+       FoundFile:=f;
+     end;
+
+
+   Function GetFileTime ( Var F : File) : Longint;
+     Var
+     {$ifdef hasunix}
+        info: Stat;
+     {$endif}
+       L : longint;
+     begin
+     {$ifdef hasunix}
+      FPFStat (F,Info);
+      L:=Info.st_Mtime;
+     {$else}
+       GetFTime(f,l);
+     {$endif}
+       GetFileTime:=L;
+     end;
+
+
+   function FindFile(const f : string;path : string;var foundfile:string):boolean;
+      Var
+        singlepathstring : string;
+        i : longint;
+     begin
+{$ifdef Unix}
+       for i:=1 to length(path) do
+        if path[i]=':' then
+         path[i]:=';';
+{$endif Unix}
+       FindFile:=false;
+       repeat
+          i:=pos(';',path);
+          if i=0 then
+           i:=256;
+          singlepathstring:=FixPath(copy(path,1,i-1),false);
+          delete(path,1,i);
+          result:=FileExistsNonCase(singlepathstring,f,FoundFile);
+          if result then
+            exit;
+       until path='';
+       FoundFile:=f;
+     end;
+
+
+   function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
+      Var
+        singlepathstring : string;
+        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
+              inc(pc);
+             move(startpc^,singlepathstring[1],pc-startpc);
+             singlepathstring[0]:=char(longint(pc-startpc));
+             singlepathstring:=FixPath(singlepathstring,false);
+             result:=FileExistsNonCase(singlepathstring,f,FoundFile);
+             if result then
+               exit;
+             if (pc^=#0) then
+               break;
+             inc(pc);
+          until false;
+        end;
+       foundfile:=f;
+     end;
+
+
+   function  FindExe(const bin:string;var foundfile:string):boolean;
+     var
+       p : pchar;
+       found : boolean;
+     begin
+       found:=FindFile(FixFileName(ChangeFileExt(bin,source_info.exeext)),'.;'+exepath,foundfile);
+       if not found then
+        begin
+{$ifdef macos}
+          p:=GetEnvPchar('Commands');
+{$else}
+          p:=GetEnvPchar('PATH');
+{$endif}
+          found:=FindFilePChar(FixFileName(ChangeFileExt(bin,source_info.exeext)),p,foundfile);
+          FreeEnvPChar(p);
+        end;
+       FindExe:=found;
+     end;
+
+
+    function GetShortName(const n:string):string;
+{$ifdef win32}
+      var
+        hs,hs2 : string;
+        i : longint;
+{$endif}
+{$ifdef go32v2}
+      var
+        hs : string;
+{$endif}
+{$ifdef watcom}
+      var
+        hs : string;
+{$endif}
+      begin
+        GetShortName:=n;
+{$ifdef win32}
+        hs:=n+#0;
+        i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
+        if (i>0) and (i<=high(hs2)) then
+          begin
+            hs2[0]:=chr(strlen(@hs2[1]));
+            GetShortName:=hs2;
+          end;
+{$endif}
+{$ifdef go32v2}
+        hs:=n;
+        if Dos.GetShortName(hs) then
+         GetShortName:=hs;
+{$endif}
+{$ifdef watcom}
+        hs:=n;
+        if Dos.GetShortName(hs) then
+         GetShortName:=hs;
+{$endif}
+      end;
+
+
+{****************************************************************************
+                           Init / Done
+****************************************************************************}
+
+    procedure InitFileUtils;
+      begin
+        DirCache:=TDirectoryCache.Create;
+      end;
+
+
+    procedure DoneFileUtils;
+      begin
+        DirCache.Free;
+      end;
+
+end.

+ 2 - 2
compiler/cmsgs.pas

@@ -62,8 +62,8 @@ function GetMsgLine(var p:pchar):string;
 implementation
 
 uses
-  cutils,
-  strings;
+  SysUtils,
+  cutils;
 
 
 function MsgReplace(const s:string;const args:array of string):string;

+ 0 - 14
compiler/comphook.pas

@@ -155,9 +155,6 @@ const
 implementation
 
   uses
-{$IFNDEF USE_SYSUTILS}
-   dos,
-{$ENDIF USE_SYSUTILS}
    cutils, systems
    ;
 
@@ -383,23 +380,12 @@ end;
 
 Function def_GetNamedFileTime (Const F : String) : Longint;
 var
-{$IFDEF USE_SYSUTILS}
   fh : THandle;
-{$ELSE USE_SYSUTILS}
-  info : SearchRec;
-{$ENDIF USE_SYSUTILS}
 begin
   Result := -1;
-{$IFDEF USE_SYSUTILS}
   fh := FileOpen(f, faArchive+faReadOnly+faHidden);
   Result := FileGetDate(fh);
   FileClose(fh);
-{$ELSE USE_SYSUTILS}
-  FindFirst (F,archive+readonly+hidden,info);
-  if DosError=0 then
-    Result := info.time;
-  FindClose(info);
-{$ENDIF USE_SYSUTILS}
 end;
 
 end.

+ 7 - 17
compiler/compiler.pas

@@ -36,17 +36,13 @@ uses
 {$ifdef BrowserLog}
   browlog,
 {$endif BrowserLog}
-{$IFDEF USE_SYSUTILS}
-{$ELSE USE_SYSUTILS}
-  dos,
-{$ENDIF USE_SYSUTILS}
 {$IFNDEF USE_FAKE_SYSUTILS}
   sysutils,
 {$ELSE}
   fksysutl,
 {$ENDIF}
   verbose,comphook,systems,
-  cutils,cclasses,globals,options,fmodule,parser,symtable,
+  cutils,cfileutils,cclasses,globals,options,fmodule,parser,symtable,
   assemble,link,dbgbase,import,export,tokens,pass_1
   { cpu parameter handling }
   ,cpupara
@@ -163,6 +159,7 @@ begin
   CompilerInited:=false;
   DoneSymtable;
   DoneGlobals;
+  DoneFileUtils;
   donetokens;
 end;
 
@@ -173,6 +170,8 @@ begin
    DoneCompiler;
 { inits which need to be done before the arguments are parsed }
   InitSystems;
+  { fileutils depends on source_info so it must be after systems }
+  InitFileUtils;
   { globals depends on source_info so it must be after systems }
   InitGlobals;
   { verbose depends on exe_path and must be after globals }
@@ -222,19 +221,10 @@ function Compile(const cmd:string):longint;
 
   function getrealtime : real;
   var
-{$IFDEF USE_SYSUTILS}
     h,m,s,s1000 : word;
-{$ELSE USE_SYSUTILS}
-    h,m,s,s100 : word;
-{$ENDIF USE_SYSUTILS}
   begin
-{$IFDEF USE_SYSUTILS}
     DecodeTime(Time,h,m,s,s1000);
-    getrealtime:=h*3600.0+m*60.0+s+s1000/1000.0;
-{$ELSE USE_SYSUTILS}
-    gettime(h,m,s,s100);
-    getrealtime:=h*3600.0+m*60.0+s+s100/100.0;
-{$ENDIF USE_SYSUTILS}
+    result:=h*3600.0+m*60.0+s+s1000/1000.0;
   end;
 
 var
@@ -265,10 +255,10 @@ begin
        { Compile the program }
   {$ifdef PREPROCWRITE}
        if parapreprocess then
-        parser.preprocess(inputdir+inputfile+inputextension)
+        parser.preprocess(inputfilepath+inputfilename)
        else
   {$endif PREPROCWRITE}
-        parser.compile(inputdir+inputfile+inputextension);
+        parser.compile(inputfilepath+inputfilename);
 
        { Show statistics }
        if status.errorcount=0 then

+ 7 - 39
compiler/comprsrc.pas

@@ -42,12 +42,9 @@ procedure CompileResourceFiles;
 implementation
 
 uses
-{$IFDEF USE_SYSUTILS}
   SysUtils,
-{$ELSE USE_SYSUTILS}
-  dos,
-{$ENDIF USE_SYSUTILS}
-  Systems,cutils,Globtype,Globals,Verbose,Fmodule,
+  Systems,cutils,cfileutils,
+  Globtype,Globals,Verbose,Fmodule,
   Script;
 
 {****************************************************************************
@@ -68,12 +65,8 @@ end;
 procedure tresourcefile.compile;
 var
   respath,
-  srcfilepath : dirstr;
-  n       : namestr;
-{$IFDEF USE_SYSUTILS}
-{$ELSE USE_SYSUTILS}
-  e       : extstr;
-{$ENDIF USE_SYSUTILS}
+  srcfilepath,
+  n,
   s,
   resobj,
   resbin   : string;
@@ -87,24 +80,16 @@ begin
   if not resfound then
     resfound:=FindExe(utilsprefix+target_res.resbin,resbin);
   { get also the path to be searched for the windres.h }
-{$IFDEF USE_SYSUTILS}
-  respath := SplitPath(resbin);
-{$ELSE USE_SYSUTILS}
-  fsplit(resbin,respath,n,e);
-{$ENDIF USE_SYSUTILS}
+  respath:=ExtractFilePath(resbin);
   if (not resfound) and not(cs_link_nolink in current_settings.globalswitches) then
    begin
      Message(exec_e_res_not_found);
      current_settings.globalswitches:=current_settings.globalswitches+[cs_link_nolink];
    end;
-{$IFDEF USE_SYSUTILS}
-  srcfilepath := SplitPath(current_module.mainsource^);
-{$ELSE USE_SYSUTILS}
-  fsplit(current_module.mainsource^,srcfilepath,n,e);
-{$ENDIF USE_SYSUTILS}
+  srcfilepath:=ExtractFilePath(current_module.mainsource^);
   if not path_absolute(fname) then
     fname:=srcfilepath+fname;
-  resobj:=ForceExtension(fname,target_info.resobjext);
+  resobj:=ChangeFileExt(fname,target_info.resobjext);
   s:=target_res.rescmd;
   ObjUsed:=(pos('$OBJ',s)>0);
   Replace(s,'$OBJ',maybequoted(resobj));
@@ -122,7 +107,6 @@ begin
      Message1(exec_i_compilingresource,fname);
      Message2(exec_d_resbin_params,resbin,s);
      FlushOutput;
-{$IFDEF USE_SYSUTILS}
      try
        if ExecuteProcess(resbin,s) <> 0 then
        begin
@@ -136,22 +120,6 @@ begin
          current_settings.globalswitches:=current_settings.globalswitches+[cs_link_nolink];
        end
      end;
-{$ELSE USE_SYSUTILS}
-     swapvectors;
-     exec(resbin,s);
-     swapvectors;
-     if (doserror<>0) then
-      begin
-        Message(exec_e_cant_call_linker);
-        current_settings.globalswitches:=current_settings.globalswitches+[cs_link_nolink];
-      end
-     else
-      if (dosexitcode<>0) then
-       begin
-         Message(exec_e_error_while_linking);
-         current_settings.globalswitches:=current_settings.globalswitches+[cs_link_nolink];
-       end;
-{$ENDIF USE_SYSUTILS}
     end;
   { Update asmres when externmode is set }
   if cs_link_nolink in current_settings.globalswitches then

+ 3 - 2
compiler/cresstr.pas

@@ -31,6 +31,7 @@ interface
 implementation
 
 uses
+   SysUtils,
    cclasses,
    cutils,globtype,globals,systems,
    symconst,symtype,symdef,symsym,
@@ -235,8 +236,8 @@ uses
         end;
 
       begin
-        ResFileName:=ForceExtension(current_module.ppufilename^,'.rst');
-        message1 (general_i_writingresourcefile,SplitFileName(ResFileName));
+        ResFileName:=ChangeFileExt(current_module.ppufilename^,'.rst');
+        message1 (general_i_writingresourcefile,ExtractFileName(ResFileName));
         Assign(F,ResFileName);
         {$i-}
         Rewrite(f);

+ 18 - 30
compiler/cutils.pas

@@ -31,7 +31,7 @@ interface
 
 
     type
-       pstring = ^string;
+       pshortstring = ^string;
        Tcharset=set of char;
 
     var
@@ -99,19 +99,18 @@ interface
 
     { releases the string p and assignes nil to p }
     { if p=nil then freemem isn't called          }
-    procedure stringdispose(var p : pstring);{$ifdef USEINLINE}inline;{$endif}
+    procedure stringdispose(var p : pshortstring);{$ifdef USEINLINE}inline;{$endif}
 
 
     { allocates mem for a copy of s, copies s to this mem and returns }
     { a pointer to this mem                                           }
-    function stringdup(const s : string) : pstring;{$ifdef USEINLINE}inline;{$endif}
+    function stringdup(const s : string) : pshortstring;{$ifdef USEINLINE}inline;{$endif}
 
     {# Allocates memory for the string @var(s) and copies s as zero
        terminated string to that allocated memory and returns a pointer
        to that mem
     }
     function  strpnew(const s : string) : pchar;
-    procedure strdispose(var p : pchar);
 
     {# makes the character @var(c) lowercase, with spanish, french and german
        character set
@@ -120,10 +119,10 @@ interface
 
     { makes zero terminated string to a pascal string }
     { the data in p is modified and p is returned     }
-    function pchar2pstring(p : pchar) : pstring;
+    function pchar2pshortstring(p : pchar) : pshortstring;
 
-    { ambivalent to pchar2pstring }
-    function pstring2pchar(p : pstring) : pchar;
+    { ambivalent to pchar2pshortstring }
+    function pshortstring2pchar(p : pshortstring) : pchar;
 
     { Speed/Hash value }
     Function GetSpeedValue(Const s:String):cardinal;
@@ -140,10 +139,8 @@ interface
 
 implementation
 
-uses
-  strings
-  ;
-
+    uses
+      SysUtils;
 
     var
       uppertbl,
@@ -721,7 +718,7 @@ uses
 
 
     function nextpowerof2(value : int64; out power: longint) : int64;
-    { 
+    {
       returns the power of 2 >= value
     }
       var
@@ -866,7 +863,7 @@ uses
     end;
 
 
-    function pchar2pstring(p : pchar) : pstring;
+    function pchar2pshortstring(p : pchar) : pshortstring;
       var
          w,i : longint;
       begin
@@ -874,11 +871,11 @@ uses
          for i:=w-1 downto 0 do
            p[i+1]:=p[i];
          p[0]:=chr(w);
-         pchar2pstring:=pstring(p);
+         pchar2pshortstring:=pshortstring(p);
       end;
 
 
-    function pstring2pchar(p : pstring) : pchar;
+    function pshortstring2pchar(p : pshortstring) : pchar;
       var
          w,i : longint;
       begin
@@ -886,7 +883,7 @@ uses
          for i:=1 to w do
            p^[i-1]:=p^[i];
          p^[w]:=#0;
-         pstring2pchar:=pchar(p);
+         pshortstring2pchar:=pchar(p);
       end;
 
 
@@ -914,22 +911,13 @@ uses
          p : pchar;
       begin
          getmem(p,length(s)+1);
-         strpcopy(p,s);
-         strpnew:=p;
-      end;
-
-
-    procedure strdispose(var p : pchar);
-      begin
-        if assigned(p) then
-         begin
-           freemem(p);
-           p:=nil;
-         end;
+         move(s[1],p^,length(s));
+         p[length(s)]:=#0;
+         result:=p;
       end;
 
 
-    procedure stringdispose(var p : pstring);{$ifdef USEINLINE}inline;{$endif}
+    procedure stringdispose(var p : pshortstring);{$ifdef USEINLINE}inline;{$endif}
       begin
          if assigned(p) then
            begin
@@ -939,7 +927,7 @@ uses
       end;
 
 
-    function stringdup(const s : string) : pstring;{$ifdef USEINLINE}inline;{$endif}
+    function stringdup(const s : string) : pshortstring;{$ifdef USEINLINE}inline;{$endif}
       begin
          getmem(result,length(s)+1);
          result^:=s;

+ 5 - 11
compiler/dbgdwarf.pas

@@ -315,17 +315,11 @@ interface
 implementation
 
     uses
-      version,
-      cutils,
-      globtype,
-      globals,
-      verbose,
-      systems,
-      cpubase,
-      cgbase,
+      cutils,cfileutils,
+      version,globtype,globals,verbose,systems,
+      cpubase,cgbase,
       fmodule,
-      defutil,
-      symconst,symtable
+      defutil,symconst,symtable
       ;
 
     const
@@ -2281,7 +2275,7 @@ end;
       var
         currfileinfo,
         lastfileinfo : tfileposinfo;
-        currfuncname : pstring;
+        currfuncname : pshortstring;
         currsectype  : TAsmSectiontype;
         hlabel       : tasmlabel;
         hp : tai;

+ 21 - 16
compiler/dbgstabs.pas

@@ -65,7 +65,7 @@ interface
 implementation
 
     uses
-      strings,cutils,
+      SysUtils,cutils,cfileutils,
       systems,globals,globtype,verbose,
       symconst,defutil,
       cpuinfo,cpubase,cgbase,paramgr,
@@ -132,7 +132,7 @@ implementation
     var i,j:byte;
         varname:string[63];
         varno,varcounter:byte;
-        varvalues:array[0..9] of Pstring;
+        varvalues:array[0..9] of pshortstring;
         {1 kb of parameters is the limit. 256 extra bytes are allocated to
          ensure buffer integrity.}
         varvaluedata:array[0..maxdata+256] of char;
@@ -166,12 +166,12 @@ implementation
                    s[i]:=char(varcounter);
                    inc(i);
                  until s[i]='}';
-                 varvalues[varcounter]:=Pstring(varptr);
+                 varvalues[varcounter]:=pshortstring(varptr);
                  if varptr>@varvaluedata[maxdata] then
                    internalerrorproc(200411152);
-                 Pstring(varptr)^:=get_var_value(varname,get_var_value_arg);
-                 inc(len,length(Pstring(varptr)^));
-                 inc(varptr,length(Pstring(varptr)^)+1);
+                 pshortstring(varptr)^:=get_var_value(varname,get_var_value_arg);
+                 inc(len,length(pshortstring(varptr)^));
+                 inc(varptr,length(pshortstring(varptr)^)+1);
                  inc(varcounter);
                end
              else if s[i+1] in ['1'..'9'] then
@@ -341,7 +341,7 @@ implementation
               end;
             strcopy(state^.stabstring+state^.stabsize,newrec);
             inc(state^.stabsize,strlen(newrec));
-            strdispose(newrec);
+            freemem(newrec);
             {This should be used for case !!}
             inc(state^.recoffset,Tfieldvarsym(p).vardef.size);
           end;
@@ -431,7 +431,7 @@ implementation
                 reallocmem(state^.stabstring,state^.staballoc);
              end;
            strcopy(state^.stabstring+olds,newrec);
-           strdispose(newrec);
+           freemem(newrec);
            {This should be used for case !!
            RecOffset := RecOffset + pd.size;}
          end;
@@ -629,8 +629,9 @@ implementation
                   tostr(def.fileinfo.line)
                   +',');
             strpcopy(strend(p),stabsstr);
-            result:=strnew(p);
-            freemem(p,length(stabsstr)+255);
+            getmem(result,strlen(p)+1);
+            move(p^,result^,strlen(p)+1);
+            freemem(p);
           end;
 
         function recorddef_stabstr(def:trecorddef):pchar;
@@ -783,8 +784,8 @@ implementation
             su:=def_stabstr_evaluate(def,'",${N_LSYM},0,0,0',[]);
             strcopy(strecopy(strend(st),ss),su);
             reallocmem(st,strlen(st)+1);
-            strdispose(ss);
-            strdispose(su);
+            freemem(ss);
+            freemem(su);
             { add to list }
             list.concat(Tai_stab.create(stab_stabs,st));
           end;
@@ -942,7 +943,7 @@ implementation
         templist : TAsmList;
         stabsendlabel : tasmlabel;
         mangled_length : longint;
-        p : pchar;
+        p,p1 : pchar;
         hs : string;
       begin
         if assigned(pd.procstarttai) then
@@ -984,7 +985,9 @@ implementation
                 {$IFDEF POWERPC64}strpcopy(strend(p), '.');{$ENDIF POWERPC64}
                 strpcopy(strend(p),pd.mangledname);
               end;
-            templist.concat(Tai_stab.Create(stab_stabn,strnew(p)));
+            getmem(p1,strlen(p)+1);
+            move(p^,p1^,strlen(p)+1);
+            templist.concat(Tai_stab.Create(stab_stabn,p1));
             strpcopy(p,tostr(N_RBRAC)+',0,0,'+stabsendlabel.name);
             if (tf_use_function_relative_addresses in target_info.flags) then
               begin
@@ -992,7 +995,9 @@ implementation
                 {$IFDEF POWERPC64}strpcopy(strend(p), '.');{$ENDIF POWERPC64}
                 strpcopy(strend(p),pd.mangledname);
               end;
-            templist.concat(Tai_stab.Create(stab_stabn,strnew(p)));
+            getmem(p1,strlen(p)+1);
+            move(p^,p1^,strlen(p)+1);
+            templist.concat(Tai_stab.Create(stab_stabn,p1));
             freemem(p,2*mangled_length+50);
             current_asmdata.asmlists[al_procedures].insertlistafter(pd.procendtai,templist);
 
@@ -1421,7 +1426,7 @@ implementation
       var
         currfileinfo,
         lastfileinfo : tfileposinfo;
-        currfuncname : pstring;
+        currfuncname : pshortstring;
         currsectype  : TAsmSectiontype;
         hlabel       : tasmlabel;
         hp : tai;

+ 1 - 1
compiler/export.pas

@@ -41,7 +41,7 @@ type
    texported_item = class(TLinkedListItem)
       sym : tsym;
       index : longint;
-      name : pstring;
+      name : pshortstring;
       options : word;
       is_var : boolean;
       constructor create;

+ 54 - 66
compiler/finput.pas

@@ -37,7 +37,7 @@ interface
        plongintarr = ^tlongintarr;
 
        tinputfile = class
-         path,name : pstring;       { path and filename }
+         path,name : pshortstring;       { path and filename }
          next      : tinputfile;    { next file for reading }
 
          is_macro,
@@ -144,58 +144,55 @@ interface
           modulename,               { name of the module in uppercase }
           realmodulename,           { name of the module in the orignal case }
           objfilename,              { fullname of the objectfile }
-          newfilename,              { fullname of the assemblerfile }
+          asmfilename,              { fullname of the assemblerfile }
           ppufilename,              { fullname of the ppufile }
           importlibfilename,        { fullname of the import libraryfile }
           staticlibfilename,        { fullname of the static libraryfile }
           sharedlibfilename,        { fullname of the shared libraryfile }
           mapfilename,              { fullname of the mapfile }
           exefilename,              { fullname of the exefile }
-          mainsource   : pstring;   { name of the main sourcefile }
+          mainsource   : pshortstring;   { name of the main sourcefile }
           constructor create(const s:string);
           destructor destroy;override;
           procedure setfilename(const fn:string;allowoutput:boolean);
-          function get_asmfilename : string;
        end;
 
 
+     Function GetNamedFileTime (Const F : String) : Longint;
+
+
 implementation
 
 uses
-{$IFDEF USE_SYSUTILS}
   SysUtils,
-  GlobType,
-{$ELSE USE_SYSUTILS}
-  dos,
-{$ENDIF USE_SYSUTILS}
+  GlobType,Comphook,
 {$ifdef heaptrc}
   fmodule,
   ppheap,
 {$endif heaptrc}
-  globals,systems
+  CFileUtils,
+  Globals,Systems
   ;
 
+
+{****************************************************************************
+                                  Utils
+ ****************************************************************************}
+
+   Function GetNamedFileTime (Const F : String) : Longint;
+     begin
+       GetNamedFileTime:=do_getnamedfiletime(F);
+     end;
+
+
 {****************************************************************************
                                   TINPUTFILE
  ****************************************************************************}
 
     constructor tinputfile.create(const fn:string);
-{$IFDEF USE_SYSUTILS}
-{$ELSE USE_SYSUTILS}
-      var
-        p:dirstr;
-        n:namestr;
-        e:extstr;
-{$ENDIF USE_SYSUTILS}
       begin
-{$IFDEF USE_SYSUTILS}
-        name:=stringdup(SplitFileName(fn));
-        path:=stringdup(SplitPath(fn));
-{$ELSE USE_SYSUTILS}
-        FSplit(fn,p,n,e);
-        name:=stringdup(n+e);
-        path:=stringdup(p);
-{$ENDIF USE_SYSUTILS}
+        name:=stringdup(ExtractFileName(fn));
+        path:=stringdup(ExtractFilePath(fn));
         next:=nil;
         filetime:=-1;
       { file info }
@@ -621,15 +618,13 @@ uses
 
     procedure tmodulebase.setfilename(const fn:string;allowoutput:boolean);
       var
-        p : dirstr;
-        n : NameStr;
-        e : ExtStr;
+        p,n,e,
+        extension,
         prefix,
-        suffix,
-        extension : NameStr;
+        suffix : string;
       begin
          stringdispose(objfilename);
-         stringdispose(newfilename);
+         stringdispose(asmfilename);
          stringdispose(ppufilename);
          stringdispose(importlibfilename);
          stringdispose(staticlibfilename);
@@ -642,28 +637,22 @@ uses
          { Create names }
          paramfn := stringdup(fn);
          paramallowoutput := allowoutput;
-{$IFDEF USE_SYSUTILS}
-         p := SplitPath(fn);
-         n := SplitName(fn);
-         e := SplitExtension(fn);
-{$ELSE USE_SYSUTILS}
-         fsplit(fn,p,n,e);
-{$ENDIF USE_SYSUTILS}
-         n:=FixFileName(n);
+         p := FixPath(ExtractFilePath(fn),false);
+         n := FixFileName(ChangeFileExt(ExtractFileName(fn),''));
+         e := ExtractFileExt(fn);
          { set path }
-         path:=stringdup(FixPath(p,false));
+         path:=stringdup(p);
          { obj,asm,ppu names }
-         p:=path^;
          if AllowOutput then
-          begin
-            if (OutputUnitDir<>'') then
-             p:=OutputUnitDir
-            else
-             if (OutputExeDir<>'') then
-              p:=OutputExeDir;
-          end;
+           begin
+             if (OutputUnitDir<>'') then
+               p:=OutputUnitDir
+             else
+               if (OutputExeDir<>'') then
+                 p:=OutputExeDir;
+           end;
          outputpath:=stringdup(p);
-         newfilename := stringdup(n);
+         asmfilename:=stringdup(p+n+target_info.asmext);
          objfilename:=stringdup(p+n+target_info.objext);
          ppufilename:=stringdup(p+n+target_info.unitext);
          { lib and exe could be loaded with a file specified with -o }
@@ -672,26 +661,30 @@ uses
          extension := target_info.sharedlibext;
 
          if AllowOutput and (compile_level=1) then
-         begin
-           if OutputFile <> '' then n:=OutputFile;
-           if Assigned(OutputPrefix) then prefix := OutputPrefix^;
-           if Assigned(OutputSuffix) then suffix := OutputSuffix^;
-           if OutputExtension <> '' then extension := OutputExtension;
-         end;
+           begin
+             if OutputFileName <> '' then
+               n:=OutputFileName;
+             if Assigned(OutputPrefix) then
+               prefix := OutputPrefix^;
+             if Assigned(OutputSuffix) then
+               suffix := OutputSuffix^;
+             if ExtractFileExt(OutputFileName) <> '' then
+               extension := ExtractFileExt(OutputFileName);
+           end;
 
          importlibfilename:=stringdup(p+target_info.staticClibprefix+'imp'+n+target_info.staticlibext);
          staticlibfilename:=stringdup(p+target_info.staticlibprefix+n+target_info.staticlibext);
 
          { output dir of exe can be specified separatly }
          if AllowOutput and (OutputExeDir<>'') then
-          p:=OutputExeDir
+           p:=OutputExeDir
          else
-          p:=path^;
+           p:=path^;
          sharedlibfilename:=stringdup(p+prefix+n+suffix+extension);
 
          { don't use extension alone to check, it can be empty !! }
-         if (OutputFile<>'') or (OutputExtension<>'') then
-           exefilename:=stringdup(p+n+OutputExtension)
+         if (OutputFileName<>'')then
+           exefilename:=stringdup(p+OutputFileName)
          else
            exefilename:=stringdup(p+n+target_info.exeext);
          mapfilename:=stringdup(p+n+'.map');
@@ -705,7 +698,7 @@ uses
         mainsource:=nil;
         ppufilename:=nil;
         objfilename:=nil;
-        newfilename:=nil;
+        asmfilename:=nil;
         importlibfilename:=nil;
         staticlibfilename:=nil;
         sharedlibfilename:=nil;
@@ -724,18 +717,13 @@ uses
       end;
 
 
-    function tmodulebase.get_asmfilename : string;
-     begin
-         get_asmfilename:=outputpath^+newfilename^+target_info.asmext;
-     end;
-
     destructor tmodulebase.destroy;
       begin
         if assigned(sourcefiles) then
          sourcefiles.free;
         sourcefiles:=nil;
         stringdispose(objfilename);
-        stringdispose(newfilename);
+        stringdispose(asmfilename);
         stringdispose(ppufilename);
         stringdispose(importlibfilename);
         stringdispose(staticlibfilename);

+ 9 - 20
compiler/fmodule.pas

@@ -42,7 +42,7 @@ unit fmodule;
 interface
 
     uses
-       cutils,cclasses,
+       cutils,cclasses,cfileutils,
        globals,finput,ogbase,
        symbase,symsym,aasmbase,aasmtai,aasmdata;
 
@@ -57,7 +57,7 @@ interface
 
       tlinkcontaineritem=class(tlinkedlistitem)
       public
-         data : pstring;
+         data : pshortstring;
          needlink : cardinal;
          constructor Create(const s:string;m:cardinal);
          destructor Destroy;override;
@@ -85,7 +85,7 @@ interface
       tderefmaprec = record
         u           : tmodule;
         { modulename, used during ppu load }
-        modulename  : pstring;
+        modulename  : pshortstring;
       end;
       pderefmap = ^tderefmaprec;
 
@@ -132,7 +132,7 @@ interface
         scanner       : TObject;  { scanner object used }
         procinfo      : TObject;  { current procedure being compiled }
         asmdata       : TObject;  { Assembler data }
-        asmprefix     : pstring;  { prefix for the smartlink asmfiles }
+        asmprefix     : pshortstring;  { prefix for the smartlink asmfiles }
         loaded_from   : tmodule;
         _exports      : tlinkedlist;
         dllscannerinputlist : TFPHashList;
@@ -203,12 +203,8 @@ interface
 implementation
 
     uses
-    {$IFDEF USE_SYSUTILS}
       SysUtils,
       GlobType,
-    {$ELSE USE_SYSUTILS}
-      dos,
-    {$ENDIF USE_SYSUTILS}
       verbose,systems,
       scanner,ppu,
       procinfo;
@@ -378,17 +374,10 @@ implementation
 
     constructor tmodule.create(LoadedFrom:TModule;const s:string;_is_unit:boolean);
       var
-        p : dirstr;
-        n : namestr;
-        e : extstr;
+        p,n : string;
       begin
-    {$IFDEF USE_SYSUTILS}
-        p := SplitPath(s);
-        n := SplitName(s);
-        e := SplitExtension(s);
-    {$ELSE USE_SYSUTILS}
-        FSplit(s,p,n,e);
-    {$ENDIF USE_SYSUTILS}
+        p:=ExtractFilePath(s);
+        n:=ChangeFileExt(ExtractFileName(s),'');
         { Programs have the name 'Program' to don't conflict with dup id's }
         if _is_unit then
          inherited create(n)
@@ -401,7 +390,7 @@ implementation
 {$else}
         asmprefix:=stringdup(FixFileName(n));
 {$endif}
-        setfilename(p+n,true);
+        setfilename(s,true);
         localunitsearchpath:=TSearchPathList.Create;
         localobjectsearchpath:=TSearchPathList.Create;
         localincludesearchpath:=TSearchPathList.Create;
@@ -511,7 +500,7 @@ implementation
         linkothersharedlibs.Free;
         FImportLibraryList.Free;
         stringdispose(objfilename);
-        stringdispose(newfilename);
+        stringdispose(asmfilename);
         stringdispose(ppufilename);
         stringdispose(importlibfilename);
         stringdispose(staticlibfilename);

+ 11 - 9
compiler/fppu.pas

@@ -42,7 +42,7 @@ interface
     type
        tppumodule = class(tmodule)
           ppufile    : tcompilerppufile; { the PPU file }
-          sourcefn   : pstring; { Source specified with "uses .. in '..'" }
+          sourcefn   : pshortstring; { Source specified with "uses .. in '..'" }
           comments   : tstringlist;
 {$ifdef Test_Double_checksum}
           crc_array  : pointer;
@@ -92,6 +92,8 @@ interface
 implementation
 
 uses
+  SysUtils,
+  cfileutils,
   verbose,systems,version,
   symtable, symsym,
   scanner,
@@ -377,17 +379,17 @@ uses
           begin
             { the full filename is specified so we can't use here the
               searchpath (PFV) }
-            Message1(unit_t_unitsearch,AddExtension(sourcefn^,sourceext));
-            fnd:=FindFile(AddExtension(sourcefn^,sourceext),'',hs);
+            Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,sourceext));
+            fnd:=FindFile(ChangeFileExt(sourcefn^,sourceext),'',hs);
             if not fnd then
              begin
-               Message1(unit_t_unitsearch,AddExtension(sourcefn^,pasext));
-               fnd:=FindFile(AddExtension(sourcefn^,pasext),'',hs);
+               Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pasext));
+               fnd:=FindFile(ChangeFileExt(sourcefn^,pasext),'',hs);
              end;
             if not fnd and ((m_mac in current_settings.modeswitches) or (tf_p_ext_support in target_info.flags)) then
              begin
-               Message1(unit_t_unitsearch,AddExtension(sourcefn^,pext));
-               fnd:=FindFile(AddExtension(sourcefn^,pext),'',hs);
+               Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pext));
+               fnd:=FindFile(ChangeFileExt(sourcefn^,pext),'',hs);
              end;
             if fnd then
              begin
@@ -525,7 +527,7 @@ uses
          begin
            s:=p.get(mask);
            if strippath then
-            ppufile.putstring(SplitFileName(s))
+            ppufile.putstring(ExtractFileName(s))
            else
             ppufile.putstring(s);
            ppufile.putlongint(mask);
@@ -743,7 +745,7 @@ uses
               if Source_Time<>-1 then
                 begin
                   if is_main then
-                    main_dir:=splitpath(hs);
+                    main_dir:=ExtractFilePath(hs);
                   temp:=' time '+filetimestring(source_time);
                   if (orgfiletime<>-1) and
                      (source_time<>orgfiletime) then

+ 3 - 2
compiler/gendef.pas

@@ -50,6 +50,7 @@ var
 implementation
 
 uses
+  SysUtils,
   systems,cutils,globtype,globals;
 
 {******************************************************************************
@@ -70,7 +71,7 @@ destructor tdeffile.destroy;
 begin
   if WrittenOnDisk and
      not(cs_link_nolink in current_settings.globalswitches) then
-   RemoveFile(FName);
+    DeleteFile(FName);
   importlist.Free;
   exportlist.Free;
 end;
@@ -114,7 +115,7 @@ begin
   case target_info.system of
     system_i386_Os2, system_i386_emx:
       begin
-        write(t,'NAME '+inputfile);
+        write(t,'NAME '+ChangeFileExt(inputfilename,''));
         if usewindowapi then
           write(t,' WINDOWAPI');
         writeln(t,'');

文件差异内容过多而无法显示
+ 13 - 1029
compiler/globals.pas


+ 4 - 11
compiler/globtype.pas

@@ -28,18 +28,11 @@ interface
        maxidlen = 127;
 
     type
-{TCmdStr is used to pass command line parameters to an external program to be
-executed from the FPC application. In some circomstances, this can be more
-than 255 characters. That's why using Ansi Strings}
-{$IFDEF USE_SYSUTILS}
+       { TCmdStr is used to pass command line parameters to an external program to be
+         executed from the FPC application. In some circomstances, this can be more
+         than 255 characters. That's why using Ansi Strings}
        TCmdStr = AnsiString;
-       PathStr = String;
-       DirStr = String;
-       NameStr = String;
-       ExtStr = String;
-{$ELSE USE_SYSUTILS}
-       TCmdStr = String;
-{$ENDIF USE_SYSUTILS}
+       TPathStr = ShortString;
 
        { Natural integer register type and size for the target machine }
 {$ifdef cpu64bit}

+ 1 - 13
compiler/impdef.pas

@@ -31,11 +31,7 @@ unit impdef;
 interface
 
    uses
-   {$IFDEF USE_SYSUTILS}
-     SysUtils,
-   {$ELSE USE_SYSUTILS}
-     Dos;
-   {$ENDIF USE_SYSUTILS}
+     SysUtils;
 
    var
      as_name,
@@ -174,11 +170,7 @@ procedure CreateTempDir(const s:string);
 procedure call_as(const name:string);
  begin
   FlushOutput;
-{$IFDEF USE_SYSUTILS}
   ExecuteProcess(as_name,'-o '+name+'o '+name);
-{$ELSE USE_SYSUTILS}
-  exec(as_name,'-o '+name+'o '+name);
-{$ENDIF USE_SYSUTILS}
  end;
 procedure call_ar;
  var
@@ -194,11 +186,7 @@ procedure call_ar;
   If DOSError=0 then
    erase(f);
   FlushOutput;
-{$IFDEF USE_SYSUTILS}
   ExecuteProcess(ar_name,'rs '+impname+' '+path+dirsep+'*.swo');
-{$ELSE USE_SYSUTILS}
-  exec(ar_name,'rs '+impname+' '+path+dirsep+'*.swo');
-{$ENDIF USE_SYSUTILS}
   cleardir(path,'*.sw');
   cleardir(path,'*.swo');
   {$i-}

+ 11 - 43
compiler/link.pas

@@ -122,15 +122,10 @@ interface
 Implementation
 
     uses
-    {$IFDEF USE_SYSUTILS}
       SysUtils,
-    {$ELSE USE_SYSUTILS}
-      dos,
-    {$ENDIF USE_SYSUTILS}
-      cutils,
+      cutils,cfileutils,
       script,globals,verbose,comphook,ppu,
       aasmbase,aasmtai,aasmdata,aasmcpu,
-//      symbase,symdef,symtype,symconst,
       owbase,owar,ogmap;
 
     type
@@ -155,7 +150,7 @@ Implementation
          the host. Look for the corresponding assembler file instead,
          because it will be assembled to object file on the target.}
         if isunit and (cs_link_on_target in current_settings.globalswitches) then
-          s:= ForceExtension(s,target_info.asmext);
+          s:=ChangeFileExt(s,target_info.asmext);
 
         { when it does not belong to the unit then check if
           the specified file exists without searching any paths }
@@ -201,7 +196,7 @@ Implementation
 
         {Restore file extension}
         if isunit and (cs_link_on_target in current_settings.globalswitches) then
-          foundfile:= ForceExtension(foundfile,target_info.objext);
+          foundfile:= ChangeFileExt(foundfile,target_info.objext);
 
         findobjectfile:=ScriptFixFileName(foundfile);
       end;
@@ -223,11 +218,7 @@ Implementation
          Found:=librarysearchpath.FindFile(s,founddll);
         if (not found) then
          begin
-           {$IFDEF USE_SYSUTILS}
            sysdir:=FixPath(GetEnvironmentVariable('windir'),false);
-           {$ELSE USE_SYSUTILS}
-           sysdir:=FixPath(GetEnv('windir'),false);
-           {$ENDIF USE_SYSUTILS}
            Found:=FindFile(s,sysdir+';'+sysdir+'system'+source_info.DirSep+';'+sysdir+'system32'+source_info.DirSep,founddll);
          end;
         if (not found) then
@@ -250,8 +241,8 @@ Implementation
         if s='' then
          exit;
         { split path from filename }
-        paths:=SplitPath(s);
-        s:=SplitFileName(s);
+        paths:=ExtractFilePath(s);
+        s:=ExtractFileName(s);
         { add prefix 'lib' }
         if (prefix<>'') and (Copy(s,1,length(prefix))<>prefix) then
          s:=prefix+s;
@@ -550,8 +541,8 @@ Implementation
         FillChar(Info,sizeof(Info),0);
         if cs_link_on_target in current_settings.globalswitches then
           begin
-            Info.ResName:=outputexedir+inputfile+'_link.res';
-            Info.ScriptName:=outputexedir+inputfile+'_script.res';
+            Info.ResName:=outputexedir+ChangeFileExt(inputfilename,'_link.res');
+            Info.ScriptName:=outputexedir+ChangeFileExt(inputfilename,'_script.res');
           end
         else
           begin
@@ -591,10 +582,10 @@ Implementation
         if cs_link_on_target in current_settings.globalswitches then
           begin
             { If linking on target, don't add any path PM }
-            FindUtil:=AddExtension(s,target_info.exeext);
+            FindUtil:=ChangeFileExt(s,target_info.exeext);
             exit;
           end;
-        UtilExe:=AddExtension(s,source_info.exeext);
+        UtilExe:=ChangeFileExt(s,source_info.exeext);
         FoundBin:='';
         Found:=false;
         if utilsdirectory<>'' then
@@ -623,7 +614,6 @@ Implementation
            if useshell then
              exitcode := shell(maybequoted(command)+' '+para)
            else
-      {$IFDEF USE_SYSUTILS}
            try
              if ExecuteProcess(command,para) <> 0
              then begin
@@ -639,28 +629,6 @@ Implementation
              end;
            end
          end;
-      {$ELSE USE_SYSUTILS}
-             begin
-               swapvectors;
-               exec(command,para);
-               swapvectors;
-               exitcode := dosexitcode;
-             end;
-           if (doserror<>0) then
-            begin
-               Message(exec_e_cant_call_linker);
-               current_settings.globalswitches:=current_settings.globalswitches+[cs_link_nolink];
-               DoExec:=false;
-            end
-           else
-            if (exitcode<>0) then
-             begin
-              Message(exec_e_error_while_linking);
-              current_settings.globalswitches:=current_settings.globalswitches+[cs_link_nolink];
-              DoExec:=false;
-             end;
-         end;
-      {$ENDIF USE_SYSUTILS}
       { Update asmres when externmode is set }
         if cs_link_nolink in current_settings.globalswitches then
          begin
@@ -700,7 +668,7 @@ Implementation
       { remove the library, to be sure that it is rewritten }
         RemoveFile(current_module.staticlibfilename^);
       { Call AR }
-        smartpath:=current_module.outputpath^+FixPath(current_module.newfilename^+target_info.smartext,false);
+        smartpath:=current_module.outputpath^+FixPath(ChangeFileExt(current_module.asmfilename^,target_info.smartext),false);
         SplitBinCmd(target_ar.arcmd,binstr,cmdstr);
         binstr := FindUtil(utilsprefix + binstr);
 
@@ -848,7 +816,7 @@ Implementation
       begin
 {$warning TODO Cleanup ignoring of   FPC generated libimp*.a files}
         { Don't load import libraries }
-        if copy(splitfilename(para),1,6)='libimp' then
+        if copy(ExtractFileName(para),1,6)='libimp' then
           exit;
         Comment(V_Tried,'Opening library '+para);
         objreader:=TArObjectreader.create(para);

+ 2 - 2
compiler/m68k/ra68kmot.pas

@@ -79,7 +79,7 @@ unit ra68kmot;
          procedure GetToken;
          function consume(t : tasmtoken):boolean;
          function findopcode(s: string; var opsize: topsize): tasmop;
-         Function BuildExpression(allow_symbol : boolean; asmsym : pstring) : longint;
+         Function BuildExpression(allow_symbol : boolean; asmsym : pshortstring) : longint;
          Procedure BuildConstant(maxvalue: longint);
          Procedure BuildRealConstant(typ : tfloattype);
          Procedure BuildScaling(const oper:tm68koperand);
@@ -577,7 +577,7 @@ const
 
 
 
-    Function tm68kmotreader.BuildExpression(allow_symbol : boolean; asmsym : pstring) : longint;
+    Function tm68kmotreader.BuildExpression(allow_symbol : boolean; asmsym : pshortstring) : longint;
   {*********************************************************************}
   { FUNCTION BuildExpression: longint                                   }
   {  Description: This routine calculates a constant expression to      }

+ 2 - 2
compiler/ncnv.pas

@@ -488,8 +488,8 @@ implementation
                           not(is_char(hdef)) then
                           CGMessage(type_e_typeconflict_in_set)
                         else
-                         for l:=1 to length(pstring(tstringconstnode(p2).value_str)^) do
-                          do_set(ord(pstring(tstringconstnode(p2).value_str)^[l]));
+                         for l:=1 to length(pshortstring(tstringconstnode(p2).value_str)^) do
+                          do_set(ord(pshortstring(tstringconstnode(p2).value_str)^[l]));
                         if hdef=nil then
                          hdef:=cchartype;
                         p2.free;

+ 2 - 2
compiler/nobj.pas

@@ -52,7 +52,7 @@ interface
       pvmtentry = ^tvmtentry;
       tvmtentry = record
          speedvalue   : cardinal;
-         name         : pstring;
+         name         : pshortstring;
          firstprocdef : pprocdefcoll;
          next         : pvmtentry;
       end;
@@ -127,7 +127,7 @@ interface
 implementation
 
     uses
-       strings,
+       SysUtils,
        globals,verbose,systems,
        symtable,symconst,symtype,defcmp,defutil,
        dbgbase

+ 3 - 2
compiler/ogbase.pas

@@ -148,7 +148,7 @@ interface
      private
        FData       : TDynamicArray;
        FSecOptions : TObjSectionOptions;
-       FCachedFullName : pstring;
+       FCachedFullName : pshortstring;
        procedure SetSecOptions(Aoptions:TObjSectionOptions);
      public
        ObjData    : TObjData;
@@ -452,6 +452,7 @@ interface
 implementation
 
     uses
+      SysUtils,
       globals,verbose,fmodule,ogmap;
 
     const
@@ -726,7 +727,7 @@ implementation
     constructor TObjData.create(const n:string);
       begin
         inherited create;
-        FName:=SplitFileName(n);
+        FName:=ExtractFileName(n);
         FObjSectionList:=TFPHashObjectList.Create(true);
         FStabsObjSec:=nil;
         FStabStrObjSec:=nil;

+ 4 - 3
compiler/ogcoff.pas

@@ -277,8 +277,9 @@ implementation
 
     uses
 {$ifdef win32}
-       windows,
+       Windows,
 {$endif win32}
+       SysUtils,
        cutils,verbose,globals,
        fmodule,aasmtai,aasmdata,
        ogmap,
@@ -1224,7 +1225,7 @@ const pemagic : array[0..3] of byte = (
            { The `.file' record, and the file name auxiliary record }
            write_symbol('.file', 0, -2, COFF_SYM_FILE, 1);
            fillchar(filename,sizeof(filename),0);
-           filename:=SplitFileName(current_module.mainsource^);
+           filename:=ExtractFileName(current_module.mainsource^);
            inc(symidx);
            FCoffSyms.write(filename[1],sizeof(filename)-1);
            { Sections }
@@ -2239,7 +2240,7 @@ const pemagic : array[0..3] of byte = (
               exemap.Add('Importing from DLL '+dllname);
             end;
           emptyint:=0;
-          basedllname:=splitfilename(dllname);
+          basedllname:=ExtractFileName(dllname);
           idata2objsection:=internalobjdata.createsection(sec_idata2,basedllname);
           idata2label:=internalobjdata.SymbolDefine('__imp_dir_'+basedllname,AB_LOCAL,AT_DATA);
           idata4objsection:=internalobjdata.createsection(sec_idata4,basedllname);

+ 2 - 2
compiler/ogelf.pas

@@ -101,7 +101,7 @@ interface
 implementation
 
       uses
-        strings,
+        SysUtils,
         verbose,
         cutils,globals,fmodule;
 
@@ -989,7 +989,7 @@ implementation
            shstrtabsect:=TElfObjSection.create_ext(ObjSectionList,'.shstrtab',SHT_STRTAB,0,0,0,1,0);
            { insert the empty and filename as first in strtab }
            strtabsect.writestr(#0);
-           strtabsect.writestr(SplitFileName(current_module.mainsource^)+#0);
+           strtabsect.writestr(ExtractFileName(current_module.mainsource^)+#0);
            { calc amount of sections we have }
            nsections:=1;
            { also create the index in the section header table }

+ 2 - 1
compiler/ogmap.pas

@@ -57,7 +57,8 @@ interface
 implementation
 
     uses
-      cutils,globals,verbose;
+      cutils,cfileutils,
+      globals,verbose;
 
 
 {****************************************************************************

+ 44 - 87
compiler/options.pas

@@ -26,7 +26,8 @@ unit options;
 interface
 
 uses
-  CClasses,globtype,globals,verbose,systems,cpuinfo;
+  CClasses,CFileUtils,
+  globtype,globals,verbose,systems,cpuinfo;
 
 Type
   TOption=class
@@ -69,11 +70,7 @@ implementation
 
 uses
   widestr,
-{$IFDEF USE_SYSUTILS}
   SysUtils,
-{$ELSE USE_SYSUTILS}
-  dos,
-{$ENDIF USE_SYSUTILS}
   version,
   cutils,cmsgs,
   comphook,
@@ -376,9 +373,8 @@ var
   more : string;
   major,minor : longint;
   error : integer;
-  j,l  : longint;
-  d    : DirStr;
-  s    : string;
+  j,l   : longint;
+  d,s   : string;
 begin
   if opt='' then
    exit;
@@ -873,15 +869,10 @@ begin
                if More<>'' then
                  begin
                    DefaultReplacements(More);
-{$IFDEF USE_SYSUTILS}
-                   D:=SplitPath(More);
-                   OutputFile:=SplitFileName(More);
-                   OutputExtension:=SplitExtension(More);
-{$ELSE USE_SYSUTILS}
-                   FSplit(More,D,OutputFile,OutputExtension);
-{$ENDIF USE_SYSUTILS}
+                   D:=ExtractFilePath(More);
                    if (D<>'') then
                      OutputExeDir:=FixPath(D,True);
+                   OutputFileName:=ExtractFileName(More);
                  end
                else
                  IllegalPara(opt);
@@ -1422,20 +1413,16 @@ begin
   If FileLevel>MaxLevel then
    Message(option_too_many_cfg_files);
 { Maybe It's Directory ?}   //Jaro Change:
-  if DirectoryExists(filename) then
+  if PathExists(filename) then
     begin
        Message1(option_config_is_dir,filename);
        exit;
     end;
 { open file }
   Message1(option_using_file,filename);
-{$ifdef USE_SYSUTILS}
   assign(f,ExpandFileName(filename));
-{$else USE_SYSUTILS}
-  assign(f,FExpand(filename));
-{$endif USE_SYsUTILS}
   {$I-}
-  reset(f);
+   reset(f);
   {$I+}
   if ioresult<>0 then
    begin
@@ -1815,19 +1802,16 @@ function check_configfile(const fn:string;var foundfn:string):boolean;
   end;
 
 var
-  configpath : pathstr;
+  hs,
+  configpath : string;
 begin
   foundfn:=fn;
   check_configfile:=true;
   { retrieve configpath }
-{$IFDEF USE_SYSUTILS}
   configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
-{$ELSE USE_SYSUTILS}
-  configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
-{$ENDIF USE_SYSUTILS}
 {$ifdef Unix}
   if configpath='' then
-   configpath:=CleanPath(FixPath(exepath+'../etc/',false));
+   configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
 {$endif}
   {
     Order to read configuration file :
@@ -1839,13 +1823,9 @@ begin
   if not FileExists(fn) then
    begin
 {$ifdef Unix}
-{$IFDEF USE_SYSUTILS}
-     if (GetEnvironmentVariable('HOME')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn) then
-      foundfn:=FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn
-{$ELSE USE_SYSUTILS}
-     if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
-      foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
-{$ENDIF USE_SYSUTILS}
+     hs:=GetEnvironmentVariable('HOME');
+     if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
+      foundfn:=FixPath(hs,false)+'.'+fn
      else
 {$endif}
       if CfgFileExists(configpath+fn) then
@@ -1871,11 +1851,7 @@ begin
   disable_configfile:=false;
 
 { get default messagefile }
-{$IFDEF USE_SYSUTILS}
   msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
-{$ELSE USE_SYSUTILS}
-  msgfilename:=dos.getenv('PPC_ERROR_FILE');
-{$ENDIF USE_SYSUTILS}
 
 { default configfile can be specified on the commandline,
    remove it first }
@@ -2119,25 +2095,20 @@ begin
    end;
 {$ifndef Unix}
   param_file:=FixFileName(param_file);
-{$endif}
-{$IFDEF USE_SYSUTILS}
-  inputdir := SplitPath(param_file);
-  inputfile := SplitName(param_file);
-  inputextension := SplitExtension(param_file);
-{$ELSE USE_SYSUTILS}
-  fsplit(param_file,inputdir,inputfile,inputextension);
-{$ENDIF USE_SYSUTILS}
-  if inputextension='' then
-   begin
-     if FileExists(inputdir+inputfile+sourceext) then
-      inputextension:=sourceext
-     else if FileExists(inputdir+inputfile+pasext) then
-       inputextension:=pasext
-     else if ((m_mac in current_settings.modeswitches) or
+{$endif not unix}
+  inputfilepath:=ExtractFilePath(param_file);
+  inputfilename:=ExtractFileName(param_file);
+  if ExtractFileExt(inputfilename)='' then
+    begin
+      if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
+        inputfilename:=ChangeFileExt(inputfilename,sourceext)
+      else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
+        inputfilename:=ChangeFileExt(inputfilename,pasext)
+      else if ((m_mac in current_settings.modeswitches) or
               (tf_p_ext_support in target_info.flags))
-             and FileExists(inputdir+inputfile+pext) then
-       inputextension:=pext;
-   end;
+             and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
+        inputfilename:=ChangeFileExt(inputfilename,pext);
+    end;
 
   { Check output dir }
   if (OutputExeDir<>'') and
@@ -2154,44 +2125,30 @@ begin
   LibrarySearchPath.AddList(option.ParaLibraryPath,true);
 
   { add unit environment and exepath to the unit search path }
-  if inputdir<>'' then
-   Unitsearchpath.AddPath(inputdir,true);
+  if inputfilepath<>'' then
+   Unitsearchpath.AddPath(inputfilepath,true);
   if not disable_configfile then
-   begin
-{$IFDEF USE_SYSUTILS}
-     UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
-{$ELSE USE_SYSUTILS}
-     UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
-{$ENDIF USE_SYSUTILS}
-   end;
+    UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
 
 {$ifdef Unix}
-{$IFDEF USE_SYSUTILS}
   fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
-{$ELSE USE_SYSUTILS}
-  fpcdir:=FixPath(getenv('FPCDIR'),false);
-{$ENDIF USE_SYSUTILS}
   if fpcdir='' then
-   begin
-     if PathExists('/usr/local/lib/fpc/'+version_string) then
-       fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
-     else
-       fpcdir:='/usr/lib/fpc/'+version_string+'/';
-   end;
-{$else}
-{$IFDEF USE_SYSUTILS}
+    begin
+      if PathExists('/usr/local/lib/fpc/'+version_string) then
+        fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
+      else
+        fpcdir:='/usr/lib/fpc/'+version_string+'/';
+    end;
+{$else unix}
   fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
-{$ELSE USE_SYSUTILS}
-  fpcdir:=FixPath(getenv('FPCDIR'),false);
-{$ENDIF USE_SYSUTILS}
   if fpcdir='' then
-   begin
-     fpcdir:=ExePath+'../';
-     if not(PathExists(fpcdir+'/units')) and
-        not(PathExists(fpcdir+'/rtl')) then
-      fpcdir:=fpcdir+'../';
-   end;
-{$endif}
+    begin
+      fpcdir:=ExePath+'../';
+      if not(PathExists(fpcdir+'/units')) and
+         not(PathExists(fpcdir+'/rtl')) then
+        fpcdir:=fpcdir+'../';
+    end;
+{$endif unix}
   { first try development RTL, else use the default installation path }
   if not disable_configfile then
     begin

+ 8 - 10
compiler/owar.pas

@@ -86,11 +86,11 @@ type
 implementation
 
     uses
+      SysUtils,
       cstreams,
       systems,
       globals,
-      verbose,
-      dos;
+      verbose;
 
     const
       symrelocbufsize = 4096;
@@ -115,7 +115,7 @@ implementation
         D0=1461;
         D1=146097;
         D2=1721119;
-    Function Gregorian2Julian(DT:DateTime):LongInt;
+    Function Gregorian2Julian(DT:TSystemTime):LongInt;
       Var
         Century,XYear,Month : LongInt;
       Begin
@@ -132,9 +132,9 @@ implementation
       End;
 
 
-    function DT2Unix(DT:DateTime):LongInt;
+    function DT2Unix(DT:TSystemTime):LongInt;
       Begin
-        DT2Unix:=(Gregorian2Julian(DT)-C1970)*86400+(LongInt(DT.Hour)*3600)+(DT.Min*60)+DT.Sec;
+        DT2Unix:=(Gregorian2Julian(DT)-C1970)*86400+(LongInt(DT.Hour)*3600)+(DT.Minute*60)+DT.Second;
       end;
 
 
@@ -159,8 +159,7 @@ implementation
 
     constructor tarobjectwriter.create(const Aarfn:string);
       var
-        time  : datetime;
-        dummy : word;
+        time  : TSystemTime;
       begin
         arfn:=Aarfn;
         ardata:=TDynamicArray.Create(arbufsize);
@@ -168,8 +167,7 @@ implementation
         symstr:=TDynamicArray.Create(symstrbufsize);
         lfnstr:=TDynamicArray.Create(lfnstrbufsize);
         { create timestamp }
-        getdate(time.year,time.month,time.day,dummy);
-        gettime(time.hour,time.min,time.sec,dummy);
+        GetLocalTime(time);
         Str(DT2Unix(time),timestamp);
       end;
 
@@ -195,7 +193,7 @@ implementation
         { win32 will change names starting with .\ to ./ when using lfn, corrupting
           the sort order required for the idata sections. To prevent this strip
           always the path from the filename. (PFV) }
-        hfn:=SplitFileName(fn);
+        hfn:=ExtractFileName(fn);
         if hfn='' then
           hfn:=fn;
         fn:=hfn+'/';

+ 2 - 1
compiler/owbase.pas

@@ -76,6 +76,7 @@ type
 implementation
 
 uses
+   SysUtils,
    verbose, globals;
 
 const
@@ -130,7 +131,7 @@ begin
   f.free;
 { Remove if size is 0 }
   if size=0 then
-   RemoveFile(fn);
+   DeleteFile(fn);
   opened:=false;
   fsize:=0;
   fobjsize:=0;

+ 2 - 2
compiler/parser.pas

@@ -105,12 +105,12 @@ implementation
 
          { open assembler response }
          if cs_link_on_target in current_settings.globalswitches then
-           GenerateAsmRes(outputexedir+inputfile+'_ppas')
+           GenerateAsmRes(outputexedir+ChangeFileExt(inputfilename,'_ppas'))
          else
            GenerateAsmRes(outputexedir+'ppas');
 
          { open deffile }
-         DefFile:=TDefFile.Create(outputexedir+inputfile+target_info.defext);
+         DefFile:=TDefFile.Create(outputexedir+ChangeFileExt(inputfilename,target_info.defext));
 
          { list of generated .o files, so the linker can remove them }
          SmartLinkOFiles:=TStringList.Create;

+ 3 - 3
compiler/pdecsub.pas

@@ -62,7 +62,7 @@ interface
 implementation
 
     uses
-       strings,
+       SysUtils,
        { common }
        cutils,cclasses,
        { global }
@@ -1508,7 +1508,7 @@ begin
       if not(token=_SEMICOLON) and not(idtoken=_NAME) then
         begin
           { Always add library prefix and suffix to create an uniform name }
-          hs:=AddExtension(get_stringconst,target_info.sharedlibext);
+          hs:=ChangeFileExt(get_stringconst,target_info.sharedlibext);
           if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
             hs:=target_info.sharedlibprefix+hs;
           import_dll:=stringdup(hs);
@@ -2129,7 +2129,7 @@ const
                           result:=maybe_cprefix(pd.import_name^);
                       end
                     else
-                      result:=splitfilename(pd.import_dll^)+'_index_'+tostr(pd.import_nr);
+                      result:=ExtractFileName(pd.import_dll^)+'_index_'+tostr(pd.import_nr);
                 end;
               end
             else

+ 2 - 1
compiler/pdecvar.pas

@@ -43,6 +43,7 @@ interface
 implementation
 
     uses
+       SysUtils,
        { common }
        cutils,cclasses,
        { global }
@@ -1015,7 +1016,7 @@ implementation
                       if (extern_var) and (idtoken<>_NAME) then
                        begin
                          is_dll:=true;
-                         dll_name:=AddExtension(get_stringconst,target_info.sharedlibext);
+                         dll_name:=ChangeFileExt(get_stringconst,target_info.sharedlibext);
                        end;
                       if try_to_consume(_NAME) then
                         C_name:=get_stringconst

+ 3 - 2
compiler/pmodules.pas

@@ -32,8 +32,9 @@ interface
 implementation
 
     uses
+       SysUtils,
        globtype,version,systems,tokens,
-       cutils,cclasses,comphook,
+       cutils,cfileutils,cclasses,comphook,
        globals,verbose,fmodule,finput,fppu,
        symconst,symbase,symtype,symdef,symsym,symtable,
        aasmtai,aasmdata,aasmcpu,aasmbase,
@@ -850,7 +851,7 @@ implementation
 
              { check for system unit }
              new(s2);
-             s2^:=upper(SplitName(main_file.name^));
+             s2^:=upper(ChangeFileExt(ExtractFileName(main_file.name^),''));
              unitname8:=copy(current_module.modulename^,1,8);
              if (cs_check_unit_name in current_settings.globalswitches) and
                 (

+ 1 - 1
compiler/ptconst.pas

@@ -35,7 +35,7 @@ interface
 implementation
 
     uses
-       strings,
+       SysUtils,
        globtype,systems,tokens,verbose,
        cutils,globals,widestr,scanner,
        symconst,symbase,symdef,symtable,

+ 1 - 1
compiler/rautils.pas

@@ -211,7 +211,7 @@ Function SearchIConstant(const s:string; var l:aint): boolean;
 Implementation
 
 uses
-  strings,
+  SysUtils,
   defutil,systems,verbose,globals,
   symtable,paramgr,
   aasmcpu,

+ 6 - 5
compiler/scandir.pas

@@ -31,7 +31,8 @@ interface
 implementation
 
     uses
-      cutils,
+      SysUtils,
+      cutils,cfileutils,
       globtype,globals,systems,widestr,cpuinfo,
       verbose,comphook,ppu,
       scanner,switches,
@@ -483,7 +484,7 @@ implementation
           end
         else
           s:= trimspace(current_scanner.readcomment);
-        s:=AddExtension(FixFileName(s),target_info.objext);
+        s:=ChangeFileExt(FixFileName(s),target_info.objext);
         current_module.linkotherofiles.add(s,link_always);
       end;
 
@@ -539,7 +540,7 @@ implementation
         linkmode:=lm_shared;
         if linkModeStr='' then
          begin
-           libext:=SplitExtension(libname);
+           libext:=ExtractFileExt(libname);
            if libext=target_info.staticClibext then
              linkMode:=lm_static;
          end
@@ -915,9 +916,9 @@ implementation
           if Assigned(Current_Module) then
             begin
               delete(S,1,1);
-              insert(SplitName(current_module.mainsource^),S,1);
+              insert(ExtractFileName(current_module.mainsource^),S,1);
             end;
-        s:=AddExtension(FixFileName(s),target_info.resext);
+        s:=ChangeFileExt(FixFileName(s),target_info.resext);
         if target_info.res<>res_none then
           begin
           current_module.flags:=current_module.flags or uf_has_resourcefiles;

+ 23 - 23
compiler/scanner.pas

@@ -205,8 +205,8 @@ interface
 implementation
 
     uses
-      dos,
-      cutils,
+      SysUtils,
+      cutils,cfileutils,
       systems,
       switches,
       symbase,symtable,symtype,symsym,symconst,symdef,defutil,
@@ -517,7 +517,9 @@ implementation
         if c <> '''' then
           Message2(scan_f_syn_expected, '''', c);
         s := current_scanner.readquotedstring;
-        outputextension := '.'+s;
+        if OutputFileName='' then
+          OutputFileName:=InputFileName;
+        OutputFileName:=ChangeFileExt(OutputFileName,'.'+s);
         with current_module do
           setfilename(paramfn^, paramallowoutput);
       end;
@@ -1454,13 +1456,12 @@ In case not, the value returned can be arbitrary.
 
     procedure dir_include;
 
-        function findincludefile(const path,name,ext:string;var foundfile:string):boolean;
+        function findincludefile(const path,name:string;var foundfile:string):boolean;
         var
           found  : boolean;
           hpath  : string;
-
         begin
-         (* look for the include file
+          (* look for the include file
            If path was specified as part of {$I } then
             1. specified path (expanded with path of inputfile if relative)
            else
@@ -1476,28 +1477,26 @@ In case not, the value returned can be arbitrary.
                  hpath:=current_scanner.inputfile.path^+path
                else
                  hpath:=path;
-               found:=FindFile(name+ext, hpath,foundfile);
+               found:=FindFile(name, hpath,foundfile);
              end
            else
              begin
                hpath:=current_scanner.inputfile.path^+';'+CurDirRelPath(source_info);
-               found:=FindFile(name+ext, hpath,foundfile);
+               found:=FindFile(name, hpath,foundfile);
                if not found then
-                 found:=current_module.localincludesearchpath.FindFile(name+ext,foundfile);
+                 found:=current_module.localincludesearchpath.FindFile(name,foundfile);
                if not found  then
-                 found:=includesearchpath.FindFile(name+ext,foundfile);
+                 found:=includesearchpath.FindFile(name,foundfile);
              end;
-           findincludefile:=found;
+           result:=found;
         end;
 
-
       var
+        path,
+        name,
         args,
         foundfile,
-        hs    : string;
-        path  : dirstr;
-        name  : namestr;
-        ext   : extstr;
+        hs    : tpathstr;
         hp    : tinputfile;
         found : boolean;
       begin
@@ -1544,7 +1543,7 @@ In case not, the value returned can be arbitrary.
             if hs='FPCTARGETOS' then
              hs:=target_info.shortname
            else
-             hs:=getenv(hs);
+             hs:=GetEnvironmentVariable(hs);
            if hs='' then
             Message1(scan_w_include_env_not_found,path);
            { make it a stringconst }
@@ -1555,18 +1554,19 @@ In case not, the value returned can be arbitrary.
         else
          begin
            hs:=FixFileName(hs);
-           fsplit(hs,path,name,ext);
+           path:=ExtractFilePath(hs);
+           name:=ExtractFileName(hs);
            { try to find the file }
-           found:=findincludefile(path,name,ext,foundfile);
-           if (ext='') then
+           found:=findincludefile(path,name,foundfile);
+           if (ExtractFileExt(name)='') then
             begin
               { try default extensions .inc , .pp and .pas }
               if (not found) then
-               found:=findincludefile(path,name,'.inc',foundfile);
+               found:=findincludefile(path,ChangeFileExt(name,'.inc'),foundfile);
               if (not found) then
-               found:=findincludefile(path,name,sourceext,foundfile);
+               found:=findincludefile(path,ChangeFileExt(name,sourceext),foundfile);
               if (not found) then
-               found:=findincludefile(path,name,pasext,foundfile);
+               found:=findincludefile(path,ChangeFileExt(name,pasext),foundfile);
             end;
            if current_scanner.inputfilecount<max_include_nesting then
              begin

+ 4 - 3
compiler/script.pas

@@ -104,7 +104,8 @@ uses
 {$ifdef hasUnix}
   BaseUnix,
 {$endif}
-  cutils,
+  SysUtils,
+  cutils,cfileutils,
   globtype,globals,systems,verbose;
 
 
@@ -136,9 +137,9 @@ constructor TScript.CreateExec(const s:string);
 begin
   fn:=FixFileName(s);
   if cs_link_on_target in current_settings.globalswitches then
-    fn:=AddExtension(fn,target_info.scriptext)
+    fn:=ChangeFileExt(fn,target_info.scriptext)
   else
-    fn:=AddExtension(fn,source_info.scriptext);
+    fn:=ChangeFileExt(fn,source_info.scriptext);
   executable:=true;
   data:=TStringList.Create;
 end;

+ 2 - 2
compiler/symbase.pas

@@ -92,8 +92,8 @@ interface
           procedure dumpsym(p : TNamedIndexItem;arg:pointer);
 {$endif EXTDEBUG}
        public
-          name      : pstring;
-          realname  : pstring;
+          name      : pshortstring;
+          realname  : pshortstring;
           symindex,
           defindex  : TIndexArray;
           symsearch : Tdictionary;

+ 10 - 9
compiler/symdef.pas

@@ -26,7 +26,7 @@ interface
 
     uses
        { common }
-       cutils,cclasses,
+       cclasses,
        { global }
        globtype,globals,tokens,
        { symtable }
@@ -135,7 +135,7 @@ interface
        end;
 
        tforwarddef = class(tstoreddef)
-          tosymname : pstring;
+          tosymname : pshortstring;
           forwardpos : tfileposinfo;
           constructor create(const s:string;const pos : tfileposinfo);
           destructor destroy;override;
@@ -239,7 +239,7 @@ interface
           childof  : tobjectdef;
           childofderef  : tderef;
           objname,
-          objrealname   : pstring;
+          objrealname   : pshortstring;
           objectoptions : tobjectoptions;
           { to be able to have a variable vmt position }
           { and no vmt field for objects without virtuals }
@@ -247,7 +247,7 @@ interface
           writing_class_record_dbginfo : boolean;
           objecttype : tobjectdeftype;
           iidguid: pguid;
-          iidstr: pstring;
+          iidstr: pshortstring;
           iitype: tinterfaceentrytype;
           iioffset: longint;
           lastvtableindex: longint;
@@ -448,7 +448,7 @@ interface
 
        tmessageinf = record
          case integer of
-           0 : (str : pstring);
+           0 : (str : pshortstring);
            1 : (i : longint);
        end;
 
@@ -476,7 +476,7 @@ interface
 
        tprocdef = class(tabstractprocdef)
        private
-          _mangledname : pstring;
+          _mangledname : pshortstring;
        public
           extnumber      : word;
           messageinf : tmessageinf;
@@ -520,7 +520,7 @@ interface
           hasforward : boolean;
           { import info }
           import_dll,
-          import_name : pstring;
+          import_name : pshortstring;
           import_nr   : word;
           { info for inlining the subroutine, if this pointer is nil,
             the procedure can't be inlined }
@@ -760,7 +760,8 @@ interface
 implementation
 
     uses
-      strings,
+      SysUtils,
+      cutils,
       { global }
       verbose,
       { target }
@@ -5203,7 +5204,7 @@ implementation
     type
       tnamemap = class(TNamedIndexItem)
         listnext : TNamedIndexItem;
-        newname: pstring;
+        newname: pshortstring;
         constructor create(const aname, anewname: string);
         destructor  destroy; override;
       end;

+ 4 - 4
compiler/symsym.pas

@@ -200,7 +200,7 @@ interface
 
       tglobalvarsym = class(tabstractnormalvarsym)
       private
-          _mangledname : pstring;
+          _mangledname : pshortstring;
       public
           constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
           constructor create_dll(const n : string;vsp:tvarspez;def:tdef);
@@ -218,7 +218,7 @@ interface
 {$ifdef i386}
          absseg  : boolean;
 {$endif i386}
-         asmname : pstring;
+         asmname : pshortstring;
          addroffset : aint;
          ref     : tpropaccesslist;
          constructor create(const n : string;def:tdef);
@@ -256,7 +256,7 @@ interface
 
        ttypedconstsym = class(tstoredsym)
        private
-          _mangledname : pstring;
+          _mangledname : pshortstring;
        public
           typedconstdef  : tdef;
           typedconstdefderef : tderef;
@@ -347,7 +347,7 @@ interface
        { compiler generated symbol to point to rtti and init/finalize tables }
        trttisym = class(tstoredsym)
        private
-          _mangledname : pstring;
+          _mangledname : pshortstring;
        public
           lab     : tasmsymbol;
           rttityp : trttitype;

+ 1 - 1
compiler/symtable.pas

@@ -252,7 +252,7 @@ interface
     type
        punit_alias = ^tunit_alias;
        tunit_alias = object(TNamedIndexItem)
-          newname : pstring;
+          newname : pshortstring;
           constructor init(const n:string);
           destructor  done;virtual;
        end;

+ 1 - 1
compiler/symtype.pas

@@ -104,7 +104,7 @@ interface
       tsym = class(tsymentry)
       protected
       public
-         _realname  : pstring;
+         _realname  : pshortstring;
          fileinfo   : tfileposinfo;
          symoptions : tsymoptions;
          refs          : longint;

+ 3 - 3
compiler/systems/t_beos.pas

@@ -56,8 +56,8 @@ interface
 implementation
 
   uses
-    dos,
-    cutils,cclasses,
+    SysUtils,
+    cutils,cfileutils,cclasses,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,i_beos,ogbase;
@@ -172,7 +172,7 @@ var
   i : integer;
 begin
   Inherited Create;
-  s:=GetEnv('BELIBRARIES');
+  s:=GetEnvironmentVariable('BELIBRARIES');
   { convert to correct format in case under unix system }
   for i:=1 to length(s) do
     if s[i] = ':' then

+ 13 - 21
compiler/systems/t_bsd.pas

@@ -31,12 +31,8 @@ interface
 implementation
 
   uses
-    cutils,cclasses,
-{$ifdef USE_SYSUTILS}
     sysutils,
-{$else USE_SYSUTILS}
-    dos,
-{$endif USE_SYSUTILS}
+    cutils,cfileutils,cclasses,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,
@@ -253,19 +249,19 @@ begin
 end;
 
 procedure TLinkerBSD.LoadPredefinedLibraryOrder;
-// put your linkorder/linkalias overrides here. 
+// put your linkorder/linkalias overrides here.
 // Note: assumes only called when reordering/aliasing is used.
 Begin
   if not(target_info.system in [system_powerpc_darwin,system_i386_darwin]) then
     begin
-      if (target_info.system =system_i386_freebsd) and 
-             not (cs_link_no_default_lib_order in  current_settings.globalswitches) Then   
+      if (target_info.system =system_i386_freebsd) and
+         not (cs_link_no_default_lib_order in  current_settings.globalswitches) Then
         Begin
-          LinkLibraryOrder.add('gcc','',15);		
-          LinkLibraryOrder.add('c','',50);		     // c and c_p mutual. excl?	
-          LinkLibraryOrder.add('c_p','',55);			
+          LinkLibraryOrder.add('gcc','',15);
+          LinkLibraryOrder.add('c','',50);		     // c and c_p mutual. excl?
+          LinkLibraryOrder.add('c_p','',55);
           LinkLibraryOrder.add('pthread','',75);	     // pthread and c_r should be mutually exclusive
-          LinkLibraryOrder.add('c_r','',76);		 		
+          LinkLibraryOrder.add('c_r','',76);
           LinkLibraryOrder.add('kvm','',80);		     // must be before ncurses
           if (cs_link_pthread in current_settings.globalswitches) Then     // convert libpthread to libc_r.
             LinkLibraryAliases.add('pthread','c_r');
@@ -273,7 +269,7 @@ Begin
     end
 else
     begin
-          LinkLibraryOrder.add('gcc','',15);		
+          LinkLibraryOrder.add('gcc','',15);
           LinkLibraryOrder.add('c','',50);
    end;
 End;
@@ -292,7 +288,7 @@ Var
   Fl1,Fl2      : Boolean;
   IsDarwin     : Boolean;
   ReOrder      : Boolean;
-  
+
 begin
   WriteResponseFile:=False;
   ReOrder:=False;
@@ -309,7 +305,7 @@ begin
       // Only reorder for now if -XL or -XO params are given
       // or when -Xf.
       reorder:= linklibc and
-                ( 
+                (
                   ReorderEntries
                    or
                   (cs_link_pthread in current_settings.globalswitches));
@@ -325,7 +321,7 @@ begin
          if linklibc then
           prtobj:=cprtobj;
        end;
-      // after this point addition of shared libs not allowed.  
+      // after this point addition of shared libs not allowed.
     end
   else
     begin
@@ -576,18 +572,14 @@ begin
 
   InitStr:='-init FPC_LIB_START';
   FiniStr:='-fini FPC_LIB_EXIT';
-  SoNameStr:='-soname '+SplitFileName(current_module.sharedlibfilename^);
+  SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename^);
 
 { Call linker }
   SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
 {$ifndef darwin}
   Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
 {$else darwin}
-{$ifdef USE_SYSUTILS}
   Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename^)));
-{$else USE_SYSUTILS}
-  Replace(cmdstr,'$EXE',maybequoted(FExpand(current_module.sharedlibfilename^)));
-{$endif USE_SYSUTILS}
 {$endif darwin}
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));

+ 30 - 15
compiler/systems/t_emx.pas

@@ -37,9 +37,8 @@ interface
 implementation
 
   uses
-     strings,
-     dos,
-     cutils,cclasses,
+     sysutils,
+     cutils,cfileutils,cclasses,
      globtype,comphook,systems,symconst,symsym,symdef,
      globals,verbose,fmodule,script,ogbase,
      import,link,i_emx,ppu;
@@ -131,21 +130,40 @@ var aout_str_size:longint;
 
     out_file:file;
 
+
+procedure PackTime (var T: TSystemTime; var P: longint);
+
+var zs:longint;
+
+begin
+    p:=-1980;
+    p:=p+t.year and 127;
+    p:=p shl 4;
+    p:=p+t.month;
+    p:=p shl 5;
+    p:=p+t.day;
+    p:=p shl 16;
+    zs:=t.hour;
+    zs:=zs shl 6;
+    zs:=zs+t.minute;
+    zs:=zs shl 5;
+    zs:=zs+t.second div 2;
+    p:=p+(zs and $ffff);
+end;
+
+
 procedure write_ar(const name:string;size:longint);
 
-var ar:ar_hdr;
-    time:datetime;
+var ar:ar_hdr;        {PackTime is platform independent}
+    time:TSystemTime;
     dummy:word;
     numtime:longint;
     tmp:string[19];
-
-
 begin
     ar_member_size:=size;
     fillchar(ar.ar_name,sizeof(ar.ar_name),' ');
     move(name[1],ar.ar_name,length(name));
-    getdate(time.year,time.month,time.day,dummy);
-    gettime(time.hour,time.min,time.sec,dummy);
+    GetLocalTime(time);
     packtime(time,numtime);
     str(numtime,tmp);
     fillchar(ar.ar_date,sizeof(ar.ar_date),' ');
@@ -438,17 +456,14 @@ var
   AppTypeStr,
   StripStr: string[40];
   RsrcStr : string;
-  DS: DirStr;
-  NS: NameStr;
-  ES: ExtStr;
-  OutName: PathStr;
+  DS,NS,ES : string;
+  OutName: string;
 begin
   if not(cs_link_nolink in current_settings.globalswitches) then
    Message1(exec_i_linking,current_module.exefilename^);
 
 { Create some replacements }
-  FSplit (current_module.exefilename^, DS, NS, ES);
-  OutName := DS + NS + '.out';
+  OutName := ChangeFileExt(current_module.exefilename^,'.out');
   if (cs_link_strip in current_settings.globalswitches) then
    StripStr := '-s'
   else

+ 5 - 3
compiler/systems/t_go32v2.pas

@@ -30,9 +30,11 @@ interface
 implementation
 
     uses
-       link,
-       cutils,cclasses,
-       globtype,globals,systems,verbose,script,fmodule,i_go32v2,ogcoff;
+       SysUtils,
+       cutils,cfileutils,cclasses,
+       globtype,globals,systems,verbose,script,
+       fmodule,i_go32v2,
+       link,ogcoff;
 
     type
       TInternalLinkerGo32v2=class(TInternallinker)

+ 11 - 10
compiler/systems/t_linux.pas

@@ -59,10 +59,11 @@ interface
 implementation
 
   uses
-    cutils,cclasses,
+    SysUtils,
+    cutils,cfileutils,cclasses,
     verbose,systems,globtype,globals,
     symconst,script,
-    fmodule,dos,
+    fmodule,
     aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,
     cgbase,cgobj,cgutils,ogbase,
     i_linux
@@ -303,10 +304,10 @@ Begin
    if not (cs_link_no_default_lib_order in  current_settings.globalswitches) Then
         Begin
           LinkLibraryOrder.add('gcc','',15);
-          LinkLibraryOrder.add('c','',100);                 
+          LinkLibraryOrder.add('c','',100);
           LinkLibraryOrder.add('gmon','',120);
-          LinkLibraryOrder.add('dl','',140);             
-          LinkLibraryOrder.add('pthread','',160);             
+          LinkLibraryOrder.add('dl','',140);
+          LinkLibraryOrder.add('pthread','',160);
          end;
 End;
 
@@ -422,13 +423,13 @@ begin
       if reorder Then
         ExpandAndApplyOrder(SharedLibFiles);
       // after this point addition of shared libs not allowed.
-      
+
       { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
         here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
-          
+
       if not SharedLibFiles.Empty then
        begin
-                      
+
          Add('INPUT(');
          While not SharedLibFiles.Empty do
           begin
@@ -605,7 +606,7 @@ begin
   if (cs_link_strip in current_settings.globalswitches) then
    StripStr:='-s';
   if (cs_link_map in current_settings.globalswitches) then
-   StripStr:='-Map '+maybequoted(ForceExtension(current_module.exefilename^,'.map'));
+   StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename^,'.map'));
   if use_smartlink_section then
    GCSectionsStr:='--gc-sections';
   If (cs_profile in current_settings.moduleswitches) or
@@ -668,7 +669,7 @@ begin
  { Create some replacements }
   InitStr:='-init FPC_LIB_START';
   FiniStr:='-fini FPC_LIB_EXIT';
-  SoNameStr:='-soname '+SplitFileName(current_module.sharedlibfilename^);
+  SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename^);
 
 { Call linker }
   SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);

+ 3 - 2
compiler/systems/t_nwl.pas

@@ -98,7 +98,8 @@ implementation
 {$endif}
 
   uses
-    cutils,
+    SysUtils,
+    cutils,cfileutils,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,
@@ -549,7 +550,7 @@ begin
 
 { if we have a xdc file, dont touch it, otherwise create a new
   one and remove it after nlmconv }
-  xdcname := ForceExtension(current_module.exefilename^,'.xdc');
+  xdcname := ChangeFileExt(current_module.exefilename^,'.xdc');
   xdcpresent := FileExists (xdcname);
   if not xdcpresent then
   begin

+ 1 - 1
compiler/systems/t_nwm.pas

@@ -92,7 +92,7 @@ interface
 implementation
 
   uses
-    cutils,
+    cutils,cfileutils,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,

+ 27 - 13
compiler/systems/t_os2.pas

@@ -37,9 +37,8 @@ interface
 implementation
 
   uses
-     strings,
-     dos,
-     cutils,cclasses,
+     SysUtils,
+     cutils,cfileutils,cclasses,
      globtype,systems,symconst,symdef,
      globals,verbose,fmodule,script,
      import,link,i_os2,ogbase;
@@ -130,11 +129,31 @@ var aout_str_size:longint;
 
     out_file:file;
 
+procedure PackTime (var T: TSystemTime; var P: longint);
+
+var zs:longint;
+
+begin
+    p:=-1980;
+    p:=p+t.year and 127;
+    p:=p shl 4;
+    p:=p+t.month;
+    p:=p shl 5;
+    p:=p+t.day;
+    p:=p shl 16;
+    zs:=t.hour;
+    zs:=zs shl 6;
+    zs:=zs+t.minute;
+    zs:=zs shl 5;
+    zs:=zs+t.second div 2;
+    p:=p+(zs and $ffff);
+end;
+
+
 procedure write_ar(const name:string;size:longint);
 
 var ar:ar_hdr;
-    time:datetime;
-    dummy:word;
+    time:TSystemTime;
     numtime:longint;
     tmp:string[19];
 
@@ -143,8 +162,7 @@ begin
     ar_member_size:=size;
     fillchar(ar.ar_name,sizeof(ar.ar_name),' ');
     move(name[1],ar.ar_name,length(name));
-    getdate(time.year,time.month,time.day,dummy);
-    gettime(time.hour,time.min,time.sec,dummy);
+    GetLocalTime(time);
     packtime(time,numtime);
     str(numtime,tmp);
     fillchar(ar.ar_date,sizeof(ar.ar_date),' ');
@@ -437,17 +455,13 @@ var
   AppTypeStr,
   StripStr: string[40];
   RsrcStr : string;
-  DS: DirStr;
-  NS: NameStr;
-  ES: ExtStr;
-  OutName: PathStr;
+  OutName: TPathStr;
 begin
   if not(cs_link_nolink in current_settings.globalswitches) then
    Message1(exec_i_linking,current_module.exefilename^);
 
 { Create some replacements }
-  FSplit (current_module.exefilename^, DS, NS, ES);
-  OutName := DS + NS + '.out';
+  OutName := ChangeFileExt(current_module.exefilename^,'.out');
   if (cs_link_strip in current_settings.globalswitches) then
    StripStr := '-s'
   else

+ 2 - 1
compiler/systems/t_sunos.pas

@@ -34,7 +34,8 @@ interface
 implementation
 
   uses
-    cutils,cclasses,
+    sysutils,
+    cutils,cfileutils,cclasses,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,

+ 2 - 1
compiler/systems/t_watcom.pas

@@ -31,7 +31,8 @@ implementation
 
     uses
        link,
-       cclasses,cutils,strings,globtype,globals,
+       SysUtils,
+       cclasses,cutils,cfileutils,globtype,globals,
        systems,verbose,script,fmodule,i_watcom;
 
 

+ 8 - 6
compiler/systems/t_win.pas

@@ -24,8 +24,8 @@ unit t_win;
 {$i fpcdefs.inc}
 
 interface
+
     uses
-       dos,
        cutils,cclasses,
        aasmbase,aasmtai,aasmdata,aasmcpu,fmodule,globtype,globals,systems,verbose,
        symconst,symdef,symsym,
@@ -89,6 +89,8 @@ interface
 implementation
 
   uses
+    SysUtils,
+    cfileutils,
     cpuinfo,cgutils,dbgbase,
     owar,ogbase,ogcoff;
 
@@ -165,7 +167,7 @@ implementation
           idata4objsection:=objdata.createsection(sec_idata4,'');
           idata5objsection:=objdata.createsection(sec_idata5,'');
           emptyint:=0;
-          basedllname:=splitfilename(dllname);
+          basedllname:=ExtractFileName(dllname);
           { idata4 }
           objdata.SetSection(idata4objsection);
           idata4label:=objdata.SymbolDefine(asmprefix+'_names_'+basedllname,AB_GLOBAL,AT_DATA);
@@ -456,7 +458,7 @@ implementation
                     if ImportSymbol.Name <> '' then
                       current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(ImportSymbol.Name,AT_FUNCTION,0))
                     else
-                      current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(splitfilename(ImportLibrary.Name)+'_index_'+tostr(ImportSymbol.ordnr),AT_FUNCTION,0));
+                      current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(ExtractFileName(ImportLibrary.Name)+'_index_'+tostr(ImportSymbol.ordnr),AT_FUNCTION,0));
                     current_asmdata.asmlists[al_imports].concat(tai_function_name.create(''));
                   {$ifdef ARM}
                     reference_reset_symbol(href,l5,0);
@@ -1281,7 +1283,7 @@ implementation
         if (cs_link_strip in current_settings.globalswitches) then
           StripStr:='-s';
         if (cs_link_map in current_settings.globalswitches) then
-          MapStr:='-Map '+maybequoted(ForceExtension(current_module.exefilename^,'.map'));
+          MapStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename^,'.map'));
 
       { Write used files and libraries }
         WriteResponseFile(false);
@@ -1383,7 +1385,7 @@ implementation
         if (cs_link_strip in current_settings.globalswitches) then
           StripStr:='-s';
         if (cs_link_map in current_settings.globalswitches) then
-          MapStr:='-Map '+maybequoted(ForceExtension(current_module.exefilename^,'.map'));
+          MapStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename^,'.map'));
 
       { Write used files and libraries }
         WriteResponseFile(true);
@@ -1650,7 +1652,7 @@ implementation
         if FindLibraryFile(binname,target_info.staticClibprefix,target_info.staticClibext,hs) then
           exit;
         { check if we can find the dll }
-        hs:=AddExtension(binname,target_info.sharedlibext);
+        hs:=ChangeFileExt(binname,target_info.sharedlibext);
         if not FindDll(hs,dllname) then
           exit;
         importfound:=false;

+ 8 - 8
compiler/utils/fixtab.pp

@@ -87,12 +87,12 @@ end;
 
 
 
-Function AddExtension(Const HStr,ext:String):String;
+Function ChangeFileExt(Const HStr,ext:String):String;
 begin
   if (Ext<>'') and (SplitExtension(HStr)='') then
-   AddExtension:=Hstr+'.'+Ext
+   ChangeFileExt:=Hstr+'.'+Ext
   else
-   AddExtension:=Hstr;
+   ChangeFileExt:=Hstr;
 end;
 
 
@@ -185,13 +185,13 @@ var
 begin
 {Create New FileName}
   if SplitExtension(nfn)='*' then
-   nfn:=AddExtension(SplitPath(nfn)+SplitName(nfn),SplitExtension(fn));
+   nfn:=ChangeFileExt(SplitPath(nfn)+SplitName(nfn),SplitExtension(fn));
   if SplitName(nfn)='*' then
    begin
      if SplitPath(nfn)='' then
-      nfn:=AddExtension(SplitPath(fn)+SplitName(fn),SplitExtension(nfn))
+      nfn:=ChangeFileExt(SplitPath(fn)+SplitName(fn),SplitExtension(nfn))
      else
-      nfn:=AddExtension(SplitPath(nfn)+SplitName(fn),SplitExtension(nfn));
+      nfn:=ChangeFileExt(SplitPath(nfn)+SplitName(fn),SplitExtension(nfn));
    end;
 {Done?}
   if FileDone(nfn) then
@@ -320,7 +320,7 @@ begin
         ch:=para[2];
         delete(para,1,2);
         case ch of
-         'O' : OutFile:=AddExtension(Para,OutputExt);
+         'O' : OutFile:=ChangeFileExt(Para,OutputExt);
          'D' : DosEol:=true;
          'T' : Val(Para,TabSize,j);
          'V' : verbose:=true;
@@ -356,7 +356,7 @@ begin
    end;
   for i:=ParaFile to ParamCount do
    begin
-     InFile:=AddExtension(ParamStr(i),InputExt);
+     InFile:=ChangeFileExt(ParamStr(i),InputExt);
      FindFirst(InFile,$20,Dir);
      while (DosError=0) do
       begin

+ 4 - 4
compiler/utils/ppufiles.pp

@@ -62,7 +62,7 @@ begin
 end;
 
 
-Function AddExtension(Const HStr,ext:String):String;
+Function ChangeFileExt(Const HStr,ext:String):String;
 {
   Return a filename which will have extension ext added if no
   extension is found
@@ -74,9 +74,9 @@ begin
   while (j>0) and (Hstr[j]<>'.') do
    dec(j);
   if j=0 then
-   AddExtension:=Hstr+'.'+Ext
+   ChangeFileExt:=Hstr+'.'+Ext
   else
-   AddExtension:=HStr;
+   ChangeFileExt:=HStr;
 end;
 
 
@@ -224,7 +224,7 @@ begin
   parafile:=i;
   for i:=parafile to ParamCount do
    begin
-     InFile:=AddExtension(ParamStr(i),PPUExt);
+     InFile:=ChangeFileExt(ParamStr(i),PPUExt);
      FindFirst(InFile,$20,Dir);
      while (DosError=0) do
       begin

+ 4 - 4
compiler/utils/ppumove.pp

@@ -147,7 +147,7 @@ begin
 end;
 
 
-Function AddExtension(Const HStr,ext:String):String;
+Function ChangeFileExt(Const HStr,ext:String):String;
 {
   Return a filename which will have extension ext added if no
   extension is found
@@ -159,9 +159,9 @@ begin
   while (j>0) and (Hstr[j]<>'.') do
    dec(j);
   if j=0 then
-   AddExtension:=Hstr+'.'+Ext
+   ChangeFileExt:=Hstr+'.'+Ext
   else
-   AddExtension:=HStr;
+   ChangeFileExt:=HStr;
 end;
 
 
@@ -635,7 +635,7 @@ begin
    end;
 { Process Files }
   i:=OptInd;
-  While (i<=ParamCount) and Dofile(AddExtension(Paramstr(i),PPUExt)) do
+  While (i<=ParamCount) and Dofile(ChangeFileExt(Paramstr(i),PPUExt)) do
    Inc(i);
 { Do Linking stage }
   DoLink;

+ 7 - 7
compiler/x86/agx86int.pas

@@ -49,6 +49,7 @@ interface
 implementation
 
     uses
+      SysUtils,
       cutils,globtype,globals,systems,cclasses,
       verbose,finput,fmodule,script,cpuinfo,
       itx86int,
@@ -845,23 +846,22 @@ implementation
 
 
     function tx86intelassembler.DoAssemble : boolean;
-    var f : file;
+    var
+      masmobjfn : string;
     begin
       DoAssemble:=Inherited DoAssemble;
       { masm does not seem to recognize specific extensions and uses .obj allways PM }
       if (target_asm.id in [as_i386_masm,as_i386_wasm]) then
         begin
+          masmobjfn:=ChangeFileExt(objfilename,'.obj');
           if not(cs_asm_extern in current_settings.globalswitches) then
             begin
               if Not FileExists(objfilename) and
-                 FileExists(ForceExtension(objfilename,'.obj')) then
-                begin
-                  Assign(F,ForceExtension(objfilename,'.obj'));
-                  Rename(F,objfilename);
-                end;
+                 FileExists(masmobjfn) then
+                RenameFile(masmobjfn,objfilename);
             end
           else
-            AsmRes.AddAsmCommand('mv',ForceExtension(objfilename,'.obj')+' '+objfilename,objfilename);
+            AsmRes.AddAsmCommand('mv',masmobjfn+' '+objfilename,objfilename);
         end;
     end;
 

部分文件因为文件数量过多而无法显示