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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,c689b55786a9f2bd X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: for S'Image use Func?? Date: Fri, 21 May 2010 09:56:02 +0300 Organization: Tidorum Ltd Message-ID: <85mp43Fs48U1@mid.individual.net> References: <4be417b4$0$6992$9b4e6d93@newsspool4.arcor-online.net> <1qcb6z4i20dyb.1dz2hd4c0vx69.dlg@40tude.net> <852u87Fr5cU1@mid.individual.net> <85kdr5FhtkU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net cYwWgYGXqAuMXVVZZhLzww2FvCvCcaHQYUAzH65y0Z05OzGcWq Cancel-Lock: sha1:jkPyFYpSBpp2CLWsXepQjdMSxQg= User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) In-Reply-To: <85kdr5FhtkU1@mid.individual.net> Xref: g2news2.google.com comp.lang.ada:11838 Date: 2010-05-21T09:56:02+03:00 List-Id: I am replying to my own post to show an even simpler solution to the "final empty line" problem. I guess this solution is what J-P. Rosen and others have suggested, earlier in this thread, but I have been too dense to understand. The "problem" is that the Text_IO functions End_Of_Line and End_Of_File give the same result when the input file is positioned at true end of file as when the file is positioned at a line terminator preceding the true end of file. This means that a reading loop of the form "while not End_Of_File loop end loop" will ignore a final empty line. The simple solution is to use a loop that uses Get_Line (or Skip_Line) and terminates on the End_Error exception. This program reads and counts the lines in the input file and works for /dev/null (zero lines) as well as for files that end with empty lines: with Ada.Text_IO; use Ada.Text_IO; procedure Count_Lines is Lines : Natural := 0; begin loop declare The_Line : constant String := Get_Line; begin Lines := Lines + 1; end; end loop; exception when End_Error => Put_Line ("Lines:" & Natural'Image (Lines)); end Count_Lines; So, with apologies for any confusion about "warts" that I may have generated, I will now shut up. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .