comp.lang.ada
 help / color / mirror / Atom feed
From: tornenvi <tornenvi@gmail.com>
Subject: Re: Windows Text_IO.Get_Line issue
Date: Mon, 01 Jun 2015 14:31:17 +0930
Date: 2015-06-01T14:31:17+09:30	[thread overview]
Message-ID: <556be720$0$12990$c3e8da3$5496439d@news.astraweb.com> (raw)
In-Reply-To: <556bdf2d$0$11110$c3e8da3@news.astraweb.com>

Sorry posted in wrong spot.
Will repost

On 6/1/2015 1:57 PM, tornenvi wrote:
> Hello,
>
>    I have found some unexpected behavior for calls to Ada.Text_IO.Get_Line
>    on windows when reading from a text that has only one line in it.
>
>    The program below simply reads the first line of a text file into a 6
>    character buffer, and outputs the length of the line read, the line and
>    the line again as hex.
>
>    I use windows notepad to create the test file Test.txt.
>
>    When using Test.txt with the one line of text
>     ABCD
>    with no blank line at the end of the file I get output 1 below
>
> -- Output 1 ------------------------------------------------------
> Length=  4
> Line=[ABCDXX]
> Line as hex=[414243445858]
> ------------------------------------------------------------------
>
>    as expected. However if Test.txt is the one line of text
>     ABCDE
>    with no blank line at the end of the file then I get output 2 below
>
> -- Output 2 -----------------------------------------------------
> Length=  6
> Line=[ABCDE ]
> Line as hex=[4142434445ff]
> -----------------------------------------------------------------
>
>    I receive an unexpected length of 6, expected 5. The fact that the last two
>    characters are not 'XX' is acceptable since ARM A.10.7 19 says
>    "The values of characters not assigned are not specified."
>
>    I get the same output 2 if I compile the program with
>    GNAT GPL 2014, 2013,2012 or 2011 or with mingw FSF GNAT 4.7.0-1 or 4.8.1-4.
>
>    However if I compile with mingw FSF GNAT 4.5.2-1 , 4.5.0-1, 4.4.0 or
>    3.4.5 then I get the expected output 3 below
>
> -- Output 3 -----------------------------------------------------
> Length=  5
> Line=[ABCDEX]
> Line as hex=[414243444558]
> -----------------------------------------------------------------
>
>    Under windows the one line text file does not have an end of line
>    character (usually CRLF) which means it is not a canonical text file
>    as described here
>
>    http://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/the_implementation_of_standard_i_o.html#text-io
>
>    however that section also states that text_io can be use to read non canonical text files
>    and the very last line of that section says
>    "Every LF character is considered to end a line, and there is an
>      implied LF character at the end of the file."
>
>    this indicates to me that there should be an implied LF at the end of the
>    file and I should be getting the expected output 3 result for
>    all the compilers.
>
>    Is this a bug in the windows builds of GNAT?
>
>
>
>
>
> ---- Program -----------------------------------------------------
> with Ada.Text_IO;
>
> procedure FileRead is
>
>
>    TestFileName : constant string := "Test.txt";
>    TestFile : Ada.Text_IO.File_Type;
>
>    Line   : string(1..6) := "XXXXXX";
>    Length : natural;
>
>    function ToHex(Msg : string) return string is
>      Hex   : constant array (0..15) of character := "0123456789abcdef";
>      Str   : String(1..Msg'length*2) := (others => ' '); -- 2 hex digits per byte
>      Index : Integer :=1;
>      ByteValue : Integer;
>    begin
>      for i in Msg'Range loop
>        ByteValue := character'Pos(Msg(i));
>        Str(Index) := Hex(ByteValue / 16);
>        Index := Index + 1;
>        Str(Index) := Hex(ByteValue mod 16);
>        Index := Index + 1;
>      end loop;
>      return Str;
>    end;
>
> begin
>
>    Ada.Text_IO.Open( TestFile, Ada.Text_IO.IN_FILE, TestFileName );
>    if not Ada.Text_IO.End_Of_File(TestFile) then
>      Ada.Text_IO.Get_Line( TestFile, Line, Length );
>      Ada.Text_IO.Put_Line("Length= " & integer'image(Length));
>      Ada.Text_IO.Put_Line("Line=[" & Line & "]");
>      Ada.Text_IO.Put_Line("Line as hex=[" & ToHex(Line) & "]");
>    end if;
>
> exception
>
>    when E: others =>
>      Ada.Text_IO.Put_Line("Exception");
>
> end;
> -------------------------------------------------------------
>
>
>
>
>

      reply	other threads:[~2015-06-01  5:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27 19:38 longest path through a task jan.de.kruyf
2015-05-27 20:09 ` Niklas Holsti
2015-05-28  6:54   ` jan.de.kruyf
2015-05-28  9:04     ` Niklas Holsti
2015-05-28 12:27       ` brbarkstrom
2015-05-28 14:01         ` jan.de.kruyf
2015-05-28 13:04       ` jan.de.kruyf
2015-05-29  4:38         ` Niklas Holsti
2015-05-28 16:37     ` Simon Wright
2015-05-28 17:43       ` jan.de.kruyf
2015-05-28 17:52         ` Simon Wright
2015-05-28 18:12           ` jan.de.kruyf
2015-05-29 16:31       ` Simon Wright
2015-05-30 10:50         ` jan.de.kruyf
2015-06-01 13:32         ` Patrick Noffke
2015-06-01 19:09           ` Simon Wright
2015-06-02 22:15           ` Stephen Leake
2015-06-01  4:27   ` Windows Text_IO.Get_Line issue tornenvi
2015-06-01  5:01     ` tornenvi [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox