├── bzlib ├── LICENSE ├── blocksort.c ├── bzlib.c ├── bzlib.h ├── bzlib_private.h ├── compress.c ├── crctable.c ├── decompress.c ├── huffman.c ├── innosetup.c ├── isbunzip.vcproj ├── isbz2.sln ├── isbz2comp.def ├── isbz2decomp.def ├── isbzip.vcproj └── randtable.c ├── lzma ├── C │ ├── 7zcrc.c │ ├── 7zcrc.h │ ├── Alloc.c │ ├── Alloc.h │ ├── Compress │ │ └── Lz │ │ │ ├── Lzhash.h │ │ │ ├── MatchFinder.c │ │ │ ├── MatchFinder.h │ │ │ ├── MatchFinderMt.c │ │ │ └── MatchFinderMt.h │ ├── Istream.h │ ├── Threads.c │ ├── Threads.h │ └── Types.h ├── CPL.html ├── CPP │ ├── 7zip │ │ ├── Common │ │ │ ├── Inbuffer.cpp │ │ │ ├── Inbuffer.h │ │ │ ├── OutBuffer.cpp │ │ │ ├── OutBuffer.h │ │ │ ├── Stdafx.h │ │ │ ├── StreamUtils.cpp │ │ │ └── StreamUtils.h │ │ ├── Compress │ │ │ ├── ISLZMA │ │ │ │ ├── ISLZMA.vcproj │ │ │ │ ├── ISLZMA_DllExports.cpp │ │ │ │ ├── Islzma.def │ │ │ │ ├── Islzma.sln │ │ │ │ ├── Stdafx.cpp │ │ │ │ └── Stdafx.h │ │ │ ├── LZMA │ │ │ │ ├── LZMAEncoder.cpp │ │ │ │ ├── LZMAEncoder.h │ │ │ │ ├── Lzma.h │ │ │ │ ├── Stdafx.cpp │ │ │ │ └── Stdafx.h │ │ │ └── RangeCoder │ │ │ │ ├── RangeCoder.h │ │ │ │ ├── RangeCoderBit.cpp │ │ │ │ ├── RangeCoderBit.h │ │ │ │ ├── RangeCoderBitTree.h │ │ │ │ ├── RangeCoderOpt.h │ │ │ │ └── Stdafx.h │ │ ├── Icoder.h │ │ └── Istream.h │ └── Common │ │ ├── Crc.cpp │ │ ├── Defs.h │ │ ├── MyException.h │ │ ├── MyGuidDef.h │ │ ├── MyInitGuid.h │ │ ├── MyUnknown.h │ │ ├── MyWindows.h │ │ ├── Mycom.h │ │ ├── NewHandler.cpp │ │ ├── NewHandler.h │ │ ├── Stdafx.h │ │ └── Types.h ├── Lgpl.txt ├── Readme.txt └── lzma.txt ├── zlib-dll ├── Readme.txt ├── adler32.c ├── compress.c ├── deflate.c ├── deflate.h ├── infback.c ├── inffast.c ├── inffast.h ├── inffixed.h ├── inflate.c ├── inflate.h ├── inftrees.c ├── inftrees.h ├── isunzlib.c ├── isunzlib.def ├── isunzlib.vcproj ├── iszlib.c ├── iszlib.def ├── iszlib.sln ├── iszlib.vcproj ├── trees.c ├── trees.h ├── uncompr.c ├── zconf.h ├── zlib.h ├── zutil.c └── zutil.h └── zlib ├── adler32.c ├── crc32.c ├── deflate.c ├── deflate.h ├── infblock.c ├── infblock.h ├── infcodes.c ├── infcodes.h ├── inffast.c ├── inffast.h ├── inffixed.h ├── inflate.c ├── inftrees.c ├── inftrees.h ├── infutil.c ├── infutil.h ├── trees.c ├── trees.h ├── zconf.h ├── zlib.h ├── zutil.c └── zutil.h /bzlib/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------- 3 | 4 | This program, "bzip2", the associated library "libbzip2", and all 5 | documentation, are copyright (C) 1996-2010 Julian R Seward. All 6 | rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | 15 | 2. The origin of this software must not be misrepresented; you must 16 | not claim that you wrote the original software. If you use this 17 | software in a product, an acknowledgment in the product 18 | documentation would be appreciated but is not required. 19 | 20 | 3. Altered source versions must be plainly marked as such, and must 21 | not be misrepresented as being the original software. 22 | 23 | 4. The name of the author may not be used to endorse or promote 24 | products derived from this software without specific prior written 25 | permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 28 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 29 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 31 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 33 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 35 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | 39 | Julian Seward, jseward@bzip.org 40 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 41 | 42 | -------------------------------------------------------------------------- 43 | -------------------------------------------------------------------------------- /bzlib/bzlib.h: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Public header file for the library. ---*/ 4 | /*--- bzlib.h ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #ifndef _BZLIB_H 23 | #define _BZLIB_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define BZ_RUN 0 30 | #define BZ_FLUSH 1 31 | #define BZ_FINISH 2 32 | 33 | #define BZ_OK 0 34 | #define BZ_RUN_OK 1 35 | #define BZ_FLUSH_OK 2 36 | #define BZ_FINISH_OK 3 37 | #define BZ_STREAM_END 4 38 | #define BZ_SEQUENCE_ERROR (-1) 39 | #define BZ_PARAM_ERROR (-2) 40 | #define BZ_MEM_ERROR (-3) 41 | #define BZ_DATA_ERROR (-4) 42 | #define BZ_DATA_ERROR_MAGIC (-5) 43 | #define BZ_IO_ERROR (-6) 44 | #define BZ_UNEXPECTED_EOF (-7) 45 | #define BZ_OUTBUFF_FULL (-8) 46 | #define BZ_CONFIG_ERROR (-9) 47 | 48 | typedef 49 | struct { 50 | char *next_in; 51 | unsigned int avail_in; 52 | unsigned int total_in_lo32; 53 | unsigned int total_in_hi32; 54 | 55 | char *next_out; 56 | unsigned int avail_out; 57 | unsigned int total_out_lo32; 58 | unsigned int total_out_hi32; 59 | 60 | void *state; 61 | 62 | void *(*bzalloc)(void *,int,int); 63 | void (*bzfree)(void *,void *); 64 | void *opaque; 65 | } 66 | bz_stream; 67 | 68 | 69 | #ifndef BZ_IMPORT 70 | #define BZ_EXPORT 71 | #endif 72 | 73 | #ifndef BZ_NO_STDIO 74 | /* Need a definitition for FILE */ 75 | #include 76 | #endif 77 | 78 | #ifdef _WIN32 79 | # include 80 | # ifdef small 81 | /* windows.h define small to char */ 82 | # undef small 83 | # endif 84 | # ifdef BZ_EXPORT 85 | # define BZ_API(func) WINAPI func 86 | # define BZ_EXTERN extern 87 | # else 88 | /* import windows dll dynamically */ 89 | # define BZ_API(func) (WINAPI * func) 90 | # define BZ_EXTERN 91 | # endif 92 | #else 93 | # define BZ_API(func) func 94 | # define BZ_EXTERN extern 95 | #endif 96 | 97 | 98 | /*-- Core (low-level) library functions --*/ 99 | 100 | BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( 101 | bz_stream* strm, 102 | int blockSize100k, 103 | int verbosity, 104 | int workFactor 105 | ); 106 | 107 | BZ_EXTERN int BZ_API(BZ2_bzCompress) ( 108 | bz_stream* strm, 109 | int action 110 | ); 111 | 112 | BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( 113 | bz_stream* strm 114 | ); 115 | 116 | BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( 117 | bz_stream *strm, 118 | int verbosity, 119 | int small 120 | ); 121 | 122 | BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( 123 | bz_stream* strm 124 | ); 125 | 126 | BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( 127 | bz_stream *strm 128 | ); 129 | 130 | 131 | 132 | /*-- High(er) level library functions --*/ 133 | 134 | #ifndef BZ_NO_STDIO 135 | #define BZ_MAX_UNUSED 5000 136 | 137 | typedef void BZFILE; 138 | 139 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( 140 | int* bzerror, 141 | FILE* f, 142 | int verbosity, 143 | int small, 144 | void* unused, 145 | int nUnused 146 | ); 147 | 148 | BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( 149 | int* bzerror, 150 | BZFILE* b 151 | ); 152 | 153 | BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( 154 | int* bzerror, 155 | BZFILE* b, 156 | void** unused, 157 | int* nUnused 158 | ); 159 | 160 | BZ_EXTERN int BZ_API(BZ2_bzRead) ( 161 | int* bzerror, 162 | BZFILE* b, 163 | void* buf, 164 | int len 165 | ); 166 | 167 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( 168 | int* bzerror, 169 | FILE* f, 170 | int blockSize100k, 171 | int verbosity, 172 | int workFactor 173 | ); 174 | 175 | BZ_EXTERN void BZ_API(BZ2_bzWrite) ( 176 | int* bzerror, 177 | BZFILE* b, 178 | void* buf, 179 | int len 180 | ); 181 | 182 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( 183 | int* bzerror, 184 | BZFILE* b, 185 | int abandon, 186 | unsigned int* nbytes_in, 187 | unsigned int* nbytes_out 188 | ); 189 | 190 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( 191 | int* bzerror, 192 | BZFILE* b, 193 | int abandon, 194 | unsigned int* nbytes_in_lo32, 195 | unsigned int* nbytes_in_hi32, 196 | unsigned int* nbytes_out_lo32, 197 | unsigned int* nbytes_out_hi32 198 | ); 199 | #endif 200 | 201 | 202 | /*-- Utility functions --*/ 203 | 204 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( 205 | char* dest, 206 | unsigned int* destLen, 207 | char* source, 208 | unsigned int sourceLen, 209 | int blockSize100k, 210 | int verbosity, 211 | int workFactor 212 | ); 213 | 214 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( 215 | char* dest, 216 | unsigned int* destLen, 217 | char* source, 218 | unsigned int sourceLen, 219 | int small, 220 | int verbosity 221 | ); 222 | 223 | 224 | /*-- 225 | Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp) 226 | to support better zlib compatibility. 227 | This code is not _officially_ part of libbzip2 (yet); 228 | I haven't tested it, documented it, or considered the 229 | threading-safeness of it. 230 | If this code breaks, please contact both Yoshioka and me. 231 | --*/ 232 | 233 | BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) ( 234 | void 235 | ); 236 | 237 | #ifndef BZ_NO_STDIO 238 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) ( 239 | const char *path, 240 | const char *mode 241 | ); 242 | 243 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) ( 244 | int fd, 245 | const char *mode 246 | ); 247 | 248 | BZ_EXTERN int BZ_API(BZ2_bzread) ( 249 | BZFILE* b, 250 | void* buf, 251 | int len 252 | ); 253 | 254 | BZ_EXTERN int BZ_API(BZ2_bzwrite) ( 255 | BZFILE* b, 256 | void* buf, 257 | int len 258 | ); 259 | 260 | BZ_EXTERN int BZ_API(BZ2_bzflush) ( 261 | BZFILE* b 262 | ); 263 | 264 | BZ_EXTERN void BZ_API(BZ2_bzclose) ( 265 | BZFILE* b 266 | ); 267 | 268 | BZ_EXTERN const char * BZ_API(BZ2_bzerror) ( 269 | BZFILE *b, 270 | int *errnum 271 | ); 272 | #endif 273 | 274 | #ifdef __cplusplus 275 | } 276 | #endif 277 | 278 | #endif 279 | 280 | /*-------------------------------------------------------------*/ 281 | /*--- end bzlib.h ---*/ 282 | /*-------------------------------------------------------------*/ 283 | -------------------------------------------------------------------------------- /bzlib/crctable.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Table for doing CRCs ---*/ 4 | /*--- crctable.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | /*-- 25 | I think this is an implementation of the AUTODIN-II, 26 | Ethernet & FDDI 32-bit CRC standard. Vaguely derived 27 | from code by Rob Warnock, in Section 51 of the 28 | comp.compression FAQ. 29 | --*/ 30 | 31 | UInt32 BZ2_crc32Table[256] = { 32 | 33 | /*-- Ugly, innit? --*/ 34 | 35 | 0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L, 36 | 0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L, 37 | 0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L, 38 | 0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL, 39 | 0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L, 40 | 0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L, 41 | 0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L, 42 | 0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL, 43 | 0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L, 44 | 0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L, 45 | 0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L, 46 | 0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL, 47 | 0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L, 48 | 0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L, 49 | 0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L, 50 | 0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL, 51 | 0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL, 52 | 0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L, 53 | 0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L, 54 | 0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL, 55 | 0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL, 56 | 0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L, 57 | 0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L, 58 | 0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL, 59 | 0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL, 60 | 0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L, 61 | 0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L, 62 | 0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL, 63 | 0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL, 64 | 0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L, 65 | 0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L, 66 | 0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL, 67 | 0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L, 68 | 0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL, 69 | 0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL, 70 | 0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L, 71 | 0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L, 72 | 0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL, 73 | 0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL, 74 | 0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L, 75 | 0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L, 76 | 0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL, 77 | 0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL, 78 | 0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L, 79 | 0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L, 80 | 0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL, 81 | 0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL, 82 | 0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L, 83 | 0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L, 84 | 0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL, 85 | 0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L, 86 | 0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L, 87 | 0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L, 88 | 0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL, 89 | 0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L, 90 | 0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L, 91 | 0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L, 92 | 0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL, 93 | 0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L, 94 | 0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L, 95 | 0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L, 96 | 0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL, 97 | 0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L, 98 | 0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L 99 | }; 100 | 101 | 102 | /*-------------------------------------------------------------*/ 103 | /*--- end crctable.c ---*/ 104 | /*-------------------------------------------------------------*/ 105 | -------------------------------------------------------------------------------- /bzlib/huffman.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Huffman coding low-level stuff ---*/ 4 | /*--- huffman.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | /*---------------------------------------------------*/ 25 | #define WEIGHTOF(zz0) ((zz0) & 0xffffff00) 26 | #define DEPTHOF(zz1) ((zz1) & 0x000000ff) 27 | #define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3)) 28 | 29 | #define ADDWEIGHTS(zw1,zw2) \ 30 | (WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \ 31 | (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2))) 32 | 33 | #define UPHEAP(z) \ 34 | { \ 35 | Int32 zz, tmp; \ 36 | zz = z; tmp = heap[zz]; \ 37 | while (weight[tmp] < weight[heap[zz >> 1]]) { \ 38 | heap[zz] = heap[zz >> 1]; \ 39 | zz >>= 1; \ 40 | } \ 41 | heap[zz] = tmp; \ 42 | } 43 | 44 | #define DOWNHEAP(z) \ 45 | { \ 46 | Int32 zz, yy, tmp; \ 47 | zz = z; tmp = heap[zz]; \ 48 | while (True) { \ 49 | yy = zz << 1; \ 50 | if (yy > nHeap) break; \ 51 | if (yy < nHeap && \ 52 | weight[heap[yy+1]] < weight[heap[yy]]) \ 53 | yy++; \ 54 | if (weight[tmp] < weight[heap[yy]]) break; \ 55 | heap[zz] = heap[yy]; \ 56 | zz = yy; \ 57 | } \ 58 | heap[zz] = tmp; \ 59 | } 60 | 61 | 62 | /*---------------------------------------------------*/ 63 | void BZ2_hbMakeCodeLengths ( UChar *len, 64 | Int32 *freq, 65 | Int32 alphaSize, 66 | Int32 maxLen ) 67 | { 68 | /*-- 69 | Nodes and heap entries run from 1. Entry 0 70 | for both the heap and nodes is a sentinel. 71 | --*/ 72 | Int32 nNodes, nHeap, n1, n2, i, j, k; 73 | Bool tooLong; 74 | 75 | Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ]; 76 | Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ]; 77 | Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ]; 78 | 79 | for (i = 0; i < alphaSize; i++) 80 | weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8; 81 | 82 | while (True) { 83 | 84 | nNodes = alphaSize; 85 | nHeap = 0; 86 | 87 | heap[0] = 0; 88 | weight[0] = 0; 89 | parent[0] = -2; 90 | 91 | for (i = 1; i <= alphaSize; i++) { 92 | parent[i] = -1; 93 | nHeap++; 94 | heap[nHeap] = i; 95 | UPHEAP(nHeap); 96 | } 97 | 98 | AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 ); 99 | 100 | while (nHeap > 1) { 101 | n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); 102 | n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); 103 | nNodes++; 104 | parent[n1] = parent[n2] = nNodes; 105 | weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]); 106 | parent[nNodes] = -1; 107 | nHeap++; 108 | heap[nHeap] = nNodes; 109 | UPHEAP(nHeap); 110 | } 111 | 112 | AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 ); 113 | 114 | tooLong = False; 115 | for (i = 1; i <= alphaSize; i++) { 116 | j = 0; 117 | k = i; 118 | while (parent[k] >= 0) { k = parent[k]; j++; } 119 | len[i-1] = j; 120 | if (j > maxLen) tooLong = True; 121 | } 122 | 123 | if (! tooLong) break; 124 | 125 | /* 17 Oct 04: keep-going condition for the following loop used 126 | to be 'i < alphaSize', which missed the last element, 127 | theoretically leading to the possibility of the compressor 128 | looping. However, this count-scaling step is only needed if 129 | one of the generated Huffman code words is longer than 130 | maxLen, which up to and including version 1.0.2 was 20 bits, 131 | which is extremely unlikely. In version 1.0.3 maxLen was 132 | changed to 17 bits, which has minimal effect on compression 133 | ratio, but does mean this scaling step is used from time to 134 | time, enough to verify that it works. 135 | 136 | This means that bzip2-1.0.3 and later will only produce 137 | Huffman codes with a maximum length of 17 bits. However, in 138 | order to preserve backwards compatibility with bitstreams 139 | produced by versions pre-1.0.3, the decompressor must still 140 | handle lengths of up to 20. */ 141 | 142 | for (i = 1; i <= alphaSize; i++) { 143 | j = weight[i] >> 8; 144 | j = 1 + (j / 2); 145 | weight[i] = j << 8; 146 | } 147 | } 148 | } 149 | 150 | 151 | /*---------------------------------------------------*/ 152 | void BZ2_hbAssignCodes ( Int32 *code, 153 | UChar *length, 154 | Int32 minLen, 155 | Int32 maxLen, 156 | Int32 alphaSize ) 157 | { 158 | Int32 n, vec, i; 159 | 160 | vec = 0; 161 | for (n = minLen; n <= maxLen; n++) { 162 | for (i = 0; i < alphaSize; i++) 163 | if (length[i] == n) { code[i] = vec; vec++; }; 164 | vec <<= 1; 165 | } 166 | } 167 | 168 | 169 | /*---------------------------------------------------*/ 170 | void BZ2_hbCreateDecodeTables ( Int32 *limit, 171 | Int32 *base, 172 | Int32 *perm, 173 | UChar *length, 174 | Int32 minLen, 175 | Int32 maxLen, 176 | Int32 alphaSize ) 177 | { 178 | Int32 pp, i, j, vec; 179 | 180 | pp = 0; 181 | for (i = minLen; i <= maxLen; i++) 182 | for (j = 0; j < alphaSize; j++) 183 | if (length[j] == i) { perm[pp] = j; pp++; }; 184 | 185 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0; 186 | for (i = 0; i < alphaSize; i++) base[length[i]+1]++; 187 | 188 | for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1]; 189 | 190 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0; 191 | vec = 0; 192 | 193 | for (i = minLen; i <= maxLen; i++) { 194 | vec += (base[i+1] - base[i]); 195 | limit[i] = vec-1; 196 | vec <<= 1; 197 | } 198 | for (i = minLen + 1; i <= maxLen; i++) 199 | base[i] = ((limit[i-1] + 1) << 1) - base[i]; 200 | } 201 | 202 | 203 | /*-------------------------------------------------------------*/ 204 | /*--- end huffman.c ---*/ 205 | /*-------------------------------------------------------------*/ 206 | -------------------------------------------------------------------------------- /bzlib/innosetup.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void bz_internal_error(int errcode) 4 | { 5 | /* If an internal error is encountered, just throw an exception 6 | with a random code. It'll probably leak memory, but that's 7 | better than doing nothing, or killing the process. */ 8 | RaiseException(0x06E15C8B, 0, 0, NULL); 9 | } 10 | 11 | void * __cdecl malloc(size_t size) 12 | { 13 | return NULL; 14 | } 15 | 16 | void __cdecl free(void *ptr) 17 | { 18 | } 19 | 20 | /* bzlib itself doesn't need memset, but VC2005's optimizer likes to replace 21 | assignment loops with calls to memset. */ 22 | #pragma function(memset) 23 | void * __cdecl memset(void *dst, int val, size_t count) 24 | { 25 | size_t i; 26 | 27 | for (i = 0; i < count; i++) { 28 | ((char *)dst)[i] = (char)val; 29 | } 30 | 31 | return dst; 32 | } 33 | 34 | BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) 35 | { 36 | if (dwReason == DLL_PROCESS_ATTACH) 37 | { 38 | DisableThreadLibraryCalls(hInstance); 39 | } 40 | return TRUE; 41 | } 42 | -------------------------------------------------------------------------------- /bzlib/isbunzip.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 26 | 29 | 32 | 35 | 38 | 41 | 53 | 56 | 59 | 62 | 76 | 79 | 83 | 86 | 89 | 92 | 95 | 98 | 101 | 102 | 103 | 104 | 105 | 106 | 109 | 110 | 113 | 114 | 117 | 118 | 121 | 122 | 125 | 126 | 129 | 130 | 133 | 134 | 137 | 138 | 141 | 142 | 145 | 146 | 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /bzlib/isbz2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "isbzip", "isbzip.vcproj", "{DEF483D4-6EE3-4D04-93D3-3C368C8B70EC}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "isbunzip", "isbunzip.vcproj", "{A6100944-837E-4627-B558-A993D4C18261}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Release|Win32 = Release|Win32 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {DEF483D4-6EE3-4D04-93D3-3C368C8B70EC}.Release|Win32.ActiveCfg = Release|Win32 14 | {DEF483D4-6EE3-4D04-93D3-3C368C8B70EC}.Release|Win32.Build.0 = Release|Win32 15 | {A6100944-837E-4627-B558-A993D4C18261}.Release|Win32.ActiveCfg = Release|Win32 16 | {A6100944-837E-4627-B558-A993D4C18261}.Release|Win32.Build.0 = Release|Win32 17 | EndGlobalSection 18 | GlobalSection(SolutionProperties) = preSolution 19 | HideSolutionNode = FALSE 20 | EndGlobalSection 21 | EndGlobal 22 | -------------------------------------------------------------------------------- /bzlib/isbz2comp.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | BZ2_bzCompressInit 3 | BZ2_bzCompress 4 | BZ2_bzCompressEnd 5 | -------------------------------------------------------------------------------- /bzlib/isbz2decomp.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | BZ2_bzDecompressInit 3 | BZ2_bzDecompress 4 | BZ2_bzDecompressEnd 5 | -------------------------------------------------------------------------------- /bzlib/isbzip.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 26 | 29 | 32 | 35 | 38 | 41 | 53 | 56 | 59 | 62 | 76 | 79 | 83 | 86 | 89 | 92 | 95 | 98 | 101 | 102 | 103 | 104 | 105 | 106 | 109 | 110 | 113 | 114 | 117 | 118 | 121 | 122 | 125 | 126 | 129 | 130 | 133 | 134 | 137 | 138 | 141 | 142 | 145 | 146 | 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /bzlib/randtable.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Table for randomising repetitive blocks ---*/ 4 | /*--- randtable.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | 25 | /*---------------------------------------------*/ 26 | Int32 BZ2_rNums[512] = { 27 | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 28 | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 29 | 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 30 | 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 31 | 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 32 | 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 33 | 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 34 | 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 35 | 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 36 | 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 37 | 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 38 | 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 39 | 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 40 | 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 41 | 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 42 | 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 43 | 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 44 | 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 45 | 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 46 | 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 47 | 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 48 | 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 49 | 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 50 | 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 51 | 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 52 | 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 53 | 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 54 | 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 55 | 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 56 | 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 57 | 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 58 | 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 59 | 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 60 | 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 61 | 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 62 | 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 63 | 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 64 | 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 65 | 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 66 | 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 67 | 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 68 | 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 69 | 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 70 | 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 71 | 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 72 | 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 73 | 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 74 | 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 75 | 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 76 | 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 77 | 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 78 | 936, 638 79 | }; 80 | 81 | 82 | /*-------------------------------------------------------------*/ 83 | /*--- end randtable.c ---*/ 84 | /*-------------------------------------------------------------*/ 85 | -------------------------------------------------------------------------------- /lzma/C/7zcrc.c: -------------------------------------------------------------------------------- 1 | /* 7zCrc.c */ 2 | 3 | #include "7zCrc.h" 4 | 5 | #define kCrcPoly 0xEDB88320 6 | UInt32 g_CrcTable[256]; 7 | 8 | void MY_FAST_CALL CrcGenerateTable() 9 | { 10 | UInt32 i; 11 | for (i = 0; i < 256; i++) 12 | { 13 | UInt32 r = i; 14 | int j; 15 | for (j = 0; j < 8; j++) 16 | r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); 17 | g_CrcTable[i] = r; 18 | } 19 | } 20 | 21 | UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size) 22 | { 23 | const Byte *p = (const Byte *)data; 24 | for (; size > 0 ; size--, p++) 25 | v = CRC_UPDATE_BYTE(v, *p); 26 | return v; 27 | } 28 | 29 | UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size) 30 | { 31 | return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF; 32 | } 33 | -------------------------------------------------------------------------------- /lzma/C/7zcrc.h: -------------------------------------------------------------------------------- 1 | /* 7zCrc.h */ 2 | 3 | #ifndef __7Z_CRC_H 4 | #define __7Z_CRC_H 5 | 6 | #include 7 | 8 | #include "Types.h" 9 | 10 | extern UInt32 g_CrcTable[]; 11 | 12 | void MY_FAST_CALL CrcGenerateTable(); 13 | 14 | #define CRC_INIT_VAL 0xFFFFFFFF 15 | #define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF) 16 | #define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 17 | 18 | UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size); 19 | UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lzma/C/Alloc.c: -------------------------------------------------------------------------------- 1 | /* Alloc.c */ 2 | 3 | #ifdef _WIN32 4 | #include 5 | #endif 6 | #include 7 | 8 | #include "Alloc.h" 9 | 10 | /* #define _SZ_ALLOC_DEBUG */ 11 | 12 | /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ 13 | #ifdef _SZ_ALLOC_DEBUG 14 | #include 15 | int g_allocCount = 0; 16 | int g_allocCountMid = 0; 17 | int g_allocCountBig = 0; 18 | #endif 19 | 20 | void *MyAlloc(size_t size) 21 | { 22 | if (size == 0) 23 | return 0; 24 | #ifdef _SZ_ALLOC_DEBUG 25 | fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount++); 26 | #endif 27 | return malloc(size); 28 | } 29 | 30 | void MyFree(void *address) 31 | { 32 | #ifdef _SZ_ALLOC_DEBUG 33 | if (address != 0) 34 | fprintf(stderr, "\nFree; count = %10d", --g_allocCount); 35 | #endif 36 | free(address); 37 | } 38 | 39 | #ifdef _WIN32 40 | 41 | void *MidAlloc(size_t size) 42 | { 43 | if (size == 0) 44 | return 0; 45 | #ifdef _SZ_ALLOC_DEBUG 46 | fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++); 47 | #endif 48 | return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); 49 | } 50 | 51 | void MidFree(void *address) 52 | { 53 | #ifdef _SZ_ALLOC_DEBUG 54 | if (address != 0) 55 | fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid); 56 | #endif 57 | if (address == 0) 58 | return; 59 | VirtualFree(address, 0, MEM_RELEASE); 60 | } 61 | 62 | #ifndef MEM_LARGE_PAGES 63 | #undef _7ZIP_LARGE_PAGES 64 | #endif 65 | 66 | #ifdef _7ZIP_LARGE_PAGES 67 | SIZE_T g_LargePageSize = 0; 68 | typedef SIZE_T (WINAPI *GetLargePageMinimumP)(); 69 | #endif 70 | 71 | void SetLargePageSize() 72 | { 73 | #ifdef _7ZIP_LARGE_PAGES 74 | SIZE_T size = 0; 75 | GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP) 76 | GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum"); 77 | if (largePageMinimum == 0) 78 | return; 79 | size = largePageMinimum(); 80 | if (size == 0 || (size & (size - 1)) != 0) 81 | return; 82 | g_LargePageSize = size; 83 | #endif 84 | } 85 | 86 | 87 | void *BigAlloc(size_t size) 88 | { 89 | if (size == 0) 90 | return 0; 91 | #ifdef _SZ_ALLOC_DEBUG 92 | fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++); 93 | #endif 94 | 95 | #ifdef _7ZIP_LARGE_PAGES 96 | if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18)) 97 | { 98 | void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), 99 | MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE); 100 | if (res != 0) 101 | return res; 102 | } 103 | #endif 104 | return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); 105 | } 106 | 107 | void BigFree(void *address) 108 | { 109 | #ifdef _SZ_ALLOC_DEBUG 110 | if (address != 0) 111 | fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig); 112 | #endif 113 | 114 | if (address == 0) 115 | return; 116 | VirtualFree(address, 0, MEM_RELEASE); 117 | } 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /lzma/C/Alloc.h: -------------------------------------------------------------------------------- 1 | /* Alloc.h */ 2 | 3 | #ifndef __COMMON_ALLOC_H 4 | #define __COMMON_ALLOC_H 5 | 6 | #include 7 | 8 | void *MyAlloc(size_t size); 9 | void MyFree(void *address); 10 | 11 | #ifdef _WIN32 12 | 13 | void SetLargePageSize(); 14 | 15 | void *MidAlloc(size_t size); 16 | void MidFree(void *address); 17 | void *BigAlloc(size_t size); 18 | void BigFree(void *address); 19 | 20 | #else 21 | 22 | #define MidAlloc(size) MyAlloc(size) 23 | #define MidFree(address) MyFree(address) 24 | #define BigAlloc(size) MyAlloc(size) 25 | #define BigFree(address) MyFree(address) 26 | 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lzma/C/Compress/Lz/Lzhash.h: -------------------------------------------------------------------------------- 1 | /* LzHash.h */ 2 | 3 | #ifndef __C_LZHASH_H 4 | #define __C_LZHASH_H 5 | 6 | #define kHash2Size (1 << 10) 7 | #define kHash3Size (1 << 16) 8 | #define kHash4Size (1 << 20) 9 | 10 | #define kFix3HashSize (kHash2Size) 11 | #define kFix4HashSize (kHash2Size + kHash3Size) 12 | #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) 13 | 14 | #define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8); 15 | 16 | #define HASH3_CALC { \ 17 | UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \ 18 | hash2Value = temp & (kHash2Size - 1); \ 19 | hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } 20 | 21 | #define HASH4_CALC { \ 22 | UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \ 23 | hash2Value = temp & (kHash2Size - 1); \ 24 | hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ 25 | hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & p->hashMask; } 26 | 27 | #define HASH5_CALC { \ 28 | UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \ 29 | hash2Value = temp & (kHash2Size - 1); \ 30 | hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ 31 | hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)); \ 32 | hashValue = (hash4Value ^ (g_CrcTable[cur[4]] << 3)) & p->hashMask; \ 33 | hash4Value &= (kHash4Size - 1); } 34 | 35 | /* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ g_CrcTable[cur[2]]) & 0xFFFF; */ 36 | #define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ g_CrcTable[cur[1]]) & 0xFFFF; 37 | 38 | 39 | #define MT_HASH2_CALC \ 40 | hash2Value = (g_CrcTable[cur[0]] ^ cur[1]) & (kHash2Size - 1); 41 | 42 | #define MT_HASH3_CALC { \ 43 | UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \ 44 | hash2Value = temp & (kHash2Size - 1); \ 45 | hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } 46 | 47 | #define MT_HASH4_CALC { \ 48 | UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \ 49 | hash2Value = temp & (kHash2Size - 1); \ 50 | hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ 51 | hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & (kHash4Size - 1); } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /lzma/C/Compress/Lz/MatchFinder.h: -------------------------------------------------------------------------------- 1 | /* MatchFinder.h */ 2 | 3 | #ifndef __MATCHFINDER_H 4 | #define __MATCHFINDER_H 5 | 6 | #include "../../IStream.h" 7 | 8 | typedef UInt32 CLzRef; 9 | 10 | typedef struct _CMatchFinder 11 | { 12 | Byte *buffer; 13 | UInt32 pos; 14 | UInt32 posLimit; 15 | UInt32 streamPos; 16 | UInt32 lenLimit; 17 | 18 | UInt32 cyclicBufferPos; 19 | UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ 20 | 21 | UInt32 matchMaxLen; 22 | CLzRef *hash; 23 | CLzRef *son; 24 | UInt32 hashMask; 25 | UInt32 cutValue; 26 | 27 | Byte *bufferBase; 28 | ISeqInStream *stream; 29 | int streamEndWasReached; 30 | 31 | UInt32 blockSize; 32 | UInt32 keepSizeBefore; 33 | UInt32 keepSizeAfter; 34 | 35 | UInt32 numHashBytes; 36 | int directInput; 37 | int btMode; 38 | /* int skipModeBits; */ 39 | int bigHash; 40 | UInt32 historySize; 41 | UInt32 fixedHashSize; 42 | UInt32 hashSizeSum; 43 | UInt32 numSons; 44 | 45 | HRes result; 46 | } CMatchFinder; 47 | 48 | #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer) 49 | #define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[index]) 50 | 51 | #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos) 52 | 53 | int MatchFinder_NeedMove(CMatchFinder *p); 54 | Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); 55 | void MatchFinder_MoveBlock(CMatchFinder *p); 56 | void MatchFinder_ReadIfRequired(CMatchFinder *p); 57 | 58 | void MatchFinder_Construct(CMatchFinder *p); 59 | 60 | /* Conditions: 61 | historySize <= 3 GB 62 | keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB 63 | */ 64 | int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, 65 | UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, 66 | ISzAlloc *alloc); 67 | void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); 68 | void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems); 69 | void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); 70 | 71 | UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, 72 | UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, 73 | UInt32 *distances, UInt32 maxLen); 74 | 75 | /* 76 | Conditions: 77 | Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. 78 | Mf_GetPointerToCurrentPos_Func's result must be used only before any other function 79 | */ 80 | 81 | typedef void (*Mf_Init_Func)(void *object); 82 | typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index); 83 | typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); 84 | typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); 85 | typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances); 86 | typedef void (*Mf_Skip_Func)(void *object, UInt32); 87 | 88 | typedef struct _IMatchFinder 89 | { 90 | Mf_Init_Func Init; 91 | Mf_GetIndexByte_Func GetIndexByte; 92 | Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; 93 | Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; 94 | Mf_GetMatches_Func GetMatches; 95 | Mf_Skip_Func Skip; 96 | } IMatchFinder; 97 | 98 | void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); 99 | 100 | void MatchFinder_Init(CMatchFinder *p); 101 | UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 102 | UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 103 | void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 104 | void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /lzma/C/Compress/Lz/MatchFinderMt.h: -------------------------------------------------------------------------------- 1 | /* MatchFinderMt.h */ 2 | 3 | #ifndef __MATCHFINDERMT_H 4 | #define __MATCHFINDERMT_H 5 | 6 | #include "../../Threads.h" 7 | #include "MatchFinder.h" 8 | 9 | #define kMtHashBlockSize (1 << 13) 10 | #define kMtHashNumBlocks (1 << 3) 11 | #define kMtHashNumBlocksMask (kMtHashNumBlocks - 1) 12 | 13 | #define kMtBtBlockSize (1 << 14) 14 | #define kMtBtNumBlocks (1 << 6) 15 | #define kMtBtNumBlocksMask (kMtBtNumBlocks - 1) 16 | 17 | typedef struct _CMtSync 18 | { 19 | Bool wasCreated; 20 | Bool needStart; 21 | Bool exit; 22 | Bool stopWriting; 23 | 24 | CThread thread; 25 | CAutoResetEvent canStart; 26 | CAutoResetEvent wasStarted; 27 | CAutoResetEvent wasStopped; 28 | CSemaphore freeSemaphore; 29 | CSemaphore filledSemaphore; 30 | Bool csWasInitialized; 31 | Bool csWasEntered; 32 | CCriticalSection cs; 33 | UInt32 numProcessedBlocks; 34 | } CMtSync; 35 | 36 | typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); 37 | 38 | /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ 39 | #define kMtCacheLineDummy 128 40 | 41 | typedef void (*Mf_GetHeads)(const Byte *buffer, size_t pos, 42 | UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads); 43 | 44 | typedef struct _CMatchFinderMt 45 | { 46 | /* LZ */ 47 | const Byte *pointerToCurPos; 48 | UInt32 *btBuf; 49 | UInt32 btBufPos; 50 | UInt32 btBufPosLimit; 51 | UInt32 lzPos; 52 | UInt32 btNumAvailBytes; 53 | 54 | UInt32 *hash; 55 | UInt32 fixedHashSize; 56 | UInt32 historySize; 57 | 58 | Mf_Mix_Matches MixMatchesFunc; 59 | 60 | /* LZ + BT */ 61 | CMtSync btSync; 62 | Byte btDummy[kMtCacheLineDummy]; 63 | 64 | /* BT */ 65 | UInt32 *hashBuf; 66 | UInt32 hashBufPos; 67 | UInt32 hashBufPosLimit; 68 | UInt32 hashNumAvail; 69 | 70 | CLzRef *son; 71 | UInt32 matchMaxLen; 72 | UInt32 numHashBytes; 73 | UInt32 pos; 74 | Byte *buffer; 75 | UInt32 cyclicBufferPos; 76 | UInt32 cyclicBufferSize; /* it must be historySize + 1 */ 77 | UInt32 cutValue; 78 | 79 | /* BT + Hash */ 80 | CMtSync hashSync; 81 | /* Byte hashDummy[kMtCacheLineDummy]; */ 82 | 83 | /* Hash */ 84 | Mf_GetHeads GetHeadsFunc; 85 | CMatchFinder *MatchFinder; 86 | } CMatchFinderMt; 87 | 88 | void MatchFinderMt_Construct(CMatchFinderMt *p); 89 | void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc); 90 | HRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, 91 | UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc); 92 | void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable); 93 | void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /lzma/C/Istream.h: -------------------------------------------------------------------------------- 1 | /* IStream.h */ 2 | 3 | #ifndef __C_ISTREAM_H 4 | #define __C_ISTREAM_H 5 | 6 | #include "Types.h" 7 | 8 | typedef struct _ISeqInStream 9 | { 10 | HRes (*Read)(void *object, void *data, UInt32 size, UInt32 *processedSize); 11 | } ISeqInStream; 12 | 13 | typedef struct _ISzAlloc 14 | { 15 | void *(*Alloc)(size_t size); 16 | void (*Free)(void *address); /* address can be 0 */ 17 | } ISzAlloc; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lzma/C/Threads.c: -------------------------------------------------------------------------------- 1 | /* Threads.c */ 2 | 3 | #include "Threads.h" 4 | #include 5 | 6 | HRes GetError() 7 | { 8 | DWORD res = GetLastError(); 9 | return (res) ? (HRes)(res) : SZE_FAIL; 10 | } 11 | 12 | HRes BoolToHRes(int v) { return v ? SZ_OK : GetError(); } 13 | HRes BOOLToHRes(BOOL v) { return v ? SZ_OK : GetError(); } 14 | 15 | HRes MyCloseHandle(HANDLE *h) 16 | { 17 | if (*h != NULL) 18 | if (!CloseHandle(*h)) 19 | return GetError(); 20 | *h = NULL; 21 | return SZ_OK; 22 | } 23 | 24 | HRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter) 25 | { 26 | unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ 27 | thread->handle = 28 | /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */ 29 | (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId); 30 | /* maybe we must use errno here, but probably GetLastError() is also OK. */ 31 | return BoolToHRes(thread->handle != 0); 32 | } 33 | 34 | HRes WaitObject(HANDLE h) 35 | { 36 | return (HRes)WaitForSingleObject(h, INFINITE); 37 | } 38 | 39 | HRes Thread_Wait(CThread *thread) 40 | { 41 | if (thread->handle == NULL) 42 | return 1; 43 | return WaitObject(thread->handle); 44 | } 45 | 46 | HRes Thread_Close(CThread *thread) 47 | { 48 | return MyCloseHandle(&thread->handle); 49 | } 50 | 51 | HRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled) 52 | { 53 | p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL); 54 | return BoolToHRes(p->handle != 0); 55 | } 56 | 57 | HRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled) 58 | { return Event_Create(p, TRUE, initialSignaled); } 59 | HRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) 60 | { return ManualResetEvent_Create(p, 0); } 61 | 62 | HRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled) 63 | { return Event_Create(p, FALSE, initialSignaled); } 64 | HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) 65 | { return AutoResetEvent_Create(p, 0); } 66 | 67 | HRes Event_Set(CEvent *p) { return BOOLToHRes(SetEvent(p->handle)); } 68 | HRes Event_Reset(CEvent *p) { return BOOLToHRes(ResetEvent(p->handle)); } 69 | HRes Event_Wait(CEvent *p) { return WaitObject(p->handle); } 70 | HRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); } 71 | 72 | 73 | HRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount) 74 | { 75 | p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL); 76 | return BoolToHRes(p->handle != 0); 77 | } 78 | 79 | HRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) 80 | { 81 | return BOOLToHRes(ReleaseSemaphore(p->handle, releaseCount, previousCount)); 82 | } 83 | HRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount) 84 | { 85 | return Semaphore_Release(p, (LONG)releaseCount, NULL); 86 | } 87 | HRes Semaphore_Release1(CSemaphore *p) 88 | { 89 | return Semaphore_ReleaseN(p, 1); 90 | } 91 | 92 | HRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); } 93 | HRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); } 94 | 95 | HRes CriticalSection_Init(CCriticalSection *p) 96 | { 97 | /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */ 98 | __try 99 | { 100 | InitializeCriticalSection(p); 101 | /* InitializeCriticalSectionAndSpinCount(p, 0); */ 102 | } 103 | __except (EXCEPTION_EXECUTE_HANDLER) { return SZE_OUTOFMEMORY; } 104 | return SZ_OK; 105 | } 106 | 107 | -------------------------------------------------------------------------------- /lzma/C/Threads.h: -------------------------------------------------------------------------------- 1 | /* Threads.h */ 2 | 3 | #ifndef __7Z_THRESDS_H 4 | #define __7Z_THRESDS_H 5 | 6 | #include 7 | 8 | #include "Types.h" 9 | 10 | typedef struct _CThread 11 | { 12 | HANDLE handle; 13 | } CThread; 14 | 15 | #define Thread_Construct(thread) (thread)->handle = NULL 16 | #define Thread_WasCreated(thread) ((thread)->handle != NULL) 17 | 18 | typedef unsigned THREAD_FUNC_RET_TYPE; 19 | #define THREAD_FUNC_CALL_TYPE StdCall 20 | #define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE 21 | 22 | HRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter); 23 | HRes Thread_Wait(CThread *thread); 24 | HRes Thread_Close(CThread *thread); 25 | 26 | typedef struct _CEvent 27 | { 28 | HANDLE handle; 29 | } CEvent; 30 | 31 | typedef CEvent CAutoResetEvent; 32 | typedef CEvent CManualResetEvent; 33 | 34 | #define Event_Construct(event) (event)->handle = NULL 35 | #define Event_IsCreated(event) ((event)->handle != NULL) 36 | 37 | HRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled); 38 | HRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event); 39 | HRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled); 40 | HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event); 41 | HRes Event_Set(CEvent *event); 42 | HRes Event_Reset(CEvent *event); 43 | HRes Event_Wait(CEvent *event); 44 | HRes Event_Close(CEvent *event); 45 | 46 | 47 | typedef struct _CSemaphore 48 | { 49 | HANDLE handle; 50 | } CSemaphore; 51 | 52 | #define Semaphore_Construct(p) (p)->handle = NULL 53 | 54 | HRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount); 55 | HRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); 56 | HRes Semaphore_Release1(CSemaphore *p); 57 | HRes Semaphore_Wait(CSemaphore *p); 58 | HRes Semaphore_Close(CSemaphore *p); 59 | 60 | 61 | typedef CRITICAL_SECTION CCriticalSection; 62 | 63 | HRes CriticalSection_Init(CCriticalSection *p); 64 | #define CriticalSection_Delete(p) DeleteCriticalSection(p) 65 | #define CriticalSection_Enter(p) EnterCriticalSection(p) 66 | #define CriticalSection_Leave(p) LeaveCriticalSection(p) 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /lzma/C/Types.h: -------------------------------------------------------------------------------- 1 | /* 7zTypes.h */ 2 | 3 | #ifndef __C_TYPES_H 4 | #define __C_TYPES_H 5 | 6 | #ifndef _7ZIP_BYTE_DEFINED 7 | #define _7ZIP_BYTE_DEFINED 8 | typedef unsigned char Byte; 9 | #endif 10 | 11 | #ifndef _7ZIP_UINT16_DEFINED 12 | #define _7ZIP_UINT16_DEFINED 13 | typedef unsigned short UInt16; 14 | #endif 15 | 16 | #ifndef _7ZIP_UINT32_DEFINED 17 | #define _7ZIP_UINT32_DEFINED 18 | #ifdef _LZMA_UINT32_IS_ULONG 19 | typedef unsigned long UInt32; 20 | #else 21 | typedef unsigned int UInt32; 22 | #endif 23 | #endif 24 | 25 | #ifndef _7ZIP_INT32_DEFINED 26 | #define _7ZIP_INT32_DEFINED 27 | #ifdef _LZMA_INT32_IS_ULONG 28 | typedef long Int32; 29 | #else 30 | typedef int Int32; 31 | #endif 32 | #endif 33 | 34 | /* #define _SZ_NO_INT_64 */ 35 | /* define it your compiler doesn't support long long int */ 36 | 37 | #ifndef _7ZIP_UINT64_DEFINED 38 | #define _7ZIP_UINT64_DEFINED 39 | #ifdef _SZ_NO_INT_64 40 | typedef unsigned long UInt64; 41 | #else 42 | #if defined(_MSC_VER) || defined(__BORLANDC__) 43 | typedef unsigned __int64 UInt64; 44 | #else 45 | typedef unsigned long long int UInt64; 46 | #endif 47 | #endif 48 | #endif 49 | 50 | 51 | /* #define _SZ_FILE_SIZE_32 */ 52 | /* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/ 53 | 54 | #ifndef CFileSize 55 | #ifdef _SZ_FILE_SIZE_32 56 | typedef UInt32 CFileSize; 57 | #else 58 | typedef UInt64 CFileSize; 59 | #endif 60 | #endif 61 | 62 | #define SZ_RESULT int 63 | 64 | typedef int HRes; 65 | #define RES_OK (0) 66 | 67 | #define SZ_OK (0) 68 | #define SZE_DATA_ERROR (1) 69 | #define SZE_CRC_ERROR (3) 70 | #define SZE_ARCHIVE_ERROR (6) 71 | 72 | #define SZE_OUTOFMEMORY (0x8007000EL) 73 | #define SZE_NOTIMPL (0x80004001L) 74 | #define SZE_FAIL (0x80004005L) 75 | #define SZE_INVALIDARG (0x80070057L) 76 | 77 | 78 | #ifndef RINOK 79 | #define RINOK(x) { HRes __result_ = (x); if(__result_ != 0) return __result_; } 80 | #endif 81 | 82 | typedef int Bool; 83 | #define True 1 84 | #define False 0 85 | 86 | #ifdef _MSC_VER 87 | #define StdCall __stdcall 88 | #else 89 | #define StdCall 90 | #endif 91 | 92 | #if _MSC_VER >= 1300 93 | #define MY_FAST_CALL __declspec(noinline) __fastcall 94 | #elif defined( _MSC_VER) 95 | #define MY_FAST_CALL __fastcall 96 | #else 97 | #define MY_FAST_CALL 98 | #endif 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Common/Inbuffer.cpp: -------------------------------------------------------------------------------- 1 | // InBuffer.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "InBuffer.h" 6 | 7 | extern "C" 8 | { 9 | #include "../../../C/Alloc.h" 10 | } 11 | 12 | CInBuffer::CInBuffer(): 13 | _buffer(0), 14 | _bufferLimit(0), 15 | _bufferBase(0), 16 | _stream(0), 17 | _bufferSize(0) 18 | {} 19 | 20 | bool CInBuffer::Create(UInt32 bufferSize) 21 | { 22 | const UInt32 kMinBlockSize = 1; 23 | if (bufferSize < kMinBlockSize) 24 | bufferSize = kMinBlockSize; 25 | if (_bufferBase != 0 && _bufferSize == bufferSize) 26 | return true; 27 | Free(); 28 | _bufferSize = bufferSize; 29 | _bufferBase = (Byte *)::MidAlloc(bufferSize); 30 | return (_bufferBase != 0); 31 | } 32 | 33 | void CInBuffer::Free() 34 | { 35 | ::MidFree(_bufferBase); 36 | _bufferBase = 0; 37 | } 38 | 39 | void CInBuffer::SetStream(ISequentialInStream *stream) 40 | { 41 | _stream = stream; 42 | } 43 | 44 | void CInBuffer::Init() 45 | { 46 | _processedSize = 0; 47 | _buffer = _bufferBase; 48 | _bufferLimit = _buffer; 49 | _wasFinished = false; 50 | #ifdef _NO_EXCEPTIONS 51 | ErrorCode = S_OK; 52 | #endif 53 | } 54 | 55 | bool CInBuffer::ReadBlock() 56 | { 57 | #ifdef _NO_EXCEPTIONS 58 | if (ErrorCode != S_OK) 59 | return false; 60 | #endif 61 | if (_wasFinished) 62 | return false; 63 | _processedSize += (_buffer - _bufferBase); 64 | UInt32 numProcessedBytes; 65 | HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes); 66 | #ifdef _NO_EXCEPTIONS 67 | ErrorCode = result; 68 | #else 69 | if (result != S_OK) 70 | throw CInBufferException(result); 71 | #endif 72 | _buffer = _bufferBase; 73 | _bufferLimit = _buffer + numProcessedBytes; 74 | _wasFinished = (numProcessedBytes == 0); 75 | return (!_wasFinished); 76 | } 77 | 78 | Byte CInBuffer::ReadBlock2() 79 | { 80 | if(!ReadBlock()) 81 | return 0xFF; 82 | return *_buffer++; 83 | } 84 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Common/Inbuffer.h: -------------------------------------------------------------------------------- 1 | // InBuffer.h 2 | 3 | #ifndef __INBUFFER_H 4 | #define __INBUFFER_H 5 | 6 | #include "../IStream.h" 7 | #include "../../Common/MyCom.h" 8 | #include "../../Common/MyException.h" 9 | 10 | #ifndef _NO_EXCEPTIONS 11 | struct CInBufferException: public CSystemException 12 | { 13 | CInBufferException(HRESULT errorCode): CSystemException(errorCode) {} 14 | }; 15 | #endif 16 | 17 | class CInBuffer 18 | { 19 | Byte *_buffer; 20 | Byte *_bufferLimit; 21 | Byte *_bufferBase; 22 | CMyComPtr _stream; 23 | UInt64 _processedSize; 24 | UInt32 _bufferSize; 25 | bool _wasFinished; 26 | 27 | bool ReadBlock(); 28 | Byte ReadBlock2(); 29 | 30 | public: 31 | #ifdef _NO_EXCEPTIONS 32 | HRESULT ErrorCode; 33 | #endif 34 | 35 | CInBuffer(); 36 | ~CInBuffer() { Free(); } 37 | 38 | bool Create(UInt32 bufferSize); 39 | void Free(); 40 | 41 | void SetStream(ISequentialInStream *stream); 42 | void Init(); 43 | void ReleaseStream() { _stream.Release(); } 44 | 45 | bool ReadByte(Byte &b) 46 | { 47 | if(_buffer >= _bufferLimit) 48 | if(!ReadBlock()) 49 | return false; 50 | b = *_buffer++; 51 | return true; 52 | } 53 | Byte ReadByte() 54 | { 55 | if(_buffer >= _bufferLimit) 56 | return ReadBlock2(); 57 | return *_buffer++; 58 | } 59 | void ReadBytes(void *data, UInt32 size, UInt32 &processedSize) 60 | { 61 | for(processedSize = 0; processedSize < size; processedSize++) 62 | if (!ReadByte(((Byte *)data)[processedSize])) 63 | return; 64 | } 65 | bool ReadBytes(void *data, UInt32 size) 66 | { 67 | UInt32 processedSize; 68 | ReadBytes(data, size, processedSize); 69 | return (processedSize == size); 70 | } 71 | UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); } 72 | bool WasFinished() const { return _wasFinished; } 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Common/OutBuffer.cpp: -------------------------------------------------------------------------------- 1 | // OutByte.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "OutBuffer.h" 6 | 7 | extern "C" 8 | { 9 | #include "../../../C/Alloc.h" 10 | } 11 | 12 | bool COutBuffer::Create(UInt32 bufferSize) 13 | { 14 | const UInt32 kMinBlockSize = 1; 15 | if (bufferSize < kMinBlockSize) 16 | bufferSize = kMinBlockSize; 17 | if (_buffer != 0 && _bufferSize == bufferSize) 18 | return true; 19 | Free(); 20 | _bufferSize = bufferSize; 21 | _buffer = (Byte *)::MidAlloc(bufferSize); 22 | return (_buffer != 0); 23 | } 24 | 25 | void COutBuffer::Free() 26 | { 27 | ::MidFree(_buffer); 28 | _buffer = 0; 29 | } 30 | 31 | void COutBuffer::SetStream(ISequentialOutStream *stream) 32 | { 33 | _stream = stream; 34 | } 35 | 36 | void COutBuffer::Init() 37 | { 38 | _streamPos = 0; 39 | _limitPos = _bufferSize; 40 | _pos = 0; 41 | _processedSize = 0; 42 | _overDict = false; 43 | #ifdef _NO_EXCEPTIONS 44 | ErrorCode = S_OK; 45 | #endif 46 | } 47 | 48 | UInt64 COutBuffer::GetProcessedSize() const 49 | { 50 | UInt64 res = _processedSize + _pos - _streamPos; 51 | if (_streamPos > _pos) 52 | res += _bufferSize; 53 | return res; 54 | } 55 | 56 | 57 | HRESULT COutBuffer::FlushPart() 58 | { 59 | // _streamPos < _bufferSize 60 | UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos); 61 | HRESULT result = S_OK; 62 | #ifdef _NO_EXCEPTIONS 63 | result = ErrorCode; 64 | #endif 65 | if (_buffer2 != 0) 66 | { 67 | memmove(_buffer2, _buffer + _streamPos, size); 68 | _buffer2 += size; 69 | } 70 | 71 | if (_stream != 0 72 | #ifdef _NO_EXCEPTIONS 73 | && (ErrorCode == S_OK) 74 | #endif 75 | ) 76 | { 77 | UInt32 processedSize = 0; 78 | result = _stream->Write(_buffer + _streamPos, size, &processedSize); 79 | size = processedSize; 80 | } 81 | _streamPos += size; 82 | if (_streamPos == _bufferSize) 83 | _streamPos = 0; 84 | if (_pos == _bufferSize) 85 | { 86 | _overDict = true; 87 | _pos = 0; 88 | } 89 | _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize; 90 | _processedSize += size; 91 | return result; 92 | } 93 | 94 | HRESULT COutBuffer::Flush() 95 | { 96 | #ifdef _NO_EXCEPTIONS 97 | if (ErrorCode != S_OK) 98 | return ErrorCode; 99 | #endif 100 | 101 | while(_streamPos != _pos) 102 | { 103 | HRESULT result = FlushPart(); 104 | if (result != S_OK) 105 | return result; 106 | } 107 | return S_OK; 108 | } 109 | 110 | void COutBuffer::FlushWithCheck() 111 | { 112 | HRESULT result = FlushPart(); 113 | #ifdef _NO_EXCEPTIONS 114 | ErrorCode = result; 115 | #else 116 | if (result != S_OK) 117 | throw COutBufferException(result); 118 | #endif 119 | } 120 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Common/OutBuffer.h: -------------------------------------------------------------------------------- 1 | // OutBuffer.h 2 | 3 | #ifndef __OUTBUFFER_H 4 | #define __OUTBUFFER_H 5 | 6 | #include "../IStream.h" 7 | #include "../../Common/MyCom.h" 8 | #include "../../Common/MyException.h" 9 | 10 | #ifndef _NO_EXCEPTIONS 11 | struct COutBufferException: public CSystemException 12 | { 13 | COutBufferException(HRESULT errorCode): CSystemException(errorCode) {} 14 | }; 15 | #endif 16 | 17 | class COutBuffer 18 | { 19 | protected: 20 | Byte *_buffer; 21 | UInt32 _pos; 22 | UInt32 _limitPos; 23 | UInt32 _streamPos; 24 | UInt32 _bufferSize; 25 | CMyComPtr _stream; 26 | UInt64 _processedSize; 27 | Byte *_buffer2; 28 | bool _overDict; 29 | 30 | HRESULT FlushPart(); 31 | public: 32 | #ifdef _NO_EXCEPTIONS 33 | HRESULT ErrorCode; 34 | #endif 35 | 36 | COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {} 37 | ~COutBuffer() { Free(); } 38 | 39 | bool Create(UInt32 bufferSize); 40 | void Free(); 41 | 42 | void SetMemStream(Byte *buffer) { _buffer2 = buffer; } 43 | void SetStream(ISequentialOutStream *stream); 44 | void Init(); 45 | HRESULT Flush(); 46 | void FlushWithCheck(); 47 | void ReleaseStream() { _stream.Release(); } 48 | 49 | void WriteByte(Byte b) 50 | { 51 | _buffer[_pos++] = b; 52 | if(_pos == _limitPos) 53 | FlushWithCheck(); 54 | } 55 | void WriteBytes(const void *data, size_t size) 56 | { 57 | for (size_t i = 0; i < size; i++) 58 | WriteByte(((const Byte *)data)[i]); 59 | } 60 | 61 | UInt64 GetProcessedSize() const; 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Common/Stdafx.h: -------------------------------------------------------------------------------- 1 | // StdAfx.h 2 | 3 | #ifndef __STDAFX_H 4 | #define __STDAFX_H 5 | 6 | #include "../../Common/MyWindows.h" 7 | #include "../../Common/NewHandler.h" 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Common/StreamUtils.cpp: -------------------------------------------------------------------------------- 1 | // StreamUtils.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../../Common/MyCom.h" 6 | #include "StreamUtils.h" 7 | 8 | HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize) 9 | { 10 | if (processedSize != 0) 11 | *processedSize = 0; 12 | while(size != 0) 13 | { 14 | UInt32 processedSizeLoc; 15 | HRESULT res = stream->Read(data, size, &processedSizeLoc); 16 | if (processedSize != 0) 17 | *processedSize += processedSizeLoc; 18 | data = (Byte *)((Byte *)data + processedSizeLoc); 19 | size -= processedSizeLoc; 20 | RINOK(res); 21 | if (processedSizeLoc == 0) 22 | return S_OK; 23 | } 24 | return S_OK; 25 | } 26 | 27 | HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize) 28 | { 29 | if (processedSize != 0) 30 | *processedSize = 0; 31 | while(size != 0) 32 | { 33 | UInt32 processedSizeLoc; 34 | HRESULT res = stream->Write(data, size, &processedSizeLoc); 35 | if (processedSize != 0) 36 | *processedSize += processedSizeLoc; 37 | data = (const void *)((const Byte *)data + processedSizeLoc); 38 | size -= processedSizeLoc; 39 | RINOK(res); 40 | if (processedSizeLoc == 0) 41 | break; 42 | } 43 | return S_OK; 44 | } 45 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Common/StreamUtils.h: -------------------------------------------------------------------------------- 1 | // StreamUtils.h 2 | 3 | #ifndef __STREAMUTILS_H 4 | #define __STREAMUTILS_H 5 | 6 | #include "../IStream.h" 7 | 8 | HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize); 9 | HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/ISLZMA/ISLZMA.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 25 | 28 | 31 | 34 | 37 | 40 | 52 | 55 | 58 | 61 | 71 | 74 | 77 | 80 | 83 | 86 | 89 | 92 | 95 | 96 | 104 | 107 | 110 | 113 | 116 | 119 | 128 | 131 | 134 | 137 | 148 | 151 | 154 | 157 | 160 | 163 | 166 | 169 | 172 | 173 | 174 | 175 | 176 | 177 | 180 | 183 | 184 | 187 | 188 | 189 | 192 | 195 | 198 | 199 | 202 | 203 | 206 | 207 | 208 | 211 | 214 | 215 | 218 | 219 | 222 | 223 | 226 | 227 | 230 | 231 | 232 | 233 | 236 | 239 | 240 | 243 | 244 | 247 | 248 | 251 | 252 | 255 | 256 | 259 | 260 | 263 | 264 | 267 | 268 | 269 | 272 | 275 | 276 | 279 | 280 | 283 | 284 | 287 | 288 | 291 | 292 | 295 | 296 | 297 | 300 | 303 | 304 | 307 | 308 | 311 | 312 | 315 | 316 | 319 | 320 | 323 | 326 | 327 | 330 | 331 | 334 | 335 | 338 | 339 | 342 | 343 | 346 | 347 | 348 | 349 | 352 | 353 | 356 | 357 | 360 | 361 | 362 | 363 | 364 | 365 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/ISLZMA/ISLZMA_DllExports.cpp: -------------------------------------------------------------------------------- 1 | // ISLZMA_DLLExports.cpp, by Jordan Russell for Inno Setup 2 | // This file may be used under the same license terms as the LZMA SDK. 3 | // $jrsoftware: iscompress/lzma/CPP/7zip/Compress/ISLZMA/ISLZMA_DllExports.cpp,v 1.4 2007/08/02 20:20:10 jr Exp $ 4 | 5 | #include "StdAfx.h" 6 | 7 | // #include 8 | #define INITGUID 9 | 10 | #include "../LZMA/LZMAEncoder.h" 11 | #include "../../../Common/NewHandler.h" 12 | 13 | extern "C" 14 | BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) 15 | { 16 | return TRUE; 17 | } 18 | 19 | HRESULT __stdcall LZMA_Init(void **handle) 20 | { 21 | try 22 | { 23 | NCompress::NLZMA::CEncoder *encoder = new NCompress::NLZMA::CEncoder(); 24 | encoder->SetWriteEndMarkerMode(true); 25 | *handle = encoder; 26 | return S_OK; 27 | } 28 | catch(CNewException) 29 | { 30 | return E_OUTOFMEMORY; 31 | } 32 | catch(...) 33 | { 34 | return E_FAIL; 35 | } 36 | } 37 | 38 | HRESULT __stdcall LZMA_SetProps(void *handle, unsigned algorithm, unsigned dicSize, unsigned numFastBytes, 39 | const LPCWSTR matchFinder, unsigned numThreads) 40 | { 41 | NCompress::NLZMA::CEncoder *encoder = reinterpret_cast(handle); 42 | 43 | PROPID propdIDs[] = 44 | { 45 | NCoderPropID::kAlgorithm, 46 | NCoderPropID::kDictionarySize, 47 | NCoderPropID::kNumFastBytes, 48 | NCoderPropID::kMatchFinder, 49 | NCoderPropID::kNumThreads 50 | }; 51 | const int kNumProps = sizeof(propdIDs) / sizeof(propdIDs[0]); 52 | PROPVARIANT props[kNumProps]; 53 | 54 | // NCoderPropID::kAlgorithm 55 | props[0].vt = VT_UI4; 56 | props[0].ulVal = algorithm; 57 | // NCoderPropID::kDictionarySize 58 | props[1].vt = VT_UI4; 59 | props[1].ulVal = dicSize; 60 | // NCoderPropID::kNumFastBytes 61 | props[2].vt = VT_UI4; 62 | props[2].ulVal = numFastBytes; 63 | // NCoderPropID::kMatchFinder 64 | props[3].vt = VT_BSTR; 65 | if (!(props[3].bstrVal = ::SysAllocString(matchFinder))) 66 | { 67 | return E_OUTOFMEMORY; 68 | } 69 | // NCoderPropID::kNumThreads 70 | props[4].vt = VT_UI4; 71 | props[4].ulVal = numThreads; 72 | 73 | HRESULT res = encoder->SetCoderProperties(propdIDs, props, kNumProps); 74 | ::SysFreeString(props[3].bstrVal); // matchFinder 75 | return res; 76 | } 77 | 78 | HRESULT __stdcall LZMA_Encode(void *handle, ISequentialInStream *in_stream, ISequentialOutStream *out_stream, 79 | ICompressProgressInfo *progress) 80 | { 81 | try 82 | { 83 | NCompress::NLZMA::CEncoder *encoder = reinterpret_cast(handle); 84 | HRESULT res; 85 | 86 | res = encoder->WriteCoderProperties(out_stream); 87 | if (res == S_OK) 88 | { 89 | res = encoder->Code(in_stream, out_stream, NULL, NULL, progress); 90 | } 91 | return res; 92 | } 93 | catch(...) 94 | { 95 | return E_FAIL; 96 | } 97 | } 98 | 99 | HRESULT __stdcall LZMA_End(void *handle) 100 | { 101 | try 102 | { 103 | NCompress::NLZMA::CEncoder *encoder = reinterpret_cast(handle); 104 | delete encoder; 105 | return S_OK; 106 | } 107 | catch(...) 108 | { 109 | return E_FAIL; 110 | } 111 | } -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/ISLZMA/Islzma.def: -------------------------------------------------------------------------------- 1 | LIBRARY ISLZMA 2 | 3 | EXPORTS 4 | LZMA_Init 5 | LZMA_SetProps2 = LZMA_SetProps 6 | LZMA_Encode2 = LZMA_Encode 7 | LZMA_End 8 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/ISLZMA/Islzma.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ISLZMA", "ISLZMA.vcproj", "{7FD65FFF-6F90-4D0E-8C43-0084FFE24EFB}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {7FD65FFF-6F90-4D0E-8C43-0084FFE24EFB}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {7FD65FFF-6F90-4D0E-8C43-0084FFE24EFB}.Debug|Win32.Build.0 = Debug|Win32 14 | {7FD65FFF-6F90-4D0E-8C43-0084FFE24EFB}.Release|Win32.ActiveCfg = Release|Win32 15 | {7FD65FFF-6F90-4D0E-8C43-0084FFE24EFB}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/ISLZMA/Stdafx.cpp: -------------------------------------------------------------------------------- 1 | // StdAfx.cpp 2 | 3 | #include "StdAfx.h" 4 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/ISLZMA/Stdafx.h: -------------------------------------------------------------------------------- 1 | // StdAfx.h 2 | 3 | #ifndef __STDAFX_H 4 | #define __STDAFX_H 5 | 6 | #include "../../../Common/MyWindows.h" 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/LZMA/Lzma.h: -------------------------------------------------------------------------------- 1 | // LZMA.h 2 | 3 | #ifndef __LZMA_H 4 | #define __LZMA_H 5 | 6 | namespace NCompress { 7 | namespace NLZMA { 8 | 9 | const UInt32 kNumRepDistances = 4; 10 | 11 | const int kNumStates = 12; 12 | 13 | const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5}; 14 | const Byte kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10}; 15 | const Byte kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11}; 16 | const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11}; 17 | 18 | class CState 19 | { 20 | public: 21 | Byte Index; 22 | void Init() { Index = 0; } 23 | void UpdateChar() { Index = kLiteralNextStates[Index]; } 24 | void UpdateMatch() { Index = kMatchNextStates[Index]; } 25 | void UpdateRep() { Index = kRepNextStates[Index]; } 26 | void UpdateShortRep() { Index = kShortRepNextStates[Index]; } 27 | bool IsCharState() const { return Index < 7; } 28 | }; 29 | 30 | const int kNumPosSlotBits = 6; 31 | const int kDicLogSizeMin = 0; 32 | const int kDicLogSizeMax = 32; 33 | const int kDistTableSizeMax = kDicLogSizeMax * 2; 34 | 35 | const UInt32 kNumLenToPosStates = 4; 36 | 37 | inline UInt32 GetLenToPosState(UInt32 len) 38 | { 39 | len -= 2; 40 | if (len < kNumLenToPosStates) 41 | return len; 42 | return kNumLenToPosStates - 1; 43 | } 44 | 45 | namespace NLength { 46 | 47 | const int kNumPosStatesBitsMax = 4; 48 | const UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax); 49 | 50 | const int kNumPosStatesBitsEncodingMax = 4; 51 | const UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax); 52 | 53 | const int kNumLowBits = 3; 54 | const int kNumMidBits = 3; 55 | const int kNumHighBits = 8; 56 | const UInt32 kNumLowSymbols = 1 << kNumLowBits; 57 | const UInt32 kNumMidSymbols = 1 << kNumMidBits; 58 | const UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits); 59 | 60 | } 61 | 62 | const UInt32 kMatchMinLen = 2; 63 | const UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1; 64 | 65 | const int kNumAlignBits = 4; 66 | const UInt32 kAlignTableSize = 1 << kNumAlignBits; 67 | const UInt32 kAlignMask = (kAlignTableSize - 1); 68 | 69 | const UInt32 kStartPosModelIndex = 4; 70 | const UInt32 kEndPosModelIndex = 14; 71 | const UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; 72 | 73 | const UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2); 74 | 75 | const int kNumLitPosStatesBitsEncodingMax = 4; 76 | const int kNumLitContextBitsMax = 8; 77 | 78 | const int kNumMoveBits = 5; 79 | 80 | }} 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/LZMA/Stdafx.cpp: -------------------------------------------------------------------------------- 1 | // StdAfx.cpp 2 | 3 | #include "StdAfx.h" 4 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/LZMA/Stdafx.h: -------------------------------------------------------------------------------- 1 | // StdAfx.h 2 | 3 | #ifndef __STDAFX_H 4 | #define __STDAFX_H 5 | 6 | #include "../../../Common/MyWindows.h" 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/RangeCoder/RangeCoder.h: -------------------------------------------------------------------------------- 1 | // Compress/RangeCoder/RangeCoder.h 2 | 3 | #ifndef __COMPRESS_RANGECODER_H 4 | #define __COMPRESS_RANGECODER_H 5 | 6 | #include "../../Common/InBuffer.h" 7 | #include "../../Common/OutBuffer.h" 8 | 9 | namespace NCompress { 10 | namespace NRangeCoder { 11 | 12 | const int kNumTopBits = 24; 13 | const UInt32 kTopValue = (1 << kNumTopBits); 14 | 15 | class CEncoder 16 | { 17 | UInt32 _cacheSize; 18 | Byte _cache; 19 | public: 20 | UInt64 Low; 21 | UInt32 Range; 22 | COutBuffer Stream; 23 | bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); } 24 | 25 | void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); } 26 | void Init() 27 | { 28 | Stream.Init(); 29 | Low = 0; 30 | Range = 0xFFFFFFFF; 31 | _cacheSize = 1; 32 | _cache = 0; 33 | } 34 | 35 | void FlushData() 36 | { 37 | // Low += 1; 38 | for(int i = 0; i < 5; i++) 39 | ShiftLow(); 40 | } 41 | 42 | HRESULT FlushStream() { return Stream.Flush(); } 43 | 44 | void ReleaseStream() { Stream.ReleaseStream(); } 45 | 46 | void Encode(UInt32 start, UInt32 size, UInt32 total) 47 | { 48 | Low += start * (Range /= total); 49 | Range *= size; 50 | while (Range < kTopValue) 51 | { 52 | Range <<= 8; 53 | ShiftLow(); 54 | } 55 | } 56 | 57 | void ShiftLow() 58 | { 59 | if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) 60 | { 61 | Byte temp = _cache; 62 | do 63 | { 64 | Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32))); 65 | temp = 0xFF; 66 | } 67 | while(--_cacheSize != 0); 68 | _cache = (Byte)((UInt32)Low >> 24); 69 | } 70 | _cacheSize++; 71 | Low = (UInt32)Low << 8; 72 | } 73 | 74 | void EncodeDirectBits(UInt32 value, int numTotalBits) 75 | { 76 | for (int i = numTotalBits - 1; i >= 0; i--) 77 | { 78 | Range >>= 1; 79 | if (((value >> i) & 1) == 1) 80 | Low += Range; 81 | if (Range < kTopValue) 82 | { 83 | Range <<= 8; 84 | ShiftLow(); 85 | } 86 | } 87 | } 88 | 89 | void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol) 90 | { 91 | UInt32 newBound = (Range >> numTotalBits) * size0; 92 | if (symbol == 0) 93 | Range = newBound; 94 | else 95 | { 96 | Low += newBound; 97 | Range -= newBound; 98 | } 99 | while (Range < kTopValue) 100 | { 101 | Range <<= 8; 102 | ShiftLow(); 103 | } 104 | } 105 | 106 | UInt64 GetProcessedSize() { return Stream.GetProcessedSize() + _cacheSize + 4; } 107 | }; 108 | 109 | class CDecoder 110 | { 111 | public: 112 | CInBuffer Stream; 113 | UInt32 Range; 114 | UInt32 Code; 115 | bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); } 116 | 117 | void Normalize() 118 | { 119 | while (Range < kTopValue) 120 | { 121 | Code = (Code << 8) | Stream.ReadByte(); 122 | Range <<= 8; 123 | } 124 | } 125 | 126 | void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); } 127 | void Init() 128 | { 129 | Stream.Init(); 130 | Code = 0; 131 | Range = 0xFFFFFFFF; 132 | for(int i = 0; i < 5; i++) 133 | Code = (Code << 8) | Stream.ReadByte(); 134 | } 135 | 136 | void ReleaseStream() { Stream.ReleaseStream(); } 137 | 138 | UInt32 GetThreshold(UInt32 total) 139 | { 140 | return (Code) / ( Range /= total); 141 | } 142 | 143 | void Decode(UInt32 start, UInt32 size) 144 | { 145 | Code -= start * Range; 146 | Range *= size; 147 | Normalize(); 148 | } 149 | 150 | UInt32 DecodeDirectBits(int numTotalBits) 151 | { 152 | UInt32 range = Range; 153 | UInt32 code = Code; 154 | UInt32 result = 0; 155 | for (int i = numTotalBits; i != 0; i--) 156 | { 157 | range >>= 1; 158 | /* 159 | result <<= 1; 160 | if (code >= range) 161 | { 162 | code -= range; 163 | result |= 1; 164 | } 165 | */ 166 | UInt32 t = (code - range) >> 31; 167 | code -= range & (t - 1); 168 | result = (result << 1) | (1 - t); 169 | 170 | if (range < kTopValue) 171 | { 172 | code = (code << 8) | Stream.ReadByte(); 173 | range <<= 8; 174 | } 175 | } 176 | Range = range; 177 | Code = code; 178 | return result; 179 | } 180 | 181 | UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits) 182 | { 183 | UInt32 newBound = (Range >> numTotalBits) * size0; 184 | UInt32 symbol; 185 | if (Code < newBound) 186 | { 187 | symbol = 0; 188 | Range = newBound; 189 | } 190 | else 191 | { 192 | symbol = 1; 193 | Code -= newBound; 194 | Range -= newBound; 195 | } 196 | Normalize(); 197 | return symbol; 198 | } 199 | 200 | UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); } 201 | }; 202 | 203 | }} 204 | 205 | #endif 206 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp: -------------------------------------------------------------------------------- 1 | // Compress/RangeCoder/RangeCoderBit.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "RangeCoderBit.h" 6 | 7 | namespace NCompress { 8 | namespace NRangeCoder { 9 | 10 | UInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; 11 | static CPriceTables g_PriceTables; 12 | 13 | CPriceTables::CPriceTables() { Init(); } 14 | 15 | void CPriceTables::Init() 16 | { 17 | const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits); 18 | for(int i = kNumBits - 1; i >= 0; i--) 19 | { 20 | UInt32 start = 1 << (kNumBits - i - 1); 21 | UInt32 end = 1 << (kNumBits - i); 22 | for (UInt32 j = start; j < end; j++) 23 | ProbPrices[j] = (i << kNumBitPriceShiftBits) + 24 | (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1)); 25 | } 26 | 27 | /* 28 | // simplest: bad solution 29 | for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++) 30 | ProbPrices[i] = kBitPrice; 31 | */ 32 | 33 | /* 34 | const double kDummyMultMid = (1.0 / kBitPrice) / 2; 35 | const double kDummyMultMid = 0; 36 | // float solution 37 | double ln2 = log(double(2)); 38 | double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits)); 39 | for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++) 40 | ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice); 41 | */ 42 | 43 | /* 44 | // experimental, slow, solution: 45 | for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++) 46 | { 47 | const int kCyclesBits = 5; 48 | const UInt32 kCycles = (1 << kCyclesBits); 49 | 50 | UInt32 range = UInt32(-1); 51 | UInt32 bitCount = 0; 52 | for (UInt32 j = 0; j < kCycles; j++) 53 | { 54 | range >>= (kNumBitModelTotalBits - kNumMoveReducingBits); 55 | range *= i; 56 | while(range < (1 << 31)) 57 | { 58 | range <<= 1; 59 | bitCount++; 60 | } 61 | } 62 | bitCount <<= kNumBitPriceShiftBits; 63 | range -= (1 << 31); 64 | for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--) 65 | { 66 | range <<= 1; 67 | if (range > (1 << 31)) 68 | { 69 | bitCount += (1 << k); 70 | range -= (1 << 31); 71 | } 72 | } 73 | ProbPrices[i] = (bitCount 74 | // + (1 << (kCyclesBits - 1)) 75 | ) >> kCyclesBits; 76 | } 77 | */ 78 | } 79 | 80 | }} 81 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h: -------------------------------------------------------------------------------- 1 | // Compress/RangeCoder/RangeCoderBit.h 2 | 3 | #ifndef __COMPRESS_RANGECODER_BIT_H 4 | #define __COMPRESS_RANGECODER_BIT_H 5 | 6 | #include "RangeCoder.h" 7 | 8 | namespace NCompress { 9 | namespace NRangeCoder { 10 | 11 | const int kNumBitModelTotalBits = 11; 12 | const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits); 13 | 14 | const int kNumMoveReducingBits = 2; 15 | 16 | const int kNumBitPriceShiftBits = 6; 17 | const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits; 18 | 19 | class CPriceTables 20 | { 21 | public: 22 | static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; 23 | static void Init(); 24 | CPriceTables(); 25 | }; 26 | 27 | template 28 | class CBitModel 29 | { 30 | public: 31 | UInt32 Prob; 32 | void UpdateModel(UInt32 symbol) 33 | { 34 | /* 35 | Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits; 36 | Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits); 37 | */ 38 | if (symbol == 0) 39 | Prob += (kBitModelTotal - Prob) >> numMoveBits; 40 | else 41 | Prob -= (Prob) >> numMoveBits; 42 | } 43 | public: 44 | void Init() { Prob = kBitModelTotal / 2; } 45 | }; 46 | 47 | template 48 | class CBitEncoder: public CBitModel 49 | { 50 | public: 51 | void Encode(CEncoder *encoder, UInt32 symbol) 52 | { 53 | /* 54 | encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol); 55 | this->UpdateModel(symbol); 56 | */ 57 | UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob; 58 | if (symbol == 0) 59 | { 60 | encoder->Range = newBound; 61 | this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits; 62 | } 63 | else 64 | { 65 | encoder->Low += newBound; 66 | encoder->Range -= newBound; 67 | this->Prob -= (this->Prob) >> numMoveBits; 68 | } 69 | if (encoder->Range < kTopValue) 70 | { 71 | encoder->Range <<= 8; 72 | encoder->ShiftLow(); 73 | } 74 | } 75 | UInt32 GetPrice(UInt32 symbol) const 76 | { 77 | return CPriceTables::ProbPrices[ 78 | (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits]; 79 | } 80 | UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; } 81 | UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; } 82 | }; 83 | 84 | 85 | template 86 | class CBitDecoder: public CBitModel 87 | { 88 | public: 89 | UInt32 Decode(CDecoder *decoder) 90 | { 91 | UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob; 92 | if (decoder->Code < newBound) 93 | { 94 | decoder->Range = newBound; 95 | this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits; 96 | if (decoder->Range < kTopValue) 97 | { 98 | decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte(); 99 | decoder->Range <<= 8; 100 | } 101 | return 0; 102 | } 103 | else 104 | { 105 | decoder->Range -= newBound; 106 | decoder->Code -= newBound; 107 | this->Prob -= (this->Prob) >> numMoveBits; 108 | if (decoder->Range < kTopValue) 109 | { 110 | decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte(); 111 | decoder->Range <<= 8; 112 | } 113 | return 1; 114 | } 115 | } 116 | }; 117 | 118 | }} 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h: -------------------------------------------------------------------------------- 1 | // Compress/RangeCoder/RangeCoderBitTree.h 2 | 3 | #ifndef __COMPRESS_RANGECODER_BIT_TREE_H 4 | #define __COMPRESS_RANGECODER_BIT_TREE_H 5 | 6 | #include "RangeCoderBit.h" 7 | #include "RangeCoderOpt.h" 8 | 9 | namespace NCompress { 10 | namespace NRangeCoder { 11 | 12 | template 13 | class CBitTreeEncoder 14 | { 15 | CBitEncoder Models[1 << NumBitLevels]; 16 | public: 17 | void Init() 18 | { 19 | for(UInt32 i = 1; i < (1 << NumBitLevels); i++) 20 | Models[i].Init(); 21 | } 22 | void Encode(CEncoder *rangeEncoder, UInt32 symbol) 23 | { 24 | UInt32 modelIndex = 1; 25 | for (int bitIndex = NumBitLevels; bitIndex != 0 ;) 26 | { 27 | bitIndex--; 28 | UInt32 bit = (symbol >> bitIndex) & 1; 29 | Models[modelIndex].Encode(rangeEncoder, bit); 30 | modelIndex = (modelIndex << 1) | bit; 31 | } 32 | }; 33 | void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol) 34 | { 35 | UInt32 modelIndex = 1; 36 | for (int i = 0; i < NumBitLevels; i++) 37 | { 38 | UInt32 bit = symbol & 1; 39 | Models[modelIndex].Encode(rangeEncoder, bit); 40 | modelIndex = (modelIndex << 1) | bit; 41 | symbol >>= 1; 42 | } 43 | } 44 | UInt32 GetPrice(UInt32 symbol) const 45 | { 46 | symbol |= (1 << NumBitLevels); 47 | UInt32 price = 0; 48 | while (symbol != 1) 49 | { 50 | price += Models[symbol >> 1].GetPrice(symbol & 1); 51 | symbol >>= 1; 52 | } 53 | return price; 54 | } 55 | UInt32 ReverseGetPrice(UInt32 symbol) const 56 | { 57 | UInt32 price = 0; 58 | UInt32 modelIndex = 1; 59 | for (int i = NumBitLevels; i != 0; i--) 60 | { 61 | UInt32 bit = symbol & 1; 62 | symbol >>= 1; 63 | price += Models[modelIndex].GetPrice(bit); 64 | modelIndex = (modelIndex << 1) | bit; 65 | } 66 | return price; 67 | } 68 | }; 69 | 70 | template 71 | class CBitTreeDecoder 72 | { 73 | CBitDecoder Models[1 << NumBitLevels]; 74 | public: 75 | void Init() 76 | { 77 | for(UInt32 i = 1; i < (1 << NumBitLevels); i++) 78 | Models[i].Init(); 79 | } 80 | UInt32 Decode(CDecoder *rangeDecoder) 81 | { 82 | UInt32 modelIndex = 1; 83 | RC_INIT_VAR 84 | for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--) 85 | { 86 | // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder); 87 | RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex) 88 | } 89 | RC_FLUSH_VAR 90 | return modelIndex - (1 << NumBitLevels); 91 | }; 92 | UInt32 ReverseDecode(CDecoder *rangeDecoder) 93 | { 94 | UInt32 modelIndex = 1; 95 | UInt32 symbol = 0; 96 | RC_INIT_VAR 97 | for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) 98 | { 99 | // UInt32 bit = Models[modelIndex].Decode(rangeDecoder); 100 | // modelIndex <<= 1; 101 | // modelIndex += bit; 102 | // symbol |= (bit << bitIndex); 103 | RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex)) 104 | } 105 | RC_FLUSH_VAR 106 | return symbol; 107 | } 108 | }; 109 | 110 | template 111 | void ReverseBitTreeEncode(CBitEncoder *Models, 112 | CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol) 113 | { 114 | UInt32 modelIndex = 1; 115 | for (int i = 0; i < NumBitLevels; i++) 116 | { 117 | UInt32 bit = symbol & 1; 118 | Models[modelIndex].Encode(rangeEncoder, bit); 119 | modelIndex = (modelIndex << 1) | bit; 120 | symbol >>= 1; 121 | } 122 | } 123 | 124 | template 125 | UInt32 ReverseBitTreeGetPrice(CBitEncoder *Models, 126 | UInt32 NumBitLevels, UInt32 symbol) 127 | { 128 | UInt32 price = 0; 129 | UInt32 modelIndex = 1; 130 | for (int i = NumBitLevels; i != 0; i--) 131 | { 132 | UInt32 bit = symbol & 1; 133 | symbol >>= 1; 134 | price += Models[modelIndex].GetPrice(bit); 135 | modelIndex = (modelIndex << 1) | bit; 136 | } 137 | return price; 138 | } 139 | 140 | template 141 | UInt32 ReverseBitTreeDecode(CBitDecoder *Models, 142 | CDecoder *rangeDecoder, int NumBitLevels) 143 | { 144 | UInt32 modelIndex = 1; 145 | UInt32 symbol = 0; 146 | RC_INIT_VAR 147 | for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) 148 | { 149 | // UInt32 bit = Models[modelIndex].Decode(rangeDecoder); 150 | // modelIndex <<= 1; 151 | // modelIndex += bit; 152 | // symbol |= (bit << bitIndex); 153 | RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex)) 154 | } 155 | RC_FLUSH_VAR 156 | return symbol; 157 | } 158 | 159 | }} 160 | 161 | #endif 162 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/RangeCoder/RangeCoderOpt.h: -------------------------------------------------------------------------------- 1 | // Compress/RangeCoder/RangeCoderOpt.h 2 | 3 | #ifndef __COMPRESS_RANGECODER_OPT_H 4 | #define __COMPRESS_RANGECODER_OPT_H 5 | 6 | #define RC_INIT_VAR \ 7 | UInt32 range = rangeDecoder->Range; \ 8 | UInt32 code = rangeDecoder->Code; 9 | 10 | #define RC_FLUSH_VAR \ 11 | rangeDecoder->Range = range; \ 12 | rangeDecoder->Code = code; 13 | 14 | #define RC_NORMALIZE \ 15 | if (range < NCompress::NRangeCoder::kTopValue) \ 16 | { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; } 17 | 18 | #define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \ 19 | { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \ 20 | if (code < bound) \ 21 | { A0; range = bound; \ 22 | prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \ 23 | mi <<= 1; } \ 24 | else \ 25 | { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \ 26 | mi = (mi + mi) + 1; }} \ 27 | RC_NORMALIZE 28 | 29 | #define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;) 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Compress/RangeCoder/Stdafx.h: -------------------------------------------------------------------------------- 1 | // StdAfx.h 2 | 3 | #ifndef __STDAFX_H 4 | #define __STDAFX_H 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Icoder.h: -------------------------------------------------------------------------------- 1 | // ICoder.h 2 | 3 | #ifndef __ICODER_H 4 | #define __ICODER_H 5 | 6 | #include "IStream.h" 7 | 8 | // "23170F69-40C1-278A-0000-000400xx0000" 9 | #define CODER_INTERFACE(i, x) \ 10 | DEFINE_GUID(IID_ ## i, \ 11 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \ 12 | struct i: public IUnknown 13 | 14 | CODER_INTERFACE(ICompressProgressInfo, 0x04) 15 | { 16 | STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE; 17 | }; 18 | 19 | CODER_INTERFACE(ICompressCoder, 0x05) 20 | { 21 | STDMETHOD(Code)(ISequentialInStream *inStream, 22 | ISequentialOutStream *outStream, 23 | const UInt64 *inSize, 24 | const UInt64 *outSize, 25 | ICompressProgressInfo *progress) PURE; 26 | }; 27 | 28 | CODER_INTERFACE(ICompressCoder2, 0x18) 29 | { 30 | STDMETHOD(Code)(ISequentialInStream **inStreams, 31 | const UInt64 **inSizes, 32 | UInt32 numInStreams, 33 | ISequentialOutStream **outStreams, 34 | const UInt64 **outSizes, 35 | UInt32 numOutStreams, 36 | ICompressProgressInfo *progress) PURE; 37 | }; 38 | 39 | namespace NCoderPropID 40 | { 41 | enum EEnum 42 | { 43 | kDictionarySize = 0x400, 44 | kUsedMemorySize, 45 | kOrder, 46 | kPosStateBits = 0x440, 47 | kLitContextBits, 48 | kLitPosBits, 49 | kNumFastBytes = 0x450, 50 | kMatchFinder, 51 | kMatchFinderCycles, 52 | kNumPasses = 0x460, 53 | kAlgorithm = 0x470, 54 | kMultiThread = 0x480, 55 | kNumThreads, 56 | kEndMarker = 0x490 57 | }; 58 | } 59 | 60 | CODER_INTERFACE(ICompressSetCoderProperties, 0x20) 61 | { 62 | STDMETHOD(SetCoderProperties)(const PROPID *propIDs, 63 | const PROPVARIANT *properties, UInt32 numProperties) PURE; 64 | }; 65 | 66 | /* 67 | CODER_INTERFACE(ICompressSetCoderProperties, 0x21) 68 | { 69 | STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE; 70 | }; 71 | */ 72 | 73 | CODER_INTERFACE(ICompressSetDecoderProperties2, 0x22) 74 | { 75 | STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE; 76 | }; 77 | 78 | CODER_INTERFACE(ICompressWriteCoderProperties, 0x23) 79 | { 80 | STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE; 81 | }; 82 | 83 | CODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24) 84 | { 85 | STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE; 86 | }; 87 | 88 | CODER_INTERFACE(ICompressSetCoderMt, 0x25) 89 | { 90 | STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE; 91 | }; 92 | 93 | CODER_INTERFACE(ICompressGetSubStreamSize, 0x30) 94 | { 95 | STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE; 96 | }; 97 | 98 | CODER_INTERFACE(ICompressSetInStream, 0x31) 99 | { 100 | STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE; 101 | STDMETHOD(ReleaseInStream)() PURE; 102 | }; 103 | 104 | CODER_INTERFACE(ICompressSetOutStream, 0x32) 105 | { 106 | STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE; 107 | STDMETHOD(ReleaseOutStream)() PURE; 108 | }; 109 | 110 | CODER_INTERFACE(ICompressSetInStreamSize, 0x33) 111 | { 112 | STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE; 113 | }; 114 | 115 | CODER_INTERFACE(ICompressSetOutStreamSize, 0x34) 116 | { 117 | STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE; 118 | }; 119 | 120 | CODER_INTERFACE(ICompressFilter, 0x40) 121 | { 122 | STDMETHOD(Init)() PURE; 123 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE; 124 | // Filter return outSize (UInt32) 125 | // if (outSize <= size): Filter have converted outSize bytes 126 | // if (outSize > size): Filter have not converted anything. 127 | // and it needs at least outSize bytes to convert one block 128 | // (it's for crypto block algorithms). 129 | }; 130 | 131 | CODER_INTERFACE(ICompressCodecsInfo, 0x60) 132 | { 133 | STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE; 134 | STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE; 135 | STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE; 136 | STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE; 137 | }; 138 | CODER_INTERFACE(ISetCompressCodecsInfo, 0x61) 139 | { 140 | STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE; 141 | }; 142 | 143 | CODER_INTERFACE(ICryptoProperties, 0x80) 144 | { 145 | STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE; 146 | STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE; 147 | }; 148 | 149 | /* 150 | CODER_INTERFACE(ICryptoResetSalt, 0x88) 151 | { 152 | STDMETHOD(ResetSalt)() PURE; 153 | }; 154 | */ 155 | 156 | CODER_INTERFACE(ICryptoResetInitVector, 0x8C) 157 | { 158 | STDMETHOD(ResetInitVector)() PURE; 159 | }; 160 | 161 | CODER_INTERFACE(ICryptoSetPassword, 0x90) 162 | { 163 | STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE; 164 | }; 165 | 166 | CODER_INTERFACE(ICryptoSetCRC, 0xA0) 167 | { 168 | STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE; 169 | }; 170 | 171 | ////////////////////// 172 | // It's for DLL file 173 | namespace NMethodPropID 174 | { 175 | enum EEnum 176 | { 177 | kID, 178 | kName, 179 | kDecoder, 180 | kEncoder, 181 | kInStreams, 182 | kOutStreams, 183 | kDescription, 184 | kDecoderIsAssigned, 185 | kEncoderIsAssigned 186 | }; 187 | } 188 | 189 | #endif 190 | -------------------------------------------------------------------------------- /lzma/CPP/7zip/Istream.h: -------------------------------------------------------------------------------- 1 | // IStream.h 2 | 3 | #ifndef __ISTREAM_H 4 | #define __ISTREAM_H 5 | 6 | #include "../Common/MyUnknown.h" 7 | #include "../Common/Types.h" 8 | 9 | // "23170F69-40C1-278A-0000-000300xx0000" 10 | 11 | #define STREAM_INTERFACE_SUB(i, b, x) \ 12 | DEFINE_GUID(IID_ ## i, \ 13 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \ 14 | struct i: public b 15 | 16 | #define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x) 17 | 18 | STREAM_INTERFACE(ISequentialInStream, 0x01) 19 | { 20 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE; 21 | /* 22 | Out: if size != 0, return_value = S_OK and (*processedSize == 0), 23 | then there are no more bytes in stream. 24 | if (size > 0) && there are bytes in stream, 25 | this function must read at least 1 byte. 26 | This function is allowed to read less than number of remaining bytes in stream. 27 | You must call Read function in loop, if you need exact amount of data 28 | */ 29 | }; 30 | 31 | STREAM_INTERFACE(ISequentialOutStream, 0x02) 32 | { 33 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE; 34 | /* 35 | if (size > 0) this function must write at least 1 byte. 36 | This function is allowed to write less than "size". 37 | You must call Write function in loop, if you need to write exact amount of data 38 | */ 39 | }; 40 | 41 | STREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03) 42 | { 43 | STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE; 44 | }; 45 | 46 | STREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04) 47 | { 48 | STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE; 49 | STDMETHOD(SetSize)(Int64 newSize) PURE; 50 | }; 51 | 52 | STREAM_INTERFACE(IStreamGetSize, 0x06) 53 | { 54 | STDMETHOD(GetSize)(UInt64 *size) PURE; 55 | }; 56 | 57 | STREAM_INTERFACE(IOutStreamFlush, 0x07) 58 | { 59 | STDMETHOD(Flush)() PURE; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /lzma/CPP/Common/Crc.cpp: -------------------------------------------------------------------------------- 1 | // Common/CRC.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | extern "C" 6 | { 7 | #include "../../C/7zCrc.h" 8 | } 9 | 10 | class CCRCTableInit 11 | { 12 | public: 13 | CCRCTableInit() { CrcGenerateTable(); } 14 | } g_CRCTableInit; 15 | -------------------------------------------------------------------------------- /lzma/CPP/Common/Defs.h: -------------------------------------------------------------------------------- 1 | // Common/Defs.h 2 | 3 | #ifndef __COMMON_DEFS_H 4 | #define __COMMON_DEFS_H 5 | 6 | template inline T MyMin(T a, T b) 7 | { return a < b ? a : b; } 8 | template inline T MyMax(T a, T b) 9 | { return a > b ? a : b; } 10 | 11 | template inline int MyCompare(T a, T b) 12 | { return a < b ? -1 : (a == b ? 0 : 1); } 13 | 14 | inline int BoolToInt(bool value) 15 | { return (value ? 1: 0); } 16 | 17 | inline bool IntToBool(int value) 18 | { return (value != 0); } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lzma/CPP/Common/MyException.h: -------------------------------------------------------------------------------- 1 | // Common/Exception.h 2 | 3 | #ifndef __COMMON_EXCEPTION_H 4 | #define __COMMON_EXCEPTION_H 5 | 6 | #include "MyWindows.h" 7 | 8 | struct CSystemException 9 | { 10 | HRESULT ErrorCode; 11 | CSystemException(HRESULT errorCode): ErrorCode(errorCode) {} 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /lzma/CPP/Common/MyGuidDef.h: -------------------------------------------------------------------------------- 1 | // Common/MyGuidDef.h 2 | 3 | #ifndef GUID_DEFINED 4 | #define GUID_DEFINED 5 | 6 | #include "Types.h" 7 | 8 | typedef struct { 9 | UInt32 Data1; 10 | UInt16 Data2; 11 | UInt16 Data3; 12 | unsigned char Data4[8]; 13 | } GUID; 14 | 15 | #ifdef __cplusplus 16 | #define REFGUID const GUID & 17 | #else 18 | #define REFGUID const GUID * 19 | #endif 20 | 21 | #define REFCLSID REFGUID 22 | #define REFIID REFGUID 23 | 24 | #ifdef __cplusplus 25 | inline int operator==(REFGUID g1, REFGUID g2) 26 | { 27 | for (int i = 0; i < (int)sizeof(g1); i++) 28 | if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i]) 29 | return 0; 30 | return 1; 31 | } 32 | inline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); } 33 | #endif 34 | 35 | #ifdef __cplusplus 36 | #define MY_EXTERN_C extern "C" 37 | #else 38 | #define MY_EXTERN_C extern 39 | #endif 40 | 41 | #endif // GUID_DEFINED 42 | 43 | 44 | #ifdef DEFINE_GUID 45 | #undef DEFINE_GUID 46 | #endif 47 | 48 | #ifdef INITGUID 49 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 50 | MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } 51 | #else 52 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 53 | MY_EXTERN_C const GUID name 54 | #endif 55 | -------------------------------------------------------------------------------- /lzma/CPP/Common/MyInitGuid.h: -------------------------------------------------------------------------------- 1 | // Common/MyInitGuid.h 2 | 3 | #ifndef __COMMON_MYINITGUID_H 4 | #define __COMMON_MYINITGUID_H 5 | 6 | #ifdef _WIN32 7 | #include 8 | #else 9 | #define INITGUID 10 | #include "MyGuidDef.h" 11 | DEFINE_GUID(IID_IUnknown, 12 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lzma/CPP/Common/MyUnknown.h: -------------------------------------------------------------------------------- 1 | // MyUnknown.h 2 | 3 | #ifndef __MYUNKNOWN_H 4 | #define __MYUNKNOWN_H 5 | 6 | #ifdef _WIN32 7 | 8 | #ifdef _WIN32_WCE 9 | #if (_WIN32_WCE > 300) 10 | #include 11 | #else 12 | #define MIDL_INTERFACE(x) struct 13 | #endif 14 | #else 15 | #include 16 | #endif 17 | 18 | #include 19 | 20 | #else 21 | #include "MyWindows.h" 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lzma/CPP/Common/MyWindows.h: -------------------------------------------------------------------------------- 1 | // MyWindows.h 2 | 3 | #ifndef __MYWINDOWS_H 4 | #define __MYWINDOWS_H 5 | 6 | #ifdef _WIN32 7 | 8 | #include 9 | 10 | #define CHAR_PATH_SEPARATOR '\\' 11 | #define WCHAR_PATH_SEPARATOR L'\\' 12 | #define STRING_PATH_SEPARATOR "\\" 13 | #define WSTRING_PATH_SEPARATOR L"\\" 14 | 15 | #else 16 | 17 | #define CHAR_PATH_SEPARATOR '/' 18 | #define WCHAR_PATH_SEPARATOR L'/' 19 | #define STRING_PATH_SEPARATOR "/" 20 | #define WSTRING_PATH_SEPARATOR L"/" 21 | 22 | #include // for wchar_t 23 | #include 24 | 25 | #include "MyGuidDef.h" 26 | 27 | typedef char CHAR; 28 | typedef unsigned char UCHAR; 29 | 30 | #undef BYTE 31 | typedef unsigned char BYTE; 32 | 33 | typedef short SHORT; 34 | typedef unsigned short USHORT; 35 | 36 | #undef WORD 37 | typedef unsigned short WORD; 38 | typedef short VARIANT_BOOL; 39 | 40 | typedef int INT; 41 | typedef Int32 INT32; 42 | typedef unsigned int UINT; 43 | typedef UInt32 UINT32; 44 | typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit 45 | typedef UINT32 ULONG; 46 | 47 | #undef DWORD 48 | typedef UINT32 DWORD; 49 | 50 | typedef Int64 LONGLONG; 51 | typedef UInt64 ULONGLONG; 52 | 53 | typedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER; 54 | typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER; 55 | 56 | typedef const CHAR *LPCSTR; 57 | typedef CHAR TCHAR; 58 | typedef const TCHAR *LPCTSTR; 59 | typedef wchar_t WCHAR; 60 | typedef WCHAR OLECHAR; 61 | typedef const WCHAR *LPCWSTR; 62 | typedef OLECHAR *BSTR; 63 | typedef const OLECHAR *LPCOLESTR; 64 | typedef OLECHAR *LPOLESTR; 65 | 66 | typedef struct _FILETIME 67 | { 68 | DWORD dwLowDateTime; 69 | DWORD dwHighDateTime; 70 | }FILETIME; 71 | 72 | #define HRESULT LONG 73 | #define FAILED(Status) ((HRESULT)(Status)<0) 74 | typedef ULONG PROPID; 75 | typedef LONG SCODE; 76 | 77 | #define S_OK ((HRESULT)0x00000000L) 78 | #define S_FALSE ((HRESULT)0x00000001L) 79 | #define E_NOTIMPL ((HRESULT)0x80004001L) 80 | #define E_NOINTERFACE ((HRESULT)0x80004002L) 81 | #define E_ABORT ((HRESULT)0x80004004L) 82 | #define E_FAIL ((HRESULT)0x80004005L) 83 | #define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L) 84 | #define E_OUTOFMEMORY ((HRESULT)0x8007000EL) 85 | #define E_INVALIDARG ((HRESULT)0x80070057L) 86 | 87 | #ifdef _MSC_VER 88 | #define STDMETHODCALLTYPE __stdcall 89 | #else 90 | #define STDMETHODCALLTYPE 91 | #endif 92 | 93 | #define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f 94 | #define STDMETHOD(f) STDMETHOD_(HRESULT, f) 95 | #define STDMETHODIMP_(type) type STDMETHODCALLTYPE 96 | #define STDMETHODIMP STDMETHODIMP_(HRESULT) 97 | 98 | #define PURE = 0 99 | 100 | #define MIDL_INTERFACE(x) struct 101 | 102 | #ifdef __cplusplus 103 | 104 | DEFINE_GUID(IID_IUnknown, 105 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); 106 | struct IUnknown 107 | { 108 | STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE; 109 | STDMETHOD_(ULONG, AddRef)() PURE; 110 | STDMETHOD_(ULONG, Release)() PURE; 111 | #ifndef _WIN32 112 | virtual ~IUnknown() {} 113 | #endif 114 | }; 115 | 116 | typedef IUnknown *LPUNKNOWN; 117 | 118 | #endif 119 | 120 | #define VARIANT_TRUE ((VARIANT_BOOL)-1) 121 | #define VARIANT_FALSE ((VARIANT_BOOL)0) 122 | 123 | enum VARENUM 124 | { 125 | VT_EMPTY = 0, 126 | VT_NULL = 1, 127 | VT_I2 = 2, 128 | VT_I4 = 3, 129 | VT_R4 = 4, 130 | VT_R8 = 5, 131 | VT_CY = 6, 132 | VT_DATE = 7, 133 | VT_BSTR = 8, 134 | VT_DISPATCH = 9, 135 | VT_ERROR = 10, 136 | VT_BOOL = 11, 137 | VT_VARIANT = 12, 138 | VT_UNKNOWN = 13, 139 | VT_DECIMAL = 14, 140 | VT_I1 = 16, 141 | VT_UI1 = 17, 142 | VT_UI2 = 18, 143 | VT_UI4 = 19, 144 | VT_I8 = 20, 145 | VT_UI8 = 21, 146 | VT_INT = 22, 147 | VT_UINT = 23, 148 | VT_VOID = 24, 149 | VT_HRESULT = 25, 150 | VT_FILETIME = 64 151 | }; 152 | 153 | typedef unsigned short VARTYPE; 154 | typedef WORD PROPVAR_PAD1; 155 | typedef WORD PROPVAR_PAD2; 156 | typedef WORD PROPVAR_PAD3; 157 | 158 | #ifdef __cplusplus 159 | 160 | typedef struct tagPROPVARIANT 161 | { 162 | VARTYPE vt; 163 | PROPVAR_PAD1 wReserved1; 164 | PROPVAR_PAD2 wReserved2; 165 | PROPVAR_PAD3 wReserved3; 166 | union 167 | { 168 | CHAR cVal; 169 | UCHAR bVal; 170 | SHORT iVal; 171 | USHORT uiVal; 172 | LONG lVal; 173 | ULONG ulVal; 174 | INT intVal; 175 | UINT uintVal; 176 | LARGE_INTEGER hVal; 177 | ULARGE_INTEGER uhVal; 178 | VARIANT_BOOL boolVal; 179 | SCODE scode; 180 | FILETIME filetime; 181 | BSTR bstrVal; 182 | }; 183 | } PROPVARIANT; 184 | 185 | typedef PROPVARIANT tagVARIANT; 186 | typedef tagVARIANT VARIANT; 187 | typedef VARIANT VARIANTARG; 188 | 189 | MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop); 190 | MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src); 191 | 192 | #endif 193 | 194 | MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len); 195 | MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz); 196 | MY_EXTERN_C void SysFreeString(BSTR bstr); 197 | MY_EXTERN_C UINT SysStringByteLen(BSTR bstr); 198 | MY_EXTERN_C UINT SysStringLen(BSTR bstr); 199 | 200 | MY_EXTERN_C DWORD GetLastError(); 201 | MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2); 202 | 203 | #define CP_ACP 0 204 | #define CP_OEMCP 1 205 | 206 | typedef enum tagSTREAM_SEEK 207 | { 208 | STREAM_SEEK_SET = 0, 209 | STREAM_SEEK_CUR = 1, 210 | STREAM_SEEK_END = 2 211 | } STREAM_SEEK; 212 | 213 | #endif 214 | #endif 215 | -------------------------------------------------------------------------------- /lzma/CPP/Common/Mycom.h: -------------------------------------------------------------------------------- 1 | // MyCom.h 2 | 3 | #ifndef __MYCOM_H 4 | #define __MYCOM_H 5 | 6 | #include "MyWindows.h" 7 | 8 | #ifndef RINOK 9 | #define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; } 10 | #endif 11 | 12 | template 13 | class CMyComPtr 14 | { 15 | T* _p; 16 | public: 17 | // typedef T _PtrClass; 18 | CMyComPtr() { _p = NULL;} 19 | CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); } 20 | CMyComPtr(const CMyComPtr& lp) 21 | { 22 | if ((_p = lp._p) != NULL) 23 | _p->AddRef(); 24 | } 25 | ~CMyComPtr() { if (_p) _p->Release(); } 26 | void Release() { if (_p) { _p->Release(); _p = NULL; } } 27 | operator T*() const { return (T*)_p; } 28 | // T& operator*() const { return *_p; } 29 | T** operator&() { return &_p; } 30 | T* operator->() const { return _p; } 31 | T* operator=(T* p) 32 | { 33 | if (p != 0) 34 | p->AddRef(); 35 | if (_p) 36 | _p->Release(); 37 | _p = p; 38 | return p; 39 | } 40 | T* operator=(const CMyComPtr& lp) { return (*this = lp._p); } 41 | bool operator!() const { return (_p == NULL); } 42 | // bool operator==(T* pT) const { return _p == pT; } 43 | // Compare two objects for equivalence 44 | void Attach(T* p2) 45 | { 46 | Release(); 47 | _p = p2; 48 | } 49 | T* Detach() 50 | { 51 | T* pt = _p; 52 | _p = NULL; 53 | return pt; 54 | } 55 | #ifdef _WIN32 56 | HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) 57 | { 58 | return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p); 59 | } 60 | #endif 61 | /* 62 | HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) 63 | { 64 | CLSID clsid; 65 | HRESULT hr = CLSIDFromProgID(szProgID, &clsid); 66 | ATLASSERT(_p == NULL); 67 | if (SUCCEEDED(hr)) 68 | hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p); 69 | return hr; 70 | } 71 | */ 72 | template 73 | HRESULT QueryInterface(REFGUID iid, Q** pp) const 74 | { 75 | return _p->QueryInterface(iid, (void**)pp); 76 | } 77 | }; 78 | 79 | ////////////////////////////////////////////////////////// 80 | 81 | class CMyComBSTR 82 | { 83 | public: 84 | BSTR m_str; 85 | CMyComBSTR() { m_str = NULL; } 86 | CMyComBSTR(LPCOLESTR pSrc) { m_str = ::SysAllocString(pSrc); } 87 | // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); } 88 | // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize); } 89 | CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); } 90 | /* 91 | CMyComBSTR(REFGUID src) 92 | { 93 | LPOLESTR szGuid; 94 | StringFromCLSID(src, &szGuid); 95 | m_str = ::SysAllocString(szGuid); 96 | CoTaskMemFree(szGuid); 97 | } 98 | */ 99 | ~CMyComBSTR() { ::SysFreeString(m_str); } 100 | CMyComBSTR& operator=(const CMyComBSTR& src) 101 | { 102 | if (m_str != src.m_str) 103 | { 104 | if (m_str) 105 | ::SysFreeString(m_str); 106 | m_str = src.MyCopy(); 107 | } 108 | return *this; 109 | } 110 | CMyComBSTR& operator=(LPCOLESTR pSrc) 111 | { 112 | ::SysFreeString(m_str); 113 | m_str = ::SysAllocString(pSrc); 114 | return *this; 115 | } 116 | unsigned int Length() const { return ::SysStringLen(m_str); } 117 | operator BSTR() const { return m_str; } 118 | BSTR* operator&() { return &m_str; } 119 | BSTR MyCopy() const 120 | { 121 | int byteLen = ::SysStringByteLen(m_str); 122 | BSTR res = ::SysAllocStringByteLen(NULL, byteLen); 123 | memmove(res, m_str, byteLen); 124 | return res; 125 | } 126 | void Attach(BSTR src) { m_str = src; } 127 | BSTR Detach() 128 | { 129 | BSTR s = m_str; 130 | m_str = NULL; 131 | return s; 132 | } 133 | void Empty() 134 | { 135 | ::SysFreeString(m_str); 136 | m_str = NULL; 137 | } 138 | bool operator!() const { return (m_str == NULL); } 139 | }; 140 | 141 | 142 | ////////////////////////////////////////////////////////// 143 | 144 | class CMyUnknownImp 145 | { 146 | public: 147 | ULONG __m_RefCount; 148 | CMyUnknownImp(): __m_RefCount(0) {} 149 | }; 150 | 151 | #define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \ 152 | (REFGUID iid, void **outObject) { 153 | 154 | #define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \ 155 | { *outObject = (void *)(i *)this; AddRef(); return S_OK; } 156 | 157 | #define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \ 158 | { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; } 159 | 160 | #define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \ 161 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \ 162 | MY_QUERYINTERFACE_ENTRY(i) 163 | 164 | #define MY_QUERYINTERFACE_END return E_NOINTERFACE; } 165 | 166 | #define MY_ADDREF_RELEASE \ 167 | STDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \ 168 | STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \ 169 | return __m_RefCount; delete this; return 0; } 170 | 171 | #define MY_UNKNOWN_IMP_SPEC(i) \ 172 | MY_QUERYINTERFACE_BEGIN \ 173 | i \ 174 | MY_QUERYINTERFACE_END \ 175 | MY_ADDREF_RELEASE 176 | 177 | 178 | #define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \ 179 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \ 180 | MY_QUERYINTERFACE_END \ 181 | MY_ADDREF_RELEASE 182 | 183 | #define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \ 184 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \ 185 | MY_QUERYINTERFACE_ENTRY(i) \ 186 | ) 187 | 188 | #define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \ 189 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ 190 | MY_QUERYINTERFACE_ENTRY(i1) \ 191 | MY_QUERYINTERFACE_ENTRY(i2) \ 192 | ) 193 | 194 | #define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \ 195 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ 196 | MY_QUERYINTERFACE_ENTRY(i1) \ 197 | MY_QUERYINTERFACE_ENTRY(i2) \ 198 | MY_QUERYINTERFACE_ENTRY(i3) \ 199 | ) 200 | 201 | #define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \ 202 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ 203 | MY_QUERYINTERFACE_ENTRY(i1) \ 204 | MY_QUERYINTERFACE_ENTRY(i2) \ 205 | MY_QUERYINTERFACE_ENTRY(i3) \ 206 | MY_QUERYINTERFACE_ENTRY(i4) \ 207 | ) 208 | 209 | #define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \ 210 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ 211 | MY_QUERYINTERFACE_ENTRY(i1) \ 212 | MY_QUERYINTERFACE_ENTRY(i2) \ 213 | MY_QUERYINTERFACE_ENTRY(i3) \ 214 | MY_QUERYINTERFACE_ENTRY(i4) \ 215 | MY_QUERYINTERFACE_ENTRY(i5) \ 216 | ) 217 | 218 | #endif 219 | -------------------------------------------------------------------------------- /lzma/CPP/Common/NewHandler.cpp: -------------------------------------------------------------------------------- 1 | // NewHandler.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include 6 | 7 | #include "NewHandler.h" 8 | 9 | // #define DEBUG_MEMORY_LEAK 10 | 11 | #ifndef DEBUG_MEMORY_LEAK 12 | 13 | #ifdef _WIN32 14 | void * 15 | #ifdef _MSC_VER 16 | __cdecl 17 | #endif 18 | operator new(size_t size) 19 | { 20 | // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); 21 | void *p = ::malloc(size); 22 | if (p == 0) 23 | throw CNewException(); 24 | return p; 25 | } 26 | 27 | void 28 | #ifdef _MSC_VER 29 | __cdecl 30 | #endif 31 | operator delete(void *p) throw() 32 | { 33 | /* 34 | if (p == 0) 35 | return; 36 | ::HeapFree(::GetProcessHeap(), 0, p); 37 | */ 38 | ::free(p); 39 | } 40 | #endif 41 | 42 | #else 43 | 44 | #pragma init_seg(lib) 45 | const int kDebugSize = 1000000; 46 | static void *a[kDebugSize]; 47 | static int index = 0; 48 | 49 | static int numAllocs = 0; 50 | void * __cdecl operator new(size_t size) 51 | { 52 | numAllocs++; 53 | void *p = HeapAlloc(GetProcessHeap(), 0, size); 54 | if (index == 40) 55 | { 56 | int t = 1; 57 | } 58 | if (index < kDebugSize) 59 | { 60 | a[index] = p; 61 | index++; 62 | } 63 | if (p == 0) 64 | throw CNewException(); 65 | printf("Alloc %6d, size = %8d\n", numAllocs, size); 66 | return p; 67 | } 68 | 69 | class CC 70 | { 71 | public: 72 | CC() 73 | { 74 | for (int i = 0; i < kDebugSize; i++) 75 | a[i] = 0; 76 | } 77 | ~CC() 78 | { 79 | for (int i = 0; i < kDebugSize; i++) 80 | if (a[i] != 0) 81 | return; 82 | } 83 | } g_CC; 84 | 85 | 86 | void __cdecl operator delete(void *p) 87 | { 88 | if (p == 0) 89 | return; 90 | /* 91 | for (int i = 0; i < index; i++) 92 | if (a[i] == p) 93 | a[i] = 0; 94 | */ 95 | HeapFree(GetProcessHeap(), 0, p); 96 | numAllocs--; 97 | printf("Free %d\n", numAllocs); 98 | } 99 | 100 | #endif 101 | 102 | /* 103 | int MemErrorVC(size_t) 104 | { 105 | throw CNewException(); 106 | // return 1; 107 | } 108 | CNewHandlerSetter::CNewHandlerSetter() 109 | { 110 | // MemErrorOldVCFunction = _set_new_handler(MemErrorVC); 111 | } 112 | CNewHandlerSetter::~CNewHandlerSetter() 113 | { 114 | // _set_new_handler(MemErrorOldVCFunction); 115 | } 116 | */ 117 | -------------------------------------------------------------------------------- /lzma/CPP/Common/NewHandler.h: -------------------------------------------------------------------------------- 1 | // Common/NewHandler.h 2 | 3 | #ifndef __COMMON_NEWHANDLER_H 4 | #define __COMMON_NEWHANDLER_H 5 | 6 | class CNewException {}; 7 | 8 | #ifdef _WIN32 9 | void 10 | #ifdef _MSC_VER 11 | __cdecl 12 | #endif 13 | operator delete(void *p) throw(); 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lzma/CPP/Common/Stdafx.h: -------------------------------------------------------------------------------- 1 | // StdAfx.h 2 | 3 | #ifndef __STDAFX_H 4 | #define __STDAFX_H 5 | 6 | // #include "MyWindows.h" 7 | #include "NewHandler.h" 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lzma/CPP/Common/Types.h: -------------------------------------------------------------------------------- 1 | // Common/Types.h 2 | 3 | #ifndef __COMMON_TYPES_H 4 | #define __COMMON_TYPES_H 5 | 6 | #ifndef _7ZIP_BYTE_DEFINED 7 | #define _7ZIP_BYTE_DEFINED 8 | typedef unsigned char Byte; 9 | #endif 10 | 11 | #ifndef _7ZIP_INT16_DEFINED 12 | #define _7ZIP_INT16_DEFINED 13 | typedef short Int16; 14 | #endif 15 | 16 | #ifndef _7ZIP_UINT16_DEFINED 17 | #define _7ZIP_UINT16_DEFINED 18 | typedef unsigned short UInt16; 19 | #endif 20 | 21 | #ifndef _7ZIP_INT32_DEFINED 22 | #define _7ZIP_INT32_DEFINED 23 | typedef int Int32; 24 | #endif 25 | 26 | #ifndef _7ZIP_UINT32_DEFINED 27 | #define _7ZIP_UINT32_DEFINED 28 | typedef unsigned int UInt32; 29 | #endif 30 | 31 | #ifdef _MSC_VER 32 | 33 | #ifndef _7ZIP_INT64_DEFINED 34 | #define _7ZIP_INT64_DEFINED 35 | typedef __int64 Int64; 36 | #endif 37 | 38 | #ifndef _7ZIP_UINT64_DEFINED 39 | #define _7ZIP_UINT64_DEFINED 40 | typedef unsigned __int64 UInt64; 41 | #endif 42 | 43 | #else 44 | 45 | #ifndef _7ZIP_INT64_DEFINED 46 | #define _7ZIP_INT64_DEFINED 47 | typedef long long int Int64; 48 | #endif 49 | 50 | #ifndef _7ZIP_UINT64_DEFINED 51 | #define _7ZIP_UINT64_DEFINED 52 | typedef unsigned long long int UInt64; 53 | #endif 54 | 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /lzma/Readme.txt: -------------------------------------------------------------------------------- 1 | Nearly all of the code in this directory and subdirectories is 2 | from the LZMA SDK version 4.49 by Igor Pavlov: 3 | 4 | http://www.7-zip.org/ 5 | 6 | See lzma.txt for the LZMA SDK's license terms. 7 | 8 | The Inno Setup-specific files in the CPP\7zip\Compress\ISLZMA 9 | directory may be used under the same license terms as the 10 | LZMA SDK. In fact, you can do whatever you want with them; 11 | I make no claim of copyright. 12 | 13 | The Visual C++ 2005 project file I use to build ISLZMA.dll is 14 | located in the CPP\7zip\Compress\ISLZMA directory. 15 | 16 | - Jordan Russell 17 | -------------------------------------------------------------------------------- /zlib-dll/Readme.txt: -------------------------------------------------------------------------------- 1 | The projects must be built using the "Release" configuration. You'll 2 | get errors if you try compiling under the "Debug" configuration. 3 | -------------------------------------------------------------------------------- /zlib-dll/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | #define BASE 65521UL /* largest prime smaller than 65536 */ 12 | #define NMAX 5552 13 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 14 | 15 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 16 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 17 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 18 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 19 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 20 | 21 | /* use NO_DIVIDE if your processor does not do division in hardware */ 22 | #ifdef NO_DIVIDE 23 | # define MOD(a) \ 24 | do { \ 25 | if (a >= (BASE << 16)) a -= (BASE << 16); \ 26 | if (a >= (BASE << 15)) a -= (BASE << 15); \ 27 | if (a >= (BASE << 14)) a -= (BASE << 14); \ 28 | if (a >= (BASE << 13)) a -= (BASE << 13); \ 29 | if (a >= (BASE << 12)) a -= (BASE << 12); \ 30 | if (a >= (BASE << 11)) a -= (BASE << 11); \ 31 | if (a >= (BASE << 10)) a -= (BASE << 10); \ 32 | if (a >= (BASE << 9)) a -= (BASE << 9); \ 33 | if (a >= (BASE << 8)) a -= (BASE << 8); \ 34 | if (a >= (BASE << 7)) a -= (BASE << 7); \ 35 | if (a >= (BASE << 6)) a -= (BASE << 6); \ 36 | if (a >= (BASE << 5)) a -= (BASE << 5); \ 37 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 38 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 39 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 40 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 41 | if (a >= BASE) a -= BASE; \ 42 | } while (0) 43 | # define MOD4(a) \ 44 | do { \ 45 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 46 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 47 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 48 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 49 | if (a >= BASE) a -= BASE; \ 50 | } while (0) 51 | #else 52 | # define MOD(a) a %= BASE 53 | # define MOD4(a) a %= BASE 54 | #endif 55 | 56 | /* ========================================================================= */ 57 | uLong ZEXPORT adler32(adler, buf, len) 58 | uLong adler; 59 | const Bytef *buf; 60 | uInt len; 61 | { 62 | unsigned long sum2; 63 | unsigned n; 64 | 65 | /* split Adler-32 into component sums */ 66 | sum2 = (adler >> 16) & 0xffff; 67 | adler &= 0xffff; 68 | 69 | /* in case user likes doing a byte at a time, keep it fast */ 70 | if (len == 1) { 71 | adler += buf[0]; 72 | if (adler >= BASE) 73 | adler -= BASE; 74 | sum2 += adler; 75 | if (sum2 >= BASE) 76 | sum2 -= BASE; 77 | return adler | (sum2 << 16); 78 | } 79 | 80 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 81 | if (buf == Z_NULL) 82 | return 1L; 83 | 84 | /* in case short lengths are provided, keep it somewhat fast */ 85 | if (len < 16) { 86 | while (len--) { 87 | adler += *buf++; 88 | sum2 += adler; 89 | } 90 | if (adler >= BASE) 91 | adler -= BASE; 92 | MOD4(sum2); /* only added so many BASE's */ 93 | return adler | (sum2 << 16); 94 | } 95 | 96 | /* do length NMAX blocks -- requires just one modulo operation */ 97 | while (len >= NMAX) { 98 | len -= NMAX; 99 | n = NMAX / 16; /* NMAX is divisible by 16 */ 100 | do { 101 | DO16(buf); /* 16 sums unrolled */ 102 | buf += 16; 103 | } while (--n); 104 | MOD(adler); 105 | MOD(sum2); 106 | } 107 | 108 | /* do remaining bytes (less than NMAX, still just one modulo) */ 109 | if (len) { /* avoid modulos if none remaining */ 110 | while (len >= 16) { 111 | len -= 16; 112 | DO16(buf); 113 | buf += 16; 114 | } 115 | while (len--) { 116 | adler += *buf++; 117 | sum2 += adler; 118 | } 119 | MOD(adler); 120 | MOD(sum2); 121 | } 122 | 123 | /* return recombined sums */ 124 | return adler | (sum2 << 16); 125 | } 126 | 127 | /* ========================================================================= */ 128 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 129 | uLong adler1; 130 | uLong adler2; 131 | z_off_t len2; 132 | { 133 | unsigned long sum1; 134 | unsigned long sum2; 135 | unsigned rem; 136 | 137 | /* the derivation of this formula is left as an exercise for the reader */ 138 | rem = (unsigned)(len2 % BASE); 139 | sum1 = adler1 & 0xffff; 140 | sum2 = rem * sum1; 141 | MOD(sum2); 142 | sum1 += (adler2 & 0xffff) + BASE - 1; 143 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 144 | if (sum1 > BASE) sum1 -= BASE; 145 | if (sum1 > BASE) sum1 -= BASE; 146 | if (sum2 > (BASE << 1)) sum2 -= (BASE << 1); 147 | if (sum2 > BASE) sum2 -= BASE; 148 | return sum1 | (sum2 << 16); 149 | } 150 | -------------------------------------------------------------------------------- /zlib-dll/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (Bytef*)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11; 79 | } 80 | -------------------------------------------------------------------------------- /zlib-dll/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /zlib-dll/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. It 6 | is part of the implementation of the compression library and 7 | is subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /zlib-dll/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY, /* i/o: waiting for input or output to copy stored block */ 36 | TABLE, /* i: waiting for dynamic block table lengths */ 37 | LENLENS, /* i: waiting for code length code lengths */ 38 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 39 | LEN, /* i: waiting for length/lit code */ 40 | LENEXT, /* i: waiting for length extra bits */ 41 | DIST, /* i: waiting for distance code */ 42 | DISTEXT, /* i: waiting for distance extra bits */ 43 | MATCH, /* o: waiting for output space to copy string */ 44 | LIT, /* o: waiting for output space to write literal */ 45 | CHECK, /* i: waiting for 32-bit check value */ 46 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 47 | DONE, /* finished check, done -- remain here until reset */ 48 | BAD, /* got a data error -- remain here until reset */ 49 | MEM, /* got an inflate() memory error -- remain here until reset */ 50 | SYNC /* looking for synchronization bytes to restart inflate() */ 51 | } inflate_mode; 52 | 53 | /* 54 | State transitions between above modes - 55 | 56 | (most modes can go to the BAD or MEM mode -- not shown for clarity) 57 | 58 | Process header: 59 | HEAD -> (gzip) or (zlib) 60 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME 61 | NAME -> COMMENT -> HCRC -> TYPE 62 | (zlib) -> DICTID or TYPE 63 | DICTID -> DICT -> TYPE 64 | Read deflate blocks: 65 | TYPE -> STORED or TABLE or LEN or CHECK 66 | STORED -> COPY -> TYPE 67 | TABLE -> LENLENS -> CODELENS -> LEN 68 | Read deflate codes: 69 | LEN -> LENEXT or LIT or TYPE 70 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 71 | LIT -> LEN 72 | Process trailer: 73 | CHECK -> LENGTH -> DONE 74 | */ 75 | 76 | /* state maintained between inflate() calls. Approximately 7K bytes. */ 77 | struct inflate_state { 78 | inflate_mode mode; /* current inflate mode */ 79 | int last; /* true if processing last block */ 80 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 81 | int havedict; /* true if dictionary provided */ 82 | int flags; /* gzip header method and flags (0 if zlib) */ 83 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 84 | unsigned long check; /* protected copy of check value */ 85 | unsigned long total; /* protected copy of output count */ 86 | gz_headerp head; /* where to save gzip header information */ 87 | /* sliding window */ 88 | unsigned wbits; /* log base 2 of requested window size */ 89 | unsigned wsize; /* window size or zero if not using window */ 90 | unsigned whave; /* valid bytes in the window */ 91 | unsigned write; /* window write index */ 92 | unsigned char FAR *window; /* allocated sliding window, if needed */ 93 | /* bit accumulator */ 94 | unsigned long hold; /* input bit accumulator */ 95 | unsigned bits; /* number of bits in "in" */ 96 | /* for string and stored block copying */ 97 | unsigned length; /* literal or length of data to copy */ 98 | unsigned offset; /* distance back to copy string from */ 99 | /* for table and code decoding */ 100 | unsigned extra; /* extra bits needed */ 101 | /* fixed and dynamic code tables */ 102 | code const FAR *lencode; /* starting table for length/literal codes */ 103 | code const FAR *distcode; /* starting table for distance codes */ 104 | unsigned lenbits; /* index bits for lencode */ 105 | unsigned distbits; /* index bits for distcode */ 106 | /* dynamic table building */ 107 | unsigned ncode; /* number of code length code lengths */ 108 | unsigned nlen; /* number of length code lengths */ 109 | unsigned ndist; /* number of distance code lengths */ 110 | unsigned have; /* number of code lengths in lens[] */ 111 | code FAR *next; /* next available space in codes[] */ 112 | unsigned short lens[320]; /* temporary storage for code lengths */ 113 | unsigned short work[288]; /* work area for code table building */ 114 | code codes[ENOUGH]; /* space for code tables */ 115 | }; 116 | -------------------------------------------------------------------------------- /zlib-dll/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of dynamic tree. The maximum found in a long but non- 39 | exhaustive search was 1444 code structures (852 for length/literals 40 | and 592 for distances, the latter actually the result of an 41 | exhaustive search). The true maximum is not known, but the value 42 | below is more than safe. */ 43 | #define ENOUGH 2048 44 | #define MAXD 592 45 | 46 | /* Type of code to build for inftable() */ 47 | typedef enum { 48 | CODES, 49 | LENS, 50 | DISTS 51 | } codetype; 52 | 53 | extern int inflate_table OF((codetype type, unsigned short FAR *lens, 54 | unsigned codes, code FAR * FAR *table, 55 | unsigned FAR *bits, unsigned short FAR *work)); 56 | -------------------------------------------------------------------------------- /zlib-dll/isunzlib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) 4 | { 5 | if (dwReason == DLL_PROCESS_ATTACH) 6 | { 7 | DisableThreadLibraryCalls(hInstance); 8 | } 9 | return TRUE; 10 | } -------------------------------------------------------------------------------- /zlib-dll/isunzlib.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | inflateInit_ 3 | inflate 4 | inflateEnd 5 | inflateReset 6 | -------------------------------------------------------------------------------- /zlib-dll/isunzlib.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 13 | 19 | 31 | 33 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 63 | 69 | 79 | 81 | 92 | 94 | 96 | 98 | 100 | 102 | 104 | 106 | 108 | 110 | 112 | 113 | 114 | 115 | 116 | 117 | 121 | 123 | 124 | 126 | 127 | 129 | 130 | 132 | 133 | 135 | 136 | 138 | 139 | 140 | 144 | 145 | 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /zlib-dll/iszlib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) 4 | { 5 | if (dwReason == DLL_PROCESS_ATTACH) 6 | { 7 | DisableThreadLibraryCalls(hInstance); 8 | } 9 | return TRUE; 10 | } -------------------------------------------------------------------------------- /zlib-dll/iszlib.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | deflateInit_ 3 | deflate 4 | deflateEnd 5 | -------------------------------------------------------------------------------- /zlib-dll/iszlib.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 8.00 2 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "iszlib", "iszlib.vcproj", "{6F1F7AE1-A46A-4777-80EA-664F87FF6A1E}" 3 | ProjectSection(ProjectDependencies) = postProject 4 | EndProjectSection 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "isunzlib", "isunzlib.vcproj", "{DB26BFD2-B7F2-4C41-9A49-97125F249A7C}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | EndProjectSection 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfiguration) = preSolution 12 | Debug = Debug 13 | Release = Release 14 | EndGlobalSection 15 | GlobalSection(ProjectConfiguration) = postSolution 16 | {6F1F7AE1-A46A-4777-80EA-664F87FF6A1E}.Debug.ActiveCfg = Debug|Win32 17 | {6F1F7AE1-A46A-4777-80EA-664F87FF6A1E}.Debug.Build.0 = Debug|Win32 18 | {6F1F7AE1-A46A-4777-80EA-664F87FF6A1E}.Release.ActiveCfg = Release|Win32 19 | {6F1F7AE1-A46A-4777-80EA-664F87FF6A1E}.Release.Build.0 = Release|Win32 20 | {DB26BFD2-B7F2-4C41-9A49-97125F249A7C}.Debug.ActiveCfg = Debug|Win32 21 | {DB26BFD2-B7F2-4C41-9A49-97125F249A7C}.Debug.Build.0 = Debug|Win32 22 | {DB26BFD2-B7F2-4C41-9A49-97125F249A7C}.Release.ActiveCfg = Release|Win32 23 | {DB26BFD2-B7F2-4C41-9A49-97125F249A7C}.Release.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(ExtensibilityGlobals) = postSolution 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityAddIns) = postSolution 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /zlib-dll/iszlib.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 13 | 19 | 31 | 33 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 63 | 69 | 79 | 81 | 92 | 94 | 96 | 98 | 100 | 102 | 104 | 106 | 108 | 110 | 112 | 113 | 114 | 115 | 116 | 117 | 121 | 123 | 124 | 126 | 127 | 129 | 130 | 132 | 133 | 135 | 136 | 138 | 139 | 141 | 142 | 143 | 147 | 148 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /zlib-dll/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | This function can be used to decompress a whole file at once if the 20 | input file is mmap'ed. 21 | 22 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 23 | enough memory, Z_BUF_ERROR if there was not enough room in the output 24 | buffer, or Z_DATA_ERROR if the input data was corrupted. 25 | */ 26 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 27 | Bytef *dest; 28 | uLongf *destLen; 29 | const Bytef *source; 30 | uLong sourceLen; 31 | { 32 | z_stream stream; 33 | int err; 34 | 35 | stream.next_in = (Bytef*)source; 36 | stream.avail_in = (uInt)sourceLen; 37 | /* Check for source > 64K on 16-bit machine: */ 38 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 39 | 40 | stream.next_out = dest; 41 | stream.avail_out = (uInt)*destLen; 42 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 43 | 44 | stream.zalloc = (alloc_func)0; 45 | stream.zfree = (free_func)0; 46 | 47 | err = inflateInit(&stream); 48 | if (err != Z_OK) return err; 49 | 50 | err = inflate(&stream, Z_FINISH); 51 | if (err != Z_STREAM_END) { 52 | inflateEnd(&stream); 53 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 54 | return Z_DATA_ERROR; 55 | return err; 56 | } 57 | *destLen = stream.total_out; 58 | 59 | err = inflateEnd(&stream); 60 | return err; 61 | } 62 | -------------------------------------------------------------------------------- /zlib-dll/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #define ZLIB_INTERNAL 17 | #include "zlib.h" 18 | 19 | #ifdef STDC 20 | # ifndef _WIN32_WCE 21 | # include 22 | # endif 23 | # include 24 | # include 25 | #endif 26 | #ifdef NO_ERRNO_H 27 | # ifdef _WIN32_WCE 28 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 29 | * errno. We define it as a global variable to simplify porting. 30 | * Its value is always 0 and should not be used. We rename it to 31 | * avoid conflict with other libraries that use the same workaround. 32 | */ 33 | # define errno z_errno 34 | # endif 35 | extern int errno; 36 | #else 37 | # ifndef _WIN32_WCE 38 | # include 39 | # endif 40 | #endif 41 | 42 | #ifndef local 43 | # define local static 44 | #endif 45 | /* compile with -Dlocal if your debugger can't find static symbols */ 46 | 47 | typedef unsigned char uch; 48 | typedef uch FAR uchf; 49 | typedef unsigned short ush; 50 | typedef ush FAR ushf; 51 | typedef unsigned long ulg; 52 | 53 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 54 | /* (size given to avoid silly warnings with Visual C++) */ 55 | 56 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 57 | 58 | #define ERR_RETURN(strm,err) \ 59 | return (strm->msg = (char*)ERR_MSG(err), (err)) 60 | /* To be used only when the state is known to be valid */ 61 | 62 | /* common constants */ 63 | 64 | #ifndef DEF_WBITS 65 | # define DEF_WBITS MAX_WBITS 66 | #endif 67 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 68 | 69 | #if MAX_MEM_LEVEL >= 8 70 | # define DEF_MEM_LEVEL 8 71 | #else 72 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 73 | #endif 74 | /* default memLevel */ 75 | 76 | #define STORED_BLOCK 0 77 | #define STATIC_TREES 1 78 | #define DYN_TREES 2 79 | /* The three kinds of block type */ 80 | 81 | #define MIN_MATCH 3 82 | #define MAX_MATCH 258 83 | /* The minimum and maximum match lengths */ 84 | 85 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 86 | 87 | /* target dependencies */ 88 | 89 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 90 | # define OS_CODE 0x00 91 | # if defined(__TURBOC__) || defined(__BORLANDC__) 92 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 93 | /* Allow compilation with ANSI keywords only enabled */ 94 | void _Cdecl farfree( void *block ); 95 | void *_Cdecl farmalloc( unsigned long nbytes ); 96 | # else 97 | # include 98 | # endif 99 | # else /* MSC or DJGPP */ 100 | # include 101 | # endif 102 | #endif 103 | 104 | #ifdef AMIGA 105 | # define OS_CODE 0x01 106 | #endif 107 | 108 | #if defined(VAXC) || defined(VMS) 109 | # define OS_CODE 0x02 110 | # define F_OPEN(name, mode) \ 111 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 112 | #endif 113 | 114 | #if defined(ATARI) || defined(atarist) 115 | # define OS_CODE 0x05 116 | #endif 117 | 118 | #ifdef OS2 119 | # define OS_CODE 0x06 120 | # ifdef M_I86 121 | #include 122 | # endif 123 | #endif 124 | 125 | #if defined(MACOS) || defined(TARGET_OS_MAC) 126 | # define OS_CODE 0x07 127 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 128 | # include /* for fdopen */ 129 | # else 130 | # ifndef fdopen 131 | # define fdopen(fd,mode) NULL /* No fdopen() */ 132 | # endif 133 | # endif 134 | #endif 135 | 136 | #ifdef TOPS20 137 | # define OS_CODE 0x0a 138 | #endif 139 | 140 | #ifdef WIN32 141 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 142 | # define OS_CODE 0x0b 143 | # endif 144 | #endif 145 | 146 | #ifdef __50SERIES /* Prime/PRIMOS */ 147 | # define OS_CODE 0x0f 148 | #endif 149 | 150 | #if defined(_BEOS_) || defined(RISCOS) 151 | # define fdopen(fd,mode) NULL /* No fdopen() */ 152 | #endif 153 | 154 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) 155 | # if defined(_WIN32_WCE) 156 | # define fdopen(fd,mode) NULL /* No fdopen() */ 157 | # ifndef _PTRDIFF_T_DEFINED 158 | typedef int ptrdiff_t; 159 | # define _PTRDIFF_T_DEFINED 160 | # endif 161 | # else 162 | # define fdopen(fd,type) _fdopen(fd,type) 163 | # endif 164 | #endif 165 | 166 | /* common defaults */ 167 | 168 | #ifndef OS_CODE 169 | # define OS_CODE 0x03 /* assume Unix */ 170 | #endif 171 | 172 | #ifndef F_OPEN 173 | # define F_OPEN(name, mode) fopen((name), (mode)) 174 | #endif 175 | 176 | /* functions */ 177 | 178 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 179 | # ifndef HAVE_VSNPRINTF 180 | # define HAVE_VSNPRINTF 181 | # endif 182 | #endif 183 | #if defined(__CYGWIN__) 184 | # ifndef HAVE_VSNPRINTF 185 | # define HAVE_VSNPRINTF 186 | # endif 187 | #endif 188 | #ifndef HAVE_VSNPRINTF 189 | # ifdef MSDOS 190 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 191 | but for now we just assume it doesn't. */ 192 | # define NO_vsnprintf 193 | # endif 194 | # ifdef __TURBOC__ 195 | # define NO_vsnprintf 196 | # endif 197 | # ifdef WIN32 198 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 199 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 200 | # define vsnprintf _vsnprintf 201 | # endif 202 | # endif 203 | # ifdef __SASC 204 | # define NO_vsnprintf 205 | # endif 206 | #endif 207 | #ifdef VMS 208 | # define NO_vsnprintf 209 | #endif 210 | 211 | #if defined(pyr) 212 | # define NO_MEMCPY 213 | #endif 214 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 215 | /* Use our own functions for small and medium model with MSC <= 5.0. 216 | * You may have to use the same strategy for Borland C (untested). 217 | * The __SC__ check is for Symantec. 218 | */ 219 | # define NO_MEMCPY 220 | #endif 221 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 222 | # define HAVE_MEMCPY 223 | #endif 224 | #ifdef HAVE_MEMCPY 225 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 226 | # define zmemcpy _fmemcpy 227 | # define zmemcmp _fmemcmp 228 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 229 | # else 230 | # define zmemcpy memcpy 231 | # define zmemcmp memcmp 232 | # define zmemzero(dest, len) memset(dest, 0, len) 233 | # endif 234 | #else 235 | extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 236 | extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 237 | extern void zmemzero OF((Bytef* dest, uInt len)); 238 | #endif 239 | 240 | /* Diagnostic functions */ 241 | #ifdef DEBUG 242 | # include 243 | extern int z_verbose; 244 | extern void z_error OF((char *m)); 245 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 246 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 247 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 248 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 249 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 250 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 251 | #else 252 | # define Assert(cond,msg) 253 | # define Trace(x) 254 | # define Tracev(x) 255 | # define Tracevv(x) 256 | # define Tracec(c,x) 257 | # define Tracecv(c,x) 258 | #endif 259 | 260 | 261 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); 262 | void zcfree OF((voidpf opaque, voidpf ptr)); 263 | 264 | #define ZALLOC(strm, items, size) \ 265 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 266 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 267 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 268 | 269 | #endif /* ZUTIL_H */ 270 | -------------------------------------------------------------------------------- /zlib/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zlib.h" 9 | 10 | #define BASE 65521L /* largest prime smaller than 65536 */ 11 | #define NMAX 5552 12 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 13 | 14 | #define DO1(buf,i) {s1 += buf[i]; s2 += s1;} 15 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 16 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 17 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 18 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 19 | 20 | /* ========================================================================= */ 21 | uLong ZEXPORT adler32(adler, buf, len) 22 | uLong adler; 23 | const Bytef *buf; 24 | uInt len; 25 | { 26 | unsigned long s1 = adler & 0xffff; 27 | unsigned long s2 = (adler >> 16) & 0xffff; 28 | int k; 29 | 30 | if (buf == Z_NULL) return 1L; 31 | 32 | while (len > 0) { 33 | k = len < NMAX ? len : NMAX; 34 | len -= k; 35 | while (k >= 16) { 36 | DO16(buf); 37 | buf += 16; 38 | k -= 16; 39 | } 40 | if (k != 0) do { 41 | s1 += *buf++; 42 | s2 += s1; 43 | } while (--k); 44 | s1 %= BASE; 45 | s2 %= BASE; 46 | } 47 | return (s2 << 16) | s1; 48 | } 49 | -------------------------------------------------------------------------------- /zlib/crc32.c: -------------------------------------------------------------------------------- 1 | /* crc32.c -- compute the CRC-32 of a data stream 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zlib.h" 9 | 10 | #define local static 11 | 12 | #ifdef DYNAMIC_CRC_TABLE 13 | 14 | local int crc_table_empty = 1; 15 | local uLongf crc_table[256]; 16 | local void make_crc_table OF((void)); 17 | 18 | /* 19 | Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: 20 | 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. 21 | 22 | Polynomials over GF(2) are represented in binary, one bit per coefficient, 23 | with the lowest powers in the most significant bit. Then adding polynomials 24 | is just exclusive-or, and multiplying a polynomial by x is a right shift by 25 | one. If we call the above polynomial p, and represent a byte as the 26 | polynomial q, also with the lowest power in the most significant bit (so the 27 | byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, 28 | where a mod b means the remainder after dividing a by b. 29 | 30 | This calculation is done using the shift-register method of multiplying and 31 | taking the remainder. The register is initialized to zero, and for each 32 | incoming bit, x^32 is added mod p to the register if the bit is a one (where 33 | x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by 34 | x (which is shifting right by one and adding x^32 mod p if the bit shifted 35 | out is a one). We start with the highest power (least significant bit) of 36 | q and repeat for all eight bits of q. 37 | 38 | The table is simply the CRC of all possible eight bit values. This is all 39 | the information needed to generate CRC's on data a byte at a time for all 40 | combinations of CRC register values and incoming bytes. 41 | */ 42 | local void make_crc_table() 43 | { 44 | uLong c; 45 | int n, k; 46 | uLong poly; /* polynomial exclusive-or pattern */ 47 | /* terms of polynomial defining this crc (except x^32): */ 48 | static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 49 | 50 | /* make exclusive-or pattern from polynomial (0xedb88320L) */ 51 | poly = 0L; 52 | for (n = 0; n < sizeof(p)/sizeof(Byte); n++) 53 | poly |= 1L << (31 - p[n]); 54 | 55 | for (n = 0; n < 256; n++) 56 | { 57 | c = (uLong)n; 58 | for (k = 0; k < 8; k++) 59 | c = c & 1 ? poly ^ (c >> 1) : c >> 1; 60 | crc_table[n] = c; 61 | } 62 | crc_table_empty = 0; 63 | } 64 | #else 65 | /* ======================================================================== 66 | * Table of CRC-32's of all single-byte values (made by make_crc_table) 67 | */ 68 | local const uLongf crc_table[256] = { 69 | 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 70 | 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 71 | 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 72 | 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 73 | 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, 74 | 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 75 | 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 76 | 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, 77 | 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 78 | 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, 79 | 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 80 | 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 81 | 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, 82 | 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 83 | 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 84 | 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, 85 | 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 86 | 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, 87 | 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 88 | 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 89 | 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, 90 | 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 91 | 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, 92 | 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, 93 | 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 94 | 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, 95 | 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 96 | 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 97 | 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, 98 | 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 99 | 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 100 | 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, 101 | 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 102 | 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, 103 | 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 104 | 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 105 | 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, 106 | 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 107 | 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 108 | 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, 109 | 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 110 | 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, 111 | 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 112 | 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 113 | 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, 114 | 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 115 | 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 116 | 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, 117 | 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 118 | 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, 119 | 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 120 | 0x2d02ef8dL 121 | }; 122 | #endif 123 | 124 | /* ========================================================================= 125 | * This function can be used by asm versions of crc32() 126 | */ 127 | const uLongf * ZEXPORT get_crc_table() 128 | { 129 | #ifdef DYNAMIC_CRC_TABLE 130 | if (crc_table_empty) make_crc_table(); 131 | #endif 132 | return (const uLongf *)crc_table; 133 | } 134 | 135 | /* ========================================================================= */ 136 | #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); 137 | #define DO2(buf) DO1(buf); DO1(buf); 138 | #define DO4(buf) DO2(buf); DO2(buf); 139 | #define DO8(buf) DO4(buf); DO4(buf); 140 | 141 | /* ========================================================================= */ 142 | uLong ZEXPORT crc32(crc, buf, len) 143 | uLong crc; 144 | const Bytef *buf; 145 | uInt len; 146 | { 147 | if (buf == Z_NULL) return 0L; 148 | #ifdef DYNAMIC_CRC_TABLE 149 | if (crc_table_empty) 150 | make_crc_table(); 151 | #endif 152 | crc = crc ^ 0xffffffffL; 153 | while (len >= 8) 154 | { 155 | DO8(buf); 156 | len -= 8; 157 | } 158 | if (len) do { 159 | DO1(buf); 160 | } while (--len); 161 | return crc ^ 0xffffffffL; 162 | } 163 | -------------------------------------------------------------------------------- /zlib/infblock.h: -------------------------------------------------------------------------------- 1 | /* infblock.h -- header to use infblock.c 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | struct inflate_blocks_state; 12 | typedef struct inflate_blocks_state FAR inflate_blocks_statef; 13 | 14 | extern inflate_blocks_statef * inflate_blocks_new OF(( 15 | z_streamp z, 16 | check_func c, /* check function */ 17 | uInt w)); /* window size */ 18 | 19 | extern int inflate_blocks OF(( 20 | inflate_blocks_statef *, 21 | z_streamp , 22 | int)); /* initial return code */ 23 | 24 | extern void inflate_blocks_reset OF(( 25 | inflate_blocks_statef *, 26 | z_streamp , 27 | uLongf *)); /* check value on output */ 28 | 29 | extern int inflate_blocks_free OF(( 30 | inflate_blocks_statef *, 31 | z_streamp)); 32 | 33 | extern void inflate_set_dictionary OF(( 34 | inflate_blocks_statef *s, 35 | const Bytef *d, /* dictionary */ 36 | uInt n)); /* dictionary length */ 37 | 38 | extern int inflate_blocks_sync_point OF(( 39 | inflate_blocks_statef *s)); 40 | -------------------------------------------------------------------------------- /zlib/infcodes.h: -------------------------------------------------------------------------------- 1 | /* infcodes.h -- header to use infcodes.c 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | struct inflate_codes_state; 12 | typedef struct inflate_codes_state FAR inflate_codes_statef; 13 | 14 | extern inflate_codes_statef *inflate_codes_new OF(( 15 | uInt, uInt, 16 | inflate_huft *, inflate_huft *, 17 | z_streamp )); 18 | 19 | extern int inflate_codes OF(( 20 | inflate_blocks_statef *, 21 | z_streamp , 22 | int)); 23 | 24 | extern void inflate_codes_free OF(( 25 | inflate_codes_statef *, 26 | z_streamp )); 27 | 28 | -------------------------------------------------------------------------------- /zlib/inffast.c: -------------------------------------------------------------------------------- 1 | /* inffast.c -- process literals and length/distance pairs fast 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "zutil.h" 7 | #include "inftrees.h" 8 | #include "infblock.h" 9 | #include "infcodes.h" 10 | #include "infutil.h" 11 | #include "inffast.h" 12 | 13 | struct inflate_codes_state {int dummy;}; /* for buggy compilers */ 14 | 15 | /* simplify the use of the inflate_huft type with some defines */ 16 | #define exop word.what.Exop 17 | #define bits word.what.Bits 18 | 19 | /* macros for bit input with no checking and for returning unused bytes */ 20 | #define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<avail_in-n;c=(k>>3)>3:c;n+=c;p-=c;k-=c<<3;} 22 | 23 | /* Called with number of bytes left to write in window at least 258 24 | (the maximum string length) and number of input bytes available 25 | at least ten. The ten bytes are six bytes for the longest length/ 26 | distance pair plus four bytes for overloading the bit buffer. */ 27 | 28 | int inflate_fast(bl, bd, tl, td, s, z) 29 | uInt bl, bd; 30 | inflate_huft *tl; 31 | inflate_huft *td; /* need separate declaration for Borland C++ */ 32 | inflate_blocks_statef *s; 33 | z_streamp z; 34 | { 35 | inflate_huft *t; /* temporary pointer */ 36 | uInt e; /* extra bits or operation */ 37 | uLong b; /* bit buffer */ 38 | uInt k; /* bits in bit buffer */ 39 | Bytef *p; /* input data pointer */ 40 | uInt n; /* bytes available there */ 41 | Bytef *q; /* output window write pointer */ 42 | uInt m; /* bytes to end of window or read pointer */ 43 | uInt ml; /* mask for literal/length tree */ 44 | uInt md; /* mask for distance tree */ 45 | uInt c; /* bytes to copy */ 46 | uInt d; /* distance back to copy from */ 47 | Bytef *r; /* copy source pointer */ 48 | 49 | /* load input, output, bit values */ 50 | LOAD 51 | 52 | /* initialize masks */ 53 | ml = inflate_mask[bl]; 54 | md = inflate_mask[bd]; 55 | 56 | /* do until not enough input or output space for fast loop */ 57 | do { /* assume called with m >= 258 && n >= 10 */ 58 | /* get literal/length code */ 59 | GRABBITS(20) /* max bits for literal/length code */ 60 | if ((e = (t = tl + ((uInt)b & ml))->exop) == 0) 61 | { 62 | DUMPBITS(t->bits) 63 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? 64 | "inflate: * literal '%c'\n" : 65 | "inflate: * literal 0x%02x\n", t->base)); 66 | *q++ = (Byte)t->base; 67 | m--; 68 | continue; 69 | } 70 | do { 71 | DUMPBITS(t->bits) 72 | if (e & 16) 73 | { 74 | /* get extra bits for length */ 75 | e &= 15; 76 | c = t->base + ((uInt)b & inflate_mask[e]); 77 | DUMPBITS(e) 78 | Tracevv((stderr, "inflate: * length %u\n", c)); 79 | 80 | /* decode distance base of block to copy */ 81 | GRABBITS(15); /* max bits for distance code */ 82 | e = (t = td + ((uInt)b & md))->exop; 83 | do { 84 | DUMPBITS(t->bits) 85 | if (e & 16) 86 | { 87 | /* get extra bits to add to distance base */ 88 | e &= 15; 89 | GRABBITS(e) /* get extra bits (up to 13) */ 90 | d = t->base + ((uInt)b & inflate_mask[e]); 91 | DUMPBITS(e) 92 | Tracevv((stderr, "inflate: * distance %u\n", d)); 93 | 94 | /* do the copy */ 95 | m -= c; 96 | r = q - d; 97 | if (r < s->window) /* wrap if needed */ 98 | { 99 | do { 100 | r += s->end - s->window; /* force pointer in window */ 101 | } while (r < s->window); /* covers invalid distances */ 102 | e = s->end - r; 103 | if (c > e) 104 | { 105 | c -= e; /* wrapped copy */ 106 | do { 107 | *q++ = *r++; 108 | } while (--e); 109 | r = s->window; 110 | do { 111 | *q++ = *r++; 112 | } while (--c); 113 | } 114 | else /* normal copy */ 115 | { 116 | *q++ = *r++; c--; 117 | *q++ = *r++; c--; 118 | do { 119 | *q++ = *r++; 120 | } while (--c); 121 | } 122 | } 123 | else /* normal copy */ 124 | { 125 | *q++ = *r++; c--; 126 | *q++ = *r++; c--; 127 | do { 128 | *q++ = *r++; 129 | } while (--c); 130 | } 131 | break; 132 | } 133 | else if ((e & 64) == 0) 134 | { 135 | t += t->base; 136 | e = (t += ((uInt)b & inflate_mask[e]))->exop; 137 | } 138 | else 139 | { 140 | z->msg = (char*)"invalid distance code"; 141 | UNGRAB 142 | UPDATE 143 | return Z_DATA_ERROR; 144 | } 145 | } while (1); 146 | break; 147 | } 148 | if ((e & 64) == 0) 149 | { 150 | t += t->base; 151 | if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0) 152 | { 153 | DUMPBITS(t->bits) 154 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? 155 | "inflate: * literal '%c'\n" : 156 | "inflate: * literal 0x%02x\n", t->base)); 157 | *q++ = (Byte)t->base; 158 | m--; 159 | break; 160 | } 161 | } 162 | else if (e & 32) 163 | { 164 | Tracevv((stderr, "inflate: * end of block\n")); 165 | UNGRAB 166 | UPDATE 167 | return Z_STREAM_END; 168 | } 169 | else 170 | { 171 | z->msg = (char*)"invalid literal/length code"; 172 | UNGRAB 173 | UPDATE 174 | return Z_DATA_ERROR; 175 | } 176 | } while (1); 177 | } while (m >= 258 && n >= 10); 178 | 179 | /* not enough input or output--restore pointers and return */ 180 | UNGRAB 181 | UPDATE 182 | return Z_OK; 183 | } 184 | -------------------------------------------------------------------------------- /zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | extern int inflate_fast OF(( 12 | uInt, 13 | uInt, 14 | inflate_huft *, 15 | inflate_huft *, 16 | inflate_blocks_statef *, 17 | z_streamp )); 18 | -------------------------------------------------------------------------------- /zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Huffman code lookup table entry--this entry is four bytes for machines 12 | that have 16-bit pointers (e.g. PC's in the small or medium model). */ 13 | 14 | typedef struct inflate_huft_s FAR inflate_huft; 15 | 16 | struct inflate_huft_s { 17 | union { 18 | struct { 19 | Byte Exop; /* number of extra bits or operation */ 20 | Byte Bits; /* number of bits in this code or subcode */ 21 | } what; 22 | uInt pad; /* pad structure to a power of 2 (4 bytes for */ 23 | } word; /* 16-bit, 8 bytes for 32-bit int's) */ 24 | uInt base; /* literal, length base, distance base, 25 | or table offset */ 26 | }; 27 | 28 | /* Maximum size of dynamic tree. The maximum found in a long but non- 29 | exhaustive search was 1004 huft structures (850 for length/literals 30 | and 154 for distances, the latter actually the result of an 31 | exhaustive search). The actual maximum is not known, but the 32 | value below is more than safe. */ 33 | #define MANY 1440 34 | 35 | extern int inflate_trees_bits OF(( 36 | uIntf *, /* 19 code lengths */ 37 | uIntf *, /* bits tree desired/actual depth */ 38 | inflate_huft * FAR *, /* bits tree result */ 39 | inflate_huft *, /* space for trees */ 40 | z_streamp)); /* for messages */ 41 | 42 | extern int inflate_trees_dynamic OF(( 43 | uInt, /* number of literal/length codes */ 44 | uInt, /* number of distance codes */ 45 | uIntf *, /* that many (total) code lengths */ 46 | uIntf *, /* literal desired/actual bit depth */ 47 | uIntf *, /* distance desired/actual bit depth */ 48 | inflate_huft * FAR *, /* literal/length tree result */ 49 | inflate_huft * FAR *, /* distance tree result */ 50 | inflate_huft *, /* space for trees */ 51 | z_streamp)); /* for messages */ 52 | 53 | extern int inflate_trees_fixed OF(( 54 | uIntf *, /* literal desired/actual bit depth */ 55 | uIntf *, /* distance desired/actual bit depth */ 56 | inflate_huft * FAR *, /* literal/length tree result */ 57 | inflate_huft * FAR *, /* distance tree result */ 58 | z_streamp)); /* for memory allocation */ 59 | -------------------------------------------------------------------------------- /zlib/infutil.c: -------------------------------------------------------------------------------- 1 | /* inflate_util.c -- data and routines common to blocks and codes 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "zutil.h" 7 | #include "infblock.h" 8 | #include "inftrees.h" 9 | #include "infcodes.h" 10 | #include "infutil.h" 11 | 12 | struct inflate_codes_state {int dummy;}; /* for buggy compilers */ 13 | 14 | /* And'ing with mask[n] masks the lower n bits */ 15 | // JR : added ifdef. inflate_mask is moved to infutil.h in nonwin32 16 | #ifdef __WIN32__ 17 | uInt inflate_mask[17] = { 18 | 0x0000, 19 | 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, 20 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff 21 | }; 22 | #endif 23 | 24 | 25 | /* copy as much as possible from the sliding window to the output area */ 26 | int inflate_flush(s, z, r) 27 | inflate_blocks_statef *s; 28 | z_streamp z; 29 | int r; 30 | { 31 | uInt n; 32 | Bytef *p; 33 | Bytef *q; 34 | 35 | /* local copies of source and destination pointers */ 36 | p = z->next_out; 37 | q = s->read; 38 | 39 | /* compute number of bytes to copy as far as end of window */ 40 | n = (uInt)((q <= s->write ? s->write : s->end) - q); 41 | if (n > z->avail_out) n = z->avail_out; 42 | if (n && r == Z_BUF_ERROR) r = Z_OK; 43 | 44 | /* update counters */ 45 | z->avail_out -= n; 46 | z->total_out += n; 47 | 48 | /* update check information */ 49 | if (s->checkfn != Z_NULL) 50 | z->adler = s->check = (*s->checkfn)(s->check, q, n); 51 | 52 | /* copy as far as end of window */ 53 | zmemcpy(p, q, n); 54 | p += n; 55 | q += n; 56 | 57 | /* see if more to copy at beginning of window */ 58 | if (q == s->end) 59 | { 60 | /* wrap pointers */ 61 | q = s->window; 62 | if (s->write == s->end) 63 | s->write = s->window; 64 | 65 | /* compute bytes to copy */ 66 | n = (uInt)(s->write - q); 67 | if (n > z->avail_out) n = z->avail_out; 68 | if (n && r == Z_BUF_ERROR) r = Z_OK; 69 | 70 | /* update counters */ 71 | z->avail_out -= n; 72 | z->total_out += n; 73 | 74 | /* update check information */ 75 | if (s->checkfn != Z_NULL) 76 | z->adler = s->check = (*s->checkfn)(s->check, q, n); 77 | 78 | /* copy */ 79 | zmemcpy(p, q, n); 80 | p += n; 81 | q += n; 82 | } 83 | 84 | /* update pointers */ 85 | z->next_out = p; 86 | s->read = q; 87 | 88 | /* done */ 89 | return r; 90 | } 91 | -------------------------------------------------------------------------------- /zlib/infutil.h: -------------------------------------------------------------------------------- 1 | /* infutil.h -- types and macros common to blocks and codes 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | #ifndef _INFUTIL_H 12 | #define _INFUTIL_H 13 | 14 | typedef enum { 15 | TYPE, /* get type bits (3, including end bit) */ 16 | LENS, /* get lengths for stored */ 17 | STORED, /* processing stored block */ 18 | TABLE, /* get table lengths */ 19 | BTREE, /* get bit lengths tree for a dynamic block */ 20 | DTREE, /* get length, distance trees for a dynamic block */ 21 | CODES, /* processing fixed or dynamic block */ 22 | DRY, /* output remaining window bytes */ 23 | DONE, /* finished last block, done */ 24 | BAD} /* got a data error--stuck here */ 25 | inflate_block_mode; 26 | 27 | /* inflate blocks semi-private state */ 28 | struct inflate_blocks_state { 29 | 30 | /* mode */ 31 | inflate_block_mode mode; /* current inflate_block mode */ 32 | 33 | /* mode dependent information */ 34 | union { 35 | uInt left; /* if STORED, bytes left to copy */ 36 | struct { 37 | uInt table; /* table lengths (14 bits) */ 38 | uInt index; /* index into blens (or border) */ 39 | uIntf *blens; /* bit lengths of codes */ 40 | uInt bb; /* bit length tree depth */ 41 | inflate_huft *tb; /* bit length decoding tree */ 42 | } trees; /* if DTREE, decoding info for trees */ 43 | struct { 44 | inflate_codes_statef 45 | *codes; 46 | } decode; /* if CODES, current state */ 47 | } sub; /* submode */ 48 | uInt last; /* true if this block is the last block */ 49 | 50 | /* mode independent information */ 51 | uInt bitk; /* bits in bit buffer */ 52 | uLong bitb; /* bit buffer */ 53 | inflate_huft *hufts; /* single malloc for tree space */ 54 | Bytef *window; /* sliding window */ 55 | Bytef *end; /* one byte after sliding window */ 56 | Bytef *read; /* window read pointer */ 57 | Bytef *write; /* window write pointer */ 58 | check_func checkfn; /* check function */ 59 | uLong check; /* check on output */ 60 | 61 | }; 62 | 63 | 64 | /* defines for inflate input/output */ 65 | /* update pointers and return */ 66 | #define UPDBITS {s->bitb=b;s->bitk=k;} 67 | #define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;} 68 | #define UPDOUT {s->write=q;} 69 | #define UPDATE {UPDBITS UPDIN UPDOUT} 70 | #define LEAVE {UPDATE return inflate_flush(s,z,r);} 71 | /* get bytes and bits */ 72 | #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;} 73 | #define NEEDBYTE {if(n)r=Z_OK;else LEAVE} 74 | #define NEXTBYTE (n--,*p++) 75 | #define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<>=(j);k-=(j);} 77 | /* output bytes */ 78 | #define WAVAIL (uInt)(qread?s->read-q-1:s->end-q) 79 | #define LOADOUT {q=s->write;m=(uInt)WAVAIL;} 80 | #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}} 81 | #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT} 82 | #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;} 83 | #define OUTBYTE(a) {*q++=(Byte)(a);m--;} 84 | /* load local pointers */ 85 | #define LOAD {LOADIN LOADOUT} 86 | 87 | /* masks for lower bits (size given to avoid silly warnings with Visual C++) */ 88 | // JR : added ifdef. inflate_mask moved from infutil.c to here and added 'local' in nonwin32 89 | #ifdef __WIN32__ 90 | extern uInt inflate_mask[17]; 91 | #else 92 | local uInt inflate_mask[17] = { 93 | 0x0000, 94 | 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, 95 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff 96 | }; 97 | #endif 98 | 99 | /* copy as much as possible from the sliding window to the output area */ 100 | extern int inflate_flush OF(( 101 | inflate_blocks_statef *, 102 | z_streamp , 103 | int)); 104 | 105 | struct internal_state {int dummy;}; /* for buggy compilers */ 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /zlib/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2002 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | 10 | struct internal_state {int dummy;}; /* for buggy compilers */ 11 | 12 | #ifndef STDC 13 | extern void exit OF((int)); 14 | #endif 15 | 16 | //JR : added ifdef, 'local' under nonwin32 only 17 | #ifndef __WIN32__ 18 | local 19 | #endif 20 | const char *z_errmsg[10] = { 21 | "need dictionary", /* Z_NEED_DICT 2 */ 22 | "stream end", /* Z_STREAM_END 1 */ 23 | "", /* Z_OK 0 */ 24 | "file error", /* Z_ERRNO (-1) */ 25 | "stream error", /* Z_STREAM_ERROR (-2) */ 26 | "data error", /* Z_DATA_ERROR (-3) */ 27 | "insufficient memory", /* Z_MEM_ERROR (-4) */ 28 | "buffer error", /* Z_BUF_ERROR (-5) */ 29 | "incompatible version",/* Z_VERSION_ERROR (-6) */ 30 | ""}; 31 | 32 | 33 | const char * ZEXPORT zlibVersion() 34 | { 35 | return ZLIB_VERSION; 36 | } 37 | 38 | #ifdef DEBUG 39 | 40 | # ifndef verbose 41 | # define verbose 0 42 | # endif 43 | int z_verbose = verbose; 44 | 45 | void z_error (m) 46 | char *m; 47 | { 48 | fprintf(stderr, "%s\n", m); 49 | exit(1); 50 | } 51 | #endif 52 | 53 | /* exported to allow conversion of error code to string for compress() and 54 | * uncompress() 55 | */ 56 | const char * ZEXPORT zError(err) 57 | int err; 58 | { 59 | return ERR_MSG(err); 60 | } 61 | 62 | 63 | #ifndef HAVE_MEMCPY 64 | 65 | void zmemcpy(dest, source, len) 66 | Bytef* dest; 67 | const Bytef* source; 68 | uInt len; 69 | { 70 | if (len == 0) return; 71 | do { 72 | *dest++ = *source++; /* ??? to be unrolled */ 73 | } while (--len != 0); 74 | } 75 | 76 | int zmemcmp(s1, s2, len) 77 | const Bytef* s1; 78 | const Bytef* s2; 79 | uInt len; 80 | { 81 | uInt j; 82 | 83 | for (j = 0; j < len; j++) { 84 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 85 | } 86 | return 0; 87 | } 88 | 89 | void zmemzero(dest, len) 90 | Bytef* dest; 91 | uInt len; 92 | { 93 | if (len == 0) return; 94 | do { 95 | *dest++ = 0; /* ??? to be unrolled */ 96 | } while (--len != 0); 97 | } 98 | #endif 99 | 100 | #ifdef __TURBOC__ 101 | #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__) 102 | /* Small and medium model in Turbo C are for now limited to near allocation 103 | * with reduced MAX_WBITS and MAX_MEM_LEVEL 104 | */ 105 | # define MY_ZCALLOC 106 | 107 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 108 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 109 | * must fix the pointer. Warning: the pointer must be put back to its 110 | * original form in order to free it, use zcfree(). 111 | */ 112 | 113 | #define MAX_PTR 10 114 | /* 10*64K = 640K */ 115 | 116 | local int next_ptr = 0; 117 | 118 | typedef struct ptr_table_s { 119 | voidpf org_ptr; 120 | voidpf new_ptr; 121 | } ptr_table; 122 | 123 | local ptr_table table[MAX_PTR]; 124 | /* This table is used to remember the original form of pointers 125 | * to large buffers (64K). Such pointers are normalized with a zero offset. 126 | * Since MSDOS is not a preemptive multitasking OS, this table is not 127 | * protected from concurrent access. This hack doesn't work anyway on 128 | * a protected system like OS/2. Use Microsoft C instead. 129 | */ 130 | 131 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 132 | { 133 | voidpf buf = opaque; /* just to make some compilers happy */ 134 | ulg bsize = (ulg)items*size; 135 | 136 | /* If we allocate less than 65520 bytes, we assume that farmalloc 137 | * will return a usable pointer which doesn't have to be normalized. 138 | */ 139 | if (bsize < 65520L) { 140 | buf = farmalloc(bsize); 141 | if (*(ush*)&buf != 0) return buf; 142 | } else { 143 | buf = farmalloc(bsize + 16L); 144 | } 145 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 146 | table[next_ptr].org_ptr = buf; 147 | 148 | /* Normalize the pointer to seg:0 */ 149 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 150 | *(ush*)&buf = 0; 151 | table[next_ptr++].new_ptr = buf; 152 | return buf; 153 | } 154 | 155 | void zcfree (voidpf opaque, voidpf ptr) 156 | { 157 | int n; 158 | if (*(ush*)&ptr != 0) { /* object < 64K */ 159 | farfree(ptr); 160 | return; 161 | } 162 | /* Find the original pointer */ 163 | for (n = 0; n < next_ptr; n++) { 164 | if (ptr != table[n].new_ptr) continue; 165 | 166 | farfree(table[n].org_ptr); 167 | while (++n < next_ptr) { 168 | table[n-1] = table[n]; 169 | } 170 | next_ptr--; 171 | return; 172 | } 173 | ptr = opaque; /* just to make some compilers happy */ 174 | Assert(0, "zcfree: ptr not found"); 175 | } 176 | #endif 177 | #endif /* __TURBOC__ */ 178 | 179 | 180 | #if defined(M_I86) && !defined(__32BIT__) 181 | /* Microsoft C in 16-bit mode */ 182 | 183 | # define MY_ZCALLOC 184 | 185 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 186 | # define _halloc halloc 187 | # define _hfree hfree 188 | #endif 189 | 190 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 191 | { 192 | if (opaque) opaque = 0; /* to make compiler happy */ 193 | return _halloc((long)items, size); 194 | } 195 | 196 | void zcfree (voidpf opaque, voidpf ptr) 197 | { 198 | if (opaque) opaque = 0; /* to make compiler happy */ 199 | _hfree(ptr); 200 | } 201 | 202 | #endif /* MSC */ 203 | 204 | 205 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 206 | 207 | #ifndef STDC 208 | extern voidp calloc OF((uInt items, uInt size)); 209 | extern void free OF((voidpf ptr)); 210 | #endif 211 | 212 | voidpf zcalloc (opaque, items, size) 213 | voidpf opaque; 214 | unsigned items; 215 | unsigned size; 216 | { 217 | if (opaque) items += size - size; /* make compiler happy */ 218 | return (voidpf)calloc(items, size); 219 | } 220 | 221 | void zcfree (opaque, ptr) 222 | voidpf opaque; 223 | voidpf ptr; 224 | { 225 | free(ptr); 226 | if (opaque) return; /* make compiler happy */ 227 | } 228 | 229 | #endif /* MY_ZCALLOC */ 230 | -------------------------------------------------------------------------------- /zlib/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2002 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef _Z_UTIL_H 14 | #define _Z_UTIL_H 15 | 16 | #include "zlib.h" 17 | 18 | #ifdef STDC 19 | # include 20 | # include 21 | # include 22 | #endif 23 | #ifdef NO_ERRNO_H 24 | extern int errno; 25 | #else 26 | # include 27 | #endif 28 | 29 | #ifndef local 30 | # define local static 31 | #endif 32 | /* compile with -Dlocal if your debugger can't find static symbols */ 33 | 34 | typedef unsigned char uch; 35 | typedef uch FAR uchf; 36 | typedef unsigned short ush; 37 | typedef ush FAR ushf; 38 | typedef unsigned long ulg; 39 | 40 | extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ 41 | /* (size given to avoid silly warnings with Visual C++) */ 42 | 43 | // JR : changed the following. (borland modification?) 44 | #define ERR_MSG(err) " " 45 | //#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 46 | 47 | #define ERR_RETURN(strm,err) \ 48 | return (strm->msg = (char*)ERR_MSG(err), (err)) 49 | /* To be used only when the state is known to be valid */ 50 | 51 | /* common constants */ 52 | 53 | #ifndef DEF_WBITS 54 | # define DEF_WBITS MAX_WBITS 55 | #endif 56 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 57 | 58 | #if MAX_MEM_LEVEL >= 8 59 | # define DEF_MEM_LEVEL 8 60 | #else 61 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 62 | #endif 63 | /* default memLevel */ 64 | 65 | #define STORED_BLOCK 0 66 | #define STATIC_TREES 1 67 | #define DYN_TREES 2 68 | /* The three kinds of block type */ 69 | 70 | #define MIN_MATCH 3 71 | #define MAX_MATCH 258 72 | /* The minimum and maximum match lengths */ 73 | 74 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 75 | 76 | /* target dependencies */ 77 | 78 | #ifdef MSDOS 79 | # define OS_CODE 0x00 80 | # if defined(__TURBOC__) || defined(__BORLANDC__) 81 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 82 | /* Allow compilation with ANSI keywords only enabled */ 83 | void _Cdecl farfree( void *block ); 84 | void *_Cdecl farmalloc( unsigned long nbytes ); 85 | # else 86 | # include 87 | # endif 88 | # else /* MSC or DJGPP */ 89 | # include 90 | # endif 91 | #endif 92 | 93 | #ifdef OS2 94 | # define OS_CODE 0x06 95 | #endif 96 | 97 | #ifdef WIN32 /* Window 95 & Windows NT */ 98 | # define OS_CODE 0x0b 99 | #endif 100 | 101 | #if defined(VAXC) || defined(VMS) 102 | # define OS_CODE 0x02 103 | # define F_OPEN(name, mode) \ 104 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 105 | #endif 106 | 107 | #ifdef AMIGA 108 | # define OS_CODE 0x01 109 | #endif 110 | 111 | #if defined(ATARI) || defined(atarist) 112 | # define OS_CODE 0x05 113 | #endif 114 | 115 | #if defined(MACOS) || defined(TARGET_OS_MAC) 116 | # define OS_CODE 0x07 117 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 118 | # include /* for fdopen */ 119 | # else 120 | # ifndef fdopen 121 | # define fdopen(fd,mode) NULL /* No fdopen() */ 122 | # endif 123 | # endif 124 | #endif 125 | 126 | #ifdef __50SERIES /* Prime/PRIMOS */ 127 | # define OS_CODE 0x0F 128 | #endif 129 | 130 | #ifdef TOPS20 131 | # define OS_CODE 0x0a 132 | #endif 133 | 134 | #if defined(_BEOS_) || defined(RISCOS) 135 | # define fdopen(fd,mode) NULL /* No fdopen() */ 136 | #endif 137 | 138 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) 139 | # define fdopen(fd,type) _fdopen(fd,type) 140 | #endif 141 | 142 | 143 | /* Common defaults */ 144 | 145 | #ifndef OS_CODE 146 | # define OS_CODE 0x03 /* assume Unix */ 147 | #endif 148 | 149 | #ifndef F_OPEN 150 | # define F_OPEN(name, mode) fopen((name), (mode)) 151 | #endif 152 | 153 | /* functions */ 154 | 155 | #ifdef HAVE_STRERROR 156 | extern char *strerror OF((int)); 157 | # define zstrerror(errnum) strerror(errnum) 158 | #else 159 | # define zstrerror(errnum) "" 160 | #endif 161 | 162 | #if defined(pyr) 163 | # define NO_MEMCPY 164 | #endif 165 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 166 | /* Use our own functions for small and medium model with MSC <= 5.0. 167 | * You may have to use the same strategy for Borland C (untested). 168 | * The __SC__ check is for Symantec. 169 | */ 170 | # define NO_MEMCPY 171 | #endif 172 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 173 | # define HAVE_MEMCPY 174 | #endif 175 | #ifdef HAVE_MEMCPY 176 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 177 | # define zmemcpy _fmemcpy 178 | # define zmemcmp _fmemcmp 179 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 180 | # else 181 | # define zmemcpy memcpy 182 | # define zmemcmp memcmp 183 | # define zmemzero(dest, len) memset(dest, 0, len) 184 | # endif 185 | #else 186 | extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 187 | extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 188 | extern void zmemzero OF((Bytef* dest, uInt len)); 189 | #endif 190 | 191 | /* Diagnostic functions */ 192 | #ifdef DEBUG 193 | # include 194 | extern int z_verbose; 195 | extern void z_error OF((char *m)); 196 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 197 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 198 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 199 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 200 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 201 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 202 | #else 203 | # define Assert(cond,msg) 204 | # define Trace(x) 205 | # define Tracev(x) 206 | # define Tracevv(x) 207 | # define Tracec(c,x) 208 | # define Tracecv(c,x) 209 | #endif 210 | 211 | 212 | typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf, 213 | uInt len)); 214 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); 215 | void zcfree OF((voidpf opaque, voidpf ptr)); 216 | 217 | #define ZALLOC(strm, items, size) \ 218 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 219 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 220 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 221 | 222 | #endif /* _Z_UTIL_H */ 223 | --------------------------------------------------------------------------------