Previous

10.3.1.5. Position enquiries

{

aa) The "current position" of a book opened on a given file is the value referred to by the cpos field of that file. It is advanced by each transput operation in accordance with the number of characters written or read.

If c is the current character number and lb is the length of the current line, then at all times 1 <= c <= lb + 1. c = 1 implies that the next transput operation will be to the first character of the line and c = lb + 1 implies that the line has overflowed and that the next transput operation will call an event routine. If lb = 0, then the line is empty and is therefore always in the overflowed state. Corresponding restrictions apply to the current line and page numbers. Note that, if the page has overflowed, the current line is empty and, if the book has overflowed, the current page and line are both empty {e}.

bb) The user may determine the current position by means of the routines char number, line number and page number (a, b, c).

cc) If the current position has overflowed the line, page or book, then it is said to be outside the "physical file" (f, g, h).

dd) If, on reading, the current position is at the logical end, then it is said to be outside the "logical file" {i}.} {Each routine in this section calls undefined if the file is not open on entry.}

a) PROC char number = (REF FILE f)INT:## (opened OF f | c OF cpos OF f | undefined);

b) PROC line number = (REF FILE f)INT:## (opened OF f | l OF cpos OF f | undefined);

c) PROC page number = (REF FILE f)INT:## (opened OF f | p OF cpos OF f | undefined);

d) PROC {?}current pos = (REF FILE f)POS:## (opened OF f | cpos OF f | undefined; SKIP);

e) PROC {?}book bounds = (REF FILE f)POS: BEGIN POS cpos = current pos(f); INT p = p OF cpos, l = l OF cpos; CASE text OF f IN (TEXT t1): (INT pb = UPB t1; INT lb = (p <= 0 ¦ p>pb | 0 | UPB t1 [p]); INT cb = (l <= 0 ¦ l>lb | 0 | UPB t1[p][l]); (pb, lb, cb)), (FLEXTEXT t2): (INT pb = UPB t2; INT lb = (p <= 0 ¦ p>pb | 0 UPB t2[p]); INT cb = (l <= 0 ¦ l>lb | 0 | UPB t2[p] [I]); (pb, lb, cb)) ESAC END;

f) PROC {?}line ended = (REF FILE f)BOOL:## (INT c = c OF current pos(f); c > c OF book bounds(f));

g) PROC {?}page ended = (REF FILE f)BOOL:## (INT l = l OF current pos(f); l > l OF book bounds(f));

h) PROC {?}physical file ended = (REF FILE f)BOOL:## (INT p = p OF current pos(f); p > p OF book bounds(f));

i) PROC {?}logical file ended = (REF FILE f)BOOL:## (lpos OF book OF f BEYOND current pos(f));



 
Next