utilada_2.6.0_99ca46a1/samples/copy.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
with Ada.Text_IO;
with Ada.Command_Line;
with Ada.Streams.Stream_IO;
with Util.Streams.Files;
procedure Copy is

   procedure Copy_File (Source      : in String;
                        Destination : in String);

   procedure Copy_File (Source      : in String;
                        Destination : in String) is
      In_Stream  : aliased Util.Streams.Files.File_Stream;
      Out_Stream : aliased Util.Streams.Files.File_Stream;
   begin
      In_Stream.Open (Mode => Ada.Streams.Stream_IO.In_File, Name => Source);
      Out_Stream.Create (Mode => Ada.Streams.Stream_IO.Out_File, Name => Destination);
      Util.Streams.Copy (From => In_Stream, Into => Out_Stream);
   end Copy_File;

begin
   if Ada.Command_Line.Argument_Count /= 2 then
      Ada.Text_IO.Put_Line ("Usage: copy source destination");
      return;
   end if;

   Copy_File (Source      => Ada.Command_Line.Argument (1),
              Destination => Ada.Command_Line.Argument (2));
end Copy;