Browse Source

+ implementation started

Tomas Hajny 25 years ago
parent
commit
0f01fb7669
1 changed files with 225 additions and 49 deletions
  1. 225 49
      rtl/os2/filutil.inc

+ 225 - 49
rtl/os2/filutil.inc

@@ -15,66 +15,155 @@
  **********************************************************************}
  **********************************************************************}
 
 
 
 
-Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
-
-Begin
-  //!! Needs implementing
+const
+ ofRead        = $0000;     {Open for reading}
+ ofWrite       = $0001;     {Open for writing}
+ ofReadWrite   = $0002;     {Open for reading/writing}
+ faCreateNew   = $00010000; {Create if file does not exist}
+ faOpenReplace = $00040000; {Truncate if file exists}
+ faCreate      = $00050000; {Create if file does not exist, truncate otherwise}
+
+{$ASMMODE INTEL}
+function FileOpen (const FileName: string; Mode: integer): longint;
+{$IFOPT H+}
+                                                                    assembler;
+{$ELSE}
+var FN: string;
+begin
+    FN := FileName + #0;
+{$ENDIF}
+    asm
+         mov eax, 7F2Bh
+         mov ecx, Mode
+{$IFOPT H+}
+         mov edx, FileName
+{$ELSE}
+         lea edx, FN
+         inc edx
+{$ENDIF}
+         call syscall
+{$IFOPT H-}
+    end;
+{$ELSE}
 end;
 end;
 
 
 
 
-Function FileCreate (Const FileName : String) : Longint;
-
+function FileCreate (const FileName: string): longint;
+var FN: string;
 begin
 begin
-  //!! Needs implementing
+    FN := FileName + #0;
+    asm
+         mov eax, 7F2Bh
+         mov ecx, ofReadWrite or faCreate
+         lea edx, FN
+         inc edx
+         call syscall
+    end;
 end;
 end;
 
 
 
 
-Function FileRead (Handle : Longint; Var Buffer; Count : longint) : Longint;
-
-begin
-  //!! Needs implementing
+function FileRead (Handle: longint; var Buffer; Count: longint): longint;
+                                                                     assembler;
+asm
+    mov eax, 3F00h
+    mov ebx, Handle
+    mov ecx, Count
+    mov edx, Buffer
+    call syscall
+    jnc @FReadEnd
+    mov eax, -1
+@FReadEnd:
 end;
 end;
 
 
 
 
-Function FileWrite (Handle : Longint; const Buffer; Count : Longint) : Longint;
-
-begin
-  //!! Needs implementing
+function FileWrite (Handle: longint; const Buffer; Count: longint): longint;
+                                                                     assembler;
+asm
+    mov eax, 4000h
+    mov ebx, Handle
+    mov ecx, Count
+    mov edx, Buffer
+    call syscall
+    jnc @FWriteEnd
+    mov eax, -1
+@FWriteEnd:
 end;
 end;
 
 
 
 
-Function FileSeek (Handle,Offset,Origin : Longint) : Longint;
-
-begin
-  //!! Needs implementing
+function FileSeek (Handle, Offset, Origin: longint): longint; assembler;
+asm
+    mov eax, Origin
+    mov ah, 42h
+    mov ebx, Handle
+    mov edx, Offset
+    call syscall
+    jnc @FSeekEnd
+    mov eax, -1
+@FSeekEnd:
 end;
 end;
 
 
 
 
-Procedure FileClose (Handle : Longint);
-
-begin
-  //!! Needs implementing
+procedure FileClose (Handle: longint); assembler;
+asm
+    mov eax, 3E00h
+    mov ebx, Handle
+    call syscall
 end;
 end;
 
 
 
 
-Function FileTruncate (Handle,Size: Longint) : boolean;
-
-begin
-  //!! Needs implementing
+function FileTruncate (Handle, Size: longint): boolean; assembler;
+asm
+    mov eax, 7F25h
+    mov ebx, Handle
+    mov edx, Size
+    call syscall
+    mov eax, 0
+    jc @FTruncEnd
+    inc eax
+@FTruncEnd:
 end;
 end;
 
 
 
 
-Function FileAge (Const FileName : String): Longint;
-
+function FileAge (const FileName: string): longint;
+var Handle: longint;
 begin
 begin
-  //!! Needs implementing
+    Handle := FileOpen (FileName, 0);
+    if Handle <> -1 then
+        begin
+            Result := FileGetDate (Handle);
+            FileClose (Handle);
+        end
+    else
+        Result := -1;
 end;
 end;
 
 
 
 
-Function FileExists (Const FileName : String) : Boolean;
-
+function FileExists (const FileName: string): boolean;
+{$IFOPT H+}
+                                                       assembler;
+{$ELSE}
+var FN: string;
 begin
 begin
