瀏覽代碼

* 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/catch.pas svneol=native#text/plain
 compiler/cclasses.pas svneol=native#text/plain
 compiler/cclasses.pas svneol=native#text/plain
 compiler/cfidwarf.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/cg64f32.pas svneol=native#text/plain
 compiler/cgbase.pas svneol=native#text/plain
 compiler/cgbase.pas svneol=native#text/plain
 compiler/cgobj.pas svneol=native#text/plain
 compiler/cgobj.pas svneol=native#text/plain

+ 1 - 1
compiler/aasmbase.pas

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

+ 11 - 9
compiler/aasmtai.pas

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

+ 6 - 25
compiler/aggas.pas

@@ -29,11 +29,6 @@ unit aggas;
 interface
 interface
 
 
     uses
     uses
-{$IFDEF USE_SYSUTILS}
-      SysUtils,
-{$ELSE USE_SYSUTILS}
-      dos,
-{$ENDIF USE_SYSUTILS}
       cclasses,
       cclasses,
       globtype,globals,
       globtype,globals,
       aasmbase,aasmtai,aasmdata,aasmcpu,
       aasmbase,aasmtai,aasmdata,aasmcpu,
@@ -90,7 +85,8 @@ interface
 implementation
 implementation
 
 
     uses
     uses
-      cutils,systems,
+      SysUtils,
+      cutils,cfileutils,systems,
       fmodule,finput,verbose,
       fmodule,finput,verbose,
       itcpugas,cpubase
       itcpugas,cpubase
       ;
       ;
@@ -1031,9 +1027,7 @@ implementation
 
 
     procedure TGNUAssembler.WriteAsmList;
     procedure TGNUAssembler.WriteAsmList;
     var
     var
-      p:dirstr;
-      n:namestr;
-      e:extstr;
+      n : string;
       hal : tasmlisttype;
       hal : tasmlisttype;
     begin
     begin
 {$ifdef EXTDEBUG}
 {$ifdef EXTDEBUG}
@@ -1046,23 +1040,10 @@ implementation
       LastInfile:=nil;
       LastInfile:=nil;
 
 
       if assigned(current_module.mainsource) then
       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
       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;
       WriteExtraHeader;
       AsmStartSize:=AsmSize;
       AsmStartSize:=AsmSize;
       symendcount:=0;
       symendcount:=0;

+ 37 - 94
compiler/assemble.pas

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

+ 14 - 13
compiler/browcol.pas

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

+ 1 - 1
compiler/browlog.pas

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

+ 125 - 3
compiler/cclasses.pas

@@ -235,7 +235,7 @@ type
   TFPHashObject = class
   TFPHashObject = class
   private
   private
     FOwner : TFPHashObjectList;
     FOwner : TFPHashObjectList;
-    FCachedStr : pstring;
+    FCachedStr : pshortstring;
     FStrIndex  : Integer;
     FStrIndex  : Integer;
   protected
   protected
     function GetName:string;
     function GetName:string;
@@ -348,7 +348,7 @@ type
 
 
        { string containerItem }
        { string containerItem }
        TStringListItem = class(TLinkedListItem)
        TStringListItem = class(TLinkedListItem)
-          FPStr : PString;
+          FPStr : pshortstring;
        public
        public
           constructor Create(const s:string);
           constructor Create(const s:string);
           destructor  Destroy;override;
           destructor  Destroy;override;
@@ -406,7 +406,7 @@ type
          FLeft,
          FLeft,
          FRight      : TNamedIndexItem;
          FRight      : TNamedIndexItem;
          FSpeedValue : cardinal;
          FSpeedValue : cardinal;
-         FName       : Pstring;
+         FName       : pshortstring;
        protected
        protected
          function  GetName:string;virtual;
          function  GetName:string;virtual;
          procedure SetName(const n:string);virtual;
          procedure SetName(const n:string);virtual;
@@ -3487,5 +3487,127 @@ begin
     end;
     end;
 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.
 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
 implementation
 
 
 uses
 uses
-  cutils,
-  strings;
+  SysUtils,
+  cutils;
 
 
 
 
 function MsgReplace(const s:string;const args:array of string):string;
 function MsgReplace(const s:string;const args:array of string):string;

+ 0 - 14
compiler/comphook.pas

