-/*****************************************************************************\r
- * name: unzip.c\r
- *\r
- * desc: IO on .zip files using portions of zlib \r
- *\r
- *\r
- *****************************************************************************/\r
-\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include "unzip.h"\r
-\r
-typedef unsigned char byte;\r
-\r
-/* unzip.h -- IO for uncompress .zip files using zlib \r
- Version 0.15 beta, Mar 19th, 1998,\r
-\r
- Copyright (C) 1998 Gilles Vollant\r
-\r
- This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g\r
- WinZip, InfoZip tools and compatible.\r
- Encryption and multi volume ZipFile (span) are not supported.\r
- Old compressions used by old PKZip 1.x are not supported\r
-\r
- THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE\r
- CAN CHANGE IN FUTURE VERSION !!\r
- I WAIT FEEDBACK at mail info@winimage.com\r
- Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution\r
-\r
- Condition of use and distribution are the same than zlib :\r
-\r
- This software is provided 'as-is', without any express or implied\r
- warranty. In no event will the authors be held liable for any damages\r
- arising from the use of this software.\r
-\r
- Permission is granted to anyone to use this software for any purpose,\r
- including commercial applications, and to alter it and redistribute it\r
- freely, subject to the following restrictions:\r
-\r
- 1. The origin of this software must not be misrepresented; you must not\r
- claim that you wrote the original software. If you use this software\r
- in a product, an acknowledgment in the product documentation would be\r
- appreciated but is not required.\r
- 2. Altered source versions must be plainly marked as such, and must not be\r
- misrepresented as being the original software.\r
- 3. This notice may not be removed or altered from any source distribution.\r
-\r
-\r
-*/\r
-/* for more info about .ZIP format, see \r
- ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip\r
- PkWare has also a specification at :\r
- ftp://ftp.pkware.com/probdesc.zip */\r
-\r
-/* zlib.h -- interface of the 'zlib' general purpose compression library\r
- version 1.1.3, July 9th, 1998\r
-\r
- Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler\r
-\r
- This software is provided 'as-is', without any express or implied\r
- warranty. In no event will the authors be held liable for any damages\r
- arising from the use of this software.\r
-\r
- Permission is granted to anyone to use this software for any purpose,\r
- including commercial applications, and to alter it and redistribute it\r
- freely, subject to the following restrictions:\r
-\r
- 1. The origin of this software must not be misrepresented; you must not\r
- claim that you wrote the original software. If you use this software\r
- in a product, an acknowledgment in the product documentation would be\r
- appreciated but is not required.\r
- 2. Altered source versions must be plainly marked as such, and must not be\r
- misrepresented as being the original software.\r
- 3. This notice may not be removed or altered from any source distribution.\r
-\r
- Jean-loup Gailly Mark Adler\r
- jloup@gzip.org madler@alumni.caltech.edu\r
-\r
-\r
- The data format used by the zlib library is described by RFCs (Request for\r
- Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt\r
- (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).\r
-*/\r
-\r
-/* zconf.h -- configuration of the zlib compression library\r
- * Copyright (C) 1995-1998 Jean-loup Gailly.\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-#ifndef _ZCONF_H\r
-#define _ZCONF_H\r
-\r
-/* Maximum value for memLevel in deflateInit2 */\r
-#ifndef MAX_MEM_LEVEL\r
-# ifdef MAXSEG_64K\r
-# define MAX_MEM_LEVEL 8\r
-# else\r
-# define MAX_MEM_LEVEL 9\r
-# endif\r
-#endif\r
-\r
-/* Maximum value for windowBits in deflateInit2 and inflateInit2.\r
- * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files\r
- * created by gzip. (Files created by minigzip can still be extracted by\r
- * gzip.)\r
- */\r
-#ifndef MAX_WBITS\r
-# define MAX_WBITS 15 /* 32K LZ77 window */\r
-#endif\r
-\r
-/* The memory requirements for deflate are (in bytes):\r
- (1 << (windowBits+2)) + (1 << (memLevel+9))\r
- that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)\r
- plus a few kilobytes for small objects. For example, if you want to reduce\r
- the default memory requirements from 256K to 128K, compile with\r
- make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"\r
- Of course this will generally degrade compression (there's no free lunch).\r
-\r
- The memory requirements for inflate are (in bytes) 1 << windowBits\r
- that is, 32K for windowBits=15 (default value) plus a few kilobytes\r
- for small objects.\r
-*/\r
-\r
- /* Type declarations */\r
-\r
-#ifndef OF /* function prototypes */\r
-#define OF(args) args\r
-#endif\r
-\r
-typedef unsigned char Byte; /* 8 bits */\r
-typedef unsigned int uInt; /* 16 bits or more */\r
-typedef unsigned long uLong; /* 32 bits or more */\r
-typedef Byte *voidp;\r
-\r
-#ifndef SEEK_SET\r
-# define SEEK_SET 0 /* Seek from beginning of file. */\r
-# define SEEK_CUR 1 /* Seek from current position. */\r
-# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */\r
-#endif\r
-\r
-#endif /* _ZCONF_H */\r
-\r
-#define ZLIB_VERSION "1.1.3"\r
-\r
-/* \r
- The 'zlib' compression library provides in-memory compression and\r
- decompression functions, including integrity checks of the uncompressed\r
- data. This version of the library supports only one compression method\r
- (deflation) but other algorithms will be added later and will have the same\r
- stream interface.\r
-\r
- Compression can be done in a single step if the buffers are large\r
- enough (for example if an input file is mmap'ed), or can be done by\r
- repeated calls of the compression function. In the latter case, the\r
- application must provide more input and/or consume the output\r
- (providing more output space) before each call.\r
-\r
- The library also supports reading and writing files in gzip (.gz) format\r
- with an interface similar to that of stdio.\r
-\r
- The library does not install any signal handler. The decoder checks\r
- the consistency of the compressed data, so the library should never\r
- crash even in case of corrupted input.\r
-*/\r
-\r
-/*\r
- The application must update next_in and avail_in when avail_in has\r
- dropped to zero. It must update next_out and avail_out when avail_out\r
- has dropped to zero. The application must initialize zalloc, zfree and\r
- opaque before calling the init function. All other fields are set by the\r
- compression library and must not be updated by the application.\r
-\r
- The opaque value provided by the application will be passed as the first\r
- parameter for calls of zalloc and zfree. This can be useful for custom\r
- memory management. The compression library attaches no meaning to the\r
- opaque value.\r
-\r
- zalloc must return Z_NULL if there is not enough memory for the object.\r
- If zlib is used in a multi-threaded application, zalloc and zfree must be\r
- thread safe.\r
-\r
- On 16-bit systems, the functions zalloc and zfree must be able to allocate\r
- exactly 65536 bytes, but will not be required to allocate more than this\r
- if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,\r
- pointers returned by zalloc for objects of exactly 65536 bytes *must*\r
- have their offset normalized to zero. The default allocation function\r
- provided by this library ensures this (see zutil.c). To reduce memory\r
- requirements and avoid any allocation of 64K objects, at the expense of\r
- compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).\r
-\r
- The fields total_in and total_out can be used for statistics or\r
- progress reports. After compression, total_in holds the total size of\r
- the uncompressed data and may be saved for use in the decompressor\r
- (particularly if the decompressor wants to decompress everything in\r
- a single step).\r
-*/\r
-\r
- /* constants */\r
-\r
-#define Z_NO_FLUSH 0\r
-#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */\r
-#define Z_SYNC_FLUSH 2\r
-#define Z_FULL_FLUSH 3\r
-#define Z_FINISH 4\r
-/* Allowed flush values; see deflate() below for details */\r
-\r
-#define Z_OK 0\r
-#define Z_STREAM_END 1\r
-#define Z_NEED_DICT 2\r
-#define Z_ERRNO (-1)\r
-#define Z_STREAM_ERROR (-2)\r
-#define Z_DATA_ERROR (-3)\r
-#define Z_MEM_ERROR (-4)\r
-#define Z_BUF_ERROR (-5)\r
-#define Z_VERSION_ERROR (-6)\r
-/* Return codes for the compression/decompression functions. Negative\r
- * values are errors, positive values are used for special but normal events.\r
- */\r
-\r
-#define Z_NO_COMPRESSION 0\r
-#define Z_BEST_SPEED 1\r
-#define Z_BEST_COMPRESSION 9\r
-#define Z_DEFAULT_COMPRESSION (-1)\r
-/* compression levels */\r
-\r
-#define Z_FILTERED 1\r
-#define Z_HUFFMAN_ONLY 2\r
-#define Z_DEFAULT_STRATEGY 0\r
-/* compression strategy; see deflateInit2() below for details */\r
-\r
-#define Z_BINARY 0\r
-#define Z_ASCII 1\r
-#define Z_UNKNOWN 2\r
-/* Possible values of the data_type field */\r
-\r
-#define Z_DEFLATED 8\r
-/* The deflate compression method (the only one supported in this version) */\r
-\r
-#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */\r
-\r
-#define zlib_version zlibVersion()\r
-/* for compatibility with versions < 1.0.2 */\r
-\r
- /* basic functions */\r
-\r
-const char * zlibVersion OF((void));\r
-/* The application can compare zlibVersion and ZLIB_VERSION for consistency.\r
- If the first character differs, the library code actually used is\r
- not compatible with the zlib.h header file used by the application.\r
- This check is automatically made by deflateInit and inflateInit.\r
- */\r
-\r
-/* \r
-int deflateInit OF((z_streamp strm, int level));\r
-\r
- Initializes the internal stream state for compression. The fields\r
- zalloc, zfree and opaque must be initialized before by the caller.\r
- If zalloc and zfree are set to Z_NULL, deflateInit updates them to\r
- use default allocation functions.\r
-\r
- The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:\r
- 1 gives best speed, 9 gives best compression, 0 gives no compression at\r
- all (the input data is simply copied a block at a time).\r
- Z_DEFAULT_COMPRESSION requests a default compromise between speed and\r
- compression (currently equivalent to level 6).\r
-\r
- deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not\r
- enough memory, Z_STREAM_ERROR if level is not a valid compression level,\r
- Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible\r
- with the version assumed by the caller (ZLIB_VERSION).\r
- msg is set to null if there is no error message. deflateInit does not\r
- perform any compression: this will be done by deflate().\r
-*/\r
-\r
-\r
-int deflate OF((z_streamp strm, int flush));\r
-/*\r
- deflate compresses as much data as possible, and stops when the input\r
- buffer becomes empty or the output buffer becomes full. It may introduce some\r
- output latency (reading input without producing any output) except when\r
- forced to flush.\r
-\r
- The detailed semantics are as follows. deflate performs one or both of the\r
- following actions:\r
-\r
- - Compress more input starting at next_in and update next_in and avail_in\r
- accordingly. If not all input can be processed (because there is not\r
- enough room in the output buffer), next_in and avail_in are updated and\r
- processing will resume at this point for the next call of deflate().\r
-\r
- - Provide more output starting at next_out and update next_out and avail_out\r
- accordingly. This action is forced if the parameter flush is non zero.\r
- Forcing flush frequently degrades the compression ratio, so this parameter\r
- should be set only when necessary (in interactive applications).\r
- Some output may be provided even if flush is not set.\r
-\r
- Before the call of deflate(), the application should ensure that at least\r
- one of the actions is possible, by providing more input and/or consuming\r
- more output, and updating avail_in or avail_out accordingly; avail_out\r
- should never be zero before the call. The application can consume the\r
- compressed output when it wants, for example when the output buffer is full\r
- (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK\r
- and with zero avail_out, it must be called again after making room in the\r
- output buffer because there might be more output pending.\r
-\r
- If the parameter flush is set to Z_SYNC_FLUSH, all pending output is\r
- flushed to the output buffer and the output is aligned on a byte boundary, so\r
- that the decompressor can get all input data available so far. (In particular\r
- avail_in is zero after the call if enough output space has been provided\r
- before the call.) Flushing may degrade compression for some compression\r
- algorithms and so it should be used only when necessary.\r
-\r
- If flush is set to Z_FULL_FLUSH, all output is flushed as with\r
- Z_SYNC_FLUSH, and the compression state is reset so that decompression can\r
- restart from this point if previous compressed data has been damaged or if\r
- random access is desired. Using Z_FULL_FLUSH too often can seriously degrade\r
- the compression.\r
-\r
- If deflate returns with avail_out == 0, this function must be called again\r
- with the same value of the flush parameter and more output space (updated\r
- avail_out), until the flush is complete (deflate returns with non-zero\r
- avail_out).\r
-\r
- If the parameter flush is set to Z_FINISH, pending input is processed,\r
- pending output is flushed and deflate returns with Z_STREAM_END if there\r
- was enough output space; if deflate returns with Z_OK, this function must be\r
- called again with Z_FINISH and more output space (updated avail_out) but no\r
- more input data, until it returns with Z_STREAM_END or an error. After\r
- deflate has returned Z_STREAM_END, the only possible operations on the\r
- stream are deflateReset or deflateEnd.\r
- \r
- Z_FINISH can be used immediately after deflateInit if all the compression\r
- is to be done in a single step. In this case, avail_out must be at least\r
- 0.1% larger than avail_in plus 12 bytes. If deflate does not return\r
- Z_STREAM_END, then it must be called again as described above.\r
-\r
- deflate() sets strm->adler to the adler32 checksum of all input read\r
- so (that is, total_in bytes).\r
-\r
- deflate() may update data_type if it can make a good guess about\r
- the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered\r
- binary. This field is only for information purposes and does not affect\r
- the compression algorithm in any manner.\r
-\r
- deflate() returns Z_OK if some progress has been made (more input\r
- processed or more output produced), Z_STREAM_END if all input has been\r
- consumed and all output has been produced (only when flush is set to\r
- Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example\r
- if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible\r
- (for example avail_in or avail_out was zero).\r
-*/\r
-\r
-\r
-int deflateEnd OF((z_streamp strm));\r
-/*\r
- All dynamically allocated data structures for this stream are freed.\r
- This function discards any unprocessed input and does not flush any\r
- pending output.\r
-\r
- deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the\r
- stream state was inconsistent, Z_DATA_ERROR if the stream was freed\r
- prematurely (some input or output was discarded). In the error case,\r
- msg may be set but then points to a static string (which must not be\r
- deallocated).\r
-*/\r
-\r
-\r
-/* \r
-int inflateInit OF((z_streamp strm));\r
-\r
- Initializes the internal stream state for decompression. The fields\r
- next_in, avail_in, zalloc, zfree and opaque must be initialized before by\r
- the caller. If next_in is not Z_NULL and avail_in is large enough (the exact\r
- value depends on the compression method), inflateInit determines the\r
- compression method from the zlib header and allocates all data structures\r
- accordingly; otherwise the allocation will be deferred to the first call of\r
- inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to\r
- use default allocation functions.\r
-\r
- inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
- memory, Z_VERSION_ERROR if the zlib library version is incompatible with the\r
- version assumed by the caller. msg is set to null if there is no error\r
- message. inflateInit does not perform any decompression apart from reading\r
- the zlib header if present: this will be done by inflate(). (So next_in and\r
- avail_in may be modified, but next_out and avail_out are unchanged.)\r
-*/\r
-\r
-\r
-int inflate OF((z_streamp strm, int flush));\r
-/*\r
- inflate decompresses as much data as possible, and stops when the input\r
- buffer becomes empty or the output buffer becomes full. It may some\r
- introduce some output latency (reading input without producing any output)\r
- except when forced to flush.\r
-\r
- The detailed semantics are as follows. inflate performs one or both of the\r
- following actions:\r
-\r
- - Decompress more input starting at next_in and update next_in and avail_in\r
- accordingly. If not all input can be processed (because there is not\r
- enough room in the output buffer), next_in is updated and processing\r
- will resume at this point for the next call of inflate().\r
-\r
- - Provide more output starting at next_out and update next_out and avail_out\r
- accordingly. inflate() provides as much output as possible, until there\r
- is no more input data or no more space in the output buffer (see below\r
- about the flush parameter).\r
-\r
- Before the call of inflate(), the application should ensure that at least\r
- one of the actions is possible, by providing more input and/or consuming\r
- more output, and updating the next_* and avail_* values accordingly.\r
- The application can consume the uncompressed output when it wants, for\r
- example when the output buffer is full (avail_out == 0), or after each\r
- call of inflate(). If inflate returns Z_OK and with zero avail_out, it\r
- must be called again after making room in the output buffer because there\r
- might be more output pending.\r
-\r
- If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much\r
- output as possible to the output buffer. The flushing behavior of inflate is\r
- not specified for values of the flush parameter other than Z_SYNC_FLUSH\r
- and Z_FINISH, but the current implementation actually flushes as much output\r
- as possible anyway.\r
-\r
- inflate() should normally be called until it returns Z_STREAM_END or an\r
- error. However if all decompression is to be performed in a single step\r
- (a single call of inflate), the parameter flush should be set to\r
- Z_FINISH. In this case all pending input is processed and all pending\r
- output is flushed; avail_out must be large enough to hold all the\r
- uncompressed data. (The size of the uncompressed data may have been saved\r
- by the compressor for this purpose.) The next operation on this stream must\r
- be inflateEnd to deallocate the decompression state. The use of Z_FINISH\r
- is never required, but can be used to inform inflate that a faster routine\r
- may be used for the single inflate() call.\r
-\r
- If a preset dictionary is needed at this point (see inflateSetDictionary\r
- below), inflate sets strm-adler to the adler32 checksum of the\r
- dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise \r
- it sets strm->adler to the adler32 checksum of all output produced\r
- so (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or\r
- an error code as described below. At the end of the stream, inflate()\r
- checks that its computed adler32 checksum is equal to that saved by the\r
- compressor and returns Z_STREAM_END only if the checksum is correct.\r
-\r
- inflate() returns Z_OK if some progress has been made (more input processed\r
- or more output produced), Z_STREAM_END if the end of the compressed data has\r
- been reached and all uncompressed output has been produced, Z_NEED_DICT if a\r
- preset dictionary is needed at this point, Z_DATA_ERROR if the input data was\r
- corrupted (input stream not conforming to the zlib format or incorrect\r
- adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent\r
- (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not\r
- enough memory, Z_BUF_ERROR if no progress is possible or if there was not\r
- enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR\r
- case, the application may then call inflateSync to look for a good\r
- compression block.\r
-*/\r
-\r
-\r
-int inflateEnd OF((z_streamp strm));\r
-/*\r
- All dynamically allocated data structures for this stream are freed.\r
- This function discards any unprocessed input and does not flush any\r
- pending output.\r
-\r
- inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state\r
- was inconsistent. In the error case, msg may be set but then points to a\r
- static string (which must not be deallocated).\r
-*/\r
-\r
- /* Advanced functions */\r
-\r
-/*\r
- The following functions are needed only in some special applications.\r
-*/\r
-\r
-/* \r
-int deflateInit2 OF((z_streamp strm,\r
- int level,\r
- int method,\r
- int windowBits,\r
- int memLevel,\r
- int strategy));\r
-\r
- This is another version of deflateInit with more compression options. The\r
- fields next_in, zalloc, zfree and opaque must be initialized before by\r
- the caller.\r
-\r
- The method parameter is the compression method. It must be Z_DEFLATED in\r
- this version of the library.\r
-\r
- The windowBits parameter is the base two logarithm of the window size\r
- (the size of the history buffer). It should be in the range 8..15 for this\r
- version of the library. Larger values of this parameter result in better\r
- compression at the expense of memory usage. The default value is 15 if\r
- deflateInit is used instead.\r
-\r
- The memLevel parameter specifies how much memory should be allocated\r
- for the internal compression state. memLevel=1 uses minimum memory but\r
- is slow and reduces compression ratio; memLevel=9 uses maximum memory\r
- for optimal speed. The default value is 8. See zconf.h for total memory\r
- usage as a function of windowBits and memLevel.\r
-\r
- The strategy parameter is used to tune the compression algorithm. Use the\r
- value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a\r
- filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no\r
- string match). Filtered data consists mostly of small values with a\r
- somewhat random distribution. In this case, the compression algorithm is\r
- tuned to compress them better. The effect of Z_FILTERED is to force more\r
- Huffman coding and less string matching; it is somewhat intermediate\r
- between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects\r
- the compression ratio but not the correctness of the compressed output even\r
- if it is not set appropriately.\r
-\r
- deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
- memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid\r
- method). msg is set to null if there is no error message. deflateInit2 does\r
- not perform any compression: this will be done by deflate().\r
-*/\r
- \r
-int deflateSetDictionary OF((z_streamp strm,\r
- const Byte *dictionary,\r
- uInt dictLength));\r
-/*\r
- Initializes the compression dictionary from the given byte sequence\r
- without producing any compressed output. This function must be called\r
- immediately after deflateInit, deflateInit2 or deflateReset, before any\r
- call of deflate. The compressor and decompressor must use exactly the same\r
- dictionary (see inflateSetDictionary).\r
-\r
- The dictionary should consist of strings (byte sequences) that are likely\r
- to be encountered later in the data to be compressed, with the most commonly\r
- used strings preferably put towards the end of the dictionary. Using a\r
- dictionary is most useful when the data to be compressed is short and can be\r
- predicted with good accuracy; the data can then be compressed better than\r
- with the default empty dictionary.\r
-\r
- Depending on the size of the compression data structures selected by\r
- deflateInit or deflateInit2, a part of the dictionary may in effect be\r
- discarded, for example if the dictionary is larger than the window size in\r
- deflate or deflate2. Thus the strings most likely to be useful should be\r
- put at the end of the dictionary, not at the front.\r
-\r
- Upon return of this function, strm->adler is set to the Adler32 value\r
- of the dictionary; the decompressor may later use this value to determine\r
- which dictionary has been used by the compressor. (The Adler32 value\r
- applies to the whole dictionary even if only a subset of the dictionary is\r
- actually used by the compressor.)\r
-\r
- deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a\r
- parameter is invalid (such as NULL dictionary) or the stream state is\r
- inconsistent (for example if deflate has already been called for this stream\r
- or if the compression method is bsort). deflateSetDictionary does not\r
- perform any compression: this will be done by deflate().\r
-*/\r
-\r
-int deflateCopy OF((z_streamp dest,\r
- z_streamp source));\r
-/*\r
- Sets the destination stream as a complete copy of the source stream.\r
-\r
- This function can be useful when several compression strategies will be\r
- tried, for example when there are several ways of pre-processing the input\r
- data with a filter. The streams that will be discarded should then be freed\r
- by calling deflateEnd. Note that deflateCopy duplicates the internal\r
- compression state which can be quite large, so this strategy is slow and\r
- can consume lots of memory.\r
-\r
- deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not\r
- enough memory, Z_STREAM_ERROR if the source stream state was inconsistent\r
- (such as zalloc being NULL). msg is left unchanged in both source and\r
- destination.\r
-*/\r
-\r
-int deflateReset OF((z_streamp strm));\r
-/*\r
- This function is equivalent to deflateEnd followed by deflateInit,\r
- but does not free and reallocate all the internal compression state.\r
- The stream will keep the same compression level and any other attributes\r
- that may have been set by deflateInit2.\r
-\r
- deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source\r
- stream state was inconsistent (such as zalloc or state being NULL).\r
-*/\r
-\r
-int deflateParams OF((z_streamp strm,\r
- int level,\r
- int strategy));\r
-/*\r
- Dynamically update the compression level and compression strategy. The\r
- interpretation of level and strategy is as in deflateInit2. This can be\r
- used to switch between compression and straight copy of the input data, or\r
- to switch to a different kind of input data requiring a different\r
- strategy. If the compression level is changed, the input available so far\r
- is compressed with the old level (and may be flushed); the new level will\r
- take effect only at the next call of deflate().\r
-\r
- Before the call of deflateParams, the stream state must be set as for\r
- a call of deflate(), since the currently available input may have to\r
- be compressed and flushed. In particular, strm->avail_out must be non-zero.\r
-\r
- deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source\r
- stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR\r
- if strm->avail_out was zero.\r
-*/\r
-\r
-/* \r
-int inflateInit2 OF((z_streamp strm,\r
- int windowBits));\r
-\r
- This is another version of inflateInit with an extra parameter. The\r
- fields next_in, avail_in, zalloc, zfree and opaque must be initialized\r
- before by the caller.\r
-\r
- The windowBits parameter is the base two logarithm of the maximum window\r
- size (the size of the history buffer). It should be in the range 8..15 for\r
- this version of the library. The default value is 15 if inflateInit is used\r
- instead. If a compressed stream with a larger window size is given as\r
- input, inflate() will return with the error code Z_DATA_ERROR instead of\r
- trying to allocate a larger window.\r
-\r
- inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
- memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative\r
- memLevel). msg is set to null if there is no error message. inflateInit2\r
- does not perform any decompression apart from reading the zlib header if\r
- present: this will be done by inflate(). (So next_in and avail_in may be\r
- modified, but next_out and avail_out are unchanged.)\r
-*/\r
-\r
-int inflateSetDictionary OF((z_streamp strm,\r
- const Byte *dictionary,\r
- uInt dictLength));\r
-/*\r
- Initializes the decompression dictionary from the given uncompressed byte\r
- sequence. This function must be called immediately after a call of inflate\r
- if this call returned Z_NEED_DICT. The dictionary chosen by the compressor\r
- can be determined from the Adler32 value returned by this call of\r
- inflate. The compressor and decompressor must use exactly the same\r
- dictionary (see deflateSetDictionary).\r
-\r
- inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a\r
- parameter is invalid (such as NULL dictionary) or the stream state is\r
- inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the\r
- expected one (incorrect Adler32 value). inflateSetDictionary does not\r
- perform any decompression: this will be done by subsequent calls of\r
- inflate().\r
-*/\r
-\r
-int inflateSync OF((z_streamp strm));\r
-/* \r
- Skips invalid compressed data until a full flush point (see above the\r
- description of deflate with Z_FULL_FLUSH) can be found, or until all\r
- available input is skipped. No output is provided.\r
-\r
- inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR\r
- if no more input was provided, Z_DATA_ERROR if no flush point has been found,\r
- or Z_STREAM_ERROR if the stream structure was inconsistent. In the success\r
- case, the application may save the current current value of total_in which\r
- indicates where valid compressed data was found. In the error case, the\r
- application may repeatedly call inflateSync, providing more input each time,\r
- until success or end of the input data.\r
-*/\r
-\r
-int inflateReset OF((z_streamp strm));\r
-/*\r
- This function is equivalent to inflateEnd followed by inflateInit,\r
- but does not free and reallocate all the internal decompression state.\r
- The stream will keep attributes that may have been set by inflateInit2.\r
-\r
- inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source\r
- stream state was inconsistent (such as zalloc or state being NULL).\r
-*/\r
-\r
-\r
- /* utility functions */\r
-\r
-/*\r
- The following utility functions are implemented on top of the\r
- basic stream-oriented functions. To simplify the interface, some\r
- default options are assumed (compression level and memory usage,\r
- standard memory allocation functions). The source code of these\r
- utility functions can easily be modified if you need special options.\r
-*/\r
-\r
-int compress OF((Byte *dest, uLong *destLen,\r
- const Byte *source, uLong sourceLen));\r
-/*\r
- Compresses the source buffer into the destination buffer. sourceLen is\r
- the byte length of the source buffer. Upon entry, destLen is the total\r
- size of the destination buffer, which must be at least 0.1% larger than\r
- sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the\r
- compressed buffer.\r
- This function can be used to compress a whole file at once if the\r
- input file is mmap'ed.\r
- compress returns Z_OK if success, Z_MEM_ERROR if there was not\r
- enough memory, Z_BUF_ERROR if there was not enough room in the output\r
- buffer.\r
-*/\r
-\r
-int compress2 OF((Byte *dest, uLong *destLen,\r
- const Byte *source, uLong sourceLen,\r
- int level));\r
-/*\r
- Compresses the source buffer into the destination buffer. The level\r
- parameter has the same meaning as in deflateInit. sourceLen is the byte\r
- length of the source buffer. Upon entry, destLen is the total size of the\r
- destination buffer, which must be at least 0.1% larger than sourceLen plus\r
- 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.\r
-\r
- compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
- memory, Z_BUF_ERROR if there was not enough room in the output buffer,\r
- Z_STREAM_ERROR if the level parameter is invalid.\r
-*/\r
-\r
-int uncompress OF((Byte *dest, uLong *destLen,\r
- const Byte *source, uLong sourceLen));\r
-/*\r
- Decompresses the source buffer into the destination buffer. sourceLen is\r
- the byte length of the source buffer. Upon entry, destLen is the total\r
- size of the destination buffer, which must be large enough to hold the\r
- entire uncompressed data. (The size of the uncompressed data must have\r
- been saved previously by the compressor and transmitted to the decompressor\r
- by some mechanism outside the scope of this compression library.)\r
- Upon exit, destLen is the actual size of the compressed buffer.\r
- This function can be used to decompress a whole file at once if the\r
- input file is mmap'ed.\r
-\r
- uncompress returns Z_OK if success, Z_MEM_ERROR if there was not\r
- enough memory, Z_BUF_ERROR if there was not enough room in the output\r
- buffer, or Z_DATA_ERROR if the input data was corrupted.\r
-*/\r
-\r
-\r
-typedef voidp gzFile;\r
-\r
-gzFile gzopen OF((const char *path, const char *mode));\r
-/*\r
- Opens a gzip (.gz) file for reading or writing. The mode parameter\r
- is as in fopen ("rb" or "wb") but can also include a compression level\r
- ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for\r
- Huffman only compression as in "wb1h". (See the description\r
- of deflateInit2 for more information about the strategy parameter.)\r
-\r
- gzopen can be used to read a file which is not in gzip format; in this\r
- case gzread will directly read from the file without decompression.\r
-\r
- gzopen returns NULL if the file could not be opened or if there was\r
- insufficient memory to allocate the (de)compression state; errno\r
- can be checked to distinguish the two cases (if errno is zero, the\r
- zlib error is Z_MEM_ERROR). */\r
-\r
-gzFile gzdopen OF((int fd, const char *mode));\r
-/*\r
- gzdopen() associates a gzFile with the file descriptor fd. File\r
- descriptors are obtained from calls like open, dup, creat, pipe or\r
- fileno (in the file has been previously opened with fopen).\r
- The mode parameter is as in gzopen.\r
- The next call of gzclose on the returned gzFile will also close the\r
- file descriptor fd, just like fclose(fdopen(fd), mode) closes the file\r
- descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).\r
- gzdopen returns NULL if there was insufficient memory to allocate\r
- the (de)compression state.\r
-*/\r
-\r
-int gzsetparams OF((gzFile file, int level, int strategy));\r
-/*\r
- Dynamically update the compression level or strategy. See the description\r
- of deflateInit2 for the meaning of these parameters.\r
- gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not\r
- opened for writing.\r
-*/\r
-\r
-int gzread OF((gzFile file, voidp buf, unsigned len));\r
-/*\r
- Reads the given number of uncompressed bytes from the compressed file.\r
- If the input file was not in gzip format, gzread copies the given number\r
- of bytes into the buffer.\r
- gzread returns the number of uncompressed bytes actually read (0 for\r
- end of file, -1 for error). */\r
-\r
-int gzwrite OF((gzFile file, \r
- const voidp buf, unsigned len));\r
-/*\r
- Writes the given number of uncompressed bytes into the compressed file.\r
- gzwrite returns the number of uncompressed bytes actually written\r
- (0 in case of error).\r
-*/\r
-\r
-int gzprintf OF((gzFile file, const char *format, ...));\r
-/*\r
- Converts, formats, and writes the args to the compressed file under\r
- control of the format string, as in fprintf. gzprintf returns the number of\r
- uncompressed bytes actually written (0 in case of error).\r
-*/\r
-\r
-int gzputs OF((gzFile file, const char *s));\r
-/*\r
- Writes the given null-terminated string to the compressed file, excluding\r
- the terminating null character.\r
- gzputs returns the number of characters written, or -1 in case of error.\r
-*/\r
-\r
-char * gzgets OF((gzFile file, char *buf, int len));\r
-/*\r
- Reads bytes from the compressed file until len-1 characters are read, or\r
- a newline character is read and transferred to buf, or an end-of-file\r
- condition is encountered. The string is then terminated with a null\r
- character.\r
- gzgets returns buf, or Z_NULL in case of error.\r
-*/\r
-\r
-int gzputc OF((gzFile file, int c));\r
-/*\r
- Writes c, converted to an unsigned char, into the compressed file.\r
- gzputc returns the value that was written, or -1 in case of error.\r
-*/\r
-\r
-int gzgetc OF((gzFile file));\r
-/*\r
- Reads one byte from the compressed file. gzgetc returns this byte\r
- or -1 in case of end of file or error.\r
-*/\r
-\r
-int gzflush OF((gzFile file, int flush));\r
-/*\r
- Flushes all pending output into the compressed file. The parameter\r
- flush is as in the deflate() function. The return value is the zlib\r
- error number (see function gzerror below). gzflush returns Z_OK if\r
- the flush parameter is Z_FINISH and all output could be flushed.\r
- gzflush should be called only when strictly necessary because it can\r
- degrade compression.\r
-*/\r
-\r
-long gzseek OF((gzFile file,\r
- long offset, int whence));\r
-/* \r
- Sets the starting position for the next gzread or gzwrite on the\r
- given compressed file. The offset represents a number of bytes in the\r
- uncompressed data stream. The whence parameter is defined as in lseek(2);\r
- the value SEEK_END is not supported.\r
- If the file is opened for reading, this function is emulated but can be\r
- extremely slow. If the file is opened for writing, only forward seeks are\r
- supported; gzseek then compresses a sequence of zeroes up to the new\r
- starting position.\r
-\r
- gzseek returns the resulting offset location as measured in bytes from\r
- the beginning of the uncompressed stream, or -1 in case of error, in\r
- particular if the file is opened for writing and the new starting position\r
- would be before the current position.\r
-*/\r
-\r
-int gzrewind OF((gzFile file));\r
-/*\r
- Rewinds the given file. This function is supported only for reading.\r
-\r
- gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)\r
-*/\r
-\r
-long gztell OF((gzFile file));\r
-/*\r
- Returns the starting position for the next gzread or gzwrite on the\r
- given compressed file. This position represents a number of bytes in the\r
- uncompressed data stream.\r
-\r
- gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)\r
-*/\r
-\r
-int gzeof OF((gzFile file));\r
-/*\r
- Returns 1 when EOF has previously been detected reading the given\r
- input stream, otherwise zero.\r
-*/\r
-\r
-int gzclose OF((gzFile file));\r
-/*\r
- Flushes all pending output if necessary, closes the compressed file\r
- and deallocates all the (de)compression state. The return value is the zlib\r
- error number (see function gzerror below).\r
-*/\r
-\r
-const char * gzerror OF((gzFile file, int *errnum));\r
-/*\r
- Returns the error message for the last error which occurred on the\r
- given compressed file. errnum is set to zlib error number. If an\r
- error occurred in the file system and not in the compression library,\r
- errnum is set to Z_ERRNO and the application may consult errno\r
- to get the exact error code.\r
-*/\r
-\r
- /* checksum functions */\r
-\r
-/*\r
- These functions are not related to compression but are exported\r
- anyway because they might be useful in applications using the\r
- compression library.\r
-*/\r
-\r
-uLong adler32 OF((uLong adler, const Byte *buf, uInt len));\r
-\r
-/*\r
- Update a running Adler-32 checksum with the bytes buf[0..len-1] and\r
- return the updated checksum. If buf is NULL, this function returns\r
- the required initial value for the checksum.\r
- An Adler-32 checksum is almost as reliable as a CRC32 but can be computed\r
- much faster. Usage example:\r
-\r
- uLong adler = adler32(0L, Z_NULL, 0);\r
-\r
- while (read_buffer(buffer, length) != EOF) {\r
- adler = adler32(adler, buffer, length);\r
- }\r
- if (adler != original_adler) error();\r
-*/\r
-\r
-uLong crc32 OF((uLong crc, const Byte *buf, uInt len));\r
-/*\r
- Update a running crc with the bytes buf[0..len-1] and return the updated\r
- crc. If buf is NULL, this function returns the required initial value\r
- for the crc. Pre- and post-conditioning (one's complement) is performed\r
- within this function so it shouldn't be done by the application.\r
- Usage example:\r
-\r
- uLong crc = crc32(0L, Z_NULL, 0);\r
-\r
- while (read_buffer(buffer, length) != EOF) {\r
- crc = crc32(crc, buffer, length);\r
- }\r
- if (crc != original_crc) error();\r
-*/\r
-\r
-// private stuff to not include cmdlib.h\r
-/*\r
-============================================================================\r
-\r
- BYTE ORDER FUNCTIONS\r
-\r
-============================================================================\r
-*/\r
-\r
-#ifdef _SGI_SOURCE\r
-#define __BIG_ENDIAN__\r
-#endif\r
-\r
-#ifdef __BIG_ENDIAN__\r
-\r
-short __LittleShort (short l)\r
-{\r
- byte b1,b2;\r
-\r
- b1 = l&255;\r
- b2 = (l>>8)&255;\r
-\r
- return (b1<<8) + b2;\r
-}\r
-\r
-short __BigShort (short l)\r
-{\r
- return l;\r
-}\r
-\r
-\r
-int __LittleLong (int l)\r
-{\r
- byte b1,b2,b3,b4;\r
-\r
- b1 = l&255;\r
- b2 = (l>>8)&255;\r
- b3 = (l>>16)&255;\r
- b4 = (l>>24)&255;\r
-\r
- return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;\r
-}\r
-\r
-int __BigLong (int l)\r
-{\r
- return l;\r
-}\r
-\r
-\r
-float __LittleFloat (float l)\r
-{\r
- union {byte b[4]; float f;} in, out;\r
- \r
- in.f = l;\r
- out.b[0] = in.b[3];\r
- out.b[1] = in.b[2];\r
- out.b[2] = in.b[1];\r
- out.b[3] = in.b[0];\r
- \r
- return out.f;\r
-}\r
-\r
-float __BigFloat (float l)\r
-{\r
- return l;\r
-}\r
-\r
-\r
-#else\r
-\r
-\r
-short __BigShort (short l)\r
-{\r
- byte b1,b2;\r
-\r
- b1 = l&255;\r
- b2 = (l>>8)&255;\r
-\r
- return (b1<<8) + b2;\r
-}\r
-\r
-short __LittleShort (short l)\r
-{\r
- return l;\r
-}\r
-\r
-\r
-int __BigLong (int l)\r
-{\r
- byte b1,b2,b3,b4;\r
-\r
- b1 = l&255;\r
- b2 = (l>>8)&255;\r
- b3 = (l>>16)&255;\r
- b4 = (l>>24)&255;\r
-\r
- return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;\r
-}\r
-\r
-int __LittleLong (int l)\r
-{\r
- return l;\r
-}\r
-\r
-float __BigFloat (float l)\r
-{\r
- union {byte b[4]; float f;} in, out;\r
- \r
- in.f = l;\r
- out.b[0] = in.b[3];\r
- out.b[1] = in.b[2];\r
- out.b[2] = in.b[1];\r
- out.b[3] = in.b[0];\r
- \r
- return out.f;\r
-}\r
-\r
-float __LittleFloat (float l)\r
-{\r
- return l;\r
-}\r
-\r
-\r
-\r
-#endif\r
-\r
-\r
-\r
-\r
- /* various hacks, don't look :) */\r
-\r
-/* deflateInit and inflateInit are macros to allow checking the zlib version\r
- * and the compiler's view of z_stream:\r
- */\r
-int deflateInit_ OF((z_streamp strm, int level,\r
- const char *version, int stream_size));\r
-int inflateInit_ OF((z_streamp strm,\r
- const char *version, int stream_size));\r
-int deflateInit2_ OF((z_streamp strm, int level, int method,\r
- int windowBits, int memLevel,\r
- int strategy, const char *version,\r
- int stream_size));\r
-int inflateInit2_ OF((z_streamp strm, int windowBits,\r
- const char *version, int stream_size));\r
-#define deflateInit(strm, level) \\r
- deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))\r
-#define inflateInit(strm) \\r
- inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))\r
-#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \\r
- deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\\r
- (strategy), ZLIB_VERSION, sizeof(z_stream))\r
-#define inflateInit2(strm, windowBits) \\r
- inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))\r
-\r
-\r
-const char * zError OF((int err));\r
-int inflateSyncPoint OF((z_streamp z));\r
-const uLong * get_crc_table OF((void));\r
-\r
-typedef unsigned char uch;\r
-typedef unsigned short ush;\r
-typedef unsigned long ulg;\r
-\r
-extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */\r
-/* (size given to avoid silly warnings with Visual C++) */\r
-\r
-#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]\r
-\r
-#define ERR_RETURN(strm,err) \\r
- return (strm->msg = (char*)ERR_MSG(err), (err))\r
-/* To be used only when the state is known to be valid */\r
-\r
- /* common constants */\r
-\r
-#ifndef DEF_WBITS\r
-# define DEF_WBITS MAX_WBITS\r
-#endif\r
-/* default windowBits for decompression. MAX_WBITS is for compression only */\r
-\r
-#if MAX_MEM_LEVEL >= 8\r
-# define DEF_MEM_LEVEL 8\r
-#else\r
-# define DEF_MEM_LEVEL MAX_MEM_LEVEL\r
-#endif\r
-/* default memLevel */\r
-\r
-#define STORED_BLOCK 0\r
-#define STATIC_TREES 1\r
-#define DYN_TREES 2\r
-/* The three kinds of block type */\r
-\r
-#define MIN_MATCH 3\r
-#define MAX_MATCH 258\r
-/* The minimum and maximum match lengths */\r
-\r
-#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */\r
-\r
- /* target dependencies */\r
-\r
- /* Common defaults */\r
-\r
-#ifndef OS_CODE\r
-# define OS_CODE 0x03 /* assume Unix */\r
-#endif\r
-\r
-#ifndef F_OPEN\r
-# define F_OPEN(name, mode) fopen((name), (mode))\r
-#endif\r
-\r
- /* functions */\r
-\r
-#ifdef HAVE_STRERROR\r
- extern char *strerror OF((int));\r
-# define zstrerror(errnum) strerror(errnum)\r
-#else\r
-# define zstrerror(errnum) ""\r
-#endif\r
-\r
-#define zmemcpy memcpy\r
-#define zmemcmp memcmp\r
-#define zmemzero(dest, len) memset(dest, 0, len)\r
-\r
-/* Diagnostic functions */\r
-#ifdef _ZIP_DEBUG_\r
- int z_verbose = 0;\r
-# define Assert(cond,msg) assert(cond);\r
- //{if(!(cond)) Sys_Error(msg);}\r
-# define Trace(x) {if (z_verbose>=0) Sys_Error x ;}\r
-# define Tracev(x) {if (z_verbose>0) Sys_Error x ;}\r
-# define Tracevv(x) {if (z_verbose>1) Sys_Error x ;}\r
-# define Tracec(c,x) {if (z_verbose>0 && (c)) Sys_Error x ;}\r
-# define Tracecv(c,x) {if (z_verbose>1 && (c)) Sys_Error x ;}\r
-#else\r
-# define Assert(cond,msg)\r
-# define Trace(x)\r
-# define Tracev(x)\r
-# define Tracevv(x)\r
-# define Tracec(c,x)\r
-# define Tracecv(c,x)\r
-#endif\r
-\r
-\r
-typedef uLong (*check_func) OF((uLong check, const Byte *buf, uInt len));\r
-voidp zcalloc OF((voidp opaque, unsigned items, unsigned size));\r
-void zcfree OF((voidp opaque, voidp ptr));\r
-\r
-#define ZALLOC(strm, items, size) \\r
- (*((strm)->zalloc))((strm)->opaque, (items), (size))\r
-#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidp)(addr))\r
-#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}\r
-\r
-\r
-#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \\r
- !defined(CASESENSITIVITYDEFAULT_NO)\r
-#define CASESENSITIVITYDEFAULT_NO\r
-#endif\r
-\r
-\r
-#ifndef UNZ_BUFSIZE\r
-#define UNZ_BUFSIZE (65536)\r
-#endif\r
-\r
-#ifndef UNZ_MAXFILENAMEINZIP\r
-#define UNZ_MAXFILENAMEINZIP (256)\r
-#endif\r
-\r
-#ifndef ALLOC\r
-# define ALLOC(size) (malloc(size))\r
-#endif\r
-#ifndef TRYFREE\r
-# define TRYFREE(p) {if (p) free(p);}\r
-#endif\r
-\r
-#define SIZECENTRALDIRITEM (0x2e)\r
-#define SIZEZIPLOCALHEADER (0x1e)\r
-\r
-\r
-\r
-/* ===========================================================================\r
- Read a byte from a gz_stream; update next_in and avail_in. Return EOF\r
- for end of file.\r
- IN assertion: the stream s has been sucessfully opened for reading.\r
-*/\r
-\r
-/*\r
-static int unzlocal_getByte(FILE *fin,int *pi)\r
-{\r
- unsigned char c;\r
- int err = fread(&c, 1, 1, fin);\r
- if (err==1)\r
- {\r
- *pi = (int)c;\r
- return UNZ_OK;\r
- }\r
- else\r
- {\r
- if (ferror(fin)) \r
- return UNZ_ERRNO;\r
- else\r
- return UNZ_EOF;\r
- }\r
-}\r
-*/\r
-\r
-/* ===========================================================================\r
- Reads a long in LSB order from the given gz_stream. Sets \r
-*/\r
-static int unzlocal_getShort (FILE* fin, uLong *pX)\r
-{\r
- short v;\r
-\r
- fread( &v, sizeof(v), 1, fin );\r
-\r
- *pX = __LittleShort( v);\r
- return UNZ_OK;\r
-\r
-/*\r
- uLong x ;\r
- int i;\r
- int err;\r
-\r
- err = unzlocal_getByte(fin,&i);\r
- x = (uLong)i;\r
- \r
- if (err==UNZ_OK)\r
- err = unzlocal_getByte(fin,&i);\r
- x += ((uLong)i)<<8;\r
- \r
- if (err==UNZ_OK)\r
- *pX = x;\r
- else\r
- *pX = 0;\r
- return err;\r
-*/\r
-}\r
-\r
-static int unzlocal_getLong (FILE *fin, uLong *pX)\r
-{\r
- int v;\r
-\r
- fread( &v, sizeof(v), 1, fin );\r
-\r
- *pX = __LittleLong( v);\r
- return UNZ_OK;\r
-\r
-/*\r
- uLong x ;\r
- int i;\r
- int err;\r
-\r
- err = unzlocal_getByte(fin,&i);\r
- x = (uLong)i;\r
- \r
- if (err==UNZ_OK)\r
- err = unzlocal_getByte(fin,&i);\r
- x += ((uLong)i)<<8;\r
-\r
- if (err==UNZ_OK)\r
- err = unzlocal_getByte(fin,&i);\r
- x += ((uLong)i)<<16;\r
-\r
- if (err==UNZ_OK)\r
- err = unzlocal_getByte(fin,&i);\r
- x += ((uLong)i)<<24;\r
- \r
- if (err==UNZ_OK)\r
- *pX = x;\r
- else\r
- *pX = 0;\r
- return err;\r
-*/\r
-}\r
-\r
-\r
-/* My own strcmpi / strcasecmp */\r
-static int strcmpcasenosensitive_internal (const char* fileName1,const char* fileName2)\r
-{\r
- for (;;)\r
- {\r
- char c1=*(fileName1++);\r
- char c2=*(fileName2++);\r
- if ((c1>='a') && (c1<='z'))\r
- c1 -= 0x20;\r
- if ((c2>='a') && (c2<='z'))\r
- c2 -= 0x20;\r
- if (c1=='\0')\r
- return ((c2=='\0') ? 0 : -1);\r
- if (c2=='\0')\r
- return 1;\r
- if (c1<c2)\r
- return -1;\r
- if (c1>c2)\r
- return 1;\r
- }\r
-}\r
-\r
-\r
-#ifdef CASESENSITIVITYDEFAULT_NO\r
-#define CASESENSITIVITYDEFAULTVALUE 2\r
-#else\r
-#define CASESENSITIVITYDEFAULTVALUE 1\r
-#endif\r
-\r
-#ifndef STRCMPCASENOSENTIVEFUNCTION\r
-#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal\r
-#endif\r
-\r
-/* \r
- Compare two filename (fileName1,fileName2).\r
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)\r
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi\r
- or strcasecmp)\r
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system\r
- (like 1 on Unix, 2 on Windows)\r
-\r
-*/\r
-extern int unzStringFileNameCompare (const char* fileName1,const char* fileName2,int iCaseSensitivity)\r
-{\r
- if (iCaseSensitivity==0)\r
- iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;\r
-\r
- if (iCaseSensitivity==1)\r
- return strcmp(fileName1,fileName2);\r
-\r
- return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);\r
-} \r
-\r
-#define BUFREADCOMMENT (0x400)\r
-\r
-/*\r
- Locate the Central directory of a zipfile (at the end, just before\r
- the global comment)\r
-*/\r
-static uLong unzlocal_SearchCentralDir(FILE *fin)\r
-{\r
- unsigned char* buf;\r
- uLong uSizeFile;\r
- uLong uBackRead;\r
- uLong uMaxBack=0xffff; /* maximum size of global comment */\r
- uLong uPosFound=0;\r
- \r
- if (fseek(fin,0,SEEK_END) != 0)\r
- return 0;\r
-\r
-\r
- uSizeFile = ftell( fin );\r
- \r
- if (uMaxBack>uSizeFile)\r
- uMaxBack = uSizeFile;\r
-\r
- buf = (unsigned char*)malloc(BUFREADCOMMENT+4);\r
- if (buf==NULL)\r
- return 0;\r
-\r
- uBackRead = 4;\r
- while (uBackRead<uMaxBack)\r
- {\r
- uLong uReadSize,uReadPos ;\r
- int i;\r
- if (uBackRead+BUFREADCOMMENT>uMaxBack) \r
- uBackRead = uMaxBack;\r
- else\r
- uBackRead+=BUFREADCOMMENT;\r
- uReadPos = uSizeFile-uBackRead ;\r
- \r
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? \r
- (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);\r
- if (fseek(fin,uReadPos,SEEK_SET)!=0)\r
- break;\r
-\r
- if (fread(buf,(uInt)uReadSize,1,fin)!=1)\r
- break;\r
-\r
- for (i=(int)uReadSize-3; (i--)>0;)\r
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && \r
- ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))\r
- {\r
- uPosFound = uReadPos+i;\r
- break;\r
- }\r
-\r
- if (uPosFound!=0)\r
- break;\r
- }\r
- free(buf);\r
- return uPosFound;\r
-}\r
-\r
-extern unzFile unzReOpen (const char* path, unzFile file)\r
-{\r
- unz_s *s;\r
- FILE * fin;\r
-\r
- fin=fopen(path,"rb");\r
- if (fin==NULL)\r
- return NULL;\r
-\r
- s=(unz_s*)malloc(sizeof(unz_s));\r
- memcpy(s, (unz_s*)file, sizeof(unz_s));\r
-\r
- s->file = fin;\r
- return (unzFile)s; \r
-}\r
-\r
-/*\r
- Open a Zip file. path contain the full pathname (by example,\r
- on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer\r
- "zlib/zlib109.zip".\r
- If the zipfile cannot be opened (file don't exist or in not valid), the\r
- return value is NULL.\r
- Else, the return value is a unzFile Handle, usable with other function\r
- of this unzip package.\r
-*/\r
-extern unzFile unzOpen (const char* path)\r
-{\r
- unz_s us;\r
- unz_s *s;\r
- uLong central_pos,uL;\r
- FILE * fin ;\r
-\r
- uLong number_disk; /* number of the current dist, used for \r
- spaning ZIP, unsupported, always 0*/\r
- uLong number_disk_with_CD; /* number the the disk with central dir, used\r
- for spaning ZIP, unsupported, always 0*/\r
- uLong number_entry_CD; /* total number of entries in\r
- the central dir \r
- (same than number_entry on nospan) */\r
-\r
- int err=UNZ_OK;\r
-\r
- fin=fopen(path,"rb");\r
- if (fin==NULL)\r
- return NULL;\r
-\r
- central_pos = unzlocal_SearchCentralDir(fin);\r
- if (central_pos==0)\r
- err=UNZ_ERRNO;\r
-\r
- if (fseek(fin,central_pos,SEEK_SET)!=0)\r
- err=UNZ_ERRNO;\r
-\r
- /* the signature, already checked */\r
- if (unzlocal_getLong(fin,&uL)!=UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- /* number of this disk */\r
- if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- /* number of the disk with the start of the central directory */\r
- if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- /* total number of entries in the central dir on this disk */\r
- if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- /* total number of entries in the central dir */\r
- if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if ((number_entry_CD!=us.gi.number_entry) ||\r
- (number_disk_with_CD!=0) ||\r
- (number_disk!=0))\r
- err=UNZ_BADZIPFILE;\r
-\r
- /* size of the central directory */\r
- if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- /* offset of start of central directory with respect to the \r
- starting disk number */\r
- if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- /* zipfile comment length */\r
- if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if ((central_pos<us.offset_central_dir+us.size_central_dir) && \r
- (err==UNZ_OK))\r
- err=UNZ_BADZIPFILE;\r
-\r
- if (err!=UNZ_OK)\r
- {\r
- fclose(fin);\r
- return NULL;\r
- }\r
-\r
- us.file=fin;\r
- us.byte_before_the_zipfile = central_pos -\r
- (us.offset_central_dir+us.size_central_dir);\r
- us.central_pos = central_pos;\r
- us.pfile_in_zip_read = NULL;\r
- \r
-\r
- s=(unz_s*)malloc(sizeof(unz_s));\r
- *s=us;\r
-// unzGoToFirstFile((unzFile)s); \r
- return (unzFile)s; \r
-}\r
-\r
-\r
-/*\r
- Close a ZipFile opened with unzipOpen.\r
- If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),\r
- these files MUST be closed with unzipCloseCurrentFile before call unzipClose.\r
- return UNZ_OK if there is no problem. */\r
-extern int unzClose (unzFile file)\r
-{\r
- unz_s* s;\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
-\r
- if (s->pfile_in_zip_read!=NULL)\r
- unzCloseCurrentFile(file);\r
-\r
- fclose(s->file);\r
- free(s);\r
- return UNZ_OK;\r
-}\r
-\r
-\r
-/*\r
- Write info about the ZipFile in the *pglobal_info structure.\r
- No preparation of the structure is needed\r
- return UNZ_OK if there is no problem. */\r
-extern int unzGetGlobalInfo (unzFile file,unz_global_info *pglobal_info)\r
-{\r
- unz_s* s;\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- *pglobal_info=s->gi;\r
- return UNZ_OK;\r
-}\r
-\r
-\r
-/*\r
- Translate date/time from Dos format to tm_unz (readable more easilty)\r
-*/\r
-static void unzlocal_DosDateToTmuDate (uLong ulDosDate, tm_unz* ptm)\r
-{\r
- uLong uDate;\r
- uDate = (uLong)(ulDosDate>>16);\r
- ptm->tm_mday = (uInt)(uDate&0x1f) ;\r
- ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;\r
- ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;\r
-\r
- ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);\r
- ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;\r
- ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;\r
-}\r
-\r
-/*\r
- Get Info about the current file in the zipfile, with internal only info\r
-*/\r
-static int unzlocal_GetCurrentFileInfoInternal (unzFile file,\r
- unz_file_info *pfile_info,\r
- unz_file_info_internal \r
- *pfile_info_internal,\r
- char *szFileName,\r
- uLong fileNameBufferSize,\r
- void *extraField,\r
- uLong extraFieldBufferSize,\r
- char *szComment,\r
- uLong commentBufferSize)\r
-{\r
- unz_s* s;\r
- unz_file_info file_info;\r
- unz_file_info_internal file_info_internal;\r
- int err=UNZ_OK;\r
- uLong uMagic;\r
- long lSeek=0;\r
-\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0)\r
- err=UNZ_ERRNO;\r
-\r
-\r
- /* we check the magic */\r
- if (err==UNZ_OK)\r
- if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
- else if (uMagic!=0x02014b50)\r
- err=UNZ_BADZIPFILE;\r
-\r
- if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);\r
-\r
- if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- lSeek+=file_info.size_filename;\r
- if ((err==UNZ_OK) && (szFileName!=NULL))\r
- {\r
- uLong uSizeRead ;\r
- if (file_info.size_filename<fileNameBufferSize)\r
- {\r
- *(szFileName+file_info.size_filename)='\0';\r
- uSizeRead = file_info.size_filename;\r
- }\r
- else\r
- uSizeRead = fileNameBufferSize;\r
-\r
- if ((file_info.size_filename>0) && (fileNameBufferSize>0))\r
- if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1)\r
- err=UNZ_ERRNO;\r
- lSeek -= uSizeRead;\r
- }\r
-\r
- \r
- if ((err==UNZ_OK) && (extraField!=NULL))\r
- {\r
- uLong uSizeRead ;\r
- if (file_info.size_file_extra<extraFieldBufferSize)\r
- uSizeRead = file_info.size_file_extra;\r
- else\r
- uSizeRead = extraFieldBufferSize;\r
-\r
- if (lSeek!=0)\r
- if (fseek(s->file,lSeek,SEEK_CUR)==0)\r
- lSeek=0;\r
- else\r
- err=UNZ_ERRNO;\r
- if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))\r
- if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)\r
- err=UNZ_ERRNO;\r
- lSeek += file_info.size_file_extra - uSizeRead;\r
- }\r
- else\r
- lSeek+=file_info.size_file_extra; \r
-\r
- \r
- if ((err==UNZ_OK) && (szComment!=NULL))\r
- {\r
- uLong uSizeRead ;\r
- if (file_info.size_file_comment<commentBufferSize)\r
- {\r
- *(szComment+file_info.size_file_comment)='\0';\r
- uSizeRead = file_info.size_file_comment;\r
- }\r
- else\r
- uSizeRead = commentBufferSize;\r
-\r
- if (lSeek!=0)\r
- if (fseek(s->file,lSeek,SEEK_CUR)==0)\r
- lSeek=0;\r
- else\r
- err=UNZ_ERRNO;\r
- if ((file_info.size_file_comment>0) && (commentBufferSize>0))\r
- if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)\r
- err=UNZ_ERRNO;\r
- lSeek+=file_info.size_file_comment - uSizeRead;\r
- }\r
- else\r
- lSeek+=file_info.size_file_comment;\r
-\r
- if ((err==UNZ_OK) && (pfile_info!=NULL))\r
- *pfile_info=file_info;\r
-\r
- if ((err==UNZ_OK) && (pfile_info_internal!=NULL))\r
- *pfile_info_internal=file_info_internal;\r
-\r
- return err;\r
-}\r
-\r
-\r
-\r
-/*\r
- Write info about the ZipFile in the *pglobal_info structure.\r
- No preparation of the structure is needed\r
- return UNZ_OK if there is no problem.\r
-*/\r
-extern int unzGetCurrentFileInfo ( unzFile file, unz_file_info *pfile_info,\r
- char *szFileName, uLong fileNameBufferSize,\r
- void *extraField, uLong extraFieldBufferSize,\r
- char *szComment, uLong commentBufferSize)\r
-{\r
- return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,\r
- szFileName,fileNameBufferSize,\r
- extraField,extraFieldBufferSize,\r
- szComment,commentBufferSize);\r
-}\r
-\r
-/*\r
- Set the current file of the zipfile to the first file.\r
- return UNZ_OK if there is no problem\r
-*/\r
-extern int unzGoToFirstFile (unzFile file)\r
-{\r
- int err=UNZ_OK;\r
- unz_s* s;\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- s->pos_in_central_dir=s->offset_central_dir;\r
- s->num_file=0;\r
- err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,\r
- &s->cur_file_info_internal,\r
- NULL,0,NULL,0,NULL,0);\r
- s->current_file_ok = (err == UNZ_OK);\r
- return err;\r
-}\r
-\r
-\r
-/*\r
- Set the current file of the zipfile to the next file.\r
- return UNZ_OK if there is no problem\r
- return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.\r
-*/\r
-extern int unzGoToNextFile (unzFile file)\r
-{\r
- unz_s* s; \r
- int err;\r
-\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- if (!s->current_file_ok)\r
- return UNZ_END_OF_LIST_OF_FILE;\r
- if (s->num_file+1==s->gi.number_entry)\r
- return UNZ_END_OF_LIST_OF_FILE;\r
-\r
- s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +\r
- s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;\r
- s->num_file++;\r
- err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,\r
- &s->cur_file_info_internal,\r
- NULL,0,NULL,0,NULL,0);\r
- s->current_file_ok = (err == UNZ_OK);\r
- return err;\r
-}\r
-\r
-\r
-/*\r
- Try locate the file szFileName in the zipfile.\r
- For the iCaseSensitivity signification, see unzipStringFileNameCompare\r
-\r
- return value :\r
- UNZ_OK if the file is found. It becomes the current file.\r
- UNZ_END_OF_LIST_OF_FILE if the file is not found\r
-*/\r
-extern int unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)\r
-{\r
- unz_s* s; \r
- int err;\r
-\r
- \r
- uLong num_fileSaved;\r
- uLong pos_in_central_dirSaved;\r
-\r
-\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
-\r
- if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)\r
- return UNZ_PARAMERROR;\r
-\r
- s=(unz_s*)file;\r
- if (!s->current_file_ok)\r
- return UNZ_END_OF_LIST_OF_FILE;\r
-\r
- num_fileSaved = s->num_file;\r
- pos_in_central_dirSaved = s->pos_in_central_dir;\r
-\r
- err = unzGoToFirstFile(file);\r
-\r
- while (err == UNZ_OK)\r
- {\r
- char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];\r
- unzGetCurrentFileInfo(file,NULL,\r
- szCurrentFileName,sizeof(szCurrentFileName)-1,\r
- NULL,0,NULL,0);\r
- if (unzStringFileNameCompare(szCurrentFileName,\r
- szFileName,iCaseSensitivity)==0)\r
- return UNZ_OK;\r
- err = unzGoToNextFile(file);\r
- }\r
-\r
- s->num_file = num_fileSaved ;\r
- s->pos_in_central_dir = pos_in_central_dirSaved ;\r
- return err;\r
-}\r
-\r
-\r
-/*\r
- Read the static header of the current zipfile\r
- Check the coherency of the static header and info in the end of central\r
- directory about this file\r
- store in *piSizeVar the size of extra info in static header\r
- (filename and size of extra field data)\r
-*/\r
-static int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar,\r
- uLong *poffset_local_extrafield,\r
- uInt *psize_local_extrafield)\r
-{\r
- uLong uMagic,uData,uFlags;\r
- uLong size_filename;\r
- uLong size_extra_field;\r
- int err=UNZ_OK;\r
-\r
- *piSizeVar = 0;\r
- *poffset_local_extrafield = 0;\r
- *psize_local_extrafield = 0;\r
-\r
- if (fseek(s->file,s->cur_file_info_internal.offset_curfile +\r
- s->byte_before_the_zipfile,SEEK_SET)!=0)\r
- return UNZ_ERRNO;\r
-\r
-\r
- if (err==UNZ_OK)\r
- if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
- else if (uMagic!=0x04034b50)\r
- err=UNZ_BADZIPFILE;\r
-\r
- if (unzlocal_getShort(s->file,&uData) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-/*\r
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))\r
- err=UNZ_BADZIPFILE;\r
-*/\r
- if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getShort(s->file,&uData) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))\r
- err=UNZ_BADZIPFILE;\r
-\r
- if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&\r
- (s->cur_file_info.compression_method!=Z_DEFLATED))\r
- err=UNZ_BADZIPFILE;\r
-\r
- if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */\r
- err=UNZ_ERRNO;\r
-\r
- if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */\r
- err=UNZ_ERRNO;\r
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&\r
- ((uFlags & 8)==0))\r
- err=UNZ_BADZIPFILE;\r
-\r
- if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */\r
- err=UNZ_ERRNO;\r
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&\r
- ((uFlags & 8)==0))\r
- err=UNZ_BADZIPFILE;\r
-\r
- if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */\r
- err=UNZ_ERRNO;\r
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && \r
- ((uFlags & 8)==0))\r
- err=UNZ_BADZIPFILE;\r
-\r
-\r
- if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
- else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))\r
- err=UNZ_BADZIPFILE;\r
-\r
- *piSizeVar += (uInt)size_filename;\r
-\r
- if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK)\r
- err=UNZ_ERRNO;\r
- *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +\r
- SIZEZIPLOCALHEADER + size_filename;\r
- *psize_local_extrafield = (uInt)size_extra_field;\r
-\r
- *piSizeVar += (uInt)size_extra_field;\r
-\r
- return err;\r
-}\r
- \r
-/*\r
- Open for reading data the current file in the zipfile.\r
- If there is no error and the file is opened, the return value is UNZ_OK.\r
-*/\r
-extern int unzOpenCurrentFile (unzFile file)\r
-{\r
- int err=UNZ_OK;\r
- int Store;\r
- uInt iSizeVar;\r
- unz_s* s;\r
- file_in_zip_read_info_s* pfile_in_zip_read_info;\r
- uLong offset_local_extrafield; /* offset of the static extra field */\r
- uInt size_local_extrafield; /* size of the static extra field */\r
-\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- if (!s->current_file_ok)\r
- return UNZ_PARAMERROR;\r
-\r
- if (s->pfile_in_zip_read != NULL)\r
- unzCloseCurrentFile(file);\r
-\r
- if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,\r
- &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)\r
- return UNZ_BADZIPFILE;\r
-\r
- pfile_in_zip_read_info = (file_in_zip_read_info_s*)\r
- malloc(sizeof(file_in_zip_read_info_s));\r
- if (pfile_in_zip_read_info==NULL)\r
- return UNZ_INTERNALERROR;\r
-\r
- pfile_in_zip_read_info->read_buffer=(char*)malloc(UNZ_BUFSIZE);\r
- pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;\r
- pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;\r
- pfile_in_zip_read_info->pos_local_extrafield=0;\r
-\r
- if (pfile_in_zip_read_info->read_buffer==NULL)\r
- {\r
- free(pfile_in_zip_read_info);\r
- return UNZ_INTERNALERROR;\r
- }\r
-\r
- pfile_in_zip_read_info->stream_initialised=0;\r
- \r
- if ((s->cur_file_info.compression_method!=0) &&\r
- (s->cur_file_info.compression_method!=Z_DEFLATED))\r
- err=UNZ_BADZIPFILE;\r
- Store = s->cur_file_info.compression_method==0;\r
-\r
- pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;\r
- pfile_in_zip_read_info->crc32=0;\r
- pfile_in_zip_read_info->compression_method =\r
- s->cur_file_info.compression_method;\r
- pfile_in_zip_read_info->file=s->file;\r
- pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;\r
-\r
- pfile_in_zip_read_info->stream.total_out = 0;\r
-\r
- if (!Store)\r
- {\r
- pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;\r
- pfile_in_zip_read_info->stream.zfree = (free_func)0;\r
- pfile_in_zip_read_info->stream.opaque = (voidp)0; \r
- \r
- err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);\r
- if (err == Z_OK)\r
- pfile_in_zip_read_info->stream_initialised=1;\r
- /* windowBits is passed < 0 to tell that there is no zlib header.\r
- * Note that in this case inflate *requires* an extra "dummy" byte\r
- * after the compressed stream in order to complete decompression and\r
- * return Z_STREAM_END. \r
- * In unzip, i don't wait absolutely Z_STREAM_END because I known the \r
- * size of both compressed and uncompressed data\r
- */\r
- }\r
- pfile_in_zip_read_info->rest_read_compressed = \r
- s->cur_file_info.compressed_size ;\r
- pfile_in_zip_read_info->rest_read_uncompressed = \r
- s->cur_file_info.uncompressed_size ;\r
-\r
- \r
- pfile_in_zip_read_info->pos_in_zipfile = \r
- s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + \r
- iSizeVar;\r
- \r
- pfile_in_zip_read_info->stream.avail_in = (uInt)0;\r
-\r
-\r
- s->pfile_in_zip_read = pfile_in_zip_read_info;\r
- return UNZ_OK;\r
-}\r
-\r
-\r
-/*\r
- Read bytes from the current file.\r
- buf contain buffer where data must be copied\r
- len the size of buf.\r
-\r
- return the number of byte copied if somes bytes are copied\r
- return 0 if the end of file was reached\r
- return <0 with error code if there is an error\r
- (UNZ_ERRNO for IO error, or zLib error for uncompress error)\r
-*/\r
-extern int unzReadCurrentFile (unzFile file, void *buf, unsigned len)\r
-{\r
- int err=UNZ_OK;\r
- uInt iRead = 0;\r
- unz_s* s;\r
- file_in_zip_read_info_s* pfile_in_zip_read_info;\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- pfile_in_zip_read_info=s->pfile_in_zip_read;\r
-\r
- if (pfile_in_zip_read_info==NULL)\r
- return UNZ_PARAMERROR;\r
-\r
-\r
- if ((pfile_in_zip_read_info->read_buffer == NULL))\r
- return UNZ_END_OF_LIST_OF_FILE;\r
- if (len==0)\r
- return 0;\r
-\r
- pfile_in_zip_read_info->stream.next_out = (Byte*)buf;\r
-\r
- pfile_in_zip_read_info->stream.avail_out = (uInt)len;\r
- \r
- if (len>pfile_in_zip_read_info->rest_read_uncompressed)\r
- pfile_in_zip_read_info->stream.avail_out = \r
- (uInt)pfile_in_zip_read_info->rest_read_uncompressed;\r
-\r
- while (pfile_in_zip_read_info->stream.avail_out>0)\r
- {\r
- if ((pfile_in_zip_read_info->stream.avail_in==0) &&\r
- (pfile_in_zip_read_info->rest_read_compressed>0))\r
- {\r
- uInt uReadThis = UNZ_BUFSIZE;\r
- if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)\r
- uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;\r
- if (uReadThis == 0)\r
- return UNZ_EOF;\r
- if (s->cur_file_info.compressed_size == pfile_in_zip_read_info->rest_read_compressed)\r
- if (fseek(pfile_in_zip_read_info->file,\r
- pfile_in_zip_read_info->pos_in_zipfile + \r
- pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0)\r
- return UNZ_ERRNO;\r
- if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,\r
- pfile_in_zip_read_info->file)!=1)\r
- return UNZ_ERRNO;\r
- pfile_in_zip_read_info->pos_in_zipfile += uReadThis;\r
-\r
- pfile_in_zip_read_info->rest_read_compressed-=uReadThis;\r
- \r
- pfile_in_zip_read_info->stream.next_in = \r
- (Byte*)pfile_in_zip_read_info->read_buffer;\r
- pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;\r
- }\r
-\r
- if (pfile_in_zip_read_info->compression_method==0)\r
- {\r
- uInt uDoCopy,i ;\r
- if (pfile_in_zip_read_info->stream.avail_out < \r
- pfile_in_zip_read_info->stream.avail_in)\r
- uDoCopy = pfile_in_zip_read_info->stream.avail_out ;\r
- else\r
- uDoCopy = pfile_in_zip_read_info->stream.avail_in ;\r
- \r
- for (i=0;i<uDoCopy;i++)\r
- *(pfile_in_zip_read_info->stream.next_out+i) =\r
- *(pfile_in_zip_read_info->stream.next_in+i);\r
- \r
- pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,\r
- pfile_in_zip_read_info->stream.next_out,\r
- uDoCopy);\r
- pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;\r
- pfile_in_zip_read_info->stream.avail_in -= uDoCopy;\r
- pfile_in_zip_read_info->stream.avail_out -= uDoCopy;\r
- pfile_in_zip_read_info->stream.next_out += uDoCopy;\r
- pfile_in_zip_read_info->stream.next_in += uDoCopy;\r
- pfile_in_zip_read_info->stream.total_out += uDoCopy;\r
- iRead += uDoCopy;\r
- }\r
- else\r
- {\r
- uLong uTotalOutBefore,uTotalOutAfter;\r
- const Byte *bufBefore;\r
- uLong uOutThis;\r
- int flush=Z_SYNC_FLUSH;\r
-\r
- uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;\r
- bufBefore = pfile_in_zip_read_info->stream.next_out;\r
-\r
- /*\r
- if ((pfile_in_zip_read_info->rest_read_uncompressed ==\r
- pfile_in_zip_read_info->stream.avail_out) &&\r
- (pfile_in_zip_read_info->rest_read_compressed == 0))\r
- flush = Z_FINISH;\r
- */\r
- err=inflate(&pfile_in_zip_read_info->stream,flush);\r
-\r
- uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;\r
- uOutThis = uTotalOutAfter-uTotalOutBefore;\r
- \r
- pfile_in_zip_read_info->crc32 = \r
- crc32(pfile_in_zip_read_info->crc32,bufBefore,\r
- (uInt)(uOutThis));\r
-\r
- pfile_in_zip_read_info->rest_read_uncompressed -=\r
- uOutThis;\r
-\r
- iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);\r
- \r
- if (err==Z_STREAM_END)\r
- return (iRead==0) ? UNZ_EOF : iRead;\r
- if (err!=Z_OK) \r
- break;\r
- }\r
- }\r
-\r
- if (err==Z_OK)\r
- return iRead;\r
- return err;\r
-}\r
-\r
-\r
-/*\r
- Give the current position in uncompressed data\r
-*/\r
-extern long unztell (unzFile file)\r
-{\r
- unz_s* s;\r
- file_in_zip_read_info_s* pfile_in_zip_read_info;\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- pfile_in_zip_read_info=s->pfile_in_zip_read;\r
-\r
- if (pfile_in_zip_read_info==NULL)\r
- return UNZ_PARAMERROR;\r
-\r
- return (long)pfile_in_zip_read_info->stream.total_out;\r
-}\r
-\r
-\r
-/*\r
- return 1 if the end of file was reached, 0 elsewhere \r
-*/\r
-extern int unzeof (unzFile file)\r
-{\r
- unz_s* s;\r
- file_in_zip_read_info_s* pfile_in_zip_read_info;\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- pfile_in_zip_read_info=s->pfile_in_zip_read;\r
-\r
- if (pfile_in_zip_read_info==NULL)\r
- return UNZ_PARAMERROR;\r
- \r
- if (pfile_in_zip_read_info->rest_read_uncompressed == 0)\r
- return 1;\r
- else\r
- return 0;\r
-}\r
-\r
-\r
-\r
-/*\r
- Read extra field from the current file (opened by unzOpenCurrentFile)\r
- This is the static-header version of the extra field (sometimes, there is\r
- more info in the static-header version than in the central-header)\r
-\r
- if buf==NULL, it return the size of the static extra field that can be read\r
-\r
- if buf!=NULL, len is the size of the buffer, the extra header is copied in\r
- buf.\r
- the return value is the number of bytes copied in buf, or (if <0) \r
- the error code\r
-*/\r
-extern int unzGetLocalExtrafield (unzFile file,void *buf,unsigned len)\r
-{\r
- unz_s* s;\r
- file_in_zip_read_info_s* pfile_in_zip_read_info;\r
- uInt read_now;\r
- uLong size_to_read;\r
-\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- pfile_in_zip_read_info=s->pfile_in_zip_read;\r
-\r
- if (pfile_in_zip_read_info==NULL)\r
- return UNZ_PARAMERROR;\r
-\r
- size_to_read = (pfile_in_zip_read_info->size_local_extrafield - \r
- pfile_in_zip_read_info->pos_local_extrafield);\r
-\r
- if (buf==NULL)\r
- return (int)size_to_read;\r
- \r
- if (len>size_to_read)\r
- read_now = (uInt)size_to_read;\r
- else\r
- read_now = (uInt)len ;\r
-\r
- if (read_now==0)\r
- return 0;\r
- \r
- if (fseek(pfile_in_zip_read_info->file,\r
- pfile_in_zip_read_info->offset_local_extrafield + \r
- pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0)\r
- return UNZ_ERRNO;\r
-\r
- if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1)\r
- return UNZ_ERRNO;\r
-\r
- return (int)read_now;\r
-}\r
-\r
-/*\r
- Close the file in zip opened with unzipOpenCurrentFile\r
- Return UNZ_CRCERROR if all the file was read but the CRC is not good\r
-*/\r
-extern int unzCloseCurrentFile (unzFile file)\r
-{\r
- int err=UNZ_OK;\r
-\r
- unz_s* s;\r
- file_in_zip_read_info_s* pfile_in_zip_read_info;\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
- pfile_in_zip_read_info=s->pfile_in_zip_read;\r
-\r
- if (pfile_in_zip_read_info==NULL)\r
- return UNZ_PARAMERROR;\r
-\r
-\r
- if (pfile_in_zip_read_info->rest_read_uncompressed == 0)\r
- {\r
- if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)\r
- err=UNZ_CRCERROR;\r
- }\r
-\r
-\r
- free(pfile_in_zip_read_info->read_buffer);\r
- pfile_in_zip_read_info->read_buffer = NULL;\r
- if (pfile_in_zip_read_info->stream_initialised)\r
- inflateEnd(&pfile_in_zip_read_info->stream);\r
-\r
- pfile_in_zip_read_info->stream_initialised = 0;\r
- free(pfile_in_zip_read_info);\r
-\r
- s->pfile_in_zip_read=NULL;\r
-\r
- return err;\r
-}\r
-\r
-\r
-/*\r
- Get the global comment string of the ZipFile, in the szComment buffer.\r
- uSizeBuf is the size of the szComment buffer.\r
- return the number of byte copied or an error code <0\r
-*/\r
-extern int unzGetGlobalComment (unzFile file, char *szComment, uLong uSizeBuf)\r
-{\r
- unz_s* s;\r
- uLong uReadThis ;\r
- if (file==NULL)\r
- return UNZ_PARAMERROR;\r
- s=(unz_s*)file;\r
-\r
- uReadThis = uSizeBuf;\r
- if (uReadThis>s->gi.size_comment)\r
- uReadThis = s->gi.size_comment;\r
-\r
- if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0)\r
- return UNZ_ERRNO;\r
-\r
- if (uReadThis>0)\r
- {\r
- *szComment='\0';\r
- if (fread(szComment,(uInt)uReadThis,1,s->file)!=1)\r
- return UNZ_ERRNO;\r
- }\r
-\r
- if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))\r
- *(szComment+s->gi.size_comment)='\0';\r
- return (int)uReadThis;\r
-}\r
-\r
-/* crc32.c -- compute the CRC-32 of a data stream\r
- * Copyright (C) 1995-1998 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-#ifdef DYNAMIC_CRC_TABLE\r
-\r
-static int crc_table_empty = 1;\r
-static uLong crc_table[256];\r
-static void make_crc_table OF((void));\r
-\r
-/*\r
- Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:\r
- x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.\r
-\r
- Polynomials over GF(2) are represented in binary, one bit per coefficient,\r
- with the lowest powers in the most significant bit. Then adding polynomials\r
- is just exclusive-or, and multiplying a polynomial by x is a right shift by\r
- one. If we call the above polynomial p, and represent a byte as the\r
- polynomial q, also with the lowest power in the most significant bit (so the\r
- byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,\r
- where a mod b means the remainder after dividing a by b.\r
-\r
- This calculation is done using the shift-register method of multiplying and\r
- taking the remainder. The register is initialized to zero, and for each\r
- incoming bit, x^32 is added mod p to the register if the bit is a one (where\r
- x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by\r
- x (which is shifting right by one and adding x^32 mod p if the bit shifted\r
- out is a one). We start with the highest power (least significant bit) of\r
- q and repeat for all eight bits of q.\r
-\r
- The table is simply the CRC of all possible eight bit values. This is all\r
- the information needed to generate CRC's on data a byte at a time for all\r
- combinations of CRC register values and incoming bytes.\r
-*/\r
-static void make_crc_table()\r
-{\r
- uLong c;\r
- int n, k;\r
- uLong poly; /* polynomial exclusive-or pattern */\r
- /* terms of polynomial defining this crc (except x^32): */\r
- static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};\r
-\r
- /* make exclusive-or pattern from polynomial (0xedb88320L) */\r
- poly = 0L;\r
- for (n = 0; n < sizeof(p)/sizeof(Byte); n++)\r
- poly |= 1L << (31 - p[n]);\r
- \r
- for (n = 0; n < 256; n++)\r
- {\r
- c = (uLong)n;\r
- for (k = 0; k < 8; k++)\r
- c = c & 1 ? poly ^ (c >> 1) : c >> 1;\r
- crc_table[n] = c;\r
- }\r
- crc_table_empty = 0;\r
-}\r
-#else\r
-/* ========================================================================\r
- * Table of CRC-32's of all single-byte values (made by make_crc_table)\r
- */\r
-static const uLong crc_table[256] = {\r
- 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,\r
- 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,\r
- 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,\r
- 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,\r
- 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,\r
- 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,\r
- 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,\r
- 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,\r
- 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,\r
- 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,\r
- 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,\r
- 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,\r
- 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,\r
- 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,\r
- 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,\r
- 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,\r
- 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,\r
- 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,\r
- 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,\r
- 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,\r
- 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,\r
- 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,\r
- 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,\r
- 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,\r
- 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,\r
- 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,\r
- 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,\r
- 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,\r
- 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,\r
- 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,\r
- 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,\r
- 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,\r
- 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,\r
- 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,\r
- 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,\r
- 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,\r
- 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,\r
- 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,\r
- 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,\r
- 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,\r
- 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,\r
- 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,\r
- 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,\r
- 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,\r
- 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,\r
- 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,\r
- 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,\r
- 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,\r
- 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,\r
- 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,\r
- 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,\r
- 0x2d02ef8dL\r
-};\r
-#endif\r
-\r
-/* =========================================================================\r
- * This function can be used by asm versions of crc32()\r
- */\r
-const uLong * get_crc_table()\r
-{\r
-#ifdef DYNAMIC_CRC_TABLE\r
- if (crc_table_empty) make_crc_table();\r
-#endif\r
- return (const uLong *)crc_table;\r
-}\r
-\r
-/* ========================================================================= */\r
-#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);\r
-#define DO2(buf) DO1(buf); DO1(buf);\r
-#define DO4(buf) DO2(buf); DO2(buf);\r
-#define DO8(buf) DO4(buf); DO4(buf);\r
-\r
-/* ========================================================================= */\r
-uLong crc32(uLong crc, const Byte *buf, uInt len)\r
-{\r
- if (buf == Z_NULL) return 0L;\r
-#ifdef DYNAMIC_CRC_TABLE\r
- if (crc_table_empty)\r
- make_crc_table();\r
-#endif\r
- crc = crc ^ 0xffffffffL;\r
- while (len >= 8)\r
- {\r
- DO8(buf);\r
- len -= 8;\r
- }\r
- if (len) do {\r
- DO1(buf);\r
- } while (--len);\r
- return crc ^ 0xffffffffL;\r
-}\r
-\r
-/* infblock.h -- header to use infblock.c\r
- * Copyright (C) 1995-1998 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-/* WARNING: this file should *not* be used by applications. It is\r
- part of the implementation of the compression library and is\r
- subject to change. Applications should only use zlib.h.\r
- */\r
-\r
-struct inflate_blocks_state;\r
-typedef struct inflate_blocks_state inflate_blocks_statef;\r
-\r
-extern inflate_blocks_statef * inflate_blocks_new OF((\r
- z_streamp z,\r
- check_func c, /* check function */\r
- uInt w)); /* window size */\r
-\r
-extern int inflate_blocks OF((\r
- inflate_blocks_statef *,\r
- z_streamp ,\r
- int)); /* initial return code */\r
-\r
-extern void inflate_blocks_reset OF((\r
- inflate_blocks_statef *,\r
- z_streamp ,\r
- uLong *)); /* check value on output */\r
-\r
-extern int inflate_blocks_free OF((\r
- inflate_blocks_statef *,\r
- z_streamp));\r
-\r
-extern void inflate_set_dictionary OF((\r
- inflate_blocks_statef *s,\r
- const Byte *d, /* dictionary */\r
- uInt n)); /* dictionary length */\r
-\r
-extern int inflate_blocks_sync_point OF((\r
- inflate_blocks_statef *s));\r
-\r
-/* simplify the use of the inflate_huft type with some defines */\r
-#define exop word.what.Exop\r
-#define bits word.what.Bits\r
-\r
-/* Table for deflate from PKZIP's appnote.txt. */\r
-static const uInt border[] = { /* Order of the bit length code lengths */\r
- 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};\r
-\r
-/* inftrees.h -- header to use inftrees.c\r
- * Copyright (C) 1995-1998 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-/* WARNING: this file should *not* be used by applications. It is\r
- part of the implementation of the compression library and is\r
- subject to change. Applications should only use zlib.h.\r
- */\r
-\r
-/* Huffman code lookup table entry--this entry is four bytes for machines\r
- that have 16-bit pointers (e.g. PC's in the small or medium model). */\r
-\r
-typedef struct inflate_huft_s inflate_huft;\r
-\r
-struct inflate_huft_s {\r
- union {\r
- struct {\r
- Byte Exop; /* number of extra bits or operation */\r
- Byte Bits; /* number of bits in this code or subcode */\r
- } what;\r
- uInt pad; /* pad structure to a power of 2 (4 bytes for */\r
- } word; /* 16-bit, 8 bytes for 32-bit int's) */\r
- uInt base; /* literal, length base, distance base,\r
- or table offset */\r
-};\r
-\r
-/* Maximum size of dynamic tree. The maximum found in a long but non-\r
- exhaustive search was 1004 huft structures (850 for length/literals\r
- and 154 for distances, the latter actually the result of an\r
- exhaustive search). The actual maximum is not known, but the\r
- value below is more than safe. */\r
-#define MANY 1440\r
-\r
-extern int inflate_trees_bits OF((\r
- uInt *, /* 19 code lengths */\r
- uInt *, /* bits tree desired/actual depth */\r
- inflate_huft * *, /* bits tree result */\r
- inflate_huft *, /* space for trees */\r
- z_streamp)); /* for messages */\r
-\r
-extern int inflate_trees_dynamic OF((\r
- uInt, /* number of literal/length codes */\r
- uInt, /* number of distance codes */\r
- uInt *, /* that many (total) code lengths */\r
- uInt *, /* literal desired/actual bit depth */\r
- uInt *, /* distance desired/actual bit depth */\r
- inflate_huft * *, /* literal/length tree result */\r
- inflate_huft * *, /* distance tree result */\r
- inflate_huft *, /* space for trees */\r
- z_streamp)); /* for messages */\r
-\r
-extern int inflate_trees_fixed OF((\r
- uInt *, /* literal desired/actual bit depth */\r
- uInt *, /* distance desired/actual bit depth */\r
- inflate_huft * *, /* literal/length tree result */\r
- inflate_huft * *, /* distance tree result */\r
- z_streamp)); /* for memory allocation */\r
-\r
-\r
-/* infcodes.h -- header to use infcodes.c\r
- * Copyright (C) 1995-1998 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-/* WARNING: this file should *not* be used by applications. It is\r
- part of the implementation of the compression library and is\r
- subject to change. Applications should only use zlib.h.\r
- */\r
-\r
-struct inflate_codes_state;\r
-typedef struct inflate_codes_state inflate_codes_statef;\r
-\r
-extern inflate_codes_statef *inflate_codes_new OF((\r
- uInt, uInt,\r
- inflate_huft *, inflate_huft *,\r
- z_streamp ));\r
-\r
-extern int inflate_codes OF((\r
- inflate_blocks_statef *,\r
- z_streamp ,\r
- int));\r
-\r
-extern void inflate_codes_free OF((\r
- inflate_codes_statef *,\r
- z_streamp ));\r
-\r
-/* infutil.h -- types and macros common to blocks and codes\r
- * Copyright (C) 1995-1998 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-/* WARNING: this file should *not* be used by applications. It is\r
- part of the implementation of the compression library and is\r
- subject to change. Applications should only use zlib.h.\r
- */\r
-\r
-#ifndef _INFUTIL_H\r
-#define _INFUTIL_H\r
-\r
-typedef enum {\r
- TYPE, /* get type bits (3, including end bit) */\r
- LENS, /* get lengths for stored */\r
- STORED, /* processing stored block */\r
- TABLE, /* get table lengths */\r
- BTREE, /* get bit lengths tree for a dynamic block */\r
- DTREE, /* get length, distance trees for a dynamic block */\r
- CODES, /* processing fixed or dynamic block */\r
- DRY, /* output remaining window bytes */\r
- DONE, /* finished last block, done */\r
- BAD} /* got a data error--stuck here */\r
-inflate_block_mode;\r
-\r
-/* inflate blocks semi-private state */\r
-struct inflate_blocks_state {\r
-\r
- /* mode */\r
- inflate_block_mode mode; /* current inflate_block mode */\r
-\r
- /* mode dependent information */\r
- union {\r
- uInt left; /* if STORED, bytes left to copy */\r
- struct {\r
- uInt table; /* table lengths (14 bits) */\r
- uInt index; /* index into blens (or border) */\r
- uInt *blens; /* bit lengths of codes */\r
- uInt bb; /* bit length tree depth */\r
- inflate_huft *tb; /* bit length decoding tree */\r
- } trees; /* if DTREE, decoding info for trees */\r
- struct {\r
- inflate_codes_statef \r
- *codes;\r
- } decode; /* if CODES, current state */\r
- } sub; /* submode */\r
- uInt last; /* true if this block is the last block */\r
-\r
- /* mode independent information */\r
- uInt bitk; /* bits in bit buffer */\r
- uLong bitb; /* bit buffer */\r
- inflate_huft *hufts; /* single malloc for tree space */\r
- Byte *window; /* sliding window */\r
- Byte *end; /* one byte after sliding window */\r
- Byte *read; /* window read pointer */\r
- Byte *write; /* window write pointer */\r
- check_func checkfn; /* check function */\r
- uLong check; /* check on output */\r
-\r
-};\r
-\r
-\r
-/* defines for inflate input/output */\r
-/* update pointers and return */\r
-#define UPDBITS {s->bitb=b;s->bitk=k;}\r
-#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}\r
-#define UPDOUT {s->write=q;}\r
-#define UPDATE {UPDBITS UPDIN UPDOUT}\r
-#define LEAVE {UPDATE return inflate_flush(s,z,r);}\r
-/* get bytes and bits */\r
-#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}\r
-#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}\r
-#define NEXTBYTE (n--,*p++)\r
-#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}\r
-#define DUMPBITS(j) {b>>=(j);k-=(j);}\r
-/* output bytes */\r
-#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)\r
-#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}\r
-#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}\r
-#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}\r
-#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}\r
-#define OUTBYTE(a) {*q++=(Byte)(a);m--;}\r
-/* load static pointers */\r
-#define LOAD {LOADIN LOADOUT}\r
-\r
-/* masks for lower bits (size given to avoid silly warnings with Visual C++) */\r
-extern uInt inflate_mask[17];\r
-\r
-/* copy as much as possible from the sliding window to the output area */\r
-extern int inflate_flush OF((\r
- inflate_blocks_statef *,\r
- z_streamp ,\r
- int));\r
-\r
-#endif\r
-\r
- \r
-/*\r
- Notes beyond the 1.93a appnote.txt:\r
-\r
- 1. Distance pointers never point before the beginning of the output\r
- stream.\r
- 2. Distance pointers can point back across blocks, up to 32k away.\r
- 3. There is an implied maximum of 7 bits for the bit length table and\r
- 15 bits for the actual data.\r
- 4. If only one code exists, then it is encoded using one bit. (Zero\r
- would be more efficient, but perhaps a little confusing.) If two\r
- codes exist, they are coded using one bit each (0 and 1).\r
- 5. There is no way of sending zero distance codes--a dummy must be\r
- sent if there are none. (History: a pre 2.0 version of PKZIP would\r
- store blocks with no distance codes, but this was discovered to be\r
- too harsh a criterion.) Valid only for 1.93a. 2.04c does allow\r
- zero distance codes, which is sent as one code of zero bits in\r
- length.\r
- 6. There are up to 286 literal/length codes. Code 256 represents the\r
- end-of-block. Note however that the static length tree defines\r
- 288 codes just to fill out the Huffman codes. Codes 286 and 287\r
- cannot be used though, since there is no length base or extra bits\r
- defined for them. Similarily, there are up to 30 distance codes.\r
- However, static trees define 32 codes (all 5 bits) to fill out the\r
- Huffman codes, but the last two had better not show up in the data.\r
- 7. Unzip can check dynamic Huffman blocks for complete code sets.\r
- The exception is that a single code would not be complete (see #4).\r
- 8. The five bits following the block type is really the number of\r
- literal codes sent minus 257.\r
- 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits\r
- (1+6+6). Therefore, to output three times the length, you output\r
- three codes (1+1+1), whereas to output four times the same length,\r
- you only need two codes (1+3). Hmm.\r
- 10. In the tree reconstruction algorithm, Code = Code + Increment\r
- only if BitLength(i) is not zero. (Pretty obvious.)\r
- 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)\r
- 12. Note: length code 284 can represent 227-258, but length code 285\r
- really is 258. The last length deserves its own, short code\r
- since it gets used a lot in very redundant files. The length\r
- 258 is special since 258 - 3 (the min match length) is 255.\r
- 13. The literal/length and distance code bit lengths are read as a\r
- single stream of lengths. It is possible (and advantageous) for\r
- a repeat code (16, 17, or 18) to go across the boundary between\r
- the two sets of lengths.\r
- */\r
-\r
-\r
-void inflate_blocks_reset(inflate_blocks_statef *s, z_streamp z, uLong *c)\r
-{\r
- if (c != Z_NULL)\r
- *c = s->check;\r
- if (s->mode == BTREE || s->mode == DTREE)\r
- ZFREE(z, s->sub.trees.blens);\r
- if (s->mode == CODES)\r
- inflate_codes_free(s->sub.decode.codes, z);\r
- s->mode = TYPE;\r
- s->bitk = 0;\r
- s->bitb = 0;\r
- s->read = s->write = s->window;\r
- if (s->checkfn != Z_NULL)\r
- z->adler = s->check = (*s->checkfn)(0L, (const Byte *)Z_NULL, 0);\r
- Tracev(("inflate: blocks reset\n"));\r
-}\r
-\r
-\r
-inflate_blocks_statef *inflate_blocks_new(z_streamp z, check_func c, uInt w)\r
-{\r
- inflate_blocks_statef *s;\r
-\r
- if ((s = (inflate_blocks_statef *)ZALLOC\r
- (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)\r
- return s;\r
- if ((s->hufts =\r
- (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)\r
- {\r
- ZFREE(z, s);\r
- return Z_NULL;\r
- }\r
- if ((s->window = (Byte *)ZALLOC(z, 1, w)) == Z_NULL)\r
- {\r
- ZFREE(z, s->hufts);\r
- ZFREE(z, s);\r
- return Z_NULL;\r
- }\r
- s->end = s->window + w;\r
- s->checkfn = c;\r
- s->mode = TYPE;\r
- Tracev(("inflate: blocks allocated\n"));\r
- inflate_blocks_reset(s, z, Z_NULL);\r
- return s;\r
-}\r
-\r
-\r
-int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)\r
-{\r
- uInt t; /* temporary storage */\r
- uLong b; /* bit buffer */\r
- uInt k; /* bits in bit buffer */\r
- Byte *p; /* input data pointer */\r
- uInt n; /* bytes available there */\r
- Byte *q; /* output window write pointer */\r
- uInt m; /* bytes to end of window or read pointer */\r
-\r
- /* copy input/output information to locals (UPDATE macro restores) */\r
- LOAD\r
-\r
- /* process input based on current state */\r
- while (1) switch (s->mode)\r
- {\r
- case TYPE:\r
- NEEDBITS(3)\r
- t = (uInt)b & 7;\r
- s->last = t & 1;\r
- switch (t >> 1)\r
- {\r
- case 0: /* stored */\r
- Tracev(("inflate: stored block%s\n",\r
- s->last ? " (last)" : ""));\r
- DUMPBITS(3)\r
- t = k & 7; /* go to byte boundary */\r
- DUMPBITS(t)\r
- s->mode = LENS; /* get length of stored block */\r
- break;\r
- case 1: /* fixed */\r
- Tracev(("inflate: fixed codes block%s\n",\r
- s->last ? " (last)" : ""));\r
- {\r
- uInt bl, bd;\r
- inflate_huft *tl, *td;\r
-\r
- inflate_trees_fixed(&bl, &bd, &tl, &td, z);\r
- s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);\r
- if (s->sub.decode.codes == Z_NULL)\r
- {\r
- r = Z_MEM_ERROR;\r
- LEAVE\r
- }\r
- }\r
- DUMPBITS(3)\r
- s->mode = CODES;\r
- break;\r
- case 2: /* dynamic */\r
- Tracev(("inflate: dynamic codes block%s\n",\r
- s->last ? " (last)" : ""));\r
- DUMPBITS(3)\r
- s->mode = TABLE;\r
- break;\r
- case 3: /* illegal */\r
- DUMPBITS(3)\r
- s->mode = BAD;\r
- z->msg = (char*)"invalid block type";\r
- r = Z_DATA_ERROR;\r
- LEAVE\r
- }\r
- break;\r
- case LENS:\r
- NEEDBITS(32)\r
- if ((((~b) >> 16) & 0xffff) != (b & 0xffff))\r
- {\r
- s->mode = BAD;\r
- z->msg = (char*)"invalid stored block lengths";\r
- r = Z_DATA_ERROR;\r
- LEAVE\r
- }\r
- s->sub.left = (uInt)b & 0xffff;\r
- b = k = 0; /* dump bits */\r
- Tracev(("inflate: stored length %u\n", s->sub.left));\r
- s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);\r
- break;\r
- case STORED:\r
- if (n == 0)\r
- LEAVE\r
- NEEDOUT\r
- t = s->sub.left;\r
- if (t > n) t = n;\r
- if (t > m) t = m;\r
- zmemcpy(q, p, t);\r
- p += t; n -= t;\r
- q += t; m -= t;\r
- if ((s->sub.left -= t) != 0)\r
- break;\r
- Tracev(("inflate: stored end, %lu total out\n",\r
- z->total_out + (q >= s->read ? q - s->read :\r
- (s->end - s->read) + (q - s->window))));\r
- s->mode = s->last ? DRY : TYPE;\r
- break;\r
- case TABLE:\r
- NEEDBITS(14)\r
- s->sub.trees.table = t = (uInt)b & 0x3fff;\r
-#ifndef PKZIP_BUG_WORKAROUND\r
- if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)\r
- {\r
- s->mode = BAD;\r
- z->msg = (char*)"too many length or distance symbols";\r
- r = Z_DATA_ERROR;\r
- LEAVE\r
- }\r
-#endif\r
- t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);\r
- if ((s->sub.trees.blens = (uInt*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)\r
- {\r
- r = Z_MEM_ERROR;\r
- LEAVE\r
- }\r
- DUMPBITS(14)\r
- s->sub.trees.index = 0;\r
- Tracev(("inflate: table sizes ok\n"));\r
- s->mode = BTREE;\r
- case BTREE:\r
- while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))\r
- {\r
- NEEDBITS(3)\r
- s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;\r
- DUMPBITS(3)\r
- }\r
- while (s->sub.trees.index < 19)\r
- s->sub.trees.blens[border[s->sub.trees.index++]] = 0;\r
- s->sub.trees.bb = 7;\r
- t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,\r
- &s->sub.trees.tb, s->hufts, z);\r
- if (t != Z_OK)\r
- {\r
- ZFREE(z, s->sub.trees.blens);\r
- r = t;\r
- if (r == Z_DATA_ERROR)\r
- s->mode = BAD;\r
- LEAVE\r
- }\r
- s->sub.trees.index = 0;\r
- Tracev(("inflate: bits tree ok\n"));\r
- s->mode = DTREE;\r
- case DTREE:\r
- while (t = s->sub.trees.table,\r
- s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))\r
- {\r
- inflate_huft *h;\r
- uInt i, j, c;\r
-\r
- t = s->sub.trees.bb;\r
- NEEDBITS(t)\r
- h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);\r
- t = h->bits;\r
- c = h->base;\r
- if (c < 16)\r
- {\r
- DUMPBITS(t)\r
- s->sub.trees.blens[s->sub.trees.index++] = c;\r
- }\r
- else /* c == 16..18 */\r
- {\r
- i = c == 18 ? 7 : c - 14;\r
- j = c == 18 ? 11 : 3;\r
- NEEDBITS(t + i)\r
- DUMPBITS(t)\r
- j += (uInt)b & inflate_mask[i];\r
- DUMPBITS(i)\r
- i = s->sub.trees.index;\r
- t = s->sub.trees.table;\r
- if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||\r
- (c == 16 && i < 1))\r
- {\r
- ZFREE(z, s->sub.trees.blens);\r
- s->mode = BAD;\r
- z->msg = (char*)"invalid bit length repeat";\r
- r = Z_DATA_ERROR;\r
- LEAVE\r
- }\r
- c = c == 16 ? s->sub.trees.blens[i - 1] : 0;\r
- do {\r
- s->sub.trees.blens[i++] = c;\r
- } while (--j);\r
- s->sub.trees.index = i;\r
- }\r
- }\r
- s->sub.trees.tb = Z_NULL;\r
- {\r
- uInt bl, bd;\r
- inflate_huft *tl, *td;\r
- inflate_codes_statef *c;\r
-\r
- bl = 9; /* must be <= 9 for lookahead assumptions */\r
- bd = 6; /* must be <= 9 for lookahead assumptions */\r
- t = s->sub.trees.table;\r
- t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),\r
- s->sub.trees.blens, &bl, &bd, &tl, &td,\r
- s->hufts, z);\r
- ZFREE(z, s->sub.trees.blens);\r
- if (t != Z_OK)\r
- {\r
- if (t == (uInt)Z_DATA_ERROR)\r
- s->mode = BAD;\r
- r = t;\r
- LEAVE\r
- }\r
- Tracev(("inflate: trees ok\n"));\r
- if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)\r
- {\r
- r = Z_MEM_ERROR;\r
- LEAVE\r
- }\r
- s->sub.decode.codes = c;\r
- }\r
- s->mode = CODES;\r
- case CODES:\r
- UPDATE\r
- if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)\r
- return inflate_flush(s, z, r);\r
- r = Z_OK;\r
- inflate_codes_free(s->sub.decode.codes, z);\r
- LOAD\r
- Tracev(("inflate: codes end, %lu total out\n",\r
- z->total_out + (q >= s->read ? q - s->read :\r
- (s->end - s->read) + (q - s->window))));\r
- if (!s->last)\r
- {\r
- s->mode = TYPE;\r
- break;\r
- }\r
- s->mode = DRY;\r
- case DRY:\r
- FLUSH\r
- if (s->read != s->write)\r
- LEAVE\r
- s->mode = DONE;\r
- case DONE:\r
- r = Z_STREAM_END;\r
- LEAVE\r
- case BAD:\r
- r = Z_DATA_ERROR;\r
- LEAVE\r
- default:\r
- r = Z_STREAM_ERROR;\r
- LEAVE\r
- }\r
-}\r
-\r
-\r
-int inflate_blocks_free(inflate_blocks_statef *s, z_streamp z)\r
-{\r
- inflate_blocks_reset(s, z, Z_NULL);\r
- ZFREE(z, s->window);\r
- ZFREE(z, s->hufts);\r
- ZFREE(z, s);\r
- Tracev(("inflate: blocks freed\n"));\r
- return Z_OK;\r
-}\r
-\r
-\r
-void inflate_set_dictionary(inflate_blocks_statef *s, const Byte *d, uInt n)\r
-{\r
- zmemcpy(s->window, d, n);\r
- s->read = s->write = s->window + n;\r
-}\r
-\r
-\r
-/* Returns true if inflate is currently at the end of a block generated\r
- * by Z_SYNC_FLUSH or Z_FULL_FLUSH. \r
- * IN assertion: s != Z_NULL\r
- */\r
-int inflate_blocks_sync_point(inflate_blocks_statef *s)\r
-{\r
- return s->mode == LENS;\r
-}\r
-\r
-/* And'ing with mask[n] masks the lower n bits */\r
-uInt inflate_mask[17] = {\r
- 0x0000,\r
- 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,\r
- 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff\r
-};\r
-\r
-/* copy as much as possible from the sliding window to the output area */\r
-int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r)\r
-{\r
- uInt n;\r
- Byte *p;\r
- Byte *q;\r
-\r
- /* static copies of source and destination pointers */\r
- p = z->next_out;\r
- q = s->read;\r
-\r
- /* compute number of bytes to copy as as end of window */\r
- n = (uInt)((q <= s->write ? s->write : s->end) - q);\r
- if (n > z->avail_out) n = z->avail_out;\r
- if (n && r == Z_BUF_ERROR) r = Z_OK;\r
-\r
- /* update counters */\r
- z->avail_out -= n;\r
- z->total_out += n;\r
-\r
- /* update check information */\r
- if (s->checkfn != Z_NULL)\r
- z->adler = s->check = (*s->checkfn)(s->check, q, n);\r
-\r
- /* copy as as end of window */\r
- zmemcpy(p, q, n);\r
- p += n;\r
- q += n;\r
-\r
- /* see if more to copy at beginning of window */\r
- if (q == s->end)\r
- {\r
- /* wrap pointers */\r
- q = s->window;\r
- if (s->write == s->end)\r
- s->write = s->window;\r
-\r
- /* compute bytes to copy */\r
- n = (uInt)(s->write - q);\r
- if (n > z->avail_out) n = z->avail_out;\r
- if (n && r == Z_BUF_ERROR) r = Z_OK;\r
-\r
- /* update counters */\r
- z->avail_out -= n;\r
- z->total_out += n;\r
-\r
- /* update check information */\r
- if (s->checkfn != Z_NULL)\r
- z->adler = s->check = (*s->checkfn)(s->check, q, n);\r
-\r
- /* copy */\r
- zmemcpy(p, q, n);\r
- p += n;\r
- q += n;\r
- }\r
-\r
- /* update pointers */\r
- z->next_out = p;\r
- s->read = q;\r
-\r
- /* done */\r
- return r;\r
-}\r
-\r
-/* inftrees.c -- generate Huffman trees for efficient decoding\r
- * Copyright (C) 1995-1998 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-const char inflate_copyright[] =\r
- " inflate 1.1.3 Copyright 1995-1998 Mark Adler ";\r
-/*\r
- If you use the zlib library in a product, an acknowledgment is welcome\r
- in the documentation of your product. If for some reason you cannot\r
- include such an acknowledgment, I would appreciate that you keep this\r
- copyright string in the executable of your product.\r
- */\r
-\r
-/* simplify the use of the inflate_huft type with some defines */\r
-#define exop word.what.Exop\r
-#define bits word.what.Bits\r
-\r
-\r
-static int huft_build OF((\r
- uInt *, /* code lengths in bits */\r
- uInt, /* number of codes */\r
- uInt, /* number of "simple" codes */\r
- const uInt *, /* list of base values for non-simple codes */\r
- const uInt *, /* list of extra bits for non-simple codes */\r
- inflate_huft **, /* result: starting table */\r
- uInt *, /* maximum lookup bits (returns actual) */\r
- inflate_huft *, /* space for trees */\r
- uInt *, /* hufts used in space */\r
- uInt * )); /* space for values */\r
-\r
-/* Tables for deflate from PKZIP's appnote.txt. */\r
-static const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */\r
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,\r
- 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};\r
- /* see note #13 above about 258 */\r
-static const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */\r
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,\r
- 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */\r
-static const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */\r
- 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,\r
- 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,\r
- 8193, 12289, 16385, 24577};\r
-static const uInt cpdext[30] = { /* Extra bits for distance codes */\r
- 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,\r
- 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,\r
- 12, 12, 13, 13};\r
-\r
-/*\r
- Huffman code decoding is performed using a multi-level table lookup.\r
- The fastest way to decode is to simply build a lookup table whose\r
- size is determined by the longest code. However, the time it takes\r
- to build this table can also be a factor if the data being decoded\r
- is not very long. The most common codes are necessarily the\r
- shortest codes, so those codes dominate the decoding time, and hence\r
- the speed. The idea is you can have a shorter table that decodes the\r
- shorter, more probable codes, and then point to subsidiary tables for\r
- the longer codes. The time it costs to decode the longer codes is\r
- then traded against the time it takes to make longer tables.\r
-\r
- This results of this trade are in the variables lbits and dbits\r
- below. lbits is the number of bits the first level table for literal/\r
- length codes can decode in one step, and dbits is the same thing for\r
- the distance codes. Subsequent tables are also less than or equal to\r
- those sizes. These values may be adjusted either when all of the\r
- codes are shorter than that, in which case the longest code length in\r
- bits is used, or when the shortest code is *longer* than the requested\r
- table size, in which case the length of the shortest code in bits is\r
- used.\r
-\r
- There are two different values for the two tables, since they code a\r
- different number of possibilities each. The literal/length table\r
- codes 286 possible values, or in a flat code, a little over eight\r
- bits. The distance table codes 30 possible values, or a little less\r
- than five bits, flat. The optimum values for speed end up being\r
- about one bit more than those, so lbits is 8+1 and dbits is 5+1.\r
- The optimum values may differ though from machine to machine, and\r
- possibly even between compilers. Your mileage may vary.\r
- */\r
-\r
-\r
-/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */\r
-#define BMAX 15 /* maximum bit length of any code */\r
-\r
-static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inflate_huft ** t, uInt *m, inflate_huft *hp, uInt *hn, uInt *v)\r
-//uInt *b; /* code lengths in bits (all assumed <= BMAX) */\r
-//uInt n; /* number of codes (assumed <= 288) */\r
-//uInt s; /* number of simple-valued codes (0..s-1) */\r
-//const uInt *d; /* list of base values for non-simple codes */\r
-//const uInt *e; /* list of extra bits for non-simple codes */\r
-//inflate_huft ** t; /* result: starting table */\r
-//uInt *m; /* maximum lookup bits, returns actual */\r
-//inflate_huft *hp; /* space for trees */\r
-//uInt *hn; /* hufts used in space */\r
-//uInt *v; /* working area: values in order of bit length */\r
-/* Given a list of code lengths and a maximum table size, make a set of\r
- tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR\r
- if the given code set is incomplete (the tables are still built in this\r
- case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of\r
- lengths), or Z_MEM_ERROR if not enough memory. */\r
-{\r
-\r
- uInt a; /* counter for codes of length k */\r
- uInt c[BMAX+1]; /* bit length count table */\r
- uInt f; /* i repeats in table every f entries */\r
- int g; /* maximum code length */\r
- int h; /* table level */\r
- register uInt i; /* counter, current code */\r
- register uInt j; /* counter */\r
- register int k; /* number of bits in current code */\r
- int l; /* bits per table (returned in m) */\r
- uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */\r
- register uInt *p; /* pointer into c[], b[], or v[] */\r
- inflate_huft *q; /* points to current table */\r
- struct inflate_huft_s r; /* table entry for structure assignment */\r
- inflate_huft *u[BMAX]; /* table stack */\r
- register int w; /* bits before this table == (l * h) */\r
- uInt x[BMAX+1]; /* bit offsets, then code stack */\r
- uInt *xp; /* pointer into x */\r
- int y; /* number of dummy codes added */\r
- uInt z; /* number of entries in current table */\r
-\r
-\r
- /* Generate counts for each bit length */\r
- p = c;\r
-#define C0 *p++ = 0;\r
-#define C2 C0 C0 C0 C0\r
-#define C4 C2 C2 C2 C2\r
- C4 /* clear c[]--assume BMAX+1 is 16 */\r
- p = b; i = n;\r
- do {\r
- c[*p++]++; /* assume all entries <= BMAX */\r
- } while (--i);\r
- if (c[0] == n) /* null input--all zero length codes */\r
- {\r
- *t = (inflate_huft *)Z_NULL;\r
- *m = 0;\r
- return Z_OK;\r
- }\r
-\r
-\r
- /* Find minimum and maximum length, bound *m by those */\r
- l = *m;\r
- for (j = 1; j <= BMAX; j++)\r
- if (c[j])\r
- break;\r
- k = j; /* minimum code length */\r
- if ((uInt)l < j)\r
- l = j;\r
- for (i = BMAX; i; i--)\r
- if (c[i])\r
- break;\r
- g = i; /* maximum code length */\r
- if ((uInt)l > i)\r
- l = i;\r
- *m = l;\r
-\r
-\r
- /* Adjust last length count to fill out codes, if needed */\r
- for (y = 1 << j; j < i; j++, y <<= 1)\r
- if ((y -= c[j]) < 0)\r
- return Z_DATA_ERROR;\r
- if ((y -= c[i]) < 0)\r
- return Z_DATA_ERROR;\r
- c[i] += y;\r
-\r
-\r
- /* Generate starting offsets into the value table for each length */\r
- x[1] = j = 0;\r
- p = c + 1; xp = x + 2;\r
- while (--i) { /* note that i == g from above */\r
- *xp++ = (j += *p++);\r
- }\r
-\r
-\r
- /* Make a table of values in order of bit lengths */\r
- p = b; i = 0;\r
- do {\r
- if ((j = *p++) != 0)\r
- v[x[j]++] = i;\r
- } while (++i < n);\r
- n = x[g]; /* set n to length of v */\r
-\r
-\r
- /* Generate the Huffman codes and for each, make the table entries */\r
- x[0] = i = 0; /* first Huffman code is zero */\r
- p = v; /* grab values in bit order */\r
- h = -1; /* no tables yet--level -1 */\r
- w = -l; /* bits decoded == (l * h) */\r
- u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */\r
- q = (inflate_huft *)Z_NULL; /* ditto */\r
- z = 0; /* ditto */\r
-\r
- /* go through the bit lengths (k already is bits in shortest code) */\r
- for (; k <= g; k++)\r
- {\r
- a = c[k];\r
- while (a--)\r
- {\r
- /* here i is the Huffman code of length k bits for value *p */\r
- /* make tables up to required level */\r
- while (k > w + l)\r
- {\r
- h++;\r
- w += l; /* previous table always l bits */\r
-\r
- /* compute minimum size table less than or equal to l bits */\r
- z = g - w;\r
- z = z > (uInt)l ? l : z; /* table size upper limit */\r
- if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */\r
- { /* too few codes for k-w bit table */\r
- f -= a + 1; /* deduct codes from patterns left */\r
- xp = c + k;\r
- if (j < z)\r
- while (++j < z) /* try smaller tables up to z bits */\r
- {\r
- if ((f <<= 1) <= *++xp)\r
- break; /* enough codes to use up j bits */\r
- f -= *xp; /* else deduct codes from patterns */\r
- }\r
- }\r
- z = 1 << j; /* table entries for j-bit table */\r
-\r
- /* allocate new table */\r
- if (*hn + z > MANY) /* (note: doesn't matter for fixed) */\r
- return Z_MEM_ERROR; /* not enough memory */\r
- u[h] = q = hp + *hn;\r
- *hn += z;\r
-\r
- /* connect to last table, if there is one */\r
- if (h)\r
- {\r
- x[h] = i; /* save pattern for backing up */\r
- r.bits = (Byte)l; /* bits to dump before this table */\r
- r.exop = (Byte)j; /* bits in this table */\r
- j = i >> (w - l);\r
- r.base = (uInt)(q - u[h-1] - j); /* offset to this table */\r
- u[h-1][j] = r; /* connect to last table */\r
- }\r
- else\r
- *t = q; /* first table is returned result */\r
- }\r
-\r
- /* set up table entry in r */\r
- r.bits = (Byte)(k - w);\r
- if (p >= v + n)\r
- r.exop = 128 + 64; /* out of values--invalid code */\r
- else if (*p < s)\r
- {\r
- r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */\r
- r.base = *p++; /* simple code is just the value */\r
- }\r
- else\r
- {\r
- r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */\r
- r.base = d[*p++ - s];\r
- }\r
-\r
- /* fill code-like entries with r */\r
- f = 1 << (k - w);\r
- for (j = i >> w; j < z; j += f)\r
- q[j] = r;\r
-\r
- /* backwards increment the k-bit code i */\r
- for (j = 1 << (k - 1); i & j; j >>= 1)\r
- i ^= j;\r
- i ^= j;\r
-\r
- /* backup over finished tables */\r
- mask = (1 << w) - 1; /* needed on HP, cc -O bug */\r
- while ((i & mask) != x[h])\r
- {\r
- h--; /* don't need to update q */\r
- w -= l;\r
- mask = (1 << w) - 1;\r
- }\r
- }\r
- }\r
-\r
-\r
- /* Return Z_BUF_ERROR if we were given an incomplete table */\r
- return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;\r
-}\r
-\r
-\r
-int inflate_trees_bits(uInt *c, uInt *bb, inflate_huft * *tb, inflate_huft *hp, z_streamp z)\r
-//uInt *c; /* 19 code lengths */\r
-//uInt *bb; /* bits tree desired/actual depth */\r
-//inflate_huft * *tb; /* bits tree result */\r
-//inflate_huft *hp; /* space for trees */\r
-//z_streamp z; /* for messages */\r
-{\r
- int r;\r
- uInt hn = 0; /* hufts used in space */\r
- uInt *v; /* work area for huft_build */\r
-\r
- if ((v = (uInt*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)\r
- return Z_MEM_ERROR;\r
- r = huft_build(c, 19, 19, (uInt*)Z_NULL, (uInt*)Z_NULL,\r
- tb, bb, hp, &hn, v);\r
- if (r == Z_DATA_ERROR)\r
- z->msg = (char*)"oversubscribed dynamic bit lengths tree";\r
- else if (r == Z_BUF_ERROR || *bb == 0)\r
- {\r
- z->msg = (char*)"incomplete dynamic bit lengths tree";\r
- r = Z_DATA_ERROR;\r
- }\r
- ZFREE(z, v);\r
- return r;\r
-}\r
-\r
-\r
-int inflate_trees_dynamic(uInt nl, uInt nd, uInt *c, uInt *bl, uInt *bd, inflate_huft * *tl, inflate_huft * *td, inflate_huft *hp, z_streamp z)\r
-//uInt nl; /* number of literal/length codes */\r
-//uInt nd; /* number of distance codes */\r
-//uInt *c; /* that many (total) code lengths */\r
-//uInt *bl; /* literal desired/actual bit depth */\r
-//uInt *bd; /* distance desired/actual bit depth */\r
-//inflate_huft * *tl; /* literal/length tree result */\r
-//inflate_huft * *td; /* distance tree result */\r
-//inflate_huft *hp; /* space for trees */\r
-//z_streamp z; /* for messages */\r
-{\r
- int r;\r
- uInt hn = 0; /* hufts used in space */\r
- uInt *v; /* work area for huft_build */\r
-\r
- /* allocate work area */\r
- if ((v = (uInt*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)\r
- return Z_MEM_ERROR;\r
-\r
- /* build literal/length tree */\r
- r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);\r
- if (r != Z_OK || *bl == 0)\r
- {\r
- if (r == Z_DATA_ERROR)\r
- z->msg = (char*)"oversubscribed literal/length tree";\r
- else if (r != Z_MEM_ERROR)\r
- {\r
- z->msg = (char*)"incomplete literal/length tree";\r
- r = Z_DATA_ERROR;\r
- }\r
- ZFREE(z, v);\r
- return r;\r
- }\r
-\r
- /* build distance tree */\r
- r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);\r
- if (r != Z_OK || (*bd == 0 && nl > 257))\r
- {\r
- if (r == Z_DATA_ERROR)\r
- z->msg = (char*)"oversubscribed distance tree";\r
- else if (r == Z_BUF_ERROR) {\r
-#ifdef PKZIP_BUG_WORKAROUND\r
- r = Z_OK;\r
- }\r
-#else\r
- z->msg = (char*)"incomplete distance tree";\r
- r = Z_DATA_ERROR;\r
- }\r
- else if (r != Z_MEM_ERROR)\r
- {\r
- z->msg = (char*)"empty distance tree with lengths";\r
- r = Z_DATA_ERROR;\r
- }\r
- ZFREE(z, v);\r
- return r;\r
-#endif\r
- }\r
-\r
- /* done */\r
- ZFREE(z, v);\r
- return Z_OK;\r
-}\r
-\r
-/* inffixed.h -- table for decoding fixed codes\r
- * Generated automatically by the maketree.c program\r
- */\r
-\r
-/* WARNING: this file should *not* be used by applications. It is\r
- part of the implementation of the compression library and is\r
- subject to change. Applications should only use zlib.h.\r
- */\r
-\r
-static uInt fixed_bl = 9;\r
-static uInt fixed_bd = 5;\r
-static inflate_huft fixed_tl[] = {\r
- {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},\r
- {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},\r
- {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},\r
- {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},\r
- {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},\r
- {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},\r
- {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},\r
- {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},\r
- {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},\r
- {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},\r
- {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},\r
- {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},\r
- {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},\r
- {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},\r
- {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},\r
- {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},\r
- {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},\r
- {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},\r
- {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},\r
- {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},\r
- {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},\r
- {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},\r
- {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},\r
- {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},\r
- {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},\r
- {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},\r
- {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},\r
- {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},\r
- {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},\r
- {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},\r
- {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},\r
- {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},\r
- {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},\r
- {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},\r
- {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},\r
- {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},\r
- {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},\r
- {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},\r
- {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},\r
- {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},\r
- {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},\r
- {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},\r
- {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},\r
- {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},\r
- {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},\r
- {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},\r
- {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},\r
- {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},\r
- {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},\r
- {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},\r
- {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},\r
- {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},\r
- {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},\r
- {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},\r
- {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},\r
- {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},\r
- {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},\r
- {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},\r
- {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},\r
- {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},\r
- {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},\r
- {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},\r
- {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},\r
- {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},\r
- {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},\r
- {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},\r
- {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},\r
- {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},\r
- {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},\r
- {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},\r
- {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},\r
- {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},\r
- {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},\r
- {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},\r
- {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},\r
- {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},\r
- {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},\r
- {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},\r
- {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},\r
- {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},\r
- {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},\r
- {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},\r
- {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},\r
- {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},\r
- {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},\r
- {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},\r
- {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},\r
- {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},\r
- {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},\r
- {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},\r
- {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},\r
- {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},\r
- {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},\r
- {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},\r
- {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},\r
- {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},\r
- {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},\r
- {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},\r
- {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},\r
- {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},\r
- {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},\r
- {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},\r
- {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},\r
- {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},\r
- {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},\r
- {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},\r
- {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},\r
- {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},\r
- {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},\r
- {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},\r
- {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},\r
- {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},\r
- {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},\r
- {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},\r
- {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},\r
- {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},\r
- {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},\r
- {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},\r
- {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},\r
- {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},\r
- {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},\r
- {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},\r
- {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},\r
- {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},\r
- {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},\r
- {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},\r
- {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},\r
- {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}\r
- };\r
-static inflate_huft fixed_td[] = {\r
- {{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},\r
- {{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},\r
- {{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},\r
- {{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},\r
- {{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},\r
- {{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},\r
- {{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},\r
- {{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}\r
- };\r
-\r
-int inflate_trees_fixed(uInt *bl, uInt *bd, inflate_huft * *tl, inflate_huft * *td, z_streamp z)\r
-//uInt *bl; /* literal desired/actual bit depth */\r
-//uInt *bd; /* distance desired/actual bit depth */\r
-//inflate_huft * *tl; /* literal/length tree result */\r
-//inflate_huft * *td; /* distance tree result */\r
-//z_streamp z; /* for memory allocation */\r
-{\r
- *bl = fixed_bl;\r
- *bd = fixed_bd;\r
- *tl = fixed_tl;\r
- *td = fixed_td;\r
- return Z_OK;\r
-}\r
-\r
-/* simplify the use of the inflate_huft type with some defines */\r
-#define exop word.what.Exop\r
-#define bits word.what.Bits\r
-\r
-/* macros for bit input with no checking and for returning unused bytes */\r
-#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}\r
-#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}\r
-\r
-/* Called with number of bytes left to write in window at least 258\r
- (the maximum string length) and number of input bytes available\r
- at least ten. The ten bytes are six bytes for the longest length/\r
- distance pair plus four bytes for overloading the bit buffer. */\r
-\r
-int inflate_fast(uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, inflate_blocks_statef *s, z_streamp z)\r
-{\r
- inflate_huft *t; /* temporary pointer */\r
- uInt e; /* extra bits or operation */\r
- uLong b; /* bit buffer */\r
- uInt k; /* bits in bit buffer */\r
- Byte *p; /* input data pointer */\r
- uInt n; /* bytes available there */\r
- Byte *q; /* output window write pointer */\r
- uInt m; /* bytes to end of window or read pointer */\r
- uInt ml; /* mask for literal/length tree */\r
- uInt md; /* mask for distance tree */\r
- uInt c; /* bytes to copy */\r
- uInt d; /* distance back to copy from */\r
- Byte *r; /* copy source pointer */\r
-\r
- /* load input, output, bit values */\r
- LOAD\r
-\r
- /* initialize masks */\r
- ml = inflate_mask[bl];\r
- md = inflate_mask[bd];\r
-\r
- /* do until not enough input or output space for fast loop */\r
- do { /* assume called with m >= 258 && n >= 10 */\r
- /* get literal/length code */\r
- GRABBITS(20) /* max bits for literal/length code */\r
- if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)\r
- {\r
- DUMPBITS(t->bits)\r
- Tracevv((t->base >= 0x20 && t->base < 0x7f ?\r
- "inflate: * literal '%c'\n" :\r
- "inflate: * literal 0x%02x\n", t->base));\r
- *q++ = (Byte)t->base;\r
- m--;\r
- continue;\r
- }\r
- do {\r
- DUMPBITS(t->bits)\r
- if (e & 16)\r
- {\r
- /* get extra bits for length */\r
- e &= 15;\r
- c = t->base + ((uInt)b & inflate_mask[e]);\r
- DUMPBITS(e)\r
- Tracevv(("inflate: * length %u\n", c));\r
-\r
- /* decode distance base of block to copy */\r
- GRABBITS(15); /* max bits for distance code */\r
- e = (t = td + ((uInt)b & md))->exop;\r
- do {\r
- DUMPBITS(t->bits)\r
- if (e & 16)\r
- {\r
- /* get extra bits to add to distance base */\r
- e &= 15;\r
- GRABBITS(e) /* get extra bits (up to 13) */\r
- d = t->base + ((uInt)b & inflate_mask[e]);\r
- DUMPBITS(e)\r
- Tracevv(("inflate: * distance %u\n", d));\r
-\r
- /* do the copy */\r
- m -= c;\r
- if ((uInt)(q - s->window) >= d) /* offset before dest */\r
- { /* just copy */\r
- r = q - d;\r
- *q++ = *r++; c--; /* minimum count is three, */\r
- *q++ = *r++; c--; /* so unroll loop a little */\r
- }\r
- else /* else offset after destination */\r
- {\r
- e = d - (uInt)(q - s->window); /* bytes from offset to end */\r
- r = s->end - e; /* pointer to offset */\r
- if (c > e) /* if source crosses, */\r
- {\r
- c -= e; /* copy to end of window */\r
- do {\r
- *q++ = *r++;\r
- } while (--e);\r
- r = s->window; /* copy rest from start of window */\r
- }\r
- }\r
- do { /* copy all or what's left */\r
- *q++ = *r++;\r
- } while (--c);\r
- break;\r
- }\r
- else if ((e & 64) == 0)\r
- {\r
- t += t->base;\r
- e = (t += ((uInt)b & inflate_mask[e]))->exop;\r
- }\r
- else\r
- {\r
- z->msg = (char*)"invalid distance code";\r
- UNGRAB\r
- UPDATE\r
- return Z_DATA_ERROR;\r
- }\r
- } while (1);\r
- break;\r
- }\r
- if ((e & 64) == 0)\r
- {\r
- t += t->base;\r
- if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)\r
- {\r
- DUMPBITS(t->bits)\r
- Tracevv((t->base >= 0x20 && t->base < 0x7f ?\r
- "inflate: * literal '%c'\n" :\r
- "inflate: * literal 0x%02x\n", t->base));\r
- *q++ = (Byte)t->base;\r
- m--;\r
- break;\r
- }\r
- }\r
- else if (e & 32)\r
- {\r
- Tracevv(("inflate: * end of block\n"));\r
- UNGRAB\r
- UPDATE\r
- return Z_STREAM_END;\r
- }\r
- else\r
- {\r
- z->msg = (char*)"invalid literal/length code";\r
- UNGRAB\r
- UPDATE\r
- return Z_DATA_ERROR;\r
- }\r
- } while (1);\r
- } while (m >= 258 && n >= 10);\r
-\r
- /* not enough input or output--restore pointers and return */\r
- UNGRAB\r
- UPDATE\r
- return Z_OK;\r
-}\r
-\r
-/* infcodes.c -- process literals and length/distance pairs\r
- * Copyright (C) 1995-1998 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-/* simplify the use of the inflate_huft type with some defines */\r
-#define exop word.what.Exop\r
-#define bits word.what.Bits\r
-\r
-typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */\r
- START, /* x: set up for LEN */\r
- LEN, /* i: get length/literal/eob next */\r
- LENEXT, /* i: getting length extra (have base) */\r
- DIST, /* i: get distance next */\r
- DISTEXT, /* i: getting distance extra */\r
- COPY, /* o: copying bytes in window, waiting for space */\r
- LIT, /* o: got literal, waiting for output space */\r
- WASH, /* o: got eob, possibly still output waiting */\r
- END, /* x: got eob and all data flushed */\r
- BADCODE} /* x: got error */\r
-inflate_codes_mode;\r
-\r
-/* inflate codes private state */\r
-struct inflate_codes_state {\r
-\r
- /* mode */\r
- inflate_codes_mode mode; /* current inflate_codes mode */\r
-\r
- /* mode dependent information */\r
- uInt len;\r
- union {\r
- struct {\r
- inflate_huft *tree; /* pointer into tree */\r
- uInt need; /* bits needed */\r
- } code; /* if LEN or DIST, where in tree */\r
- uInt lit; /* if LIT, literal */\r
- struct {\r
- uInt get; /* bits to get for extra */\r
- uInt dist; /* distance back to copy from */\r
- } copy; /* if EXT or COPY, where and how much */\r
- } sub; /* submode */\r
-\r
- /* mode independent information */\r
- Byte lbits; /* ltree bits decoded per branch */\r
- Byte dbits; /* dtree bits decoder per branch */\r
- inflate_huft *ltree; /* literal/length/eob tree */\r
- inflate_huft *dtree; /* distance tree */\r
-\r
-};\r
-\r
-\r
-inflate_codes_statef *inflate_codes_new(uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, z_streamp z)\r
-{\r
- inflate_codes_statef *c;\r
-\r
- if ((c = (inflate_codes_statef *)\r
- ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)\r
- {\r
- c->mode = START;\r
- c->lbits = (Byte)bl;\r
- c->dbits = (Byte)bd;\r
- c->ltree = tl;\r
- c->dtree = td;\r
- Tracev(("inflate: codes new\n"));\r
- }\r
- return c;\r
-}\r
-\r
-\r
-int inflate_codes(inflate_blocks_statef *s, z_streamp z, int r)\r
-{\r
- uInt j; /* temporary storage */\r
- inflate_huft *t; /* temporary pointer */\r
- uInt e; /* extra bits or operation */\r
- uLong b; /* bit buffer */\r
- uInt k; /* bits in bit buffer */\r
- Byte *p; /* input data pointer */\r
- uInt n; /* bytes available there */\r
- Byte *q; /* output window write pointer */\r
- uInt m; /* bytes to end of window or read pointer */\r
- Byte *f; /* pointer to copy strings from */\r
- inflate_codes_statef *c = s->sub.decode.codes; /* codes state */\r
-\r
- /* copy input/output information to locals (UPDATE macro restores) */\r
- LOAD\r
-\r
- /* process input and output based on current state */\r
- while (1) switch (c->mode)\r
- { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */\r
- case START: /* x: set up for LEN */\r
-#ifndef SLOW\r
- if (m >= 258 && n >= 10)\r
- {\r
- UPDATE\r
- r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);\r
- LOAD\r
- if (r != Z_OK)\r
- {\r
- c->mode = r == Z_STREAM_END ? WASH : BADCODE;\r
- break;\r
- }\r
- }\r
-#endif /* !SLOW */\r
- c->sub.code.need = c->lbits;\r
- c->sub.code.tree = c->ltree;\r
- c->mode = LEN;\r
- case LEN: /* i: get length/literal/eob next */\r
- j = c->sub.code.need;\r
- NEEDBITS(j)\r
- t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);\r
- DUMPBITS(t->bits)\r
- e = (uInt)(t->exop);\r
- if (e == 0) /* literal */\r
- {\r
- c->sub.lit = t->base;\r
- Tracevv((t->base >= 0x20 && t->base < 0x7f ?\r
- "inflate: literal '%c'\n" :\r
- "inflate: literal 0x%02x\n", t->base));\r
- c->mode = LIT;\r
- break;\r
- }\r
- if (e & 16) /* length */\r
- {\r
- c->sub.copy.get = e & 15;\r
- c->len = t->base;\r
- c->mode = LENEXT;\r
- break;\r
- }\r
- if ((e & 64) == 0) /* next table */\r
- {\r
- c->sub.code.need = e;\r
- c->sub.code.tree = t + t->base;\r
- break;\r
- }\r
- if (e & 32) /* end of block */\r
- {\r
- Tracevv(("inflate: end of block\n"));\r
- c->mode = WASH;\r
- break;\r
- }\r
- c->mode = BADCODE; /* invalid code */\r
- z->msg = (char*)"invalid literal/length code";\r
- r = Z_DATA_ERROR;\r
- LEAVE\r
- case LENEXT: /* i: getting length extra (have base) */\r
- j = c->sub.copy.get;\r
- NEEDBITS(j)\r
- c->len += (uInt)b & inflate_mask[j];\r
- DUMPBITS(j)\r
- c->sub.code.need = c->dbits;\r
- c->sub.code.tree = c->dtree;\r
- Tracevv(("inflate: length %u\n", c->len));\r
- c->mode = DIST;\r
- case DIST: /* i: get distance next */\r
- j = c->sub.code.need;\r
- NEEDBITS(j)\r
- t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);\r
- DUMPBITS(t->bits)\r
- e = (uInt)(t->exop);\r
- if (e & 16) /* distance */\r
- {\r
- c->sub.copy.get = e & 15;\r
- c->sub.copy.dist = t->base;\r
- c->mode = DISTEXT;\r
- break;\r
- }\r
- if ((e & 64) == 0) /* next table */\r
- {\r
- c->sub.code.need = e;\r
- c->sub.code.tree = t + t->base;\r
- break;\r
- }\r
- c->mode = BADCODE; /* invalid code */\r
- z->msg = (char*)"invalid distance code";\r
- r = Z_DATA_ERROR;\r
- LEAVE\r
- case DISTEXT: /* i: getting distance extra */\r
- j = c->sub.copy.get;\r
- NEEDBITS(j)\r
- c->sub.copy.dist += (uInt)b & inflate_mask[j];\r
- DUMPBITS(j)\r
- Tracevv(("inflate: distance %u\n", c->sub.copy.dist));\r
- c->mode = COPY;\r
- case COPY: /* o: copying bytes in window, waiting for space */\r
-#ifndef __TURBOC__ /* Turbo C bug for following expression */\r
- f = (uInt)(q - s->window) < c->sub.copy.dist ?\r
- s->end - (c->sub.copy.dist - (q - s->window)) :\r
- q - c->sub.copy.dist;\r
-#else\r
- f = q - c->sub.copy.dist;\r
- if ((uInt)(q - s->window) < c->sub.copy.dist)\r
- f = s->end - (c->sub.copy.dist - (uInt)(q - s->window));\r
-#endif\r
- while (c->len)\r
- {\r
- NEEDOUT\r
- OUTBYTE(*f++)\r
- if (f == s->end)\r
- f = s->window;\r
- c->len--;\r
- }\r
- c->mode = START;\r
- break;\r
- case LIT: /* o: got literal, waiting for output space */\r
- NEEDOUT\r
- OUTBYTE(c->sub.lit)\r
- c->mode = START;\r
- break;\r
- case WASH: /* o: got eob, possibly more output */\r
- if (k > 7) /* return unused byte, if any */\r
- {\r
- Assert(k < 16, "inflate_codes grabbed too many bytes")\r
- k -= 8;\r
- n++;\r
- p--; /* can always return one */\r
- }\r
- FLUSH\r
- if (s->read != s->write)\r
- LEAVE\r
- c->mode = END;\r
- case END:\r
- r = Z_STREAM_END;\r
- LEAVE\r
- case BADCODE: /* x: got error */\r
- r = Z_DATA_ERROR;\r
- LEAVE\r
- default:\r
- r = Z_STREAM_ERROR;\r
- LEAVE\r
- }\r
-#ifdef NEED_DUMMY_RETURN\r
- return Z_STREAM_ERROR; /* Some dumb compilers complain without this */\r
-#endif\r
-}\r
-\r
-\r
-void inflate_codes_free(inflate_codes_statef *c, z_streamp z)\r
-{\r
- ZFREE(z, c);\r
- Tracev(("inflate: codes free\n"));\r
-}\r
-\r
-/* adler32.c -- compute the Adler-32 checksum of a data stream\r
- * Copyright (C) 1995-1998 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-#define BASE 65521L /* largest prime smaller than 65536 */\r
-#define NMAX 5552\r
-/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */\r
-\r
-#undef DO1\r
-#undef DO2\r
-#undef DO4\r
-#undef DO8\r
-\r
-#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}\r
-#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);\r
-#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);\r
-#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);\r
-#define DO16(buf) DO8(buf,0); DO8(buf,8);\r
-\r
-/* ========================================================================= */\r
-uLong adler32(uLong adler, const Byte *buf, uInt len)\r
-{\r
- unsigned long s1 = adler & 0xffff;\r
- unsigned long s2 = (adler >> 16) & 0xffff;\r
- int k;\r
-\r
- if (buf == Z_NULL) return 1L;\r
-\r
- while (len > 0) {\r
- k = len < NMAX ? len : NMAX;\r
- len -= k;\r
- while (k >= 16) {\r
- DO16(buf);\r
- buf += 16;\r
- k -= 16;\r
- }\r
- if (k != 0) do {\r
- s1 += *buf++;\r
- s2 += s1;\r
- } while (--k);\r
- s1 %= BASE;\r
- s2 %= BASE;\r
- }\r
- return (s2 << 16) | s1;\r
-}\r
-\r
-/* infblock.h -- header to use infblock.c\r
- * Copyright (C) 1995-1998 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- */\r
-\r
-/* WARNING: this file should *not* be used by applications. It is\r
- part of the implementation of the compression library and is\r
- subject to change. Applications should only use zlib.h.\r
- */\r
-\r
-extern inflate_blocks_statef * inflate_blocks_new OF((\r
- z_streamp z,\r
- check_func c, /* check function */\r
- uInt w)); /* window size */\r
-\r
-extern int inflate_blocks OF((\r
- inflate_blocks_statef *,\r
- z_streamp ,\r
- int)); /* initial return code */\r
-\r
-extern void inflate_blocks_reset OF((\r
- inflate_blocks_statef *,\r
- z_streamp ,\r
- uLong *)); /* check value on output */\r
-\r
-extern int inflate_blocks_free OF((\r
- inflate_blocks_statef *,\r
- z_streamp));\r
-\r
-extern void inflate_set_dictionary OF((\r
- inflate_blocks_statef *s,\r
- const Byte *d, /* dictionary */\r
- uInt n)); /* dictionary length */\r
-\r
-extern int inflate_blocks_sync_point OF((\r
- inflate_blocks_statef *s));\r
-\r
-typedef enum {\r
- imMETHOD, /* waiting for method byte */\r
- imFLAG, /* waiting for flag byte */\r
- imDICT4, /* four dictionary check bytes to go */\r
- imDICT3, /* three dictionary check bytes to go */\r
- imDICT2, /* two dictionary check bytes to go */\r
- imDICT1, /* one dictionary check byte to go */\r
- imDICT0, /* waiting for inflateSetDictionary */\r
- imBLOCKS, /* decompressing blocks */\r
- imCHECK4, /* four check bytes to go */\r
- imCHECK3, /* three check bytes to go */\r
- imCHECK2, /* two check bytes to go */\r
- imCHECK1, /* one check byte to go */\r
- imDONE, /* finished check, done */\r
- imBAD} /* got an error--stay here */\r
-inflate_mode;\r
-\r
-/* inflate private state */\r
-struct internal_state {\r
-\r
- /* mode */\r
- inflate_mode mode; /* current inflate mode */\r
-\r
- /* mode dependent information */\r
- union {\r
- uInt method; /* if FLAGS, method byte */\r
- struct {\r
- uLong was; /* computed check value */\r
- uLong need; /* stream check value */\r
- } check; /* if CHECK, check values to compare */\r
- uInt marker; /* if BAD, inflateSync's marker bytes count */\r
- } sub; /* submode */\r
-\r
- /* mode independent information */\r
- int nowrap; /* flag for no wrapper */\r
- uInt wbits; /* log2(window size) (8..15, defaults to 15) */\r
- inflate_blocks_statef \r
- *blocks; /* current inflate_blocks state */\r
-\r
-};\r
-\r
-\r
-int inflateReset(z_streamp z)\r
-{\r
- if (z == Z_NULL || z->state == Z_NULL)\r
- return Z_STREAM_ERROR;\r
- z->total_in = z->total_out = 0;\r
- z->msg = Z_NULL;\r
- z->state->mode = z->state->nowrap ? imBLOCKS : imMETHOD;\r
- inflate_blocks_reset(z->state->blocks, z, Z_NULL);\r
- Tracev(("inflate: reset\n"));\r
- return Z_OK;\r
-}\r
-\r
-\r
-int inflateEnd(z_streamp z)\r
-{\r
- if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)\r
- return Z_STREAM_ERROR;\r
- if (z->state->blocks != Z_NULL)\r
- inflate_blocks_free(z->state->blocks, z);\r
- ZFREE(z, z->state);\r
- z->state = Z_NULL;\r
- Tracev(("inflate: end\n"));\r
- return Z_OK;\r
-}\r
-\r
-\r
-\r
-int inflateInit2_(z_streamp z, int w, const char *version, int stream_size)\r
-{\r
- if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||\r
- stream_size != sizeof(z_stream))\r
- return Z_VERSION_ERROR;\r
-\r
- /* initialize state */\r
- if (z == Z_NULL)\r
- return Z_STREAM_ERROR;\r
- z->msg = Z_NULL;\r
- if (z->zalloc == Z_NULL)\r
- {\r
- z->zalloc = (void *(*)(void *, unsigned, unsigned))zcalloc;\r
- z->opaque = (voidp)0;\r
- }\r
- if (z->zfree == Z_NULL) z->zfree = (void (*)(void *, void *))zcfree;\r
- if ((z->state = (struct internal_state *)\r
- ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)\r
- return Z_MEM_ERROR;\r
- z->state->blocks = Z_NULL;\r
-\r
- /* handle undocumented nowrap option (no zlib header or check) */\r
- z->state->nowrap = 0;\r
- if (w < 0)\r
- {\r
- w = - w;\r
- z->state->nowrap = 1;\r
- }\r
-\r
- /* set window size */\r
- if (w < 8 || w > 15)\r
- {\r
- inflateEnd(z);\r
- return Z_STREAM_ERROR;\r
- }\r
- z->state->wbits = (uInt)w;\r
-\r
- /* create inflate_blocks state */\r
- if ((z->state->blocks =\r
- inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))\r
- == Z_NULL)\r
- {\r
- inflateEnd(z);\r
- return Z_MEM_ERROR;\r
- }\r
- Tracev(("inflate: allocated\n"));\r
-\r
- /* reset state */\r
- inflateReset(z);\r
- return Z_OK;\r
-}\r
-\r
-\r
-int inflateInit_(z_streamp z, const char *version, int stream_size)\r
-{\r
- return inflateInit2_(z, DEF_WBITS, version, stream_size);\r
-}\r
-\r
-\r
-#define iNEEDBYTE {if(z->avail_in==0)return r;r=f;}\r
-#define iNEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)\r
-\r
-int inflate(z_streamp z, int f)\r
-{\r
- int r;\r
- uInt b;\r
-\r
- if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)\r
- return Z_STREAM_ERROR;\r
- f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;\r
- r = Z_BUF_ERROR;\r
- while (1) switch (z->state->mode)\r
- {\r
- case imMETHOD:\r
- iNEEDBYTE\r
- if (((z->state->sub.method = iNEXTBYTE) & 0xf) != Z_DEFLATED)\r
- {\r
- z->state->mode = imBAD;\r
- z->msg = (char*)"unknown compression method";\r
- z->state->sub.marker = 5; /* can't try inflateSync */\r
- break;\r
- }\r
- if ((z->state->sub.method >> 4) + 8 > z->state->wbits)\r
- {\r
- z->state->mode = imBAD;\r
- z->msg = (char*)"invalid window size";\r
- z->state->sub.marker = 5; /* can't try inflateSync */\r
- break;\r
- }\r
- z->state->mode = imFLAG;\r
- case imFLAG:\r
- iNEEDBYTE\r
- b = iNEXTBYTE;\r
- if (((z->state->sub.method << 8) + b) % 31)\r
- {\r
- z->state->mode = imBAD;\r
- z->msg = (char*)"incorrect header check";\r
- z->state->sub.marker = 5; /* can't try inflateSync */\r
- break;\r
- }\r
- Tracev(("inflate: zlib header ok\n"));\r
- if (!(b & PRESET_DICT))\r
- {\r
- z->state->mode = imBLOCKS;\r
- break;\r
- }\r
- z->state->mode = imDICT4;\r
- case imDICT4:\r
- iNEEDBYTE\r
- z->state->sub.check.need = (uLong)iNEXTBYTE << 24;\r
- z->state->mode = imDICT3;\r
- case imDICT3:\r
- iNEEDBYTE\r
- z->state->sub.check.need += (uLong)iNEXTBYTE << 16;\r
- z->state->mode = imDICT2;\r
- case imDICT2:\r
- iNEEDBYTE\r
- z->state->sub.check.need += (uLong)iNEXTBYTE << 8;\r
- z->state->mode = imDICT1;\r
- case imDICT1:\r
- iNEEDBYTE\r
- z->state->sub.check.need += (uLong)iNEXTBYTE;\r
- z->adler = z->state->sub.check.need;\r
- z->state->mode = imDICT0;\r
- return Z_NEED_DICT;\r
- case imDICT0:\r
- z->state->mode = imBAD;\r
- z->msg = (char*)"need dictionary";\r
- z->state->sub.marker = 0; /* can try inflateSync */\r
- return Z_STREAM_ERROR;\r
- case imBLOCKS:\r
- r = inflate_blocks(z->state->blocks, z, r);\r
- if (r == Z_DATA_ERROR)\r
- {\r
- z->state->mode = imBAD;\r
- z->state->sub.marker = 0; /* can try inflateSync */\r
- break;\r
- }\r
- if (r == Z_OK)\r
- r = f;\r
- if (r != Z_STREAM_END)\r
- return r;\r
- r = f;\r
- inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);\r
- if (z->state->nowrap)\r
- {\r
- z->state->mode = imDONE;\r
- break;\r
- }\r
- z->state->mode = imCHECK4;\r
- case imCHECK4:\r
- iNEEDBYTE\r
- z->state->sub.check.need = (uLong)iNEXTBYTE << 24;\r
- z->state->mode = imCHECK3;\r
- case imCHECK3:\r
- iNEEDBYTE\r
- z->state->sub.check.need += (uLong)iNEXTBYTE << 16;\r
- z->state->mode = imCHECK2;\r
- case imCHECK2:\r
- iNEEDBYTE\r
- z->state->sub.check.need += (uLong)iNEXTBYTE << 8;\r
- z->state->mode = imCHECK1;\r
- case imCHECK1:\r
- iNEEDBYTE\r
- z->state->sub.check.need += (uLong)iNEXTBYTE;\r
-\r
- if (z->state->sub.check.was != z->state->sub.check.need)\r
- {\r
- z->state->mode = imBAD;\r
- z->msg = (char*)"incorrect data check";\r
- z->state->sub.marker = 5; /* can't try inflateSync */\r
- break;\r
- }\r
- Tracev(("inflate: zlib check ok\n"));\r
- z->state->mode = imDONE;\r
- case imDONE:\r
- return Z_STREAM_END;\r
- case imBAD:\r
- return Z_DATA_ERROR;\r
- default:\r
- return Z_STREAM_ERROR;\r
- }\r
-#ifdef NEED_DUMMY_RETURN\r
- return Z_STREAM_ERROR; /* Some dumb compilers complain without this */\r
-#endif\r
-}\r
-\r
-\r
-int inflateSetDictionary(z_streamp z, const Byte *dictionary, uInt dictLength)\r
-{\r
- uInt length = dictLength;\r
-\r
- if (z == Z_NULL || z->state == Z_NULL || z->state->mode != imDICT0)\r
- return Z_STREAM_ERROR;\r
-\r
- if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;\r
- z->adler = 1L;\r
-\r
- if (length >= ((uInt)1<<z->state->wbits))\r
- {\r
- length = (1<<z->state->wbits)-1;\r
- dictionary += dictLength - length;\r
- }\r
- inflate_set_dictionary(z->state->blocks, dictionary, length);\r
- z->state->mode = imBLOCKS;\r
- return Z_OK;\r
-}\r
-\r
-\r
-int inflateSync(z_streamp z)\r
-{\r
- uInt n; /* number of bytes to look at */\r
- Byte *p; /* pointer to bytes */\r
- uInt m; /* number of marker bytes found in a row */\r
- uLong r, w; /* temporaries to save total_in and total_out */\r
-\r
- /* set up */\r
- if (z == Z_NULL || z->state == Z_NULL)\r
- return Z_STREAM_ERROR;\r
- if (z->state->mode != imBAD)\r
- {\r
- z->state->mode = imBAD;\r
- z->state->sub.marker = 0;\r
- }\r
- if ((n = z->avail_in) == 0)\r
- return Z_BUF_ERROR;\r
- p = z->next_in;\r
- m = z->state->sub.marker;\r
-\r
- /* search */\r
- while (n && m < 4)\r
- {\r
- static const Byte mark[4] = {0, 0, 0xff, 0xff};\r
- if (*p == mark[m])\r
- m++;\r
- else if (*p)\r
- m = 0;\r
- else\r
- m = 4 - m;\r
- p++, n--;\r
- }\r
-\r
- /* restore */\r
- z->total_in += p - z->next_in;\r
- z->next_in = p;\r
- z->avail_in = n;\r
- z->state->sub.marker = m;\r
-\r
- /* return no joy or set up to restart on a new block */\r
- if (m != 4)\r
- return Z_DATA_ERROR;\r
- r = z->total_in; w = z->total_out;\r
- inflateReset(z);\r
- z->total_in = r; z->total_out = w;\r
- z->state->mode = imBLOCKS;\r
- return Z_OK;\r
-}\r
-\r
-\r
-/* Returns true if inflate is currently at the end of a block generated\r
- * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP\r
- * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH\r
- * but removes the length bytes of the resulting empty stored block. When\r
- * decompressing, PPP checks that at the end of input packet, inflate is\r
- * waiting for these length bytes.\r
- */\r
-int inflateSyncPoint(z_streamp z)\r
-{\r
- if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)\r
- return Z_STREAM_ERROR;\r
- return inflate_blocks_sync_point(z->state->blocks);\r
-}\r
-\r
-voidp zcalloc (voidp opaque, unsigned items, unsigned size)\r
-{\r
- if (opaque) items += size - size; /* make compiler happy */\r
- return (voidp)malloc(items*size);\r
-}\r
-\r
-void zcfree (voidp opaque, voidp ptr)\r
-{\r
- free(ptr);\r
- if (opaque) return; /* make compiler happy */\r
-}\r
-\r
+/*****************************************************************************
+* name: unzip.c
+*
+* desc: IO on .zip files using portions of zlib
+*
+*
+*****************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "unzip.h"
+
+typedef unsigned char byte;
+
+/* unzip.h -- IO for uncompress .zip files using zlib
+ Version 0.15 beta, Mar 19th, 1998,
+
+ Copyright (C) 1998 Gilles Vollant
+
+ This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
+ WinZip, InfoZip tools and compatible.
+ Encryption and multi volume ZipFile (span) are not supported.
+ Old compressions used by old PKZip 1.x are not supported
+
+ THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
+ CAN CHANGE IN FUTURE VERSION !!
+ I WAIT FEEDBACK at mail info@winimage.com
+ Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
+
+ Condition of use and distribution are the same than zlib :
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+
+ */
+/* for more info about .ZIP format, see
+ ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
+ PkWare has also a specification at :
+ ftp://ftp.pkware.com/probdesc.zip */
+
+/* zlib.h -- interface of the 'zlib' general purpose compression library
+ version 1.1.3, July 9th, 1998
+
+ Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+
+ The data format used by the zlib library is described by RFCs (Request for
+ Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
+ (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
+ */
+
+/* zconf.h -- configuration of the zlib compression library
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#ifndef _ZCONF_H
+#define _ZCONF_H
+
+/* Maximum value for memLevel in deflateInit2 */
+#ifndef MAX_MEM_LEVEL
+# ifdef MAXSEG_64K
+# define MAX_MEM_LEVEL 8
+# else
+# define MAX_MEM_LEVEL 9
+# endif
+#endif
+
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
+ * created by gzip. (Files created by minigzip can still be extracted by
+ * gzip.)
+ */
+#ifndef MAX_WBITS
+# define MAX_WBITS 15 /* 32K LZ77 window */
+#endif
+
+/* The memory requirements for deflate are (in bytes):
+ (1 << (windowBits+2)) + (1 << (memLevel+9))
+ that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
+ plus a few kilobytes for small objects. For example, if you want to reduce
+ the default memory requirements from 256K to 128K, compile with
+ make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
+ Of course this will generally degrade compression (there's no free lunch).
+
+ The memory requirements for inflate are (in bytes) 1 << windowBits
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ for small objects.
+ */
+
+/* Type declarations */
+
+#ifndef OF /* function prototypes */
+#define OF( args ) args
+#endif
+
+typedef unsigned char Byte; /* 8 bits */
+typedef unsigned int uInt; /* 16 bits or more */
+typedef unsigned long uLong; /* 32 bits or more */
+typedef Byte *voidp;
+
+#ifndef SEEK_SET
+# define SEEK_SET 0 /* Seek from beginning of file. */
+# define SEEK_CUR 1 /* Seek from current position. */
+# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
+#endif
+
+#endif /* _ZCONF_H */
+
+#define ZLIB_VERSION "1.1.3"
+
+/*
+ The 'zlib' compression library provides in-memory compression and
+ decompression functions, including integrity checks of the uncompressed
+ data. This version of the library supports only one compression method
+ (deflation) but other algorithms will be added later and will have the same
+ stream interface.
+
+ Compression can be done in a single step if the buffers are large
+ enough (for example if an input file is mmap'ed), or can be done by
+ repeated calls of the compression function. In the latter case, the
+ application must provide more input and/or consume the output
+ (providing more output space) before each call.
+
+ The library also supports reading and writing files in gzip (.gz) format
+ with an interface similar to that of stdio.
+
+ The library does not install any signal handler. The decoder checks
+ the consistency of the compressed data, so the library should never
+ crash even in case of corrupted input.
+ */
+
+/*
+ The application must update next_in and avail_in when avail_in has
+ dropped to zero. It must update next_out and avail_out when avail_out
+ has dropped to zero. The application must initialize zalloc, zfree and
+ opaque before calling the init function. All other fields are set by the
+ compression library and must not be updated by the application.
+
+ The opaque value provided by the application will be passed as the first
+ parameter for calls of zalloc and zfree. This can be useful for custom
+ memory management. The compression library attaches no meaning to the
+ opaque value.
+
+ zalloc must return Z_NULL if there is not enough memory for the object.
+ If zlib is used in a multi-threaded application, zalloc and zfree must be
+ thread safe.
+
+ On 16-bit systems, the functions zalloc and zfree must be able to allocate
+ exactly 65536 bytes, but will not be required to allocate more than this
+ if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
+ pointers returned by zalloc for objects of exactly 65536 bytes *must*
+ have their offset normalized to zero. The default allocation function
+ provided by this library ensures this (see zutil.c). To reduce memory
+ requirements and avoid any allocation of 64K objects, at the expense of
+ compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
+
+ The fields total_in and total_out can be used for statistics or
+ progress reports. After compression, total_in holds the total size of
+ the uncompressed data and may be saved for use in the decompressor
+ (particularly if the decompressor wants to decompress everything in
+ a single step).
+ */
+
+/* constants */
+
+#define Z_NO_FLUSH 0
+#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
+#define Z_SYNC_FLUSH 2
+#define Z_FULL_FLUSH 3
+#define Z_FINISH 4
+/* Allowed flush values; see deflate() below for details */
+
+#define Z_OK 0
+#define Z_STREAM_END 1
+#define Z_NEED_DICT 2
+#define Z_ERRNO ( -1 )
+#define Z_STREAM_ERROR ( -2 )
+#define Z_DATA_ERROR ( -3 )
+#define Z_MEM_ERROR ( -4 )
+#define Z_BUF_ERROR ( -5 )
+#define Z_VERSION_ERROR ( -6 )
+/* Return codes for the compression/decompression functions. Negative
+ * values are errors, positive values are used for special but normal events.
+ */
+
+#define Z_NO_COMPRESSION 0
+#define Z_BEST_SPEED 1
+#define Z_BEST_COMPRESSION 9
+#define Z_DEFAULT_COMPRESSION ( -1 )
+/* compression levels */
+
+#define Z_FILTERED 1
+#define Z_HUFFMAN_ONLY 2
+#define Z_DEFAULT_STRATEGY 0
+/* compression strategy; see deflateInit2() below for details */
+
+#define Z_BINARY 0
+#define Z_ASCII 1
+#define Z_UNKNOWN 2
+/* Possible values of the data_type field */
+
+#define Z_DEFLATED 8
+/* The deflate compression method (the only one supported in this version) */
+
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
+
+#define zlib_version zlibVersion()
+/* for compatibility with versions < 1.0.2 */
+
+/* basic functions */
+
+const char * zlibVersion OF( (void) );
+/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
+ If the first character differs, the library code actually used is
+ not compatible with the zlib.h header file used by the application.
+ This check is automatically made by deflateInit and inflateInit.
+ */
+
+/*
+ int deflateInit OF((z_streamp strm, int level));
+
+ Initializes the internal stream state for compression. The fields
+ zalloc, zfree and opaque must be initialized before by the caller.
+ If zalloc and zfree are set to Z_NULL, deflateInit updates them to
+ use default allocation functions.
+
+ The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
+ 1 gives best speed, 9 gives best compression, 0 gives no compression at
+ all (the input data is simply copied a block at a time).
+ Z_DEFAULT_COMPRESSION requests a default compromise between speed and
+ compression (currently equivalent to level 6).
+
+ deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if level is not a valid compression level,
+ Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
+ with the version assumed by the caller (ZLIB_VERSION).
+ msg is set to null if there is no error message. deflateInit does not
+ perform any compression: this will be done by deflate().
+ */
+
+
+int deflate OF( ( z_streamp strm, int flush ) );
+/*
+ deflate compresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce some
+ output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. deflate performs one or both of the
+ following actions:
+
+ - Compress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in and avail_in are updated and
+ processing will resume at this point for the next call of deflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. This action is forced if the parameter flush is non zero.
+ Forcing flush frequently degrades the compression ratio, so this parameter
+ should be set only when necessary (in interactive applications).
+ Some output may be provided even if flush is not set.
+
+ Before the call of deflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming
+ more output, and updating avail_in or avail_out accordingly; avail_out
+ should never be zero before the call. The application can consume the
+ compressed output when it wants, for example when the output buffer is full
+ (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
+ and with zero avail_out, it must be called again after making room in the
+ output buffer because there might be more output pending.
+
+ If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
+ flushed to the output buffer and the output is aligned on a byte boundary, so
+ that the decompressor can get all input data available so far. (In particular
+ avail_in is zero after the call if enough output space has been provided
+ before the call.) Flushing may degrade compression for some compression
+ algorithms and so it should be used only when necessary.
+
+ If flush is set to Z_FULL_FLUSH, all output is flushed as with
+ Z_SYNC_FLUSH, and the compression state is reset so that decompression can
+ restart from this point if previous compressed data has been damaged or if
+ random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
+ the compression.
+
+ If deflate returns with avail_out == 0, this function must be called again
+ with the same value of the flush parameter and more output space (updated
+ avail_out), until the flush is complete (deflate returns with non-zero
+ avail_out).
+
+ If the parameter flush is set to Z_FINISH, pending input is processed,
+ pending output is flushed and deflate returns with Z_STREAM_END if there
+ was enough output space; if deflate returns with Z_OK, this function must be
+ called again with Z_FINISH and more output space (updated avail_out) but no
+ more input data, until it returns with Z_STREAM_END or an error. After
+ deflate has returned Z_STREAM_END, the only possible operations on the
+ stream are deflateReset or deflateEnd.
+
+ Z_FINISH can be used immediately after deflateInit if all the compression
+ is to be done in a single step. In this case, avail_out must be at least
+ 0.1% larger than avail_in plus 12 bytes. If deflate does not return
+ Z_STREAM_END, then it must be called again as described above.
+
+ deflate() sets strm->adler to the adler32 checksum of all input read
+ so (that is, total_in bytes).
+
+ deflate() may update data_type if it can make a good guess about
+ the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
+ binary. This field is only for information purposes and does not affect
+ the compression algorithm in any manner.
+
+ deflate() returns Z_OK if some progress has been made (more input
+ processed or more output produced), Z_STREAM_END if all input has been
+ consumed and all output has been produced (only when flush is set to
+ Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
+ if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
+ (for example avail_in or avail_out was zero).
+ */
+
+
+int deflateEnd OF( (z_streamp strm) );
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any
+ pending output.
+
+ deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
+ stream state was inconsistent, Z_DATA_ERROR if the stream was freed
+ prematurely (some input or output was discarded). In the error case,
+ msg may be set but then points to a static string (which must not be
+ deallocated).
+ */
+
+
+/*
+ int inflateInit OF((z_streamp strm));
+
+ Initializes the internal stream state for decompression. The fields
+ next_in, avail_in, zalloc, zfree and opaque must be initialized before by
+ the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
+ value depends on the compression method), inflateInit determines the
+ compression method from the zlib header and allocates all data structures
+ accordingly; otherwise the allocation will be deferred to the first call of
+ inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
+ use default allocation functions.
+
+ inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
+ version assumed by the caller. msg is set to null if there is no error
+ message. inflateInit does not perform any decompression apart from reading
+ the zlib header if present: this will be done by inflate(). (So next_in and
+ avail_in may be modified, but next_out and avail_out are unchanged.)
+ */
+
+
+int inflate OF( ( z_streamp strm, int flush ) );
+/*
+ inflate decompresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may some
+ introduce some output latency (reading input without producing any output)
+ except when forced to flush.
+
+ The detailed semantics are as follows. inflate performs one or both of the
+ following actions:
+
+ - Decompress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in is updated and processing
+ will resume at this point for the next call of inflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. inflate() provides as much output as possible, until there
+ is no more input data or no more space in the output buffer (see below
+ about the flush parameter).
+
+ Before the call of inflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming
+ more output, and updating the next_* and avail_* values accordingly.
+ The application can consume the uncompressed output when it wants, for
+ example when the output buffer is full (avail_out == 0), or after each
+ call of inflate(). If inflate returns Z_OK and with zero avail_out, it
+ must be called again after making room in the output buffer because there
+ might be more output pending.
+
+ If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
+ output as possible to the output buffer. The flushing behavior of inflate is
+ not specified for values of the flush parameter other than Z_SYNC_FLUSH
+ and Z_FINISH, but the current implementation actually flushes as much output
+ as possible anyway.
+
+ inflate() should normally be called until it returns Z_STREAM_END or an
+ error. However if all decompression is to be performed in a single step
+ (a single call of inflate), the parameter flush should be set to
+ Z_FINISH. In this case all pending input is processed and all pending
+ output is flushed; avail_out must be large enough to hold all the
+ uncompressed data. (The size of the uncompressed data may have been saved
+ by the compressor for this purpose.) The next operation on this stream must
+ be inflateEnd to deallocate the decompression state. The use of Z_FINISH
+ is never required, but can be used to inform inflate that a faster routine
+ may be used for the single inflate() call.
+
+ If a preset dictionary is needed at this point (see inflateSetDictionary
+ below), inflate sets strm-adler to the adler32 checksum of the
+ dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
+ it sets strm->adler to the adler32 checksum of all output produced
+ so (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
+ an error code as described below. At the end of the stream, inflate()
+ checks that its computed adler32 checksum is equal to that saved by the
+ compressor and returns Z_STREAM_END only if the checksum is correct.
+
+ inflate() returns Z_OK if some progress has been made (more input processed
+ or more output produced), Z_STREAM_END if the end of the compressed data has
+ been reached and all uncompressed output has been produced, Z_NEED_DICT if a
+ preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
+ corrupted (input stream not conforming to the zlib format or incorrect
+ adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
+ (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if no progress is possible or if there was not
+ enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
+ case, the application may then call inflateSync to look for a good
+ compression block.
+ */
+
+
+int inflateEnd OF( (z_streamp strm) );
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any
+ pending output.
+
+ inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
+ was inconsistent. In the error case, msg may be set but then points to a
+ static string (which must not be deallocated).
+ */
+
+/* Advanced functions */
+
+/*
+ The following functions are needed only in some special applications.
+ */
+
+/*
+ int deflateInit2 OF((z_streamp strm,
+ int level,
+ int method,
+ int windowBits,
+ int memLevel,
+ int strategy));
+
+ This is another version of deflateInit with more compression options. The
+ fields next_in, zalloc, zfree and opaque must be initialized before by
+ the caller.
+
+ The method parameter is the compression method. It must be Z_DEFLATED in
+ this version of the library.
+
+ The windowBits parameter is the base two logarithm of the window size
+ (the size of the history buffer). It should be in the range 8..15 for this
+ version of the library. Larger values of this parameter result in better
+ compression at the expense of memory usage. The default value is 15 if
+ deflateInit is used instead.
+
+ The memLevel parameter specifies how much memory should be allocated
+ for the internal compression state. memLevel=1 uses minimum memory but
+ is slow and reduces compression ratio; memLevel=9 uses maximum memory
+ for optimal speed. The default value is 8. See zconf.h for total memory
+ usage as a function of windowBits and memLevel.
+
+ The strategy parameter is used to tune the compression algorithm. Use the
+ value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
+ filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
+ string match). Filtered data consists mostly of small values with a
+ somewhat random distribution. In this case, the compression algorithm is
+ tuned to compress them better. The effect of Z_FILTERED is to force more
+ Huffman coding and less string matching; it is somewhat intermediate
+ between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
+ the compression ratio but not the correctness of the compressed output even
+ if it is not set appropriately.
+
+ deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
+ method). msg is set to null if there is no error message. deflateInit2 does
+ not perform any compression: this will be done by deflate().
+ */
+
+int deflateSetDictionary OF( ( z_streamp strm,
+ const Byte * dictionary,
+ uInt dictLength ) );
+/*
+ Initializes the compression dictionary from the given byte sequence
+ without producing any compressed output. This function must be called
+ immediately after deflateInit, deflateInit2 or deflateReset, before any
+ call of deflate. The compressor and decompressor must use exactly the same
+ dictionary (see inflateSetDictionary).
+
+ The dictionary should consist of strings (byte sequences) that are likely
+ to be encountered later in the data to be compressed, with the most commonly
+ used strings preferably put towards the end of the dictionary. Using a
+ dictionary is most useful when the data to be compressed is short and can be
+ predicted with good accuracy; the data can then be compressed better than
+ with the default empty dictionary.
+
+ Depending on the size of the compression data structures selected by
+ deflateInit or deflateInit2, a part of the dictionary may in effect be
+ discarded, for example if the dictionary is larger than the window size in
+ deflate or deflate2. Thus the strings most likely to be useful should be
+ put at the end of the dictionary, not at the front.
+
+ Upon return of this function, strm->adler is set to the Adler32 value
+ of the dictionary; the decompressor may later use this value to determine
+ which dictionary has been used by the compressor. (The Adler32 value
+ applies to the whole dictionary even if only a subset of the dictionary is
+ actually used by the compressor.)
+
+ deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
+ parameter is invalid (such as NULL dictionary) or the stream state is
+ inconsistent (for example if deflate has already been called for this stream
+ or if the compression method is bsort). deflateSetDictionary does not
+ perform any compression: this will be done by deflate().
+ */
+
+int deflateCopy OF( ( z_streamp dest,
+ z_streamp source ) );
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when several compression strategies will be
+ tried, for example when there are several ways of pre-processing the input
+ data with a filter. The streams that will be discarded should then be freed
+ by calling deflateEnd. Note that deflateCopy duplicates the internal
+ compression state which can be quite large, so this strategy is slow and
+ can consume lots of memory.
+
+ deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being NULL). msg is left unchanged in both source and
+ destination.
+ */
+
+int deflateReset OF( (z_streamp strm) );
+/*
+ This function is equivalent to deflateEnd followed by deflateInit,
+ but does not free and reallocate all the internal compression state.
+ The stream will keep the same compression level and any other attributes
+ that may have been set by deflateInit2.
+
+ deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being NULL).
+ */
+
+int deflateParams OF( ( z_streamp strm,
+ int level,
+ int strategy ) );
+/*
+ Dynamically update the compression level and compression strategy. The
+ interpretation of level and strategy is as in deflateInit2. This can be
+ used to switch between compression and straight copy of the input data, or
+ to switch to a different kind of input data requiring a different
+ strategy. If the compression level is changed, the input available so far
+ is compressed with the old level (and may be flushed); the new level will
+ take effect only at the next call of deflate().
+
+ Before the call of deflateParams, the stream state must be set as for
+ a call of deflate(), since the currently available input may have to
+ be compressed and flushed. In particular, strm->avail_out must be non-zero.
+
+ deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
+ stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
+ if strm->avail_out was zero.
+ */
+
+/*
+ int inflateInit2 OF((z_streamp strm,
+ int windowBits));
+
+ This is another version of inflateInit with an extra parameter. The
+ fields next_in, avail_in, zalloc, zfree and opaque must be initialized
+ before by the caller.
+
+ The windowBits parameter is the base two logarithm of the maximum window
+ size (the size of the history buffer). It should be in the range 8..15 for
+ this version of the library. The default value is 15 if inflateInit is used
+ instead. If a compressed stream with a larger window size is given as
+ input, inflate() will return with the error code Z_DATA_ERROR instead of
+ trying to allocate a larger window.
+
+ inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
+ memLevel). msg is set to null if there is no error message. inflateInit2
+ does not perform any decompression apart from reading the zlib header if
+ present: this will be done by inflate(). (So next_in and avail_in may be
+ modified, but next_out and avail_out are unchanged.)
+ */
+
+int inflateSetDictionary OF( ( z_streamp strm,
+ const Byte * dictionary,
+ uInt dictLength ) );
+/*
+ Initializes the decompression dictionary from the given uncompressed byte
+ sequence. This function must be called immediately after a call of inflate
+ if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
+ can be determined from the Adler32 value returned by this call of
+ inflate. The compressor and decompressor must use exactly the same
+ dictionary (see deflateSetDictionary).
+
+ inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
+ parameter is invalid (such as NULL dictionary) or the stream state is
+ inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
+ expected one (incorrect Adler32 value). inflateSetDictionary does not
+ perform any decompression: this will be done by subsequent calls of
+ inflate().
+ */
+
+int inflateSync OF( (z_streamp strm) );
+/*
+ Skips invalid compressed data until a full flush point (see above the
+ description of deflate with Z_FULL_FLUSH) can be found, or until all
+ available input is skipped. No output is provided.
+
+ inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
+ if no more input was provided, Z_DATA_ERROR if no flush point has been found,
+ or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
+ case, the application may save the current current value of total_in which
+ indicates where valid compressed data was found. In the error case, the
+ application may repeatedly call inflateSync, providing more input each time,
+ until success or end of the input data.
+ */
+
+int inflateReset OF( (z_streamp strm) );
+/*
+ This function is equivalent to inflateEnd followed by inflateInit,
+ but does not free and reallocate all the internal decompression state.
+ The stream will keep attributes that may have been set by inflateInit2.
+
+ inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being NULL).
+ */
+
+
+/* utility functions */
+
+/*
+ The following utility functions are implemented on top of the
+ basic stream-oriented functions. To simplify the interface, some
+ default options are assumed (compression level and memory usage,
+ standard memory allocation functions). The source code of these
+ utility functions can easily be modified if you need special options.
+ */
+
+int compress OF( ( Byte * dest, uLong * destLen,
+ const Byte * source, uLong sourceLen ) );
+/*
+ Compresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be at least 0.1% larger than
+ sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
+ compressed buffer.
+ This function can be used to compress a whole file at once if the
+ input file is mmap'ed.
+ compress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer.
+ */
+
+int compress2 OF( ( Byte * dest, uLong * destLen,
+ const Byte * source, uLong sourceLen,
+ int level ) );
+/*
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least 0.1% larger than sourceLen plus
+ 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+ */
+
+int uncompress OF( ( Byte * dest, uLong * destLen,
+ const Byte * source, uLong sourceLen ) );
+/*
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be large enough to hold the
+ entire uncompressed data. (The size of the uncompressed data must have
+ been saved previously by the compressor and transmitted to the decompressor
+ by some mechanism outside the scope of this compression library.)
+ Upon exit, destLen is the actual size of the compressed buffer.
+ This function can be used to decompress a whole file at once if the
+ input file is mmap'ed.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted.
+ */
+
+
+typedef voidp gzFile;
+
+gzFile gzopen OF( ( const char *path, const char *mode ) );
+/*
+ Opens a gzip (.gz) file for reading or writing. The mode parameter
+ is as in fopen ("rb" or "wb") but can also include a compression level
+ ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
+ Huffman only compression as in "wb1h". (See the description
+ of deflateInit2 for more information about the strategy parameter.)
+
+ gzopen can be used to read a file which is not in gzip format; in this
+ case gzread will directly read from the file without decompression.
+
+ gzopen returns NULL if the file could not be opened or if there was
+ insufficient memory to allocate the (de)compression state; errno
+ can be checked to distinguish the two cases (if errno is zero, the
+ zlib error is Z_MEM_ERROR). */
+
+gzFile gzdopen OF( ( int fd, const char *mode ) );
+/*
+ gzdopen() associates a gzFile with the file descriptor fd. File
+ descriptors are obtained from calls like open, dup, creat, pipe or
+ fileno (in the file has been previously opened with fopen).
+ The mode parameter is as in gzopen.
+ The next call of gzclose on the returned gzFile will also close the
+ file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
+ descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
+ gzdopen returns NULL if there was insufficient memory to allocate
+ the (de)compression state.
+ */
+
+int gzsetparams OF( ( gzFile file, int level, int strategy ) );
+/*
+ Dynamically update the compression level or strategy. See the description
+ of deflateInit2 for the meaning of these parameters.
+ gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
+ opened for writing.
+ */
+
+int gzread OF( ( gzFile file, voidp buf, unsigned len ) );
+/*
+ Reads the given number of uncompressed bytes from the compressed file.
+ If the input file was not in gzip format, gzread copies the given number
+ of bytes into the buffer.
+ gzread returns the number of uncompressed bytes actually read (0 for
+ end of file, -1 for error). */
+
+int gzwrite OF( ( gzFile file,
+ const voidp buf, unsigned len ) );
+/*
+ Writes the given number of uncompressed bytes into the compressed file.
+ gzwrite returns the number of uncompressed bytes actually written
+ (0 in case of error).
+ */
+
+int gzprintf OF( ( gzFile file, const char *format, ... ) );
+/*
+ Converts, formats, and writes the args to the compressed file under
+ control of the format string, as in fprintf. gzprintf returns the number of
+ uncompressed bytes actually written (0 in case of error).
+ */
+
+int gzputs OF( ( gzFile file, const char *s ) );
+/*
+ Writes the given null-terminated string to the compressed file, excluding
+ the terminating null character.
+ gzputs returns the number of characters written, or -1 in case of error.
+ */
+
+char * gzgets OF( ( gzFile file, char *buf, int len ) );
+/*
+ Reads bytes from the compressed file until len-1 characters are read, or
+ a newline character is read and transferred to buf, or an end-of-file
+ condition is encountered. The string is then terminated with a null
+ character.
+ gzgets returns buf, or Z_NULL in case of error.
+ */
+
+int gzputc OF( ( gzFile file, int c ) );
+/*
+ Writes c, converted to an unsigned char, into the compressed file.
+ gzputc returns the value that was written, or -1 in case of error.
+ */
+
+int gzgetc OF( (gzFile file) );
+/*
+ Reads one byte from the compressed file. gzgetc returns this byte
+ or -1 in case of end of file or error.
+ */
+
+int gzflush OF( ( gzFile file, int flush ) );
+/*
+ Flushes all pending output into the compressed file. The parameter
+ flush is as in the deflate() function. The return value is the zlib
+ error number (see function gzerror below). gzflush returns Z_OK if
+ the flush parameter is Z_FINISH and all output could be flushed.
+ gzflush should be called only when strictly necessary because it can
+ degrade compression.
+ */
+
+long gzseek OF( ( gzFile file,
+ long offset, int whence ) );
+/*
+ Sets the starting position for the next gzread or gzwrite on the
+ given compressed file. The offset represents a number of bytes in the
+ uncompressed data stream. The whence parameter is defined as in lseek(2);
+ the value SEEK_END is not supported.
+ If the file is opened for reading, this function is emulated but can be
+ extremely slow. If the file is opened for writing, only forward seeks are
+ supported; gzseek then compresses a sequence of zeroes up to the new
+ starting position.
+
+ gzseek returns the resulting offset location as measured in bytes from
+ the beginning of the uncompressed stream, or -1 in case of error, in
+ particular if the file is opened for writing and the new starting position
+ would be before the current position.
+ */
+
+int gzrewind OF( (gzFile file) );
+/*
+ Rewinds the given file. This function is supported only for reading.
+
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
+ */
+
+long gztell OF( (gzFile file) );
+/*
+ Returns the starting position for the next gzread or gzwrite on the
+ given compressed file. This position represents a number of bytes in the
+ uncompressed data stream.
+
+ gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
+ */
+
+int gzeof OF( (gzFile file) );
+/*
+ Returns 1 when EOF has previously been detected reading the given
+ input stream, otherwise zero.
+ */
+
+int gzclose OF( (gzFile file) );
+/*
+ Flushes all pending output if necessary, closes the compressed file
+ and deallocates all the (de)compression state. The return value is the zlib
+ error number (see function gzerror below).
+ */
+
+const char * gzerror OF( ( gzFile file, int *errnum ) );
+/*
+ Returns the error message for the last error which occurred on the
+ given compressed file. errnum is set to zlib error number. If an
+ error occurred in the file system and not in the compression library,
+ errnum is set to Z_ERRNO and the application may consult errno
+ to get the exact error code.
+ */
+
+/* checksum functions */
+
+/*
+ These functions are not related to compression but are exported
+ anyway because they might be useful in applications using the
+ compression library.
+ */
+
+uLong adler32 OF( ( uLong adler, const Byte * buf, uInt len ) );
+
+/*
+ Update a running Adler-32 checksum with the bytes buf[0..len-1] and
+ return the updated checksum. If buf is NULL, this function returns
+ the required initial value for the checksum.
+ An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
+ much faster. Usage example:
+
+ uLong adler = adler32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ adler = adler32(adler, buffer, length);
+ }
+ if (adler != original_adler) error();
+ */
+
+uLong crc32 OF( ( uLong crc, const Byte * buf, uInt len ) );
+/*
+ Update a running crc with the bytes buf[0..len-1] and return the updated
+ crc. If buf is NULL, this function returns the required initial value
+ for the crc. Pre- and post-conditioning (one's complement) is performed
+ within this function so it shouldn't be done by the application.
+ Usage example:
+
+ uLong crc = crc32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ crc = crc32(crc, buffer, length);
+ }
+ if (crc != original_crc) error();
+ */
+
+// private stuff to not include cmdlib.h
+/*
+ ============================================================================
+
+ BYTE ORDER FUNCTIONS
+
+ ============================================================================
+ */
+
+#ifdef _SGI_SOURCE
+#define __BIG_ENDIAN__
+#endif
+
+#ifdef __BIG_ENDIAN__
+
+short __LittleShort( short l ){
+ byte b1,b2;
+
+ b1 = l & 255;
+ b2 = ( l >> 8 ) & 255;
+
+ return ( b1 << 8 ) + b2;
+}
+
+short __BigShort( short l ){
+ return l;
+}
+
+
+int __LittleLong( int l ){
+ byte b1,b2,b3,b4;
+
+ b1 = l & 255;
+ b2 = ( l >> 8 ) & 255;
+ b3 = ( l >> 16 ) & 255;
+ b4 = ( l >> 24 ) & 255;
+
+ return ( (int)b1 << 24 ) + ( (int)b2 << 16 ) + ( (int)b3 << 8 ) + b4;
+}
+
+int __BigLong( int l ){
+ return l;
+}
+
+
+float __LittleFloat( float l ){
+ union {byte b[4]; float f; } in, out;
+
+ in.f = l;
+ out.b[0] = in.b[3];
+ out.b[1] = in.b[2];
+ out.b[2] = in.b[1];
+ out.b[3] = in.b[0];
+
+ return out.f;
+}
+
+float __BigFloat( float l ){
+ return l;
+}
+
+
+#else
+
+
+short __BigShort( short l ){
+ byte b1,b2;
+
+ b1 = l & 255;
+ b2 = ( l >> 8 ) & 255;
+
+ return ( b1 << 8 ) + b2;
+}
+
+short __LittleShort( short l ){
+ return l;
+}
+
+
+int __BigLong( int l ){
+ byte b1,b2,b3,b4;
+
+ b1 = l & 255;
+ b2 = ( l >> 8 ) & 255;
+ b3 = ( l >> 16 ) & 255;
+ b4 = ( l >> 24 ) & 255;
+
+ return ( (int)b1 << 24 ) + ( (int)b2 << 16 ) + ( (int)b3 << 8 ) + b4;
+}
+
+int __LittleLong( int l ){
+ return l;
+}
+
+float __BigFloat( float l ){
+ union {byte b[4]; float f; } in, out;
+
+ in.f = l;
+ out.b[0] = in.b[3];
+ out.b[1] = in.b[2];
+ out.b[2] = in.b[1];
+ out.b[3] = in.b[0];
+
+ return out.f;
+}
+
+float __LittleFloat( float l ){
+ return l;
+}
+
+
+
+#endif
+
+
+
+
+/* various hacks, don't look :) */
+
+/* deflateInit and inflateInit are macros to allow checking the zlib version
+ * and the compiler's view of z_stream:
+ */
+int deflateInit_ OF( ( z_streamp strm, int level,
+ const char *version, int stream_size ) );
+int inflateInit_ OF( ( z_streamp strm,
+ const char *version, int stream_size ) );
+int deflateInit2_ OF( ( z_streamp strm, int level, int method,
+ int windowBits, int memLevel,
+ int strategy, const char *version,
+ int stream_size ) );
+int inflateInit2_ OF( ( z_streamp strm, int windowBits,
+ const char *version, int stream_size ) );
+#define deflateInit( strm, level ) \
+ deflateInit_( ( strm ), ( level ), ZLIB_VERSION, sizeof( z_stream ) )
+#define inflateInit( strm ) \
+ inflateInit_( ( strm ), ZLIB_VERSION, sizeof( z_stream ) )
+#define deflateInit2( strm, level, method, windowBits, memLevel, strategy ) \
+ deflateInit2_( ( strm ),( level ),( method ),( windowBits ),( memLevel ), \
+ ( strategy ), ZLIB_VERSION, sizeof( z_stream ) )
+#define inflateInit2( strm, windowBits ) \
+ inflateInit2_( ( strm ), ( windowBits ), ZLIB_VERSION, sizeof( z_stream ) )
+
+
+const char * zError OF( (int err) );
+int inflateSyncPoint OF( (z_streamp z) );
+const uLong * get_crc_table OF( (void) );
+
+typedef unsigned char uch;
+typedef unsigned short ush;
+typedef unsigned long ulg;
+
+extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
+/* (size given to avoid silly warnings with Visual C++) */
+
+#define ERR_MSG( err ) z_errmsg[Z_NEED_DICT - ( err )]
+
+#define ERR_RETURN( strm,err ) \
+ return ( strm->msg = (char*)ERR_MSG( err ), ( err ) )
+/* To be used only when the state is known to be valid */
+
+/* common constants */
+
+#ifndef DEF_WBITS
+# define DEF_WBITS MAX_WBITS
+#endif
+/* default windowBits for decompression. MAX_WBITS is for compression only */
+
+#if MAX_MEM_LEVEL >= 8
+# define DEF_MEM_LEVEL 8
+#else
+# define DEF_MEM_LEVEL MAX_MEM_LEVEL
+#endif
+/* default memLevel */
+
+#define STORED_BLOCK 0
+#define STATIC_TREES 1
+#define DYN_TREES 2
+/* The three kinds of block type */
+
+#define MIN_MATCH 3
+#define MAX_MATCH 258
+/* The minimum and maximum match lengths */
+
+#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
+
+/* target dependencies */
+
+/* Common defaults */
+
+#ifndef OS_CODE
+# define OS_CODE 0x03 /* assume Unix */
+#endif
+
+#ifndef F_OPEN
+# define F_OPEN( name, mode ) fopen( ( name ), ( mode ) )
+#endif
+
+/* functions */
+
+#ifdef HAVE_STRERROR
+extern char *strerror OF( (int) );
+# define zstrerror( errnum ) strerror( errnum )
+#else
+# define zstrerror( errnum ) ""
+#endif
+
+#define zmemcpy memcpy
+#define zmemcmp memcmp
+#define zmemzero( dest, len ) memset( dest, 0, len )
+
+/* Diagnostic functions */
+#ifdef _ZIP_DEBUG_
+int z_verbose = 0;
+# define Assert( cond,msg ) assert( cond );
+//{if(!(cond)) Sys_Error(msg);}
+# define Trace( x ) {if ( z_verbose >= 0 ) {Sys_Error x ; }}
+# define Tracev( x ) {if ( z_verbose > 0 ) {Sys_Error x ; }}
+# define Tracevv( x ) {if ( z_verbose > 1 ) {Sys_Error x ; }}
+# define Tracec( c,x ) {if ( z_verbose > 0 && ( c ) ) {Sys_Error x ; }}
+# define Tracecv( c,x ) {if ( z_verbose > 1 && ( c ) ) {Sys_Error x ; }}
+#else
+# define Assert( cond,msg )
+# define Trace( x )
+# define Tracev( x )
+# define Tracevv( x )
+# define Tracec( c,x )
+# define Tracecv( c,x )
+#endif
+
+
+typedef uLong ( *check_func ) OF ( ( uLong check, const Byte * buf, uInt len ) );
+voidp zcalloc OF( ( voidp opaque, unsigned items, unsigned size ) );
+void zcfree OF( ( voidp opaque, voidp ptr ) );
+
+#define ZALLOC( strm, items, size ) \
+ ( *( ( strm )->zalloc ) )( ( strm )->opaque, ( items ), ( size ) )
+#define ZFREE( strm, addr ) ( *( ( strm )->zfree ) )( ( strm )->opaque, (voidp)( addr ) )
+#define TRY_FREE( s, p ) {if ( p ) {ZFREE( s, p ); }}
+
+
+#if !defined( unix ) && !defined( CASESENSITIVITYDEFAULT_YES ) && \
+ !defined( CASESENSITIVITYDEFAULT_NO )
+#define CASESENSITIVITYDEFAULT_NO
+#endif
+
+
+#ifndef UNZ_BUFSIZE
+#define UNZ_BUFSIZE ( 65536 )
+#endif
+
+#ifndef UNZ_MAXFILENAMEINZIP
+#define UNZ_MAXFILENAMEINZIP ( 256 )
+#endif
+
+#ifndef ALLOC
+# define ALLOC( size ) ( malloc( size ) )
+#endif
+#ifndef TRYFREE
+# define TRYFREE( p ) {if ( p ) {free( p ); }}
+#endif
+
+#define SIZECENTRALDIRITEM ( 0x2e )
+#define SIZEZIPLOCALHEADER ( 0x1e )
+
+
+
+/* ===========================================================================
+ Read a byte from a gz_stream; update next_in and avail_in. Return EOF
+ for end of file.
+ IN assertion: the stream s has been sucessfully opened for reading.
+ */
+
+/*
+ static int unzlocal_getByte(FILE *fin,int *pi)
+ {
+ unsigned char c;
+ int err = fread(&c, 1, 1, fin);
+ if (err==1)
+ {
+ *pi = (int)c;
+ return UNZ_OK;
+ }
+ else
+ {
+ if (ferror(fin))
+ return UNZ_ERRNO;
+ else
+ return UNZ_EOF;
+ }
+ }
+ */
+
+/* ===========================================================================
+ Reads a long in LSB order from the given gz_stream. Sets
+ */
+static int unzlocal_getShort( FILE* fin, uLong *pX ){
+ short v;
+
+ fread( &v, sizeof( v ), 1, fin );
+
+ *pX = __LittleShort( v );
+ return UNZ_OK;
+
+/*
+ uLong x ;
+ int i;
+ int err;
+
+ err = unzlocal_getByte(fin,&i);
+ x = (uLong)i;
+
+ if (err==UNZ_OK)
+ err = unzlocal_getByte(fin,&i);
+ x += ((uLong)i)<<8;
+
+ if (err==UNZ_OK)
+ *pX = x;
+ else
+ *pX = 0;
+ return err;
+ */
+}
+
+static int unzlocal_getLong( FILE *fin, uLong *pX ){
+ int v;
+
+ fread( &v, sizeof( v ), 1, fin );
+
+ *pX = __LittleLong( v );
+ return UNZ_OK;
+
+/*
+ uLong x ;
+ int i;
+ int err;
+
+ err = unzlocal_getByte(fin,&i);
+ x = (uLong)i;
+
+ if (err==UNZ_OK)
+ err = unzlocal_getByte(fin,&i);
+ x += ((uLong)i)<<8;
+
+ if (err==UNZ_OK)
+ err = unzlocal_getByte(fin,&i);
+ x += ((uLong)i)<<16;
+
+ if (err==UNZ_OK)
+ err = unzlocal_getByte(fin,&i);
+ x += ((uLong)i)<<24;
+
+ if (err==UNZ_OK)
+ *pX = x;
+ else
+ *pX = 0;
+ return err;
+ */
+}
+
+
+/* My own strcmpi / strcasecmp */
+static int strcmpcasenosensitive_internal( const char* fileName1,const char* fileName2 ){
+ for (;; )
+ {
+ char c1 = *( fileName1++ );
+ char c2 = *( fileName2++ );
+ if ( ( c1 >= 'a' ) && ( c1 <= 'z' ) ) {
+ c1 -= 0x20;
+ }
+ if ( ( c2 >= 'a' ) && ( c2 <= 'z' ) ) {
+ c2 -= 0x20;
+ }
+ if ( c1 == '\0' ) {
+ return ( ( c2 == '\0' ) ? 0 : -1 );
+ }
+ if ( c2 == '\0' ) {
+ return 1;
+ }
+ if ( c1 < c2 ) {
+ return -1;
+ }
+ if ( c1 > c2 ) {
+ return 1;
+ }
+ }
+}
+
+
+#ifdef CASESENSITIVITYDEFAULT_NO
+#define CASESENSITIVITYDEFAULTVALUE 2
+#else
+#define CASESENSITIVITYDEFAULTVALUE 1
+#endif
+
+#ifndef STRCMPCASENOSENTIVEFUNCTION
+#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
+#endif
+
+/*
+ Compare two filename (fileName1,fileName2).
+ If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
+ If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
+ or strcasecmp)
+ If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
+ (like 1 on Unix, 2 on Windows)
+
+ */
+extern int unzStringFileNameCompare( const char* fileName1,const char* fileName2,int iCaseSensitivity ){
+ if ( iCaseSensitivity == 0 ) {
+ iCaseSensitivity = CASESENSITIVITYDEFAULTVALUE;
+ }
+
+ if ( iCaseSensitivity == 1 ) {
+ return strcmp( fileName1,fileName2 );
+ }
+
+ return STRCMPCASENOSENTIVEFUNCTION( fileName1,fileName2 );
+}
+
+#define BUFREADCOMMENT ( 0x400 )
+
+/*
+ Locate the Central directory of a zipfile (at the end, just before
+ the global comment)
+ */
+static uLong unzlocal_SearchCentralDir( FILE *fin ){
+ unsigned char* buf;
+ uLong uSizeFile;
+ uLong uBackRead;
+ uLong uMaxBack = 0xffff; /* maximum size of global comment */
+ uLong uPosFound = 0;
+
+ if ( fseek( fin,0,SEEK_END ) != 0 ) {
+ return 0;
+ }
+
+
+ uSizeFile = ftell( fin );
+
+ if ( uMaxBack > uSizeFile ) {
+ uMaxBack = uSizeFile;
+ }
+
+ buf = (unsigned char*)malloc( BUFREADCOMMENT + 4 );
+ if ( buf == NULL ) {
+ return 0;
+ }
+
+ uBackRead = 4;
+ while ( uBackRead < uMaxBack )
+ {
+ uLong uReadSize,uReadPos ;
+ int i;
+ if ( uBackRead + BUFREADCOMMENT > uMaxBack ) {
+ uBackRead = uMaxBack;
+ }
+ else{
+ uBackRead += BUFREADCOMMENT;
+ }
+ uReadPos = uSizeFile - uBackRead ;
+
+ uReadSize = ( ( BUFREADCOMMENT + 4 ) < ( uSizeFile - uReadPos ) ) ?
+ ( BUFREADCOMMENT + 4 ) : ( uSizeFile - uReadPos );
+ if ( fseek( fin,uReadPos,SEEK_SET ) != 0 ) {
+ break;
+ }
+
+ if ( fread( buf,(uInt)uReadSize,1,fin ) != 1 ) {
+ break;
+ }
+
+ for ( i = (int)uReadSize - 3; ( i-- ) > 0; )
+ if ( ( ( *( buf + i ) ) == 0x50 ) && ( ( *( buf + i + 1 ) ) == 0x4b ) &&
+ ( ( *( buf + i + 2 ) ) == 0x05 ) && ( ( *( buf + i + 3 ) ) == 0x06 ) ) {
+ uPosFound = uReadPos + i;
+ break;
+ }
+
+ if ( uPosFound != 0 ) {
+ break;
+ }
+ }
+ free( buf );
+ return uPosFound;
+}
+
+extern unzFile unzReOpen( const char* path, unzFile file ){
+ unz_s *s;
+ FILE * fin;
+
+ fin = fopen( path,"rb" );
+ if ( fin == NULL ) {
+ return NULL;
+ }
+
+ s = (unz_s*)malloc( sizeof( unz_s ) );
+ memcpy( s, (unz_s*)file, sizeof( unz_s ) );
+
+ s->file = fin;
+ return (unzFile)s;
+}
+
+/*
+ Open a Zip file. path contain the full pathname (by example,
+ on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer
+ "zlib/zlib109.zip".
+ If the zipfile cannot be opened (file don't exist or in not valid), the
+ return value is NULL.
+ Else, the return value is a unzFile Handle, usable with other function
+ of this unzip package.
+ */
+extern unzFile unzOpen( const char* path ){
+ unz_s us;
+ unz_s *s;
+ uLong central_pos,uL;
+ FILE * fin ;
+
+ uLong number_disk; /* number of the current dist, used for
+ spaning ZIP, unsupported, always 0*/
+ uLong number_disk_with_CD; /* number the the disk with central dir, used
+ for spaning ZIP, unsupported, always 0*/
+ uLong number_entry_CD; /* total number of entries in
+ the central dir
+ (same than number_entry on nospan) */
+
+ int err = UNZ_OK;
+
+ fin = fopen( path,"rb" );
+ if ( fin == NULL ) {
+ return NULL;
+ }
+
+ central_pos = unzlocal_SearchCentralDir( fin );
+ if ( central_pos == 0 ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( fseek( fin,central_pos,SEEK_SET ) != 0 ) {
+ err = UNZ_ERRNO;
+ }
+
+ /* the signature, already checked */
+ if ( unzlocal_getLong( fin,&uL ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ /* number of this disk */
+ if ( unzlocal_getShort( fin,&number_disk ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ /* number of the disk with the start of the central directory */
+ if ( unzlocal_getShort( fin,&number_disk_with_CD ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ /* total number of entries in the central dir on this disk */
+ if ( unzlocal_getShort( fin,&us.gi.number_entry ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ /* total number of entries in the central dir */
+ if ( unzlocal_getShort( fin,&number_entry_CD ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( ( number_entry_CD != us.gi.number_entry ) ||
+ ( number_disk_with_CD != 0 ) ||
+ ( number_disk != 0 ) ) {
+ err = UNZ_BADZIPFILE;
+ }
+
+ /* size of the central directory */
+ if ( unzlocal_getLong( fin,&us.size_central_dir ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ /* offset of start of central directory with respect to the
+ starting disk number */
+ if ( unzlocal_getLong( fin,&us.offset_central_dir ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ /* zipfile comment length */
+ if ( unzlocal_getShort( fin,&us.gi.size_comment ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( ( central_pos < us.offset_central_dir + us.size_central_dir ) &&
+ ( err == UNZ_OK ) ) {
+ err = UNZ_BADZIPFILE;
+ }
+
+ if ( err != UNZ_OK ) {
+ fclose( fin );
+ return NULL;
+ }
+
+ us.file = fin;
+ us.byte_before_the_zipfile = central_pos -
+ ( us.offset_central_dir + us.size_central_dir );
+ us.central_pos = central_pos;
+ us.pfile_in_zip_read = NULL;
+
+
+ s = (unz_s*)malloc( sizeof( unz_s ) );
+ *s = us;
+// unzGoToFirstFile((unzFile)s);
+ return (unzFile)s;
+}
+
+
+/*
+ Close a ZipFile opened with unzipOpen.
+ If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
+ these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
+ return UNZ_OK if there is no problem. */
+extern int unzClose( unzFile file ){
+ unz_s* s;
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+
+ if ( s->pfile_in_zip_read != NULL ) {
+ unzCloseCurrentFile( file );
+ }
+
+ fclose( s->file );
+ free( s );
+ return UNZ_OK;
+}
+
+
+/*
+ Write info about the ZipFile in the *pglobal_info structure.
+ No preparation of the structure is needed
+ return UNZ_OK if there is no problem. */
+extern int unzGetGlobalInfo( unzFile file,unz_global_info *pglobal_info ){
+ unz_s* s;
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ *pglobal_info = s->gi;
+ return UNZ_OK;
+}
+
+
+/*
+ Translate date/time from Dos format to tm_unz (readable more easilty)
+ */
+static void unzlocal_DosDateToTmuDate( uLong ulDosDate, tm_unz* ptm ){
+ uLong uDate;
+ uDate = (uLong)( ulDosDate >> 16 );
+ ptm->tm_mday = (uInt)( uDate & 0x1f ) ;
+ ptm->tm_mon = (uInt)( ( ( ( uDate ) & 0x1E0 ) / 0x20 ) - 1 ) ;
+ ptm->tm_year = (uInt)( ( ( uDate & 0x0FE00 ) / 0x0200 ) + 1980 ) ;
+
+ ptm->tm_hour = (uInt) ( ( ulDosDate & 0xF800 ) / 0x800 );
+ ptm->tm_min = (uInt) ( ( ulDosDate & 0x7E0 ) / 0x20 ) ;
+ ptm->tm_sec = (uInt) ( 2 * ( ulDosDate & 0x1f ) ) ;
+}
+
+/*
+ Get Info about the current file in the zipfile, with internal only info
+ */
+static int unzlocal_GetCurrentFileInfoInternal( unzFile file,
+ unz_file_info *pfile_info,
+ unz_file_info_internal
+ *pfile_info_internal,
+ char *szFileName,
+ uLong fileNameBufferSize,
+ void *extraField,
+ uLong extraFieldBufferSize,
+ char *szComment,
+ uLong commentBufferSize ){
+ unz_s* s;
+ unz_file_info file_info;
+ unz_file_info_internal file_info_internal;
+ int err = UNZ_OK;
+ uLong uMagic;
+ long lSeek = 0;
+
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ if ( fseek( s->file,s->pos_in_central_dir + s->byte_before_the_zipfile,SEEK_SET ) != 0 ) {
+ err = UNZ_ERRNO;
+ }
+
+
+ /* we check the magic */
+ if ( err == UNZ_OK ) {
+ if ( unzlocal_getLong( s->file,&uMagic ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+ else if ( uMagic != 0x02014b50 ) {
+ err = UNZ_BADZIPFILE;
+ }
+ }
+
+ if ( unzlocal_getShort( s->file,&file_info.version ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getShort( s->file,&file_info.version_needed ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getShort( s->file,&file_info.flag ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getShort( s->file,&file_info.compression_method ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getLong( s->file,&file_info.dosDate ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ unzlocal_DosDateToTmuDate( file_info.dosDate,&file_info.tmu_date );
+
+ if ( unzlocal_getLong( s->file,&file_info.crc ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getLong( s->file,&file_info.compressed_size ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getLong( s->file,&file_info.uncompressed_size ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getShort( s->file,&file_info.size_filename ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getShort( s->file,&file_info.size_file_extra ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getShort( s->file,&file_info.size_file_comment ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getShort( s->file,&file_info.disk_num_start ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getShort( s->file,&file_info.internal_fa ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getLong( s->file,&file_info.external_fa ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getLong( s->file,&file_info_internal.offset_curfile ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ lSeek += file_info.size_filename;
+ if ( ( err == UNZ_OK ) && ( szFileName != NULL ) ) {
+ uLong uSizeRead ;
+ if ( file_info.size_filename < fileNameBufferSize ) {
+ *( szFileName + file_info.size_filename ) = '\0';
+ uSizeRead = file_info.size_filename;
+ }
+ else{
+ uSizeRead = fileNameBufferSize;
+ }
+
+ if ( ( file_info.size_filename > 0 ) && ( fileNameBufferSize > 0 ) ) {
+ if ( fread( szFileName,(uInt)uSizeRead,1,s->file ) != 1 ) {
+ err = UNZ_ERRNO;
+ }
+ }
+ lSeek -= uSizeRead;
+ }
+
+
+ if ( ( err == UNZ_OK ) && ( extraField != NULL ) ) {
+ uLong uSizeRead ;
+ if ( file_info.size_file_extra < extraFieldBufferSize ) {
+ uSizeRead = file_info.size_file_extra;
+ }
+ else{
+ uSizeRead = extraFieldBufferSize;
+ }
+
+ if ( lSeek != 0 ) {
+ if ( fseek( s->file,lSeek,SEEK_CUR ) == 0 ) {
+ lSeek = 0;
+ }
+ else{
+ err = UNZ_ERRNO;
+ }
+ }
+ if ( ( file_info.size_file_extra > 0 ) && ( extraFieldBufferSize > 0 ) ) {
+ if ( fread( extraField,(uInt)uSizeRead,1,s->file ) != 1 ) {
+ err = UNZ_ERRNO;
+ }
+ }
+ lSeek += file_info.size_file_extra - uSizeRead;
+ }
+ else{
+ lSeek += file_info.size_file_extra;
+ }
+
+
+ if ( ( err == UNZ_OK ) && ( szComment != NULL ) ) {
+ uLong uSizeRead ;
+ if ( file_info.size_file_comment < commentBufferSize ) {
+ *( szComment + file_info.size_file_comment ) = '\0';
+ uSizeRead = file_info.size_file_comment;
+ }
+ else{
+ uSizeRead = commentBufferSize;
+ }
+
+ if ( lSeek != 0 ) {
+ if ( fseek( s->file,lSeek,SEEK_CUR ) == 0 ) {
+ lSeek = 0;
+ }
+ else{
+ err = UNZ_ERRNO;
+ }
+ }
+ if ( ( file_info.size_file_comment > 0 ) && ( commentBufferSize > 0 ) ) {
+ if ( fread( szComment,(uInt)uSizeRead,1,s->file ) != 1 ) {
+ err = UNZ_ERRNO;
+ }
+ }
+ lSeek += file_info.size_file_comment - uSizeRead;
+ }
+ else{
+ lSeek += file_info.size_file_comment;
+ }
+
+ if ( ( err == UNZ_OK ) && ( pfile_info != NULL ) ) {
+ *pfile_info = file_info;
+ }
+
+ if ( ( err == UNZ_OK ) && ( pfile_info_internal != NULL ) ) {
+ *pfile_info_internal = file_info_internal;
+ }
+
+ return err;
+}
+
+
+
+/*
+ Write info about the ZipFile in the *pglobal_info structure.
+ No preparation of the structure is needed
+ return UNZ_OK if there is no problem.
+ */
+extern int unzGetCurrentFileInfo( unzFile file, unz_file_info *pfile_info,
+ char *szFileName, uLong fileNameBufferSize,
+ void *extraField, uLong extraFieldBufferSize,
+ char *szComment, uLong commentBufferSize ){
+ return unzlocal_GetCurrentFileInfoInternal( file,pfile_info,NULL,
+ szFileName,fileNameBufferSize,
+ extraField,extraFieldBufferSize,
+ szComment,commentBufferSize );
+}
+
+/*
+ Set the current file of the zipfile to the first file.
+ return UNZ_OK if there is no problem
+ */
+extern int unzGoToFirstFile( unzFile file ){
+ int err = UNZ_OK;
+ unz_s* s;
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ s->pos_in_central_dir = s->offset_central_dir;
+ s->num_file = 0;
+ err = unzlocal_GetCurrentFileInfoInternal( file,&s->cur_file_info,
+ &s->cur_file_info_internal,
+ NULL,0,NULL,0,NULL,0 );
+ s->current_file_ok = ( err == UNZ_OK );
+ return err;
+}
+
+
+/*
+ Set the current file of the zipfile to the next file.
+ return UNZ_OK if there is no problem
+ return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
+ */
+extern int unzGoToNextFile( unzFile file ){
+ unz_s* s;
+ int err;
+
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ if ( !s->current_file_ok ) {
+ return UNZ_END_OF_LIST_OF_FILE;
+ }
+ if ( s->num_file + 1 == s->gi.number_entry ) {
+ return UNZ_END_OF_LIST_OF_FILE;
+ }
+
+ s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
+ s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
+ s->num_file++;
+ err = unzlocal_GetCurrentFileInfoInternal( file,&s->cur_file_info,
+ &s->cur_file_info_internal,
+ NULL,0,NULL,0,NULL,0 );
+ s->current_file_ok = ( err == UNZ_OK );
+ return err;
+}
+
+
+/*
+ Try locate the file szFileName in the zipfile.
+ For the iCaseSensitivity signification, see unzipStringFileNameCompare
+
+ return value :
+ UNZ_OK if the file is found. It becomes the current file.
+ UNZ_END_OF_LIST_OF_FILE if the file is not found
+ */
+extern int unzLocateFile( unzFile file, const char *szFileName, int iCaseSensitivity ){
+ unz_s* s;
+ int err;
+
+
+ uLong num_fileSaved;
+ uLong pos_in_central_dirSaved;
+
+
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+
+ if ( strlen( szFileName ) >= UNZ_MAXFILENAMEINZIP ) {
+ return UNZ_PARAMERROR;
+ }
+
+ s = (unz_s*)file;
+ if ( !s->current_file_ok ) {
+ return UNZ_END_OF_LIST_OF_FILE;
+ }
+
+ num_fileSaved = s->num_file;
+ pos_in_central_dirSaved = s->pos_in_central_dir;
+
+ err = unzGoToFirstFile( file );
+
+ while ( err == UNZ_OK )
+ {
+ char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1];
+ unzGetCurrentFileInfo( file,NULL,
+ szCurrentFileName,sizeof( szCurrentFileName ) - 1,
+ NULL,0,NULL,0 );
+ if ( unzStringFileNameCompare( szCurrentFileName,
+ szFileName,iCaseSensitivity ) == 0 ) {
+ return UNZ_OK;
+ }
+ err = unzGoToNextFile( file );
+ }
+
+ s->num_file = num_fileSaved ;
+ s->pos_in_central_dir = pos_in_central_dirSaved ;
+ return err;
+}
+
+
+/*
+ Read the static header of the current zipfile
+ Check the coherency of the static header and info in the end of central
+ directory about this file
+ store in *piSizeVar the size of extra info in static header
+ (filename and size of extra field data)
+ */
+static int unzlocal_CheckCurrentFileCoherencyHeader( unz_s* s, uInt* piSizeVar,
+ uLong *poffset_local_extrafield,
+ uInt *psize_local_extrafield ){
+ uLong uMagic,uData,uFlags;
+ uLong size_filename;
+ uLong size_extra_field;
+ int err = UNZ_OK;
+
+ *piSizeVar = 0;
+ *poffset_local_extrafield = 0;
+ *psize_local_extrafield = 0;
+
+ if ( fseek( s->file,s->cur_file_info_internal.offset_curfile +
+ s->byte_before_the_zipfile,SEEK_SET ) != 0 ) {
+ return UNZ_ERRNO;
+ }
+
+
+ if ( err == UNZ_OK ) {
+ if ( unzlocal_getLong( s->file,&uMagic ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+ else if ( uMagic != 0x04034b50 ) {
+ err = UNZ_BADZIPFILE;
+ }
+ }
+
+ if ( unzlocal_getShort( s->file,&uData ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+/*
+ else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
+ err=UNZ_BADZIPFILE;
+ */
+ if ( unzlocal_getShort( s->file,&uFlags ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getShort( s->file,&uData ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+ else if ( ( err == UNZ_OK ) && ( uData != s->cur_file_info.compression_method ) ) {
+ err = UNZ_BADZIPFILE;
+ }
+
+ if ( ( err == UNZ_OK ) && ( s->cur_file_info.compression_method != 0 ) &&
+ ( s->cur_file_info.compression_method != Z_DEFLATED ) ) {
+ err = UNZ_BADZIPFILE;
+ }
+
+ if ( unzlocal_getLong( s->file,&uData ) != UNZ_OK ) { /* date/time */
+ err = UNZ_ERRNO;
+ }
+
+ if ( unzlocal_getLong( s->file,&uData ) != UNZ_OK ) { /* crc */
+ err = UNZ_ERRNO;
+ }
+ else if ( ( err == UNZ_OK ) && ( uData != s->cur_file_info.crc ) &&
+ ( ( uFlags & 8 ) == 0 ) ) {
+ err = UNZ_BADZIPFILE;
+ }
+
+ if ( unzlocal_getLong( s->file,&uData ) != UNZ_OK ) { /* size compr */
+ err = UNZ_ERRNO;
+ }
+ else if ( ( err == UNZ_OK ) && ( uData != s->cur_file_info.compressed_size ) &&
+ ( ( uFlags & 8 ) == 0 ) ) {
+ err = UNZ_BADZIPFILE;
+ }
+
+ if ( unzlocal_getLong( s->file,&uData ) != UNZ_OK ) { /* size uncompr */
+ err = UNZ_ERRNO;
+ }
+ else if ( ( err == UNZ_OK ) && ( uData != s->cur_file_info.uncompressed_size ) &&
+ ( ( uFlags & 8 ) == 0 ) ) {
+ err = UNZ_BADZIPFILE;
+ }
+
+
+ if ( unzlocal_getShort( s->file,&size_filename ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+ else if ( ( err == UNZ_OK ) && ( size_filename != s->cur_file_info.size_filename ) ) {
+ err = UNZ_BADZIPFILE;
+ }
+
+ *piSizeVar += (uInt)size_filename;
+
+ if ( unzlocal_getShort( s->file,&size_extra_field ) != UNZ_OK ) {
+ err = UNZ_ERRNO;
+ }
+ *poffset_local_extrafield = s->cur_file_info_internal.offset_curfile +
+ SIZEZIPLOCALHEADER + size_filename;
+ *psize_local_extrafield = (uInt)size_extra_field;
+
+ *piSizeVar += (uInt)size_extra_field;
+
+ return err;
+}
+
+/*
+ Open for reading data the current file in the zipfile.
+ If there is no error and the file is opened, the return value is UNZ_OK.
+ */
+extern int unzOpenCurrentFile( unzFile file ){
+ int err = UNZ_OK;
+ int Store;
+ uInt iSizeVar;
+ unz_s* s;
+ file_in_zip_read_info_s* pfile_in_zip_read_info;
+ uLong offset_local_extrafield; /* offset of the static extra field */
+ uInt size_local_extrafield; /* size of the static extra field */
+
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ if ( !s->current_file_ok ) {
+ return UNZ_PARAMERROR;
+ }
+
+ if ( s->pfile_in_zip_read != NULL ) {
+ unzCloseCurrentFile( file );
+ }
+
+ if ( unzlocal_CheckCurrentFileCoherencyHeader( s,&iSizeVar,
+ &offset_local_extrafield,&size_local_extrafield ) != UNZ_OK ) {
+ return UNZ_BADZIPFILE;
+ }
+
+ pfile_in_zip_read_info = (file_in_zip_read_info_s*)
+ malloc( sizeof( file_in_zip_read_info_s ) );
+ if ( pfile_in_zip_read_info == NULL ) {
+ return UNZ_INTERNALERROR;
+ }
+
+ pfile_in_zip_read_info->read_buffer = (char*)malloc( UNZ_BUFSIZE );
+ pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
+ pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
+ pfile_in_zip_read_info->pos_local_extrafield = 0;
+
+ if ( pfile_in_zip_read_info->read_buffer == NULL ) {
+ free( pfile_in_zip_read_info );
+ return UNZ_INTERNALERROR;
+ }
+
+ pfile_in_zip_read_info->stream_initialised = 0;
+
+ if ( ( s->cur_file_info.compression_method != 0 ) &&
+ ( s->cur_file_info.compression_method != Z_DEFLATED ) ) {
+ err = UNZ_BADZIPFILE;
+ }
+ Store = s->cur_file_info.compression_method == 0;
+
+ pfile_in_zip_read_info->crc32_wait = s->cur_file_info.crc;
+ pfile_in_zip_read_info->crc32 = 0;
+ pfile_in_zip_read_info->compression_method =
+ s->cur_file_info.compression_method;
+ pfile_in_zip_read_info->file = s->file;
+ pfile_in_zip_read_info->byte_before_the_zipfile = s->byte_before_the_zipfile;
+
+ pfile_in_zip_read_info->stream.total_out = 0;
+
+ if ( !Store ) {
+ pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
+ pfile_in_zip_read_info->stream.zfree = (free_func)0;
+ pfile_in_zip_read_info->stream.opaque = (voidp)0;
+
+ err = inflateInit2( &pfile_in_zip_read_info->stream, -MAX_WBITS );
+ if ( err == Z_OK ) {
+ pfile_in_zip_read_info->stream_initialised = 1;
+ }
+ /* windowBits is passed < 0 to tell that there is no zlib header.
+ * Note that in this case inflate *requires* an extra "dummy" byte
+ * after the compressed stream in order to complete decompression and
+ * return Z_STREAM_END.
+ * In unzip, i don't wait absolutely Z_STREAM_END because I known the
+ * size of both compressed and uncompressed data
+ */
+ }
+ pfile_in_zip_read_info->rest_read_compressed =
+ s->cur_file_info.compressed_size ;
+ pfile_in_zip_read_info->rest_read_uncompressed =
+ s->cur_file_info.uncompressed_size ;
+
+
+ pfile_in_zip_read_info->pos_in_zipfile =
+ s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
+ iSizeVar;
+
+ pfile_in_zip_read_info->stream.avail_in = (uInt)0;
+
+
+ s->pfile_in_zip_read = pfile_in_zip_read_info;
+ return UNZ_OK;
+}
+
+
+/*
+ Read bytes from the current file.
+ buf contain buffer where data must be copied
+ len the size of buf.
+
+ return the number of byte copied if somes bytes are copied
+ return 0 if the end of file was reached
+ return <0 with error code if there is an error
+ (UNZ_ERRNO for IO error, or zLib error for uncompress error)
+ */
+extern int unzReadCurrentFile( unzFile file, void *buf, unsigned len ){
+ int err = UNZ_OK;
+ uInt iRead = 0;
+ unz_s* s;
+ file_in_zip_read_info_s* pfile_in_zip_read_info;
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ pfile_in_zip_read_info = s->pfile_in_zip_read;
+
+ if ( pfile_in_zip_read_info == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+
+
+ if ( ( pfile_in_zip_read_info->read_buffer == NULL ) ) {
+ return UNZ_END_OF_LIST_OF_FILE;
+ }
+ if ( len == 0 ) {
+ return 0;
+ }
+
+ pfile_in_zip_read_info->stream.next_out = (Byte*)buf;
+
+ pfile_in_zip_read_info->stream.avail_out = (uInt)len;
+
+ if ( len > pfile_in_zip_read_info->rest_read_uncompressed ) {
+ pfile_in_zip_read_info->stream.avail_out =
+ (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
+ }
+
+ while ( pfile_in_zip_read_info->stream.avail_out > 0 )
+ {
+ if ( ( pfile_in_zip_read_info->stream.avail_in == 0 ) &&
+ ( pfile_in_zip_read_info->rest_read_compressed > 0 ) ) {
+ uInt uReadThis = UNZ_BUFSIZE;
+ if ( pfile_in_zip_read_info->rest_read_compressed < uReadThis ) {
+ uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
+ }
+ if ( uReadThis == 0 ) {
+ return UNZ_EOF;
+ }
+ if ( s->cur_file_info.compressed_size == pfile_in_zip_read_info->rest_read_compressed ) {
+ if ( fseek( pfile_in_zip_read_info->file,
+ pfile_in_zip_read_info->pos_in_zipfile +
+ pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET ) != 0 ) {
+ return UNZ_ERRNO;
+ }
+ }
+ if ( fread( pfile_in_zip_read_info->read_buffer,uReadThis,1,
+ pfile_in_zip_read_info->file ) != 1 ) {
+ return UNZ_ERRNO;
+ }
+ pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
+
+ pfile_in_zip_read_info->rest_read_compressed -= uReadThis;
+
+ pfile_in_zip_read_info->stream.next_in =
+ (Byte*)pfile_in_zip_read_info->read_buffer;
+ pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
+ }
+
+ if ( pfile_in_zip_read_info->compression_method == 0 ) {
+ uInt uDoCopy,i ;
+ if ( pfile_in_zip_read_info->stream.avail_out <
+ pfile_in_zip_read_info->stream.avail_in ) {
+ uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
+ }
+ else{
+ uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
+ }
+
+ for ( i = 0; i < uDoCopy; i++ )
+ *( pfile_in_zip_read_info->stream.next_out + i ) =
+ *( pfile_in_zip_read_info->stream.next_in + i );
+
+ pfile_in_zip_read_info->crc32 = crc32( pfile_in_zip_read_info->crc32,
+ pfile_in_zip_read_info->stream.next_out,
+ uDoCopy );
+ pfile_in_zip_read_info->rest_read_uncompressed -= uDoCopy;
+ pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
+ pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
+ pfile_in_zip_read_info->stream.next_out += uDoCopy;
+ pfile_in_zip_read_info->stream.next_in += uDoCopy;
+ pfile_in_zip_read_info->stream.total_out += uDoCopy;
+ iRead += uDoCopy;
+ }
+ else
+ {
+ uLong uTotalOutBefore,uTotalOutAfter;
+ const Byte *bufBefore;
+ uLong uOutThis;
+ int flush = Z_SYNC_FLUSH;
+
+ uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
+ bufBefore = pfile_in_zip_read_info->stream.next_out;
+
+ /*
+ if ((pfile_in_zip_read_info->rest_read_uncompressed ==
+ pfile_in_zip_read_info->stream.avail_out) &&
+ (pfile_in_zip_read_info->rest_read_compressed == 0))
+ flush = Z_FINISH;
+ */
+ err = inflate( &pfile_in_zip_read_info->stream,flush );
+
+ uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
+ uOutThis = uTotalOutAfter - uTotalOutBefore;
+
+ pfile_in_zip_read_info->crc32 =
+ crc32( pfile_in_zip_read_info->crc32,bufBefore,
+ (uInt)( uOutThis ) );
+
+ pfile_in_zip_read_info->rest_read_uncompressed -=
+ uOutThis;
+
+ iRead += (uInt)( uTotalOutAfter - uTotalOutBefore );
+
+ if ( err == Z_STREAM_END ) {
+ return ( iRead == 0 ) ? UNZ_EOF : iRead;
+ }
+ if ( err != Z_OK ) {
+ break;
+ }
+ }
+ }
+
+ if ( err == Z_OK ) {
+ return iRead;
+ }
+ return err;
+}
+
+
+/*
+ Give the current position in uncompressed data
+ */
+extern long unztell( unzFile file ){
+ unz_s* s;
+ file_in_zip_read_info_s* pfile_in_zip_read_info;
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ pfile_in_zip_read_info = s->pfile_in_zip_read;
+
+ if ( pfile_in_zip_read_info == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+
+ return (long)pfile_in_zip_read_info->stream.total_out;
+}
+
+
+/*
+ return 1 if the end of file was reached, 0 elsewhere
+ */
+extern int unzeof( unzFile file ){
+ unz_s* s;
+ file_in_zip_read_info_s* pfile_in_zip_read_info;
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ pfile_in_zip_read_info = s->pfile_in_zip_read;
+
+ if ( pfile_in_zip_read_info == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+
+ if ( pfile_in_zip_read_info->rest_read_uncompressed == 0 ) {
+ return 1;
+ }
+ else{
+ return 0;
+ }
+}
+
+
+
+/*
+ Read extra field from the current file (opened by unzOpenCurrentFile)
+ This is the static-header version of the extra field (sometimes, there is
+ more info in the static-header version than in the central-header)
+
+ if buf==NULL, it return the size of the static extra field that can be read
+
+ if buf!=NULL, len is the size of the buffer, the extra header is copied in
+ buf.
+ the return value is the number of bytes copied in buf, or (if <0)
+ the error code
+ */
+extern int unzGetLocalExtrafield( unzFile file,void *buf,unsigned len ){
+ unz_s* s;
+ file_in_zip_read_info_s* pfile_in_zip_read_info;
+ uInt read_now;
+ uLong size_to_read;
+
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ pfile_in_zip_read_info = s->pfile_in_zip_read;
+
+ if ( pfile_in_zip_read_info == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+
+ size_to_read = ( pfile_in_zip_read_info->size_local_extrafield -
+ pfile_in_zip_read_info->pos_local_extrafield );
+
+ if ( buf == NULL ) {
+ return (int)size_to_read;
+ }
+
+ if ( len > size_to_read ) {
+ read_now = (uInt)size_to_read;
+ }
+ else{
+ read_now = (uInt)len ;
+ }
+
+ if ( read_now == 0 ) {
+ return 0;
+ }
+
+ if ( fseek( pfile_in_zip_read_info->file,
+ pfile_in_zip_read_info->offset_local_extrafield +
+ pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET ) != 0 ) {
+ return UNZ_ERRNO;
+ }
+
+ if ( fread( buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file ) != 1 ) {
+ return UNZ_ERRNO;
+ }
+
+ return (int)read_now;
+}
+
+/*
+ Close the file in zip opened with unzipOpenCurrentFile
+ Return UNZ_CRCERROR if all the file was read but the CRC is not good
+ */
+extern int unzCloseCurrentFile( unzFile file ){
+ int err = UNZ_OK;
+
+ unz_s* s;
+ file_in_zip_read_info_s* pfile_in_zip_read_info;
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+ pfile_in_zip_read_info = s->pfile_in_zip_read;
+
+ if ( pfile_in_zip_read_info == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+
+
+ if ( pfile_in_zip_read_info->rest_read_uncompressed == 0 ) {
+ if ( pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait ) {
+ err = UNZ_CRCERROR;
+ }
+ }
+
+
+ free( pfile_in_zip_read_info->read_buffer );
+ pfile_in_zip_read_info->read_buffer = NULL;
+ if ( pfile_in_zip_read_info->stream_initialised ) {
+ inflateEnd( &pfile_in_zip_read_info->stream );
+ }
+
+ pfile_in_zip_read_info->stream_initialised = 0;
+ free( pfile_in_zip_read_info );
+
+ s->pfile_in_zip_read = NULL;
+
+ return err;
+}
+
+
+/*
+ Get the global comment string of the ZipFile, in the szComment buffer.
+ uSizeBuf is the size of the szComment buffer.
+ return the number of byte copied or an error code <0
+ */
+extern int unzGetGlobalComment( unzFile file, char *szComment, uLong uSizeBuf ){
+ unz_s* s;
+ uLong uReadThis ;
+ if ( file == NULL ) {
+ return UNZ_PARAMERROR;
+ }
+ s = (unz_s*)file;
+
+ uReadThis = uSizeBuf;
+ if ( uReadThis > s->gi.size_comment ) {
+ uReadThis = s->gi.size_comment;
+ }
+
+ if ( fseek( s->file,s->central_pos + 22,SEEK_SET ) != 0 ) {
+ return UNZ_ERRNO;
+ }
+
+ if ( uReadThis > 0 ) {
+ *szComment = '\0';
+ if ( fread( szComment,(uInt)uReadThis,1,s->file ) != 1 ) {
+ return UNZ_ERRNO;
+ }
+ }
+
+ if ( ( szComment != NULL ) && ( uSizeBuf > s->gi.size_comment ) ) {
+ *( szComment + s->gi.size_comment ) = '\0';
+ }
+ return (int)uReadThis;
+}
+
+/* crc32.c -- compute the CRC-32 of a data stream
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#ifdef DYNAMIC_CRC_TABLE
+
+static int crc_table_empty = 1;
+static uLong crc_table[256];
+static void make_crc_table OF( (void) );
+
+/*
+ Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
+ x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
+
+ Polynomials over GF(2) are represented in binary, one bit per coefficient,
+ with the lowest powers in the most significant bit. Then adding polynomials
+ is just exclusive-or, and multiplying a polynomial by x is a right shift by
+ one. If we call the above polynomial p, and represent a byte as the
+ polynomial q, also with the lowest power in the most significant bit (so the
+ byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
+ where a mod b means the remainder after dividing a by b.
+
+ This calculation is done using the shift-register method of multiplying and
+ taking the remainder. The register is initialized to zero, and for each
+ incoming bit, x^32 is added mod p to the register if the bit is a one (where
+ x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
+ x (which is shifting right by one and adding x^32 mod p if the bit shifted
+ out is a one). We start with the highest power (least significant bit) of
+ q and repeat for all eight bits of q.
+
+ The table is simply the CRC of all possible eight bit values. This is all
+ the information needed to generate CRC's on data a byte at a time for all
+ combinations of CRC register values and incoming bytes.
+ */
+static void make_crc_table(){
+ uLong c;
+ int n, k;
+ uLong poly; /* polynomial exclusive-or pattern */
+ /* terms of polynomial defining this crc (except x^32): */
+ static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
+
+ /* make exclusive-or pattern from polynomial (0xedb88320L) */
+ poly = 0L;
+ for ( n = 0; n < sizeof( p ) / sizeof( Byte ); n++ )
+ poly |= 1L << ( 31 - p[n] );
+
+ for ( n = 0; n < 256; n++ )
+ {
+ c = (uLong)n;
+ for ( k = 0; k < 8; k++ )
+ c = c & 1 ? poly ^ ( c >> 1 ) : c >> 1;
+ crc_table[n] = c;
+ }
+ crc_table_empty = 0;
+}
+#else
+/* ========================================================================
+ * Table of CRC-32's of all single-byte values (made by make_crc_table)
+ */
+static const uLong crc_table[256] = {
+ 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
+ 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
+ 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
+ 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
+ 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
+ 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
+ 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
+ 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
+ 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
+ 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
+ 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
+ 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
+ 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
+ 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
+ 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
+ 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
+ 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
+ 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
+ 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
+ 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
+ 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
+ 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
+ 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
+ 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
+ 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
+ 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
+ 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
+ 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
+ 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
+ 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
+ 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
+ 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
+ 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
+ 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
+ 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
+ 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
+ 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
+ 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
+ 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
+ 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
+ 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
+ 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
+ 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
+ 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
+ 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
+ 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
+ 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
+ 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
+ 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
+ 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
+ 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
+ 0x2d02ef8dL
+};
+#endif
+
+/* =========================================================================
+ * This function can be used by asm versions of crc32()
+ */
+const uLong * get_crc_table(){
+#ifdef DYNAMIC_CRC_TABLE
+ if ( crc_table_empty ) {
+ make_crc_table();
+ }
+#endif
+ return (const uLong *)crc_table;
+}
+
+/* ========================================================================= */
+#define DO1( buf ) crc = crc_table[( (int)crc ^ ( *buf++ ) ) & 0xff] ^ ( crc >> 8 );
+#define DO2( buf ) DO1( buf ); DO1( buf );
+#define DO4( buf ) DO2( buf ); DO2( buf );
+#define DO8( buf ) DO4( buf ); DO4( buf );
+
+/* ========================================================================= */
+uLong crc32( uLong crc, const Byte *buf, uInt len ){
+ if ( buf == Z_NULL ) {
+ return 0L;
+ }
+#ifdef DYNAMIC_CRC_TABLE
+ if ( crc_table_empty ) {
+ make_crc_table();
+ }
+#endif
+ crc = crc ^ 0xffffffffL;
+ while ( len >= 8 )
+ {
+ DO8( buf );
+ len -= 8;
+ }
+ if ( len ) {
+ do {
+ DO1( buf );
+ } while ( --len );
+ }
+ return crc ^ 0xffffffffL;
+}
+
+/* infblock.h -- header to use infblock.c
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+struct inflate_blocks_state;
+typedef struct inflate_blocks_state inflate_blocks_statef;
+
+extern inflate_blocks_statef * inflate_blocks_new OF( (
+ z_streamp z,
+ check_func c, /* check function */
+ uInt w ) ); /* window size */
+
+extern int inflate_blocks OF( (
+ inflate_blocks_statef *,
+ z_streamp,
+ int ) ); /* initial return code */
+
+extern void inflate_blocks_reset OF( (
+ inflate_blocks_statef *,
+ z_streamp,
+ uLong * ) ); /* check value on output */
+
+extern int inflate_blocks_free OF( (
+ inflate_blocks_statef *,
+ z_streamp ) );
+
+extern void inflate_set_dictionary OF( (
+ inflate_blocks_statef * s,
+ const Byte * d, /* dictionary */
+ uInt n ) ); /* dictionary length */
+
+extern int inflate_blocks_sync_point OF( (
+ inflate_blocks_statef * s ) );
+
+/* simplify the use of the inflate_huft type with some defines */
+#define exop word.what.Exop
+#define bits word.what.Bits
+
+/* Table for deflate from PKZIP's appnote.txt. */
+static const uInt border[] = { /* Order of the bit length code lengths */
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+};
+
+/* inftrees.h -- header to use inftrees.c
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* Huffman code lookup table entry--this entry is four bytes for machines
+ that have 16-bit pointers (e.g. PC's in the small or medium model). */
+
+typedef struct inflate_huft_s inflate_huft;
+
+struct inflate_huft_s {
+ union {
+ struct {
+ Byte Exop; /* number of extra bits or operation */
+ Byte Bits; /* number of bits in this code or subcode */
+ } what;
+ uInt pad; /* pad structure to a power of 2 (4 bytes for */
+ } word; /* 16-bit, 8 bytes for 32-bit int's) */
+ uInt base; /* literal, length base, distance base,
+ or table offset */
+};
+
+/* Maximum size of dynamic tree. The maximum found in a long but non-
+ exhaustive search was 1004 huft structures (850 for length/literals
+ and 154 for distances, the latter actually the result of an
+ exhaustive search). The actual maximum is not known, but the
+ value below is more than safe. */
+#define MANY 1440
+
+extern int inflate_trees_bits OF( (
+ uInt *, /* 19 code lengths */
+ uInt *, /* bits tree desired/actual depth */
+ inflate_huft * *, /* bits tree result */
+ inflate_huft *, /* space for trees */
+ z_streamp ) ); /* for messages */
+
+extern int inflate_trees_dynamic OF( (
+ uInt, /* number of literal/length codes */
+ uInt, /* number of distance codes */
+ uInt *, /* that many (total) code lengths */
+ uInt *, /* literal desired/actual bit depth */
+ uInt *, /* distance desired/actual bit depth */
+ inflate_huft * *, /* literal/length tree result */
+ inflate_huft * *, /* distance tree result */
+ inflate_huft *, /* space for trees */
+ z_streamp ) ); /* for messages */
+
+extern int inflate_trees_fixed OF( (
+ uInt *, /* literal desired/actual bit depth */
+ uInt *, /* distance desired/actual bit depth */
+ inflate_huft * *, /* literal/length tree result */
+ inflate_huft * *, /* distance tree result */
+ z_streamp ) ); /* for memory allocation */
+
+
+/* infcodes.h -- header to use infcodes.c
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+struct inflate_codes_state;
+typedef struct inflate_codes_state inflate_codes_statef;
+
+extern inflate_codes_statef *inflate_codes_new OF( (
+ uInt, uInt,
+ inflate_huft *, inflate_huft *,
+ z_streamp ) );
+
+extern int inflate_codes OF( (
+ inflate_blocks_statef *,
+ z_streamp,
+ int ) );
+
+extern void inflate_codes_free OF( (
+ inflate_codes_statef *,
+ z_streamp ) );
+
+/* infutil.h -- types and macros common to blocks and codes
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+#ifndef _INFUTIL_H
+#define _INFUTIL_H
+
+typedef enum {
+ TYPE, /* get type bits (3, including end bit) */
+ LENS, /* get lengths for stored */
+ STORED, /* processing stored block */
+ TABLE, /* get table lengths */
+ BTREE, /* get bit lengths tree for a dynamic block */
+ DTREE, /* get length, distance trees for a dynamic block */
+ CODES, /* processing fixed or dynamic block */
+ DRY, /* output remaining window bytes */
+ DONE, /* finished last block, done */
+ BAD
+} /* got a data error--stuck here */
+inflate_block_mode;
+
+/* inflate blocks semi-private state */
+struct inflate_blocks_state {
+
+ /* mode */
+ inflate_block_mode mode; /* current inflate_block mode */
+
+ /* mode dependent information */
+ union {
+ uInt left; /* if STORED, bytes left to copy */
+ struct {
+ uInt table; /* table lengths (14 bits) */
+ uInt index; /* index into blens (or border) */
+ uInt *blens; /* bit lengths of codes */
+ uInt bb; /* bit length tree depth */
+ inflate_huft *tb; /* bit length decoding tree */
+ } trees; /* if DTREE, decoding info for trees */
+ struct {
+ inflate_codes_statef
+ *codes;
+ } decode; /* if CODES, current state */
+ } sub; /* submode */
+ uInt last; /* true if this block is the last block */
+
+ /* mode independent information */
+ uInt bitk; /* bits in bit buffer */
+ uLong bitb; /* bit buffer */
+ inflate_huft *hufts; /* single malloc for tree space */
+ Byte *window; /* sliding window */
+ Byte *end; /* one byte after sliding window */
+ Byte *read; /* window read pointer */
+ Byte *write; /* window write pointer */
+ check_func checkfn; /* check function */
+ uLong check; /* check on output */
+
+};
+
+
+/* defines for inflate input/output */
+/* update pointers and return */
+#define UPDBITS {s->bitb = b; s->bitk = k; }
+#define UPDIN {z->avail_in = n; z->total_in += p - z->next_in; z->next_in = p; }
+#define UPDOUT {s->write = q; }
+#define UPDATE {UPDBITS UPDIN UPDOUT}
+#define LEAVE {UPDATE return inflate_flush( s,z,r ); }
+/* get bytes and bits */
+#define LOADIN {p = z->next_in; n = z->avail_in; b = s->bitb; k = s->bitk; }
+#define NEEDBYTE {if ( n ) {r = Z_OK; }else LEAVE}
+#define NEXTBYTE ( n--,*p++ )
+#define NEEDBITS( j ) {while ( k < ( j ) ) {NEEDBYTE; b |= ( (uLong)NEXTBYTE ) << k; k += 8; }}
+#define DUMPBITS( j ) {b >>= ( j ); k -= ( j ); }
+/* output bytes */
+#define WAVAIL (uInt)( q < s->read ? s->read - q - 1 : s->end - q )
+#define LOADOUT {q = s->write; m = (uInt)WAVAIL; }
+#define WRAP {if ( q == s->end && s->read != s->window ) {q = s->window; m = (uInt)WAVAIL; }}
+#define FLUSH {UPDOUT r = inflate_flush( s,z,r ); LOADOUT}
+#define NEEDOUT {if ( m == 0 ) {WRAP if ( m == 0 ) {FLUSH WRAP if ( m == 0 ) {LEAVE}} r = Z_OK; }}
+#define OUTBYTE( a ) {*q++ = (Byte)( a ); m--; }
+/* load static pointers */
+#define LOAD {LOADIN LOADOUT}
+
+/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
+extern uInt inflate_mask[17];
+
+/* copy as much as possible from the sliding window to the output area */
+extern int inflate_flush OF( (
+ inflate_blocks_statef *,
+ z_streamp,
+ int ) );
+
+#endif
+
+
+/*
+ Notes beyond the 1.93a appnote.txt:
+
+ 1. Distance pointers never point before the beginning of the output
+ stream.
+ 2. Distance pointers can point back across blocks, up to 32k away.
+ 3. There is an implied maximum of 7 bits for the bit length table and
+ 15 bits for the actual data.
+ 4. If only one code exists, then it is encoded using one bit. (Zero
+ would be more efficient, but perhaps a little confusing.) If two
+ codes exist, they are coded using one bit each (0 and 1).
+ 5. There is no way of sending zero distance codes--a dummy must be
+ sent if there are none. (History: a pre 2.0 version of PKZIP would
+ store blocks with no distance codes, but this was discovered to be
+ too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
+ zero distance codes, which is sent as one code of zero bits in
+ length.
+ 6. There are up to 286 literal/length codes. Code 256 represents the
+ end-of-block. Note however that the static length tree defines
+ 288 codes just to fill out the Huffman codes. Codes 286 and 287
+ cannot be used though, since there is no length base or extra bits
+ defined for them. Similarily, there are up to 30 distance codes.
+ However, static trees define 32 codes (all 5 bits) to fill out the
+ Huffman codes, but the last two had better not show up in the data.
+ 7. Unzip can check dynamic Huffman blocks for complete code sets.
+ The exception is that a single code would not be complete (see #4).
+ 8. The five bits following the block type is really the number of
+ literal codes sent minus 257.
+ 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
+ (1+6+6). Therefore, to output three times the length, you output
+ three codes (1+1+1), whereas to output four times the same length,
+ you only need two codes (1+3). Hmm.
+ 10. In the tree reconstruction algorithm, Code = Code + Increment
+ only if BitLength(i) is not zero. (Pretty obvious.)
+ 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
+ 12. Note: length code 284 can represent 227-258, but length code 285
+ really is 258. The last length deserves its own, short code
+ since it gets used a lot in very redundant files. The length
+ 258 is special since 258 - 3 (the min match length) is 255.
+ 13. The literal/length and distance code bit lengths are read as a
+ single stream of lengths. It is possible (and advantageous) for
+ a repeat code (16, 17, or 18) to go across the boundary between
+ the two sets of lengths.
+ */
+
+
+void inflate_blocks_reset( inflate_blocks_statef *s, z_streamp z, uLong *c ){
+ if ( c != Z_NULL ) {
+ *c = s->check;
+ }
+ if ( s->mode == BTREE || s->mode == DTREE ) {
+ ZFREE( z, s->sub.trees.blens );
+ }
+ if ( s->mode == CODES ) {
+ inflate_codes_free( s->sub.decode.codes, z );
+ }
+ s->mode = TYPE;
+ s->bitk = 0;
+ s->bitb = 0;
+ s->read = s->write = s->window;
+ if ( s->checkfn != Z_NULL ) {
+ z->adler = s->check = ( *s->checkfn )( 0L, (const Byte *)Z_NULL, 0 );
+ }
+ Tracev( ( "inflate: blocks reset\n" ) );
+}
+
+
+inflate_blocks_statef *inflate_blocks_new( z_streamp z, check_func c, uInt w ){
+ inflate_blocks_statef *s;
+
+ if ( ( s = (inflate_blocks_statef *)ZALLOC
+ ( z,1,sizeof( struct inflate_blocks_state ) ) ) == Z_NULL ) {
+ return s;
+ }
+ if ( ( s->hufts =
+ (inflate_huft *)ZALLOC( z, sizeof( inflate_huft ), MANY ) ) == Z_NULL ) {
+ ZFREE( z, s );
+ return Z_NULL;
+ }
+ if ( ( s->window = (Byte *)ZALLOC( z, 1, w ) ) == Z_NULL ) {
+ ZFREE( z, s->hufts );
+ ZFREE( z, s );
+ return Z_NULL;
+ }
+ s->end = s->window + w;
+ s->checkfn = c;
+ s->mode = TYPE;
+ Tracev( ( "inflate: blocks allocated\n" ) );
+ inflate_blocks_reset( s, z, Z_NULL );
+ return s;
+}
+
+
+int inflate_blocks( inflate_blocks_statef *s, z_streamp z, int r ){
+ uInt t; /* temporary storage */
+ uLong b; /* bit buffer */
+ uInt k; /* bits in bit buffer */
+ Byte *p; /* input data pointer */
+ uInt n; /* bytes available there */
+ Byte *q; /* output window write pointer */
+ uInt m; /* bytes to end of window or read pointer */
+
+ /* copy input/output information to locals (UPDATE macro restores) */
+ LOAD
+
+ /* process input based on current state */
+ while ( 1 ) switch ( s->mode )
+ {
+ case TYPE:
+ NEEDBITS( 3 )
+ t = (uInt)b & 7;
+ s->last = t & 1;
+ switch ( t >> 1 )
+ {
+ case 0: /* stored */
+ Tracev( ( "inflate: stored block%s\n",
+ s->last ? " (last)" : "" ) );
+ DUMPBITS( 3 )
+ t = k & 7; /* go to byte boundary */
+ DUMPBITS( t )
+ s->mode = LENS; /* get length of stored block */
+ break;
+ case 1: /* fixed */
+ Tracev( ( "inflate: fixed codes block%s\n",
+ s->last ? " (last)" : "" ) );
+ {
+ uInt bl, bd;
+ inflate_huft *tl, *td;
+
+ inflate_trees_fixed( &bl, &bd, &tl, &td, z );
+ s->sub.decode.codes = inflate_codes_new( bl, bd, tl, td, z );
+ if ( s->sub.decode.codes == Z_NULL ) {
+ r = Z_MEM_ERROR;
+ LEAVE
+ }
+ }
+ DUMPBITS( 3 )
+ s->mode = CODES;
+ break;
+ case 2: /* dynamic */
+ Tracev( ( "inflate: dynamic codes block%s\n",
+ s->last ? " (last)" : "" ) );
+ DUMPBITS( 3 )
+ s->mode = TABLE;
+ break;
+ case 3: /* illegal */
+ DUMPBITS( 3 )
+ s->mode = BAD;
+ z->msg = (char*)"invalid block type";
+ r = Z_DATA_ERROR;
+ LEAVE
+ }
+ break;
+ case LENS:
+ NEEDBITS( 32 )
+ if ( ( ( ( ~b ) >> 16 ) & 0xffff ) != ( b & 0xffff ) ) {
+ s->mode = BAD;
+ z->msg = (char*)"invalid stored block lengths";
+ r = Z_DATA_ERROR;
+ LEAVE
+ }
+ s->sub.left = (uInt)b & 0xffff;
+ b = k = 0; /* dump bits */
+ Tracev( ( "inflate: stored length %u\n", s->sub.left ) );
+ s->mode = s->sub.left ? STORED : ( s->last ? DRY : TYPE );
+ break;
+ case STORED:
+ if ( n == 0 ) {
+ LEAVE
+ NEEDOUT
+ t = s->sub.left;
+ }
+ if ( t > n ) {
+ t = n;
+ }
+ if ( t > m ) {
+ t = m;
+ }
+ zmemcpy( q, p, t );
+ p += t; n -= t;
+ q += t; m -= t;
+ if ( ( s->sub.left -= t ) != 0 ) {
+ break;
+ }
+ Tracev( ( "inflate: stored end, %lu total out\n",
+ z->total_out + ( q >= s->read ? q - s->read :
+ ( s->end - s->read ) + ( q - s->window ) ) ) );
+ s->mode = s->last ? DRY : TYPE;
+ break;
+ case TABLE:
+ NEEDBITS( 14 )
+ s->sub.trees.table = t = (uInt)b & 0x3fff;
+#ifndef PKZIP_BUG_WORKAROUND
+ if ( ( t & 0x1f ) > 29 || ( ( t >> 5 ) & 0x1f ) > 29 ) {
+ s->mode = BAD;
+ z->msg = (char*)"too many length or distance symbols";
+ r = Z_DATA_ERROR;
+ LEAVE
+ }
+#endif
+ t = 258 + ( t & 0x1f ) + ( ( t >> 5 ) & 0x1f );
+ if ( ( s->sub.trees.blens = (uInt*)ZALLOC( z, t, sizeof( uInt ) ) ) == Z_NULL ) {
+ r = Z_MEM_ERROR;
+ LEAVE
+ }
+ DUMPBITS( 14 )
+ s->sub.trees.index = 0;
+ Tracev( ( "inflate: table sizes ok\n" ) );
+ s->mode = BTREE;
+ case BTREE:
+ while ( s->sub.trees.index < 4 + ( s->sub.trees.table >> 10 ) )
+ {
+ NEEDBITS( 3 )
+ s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
+ DUMPBITS( 3 )
+ }
+ while ( s->sub.trees.index < 19 )
+ s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
+ s->sub.trees.bb = 7;
+ t = inflate_trees_bits( s->sub.trees.blens, &s->sub.trees.bb,
+ &s->sub.trees.tb, s->hufts, z );
+ if ( t != Z_OK ) {
+ ZFREE( z, s->sub.trees.blens );
+ r = t;
+ if ( r == Z_DATA_ERROR ) {
+ s->mode = BAD;
+ }
+ LEAVE
+ }
+ s->sub.trees.index = 0;
+ Tracev( ( "inflate: bits tree ok\n" ) );
+ s->mode = DTREE;
+ case DTREE:
+ while ( t = s->sub.trees.table,
+ s->sub.trees.index < 258 + ( t & 0x1f ) + ( ( t >> 5 ) & 0x1f ) )
+ {
+ inflate_huft *h;
+ uInt i, j, c;
+
+ t = s->sub.trees.bb;
+ NEEDBITS( t )
+ h = s->sub.trees.tb + ( (uInt)b & inflate_mask[t] );
+ t = h->bits;
+ c = h->base;
+ if ( c < 16 ) {
+ DUMPBITS( t )
+ s->sub.trees.blens[s->sub.trees.index++] = c;
+ }
+ else /* c == 16..18 */
+ {
+ i = c == 18 ? 7 : c - 14;
+ j = c == 18 ? 11 : 3;
+ NEEDBITS( t + i )
+ DUMPBITS( t )
+ j += (uInt)b & inflate_mask[i];
+ DUMPBITS( i )
+ i = s->sub.trees.index;
+ t = s->sub.trees.table;
+ if ( i + j > 258 + ( t & 0x1f ) + ( ( t >> 5 ) & 0x1f ) ||
+ ( c == 16 && i < 1 ) ) {
+ ZFREE( z, s->sub.trees.blens );
+ s->mode = BAD;
+ z->msg = (char*)"invalid bit length repeat";
+ r = Z_DATA_ERROR;
+ LEAVE
+ }
+ c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
+ do {
+ s->sub.trees.blens[i++] = c;
+ } while ( --j );
+ s->sub.trees.index = i;
+ }
+ }
+ s->sub.trees.tb = Z_NULL;
+ {
+ uInt bl, bd;
+ inflate_huft *tl, *td;
+ inflate_codes_statef *c;
+
+ bl = 9; /* must be <= 9 for lookahead assumptions */
+ bd = 6; /* must be <= 9 for lookahead assumptions */
+ t = s->sub.trees.table;
+ t = inflate_trees_dynamic( 257 + ( t & 0x1f ), 1 + ( ( t >> 5 ) & 0x1f ),
+ s->sub.trees.blens, &bl, &bd, &tl, &td,
+ s->hufts, z );
+ ZFREE( z, s->sub.trees.blens );
+ if ( t != Z_OK ) {
+ if ( t == (uInt)Z_DATA_ERROR ) {
+ s->mode = BAD;
+ }
+ r = t;
+ LEAVE
+ }
+ Tracev( ( "inflate: trees ok\n" ) );
+ if ( ( c = inflate_codes_new( bl, bd, tl, td, z ) ) == Z_NULL ) {
+ r = Z_MEM_ERROR;
+ LEAVE
+ }
+ s->sub.decode.codes = c;
+ }
+ s->mode = CODES;
+ case CODES:
+ UPDATE
+ if ( ( r = inflate_codes( s, z, r ) ) != Z_STREAM_END ) {
+ return inflate_flush( s, z, r );
+ }
+ r = Z_OK;
+ inflate_codes_free( s->sub.decode.codes, z );
+ LOAD
+ Tracev( ( "inflate: codes end, %lu total out\n",
+ z->total_out + ( q >= s->read ? q - s->read :
+ ( s->end - s->read ) + ( q - s->window ) ) ) );
+ if ( !s->last ) {
+ s->mode = TYPE;
+ break;
+ }
+ s->mode = DRY;
+ case DRY:
+ FLUSH
+ if ( s->read != s->write ) {
+ LEAVE
+ s->mode = DONE;
+ }
+ case DONE:
+ r = Z_STREAM_END;
+ LEAVE
+ case BAD:
+ r = Z_DATA_ERROR;
+ LEAVE
+ default:
+ r = Z_STREAM_ERROR;
+ LEAVE
+ }
+}
+
+
+int inflate_blocks_free( inflate_blocks_statef *s, z_streamp z ){
+ inflate_blocks_reset( s, z, Z_NULL );
+ ZFREE( z, s->window );
+ ZFREE( z, s->hufts );
+ ZFREE( z, s );
+ Tracev( ( "inflate: blocks freed\n" ) );
+ return Z_OK;
+}
+
+
+void inflate_set_dictionary( inflate_blocks_statef *s, const Byte *d, uInt n ){
+ zmemcpy( s->window, d, n );
+ s->read = s->write = s->window + n;
+}
+
+
+/* Returns true if inflate is currently at the end of a block generated
+ * by Z_SYNC_FLUSH or Z_FULL_FLUSH.
+ * IN assertion: s != Z_NULL
+ */
+int inflate_blocks_sync_point( inflate_blocks_statef *s ){
+ return s->mode == LENS;
+}
+
+/* And'ing with mask[n] masks the lower n bits */
+uInt inflate_mask[17] = {
+ 0x0000,
+ 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
+ 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
+};
+
+/* copy as much as possible from the sliding window to the output area */
+int inflate_flush( inflate_blocks_statef *s, z_streamp z, int r ){
+ uInt n;
+ Byte *p;
+ Byte *q;
+
+ /* static copies of source and destination pointers */
+ p = z->next_out;
+ q = s->read;
+
+ /* compute number of bytes to copy as as end of window */
+ n = (uInt)( ( q <= s->write ? s->write : s->end ) - q );
+ if ( n > z->avail_out ) {
+ n = z->avail_out;
+ }
+ if ( n && r == Z_BUF_ERROR ) {
+ r = Z_OK;
+ }
+
+ /* update counters */
+ z->avail_out -= n;
+ z->total_out += n;
+
+ /* update check information */
+ if ( s->checkfn != Z_NULL ) {
+ z->adler = s->check = ( *s->checkfn )( s->check, q, n );
+ }
+
+ /* copy as as end of window */
+ zmemcpy( p, q, n );
+ p += n;
+ q += n;
+
+ /* see if more to copy at beginning of window */
+ if ( q == s->end ) {
+ /* wrap pointers */
+ q = s->window;
+ if ( s->write == s->end ) {
+ s->write = s->window;
+ }
+
+ /* compute bytes to copy */
+ n = (uInt)( s->write - q );
+ if ( n > z->avail_out ) {
+ n = z->avail_out;
+ }
+ if ( n && r == Z_BUF_ERROR ) {
+ r = Z_OK;
+ }
+
+ /* update counters */
+ z->avail_out -= n;
+ z->total_out += n;
+
+ /* update check information */
+ if ( s->checkfn != Z_NULL ) {
+ z->adler = s->check = ( *s->checkfn )( s->check, q, n );
+ }
+
+ /* copy */
+ zmemcpy( p, q, n );
+ p += n;
+ q += n;
+ }
+
+ /* update pointers */
+ z->next_out = p;
+ s->read = q;
+
+ /* done */
+ return r;
+}
+
+/* inftrees.c -- generate Huffman trees for efficient decoding
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+const char inflate_copyright[] =
+ " inflate 1.1.3 Copyright 1995-1998 Mark Adler ";
+/*
+ If you use the zlib library in a product, an acknowledgment is welcome
+ in the documentation of your product. If for some reason you cannot
+ include such an acknowledgment, I would appreciate that you keep this
+ copyright string in the executable of your product.
+ */
+
+/* simplify the use of the inflate_huft type with some defines */
+#define exop word.what.Exop
+#define bits word.what.Bits
+
+
+static int huft_build OF( (
+ uInt *, /* code lengths in bits */
+ uInt, /* number of codes */
+ uInt, /* number of "simple" codes */
+ const uInt *, /* list of base values for non-simple codes */
+ const uInt *, /* list of extra bits for non-simple codes */
+ inflate_huft * *, /* result: starting table */
+ uInt *, /* maximum lookup bits (returns actual) */
+ inflate_huft *, /* space for trees */
+ uInt *, /* hufts used in space */
+ uInt * ) ); /* space for values */
+
+/* Tables for deflate from PKZIP's appnote.txt. */
+static const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
+ 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
+};
+/* see note #13 above about 258 */
+static const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
+ 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, 112, 112
+}; /* 112==invalid */
+static const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
+ 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
+};
+static const uInt cpdext[30] = { /* Extra bits for distance codes */
+ 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
+};
+
+/*
+ Huffman code decoding is performed using a multi-level table lookup.
+ The fastest way to decode is to simply build a lookup table whose
+ size is determined by the longest code. However, the time it takes
+ to build this table can also be a factor if the data being decoded
+ is not very long. The most common codes are necessarily the
+ shortest codes, so those codes dominate the decoding time, and hence
+ the speed. The idea is you can have a shorter table that decodes the
+ shorter, more probable codes, and then point to subsidiary tables for
+ the longer codes. The time it costs to decode the longer codes is
+ then traded against the time it takes to make longer tables.
+
+ This results of this trade are in the variables lbits and dbits
+ below. lbits is the number of bits the first level table for literal/
+ length codes can decode in one step, and dbits is the same thing for
+ the distance codes. Subsequent tables are also less than or equal to
+ those sizes. These values may be adjusted either when all of the
+ codes are shorter than that, in which case the longest code length in
+ bits is used, or when the shortest code is *longer* than the requested
+ table size, in which case the length of the shortest code in bits is
+ used.
+
+ There are two different values for the two tables, since they code a
+ different number of possibilities each. The literal/length table
+ codes 286 possible values, or in a flat code, a little over eight
+ bits. The distance table codes 30 possible values, or a little less
+ than five bits, flat. The optimum values for speed end up being
+ about one bit more than those, so lbits is 8+1 and dbits is 5+1.
+ The optimum values may differ though from machine to machine, and
+ possibly even between compilers. Your mileage may vary.
+ */
+
+
+/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
+#define BMAX 15 /* maximum bit length of any code */
+
+static int huft_build( uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inflate_huft ** t, uInt *m, inflate_huft *hp, uInt *hn, uInt *v ){
+//uInt *b; /* code lengths in bits (all assumed <= BMAX) */
+//uInt n; /* number of codes (assumed <= 288) */
+//uInt s; /* number of simple-valued codes (0..s-1) */
+//const uInt *d; /* list of base values for non-simple codes */
+//const uInt *e; /* list of extra bits for non-simple codes */
+//inflate_huft ** t; /* result: starting table */
+//uInt *m; /* maximum lookup bits, returns actual */
+//inflate_huft *hp; /* space for trees */
+//uInt *hn; /* hufts used in space */
+//uInt *v; /* working area: values in order of bit length */
+/* Given a list of code lengths and a maximum table size, make a set of
+ tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
+ if the given code set is incomplete (the tables are still built in this
+ case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
+ lengths), or Z_MEM_ERROR if not enough memory. */
+
+ uInt a; /* counter for codes of length k */
+ uInt c[BMAX + 1]; /* bit length count table */
+ uInt f; /* i repeats in table every f entries */
+ int g; /* maximum code length */
+ int h; /* table level */
+ register uInt i; /* counter, current code */
+ register uInt j; /* counter */
+ register int k; /* number of bits in current code */
+ int l; /* bits per table (returned in m) */
+ uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
+ register uInt *p; /* pointer into c[], b[], or v[] */
+ inflate_huft *q; /* points to current table */
+ struct inflate_huft_s r; /* table entry for structure assignment */
+ inflate_huft *u[BMAX]; /* table stack */
+ register int w; /* bits before this table == (l * h) */
+ uInt x[BMAX + 1]; /* bit offsets, then code stack */
+ uInt *xp; /* pointer into x */
+ int y; /* number of dummy codes added */
+ uInt z; /* number of entries in current table */
+
+
+ /* Generate counts for each bit length */
+ p = c;
+#define C0 *p++ = 0;
+#define C2 C0 C0 C0 C0
+#define C4 C2 C2 C2 C2
+ C4 /* clear c[]--assume BMAX+1 is 16 */
+ p = b; i = n;
+ do {
+ c[*p++]++; /* assume all entries <= BMAX */
+ } while ( --i );
+ if ( c[0] == n ) { /* null input--all zero length codes */
+ *t = (inflate_huft *)Z_NULL;
+ *m = 0;
+ return Z_OK;
+ }
+
+
+ /* Find minimum and maximum length, bound *m by those */
+ l = *m;
+ for ( j = 1; j <= BMAX; j++ )
+ if ( c[j] ) {
+ break;
+ }
+ k = j; /* minimum code length */
+ if ( (uInt)l < j ) {
+ l = j;
+ }
+ for ( i = BMAX; i; i-- )
+ if ( c[i] ) {
+ break;
+ }
+ g = i; /* maximum code length */
+ if ( (uInt)l > i ) {
+ l = i;
+ }
+ *m = l;
+
+
+ /* Adjust last length count to fill out codes, if needed */
+ for ( y = 1 << j; j < i; j++, y <<= 1 )
+ if ( ( y -= c[j] ) < 0 ) {
+ return Z_DATA_ERROR;
+ }
+ if ( ( y -= c[i] ) < 0 ) {
+ return Z_DATA_ERROR;
+ }
+ c[i] += y;
+
+
+ /* Generate starting offsets into the value table for each length */
+ x[1] = j = 0;
+ p = c + 1; xp = x + 2;
+ while ( --i ) { /* note that i == g from above */
+ *xp++ = ( j += *p++ );
+ }
+
+
+ /* Make a table of values in order of bit lengths */
+ p = b; i = 0;
+ do {
+ if ( ( j = *p++ ) != 0 ) {
+ v[x[j]++] = i;
+ }
+ } while ( ++i < n );
+ n = x[g]; /* set n to length of v */
+
+
+ /* Generate the Huffman codes and for each, make the table entries */
+ x[0] = i = 0; /* first Huffman code is zero */
+ p = v; /* grab values in bit order */
+ h = -1; /* no tables yet--level -1 */
+ w = -l; /* bits decoded == (l * h) */
+ u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
+ q = (inflate_huft *)Z_NULL; /* ditto */
+ z = 0; /* ditto */
+
+ /* go through the bit lengths (k already is bits in shortest code) */
+ for (; k <= g; k++ )
+ {
+ a = c[k];
+ while ( a-- )
+ {
+ /* here i is the Huffman code of length k bits for value *p */
+ /* make tables up to required level */
+ while ( k > w + l )
+ {
+ h++;
+ w += l; /* previous table always l bits */
+
+ /* compute minimum size table less than or equal to l bits */
+ z = g - w;
+ z = z > (uInt)l ? l : z; /* table size upper limit */
+ if ( ( f = 1 << ( j = k - w ) ) > a + 1 ) { /* try a k-w bit table */
+ /* too few codes for k-w bit table */
+ f -= a + 1; /* deduct codes from patterns left */
+ xp = c + k;
+ if ( j < z ) {
+ while ( ++j < z ) /* try smaller tables up to z bits */
+ {
+ if ( ( f <<= 1 ) <= *++xp ) {
+ break; /* enough codes to use up j bits */
+ }
+ f -= *xp; /* else deduct codes from patterns */
+ }
+ }
+ }
+ z = 1 << j; /* table entries for j-bit table */
+
+ /* allocate new table */
+ if ( *hn + z > MANY ) { /* (note: doesn't matter for fixed) */
+ return Z_MEM_ERROR; /* not enough memory */
+ }
+ u[h] = q = hp + *hn;
+ *hn += z;
+
+ /* connect to last table, if there is one */
+ if ( h ) {
+ x[h] = i; /* save pattern for backing up */
+ r.bits = (Byte)l; /* bits to dump before this table */
+ r.exop = (Byte)j; /* bits in this table */
+ j = i >> ( w - l );
+ r.base = (uInt)( q - u[h - 1] - j ); /* offset to this table */
+ u[h - 1][j] = r; /* connect to last table */
+ }
+ else{
+ *t = q; /* first table is returned result */
+ }
+ }
+
+ /* set up table entry in r */
+ r.bits = (Byte)( k - w );
+ if ( p >= v + n ) {
+ r.exop = 128 + 64; /* out of values--invalid code */
+ }
+ else if ( *p < s ) {
+ r.exop = (Byte)( *p < 256 ? 0 : 32 + 64 ); /* 256 is end-of-block */
+ r.base = *p++; /* simple code is just the value */
+ }
+ else
+ {
+ r.exop = (Byte)( e[*p - s] + 16 + 64 ); /* non-simple--look up in lists */
+ r.base = d[*p++ - s];
+ }
+
+ /* fill code-like entries with r */
+ f = 1 << ( k - w );
+ for ( j = i >> w; j < z; j += f )
+ q[j] = r;
+
+ /* backwards increment the k-bit code i */
+ for ( j = 1 << ( k - 1 ); i &j; j >>= 1 )
+ i ^= j;
+ i ^= j;
+
+ /* backup over finished tables */
+ mask = ( 1 << w ) - 1; /* needed on HP, cc -O bug */
+ while ( ( i & mask ) != x[h] )
+ {
+ h--; /* don't need to update q */
+ w -= l;
+ mask = ( 1 << w ) - 1;
+ }
+ }
+ }
+
+
+ /* Return Z_BUF_ERROR if we were given an incomplete table */
+ return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
+}
+
+
+int inflate_trees_bits( uInt *c, uInt *bb, inflate_huft * *tb, inflate_huft *hp, z_streamp z ){
+//uInt *c; /* 19 code lengths */
+//uInt *bb; /* bits tree desired/actual depth */
+//inflate_huft * *tb; /* bits tree result */
+//inflate_huft *hp; /* space for trees */
+//z_streamp z; /* for messages */
+ int r;
+ uInt hn = 0; /* hufts used in space */
+ uInt *v; /* work area for huft_build */
+
+ if ( ( v = (uInt*)ZALLOC( z, 19, sizeof( uInt ) ) ) == Z_NULL ) {
+ return Z_MEM_ERROR;
+ }
+ r = huft_build( c, 19, 19, (uInt*)Z_NULL, (uInt*)Z_NULL,
+ tb, bb, hp, &hn, v );
+ if ( r == Z_DATA_ERROR ) {
+ z->msg = (char*)"oversubscribed dynamic bit lengths tree";
+ }
+ else if ( r == Z_BUF_ERROR || *bb == 0 ) {
+ z->msg = (char*)"incomplete dynamic bit lengths tree";
+ r = Z_DATA_ERROR;
+ }
+ ZFREE( z, v );
+ return r;
+}
+
+
+int inflate_trees_dynamic( uInt nl, uInt nd, uInt *c, uInt *bl, uInt *bd, inflate_huft * *tl, inflate_huft * *td, inflate_huft *hp, z_streamp z ){
+//uInt nl; /* number of literal/length codes */
+//uInt nd; /* number of distance codes */
+//uInt *c; /* that many (total) code lengths */
+//uInt *bl; /* literal desired/actual bit depth */
+//uInt *bd; /* distance desired/actual bit depth */
+//inflate_huft * *tl; /* literal/length tree result */
+//inflate_huft * *td; /* distance tree result */
+//inflate_huft *hp; /* space for trees */
+//z_streamp z; /* for messages */
+ int r;
+ uInt hn = 0; /* hufts used in space */
+ uInt *v; /* work area for huft_build */
+
+ /* allocate work area */
+ if ( ( v = (uInt*)ZALLOC( z, 288, sizeof( uInt ) ) ) == Z_NULL ) {
+ return Z_MEM_ERROR;
+ }
+
+ /* build literal/length tree */
+ r = huft_build( c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v );
+ if ( r != Z_OK || *bl == 0 ) {
+ if ( r == Z_DATA_ERROR ) {
+ z->msg = (char*)"oversubscribed literal/length tree";
+ }
+ else if ( r != Z_MEM_ERROR ) {
+ z->msg = (char*)"incomplete literal/length tree";
+ r = Z_DATA_ERROR;
+ }
+ ZFREE( z, v );
+ return r;
+ }
+
+ /* build distance tree */
+ r = huft_build( c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v );
+ if ( r != Z_OK || ( *bd == 0 && nl > 257 ) ) {
+ if ( r == Z_DATA_ERROR ) {
+ z->msg = (char*)"oversubscribed distance tree";
+ }
+ else if ( r == Z_BUF_ERROR ) {
+#ifdef PKZIP_BUG_WORKAROUND
+ r = Z_OK;
+ }
+#else
+ z->msg = (char*)"incomplete distance tree";
+ r = Z_DATA_ERROR;
+ }
+ else if ( r != Z_MEM_ERROR ) {
+ z->msg = (char*)"empty distance tree with lengths";
+ r = Z_DATA_ERROR;
+ }
+ ZFREE( z, v );
+ return r;
+#endif
+ }
+
+ /* done */
+ ZFREE( z, v );
+ return Z_OK;
+}
+
+/* inffixed.h -- table for decoding fixed codes
+ * Generated automatically by the maketree.c program
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+static uInt fixed_bl = 9;
+static uInt fixed_bd = 5;
+static inflate_huft fixed_tl[] = {
+ {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
+ {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
+ {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
+ {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},
+ {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},
+ {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},
+ {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},
+ {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},
+ {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
+ {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},
+ {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},
+ {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},
+ {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},
+ {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},
+ {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},
+ {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},
+ {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
+ {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},
+ {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},
+ {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},
+ {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},
+ {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},
+ {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},
+ {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},
+ {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
+ {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},
+ {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},
+ {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},
+ {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},
+ {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},
+ {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},
+ {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},
+ {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
+ {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},
+ {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},
+ {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},
+ {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},
+ {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},
+ {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},
+ {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},
+ {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
+ {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},
+ {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},
+ {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},
+ {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},
+ {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},
+ {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},
+ {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},
+ {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
+ {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},
+ {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},
+ {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},
+ {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},
+ {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},
+ {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},
+ {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},
+ {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
+ {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},
+ {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},
+ {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},
+ {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},
+ {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},
+ {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},
+ {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},
+ {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
+ {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},
+ {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},
+ {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},
+ {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},
+ {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},
+ {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},
+ {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},
+ {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
+ {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},
+ {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},
+ {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},
+ {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},
+ {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},
+ {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},
+ {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},
+ {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
+ {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},
+ {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},
+ {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},
+ {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},
+ {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},
+ {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},
+ {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},
+ {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
+ {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},
+ {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},
+ {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},
+ {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},
+ {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},
+ {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},
+ {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},
+ {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
+ {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},
+ {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},
+ {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},
+ {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},
+ {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},
+ {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},
+ {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},
+ {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
+ {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},
+ {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},
+ {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},
+ {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},
+ {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},
+ {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},
+ {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},
+ {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
+ {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},
+ {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},
+ {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},
+ {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},
+ {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},
+ {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},
+ {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},
+ {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
+ {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},
+ {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},
+ {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},
+ {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},
+ {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},
+ {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
+ {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
+};
+static inflate_huft fixed_td[] = {
+ {{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
+ {{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
+ {{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
+ {{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},
+ {{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},
+ {{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},
+ {{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},
+ {{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}
+};
+
+int inflate_trees_fixed( uInt *bl, uInt *bd, inflate_huft * *tl, inflate_huft * *td, z_streamp z ){
+//uInt *bl; /* literal desired/actual bit depth */
+//uInt *bd; /* distance desired/actual bit depth */
+//inflate_huft * *tl; /* literal/length tree result */
+//inflate_huft * *td; /* distance tree result */
+//z_streamp z; /* for memory allocation */
+ *bl = fixed_bl;
+ *bd = fixed_bd;
+ *tl = fixed_tl;
+ *td = fixed_td;
+ return Z_OK;
+}
+
+/* simplify the use of the inflate_huft type with some defines */
+#define exop word.what.Exop
+#define bits word.what.Bits
+
+/* macros for bit input with no checking and for returning unused bytes */
+#define GRABBITS( j ) {while ( k < ( j ) ) {b |= ( (uLong)NEXTBYTE ) << k; k += 8; }}
+#define UNGRAB {c = z->avail_in - n; c = ( k >> 3 ) < c ? k >> 3 : c; n += c; p -= c; k -= c << 3; }
+
+/* Called with number of bytes left to write in window at least 258
+ (the maximum string length) and number of input bytes available
+ at least ten. The ten bytes are six bytes for the longest length/
+ distance pair plus four bytes for overloading the bit buffer. */
+
+int inflate_fast( uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, inflate_blocks_statef *s, z_streamp z ){
+ inflate_huft *t; /* temporary pointer */
+ uInt e; /* extra bits or operation */
+ uLong b; /* bit buffer */
+ uInt k; /* bits in bit buffer */
+ Byte *p; /* input data pointer */
+ uInt n; /* bytes available there */
+ Byte *q; /* output window write pointer */
+ uInt m; /* bytes to end of window or read pointer */
+ uInt ml; /* mask for literal/length tree */
+ uInt md; /* mask for distance tree */
+ uInt c; /* bytes to copy */
+ uInt d; /* distance back to copy from */
+ Byte *r; /* copy source pointer */
+
+ /* load input, output, bit values */
+ LOAD
+
+ /* initialize masks */
+ ml = inflate_mask[bl];
+ md = inflate_mask[bd];
+
+ /* do until not enough input or output space for fast loop */
+ do { /* assume called with m >= 258 && n >= 10 */
+ /* get literal/length code */
+ GRABBITS( 20 ) /* max bits for literal/length code */
+ if ( ( e = ( t = tl + ( (uInt)b & ml ) )->exop ) == 0 ) {
+ DUMPBITS( t->bits )
+ Tracevv( ( t->base >= 0x20 && t->base < 0x7f ?
+ "inflate: * literal '%c'\n" :
+ "inflate: * literal 0x%02x\n", t->base ) );
+ *q++ = (Byte)t->base;
+ m--;
+ continue;
+ }
+ do {
+ DUMPBITS( t->bits )
+ if ( e & 16 ) {
+ /* get extra bits for length */
+ e &= 15;
+ c = t->base + ( (uInt)b & inflate_mask[e] );
+ DUMPBITS( e )
+ Tracevv( ( "inflate: * length %u\n", c ) );
+
+ /* decode distance base of block to copy */
+ GRABBITS( 15 ); /* max bits for distance code */
+ e = ( t = td + ( (uInt)b & md ) )->exop;
+ do {
+ DUMPBITS( t->bits )
+ if ( e & 16 ) {
+ /* get extra bits to add to distance base */
+ e &= 15;
+ GRABBITS( e ) /* get extra bits (up to 13) */
+ d = t->base + ( (uInt)b & inflate_mask[e] );
+ DUMPBITS( e )
+ Tracevv( ( "inflate: * distance %u\n", d ) );
+
+ /* do the copy */
+ m -= c;
+ if ( (uInt)( q - s->window ) >= d ) { /* offset before dest */
+ /* just copy */
+ r = q - d;
+ *q++ = *r++; c--; /* minimum count is three, */
+ *q++ = *r++; c--; /* so unroll loop a little */
+ }
+ else /* else offset after destination */
+ {
+ e = d - (uInt)( q - s->window ); /* bytes from offset to end */
+ r = s->end - e; /* pointer to offset */
+ if ( c > e ) { /* if source crosses, */
+ c -= e; /* copy to end of window */
+ do {
+ *q++ = *r++;
+ } while ( --e );
+ r = s->window; /* copy rest from start of window */
+ }
+ }
+ do { /* copy all or what's left */
+ *q++ = *r++;
+ } while ( --c );
+ break;
+ }
+ else if ( ( e & 64 ) == 0 ) {
+ t += t->base;
+ e = ( t += ( (uInt)b & inflate_mask[e] ) )->exop;
+ }
+ else
+ {
+ z->msg = (char*)"invalid distance code";
+ UNGRAB
+ UPDATE
+ return Z_DATA_ERROR;
+ }
+ } while ( 1 );
+ break;
+ }
+ if ( ( e & 64 ) == 0 ) {
+ t += t->base;
+ if ( ( e = ( t += ( (uInt)b & inflate_mask[e] ) )->exop ) == 0 ) {
+ DUMPBITS( t->bits )
+ Tracevv( ( t->base >= 0x20 && t->base < 0x7f ?
+ "inflate: * literal '%c'\n" :
+ "inflate: * literal 0x%02x\n", t->base ) );
+ *q++ = (Byte)t->base;
+ m--;
+ break;
+ }
+ }
+ else if ( e & 32 ) {
+ Tracevv( ( "inflate: * end of block\n" ) );
+ UNGRAB
+ UPDATE
+ return Z_STREAM_END;
+ }
+ else
+ {
+ z->msg = (char*)"invalid literal/length code";
+ UNGRAB
+ UPDATE
+ return Z_DATA_ERROR;
+ }
+ } while ( 1 );
+ } while ( m >= 258 && n >= 10 );
+
+ /* not enough input or output--restore pointers and return */
+ UNGRAB
+ UPDATE
+ return Z_OK;
+}
+
+/* infcodes.c -- process literals and length/distance pairs
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* simplify the use of the inflate_huft type with some defines */
+#define exop word.what.Exop
+#define bits word.what.Bits
+
+typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
+ START, /* x: set up for LEN */
+ LEN, /* i: get length/literal/eob next */
+ LENEXT, /* i: getting length extra (have base) */
+ DIST, /* i: get distance next */
+ DISTEXT, /* i: getting distance extra */
+ COPY, /* o: copying bytes in window, waiting for space */
+ LIT, /* o: got literal, waiting for output space */
+ WASH, /* o: got eob, possibly still output waiting */
+ END, /* x: got eob and all data flushed */
+ BADCODE
+} /* x: got error */
+inflate_codes_mode;
+
+/* inflate codes private state */
+struct inflate_codes_state {
+
+ /* mode */
+ inflate_codes_mode mode; /* current inflate_codes mode */
+
+ /* mode dependent information */
+ uInt len;
+ union {
+ struct {
+ inflate_huft *tree; /* pointer into tree */
+ uInt need; /* bits needed */
+ } code; /* if LEN or DIST, where in tree */
+ uInt lit; /* if LIT, literal */
+ struct {
+ uInt get; /* bits to get for extra */
+ uInt dist; /* distance back to copy from */
+ } copy; /* if EXT or COPY, where and how much */
+ } sub; /* submode */
+
+ /* mode independent information */
+ Byte lbits; /* ltree bits decoded per branch */
+ Byte dbits; /* dtree bits decoder per branch */
+ inflate_huft *ltree; /* literal/length/eob tree */
+ inflate_huft *dtree; /* distance tree */
+
+};
+
+
+inflate_codes_statef *inflate_codes_new( uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, z_streamp z ){
+ inflate_codes_statef *c;
+
+ if ( ( c = (inflate_codes_statef *)
+ ZALLOC( z,1,sizeof( struct inflate_codes_state ) ) ) != Z_NULL ) {
+ c->mode = START;
+ c->lbits = (Byte)bl;
+ c->dbits = (Byte)bd;
+ c->ltree = tl;
+ c->dtree = td;
+ Tracev( ( "inflate: codes new\n" ) );
+ }
+ return c;
+}
+
+
+int inflate_codes( inflate_blocks_statef *s, z_streamp z, int r ){
+ uInt j; /* temporary storage */
+ inflate_huft *t; /* temporary pointer */
+ uInt e; /* extra bits or operation */
+ uLong b; /* bit buffer */
+ uInt k; /* bits in bit buffer */
+ Byte *p; /* input data pointer */
+ uInt n; /* bytes available there */
+ Byte *q; /* output window write pointer */
+ uInt m; /* bytes to end of window or read pointer */
+ Byte *f; /* pointer to copy strings from */
+ inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
+
+ /* copy input/output information to locals (UPDATE macro restores) */
+ LOAD
+
+ /* process input and output based on current state */
+ while ( 1 ) switch ( c->mode )
+ { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
+ case START: /* x: set up for LEN */
+#ifndef SLOW
+ if ( m >= 258 && n >= 10 ) {
+ UPDATE
+ r = inflate_fast( c->lbits, c->dbits, c->ltree, c->dtree, s, z );
+ LOAD
+ if ( r != Z_OK ) {
+ c->mode = r == Z_STREAM_END ? WASH : BADCODE;
+ break;
+ }
+ }
+#endif /* !SLOW */
+ c->sub.code.need = c->lbits;
+ c->sub.code.tree = c->ltree;
+ c->mode = LEN;
+ case LEN: /* i: get length/literal/eob next */
+ j = c->sub.code.need;
+ NEEDBITS( j )
+ t = c->sub.code.tree + ( (uInt)b & inflate_mask[j] );
+ DUMPBITS( t->bits )
+ e = (uInt)( t->exop );
+ if ( e == 0 ) { /* literal */
+ c->sub.lit = t->base;
+ Tracevv( ( t->base >= 0x20 && t->base < 0x7f ?
+ "inflate: literal '%c'\n" :
+ "inflate: literal 0x%02x\n", t->base ) );
+ c->mode = LIT;
+ break;
+ }
+ if ( e & 16 ) { /* length */
+ c->sub.copy.get = e & 15;
+ c->len = t->base;
+ c->mode = LENEXT;
+ break;
+ }
+ if ( ( e & 64 ) == 0 ) { /* next table */
+ c->sub.code.need = e;
+ c->sub.code.tree = t + t->base;
+ break;
+ }
+ if ( e & 32 ) { /* end of block */
+ Tracevv( ( "inflate: end of block\n" ) );
+ c->mode = WASH;
+ break;
+ }
+ c->mode = BADCODE; /* invalid code */
+ z->msg = (char*)"invalid literal/length code";
+ r = Z_DATA_ERROR;
+ LEAVE
+ case LENEXT: /* i: getting length extra (have base) */
+ j = c->sub.copy.get;
+ NEEDBITS( j )
+ c->len += (uInt)b & inflate_mask[j];
+ DUMPBITS( j )
+ c->sub.code.need = c->dbits;
+ c->sub.code.tree = c->dtree;
+ Tracevv( ( "inflate: length %u\n", c->len ) );
+ c->mode = DIST;
+ case DIST: /* i: get distance next */
+ j = c->sub.code.need;
+ NEEDBITS( j )
+ t = c->sub.code.tree + ( (uInt)b & inflate_mask[j] );
+ DUMPBITS( t->bits )
+ e = (uInt)( t->exop );
+ if ( e & 16 ) { /* distance */
+ c->sub.copy.get = e & 15;
+ c->sub.copy.dist = t->base;
+ c->mode = DISTEXT;
+ break;
+ }
+ if ( ( e & 64 ) == 0 ) { /* next table */
+ c->sub.code.need = e;
+ c->sub.code.tree = t + t->base;
+ break;
+ }
+ c->mode = BADCODE; /* invalid code */
+ z->msg = (char*)"invalid distance code";
+ r = Z_DATA_ERROR;
+ LEAVE
+ case DISTEXT: /* i: getting distance extra */
+ j = c->sub.copy.get;
+ NEEDBITS( j )
+ c->sub.copy.dist += (uInt)b & inflate_mask[j];
+ DUMPBITS( j )
+ Tracevv( ( "inflate: distance %u\n", c->sub.copy.dist ) );
+ c->mode = COPY;
+ case COPY: /* o: copying bytes in window, waiting for space */
+#ifndef __TURBOC__ /* Turbo C bug for following expression */
+ f = (uInt)( q - s->window ) < c->sub.copy.dist ?
+ s->end - ( c->sub.copy.dist - ( q - s->window ) ) :
+ q - c->sub.copy.dist;
+#else
+ f = q - c->sub.copy.dist;
+ if ( (uInt)( q - s->window ) < c->sub.copy.dist ) {
+ f = s->end - ( c->sub.copy.dist - (uInt)( q - s->window ) );
+ }
+#endif
+ while ( c->len )
+ {
+ NEEDOUT
+ OUTBYTE( *f++ )
+ if ( f == s->end ) {
+ f = s->window;
+ }
+ c->len--;
+ }
+ c->mode = START;
+ break;
+ case LIT: /* o: got literal, waiting for output space */
+ NEEDOUT
+ OUTBYTE( c->sub.lit )
+ c->mode = START;
+ break;
+ case WASH: /* o: got eob, possibly more output */
+ if ( k > 7 ) { /* return unused byte, if any */
+ Assert( k < 16, "inflate_codes grabbed too many bytes" )
+ k -= 8;
+ n++;
+ p--; /* can always return one */
+ }
+ FLUSH
+ if ( s->read != s->write ) {
+ LEAVE
+ c->mode = END;
+ }
+ case END:
+ r = Z_STREAM_END;
+ LEAVE
+ case BADCODE: /* x: got error */
+ r = Z_DATA_ERROR;
+ LEAVE
+ default:
+ r = Z_STREAM_ERROR;
+ LEAVE
+ }
+#ifdef NEED_DUMMY_RETURN
+ return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
+#endif
+}
+
+
+void inflate_codes_free( inflate_codes_statef *c, z_streamp z ){
+ ZFREE( z, c );
+ Tracev( ( "inflate: codes free\n" ) );
+}
+
+/* adler32.c -- compute the Adler-32 checksum of a data stream
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#define BASE 65521L /* largest prime smaller than 65536 */
+#define NMAX 5552
+/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
+
+#undef DO1
+#undef DO2
+#undef DO4
+#undef DO8
+
+#define DO1( buf,i ) {s1 += buf[i]; s2 += s1; }
+#define DO2( buf,i ) DO1( buf,i ); DO1( buf,i + 1 );
+#define DO4( buf,i ) DO2( buf,i ); DO2( buf,i + 2 );
+#define DO8( buf,i ) DO4( buf,i ); DO4( buf,i + 4 );
+#define DO16( buf ) DO8( buf,0 ); DO8( buf,8 );
+
+/* ========================================================================= */
+uLong adler32( uLong adler, const Byte *buf, uInt len ){
+ unsigned long s1 = adler & 0xffff;
+ unsigned long s2 = ( adler >> 16 ) & 0xffff;
+ int k;
+
+ if ( buf == Z_NULL ) {
+ return 1L;
+ }
+
+ while ( len > 0 ) {
+ k = len < NMAX ? len : NMAX;
+ len -= k;
+ while ( k >= 16 ) {
+ DO16( buf );
+ buf += 16;
+ k -= 16;
+ }
+ if ( k != 0 ) {
+ do {
+ s1 += *buf++;
+ s2 += s1;
+ } while ( --k );
+ }
+ s1 %= BASE;
+ s2 %= BASE;
+ }
+ return ( s2 << 16 ) | s1;
+}
+
+/* infblock.h -- header to use infblock.c
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+extern inflate_blocks_statef * inflate_blocks_new OF( (
+ z_streamp z,
+ check_func c, /* check function */
+ uInt w ) ); /* window size */
+
+extern int inflate_blocks OF( (
+ inflate_blocks_statef *,
+ z_streamp,
+ int ) ); /* initial return code */
+
+extern void inflate_blocks_reset OF( (
+ inflate_blocks_statef *,
+ z_streamp,
+ uLong * ) ); /* check value on output */
+
+extern int inflate_blocks_free OF( (
+ inflate_blocks_statef *,
+ z_streamp ) );
+
+extern void inflate_set_dictionary OF( (
+ inflate_blocks_statef * s,
+ const Byte * d, /* dictionary */
+ uInt n ) ); /* dictionary length */
+
+extern int inflate_blocks_sync_point OF( (
+ inflate_blocks_statef * s ) );
+
+typedef enum {
+ imMETHOD, /* waiting for method byte */
+ imFLAG, /* waiting for flag byte */
+ imDICT4, /* four dictionary check bytes to go */
+ imDICT3, /* three dictionary check bytes to go */
+ imDICT2, /* two dictionary check bytes to go */
+ imDICT1, /* one dictionary check byte to go */
+ imDICT0, /* waiting for inflateSetDictionary */
+ imBLOCKS, /* decompressing blocks */
+ imCHECK4, /* four check bytes to go */
+ imCHECK3, /* three check bytes to go */
+ imCHECK2, /* two check bytes to go */
+ imCHECK1, /* one check byte to go */
+ imDONE, /* finished check, done */
+ imBAD
+} /* got an error--stay here */
+inflate_mode;
+
+/* inflate private state */
+struct internal_state {
+
+ /* mode */
+ inflate_mode mode; /* current inflate mode */
+
+ /* mode dependent information */
+ union {
+ uInt method; /* if FLAGS, method byte */
+ struct {
+ uLong was; /* computed check value */
+ uLong need; /* stream check value */
+ } check; /* if CHECK, check values to compare */
+ uInt marker; /* if BAD, inflateSync's marker bytes count */
+ } sub; /* submode */
+
+ /* mode independent information */
+ int nowrap; /* flag for no wrapper */
+ uInt wbits; /* log2(window size) (8..15, defaults to 15) */
+ inflate_blocks_statef
+ *blocks; /* current inflate_blocks state */
+
+};
+
+
+int inflateReset( z_streamp z ){
+ if ( z == Z_NULL || z->state == Z_NULL ) {
+ return Z_STREAM_ERROR;
+ }
+ z->total_in = z->total_out = 0;
+ z->msg = Z_NULL;
+ z->state->mode = z->state->nowrap ? imBLOCKS : imMETHOD;
+ inflate_blocks_reset( z->state->blocks, z, Z_NULL );
+ Tracev( ( "inflate: reset\n" ) );
+ return Z_OK;
+}
+
+
+int inflateEnd( z_streamp z ){
+ if ( z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL ) {
+ return Z_STREAM_ERROR;
+ }
+ if ( z->state->blocks != Z_NULL ) {
+ inflate_blocks_free( z->state->blocks, z );
+ }
+ ZFREE( z, z->state );
+ z->state = Z_NULL;
+ Tracev( ( "inflate: end\n" ) );
+ return Z_OK;
+}
+
+
+
+int inflateInit2_( z_streamp z, int w, const char *version, int stream_size ){
+ if ( version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
+ stream_size != sizeof( z_stream ) ) {
+ return Z_VERSION_ERROR;
+ }
+
+ /* initialize state */
+ if ( z == Z_NULL ) {
+ return Z_STREAM_ERROR;
+ }
+ z->msg = Z_NULL;
+ if ( z->zalloc == Z_NULL ) {
+ z->zalloc = ( void *( * )( void *, unsigned, unsigned ) )zcalloc;
+ z->opaque = (voidp)0;
+ }
+ if ( z->zfree == Z_NULL ) {
+ z->zfree = ( void ( * )( void *, void * ) )zcfree;
+ }
+ if ( ( z->state = (struct internal_state *)
+ ZALLOC( z,1,sizeof( struct internal_state ) ) ) == Z_NULL ) {
+ return Z_MEM_ERROR;
+ }
+ z->state->blocks = Z_NULL;
+
+ /* handle undocumented nowrap option (no zlib header or check) */
+ z->state->nowrap = 0;
+ if ( w < 0 ) {
+ w = -w;
+ z->state->nowrap = 1;
+ }
+
+ /* set window size */
+ if ( w < 8 || w > 15 ) {
+ inflateEnd( z );
+ return Z_STREAM_ERROR;
+ }
+ z->state->wbits = (uInt)w;
+
+ /* create inflate_blocks state */
+ if ( ( z->state->blocks =
+ inflate_blocks_new( z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w ) )
+ == Z_NULL ) {
+ inflateEnd( z );
+ return Z_MEM_ERROR;
+ }
+ Tracev( ( "inflate: allocated\n" ) );
+
+ /* reset state */
+ inflateReset( z );
+ return Z_OK;
+}
+
+
+int inflateInit_( z_streamp z, const char *version, int stream_size ){
+ return inflateInit2_( z, DEF_WBITS, version, stream_size );
+}
+
+
+#define iNEEDBYTE {if ( z->avail_in == 0 ) {return r; } r = f; }
+#define iNEXTBYTE ( z->avail_in--,z->total_in++,*z->next_in++ )
+
+int inflate( z_streamp z, int f ){
+ int r;
+ uInt b;
+
+ if ( z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL ) {
+ return Z_STREAM_ERROR;
+ }
+ f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
+ r = Z_BUF_ERROR;
+ while ( 1 ) switch ( z->state->mode )
+ {
+ case imMETHOD:
+ iNEEDBYTE
+ if ( ( ( z->state->sub.method = iNEXTBYTE ) & 0xf ) != Z_DEFLATED ) {
+ z->state->mode = imBAD;
+ z->msg = (char*)"unknown compression method";
+ z->state->sub.marker = 5; /* can't try inflateSync */
+ break;
+ }
+ if ( ( z->state->sub.method >> 4 ) + 8 > z->state->wbits ) {
+ z->state->mode = imBAD;
+ z->msg = (char*)"invalid window size";
+ z->state->sub.marker = 5; /* can't try inflateSync */
+ break;
+ }
+ z->state->mode = imFLAG;
+ case imFLAG:
+ iNEEDBYTE
+ b = iNEXTBYTE;
+ if ( ( ( z->state->sub.method << 8 ) + b ) % 31 ) {
+ z->state->mode = imBAD;
+ z->msg = (char*)"incorrect header check";
+ z->state->sub.marker = 5; /* can't try inflateSync */
+ break;
+ }
+ Tracev( ( "inflate: zlib header ok\n" ) );
+ if ( !( b & PRESET_DICT ) ) {
+ z->state->mode = imBLOCKS;
+ break;
+ }
+ z->state->mode = imDICT4;
+ case imDICT4:
+ iNEEDBYTE
+ z->state->sub.check.need = (uLong)iNEXTBYTE << 24;
+ z->state->mode = imDICT3;
+ case imDICT3:
+ iNEEDBYTE
+ z->state->sub.check.need += (uLong)iNEXTBYTE << 16;
+ z->state->mode = imDICT2;
+ case imDICT2:
+ iNEEDBYTE
+ z->state->sub.check.need += (uLong)iNEXTBYTE << 8;
+ z->state->mode = imDICT1;
+ case imDICT1:
+ iNEEDBYTE
+ z->state->sub.check.need += (uLong)iNEXTBYTE;
+ z->adler = z->state->sub.check.need;
+ z->state->mode = imDICT0;
+ return Z_NEED_DICT;
+ case imDICT0:
+ z->state->mode = imBAD;
+ z->msg = (char*)"need dictionary";
+ z->state->sub.marker = 0; /* can try inflateSync */
+ return Z_STREAM_ERROR;
+ case imBLOCKS:
+ r = inflate_blocks( z->state->blocks, z, r );
+ if ( r == Z_DATA_ERROR ) {
+ z->state->mode = imBAD;
+ z->state->sub.marker = 0; /* can try inflateSync */
+ break;
+ }
+ if ( r == Z_OK ) {
+ r = f;
+ }
+ if ( r != Z_STREAM_END ) {
+ return r;
+ }
+ r = f;
+ inflate_blocks_reset( z->state->blocks, z, &z->state->sub.check.was );
+ if ( z->state->nowrap ) {
+ z->state->mode = imDONE;
+ break;
+ }
+ z->state->mode = imCHECK4;
+ case imCHECK4:
+ iNEEDBYTE
+ z->state->sub.check.need = (uLong)iNEXTBYTE << 24;
+ z->state->mode = imCHECK3;
+ case imCHECK3:
+ iNEEDBYTE
+ z->state->sub.check.need += (uLong)iNEXTBYTE << 16;
+ z->state->mode = imCHECK2;
+ case imCHECK2:
+ iNEEDBYTE
+ z->state->sub.check.need += (uLong)iNEXTBYTE << 8;
+ z->state->mode = imCHECK1;
+ case imCHECK1:
+ iNEEDBYTE
+ z->state->sub.check.need += (uLong)iNEXTBYTE;
+
+ if ( z->state->sub.check.was != z->state->sub.check.need ) {
+ z->state->mode = imBAD;
+ z->msg = (char*)"incorrect data check";
+ z->state->sub.marker = 5; /* can't try inflateSync */
+ break;
+ }
+ Tracev( ( "inflate: zlib check ok\n" ) );
+ z->state->mode = imDONE;
+ case imDONE:
+ return Z_STREAM_END;
+ case imBAD:
+ return Z_DATA_ERROR;
+ default:
+ return Z_STREAM_ERROR;
+ }
+#ifdef NEED_DUMMY_RETURN
+ return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
+#endif
+}
+
+
+int inflateSetDictionary( z_streamp z, const Byte *dictionary, uInt dictLength ){
+ uInt length = dictLength;
+
+ if ( z == Z_NULL || z->state == Z_NULL || z->state->mode != imDICT0 ) {
+ return Z_STREAM_ERROR;
+ }
+
+ if ( adler32( 1L, dictionary, dictLength ) != z->adler ) {
+ return Z_DATA_ERROR;
+ }
+ z->adler = 1L;
+
+ if ( length >= ( (uInt)1 << z->state->wbits ) ) {
+ length = ( 1 << z->state->wbits ) - 1;
+ dictionary += dictLength - length;
+ }
+ inflate_set_dictionary( z->state->blocks, dictionary, length );
+ z->state->mode = imBLOCKS;
+ return Z_OK;
+}
+
+
+int inflateSync( z_streamp z ){
+ uInt n; /* number of bytes to look at */
+ Byte *p; /* pointer to bytes */
+ uInt m; /* number of marker bytes found in a row */
+ uLong r, w; /* temporaries to save total_in and total_out */
+
+ /* set up */
+ if ( z == Z_NULL || z->state == Z_NULL ) {
+ return Z_STREAM_ERROR;
+ }
+ if ( z->state->mode != imBAD ) {
+ z->state->mode = imBAD;
+ z->state->sub.marker = 0;
+ }
+ if ( ( n = z->avail_in ) == 0 ) {
+ return Z_BUF_ERROR;
+ }
+ p = z->next_in;
+ m = z->state->sub.marker;
+
+ /* search */
+ while ( n && m < 4 )
+ {
+ static const Byte mark[4] = {0, 0, 0xff, 0xff};
+ if ( *p == mark[m] ) {
+ m++;
+ }
+ else if ( *p ) {
+ m = 0;
+ }
+ else{
+ m = 4 - m;
+ }
+ p++, n--;
+ }
+
+ /* restore */
+ z->total_in += p - z->next_in;
+ z->next_in = p;
+ z->avail_in = n;
+ z->state->sub.marker = m;
+
+ /* return no joy or set up to restart on a new block */
+ if ( m != 4 ) {
+ return Z_DATA_ERROR;
+ }
+ r = z->total_in; w = z->total_out;
+ inflateReset( z );
+ z->total_in = r; z->total_out = w;
+ z->state->mode = imBLOCKS;
+ return Z_OK;
+}
+
+
+/* Returns true if inflate is currently at the end of a block generated
+ * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
+ * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
+ * but removes the length bytes of the resulting empty stored block. When
+ * decompressing, PPP checks that at the end of input packet, inflate is
+ * waiting for these length bytes.
+ */
+int inflateSyncPoint( z_streamp z ){
+ if ( z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL ) {
+ return Z_STREAM_ERROR;
+ }
+ return inflate_blocks_sync_point( z->state->blocks );
+}
+
+voidp zcalloc( voidp opaque, unsigned items, unsigned size ){
+ if ( opaque ) {
+ items += size - size; /* make compiler happy */
+ }
+ return (voidp)malloc( items * size );
+}
+
+void zcfree( voidp opaque, voidp ptr ){
+ free( ptr );
+ if ( opaque ) {
+ return; /* make compiler happy */
+ }
+}