-  //!! Needs implementing
+    FN := FileName + #0;
+{$ENDIF}
+asm
+    mov ax, 4300h
+{$IFOPT H+}
+    mov edx, FileName
+{$ELSE}
+    lea edx, FN
+    inc edx
+{$ENDIF}
+    call syscall
+    mov eax, 0
+    jc @FExistsEnd
+    test cx, 18h
+    jnz @FExistsEnd
+    inc eax
+@FExistsEnd:
+{$IFOPT H-}
+end;
+{$ENDIF}
 end;
 end;
 
 
 
 
@@ -113,38 +202,121 @@ begin
 end;
 end;
 
 
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
-
+function FileGetAttr (const FileName: string): longint;
+{$IFOPT H+}
+                                                        assembler;
+{$ELSE}
+var FN: string;
 begin
 begin
-  //!! Needs implementing
+    FN := FileName + #0;
+{$ENDIF}
+asm
+    mov ax, 4300h
+{$IFOPT H+}
+    mov edx, FileName
+{$ELSE}
+    lea edx, FN
+    inc edx
+{$ENDIF}
+    call syscall
+    jnc @FGetAttrEnd
+    mov eax, -1
+@FGetAttrEnd:
+{$IFOPT H-}
+end;
+{$ENDIF}
 end;
 end;
 
 
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
-
+function FileSetAttr (const Filename: string; Attr: longint): longint;
+{$IFOPT H+}
+                                                                     assembler;
+{$ELSE}
+var FN: string;
 begin
 begin
-  //!! Needs implementing
+    FN := FileName + #0;
+{$ENDIF}
+asm
+    mov ax, 4301h
+    mov ecx, Attr
+{$IFOPT H+}
+    mov edx, FileName
+{$ELSE}
+    lea edx, FN
+    inc edx
+{$ENDIF}
+    call syscall
+    mov eax, 0
+    jnc @FSetAttrEnd
+    mov eax, -1
+@FSetAttrEnd:
+{$IFOPT H-}
+end;
+{$ENDIF}
 end;
 end;
 
 
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
-
+function DeleteFile (const FileName: string): boolean;
+{$IFOPT H+}
+                                                       assembler;
+{$ELSE}
+var FN: string;
 begin
 begin
-  //!! Needs implementing
+    FN := FileName + #0;
+{$ENDIF}
+asm
+    mov ax, 4100h
+{$IFOPT H+}
+    mov edx, FileName
+{$ELSE}
+    lea edx, FN
+    inc edx
+{$ENDIF}
+    call syscall
+    mov eax, 0
+    jc @FDeleteEnd
+    inc eax
+@FExistsEnd:
+{$IFOPT H-}
+end;
+{$ENDIF}
 end;
 end;
 
 
 
 
-Function RenameFile (Const OldName, NewName : String) : Boolean;
-
+function RenameFile (const OldName, NewName: string): boolean;
+{$IFOPT H+}
+                                                       assembler;
+{$ELSE}
+var FN1, FN2: string;
 begin
 begin
-  //!! Needs implementing
+    FN1 := OldName + #0;
+    FN2 := NewName + #0;
+{$ENDIF}
+asm
+    mov ax, 5600h
+{$IFOPT H+}
+    mov edx, OldName
+    mov edi, NewName
+{$ELSE}
+    lea edx, FN1
+    inc edx
+    lea edi, FN2
+    inc edi
+{$ENDIF}
+    call syscall
+    mov eax, 0
+    jc @FRenameEnd
+    inc eax
+@FRenameEnd:
+{$IFOPT H-}
+end;
+{$ENDIF}
 end;
 end;
 
 
 
 
-Function FileSearch (Const Name, DirList : String) : String;
-
+function FileSearch (const Name, DirList: string): string;
 begin
 begin
-  //!! Needs implementing
+    Result := Dos.FSearch (Name, DirList);
 end;
 end;
 
 
 
 
@@ -155,6 +327,7 @@ begin
 end ;
 end ;
 
 
 Procedure InitAnsi;
 Procedure InitAnsi;
+(* __nls_ctype ??? *)
 begin
 begin
   //!! Needs implementing
   //!! Needs implementing
 end;
 end;
@@ -167,7 +340,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.6  2000-02-17 22:16:05  sg
+  Revision 1.7  2000-05-28 18:22:58  hajny
+    + implementation started
+
+  Revision 1.6  2000/02/17 22:16:05  sg
   * Changed the second argument of FileWrite from "var buffer" to
   * Changed the second argument of FileWrite from "var buffer" to
     "const buffer", like in Delphi.
     "const buffer", like in Delphi.