From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a0833bbed8752e1f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!proxad.net!134.158.69.22.MISMATCH!in2p3.fr!irazu.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: variable lenght strings Date: Tue, 26 Oct 2004 15:15:12 +0200 Organization: AdaCL Message-ID: <1174011.lJ1dcgRM3Q@linux1.krischik.com> References: <1861614.TWv5A9FgVL@linux1.krischik.com> <4178e979_1@baen1673807.greenlnk.net> <1195374.UMjBCk7lO1@linux1.krischik.com> <1154613.ipZcUgduzp@linux1.krischik.com> Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8Bit X-Trace: news.t-online.com 1098796864 05 11051 KlQtXhp68gJx2J2 041026 13:21:04 X-Complaints-To: usenet-abuse@t-online.de X-ID: VgER8-ZSYeoo7s15N46d-y+jpgMxeI-xX0JIM9Mp3ZBU5hiV-wms0m User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:5722 Date: 2004-10-26T15:15:12+02:00 List-Id: 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