10.3.3. Formatless transput {In formatless transput, the elements of a "data list" are transput, one after the other, via a specified file. Each element of the data list is either a layout routine of the mode specified by PROC (REF FILE )VOID {10.3.1.6 } or a value of the mode specified by OUTTYPE (on output) or INTYPE (on input). On encountering a layout routine in the data list, that routine is called with the specified file as parameter. Other values in the data list are first straightened {10.3.2.3 } and the resulting values are then transput via the given file one after the other.
Transput normally takes place at the current position
but, if there is no room on the current line (on output) or if a readable
value is not present there (on input), then first, the event routine corresponding
to
on line end (or, where appropriate, to on page end,
on physical file end or
on logical file end) is called,
and next, if this returns false, the next "good" character position of
the book is found, viz., the first character position of the next nonempty
line.}
10.3.3.1. Formatless output {For formatless output, put (a) and print (or write) {10.5.1.d } may be used. Each straightened value V from the data list is output as follows:
aa) If the mode of V is specified by {L} INT , then first, if there is not enough room for {l} int width + 2 characters on the remainder of the current line, a good position is found on a subsequent line (see 10.3.3 ): next, when not at the beginning of a line, a space is given and then V is output as if under the control of the picture n({l} int width - 1)z + d.
bb) If the mode of V is specified by {L} REAL , then first, if there is not enough room for {l} real width + {l} exp width + 5 characters on the current line, then a good position is found on a subsequent line: next, when not at the beginning of a line, a space is given and then V is output as if under control of the picture
+d . n({l} real width - 1)den({l} exp width - 1)z +d.
cc) If the mode of V is specified by {L} COMPL , then first, if there is not enough room for 2 * ({l} real width + {l} exp width) + 11 characters on the current line, then a good position is found on a subsequent line: next, when not at the beginning of a line, a space is given and then V is output as if under control of the picture
+d.n({l} real width - 1)den({l} exp width - 1)z+d" "i +d.n({l} real width - 1)den({l} exp width - 1)z+d .
dd) If the mode of V is specified by BOOL, then first, if the current line is full, a good position is found on a subsequent line: next, if V is true (false), the character yielded by flip (flop) is output (with no intervening space).
ee) If the mode of V is specified by {L} BITS , then the elements of the only field of V are output (as in dd) one after the other (with no intervening spaces, and with new lines being taken as required),
ff) If the mode of V is specified by CHAR, then first, if the current line is full, a good position is found on a subsequent line: next V is output (with no intervening space).
gg) If the mode of V is specified by [ ] CHAR, then the elements of Vare output (as in ff) one after the other (with no intervening spaces, and with new lines being taken as required).}
a) PROC put = (REF FILE f, [ ] UNION(OUTTYPE, PROC(REF FILE )VOID) x)VOID: IF opened OF f THEN FOR i TO UPB x DO CASE set write mood(f); set char mood(f); x [i] IN (PROC(REF FILE )VOID pf): pf(f), (OUTTYPE ot): BEGIN [ ] SIMPLOUT y = STRAIGHTOUT ot; « PROC {l} real conv = ({L} REAL r)STRING: float(r, {l} real width + {l} exp width +4, {l} real width - 1, {l} exp width + 1)» ; FOR j TO UPB y DO CASE y[j] IN (UNION(NUMBER, « {L} COMPL » ) nc): BEGIN STRING s := CASE nc IN « ({L} INT k): whole(k, {l} int width + 1)» , « ({L} REAL r): {l} real conv(r)» , « ({L} COMPL z): {l} real conv(RE z) + " ^" +{l} real conv(IM z)» ESAC; REF REF POS cpos cpos OF f, INT n = UPB s; WHILE nextpos(f); (n > c OF book bounds(f) | undefined); c OF cpos + (c OF cpos = 1 | n | n+1)> c OF book bounds(f) + 1 DO ( (line mended OF f)(f) | put(f, newline)); set write mood(f) OD; (c OF cpos /= 1 | "," PLUSTO s); FOR k TO UPB s DO put char(f, s [k]) OD END # numeric # , (BOOL b): (next pos(f); put char(f, (b | flip | flop))), « ({L} BITS lb): FOR k TO {l} bits width DO put(f, ({l} {F}f of lb)[k]) OD» , (CHAR k): (nextpos(f); put char(f, k)), ([ ] CHAR ss): FOR k FROM LWB ss TO UPB ss DO next pos(f); put char(f, ss [k ]) OD ESAC OD END ESAC OD ELSE undefined FI;
b) PROC {?}put char = (REF FILE f, CHAR char)VOID: IF opened OF f line ended(f) THEN REF POS cpos = cpos OF f, lpos = lpos OF book OF f; set char mood(f); set write mood(f); REF INT p = p OF cpos, l = l OF cpos, c = c OF cpos; CHAR k; BOOL found := FALSE; CASE text OF f IN (TEXT): (k := char; found := TRUE), (FLEXTEXT): FOR i TO UPB {F}f OF conv OF f WHILE found DO STRUCT(CHAR internal, external) key = ({F}f OF conv OF f) [i]; (internal OF key = CHAR k := external OF key; found := TRUE)
OD
ESAC; IF found THEN CASE text OF f IN (TEXT t1): t1 [p] [l] [c] := k, (FLEXTEXT t2): t2[p] [l] [c] := k ESAC; c+:= 1; IF cpos BEYOND lpos THEN lpos := cpos ELIF set possible(f) POS(p OF lpos, l OF lpos, l) BEYOND cpos THEN lpos := cpos; (compressible(f) | © the size of the line and page containing the logical end of the book and of all subsequent lines and pages may be increased {e.g., to the sizes with which the book was originally established {10.3.1.4.cc } or to the sizes implied by maxpos OF chan OF f} ©) FI ELSE k := " "; IF (char error mended OF f)(f, k) THEN undefined; k := " " FI; check pos(f); put char(f, k) FI ELSE undefined FI # write mood is still set # ;
c) PROC {?}next pos = (REF FILE f)VOID: (get good
line(f, read mood OF f) | undefined) # the line is now good {10.3.1.6.dd
} and
the read/write mood is as on entry # ;
10.3.3.2. Formatless input {For formatless input, get (a) and read {10.5.1.e } may be used. Values from the book are assigned to each straightened name N from the data list as follows:
aa) If the mode of N is specified by REF {L} INT , then first, the book is searched for the first character that is not a space (finding good positions on subsequent lines as necessary); next, the largest string is read from the book that could be "indited" {10.3.4.1.1.kk } under the control of some picture of the form +n(k1)" "n(k2)dd or n(k2)dd (where k1 and k2 yield arbitrary nonnegative integers): this string is converted to an integer and assigned to N; if the conversion is unsuccessful, the event routine corresponding to on value error is called.
bb) If the mode of N is specified by REF {L} REAL , then first, the book is searched for the first character that is not a space (finding good positions on subsequent lines as necessary); next, the largest string is read from the book that could be indited under the control of some picture of the form + n(k1)" " n(k2)d or n(k2)d followed by .n(k3)d d or by ds., possibly followed again by e n(k4)" " + n(k,5)" " n(k6)d d or by e n(k5)" " n(k6)d d; this string is converted to a real number and assigned to N; if the conversion is unsuccessful, the event routine corresponding to on value error is called.
cc) If the mode of N is specified by REF {L} COMPL , then first, a real number is input (as in bb) and assigned to the first subname of N; next, the book is searched for the first character that is not a space; next, a character is input and, if it is not "^" or "i", then the event routine corresponding to on char error {10.3.1.3.cc } is called, the suggestion being "^"; finally, a real number is input and assigned to the second subname of N.
dd) If the mode of N is specified by REF BOOL, then first, the book is searched for the first character that is not a space (finding good positions on subsequent lines as necessary); next, a character is read: if this character is the same as that yielded by flip (flop), then true (false) is assigned to N; otherwise, the event routine corresponding to on char error is called, the suggestion being flop.
ee) If the mode of N is specified by REF {L} BITS , then input takes place (as in dd) to the subnames of N one after the other (with new lines being taken as required).
ff) If the mode of N is specified by REF CHAR, then first, if the current line is exhausted, a good position is found on a subsequent line; next, a character is read and assigned to N.
gg) If the mode of N is specified by REF [ ] CHAR, then input takes place (as in ff) to the subnames of N one after the other (with new lines being taken as required).
hh) If the mode of N is specified by REF STRING, then characters are read until either
a) PROC get = (REF FILE f, [ ] UNION(INTYPE, PROC(REF FILE )VOID) x)VOID: IF opened OF f THEN FOR i TO UPB x DO CASE set read mood(f); set char mood(f); x [i ] IN (PROC(REF FILE )VOID pf): pf(f), (INTYPE it): BEGIN [ ] SIMPLIN y = STRAIGHTIN it; CHAR k; BOOL k empty; OP ? = (STRING s)BOOL: # TRUE if the next character, if any, in the current line is contained in 's' (the character is assigned to 'k') and FALSE otherwise # IF k empty (line ended(f) ¦ logical file ended(f)) THEN FALSE ELSE (k empty get char(f, k)); k empty := char in string(k, LOC INT, s) FI; OP ? = (CHAR c)BOOL: ? STRING(c); PRIO ! = 8; OP ! = (STRING s, CHAR c)CHAR: # expects a character contained in 's'; if the character read is not in 's', the event routine corresponding to 'on char error' is called with the suggestion 'c' # IF (k empty | check pos(f); get char(f, k)); k empty := TRUE; char in string(k, LOC INT, s) THEN k ELSE CHAR sugg := c; CHAR cc = IF (charerror mended OF f)(f, sugg) THEN (char in string(sugg, LOC INT, s) | sugg | undefined; c) ELSE undefined; c FI; set read mood(f); cc FI; OP ! = (CHAR s, c)CHAR: STRING(s)! c; PROC skip initial spaces = VOID: WHILE (k empty | next pos(f)); ?" " DO SKIP OD; PROC skip spaces = VOID: WHILE ?" " DO SKIP OD; PROC read dig = STRING: (STRING t := "0123456789"! "0"; WHILE ?"0123456789" DO t PLUSAB k OD; t); PROC read sign = char: (CHAR t = (skipspaces; ?"+-" | k | "+"); skip spaces; t); PROC read num = STRING: (CHAR t = read sign; t + read dig); PROC read real = STRING: (STRING tread sign; ( ?"." | t PLUSAB read dig | k empty := FALSE); (?"." | t PLUSAB "." + read dig); (?"10'134e" | t PLUSAB "10" + read num); t); FOR j TO UPB y DO BOOL incomp := FALSE; k empty := TRUE; CASE y [j] IN « (REF {L} INT ii): (skip initial spaces; incomp := string to {l} int(read num, 10, ii))», « (REF {L} REAL rr): (skip initial spaces; incomp := string to {l} real(read real, rr)) », « (REF {L} COMPL zz): (skip initial spaces; incomp := string to {l} real(read real, re OF zz); skip spaces; "i^" ! "^"; incomp := incomp ¦ string to {l} real(read real, im OF zz))» (REF BOOL bb): (skip initial spaces; bb := (flip + flop) | flop = flip), « (REF {L} BITS lb): FOR i TO {l} bits width DO get(f, ({l} {F}f OF lb)[i]) OD», (REF CHAR cc): (nextpos(f); get char(f, cc)). (REF [ ]CHAR ss): FOR i FROM LWB ss TO UPB ss DO next pos(f); get char(f, ss [i]) OD, (REF STRING ss): BEGIN STRING t; WHILE check pos(f); IF line ended(f) ¦ logical file ended(f) THEN FALSE ELSE get char(f, k); k empty := char in string(k, LOC INT, term OF f) FI DO t PLUSAB k OD; ss := t END ESAC; ( k empty | backspace(f)); IF incomp THEN ( (value error mended OF f)(f) | undefined); set read mood(f) FI OD END ESAC OD ELSE undefined FI;
b) PROC {?}get char = (REF FILE f, REF CHAR char)VOID: IF opened OF f line ended(f) logical file ended(f) THEN REF POS cpos = cpos OF f; set char mood(f); set read mood(f); INT p = p OF cpos, l = l OF cpos, c = c OF cpos; c OF cpos +:= 1; char := CASE text OF f IN (TEXT t1): t1 [p][l][c], (FLEXTEXT t2): (CHAR k := t2[p][l][c]; BOOL found := FALSE; FOR i TO UPB {F}f OF conv OF f WHILE found DO STRUCT(CHAR internal, external) key = ({F}f OF conv OF f) [i]; (external OF key = k | k := internal OF key;## found := TRUE) OD; IF found THEN k ELSE k:= "."; CHAR cc = IF (char error mended OF f)(f, k) THEN k ELSE undefined; " " FI; set read mood(f); cc FI) ESAC ELSE undefined FI # read mood is still set # ;
c) PROC {?}check pos = (REF FILE f)VOID: BEGIN BOOL reading = read mood OF f; BOOL not ended := TRUE; WHILE not ended := not ended get good page(f, reading); line ended(f) not ended DO not ended := (line mended OF f)(f) OD END;
{The routine check pos is used in formatted transput
before each call of put char or get char. If the
position is not good {10.3.1.6.dd
}, it calls the
appropriate event routine, and may call further event routines if true
is returned. If the event routine corresponding to on page end
returns false, newpage is called but, if any other event routine
returns false, no default action is taken and no more event routines are
called. On exit, the read/write mood is as on entry, but the current position
may not be good, in which case undefined will be called in the
following put char or get char. However, check pos
is also called when getting strings {hh
}, in which
case the string is then terminated if the current position is not good.}
Next