comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Out_File , excess line
Date: Sun, 31 Jan 2016 13:57:30 +0100
Date: 2016-01-31T13:57:30+01:00	[thread overview]
Message-ID: <n8l0bp$4de$1@gioia.aioe.org> (raw)
In-Reply-To: lya8nmuh2h.fsf@pushface.org

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

  reply	other threads:[~2016-01-31 12:57 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-20  1:39 Out_File , excess line comicfanzine
2016-01-20 11:23 ` AdaMagica
2016-01-20 13:31 ` comicfanzine
2016-01-20 14:03 ` comicfanzine
2016-01-20 14:26   ` Dmitry A. Kazakov
2016-01-20 17:33   ` AdaMagica
2016-01-21  4:50 ` comicfanzine
2016-01-21 10:27   ` Jacob Sparre Andersen
2016-01-21 10:56     ` AdaMagica
2016-01-21 11:57       ` G.B.
2016-01-21 14:42         ` Dmitry A. Kazakov
2016-01-21 16:23           ` AdaMagica
2016-01-22  2:50             ` Dennis Lee Bieber
2016-01-21 13:38   ` Dennis Lee Bieber
2016-01-21 17:30 ` comicfanzine
2016-01-22  1:56   ` comicfanzine
2016-01-22 12:28   ` Brian Drummond
2016-01-22 20:01 ` comicfanzine
2016-01-23 20:06 ` comicfanzine
2016-01-27  9:26   ` Simon Wright
2016-01-27 19:32     ` Simon Wright
2016-01-27 21:31       ` Jeffrey R. Carter
2016-01-27 20:28     ` Dmitry A. Kazakov
2016-01-24 16:11 ` comicfanzine
2016-01-25 21:54 ` comicfanzine
2016-01-25 22:01   ` MM
2016-01-26  0:50     ` comicfanzine
2016-01-26 10:10 ` comicfanzine
2016-01-27  3:57 ` comicfanzine
2016-01-27  8:13   ` AdaMagica
2016-01-28  4:35 ` comicfanzine
2016-01-29 23:04 ` comicfanzine
2016-01-30  9:44 ` Simon Wright
2016-01-30 10:43   ` AdaMagica
2016-01-30 13:51     ` Simon Wright
2016-01-31  8:56 ` comicfanzine
2016-01-31 11:25   ` Simon Wright
2016-01-31 12:57     ` Dmitry A. Kazakov [this message]
2016-01-31 17:00       ` Simon Wright
2016-01-31 11:51   ` AdaMagica
2016-02-01  6:22 ` comicfanzine
2016-02-01  8:32   ` Dmitry A. Kazakov
2016-02-09 15:07 ` comicfanzine
2016-02-09 17:00   ` 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