Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 40
Entry-Sequenced File Programming Example
!-----------------------------------------------------------
! This procedure writes a message on the terminal and checks
! for any error. If there is an error, it attempts to write
! a message about the error and the program is stopped.
!-----------------------------------------------------------
PROC WRITE^LINE (BUF, LEN);
STRING .BUF;
INT LEN;
BEGIN
CALL WRITEX(TERMNUM,BUF,LEN);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
END;
!------------------------------------------------------------
! This procedure asks the user for the next function to do:
!
! "r" to read records
! "a" to append a record
! "x" to exit the program
!
! The selection made is returned as the result of the call.
!------------------------------------------------------------
INT PROC GET^COMMAND;
BEGIN
INT COUNT^READ;
! Prompt the user for the function to be performed:
PRINT^BLANK;
PRINT^STR("Type 'r' for Read Log, ");
PRINT^STR(" 'a' for Append to Log, ");
PRINT^STR(" 'x' for Exit. ");
PRINT^BLANK;
SBUFFER ':=' "Choice: " -> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
SBUFFER[COUNT^READ] := 0;
RETURN SBUFFER[0];
END;