Enscribe Programmer's Guide
If the file is an odd unstructured file, both the number of bytes transferred and the amount by which
the pointers are incremented are exactly the number of bytes specified by the write count or read
count parameter. If the file is an even unstructured file, the values of the write count and read count
parameters are rounded up to an even number before the transfer takes place and the file pointers
are incremented by the rounded-up value.
Example:
This sequence of system procedure calls illustrates how the file pointers are used when sequentially
accessing an unstructured disk file; the example assumes that these are the first operations after
the file is opened:
CALL READ ( filenum, buffer, 512 );
CALL READ ( filenum, buffer, 512 );
CALL WRITEUPDATE ( filenum, buffer, 512 );
CALL READ ( filenum, buffer, 512 );
The first READ transfers 512 bytes into the designated buffer starting at relative byte 0. Upon
completion of this READ operation, the next-record pointer points to relative byte 512 and the
current-record pointer points to relative byte 0.
The second READ transfers 512 bytes into the buffer starting at relative byte 512. Upon completion
of this READ operation, the next-record pointer points to relative byte 1024 and the current-record
pointer points to relative byte 512.
The WRITEUPDATE procedure then replaces the just-read data with new data in the same disk
location. The file system transfers 512 bytes from the buffer to the file at the position indicated by
the current-record pointer (relative byte 512). The next-record and current-record pointers are not
altered by the WRITEUPDATE operation.
The third READ transfers 512 bytes into the buffer starting at relative byte 1024 (the address in
the next-record pointer). Upon completion of this READ operation, the nextrecord pointer points to
relative byte 1536 and the current-record pointer points to relative byte 1024.
Encountering the EOF During Sequential Reading.
If you encounter the EOF boundary while reading an unstructured disk file, the data up to the EOF
location is transferred. A subsequent read request will return an EOF indication (condition code
CCG) because it is not permissible to read past the EOF location. If you do not alter the pointers
by using a FILE_SETPOSITION_ call, the EOF indication will be returned for every subsequent read
request.
For example, consider an unstructured file with the EOF location at relative byte 4096, as illustrated
in Figure 12 (page 66). Assume that an application program executes this sequence of 512-byte
reads starting at relative byte 0:
file^eof := 0;
WHILE NOT file^eof DO
BEGIN
CALL READ ( filenum, buffer, 512, num^read, .. );
IF > THEN file^eof := 1
ELSE
IF = THEN
BEGIN
...process the data...
END
ELSE ... ! error
END;
Accessing Unstructured Files 65