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