DEFINITION MODULE NDX;        (* version 1.4 *)

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

CONST
   (* Constant values fixed for dBase compatibility                         *)
   MaxKeyLen = 100;     (* Maximum key string length = 100 chars            *)

   (* 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.      *)
   ErrPageNo = 100;     (*   Invalid page number.                           *)
   ErrBadNDX = 102;     (*   File not NDX or NDX damaged.                   *)
   ErrLockedNDX = 103;  (*   NDX file locked by another application.        *)

TYPE  NDXFile;          (*   Opaque NDX 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 AddKey   (I : NDXFile; Key : ARRAY OF CHAR; Ptr : LONGCARD);
PROCEDURE AddNKey  (I : NDXFile; NumKey : LONGREAL; Ptr : LONGCARD);
PROCEDURE BOF      (I : NDXFile) : BOOLEAN;
PROCEDURE CloseNDX (VAR I : NDXFile);
PROCEDURE CreateNDX(VAR I : NDXFile; FileName : ARRAY OF CHAR;
                    KeyField : ARRAY OF CHAR;
                    KeyType  : CHAR;
                    KeyLen   : CARDINAL);
PROCEDURE CurKey   (I : NDXFile; VAR Field : ARRAY OF CHAR);
PROCEDURE DelKey   (I : NDXFile);
PROCEDURE EOF      (I : NDXFile) : BOOLEAN;
PROCEDURE Find     (I : NDXFile; Key : ARRAY OF CHAR) : LONGCARD;
PROCEDURE FindNKey (I : NDXFile; Num : LONGREAL) : LONGCARD;
PROCEDURE FOUND    (I : NDXFile) : BOOLEAN;
PROCEDURE GoBottom (I : NDXFile);
PROCEDURE GoTop    (I : NDXFile);
PROCEDURE KeyField (I : NDXFile; VAR Field : ARRAY OF CHAR);
PROCEDURE Next     (I : NDXFile) : LONGCARD;
PROCEDURE OpenNDX  (VAR I : NDXFile; Name : ARRAY OF CHAR);
PROCEDURE Prev     (I : NDXFile) : LONGCARD;
PROCEDURE Unique   (I : NDXFile) : BOOLEAN;

END NDX.

