comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier <gautier@fakeaddress.nil>
Subject: Q: Index value in case of Ada.Streams.Stream_IO.End_Error
Date: Sat, 22 Apr 2006 03:33:52 +0200
Date: 2006-04-22T03:33:52+02:00	[thread overview]
Message-ID: <44498820$1_7@news.bluewin.ch> (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!



             reply	other threads:[~2006-04-22  1:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-22  1:33 Gautier [this message]
2006-04-24  8:11 ` Q: Index value in case of Ada.Streams.Stream_IO.End_Error Jean-Pierre Rosen
2006-04-24 14:33   ` Gautier
2006-04-24 16:05     ` Jean-Pierre Rosen
2006-04-24 17:44       ` Gautier
replies disabled

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