From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!news.astraweb.com!border5.newsrouter.astraweb.com!not-for-mail Date: Mon, 01 Jun 2015 14:31:17 +0930 From: tornenvi User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Windows Text_IO.Get_Line issue References: <9ad1fcdc-cdf9-4ff0-aa7e-051d53b6736a@googlegroups.com> <556bdf2d$0$11110$c3e8da3@news.astraweb.com> In-Reply-To: <556bdf2d$0$11110$c3e8da3@news.astraweb.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <556be720$0$12990$c3e8da3$5496439d@news.astraweb.com> Organization: Unlimited download news at news.astraweb.com NNTP-Posting-Host: 4b1492a5.news.astraweb.com X-Trace: DXC=WiP?PcRL8V0IHnC;ELbe^;L?0kYOcDh@:2AWVo<6C[T2oCSV^?kW357Cj0NWo Xref: news.eternal-september.org comp.lang.ada:26118 Date: 2015-06-01T14:31:17+09:30 List-Id: 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; > ------------------------------------------------------------- > > > > >