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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6286c332c8cae43d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-26 04:30:53 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: hfrumblefoot@yahoo.com (Hambut) Newsgroups: comp.lang.ada Subject: Re: Text_IO.End_Of_File Problem Date: 26 Nov 2001 04:30:53 -0800 Organization: http://groups.google.com/ Message-ID: References: <3C01A0AA.AF2F54BF@acm.org> NNTP-Posting-Host: 194.131.227.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1006777853 22195 127.0.0.1 (26 Nov 2001 12:30:53 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 26 Nov 2001 12:30:53 GMT Xref: archiver1.google.com comp.lang.ada:16977 Date: 2001-11-26T12:30:53+00:00 List-Id: First apologies - I should have specified that I was working on Wondows with Gnat 3.13p. Jeffrey Carter wrote in message news:<3C01A0AA.AF2F54BF@acm.org>... > Hambut wrote: > > > > Hi, > > > > I'm getting an exception with the attached code, and I can't see what > > I'm doing wrong, or why it's falling over. > > It's not falling over, it's terminating with an unhandled exception. Well - I do handle it, I just purposely raise it again so I can see the exception :-). > > > > Failure_Characters : constant String := ( 1 => Ascii.CR, > > 2 => Ascii.CR, > > 3 => Ascii.LF, > > 4 => Ascii.CR, > > 5 => Ascii.CR, > > 6 => Ascii.LF, > > 7 => Ascii.CR, > > 8 => Ascii.LF ); > > What you are doing is writing characters that contain embedded within > them what your specific system considers line terminators. Based on your > sample output, I would guess you're running under Win32. On such > systems, a line terminator is a CR followed by an LF. So you have (in > Text_IO terms) 3 lines. The first 2 lines contain a single character, > which is a CR; the 3rd line is null. Perhaps this is a part of my problem - Reading the secret documents, and looking at a-textio.ads I noted that LM (Line marker?) was set to Ascii.LF. I should have spent more time looking for windows specific docs perhaps? > > Next, note how Ada.Text_IO.Get (Character) works. It skips any line > terminators looking for a character. So your first call to Get reads > item 1 above. The second skips a line terminator (items 2 & 3) and reads > item 4. You are not now at the end of the file, so End_Of_File returns > False. Your 3rd call to get skips 2 line terminators (items 5-8), which > brings you to the end of the file, raising End_Error. > > Note that on a different system, with (a) different character(s) > representing a line terminator, you would get different results, but you > could still define a value for Failure_Characters that would cause the > program to raise End_Error even though End_Of_File is False. > Hmm - OK I understand what you're saying. I think my naive(?) view was that End_of_File would return true when there were no more characters for Get to return. To me this seems like an intuitive assumption. > > The basic lesson is that Text_IO interprets the characters in your file, > and in the process does not return every character to you. This can > result in some operations reading past the end of the file, although > End_Of_File has just returned False. This seems counter-intuitive. However assuming that it is in line with the LRM I guess it must be OK.