text stringlengths 0 234 |
|---|
-- Bodies of UnZ_* packages -- |
------------------------------ |
package body UnZ_IO is |
-- Centralize buffer initialisations - 29 - Jun - 2001 |
procedure Init_Buffers is |
begin |
UnZ_Glob.inpos := 0; -- Input buffer position |
UnZ_Glob.readpos := -1; -- Nothing read |
UnZ_Glob.slide_index := 0; |
UnZ_Glob.reachedsize := 0; |
UnZ_Glob.effective_writes := 0; |
UnZ_Glob.Zip_EOF := False; |
Zip.CRC.Init (UnZ_Glob.crc32val); |
Bit_buffer.Init; |
end Init_Buffers; |
procedure Read_buffer is |
begin |
if full_trace then |
pragma Warnings (Off, "this code can never be executed and has been deleted"); |
Ada.Text_IO.Put ("[Read_buffer .. ."); |
pragma Warnings (On, "this code can never be executed and has been deleted"); |
end if; |
if UnZ_Glob.reachedsize > UnZ_Glob.compsize + 2 then |
-- + 2 : last code is smaller than requested! |
UnZ_Glob.readpos := UnZ_Glob.inbuf'Length; |
-- Simulates reading - > no blocking |
UnZ_Glob.Zip_EOF := True; |
else |
begin |
Zip.BlockRead ( |
stream => zip_file, |
buffer => UnZ_Glob.inbuf, |
actually_read => UnZ_Glob.readpos |
); |
exception |
when others => -- I/O error |
UnZ_Glob.readpos := UnZ_Glob.inbuf'Length; |
-- Simulates reading - > CRC error |
UnZ_Glob.Zip_EOF := True; |
Function Definition: procedure Init is |
Function Body: begin |
B := 0; |
K := 0; |
end Init; |
procedure Need (n : Natural) is |
pragma Inline (Need); |
bt : Zip.Byte; |
begin |
while K < n loop |
Read_raw_byte (bt); |
B := B or Shift_Left (Unsigned_32 (bt), K); |
K := K + 8; |
end loop; |
end Need; |
procedure Dump (n : Natural) is |
begin |
B := Shift_Right (B, n); |
K := K - n; |
end Dump; |
procedure Dump_to_byte_boundary is |
begin |
Dump (K mod 8); |
end Dump_to_byte_boundary; |
function Read_U32 (n : Natural) return Unsigned_32 is |
begin |
Need (n); |
return B and (Shift_Left (1, n) - 1); |
end Read_U32; |
function Read_inverted (n : Natural) return Integer is |
begin |
Need (n); |
return Integer ((not B) and (Shift_Left (1, n) - 1)); |
end Read_inverted; |
function Read (n : Natural) return Integer is |
begin |
return Integer (Read_U32 (n)); |
end Read; |
function Read_and_dump (n : Natural) return Integer is |
res : Integer; |
begin |
res := Read (n); |
Dump (n); |
return res; |
end Read_and_dump; |
function Read_and_dump_U32 (n : Natural) return Unsigned_32 is |
res : Unsigned_32; |
begin |
res := Read_U32 (n); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.