Guardian Programmer's Guide

Table Of Contents
Using the File System
Guardian Programmer’s Guide 421922-014
2 - 34
Accessing Files: 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. Display "No such record"
! if reach end of file:
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;