Browse Source

+ Moved getlocaltime to system-dependent files

michael 26 years ago
parent
commit
f6908c234f
3 changed files with 159 additions and 23 deletions
  1. 21 1
      rtl/go32v2/filutil.inc
  2. 12 1
      rtl/linux/filutil.inc
  3. 126 21
      rtl/win32/filutil.inc

+ 21 - 1
rtl/go32v2/filutil.inc

@@ -331,10 +331,30 @@ begin
   result := DOS.FSearch(Name, DirList);
 end;
 
+Procedure GetLocalTime(var SystemTime: TSystemTime);
+
+var Regs: Registers;
+
+begin
+Regs.ah := $2C;
+RealIntr($21, Regs);
+SystemTime.Hour := Regs.Ch;
+SystemTime.Minute := Regs.Cl;
+SystemTime.Second := Regs.Dh;
+SystemTime.MilliSecond := Regs.Dl;
+Regs.ah := $2A;
+RealIntr($21, Regs);
+SystemTime.Year := Regs.Cx;
+SystemTime.Month := Regs.Dh;
+SystemTime.Day := Regs.Dl;
+end ;
 
 {
   $Log$
-  Revision 1.3  1999-02-09 17:16:59  florian
+  Revision 1.4  1999-02-24 15:57:28  michael
+  + Moved getlocaltime to system-dependent files
+
+  Revision 1.3  1999/02/09 17:16:59  florian
     + typinfo is now also in the makefile for go32v2
     + sysutils.filetruncate for go32v2
 

+ 12 - 1
rtl/linux/filutil.inc

@@ -233,10 +233,21 @@ begin
   FileSearch:=Linux.FSearch(Name,Dirlist);
 end;
 
+Procedure GetLocalTime(var SystemTime: TSystemTime);
+
+begin
+linux.GetTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second);
+linux.GetDate(SystemTime.Year, SystemTime.Month, SystemTime.Day);
+SystemTime.MilliSecond := 0;
+end ;
+
 
 {
   $Log$
-  Revision 1.6  1999-02-04 21:43:08  michael
+  Revision 1.7  1999-02-24 15:57:29  michael
+  + Moved getlocaltime to system-dependent files
+
+  Revision 1.6  1999/02/04 21:43:08  michael
   FileCreate must truncate the file
 
   Revision 1.5  1999/02/02 21:20:34  michael

+ 126 - 21
rtl/win32/filutil.inc

@@ -91,6 +91,23 @@ begin
     Result:=SetEndOfFile(handle);
 end;
 
+Function DosToWinTime (DTime:longint;Var Wtime : TFileTime):longbool;
+var
+  lft : TFileTime;
+begin
+  DosToWinTime:=DosDateTimeToFileTime(longrec(dtime).hi,longrec(dtime).lo,@lft) and
+                LocalFileTimeToFileTime(lft,@Wtime);
+end;
+
+
+Function WinToDosTime (Var Wtime : TFileTime;var DTime:longint):longbool;
+var
+  lft : FileTime;
+begin
+  WinToDosTime:=FileTimeToLocalFileTime(WTime,@lft) and
+                FileTimeToDosDateTime(lft,@Longrec(Dtime).Hi,@LongRec(DTIME).lo);
+end;
+
 
 Function FileAge (Const FileName : String): Longint;
 
@@ -101,18 +118,12 @@ var
   Fn : String;
   
 begin
-  FN:=FN+#0;
-  Handle := FindFirstFile(@FN[1], @FindData);
+  Handle := FindFirstFile(Pchar(FileName), @FindData);
   if Handle <> INVALID_HANDLE_VALUE then
     begin
     Windows.FindClose(Handle);
     if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
-      begin
-{
-      FileTimeToLocalFileTime(FindData.ftLastWriteTime, @LocalFileTime);
-      if FileTimeToDosDateTime(LocalFileTime, LongRec(Result).Hi,
-                               LongRec(Result).Lo) then Exit;
-}      end;
+      If WinToDosTime(FindData.ftLastWriteTime,Result) then exit;
     end;
   Result := -1;
 end;
@@ -120,84 +131,178 @@ end;
 
 Function FileExists (Const FileName : String) : Boolean;
 
+var
+  Handle: THandle;
+  FindData: TWin32FindData;
+  P : Pchar;
 begin
-  Result := FileAge(FileName) <> -1;
+  P:=Pchar(Filename);
+  Handle := FindFirstFile(Pchar(FileName), @FindData);
+  Result:=Handle <> INVALID_HANDLE_VALUE;
+  If Result then 
+    Windows.FindClose(Handle);
 end;
 
+Function FindMatch(var f: TSearchRec) : Longint;
+
+begin
+  { Find file with correct attribute }
+  While (F.FindData.dwFileAttributes and F.ExcludeAttr)<>0 do
+   begin
+     if not FindNextFile (F.FindHandle,@F.FindData) then
+      begin
+      Result:=GetLastError;
+      exit;
+      end;
+   end;
+  { Convert some attributes back }
+  WinToDosTime(F.FindData.ftLastWriteTime,F.Time);
+  f.size:=F.FindData.NFileSizeLow;
+  f.attr:=F.FindData.dwFileAttributes;
+  f.Name:=StrPas(@F.FindData.cFileName);
+end;
 
 Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
 
 begin
-  //!! Needs implementing    
+  Rslt.Name:=Path;
+  Rslt.Attr:=attr;
+  Rslt.ExcludeAttr:=(not Attr) and ($1e);
+                 { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
+  { FindFirstFile is a Win32 Call }
+  Rslt.FindHandle:=FindFirstFile (PChar(Path),@Rslt.FindData);
+  If Rslt.FindHandle=Invalid_Handle_value then
+     begin
+     Result:=GetLastError;
+     exit;
+     end;
+  { Find file with correct attribute }
+  Result:=FindMatch(Rslt);
 end;
 
 
 Function FindNext (Var Rslt : TSearchRec) : Longint;
 
 begin
-  //!! Needs implementing    
+  if FindNextFile(Rslt.FindHandle, @Rslt.FindData) then
+    Result := FindMatch(Rslt)
+  else
+    Result := GetLastError;
 end;
 
 
 Procedure FindClose (Var F : TSearchrec);
 
 begin
-  //!! Needs implementing    
+   if F.FindHandle <> INVALID_HANDLE_VALUE then
+    Windows.FindClose(F.FindHandle);
 end;
 
 
+
 Function FileGetDate (Handle : Longint) : Longint;
 
+Var FT : TFileTime;
+
 begin
-  //!! Needs implementing    
+  If GetFileTime(Handle,nil,nil,@ft) and
+     WinToDosTime(FT,Result) then exit;
+  Result:=-1;
 end;
 
 
 Function FileSetDate (Handle,Age : Longint) : Longint;
 
+Var FT: TFileTime;
+  
 begin
-  //!! Needs implementing    
+  Result := 0;
+  if DosToWinTime(Age,FT) and
+     SetFileTime(Handle, ft, ft, FT) then Exit;
+  Result := GetLastError;
 end;
 
 
 Function FileGetAttr (Const FileName : String) : Longint;
 
 begin
-  //!! Needs implementing    
+  Result:=GetFileAttributes(PChar(FileName));
 end;
 
 
 Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
 
 begin
-  //!! Needs implementing    
+  if not SetFileAttributes(PChar(FileName), Attr) then
+    Result := GetLastError
+  else
+    Result:=0;
 end;
 
 
 Function DeleteFile (Const FileName : String) : Boolean;
 
 begin
-  //!! Needs implementing    
+  DeleteFile:=Windows.DeleteFile(Pchar(FileName));
 end;
 
 
 Function RenameFile (Const OldName, NewName : String) : Boolean;
 
 begin
-  //!! Needs implementing    
+  Result := MoveFile(PChar(OldName), PChar(NewName));
 end;
 
 
 Function FileSearch (Const Name, DirList : String) : String;
 
+Var I : longint;
+    Temp : String;
+
 begin
-  //!! Needs implementing    
+  Result:='';
+  temp:=Dirlist;
+  repeat
+    I:=pos(';',Temp);
+    If I<>0 then
+      begin
+      Result:=Copy (Temp,1,i-1);
+      system.Delete(Temp,1,I);
+      end
+    else
+      begin
+      Result:=Temp;
+      Temp:='';
+      end;  
+    If result[length(result)]<>'\' then
+      Result:=Result+'\';
+    Result:=Result+name;
+    If not FileExists(Result) Then 
+     Result:='';
+  until (length(temp)=0) or (length(result)<>0);
 end;
 
+Procedure GetLocalTime(var ST: TSystemTime);
+
+Var Syst:Systemtime;
+
+begin
+  windows.Getlocaltime(@syst);
+  st.year:=syst.wYear;
+  st.month:=syst.wMonth;
+  st.day:=syst.wDay;
+  st.hour:=syst.wHour;
+  st.minute:=syst.wMinute;
+  st.second:=syst.wSecond;
+  st.millisecond:=syst.wMilliSeconds;
+end;
 
 {
   $Log$
-  Revision 1.3  1999-02-09 12:01:03  michael
+  Revision 1.4  1999-02-24 15:57:30  michael
+  + Moved getlocaltime to system-dependent files
+
+  Revision 1.3  1999/02/09 12:01:03  michael
   + Implemented filetruncate
 
   Revision 1.2  1999/02/03 11:41:30  michael
@@ -206,4 +311,4 @@ end;
   Revision 1.1  1998/10/11 12:21:01  michael
   Added file calls. Implemented for linux only
 
-}
+}