comp.lang.ada
 help / color / mirror / Atom feed
From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: variable lenght strings
Date: Tue, 26 Oct 2004 15:15:12 +0200
Date: 2004-10-26T15:15:12+02:00	[thread overview]
Message-ID: <1174011.lJ1dcgRM3Q@linux1.krischik.com> (raw)
In-Reply-To: ln2llc.e3u.ln@skymaster

Jean-Pierre Rosen wrote:

> Randy Brukardt a ï¿œcrit :
> 
>> My opinion is that GNAT is wrong in that case. A.10(7) makes it quite
>> clear that you can't have a file terminator without a line and page
>> terminator in front of it.

> More precisely: a file that doesn't end with a line/page terminator is
> improperly formatted.

There is a world beyond Ada and you might like to read files from there too.

>> I vaguely recall having argued this with Robert Dewar, and I think that
>> they had a different interpretation, based on the idea that a file with a
>> missing CR/LF is incorrect for use with Text_IO. I hope I misremember
>> that, because it is stupid (even if it is logically correct) as it
>> essentially says that you can't read outside generated text files with
>> Text_IO (you can't know whether the file has CR/LFs as required).
>> 
>> But I can understand why they wouldn't want to do this properly, because
>> it is a pain to get right, and it saps the performance of Text_IO (since
>> you have the be prepared to check for implied characters for each one you
>> read).

> No, it's simpler than that.
> 
> In all my programs, I simply never check for End_Of_File, I catch
> End_Error instead. It is simpler in other cases too: if you read
> numbers, and the file is terminated with blank lines, you can get
> End_Error even when End_Of_File is false.

Well you could create a Get_Line with End_Error too. But I like to see where
the "easier" part comes into play:

ᅵᅵᅵpackageᅵIOᅵᅵᅵᅵᅵᅵrenamesᅵAda.Text_IO;

ᅵᅵᅵfunctionᅵGet_Lineᅵ(
ᅵᅵᅵᅵᅵᅵFileᅵ:ᅵinᅵIO.File_Type)
ᅵᅵᅵreturn
ᅵᅵᅵᅵᅵᅵString
ᅵᅵᅵis
ᅵᅵᅵᅵᅵᅵBufferᅵ:ᅵStringᅵ(1ᅵ..ᅵBufferSize);
ᅵᅵᅵᅵᅵᅵLastᅵᅵᅵ:ᅵNatural;
ᅵᅵᅵbegin
ᅵᅵᅵᅵᅵᅵIO.Get_Lineᅵ(
ᅵᅵᅵᅵᅵᅵᅵᅵᅵFileᅵ=>ᅵFile,
ᅵᅵᅵᅵᅵᅵᅵᅵᅵItemᅵ=>ᅵBuffer,
ᅵᅵᅵᅵᅵᅵᅵᅵᅵLastᅵ=>ᅵLast);

ᅵᅵᅵᅵᅵᅵifᅵLastᅵ<ᅵBuffer'Lastᅵthen
ᅵᅵᅵᅵᅵᅵᅵᅵᅵreturnᅵBufferᅵ(1ᅵ..ᅵLast);
ᅵᅵᅵᅵᅵᅵelsifᅵIO.End_Of_Fileᅵ(File)ᅵthen
ᅵᅵᅵᅵᅵᅵᅵᅵᅵreturnᅵBuffer;
ᅵᅵᅵᅵᅵᅵelse
ᅵᅵᅵᅵᅵᅵᅵᅵᅵreturnᅵBufferᅵ&ᅵGet_Lineᅵ(File);
ᅵᅵᅵᅵᅵᅵendᅵif;
ᅵᅵᅵendᅵGet_Line;

I can see a just as easy - but easier...

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




  reply	other threads:[~2004-10-26 13:15 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-21 17:52 variable lenght strings fabio de francesco
2004-10-21 21:22 ` Martin Dowie
2004-10-21 22:42 ` Marius Amado Alves
2004-10-21 23:14   ` Matthew Heaney
2004-10-22  7:38     ` Martin Krischik
2004-10-22 12:30     ` fabio de francesco
2004-10-22  7:29   ` Martin Krischik
2004-10-22 13:01     ` Matthew Heaney
2004-10-24 15:46       ` Martin Krischik
2004-10-24 19:54         ` Jeffrey Carter
2004-10-24 21:30           ` Larry Kilgallen
2004-10-25  4:02             ` Jeffrey Carter
2004-10-21 23:01 ` Marius Amado Alves
2004-10-21 23:05 ` Stephen Leake
2004-10-22  7:25 ` Martin Krischik
2004-10-22 11:11   ` Martin Dowie
2004-10-24 15:43     ` Martin Krischik
2004-10-24 17:39       ` Martin Dowie
2004-10-24 18:37       ` Björn Persson
2004-10-25  7:30         ` Martin Krischik
2004-10-26  0:06           ` Randy Brukardt
2004-10-26  1:53             ` Larry Kilgallen
2004-10-26  8:49               ` Martin Krischik
2004-10-26 11:18               ` Marius Amado Alves
2004-10-26 12:48                 ` variable length strings Larry Kilgallen
2004-10-26 16:11                   ` Warren W. Gay VE3WWG
2004-10-26 18:50                     ` Björn Persson
2004-10-26 19:46                       ` Larry Kilgallen
2004-10-26  8:43             ` variable lenght strings Jean-Pierre Rosen
2004-10-26 13:15               ` Martin Krischik [this message]
2004-10-26 17:37                 ` Pascal Obry
2004-10-26 18:07                   ` Hyman Rosen
2004-10-26 20:10                     ` Pascal Obry
2004-10-27 10:26                       ` variable length strings Jacob Sparre Andersen
2004-10-27 10:39                         ` Pascal Obry
2004-10-27 11:47                         ` Larry Kilgallen
2004-10-28  7:18                           ` Jacob Sparre Andersen
2004-10-27 11:50                         ` Larry Kilgallen
     [not found]                         ` <uwtxcla1n.fsf@obry.Organization: LJK Software <PTzuwe3GsIg6@eisner.encompasserve.org>
2004-10-27 12:12                           ` Samuel Tardieu
2004-10-27 12:58                             ` Pascal Obry
2004-10-27 13:04                           ` Pascal Obry
2004-10-27 14:54                             ` Dmitry A. Kazakov
2004-10-27 16:38                               ` Pascal Obry
2004-10-28  8:14                                 ` Dmitry A. Kazakov
2004-10-28  8:49                                   ` Pascal Obry
2004-10-28  9:06                                     ` Dmitry A. Kazakov
2004-10-28 16:07                                       ` Pascal Obry
2004-10-28 22:05                                         ` Jeffrey Carter
2004-10-28 22:41                                           ` Randy Brukardt
2004-10-29  1:11                                             ` Jeffrey Carter
2004-10-29  7:42                                         ` Dmitry A. Kazakov
2004-10-28 10:31                         ` Larry Kilgallen
2004-10-26 18:13                   ` variable lenght strings Martin Krischik
2004-10-27 12:01                 ` Jean-Pierre Rosen
2004-10-26 17:46             ` Jeffrey Carter
2004-10-28 22:50               ` Randy Brukardt
2004-10-28 23:01                 ` Larry Kilgallen
2004-10-29 21:52                   ` Randy Brukardt
2004-10-29  8:48                 ` Dale Stanbrough
2004-10-29  9:11                   ` Larry Kilgallen
2004-10-24 18:38     ` Why these "Drop" parameters? (was: variable lenght strings) Björn Persson
2004-10-26  0:13       ` Randy Brukardt
2004-11-01  1:02         ` Why these "Drop" parameters? Björn Persson
2004-11-01 19:59           ` Randy Brukardt
2004-10-24 18:57 ` variable lenght strings Jeffrey Carter
replies disabled

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