Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 25
Relative-File Programming Example
! Loop reading and displaying records until user declines
! to read next record (any response other than "y"):
DO BEGIN
PRINT^BLANK;
! Read a record from the log file and display
! it on the terminal. If end-of-file is reached,
! return control to LOGGER procedure:
CALL READX(LOGNUM,SBUFFER,BUFSIZE,COUNT^READ);
IF <> THEN
BEGIN
CALL FILE_GETINFO_(LOGNUM,ERROR);
IF ERROR = 1 THEN
BEGIN
PRINT^STR("No such record");
RETURN;
END;
CALL FILE^ERRORS(LOGNUM);
END;
CALL WRITE^LINE(SBUFFER,COUNT^READ);
PRINT^BLANK;
! Prompt the user to read the next record (user
! must respond "y" to accept, otherwise return
! 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;