@@ -155,9 +155,6 @@ const
 implementation
 implementation
 
 
   uses
   uses
-{$IFNDEF USE_SYSUTILS}
-   dos,
-{$ENDIF USE_SYSUTILS}
    cutils, systems
    cutils, systems
    ;
    ;
 
 
@@ -383,23 +380,12 @@ end;
 
 
 Function def_GetNamedFileTime (Const F : String) : Longint;
 Function def_GetNamedFileTime (Const F : String) : Longint;
 var
 var
-{$IFDEF USE_SYSUTILS}
   fh : THandle;
   fh : THandle;
-{$ELSE USE_SYSUTILS}
-  info : SearchRec;
-{$ENDIF USE_SYSUTILS}
 begin
 begin
   Result := -1;
   Result := -1;
-{$IFDEF USE_SYSUTILS}
   fh := FileOpen(f, faArchive+faReadOnly+faHidden);
   fh := FileOpen(f, faArchive+faReadOnly+faHidden);
   Result := FileGetDate(fh);
   Result := FileGetDate(fh);
   FileClose(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;
 
 
 end.
 end.

+ 7 - 17
compiler/compiler.pas

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

+ 7 - 39
compiler/comprsrc.pas

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

+ 3 - 2
compiler/cresstr.pas

@@ -31,6 +31,7 @@ interface
 implementation
 implementation
 
 
 uses
 uses
+   SysUtils,
    cclasses,
    cclasses,
    cutils,globtype,globals,systems,
    cutils,globtype,globals,systems,
    symconst,symtype,symdef,symsym,
    symconst,symtype,symdef,symsym,
@@ -235,8 +236,8 @@ uses
         end;
         end;
 
 
       begin
       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);
         Assign(F,ResFileName);
         {$i-}
         {$i-}
         Rewrite(f);
         Rewrite(f);

+ 18 - 30
compiler/cutils.pas

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

+ 5 - 11
compiler/dbgdwarf.pas

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

+ 21 - 16
compiler/dbgstabs.pas

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

+ 1 - 1
compiler/export.pas

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

+ 54 - 66
compiler/finput.pas

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

+ 9 - 20
compiler/fmodule.pas

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

+ 11 - 9
compiler/fppu.pas

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

+ 3 - 2
compiler/gendef.pas

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

File diff suppressed because it is too large
+ 13 - 1029
compiler/globals.pas


+ 4 - 11
compiler/globtype.pas

@@ -28,18 +28,11 @@ interface
        maxidlen = 127;
        maxidlen = 127;
 
 
     type
     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;
        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 }
        { Natural integer register type and size for the target machine }
 {$ifdef cpu64bit}
 {$ifdef cpu64bit}

+ 1 - 13
compiler/impdef.pas

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

+ 11 - 43
compiler/link.pas

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

+ 2 - 2
compiler/m68k/ra68kmot.pas

@@ -79,7 +79,7 @@ unit ra68kmot;
          procedure GetToken;
          procedure GetToken;
          function consume(t : tasmtoken):boolean;
          function consume(t : tasmtoken):boolean;
          function findopcode(s: string; var opsize: topsize): tasmop;
          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 BuildConstant(maxvalue: longint);
          Procedure BuildRealConstant(typ : tfloattype);
          Procedure BuildRealConstant(typ : tfloattype);
          Procedure BuildScaling(const oper:tm68koperand);
          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                                   }
   { FUNCTION BuildExpression: longint                                   }
   {  Description: This routine calculates a constant expression to      }
   {  Description: This routine calculates a constant expression to      }

+ 2 - 2
compiler/ncnv.pas

@@ -488,8 +488,8 @@ implementation
                           not(is_char(hdef)) then
                           not(is_char(hdef)) then
                           CGMessage(type_e_typeconflict_in_set)
                           CGMessage(type_e_typeconflict_in_set)
                         else
                         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
                         if hdef=nil then
                          hdef:=cchartype;
                          hdef:=cchartype;
                         p2.free;
                         p2.free;

+ 2 - 2
compiler/nobj.pas

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

+ 3 - 2
compiler/ogbase.pas

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

+ 4 - 3
compiler/ogcoff.pas

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

+ 2 - 2
compiler/ogelf.pas

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

+ 2 - 1
compiler/ogmap.pas

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

