summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--contrib/README.contrib10
-rw-r--r--contrib/asm586/README.58643
-rw-r--r--contrib/asm586/match.S354
-rw-r--r--contrib/asm686/README.68634
-rw-r--r--contrib/asm686/match.S327
-rw-r--r--contrib/delphi/zlib.mak36
-rw-r--r--contrib/delphi/zlibdef.pas169
-rw-r--r--contrib/delphi2/d_zlib.bpr224
-rw-r--r--contrib/delphi2/d_zlib.cpp17
-rw-r--r--contrib/delphi2/readme.txt17
-rw-r--r--contrib/delphi2/zlib.bpg26
-rw-r--r--contrib/delphi2/zlib.bpr225
-rw-r--r--contrib/delphi2/zlib.cpp22
-rw-r--r--contrib/delphi2/zlib.pas534
-rw-r--r--contrib/delphi2/zlib32.bpr174
-rw-r--r--contrib/delphi2/zlib32.cpp42
-rw-r--r--contrib/minizip/unzip.c2
-rw-r--r--contrib/minizip/zip.c90
-rw-r--r--contrib/untgz/untgz.c64
-rw-r--r--contrib/visual-basic.txt14
20 files changed, 2368 insertions, 56 deletions
diff --git a/contrib/README.contrib b/contrib/README.contrib
index dfe9031..7ad191c 100644
--- a/contrib/README.contrib
+++ b/contrib/README.contrib
@@ -7,6 +7,16 @@ for help about these, not the zlib authors. Thanks.
7asm386/ by Gilles Vollant <info@winimage.com> 7asm386/ by Gilles Vollant <info@winimage.com>
8 386 asm code replacing longest_match(), for Visual C++ 4.2 and ML 6.11c 8 386 asm code replacing longest_match(), for Visual C++ 4.2 and ML 6.11c
9 9
10asm586/ and asm686/ by Brian Raiter <breadbox@muppetlabs.com>
11 asm code for Pentium and Pentium Pro
12 See http://www.muppetlabs.com/~breadbox/software/assembly.html
13
14delphi/ by Bob Dellaca <bobdl@xtra.co.nz>
15 Support for Delphi
16
17delphi2/ by Davide Moretti <dave@rimini.com>
18 Another support for C++Builder and Delphi
19
10minizip/ by Gilles Vollant <info@winimage.com> 20minizip/ by Gilles Vollant <info@winimage.com>
11 Mini zip and unzip based on zlib 21 Mini zip and unzip based on zlib
12 See http://www.winimage.com/zLibDll/unzip.html 22 See http://www.winimage.com/zLibDll/unzip.html
diff --git a/contrib/asm586/README.586 b/contrib/asm586/README.586
new file mode 100644
index 0000000..6bb78f3
--- /dev/null
+++ b/contrib/asm586/README.586
@@ -0,0 +1,43 @@
1This is a patched version of zlib modified to use
2Pentium-optimized assembly code in the deflation algorithm. The files
3changed/added by this patch are:
4
5README.586
6match.S
7
8The effectiveness of these modifications is a bit marginal, as the the
9program's bottleneck seems to be mostly L1-cache contention, for which
10there is no real way to work around without rewriting the basic
11algorithm. The speedup on average is around 5-10% (which is generally
12less than the amount of variance between subsequent executions).
13However, when used at level 9 compression, the cache contention can
14drop enough for the assembly version to achieve 10-20% speedup (and
15sometimes more, depending on the amount of overall redundancy in the
16files). Even here, though, cache contention can still be the limiting
17factor, depending on the nature of the program using the zlib library.
18This may also mean that better improvements will be seen on a Pentium
19with MMX, which suffers much less from L1-cache contention, but I have
20not yet verified this.
21
22Note that this code has been tailored for the Pentium in particular,
23and will not perform well on the Pentium Pro (due to the use of a
24partial register in the inner loop).
25
26If you are using an assembler other than GNU as, you will have to
27translate match.S to use your assembler's syntax. (Have fun.)
28
29Brian Raiter
30breadbox@muppetlabs.com
31April, 1998
32
33
34Added for zlib 1.1.3:
35
36The patches come from
37http://www.muppetlabs.com/~breadbox/software/assembly.html
38
39To compile zlib with this asm file, copy match.S to the zlib directory
40then do:
41
42CFLAGS="-O3 -DASMV" ./configure
43make OBJA=match.o
diff --git a/contrib/asm586/match.S b/contrib/asm586/match.S
new file mode 100644
index 0000000..8f16140
--- /dev/null
+++ b/contrib/asm586/match.S
@@ -0,0 +1,354 @@
1/* match.s -- Pentium-optimized version of longest_match()
2 * Written for zlib 1.1.2
3 * Copyright (C) 1998 Brian Raiter <breadbox@muppetlabs.com>
4 *
5 * This is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License.
7 */
8
9#ifndef NO_UNDERLINE
10#define match_init _match_init
11#define longest_match _longest_match
12#endif
13
14#define MAX_MATCH (258)
15#define MIN_MATCH (3)
16#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1)
17#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7)
18
19/* stack frame offsets */
20
21#define wmask 0 /* local copy of s->wmask */
22#define window 4 /* local copy of s->window */
23#define windowbestlen 8 /* s->window + bestlen */
24#define chainlenscanend 12 /* high word: current chain len */
25 /* low word: last bytes sought */
26#define scanstart 16 /* first two bytes of string */
27#define scanalign 20 /* dword-misalignment of string */
28#define nicematch 24 /* a good enough match size */
29#define bestlen 28 /* size of best match so far */
30#define scan 32 /* ptr to string wanting match */
31
32#define LocalVarsSize (36)
33/* saved ebx 36 */
34/* saved edi 40 */
35/* saved esi 44 */
36/* saved ebp 48 */
37/* return address 52 */
38#define deflatestate 56 /* the function arguments */
39#define curmatch 60
40
41/* Offsets for fields in the deflate_state structure. These numbers
42 * are calculated from the definition of deflate_state, with the
43 * assumption that the compiler will dword-align the fields. (Thus,
44 * changing the definition of deflate_state could easily cause this
45 * program to crash horribly, without so much as a warning at
46 * compile time. Sigh.)
47 */
48#define dsWSize 36
49#define dsWMask 44
50#define dsWindow 48
51#define dsPrev 56
52#define dsMatchLen 88
53#define dsPrevMatch 92
54#define dsStrStart 100
55#define dsMatchStart 104
56#define dsLookahead 108
57#define dsPrevLen 112
58#define dsMaxChainLen 116
59#define dsGoodMatch 132
60#define dsNiceMatch 136
61
62
63.file "match.S"
64
65.globl match_init, longest_match
66
67.text
68
69/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */
70
71longest_match:
72
73/* Save registers that the compiler may be using, and adjust %esp to */
74/* make room for our stack frame. */
75
76 pushl %ebp
77 pushl %edi
78 pushl %esi
79 pushl %ebx
80 subl $LocalVarsSize, %esp
81
82/* Retrieve the function arguments. %ecx will hold cur_match */
83/* throughout the entire function. %edx will hold the pointer to the */
84/* deflate_state structure during the function's setup (before */
85/* entering the main loop). */
86
87 movl deflatestate(%esp), %edx
88 movl curmatch(%esp), %ecx
89
90/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */
91
92 movl dsNiceMatch(%edx), %eax
93 movl dsLookahead(%edx), %ebx
94 cmpl %eax, %ebx
95 jl LookaheadLess
96 movl %eax, %ebx
97LookaheadLess: movl %ebx, nicematch(%esp)
98
99/* register Bytef *scan = s->window + s->strstart; */
100
101 movl dsWindow(%edx), %esi
102 movl %esi, window(%esp)
103 movl dsStrStart(%edx), %ebp
104 lea (%esi,%ebp), %edi
105 movl %edi, scan(%esp)
106
107/* Determine how many bytes the scan ptr is off from being */
108/* dword-aligned. */
109
110 movl %edi, %eax
111 negl %eax
112 andl $3, %eax
113 movl %eax, scanalign(%esp)
114
115/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */
116/* s->strstart - (IPos)MAX_DIST(s) : NIL; */
117
118 movl dsWSize(%edx), %eax
119 subl $MIN_LOOKAHEAD, %eax
120 subl %eax, %ebp
121 jg LimitPositive
122 xorl %ebp, %ebp
123LimitPositive:
124
125/* unsigned chain_length = s->max_chain_length; */
126/* if (s->prev_length >= s->good_match) { */
127/* chain_length >>= 2; */
128/* } */
129
130 movl dsPrevLen(%edx), %eax
131 movl dsGoodMatch(%edx), %ebx
132 cmpl %ebx, %eax
133 movl dsMaxChainLen(%edx), %ebx
134 jl LastMatchGood
135 shrl $2, %ebx
136LastMatchGood:
137
138/* chainlen is decremented once beforehand so that the function can */
139/* use the sign flag instead of the zero flag for the exit test. */
140/* It is then shifted into the high word, to make room for the scanend */
141/* scanend value, which it will always accompany. */
142
143 decl %ebx
144 shll $16, %ebx
145
146/* int best_len = s->prev_length; */
147
148 movl dsPrevLen(%edx), %eax
149 movl %eax, bestlen(%esp)
150
151/* Store the sum of s->window + best_len in %esi locally, and in %esi. */
152
153 addl %eax, %esi
154 movl %esi, windowbestlen(%esp)
155
156/* register ush scan_start = *(ushf*)scan; */
157/* register ush scan_end = *(ushf*)(scan+best_len-1); */
158
159 movw (%edi), %bx
160 movw %bx, scanstart(%esp)
161 movw -1(%edi,%eax), %bx
162 movl %ebx, chainlenscanend(%esp)
163
164/* Posf *prev = s->prev; */
165/* uInt wmask = s->w_mask; */
166
167 movl dsPrev(%edx), %edi
168 movl dsWMask(%edx), %edx
169 mov %edx, wmask(%esp)
170
171/* Jump into the main loop. */
172
173 jmp LoopEntry
174
175.balign 16
176
177/* do {
178 * match = s->window + cur_match;
179 * if (*(ushf*)(match+best_len-1) != scan_end ||
180 * *(ushf*)match != scan_start) continue;
181 * [...]
182 * } while ((cur_match = prev[cur_match & wmask]) > limit
183 * && --chain_length != 0);
184 *
185 * Here is the inner loop of the function. The function will spend the
186 * majority of its time in this loop, and majority of that time will
187 * be spent in the first ten instructions.
188 *
189 * Within this loop:
190 * %ebx = chainlenscanend - i.e., ((chainlen << 16) | scanend)
191 * %ecx = curmatch
192 * %edx = curmatch & wmask
193 * %esi = windowbestlen - i.e., (window + bestlen)
194 * %edi = prev
195 * %ebp = limit
196 *
197 * Two optimization notes on the choice of instructions:
198 *
199 * The first instruction uses a 16-bit address, which costs an extra,
200 * unpairable cycle. This is cheaper than doing a 32-bit access and
201 * zeroing the high word, due to the 3-cycle misalignment penalty which
202 * would occur half the time. This also turns out to be cheaper than
203 * doing two separate 8-bit accesses, as the memory is so rarely in the
204 * L1 cache.
205 *
206 * The window buffer, however, apparently spends a lot of time in the
207 * cache, and so it is faster to retrieve the word at the end of the
208 * match string with two 8-bit loads. The instructions that test the
209 * word at the beginning of the match string, however, are executed
210 * much less frequently, and there it was cheaper to use 16-bit
211 * instructions, which avoided the necessity of saving off and
212 * subsequently reloading one of the other registers.
213 */
214LookupLoop:
215 /* 1 U & V */
216 movw (%edi,%edx,2), %cx /* 2 U pipe */
217 movl wmask(%esp), %edx /* 2 V pipe */
218 cmpl %ebp, %ecx /* 3 U pipe */
219 jbe LeaveNow /* 3 V pipe */
220 subl $0x00010000, %ebx /* 4 U pipe */
221 js LeaveNow /* 4 V pipe */
222LoopEntry: movb -1(%esi,%ecx), %al /* 5 U pipe */
223 andl %ecx, %edx /* 5 V pipe */
224 cmpb %bl, %al /* 6 U pipe */
225 jnz LookupLoop /* 6 V pipe */
226 movb (%esi,%ecx), %ah
227 cmpb %bh, %ah
228 jnz LookupLoop
229 movl window(%esp), %eax
230 movw (%eax,%ecx), %ax
231 cmpw scanstart(%esp), %ax
232 jnz LookupLoop
233
234/* Store the current value of chainlen. */
235
236 movl %ebx, chainlenscanend(%esp)
237
238/* Point %edi to the string under scrutiny, and %esi to the string we */
239/* are hoping to match it up with. In actuality, %esi and %edi are */
240/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */
241/* initialized to -(MAX_MATCH_8 - scanalign). */
242
243 movl window(%esp), %esi
244 movl scan(%esp), %edi
245 addl %ecx, %esi
246 movl scanalign(%esp), %eax
247 movl $(-MAX_MATCH_8), %edx
248 lea MAX_MATCH_8(%edi,%eax), %edi
249 lea MAX_MATCH_8(%esi,%eax), %esi
250
251/* Test the strings for equality, 8 bytes at a time. At the end,
252 * adjust %edx so that it is offset to the exact byte that mismatched.
253 *
254 * We already know at this point that the first three bytes of the
255 * strings match each other, and they can be safely passed over before
256 * starting the compare loop. So what this code does is skip over 0-3
257 * bytes, as much as necessary in order to dword-align the %edi
258 * pointer. (%esi will still be misaligned three times out of four.)
259 *
260 * It should be confessed that this loop usually does not represent
261 * much of the total running time. Replacing it with a more
262 * straightforward "rep cmpsb" would not drastically degrade
263 * performance.
264 */
265LoopCmps:
266 movl (%esi,%edx), %eax
267 movl (%edi,%edx), %ebx
268 xorl %ebx, %eax
269 jnz LeaveLoopCmps
270 movl 4(%esi,%edx), %eax
271 movl 4(%edi,%edx), %ebx
272 xorl %ebx, %eax
273 jnz LeaveLoopCmps4
274 addl $8, %edx
275 jnz LoopCmps
276 jmp LenMaximum
277LeaveLoopCmps4: addl $4, %edx
278LeaveLoopCmps: testl $0x0000FFFF, %eax
279 jnz LenLower
280 addl $2, %edx
281 shrl $16, %eax
282LenLower: subb $1, %al
283 adcl $0, %edx
284
285/* Calculate the length of the match. If it is longer than MAX_MATCH, */
286/* then automatically accept it as the best possible match and leave. */
287
288 lea (%edi,%edx), %eax
289 movl scan(%esp), %edi
290 subl %edi, %eax
291 cmpl $MAX_MATCH, %eax
292 jge LenMaximum
293
294/* If the length of the match is not longer than the best match we */
295/* have so far, then forget it and return to the lookup loop. */
296
297 movl deflatestate(%esp), %edx
298 movl bestlen(%esp), %ebx
299 cmpl %ebx, %eax
300 jg LongerMatch
301 movl chainlenscanend(%esp), %ebx
302 movl windowbestlen(%esp), %esi
303 movl dsPrev(%edx), %edi
304 movl wmask(%esp), %edx
305 andl %ecx, %edx
306 jmp LookupLoop
307
308/* s->match_start = cur_match; */
309/* best_len = len; */
310/* if (len >= nice_match) break; */
311/* scan_end = *(ushf*)(scan+best_len-1); */
312
313LongerMatch: movl nicematch(%esp), %ebx
314 movl %eax, bestlen(%esp)
315 movl %ecx, dsMatchStart(%edx)
316 cmpl %ebx, %eax
317 jge LeaveNow
318 movl window(%esp), %esi
319 addl %eax, %esi
320 movl %esi, windowbestlen(%esp)
321 movl chainlenscanend(%esp), %ebx
322 movw -1(%edi,%eax), %bx
323 movl dsPrev(%edx), %edi
324 movl %ebx, chainlenscanend(%esp)
325 movl wmask(%esp), %edx
326 andl %ecx, %edx
327 jmp LookupLoop
328
329/* Accept the current string, with the maximum possible length. */
330
331LenMaximum: movl deflatestate(%esp), %edx
332 movl $MAX_MATCH, bestlen(%esp)
333 movl %ecx, dsMatchStart(%edx)
334
335/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */
336/* return s->lookahead; */
337
338LeaveNow:
339 movl deflatestate(%esp), %edx
340 movl bestlen(%esp), %ebx
341 movl dsLookahead(%edx), %eax
342 cmpl %eax, %ebx
343 jg LookaheadRet
344 movl %ebx, %eax
345LookaheadRet:
346
347/* Restore the stack and return from whence we came. */
348
349 addl $LocalVarsSize, %esp
350 popl %ebx
351 popl %esi
352 popl %edi
353 popl %ebp
354match_init: ret
diff --git a/contrib/asm686/README.686 b/contrib/asm686/README.686
new file mode 100644
index 0000000..a593f23
--- /dev/null
+++ b/contrib/asm686/README.686
@@ -0,0 +1,34 @@
1This is a patched version of zlib, modified to use
2Pentium-Pro-optimized assembly code in the deflation algorithm. The
3files changed/added by this patch are:
4
5README.686
6match.S
7
8The speedup that this patch provides varies, depending on whether the
9compiler used to build the original version of zlib falls afoul of the
10PPro's speed traps. My own tests show a speedup of around 10-20% at
11the default compression level, and 20-30% using -9, against a version
12compiled using gcc 2.7.2.3. Your mileage may vary.
13
14Note that this code has been tailored for the PPro/PII in particular,
15and will not perform particuarly well on a Pentium.
16
17If you are using an assembler other than GNU as, you will have to
18translate match.S to use your assembler's syntax. (Have fun.)
19
20Brian Raiter
21breadbox@muppetlabs.com
22April, 1998
23
24
25Added for zlib 1.1.3:
26
27The patches come from
28http://www.muppetlabs.com/~breadbox/software/assembly.html
29
30To compile zlib with this asm file, copy match.S to the zlib directory
31then do:
32
33CFLAGS="-O3 -DASMV" ./configure
34make OBJA=match.o
diff --git a/contrib/asm686/match.S b/contrib/asm686/match.S
new file mode 100644
index 0000000..8e86c33
--- /dev/null
+++ b/contrib/asm686/match.S
@@ -0,0 +1,327 @@
1/* match.s -- Pentium-Pro-optimized version of longest_match()
2 * Written for zlib 1.1.2
3 * Copyright (C) 1998 Brian Raiter <breadbox@muppetlabs.com>
4 *
5 * This is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License.
7 */
8
9#ifndef NO_UNDERLINE
10#define match_init _match_init
11#define longest_match _longest_match
12#endif
13
14#define MAX_MATCH (258)
15#define MIN_MATCH (3)
16#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1)
17#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7)
18
19/* stack frame offsets */
20
21#define chainlenwmask 0 /* high word: current chain len */
22 /* low word: s->wmask */
23#define window 4 /* local copy of s->window */
24#define windowbestlen 8 /* s->window + bestlen */
25#define scanstart 16 /* first two bytes of string */
26#define scanend 12 /* last two bytes of string */
27#define scanalign 20 /* dword-misalignment of string */
28#define nicematch 24 /* a good enough match size */
29#define bestlen 28 /* size of best match so far */
30#define scan 32 /* ptr to string wanting match */
31
32#define LocalVarsSize (36)
33/* saved ebx 36 */
34/* saved edi 40 */
35/* saved esi 44 */
36/* saved ebp 48 */
37/* return address 52 */
38#define deflatestate 56 /* the function arguments */
39#define curmatch 60
40
41/* Offsets for fields in the deflate_state structure. These numbers
42 * are calculated from the definition of deflate_state, with the
43 * assumption that the compiler will dword-align the fields. (Thus,
44 * changing the definition of deflate_state could easily cause this
45 * program to crash horribly, without so much as a warning at
46 * compile time. Sigh.)
47 */
48#define dsWSize 36
49#define dsWMask 44
50#define dsWindow 48
51#define dsPrev 56
52#define dsMatchLen 88
53#define dsPrevMatch 92
54#define dsStrStart 100
55#define dsMatchStart 104
56#define dsLookahead 108
57#define dsPrevLen 112
58#define dsMaxChainLen 116
59#define dsGoodMatch 132
60#define dsNiceMatch 136
61
62
63.file "match.S"
64
65.globl match_init, longest_match
66
67.text
68
69/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */
70
71longest_match:
72
73/* Save registers that the compiler may be using, and adjust %esp to */
74/* make room for our stack frame. */
75
76 pushl %ebp
77 pushl %edi
78 pushl %esi
79 pushl %ebx
80 subl $LocalVarsSize, %esp
81
82/* Retrieve the function arguments. %ecx will hold cur_match */
83/* throughout the entire function. %edx will hold the pointer to the */
84/* deflate_state structure during the function's setup (before */
85/* entering the main loop). */
86
87 movl deflatestate(%esp), %edx
88 movl curmatch(%esp), %ecx
89
90/* uInt wmask = s->w_mask; */
91/* unsigned chain_length = s->max_chain_length; */
92/* if (s->prev_length >= s->good_match) { */
93/* chain_length >>= 2; */
94/* } */
95
96 movl dsPrevLen(%edx), %eax
97 movl dsGoodMatch(%edx), %ebx
98 cmpl %ebx, %eax
99 movl dsWMask(%edx), %eax
100 movl dsMaxChainLen(%edx), %ebx
101 jl LastMatchGood
102 shrl $2, %ebx
103LastMatchGood:
104
105/* chainlen is decremented once beforehand so that the function can */
106/* use the sign flag instead of the zero flag for the exit test. */
107/* It is then shifted into the high word, to make room for the wmask */
108/* value, which it will always accompany. */
109
110 decl %ebx
111 shll $16, %ebx
112 orl %eax, %ebx
113 movl %ebx, chainlenwmask(%esp)
114
115/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */
116
117 movl dsNiceMatch(%edx), %eax
118 movl dsLookahead(%edx), %ebx
119 cmpl %eax, %ebx
120 jl LookaheadLess
121 movl %eax, %ebx
122LookaheadLess: movl %ebx, nicematch(%esp)
123
124/* register Bytef *scan = s->window + s->strstart; */
125
126 movl dsWindow(%edx), %esi
127 movl %esi, window(%esp)
128 movl dsStrStart(%edx), %ebp
129 lea (%esi,%ebp), %edi
130 movl %edi, scan(%esp)
131
132/* Determine how many bytes the scan ptr is off from being */
133/* dword-aligned. */
134
135 movl %edi, %eax
136 negl %eax
137 andl $3, %eax
138 movl %eax, scanalign(%esp)
139
140/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */
141/* s->strstart - (IPos)MAX_DIST(s) : NIL; */
142
143 movl dsWSize(%edx), %eax
144 subl $MIN_LOOKAHEAD, %eax
145 subl %eax, %ebp
146 jg LimitPositive
147 xorl %ebp, %ebp
148LimitPositive:
149
150/* int best_len = s->prev_length; */
151
152 movl dsPrevLen(%edx), %eax
153 movl %eax, bestlen(%esp)
154
155/* Store the sum of s->window + best_len in %esi locally, and in %esi. */
156
157 addl %eax, %esi
158 movl %esi, windowbestlen(%esp)
159
160/* register ush scan_start = *(ushf*)scan; */
161/* register ush scan_end = *(ushf*)(scan+best_len-1); */
162/* Posf *prev = s->prev; */
163
164 movzwl (%edi), %ebx
165 movl %ebx, scanstart(%esp)
166 movzwl -1(%edi,%eax), %ebx
167 movl %ebx, scanend(%esp)
168 movl dsPrev(%edx), %edi
169
170/* Jump into the main loop. */
171
172 movl chainlenwmask(%esp), %edx
173 jmp LoopEntry
174
175.balign 16
176
177/* do {
178 * match = s->window + cur_match;
179 * if (*(ushf*)(match+best_len-1) != scan_end ||
180 * *(ushf*)match != scan_start) continue;
181 * [...]
182 * } while ((cur_match = prev[cur_match & wmask]) > limit
183 * && --chain_length != 0);
184 *
185 * Here is the inner loop of the function. The function will spend the
186 * majority of its time in this loop, and majority of that time will
187 * be spent in the first ten instructions.
188 *
189 * Within this loop:
190 * %ebx = scanend
191 * %ecx = curmatch
192 * %edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)
193 * %esi = windowbestlen - i.e., (window + bestlen)
194 * %edi = prev
195 * %ebp = limit
196 */
197LookupLoop:
198 andl %edx, %ecx
199 movzwl (%edi,%ecx,2), %ecx
200 cmpl %ebp, %ecx
201 jbe LeaveNow
202 subl $0x00010000, %edx
203 js LeaveNow
204LoopEntry: movzwl -1(%esi,%ecx), %eax
205 cmpl %ebx, %eax
206 jnz LookupLoop
207 movl window(%esp), %eax
208 movzwl (%eax,%ecx), %eax
209 cmpl scanstart(%esp), %eax
210 jnz LookupLoop
211
212/* Store the current value of chainlen. */
213
214 movl %edx, chainlenwmask(%esp)
215
216/* Point %edi to the string under scrutiny, and %esi to the string we */
217/* are hoping to match it up with. In actuality, %esi and %edi are */
218/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */
219/* initialized to -(MAX_MATCH_8 - scanalign). */
220
221 movl window(%esp), %esi
222 movl scan(%esp), %edi
223 addl %ecx, %esi
224 movl scanalign(%esp), %eax
225 movl $(-MAX_MATCH_8), %edx
226 lea MAX_MATCH_8(%edi,%eax), %edi
227 lea MAX_MATCH_8(%esi,%eax), %esi
228
229/* Test the strings for equality, 8 bytes at a time. At the end,
230 * adjust %edx so that it is offset to the exact byte that mismatched.
231 *
232 * We already know at this point that the first three bytes of the
233 * strings match each other, and they can be safely passed over before
234 * starting the compare loop. So what this code does is skip over 0-3
235 * bytes, as much as necessary in order to dword-align the %edi
236 * pointer. (%esi will still be misaligned three times out of four.)
237 *
238 * It should be confessed that this loop usually does not represent
239 * much of the total running time. Replacing it with a more
240 * straightforward "rep cmpsb" would not drastically degrade
241 * performance.
242 */
243LoopCmps:
244 movl (%esi,%edx), %eax
245 xorl (%edi,%edx), %eax
246 jnz LeaveLoopCmps
247 movl 4(%esi,%edx), %eax
248 xorl 4(%edi,%edx), %eax
249 jnz LeaveLoopCmps4
250 addl $8, %edx
251 jnz LoopCmps
252 jmp LenMaximum
253LeaveLoopCmps4: addl $4, %edx
254LeaveLoopCmps: testl $0x0000FFFF, %eax
255 jnz LenLower
256 addl $2, %edx
257 shrl $16, %eax
258LenLower: subb $1, %al
259 adcl $0, %edx
260
261/* Calculate the length of the match. If it is longer than MAX_MATCH, */
262/* then automatically accept it as the best possible match and leave. */
263
264 lea (%edi,%edx), %eax
265 movl scan(%esp), %edi
266 subl %edi, %eax
267 cmpl $MAX_MATCH, %eax
268 jge LenMaximum
269
270/* If the length of the match is not longer than the best match we */
271/* have so far, then forget it and return to the lookup loop. */
272
273 movl deflatestate(%esp), %edx
274 movl bestlen(%esp), %ebx
275 cmpl %ebx, %eax
276 jg LongerMatch
277 movl windowbestlen(%esp), %esi
278 movl dsPrev(%edx), %edi
279 movl scanend(%esp), %ebx
280 movl chainlenwmask(%esp), %edx
281 jmp LookupLoop
282
283/* s->match_start = cur_match; */
284/* best_len = len; */
285/* if (len >= nice_match) break; */
286/* scan_end = *(ushf*)(scan+best_len-1); */
287
288LongerMatch: movl nicematch(%esp), %ebx
289 movl %eax, bestlen(%esp)
290 movl %ecx, dsMatchStart(%edx)
291 cmpl %ebx, %eax
292 jge LeaveNow
293 movl window(%esp), %esi
294 addl %eax, %esi
295 movl %esi, windowbestlen(%esp)
296 movzwl -1(%edi,%eax), %ebx
297 movl dsPrev(%edx), %edi
298 movl %ebx, scanend(%esp)
299 movl chainlenwmask(%esp), %edx
300 jmp LookupLoop
301
302/* Accept the current string, with the maximum possible length. */
303
304LenMaximum: movl deflatestate(%esp), %edx
305 movl $MAX_MATCH, bestlen(%esp)
306 movl %ecx, dsMatchStart(%edx)
307
308/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */
309/* return s->lookahead; */
310
311LeaveNow:
312 movl deflatestate(%esp), %edx
313 movl bestlen(%esp), %ebx
314 movl dsLookahead(%edx), %eax
315 cmpl %eax, %ebx
316 jg LookaheadRet
317 movl %ebx, %eax
318LookaheadRet:
319
320/* Restore the stack and return from whence we came. */
321
322 addl $LocalVarsSize, %esp
323 popl %ebx
324 popl %esi
325 popl %edi
326 popl %ebp
327match_init: ret
diff --git a/contrib/delphi/zlib.mak b/contrib/delphi/zlib.mak
new file mode 100644
index 0000000..ba557e2
--- /dev/null
+++ b/contrib/delphi/zlib.mak
@@ -0,0 +1,36 @@
1# Makefile for zlib32bd.lib
2# ------------- Borland C++ 4.5 -------------
3
4# The (32-bit) zlib32bd.lib made with this makefile is intended for use
5# in making the (32-bit) DLL, png32bd.dll. It uses the "stdcall" calling
6# convention.
7
8CFLAGS= -ps -O2 -C -K -N- -k- -d -3 -r- -w-par -w-aus -WDE
9CC=f:\bc45\bin\bcc32
10LIBFLAGS= /C
11LIB=f:\bc45\bin\tlib
12ZLIB=zlib32bd.lib
13
14.autodepend
15.c.obj:
16 $(CC) -c $(CFLAGS) $<
17
18OBJ1=adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infblock.obj
19OBJ2=infcodes.obj inflate.obj inftrees.obj infutil.obj inffast.obj
20OBJ3=trees.obj uncompr.obj zutil.obj
21pOBJ1=+adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infblock.obj
22pOBJ2=+infcodes.obj+inflate.obj+inftrees.obj+infutil.obj+inffast.obj
23pOBJ3=+trees.obj+uncompr.obj+zutil.obj
24
25all: $(ZLIB)
26
27$(ZLIB): $(OBJ1) $(OBJ2) $(OBJ3)
28 @if exist $@ del $@
29 $(LIB) @&&|
30$@ $(LIBFLAGS) &
31$(pOBJ1) &
32$(pOBJ2) &
33$(pOBJ3)
34|
35
36# End of makefile for zlib32bd.lib
diff --git a/contrib/delphi/zlibdef.pas b/contrib/delphi/zlibdef.pas
new file mode 100644
index 0000000..4f96b7d
--- /dev/null
+++ b/contrib/delphi/zlibdef.pas
@@ -0,0 +1,169 @@
1unit zlibdef;
2
3interface
4
5uses
6 Windows;
7
8const
9 ZLIB_VERSION = '1.1.3';
10
11type
12 voidpf = Pointer;
13 int = Integer;
14 uInt = Cardinal;
15 pBytef = PChar;
16 uLong = Cardinal;
17
18 alloc_func = function(opaque: voidpf; items, size: uInt): voidpf;
19 stdcall;
20 free_func = procedure(opaque, address: voidpf);
21 stdcall;
22
23 internal_state = Pointer;
24
25 z_streamp = ^z_stream;
26 z_stream = packed record
27 next_in: pBytef; // next input byte
28 avail_in: uInt; // number of bytes available at next_in
29 total_in: uLong; // total nb of input bytes read so far
30
31 next_out: pBytef; // next output byte should be put there
32 avail_out: uInt; // remaining free space at next_out
33 total_out: uLong; // total nb of bytes output so far
34
35 msg: PChar; // last error message, NULL if no error
36 state: internal_state; // not visible by applications
37
38 zalloc: alloc_func; // used to allocate the internal state
39 zfree: free_func; // used to free the internal state
40 opaque: voidpf; // private data object passed to zalloc and zfree
41
42 data_type: int; // best guess about the data type: ascii or binary
43 adler: uLong; // adler32 value of the uncompressed data
44 reserved: uLong; // reserved for future use
45 end;
46
47const
48 Z_NO_FLUSH = 0;
49 Z_SYNC_FLUSH = 2;
50 Z_FULL_FLUSH = 3;
51 Z_FINISH = 4;
52
53 Z_OK = 0;
54 Z_STREAM_END = 1;
55
56 Z_NO_COMPRESSION = 0;
57 Z_BEST_SPEED = 1;
58 Z_BEST_COMPRESSION = 9;
59 Z_DEFAULT_COMPRESSION = -1;
60
61 Z_FILTERED = 1;
62 Z_HUFFMAN_ONLY = 2;
63 Z_DEFAULT_STRATEGY = 0;
64
65 Z_BINARY = 0;
66 Z_ASCII = 1;
67 Z_UNKNOWN = 2;
68
69 Z_DEFLATED = 8;
70
71 MAX_MEM_LEVEL = 9;
72
73function adler32(adler: uLong; const buf: pBytef; len: uInt): uLong;
74 stdcall;
75function crc32(crc: uLong; const buf: pBytef; len: uInt): uLong;
76 stdcall;
77function deflate(strm: z_streamp; flush: int): int;
78 stdcall;
79function deflateCopy(dest, source: z_streamp): int;
80 stdcall;
81function deflateEnd(strm: z_streamp): int;
82 stdcall;
83function deflateInit2_(strm: z_streamp; level, method,
84 windowBits, memLevel, strategy: int;
85 const version: PChar; stream_size: int): int;
86 stdcall;
87function deflateInit_(strm: z_streamp; level: int;
88 const version: PChar; stream_size: int): int;
89 stdcall;
90function deflateParams(strm: z_streamp; level, strategy: int): int;
91 stdcall;
92function deflateReset(strm: z_streamp): int;
93 stdcall;
94function deflateSetDictionary(strm: z_streamp;
95 const dictionary: pBytef;
96 dictLength: uInt): int;
97 stdcall;
98function inflate(strm: z_streamp; flush: int): int;
99 stdcall;
100function inflateEnd(strm: z_streamp): int;
101 stdcall;
102function inflateInit2_(strm: z_streamp; windowBits: int;
103 const version: PChar; stream_size: int): int;
104 stdcall;
105function inflateInit_(strm: z_streamp; const version: PChar;
106 stream_size: int): int;
107 stdcall;
108function inflateReset(strm: z_streamp): int;
109 stdcall;
110function inflateSetDictionary(strm: z_streamp;
111 const dictionary: pBytef;
112 dictLength: uInt): int;
113 stdcall;
114function inflateSync(strm: z_streamp): int;
115 stdcall;
116
117function deflateInit(strm: z_streamp; level: int): int;
118function deflateInit2(strm: z_streamp; level, method, windowBits,
119 memLevel, strategy: int): int;
120function inflateInit(strm: z_streamp): int;
121function inflateInit2(strm: z_streamp; windowBits: int): int;
122
123implementation
124
125function deflateInit(strm: z_streamp; level: int): int;
126begin
127 Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
128end;
129
130function deflateInit2(strm: z_streamp; level, method, windowBits,
131 memLevel, strategy: int): int;
132begin
133 Result := deflateInit2_(strm, level, method, windowBits, memLevel,
134 strategy, ZLIB_VERSION, sizeof(z_stream));
135end;
136
137function inflateInit(strm: z_streamp): int;
138begin
139 Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
140end;
141
142function inflateInit2(strm: z_streamp; windowBits: int): int;
143begin
144 Result := inflateInit2_(strm, windowBits, ZLIB_VERSION,
145 sizeof(z_stream));
146end;
147
148const
149 zlibDLL = 'png32bd.dll';
150
151function adler32; external zlibDLL;
152function crc32; external zlibDLL;
153function deflate; external zlibDLL;
154function deflateCopy; external zlibDLL;
155function deflateEnd; external zlibDLL;
156function deflateInit2_; external zlibDLL;
157function deflateInit_; external zlibDLL;
158function deflateParams; external zlibDLL;
159function deflateReset; external zlibDLL;
160function deflateSetDictionary; external zlibDLL;
161function inflate; external zlibDLL;
162function inflateEnd; external zlibDLL;
163function inflateInit2_; external zlibDLL;
164function inflateInit_; external zlibDLL;
165function inflateReset; external zlibDLL;
166function inflateSetDictionary; external zlibDLL;
167function inflateSync; external zlibDLL;
168
169end.
diff --git a/contrib/delphi2/d_zlib.bpr b/contrib/delphi2/d_zlib.bpr
new file mode 100644
index 0000000..78bb254
--- /dev/null
+++ b/contrib/delphi2/d_zlib.bpr
@@ -0,0 +1,224 @@
1# ---------------------------------------------------------------------------
2!if !$d(BCB)
3BCB = $(MAKEDIR)\..
4!endif
5
6# ---------------------------------------------------------------------------
7# IDE SECTION
8# ---------------------------------------------------------------------------
9# The following section of the project makefile is managed by the BCB IDE.
10# It is recommended to use the IDE to change any of the values in this
11# section.
12# ---------------------------------------------------------------------------
13
14VERSION = BCB.03
15# ---------------------------------------------------------------------------
16PROJECT = d_zlib.lib
17OBJFILES = d_zlib.obj adler32.obj deflate.obj infblock.obj infcodes.obj inffast.obj \
18 inflate.obj inftrees.obj infutil.obj trees.obj
19RESFILES =
20RESDEPEN = $(RESFILES)
21LIBFILES =
22LIBRARIES = VCL35.lib
23SPARELIBS = VCL35.lib
24DEFFILE =
25PACKAGES = VCLX35.bpi VCL35.bpi VCLDB35.bpi VCLDBX35.bpi ibsmp35.bpi bcbsmp35.bpi \
26 dclocx35.bpi QRPT35.bpi TEEUI35.bpi TEEDB35.bpi TEE35.bpi DSS35.bpi \
27 NMFAST35.bpi INETDB35.bpi INET35.bpi VCLMID35.bpi
28# ---------------------------------------------------------------------------
29PATHCPP = .;
30PATHASM = .;
31PATHPAS = .;
32PATHRC = .;
33DEBUGLIBPATH = $(BCB)\lib\debug
34RELEASELIBPATH = $(BCB)\lib\release
35# ---------------------------------------------------------------------------
36CFLAG1 = -O2 -Ve -d -k- -vi
37CFLAG2 = -I$(BCB)\include;$(BCB)\include\vcl -H=$(BCB)\lib\vcl35.csm
38CFLAG3 = -ff -pr -5
39PFLAGS = -U;$(DEBUGLIBPATH) -I$(BCB)\include;$(BCB)\include\vcl -H -W -$I- -v -JPHN -M
40RFLAGS = -i$(BCB)\include;$(BCB)\include\vcl
41AFLAGS = /i$(BCB)\include /i$(BCB)\include\vcl /mx /w2 /zn
42LFLAGS =
43IFLAGS = -g -Gn
44# ---------------------------------------------------------------------------
45ALLOBJ = c0w32.obj $(OBJFILES)
46ALLRES = $(RESFILES)
47ALLLIB = $(LIBFILES) $(LIBRARIES) import32.lib cp32mt.lib
48# ---------------------------------------------------------------------------
49!!ifdef IDEOPTIONS
50
51[Version Info]
52IncludeVerInfo=0
53AutoIncBuild=0
54MajorVer=1
55MinorVer=0
56Release=0
57Build=0
58Debug=0
59PreRelease=0
60Special=0
61Private=0
62DLL=0
63Locale=1040
64CodePage=1252
65
66[Version Info Keys]
67CompanyName=
68FileDescription=
69FileVersion=1.0.0.0
70InternalName=
71LegalCopyright=
72LegalTrademarks=
73OriginalFilename=
74ProductName=
75ProductVersion=1.0.0.0
76Comments=
77
78[HistoryLists\hlIncludePath]
79Count=2
80Item0=$(BCB)\include
81Item1=$(BCB)\include;$(BCB)\include\vcl
82
83[HistoryLists\hlLibraryPath]
84Count=1
85Item0=$(BCB)\lib\obj;$(BCB)\lib
86
87[HistoryLists\hlDebugSourcePath]
88Count=1
89Item0=$(BCB)\source\vcl
90
91[Debugging]
92DebugSourceDirs=
93
94[Parameters]
95RunParams=
96HostApplication=
97
98!endif
99
100 ---------------------------------------------------------------------------
101# MAKE SECTION
102# ---------------------------------------------------------------------------
103# This section of the project file is not used by the BCB IDE. It is for
104# the benefit of building from the command-line using the MAKE utility.
105# ---------------------------------------------------------------------------
106
107.autodepend
108# ---------------------------------------------------------------------------
109!if !$d(BCC32)
110BCC32 = bcc32
111!endif
112
113!if !$d(DCC32)
114DCC32 = dcc32
115!endif
116
117!if !$d(TASM32)
118TASM32 = tasm32
119!endif
120
121!if !$d(LINKER)
122LINKER = TLib
123!endif
124
125!if !$d(BRCC32)
126BRCC32 = brcc32
127!endif
128# ---------------------------------------------------------------------------
129!if $d(PATHCPP)
130.PATH.CPP = $(PATHCPP)
131.PATH.C = $(PATHCPP)
132!endif
133
134!if $d(PATHPAS)
135.PATH.PAS = $(PATHPAS)
136!endif
137
138!if $d(PATHASM)
139.PATH.ASM = $(PATHASM)
140!endif
141
142!if $d(PATHRC)
143.PATH.RC = $(PATHRC)
144!endif
145# ---------------------------------------------------------------------------
146!ifdef IDEOPTIONS
147
148[Version Info]
149IncludeVerInfo=0
150AutoIncBuild=0
151MajorVer=1
152MinorVer=0
153Release=0
154Build=0
155Debug=0
156PreRelease=0
157Special=0
158Private=0
159DLL=0
160Locale=1040
161CodePage=1252
162
163[Version Info Keys]
164CompanyName=
165FileDescription=
166FileVersion=1.0.0.0
167InternalName=
168LegalCopyright=
169LegalTrademarks=
170OriginalFilename=
171ProductName=
172ProductVersion=1.0.0.0
173Comments=
174
175[HistoryLists\hlIncludePath]
176Count=2
177Item0=$(BCB)\include;$(BCB)\include\vcl
178Item1=$(BCB)\include
179
180[HistoryLists\hlLibraryPath]
181Count=1
182Item0=$(BCB)\lib\obj;$(BCB)\lib
183
184[HistoryLists\hlDebugSourcePath]
185Count=1
186Item0=$(BCB)\source\vcl
187
188[Debugging]
189DebugSourceDirs=
190
191[Parameters]
192RunParams=
193HostApplication=
194
195!endif
196
197$(PROJECT): $(OBJFILES) $(RESDEPEN) $(DEFFILE)
198 $(BCB)\BIN\$(LINKER) @&&!
199 $(LFLAGS) $(IFLAGS) +
200 $(ALLOBJ), +
201 $(PROJECT),, +
202 $(ALLLIB), +
203 $(DEFFILE), +
204 $(ALLRES)
205!
206# ---------------------------------------------------------------------------
207.pas.hpp:
208 $(BCB)\BIN\$(DCC32) $(PFLAGS) {$< }
209
210.pas.obj:
211 $(BCB)\BIN\$(DCC32) $(PFLAGS) {$< }
212
213.cpp.obj:
214 $(BCB)\BIN\$(BCC32) $(CFLAG1) $(CFLAG2) $(CFLAG3) -n$(@D) {$< }
215
216.c.obj:
217 $(BCB)\BIN\$(BCC32) $(CFLAG1) $(CFLAG2) $(CFLAG3) -n$(@D) {$< }
218
219.asm.obj:
220 $(BCB)\BIN\$(TASM32) $(AFLAGS) $<, $@
221
222.rc.res:
223 $(BCB)\BIN\$(BRCC32) $(RFLAGS) -fo$@ $<
224# ---------------------------------------------------------------------------
diff --git a/contrib/delphi2/d_zlib.cpp b/contrib/delphi2/d_zlib.cpp
new file mode 100644
index 0000000..f5dea59
--- /dev/null
+++ b/contrib/delphi2/d_zlib.cpp
@@ -0,0 +1,17 @@
1#include <condefs.h>
2#pragma hdrstop
3//---------------------------------------------------------------------------
4USEUNIT("adler32.c");
5USEUNIT("deflate.c");
6USEUNIT("infblock.c");
7USEUNIT("infcodes.c");
8USEUNIT("inffast.c");
9USEUNIT("inflate.c");
10USEUNIT("inftrees.c");
11USEUNIT("infutil.c");
12USEUNIT("trees.c");
13//---------------------------------------------------------------------------
14#define Library
15
16// To add a file to the library use the Project menu 'Add to Project'.
17
diff --git a/contrib/delphi2/readme.txt b/contrib/delphi2/readme.txt
new file mode 100644
index 0000000..cbd3162
--- /dev/null
+++ b/contrib/delphi2/readme.txt
@@ -0,0 +1,17 @@
1These are files used to compile zlib under Borland C++ Builder 3.
2
3zlib.bpg is the main project group that can be loaded in the BCB IDE and
4loads all other *.bpr projects
5
6zlib.bpr is a project used to create a static zlib.lib library with C calling
7convention for functions.
8
9zlib32.bpr creates a zlib32.dll dynamic link library with Windows standard
10calling convention.
11
12d_zlib.bpr creates a set of .obj files with register calling convention.
13These files are used by zlib.pas to create a Delphi unit containing zlib.
14The d_zlib.lib file generated isn't useful and can be deleted.
15
16zlib.cpp, zlib32.cpp and d_zlib.cpp are used by the above projects.
17
diff --git a/contrib/delphi2/zlib.bpg b/contrib/delphi2/zlib.bpg
new file mode 100644
index 0000000..b6c9acd
--- /dev/null
+++ b/contrib/delphi2/zlib.bpg
@@ -0,0 +1,26 @@
1#------------------------------------------------------------------------------
2VERSION = BWS.01
3#------------------------------------------------------------------------------
4!ifndef ROOT
5ROOT = $(MAKEDIR)\..
6!endif
7#------------------------------------------------------------------------------
8MAKE = $(ROOT)\bin\make.exe -$(MAKEFLAGS) -f$**
9DCC = $(ROOT)\bin\dcc32.exe $**
10BRCC = $(ROOT)\bin\brcc32.exe $**
11#------------------------------------------------------------------------------
12PROJECTS = zlib zlib32 d_zlib
13#------------------------------------------------------------------------------
14default: $(PROJECTS)
15#------------------------------------------------------------------------------
16
17zlib: zlib.bpr
18 $(MAKE)
19
20zlib32: zlib32.bpr
21 $(MAKE)
22
23d_zlib: d_zlib.bpr
24 $(MAKE)
25
26
diff --git a/contrib/delphi2/zlib.bpr b/contrib/delphi2/zlib.bpr
new file mode 100644
index 0000000..cf3945b
--- /dev/null
+++ b/contrib/delphi2/zlib.bpr
@@ -0,0 +1,225 @@
1# ---------------------------------------------------------------------------
2!if !$d(BCB)
3BCB = $(MAKEDIR)\..
4!endif
5
6# ---------------------------------------------------------------------------
7# IDE SECTION
8# ---------------------------------------------------------------------------
9# The following section of the project makefile is managed by the BCB IDE.
10# It is recommended to use the IDE to change any of the values in this
11# section.
12# ---------------------------------------------------------------------------
13
14VERSION = BCB.03
15# ---------------------------------------------------------------------------
16PROJECT = zlib.lib
17OBJFILES = zlib.obj adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infblock.obj \
18 infcodes.obj inffast.obj inflate.obj inftrees.obj infutil.obj trees.obj \
19 uncompr.obj zutil.obj
20RESFILES =
21RESDEPEN = $(RESFILES)
22LIBFILES =
23LIBRARIES = VCL35.lib
24SPARELIBS = VCL35.lib
25DEFFILE =
26PACKAGES = VCLX35.bpi VCL35.bpi VCLDB35.bpi VCLDBX35.bpi ibsmp35.bpi bcbsmp35.bpi \
27 dclocx35.bpi QRPT35.bpi TEEUI35.bpi TEEDB35.bpi TEE35.bpi DSS35.bpi \
28 NMFAST35.bpi INETDB35.bpi INET35.bpi VCLMID35.bpi
29# ---------------------------------------------------------------------------
30PATHCPP = .;
31PATHASM = .;
32PATHPAS = .;
33PATHRC = .;
34DEBUGLIBPATH = $(BCB)\lib\debug
35RELEASELIBPATH = $(BCB)\lib\release
36# ---------------------------------------------------------------------------
37CFLAG1 = -O2 -Ve -d -k- -vi
38CFLAG2 = -I$(BCB)\include;$(BCB)\include\vcl -H=$(BCB)\lib\vcl35.csm
39CFLAG3 = -ff -5
40PFLAGS = -U;$(DEBUGLIBPATH) -I$(BCB)\include;$(BCB)\include\vcl -H -W -$I- -v -JPHN -M
41RFLAGS = -i$(BCB)\include;$(BCB)\include\vcl
42AFLAGS = /i$(BCB)\include /i$(BCB)\include\vcl /mx /w2 /zn
43LFLAGS =
44IFLAGS = -g -Gn
45# ---------------------------------------------------------------------------
46ALLOBJ = c0w32.obj $(OBJFILES)
47ALLRES = $(RESFILES)
48ALLLIB = $(LIBFILES) $(LIBRARIES) import32.lib cp32mt.lib
49# ---------------------------------------------------------------------------
50!!ifdef IDEOPTIONS
51
52[Version Info]
53IncludeVerInfo=0
54AutoIncBuild=0
55MajorVer=1
56MinorVer=0
57Release=0
58Build=0
59Debug=0
60PreRelease=0
61Special=0
62Private=0
63DLL=0
64Locale=1040
65CodePage=1252
66
67[Version Info Keys]
68CompanyName=
69FileDescription=
70FileVersion=1.0.0.0
71InternalName=
72LegalCopyright=
73LegalTrademarks=
74OriginalFilename=
75ProductName=
76ProductVersion=1.0.0.0
77Comments=
78
79[HistoryLists\hlIncludePath]
80Count=2
81Item0=$(BCB)\include
82Item1=$(BCB)\include;$(BCB)\include\vcl
83
84[HistoryLists\hlLibraryPath]
85Count=1
86Item0=$(BCB)\lib\obj;$(BCB)\lib
87
88[HistoryLists\hlDebugSourcePath]
89Count=1
90Item0=$(BCB)\source\vcl
91
92[Debugging]
93DebugSourceDirs=
94
95[Parameters]
96RunParams=
97HostApplication=
98
99!endif
100
101 ---------------------------------------------------------------------------
102# MAKE SECTION
103# ---------------------------------------------------------------------------
104# This section of the project file is not used by the BCB IDE. It is for
105# the benefit of building from the command-line using the MAKE utility.
106# ---------------------------------------------------------------------------
107
108.autodepend
109# ---------------------------------------------------------------------------
110!if !$d(BCC32)
111BCC32 = bcc32
112!endif
113
114!if !$d(DCC32)
115DCC32 = dcc32
116!endif
117
118!if !$d(TASM32)
119TASM32 = tasm32
120!endif
121
122!if !$d(LINKER)
123LINKER = TLib
124!endif
125
126!if !$d(BRCC32)
127BRCC32 = brcc32
128!endif
129# ---------------------------------------------------------------------------
130!if $d(PATHCPP)
131.PATH.CPP = $(PATHCPP)
132.PATH.C = $(PATHCPP)
133!endif
134
135!if $d(PATHPAS)
136.PATH.PAS = $(PATHPAS)
137!endif
138
139!if $d(PATHASM)
140.PATH.ASM = $(PATHASM)
141!endif
142
143!if $d(PATHRC)
144.PATH.RC = $(PATHRC)
145!endif
146# ---------------------------------------------------------------------------
147!ifdef IDEOPTIONS
148
149[Version Info]
150IncludeVerInfo=0
151AutoIncBuild=0
152MajorVer=1
153MinorVer=0
154Release=0
155Build=0
156Debug=0
157PreRelease=0
158Special=0
159Private=0
160DLL=0
161Locale=1040
162CodePage=1252
163
164[Version Info Keys]
165CompanyName=
166FileDescription=
167FileVersion=1.0.0.0
168InternalName=
169LegalCopyright=
170LegalTrademarks=
171OriginalFilename=
172ProductName=
173ProductVersion=1.0.0.0
174Comments=
175
176[HistoryLists\hlIncludePath]
177Count=2
178Item0=$(BCB)\include;$(BCB)\include\vcl
179Item1=$(BCB)\include
180
181[HistoryLists\hlLibraryPath]
182Count=1
183Item0=$(BCB)\lib\obj;$(BCB)\lib
184
185[HistoryLists\hlDebugSourcePath]
186Count=1
187Item0=$(BCB)\source\vcl
188
189[Debugging]
190DebugSourceDirs=
191
192[Parameters]
193RunParams=
194HostApplication=
195
196!endif
197
198$(PROJECT): $(OBJFILES) $(RESDEPEN) $(DEFFILE)
199 $(BCB)\BIN\$(LINKER) @&&!
200 $(LFLAGS) $(IFLAGS) +
201 $(ALLOBJ), +
202 $(PROJECT),, +
203 $(ALLLIB), +
204 $(DEFFILE), +
205 $(ALLRES)
206!
207# ---------------------------------------------------------------------------
208.pas.hpp:
209 $(BCB)\BIN\$(DCC32) $(PFLAGS) {$< }
210
211.pas.obj:
212 $(BCB)\BIN\$(DCC32) $(PFLAGS) {$< }
213
214.cpp.obj:
215 $(BCB)\BIN\$(BCC32) $(CFLAG1) $(CFLAG2) $(CFLAG3) -n$(@D) {$< }
216
217.c.obj:
218 $(BCB)\BIN\$(BCC32) $(CFLAG1) $(CFLAG2) $(CFLAG3) -n$(@D) {$< }
219
220.asm.obj:
221 $(BCB)\BIN\$(TASM32) $(AFLAGS) $<, $@
222
223.rc.res:
224 $(BCB)\BIN\$(BRCC32) $(RFLAGS) -fo$@ $<
225# ---------------------------------------------------------------------------
diff --git a/contrib/delphi2/zlib.cpp b/contrib/delphi2/zlib.cpp
new file mode 100644
index 0000000..bf6953b
--- /dev/null
+++ b/contrib/delphi2/zlib.cpp
@@ -0,0 +1,22 @@
1#include <condefs.h>
2#pragma hdrstop
3//---------------------------------------------------------------------------
4USEUNIT("adler32.c");
5USEUNIT("compress.c");
6USEUNIT("crc32.c");
7USEUNIT("deflate.c");
8USEUNIT("gzio.c");
9USEUNIT("infblock.c");
10USEUNIT("infcodes.c");
11USEUNIT("inffast.c");
12USEUNIT("inflate.c");
13USEUNIT("inftrees.c");
14USEUNIT("infutil.c");
15USEUNIT("trees.c");
16USEUNIT("uncompr.c");
17USEUNIT("zutil.c");
18//---------------------------------------------------------------------------
19#define Library
20
21// To add a file to the library use the Project menu 'Add to Project'.
22
diff --git a/contrib/delphi2/zlib.pas b/contrib/delphi2/zlib.pas
new file mode 100644
index 0000000..10ae4ca
--- /dev/null
+++ b/contrib/delphi2/zlib.pas
@@ -0,0 +1,534 @@
1{*******************************************************}
2{ }
3{ Delphi Supplemental Components }
4{ ZLIB Data Compression Interface Unit }
5{ }
6{ Copyright (c) 1997 Borland International }
7{ }
8{*******************************************************}
9
10{ Modified for zlib 1.1.3 by Davide Moretti <dave@rimini.com }
11
12unit zlib;
13
14interface
15
16uses Sysutils, Classes;
17
18type
19 TAlloc = function (AppData: Pointer; Items, Size: Integer): Pointer;
20 TFree = procedure (AppData, Block: Pointer);
21
22 // Internal structure. Ignore.
23 TZStreamRec = packed record
24 next_in: PChar; // next input byte
25 avail_in: Integer; // number of bytes available at next_in
26 total_in: Integer; // total nb of input bytes read so far
27
28 next_out: PChar; // next output byte should be put here
29 avail_out: Integer; // remaining free space at next_out
30 total_out: Integer; // total nb of bytes output so far
31
32 msg: PChar; // last error message, NULL if no error
33 internal: Pointer; // not visible by applications
34
35 zalloc: TAlloc; // used to allocate the internal state
36 zfree: TFree; // used to free the internal state
37 AppData: Pointer; // private data object passed to zalloc and zfree
38
39 data_type: Integer; // best guess about the data type: ascii or binary
40 adler: Integer; // adler32 value of the uncompressed data
41 reserved: Integer; // reserved for future use
42 end;
43
44 // Abstract ancestor class
45 TCustomZlibStream = class(TStream)
46 private
47 FStrm: TStream;
48 FStrmPos: Integer;
49 FOnProgress: TNotifyEvent;
50 FZRec: TZStreamRec;
51 FBuffer: array [Word] of Char;
52 protected
53 procedure Progress(Sender: TObject); dynamic;
54 property OnProgress: TNotifyEvent read FOnProgress write FOnProgress;
55 constructor Create(Strm: TStream);
56 end;
57
58{ TCompressionStream compresses data on the fly as data is written to it, and
59 stores the compressed data to another stream.
60
61 TCompressionStream is write-only and strictly sequential. Reading from the
62 stream will raise an exception. Using Seek to move the stream pointer
63 will raise an exception.
64
65 Output data is cached internally, written to the output stream only when
66 the internal output buffer is full. All pending output data is flushed
67 when the stream is destroyed.
68
69 The Position property returns the number of uncompressed bytes of
70 data that have been written to the stream so far.
71
72 CompressionRate returns the on-the-fly percentage by which the original
73 data has been compressed: (1 - (CompressedBytes / UncompressedBytes)) * 100
74 If raw data size = 100 and compressed data size = 25, the CompressionRate
75 is 75%
76
77 The OnProgress event is called each time the output buffer is filled and
78 written to the output stream. This is useful for updating a progress
79 indicator when you are writing a large chunk of data to the compression
80 stream in a single call.}
81
82
83 TCompressionLevel = (clNone, clFastest, clDefault, clMax);
84
85 TCompressionStream = class(TCustomZlibStream)
86 private
87 function GetCompressionRate: Single;
88 public
89 constructor Create(CompressionLevel: TCompressionLevel; Dest: TStream);
90 destructor Destroy; override;
91 function Read(var Buffer; Count: Longint): Longint; override;
92 function Write(const Buffer; Count: Longint): Longint; override;
93 function Seek(Offset: Longint; Origin: Word): Longint; override;
94 property CompressionRate: Single read GetCompressionRate;
95 property OnProgress;
96 end;
97
98{ TDecompressionStream decompresses data on the fly as data is read from it.
99
100 Compressed data comes from a separate source stream. TDecompressionStream
101 is read-only and unidirectional; you can seek forward in the stream, but not
102 backwards. The special case of setting the stream position to zero is
103 allowed. Seeking forward decompresses data until the requested position in
104 the uncompressed data has been reached. Seeking backwards, seeking relative
105 to the end of the stream, requesting the size of the stream, and writing to
106 the stream will raise an exception.
107
108 The Position property returns the number of bytes of uncompressed data that
109 have been read from the stream so far.
110
111 The OnProgress event is called each time the internal input buffer of
112 compressed data is exhausted and the next block is read from the input stream.
113 This is useful for updating a progress indicator when you are reading a
114 large chunk of data from the decompression stream in a single call.}
115
116 TDecompressionStream = class(TCustomZlibStream)
117 public
118 constructor Create(Source: TStream);
119 destructor Destroy; override;
120 function Read(var Buffer; Count: Longint): Longint; override;
121 function Write(const Buffer; Count: Longint): Longint; override;
122 function Seek(Offset: Longint; Origin: Word): Longint; override;
123 property OnProgress;
124 end;
125
126
127
128{ CompressBuf compresses data, buffer to buffer, in one call.
129 In: InBuf = ptr to compressed data
130 InBytes = number of bytes in InBuf
131 Out: OutBuf = ptr to newly allocated buffer containing decompressed data
132 OutBytes = number of bytes in OutBuf }
133procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
134 out OutBuf: Pointer; out OutBytes: Integer);
135
136
137{ DecompressBuf decompresses data, buffer to buffer, in one call.
138 In: InBuf = ptr to compressed data
139 InBytes = number of bytes in InBuf
140 OutEstimate = zero, or est. size of the decompressed data
141 Out: OutBuf = ptr to newly allocated buffer containing decompressed data
142 OutBytes = number of bytes in OutBuf }
143procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
144 OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
145
146const
147 zlib_version = '1.1.3';
148
149type
150 EZlibError = class(Exception);
151 ECompressionError = class(EZlibError);
152 EDecompressionError = class(EZlibError);
153
154function adler32(adler: Integer; buf: PChar; len: Integer): Integer;
155
156implementation
157
158const
159 Z_NO_FLUSH = 0;
160 Z_PARTIAL_FLUSH = 1;
161 Z_SYNC_FLUSH = 2;
162 Z_FULL_FLUSH = 3;
163 Z_FINISH = 4;
164
165 Z_OK = 0;
166 Z_STREAM_END = 1;
167 Z_NEED_DICT = 2;
168 Z_ERRNO = (-1);
169 Z_STREAM_ERROR = (-2);
170 Z_DATA_ERROR = (-3);
171 Z_MEM_ERROR = (-4);
172 Z_BUF_ERROR = (-5);
173 Z_VERSION_ERROR = (-6);
174
175 Z_NO_COMPRESSION = 0;
176 Z_BEST_SPEED = 1;
177 Z_BEST_COMPRESSION = 9;
178 Z_DEFAULT_COMPRESSION = (-1);
179
180 Z_FILTERED = 1;
181 Z_HUFFMAN_ONLY = 2;
182 Z_DEFAULT_STRATEGY = 0;
183
184 Z_BINARY = 0;
185 Z_ASCII = 1;
186 Z_UNKNOWN = 2;
187
188 Z_DEFLATED = 8;
189
190 _z_errmsg: array[0..9] of PChar = (
191 'need dictionary', // Z_NEED_DICT (2)
192 'stream end', // Z_STREAM_END (1)
193 '', // Z_OK (0)
194 'file error', // Z_ERRNO (-1)
195 'stream error', // Z_STREAM_ERROR (-2)
196 'data error', // Z_DATA_ERROR (-3)
197 'insufficient memory', // Z_MEM_ERROR (-4)
198 'buffer error', // Z_BUF_ERROR (-5)
199 'incompatible version', // Z_VERSION_ERROR (-6)
200 ''
201 );
202
203{$L deflate.obj}
204{$L inflate.obj}
205{$L inftrees.obj}
206{$L trees.obj}
207{$L adler32.obj}
208{$L infblock.obj}
209{$L infcodes.obj}
210{$L infutil.obj}
211{$L inffast.obj}
212
213procedure _tr_init; external;
214procedure _tr_tally; external;
215procedure _tr_flush_block; external;
216procedure _tr_align; external;
217procedure _tr_stored_block; external;
218function adler32; external;
219procedure inflate_blocks_new; external;
220procedure inflate_blocks; external;
221procedure inflate_blocks_reset; external;
222procedure inflate_blocks_free; external;
223procedure inflate_set_dictionary; external;
224procedure inflate_trees_bits; external;
225procedure inflate_trees_dynamic; external;
226procedure inflate_trees_fixed; external;
227procedure inflate_codes_new; external;
228procedure inflate_codes; external;
229procedure inflate_codes_free; external;
230procedure _inflate_mask; external;
231procedure inflate_flush; external;
232procedure inflate_fast; external;
233
234procedure _memset(P: Pointer; B: Byte; count: Integer);cdecl;
235begin
236 FillChar(P^, count, B);
237end;
238
239procedure _memcpy(dest, source: Pointer; count: Integer);cdecl;
240begin
241 Move(source^, dest^, count);
242end;
243
244
245
246// deflate compresses data
247function deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar;
248 recsize: Integer): Integer; external;
249function deflate(var strm: TZStreamRec; flush: Integer): Integer; external;
250function deflateEnd(var strm: TZStreamRec): Integer; external;
251
252// inflate decompresses data
253function inflateInit_(var strm: TZStreamRec; version: PChar;
254 recsize: Integer): Integer; external;
255function inflate(var strm: TZStreamRec; flush: Integer): Integer; external;
256function inflateEnd(var strm: TZStreamRec): Integer; external;
257function inflateReset(var strm: TZStreamRec): Integer; external;
258
259
260function zcalloc(AppData: Pointer; Items, Size: Integer): Pointer;
261begin
262 GetMem(Result, Items*Size);
263end;
264
265procedure zcfree(AppData, Block: Pointer);
266begin
267 FreeMem(Block);
268end;
269
270function zlibCheck(code: Integer): Integer;
271begin
272 Result := code;
273 if code < 0 then
274 raise EZlibError.Create('error'); //!!
275end;
276
277function CCheck(code: Integer): Integer;
278begin
279 Result := code;
280 if code < 0 then
281 raise ECompressionError.Create('error'); //!!
282end;
283
284function DCheck(code: Integer): Integer;
285begin
286 Result := code;
287 if code < 0 then
288 raise EDecompressionError.Create('error'); //!!
289end;
290
291procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
292 out OutBuf: Pointer; out OutBytes: Integer);
293var
294 strm: TZStreamRec;
295 P: Pointer;
296begin
297 FillChar(strm, sizeof(strm), 0);
298 OutBytes := ((InBytes + (InBytes div 10) + 12) + 255) and not 255;
299 GetMem(OutBuf, OutBytes);
300 try
301 strm.next_in := InBuf;
302 strm.avail_in := InBytes;
303 strm.next_out := OutBuf;
304 strm.avail_out := OutBytes;
305 CCheck(deflateInit_(strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm)));
306 try
307 while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do
308 begin
309 P := OutBuf;
310 Inc(OutBytes, 256);
311 ReallocMem(OutBuf, OutBytes);
312 strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
313 strm.avail_out := 256;
314 end;
315 finally
316 CCheck(deflateEnd(strm));
317 end;
318 ReallocMem(OutBuf, strm.total_out);
319 OutBytes := strm.total_out;
320 except
321 FreeMem(OutBuf);
322 raise
323 end;
324end;
325
326
327procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
328 OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
329var
330 strm: TZStreamRec;
331 P: Pointer;
332 BufInc: Integer;
333begin
334 FillChar(strm, sizeof(strm), 0);
335 BufInc := (InBytes + 255) and not 255;
336 if OutEstimate = 0 then
337 OutBytes := BufInc
338 else
339 OutBytes := OutEstimate;
340 GetMem(OutBuf, OutBytes);
341 try
342 strm.next_in := InBuf;
343 strm.avail_in := InBytes;
344 strm.next_out := OutBuf;
345 strm.avail_out := OutBytes;
346 DCheck(inflateInit_(strm, zlib_version, sizeof(strm)));
347 try
348 while DCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END do
349 begin
350 P := OutBuf;
351 Inc(OutBytes, BufInc);
352 ReallocMem(OutBuf, OutBytes);
353 strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
354 strm.avail_out := BufInc;
355 end;
356 finally
357 DCheck(inflateEnd(strm));
358 end;
359 ReallocMem(OutBuf, strm.total_out);
360 OutBytes := strm.total_out;
361 except
362 FreeMem(OutBuf);
363 raise
364 end;
365end;
366
367
368// TCustomZlibStream
369
370constructor TCustomZLibStream.Create(Strm: TStream);
371begin
372 inherited Create;
373 FStrm := Strm;
374 FStrmPos := Strm.Position;
375end;
376
377procedure TCustomZLibStream.Progress(Sender: TObject);
378begin
379 if Assigned(FOnProgress) then FOnProgress(Sender);
380end;
381
382
383// TCompressionStream
384
385constructor TCompressionStream.Create(CompressionLevel: TCompressionLevel;
386 Dest: TStream);
387const
388 Levels: array [TCompressionLevel] of ShortInt =
389 (Z_NO_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_BEST_COMPRESSION);
390begin
391 inherited Create(Dest);
392 FZRec.next_out := FBuffer;
393 FZRec.avail_out := sizeof(FBuffer);
394 CCheck(deflateInit_(FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec)));
395end;
396
397destructor TCompressionStream.Destroy;
398begin
399 FZRec.next_in := nil;
400 FZRec.avail_in := 0;
401 try
402 if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
403 while (CCheck(deflate(FZRec, Z_FINISH)) <> Z_STREAM_END)
404 and (FZRec.avail_out = 0) do
405 begin
406 FStrm.WriteBuffer(FBuffer, sizeof(FBuffer));
407 FZRec.next_out := FBuffer;
408 FZRec.avail_out := sizeof(FBuffer);
409 end;
410 if FZRec.avail_out < sizeof(FBuffer) then
411 FStrm.WriteBuffer(FBuffer, sizeof(FBuffer) - FZRec.avail_out);
412 finally
413 deflateEnd(FZRec);
414 end;
415 inherited Destroy;
416end;
417
418function TCompressionStream.Read(var Buffer; Count: Longint): Longint;
419begin
420 raise ECompressionError.Create('Invalid stream operation');
421end;
422
423function TCompressionStream.Write(const Buffer; Count: Longint): Longint;
424begin
425 FZRec.next_in := @Buffer;
426 FZRec.avail_in := Count;
427 if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
428 while (FZRec.avail_in > 0) do
429 begin
430 CCheck(deflate(FZRec, 0));
431 if FZRec.avail_out = 0 then
432 begin
433 FStrm.WriteBuffer(FBuffer, sizeof(FBuffer));
434 FZRec.next_out := FBuffer;
435 FZRec.avail_out := sizeof(FBuffer);
436 FStrmPos := FStrm.Position;
437 Progress(Self);
438 end;
439 end;
440 Result := Count;
441end;
442
443function TCompressionStream.Seek(Offset: Longint; Origin: Word): Longint;
444begin
445 if (Offset = 0) and (Origin = soFromCurrent) then
446 Result := FZRec.total_in
447 else
448 raise ECompressionError.Create('Invalid stream operation');
449end;
450
451function TCompressionStream.GetCompressionRate: Single;
452begin
453 if FZRec.total_in = 0 then
454 Result := 0
455 else
456 Result := (1.0 - (FZRec.total_out / FZRec.total_in)) * 100.0;
457end;
458
459
460// TDecompressionStream
461
462constructor TDecompressionStream.Create(Source: TStream);
463begin
464 inherited Create(Source);
465 FZRec.next_in := FBuffer;
466 FZRec.avail_in := 0;
467 DCheck(inflateInit_(FZRec, zlib_version, sizeof(FZRec)));
468end;
469
470destructor TDecompressionStream.Destroy;
471begin
472 inflateEnd(FZRec);
473 inherited Destroy;
474end;
475
476function TDecompressionStream.Read(var Buffer; Count: Longint): Longint;
477begin
478 FZRec.next_out := @Buffer;
479 FZRec.avail_out := Count;
480 if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
481 while (FZRec.avail_out > 0) do
482 begin
483 if FZRec.avail_in = 0 then
484 begin
485 FZRec.avail_in := FStrm.Read(FBuffer, sizeof(FBuffer));
486 if FZRec.avail_in = 0 then
487 begin
488 Result := Count - FZRec.avail_out;
489 Exit;
490 end;
491 FZRec.next_in := FBuffer;
492 FStrmPos := FStrm.Position;
493 Progress(Self);
494 end;
495 DCheck(inflate(FZRec, 0));
496 end;
497 Result := Count;
498end;
499
500function TDecompressionStream.Write(const Buffer; Count: Longint): Longint;
501begin
502 raise EDecompressionError.Create('Invalid stream operation');
503end;
504
505function TDecompressionStream.Seek(Offset: Longint; Origin: Word): Longint;
506var
507 I: Integer;
508 Buf: array [0..4095] of Char;
509begin
510 if (Offset = 0) and (Origin = soFromBeginning) then
511 begin
512 DCheck(inflateReset(FZRec));
513 FZRec.next_in := FBuffer;
514 FZRec.avail_in := 0;
515 FStrm.Position := 0;
516 FStrmPos := 0;
517 end
518 else if ( (Offset >= 0) and (Origin = soFromCurrent)) or
519 ( ((Offset - FZRec.total_out) > 0) and (Origin = soFromBeginning)) then
520 begin
521 if Origin = soFromBeginning then Dec(Offset, FZRec.total_out);
522 if Offset > 0 then
523 begin
524 for I := 1 to Offset div sizeof(Buf) do
525 ReadBuffer(Buf, sizeof(Buf));
526 ReadBuffer(Buf, Offset mod sizeof(Buf));
527 end;
528 end
529 else
530 raise EDecompressionError.Create('Invalid stream operation');
531 Result := FZRec.total_out;
532end;
533
534end.
diff --git a/contrib/delphi2/zlib32.bpr b/contrib/delphi2/zlib32.bpr
new file mode 100644
index 0000000..cabcec4
--- /dev/null
+++ b/contrib/delphi2/zlib32.bpr
@@ -0,0 +1,174 @@
1# ---------------------------------------------------------------------------
2!if !$d(BCB)
3BCB = $(MAKEDIR)\..
4!endif
5
6# ---------------------------------------------------------------------------
7# IDE SECTION
8# ---------------------------------------------------------------------------
9# The following section of the project makefile is managed by the BCB IDE.
10# It is recommended to use the IDE to change any of the values in this
11# section.
12# ---------------------------------------------------------------------------
13
14VERSION = BCB.03
15# ---------------------------------------------------------------------------
16PROJECT = zlib32.dll
17OBJFILES = zlib32.obj adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infblock.obj \
18 infcodes.obj inffast.obj inflate.obj inftrees.obj infutil.obj trees.obj \
19 uncompr.obj zutil.obj
20RESFILES =
21RESDEPEN = $(RESFILES)
22LIBFILES =
23LIBRARIES =
24SPARELIBS =
25DEFFILE =
26PACKAGES = VCLX35.bpi VCL35.bpi VCLDB35.bpi VCLDBX35.bpi ibsmp35.bpi bcbsmp35.bpi \
27 dclocx35.bpi QRPT35.bpi TEEUI35.bpi TEEDB35.bpi TEE35.bpi DSS35.bpi \
28 NMFAST35.bpi INETDB35.bpi INET35.bpi VCLMID35.bpi
29# ---------------------------------------------------------------------------
30PATHCPP = .;
31PATHASM = .;
32PATHPAS = .;
33PATHRC = .;
34DEBUGLIBPATH = $(BCB)\lib\debug
35RELEASELIBPATH = $(BCB)\lib\release
36# ---------------------------------------------------------------------------
37CFLAG1 = -WD -O2 -Ve -d -k- -vi -c -tWD
38CFLAG2 = -D_NO_VCL;ZLIB_DLL -I$(BCB)\include
39CFLAG3 = -ff -5
40PFLAGS = -D_NO_VCL;ZLIB_DLL -U$(BCB)\lib;$(RELEASELIBPATH) -I$(BCB)\include -$I- -v \
41 -JPHN -M
42RFLAGS = -D_NO_VCL;ZLIB_DLL -i$(BCB)\include
43AFLAGS = /i$(BCB)\include /d_NO_VCL /dZLIB_DLL /mx /w2 /zn
44LFLAGS = -L$(BCB)\lib;$(RELEASELIBPATH) -aa -Tpd -x -Gi
45IFLAGS = -Gn -g
46# ---------------------------------------------------------------------------
47ALLOBJ = c0d32.obj $(OBJFILES)
48ALLRES = $(RESFILES)
49ALLLIB = $(LIBFILES) import32.lib cw32mt.lib
50# ---------------------------------------------------------------------------
51!ifdef IDEOPTIONS
52
53[Version Info]
54IncludeVerInfo=0
55AutoIncBuild=0
56MajorVer=1
57MinorVer=0
58Release=0
59Build=0
60Debug=0
61PreRelease=0
62Special=0
63Private=0
64DLL=1
65Locale=1040
66CodePage=1252
67
68[Version Info Keys]
69CompanyName=
70FileDescription=DLL (GUI)
71FileVersion=1.0.0.0
72InternalName=
73LegalCopyright=
74LegalTrademarks=
75OriginalFilename=
76ProductName=
77ProductVersion=1.0.0.0
78Comments=
79
80[HistoryLists\hlIncludePath]
81Count=1
82Item0=$(BCB)\include
83
84[HistoryLists\hlLibraryPath]
85Count=1
86Item0=$(BCB)\lib
87
88[HistoryLists\hlConditionals]
89Count=1
90Item0=_NO_VCL;ZLIB_DLL
91
92[Debugging]
93DebugSourceDirs=
94
95[Parameters]
96RunParams=
97HostApplication=
98
99!endif
100
101# ---------------------------------------------------------------------------
102# MAKE SECTION
103# ---------------------------------------------------------------------------
104# This section of the project file is not used by the BCB IDE. It is for
105# the benefit of building from the command-line using the MAKE utility.
106# ---------------------------------------------------------------------------
107
108.autodepend
109# ---------------------------------------------------------------------------
110!if !$d(BCC32)
111BCC32 = bcc32
112!endif
113
114!if !$d(DCC32)
115DCC32 = dcc32
116!endif
117
118!if !$d(TASM32)
119TASM32 = tasm32
120!endif
121
122!if !$d(LINKER)
123LINKER = ilink32
124!endif
125
126!if !$d(BRCC32)
127BRCC32 = brcc32
128!endif
129# ---------------------------------------------------------------------------
130!if $d(PATHCPP)
131.PATH.CPP = $(PATHCPP)
132.PATH.C = $(PATHCPP)
133!endif
134
135!if $d(PATHPAS)
136.PATH.PAS = $(PATHPAS)
137!endif
138
139!if $d(PATHASM)
140.PATH.ASM = $(PATHASM)
141!endif
142
143!if $d(PATHRC)
144.PATH.RC = $(PATHRC)
145!endif
146# ---------------------------------------------------------------------------
147$(PROJECT): $(OBJFILES) $(RESDEPEN) $(DEFFILE)
148 $(BCB)\BIN\$(LINKER) @&&!
149 $(LFLAGS) $(IFLAGS) +
150 $(ALLOBJ), +
151 $(PROJECT),, +
152 $(ALLLIB), +
153 $(DEFFILE), +
154 $(ALLRES)
155!
156# ---------------------------------------------------------------------------
157.pas.hpp:
158 $(BCB)\BIN\$(DCC32) $(PFLAGS) {$< }
159
160.pas.obj:
161 $(BCB)\BIN\$(DCC32) $(PFLAGS) {$< }
162
163.cpp.obj:
164 $(BCB)\BIN\$(BCC32) $(CFLAG1) $(CFLAG2) $(CFLAG3) -n$(@D) {$< }
165
166.c.obj:
167 $(BCB)\BIN\$(BCC32) $(CFLAG1) $(CFLAG2) $(CFLAG3) -n$(@D) {$< }
168
169.asm.obj:
170 $(BCB)\BIN\$(TASM32) $(AFLAGS) $<, $@
171
172.rc.res:
173 $(BCB)\BIN\$(BRCC32) $(RFLAGS) -fo$@ $<
174# ---------------------------------------------------------------------------
diff --git a/contrib/delphi2/zlib32.cpp b/contrib/delphi2/zlib32.cpp
new file mode 100644
index 0000000..7372f6b
--- /dev/null
+++ b/contrib/delphi2/zlib32.cpp
@@ -0,0 +1,42 @@
1
2#include <windows.h>
3#pragma hdrstop
4#include <condefs.h>
5
6
7//---------------------------------------------------------------------------
8// Important note about DLL memory management in a VCL DLL:
9//
10//
11//
12// If your DLL uses VCL and exports any functions that pass VCL String objects
13// (or structs/classes containing nested Strings) as parameter or function
14// results, you will need to build both your DLL project and any EXE projects
15// that use your DLL with the dynamic RTL (the RTL DLL). This will change your
16// DLL and its calling EXE's to use BORLNDMM.DLL as their memory manager. In
17// these cases, the file BORLNDMM.DLL should be deployed along with your DLL
18// and the RTL DLL (CP3240MT.DLL). To avoid the requiring BORLNDMM.DLL in
19// these situations, pass string information using "char *" or ShortString
20// parameters and then link with the static RTL.
21//
22//---------------------------------------------------------------------------
23USEUNIT("adler32.c");
24USEUNIT("compress.c");
25USEUNIT("crc32.c");
26USEUNIT("deflate.c");
27USEUNIT("gzio.c");
28USEUNIT("infblock.c");
29USEUNIT("infcodes.c");
30USEUNIT("inffast.c");
31USEUNIT("inflate.c");
32USEUNIT("inftrees.c");
33USEUNIT("infutil.c");
34USEUNIT("trees.c");
35USEUNIT("uncompr.c");
36USEUNIT("zutil.c");
37//---------------------------------------------------------------------------
38#pragma argsused
39int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
40{
41 return 1;
42}
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c
index 78a8473..ff71a47 100644
--- a/contrib/minizip/unzip.c
+++ b/contrib/minizip/unzip.c
@@ -315,7 +315,7 @@ local uLong unzlocal_SearchCentralDir(fin)
315 if (fread(buf,(uInt)uReadSize,1,fin)!=1) 315 if (fread(buf,(uInt)uReadSize,1,fin)!=1)
316 break; 316 break;
317 317
318 for (i=0;i<(int)uReadSize-3;i++) 318 for (i=(int)uReadSize-3; (i--)>0;)
319 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 319 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
320 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) 320 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
321 { 321 {
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
index ddb2334..0cae64a 100644
--- a/contrib/minizip/zip.c
+++ b/contrib/minizip/zip.c
@@ -242,6 +242,8 @@ local int write_datablock(fout,ll)
242 Outputs a long in LSB order to the given file 242 Outputs a long in LSB order to the given file
243 nbByte == 1, 2 or 4 (byte, short or long) 243 nbByte == 1, 2 or 4 (byte, short or long)
244*/ 244*/
245
246local int ziplocal_putValue OF((FILE *file, uLong x, int nbByte));
245local int ziplocal_putValue (file, x, nbByte) 247local int ziplocal_putValue (file, x, nbByte)
246 FILE *file; 248 FILE *file;
247 uLong x; 249 uLong x;
@@ -259,7 +261,7 @@ local int ziplocal_putValue (file, x, nbByte)
259 return ZIP_OK; 261 return ZIP_OK;
260} 262}
261 263
262 264local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte));
263local void ziplocal_putValue_inmemory (dest, x, nbByte) 265local void ziplocal_putValue_inmemory (dest, x, nbByte)
264 void* dest; 266 void* dest;
265 uLong x; 267 uLong x;
@@ -390,34 +392,34 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
390 zi->ci.pos_local_header = ftell(zi->filezip); 392 zi->ci.pos_local_header = ftell(zi->filezip);
391 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + 393 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
392 size_extrafield_global + size_comment; 394 size_extrafield_global + size_comment;
393 zi->ci.central_header = (char*)ALLOC(zi->ci.size_centralheader); 395 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
394 396
395 ziplocal_putValue_inmemory(zi->ci.central_header,CENTRALHEADERMAGIC,4); 397 ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
396 /* version info */ 398 /* version info */
397 ziplocal_putValue_inmemory(zi->ci.central_header+4,VERSIONMADEBY,2); 399 ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2);
398 ziplocal_putValue_inmemory(zi->ci.central_header+6,20,2); 400 ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
399 ziplocal_putValue_inmemory(zi->ci.central_header+8,zi->ci.flag,2); 401 ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
400 ziplocal_putValue_inmemory(zi->ci.central_header+10,zi->ci.method,2); 402 ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
401 ziplocal_putValue_inmemory(zi->ci.central_header+12,zi->ci.dosDate,4); 403 ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
402 ziplocal_putValue_inmemory(zi->ci.central_header+16,0,4); /*crc*/ 404 ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
403 ziplocal_putValue_inmemory(zi->ci.central_header+20,0,4); /*compr size*/ 405 ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
404 ziplocal_putValue_inmemory(zi->ci.central_header+24,0,4); /*uncompr size*/ 406 ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
405 ziplocal_putValue_inmemory(zi->ci.central_header+28,size_filename,2); 407 ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
406 ziplocal_putValue_inmemory(zi->ci.central_header+30,size_extrafield_global,2); 408 ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
407 ziplocal_putValue_inmemory(zi->ci.central_header+32,size_comment,2); 409 ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
408 ziplocal_putValue_inmemory(zi->ci.central_header+34,0,2); /*disk nm start*/ 410 ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
409 411
410 if (zipfi==NULL) 412 if (zipfi==NULL)
411 ziplocal_putValue_inmemory(zi->ci.central_header+36,0,2); 413 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
412 else 414 else
413 ziplocal_putValue_inmemory(zi->ci.central_header+36,zipfi->internal_fa,2); 415 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
414 416
415 if (zipfi==NULL) 417 if (zipfi==NULL)
416 ziplocal_putValue_inmemory(zi->ci.central_header+38,0,4); 418 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
417 else 419 else
418 ziplocal_putValue_inmemory(zi->ci.central_header+38,zipfi->external_fa,4); 420 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
419 421
420 ziplocal_putValue_inmemory(zi->ci.central_header+42,zi->ci.pos_local_header,4); 422 ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header,4);
421 423
422 for (i=0;i<size_filename;i++) 424 for (i=0;i<size_filename;i++)
423 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); 425 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
@@ -433,25 +435,25 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
433 return ZIP_INTERNALERROR; 435 return ZIP_INTERNALERROR;
434 436
435 /* write the local header */ 437 /* write the local header */
436 err = ziplocal_putValue(zi->filezip,LOCALHEADERMAGIC,4); 438 err = ziplocal_putValue(zi->filezip,(uLong)LOCALHEADERMAGIC,4);
437 439
438 if (err==ZIP_OK) 440 if (err==ZIP_OK)
439 err = ziplocal_putValue(zi->filezip,20,2);/* version needed to extract */ 441 err = ziplocal_putValue(zi->filezip,(uLong)20,2);/* version needed to extract */
440 if (err==ZIP_OK) 442 if (err==ZIP_OK)
441 err = ziplocal_putValue(zi->filezip,zi->ci.flag,2); 443 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.flag,2);
442 444
443 if (err==ZIP_OK) 445 if (err==ZIP_OK)
444 err = ziplocal_putValue(zi->filezip,zi->ci.method,2); 446 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.method,2);
445 447
446 if (err==ZIP_OK) 448 if (err==ZIP_OK)
447 err = ziplocal_putValue(zi->filezip,zi->ci.dosDate,4); 449 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.dosDate,4);
448 450
449 if (err==ZIP_OK) 451 if (err==ZIP_OK)
450 err = ziplocal_putValue(zi->filezip,0,4); /* crc 32, unknown */ 452 err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* crc 32, unknown */
451 if (err==ZIP_OK) 453 if (err==ZIP_OK)
452 err = ziplocal_putValue(zi->filezip,0,4); /* compressed size, unknown */ 454 err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* compressed size, unknown */
453 if (err==ZIP_OK) 455 if (err==ZIP_OK)
454 err = ziplocal_putValue(zi->filezip,0,4); /* uncompressed size, unknown */ 456 err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* uncompressed size, unknown */
455 457
456 if (err==ZIP_OK) 458 if (err==ZIP_OK)
457 err = ziplocal_putValue(zi->filezip,(uLong)size_filename,2); 459 err = ziplocal_putValue(zi->filezip,(uLong)size_filename,2);
@@ -481,7 +483,7 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
481 zi->ci.stream.opaque = (voidpf)0; 483 zi->ci.stream.opaque = (voidpf)0;
482 484
483 err = deflateInit2(&zi->ci.stream, level, 485 err = deflateInit2(&zi->ci.stream, level,
484 Z_DEFLATED, -MAX_WBITS, /*DEF_MEM_LEVEL*/8, 0); 486 Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0);
485 487
486 if (err==Z_OK) 488 if (err==Z_OK)
487 zi->ci.stream_initialised = 1; 489 zi->ci.stream_initialised = 1;
@@ -528,7 +530,7 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
528 { 530 {
529 uLong uTotalOutBefore = zi->ci.stream.total_out; 531 uLong uTotalOutBefore = zi->ci.stream.total_out;
530 err=deflate(&zi->ci.stream, Z_NO_FLUSH); 532 err=deflate(&zi->ci.stream, Z_NO_FLUSH);
531 zi->ci.pos_in_buffered_data += zi->ci.stream.total_out - uTotalOutBefore ; 533 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
532 534
533 } 535 }
534 else 536 else
@@ -585,7 +587,7 @@ extern int ZEXPORT zipCloseFileInZip (file)
585 } 587 }
586 uTotalOutBefore = zi->ci.stream.total_out; 588 uTotalOutBefore = zi->ci.stream.total_out;
587 err=deflate(&zi->ci.stream, Z_FINISH); 589 err=deflate(&zi->ci.stream, Z_FINISH);
588 zi->ci.pos_in_buffered_data += zi->ci.stream.total_out - uTotalOutBefore ; 590 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
589 } 591 }
590 592
591 if (err==Z_STREAM_END) 593 if (err==Z_STREAM_END)
@@ -602,11 +604,11 @@ extern int ZEXPORT zipCloseFileInZip (file)
602 zi->ci.stream_initialised = 0; 604 zi->ci.stream_initialised = 0;
603 } 605 }
604 606
605 ziplocal_putValue_inmemory(zi->ci.central_header+16,zi->ci.crc32,4); /*crc*/ 607 ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)zi->ci.crc32,4); /*crc*/
606 ziplocal_putValue_inmemory(zi->ci.central_header+20, 608 ziplocal_putValue_inmemory(zi->ci.central_header+20,
607 zi->ci.stream.total_out,4); /*compr size*/ 609 (uLong)zi->ci.stream.total_out,4); /*compr size*/
608 ziplocal_putValue_inmemory(zi->ci.central_header+24, 610 ziplocal_putValue_inmemory(zi->ci.central_header+24,
609 zi->ci.stream.total_in,4); /*uncompr size*/ 611 (uLong)zi->ci.stream.total_in,4); /*uncompr size*/
610 612
611 if (err==ZIP_OK) 613 if (err==ZIP_OK)
612 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, 614 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,
@@ -621,13 +623,13 @@ extern int ZEXPORT zipCloseFileInZip (file)
621 err = ZIP_ERRNO; 623 err = ZIP_ERRNO;
622 624
623 if (err==ZIP_OK) 625 if (err==ZIP_OK)
624 err = ziplocal_putValue(zi->filezip,zi->ci.crc32,4); /* crc 32, unknown */ 626 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.crc32,4); /* crc 32, unknown */
625 627
626 if (err==ZIP_OK) /* compressed size, unknown */ 628 if (err==ZIP_OK) /* compressed size, unknown */
627 err = ziplocal_putValue(zi->filezip,zi->ci.stream.total_out,4); 629 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_out,4);
628 630
629 if (err==ZIP_OK) /* uncompressed size, unknown */ 631 if (err==ZIP_OK) /* uncompressed size, unknown */
630 err = ziplocal_putValue(zi->filezip,zi->ci.stream.total_in,4); 632 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_in,4);
631 633
632 if (fseek(zi->filezip, 634 if (fseek(zi->filezip,
633 cur_pos_inzip,SEEK_SET)!=0) 635 cur_pos_inzip,SEEK_SET)!=0)
@@ -682,26 +684,26 @@ extern int ZEXPORT zipClose (file, global_comment)
682 free_datablock(zi->central_dir.first_block); 684 free_datablock(zi->central_dir.first_block);
683 685
684 if (err==ZIP_OK) /* Magic End */ 686 if (err==ZIP_OK) /* Magic End */
685 err = ziplocal_putValue(zi->filezip,ENDHEADERMAGIC,4); 687 err = ziplocal_putValue(zi->filezip,(uLong)ENDHEADERMAGIC,4);
686 688
687 if (err==ZIP_OK) /* number of this disk */ 689 if (err==ZIP_OK) /* number of this disk */
688 err = ziplocal_putValue(zi->filezip,0,2); 690 err = ziplocal_putValue(zi->filezip,(uLong)0,2);
689 691
690 if (err==ZIP_OK) /* number of the disk with the start of the central directory */ 692 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
691 err = ziplocal_putValue(zi->filezip,0,2); 693 err = ziplocal_putValue(zi->filezip,(uLong)0,2);
692 694
693 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ 695 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
694 err = ziplocal_putValue(zi->filezip,zi->number_entry,2); 696 err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2);
695 697
696 if (err==ZIP_OK) /* total number of entries in the central dir */ 698 if (err==ZIP_OK) /* total number of entries in the central dir */
697 err = ziplocal_putValue(zi->filezip,zi->number_entry,2); 699 err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2);
698 700
699 if (err==ZIP_OK) /* size of the central directory */ 701 if (err==ZIP_OK) /* size of the central directory */
700 err = ziplocal_putValue(zi->filezip,size_centraldir,4); 702 err = ziplocal_putValue(zi->filezip,(uLong)size_centraldir,4);
701 703
702 if (err==ZIP_OK) /* offset of start of central directory with respect to the 704 if (err==ZIP_OK) /* offset of start of central directory with respect to the
703 starting disk number */ 705 starting disk number */
704 err = ziplocal_putValue(zi->filezip,centraldir_pos_inzip ,4); 706 err = ziplocal_putValue(zi->filezip,(uLong)centraldir_pos_inzip ,4);
705 707
706 if (err==ZIP_OK) /* zipfile comment length */ 708 if (err==ZIP_OK) /* zipfile comment length */
707 err = ziplocal_putValue(zi->filezip,(uLong)size_global_comment,2); 709 err = ziplocal_putValue(zi->filezip,(uLong)size_global_comment,2);
diff --git a/contrib/untgz/untgz.c b/contrib/untgz/untgz.c
index 6fa9a5d..4a431ff 100644
--- a/contrib/untgz/untgz.c
+++ b/contrib/untgz/untgz.c
@@ -9,7 +9,6 @@
9#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h> 10#include <string.h>
11#include <time.h> 11#include <time.h>
12#include <utime.h>
13#include <errno.h> 12#include <errno.h>
14#include <fcntl.h> 13#include <fcntl.h>
15#ifdef unix 14#ifdef unix
@@ -21,6 +20,23 @@
21 20
22#include "zlib.h" 21#include "zlib.h"
23 22
23#ifdef WIN32
24# ifndef F_OK
25# define F_OK (0)
26# endif
27# ifdef _MSC_VER
28# define mkdir(dirname,mode) _mkdir(dirname)
29# define strdup(str) _strdup(str)
30# define unlink(fn) _unlink(fn)
31# define access(path,mode) _access(path,mode)
32# else
33# define mkdir(dirname,mode) _mkdir(dirname)
34# endif
35#else
36# include <utime.h>
37#endif
38
39
24/* Values used in typeflag field. */ 40/* Values used in typeflag field. */
25 41
26#define REGTYPE '0' /* regular file */ 42#define REGTYPE '0' /* regular file */
@@ -83,7 +99,7 @@ char *prog;
83 99
84/* This will give a benign warning */ 100/* This will give a benign warning */
85 101
86static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", NULL }; 102static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", ".tar", NULL };
87 103
88/* Return the real name of the TGZ archive */ 104/* Return the real name of the TGZ archive */
89/* or NULL if it does not exist. */ 105/* or NULL if it does not exist. */
@@ -272,14 +288,6 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
272 if (len < 0) 288 if (len < 0)
273 error (gzerror(in, &err)); 289 error (gzerror(in, &err));
274 /* 290 /*
275 * if we met the end of the tar
276 * or the end-of-tar block,
277 * we are done
278 */
279 if ((len == 0) || (buffer.header.name[0]== 0))
280 break;
281
282 /*
283 * Always expect complete blocks to process 291 * Always expect complete blocks to process
284 * the tar information. 292 * the tar information.
285 */ 293 */
@@ -291,6 +299,13 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
291 */ 299 */
292 if (getheader == 1) 300 if (getheader == 1)
293 { 301 {
302 /*
303 * if we met the end of the tar
304 * or the end-of-tar block,
305 * we are done
306 */
307 if ((len == 0) || (buffer.header.name[0]== 0)) break;
308
294 tartime = (time_t)getoct(buffer.header.mtime,12); 309 tartime = (time_t)getoct(buffer.header.mtime,12);
295 strcpy(fname,buffer.header.name); 310 strcpy(fname,buffer.header.name);
296 311
@@ -360,6 +375,34 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
360 getheader = 1; 375 getheader = 1;
361 if ((action == TGZ_EXTRACT) && (outfile != NULL)) 376 if ((action == TGZ_EXTRACT) && (outfile != NULL))
362 { 377 {
378#ifdef WIN32
379 HANDLE hFile;
380 FILETIME ftm,ftLocal;
381 SYSTEMTIME st;
382 struct tm localt;
383
384 fclose(outfile);
385
386 localt = *localtime(&tartime);
387
388 hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE,
389 0, NULL, OPEN_EXISTING, 0, NULL);
390
391 st.wYear = (WORD)localt.tm_year+1900;
392 st.wMonth = (WORD)localt.tm_mon;
393 st.wDayOfWeek = (WORD)localt.tm_wday;
394 st.wDay = (WORD)localt.tm_mday;
395 st.wHour = (WORD)localt.tm_hour;
396 st.wMinute = (WORD)localt.tm_min;
397 st.wSecond = (WORD)localt.tm_sec;
398 st.wMilliseconds = 0;
399 SystemTimeToFileTime(&st,&ftLocal);
400 LocalFileTimeToFileTime(&ftLocal,&ftm);
401 SetFileTime(hFile,&ftm,NULL,&ftm);
402 CloseHandle(hFile);
403
404 outfile = NULL;
405#else
363 struct utimbuf settime; 406 struct utimbuf settime;
364 407
365 settime.actime = settime.modtime = tartime; 408 settime.actime = settime.modtime = tartime;
@@ -367,6 +410,7 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
367 fclose(outfile); 410 fclose(outfile);
368 outfile = NULL; 411 outfile = NULL;
369 utime(fname,&settime); 412 utime(fname,&settime);
413#endif
370 } 414 }
371 } 415 }
372 } 416 }
diff --git a/contrib/visual-basic.txt b/contrib/visual-basic.txt
index 18aa084..10fb44b 100644
--- a/contrib/visual-basic.txt
+++ b/contrib/visual-basic.txt
@@ -1,5 +1,17 @@
1See below some functions declarations for Visual Basic.
2
3Frequently Asked Question:
4
5Q: Each time I use the compress function I get the -5 error (not enough
6 room in the output buffer).
7
8A: Make sure that the length of the compressed buffer is passed by
9 reference ("as any"), not by value ("as long"). Also check that
10 before the call of compress this length is equal to the total size of
11 the compressed buffer and not zero.
12
13
1From: "Jon Caruana" <jon-net@usa.net> 14From: "Jon Caruana" <jon-net@usa.net>
2To: "Jean-loup Gailly" <gzip@prep.ai.mit.edu>
3Subject: Re: How to port zlib declares to vb? 15Subject: Re: How to port zlib declares to vb?
4Date: Mon, 28 Oct 1996 18:33:03 -0600 16Date: Mon, 28 Oct 1996 18:33:03 -0600
5 17