Guardian Programmer's Guide

Table Of Contents
Using the IOEdit Procedures
Guardian Programmer’s Guide 421922-014
14 - 14
Performing Sequential Writing
Typically, when you write lines to a file, you either append them to the end of the file or
insert them between existing lines in the file. The following paragraphs describe how
to perform these operations.
Appending to a File
To append new lines of text to the end of an EDIT file you must:
1. Position the next-record pointer to the end of the file.
2. Set the record increment to the desired value.
3. Issue repeated write operations, one for each line of text.
The record increment you set in Step 2 determines the difference in record numbers
between logically adjacent records as you add them to the file. For example, if the last
line in the file is line 60 (record 60000) and the record increment is 1000, then
successive records will have record numbers 61000, 62000, and so on.
The following example writes unpacked lines to the end of an EDIT file until the user
presses the F1 key. This example uses a record increment of 1000:
LITERAL LAST^RECORD = -2D,
F1 = ...;
RECORD^NUMBER := LAST^RECORD;
ERROR := POSITIONEDIT(FILE^NUM,RECORD^NUMBER);
IF ERROR > 0 THEN ...
!Set the record number increment:
DELTA := 1000D;
CALL INCREMENTEDIT(FILE^NUM,DELTA);
!Read text line from terminal:
BUFFER ':=' "> ";
WCOUNT := 2;
RCOUNT := 80;
CALL WRITEREAD(TERM^NUM,BUFFER,WCOUNT,RCOUNT,BYTES^READ);
!If not function key 1, write to end of file and read next
!line. Repeat until user presses F1:
WHILE FIRST^BYTE <> F1 DO !FIRST^BYTE is a bytes
BEGIN ! pointer to BUFFER
ERROR := WRITEEDIT(FILE^NUM,
!record^number!,
BUFFER,WCOUNT);
BUFFER ':=' "> ";
WCOUNT := 2;
CALL WRITEREAD(TERM^NUM,BUFFER,RCOUNT,BYTES^READ);
END;