zipada_56.0.2_b3043499/extras/bwt_enc.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
29
30
31
32
33
34
--  Burrows-Wheeler data precompression tool - encoding
--
--  Caution: stack memory required is the SQUARE of the file size!...
--
--  See BWT_Dec for decoding and BWT_Demo for a simple demo.
--

with BWT;

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Ada.Command_Line; use Ada.Command_Line;

procedure BWT_Enc is
  fi, fo : Ada.Streams.Stream_IO.File_Type;
begin
  if Argument_Count < 2 then
    Put_Line ("Syntax: bwt_enc infile outfile");
    return;
  end if;
  Open (fi, In_File, Argument (1));
  Create (fo, Out_File, Argument (2));
  declare
    msg : String (1 .. Integer (Size (fi)));
    idx : Positive;
  begin
    String'Read (Stream (fi), msg);
    BWT.Encode (msg, idx);
    String'Write (Stream (fo), msg);
    Put_Line (Current_Error, "Index: " & Integer'Image (idx));
  end;
  Close (fi);
  Close (fo);
end BWT_Enc;