diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:26:40 -0700 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:26:40 -0700 |
| commit | f6194ef39af5864f792412460c354cc339dde7d1 (patch) | |
| tree | 5ea1e6849128e9b2194c66ee3d82afa36b4ac07c /contrib | |
| parent | 639be997883d9016baaf46017a2802b2ce1698bd (diff) | |
| download | zlib-1.2.3.4.tar.gz zlib-1.2.3.4.tar.bz2 zlib-1.2.3.4.zip | |
zlib 1.2.3.4v1.2.3.4
Diffstat (limited to 'contrib')
| -rw-r--r-- | contrib/README.contrib | 4 | ||||
| -rw-r--r-- | contrib/amd64/amd64-match.S | 357 | ||||
| -rw-r--r-- | contrib/infback9/infback9.c | 13 | ||||
| -rw-r--r-- | contrib/infback9/inftree9.c | 21 | ||||
| -rw-r--r-- | contrib/infback9/inftree9.h | 24 | ||||
| -rw-r--r-- | contrib/nintendods/Makefile | 126 | ||||
| -rw-r--r-- | contrib/nintendods/README | 5 | ||||
| -rwxr-xr-x | contrib/puff/puff | bin | 0 -> 17344 bytes | |||
| -rw-r--r-- | contrib/puff/puff.c | 193 | ||||
| -rw-r--r-- | contrib/puff/puff.h | 4 | ||||
| -rw-r--r-- | contrib/vstudio/vc7/zlib.rc | 6 |
11 files changed, 683 insertions, 70 deletions
diff --git a/contrib/README.contrib b/contrib/README.contrib index 20afc62..f9c1665 100644 --- a/contrib/README.contrib +++ b/contrib/README.contrib | |||
| @@ -8,6 +8,10 @@ ada/ by Dmitriy Anisimkov <anisimkov@yahoo.com> | |||
| 8 | Support for Ada | 8 | Support for Ada |
| 9 | See http://zlib-ada.sourceforge.net/ | 9 | See http://zlib-ada.sourceforge.net/ |
| 10 | 10 | ||
| 11 | amd64/ by Mikhail Teterin <mi@ALDAN.algebra.com> | ||
| 12 | asm code for AMD64 | ||
| 13 | See patch at http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/96393 | ||
| 14 | |||
| 11 | asm586/ | 15 | asm586/ |
| 12 | asm686/ by Brian Raiter <breadbox@muppetlabs.com> | 16 | asm686/ by Brian Raiter <breadbox@muppetlabs.com> |
| 13 | asm code for Pentium and PPro/PII, using the AT&T (GNU as) syntax | 17 | asm code for Pentium and PPro/PII, using the AT&T (GNU as) syntax |
diff --git a/contrib/amd64/amd64-match.S b/contrib/amd64/amd64-match.S new file mode 100644 index 0000000..b3bf1ac --- /dev/null +++ b/contrib/amd64/amd64-match.S | |||
| @@ -0,0 +1,357 @@ | |||
| 1 | /* | ||
| 2 | * match.S -- optimized version of longest_match() | ||
| 3 | * based on the similar work by Gilles Vollant, and Brian Raiter, written 1998 | ||
| 4 | * | ||
| 5 | * This is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the BSD License. Use by owners of Che Guevarra | ||
| 7 | * parafernalia is prohibited, where possible, and highly discouraged | ||
| 8 | * elsewhere. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #ifndef NO_UNDERLINE | ||
| 12 | # define match_init _match_init | ||
| 13 | # define longest_match _longest_match | ||
| 14 | #endif | ||
| 15 | |||
| 16 | #define scanend ebx | ||
| 17 | #define scanendw bx | ||
| 18 | #define chainlenwmask edx /* high word: current chain len low word: s->wmask */ | ||
| 19 | #define curmatch rsi | ||
| 20 | #define curmatchd esi | ||
| 21 | #define windowbestlen r8 | ||
| 22 | #define scanalign r9 | ||
| 23 | #define scanalignd r9d | ||
| 24 | #define window r10 | ||
| 25 | #define bestlen r11 | ||
| 26 | #define bestlend r11d | ||
| 27 | #define scanstart r12d | ||
| 28 | #define scanstartw r12w | ||
| 29 | #define scan r13 | ||
| 30 | #define nicematch r14d | ||
| 31 | #define limit r15 | ||
| 32 | #define limitd r15d | ||
| 33 | #define prev rcx | ||
| 34 | |||
| 35 | /* | ||
| 36 | * The 258 is a "magic number, not a parameter -- changing it | ||
| 37 | * breaks the hell loose | ||
| 38 | */ | ||
| 39 | #define MAX_MATCH (258) | ||
| 40 | #define MIN_MATCH (3) | ||
| 41 | #define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) | ||
| 42 | #define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7) | ||
| 43 | |||
| 44 | /* stack frame offsets */ | ||
| 45 | #define LocalVarsSize (112) | ||
| 46 | #define _chainlenwmask ( 8-LocalVarsSize)(%rsp) | ||
| 47 | #define _windowbestlen (16-LocalVarsSize)(%rsp) | ||
| 48 | #define save_r14 (24-LocalVarsSize)(%rsp) | ||
| 49 | #define save_rsi (32-LocalVarsSize)(%rsp) | ||
| 50 | #define save_rbx (40-LocalVarsSize)(%rsp) | ||
| 51 | #define save_r12 (56-LocalVarsSize)(%rsp) | ||
| 52 | #define save_r13 (64-LocalVarsSize)(%rsp) | ||
| 53 | #define save_r15 (80-LocalVarsSize)(%rsp) | ||
| 54 | |||
| 55 | /* | ||
| 56 | * On AMD64 the first argument of a function (in our case -- the pointer to | ||
| 57 | * deflate_state structure) is passed in %rdi, hence our offsets below are | ||
| 58 | * all off of that. | ||
| 59 | */ | ||
| 60 | #ifndef STRUCT_OFFSET | ||
| 61 | # define STRUCT_OFFSET (0) | ||
| 62 | #endif | ||
| 63 | #define dsWSize ( 56 + STRUCT_OFFSET)(%rdi) | ||
| 64 | #define dsWMask ( 64 + STRUCT_OFFSET)(%rdi) | ||
| 65 | #define dsWindow ( 72 + STRUCT_OFFSET)(%rdi) | ||
| 66 | #define dsPrev ( 88 + STRUCT_OFFSET)(%rdi) | ||
| 67 | #define dsMatchLen (136 + STRUCT_OFFSET)(%rdi) | ||
| 68 | #define dsPrevMatch (140 + STRUCT_OFFSET)(%rdi) | ||
| 69 | #define dsStrStart (148 + STRUCT_OFFSET)(%rdi) | ||
| 70 | #define dsMatchStart (152 + STRUCT_OFFSET)(%rdi) | ||
| 71 | #define dsLookahead (156 + STRUCT_OFFSET)(%rdi) | ||
| 72 | #define dsPrevLen (160 + STRUCT_OFFSET)(%rdi) | ||
| 73 | #define dsMaxChainLen (164 + STRUCT_OFFSET)(%rdi) | ||
| 74 | #define dsGoodMatch (180 + STRUCT_OFFSET)(%rdi) | ||
| 75 | #define dsNiceMatch (184 + STRUCT_OFFSET)(%rdi) | ||
| 76 | |||
| 77 | .globl match_init, longest_match | ||
| 78 | |||
| 79 | .text | ||
| 80 | |||
| 81 | /* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */ | ||
| 82 | |||
| 83 | longest_match: | ||
| 84 | /* | ||
| 85 | * Retrieve the function arguments. %curmatch will hold cur_match | ||
| 86 | * throughout the entire function (passed via rsi on amd64). | ||
| 87 | * rdi will hold the pointer to the deflate_state (first arg on amd64) | ||
| 88 | */ | ||
| 89 | mov %rsi, save_rsi | ||
| 90 | mov %rbx, save_rbx | ||
| 91 | mov %r12, save_r12 | ||
| 92 | mov %r13, save_r13 | ||
| 93 | mov %r14, save_r14 | ||
| 94 | mov %r15, save_r15 | ||
| 95 | |||
| 96 | /* uInt wmask = s->w_mask; */ | ||
| 97 | /* unsigned chain_length = s->max_chain_length; */ | ||
| 98 | /* if (s->prev_length >= s->good_match) { */ | ||
| 99 | /* chain_length >>= 2; */ | ||
| 100 | /* } */ | ||
| 101 | |||
| 102 | movl dsPrevLen, %eax | ||
| 103 | movl dsGoodMatch, %ebx | ||
| 104 | cmpl %ebx, %eax | ||
| 105 | movl dsWMask, %eax | ||
| 106 | movl dsMaxChainLen, %chainlenwmask | ||
| 107 | jl LastMatchGood | ||
| 108 | shrl $2, %chainlenwmask | ||
| 109 | LastMatchGood: | ||
| 110 | |||
| 111 | /* chainlen is decremented once beforehand so that the function can */ | ||
| 112 | /* use the sign flag instead of the zero flag for the exit test. */ | ||
| 113 | /* It is then shifted into the high word, to make room for the wmask */ | ||
| 114 | /* value, which it will always accompany. */ | ||
| 115 | |||
| 116 | decl %chainlenwmask | ||
| 117 | shll $16, %chainlenwmask | ||
| 118 | orl %eax, %chainlenwmask | ||
| 119 | |||
| 120 | /* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */ | ||
| 121 | |||
| 122 | movl dsNiceMatch, %eax | ||
| 123 | movl dsLookahead, %ebx | ||
| 124 | cmpl %eax, %ebx | ||
| 125 | jl LookaheadLess | ||
| 126 | movl %eax, %ebx | ||
| 127 | LookaheadLess: movl %ebx, %nicematch | ||
| 128 | |||
| 129 | /* register Bytef *scan = s->window + s->strstart; */ | ||
| 130 | |||
| 131 | mov dsWindow, %window | ||
| 132 | movl dsStrStart, %limitd | ||
| 133 | lea (%limit, %window), %scan | ||
| 134 | |||
| 135 | /* Determine how many bytes the scan ptr is off from being */ | ||
| 136 | /* dword-aligned. */ | ||
| 137 | |||
| 138 | mov %scan, %scanalign | ||
| 139 | negl %scanalignd | ||
| 140 | andl $3, %scanalignd | ||
| 141 | |||
| 142 | /* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */ | ||
| 143 | /* s->strstart - (IPos)MAX_DIST(s) : NIL; */ | ||
| 144 | |||
| 145 | movl dsWSize, %eax | ||
| 146 | subl $MIN_LOOKAHEAD, %eax | ||
| 147 | xorl %ecx, %ecx | ||
| 148 | subl %eax, %limitd | ||
| 149 | cmovng %ecx, %limitd | ||
| 150 | |||
| 151 | /* int best_len = s->prev_length; */ | ||
| 152 | |||
| 153 | movl dsPrevLen, %bestlend | ||
| 154 | |||
| 155 | /* Store the sum of s->window + best_len in %windowbestlen locally, and in memory. */ | ||
| 156 | |||
| 157 | lea (%window, %bestlen), %windowbestlen | ||
| 158 | mov %windowbestlen, _windowbestlen | ||
| 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 (%scan), %scanstart | ||
| 165 | movzwl -1(%scan, %bestlen), %scanend | ||
| 166 | mov dsPrev, %prev | ||
| 167 | |||
| 168 | /* Jump into the main loop. */ | ||
| 169 | |||
| 170 | movl %chainlenwmask, _chainlenwmask | ||
| 171 | jmp LoopEntry | ||
| 172 | |||
| 173 | .balign 16 | ||
| 174 | |||
| 175 | /* do { | ||
| 176 | * match = s->window + cur_match; | ||
| 177 | * if (*(ushf*)(match+best_len-1) != scan_end || | ||
| 178 | * *(ushf*)match != scan_start) continue; | ||
| 179 | * [...] | ||
| 180 | * } while ((cur_match = prev[cur_match & wmask]) > limit | ||
| 181 | * && --chain_length != 0); | ||
| 182 | * | ||
| 183 | * Here is the inner loop of the function. The function will spend the | ||
| 184 | * majority of its time in this loop, and majority of that time will | ||
| 185 | * be spent in the first ten instructions. | ||
| 186 | */ | ||
| 187 | LookupLoop: | ||
| 188 | andl %chainlenwmask, %curmatchd | ||
| 189 | movzwl (%prev, %curmatch, 2), %curmatchd | ||
| 190 | cmpl %limitd, %curmatchd | ||
| 191 | jbe LeaveNow | ||
| 192 | subl $0x00010000, %chainlenwmask | ||
| 193 | js LeaveNow | ||
| 194 | LoopEntry: cmpw -1(%windowbestlen, %curmatch), %scanendw | ||
| 195 | jne LookupLoop | ||
| 196 | cmpw %scanstartw, (%window, %curmatch) | ||
| 197 | jne LookupLoop | ||
| 198 | |||
| 199 | /* Store the current value of chainlen. */ | ||
| 200 | movl %chainlenwmask, _chainlenwmask | ||
| 201 | |||
| 202 | /* %scan is the string under scrutiny, and %prev to the string we */ | ||
| 203 | /* are hoping to match it up with. In actuality, %esi and %edi are */ | ||
| 204 | /* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */ | ||
| 205 | /* initialized to -(MAX_MATCH_8 - scanalign). */ | ||
| 206 | |||
| 207 | mov $(-MAX_MATCH_8), %rdx | ||
| 208 | lea (%curmatch, %window), %windowbestlen | ||
| 209 | lea MAX_MATCH_8(%windowbestlen, %scanalign), %windowbestlen | ||
| 210 | lea MAX_MATCH_8(%scan, %scanalign), %prev | ||
| 211 | |||
| 212 | /* the prefetching below makes very little difference... */ | ||
| 213 | prefetcht1 (%windowbestlen, %rdx) | ||
| 214 | prefetcht1 (%prev, %rdx) | ||
| 215 | |||
| 216 | /* | ||
| 217 | * Test the strings for equality, 8 bytes at a time. At the end, | ||
| 218 | * adjust %rdx so that it is offset to the exact byte that mismatched. | ||
| 219 | * | ||
| 220 | * It should be confessed that this loop usually does not represent | ||
| 221 | * much of the total running time. Replacing it with a more | ||
| 222 | * straightforward "rep cmpsb" would not drastically degrade | ||
| 223 | * performance -- unrolling it, for example, makes no difference. | ||
| 224 | */ | ||
| 225 | #undef USE_SSE /* works, but is 6-7% slower, than non-SSE... */ | ||
| 226 | LoopCmps: | ||
| 227 | #ifdef USE_SSE | ||
| 228 | /* Preload the SSE registers */ | ||
| 229 | movdqu (%windowbestlen, %rdx), %xmm1 | ||
| 230 | movdqu (%prev, %rdx), %xmm2 | ||
| 231 | pcmpeqb %xmm2, %xmm1 | ||
| 232 | movdqu 16(%windowbestlen, %rdx), %xmm3 | ||
| 233 | movdqu 16(%prev, %rdx), %xmm4 | ||
| 234 | pcmpeqb %xmm4, %xmm3 | ||
| 235 | movdqu 32(%windowbestlen, %rdx), %xmm5 | ||
| 236 | movdqu 32(%prev, %rdx), %xmm6 | ||
| 237 | pcmpeqb %xmm6, %xmm5 | ||
| 238 | movdqu 48(%windowbestlen, %rdx), %xmm7 | ||
| 239 | movdqu 48(%prev, %rdx), %xmm8 | ||
| 240 | pcmpeqb %xmm8, %xmm7 | ||
| 241 | |||
| 242 | /* Check the comparisions' results */ | ||
| 243 | pmovmskb %xmm1, %rax | ||
| 244 | notw %ax | ||
| 245 | bsfw %ax, %ax | ||
| 246 | jnz LeaveLoopCmps | ||
| 247 | add $16, %rdx | ||
| 248 | pmovmskb %xmm3, %rax | ||
| 249 | notw %ax | ||
| 250 | bsfw %ax, %ax | ||
| 251 | jnz LeaveLoopCmps | ||
| 252 | add $16, %rdx | ||
| 253 | pmovmskb %xmm5, %rax | ||
| 254 | notw %ax | ||
| 255 | bsfw %ax, %ax | ||
| 256 | jnz LeaveLoopCmps | ||
| 257 | add $16, %rdx | ||
| 258 | pmovmskb %xmm7, %rax | ||
| 259 | notw %ax | ||
| 260 | bsfw %ax, %ax | ||
| 261 | jnz LeaveLoopCmps | ||
| 262 | add $16, %rdx | ||
| 263 | jmp LoopCmps | ||
| 264 | LeaveLoopCmps: add %rax, %rdx | ||
| 265 | #else | ||
| 266 | mov (%windowbestlen, %rdx), %rax | ||
| 267 | xor (%prev, %rdx), %rax | ||
| 268 | jnz LeaveLoopCmps | ||
| 269 | add $8, %rdx | ||
| 270 | jnz LoopCmps | ||
| 271 | jmp LenMaximum | ||
| 272 | # if 0 | ||
| 273 | /* | ||
| 274 | * This three-liner is tantalizingly simple, but bsf is a slow instruction, | ||
| 275 | * and the complicated alternative down below is quite a bit faster. Sad... | ||
| 276 | */ | ||
| 277 | LeaveLoopCmps: bsf %rax, %rax /* find the first non-zero bit */ | ||
| 278 | shrl $3, %eax /* divide by 8 to get the byte */ | ||
| 279 | add %rax, %rdx | ||
| 280 | # else | ||
| 281 | LeaveLoopCmps: testl $0xFFFFFFFF, %eax /* Check the first 4 bytes */ | ||
| 282 | jnz Check16 | ||
| 283 | add $4, %rdx | ||
| 284 | shr $32, %rax | ||
| 285 | Check16: testw $0xFFFF, %ax | ||
| 286 | jnz LenLower | ||
| 287 | add $2, %rdx | ||
| 288 | shrl $16, %eax | ||
| 289 | LenLower: subb $1, %al | ||
| 290 | adc $0, %rdx | ||
| 291 | # endif | ||
| 292 | #endif | ||
| 293 | |||
| 294 | /* Calculate the length of the match. If it is longer than MAX_MATCH, */ | ||
| 295 | /* then automatically accept it as the best possible match and leave. */ | ||
| 296 | |||
| 297 | lea (%prev, %rdx), %rax | ||
| 298 | sub %scan, %rax | ||
| 299 | cmpl $MAX_MATCH, %eax | ||
| 300 | jge LenMaximum | ||
| 301 | |||
| 302 | /* If the length of the match is not longer than the best match we */ | ||
| 303 | /* have so far, then forget it and return to the lookup loop. */ | ||
| 304 | |||
| 305 | cmpl %bestlend, %eax | ||
| 306 | jg LongerMatch | ||
| 307 | mov _windowbestlen, %windowbestlen | ||
| 308 | mov dsPrev, %prev | ||
| 309 | movl _chainlenwmask, %edx | ||
| 310 | jmp LookupLoop | ||
| 311 | |||
| 312 | /* s->match_start = cur_match; */ | ||
| 313 | /* best_len = len; */ | ||
| 314 | /* if (len >= nice_match) break; */ | ||
| 315 | /* scan_end = *(ushf*)(scan+best_len-1); */ | ||
| 316 | |||
| 317 | LongerMatch: | ||
| 318 | movl %eax, %bestlend | ||
| 319 | movl %curmatchd, dsMatchStart | ||
| 320 | cmpl %nicematch, %eax | ||
| 321 | jge LeaveNow | ||
| 322 | |||
| 323 | lea (%window, %bestlen), %windowbestlen | ||
| 324 | mov %windowbestlen, _windowbestlen | ||
| 325 | |||
| 326 | movzwl -1(%scan, %rax), %scanend | ||
| 327 | mov dsPrev, %prev | ||
| 328 | movl _chainlenwmask, %chainlenwmask | ||
| 329 | jmp LookupLoop | ||
| 330 | |||
| 331 | /* Accept the current string, with the maximum possible length. */ | ||
| 332 | |||
| 333 | LenMaximum: | ||
| 334 | movl $MAX_MATCH, %bestlend | ||
| 335 | movl %curmatchd, dsMatchStart | ||
| 336 | |||
| 337 | /* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */ | ||
| 338 | /* return s->lookahead; */ | ||
| 339 | |||
| 340 | LeaveNow: | ||
| 341 | movl dsLookahead, %eax | ||
| 342 | cmpl %eax, %bestlend | ||
| 343 | cmovngl %bestlend, %eax | ||
| 344 | LookaheadRet: | ||
| 345 | |||
| 346 | /* Restore the registers and return from whence we came. */ | ||
| 347 | |||
| 348 | mov save_rsi, %rsi | ||
| 349 | mov save_rbx, %rbx | ||
| 350 | mov save_r12, %r12 | ||
| 351 | mov save_r13, %r13 | ||
| 352 | mov save_r14, %r14 | ||
| 353 | mov save_r15, %r15 | ||
| 354 | |||
| 355 | ret | ||
| 356 | |||
| 357 | match_init: ret | ||
diff --git a/contrib/infback9/infback9.c b/contrib/infback9/infback9.c index c5547ae..7bbe90c 100644 --- a/contrib/infback9/infback9.c +++ b/contrib/infback9/infback9.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* infback9.c -- inflate deflate64 data using a call-back interface | 1 | /* infback9.c -- inflate deflate64 data using a call-back interface |
| 2 | * Copyright (C) 1995-2006 Mark Adler | 2 | * Copyright (C) 1995-2008 Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -433,7 +433,16 @@ void FAR *out_desc; | |||
| 433 | /* handle error breaks in while */ | 433 | /* handle error breaks in while */ |
| 434 | if (mode == BAD) break; | 434 | if (mode == BAD) break; |
| 435 | 435 | ||
| 436 | /* build code tables */ | 436 | /* check for end-of-block code (better have one) */ |
| 437 | if (state->lens[256] == 0) { | ||
| 438 | strm->msg = (char *)"invalid code -- missing end-of-block"; | ||
| 439 | mode = BAD; | ||
| 440 | break; | ||
| 441 | } | ||
| 442 | |||
| 443 | /* build code tables -- note: do not change the lenbits or distbits | ||
| 444 | values here (9 and 6) without reading the comments in inftree9.h | ||
| 445 | concerning the ENOUGH constants, which depend on those values */ | ||
| 437 | state->next = state->codes; | 446 | state->next = state->codes; |
| 438 | lencode = (code const FAR *)(state->next); | 447 | lencode = (code const FAR *)(state->next); |
| 439 | lenbits = 9; | 448 | lenbits = 9; |
diff --git a/contrib/infback9/inftree9.c b/contrib/infback9/inftree9.c index c24302b..18353cb 100644 --- a/contrib/infback9/inftree9.c +++ b/contrib/infback9/inftree9.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* inftree9.c -- generate Huffman trees for efficient decoding | 1 | /* inftree9.c -- generate Huffman trees for efficient decoding |
| 2 | * Copyright (C) 1995-2006 Mark Adler | 2 | * Copyright (C) 1995-2008 Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -9,7 +9,7 @@ | |||
| 9 | #define MAXBITS 15 | 9 | #define MAXBITS 15 |
| 10 | 10 | ||
| 11 | const char inflate9_copyright[] = | 11 | const char inflate9_copyright[] = |
| 12 | " inflate9 1.2.3.3 Copyright 1995-2006 Mark Adler "; | 12 | " inflate9 1.2.3.4 Copyright 1995-2008 Mark Adler "; |
| 13 | /* | 13 | /* |
| 14 | If you use the zlib library in a product, an acknowledgment is welcome | 14 | If you use the zlib library in a product, an acknowledgment is welcome |
| 15 | in the documentation of your product. If for some reason you cannot | 15 | in the documentation of your product. If for some reason you cannot |
| @@ -64,7 +64,7 @@ unsigned short FAR *work; | |||
| 64 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ | 64 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ |
| 65 | 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, | 65 | 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, |
| 66 | 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, | 66 | 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, |
| 67 | 133, 133, 133, 133, 144, 201, 203}; | 67 | 133, 133, 133, 133, 144, 72, 200}; |
| 68 | static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ | 68 | static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ |
| 69 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, | 69 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, |
| 70 | 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, | 70 | 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, |
| @@ -160,11 +160,10 @@ unsigned short FAR *work; | |||
| 160 | entered in the tables. | 160 | entered in the tables. |
| 161 | 161 | ||
| 162 | used keeps track of how many table entries have been allocated from the | 162 | used keeps track of how many table entries have been allocated from the |
| 163 | provided *table space. It is checked when a LENS table is being made | 163 | provided *table space. It is checked for LENS and DIST tables against |
| 164 | against the space in *table, ENOUGH, minus the maximum space needed by | 164 | the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in |
| 165 | the worst case distance code, MAXD. This should never happen, but the | 165 | the initial root table size constants. See the comments in inftree9.h |
| 166 | sufficiency of ENOUGH has not been proven exhaustively, hence the check. | 166 | for more information. |
| 167 | This assumes that when type == LENS, bits == 9. | ||
| 168 | 167 | ||
| 169 | sym increments through all symbols, and the loop terminates when | 168 | sym increments through all symbols, and the loop terminates when |
| 170 | all codes of length max, i.e. all codes, have been processed. This | 169 | all codes of length max, i.e. all codes, have been processed. This |
| @@ -203,7 +202,8 @@ unsigned short FAR *work; | |||
| 203 | mask = used - 1; /* mask for comparing low */ | 202 | mask = used - 1; /* mask for comparing low */ |
| 204 | 203 | ||
| 205 | /* check available table space */ | 204 | /* check available table space */ |
| 206 | if (type == LENS && used >= ENOUGH - MAXD) | 205 | if ((type == LENS && used >= ENOUGH_LENS) || |
| 206 | (type == DISTS && used >= ENOUGH_DISTS)) | ||
| 207 | return 1; | 207 | return 1; |
| 208 | 208 | ||
| 209 | /* process all codes and make table entries */ | 209 | /* process all codes and make table entries */ |
| @@ -270,7 +270,8 @@ unsigned short FAR *work; | |||
| 270 | 270 | ||
| 271 | /* check for enough space */ | 271 | /* check for enough space */ |
| 272 | used += 1U << curr; | 272 | used += 1U << curr; |
| 273 | if (type == LENS && used >= ENOUGH - MAXD) | 273 | if ((type == LENS && used >= ENOUGH_LENS) || |
| 274 | (type == DISTS && used >= ENOUGH_DISTS)) | ||
| 274 | return 1; | 275 | return 1; |
| 275 | 276 | ||
| 276 | /* point entry in root table to sub-table */ | 277 | /* point entry in root table to sub-table */ |
diff --git a/contrib/infback9/inftree9.h b/contrib/infback9/inftree9.h index a268084..5ab21f0 100644 --- a/contrib/infback9/inftree9.h +++ b/contrib/infback9/inftree9.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* inftree9.h -- header to use inftree9.c | 1 | /* inftree9.h -- header to use inftree9.c |
| 2 | * Copyright (C) 1995-2003 Mark Adler | 2 | * Copyright (C) 1995-2008 Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -35,15 +35,21 @@ typedef struct { | |||
| 35 | 01000000 - invalid code | 35 | 01000000 - invalid code |
| 36 | */ | 36 | */ |
| 37 | 37 | ||
| 38 | /* Maximum size of dynamic tree. The maximum found in a long but non- | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is |
| 39 | exhaustive search was 1444 code structures (852 for length/literals | 39 | 1446, which is the sum of 852 for literal/length codes and 594 for distance |
| 40 | and 592 for distances, the latter actually the result of an | 40 | codes. These values were found by exhaustive searches using the program |
| 41 | exhaustive search). The true maximum is not known, but the value | 41 | examples/enough.c found in the zlib distribtution. The arguments to that |
| 42 | below is more than safe. */ | 42 | program are the number of symbols, the initial root table size, and the |
| 43 | #define ENOUGH 2048 | 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes |
| 44 | #define MAXD 592 | 44 | returns returns 852, and "enough 32 6 15" for distance codes returns 594. |
| 45 | The initial root table size (9 or 6) is found in the fifth argument of the | ||
| 46 | inflate_table() calls in infback9.c. If the root table size is changed, | ||
| 47 | then these maximum sizes would be need to be recalculated and updated. */ | ||
| 48 | #define ENOUGH_LENS 852 | ||
| 49 | #define ENOUGH_DISTS 594 | ||
| 50 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) | ||
| 45 | 51 | ||
| 46 | /* Type of code to build for inftable() */ | 52 | /* Type of code to build for inflate_table9() */ |
| 47 | typedef enum { | 53 | typedef enum { |
| 48 | CODES, | 54 | CODES, |
| 49 | LENS, | 55 | LENS, |
diff --git a/contrib/nintendods/Makefile b/contrib/nintendods/Makefile new file mode 100644 index 0000000..21337d0 --- /dev/null +++ b/contrib/nintendods/Makefile | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | #--------------------------------------------------------------------------------- | ||
| 2 | .SUFFIXES: | ||
| 3 | #--------------------------------------------------------------------------------- | ||
| 4 | |||
| 5 | ifeq ($(strip $(DEVKITARM)),) | ||
| 6 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") | ||
| 7 | endif | ||
| 8 | |||
| 9 | include $(DEVKITARM)/ds_rules | ||
| 10 | |||
| 11 | #--------------------------------------------------------------------------------- | ||
| 12 | # TARGET is the name of the output | ||
| 13 | # BUILD is the directory where object files & intermediate files will be placed | ||
| 14 | # SOURCES is a list of directories containing source code | ||
| 15 | # DATA is a list of directories containing data files | ||
| 16 | # INCLUDES is a list of directories containing header files | ||
| 17 | #--------------------------------------------------------------------------------- | ||
| 18 | TARGET := $(shell basename $(CURDIR)) | ||
| 19 | BUILD := build | ||
| 20 | SOURCES := ../../ | ||
| 21 | DATA := data | ||
| 22 | INCLUDES := include | ||
| 23 | |||
| 24 | #--------------------------------------------------------------------------------- | ||
| 25 | # options for code generation | ||
| 26 | #--------------------------------------------------------------------------------- | ||
| 27 | ARCH := -mthumb -mthumb-interwork | ||
| 28 | |||
| 29 | CFLAGS := -Wall -O2\ | ||
| 30 | -march=armv5te -mtune=arm946e-s \ | ||
| 31 | -fomit-frame-pointer -ffast-math \ | ||
| 32 | $(ARCH) | ||
| 33 | |||
| 34 | CFLAGS += $(INCLUDE) -DARM9 | ||
| 35 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions | ||
| 36 | |||
| 37 | ASFLAGS := $(ARCH) -march=armv5te -mtune=arm946e-s | ||
| 38 | LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) | ||
| 39 | |||
| 40 | #--------------------------------------------------------------------------------- | ||
| 41 | # list of directories containing libraries, this must be the top level containing | ||
| 42 | # include and lib | ||
| 43 | #--------------------------------------------------------------------------------- | ||
| 44 | LIBDIRS := $(LIBNDS) | ||
| 45 | |||
| 46 | #--------------------------------------------------------------------------------- | ||
| 47 | # no real need to edit anything past this point unless you need to add additional | ||
| 48 | # rules for different file extensions | ||
| 49 | #--------------------------------------------------------------------------------- | ||
| 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) | ||
| 51 | #--------------------------------------------------------------------------------- | ||
| 52 | |||
| 53 | export OUTPUT := $(CURDIR)/lib/libz.a | ||
| 54 | |||
| 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ | ||
| 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) | ||
| 57 | |||
| 58 | export DEPSDIR := $(CURDIR)/$(BUILD) | ||
| 59 | |||
| 60 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) | ||
| 61 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) | ||
| 62 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) | ||
| 63 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) | ||
| 64 | |||
| 65 | #--------------------------------------------------------------------------------- | ||
| 66 | # use CXX for linking C++ projects, CC for standard C | ||
| 67 | #--------------------------------------------------------------------------------- | ||
| 68 | ifeq ($(strip $(CPPFILES)),) | ||
| 69 | #--------------------------------------------------------------------------------- | ||
| 70 | export LD := $(CC) | ||
| 71 | #--------------------------------------------------------------------------------- | ||
| 72 | else | ||
| 73 | #--------------------------------------------------------------------------------- | ||
| 74 | export LD := $(CXX) | ||
| 75 | #--------------------------------------------------------------------------------- | ||
| 76 | endif | ||
| 77 | #--------------------------------------------------------------------------------- | ||
| 78 | |||
| 79 | export OFILES := $(addsuffix .o,$(BINFILES)) \ | ||
| 80 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) | ||
| 81 | |||
| 82 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ | ||
| 83 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ | ||
| 84 | -I$(CURDIR)/$(BUILD) | ||
| 85 | |||
| 86 | .PHONY: $(BUILD) clean all | ||
| 87 | |||
| 88 | #--------------------------------------------------------------------------------- | ||
| 89 | all: $(BUILD) | ||
| 90 | @[ -d $@ ] || mkdir -p include | ||
| 91 | @cp ../../*.h include | ||
| 92 | |||
| 93 | lib: | ||
| 94 | @[ -d $@ ] || mkdir -p $@ | ||
| 95 | |||
| 96 | $(BUILD): lib | ||
| 97 | @[ -d $@ ] || mkdir -p $@ | ||
| 98 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile | ||
| 99 | |||
| 100 | #--------------------------------------------------------------------------------- | ||
| 101 | clean: | ||
| 102 | @echo clean ... | ||
| 103 | @rm -fr $(BUILD) lib | ||
| 104 | |||
| 105 | #--------------------------------------------------------------------------------- | ||
| 106 | else | ||
| 107 | |||
| 108 | DEPENDS := $(OFILES:.o=.d) | ||
| 109 | |||
| 110 | #--------------------------------------------------------------------------------- | ||
| 111 | # main targets | ||
| 112 | #--------------------------------------------------------------------------------- | ||
| 113 | $(OUTPUT) : $(OFILES) | ||
| 114 | |||
| 115 | #--------------------------------------------------------------------------------- | ||
| 116 | %.bin.o : %.bin | ||
| 117 | #--------------------------------------------------------------------------------- | ||
| 118 | @echo $(notdir $<) | ||
| 119 | @$(bin2o) | ||
| 120 | |||
| 121 | |||
| 122 | -include $(DEPENDS) | ||
| 123 | |||
| 124 | #--------------------------------------------------------------------------------------- | ||
| 125 | endif | ||
| 126 | #--------------------------------------------------------------------------------------- | ||
diff --git a/contrib/nintendods/README b/contrib/nintendods/README new file mode 100644 index 0000000..ba7a37d --- /dev/null +++ b/contrib/nintendods/README | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | This Makefile requires devkitARM (http://www.devkitpro.org/category/devkitarm/) and works inside "contrib/nds". It is based on a devkitARM template. | ||
| 2 | |||
| 3 | Eduardo Costa <eduardo.m.costa@gmail.com> | ||
| 4 | January 3, 2009 | ||
| 5 | |||
diff --git a/contrib/puff/puff b/contrib/puff/puff new file mode 100755 index 0000000..bedac26 --- /dev/null +++ b/contrib/puff/puff | |||
| Binary files differ | |||
diff --git a/contrib/puff/puff.c b/contrib/puff/puff.c index ce0cc40..df5b79f 100644 --- a/contrib/puff/puff.c +++ b/contrib/puff/puff.c | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * puff.c | 2 | * puff.c |
| 3 | * Copyright (C) 2002-2004 Mark Adler | 3 | * Copyright (C) 2002-2008 Mark Adler |
| 4 | * For conditions of distribution and use, see copyright notice in puff.h | 4 | * For conditions of distribution and use, see copyright notice in puff.h |
| 5 | * version 1.8, 9 Jan 2004 | 5 | * version 2.0, 25 Jul 2008 |
| 6 | * | 6 | * |
| 7 | * puff.c is a simple inflate written to be an unambiguous way to specify the | 7 | * puff.c is a simple inflate written to be an unambiguous way to specify the |
| 8 | * deflate format. It is not written for speed but rather simplicity. As a | 8 | * deflate format. It is not written for speed but rather simplicity. As a |
| @@ -61,6 +61,12 @@ | |||
| 61 | * 1.7 3 Mar 2003 - Added test code for distribution | 61 | * 1.7 3 Mar 2003 - Added test code for distribution |
| 62 | * - Added zlib-like license | 62 | * - Added zlib-like license |
| 63 | * 1.8 9 Jan 2004 - Added some comments on no distance codes case | 63 | * 1.8 9 Jan 2004 - Added some comments on no distance codes case |
| 64 | * 1.9 21 Feb 2008 - Fix bug on 16-bit integer architectures [Pohland] | ||
| 65 | * - Catch missing end-of-block symbol error | ||
| 66 | * 2.0 25 Jul 2008 - Add #define to permit distance too far back | ||
| 67 | * - Add option in TEST code for puff to write the data | ||
| 68 | * - Add option in TEST code to skip input bytes | ||
| 69 | * - Allow TEST code to read from piped stdin | ||
| 64 | */ | 70 | */ |
| 65 | 71 | ||
| 66 | #include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */ | 72 | #include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */ |
| @@ -194,7 +200,7 @@ struct huffman { | |||
| 194 | * Decode a code from the stream s using huffman table h. Return the symbol or | 200 | * Decode a code from the stream s using huffman table h. Return the symbol or |
| 195 | * a negative value if there is an error. If all of the lengths are zero, i.e. | 201 | * a negative value if there is an error. If all of the lengths are zero, i.e. |
| 196 | * an empty code, or if the code is incomplete and an invalid code is received, | 202 | * an empty code, or if the code is incomplete and an invalid code is received, |
| 197 | * then -9 is returned after reading MAXBITS bits. | 203 | * then -10 is returned after reading MAXBITS bits. |
| 198 | * | 204 | * |
| 199 | * Format notes: | 205 | * Format notes: |
| 200 | * | 206 | * |
| @@ -226,14 +232,14 @@ local int decode(struct state *s, struct huffman *h) | |||
| 226 | for (len = 1; len <= MAXBITS; len++) { | 232 | for (len = 1; len <= MAXBITS; len++) { |
| 227 | code |= bits(s, 1); /* get next bit */ | 233 | code |= bits(s, 1); /* get next bit */ |
| 228 | count = h->count[len]; | 234 | count = h->count[len]; |
| 229 | if (code < first + count) /* if length len, return symbol */ | 235 | if (code - count < first) /* if length len, return symbol */ |
| 230 | return h->symbol[index + (code - first)]; | 236 | return h->symbol[index + (code - first)]; |
| 231 | index += count; /* else update for next length */ | 237 | index += count; /* else update for next length */ |
| 232 | first += count; | 238 | first += count; |
| 233 | first <<= 1; | 239 | first <<= 1; |
| 234 | code <<= 1; | 240 | code <<= 1; |
| 235 | } | 241 | } |
| 236 | return -9; /* ran out of codes */ | 242 | return -10; /* ran out of codes */ |
| 237 | } | 243 | } |
| 238 | 244 | ||
| 239 | /* | 245 | /* |
| @@ -263,7 +269,7 @@ local int decode(struct state *s, struct huffman *h) | |||
| 263 | code |= bitbuf & 1; | 269 | code |= bitbuf & 1; |
| 264 | bitbuf >>= 1; | 270 | bitbuf >>= 1; |
| 265 | count = *next++; | 271 | count = *next++; |
| 266 | if (code < first + count) { /* if length len, return symbol */ | 272 | if (code - count < first) { /* if length len, return symbol */ |
| 267 | s->bitbuf = bitbuf; | 273 | s->bitbuf = bitbuf; |
| 268 | s->bitcnt = (s->bitcnt - len) & 7; | 274 | s->bitcnt = (s->bitcnt - len) & 7; |
| 269 | return h->symbol[index + (code - first)]; | 275 | return h->symbol[index + (code - first)]; |
| @@ -280,7 +286,7 @@ local int decode(struct state *s, struct huffman *h) | |||
| 280 | bitbuf = s->in[s->incnt++]; | 286 | bitbuf = s->in[s->incnt++]; |
| 281 | if (left > 8) left = 8; | 287 | if (left > 8) left = 8; |
| 282 | } | 288 | } |
| 283 | return -9; /* ran out of codes */ | 289 | return -10; /* ran out of codes */ |
| 284 | } | 290 | } |
| 285 | #endif /* SLOW */ | 291 | #endif /* SLOW */ |
| 286 | 292 | ||
| @@ -448,21 +454,27 @@ local int codes(struct state *s, | |||
| 448 | else if (symbol > 256) { /* length */ | 454 | else if (symbol > 256) { /* length */ |
| 449 | /* get and compute length */ | 455 | /* get and compute length */ |
| 450 | symbol -= 257; | 456 | symbol -= 257; |
| 451 | if (symbol >= 29) return -9; /* invalid fixed code */ | 457 | if (symbol >= 29) return -10; /* invalid fixed code */ |
| 452 | len = lens[symbol] + bits(s, lext[symbol]); | 458 | len = lens[symbol] + bits(s, lext[symbol]); |
| 453 | 459 | ||
| 454 | /* get and check distance */ | 460 | /* get and check distance */ |
| 455 | symbol = decode(s, distcode); | 461 | symbol = decode(s, distcode); |
| 456 | if (symbol < 0) return symbol; /* invalid symbol */ | 462 | if (symbol < 0) return symbol; /* invalid symbol */ |
| 457 | dist = dists[symbol] + bits(s, dext[symbol]); | 463 | dist = dists[symbol] + bits(s, dext[symbol]); |
| 464 | #ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR | ||
| 458 | if (dist > s->outcnt) | 465 | if (dist > s->outcnt) |
| 459 | return -10; /* distance too far back */ | 466 | return -11; /* distance too far back */ |
| 467 | #endif | ||
| 460 | 468 | ||
| 461 | /* copy length bytes from distance bytes back */ | 469 | /* copy length bytes from distance bytes back */ |
| 462 | if (s->out != NIL) { | 470 | if (s->out != NIL) { |
| 463 | if (s->outcnt + len > s->outlen) return 1; | 471 | if (s->outcnt + len > s->outlen) return 1; |
| 464 | while (len--) { | 472 | while (len--) { |
| 465 | s->out[s->outcnt] = s->out[s->outcnt - dist]; | 473 | s->out[s->outcnt] = |
| 474 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR | ||
| 475 | dist > s->outcnt ? 0 : | ||
| 476 | #endif | ||
| 477 | s->out[s->outcnt - dist]; | ||
| 466 | s->outcnt++; | 478 | s->outcnt++; |
| 467 | } | 479 | } |
| 468 | } | 480 | } |
| @@ -680,6 +692,10 @@ local int dynamic(struct state *s) | |||
| 680 | } | 692 | } |
| 681 | } | 693 | } |
| 682 | 694 | ||
| 695 | /* check for end-of-block code -- there better be one! */ | ||
| 696 | if (lengths[256] == 0) | ||
| 697 | return -9; | ||
| 698 | |||
| 683 | /* build huffman table for literal/length codes */ | 699 | /* build huffman table for literal/length codes */ |
| 684 | err = construct(&lencode, lengths, nlen); | 700 | err = construct(&lencode, lengths, nlen); |
| 685 | if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) | 701 | if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) |
| @@ -724,8 +740,9 @@ local int dynamic(struct state *s) | |||
| 724 | * -6: dynamic block code description: repeat more than specified lengths | 740 | * -6: dynamic block code description: repeat more than specified lengths |
| 725 | * -7: dynamic block code description: invalid literal/length code lengths | 741 | * -7: dynamic block code description: invalid literal/length code lengths |
| 726 | * -8: dynamic block code description: invalid distance code lengths | 742 | * -8: dynamic block code description: invalid distance code lengths |
| 727 | * -9: invalid literal/length or distance code in fixed or dynamic block | 743 | * -9: dynamic block code description: missing end-of-block code |
| 728 | * -10: distance is too far back in fixed or dynamic block | 744 | * -10: invalid literal/length or distance code in fixed or dynamic block |
| 745 | * -11: distance is too far back in fixed or dynamic block | ||
| 729 | * | 746 | * |
| 730 | * Format notes: | 747 | * Format notes: |
| 731 | * | 748 | * |
| @@ -783,54 +800,142 @@ int puff(unsigned char *dest, /* pointer to destination pointer */ | |||
| 783 | } | 800 | } |
| 784 | 801 | ||
| 785 | #ifdef TEST | 802 | #ifdef TEST |
| 786 | /* Example of how to use puff() */ | 803 | /* Examples of how to use puff(). |
| 804 | |||
| 805 | Usage: puff [-w] [-nnn] file | ||
| 806 | ... | puff [-w] [-nnn] | ||
| 807 | |||
| 808 | where file is the input file with deflate data, nnn is the number of bytes | ||
| 809 | of input to skip before inflating (e.g. to skip a zlib or gzip header), and | ||
| 810 | -w is used to write the decompressed data to stdout */ | ||
| 811 | |||
| 787 | #include <stdio.h> | 812 | #include <stdio.h> |
| 788 | #include <stdlib.h> | 813 | #include <stdlib.h> |
| 789 | #include <sys/types.h> | ||
| 790 | #include <sys/stat.h> | ||
| 791 | 814 | ||
| 792 | local unsigned char *yank(char *name, unsigned long *len) | 815 | /* Return size times approximately the cube root of 2, keeping the result as 1, |
| 816 | 3, or 5 times a power of 2 -- the result is always > size, until the result | ||
| 817 | is the maximum value of an unsigned long, where it remains. This is useful | ||
| 818 | to keep reallocations less than ~33% over the actual data. */ | ||
| 819 | local size_t bythirds(size_t size) | ||
| 793 | { | 820 | { |
| 794 | unsigned long size; | 821 | int n; |
| 795 | unsigned char *buf; | 822 | size_t m; |
| 823 | |||
| 824 | m = size; | ||
| 825 | for (n = 0; m; n++) | ||
| 826 | m >>= 1; | ||
| 827 | if (n < 3) | ||
| 828 | return size + 1; | ||
| 829 | n -= 3; | ||
| 830 | m = size >> n; | ||
| 831 | m += m == 6 ? 2 : 1; | ||
| 832 | m <<= n; | ||
| 833 | return m > size ? m : (size_t)(-1); | ||
| 834 | } | ||
| 835 | |||
| 836 | /* Read the input file *name, or stdin if name is NULL, into allocated memory. | ||
| 837 | Reallocate to larger buffers until the entire file is read in. Return a | ||
| 838 | pointer to the allocated data, or NULL if there was a memory allocation | ||
| 839 | failure. *len is the number of bytes of data read from the input file (even | ||
| 840 | if load() returns NULL). If the input file was empty or could not be opened | ||
| 841 | or read, *len is zero. */ | ||
| 842 | local void *load(char *name, size_t *len) | ||
| 843 | { | ||
| 844 | size_t size; | ||
| 845 | void *buf, *swap; | ||
| 796 | FILE *in; | 846 | FILE *in; |
| 797 | struct stat s; | ||
| 798 | 847 | ||
| 799 | *len = 0; | 848 | *len = 0; |
| 800 | if (stat(name, &s)) return NULL; | 849 | buf = malloc(size = 4096); |
| 801 | if ((s.st_mode & S_IFMT) != S_IFREG) return NULL; | 850 | if (buf == NULL) |
| 802 | size = (unsigned long)(s.st_size); | 851 | return NULL; |
| 803 | if (size == 0 || (off_t)size != s.st_size) return NULL; | 852 | in = name == NULL ? stdin : fopen(name, "rb"); |
| 804 | in = fopen(name, "r"); | 853 | if (in != NULL) { |
| 805 | if (in == NULL) return NULL; | 854 | for (;;) { |
| 806 | buf = malloc(size); | 855 | *len += fread((char *)buf + *len, 1, size - *len, in); |
| 807 | if (buf != NULL && fread(buf, 1, size, in) != size) { | 856 | if (*len < size) break; |
| 808 | free(buf); | 857 | size = bythirds(size); |
| 809 | buf = NULL; | 858 | if (size == *len || (swap = realloc(buf, size)) == NULL) { |
| 859 | free(buf); | ||
| 860 | buf = NULL; | ||
| 861 | break; | ||
| 862 | } | ||
| 863 | buf = swap; | ||
| 864 | } | ||
| 865 | fclose(in); | ||
| 810 | } | 866 | } |
| 811 | fclose(in); | ||
| 812 | *len = size; | ||
| 813 | return buf; | 867 | return buf; |
| 814 | } | 868 | } |
| 815 | 869 | ||
| 816 | int main(int argc, char **argv) | 870 | int main(int argc, char **argv) |
| 817 | { | 871 | { |
| 818 | int ret; | 872 | int ret, skip = 0, put = 0; |
| 819 | unsigned char *source; | 873 | char *arg, *name = NULL; |
| 820 | unsigned long len, sourcelen, destlen; | 874 | unsigned char *source = NULL, *dest; |
| 821 | 875 | size_t len = 0; | |
| 822 | if (argc < 2) return 2; | 876 | unsigned long sourcelen, destlen; |
| 823 | source = yank(argv[1], &len); | 877 | |
| 824 | if (source == NULL) return 2; | 878 | /* process arguments */ |
| 825 | sourcelen = len; | 879 | while (arg = *++argv, --argc) |
| 826 | ret = puff(NIL, &destlen, source, &sourcelen); | 880 | if (arg[0] == '-') { |
| 881 | if (arg[1] == 'w' && arg[2] == 0) | ||
| 882 | put = 1; | ||
| 883 | else if (arg[1] >= '0' && arg[1] <= '9') | ||
| 884 | skip = atoi(arg + 1); | ||
| 885 | else { | ||
| 886 | fprintf(stderr, "invalid option %s\n", arg); | ||
| 887 | return 3; | ||
| 888 | } | ||
| 889 | } | ||
| 890 | else if (name != NULL) { | ||
| 891 | fprintf(stderr, "only one file name allowed\n"); | ||
| 892 | return 3; | ||
| 893 | } | ||
| 894 | else | ||
| 895 | name = arg; | ||
| 896 | source = load(name, &len); | ||
| 897 | if (source == NULL) { | ||
| 898 | fprintf(stderr, "memory allocation failure\n"); | ||
| 899 | return 4; | ||
| 900 | } | ||
| 901 | if (len == 0) { | ||
| 902 | fprintf(stderr, "could not read %s, or it was empty\n", | ||
| 903 | name == NULL ? "<stdin>" : name); | ||
| 904 | free(source); | ||
| 905 | return 3; | ||
| 906 | } | ||
| 907 | if (skip >= len) { | ||
| 908 | fprintf(stderr, "skip request of %d leaves no input\n", skip); | ||
| 909 | free(source); | ||
| 910 | return 3; | ||
| 911 | } | ||
| 912 | |||
| 913 | /* test inflate data with offset skip */ | ||
| 914 | len -= skip; | ||
| 915 | sourcelen = (unsigned long)len; | ||
| 916 | ret = puff(NIL, &destlen, source + skip, &sourcelen); | ||
| 827 | if (ret) | 917 | if (ret) |
| 828 | printf("puff() failed with return code %d\n", ret); | 918 | fprintf(stderr, "puff() failed with return code %d\n", ret); |
| 829 | else { | 919 | else { |
| 830 | printf("puff() succeeded uncompressing %lu bytes\n", destlen); | 920 | fprintf(stderr, "puff() succeeded uncompressing %lu bytes\n", destlen); |
| 831 | if (sourcelen < len) printf("%lu compressed bytes unused\n", | 921 | if (sourcelen < len) fprintf(stderr, "%lu compressed bytes unused\n", |
| 832 | len - sourcelen); | 922 | len - sourcelen); |
| 833 | } | 923 | } |
| 924 | |||
| 925 | /* if requested, inflate again and write decompressd data to stdout */ | ||
| 926 | if (put) { | ||
| 927 | dest = malloc(destlen); | ||
| 928 | if (dest == NULL) { | ||
| 929 | fprintf(stderr, "memory allocation failure\n"); | ||
| 930 | free(source); | ||
| 931 | return 4; | ||
| 932 | } | ||
| 933 | puff(dest, &destlen, source + skip, &sourcelen); | ||
| 934 | fwrite(dest, 1, destlen, stdout); | ||
| 935 | free(dest); | ||
| 936 | } | ||
| 937 | |||
| 938 | /* clean up */ | ||
| 834 | free(source); | 939 | free(source); |
| 835 | return ret; | 940 | return ret; |
| 836 | } | 941 | } |
diff --git a/contrib/puff/puff.h b/contrib/puff/puff.h index ef61252..8d7f5f8 100644 --- a/contrib/puff/puff.h +++ b/contrib/puff/puff.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* puff.h | 1 | /* puff.h |
| 2 | Copyright (C) 2002, 2003 Mark Adler, all rights reserved | 2 | Copyright (C) 2002-2008 Mark Adler, all rights reserved |
| 3 | version 1.7, 3 Mar 2002 | 3 | version 1.9, 10 Jan 2008 |
| 4 | 4 | ||
| 5 | This software is provided 'as-is', without any express or implied | 5 | This software is provided 'as-is', without any express or implied |
| 6 | warranty. In no event will the author be held liable for any damages | 6 | warranty. In no event will the author be held liable for any damages |
diff --git a/contrib/vstudio/vc7/zlib.rc b/contrib/vstudio/vc7/zlib.rc index 39eca7e..98ca20b 100644 --- a/contrib/vstudio/vc7/zlib.rc +++ b/contrib/vstudio/vc7/zlib.rc | |||
| @@ -2,8 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | #define IDR_VERSION1 1 | 3 | #define IDR_VERSION1 1 |
| 4 | IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE | 4 | IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE |
| 5 | FILEVERSION 1,2,3,3 | 5 | FILEVERSION 1,2,3,4 |
| 6 | PRODUCTVERSION 1,2,3,3 | 6 | PRODUCTVERSION 1,2,3,4 |
| 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK | 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK |
| 8 | FILEFLAGS 0 | 8 | FILEFLAGS 0 |
| 9 | FILEOS VOS_DOS_WINDOWS32 | 9 | FILEOS VOS_DOS_WINDOWS32 |
| @@ -17,7 +17,7 @@ BEGIN | |||
| 17 | 17 | ||
| 18 | BEGIN | 18 | BEGIN |
| 19 | VALUE "FileDescription", "zlib data compression library\0" | 19 | VALUE "FileDescription", "zlib data compression library\0" |
| 20 | VALUE "FileVersion", "1.2.3.3\0" | 20 | VALUE "FileVersion", "1.2.3.4\0" |
| 21 | VALUE "InternalName", "zlib\0" | 21 | VALUE "InternalName", "zlib\0" |
| 22 | VALUE "OriginalFilename", "zlib.dll\0" | 22 | VALUE "OriginalFilename", "zlib.dll\0" |
| 23 | VALUE "ProductName", "ZLib.DLL\0" | 23 | VALUE "ProductName", "ZLib.DLL\0" |
