* 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
* Re: Q: Index value in case of Ada.Streams.Stream_IO.End_Error
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
0 siblings, 1 reply; 5+ messages in thread
From: Jean-Pierre Rosen @ 2006-04-24 8:11 UTC (permalink / raw)
Gautier a �crit :
> 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 ?
out parameter Last in function Read...
This gives you the number of bytes actually read.
--
---------------------------------------------------------
J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Q: Index value in case of Ada.Streams.Stream_IO.End_Error
2006-04-24 8:11 ` Jean-Pierre Rosen
@ 2006-04-24 14:33 ` Gautier
2006-04-24 16:05 ` Jean-Pierre Rosen
0 siblings, 1 reply; 5+ messages in thread
From: Gautier @ 2006-04-24 14:33 UTC (permalink / raw)
Jean-Pierre Rosen:
>> 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 ?
> out parameter Last in function Read...
>
> This gives you the number of bytes actually read.
You mean the _procedure_ Read, from Stream_IO ?
procedure Read (File : in File_Type;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset);
Nice, but for my buffer I need to use the Read _attribute_ (13.13.2).
procedure S'Read( Stream : access Ada.Streams.Root_Stream_Type'Class;
Item : out T)
No "Last" there... If I try:
IO_buf'Read( Ada.Streams.Stream_IO.Stream(infile), inbuf, last );
a compiler says as expected:
unz_io.adb:55:67: unexpected argument for "Read" attribute
Hence my question.
Mmmh, unless I redefine my buffer as a Stream_Element_Array.
Are you assuming that ?
_______________________________________________________________
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
* Re: Q: Index value in case of Ada.Streams.Stream_IO.End_Error
2006-04-24 14:33 ` Gautier
@ 2006-04-24 16:05 ` Jean-Pierre Rosen
2006-04-24 17:44 ` Gautier
0 siblings, 1 reply; 5+ messages in thread
From: Jean-Pierre Rosen @ 2006-04-24 16:05 UTC (permalink / raw)
Gautier a �crit :
> Jean-Pierre Rosen:
>
>>> 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 ?
>
>> out parameter Last in function Read...
>>
>> This gives you the number of bytes actually read.
>
> You mean the _procedure_ Read, from Stream_IO ?
>
> procedure Read (File : in File_Type;
> Item : out Stream_Element_Array;
> Last : out Stream_Element_Offset);
>
> Nice, but for my buffer I need to use the Read _attribute_ (13.13.2).
>
If you use 'Read, and there is not enough bytes left in the file, then
your file is corrupted. You will get End_Error.
Now, if you want to analyze what happened, here is what you can do:
1) before calling 'Read, get the current index (function Index)
2) Do a T'Read
3) If you get End_Error, do a Set_Index to return where you were, and
use the Read procedure to get the corresponding array of bytes.
Then it's up to you...
--
---------------------------------------------------------
J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Q: Index value in case of Ada.Streams.Stream_IO.End_Error
2006-04-24 16:05 ` Jean-Pierre Rosen
@ 2006-04-24 17:44 ` Gautier
0 siblings, 0 replies; 5+ messages in thread
From: Gautier @ 2006-04-24 17:44 UTC (permalink / raw)
Jean-Pierre Rosen:
> If you use 'Read, and there is not enough bytes left in the file, then
> your file is corrupted. You will get End_Error.
> Now, if you want to analyze what happened, here is what you can do:
> 1) before calling 'Read, get the current index (function Index)
> 2) Do a T'Read
> 3) If you get End_Error, do a Set_Index to return where you were, and
> use the Read procedure to get the corresponding array of bytes.
> Then it's up to you...
Fine, it's what I'm doing currently (cf the lines of code in my 1st post).
But since the buffer in question happens to be a byte array,
I'll switch to the Read procedure and just define the buffer as a
Stream_Element_Array.
Thanks
_______________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm
^ 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