DEFINITION MODULE Directories;

(* (C) Copyright 1987 Fitted Software Tools. All rights reserved. *)


TYPE DirEntry = RECORD
                  name      :ARRAY [0..65] OF CHAR;
                  attribute :BITSET;
                  time      :CARDINAL;
                  date      :CARDINAL;
                  size      :LONGCARD;
                END;

CONST  (* directory entry attributes bits *)
    NORMAL      = {};
    READONLY    = {0};
    HIDDEN      = {1};
    SYSTEM      = {2};
    DIRECTORY   = {4};
    ARCHIVE     = {5};


(* === Low level directory access === *)

PROCEDURE GetFirstDir( Path :ARRAY OF CHAR; Attribute :BITSET;
                       VAR Dir :DirEntry; VAR ok :BOOLEAN );
(*
    on return:
    IF ok THEN
        Dir is the first directory entry that matches Path & Attribute
    END;
*)

PROCEDURE GetNextDir( VAR Dir :DirEntry; VAR ok :BOOLEAN );
(*
    on return:
    IF ok THEN
        Dir is the next directory entry to match the Path and Attribute
        of the last GetFirstDir or GetNextDir.
    END;
*)


(* === High level directory access === *)

TYPE QueryProc = PROCEDURE( DirEntry );

PROCEDURE DirQuery( path :ARRAY OF CHAR; attributes :BITSET; p :QueryProc );
(*
    invokes p for every directory entry that matches path and attributes,
    passing along the directory entry.
*)


(* === Directory manipulation procedures === *)

VAR DirStatus   :CARDINAL;      (* DOS status after last procedure call *)

(*
    in the following procedures, fileName and dirName are any valid
    path name, including a drive specification if so desired.
*)

PROCEDURE MkDir( dirName :ARRAY OF CHAR );
(*
    make a new directory
*)

PROCEDURE RmDir( dirName :ARRAY OF CHAR );
(*
    remove directory dirName
*)

PROCEDURE ChDir( dirName :ARRAY OF CHAR );
(*
    change the current directory to dirName
*)

PROCEDURE GetFileAttr( fileName :ARRAY OF CHAR; VAR attr :BITSET );
(*
    get the attribute bits for file fileName
*)

PROCEDURE SetFileAttr( fileName :ARRAY OF CHAR; attr :BITSET );
(*
    set the file attribute bits
*)

PROCEDURE GetCurDir( drive :CARDINAL; VAR curDir :ARRAY OF CHAR );
(*
    get the current directory for the specified drive, where:
      drive = 0     - current drive
            = 1     - drive A
            = 2     - drive B
            ...
*)

PROCEDURE Delete( fileName :ARRAY OF CHAR );
(*
    delete the file fileName
*)

PROCEDURE Rename( oldName, newName :ARRAY OF CHAR );
(*
    rename the file oldName as newName.

    Rename may be used to move a file to another directory in the
    same drive.
*)

PROCEDURE GetFileTime( fileName :ARRAY OF CHAR; VAR time :LONGCARD );
(*
    returns in time the date and time of last modification of the file
    fileName.

    time DIV 65536L = date of last modification
    time MOD 65536L = time of last modification

*)
PROCEDURE SetFileTime( fileName :ARRAY OF CHAR; time :LONGCARD );
(*
    Sets the file's modification date and time.
*)

PROCEDURE ASCIIZ( VAR src, dest :ARRAY OF CHAR );
(*
    converts the string src into a null terminated string in dest.
    used by procedures from Files.
*)

END Directories.