+ 44 - 87
compiler/options.pas

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

+ 8 - 10
compiler/owar.pas

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

+ 2 - 1
compiler/owbase.pas

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

+ 2 - 2
compiler/parser.pas

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

+ 3 - 3
compiler/pdecsub.pas

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

+ 2 - 1
compiler/pdecvar.pas

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

+ 3 - 2
compiler/pmodules.pas

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

+ 1 - 1
compiler/ptconst.pas

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

+ 1 - 1
compiler/rautils.pas

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

+ 6 - 5
compiler/scandir.pas

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

+ 23 - 23
compiler/scanner.pas

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

+ 4 - 3
compiler/script.pas

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

+ 2 - 2
compiler/symbase.pas

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

+ 10 - 9
compiler/symdef.pas

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

+ 4 - 4
compiler/symsym.pas

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

+ 1 - 1
compiler/symtable.pas

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

+ 1 - 1
compiler/symtype.pas

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

+ 3 - 3
compiler/systems/t_beos.pas

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

+ 13 - 21
compiler/systems/t_bsd.pas

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

+ 30 - 15
compiler/systems/t_emx.pas

@@ -37,9 +37,8 @@ interface
 implementation
 implementation
 
 
   uses
   uses
-     strings,
-     dos,
-     cutils,cclasses,
+     sysutils,
+     cutils,cfileutils,cclasses,
      globtype,comphook,systems,symconst,symsym,symdef,
      globtype,comphook,systems,symconst,symsym,symdef,
      globals,verbose,fmodule,script,ogbase,
      globals,verbose,fmodule,script,ogbase,
      import,link,i_emx,ppu;
      import,link,i_emx,ppu;
@@ -131,21 +130,40 @@ var aout_str_size:longint;
 
 
     out_file:file;
     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);
 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;
     dummy:word;
     numtime:longint;
     numtime:longint;
     tmp:string[19];
     tmp:string[19];
