Previous

10.3.1.6. Layout routines

{

aa) A book input from an external medium by some system-task may contain lines and pages not all of the same length. Contrariwise, the lines and pages of a book which has been established {10.3.1.4.cc } are all initially of the size specified by the user. However if, during output to a compressible book {10.3.1.3.ff }, newline (newpage) is called with the current position in the same line (page) as the logical end of the book, then that line (the page containing that line) is shortened to the character number (line number) of the logical end. Thus print(("abcde", newline)) could cause the current line to be reduced to 5 characters in length. Note that it is perfectly meaningful for a line to contain no characters and for a page to contain no lines.

Although the effect of a channel whose books are both compressible and of random access {10.3.1.3.ff } is well defined, it is not anticipated that such a combination is likely to occur in actual implementations.

bb) The routines space {a}, newline {c}and newpage {d}serve to advance the current position to the next character, line or page, respectively. They do not, however, (except as provided in cc below) alter the contents of the positions skipped over. Thus print(("a", backspace, space)) has a different effect from print(("a", backspace, blank)).

The current position may be altered also by calls of backspace {b}, set char number {k} and, on appropriate channels, of set {i}and reset {j}.

cc) The contents of a newly established book are undefined and both its current position and its logical end are at (1, 1, 1). As output proceeds, it is filled with characters and the logical end is moved forward accordingly. If, during character output with the current position at the logical end of the book, space is called, then a space character is written (similar action being taken in the case of newline and newpage if the book is not compressible).

A call of set which attempts to leave the current position heyond the logical end results in a call of undefined (a sensible system action might then be to advance the logical end to the current position, or even to the physical end of the book). There is thus no defined way in which the current position can be made to be beyond the logical end, nor in which any character within the logical file can remain in its initial undefined state.

dd) A reading or writing operation, or a call of space, newline, newpage, set or set char number, may bring the current position outside the physical or logical file {10.3.1.5.cc, dd }, but this does not have any immediate consequence. However, before any further transput is attempted, or a further call of space, newline or newpage (but not of set or set char number) is made, the current position must be brought to a "good" position. The file is "good" if, on writing (reading), the current position is not outside the physical (logical) file {10.3.1.5.cc, dd }. The page (line) is "good" if the line number (character number) has not overflowed. The event routine {10.3.1.3.cc } corresponding to on logical file end, on physical file end, on page end or on line end is therefore called as appropriate. Except in the case of formatted transput (which uses check pos, 10.3.3.2.c ), the default action, if the event routine returns false, is to call, respectively, undefined, undefined, newpage or newline. After this (or if true is returned), if the position is still not good, an event routine (not necessarily the same one) is called again.

ee) The state of the file {10.3.1.3.bb } controls some effects of the layout routines. If the read/write mood is reading, the effect of space, newline and newpage, upon attempting to pass the logical end, is to call the event routine corresponding to on logical file end with default action undefined; if it is writing, the effect is to output spaces (or, in bin mood, to write some undefined character) or to compress the current line or page (see cc). If the read/write mood is not determined on entry to a layout routine, undefined is called. On exit, the read/write mood present on entry is restored.}

a) PROC space = (REF FILE f)VOID: IF opened OF f THEN undefined ELSE BOOL reading = (read mood OF f | TRUE |: write mood OF f | FALSE## | undefined; SKIP); ( get good line(f, reading) | undefined); REF POS cpos = cpos OF f; IF reading THEN c OF cpos +:= 1 ELSE IF logical file ended(f)THEN IF bin mood OF f THEN (text OF f | (FLEXTEXT t2): t2[p OF cpos] [l OF cpos] [c OF cpos] := SKIP); c OF pos +:= 1; lpos OF book OF f := cpos ELSE put char(f, "") FI ELSE c OF cpos +:= 1 FI FI FI ;

b) PROC backspace = (REF FILE f)VOID: IF opened OF f THEN undefined ELSE REF INT c = c OF cpos OF f; (c>1 | c-:= 1 | undefined) FI;

