DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Package Ada.Text_IO

Verada predefined library: Ada.Text_IO (Ada RM A.10): standard input, output and error and the text files a program opens, by characters, strings and lines, with their layout (columns, lines and pages, and the line and page lengths that bound them on output), and numbers and enumeration values read and written by the generic packages below. The primitives are run-time functions (rt/textio.c).

A file's state is the abstract state File_System, so input and output take their order from the flow contracts. A procedure given a file that is not open, or not open in the mode it needs, propagates Status_Error or Mode_Error, as Ada's does, and its Exceptional_Cases say so: a program that knows its file is open in the right mode proves that they never happen. A function (Mode, Col, End_Of_File, ...) propagates no exception, so for a function that is a precondition. What depends on the world outside is an exception the program may handle, as each Exceptional_Cases says: Name_Error and Use_Error when a file cannot be made, opened, reset or deleted; End_Error when input runs out; Data_Error when a number or a value read is not one; Layout_Error when a value does not fit where it is put. A file the program closes while it is the current input or output leaves the standard one current again. A program starts with no line or page length set (No_Lengths_Set): every one unbounded. Which files are current (Is_Current) is part of the same state: each operation but Set_Input, Set_Output, Set_Error, Close, Delete and a Reset that closes its file says it leaves them as they were (Settings = Settings'Old), on return and with each exception a program may handle (Name_Error, Use_Error, End_Error, Data_Error, Layout_Error), and those say how they change them.

File_Type

type File_Type is limited private
  with Default_Initial_Condition => not Is_Open (File_Type);

(a file object is closed until Create or Open opens it)

File_Mode

type File_Mode is (In_File, Out_File, Append_File);

Count

type Count is range 0 .. Natural'Last;

Positive_Count

subtype Positive_Count is Count range 1 .. Count'Last;

Unbounded

Unbounded : constant Count := 0;

Field

subtype Field is Integer range 0 .. Integer'Last;

Number_Base

subtype Number_Base is Integer range 2 .. 16;

Type_Set

type Type_Set is (Lower_Case, Upper_Case);
Status_Error : exception renames Ada.IO_Exceptions.Status_Error;
Mode_Error   : exception renames Ada.IO_Exceptions.Mode_Error;
Name_Error   : exception renames Ada.IO_Exceptions.Name_Error;
Use_Error    : exception renames Ada.IO_Exceptions.Use_Error;
Device_Error : exception renames Ada.IO_Exceptions.Device_Error;
End_Error    : exception renames Ada.IO_Exceptions.End_Error;
Data_Error   : exception renames Ada.IO_Exceptions.Data_Error;
Layout_Error : exception renames Ada.IO_Exceptions.Layout_Error;

Is_Open

function Is_Open (File : File_Type) return Boolean
  with Global => null;

Mode

function Mode (File : File_Type) return File_Mode
  with Pre => Is_Open (File), Global => null;

Create

procedure Create (File : in out File_Type; Mode : File_Mode := Out_File; Name : String := ""; Form : String := "")
  with Post => Settings = Settings'Old and then Is_Open (File) and then Ada.Text_IO.Mode (File) = Mode
               and then Line_Bound (File) = 0 and then Page_Bound (File) = 0
               and then not Is_Current (File),
       Global => (In_Out => File_System),
       Exceptional_Cases => (Status_Error => Is_Open (File)'Old,
                             Name_Error | Use_Error => Settings = Settings'Old and then not Is_Open (File));

a new file (an empty Name: a temporary one, deleted when it is closed), open in Mode; or, when it cannot be made, Name_Error or Use_Error and the file still closed

Open

procedure Open (File : in out File_Type; Mode : File_Mode; Name : String; Form : String := "")
  with Post => Settings = Settings'Old and then Is_Open (File) and then Ada.Text_IO.Mode (File) = Mode
               and then Line_Bound (File) = 0 and then Page_Bound (File) = 0
               and then not Is_Current (File),
       Global => (In_Out => File_System),
       Exceptional_Cases => (Status_Error => Is_Open (File)'Old,
                             Name_Error | Use_Error => Settings = Settings'Old and then not Is_Open (File));

an existing file, open in Mode; or Name_Error (there is no such file) or Use_Error

Close

procedure Close (File : in out File_Type)
  with Post => Settings = Without (Settings, File)'Old and then not Is_Open (File),
       Global => (In_Out => File_System),
       Exceptional_Cases => (Status_Error => not Is_Open (File)'Old);

(an output file's last line is ended first; where it was current, the standard file is current again)

Delete

procedure Delete (File : in out File_Type)
  with Post => Settings = Without (Settings, File)'Old and then not Is_Open (File),
       Global => (In_Out => File_System),
       Exceptional_Cases => (Status_Error => not Is_Open (File)'Old,
                             Use_Error => Settings = Without (Settings, File)'Old and then not Is_Open (File));

the file closed and deleted; Use_Error when it cannot be deleted

Reset

procedure Reset (File : in out File_Type; Mode : File_Mode)
  with Post => Settings = Reset_Of (Settings, File)'Old and Is_Current (File) = Is_Current (File)'Old
               and (Is_Open (File) and then Ada.Text_IO.Mode (File) = Mode
                    and then Line_Bound (File) = 0 and then Page_Bound (File) = 0),
       Global => (In_Out => File_System),
       Exceptional_Cases => (Status_Error => not Is_Open (File)'Old,
                             Mode_Error => Is_Current (File)'Old and then Is_Open (File)
                                           and then Mode /= Ada.Text_IO.Mode (File),
                             Use_Error => Settings = Without (Settings, File)'Old and then not Is_Open (File));

the file again from its start, in Mode (its mode when none is given); Use_Error when it cannot be, the file then closed; Mode_Error when the file is a current default file and Mode is not its mode (RM A.10.2(4)), the file left as it was

Reset

procedure Reset (File : in out File_Type)
  with Post => Settings = Reset_Of (Settings, File)'Old and Is_Current (File) = Is_Current (File)'Old
               and (Mode (File)'Old = Mode (File) and then Is_Open (File)
                    and then Line_Bound (File) = 0 and then Page_Bound (File) = 0),
       Global => (In_Out => File_System),
       Exceptional_Cases => (Status_Error => not Is_Open (File)'Old,
                             Use_Error => Settings = Without (Settings, File)'Old and then not Is_Open (File));

Name

function Name (File : File_Type) return String
  with Pre => Is_Open (File), Global => File_System,
       Post => Name'Result'Length < Verada.Storage.Length_Bound;

the file's name (a temporary file's own), and its form: Verada takes none

Form

function Form (File : File_Type) return String
  with Pre => Is_Open (File), Global => null,
       Post => Form'Result'Length = 0;

Standard_Input

function Standard_Input return File_Type
  with Global => null,
       Post => Is_Open (Standard_Input'Result) and then Mode (Standard_Input'Result) = In_File;

Standard_Output

function Standard_Output return File_Type
  with Global => null,
       Post => Is_Open (Standard_Output'Result) and then Mode (Standard_Output'Result) = Out_File;

Standard_Error

function Standard_Error return File_Type
  with Global => null,
       Post => Is_Open (Standard_Error'Result) and then Mode (Standard_Error'Result) = Out_File;

Current_Input

function Current_Input return File_Type
  with Global => File_System,
       Post => Is_Open (Current_Input'Result) and then Mode (Current_Input'Result) = In_File;

Current_Output

function Current_Output return File_Type
  with Global => File_System,
       Post => Is_Open (Current_Output'Result) and then Mode (Current_Output'Result) /= In_File;

Current_Error

function Current_Error return File_Type
  with Global => File_System,
       Post => Is_Open (Current_Error'Result) and then Mode (Current_Error'Result) /= In_File;

Set_Input

procedure Set_Input (File : File_Type)
  with Global => (In_Out => File_System),
       Post => Settings = With_Input (Settings'Old, File),
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) /= In_File);

Set_Output

procedure Set_Output (File : File_Type)
  with Global => (In_Out => File_System),
       Post => Settings = With_Output (Settings'Old, File),
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

Set_Error

procedure Set_Error (File : File_Type)
  with Global => (In_Out => File_System),
       Post => Settings = With_Error (Settings'Old, File),
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

Flush

procedure Flush (File : File_Type)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

Flush

procedure Flush
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old;

Set_Line_Length

procedure Set_Line_Length (File : File_Type; To : Count)
  with Global => (In_Out => File_System),
       Post => Settings = With_Line_Length (Settings, File, To)'Old
               and Line_Bound (File) = To and Page_Bound (File) = Page_Bound (File)'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

Set_Line_Length

procedure Set_Line_Length (To : Count)
  with Global => (In_Out => File_System),
       Post => Settings = With_Line_Length (Settings'Old, To)
               and then Line_Length = To;

Set_Page_Length

procedure Set_Page_Length (File : File_Type; To : Count)
  with Global => (In_Out => File_System),
       Post => Settings = With_Page_Length (Settings, File, To)'Old
               and Page_Bound (File) = To and Line_Bound (File) = Line_Bound (File)'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

Set_Page_Length

procedure Set_Page_Length (To : Count)
  with Global => (In_Out => File_System),
       Post => Settings = With_Page_Length (Settings'Old, To)
               and then Page_Length = To;

Line_Length

function Line_Length (File : File_Type) return Count
  with Pre => Is_Open (File) and then Mode (File) /= In_File, Global => File_System,
       Post => (if Is_Current_Output (File) then Line_Length'Result = Line_Length);

(the current output's are the default forms')

Line_Length

function Line_Length return Count
  with Global => File_System;

Page_Length

function Page_Length (File : File_Type) return Count
  with Pre => Is_Open (File) and then Mode (File) /= In_File, Global => File_System,
       Post => (if Is_Current_Output (File) then Page_Length'Result = Page_Length);

Page_Length

function Page_Length return Count
  with Global => File_System;

New_Line

procedure New_Line (File : File_Type; Spacing : Positive_Count := 1)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

Spacing line terminators (and a page terminator after a page's last line)

New_Line

procedure New_Line (Spacing : Positive_Count := 1)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old;

Skip_Line

procedure Skip_Line (File : File_Type; Spacing : Positive_Count := 1)
  with Pre => Is_Open (File) and then Mode (File) = In_File,
       Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (End_Error => Settings = Settings'Old and (End_Of_File (File)'Old or else Spacing > 1));

past Spacing line terminators; End_Error when the file ends before the last (at its end on entry, or later when Spacing is above 1). (Its End_Error case names End_Of_File on entry, which needs the file open for input: so that is a precondition here, as for Skip_Page and the procedure Get_Line, rather than Status_Error and Mode_Error.)

Skip_Line

procedure Skip_Line (Spacing : Positive_Count := 1)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (End_Error => Settings = Settings'Old and (End_Of_File'Old or else Spacing > 1));

End_Of_Line

function End_Of_Line (File : File_Type) return Boolean
  with Pre => Is_Open (File) and then Mode (File) = In_File, Global => File_System,
       Post => (if Is_Current_Input (File) then End_Of_Line'Result = End_Of_Line);

End_Of_Line

function End_Of_Line return Boolean
  with Global => File_System;

New_Page

procedure New_Page (File : File_Type)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

a page terminator (the current line ended first)

New_Page

procedure New_Page
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old;

Skip_Page

procedure Skip_Page (File : File_Type)
  with Pre => Is_Open (File) and then Mode (File) = In_File,
       Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (End_Error => Settings = Settings'Old and End_Of_File (File)'Old);

past the next page terminator (or to the end of the file); End_Error when the file is at its end on entry

Skip_Page

procedure Skip_Page
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (End_Error => Settings = Settings'Old and End_Of_File'Old);

End_Of_Page

function End_Of_Page (File : File_Type) return Boolean
  with Pre => Is_Open (File) and then Mode (File) = In_File, Global => File_System,
       Post => (if Is_Current_Input (File) then End_Of_Page'Result = End_Of_Page);

End_Of_Page

function End_Of_Page return Boolean
  with Global => File_System;

End_Of_File

function End_Of_File (File : File_Type) return Boolean
  with Pre => Is_Open (File) and then Mode (File) = In_File, Global => File_System,
       Post => (if Is_Current_Input (File) then End_Of_File'Result = End_Of_File);

End_Of_File

function End_Of_File return Boolean
  with Global => File_System;

Line_Bound

function Line_Bound (File : File_Type) return Count
  with Ghost, Global => File_System,
       Post => Line_Bound'Result = (if Is_Open (File) and then Mode (File) /= In_File then Line_Length (File) else 0);

(for contracts: the line length, or the page length, of a file open for output; 0, as for no bound, for a file that is not)

Page_Bound

function Page_Bound (File : File_Type) return Count
  with Ghost, Global => File_System,
       Post => Page_Bound'Result = (if Is_Open (File) and then Mode (File) /= In_File then Page_Length (File) else 0);

File_Settings

type File_Settings is private;

(for contracts: the files' settings, as one value: which files are the current default input, output and error, and every file's line and page lengths. Whether File is a current file (open, then), or the current input or output. The settings after Set_Input, Set_Output or Set_Error of File; after Set_Line_Length or Set_Page_Length of File; after File is reset (its lengths unbounded), or closed (where it was current, the standard file is again))

Settings

function Settings return File_Settings
  with Ghost, Global => File_System;

No_Lengths_Set

function No_Lengths_Set return Boolean
  with Ghost, Global => File_System;

(whether no line or page length has been set since the program started, so that every one is unbounded: Text_IO's Initial_Condition)

Is_Current

function Is_Current (File : File_Type) return Boolean
  with Ghost, Global => File_System;

Is_Current_Input

function Is_Current_Input (File : File_Type) return Boolean
  with Ghost, Global => File_System;

Is_Current_Output

function Is_Current_Output (File : File_Type) return Boolean
  with Ghost, Global => File_System;

With_Input

function With_Input (Files : File_Settings; File : File_Type) return File_Settings
  with Ghost, Global => null;

With_Output

function With_Output (Files : File_Settings; File : File_Type) return File_Settings
  with Ghost, Global => null;

With_Error

function With_Error (Files : File_Settings; File : File_Type) return File_Settings
  with Ghost, Global => null;

With_Line_Length

function With_Line_Length (Files : File_Settings; File : File_Type; To : Count) return File_Settings
  with Ghost, Global => null;

With_Page_Length

function With_Page_Length (Files : File_Settings; File : File_Type; To : Count) return File_Settings
  with Ghost, Global => null;

With_Line_Length

function With_Line_Length (Files : File_Settings; To : Count) return File_Settings
  with Ghost, Global => null;

(the current output's)

With_Page_Length

function With_Page_Length (Files : File_Settings; To : Count) return File_Settings
  with Ghost, Global => null;

Reset_Of

function Reset_Of (Files : File_Settings; File : File_Type) return File_Settings
  with Ghost, Global => null;

Without

function Without (Files : File_Settings; File : File_Type) return File_Settings
  with Ghost, Global => null;

Set_Col

procedure Set_Col (File : File_Type; To : Positive_Count)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Layout_Error => Settings = Settings'Old and (Line_Bound (File)'Old /= 0 and then To > Line_Bound (File)'Old),
                             End_Error => Settings = Settings'Old and then Is_Open (File) and then Mode (File) = In_File);

output: spaces (after a new line, when past it) up to column To; Layout_Error when the line length is bounded and To is beyond it (never for column 1). Input: characters skipped up to column To; End_Error when the file ends first

Set_Col

procedure Set_Col (To : Positive_Count)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Layout_Error => Settings = Settings'Old and (Line_Length'Old /= 0 and then To > Line_Length'Old));

Set_Line

procedure Set_Line (File : File_Type; To : Positive_Count)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Layout_Error => Settings = Settings'Old and (Page_Bound (File)'Old /= 0 and then To > Page_Bound (File)'Old),
                             End_Error => Settings = Settings'Old and then Is_Open (File) and then Mode (File) = In_File);

output: new lines (after a new page, when past it) up to line To; Layout_Error when the page length is bounded and To is beyond it (never for line 1). Input: lines skipped up to line To; End_Error when the file ends first

Set_Line

procedure Set_Line (To : Positive_Count)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Layout_Error => Settings = Settings'Old and (Page_Length'Old /= 0 and then To > Page_Length'Old));

Col

function Col (File : File_Type) return Positive_Count
  with Pre => Is_Open (File), Global => File_System,
       Post => (if Is_Current_Output (File) then Col'Result = Col);

Col

function Col return Positive_Count
  with Global => File_System;

Line

function Line (File : File_Type) return Positive_Count
  with Pre => Is_Open (File), Global => File_System,
       Post => (if Is_Current_Output (File) then Line'Result = Line);

Line

function Line return Positive_Count
  with Global => File_System;

Page

function Page (File : File_Type) return Positive_Count
  with Pre => Is_Open (File), Global => File_System,
       Post => (if Is_Current_Output (File) then Page'Result = Page);

Page

function Page return Positive_Count
  with Global => File_System;

Get

procedure Get (File : File_Type; Item : out Character)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                             End_Error => Settings = Settings'Old);

the next character, line and page terminators skipped; End_Error at the file's end

Get

procedure Get (Item : out Character)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (End_Error => Settings = Settings'Old);

Put

procedure Put (File : File_Type; Item : Character)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

Put

procedure Put (Item : Character)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old;

Look_Ahead

procedure Look_Ahead (File : File_Type; Item : out Character; End_Of_Line : out Boolean)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) /= In_File);

the next character, not taken, or End_Of_Line when the line has ended

Look_Ahead

procedure Look_Ahead (Item : out Character; End_Of_Line : out Boolean)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old;

Get

procedure Get (File : File_Type; Item : out String)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                             End_Error => Settings = Settings'Old);

Item'Length characters, as Get reads them

Get

procedure Get (Item : out String)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (End_Error => Settings = Settings'Old);

Put

procedure Put (File : File_Type; Item : String)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

Put

procedure Put (Item : String)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old;

Put_Line

procedure Put_Line (File : File_Type; Item : String)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) = In_File);

Put_Line

procedure Put_Line (Item : String)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old;

Get_Line

procedure Get_Line (File : File_Type; Item : out String; Last : out Natural)
  with Pre => Is_Open (File) and then Mode (File) = In_File and then Item'First > 0,
       Post => Settings = Settings'Old
               and then (if Item'Length > 0 then Last in Item'First - 1 .. Item'Last else Last = Item'First - 1),
       Global => (In_Out => File_System),
       Exceptional_Cases => (End_Error => Settings = Settings'Old and End_Of_File (File)'Old);

a line's characters to Item from Item'First, and Last the index of the last one (Item'First - 1 for none); the line terminator is skipped when it is reached (not when Item is filled just before it). End_Error when no line is left to read (the file at its end on entry); an empty Item reads nothing

Get_Line

procedure Get_Line (Item : out String; Last : out Natural)
  with Pre => Item'First > 0,
       Post => Settings = Settings'Old
               and then (if Item'Length > 0 then Last in Item'First - 1 .. Item'Last else Last = Item'First - 1),
       Global => (In_Out => File_System),
       Exceptional_Cases => (End_Error => Settings = Settings'Old and End_Of_File'Old);

Get_Line

function Get_Line return String
  with Side_Effects, Pre => not End_Of_File, Global => (In_Out => File_System),
       Post => Settings = Settings'Old
               and then Get_Line'Result'Length < Verada.Storage.Length_Bound;

a line of any length: a function with side effects, since each call reads the next line, so it is called only as a declaration's or an assignment's value; a function propagates no exception, so a line must be left to read

Get_Line

function Get_Line (File : File_Type) return String
  with Side_Effects, Pre => Is_Open (File) and then Mode (File) = In_File and then not End_Of_File (File),
       Global => (In_Out => File_System),
       Post => Settings = Settings'Old
               and then Get_Line'Result'Length < Verada.Storage.Length_Bound;

Get_Immediate

procedure Get_Immediate (File : File_Type; Item : out Character)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                             End_Error => Settings = Settings'Old);

the next character, a control character (a line or page terminator's) too, at once (RM A.10.7); End_Error at the file's end

Get_Immediate

procedure Get_Immediate (Item : out Character)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (End_Error => Settings = Settings'Old);

Get_Immediate

procedure Get_Immediate (File : File_Type; Item : out Character; Available : out Boolean)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (Status_Error => not Is_Open (File),
                             Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                             End_Error => Settings = Settings'Old);

the same without waiting: Available is False when no character has arrived yet (a file's are always there; standard input's when it has been typed), Item then ' '

Get_Immediate

procedure Get_Immediate (Item : out Character; Available : out Boolean)
  with Global => (In_Out => File_System),
       Post => Settings = Settings'Old,
       Exceptional_Cases => (End_Error => Settings = Settings'Old);
generic
   type Num is range <>;
package Integer_IO is
   Default_Width : Field := Num'Width;
   Default_Base : Number_Base := 10;

   procedure Get (File : File_Type; Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                                Data_Error | End_Error => Settings = Settings'Old);
   procedure Get (Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Data_Error | End_Error => Settings = Settings'Old);

   --  (for contracts: how many characters Put writes for Item, Width and Base)
   function Put_Length (Item : Num; Width : Field; Base : Number_Base) return Count
     with Ghost, Global => null,
          Post => Put_Length'Result >= Count (Width) and then Put_Length'Result <= Count (Integer'Max (Width, 133));

   procedure Put (File : File_Type; Item : Num; Width : Field := Default_Width; Base : Number_Base := Default_Base)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) = In_File,
                                Layout_Error => Settings = Settings'Old
                                                and (Line_Bound (File)'Old /= 0
                                                     and then Put_Length (Item, Width, Base) > Line_Bound (File)'Old));
   procedure Put (Item : Num; Width : Field := Default_Width; Base : Number_Base := Default_Base)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Layout_Error => Settings = Settings'Old
                                                and (Line_Length'Old /= 0
                                                     and then Put_Length (Item, Width, Base) > Line_Length'Old));

   procedure Get (From : String; Item : out Num; Last : out Positive)
     with Global => null,
          Post => Last in From'Range,
          Exceptional_Cases => (Data_Error | End_Error => True);
   procedure Put (To : out String; Item : Num; Base : Number_Base := Default_Base)
     with Global => null,
          Exceptional_Cases => (Layout_Error => True);
end Integer_IO;
generic
   type Num is mod <>;
package Modular_IO is
   Default_Width : Field := Num'Width;
   Default_Base : Number_Base := 10;

   procedure Get (File : File_Type; Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                                Data_Error | End_Error => Settings = Settings'Old);
   procedure Get (Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Data_Error | End_Error => Settings = Settings'Old);

   --  (for contracts: how many characters Put writes for Item, Width and Base)
   function Put_Length (Item : Num; Width : Field; Base : Number_Base) return Count
     with Ghost, Global => null,
          Post => Put_Length'Result >= Count (Width) and then Put_Length'Result <= Count (Integer'Max (Width, 133));

   procedure Put (File : File_Type; Item : Num; Width : Field := Default_Width; Base : Number_Base := Default_Base)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) = In_File,
                                Layout_Error => Settings = Settings'Old
                                                and (Line_Bound (File)'Old /= 0
                                                     and then Put_Length (Item, Width, Base) > Line_Bound (File)'Old));
   procedure Put (Item : Num; Width : Field := Default_Width; Base : Number_Base := Default_Base)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Layout_Error => Settings = Settings'Old
                                                and (Line_Length'Old /= 0
                                                     and then Put_Length (Item, Width, Base) > Line_Length'Old));

   procedure Get (From : String; Item : out Num; Last : out Positive)
     with Global => null,
          Post => Last in From'Range,
          Exceptional_Cases => (Data_Error | End_Error => True);
   procedure Put (To : out String; Item : Num; Base : Number_Base := Default_Base)
     with Global => null,
          Exceptional_Cases => (Layout_Error => True);
end Modular_IO;
generic
   type Num is digits <>;
package Float_IO is
   Default_Fore : Field := 2;
   Default_Aft : Field := Num'Digits - 1;
   Default_Exp : Field := 3;

   procedure Get (File : File_Type; Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                                Data_Error | End_Error => Settings = Settings'Old);
   procedure Get (Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Data_Error | End_Error => Settings = Settings'Old);

   --  (for contracts: how many characters Put writes for Item, Fore, Aft and Exp)
   function Put_Length (Item : Num; Fore, Aft, Exp : Field) return Count
     with Ghost, Global => null;

   procedure Put (File : File_Type; Item : Num; Fore : Field := Default_Fore; Aft : Field := Default_Aft; Exp : Field := Default_Exp)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) = In_File,
                                Layout_Error => Settings = Settings'Old
                                                and (Line_Bound (File)'Old /= 0
                                                     and then Put_Length (Item, Fore, Aft, Exp) > Line_Bound (File)'Old));
   procedure Put (Item : Num; Fore : Field := Default_Fore; Aft : Field := Default_Aft; Exp : Field := Default_Exp)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Layout_Error => Settings = Settings'Old
                                                and (Line_Length'Old /= 0
                                                     and then Put_Length (Item, Fore, Aft, Exp) > Line_Length'Old));

   procedure Get (From : String; Item : out Num; Last : out Positive)
     with Global => null,
          Post => Last in From'Range,
          Exceptional_Cases => (Data_Error | End_Error => True);
   procedure Put (To : out String; Item : Num; Aft : Field := Default_Aft; Exp : Field := Default_Exp)
     with Global => null,
          Exceptional_Cases => (Layout_Error => True);
end Float_IO;

floating point: Put writes Fore characters before the point (the sign among them), Aft digits after it, and, when Exp is not 0, an exponent of Exp characters (its sign among them); the digits are the value's, correctly rounded

generic
   type Num is delta <>;
package Fixed_IO is
   Default_Fore : Field := Num'Fore;
   Default_Aft : Field := Num'Aft;
   Default_Exp : Field := 0;

   procedure Get (File : File_Type; Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                                Data_Error | End_Error => Settings = Settings'Old);
   procedure Get (Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Data_Error | End_Error => Settings = Settings'Old);

   --  (for contracts: how many characters Put writes for Item, Fore, Aft and Exp)
   function Put_Length (Item : Num; Fore, Aft, Exp : Field) return Count
     with Ghost, Global => null;

   procedure Put (File : File_Type; Item : Num; Fore : Field := Default_Fore; Aft : Field := Default_Aft; Exp : Field := Default_Exp)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) = In_File,
                                Layout_Error => Settings = Settings'Old
                                                and (Line_Bound (File)'Old /= 0
                                                     and then Put_Length (Item, Fore, Aft, Exp) > Line_Bound (File)'Old));
   procedure Put (Item : Num; Fore : Field := Default_Fore; Aft : Field := Default_Aft; Exp : Field := Default_Exp)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Layout_Error => Settings = Settings'Old
                                                and (Line_Length'Old /= 0
                                                     and then Put_Length (Item, Fore, Aft, Exp) > Line_Length'Old));

   procedure Get (From : String; Item : out Num; Last : out Positive)
     with Global => null,
          Post => Last in From'Range,
          Exceptional_Cases => (Data_Error | End_Error => True);
   procedure Put (To : out String; Item : Num; Aft : Field := Default_Aft; Exp : Field := Default_Exp)
     with Global => null,
          Exceptional_Cases => (Layout_Error => True);
end Fixed_IO;

fixed point: as floating point, the digits the value's exactly, rounded to the nearest (halves away from zero); a value read is truncated to a multiple of the small, as a conversion to the type is

generic
   type Num is delta <> digits <>;
package Decimal_IO is
   Default_Fore : Field := Num'Fore;
   Default_Aft : Field := Num'Aft;
   Default_Exp : Field := 0;

   procedure Get (File : File_Type; Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                                Data_Error | End_Error => Settings = Settings'Old);
   procedure Get (Item : out Num; Width : Field := 0)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Data_Error | End_Error => Settings = Settings'Old);

   --  (for contracts: how many characters Put writes for Item, Fore, Aft and Exp)
   function Put_Length (Item : Num; Fore, Aft, Exp : Field) return Count
     with Ghost, Global => null;

   procedure Put (File : File_Type; Item : Num; Fore : Field := Default_Fore; Aft : Field := Default_Aft; Exp : Field := Default_Exp)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) = In_File,
                                Layout_Error => Settings = Settings'Old
                                                and (Line_Bound (File)'Old /= 0
                                                     and then Put_Length (Item, Fore, Aft, Exp) > Line_Bound (File)'Old));
   procedure Put (Item : Num; Fore : Field := Default_Fore; Aft : Field := Default_Aft; Exp : Field := Default_Exp)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Layout_Error => Settings = Settings'Old
                                                and (Line_Length'Old /= 0
                                                     and then Put_Length (Item, Fore, Aft, Exp) > Line_Length'Old));

   procedure Get (From : String; Item : out Num; Last : out Positive)
     with Global => null,
          Post => Last in From'Range,
          Exceptional_Cases => (Data_Error | End_Error => True);
   procedure Put (To : out String; Item : Num; Aft : Field := Default_Aft; Exp : Field := Default_Exp)
     with Global => null,
          Exceptional_Cases => (Layout_Error => True);
end Decimal_IO;

decimal fixed point: as fixed point

generic
   type Enum is (<>);
package Enumeration_IO is
   Default_Width : Field := 0;
   Default_Setting : Type_Set := Upper_Case;

   procedure Get (File : File_Type; Item : out Enum)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) /= In_File,
                                Data_Error | End_Error => Settings = Settings'Old);
   procedure Get (Item : out Enum)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Data_Error | End_Error => Settings = Settings'Old);

   --  (for contracts: how many characters Put writes for Item and Width)
   function Put_Length (Item : Enum; Width : Field) return Count
     with Ghost, Global => null,
          Post => Put_Length'Result >= Count (Width);

   procedure Put (File : File_Type; Item : Enum; Width : Field := Default_Width; Set : Type_Set := Default_Setting)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Status_Error => not Is_Open (File),
                                Mode_Error => Is_Open (File) and then Mode (File) = In_File,
                                Layout_Error => Settings = Settings'Old
                                                and (Line_Bound (File)'Old /= 0
                                                     and then Put_Length (Item, Width) > Line_Bound (File)'Old));
   procedure Put (Item : Enum; Width : Field := Default_Width; Set : Type_Set := Default_Setting)
     with Global => (In_Out => File_System),
          Post => Settings = Settings'Old,
          Exceptional_Cases => (Layout_Error => Settings = Settings'Old
                                                and (Line_Length'Old /= 0
                                                     and then Put_Length (Item, Width) > Line_Length'Old));

   procedure Get (From : String; Item : out Enum; Last : out Positive)
     with Global => null,
          Post => Last in From'Range,
          Exceptional_Cases => (Data_Error | End_Error => True);
   procedure Put (To : out String; Item : Enum; Set : Type_Set := Default_Setting)
     with Global => null,
          Exceptional_Cases => (Layout_Error => True);
end Enumeration_IO;

enumeration values: Put writes the literal in Set's case (a character literal as it is), left-justified in Width characters