Guardian Programmer's Guide

Table Of Contents
Using the File System
Guardian Programmer’s Guide 421922-014
2 - 35
Accessing Files: An Example
! Prompt the user to read the next record. The user
! must respond "y" to accept, otherwise the procedure
! returns to select next function:
SBUFFER ':=' ["Do you want to read another ",
"record (y/n)? "]
-> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
SBUFFER[COUNT^READ] := 0;
END
UNTIL NOT (SBUFFER[0] = "y" OR SBUFFER[0] = "Y");
END;
!------------------------------------------------------------
! Procedure for appending a record. The user selected
! function "a." The user is prompted to enter comments. The
! procedure puts the comments in a new record at the end of
! the file.
!------------------------------------------------------------
PROC APPEND^RECORD;
BEGIN
INT COUNT^READ;
PRINT^BLANK;
! Prompt user for comments and read comments into the
! buffer:
SBUFFER ':=' "Enter today's comments: "
-> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
! Blank out portion of buffer past last character read:
SBUFFER[COUNT^READ] ':=' " " & SBUFFER[COUNT^READ]
FOR BUFSIZE-COUNT^READ BYTES;
! Place the next-record pointer at the end of file and
! write the new record there:
CALL POSITION (LOGNUM,-1D);
IF <> THEN CALL FILE^ERRORS(LOGNUM);
CALL WRITEX(LOGNUM,SBUFFER,BUFSIZE);
IF <> THEN CALL FILE^ERRORS(LOGNUM);
END;