source upload
This commit is contained in:
1165
contrib/fundamentals/ZLib/flcZLib.pas
Normal file
1165
contrib/fundamentals/ZLib/flcZLib.pas
Normal file
File diff suppressed because it is too large
Load Diff
117
contrib/fundamentals/ZLib/paszlib/Adler.pas
Normal file
117
contrib/fundamentals/ZLib/paszlib/Adler.pas
Normal file
@@ -0,0 +1,117 @@
|
||||
Unit Adler;
|
||||
|
||||
{
|
||||
adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
Copyright (C) 1995-1998 Mark Adler
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
uses
|
||||
ZUtil;
|
||||
|
||||
function adler32(adler : uLong; buf : pBytef; len : uInt) : uLong;
|
||||
|
||||
{ Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||
return the updated checksum. If buf is NIL, this function returns
|
||||
the required initial value for the checksum.
|
||||
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
|
||||
much faster. Usage example:
|
||||
|
||||
var
|
||||
adler : uLong;
|
||||
begin
|
||||
adler := adler32(0, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) <> EOF) do
|
||||
adler := adler32(adler, buffer, length);
|
||||
|
||||
if (adler <> original_adler) then
|
||||
error();
|
||||
end;
|
||||
}
|
||||
|
||||
implementation
|
||||
|
||||
const
|
||||
BASE = uLong(65521); { largest prime smaller than 65536 }
|
||||
{NMAX = 5552; original code with unsigned 32 bit integer }
|
||||
{ NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 }
|
||||
NMAX = 3854; { code with signed 32 bit integer }
|
||||
{ NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^31-1 }
|
||||
{ The penalty is the time loss in the extra MOD-calls. }
|
||||
|
||||
|
||||
{ ========================================================================= }
|
||||
|
||||
function adler32(adler : uLong; buf : pBytef; len : uInt) : uLong;
|
||||
var
|
||||
s1, s2 : uLong;
|
||||
k : int;
|
||||
begin
|
||||
s1 := adler and $ffff;
|
||||
s2 := (adler shr 16) and $ffff;
|
||||
|
||||
if not Assigned(buf) then
|
||||
begin
|
||||
adler32 := uLong(1);
|
||||
exit;
|
||||
end;
|
||||
|
||||
while (len > 0) do
|
||||
begin
|
||||
if len < NMAX then
|
||||
k := len
|
||||
else
|
||||
k := NMAX;
|
||||
Dec(len, k);
|
||||
{
|
||||
while (k >= 16) do
|
||||
begin
|
||||
DO16(buf);
|
||||
Inc(buf, 16);
|
||||
Dec(k, 16);
|
||||
end;
|
||||
if (k <> 0) then
|
||||
repeat
|
||||
Inc(s1, buf^);
|
||||
Inc(puf);
|
||||
Inc(s2, s1);
|
||||
Dec(k);
|
||||
until (k = 0);
|
||||
}
|
||||
while (k > 0) do
|
||||
begin
|
||||
Inc(s1, buf^);
|
||||
Inc(s2, s1);
|
||||
Inc(buf);
|
||||
Dec(k);
|
||||
end;
|
||||
s1 := s1 mod BASE;
|
||||
s2 := s2 mod BASE;
|
||||
end;
|
||||
adler32 := (s2 shl 16) or s1;
|
||||
end;
|
||||
|
||||
{
|
||||
#define DO1(buf,i)
|
||||
begin
|
||||
Inc(s1, buf[i]);
|
||||
Inc(s2, s1);
|
||||
end;
|
||||
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||
}
|
||||
end.
|
||||
|
||||
239
contrib/fundamentals/ZLib/paszlib/Crc.pas
Normal file
239
contrib/fundamentals/ZLib/paszlib/Crc.pas
Normal file
@@ -0,0 +1,239 @@
|
||||
Unit Crc;
|
||||
{
|
||||
crc32.c -- compute the CRC-32 of a data stream
|
||||
Copyright (C) 1995-1998 Mark Adler
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
uses
|
||||
ZUtil, gZlib;
|
||||
|
||||
|
||||
function crc32(crc : uLong; buf : pBytef; len : uInt) : uLong;
|
||||
|
||||
{ Update a running crc with the bytes buf[0..len-1] and return the updated
|
||||
crc. If buf is NULL, this function returns the required initial value
|
||||
for the crc. Pre- and post-conditioning (one's complement) is performed
|
||||
within this function so it shouldn't be done by the application.
|
||||
Usage example:
|
||||
|
||||
var
|
||||
crc : uLong;
|
||||
begin
|
||||
crc := crc32(0, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) <> EOF) do
|
||||
crc := crc32(crc, buffer, length);
|
||||
|
||||
if (crc <> original_crc) then error();
|
||||
end;
|
||||
|
||||
}
|
||||
|
||||
function get_crc_table : puLong; { can be used by asm versions of crc32() }
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
{$IFDEF DYNAMIC_CRC_TABLE}
|
||||
|
||||
{local}
|
||||
const
|
||||
crc_table_empty : boolean = TRUE;
|
||||
{local}
|
||||
var
|
||||
crc_table : array[0..256-1] of uLongf;
|
||||
|
||||
|
||||
{
|
||||
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
||||
|
||||
Polynomials over GF(2) are represented in binary, one bit per coefficient,
|
||||
with the lowest powers in the most significant bit. Then adding polynomials
|
||||
is just exclusive-or, and multiplying a polynomial by x is a right shift by
|
||||
one. If we call the above polynomial p, and represent a byte as the
|
||||
polynomial q, also with the lowest power in the most significant bit (so the
|
||||
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
|
||||
where a mod b means the remainder after dividing a by b.
|
||||
|
||||
This calculation is done using the shift-register method of multiplying and
|
||||
taking the remainder. The register is initialized to zero, and for each
|
||||
incoming bit, x^32 is added mod p to the register if the bit is a one (where
|
||||
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
|
||||
x (which is shifting right by one and adding x^32 mod p if the bit shifted
|
||||
out is a one). We start with the highest power (least significant bit) of
|
||||
q and repeat for all eight bits of q.
|
||||
|
||||
The table is simply the CRC of all possible eight bit values. This is all
|
||||
the information needed to generate CRC's on data a byte at a time for all
|
||||
combinations of CRC register values and incoming bytes.
|
||||
}
|
||||
{local}
|
||||
procedure make_crc_table;
|
||||
var
|
||||
c : uLong;
|
||||
n,k : int;
|
||||
poly : uLong; { polynomial exclusive-or pattern }
|
||||
|
||||
const
|
||||
{ terms of polynomial defining this crc (except x^32): }
|
||||
p: array [0..13] of Byte = (0,1,2,4,5,7,8,10,11,12,16,22,23,26);
|
||||
|
||||
begin
|
||||
{ make exclusive-or pattern from polynomial ($EDB88320) }
|
||||
poly := Long(0);
|
||||
for n := 0 to (sizeof(p) div sizeof(Byte))-1 do
|
||||
poly := poly or (Long(1) shl (31 - p[n]));
|
||||
|
||||
for n := 0 to 255 do
|
||||
begin
|
||||
c := uLong(n);
|
||||
for k := 0 to 7 do
|
||||
begin
|
||||
if (c and 1) <> 0 then
|
||||
c := poly xor (c shr 1)
|
||||
else
|
||||
c := (c shr 1);
|
||||
end;
|
||||
crc_table[n] := c;
|
||||
end;
|
||||
crc_table_empty := FALSE;
|
||||
end;
|
||||
|
||||
{$ELSE}
|
||||
|
||||
{ ========================================================================
|
||||
Table of CRC-32's of all single-byte values (made by make_crc_table) }
|
||||
|
||||
{local}
|
||||
const
|
||||
crc_table : array[0..255] of uLongf = (
|
||||
$00000000, $77073096, $ee0e612c, $990951ba, $076dc419,
|
||||
$706af48f, $e963a535, $9e6495a3, $0edb8832, $79dcb8a4,
|
||||
$e0d5e91e, $97d2d988, $09b64c2b, $7eb17cbd, $e7b82d07,
|
||||
$90bf1d91, $1db71064, $6ab020f2, $f3b97148, $84be41de,
|
||||
$1adad47d, $6ddde4eb, $f4d4b551, $83d385c7, $136c9856,
|
||||
$646ba8c0, $fd62f97a, $8a65c9ec, $14015c4f, $63066cd9,
|
||||
$fa0f3d63, $8d080df5, $3b6e20c8, $4c69105e, $d56041e4,
|
||||
$a2677172, $3c03e4d1, $4b04d447, $d20d85fd, $a50ab56b,
|
||||
$35b5a8fa, $42b2986c, $dbbbc9d6, $acbcf940, $32d86ce3,
|
||||
$45df5c75, $dcd60dcf, $abd13d59, $26d930ac, $51de003a,
|
||||
$c8d75180, $bfd06116, $21b4f4b5, $56b3c423, $cfba9599,
|
||||
$b8bda50f, $2802b89e, $5f058808, $c60cd9b2, $b10be924,
|
||||
$2f6f7c87, $58684c11, $c1611dab, $b6662d3d, $76dc4190,
|
||||
$01db7106, $98d220bc, $efd5102a, $71b18589, $06b6b51f,
|
||||
$9fbfe4a5, $e8b8d433, $7807c9a2, $0f00f934, $9609a88e,
|
||||
$e10e9818, $7f6a0dbb, $086d3d2d, $91646c97, $e6635c01,
|
||||
$6b6b51f4, $1c6c6162, $856530d8, $f262004e, $6c0695ed,
|
||||
$1b01a57b, $8208f4c1, $f50fc457, $65b0d9c6, $12b7e950,
|
||||
$8bbeb8ea, $fcb9887c, $62dd1ddf, $15da2d49, $8cd37cf3,
|
||||
$fbd44c65, $4db26158, $3ab551ce, $a3bc0074, $d4bb30e2,
|
||||
$4adfa541, $3dd895d7, $a4d1c46d, $d3d6f4fb, $4369e96a,
|
||||
$346ed9fc, $ad678846, $da60b8d0, $44042d73, $33031de5,
|
||||
$aa0a4c5f, $dd0d7cc9, $5005713c, $270241aa, $be0b1010,
|
||||
$c90c2086, $5768b525, $206f85b3, $b966d409, $ce61e49f,
|
||||
$5edef90e, $29d9c998, $b0d09822, $c7d7a8b4, $59b33d17,
|
||||
$2eb40d81, $b7bd5c3b, $c0ba6cad, $edb88320, $9abfb3b6,
|
||||
$03b6e20c, $74b1d29a, $ead54739, $9dd277af, $04db2615,
|
||||
$73dc1683, $e3630b12, $94643b84, $0d6d6a3e, $7a6a5aa8,
|
||||
$e40ecf0b, $9309ff9d, $0a00ae27, $7d079eb1, $f00f9344,
|
||||
$8708a3d2, $1e01f268, $6906c2fe, $f762575d, $806567cb,
|
||||
$196c3671, $6e6b06e7, $fed41b76, $89d32be0, $10da7a5a,
|
||||
$67dd4acc, $f9b9df6f, $8ebeeff9, $17b7be43, $60b08ed5,
|
||||
$d6d6a3e8, $a1d1937e, $38d8c2c4, $4fdff252, $d1bb67f1,
|
||||
$a6bc5767, $3fb506dd, $48b2364b, $d80d2bda, $af0a1b4c,
|
||||
$36034af6, $41047a60, $df60efc3, $a867df55, $316e8eef,
|
||||
$4669be79, $cb61b38c, $bc66831a, $256fd2a0, $5268e236,
|
||||
$cc0c7795, $bb0b4703, $220216b9, $5505262f, $c5ba3bbe,
|
||||
$b2bd0b28, $2bb45a92, $5cb36a04, $c2d7ffa7, $b5d0cf31,
|
||||
$2cd99e8b, $5bdeae1d, $9b64c2b0, $ec63f226, $756aa39c,
|
||||
$026d930a, $9c0906a9, $eb0e363f, $72076785, $05005713,
|
||||
$95bf4a82, $e2b87a14, $7bb12bae, $0cb61b38, $92d28e9b,
|
||||
$e5d5be0d, $7cdcefb7, $0bdbdf21, $86d3d2d4, $f1d4e242,
|
||||
$68ddb3f8, $1fda836e, $81be16cd, $f6b9265b, $6fb077e1,
|
||||
$18b74777, $88085ae6, $ff0f6a70, $66063bca, $11010b5c,
|
||||
$8f659eff, $f862ae69, $616bffd3, $166ccf45, $a00ae278,
|
||||
$d70dd2ee, $4e048354, $3903b3c2, $a7672661, $d06016f7,
|
||||
$4969474d, $3e6e77db, $aed16a4a, $d9d65adc, $40df0b66,
|
||||
$37d83bf0, $a9bcae53, $debb9ec5, $47b2cf7f, $30b5ffe9,
|
||||
$bdbdf21c, $cabac28a, $53b39330, $24b4a3a6, $bad03605,
|
||||
$cdd70693, $54de5729, $23d967bf, $b3667a2e, $c4614ab8,
|
||||
$5d681b02, $2a6f2b94, $b40bbe37, $c30c8ea1, $5a05df1b,
|
||||
$2d02ef8d);
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
{ =========================================================================
|
||||
This function can be used by asm versions of crc32() }
|
||||
|
||||
function get_crc_table : {const} puLong;
|
||||
begin
|
||||
{$ifdef DYNAMIC_CRC_TABLE}
|
||||
if (crc_table_empty) then
|
||||
make_crc_table;
|
||||
{$endif}
|
||||
get_crc_table := {const} puLong(@crc_table);
|
||||
end;
|
||||
|
||||
{ ========================================================================= }
|
||||
|
||||
function crc32 (crc : uLong; buf : pBytef; len : uInt): uLong;
|
||||
begin
|
||||
if (buf = Z_NULL) then
|
||||
crc32 := Long(0)
|
||||
else
|
||||
begin
|
||||
|
||||
{$IFDEF DYNAMIC_CRC_TABLE}
|
||||
if crc_table_empty then
|
||||
make_crc_table;
|
||||
{$ENDIF}
|
||||
|
||||
crc := crc xor uLong($ffffffff);
|
||||
while (len >= 8) do
|
||||
begin
|
||||
{DO8(buf)}
|
||||
crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
|
||||
inc(buf);
|
||||
crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
|
||||
inc(buf);
|
||||
crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
|
||||
inc(buf);
|
||||
crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
|
||||
inc(buf);
|
||||
crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
|
||||
inc(buf);
|
||||
crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
|
||||
inc(buf);
|
||||
crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
|
||||
inc(buf);
|
||||
crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
|
||||
inc(buf);
|
||||
|
||||
Dec(len, 8);
|
||||
end;
|
||||
if (len <> 0) then
|
||||
repeat
|
||||
{DO1(buf)}
|
||||
crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
|
||||
inc(buf);
|
||||
|
||||
Dec(len);
|
||||
until (len = 0);
|
||||
crc32 := crc xor uLong($ffffffff);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
952
contrib/fundamentals/ZLib/paszlib/InfBlock.pas
Normal file
952
contrib/fundamentals/ZLib/paszlib/InfBlock.pas
Normal file
@@ -0,0 +1,952 @@
|
||||
Unit InfBlock;
|
||||
|
||||
{ infblock.h and
|
||||
infblock.c -- interpret and process block types to last block
|
||||
Copyright (C) 1995-1998 Mark Adler
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
{.DEFINE INFBLOCK_DEBUG}
|
||||
|
||||
uses zutil, gzlib;
|
||||
|
||||
function inflate_blocks_new(var z : z_stream;
|
||||
c : check_func; { check function }
|
||||
w : uInt { window size }
|
||||
) : pInflate_blocks_state;
|
||||
|
||||
function inflate_blocks (var s : inflate_blocks_state;
|
||||
var z : z_stream;
|
||||
r : int { initial return code }
|
||||
) : int;
|
||||
|
||||
procedure inflate_blocks_reset (var s : inflate_blocks_state;
|
||||
var z : z_stream;
|
||||
c : puLong); { check value on output }
|
||||
|
||||
|
||||
function inflate_blocks_free(s : pInflate_blocks_state;
|
||||
var z : z_stream) : int;
|
||||
|
||||
procedure inflate_set_dictionary(var s : inflate_blocks_state;
|
||||
const d : array of byte; { dictionary }
|
||||
n : uInt); { dictionary length }
|
||||
|
||||
function inflate_blocks_sync_point(var s : inflate_blocks_state) : int;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
InfCodes, InfTrees, InfUtil;
|
||||
|
||||
{ Tables for deflate from PKZIP's appnote.txt. }
|
||||
Const
|
||||
border : Array [0..18] Of Word { Order of the bit length code lengths }
|
||||
= (16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);
|
||||
|
||||
{ Notes beyond the 1.93a appnote.txt:
|
||||
|
||||
1. Distance pointers never point before the beginning of the output
|
||||
stream.
|
||||
2. Distance pointers can point back across blocks, up to 32k away.
|
||||
3. There is an implied maximum of 7 bits for the bit length table and
|
||||
15 bits for the actual data.
|
||||
4. If only one code exists, then it is encoded using one bit. (Zero
|
||||
would be more efficient, but perhaps a little confusing.) If two
|
||||
codes exist, they are coded using one bit each (0 and 1).
|
||||
5. There is no way of sending zero distance codes--a dummy must be
|
||||
sent if there are none. (History: a pre 2.0 version of PKZIP would
|
||||
store blocks with no distance codes, but this was discovered to be
|
||||
too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
|
||||
zero distance codes, which is sent as one code of zero bits in
|
||||
length.
|
||||
6. There are up to 286 literal/length codes. Code 256 represents the
|
||||
end-of-block. Note however that the static length tree defines
|
||||
288 codes just to fill out the Huffman codes. Codes 286 and 287
|
||||
cannot be used though, since there is no length base or extra bits
|
||||
defined for them. Similarily, there are up to 30 distance codes.
|
||||
However, static trees define 32 codes (all 5 bits) to fill out the
|
||||
Huffman codes, but the last two had better not show up in the data.
|
||||
7. Unzip can check dynamic Huffman blocks for complete code sets.
|
||||
The exception is that a single code would not be complete (see #4).
|
||||
8. The five bits following the block type is really the number of
|
||||
literal codes sent minus 257.
|
||||
9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
|
||||
(1+6+6). Therefore, to output three times the length, you output
|
||||
three codes (1+1+1), whereas to output four times the same length,
|
||||
you only need two codes (1+3). Hmm.
|
||||
10. In the tree reconstruction algorithm, Code = Code + Increment
|
||||
only if BitLength(i) is not zero. (Pretty obvious.)
|
||||
11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
|
||||
12. Note: length code 284 can represent 227-258, but length code 285
|
||||
really is 258. The last length deserves its own, short code
|
||||
since it gets used a lot in very redundant files. The length
|
||||
258 is special since 258 - 3 (the min match length) is 255.
|
||||
13. The literal/length and distance code bit lengths are read as a
|
||||
single stream of lengths. It is possible (and advantageous) for
|
||||
a repeat code (16, 17, or 18) to go across the boundary between
|
||||
the two sets of lengths. }
|
||||
|
||||
|
||||
procedure inflate_blocks_reset (var s : inflate_blocks_state;
|
||||
var z : z_stream;
|
||||
c : puLong); { check value on output }
|
||||
begin
|
||||
if (c <> Z_NULL) then
|
||||
c^ := s.check;
|
||||
if (s.mode = BTREE) or (s.mode = DTREE) then
|
||||
ZFREE(z, s.sub.trees.blens);
|
||||
if (s.mode = CODES) then
|
||||
inflate_codes_free(s.sub.decode.codes, z);
|
||||
|
||||
s.mode := ZTYPE;
|
||||
s.bitk := 0;
|
||||
s.bitb := 0;
|
||||
|
||||
s.write := s.window;
|
||||
s.read := s.window;
|
||||
if Assigned(s.checkfn) then
|
||||
begin
|
||||
s.check := s.checkfn(uLong(0), pBytef(NIL), 0);
|
||||
z.adler := s.check;
|
||||
end;
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
Tracev('inflate: blocks reset');
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
||||
function inflate_blocks_new(var z : z_stream;
|
||||
c : check_func; { check function }
|
||||
w : uInt { window size }
|
||||
) : pInflate_blocks_state;
|
||||
var
|
||||
s : pInflate_blocks_state;
|
||||
begin
|
||||
s := pInflate_blocks_state( ZALLOC(z,1, sizeof(inflate_blocks_state)) );
|
||||
if (s = Z_NULL) then
|
||||
begin
|
||||
inflate_blocks_new := s;
|
||||
exit;
|
||||
end;
|
||||
s^.hufts := huft_ptr( ZALLOC(z, sizeof(inflate_huft), MANY) );
|
||||
|
||||
if (s^.hufts = Z_NULL) then
|
||||
begin
|
||||
ZFREE(z, s);
|
||||
inflate_blocks_new := Z_NULL;
|
||||
exit;
|
||||
end;
|
||||
|
||||
s^.window := pBytef( ZALLOC(z, 1, w) );
|
||||
if (s^.window = Z_NULL) then
|
||||
begin
|
||||
ZFREE(z, s^.hufts);
|
||||
ZFREE(z, s);
|
||||
inflate_blocks_new := Z_NULL;
|
||||
exit;
|
||||
end;
|
||||
s^.zend := s^.window;
|
||||
Inc(s^.zend, w);
|
||||
s^.checkfn := c;
|
||||
s^.mode := ZTYPE;
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
Tracev('inflate: blocks allocated');
|
||||
{$ENDIF}
|
||||
inflate_blocks_reset(s^, z, Z_NULL);
|
||||
inflate_blocks_new := s;
|
||||
end;
|
||||
|
||||
|
||||
function inflate_blocks (var s : inflate_blocks_state;
|
||||
var z : z_stream;
|
||||
r : int) : int; { initial return code }
|
||||
label
|
||||
start_btree, start_dtree,
|
||||
start_blkdone, start_dry,
|
||||
start_codes;
|
||||
|
||||
var
|
||||
t : uInt; { temporary storage }
|
||||
b : uLong; { bit buffer }
|
||||
k : uInt; { bits in bit buffer }
|
||||
p : pBytef; { input data pointer }
|
||||
n : uInt; { bytes available there }
|
||||
q : pBytef; { output window write pointer }
|
||||
m : uInt; { bytes to end of window or read pointer }
|
||||
{ fixed code blocks }
|
||||
var
|
||||
bl, bd : uInt;
|
||||
tl, td : pInflate_huft;
|
||||
var
|
||||
h : pInflate_huft;
|
||||
i, j, c : uInt;
|
||||
var
|
||||
cs : pInflate_codes_state;
|
||||
begin
|
||||
{ copy input/output information to locals }
|
||||
p := z.next_in;
|
||||
n := z.avail_in;
|
||||
b := s.bitb;
|
||||
k := s.bitk;
|
||||
q := s.write;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
|
||||
{ decompress an inflated block }
|
||||
|
||||
|
||||
{ process input based on current state }
|
||||
while True do
|
||||
Case s.mode of
|
||||
ZTYPE:
|
||||
begin
|
||||
{NEEDBITS(3);}
|
||||
while (k < 3) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
|
||||
t := uInt(b) and 7;
|
||||
s.last := boolean(t and 1);
|
||||
case (t shr 1) of
|
||||
0: { stored }
|
||||
begin
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
if s.last then
|
||||
Tracev('inflate: stored block (last)')
|
||||
else
|
||||
Tracev('inflate: stored block');
|
||||
{$ENDIF}
|
||||
{DUMPBITS(3);}
|
||||
b := b shr 3;
|
||||
Dec(k, 3);
|
||||
|
||||
t := k and 7; { go to byte boundary }
|
||||
{DUMPBITS(t);}
|
||||
b := b shr t;
|
||||
Dec(k, t);
|
||||
|
||||
s.mode := LENS; { get length of stored block }
|
||||
end;
|
||||
1: { fixed }
|
||||
begin
|
||||
begin
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
if s.last then
|
||||
Tracev('inflate: fixed codes blocks (last)')
|
||||
else
|
||||
Tracev('inflate: fixed codes blocks');
|
||||
{$ENDIF}
|
||||
inflate_trees_fixed(bl, bd, tl, td, z);
|
||||
s.sub.decode.codes := inflate_codes_new(bl, bd, tl, td, z);
|
||||
if (s.sub.decode.codes = Z_NULL) then
|
||||
begin
|
||||
r := Z_MEM_ERROR;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
{DUMPBITS(3);}
|
||||
b := b shr 3;
|
||||
Dec(k, 3);
|
||||
|
||||
s.mode := CODES;
|
||||
end;
|
||||
2: { dynamic }
|
||||
begin
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
if s.last then
|
||||
Tracev('inflate: dynamic codes block (last)')
|
||||
else
|
||||
Tracev('inflate: dynamic codes block');
|
||||
{$ENDIF}
|
||||
{DUMPBITS(3);}
|
||||
b := b shr 3;
|
||||
Dec(k, 3);
|
||||
|
||||
s.mode := TABLE;
|
||||
end;
|
||||
3:
|
||||
begin { illegal }
|
||||
{DUMPBITS(3);}
|
||||
b := b shr 3;
|
||||
Dec(k, 3);
|
||||
|
||||
s.mode := BLKBAD;
|
||||
z.msg := 'invalid block type';
|
||||
r := Z_DATA_ERROR;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
LENS:
|
||||
begin
|
||||
{NEEDBITS(32);}
|
||||
while (k < 32) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
|
||||
if (((not b) shr 16) and $ffff) <> (b and $ffff) then
|
||||
begin
|
||||
s.mode := BLKBAD;
|
||||
z.msg := 'invalid stored block lengths';
|
||||
r := Z_DATA_ERROR;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
s.sub.left := uInt(b) and $ffff;
|
||||
k := 0;
|
||||
b := 0; { dump bits }
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
Tracev('inflate: stored length '+IntToStr(s.sub.left));
|
||||
{$ENDIF}
|
||||
if s.sub.left <> 0 then
|
||||
s.mode := STORED
|
||||
else
|
||||
if s.last then
|
||||
s.mode := DRY
|
||||
else
|
||||
s.mode := ZTYPE;
|
||||
end;
|
||||
STORED:
|
||||
begin
|
||||
if (n = 0) then
|
||||
begin
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
{NEEDOUT}
|
||||
if (m = 0) then
|
||||
begin
|
||||
{WRAP}
|
||||
if (q = s.zend) and (s.read <> s.window) then
|
||||
begin
|
||||
q := s.window;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
end;
|
||||
|
||||
if (m = 0) then
|
||||
begin
|
||||
{FLUSH}
|
||||
s.write := q;
|
||||
r := inflate_flush(s,z,r);
|
||||
q := s.write;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
|
||||
{WRAP}
|
||||
if (q = s.zend) and (s.read <> s.window) then
|
||||
begin
|
||||
q := s.window;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
end;
|
||||
|
||||
if (m = 0) then
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
r := Z_OK;
|
||||
|
||||
t := s.sub.left;
|
||||
if (t > n) then
|
||||
t := n;
|
||||
if (t > m) then
|
||||
t := m;
|
||||
zmemcpy(q, p, t);
|
||||
Inc(p, t); Dec(n, t);
|
||||
Inc(q, t); Dec(m, t);
|
||||
Dec(s.sub.left, t);
|
||||
if (s.sub.left = 0) then
|
||||
begin
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
if (ptr2int(q) >= ptr2int(s.read)) then
|
||||
Tracev('inflate: stored end '+
|
||||
IntToStr(z.total_out + ptr2int(q) - ptr2int(s.read)) + ' total out')
|
||||
else
|
||||
Tracev('inflate: stored end '+
|
||||
IntToStr(z.total_out + ptr2int(s.zend) - ptr2int(s.read) +
|
||||
ptr2int(q) - ptr2int(s.window)) + ' total out');
|
||||
{$ENDIF}
|
||||
if s.last then
|
||||
s.mode := DRY
|
||||
else
|
||||
s.mode := ZTYPE;
|
||||
end;
|
||||
end;
|
||||
TABLE:
|
||||
begin
|
||||
{NEEDBITS(14);}
|
||||
while (k < 14) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
|
||||
t := uInt(b) and $3fff;
|
||||
s.sub.trees.table := t;
|
||||
{$ifndef PKZIP_BUG_WORKAROUND}
|
||||
if ((t and $1f) > 29) or (((t shr 5) and $1f) > 29) then
|
||||
begin
|
||||
s.mode := BLKBAD;
|
||||
z.msg := 'too many length or distance symbols';
|
||||
r := Z_DATA_ERROR;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
{$endif}
|
||||
t := 258 + (t and $1f) + ((t shr 5) and $1f);
|
||||
s.sub.trees.blens := puIntArray( ZALLOC(z, t, sizeof(uInt)) );
|
||||
if (s.sub.trees.blens = Z_NULL) then
|
||||
begin
|
||||
r := Z_MEM_ERROR;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
{DUMPBITS(14);}
|
||||
b := b shr 14;
|
||||
Dec(k, 14);
|
||||
|
||||
s.sub.trees.index := 0;
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
Tracev('inflate: table sizes ok');
|
||||
{$ENDIF}
|
||||
s.mode := BTREE;
|
||||
{ fall trough case is handled by the while }
|
||||
{ try GOTO for speed - Nomssi }
|
||||
goto start_btree;
|
||||
end;
|
||||
BTREE:
|
||||
begin
|
||||
start_btree:
|
||||
while (s.sub.trees.index < 4 + (s.sub.trees.table shr 10)) do
|
||||
begin
|
||||
{NEEDBITS(3);}
|
||||
while (k < 3) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
|
||||
s.sub.trees.blens^[border[s.sub.trees.index]] := uInt(b) and 7;
|
||||
Inc(s.sub.trees.index);
|
||||
{DUMPBITS(3);}
|
||||
b := b shr 3;
|
||||
Dec(k, 3);
|
||||
end;
|
||||
while (s.sub.trees.index < 19) do
|
||||
begin
|
||||
s.sub.trees.blens^[border[s.sub.trees.index]] := 0;
|
||||
Inc(s.sub.trees.index);
|
||||
end;
|
||||
s.sub.trees.bb := 7;
|
||||
t := inflate_trees_bits(s.sub.trees.blens^, s.sub.trees.bb,
|
||||
s.sub.trees.tb, s.hufts^, z);
|
||||
if (t <> Z_OK) then
|
||||
begin
|
||||
ZFREE(z, s.sub.trees.blens);
|
||||
r := t;
|
||||
if (r = Z_DATA_ERROR) then
|
||||
s.mode := BLKBAD;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
s.sub.trees.index := 0;
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
Tracev('inflate: bits tree ok');
|
||||
{$ENDIF}
|
||||
s.mode := DTREE;
|
||||
{ fall through again }
|
||||
goto start_dtree;
|
||||
end;
|
||||
DTREE:
|
||||
begin
|
||||
start_dtree:
|
||||
while TRUE do
|
||||
begin
|
||||
t := s.sub.trees.table;
|
||||
if not (s.sub.trees.index < 258 +
|
||||
(t and $1f) + ((t shr 5) and $1f)) then
|
||||
break;
|
||||
t := s.sub.trees.bb;
|
||||
{NEEDBITS(t);}
|
||||
while (k < t) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
|
||||
h := s.sub.trees.tb;
|
||||
Inc(h, uInt(b) and inflate_mask[t]);
|
||||
t := h^.Bits;
|
||||
c := h^.Base;
|
||||
|
||||
if (c < 16) then
|
||||
begin
|
||||
{DUMPBITS(t);}
|
||||
b := b shr t;
|
||||
Dec(k, t);
|
||||
|
||||
s.sub.trees.blens^[s.sub.trees.index] := c;
|
||||
Inc(s.sub.trees.index);
|
||||
end
|
||||
else { c = 16..18 }
|
||||
begin
|
||||
if c = 18 then
|
||||
begin
|
||||
i := 7;
|
||||
j := 11;
|
||||
end
|
||||
else
|
||||
begin
|
||||
i := c - 14;
|
||||
j := 3;
|
||||
end;
|
||||
{NEEDBITS(t + i);}
|
||||
while (k < t + i) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
|
||||
{DUMPBITS(t);}
|
||||
b := b shr t;
|
||||
Dec(k, t);
|
||||
|
||||
Inc(j, uInt(b) and inflate_mask[i]);
|
||||
{DUMPBITS(i);}
|
||||
b := b shr i;
|
||||
Dec(k, i);
|
||||
|
||||
i := s.sub.trees.index;
|
||||
t := s.sub.trees.table;
|
||||
if (i + j > 258 + (t and $1f) + ((t shr 5) and $1f)) or
|
||||
((c = 16) and (i < 1)) then
|
||||
begin
|
||||
ZFREE(z, s.sub.trees.blens);
|
||||
s.mode := BLKBAD;
|
||||
z.msg := 'invalid bit length repeat';
|
||||
r := Z_DATA_ERROR;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
if c = 16 then
|
||||
c := s.sub.trees.blens^[i - 1]
|
||||
else
|
||||
c := 0;
|
||||
repeat
|
||||
s.sub.trees.blens^[i] := c;
|
||||
Inc(i);
|
||||
Dec(j);
|
||||
until (j=0);
|
||||
s.sub.trees.index := i;
|
||||
end;
|
||||
end; { while }
|
||||
s.sub.trees.tb := Z_NULL;
|
||||
begin
|
||||
bl := 9; { must be <= 9 for lookahead assumptions }
|
||||
bd := 6; { must be <= 9 for lookahead assumptions }
|
||||
t := s.sub.trees.table;
|
||||
t := inflate_trees_dynamic(257 + (t and $1f),
|
||||
1 + ((t shr 5) and $1f),
|
||||
s.sub.trees.blens^, bl, bd, tl, td, s.hufts^, z);
|
||||
ZFREE(z, s.sub.trees.blens);
|
||||
if (t <> Z_OK) then
|
||||
begin
|
||||
if (t = uInt(Z_DATA_ERROR)) then
|
||||
s.mode := BLKBAD;
|
||||
r := t;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
Tracev('inflate: trees ok');
|
||||
{$ENDIF}
|
||||
{ c renamed to cs }
|
||||
cs := inflate_codes_new(bl, bd, tl, td, z);
|
||||
if (cs = Z_NULL) then
|
||||
begin
|
||||
r := Z_MEM_ERROR;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
s.sub.decode.codes := cs;
|
||||
end;
|
||||
s.mode := CODES;
|
||||
{ yet another falltrough }
|
||||
goto start_codes;
|
||||
end;
|
||||
CODES:
|
||||
begin
|
||||
start_codes:
|
||||
{ update pointers }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
|
||||
r := inflate_codes(s, z, r);
|
||||
if (r <> Z_STREAM_END) then
|
||||
begin
|
||||
inflate_blocks := inflate_flush(s, z, r);
|
||||
exit;
|
||||
end;
|
||||
r := Z_OK;
|
||||
inflate_codes_free(s.sub.decode.codes, z);
|
||||
{ load local pointers }
|
||||
p := z.next_in;
|
||||
n := z.avail_in;
|
||||
b := s.bitb;
|
||||
k := s.bitk;
|
||||
q := s.write;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
if (ptr2int(q) >= ptr2int(s.read)) then
|
||||
Tracev('inflate: codes end '+
|
||||
IntToStr(z.total_out + ptr2int(q) - ptr2int(s.read)) + ' total out')
|
||||
else
|
||||
Tracev('inflate: codes end '+
|
||||
IntToStr(z.total_out + ptr2int(s.zend) - ptr2int(s.read) +
|
||||
ptr2int(q) - ptr2int(s.window)) + ' total out');
|
||||
{$ENDIF}
|
||||
if (not s.last) then
|
||||
begin
|
||||
s.mode := ZTYPE;
|
||||
continue; { break for switch statement in C-code }
|
||||
end;
|
||||
{$ifndef patch112}
|
||||
if (k > 7) then { return unused byte, if any }
|
||||
begin
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
Assert(k < 16, 'inflate_codes grabbed too many bytes');
|
||||
{$ENDIF}
|
||||
Dec(k, 8);
|
||||
Inc(n);
|
||||
Dec(p); { can always return one }
|
||||
end;
|
||||
{$endif}
|
||||
s.mode := DRY;
|
||||
{ another falltrough }
|
||||
goto start_dry;
|
||||
end;
|
||||
DRY:
|
||||
begin
|
||||
start_dry:
|
||||
{FLUSH}
|
||||
s.write := q;
|
||||
r := inflate_flush(s,z,r);
|
||||
q := s.write;
|
||||
|
||||
{ not needed anymore, we are done:
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
}
|
||||
|
||||
if (s.read <> s.write) then
|
||||
begin
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
s.mode := BLKDONE;
|
||||
goto start_blkdone;
|
||||
end;
|
||||
BLKDONE:
|
||||
begin
|
||||
start_blkdone:
|
||||
r := Z_STREAM_END;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
BLKBAD:
|
||||
begin
|
||||
r := Z_DATA_ERROR;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
else
|
||||
begin
|
||||
r := Z_STREAM_ERROR;
|
||||
{ update pointers and return }
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_blocks := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
end; { Case s.mode of }
|
||||
|
||||
end;
|
||||
|
||||
|
||||
function inflate_blocks_free(s : pInflate_blocks_state;
|
||||
var z : z_stream) : int;
|
||||
begin
|
||||
inflate_blocks_reset(s^, z, Z_NULL);
|
||||
ZFREE(z, s^.window);
|
||||
ZFREE(z, s^.hufts);
|
||||
ZFREE(z, s);
|
||||
{$IFDEF INFBLOCK_DEBUG}
|
||||
Trace('inflate: blocks freed');
|
||||
{$ENDIF}
|
||||
inflate_blocks_free := Z_OK;
|
||||
end;
|
||||
|
||||
|
||||
procedure inflate_set_dictionary(var s : inflate_blocks_state;
|
||||
const d : array of byte; { dictionary }
|
||||
n : uInt); { dictionary length }
|
||||
begin
|
||||
zmemcpy(s.window, pBytef(@d), n);
|
||||
s.write := s.window;
|
||||
Inc(s.write, n);
|
||||
s.read := s.write;
|
||||
end;
|
||||
|
||||
|
||||
{ Returns true if inflate is currently at the end of a block generated
|
||||
by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
||||
IN assertion: s <> Z_NULL }
|
||||
|
||||
function inflate_blocks_sync_point(var s : inflate_blocks_state) : int;
|
||||
begin
|
||||
inflate_blocks_sync_point := int(s.mode = LENS);
|
||||
end;
|
||||
|
||||
end.
|
||||
578
contrib/fundamentals/ZLib/paszlib/InfCodes.pas
Normal file
578
contrib/fundamentals/ZLib/paszlib/InfCodes.pas
Normal file
@@ -0,0 +1,578 @@
|
||||
Unit InfCodes;
|
||||
|
||||
{ infcodes.c -- process literals and length/distance pairs
|
||||
Copyright (C) 1995-1998 Mark Adler
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
{.DEFINE INFCODES_DEBUG}
|
||||
|
||||
uses
|
||||
zutil, gzlib;
|
||||
|
||||
function inflate_codes_new (bl : uInt;
|
||||
bd : uInt;
|
||||
tl : pInflate_huft;
|
||||
td : pInflate_huft;
|
||||
var z : z_stream): pInflate_codes_state;
|
||||
|
||||
function inflate_codes(var s : inflate_blocks_state;
|
||||
var z : z_stream;
|
||||
r : int) : int;
|
||||
|
||||
procedure inflate_codes_free(c : pInflate_codes_state;
|
||||
var z : z_stream);
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
infutil, InfFast;
|
||||
|
||||
|
||||
function inflate_codes_new (bl : uInt;
|
||||
bd : uInt;
|
||||
tl : pInflate_huft;
|
||||
td : pInflate_huft;
|
||||
var z : z_stream): pInflate_codes_state;
|
||||
var
|
||||
c : pInflate_codes_state;
|
||||
begin
|
||||
c := pInflate_codes_state( ZALLOC(z,1,sizeof(inflate_codes_state)) );
|
||||
if (c <> Z_NULL) then
|
||||
begin
|
||||
c^.mode := START;
|
||||
c^.lbits := Byte(bl);
|
||||
c^.dbits := Byte(bd);
|
||||
c^.ltree := tl;
|
||||
c^.dtree := td;
|
||||
{$IFDEF INFCODES_DEBUG}
|
||||
Tracev('inflate: codes new');
|
||||
{$ENDIF}
|
||||
end;
|
||||
inflate_codes_new := c;
|
||||
end;
|
||||
|
||||
|
||||
function inflate_codes(var s : inflate_blocks_state;
|
||||
var z : z_stream;
|
||||
r : int) : int;
|
||||
var
|
||||
j : uInt; { temporary storage }
|
||||
t : pInflate_huft; { temporary pointer }
|
||||
e : uInt; { extra bits or operation }
|
||||
b : uLong; { bit buffer }
|
||||
k : uInt; { bits in bit buffer }
|
||||
p : pBytef; { input data pointer }
|
||||
n : uInt; { bytes available there }
|
||||
q : pBytef; { output window write pointer }
|
||||
m : uInt; { bytes to end of window or read pointer }
|
||||
f : pBytef; { pointer to copy strings from }
|
||||
var
|
||||
c : pInflate_codes_state;
|
||||
begin
|
||||
c := s.sub.decode.codes; { codes state }
|
||||
|
||||
{ copy input/output information to locals }
|
||||
p := z.next_in;
|
||||
n := z.avail_in;
|
||||
b := s.bitb;
|
||||
k := s.bitk;
|
||||
q := s.write;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
|
||||
{ process input and output based on current state }
|
||||
while True do
|
||||
case (c^.mode) of
|
||||
{ waiting for "i:"=input, "o:"=output, "x:"=nothing }
|
||||
START: { x: set up for LEN }
|
||||
begin
|
||||
{$ifndef SLOW}
|
||||
if (m >= 258) and (n >= 10) then
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
|
||||
r := inflate_fast(c^.lbits, c^.dbits, c^.ltree, c^.dtree, s, z);
|
||||
{LOAD}
|
||||
p := z.next_in;
|
||||
n := z.avail_in;
|
||||
b := s.bitb;
|
||||
k := s.bitk;
|
||||
q := s.write;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
|
||||
if (r <> Z_OK) then
|
||||
begin
|
||||
if (r = Z_STREAM_END) then
|
||||
c^.mode := WASH
|
||||
else
|
||||
c^.mode := BADCODE;
|
||||
continue; { break for switch-statement in C }
|
||||
end;
|
||||
end;
|
||||
{$endif} { not SLOW }
|
||||
c^.sub.code.need := c^.lbits;
|
||||
c^.sub.code.tree := c^.ltree;
|
||||
c^.mode := LEN; { falltrough }
|
||||
end;
|
||||
LEN: { i: get length/literal/eob next }
|
||||
begin
|
||||
j := c^.sub.code.need;
|
||||
{NEEDBITS(j);}
|
||||
while (k < j) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
t := c^.sub.code.tree;
|
||||
Inc(t, uInt(b) and inflate_mask[j]);
|
||||
{DUMPBITS(t^.bits);}
|
||||
b := b shr t^.bits;
|
||||
Dec(k, t^.bits);
|
||||
|
||||
e := uInt(t^.exop);
|
||||
if (e = 0) then { literal }
|
||||
begin
|
||||
c^.sub.lit := t^.base;
|
||||
{$IFDEF INFCODES_DEBUG}
|
||||
if (t^.base >= $20) and (t^.base < $7f) then
|
||||
Tracevv('inflate: literal '+char(t^.base))
|
||||
else
|
||||
Tracevv('inflate: literal '+IntToStr(t^.base));
|
||||
{$ENDIF}
|
||||
c^.mode := LIT;
|
||||
continue; { break switch statement }
|
||||
end;
|
||||
if (e and 16 <> 0) then { length }
|
||||
begin
|
||||
c^.sub.copy.get := e and 15;
|
||||
c^.len := t^.base;
|
||||
c^.mode := LENEXT;
|
||||
continue; { break C-switch statement }
|
||||
end;
|
||||
if (e and 64 = 0) then { next table }
|
||||
begin
|
||||
c^.sub.code.need := e;
|
||||
c^.sub.code.tree := @huft_ptr(t)^[t^.base];
|
||||
continue; { break C-switch statement }
|
||||
end;
|
||||
if (e and 32 <> 0) then { end of block }
|
||||
begin
|
||||
{$IFDEF INFCODES_DEBUG}
|
||||
Tracevv('inflate: end of block');
|
||||
{$ENDIF}
|
||||
c^.mode := WASH;
|
||||
continue; { break C-switch statement }
|
||||
end;
|
||||
c^.mode := BADCODE; { invalid code }
|
||||
z.msg := 'invalid literal/length code';
|
||||
r := Z_DATA_ERROR;
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
LENEXT: { i: getting length extra (have base) }
|
||||
begin
|
||||
j := c^.sub.copy.get;
|
||||
{NEEDBITS(j);}
|
||||
while (k < j) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
Inc(c^.len, uInt(b and inflate_mask[j]));
|
||||
{DUMPBITS(j);}
|
||||
b := b shr j;
|
||||
Dec(k, j);
|
||||
|
||||
c^.sub.code.need := c^.dbits;
|
||||
c^.sub.code.tree := c^.dtree;
|
||||
{$IFDEF INFCODES_DEBUG}
|
||||
Tracevv('inflate: length '+IntToStr(c^.len));
|
||||
{$ENDIF}
|
||||
c^.mode := DIST;
|
||||
{ falltrough }
|
||||
end;
|
||||
DIST: { i: get distance next }
|
||||
begin
|
||||
j := c^.sub.code.need;
|
||||
{NEEDBITS(j);}
|
||||
while (k < j) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
t := @huft_ptr(c^.sub.code.tree)^[uInt(b) and inflate_mask[j]];
|
||||
{DUMPBITS(t^.bits);}
|
||||
b := b shr t^.bits;
|
||||
Dec(k, t^.bits);
|
||||
|
||||
e := uInt(t^.exop);
|
||||
if (e and 16 <> 0) then { distance }
|
||||
begin
|
||||
c^.sub.copy.get := e and 15;
|
||||
c^.sub.copy.dist := t^.base;
|
||||
c^.mode := DISTEXT;
|
||||
continue; { break C-switch statement }
|
||||
end;
|
||||
if (e and 64 = 0) then { next table }
|
||||
begin
|
||||
c^.sub.code.need := e;
|
||||
c^.sub.code.tree := @huft_ptr(t)^[t^.base];
|
||||
continue; { break C-switch statement }
|
||||
end;
|
||||
c^.mode := BADCODE; { invalid code }
|
||||
z.msg := 'invalid distance code';
|
||||
r := Z_DATA_ERROR;
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
DISTEXT: { i: getting distance extra }
|
||||
begin
|
||||
j := c^.sub.copy.get;
|
||||
{NEEDBITS(j);}
|
||||
while (k < j) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
Inc(c^.sub.copy.dist, uInt(b) and inflate_mask[j]);
|
||||
{DUMPBITS(j);}
|
||||
b := b shr j;
|
||||
Dec(k, j);
|
||||
{$IFDEF INFCODES_DEBUG}
|
||||
Tracevv('inflate: distance '+ IntToStr(c^.sub.copy.dist));
|
||||
{$ENDIF}
|
||||
c^.mode := COPY;
|
||||
{ falltrough }
|
||||
end;
|
||||
COPY: { o: copying bytes in window, waiting for space }
|
||||
begin
|
||||
f := q;
|
||||
Dec(f, c^.sub.copy.dist);
|
||||
if (uInt(ptr2int(q) - ptr2int(s.window)) < c^.sub.copy.dist) then
|
||||
begin
|
||||
f := s.zend;
|
||||
Dec(f, c^.sub.copy.dist - uInt(ptr2int(q) - ptr2int(s.window)));
|
||||
end;
|
||||
|
||||
while (c^.len <> 0) do
|
||||
begin
|
||||
{NEEDOUT}
|
||||
if (m = 0) then
|
||||
begin
|
||||
{WRAP}
|
||||
if (q = s.zend) and (s.read <> s.window) then
|
||||
begin
|
||||
q := s.window;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
end;
|
||||
|
||||
if (m = 0) then
|
||||
begin
|
||||
{FLUSH}
|
||||
s.write := q;
|
||||
r := inflate_flush(s,z,r);
|
||||
q := s.write;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
|
||||
{WRAP}
|
||||
if (q = s.zend) and (s.read <> s.window) then
|
||||
begin
|
||||
q := s.window;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
end;
|
||||
|
||||
if (m = 0) then
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
r := Z_OK;
|
||||
|
||||
{OUTBYTE( *f++)}
|
||||
q^ := f^;
|
||||
Inc(q);
|
||||
Inc(f);
|
||||
Dec(m);
|
||||
|
||||
if (f = s.zend) then
|
||||
f := s.window;
|
||||
Dec(c^.len);
|
||||
end;
|
||||
c^.mode := START;
|
||||
{ C-switch break; not needed }
|
||||
end;
|
||||
LIT: { o: got literal, waiting for output space }
|
||||
begin
|
||||
{NEEDOUT}
|
||||
if (m = 0) then
|
||||
begin
|
||||
{WRAP}
|
||||
if (q = s.zend) and (s.read <> s.window) then
|
||||
begin
|
||||
q := s.window;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
end;
|
||||
|
||||
if (m = 0) then
|
||||
begin
|
||||
{FLUSH}
|
||||
s.write := q;
|
||||
r := inflate_flush(s,z,r);
|
||||
q := s.write;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
|
||||
{WRAP}
|
||||
if (q = s.zend) and (s.read <> s.window) then
|
||||
begin
|
||||
q := s.window;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
end;
|
||||
|
||||
if (m = 0) then
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
r := Z_OK;
|
||||
|
||||
{OUTBYTE(c^.sub.lit);}
|
||||
q^ := c^.sub.lit;
|
||||
Inc(q);
|
||||
Dec(m);
|
||||
|
||||
c^.mode := START;
|
||||
{break;}
|
||||
end;
|
||||
WASH: { o: got eob, possibly more output }
|
||||
begin
|
||||
{$ifdef patch112}
|
||||
if (k > 7) then { return unused byte, if any }
|
||||
begin
|
||||
{$IFDEF INFCODES_DEBUG}
|
||||
Assert(k < 16, 'inflate_codes grabbed too many bytes');
|
||||
{$ENDIF}
|
||||
Dec(k, 8);
|
||||
Inc(n);
|
||||
Dec(p); { can always return one }
|
||||
end;
|
||||
{$endif}
|
||||
{FLUSH}
|
||||
s.write := q;
|
||||
r := inflate_flush(s,z,r);
|
||||
q := s.write;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
|
||||
if (s.read <> s.write) then
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
c^.mode := ZEND;
|
||||
{ falltrough }
|
||||
end;
|
||||
|
||||
ZEND:
|
||||
begin
|
||||
r := Z_STREAM_END;
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
BADCODE: { x: got error }
|
||||
begin
|
||||
r := Z_DATA_ERROR;
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
else
|
||||
begin
|
||||
r := Z_STREAM_ERROR;
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_codes := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
{NEED_DUMMY_RETURN - Delphi2+ dumb compilers complain without this }
|
||||
inflate_codes := Z_STREAM_ERROR;
|
||||
end;
|
||||
|
||||
|
||||
procedure inflate_codes_free(c : pInflate_codes_state;
|
||||
var z : z_stream);
|
||||
begin
|
||||
ZFREE(z, c);
|
||||
{$IFDEF INFCODES_DEBUG}
|
||||
Tracev('inflate: codes free');
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
end.
|
||||
319
contrib/fundamentals/ZLib/paszlib/InfFast.pas
Normal file
319
contrib/fundamentals/ZLib/paszlib/InfFast.pas
Normal file
@@ -0,0 +1,319 @@
|
||||
Unit InfFast;
|
||||
|
||||
{
|
||||
inffast.h and
|
||||
inffast.c -- process literals and length/distance pairs fast
|
||||
Copyright (C) 1995-1998 Mark Adler
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
{.DEFINE INFFAST_DEBUG}
|
||||
|
||||
uses zutil, gzlib;
|
||||
|
||||
function inflate_fast( bl : uInt;
|
||||
bd : uInt;
|
||||
tl : pInflate_huft;
|
||||
td : pInflate_huft;
|
||||
var s : inflate_blocks_state;
|
||||
var z : z_stream) : int;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
infutil;
|
||||
|
||||
|
||||
{ Called with number of bytes left to write in window at least 258
|
||||
(the maximum string length) and number of input bytes available
|
||||
at least ten. The ten bytes are six bytes for the longest length/
|
||||
distance pair plus four bytes for overloading the bit buffer. }
|
||||
|
||||
function inflate_fast( bl : uInt;
|
||||
bd : uInt;
|
||||
tl : pInflate_huft;
|
||||
td : pInflate_huft;
|
||||
var s : inflate_blocks_state;
|
||||
var z : z_stream) : int;
|
||||
|
||||
var
|
||||
t : pInflate_huft; { temporary pointer }
|
||||
e : uInt; { extra bits or operation }
|
||||
b : uLong; { bit buffer }
|
||||
k : uInt; { bits in bit buffer }
|
||||
p : pBytef; { input data pointer }
|
||||
n : uInt; { bytes available there }
|
||||
q : pBytef; { output window write pointer }
|
||||
m : uInt; { bytes to end of window or read pointer }
|
||||
ml : uInt; { mask for literal/length tree }
|
||||
md : uInt; { mask for distance tree }
|
||||
c : uInt; { bytes to copy }
|
||||
d : uInt; { distance back to copy from }
|
||||
r : pBytef; { copy source pointer }
|
||||
begin
|
||||
{ load input, output, bit values (macro LOAD) }
|
||||
p := z.next_in;
|
||||
n := z.avail_in;
|
||||
b := s.bitb;
|
||||
k := s.bitk;
|
||||
q := s.write;
|
||||
if ptr2int(q) < ptr2int(s.read) then
|
||||
m := uInt(ptr2int(s.read)-ptr2int(q)-1)
|
||||
else
|
||||
m := uInt(ptr2int(s.zend)-ptr2int(q));
|
||||
|
||||
{ initialize masks }
|
||||
ml := inflate_mask[bl];
|
||||
md := inflate_mask[bd];
|
||||
|
||||
{ do until not enough input or output space for fast loop }
|
||||
repeat { assume called with (m >= 258) and (n >= 10) }
|
||||
{ get literal/length code }
|
||||
{GRABBITS(20);} { max bits for literal/length code }
|
||||
while (k < 20) do
|
||||
begin
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
|
||||
t := @(huft_ptr(tl)^[uInt(b) and ml]);
|
||||
|
||||
e := t^.exop;
|
||||
if (e = 0) then
|
||||
begin
|
||||
{DUMPBITS(t^.bits);}
|
||||
b := b shr t^.bits;
|
||||
Dec(k, t^.bits);
|
||||
{$IFDEF INFFAST_DEBUG}
|
||||
if (t^.base >= $20) and (t^.base < $7f) then
|
||||
Tracevv('inflate: * literal '+char(t^.base))
|
||||
else
|
||||
Tracevv('inflate: * literal '+ IntToStr(t^.base));
|
||||
{$ENDIF}
|
||||
q^ := Byte(t^.base);
|
||||
Inc(q);
|
||||
Dec(m);
|
||||
continue;
|
||||
end;
|
||||
repeat
|
||||
{DUMPBITS(t^.bits);}
|
||||
b := b shr t^.bits;
|
||||
Dec(k, t^.bits);
|
||||
|
||||
if (e and 16 <> 0) then
|
||||
begin
|
||||
{ get extra bits for length }
|
||||
e := e and 15;
|
||||
c := t^.base + (uInt(b) and inflate_mask[e]);
|
||||
{DUMPBITS(e);}
|
||||
b := b shr e;
|
||||
Dec(k, e);
|
||||
{$IFDEF INFFAST_DEBUG}
|
||||
Tracevv('inflate: * length ' + IntToStr(c));
|
||||
{$ENDIF}
|
||||
{ decode distance base of block to copy }
|
||||
{GRABBITS(15);} { max bits for distance code }
|
||||
while (k < 15) do
|
||||
begin
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
|
||||
t := @huft_ptr(td)^[uInt(b) and md];
|
||||
e := t^.exop;
|
||||
repeat
|
||||
{DUMPBITS(t^.bits);}
|
||||
b := b shr t^.bits;
|
||||
Dec(k, t^.bits);
|
||||
|
||||
if (e and 16 <> 0) then
|
||||
begin
|
||||
{ get extra bits to add to distance base }
|
||||
e := e and 15;
|
||||
{GRABBITS(e);} { get extra bits (up to 13) }
|
||||
while (k < e) do
|
||||
begin
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
|
||||
d := t^.base + (uInt(b) and inflate_mask[e]);
|
||||
{DUMPBITS(e);}
|
||||
b := b shr e;
|
||||
Dec(k, e);
|
||||
|
||||
{$IFDEF INFFAST_DEBUG}
|
||||
Tracevv('inflate: * distance '+IntToStr(d));
|
||||
{$ENDIF}
|
||||
{ do the copy }
|
||||
Dec(m, c);
|
||||
if (uInt(ptr2int(q) - ptr2int(s.window)) >= d) then { offset before dest }
|
||||
begin { just copy }
|
||||
r := q;
|
||||
Dec(r, d);
|
||||
q^ := r^; Inc(q); Inc(r); Dec(c); { minimum count is three, }
|
||||
q^ := r^; Inc(q); Inc(r); Dec(c); { so unroll loop a little }
|
||||
end
|
||||
else { else offset after destination }
|
||||
begin
|
||||
e := d - uInt(ptr2int(q) - ptr2int(s.window)); { bytes from offset to end }
|
||||
r := s.zend;
|
||||
Dec(r, e); { pointer to offset }
|
||||
if (c > e) then { if source crosses, }
|
||||
begin
|
||||
Dec(c, e); { copy to end of window }
|
||||
repeat
|
||||
q^ := r^;
|
||||
Inc(q);
|
||||
Inc(r);
|
||||
Dec(e);
|
||||
until (e=0);
|
||||
r := s.window; { copy rest from start of window }
|
||||
end;
|
||||
end;
|
||||
repeat { copy all or what's left }
|
||||
q^ := r^;
|
||||
Inc(q);
|
||||
Inc(r);
|
||||
Dec(c);
|
||||
until (c = 0);
|
||||
break;
|
||||
end
|
||||
else
|
||||
if (e and 64 = 0) then
|
||||
begin
|
||||
Inc(t, t^.base + (uInt(b) and inflate_mask[e]));
|
||||
e := t^.exop;
|
||||
end
|
||||
else
|
||||
begin
|
||||
z.msg := 'invalid distance code';
|
||||
{UNGRAB}
|
||||
c := z.avail_in-n;
|
||||
if (k shr 3) < c then
|
||||
c := k shr 3;
|
||||
Inc(n, c);
|
||||
Dec(p, c);
|
||||
Dec(k, c shl 3);
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
|
||||
inflate_fast := Z_DATA_ERROR;
|
||||
exit;
|
||||
end;
|
||||
until FALSE;
|
||||
break;
|
||||
end;
|
||||
if (e and 64 = 0) then
|
||||
begin
|
||||
{t += t->base;
|
||||
e = (t += ((uInt)b & inflate_mask[e]))->exop;}
|
||||
|
||||
Inc(t, t^.base + (uInt(b) and inflate_mask[e]));
|
||||
e := t^.exop;
|
||||
if (e = 0) then
|
||||
begin
|
||||
{DUMPBITS(t^.bits);}
|
||||
b := b shr t^.bits;
|
||||
Dec(k, t^.bits);
|
||||
|
||||
{$IFDEF INFFAST_DEBUG}
|
||||
if (t^.base >= $20) and (t^.base < $7f) then
|
||||
Tracevv('inflate: * literal '+char(t^.base))
|
||||
else
|
||||
Tracevv('inflate: * literal '+IntToStr(t^.base));
|
||||
{$ENDIF}
|
||||
q^ := Byte(t^.base);
|
||||
Inc(q);
|
||||
Dec(m);
|
||||
break;
|
||||
end;
|
||||
end
|
||||
else
|
||||
if (e and 32 <> 0) then
|
||||
begin
|
||||
{$IFDEF INFFAST_DEBUG}
|
||||
Tracevv('inflate: * end of block');
|
||||
{$ENDIF}
|
||||
{UNGRAB}
|
||||
c := z.avail_in-n;
|
||||
if (k shr 3) < c then
|
||||
c := k shr 3;
|
||||
Inc(n, c);
|
||||
Dec(p, c);
|
||||
Dec(k, c shl 3);
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_fast := Z_STREAM_END;
|
||||
exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
z.msg := 'invalid literal/length code';
|
||||
{UNGRAB}
|
||||
c := z.avail_in-n;
|
||||
if (k shr 3) < c then
|
||||
c := k shr 3;
|
||||
Inc(n, c);
|
||||
Dec(p, c);
|
||||
Dec(k, c shl 3);
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_fast := Z_DATA_ERROR;
|
||||
exit;
|
||||
end;
|
||||
until FALSE;
|
||||
until (m < 258) or (n < 10);
|
||||
|
||||
{ not enough input or output--restore pointers and return }
|
||||
{UNGRAB}
|
||||
c := z.avail_in-n;
|
||||
if (k shr 3) < c then
|
||||
c := k shr 3;
|
||||
Inc(n, c);
|
||||
Dec(p, c);
|
||||
Dec(k, c shl 3);
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
inflate_fast := Z_OK;
|
||||
end;
|
||||
|
||||
end.
|
||||
784
contrib/fundamentals/ZLib/paszlib/InfTrees.pas
Normal file
784
contrib/fundamentals/ZLib/paszlib/InfTrees.pas
Normal file
@@ -0,0 +1,784 @@
|
||||
Unit InfTrees;
|
||||
|
||||
{ inftrees.h -- header to use inftrees.c
|
||||
inftrees.c -- generate Huffman trees for efficient decoding
|
||||
Copyright (C) 1995-1998 Mark Adler
|
||||
|
||||
WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change.
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
Interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
uses
|
||||
zutil, gzlib;
|
||||
|
||||
|
||||
{ Maximum size of dynamic tree. The maximum found in a long but non-
|
||||
exhaustive search was 1004 huft structures (850 for length/literals
|
||||
and 154 for distances, the latter actually the result of an
|
||||
exhaustive search). The actual maximum is not known, but the
|
||||
value below is more than safe. }
|
||||
const
|
||||
MANY = 1440;
|
||||
|
||||
|
||||
{$ifdef DEBUG}
|
||||
var
|
||||
inflate_hufts : uInt;
|
||||
{$endif}
|
||||
|
||||
function inflate_trees_bits(
|
||||
var c : array of uIntf; { 19 code lengths }
|
||||
var bb : uIntf; { bits tree desired/actual depth }
|
||||
var tb : pinflate_huft; { bits tree result }
|
||||
var hp : array of Inflate_huft; { space for trees }
|
||||
var z : z_stream { for messages }
|
||||
) : int;
|
||||
|
||||
function inflate_trees_dynamic(
|
||||
nl : uInt; { number of literal/length codes }
|
||||
nd : uInt; { number of distance codes }
|
||||
var c : Array of uIntf; { that many (total) code lengths }
|
||||
var bl : uIntf; { literal desired/actual bit depth }
|
||||
var bd : uIntf; { distance desired/actual bit depth }
|
||||
var tl : pInflate_huft; { literal/length tree result }
|
||||
var td : pInflate_huft; { distance tree result }
|
||||
var hp : array of Inflate_huft; { space for trees }
|
||||
var z : z_stream { for messages }
|
||||
) : int;
|
||||
|
||||
function inflate_trees_fixed (
|
||||
var bl : uInt; { literal desired/actual bit depth }
|
||||
var bd : uInt; { distance desired/actual bit depth }
|
||||
var tl : pInflate_huft; { literal/length tree result }
|
||||
var td : pInflate_huft; { distance tree result }
|
||||
var z : z_stream { for memory allocation }
|
||||
) : int;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
const
|
||||
inflate_copyright = 'inflate 1.1.2 Copyright 1995-1998 Mark Adler';
|
||||
|
||||
{
|
||||
If you use the zlib library in a product, an acknowledgment is welcome
|
||||
in the documentation of your product. If for some reason you cannot
|
||||
include such an acknowledgment, I would appreciate that you keep this
|
||||
copyright string in the executable of your product.
|
||||
}
|
||||
|
||||
|
||||
const
|
||||
{ Tables for deflate from PKZIP's appnote.txt. }
|
||||
cplens : Array [0..30] Of uInt { Copy lengths for literal codes 257..285 }
|
||||
= (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0);
|
||||
{ actually lengths - 2; also see note #13 above about 258 }
|
||||
|
||||
invalid_code = 112;
|
||||
|
||||
cplext : Array [0..30] Of uInt { Extra bits for literal codes 257..285 }
|
||||
= (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, invalid_code, invalid_code);
|
||||
|
||||
cpdist : Array [0..29] Of uInt { Copy offsets for distance codes 0..29 }
|
||||
= (1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577);
|
||||
|
||||
cpdext : Array [0..29] Of uInt { Extra bits for distance codes }
|
||||
= (0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||
12, 12, 13, 13);
|
||||
|
||||
{ Huffman code decoding is performed using a multi-level table lookup.
|
||||
The fastest way to decode is to simply build a lookup table whose
|
||||
size is determined by the longest code. However, the time it takes
|
||||
to build this table can also be a factor if the data being decoded
|
||||
is not very long. The most common codes are necessarily the
|
||||
shortest codes, so those codes dominate the decoding time, and hence
|
||||
the speed. The idea is you can have a shorter table that decodes the
|
||||
shorter, more probable codes, and then point to subsidiary tables for
|
||||
the longer codes. The time it costs to decode the longer codes is
|
||||
then traded against the time it takes to make longer tables.
|
||||
|
||||
This results of this trade are in the variables lbits and dbits
|
||||
below. lbits is the number of bits the first level table for literal/
|
||||
length codes can decode in one step, and dbits is the same thing for
|
||||
the distance codes. Subsequent tables are also less than or equal to
|
||||
those sizes. These values may be adjusted either when all of the
|
||||
codes are shorter than that, in which case the longest code length in
|
||||
bits is used, or when the shortest code is *longer* than the requested
|
||||
table size, in which case the length of the shortest code in bits is
|
||||
used.
|
||||
|
||||
There are two different values for the two tables, since they code a
|
||||
different number of possibilities each. The literal/length table
|
||||
codes 286 possible values, or in a flat code, a little over eight
|
||||
bits. The distance table codes 30 possible values, or a little less
|
||||
than five bits, flat. The optimum values for speed end up being
|
||||
about one bit more than those, so lbits is 8+1 and dbits is 5+1.
|
||||
The optimum values may differ though from machine to machine, and
|
||||
possibly even between compilers. Your mileage may vary. }
|
||||
|
||||
|
||||
{ If BMAX needs to be larger than 16, then h and x[] should be uLong. }
|
||||
const
|
||||
BMAX = 15; { maximum bit length of any code }
|
||||
|
||||
{$DEFINE USE_PTR}
|
||||
|
||||
function huft_build(
|
||||
var b : array of uIntf; { code lengths in bits (all assumed <= BMAX) }
|
||||
n : uInt; { number of codes (assumed <= N_MAX) }
|
||||
s : uInt; { number of simple-valued codes (0..s-1) }
|
||||
const d : array of uIntf; { list of base values for non-simple codes }
|
||||
{ array of word }
|
||||
const e : array of uIntf; { list of extra bits for non-simple codes }
|
||||
{ array of byte }
|
||||
t : ppInflate_huft; { result: starting table }
|
||||
var m : uIntf; { maximum lookup bits, returns actual }
|
||||
var hp : array of inflate_huft; { space for trees }
|
||||
var hn : uInt; { hufts used in space }
|
||||
var v : array of uIntf { working area: values in order of bit length }
|
||||
) : int;
|
||||
{ Given a list of code lengths and a maximum table size, make a set of
|
||||
tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
|
||||
if the given code set is incomplete (the tables are still built in this
|
||||
case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
|
||||
lengths), or Z_MEM_ERROR if not enough memory. }
|
||||
Var
|
||||
a : uInt; { counter for codes of length k }
|
||||
c : Array [0..BMAX] Of uInt; { bit length count table }
|
||||
f : uInt; { i repeats in table every f entries }
|
||||
g : int; { maximum code length }
|
||||
h : int; { table level }
|
||||
i : uInt; {register} { counter, current code }
|
||||
j : uInt; {register} { counter }
|
||||
k : Int; {register} { number of bits in current code }
|
||||
l : int; { bits per table (returned in m) }
|
||||
mask : uInt; { (1 shl w) - 1, to avoid cc -O bug on HP }
|
||||
p : ^uIntf; {register} { pointer into c[], b[], or v[] }
|
||||
q : pInflate_huft; { points to current table }
|
||||
r : inflate_huft; { table entry for structure assignment }
|
||||
u : Array [0..BMAX-1] Of pInflate_huft; { table stack }
|
||||
w : int; {register} { bits before this table = (l*h) }
|
||||
x : Array [0..BMAX] Of uInt; { bit offsets, then code stack }
|
||||
{$IFDEF USE_PTR}
|
||||
xp : puIntf; { pointer into x }
|
||||
{$ELSE}
|
||||
xp : uInt;
|
||||
{$ENDIF}
|
||||
y : int; { number of dummy codes added }
|
||||
z : uInt; { number of entries in current table }
|
||||
Begin
|
||||
{ Generate counts for each bit length }
|
||||
FillChar(c,SizeOf(c),0) ; { clear c[] }
|
||||
|
||||
for i := 0 to n-1 do
|
||||
Inc (c[b[i]]); { assume all entries <= BMAX }
|
||||
|
||||
If (c[0] = n) Then { null input--all zero length codes }
|
||||
Begin
|
||||
t^ := pInflate_huft(NIL);
|
||||
m := 0 ;
|
||||
huft_build := Z_OK ;
|
||||
Exit;
|
||||
End ;
|
||||
|
||||
{ Find minimum and maximum length, bound [m] by those }
|
||||
l := m;
|
||||
for j:=1 To BMAX do
|
||||
if (c[j] <> 0) then
|
||||
break;
|
||||
k := j ; { minimum code length }
|
||||
if (uInt(l) < j) then
|
||||
l := j;
|
||||
for i := BMAX downto 1 do
|
||||
if (c[i] <> 0) then
|
||||
break ;
|
||||
g := i ; { maximum code length }
|
||||
if (uInt(l) > i) then
|
||||
l := i;
|
||||
m := l;
|
||||
|
||||
{ Adjust last length count to fill out codes, if needed }
|
||||
y := 1 shl j ;
|
||||
while (j < i) do
|
||||
begin
|
||||
Dec(y, c[j]) ;
|
||||
if (y < 0) then
|
||||
begin
|
||||
huft_build := Z_DATA_ERROR; { bad input: more codes than bits }
|
||||
exit;
|
||||
end ;
|
||||
Inc(j) ;
|
||||
y := y shl 1
|
||||
end;
|
||||
Dec (y, c[i]) ;
|
||||
if (y < 0) then
|
||||
begin
|
||||
huft_build := Z_DATA_ERROR; { bad input: more codes than bits }
|
||||
exit;
|
||||
end;
|
||||
Inc(c[i], y);
|
||||
|
||||
{ Generate starting offsets into the value table FOR each length }
|
||||
{$IFDEF USE_PTR}
|
||||
x[1] := 0;
|
||||
j := 0;
|
||||
|
||||
p := @c[1];
|
||||
xp := @x[2];
|
||||
|
||||
dec(i); { note that i = g from above }
|
||||
WHILE (i > 0) DO
|
||||
BEGIN
|
||||
inc(j, p^);
|
||||
xp^ := j;
|
||||
inc(p);
|
||||
inc(xp);
|
||||
dec(i);
|
||||
END;
|
||||
{$ELSE}
|
||||
x[1] := 0;
|
||||
j := 0 ;
|
||||
for i := 1 to g do
|
||||
begin
|
||||
x[i] := j;
|
||||
Inc(j, c[i]);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ Make a table of values in order of bit lengths }
|
||||
for i := 0 to n-1 do
|
||||
begin
|
||||
j := b[i];
|
||||
if (j <> 0) then
|
||||
begin
|
||||
v[ x[j] ] := i;
|
||||
Inc(x[j]);
|
||||
end;
|
||||
end;
|
||||
n := x[g]; { set n to length of v }
|
||||
|
||||
{ Generate the Huffman codes and for each, make the table entries }
|
||||
i := 0 ;
|
||||
x[0] := 0 ; { first Huffman code is zero }
|
||||
p := Addr(v) ; { grab values in bit order }
|
||||
h := -1 ; { no tables yet--level -1 }
|
||||
w := -l ; { bits decoded = (l*h) }
|
||||
|
||||
u[0] := pInflate_huft(NIL); { just to keep compilers happy }
|
||||
q := pInflate_huft(NIL); { ditto }
|
||||
z := 0 ; { ditto }
|
||||
|
||||
{ go through the bit lengths (k already is bits in shortest code) }
|
||||
while (k <= g) Do
|
||||
begin
|
||||
a := c[k] ;
|
||||
while (a<>0) Do
|
||||
begin
|
||||
Dec (a) ;
|
||||
{ here i is the Huffman code of length k bits for value p^ }
|
||||
{ make tables up to required level }
|
||||
while (k > w + l) do
|
||||
begin
|
||||
|
||||
Inc (h) ;
|
||||
Inc (w, l); { add bits already decoded }
|
||||
{ previous table always l bits }
|
||||
{ compute minimum size table less than or equal to l bits }
|
||||
|
||||
{ table size upper limit }
|
||||
z := g - w;
|
||||
If (z > uInt(l)) Then
|
||||
z := l;
|
||||
|
||||
{ try a k-w bit table }
|
||||
j := k - w;
|
||||
f := 1 shl j;
|
||||
if (f > a+1) Then { too few codes for k-w bit table }
|
||||
begin
|
||||
Dec(f, a+1); { deduct codes from patterns left }
|
||||
{$IFDEF USE_PTR}
|
||||
xp := Addr(c[k]);
|
||||
|
||||
if (j < z) then
|
||||
begin
|
||||
Inc(j);
|
||||
while (j < z) do
|
||||
begin { try smaller tables up to z bits }
|
||||
f := f shl 1;
|
||||
Inc (xp) ;
|
||||
If (f <= xp^) Then
|
||||
break; { enough codes to use up j bits }
|
||||
Dec(f, xp^); { else deduct codes from patterns }
|
||||
Inc(j);
|
||||
end;
|
||||
end;
|
||||
{$ELSE}
|
||||
xp := k;
|
||||
|
||||
if (j < z) then
|
||||
begin
|
||||
Inc (j) ;
|
||||
While (j < z) Do
|
||||
begin { try smaller tables up to z bits }
|
||||
f := f * 2;
|
||||
Inc (xp) ;
|
||||
if (f <= c[xp]) then
|
||||
Break ; { enough codes to use up j bits }
|
||||
Dec (f, c[xp]) ; { else deduct codes from patterns }
|
||||
Inc (j);
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
z := 1 shl j; { table entries for j-bit table }
|
||||
|
||||
{ allocate new table }
|
||||
if (hn + z > MANY) then { (note: doesn't matter for fixed) }
|
||||
begin
|
||||
huft_build := Z_MEM_ERROR; { not enough memory }
|
||||
exit;
|
||||
end;
|
||||
|
||||
q := @hp[hn];
|
||||
u[h] := q;
|
||||
Inc(hn, z);
|
||||
|
||||
{ connect to last table, if there is one }
|
||||
if (h <> 0) then
|
||||
begin
|
||||
x[h] := i; { save pattern for backing up }
|
||||
r.bits := Byte(l); { bits to dump before this table }
|
||||
r.exop := Byte(j); { bits in this table }
|
||||
j := i shr (w - l);
|
||||
{r.base := uInt( q - u[h-1] -j);} { offset to this table }
|
||||
r.base := (ptr2int(q) - ptr2int(u[h-1]) ) div sizeof(q^) - j;
|
||||
huft_Ptr(u[h-1])^[j] := r; { connect to last table }
|
||||
end
|
||||
else
|
||||
t^ := q; { first table is returned result }
|
||||
end;
|
||||
|
||||
{ set up table entry in r }
|
||||
r.bits := Byte(k - w);
|
||||
|
||||
{ C-code: if (p >= v + n) - see ZUTIL.PAS for comments }
|
||||
|
||||
if ptr2int(p)>=ptr2int(@(v[n])) then { also works under DPMI ?? }
|
||||
r.exop := 128 + 64 { out of values--invalid code }
|
||||
else
|
||||
if (p^ < s) then
|
||||
begin
|
||||
if (p^ < 256) then { 256 is end-of-block code }
|
||||
r.exop := 0
|
||||
Else
|
||||
r.exop := 32 + 64; { EOB_code; }
|
||||
r.base := p^; { simple code is just the value }
|
||||
Inc(p);
|
||||
end
|
||||
Else
|
||||
begin
|
||||
r.exop := Byte(e[p^-s] + 16 + 64); { non-simple--look up in lists }
|
||||
r.base := d[p^-s];
|
||||
Inc (p);
|
||||
end ;
|
||||
|
||||
{ fill code-like entries with r }
|
||||
f := 1 shl (k - w);
|
||||
j := i shr w;
|
||||
while (j < z) do
|
||||
begin
|
||||
huft_Ptr(q)^[j] := r;
|
||||
Inc(j, f);
|
||||
end;
|
||||
|
||||
{ backwards increment the k-bit code i }
|
||||
j := 1 shl (k-1) ;
|
||||
while (i and j) <> 0 do
|
||||
begin
|
||||
i := i xor j; { bitwise exclusive or }
|
||||
j := j shr 1
|
||||
end ;
|
||||
i := i xor j;
|
||||
|
||||
{ backup over finished tables }
|
||||
mask := (1 shl w) - 1; { needed on HP, cc -O bug }
|
||||
while ((i and mask) <> x[h]) do
|
||||
begin
|
||||
Dec(h); { don't need to update q }
|
||||
Dec(w, l);
|
||||
mask := (1 shl w) - 1;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
Inc(k);
|
||||
end;
|
||||
|
||||
{ Return Z_BUF_ERROR if we were given an incomplete table }
|
||||
if (y <> 0) And (g <> 1) then
|
||||
huft_build := Z_BUF_ERROR
|
||||
else
|
||||
huft_build := Z_OK;
|
||||
end; { huft_build}
|
||||
|
||||
|
||||
function inflate_trees_bits(
|
||||
var c : array of uIntf; { 19 code lengths }
|
||||
var bb : uIntf; { bits tree desired/actual depth }
|
||||
var tb : pinflate_huft; { bits tree result }
|
||||
var hp : array of Inflate_huft; { space for trees }
|
||||
var z : z_stream { for messages }
|
||||
) : int;
|
||||
var
|
||||
r : int;
|
||||
hn : uInt; { hufts used in space }
|
||||
v : PuIntArray; { work area for huft_build }
|
||||
begin
|
||||
hn := 0;
|
||||
v := PuIntArray( ZALLOC(z, 19, sizeof(uInt)) );
|
||||
if (v = Z_NULL) then
|
||||
begin
|
||||
inflate_trees_bits := Z_MEM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
r := huft_build(c, 19, 19, cplens, cplext,
|
||||
{puIntf(Z_NULL), puIntf(Z_NULL),}
|
||||
@tb, bb, hp, hn, v^);
|
||||
if (r = Z_DATA_ERROR) then
|
||||
z.msg := 'oversubscribed dynamic bit lengths tree'
|
||||
else
|
||||
if (r = Z_BUF_ERROR) or (bb = 0) then
|
||||
begin
|
||||
z.msg := 'incomplete dynamic bit lengths tree';
|
||||
r := Z_DATA_ERROR;
|
||||
end;
|
||||
ZFREE(z, v);
|
||||
inflate_trees_bits := r;
|
||||
end;
|
||||
|
||||
|
||||
function inflate_trees_dynamic(
|
||||
nl : uInt; { number of literal/length codes }
|
||||
nd : uInt; { number of distance codes }
|
||||
var c : Array of uIntf; { that many (total) code lengths }
|
||||
var bl : uIntf; { literal desired/actual bit depth }
|
||||
var bd : uIntf; { distance desired/actual bit depth }
|
||||
var tl : pInflate_huft; { literal/length tree result }
|
||||
var td : pInflate_huft; { distance tree result }
|
||||
var hp : array of Inflate_huft; { space for trees }
|
||||
var z : z_stream { for messages }
|
||||
) : int;
|
||||
var
|
||||
r : int;
|
||||
hn : uInt; { hufts used in space }
|
||||
v : PuIntArray; { work area for huft_build }
|
||||
begin
|
||||
hn := 0;
|
||||
{ allocate work area }
|
||||
v := PuIntArray( ZALLOC(z, 288, sizeof(uInt)) );
|
||||
if (v = Z_NULL) then
|
||||
begin
|
||||
inflate_trees_dynamic := Z_MEM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ build literal/length tree }
|
||||
r := huft_build(c, nl, 257, cplens, cplext, @tl, bl, hp, hn, v^);
|
||||
if (r <> Z_OK) or (bl = 0) then
|
||||
begin
|
||||
if (r = Z_DATA_ERROR) then
|
||||
z.msg := 'oversubscribed literal/length tree'
|
||||
else
|
||||
if (r <> Z_MEM_ERROR) then
|
||||
begin
|
||||
z.msg := 'incomplete literal/length tree';
|
||||
r := Z_DATA_ERROR;
|
||||
end;
|
||||
|
||||
ZFREE(z, v);
|
||||
inflate_trees_dynamic := r;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ build distance tree }
|
||||
r := huft_build(puIntArray(@c[nl])^, nd, 0,
|
||||
cpdist, cpdext, @td, bd, hp, hn, v^);
|
||||
if (r <> Z_OK) or ((bd = 0) and (nl > 257)) then
|
||||
begin
|
||||
if (r = Z_DATA_ERROR) then
|
||||
z.msg := 'oversubscribed literal/length tree'
|
||||
else
|
||||
if (r = Z_BUF_ERROR) then
|
||||
begin
|
||||
{$ifdef PKZIP_BUG_WORKAROUND}
|
||||
r := Z_OK;
|
||||
end;
|
||||
{$else}
|
||||
z.msg := 'incomplete literal/length tree';
|
||||
r := Z_DATA_ERROR;
|
||||
end
|
||||
else
|
||||
if (r <> Z_MEM_ERROR) then
|
||||
begin
|
||||
z.msg := 'empty distance tree with lengths';
|
||||
r := Z_DATA_ERROR;
|
||||
end;
|
||||
ZFREE(z, v);
|
||||
inflate_trees_dynamic := r;
|
||||
exit;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
{ done }
|
||||
ZFREE(z, v);
|
||||
inflate_trees_dynamic := Z_OK;
|
||||
end;
|
||||
|
||||
{$UNDEF BUILDFIXED}
|
||||
|
||||
{ build fixed tables only once--keep them here }
|
||||
{$IFNDEF BUILDFIXED}
|
||||
{ locals }
|
||||
var
|
||||
fixed_built : Boolean = false;
|
||||
const
|
||||
FIXEDH = 544; { number of hufts used by fixed tables }
|
||||
var
|
||||
fixed_mem : array[0..FIXEDH-1] of inflate_huft;
|
||||
fixed_bl : uInt;
|
||||
fixed_bd : uInt;
|
||||
fixed_tl : pInflate_huft;
|
||||
fixed_td : pInflate_huft;
|
||||
|
||||
{$ELSE}
|
||||
|
||||
{ inffixed.h -- table for decoding fixed codes }
|
||||
|
||||
{local}
|
||||
const
|
||||
fixed_bl = uInt(9);
|
||||
{local}
|
||||
const
|
||||
fixed_bd = uInt(5);
|
||||
{local}
|
||||
const
|
||||
fixed_tl : array [0..288-1] of inflate_huft = (
|
||||
Exop, { number of extra bits or operation }
|
||||
bits : Byte; { number of bits in this code or subcode }
|
||||
{pad : uInt;} { pad structure to a power of 2 (4 bytes for }
|
||||
{ 16-bit, 8 bytes for 32-bit int's) }
|
||||
base : uInt; { literal, length base, or distance base }
|
||||
{ or table offset }
|
||||
|
||||
((96,7),256), ((0,8),80), ((0,8),16), ((84,8),115), ((82,7),31),
|
||||
((0,8),112), ((0,8),48), ((0,9),192), ((80,7),10), ((0,8),96),
|
||||
((0,8),32), ((0,9),160), ((0,8),0), ((0,8),128), ((0,8),64),
|
||||
((0,9),224), ((80,7),6), ((0,8),88), ((0,8),24), ((0,9),144),
|
||||
((83,7),59), ((0,8),120), ((0,8),56), ((0,9),208), ((81,7),17),
|
||||
((0,8),104), ((0,8),40), ((0,9),176), ((0,8),8), ((0,8),136),
|
||||
((0,8),72), ((0,9),240), ((80,7),4), ((0,8),84), ((0,8),20),
|
||||
((85,8),227), ((83,7),43), ((0,8),116), ((0,8),52), ((0,9),200),
|
||||
((81,7),13), ((0,8),100), ((0,8),36), ((0,9),168), ((0,8),4),
|
||||
((0,8),132), ((0,8),68), ((0,9),232), ((80,7),8), ((0,8),92),
|
||||
((0,8),28), ((0,9),152), ((84,7),83), ((0,8),124), ((0,8),60),
|
||||
((0,9),216), ((82,7),23), ((0,8),108), ((0,8),44), ((0,9),184),
|
||||
((0,8),12), ((0,8),140), ((0,8),76), ((0,9),248), ((80,7),3),
|
||||
((0,8),82), ((0,8),18), ((85,8),163), ((83,7),35), ((0,8),114),
|
||||
((0,8),50), ((0,9),196), ((81,7),11), ((0,8),98), ((0,8),34),
|
||||
((0,9),164), ((0,8),2), ((0,8),130), ((0,8),66), ((0,9),228),
|
||||
((80,7),7), ((0,8),90), ((0,8),26), ((0,9),148), ((84,7),67),
|
||||
((0,8),122), ((0,8),58), ((0,9),212), ((82,7),19), ((0,8),106),
|
||||
((0,8),42), ((0,9),180), ((0,8),10), ((0,8),138), ((0,8),74),
|
||||
((0,9),244), ((80,7),5), ((0,8),86), ((0,8),22), ((192,8),0),
|
||||
((83,7),51), ((0,8),118), ((0,8),54), ((0,9),204), ((81,7),15),
|
||||
((0,8),102), ((0,8),38), ((0,9),172), ((0,8),6), ((0,8),134),
|
||||
((0,8),70), ((0,9),236), ((80,7),9), ((0,8),94), ((0,8),30),
|
||||
((0,9),156), ((84,7),99), ((0,8),126), ((0,8),62), ((0,9),220),
|
||||
((82,7),27), ((0,8),110), ((0,8),46), ((0,9),188), ((0,8),14),
|
||||
((0,8),142), ((0,8),78), ((0,9),252), ((96,7),256), ((0,8),81),
|
||||
((0,8),17), ((85,8),131), ((82,7),31), ((0,8),113), ((0,8),49),
|
||||
((0,9),194), ((80,7),10), ((0,8),97), ((0,8),33), ((0,9),162),
|
||||
((0,8),1), ((0,8),129), ((0,8),65), ((0,9),226), ((80,7),6),
|
||||
((0,8),89), ((0,8),25), ((0,9),146), ((83,7),59), ((0,8),121),
|
||||
((0,8),57), ((0,9),210), ((81,7),17), ((0,8),105), ((0,8),41),
|
||||
((0,9),178), ((0,8),9), ((0,8),137), ((0,8),73), ((0,9),242),
|
||||
((80,7),4), ((0,8),85), ((0,8),21), ((80,8),258), ((83,7),43),
|
||||
((0,8),117), ((0,8),53), ((0,9),202), ((81,7),13), ((0,8),101),
|
||||
((0,8),37), ((0,9),170), ((0,8),5), ((0,8),133), ((0,8),69),
|
||||
((0,9),234), ((80,7),8), ((0,8),93), ((0,8),29), ((0,9),154),
|
||||
((84,7),83), ((0,8),125), ((0,8),61), ((0,9),218), ((82,7),23),
|
||||
((0,8),109), ((0,8),45), ((0,9),186), ((0,8),13), ((0,8),141),
|
||||
((0,8),77), ((0,9),250), ((80,7),3), ((0,8),83), ((0,8),19),
|
||||
((85,8),195), ((83,7),35), ((0,8),115), ((0,8),51), ((0,9),198),
|
||||
((81,7),11), ((0,8),99), ((0,8),35), ((0,9),166), ((0,8),3),
|
||||
((0,8),131), ((0,8),67), ((0,9),230), ((80,7),7), ((0,8),91),
|
||||
((0,8),27), ((0,9),150), ((84,7),67), ((0,8),123), ((0,8),59),
|
||||
((0,9),214), ((82,7),19), ((0,8),107), ((0,8),43), ((0,9),182),
|
||||
((0,8),11), ((0,8),139), ((0,8),75), ((0,9),246), ((80,7),5),
|
||||
((0,8),87), ((0,8),23), ((192,8),0), ((83,7),51), ((0,8),119),
|
||||
((0,8),55), ((0,9),206), ((81,7),15), ((0,8),103), ((0,8),39),
|
||||
((0,9),174), ((0,8),7), ((0,8),135), ((0,8),71), ((0,9),238),
|
||||
((80,7),9), ((0,8),95), ((0,8),31), ((0,9),158), ((84,7),99),
|
||||
((0,8),127), ((0,8),63), ((0,9),222), ((82,7),27), ((0,8),111),
|
||||
((0,8),47), ((0,9),190), ((0,8),15), ((0,8),143), ((0,8),79),
|
||||
((0,9),254), ((96,7),256), ((0,8),80), ((0,8),16), ((84,8),115),
|
||||
((82,7),31), ((0,8),112), ((0,8),48), ((0,9),193), ((80,7),10),
|
||||
((0,8),96), ((0,8),32), ((0,9),161), ((0,8),0), ((0,8),128),
|
||||
((0,8),64), ((0,9),225), ((80,7),6), ((0,8),88), ((0,8),24),
|
||||
((0,9),145), ((83,7),59), ((0,8),120), ((0,8),56), ((0,9),209),
|
||||
((81,7),17), ((0,8),104), ((0,8),40), ((0,9),177), ((0,8),8),
|
||||
((0,8),136), ((0,8),72), ((0,9),241), ((80,7),4), ((0,8),84),
|
||||
((0,8),20), ((85,8),227), ((83,7),43), ((0,8),116), ((0,8),52),
|
||||
((0,9),201), ((81,7),13), ((0,8),100), ((0,8),36), ((0,9),169),
|
||||
((0,8),4), ((0,8),132), ((0,8),68), ((0,9),233), ((80,7),8),
|
||||
((0,8),92), ((0,8),28), ((0,9),153), ((84,7),83), ((0,8),124),
|
||||
((0,8),60), ((0,9),217), ((82,7),23), ((0,8),108), ((0,8),44),
|
||||
((0,9),185), ((0,8),12), ((0,8),140), ((0,8),76), ((0,9),249),
|
||||
((80,7),3), ((0,8),82), ((0,8),18), ((85,8),163), ((83,7),35),
|
||||
((0,8),114), ((0,8),50), ((0,9),197), ((81,7),11), ((0,8),98),
|
||||
((0,8),34), ((0,9),165), ((0,8),2), ((0,8),130), ((0,8),66),
|
||||
((0,9),229), ((80,7),7), ((0,8),90), ((0,8),26), ((0,9),149),
|
||||
((84,7),67), ((0,8),122), ((0,8),58), ((0,9),213), ((82,7),19),
|
||||
((0,8),106), ((0,8),42), ((0,9),181), ((0,8),10), ((0,8),138),
|
||||
((0,8),74), ((0,9),245), ((80,7),5), ((0,8),86), ((0,8),22),
|
||||
((192,8),0), ((83,7),51), ((0,8),118), ((0,8),54), ((0,9),205),
|
||||
((81,7),15), ((0,8),102), ((0,8),38), ((0,9),173), ((0,8),6),
|
||||
((0,8),134), ((0,8),70), ((0,9),237), ((80,7),9), ((0,8),94),
|
||||
((0,8),30), ((0,9),157), ((84,7),99), ((0,8),126), ((0,8),62),
|
||||
((0,9),221), ((82,7),27), ((0,8),110), ((0,8),46), ((0,9),189),
|
||||
((0,8),14), ((0,8),142), ((0,8),78), ((0,9),253), ((96,7),256),
|
||||
((0,8),81), ((0,8),17), ((85,8),131), ((82,7),31), ((0,8),113),
|
||||
((0,8),49), ((0,9),195), ((80,7),10), ((0,8),97), ((0,8),33),
|
||||
((0,9),163), ((0,8),1), ((0,8),129), ((0,8),65), ((0,9),227),
|
||||
((80,7),6), ((0,8),89), ((0,8),25), ((0,9),147), ((83,7),59),
|
||||
((0,8),121), ((0,8),57), ((0,9),211), ((81,7),17), ((0,8),105),
|
||||
((0,8),41), ((0,9),179), ((0,8),9), ((0,8),137), ((0,8),73),
|
||||
((0,9),243), ((80,7),4), ((0,8),85), ((0,8),21), ((80,8),258),
|
||||
((83,7),43), ((0,8),117), ((0,8),53), ((0,9),203), ((81,7),13),
|
||||
((0,8),101), ((0,8),37), ((0,9),171), ((0,8),5), ((0,8),133),
|
||||
((0,8),69), ((0,9),235), ((80,7),8), ((0,8),93), ((0,8),29),
|
||||
((0,9),155), ((84,7),83), ((0,8),125), ((0,8),61), ((0,9),219),
|
||||
((82,7),23), ((0,8),109), ((0,8),45), ((0,9),187), ((0,8),13),
|
||||
((0,8),141), ((0,8),77), ((0,9),251), ((80,7),3), ((0,8),83),
|
||||
((0,8),19), ((85,8),195), ((83,7),35), ((0,8),115), ((0,8),51),
|
||||
((0,9),199), ((81,7),11), ((0,8),99), ((0,8),35), ((0,9),167),
|
||||
((0,8),3), ((0,8),131), ((0,8),67), ((0,9),231), ((80,7),7),
|
||||
((0,8),91), ((0,8),27), ((0,9),151), ((84,7),67), ((0,8),123),
|
||||
((0,8),59), ((0,9),215), ((82,7),19), ((0,8),107), ((0,8),43),
|
||||
((0,9),183), ((0,8),11), ((0,8),139), ((0,8),75), ((0,9),247),
|
||||
((80,7),5), ((0,8),87), ((0,8),23), ((192,8),0), ((83,7),51),
|
||||
((0,8),119), ((0,8),55), ((0,9),207), ((81,7),15), ((0,8),103),
|
||||
((0,8),39), ((0,9),175), ((0,8),7), ((0,8),135), ((0,8),71),
|
||||
((0,9),239), ((80,7),9), ((0,8),95), ((0,8),31), ((0,9),159),
|
||||
((84,7),99), ((0,8),127), ((0,8),63), ((0,9),223), ((82,7),27),
|
||||
((0,8),111), ((0,8),47), ((0,9),191), ((0,8),15), ((0,8),143),
|
||||
((0,8),79), ((0,9),255)
|
||||
);
|
||||
|
||||
{local}
|
||||
const
|
||||
fixed_td : array[0..32-1] of inflate_huft = (
|
||||
(Exop:80;bits:5;base:1), (Exop:87;bits:5;base:257), (Exop:83;bits:5;base:17),
|
||||
(Exop:91;bits:5;base:4097), (Exop:81;bits:5;base), (Exop:89;bits:5;base:1025),
|
||||
(Exop:85;bits:5;base:65), (Exop:93;bits:5;base:16385), (Exop:80;bits:5;base:3),
|
||||
(Exop:88;bits:5;base:513), (Exop:84;bits:5;base:33), (Exop:92;bits:5;base:8193),
|
||||
(Exop:82;bits:5;base:9), (Exop:90;bits:5;base:2049), (Exop:86;bits:5;base:129),
|
||||
(Exop:192;bits:5;base:24577), (Exop:80;bits:5;base:2), (Exop:87;bits:5;base:385),
|
||||
(Exop:83;bits:5;base:25), (Exop:91;bits:5;base:6145), (Exop:81;bits:5;base:7),
|
||||
(Exop:89;bits:5;base:1537), (Exop:85;bits:5;base:97), (Exop:93;bits:5;base:24577),
|
||||
(Exop:80;bits:5;base:4), (Exop:88;bits:5;base:769), (Exop:84;bits:5;base:49),
|
||||
(Exop:92;bits:5;base:12289), (Exop:82;bits:5;base:13), (Exop:90;bits:5;base:3073),
|
||||
(Exop:86;bits:5;base:193), (Exop:192;bits:5;base:24577)
|
||||
);
|
||||
{$ENDIF}
|
||||
|
||||
function inflate_trees_fixed(
|
||||
var bl : uInt; { literal desired/actual bit depth }
|
||||
var bd : uInt; { distance desired/actual bit depth }
|
||||
var tl : pInflate_huft; { literal/length tree result }
|
||||
var td : pInflate_huft; { distance tree result }
|
||||
var z : z_stream { for memory allocation }
|
||||
) : int;
|
||||
type
|
||||
pFixed_table = ^fixed_table;
|
||||
fixed_table = array[0..288-1] of uIntf;
|
||||
var
|
||||
k : int; { temporary variable }
|
||||
c : pFixed_table; { length list for huft_build }
|
||||
v : PuIntArray; { work area for huft_build }
|
||||
var
|
||||
f : uInt; { number of hufts used in fixed_mem }
|
||||
begin
|
||||
{ build fixed tables if not already (multiple overlapped executions ok) }
|
||||
if not fixed_built then
|
||||
begin
|
||||
f := 0;
|
||||
|
||||
{ allocate memory }
|
||||
c := pFixed_table( ZALLOC(z, 288, sizeof(uInt)) );
|
||||
if (c = Z_NULL) then
|
||||
begin
|
||||
inflate_trees_fixed := Z_MEM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
v := PuIntArray( ZALLOC(z, 288, sizeof(uInt)) );
|
||||
if (v = Z_NULL) then
|
||||
begin
|
||||
ZFREE(z, c);
|
||||
inflate_trees_fixed := Z_MEM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ literal table }
|
||||
for k := 0 to Pred(144) do
|
||||
c^[k] := 8;
|
||||
for k := 144 to Pred(256) do
|
||||
c^[k] := 9;
|
||||
for k := 256 to Pred(280) do
|
||||
c^[k] := 7;
|
||||
for k := 280 to Pred(288) do
|
||||
c^[k] := 8;
|
||||
fixed_bl := 9;
|
||||
huft_build(c^, 288, 257, cplens, cplext, @fixed_tl, fixed_bl,
|
||||
fixed_mem, f, v^);
|
||||
|
||||
{ distance table }
|
||||
for k := 0 to Pred(30) do
|
||||
c^[k] := 5;
|
||||
fixed_bd := 5;
|
||||
huft_build(c^, 30, 0, cpdist, cpdext, @fixed_td, fixed_bd,
|
||||
fixed_mem, f, v^);
|
||||
|
||||
{ done }
|
||||
ZFREE(z, v);
|
||||
ZFREE(z, c);
|
||||
fixed_built := True;
|
||||
end;
|
||||
bl := fixed_bl;
|
||||
bd := fixed_bd;
|
||||
tl := fixed_tl;
|
||||
td := fixed_td;
|
||||
inflate_trees_fixed := Z_OK;
|
||||
end; { inflate_trees_fixed }
|
||||
|
||||
|
||||
end.
|
||||
140
contrib/fundamentals/ZLib/paszlib/README.txt
Normal file
140
contrib/fundamentals/ZLib/paszlib/README.txt
Normal file
@@ -0,0 +1,140 @@
|
||||
|
||||
This version of PASZLIB was modified by David J Butler, 04/2015
|
||||
for inclusion in the Fundamentals Library.
|
||||
https://github.com/fundamentalslib
|
||||
_____________________________________________________________________________
|
||||
|
||||
This version of PASZLIB was modified by Sergey A. Galin, 02/2003.
|
||||
See the
|
||||
README in directory above for details.
|
||||
|
||||
|
||||
_____________________________________________________________________________
|
||||
|
||||
PASZLIB 1.0 May 11th, 1998
|
||||
|
||||
Based on the zlib 1.1.2, a general purpose data compression library.
|
||||
|
||||
Copyright (C) 1998,1999,2000 by NOMSSI NZALI Jacques H. C.
|
||||
[kn&n DES] See "Legal issues" for conditions of distribution and use.
|
||||
_____________________________________________________________________________
|
||||
|
||||
|
||||
Introduction
|
||||
============
|
||||
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
decompression functions, including integrity checks of the uncompressed
|
||||
data. This version of the library supports only one compression method
|
||||
(deflation) but other algorithms will be added later and will have the same
|
||||
stream interface.
|
||||
|
||||
Compression can be done in a single step if the buffers are large
|
||||
enough (for example if an input file is mmap'ed), or can be done by
|
||||
repeated calls of the compression function. In the latter case, the
|
||||
application must provide more input and/or consume the output
|
||||
(providing more output space) before each call.
|
||||
|
||||
The default memory requirements for deflate are 256K plus a few kilobytes
|
||||
for small objects. The default memory requirements for inflate are 32K
|
||||
plus a few kilobytes for small objects.
|
||||
|
||||
Change Log
|
||||
==========
|
||||
|
||||
March 24th 2000 - minizip code by Gilles Vollant ported to Pascal.
|
||||
z_stream.msg defined as string[255] to avoid problems
|
||||
with Delphi 2+ dynamic string handling.
|
||||
changes to silence Delphi 5 compiler warning. If you
|
||||
have Delphi 5, defines Delphi5 in zconf.inc
|
||||
|
||||
May 7th 1999 - Some changes for FPC
|
||||
deflateCopy() has new parameters
|
||||
trees.pas - record constant definition
|
||||
June 17th 1998 - Applied official 1.1.2 patch.
|
||||
Memcheck turned off by default.
|
||||
zutil.pas patch for Delphi 1 memory allocation corrected.
|
||||
dzlib.txt file added.
|
||||
compress2() is now exported
|
||||
|
||||
June 25th 1998 - fixed a conversion bug: in inftrees.pas, ZFREE(z, v) was
|
||||
missing in line 574;
|
||||
|
||||
File list
|
||||
=========
|
||||
|
||||
Here is a road map to the files in the Paszlib distribution.
|
||||
|
||||
readme.txt Introduction, Documentation
|
||||
dzlib.txt Changes to Delphi sources for Paszlib stream classes
|
||||
|
||||
include file
|
||||
|
||||
zconf.inc Configuration declarations.
|
||||
|
||||
Pascal source code files:
|
||||
|
||||
adler.pas compute the Adler-32 checksum of a data stream
|
||||
crc.pas compute the CRC-32 of a data stream
|
||||
gzio.pas IO on .gz files
|
||||
infblock.pas interpret and process block types to last block
|
||||
infcodes.pas process literals and length/distance pairs
|
||||
inffast.pas process literals and length/distance pairs fast
|
||||
inftrees.pas generate Huffman trees for efficient decoding
|
||||
infutil.pas types and macros common to blocks and codes
|
||||
strutils.pas string utilities
|
||||
trees.pas output deflated data using Huffman coding
|
||||
zcompres.pas compress a memory buffer
|
||||
zdeflate.pas compress data using the deflation algorithm
|
||||
zinflate.pas zlib interface to inflate modules
|
||||
zlib.pas zlib data structures. read the comments there!
|
||||
zuncompr.pas decompress a memory buffer
|
||||
zutil.pas
|
||||
|
||||
minizip/ziputils.pas data structure and IO on .zip file
|
||||
minizip/unzip.pas
|
||||
minizip/zip.pas
|
||||
|
||||
Test applications
|
||||
|
||||
example.pas usage example of the zlib compression library
|
||||
minigzip.pas simulate gzip using the zlib compression library
|
||||
minizip/miniunz.pas simulates unzip using the zlib compression library
|
||||
minizip/minizip.pas simulates zip using the zlib compression library
|
||||
|
||||
Legal issues
|
||||
============
|
||||
|
||||
Copyright (C) 1998,1999,2000 by Jacques Nomssi Nzali
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
Archive Locations:
|
||||
==================
|
||||
|
||||
Check the Paszlib home page with links
|
||||
|
||||
http://www.tu-chemnitz.de/~nomssi/paszlib.html
|
||||
|
||||
The data format used by the zlib library is described by RFCs (Request for
|
||||
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
|
||||
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||
These documents are also available in other formats from
|
||||
ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html.
|
||||
____________________________________________________________________________
|
||||
Jacques Nomssi Nzali <mailto:nomssi@physik.tu-chemnitz.de> March 24th, 2000
|
||||
557
contrib/fundamentals/ZLib/paszlib/ZUtil.pas
Normal file
557
contrib/fundamentals/ZLib/paszlib/ZUtil.pas
Normal file
@@ -0,0 +1,557 @@
|
||||
Unit ZUtil;
|
||||
{
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
|
||||
Modified 04/2015 by David J Butler for additional compilers compatibility.
|
||||
}
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
{$IFNDEF SupportRawByteString}
|
||||
type
|
||||
AnsiChar = Byte;
|
||||
AnsiString = array of AnsiChar;
|
||||
RawByteString = AnsiString;
|
||||
PRawByteString = ^RawByteString;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF SupportNativeUInt}
|
||||
type
|
||||
{$IFDEF CPU_X86_64}
|
||||
{$IFNDEF SupportUInt64}
|
||||
UInt64 = type Int64;
|
||||
Word64 = UInt64;
|
||||
{$ENDIF}
|
||||
NativeUInt = type Word64;
|
||||
{$ELSE}
|
||||
NativeUInt = type Cardinal;
|
||||
{$ENDIF}
|
||||
PNativeUInt = ^NativeUInt;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF FREEPASCAL}
|
||||
type
|
||||
PNativeUInt = ^NativeUInt;
|
||||
{$ENDIF}
|
||||
|
||||
{ Type declarations }
|
||||
|
||||
type
|
||||
{Byte = usigned char; 8 bits}
|
||||
Bytef = byte;
|
||||
charf = byte;
|
||||
int = integer;
|
||||
intf = int;
|
||||
uInt = cardinal; { 16 bits or more }
|
||||
uIntf = uInt;
|
||||
|
||||
Long = longint;
|
||||
uLong = Cardinal;
|
||||
uLongf = uLong;
|
||||
|
||||
voidp = pointer;
|
||||
voidpf = voidp;
|
||||
pBytef = ^Bytef;
|
||||
pIntf = ^intf;
|
||||
puIntf = ^uIntf;
|
||||
puLong = ^uLongf;
|
||||
|
||||
ptr2int = NativeUInt;
|
||||
{ a pointer to integer casting is used to do pointer arithmetic.
|
||||
ptr2int must be an integer type and sizeof(ptr2int) must be less
|
||||
than sizeof(pointer) - Nomssi }
|
||||
|
||||
const
|
||||
{$IFDEF MAXSEG_64K}
|
||||
MaxMemBlock = $FFFF;
|
||||
{$ELSE}
|
||||
MaxMemBlock = MaxInt;
|
||||
{$ENDIF}
|
||||
|
||||
type
|
||||
zByteArray = array[0..(MaxMemBlock div SizeOf(Bytef))-1] of Bytef;
|
||||
pzByteArray = ^zByteArray;
|
||||
type
|
||||
zIntfArray = array[0..(MaxMemBlock div SizeOf(Intf))-1] of Intf;
|
||||
pzIntfArray = ^zIntfArray;
|
||||
type
|
||||
zuIntArray = array[0..(MaxMemBlock div SizeOf(uInt))-1] of uInt;
|
||||
PuIntArray = ^zuIntArray;
|
||||
|
||||
{ Type declarations - only for deflate }
|
||||
|
||||
type
|
||||
uch = Byte;
|
||||
uchf = uch; { FAR }
|
||||
ush = Word;
|
||||
ushf = ush;
|
||||
ulg = LongInt;
|
||||
|
||||
unsigned = uInt;
|
||||
|
||||
pcharf = ^charf;
|
||||
puchf = ^uchf;
|
||||
pushf = ^ushf;
|
||||
|
||||
type
|
||||
zuchfArray = zByteArray;
|
||||
puchfArray = ^zuchfArray;
|
||||
type
|
||||
zushfArray = array[0..(MaxMemBlock div SizeOf(ushf))-1] of ushf;
|
||||
pushfArray = ^zushfArray;
|
||||
|
||||
procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt);
|
||||
function zmemcmp(s1p, s2p : pBytef; len : uInt) : int;
|
||||
procedure zmemzero(destp : pBytef; len : uInt);
|
||||
procedure zcfree(opaque : voidpf; ptr : voidpf);
|
||||
function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf;
|
||||
|
||||
implementation
|
||||
|
||||
{$ifdef ver80}
|
||||
{$define Delphi16}
|
||||
{$endif}
|
||||
{$ifdef ver70}
|
||||
{$define HugeMem}
|
||||
{$endif}
|
||||
{$ifdef ver60}
|
||||
{$define HugeMem}
|
||||
{$endif}
|
||||
|
||||
{$IFDEF CALLDOS}
|
||||
uses
|
||||
WinDos;
|
||||
{$ENDIF}
|
||||
{$IFDEF Delphi16}
|
||||
uses
|
||||
WinTypes,
|
||||
WinProcs;
|
||||
{$ENDIF}
|
||||
{$IFNDEF FPC}
|
||||
{$IFDEF DPMI}
|
||||
uses
|
||||
WinAPI;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF CALLDOS}
|
||||
{ reduce your application memory footprint with $M before using this }
|
||||
function dosAlloc (Size : Longint) : Pointer;
|
||||
var
|
||||
regs: TRegisters;
|
||||
begin
|
||||
regs.bx := (Size + 15) div 16; { number of 16-bytes-paragraphs }
|
||||
regs.ah := $48; { Allocate memory block }
|
||||
msdos(regs);
|
||||
if regs.Flags and FCarry <> 0 then
|
||||
DosAlloc := NIL
|
||||
else
|
||||
DosAlloc := Ptr(regs.ax, 0);
|
||||
end;
|
||||
|
||||
|
||||
function dosFree(P : pointer) : boolean;
|
||||
var
|
||||
regs: TRegisters;
|
||||
begin
|
||||
dosFree := FALSE;
|
||||
regs.bx := Seg(P^); { segment }
|
||||
if Ofs(P) <> 0 then
|
||||
exit;
|
||||
regs.ah := $49; { Free memory block }
|
||||
msdos(regs);
|
||||
dosFree := (regs.Flags and FCarry = 0);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
type
|
||||
LH = record
|
||||
L, H : word;
|
||||
end;
|
||||
|
||||
{$IFDEF HugeMem}
|
||||
{$define HEAP_LIST}
|
||||
{$endif}
|
||||
|
||||
{$IFDEF HEAP_LIST} {--- to avoid Mark and Release --- }
|
||||
const
|
||||
MaxAllocEntries = 50;
|
||||
type
|
||||
TMemRec = record
|
||||
orgvalue,
|
||||
value : pointer;
|
||||
size: longint;
|
||||
end;
|
||||
const
|
||||
allocatedCount : 0..MaxAllocEntries = 0;
|
||||
var
|
||||
allocatedList : array[0..MaxAllocEntries-1] of TMemRec;
|
||||
|
||||
function NewAllocation(ptr0, ptr : pointer; memsize : longint) : boolean;
|
||||
begin
|
||||
if (allocatedCount < MaxAllocEntries) and (ptr0 <> NIL) then
|
||||
begin
|
||||
with allocatedList[allocatedCount] do
|
||||
begin
|
||||
orgvalue := ptr0;
|
||||
value := ptr;
|
||||
size := memsize;
|
||||
end;
|
||||
Inc(allocatedCount); { we don't check for duplicate }
|
||||
NewAllocation := TRUE;
|
||||
end
|
||||
else
|
||||
NewAllocation := FALSE;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF HugeMem}
|
||||
|
||||
{ The code below is extremely version specific to the TP 6/7 heap manager!!}
|
||||
type
|
||||
PFreeRec = ^TFreeRec;
|
||||
TFreeRec = record
|
||||
next: PFreeRec;
|
||||
size: Pointer;
|
||||
end;
|
||||
type
|
||||
HugePtr = voidpf;
|
||||
|
||||
|
||||
procedure IncPtr(var p:pointer;count:word);
|
||||
{ Increments pointer }
|
||||
begin
|
||||
inc(LH(p).L,count);
|
||||
if LH(p).L < count then
|
||||
inc(LH(p).H,SelectorInc); { $1000 }
|
||||
end;
|
||||
|
||||
procedure DecPtr(var p:pointer;count:word);
|
||||
{ decrements pointer }
|
||||
begin
|
||||
if count > LH(p).L then
|
||||
dec(LH(p).H,SelectorInc);
|
||||
dec(LH(p).L,Count);
|
||||
end;
|
||||
|
||||
procedure IncPtrLong(var p:pointer;count:longint);
|
||||
{ Increments pointer; assumes count > 0 }
|
||||
begin
|
||||
inc(LH(p).H,SelectorInc*LH(count).H);
|
||||
inc(LH(p).L,LH(Count).L);
|
||||
if LH(p).L < LH(count).L then
|
||||
inc(LH(p).H,SelectorInc);
|
||||
end;
|
||||
|
||||
procedure DecPtrLong(var p:pointer;count:longint);
|
||||
{ Decrements pointer; assumes count > 0 }
|
||||
begin
|
||||
if LH(count).L > LH(p).L then
|
||||
dec(LH(p).H,SelectorInc);
|
||||
dec(LH(p).L,LH(Count).L);
|
||||
dec(LH(p).H,SelectorInc*LH(Count).H);
|
||||
end;
|
||||
{ The next section is for real mode only }
|
||||
|
||||
function Normalized(p : pointer) : pointer;
|
||||
var
|
||||
count : word;
|
||||
begin
|
||||
count := LH(p).L and $FFF0;
|
||||
Normalized := Ptr(LH(p).H + (count shr 4), LH(p).L and $F);
|
||||
end;
|
||||
|
||||
procedure FreeHuge(var p:HugePtr; size : longint);
|
||||
const
|
||||
blocksize = $FFF0;
|
||||
var
|
||||
block : word;
|
||||
begin
|
||||
while size > 0 do
|
||||
begin
|
||||
{ block := minimum(size, blocksize); }
|
||||
if size > blocksize then
|
||||
block := blocksize
|
||||
else
|
||||
block := size;
|
||||
|
||||
dec(size,block);
|
||||
freemem(p,block);
|
||||
IncPtr(p,block); { we may get ptr($xxxx, $fff8) and 31 bytes left }
|
||||
p := Normalized(p); { to free, so we must normalize }
|
||||
end;
|
||||
end;
|
||||
|
||||
function FreeMemHuge(ptr : pointer) : boolean;
|
||||
var
|
||||
i : integer; { -1..MaxAllocEntries }
|
||||
begin
|
||||
FreeMemHuge := FALSE;
|
||||
i := allocatedCount - 1;
|
||||
while (i >= 0) do
|
||||
begin
|
||||
if (ptr = allocatedList[i].value) then
|
||||
begin
|
||||
with allocatedList[i] do
|
||||
FreeHuge(orgvalue, size);
|
||||
|
||||
Move(allocatedList[i+1], allocatedList[i],
|
||||
SizeOf(TMemRec)*(allocatedCount - 1 - i));
|
||||
Dec(allocatedCount);
|
||||
FreeMemHuge := TRUE;
|
||||
break;
|
||||
end;
|
||||
Dec(i);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure GetMemHuge(var p:HugePtr;memsize:Longint);
|
||||
const
|
||||
blocksize = $FFF0;
|
||||
var
|
||||
size : longint;
|
||||
prev,free : PFreeRec;
|
||||
save,temp : pointer;
|
||||
block : word;
|
||||
begin
|
||||
p := NIL;
|
||||
{ Handle the easy cases first }
|
||||
if memsize > maxavail then
|
||||
exit
|
||||
else
|
||||
if memsize <= blocksize then
|
||||
begin
|
||||
getmem(p, memsize);
|
||||
if not NewAllocation(p, p, memsize) then
|
||||
begin
|
||||
FreeMem(p, memsize);
|
||||
p := NIL;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
size := memsize + 15;
|
||||
|
||||
{ Find the block that has enough space }
|
||||
prev := PFreeRec(@freeList);
|
||||
free := prev^.next;
|
||||
while (free <> heapptr) and (ptr2int(free^.size) < size) do
|
||||
begin
|
||||
prev := free;
|
||||
free := prev^.next;
|
||||
end;
|
||||
|
||||
{ Now free points to a region with enough space; make it the first one and
|
||||
multiple allocations will be contiguous. }
|
||||
|
||||
save := freelist;
|
||||
freelist := free;
|
||||
{ In TP 6, this works; check against other heap managers }
|
||||
while size > 0 do
|
||||
begin
|
||||
{ block := minimum(size, blocksize); }
|
||||
if size > blocksize then
|
||||
block := blocksize
|
||||
else
|
||||
block := size;
|
||||
dec(size,block);
|
||||
getmem(temp,block);
|
||||
end;
|
||||
|
||||
{ We've got what we want now; just sort things out and restore the
|
||||
free list to normal }
|
||||
|
||||
p := free;
|
||||
if prev^.next <> freelist then
|
||||
begin
|
||||
prev^.next := freelist;
|
||||
freelist := save;
|
||||
end;
|
||||
|
||||
if (p <> NIL) then
|
||||
begin
|
||||
{ return pointer with 0 offset }
|
||||
temp := p;
|
||||
if Ofs(p^)<>0 Then
|
||||
p := Ptr(Seg(p^)+1,0); { hack }
|
||||
if not NewAllocation(temp, p, memsize + 15) then
|
||||
begin
|
||||
FreeHuge(temp, size);
|
||||
p := NIL;
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
end;
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt);
|
||||
begin
|
||||
Move(sourcep^, destp^, len);
|
||||
end;
|
||||
|
||||
function zmemcmp(s1p, s2p : pBytef; len : uInt) : int;
|
||||
var
|
||||
j : uInt;
|
||||
source,
|
||||
dest : pBytef;
|
||||
begin
|
||||
source := s1p;
|
||||
dest := s2p;
|
||||
for j := 0 to pred(len) do
|
||||
begin
|
||||
if (source^ <> dest^) then
|
||||
begin
|
||||
zmemcmp := 2*Ord(source^ > dest^)-1;
|
||||
exit;
|
||||
end;
|
||||
Inc(source);
|
||||
Inc(dest);
|
||||
end;
|
||||
zmemcmp := 0;
|
||||
end;
|
||||
|
||||
procedure zmemzero(destp : pBytef; len : uInt);
|
||||
begin
|
||||
FillChar(destp^, len, 0);
|
||||
end;
|
||||
|
||||
procedure zcfree(opaque : voidpf; ptr : voidpf);
|
||||
{$ifdef Delphi16}
|
||||
var
|
||||
Handle : THandle;
|
||||
{$endif}
|
||||
{$IFDEF FPC}
|
||||
var
|
||||
memsize : uint;
|
||||
{$ENDIF}
|
||||
begin
|
||||
{$IFDEF DPMI}
|
||||
{h :=} GlobalFreePtr(ptr);
|
||||
{$ELSE}
|
||||
{$IFDEF CALL_DOS}
|
||||
dosFree(ptr);
|
||||
{$ELSE}
|
||||
{$ifdef HugeMem}
|
||||
FreeMemHuge(ptr);
|
||||
{$else}
|
||||
{$ifdef Delphi16}
|
||||
Handle := GlobalHandle(LH(ptr).H); { HiWord(LongInt(ptr)) }
|
||||
GlobalUnLock(Handle);
|
||||
GlobalFree(Handle);
|
||||
{$else}
|
||||
{$IFDEF FPC}
|
||||
Dec(puIntf(ptr));
|
||||
memsize := puIntf(ptr)^;
|
||||
FreeMem(ptr, memsize+SizeOf(uInt));
|
||||
{$ELSE}
|
||||
FreeMem(ptr); { Delphi 2,3,4 }
|
||||
{$ENDIF}
|
||||
{$endif}
|
||||
{$endif}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf;
|
||||
var
|
||||
p : voidpf;
|
||||
memsize : uLong;
|
||||
{$ifdef Delphi16}
|
||||
handle : THandle;
|
||||
{$endif}
|
||||
begin
|
||||
memsize := uLong(items) * size;
|
||||
{$IFDEF DPMI}
|
||||
p := GlobalAllocPtr(gmem_moveable, memsize);
|
||||
{$ELSE}
|
||||
{$IFDEF CALLDOS}
|
||||
p := dosAlloc(memsize);
|
||||
{$ELSE}
|
||||
{$ifdef HugeMem}
|
||||
GetMemHuge(p, memsize);
|
||||
{$else}
|
||||
{$ifdef Delphi16}
|
||||
Handle := GlobalAlloc(HeapAllocFlags, memsize);
|
||||
p := GlobalLock(Handle);
|
||||
{$else}
|
||||
{$IFDEF FPC}
|
||||
GetMem(p, memsize+SizeOf(uInt));
|
||||
puIntf(p)^:= memsize;
|
||||
Inc(puIntf(p));
|
||||
{$ELSE}
|
||||
GetMem(p, memsize); { Delphi: p := AllocMem(memsize); }
|
||||
{$ENDIF}
|
||||
{$endif}
|
||||
{$endif}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
zcalloc := p;
|
||||
end;
|
||||
|
||||
|
||||
{ edited from a SWAG posting:
|
||||
|
||||
In Turbo Pascal 6, the heap is the memory allocated when using the Procedures 'New' and
|
||||
'GetMem'. The heap starts at the address location pointed to by 'Heaporg' and
|
||||
grows to higher addresses as more memory is allocated. The top of the heap,
|
||||
the first address of allocatable memory space above the allocated memory
|
||||
space, is pointed to by 'HeapPtr'.
|
||||
|
||||
Memory is deallocated by the Procedures 'Dispose' and 'FreeMem'. As memory
|
||||
blocks are deallocated more memory becomes available, but..... When a block
|
||||
of memory, which is not the top-most block in the heap is deallocated, a gap
|
||||
in the heap will appear. to keep track of these gaps Turbo Pascal maintains
|
||||
a so called free list.
|
||||
|
||||
The Function 'MaxAvail' holds the size of the largest contiguous free block
|
||||
_in_ the heap. The Function 'MemAvail' holds the sum of all free blocks in
|
||||
the heap.
|
||||
|
||||
TP6.0 keeps track of the free blocks by writing a 'free list Record' to the
|
||||
first eight Bytes of the freed memory block! A (TP6.0) free-list Record
|
||||
contains two four Byte Pointers of which the first one points to the next
|
||||
free memory block, the second Pointer is not a Real Pointer but contains the
|
||||
size of the memory block.
|
||||
|
||||
Summary
|
||||
|
||||
TP6.0 maintains a linked list with block sizes and Pointers to the _next_
|
||||
free block. An extra heap Variable 'Heapend' designate the end of the heap.
|
||||
When 'HeapPtr' and 'FreeList' have the same value, the free list is empty.
|
||||
|
||||
|
||||
TP6.0 Heapend
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ <<3C><><EFBFBD><EFBFBD>
|
||||
<20> <20>
|
||||
<20> <20>
|
||||
<20> <20>
|
||||
<20> <20>
|
||||
<20> <20>
|
||||
<20> <20>
|
||||
<20> <20>
|
||||
<20> <20> HeapPtr
|
||||
<20><>><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ <<3C><><EFBFBD><EFBFBD>
|
||||
<20> <20> <20>
|
||||
<20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ
|
||||
<20><>ij Free <20>
|
||||
<20><>><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ
|
||||
<20> <20> <20>
|
||||
<20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ
|
||||
<20><>ij Free <20> FreeList
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ <<3C><><EFBFBD><EFBFBD>
|
||||
<20> <20> Heaporg
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ <<3C><><EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
}
|
||||
|
||||
end.
|
||||
|
||||
485
contrib/fundamentals/ZLib/paszlib/dzlib.pas
Normal file
485
contrib/fundamentals/ZLib/paszlib/dzlib.pas
Normal file
@@ -0,0 +1,485 @@
|
||||
{*******************************************************}
|
||||
{ }
|
||||
{ Delphi Supplemental Components }
|
||||
{ ZLIB Data Compression Interface Unit }
|
||||
{ }
|
||||
{ Copyright (c) 1997 Borland International }
|
||||
{ Copyright (c) 1998 Jacques Nomssi Nzali }
|
||||
{ }
|
||||
{*******************************************************}
|
||||
|
||||
unit dzlib;
|
||||
|
||||
{$WARN UNSAFE_TYPE OFF}
|
||||
{$WARN UNSAFE_CODE OFF}
|
||||
|
||||
interface
|
||||
|
||||
uses gzlib, Sysutils, Classes;
|
||||
|
||||
{$IFDEF VER80}
|
||||
{$DEFINE Delphi16}
|
||||
{$ENDIF}
|
||||
|
||||
type
|
||||
TAlloc = alloc_func;
|
||||
{function (AppData: Pointer; Items, Size: Integer): Pointer;}
|
||||
TFree = free_func;
|
||||
{procedure (AppData, Block: Pointer);}
|
||||
|
||||
{ Internal structure. Ignore. }
|
||||
TZStreamRec = z_stream;
|
||||
|
||||
const
|
||||
FBufSize = 8192;
|
||||
type
|
||||
{ Abstract ancestor class }
|
||||
TCustomZlibStream = class(TStream)
|
||||
private
|
||||
FStrm: TStream;
|
||||
FStrmPos: Integer;
|
||||
FOnProgress: TNotifyEvent;
|
||||
FZRec: TZStreamRec;
|
||||
FBuffer: array [0..FBufSize-1] of Char;
|
||||
protected
|
||||
procedure Progress(Sender: TObject); dynamic;
|
||||
property OnProgress: TNotifyEvent read FOnProgress write FOnProgress;
|
||||
constructor Create(Strm: TStream);
|
||||
end;
|
||||
|
||||
{ TCompressionStream compresses data on the fly as data is written to it, and
|
||||
stores the compressed data to another stream.
|
||||
|
||||
TCompressionStream is write-only and strictly sequential. Reading from the
|
||||
stream will raise an exception. Using Seek to move the stream pointer
|
||||
will raise an exception.
|
||||
|
||||
Output data is cached internally, written to the output stream only when
|
||||
the internal output buffer is full. All pending output data is flushed
|
||||
when the stream is destroyed.
|
||||
|
||||
The Position property returns the number of uncompressed bytes of
|
||||
data that have been written to the stream so far.
|
||||
|
||||
CompressionRate returns the on-the-fly percentage by which the original
|
||||
data has been compressed: (1 - (CompressedBytes / UncompressedBytes)) * 100
|
||||
If raw data size = 100 and compressed data size = 25, the CompressionRate
|
||||
is 75%
|
||||
|
||||
The OnProgress event is called each time the output buffer is filled and
|
||||
written to the output stream. This is useful for updating a progress
|
||||
indicator when you are writing a large chunk of data to the compression
|
||||
stream in a single call.}
|
||||
|
||||
|
||||
TCompressionLevel = (clNone, clFastest, clDefault, clMax);
|
||||
|
||||
TCompressionStream = class(TCustomZlibStream)
|
||||
private
|
||||
function GetCompressionRate: Single;
|
||||
public
|
||||
constructor Create(CompressionLevel: TCompressionLevel; Dest: TStream);
|
||||
destructor Destroy; override;
|
||||
function Read(var Buffer; Count: Longint): Longint; override;
|
||||
function Write(const Buffer; Count: Longint): Longint; override;
|
||||
function Seek(Offset: Longint; Origin: Word): Longint; override;
|
||||
property CompressionRate: Single read GetCompressionRate;
|
||||
property OnProgress;
|
||||
end;
|
||||
|
||||
{ TDecompressionStream decompresses data on the fly as data is read from it.
|
||||
|
||||
Compressed data comes from a separate source stream. TDecompressionStream
|
||||
is read-only and unidirectional; you can seek forward in the stream, but not
|
||||
backwards. The special case of setting the stream position to zero is
|
||||
allowed. Seeking forward decompresses data until the requested position in
|
||||
the uncompressed data has been reached. Seeking backwards, seeking relative
|
||||
to the end of the stream, requesting the size of the stream, and writing to
|
||||
the stream will raise an exception.
|
||||
|
||||
The Position property returns the number of bytes of uncompressed data that
|
||||
have been read from the stream so far.
|
||||
|
||||
The OnProgress event is called each time the internal input buffer of
|
||||
compressed data is exhausted and the next block is read from the input stream.
|
||||
This is useful for updating a progress indicator when you are reading a
|
||||
large chunk of data from the decompression stream in a single call.}
|
||||
|
||||
TDecompressionStream = class(TCustomZlibStream)
|
||||
public
|
||||
constructor Create(Source: TStream);
|
||||
destructor Destroy; override;
|
||||
function Read(var Buffer; Count: Longint): Longint; override;
|
||||
function Write(const Buffer; Count: Longint): Longint; override;
|
||||
function Seek(Offset: Longint; Origin: Word): Longint; override;
|
||||
property OnProgress;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{ CompressBuf compresses data, buffer to buffer, in one call.
|
||||
In: InBuf = ptr to compressed data
|
||||
InBytes = number of bytes in InBuf
|
||||
Out: OutBuf = ptr to newly allocated buffer containing decompressed data
|
||||
OutBytes = number of bytes in OutBuf }
|
||||
{$IFDEF Delphi16}
|
||||
procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
|
||||
var OutBuf: Pointer; var OutBytes: Integer);
|
||||
{$ELSE}
|
||||
procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
|
||||
out OutBuf: Pointer; out OutBytes: Integer);
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{ DecompressBuf decompresses data, buffer to buffer, in one call.
|
||||
In: InBuf = ptr to compressed data
|
||||
InBytes = number of bytes in InBuf
|
||||
OutEstimate = zero, or est. size of the decompressed data
|
||||
Out: OutBuf = ptr to newly allocated buffer containing decompressed data
|
||||
OutBytes = number of bytes in OutBuf }
|
||||
{$IFDEF Delphi16}
|
||||
procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
|
||||
OutEstimate: Integer; var OutBuf: Pointer; var OutBytes: Integer);
|
||||
{$ELSE}
|
||||
procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
|
||||
OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
|
||||
{$ENDIF}
|
||||
type
|
||||
EZlibError = class(Exception);
|
||||
ECompressionError = class(EZlibError);
|
||||
EDecompressionError = class(EZlibError);
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
{$IFDEF Delphi16}
|
||||
WinTypes, WinProcs,
|
||||
{$ENDIF}
|
||||
zutil, zDeflate, zInflate;
|
||||
|
||||
{$IFDEF Delphi16}
|
||||
Procedure zlibFreeMem(AppData, Block: Pointer); far;
|
||||
type
|
||||
LH = packed record
|
||||
L, H : word;
|
||||
end;
|
||||
var
|
||||
Handle : THandle;
|
||||
begin
|
||||
Handle := GlobalHandle(LH(Block).H); { HiWord(LongInt(ptr)) }
|
||||
GlobalUnLock(Handle);
|
||||
GlobalFree(Handle);
|
||||
end;
|
||||
|
||||
function zlibAllocMem(AppData: Pointer; Items, Size: Cardinal): Pointer; far;
|
||||
var
|
||||
handle : THandle;
|
||||
begin
|
||||
Handle := GlobalAlloc(HeapAllocFlags, Long(Items) * Size);
|
||||
zlibAllocMem := GlobalLock(Handle);
|
||||
end;
|
||||
|
||||
procedure ReAllocMem(OutBuf : voidpf; OutBytes : uInt);
|
||||
begin
|
||||
zlibFreeMem(NIL, OutBuf);
|
||||
OutBuf := zlibAllocMem(NIL, OutBytes, 1);
|
||||
end;
|
||||
|
||||
{$ELSE}
|
||||
function zlibAllocMem(AppData: Pointer; Items, Size: Cardinal): Pointer;
|
||||
begin
|
||||
GetMem(Result, Items*Size);
|
||||
end;
|
||||
|
||||
procedure zlibFreeMem(AppData, Block: Pointer);
|
||||
begin
|
||||
FreeMem(Block);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function zlibCheck(code: Integer): Integer;
|
||||
begin
|
||||
Result := code;
|
||||
if code < 0 then
|
||||
raise EZlibError.Create('error'); {!!}
|
||||
end;
|
||||
|
||||
function CCheck(code: Integer): Integer;
|
||||
begin
|
||||
Result := code;
|
||||
if code < 0 then
|
||||
raise ECompressionError.Create('error'); {!!}
|
||||
end;
|
||||
|
||||
function DCheck(code: Integer): Integer;
|
||||
begin
|
||||
Result := code;
|
||||
if code < 0 then
|
||||
raise EDecompressionError.Create('error'); {!!}
|
||||
end;
|
||||
|
||||
|
||||
{$IFDEF Delphi16}
|
||||
procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
|
||||
var OutBuf: Pointer; var OutBytes: Integer);
|
||||
{$ELSE}
|
||||
procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
|
||||
out OutBuf: Pointer; out OutBytes: Integer);
|
||||
{$ENDIF}
|
||||
var
|
||||
strm: TZStreamRec;
|
||||
P: Pointer;
|
||||
begin
|
||||
FillChar(strm, sizeof(strm), 0);
|
||||
strm.zalloc := zlibAllocMem;
|
||||
strm.zfree := zlibFreeMem;
|
||||
OutBytes := ((InBytes + (InBytes div 10) + 12) + 255) and not 255;
|
||||
GetMem(OutBuf, OutBytes);
|
||||
try
|
||||
strm.next_in := InBuf;
|
||||
strm.avail_in := InBytes;
|
||||
strm.next_out := OutBuf;
|
||||
strm.avail_out := OutBytes;
|
||||
CCheck(deflateInit_(@strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm)));
|
||||
try
|
||||
while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do
|
||||
begin
|
||||
P := OutBuf;
|
||||
Inc(OutBytes, 256);
|
||||
ReallocMem(OutBuf, OutBytes);
|
||||
strm.next_out := pBytef(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
|
||||
strm.avail_out := 256;
|
||||
end;
|
||||
finally
|
||||
CCheck(deflateEnd(strm));
|
||||
end;
|
||||
ReallocMem(OutBuf, strm.total_out);
|
||||
OutBytes := strm.total_out;
|
||||
except
|
||||
{$IFDEF Delphi16} {next line changed} {$ENDIF}
|
||||
zlibFreeMem(NIL, OutBuf);
|
||||
raise
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{$IFDEF Delphi16}
|
||||
procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
|
||||
OutEstimate: Integer; var OutBuf: Pointer; var OutBytes: Integer);
|
||||
{$ELSE}
|
||||
procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
|
||||
OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
|
||||
{$ENDIF}
|
||||
var
|
||||
strm: TZStreamRec;
|
||||
P: Pointer;
|
||||
BufInc: Integer;
|
||||
begin
|
||||
FillChar(strm, sizeof(strm), 0);
|
||||
strm.zalloc := zlibAllocMem;
|
||||
strm.zfree := zlibFreeMem;
|
||||
BufInc := (InBytes + 255) and not 255;
|
||||
if OutEstimate = 0 then
|
||||
OutBytes := BufInc
|
||||
else
|
||||
OutBytes := OutEstimate;
|
||||
GetMem(OutBuf, OutBytes);
|
||||
try
|
||||
strm.next_in := InBuf;
|
||||
strm.avail_in := InBytes;
|
||||
strm.next_out := OutBuf;
|
||||
strm.avail_out := OutBytes;
|
||||
DCheck(inflateInit_(@strm, zlib_version, sizeof(strm)));
|
||||
try
|
||||
while inflate(strm, Z_FINISH) <> Z_STREAM_END do
|
||||
begin
|
||||
P := OutBuf;
|
||||
Inc(OutBytes, BufInc);
|
||||
ReallocMem(OutBuf, OutBytes);
|
||||
strm.next_out := pBytef(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
|
||||
strm.avail_out := BufInc;
|
||||
end;
|
||||
finally
|
||||
DCheck(inflateEnd(strm));
|
||||
end;
|
||||
ReallocMem(OutBuf, strm.total_out);
|
||||
OutBytes := strm.total_out;
|
||||
except
|
||||
{$IFDEF Delphi16} {next line changed} {$ENDIF}
|
||||
zlibFreeMem(NIL, OutBuf);
|
||||
raise
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ TCustomZlibStream }
|
||||
|
||||
constructor TCustomZLibStream.Create(Strm: TStream);
|
||||
begin
|
||||
inherited Create;
|
||||
FStrm := Strm;
|
||||
FStrmPos := Strm.Position;
|
||||
FZRec.zalloc := zlibAllocMem;
|
||||
FZRec.zfree := zlibFreeMem;
|
||||
end;
|
||||
|
||||
procedure TCustomZLibStream.Progress(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FOnProgress) then FOnProgress(Sender);
|
||||
end;
|
||||
|
||||
|
||||
{ TCompressionStream }
|
||||
|
||||
constructor TCompressionStream.Create(CompressionLevel: TCompressionLevel;
|
||||
Dest: TStream);
|
||||
const
|
||||
Levels: array [TCompressionLevel] of ShortInt =
|
||||
(Z_NO_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_BEST_COMPRESSION);
|
||||
begin
|
||||
inherited Create(Dest);
|
||||
FZRec.next_out := @FBuffer;
|
||||
FZRec.avail_out := sizeof(FBuffer);
|
||||
CCheck(deflateInit_(@FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec)));
|
||||
end;
|
||||
|
||||
destructor TCompressionStream.Destroy;
|
||||
begin
|
||||
FZRec.next_in := nil;
|
||||
FZRec.avail_in := 0;
|
||||
try
|
||||
if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
|
||||
while (CCheck(deflate(FZRec, Z_FINISH)) <> Z_STREAM_END)
|
||||
and (FZRec.avail_out = 0) do
|
||||
begin
|
||||
FStrm.WriteBuffer(FBuffer, sizeof(FBuffer));
|
||||
FZRec.next_out := @FBuffer;
|
||||
FZRec.avail_out := sizeof(FBuffer);
|
||||
end;
|
||||
if FZRec.avail_out < sizeof(FBuffer) then
|
||||
FStrm.WriteBuffer(FBuffer, sizeof(FBuffer) - FZRec.avail_out);
|
||||
finally
|
||||
deflateEnd(FZRec);
|
||||
end;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TCompressionStream.Read(var Buffer; Count: Longint): Longint;
|
||||
begin
|
||||
raise ECompressionError.Create('Invalid stream operation');
|
||||
end;
|
||||
|
||||
function TCompressionStream.Write(const Buffer; Count: Longint): Longint;
|
||||
begin
|
||||
FZRec.next_in := @Buffer;
|
||||
FZRec.avail_in := Count;
|
||||
if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
|
||||
while (FZRec.avail_in > 0) do
|
||||
begin
|
||||
CCheck(deflate(FZRec, 0));
|
||||
if FZRec.avail_out = 0 then
|
||||
begin
|
||||
FStrm.WriteBuffer(FBuffer, sizeof(FBuffer));
|
||||
FZRec.next_out := @FBuffer;
|
||||
FZRec.avail_out := sizeof(FBuffer);
|
||||
FStrmPos := FStrm.Position;
|
||||
Progress(Self);
|
||||
end;
|
||||
end;
|
||||
Result := Count;
|
||||
end;
|
||||
|
||||
function TCompressionStream.Seek(Offset: Longint; Origin: Word): Longint;
|
||||
begin
|
||||
if (Offset = 0) and (Origin = soFromCurrent) then
|
||||
Result := FZRec.total_in
|
||||
else
|
||||
raise ECompressionError.Create('Invalid stream operation');
|
||||
end;
|
||||
|
||||
function TCompressionStream.GetCompressionRate: Single;
|
||||
begin
|
||||
if FZRec.total_in = 0 then
|
||||
Result := 0
|
||||
else
|
||||
Result := (1.0 - (FZRec.total_out / FZRec.total_in)) * 100.0;
|
||||
end;
|
||||
|
||||
|
||||
{ TDecompressionStream }
|
||||
|
||||
constructor TDecompressionStream.Create(Source: TStream);
|
||||
begin
|
||||
inherited Create(Source);
|
||||
FZRec.next_in := @FBuffer;
|
||||
FZRec.avail_in := 0;
|
||||
DCheck(inflateInit_(@FZRec, zlib_version, sizeof(FZRec)));
|
||||
end;
|
||||
|
||||
destructor TDecompressionStream.Destroy;
|
||||
begin
|
||||
inflateEnd(FZRec);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TDecompressionStream.Read(var Buffer; Count: Longint): Longint;
|
||||
begin
|
||||
FZRec.next_out := @Buffer;
|
||||
FZRec.avail_out := Count;
|
||||
if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
|
||||
while (FZRec.avail_out > 0) do
|
||||
begin
|
||||
if FZRec.avail_in = 0 then
|
||||
begin
|
||||
FZRec.avail_in := FStrm.Read(FBuffer, sizeof(FBuffer));
|
||||
if FZRec.avail_in = 0 then
|
||||
begin
|
||||
Result := Count - FZRec.avail_out;
|
||||
Exit;
|
||||
end;
|
||||
FZRec.next_in := @FBuffer;
|
||||
FStrmPos := FStrm.Position;
|
||||
Progress(Self);
|
||||
end;
|
||||
CCheck(inflate(FZRec, 0));
|
||||
end;
|
||||
Result := Count;
|
||||
end;
|
||||
|
||||
function TDecompressionStream.Write(const Buffer; Count: Longint): Longint;
|
||||
begin
|
||||
raise EDecompressionError.Create('Invalid stream operation');
|
||||
end;
|
||||
|
||||
function TDecompressionStream.Seek(Offset: Longint; Origin: Word): Longint;
|
||||
var
|
||||
I: Integer;
|
||||
Buf: array [0..4095] of Char;
|
||||
begin
|
||||
if (Offset = 0) and (Origin = soFromBeginning) then
|
||||
begin
|
||||
DCheck(inflateReset(FZRec));
|
||||
FZRec.next_in := @FBuffer;
|
||||
FZRec.avail_in := 0;
|
||||
FStrm.Position := 0;
|
||||
FStrmPos := 0;
|
||||
end
|
||||
else if ( (Offset >= 0) and (Origin = soFromCurrent)) or
|
||||
( ((Offset - FZRec.total_out) > 0) and (Origin = soFromBeginning)) then
|
||||
begin
|
||||
if Origin = soFromBeginning then Dec(Offset, FZRec.total_out);
|
||||
if Offset > 0 then
|
||||
begin
|
||||
for I := 1 to Offset div sizeof(Buf) do
|
||||
ReadBuffer(Buf, sizeof(Buf));
|
||||
ReadBuffer(Buf, Offset mod sizeof(Buf));
|
||||
end;
|
||||
end
|
||||
else
|
||||
raise EDecompressionError.Create('Invalid stream operation');
|
||||
Result := FZRec.total_out;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
end.
|
||||
102
contrib/fundamentals/ZLib/paszlib/dzlib.txt
Normal file
102
contrib/fundamentals/ZLib/paszlib/dzlib.txt
Normal file
@@ -0,0 +1,102 @@
|
||||
The Delphi 3 CD-ROM contains in \INFO\EXTRAS\ZLIB a zlib unit that implements
|
||||
the TCompressionStream and TDecompressionStream classes. With some changes to
|
||||
this unit you can implement the same functionality using Paszlib. I can not
|
||||
publish the modified file (Copyright 1997 by Borland International), but this
|
||||
document tells you how to make the changes by hand.
|
||||
|
||||
|
||||
1. zlib.pas conflicts to a Paszlib unit name, change the name to dzlib.pas.
|
||||
< unit dzlib;
|
||||
---
|
||||
> unit zlib;
|
||||
|
||||
2. Add zlib to the uses clause:
|
||||
< uses zlib, Sysutils, Classes;
|
||||
---
|
||||
> uses Sysutils, Classes;
|
||||
|
||||
3. Change the type declarations for TAlloc, TFree and TZStreamRec to
|
||||
< TAlloc = alloc_func;
|
||||
< TFree = free_func;
|
||||
< TZStreamRec = z_stream;
|
||||
|
||||
4. Remove the zlib_Version const.
|
||||
> const
|
||||
> zlib_Version = '1.0.4';
|
||||
|
||||
5. In the implementation part, add the following uses clause
|
||||
< uses
|
||||
< zutil, zDeflate, zInflate;
|
||||
|
||||
6. remove all Z_xxx const, {$L xxx} and all external procedures up to
|
||||
(and including) the inflateReset() function and the _memset and _memcpy
|
||||
procedure definitions.
|
||||
|
||||
7. for compatibility with D1 you should change the type of the "Size"
|
||||
parameter of the zlibAllocMem() function from Integer to Cardinal
|
||||
and all comments of the // form into the {} form.
|
||||
|
||||
8. Now, make the following changes, so that the dzlib can compile, you
|
||||
can then use the modified unit dzlib in the test.pas source.
|
||||
185c293
|
||||
< CCheck(deflateInit_(@strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm)));
|
||||
---
|
||||
> CCheck(deflateInit_(strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm)));
|
||||
192c300
|
||||
< strm.next_out := pBytef(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
|
||||
---
|
||||
> strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
|
||||
228c336
|
||||
< DCheck(inflateInit_(@strm, zlib_version, sizeof(strm)));
|
||||
---
|
||||
> DCheck(inflateInit_(strm, zlib_version, sizeof(strm)));
|
||||
235c343
|
||||
< strm.next_out := pBytef(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
|
||||
---
|
||||
> strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
|
||||
250c358
|
||||
276c384
|
||||
< FZRec.next_out := @FBuffer;
|
||||
---
|
||||
> FZRec.next_out := FBuffer;
|
||||
278c386
|
||||
< CCheck(deflateInit_(@FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec)));
|
||||
---
|
||||
> CCheck(deflateInit_(FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec)));
|
||||
291c399
|
||||
< FZRec.next_out := @FBuffer;
|
||||
---
|
||||
> FZRec.next_out := FBuffer;
|
||||
318c426
|
||||
< FZRec.next_out := @FBuffer;
|
||||
---
|
||||
> FZRec.next_out := FBuffer;
|
||||
344c452
|
||||
< FZRec.next_in := @FBuffer;
|
||||
---
|
||||
> FZRec.next_in := FBuffer;
|
||||
351c459
|
||||
< DCheck(inflateInit_(@FZRec, zlib_version, sizeof(FZRec)));
|
||||
---
|
||||
> DCheck(inflateInit_(FZRec, zlib_version, sizeof(FZRec)));
|
||||
375c483
|
||||
< FZRec.next_in := @FBuffer;
|
||||
---
|
||||
> FZRec.next_in := FBuffer;
|
||||
397c505
|
||||
< FZRec.next_in := @FBuffer;
|
||||
---
|
||||
> FZRec.next_in := FBuffer;
|
||||
|
||||
9. This is a bug fix:
|
||||
in CompressBuf() change
|
||||
< while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do
|
||||
to
|
||||
> while deflate(strm, Z_FINISH) <> Z_STREAM_END do
|
||||
|
||||
in DeCompressBuf() change
|
||||
< while CCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END do
|
||||
to
|
||||
> while inflate(strm, Z_FINISH) <> Z_STREAM_END do
|
||||
|
||||
Jacques Nomssi Nzali <nomssi@physik.tu-chemnitz.de> [25.3.2000]
|
||||
704
contrib/fundamentals/ZLib/paszlib/example.pas
Normal file
704
contrib/fundamentals/ZLib/paszlib/example.pas
Normal file
@@ -0,0 +1,704 @@
|
||||
program example;
|
||||
|
||||
{ example.c -- usage example of the zlib compression library
|
||||
Copyright (C) 1995-1998 Jean-loup Gailly.
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
}
|
||||
{-$define MemCheck}
|
||||
{$DEFINE TEST_COMPRESS}
|
||||
{$DEFINE TEST_GZIO}
|
||||
{$DEFINE TEST_INFLATE}
|
||||
{$DEFINE TEST_DEFLATE}
|
||||
{$DEFINE TEST_SYNC}
|
||||
{$DEFINE TEST_DICT}
|
||||
{$DEFINE TEST_FLUSH}
|
||||
|
||||
uses
|
||||
{$ifdef ver80}
|
||||
WinCrt,
|
||||
{$endif}
|
||||
{$ifdef you may have to define this in Delphi < 5}
|
||||
strings,
|
||||
{$endif}
|
||||
{$ifndef MSDOS}
|
||||
SysUtils,
|
||||
{$endif}
|
||||
zutil,
|
||||
gzLib,
|
||||
gzIo,
|
||||
zInflate,
|
||||
zDeflate,
|
||||
zCompres,
|
||||
zUnCompr
|
||||
{$ifdef MemCheck}
|
||||
, MemCheck in '..\..\monotekt\pas\memcheck\memcheck.pas'
|
||||
{$endif}
|
||||
;
|
||||
|
||||
procedure Stop;
|
||||
begin
|
||||
Write('Program halted...');
|
||||
ReadLn;
|
||||
Halt(1);
|
||||
end;
|
||||
|
||||
procedure CHECK_ERR(err : int; msg : string);
|
||||
begin
|
||||
if (err <> Z_OK) then
|
||||
begin
|
||||
Write(msg, ' error: ', err);
|
||||
Stop;
|
||||
end;
|
||||
end;
|
||||
|
||||
const
|
||||
hello : PChar = 'hello, hello!';
|
||||
{ "hello world" would be more standard, but the repeated "hello"
|
||||
stresses the compression code better, sorry... }
|
||||
|
||||
{$IFDEF TEST_DICT}
|
||||
const
|
||||
dictionary : PChar = 'hello';
|
||||
var
|
||||
dictId : uLong; { Adler32 value of the dictionary }
|
||||
{$ENDIF}
|
||||
|
||||
{ ===========================================================================
|
||||
Test compress() and uncompress() }
|
||||
|
||||
{$IFDEF TEST_COMPRESS}
|
||||
procedure test_compress(compr : pBytef; var comprLen : uLong;
|
||||
uncompr : pBytef; uncomprLen : uLong);
|
||||
var
|
||||
err : int;
|
||||
len : uLong;
|
||||
begin
|
||||
len := strlen(hello)+1;
|
||||
err := compress(compr, comprLen, pBytef(hello)^, len);
|
||||
CHECK_ERR(err, 'compress');
|
||||
|
||||
strcopy(PChar(uncompr), 'garbage');
|
||||
|
||||
err := uncompress(uncompr, uncomprLen, compr^, comprLen);
|
||||
CHECK_ERR(err, 'uncompress');
|
||||
|
||||
if (strcomp(PChar(uncompr), hello)) <> 0 then
|
||||
begin
|
||||
WriteLn('bad uncompress');
|
||||
Stop;
|
||||
end
|
||||
else
|
||||
WriteLn('uncompress(): ', StrPas(PChar(uncompr)));
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ ===========================================================================
|
||||
Test read/write of .gz files }
|
||||
|
||||
{$IFDEF TEST_GZIO}
|
||||
procedure test_gzio(const outf : string; { output file }
|
||||
const inf : string; { input file }
|
||||
uncompr : pBytef;
|
||||
uncomprLen : int);
|
||||
var
|
||||
err : int;
|
||||
len : int;
|
||||
var
|
||||
zfile : gzFile;
|
||||
pos : z_off_t;
|
||||
begin
|
||||
len := strlen(hello)+1;
|
||||
|
||||
zfile := gzopen(outf, 'w');
|
||||
if (zfile = NIL) then
|
||||
begin
|
||||
WriteLn('_gzopen error');
|
||||
Stop;
|
||||
end;
|
||||
gzputc(zfile, 'h');
|
||||
if (gzputs(zfile, 'ello') <> 4) then
|
||||
begin
|
||||
WriteLn('gzputs err: ', gzerror(zfile, err));
|
||||
Stop;
|
||||
end;
|
||||
{$ifdef GZ_FORMAT_STRING}
|
||||
if (gzprintf(zfile, ', %s!', 'hello') <> 8) then
|
||||
begin
|
||||
WriteLn('gzprintf err: ', gzerror(zfile, err));
|
||||
Stop;
|
||||
end;
|
||||
{$else}
|
||||
if (gzputs(zfile, ', hello!') <> 8) then
|
||||
begin
|
||||
WriteLn('gzputs err: ', gzerror(zfile, err));
|
||||
Stop;
|
||||
end;
|
||||
{$ENDIF}
|
||||
gzseek(zfile, Long(1), SEEK_CUR); { add one zero byte }
|
||||
gzclose(zfile);
|
||||
|
||||
zfile := gzopen(inf, 'r');
|
||||
if (zfile = NIL) then
|
||||
WriteLn('gzopen error');
|
||||
|
||||
strcopy(pchar(uncompr), 'garbage');
|
||||
|
||||
uncomprLen := gzread(zfile, uncompr, uInt(uncomprLen));
|
||||
if (uncomprLen <> len) then
|
||||
begin
|
||||
WriteLn('gzread err: ', gzerror(zfile, err));
|
||||
Stop;
|
||||
end;
|
||||
if (strcomp(pchar(uncompr), hello)) <> 0 then
|
||||
begin
|
||||
WriteLn('bad gzread: ', pchar(uncompr));
|
||||
Stop;
|
||||
end
|
||||
else
|
||||
WriteLn('gzread(): ', pchar(uncompr));
|
||||
|
||||
pos := gzseek(zfile, Long(-8), SEEK_CUR);
|
||||
if (pos <> 6) or (gztell(zfile) <> pos) then
|
||||
begin
|
||||
WriteLn('gzseek error, pos=',pos,', gztell=',gztell(zfile));
|
||||
Stop;
|
||||
end;
|
||||
|
||||
if (char(gzgetc(zfile)) <> ' ') then
|
||||
begin
|
||||
WriteLn('gzgetc error');
|
||||
Stop;
|
||||
end;
|
||||
|
||||
gzgets(zfile, pchar(uncompr), uncomprLen);
|
||||
uncomprLen := strlen(pchar(uncompr));
|
||||
if (uncomprLen <> 6) then
|
||||
begin { "hello!" }
|
||||
WriteLn('gzgets err after gzseek: ', gzerror(zfile, err));
|
||||
Stop;
|
||||
end;
|
||||
if (strcomp(pchar(uncompr), hello+7)) <> 0 then
|
||||
begin
|
||||
WriteLn('bad gzgets after gzseek');
|
||||
Stop;
|
||||
end
|
||||
else
|
||||
WriteLn('gzgets() after gzseek: ', PChar(uncompr));
|
||||
|
||||
gzclose(zfile);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ ===========================================================================
|
||||
Test deflate() with small buffers }
|
||||
|
||||
{$IFDEF TEST_DEFLATE}
|
||||
procedure test_deflate(compr : pBytef; comprLen : uLong);
|
||||
var
|
||||
c_stream : z_stream; { compression stream }
|
||||
err : int;
|
||||
len : int;
|
||||
begin
|
||||
len := strlen(hello)+1;
|
||||
c_stream.zalloc := NIL; {alloc_func(0);}
|
||||
c_stream.zfree := NIL; {free_func(0);}
|
||||
c_stream.opaque := NIL; {voidpf(0);}
|
||||
|
||||
err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION);
|
||||
CHECK_ERR(err, 'deflateInit');
|
||||
|
||||
c_stream.next_in := pBytef(hello);
|
||||
c_stream.next_out := compr;
|
||||
|
||||
while (c_stream.total_in <> uLong(len)) and (c_stream.total_out < comprLen) do
|
||||
begin
|
||||
c_stream.avail_out := 1; { force small buffers }
|
||||
c_stream.avail_in := 1;
|
||||
err := deflate(c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, 'deflate');
|
||||
end;
|
||||
|
||||
{ Finish the stream, still forcing small buffers: }
|
||||
while TRUE do
|
||||
begin
|
||||
c_stream.avail_out := 1;
|
||||
err := deflate(c_stream, Z_FINISH);
|
||||
if (err = Z_STREAM_END) then
|
||||
break;
|
||||
CHECK_ERR(err, 'deflate');
|
||||
end;
|
||||
|
||||
err := deflateEnd(c_stream);
|
||||
CHECK_ERR(err, 'deflateEnd');
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ ===========================================================================
|
||||
Test inflate() with small buffers
|
||||
}
|
||||
|
||||
{$IFDEF TEST_INFLATE}
|
||||
procedure test_inflate(compr : pBytef; comprLen : uLong;
|
||||
uncompr : pBytef; uncomprLen : uLong);
|
||||
var
|
||||
err : int;
|
||||
d_stream : z_stream; { decompression stream }
|
||||
begin
|
||||
strcopy(PChar(uncompr), 'garbage');
|
||||
|
||||
d_stream.zalloc := NIL; {alloc_func(0);}
|
||||
d_stream.zfree := NIL; {free_func(0);}
|
||||
d_stream.opaque := NIL; {voidpf(0);}
|
||||
|
||||
d_stream.next_in := compr;
|
||||
d_stream.avail_in := 0;
|
||||
d_stream.next_out := uncompr;
|
||||
|
||||
err := inflateInit(d_stream);
|
||||
CHECK_ERR(err, 'inflateInit');
|
||||
|
||||
while (d_stream.total_out < uncomprLen) and
|
||||
(d_stream.total_in < comprLen) do
|
||||
begin
|
||||
d_stream.avail_out := 1; { force small buffers }
|
||||
d_stream.avail_in := 1;
|
||||
err := inflate(d_stream, Z_NO_FLUSH);
|
||||
if (err = Z_STREAM_END) then
|
||||
break;
|
||||
CHECK_ERR(err, 'inflate');
|
||||
end;
|
||||
|
||||
err := inflateEnd(d_stream);
|
||||
CHECK_ERR(err, 'inflateEnd');
|
||||
|
||||
if (strcomp(PChar(uncompr), hello) <> 0) then
|
||||
begin
|
||||
WriteLn('bad inflate');
|
||||
exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
WriteLn('inflate(): ', StrPas(PChar(uncompr)));
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ ===========================================================================
|
||||
Test deflate() with large buffers and dynamic change of compression level
|
||||
}
|
||||
|
||||
{$IFDEF TEST_DEFLATE}
|
||||
procedure test_large_deflate(compr : pBytef; comprLen : uLong;
|
||||
uncompr : pBytef; uncomprLen : uLong);
|
||||
var
|
||||
c_stream : z_stream; { compression stream }
|
||||
err : int;
|
||||
begin
|
||||
c_stream.zalloc := NIL; {alloc_func(0);}
|
||||
c_stream.zfree := NIL; {free_func(0);}
|
||||
c_stream.opaque := NIL; {voidpf(0);}
|
||||
|
||||
err := deflateInit(c_stream, Z_BEST_SPEED);
|
||||
CHECK_ERR(err, 'deflateInit');
|
||||
|
||||
c_stream.next_out := compr;
|
||||
c_stream.avail_out := uInt(comprLen);
|
||||
|
||||
{ At this point, uncompr is still mostly zeroes, so it should compress
|
||||
very well: }
|
||||
|
||||
c_stream.next_in := uncompr;
|
||||
c_stream.avail_in := uInt(uncomprLen);
|
||||
err := deflate(c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, 'deflate');
|
||||
if (c_stream.avail_in <> 0) then
|
||||
begin
|
||||
WriteLn('deflate not greedy');
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ Feed in already compressed data and switch to no compression: }
|
||||
deflateParams(c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
|
||||
c_stream.next_in := compr;
|
||||
c_stream.avail_in := uInt(comprLen div 2);
|
||||
err := deflate(c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, 'deflate');
|
||||
|
||||
{ Switch back to compressing mode: }
|
||||
deflateParams(c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
|
||||
c_stream.next_in := uncompr;
|
||||
c_stream.avail_in := uInt(uncomprLen);
|
||||
err := deflate(c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, 'deflate');
|
||||
|
||||
err := deflate(c_stream, Z_FINISH);
|
||||
if (err <> Z_STREAM_END) then
|
||||
begin
|
||||
WriteLn('deflate should report Z_STREAM_END');
|
||||
exit;
|
||||
end;
|
||||
err := deflateEnd(c_stream);
|
||||
CHECK_ERR(err, 'deflateEnd');
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ ===========================================================================
|
||||
Test inflate() with large buffers }
|
||||
|
||||
{$IFDEF TEST_INFLATE}
|
||||
procedure test_large_inflate(compr : pBytef; comprLen : uLong;
|
||||
uncompr : pBytef; uncomprLen : uLong);
|
||||
var
|
||||
err : int;
|
||||
d_stream : z_stream; { decompression stream }
|
||||
begin
|
||||
strcopy(PChar(uncompr), 'garbage');
|
||||
|
||||
d_stream.zalloc := NIL; {alloc_func(0);}
|
||||
d_stream.zfree := NIL; {free_func(0);}
|
||||
d_stream.opaque := NIL; {voidpf(0);}
|
||||
|
||||
d_stream.next_in := compr;
|
||||
d_stream.avail_in := uInt(comprLen);
|
||||
|
||||
err := inflateInit(d_stream);
|
||||
CHECK_ERR(err, 'inflateInit');
|
||||
|
||||
while TRUE do
|
||||
begin
|
||||
d_stream.next_out := uncompr; { discard the output }
|
||||
d_stream.avail_out := uInt(uncomprLen);
|
||||
err := inflate(d_stream, Z_NO_FLUSH);
|
||||
if (err = Z_STREAM_END) then
|
||||
break;
|
||||
CHECK_ERR(err, 'large inflate');
|
||||
end;
|
||||
|
||||
err := inflateEnd(d_stream);
|
||||
CHECK_ERR(err, 'inflateEnd');
|
||||
|
||||
if (d_stream.total_out <> 2*uncomprLen + comprLen div 2) then
|
||||
begin
|
||||
WriteLn('bad large inflate: ', d_stream.total_out);
|
||||
Stop;
|
||||
end
|
||||
else
|
||||
WriteLn('large_inflate(): OK');
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ ===========================================================================
|
||||
Test deflate() with full flush
|
||||
}
|
||||
{$IFDEF TEST_FLUSH}
|
||||
procedure test_flush(compr : pBytef; var comprLen : uLong);
|
||||
var
|
||||
c_stream : z_stream; { compression stream }
|
||||
err : int;
|
||||
len : int;
|
||||
|
||||
begin
|
||||
len := strlen(hello)+1;
|
||||
c_stream.zalloc := NIL; {alloc_func(0);}
|
||||
c_stream.zfree := NIL; {free_func(0);}
|
||||
c_stream.opaque := NIL; {voidpf(0);}
|
||||
|
||||
err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION);
|
||||
CHECK_ERR(err, 'deflateInit');
|
||||
|
||||
c_stream.next_in := pBytef(hello);
|
||||
c_stream.next_out := compr;
|
||||
c_stream.avail_in := 3;
|
||||
c_stream.avail_out := uInt(comprLen);
|
||||
|
||||
err := deflate(c_stream, Z_FULL_FLUSH);
|
||||
CHECK_ERR(err, 'deflate');
|
||||
|
||||
Inc(pzByteArray(compr)^[3]); { force an error in first compressed block }
|
||||
c_stream.avail_in := len - 3;
|
||||
|
||||
err := deflate(c_stream, Z_FINISH);
|
||||
if (err <> Z_STREAM_END) then
|
||||
CHECK_ERR(err, 'deflate');
|
||||
|
||||
err := deflateEnd(c_stream);
|
||||
CHECK_ERR(err, 'deflateEnd');
|
||||
|
||||
comprLen := c_stream.total_out;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ ===========================================================================
|
||||
Test inflateSync()
|
||||
}
|
||||
{$IFDEF TEST_SYNC}
|
||||
procedure test_sync(compr : pBytef; comprLen : uLong;
|
||||
uncompr : pBytef; uncomprLen : uLong);
|
||||
var
|
||||
err : int;
|
||||
d_stream : z_stream; { decompression stream }
|
||||
begin
|
||||
strcopy(PChar(uncompr), 'garbage');
|
||||
|
||||
d_stream.zalloc := NIL; {alloc_func(0);}
|
||||
d_stream.zfree := NIL; {free_func(0);}
|
||||
d_stream.opaque := NIL; {voidpf(0);}
|
||||
|
||||
d_stream.next_in := compr;
|
||||
d_stream.avail_in := 2; { just read the zlib header }
|
||||
|
||||
err := inflateInit(d_stream);
|
||||
CHECK_ERR(err, 'inflateInit');
|
||||
|
||||
d_stream.next_out := uncompr;
|
||||
d_stream.avail_out := uInt(uncomprLen);
|
||||
|
||||
inflate(d_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, 'inflate');
|
||||
|
||||
d_stream.avail_in := uInt(comprLen-2); { read all compressed data }
|
||||
err := inflateSync(d_stream); { but skip the damaged part }
|
||||
CHECK_ERR(err, 'inflateSync');
|
||||
|
||||
err := inflate(d_stream, Z_FINISH);
|
||||
if (err <> Z_DATA_ERROR) then
|
||||
begin
|
||||
WriteLn('inflate should report DATA_ERROR');
|
||||
{ Because of incorrect adler32 }
|
||||
Stop;
|
||||
end;
|
||||
err := inflateEnd(d_stream);
|
||||
CHECK_ERR(err, 'inflateEnd');
|
||||
|
||||
WriteLn('after inflateSync(): hel', StrPas(PChar(uncompr)));
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ ===========================================================================
|
||||
Test deflate() with preset dictionary
|
||||
}
|
||||
{$IFDEF TEST_DICT}
|
||||
procedure test_dict_deflate(compr : pBytef; comprLen : uLong);
|
||||
var
|
||||
c_stream : z_stream; { compression stream }
|
||||
err : int;
|
||||
begin
|
||||
c_stream.zalloc := NIL; {(alloc_func)0;}
|
||||
c_stream.zfree := NIL; {(free_func)0;}
|
||||
c_stream.opaque := NIL; {(voidpf)0;}
|
||||
|
||||
err := deflateInit(c_stream, Z_BEST_COMPRESSION);
|
||||
CHECK_ERR(err, 'deflateInit');
|
||||
|
||||
err := deflateSetDictionary(c_stream,
|
||||
pBytef(dictionary), StrLen(dictionary));
|
||||
CHECK_ERR(err, 'deflateSetDictionary');
|
||||
|
||||
dictId := c_stream.adler;
|
||||
c_stream.next_out := compr;
|
||||
c_stream.avail_out := uInt(comprLen);
|
||||
|
||||
c_stream.next_in := pBytef(hello);
|
||||
c_stream.avail_in := uInt(strlen(hello)+1);
|
||||
|
||||
err := deflate(c_stream, Z_FINISH);
|
||||
if (err <> Z_STREAM_END) then
|
||||
begin
|
||||
WriteLn('deflate should report Z_STREAM_END');
|
||||
exit;
|
||||
end;
|
||||
err := deflateEnd(c_stream);
|
||||
CHECK_ERR(err, 'deflateEnd');
|
||||
end;
|
||||
|
||||
{ ===========================================================================
|
||||
Test inflate() with a preset dictionary }
|
||||
|
||||
procedure test_dict_inflate(compr : pBytef; comprLen : uLong;
|
||||
uncompr : pBytef; uncomprLen : uLong);
|
||||
var
|
||||
err : int;
|
||||
d_stream : z_stream; { decompression stream }
|
||||
begin
|
||||
strcopy(PChar(uncompr), 'garbage');
|
||||
|
||||
d_stream.zalloc := NIL; { alloc_func(0); }
|
||||
d_stream.zfree := NIL; { free_func(0); }
|
||||
d_stream.opaque := NIL; { voidpf(0); }
|
||||
|
||||
d_stream.next_in := compr;
|
||||
d_stream.avail_in := uInt(comprLen);
|
||||
|
||||
err := inflateInit(d_stream);
|
||||
CHECK_ERR(err, 'inflateInit');
|
||||
|
||||
d_stream.next_out := uncompr;
|
||||
d_stream.avail_out := uInt(uncomprLen);
|
||||
|
||||
while TRUE do
|
||||
begin
|
||||
err := inflate(d_stream, Z_NO_FLUSH);
|
||||
if (err = Z_STREAM_END) then
|
||||
break;
|
||||
if (err = Z_NEED_DICT) then
|
||||
begin
|
||||
if (d_stream.adler <> dictId) then
|
||||
begin
|
||||
WriteLn('unexpected dictionary');
|
||||
Stop;
|
||||
end;
|
||||
err := inflateSetDictionary(d_stream, pBytef(dictionary),
|
||||
StrLen(dictionary));
|
||||
end;
|
||||
CHECK_ERR(err, 'inflate with dict');
|
||||
end;
|
||||
|
||||
err := inflateEnd(d_stream);
|
||||
CHECK_ERR(err, 'inflateEnd');
|
||||
|
||||
if (strcomp(PChar(uncompr), hello)) <> 0 then
|
||||
begin
|
||||
WriteLn('bad inflate with dict');
|
||||
Stop;
|
||||
end
|
||||
else
|
||||
begin
|
||||
WriteLn('inflate with dictionary: ', StrPas(PChar(uncompr)));
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function GetFromFile(buf : pBytef; FName : string;
|
||||
var MaxLen : uInt) : boolean;
|
||||
const
|
||||
zOfs = 0;
|
||||
var
|
||||
f : file;
|
||||
Len : uLong;
|
||||
begin
|
||||
assign(f, FName);
|
||||
GetFromFile := false;
|
||||
{$I-}
|
||||
filemode := 0; { read only }
|
||||
reset(f, 1);
|
||||
if IOresult = 0 then
|
||||
begin
|
||||
Len := FileSize(f)-zOfs;
|
||||
Seek(f, zOfs);
|
||||
if Len < MaxLen then
|
||||
MaxLen := Len;
|
||||
BlockRead(f, buf^, MaxLen);
|
||||
close(f);
|
||||
WriteLn(FName);
|
||||
GetFromFile := (IOresult = 0) and (MaxLen > 0);
|
||||
end
|
||||
else
|
||||
WriteLn('Could not open ', FName);
|
||||
end;
|
||||
|
||||
{ ===========================================================================
|
||||
Usage: example [output.gz [input.gz]]
|
||||
}
|
||||
|
||||
var
|
||||
compr, uncompr : pBytef;
|
||||
const
|
||||
msdoslen = 25000;
|
||||
comprLenL : uLong = msdoslen div sizeof(uInt); { don't overflow on MSDOS }
|
||||
uncomprLenL : uLong = msdoslen div sizeof(uInt);
|
||||
var
|
||||
zVersion,
|
||||
myVersion : string;
|
||||
var
|
||||
comprLen : uInt;
|
||||
uncomprLen : uInt;
|
||||
begin
|
||||
{$ifdef MemCheck}
|
||||
MemChk;
|
||||
{$endif}
|
||||
comprLen := comprLenL;
|
||||
uncomprLen := uncomprLenL;
|
||||
|
||||
myVersion := ZLIB_VERSION;
|
||||
zVersion := zlibVersion;
|
||||
if (zVersion[1] <> myVersion[1]) then
|
||||
begin
|
||||
WriteLn('incompatible zlib version');
|
||||
Stop;
|
||||
end
|
||||
else
|
||||
if (zVersion <> ZLIB_VERSION) then
|
||||
begin
|
||||
WriteLn('warning: different zlib version');
|
||||
end;
|
||||
|
||||
GetMem(compr, comprLen*sizeof(uInt));
|
||||
GetMem(uncompr, uncomprLen*sizeof(uInt));
|
||||
{ compr and uncompr are cleared to avoid reading uninitialized
|
||||
data and to ensure that uncompr compresses well. }
|
||||
|
||||
if (compr = Z_NULL) or (uncompr = Z_NULL) then
|
||||
begin
|
||||
WriteLn('out of memory');
|
||||
Stop;
|
||||
end;
|
||||
FillChar(compr^, comprLen*sizeof(uInt), 0);
|
||||
FillChar(uncompr^, uncomprLen*sizeof(uInt), 0);
|
||||
|
||||
if (compr = Z_NULL) or (uncompr = Z_NULL) then
|
||||
begin
|
||||
WriteLn('out of memory');
|
||||
Stop;
|
||||
end;
|
||||
{$IFDEF TEST_COMPRESS}
|
||||
test_compress(compr, comprLenL, uncompr, uncomprLen);
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF TEST_GZIO}
|
||||
Case ParamCount of
|
||||
0: test_gzio('foo.gz', 'foo.gz', uncompr, int(uncomprLen));
|
||||
1: test_gzio(ParamStr(1), 'foo.gz', uncompr, int(uncomprLen));
|
||||
else
|
||||
test_gzio(ParamStr(1), ParamStr(2), uncompr, int(uncomprLen));
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF TEST_DEFLATE}
|
||||
WriteLn('small buffer Deflate');
|
||||
test_deflate(compr, comprLen);
|
||||
{$ENDIF}
|
||||
{$IFDEF TEST_INFLATE}
|
||||
{$IFNDEF TEST_DEFLATE}
|
||||
WriteLn('small buffer Inflate');
|
||||
if GetFromFile(compr, 'u:\nomssi\paszlib\new\test0.z', comprLen) then
|
||||
{$ENDIF}
|
||||
test_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
{$ENDIF}
|
||||
readln;
|
||||
{$IFDEF TEST_DEFLATE}
|
||||
WriteLn('large buffer Deflate');
|
||||
test_large_deflate(compr, comprLen, uncompr, uncomprLen);
|
||||
{$ENDIF}
|
||||
{$IFDEF TEST_INFLATE}
|
||||
WriteLn('large buffer Inflate');
|
||||
test_large_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
{$ENDIF}
|
||||
{$IFDEF TEST_FLUSH}
|
||||
test_flush(compr, comprLenL);
|
||||
{$ENDIF}
|
||||
{$IFDEF TEST_SYNC}
|
||||
test_sync(compr, comprLen, uncompr, uncomprLen);
|
||||
{$ENDIF}
|
||||
comprLen := uncomprLen;
|
||||
|
||||
{$IFDEF TEST_DICT}
|
||||
test_dict_deflate(compr, comprLen);
|
||||
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
{$ENDIF}
|
||||
readln;
|
||||
FreeMem(compr, comprLen*sizeof(uInt));
|
||||
FreeMem(uncompr, uncomprLen*sizeof(uInt));
|
||||
end.
|
||||
526
contrib/fundamentals/ZLib/paszlib/gZlib.pas
Normal file
526
contrib/fundamentals/ZLib/paszlib/gZlib.pas
Normal file
@@ -0,0 +1,526 @@
|
||||
unit gZlib;
|
||||
{ Original:
|
||||
zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.1.0, Feb 24th, 1998
|
||||
|
||||
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
|
||||
|
||||
The data format used by the zlib library is described by RFCs (Request for
|
||||
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
|
||||
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
uses
|
||||
ZUtil;
|
||||
|
||||
{ zconf.h -- configuration of the zlib compression library }
|
||||
{ zutil.c -- target dependent utility functions for the compression library }
|
||||
|
||||
{ The 'zlib' compression library provides in-memory compression and
|
||||
decompression functions, including integrity checks of the uncompressed
|
||||
data. This version of the library supports only one compression method
|
||||
(deflation) but other algorithms will be added later and will have the same
|
||||
stream interface.
|
||||
|
||||
Compression can be done in a single step if the buffers are large
|
||||
enough (for example if an input file is mmap'ed), or can be done by
|
||||
repeated calls of the compression function. In the latter case, the
|
||||
application must provide more input and/or consume the output
|
||||
(providing more output space) before each call.
|
||||
|
||||
The library also supports reading and writing files in gzip (.gz) format
|
||||
with an interface similar to that of stdio.
|
||||
|
||||
The library does not install any signal handler. The decoder checks
|
||||
the consistency of the compressed data, so the library should never
|
||||
crash even in case of corrupted input. }
|
||||
|
||||
|
||||
|
||||
{ Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
than 64k bytes at a time (needed on systems with 16-bit int). }
|
||||
|
||||
{ Maximum value for memLevel in deflateInit2 }
|
||||
{$ifdef MAXSEG_64K}
|
||||
{$IFDEF VER70}
|
||||
const
|
||||
MAX_MEM_LEVEL = 7;
|
||||
DEF_MEM_LEVEL = MAX_MEM_LEVEL; { default memLevel }
|
||||
{$ELSE}
|
||||
const
|
||||
MAX_MEM_LEVEL = 8;
|
||||
DEF_MEM_LEVEL = MAX_MEM_LEVEL; { default memLevel }
|
||||
{$ENDIF}
|
||||
{$else}
|
||||
const
|
||||
MAX_MEM_LEVEL = 9;
|
||||
DEF_MEM_LEVEL = 8; { if MAX_MEM_LEVEL > 8 }
|
||||
{$endif}
|
||||
|
||||
{ Maximum value for windowBits in deflateInit2 and inflateInit2 }
|
||||
const
|
||||
{$IFDEF VER70}
|
||||
MAX_WBITS = 14; { 32K LZ77 window }
|
||||
{$ELSE}
|
||||
MAX_WBITS = 15; { 32K LZ77 window }
|
||||
{$ENDIF}
|
||||
|
||||
{ default windowBits for decompression. MAX_WBITS is for compression only }
|
||||
const
|
||||
DEF_WBITS = MAX_WBITS;
|
||||
|
||||
{ The memory requirements for deflate are (in bytes):
|
||||
1 shl (windowBits+2) + 1 shl (memLevel+9)
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
DMAX_WBITS=14 DMAX_MEM_LEVEL=7
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 shl windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
for small objects. }
|
||||
|
||||
|
||||
{ Huffman code lookup table entry--this entry is four bytes for machines
|
||||
that have 16-bit pointers (e.g. PC's in the small or medium model). }
|
||||
|
||||
type
|
||||
pInflate_huft = ^inflate_huft;
|
||||
inflate_huft = Record
|
||||
Exop, { number of extra bits or operation }
|
||||
bits : Byte; { number of bits in this code or subcode }
|
||||
{pad : uInt;} { pad structure to a power of 2 (4 bytes for }
|
||||
{ 16-bit, 8 bytes for 32-bit int's) }
|
||||
base : uInt; { literal, length base, or distance base }
|
||||
{ or table offset }
|
||||
End;
|
||||
|
||||
type
|
||||
huft_field = Array[0..(MaxMemBlock div SizeOf(inflate_huft))-1] of inflate_huft;
|
||||
huft_ptr = ^huft_field;
|
||||
type
|
||||
ppInflate_huft = ^pInflate_huft;
|
||||
|
||||
type
|
||||
inflate_codes_mode = ( { waiting for "i:"=input, "o:"=output, "x:"=nothing }
|
||||
START, { x: set up for LEN }
|
||||
LEN, { i: get length/literal/eob next }
|
||||
LENEXT, { i: getting length extra (have base) }
|
||||
DIST, { i: get distance next }
|
||||
DISTEXT, { i: getting distance extra }
|
||||
COPY, { o: copying bytes in window, waiting for space }
|
||||
LIT, { o: got literal, waiting for output space }
|
||||
WASH, { o: got eob, possibly still output waiting }
|
||||
ZEND, { x: got eob and all data flushed }
|
||||
BADCODE); { x: got error }
|
||||
|
||||
{ inflate codes private state }
|
||||
type
|
||||
pInflate_codes_state = ^inflate_codes_state;
|
||||
inflate_codes_state = record
|
||||
|
||||
mode : inflate_codes_mode; { current inflate_codes mode }
|
||||
|
||||
{ mode dependent information }
|
||||
len : uInt;
|
||||
sub : record { submode }
|
||||
Case Byte of
|
||||
0:(code : record { if LEN or DIST, where in tree }
|
||||
tree : pInflate_huft; { pointer into tree }
|
||||
need : uInt; { bits needed }
|
||||
end);
|
||||
1:(lit : uInt); { if LIT, literal }
|
||||
2:(copy: record { if EXT or COPY, where and how much }
|
||||
get : uInt; { bits to get for extra }
|
||||
dist : uInt; { distance back to copy from }
|
||||
end);
|
||||
end;
|
||||
|
||||
{ mode independent information }
|
||||
lbits : Byte; { ltree bits decoded per branch }
|
||||
dbits : Byte; { dtree bits decoder per branch }
|
||||
ltree : pInflate_huft; { literal/length/eob tree }
|
||||
dtree : pInflate_huft; { distance tree }
|
||||
end;
|
||||
|
||||
type
|
||||
check_func = function(check : uLong;
|
||||
buf : pBytef;
|
||||
{const buf : array of byte;}
|
||||
len : uInt) : uLong;
|
||||
type
|
||||
inflate_block_mode =
|
||||
(ZTYPE, { get type bits (3, including end bit) }
|
||||
LENS, { get lengths for stored }
|
||||
STORED, { processing stored block }
|
||||
TABLE, { get table lengths }
|
||||
BTREE, { get bit lengths tree for a dynamic block }
|
||||
DTREE, { get length, distance trees for a dynamic block }
|
||||
CODES, { processing fixed or dynamic block }
|
||||
DRY, { output remaining window bytes }
|
||||
BLKDONE, { finished last block, done }
|
||||
BLKBAD); { got a data error--stuck here }
|
||||
|
||||
type
|
||||
pInflate_blocks_state = ^inflate_blocks_state;
|
||||
|
||||
{ inflate blocks semi-private state }
|
||||
inflate_blocks_state = record
|
||||
|
||||
mode : inflate_block_mode; { current inflate_block mode }
|
||||
|
||||
{ mode dependent information }
|
||||
sub : record { submode }
|
||||
case Byte of
|
||||
0:(left : uInt); { if STORED, bytes left to copy }
|
||||
1:(trees : record { if DTREE, decoding info for trees }
|
||||
table : uInt; { table lengths (14 bits) }
|
||||
index : uInt; { index into blens (or border) }
|
||||
blens : PuIntArray; { bit lengths of codes }
|
||||
bb : uInt; { bit length tree depth }
|
||||
tb : pInflate_huft; { bit length decoding tree }
|
||||
end);
|
||||
2:(decode : record { if CODES, current state }
|
||||
tl : pInflate_huft;
|
||||
td : pInflate_huft; { trees to free }
|
||||
codes : pInflate_codes_state;
|
||||
end);
|
||||
end;
|
||||
last : boolean; { true if this block is the last block }
|
||||
|
||||
{ mode independent information }
|
||||
bitk : uInt; { bits in bit buffer }
|
||||
bitb : uLong; { bit buffer }
|
||||
hufts : huft_ptr; {pInflate_huft;} { single malloc for tree space }
|
||||
window : pBytef; { sliding window }
|
||||
zend : pBytef; { one byte after sliding window }
|
||||
read : pBytef; { window read pointer }
|
||||
write : pBytef; { window write pointer }
|
||||
checkfn : check_func; { check function }
|
||||
check : uLong; { check on output }
|
||||
end;
|
||||
|
||||
type
|
||||
inflate_mode = (
|
||||
METHOD, { waiting for method byte }
|
||||
FLAG, { waiting for flag byte }
|
||||
DICT4, { four dictionary check bytes to go }
|
||||
DICT3, { three dictionary check bytes to go }
|
||||
DICT2, { two dictionary check bytes to go }
|
||||
DICT1, { one dictionary check byte to go }
|
||||
DICT0, { waiting for inflateSetDictionary }
|
||||
BLOCKS, { decompressing blocks }
|
||||
CHECK4, { four check bytes to go }
|
||||
CHECK3, { three check bytes to go }
|
||||
CHECK2, { two check bytes to go }
|
||||
CHECK1, { one check byte to go }
|
||||
DONE, { finished check, done }
|
||||
BAD); { got an error--stay here }
|
||||
|
||||
{ inflate private state }
|
||||
type
|
||||
pInternal_state = ^internal_state; { or point to a deflate_state record }
|
||||
internal_state = record
|
||||
|
||||
mode : inflate_mode; { current inflate mode }
|
||||
|
||||
{ mode dependent information }
|
||||
sub : record { submode }
|
||||
case byte of
|
||||
0:(method : uInt); { if FLAGS, method byte }
|
||||
1:(check : record { if CHECK, check values to compare }
|
||||
was : uLong; { computed check value }
|
||||
need : uLong; { stream check value }
|
||||
end);
|
||||
2:(marker : uInt); { if BAD, inflateSync's marker bytes count }
|
||||
end;
|
||||
|
||||
{ mode independent information }
|
||||
nowrap : boolean; { flag for no wrapper }
|
||||
wbits : uInt; { log2(window size) (8..15, defaults to 15) }
|
||||
blocks : pInflate_blocks_state; { current inflate_blocks state }
|
||||
end;
|
||||
|
||||
type
|
||||
alloc_func = function(opaque : voidpf; items : uInt; size : uInt) : voidpf;
|
||||
free_func = procedure(opaque : voidpf; address : voidpf);
|
||||
|
||||
type
|
||||
z_streamp = ^z_stream;
|
||||
z_stream = record
|
||||
next_in : pBytef; { next input byte }
|
||||
avail_in : uInt; { number of bytes available at next_in }
|
||||
total_in : uLong; { total nb of input bytes read so far }
|
||||
|
||||
next_out : pBytef; { next output byte should be put there }
|
||||
avail_out : uInt; { remaining free space at next_out }
|
||||
total_out : uLong; { total nb of bytes output so far }
|
||||
|
||||
msg : string; { last error message, '' if no error }
|
||||
state : pInternal_state; { not visible by applications }
|
||||
|
||||
zalloc : alloc_func; { used to allocate the internal state }
|
||||
zfree : free_func; { used to free the internal state }
|
||||
opaque : voidpf; { private data object passed to zalloc and zfree }
|
||||
|
||||
data_type : int; { best guess about the data type: ascii or binary }
|
||||
adler : uLong; { adler32 value of the uncompressed data }
|
||||
reserved : uLong; { reserved for future use }
|
||||
end;
|
||||
|
||||
|
||||
{ The application must update next_in and avail_in when avail_in has
|
||||
dropped to zero. It must update next_out and avail_out when avail_out
|
||||
has dropped to zero. The application must initialize zalloc, zfree and
|
||||
opaque before calling the init function. All other fields are set by the
|
||||
compression library and must not be updated by the application.
|
||||
|
||||
The opaque value provided by the application will be passed as the first
|
||||
parameter for calls of zalloc and zfree. This can be useful for custom
|
||||
memory management. The compression library attaches no meaning to the
|
||||
opaque value.
|
||||
|
||||
zalloc must return Z_NULL if there is not enough memory for the object.
|
||||
On 16-bit systems, the functions zalloc and zfree must be able to allocate
|
||||
exactly 65536 bytes, but will not be required to allocate more than this
|
||||
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
|
||||
pointers returned by zalloc for objects of exactly 65536 bytes *must*
|
||||
have their offset normalized to zero. The default allocation function
|
||||
provided by this library ensures this (see zutil.c). To reduce memory
|
||||
requirements and avoid any allocation of 64K objects, at the expense of
|
||||
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
|
||||
|
||||
The fields total_in and total_out can be used for statistics or
|
||||
progress reports. After compression, total_in holds the total size of
|
||||
the uncompressed data and may be saved for use in the decompressor
|
||||
(particularly if the decompressor wants to decompress everything in
|
||||
a single step). }
|
||||
|
||||
const { constants }
|
||||
Z_NO_FLUSH = 0;
|
||||
Z_PARTIAL_FLUSH = 1;
|
||||
Z_SYNC_FLUSH = 2;
|
||||
Z_FULL_FLUSH = 3;
|
||||
Z_FINISH = 4;
|
||||
{ Allowed flush values; see deflate() below for details }
|
||||
|
||||
Z_OK = 0;
|
||||
Z_STREAM_END = 1;
|
||||
Z_NEED_DICT = 2;
|
||||
Z_ERRNO = (-1);
|
||||
Z_STREAM_ERROR = (-2);
|
||||
Z_DATA_ERROR = (-3);
|
||||
Z_MEM_ERROR = (-4);
|
||||
Z_BUF_ERROR = (-5);
|
||||
Z_VERSION_ERROR = (-6);
|
||||
{ Return codes for the compression/decompression functions. Negative
|
||||
values are errors, positive values are used for special but normal events.}
|
||||
|
||||
Z_NO_COMPRESSION = 0;
|
||||
Z_BEST_SPEED = 1;
|
||||
Z_BEST_COMPRESSION = 9;
|
||||
Z_DEFAULT_COMPRESSION = (-1);
|
||||
{ compression levels }
|
||||
|
||||
Z_FILTERED = 1;
|
||||
Z_HUFFMAN_ONLY = 2;
|
||||
Z_DEFAULT_STRATEGY = 0;
|
||||
{ compression strategy; see deflateInit2() below for details }
|
||||
|
||||
Z_BINARY = 0;
|
||||
Z_ASCII = 1;
|
||||
Z_UNKNOWN = 2;
|
||||
{ Possible values of the data_type field }
|
||||
|
||||
Z_DEFLATED = 8;
|
||||
{ The deflate compression method (the only one supported in this version) }
|
||||
|
||||
Z_NULL = NIL; { for initializing zalloc, zfree, opaque }
|
||||
|
||||
{$IFDEF GZIO}
|
||||
var
|
||||
errno : int;
|
||||
{$ENDIF}
|
||||
|
||||
{ common constants }
|
||||
|
||||
|
||||
{ The three kinds of block type }
|
||||
const
|
||||
STORED_BLOCK = 0;
|
||||
STATIC_TREES = 1;
|
||||
DYN_TREES = 2;
|
||||
{ The minimum and maximum match lengths }
|
||||
const
|
||||
MIN_MATCH = 3;
|
||||
{$ifdef MAX_MATCH_IS_258}
|
||||
MAX_MATCH = 258;
|
||||
{$else}
|
||||
MAX_MATCH = ??; { deliberate syntax error }
|
||||
{$endif}
|
||||
|
||||
const
|
||||
PRESET_DICT = $20; { preset dictionary flag in zlib header }
|
||||
|
||||
|
||||
{$IFDEF DEBUG}
|
||||
// procedure Assert(cond : boolean; msg : string);
|
||||
{$ENDIF}
|
||||
|
||||
procedure Trace(x : string);
|
||||
procedure Tracev(x : string);
|
||||
procedure Tracevv(x : string);
|
||||
procedure Tracevvv(x : string);
|
||||
procedure Tracec(c : boolean; x : string);
|
||||
procedure Tracecv(c : boolean; x : string);
|
||||
|
||||
function zlibVersion : string;
|
||||
{ The application can compare zlibVersion and ZLIB_VERSION for consistency.
|
||||
If the first character differs, the library code actually used is
|
||||
not compatible with the zlib.h header file used by the application.
|
||||
This check is automatically made by deflateInit and inflateInit. }
|
||||
|
||||
function zError(err : int) : string;
|
||||
|
||||
function ZALLOC (var strm : z_stream; items : uInt; size : uInt) : voidpf;
|
||||
|
||||
procedure ZFREE (var strm : z_stream; ptr : voidpf);
|
||||
|
||||
procedure TRY_FREE (var strm : z_stream; ptr : voidpf);
|
||||
|
||||
const
|
||||
ZLIB_VERSION : string = '1.1.2';
|
||||
|
||||
const
|
||||
z_errbase = Z_NEED_DICT;
|
||||
z_errmsg : array[0..9] of string = { indexed by 2-zlib_error }
|
||||
('need dictionary', { Z_NEED_DICT 2 }
|
||||
'stream end', { Z_STREAM_END 1 }
|
||||
'', { Z_OK 0 }
|
||||
'file error', { Z_ERRNO (-1) }
|
||||
'stream error', { Z_STREAM_ERROR (-2) }
|
||||
'data error', { Z_DATA_ERROR (-3) }
|
||||
'insufficient memory', { Z_MEM_ERROR (-4) }
|
||||
'buffer error', { Z_BUF_ERROR (-5) }
|
||||
'incompatible version',{ Z_VERSION_ERROR (-6) }
|
||||
'');
|
||||
const
|
||||
z_verbose : int = 1;
|
||||
|
||||
{$IFDEF DEBUG}
|
||||
procedure z_error (m : string);
|
||||
{$ENDIF}
|
||||
|
||||
implementation
|
||||
|
||||
function zError(err : int) : string;
|
||||
begin
|
||||
zError := String(z_errmsg[Z_NEED_DICT-err]);
|
||||
end;
|
||||
|
||||
function zlibVersion : string;
|
||||
begin
|
||||
zlibVersion := ZLIB_VERSION;
|
||||
end;
|
||||
|
||||
procedure z_error (m : string);
|
||||
begin
|
||||
WriteLn(output, m);
|
||||
Write('Zlib - Halt...');
|
||||
ReadLn;
|
||||
Halt(1);
|
||||
end;
|
||||
|
||||
{
|
||||
procedure Assert(cond : boolean; msg : string);
|
||||
begin
|
||||
if not cond then
|
||||
z_error(msg);
|
||||
end;
|
||||
}
|
||||
|
||||
procedure Trace(x : string);
|
||||
begin
|
||||
WriteLn(x);
|
||||
end;
|
||||
|
||||
procedure Tracev(x : string);
|
||||
begin
|
||||
if (z_verbose>0) then
|
||||
WriteLn(x);
|
||||
end;
|
||||
|
||||
procedure Tracevv(x : string);
|
||||
begin
|
||||
if (z_verbose>1) then
|
||||
WriteLn(x);
|
||||
end;
|
||||
|
||||
procedure Tracevvv(x : string);
|
||||
begin
|
||||
if (z_verbose>2) then
|
||||
WriteLn(x);
|
||||
end;
|
||||
|
||||
procedure Tracec(c : boolean; x : string);
|
||||
begin
|
||||
if (z_verbose>0) and (c) then
|
||||
WriteLn(x);
|
||||
end;
|
||||
|
||||
procedure Tracecv(c : boolean; x : string);
|
||||
begin
|
||||
if (z_verbose>1) and c then
|
||||
WriteLn(x);
|
||||
end;
|
||||
|
||||
function ZALLOC (var strm : z_stream; items : uInt; size : uInt) : voidpf;
|
||||
begin
|
||||
ZALLOC := strm.zalloc(strm.opaque, items, size);
|
||||
end;
|
||||
|
||||
procedure ZFREE (var strm : z_stream; ptr : voidpf);
|
||||
begin
|
||||
strm.zfree(strm.opaque, ptr);
|
||||
end;
|
||||
|
||||
procedure TRY_FREE (var strm : z_stream; ptr : voidpf);
|
||||
begin
|
||||
{if @strm <> Z_NULL then}
|
||||
strm.zfree(strm.opaque, ptr);
|
||||
end;
|
||||
|
||||
end.
|
||||
1174
contrib/fundamentals/ZLib/paszlib/gzIO.pas
Normal file
1174
contrib/fundamentals/ZLib/paszlib/gzIO.pas
Normal file
File diff suppressed because it is too large
Load Diff
225
contrib/fundamentals/ZLib/paszlib/infutil.pas
Normal file
225
contrib/fundamentals/ZLib/paszlib/infutil.pas
Normal file
@@ -0,0 +1,225 @@
|
||||
Unit infutil;
|
||||
|
||||
{ types and macros common to blocks and codes
|
||||
Copyright (C) 1995-1998 Mark Adler
|
||||
|
||||
WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change.
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
uses
|
||||
ZUtil, gZlib;
|
||||
|
||||
{ copy as much as possible from the sliding window to the output area }
|
||||
function inflate_flush(var s : inflate_blocks_state;
|
||||
var z : z_stream;
|
||||
r : int) : int;
|
||||
|
||||
{ And'ing with mask[n] masks the lower n bits }
|
||||
const
|
||||
inflate_mask : array[0..17-1] of uInt = (
|
||||
$0000,
|
||||
$0001, $0003, $0007, $000f, $001f, $003f, $007f, $00ff,
|
||||
$01ff, $03ff, $07ff, $0fff, $1fff, $3fff, $7fff, $ffff);
|
||||
|
||||
{procedure GRABBITS(j : int);}
|
||||
{procedure DUMPBITS(j : int);}
|
||||
{procedure NEEDBITS(j : int);}
|
||||
|
||||
implementation
|
||||
|
||||
{ macros for bit input with no checking and for returning unused bytes }
|
||||
procedure GRABBITS(j : int);
|
||||
begin
|
||||
{while (k < j) do
|
||||
begin
|
||||
Dec(z^.avail_in);
|
||||
Inc(z^.total_in);
|
||||
b := b or (uLong(z^.next_in^) shl k);
|
||||
Inc(z^.next_in);
|
||||
Inc(k, 8);
|
||||
end;}
|
||||
end;
|
||||
|
||||
procedure DUMPBITS(j : int);
|
||||
begin
|
||||
{b := b shr j;
|
||||
Dec(k, j);}
|
||||
end;
|
||||
|
||||
procedure NEEDBITS(j : int);
|
||||
begin
|
||||
(*
|
||||
while (k < j) do
|
||||
begin
|
||||
{NEEDBYTE;}
|
||||
if (n <> 0) then
|
||||
r :=Z_OK
|
||||
else
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, LongInt(p)-LongInt(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
result := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
Dec(n);
|
||||
b := b or (uLong(p^) shl k);
|
||||
Inc(p);
|
||||
Inc(k, 8);
|
||||
end;
|
||||
*)
|
||||
end;
|
||||
|
||||
procedure NEEDOUT;
|
||||
begin
|
||||
(*
|
||||
if (m = 0) then
|
||||
begin
|
||||
{WRAP}
|
||||
if (q = s.zend) and (s.read <> s.window) then
|
||||
begin
|
||||
q := s.window;
|
||||
if LongInt(q) < LongInt(s.read) then
|
||||
m := uInt(LongInt(s.read)-LongInt(q)-1)
|
||||
else
|
||||
m := uInt(LongInt(s.zend)-LongInt(q));
|
||||
end;
|
||||
|
||||
if (m = 0) then
|
||||
begin
|
||||
{FLUSH}
|
||||
s.write := q;
|
||||
r := inflate_flush(s,z,r);
|
||||
q := s.write;
|
||||
if LongInt(q) < LongInt(s.read) then
|
||||
m := uInt(LongInt(s.read)-LongInt(q)-1)
|
||||
else
|
||||
m := uInt(LongInt(s.zend)-LongInt(q));
|
||||
|
||||
{WRAP}
|
||||
if (q = s.zend) and (s.read <> s.window) then
|
||||
begin
|
||||
q := s.window;
|
||||
if LongInt(q) < LongInt(s.read) then
|
||||
m := uInt(LongInt(s.read)-LongInt(q)-1)
|
||||
else
|
||||
m := uInt(LongInt(s.zend)-LongInt(q));
|
||||
end;
|
||||
|
||||
if (m = 0) then
|
||||
begin
|
||||
{UPDATE}
|
||||
s.bitb := b;
|
||||
s.bitk := k;
|
||||
z.avail_in := n;
|
||||
Inc(z.total_in, LongInt(p)-LongInt(z.next_in));
|
||||
z.next_in := p;
|
||||
s.write := q;
|
||||
result := inflate_flush(s,z,r);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
r := Z_OK;
|
||||
*)
|
||||
end;
|
||||
|
||||
{ copy as much as possible from the sliding window to the output area }
|
||||
function inflate_flush(var s : inflate_blocks_state;
|
||||
var z : z_stream;
|
||||
r : int) : int;
|
||||
var
|
||||
n : uInt;
|
||||
p : pBytef;
|
||||
q : pBytef;
|
||||
begin
|
||||
{ local copies of source and destination pointers }
|
||||
p := z.next_out;
|
||||
q := s.read;
|
||||
|
||||
{ compute number of bytes to copy as far as end of window }
|
||||
if ptr2int(q) <= ptr2int(s.write) then
|
||||
n := uInt(ptr2int(s.write) - ptr2int(q))
|
||||
else
|
||||
n := uInt(ptr2int(s.zend) - ptr2int(q));
|
||||
if (n > z.avail_out) then
|
||||
n := z.avail_out;
|
||||
if (n <> 0) and (r = Z_BUF_ERROR) then
|
||||
r := Z_OK;
|
||||
|
||||
{ update counters }
|
||||
Dec(z.avail_out, n);
|
||||
Inc(z.total_out, n);
|
||||
|
||||
|
||||
{ update check information }
|
||||
if Assigned(s.checkfn) then
|
||||
begin
|
||||
s.check := s.checkfn(s.check, q, n);
|
||||
z.adler := s.check;
|
||||
end;
|
||||
|
||||
{ copy as far as end of window }
|
||||
zmemcpy(p, q, n);
|
||||
Inc(p, n);
|
||||
Inc(q, n);
|
||||
|
||||
{ see if more to copy at beginning of window }
|
||||
if (q = s.zend) then
|
||||
begin
|
||||
{ wrap pointers }
|
||||
q := s.window;
|
||||
if (s.write = s.zend) then
|
||||
s.write := s.window;
|
||||
|
||||
{ compute bytes to copy }
|
||||
n := uInt(ptr2int(s.write) - ptr2int(q));
|
||||
if (n > z.avail_out) then
|
||||
n := z.avail_out;
|
||||
if (n <> 0) and (r = Z_BUF_ERROR) then
|
||||
r := Z_OK;
|
||||
|
||||
{ update counters }
|
||||
Dec( z.avail_out, n);
|
||||
Inc( z.total_out, n);
|
||||
|
||||
{ update check information }
|
||||
if Assigned(s.checkfn) then
|
||||
begin
|
||||
s.check := s.checkfn(s.check, q, n);
|
||||
z.adler := s.check;
|
||||
end;
|
||||
|
||||
{ copy }
|
||||
zmemcpy(p, q, n);
|
||||
Inc(p, n);
|
||||
Inc(q, n);
|
||||
end;
|
||||
|
||||
|
||||
{ update pointers }
|
||||
z.next_out := p;
|
||||
s.read := q;
|
||||
|
||||
{ done }
|
||||
inflate_flush := r;
|
||||
end;
|
||||
|
||||
end.
|
||||
251
contrib/fundamentals/ZLib/paszlib/minigzip.pas
Normal file
251
contrib/fundamentals/ZLib/paszlib/minigzip.pas
Normal file
@@ -0,0 +1,251 @@
|
||||
program minigzip;
|
||||
|
||||
{
|
||||
minigzip.c -- simulate gzip using the zlib compression library
|
||||
Copyright (C) 1995-1998 Jean-loup Gailly.
|
||||
|
||||
minigzip is a minimal implementation of the gzip utility. This is
|
||||
only an example of using zlib and isn't meant to replace the
|
||||
full-featured gzip. No attempt is made to deal with file systems
|
||||
limiting names to 14 or 8+3 characters, etc... Error checking is
|
||||
very limited. So use minigzip only for testing; use gzip for the
|
||||
real thing. On MSDOS, use only on file names without extension
|
||||
or in pipe mode.
|
||||
|
||||
Pascal tranlastion based on code contributed by Francisco Javier Crespo
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
}
|
||||
|
||||
uses
|
||||
{$IFDEF VER80}
|
||||
WinCrt,
|
||||
{$ENDIF}
|
||||
gzio, zutil;
|
||||
|
||||
const
|
||||
BUFLEN = 16384 ;
|
||||
GZ_SUFFIX = '.gz' ;
|
||||
|
||||
{$DEFINE MAXSEF_64K}
|
||||
|
||||
var
|
||||
buf : packed array [0..BUFLEN-1] of byte; { Global uses BSS instead of stack }
|
||||
prog : string;
|
||||
|
||||
{ ERROR =====================================================================
|
||||
|
||||
Display error message and exit
|
||||
|
||||
============================================================================}
|
||||
|
||||
procedure error (msg:string);
|
||||
begin
|
||||
writeln (prog,': ',msg);
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
|
||||
{ GZ_COMPRESS ===============================================================
|
||||
|
||||
Compress input to output then close both files
|
||||
|
||||
============================================================================}
|
||||
|
||||
procedure gz_compress (var infile:file; outfile:gzFile);
|
||||
var
|
||||
len : uInt;
|
||||
ioerr : integer;
|
||||
err : int;
|
||||
begin
|
||||
|
||||
while true do begin
|
||||
|
||||
{$I-}
|
||||
blockread (infile, buf, BUFLEN, len);
|
||||
{$I+}
|
||||
ioerr := IOResult;
|
||||
if (ioerr <> 0) then begin
|
||||
writeln ('read error: ',ioerr);
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
if (len = 0) then break;
|
||||
|
||||
if (gzwrite (outfile, @buf, len) <> len)
|
||||
then error (gzerror (outfile, err));
|
||||
|
||||
end; {WHILE}
|
||||
|
||||
close (infile);
|
||||
if (gzclose (outfile) <> 0{Z_OK})
|
||||
then error ('gzclose error');
|
||||
end;
|
||||
|
||||
|
||||
{ GZ_UNCOMPRESS =============================================================
|
||||
|
||||
Uncompress input to output then close both files
|
||||
|
||||
============================================================================}
|
||||
|
||||
procedure gz_uncompress (infile:gzFile; var outfile:file);
|
||||
var
|
||||
len : int;
|
||||
written : uInt;
|
||||
ioerr : integer;
|
||||
err : int;
|
||||
begin
|
||||
while true do begin
|
||||
|
||||
len := gzread (infile, @buf, BUFLEN);
|
||||
if (len < 0)
|
||||
then error (gzerror (infile, err));
|
||||
if (len = 0)
|
||||
then break;
|
||||
|
||||
{$I-}
|
||||
blockwrite (outfile, buf, len, written);
|
||||
{$I+}
|
||||
if (written <> len)
|
||||
then error ('write error');
|
||||
|
||||
end; {WHILE}
|
||||
|
||||
{$I-}
|
||||
close (outfile);
|
||||
{$I+}
|
||||
ioerr := IOResult;
|
||||
if (ioerr <> 0) then begin
|
||||
writeln ('close error: ',ioerr);
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
if (gzclose (infile) <> 0{Z_OK})
|
||||
then error ('gzclose error');
|
||||
end;
|
||||
|
||||
|
||||
{ FILE_COMPRESS =============================================================
|
||||
|
||||
Compress the given file:
|
||||
create a corresponding .gz file and remove the original
|
||||
|
||||
============================================================================}
|
||||
|
||||
procedure file_compress (filename:string; mode:string);
|
||||
var
|
||||
infile : file;
|
||||
outfile : gzFile;
|
||||
ioerr : integer;
|
||||
outname : string;
|
||||
begin
|
||||
Assign (infile, filename);
|
||||
{$I-}
|
||||
Reset (infile,1);
|
||||
{$I+}
|
||||
ioerr := IOResult;
|
||||
if (ioerr <> 0) then begin
|
||||
writeln ('open error: ',ioerr);
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
outname := filename + GZ_SUFFIX;
|
||||
outfile := gzopen (outname, mode);
|
||||
|
||||
if (outfile = NIL) then begin
|
||||
writeln (prog,': can''t gzopen ',outname);
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
gz_compress(infile, outfile);
|
||||
erase (infile);
|
||||
end;
|
||||
|
||||
|
||||
{ FILE_UNCOMPRESS ===========================================================
|
||||
|
||||
Uncompress the given file and remove the original
|
||||
|
||||
============================================================================}
|
||||
|
||||
procedure file_uncompress (filename:string);
|
||||
var
|
||||
inname : string;
|
||||
outname : string;
|
||||
infile : gzFile;
|
||||
outfile : file;
|
||||
ioerr : integer;
|
||||
len : integer;
|
||||
begin
|
||||
len := Length(filename);
|
||||
|
||||
if (copy(filename,len-2,3) = GZ_SUFFIX) then begin
|
||||
inname := filename;
|
||||
outname := copy(filename,0,len-3);
|
||||
end
|
||||
else begin
|
||||
inname := filename + GZ_SUFFIX;
|
||||
outname := filename;
|
||||
end;
|
||||
|
||||
infile := gzopen (inname, 'r');
|
||||
if (infile = NIL) then begin
|
||||
writeln (prog,': can''t gzopen ',inname);
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
Assign (outfile, outname);
|
||||
{$I-}
|
||||
Rewrite (outfile,1);
|
||||
{$I+}
|
||||
ioerr := IOResult;
|
||||
if (ioerr <> 0) then begin
|
||||
writeln ('open error: ',ioerr);
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
gz_uncompress (infile, outfile);
|
||||
|
||||
{ erase (infile); }
|
||||
end;
|
||||
|
||||
|
||||
{ MINIGZIP =================================================================}
|
||||
|
||||
var
|
||||
|
||||
uncompr : boolean;
|
||||
outmode : string[20];
|
||||
i : integer;
|
||||
option : string;
|
||||
|
||||
begin
|
||||
uncompr := false;
|
||||
outmode := 'w6 ';
|
||||
prog := ParamStr(0);
|
||||
|
||||
if (ParamCount = 0) then begin
|
||||
writeln ('Error: STDIO/STDOUT not supported yet');
|
||||
writeln;
|
||||
writeln ('Usage: minigzip [-d] [-f] [-h] [-1 to -9] <file>');
|
||||
writeln (' -d : decompress');
|
||||
writeln (' -f : compress with Z_FILTERED');
|
||||
writeln (' -h : compress with Z_HUFFMAN_ONLY');
|
||||
writeln (' -1 to -9 : compression level');
|
||||
exit;
|
||||
end;
|
||||
|
||||
for i:=1 to ParamCount do begin
|
||||
option := ParamStr(i);
|
||||
if (option = '-d') then uncompr := true;
|
||||
if (option = '-f') then outmode[3] := 'f';
|
||||
if (option = '-h') then outmode[3] := 'h';
|
||||
if (option[1] = '-') and (option[2] >= '1') and (option[2] <= '9')
|
||||
then outmode[2] := option[2];
|
||||
end;
|
||||
|
||||
if (uncompr = true)
|
||||
then file_uncompress (ParamStr(ParamCount))
|
||||
else file_compress (ParamStr(ParamCount), outmode);
|
||||
end.
|
||||
597
contrib/fundamentals/ZLib/paszlib/minizip/MiniUnz.pas
Normal file
597
contrib/fundamentals/ZLib/paszlib/minizip/MiniUnz.pas
Normal file
@@ -0,0 +1,597 @@
|
||||
Program MiniUnz;
|
||||
|
||||
{ mini unzip demo package by Gilles Vollant
|
||||
|
||||
Usage : miniunz [-exvlo] file.zip [file_to_extract]
|
||||
|
||||
-l or -v list the content of the zipfile.
|
||||
-e extract a specific file or all files if [file_to_extract] is missing
|
||||
-x like -e, but extract without path information
|
||||
-o overwrite an existing file without warning
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 2000 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
}
|
||||
|
||||
{$ifdef WIN32}
|
||||
{$define Delphi}
|
||||
{$ifndef FPC}
|
||||
{$define Delphi32}
|
||||
{$endif}
|
||||
{$endif}
|
||||
|
||||
uses
|
||||
{$ifdef Delphi}
|
||||
SysUtils, Windows,
|
||||
{$else}
|
||||
WinDos, strings,
|
||||
{$endif}
|
||||
zutil,
|
||||
gzlib, ziputils,
|
||||
unzip;
|
||||
|
||||
const
|
||||
CASESENSITIVITY = 0;
|
||||
WRITEBUFFERSIZE = 8192;
|
||||
|
||||
|
||||
{ change_file_date : change the date/time of a file
|
||||
filename : the filename of the file where date/time must be modified
|
||||
dosdate : the new date at the MSDos format (4 bytes)
|
||||
tmu_date : the SAME new date at the tm_unz format }
|
||||
|
||||
procedure change_file_date(const filename : PChar;
|
||||
dosdate : uLong;
|
||||
tmu_date : tm_unz);
|
||||
{$ifdef Delphi32}
|
||||
var
|
||||
hFile : THandle;
|
||||
ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite : TFileTime;
|
||||
begin
|
||||
hFile := CreateFile(filename,GENERIC_READ or GENERIC_WRITE,
|
||||
0,NIL,OPEN_EXISTING,0,0);
|
||||
GetFileTime(hFile, @ftCreate, @ftLastAcc, @ftLastWrite);
|
||||
DosDateTimeToFileTime(WORD((dosdate shl 16)), WORD(dosdate), ftLocal);
|
||||
LocalFileTimeToFileTime(ftLocal, ftm);
|
||||
SetFileTime(hFile,@ftm, @ftLastAcc, @ftm);
|
||||
CloseHandle(hFile);
|
||||
end;
|
||||
{$else}
|
||||
{$ifdef FPC}
|
||||
var
|
||||
hFile : THandle;
|
||||
ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite : TFileTime;
|
||||
begin
|
||||
hFile := CreateFile(filename,GENERIC_READ or GENERIC_WRITE,
|
||||
0,NIL,OPEN_EXISTING,0,0);
|
||||
GetFileTime(hFile, @ftCreate, @ftLastAcc, @ftLastWrite);
|
||||
DosDateTimeToFileTime(WORD((dosdate shl 16)), WORD(dosdate), @ftLocal);
|
||||
LocalFileTimeToFileTime(ftLocal, @ftm);
|
||||
SetFileTime(hFile,ftm, ftLastAcc, ftm);
|
||||
CloseHandle(hFile);
|
||||
end;
|
||||
{$else} { msdos }
|
||||
var
|
||||
f: file;
|
||||
begin
|
||||
Assign(f, filename);
|
||||
Reset(f, 1); { open file for reading }
|
||||
{ (Otherwise, close will update time) }
|
||||
SetFTime(f,dosDate);
|
||||
Close(f);
|
||||
end;
|
||||
{$endif}
|
||||
{$endif}
|
||||
|
||||
|
||||
{ mymkdir and change_file_date are not 100 % portable
|
||||
As I don't know well Unix, I wait feedback for the unix portion }
|
||||
|
||||
function mymkdir(dirname : PChar) : boolean;
|
||||
var
|
||||
S : string;
|
||||
begin
|
||||
S := StrPas(dirname);
|
||||
{$I-}
|
||||
mkdir(S);
|
||||
mymkdir := IOresult = 0;
|
||||
end;
|
||||
|
||||
function makedir (newdir : PChar) : boolean;
|
||||
var
|
||||
buffer : PChar;
|
||||
p : PChar;
|
||||
len : int;
|
||||
var
|
||||
hold : char;
|
||||
begin
|
||||
makedir := false;
|
||||
len := strlen(newdir);
|
||||
|
||||
if (len <= 0) then
|
||||
exit;
|
||||
|
||||
buffer := PChar(zcalloc (NIL, len+1, 1));
|
||||
|
||||
strcopy(buffer,newdir);
|
||||
|
||||
if (buffer[len-1] = '/') then
|
||||
buffer[len-1] := #0;
|
||||
|
||||
if mymkdir(buffer) then
|
||||
begin
|
||||
if Assigned(buffer) then
|
||||
zcfree(NIL, buffer);
|
||||
makedir := true;
|
||||
exit;
|
||||
end;
|
||||
|
||||
p := buffer+1;
|
||||
while true do
|
||||
begin
|
||||
while( (p^<>#0) and (p^ <> '\') and (p^ <> '/') ) do
|
||||
Inc(p);
|
||||
hold := p^;
|
||||
p^ := #0;
|
||||
if (not mymkdir(buffer)) {and (errno = ENOENT)} then
|
||||
begin
|
||||
WriteLn('couldn''t create directory ',buffer);
|
||||
if Assigned(buffer) then
|
||||
zcfree(NIL, buffer);
|
||||
exit;
|
||||
end;
|
||||
if (hold = #0) then
|
||||
break;
|
||||
p^ := hold;
|
||||
Inc(p);
|
||||
end;
|
||||
if Assigned(buffer) then
|
||||
zcfree(NIL, buffer);
|
||||
makedir := true;
|
||||
end;
|
||||
|
||||
procedure do_banner;
|
||||
begin
|
||||
WriteLn('MiniUnz 0.15, demo package written by Gilles Vollant');
|
||||
WriteLn('Pascal port by Jacques Nomssi Nzali');
|
||||
WriteLn('more info at http://wwww.tu-chemnitz.de/~nomssi/paszlib.html');
|
||||
WriteLn;
|
||||
end;
|
||||
|
||||
procedure do_help;
|
||||
begin
|
||||
WriteLn('Usage : miniunz [-exvlo] file.zip [file_to_extract]');
|
||||
WriteLn;
|
||||
end;
|
||||
|
||||
function LeadingZero(w : Word) : String;
|
||||
var
|
||||
s : String;
|
||||
begin
|
||||
Str(w:0,s);
|
||||
if Length(s) = 1 then
|
||||
s := '0' + s;
|
||||
LeadingZero := s;
|
||||
end;
|
||||
|
||||
function HexToStr(w : long) : string;
|
||||
const
|
||||
ByteToChar : array[0..$F] of char ='0123456789ABCDEF';
|
||||
var
|
||||
s : string;
|
||||
i : int;
|
||||
x : long;
|
||||
begin
|
||||
s := '';
|
||||
x := w;
|
||||
for i := 0 to 3 do
|
||||
begin
|
||||
s := ByteToChar[Byte(x) shr 4] + ByteToChar[Byte(x) and $F] + s;
|
||||
x := x shr 8;
|
||||
end;
|
||||
HexToStr := s;
|
||||
end;
|
||||
|
||||
function do_list(uf : unzFile) : int;
|
||||
var
|
||||
i : uLong;
|
||||
gi : unz_global_info;
|
||||
err : int;
|
||||
var
|
||||
filename_inzip : array[0..255] of char;
|
||||
file_info : unz_file_info;
|
||||
ratio : uLong;
|
||||
string_method : string[255];
|
||||
var
|
||||
iLevel : uInt;
|
||||
begin
|
||||
err := unzGetGlobalInfo(uf, gi);
|
||||
if (err <> UNZ_OK) then
|
||||
WriteLn('error ',err,' with zipfile in unzGetGlobalInfo');
|
||||
WriteLn(' Length Method Size Ratio Date Time CRC-32 Name');
|
||||
WriteLn(' ------ ------ ---- ----- ---- ---- ------ ----');
|
||||
for i := 0 to gi.number_entry-1 do
|
||||
begin
|
||||
ratio := 0;
|
||||
err := unzGetCurrentFileInfo(uf, @file_info, filename_inzip, sizeof(filename_inzip),NIL,0,NIL,0);
|
||||
if (err <> UNZ_OK) then
|
||||
begin
|
||||
WriteLn('error ',err,' with zipfile in unzGetCurrentFileInfo');
|
||||
break;
|
||||
end;
|
||||
if (file_info.uncompressed_size>0) then
|
||||
ratio := (file_info.compressed_size*100) div file_info.uncompressed_size;
|
||||
|
||||
if (file_info.compression_method=0) then
|
||||
string_method := 'Stored'
|
||||
else
|
||||
if (file_info.compression_method=Z_DEFLATED) then
|
||||
begin
|
||||
iLevel := uInt((file_info.flag and $06) div 2);
|
||||
Case iLevel of
|
||||
0: string_method := 'Defl:N';
|
||||
1: string_method := 'Defl:X';
|
||||
2,3: string_method := 'Defl:F'; { 2:fast , 3 : extra fast}
|
||||
else
|
||||
string_method := 'Unkn. ';
|
||||
end;
|
||||
end;
|
||||
|
||||
WriteLn(file_info.uncompressed_size:7, ' ',
|
||||
string_method:6, ' ',
|
||||
file_info.compressed_size:7, ' ',
|
||||
ratio:3,'% ', LeadingZero(uLong(file_info.tmu_date.tm_mon)+1),'-',
|
||||
LeadingZero(uLong(file_info.tmu_date.tm_mday)):2,'-',
|
||||
LeadingZero(uLong(file_info.tmu_date.tm_year mod 100)):2,' ',
|
||||
LeadingZero(uLong(file_info.tmu_date.tm_hour)),':',
|
||||
LeadingZero(uLong(file_info.tmu_date.tm_min)),' ',
|
||||
HexToStr(uLong(file_info.crc)),' ',
|
||||
filename_inzip);
|
||||
|
||||
if ((i+1)<gi.number_entry) then
|
||||
begin
|
||||
err := unzGoToNextFile(uf);
|
||||
if (err <> UNZ_OK) then
|
||||
begin
|
||||
WriteLn('error ',err,' with zipfile in unzGoToNextFile');
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
do_list := 0;
|
||||
end;
|
||||
|
||||
|
||||
function do_extract_currentfile(
|
||||
uf : unzFile;
|
||||
const popt_extract_without_path : int;
|
||||
var popt_overwrite : int) : int;
|
||||
var
|
||||
filename_inzip : packed array[0..255] of char;
|
||||
filename_withoutpath : PChar;
|
||||
p: PChar;
|
||||
err : int;
|
||||
fout : FILEptr;
|
||||
buf : pointer;
|
||||
size_buf : uInt;
|
||||
file_info : unz_file_info;
|
||||
var
|
||||
write_filename : PChar;
|
||||
skip : int;
|
||||
var
|
||||
rep : char;
|
||||
ftestexist : FILEptr;
|
||||
var
|
||||
answer : string[127];
|
||||
var
|
||||
c : char;
|
||||
begin
|
||||
fout := NIL;
|
||||
|
||||
err := unzGetCurrentFileInfo(uf, @file_info, filename_inzip,
|
||||
sizeof(filename_inzip), NIL, 0, NIL,0);
|
||||
|
||||
if (err <> UNZ_OK) then
|
||||
begin
|
||||
WriteLn('error ',err, ' with zipfile in unzGetCurrentFileInfo');
|
||||
do_extract_currentfile := err;
|
||||
exit;
|
||||
end;
|
||||
|
||||
size_buf := WRITEBUFFERSIZE;
|
||||
buf := zcalloc (NIL, size_buf, 1);
|
||||
if (buf = NIL) then
|
||||
begin
|
||||
WriteLn('Error allocating memory');
|
||||
do_extract_currentfile := UNZ_INTERNALERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
filename_withoutpath := filename_inzip;
|
||||
p := filename_withoutpath;
|
||||
while (p^ <> #0) do
|
||||
begin
|
||||
if (p^='/') or (p^='\') then
|
||||
filename_withoutpath := p+1;
|
||||
Inc(p);
|
||||
end;
|
||||
|
||||
if (filename_withoutpath^=#0) then
|
||||
begin
|
||||
if (popt_extract_without_path=0) then
|
||||
begin
|
||||
WriteLn('creating directory: ',filename_inzip);
|
||||
mymkdir(filename_inzip);
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
|
||||
skip := 0;
|
||||
if (popt_extract_without_path=0) then
|
||||
write_filename := filename_inzip
|
||||
else
|
||||
write_filename := filename_withoutpath;
|
||||
|
||||
err := unzOpenCurrentFile(uf);
|
||||
if (err <> UNZ_OK) then
|
||||
WriteLn('error ',err,' with zipfile in unzOpenCurrentFile');
|
||||
|
||||
|
||||
if ((popt_overwrite=0) and (err=UNZ_OK)) then
|
||||
begin
|
||||
rep := #0;
|
||||
|
||||
ftestexist := fopen(write_filename,fopenread);
|
||||
if (ftestexist <> NIL) then
|
||||
begin
|
||||
fclose(ftestexist);
|
||||
repeat
|
||||
Write('The file ',write_filename,
|
||||
' exist. Overwrite ? [y]es, [n]o, [A]ll: ');
|
||||
ReadLn(answer);
|
||||
|
||||
rep := answer[1] ;
|
||||
if ((rep>='a') and (rep<='z')) then
|
||||
Dec(rep, $20);
|
||||
until (rep = 'Y') or (rep = 'N') or (rep = 'A');
|
||||
end;
|
||||
|
||||
if (rep = 'N') then
|
||||
skip := 1;
|
||||
|
||||
if (rep = 'A') then
|
||||
popt_overwrite := 1;
|
||||
end;
|
||||
|
||||
if (skip=0) and (err=UNZ_OK) then
|
||||
begin
|
||||
fout := fopen(write_filename,fopenwrite);
|
||||
|
||||
{ some zipfile don't contain directory alone before file }
|
||||
if (fout=NIL) and (popt_extract_without_path=0) and
|
||||
(filename_withoutpath <> PChar(@filename_inzip)) then
|
||||
begin
|
||||
c := (filename_withoutpath-1)^;
|
||||
(filename_withoutpath-1)^ := #0;
|
||||
makedir(write_filename);
|
||||
(filename_withoutpath-1)^ := c;
|
||||
fout := fopen(write_filename, fopenwrite);
|
||||
end;
|
||||
|
||||
if (fout=NIL) then
|
||||
WriteLn('error opening ',write_filename);
|
||||
end;
|
||||
|
||||
if (fout <> NIL) then
|
||||
begin
|
||||
WriteLn(' extracting: ',write_filename);
|
||||
|
||||
repeat
|
||||
err := unzReadCurrentFile(uf,buf,size_buf);
|
||||
if (err<0) then
|
||||
begin
|
||||
WriteLn('error ',err,' with zipfile in unzReadCurrentFile');
|
||||
break;
|
||||
end;
|
||||
if (err>0) then
|
||||
begin
|
||||
if (fwrite(buf,err,1,fout) <> 1) then
|
||||
begin
|
||||
WriteLn('error in writing extracted file');
|
||||
err := UNZ_ERRNO;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
until (err=0);
|
||||
fclose(fout);
|
||||
if (err=0) then
|
||||
change_file_date(write_filename,file_info.dosDate,
|
||||
file_info.tmu_date);
|
||||
end;
|
||||
|
||||
if (err=UNZ_OK) then
|
||||
begin
|
||||
err := unzCloseCurrentFile (uf);
|
||||
if (err <> UNZ_OK) then
|
||||
WriteLn('error ',err,' with zipfile in unzCloseCurrentFile')
|
||||
else
|
||||
unzCloseCurrentFile(uf); { don't lose the error }
|
||||
end;
|
||||
end;
|
||||
|
||||
if buf <> NIL then
|
||||
zcfree(NIL, buf);
|
||||
do_extract_currentfile := err;
|
||||
end;
|
||||
|
||||
|
||||
function do_extract(uf : unzFile;
|
||||
opt_extract_without_path : int;
|
||||
opt_overwrite : int) : int;
|
||||
var
|
||||
i : uLong;
|
||||
gi : unz_global_info;
|
||||
err : int;
|
||||
begin
|
||||
err := unzGetGlobalInfo (uf, gi);
|
||||
if (err <> UNZ_OK) then
|
||||
WriteLn('error ',err,' with zipfile in unzGetGlobalInfo ');
|
||||
|
||||
for i:=0 to gi.number_entry-1 do
|
||||
begin
|
||||
if (do_extract_currentfile(uf, opt_extract_without_path,
|
||||
opt_overwrite) <> UNZ_OK) then
|
||||
break;
|
||||
|
||||
if ((i+1)<gi.number_entry) then
|
||||
begin
|
||||
err := unzGoToNextFile(uf);
|
||||
if (err <> UNZ_OK) then
|
||||
begin
|
||||
WriteLn('error ',err,' with zipfile in unzGoToNextFile');
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
do_extract := 0;
|
||||
end;
|
||||
|
||||
function do_extract_onefile(uf : unzFile;
|
||||
const filename : PChar;
|
||||
opt_extract_without_path : int;
|
||||
opt_overwrite : int) : int;
|
||||
begin
|
||||
if (unzLocateFile(uf,filename,CASESENSITIVITY) <> UNZ_OK) then
|
||||
begin
|
||||
WriteLn('file ',filename,' not found in the zipfile');
|
||||
do_extract_onefile := 2;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (do_extract_currentfile(uf, opt_extract_without_path,
|
||||
opt_overwrite) = UNZ_OK) then
|
||||
do_extract_onefile := 0
|
||||
else
|
||||
do_extract_onefile := 1;
|
||||
end;
|
||||
|
||||
{ -------------------------------------------------------------------- }
|
||||
function main : int;
|
||||
const
|
||||
zipfilename : PChar = NIL;
|
||||
filename_to_extract : PChar = NIL;
|
||||
var
|
||||
i : int;
|
||||
opt_do_list : int;
|
||||
opt_do_extract : int;
|
||||
opt_do_extract_withoutpath : int;
|
||||
opt_overwrite : int;
|
||||
filename_try : array[0..512-1] of char;
|
||||
uf : unzFile;
|
||||
var
|
||||
p : int;
|
||||
pstr : string[255];
|
||||
c : char;
|
||||
begin
|
||||
opt_do_list := 0;
|
||||
opt_do_extract := 1;
|
||||
opt_do_extract_withoutpath := 0;
|
||||
opt_overwrite := 0;
|
||||
uf := NIL;
|
||||
|
||||
do_banner;
|
||||
if (ParamCount=0) then
|
||||
begin
|
||||
do_help;
|
||||
Halt(0);
|
||||
end
|
||||
else
|
||||
begin
|
||||
for i := 1 to ParamCount do
|
||||
begin
|
||||
pstr := ParamStr(i);
|
||||
if pstr[1]='-' then
|
||||
begin
|
||||
for p := 2 to Length(pstr) do
|
||||
begin
|
||||
c := pstr[p];
|
||||
Case UpCase(c) of
|
||||
'L',
|
||||
'V' : opt_do_list := 1;
|
||||
'X' : opt_do_extract := 1;
|
||||
'E' : begin
|
||||
opt_do_extract := 1;
|
||||
opt_do_extract_withoutpath := 1;
|
||||
end;
|
||||
'O' : opt_overwrite := 1;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
pstr := pstr + #0;
|
||||
if (zipfilename = NIL) then
|
||||
zipfilename := StrNew(PChar(@pstr[1]))
|
||||
else
|
||||
if (filename_to_extract=NIL) then
|
||||
filename_to_extract := StrNew(PChar(@pstr[1]));
|
||||
end;
|
||||
end; { for }
|
||||
end;
|
||||
|
||||
if (zipfilename <> NIL) then
|
||||
begin
|
||||
strcopy(filename_try,zipfilename);
|
||||
uf := unzOpen(zipfilename);
|
||||
if (uf = NIL) then
|
||||
begin
|
||||
strcat(filename_try,'.zip');
|
||||
uf := unzOpen(filename_try);
|
||||
end;
|
||||
end;
|
||||
|
||||
if (uf = NIL) then
|
||||
begin
|
||||
WriteLn('Cannot open ',zipfilename,' or ',zipfilename,'.zip');
|
||||
Halt(1);
|
||||
end;
|
||||
|
||||
WriteLn(filename_try,' opened');
|
||||
|
||||
if (opt_do_list=1) then
|
||||
begin
|
||||
main := do_list(uf);
|
||||
exit;
|
||||
end
|
||||
else
|
||||
if (opt_do_extract=1) then
|
||||
begin
|
||||
if (filename_to_extract = NIL) then
|
||||
begin
|
||||
main := do_extract(uf,opt_do_extract_withoutpath,opt_overwrite);
|
||||
exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
main := do_extract_onefile(uf,filename_to_extract,
|
||||
opt_do_extract_withoutpath,opt_overwrite);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
unzCloseCurrentFile(uf);
|
||||
|
||||
strDispose(zipfilename);
|
||||
strDispose(filename_to_extract);
|
||||
main := 0;
|
||||
end;
|
||||
|
||||
begin
|
||||
main;
|
||||
Write('Done...');
|
||||
Readln;
|
||||
end.
|
||||
344
contrib/fundamentals/ZLib/paszlib/minizip/MiniZip.pas
Normal file
344
contrib/fundamentals/ZLib/paszlib/minizip/MiniZip.pas
Normal file
@@ -0,0 +1,344 @@
|
||||
Program MiniZip;
|
||||
{ minizip demo package by Gilles Vollant
|
||||
|
||||
Usage : minizip [-o] file.zip [files_to_add]
|
||||
|
||||
a file.zip file is created, all files listed in [files_to_add] are added
|
||||
to the new .zip file.
|
||||
-o an existing .zip file with be overwritten without warning
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 2000 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
}
|
||||
|
||||
{$ifdef WIN32}
|
||||
{$define Delphi}
|
||||
{$ifndef FPC}
|
||||
{$define Delphi32}
|
||||
{$endif}
|
||||
{$endif}
|
||||
|
||||
uses
|
||||
{$ifdef Delphi}
|
||||
SysUtils, Windows,
|
||||
{$else}
|
||||
WinDos, strings,
|
||||
{$endif}
|
||||
zutil, gzlib, ziputils, zip;
|
||||
|
||||
const
|
||||
WRITEBUFFERSIZE = Z_BUFSIZE;
|
||||
MAXFILENAME = Z_MAXFILENAMEINZIP;
|
||||
|
||||
{$ifdef Delphi32}
|
||||
function filetime(f : PChar; { name of file to get info on }
|
||||
var tmzip : tm_zip; { return value: access, modific. and creation times }
|
||||
var dt : uLong) : uLong; { dostime }
|
||||
var
|
||||
ret : int;
|
||||
var
|
||||
ftLocal : TFileTime; // FILETIME;
|
||||
hFind : THandle; // HANDLE;
|
||||
ff32 : TWIN32FindData; // WIN32_FIND_DATA;
|
||||
begin
|
||||
ret := 0;
|
||||
hFind := FindFirstFile(f, ff32);
|
||||
if (hFind <> INVALID_HANDLE_VALUE) then
|
||||
begin
|
||||
FileTimeToLocalFileTime(ff32.ftLastWriteTime,ftLocal);
|
||||
FileTimeToDosDateTime(ftLocal,LongRec(dt).hi,LongRec(dt).lo);
|
||||
FindClose(hFind);
|
||||
ret := 1;
|
||||
end;
|
||||
filetime := ret;
|
||||
end;
|
||||
{$else}
|
||||
{$ifdef FPC}
|
||||
function filetime(f : PChar; { name of file to get info on }
|
||||
var tmzip : tm_zip; { return value: access, modific. and creation times }
|
||||
var dt : uLong) : uLong; { dostime }
|
||||
var
|
||||
ret : int;
|
||||
var
|
||||
ftLocal : TFileTime; // FILETIME;
|
||||
hFind : THandle; // HANDLE;
|
||||
ff32 : TWIN32FindData; // WIN32_FIND_DATA;
|
||||
begin
|
||||
ret := 0;
|
||||
hFind := FindFirstFile(f, @ff32);
|
||||
if (hFind <> INVALID_HANDLE_VALUE) then
|
||||
begin
|
||||
FileTimeToLocalFileTime(ff32.ftLastWriteTime,@ftLocal);
|
||||
FileTimeToDosDateTime(ftLocal,@LongRec(dt).hi,@LongRec(dt).lo);
|
||||
FindClose(hFind);
|
||||
ret := 1;
|
||||
end;
|
||||
filetime := ret;
|
||||
end;
|
||||
{$else}
|
||||
function filetime(f : PChar; { name of file to get info on }
|
||||
var tmzip : tm_zip; { return value: access, modific. and creation times }
|
||||
var dt : uLong) : uLong; { dostime }
|
||||
var
|
||||
fl : file;
|
||||
yy, mm, dd, dow : Word;
|
||||
h, m, s, hund : Word; { For GetTime}
|
||||
dtrec : TDateTime; { For Pack/UnpackTime}
|
||||
begin
|
||||
{$i-}
|
||||
Assign(fl, f);
|
||||
Reset(fl, 1);
|
||||
if IOresult = 0 then
|
||||
begin
|
||||
GetFTime(fl,dt); { Get creation time }
|
||||
UnpackTime(dt, dtrec);
|
||||
Close(fl);
|
||||
tmzip.tm_sec := dtrec.sec;
|
||||
tmzip.tm_min := dtrec.min;
|
||||
tmzip.tm_hour := dtrec.hour;
|
||||
tmzip.tm_mday := dtrec.day;
|
||||
tmzip.tm_mon := dtrec.month;
|
||||
tmzip.tm_year := dtrec.year;
|
||||
end;
|
||||
|
||||
filetime := 0;
|
||||
end;
|
||||
{$endif}
|
||||
{$endif}
|
||||
|
||||
function check_exist_file(const filename : PChar) : int;
|
||||
var
|
||||
ftestexist : FILE;
|
||||
ret : int;
|
||||
begin
|
||||
ret := 1;
|
||||
Assign(ftestexist, filename);
|
||||
{$i-}
|
||||
reset(ftestexist);
|
||||
if IOresult <> 0 then
|
||||
ret := 0
|
||||
else
|
||||
system.close(ftestexist);
|
||||
check_exist_file := ret;
|
||||
end;
|
||||
|
||||
procedure do_banner;
|
||||
begin
|
||||
WriteLn('MiniZip 0.15, demo package written by Gilles Vollant');
|
||||
WriteLn('Pascal port by Jacques Nomssi Nzali');
|
||||
WriteLn('more info at http://www.tu-chemnitz.de/~nomssi/paszlib.html');
|
||||
WriteLn;
|
||||
end;
|
||||
|
||||
procedure do_help;
|
||||
begin
|
||||
WriteLn('Usage : minizip [-o] file.zip [files_to_add]');
|
||||
WriteLn;
|
||||
end;
|
||||
|
||||
function main : int;
|
||||
var
|
||||
argstr : string;
|
||||
i : int;
|
||||
opt_overwrite : int;
|
||||
opt_compress_level : int;
|
||||
zipfilenamearg : int;
|
||||
filename_try : array[0..MAXFILENAME-1] of char;
|
||||
zipok : int;
|
||||
err : int;
|
||||
size_buf : int;
|
||||
buf : voidp;
|
||||
var
|
||||
p : PChar;
|
||||
c : char;
|
||||
var
|
||||
len : int;
|
||||
dot_found : int;
|
||||
var
|
||||
rep : char;
|
||||
answer : string[128];
|
||||
var
|
||||
zf : zipFile;
|
||||
errclose : int;
|
||||
var
|
||||
fin : FILEptr;
|
||||
size_read : int;
|
||||
filenameinzip : {const} PChar;
|
||||
zi : zip_fileinfo;
|
||||
begin
|
||||
opt_overwrite := 0;
|
||||
opt_compress_level := Z_DEFAULT_COMPRESSION;
|
||||
zipfilenamearg := 0;
|
||||
err := 0;
|
||||
main := 0;
|
||||
|
||||
do_banner;
|
||||
if (ParamCount=0) then
|
||||
begin
|
||||
do_help;
|
||||
main := 0;
|
||||
exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
for i:=1 to ParamCount-1+1 do
|
||||
begin
|
||||
argstr := ParamStr(i)+#0;
|
||||
if (argstr[1]='-') then
|
||||
begin
|
||||
p := @argstr[1+1]; {const char *p=argv[i]+1;}
|
||||
|
||||
while (p^<>#0) do
|
||||
begin
|
||||
c := p^;
|
||||
Inc(p);
|
||||
if (c='o') or (c='O') then
|
||||
opt_overwrite := 1;
|
||||
if (c>='0') and (c<='9') then
|
||||
opt_compress_level := Byte(c)-Byte('0');
|
||||
end;
|
||||
end
|
||||
else
|
||||
if (zipfilenamearg = 0) then
|
||||
zipfilenamearg := i;
|
||||
end;
|
||||
end;
|
||||
|
||||
size_buf := WRITEBUFFERSIZE;
|
||||
buf := ALLOC(size_buf);
|
||||
if (buf=NIL) then
|
||||
begin
|
||||
WriteLn('Error allocating memory');
|
||||
main := ZIP_INTERNALERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (zipfilenamearg=0) then
|
||||
zipok := 0
|
||||
else
|
||||
begin
|
||||
dot_found := 0;
|
||||
|
||||
zipok := 1 ;
|
||||
argstr := ParamStr(zipfilenamearg) + #0;
|
||||
strcopy(filename_try, PChar(@argstr[1]));
|
||||
len := strlen(filename_try);
|
||||
for i:=0 to len-1 do
|
||||
if (filename_try[i]='.') then
|
||||
dot_found := 1;
|
||||
|
||||
if (dot_found = 0) then
|
||||
strcat(filename_try,'.zip');
|
||||
|
||||
if (opt_overwrite=0) then
|
||||
if (check_exist_file(filename_try)<>0) then
|
||||
begin
|
||||
repeat
|
||||
WriteLn('The file ',filename_try,
|
||||
' exist. Overwrite ? [y]es, [n]o : ');
|
||||
ReadLn(answer);
|
||||
rep := answer[1] ;
|
||||
if (rep>='a') and (rep<='z') then
|
||||
Dec(rep, $20);
|
||||
until (rep='Y') or (rep='N');
|
||||
if (rep='N') then
|
||||
zipok := 0;
|
||||
end;
|
||||
end;
|
||||
|
||||
if (zipok=1) then
|
||||
begin
|
||||
zf := zipOpen(filename_try,0);
|
||||
if (zf = NIL) then
|
||||
begin
|
||||
WriteLn('error opening ', filename_try);
|
||||
err := ZIP_ERRNO;
|
||||
end
|
||||
else
|
||||
WriteLn('creating ',filename_try);
|
||||
|
||||
i := zipfilenamearg+1;
|
||||
while (i<=ParamCount) and (err=ZIP_OK) do
|
||||
begin
|
||||
argstr := ParamStr(i)+#0;
|
||||
if (argstr[1] <>'-') and (argstr[1] <>'/') then
|
||||
begin
|
||||
filenameinzip := PChar(@argstr[1]);
|
||||
|
||||
zi.tmz_date.tm_sec := 0;
|
||||
zi.tmz_date.tm_min := 0;
|
||||
zi.tmz_date.tm_hour := 0;
|
||||
zi.tmz_date.tm_mday := 0;
|
||||
zi.tmz_date.tm_min := 0;
|
||||
zi.tmz_date.tm_year := 0;
|
||||
zi.dosDate := 0;
|
||||
zi.internal_fa := 0;
|
||||
zi.external_fa := 0;
|
||||
filetime(filenameinzip,zi.tmz_date,zi.dosDate);
|
||||
|
||||
if (opt_compress_level <> 0) then
|
||||
err := zipOpenNewFileInZip(zf,filenameinzip, @zi,
|
||||
NIL,0,NIL,0,NIL { comment}, Z_DEFLATED, opt_compress_level)
|
||||
else
|
||||
err := zipOpenNewFileInZip(zf,filenameinzip, @zi,
|
||||
NIL,0,NIL,0,NIL, 0, opt_compress_level);
|
||||
|
||||
if (err <> ZIP_OK) then
|
||||
WriteLn('error in opening ',filenameinzip,' in zipfile')
|
||||
else
|
||||
begin
|
||||
fin := fopen(filenameinzip, fopenread);
|
||||
if (fin=NIL) then
|
||||
begin
|
||||
err := ZIP_ERRNO;
|
||||
WriteLn('error in opening ',filenameinzip,' for reading');
|
||||
end;
|
||||
|
||||
if (err = ZIP_OK) then
|
||||
repeat
|
||||
err := ZIP_OK;
|
||||
size_read := fread(buf,1,size_buf,fin);
|
||||
|
||||
if (size_read < size_buf) then
|
||||
if feof(fin)=0 then
|
||||
begin
|
||||
WriteLn('error in reading ',filenameinzip);
|
||||
err := ZIP_ERRNO;
|
||||
end;
|
||||
|
||||
if (size_read>0) then
|
||||
begin
|
||||
err := zipWriteInFileInZip (zf,buf,size_read);
|
||||
if (err<0) then
|
||||
WriteLn('error in writing ',filenameinzip,' in the zipfile');
|
||||
end;
|
||||
until (err <> ZIP_OK) or (size_read=0);
|
||||
|
||||
fclose(fin);
|
||||
end;
|
||||
if (err<0) then
|
||||
err := ZIP_ERRNO
|
||||
else
|
||||
begin
|
||||
err := zipCloseFileInZip(zf);
|
||||
if (err<>ZIP_OK) then
|
||||
WriteLn('error in closing ',filenameinzip,' in the zipfile');
|
||||
end;
|
||||
Inc(i);
|
||||
end; { while }
|
||||
end; { if }
|
||||
|
||||
errclose := zipClose(zf,NIL);
|
||||
if (errclose <> ZIP_OK) then
|
||||
WriteLn('error in closing ',filename_try);
|
||||
end;
|
||||
|
||||
TRYFREE(buf); {FreeMem(buf, size_buf);}
|
||||
end;
|
||||
|
||||
begin
|
||||
main;
|
||||
Write('Done...');
|
||||
ReadLn;
|
||||
end.
|
||||
1629
contrib/fundamentals/ZLib/paszlib/minizip/UnZip.pas
Normal file
1629
contrib/fundamentals/ZLib/paszlib/minizip/UnZip.pas
Normal file
File diff suppressed because it is too large
Load Diff
831
contrib/fundamentals/ZLib/paszlib/minizip/Zip.pas
Normal file
831
contrib/fundamentals/ZLib/paszlib/minizip/Zip.pas
Normal file
@@ -0,0 +1,831 @@
|
||||
Unit zip;
|
||||
|
||||
{ zip.c -- IO on .zip files using zlib
|
||||
zip.h -- IO for compress .zip files using zlib
|
||||
Version 0.15 alpha, Mar 19th, 1998,
|
||||
|
||||
Copyright (C) 1998 Gilles Vollant
|
||||
|
||||
This package allows to create .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Encryption and multi volume ZipFile (span) are not supported.
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
For decompression of .zip files, look at unzip.pas
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 2000 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt }
|
||||
|
||||
|
||||
interface
|
||||
|
||||
{$ifdef WIN32}
|
||||
{$define Delphi}
|
||||
{$endif}
|
||||
|
||||
uses
|
||||
zutil,
|
||||
gzLib,
|
||||
ziputils;
|
||||
|
||||
const
|
||||
ZIP_OK = (0);
|
||||
ZIP_ERRNO = (Z_ERRNO);
|
||||
ZIP_PARAMERROR = (-102);
|
||||
ZIP_INTERNALERROR = (-104);
|
||||
|
||||
(*
|
||||
{ tm_zip contain date/time info }
|
||||
type
|
||||
tm_zip = record
|
||||
tm_sec : uInt; { seconds after the minute - [0,59] }
|
||||
tm_min : uInt; { minutes after the hour - [0,59] }
|
||||
tm_hour : uInt; { hours since midnight - [0,23] }
|
||||
tm_mday : uInt; { day of the month - [1,31] }
|
||||
tm_mon : uInt; { months since January - [0,11] }
|
||||
tm_year : uInt; { years - [1980..2044] }
|
||||
end;
|
||||
*)
|
||||
type
|
||||
zip_fileinfo = record
|
||||
tmz_date : tm_zip; { date in understandable format }
|
||||
dosDate : uLong; { if dos_date = 0, tmu_date is used }
|
||||
{ flag : uLong; } { general purpose bit flag 2 bytes }
|
||||
|
||||
internal_fa : uLong; { internal file attributes 2 bytes }
|
||||
external_fa : uLong; { external file attributes 4 bytes }
|
||||
end;
|
||||
zip_fileinfo_ptr = ^zip_fileinfo;
|
||||
|
||||
function zipOpen (const pathname : PChar; append : int) : zipFile; {ZEXPORT}
|
||||
{ Create a zipfile.
|
||||
pathname contain on Windows NT a filename like "c:\\zlib\\zlib111.zip" or on
|
||||
an Unix computer "zlib/zlib111.zip".
|
||||
if the file pathname exist and append=1, the zip will be created at the end
|
||||
of the file. (useful if the file contain a self extractor code)
|
||||
If the zipfile cannot be opened, the return value is NIL.
|
||||
Else, the return value is a zipFile Handle, usable with other function
|
||||
of this zip package. }
|
||||
|
||||
function zipOpenNewFileInZip(afile : zipFile;
|
||||
{const} filename : PChar;
|
||||
const zipfi : zip_fileinfo_ptr;
|
||||
const extrafield_local : voidp;
|
||||
size_extrafield_local : uInt;
|
||||
const extrafield_global : voidp;
|
||||
size_extrafield_global : uInt;
|
||||
const comment : PChar;
|
||||
method : int;
|
||||
level : int): int; {ZEXPORT}
|
||||
{ Open a file in the ZIP for writing.
|
||||
filename : the filename in zip (if NIL, '-' without quote will be used
|
||||
zipfi^ contain supplemental information
|
||||
if extrafield_local<>NIL and size_extrafield_local>0, extrafield_local
|
||||
contains the extrafield data the the local header
|
||||
if extrafield_global<>NIL and size_extrafield_global>0, extrafield_global
|
||||
contains the extrafield data the the local header
|
||||
if comment <> NIL, comment contain the comment string
|
||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION) }
|
||||
|
||||
function zipWriteInFileInZip (afile : zipFile;
|
||||
const buf : voidp;
|
||||
len : unsigned) : int; {ZEXPORT}
|
||||
{ Write data in the zipfile }
|
||||
|
||||
function zipCloseFileInZip (afile : zipFile): int; {ZEXPORT}
|
||||
{ Close the current file in the zipfile }
|
||||
|
||||
function zipClose (afile : zipFile; const global_comment : PChar): int; {ZEXPORT}
|
||||
{ Close the zipfile }
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
{$ifdef Delphi}
|
||||
SysUtils,
|
||||
{$else}
|
||||
strings,
|
||||
{$endif}
|
||||
zDeflate, crc;
|
||||
|
||||
const
|
||||
VERSIONMADEBY = ($0); { platform depedent }
|
||||
|
||||
const
|
||||
zip_copyright : PChar = ' zip 0.15 Copyright 1998 Gilles Vollant ';
|
||||
|
||||
|
||||
const
|
||||
SIZEDATA_INDATABLOCK = (4096-(4*4));
|
||||
|
||||
LOCALHEADERMAGIC = $04034b50;
|
||||
{CENTRALHEADERMAGIC = $02014b50;}
|
||||
ENDHEADERMAGIC = $06054b50;
|
||||
|
||||
FLAG_LOCALHEADER_OFFSET = $06;
|
||||
CRC_LOCALHEADER_OFFSET = $0e;
|
||||
|
||||
SIZECENTRALHEADER = $2e; { 46 }
|
||||
|
||||
type
|
||||
linkedlist_datablock_internal_ptr = ^linkedlist_datablock_internal;
|
||||
linkedlist_datablock_internal = record
|
||||
next_datablock : linkedlist_datablock_internal_ptr;
|
||||
avail_in_this_block : uLong;
|
||||
filled_in_this_block : uLong;
|
||||
unused : uLong; { for future use and alignement }
|
||||
data : array[0..SIZEDATA_INDATABLOCK-1] of byte;
|
||||
end;
|
||||
|
||||
type
|
||||
linkedlist_data = record
|
||||
first_block : linkedlist_datablock_internal_ptr;
|
||||
last_block : linkedlist_datablock_internal_ptr;
|
||||
end;
|
||||
linkedlist_data_ptr = ^linkedlist_data;
|
||||
|
||||
type
|
||||
curfile_info = record
|
||||
stream : z_stream; { zLib stream structure for inflate }
|
||||
stream_initialised : boolean; { TRUE is stream is initialised }
|
||||
pos_in_buffered_data : uInt; { last written byte in buffered_data }
|
||||
|
||||
pos_local_header : uLong; { offset of the local header of the file
|
||||
currenty writing }
|
||||
central_header : PChar; { central header data for the current file }
|
||||
size_centralheader : uLong; { size of the central header for cur file }
|
||||
flag : uLong; { flag of the file currently writing }
|
||||
|
||||
method : int; { compression method of file currenty wr.}
|
||||
buffered_data : array[0..Z_BUFSIZE-1] of byte;{ buffer contain compressed data to be written}
|
||||
dosDate : uLong;
|
||||
crc32 : uLong;
|
||||
end;
|
||||
|
||||
type
|
||||
zip_internal = record
|
||||
filezip : FILEptr;
|
||||
central_dir : linkedlist_data; { datablock with central dir in construction}
|
||||
in_opened_file_inzip : boolean; { TRUE if a file in the zip is currently writ.}
|
||||
ci : curfile_info; { info on the file curretly writing }
|
||||
|
||||
begin_pos : uLong; { position of the beginning of the zipfile }
|
||||
number_entry : uLong;
|
||||
end;
|
||||
zip_internal_ptr = ^zip_internal;
|
||||
|
||||
function allocate_new_datablock : linkedlist_datablock_internal_ptr;
|
||||
var
|
||||
ldi : linkedlist_datablock_internal_ptr;
|
||||
begin
|
||||
ldi := linkedlist_datablock_internal_ptr( ALLOC(sizeof(linkedlist_datablock_internal)) );
|
||||
if (ldi<>NIL) then
|
||||
begin
|
||||
ldi^.next_datablock := NIL ;
|
||||
ldi^.filled_in_this_block := 0 ;
|
||||
ldi^.avail_in_this_block := SIZEDATA_INDATABLOCK ;
|
||||
end;
|
||||
allocate_new_datablock := ldi;
|
||||
end;
|
||||
|
||||
procedure free_datablock(ldi : linkedlist_datablock_internal_ptr);
|
||||
var
|
||||
ldinext : linkedlist_datablock_internal_ptr;
|
||||
begin
|
||||
while (ldi<>NIL) do
|
||||
begin
|
||||
ldinext := ldi^.next_datablock;
|
||||
TRYFREE(ldi);
|
||||
ldi := ldinext;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure init_linkedlist(var ll : linkedlist_data);
|
||||
begin
|
||||
ll.last_block := NIL;
|
||||
ll.first_block := NIL;
|
||||
end;
|
||||
|
||||
procedure free_linkedlist(var ll : linkedlist_data);
|
||||
begin
|
||||
free_datablock(ll.first_block);
|
||||
ll.last_block := NIL;
|
||||
ll.first_block := NIL;
|
||||
end;
|
||||
|
||||
function add_data_in_datablock(ll : linkedlist_data_ptr;
|
||||
const buf : voidp;
|
||||
len : uLong) : int;
|
||||
var
|
||||
ldi : linkedlist_datablock_internal_ptr;
|
||||
from_copy : {const} pBytef ;
|
||||
var
|
||||
copy_this : uInt;
|
||||
i : uInt;
|
||||
to_copy : pBytef;
|
||||
begin
|
||||
if (ll=NIL) then
|
||||
begin
|
||||
add_data_in_datablock := ZIP_INTERNALERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (ll^.last_block = NIL) then
|
||||
begin
|
||||
ll^.last_block := allocate_new_datablock;
|
||||
ll^.first_block := ll^.last_block;
|
||||
if (ll^.first_block = NIL) then
|
||||
begin
|
||||
add_data_in_datablock := ZIP_INTERNALERROR;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
ldi := ll^.last_block;
|
||||
from_copy := pBytef(buf);
|
||||
|
||||
while (len>0) do
|
||||
begin
|
||||
if (ldi^.avail_in_this_block=0) then
|
||||
begin
|
||||
ldi^.next_datablock := allocate_new_datablock;
|
||||
if (ldi^.next_datablock = NIL) then
|
||||
begin
|
||||
add_data_in_datablock := ZIP_INTERNALERROR;
|
||||
exit;
|
||||
end;
|
||||
ldi := ldi^.next_datablock ;
|
||||
ll^.last_block := ldi;
|
||||
end;
|
||||
|
||||
if (ldi^.avail_in_this_block < len) then
|
||||
copy_this := uInt(ldi^.avail_in_this_block)
|
||||
else
|
||||
copy_this := uInt(len);
|
||||
|
||||
to_copy := @(ldi^.data[ldi^.filled_in_this_block]);
|
||||
|
||||
for i :=0 to copy_this-1 do
|
||||
pzByteArray(to_copy)^[i] := pzByteArray(from_copy)^[i];
|
||||
|
||||
Inc(ldi^.filled_in_this_block, copy_this);
|
||||
Dec(ldi^.avail_in_this_block, copy_this);
|
||||
Inc(from_copy, copy_this);
|
||||
Dec(len, copy_this);
|
||||
end;
|
||||
add_data_in_datablock := ZIP_OK;
|
||||
end;
|
||||
|
||||
|
||||
function write_datablock(fout : FILEptr; ll : linkedlist_data_ptr) : int;
|
||||
var
|
||||
ldi : linkedlist_datablock_internal_ptr;
|
||||
begin
|
||||
ldi := ll^.first_block;
|
||||
while (ldi<>NIL) do
|
||||
begin
|
||||
if (ldi^.filled_in_this_block > 0) then
|
||||
begin
|
||||
if (fwrite(@ldi^.data,uInt(ldi^.filled_in_this_block),1,fout)<>1) then
|
||||
begin
|
||||
write_datablock := ZIP_ERRNO;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
ldi := ldi^.next_datablock;
|
||||
end;
|
||||
write_datablock := ZIP_OK;
|
||||
end;
|
||||
|
||||
{**************************************************************************}
|
||||
|
||||
{ ===========================================================================
|
||||
Outputs a long in LSB order to the given file
|
||||
nbByte = 1, 2 or 4 (byte, short or long) }
|
||||
|
||||
function ziplocal_putValue (afile : FILEptr; x : uLong; nbByte : int) : int;
|
||||
var
|
||||
buf : array[0..4-1] of byte;
|
||||
n : int;
|
||||
begin
|
||||
for n := 0 to nbByte-1 do
|
||||
begin
|
||||
buf[n] := Byte(x and $ff);
|
||||
x := x shr 8;
|
||||
end;
|
||||
if (fwrite(@buf,nbByte,1,afile)<>1) then
|
||||
ziplocal_putValue := ZIP_ERRNO
|
||||
else
|
||||
ziplocal_putValue := ZIP_OK;
|
||||
end;
|
||||
|
||||
procedure ziplocal_putValue_inmemory (dest : voidp;
|
||||
x : uLong;
|
||||
nbByte : int);
|
||||
var
|
||||
buf : pzByteArray;
|
||||
n : int;
|
||||
begin
|
||||
buf := pzByteArray(dest);
|
||||
for n := 0 to nbByte-1 do
|
||||
begin
|
||||
buf^[n] := Bytef(x and $ff);
|
||||
x := x shr 8;
|
||||
end;
|
||||
end;
|
||||
|
||||
{**************************************************************************}
|
||||
|
||||
|
||||
function ziplocal_TmzDateToDosDate(var ptm : tm_zip; dosDate : uLong) : uLong;
|
||||
var
|
||||
year : uLong;
|
||||
begin
|
||||
year := uLong(ptm.tm_year);
|
||||
if (year>1980) then
|
||||
Dec(year, 1980)
|
||||
else
|
||||
if (year>80) then
|
||||
Dec(year, 80);
|
||||
ziplocal_TmzDateToDosDate := uLong (
|
||||
((ptm.tm_mday) + (32 * (ptm.tm_mon+1)) + (512 * year)) shl 16) or
|
||||
((ptm.tm_sec div 2) + (32* ptm.tm_min) + (2048 * uLong(ptm.tm_hour)));
|
||||
end;
|
||||
|
||||
|
||||
{**************************************************************************}
|
||||
|
||||
function zipOpen (const pathname : PChar; append : int) : zipFile; {ZEXPORT}
|
||||
var
|
||||
ziinit : zip_internal;
|
||||
zi : zip_internal_ptr;
|
||||
begin
|
||||
if (append = 0) then
|
||||
ziinit.filezip := fopen(pathname, fopenwrite)
|
||||
else
|
||||
ziinit.filezip := fopen(pathname, fappendwrite);
|
||||
|
||||
if (ziinit.filezip = NIL) then
|
||||
begin
|
||||
zipOpen := NIL;
|
||||
exit;
|
||||
end;
|
||||
ziinit.begin_pos := ftell(ziinit.filezip);
|
||||
ziinit.in_opened_file_inzip := False;
|
||||
ziinit.ci.stream_initialised := False;
|
||||
ziinit.number_entry := 0;
|
||||
init_linkedlist(ziinit.central_dir);
|
||||
|
||||
zi := zip_internal_ptr(ALLOC(sizeof(zip_internal)));
|
||||
if (zi=NIL) then
|
||||
begin
|
||||
fclose(ziinit.filezip);
|
||||
zipOpen := NIL;
|
||||
exit;
|
||||
end;
|
||||
|
||||
zi^ := ziinit;
|
||||
zipOpen := zipFile(zi);
|
||||
end;
|
||||
|
||||
function zipOpenNewFileInZip (afile : zipFile;
|
||||
{const} filename : PChar;
|
||||
const zipfi : zip_fileinfo_ptr;
|
||||
const extrafield_local : voidp;
|
||||
size_extrafield_local : uInt;
|
||||
const extrafield_global : voidp;
|
||||
size_extrafield_global : uInt;
|
||||
const comment : PChar;
|
||||
method : int;
|
||||
level : int) : int; {ZEXPORT}
|
||||
var
|
||||
zi : zip_internal_ptr;
|
||||
size_filename : uInt;
|
||||
size_comment : uInt;
|
||||
i : uInt;
|
||||
err : int;
|
||||
begin
|
||||
err := ZIP_OK;
|
||||
if (afile = NIL) then
|
||||
begin
|
||||
zipOpenNewFileInZip := ZIP_PARAMERROR;
|
||||
exit;
|
||||
end;
|
||||
if ((method<>0) and (method<>Z_DEFLATED)) then
|
||||
begin
|
||||
zipOpenNewFileInZip := ZIP_PARAMERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
zi := zip_internal_ptr(afile);
|
||||
|
||||
if (zi^.in_opened_file_inzip = True) then
|
||||
begin
|
||||
err := zipCloseFileInZip (afile);
|
||||
if (err <> ZIP_OK) then
|
||||
begin
|
||||
zipOpenNewFileInZip := err;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
if (filename=NIL) then
|
||||
filename := '-';
|
||||
|
||||
if (comment=NIL) then
|
||||
size_comment := 0
|
||||
else
|
||||
size_comment := strlen(comment);
|
||||
|
||||
size_filename := strlen(filename);
|
||||
|
||||
if (zipfi = NIL) then
|
||||
zi^.ci.dosDate := 0
|
||||
else
|
||||
begin
|
||||
if (zipfi^.dosDate <> 0) then
|
||||
zi^.ci.dosDate := zipfi^.dosDate
|
||||
else
|
||||
zi^.ci.dosDate := ziplocal_TmzDateToDosDate(zipfi^.tmz_date,zipfi^.dosDate);
|
||||
end;
|
||||
zi^.ci.flag := 0;
|
||||
if ((level=8) or (level=9)) then
|
||||
zi^.ci.flag := zi^.ci.flag or 2;
|
||||
if ((level=2)) then
|
||||
zi^.ci.flag := zi^.ci.flag or 4;
|
||||
if ((level=1)) then
|
||||
zi^.ci.flag := zi^.ci.flag or 6;
|
||||
|
||||
zi^.ci.crc32 := 0;
|
||||
zi^.ci.method := method;
|
||||
zi^.ci.stream_initialised := False;
|
||||
zi^.ci.pos_in_buffered_data := 0;
|
||||
zi^.ci.pos_local_header := ftell(zi^.filezip);
|
||||
zi^.ci.size_centralheader := SIZECENTRALHEADER + size_filename +
|
||||
size_extrafield_global + size_comment;
|
||||
zi^.ci.central_header := PChar( ALLOC( uInt(zi^.ci.size_centralheader)) );
|
||||
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header,uLong(CENTRALHEADERMAGIC),4);
|
||||
{ version info }
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+4,uLong(VERSIONMADEBY),2);
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+6,uLong(20),2);
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+8,uLong(zi^.ci.flag),2);
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+10,uLong(zi^.ci.method),2);
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+12,uLong(zi^.ci.dosDate),4);
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+16,uLong(0),4); {crc}
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+20,uLong(0),4); {compr size}
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+24,uLong(0),4); {uncompr size}
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+28,uLong(size_filename),2);
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+30,uLong(size_extrafield_global),2);
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+32,uLong(size_comment),2);
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+34,uLong(0),2); {disk nm start}
|
||||
|
||||
if (zipfi=NIL) then
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+36,uLong(0),2)
|
||||
else
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+36,uLong(zipfi^.internal_fa),2);
|
||||
|
||||
if (zipfi=NIL) then
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+38,uLong(0),4)
|
||||
else
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+38,uLong(zipfi^.external_fa),4);
|
||||
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+42,uLong(zi^.ci.pos_local_header),4);
|
||||
|
||||
i := 0;
|
||||
while (i < size_filename) do
|
||||
begin
|
||||
(zi^.ci.central_header+SIZECENTRALHEADER+i)^ := (filename+i)^;
|
||||
Inc(i);
|
||||
end;
|
||||
|
||||
i := 0;
|
||||
while (i < size_extrafield_global) do
|
||||
begin
|
||||
(zi^.ci.central_header+SIZECENTRALHEADER+size_filename+i)^ :=
|
||||
({const} PChar(extrafield_global)+i)^;
|
||||
Inc(i);
|
||||
end;
|
||||
|
||||
i:= 0;
|
||||
while (i < size_comment) do
|
||||
begin
|
||||
(zi^.ci.central_header+SIZECENTRALHEADER+size_filename+ size_extrafield_global+i)^ := (filename+i)^;
|
||||
Inc(i);
|
||||
end;
|
||||
if (zi^.ci.central_header = NIL) then
|
||||
begin
|
||||
zipOpenNewFileInZip := ZIP_INTERNALERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ write the local header }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(LOCALHEADERMAGIC),4);
|
||||
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(20),2); { version needed to extract }
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(zi^.ci.flag),2);
|
||||
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(zi^.ci.method),2);
|
||||
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(zi^.ci.dosDate),4);
|
||||
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(0),4); { crc 32, unknown }
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(0),4); { compressed size, unknown }
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(0),4); { uncompressed size, unknown }
|
||||
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(size_filename),2);
|
||||
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(size_extrafield_local),2);
|
||||
|
||||
if ((err=ZIP_OK) and (size_filename>0)) then
|
||||
begin
|
||||
if (fwrite(filename,uInt(size_filename),1,zi^.filezip)<>1) then
|
||||
err := ZIP_ERRNO;
|
||||
end;
|
||||
|
||||
if ((err=ZIP_OK) and (size_extrafield_local>0)) then
|
||||
begin
|
||||
if (fwrite(extrafield_local, uInt(size_extrafield_local),1,zi^.filezip) <>1) then
|
||||
err := ZIP_ERRNO;
|
||||
end;
|
||||
|
||||
zi^.ci.stream.avail_in := uInt(0);
|
||||
zi^.ci.stream.avail_out := uInt(Z_BUFSIZE);
|
||||
zi^.ci.stream.next_out := pBytef(@zi^.ci.buffered_data);
|
||||
zi^.ci.stream.total_in := 0;
|
||||
zi^.ci.stream.total_out := 0;
|
||||
|
||||
if ((err=ZIP_OK) and (zi^.ci.method = Z_DEFLATED)) then
|
||||
begin
|
||||
zi^.ci.stream.zalloc := NIL;
|
||||
zi^.ci.stream.zfree := NIL;
|
||||
zi^.ci.stream.opaque := NIL;
|
||||
|
||||
err := deflateInit2(zi^.ci.stream, level,
|
||||
Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0);
|
||||
|
||||
if (err=Z_OK) then
|
||||
zi^.ci.stream_initialised := True;
|
||||
end;
|
||||
|
||||
if (err=Z_OK) then
|
||||
zi^.in_opened_file_inzip := True;
|
||||
zipOpenNewFileInZip := err;
|
||||
end;
|
||||
|
||||
function zipWriteInFileInZip (afile : zipFile; const buf : voidp; len : unsigned) : int; {ZEXPORT}
|
||||
var
|
||||
zi : zip_internal_ptr;
|
||||
err : int;
|
||||
var
|
||||
uTotalOutBefore : uLong;
|
||||
var
|
||||
copy_this,i : uInt;
|
||||
begin
|
||||
err := ZIP_OK;
|
||||
|
||||
if (afile = NIL) then
|
||||
begin
|
||||
zipWriteInFileInZip := ZIP_PARAMERROR;
|
||||
exit;
|
||||
end;
|
||||
zi := zip_internal_ptr(afile);
|
||||
|
||||
if (zi^.in_opened_file_inzip = False) then
|
||||
begin
|
||||
zipWriteInFileInZip := ZIP_PARAMERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
zi^.ci.stream.next_in := buf;
|
||||
zi^.ci.stream.avail_in := len;
|
||||
zi^.ci.crc32 := crc32(zi^.ci.crc32,buf,len);
|
||||
|
||||
while ((err=ZIP_OK) and (zi^.ci.stream.avail_in>0)) do
|
||||
begin
|
||||
if (zi^.ci.stream.avail_out = 0) then
|
||||
begin
|
||||
if fwrite(@zi^.ci.buffered_data,uInt(zi^.ci.pos_in_buffered_data),1,zi^.filezip)<>1 then
|
||||
err := ZIP_ERRNO;
|
||||
zi^.ci.pos_in_buffered_data := 0;
|
||||
zi^.ci.stream.avail_out := uInt(Z_BUFSIZE);
|
||||
zi^.ci.stream.next_out := pBytef(@zi^.ci.buffered_data);
|
||||
end;
|
||||
|
||||
if (zi^.ci.method = Z_DEFLATED) then
|
||||
begin
|
||||
uTotalOutBefore := zi^.ci.stream.total_out;
|
||||
err := deflate(zi^.ci.stream, Z_NO_FLUSH);
|
||||
Inc(zi^.ci.pos_in_buffered_data, uInt(zi^.ci.stream.total_out - uTotalOutBefore) );
|
||||
end
|
||||
else
|
||||
begin
|
||||
if (zi^.ci.stream.avail_in < zi^.ci.stream.avail_out) then
|
||||
copy_this := zi^.ci.stream.avail_in
|
||||
else
|
||||
copy_this := zi^.ci.stream.avail_out;
|
||||
|
||||
for i := 0 to copy_this-1 do
|
||||
(PChar(zi^.ci.stream.next_out)+i)^ :=
|
||||
( {const} PChar(zi^.ci.stream.next_in) +i)^;
|
||||
|
||||
|
||||
Dec(zi^.ci.stream.avail_in, copy_this);
|
||||
Dec(zi^.ci.stream.avail_out, copy_this);
|
||||
Inc(zi^.ci.stream.next_in, copy_this);
|
||||
Inc(zi^.ci.stream.next_out, copy_this);
|
||||
Inc(zi^.ci.stream.total_in, copy_this);
|
||||
Inc(zi^.ci.stream.total_out, copy_this);
|
||||
Inc(zi^.ci.pos_in_buffered_data, copy_this);
|
||||
end;
|
||||
end;
|
||||
|
||||
zipWriteInFileInZip := 0;
|
||||
end;
|
||||
|
||||
function zipCloseFileInZip (afile : zipFile) : int; {ZEXPORT}
|
||||
var
|
||||
zi : zip_internal_ptr;
|
||||
err : int;
|
||||
var
|
||||
uTotalOutBefore : uLong;
|
||||
var
|
||||
cur_pos_inzip : long;
|
||||
begin
|
||||
err := ZIP_OK;
|
||||
|
||||
if (afile = NIL) then
|
||||
begin
|
||||
zipCloseFileInZip := ZIP_PARAMERROR;
|
||||
exit;
|
||||
end;
|
||||
zi := zip_internal_ptr(afile);
|
||||
|
||||
if (zi^.in_opened_file_inzip = False) then
|
||||
begin
|
||||
zipCloseFileInZip := ZIP_PARAMERROR;
|
||||
exit;
|
||||
end;
|
||||
zi^.ci.stream.avail_in := 0;
|
||||
|
||||
if (zi^.ci.method = Z_DEFLATED) then
|
||||
while (err=ZIP_OK) do
|
||||
begin
|
||||
if (zi^.ci.stream.avail_out = 0) then
|
||||
begin
|
||||
if fwrite(@zi^.ci.buffered_data,uInt(zi^.ci.pos_in_buffered_data),1,zi^.filezip) <>1 then
|
||||
err := ZIP_ERRNO;
|
||||
zi^.ci.pos_in_buffered_data := 0;
|
||||
zi^.ci.stream.avail_out := uInt(Z_BUFSIZE);
|
||||
zi^.ci.stream.next_out := pBytef(@zi^.ci.buffered_data);
|
||||
end;
|
||||
uTotalOutBefore := zi^.ci.stream.total_out;
|
||||
err := deflate(zi^.ci.stream, Z_FINISH);
|
||||
Inc(zi^.ci.pos_in_buffered_data, uInt(zi^.ci.stream.total_out - uTotalOutBefore) );
|
||||
end;
|
||||
|
||||
if (err=Z_STREAM_END) then
|
||||
err := ZIP_OK; { this is normal }
|
||||
|
||||
if (zi^.ci.pos_in_buffered_data>0) and (err=ZIP_OK) then
|
||||
begin
|
||||
if fwrite(@zi^.ci.buffered_data,uInt(zi^.ci.pos_in_buffered_data),1,zi^.filezip) <>1 then
|
||||
err := ZIP_ERRNO;
|
||||
end;
|
||||
|
||||
if ((zi^.ci.method = Z_DEFLATED) and (err=ZIP_OK)) then
|
||||
begin
|
||||
err := deflateEnd(zi^.ci.stream);
|
||||
zi^.ci.stream_initialised := False;
|
||||
end;
|
||||
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+16, uLong(zi^.ci.crc32),4); {crc}
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+20, uLong(zi^.ci.stream.total_out),4); {compr size}
|
||||
ziplocal_putValue_inmemory(zi^.ci.central_header+24, uLong(zi^.ci.stream.total_in),4); {uncompr size}
|
||||
|
||||
if (err=ZIP_OK) then
|
||||
err := add_data_in_datablock(@zi^.central_dir,zi^.ci.central_header, uLong(zi^.ci.size_centralheader));
|
||||
|
||||
TRYFREE(zi^.ci.central_header);
|
||||
|
||||
if (err=ZIP_OK) then
|
||||
begin
|
||||
cur_pos_inzip := ftell(zi^.filezip);
|
||||
if fseek(zi^.filezip, zi^.ci.pos_local_header + 14,SEEK_SET)<>0 then
|
||||
err := ZIP_ERRNO;
|
||||
|
||||
if (err=ZIP_OK) then
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(zi^.ci.crc32),4); { crc 32, unknown }
|
||||
|
||||
if (err=ZIP_OK) then { compressed size, unknown }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(zi^.ci.stream.total_out),4);
|
||||
|
||||
if (err=ZIP_OK) then { uncompressed size, unknown }
|
||||
err := ziplocal_putValue(zi^.filezip,uLong(zi^.ci.stream.total_in),4);
|
||||
|
||||
if fseek(zi^.filezip, cur_pos_inzip,SEEK_SET)<>0 then
|
||||
err := ZIP_ERRNO;
|
||||
end;
|
||||
|
||||
Inc(zi^.number_entry);
|
||||
zi^.in_opened_file_inzip := False;
|
||||
|
||||
zipCloseFileInZip := err;
|
||||
end;
|
||||
|
||||
function zipClose (afile : zipFile;
|
||||
const global_comment : PChar) : int; {ZEXPORT}
|
||||
var
|
||||
zi : zip_internal_ptr;
|
||||
err : int;
|
||||
size_centraldir : uLong;
|
||||
centraldir_pos_inzip : uLong;
|
||||
size_global_comment : uInt;
|
||||
var
|
||||
ldi : linkedlist_datablock_internal_ptr;
|
||||
begin
|
||||
err := 0;
|
||||
size_centraldir := 0;
|
||||
if (afile = NIL) then
|
||||
begin
|
||||
zipClose := ZIP_PARAMERROR;
|
||||
exit;
|
||||
end;
|
||||
zi := zip_internal_ptr(afile);
|
||||
|
||||
if (zi^.in_opened_file_inzip = True) then
|
||||
begin
|
||||
err := zipCloseFileInZip (afile);
|
||||
end;
|
||||
|
||||
if (global_comment=NIL) then
|
||||
size_global_comment := 0
|
||||
else
|
||||
size_global_comment := strlen(global_comment);
|
||||
|
||||
centraldir_pos_inzip := ftell(zi^.filezip);
|
||||
if (err=ZIP_OK) then
|
||||
begin
|
||||
ldi := zi^.central_dir.first_block ;
|
||||
while (ldi<>NIL) do
|
||||
begin
|
||||
if ((err=ZIP_OK) and (ldi^.filled_in_this_block>0)) then
|
||||
begin
|
||||
if fwrite(@ldi^.data,uInt(ldi^.filled_in_this_block), 1,zi^.filezip)<>1 then
|
||||
err := ZIP_ERRNO;
|
||||
end;
|
||||
|
||||
Inc(size_centraldir, ldi^.filled_in_this_block);
|
||||
ldi := ldi^.next_datablock;
|
||||
end;
|
||||
end;
|
||||
free_datablock(zi^.central_dir.first_block);
|
||||
|
||||
if (err=ZIP_OK) then { Magic End }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(ENDHEADERMAGIC),4);
|
||||
|
||||
if (err=ZIP_OK) then { number of this disk }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(0),2);
|
||||
|
||||
if (err=ZIP_OK) then { number of the disk with the start of the central directory }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(0),2);
|
||||
|
||||
if (err=ZIP_OK) then { total number of entries in the central dir on this disk }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(zi^.number_entry),2);
|
||||
|
||||
if (err=ZIP_OK) then { total number of entries in the central dir }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(zi^.number_entry),2);
|
||||
|
||||
if (err=ZIP_OK) then { size of the central directory }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(size_centraldir),4);
|
||||
|
||||
if (err=ZIP_OK) then { offset of start of central directory with respect to the
|
||||
starting disk number }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(centraldir_pos_inzip) ,4);
|
||||
|
||||
if (err=ZIP_OK) then { zipfile comment length }
|
||||
err := ziplocal_putValue(zi^.filezip, uLong(size_global_comment),2);
|
||||
|
||||
if ((err=ZIP_OK) and (size_global_comment>0)) then
|
||||
begin
|
||||
if fwrite(global_comment, uInt(size_global_comment),1,zi^.filezip)<>1 then
|
||||
err := ZIP_ERRNO;
|
||||
end;
|
||||
fclose(zi^.filezip);
|
||||
TRYFREE(zi);
|
||||
|
||||
zipClose := err;
|
||||
end;
|
||||
|
||||
end.
|
||||
331
contrib/fundamentals/ZLib/paszlib/minizip/ZipUtil.pas
Normal file
331
contrib/fundamentals/ZLib/paszlib/minizip/ZipUtil.pas
Normal file
@@ -0,0 +1,331 @@
|
||||
Unit ziputils;
|
||||
|
||||
{ ziputils.pas - IO on .zip files using zlib
|
||||
- definitions, declarations and routines used by both
|
||||
zip.pas and unzip.pas
|
||||
The file IO is implemented here.
|
||||
|
||||
based on work by Gilles Vollant
|
||||
|
||||
March 23th, 2000,
|
||||
Copyright (C) 2000 Jacques Nomssi Nzali }
|
||||
|
||||
interface
|
||||
|
||||
{$undef UseStream}
|
||||
{$ifdef WIN32}
|
||||
{$define Delphi}
|
||||
{$ifdef UseStream}
|
||||
{$define Streams}
|
||||
{$endif}
|
||||
{$endif}
|
||||
|
||||
uses
|
||||
{$ifdef Delphi}
|
||||
classes, SysUtils,
|
||||
{$endif}
|
||||
zutil;
|
||||
|
||||
{ -------------------------------------------------------------- }
|
||||
{$ifdef Streams}
|
||||
type
|
||||
FILEptr = TFileStream;
|
||||
{$else}
|
||||
type
|
||||
FILEptr = ^file;
|
||||
{$endif}
|
||||
type
|
||||
seek_mode = (SEEK_SET, SEEK_CUR, SEEK_END);
|
||||
open_mode = (fopenread, fopenwrite, fappendwrite);
|
||||
|
||||
function fopen(filename : PChar; mode : open_mode) : FILEptr;
|
||||
|
||||
procedure fclose(fp : FILEptr);
|
||||
|
||||
function fseek(fp : FILEptr; recPos : uLong; mode : seek_mode) : int;
|
||||
|
||||
function fread(buf : voidp; recSize : uInt;
|
||||
recCount : uInt; fp : FILEptr) : uInt;
|
||||
|
||||
function fwrite(buf : voidp; recSize : uInt;
|
||||
recCount : uInt; fp : FILEptr) : uInt;
|
||||
|
||||
function ftell(fp : FILEptr) : uLong; { ZIP }
|
||||
|
||||
function feof(fp : FILEptr) : uInt; { MiniZIP }
|
||||
|
||||
{ ------------------------------------------------------------------- }
|
||||
|
||||
type
|
||||
zipFile = voidp;
|
||||
unzFile = voidp;
|
||||
type
|
||||
z_off_t = long;
|
||||
|
||||
{ tm_zip contain date/time info }
|
||||
type
|
||||
tm_zip = record
|
||||
tm_sec : uInt; { seconds after the minute - [0,59] }
|
||||
tm_min : uInt; { minutes after the hour - [0,59] }
|
||||
tm_hour : uInt; { hours since midnight - [0,23] }
|
||||
tm_mday : uInt; { day of the month - [1,31] }
|
||||
tm_mon : uInt; { months since January - [0,11] }
|
||||
tm_year : uInt; { years - [1980..2044] }
|
||||
end;
|
||||
|
||||
tm_unz = tm_zip;
|
||||
|
||||
const
|
||||
Z_BUFSIZE = (16384);
|
||||
Z_MAXFILENAMEINZIP = (256);
|
||||
|
||||
const
|
||||
CENTRALHEADERMAGIC = $02014b50;
|
||||
|
||||
const
|
||||
SIZECENTRALDIRITEM = $2e;
|
||||
SIZEZIPLOCALHEADER = $1e;
|
||||
|
||||
function ALLOC(size : int) : voidp;
|
||||
|
||||
procedure TRYFREE(p : voidp);
|
||||
|
||||
const
|
||||
Paszip_copyright : PChar = ' Paszip Copyright 2000 Jacques Nomssi Nzali ';
|
||||
|
||||
implementation
|
||||
|
||||
function ALLOC(size : int) : voidp;
|
||||
begin
|
||||
ALLOC := zcalloc (NIL, size, 1);
|
||||
end;
|
||||
|
||||
procedure TRYFREE(p : voidp);
|
||||
begin
|
||||
if Assigned(p) then
|
||||
zcfree(NIL, p);
|
||||
end;
|
||||
|
||||
{$ifdef Streams}
|
||||
{ ---------------------------------------------------------------- }
|
||||
|
||||
function fopen(filename : PChar; mode : open_mode) : FILEptr;
|
||||
var
|
||||
fp : FILEptr;
|
||||
begin
|
||||
fp := NIL;
|
||||
try
|
||||
Case mode of
|
||||
fopenread: fp := TFileStream.Create(filename, fmOpenRead);
|
||||
fopenwrite: fp := TFileStream.Create(filename, fmCreate);
|
||||
fappendwrite :
|
||||
begin
|
||||
fp := TFileStream.Create(filename, fmOpenReadWrite);
|
||||
fp.Seek(soFromEnd, 0);
|
||||
end;
|
||||
end;
|
||||
except
|
||||
on EFOpenError do
|
||||
fp := NIL;
|
||||
end;
|
||||
fopen := fp;
|
||||
end;
|
||||
|
||||
procedure fclose(fp : FILEptr);
|
||||
begin
|
||||
fp.Free;
|
||||
end;
|
||||
|
||||
function fread(buf : voidp;
|
||||
recSize : uInt;
|
||||
recCount : uInt;
|
||||
fp : FILEptr) : uInt;
|
||||
var
|
||||
totalSize, readcount : uInt;
|
||||
begin
|
||||
if Assigned(buf) then
|
||||
begin
|
||||
totalSize := recCount * uInt(recSize);
|
||||
readCount := fp.Read(buf^, totalSize);
|
||||
if (readcount <> totalSize) then
|
||||
fread := readcount div recSize
|
||||
else
|
||||
fread := recCount;
|
||||
end
|
||||
else
|
||||
fread := 0;
|
||||
end;
|
||||
|
||||
function fwrite(buf : voidp;
|
||||
recSize : uInt;
|
||||
recCount : uInt;
|
||||
fp : FILEptr) : uInt;
|
||||
var
|
||||
totalSize, written : uInt;
|
||||
begin
|
||||
if Assigned(buf) then
|
||||
begin
|
||||
totalSize := recCount * uInt(recSize);
|
||||
written := fp.Write(buf^, totalSize);
|
||||
if (written <> totalSize) then
|
||||
fwrite := written div recSize
|
||||
else
|
||||
fwrite := recCount;
|
||||
end
|
||||
else
|
||||
fwrite := 0;
|
||||
end;
|
||||
|
||||
function fseek(fp : FILEptr;
|
||||
recPos : uLong;
|
||||
mode : seek_mode) : int;
|
||||
const
|
||||
fsmode : array[seek_mode] of Word
|
||||
= (soFromBeginning, soFromCurrent, soFromEnd);
|
||||
begin
|
||||
fp.Seek(recPos, fsmode[mode]);
|
||||
fseek := 0; { = 0 for success }
|
||||
end;
|
||||
|
||||
function ftell(fp : FILEptr) : uLong;
|
||||
begin
|
||||
ftell := fp.Position;
|
||||
end;
|
||||
|
||||
function feof(fp : FILEptr) : uInt;
|
||||
begin
|
||||
feof := 0;
|
||||
if Assigned(fp) then
|
||||
if fp.Position = fp.Size then
|
||||
feof := 1
|
||||
else
|
||||
feof := 0;
|
||||
end;
|
||||
|
||||
{$else}
|
||||
{ ---------------------------------------------------------------- }
|
||||
|
||||
function fopen(filename : PChar; mode : open_mode) : FILEptr;
|
||||
var
|
||||
fp : FILEptr;
|
||||
OldFileMode : byte;
|
||||
begin
|
||||
fp := NIL;
|
||||
OldFileMode := FileMode;
|
||||
|
||||
GetMem(fp, SizeOf(file));
|
||||
Assign(fp^, filename);
|
||||
{$i-}
|
||||
Case mode of
|
||||
fopenread:
|
||||
begin
|
||||
FileMode := 0;
|
||||
Reset(fp^, 1);
|
||||
end;
|
||||
fopenwrite:
|
||||
begin
|
||||
FileMode := 1;
|
||||
ReWrite(fp^, 1);
|
||||
end;
|
||||
fappendwrite :
|
||||
begin
|
||||
FileMode := 2;
|
||||
Reset(fp^, 1);
|
||||
Seek(fp^, FileSize(fp^));
|
||||
end;
|
||||
end;
|
||||
FileMode := OldFileMode;
|
||||
if IOresult<>0 then
|
||||
begin
|
||||
FreeMem(fp, SizeOf(file));
|
||||
fp := NIL;
|
||||
end;
|
||||
|
||||
fopen := fp;
|
||||
end;
|
||||
|
||||
procedure fclose(fp : FILEptr);
|
||||
begin
|
||||
if Assigned(fp) then
|
||||
begin
|
||||
{$i-}
|
||||
system.close(fp^);
|
||||
if IOresult=0 then;
|
||||
FreeMem(fp, SizeOf(file));
|
||||
end;
|
||||
end;
|
||||
|
||||
function fread(buf : voidp;
|
||||
recSize : uInt;
|
||||
recCount : uInt;
|
||||
fp : FILEptr) : uInt;
|
||||
var
|
||||
totalSize, readcount : uInt;
|
||||
begin
|
||||
if Assigned(buf) then
|
||||
begin
|
||||
totalSize := recCount * uInt(recSize);
|
||||
{$i-}
|
||||
system.BlockRead(fp^, buf^, totalSize, readcount);
|
||||
if (readcount <> totalSize) then
|
||||
fread := readcount div recSize
|
||||
else
|
||||
fread := recCount;
|
||||
end
|
||||
else
|
||||
fread := 0;
|
||||
end;
|
||||
|
||||
function fwrite(buf : voidp;
|
||||
recSize : uInt;
|
||||
recCount : uInt;
|
||||
fp : FILEptr) : uInt;
|
||||
var
|
||||
totalSize, written : uInt;
|
||||
begin
|
||||
if Assigned(buf) then
|
||||
begin
|
||||
totalSize := recCount * uInt(recSize);
|
||||
{$i-}
|
||||
system.BlockWrite(fp^, buf^, totalSize, written);
|
||||
if (written <> totalSize) then
|
||||
fwrite := written div recSize
|
||||
else
|
||||
fwrite := recCount;
|
||||
end
|
||||
else
|
||||
fwrite := 0;
|
||||
end;
|
||||
|
||||
function fseek(fp : FILEptr;
|
||||
recPos : uLong;
|
||||
mode : seek_mode) : int;
|
||||
begin
|
||||
{$i-}
|
||||
case mode of
|
||||
SEEK_SET : system.Seek(fp^, recPos);
|
||||
SEEK_CUR : system.Seek(fp^, FilePos(fp^)+recPos);
|
||||
SEEK_END : system.Seek(fp^, FileSize(fp^)-1-recPos); { ?? check }
|
||||
end;
|
||||
fseek := IOresult; { = 0 for success }
|
||||
end;
|
||||
|
||||
function ftell(fp : FILEptr) : uLong;
|
||||
begin
|
||||
ftell := FilePos(fp^);
|
||||
end;
|
||||
|
||||
function feof(fp : FILEptr) : uInt;
|
||||
begin
|
||||
feof := 0;
|
||||
if Assigned(fp) then
|
||||
if eof(fp^) then
|
||||
feof := 1
|
||||
else
|
||||
feof := 0;
|
||||
end;
|
||||
|
||||
{$endif}
|
||||
{ ---------------------------------------------------------------- }
|
||||
|
||||
end.
|
||||
2252
contrib/fundamentals/ZLib/paszlib/trees.pas
Normal file
2252
contrib/fundamentals/ZLib/paszlib/trees.pas
Normal file
File diff suppressed because it is too large
Load Diff
124
contrib/fundamentals/ZLib/paszlib/zCompres.pas
Normal file
124
contrib/fundamentals/ZLib/paszlib/zCompres.pas
Normal file
@@ -0,0 +1,124 @@
|
||||
Unit zCompres;
|
||||
|
||||
{ compress.c -- compress a memory buffer
|
||||
Copyright (C) 1995-1998 Jean-loup Gailly.
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
uses
|
||||
ZUtil, gZlib, zDeflate;
|
||||
|
||||
{ utility functions }
|
||||
|
||||
{EXPORT}
|
||||
function compress (dest : pBytef;
|
||||
var destLen : uLong;
|
||||
const source : array of Byte;
|
||||
sourceLen : uLong) : int;
|
||||
|
||||
{ Compresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be at least 0.1% larger than
|
||||
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
|
||||
compressed buffer.
|
||||
This function can be used to compress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
compress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer. }
|
||||
|
||||
{EXPORT}
|
||||
function compress2 (dest : pBytef;
|
||||
var destLen : uLong;
|
||||
const source : array of byte;
|
||||
sourceLen : uLong;
|
||||
level : int) : int;
|
||||
{ Compresses the source buffer into the destination buffer. The level
|
||||
parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||
length of the source buffer. Upon entry, destLen is the total size of the
|
||||
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
||||
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
||||
|
||||
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid. }
|
||||
|
||||
implementation
|
||||
|
||||
{ ===========================================================================
|
||||
}
|
||||
function compress2 (dest : pBytef;
|
||||
var destLen : uLong;
|
||||
const source : array of byte;
|
||||
sourceLen : uLong;
|
||||
level : int) : int;
|
||||
var
|
||||
stream : z_stream;
|
||||
err : int;
|
||||
begin
|
||||
stream.next_in := pBytef(@source);
|
||||
stream.avail_in := uInt(sourceLen);
|
||||
{$ifdef MAXSEG_64K}
|
||||
{ Check for source > 64K on 16-bit machine: }
|
||||
if (uLong(stream.avail_in) <> sourceLen) then
|
||||
begin
|
||||
compress2 := Z_BUF_ERROR;
|
||||
exit;
|
||||
end;
|
||||
{$endif}
|
||||
stream.next_out := dest;
|
||||
stream.avail_out := uInt(destLen);
|
||||
if (uLong(stream.avail_out) <> destLen) then
|
||||
begin
|
||||
compress2 := Z_BUF_ERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
stream.zalloc := NIL; { alloc_func(0); }
|
||||
stream.zfree := NIL; { free_func(0); }
|
||||
stream.opaque := NIL; { voidpf(0); }
|
||||
|
||||
err := deflateInit(stream, level);
|
||||
if (err <> Z_OK) then
|
||||
begin
|
||||
compress2 := err;
|
||||
exit;
|
||||
end;
|
||||
|
||||
err := deflate(stream, Z_FINISH);
|
||||
if (err <> Z_STREAM_END) then
|
||||
begin
|
||||
deflateEnd(stream);
|
||||
if err = Z_OK then
|
||||
compress2 := Z_BUF_ERROR
|
||||
else
|
||||
compress2 := err;
|
||||
exit;
|
||||
end;
|
||||
destLen := stream.total_out;
|
||||
|
||||
err := deflateEnd(stream);
|
||||
compress2 := err;
|
||||
end;
|
||||
|
||||
{ ===========================================================================
|
||||
}
|
||||
function compress (dest : pBytef;
|
||||
var destLen : uLong;
|
||||
const source : array of Byte;
|
||||
sourceLen : uLong) : int;
|
||||
begin
|
||||
compress := compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
2144
contrib/fundamentals/ZLib/paszlib/zDeflate.pas
Normal file
2144
contrib/fundamentals/ZLib/paszlib/zDeflate.pas
Normal file
File diff suppressed because it is too large
Load Diff
755
contrib/fundamentals/ZLib/paszlib/zInflate.pas
Normal file
755
contrib/fundamentals/ZLib/paszlib/zInflate.pas
Normal file
@@ -0,0 +1,755 @@
|
||||
Unit zInflate;
|
||||
|
||||
{ inflate.c -- zlib interface to inflate modules
|
||||
Copyright (C) 1995-1998 Mark Adler
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
{.DEFINE ZINFLATE_DEBUG}
|
||||
|
||||
uses
|
||||
ZUtil, gZlib, InfBlock, infutil;
|
||||
|
||||
function inflateInit(var z : z_stream) : int;
|
||||
|
||||
{ Initializes the internal stream state for decompression. The fields
|
||||
zalloc, zfree and opaque must be initialized before by the caller. If
|
||||
zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
|
||||
allocation functions.
|
||||
|
||||
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
|
||||
with the version assumed by the caller. msg is set to null if there is no
|
||||
error message. inflateInit does not perform any decompression: this will be
|
||||
done by inflate(). }
|
||||
|
||||
|
||||
|
||||
function inflateInit_(z : z_streamp;
|
||||
const version : string;
|
||||
stream_size : int) : int;
|
||||
|
||||
|
||||
function inflateInit2_(var z: z_stream;
|
||||
w : int;
|
||||
const version : string;
|
||||
stream_size : int) : int;
|
||||
|
||||
function inflateInit2(var z: z_stream;
|
||||
windowBits : int) : int;
|
||||
|
||||
{
|
||||
This is another version of inflateInit with an extra parameter. The
|
||||
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
|
||||
before by the caller.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the maximum window
|
||||
size (the size of the history buffer). It should be in the range 8..15 for
|
||||
this version of the library. The default value is 15 if inflateInit is used
|
||||
instead. If a compressed stream with a larger window size is given as
|
||||
input, inflate() will return with the error code Z_DATA_ERROR instead of
|
||||
trying to allocate a larger window.
|
||||
|
||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
|
||||
memLevel). msg is set to null if there is no error message. inflateInit2
|
||||
does not perform any decompression apart from reading the zlib header if
|
||||
present: this will be done by inflate(). (So next_in and avail_in may be
|
||||
modified, but next_out and avail_out are unchanged.)
|
||||
}
|
||||
|
||||
|
||||
|
||||
function inflateEnd(var z : z_stream) : int;
|
||||
|
||||
{
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
pending output.
|
||||
|
||||
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
|
||||
was inconsistent. In the error case, msg may be set but then points to a
|
||||
static string (which must not be deallocated).
|
||||
}
|
||||
|
||||
function inflateReset(var z : z_stream) : int;
|
||||
|
||||
{
|
||||
This function is equivalent to inflateEnd followed by inflateInit,
|
||||
but does not free and reallocate all the internal decompression state.
|
||||
The stream will keep attributes that may have been set by inflateInit2.
|
||||
|
||||
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
}
|
||||
|
||||
|
||||
function inflate(var z : z_stream;
|
||||
f : int) : int;
|
||||
{
|
||||
inflate decompresses as much data as possible, and stops when the input
|
||||
buffer becomes empty or the output buffer becomes full. It may introduce
|
||||
some output latency (reading input without producing any output)
|
||||
except when forced to flush.
|
||||
|
||||
The detailed semantics are as follows. inflate performs one or both of the
|
||||
following actions:
|
||||
|
||||
- Decompress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
enough room in the output buffer), next_in is updated and processing
|
||||
will resume at this point for the next call of inflate().
|
||||
|
||||
- Provide more output starting at next_out and update next_out and avail_out
|
||||
accordingly. inflate() provides as much output as possible, until there
|
||||
is no more input data or no more space in the output buffer (see below
|
||||
about the flush parameter).
|
||||
|
||||
Before the call of inflate(), the application should ensure that at least
|
||||
one of the actions is possible, by providing more input and/or consuming
|
||||
more output, and updating the next_* and avail_* values accordingly.
|
||||
The application can consume the uncompressed output when it wants, for
|
||||
example when the output buffer is full (avail_out == 0), or after each
|
||||
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
|
||||
must be called again after making room in the output buffer because there
|
||||
might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
|
||||
output as possible to the output buffer. The flushing behavior of inflate is
|
||||
not specified for values of the flush parameter other than Z_SYNC_FLUSH
|
||||
and Z_FINISH, but the current implementation actually flushes as much output
|
||||
as possible anyway.
|
||||
|
||||
inflate() should normally be called until it returns Z_STREAM_END or an
|
||||
error. However if all decompression is to be performed in a single step
|
||||
(a single call of inflate), the parameter flush should be set to
|
||||
Z_FINISH. In this case all pending input is processed and all pending
|
||||
output is flushed; avail_out must be large enough to hold all the
|
||||
uncompressed data. (The size of the uncompressed data may have been saved
|
||||
by the compressor for this purpose.) The next operation on this stream must
|
||||
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
|
||||
is never required, but can be used to inform inflate that a faster routine
|
||||
may be used for the single inflate() call.
|
||||
|
||||
If a preset dictionary is needed at this point (see inflateSetDictionary
|
||||
below), inflate sets strm-adler to the adler32 checksum of the
|
||||
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
|
||||
it sets strm->adler to the adler32 checksum of all output produced
|
||||
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
|
||||
an error code as described below. At the end of the stream, inflate()
|
||||
checks that its computed adler32 checksum is equal to that saved by the
|
||||
compressor and returns Z_STREAM_END only if the checksum is correct.
|
||||
|
||||
inflate() returns Z_OK if some progress has been made (more input processed
|
||||
or more output produced), Z_STREAM_END if the end of the compressed data has
|
||||
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
|
||||
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
|
||||
corrupted (input stream not conforming to the zlib format or incorrect
|
||||
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
|
||||
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
|
||||
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
|
||||
case, the application may then call inflateSync to look for a good
|
||||
compression block.
|
||||
}
|
||||
|
||||
|
||||
function inflateSetDictionary(var z : z_stream;
|
||||
dictionary : pBytef; {const array of byte}
|
||||
dictLength : uInt) : int;
|
||||
|
||||
{
|
||||
Initializes the decompression dictionary from the given uncompressed byte
|
||||
sequence. This function must be called immediately after a call of inflate
|
||||
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||
can be determined from the Adler32 value returned by this call of
|
||||
inflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see deflateSetDictionary).
|
||||
|
||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
|
||||
expected one (incorrect Adler32 value). inflateSetDictionary does not
|
||||
perform any decompression: this will be done by subsequent calls of
|
||||
inflate().
|
||||
}
|
||||
|
||||
function inflateSync(var z : z_stream) : int;
|
||||
|
||||
{
|
||||
Skips invalid compressed data until a full flush point (see above the
|
||||
description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
available input is skipped. No output is provided.
|
||||
|
||||
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
|
||||
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
|
||||
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
|
||||
case, the application may save the current current value of total_in which
|
||||
indicates where valid compressed data was found. In the error case, the
|
||||
application may repeatedly call inflateSync, providing more input each time,
|
||||
until success or end of the input data.
|
||||
}
|
||||
|
||||
|
||||
function inflateSyncPoint(var z : z_stream) : int;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
adler;
|
||||
|
||||
function inflateReset(var z : z_stream) : int;
|
||||
begin
|
||||
if (z.state = Z_NULL) then
|
||||
begin
|
||||
inflateReset := Z_STREAM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
z.total_out := 0;
|
||||
z.total_in := 0;
|
||||
z.msg := '';
|
||||
if z.state^.nowrap then
|
||||
z.state^.mode := BLOCKS
|
||||
else
|
||||
z.state^.mode := METHOD;
|
||||
inflate_blocks_reset(z.state^.blocks^, z, Z_NULL);
|
||||
{$IFDEF ZINFLATE_DEBUG}
|
||||
Tracev('inflate: reset');
|
||||
{$ENDIF}
|
||||
inflateReset := Z_OK;
|
||||
end;
|
||||
|
||||
|
||||
function inflateEnd(var z : z_stream) : int;
|
||||
begin
|
||||
if (z.state = Z_NULL) or not Assigned(z.zfree) then
|
||||
begin
|
||||
inflateEnd := Z_STREAM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
if (z.state^.blocks <> Z_NULL) then
|
||||
inflate_blocks_free(z.state^.blocks, z);
|
||||
ZFREE(z, z.state);
|
||||
z.state := Z_NULL;
|
||||
{$IFDEF ZINFLATE_DEBUG}
|
||||
Tracev('inflate: end');
|
||||
{$ENDIF}
|
||||
inflateEnd := Z_OK;
|
||||
end;
|
||||
|
||||
|
||||
function inflateInit2_(var z: z_stream;
|
||||
w : int;
|
||||
const version : string;
|
||||
stream_size : int) : int;
|
||||
begin
|
||||
if (version = '') or (version[1] <> ZLIB_VERSION[1]) or
|
||||
(stream_size <> sizeof(z_stream)) then
|
||||
begin
|
||||
inflateInit2_ := Z_VERSION_ERROR;
|
||||
exit;
|
||||
end;
|
||||
{ initialize state }
|
||||
{ SetLength(strm.msg, 255); }
|
||||
z.msg := '';
|
||||
if not Assigned(z.zalloc) then
|
||||
begin
|
||||
{$IFDEF FPC} z.zalloc := @zcalloc; {$ELSE}
|
||||
z.zalloc := zcalloc;
|
||||
{$endif}
|
||||
z.opaque := voidpf(0);
|
||||
end;
|
||||
if not Assigned(z.zfree) then
|
||||
{$IFDEF FPC} z.zfree := @zcfree; {$ELSE}
|
||||
z.zfree := zcfree;
|
||||
{$ENDIF}
|
||||
|
||||
z.state := pInternal_state( ZALLOC(z,1,sizeof(internal_state)) );
|
||||
if (z.state = Z_NULL) then
|
||||
begin
|
||||
inflateInit2_ := Z_MEM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
z.state^.blocks := Z_NULL;
|
||||
|
||||
{ handle undocumented nowrap option (no zlib header or check) }
|
||||
z.state^.nowrap := FALSE;
|
||||
if (w < 0) then
|
||||
begin
|
||||
w := - w;
|
||||
z.state^.nowrap := TRUE;
|
||||
end;
|
||||
|
||||
{ set window size }
|
||||
if (w < 8) or (w > 15) then
|
||||
begin
|
||||
inflateEnd(z);
|
||||
inflateInit2_ := Z_STREAM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
z.state^.wbits := uInt(w);
|
||||
|
||||
{ create inflate_blocks state }
|
||||
if z.state^.nowrap then
|
||||
z.state^.blocks := inflate_blocks_new(z, NIL, uInt(1) shl w)
|
||||
else
|
||||
{$IFDEF FPC}
|
||||
z.state^.blocks := inflate_blocks_new(z, @adler32, uInt(1) shl w);
|
||||
{$ELSE}
|
||||
z.state^.blocks := inflate_blocks_new(z, adler32, uInt(1) shl w);
|
||||
{$ENDIF}
|
||||
if (z.state^.blocks = Z_NULL) then
|
||||
begin
|
||||
inflateEnd(z);
|
||||
inflateInit2_ := Z_MEM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
{$IFDEF ZINFLATE_DEBUG}
|
||||
Tracev('inflate: allocated');
|
||||
{$ENDIF}
|
||||
{ reset state }
|
||||
inflateReset(z);
|
||||
inflateInit2_ := Z_OK;
|
||||
end;
|
||||
|
||||
function inflateInit2(var z: z_stream; windowBits : int) : int;
|
||||
begin
|
||||
inflateInit2 := inflateInit2_(z, windowBits, ZLIB_VERSION, sizeof(z_stream));
|
||||
end;
|
||||
|
||||
|
||||
function inflateInit(var z : z_stream) : int;
|
||||
{ inflateInit is a macro to allow checking the zlib version
|
||||
and the compiler's view of z_stream: }
|
||||
begin
|
||||
inflateInit := inflateInit2_(z, DEF_WBITS, ZLIB_VERSION, sizeof(z_stream));
|
||||
end;
|
||||
|
||||
function inflateInit_(z : z_streamp;
|
||||
const version : string;
|
||||
stream_size : int) : int;
|
||||
begin
|
||||
{ initialize state }
|
||||
if (z = Z_NULL) then
|
||||
inflateInit_ := Z_STREAM_ERROR
|
||||
else
|
||||
inflateInit_ := inflateInit2_(z^, DEF_WBITS, version, stream_size);
|
||||
end;
|
||||
|
||||
function inflate(var z : z_stream;
|
||||
f : int) : int;
|
||||
var
|
||||
r : int;
|
||||
b : uInt;
|
||||
begin
|
||||
if (z.state = Z_NULL) or (z.next_in = Z_NULL) then
|
||||
begin
|
||||
inflate := Z_STREAM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
if f = Z_FINISH then
|
||||
f := Z_BUF_ERROR
|
||||
else
|
||||
f := Z_OK;
|
||||
r := Z_BUF_ERROR;
|
||||
while True do
|
||||
case (z.state^.mode) of
|
||||
BLOCKS:
|
||||
begin
|
||||
r := inflate_blocks(z.state^.blocks^, z, r);
|
||||
if (r = Z_DATA_ERROR) then
|
||||
begin
|
||||
z.state^.mode := BAD;
|
||||
z.state^.sub.marker := 0; { can try inflateSync }
|
||||
continue; { break C-switch }
|
||||
end;
|
||||
if (r = Z_OK) then
|
||||
r := f;
|
||||
if (r <> Z_STREAM_END) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f;
|
||||
inflate_blocks_reset(z.state^.blocks^, z, @z.state^.sub.check.was);
|
||||
if (z.state^.nowrap) then
|
||||
begin
|
||||
z.state^.mode := DONE;
|
||||
continue; { break C-switch }
|
||||
end;
|
||||
z.state^.mode := CHECK4; { falltrough }
|
||||
end;
|
||||
CHECK4:
|
||||
begin
|
||||
{NEEDBYTE}
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f;
|
||||
|
||||
{z.state^.sub.check.need := uLong(NEXTBYTE(z)) shl 24;}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
z.state^.sub.check.need := uLong(z.next_in^) shl 24;
|
||||
Inc(z.next_in);
|
||||
|
||||
z.state^.mode := CHECK3; { falltrough }
|
||||
end;
|
||||
CHECK3:
|
||||
begin
|
||||
{NEEDBYTE}
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f;
|
||||
{Inc( z.state^.sub.check.need, uLong(NEXTBYTE(z)) shl 16);}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
Inc(z.state^.sub.check.need, uLong(z.next_in^) shl 16);
|
||||
Inc(z.next_in);
|
||||
|
||||
z.state^.mode := CHECK2; { falltrough }
|
||||
end;
|
||||
CHECK2:
|
||||
begin
|
||||
{NEEDBYTE}
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f;
|
||||
|
||||
{Inc( z.state^.sub.check.need, uLong(NEXTBYTE(z)) shl 8);}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
Inc(z.state^.sub.check.need, uLong(z.next_in^) shl 8);
|
||||
Inc(z.next_in);
|
||||
|
||||
z.state^.mode := CHECK1; { falltrough }
|
||||
end;
|
||||
CHECK1:
|
||||
begin
|
||||
{NEEDBYTE}
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f;
|
||||
{Inc( z.state^.sub.check.need, uLong(NEXTBYTE(z)) );}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
Inc(z.state^.sub.check.need, uLong(z.next_in^) );
|
||||
Inc(z.next_in);
|
||||
|
||||
|
||||
if (z.state^.sub.check.was <> z.state^.sub.check.need) then
|
||||
begin
|
||||
z.state^.mode := BAD;
|
||||
z.msg := 'incorrect data check';
|
||||
z.state^.sub.marker := 5; { can't try inflateSync }
|
||||
continue; { break C-switch }
|
||||
end;
|
||||
{$IFDEF ZINFLATE_DEBUG}
|
||||
Tracev('inflate: zlib check ok');
|
||||
{$ENDIF}
|
||||
z.state^.mode := DONE; { falltrough }
|
||||
end;
|
||||
DONE:
|
||||
begin
|
||||
inflate := Z_STREAM_END;
|
||||
exit;
|
||||
end;
|
||||
METHOD:
|
||||
begin
|
||||
{NEEDBYTE}
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f; {}
|
||||
|
||||
{z.state^.sub.method := NEXTBYTE(z);}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
z.state^.sub.method := z.next_in^;
|
||||
Inc(z.next_in);
|
||||
|
||||
if ((z.state^.sub.method and $0f) <> Z_DEFLATED) then
|
||||
begin
|
||||
z.state^.mode := BAD;
|
||||
z.msg := 'unknown compression method';
|
||||
z.state^.sub.marker := 5; { can't try inflateSync }
|
||||
continue; { break C-switch }
|
||||
end;
|
||||
if ((z.state^.sub.method shr 4) + 8 > z.state^.wbits) then
|
||||
begin
|
||||
z.state^.mode := BAD;
|
||||
z.msg := 'invalid window size';
|
||||
z.state^.sub.marker := 5; { can't try inflateSync }
|
||||
continue; { break C-switch }
|
||||
end;
|
||||
z.state^.mode := FLAG;
|
||||
{ fall trough }
|
||||
end;
|
||||
FLAG:
|
||||
begin
|
||||
{NEEDBYTE}
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f; {}
|
||||
{b := NEXTBYTE(z);}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
b := z.next_in^;
|
||||
Inc(z.next_in);
|
||||
|
||||
if (((z.state^.sub.method shl 8) + b) mod 31) <> 0 then {% mod ?}
|
||||
begin
|
||||
z.state^.mode := BAD;
|
||||
z.msg := 'incorrect header check';
|
||||
z.state^.sub.marker := 5; { can't try inflateSync }
|
||||
continue; { break C-switch }
|
||||
end;
|
||||
{$IFDEF ZINFLATE_DEBUG}
|
||||
Tracev('inflate: zlib header ok');
|
||||
{$ENDIF}
|
||||
if ((b and PRESET_DICT) = 0) then
|
||||
begin
|
||||
z.state^.mode := BLOCKS;
|
||||
continue; { break C-switch }
|
||||
end;
|
||||
z.state^.mode := DICT4;
|
||||
{ falltrough }
|
||||
end;
|
||||
DICT4:
|
||||
begin
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f;
|
||||
|
||||
{z.state^.sub.check.need := uLong(NEXTBYTE(z)) shl 24;}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
z.state^.sub.check.need := uLong(z.next_in^) shl 24;
|
||||
Inc(z.next_in);
|
||||
|
||||
z.state^.mode := DICT3; { falltrough }
|
||||
end;
|
||||
DICT3:
|
||||
begin
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f;
|
||||
{Inc(z.state^.sub.check.need, uLong(NEXTBYTE(z)) shl 16);}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
Inc(z.state^.sub.check.need, uLong(z.next_in^) shl 16);
|
||||
Inc(z.next_in);
|
||||
|
||||
z.state^.mode := DICT2; { falltrough }
|
||||
end;
|
||||
DICT2:
|
||||
begin
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
r := f;
|
||||
|
||||
{Inc(z.state^.sub.check.need, uLong(NEXTBYTE(z)) shl 8);}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
Inc(z.state^.sub.check.need, uLong(z.next_in^) shl 8);
|
||||
Inc(z.next_in);
|
||||
|
||||
z.state^.mode := DICT1; { falltrough }
|
||||
end;
|
||||
DICT1:
|
||||
begin
|
||||
if (z.avail_in = 0) then
|
||||
begin
|
||||
inflate := r;
|
||||
exit;
|
||||
end;
|
||||
{ r := f; --- wird niemals benutzt }
|
||||
{Inc(z.state^.sub.check.need, uLong(NEXTBYTE(z)) );}
|
||||
Dec(z.avail_in);
|
||||
Inc(z.total_in);
|
||||
Inc(z.state^.sub.check.need, uLong(z.next_in^) );
|
||||
Inc(z.next_in);
|
||||
|
||||
z.adler := z.state^.sub.check.need;
|
||||
z.state^.mode := DICT0;
|
||||
inflate := Z_NEED_DICT;
|
||||
exit;
|
||||
end;
|
||||
DICT0:
|
||||
begin
|
||||
z.state^.mode := BAD;
|
||||
z.msg := 'need dictionary';
|
||||
z.state^.sub.marker := 0; { can try inflateSync }
|
||||
inflate := Z_STREAM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
BAD:
|
||||
begin
|
||||
inflate := Z_DATA_ERROR;
|
||||
exit;
|
||||
end;
|
||||
else
|
||||
begin
|
||||
inflate := Z_STREAM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
{$ifdef NEED_DUMMY_result}
|
||||
result := Z_STREAM_ERROR; { Some dumb compilers complain without this }
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
function inflateSetDictionary(var z : z_stream;
|
||||
dictionary : pBytef; {const array of byte}
|
||||
dictLength : uInt) : int;
|
||||
var
|
||||
length : uInt;
|
||||
begin
|
||||
length := dictLength;
|
||||
|
||||
if (z.state = Z_NULL) or (z.state^.mode <> DICT0) then
|
||||
begin
|
||||
inflateSetDictionary := Z_STREAM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
if (adler32(Long(1), dictionary, dictLength) <> z.adler) then
|
||||
begin
|
||||
inflateSetDictionary := Z_DATA_ERROR;
|
||||
exit;
|
||||
end;
|
||||
z.adler := Long(1);
|
||||
|
||||
if (length >= (uInt(1) shl z.state^.wbits)) then
|
||||
begin
|
||||
length := (1 shl z.state^.wbits)-1;
|
||||
Inc( dictionary, dictLength - length);
|
||||
end;
|
||||
inflate_set_dictionary(z.state^.blocks^, dictionary^, length);
|
||||
z.state^.mode := BLOCKS;
|
||||
inflateSetDictionary := Z_OK;
|
||||
end;
|
||||
|
||||
|
||||
function inflateSync(var z : z_stream) : int;
|
||||
const
|
||||
mark : packed array[0..3] of byte = (0, 0, $ff, $ff);
|
||||
var
|
||||
n : uInt; { number of bytes to look at }
|
||||
p : pBytef; { pointer to bytes }
|
||||
m : uInt; { number of marker bytes found in a row }
|
||||
r, w : uLong; { temporaries to save total_in and total_out }
|
||||
begin
|
||||
{ set up }
|
||||
if (z.state = Z_NULL) then
|
||||
begin
|
||||
inflateSync := Z_STREAM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
if (z.state^.mode <> BAD) then
|
||||
begin
|
||||
z.state^.mode := BAD;
|
||||
z.state^.sub.marker := 0;
|
||||
end;
|
||||
n := z.avail_in;
|
||||
if (n = 0) then
|
||||
begin
|
||||
inflateSync := Z_BUF_ERROR;
|
||||
exit;
|
||||
end;
|
||||
p := z.next_in;
|
||||
m := z.state^.sub.marker;
|
||||
|
||||
{ search }
|
||||
while (n <> 0) and (m < 4) do
|
||||
begin
|
||||
if (p^ = mark[m]) then
|
||||
Inc(m)
|
||||
else
|
||||
if (p^ <> 0) then
|
||||
m := 0
|
||||
else
|
||||
m := 4 - m;
|
||||
Inc(p);
|
||||
Dec(n);
|
||||
end;
|
||||
|
||||
{ restore }
|
||||
Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
|
||||
z.next_in := p;
|
||||
z.avail_in := n;
|
||||
z.state^.sub.marker := m;
|
||||
|
||||
|
||||
{ return no joy or set up to restart on a new block }
|
||||
if (m <> 4) then
|
||||
begin
|
||||
inflateSync := Z_DATA_ERROR;
|
||||
exit;
|
||||
end;
|
||||
r := z.total_in;
|
||||
w := z.total_out;
|
||||
inflateReset(z);
|
||||
z.total_in := r;
|
||||
z.total_out := w;
|
||||
z.state^.mode := BLOCKS;
|
||||
inflateSync := Z_OK;
|
||||
end;
|
||||
|
||||
|
||||
{
|
||||
returns true if inflate is currently at the end of a block generated
|
||||
by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
|
||||
implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
|
||||
but removes the length bytes of the resulting empty stored block. When
|
||||
decompressing, PPP checks that at the end of input packet, inflate is
|
||||
waiting for these length bytes.
|
||||
}
|
||||
|
||||
function inflateSyncPoint(var z : z_stream) : int;
|
||||
begin
|
||||
if (z.state = Z_NULL) or (z.state^.blocks = Z_NULL) then
|
||||
begin
|
||||
inflateSyncPoint := Z_STREAM_ERROR;
|
||||
exit;
|
||||
end;
|
||||
inflateSyncPoint := inflate_blocks_sync_point(z.state^.blocks^);
|
||||
end;
|
||||
|
||||
end.
|
||||
94
contrib/fundamentals/ZLib/paszlib/zUnCompr.pas
Normal file
94
contrib/fundamentals/ZLib/paszlib/zUnCompr.pas
Normal file
@@ -0,0 +1,94 @@
|
||||
Unit zUnCompr;
|
||||
{ uncompr.c -- decompress a memory buffer
|
||||
Copyright (C) 1995-1998 Jean-loup Gailly.
|
||||
|
||||
Pascal tranlastion
|
||||
Copyright (C) 1998 by Jacques Nomssi Nzali
|
||||
For conditions of distribution and use, see copyright notice in readme.txt
|
||||
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
interface
|
||||
|
||||
{$I zconf.inc}
|
||||
|
||||
uses
|
||||
zutil, gzlib, zInflate;
|
||||
|
||||
{ ===========================================================================
|
||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be large enough to hold the
|
||||
entire uncompressed data. (The size of the uncompressed data must have
|
||||
been saved previously by the compressor and transmitted to the decompressor
|
||||
by some mechanism outside the scope of this compression library.)
|
||||
Upon exit, destLen is the actual size of the compressed buffer.
|
||||
This function can be used to decompress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
|
||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||
}
|
||||
|
||||
function uncompress (dest : pBytef;
|
||||
var destLen : uLong;
|
||||
const source : array of byte;
|
||||
sourceLen : uLong) : int;
|
||||
|
||||
implementation
|
||||
|
||||
function uncompress (dest : pBytef;
|
||||
var destLen : uLong;
|
||||
const source : array of byte;
|
||||
sourceLen : uLong) : int;
|
||||
var
|
||||
stream : z_stream;
|
||||
err : int;
|
||||
begin
|
||||
stream.next_in := pBytef(@source);
|
||||
stream.avail_in := uInt(sourceLen);
|
||||
{ Check for source > 64K on 16-bit machine: }
|
||||
if (uLong(stream.avail_in) <> sourceLen) then
|
||||
begin
|
||||
uncompress := Z_BUF_ERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
stream.next_out := dest;
|
||||
stream.avail_out := uInt(destLen);
|
||||
if (uLong(stream.avail_out) <> destLen) then
|
||||
begin
|
||||
uncompress := Z_BUF_ERROR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
stream.zalloc := NIL; { alloc_func(0); }
|
||||
stream.zfree := NIL; { free_func(0); }
|
||||
|
||||
err := inflateInit(stream);
|
||||
if (err <> Z_OK) then
|
||||
begin
|
||||
uncompress := err;
|
||||
exit;
|
||||
end;
|
||||
|
||||
err := inflate(stream, Z_FINISH);
|
||||
if (err <> Z_STREAM_END) then
|
||||
begin
|
||||
inflateEnd(stream);
|
||||
if err = Z_OK then
|
||||
uncompress := Z_BUF_ERROR
|
||||
else
|
||||
uncompress := err;
|
||||
exit;
|
||||
end;
|
||||
destLen := stream.total_out;
|
||||
|
||||
err := inflateEnd(stream);
|
||||
uncompress := err;
|
||||
end;
|
||||
|
||||
end.
|
||||
36
contrib/fundamentals/ZLib/paszlib/zconf.inc
Normal file
36
contrib/fundamentals/ZLib/paszlib/zconf.inc
Normal file
@@ -0,0 +1,36 @@
|
||||
{ -------------------------------------------------------------------- }
|
||||
|
||||
{
|
||||
Modified 04/2015 by David J Butler for inclusion in Fundamentals library.
|
||||
}
|
||||
|
||||
{$INCLUDE ..\..\flcInclude.inc}
|
||||
|
||||
{ -------------------------------------------------------------------- }
|
||||
|
||||
{
|
||||
Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility.
|
||||
See README in directory above for more information.
|
||||
}
|
||||
|
||||
|
||||
{$DEFINE X32}
|
||||
{$DEFINE Delphi32}
|
||||
{$DEFINE Delphi}
|
||||
{$DEFINE Kylix}
|
||||
|
||||
{$WARN UNSAFE_CODE OFF}
|
||||
{$WARN UNSAFE_TYPE OFF}
|
||||
|
||||
{$DEFINE MAX_MATCH_IS_258}
|
||||
|
||||
{$IFNDEF X32}
|
||||
{$DEFINE UNALIGNED_OK} { requires SizeOf(ush) = 2 ! }
|
||||
{$ENDIF}
|
||||
|
||||
{$UNDEF DYNAMIC_CRC_TABLE}
|
||||
{$UNDEF FASTEST}
|
||||
{$DEFINE patch112} { apply patch from the zlib home page }
|
||||
|
||||
{ -------------------------------------------------------------------- }
|
||||
|
||||
1
contrib/fundamentals/ZLib/zlib123/Compile.bat
Normal file
1
contrib/fundamentals/ZLib/zlib123/Compile.bat
Normal file
@@ -0,0 +1 @@
|
||||
bcc32 -c -6 -O2 -Ve -X -pr -a8 -b -d -k- -vi -tWM -r -RT- -ff *.c
|
||||
149
contrib/fundamentals/ZLib/zlib123/adler32.c
Normal file
149
contrib/fundamentals/ZLib/zlib123/adler32.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
* Copyright (C) 1995-2004 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
|
||||
#define BASE 65521UL /* largest prime smaller than 65536 */
|
||||
#define NMAX 5552
|
||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
|
||||
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
|
||||
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||
|
||||
/* use NO_DIVIDE if your processor does not do division in hardware */
|
||||
#ifdef NO_DIVIDE
|
||||
# define MOD(a) \
|
||||
do { \
|
||||
if (a >= (BASE << 16)) a -= (BASE << 16); \
|
||||
if (a >= (BASE << 15)) a -= (BASE << 15); \
|
||||
if (a >= (BASE << 14)) a -= (BASE << 14); \
|
||||
if (a >= (BASE << 13)) a -= (BASE << 13); \
|
||||
if (a >= (BASE << 12)) a -= (BASE << 12); \
|
||||
if (a >= (BASE << 11)) a -= (BASE << 11); \
|
||||
if (a >= (BASE << 10)) a -= (BASE << 10); \
|
||||
if (a >= (BASE << 9)) a -= (BASE << 9); \
|
||||
if (a >= (BASE << 8)) a -= (BASE << 8); \
|
||||
if (a >= (BASE << 7)) a -= (BASE << 7); \
|
||||
if (a >= (BASE << 6)) a -= (BASE << 6); \
|
||||
if (a >= (BASE << 5)) a -= (BASE << 5); \
|
||||
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
||||
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
||||
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
||||
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
||||
if (a >= BASE) a -= BASE; \
|
||||
} while (0)
|
||||
# define MOD4(a) \
|
||||
do { \
|
||||
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
||||
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
||||
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
||||
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
||||
if (a >= BASE) a -= BASE; \
|
||||
} while (0)
|
||||
#else
|
||||
# define MOD(a) a %= BASE
|
||||
# define MOD4(a) a %= BASE
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32(adler, buf, len)
|
||||
uLong adler;
|
||||
const Bytef *buf;
|
||||
uInt len;
|
||||
{
|
||||
unsigned long sum2;
|
||||
unsigned n;
|
||||
|
||||
/* split Adler-32 into component sums */
|
||||
sum2 = (adler >> 16) & 0xffff;
|
||||
adler &= 0xffff;
|
||||
|
||||
/* in case user likes doing a byte at a time, keep it fast */
|
||||
if (len == 1) {
|
||||
adler += buf[0];
|
||||
if (adler >= BASE)
|
||||
adler -= BASE;
|
||||
sum2 += adler;
|
||||
if (sum2 >= BASE)
|
||||
sum2 -= BASE;
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* initial Adler-32 value (deferred check for len == 1 speed) */
|
||||
if (buf == Z_NULL)
|
||||
return 1L;
|
||||
|
||||
/* in case short lengths are provided, keep it somewhat fast */
|
||||
if (len < 16) {
|
||||
while (len--) {
|
||||
adler += *buf++;
|
||||
sum2 += adler;
|
||||
}
|
||||
if (adler >= BASE)
|
||||
adler -= BASE;
|
||||
MOD4(sum2); /* only added so many BASE's */
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* do length NMAX blocks -- requires just one modulo operation */
|
||||
while (len >= NMAX) {
|
||||
len -= NMAX;
|
||||
n = NMAX / 16; /* NMAX is divisible by 16 */
|
||||
do {
|
||||
DO16(buf); /* 16 sums unrolled */
|
||||
buf += 16;
|
||||
} while (--n);
|
||||
MOD(adler);
|
||||
MOD(sum2);
|
||||
}
|
||||
|
||||
/* do remaining bytes (less than NMAX, still just one modulo) */
|
||||
if (len) { /* avoid modulos if none remaining */
|
||||
while (len >= 16) {
|
||||
len -= 16;
|
||||
DO16(buf);
|
||||
buf += 16;
|
||||
}
|
||||
while (len--) {
|
||||
adler += *buf++;
|
||||
sum2 += adler;
|
||||
}
|
||||
MOD(adler);
|
||||
MOD(sum2);
|
||||
}
|
||||
|
||||
/* return recombined sums */
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off_t len2;
|
||||
{
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
unsigned rem;
|
||||
|
||||
/* the derivation of this formula is left as an exercise for the reader */
|
||||
rem = (unsigned)(len2 % BASE);
|
||||
sum1 = adler1 & 0xffff;
|
||||
sum2 = rem * sum1;
|
||||
MOD(sum2);
|
||||
sum1 += (adler2 & 0xffff) + BASE - 1;
|
||||
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
||||
if (sum1 > BASE) sum1 -= BASE;
|
||||
if (sum1 > BASE) sum1 -= BASE;
|
||||
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
|
||||
if (sum2 > BASE) sum2 -= BASE;
|
||||
return sum1 | (sum2 << 16);
|
||||
}
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/adler32.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/adler32.obj
Normal file
Binary file not shown.
79
contrib/fundamentals/ZLib/zlib123/compress.c
Normal file
79
contrib/fundamentals/ZLib/zlib123/compress.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/* compress.c -- compress a memory buffer
|
||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
|
||||
/* ===========================================================================
|
||||
Compresses the source buffer into the destination buffer. The level
|
||||
parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||
length of the source buffer. Upon entry, destLen is the total size of the
|
||||
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
||||
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
||||
|
||||
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
int level;
|
||||
{
|
||||
z_stream stream;
|
||||
int err;
|
||||
|
||||
stream.next_in = (Bytef*)source;
|
||||
stream.avail_in = (uInt)sourceLen;
|
||||
#ifdef MAXSEG_64K
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
|
||||
#endif
|
||||
stream.next_out = dest;
|
||||
stream.avail_out = (uInt)*destLen;
|
||||
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
|
||||
|
||||
stream.zalloc = (alloc_func)0;
|
||||
stream.zfree = (free_func)0;
|
||||
stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&stream, level);
|
||||
if (err != Z_OK) return err;
|
||||
|
||||
err = deflate(&stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
deflateEnd(&stream);
|
||||
return err == Z_OK ? Z_BUF_ERROR : err;
|
||||
}
|
||||
*destLen = stream.total_out;
|
||||
|
||||
err = deflateEnd(&stream);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
int ZEXPORT compress (dest, destLen, source, sourceLen)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
{
|
||||
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
If the default memLevel or windowBits for deflateInit() is changed, then
|
||||
this function needs to be updated.
|
||||
*/
|
||||
uLong ZEXPORT compressBound (sourceLen)
|
||||
uLong sourceLen;
|
||||
{
|
||||
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
|
||||
}
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/compress.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/compress.obj
Normal file
Binary file not shown.
423
contrib/fundamentals/ZLib/zlib123/crc32.c
Normal file
423
contrib/fundamentals/ZLib/zlib123/crc32.c
Normal file
@@ -0,0 +1,423 @@
|
||||
/* crc32.c -- compute the CRC-32 of a data stream
|
||||
* Copyright (C) 1995-2005 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
||||
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
|
||||
* tables for updating the shift register in one step with three exclusive-ors
|
||||
* instead of four steps with four exclusive-ors. This results in about a
|
||||
* factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
/*
|
||||
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
|
||||
protection on the static variables used to control the first-use generation
|
||||
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
||||
first call get_crc_table() to initialize the tables before allowing more than
|
||||
one thread to use crc32().
|
||||
*/
|
||||
|
||||
#ifdef MAKECRCH
|
||||
# include <stdio.h>
|
||||
# ifndef DYNAMIC_CRC_TABLE
|
||||
# define DYNAMIC_CRC_TABLE
|
||||
# endif /* !DYNAMIC_CRC_TABLE */
|
||||
#endif /* MAKECRCH */
|
||||
|
||||
#include "zutil.h" /* for STDC and FAR definitions */
|
||||
|
||||
#define local static
|
||||
|
||||
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
|
||||
#ifndef NOBYFOUR
|
||||
# ifdef STDC /* need ANSI C limits.h to determine sizes */
|
||||
# include <limits.h>
|
||||
# define BYFOUR
|
||||
# if (UINT_MAX == 0xffffffffUL)
|
||||
typedef unsigned int u4;
|
||||
# else
|
||||
# if (ULONG_MAX == 0xffffffffUL)
|
||||
typedef unsigned long u4;
|
||||
# else
|
||||
# if (USHRT_MAX == 0xffffffffUL)
|
||||
typedef unsigned short u4;
|
||||
# else
|
||||
# undef BYFOUR /* can't find a four-byte integer type! */
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# endif /* STDC */
|
||||
#endif /* !NOBYFOUR */
|
||||
|
||||
/* Definitions for doing the crc four data bytes at a time. */
|
||||
#ifdef BYFOUR
|
||||
# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
|
||||
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
|
||||
local unsigned long crc32_little OF((unsigned long,
|
||||
const unsigned char FAR *, unsigned));
|
||||
local unsigned long crc32_big OF((unsigned long,
|
||||
const unsigned char FAR *, unsigned));
|
||||
# define TBLS 8
|
||||
#else
|
||||
# define TBLS 1
|
||||
#endif /* BYFOUR */
|
||||
|
||||
/* Local functions for crc concatenation */
|
||||
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
||||
unsigned long vec));
|
||||
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
|
||||
local volatile int crc_table_empty = 1;
|
||||
local unsigned long FAR crc_table[TBLS][256];
|
||||
local void make_crc_table OF((void));
|
||||
#ifdef MAKECRCH
|
||||
local void write_table OF((FILE *, const unsigned long FAR *));
|
||||
#endif /* MAKECRCH */
|
||||
/*
|
||||
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
||||
|
||||
Polynomials over GF(2) are represented in binary, one bit per coefficient,
|
||||
with the lowest powers in the most significant bit. Then adding polynomials
|
||||
is just exclusive-or, and multiplying a polynomial by x is a right shift by
|
||||
one. If we call the above polynomial p, and represent a byte as the
|
||||
polynomial q, also with the lowest power in the most significant bit (so the
|
||||
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
|
||||
where a mod b means the remainder after dividing a by b.
|
||||
|
||||
This calculation is done using the shift-register method of multiplying and
|
||||
taking the remainder. The register is initialized to zero, and for each
|
||||
incoming bit, x^32 is added mod p to the register if the bit is a one (where
|
||||
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
|
||||
x (which is shifting right by one and adding x^32 mod p if the bit shifted
|
||||
out is a one). We start with the highest power (least significant bit) of
|
||||
q and repeat for all eight bits of q.
|
||||
|
||||
The first table is simply the CRC of all possible eight bit values. This is
|
||||
all the information needed to generate CRCs on data a byte at a time for all
|
||||
combinations of CRC register values and incoming bytes. The remaining tables
|
||||
allow for word-at-a-time CRC calculation for both big-endian and little-
|
||||
endian machines, where a word is four bytes.
|
||||
*/
|
||||
local void make_crc_table()
|
||||
{
|
||||
unsigned long c;
|
||||
int n, k;
|
||||
unsigned long poly; /* polynomial exclusive-or pattern */
|
||||
/* terms of polynomial defining this crc (except x^32): */
|
||||
static volatile int first = 1; /* flag to limit concurrent making */
|
||||
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
||||
|
||||
/* See if another task is already doing this (not thread-safe, but better
|
||||
than nothing -- significantly reduces duration of vulnerability in
|
||||
case the advice about DYNAMIC_CRC_TABLE is ignored) */
|
||||
if (first) {
|
||||
first = 0;
|
||||
|
||||
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
||||
poly = 0UL;
|
||||
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
||||
poly |= 1UL << (31 - p[n]);
|
||||
|
||||
/* generate a crc for every 8-bit value */
|
||||
for (n = 0; n < 256; n++) {
|
||||
c = (unsigned long)n;
|
||||
for (k = 0; k < 8; k++)
|
||||
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||
crc_table[0][n] = c;
|
||||
}
|
||||
|
||||
#ifdef BYFOUR
|
||||
/* generate crc for each value followed by one, two, and three zeros,
|
||||
and then the byte reversal of those as well as the first table */
|
||||
for (n = 0; n < 256; n++) {
|
||||
c = crc_table[0][n];
|
||||
crc_table[4][n] = REV(c);
|
||||
for (k = 1; k < 4; k++) {
|
||||
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
||||
crc_table[k][n] = c;
|
||||
crc_table[k + 4][n] = REV(c);
|
||||
}
|
||||
}
|
||||
#endif /* BYFOUR */
|
||||
|
||||
crc_table_empty = 0;
|
||||
}
|
||||
else { /* not first */
|
||||
/* wait for the other guy to finish (not efficient, but rare) */
|
||||
while (crc_table_empty)
|
||||
;
|
||||
}
|
||||
|
||||
#ifdef MAKECRCH
|
||||
/* write out CRC tables to crc32.h */
|
||||
{
|
||||
FILE *out;
|
||||
|
||||
out = fopen("crc32.h", "w");
|
||||
if (out == NULL) return;
|
||||
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
||||
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
||||
fprintf(out, "local const unsigned long FAR ");
|
||||
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
||||
write_table(out, crc_table[0]);
|
||||
# ifdef BYFOUR
|
||||
fprintf(out, "#ifdef BYFOUR\n");
|
||||
for (k = 1; k < 8; k++) {
|
||||
fprintf(out, " },\n {\n");
|
||||
write_table(out, crc_table[k]);
|
||||
}
|
||||
fprintf(out, "#endif\n");
|
||||
# endif /* BYFOUR */
|
||||
fprintf(out, " }\n};\n");
|
||||
fclose(out);
|
||||
}
|
||||
#endif /* MAKECRCH */
|
||||
}
|
||||
|
||||
#ifdef MAKECRCH
|
||||
local void write_table(out, table)
|
||||
FILE *out;
|
||||
const unsigned long FAR *table;
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
|
||||
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
||||
}
|
||||
#endif /* MAKECRCH */
|
||||
|
||||
#else /* !DYNAMIC_CRC_TABLE */
|
||||
/* ========================================================================
|
||||
* Tables of CRC-32s of all single-byte values, made by make_crc_table().
|
||||
*/
|
||||
#include "crc32.h"
|
||||
#endif /* DYNAMIC_CRC_TABLE */
|
||||
|
||||
/* =========================================================================
|
||||
* This function can be used by asm versions of crc32()
|
||||
*/
|
||||
const unsigned long FAR * ZEXPORT get_crc_table()
|
||||
{
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty)
|
||||
make_crc_table();
|
||||
#endif /* DYNAMIC_CRC_TABLE */
|
||||
return (const unsigned long FAR *)crc_table;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
|
||||
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
|
||||
|
||||
/* ========================================================================= */
|
||||
unsigned long ZEXPORT crc32(crc, buf, len)
|
||||
unsigned long crc;
|
||||
const unsigned char FAR *buf;
|
||||
unsigned len;
|
||||
{
|
||||
if (buf == Z_NULL) return 0UL;
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty)
|
||||
make_crc_table();
|
||||
#endif /* DYNAMIC_CRC_TABLE */
|
||||
|
||||
#ifdef BYFOUR
|
||||
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
||||
u4 endian;
|
||||
|
||||
endian = 1;
|
||||
if (*((unsigned char *)(&endian)))
|
||||
return crc32_little(crc, buf, len);
|
||||
else
|
||||
return crc32_big(crc, buf, len);
|
||||
}
|
||||
#endif /* BYFOUR */
|
||||
crc = crc ^ 0xffffffffUL;
|
||||
while (len >= 8) {
|
||||
DO8;
|
||||
len -= 8;
|
||||
}
|
||||
if (len) do {
|
||||
DO1;
|
||||
} while (--len);
|
||||
return crc ^ 0xffffffffUL;
|
||||
}
|
||||
|
||||
#ifdef BYFOUR
|
||||
|
||||
/* ========================================================================= */
|
||||
#define DOLIT4 c ^= *buf4++; \
|
||||
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
|
||||
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
|
||||
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
|
||||
|
||||
/* ========================================================================= */
|
||||
local unsigned long crc32_little(crc, buf, len)
|
||||
unsigned long crc;
|
||||
const unsigned char FAR *buf;
|
||||
unsigned len;
|
||||
{
|
||||
register u4 c;
|
||||
register const u4 FAR *buf4;
|
||||
|
||||
c = (u4)crc;
|
||||
c = ~c;
|
||||
while (len && ((ptrdiff_t)buf & 3)) {
|
||||
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
||||
len--;
|
||||
}
|
||||
|
||||
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
||||
while (len >= 32) {
|
||||
DOLIT32;
|
||||
len -= 32;
|
||||
}
|
||||
while (len >= 4) {
|
||||
DOLIT4;
|
||||
len -= 4;
|
||||
}
|
||||
buf = (const unsigned char FAR *)buf4;
|
||||
|
||||
if (len) do {
|
||||
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
||||
} while (--len);
|
||||
c = ~c;
|
||||
return (unsigned long)c;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
#define DOBIG4 c ^= *++buf4; \
|
||||
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
|
||||
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
|
||||
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
|
||||
|
||||
/* ========================================================================= */
|
||||
local unsigned long crc32_big(crc, buf, len)
|
||||
unsigned long crc;
|
||||
const unsigned char FAR *buf;
|
||||
unsigned len;
|
||||
{
|
||||
register u4 c;
|
||||
register const u4 FAR *buf4;
|
||||
|
||||
c = REV((u4)crc);
|
||||
c = ~c;
|
||||
while (len && ((ptrdiff_t)buf & 3)) {
|
||||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||
len--;
|
||||
}
|
||||
|
||||
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
||||
buf4--;
|
||||
while (len >= 32) {
|
||||
DOBIG32;
|
||||
len -= 32;
|
||||
}
|
||||
while (len >= 4) {
|
||||
DOBIG4;
|
||||
len -= 4;
|
||||
}
|
||||
buf4++;
|
||||
buf = (const unsigned char FAR *)buf4;
|
||||
|
||||
if (len) do {
|
||||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||
} while (--len);
|
||||
c = ~c;
|
||||
return (unsigned long)(REV(c));
|
||||
}
|
||||
|
||||
#endif /* BYFOUR */
|
||||
|
||||
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
|
||||
|
||||
/* ========================================================================= */
|
||||
local unsigned long gf2_matrix_times(mat, vec)
|
||||
unsigned long *mat;
|
||||
unsigned long vec;
|
||||
{
|
||||
unsigned long sum;
|
||||
|
||||
sum = 0;
|
||||
while (vec) {
|
||||
if (vec & 1)
|
||||
sum ^= *mat;
|
||||
vec >>= 1;
|
||||
mat++;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
local void gf2_matrix_square(square, mat)
|
||||
unsigned long *square;
|
||||
unsigned long *mat;
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; n < GF2_DIM; n++)
|
||||
square[n] = gf2_matrix_times(mat, mat[n]);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
||||
uLong crc1;
|
||||
uLong crc2;
|
||||
z_off_t len2;
|
||||
{
|
||||
int n;
|
||||
unsigned long row;
|
||||
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
|
||||
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
|
||||
|
||||
/* degenerate case */
|
||||
if (len2 == 0)
|
||||
return crc1;
|
||||
|
||||
/* put operator for one zero bit in odd */
|
||||
odd[0] = 0xedb88320L; /* CRC-32 polynomial */
|
||||
row = 1;
|
||||
for (n = 1; n < GF2_DIM; n++) {
|
||||
odd[n] = row;
|
||||
row <<= 1;
|
||||
}
|
||||
|
||||
/* put operator for two zero bits in even */
|
||||
gf2_matrix_square(even, odd);
|
||||
|
||||
/* put operator for four zero bits in odd */
|
||||
gf2_matrix_square(odd, even);
|
||||
|
||||
/* apply len2 zeros to crc1 (first square will put the operator for one
|
||||
zero byte, eight zero bits, in even) */
|
||||
do {
|
||||
/* apply zeros operator for this bit of len2 */
|
||||
gf2_matrix_square(even, odd);
|
||||
if (len2 & 1)
|
||||
crc1 = gf2_matrix_times(even, crc1);
|
||||
len2 >>= 1;
|
||||
|
||||
/* if no more bits set, then done */
|
||||
if (len2 == 0)
|
||||
break;
|
||||
|
||||
/* another iteration of the loop with odd and even swapped */
|
||||
gf2_matrix_square(odd, even);
|
||||
if (len2 & 1)
|
||||
crc1 = gf2_matrix_times(odd, crc1);
|
||||
len2 >>= 1;
|
||||
|
||||
/* if no more bits set, then done */
|
||||
} while (len2 != 0);
|
||||
|
||||
/* return combined crc */
|
||||
crc1 ^= crc2;
|
||||
return crc1;
|
||||
}
|
||||
441
contrib/fundamentals/ZLib/zlib123/crc32.h
Normal file
441
contrib/fundamentals/ZLib/zlib123/crc32.h
Normal file
@@ -0,0 +1,441 @@
|
||||
/* crc32.h -- tables for rapid CRC calculation
|
||||
* Generated automatically by crc32.c
|
||||
*/
|
||||
|
||||
local const unsigned long FAR crc_table[TBLS][256] =
|
||||
{
|
||||
{
|
||||
0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
|
||||
0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
|
||||
0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
|
||||
0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
|
||||
0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
|
||||
0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
|
||||
0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
|
||||
0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
|
||||
0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
|
||||
0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
|
||||
0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
|
||||
0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
|
||||
0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
|
||||
0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
|
||||
0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
|
||||
0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
|
||||
0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
|
||||
0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
|
||||
0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
|
||||
0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
|
||||
0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
|
||||
0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
|
||||
0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
|
||||
0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
|
||||
0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
|
||||
0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
|
||||
0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
|
||||
0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
|
||||
0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
|
||||
0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
|
||||
0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
|
||||
0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
|
||||
0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
|
||||
0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
|
||||
0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
|
||||
0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
|
||||
0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
|
||||
0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
|
||||
0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
|
||||
0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
|
||||
0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
|
||||
0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
|
||||
0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
|
||||
0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
|
||||
0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
|
||||
0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
|
||||
0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
|
||||
0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
|
||||
0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
|
||||
0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
|
||||
0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
|
||||
0x2d02ef8dUL
|
||||
#ifdef BYFOUR
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
|
||||
0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
|
||||
0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
|
||||
0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
|
||||
0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
|
||||
0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
|
||||
0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
|
||||
0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
|
||||
0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
|
||||
0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
|
||||
0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
|
||||
0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
|
||||
0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
|
||||
0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
|
||||
0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
|
||||
0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
|
||||
0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
|
||||
0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
|
||||
0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
|
||||
0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
|
||||
0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
|
||||
0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
|
||||
0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
|
||||
0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
|
||||
0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
|
||||
0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
|
||||
0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
|
||||
0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
|
||||
0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
|
||||
0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
|
||||
0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
|
||||
0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
|
||||
0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
|
||||
0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
|
||||
0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
|
||||
0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
|
||||
0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
|
||||
0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
|
||||
0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
|
||||
0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
|
||||
0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
|
||||
0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
|
||||
0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
|
||||
0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
|
||||
0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
|
||||
0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
|
||||
0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
|
||||
0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
|
||||
0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
|
||||
0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
|
||||
0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
|
||||
0x9324fd72UL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
|
||||
0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
|
||||
0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
|
||||
0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
|
||||
0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
|
||||
0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
|
||||
0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
|
||||
0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
|
||||
0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
|
||||
0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
|
||||
0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
|
||||
0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
|
||||
0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
|
||||
0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
|
||||
0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
|
||||
0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
|
||||
0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
|
||||
0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
|
||||
0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
|
||||
0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
|
||||
0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
|
||||
0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
|
||||
0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
|
||||
0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
|
||||
0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
|
||||
0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
|
||||
0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
|
||||
0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
|
||||
0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
|
||||
0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
|
||||
0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
|
||||
0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
|
||||
0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
|
||||
0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
|
||||
0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
|
||||
0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
|
||||
0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
|
||||
0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
|
||||
0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
|
||||
0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
|
||||
0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
|
||||
0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
|
||||
0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
|
||||
0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
|
||||
0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
|
||||
0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
|
||||
0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
|
||||
0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
|
||||
0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
|
||||
0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
|
||||
0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
|
||||
0xbe9834edUL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
|
||||
0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
|
||||
0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
|
||||
0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
|
||||
0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
|
||||
0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
|
||||
0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
|
||||
0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
|
||||
0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
|
||||
0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
|
||||
0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
|
||||
0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
|
||||
0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
|
||||
0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
|
||||
0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
|
||||
0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
|
||||
0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
|
||||
0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
|
||||
0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
|
||||
0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
|
||||
0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
|
||||
0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
|
||||
0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
|
||||
0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
|
||||
0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
|
||||
0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
|
||||
0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
|
||||
0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
|
||||
0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
|
||||
0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
|
||||
0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
|
||||
0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
|
||||
0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
|
||||
0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
|
||||
0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
|
||||
0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
|
||||
0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
|
||||
0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
|
||||
0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
|
||||
0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
|
||||
0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
|
||||
0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
|
||||
0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
|
||||
0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
|
||||
0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
|
||||
0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
|
||||
0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
|
||||
0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
|
||||
0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
|
||||
0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
|
||||
0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
|
||||
0xde0506f1UL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
|
||||
0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
|
||||
0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
|
||||
0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
|
||||
0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
|
||||
0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
|
||||
0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
|
||||
0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
|
||||
0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
|
||||
0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
|
||||
0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
|
||||
0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
|
||||
0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
|
||||
0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
|
||||
0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
|
||||
0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
|
||||
0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
|
||||
0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
|
||||
0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
|
||||
0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
|
||||
0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
|
||||
0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
|
||||
0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
|
||||
0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
|
||||
0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
|
||||
0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
|
||||
0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
|
||||
0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
|
||||
0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
|
||||
0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
|
||||
0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
|
||||
0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
|
||||
0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
|
||||
0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
|
||||
0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
|
||||
0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
|
||||
0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
|
||||
0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
|
||||
0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
|
||||
0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
|
||||
0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
|
||||
0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
|
||||
0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
|
||||
0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
|
||||
0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
|
||||
0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
|
||||
0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
|
||||
0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
|
||||
0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
|
||||
0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
|
||||
0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
|
||||
0x8def022dUL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
|
||||
0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
|
||||
0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
|
||||
0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
|
||||
0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
|
||||
0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
|
||||
0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
|
||||
0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
|
||||
0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
|
||||
0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
|
||||
0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
|
||||
0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
|
||||
0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
|
||||
0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
|
||||
0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
|
||||
0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
|
||||
0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
|
||||
0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
|
||||
0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
|
||||
0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
|
||||
0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
|
||||
0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
|
||||
0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
|
||||
0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
|
||||
0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
|
||||
0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
|
||||
0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
|
||||
0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
|
||||
0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
|
||||
0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
|
||||
0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
|
||||
0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
|
||||
0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
|
||||
0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
|
||||
0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
|
||||
0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
|
||||
0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
|
||||
0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
|
||||
0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
|
||||
0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
|
||||
0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
|
||||
0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
|
||||
0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
|
||||
0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
|
||||
0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
|
||||
0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
|
||||
0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
|
||||
0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
|
||||
0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
|
||||
0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
|
||||
0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
|
||||
0x72fd2493UL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
|
||||
0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
|
||||
0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
|
||||
0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
|
||||
0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
|
||||
0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
|
||||
0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
|
||||
0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
|
||||
0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
|
||||
0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
|
||||
0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
|
||||
0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
|
||||
0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
|
||||
0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
|
||||
0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
|
||||
0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
|
||||
0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
|
||||
0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
|
||||
0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
|
||||
0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
|
||||
0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
|
||||
0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
|
||||
0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
|
||||
0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
|
||||
0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
|
||||
0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
|
||||
0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
|
||||
0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
|
||||
0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
|
||||
0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
|
||||
0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
|
||||
0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
|
||||
0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
|
||||
0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
|
||||
0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
|
||||
0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
|
||||
0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
|
||||
0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
|
||||
0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
|
||||
0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
|
||||
0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
|
||||
0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
|
||||
0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
|
||||
0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
|
||||
0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
|
||||
0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
|
||||
0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
|
||||
0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
|
||||
0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
|
||||
0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
|
||||
0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
|
||||
0xed3498beUL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
|
||||
0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
|
||||
0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
|
||||
0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
|
||||
0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
|
||||
0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
|
||||
0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
|
||||
0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
|
||||
0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
|
||||
0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
|
||||
0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
|
||||
0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
|
||||
0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
|
||||
0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
|
||||
0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
|
||||
0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
|
||||
0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
|
||||
0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
|
||||
0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
|
||||
0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
|
||||
0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
|
||||
0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
|
||||
0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
|
||||
0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
|
||||
0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
|
||||
0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
|
||||
0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
|
||||
0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
|
||||
0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
|
||||
0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
|
||||
0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
|
||||
0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
|
||||
0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
|
||||
0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
|
||||
0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
|
||||
0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
|
||||
0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
|
||||
0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
|
||||
0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
|
||||
0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
|
||||
0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
|
||||
0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
|
||||
0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
|
||||
0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
|
||||
0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
|
||||
0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
|
||||
0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
|
||||
0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
|
||||
0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
|
||||
0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
|
||||
0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
|
||||
0xf10605deUL
|
||||
#endif
|
||||
}
|
||||
};
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/crc32.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/crc32.obj
Normal file
Binary file not shown.
1736
contrib/fundamentals/ZLib/zlib123/deflate.c
Normal file
1736
contrib/fundamentals/ZLib/zlib123/deflate.c
Normal file
File diff suppressed because it is too large
Load Diff
331
contrib/fundamentals/ZLib/zlib123/deflate.h
Normal file
331
contrib/fundamentals/ZLib/zlib123/deflate.h
Normal file
@@ -0,0 +1,331 @@
|
||||
/* deflate.h -- internal compression state
|
||||
* Copyright (C) 1995-2004 Jean-loup Gailly
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef DEFLATE_H
|
||||
#define DEFLATE_H
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
/* define NO_GZIP when compiling if you want to disable gzip header and
|
||||
trailer creation by deflate(). NO_GZIP would be used to avoid linking in
|
||||
the crc code when it is not needed. For shared libraries, gzip encoding
|
||||
should be left enabled. */
|
||||
#ifndef NO_GZIP
|
||||
# define GZIP
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
* Internal compression state.
|
||||
*/
|
||||
|
||||
#define LENGTH_CODES 29
|
||||
/* number of length codes, not counting the special END_BLOCK code */
|
||||
|
||||
#define LITERALS 256
|
||||
/* number of literal bytes 0..255 */
|
||||
|
||||
#define L_CODES (LITERALS+1+LENGTH_CODES)
|
||||
/* number of Literal or Length codes, including the END_BLOCK code */
|
||||
|
||||
#define D_CODES 30
|
||||
/* number of distance codes */
|
||||
|
||||
#define BL_CODES 19
|
||||
/* number of codes used to transfer the bit lengths */
|
||||
|
||||
#define HEAP_SIZE (2*L_CODES+1)
|
||||
/* maximum heap size */
|
||||
|
||||
#define MAX_BITS 15
|
||||
/* All codes must not exceed MAX_BITS bits */
|
||||
|
||||
#define INIT_STATE 42
|
||||
#define EXTRA_STATE 69
|
||||
#define NAME_STATE 73
|
||||
#define COMMENT_STATE 91
|
||||
#define HCRC_STATE 103
|
||||
#define BUSY_STATE 113
|
||||
#define FINISH_STATE 666
|
||||
/* Stream status */
|
||||
|
||||
|
||||
/* Data structure describing a single value and its code string. */
|
||||
typedef struct ct_data_s {
|
||||
union {
|
||||
ush freq; /* frequency count */
|
||||
ush code; /* bit string */
|
||||
} fc;
|
||||
union {
|
||||
ush dad; /* father node in Huffman tree */
|
||||
ush len; /* length of bit string */
|
||||
} dl;
|
||||
} FAR ct_data;
|
||||
|
||||
#define Freq fc.freq
|
||||
#define Code fc.code
|
||||
#define Dad dl.dad
|
||||
#define Len dl.len
|
||||
|
||||
typedef struct static_tree_desc_s static_tree_desc;
|
||||
|
||||
typedef struct tree_desc_s {
|
||||
ct_data *dyn_tree; /* the dynamic tree */
|
||||
int max_code; /* largest code with non zero frequency */
|
||||
static_tree_desc *stat_desc; /* the corresponding static tree */
|
||||
} FAR tree_desc;
|
||||
|
||||
typedef ush Pos;
|
||||
typedef Pos FAR Posf;
|
||||
typedef unsigned IPos;
|
||||
|
||||
/* A Pos is an index in the character window. We use short instead of int to
|
||||
* save space in the various tables. IPos is used only for parameter passing.
|
||||
*/
|
||||
|
||||
typedef struct internal_state {
|
||||
z_streamp strm; /* pointer back to this zlib stream */
|
||||
int status; /* as the name implies */
|
||||
Bytef *pending_buf; /* output still pending */
|
||||
ulg pending_buf_size; /* size of pending_buf */
|
||||
Bytef *pending_out; /* next pending byte to output to the stream */
|
||||
uInt pending; /* nb of bytes in the pending buffer */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||
gz_headerp gzhead; /* gzip header information to write */
|
||||
uInt gzindex; /* where in extra, name, or comment */
|
||||
Byte method; /* STORED (for zip only) or DEFLATED */
|
||||
int last_flush; /* value of flush param for previous deflate call */
|
||||
|
||||
/* used by deflate.c: */
|
||||
|
||||
uInt w_size; /* LZ77 window size (32K by default) */
|
||||
uInt w_bits; /* log2(w_size) (8..16) */
|
||||
uInt w_mask; /* w_size - 1 */
|
||||
|
||||
Bytef *window;
|
||||
/* Sliding window. Input bytes are read into the second half of the window,
|
||||
* and move to the first half later to keep a dictionary of at least wSize
|
||||
* bytes. With this organization, matches are limited to a distance of
|
||||
* wSize-MAX_MATCH bytes, but this ensures that IO is always
|
||||
* performed with a length multiple of the block size. Also, it limits
|
||||
* the window size to 64K, which is quite useful on MSDOS.
|
||||
* To do: use the user input buffer as sliding window.
|
||||
*/
|
||||
|
||||
ulg window_size;
|
||||
/* Actual size of window: 2*wSize, except when the user input buffer
|
||||
* is directly used as sliding window.
|
||||
*/
|
||||
|
||||
Posf *prev;
|
||||
/* Link to older string with same hash index. To limit the size of this
|
||||
* array to 64K, this link is maintained only for the last 32K strings.
|
||||
* An index in this array is thus a window index modulo 32K.
|
||||
*/
|
||||
|
||||
Posf *head; /* Heads of the hash chains or NIL. */
|
||||
|
||||
uInt ins_h; /* hash index of string to be inserted */
|
||||
uInt hash_size; /* number of elements in hash table */
|
||||
uInt hash_bits; /* log2(hash_size) */
|
||||
uInt hash_mask; /* hash_size-1 */
|
||||
|
||||
uInt hash_shift;
|
||||
/* Number of bits by which ins_h must be shifted at each input
|
||||
* step. It must be such that after MIN_MATCH steps, the oldest
|
||||
* byte no longer takes part in the hash key, that is:
|
||||
* hash_shift * MIN_MATCH >= hash_bits
|
||||
*/
|
||||
|
||||
long block_start;
|
||||
/* Window position at the beginning of the current output block. Gets
|
||||
* negative when the window is moved backwards.
|
||||
*/
|
||||
|
||||
uInt match_length; /* length of best match */
|
||||
IPos prev_match; /* previous match */
|
||||
int match_available; /* set if previous match exists */
|
||||
uInt strstart; /* start of string to insert */
|
||||
uInt match_start; /* start of matching string */
|
||||
uInt lookahead; /* number of valid bytes ahead in window */
|
||||
|
||||
uInt prev_length;
|
||||
/* Length of the best match at previous step. Matches not greater than this
|
||||
* are discarded. This is used in the lazy match evaluation.
|
||||
*/
|
||||
|
||||
uInt max_chain_length;
|
||||
/* To speed up deflation, hash chains are never searched beyond this
|
||||
* length. A higher limit improves compression ratio but degrades the
|
||||
* speed.
|
||||
*/
|
||||
|
||||
uInt max_lazy_match;
|
||||
/* Attempt to find a better match only when the current match is strictly
|
||||
* smaller than this value. This mechanism is used only for compression
|
||||
* levels >= 4.
|
||||
*/
|
||||
# define max_insert_length max_lazy_match
|
||||
/* Insert new strings in the hash table only if the match length is not
|
||||
* greater than this length. This saves time but degrades compression.
|
||||
* max_insert_length is used only for compression levels <= 3.
|
||||
*/
|
||||
|
||||
int level; /* compression level (1..9) */
|
||||
int strategy; /* favor or force Huffman coding*/
|
||||
|
||||
uInt good_match;
|
||||
/* Use a faster search when the previous match is longer than this */
|
||||
|
||||
int nice_match; /* Stop searching when current match exceeds this */
|
||||
|
||||
/* used by trees.c: */
|
||||
/* Didn't use ct_data typedef below to supress compiler warning */
|
||||
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
|
||||
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
|
||||
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
|
||||
|
||||
struct tree_desc_s l_desc; /* desc. for literal tree */
|
||||
struct tree_desc_s d_desc; /* desc. for distance tree */
|
||||
struct tree_desc_s bl_desc; /* desc. for bit length tree */
|
||||
|
||||
ush bl_count[MAX_BITS+1];
|
||||
/* number of codes at each bit length for an optimal tree */
|
||||
|
||||
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
|
||||
int heap_len; /* number of elements in the heap */
|
||||
int heap_max; /* element of largest frequency */
|
||||
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
|
||||
* The same heap array is used to build all trees.
|
||||
*/
|
||||
|
||||
uch depth[2*L_CODES+1];
|
||||
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
||||
*/
|
||||
|
||||
uchf *l_buf; /* buffer for literals or lengths */
|
||||
|
||||
uInt lit_bufsize;
|
||||
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
||||
* limiting lit_bufsize to 64K:
|
||||
* - frequencies can be kept in 16 bit counters
|
||||
* - if compression is not successful for the first block, all input
|
||||
* data is still in the window so we can still emit a stored block even
|
||||
* when input comes from standard input. (This can also be done for
|
||||
* all blocks if lit_bufsize is not greater than 32K.)
|
||||
* - if compression is not successful for a file smaller than 64K, we can
|
||||
* even emit a stored file instead of a stored block (saving 5 bytes).
|
||||
* This is applicable only for zip (not gzip or zlib).
|
||||
* - creating new Huffman trees less frequently may not provide fast
|
||||
* adaptation to changes in the input data statistics. (Take for
|
||||
* example a binary file with poorly compressible code followed by
|
||||
* a highly compressible string table.) Smaller buffer sizes give
|
||||
* fast adaptation but have of course the overhead of transmitting
|
||||
* trees more frequently.
|
||||
* - I can't count above 4
|
||||
*/
|
||||
|
||||
uInt last_lit; /* running index in l_buf */
|
||||
|
||||
ushf *d_buf;
|
||||
/* Buffer for distances. To simplify the code, d_buf and l_buf have
|
||||
* the same number of elements. To use different lengths, an extra flag
|
||||
* array would be necessary.
|
||||
*/
|
||||
|
||||
ulg opt_len; /* bit length of current block with optimal trees */
|
||||
ulg static_len; /* bit length of current block with static trees */
|
||||
uInt matches; /* number of string matches in current block */
|
||||
int last_eob_len; /* bit length of EOB code for last block */
|
||||
|
||||
#ifdef DEBUG
|
||||
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
|
||||
#endif
|
||||
|
||||
ush bi_buf;
|
||||
/* Output buffer. bits are inserted starting at the bottom (least
|
||||
* significant bits).
|
||||
*/
|
||||
int bi_valid;
|
||||
/* Number of valid bits in bi_buf. All bits above the last valid bit
|
||||
* are always zero.
|
||||
*/
|
||||
|
||||
} FAR deflate_state;
|
||||
|
||||
/* Output a byte on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
|
||||
|
||||
|
||||
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
||||
/* Minimum amount of lookahead, except at the end of the input file.
|
||||
* See deflate.c for comments about the MIN_MATCH+1.
|
||||
*/
|
||||
|
||||
#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
|
||||
/* In order to simplify the code, particularly on 16 bit machines, match
|
||||
* distances are limited to MAX_DIST instead of WSIZE.
|
||||
*/
|
||||
|
||||
/* in trees.c */
|
||||
void _tr_init OF((deflate_state *s));
|
||||
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
||||
void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||
int eof));
|
||||
void _tr_align OF((deflate_state *s));
|
||||
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||
int eof));
|
||||
|
||||
#define d_code(dist) \
|
||||
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
|
||||
/* Mapping from a distance to a distance code. dist is the distance - 1 and
|
||||
* must not have side effects. _dist_code[256] and _dist_code[257] are never
|
||||
* used.
|
||||
*/
|
||||
|
||||
#ifndef DEBUG
|
||||
/* Inline versions of _tr_tally for speed: */
|
||||
|
||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||
extern uch _length_code[];
|
||||
extern uch _dist_code[];
|
||||
#else
|
||||
extern const uch _length_code[];
|
||||
extern const uch _dist_code[];
|
||||
#endif
|
||||
|
||||
# define _tr_tally_lit(s, c, flush) \
|
||||
{ uch cc = (c); \
|
||||
s->d_buf[s->last_lit] = 0; \
|
||||
s->l_buf[s->last_lit++] = cc; \
|
||||
s->dyn_ltree[cc].Freq++; \
|
||||
flush = (s->last_lit == s->lit_bufsize-1); \
|
||||
}
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
{ uch len = (length); \
|
||||
ush dist = (distance); \
|
||||
s->d_buf[s->last_lit] = dist; \
|
||||
s->l_buf[s->last_lit++] = len; \
|
||||
dist--; \
|
||||
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
|
||||
s->dyn_dtree[d_code(dist)].Freq++; \
|
||||
flush = (s->last_lit == s->lit_bufsize-1); \
|
||||
}
|
||||
#else
|
||||
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
flush = _tr_tally(s, distance, length)
|
||||
#endif
|
||||
|
||||
#endif /* DEFLATE_H */
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/deflate.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/deflate.obj
Normal file
Binary file not shown.
565
contrib/fundamentals/ZLib/zlib123/example.c
Normal file
565
contrib/fundamentals/ZLib/zlib123/example.c
Normal file
@@ -0,0 +1,565 @@
|
||||
/* example.c -- usage example of the zlib compression library
|
||||
* Copyright (C) 1995-2004 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef STDC
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if defined(VMS) || defined(RISCOS)
|
||||
# define TESTFILE "foo-gz"
|
||||
#else
|
||||
# define TESTFILE "foo.gz"
|
||||
#endif
|
||||
|
||||
#define CHECK_ERR(err, msg) { \
|
||||
if (err != Z_OK) { \
|
||||
fprintf(stderr, "%s error: %d\n", msg, err); \
|
||||
exit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
const char hello[] = "hello, hello!";
|
||||
/* "hello world" would be more standard, but the repeated "hello"
|
||||
* stresses the compression code better, sorry...
|
||||
*/
|
||||
|
||||
const char dictionary[] = "hello";
|
||||
uLong dictId; /* Adler32 value of the dictionary */
|
||||
|
||||
void test_compress OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_gzio OF((const char *fname,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_deflate OF((Byte *compr, uLong comprLen));
|
||||
void test_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_large_deflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_large_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_flush OF((Byte *compr, uLong *comprLen));
|
||||
void test_sync OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_dict_deflate OF((Byte *compr, uLong comprLen));
|
||||
void test_dict_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
int main OF((int argc, char *argv[]));
|
||||
|
||||
/* ===========================================================================
|
||||
* Test compress() and uncompress()
|
||||
*/
|
||||
void test_compress(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
int err;
|
||||
uLong len = (uLong)strlen(hello)+1;
|
||||
|
||||
err = compress(compr, &comprLen, (const Bytef*)hello, len);
|
||||
CHECK_ERR(err, "compress");
|
||||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
err = uncompress(uncompr, &uncomprLen, compr, comprLen);
|
||||
CHECK_ERR(err, "uncompress");
|
||||
|
||||
if (strcmp((char*)uncompr, hello)) {
|
||||
fprintf(stderr, "bad uncompress\n");
|
||||
exit(1);
|
||||
} else {
|
||||
printf("uncompress(): %s\n", (char *)uncompr);
|
||||
}
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Test read/write of .gz files
|
||||
*/
|
||||
void test_gzio(fname, uncompr, uncomprLen)
|
||||
const char *fname; /* compressed file name */
|
||||
Byte *uncompr;
|
||||
uLong uncomprLen;
|
||||
{
|
||||
#ifdef NO_GZCOMPRESS
|
||||
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
|
||||
#else
|
||||
int err;
|
||||
int len = (int)strlen(hello)+1;
|
||||
gzFile file;
|
||||
z_off_t pos;
|
||||
|
||||
file = gzopen(fname, "wb");
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "gzopen error\n");
|
||||
exit(1);
|
||||
}
|
||||
gzputc(file, 'h');
|
||||
if (gzputs(file, "ello") != 4) {
|
||||
fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
|
||||
exit(1);
|
||||
}
|
||||
if (gzprintf(file, ", %s!", "hello") != 8) {
|
||||
fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
|
||||
exit(1);
|
||||
}
|
||||
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
|
||||
gzclose(file);
|
||||
|
||||
file = gzopen(fname, "rb");
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "gzopen error\n");
|
||||
exit(1);
|
||||
}
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
|
||||
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
|
||||
exit(1);
|
||||
}
|
||||
if (strcmp((char*)uncompr, hello)) {
|
||||
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
|
||||
exit(1);
|
||||
} else {
|
||||
printf("gzread(): %s\n", (char*)uncompr);
|
||||
}
|
||||
|
||||
pos = gzseek(file, -8L, SEEK_CUR);
|
||||
if (pos != 6 || gztell(file) != pos) {
|
||||
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
|
||||
(long)pos, (long)gztell(file));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (gzgetc(file) != ' ') {
|
||||
fprintf(stderr, "gzgetc error\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (gzungetc(' ', file) != ' ') {
|
||||
fprintf(stderr, "gzungetc error\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gzgets(file, (char*)uncompr, (int)uncomprLen);
|
||||
if (strlen((char*)uncompr) != 7) { /* " hello!" */
|
||||
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
|
||||
exit(1);
|
||||
}
|
||||
if (strcmp((char*)uncompr, hello + 6)) {
|
||||
fprintf(stderr, "bad gzgets after gzseek\n");
|
||||
exit(1);
|
||||
} else {
|
||||
printf("gzgets() after gzseek: %s\n", (char*)uncompr);
|
||||
}
|
||||
|
||||
gzclose(file);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Test deflate() with small buffers
|
||||
*/
|
||||
void test_deflate(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong comprLen;
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
uLong len = (uLong)strlen(hello)+1;
|
||||
|
||||
c_stream.zalloc = (alloc_func)0;
|
||||
c_stream.zfree = (free_func)0;
|
||||
c_stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
c_stream.next_in = (Bytef*)hello;
|
||||
c_stream.next_out = compr;
|
||||
|
||||
while (c_stream.total_in != len && c_stream.total_out < comprLen) {
|
||||
c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
|
||||
err = deflate(&c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, "deflate");
|
||||
}
|
||||
/* Finish the stream, still forcing small buffers: */
|
||||
for (;;) {
|
||||
c_stream.avail_out = 1;
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
if (err == Z_STREAM_END) break;
|
||||
CHECK_ERR(err, "deflate");
|
||||
}
|
||||
|
||||
err = deflateEnd(&c_stream);
|
||||
CHECK_ERR(err, "deflateEnd");
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Test inflate() with small buffers
|
||||
*/
|
||||
void test_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
d_stream.zalloc = (alloc_func)0;
|
||||
d_stream.zfree = (free_func)0;
|
||||
d_stream.opaque = (voidpf)0;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
d_stream.avail_in = 0;
|
||||
d_stream.next_out = uncompr;
|
||||
|
||||
err = inflateInit(&d_stream);
|
||||
CHECK_ERR(err, "inflateInit");
|
||||
|
||||
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
|
||||
d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
|
||||
err = inflate(&d_stream, Z_NO_FLUSH);
|
||||
if (err == Z_STREAM_END) break;
|
||||
CHECK_ERR(err, "inflate");
|
||||
}
|
||||
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
|
||||
if (strcmp((char*)uncompr, hello)) {
|
||||
fprintf(stderr, "bad inflate\n");
|
||||
exit(1);
|
||||
} else {
|
||||
printf("inflate(): %s\n", (char *)uncompr);
|
||||
}
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Test deflate() with large buffers and dynamic change of compression level
|
||||
*/
|
||||
void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
||||
c_stream.zalloc = (alloc_func)0;
|
||||
c_stream.zfree = (free_func)0;
|
||||
c_stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&c_stream, Z_BEST_SPEED);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
c_stream.next_out = compr;
|
||||
c_stream.avail_out = (uInt)comprLen;
|
||||
|
||||
/* At this point, uncompr is still mostly zeroes, so it should compress
|
||||
* very well:
|
||||
*/
|
||||
c_stream.next_in = uncompr;
|
||||
c_stream.avail_in = (uInt)uncomprLen;
|
||||
err = deflate(&c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, "deflate");
|
||||
if (c_stream.avail_in != 0) {
|
||||
fprintf(stderr, "deflate not greedy\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Feed in already compressed data and switch to no compression: */
|
||||
deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
|
||||
c_stream.next_in = compr;
|
||||
c_stream.avail_in = (uInt)comprLen/2;
|
||||
err = deflate(&c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, "deflate");
|
||||
|
||||
/* Switch back to compressing mode: */
|
||||
deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
|
||||
c_stream.next_in = uncompr;
|
||||
c_stream.avail_in = (uInt)uncomprLen;
|
||||
err = deflate(&c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, "deflate");
|
||||
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
fprintf(stderr, "deflate should report Z_STREAM_END\n");
|
||||
exit(1);
|
||||
}
|
||||
err = deflateEnd(&c_stream);
|
||||
CHECK_ERR(err, "deflateEnd");
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Test inflate() with large buffers
|
||||
*/
|
||||
void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
d_stream.zalloc = (alloc_func)0;
|
||||
d_stream.zfree = (free_func)0;
|
||||
d_stream.opaque = (voidpf)0;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
d_stream.avail_in = (uInt)comprLen;
|
||||
|
||||
err = inflateInit(&d_stream);
|
||||
CHECK_ERR(err, "inflateInit");
|
||||
|
||||
for (;;) {
|
||||
d_stream.next_out = uncompr; /* discard the output */
|
||||
d_stream.avail_out = (uInt)uncomprLen;
|
||||
err = inflate(&d_stream, Z_NO_FLUSH);
|
||||
if (err == Z_STREAM_END) break;
|
||||
CHECK_ERR(err, "large inflate");
|
||||
}
|
||||
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
|
||||
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
|
||||
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
|
||||
exit(1);
|
||||
} else {
|
||||
printf("large_inflate(): OK\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Test deflate() with full flush
|
||||
*/
|
||||
void test_flush(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong *comprLen;
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
uInt len = (uInt)strlen(hello)+1;
|
||||
|
||||
c_stream.zalloc = (alloc_func)0;
|
||||
c_stream.zfree = (free_func)0;
|
||||
c_stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
c_stream.next_in = (Bytef*)hello;
|
||||
c_stream.next_out = compr;
|
||||
c_stream.avail_in = 3;
|
||||
c_stream.avail_out = (uInt)*comprLen;
|
||||
err = deflate(&c_stream, Z_FULL_FLUSH);
|
||||
CHECK_ERR(err, "deflate");
|
||||
|
||||
compr[3]++; /* force an error in first compressed block */
|
||||
c_stream.avail_in = len - 3;
|
||||
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
CHECK_ERR(err, "deflate");
|
||||
}
|
||||
err = deflateEnd(&c_stream);
|
||||
CHECK_ERR(err, "deflateEnd");
|
||||
|
||||
*comprLen = c_stream.total_out;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Test inflateSync()
|
||||
*/
|
||||
void test_sync(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
d_stream.zalloc = (alloc_func)0;
|
||||
d_stream.zfree = (free_func)0;
|
||||
d_stream.opaque = (voidpf)0;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
d_stream.avail_in = 2; /* just read the zlib header */
|
||||
|
||||
err = inflateInit(&d_stream);
|
||||
CHECK_ERR(err, "inflateInit");
|
||||
|
||||
d_stream.next_out = uncompr;
|
||||
d_stream.avail_out = (uInt)uncomprLen;
|
||||
|
||||
inflate(&d_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, "inflate");
|
||||
|
||||
d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
|
||||
err = inflateSync(&d_stream); /* but skip the damaged part */
|
||||
CHECK_ERR(err, "inflateSync");
|
||||
|
||||
err = inflate(&d_stream, Z_FINISH);
|
||||
if (err != Z_DATA_ERROR) {
|
||||
fprintf(stderr, "inflate should report DATA_ERROR\n");
|
||||
/* Because of incorrect adler32 */
|
||||
exit(1);
|
||||
}
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
|
||||
printf("after inflateSync(): hel%s\n", (char *)uncompr);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Test deflate() with preset dictionary
|
||||
*/
|
||||
void test_dict_deflate(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong comprLen;
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
||||
c_stream.zalloc = (alloc_func)0;
|
||||
c_stream.zfree = (free_func)0;
|
||||
c_stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
err = deflateSetDictionary(&c_stream,
|
||||
(const Bytef*)dictionary, sizeof(dictionary));
|
||||
CHECK_ERR(err, "deflateSetDictionary");
|
||||
|
||||
dictId = c_stream.adler;
|
||||
c_stream.next_out = compr;
|
||||
c_stream.avail_out = (uInt)comprLen;
|
||||
|
||||
c_stream.next_in = (Bytef*)hello;
|
||||
c_stream.avail_in = (uInt)strlen(hello)+1;
|
||||
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
fprintf(stderr, "deflate should report Z_STREAM_END\n");
|
||||
exit(1);
|
||||
}
|
||||
err = deflateEnd(&c_stream);
|
||||
CHECK_ERR(err, "deflateEnd");
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Test inflate() with a preset dictionary
|
||||
*/
|
||||
void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
d_stream.zalloc = (alloc_func)0;
|
||||
d_stream.zfree = (free_func)0;
|
||||
d_stream.opaque = (voidpf)0;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
d_stream.avail_in = (uInt)comprLen;
|
||||
|
||||
err = inflateInit(&d_stream);
|
||||
CHECK_ERR(err, "inflateInit");
|
||||
|
||||
d_stream.next_out = uncompr;
|
||||
d_stream.avail_out = (uInt)uncomprLen;
|
||||
|
||||
for (;;) {
|
||||
err = inflate(&d_stream, Z_NO_FLUSH);
|
||||
if (err == Z_STREAM_END) break;
|
||||
if (err == Z_NEED_DICT) {
|
||||
if (d_stream.adler != dictId) {
|
||||
fprintf(stderr, "unexpected dictionary");
|
||||
exit(1);
|
||||
}
|
||||
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
|
||||
sizeof(dictionary));
|
||||
}
|
||||
CHECK_ERR(err, "inflate with dict");
|
||||
}
|
||||
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
|
||||
if (strcmp((char*)uncompr, hello)) {
|
||||
fprintf(stderr, "bad inflate with dict\n");
|
||||
exit(1);
|
||||
} else {
|
||||
printf("inflate with dictionary: %s\n", (char *)uncompr);
|
||||
}
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Usage: example [output.gz [input.gz]]
|
||||
*/
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
|
||||
uLong uncomprLen = comprLen;
|
||||
static const char* myVersion = ZLIB_VERSION;
|
||||
|
||||
if (zlibVersion()[0] != myVersion[0]) {
|
||||
fprintf(stderr, "incompatible zlib version\n");
|
||||
exit(1);
|
||||
|
||||
} else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
|
||||
fprintf(stderr, "warning: different zlib version\n");
|
||||
}
|
||||
|
||||
printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
|
||||
ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
|
||||
|
||||
compr = (Byte*)calloc((uInt)comprLen, 1);
|
||||
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
|
||||
/* compr and uncompr are cleared to avoid reading uninitialized
|
||||
* data and to ensure that uncompr compresses well.
|
||||
*/
|
||||
if (compr == Z_NULL || uncompr == Z_NULL) {
|
||||
printf("out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
test_compress(compr, comprLen, uncompr, uncomprLen);
|
||||
|
||||
test_gzio((argc > 1 ? argv[1] : TESTFILE),
|
||||
uncompr, uncomprLen);
|
||||
|
||||
test_deflate(compr, comprLen);
|
||||
test_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
|
||||
test_large_deflate(compr, comprLen, uncompr, uncomprLen);
|
||||
test_large_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
|
||||
test_flush(compr, &comprLen);
|
||||
test_sync(compr, comprLen, uncompr, uncomprLen);
|
||||
comprLen = uncomprLen;
|
||||
|
||||
test_dict_deflate(compr, comprLen);
|
||||
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
|
||||
free(compr);
|
||||
free(uncompr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
1026
contrib/fundamentals/ZLib/zlib123/gzio.c
Normal file
1026
contrib/fundamentals/ZLib/zlib123/gzio.c
Normal file
File diff suppressed because it is too large
Load Diff
BIN
contrib/fundamentals/ZLib/zlib123/gzio.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/gzio.obj
Normal file
Binary file not shown.
623
contrib/fundamentals/ZLib/zlib123/infback.c
Normal file
623
contrib/fundamentals/ZLib/zlib123/infback.c
Normal file
@@ -0,0 +1,623 @@
|
||||
/* infback.c -- inflate using a call-back interface
|
||||
* Copyright (C) 1995-2005 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/*
|
||||
This code is largely copied from inflate.c. Normally either infback.o or
|
||||
inflate.o would be linked into an application--not both. The interface
|
||||
with inffast.c is retained so that optimized assembler-coded versions of
|
||||
inflate_fast() can be used with either inflate.c or infback.c.
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
#include "inffast.h"
|
||||
|
||||
/* function prototypes */
|
||||
local void fixedtables OF((struct inflate_state FAR *state));
|
||||
|
||||
/*
|
||||
strm provides memory allocation functions in zalloc and zfree, or
|
||||
Z_NULL to use the library memory allocation functions.
|
||||
|
||||
windowBits is in the range 8..15, and window is a user-supplied
|
||||
window and output buffer that is 2**windowBits bytes.
|
||||
*/
|
||||
int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
|
||||
z_streamp strm;
|
||||
int windowBits;
|
||||
unsigned char FAR *window;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
|
||||
stream_size != (int)(sizeof(z_stream)))
|
||||
return Z_VERSION_ERROR;
|
||||
if (strm == Z_NULL || window == Z_NULL ||
|
||||
windowBits < 8 || windowBits > 15)
|
||||
return Z_STREAM_ERROR;
|
||||
strm->msg = Z_NULL; /* in case we return an error */
|
||||
if (strm->zalloc == (alloc_func)0) {
|
||||
strm->zalloc = zcalloc;
|
||||
strm->opaque = (voidpf)0;
|
||||
}
|
||||
if (strm->zfree == (free_func)0) strm->zfree = zcfree;
|
||||
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
|
||||
sizeof(struct inflate_state));
|
||||
if (state == Z_NULL) return Z_MEM_ERROR;
|
||||
Tracev((stderr, "inflate: allocated\n"));
|
||||
strm->state = (struct internal_state FAR *)state;
|
||||
state->dmax = 32768U;
|
||||
state->wbits = windowBits;
|
||||
state->wsize = 1U << windowBits;
|
||||
state->window = window;
|
||||
state->write = 0;
|
||||
state->whave = 0;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
Return state with length and distance decoding tables and index sizes set to
|
||||
fixed code decoding. Normally this returns fixed tables from inffixed.h.
|
||||
If BUILDFIXED is defined, then instead this routine builds the tables the
|
||||
first time it's called, and returns those tables the first time and
|
||||
thereafter. This reduces the size of the code by about 2K bytes, in
|
||||
exchange for a little execution time. However, BUILDFIXED should not be
|
||||
used for threaded applications, since the rewriting of the tables and virgin
|
||||
may not be thread-safe.
|
||||
*/
|
||||
local void fixedtables(state)
|
||||
struct inflate_state FAR *state;
|
||||
{
|
||||
#ifdef BUILDFIXED
|
||||
static int virgin = 1;
|
||||
static code *lenfix, *distfix;
|
||||
static code fixed[544];
|
||||
|
||||
/* build fixed huffman tables if first call (may not be thread safe) */
|
||||
if (virgin) {
|
||||
unsigned sym, bits;
|
||||
static code *next;
|
||||
|
||||
/* literal/length table */
|
||||
sym = 0;
|
||||
while (sym < 144) state->lens[sym++] = 8;
|
||||
while (sym < 256) state->lens[sym++] = 9;
|
||||
while (sym < 280) state->lens[sym++] = 7;
|
||||
while (sym < 288) state->lens[sym++] = 8;
|
||||
next = fixed;
|
||||
lenfix = next;
|
||||
bits = 9;
|
||||
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
|
||||
|
||||
/* distance table */
|
||||
sym = 0;
|
||||
while (sym < 32) state->lens[sym++] = 5;
|
||||
distfix = next;
|
||||
bits = 5;
|
||||
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
|
||||
|
||||
/* do this just once */
|
||||
virgin = 0;
|
||||
}
|
||||
#else /* !BUILDFIXED */
|
||||
# include "inffixed.h"
|
||||
#endif /* BUILDFIXED */
|
||||
state->lencode = lenfix;
|
||||
state->lenbits = 9;
|
||||
state->distcode = distfix;
|
||||
state->distbits = 5;
|
||||
}
|
||||
|
||||
/* Macros for inflateBack(): */
|
||||
|
||||
/* Load returned state from inflate_fast() */
|
||||
#define LOAD() \
|
||||
do { \
|
||||
put = strm->next_out; \
|
||||
left = strm->avail_out; \
|
||||
next = strm->next_in; \
|
||||
have = strm->avail_in; \
|
||||
hold = state->hold; \
|
||||
bits = state->bits; \
|
||||
} while (0)
|
||||
|
||||
/* Set state from registers for inflate_fast() */
|
||||
#define RESTORE() \
|
||||
do { \
|
||||
strm->next_out = put; \
|
||||
strm->avail_out = left; \
|
||||
strm->next_in = next; \
|
||||
strm->avail_in = have; \
|
||||
state->hold = hold; \
|
||||
state->bits = bits; \
|
||||
} while (0)
|
||||
|
||||
/* Clear the input bit accumulator */
|
||||
#define INITBITS() \
|
||||
do { \
|
||||
hold = 0; \
|
||||
bits = 0; \
|
||||
} while (0)
|
||||
|
||||
/* Assure that some input is available. If input is requested, but denied,
|
||||
then return a Z_BUF_ERROR from inflateBack(). */
|
||||
#define PULL() \
|
||||
do { \
|
||||
if (have == 0) { \
|
||||
have = in(in_desc, &next); \
|
||||
if (have == 0) { \
|
||||
next = Z_NULL; \
|
||||
ret = Z_BUF_ERROR; \
|
||||
goto inf_leave; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Get a byte of input into the bit accumulator, or return from inflateBack()
|
||||
with an error if there is no input available. */
|
||||
#define PULLBYTE() \
|
||||
do { \
|
||||
PULL(); \
|
||||
have--; \
|
||||
hold += (unsigned long)(*next++) << bits; \
|
||||
bits += 8; \
|
||||
} while (0)
|
||||
|
||||
/* Assure that there are at least n bits in the bit accumulator. If there is
|
||||
not enough available input to do that, then return from inflateBack() with
|
||||
an error. */
|
||||
#define NEEDBITS(n) \
|
||||
do { \
|
||||
while (bits < (unsigned)(n)) \
|
||||
PULLBYTE(); \
|
||||
} while (0)
|
||||
|
||||
/* Return the low n bits of the bit accumulator (n < 16) */
|
||||
#define BITS(n) \
|
||||
((unsigned)hold & ((1U << (n)) - 1))
|
||||
|
||||
/* Remove n bits from the bit accumulator */
|
||||
#define DROPBITS(n) \
|
||||
do { \
|
||||
hold >>= (n); \
|
||||
bits -= (unsigned)(n); \
|
||||
} while (0)
|
||||
|
||||
/* Remove zero to seven bits as needed to go to a byte boundary */
|
||||
#define BYTEBITS() \
|
||||
do { \
|
||||
hold >>= bits & 7; \
|
||||
bits -= bits & 7; \
|
||||
} while (0)
|
||||
|
||||
/* Assure that some output space is available, by writing out the window
|
||||
if it's full. If the write fails, return from inflateBack() with a
|
||||
Z_BUF_ERROR. */
|
||||
#define ROOM() \
|
||||
do { \
|
||||
if (left == 0) { \
|
||||
put = state->window; \
|
||||
left = state->wsize; \
|
||||
state->whave = left; \
|
||||
if (out(out_desc, put, left)) { \
|
||||
ret = Z_BUF_ERROR; \
|
||||
goto inf_leave; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
strm provides the memory allocation functions and window buffer on input,
|
||||
and provides information on the unused input on return. For Z_DATA_ERROR
|
||||
returns, strm will also provide an error message.
|
||||
|
||||
in() and out() are the call-back input and output functions. When
|
||||
inflateBack() needs more input, it calls in(). When inflateBack() has
|
||||
filled the window with output, or when it completes with data in the
|
||||
window, it calls out() to write out the data. The application must not
|
||||
change the provided input until in() is called again or inflateBack()
|
||||
returns. The application must not change the window/output buffer until
|
||||
inflateBack() returns.
|
||||
|
||||
in() and out() are called with a descriptor parameter provided in the
|
||||
inflateBack() call. This parameter can be a structure that provides the
|
||||
information required to do the read or write, as well as accumulated
|
||||
information on the input and output such as totals and check values.
|
||||
|
||||
in() should return zero on failure. out() should return non-zero on
|
||||
failure. If either in() or out() fails, than inflateBack() returns a
|
||||
Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
|
||||
was in() or out() that caused in the error. Otherwise, inflateBack()
|
||||
returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
|
||||
error, or Z_MEM_ERROR if it could not allocate memory for the state.
|
||||
inflateBack() can also return Z_STREAM_ERROR if the input parameters
|
||||
are not correct, i.e. strm is Z_NULL or the state was not initialized.
|
||||
*/
|
||||
int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
|
||||
z_streamp strm;
|
||||
in_func in;
|
||||
void FAR *in_desc;
|
||||
out_func out;
|
||||
void FAR *out_desc;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned char FAR *next; /* next input */
|
||||
unsigned char FAR *put; /* next output */
|
||||
unsigned have, left; /* available input and output */
|
||||
unsigned long hold; /* bit buffer */
|
||||
unsigned bits; /* bits in bit buffer */
|
||||
unsigned copy; /* number of stored or match bytes to copy */
|
||||
unsigned char FAR *from; /* where to copy match bytes from */
|
||||
code this; /* current decoding table entry */
|
||||
code last; /* parent table entry */
|
||||
unsigned len; /* length to copy for repeats, bits to drop */
|
||||
int ret; /* return code */
|
||||
static const unsigned short order[19] = /* permutation of code lengths */
|
||||
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
/* Check that the strm exists and that the state was initialized */
|
||||
if (strm == Z_NULL || strm->state == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
|
||||
/* Reset the state */
|
||||
strm->msg = Z_NULL;
|
||||
state->mode = TYPE;
|
||||
state->last = 0;
|
||||
state->whave = 0;
|
||||
next = strm->next_in;
|
||||
have = next != Z_NULL ? strm->avail_in : 0;
|
||||
hold = 0;
|
||||
bits = 0;
|
||||
put = state->window;
|
||||
left = state->wsize;
|
||||
|
||||
/* Inflate until end of block marked as last */
|
||||
for (;;)
|
||||
switch (state->mode) {
|
||||
case TYPE:
|
||||
/* determine and dispatch block type */
|
||||
if (state->last) {
|
||||
BYTEBITS();
|
||||
state->mode = DONE;
|
||||
break;
|
||||
}
|
||||
NEEDBITS(3);
|
||||
state->last = BITS(1);
|
||||
DROPBITS(1);
|
||||
switch (BITS(2)) {
|
||||
case 0: /* stored block */
|
||||
Tracev((stderr, "inflate: stored block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
state->mode = STORED;
|
||||
break;
|
||||
case 1: /* fixed block */
|
||||
fixedtables(state);
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
state->mode = LEN; /* decode codes */
|
||||
break;
|
||||
case 2: /* dynamic block */
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
state->mode = TABLE;
|
||||
break;
|
||||
case 3:
|
||||
strm->msg = (char *)"invalid block type";
|
||||
state->mode = BAD;
|
||||
}
|
||||
DROPBITS(2);
|
||||
break;
|
||||
|
||||
case STORED:
|
||||
/* get and verify stored block length */
|
||||
BYTEBITS(); /* go to byte boundary */
|
||||
NEEDBITS(32);
|
||||
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
|
||||
strm->msg = (char *)"invalid stored block lengths";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->length = (unsigned)hold & 0xffff;
|
||||
Tracev((stderr, "inflate: stored length %u\n",
|
||||
state->length));
|
||||
INITBITS();
|
||||
|
||||
/* copy stored block from input to output */
|
||||
while (state->length != 0) {
|
||||
copy = state->length;
|
||||
PULL();
|
||||
ROOM();
|
||||
if (copy > have) copy = have;
|
||||
if (copy > left) copy = left;
|
||||
zmemcpy(put, next, copy);
|
||||
have -= copy;
|
||||
next += copy;
|
||||
left -= copy;
|
||||
put += copy;
|
||||
state->length -= copy;
|
||||
}
|
||||
Tracev((stderr, "inflate: stored end\n"));
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
|
||||
case TABLE:
|
||||
/* get dynamic table entries descriptor */
|
||||
NEEDBITS(14);
|
||||
state->nlen = BITS(5) + 257;
|
||||
DROPBITS(5);
|
||||
state->ndist = BITS(5) + 1;
|
||||
DROPBITS(5);
|
||||
state->ncode = BITS(4) + 4;
|
||||
DROPBITS(4);
|
||||
#ifndef PKZIP_BUG_WORKAROUND
|
||||
if (state->nlen > 286 || state->ndist > 30) {
|
||||
strm->msg = (char *)"too many length or distance symbols";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
Tracev((stderr, "inflate: table sizes ok\n"));
|
||||
|
||||
/* get code length code lengths (not a typo) */
|
||||
state->have = 0;
|
||||
while (state->have < state->ncode) {
|
||||
NEEDBITS(3);
|
||||
state->lens[order[state->have++]] = (unsigned short)BITS(3);
|
||||
DROPBITS(3);
|
||||
}
|
||||
while (state->have < 19)
|
||||
state->lens[order[state->have++]] = 0;
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lenbits = 7;
|
||||
ret = inflate_table(CODES, state->lens, 19, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
if (ret) {
|
||||
strm->msg = (char *)"invalid code lengths set";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: code lengths ok\n"));
|
||||
|
||||
/* get length and distance code code lengths */
|
||||
state->have = 0;
|
||||
while (state->have < state->nlen + state->ndist) {
|
||||
for (;;) {
|
||||
this = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (this.val < 16) {
|
||||
NEEDBITS(this.bits);
|
||||
DROPBITS(this.bits);
|
||||
state->lens[state->have++] = this.val;
|
||||
}
|
||||
else {
|
||||
if (this.val == 16) {
|
||||
NEEDBITS(this.bits + 2);
|
||||
DROPBITS(this.bits);
|
||||
if (state->have == 0) {
|
||||
strm->msg = (char *)"invalid bit length repeat";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
len = (unsigned)(state->lens[state->have - 1]);
|
||||
copy = 3 + BITS(2);
|
||||
DROPBITS(2);
|
||||
}
|
||||
else if (this.val == 17) {
|
||||
NEEDBITS(this.bits + 3);
|
||||
DROPBITS(this.bits);
|
||||
len = 0;
|
||||
copy = 3 + BITS(3);
|
||||
DROPBITS(3);
|
||||
}
|
||||
else {
|
||||
NEEDBITS(this.bits + 7);
|
||||
DROPBITS(this.bits);
|
||||
len = 0;
|
||||
copy = 11 + BITS(7);
|
||||
DROPBITS(7);
|
||||
}
|
||||
if (state->have + copy > state->nlen + state->ndist) {
|
||||
strm->msg = (char *)"invalid bit length repeat";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
while (copy--)
|
||||
state->lens[state->have++] = (unsigned short)len;
|
||||
}
|
||||
}
|
||||
|
||||
/* handle error breaks in while */
|
||||
if (state->mode == BAD) break;
|
||||
|
||||
/* build code tables */
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lenbits = 9;
|
||||
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
if (ret) {
|
||||
strm->msg = (char *)"invalid literal/lengths set";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->distcode = (code const FAR *)(state->next);
|
||||
state->distbits = 6;
|
||||
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
|
||||
&(state->next), &(state->distbits), state->work);
|
||||
if (ret) {
|
||||
strm->msg = (char *)"invalid distances set";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: codes ok\n"));
|
||||
state->mode = LEN;
|
||||
|
||||
case LEN:
|
||||
/* use inflate_fast() if we have enough input and output */
|
||||
if (have >= 6 && left >= 258) {
|
||||
RESTORE();
|
||||
if (state->whave < state->wsize)
|
||||
state->whave = state->wsize - left;
|
||||
inflate_fast(strm, state->wsize);
|
||||
LOAD();
|
||||
break;
|
||||
}
|
||||
|
||||
/* get a literal, length, or end-of-block code */
|
||||
for (;;) {
|
||||
this = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (this.op && (this.op & 0xf0) == 0) {
|
||||
last = this;
|
||||
for (;;) {
|
||||
this = state->lencode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + this.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(this.bits);
|
||||
state->length = (unsigned)this.val;
|
||||
|
||||
/* process literal */
|
||||
if (this.op == 0) {
|
||||
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", this.val));
|
||||
ROOM();
|
||||
*put++ = (unsigned char)(state->length);
|
||||
left--;
|
||||
state->mode = LEN;
|
||||
break;
|
||||
}
|
||||
|
||||
/* process end of block */
|
||||
if (this.op & 32) {
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* invalid code */
|
||||
if (this.op & 64) {
|
||||
strm->msg = (char *)"invalid literal/length code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
|
||||
/* length code -- get extra bits, if any */
|
||||
state->extra = (unsigned)(this.op) & 15;
|
||||
if (state->extra != 0) {
|
||||
NEEDBITS(state->extra);
|
||||
state->length += BITS(state->extra);
|
||||
DROPBITS(state->extra);
|
||||
}
|
||||
Tracevv((stderr, "inflate: length %u\n", state->length));
|
||||
|
||||
/* get distance code */
|
||||
for (;;) {
|
||||
this = state->distcode[BITS(state->distbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if ((this.op & 0xf0) == 0) {
|
||||
last = this;
|
||||
for (;;) {
|
||||
this = state->distcode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + this.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(this.bits);
|
||||
if (this.op & 64) {
|
||||
strm->msg = (char *)"invalid distance code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->offset = (unsigned)this.val;
|
||||
|
||||
/* get distance extra bits, if any */
|
||||
state->extra = (unsigned)(this.op) & 15;
|
||||
if (state->extra != 0) {
|
||||
NEEDBITS(state->extra);
|
||||
state->offset += BITS(state->extra);
|
||||
DROPBITS(state->extra);
|
||||
}
|
||||
if (state->offset > state->wsize - (state->whave < state->wsize ?
|
||||
left : 0)) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
Tracevv((stderr, "inflate: distance %u\n", state->offset));
|
||||
|
||||
/* copy match from window to output */
|
||||
do {
|
||||
ROOM();
|
||||
copy = state->wsize - state->offset;
|
||||
if (copy < left) {
|
||||
from = put + copy;
|
||||
copy = left - copy;
|
||||
}
|
||||
else {
|
||||
from = put - state->offset;
|
||||
copy = left;
|
||||
}
|
||||
if (copy > state->length) copy = state->length;
|
||||
state->length -= copy;
|
||||
left -= copy;
|
||||
do {
|
||||
*put++ = *from++;
|
||||
} while (--copy);
|
||||
} while (state->length != 0);
|
||||
break;
|
||||
|
||||
case DONE:
|
||||
/* inflate stream terminated properly -- write leftover output */
|
||||
ret = Z_STREAM_END;
|
||||
if (left < state->wsize) {
|
||||
if (out(out_desc, state->window, state->wsize - left))
|
||||
ret = Z_BUF_ERROR;
|
||||
}
|
||||
goto inf_leave;
|
||||
|
||||
case BAD:
|
||||
ret = Z_DATA_ERROR;
|
||||
goto inf_leave;
|
||||
|
||||
default: /* can't happen, but makes compilers happy */
|
||||
ret = Z_STREAM_ERROR;
|
||||
goto inf_leave;
|
||||
}
|
||||
|
||||
/* Return unused input */
|
||||
inf_leave:
|
||||
strm->next_in = next;
|
||||
strm->avail_in = have;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateBackEnd(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
|
||||
return Z_STREAM_ERROR;
|
||||
ZFREE(strm, strm->state);
|
||||
strm->state = Z_NULL;
|
||||
Tracev((stderr, "inflate: end\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/infback.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/infback.obj
Normal file
Binary file not shown.
318
contrib/fundamentals/ZLib/zlib123/inffast.c
Normal file
318
contrib/fundamentals/ZLib/zlib123/inffast.c
Normal file
@@ -0,0 +1,318 @@
|
||||
/* inffast.c -- fast decoding
|
||||
* Copyright (C) 1995-2004 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
#include "inffast.h"
|
||||
|
||||
#ifndef ASMINF
|
||||
|
||||
/* Allow machine dependent optimization for post-increment or pre-increment.
|
||||
Based on testing to date,
|
||||
Pre-increment preferred for:
|
||||
- PowerPC G3 (Adler)
|
||||
- MIPS R5000 (Randers-Pehrson)
|
||||
Post-increment preferred for:
|
||||
- none
|
||||
No measurable difference:
|
||||
- Pentium III (Anderson)
|
||||
- M68060 (Nikl)
|
||||
*/
|
||||
#ifdef POSTINC
|
||||
# define OFF 0
|
||||
# define PUP(a) *(a)++
|
||||
#else
|
||||
# define OFF 1
|
||||
# define PUP(a) *++(a)
|
||||
#endif
|
||||
|
||||
/*
|
||||
Decode literal, length, and distance codes and write out the resulting
|
||||
literal and match bytes until either not enough input or output is
|
||||
available, an end-of-block is encountered, or a data error is encountered.
|
||||
When large enough input and output buffers are supplied to inflate(), for
|
||||
example, a 16K input buffer and a 64K output buffer, more than 95% of the
|
||||
inflate execution time is spent in this routine.
|
||||
|
||||
Entry assumptions:
|
||||
|
||||
state->mode == LEN
|
||||
strm->avail_in >= 6
|
||||
strm->avail_out >= 258
|
||||
start >= strm->avail_out
|
||||
state->bits < 8
|
||||
|
||||
On return, state->mode is one of:
|
||||
|
||||
LEN -- ran out of enough output space or enough available input
|
||||
TYPE -- reached end of block code, inflate() to interpret next block
|
||||
BAD -- error in block data
|
||||
|
||||
Notes:
|
||||
|
||||
- The maximum input bits used by a length/distance pair is 15 bits for the
|
||||
length code, 5 bits for the length extra, 15 bits for the distance code,
|
||||
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
|
||||
Therefore if strm->avail_in >= 6, then there is enough input to avoid
|
||||
checking for available input while decoding.
|
||||
|
||||
- The maximum bytes that a single length/distance pair can output is 258
|
||||
bytes, which is the maximum length that can be coded. inflate_fast()
|
||||
requires strm->avail_out >= 258 for each loop to avoid checking for
|
||||
output space.
|
||||
*/
|
||||
void inflate_fast(strm, start)
|
||||
z_streamp strm;
|
||||
unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned char FAR *in; /* local strm->next_in */
|
||||
unsigned char FAR *last; /* while in < last, enough input available */
|
||||
unsigned char FAR *out; /* local strm->next_out */
|
||||
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
|
||||
unsigned char FAR *end; /* while out < end, enough space available */
|
||||
#ifdef INFLATE_STRICT
|
||||
unsigned dmax; /* maximum distance from zlib header */
|
||||
#endif
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned write; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
|
||||
unsigned long hold; /* local strm->hold */
|
||||
unsigned bits; /* local strm->bits */
|
||||
code const FAR *lcode; /* local strm->lencode */
|
||||
code const FAR *dcode; /* local strm->distcode */
|
||||
unsigned lmask; /* mask for first level of length codes */
|
||||
unsigned dmask; /* mask for first level of distance codes */
|
||||
code this; /* retrieved table entry */
|
||||
unsigned op; /* code bits, operation, extra bits, or */
|
||||
/* window position, window bytes to copy */
|
||||
unsigned len; /* match length, unused bytes */
|
||||
unsigned dist; /* match distance */
|
||||
unsigned char FAR *from; /* where to copy match from */
|
||||
|
||||
/* copy state to local variables */
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
in = strm->next_in - OFF;
|
||||
last = in + (strm->avail_in - 5);
|
||||
out = strm->next_out - OFF;
|
||||
beg = out - (start - strm->avail_out);
|
||||
end = out + (strm->avail_out - 257);
|
||||
#ifdef INFLATE_STRICT
|
||||
dmax = state->dmax;
|
||||
#endif
|
||||
wsize = state->wsize;
|
||||
whave = state->whave;
|
||||
write = state->write;
|
||||
window = state->window;
|
||||
hold = state->hold;
|
||||
bits = state->bits;
|
||||
lcode = state->lencode;
|
||||
dcode = state->distcode;
|
||||
lmask = (1U << state->lenbits) - 1;
|
||||
dmask = (1U << state->distbits) - 1;
|
||||
|
||||
/* decode literals and length/distances until end-of-block or not enough
|
||||
input data or output space */
|
||||
do {
|
||||
if (bits < 15) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
this = lcode[hold & lmask];
|
||||
dolen:
|
||||
op = (unsigned)(this.bits);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
op = (unsigned)(this.op);
|
||||
if (op == 0) { /* literal */
|
||||
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", this.val));
|
||||
PUP(out) = (unsigned char)(this.val);
|
||||
}
|
||||
else if (op & 16) { /* length base */
|
||||
len = (unsigned)(this.val);
|
||||
op &= 15; /* number of extra bits */
|
||||
if (op) {
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
len += (unsigned)hold & ((1U << op) - 1);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
}
|
||||
Tracevv((stderr, "inflate: length %u\n", len));
|
||||
if (bits < 15) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
this = dcode[hold & dmask];
|
||||
dodist:
|
||||
op = (unsigned)(this.bits);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
op = (unsigned)(this.op);
|
||||
if (op & 16) { /* distance base */
|
||||
dist = (unsigned)(this.val);
|
||||
op &= 15; /* number of extra bits */
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
}
|
||||
dist += (unsigned)hold & ((1U << op) - 1);
|
||||
#ifdef INFLATE_STRICT
|
||||
if (dist > dmax) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
Tracevv((stderr, "inflate: distance %u\n", dist));
|
||||
op = (unsigned)(out - beg); /* max distance in output */
|
||||
if (dist > op) { /* see if copy from window */
|
||||
op = dist - op; /* distance back in window */
|
||||
if (op > whave) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
from = window - OFF;
|
||||
if (write == 0) { /* very common case */
|
||||
from += wsize - op;
|
||||
if (op < len) { /* some from window */
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--op);
|
||||
from = out - dist; /* rest from output */
|
||||
}
|
||||
}
|
||||
else if (write < op) { /* wrap around window */
|
||||
from += wsize + write - op;
|
||||
op -= write;
|
||||
if (op < len) { /* some from end of window */
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--op);
|
||||
from = window - OFF;
|
||||
if (write < len) { /* some from start of window */
|
||||
op = write;
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--op);
|
||||
from = out - dist; /* rest from output */
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* contiguous in window */
|
||||
from += write - op;
|
||||
if (op < len) { /* some from window */
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--op);
|
||||
from = out - dist; /* rest from output */
|
||||
}
|
||||
}
|
||||
while (len > 2) {
|
||||
PUP(out) = PUP(from);
|
||||
PUP(out) = PUP(from);
|
||||
PUP(out) = PUP(from);
|
||||
len -= 3;
|
||||
}
|
||||
if (len) {
|
||||
PUP(out) = PUP(from);
|
||||
if (len > 1)
|
||||
PUP(out) = PUP(from);
|
||||
}
|
||||
}
|
||||
else {
|
||||
from = out - dist; /* copy direct from output */
|
||||
do { /* minimum length is three */
|
||||
PUP(out) = PUP(from);
|
||||
PUP(out) = PUP(from);
|
||||
PUP(out) = PUP(from);
|
||||
len -= 3;
|
||||
} while (len > 2);
|
||||
if (len) {
|
||||
PUP(out) = PUP(from);
|
||||
if (len > 1)
|
||||
PUP(out) = PUP(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((op & 64) == 0) { /* 2nd level distance code */
|
||||
this = dcode[this.val + (hold & ((1U << op) - 1))];
|
||||
goto dodist;
|
||||
}
|
||||
else {
|
||||
strm->msg = (char *)"invalid distance code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ((op & 64) == 0) { /* 2nd level length code */
|
||||
this = lcode[this.val + (hold & ((1U << op) - 1))];
|
||||
goto dolen;
|
||||
}
|
||||
else if (op & 32) { /* end-of-block */
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
strm->msg = (char *)"invalid literal/length code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
} while (in < last && out < end);
|
||||
|
||||
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
|
||||
len = bits >> 3;
|
||||
in -= len;
|
||||
bits -= len << 3;
|
||||
hold &= (1U << bits) - 1;
|
||||
|
||||
/* update state and return */
|
||||
strm->next_in = in + OFF;
|
||||
strm->next_out = out + OFF;
|
||||
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
|
||||
strm->avail_out = (unsigned)(out < end ?
|
||||
257 + (end - out) : 257 - (out - end));
|
||||
state->hold = hold;
|
||||
state->bits = bits;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
|
||||
- Using bit fields for code structure
|
||||
- Different op definition to avoid & for extra bits (do & for table bits)
|
||||
- Three separate decoding do-loops for direct, window, and write == 0
|
||||
- Special case for distance > 1 copies to do overlapped load and store copy
|
||||
- Explicit branch predictions (based on measured branch probabilities)
|
||||
- Deferring match copy and interspersed it with decoding subsequent codes
|
||||
- Swapping literal/length else
|
||||
- Swapping window/direct else
|
||||
- Larger unrolled copy loops (three is about right)
|
||||
- Moving len -= 3 statement into middle of loop
|
||||
*/
|
||||
|
||||
#endif /* !ASMINF */
|
||||
11
contrib/fundamentals/ZLib/zlib123/inffast.h
Normal file
11
contrib/fundamentals/ZLib/zlib123/inffast.h
Normal file
@@ -0,0 +1,11 @@
|
||||
/* inffast.h -- header to use inffast.c
|
||||
* Copyright (C) 1995-2003 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
void inflate_fast OF((z_streamp strm, unsigned start));
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/inffast.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/inffast.obj
Normal file
Binary file not shown.
94
contrib/fundamentals/ZLib/zlib123/inffixed.h
Normal file
94
contrib/fundamentals/ZLib/zlib123/inffixed.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/* inffixed.h -- table for decoding fixed codes
|
||||
* Generated automatically by makefixed().
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It
|
||||
is part of the implementation of the compression library and
|
||||
is subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
static const code lenfix[512] = {
|
||||
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
|
||||
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
|
||||
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
|
||||
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
|
||||
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
|
||||
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
|
||||
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
|
||||
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
|
||||
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
|
||||
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
|
||||
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
|
||||
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
|
||||
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
|
||||
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
|
||||
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
|
||||
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
|
||||
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
|
||||
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
|
||||
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
|
||||
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
|
||||
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
|
||||
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
|
||||
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
|
||||
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
|
||||
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
|
||||
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
|
||||
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
|
||||
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
|
||||
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
|
||||
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
|
||||
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
|
||||
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
|
||||
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
|
||||
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
|
||||
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
|
||||
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
|
||||
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
|
||||
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
|
||||
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
|
||||
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
|
||||
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
|
||||
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
|
||||
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
|
||||
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
|
||||
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
|
||||
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
|
||||
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
|
||||
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
|
||||
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
|
||||
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
|
||||
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
|
||||
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
|
||||
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
|
||||
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
|
||||
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
|
||||
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
|
||||
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
|
||||
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
|
||||
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
|
||||
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
|
||||
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
|
||||
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
|
||||
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
|
||||
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
|
||||
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
|
||||
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
|
||||
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
|
||||
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
|
||||
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
|
||||
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
|
||||
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
|
||||
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
|
||||
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
|
||||
{0,9,255}
|
||||
};
|
||||
|
||||
static const code distfix[32] = {
|
||||
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
|
||||
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
|
||||
{18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
|
||||
{19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
|
||||
{16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
|
||||
{22,5,193},{64,5,0}
|
||||
};
|
||||
1368
contrib/fundamentals/ZLib/zlib123/inflate.c
Normal file
1368
contrib/fundamentals/ZLib/zlib123/inflate.c
Normal file
File diff suppressed because it is too large
Load Diff
115
contrib/fundamentals/ZLib/zlib123/inflate.h
Normal file
115
contrib/fundamentals/ZLib/zlib123/inflate.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/* inflate.h -- internal inflate state definition
|
||||
* Copyright (C) 1995-2004 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* define NO_GZIP when compiling if you want to disable gzip header and
|
||||
trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
|
||||
the crc code when it is not needed. For shared libraries, gzip decoding
|
||||
should be left enabled. */
|
||||
#ifndef NO_GZIP
|
||||
# define GUNZIP
|
||||
#endif
|
||||
|
||||
/* Possible inflate modes between inflate() calls */
|
||||
typedef enum {
|
||||
HEAD, /* i: waiting for magic header */
|
||||
FLAGS, /* i: waiting for method and flags (gzip) */
|
||||
TIME, /* i: waiting for modification time (gzip) */
|
||||
OS, /* i: waiting for extra flags and operating system (gzip) */
|
||||
EXLEN, /* i: waiting for extra length (gzip) */
|
||||
EXTRA, /* i: waiting for extra bytes (gzip) */
|
||||
NAME, /* i: waiting for end of file name (gzip) */
|
||||
COMMENT, /* i: waiting for end of comment (gzip) */
|
||||
HCRC, /* i: waiting for header crc (gzip) */
|
||||
DICTID, /* i: waiting for dictionary check value */
|
||||
DICT, /* waiting for inflateSetDictionary() call */
|
||||
TYPE, /* i: waiting for type bits, including last-flag bit */
|
||||
TYPEDO, /* i: same, but skip check to exit inflate on new block */
|
||||
STORED, /* i: waiting for stored size (length and complement) */
|
||||
COPY, /* i/o: waiting for input or output to copy stored block */
|
||||
TABLE, /* i: waiting for dynamic block table lengths */
|
||||
LENLENS, /* i: waiting for code length code lengths */
|
||||
CODELENS, /* i: waiting for length/lit and distance code lengths */
|
||||
LEN, /* i: waiting for length/lit code */
|
||||
LENEXT, /* i: waiting for length extra bits */
|
||||
DIST, /* i: waiting for distance code */
|
||||
DISTEXT, /* i: waiting for distance extra bits */
|
||||
MATCH, /* o: waiting for output space to copy string */
|
||||
LIT, /* o: waiting for output space to write literal */
|
||||
CHECK, /* i: waiting for 32-bit check value */
|
||||
LENGTH, /* i: waiting for 32-bit length (gzip) */
|
||||
DONE, /* finished check, done -- remain here until reset */
|
||||
BAD, /* got a data error -- remain here until reset */
|
||||
MEM, /* got an inflate() memory error -- remain here until reset */
|
||||
SYNC /* looking for synchronization bytes to restart inflate() */
|
||||
} inflate_mode;
|
||||
|
||||
/*
|
||||
State transitions between above modes -
|
||||
|
||||
(most modes can go to the BAD or MEM mode -- not shown for clarity)
|
||||
|
||||
Process header:
|
||||
HEAD -> (gzip) or (zlib)
|
||||
(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
|
||||
NAME -> COMMENT -> HCRC -> TYPE
|
||||
(zlib) -> DICTID or TYPE
|
||||
DICTID -> DICT -> TYPE
|
||||
Read deflate blocks:
|
||||
TYPE -> STORED or TABLE or LEN or CHECK
|
||||
STORED -> COPY -> TYPE
|
||||
TABLE -> LENLENS -> CODELENS -> LEN
|
||||
Read deflate codes:
|
||||
LEN -> LENEXT or LIT or TYPE
|
||||
LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
|
||||
LIT -> LEN
|
||||
Process trailer:
|
||||
CHECK -> LENGTH -> DONE
|
||||
*/
|
||||
|
||||
/* state maintained between inflate() calls. Approximately 7K bytes. */
|
||||
struct inflate_state {
|
||||
inflate_mode mode; /* current inflate mode */
|
||||
int last; /* true if processing last block */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||
int havedict; /* true if dictionary provided */
|
||||
int flags; /* gzip header method and flags (0 if zlib) */
|
||||
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
|
||||
unsigned long check; /* protected copy of check value */
|
||||
unsigned long total; /* protected copy of output count */
|
||||
gz_headerp head; /* where to save gzip header information */
|
||||
/* sliding window */
|
||||
unsigned wbits; /* log base 2 of requested window size */
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned write; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if needed */
|
||||
/* bit accumulator */
|
||||
unsigned long hold; /* input bit accumulator */
|
||||
unsigned bits; /* number of bits in "in" */
|
||||
/* for string and stored block copying */
|
||||
unsigned length; /* literal or length of data to copy */
|
||||
unsigned offset; /* distance back to copy string from */
|
||||
/* for table and code decoding */
|
||||
unsigned extra; /* extra bits needed */
|
||||
/* fixed and dynamic code tables */
|
||||
code const FAR *lencode; /* starting table for length/literal codes */
|
||||
code const FAR *distcode; /* starting table for distance codes */
|
||||
unsigned lenbits; /* index bits for lencode */
|
||||
unsigned distbits; /* index bits for distcode */
|
||||
/* dynamic table building */
|
||||
unsigned ncode; /* number of code length code lengths */
|
||||
unsigned nlen; /* number of length code lengths */
|
||||
unsigned ndist; /* number of distance code lengths */
|
||||
unsigned have; /* number of code lengths in lens[] */
|
||||
code FAR *next; /* next available space in codes[] */
|
||||
unsigned short lens[320]; /* temporary storage for code lengths */
|
||||
unsigned short work[288]; /* work area for code table building */
|
||||
code codes[ENOUGH]; /* space for code tables */
|
||||
};
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/inflate.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/inflate.obj
Normal file
Binary file not shown.
329
contrib/fundamentals/ZLib/zlib123/inftrees.c
Normal file
329
contrib/fundamentals/ZLib/zlib123/inftrees.c
Normal file
@@ -0,0 +1,329 @@
|
||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-2005 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
|
||||
#define MAXBITS 15
|
||||
|
||||
const char inflate_copyright[] =
|
||||
" inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
|
||||
/*
|
||||
If you use the zlib library in a product, an acknowledgment is welcome
|
||||
in the documentation of your product. If for some reason you cannot
|
||||
include such an acknowledgment, I would appreciate that you keep this
|
||||
copyright string in the executable of your product.
|
||||
*/
|
||||
|
||||
/*
|
||||
Build a set of tables to decode the provided canonical Huffman code.
|
||||
The code lengths are lens[0..codes-1]. The result starts at *table,
|
||||
whose indices are 0..2^bits-1. work is a writable array of at least
|
||||
lens shorts, which is used as a work area. type is the type of code
|
||||
to be generated, CODES, LENS, or DISTS. On return, zero is success,
|
||||
-1 is an invalid code, and +1 means that ENOUGH isn't enough. table
|
||||
on return points to the next available entry's address. bits is the
|
||||
requested root table index bits, and on return it is the actual root
|
||||
table index bits. It will differ if the request is greater than the
|
||||
longest code or if it is less than the shortest code.
|
||||
*/
|
||||
int inflate_table(type, lens, codes, table, bits, work)
|
||||
codetype type;
|
||||
unsigned short FAR *lens;
|
||||
unsigned codes;
|
||||
code FAR * FAR *table;
|
||||
unsigned FAR *bits;
|
||||
unsigned short FAR *work;
|
||||
{
|
||||
unsigned len; /* a code's length in bits */
|
||||
unsigned sym; /* index of code symbols */
|
||||
unsigned min, max; /* minimum and maximum code lengths */
|
||||
unsigned root; /* number of index bits for root table */
|
||||
unsigned curr; /* number of index bits for current table */
|
||||
unsigned drop; /* code bits to drop for sub-table */
|
||||
int left; /* number of prefix codes available */
|
||||
unsigned used; /* code entries in table used */
|
||||
unsigned huff; /* Huffman code */
|
||||
unsigned incr; /* for incrementing code, index */
|
||||
unsigned fill; /* index for replicating entries */
|
||||
unsigned low; /* low bits for current root entry */
|
||||
unsigned mask; /* mask for low root bits */
|
||||
code this; /* table entry for duplication */
|
||||
code FAR *next; /* next available space in table */
|
||||
const unsigned short FAR *base; /* base value table to use */
|
||||
const unsigned short FAR *extra; /* extra bits table to use */
|
||||
int end; /* use base and extra for symbol > end */
|
||||
unsigned short count[MAXBITS+1]; /* number of codes of each length */
|
||||
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
|
||||
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
|
||||
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
|
||||
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577, 0, 0};
|
||||
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
|
||||
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
|
||||
23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
|
||||
28, 28, 29, 29, 64, 64};
|
||||
|
||||
/*
|
||||
Process a set of code lengths to create a canonical Huffman code. The
|
||||
code lengths are lens[0..codes-1]. Each length corresponds to the
|
||||
symbols 0..codes-1. The Huffman code is generated by first sorting the
|
||||
symbols by length from short to long, and retaining the symbol order
|
||||
for codes with equal lengths. Then the code starts with all zero bits
|
||||
for the first code of the shortest length, and the codes are integer
|
||||
increments for the same length, and zeros are appended as the length
|
||||
increases. For the deflate format, these bits are stored backwards
|
||||
from their more natural integer increment ordering, and so when the
|
||||
decoding tables are built in the large loop below, the integer codes
|
||||
are incremented backwards.
|
||||
|
||||
This routine assumes, but does not check, that all of the entries in
|
||||
lens[] are in the range 0..MAXBITS. The caller must assure this.
|
||||
1..MAXBITS is interpreted as that code length. zero means that that
|
||||
symbol does not occur in this code.
|
||||
|
||||
The codes are sorted by computing a count of codes for each length,
|
||||
creating from that a table of starting indices for each length in the
|
||||
sorted table, and then entering the symbols in order in the sorted
|
||||
table. The sorted table is work[], with that space being provided by
|
||||
the caller.
|
||||
|
||||
The length counts are used for other purposes as well, i.e. finding
|
||||
the minimum and maximum length codes, determining if there are any
|
||||
codes at all, checking for a valid set of lengths, and looking ahead
|
||||
at length counts to determine sub-table sizes when building the
|
||||
decoding tables.
|
||||
*/
|
||||
|
||||
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
|
||||
for (len = 0; len <= MAXBITS; len++)
|
||||
count[len] = 0;
|
||||
for (sym = 0; sym < codes; sym++)
|
||||
count[lens[sym]]++;
|
||||
|
||||
/* bound code lengths, force root to be within code lengths */
|
||||
root = *bits;
|
||||
for (max = MAXBITS; max >= 1; max--)
|
||||
if (count[max] != 0) break;
|
||||
if (root > max) root = max;
|
||||
if (max == 0) { /* no symbols to code at all */
|
||||
this.op = (unsigned char)64; /* invalid code marker */
|
||||
this.bits = (unsigned char)1;
|
||||
this.val = (unsigned short)0;
|
||||
*(*table)++ = this; /* make a table to force an error */
|
||||
*(*table)++ = this;
|
||||
*bits = 1;
|
||||
return 0; /* no symbols, but wait for decoding to report error */
|
||||
}
|
||||
for (min = 1; min <= MAXBITS; min++)
|
||||
if (count[min] != 0) break;
|
||||
if (root < min) root = min;
|
||||
|
||||
/* check for an over-subscribed or incomplete set of lengths */
|
||||
left = 1;
|
||||
for (len = 1; len <= MAXBITS; len++) {
|
||||
left <<= 1;
|
||||
left -= count[len];
|
||||
if (left < 0) return -1; /* over-subscribed */
|
||||
}
|
||||
if (left > 0 && (type == CODES || max != 1))
|
||||
return -1; /* incomplete set */
|
||||
|
||||
/* generate offsets into symbol table for each length for sorting */
|
||||
offs[1] = 0;
|
||||
for (len = 1; len < MAXBITS; len++)
|
||||
offs[len + 1] = offs[len] + count[len];
|
||||
|
||||
/* sort symbols by length, by symbol order within each length */
|
||||
for (sym = 0; sym < codes; sym++)
|
||||
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
|
||||
|
||||
/*
|
||||
Create and fill in decoding tables. In this loop, the table being
|
||||
filled is at next and has curr index bits. The code being used is huff
|
||||
with length len. That code is converted to an index by dropping drop
|
||||
bits off of the bottom. For codes where len is less than drop + curr,
|
||||
those top drop + curr - len bits are incremented through all values to
|
||||
fill the table with replicated entries.
|
||||
|
||||
root is the number of index bits for the root table. When len exceeds
|
||||
root, sub-tables are created pointed to by the root entry with an index
|
||||
of the low root bits of huff. This is saved in low to check for when a
|
||||
new sub-table should be started. drop is zero when the root table is
|
||||
being filled, and drop is root when sub-tables are being filled.
|
||||
|
||||
When a new sub-table is needed, it is necessary to look ahead in the
|
||||
code lengths to determine what size sub-table is needed. The length
|
||||
counts are used for this, and so count[] is decremented as codes are
|
||||
entered in the tables.
|
||||
|
||||
used keeps track of how many table entries have been allocated from the
|
||||
provided *table space. It is checked when a LENS table is being made
|
||||
against the space in *table, ENOUGH, minus the maximum space needed by
|
||||
the worst case distance code, MAXD. This should never happen, but the
|
||||
sufficiency of ENOUGH has not been proven exhaustively, hence the check.
|
||||
This assumes that when type == LENS, bits == 9.
|
||||
|
||||
sym increments through all symbols, and the loop terminates when
|
||||
all codes of length max, i.e. all codes, have been processed. This
|
||||
routine permits incomplete codes, so another loop after this one fills
|
||||
in the rest of the decoding tables with invalid code markers.
|
||||
*/
|
||||
|
||||
/* set up for code type */
|
||||
switch (type) {
|
||||
case CODES:
|
||||
base = extra = work; /* dummy value--not used */
|
||||
end = 19;
|
||||
break;
|
||||
case LENS:
|
||||
base = lbase;
|
||||
base -= 257;
|
||||
extra = lext;
|
||||
extra -= 257;
|
||||
end = 256;
|
||||
break;
|
||||
default: /* DISTS */
|
||||
base = dbase;
|
||||
extra = dext;
|
||||
end = -1;
|
||||
}
|
||||
|
||||
/* initialize state for loop */
|
||||
huff = 0; /* starting code */
|
||||
sym = 0; /* starting code symbol */
|
||||
len = min; /* starting code length */
|
||||
next = *table; /* current table to fill in */
|
||||
curr = root; /* current table index bits */
|
||||
drop = 0; /* current bits to drop from code for index */
|
||||
low = (unsigned)(-1); /* trigger new sub-table when len > root */
|
||||
used = 1U << root; /* use root table entries */
|
||||
mask = used - 1; /* mask for comparing low */
|
||||
|
||||
/* check available table space */
|
||||
if (type == LENS && used >= ENOUGH - MAXD)
|
||||
return 1;
|
||||
|
||||
/* process all codes and make table entries */
|
||||
for (;;) {
|
||||
/* create table entry */
|
||||
this.bits = (unsigned char)(len - drop);
|
||||
if ((int)(work[sym]) < end) {
|
||||
this.op = (unsigned char)0;
|
||||
this.val = work[sym];
|
||||
}
|
||||
else if ((int)(work[sym]) > end) {
|
||||
this.op = (unsigned char)(extra[work[sym]]);
|
||||
this.val = base[work[sym]];
|
||||
}
|
||||
else {
|
||||
this.op = (unsigned char)(32 + 64); /* end of block */
|
||||
this.val = 0;
|
||||
}
|
||||
|
||||
/* replicate for those indices with low len bits equal to huff */
|
||||
incr = 1U << (len - drop);
|
||||
fill = 1U << curr;
|
||||
min = fill; /* save offset to next table */
|
||||
do {
|
||||
fill -= incr;
|
||||
next[(huff >> drop) + fill] = this;
|
||||
} while (fill != 0);
|
||||
|
||||
/* backwards increment the len-bit code huff */
|
||||
incr = 1U << (len - 1);
|
||||
while (huff & incr)
|
||||
incr >>= 1;
|
||||
if (incr != 0) {
|
||||
huff &= incr - 1;
|
||||
huff += incr;
|
||||
}
|
||||
else
|
||||
huff = 0;
|
||||
|
||||
/* go to next symbol, update count, len */
|
||||
sym++;
|
||||
if (--(count[len]) == 0) {
|
||||
if (len == max) break;
|
||||
len = lens[work[sym]];
|
||||
}
|
||||
|
||||
/* create new sub-table if needed */
|
||||
if (len > root && (huff & mask) != low) {
|
||||
/* if first time, transition to sub-tables */
|
||||
if (drop == 0)
|
||||
drop = root;
|
||||
|
||||
/* increment past last table */
|
||||
next += min; /* here min is 1 << curr */
|
||||
|
||||
/* determine length of next table */
|
||||
curr = len - drop;
|
||||
left = (int)(1 << curr);
|
||||
while (curr + drop < max) {
|
||||
left -= count[curr + drop];
|
||||
if (left <= 0) break;
|
||||
curr++;
|
||||
left <<= 1;
|
||||
}
|
||||
|
||||
/* check for enough space */
|
||||
used += 1U << curr;
|
||||
if (type == LENS && used >= ENOUGH - MAXD)
|
||||
return 1;
|
||||
|
||||
/* point entry in root table to sub-table */
|
||||
low = huff & mask;
|
||||
(*table)[low].op = (unsigned char)curr;
|
||||
(*table)[low].bits = (unsigned char)root;
|
||||
(*table)[low].val = (unsigned short)(next - *table);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Fill in rest of table for incomplete codes. This loop is similar to the
|
||||
loop above in incrementing huff for table indices. It is assumed that
|
||||
len is equal to curr + drop, so there is no loop needed to increment
|
||||
through high index bits. When the current sub-table is filled, the loop
|
||||
drops back to the root table to fill in any remaining entries there.
|
||||
*/
|
||||
this.op = (unsigned char)64; /* invalid code marker */
|
||||
this.bits = (unsigned char)(len - drop);
|
||||
this.val = (unsigned short)0;
|
||||
while (huff != 0) {
|
||||
/* when done with sub-table, drop back to root table */
|
||||
if (drop != 0 && (huff & mask) != low) {
|
||||
drop = 0;
|
||||
len = root;
|
||||
next = *table;
|
||||
this.bits = (unsigned char)len;
|
||||
}
|
||||
|
||||
/* put invalid code marker in table */
|
||||
next[huff >> drop] = this;
|
||||
|
||||
/* backwards increment the len-bit code huff */
|
||||
incr = 1U << (len - 1);
|
||||
while (huff & incr)
|
||||
incr >>= 1;
|
||||
if (incr != 0) {
|
||||
huff &= incr - 1;
|
||||
huff += incr;
|
||||
}
|
||||
else
|
||||
huff = 0;
|
||||
}
|
||||
|
||||
/* set return parameters */
|
||||
*table += used;
|
||||
*bits = root;
|
||||
return 0;
|
||||
}
|
||||
55
contrib/fundamentals/ZLib/zlib123/inftrees.h
Normal file
55
contrib/fundamentals/ZLib/zlib123/inftrees.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* inftrees.h -- header to use inftrees.c
|
||||
* Copyright (C) 1995-2005 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* Structure for decoding tables. Each entry provides either the
|
||||
information needed to do the operation requested by the code that
|
||||
indexed that table entry, or it provides a pointer to another
|
||||
table that indexes more bits of the code. op indicates whether
|
||||
the entry is a pointer to another table, a literal, a length or
|
||||
distance, an end-of-block, or an invalid code. For a table
|
||||
pointer, the low four bits of op is the number of index bits of
|
||||
that table. For a length or distance, the low four bits of op
|
||||
is the number of extra bits to get after the code. bits is
|
||||
the number of bits in this code or part of the code to drop off
|
||||
of the bit buffer. val is the actual byte to output in the case
|
||||
of a literal, the base length or distance, or the offset from
|
||||
the current table to the next table. Each entry is four bytes. */
|
||||
typedef struct {
|
||||
unsigned char op; /* operation, extra bits, table bits */
|
||||
unsigned char bits; /* bits in this part of the code */
|
||||
unsigned short val; /* offset in table or code value */
|
||||
} code;
|
||||
|
||||
/* op values as set by inflate_table():
|
||||
00000000 - literal
|
||||
0000tttt - table link, tttt != 0 is the number of table index bits
|
||||
0001eeee - length or distance, eeee is the number of extra bits
|
||||
01100000 - end of block
|
||||
01000000 - invalid code
|
||||
*/
|
||||
|
||||
/* Maximum size of dynamic tree. The maximum found in a long but non-
|
||||
exhaustive search was 1444 code structures (852 for length/literals
|
||||
and 592 for distances, the latter actually the result of an
|
||||
exhaustive search). The true maximum is not known, but the value
|
||||
below is more than safe. */
|
||||
#define ENOUGH 2048
|
||||
#define MAXD 592
|
||||
|
||||
/* Type of code to build for inftable() */
|
||||
typedef enum {
|
||||
CODES,
|
||||
LENS,
|
||||
DISTS
|
||||
} codetype;
|
||||
|
||||
extern int inflate_table OF((codetype type, unsigned short FAR *lens,
|
||||
unsigned codes, code FAR * FAR *table,
|
||||
unsigned FAR *bits, unsigned short FAR *work));
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/inftrees.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/inftrees.obj
Normal file
Binary file not shown.
322
contrib/fundamentals/ZLib/zlib123/minigzip.c
Normal file
322
contrib/fundamentals/ZLib/zlib123/minigzip.c
Normal file
@@ -0,0 +1,322 @@
|
||||
/* minigzip.c -- simulate gzip using the zlib compression library
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/*
|
||||
* minigzip is a minimal implementation of the gzip utility. This is
|
||||
* only an example of using zlib and isn't meant to replace the
|
||||
* full-featured gzip. No attempt is made to deal with file systems
|
||||
* limiting names to 14 or 8+3 characters, etc... Error checking is
|
||||
* very limited. So use minigzip only for testing; use gzip for the
|
||||
* real thing. On MSDOS, use only on file names without extension
|
||||
* or in pipe mode.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef STDC
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_MMAP
|
||||
# include <sys/types.h>
|
||||
# include <sys/mman.h>
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
|
||||
# include <fcntl.h>
|
||||
# include <io.h>
|
||||
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
|
||||
#else
|
||||
# define SET_BINARY_MODE(file)
|
||||
#endif
|
||||
|
||||
#ifdef VMS
|
||||
# define unlink delete
|
||||
# define GZ_SUFFIX "-gz"
|
||||
#endif
|
||||
#ifdef RISCOS
|
||||
# define unlink remove
|
||||
# define GZ_SUFFIX "-gz"
|
||||
# define fileno(file) file->__file
|
||||
#endif
|
||||
#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
||||
# include <unix.h> /* for fileno */
|
||||
#endif
|
||||
|
||||
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
|
||||
extern int unlink OF((const char *));
|
||||
#endif
|
||||
|
||||
#ifndef GZ_SUFFIX
|
||||
# define GZ_SUFFIX ".gz"
|
||||
#endif
|
||||
#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
|
||||
|
||||
#define BUFLEN 16384
|
||||
#define MAX_NAME_LEN 1024
|
||||
|
||||
#ifdef MAXSEG_64K
|
||||
# define local static
|
||||
/* Needed for systems with limitation on stack size. */
|
||||
#else
|
||||
# define local
|
||||
#endif
|
||||
|
||||
char *prog;
|
||||
|
||||
void error OF((const char *msg));
|
||||
void gz_compress OF((FILE *in, gzFile out));
|
||||
#ifdef USE_MMAP
|
||||
int gz_compress_mmap OF((FILE *in, gzFile out));
|
||||
#endif
|
||||
void gz_uncompress OF((gzFile in, FILE *out));
|
||||
void file_compress OF((char *file, char *mode));
|
||||
void file_uncompress OF((char *file));
|
||||
int main OF((int argc, char *argv[]));
|
||||
|
||||
/* ===========================================================================
|
||||
* Display error message and exit
|
||||
*/
|
||||
void error(msg)
|
||||
const char *msg;
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", prog, msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Compress input to output then close both files.
|
||||
*/
|
||||
|
||||
void gz_compress(in, out)
|
||||
FILE *in;
|
||||
gzFile out;
|
||||
{
|
||||
local char buf[BUFLEN];
|
||||
int len;
|
||||
int err;
|
||||
|
||||
#ifdef USE_MMAP
|
||||
/* Try first compressing with mmap. If mmap fails (minigzip used in a
|
||||
* pipe), use the normal fread loop.
|
||||
*/
|
||||
if (gz_compress_mmap(in, out) == Z_OK) return;
|
||||
#endif
|
||||
for (;;) {
|
||||
len = (int)fread(buf, 1, sizeof(buf), in);
|
||||
if (ferror(in)) {
|
||||
perror("fread");
|
||||
exit(1);
|
||||
}
|
||||
if (len == 0) break;
|
||||
|
||||
if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
|
||||
}
|
||||
fclose(in);
|
||||
if (gzclose(out) != Z_OK) error("failed gzclose");
|
||||
}
|
||||
|
||||
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
|
||||
|
||||
/* Try compressing the input file at once using mmap. Return Z_OK if
|
||||
* if success, Z_ERRNO otherwise.
|
||||
*/
|
||||
int gz_compress_mmap(in, out)
|
||||
FILE *in;
|
||||
gzFile out;
|
||||
{
|
||||
int len;
|
||||
int err;
|
||||
int ifd = fileno(in);
|
||||
caddr_t buf; /* mmap'ed buffer for the entire input file */
|
||||
off_t buf_len; /* length of the input file */
|
||||
struct stat sb;
|
||||
|
||||
/* Determine the size of the file, needed for mmap: */
|
||||
if (fstat(ifd, &sb) < 0) return Z_ERRNO;
|
||||
buf_len = sb.st_size;
|
||||
if (buf_len <= 0) return Z_ERRNO;
|
||||
|
||||
/* Now do the actual mmap: */
|
||||
buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
|
||||
if (buf == (caddr_t)(-1)) return Z_ERRNO;
|
||||
|
||||
/* Compress the whole file at once: */
|
||||
len = gzwrite(out, (char *)buf, (unsigned)buf_len);
|
||||
|
||||
if (len != (int)buf_len) error(gzerror(out, &err));
|
||||
|
||||
munmap(buf, buf_len);
|
||||
fclose(in);
|
||||
if (gzclose(out) != Z_OK) error("failed gzclose");
|
||||
return Z_OK;
|
||||
}
|
||||
#endif /* USE_MMAP */
|
||||
|
||||
/* ===========================================================================
|
||||
* Uncompress input to output then close both files.
|
||||
*/
|
||||
void gz_uncompress(in, out)
|
||||
gzFile in;
|
||||
FILE *out;
|
||||
{
|
||||
local char buf[BUFLEN];
|
||||
int len;
|
||||
int err;
|
||||
|
||||
for (;;) {
|
||||
len = gzread(in, buf, sizeof(buf));
|
||||
if (len < 0) error (gzerror(in, &err));
|
||||
if (len == 0) break;
|
||||
|
||||
if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
|
||||
error("failed fwrite");
|
||||
}
|
||||
}
|
||||
if (fclose(out)) error("failed fclose");
|
||||
|
||||
if (gzclose(in) != Z_OK) error("failed gzclose");
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Compress the given file: create a corresponding .gz file and remove the
|
||||
* original.
|
||||
*/
|
||||
void file_compress(file, mode)
|
||||
char *file;
|
||||
char *mode;
|
||||
{
|
||||
local char outfile[MAX_NAME_LEN];
|
||||
FILE *in;
|
||||
gzFile out;
|
||||
|
||||
strcpy(outfile, file);
|
||||
strcat(outfile, GZ_SUFFIX);
|
||||
|
||||
in = fopen(file, "rb");
|
||||
if (in == NULL) {
|
||||
perror(file);
|
||||
exit(1);
|
||||
}
|
||||
out = gzopen(outfile, mode);
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
|
||||
exit(1);
|
||||
}
|
||||
gz_compress(in, out);
|
||||
|
||||
unlink(file);
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Uncompress the given file and remove the original.
|
||||
*/
|
||||
void file_uncompress(file)
|
||||
char *file;
|
||||
{
|
||||
local char buf[MAX_NAME_LEN];
|
||||
char *infile, *outfile;
|
||||
FILE *out;
|
||||
gzFile in;
|
||||
uInt len = (uInt)strlen(file);
|
||||
|
||||
strcpy(buf, file);
|
||||
|
||||
if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
|
||||
infile = file;
|
||||
outfile = buf;
|
||||
outfile[len-3] = '\0';
|
||||
} else {
|
||||
outfile = file;
|
||||
infile = buf;
|
||||
strcat(infile, GZ_SUFFIX);
|
||||
}
|
||||
in = gzopen(infile, "rb");
|
||||
if (in == NULL) {
|
||||
fprintf(stderr, "%s: can't gzopen %s\n", prog, infile);
|
||||
exit(1);
|
||||
}
|
||||
out = fopen(outfile, "wb");
|
||||
if (out == NULL) {
|
||||
perror(file);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gz_uncompress(in, out);
|
||||
|
||||
unlink(infile);
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...]
|
||||
* -d : decompress
|
||||
* -f : compress with Z_FILTERED
|
||||
* -h : compress with Z_HUFFMAN_ONLY
|
||||
* -r : compress with Z_RLE
|
||||
* -1 to -9 : compression level
|
||||
*/
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int uncompr = 0;
|
||||
gzFile file;
|
||||
char outmode[20];
|
||||
|
||||
strcpy(outmode, "wb6 ");
|
||||
|
||||
prog = argv[0];
|
||||
argc--, argv++;
|
||||
|
||||
while (argc > 0) {
|
||||
if (strcmp(*argv, "-d") == 0)
|
||||
uncompr = 1;
|
||||
else if (strcmp(*argv, "-f") == 0)
|
||||
outmode[3] = 'f';
|
||||
else if (strcmp(*argv, "-h") == 0)
|
||||
outmode[3] = 'h';
|
||||
else if (strcmp(*argv, "-r") == 0)
|
||||
outmode[3] = 'R';
|
||||
else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
|
||||
(*argv)[2] == 0)
|
||||
outmode[2] = (*argv)[1];
|
||||
else
|
||||
break;
|
||||
argc--, argv++;
|
||||
}
|
||||
if (outmode[3] == ' ')
|
||||
outmode[3] = 0;
|
||||
if (argc == 0) {
|
||||
SET_BINARY_MODE(stdin);
|
||||
SET_BINARY_MODE(stdout);
|
||||
if (uncompr) {
|
||||
file = gzdopen(fileno(stdin), "rb");
|
||||
if (file == NULL) error("can't gzdopen stdin");
|
||||
gz_uncompress(file, stdout);
|
||||
} else {
|
||||
file = gzdopen(fileno(stdout), outmode);
|
||||
if (file == NULL) error("can't gzdopen stdout");
|
||||
gz_compress(stdin, file);
|
||||
}
|
||||
} else {
|
||||
do {
|
||||
if (uncompr) {
|
||||
file_uncompress(*argv);
|
||||
} else {
|
||||
file_compress(*argv, outmode);
|
||||
}
|
||||
} while (argv++, --argc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1219
contrib/fundamentals/ZLib/zlib123/trees.c
Normal file
1219
contrib/fundamentals/ZLib/zlib123/trees.c
Normal file
File diff suppressed because it is too large
Load Diff
128
contrib/fundamentals/ZLib/zlib123/trees.h
Normal file
128
contrib/fundamentals/ZLib/zlib123/trees.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/* header created automatically with -DGEN_TREES_H */
|
||||
|
||||
local const ct_data static_ltree[L_CODES+2] = {
|
||||
{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
|
||||
{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
|
||||
{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
|
||||
{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
|
||||
{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
|
||||
{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
|
||||
{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
|
||||
{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
|
||||
{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
|
||||
{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
|
||||
{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
|
||||
{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
|
||||
{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
|
||||
{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
|
||||
{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
|
||||
{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
|
||||
{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
|
||||
{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
|
||||
{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
|
||||
{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
|
||||
{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
|
||||
{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
|
||||
{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
|
||||
{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
|
||||
{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
|
||||
{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
|
||||
{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
|
||||
{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
|
||||
{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
|
||||
{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
|
||||
{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
|
||||
{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
|
||||
{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
|
||||
{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
|
||||
{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
|
||||
{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
|
||||
{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
|
||||
{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
|
||||
{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
|
||||
{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
|
||||
{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
|
||||
{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
|
||||
{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
|
||||
{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
|
||||
{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
|
||||
{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
|
||||
{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
|
||||
{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
|
||||
{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
|
||||
{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
|
||||
{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
|
||||
{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
|
||||
{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
|
||||
{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
|
||||
{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
|
||||
{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
|
||||
{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
|
||||
{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
|
||||
};
|
||||
|
||||
local const ct_data static_dtree[D_CODES] = {
|
||||
{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
|
||||
{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
|
||||
{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
|
||||
{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
|
||||
{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
|
||||
{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
|
||||
};
|
||||
|
||||
const uch _dist_code[DIST_CODE_LEN] = {
|
||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
|
||||
18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||
};
|
||||
|
||||
const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
||||
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
|
||||
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
|
||||
};
|
||||
|
||||
local const int base_length[LENGTH_CODES] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
|
||||
64, 80, 96, 112, 128, 160, 192, 224, 0
|
||||
};
|
||||
|
||||
local const int base_dist[D_CODES] = {
|
||||
0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
|
||||
32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
|
||||
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
|
||||
};
|
||||
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/trees.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/trees.obj
Normal file
Binary file not shown.
61
contrib/fundamentals/ZLib/zlib123/uncompr.c
Normal file
61
contrib/fundamentals/ZLib/zlib123/uncompr.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* uncompr.c -- decompress a memory buffer
|
||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
|
||||
/* ===========================================================================
|
||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be large enough to hold the
|
||||
entire uncompressed data. (The size of the uncompressed data must have
|
||||
been saved previously by the compressor and transmitted to the decompressor
|
||||
by some mechanism outside the scope of this compression library.)
|
||||
Upon exit, destLen is the actual size of the compressed buffer.
|
||||
This function can be used to decompress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
|
||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||
*/
|
||||
int ZEXPORT uncompress (dest, destLen, source, sourceLen)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
{
|
||||
z_stream stream;
|
||||
int err;
|
||||
|
||||
stream.next_in = (Bytef*)source;
|
||||
stream.avail_in = (uInt)sourceLen;
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
|
||||
|
||||
stream.next_out = dest;
|
||||
stream.avail_out = (uInt)*destLen;
|
||||
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
|
||||
|
||||
stream.zalloc = (alloc_func)0;
|
||||
stream.zfree = (free_func)0;
|
||||
|
||||
err = inflateInit(&stream);
|
||||
if (err != Z_OK) return err;
|
||||
|
||||
err = inflate(&stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
inflateEnd(&stream);
|
||||
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
|
||||
return Z_DATA_ERROR;
|
||||
return err;
|
||||
}
|
||||
*destLen = stream.total_out;
|
||||
|
||||
err = inflateEnd(&stream);
|
||||
return err;
|
||||
}
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/uncompr.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/uncompr.obj
Normal file
Binary file not shown.
332
contrib/fundamentals/ZLib/zlib123/zconf.h
Normal file
332
contrib/fundamentals/ZLib/zlib123/zconf.h
Normal file
@@ -0,0 +1,332 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
# define zError z_zError
|
||||
|
||||
# define alloc_func z_alloc_func
|
||||
# define free_func z_free_func
|
||||
# define in_func z_in_func
|
||||
# define out_func z_out_func
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
|
||||
# define OS2
|
||||
#endif
|
||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||
# define WINDOWS
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
#endif
|
||||
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
||||
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
||||
# ifndef SYS16BIT
|
||||
# define SYS16BIT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#ifdef __STDC_VERSION__
|
||||
# ifndef STDC
|
||||
# define STDC
|
||||
# endif
|
||||
# if __STDC_VERSION__ >= 199901L
|
||||
# ifndef STDC99
|
||||
# define STDC99
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const /* note: need a more gentle solution here */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some Mac compilers merge all .h files incorrectly: */
|
||||
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
||||
# define NO_DUMMY_DECL
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# if defined(M_I86SM) || defined(M_I86MM)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
# if (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
/* Turbo C small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef __BORLANDC__
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS) || defined(WIN32)
|
||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||
* This is not mandatory, but it offers a little performance increase.
|
||||
*/
|
||||
# ifdef ZLIB_DLL
|
||||
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
# endif /* ZLIB_DLL */
|
||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||
* define ZLIB_WINAPI.
|
||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||
*/
|
||||
# ifdef ZLIB_WINAPI
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define ZEXPORT WINAPI
|
||||
# ifdef WIN32
|
||||
# define ZEXPORTVA WINAPIV
|
||||
# else
|
||||
# define ZEXPORTVA FAR CDECL
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (__BEOS__)
|
||||
# ifdef ZLIB_DLL
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXPORT __declspec(dllexport)
|
||||
# define ZEXPORTVA __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXPORT __declspec(dllimport)
|
||||
# define ZEXPORTVA __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN extern
|
||||
#endif
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA
|
||||
#endif
|
||||
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
#if !defined(__MACTYPES__)
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void const *voidpc;
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte const *voidpc;
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# define z_off_t off_t
|
||||
#endif
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__)
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
# pragma map(deflateInit_,"DEIN")
|
||||
# pragma map(deflateInit2_,"DEIN2")
|
||||
# pragma map(deflateEnd,"DEEND")
|
||||
# pragma map(deflateBound,"DEBND")
|
||||
# pragma map(inflateInit_,"ININ")
|
||||
# pragma map(inflateInit2_,"ININ2")
|
||||
# pragma map(inflateEnd,"INEND")
|
||||
# pragma map(inflateSync,"INSY")
|
||||
# pragma map(inflateSetDictionary,"INSEDI")
|
||||
# pragma map(compressBound,"CMBND")
|
||||
# pragma map(inflate_table,"INTABL")
|
||||
# pragma map(inflate_fast,"INFA")
|
||||
# pragma map(inflate_copyright,"INCOPY")
|
||||
#endif
|
||||
|
||||
#endif /* ZCONF_H */
|
||||
332
contrib/fundamentals/ZLib/zlib123/zconf.in.h
Normal file
332
contrib/fundamentals/ZLib/zlib123/zconf.in.h
Normal file
@@ -0,0 +1,332 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
# define zError z_zError
|
||||
|
||||
# define alloc_func z_alloc_func
|
||||
# define free_func z_free_func
|
||||
# define in_func z_in_func
|
||||
# define out_func z_out_func
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
|
||||
# define OS2
|
||||
#endif
|
||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||
# define WINDOWS
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
#endif
|
||||
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
||||
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
||||
# ifndef SYS16BIT
|
||||
# define SYS16BIT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#ifdef __STDC_VERSION__
|
||||
# ifndef STDC
|
||||
# define STDC
|
||||
# endif
|
||||
# if __STDC_VERSION__ >= 199901L
|
||||
# ifndef STDC99
|
||||
# define STDC99
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const /* note: need a more gentle solution here */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some Mac compilers merge all .h files incorrectly: */
|
||||
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
||||
# define NO_DUMMY_DECL
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# if defined(M_I86SM) || defined(M_I86MM)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
# if (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
/* Turbo C small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef __BORLANDC__
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS) || defined(WIN32)
|
||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||
* This is not mandatory, but it offers a little performance increase.
|
||||
*/
|
||||
# ifdef ZLIB_DLL
|
||||
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
# endif /* ZLIB_DLL */
|
||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||
* define ZLIB_WINAPI.
|
||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||
*/
|
||||
# ifdef ZLIB_WINAPI
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define ZEXPORT WINAPI
|
||||
# ifdef WIN32
|
||||
# define ZEXPORTVA WINAPIV
|
||||
# else
|
||||
# define ZEXPORTVA FAR CDECL
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (__BEOS__)
|
||||
# ifdef ZLIB_DLL
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXPORT __declspec(dllexport)
|
||||
# define ZEXPORTVA __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXPORT __declspec(dllimport)
|
||||
# define ZEXPORTVA __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN extern
|
||||
#endif
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA
|
||||
#endif
|
||||
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
#if !defined(__MACTYPES__)
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void const *voidpc;
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte const *voidpc;
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# define z_off_t off_t
|
||||
#endif
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__)
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
# pragma map(deflateInit_,"DEIN")
|
||||
# pragma map(deflateInit2_,"DEIN2")
|
||||
# pragma map(deflateEnd,"DEEND")
|
||||
# pragma map(deflateBound,"DEBND")
|
||||
# pragma map(inflateInit_,"ININ")
|
||||
# pragma map(inflateInit2_,"ININ2")
|
||||
# pragma map(inflateEnd,"INEND")
|
||||
# pragma map(inflateSync,"INSY")
|
||||
# pragma map(inflateSetDictionary,"INSEDI")
|
||||
# pragma map(compressBound,"CMBND")
|
||||
# pragma map(inflate_table,"INTABL")
|
||||
# pragma map(inflate_fast,"INFA")
|
||||
# pragma map(inflate_copyright,"INCOPY")
|
||||
#endif
|
||||
|
||||
#endif /* ZCONF_H */
|
||||
1357
contrib/fundamentals/ZLib/zlib123/zlib.h
Normal file
1357
contrib/fundamentals/ZLib/zlib123/zlib.h
Normal file
File diff suppressed because it is too large
Load Diff
318
contrib/fundamentals/ZLib/zlib123/zutil.c
Normal file
318
contrib/fundamentals/ZLib/zlib123/zutil.c
Normal file
@@ -0,0 +1,318 @@
|
||||
/* zutil.c -- target dependent utility functions for the compression library
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
#ifndef NO_DUMMY_DECL
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
#endif
|
||||
|
||||
const char * const z_errmsg[10] = {
|
||||
"need dictionary", /* Z_NEED_DICT 2 */
|
||||
"stream end", /* Z_STREAM_END 1 */
|
||||
"", /* Z_OK 0 */
|
||||
"file error", /* Z_ERRNO (-1) */
|
||||
"stream error", /* Z_STREAM_ERROR (-2) */
|
||||
"data error", /* Z_DATA_ERROR (-3) */
|
||||
"insufficient memory", /* Z_MEM_ERROR (-4) */
|
||||
"buffer error", /* Z_BUF_ERROR (-5) */
|
||||
"incompatible version",/* Z_VERSION_ERROR (-6) */
|
||||
""};
|
||||
|
||||
|
||||
const char * ZEXPORT zlibVersion()
|
||||
{
|
||||
return ZLIB_VERSION;
|
||||
}
|
||||
|
||||
uLong ZEXPORT zlibCompileFlags()
|
||||
{
|
||||
uLong flags;
|
||||
|
||||
flags = 0;
|
||||
switch (sizeof(uInt)) {
|
||||
case 2: break;
|
||||
case 4: flags += 1; break;
|
||||
case 8: flags += 2; break;
|
||||
default: flags += 3;
|
||||
}
|
||||
switch (sizeof(uLong)) {
|
||||
case 2: break;
|
||||
case 4: flags += 1 << 2; break;
|
||||
case 8: flags += 2 << 2; break;
|
||||
default: flags += 3 << 2;
|
||||
}
|
||||
switch (sizeof(voidpf)) {
|
||||
case 2: break;
|
||||
case 4: flags += 1 << 4; break;
|
||||
case 8: flags += 2 << 4; break;
|
||||
default: flags += 3 << 4;
|
||||
}
|
||||
switch (sizeof(z_off_t)) {
|
||||
case 2: break;
|
||||
case 4: flags += 1 << 6; break;
|
||||
case 8: flags += 2 << 6; break;
|
||||
default: flags += 3 << 6;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
flags += 1 << 8;
|
||||
#endif
|
||||
#if defined(ASMV) || defined(ASMINF)
|
||||
flags += 1 << 9;
|
||||
#endif
|
||||
#ifdef ZLIB_WINAPI
|
||||
flags += 1 << 10;
|
||||
#endif
|
||||
#ifdef BUILDFIXED
|
||||
flags += 1 << 12;
|
||||
#endif
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
flags += 1 << 13;
|
||||
#endif
|
||||
#ifdef NO_GZCOMPRESS
|
||||
flags += 1L << 16;
|
||||
#endif
|
||||
#ifdef NO_GZIP
|
||||
flags += 1L << 17;
|
||||
#endif
|
||||
#ifdef PKZIP_BUG_WORKAROUND
|
||||
flags += 1L << 20;
|
||||
#endif
|
||||
#ifdef FASTEST
|
||||
flags += 1L << 21;
|
||||
#endif
|
||||
#ifdef STDC
|
||||
# ifdef NO_vsnprintf
|
||||
flags += 1L << 25;
|
||||
# ifdef HAS_vsprintf_void
|
||||
flags += 1L << 26;
|
||||
# endif
|
||||
# else
|
||||
# ifdef HAS_vsnprintf_void
|
||||
flags += 1L << 26;
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
flags += 1L << 24;
|
||||
# ifdef NO_snprintf
|
||||
flags += 1L << 25;
|
||||
# ifdef HAS_sprintf_void
|
||||
flags += 1L << 26;
|
||||
# endif
|
||||
# else
|
||||
# ifdef HAS_snprintf_void
|
||||
flags += 1L << 26;
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
return flags;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
# ifndef verbose
|
||||
# define verbose 0
|
||||
# endif
|
||||
int z_verbose = verbose;
|
||||
|
||||
void z_error (m)
|
||||
char *m;
|
||||
{
|
||||
fprintf(stderr, "%s\n", m);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* exported to allow conversion of error code to string for compress() and
|
||||
* uncompress()
|
||||
*/
|
||||
const char * ZEXPORT zError(err)
|
||||
int err;
|
||||
{
|
||||
return ERR_MSG(err);
|
||||
}
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
/* The Microsoft C Run-Time Library for Windows CE doesn't have
|
||||
* errno. We define it as a global variable to simplify porting.
|
||||
* Its value is always 0 and should not be used.
|
||||
*/
|
||||
int errno = 0;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MEMCPY
|
||||
|
||||
void zmemcpy(dest, source, len)
|
||||
Bytef* dest;
|
||||
const Bytef* source;
|
||||
uInt len;
|
||||
{
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = *source++; /* ??? to be unrolled */
|
||||
} while (--len != 0);
|
||||
}
|
||||
|
||||
int zmemcmp(s1, s2, len)
|
||||
const Bytef* s1;
|
||||
const Bytef* s2;
|
||||
uInt len;
|
||||
{
|
||||
uInt j;
|
||||
|
||||
for (j = 0; j < len; j++) {
|
||||
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void zmemzero(dest, len)
|
||||
Bytef* dest;
|
||||
uInt len;
|
||||
{
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = 0; /* ??? to be unrolled */
|
||||
} while (--len != 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SYS16BIT
|
||||
|
||||
#ifdef __TURBOC__
|
||||
/* Turbo C in 16-bit mode */
|
||||
|
||||
# define MY_ZCALLOC
|
||||
|
||||
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
|
||||
* and farmalloc(64K) returns a pointer with an offset of 8, so we
|
||||
* must fix the pointer. Warning: the pointer must be put back to its
|
||||
* original form in order to free it, use zcfree().
|
||||
*/
|
||||
|
||||
#define MAX_PTR 10
|
||||
/* 10*64K = 640K */
|
||||
|
||||
local int next_ptr = 0;
|
||||
|
||||
typedef struct ptr_table_s {
|
||||
voidpf org_ptr;
|
||||
voidpf new_ptr;
|
||||
} ptr_table;
|
||||
|
||||
local ptr_table table[MAX_PTR];
|
||||
/* This table is used to remember the original form of pointers
|
||||
* to large buffers (64K). Such pointers are normalized with a zero offset.
|
||||
* Since MSDOS is not a preemptive multitasking OS, this table is not
|
||||
* protected from concurrent access. This hack doesn't work anyway on
|
||||
* a protected system like OS/2. Use Microsoft C instead.
|
||||
*/
|
||||
|
||||
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||
{
|
||||
voidpf buf = opaque; /* just to make some compilers happy */
|
||||
ulg bsize = (ulg)items*size;
|
||||
|
||||
/* If we allocate less than 65520 bytes, we assume that farmalloc
|
||||
* will return a usable pointer which doesn't have to be normalized.
|
||||
*/
|
||||
if (bsize < 65520L) {
|
||||
buf = farmalloc(bsize);
|
||||
if (*(ush*)&buf != 0) return buf;
|
||||
} else {
|
||||
buf = farmalloc(bsize + 16L);
|
||||
}
|
||||
if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
|
||||
table[next_ptr].org_ptr = buf;
|
||||
|
||||
/* Normalize the pointer to seg:0 */
|
||||
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
|
||||
*(ush*)&buf = 0;
|
||||
table[next_ptr++].new_ptr = buf;
|
||||
return buf;
|
||||
}
|
||||
|
||||
void zcfree (voidpf opaque, voidpf ptr)
|
||||
{
|
||||
int n;
|
||||
if (*(ush*)&ptr != 0) { /* object < 64K */
|
||||
farfree(ptr);
|
||||
return;
|
||||
}
|
||||
/* Find the original pointer */
|
||||
for (n = 0; n < next_ptr; n++) {
|
||||
if (ptr != table[n].new_ptr) continue;
|
||||
|
||||
farfree(table[n].org_ptr);
|
||||
while (++n < next_ptr) {
|
||||
table[n-1] = table[n];
|
||||
}
|
||||
next_ptr--;
|
||||
return;
|
||||
}
|
||||
ptr = opaque; /* just to make some compilers happy */
|
||||
Assert(0, "zcfree: ptr not found");
|
||||
}
|
||||
|
||||
#endif /* __TURBOC__ */
|
||||
|
||||
|
||||
#ifdef M_I86
|
||||
/* Microsoft C in 16-bit mode */
|
||||
|
||||
# define MY_ZCALLOC
|
||||
|
||||
#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
|
||||
# define _halloc halloc
|
||||
# define _hfree hfree
|
||||
#endif
|
||||
|
||||
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||
{
|
||||
if (opaque) opaque = 0; /* to make compiler happy */
|
||||
return _halloc((long)items, size);
|
||||
}
|
||||
|
||||
void zcfree (voidpf opaque, voidpf ptr)
|
||||
{
|
||||
if (opaque) opaque = 0; /* to make compiler happy */
|
||||
_hfree(ptr);
|
||||
}
|
||||
|
||||
#endif /* M_I86 */
|
||||
|
||||
#endif /* SYS16BIT */
|
||||
|
||||
|
||||
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
|
||||
|
||||
#ifndef STDC
|
||||
extern voidp malloc OF((uInt size));
|
||||
extern voidp calloc OF((uInt items, uInt size));
|
||||
extern void free OF((voidpf ptr));
|
||||
#endif
|
||||
|
||||
voidpf zcalloc (opaque, items, size)
|
||||
voidpf opaque;
|
||||
unsigned items;
|
||||
unsigned size;
|
||||
{
|
||||
if (opaque) items += size - size; /* make compiler happy */
|
||||
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
|
||||
(voidpf)calloc(items, size);
|
||||
}
|
||||
|
||||
void zcfree (opaque, ptr)
|
||||
voidpf opaque;
|
||||
voidpf ptr;
|
||||
{
|
||||
free(ptr);
|
||||
if (opaque) return; /* make compiler happy */
|
||||
}
|
||||
|
||||
#endif /* MY_ZCALLOC */
|
||||
269
contrib/fundamentals/ZLib/zlib123/zutil.h
Normal file
269
contrib/fundamentals/ZLib/zlib123/zutil.h
Normal file
@@ -0,0 +1,269 @@
|
||||
/* zutil.h -- internal interface and configuration of the compression library
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef ZUTIL_H
|
||||
#define ZUTIL_H
|
||||
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef STDC
|
||||
# ifndef _WIN32_WCE
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_ERRNO_H
|
||||
# ifdef _WIN32_WCE
|
||||
/* The Microsoft C Run-Time Library for Windows CE doesn't have
|
||||
* errno. We define it as a global variable to simplify porting.
|
||||
* Its value is always 0 and should not be used. We rename it to
|
||||
* avoid conflict with other libraries that use the same workaround.
|
||||
*/
|
||||
# define errno z_errno
|
||||
# endif
|
||||
extern int errno;
|
||||
#else
|
||||
# ifndef _WIN32_WCE
|
||||
# include <errno.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
/* compile with -Dlocal if your debugger can't find static symbols */
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef uch FAR uchf;
|
||||
typedef unsigned short ush;
|
||||
typedef ush FAR ushf;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
/* (size given to avoid silly warnings with Visual C++) */
|
||||
|
||||
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
|
||||
|
||||
#define ERR_RETURN(strm,err) \
|
||||
return (strm->msg = (char*)ERR_MSG(err), (err))
|
||||
/* To be used only when the state is known to be valid */
|
||||
|
||||
/* common constants */
|
||||
|
||||
#ifndef DEF_WBITS
|
||||
# define DEF_WBITS MAX_WBITS
|
||||
#endif
|
||||
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
||||
|
||||
#if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
#else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
#define STORED_BLOCK 0
|
||||
#define STATIC_TREES 1
|
||||
#define DYN_TREES 2
|
||||
/* The three kinds of block type */
|
||||
|
||||
#define MIN_MATCH 3
|
||||
#define MAX_MATCH 258
|
||||
/* The minimum and maximum match lengths */
|
||||
|
||||
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
|
||||
|
||||
/* target dependencies */
|
||||
|
||||
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
||||
# define OS_CODE 0x00
|
||||
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||
/* Allow compilation with ANSI keywords only enabled */
|
||||
void _Cdecl farfree( void *block );
|
||||
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||
# else
|
||||
# include <alloc.h>
|
||||
# endif
|
||||
# else /* MSC or DJGPP */
|
||||
# include <malloc.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef AMIGA
|
||||
# define OS_CODE 0x01
|
||||
#endif
|
||||
|
||||
#if defined(VAXC) || defined(VMS)
|
||||
# define OS_CODE 0x02
|
||||
# define F_OPEN(name, mode) \
|
||||
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
||||
#endif
|
||||
|
||||
#if defined(ATARI) || defined(atarist)
|
||||
# define OS_CODE 0x05
|
||||
#endif
|
||||
|
||||
#ifdef OS2
|
||||
# define OS_CODE 0x06
|
||||
# ifdef M_I86
|
||||
#include <malloc.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||
# define OS_CODE 0x07
|
||||
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
||||
# include <unix.h> /* for fdopen */
|
||||
# else
|
||||
# ifndef fdopen
|
||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef TOPS20
|
||||
# define OS_CODE 0x0a
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
|
||||
# define OS_CODE 0x0b
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __50SERIES /* Prime/PRIMOS */
|
||||
# define OS_CODE 0x0f
|
||||
#endif
|
||||
|
||||
#if defined(_BEOS_) || defined(RISCOS)
|
||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && (_MSC_VER > 600))
|
||||
# if defined(_WIN32_WCE)
|
||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||
# ifndef _PTRDIFF_T_DEFINED
|
||||
typedef int ptrdiff_t;
|
||||
# define _PTRDIFF_T_DEFINED
|
||||
# endif
|
||||
# else
|
||||
# define fdopen(fd,type) _fdopen(fd,type)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* common defaults */
|
||||
|
||||
#ifndef OS_CODE
|
||||
# define OS_CODE 0x03 /* assume Unix */
|
||||
#endif
|
||||
|
||||
#ifndef F_OPEN
|
||||
# define F_OPEN(name, mode) fopen((name), (mode))
|
||||
#endif
|
||||
|
||||
/* functions */
|
||||
|
||||
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
# ifdef MSDOS
|
||||
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
||||
but for now we just assume it doesn't. */
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __TURBOC__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef WIN32
|
||||
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
||||
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
# endif
|
||||
# ifdef __SASC
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
#endif
|
||||
#ifdef VMS
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(pyr)
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||
/* Use our own functions for small and medium model with MSC <= 5.0.
|
||||
* You may have to use the same strategy for Borland C (untested).
|
||||
* The __SC__ check is for Symantec.
|
||||
*/
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
||||
# define HAVE_MEMCPY
|
||||
#endif
|
||||
#ifdef HAVE_MEMCPY
|
||||
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
|
||||
# define zmemcpy _fmemcpy
|
||||
# define zmemcmp _fmemcmp
|
||||
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
||||
# else
|
||||
# define zmemcpy memcpy
|
||||
# define zmemcmp memcmp
|
||||
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||
# endif
|
||||
#else
|
||||
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
||||
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
||||
extern void zmemzero OF((Bytef* dest, uInt len));
|
||||
#endif
|
||||
|
||||
/* Diagnostic functions */
|
||||
#ifdef DEBUG
|
||||
# include <stdio.h>
|
||||
extern int z_verbose;
|
||||
extern void z_error OF((char *m));
|
||||
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
|
||||
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
|
||||
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
|
||||
#else
|
||||
# define Assert(cond,msg)
|
||||
# define Trace(x)
|
||||
# define Tracev(x)
|
||||
# define Tracevv(x)
|
||||
# define Tracec(c,x)
|
||||
# define Tracecv(c,x)
|
||||
#endif
|
||||
|
||||
|
||||
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
||||
void zcfree OF((voidpf opaque, voidpf ptr));
|
||||
|
||||
#define ZALLOC(strm, items, size) \
|
||||
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||
|
||||
#endif /* ZUTIL_H */
|
||||
BIN
contrib/fundamentals/ZLib/zlib123/zutil.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib123/zutil.obj
Normal file
Binary file not shown.
173
contrib/fundamentals/ZLib/zlib127/ZLibEx.inc
Normal file
173
contrib/fundamentals/ZLib/zlib127/ZLibEx.inc
Normal file
@@ -0,0 +1,173 @@
|
||||
{*************************************************************************************************
|
||||
* ZLibEx.inc *
|
||||
* copyright (c) 2006-2012 base2 technologies *
|
||||
* *
|
||||
* version information for delphi/c++ builder *
|
||||
* *
|
||||
* revision history *
|
||||
* 2012.05.01 updated for delphi xe2 (2012) *
|
||||
* 2010.09.18 updated for delphi xe (2011) *
|
||||
* 2010.01.27 updated for delphi 2010 *
|
||||
* 2009.04.11 updated to use CONDITIONALEXPRESSIONS and CompilerVersion *
|
||||
* 2009.01.28 updated for delphi 2009 *
|
||||
* 2007.10.01 updated for delphi 2007 *
|
||||
* 2005.11.29 created *
|
||||
* *
|
||||
* acknowledgments *
|
||||
* iztok kacin *
|
||||
* 2009.04.11 CONDITIONALEXPRESSIONS and CompilerVersion changes *
|
||||
*************************************************************************************************}
|
||||
|
||||
{$ifndef CONDITIONALEXPRESSIONS}
|
||||
|
||||
{** delphi ************************************************************************************}
|
||||
|
||||
{$ifdef VER80} // delphi 1
|
||||
{$define Delphi}
|
||||
|
||||
{$define Version1}
|
||||
{$endif}
|
||||
|
||||
{$ifdef VER90} // delphi 2
|
||||
{$define Delphi}
|
||||
|
||||
{$define Version2}
|
||||
{$endif}
|
||||
|
||||
{$ifdef VER100} // delphi 3
|
||||
{$define Delphi}
|
||||
|
||||
{$define Version3}
|
||||
{$endif}
|
||||
|
||||
{$ifdef VER120} // delphi 4
|
||||
{$define Delphi}
|
||||
|
||||
{$define Version4}
|
||||
{$endif}
|
||||
|
||||
{** c++ builder *******************************************************************************}
|
||||
|
||||
{$ifdef VER93} // c++ builder 1
|
||||
{$define CBuilder}
|
||||
|
||||
{$define Version1}
|
||||
{$endif}
|
||||
|
||||
{$ifdef VER110} // c++ builder 3
|
||||
{$define CBuilder}
|
||||
|
||||
{$define Version3}
|
||||
{$endif}
|
||||
|
||||
{$ifdef VER125} // c++ builder 4
|
||||
{$define CBuilder}
|
||||
|
||||
{$define Version4}
|
||||
{$endif}
|
||||
|
||||
{** delphi/c++ builder (common) ***************************************************************}
|
||||
|
||||
{$ifdef VER130} // delphi/c++ builder 5
|
||||
{$ifdef BCB}
|
||||
{$define CBuilder}
|
||||
{$ELSE}
|
||||
{$define Delphi}
|
||||
{$endif}
|
||||
|
||||
{$define Version5}
|
||||
|
||||
{$define Version5Plus}
|
||||
{$endif}
|
||||
|
||||
{$ELSE}
|
||||
|
||||
{$ifdef BCB}
|
||||
{$define CBuilder}
|
||||
{$ELSE}
|
||||
{$define Delphi}
|
||||
{$endif}
|
||||
|
||||
{$define Version5Plus}
|
||||
|
||||
{$if CompilerVersion >= 14.0} // delphi 6
|
||||
{$ifdef VER140}
|
||||
{$define Version6}
|
||||
{$endif}
|
||||
|
||||
{$define Version6Plus}
|
||||
{$ifend}
|
||||
|
||||
{$if CompilerVersion >= 15.0} // delphi 7
|
||||
{$ifdef VER150}
|
||||
{$define Version7}
|
||||
{$endif}
|
||||
|
||||
{$define Version7Plus}
|
||||
{$ifend}
|
||||
|
||||
{$if CompilerVersion >= 16.0} // delphi 8 (.net)
|
||||
{$ifdef VER160}
|
||||
{$define Version8}
|
||||
{$endif}
|
||||
|
||||
{$define Version8Plus}
|
||||
{$ifend}
|
||||
|
||||
{$if CompilerVersion >= 17.0} // delphi 2005
|
||||
{$ifdef VER170}
|
||||
{$define Version2005}
|
||||
{$endif}
|
||||
|
||||
{$define Version2005Plus}
|
||||
{$ifend}
|
||||
|
||||
{$if CompilerVersion >= 18.0} // bds 2006
|
||||
{$ifdef VER180}
|
||||
{$define Version2006}
|
||||
{$endif}
|
||||
|
||||
{$define Version2006Plus}
|
||||
{$ifend}
|
||||
|
||||
{$if CompilerVersion >= 18.5} // bds 2007
|
||||
{$ifdef VER185}
|
||||
{$define Version2007}
|
||||
{$endif}
|
||||
|
||||
{$define Version2007Plus}
|
||||
{$ifend}
|
||||
|
||||
{$if CompilerVersion >= 20.0} // bds 2009
|
||||
{$ifdef VER200}
|
||||
{$define Version2009}
|
||||
{$endif}
|
||||
|
||||
{$define Version2009Plus}
|
||||
{$ifend}
|
||||
|
||||
{$if CompilerVersion >= 21.0} // bds 2010
|
||||
{$ifdef VER210}
|
||||
{$define Version2010}
|
||||
{$endif}
|
||||
|
||||
{$define Version2010Plus}
|
||||
{$ifend}
|
||||
|
||||
{$if CompilerVersion >= 22.0} // bds xe (2011)
|
||||
{$ifdef VER220}
|
||||
{$define Version2011}
|
||||
{$endif}
|
||||
|
||||
{$define Version2011Plus}
|
||||
{$ifend}
|
||||
|
||||
{$if CompilerVersion >= 23.0} // bds xe2 (2012)
|
||||
{$ifdef VER230}
|
||||
{$define Version2012}
|
||||
{$endif}
|
||||
|
||||
{$define Version2012Plus}
|
||||
{$ifend}
|
||||
|
||||
{$endif}
|
||||
2231
contrib/fundamentals/ZLib/zlib127/ZLibEx.pas
Normal file
2231
contrib/fundamentals/ZLib/zlib127/ZLibEx.pas
Normal file
File diff suppressed because it is too large
Load Diff
334
contrib/fundamentals/ZLib/zlib127/ZLibExApi.pas
Normal file
334
contrib/fundamentals/ZLib/zlib127/ZLibExApi.pas
Normal file
@@ -0,0 +1,334 @@
|
||||
{*************************************************************************************************
|
||||
* ZLibExApi.pas *
|
||||
* *
|
||||
* copyright (c) 2000-2012 base2 technologies *
|
||||
* copyright (c) 1995-2002 Borland Software Corporation *
|
||||
* *
|
||||
* revision history *
|
||||
* 2012.05.21 updated for win64 (delphi xe2) *
|
||||
* moved win32 obj files to win32 subfolder *
|
||||
* changed win32 obj options to exclude the underscore *
|
||||
* 2012.05.07 updated to zlib version 1.2.7 *
|
||||
* 2012.03.05 udpated to zlib version 1.2.6 *
|
||||
* 2010.04.20 updated to zlib version 1.2.5 *
|
||||
* 2010.04.15 updated to zlib version 1.2.4 *
|
||||
* 2005.07.25 updated to zlib version 1.2.3 *
|
||||
* 2005.01.11 updated to zlib version 1.2.2 *
|
||||
* 2004.01.06 updated to zlib version 1.2.1 *
|
||||
* 2002.03.15 updated to zlib version 1.1.4 *
|
||||
* *
|
||||
* acknowledgments *
|
||||
* burak kalayci *
|
||||
* 2002.03.15 informing me about the zlib 1.1.4 update *
|
||||
* 2004.01.06 informing me about the zlib 1.2.1 update *
|
||||
* *
|
||||
* vicente sanchez-alarcos *
|
||||
* 2005.01.11 informing me about the zlib 1.2.2 update *
|
||||
* *
|
||||
* mathijs van veluw *
|
||||
* 2005.07.25 informing me about the zlib 1.2.3 update *
|
||||
* *
|
||||
* tommi prami *
|
||||
* 2012.03.05 informing me about the zlib 1.2.6 update *
|
||||
* *
|
||||
* marian pascalau *
|
||||
* 2012.05.21 providing the win64 obj files and your win64 modifications *
|
||||
*************************************************************************************************}
|
||||
|
||||
unit ZLibExApi;
|
||||
|
||||
interface
|
||||
|
||||
{$I ZLibEx.inc}
|
||||
|
||||
const
|
||||
{** version ids *******************************************************************************}
|
||||
|
||||
ZLIB_VERSION: PAnsiChar = '1.2.7';
|
||||
|
||||
ZLIB_VERNUM = $1270;
|
||||
|
||||
ZLIB_VER_MAJOR = 1;
|
||||
ZLIB_VER_MINOR = 2;
|
||||
ZLIB_VER_REVISION = 7;
|
||||
ZLIB_VER_SUBREVISION = 0;
|
||||
|
||||
{** compression methods ***********************************************************************}
|
||||
|
||||
Z_DEFLATED = 8;
|
||||
|
||||
{** information flags *************************************************************************}
|
||||
|
||||
Z_INFO_FLAG_SIZE = $1;
|
||||
Z_INFO_FLAG_CRC = $2;
|
||||
Z_INFO_FLAG_ADLER = $4;
|
||||
|
||||
Z_INFO_NONE = 0;
|
||||
Z_INFO_DEFAULT = Z_INFO_FLAG_SIZE or Z_INFO_FLAG_CRC;
|
||||
|
||||
{** flush constants ***************************************************************************}
|
||||
|
||||
Z_NO_FLUSH = 0;
|
||||
Z_PARTIAL_FLUSH = 1;
|
||||
Z_SYNC_FLUSH = 2;
|
||||
Z_FULL_FLUSH = 3;
|
||||
Z_FINISH = 4;
|
||||
Z_BLOCK = 5;
|
||||
Z_TREES = 6;
|
||||
|
||||
{** return codes ******************************************************************************}
|
||||
|
||||
Z_OK = 0;
|
||||
Z_STREAM_END = 1;
|
||||
Z_NEED_DICT = 2;
|
||||
Z_ERRNO = (-1);
|
||||
Z_STREAM_ERROR = (-2);
|
||||
Z_DATA_ERROR = (-3);
|
||||
Z_MEM_ERROR = (-4);
|
||||
Z_BUF_ERROR = (-5);
|
||||
Z_VERSION_ERROR = (-6);
|
||||
|
||||
{** compression levels ************************************************************************}
|
||||
|
||||
Z_NO_COMPRESSION = 0;
|
||||
Z_BEST_SPEED = 1;
|
||||
Z_BEST_COMPRESSION = 9;
|
||||
Z_DEFAULT_COMPRESSION = (-1);
|
||||
|
||||
{** compression strategies ********************************************************************}
|
||||
|
||||
Z_FILTERED = 1;
|
||||
Z_HUFFMAN_ONLY = 2;
|
||||
Z_RLE = 3;
|
||||
Z_FIXED = 4;
|
||||
Z_DEFAULT_STRATEGY = 0;
|
||||
|
||||
{** data types ********************************************************************************}
|
||||
|
||||
Z_BINARY = 0;
|
||||
Z_ASCII = 1;
|
||||
Z_TEXT = Z_ASCII;
|
||||
Z_UNKNOWN = 2;
|
||||
|
||||
{** return code messages **********************************************************************}
|
||||
|
||||
z_errmsg: Array [0..9] of String = (
|
||||
'Need dictionary', // Z_NEED_DICT (2)
|
||||
'Stream end', // Z_STREAM_END (1)
|
||||
'OK', // Z_OK (0)
|
||||
'File error', // Z_ERRNO (-1)
|
||||
'Stream error', // Z_STREAM_ERROR (-2)
|
||||
'Data error', // Z_DATA_ERROR (-3)
|
||||
'Insufficient memory', // Z_MEM_ERROR (-4)
|
||||
'Buffer error', // Z_BUF_ERROR (-5)
|
||||
'Incompatible version', // Z_VERSION_ERROR (-6)
|
||||
''
|
||||
);
|
||||
|
||||
type
|
||||
TZAlloc = function (opaque: Pointer; items, size: Integer): Pointer; cdecl;
|
||||
TZFree = procedure (opaque, block: Pointer); cdecl;
|
||||
|
||||
{** TZStreamRec *******************************************************************************}
|
||||
|
||||
TZStreamRec = packed record
|
||||
next_in : PByte; // next input byte
|
||||
avail_in : Cardinal; // number of bytes available at next_in
|
||||
total_in : Longword; // total nb of input bytes read so far
|
||||
|
||||
next_out : PByte; // next output byte should be put here
|
||||
avail_out: Cardinal; // remaining free space at next_out
|
||||
total_out: Longword; // total nb of bytes output so far
|
||||
|
||||
msg : PAnsiChar; // last error message, NULL if no error
|
||||
state : Pointer; // not visible by applications
|
||||
|
||||
zalloc : TZAlloc; // used to allocate the internal state
|
||||
zfree : TZFree; // used to free the internal state
|
||||
opaque : Pointer; // private data object passed to zalloc and zfree
|
||||
|
||||
data_type: Integer; // best guess about the data type: ascii or binary
|
||||
adler : Longword; // adler32 value of the uncompressed data
|
||||
reserved : Longword; // reserved for future use
|
||||
end;
|
||||
|
||||
{** macros **************************************************************************************}
|
||||
|
||||
function deflateInit(var strm: TZStreamRec; level: Integer): Integer;
|
||||
{$ifdef Version2005Plus} inline; {$endif}
|
||||
|
||||
function deflateInit2(var strm: TZStreamRec; level, method, windowBits,
|
||||
memLevel, strategy: Integer): Integer;
|
||||
{$ifdef Version2005Plus} inline; {$endif}
|
||||
|
||||
function inflateInit(var strm: TZStreamRec): Integer;
|
||||
{$ifdef Version2005Plus} inline; {$endif}
|
||||
|
||||
function inflateInit2(var strm: TZStreamRec; windowBits: Integer): Integer;
|
||||
{$ifdef Version2005Plus} inline; {$endif}
|
||||
|
||||
{** external routines ***************************************************************************}
|
||||
|
||||
function deflateInit_(var strm: TZStreamRec; level: Integer;
|
||||
version: PAnsiChar; recsize: Integer): Integer;
|
||||
|
||||
function deflateInit2_(var strm: TZStreamRec; level, method, windowBits,
|
||||
memLevel, strategy: Integer; version: PAnsiChar; recsize: Integer): Integer;
|
||||
|
||||
function deflate(var strm: TZStreamRec; flush: Integer): Integer;
|
||||
|
||||
function deflateEnd(var strm: TZStreamRec): Integer;
|
||||
|
||||
function deflateReset(var strm: TZStreamRec): Integer;
|
||||
|
||||
function inflateInit_(var strm: TZStreamRec; version: PAnsiChar;
|
||||
recsize: Integer): Integer;
|
||||
|
||||
function inflateInit2_(var strm: TZStreamRec; windowBits: Integer;
|
||||
version: PAnsiChar; recsize: Integer): Integer;
|
||||
|
||||
function inflate(var strm: TZStreamRec; flush: Integer): Integer;
|
||||
|
||||
function inflateEnd(var strm: TZStreamRec): Integer;
|
||||
|
||||
function inflateReset(var strm: TZStreamRec): Integer;
|
||||
|
||||
function adler32(adler: Longint; const buf; len: Integer): Longint;
|
||||
|
||||
function crc32(crc: Longint; const buf; len: Integer): Longint;
|
||||
|
||||
implementation
|
||||
|
||||
{*************************************************************************************************
|
||||
* link zlib code *
|
||||
* *
|
||||
* bcc32 flags *
|
||||
* -c -O2 -Ve -X -pr -a8 -b -d -k- -vi -tWM -u- *
|
||||
* *
|
||||
* note: do not reorder the following -- doing so will result in external *
|
||||
* functions being undefined *
|
||||
*************************************************************************************************}
|
||||
|
||||
{$ifdef WIN64}
|
||||
{$L win64\deflate.obj}
|
||||
{$L win64\inflate.obj}
|
||||
{$L win64\inftrees.obj}
|
||||
{$L win64\infback.obj}
|
||||
{$L win64\inffast.obj}
|
||||
{$L win64\trees.obj}
|
||||
{$L win64\compress.obj}
|
||||
{$L win64\adler32.obj}
|
||||
{$L win64\crc32.obj}
|
||||
{$else}
|
||||
{$L win32\deflate.obj}
|
||||
{$L win32\inflate.obj}
|
||||
{$L win32\inftrees.obj}
|
||||
{$L win32\infback.obj}
|
||||
{$L win32\inffast.obj}
|
||||
{$L win32\trees.obj}
|
||||
{$L win32\compress.obj}
|
||||
{$L win32\adler32.obj}
|
||||
{$L win32\crc32.obj}
|
||||
{$endif}
|
||||
|
||||
{** macros **************************************************************************************}
|
||||
|
||||
function deflateInit(var strm: TZStreamRec; level: Integer): Integer;
|
||||
begin
|
||||
result := deflateInit_(strm, level, ZLIB_VERSION, SizeOf(TZStreamRec));
|
||||
end;
|
||||
|
||||
function deflateInit2(var strm: TZStreamRec; level, method, windowBits,
|
||||
memLevel, strategy: Integer): Integer;
|
||||
begin
|
||||
result := deflateInit2_(strm, level, method, windowBits,
|
||||
memLevel, strategy, ZLIB_VERSION, SizeOf(TZStreamRec));
|
||||
end;
|
||||
|
||||
function inflateInit(var strm: TZStreamRec): Integer;
|
||||
begin
|
||||
result := inflateInit_(strm, ZLIB_VERSION, SizeOf(TZStreamRec));
|
||||
end;
|
||||
|
||||
function inflateInit2(var strm: TZStreamRec; windowBits: Integer): Integer;
|
||||
begin
|
||||
result := inflateInit2_(strm, windowBits, ZLIB_VERSION,
|
||||
SizeOf(TZStreamRec));
|
||||
end;
|
||||
|
||||
{** external routines ***************************************************************************}
|
||||
|
||||
function deflateInit_(var strm: TZStreamRec; level: Integer;
|
||||
version: PAnsiChar; recsize: Integer): Integer;
|
||||
external;
|
||||
|
||||
function deflateInit2_(var strm: TZStreamRec; level, method, windowBits,
|
||||
memLevel, strategy: Integer; version: PAnsiChar; recsize: Integer): Integer;
|
||||
external;
|
||||
|
||||
function deflate(var strm: TZStreamRec; flush: Integer): Integer;
|
||||
external;
|
||||
|
||||
function deflateEnd(var strm: TZStreamRec): Integer;
|
||||
external;
|
||||
|
||||
function deflateReset(var strm: TZStreamRec): Integer;
|
||||
external;
|
||||
|
||||
function inflateInit_(var strm: TZStreamRec; version: PAnsiChar;
|
||||
recsize: Integer): Integer;
|
||||
external;
|
||||
|
||||
function inflateInit2_(var strm: TZStreamRec; windowBits: Integer;
|
||||
version: PAnsiChar; recsize: Integer): Integer;
|
||||
external;
|
||||
|
||||
function inflate(var strm: TZStreamRec; flush: Integer): Integer;
|
||||
external;
|
||||
|
||||
function inflateEnd(var strm: TZStreamRec): Integer;
|
||||
external;
|
||||
|
||||
function inflateReset(var strm: TZStreamRec): Integer;
|
||||
external;
|
||||
|
||||
function adler32(adler: Longint; const buf; len: Integer): Longint;
|
||||
external;
|
||||
|
||||
function crc32(crc: Longint; const buf; len: Integer): Longint;
|
||||
external;
|
||||
|
||||
{** zlib function implementations ***************************************************************}
|
||||
|
||||
function zcalloc(opaque: Pointer; items, size: Integer): Pointer;
|
||||
begin
|
||||
GetMem(result,items * size);
|
||||
end;
|
||||
|
||||
procedure zcfree(opaque, block: Pointer);
|
||||
begin
|
||||
FreeMem(block);
|
||||
end;
|
||||
|
||||
{** c function implementations ******************************************************************}
|
||||
|
||||
function memset(p: Pointer; b: Byte; count: Integer): Pointer; cdecl;
|
||||
begin
|
||||
FillChar(p^, count, b);
|
||||
|
||||
result := p;
|
||||
end;
|
||||
|
||||
procedure memcpy(dest, source: Pointer; count: Integer); cdecl;
|
||||
begin
|
||||
Move(source^, dest^, count);
|
||||
end;
|
||||
|
||||
{$ifndef WIN64}
|
||||
procedure _llmod;
|
||||
asm
|
||||
jmp System.@_llmod;
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
end.
|
||||
1247
contrib/fundamentals/ZLib/zlib127/ZLibExGZ.pas
Normal file
1247
contrib/fundamentals/ZLib/zlib127/ZLibExGZ.pas
Normal file
File diff suppressed because it is too large
Load Diff
348
contrib/fundamentals/ZLib/zlib127/readme.txt
Normal file
348
contrib/fundamentals/ZLib/zlib127/readme.txt
Normal file
@@ -0,0 +1,348 @@
|
||||
-- notes ---------------------------------------------------------------------
|
||||
|
||||
the units included in this archive should work with delphi 5 through delphi
|
||||
xe2 for win32.
|
||||
|
||||
the units included in this archive with the exception of zlibexgz should
|
||||
work with delphi xe2 for win64.
|
||||
|
||||
please contact me if you find any errors, make any changes, add new
|
||||
functionality, or have any general suggestions so that i may incorporate
|
||||
them into my version. i can be reached via my website at
|
||||
|
||||
http://www.base2ti.com
|
||||
|
||||
thanks.
|
||||
brent sherwood
|
||||
|
||||
-- disclaimer ----------------------------------------------------------------
|
||||
|
||||
this software is provided "as-is", without any express or implied warranty.
|
||||
in no event will the authors be held liable for any damages arising from the
|
||||
use of this software.
|
||||
|
||||
permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications. please do not misrepresent the origin of
|
||||
this software. if you use this software in a product, an acknowledgment in
|
||||
the product documentation (readme, about box, help file, etc.) would be
|
||||
appreciated but is not required.
|
||||
|
||||
-- installation --------------------------------------------------------------
|
||||
|
||||
first, copy all of the files into a folder (for example, c:\delphi\zlib).
|
||||
next, include the folder in the library path in the environment options.
|
||||
finally, "use" the zlibex and zlibexgz units as needed.
|
||||
|
||||
-- history -------------------------------------------------------------------
|
||||
|
||||
2012.05.23 zlibexgz.pas
|
||||
updated for delphi xe2
|
||||
added overloaded GZCompressFile
|
||||
|
||||
2012.05.21 zlibex.pas
|
||||
updated for win64 (delphi xe2)
|
||||
added NativeInt type for delphi 2007-
|
||||
added NativeUInt type for delphi 2007-
|
||||
|
||||
zlibexapi.pas
|
||||
updated for win64 (delphi xe2)
|
||||
moved win32 obj files to win32 subfolder
|
||||
changed win32 obj options to exclude the underscore
|
||||
|
||||
2012.05.07 zlibexapi.pas
|
||||
updated to zlib version 1.2.7
|
||||
|
||||
2012.05.01 zlibex.inc
|
||||
updated for delphi xe2 (2012)
|
||||
|
||||
2012.03.05 zliexapi.pas
|
||||
udpated to zlib version 1.2.6
|
||||
|
||||
2011.07.21 zlibex.pas
|
||||
fixed routines to validate size before calling Move
|
||||
|
||||
zlibexgz.pas
|
||||
fixed routines to validate size before calling Move
|
||||
|
||||
2010.07.01 zlibex.pas
|
||||
hide overloaded Z*String* routines for delphi 5
|
||||
|
||||
2010.05.02 zlibex.pas
|
||||
added ZDeflateEx and ZInflateEx
|
||||
|
||||
2010.04.20 zlibex.pas
|
||||
added TZ*Buffer classes
|
||||
|
||||
zlibexapi.pas
|
||||
updated to zlib version 1.2.5
|
||||
|
||||
2010.04.15 zlibex.pas
|
||||
moved core zlib routines to separate unit (ZLibExApi.pas)
|
||||
|
||||
zlibexapi.pas
|
||||
updated to zlib version 1.2.4
|
||||
|
||||
2010.01.27 zlibex.pas
|
||||
updated for delphi 2010
|
||||
|
||||
zlibexgz.pas
|
||||
updated for delphi 2010
|
||||
|
||||
zlibex.inc
|
||||
updated for delphi 2010
|
||||
|
||||
2009.04.14 zlibex.pas
|
||||
added overloaded string routines for AnsiString and
|
||||
UnicodeString
|
||||
|
||||
zlibexgz.pas
|
||||
added overloaded string routines for AnsiString and
|
||||
UnicodeString
|
||||
removed deprecated Z*G routines
|
||||
|
||||
2009.04.11 zlibex.inc
|
||||
updated to use CONDITIONALEXPRESSIONS and CompilerVersion
|
||||
|
||||
2009.01.28 zlibex.pas
|
||||
updated for delphi 2009 String (UnicodeString)
|
||||
|
||||
zlibexgz.pas
|
||||
updated for delphi 2009 String (UnicodeString)
|
||||
|
||||
zlibex.inc
|
||||
updated for delphi 2009
|
||||
|
||||
2008.05.15 zlibex.pas
|
||||
added TStreamPos type Stream.Position variants
|
||||
added TCustomZStream.Stream* methods
|
||||
|
||||
zlibexgz.pas
|
||||
added TGZCompressionStream and TGZDecompressionStream
|
||||
|
||||
2007.11.06 zlibexgz.pas
|
||||
changed TGZTrailer.Crc from Cardinal to Longint
|
||||
|
||||
2007.10.01 zlibexgz.pas
|
||||
added GZDecompressStreamSize
|
||||
fixed GZDecompressStream position handling
|
||||
|
||||
zlibex.inc
|
||||
updated for delphi 2007
|
||||
|
||||
2007.08.17 zlibex.pas
|
||||
modified TZCompressionStream.Write to use Write instead of
|
||||
WriteBuffer
|
||||
|
||||
2007.07.18 zlibexgz.pas
|
||||
fixed GZCompressStr filename and comment processing
|
||||
|
||||
2007.03.18 zlibexgz.pas
|
||||
modified naming convention for gzip routines GZ*
|
||||
deprecated previous gzip routines Z*G
|
||||
|
||||
2007.03.15 zlibex.pas
|
||||
moved gzip routines to separate unit - zlibexgz.pas
|
||||
|
||||
zlibexgz.pas
|
||||
added ZDecompressStreamG
|
||||
added overloaded ZCompressStrG
|
||||
added overloaded ZCompressStreamG
|
||||
|
||||
2007.02.24 zlibex.pas
|
||||
added PWord declaration for delphi 5-
|
||||
|
||||
2006.10.07 zlibex.pas
|
||||
fixed EZLibError constructor for c++ builder compatibility
|
||||
|
||||
2006.08.10 zlibex.pas
|
||||
added ZDecompressStrG (simple gzip format)
|
||||
|
||||
2006.06.02 zlibex.pas
|
||||
added DateTimeToUnix for delphi 5-
|
||||
|
||||
2006.03.28 zlibex.pas
|
||||
moved Z_DEFLATED to interface section
|
||||
added custom compression levels zcLevel1 thru zcLevel9
|
||||
|
||||
2006.03.27 zlibex.pas
|
||||
added ZCompressStreamWeb
|
||||
added ZCompressStreamG (simple gzip format)
|
||||
|
||||
2006.03.24 zlibex.pas
|
||||
added ZCompressStrG (simple gzip format)
|
||||
added ZAdler32 and ZCrc32
|
||||
|
||||
2005.11.29 zlibex.pas
|
||||
changed FStreamPos to Int64 for delphi 6+
|
||||
|
||||
2005.07.25 zlibex.pas
|
||||
updated to zlib version 1.2.3
|
||||
|
||||
2005.03.04 zlibex.pas
|
||||
modified ZInternalCompressStream loops
|
||||
modified ZInternalDecompressStream loops
|
||||
|
||||
2005.02.07 zlibex.pas
|
||||
fixed ZInternalCompressStream loop conditions
|
||||
fixed ZInternalDecompressStream loop conditions
|
||||
|
||||
2005.01.11 zlibex.pas
|
||||
updated to zlib version 1.2.2
|
||||
added ZCompressStrWeb
|
||||
|
||||
2004.01.06 zlibex.pas
|
||||
updated to zlib version 1.2.1
|
||||
|
||||
2003.04.14 zlibex.pas
|
||||
added ZCompress2 and ZDecompress2
|
||||
added ZCompressStr2 and ZDecompressStr2
|
||||
added ZCompressStream2 and ZDecompressStream2
|
||||
added overloaded T*Stream constructors to support InflateInit2
|
||||
and DeflateInit2
|
||||
fixed ZDecompressStream to use ZDecompressCheck instead of
|
||||
ZCompressCheck
|
||||
|
||||
2002.03.15 zlibex.pas
|
||||
updated to zlib version 1.1.4
|
||||
|
||||
2001.11.27 zlibex.pas
|
||||
enhanced TZDecompressionStream.Read to adjust source stream
|
||||
position upon end of compression data
|
||||
fixed endless loop in TZDecompressionStream.Read when
|
||||
destination count was greater than uncompressed data
|
||||
|
||||
2001.10.26 zlibex.pas
|
||||
renamed unit to integrate "nicely" with delphi 6
|
||||
|
||||
2000.11.24 zlib.pas
|
||||
added soFromEnd condition to TZDecompressionStream.Seek
|
||||
added ZCompressStream and ZDecompressStream
|
||||
|
||||
2000.06.13 zlib.pas
|
||||
optimized, fixed, rewrote, and enhanced the zlib.pas unit
|
||||
included on the delphi cd (zlib version 1.1.3)
|
||||
|
||||
-- acknowledgments -----------------------------------------------------------
|
||||
|
||||
erik turner - thanks for the enhancements and recommendations.
|
||||
specifically, the ZCompressionStream and ZDecompressionStream routines.
|
||||
my apologies for the delay in getting these in here.
|
||||
|
||||
david bennion - thanks for finding that nasty little endless loop quirk
|
||||
with the TZDecompressionStream.Read method.
|
||||
|
||||
burak kalayci - thanks for emailing to inform me about the zlib 1.1.4
|
||||
update; and again for emailing about 1.2.1.
|
||||
|
||||
vicente sánchez-alarcos - thanks for emailing to inform me about the zlib
|
||||
1.2.2 update.
|
||||
|
||||
luigi sandon - thanks for pointing out the missing loop condition
|
||||
(Z_STREAM_END) in ZInternalCompressStream and ZInternalDecompressStream.
|
||||
|
||||
ferry van genderen - thanks for assisting me fine tune and beta test the
|
||||
ZInternalCompressStream and ZInternalDecompressStream routines.
|
||||
|
||||
mathijs van veluw - thanks for emailing to inform me about the zlib 1.2.3
|
||||
update.
|
||||
|
||||
j. rathlev - thanks for pointing out the FStreamPos and TStream.Position
|
||||
type inconsistency.
|
||||
|
||||
ralf wenske - thanks for prototyping and assisting with ZCompressStrG and
|
||||
ZCompressStreamG.
|
||||
|
||||
roman krupicka - thanks for pointing out the DateUtils unit and the
|
||||
DateTimeToUnix function wasn't available prior to delphi 6.
|
||||
|
||||
anders johansen - thanks for pointing out the ELibError constructor
|
||||
incompatibility with c++ builder.
|
||||
|
||||
marcin treffler - thanks for pointing out the missing PWord declaration for
|
||||
delphi 5.
|
||||
|
||||
jean-jacques esquirol - thanks for pointing out the "result" address issue
|
||||
when processing filename and comment flags/content in GZCompressStr; and
|
||||
for pointing out the type differences with TGZTrailer.Crc (Cardinal) and
|
||||
ZCrc32 (Longint).
|
||||
|
||||
graham wideman - thanks for beta testing GZDecompressStreamSize and pointing
|
||||
out the position handling issue in GZDecompressStream.
|
||||
|
||||
marcin szafrański - thanks for beta testing the delphi 2009 changes.
|
||||
|
||||
iztok kacin - thanks for the CONDITIONALEXPRESSIONS, CompilerVersion
|
||||
changes, and assisting me design and further improve support for delphi
|
||||
2009.
|
||||
|
||||
oleg matrozov - thanks for pointing out the missing loop condition
|
||||
(avail_in > 0) in ZInternalCompress and ZInternalDecompress; and for
|
||||
prototyping and assisting with the TZ*Buffer classes.
|
||||
|
||||
edward koo - thanks for pointing out the delphi 5 incompatibility with the
|
||||
overloaded Z*String* routines.
|
||||
|
||||
farshad mohajeri - thank for the paypal donation
|
||||
|
||||
egron elbra - thanks for pointing out the range exception when moving empty
|
||||
strings
|
||||
|
||||
tommi prami - thanks for emailing to inform me about the zlib 1.2.6 udpate
|
||||
|
||||
marian pascalau - thanks for providing the win64 obj files and your win64
|
||||
modifications
|
||||
|
||||
-- contents ------------------------------------------------------------------
|
||||
|
||||
delphi files
|
||||
|
||||
zlibex.inc
|
||||
zlibex.pas
|
||||
zlibexapi.pas
|
||||
zlibexgz.pas
|
||||
|
||||
objects files used by zlibex.pas
|
||||
|
||||
win32\adler32.obj
|
||||
win32\compress.obj
|
||||
win32\crc32.obj
|
||||
win32\deflate.obj
|
||||
win32\infback.obj
|
||||
win32\inffast.obj
|
||||
win32\inflate.obj
|
||||
win32\inftrees.obj
|
||||
win32\trees.obj
|
||||
|
||||
win64\adler32.obj
|
||||
win64\compress.obj
|
||||
win64\crc32.obj
|
||||
win64\deflate.obj
|
||||
win64\infback.obj
|
||||
win64\inffast.obj
|
||||
win64\inflate.obj
|
||||
win64\inftrees.obj
|
||||
win64\trees.obj
|
||||
|
||||
zlib 1.2.7 source files (http://www.zlib.net)
|
||||
|
||||
zlib\adler32.c
|
||||
zlib\compress.c
|
||||
zlib\crc32.c
|
||||
zlib\deflate.c
|
||||
zlib\infback.c
|
||||
zlib\inffast.c
|
||||
zlib\inflate.c
|
||||
zlib\inftrees.c
|
||||
zlib\trees.c
|
||||
zlib\zutil.c
|
||||
zlib\crc32.h
|
||||
zlib\deflate.h
|
||||
zlib\inffast.h
|
||||
zlib\inffixed.h
|
||||
zlib\inflate.h
|
||||
zlib\inftrees.h
|
||||
zlib\trees.h
|
||||
zlib\zconf.h
|
||||
zlib\zlib.h
|
||||
zlib\zutil.h
|
||||
|
||||
BIN
contrib/fundamentals/ZLib/zlib127/win32/adler32.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win32/adler32.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win32/compress.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win32/compress.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win32/crc32.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win32/crc32.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win32/deflate.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win32/deflate.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win32/infback.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win32/infback.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win32/inffast.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win32/inffast.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win32/inflate.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win32/inflate.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win32/inftrees.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win32/inftrees.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win32/trees.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win32/trees.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win64/adler32.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win64/adler32.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win64/compress.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win64/compress.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win64/crc32.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win64/crc32.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win64/deflate.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win64/deflate.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win64/infback.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win64/infback.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win64/inffast.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win64/inffast.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win64/inflate.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win64/inflate.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win64/inftrees.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win64/inftrees.obj
Normal file
Binary file not shown.
BIN
contrib/fundamentals/ZLib/zlib127/win64/trees.obj
Normal file
BIN
contrib/fundamentals/ZLib/zlib127/win64/trees.obj
Normal file
Binary file not shown.
179
contrib/fundamentals/ZLib/zlib127/zlib/adler32.c
Normal file
179
contrib/fundamentals/ZLib/zlib127/zlib/adler32.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
* Copyright (C) 1995-2011 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
#define local static
|
||||
|
||||
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
||||
|
||||
#define BASE 65521 /* largest prime smaller than 65536 */
|
||||
#define NMAX 5552
|
||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
|
||||
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
|
||||
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||
|
||||
/* use NO_DIVIDE if your processor does not do division in hardware --
|
||||
try it both ways to see which is faster */
|
||||
#ifdef NO_DIVIDE
|
||||
/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
|
||||
(thank you to John Reiser for pointing this out) */
|
||||
# define CHOP(a) \
|
||||
do { \
|
||||
unsigned long tmp = a >> 16; \
|
||||
a &= 0xffffUL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
} while (0)
|
||||
# define MOD28(a) \
|
||||
do { \
|
||||
CHOP(a); \
|
||||
if (a >= BASE) a -= BASE; \
|
||||
} while (0)
|
||||
# define MOD(a) \
|
||||
do { \
|
||||
CHOP(a); \
|
||||
MOD28(a); \
|
||||
} while (0)
|
||||
# define MOD63(a) \
|
||||
do { /* this assumes a is not negative */ \
|
||||
z_off64_t tmp = a >> 32; \
|
||||
a &= 0xffffffffL; \
|
||||
a += (tmp << 8) - (tmp << 5) + tmp; \
|
||||
tmp = a >> 16; \
|
||||
a &= 0xffffL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
tmp = a >> 16; \
|
||||
a &= 0xffffL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
if (a >= BASE) a -= BASE; \
|
||||
} while (0)
|
||||
#else
|
||||
# define MOD(a) a %= BASE
|
||||
# define MOD28(a) a %= BASE
|
||||
# define MOD63(a) a %= BASE
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32(adler, buf, len)
|
||||
uLong adler;
|
||||
const Bytef *buf;
|
||||
uInt len;
|
||||
{
|
||||
unsigned long sum2;
|
||||
unsigned n;
|
||||
|
||||
/* split Adler-32 into component sums */
|
||||
sum2 = (adler >> 16) & 0xffff;
|
||||
adler &= 0xffff;
|
||||
|
||||
/* in case user likes doing a byte at a time, keep it fast */
|
||||
if (len == 1) {
|
||||
adler += buf[0];
|
||||
if (adler >= BASE)
|
||||
adler -= BASE;
|
||||
sum2 += adler;
|
||||
if (sum2 >= BASE)
|
||||
sum2 -= BASE;
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* initial Adler-32 value (deferred check for len == 1 speed) */
|
||||
if (buf == Z_NULL)
|
||||
return 1L;
|
||||
|
||||
/* in case short lengths are provided, keep it somewhat fast */
|
||||
if (len < 16) {
|
||||
while (len--) {
|
||||
adler += *buf++;
|
||||
sum2 += adler;
|
||||
}
|
||||
if (adler >= BASE)
|
||||
adler -= BASE;
|
||||
MOD28(sum2); /* only added so many BASE's */
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* do length NMAX blocks -- requires just one modulo operation */
|
||||
while (len >= NMAX) {
|
||||
len -= NMAX;
|
||||
n = NMAX / 16; /* NMAX is divisible by 16 */
|
||||
do {
|
||||
DO16(buf); /* 16 sums unrolled */
|
||||
buf += 16;
|
||||
} while (--n);
|
||||
MOD(adler);
|
||||
MOD(sum2);
|
||||
}
|
||||
|
||||
/* do remaining bytes (less than NMAX, still just one modulo) */
|
||||
if (len) { /* avoid modulos if none remaining */
|
||||
while (len >= 16) {
|
||||
len -= 16;
|
||||
DO16(buf);
|
||||
buf += 16;
|
||||
}
|
||||
while (len--) {
|
||||
adler += *buf++;
|
||||
sum2 += adler;
|
||||
}
|
||||
MOD(adler);
|
||||
MOD(sum2);
|
||||
}
|
||||
|
||||
/* return recombined sums */
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
local uLong adler32_combine_(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
unsigned rem;
|
||||
|
||||
/* for negative len, return invalid adler32 as a clue for debugging */
|
||||
if (len2 < 0)
|
||||
return 0xffffffffUL;
|
||||
|
||||
/* the derivation of this formula is left as an exercise for the reader */
|
||||
MOD63(len2); /* assumes len2 >= 0 */
|
||||
rem = (unsigned)len2;
|
||||
sum1 = adler1 & 0xffff;
|
||||
sum2 = rem * sum1;
|
||||
MOD(sum2);
|
||||
sum1 += (adler2 & 0xffff) + BASE - 1;
|
||||
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
||||
if (sum1 >= BASE) sum1 -= BASE;
|
||||
if (sum1 >= BASE) sum1 -= BASE;
|
||||
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
|
||||
if (sum2 >= BASE) sum2 -= BASE;
|
||||
return sum1 | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off_t len2;
|
||||
{
|
||||
return adler32_combine_(adler1, adler2, len2);
|
||||
}
|
||||
|
||||
uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
return adler32_combine_(adler1, adler2, len2);
|
||||
}
|
||||
80
contrib/fundamentals/ZLib/zlib127/zlib/compress.c
Normal file
80
contrib/fundamentals/ZLib/zlib127/zlib/compress.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/* compress.c -- compress a memory buffer
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
|
||||
/* ===========================================================================
|
||||
Compresses the source buffer into the destination buffer. The level
|
||||
parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||
length of the source buffer. Upon entry, destLen is the total size of the
|
||||
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
||||
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
||||
|
||||
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
int level;
|
||||
{
|
||||
z_stream stream;
|
||||
int err;
|
||||
|
||||
stream.next_in = (Bytef*)source;
|
||||
stream.avail_in = (uInt)sourceLen;
|
||||
#ifdef MAXSEG_64K
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
|
||||
#endif
|
||||
stream.next_out = dest;
|
||||
stream.avail_out = (uInt)*destLen;
|
||||
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
|
||||
|
||||
stream.zalloc = (alloc_func)0;
|
||||
stream.zfree = (free_func)0;
|
||||
stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&stream, level);
|
||||
if (err != Z_OK) return err;
|
||||
|
||||
err = deflate(&stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
deflateEnd(&stream);
|
||||
return err == Z_OK ? Z_BUF_ERROR : err;
|
||||
}
|
||||
*destLen = stream.total_out;
|
||||
|
||||
err = deflateEnd(&stream);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
int ZEXPORT compress (dest, destLen, source, sourceLen)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
{
|
||||
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
If the default memLevel or windowBits for deflateInit() is changed, then
|
||||
this function needs to be updated.
|
||||
*/
|
||||
uLong ZEXPORT compressBound (sourceLen)
|
||||
uLong sourceLen;
|
||||
{
|
||||
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
|
||||
(sourceLen >> 25) + 13;
|
||||
}
|
||||
425
contrib/fundamentals/ZLib/zlib127/zlib/crc32.c
Normal file
425
contrib/fundamentals/ZLib/zlib127/zlib/crc32.c
Normal file
@@ -0,0 +1,425 @@
|
||||
/* crc32.c -- compute the CRC-32 of a data stream
|
||||
* Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
||||
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
|
||||
* tables for updating the shift register in one step with three exclusive-ors
|
||||
* instead of four steps with four exclusive-ors. This results in about a
|
||||
* factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
/*
|
||||
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
|
||||
protection on the static variables used to control the first-use generation
|
||||
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
||||
first call get_crc_table() to initialize the tables before allowing more than
|
||||
one thread to use crc32().
|
||||
|
||||
DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
|
||||
*/
|
||||
|
||||
#ifdef MAKECRCH
|
||||
# include <stdio.h>
|
||||
# ifndef DYNAMIC_CRC_TABLE
|
||||
# define DYNAMIC_CRC_TABLE
|
||||
# endif /* !DYNAMIC_CRC_TABLE */
|
||||
#endif /* MAKECRCH */
|
||||
|
||||
#include "zutil.h" /* for STDC and FAR definitions */
|
||||
|
||||
#define local static
|
||||
|
||||
/* Definitions for doing the crc four data bytes at a time. */
|
||||
#if !defined(NOBYFOUR) && defined(Z_U4)
|
||||
# define BYFOUR
|
||||
#endif
|
||||
#ifdef BYFOUR
|
||||
local unsigned long crc32_little OF((unsigned long,
|
||||
const unsigned char FAR *, unsigned));
|
||||
local unsigned long crc32_big OF((unsigned long,
|
||||
const unsigned char FAR *, unsigned));
|
||||
# define TBLS 8
|
||||
#else
|
||||
# define TBLS 1
|
||||
#endif /* BYFOUR */
|
||||
|
||||
/* Local functions for crc concatenation */
|
||||
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
||||
unsigned long vec));
|
||||
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
||||
local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
|
||||
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
|
||||
local volatile int crc_table_empty = 1;
|
||||
local z_crc_t FAR crc_table[TBLS][256];
|
||||
local void make_crc_table OF((void));
|
||||
#ifdef MAKECRCH
|
||||
local void write_table OF((FILE *, const z_crc_t FAR *));
|
||||
#endif /* MAKECRCH */
|
||||
/*
|
||||
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
||||
|
||||
Polynomials over GF(2) are represented in binary, one bit per coefficient,
|
||||
with the lowest powers in the most significant bit. Then adding polynomials
|
||||
is just exclusive-or, and multiplying a polynomial by x is a right shift by
|
||||
one. If we call the above polynomial p, and represent a byte as the
|
||||
polynomial q, also with the lowest power in the most significant bit (so the
|
||||
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
|
||||
where a mod b means the remainder after dividing a by b.
|
||||
|
||||
This calculation is done using the shift-register method of multiplying and
|
||||
taking the remainder. The register is initialized to zero, and for each
|
||||
incoming bit, x^32 is added mod p to the register if the bit is a one (where
|
||||
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
|
||||
x (which is shifting right by one and adding x^32 mod p if the bit shifted
|
||||
out is a one). We start with the highest power (least significant bit) of
|
||||
q and repeat for all eight bits of q.
|
||||
|
||||
The first table is simply the CRC of all possible eight bit values. This is
|
||||
all the information needed to generate CRCs on data a byte at a time for all
|
||||
combinations of CRC register values and incoming bytes. The remaining tables
|
||||
allow for word-at-a-time CRC calculation for both big-endian and little-
|
||||
endian machines, where a word is four bytes.
|
||||
*/
|
||||
local void make_crc_table()
|
||||
{
|
||||
z_crc_t c;
|
||||
int n, k;
|
||||
z_crc_t poly; /* polynomial exclusive-or pattern */
|
||||
/* terms of polynomial defining this crc (except x^32): */
|
||||
static volatile int first = 1; /* flag to limit concurrent making */
|
||||
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
||||
|
||||
/* See if another task is already doing this (not thread-safe, but better
|
||||
than nothing -- significantly reduces duration of vulnerability in
|
||||
case the advice about DYNAMIC_CRC_TABLE is ignored) */
|
||||
if (first) {
|
||||
first = 0;
|
||||
|
||||
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
||||
poly = 0;
|
||||
for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
|
||||
poly |= (z_crc_t)1 << (31 - p[n]);
|
||||
|
||||
/* generate a crc for every 8-bit value */
|
||||
for (n = 0; n < 256; n++) {
|
||||
c = (z_crc_t)n;
|
||||
for (k = 0; k < 8; k++)
|
||||
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||
crc_table[0][n] = c;
|
||||
}
|
||||
|
||||
#ifdef BYFOUR
|
||||
/* generate crc for each value followed by one, two, and three zeros,
|
||||
and then the byte reversal of those as well as the first table */
|
||||
for (n = 0; n < 256; n++) {
|
||||
c = crc_table[0][n];
|
||||
crc_table[4][n] = ZSWAP32(c);
|
||||
for (k = 1; k < 4; k++) {
|
||||
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
||||
crc_table[k][n] = c;
|
||||
crc_table[k + 4][n] = ZSWAP32(c);
|
||||
}
|
||||
}
|
||||
#endif /* BYFOUR */
|
||||
|
||||
crc_table_empty = 0;
|
||||
}
|
||||
else { /* not first */
|
||||
/* wait for the other guy to finish (not efficient, but rare) */
|
||||
while (crc_table_empty)
|
||||
;
|
||||
}
|
||||
|
||||
#ifdef MAKECRCH
|
||||
/* write out CRC tables to crc32.h */
|
||||
{
|
||||
FILE *out;
|
||||
|
||||
out = fopen("crc32.h", "w");
|
||||
if (out == NULL) return;
|
||||
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
||||
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
||||
fprintf(out, "local const z_crc_t FAR ");
|
||||
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
||||
write_table(out, crc_table[0]);
|
||||
# ifdef BYFOUR
|
||||
fprintf(out, "#ifdef BYFOUR\n");
|
||||
for (k = 1; k < 8; k++) {
|
||||
fprintf(out, " },\n {\n");
|
||||
write_table(out, crc_table[k]);
|
||||
}
|
||||
fprintf(out, "#endif\n");
|
||||
# endif /* BYFOUR */
|
||||
fprintf(out, " }\n};\n");
|
||||
fclose(out);
|
||||
}
|
||||
#endif /* MAKECRCH */
|
||||
}
|
||||
|
||||
#ifdef MAKECRCH
|
||||
local void write_table(out, table)
|
||||
FILE *out;
|
||||
const z_crc_t FAR *table;
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
|
||||
(unsigned long)(table[n]),
|
||||
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
||||
}
|
||||
#endif /* MAKECRCH */
|
||||
|
||||
#else /* !DYNAMIC_CRC_TABLE */
|
||||
/* ========================================================================
|
||||
* Tables of CRC-32s of all single-byte values, made by make_crc_table().
|
||||
*/
|
||||
#include "crc32.h"
|
||||
#endif /* DYNAMIC_CRC_TABLE */
|
||||
|
||||
/* =========================================================================
|
||||
* This function can be used by asm versions of crc32()
|
||||
*/
|
||||
const z_crc_t FAR * ZEXPORT get_crc_table()
|
||||
{
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty)
|
||||
make_crc_table();
|
||||
#endif /* DYNAMIC_CRC_TABLE */
|
||||
return (const z_crc_t FAR *)crc_table;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
|
||||
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
|
||||
|
||||
/* ========================================================================= */
|
||||
unsigned long ZEXPORT crc32(crc, buf, len)
|
||||
unsigned long crc;
|
||||
const unsigned char FAR *buf;
|
||||
uInt len;
|
||||
{
|
||||
if (buf == Z_NULL) return 0UL;
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty)
|
||||
make_crc_table();
|
||||
#endif /* DYNAMIC_CRC_TABLE */
|
||||
|
||||
#ifdef BYFOUR
|
||||
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
||||
z_crc_t endian;
|
||||
|
||||
endian = 1;
|
||||
if (*((unsigned char *)(&endian)))
|
||||
return crc32_little(crc, buf, len);
|
||||
else
|
||||
return crc32_big(crc, buf, len);
|
||||
}
|
||||
#endif /* BYFOUR */
|
||||
crc = crc ^ 0xffffffffUL;
|
||||
while (len >= 8) {
|
||||
DO8;
|
||||
len -= 8;
|
||||
}
|
||||
if (len) do {
|
||||
DO1;
|
||||
} while (--len);
|
||||
return crc ^ 0xffffffffUL;
|
||||
}
|
||||
|
||||
#ifdef BYFOUR
|
||||
|
||||
/* ========================================================================= */
|
||||
#define DOLIT4 c ^= *buf4++; \
|
||||
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
|
||||
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
|
||||
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
|
||||
|
||||
/* ========================================================================= */
|
||||
local unsigned long crc32_little(crc, buf, len)
|
||||
unsigned long crc;
|
||||
const unsigned char FAR *buf;
|
||||
unsigned len;
|
||||
{
|
||||
register z_crc_t c;
|
||||
register const z_crc_t FAR *buf4;
|
||||
|
||||
c = (z_crc_t)crc;
|
||||
c = ~c;
|
||||
while (len && ((ptrdiff_t)buf & 3)) {
|
||||
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
||||
len--;
|
||||
}
|
||||
|
||||
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
|
||||
while (len >= 32) {
|
||||
DOLIT32;
|
||||
len -= 32;
|
||||
}
|
||||
while (len >= 4) {
|
||||
DOLIT4;
|
||||
len -= 4;
|
||||
}
|
||||
buf = (const unsigned char FAR *)buf4;
|
||||
|
||||
if (len) do {
|
||||
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
||||
} while (--len);
|
||||
c = ~c;
|
||||
return (unsigned long)c;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
#define DOBIG4 c ^= *++buf4; \
|
||||
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
|
||||
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
|
||||
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
|
||||
|
||||
/* ========================================================================= */
|
||||
local unsigned long crc32_big(crc, buf, len)
|
||||
unsigned long crc;
|
||||
const unsigned char FAR *buf;
|
||||
unsigned len;
|
||||
{
|
||||
register z_crc_t c;
|
||||
register const z_crc_t FAR *buf4;
|
||||
|
||||
c = ZSWAP32((z_crc_t)crc);
|
||||
c = ~c;
|
||||
while (len && ((ptrdiff_t)buf & 3)) {
|
||||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||
len--;
|
||||
}
|
||||
|
||||
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
|
||||
buf4--;
|
||||
while (len >= 32) {
|
||||
DOBIG32;
|
||||
len -= 32;
|
||||
}
|
||||
while (len >= 4) {
|
||||
DOBIG4;
|
||||
len -= 4;
|
||||
}
|
||||
buf4++;
|
||||
buf = (const unsigned char FAR *)buf4;
|
||||
|
||||
if (len) do {
|
||||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||
} while (--len);
|
||||
c = ~c;
|
||||
return (unsigned long)(ZSWAP32(c));
|
||||
}
|
||||
|
||||
#endif /* BYFOUR */
|
||||
|
||||
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
|
||||
|
||||
/* ========================================================================= */
|
||||
local unsigned long gf2_matrix_times(mat, vec)
|
||||
unsigned long *mat;
|
||||
unsigned long vec;
|
||||
{
|
||||
unsigned long sum;
|
||||
|
||||
sum = 0;
|
||||
while (vec) {
|
||||
if (vec & 1)
|
||||
sum ^= *mat;
|
||||
vec >>= 1;
|
||||
mat++;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
local void gf2_matrix_square(square, mat)
|
||||
unsigned long *square;
|
||||
unsigned long *mat;
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; n < GF2_DIM; n++)
|
||||
square[n] = gf2_matrix_times(mat, mat[n]);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
local uLong crc32_combine_(crc1, crc2, len2)
|
||||
uLong crc1;
|
||||
uLong crc2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
int n;
|
||||
unsigned long row;
|
||||
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
|
||||
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
|
||||
|
||||
/* degenerate case (also disallow negative lengths) */
|
||||
if (len2 <= 0)
|
||||
return crc1;
|
||||
|
||||
/* put operator for one zero bit in odd */
|
||||
odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
|
||||
row = 1;
|
||||
for (n = 1; n < GF2_DIM; n++) {
|
||||
odd[n] = row;
|
||||
row <<= 1;
|
||||
}
|
||||
|
||||
/* put operator for two zero bits in even */
|
||||
gf2_matrix_square(even, odd);
|
||||
|
||||
/* put operator for four zero bits in odd */
|
||||
gf2_matrix_square(odd, even);
|
||||
|
||||
/* apply len2 zeros to crc1 (first square will put the operator for one
|
||||
zero byte, eight zero bits, in even) */
|
||||
do {
|
||||
/* apply zeros operator for this bit of len2 */
|
||||
gf2_matrix_square(even, odd);
|
||||
if (len2 & 1)
|
||||
crc1 = gf2_matrix_times(even, crc1);
|
||||
len2 >>= 1;
|
||||
|
||||
/* if no more bits set, then done */
|
||||
if (len2 == 0)
|
||||
break;
|
||||
|
||||
/* another iteration of the loop with odd and even swapped */
|
||||
gf2_matrix_square(odd, even);
|
||||
if (len2 & 1)
|
||||
crc1 = gf2_matrix_times(odd, crc1);
|
||||
len2 >>= 1;
|
||||
|
||||
/* if no more bits set, then done */
|
||||
} while (len2 != 0);
|
||||
|
||||
/* return combined crc */
|
||||
crc1 ^= crc2;
|
||||
return crc1;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
||||
uLong crc1;
|
||||
uLong crc2;
|
||||
z_off_t len2;
|
||||
{
|
||||
return crc32_combine_(crc1, crc2, len2);
|
||||
}
|
||||
|
||||
uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
|
||||
uLong crc1;
|
||||
uLong crc2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
return crc32_combine_(crc1, crc2, len2);
|
||||
}
|
||||
441
contrib/fundamentals/ZLib/zlib127/zlib/crc32.h
Normal file
441
contrib/fundamentals/ZLib/zlib127/zlib/crc32.h
Normal file
@@ -0,0 +1,441 @@
|
||||
/* crc32.h -- tables for rapid CRC calculation
|
||||
* Generated automatically by crc32.c
|
||||
*/
|
||||
|
||||
local const z_crc_t FAR crc_table[TBLS][256] =
|
||||
{
|
||||
{
|
||||
0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
|
||||
0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
|
||||
0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
|
||||
0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
|
||||
0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
|
||||
0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
|
||||
0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
|
||||
0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
|
||||
0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
|
||||
0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
|
||||
0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
|
||||
0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
|
||||
0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
|
||||
0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
|
||||
0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
|
||||
0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
|
||||
0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
|
||||
0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
|
||||
0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
|
||||
0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
|
||||
0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
|
||||
0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
|
||||
0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
|
||||
0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
|
||||
0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
|
||||
0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
|
||||
0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
|
||||
0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
|
||||
0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
|
||||
0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
|
||||
0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
|
||||
0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
|
||||
0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
|
||||
0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
|
||||
0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
|
||||
0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
|
||||
0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
|
||||
0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
|
||||
0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
|
||||
0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
|
||||
0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
|
||||
0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
|
||||
0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
|
||||
0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
|
||||
0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
|
||||
0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
|
||||
0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
|
||||
0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
|
||||
0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
|
||||
0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
|
||||
0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
|
||||
0x2d02ef8dUL
|
||||
#ifdef BYFOUR
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
|
||||
0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
|
||||
0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
|
||||
0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
|
||||
0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
|
||||
0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
|
||||
0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
|
||||
0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
|
||||
0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
|
||||
0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
|
||||
0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
|
||||
0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
|
||||
0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
|
||||
0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
|
||||
0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
|
||||
0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
|
||||
0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
|
||||
0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
|
||||
0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
|
||||
0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
|
||||
0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
|
||||
0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
|
||||
0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
|
||||
0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
|
||||
0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
|
||||
0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
|
||||
0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
|
||||
0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
|
||||
0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
|
||||
0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
|
||||
0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
|
||||
0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
|
||||
0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
|
||||
0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
|
||||
0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
|
||||
0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
|
||||
0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
|
||||
0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
|
||||
0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
|
||||
0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
|
||||
0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
|
||||
0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
|
||||
0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
|
||||
0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
|
||||
0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
|
||||
0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
|
||||
0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
|
||||
0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
|
||||
0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
|
||||
0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
|
||||
0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
|
||||
0x9324fd72UL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
|
||||
0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
|
||||
0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
|
||||
0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
|
||||
0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
|
||||
0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
|
||||
0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
|
||||
0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
|
||||
0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
|
||||
0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
|
||||
0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
|
||||
0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
|
||||
0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
|
||||
0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
|
||||
0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
|
||||
0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
|
||||
0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
|
||||
0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
|
||||
0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
|
||||
0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
|
||||
0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
|
||||
0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
|
||||
0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
|
||||
0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
|
||||
0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
|
||||
0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
|
||||
0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
|
||||
0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
|
||||
0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
|
||||
0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
|
||||
0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
|
||||
0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
|
||||
0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
|
||||
0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
|
||||
0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
|
||||
0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
|
||||
0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
|
||||
0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
|
||||
0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
|
||||
0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
|
||||
0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
|
||||
0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
|
||||
0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
|
||||
0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
|
||||
0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
|
||||
0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
|
||||
0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
|
||||
0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
|
||||
0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
|
||||
0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
|
||||
0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
|
||||
0xbe9834edUL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
|
||||
0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
|
||||
0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
|
||||
0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
|
||||
0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
|
||||
0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
|
||||
0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
|
||||
0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
|
||||
0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
|
||||
0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
|
||||
0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
|
||||
0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
|
||||
0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
|
||||
0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
|
||||
0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
|
||||
0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
|
||||
0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
|
||||
0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
|
||||
0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
|
||||
0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
|
||||
0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
|
||||
0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
|
||||
0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
|
||||
0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
|
||||
0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
|
||||
0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
|
||||
0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
|
||||
0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
|
||||
0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
|
||||
0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
|
||||
0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
|
||||
0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
|
||||
0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
|
||||
0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
|
||||
0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
|
||||
0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
|
||||
0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
|
||||
0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
|
||||
0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
|
||||
0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
|
||||
0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
|
||||
0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
|
||||
0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
|
||||
0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
|
||||
0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
|
||||
0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
|
||||
0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
|
||||
0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
|
||||
0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
|
||||
0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
|
||||
0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
|
||||
0xde0506f1UL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
|
||||
0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
|
||||
0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
|
||||
0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
|
||||
0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
|
||||
0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
|
||||
0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
|
||||
0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
|
||||
0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
|
||||
0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
|
||||
0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
|
||||
0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
|
||||
0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
|
||||
0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
|
||||
0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
|
||||
0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
|
||||
0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
|
||||
0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
|
||||
0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
|
||||
0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
|
||||
0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
|
||||
0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
|
||||
0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
|
||||
0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
|
||||
0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
|
||||
0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
|
||||
0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
|
||||
0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
|
||||
0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
|
||||
0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
|
||||
0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
|
||||
0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
|
||||
0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
|
||||
0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
|
||||
0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
|
||||
0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
|
||||
0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
|
||||
0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
|
||||
0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
|
||||
0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
|
||||
0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
|
||||
0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
|
||||
0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
|
||||
0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
|
||||
0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
|
||||
0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
|
||||
0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
|
||||
0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
|
||||
0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
|
||||
0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
|
||||
0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
|
||||
0x8def022dUL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
|
||||
0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
|
||||
0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
|
||||
0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
|
||||
0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
|
||||
0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
|
||||
0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
|
||||
0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
|
||||
0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
|
||||
0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
|
||||
0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
|
||||
0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
|
||||
0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
|
||||
0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
|
||||
0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
|
||||
0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
|
||||
0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
|
||||
0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
|
||||
0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
|
||||
0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
|
||||
0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
|
||||
0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
|
||||
0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
|
||||
0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
|
||||
0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
|
||||
0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
|
||||
0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
|
||||
0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
|
||||
0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
|
||||
0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
|
||||
0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
|
||||
0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
|
||||
0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
|
||||
0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
|
||||
0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
|
||||
0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
|
||||
0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
|
||||
0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
|
||||
0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
|
||||
0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
|
||||
0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
|
||||
0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
|
||||
0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
|
||||
0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
|
||||
0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
|
||||
0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
|
||||
0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
|
||||
0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
|
||||
0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
|
||||
0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
|
||||
0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
|
||||
0x72fd2493UL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
|
||||
0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
|
||||
0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
|
||||
0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
|
||||
0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
|
||||
0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
|
||||
0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
|
||||
0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
|
||||
0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
|
||||
0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
|
||||
0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
|
||||
0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
|
||||
0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
|
||||
0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
|
||||
0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
|
||||
0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
|
||||
0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
|
||||
0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
|
||||
0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
|
||||
0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
|
||||
0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
|
||||
0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
|
||||
0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
|
||||
0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
|
||||
0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
|
||||
0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
|
||||
0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
|
||||
0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
|
||||
0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
|
||||
0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
|
||||
0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
|
||||
0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
|
||||
0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
|
||||
0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
|
||||
0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
|
||||
0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
|
||||
0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
|
||||
0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
|
||||
0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
|
||||
0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
|
||||
0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
|
||||
0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
|
||||
0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
|
||||
0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
|
||||
0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
|
||||
0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
|
||||
0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
|
||||
0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
|
||||
0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
|
||||
0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
|
||||
0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
|
||||
0xed3498beUL
|
||||
},
|
||||
{
|
||||
0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
|
||||
0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
|
||||
0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
|
||||
0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
|
||||
0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
|
||||
0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
|
||||
0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
|
||||
0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
|
||||
0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
|
||||
0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
|
||||
0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
|
||||
0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
|
||||
0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
|
||||
0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
|
||||
0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
|
||||
0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
|
||||
0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
|
||||
0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
|
||||
0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
|
||||
0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
|
||||
0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
|
||||
0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
|
||||
0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
|
||||
0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
|
||||
0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
|
||||
0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
|
||||
0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
|
||||
0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
|
||||
0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
|
||||
0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
|
||||
0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
|
||||
0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
|
||||
0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
|
||||
0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
|
||||
0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
|
||||
0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
|
||||
0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
|
||||
0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
|
||||
0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
|
||||
0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
|
||||
0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
|
||||
0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
|
||||
0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
|
||||
0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
|
||||
0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
|
||||
0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
|
||||
0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
|
||||
0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
|
||||
0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
|
||||
0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
|
||||
0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
|
||||
0xf10605deUL
|
||||
#endif
|
||||
}
|
||||
};
|
||||
1965
contrib/fundamentals/ZLib/zlib127/zlib/deflate.c
Normal file
1965
contrib/fundamentals/ZLib/zlib127/zlib/deflate.c
Normal file
File diff suppressed because it is too large
Load Diff
346
contrib/fundamentals/ZLib/zlib127/zlib/deflate.h
Normal file
346
contrib/fundamentals/ZLib/zlib127/zlib/deflate.h
Normal file
@@ -0,0 +1,346 @@
|
||||
/* deflate.h -- internal compression state
|
||||
* Copyright (C) 1995-2012 Jean-loup Gailly
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef DEFLATE_H
|
||||
#define DEFLATE_H
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
/* define NO_GZIP when compiling if you want to disable gzip header and
|
||||
trailer creation by deflate(). NO_GZIP would be used to avoid linking in
|
||||
the crc code when it is not needed. For shared libraries, gzip encoding
|
||||
should be left enabled. */
|
||||
#ifndef NO_GZIP
|
||||
# define GZIP
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
* Internal compression state.
|
||||
*/
|
||||
|
||||
#define LENGTH_CODES 29
|
||||
/* number of length codes, not counting the special END_BLOCK code */
|
||||
|
||||
#define LITERALS 256
|
||||
/* number of literal bytes 0..255 */
|
||||
|
||||
#define L_CODES (LITERALS+1+LENGTH_CODES)
|
||||
/* number of Literal or Length codes, including the END_BLOCK code */
|
||||
|
||||
#define D_CODES 30
|
||||
/* number of distance codes */
|
||||
|
||||
#define BL_CODES 19
|
||||
/* number of codes used to transfer the bit lengths */
|
||||
|
||||
#define HEAP_SIZE (2*L_CODES+1)
|
||||
/* maximum heap size */
|
||||
|
||||
#define MAX_BITS 15
|
||||
/* All codes must not exceed MAX_BITS bits */
|
||||
|
||||
#define Buf_size 16
|
||||
/* size of bit buffer in bi_buf */
|
||||
|
||||
#define INIT_STATE 42
|
||||
#define EXTRA_STATE 69
|
||||
#define NAME_STATE 73
|
||||
#define COMMENT_STATE 91
|
||||
#define HCRC_STATE 103
|
||||
#define BUSY_STATE 113
|
||||
#define FINISH_STATE 666
|
||||
/* Stream status */
|
||||
|
||||
|
||||
/* Data structure describing a single value and its code string. */
|
||||
typedef struct ct_data_s {
|
||||
union {
|
||||
ush freq; /* frequency count */
|
||||
ush code; /* bit string */
|
||||
} fc;
|
||||
union {
|
||||
ush dad; /* father node in Huffman tree */
|
||||
ush len; /* length of bit string */
|
||||
} dl;
|
||||
} FAR ct_data;
|
||||
|
||||
#define Freq fc.freq
|
||||
#define Code fc.code
|
||||
#define Dad dl.dad
|
||||
#define Len dl.len
|
||||
|
||||
typedef struct static_tree_desc_s static_tree_desc;
|
||||
|
||||
typedef struct tree_desc_s {
|
||||
ct_data *dyn_tree; /* the dynamic tree */
|
||||
int max_code; /* largest code with non zero frequency */
|
||||
static_tree_desc *stat_desc; /* the corresponding static tree */
|
||||
} FAR tree_desc;
|
||||
|
||||
typedef ush Pos;
|
||||
typedef Pos FAR Posf;
|
||||
typedef unsigned IPos;
|
||||
|
||||
/* A Pos is an index in the character window. We use short instead of int to
|
||||
* save space in the various tables. IPos is used only for parameter passing.
|
||||
*/
|
||||
|
||||
typedef struct internal_state {
|
||||
z_streamp strm; /* pointer back to this zlib stream */
|
||||
int status; /* as the name implies */
|
||||
Bytef *pending_buf; /* output still pending */
|
||||
ulg pending_buf_size; /* size of pending_buf */
|
||||
Bytef *pending_out; /* next pending byte to output to the stream */
|
||||
uInt pending; /* nb of bytes in the pending buffer */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||
gz_headerp gzhead; /* gzip header information to write */
|
||||
uInt gzindex; /* where in extra, name, or comment */
|
||||
Byte method; /* STORED (for zip only) or DEFLATED */
|
||||
int last_flush; /* value of flush param for previous deflate call */
|
||||
|
||||
/* used by deflate.c: */
|
||||
|
||||
uInt w_size; /* LZ77 window size (32K by default) */
|
||||
uInt w_bits; /* log2(w_size) (8..16) */
|
||||
uInt w_mask; /* w_size - 1 */
|
||||
|
||||
Bytef *window;
|
||||
/* Sliding window. Input bytes are read into the second half of the window,
|
||||
* and move to the first half later to keep a dictionary of at least wSize
|
||||
* bytes. With this organization, matches are limited to a distance of
|
||||
* wSize-MAX_MATCH bytes, but this ensures that IO is always
|
||||
* performed with a length multiple of the block size. Also, it limits
|
||||
* the window size to 64K, which is quite useful on MSDOS.
|
||||
* To do: use the user input buffer as sliding window.
|
||||
*/
|
||||
|
||||
ulg window_size;
|
||||
/* Actual size of window: 2*wSize, except when the user input buffer
|
||||
* is directly used as sliding window.
|
||||
*/
|
||||
|
||||
Posf *prev;
|
||||
/* Link to older string with same hash index. To limit the size of this
|
||||
* array to 64K, this link is maintained only for the last 32K strings.
|
||||
* An index in this array is thus a window index modulo 32K.
|
||||
*/
|
||||
|
||||
Posf *head; /* Heads of the hash chains or NIL. */
|
||||
|
||||
uInt ins_h; /* hash index of string to be inserted */
|
||||
uInt hash_size; /* number of elements in hash table */
|
||||
uInt hash_bits; /* log2(hash_size) */
|
||||
uInt hash_mask; /* hash_size-1 */
|
||||
|
||||
uInt hash_shift;
|
||||
/* Number of bits by which ins_h must be shifted at each input
|
||||
* step. It must be such that after MIN_MATCH steps, the oldest
|
||||
* byte no longer takes part in the hash key, that is:
|
||||
* hash_shift * MIN_MATCH >= hash_bits
|
||||
*/
|
||||
|
||||
long block_start;
|
||||
/* Window position at the beginning of the current output block. Gets
|
||||
* negative when the window is moved backwards.
|
||||
*/
|
||||
|
||||
uInt match_length; /* length of best match */
|
||||
IPos prev_match; /* previous match */
|
||||
int match_available; /* set if previous match exists */
|
||||
uInt strstart; /* start of string to insert */
|
||||
uInt match_start; /* start of matching string */
|
||||
uInt lookahead; /* number of valid bytes ahead in window */
|
||||
|
||||
uInt prev_length;
|
||||
/* Length of the best match at previous step. Matches not greater than this
|
||||
* are discarded. This is used in the lazy match evaluation.
|
||||
*/
|
||||
|
||||
uInt max_chain_length;
|
||||
/* To speed up deflation, hash chains are never searched beyond this
|
||||
* length. A higher limit improves compression ratio but degrades the
|
||||
* speed.
|
||||
*/
|
||||
|
||||
uInt max_lazy_match;
|
||||
/* Attempt to find a better match only when the current match is strictly
|
||||
* smaller than this value. This mechanism is used only for compression
|
||||
* levels >= 4.
|
||||
*/
|
||||
# define max_insert_length max_lazy_match
|
||||
/* Insert new strings in the hash table only if the match length is not
|
||||
* greater than this length. This saves time but degrades compression.
|
||||
* max_insert_length is used only for compression levels <= 3.
|
||||
*/
|
||||
|
||||
int level; /* compression level (1..9) */
|
||||
int strategy; /* favor or force Huffman coding*/
|
||||
|
||||
uInt good_match;
|
||||
/* Use a faster search when the previous match is longer than this */
|
||||
|
||||
int nice_match; /* Stop searching when current match exceeds this */
|
||||
|
||||
/* used by trees.c: */
|
||||
/* Didn't use ct_data typedef below to suppress compiler warning */
|
||||
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
|
||||
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
|
||||
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
|
||||
|
||||
struct tree_desc_s l_desc; /* desc. for literal tree */
|
||||
struct tree_desc_s d_desc; /* desc. for distance tree */
|
||||
struct tree_desc_s bl_desc; /* desc. for bit length tree */
|
||||
|
||||
ush bl_count[MAX_BITS+1];
|
||||
/* number of codes at each bit length for an optimal tree */
|
||||
|
||||
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
|
||||
int heap_len; /* number of elements in the heap */
|
||||
int heap_max; /* element of largest frequency */
|
||||
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
|
||||
* The same heap array is used to build all trees.
|
||||
*/
|
||||
|
||||
uch depth[2*L_CODES+1];
|
||||
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
||||
*/
|
||||
|
||||
uchf *l_buf; /* buffer for literals or lengths */
|
||||
|
||||
uInt lit_bufsize;
|
||||
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
||||
* limiting lit_bufsize to 64K:
|
||||
* - frequencies can be kept in 16 bit counters
|
||||
* - if compression is not successful for the first block, all input
|
||||
* data is still in the window so we can still emit a stored block even
|
||||
* when input comes from standard input. (This can also be done for
|
||||
* all blocks if lit_bufsize is not greater than 32K.)
|
||||
* - if compression is not successful for a file smaller than 64K, we can
|
||||
* even emit a stored file instead of a stored block (saving 5 bytes).
|
||||
* This is applicable only for zip (not gzip or zlib).
|
||||
* - creating new Huffman trees less frequently may not provide fast
|
||||
* adaptation to changes in the input data statistics. (Take for
|
||||
* example a binary file with poorly compressible code followed by
|
||||
* a highly compressible string table.) Smaller buffer sizes give
|
||||
* fast adaptation but have of course the overhead of transmitting
|
||||
* trees more frequently.
|
||||
* - I can't count above 4
|
||||
*/
|
||||
|
||||
uInt last_lit; /* running index in l_buf */
|
||||
|
||||
ushf *d_buf;
|
||||
/* Buffer for distances. To simplify the code, d_buf and l_buf have
|
||||
* the same number of elements. To use different lengths, an extra flag
|
||||
* array would be necessary.
|
||||
*/
|
||||
|
||||
ulg opt_len; /* bit length of current block with optimal trees */
|
||||
ulg static_len; /* bit length of current block with static trees */
|
||||
uInt matches; /* number of string matches in current block */
|
||||
uInt insert; /* bytes at end of window left to insert */
|
||||
|
||||
#ifdef DEBUG
|
||||
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
|
||||
#endif
|
||||
|
||||
ush bi_buf;
|
||||
/* Output buffer. bits are inserted starting at the bottom (least
|
||||
* significant bits).
|
||||
*/
|
||||
int bi_valid;
|
||||
/* Number of valid bits in bi_buf. All bits above the last valid bit
|
||||
* are always zero.
|
||||
*/
|
||||
|
||||
ulg high_water;
|
||||
/* High water mark offset in window for initialized bytes -- bytes above
|
||||
* this are set to zero in order to avoid memory check warnings when
|
||||
* longest match routines access bytes past the input. This is then
|
||||
* updated to the new high water mark.
|
||||
*/
|
||||
|
||||
} FAR deflate_state;
|
||||
|
||||
/* Output a byte on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
|
||||
|
||||
|
||||
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
||||
/* Minimum amount of lookahead, except at the end of the input file.
|
||||
* See deflate.c for comments about the MIN_MATCH+1.
|
||||
*/
|
||||
|
||||
#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
|
||||
/* In order to simplify the code, particularly on 16 bit machines, match
|
||||
* distances are limited to MAX_DIST instead of WSIZE.
|
||||
*/
|
||||
|
||||
#define WIN_INIT MAX_MATCH
|
||||
/* Number of bytes after end of data in window to initialize in order to avoid
|
||||
memory checker errors from longest match routines */
|
||||
|
||||
/* in trees.c */
|
||||
void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
|
||||
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
||||
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
|
||||
ulg stored_len, int last));
|
||||
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
|
||||
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
|
||||
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
|
||||
ulg stored_len, int last));
|
||||
|
||||
#define d_code(dist) \
|
||||
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
|
||||
/* Mapping from a distance to a distance code. dist is the distance - 1 and
|
||||
* must not have side effects. _dist_code[256] and _dist_code[257] are never
|
||||
* used.
|
||||
*/
|
||||
|
||||
#ifndef DEBUG
|
||||
/* Inline versions of _tr_tally for speed: */
|
||||
|
||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||
extern uch ZLIB_INTERNAL _length_code[];
|
||||
extern uch ZLIB_INTERNAL _dist_code[];
|
||||
#else
|
||||
extern const uch ZLIB_INTERNAL _length_code[];
|
||||
extern const uch ZLIB_INTERNAL _dist_code[];
|
||||
#endif
|
||||
|
||||
# define _tr_tally_lit(s, c, flush) \
|
||||
{ uch cc = (c); \
|
||||
s->d_buf[s->last_lit] = 0; \
|
||||
s->l_buf[s->last_lit++] = cc; \
|
||||
s->dyn_ltree[cc].Freq++; \
|
||||
flush = (s->last_lit == s->lit_bufsize-1); \
|
||||
}
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
{ uch len = (length); \
|
||||
ush dist = (distance); \
|
||||
s->d_buf[s->last_lit] = dist; \
|
||||
s->l_buf[s->last_lit++] = len; \
|
||||
dist--; \
|
||||
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
|
||||
s->dyn_dtree[d_code(dist)].Freq++; \
|
||||
flush = (s->last_lit == s->lit_bufsize-1); \
|
||||
}
|
||||
#else
|
||||
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
flush = _tr_tally(s, distance, length)
|
||||
#endif
|
||||
|
||||
#endif /* DEFLATE_H */
|
||||
640
contrib/fundamentals/ZLib/zlib127/zlib/infback.c
Normal file
640
contrib/fundamentals/ZLib/zlib127/zlib/infback.c
Normal file
@@ -0,0 +1,640 @@
|
||||
/* infback.c -- inflate using a call-back interface
|
||||
* Copyright (C) 1995-2011 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/*
|
||||
This code is largely copied from inflate.c. Normally either infback.o or
|
||||
inflate.o would be linked into an application--not both. The interface
|
||||
with inffast.c is retained so that optimized assembler-coded versions of
|
||||
inflate_fast() can be used with either inflate.c or infback.c.
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
#include "inffast.h"
|
||||
|
||||
/* function prototypes */
|
||||
local void fixedtables OF((struct inflate_state FAR *state));
|
||||
|
||||
/*
|
||||
strm provides memory allocation functions in zalloc and zfree, or
|
||||
Z_NULL to use the library memory allocation functions.
|
||||
|
||||
windowBits is in the range 8..15, and window is a user-supplied
|
||||
window and output buffer that is 2**windowBits bytes.
|
||||
*/
|
||||
int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
|
||||
z_streamp strm;
|
||||
int windowBits;
|
||||
unsigned char FAR *window;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
|
||||
stream_size != (int)(sizeof(z_stream)))
|
||||
return Z_VERSION_ERROR;
|
||||
if (strm == Z_NULL || window == Z_NULL ||
|
||||
windowBits < 8 || windowBits > 15)
|
||||
return Z_STREAM_ERROR;
|
||||
strm->msg = Z_NULL; /* in case we return an error */
|
||||
if (strm->zalloc == (alloc_func)0) {
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zalloc = zcalloc;
|
||||
strm->opaque = (voidpf)0;
|
||||
#endif
|
||||
}
|
||||
if (strm->zfree == (free_func)0)
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zfree = zcfree;
|
||||
#endif
|
||||
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
|
||||
sizeof(struct inflate_state));
|
||||
if (state == Z_NULL) return Z_MEM_ERROR;
|
||||
Tracev((stderr, "inflate: allocated\n"));
|
||||
strm->state = (struct internal_state FAR *)state;
|
||||
state->dmax = 32768U;
|
||||
state->wbits = windowBits;
|
||||
state->wsize = 1U << windowBits;
|
||||
state->window = window;
|
||||
state->wnext = 0;
|
||||
state->whave = 0;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
Return state with length and distance decoding tables and index sizes set to
|
||||
fixed code decoding. Normally this returns fixed tables from inffixed.h.
|
||||
If BUILDFIXED is defined, then instead this routine builds the tables the
|
||||
first time it's called, and returns those tables the first time and
|
||||
thereafter. This reduces the size of the code by about 2K bytes, in
|
||||
exchange for a little execution time. However, BUILDFIXED should not be
|
||||
used for threaded applications, since the rewriting of the tables and virgin
|
||||
may not be thread-safe.
|
||||
*/
|
||||
local void fixedtables(state)
|
||||
struct inflate_state FAR *state;
|
||||
{
|
||||
#ifdef BUILDFIXED
|
||||
static int virgin = 1;
|
||||
static code *lenfix, *distfix;
|
||||
static code fixed[544];
|
||||
|
||||
/* build fixed huffman tables if first call (may not be thread safe) */
|
||||
if (virgin) {
|
||||
unsigned sym, bits;
|
||||
static code *next;
|
||||
|
||||
/* literal/length table */
|
||||
sym = 0;
|
||||
while (sym < 144) state->lens[sym++] = 8;
|
||||
while (sym < 256) state->lens[sym++] = 9;
|
||||
while (sym < 280) state->lens[sym++] = 7;
|
||||
while (sym < 288) state->lens[sym++] = 8;
|
||||
next = fixed;
|
||||
lenfix = next;
|
||||
bits = 9;
|
||||
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
|
||||
|
||||
/* distance table */
|
||||
sym = 0;
|
||||
while (sym < 32) state->lens[sym++] = 5;
|
||||
distfix = next;
|
||||
bits = 5;
|
||||
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
|
||||
|
||||
/* do this just once */
|
||||
virgin = 0;
|
||||
}
|
||||
#else /* !BUILDFIXED */
|
||||
# include "inffixed.h"
|
||||
#endif /* BUILDFIXED */
|
||||
state->lencode = lenfix;
|
||||
state->lenbits = 9;
|
||||
state->distcode = distfix;
|
||||
state->distbits = 5;
|
||||
}
|
||||
|
||||
/* Macros for inflateBack(): */
|
||||
|
||||
/* Load returned state from inflate_fast() */
|
||||
#define LOAD() \
|
||||
do { \
|
||||
put = strm->next_out; \
|
||||
left = strm->avail_out; \
|
||||
next = strm->next_in; \
|
||||
have = strm->avail_in; \
|
||||
hold = state->hold; \
|
||||
bits = state->bits; \
|
||||
} while (0)
|
||||
|
||||
/* Set state from registers for inflate_fast() */
|
||||
#define RESTORE() \
|
||||
do { \
|
||||
strm->next_out = put; \
|
||||
strm->avail_out = left; \
|
||||
strm->next_in = next; \
|
||||
strm->avail_in = have; \
|
||||
state->hold = hold; \
|
||||
state->bits = bits; \
|
||||
} while (0)
|
||||
|
||||
/* Clear the input bit accumulator */
|
||||
#define INITBITS() \
|
||||
do { \
|
||||
hold = 0; \
|
||||
bits = 0; \
|
||||
} while (0)
|
||||
|
||||
/* Assure that some input is available. If input is requested, but denied,
|
||||
then return a Z_BUF_ERROR from inflateBack(). */
|
||||
#define PULL() \
|
||||
do { \
|
||||
if (have == 0) { \
|
||||
have = in(in_desc, &next); \
|
||||
if (have == 0) { \
|
||||
next = Z_NULL; \
|
||||
ret = Z_BUF_ERROR; \
|
||||
goto inf_leave; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Get a byte of input into the bit accumulator, or return from inflateBack()
|
||||
with an error if there is no input available. */
|
||||
#define PULLBYTE() \
|
||||
do { \
|
||||
PULL(); \
|
||||
have--; \
|
||||
hold += (unsigned long)(*next++) << bits; \
|
||||
bits += 8; \
|
||||
} while (0)
|
||||
|
||||
/* Assure that there are at least n bits in the bit accumulator. If there is
|
||||
not enough available input to do that, then return from inflateBack() with
|
||||
an error. */
|
||||
#define NEEDBITS(n) \
|
||||
do { \
|
||||
while (bits < (unsigned)(n)) \
|
||||
PULLBYTE(); \
|
||||
} while (0)
|
||||
|
||||
/* Return the low n bits of the bit accumulator (n < 16) */
|
||||
#define BITS(n) \
|
||||
((unsigned)hold & ((1U << (n)) - 1))
|
||||
|
||||
/* Remove n bits from the bit accumulator */
|
||||
#define DROPBITS(n) \
|
||||
do { \
|
||||
hold >>= (n); \
|
||||
bits -= (unsigned)(n); \
|
||||
} while (0)
|
||||
|
||||
/* Remove zero to seven bits as needed to go to a byte boundary */
|
||||
#define BYTEBITS() \
|
||||
do { \
|
||||
hold >>= bits & 7; \
|
||||
bits -= bits & 7; \
|
||||
} while (0)
|
||||
|
||||
/* Assure that some output space is available, by writing out the window
|
||||
if it's full. If the write fails, return from inflateBack() with a
|
||||
Z_BUF_ERROR. */
|
||||
#define ROOM() \
|
||||
do { \
|
||||
if (left == 0) { \
|
||||
put = state->window; \
|
||||
left = state->wsize; \
|
||||
state->whave = left; \
|
||||
if (out(out_desc, put, left)) { \
|
||||
ret = Z_BUF_ERROR; \
|
||||
goto inf_leave; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
strm provides the memory allocation functions and window buffer on input,
|
||||
and provides information on the unused input on return. For Z_DATA_ERROR
|
||||
returns, strm will also provide an error message.
|
||||
|
||||
in() and out() are the call-back input and output functions. When
|
||||
inflateBack() needs more input, it calls in(). When inflateBack() has
|
||||
filled the window with output, or when it completes with data in the
|
||||
window, it calls out() to write out the data. The application must not
|
||||
change the provided input until in() is called again or inflateBack()
|
||||
returns. The application must not change the window/output buffer until
|
||||
inflateBack() returns.
|
||||
|
||||
in() and out() are called with a descriptor parameter provided in the
|
||||
inflateBack() call. This parameter can be a structure that provides the
|
||||
information required to do the read or write, as well as accumulated
|
||||
information on the input and output such as totals and check values.
|
||||
|
||||
in() should return zero on failure. out() should return non-zero on
|
||||
failure. If either in() or out() fails, than inflateBack() returns a
|
||||
Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
|
||||
was in() or out() that caused in the error. Otherwise, inflateBack()
|
||||
returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
|
||||
error, or Z_MEM_ERROR if it could not allocate memory for the state.
|
||||
inflateBack() can also return Z_STREAM_ERROR if the input parameters
|
||||
are not correct, i.e. strm is Z_NULL or the state was not initialized.
|
||||
*/
|
||||
int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
|
||||
z_streamp strm;
|
||||
in_func in;
|
||||
void FAR *in_desc;
|
||||
out_func out;
|
||||
void FAR *out_desc;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned char FAR *next; /* next input */
|
||||
unsigned char FAR *put; /* next output */
|
||||
unsigned have, left; /* available input and output */
|
||||
unsigned long hold; /* bit buffer */
|
||||
unsigned bits; /* bits in bit buffer */
|
||||
unsigned copy; /* number of stored or match bytes to copy */
|
||||
unsigned char FAR *from; /* where to copy match bytes from */
|
||||
code here; /* current decoding table entry */
|
||||
code last; /* parent table entry */
|
||||
unsigned len; /* length to copy for repeats, bits to drop */
|
||||
int ret; /* return code */
|
||||
static const unsigned short order[19] = /* permutation of code lengths */
|
||||
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
/* Check that the strm exists and that the state was initialized */
|
||||
if (strm == Z_NULL || strm->state == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
|
||||
/* Reset the state */
|
||||
strm->msg = Z_NULL;
|
||||
state->mode = TYPE;
|
||||
state->last = 0;
|
||||
state->whave = 0;
|
||||
next = strm->next_in;
|
||||
have = next != Z_NULL ? strm->avail_in : 0;
|
||||
hold = 0;
|
||||
bits = 0;
|
||||
put = state->window;
|
||||
left = state->wsize;
|
||||
|
||||
/* Inflate until end of block marked as last */
|
||||
for (;;)
|
||||
switch (state->mode) {
|
||||
case TYPE:
|
||||
/* determine and dispatch block type */
|
||||
if (state->last) {
|
||||
BYTEBITS();
|
||||
state->mode = DONE;
|
||||
break;
|
||||
}
|
||||
NEEDBITS(3);
|
||||
state->last = BITS(1);
|
||||
DROPBITS(1);
|
||||
switch (BITS(2)) {
|
||||
case 0: /* stored block */
|
||||
Tracev((stderr, "inflate: stored block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
state->mode = STORED;
|
||||
break;
|
||||
case 1: /* fixed block */
|
||||
fixedtables(state);
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
state->mode = LEN; /* decode codes */
|
||||
break;
|
||||
case 2: /* dynamic block */
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
state->mode = TABLE;
|
||||
break;
|
||||
case 3:
|
||||
strm->msg = (char *)"invalid block type";
|
||||
state->mode = BAD;
|
||||
}
|
||||
DROPBITS(2);
|
||||
break;
|
||||
|
||||
case STORED:
|
||||
/* get and verify stored block length */
|
||||
BYTEBITS(); /* go to byte boundary */
|
||||
NEEDBITS(32);
|
||||
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
|
||||
strm->msg = (char *)"invalid stored block lengths";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->length = (unsigned)hold & 0xffff;
|
||||
Tracev((stderr, "inflate: stored length %u\n",
|
||||
state->length));
|
||||
INITBITS();
|
||||
|
||||
/* copy stored block from input to output */
|
||||
while (state->length != 0) {
|
||||
copy = state->length;
|
||||
PULL();
|
||||
ROOM();
|
||||
if (copy > have) copy = have;
|
||||
if (copy > left) copy = left;
|
||||
zmemcpy(put, next, copy);
|
||||
have -= copy;
|
||||
next += copy;
|
||||
left -= copy;
|
||||
put += copy;
|
||||
state->length -= copy;
|
||||
}
|
||||
Tracev((stderr, "inflate: stored end\n"));
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
|
||||
case TABLE:
|
||||
/* get dynamic table entries descriptor */
|
||||
NEEDBITS(14);
|
||||
state->nlen = BITS(5) + 257;
|
||||
DROPBITS(5);
|
||||
state->ndist = BITS(5) + 1;
|
||||
DROPBITS(5);
|
||||
state->ncode = BITS(4) + 4;
|
||||
DROPBITS(4);
|
||||
#ifndef PKZIP_BUG_WORKAROUND
|
||||
if (state->nlen > 286 || state->ndist > 30) {
|
||||
strm->msg = (char *)"too many length or distance symbols";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
Tracev((stderr, "inflate: table sizes ok\n"));
|
||||
|
||||
/* get code length code lengths (not a typo) */
|
||||
state->have = 0;
|
||||
while (state->have < state->ncode) {
|
||||
NEEDBITS(3);
|
||||
state->lens[order[state->have++]] = (unsigned short)BITS(3);
|
||||
DROPBITS(3);
|
||||
}
|
||||
while (state->have < 19)
|
||||
state->lens[order[state->have++]] = 0;
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lenbits = 7;
|
||||
ret = inflate_table(CODES, state->lens, 19, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
if (ret) {
|
||||
strm->msg = (char *)"invalid code lengths set";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: code lengths ok\n"));
|
||||
|
||||
/* get length and distance code code lengths */
|
||||
state->have = 0;
|
||||
while (state->have < state->nlen + state->ndist) {
|
||||
for (;;) {
|
||||
here = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (here.val < 16) {
|
||||
DROPBITS(here.bits);
|
||||
state->lens[state->have++] = here.val;
|
||||
}
|
||||
else {
|
||||
if (here.val == 16) {
|
||||
NEEDBITS(here.bits + 2);
|
||||
DROPBITS(here.bits);
|
||||
if (state->have == 0) {
|
||||
strm->msg = (char *)"invalid bit length repeat";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
len = (unsigned)(state->lens[state->have - 1]);
|
||||
copy = 3 + BITS(2);
|
||||
DROPBITS(2);
|
||||
}
|
||||
else if (here.val == 17) {
|
||||
NEEDBITS(here.bits + 3);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
copy = 3 + BITS(3);
|
||||
DROPBITS(3);
|
||||
}
|
||||
else {
|
||||
NEEDBITS(here.bits + 7);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
copy = 11 + BITS(7);
|
||||
DROPBITS(7);
|
||||
}
|
||||
if (state->have + copy > state->nlen + state->ndist) {
|
||||
strm->msg = (char *)"invalid bit length repeat";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
while (copy--)
|
||||
state->lens[state->have++] = (unsigned short)len;
|
||||
}
|
||||
}
|
||||
|
||||
/* handle error breaks in while */
|
||||
if (state->mode == BAD) break;
|
||||
|
||||
/* check for end-of-block code (better have one) */
|
||||
if (state->lens[256] == 0) {
|
||||
strm->msg = (char *)"invalid code -- missing end-of-block";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
|
||||
/* build code tables -- note: do not change the lenbits or distbits
|
||||
values here (9 and 6) without reading the comments in inftrees.h
|
||||
concerning the ENOUGH constants, which depend on those values */
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lenbits = 9;
|
||||
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
if (ret) {
|
||||
strm->msg = (char *)"invalid literal/lengths set";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->distcode = (code const FAR *)(state->next);
|
||||
state->distbits = 6;
|
||||
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
|
||||
&(state->next), &(state->distbits), state->work);
|
||||
if (ret) {
|
||||
strm->msg = (char *)"invalid distances set";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: codes ok\n"));
|
||||
state->mode = LEN;
|
||||
|
||||
case LEN:
|
||||
/* use inflate_fast() if we have enough input and output */
|
||||
if (have >= 6 && left >= 258) {
|
||||
RESTORE();
|
||||
if (state->whave < state->wsize)
|
||||
state->whave = state->wsize - left;
|
||||
inflate_fast(strm, state->wsize);
|
||||
LOAD();
|
||||
break;
|
||||
}
|
||||
|
||||
/* get a literal, length, or end-of-block code */
|
||||
for (;;) {
|
||||
here = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (here.op && (here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
here = state->lencode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(here.bits);
|
||||
state->length = (unsigned)here.val;
|
||||
|
||||
/* process literal */
|
||||
if (here.op == 0) {
|
||||
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", here.val));
|
||||
ROOM();
|
||||
*put++ = (unsigned char)(state->length);
|
||||
left--;
|
||||
state->mode = LEN;
|
||||
break;
|
||||
}
|
||||
|
||||
/* process end of block */
|
||||
if (here.op & 32) {
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* invalid code */
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid literal/length code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
|
||||
/* length code -- get extra bits, if any */
|
||||
state->extra = (unsigned)(here.op) & 15;
|
||||
if (state->extra != 0) {
|
||||
NEEDBITS(state->extra);
|
||||
state->length += BITS(state->extra);
|
||||
DROPBITS(state->extra);
|
||||
}
|
||||
Tracevv((stderr, "inflate: length %u\n", state->length));
|
||||
|
||||
/* get distance code */
|
||||
for (;;) {
|
||||
here = state->distcode[BITS(state->distbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if ((here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
here = state->distcode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(here.bits);
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid distance code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->offset = (unsigned)here.val;
|
||||
|
||||
/* get distance extra bits, if any */
|
||||
state->extra = (unsigned)(here.op) & 15;
|
||||
if (state->extra != 0) {
|
||||
NEEDBITS(state->extra);
|
||||
state->offset += BITS(state->extra);
|
||||
DROPBITS(state->extra);
|
||||
}
|
||||
if (state->offset > state->wsize - (state->whave < state->wsize ?
|
||||
left : 0)) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
Tracevv((stderr, "inflate: distance %u\n", state->offset));
|
||||
|
||||
/* copy match from window to output */
|
||||
do {
|
||||
ROOM();
|
||||
copy = state->wsize - state->offset;
|
||||
if (copy < left) {
|
||||
from = put + copy;
|
||||
copy = left - copy;
|
||||
}
|
||||
else {
|
||||
from = put - state->offset;
|
||||
copy = left;
|
||||
}
|
||||
if (copy > state->length) copy = state->length;
|
||||
state->length -= copy;
|
||||
left -= copy;
|
||||
do {
|
||||
*put++ = *from++;
|
||||
} while (--copy);
|
||||
} while (state->length != 0);
|
||||
break;
|
||||
|
||||
case DONE:
|
||||
/* inflate stream terminated properly -- write leftover output */
|
||||
ret = Z_STREAM_END;
|
||||
if (left < state->wsize) {
|
||||
if (out(out_desc, state->window, state->wsize - left))
|
||||
ret = Z_BUF_ERROR;
|
||||
}
|
||||
goto inf_leave;
|
||||
|
||||
case BAD:
|
||||
ret = Z_DATA_ERROR;
|
||||
goto inf_leave;
|
||||
|
||||
default: /* can't happen, but makes compilers happy */
|
||||
ret = Z_STREAM_ERROR;
|
||||
goto inf_leave;
|
||||
}
|
||||
|
||||
/* Return unused input */
|
||||
inf_leave:
|
||||
strm->next_in = next;
|
||||
strm->avail_in = have;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateBackEnd(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
|
||||
return Z_STREAM_ERROR;
|
||||
ZFREE(strm, strm->state);
|
||||
strm->state = Z_NULL;
|
||||
Tracev((stderr, "inflate: end\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
340
contrib/fundamentals/ZLib/zlib127/zlib/inffast.c
Normal file
340
contrib/fundamentals/ZLib/zlib127/zlib/inffast.c
Normal file
@@ -0,0 +1,340 @@
|
||||
/* inffast.c -- fast decoding
|
||||
* Copyright (C) 1995-2008, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
#include "inffast.h"
|
||||
|
||||
#ifndef ASMINF
|
||||
|
||||
/* Allow machine dependent optimization for post-increment or pre-increment.
|
||||
Based on testing to date,
|
||||
Pre-increment preferred for:
|
||||
- PowerPC G3 (Adler)
|
||||
- MIPS R5000 (Randers-Pehrson)
|
||||
Post-increment preferred for:
|
||||
- none
|
||||
No measurable difference:
|
||||
- Pentium III (Anderson)
|
||||
- M68060 (Nikl)
|
||||
*/
|
||||
#ifdef POSTINC
|
||||
# define OFF 0
|
||||
# define PUP(a) *(a)++
|
||||
#else
|
||||
# define OFF 1
|
||||
# define PUP(a) *++(a)
|
||||
#endif
|
||||
|
||||
/*
|
||||
Decode literal, length, and distance codes and write out the resulting
|
||||
literal and match bytes until either not enough input or output is
|
||||
available, an end-of-block is encountered, or a data error is encountered.
|
||||
When large enough input and output buffers are supplied to inflate(), for
|
||||
example, a 16K input buffer and a 64K output buffer, more than 95% of the
|
||||
inflate execution time is spent in this routine.
|
||||
|
||||
Entry assumptions:
|
||||
|
||||
state->mode == LEN
|
||||
strm->avail_in >= 6
|
||||
strm->avail_out >= 258
|
||||
start >= strm->avail_out
|
||||
state->bits < 8
|
||||
|
||||
On return, state->mode is one of:
|
||||
|
||||
LEN -- ran out of enough output space or enough available input
|
||||
TYPE -- reached end of block code, inflate() to interpret next block
|
||||
BAD -- error in block data
|
||||
|
||||
Notes:
|
||||
|
||||
- The maximum input bits used by a length/distance pair is 15 bits for the
|
||||
length code, 5 bits for the length extra, 15 bits for the distance code,
|
||||
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
|
||||
Therefore if strm->avail_in >= 6, then there is enough input to avoid
|
||||
checking for available input while decoding.
|
||||
|
||||
- The maximum bytes that a single length/distance pair can output is 258
|
||||
bytes, which is the maximum length that can be coded. inflate_fast()
|
||||
requires strm->avail_out >= 258 for each loop to avoid checking for
|
||||
output space.
|
||||
*/
|
||||
void ZLIB_INTERNAL inflate_fast(strm, start)
|
||||
z_streamp strm;
|
||||
unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned char FAR *in; /* local strm->next_in */
|
||||
unsigned char FAR *last; /* while in < last, enough input available */
|
||||
unsigned char FAR *out; /* local strm->next_out */
|
||||
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
|
||||
unsigned char FAR *end; /* while out < end, enough space available */
|
||||
#ifdef INFLATE_STRICT
|
||||
unsigned dmax; /* maximum distance from zlib header */
|
||||
#endif
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned wnext; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
|
||||
unsigned long hold; /* local strm->hold */
|
||||
unsigned bits; /* local strm->bits */
|
||||
code const FAR *lcode; /* local strm->lencode */
|
||||
code const FAR *dcode; /* local strm->distcode */
|
||||
unsigned lmask; /* mask for first level of length codes */
|
||||
unsigned dmask; /* mask for first level of distance codes */
|
||||
code here; /* retrieved table entry */
|
||||
unsigned op; /* code bits, operation, extra bits, or */
|
||||
/* window position, window bytes to copy */
|
||||
unsigned len; /* match length, unused bytes */
|
||||
unsigned dist; /* match distance */
|
||||
unsigned char FAR *from; /* where to copy match from */
|
||||
|
||||
/* copy state to local variables */
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
in = strm->next_in - OFF;
|
||||
last = in + (strm->avail_in - 5);
|
||||
out = strm->next_out - OFF;
|
||||
beg = out - (start - strm->avail_out);
|
||||
end = out + (strm->avail_out - 257);
|
||||
#ifdef INFLATE_STRICT
|
||||
dmax = state->dmax;
|
||||
#endif
|
||||
wsize = state->wsize;
|
||||
whave = state->whave;
|
||||
wnext = state->wnext;
|
||||
window = state->window;
|
||||
hold = state->hold;
|
||||
bits = state->bits;
|
||||
lcode = state->lencode;
|
||||
dcode = state->distcode;
|
||||
lmask = (1U << state->lenbits) - 1;
|
||||
dmask = (1U << state->distbits) - 1;
|
||||
|
||||
/* decode literals and length/distances until end-of-block or not enough
|
||||
input data or output space */
|
||||
do {
|
||||
if (bits < 15) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
here = lcode[hold & lmask];
|
||||
dolen:
|
||||
op = (unsigned)(here.bits);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
op = (unsigned)(here.op);
|
||||
if (op == 0) { /* literal */
|
||||
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", here.val));
|
||||
PUP(out) = (unsigned char)(here.val);
|
||||
}
|
||||
else if (op & 16) { /* length base */
|
||||
len = (unsigned)(here.val);
|
||||
op &= 15; /* number of extra bits */
|
||||
if (op) {
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
len += (unsigned)hold & ((1U << op) - 1);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
}
|
||||
Tracevv((stderr, "inflate: length %u\n", len));
|
||||
if (bits < 15) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
here = dcode[hold & dmask];
|
||||
dodist:
|
||||
op = (unsigned)(here.bits);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
op = (unsigned)(here.op);
|
||||
if (op & 16) { /* distance base */
|
||||
dist = (unsigned)(here.val);
|
||||
op &= 15; /* number of extra bits */
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
}
|
||||
dist += (unsigned)hold & ((1U << op) - 1);
|
||||
#ifdef INFLATE_STRICT
|
||||
if (dist > dmax) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
Tracevv((stderr, "inflate: distance %u\n", dist));
|
||||
op = (unsigned)(out - beg); /* max distance in output */
|
||||
if (dist > op) { /* see if copy from window */
|
||||
op = dist - op; /* distance back in window */
|
||||
if (op > whave) {
|
||||
if (state->sane) {
|
||||
strm->msg =
|
||||
(char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
if (len <= op - whave) {
|
||||
do {
|
||||
PUP(out) = 0;
|
||||
} while (--len);
|
||||
continue;
|
||||
}
|
||||
len -= op - whave;
|
||||
do {
|
||||
PUP(out) = 0;
|
||||
} while (--op > whave);
|
||||
if (op == 0) {
|
||||
from = out - dist;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--len);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
from = window - OFF;
|
||||
if (wnext == 0) { /* very common case */
|
||||
from += wsize - op;
|
||||
if (op < len) { /* some from window */
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--op);
|
||||
from = out - dist; /* rest from output */
|
||||
}
|
||||
}
|
||||
else if (wnext < op) { /* wrap around window */
|
||||
from += wsize + wnext - op;
|
||||
op -= wnext;
|
||||
if (op < len) { /* some from end of window */
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--op);
|
||||
from = window - OFF;
|
||||
if (wnext < len) { /* some from start of window */
|
||||
op = wnext;
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--op);
|
||||
from = out - dist; /* rest from output */
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* contiguous in window */
|
||||
from += wnext - op;
|
||||
if (op < len) { /* some from window */
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--op);
|
||||
from = out - dist; /* rest from output */
|
||||
}
|
||||
}
|
||||
while (len > 2) {
|
||||
PUP(out) = PUP(from);
|
||||
PUP(out) = PUP(from);
|
||||
PUP(out) = PUP(from);
|
||||
len -= 3;
|
||||
}
|
||||
if (len) {
|
||||
PUP(out) = PUP(from);
|
||||
if (len > 1)
|
||||
PUP(out) = PUP(from);
|
||||
}
|
||||
}
|
||||
else {
|
||||
from = out - dist; /* copy direct from output */
|
||||
do { /* minimum length is three */
|
||||
PUP(out) = PUP(from);
|
||||
PUP(out) = PUP(from);
|
||||
PUP(out) = PUP(from);
|
||||
len -= 3;
|
||||
} while (len > 2);
|
||||
if (len) {
|
||||
PUP(out) = PUP(from);
|
||||
if (len > 1)
|
||||
PUP(out) = PUP(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((op & 64) == 0) { /* 2nd level distance code */
|
||||
here = dcode[here.val + (hold & ((1U << op) - 1))];
|
||||
goto dodist;
|
||||
}
|
||||
else {
|
||||
strm->msg = (char *)"invalid distance code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ((op & 64) == 0) { /* 2nd level length code */
|
||||
here = lcode[here.val + (hold & ((1U << op) - 1))];
|
||||
goto dolen;
|
||||
}
|
||||
else if (op & 32) { /* end-of-block */
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
strm->msg = (char *)"invalid literal/length code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
} while (in < last && out < end);
|
||||
|
||||
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
|
||||
len = bits >> 3;
|
||||
in -= len;
|
||||
bits -= len << 3;
|
||||
hold &= (1U << bits) - 1;
|
||||
|
||||
/* update state and return */
|
||||
strm->next_in = in + OFF;
|
||||
strm->next_out = out + OFF;
|
||||
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
|
||||
strm->avail_out = (unsigned)(out < end ?
|
||||
257 + (end - out) : 257 - (out - end));
|
||||
state->hold = hold;
|
||||
state->bits = bits;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
|
||||
- Using bit fields for code structure
|
||||
- Different op definition to avoid & for extra bits (do & for table bits)
|
||||
- Three separate decoding do-loops for direct, window, and wnext == 0
|
||||
- Special case for distance > 1 copies to do overlapped load and store copy
|
||||
- Explicit branch predictions (based on measured branch probabilities)
|
||||
- Deferring match copy and interspersed it with decoding subsequent codes
|
||||
- Swapping literal/length else
|
||||
- Swapping window/direct else
|
||||
- Larger unrolled copy loops (three is about right)
|
||||
- Moving len -= 3 statement into middle of loop
|
||||
*/
|
||||
|
||||
#endif /* !ASMINF */
|
||||
11
contrib/fundamentals/ZLib/zlib127/zlib/inffast.h
Normal file
11
contrib/fundamentals/ZLib/zlib127/zlib/inffast.h
Normal file
@@ -0,0 +1,11 @@
|
||||
/* inffast.h -- header to use inffast.c
|
||||
* Copyright (C) 1995-2003, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
|
||||
94
contrib/fundamentals/ZLib/zlib127/zlib/inffixed.h
Normal file
94
contrib/fundamentals/ZLib/zlib127/zlib/inffixed.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/* inffixed.h -- table for decoding fixed codes
|
||||
* Generated automatically by makefixed().
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications.
|
||||
It is part of the implementation of this library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
static const code lenfix[512] = {
|
||||
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
|
||||
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
|
||||
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
|
||||
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
|
||||
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
|
||||
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
|
||||
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
|
||||
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
|
||||
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
|
||||
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
|
||||
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
|
||||
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
|
||||
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
|
||||
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
|
||||
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
|
||||
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
|
||||
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
|
||||
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
|
||||
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
|
||||
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
|
||||
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
|
||||
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
|
||||
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
|
||||
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
|
||||
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
|
||||
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
|
||||
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
|
||||
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
|
||||
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
|
||||
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
|
||||
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
|
||||
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
|
||||
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
|
||||
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
|
||||
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
|
||||
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
|
||||
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
|
||||
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
|
||||
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
|
||||
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
|
||||
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
|
||||
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
|
||||
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
|
||||
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
|
||||
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
|
||||
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
|
||||
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
|
||||
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
|
||||
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
|
||||
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
|
||||
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
|
||||
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
|
||||
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
|
||||
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
|
||||
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
|
||||
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
|
||||
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
|
||||
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
|
||||
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
|
||||
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
|
||||
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
|
||||
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
|
||||
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
|
||||
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
|
||||
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
|
||||
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
|
||||
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
|
||||
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
|
||||
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
|
||||
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
|
||||
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
|
||||
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
|
||||
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
|
||||
{0,9,255}
|
||||
};
|
||||
|
||||
static const code distfix[32] = {
|
||||
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
|
||||
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
|
||||
{18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
|
||||
{19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
|
||||
{16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
|
||||
{22,5,193},{64,5,0}
|
||||
};
|
||||
1496
contrib/fundamentals/ZLib/zlib127/zlib/inflate.c
Normal file
1496
contrib/fundamentals/ZLib/zlib127/zlib/inflate.c
Normal file
File diff suppressed because it is too large
Load Diff
122
contrib/fundamentals/ZLib/zlib127/zlib/inflate.h
Normal file
122
contrib/fundamentals/ZLib/zlib127/zlib/inflate.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/* inflate.h -- internal inflate state definition
|
||||
* Copyright (C) 1995-2009 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* define NO_GZIP when compiling if you want to disable gzip header and
|
||||
trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
|
||||
the crc code when it is not needed. For shared libraries, gzip decoding
|
||||
should be left enabled. */
|
||||
#ifndef NO_GZIP
|
||||
# define GUNZIP
|
||||
#endif
|
||||
|
||||
/* Possible inflate modes between inflate() calls */
|
||||
typedef enum {
|
||||
HEAD, /* i: waiting for magic header */
|
||||
FLAGS, /* i: waiting for method and flags (gzip) */
|
||||
TIME, /* i: waiting for modification time (gzip) */
|
||||
OS, /* i: waiting for extra flags and operating system (gzip) */
|
||||
EXLEN, /* i: waiting for extra length (gzip) */
|
||||
EXTRA, /* i: waiting for extra bytes (gzip) */
|
||||
NAME, /* i: waiting for end of file name (gzip) */
|
||||
COMMENT, /* i: waiting for end of comment (gzip) */
|
||||
HCRC, /* i: waiting for header crc (gzip) */
|
||||
DICTID, /* i: waiting for dictionary check value */
|
||||
DICT, /* waiting for inflateSetDictionary() call */
|
||||
TYPE, /* i: waiting for type bits, including last-flag bit */
|
||||
TYPEDO, /* i: same, but skip check to exit inflate on new block */
|
||||
STORED, /* i: waiting for stored size (length and complement) */
|
||||
COPY_, /* i/o: same as COPY below, but only first time in */
|
||||
COPY, /* i/o: waiting for input or output to copy stored block */
|
||||
TABLE, /* i: waiting for dynamic block table lengths */
|
||||
LENLENS, /* i: waiting for code length code lengths */
|
||||
CODELENS, /* i: waiting for length/lit and distance code lengths */
|
||||
LEN_, /* i: same as LEN below, but only first time in */
|
||||
LEN, /* i: waiting for length/lit/eob code */
|
||||
LENEXT, /* i: waiting for length extra bits */
|
||||
DIST, /* i: waiting for distance code */
|
||||
DISTEXT, /* i: waiting for distance extra bits */
|
||||
MATCH, /* o: waiting for output space to copy string */
|
||||
LIT, /* o: waiting for output space to write literal */
|
||||
CHECK, /* i: waiting for 32-bit check value */
|
||||
LENGTH, /* i: waiting for 32-bit length (gzip) */
|
||||
DONE, /* finished check, done -- remain here until reset */
|
||||
BAD, /* got a data error -- remain here until reset */
|
||||
MEM, /* got an inflate() memory error -- remain here until reset */
|
||||
SYNC /* looking for synchronization bytes to restart inflate() */
|
||||
} inflate_mode;
|
||||
|
||||
/*
|
||||
State transitions between above modes -
|
||||
|
||||
(most modes can go to BAD or MEM on error -- not shown for clarity)
|
||||
|
||||
Process header:
|
||||
HEAD -> (gzip) or (zlib) or (raw)
|
||||
(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->
|
||||
HCRC -> TYPE
|
||||
(zlib) -> DICTID or TYPE
|
||||
DICTID -> DICT -> TYPE
|
||||
(raw) -> TYPEDO
|
||||
Read deflate blocks:
|
||||
TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK
|
||||
STORED -> COPY_ -> COPY -> TYPE
|
||||
TABLE -> LENLENS -> CODELENS -> LEN_
|
||||
LEN_ -> LEN
|
||||
Read deflate codes in fixed or dynamic block:
|
||||
LEN -> LENEXT or LIT or TYPE
|
||||
LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
|
||||
LIT -> LEN
|
||||
Process trailer:
|
||||
CHECK -> LENGTH -> DONE
|
||||
*/
|
||||
|
||||
/* state maintained between inflate() calls. Approximately 10K bytes. */
|
||||
struct inflate_state {
|
||||
inflate_mode mode; /* current inflate mode */
|
||||
int last; /* true if processing last block */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||
int havedict; /* true if dictionary provided */
|
||||
int flags; /* gzip header method and flags (0 if zlib) */
|
||||
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
|
||||
unsigned long check; /* protected copy of check value */
|
||||
unsigned long total; /* protected copy of output count */
|
||||
gz_headerp head; /* where to save gzip header information */
|
||||
/* sliding window */
|
||||
unsigned wbits; /* log base 2 of requested window size */
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned wnext; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if needed */
|
||||
/* bit accumulator */
|
||||
unsigned long hold; /* input bit accumulator */
|
||||
unsigned bits; /* number of bits in "in" */
|
||||
/* for string and stored block copying */
|
||||
unsigned length; /* literal or length of data to copy */
|
||||
unsigned offset; /* distance back to copy string from */
|
||||
/* for table and code decoding */
|
||||
unsigned extra; /* extra bits needed */
|
||||
/* fixed and dynamic code tables */
|
||||
code const FAR *lencode; /* starting table for length/literal codes */
|
||||
code const FAR *distcode; /* starting table for distance codes */
|
||||
unsigned lenbits; /* index bits for lencode */
|
||||
unsigned distbits; /* index bits for distcode */
|
||||
/* dynamic table building */
|
||||
unsigned ncode; /* number of code length code lengths */
|
||||
unsigned nlen; /* number of length code lengths */
|
||||
unsigned ndist; /* number of distance code lengths */
|
||||
unsigned have; /* number of code lengths in lens[] */
|
||||
code FAR *next; /* next available space in codes[] */
|
||||
unsigned short lens[320]; /* temporary storage for code lengths */
|
||||
unsigned short work[288]; /* work area for code table building */
|
||||
code codes[ENOUGH]; /* space for code tables */
|
||||
int sane; /* if false, allow invalid distance too far */
|
||||
int back; /* bits back of last unprocessed length/lit */
|
||||
unsigned was; /* initial length of match */
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user