text
stringlengths
0
234
Bl, Bd : Integer; -- lookup bits for tl/bd
Nb : Natural; -- number of bit length codes
Nl : Natural; -- number of literal length codes
Nd : Natural; -- number of distance codes
-- literal/length and distance code lengths
Ll : Length_array (0 .. 288 + 32 - 1) := (others => 0);
huft_incomplete : Boolean;
procedure Repeat_length_code (amount : Natural) is
begin
if defined + amount > number_of_lengths then
raise Zip.Zip_file_Error;
end if;
for c in reverse 1 .. amount loop
Ll (defined) := current_length;
defined := defined + 1;
end loop;
end Repeat_length_code;
begin
if some_trace then
pragma Warnings (Off, "this code can never be executed and has been deleted");
Ada.Text_IO.Put_Line ("Begin Inflate_dynamic_block");
pragma Warnings (On, "this code can never be executed and has been deleted");
end if;
-- Read in table lengths
Nl := 257 + UnZ_IO.Bit_buffer.Read_and_dump (5);
Nd := 1 + UnZ_IO.Bit_buffer.Read_and_dump (5);
Nb := 4 + UnZ_IO.Bit_buffer.Read_and_dump (4);
if Nl > 288 or else Nd > 32 then
raise Zip.Zip_file_Error;
end if;
-- Read in bit - length - code lengths.
-- The rest, Ll (Bit_Order (Nb .. 18)), is already = 0
for J in 0 .. Nb - 1 loop
Ll (bit_order (J)) := UnZ_IO.Bit_buffer.Read_and_dump (3);
end loop;
-- Build decoding table for trees --single level, 7 bit lookup
Bl := 7;
begin
HufT_build (
Ll (0 .. 18), 19, empty, empty, Tl, Bl, huft_incomplete
);
if huft_incomplete then
HufT_free (Tl);
raise Zip.Zip_file_Error;
end if;
exception
when others =>
raise Zip.Zip_file_Error;
Function Definition: procedure Inflate is
Function Body: is_last_block : Boolean;
blocks : Positive := 1;
begin
if deflate_e_mode then
copy_lengths_literal (28) := 3; -- instead of 258
extra_bits_literal (28) := 16; -- instead of 0
max_dist := 31;
end if;
loop
Inflate_Block (is_last_block);
exit when is_last_block;
blocks := blocks + 1;
end loop;
UnZ_IO.Flush (UnZ_Glob.slide_index);
UnZ_Glob.slide_index := 0;
if some_trace then
pragma Warnings (Off, "this code can never be executed and has been deleted");
Ada.Text_IO.Put ("# blocks:" & Integer'Image (blocks));
pragma Warnings (On, "this code can never be executed and has been deleted");
end if;
end Inflate;
--------[ Method : BZip2 ] --------
procedure Bunzip2 is
type BZ_Buffer is array (Natural range <>) of Interfaces.Unsigned_8;
procedure Read (b : out BZ_Buffer) is
begin
for i in b'Range loop
exit when UnZ_Glob.Zip_EOF;
UnZ_IO.Read_raw_byte (b (i));
end loop;
end Read;
procedure Write (b : BZ_Buffer) is
begin
for i in b'Range loop
UnZ_Glob.slide (UnZ_Glob.slide_index) := b (i);
UnZ_Glob.slide_index := UnZ_Glob.slide_index + 1;
UnZ_IO.Flush_if_full (UnZ_Glob.slide_index);
end loop;
end Write;
package My_BZip2 is new BZip2