2020-05-25 22:48:33 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
Copyright 2016, 2018 Anton Krotov
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE File;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IMPORT sys := SYSTEM, KOSAPI;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
CONST
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
SEEK_BEG* = 0; SEEK_CUR* = 1; SEEK_END* = 2;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
TYPE
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
FNAME* = ARRAY 520 OF CHAR;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
FS* = POINTER TO rFS;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
rFS* = RECORD
|
|
|
|
subfunc*, pos*, hpos*, bytes*, buffer*: INTEGER;
|
|
|
|
name*: FNAME
|
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
FD* = POINTER TO rFD;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
rFD* = RECORD
|
|
|
|
attr*: INTEGER;
|
|
|
|
ntyp*: CHAR;
|
|
|
|
reserved: ARRAY 3 OF CHAR;
|
|
|
|
time_create*, date_create*,
|
|
|
|
time_access*, date_access*,
|
|
|
|
time_modif*, date_modif*,
|
|
|
|
size*, hsize*: INTEGER;
|
|
|
|
name*: FNAME
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE [stdcall] f_68_27 (file_name: INTEGER; VAR size: INTEGER): INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
sys.CODE(
|
|
|
|
053H, (* push ebx *)
|
|
|
|
06AH, 044H, (* push 68 *)
|
|
|
|
058H, (* pop eax *)
|
|
|
|
06AH, 01BH, (* push 27 *)
|
|
|
|
05BH, (* pop ebx *)
|
|
|
|
08BH, 04DH, 008H, (* mov ecx, dword [ebp + 8] *)
|
|
|
|
0CDH, 040H, (* int 64 *)
|
|
|
|
08BH, 04DH, 00CH, (* mov ecx, dword [ebp + 12] *)
|
|
|
|
089H, 011H, (* mov dword [ecx], edx *)
|
|
|
|
05BH, (* pop ebx *)
|
|
|
|
0C9H, (* leave *)
|
|
|
|
0C2H, 008H, 000H (* ret 8 *)
|
|
|
|
)
|
|
|
|
RETURN 0
|
2019-09-26 22:23:06 +02:00
|
|
|
END f_68_27;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Load* (FName: ARRAY OF CHAR; VAR size: INTEGER): INTEGER;
|
|
|
|
RETURN f_68_27(sys.ADR(FName[0]), size)
|
2016-10-24 01:30:27 +02:00
|
|
|
END Load;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE GetFileInfo* (FName: ARRAY OF CHAR; VAR Info: rFD): BOOLEAN;
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
res2: INTEGER; fs: rFS;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
fs.subfunc := 5;
|
|
|
|
fs.pos := 0;
|
|
|
|
fs.hpos := 0;
|
|
|
|
fs.bytes := 0;
|
|
|
|
fs.buffer := sys.ADR(Info);
|
|
|
|
COPY(FName, fs.name)
|
|
|
|
|
|
|
|
RETURN KOSAPI.sysfunc22(70, sys.ADR(fs), res2) = 0
|
2019-09-26 22:23:06 +02:00
|
|
|
END GetFileInfo;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Exists* (FName: ARRAY OF CHAR): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
fd: rFD;
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
RETURN GetFileInfo(FName, fd) & ~(4 IN BITS(fd.attr))
|
2016-10-24 01:30:27 +02:00
|
|
|
END Exists;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE Close* (VAR F: FS);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF F # NIL THEN
|
|
|
|
DISPOSE(F)
|
|
|
|
END
|
2016-10-24 01:30:27 +02:00
|
|
|
END Close;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE Open* (FName: ARRAY OF CHAR): FS;
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
F: FS;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF Exists(FName) THEN
|
|
|
|
NEW(F);
|
|
|
|
IF F # NIL THEN
|
|
|
|
F.subfunc := 0;
|
|
|
|
F.pos := 0;
|
|
|
|
F.hpos := 0;
|
|
|
|
F.bytes := 0;
|
|
|
|
F.buffer := 0;
|
|
|
|
COPY(FName, F.name)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
F := NIL
|
2016-10-24 01:30:27 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN F
|
2019-09-26 22:23:06 +02:00
|
|
|
END Open;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Delete* (FName: ARRAY OF CHAR): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
F: FS;
|
|
|
|
res, res2: INTEGER;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF Exists(FName) THEN
|
|
|
|
NEW(F);
|
|
|
|
IF F # NIL THEN
|
|
|
|
F.subfunc := 8;
|
|
|
|
F.pos := 0;
|
|
|
|
F.hpos := 0;
|
|
|
|
F.bytes := 0;
|
|
|
|
F.buffer := 0;
|
|
|
|
COPY(FName, F.name);
|
|
|
|
res := KOSAPI.sysfunc22(70, sys.ADR(F^), res2);
|
|
|
|
DISPOSE(F)
|
|
|
|
ELSE
|
|
|
|
res := -1
|
|
|
|
END
|
2016-10-24 01:30:27 +02:00
|
|
|
ELSE
|
2019-03-11 09:59:55 +01:00
|
|
|
res := -1
|
2016-10-24 01:30:27 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN res = 0
|
2016-10-24 01:30:27 +02:00
|
|
|
END Delete;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE Seek* (F: FS; Offset, Origin: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
|
|
|
fd: rFD;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF (F # NIL) & GetFileInfo(F.name, fd) & (BITS(fd.attr) * {4} = {}) THEN
|
|
|
|
CASE Origin OF
|
|
|
|
|SEEK_BEG: F.pos := Offset
|
|
|
|
|SEEK_CUR: F.pos := F.pos + Offset
|
|
|
|
|SEEK_END: F.pos := fd.size + Offset
|
|
|
|
ELSE
|
|
|
|
END;
|
|
|
|
res := F.pos
|
2016-10-24 01:30:27 +02:00
|
|
|
ELSE
|
2019-03-11 09:59:55 +01:00
|
|
|
res := -1
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
2016-10-24 01:30:27 +02:00
|
|
|
END Seek;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE Read* (F: FS; Buffer, Count: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
res, res2: INTEGER;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF F # NIL THEN
|
|
|
|
F.subfunc := 0;
|
|
|
|
F.bytes := Count;
|
|
|
|
F.buffer := Buffer;
|
|
|
|
res := KOSAPI.sysfunc22(70, sys.ADR(F^), res2);
|
|
|
|
IF res2 > 0 THEN
|
|
|
|
F.pos := F.pos + res2
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
res2 := 0
|
2016-10-24 01:30:27 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN res2
|
2019-09-26 22:23:06 +02:00
|
|
|
END Read;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Write* (F: FS; Buffer, Count: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
res, res2: INTEGER;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF F # NIL THEN
|
|
|
|
F.subfunc := 3;
|
|
|
|
F.bytes := Count;
|
|
|
|
F.buffer := Buffer;
|
|
|
|
res := KOSAPI.sysfunc22(70, sys.ADR(F^), res2);
|
|
|
|
IF res2 > 0 THEN
|
|
|
|
F.pos := F.pos + res2
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
res2 := 0
|
2016-10-24 01:30:27 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN res2
|
2016-10-24 01:30:27 +02:00
|
|
|
END Write;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE Create* (FName: ARRAY OF CHAR): FS;
|
|
|
|
VAR
|
|
|
|
F: FS;
|
|
|
|
res2: INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
NEW(F);
|
|
|
|
|
|
|
|
IF F # NIL THEN
|
|
|
|
F.subfunc := 2;
|
|
|
|
F.pos := 0;
|
|
|
|
F.hpos := 0;
|
|
|
|
F.bytes := 0;
|
|
|
|
F.buffer := 0;
|
|
|
|
COPY(FName, F.name);
|
|
|
|
IF KOSAPI.sysfunc22(70, sys.ADR(F^), res2) # 0 THEN
|
|
|
|
DISPOSE(F)
|
|
|
|
END
|
2016-10-24 01:30:27 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN F
|
2016-10-24 01:30:27 +02:00
|
|
|
END Create;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE DirExists* (FName: ARRAY OF CHAR): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
fd: rFD;
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
RETURN GetFileInfo(FName, fd) & (4 IN BITS(fd.attr))
|
2019-09-26 22:23:06 +02:00
|
|
|
END DirExists;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE CreateDir* (DirName: ARRAY OF CHAR): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
F: FS;
|
|
|
|
res, res2: INTEGER;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
|
|
|
NEW(F);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
IF F # NIL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
F.subfunc := 9;
|
|
|
|
F.pos := 0;
|
|
|
|
F.hpos := 0;
|
|
|
|
F.bytes := 0;
|
|
|
|
F.buffer := 0;
|
|
|
|
COPY(DirName, F.name);
|
|
|
|
res := KOSAPI.sysfunc22(70, sys.ADR(F^), res2);
|
|
|
|
DISPOSE(F)
|
|
|
|
ELSE
|
|
|
|
res := -1
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res = 0
|
|
|
|
END CreateDir;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE DeleteDir* (DirName: ARRAY OF CHAR): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
F: FS;
|
|
|
|
res, res2: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
IF DirExists(DirName) THEN
|
|
|
|
NEW(F);
|
|
|
|
IF F # NIL THEN
|
|
|
|
F.subfunc := 8;
|
|
|
|
F.pos := 0;
|
|
|
|
F.hpos := 0;
|
|
|
|
F.bytes := 0;
|
|
|
|
F.buffer := 0;
|
|
|
|
COPY(DirName, F.name);
|
|
|
|
res := KOSAPI.sysfunc22(70, sys.ADR(F^), res2);
|
|
|
|
DISPOSE(F)
|
|
|
|
ELSE
|
|
|
|
res := -1
|
|
|
|
END
|
2016-10-24 01:30:27 +02:00
|
|
|
ELSE
|
2019-03-11 09:59:55 +01:00
|
|
|
res := -1
|
2016-10-24 01:30:27 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN res = 0
|
2016-10-24 01:30:27 +02:00
|
|
|
END DeleteDir;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
END File.
|