-
-
 begin
 begin
     ar_member_size:=size;
     ar_member_size:=size;
     fillchar(ar.ar_name,sizeof(ar.ar_name),' ');
     fillchar(ar.ar_name,sizeof(ar.ar_name),' ');
     move(name[1],ar.ar_name,length(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);
     packtime(time,numtime);
     str(numtime,tmp);
     str(numtime,tmp);
     fillchar(ar.ar_date,sizeof(ar.ar_date),' ');
     fillchar(ar.ar_date,sizeof(ar.ar_date),' ');
@@ -438,17 +456,14 @@ var
   AppTypeStr,
   AppTypeStr,
   StripStr: string[40];
   StripStr: string[40];
   RsrcStr : string;
   RsrcStr : string;
-  DS: DirStr;
-  NS: NameStr;
-  ES: ExtStr;
-  OutName: PathStr;
+  DS,NS,ES : string;
+  OutName: string;
 begin
 begin
   if not(cs_link_nolink in current_settings.globalswitches) then
   if not(cs_link_nolink in current_settings.globalswitches) then
    Message1(exec_i_linking,current_module.exefilename^);
    Message1(exec_i_linking,current_module.exefilename^);
 
 
 { Create some replacements }
 { 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
   if (cs_link_strip in current_settings.globalswitches) then
    StripStr := '-s'
    StripStr := '-s'
   else
   else

+ 5 - 3
compiler/systems/t_go32v2.pas

@@ -30,9 +30,11 @@ interface
 implementation
 implementation
 
 
     uses
     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
     type
       TInternalLinkerGo32v2=class(TInternallinker)
       TInternalLinkerGo32v2=class(TInternallinker)

+ 11 - 10
compiler/systems/t_linux.pas

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

+ 3 - 2
compiler/systems/t_nwl.pas

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

+ 1 - 1
compiler/systems/t_nwm.pas

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

+ 27 - 13
compiler/systems/t_os2.pas

@@ -37,9 +37,8 @@ interface
 implementation
 implementation
 
 
   uses
   uses
-     strings,
-     dos,
-     cutils,cclasses,
+     SysUtils,
+     cutils,cfileutils,cclasses,
      globtype,systems,symconst,symdef,
      globtype,systems,symconst,symdef,
      globals,verbose,fmodule,script,
      globals,verbose,fmodule,script,
      import,link,i_os2,ogbase;
      import,link,i_os2,ogbase;
@@ -130,11 +129,31 @@ var aout_str_size:longint;
 
 
     out_file:file;
     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);
 procedure write_ar(const name:string;size:longint);
 
 
 var ar:ar_hdr;
 var ar:ar_hdr;
-    time:datetime;
-    dummy:word;
+    time:TSystemTime;
     numtime:longint;
     numtime:longint;
     tmp:string[19];
     tmp:string[19];
 
 
@@ -143,8 +162,7 @@ begin
     ar_member_size:=size;
     ar_member_size:=size;
     fillchar(ar.ar_name,sizeof(ar.ar_name),' ');
     fillchar(ar.ar_name,sizeof(ar.ar_name),' ');
     move(name[1],ar.ar_name,length(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);
     packtime(time,numtime);
     str(numtime,tmp);
     str(numtime,tmp);
     fillchar(ar.ar_date,sizeof(ar.ar_date),' ');
     fillchar(ar.ar_date,sizeof(ar.ar_date),' ');
@@ -437,17 +455,13 @@ var
   AppTypeStr,
   AppTypeStr,
   StripStr: string[40];
   StripStr: string[40];
   RsrcStr : string;
   RsrcStr : string;
-  DS: DirStr;
-  NS: NameStr;
-  ES: ExtStr;
-  OutName: PathStr;
+  OutName: TPathStr;
 begin
 begin
   if not(cs_link_nolink in current_settings.globalswitches) then
   if not(cs_link_nolink in current_settings.globalswitches) then
    Message1(exec_i_linking,current_module.exefilename^);
    Message1(exec_i_linking,current_module.exefilename^);
 
 
 { Create some replacements }
 { 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
   if (cs_link_strip in current_settings.globalswitches) then
    StripStr := '-s'
    StripStr := '-s'
   else
   else

+ 2 - 1
compiler/systems/t_sunos.pas

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

+ 2 - 1
compiler/systems/t_watcom.pas

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

+ 8 - 6
compiler/systems/t_win.pas

@@ -24,8 +24,8 @@ unit t_win;
 {$i fpcdefs.inc}
 {$i fpcdefs.inc}
 
 
 interface
 interface
+
     uses
     uses
-       dos,
        cutils,cclasses,
        cutils,cclasses,
        aasmbase,aasmtai,aasmdata,aasmcpu,fmodule,globtype,globals,systems,verbose,
        aasmbase,aasmtai,aasmdata,aasmcpu,fmodule,globtype,globals,systems,verbose,
        symconst,symdef,symsym,
        symconst,symdef,symsym,
@@ -89,6 +89,8 @@ interface
 implementation
 implementation
 
 
   uses
   uses
+    SysUtils,
+    cfileutils,
     cpuinfo,cgutils,dbgbase,
     cpuinfo,cgutils,dbgbase,
     owar,ogbase,ogcoff;
     owar,ogbase,ogcoff;
 
 
@@ -165,7 +167,7 @@ implementation
           idata4objsection:=objdata.createsection(sec_idata4,'');
           idata4objsection:=objdata.createsection(sec_idata4,'');
           idata5objsection:=objdata.createsection(sec_idata5,'');
           idata5objsection:=objdata.createsection(sec_idata5,'');
           emptyint:=0;
           emptyint:=0;
-          basedllname:=splitfilename(dllname);
+          basedllname:=ExtractFileName(dllname);
           { idata4 }
           { idata4 }
           objdata.SetSection(idata4objsection);
           objdata.SetSection(idata4objsection);
           idata4label:=objdata.SymbolDefine(asmprefix+'_names_'+basedllname,AB_GLOBAL,AT_DATA);
           idata4label:=objdata.SymbolDefine(asmprefix+'_names_'+basedllname,AB_GLOBAL,AT_DATA);
@@ -456,7 +458,7 @@ implementation
                     if ImportSymbol.Name <> '' then
                     if ImportSymbol.Name <> '' then
                       current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(ImportSymbol.Name,AT_FUNCTION,0))
                       current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(ImportSymbol.Name,AT_FUNCTION,0))
                     else
                     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(''));
                     current_asmdata.asmlists[al_imports].concat(tai_function_name.create(''));
                   {$ifdef ARM}
                   {$ifdef ARM}
                     reference_reset_symbol(href,l5,0);
                     reference_reset_symbol(href,l5,0);
