All pastes #2115465 Raw Edit

Miscellany

public text v1 · immutable
#2115465 ·published 2012-02-09 19:48 UTC
rendered paste body
with Ada.Text_IO;
with Ada.Text_IO.Text_Streams;
with Ada.Streams;

procedure Show_Bytes is
   
   use Ada.Text_IO;
   Buffer : Ada.Streams.Stream_Element_Array (1 .. 4096);
   Stdin : Text_Streams.Stream_Access :=
     Text_Streams.Stream (Standard_Input);
   Last : Ada.Streams.Stream_Element_Offset;
   C : Character;
   Number : Integer := 0;
   
begin
   
   while not End_Of_File (Standard_Input) loop
      
      Ada.Streams.Read (Stdin.all, Buffer, Last);
      
      for I in 1 .. Last loop
	 C := Character'Val (Buffer (I));
	 
	 if C = Character'Val (10) then
	    Ada.Text_IO.Put_Line (Integer'Image (Number));
	    Number := 0;
	 elsif C >= '0' and C <= '9' then
	    Number := 10 * Number;
	    Number := Number + Character'Pos (C) - Character'Pos ('0');
	 end if;
	 
      end loop;
      
   end loop;
   
end Show_Bytes;