misc/libphysfs/physfs_miniz.h
branchphysfslayer
changeset 8524 a65e9bcf0a03
parent 8522 1853628ae285
child 10017 de822cd3df3a
equal deleted inserted replaced
8522:1853628ae285 8524:a65e9bcf0a03
       
     1 /* tinfl.c v1.11 - public domain inflate with zlib header parsing/adler32 checking (inflate-only subset of miniz.c)
       
     2    See "unlicense" statement at the end of this file.
       
     3    Rich Geldreich <richgel99@gmail.com>, last updated May 20, 2011
       
     4    Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
       
     5 
       
     6    The entire decompressor coroutine is implemented in tinfl_decompress(). The other functions are optional high-level helpers.
       
     7 */
       
     8 #ifndef TINFL_HEADER_INCLUDED
       
     9 #define TINFL_HEADER_INCLUDED
       
    10 
       
    11 typedef PHYSFS_uint8 mz_uint8;
       
    12 typedef PHYSFS_sint16 mz_int16;
       
    13 typedef PHYSFS_uint16 mz_uint16;
       
    14 typedef PHYSFS_uint32 mz_uint32;
       
    15 typedef unsigned int mz_uint; 
       
    16 typedef PHYSFS_uint64 mz_uint64;
       
    17 
       
    18 /* For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. */
       
    19 typedef unsigned long mz_ulong;
       
    20 
       
    21 /* Heap allocation callbacks. */
       
    22 typedef void *(*mz_alloc_func)(void *opaque, unsigned int items, unsigned int size);
       
    23 typedef void (*mz_free_func)(void *opaque, void *address);
       
    24 
       
    25 #if defined(_M_IX86) || defined(_M_X64)
       
    26 /* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 if integer loads and stores to unaligned addresses are acceptable on the target platform (slightly faster). */
       
    27 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
       
    28 /* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */
       
    29 #define MINIZ_LITTLE_ENDIAN 1
       
    30 #endif
       
    31 
       
    32 #if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
       
    33 /* Set MINIZ_HAS_64BIT_REGISTERS to 1 if the processor has 64-bit general purpose registers (enables 64-bit bitbuffer in inflator) */
       
    34 #define MINIZ_HAS_64BIT_REGISTERS 1
       
    35 #endif
       
    36 
       
    37 /* Works around MSVC's spammy "warning C4127: conditional expression is constant" message. */
       
    38 #ifdef _MSC_VER
       
    39 #define MZ_MACRO_END while (0, 0)
       
    40 #else
       
    41 #define MZ_MACRO_END while (0)
       
    42 #endif
       
    43 
       
    44 /* Decompression flags. */
       
    45 enum
       
    46 {
       
    47   TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
       
    48   TINFL_FLAG_HAS_MORE_INPUT = 2,
       
    49   TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
       
    50   TINFL_FLAG_COMPUTE_ADLER32 = 8
       
    51 };
       
    52 
       
    53 struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor;
       
    54 
       
    55 /* Max size of LZ dictionary. */
       
    56 #define TINFL_LZ_DICT_SIZE 32768
       
    57 
       
    58 /* Return status. */
       
    59 typedef enum
       
    60 {
       
    61   TINFL_STATUS_BAD_PARAM = -3,
       
    62   TINFL_STATUS_ADLER32_MISMATCH = -2,
       
    63   TINFL_STATUS_FAILED = -1,
       
    64   TINFL_STATUS_DONE = 0,
       
    65   TINFL_STATUS_NEEDS_MORE_INPUT = 1,
       
    66   TINFL_STATUS_HAS_MORE_OUTPUT = 2
       
    67 } tinfl_status;
       
    68 
       
    69 /* Initializes the decompressor to its initial state. */
       
    70 #define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
       
    71 #define tinfl_get_adler32(r) (r)->m_check_adler32
       
    72 
       
    73 /* Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability. */
       
    74 /* This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output. */
       
    75 static tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags);
       
    76 
       
    77 /* Internal/private bits follow. */
       
    78 enum
       
    79 {
       
    80   TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
       
    81   TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
       
    82 };
       
    83 
       
    84 typedef struct
       
    85 {
       
    86   mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
       
    87   mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
       
    88 } tinfl_huff_table;
       
    89 
       
    90 #if MINIZ_HAS_64BIT_REGISTERS
       
    91   #define TINFL_USE_64BIT_BITBUF 1
       
    92 #endif
       
    93 
       
    94 #if TINFL_USE_64BIT_BITBUF
       
    95   typedef mz_uint64 tinfl_bit_buf_t;
       
    96   #define TINFL_BITBUF_SIZE (64)
       
    97 #else
       
    98   typedef mz_uint32 tinfl_bit_buf_t;
       
    99   #define TINFL_BITBUF_SIZE (32)
       
   100 #endif
       
   101 
       
   102 struct tinfl_decompressor_tag
       
   103 {
       
   104   mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
       
   105   tinfl_bit_buf_t m_bit_buf;
       
   106   size_t m_dist_from_out_buf_start;
       
   107   tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
       
   108   mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
       
   109 };
       
   110 
       
   111 #endif /* #ifdef TINFL_HEADER_INCLUDED */
       
   112 
       
   113 /* ------------------- End of Header: Implementation follows. (If you only want the header, define MINIZ_HEADER_FILE_ONLY.) */
       
   114 
       
   115 #ifndef TINFL_HEADER_FILE_ONLY
       
   116 
       
   117 #define MZ_MAX(a,b) (((a)>(b))?(a):(b))
       
   118 #define MZ_MIN(a,b) (((a)<(b))?(a):(b))
       
   119 #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
       
   120 
       
   121 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
       
   122   #define MZ_READ_LE16(p) *((const mz_uint16 *)(p))
       
   123   #define MZ_READ_LE32(p) *((const mz_uint32 *)(p))
       
   124 #else
       
   125   #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))
       
   126   #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U))
       
   127 #endif
       
   128 
       
   129 #define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
       
   130 #define TINFL_MEMSET(p, c, l) memset(p, c, l)
       
   131 
       
   132 #define TINFL_CR_BEGIN switch(r->m_state) { case 0:
       
   133 #define TINFL_CR_RETURN(state_index, result) do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END
       
   134 #define TINFL_CR_RETURN_FOREVER(state_index, result) do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END
       
   135 #define TINFL_CR_FINISH }
       
   136 
       
   137 /* TODO: If the caller has indicated that there's no more input, and we attempt to read beyond the input buf, then something is wrong with the input because the inflator never */
       
   138 /* reads ahead more than it needs to. Currently TINFL_GET_BYTE() pads the end of the stream with 0's in this scenario. */
       
   139 #define TINFL_GET_BYTE(state_index, c) do { \
       
   140   if (pIn_buf_cur >= pIn_buf_end) { \
       
   141     for ( ; ; ) { \
       
   142       if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \
       
   143         TINFL_CR_RETURN(state_index, TINFL_STATUS_NEEDS_MORE_INPUT); \
       
   144         if (pIn_buf_cur < pIn_buf_end) { \
       
   145           c = *pIn_buf_cur++; \
       
   146           break; \
       
   147         } \
       
   148       } else { \
       
   149         c = 0; \
       
   150         break; \
       
   151       } \
       
   152     } \
       
   153   } else c = *pIn_buf_cur++; } MZ_MACRO_END
       
   154 
       
   155 #define TINFL_NEED_BITS(state_index, n) do { mz_uint c; TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; } while (num_bits < (mz_uint)(n))
       
   156 #define TINFL_SKIP_BITS(state_index, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
       
   157 #define TINFL_GET_BITS(state_index, b, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } b = bit_buf & ((1 << (n)) - 1); bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
       
   158 
       
   159 /* TINFL_HUFF_BITBUF_FILL() is only used rarely, when the number of bytes remaining in the input buffer falls below 2. */
       
   160 /* It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a */
       
   161 /* Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the */
       
   162 /* bit buffer contains >=15 bits (deflate's max. Huffman code size). */
       
   163 #define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \
       
   164   do { \
       
   165     temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
       
   166     if (temp >= 0) { \
       
   167       code_len = temp >> 9; \
       
   168       if ((code_len) && (num_bits >= code_len)) \
       
   169       break; \
       
   170     } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \
       
   171        code_len = TINFL_FAST_LOOKUP_BITS; \
       
   172        do { \
       
   173           temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
       
   174        } while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \
       
   175     } TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \
       
   176   } while (num_bits < 15);
       
   177 
       
   178 /* TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read */
       
   179 /* beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully */
       
   180 /* decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32. */
       
   181 /* The slow path is only executed at the very end of the input buffer. */
       
   182 #define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \
       
   183   int temp; mz_uint code_len, c; \
       
   184   if (num_bits < 15) { \
       
   185     if ((pIn_buf_end - pIn_buf_cur) < 2) { \
       
   186        TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
       
   187     } else { \
       
   188        bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \
       
   189     } \
       
   190   } \
       
   191   if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
       
   192     code_len = temp >> 9, temp &= 511; \
       
   193   else { \
       
   194     code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \
       
   195   } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END
       
   196 
       
   197 static tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags)
       
   198 {
       
   199   static const int s_length_base[31] = { 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 };
       
   200   static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
       
   201   static const int s_dist_base[32] = { 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};
       
   202   static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
       
   203   static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
       
   204   static const int s_min_table_sizes[3] = { 257, 1, 4 };
       
   205 
       
   206   tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf;
       
   207   const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
       
   208   mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
       
   209   size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
       
   210 
       
   211   /* Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter). */
       
   212   if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; }
       
   213 
       
   214   num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start;
       
   215   TINFL_CR_BEGIN
       
   216 
       
   217   bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1;
       
   218   if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
       
   219   {
       
   220     TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1);
       
   221     counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
       
   222     if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
       
   223     if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); }
       
   224   }
       
   225 
       
   226   do
       
   227   {
       
   228     TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1;
       
   229     if (r->m_type == 0)
       
   230     {
       
   231       TINFL_SKIP_BITS(5, num_bits & 7);
       
   232       for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); }
       
   233       if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); }
       
   234       while ((counter) && (num_bits))
       
   235       {
       
   236         TINFL_GET_BITS(51, dist, 8);
       
   237         while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); }
       
   238         *pOut_buf_cur++ = (mz_uint8)dist;
       
   239         counter--;
       
   240       }
       
   241       while (counter)
       
   242       {
       
   243         size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); }
       
   244         while (pIn_buf_cur >= pIn_buf_end)
       
   245         {
       
   246           if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT)
       
   247           {
       
   248             TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT);
       
   249           }
       
   250           else
       
   251           {
       
   252             TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED);
       
   253           }
       
   254         }
       
   255         n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter);
       
   256         TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n;
       
   257       }
       
   258     }
       
   259     else if (r->m_type == 3)
       
   260     {
       
   261       TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
       
   262     }
       
   263     else
       
   264     {
       
   265       if (r->m_type == 1)
       
   266       {
       
   267         mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i;
       
   268         r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
       
   269         for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
       
   270       }
       
   271       else
       
   272       {
       
   273         for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
       
   274         MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
       
   275         r->m_table_sizes[2] = 19;
       
   276       }
       
   277       for ( ; (int)r->m_type >= 0; r->m_type--)
       
   278       {
       
   279         int tree_next, tree_cur; tinfl_huff_table *pTable;
       
   280         mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree);
       
   281         for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
       
   282         used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
       
   283         for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
       
   284         if ((65536 != total) && (used_syms > 1))
       
   285         {
       
   286           TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
       
   287         }
       
   288         for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
       
   289         {
       
   290           mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue;
       
   291           cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
       
   292           if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; }
       
   293           if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
       
   294           rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
       
   295           for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
       
   296           {
       
   297             tree_cur -= ((rev_code >>= 1) & 1);
       
   298             if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1];
       
   299           }
       
   300           tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
       
   301         }
       
   302         if (r->m_type == 2)
       
   303         {
       
   304           for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); )
       
   305           {
       
   306             mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; }
       
   307             if ((dist == 16) && (!counter))
       
   308             {
       
   309               TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED);
       
   310             }
       
   311             num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16];
       
   312             TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s;
       
   313           }
       
   314           if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
       
   315           {
       
   316             TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
       
   317           }
       
   318           TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
       
   319         }
       
   320       }
       
   321       for ( ; ; )
       
   322       {
       
   323         mz_uint8 *pSrc;
       
   324         for ( ; ; )
       
   325         {
       
   326           if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
       
   327           {
       
   328             TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
       
   329             if (counter >= 256)
       
   330               break;
       
   331             while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
       
   332             *pOut_buf_cur++ = (mz_uint8)counter;
       
   333           }
       
   334           else
       
   335           {
       
   336             int sym2; mz_uint code_len;
       
   337 #if TINFL_USE_64BIT_BITBUF
       
   338             if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; }
       
   339 #else
       
   340             if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
       
   341 #endif
       
   342             if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
       
   343               code_len = sym2 >> 9;
       
   344             else
       
   345             {
       
   346               code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
       
   347             }
       
   348             counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
       
   349             if (counter & 256)
       
   350               break;
       
   351 
       
   352 #if !TINFL_USE_64BIT_BITBUF
       
   353             if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
       
   354 #endif
       
   355             if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
       
   356               code_len = sym2 >> 9;
       
   357             else
       
   358             {
       
   359               code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
       
   360             }
       
   361             bit_buf >>= code_len; num_bits -= code_len;
       
   362 
       
   363             pOut_buf_cur[0] = (mz_uint8)counter;
       
   364             if (sym2 & 256)
       
   365             {
       
   366               pOut_buf_cur++;
       
   367               counter = sym2;
       
   368               break;
       
   369             }
       
   370             pOut_buf_cur[1] = (mz_uint8)sym2;
       
   371             pOut_buf_cur += 2;
       
   372           }
       
   373         }
       
   374         if ((counter &= 511) == 256) break;
       
   375 
       
   376         num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
       
   377         if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
       
   378 
       
   379         TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
       
   380         num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
       
   381         if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
       
   382 
       
   383         dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
       
   384         if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
       
   385         {
       
   386           TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
       
   387         }
       
   388 
       
   389         pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
       
   390 
       
   391         if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
       
   392         {
       
   393           while (counter--)
       
   394           {
       
   395             while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); }
       
   396             *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
       
   397           }
       
   398           continue;
       
   399         }
       
   400 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
       
   401         else if ((counter >= 9) && (counter <= dist))
       
   402         {
       
   403           const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
       
   404           do
       
   405           {
       
   406             ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
       
   407             ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
       
   408             pOut_buf_cur += 8;
       
   409           } while ((pSrc += 8) < pSrc_end);
       
   410           if ((counter &= 7) < 3)
       
   411           {
       
   412             if (counter)
       
   413             {
       
   414               pOut_buf_cur[0] = pSrc[0];
       
   415               if (counter > 1)
       
   416                 pOut_buf_cur[1] = pSrc[1];
       
   417               pOut_buf_cur += counter;
       
   418             }
       
   419             continue;
       
   420           }
       
   421         }
       
   422 #endif
       
   423         do
       
   424         {
       
   425           pOut_buf_cur[0] = pSrc[0];
       
   426           pOut_buf_cur[1] = pSrc[1];
       
   427           pOut_buf_cur[2] = pSrc[2];
       
   428           pOut_buf_cur += 3; pSrc += 3;
       
   429         } while ((int)(counter -= 3) > 2);
       
   430         if ((int)counter > 0)
       
   431         {
       
   432           pOut_buf_cur[0] = pSrc[0];
       
   433           if ((int)counter > 1)
       
   434             pOut_buf_cur[1] = pSrc[1];
       
   435           pOut_buf_cur += counter;
       
   436         }
       
   437       }
       
   438     }
       
   439   } while (!(r->m_final & 1));
       
   440   if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
       
   441   {
       
   442     TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; }
       
   443   }
       
   444   TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE);
       
   445   TINFL_CR_FINISH
       
   446 
       
   447 common_exit:
       
   448   r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start;
       
   449   *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
       
   450   if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
       
   451   {
       
   452     const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size;
       
   453     mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552;
       
   454     while (buf_len)
       
   455     {
       
   456       for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
       
   457       {
       
   458         s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
       
   459         s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
       
   460       }
       
   461       for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
       
   462       s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
       
   463     }
       
   464     r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH;
       
   465   }
       
   466   return status;
       
   467 }
       
   468 
       
   469 /* Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other stuff is for advanced use. */
       
   470 enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
       
   471 
       
   472 /* Return status codes. MZ_PARAM_ERROR is non-standard. */
       
   473 enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
       
   474 
       
   475 /* Compression levels. */
       
   476 enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_DEFAULT_COMPRESSION = -1 };
       
   477 
       
   478 /* Window bits */
       
   479 #define MZ_DEFAULT_WINDOW_BITS 15
       
   480 
       
   481 struct mz_internal_state;
       
   482 
       
   483 /* Compression/decompression stream struct. */
       
   484 typedef struct mz_stream_s
       
   485 {
       
   486   const unsigned char *next_in;     /* pointer to next byte to read */
       
   487   unsigned int avail_in;            /* number of bytes available at next_in */
       
   488   mz_ulong total_in;                /* total number of bytes consumed so far */
       
   489 
       
   490   unsigned char *next_out;          /* pointer to next byte to write */
       
   491   unsigned int avail_out;           /* number of bytes that can be written to next_out */
       
   492   mz_ulong total_out;               /* total number of bytes produced so far */
       
   493 
       
   494   char *msg;                        /* error msg (unused) */
       
   495   struct mz_internal_state *state;  /* internal state, allocated by zalloc/zfree */
       
   496 
       
   497   mz_alloc_func zalloc;             /* optional heap allocation function (defaults to malloc) */
       
   498   mz_free_func zfree;               /* optional heap free function (defaults to free) */
       
   499   void *opaque;                     /* heap alloc function user pointer */
       
   500 
       
   501   int data_type;                    /* data_type (unused) */
       
   502   mz_ulong adler;                   /* adler32 of the source or uncompressed data */
       
   503   mz_ulong reserved;                /* not used */
       
   504 } mz_stream;
       
   505 
       
   506 typedef mz_stream *mz_streamp;
       
   507 
       
   508 
       
   509 typedef struct
       
   510 {
       
   511   tinfl_decompressor m_decomp;
       
   512   mz_uint m_dict_ofs, m_dict_avail, m_first_call, m_has_flushed; int m_window_bits;
       
   513   mz_uint8 m_dict[TINFL_LZ_DICT_SIZE];
       
   514   tinfl_status m_last_status;
       
   515 } inflate_state;
       
   516 
       
   517 static int mz_inflateInit2(mz_streamp pStream, int window_bits)
       
   518 {
       
   519   inflate_state *pDecomp;
       
   520   if (!pStream) return MZ_STREAM_ERROR;
       
   521   if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)) return MZ_PARAM_ERROR;
       
   522 
       
   523   pStream->data_type = 0;
       
   524   pStream->adler = 0;
       
   525   pStream->msg = NULL;
       
   526   pStream->total_in = 0;
       
   527   pStream->total_out = 0;
       
   528   pStream->reserved = 0;
       
   529   /* if (!pStream->zalloc) pStream->zalloc = def_alloc_func; */
       
   530   /* if (!pStream->zfree) pStream->zfree = def_free_func; */
       
   531 
       
   532   pDecomp = (inflate_state*)pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state));
       
   533   if (!pDecomp) return MZ_MEM_ERROR;
       
   534 
       
   535   pStream->state = (struct mz_internal_state *)pDecomp;
       
   536 
       
   537   tinfl_init(&pDecomp->m_decomp);
       
   538   pDecomp->m_dict_ofs = 0;
       
   539   pDecomp->m_dict_avail = 0;
       
   540   pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT;
       
   541   pDecomp->m_first_call = 1;
       
   542   pDecomp->m_has_flushed = 0;
       
   543   pDecomp->m_window_bits = window_bits;
       
   544 
       
   545   return MZ_OK;
       
   546 }
       
   547 
       
   548 static int mz_inflate(mz_streamp pStream, int flush)
       
   549 {
       
   550   inflate_state* pState;
       
   551   mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32;
       
   552   size_t in_bytes, out_bytes, orig_avail_in;
       
   553   tinfl_status status;
       
   554 
       
   555   if ((!pStream) || (!pStream->state)) return MZ_STREAM_ERROR;
       
   556   if (flush == MZ_PARTIAL_FLUSH) flush = MZ_SYNC_FLUSH;
       
   557   if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH)) return MZ_STREAM_ERROR;
       
   558 
       
   559   pState = (inflate_state*)pStream->state;
       
   560   if (pState->m_window_bits > 0) decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER;
       
   561   orig_avail_in = pStream->avail_in;
       
   562 
       
   563   first_call = pState->m_first_call; pState->m_first_call = 0;
       
   564   if (pState->m_last_status < 0) return MZ_DATA_ERROR;
       
   565 
       
   566   if (pState->m_has_flushed && (flush != MZ_FINISH)) return MZ_STREAM_ERROR;
       
   567   pState->m_has_flushed |= (flush == MZ_FINISH);
       
   568 
       
   569   if ((flush == MZ_FINISH) && (first_call))
       
   570   {
       
   571     /* MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. */
       
   572     decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
       
   573     in_bytes = pStream->avail_in; out_bytes = pStream->avail_out;
       
   574     status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags);
       
   575     pState->m_last_status = status;
       
   576     pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes;
       
   577     pStream->adler = tinfl_get_adler32(&pState->m_decomp);
       
   578     pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes; pStream->total_out += (mz_uint)out_bytes;
       
   579 
       
   580     if (status < 0)
       
   581       return MZ_DATA_ERROR;
       
   582     else if (status != TINFL_STATUS_DONE)
       
   583     {
       
   584       pState->m_last_status = TINFL_STATUS_FAILED;
       
   585       return MZ_BUF_ERROR;
       
   586     }
       
   587     return MZ_STREAM_END;
       
   588   }
       
   589   /* flush != MZ_FINISH then we must assume there's more input. */
       
   590   if (flush != MZ_FINISH) decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;
       
   591 
       
   592   if (pState->m_dict_avail)
       
   593   {
       
   594     n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
       
   595     memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
       
   596     pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n;
       
   597     pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
       
   598     return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
       
   599   }
       
   600 
       
   601   for ( ; ; )
       
   602   {
       
   603     in_bytes = pStream->avail_in;
       
   604     out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs;
       
   605 
       
   606     status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags);
       
   607     pState->m_last_status = status;
       
   608 
       
   609     pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes;
       
   610     pStream->total_in += (mz_uint)in_bytes; pStream->adler = tinfl_get_adler32(&pState->m_decomp);
       
   611 
       
   612     pState->m_dict_avail = (mz_uint)out_bytes;
       
   613 
       
   614     n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
       
   615     memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
       
   616     pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n;
       
   617     pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
       
   618 
       
   619     if (status < 0)
       
   620        return MZ_DATA_ERROR; /* Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). */
       
   621     else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
       
   622       return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. */
       
   623     else if (flush == MZ_FINISH)
       
   624     {
       
   625        /* The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. */
       
   626        if (status == TINFL_STATUS_DONE)
       
   627           return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END;
       
   628        /* status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. */
       
   629        else if (!pStream->avail_out)
       
   630           return MZ_BUF_ERROR;
       
   631     }
       
   632     else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail))
       
   633       break;
       
   634   }
       
   635 
       
   636   return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
       
   637 }
       
   638 
       
   639 static int mz_inflateEnd(mz_streamp pStream)
       
   640 {
       
   641   if (!pStream)
       
   642     return MZ_STREAM_ERROR;
       
   643   if (pStream->state)
       
   644   {
       
   645     pStream->zfree(pStream->opaque, pStream->state);
       
   646     pStream->state = NULL;
       
   647   }
       
   648   return MZ_OK;
       
   649 }
       
   650 
       
   651 /* make this a drop-in replacement for zlib... */
       
   652   #define voidpf void*
       
   653   #define uInt unsigned int
       
   654   #define z_stream              mz_stream
       
   655   #define inflateInit2          mz_inflateInit2
       
   656   #define inflate               mz_inflate
       
   657   #define inflateEnd            mz_inflateEnd
       
   658   #define Z_SYNC_FLUSH          MZ_SYNC_FLUSH
       
   659   #define Z_FINISH              MZ_FINISH
       
   660   #define Z_OK                  MZ_OK
       
   661   #define Z_STREAM_END          MZ_STREAM_END
       
   662   #define Z_NEED_DICT           MZ_NEED_DICT
       
   663   #define Z_ERRNO               MZ_ERRNO
       
   664   #define Z_STREAM_ERROR        MZ_STREAM_ERROR
       
   665   #define Z_DATA_ERROR          MZ_DATA_ERROR
       
   666   #define Z_MEM_ERROR           MZ_MEM_ERROR
       
   667   #define Z_BUF_ERROR           MZ_BUF_ERROR
       
   668   #define Z_VERSION_ERROR       MZ_VERSION_ERROR
       
   669   #define MAX_WBITS             15
       
   670 
       
   671 #endif /* #ifndef TINFL_HEADER_FILE_ONLY */
       
   672 
       
   673 /* 
       
   674   This is free and unencumbered software released into the public domain.
       
   675 
       
   676   Anyone is free to copy, modify, publish, use, compile, sell, or
       
   677   distribute this software, either in source code form or as a compiled
       
   678   binary, for any purpose, commercial or non-commercial, and by any
       
   679   means.
       
   680 
       
   681   In jurisdictions that recognize copyright laws, the author or authors
       
   682   of this software dedicate any and all copyright interest in the
       
   683   software to the public domain. We make this dedication for the benefit
       
   684   of the public at large and to the detriment of our heirs and
       
   685   successors. We intend this dedication to be an overt act of
       
   686   relinquishment in perpetuity of all present and future rights to this
       
   687   software under copyright law.
       
   688 
       
   689   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
   690   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
   691   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
   692   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
       
   693   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
       
   694   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
       
   695   OTHER DEALINGS IN THE SOFTWARE.
       
   696 
       
   697   For more information, please refer to <http://unlicense.org/>
       
   698 */