--  A number or an enumeration value is Put as one item (RM A.10.6(8)): on a line with a
--  length, a new line first when it does not fit in what is left of the line, and
--  Layout_Error, nothing written, when it is longer than the line itself (D255). A string is
--  not an item: its characters wrap.
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   type Colour is (Red, Green, Blue);
   type Fix is delta 0.01 range -1000.0 .. 1000.0;
   package Int_IO is new Integer_IO (Integer);
   package Real_IO is new Float_IO (Float);
   package Fix_IO is new Fixed_IO (Fix);
   package Colour_IO is new Enumeration_IO (Colour);
   F : File_Type;
   Text : String (1 .. 40);
   Last : Natural;
begin
   Create (F);
   Set_Line_Length (F, 6);
   Int_IO.Put (F, 123, Width => 0);
   Int_IO.Put (F, 456, Width => 0);
   Int_IO.Put (F, 7, Width => 3);
   begin
      Int_IO.Put (F, 1234567, Width => 0);
      Put_Line ("no Layout_Error");
   exception
      when Layout_Error => Put_Line ("Layout_Error, line" & Positive_Count'Image (Line (F)));
   end;
   Colour_IO.Put (F, Green, Width => 6);
   Colour_IO.Put (F, Red);
   Real_IO.Put (F, 1.5, Fore => 1, Aft => 1, Exp => 0);
   begin
      Real_IO.Put (F, 1.5);
   exception
      when Layout_Error => Put_Line ("Layout_Error for a float of 9");
   end;
   Fix_IO.Put (F, 12.25, Fore => 2, Aft => 2);
   Put (F, "abcdefgh");
   Reset (F, In_File);
   while not End_Of_File (F) loop
      Get_Line (F, Text, Last);
      Put_Line ("[" & Text (1 .. Last) & "]");
   end loop;
   Close (F);
   Set_Line_Length (4);
   Int_IO.Put (12, Width => 0);
   Int_IO.Put (34, Width => 0);
   Int_IO.Put (5, Width => 0);
   New_Line;
   Set_Line_Length (0);
exception
   when Name_Error | Use_Error | Layout_Error => Put_Line ("unexpected");
end Main;
