A.10.7 Input-Output of Characters and Strings
Static Semantics
1
For an item of type 
Character the following procedures are provided: 
2
procedure Get(File : in File_Type; Item : out Character);
procedure Get(Item : out Character);
3
After skipping any line terminators and any page 
terminators, reads the next character from the specified input file and 
returns the value of this character in the out parameter Item.
4
The exception End_Error 
is propagated if an attempt is made to skip a file terminator.
5
procedure Put(File : in File_Type; Item : in Character);
procedure Put(Item : in Character);
6
If the line length 
of the specified output file is bounded (that is, does not have the conventional 
value zero), and the current column number exceeds it, has the effect 
of calling New_Line with a spacing of one. Then, or otherwise, outputs 
the given character to the file.
7
procedure Look_Ahead (File        : in  File_Type;
                      Item        : out Character;
                      End_Of_Line : out Boolean);
procedure Look_Ahead (Item        : out Character;
                      End_Of_Line : out Boolean);
8/3
{
AI05-0038-1} 
{
AI05-0264-1} 
Status_Error is propagated if the file is not open. 
Mode_Error is propagated if the mode of the file is not In_File. 
Sets End_Of_Line to True if at end of line, including if at end of page 
or at end of file; in each of these cases the value of Item is not specified. 
Otherwise
, End_Of_Line 
is set to False and Item is set to 
the the 
next character (without consuming it) from the file.
 
9
procedure Get_Immediate(File : in  File_Type;
                        Item : out Character);
procedure Get_Immediate(Item : out Character);
10/3
{
AI05-0038-1} 
Reads the next character, either control or graphic, from the specified 
File or the default input file. 
Status_Error is 
propagated if the file is not open. Mode_Error is propagated if 
the mode of the file is not In_File. End_Error is propagated if at the 
end of the file. The current column, line and page numbers for the file 
are not affected.
 
11
procedure Get_Immediate(File      : in  File_Type;
                        Item      : out Character;
                        Available : out Boolean);
procedure Get_Immediate(Item      : out Character;
                        Available : out Boolean);
12/3
{
AI05-0038-1} 
If a character, either control or graphic, is available from the specified 
File or the default input file, then the character is read; Available 
is True and Item contains the value of this character. If a character 
is not available, then Available is False and the value of Item is not 
specified. 
Status_Error is 
propagated if the file is not open. Mode_Error is propagated if 
the mode of the file is not In_File. End_Error is propagated if at the 
end of the file. The current column, line and page numbers for the file 
are not affected.
 
13/2
 {
AI95-00301-01} 
For an item of type String the following 
subprograms procedures 
are provided: 
 
14
procedure Get(File : in File_Type; Item : out String);
procedure Get(Item : out String);
15
Determines the length 
of the given string and attempts that number of Get operations for successive 
characters of the string (in particular, no operation is performed if 
the string is null).
16
procedure Put(File : in File_Type; Item : in String);
procedure Put(Item : in String);
17
Determines the length 
of the given string and attempts that number of Put operations for successive 
characters of the string (in particular, no operation is performed if 
the string is null).
17.1/2
function Get_Line(File : in File_Type) return String;
function Get_Line return String;
17.2/2
{
AI95-00301-01} 
Returns a result string constructed by reading 
successive characters from the specified input file, and assigning them 
to successive characters of the result string. The result string has 
a lower bound of 1 and an upper bound of the number of characters read. 
Reading stops when the end of the line is met; Skip_Line is then (in 
effect) called with a spacing of 1. 
17.3/2
{
AI95-00301-01} 
Constraint_Error is raised if the length of the 
line exceeds Positive'Last; in this case, the line number and page number 
are unchanged, and the column number is unspecified but no less than 
it was before the call. The exception End_Error is 
propagated if an attempt is made to skip a file terminator. 
17.a/2
Ramification: {
AI95-00301-01} 
Precisely what is left in the file is unspecified 
if Constraint_Error is raised because the line doesn't fit in a String; 
it should be consistent with column number. This allows implementers 
to use whatever buffering scheme makes sense. But the line terminator 
is not skipped in this case.  
18
procedure Get_Line(File : in File_Type;
                   Item : out String;
                   Last : out Natural);
procedure Get_Line(Item : out String;
                   Last : out Natural);
19
Reads successive characters from the specified 
input file and assigns them to successive characters of the specified 
string. Reading stops if the end of the string is met. Reading also stops 
if the end of the line is met before meeting the end of the string; in 
this case Skip_Line is (in effect) called with a spacing of 1. 
The 
values of characters not assigned are not specified.
 
20
If characters are 
read, returns in Last the index value such that Item(Last) is the last 
character assigned (the index of the first character assigned is Item'First). 
If no characters are read, returns in Last an index value that is one 
less than Item'First. The exception End_Error is propagated if an attempt 
is made to skip a file terminator.
21
procedure Put_Line(File : in File_Type; Item : in String);
procedure Put_Line(Item : in String);
22
Calls the procedure Put for the given string, 
and then the procedure New_Line with a spacing of one. 
Implementation Advice
23
The Get_Immediate procedures should be implemented 
with unbuffered input. For a device such as a keyboard, input should 
be “available” if a key has already been typed, whereas for 
a disk file, input should always be available except at end of file. 
For a file associated with a keyboard-like device, any line-editing features 
of the underlying operating system should be disabled during the execution 
of Get_Immediate. 
23.a/2
Implementation Advice: 
Get_Immediate should be implemented 
with unbuffered input; input should be available immediately; line-editing 
should be disabled.
24
30  Get_Immediate can be used to read a 
single key from the keyboard “immediately”; that is, without 
waiting for an end of line. In a call of Get_Immediate without the parameter 
Available, the caller will wait until a character is available.
25
31  In a literal string parameter of Put, 
the enclosing string bracket characters are not output. Each doubled 
string bracket character in the enclosed string is output as a single 
string bracket character, as a consequence of the rule for string literals 
(see 
2.6).
 
26
32  A string read by Get or written by Put 
can extend over several lines. An implementation is allowed to assume 
that certain external files do not contain page terminators, in which 
case Get_Line and Skip_Line can return as soon as a line terminator is 
read. 
Incompatibilities With Ada 95
26.a/2
{
AI95-00301-01} 
The Get_Line functions are 
newly added to Ada.Text_IO. If Ada.Text_IO is referenced in a use_clause, 
and a function Get_Line is defined in a package that is also referenced 
in a use_clause, 
the user-defined Get_Line may no longer be use-visible, resulting in 
errors. This should be rare and is easily fixed if it does occur. 
 
Extensions to Ada 95
26.b/2
Wording Changes from Ada 2005
26.c/3
{
AI05-0038-1} 
Correction: Added missing wording about 
raising Status_Error to Look_Ahead and Get_Immediate.  
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe