From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-91-241.ec2.internal X-Spam-Level: * X-Spam-Status: No, score=1.0 required=3.0 tests=PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Weird behavior of Get character with trailing new lines. Date: Tue, 26 Sep 2023 00:53:53 -0500 Organization: A noiseless patient Spider Message-ID: References: Injection-Date: Tue, 26 Sep 2023 05:53:29 -0000 (UTC) Injection-Info: dont-email.me; posting-host="f0a5cbfd923c9b47a54100ea42585311"; logging-data="2501649"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18v4kuyb2P3JQqDqC5X6Otr83la59dbw6I=" Cancel-Lock: sha1:PuGv/BM5eIOmiD6+oUAzFXzjVZk= X-Priority: 3 X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response Xref: news.eternal-september.org comp.lang.ada:65726 List-Id: "J-P. Rosen" wrote in message news:uem2id$moia$1@dont-email.me... > Le 22/09/2023 à 22:05, Jeffrey R.Carter a écrit : >> On 2023-09-22 21:30, Blady wrote: >>> >>> A.10.7 Input-Output of Characters and Strings >>> For an item of type Character the following procedures are provided: >>> procedure Get(File : in File_Type; Item : out Character); >>> procedure Get(Item : out Character); >>> After skipping any line terminators and any page terminators, reads the >>> next character from the specified input file and returns the value of >>> this character in the out parameter Item. >>> The exception End_Error is propagated if an attempt is made to skip a >>> file terminator. >> >> As you have quoted, Get (Character) skips line terminators. End_Of_File >> returns True if there is a single line terminator before the file >> terminator, but False if there are multiple line terminators before the >> file terminator. So you either have to explicitly skip line terminators, >> or handle End_Error. >> > And this works only if the input file is "well formed", i.e. if it has > line terminators as the compiler expects them to be (f.e., you will be in > trouble if the last line has no LF). > That's why I never check End_Of_File, but handle the End_Error exception. > It always works. Agreed. And if the file might contain a page terminator, things get even worse because you would have to mess around with End_of_Page in order to avoid hitting a combination that still will raise End_Error. It's not worth the mental energy to avoid it, especially in a program that will be used by others. (I've sometimes used the simplest possible way to writing a "quick&dirty" program for my own use; for such programs I skip the error handling as I figure I can figure out what I did wrong by looking at the exception raised. But that's often a bad idea even in that case as such programs have a tendency to get reused years later and then the intended usage often isn't clear.) Randy.