From: "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not>
Subject: Re: Get_Immediate does not read CR in CRLF pairs
Date: Tue, 8 Mar 2022 10:06:02 +0100 [thread overview]
Message-ID: <t0769t$id9$1@dont-email.me> (raw)
In-Reply-To: <1bd9b7ee-9195-44b3-8de2-c018a44b7eden@googlegroups.com>
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
next prev parent reply other threads:[~2022-03-08 9:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-08 7:45 Get_Immediate does not read CR in CRLF pairs Marius Amado-Alves
2022-03-08 7:46 ` Luke A. Guest
2022-03-08 12:08 ` Marius Amado-Alves
2022-03-08 14:57 ` Luke A. Guest
2022-03-08 16:43 ` Marius Amado-Alves
2022-03-08 17:21 ` Dennis Lee Bieber
2022-03-08 17:26 ` Dennis Lee Bieber
2022-03-09 9:11 ` Luke A. Guest
2022-03-08 8:03 ` Dmitry A. Kazakov
2022-03-08 9:06 ` Jeffrey R.Carter [this message]
2022-03-08 12:20 ` Marius Amado-Alves
2022-03-08 12:53 ` Dmitry A. Kazakov
2022-03-09 11:26 ` Marius Amado-Alves
2022-03-09 12:54 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox