Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 26
Relative-File Programming Example
!------------------------------------------------------------
! Procedure for updating a record. The user selected
! function "u." The user is prompted for the record number
! to update. The procedure displays the current contents and
! prompts for the new. After the user enters the new
! contents, the procedure updates the log file.
!------------------------------------------------------------
PROC UPDATE^RECORD;
BEGIN
INT COUNT^READ;
INT(32) RECORD^NUM;
STRING .EXT NEXT^ADR;
INT STATUS;
INT ERROR;
! Prompt the user to select a record:
PROMPT^AGAIN:
PRINT^BLANK;
SBUFFER ':=' "Enter Record Number: " -> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
SBUFFER[COUNT^READ] := 0;
! Convert ASCII to numeric:
@NEXT^ADR := DNUMIN(SBUFFER,RECORD^NUM,10,STATUS);
IF STATUS OR @NEXT^ADR <> $XADR(SBUFFER[COUNT^READ]) THEN
BEGIN
PRINT^STR("Error in the record number");
GOTO PROMPT^AGAIN;
END;
! Position current-record and next-record pointers to
! selected record:
CALL POSITION(LOGNUM,RECORD^NUM);
IF <> THEN CALL FILE^ERRORS(LOGNUM);
! Read the record without moving the current-record and
! next-record pointers. If end-of-file is reported,
! return to LOGGER:
CALL READUPDATEX(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;