Readln shall only be applied to textfiles. If the file-variable or the entire readln-parameter-list is omitted, the procedure shall be applied to the required textfile input, and the program shall contain a program-parameter-list containing an identifier with the spelling input.
Readln(f,v1,...,vn) shall access the textfile and establish a reference to that textfile for the remaining execution of the statement. The execution of the statement shall be equivalent to
begin read(ff,v1,...,vn); readln(ff) end
where ff denotes the referenced textfile.
Readln(f) shall access the textfile and establish a reference to that textfile for the remaining execution of the statement. The execution of the statement shall be equivalent to
begin while not eoln(ff) do get(ff); get(ff) end
where ff denotes the referenced textfile.
NOTES
1 The effect of readln is to place the current file position just past the end of the current line in the textfile. Unless this is the end-of-file position, the current file position is therefore at the start of the next line.
2 Because the definition of readln makes use of get, the implementation-defined aspects of the post-assertion of get also apply (see 6.6.5.2).
The procedure write
The syntax of the parameter list of write when applied to a textfile shall be
If the file-variable is omitted, the procedure shall be applied to the required textfile output, and the program shall contain a program-parameter-list containing an identifier with the spelling output. When write is applied to a textfile f, it shall be an error if f is undefined or f.M = Inspection (see 6.4.3.5).
For n>=1, write(f,p1,...,pn) shall access the textfile and establish a reference to that textfile for the remaining execution of the statement. For n>=2, the execution of the statement shall be equivalent to
begin write(ff,p1); write(ff,p2,...,pn) end
where ff denotes the referenced textfile.
Write(f,p), where f denotes a textfile and p is a write-parameter, shall write a sequence of zero or more characters on the textfile f; for each character c in the sequence, the equivalent of
begin ff := c; put(ff) end
where ff denotes the referenced textfile, shall be applied to the textfile f. The sequence of characters written shall be a representation of the value of the first expression in the write-parameter p, as specified in the remainder of this subclause.
NOTE --- Because the definition of write includes the use of put, the implementation-defined aspects of the post-assertion of put also apply (see 6.6.5.2).
Write-parameters
A write-parameter shall have one of the following forms
e : TotalWidth : FracDigits
e : TotalWidth
e
where e shall be an expression whose value is to be written on the file f and shall be of integer-type, real-type, char-type, Boolean-type, or a string-type, and where TotalWidth and FracDigits shall be expressions of integer-type whose values shall be the field-width parameters. The values of TotalWidth and FracDigits shall be greater than or equal to one; it shall be an error if either value is less than one.
Write(f,e) shall be equivalent to the form write(f, e : TotalWidth), using a default value for TotalWidth that depends on the type of e; for integer-type, real-type, and Boolean-type, the default values shall be implementation-defined.
Write(f, e : TotalWidth : FracDigits) shall be applicable only if e is of real-type (see 6.9.3.4.2).
Char-type
If e is of char-type, the default value of TotalWidth shall be one. The representation written on the file f shall be
(TotalWidth - 1) spaces, the character value of e.
Integer-type
If e is of integer-type, the decimal representation of the value of e shall be written on the file f. Assume a function
function IntegerSize (x : integer ) : integer;
{ returns the number of digits, z, such that
10 to the power (z-1) <= abs(x) < 10 to the power z }
and let IntDigits be the positive integer defined by
if e = 0 then IntDigits := 1
else IntDigits := IntegerSize(e);
then the representation shall consist of
a) if TotalWidth >= IntDigits + 1:
(TotalWidth - IntDigits - 1) spaces,
the sign character: '-' if e < 0, oterwise a space,
IntDigits digit-characters of the decimal representation of abs(e).
b) if TotalWidth < IntDigits + 1:
if e < 0 the sign character '-',
IntDigits digit-characters of the decimal representation of abs(e).
Real-type
If e is of real-type, a decimal representation of the value of e, rounded to the specified number of significant figures or decimal places, shall be written on the file f.
6.9.3.4.1 The floating-point representation
Write(f, e : TotalWidth) shall cause a floating-point representation of the value of e to be written. Assume functions
function TenPower ( Int : integer ) : real ;
{ Returns 10.0 raised to the power Int }
function RealSize ( y : real ) : integer ;
{ Returns the value, z, such that TenPower(z -1) <= abs(y) < TenPower(z) }
function Truncate( y : real ; DecPlaces : integer ) : real ;
{ Returns the value of y after truncation to DecPlaces decimal places }
let ExpDigits be an implementation-defined value representing the number of digit-characters written in an exponent;
let ActWidth be the positive integer defined by
if TotalWidth >= ExpDigits + 6
then ActWidth := TotalWidth
else ActWidth := ExpDigits + 6;
and let the non-negative number eWritten, the positive integer DecPlaces, and the integer ExpValue be defined by
then the floating-point representation of the value of e shall consist of
the sign character ( '-' if (e < 0.0 ) and (eWritten > 0.0), otherwise a space),
the leading digit-character of the decimal representation of eWritten,
the character '.' ,
the next DecPlaces digit-characters of the decimal representation of eWritten,
an implementation-defined exponent character (either 'e' or 'E'),
the sign of ExpValue ( ' -' if ExpValue < 0, otherwise '+'),
the ExpDigits digit-character of the decimal representation of ExpValue (with leading zeros
if the value requires them).
6.9.3.4.2 The fixed-point representation
Write(f, e : TotalWidth : FracDigits) shall cause a fixed-point representation of the value of e to be written. Assume the functions TenPower, RealSize, and Truncate described in 6.9.3.4.1;
let eWritten be the non-negative number defined by
and let MinNumChars be the positive integer defined by
MinNumChars := IntDigits + FracDigits + 1;
if (e < 0.0) and (eWritten > 0.0)
then MinNumChars := MinNumChars + 1; {'-' requried}
then the fixed-point representation of the value of e shall consist of
if TotalWidth >= MinNumChars : (TotalWidth - MinNumChars) spaces,
the character '-' if (e < 0.0) and (eWritten > 0.0),
the first IntDigits digit-characters of the decimal representation of the value of eWritten,
the character '.',
the next FracDigits digit-characters of the decimal representation of the value of eWritten.
NOTE --- At least MinNumChars characters are written. If TotalWidth is less than this value, no initial spaces are written.
Boolean-type
If e is of Boolean-type, a representation of the word true or the word false (as appropriate to the value of e) shall be written on the file f. This shall be equivalent to writing the appropriate character-string 'True' or 'False' (see 6.9.3.6), where the case of each letter is implementation-defined, with a field-width parameter of TotalWidth.
String-types
If the type of e is a string-type with n components, the default value of TotalWidth shall be n. The representation shall consist of
if TotalWidth > n : (TotalWidth - n) spaces,
the first through n-th characters of the value of e in that order,
if 1 <= TotalWidth <=n : the first through TotalWidth-th characters in that order.