Guardian Programmer's Guide

Table Of Contents
Using Nowait Input/Output
Guardian Programmer’s Guide 421922-014
4 - 19
Nowait I/O: An Example
!------------------------------------------------------------
! Procedure for reading records. The user selected function
! "r." The start of the read is selected randomly by record
! number. The user has the option of sequentially reading
! subsequent messages.
!------------------------------------------------------------
PROC READ^RECORD;
BEGIN
INT COUNT^READ;
INT ERROR;
! Position current-record and next-record pointers to the
! beginning of the file:
CALL POSITION(LOGNUM, 0D);
IF <> THEN CALL FILE^ERRORS(LOGNUM);
! 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. Print "No Such Record" if end of file
! reached:
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;