DEFINITION MODULE DBF;

(**********************************************************************)
(* Copyright 1988,1989,1990,1991 by David Albert                      *)
(**********************************************************************)

CONST
   (* Constant values fixed for dBase compatibility                         *)
   MaxFields = 200;     (*   Max fields per record = 200                    *)
   MaxRecLen = 4000;    (*   Max record length = 4000 bytes                 *)

   (* 3 levels of error handling are provided - None, AskUser, Halt.        *)
   None      = 0;       (*   ErrCode & DosCode set on errors, nothing else  *)
   AskUser   = 1;       (*   ErrCode & DOSCode set, Error Dialog with user  *)
   Halt      = 2;       (*   Error Dialog indicating error source then HALT *)

   (* ErrCodes provide information about source of errors.                  *)
   ErrOpen   = 1;       (*   Unable to open data file.                      *)
   ErrClose  = 2;       (*   Unable to close data file.                     *)
   ErrRead   = 3;       (*   Unable to read record/file data.               *)
   ErrWrite  = 4;       (*   Unable to write record/file data.              *)
   ErrSeek   = 5;       (*   Unable to seek to record in file.              *)
   ErrLock   = 6;       (*   Unable to lock record/file.                    *)
   ErrUnLock = 7;       (*   Unable to unlock record/file.                  *)
   ErrHandle = 8;       (*   Bad file handle (file probably not opened).    *)
   ErrMemory = 9;       (*   Not enough memory for file/record buffers.     *)
   ErrRecNo  = 100;     (*   Invalid record number.                         *)
   ErrField  = 101;     (*   Invalid field specified.                       *)
   ErrBadDBF = 102;     (*   File not DBF or DBF damaged.                   *)
   ErrLockedDBF = 103;  (*   DBF file locked by another application.        *)

TYPE DBFile;            (*   Opaque DBF file type                           *)

VAR                                                              (* default *)
    MultiUser : BOOLEAN;           (* Multi-user mode                   OFF *)
    Safety    : BOOLEAN;           (* Safety mode                       OFF *)
    ErrCheck  : CARDINAL;          (* Error handling level          AskUser *)
    ErrCode   : CARDINAL;          (* Error return code                   0 *)
    DosCode   : CARDINAL;          (* DOS extended error code             0 *)

PROCEDURE AddRec    (D : DBFile);
PROCEDURE CloseDBF  (VAR D : DBFile);
PROCEDURE Deleted   (D : DBFile): BOOLEAN;
PROCEDURE DelRec    (D : DBFile);
PROCEDURE Encrypted (D : DBFile) : BOOLEAN;
PROCEDURE FieldData (D : DBFile; FieldName:ARRAY OF CHAR;
                     VAR Type     : CHAR;
                     VAR Len, Dec : CARDINAL);
PROCEDURE FieldName (D : DBFile; FieldNum : CARDINAL;
                     VAR FieldName : ARRAY OF CHAR);
PROCEDURE FileName  (D : DBFile; VAR Name : ARRAY OF CHAR);
PROCEDURE GetField  (D : DBFile; FieldName: ARRAY OF CHAR;
                     VAR TheField : ARRAY OF CHAR);
PROCEDURE GetRec    (D : DBFile; RecNum   : LONGCARD);
PROCEDURE GetRecBuf (D : DBFile; Buf      : ADDRESS);
PROCEDURE HasMDX    (D : DBFile) : BOOLEAN;
PROCEDURE Incomplete(D : DBFile) : BOOLEAN;
PROCEDURE LockRec   (D : DBFile; RecNum   : LONGCARD);
PROCEDURE NumFields (D : DBFile) : CARDINAL;
PROCEDURE OldField  (D : DBFile; FieldName: ARRAY OF CHAR;
                     VAR TheField : ARRAY OF CHAR);
PROCEDURE OpenDBF   (VAR D : DBFile; FileName : ARRAY OF CHAR);
PROCEDURE PutField  (D : DBFile; FieldName: ARRAY OF CHAR;
                     TheField : ARRAY OF CHAR);
PROCEDURE PutRec    (D : DBFile; RecNum   : LONGCARD);
PROCEDURE PutRecBuf (D : DBFile; Buf      : ADDRESS);
PROCEDURE RecChanged(D : DBFile) : BOOLEAN;
PROCEDURE RecCount  (D : DBFile) : LONGCARD;
PROCEDURE RecNo     (D : DBFile) : LONGCARD;
PROCEDURE RecSize   (D : DBFile) : CARDINAL;
PROCEDURE UnDelRec  (D : DBFile);
PROCEDURE UnLockRec (D : DBFile; RecNum   : LONGCARD);

END DBF.