@@ -1281,7 +1283,7 @@ implementation
         if (cs_link_strip in current_settings.globalswitches) then
         if (cs_link_strip in current_settings.globalswitches) then
           StripStr:='-s';
           StripStr:='-s';
         if (cs_link_map in current_settings.globalswitches) then
         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 }
       { Write used files and libraries }
         WriteResponseFile(false);
         WriteResponseFile(false);
@@ -1383,7 +1385,7 @@ implementation
         if (cs_link_strip in current_settings.globalswitches) then
         if (cs_link_strip in current_settings.globalswitches) then
           StripStr:='-s';
           StripStr:='-s';
         if (cs_link_map in current_settings.globalswitches) then
         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 }
       { Write used files and libraries }
         WriteResponseFile(true);
         WriteResponseFile(true);
@@ -1650,7 +1652,7 @@ implementation
         if FindLibraryFile(binname,target_info.staticClibprefix,target_info.staticClibext,hs) then
         if FindLibraryFile(binname,target_info.staticClibprefix,target_info.staticClibext,hs) then
           exit;
           exit;
         { check if we can find the dll }
         { 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
         if not FindDll(hs,dllname) then
           exit;
           exit;
         importfound:=false;
         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
 begin
   if (Ext<>'') and (SplitExtension(HStr)='') then
   if (Ext<>'') and (SplitExtension(HStr)='') then
-   AddExtension:=Hstr+'.'+Ext
+   ChangeFileExt:=Hstr+'.'+Ext
   else
   else
-   AddExtension:=Hstr;
+   ChangeFileExt:=Hstr;
 end;
 end;
 
 
 
 
@@ -185,13 +185,13 @@ var
 begin
 begin
 {Create New FileName}
 {Create New FileName}
   if SplitExtension(nfn)='*' then
   if SplitExtension(nfn)='*' then
-   nfn:=AddExtension(SplitPath(nfn)+SplitName(nfn),SplitExtension(fn));
+   nfn:=ChangeFileExt(SplitPath(nfn)+SplitName(nfn),SplitExtension(fn));
   if SplitName(nfn)='*' then
   if SplitName(nfn)='*' then
    begin
    begin
      if SplitPath(nfn)='' then
      if SplitPath(nfn)='' then
-      nfn:=AddExtension(SplitPath(fn)+SplitName(fn),SplitExtension(nfn))
+      nfn:=ChangeFileExt(SplitPath(fn)+SplitName(fn),SplitExtension(nfn))
      else
      else
-      nfn:=AddExtension(SplitPath(nfn)+SplitName(fn),SplitExtension(nfn));
+      nfn:=ChangeFileExt(SplitPath(nfn)+SplitName(fn),SplitExtension(nfn));
    end;
    end;
 {Done?}
 {Done?}
   if FileDone(nfn) then
   if FileDone(nfn) then
@@ -320,7 +320,7 @@ begin
         ch:=para[2];
         ch:=para[2];
         delete(para,1,2);
         delete(para,1,2);
         case ch of
         case ch of
-         'O' : OutFile:=AddExtension(Para,OutputExt);
+         'O' : OutFile:=ChangeFileExt(Para,OutputExt);
          'D' : DosEol:=true;
          'D' : DosEol:=true;
          'T' : Val(Para,TabSize,j);
          'T' : Val(Para,TabSize,j);
          'V' : verbose:=true;
          'V' : verbose:=true;
@@ -356,7 +356,7 @@ begin
    end;
    end;
   for i:=ParaFile to ParamCount do
   for i:=ParaFile to ParamCount do
    begin
    begin
-     InFile:=AddExtension(ParamStr(i),InputExt);
+     InFile:=ChangeFileExt(ParamStr(i),InputExt);
      FindFirst(InFile,$20,Dir);
      FindFirst(InFile,$20,Dir);
      while (DosError=0) do
      while (DosError=0) do
       begin
       begin

+ 4 - 4
compiler/utils/ppufiles.pp

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

+ 4 - 4
compiler/utils/ppumove.pp

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

+ 7 - 7
compiler/x86/agx86int.pas

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

Some files were not shown because too many files changed in this diff