c) PROC newline = (REF FILE f)VOID: IF opened OF f THEN undefined ELSE BOOL reading = (read mood OF f | TRUE |: write mood OF f | FALSE## | undefined; SKIP); ( get good page(f, reading) | undefined); REF POS cpos = cpos OF f, lpos = lpos OF book OF f; IF p OF cpos = p OF lpos l OF cpos = l OF lpos THEN c OF cpos := c OF lpos; IF reading THEN newline(f) ELSE IF compressible(f) THEN REF INT pl = p OF lpos, ll = l OF lpos; FLEXTEXT text = (text OF f | (FLEXTEXT t2): t2); text [pl] [ll] text [pl] [ll] [ : c OF lpos - 1] ELSE WHILE line ended(f) DO space(f) OD FI; cpos := lpos := (p OF cpos, l OF cpos + 1, 1) FI ELSE cpos := (p OF cpos, l OF cpos + 1, 1) FI FI;

d) PROC newpage = (REF FILE f)VOID: IF opened OF f THEN undefined ELSE BOOL reading = (read mood OF f) | TRUE |: write mood OF f | FALSE## | undefined; SKIP); ( get good file(f, reading) | undefined); REF POS cpos = cpos OF f, lpos = lpos OF book OF f; IF p OF cpos = p OF lpos THEN cpos := lpos; IF reading THEN newpage(f) ELSE IF compressible(f) l OF lpos <= l OF book bounds(f) THEN REF INT pl = p OF lpos, ll = l OF lpos; FLEXTEXT text = (text OF f | (FLEXTEXT t2): t2); text[pl] [ll] text [pl] [ll]t: c OF lpos - 1]; text [pl] := text [pl] [ : (c OF lpos> 1 | ll | ll - 1)] ELSE WHILE page ended(f) DO newline(f) OD FI; cpos := lpos := (p OF cpos + 1, 1, 1) FI ELSE cpos := (p OF cpos + 1, 1, 1) FI FI;

{Each of the following 3 routines either returns true, in which case the line, page or file is good {dd }, or it returns false, in which case the current position may be outside the logical file or the page number may have overflowed, or it loops until the matter is resolved, or it is terminated by a jump. On exit, the read/write mood is as determined by its reading parameter.}

e) PROC {?}get good line = (REF FILE f, BOOL reading)BOOL: BEGIN BOOL not ended; WHILE not ended := get good page(f, reading); line ended(f) not ended DO ( (line mended OF f)(f) | set mood(f, reading); newline(f)) OD; not ended END;

f) PROC {?}get good page = (REF FILE f, BOOL reading)BOOL: BEGIN BOOL not ended; WHILE not ended := get good file(f, reading); page ended(f) not ended DO ( (page mended OF f)(f) | set mood(f, reading); newpage(f)) OD; not ended END;

g) PROC {?}get good file = (REF FILE f, BOOL reading) BOOL: BEGIN BOOL not ended := TRUE; WHILE set mood(f, reading); not ended (reading | logical file ended | physical file ended)(f) DO not ended := (reading | logical file mended OF f## | physical file mended OF f)(f) OD; not ended END;

h) PROC {?}set mood = (REF FILE f, BOOL reading)VOID: (reading | set read mood(f) | set write mood(f));

i) PROC set = (REF FILE f, INT p, l, c)VOID: IF opened OF f ¦ get possible(f) THEN undefined ELSE BOOL reading = (read mood OF f | TRUE |: write mood OF f | FALSE undefined; SKIP); REF POS cpos = cpos OF f, lpos = lpos OF book OF f; POS ccpos = cpos; IF (cpos := (p, l, c)) BEYOND lpos THEN cpos := lpos; ( (logical file mended OF f)(f) | undefined); set mood(f, reading) ELIF POS bounds = book bounds(f); p < 1 ¦ p > p OF bounds + 1 ¦ l < 1 ¦ l > l OF bounds + 1 ¦ c < 1 ¦ c > c OF bounds + 1 THEN cpos := ccpos; undefined FI FI;

j) PROC reset = (REF FILE f)VOID: IF opened OF f ¦ reset possible(f) THEN undefined ELSE REF BOOL (read mood OF f):= put possible(f); REF BOOL (write mood OF f) := get possible(f); REF BOOL (char mood OF f) := bin possible(f); REF BOOL (bin mood OF f) := FALSE; REF POS (cpos OF f) := (1, 1, 1) FI;

k) PROC set char number = (REF FILE f, INT c)VOID: IF opened OF f THEN undefined ELSE REF REF POS cpos = cpos OF f; WHILE c OF cpos /= c DO IF c < 1 ¦ c > c OF book bounds(f) + 1 THEN undefined ELIF c > c OF cpos THEN space(f) ELSE backspace(f) FI END FI;



 
Next