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=NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: Weird behavior of Get character with trailing new lines. Date: Sat, 23 Sep 2023 09:02:37 +0200 Organization: Adalog Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 23 Sep 2023 07:02:38 -0000 (UTC) Injection-Info: dont-email.me; posting-host="a921a0f1aeaed0f13dc78d6902098417"; logging-data="746058"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19uXR2Eg4Q/yU8QwDUvQxX2" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Cancel-Lock: sha1:l3wxHkNIF90+eISY5eaJOA1uI/g= Content-Language: en-US, fr In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:65698 List-Id: 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. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX https://www.adalog.fr https://www.adacontrol.fr