| @@ -0,0 +1,179 @@ | ||
| /* adler32.c -- compute the Adler-32 checksum of a data stream | ||
| * Copyright (C) 1995-2011 Mark Adler | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| /* @(#) $Id$ */ | ||
|
|
||
| #include "zutil.h" | ||
|
|
||
| #define local static | ||
|
|
||
| local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); | ||
|
|
||
| #define BASE 65521 /* largest prime smaller than 65536 */ | ||
| #define NMAX 5552 | ||
| /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ | ||
|
|
||
| #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} | ||
| #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); | ||
| #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); | ||
| #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); | ||
| #define DO16(buf) DO8(buf,0); DO8(buf,8); | ||
|
|
||
| /* use NO_DIVIDE if your processor does not do division in hardware -- | ||
| try it both ways to see which is faster */ | ||
| #ifdef NO_DIVIDE | ||
| /* note that this assumes BASE is 65521, where 65536 % 65521 == 15 | ||
| (thank you to John Reiser for pointing this out) */ | ||
| # define CHOP(a) \ | ||
| do { \ | ||
| unsigned long tmp = a >> 16; \ | ||
| a &= 0xffffUL; \ | ||
| a += (tmp << 4) - tmp; \ | ||
| } while (0) | ||
| # define MOD28(a) \ | ||
| do { \ | ||
| CHOP(a); \ | ||
| if (a >= BASE) a -= BASE; \ | ||
| } while (0) | ||
| # define MOD(a) \ | ||
| do { \ | ||
| CHOP(a); \ | ||
| MOD28(a); \ | ||
| } while (0) | ||
| # define MOD63(a) \ | ||
| do { /* this assumes a is not negative */ \ | ||
| z_off64_t tmp = a >> 32; \ | ||
| a &= 0xffffffffL; \ | ||
| a += (tmp << 8) - (tmp << 5) + tmp; \ | ||
| tmp = a >> 16; \ | ||
| a &= 0xffffL; \ | ||
| a += (tmp << 4) - tmp; \ | ||
| tmp = a >> 16; \ | ||
| a &= 0xffffL; \ | ||
| a += (tmp << 4) - tmp; \ | ||
| if (a >= BASE) a -= BASE; \ | ||
| } while (0) | ||
| #else | ||
| # define MOD(a) a %= BASE | ||
| # define MOD28(a) a %= BASE | ||
| # define MOD63(a) a %= BASE | ||
| #endif | ||
|
|
||
| /* ========================================================================= */ | ||
| uLong ZEXPORT adler32(adler, buf, len) | ||
| uLong adler; | ||
| const Bytef *buf; | ||
| uInt len; | ||
| { | ||
| unsigned long sum2; | ||
| unsigned n; | ||
|
|
||
| /* split Adler-32 into component sums */ | ||
| sum2 = (adler >> 16) & 0xffff; | ||
| adler &= 0xffff; | ||
|
|
||
| /* in case user likes doing a byte at a time, keep it fast */ | ||
| if (len == 1) { | ||
| adler += buf[0]; | ||
| if (adler >= BASE) | ||
| adler -= BASE; | ||
| sum2 += adler; | ||
| if (sum2 >= BASE) | ||
| sum2 -= BASE; | ||
| return adler | (sum2 << 16); | ||
| } | ||
|
|
||
| /* initial Adler-32 value (deferred check for len == 1 speed) */ | ||
| if (buf == Z_NULL) | ||
| return 1L; | ||
|
|
||
| /* in case short lengths are provided, keep it somewhat fast */ | ||
| if (len < 16) { | ||
| while (len--) { | ||
| adler += *buf++; | ||
| sum2 += adler; | ||
| } | ||
| if (adler >= BASE) | ||
| adler -= BASE; | ||
| MOD28(sum2); /* only added so many BASE's */ | ||
| return adler | (sum2 << 16); | ||
| } | ||
|
|
||
| /* do length NMAX blocks -- requires just one modulo operation */ | ||
| while (len >= NMAX) { | ||
| len -= NMAX; | ||
| n = NMAX / 16; /* NMAX is divisible by 16 */ | ||
| do { | ||
| DO16(buf); /* 16 sums unrolled */ | ||
| buf += 16; | ||
| } while (--n); | ||
| MOD(adler); | ||
| MOD(sum2); | ||
| } | ||
|
|
||
| /* do remaining bytes (less than NMAX, still just one modulo) */ | ||
| if (len) { /* avoid modulos if none remaining */ | ||
| while (len >= 16) { | ||
| len -= 16; | ||
| DO16(buf); | ||
| buf += 16; | ||
| } | ||
| while (len--) { | ||
| adler += *buf++; | ||
| sum2 += adler; | ||
| } | ||
| MOD(adler); | ||
| MOD(sum2); | ||
| } | ||
|
|
||
| /* return recombined sums */ | ||
| return adler | (sum2 << 16); | ||
| } | ||
|
|
||
| /* ========================================================================= */ | ||
| local uLong adler32_combine_(adler1, adler2, len2) | ||
| uLong adler1; | ||
| uLong adler2; | ||
| z_off64_t len2; | ||
| { | ||
| unsigned long sum1; | ||
| unsigned long sum2; | ||
| unsigned rem; | ||
|
|
||
| /* for negative len, return invalid adler32 as a clue for debugging */ | ||
| if (len2 < 0) | ||
| return 0xffffffffUL; | ||
|
|
||
| /* the derivation of this formula is left as an exercise for the reader */ | ||
| MOD63(len2); /* assumes len2 >= 0 */ | ||
| rem = (unsigned)len2; | ||
| sum1 = adler1 & 0xffff; | ||
| sum2 = rem * sum1; | ||
| MOD(sum2); | ||
| sum1 += (adler2 & 0xffff) + BASE - 1; | ||
| sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; | ||
| if (sum1 >= BASE) sum1 -= BASE; | ||
| if (sum1 >= BASE) sum1 -= BASE; | ||
| if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); | ||
| if (sum2 >= BASE) sum2 -= BASE; | ||
| return sum1 | (sum2 << 16); | ||
| } | ||
|
|
||
| /* ========================================================================= */ | ||
| uLong ZEXPORT adler32_combine(adler1, adler2, len2) | ||
| uLong adler1; | ||
| uLong adler2; | ||
| z_off_t len2; | ||
| { | ||
| return adler32_combine_(adler1, adler2, len2); | ||
| } | ||
|
|
||
| uLong ZEXPORT adler32_combine64(adler1, adler2, len2) | ||
| uLong adler1; | ||
| uLong adler2; | ||
| z_off64_t len2; | ||
| { | ||
| return adler32_combine_(adler1, adler2, len2); | ||
| } |
| @@ -0,0 +1,12 @@ | ||
| #!/bin/sh | ||
|
|
||
| if [ "$RHO_PLATFORM" = "iphone" ]; then | ||
|
|
||
| cd iphone | ||
| rake --trace | ||
|
|
||
| else | ||
|
|
||
| rake --trace | ||
|
|
||
| fi |
| @@ -0,0 +1 @@ | ||
| rake --trace |
| @@ -0,0 +1,80 @@ | ||
| /* compress.c -- compress a memory buffer | ||
| * Copyright (C) 1995-2005 Jean-loup Gailly. | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| /* @(#) $Id$ */ | ||
|
|
||
| #define ZLIB_INTERNAL | ||
| #include "zlib.h" | ||
|
|
||
| /* =========================================================================== | ||
| Compresses the source buffer into the destination buffer. The level | ||
| parameter has the same meaning as in deflateInit. sourceLen is the byte | ||
| length of the source buffer. Upon entry, destLen is the total size of the | ||
| destination buffer, which must be at least 0.1% larger than sourceLen plus | ||
| 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. | ||
| compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough | ||
| memory, Z_BUF_ERROR if there was not enough room in the output buffer, | ||
| Z_STREAM_ERROR if the level parameter is invalid. | ||
| */ | ||
| int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) | ||
| Bytef *dest; | ||
| uLongf *destLen; | ||
| const Bytef *source; | ||
| uLong sourceLen; | ||
| int level; | ||
| { | ||
| z_stream stream; | ||
| int err; | ||
|
|
||
| stream.next_in = (Bytef*)source; | ||
| stream.avail_in = (uInt)sourceLen; | ||
| #ifdef MAXSEG_64K | ||
| /* Check for source > 64K on 16-bit machine: */ | ||
| if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; | ||
| #endif | ||
| stream.next_out = dest; | ||
| stream.avail_out = (uInt)*destLen; | ||
| if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; | ||
|
|
||
| stream.zalloc = (alloc_func)0; | ||
| stream.zfree = (free_func)0; | ||
| stream.opaque = (voidpf)0; | ||
|
|
||
| err = deflateInit(&stream, level); | ||
| if (err != Z_OK) return err; | ||
|
|
||
| err = deflate(&stream, Z_FINISH); | ||
| if (err != Z_STREAM_END) { | ||
| deflateEnd(&stream); | ||
| return err == Z_OK ? Z_BUF_ERROR : err; | ||
| } | ||
| *destLen = stream.total_out; | ||
|
|
||
| err = deflateEnd(&stream); | ||
| return err; | ||
| } | ||
|
|
||
| /* =========================================================================== | ||
| */ | ||
| int ZEXPORT compress (dest, destLen, source, sourceLen) | ||
| Bytef *dest; | ||
| uLongf *destLen; | ||
| const Bytef *source; | ||
| uLong sourceLen; | ||
| { | ||
| return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); | ||
| } | ||
|
|
||
| /* =========================================================================== | ||
| If the default memLevel or windowBits for deflateInit() is changed, then | ||
| this function needs to be updated. | ||
| */ | ||
| uLong ZEXPORT compressBound (sourceLen) | ||
| uLong sourceLen; | ||
| { | ||
| return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + | ||
| (sourceLen >> 25) + 13; | ||
| } |
| @@ -0,0 +1,346 @@ | ||
| /* deflate.h -- internal compression state | ||
| * Copyright (C) 1995-2012 Jean-loup Gailly | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| /* WARNING: this file should *not* be used by applications. It is | ||
| part of the implementation of the compression library and is | ||
| subject to change. Applications should only use zlib.h. | ||
| */ | ||
|
|
||
| /* @(#) $Id$ */ | ||
|
|
||
| #ifndef DEFLATE_H | ||
| #define DEFLATE_H | ||
|
|
||
| #include "zutil.h" | ||
|
|
||
| /* define NO_GZIP when compiling if you want to disable gzip header and | ||
| trailer creation by deflate(). NO_GZIP would be used to avoid linking in | ||
| the crc code when it is not needed. For shared libraries, gzip encoding | ||
| should be left enabled. */ | ||
| #ifndef NO_GZIP | ||
| # define GZIP | ||
| #endif | ||
|
|
||
| /* =========================================================================== | ||
| * Internal compression state. | ||
| */ | ||
|
|
||
| #define LENGTH_CODES 29 | ||
| /* number of length codes, not counting the special END_BLOCK code */ | ||
|
|
||
| #define LITERALS 256 | ||
| /* number of literal bytes 0..255 */ | ||
|
|
||
| #define L_CODES (LITERALS+1+LENGTH_CODES) | ||
| /* number of Literal or Length codes, including the END_BLOCK code */ | ||
|
|
||
| #define D_CODES 30 | ||
| /* number of distance codes */ | ||
|
|
||
| #define BL_CODES 19 | ||
| /* number of codes used to transfer the bit lengths */ | ||
|
|
||
| #define HEAP_SIZE (2*L_CODES+1) | ||
| /* maximum heap size */ | ||
|
|
||
| #define MAX_BITS 15 | ||
| /* All codes must not exceed MAX_BITS bits */ | ||
|
|
||
| #define Buf_size 16 | ||
| /* size of bit buffer in bi_buf */ | ||
|
|
||
| #define INIT_STATE 42 | ||
| #define EXTRA_STATE 69 | ||
| #define NAME_STATE 73 | ||
| #define COMMENT_STATE 91 | ||
| #define HCRC_STATE 103 | ||
| #define BUSY_STATE 113 | ||
| #define FINISH_STATE 666 | ||
| /* Stream status */ | ||
|
|
||
|
|
||
| /* Data structure describing a single value and its code string. */ | ||
| typedef struct ct_data_s { | ||
| union { | ||
| ush freq; /* frequency count */ | ||
| ush code; /* bit string */ | ||
| } fc; | ||
| union { | ||
| ush dad; /* father node in Huffman tree */ | ||
| ush len; /* length of bit string */ | ||
| } dl; | ||
| } FAR ct_data; | ||
|
|
||
| #define Freq fc.freq | ||
| #define Code fc.code | ||
| #define Dad dl.dad | ||
| #define Len dl.len | ||
|
|
||
| typedef struct static_tree_desc_s static_tree_desc; | ||
|
|
||
| typedef struct tree_desc_s { | ||
| ct_data *dyn_tree; /* the dynamic tree */ | ||
| int max_code; /* largest code with non zero frequency */ | ||
| static_tree_desc *stat_desc; /* the corresponding static tree */ | ||
| } FAR tree_desc; | ||
|
|
||
| typedef ush Pos; | ||
| typedef Pos FAR Posf; | ||
| typedef unsigned IPos; | ||
|
|
||
| /* A Pos is an index in the character window. We use short instead of int to | ||
| * save space in the various tables. IPos is used only for parameter passing. | ||
| */ | ||
|
|
||
| typedef struct internal_state { | ||
| z_streamp strm; /* pointer back to this zlib stream */ | ||
| int status; /* as the name implies */ | ||
| Bytef *pending_buf; /* output still pending */ | ||
| ulg pending_buf_size; /* size of pending_buf */ | ||
| Bytef *pending_out; /* next pending byte to output to the stream */ | ||
| uInt pending; /* nb of bytes in the pending buffer */ | ||
| int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ | ||
| gz_headerp gzhead; /* gzip header information to write */ | ||
| uInt gzindex; /* where in extra, name, or comment */ | ||
| Byte method; /* STORED (for zip only) or DEFLATED */ | ||
| int last_flush; /* value of flush param for previous deflate call */ | ||
|
|
||
| /* used by deflate.c: */ | ||
|
|
||
| uInt w_size; /* LZ77 window size (32K by default) */ | ||
| uInt w_bits; /* log2(w_size) (8..16) */ | ||
| uInt w_mask; /* w_size - 1 */ | ||
|
|
||
| Bytef *window; | ||
| /* Sliding window. Input bytes are read into the second half of the window, | ||
| * and move to the first half later to keep a dictionary of at least wSize | ||
| * bytes. With this organization, matches are limited to a distance of | ||
| * wSize-MAX_MATCH bytes, but this ensures that IO is always | ||
| * performed with a length multiple of the block size. Also, it limits | ||
| * the window size to 64K, which is quite useful on MSDOS. | ||
| * To do: use the user input buffer as sliding window. | ||
| */ | ||
|
|
||
| ulg window_size; | ||
| /* Actual size of window: 2*wSize, except when the user input buffer | ||
| * is directly used as sliding window. | ||
| */ | ||
|
|
||
| Posf *prev; | ||
| /* Link to older string with same hash index. To limit the size of this | ||
| * array to 64K, this link is maintained only for the last 32K strings. | ||
| * An index in this array is thus a window index modulo 32K. | ||
| */ | ||
|
|
||
| Posf *head; /* Heads of the hash chains or NIL. */ | ||
|
|
||
| uInt ins_h; /* hash index of string to be inserted */ | ||
| uInt hash_size; /* number of elements in hash table */ | ||
| uInt hash_bits; /* log2(hash_size) */ | ||
| uInt hash_mask; /* hash_size-1 */ | ||
|
|
||
| uInt hash_shift; | ||
| /* Number of bits by which ins_h must be shifted at each input | ||
| * step. It must be such that after MIN_MATCH steps, the oldest | ||
| * byte no longer takes part in the hash key, that is: | ||
| * hash_shift * MIN_MATCH >= hash_bits | ||
| */ | ||
|
|
||
| long block_start; | ||
| /* Window position at the beginning of the current output block. Gets | ||
| * negative when the window is moved backwards. | ||
| */ | ||
|
|
||
| uInt match_length; /* length of best match */ | ||
| IPos prev_match; /* previous match */ | ||
| int match_available; /* set if previous match exists */ | ||
| uInt strstart; /* start of string to insert */ | ||
| uInt match_start; /* start of matching string */ | ||
| uInt lookahead; /* number of valid bytes ahead in window */ | ||
|
|
||
| uInt prev_length; | ||
| /* Length of the best match at previous step. Matches not greater than this | ||
| * are discarded. This is used in the lazy match evaluation. | ||
| */ | ||
|
|
||
| uInt max_chain_length; | ||
| /* To speed up deflation, hash chains are never searched beyond this | ||
| * length. A higher limit improves compression ratio but degrades the | ||
| * speed. | ||
| */ | ||
|
|
||
| uInt max_lazy_match; | ||
| /* Attempt to find a better match only when the current match is strictly | ||
| * smaller than this value. This mechanism is used only for compression | ||
| * levels >= 4. | ||
| */ | ||
| # define max_insert_length max_lazy_match | ||
| /* Insert new strings in the hash table only if the match length is not | ||
| * greater than this length. This saves time but degrades compression. | ||
| * max_insert_length is used only for compression levels <= 3. | ||
| */ | ||
|
|
||
| int level; /* compression level (1..9) */ | ||
| int strategy; /* favor or force Huffman coding*/ | ||
|
|
||
| uInt good_match; | ||
| /* Use a faster search when the previous match is longer than this */ | ||
|
|
||
| int nice_match; /* Stop searching when current match exceeds this */ | ||
|
|
||
| /* used by trees.c: */ | ||
| /* Didn't use ct_data typedef below to suppress compiler warning */ | ||
| struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ | ||
| struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ | ||
| struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ | ||
|
|
||
| struct tree_desc_s l_desc; /* desc. for literal tree */ | ||
| struct tree_desc_s d_desc; /* desc. for distance tree */ | ||
| struct tree_desc_s bl_desc; /* desc. for bit length tree */ | ||
|
|
||
| ush bl_count[MAX_BITS+1]; | ||
| /* number of codes at each bit length for an optimal tree */ | ||
|
|
||
| int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ | ||
| int heap_len; /* number of elements in the heap */ | ||
| int heap_max; /* element of largest frequency */ | ||
| /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. | ||
| * The same heap array is used to build all trees. | ||
| */ | ||
|
|
||
| uch depth[2*L_CODES+1]; | ||
| /* Depth of each subtree used as tie breaker for trees of equal frequency | ||
| */ | ||
|
|
||
| uchf *l_buf; /* buffer for literals or lengths */ | ||
|
|
||
| uInt lit_bufsize; | ||
| /* Size of match buffer for literals/lengths. There are 4 reasons for | ||
| * limiting lit_bufsize to 64K: | ||
| * - frequencies can be kept in 16 bit counters | ||
| * - if compression is not successful for the first block, all input | ||
| * data is still in the window so we can still emit a stored block even | ||
| * when input comes from standard input. (This can also be done for | ||
| * all blocks if lit_bufsize is not greater than 32K.) | ||
| * - if compression is not successful for a file smaller than 64K, we can | ||
| * even emit a stored file instead of a stored block (saving 5 bytes). | ||
| * This is applicable only for zip (not gzip or zlib). | ||
| * - creating new Huffman trees less frequently may not provide fast | ||
| * adaptation to changes in the input data statistics. (Take for | ||
| * example a binary file with poorly compressible code followed by | ||
| * a highly compressible string table.) Smaller buffer sizes give | ||
| * fast adaptation but have of course the overhead of transmitting | ||
| * trees more frequently. | ||
| * - I can't count above 4 | ||
| */ | ||
|
|
||
| uInt last_lit; /* running index in l_buf */ | ||
|
|
||
| ushf *d_buf; | ||
| /* Buffer for distances. To simplify the code, d_buf and l_buf have | ||
| * the same number of elements. To use different lengths, an extra flag | ||
| * array would be necessary. | ||
| */ | ||
|
|
||
| ulg opt_len; /* bit length of current block with optimal trees */ | ||
| ulg static_len; /* bit length of current block with static trees */ | ||
| uInt matches; /* number of string matches in current block */ | ||
| uInt insert; /* bytes at end of window left to insert */ | ||
|
|
||
| #ifdef DEBUG | ||
| ulg compressed_len; /* total bit length of compressed file mod 2^32 */ | ||
| ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ | ||
| #endif | ||
|
|
||
| ush bi_buf; | ||
| /* Output buffer. bits are inserted starting at the bottom (least | ||
| * significant bits). | ||
| */ | ||
| int bi_valid; | ||
| /* Number of valid bits in bi_buf. All bits above the last valid bit | ||
| * are always zero. | ||
| */ | ||
|
|
||
| ulg high_water; | ||
| /* High water mark offset in window for initialized bytes -- bytes above | ||
| * this are set to zero in order to avoid memory check warnings when | ||
| * longest match routines access bytes past the input. This is then | ||
| * updated to the new high water mark. | ||
| */ | ||
|
|
||
| } FAR deflate_state; | ||
|
|
||
| /* Output a byte on the stream. | ||
| * IN assertion: there is enough room in pending_buf. | ||
| */ | ||
| #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} | ||
|
|
||
|
|
||
| #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) | ||
| /* Minimum amount of lookahead, except at the end of the input file. | ||
| * See deflate.c for comments about the MIN_MATCH+1. | ||
| */ | ||
|
|
||
| #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) | ||
| /* In order to simplify the code, particularly on 16 bit machines, match | ||
| * distances are limited to MAX_DIST instead of WSIZE. | ||
| */ | ||
|
|
||
| #define WIN_INIT MAX_MATCH | ||
| /* Number of bytes after end of data in window to initialize in order to avoid | ||
| memory checker errors from longest match routines */ | ||
|
|
||
| /* in trees.c */ | ||
| void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); | ||
| int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); | ||
| void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, | ||
| ulg stored_len, int last)); | ||
| void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); | ||
| void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); | ||
| void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, | ||
| ulg stored_len, int last)); | ||
|
|
||
| #define d_code(dist) \ | ||
| ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) | ||
| /* Mapping from a distance to a distance code. dist is the distance - 1 and | ||
| * must not have side effects. _dist_code[256] and _dist_code[257] are never | ||
| * used. | ||
| */ | ||
|
|
||
| #ifndef DEBUG | ||
| /* Inline versions of _tr_tally for speed: */ | ||
|
|
||
| #if defined(GEN_TREES_H) || !defined(STDC) | ||
| extern uch ZLIB_INTERNAL _length_code[]; | ||
| extern uch ZLIB_INTERNAL _dist_code[]; | ||
| #else | ||
| extern const uch ZLIB_INTERNAL _length_code[]; | ||
| extern const uch ZLIB_INTERNAL _dist_code[]; | ||
| #endif | ||
|
|
||
| # define _tr_tally_lit(s, c, flush) \ | ||
| { uch cc = (c); \ | ||
| s->d_buf[s->last_lit] = 0; \ | ||
| s->l_buf[s->last_lit++] = cc; \ | ||
| s->dyn_ltree[cc].Freq++; \ | ||
| flush = (s->last_lit == s->lit_bufsize-1); \ | ||
| } | ||
| # define _tr_tally_dist(s, distance, length, flush) \ | ||
| { uch len = (length); \ | ||
| ush dist = (distance); \ | ||
| s->d_buf[s->last_lit] = dist; \ | ||
| s->l_buf[s->last_lit++] = len; \ | ||
| dist--; \ | ||
| s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ | ||
| s->dyn_dtree[d_code(dist)].Freq++; \ | ||
| flush = (s->last_lit == s->lit_bufsize-1); \ | ||
| } | ||
| #else | ||
| # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) | ||
| # define _tr_tally_dist(s, distance, length, flush) \ | ||
| flush = _tr_tally(s, distance, length) | ||
| #endif | ||
|
|
||
| #endif /* DEFLATE_H */ |
| @@ -0,0 +1,25 @@ | ||
| /* gzclose.c -- zlib gzclose() function | ||
| * Copyright (C) 2004, 2010 Mark Adler | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| #include "gzguts.h" | ||
|
|
||
| /* gzclose() is in a separate file so that it is linked in only if it is used. | ||
| That way the other gzclose functions can be used instead to avoid linking in | ||
| unneeded compression or decompression routines. */ | ||
| int ZEXPORT gzclose(file) | ||
| gzFile file; | ||
| { | ||
| #ifndef NO_GZCOMPRESS | ||
| gz_statep state; | ||
|
|
||
| if (file == NULL) | ||
| return Z_STREAM_ERROR; | ||
| state = (gz_statep)file; | ||
|
|
||
| return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); | ||
| #else | ||
| return gzclose_r(file); | ||
| #endif | ||
| } |
| @@ -0,0 +1,193 @@ | ||
| /* gzguts.h -- zlib internal header definitions for gz* operations | ||
| * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| #ifdef _LARGEFILE64_SOURCE | ||
| # ifndef _LARGEFILE_SOURCE | ||
| # define _LARGEFILE_SOURCE 1 | ||
| # endif | ||
| # ifdef _FILE_OFFSET_BITS | ||
| # undef _FILE_OFFSET_BITS | ||
| # endif | ||
| #endif | ||
|
|
||
| #ifdef HAVE_HIDDEN | ||
| # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) | ||
| #else | ||
| # define ZLIB_INTERNAL | ||
| #endif | ||
|
|
||
| #include <stdio.h> | ||
| #include "zlib.h" | ||
| #ifdef STDC | ||
| # include <string.h> | ||
| # include <stdlib.h> | ||
| # include <limits.h> | ||
| #endif | ||
| #include <fcntl.h> | ||
|
|
||
| #ifdef _WIN32 | ||
| # include <stddef.h> | ||
| #endif | ||
|
|
||
| #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) | ||
| # include <io.h> | ||
| #endif | ||
|
|
||
| #ifdef NO_DEFLATE /* for compatibility with old definition */ | ||
| # define NO_GZCOMPRESS | ||
| #endif | ||
|
|
||
| #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) | ||
| # ifndef HAVE_VSNPRINTF | ||
| # define HAVE_VSNPRINTF | ||
| # endif | ||
| #endif | ||
|
|
||
| #if defined(__CYGWIN__) | ||
| # ifndef HAVE_VSNPRINTF | ||
| # define HAVE_VSNPRINTF | ||
| # endif | ||
| #endif | ||
|
|
||
| #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) | ||
| # ifndef HAVE_VSNPRINTF | ||
| # define HAVE_VSNPRINTF | ||
| # endif | ||
| #endif | ||
|
|
||
| #ifndef HAVE_VSNPRINTF | ||
| # ifdef MSDOS | ||
| /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), | ||
| but for now we just assume it doesn't. */ | ||
| # define NO_vsnprintf | ||
| # endif | ||
| # ifdef __TURBOC__ | ||
| # define NO_vsnprintf | ||
| # endif | ||
| # ifdef WIN32 | ||
| /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ | ||
| # if !defined(vsnprintf) && !defined(NO_vsnprintf) | ||
| # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) | ||
| # define vsnprintf _vsnprintf | ||
| # endif | ||
| # endif | ||
| # endif | ||
| # ifdef __SASC | ||
| # define NO_vsnprintf | ||
| # endif | ||
| # ifdef VMS | ||
| # define NO_vsnprintf | ||
| # endif | ||
| # ifdef __OS400__ | ||
| # define NO_vsnprintf | ||
| # endif | ||
| # ifdef __MVS__ | ||
| # define NO_vsnprintf | ||
| # endif | ||
| #endif | ||
|
|
||
| #ifndef local | ||
| # define local static | ||
| #endif | ||
| /* compile with -Dlocal if your debugger can't find static symbols */ | ||
|
|
||
| /* gz* functions always use library allocation functions */ | ||
| #ifndef STDC | ||
| extern voidp malloc OF((uInt size)); | ||
| extern void free OF((voidpf ptr)); | ||
| #endif | ||
|
|
||
| /* get errno and strerror definition */ | ||
| #if defined UNDER_CE | ||
| # include <windows.h> | ||
| # define zstrerror() gz_strwinerror((DWORD)GetLastError()) | ||
| #else | ||
| # ifndef NO_STRERROR | ||
| # include <errno.h> | ||
| # define zstrerror() strerror(errno) | ||
| # else | ||
| # define zstrerror() "stdio error (consult errno)" | ||
| # endif | ||
| #endif | ||
|
|
||
| /* provide prototypes for these when building zlib without LFS */ | ||
| #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 | ||
| ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); | ||
| ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); | ||
| ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); | ||
| ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); | ||
| #endif | ||
|
|
||
| /* default memLevel */ | ||
| #if MAX_MEM_LEVEL >= 8 | ||
| # define DEF_MEM_LEVEL 8 | ||
| #else | ||
| # define DEF_MEM_LEVEL MAX_MEM_LEVEL | ||
| #endif | ||
|
|
||
| /* default i/o buffer size -- double this for output when reading */ | ||
| #define GZBUFSIZE 8192 | ||
|
|
||
| /* gzip modes, also provide a little integrity check on the passed structure */ | ||
| #define GZ_NONE 0 | ||
| #define GZ_READ 7247 | ||
| #define GZ_WRITE 31153 | ||
| #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ | ||
|
|
||
| /* values for gz_state how */ | ||
| #define LOOK 0 /* look for a gzip header */ | ||
| #define COPY 1 /* copy input directly */ | ||
| #define GZIP 2 /* decompress a gzip stream */ | ||
|
|
||
| /* internal gzip file state data structure */ | ||
| typedef struct { | ||
| /* exposed contents for gzgetc() macro */ | ||
| struct gzFile_s x; /* "x" for exposed */ | ||
| /* x.have: number of bytes available at x.next */ | ||
| /* x.next: next output data to deliver or write */ | ||
| /* x.pos: current position in uncompressed data */ | ||
| /* used for both reading and writing */ | ||
| int mode; /* see gzip modes above */ | ||
| int fd; /* file descriptor */ | ||
| char *path; /* path or fd for error messages */ | ||
| unsigned size; /* buffer size, zero if not allocated yet */ | ||
| unsigned want; /* requested buffer size, default is GZBUFSIZE */ | ||
| unsigned char *in; /* input buffer */ | ||
| unsigned char *out; /* output buffer (double-sized when reading) */ | ||
| int direct; /* 0 if processing gzip, 1 if transparent */ | ||
| /* just for reading */ | ||
| int how; /* 0: get header, 1: copy, 2: decompress */ | ||
| z_off64_t start; /* where the gzip data started, for rewinding */ | ||
| int eof; /* true if end of input file reached */ | ||
| int past; /* true if read requested past end */ | ||
| /* just for writing */ | ||
| int level; /* compression level */ | ||
| int strategy; /* compression strategy */ | ||
| /* seek request */ | ||
| z_off64_t skip; /* amount to skip (already rewound if backwards) */ | ||
| int seek; /* true if seek request pending */ | ||
| /* error information */ | ||
| int err; /* error code */ | ||
| char *msg; /* error message */ | ||
| /* zlib inflate or deflate stream */ | ||
| z_stream strm; /* stream structure in-place (not a pointer) */ | ||
| } gz_state; | ||
| typedef gz_state FAR *gz_statep; | ||
|
|
||
| /* shared functions */ | ||
| void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); | ||
| #if defined UNDER_CE | ||
| char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); | ||
| #endif | ||
|
|
||
| /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t | ||
| value -- needed when comparing unsigned to z_off64_t, which is signed | ||
| (possible z_off64_t types off_t, off64_t, and long are all signed) */ | ||
| #ifdef INT_MAX | ||
| # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) | ||
| #else | ||
| unsigned ZLIB_INTERNAL gz_intmax OF((void)); | ||
| # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) | ||
| #endif |
| @@ -0,0 +1,340 @@ | ||
| /* inffast.c -- fast decoding | ||
| * Copyright (C) 1995-2008, 2010 Mark Adler | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| #include "zutil.h" | ||
| #include "inftrees.h" | ||
| #include "inflate.h" | ||
| #include "inffast.h" | ||
|
|
||
| #ifndef ASMINF | ||
|
|
||
| /* Allow machine dependent optimization for post-increment or pre-increment. | ||
| Based on testing to date, | ||
| Pre-increment preferred for: | ||
| - PowerPC G3 (Adler) | ||
| - MIPS R5000 (Randers-Pehrson) | ||
| Post-increment preferred for: | ||
| - none | ||
| No measurable difference: | ||
| - Pentium III (Anderson) | ||
| - M68060 (Nikl) | ||
| */ | ||
| #ifdef POSTINC | ||
| # define OFF 0 | ||
| # define PUP(a) *(a)++ | ||
| #else | ||
| # define OFF 1 | ||
| # define PUP(a) *++(a) | ||
| #endif | ||
|
|
||
| /* | ||
| Decode literal, length, and distance codes and write out the resulting | ||
| literal and match bytes until either not enough input or output is | ||
| available, an end-of-block is encountered, or a data error is encountered. | ||
| When large enough input and output buffers are supplied to inflate(), for | ||
| example, a 16K input buffer and a 64K output buffer, more than 95% of the | ||
| inflate execution time is spent in this routine. | ||
| Entry assumptions: | ||
| state->mode == LEN | ||
| strm->avail_in >= 6 | ||
| strm->avail_out >= 258 | ||
| start >= strm->avail_out | ||
| state->bits < 8 | ||
| On return, state->mode is one of: | ||
| LEN -- ran out of enough output space or enough available input | ||
| TYPE -- reached end of block code, inflate() to interpret next block | ||
| BAD -- error in block data | ||
| Notes: | ||
| - The maximum input bits used by a length/distance pair is 15 bits for the | ||
| length code, 5 bits for the length extra, 15 bits for the distance code, | ||
| and 13 bits for the distance extra. This totals 48 bits, or six bytes. | ||
| Therefore if strm->avail_in >= 6, then there is enough input to avoid | ||
| checking for available input while decoding. | ||
| - The maximum bytes that a single length/distance pair can output is 258 | ||
| bytes, which is the maximum length that can be coded. inflate_fast() | ||
| requires strm->avail_out >= 258 for each loop to avoid checking for | ||
| output space. | ||
| */ | ||
| void ZLIB_INTERNAL inflate_fast(strm, start) | ||
| z_streamp strm; | ||
| unsigned start; /* inflate()'s starting value for strm->avail_out */ | ||
| { | ||
| struct inflate_state FAR *state; | ||
| unsigned char FAR *in; /* local strm->next_in */ | ||
| unsigned char FAR *last; /* while in < last, enough input available */ | ||
| unsigned char FAR *out; /* local strm->next_out */ | ||
| unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ | ||
| unsigned char FAR *end; /* while out < end, enough space available */ | ||
| #ifdef INFLATE_STRICT | ||
| unsigned dmax; /* maximum distance from zlib header */ | ||
| #endif | ||
| unsigned wsize; /* window size or zero if not using window */ | ||
| unsigned whave; /* valid bytes in the window */ | ||
| unsigned wnext; /* window write index */ | ||
| unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ | ||
| unsigned long hold; /* local strm->hold */ | ||
| unsigned bits; /* local strm->bits */ | ||
| code const FAR *lcode; /* local strm->lencode */ | ||
| code const FAR *dcode; /* local strm->distcode */ | ||
| unsigned lmask; /* mask for first level of length codes */ | ||
| unsigned dmask; /* mask for first level of distance codes */ | ||
| code here; /* retrieved table entry */ | ||
| unsigned op; /* code bits, operation, extra bits, or */ | ||
| /* window position, window bytes to copy */ | ||
| unsigned len; /* match length, unused bytes */ | ||
| unsigned dist; /* match distance */ | ||
| unsigned char FAR *from; /* where to copy match from */ | ||
|
|
||
| /* copy state to local variables */ | ||
| state = (struct inflate_state FAR *)strm->state; | ||
| in = strm->next_in - OFF; | ||
| last = in + (strm->avail_in - 5); | ||
| out = strm->next_out - OFF; | ||
| beg = out - (start - strm->avail_out); | ||
| end = out + (strm->avail_out - 257); | ||
| #ifdef INFLATE_STRICT | ||
| dmax = state->dmax; | ||
| #endif | ||
| wsize = state->wsize; | ||
| whave = state->whave; | ||
| wnext = state->wnext; | ||
| window = state->window; | ||
| hold = state->hold; | ||
| bits = state->bits; | ||
| lcode = state->lencode; | ||
| dcode = state->distcode; | ||
| lmask = (1U << state->lenbits) - 1; | ||
| dmask = (1U << state->distbits) - 1; | ||
|
|
||
| /* decode literals and length/distances until end-of-block or not enough | ||
| input data or output space */ | ||
| do { | ||
| if (bits < 15) { | ||
| hold += (unsigned long)(PUP(in)) << bits; | ||
| bits += 8; | ||
| hold += (unsigned long)(PUP(in)) << bits; | ||
| bits += 8; | ||
| } | ||
| here = lcode[hold & lmask]; | ||
| dolen: | ||
| op = (unsigned)(here.bits); | ||
| hold >>= op; | ||
| bits -= op; | ||
| op = (unsigned)(here.op); | ||
| if (op == 0) { /* literal */ | ||
| Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? | ||
| "inflate: literal '%c'\n" : | ||
| "inflate: literal 0x%02x\n", here.val)); | ||
| PUP(out) = (unsigned char)(here.val); | ||
| } | ||
| else if (op & 16) { /* length base */ | ||
| len = (unsigned)(here.val); | ||
| op &= 15; /* number of extra bits */ | ||
| if (op) { | ||
| if (bits < op) { | ||
| hold += (unsigned long)(PUP(in)) << bits; | ||
| bits += 8; | ||
| } | ||
| len += (unsigned)hold & ((1U << op) - 1); | ||
| hold >>= op; | ||
| bits -= op; | ||
| } | ||
| Tracevv((stderr, "inflate: length %u\n", len)); | ||
| if (bits < 15) { | ||
| hold += (unsigned long)(PUP(in)) << bits; | ||
| bits += 8; | ||
| hold += (unsigned long)(PUP(in)) << bits; | ||
| bits += 8; | ||
| } | ||
| here = dcode[hold & dmask]; | ||
| dodist: | ||
| op = (unsigned)(here.bits); | ||
| hold >>= op; | ||
| bits -= op; | ||
| op = (unsigned)(here.op); | ||
| if (op & 16) { /* distance base */ | ||
| dist = (unsigned)(here.val); | ||
| op &= 15; /* number of extra bits */ | ||
| if (bits < op) { | ||
| hold += (unsigned long)(PUP(in)) << bits; | ||
| bits += 8; | ||
| if (bits < op) { | ||
| hold += (unsigned long)(PUP(in)) << bits; | ||
| bits += 8; | ||
| } | ||
| } | ||
| dist += (unsigned)hold & ((1U << op) - 1); | ||
| #ifdef INFLATE_STRICT | ||
| if (dist > dmax) { | ||
| strm->msg = (char *)"invalid distance too far back"; | ||
| state->mode = BAD; | ||
| break; | ||
| } | ||
| #endif | ||
| hold >>= op; | ||
| bits -= op; | ||
| Tracevv((stderr, "inflate: distance %u\n", dist)); | ||
| op = (unsigned)(out - beg); /* max distance in output */ | ||
| if (dist > op) { /* see if copy from window */ | ||
| op = dist - op; /* distance back in window */ | ||
| if (op > whave) { | ||
| if (state->sane) { | ||
| strm->msg = | ||
| (char *)"invalid distance too far back"; | ||
| state->mode = BAD; | ||
| break; | ||
| } | ||
| #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR | ||
| if (len <= op - whave) { | ||
| do { | ||
| PUP(out) = 0; | ||
| } while (--len); | ||
| continue; | ||
| } | ||
| len -= op - whave; | ||
| do { | ||
| PUP(out) = 0; | ||
| } while (--op > whave); | ||
| if (op == 0) { | ||
| from = out - dist; | ||
| do { | ||
| PUP(out) = PUP(from); | ||
| } while (--len); | ||
| continue; | ||
| } | ||
| #endif | ||
| } | ||
| from = window - OFF; | ||
| if (wnext == 0) { /* very common case */ | ||
| from += wsize - op; | ||
| if (op < len) { /* some from window */ | ||
| len -= op; | ||
| do { | ||
| PUP(out) = PUP(from); | ||
| } while (--op); | ||
| from = out - dist; /* rest from output */ | ||
| } | ||
| } | ||
| else if (wnext < op) { /* wrap around window */ | ||
| from += wsize + wnext - op; | ||
| op -= wnext; | ||
| if (op < len) { /* some from end of window */ | ||
| len -= op; | ||
| do { | ||
| PUP(out) = PUP(from); | ||
| } while (--op); | ||
| from = window - OFF; | ||
| if (wnext < len) { /* some from start of window */ | ||
| op = wnext; | ||
| len -= op; | ||
| do { | ||
| PUP(out) = PUP(from); | ||
| } while (--op); | ||
| from = out - dist; /* rest from output */ | ||
| } | ||
| } | ||
| } | ||
| else { /* contiguous in window */ | ||
| from += wnext - op; | ||
| if (op < len) { /* some from window */ | ||
| len -= op; | ||
| do { | ||
| PUP(out) = PUP(from); | ||
| } while (--op); | ||
| from = out - dist; /* rest from output */ | ||
| } | ||
| } | ||
| while (len > 2) { | ||
| PUP(out) = PUP(from); | ||
| PUP(out) = PUP(from); | ||
| PUP(out) = PUP(from); | ||
| len -= 3; | ||
| } | ||
| if (len) { | ||
| PUP(out) = PUP(from); | ||
| if (len > 1) | ||
| PUP(out) = PUP(from); | ||
| } | ||
| } | ||
| else { | ||
| from = out - dist; /* copy direct from output */ | ||
| do { /* minimum length is three */ | ||
| PUP(out) = PUP(from); | ||
| PUP(out) = PUP(from); | ||
| PUP(out) = PUP(from); | ||
| len -= 3; | ||
| } while (len > 2); | ||
| if (len) { | ||
| PUP(out) = PUP(from); | ||
| if (len > 1) | ||
| PUP(out) = PUP(from); | ||
| } | ||
| } | ||
| } | ||
| else if ((op & 64) == 0) { /* 2nd level distance code */ | ||
| here = dcode[here.val + (hold & ((1U << op) - 1))]; | ||
| goto dodist; | ||
| } | ||
| else { | ||
| strm->msg = (char *)"invalid distance code"; | ||
| state->mode = BAD; | ||
| break; | ||
| } | ||
| } | ||
| else if ((op & 64) == 0) { /* 2nd level length code */ | ||
| here = lcode[here.val + (hold & ((1U << op) - 1))]; | ||
| goto dolen; | ||
| } | ||
| else if (op & 32) { /* end-of-block */ | ||
| Tracevv((stderr, "inflate: end of block\n")); | ||
| state->mode = TYPE; | ||
| break; | ||
| } | ||
| else { | ||
| strm->msg = (char *)"invalid literal/length code"; | ||
| state->mode = BAD; | ||
| break; | ||
| } | ||
| } while (in < last && out < end); | ||
|
|
||
| /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ | ||
| len = bits >> 3; | ||
| in -= len; | ||
| bits -= len << 3; | ||
| hold &= (1U << bits) - 1; | ||
|
|
||
| /* update state and return */ | ||
| strm->next_in = in + OFF; | ||
| strm->next_out = out + OFF; | ||
| strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); | ||
| strm->avail_out = (unsigned)(out < end ? | ||
| 257 + (end - out) : 257 - (out - end)); | ||
| state->hold = hold; | ||
| state->bits = bits; | ||
| return; | ||
| } | ||
|
|
||
| /* | ||
| inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): | ||
| - Using bit fields for code structure | ||
| - Different op definition to avoid & for extra bits (do & for table bits) | ||
| - Three separate decoding do-loops for direct, window, and wnext == 0 | ||
| - Special case for distance > 1 copies to do overlapped load and store copy | ||
| - Explicit branch predictions (based on measured branch probabilities) | ||
| - Deferring match copy and interspersed it with decoding subsequent codes | ||
| - Swapping literal/length else | ||
| - Swapping window/direct else | ||
| - Larger unrolled copy loops (three is about right) | ||
| - Moving len -= 3 statement into middle of loop | ||
| */ | ||
|
|
||
| #endif /* !ASMINF */ |
| @@ -0,0 +1,11 @@ | ||
| /* inffast.h -- header to use inffast.c | ||
| * Copyright (C) 1995-2003, 2010 Mark Adler | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| /* WARNING: this file should *not* be used by applications. It is | ||
| part of the implementation of the compression library and is | ||
| subject to change. Applications should only use zlib.h. | ||
| */ | ||
|
|
||
| void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); |
| @@ -0,0 +1,94 @@ | ||
| /* inffixed.h -- table for decoding fixed codes | ||
| * Generated automatically by makefixed(). | ||
| */ | ||
|
|
||
| /* WARNING: this file should *not* be used by applications. | ||
| It is part of the implementation of this library and is | ||
| subject to change. Applications should only use zlib.h. | ||
| */ | ||
|
|
||
| static const code lenfix[512] = { | ||
| {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, | ||
| {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, | ||
| {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, | ||
| {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, | ||
| {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, | ||
| {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, | ||
| {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, | ||
| {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, | ||
| {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, | ||
| {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, | ||
| {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, | ||
| {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, | ||
| {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, | ||
| {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, | ||
| {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, | ||
| {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, | ||
| {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, | ||
| {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, | ||
| {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, | ||
| {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, | ||
| {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, | ||
| {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, | ||
| {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, | ||
| {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, | ||
| {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, | ||
| {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, | ||
| {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, | ||
| {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, | ||
| {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, | ||
| {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, | ||
| {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, | ||
| {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, | ||
| {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, | ||
| {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, | ||
| {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, | ||
| {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, | ||
| {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, | ||
| {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, | ||
| {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, | ||
| {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, | ||
| {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, | ||
| {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, | ||
| {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, | ||
| {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, | ||
| {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, | ||
| {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, | ||
| {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, | ||
| {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, | ||
| {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, | ||
| {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, | ||
| {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, | ||
| {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, | ||
| {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, | ||
| {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, | ||
| {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, | ||
| {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, | ||
| {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, | ||
| {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, | ||
| {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, | ||
| {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, | ||
| {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, | ||
| {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, | ||
| {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, | ||
| {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, | ||
| {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, | ||
| {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, | ||
| {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, | ||
| {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, | ||
| {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, | ||
| {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, | ||
| {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, | ||
| {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, | ||
| {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, | ||
| {0,9,255} | ||
| }; | ||
|
|
||
| static const code distfix[32] = { | ||
| {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, | ||
| {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, | ||
| {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, | ||
| {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, | ||
| {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, | ||
| {22,5,193},{64,5,0} | ||
| }; |
| @@ -0,0 +1,122 @@ | ||
| /* inflate.h -- internal inflate state definition | ||
| * Copyright (C) 1995-2009 Mark Adler | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| /* WARNING: this file should *not* be used by applications. It is | ||
| part of the implementation of the compression library and is | ||
| subject to change. Applications should only use zlib.h. | ||
| */ | ||
|
|
||
| /* define NO_GZIP when compiling if you want to disable gzip header and | ||
| trailer decoding by inflate(). NO_GZIP would be used to avoid linking in | ||
| the crc code when it is not needed. For shared libraries, gzip decoding | ||
| should be left enabled. */ | ||
| #ifndef NO_GZIP | ||
| # define GUNZIP | ||
| #endif | ||
|
|
||
| /* Possible inflate modes between inflate() calls */ | ||
| typedef enum { | ||
| HEAD, /* i: waiting for magic header */ | ||
| FLAGS, /* i: waiting for method and flags (gzip) */ | ||
| TIME, /* i: waiting for modification time (gzip) */ | ||
| OS, /* i: waiting for extra flags and operating system (gzip) */ | ||
| EXLEN, /* i: waiting for extra length (gzip) */ | ||
| EXTRA, /* i: waiting for extra bytes (gzip) */ | ||
| NAME, /* i: waiting for end of file name (gzip) */ | ||
| COMMENT, /* i: waiting for end of comment (gzip) */ | ||
| HCRC, /* i: waiting for header crc (gzip) */ | ||
| DICTID, /* i: waiting for dictionary check value */ | ||
| DICT, /* waiting for inflateSetDictionary() call */ | ||
| TYPE, /* i: waiting for type bits, including last-flag bit */ | ||
| TYPEDO, /* i: same, but skip check to exit inflate on new block */ | ||
| STORED, /* i: waiting for stored size (length and complement) */ | ||
| COPY_, /* i/o: same as COPY below, but only first time in */ | ||
| COPY, /* i/o: waiting for input or output to copy stored block */ | ||
| TABLE, /* i: waiting for dynamic block table lengths */ | ||
| LENLENS, /* i: waiting for code length code lengths */ | ||
| CODELENS, /* i: waiting for length/lit and distance code lengths */ | ||
| LEN_, /* i: same as LEN below, but only first time in */ | ||
| LEN, /* i: waiting for length/lit/eob code */ | ||
| LENEXT, /* i: waiting for length extra bits */ | ||
| DIST, /* i: waiting for distance code */ | ||
| DISTEXT, /* i: waiting for distance extra bits */ | ||
| MATCH, /* o: waiting for output space to copy string */ | ||
| LIT, /* o: waiting for output space to write literal */ | ||
| CHECK, /* i: waiting for 32-bit check value */ | ||
| LENGTH, /* i: waiting for 32-bit length (gzip) */ | ||
| DONE, /* finished check, done -- remain here until reset */ | ||
| BAD, /* got a data error -- remain here until reset */ | ||
| MEM, /* got an inflate() memory error -- remain here until reset */ | ||
| SYNC /* looking for synchronization bytes to restart inflate() */ | ||
| } inflate_mode; | ||
|
|
||
| /* | ||
| State transitions between above modes - | ||
| (most modes can go to BAD or MEM on error -- not shown for clarity) | ||
| Process header: | ||
| HEAD -> (gzip) or (zlib) or (raw) | ||
| (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> | ||
| HCRC -> TYPE | ||
| (zlib) -> DICTID or TYPE | ||
| DICTID -> DICT -> TYPE | ||
| (raw) -> TYPEDO | ||
| Read deflate blocks: | ||
| TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK | ||
| STORED -> COPY_ -> COPY -> TYPE | ||
| TABLE -> LENLENS -> CODELENS -> LEN_ | ||
| LEN_ -> LEN | ||
| Read deflate codes in fixed or dynamic block: | ||
| LEN -> LENEXT or LIT or TYPE | ||
| LENEXT -> DIST -> DISTEXT -> MATCH -> LEN | ||
| LIT -> LEN | ||
| Process trailer: | ||
| CHECK -> LENGTH -> DONE | ||
| */ | ||
|
|
||
| /* state maintained between inflate() calls. Approximately 10K bytes. */ | ||
| struct inflate_state { | ||
| inflate_mode mode; /* current inflate mode */ | ||
| int last; /* true if processing last block */ | ||
| int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ | ||
| int havedict; /* true if dictionary provided */ | ||
| int flags; /* gzip header method and flags (0 if zlib) */ | ||
| unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ | ||
| unsigned long check; /* protected copy of check value */ | ||
| unsigned long total; /* protected copy of output count */ | ||
| gz_headerp head; /* where to save gzip header information */ | ||
| /* sliding window */ | ||
| unsigned wbits; /* log base 2 of requested window size */ | ||
| unsigned wsize; /* window size or zero if not using window */ | ||
| unsigned whave; /* valid bytes in the window */ | ||
| unsigned wnext; /* window write index */ | ||
| unsigned char FAR *window; /* allocated sliding window, if needed */ | ||
| /* bit accumulator */ | ||
| unsigned long hold; /* input bit accumulator */ | ||
| unsigned bits; /* number of bits in "in" */ | ||
| /* for string and stored block copying */ | ||
| unsigned length; /* literal or length of data to copy */ | ||
| unsigned offset; /* distance back to copy string from */ | ||
| /* for table and code decoding */ | ||
| unsigned extra; /* extra bits needed */ | ||
| /* fixed and dynamic code tables */ | ||
| code const FAR *lencode; /* starting table for length/literal codes */ | ||
| code const FAR *distcode; /* starting table for distance codes */ | ||
| unsigned lenbits; /* index bits for lencode */ | ||
| unsigned distbits; /* index bits for distcode */ | ||
| /* dynamic table building */ | ||
| unsigned ncode; /* number of code length code lengths */ | ||
| unsigned nlen; /* number of length code lengths */ | ||
| unsigned ndist; /* number of distance code lengths */ | ||
| unsigned have; /* number of code lengths in lens[] */ | ||
| code FAR *next; /* next available space in codes[] */ | ||
| unsigned short lens[320]; /* temporary storage for code lengths */ | ||
| unsigned short work[288]; /* work area for code table building */ | ||
| code codes[ENOUGH]; /* space for code tables */ | ||
| int sane; /* if false, allow invalid distance too far */ | ||
| int back; /* bits back of last unprocessed length/lit */ | ||
| unsigned was; /* initial length of match */ | ||
| }; |
| @@ -0,0 +1,306 @@ | ||
| /* inftrees.c -- generate Huffman trees for efficient decoding | ||
| * Copyright (C) 1995-2012 Mark Adler | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| #include "zutil.h" | ||
| #include "inftrees.h" | ||
|
|
||
| #define MAXBITS 15 | ||
|
|
||
| const char inflate_copyright[] = | ||
| " inflate 1.2.7 Copyright 1995-2012 Mark Adler "; | ||
| /* | ||
| If you use the zlib library in a product, an acknowledgment is welcome | ||
| in the documentation of your product. If for some reason you cannot | ||
| include such an acknowledgment, I would appreciate that you keep this | ||
| copyright string in the executable of your product. | ||
| */ | ||
|
|
||
| /* | ||
| Build a set of tables to decode the provided canonical Huffman code. | ||
| The code lengths are lens[0..codes-1]. The result starts at *table, | ||
| whose indices are 0..2^bits-1. work is a writable array of at least | ||
| lens shorts, which is used as a work area. type is the type of code | ||
| to be generated, CODES, LENS, or DISTS. On return, zero is success, | ||
| -1 is an invalid code, and +1 means that ENOUGH isn't enough. table | ||
| on return points to the next available entry's address. bits is the | ||
| requested root table index bits, and on return it is the actual root | ||
| table index bits. It will differ if the request is greater than the | ||
| longest code or if it is less than the shortest code. | ||
| */ | ||
| int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) | ||
| codetype type; | ||
| unsigned short FAR *lens; | ||
| unsigned codes; | ||
| code FAR * FAR *table; | ||
| unsigned FAR *bits; | ||
| unsigned short FAR *work; | ||
| { | ||
| unsigned len; /* a code's length in bits */ | ||
| unsigned sym; /* index of code symbols */ | ||
| unsigned min, max; /* minimum and maximum code lengths */ | ||
| unsigned root; /* number of index bits for root table */ | ||
| unsigned curr; /* number of index bits for current table */ | ||
| unsigned drop; /* code bits to drop for sub-table */ | ||
| int left; /* number of prefix codes available */ | ||
| unsigned used; /* code entries in table used */ | ||
| unsigned huff; /* Huffman code */ | ||
| unsigned incr; /* for incrementing code, index */ | ||
| unsigned fill; /* index for replicating entries */ | ||
| unsigned low; /* low bits for current root entry */ | ||
| unsigned mask; /* mask for low root bits */ | ||
| code here; /* table entry for duplication */ | ||
| code FAR *next; /* next available space in table */ | ||
| const unsigned short FAR *base; /* base value table to use */ | ||
| const unsigned short FAR *extra; /* extra bits table to use */ | ||
| int end; /* use base and extra for symbol > end */ | ||
| unsigned short count[MAXBITS+1]; /* number of codes of each length */ | ||
| unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ | ||
| static const unsigned short lbase[31] = { /* Length codes 257..285 base */ | ||
| 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, | ||
| 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; | ||
| static const unsigned short lext[31] = { /* Length codes 257..285 extra */ | ||
| 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, | ||
| 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68}; | ||
| static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ | ||
| 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, | ||
| 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, | ||
| 8193, 12289, 16385, 24577, 0, 0}; | ||
| static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ | ||
| 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, | ||
| 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, | ||
| 28, 28, 29, 29, 64, 64}; | ||
|
|
||
| /* | ||
| Process a set of code lengths to create a canonical Huffman code. The | ||
| code lengths are lens[0..codes-1]. Each length corresponds to the | ||
| symbols 0..codes-1. The Huffman code is generated by first sorting the | ||
| symbols by length from short to long, and retaining the symbol order | ||
| for codes with equal lengths. Then the code starts with all zero bits | ||
| for the first code of the shortest length, and the codes are integer | ||
| increments for the same length, and zeros are appended as the length | ||
| increases. For the deflate format, these bits are stored backwards | ||
| from their more natural integer increment ordering, and so when the | ||
| decoding tables are built in the large loop below, the integer codes | ||
| are incremented backwards. | ||
| This routine assumes, but does not check, that all of the entries in | ||
| lens[] are in the range 0..MAXBITS. The caller must assure this. | ||
| 1..MAXBITS is interpreted as that code length. zero means that that | ||
| symbol does not occur in this code. | ||
| The codes are sorted by computing a count of codes for each length, | ||
| creating from that a table of starting indices for each length in the | ||
| sorted table, and then entering the symbols in order in the sorted | ||
| table. The sorted table is work[], with that space being provided by | ||
| the caller. | ||
| The length counts are used for other purposes as well, i.e. finding | ||
| the minimum and maximum length codes, determining if there are any | ||
| codes at all, checking for a valid set of lengths, and looking ahead | ||
| at length counts to determine sub-table sizes when building the | ||
| decoding tables. | ||
| */ | ||
|
|
||
| /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ | ||
| for (len = 0; len <= MAXBITS; len++) | ||
| count[len] = 0; | ||
| for (sym = 0; sym < codes; sym++) | ||
| count[lens[sym]]++; | ||
|
|
||
| /* bound code lengths, force root to be within code lengths */ | ||
| root = *bits; | ||
| for (max = MAXBITS; max >= 1; max--) | ||
| if (count[max] != 0) break; | ||
| if (root > max) root = max; | ||
| if (max == 0) { /* no symbols to code at all */ | ||
| here.op = (unsigned char)64; /* invalid code marker */ | ||
| here.bits = (unsigned char)1; | ||
| here.val = (unsigned short)0; | ||
| *(*table)++ = here; /* make a table to force an error */ | ||
| *(*table)++ = here; | ||
| *bits = 1; | ||
| return 0; /* no symbols, but wait for decoding to report error */ | ||
| } | ||
| for (min = 1; min < max; min++) | ||
| if (count[min] != 0) break; | ||
| if (root < min) root = min; | ||
|
|
||
| /* check for an over-subscribed or incomplete set of lengths */ | ||
| left = 1; | ||
| for (len = 1; len <= MAXBITS; len++) { | ||
| left <<= 1; | ||
| left -= count[len]; | ||
| if (left < 0) return -1; /* over-subscribed */ | ||
| } | ||
| if (left > 0 && (type == CODES || max != 1)) | ||
| return -1; /* incomplete set */ | ||
|
|
||
| /* generate offsets into symbol table for each length for sorting */ | ||
| offs[1] = 0; | ||
| for (len = 1; len < MAXBITS; len++) | ||
| offs[len + 1] = offs[len] + count[len]; | ||
|
|
||
| /* sort symbols by length, by symbol order within each length */ | ||
| for (sym = 0; sym < codes; sym++) | ||
| if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; | ||
|
|
||
| /* | ||
| Create and fill in decoding tables. In this loop, the table being | ||
| filled is at next and has curr index bits. The code being used is huff | ||
| with length len. That code is converted to an index by dropping drop | ||
| bits off of the bottom. For codes where len is less than drop + curr, | ||
| those top drop + curr - len bits are incremented through all values to | ||
| fill the table with replicated entries. | ||
| root is the number of index bits for the root table. When len exceeds | ||
| root, sub-tables are created pointed to by the root entry with an index | ||
| of the low root bits of huff. This is saved in low to check for when a | ||
| new sub-table should be started. drop is zero when the root table is | ||
| being filled, and drop is root when sub-tables are being filled. | ||
| When a new sub-table is needed, it is necessary to look ahead in the | ||
| code lengths to determine what size sub-table is needed. The length | ||
| counts are used for this, and so count[] is decremented as codes are | ||
| entered in the tables. | ||
| used keeps track of how many table entries have been allocated from the | ||
| provided *table space. It is checked for LENS and DIST tables against | ||
| the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in | ||
| the initial root table size constants. See the comments in inftrees.h | ||
| for more information. | ||
| sym increments through all symbols, and the loop terminates when | ||
| all codes of length max, i.e. all codes, have been processed. This | ||
| routine permits incomplete codes, so another loop after this one fills | ||
| in the rest of the decoding tables with invalid code markers. | ||
| */ | ||
|
|
||
| /* set up for code type */ | ||
| switch (type) { | ||
| case CODES: | ||
| base = extra = work; /* dummy value--not used */ | ||
| end = 19; | ||
| break; | ||
| case LENS: | ||
| base = lbase; | ||
| base -= 257; | ||
| extra = lext; | ||
| extra -= 257; | ||
| end = 256; | ||
| break; | ||
| default: /* DISTS */ | ||
| base = dbase; | ||
| extra = dext; | ||
| end = -1; | ||
| } | ||
|
|
||
| /* initialize state for loop */ | ||
| huff = 0; /* starting code */ | ||
| sym = 0; /* starting code symbol */ | ||
| len = min; /* starting code length */ | ||
| next = *table; /* current table to fill in */ | ||
| curr = root; /* current table index bits */ | ||
| drop = 0; /* current bits to drop from code for index */ | ||
| low = (unsigned)(-1); /* trigger new sub-table when len > root */ | ||
| used = 1U << root; /* use root table entries */ | ||
| mask = used - 1; /* mask for comparing low */ | ||
|
|
||
| /* check available table space */ | ||
| if ((type == LENS && used >= ENOUGH_LENS) || | ||
| (type == DISTS && used >= ENOUGH_DISTS)) | ||
| return 1; | ||
|
|
||
| /* process all codes and make table entries */ | ||
| for (;;) { | ||
| /* create table entry */ | ||
| here.bits = (unsigned char)(len - drop); | ||
| if ((int)(work[sym]) < end) { | ||
| here.op = (unsigned char)0; | ||
| here.val = work[sym]; | ||
| } | ||
| else if ((int)(work[sym]) > end) { | ||
| here.op = (unsigned char)(extra[work[sym]]); | ||
| here.val = base[work[sym]]; | ||
| } | ||
| else { | ||
| here.op = (unsigned char)(32 + 64); /* end of block */ | ||
| here.val = 0; | ||
| } | ||
|
|
||
| /* replicate for those indices with low len bits equal to huff */ | ||
| incr = 1U << (len - drop); | ||
| fill = 1U << curr; | ||
| min = fill; /* save offset to next table */ | ||
| do { | ||
| fill -= incr; | ||
| next[(huff >> drop) + fill] = here; | ||
| } while (fill != 0); | ||
|
|
||
| /* backwards increment the len-bit code huff */ | ||
| incr = 1U << (len - 1); | ||
| while (huff & incr) | ||
| incr >>= 1; | ||
| if (incr != 0) { | ||
| huff &= incr - 1; | ||
| huff += incr; | ||
| } | ||
| else | ||
| huff = 0; | ||
|
|
||
| /* go to next symbol, update count, len */ | ||
| sym++; | ||
| if (--(count[len]) == 0) { | ||
| if (len == max) break; | ||
| len = lens[work[sym]]; | ||
| } | ||
|
|
||
| /* create new sub-table if needed */ | ||
| if (len > root && (huff & mask) != low) { | ||
| /* if first time, transition to sub-tables */ | ||
| if (drop == 0) | ||
| drop = root; | ||
|
|
||
| /* increment past last table */ | ||
| next += min; /* here min is 1 << curr */ | ||
|
|
||
| /* determine length of next table */ | ||
| curr = len - drop; | ||
| left = (int)(1 << curr); | ||
| while (curr + drop < max) { | ||
| left -= count[curr + drop]; | ||
| if (left <= 0) break; | ||
| curr++; | ||
| left <<= 1; | ||
| } | ||
|
|
||
| /* check for enough space */ | ||
| used += 1U << curr; | ||
| if ((type == LENS && used >= ENOUGH_LENS) || | ||
| (type == DISTS && used >= ENOUGH_DISTS)) | ||
| return 1; | ||
|
|
||
| /* point entry in root table to sub-table */ | ||
| low = huff & mask; | ||
| (*table)[low].op = (unsigned char)curr; | ||
| (*table)[low].bits = (unsigned char)root; | ||
| (*table)[low].val = (unsigned short)(next - *table); | ||
| } | ||
| } | ||
|
|
||
| /* fill in remaining table entry if code is incomplete (guaranteed to have | ||
| at most one remaining entry, since if the code is incomplete, the | ||
| maximum code length that was allowed to get this far is one bit) */ | ||
| if (huff != 0) { | ||
| here.op = (unsigned char)64; /* invalid code marker */ | ||
| here.bits = (unsigned char)(len - drop); | ||
| here.val = (unsigned short)0; | ||
| next[huff] = here; | ||
| } | ||
|
|
||
| /* set return parameters */ | ||
| *table += used; | ||
| *bits = root; | ||
| return 0; | ||
| } |
| @@ -0,0 +1,62 @@ | ||
| /* inftrees.h -- header to use inftrees.c | ||
| * Copyright (C) 1995-2005, 2010 Mark Adler | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| /* WARNING: this file should *not* be used by applications. It is | ||
| part of the implementation of the compression library and is | ||
| subject to change. Applications should only use zlib.h. | ||
| */ | ||
|
|
||
| /* Structure for decoding tables. Each entry provides either the | ||
| information needed to do the operation requested by the code that | ||
| indexed that table entry, or it provides a pointer to another | ||
| table that indexes more bits of the code. op indicates whether | ||
| the entry is a pointer to another table, a literal, a length or | ||
| distance, an end-of-block, or an invalid code. For a table | ||
| pointer, the low four bits of op is the number of index bits of | ||
| that table. For a length or distance, the low four bits of op | ||
| is the number of extra bits to get after the code. bits is | ||
| the number of bits in this code or part of the code to drop off | ||
| of the bit buffer. val is the actual byte to output in the case | ||
| of a literal, the base length or distance, or the offset from | ||
| the current table to the next table. Each entry is four bytes. */ | ||
| typedef struct { | ||
| unsigned char op; /* operation, extra bits, table bits */ | ||
| unsigned char bits; /* bits in this part of the code */ | ||
| unsigned short val; /* offset in table or code value */ | ||
| } code; | ||
|
|
||
| /* op values as set by inflate_table(): | ||
| 00000000 - literal | ||
| 0000tttt - table link, tttt != 0 is the number of table index bits | ||
| 0001eeee - length or distance, eeee is the number of extra bits | ||
| 01100000 - end of block | ||
| 01000000 - invalid code | ||
| */ | ||
|
|
||
| /* Maximum size of the dynamic table. The maximum number of code structures is | ||
| 1444, which is the sum of 852 for literal/length codes and 592 for distance | ||
| codes. These values were found by exhaustive searches using the program | ||
| examples/enough.c found in the zlib distribtution. The arguments to that | ||
| program are the number of symbols, the initial root table size, and the | ||
| maximum bit length of a code. "enough 286 9 15" for literal/length codes | ||
| returns returns 852, and "enough 30 6 15" for distance codes returns 592. | ||
| The initial root table size (9 or 6) is found in the fifth argument of the | ||
| inflate_table() calls in inflate.c and infback.c. If the root table size is | ||
| changed, then these maximum sizes would be need to be recalculated and | ||
| updated. */ | ||
| #define ENOUGH_LENS 852 | ||
| #define ENOUGH_DISTS 592 | ||
| #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) | ||
|
|
||
| /* Type of code to build for inflate_table() */ | ||
| typedef enum { | ||
| CODES, | ||
| LENS, | ||
| DISTS | ||
| } codetype; | ||
|
|
||
| int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, | ||
| unsigned codes, code FAR * FAR *table, | ||
| unsigned FAR *bits, unsigned short FAR *work)); |
| @@ -0,0 +1,79 @@ | ||
| require 'fileutils' | ||
|
|
||
| USE_STLPORT = true | ||
|
|
||
| puts "zlib extension !" | ||
|
|
||
| namespace "build" do | ||
|
|
||
| task :config do | ||
|
|
||
| $targetdir = ENV['TARGET_TEMP_DIR'] | ||
| raise "TARGET_TEMP_DIR is not set" if $targetdir.nil? | ||
|
|
||
| $tempdir = ENV['TEMP_FILES_DIR'] | ||
| raise "TEMP_FILES_DIR is not set" if $tempdir.nil? | ||
|
|
||
| $rootdir = ENV['RHO_ROOT'] | ||
| raise "RHO_ROOT is not set" if $rootdir.nil? | ||
|
|
||
| $xcodebuild = ENV['XCODEBUILD'] | ||
| raise "XCODEBUILD is not set" if $xcodebuild.nil? | ||
|
|
||
| $configuration = ENV['CONFIGURATION'] | ||
| raise "CONFIGURATION is not set" if $configuration.nil? | ||
|
|
||
| $sdk = ENV['SDK_NAME'] | ||
| raise "SDK_NAME is not set" if $sdk.nil? | ||
|
|
||
| $bindir = ENV['PLATFORM_DEVELOPER_BIN_DIR'] | ||
| raise "PLATFORM_DEVELOPER_BIN_DIR is not set" if $bindir.nil? | ||
|
|
||
| $sdkroot = ENV['SDKROOT'] | ||
| raise "SDKROOT is not set" if $sdkroot.nil? | ||
|
|
||
| $arch = ENV['ARCHS'] | ||
| raise "ARCHS is not set" if $arch.nil? | ||
|
|
||
| $gccbin = $bindir + '/gcc-4.2' | ||
| $arbin = $bindir + '/ar' | ||
|
|
||
| end | ||
|
|
||
| task :all => :config do | ||
|
|
||
| iphone_path = '.' | ||
|
|
||
| simulator = $sdk =~ /iphonesimulator/ | ||
|
|
||
| if $configuration == 'Distribution' | ||
| $configuration = 'Release' | ||
| end | ||
|
|
||
| result_lib = iphone_path + '/build/' + $configuration + '-' + ( simulator ? "iphonesimulator" : "iphoneos") + '/libzlib.a' | ||
| target_lib = $targetdir + '/libzlib.a' | ||
|
|
||
| rm_rf 'build' | ||
| rm_rf target_lib | ||
|
|
||
| args = ['build', '-target', 'zlib', '-configuration', $configuration, '-sdk', $sdk] | ||
|
|
||
| if simulator | ||
| args << '-arch' | ||
| args << 'i386' | ||
| end | ||
|
|
||
| require $rootdir + '/lib/build/jake.rb' | ||
|
|
||
| puts Jake.run($xcodebuild,args) | ||
| ret = $? | ||
|
|
||
| # copy result to $targetdir | ||
| cp result_lib,target_lib | ||
|
|
||
| end | ||
|
|
||
|
|
||
| end | ||
|
|
||
| task :default => "build:all" |
| @@ -0,0 +1,266 @@ | ||
| // !$*UTF8*$! | ||
| { | ||
| archiveVersion = 1; | ||
| classes = { | ||
| }; | ||
| objectVersion = 45; | ||
| objects = { | ||
|
|
||
| /* Begin PBXBuildFile section */ | ||
| FA64196B14A25397001BDDEC /* zip.h in Headers */ = {isa = PBXBuildFile; fileRef = FA64196814A25397001BDDEC /* zip.h */; }; | ||
| FA64196C14A25397001BDDEC /* zlib.c in Sources */ = {isa = PBXBuildFile; fileRef = FA64196914A25397001BDDEC /* zlib.c */; }; | ||
| FAC155E7145855CF0016F3BD /* zlib_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = FAD45FD51225FED600141873 /* zlib_Prefix.pch */; }; | ||
| FAC155EE145855CF0016F3BD /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; | ||
| FAC155EF145855CF0016F3BD /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAD4602C12260A8500141873 /* UIKit.framework */; }; | ||
| /* End PBXBuildFile section */ | ||
|
|
||
| /* Begin PBXFileReference section */ | ||
| AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; | ||
| FA64196814A25397001BDDEC /* zip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = zip.h; path = ../zip.h; sourceTree = "<group>"; }; | ||
| FA64196914A25397001BDDEC /* zlib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = zlib.c; path = ../zlib.c; sourceTree = "<group>"; }; | ||
| FAC155F3145855CF0016F3BD /* libzlib.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libzlib.a; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
| FAD45FD51225FED600141873 /* zlib_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = zlib_Prefix.pch; sourceTree = "<group>"; }; | ||
| FAD4602C12260A8500141873 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; | ||
| /* End PBXFileReference section */ | ||
|
|
||
| /* Begin PBXFrameworksBuildPhase section */ | ||
| FAC155ED145855CF0016F3BD /* Frameworks */ = { | ||
| isa = PBXFrameworksBuildPhase; | ||
| buildActionMask = 2147483647; | ||
| files = ( | ||
| FAC155EE145855CF0016F3BD /* Foundation.framework in Frameworks */, | ||
| FAC155EF145855CF0016F3BD /* UIKit.framework in Frameworks */, | ||
| ); | ||
| runOnlyForDeploymentPostprocessing = 0; | ||
| }; | ||
| /* End PBXFrameworksBuildPhase section */ | ||
|
|
||
| /* Begin PBXGroup section */ | ||
| 034768DFFF38A50411DB9C8B /* Products */ = { | ||
| isa = PBXGroup; | ||
| children = ( | ||
| FAC155F3145855CF0016F3BD /* libzlib.a */, | ||
| ); | ||
| name = Products; | ||
| sourceTree = "<group>"; | ||
| }; | ||
| 0867D691FE84028FC02AAC07 /* Barcode */ = { | ||
| isa = PBXGroup; | ||
| children = ( | ||
| 08FB77AEFE84172EC02AAC07 /* Classes */, | ||
| 32C88DFF0371C24200C91783 /* Other Sources */, | ||
| 0867D69AFE84028FC02AAC07 /* Frameworks */, | ||
| 034768DFFF38A50411DB9C8B /* Products */, | ||
| ); | ||
| name = Barcode; | ||
| sourceTree = "<group>"; | ||
| }; | ||
| 0867D69AFE84028FC02AAC07 /* Frameworks */ = { | ||
| isa = PBXGroup; | ||
| children = ( | ||
| AACBBE490F95108600F1A2B1 /* Foundation.framework */, | ||
| FAD4602C12260A8500141873 /* UIKit.framework */, | ||
| ); | ||
| name = Frameworks; | ||
| sourceTree = "<group>"; | ||
| }; | ||
| 08FB77AEFE84172EC02AAC07 /* Classes */ = { | ||
| isa = PBXGroup; | ||
| children = ( | ||
| FA64196814A25397001BDDEC /* zip.h */, | ||
| FA64196914A25397001BDDEC /* zlib.c */, | ||
| ); | ||
| name = Classes; | ||
| sourceTree = "<group>"; | ||
| }; | ||
| 32C88DFF0371C24200C91783 /* Other Sources */ = { | ||
| isa = PBXGroup; | ||
| children = ( | ||
| FAD45FD51225FED600141873 /* zlib_Prefix.pch */, | ||
| ); | ||
| name = "Other Sources"; | ||
| sourceTree = "<group>"; | ||
| }; | ||
| /* End PBXGroup section */ | ||
|
|
||
| /* Begin PBXHeadersBuildPhase section */ | ||
| FAC155E6145855CF0016F3BD /* Headers */ = { | ||
| isa = PBXHeadersBuildPhase; | ||
| buildActionMask = 2147483647; | ||
| files = ( | ||
| FAC155E7145855CF0016F3BD /* zlib_Prefix.pch in Headers */, | ||
| FA64196B14A25397001BDDEC /* zip.h in Headers */, | ||
| ); | ||
| runOnlyForDeploymentPostprocessing = 0; | ||
| }; | ||
| /* End PBXHeadersBuildPhase section */ | ||
|
|
||
| /* Begin PBXNativeTarget section */ | ||
| FAC155E5145855CF0016F3BD /* zlib */ = { | ||
| isa = PBXNativeTarget; | ||
| buildConfigurationList = FAC155F0145855CF0016F3BD /* Build configuration list for PBXNativeTarget "zlib" */; | ||
| buildPhases = ( | ||
| FAC155E6145855CF0016F3BD /* Headers */, | ||
| FAC155E9145855CF0016F3BD /* Sources */, | ||
| FAC155ED145855CF0016F3BD /* Frameworks */, | ||
| ); | ||
| buildRules = ( | ||
| ); | ||
| dependencies = ( | ||
| ); | ||
| name = zlib; | ||
| productName = Barcode; | ||
| productReference = FAC155F3145855CF0016F3BD /* libzlib.a */; | ||
| productType = "com.apple.product-type.library.static"; | ||
| }; | ||
| /* End PBXNativeTarget section */ | ||
|
|
||
| /* Begin PBXProject section */ | ||
| 0867D690FE84028FC02AAC07 /* Project object */ = { | ||
| isa = PBXProject; | ||
| buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "zlib" */; | ||
| compatibilityVersion = "Xcode 3.1"; | ||
| developmentRegion = English; | ||
| hasScannedForEncodings = 1; | ||
| knownRegions = ( | ||
| English, | ||
| Japanese, | ||
| French, | ||
| German, | ||
| ); | ||
| mainGroup = 0867D691FE84028FC02AAC07 /* Barcode */; | ||
| productRefGroup = 034768DFFF38A50411DB9C8B /* Products */; | ||
| projectDirPath = ""; | ||
| projectRoot = ""; | ||
| targets = ( | ||
| FAC155E5145855CF0016F3BD /* zlib */, | ||
| ); | ||
| }; | ||
| /* End PBXProject section */ | ||
|
|
||
| /* Begin PBXSourcesBuildPhase section */ | ||
| FAC155E9145855CF0016F3BD /* Sources */ = { | ||
| isa = PBXSourcesBuildPhase; | ||
| buildActionMask = 2147483647; | ||
| files = ( | ||
| FA64196C14A25397001BDDEC /* zlib.c in Sources */, | ||
| ); | ||
| runOnlyForDeploymentPostprocessing = 0; | ||
| }; | ||
| /* End PBXSourcesBuildPhase section */ | ||
|
|
||
| /* Begin XCBuildConfiguration section */ | ||
| 1DEB922308733DC00010E9CD /* Debug */ = { | ||
| isa = XCBuildConfiguration; | ||
| buildSettings = { | ||
| GCC_C_LANGUAGE_STANDARD = c99; | ||
| GCC_OPTIMIZATION_LEVEL = 0; | ||
| GCC_WARN_ABOUT_RETURN_TYPE = YES; | ||
| GCC_WARN_UNUSED_VARIABLE = YES; | ||
| HEADER_SEARCH_PATHS = ( | ||
| "$(RHO_ROOT)/platform/shared/common", | ||
| "$(RHO_ROOT)/platform/shared/rubyext", | ||
| "$(RHO_ROOT)/platform/shared/ruby/include", | ||
| "$(RHO_ROOT)/platform/shared/ruby/iphone", | ||
| "$(RHO_ROOT)/platform/shared", | ||
| ); | ||
| IPHONEOS_DEPLOYMENT_TARGET = 3.0; | ||
| ONLY_ACTIVE_ARCH = NO; | ||
| PREBINDING = NO; | ||
| SDKROOT = iphonesimulator4.1; | ||
| STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = static; | ||
| }; | ||
| name = Debug; | ||
| }; | ||
| 1DEB922408733DC00010E9CD /* Release */ = { | ||
| isa = XCBuildConfiguration; | ||
| buildSettings = { | ||
| GCC_C_LANGUAGE_STANDARD = c99; | ||
| GCC_WARN_ABOUT_RETURN_TYPE = YES; | ||
| GCC_WARN_UNUSED_VARIABLE = YES; | ||
| HEADER_SEARCH_PATHS = ( | ||
| "$(RHO_ROOT)/platform/shared/common", | ||
| "$(RHO_ROOT)/platform/shared/rubyext", | ||
| "$(RHO_ROOT)/platform/shared/ruby/include", | ||
| "$(RHO_ROOT)/platform/shared/ruby/iphone", | ||
| "$(RHO_ROOT)/platform/shared", | ||
| ); | ||
| IPHONEOS_DEPLOYMENT_TARGET = 3.0; | ||
| ONLY_ACTIVE_ARCH = NO; | ||
| PREBINDING = NO; | ||
| SDKROOT = iphonesimulator4.1; | ||
| STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = static; | ||
| }; | ||
| name = Release; | ||
| }; | ||
| FAC155F1145855CF0016F3BD /* Debug */ = { | ||
| isa = XCBuildConfiguration; | ||
| buildSettings = { | ||
| ALWAYS_SEARCH_USER_PATHS = NO; | ||
| ARCHS = ( | ||
| armv7, | ||
| armv6, | ||
| ); | ||
| COPY_PHASE_STRIP = NO; | ||
| DSTROOT = /tmp/zlib.dst; | ||
| GCC_DYNAMIC_NO_PIC = NO; | ||
| GCC_ENABLE_FIX_AND_CONTINUE = YES; | ||
| GCC_MODEL_TUNING = G5; | ||
| GCC_OPTIMIZATION_LEVEL = 0; | ||
| GCC_PRECOMPILE_PREFIX_HEADER = YES; | ||
| GCC_PREFIX_HEADER = zlib_Prefix.pch; | ||
| INSTALL_PATH = /usr/local/lib; | ||
| IPHONEOS_DEPLOYMENT_TARGET = 3.0; | ||
| MACOSX_DEPLOYMENT_TARGET = 10.5; | ||
| PRODUCT_NAME = zlib; | ||
| SDKROOT = iphoneos; | ||
| VALID_ARCHS = "i386 armv6 armv7"; | ||
| }; | ||
| name = Debug; | ||
| }; | ||
| FAC155F2145855CF0016F3BD /* Release */ = { | ||
| isa = XCBuildConfiguration; | ||
| buildSettings = { | ||
| ALWAYS_SEARCH_USER_PATHS = NO; | ||
| ARCHS = ( | ||
| armv7, | ||
| armv6, | ||
| ); | ||
| DSTROOT = /tmp/zlib.dst; | ||
| GCC_MODEL_TUNING = G5; | ||
| GCC_PRECOMPILE_PREFIX_HEADER = YES; | ||
| GCC_PREFIX_HEADER = zlib_Prefix.pch; | ||
| INSTALL_PATH = /usr/local/lib; | ||
| IPHONEOS_DEPLOYMENT_TARGET = 3.0; | ||
| MACOSX_DEPLOYMENT_TARGET = 10.5; | ||
| PRODUCT_NAME = zlib; | ||
| SDKROOT = iphoneos; | ||
| VALID_ARCHS = "i386 armv6 armv7"; | ||
| }; | ||
| name = Release; | ||
| }; | ||
| /* End XCBuildConfiguration section */ | ||
|
|
||
| /* Begin XCConfigurationList section */ | ||
| 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "zlib" */ = { | ||
| isa = XCConfigurationList; | ||
| buildConfigurations = ( | ||
| 1DEB922308733DC00010E9CD /* Debug */, | ||
| 1DEB922408733DC00010E9CD /* Release */, | ||
| ); | ||
| defaultConfigurationIsVisible = 0; | ||
| defaultConfigurationName = Release; | ||
| }; | ||
| FAC155F0145855CF0016F3BD /* Build configuration list for PBXNativeTarget "zlib" */ = { | ||
| isa = XCConfigurationList; | ||
| buildConfigurations = ( | ||
| FAC155F1145855CF0016F3BD /* Debug */, | ||
| FAC155F2145855CF0016F3BD /* Release */, | ||
| ); | ||
| defaultConfigurationIsVisible = 0; | ||
| defaultConfigurationName = Release; | ||
| }; | ||
| /* End XCConfigurationList section */ | ||
| }; | ||
| rootObject = 0867D690FE84028FC02AAC07 /* Project object */; | ||
| } |
| @@ -0,0 +1,7 @@ | ||
| // | ||
| // Prefix header for all source files of the 'CocoaTouchStaticLibrary' target in the 'CocoaTouchStaticLibrary' project. | ||
| // | ||
|
|
||
| #ifdef __OBJC__ | ||
| #import <Foundation/Foundation.h> | ||
| #endif |
| @@ -0,0 +1,128 @@ | ||
| /* header created automatically with -DGEN_TREES_H */ | ||
|
|
||
| local const ct_data static_ltree[L_CODES+2] = { | ||
| {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, | ||
| {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, | ||
| {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, | ||
| {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, | ||
| {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, | ||
| {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, | ||
| {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, | ||
| {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, | ||
| {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, | ||
| {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, | ||
| {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, | ||
| {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, | ||
| {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, | ||
| {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, | ||
| {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, | ||
| {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, | ||
| {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, | ||
| {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, | ||
| {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, | ||
| {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, | ||
| {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, | ||
| {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, | ||
| {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, | ||
| {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, | ||
| {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, | ||
| {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, | ||
| {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, | ||
| {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, | ||
| {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, | ||
| {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, | ||
| {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, | ||
| {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, | ||
| {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, | ||
| {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, | ||
| {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, | ||
| {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, | ||
| {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, | ||
| {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, | ||
| {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, | ||
| {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, | ||
| {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, | ||
| {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, | ||
| {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, | ||
| {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, | ||
| {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, | ||
| {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, | ||
| {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, | ||
| {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, | ||
| {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, | ||
| {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, | ||
| {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, | ||
| {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, | ||
| {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, | ||
| {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, | ||
| {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, | ||
| {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, | ||
| {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, | ||
| {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} | ||
| }; | ||
|
|
||
| local const ct_data static_dtree[D_CODES] = { | ||
| {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, | ||
| {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, | ||
| {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, | ||
| {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, | ||
| {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, | ||
| {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} | ||
| }; | ||
|
|
||
| const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { | ||
| 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, | ||
| 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, | ||
| 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, | ||
| 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, | ||
| 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, | ||
| 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, | ||
| 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, | ||
| 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, | ||
| 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, | ||
| 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, | ||
| 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, | ||
| 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, | ||
| 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, | ||
| 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, | ||
| 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, | ||
| 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, | ||
| 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, | ||
| 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, | ||
| 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, | ||
| 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, | ||
| 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, | ||
| 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, | ||
| 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | ||
| 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | ||
| 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | ||
| 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 | ||
| }; | ||
|
|
||
| const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { | ||
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, | ||
| 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, | ||
| 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, | ||
| 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, | ||
| 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, | ||
| 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, | ||
| 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, | ||
| 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, | ||
| 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, | ||
| 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, | ||
| 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, | ||
| 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, | ||
| 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 | ||
| }; | ||
|
|
||
| local const int base_length[LENGTH_CODES] = { | ||
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, | ||
| 64, 80, 96, 112, 128, 160, 192, 224, 0 | ||
| }; | ||
|
|
||
| local const int base_dist[D_CODES] = { | ||
| 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, | ||
| 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, | ||
| 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 | ||
| }; | ||
|
|
| @@ -0,0 +1,59 @@ | ||
| /* uncompr.c -- decompress a memory buffer | ||
| * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. | ||
| * For conditions of distribution and use, see copyright notice in zlib.h | ||
| */ | ||
|
|
||
| /* @(#) $Id$ */ | ||
|
|
||
| #define ZLIB_INTERNAL | ||
| #include "zlib.h" | ||
|
|
||
| /* =========================================================================== | ||
| Decompresses the source buffer into the destination buffer. sourceLen is | ||
| the byte length of the source buffer. Upon entry, destLen is the total | ||
| size of the destination buffer, which must be large enough to hold the | ||
| entire uncompressed data. (The size of the uncompressed data must have | ||
| been saved previously by the compressor and transmitted to the decompressor | ||
| by some mechanism outside the scope of this compression library.) | ||
| Upon exit, destLen is the actual size of the compressed buffer. | ||
| uncompress returns Z_OK if success, Z_MEM_ERROR if there was not | ||
| enough memory, Z_BUF_ERROR if there was not enough room in the output | ||
| buffer, or Z_DATA_ERROR if the input data was corrupted. | ||
| */ | ||
| int ZEXPORT uncompress (dest, destLen, source, sourceLen) | ||
| Bytef *dest; | ||
| uLongf *destLen; | ||
| const Bytef *source; | ||
| uLong sourceLen; | ||
| { | ||
| z_stream stream; | ||
| int err; | ||
|
|
||
| stream.next_in = (Bytef*)source; | ||
| stream.avail_in = (uInt)sourceLen; | ||
| /* Check for source > 64K on 16-bit machine: */ | ||
| if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; | ||
|
|
||
| stream.next_out = dest; | ||
| stream.avail_out = (uInt)*destLen; | ||
| if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; | ||
|
|
||
| stream.zalloc = (alloc_func)0; | ||
| stream.zfree = (free_func)0; | ||
|
|
||
| err = inflateInit(&stream); | ||
| if (err != Z_OK) return err; | ||
|
|
||
| err = inflate(&stream, Z_FINISH); | ||
| if (err != Z_STREAM_END) { | ||
| inflateEnd(&stream); | ||
| if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) | ||
| return Z_DATA_ERROR; | ||
| return err; | ||
| } | ||
| *destLen = stream.total_out; | ||
|
|
||
| err = inflateEnd(&stream); | ||
| return err; | ||
| } |