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.1 required=5.0 tests=BAYES_00,PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.4 Path: border2.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Will Ada-95 Programs Written in MS Windows Run in MacOS and Linux Without Some Tweaking. Date: Wed, 11 Dec 2013 00:34:03 +0000 Organization: A noiseless patient Spider Message-ID: References: <1d445f04-b670-444f-9858-55da271fe17a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="aa5206ded37b2ca7f9833bd0a598d69e"; logging-data="4379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Pmwx0FZiDWCwK21D7uP2RBvnBdSCjlr4=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:tD+Qgg1fb8dglybkzMQcdm/s7/E= sha1:rXL/HunekCStvdvOYHEFWoByt3s= Xref: number.nntp.dca.giganews.com comp.lang.ada:184172 Date: 2013-12-11T00:34:03+00:00 List-Id: "Randy Brukardt" writes: > "Simon Wright" wrote in message > news:lywqjf45za.fsf@pushface.org... > ... >> I'm not sure of the best way to get an Ada program not to care what >> sort of input line terminators it's reading. > > I'm surprised that that would be a problem, at least for Unix and > Windows files. It's pretty simple to design Text_IO so that it can > read either properly; that's how Text_IO in Janus/Ada works. (The only > difference for it between Windows and Unix versions is the characters > output by New_Line). GNAT is certainly not as clever as that. On Mac OS X, this program ======================================================================== with Ada.Streams.Stream_IO; with Ada.Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; procedure S is Data_File_Name : constant String := "s.dat"; Text_File : Ada.Text_IO.File_Type; procedure Write_As_Stream (Data : String) is package ASS renames Ada.Streams.Stream_IO; Stream_File : ASS.File_Type; begin ASS.Open (Stream_File, Name => Data_File_Name, Mode => ASS.Out_File); declare Stream_Access : constant ASS.Stream_Access := ASS.Stream (Stream_File); -- the file has to be open already begin String'Write (Stream_Access, Data); end; ASS.Close (Stream_File); end Write_As_Stream; begin Put_Line ("testing \n"); Write_As_Stream (String'(1 => ASCII.LF)); Open (Text_File, Name => Data_File_Name, Mode => In_File); Put_Line ("EOL is " & Boolean'Image (End_Of_Line (Text_File))); Put_Line ("EOF is " & Boolean'Image (End_Of_File (Text_File))); Close (Text_File); Put_Line ("testing \r\n"); Write_As_Stream (String'(1 => ASCII.CR, 2 => ASCII.LF)); Open (Text_File, Name => Data_File_Name, Mode => In_File); Put_Line ("EOL is " & Boolean'Image (End_Of_Line (Text_File))); Put_Line ("EOF is " & Boolean'Image (End_Of_File (Text_File))); Close (Text_File); declare Dummy : Integer; begin Put_Line ("testing \n42"); Write_As_Stream (String'(1 => ASCII.LF) & "42"); Open (Text_File, Name => Data_File_Name, Mode => In_File); Ada.Integer_Text_IO.Get (Text_File, Dummy); Put_Line ("Value is " & Integer'Image (Dummy)); Close (Text_File); end; declare Dummy : Integer; begin Put_Line ("testing \r\n42"); Write_As_Stream (String'(1 => ASCII.CR, 2 => ASCII.LF) & "42"); Open (Text_File, Name => Data_File_Name, Mode => In_File); Ada.Integer_Text_IO.Get (Text_File, Dummy); Put_Line ("Value is " & Integer'Image (Dummy)); Close (Text_File); end; end S; ======================================================================== results in ------------------------------------------------------------------------ testing \n EOL is TRUE EOF is TRUE testing \r\n EOL is FALSE EOF is FALSE testing \n42 Value is 42 testing \r\n42 Execution terminated by unhandled exception Exception name: ADA.IO_EXCEPTIONS.DATA_ERROR ------------------------------------------------------------------------ whereas on a Windows machine I get ------------------------------------------------------------------------ testing \n EOL is TRUE EOF is TRUE testing \r\n EOL is TRUE EOF is TRUE testing \n42 Value is 42 testing \r\n42 Value is 42 ------------------------------------------------------------------------ so I feel a bug report coming on .. > But if you don't want to change the terminators (or your compiler has an > unnecessarily inflexible Text_IO), I'd suggest using Stream_IO. Of course, > then you'll have to do your own buffering of input (but that's usually a > good idea anyway). Yes. Actually I tried Sequential_IO, but for just reading Characters there's not a lot of difference ... is there?