3 { types and macros common to blocks and codes
4 Copyright (C) 1995-1998 Mark Adler
6 WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
11 Copyright (C) 1998 by Jacques Nomssi Nzali
12 For conditions of distribution and use, see copyright notice in readme.txt
22 { copy as much as possible from the sliding window to the output area }
23 function inflate_flush(var s
: inflate_blocks_state
;
27 { And'ing with mask[n] masks the lower n bits }
29 inflate_mask
: array[0..17-1] of uInt
= (
31 $0001, $0003, $0007, $000f, $001f, $003f, $007f, $00ff,
32 $01ff, $03ff, $07ff, $0fff, $1fff, $3fff, $7fff, $ffff);
34 {procedure GRABBITS(j : int);}
35 {procedure DUMPBITS(j : int);}
36 {procedure NEEDBITS(j : int);}
40 { macros for bit input with no checking and for returning unused bytes }
41 procedure GRABBITS(j
: int
);
47 b := b or (uLong(z^.next_in^) shl k);
53 procedure DUMPBITS(j
: int
);
59 procedure NEEDBITS(j
: int
);
73 Inc(z.total_in, LongInt(p)-LongInt(z.next_in));
76 result := inflate_flush(s,z,r);
80 b := b or (uLong(p^) shl k);
93 if (q = s.zend) and (s.read <> s.window) then
96 if LongInt(q) < LongInt(s.read) then
97 m := uInt(LongInt(s.read)-LongInt(q)-1)
99 m := uInt(LongInt(s.zend)-LongInt(q));
106 r := inflate_flush(s,z,r);
108 if LongInt(q) < LongInt(s.read) then
109 m := uInt(LongInt(s.read)-LongInt(q)-1)
111 m := uInt(LongInt(s.zend)-LongInt(q));
114 if (q = s.zend) and (s.read <> s.window) then
117 if LongInt(q) < LongInt(s.read) then
118 m := uInt(LongInt(s.read)-LongInt(q)-1)
120 m := uInt(LongInt(s.zend)-LongInt(q));
129 Inc(z.total_in, LongInt(p)-LongInt(z.next_in));
132 result := inflate_flush(s,z,r);
141 { copy as much as possible from the sliding window to the output area }
142 function inflate_flush(var s
: inflate_blocks_state
;
150 { local copies of source and destination pointers }
154 { compute number of bytes to copy as far as end of window }
155 if ptr2int(q
) <= ptr2int(s
.write
) then
156 n
:= uInt(ptr2int(s
.write
) - ptr2int(q
))
158 n
:= uInt(ptr2int(s
.zend
) - ptr2int(q
));
159 if (n
> z
.avail_out
) then
161 if (n
<> 0) and (r
= Z_BUF_ERROR
) then
169 { update check information }
170 if Assigned(s
.checkfn
) then
172 s
.check
:= s
.checkfn(s
.check
, q
, n
);
176 { copy as far as end of window }
181 { see if more to copy at beginning of window }
186 if (s
.write
= s
.zend
) then
189 { compute bytes to copy }
190 n
:= uInt(ptr2int(s
.write
) - ptr2int(q
));
191 if (n
> z
.avail_out
) then
193 if (n
<> 0) and (r
= Z_BUF_ERROR
) then
197 Dec( z
.avail_out
, n
);
198 Inc( z
.total_out
, n
);
200 { update check information }
201 if Assigned(s
.checkfn
) then
203 s
.check
:= s
.checkfn(s
.check
, q
, n
);