DEFINITION MODULE BuildNDX;

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

CONST
   (* 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 index file.                     *)
   ErrClose  = 2;       (*   Unable to close index file.                    *)
   ErrRead   = 3;       (*   Unable to read index page/data.                *)
   ErrWrite  = 4;       (*   Unable to write index page/data.               *)
   ErrSeek   = 5;       (*   Unable to seek to index page/data.             *)
   ErrLock   = 6;       (*   Unable to lock index page/file.                *)
   ErrUnLock = 7;       (*   Unable to unlock index page/file.              *)
   ErrHandle = 8;       (*   Bad file handle (file probably not opened).    *)
   ErrMemory = 9;       (*   Not enough memory for index/page buffers.      *)
   ErrCreate = 10;      (*   Unable to create index file.                   *)
   ErrPageNo = 100;     (*   Invalid page number.                           *)
   ErrBadNDX = 102;     (*   File not NDX or NDX damaged.                   *)
   ErrLockedNDX = 103;  (*   NDX file locked by another application.        *)
   ErrBadField  = 104;  (*   Invalid field specified.                       *)

TYPE
    FilterType = PROCEDURE() : BOOLEAN;
    KeyExpType = PROCEDURE(VAR ARRAY OF CHAR);

VAR 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 *)
    Filter : FilterType;
    KeyExp : KeyExpType;

PROCEDURE MakeNDX(DBFName : ARRAY OF CHAR;      (* DBF file name.       *)
                  NDXName : ARRAY OF CHAR;      (* NDX file name.       *)
                  KeyName : ARRAY OF CHAR;      (* dBase key expression *)
                  KeyLen  : CARDINAL);          (* length of key field  *)

PROCEDURE Deleted () : BOOLEAN;                 (* TRUE if rec deleted  *)
PROCEDURE GetField (FieldName : ARRAY OF CHAR;  (* Gets field from data *)
                    VAR Field : ARRAY OF CHAR); (*   record.            *)

PROCEDURE DefaultFilter() : BOOLEAN;
PROCEDURE DefaultKeyExp(VAR Key : ARRAY OF CHAR);

END BuildNDX.