text
stringlengths
0
234
function Remove_leading_binary_1 (n : Integer) return Integer is
x : Integer := 2**16; -- supposed maximum
begin
if n < 1 then
return n;
end if;
while n mod x = n loop
x := x / 2;
end loop;
return n mod x;
end Remove_leading_binary_1;
begin -- Vine_to_tree
leaf_count := Remove_leading_binary_1 (size + 1);
Compression (root, leaf_count); -- create deepest leaves
-- use Perfect_leaves instead for a perfectly balanced tree
size := size - leaf_count;
while size > 1 loop
Compression (root, size / 2);
size := size / 2;
end loop;
end Vine_to_tree;
procedure Rebalance (root : in out p_Dir_node) is
-- Rebalance the binary search tree with root "root.all",
-- with the result also rooted at "root.all".
-- Uses the Tree_to_vine and Vine_to_tree procedures.
pseudo_root : p_Dir_node;
size : Integer;
begin
pseudo_root := new Dir_node (name_len => 0);
pseudo_root.all.right := root;
Tree_to_vine (pseudo_root, size);
Vine_to_tree (pseudo_root, size);
root := pseudo_root.all.right;
Dispose (pseudo_root);
end Rebalance;
end Binary_tree_rebalancing;
-- 19 - Jun - 2001 : Enhanced file name identification
-- a) when case insensitive - > all UPPER (current)
-- b) '\' and '/' identified - > all '/' (new)
function Normalize (s : String; case_sensitive : Boolean) return String is
sn : String (s'Range);
begin
if case_sensitive then
sn := s;
else
sn := Ada.Characters.Handling.To_Upper (s);
end if;
for i in sn'Range loop
if sn (i) = '\' then
sn (i) := '/';
end if;
end loop;
return sn;
end Normalize;
-------------------------------------------------------------
-- Load Zip_info from a stream containing the .zip archive --
-------------------------------------------------------------
procedure Load (info : out Zip_info;
from : Zip_Streams.Zipstream_Class;
case_sensitive : Boolean := False) is
procedure Insert (dico_name : String; -- UPPER if case - insensitive search
file_name : String;
file_index : Ada.Streams.Stream_IO.Positive_Count;
comp_size,
uncomp_size : File_size_type;
crc_32 : Unsigned_32;
date_time : Time;
method : PKZip_method;
unicode_file_name : Boolean;
node : in out p_Dir_node) is
begin
if node = null then
node := new Dir_node'
((name_len => file_name'Length,
left => null,
right => null,
dico_name => dico_name,
file_name => file_name,
file_index => file_index,
comp_size => comp_size,
uncomp_size => uncomp_size,
crc_32 => crc_32,
date_time => date_time,
method => method,
unicode_file_name => unicode_file_name
)
);
elsif dico_name > node.all.dico_name then
Insert (dico_name, file_name, file_index, comp_size, uncomp_size, crc_32, date_time, method, unicode_file_name, node.all.right);
elsif dico_name < node.all.dico_name then
Insert (dico_name, file_name, file_index, comp_size, uncomp_size, crc_32, date_time, method, unicode_file_name, node.all.left);