zipada_56.0.2_b3043499/extras/bwt_dec.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 - decoding
--
--  Caution: stack memory required is the SQUARE of the file size!...
--
--  See BWT_Enc for encoding 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_Dec is
  fi, fo : Ada.Streams.Stream_IO.File_Type;
begin
  if Argument_Count < 3 then
    Put_Line ("Syntax: bwt_dec infile index outfile");
    Put_Line ("The parameter 'index' is the number given by the encoder, bwt_enc.");
    return;
  end if;
  Open (fi, In_File, Argument (1));
  Create (fo, Out_File, Argument (3));
  declare
    msg : String (1 .. Integer (Size (fi)));
    idx : constant Positive := Integer'Value (Argument (2));
  begin
    String'Read (Stream (fi), msg);
    BWT.Decode (msg, idx);
    String'Write (Stream (fo), msg);
  end;
  Close (fi);
  Close (fo);
end BWT_Dec;