The Ada Program: encode.adb

  1 -- encode.adb:
  2 
  3 with Code;
  4 with Ada.Text_IO, Ada.Integer_Text_IO;
  5 use Ada;
  6 
  7 procedure Encode is
  8 
  9    Line : String (1..100);
 10    Length : Integer;
 11 
 12    subtype Block_Number_Range is Natural range 0 .. 15;
 13    Block_Count : Block_Number_Range := 0;
 14 
 15    procedure Put (C: Code.T; Last: Boolean := False) is
 16    begin
 17       Integer_Text_IO.Put (C, Width=>4);
 18       if Last or else Block_Count = Block_Number_Range'Last then
 19          Text_IO.New_Line;
 20          Block_Count := 0;
 21       else
 22          Block_Count := Block_Count + 1;
 23       end if;
 24    end Put;
 25 
 26 
 27 begin
 28 
 29    while not Text_IO.End_Of_File loop
 30       Text_IO.Get_Line (Line, Length);
 31       for I in 1 ..Length loop
 32          Put (Character'Pos (Line(I)));
 33       end loop;
 34       Put (Code.End_Of_Line);
 35    end loop;
 36    Put (Code.End_Of_Message, True);
 37 
 38 end Encode;