DEFINITION MODULE GfileManager;
(*
This module provides routines to do WORD oriented IO to files. The file
is fixed length file with 512 bytes per record. Files must be closed to
make changes permanent.
*)

FROM SYSTEM IMPORT WORD;
FROM FileSystem IMPORT File;

EXPORT QUALIFIED CreateGfile, OpenGfile, GetW, GetWords, 
                 PutW, PutWords, CloseGfile;

PROCEDURE CreateGfile( 
    VAR Gfile  : File          (* out *) ;
        Gfname : ARRAY OF CHAR (* in *) ) : BOOLEAN;
    (*
    Create and open Gfname for writing. Return true if successful.
    *)
PROCEDURE OpenGfile( 
    VAR Gfile  : File          (* out *);
    Gfname     : ARRAY OF CHAR (* in *);
    ReadOnly   : BOOLEAN       (* in *) ) : BOOLEAN;
    (*
    Open an existing Gfile. The parameter ReadOnly can be true or
    false. value returned is true if successful.
    *)
PROCEDURE PutW( 
    VAR Gfile : File (* in/out *);
        Arg   : WORD (* in     *) ) : BOOLEAN;
    (*
    Put a word on Gfile. Return true if OK.
    *)
PROCEDURE PutWords( 
    VAR Gfile : File (* in/out *);
        Arg   : ARRAY OF WORD (* in *);
        wc    : CARDINAL (* in *) ) : BOOLEAN;
    (*
    Put an array of words to Gfile. Return true if OK.
    *)
PROCEDURE GetW(
    VAR Gfile  : File  (* in/out *);
    VAR AWord  : WORD  (* out    *) ): BOOLEAN;
    (*
    Read a word from Gfile at the current positions. Errors or EOF indicated
    by a RETURN of FALSE.
    *)
PROCEDURE GetWords(
    VAR Gfile : File (* in/out *);
    VAR Words : ARRAY OF WORD (* out *);
        Wcnt  : CARDINAL (* in *) ) : BOOLEAN;
    (*
    Get "wcnt" number of words from Gfile.
    *)
PROCEDURE CloseGfile(
    VAR Gfile : File (* in/out *) ) : BOOLEAN;
    (*
    Close file. Make sure that there is nothing pending in WBuffer. If
    so, flush it.
    *)

END GfileManager.
