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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable 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!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Out_File , excess line Date: Sun, 31 Jan 2016 13:57:30 +0100 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: LNA1TkTuMxfwTHzeJdi6nA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:29303 Date: 2016-01-31T13:57:30+01:00 List-Id: On 2016-01-31 12:25, Simon Wright wrote: > The standard solution to copying a file would be > > with Ada.Text_IO; use Ada.Text_IO; No, that does not copy a file. That 1) interprets a file context as a text file specific to the given operating system and then 2) writes the interpretation into another file. So it is a file conversion. One solution to copy a file is using Copy_File from Ada.Directories. Another is using Ada.Streams.Stream_IO. Both are not ideal but will work in most cases. E.g. your example with Ada.Streams.Stream_IO: with Ada.Exceptions; use Ada.Exceptions; with Ada.Streams; use Ada.Streams; with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Fanzine is Buffer_Size : constant := 1024; -- Or more Input_File : File_Type; Output_File : File_Type; Buffer : Stream_Element_Array (1..Buffer_Size); Last : Stream_Element_Offset; Count : Stream_Element_Count := 0; begin Open (Input_File, In_File, "fanzine.adb"); begin Create (Output_File, Out_File, "fanzine.adb.copy"); loop Read (Input_File, Buffer, Last); exit when Last < Buffer'First; Count := Count + Last; Write (Output_File, Buffer (Buffer'First..Last)); end loop; exception when End_Error => null; -- Never here end; Close (Output_File); Close (Input_File); Ada.Text_IO.Put_Line ( "Written" & Stream_Element_Count'Image (Count) & " elements" ); exception when Error : others => Ada.Text_IO.Put_Line ("Error " & Exception_Information (Error)); end Fanzine; It is quite simple, if necessary, to detect line ends in a manner compatible with both Windows and Linux systems, given fixed encoding. (Doing that independently of the encoding would probably be impossible, but who cares?) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de