home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
oberon-a-1.4ß.lha
/
Oberon-A
/
source
/
amigautil
/
DosUtil.mod
< prev
next >
Wrap
Text File
|
1994-09-03
|
3KB
|
114 lines
(***************************************************************************
$RCSfile: DosUtil.mod $
Description: Support for clients of dos.library
Created by: fjc (Frank Copeland)
$Revision: 3.3 $
$Author: fjc $
$Date: 1994/09/03 16:08:43 $
Copyright © 1994, Frank Copeland.
This file is part of the Oberon-A Library.
See Oberon-A.doc for conditions of use and distribution.
***************************************************************************)
MODULE DosUtil;
(*
** $C= CaseChk $I= IndexChk $L+ LongAdr $N= NilChk
** $P- PortableCode $R= RangeChk $S= StackChk $T= TypeChk
** $V= OvflChk $Z= ZeroVars
*)
IMPORT Exec, Dos, Str := Strings;
CONST (* Returned by ObjectExists() *)
no *= 0;
file *= 1;
dir *= 2;
other *= 3;
(*------------------------------------*)
PROCEDURE ObjectExists * ( path : ARRAY OF CHAR ) : INTEGER;
VAR
lock : Dos.FileLockPtr;
fib : Dos.FileInfoBlockPtr;
result : INTEGER;
(* len : LONGINT; *)
(* $D- disable copying of open arrays *)
BEGIN (* ObjectExists *)
result := no;
(* len := Str.Length (path); *)
(* IF path [len - 1] = "/" THEN path [len - 1] := 0X END; *)
lock := Dos.base.Lock (path, Dos.sharedLock);
IF lock # NIL THEN
fib := Dos.base.AllocDosObjectTags (Dos.fib, NIL);
IF fib # NIL THEN
IF Dos.base.Examine (lock, fib^) THEN
IF fib.dirEntryType < 0 THEN result := file
ELSIF fib.dirEntryType > 0 THEN result := dir
ELSE result := other
END
END;
Dos.base.FreeDosObject (Dos.fib, fib)
END;
Dos.base.UnLock (lock)
END;
RETURN result
END ObjectExists;
(*------------------------------------*)
PROCEDURE FileExists * (path : ARRAY OF CHAR) : BOOLEAN;
(* $D- disable copying of open arrays *)
BEGIN (* FileExists *)
RETURN (ObjectExists (path) = file)
END FileExists;
(*------------------------------------*)
PROCEDURE DirExists * (path : ARRAY OF CHAR) : BOOLEAN;
(* $D- disable copying of open arrays *)
BEGIN (* DirExists *)
RETURN (ObjectExists (path) = dir)
END DirExists;
(*------------------------------------*)
(*
Searches for "file" in the current directory first, followed by the
directories listed in "paths". If it is found the procedure returns TRUE
and the full pathname of the file is returned in "fullPath". If not, the
procedure returns FALSE and fullPath is set to "".
*)
PROCEDURE Search *
( VAR paths : ARRAY OF Exec.STRPTR;
file : ARRAY OF CHAR;
VAR fullPath : ARRAY OF CHAR)
: BOOLEAN;
VAR index : INTEGER; len : LONGINT; ch : CHAR;
(* $D- disable copying of open arrays *)
BEGIN (* Search *)
fullPath [0] := 0X; index := 0;
LOOP
IF ~Dos.base.AddPart (fullPath, file, LEN (fullPath)) THEN
RETURN FALSE
END;
IF FileExists (fullPath) THEN RETURN TRUE END;
IF paths [index] = NIL THEN
fullPath [0] := 0X; RETURN FALSE
ELSE
COPY (paths [index]^, fullPath); INC (index)
END
END
END Search;
END DosUtil.