Previous
10.3.6. Binary transput
{In binary transput, the values obtained by straightening
the elements of a data list (cf. 10.3.3
) are transput,
via the specified file, one after the other. The manner in which such a
value is stored in the book is defined only to the extent that a value
of mode M (being some mode from which that specified by SIMPLOUT
is united) output at a given position may subsequently be re-input from
that same position to a name of mode
'reference to M'. Note
that, during input to the name referring to a multiple value, the number
of elements read will be the existing number of elements referred to by
that name.
The current position is advanced after each value by a
suitable amount and, at the end of each line or page, the appropriate event
routine is called, and next, if this returns false, the next good character
position of the book is found (cf. 10.3.3
).
For binary output, put bin {10.3.6.1.a
} and
write bin {10.5.1.h
} may be used and, for binary
input, get bin {10.3.6.2.a
} and read bin
{10.5.1.i
}.}
a)
PROC {?} to bin = (REF FILE f, SIMPLOUT x) [ ] CHAR :
© a value of mode 'row of character' whose lower bound is one and whose upper
bound depends on the value of 'book OF f' and on the mode and the value of 'x';
furthermore, x = from bin (f, x, to bin (f, x)) ©;
b) PROC {?}from bin = (REF FILE f, SIMPLOUT y. [ ]
CHAR c)SIMPLOUT:
© a value, if one exists, of the mode of the value yielded
by 'y', such that c = to bin(f, from bin(f, y, c)) ©;
10.3.6.1. Binary output
a)
PROC put bin = (REF FILE f, [ ] OUTTYPE ot) VOID:
IF opened OF f THEN
set bin mood (f); set write mood (f);
FOR k TO UPB ot
DO [ ] SIMPLOUT y = STRAIGHTOUT ot [k];
FOR j TO UPB y
DO [ ] CHAR bin = to bin(f, y[j]);
FOR i TO UPB bin
DO next pos (f);
set bin mood (f);
REF POS cpos = cpos OF f, lpos = lpos OF book OF f;
CASE text OF f IN
( FLEXTEXT t2):
t2 [p OF cpos ] [l OF cpos] [c OF cpos] := bin [i]
ESAC;
c OF cpos+:= 1;
IF cpos BEYOND lpos THEN lpos := cpos
ELIF ~ set possible (f)
& POS (p OF lpos, l OF lpos, 1) 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 © )
FI
OD
OD
OD
ELSE undefined
FI;
10.3.6.2. Binary input
a)
PROC get bin = (REF FILE f, [ ] INTYPE it) VOID:
IF opened OF f THEN
set bin mood (f); set read mood (f);
FOR k TO UPB it
DO [ ] SIMPLIN y = STRAIGHTIN it [k];
FOR j TO UPB y
DO
SIMPLOUT yj = CASE y[j] IN
«(REF {L} INT i): i»,
« (REF {L} REAL r): r»,
«(REF {L} COMPL z): z»,
(REF BOOL b): b,
«(REF {L} BITS lb): lb»,
(REF CHAR c): c,
(REF [ ] CHAR s): s,
( REF STRING ss): ss ESAC;
[ 1: UPB (to bin (f, yj))] CHAR bin;
FOR i TO UPB bin
DO next pos (f); set bin mood (f);
REF POS cpos = cpos OF f;
bin [i] :=
CASE text OF f IN
( FLEXTEXT t2):
t2[p OF cpos] [l OF cpos] [c OF cpos]
ESAC;
c OF cpos+:= 1
OD;
CASE y [j] IN
« (REF {L} INT ii): ( from bin (f, ii, bin) | ({L} INT i): i
i := i) »,
« (REF {L} REAL rr):
( from bin (f, rr, bin) | ({L} REAL r): rr := r)»,
« (REF {L} COMPL zz):
( from bin (f, zz, bin) | ({L} COMPL z): zz := z)»,
( REF BOOL bb): (from bin (f, bb, bin) | (BOOL b): bb := b),
« (REF {L} BITS lb):
( from bin (f, lb, bin) | ({L} BITS b): lb := b)»,
( REF CHAR cc): ( from bin (f, cc, bin) | (CHAR c): cc := c),
( REF [ ]CHAR ss):
( from bin (f, ss, bin) | ([ ] CHAR s): ss := s),
( REF STRING ssss):
( from bin (f, ssss, bin) | ([ ] CHAR s): ssss := s)
ESAC
OD
OD
ELSE undefined
FI;
{But Eeyore wasn't listening. He
was taking the balloon out, and putting it back again, as happy as could
be. ... Winnie-the-Pooh, A.A.Milne.}
Next