comp.lang.ada
 help / color / mirror / Atom feed
* Q: Index value in case of Ada.Streams.Stream_IO.End_Error
@ 2006-04-22  1:33 Gautier
  2006-04-24  8:11 ` Jean-Pierre Rosen
  0 siblings, 1 reply; 5+ messages in thread
From: Gautier @ 2006-04-22  1:33 UTC (permalink / raw)


Hello!

Is there a RM-documented way to know the Index of a Ada.Streams.Stream_IO.File_Type
when it knocks the end of a file at reading it ?
I did not see a mention of what value the Index should have in that situation in
the RM 95, so for the moment I prefer to reread a partial buffer byte per byte
in order to know what has been effectively read. But maybe - hopefully - there
is a better way.

   procedure Read_buffer is

     procedure Byte_per_byte is
     begin
       for i in inbuf'Range loop
         Byte'Read( Ada.Streams.Stream_IO.Stream(infile), inbuf(i) );
         readpos:= readpos + 1;
       end loop;
     exception
       when Ada.Streams.Stream_IO.End_Error => null;
       -- nothing, we just reached EOF again
     end Byte_per_byte;

     start: Ada.Streams.Stream_IO.Positive_Count:=
              Ada.Streams.Stream_IO.Index(infile);
   begin
     readpos:= 0;
     begin
       IO_buf'Read( Ada.Streams.Stream_IO.Stream(infile), inbuf );
       readpos:= inbuf'Length;
     exception
       when Ada.Streams.Stream_IO.End_Error =>
         -- End reached, re-read in order to know the last position
         Ada.Streams.Stream_IO.Set_Index(infile, start);
         Read_buffer.Byte_per_byte;
     end;
   end Read_buffer;

Thanks in advance!
_______________________________________________________________
Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-04-24 17:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-22  1:33 Q: Index value in case of Ada.Streams.Stream_IO.End_Error Gautier
2006-04-24  8:11 ` Jean-Pierre Rosen
2006-04-24 14:33   ` Gautier
2006-04-24 16:05     ` Jean-Pierre Rosen
2006-04-24 17:44       ` Gautier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox