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-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R.Carter" Newsgroups: comp.lang.ada Subject: Re: Get_Immediate does not read CR in CRLF pairs Date: Tue, 8 Mar 2022 10:06:02 +0100 Organization: A noiseless patient Spider Message-ID: References: <1bd9b7ee-9195-44b3-8de2-c018a44b7eden@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 8 Mar 2022 09:06:05 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="101cb3e40e232cbf9aa095c202bc615b"; logging-data="18857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0/Vs3YS+zBNEH3L0O0KXYPLKYQptlWnA=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Cancel-Lock: sha1:JXof76ak+J3ONS17qQ2V9JGOKDA= In-Reply-To: <1bd9b7ee-9195-44b3-8de2-c018a44b7eden@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:63585 List-Id: On 2022-03-08 08:45, Marius Amado-Alves wrote: > Behaviour of Ada.Text_IO on GNAT/Windows 11: > > (1) Get_Immediate does not read the CR in CRLF pairs Get_Immediate is only of interest for reading from Standard_Input, primarily when it is the keyboard. It's better to use Get for other cases. Get_Immediate is not well defined for reading line terminators. Whatever the compiler decides to implement is probably correct, and implementation defined. Should it behave like Get, which ignores line terminators? ObjectAda 10.2 ignores the Enter key (10.3 returns CR). Get_Immediate returns the character corresponding to the key pressed. What is the character for the Enter key? GNAT has decided to return LF in that case. Should it behave differently if the input is from a file? Presumably, Get_Immediate should behave the same whether Standard_Input is the keyboard or redirected from a file. > (2) Get_Immediate does not read the ending CRLF pair at all (in loop terminated upon End_Of_File) End_Of_File is defined to return True if all that remains in the file is a line terminator followed by a page terminator (A.10.5). As such, it is broken, since, when reading a file with a null last line, it will return True before the last line is read. In practice, most compilers treat a final line terminator the same, to work with files produced by non-Ada programs. > (3) an extra ending CRLF pair is output Close is defined to call New_page if the file does not already end with a page terminator [ARM A.10.2(3), http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A-10-2.html], and a page is defined to be terminated by a line terminator followed by a page terminator (A.10). GNAT seems to use the same character sequence for line and page terminators, presumably so that text files output with Ada.Text_IO may be read by non-Ada programs. If you've output a single LF as the last thing in a file on Windows, that is not a page terminator, so Close adds one. If you need to see all the bytes in a file, Sequential_IO or Stream_IO are the ways to go. Of course, there is no portable way to read Standard_Input using Sequential_IO. -- Jeff Carter "What's the amount of the insult?" Never Give a Sucker an Even Break 104