Merge pull request #513 from negativeExponent/simplity_multitap_core_option
authorAutechre <libretro@gmail.com>
Wed, 28 Apr 2021 20:28:46 +0000 (22:28 +0200)
committerGitHub <noreply@github.com>
Wed, 28 Apr 2021 20:28:46 +0000 (22:28 +0200)
Simplify multitap core options

231 files changed:
Makefile
Makefile.libretro
deps/crypto/README.md [deleted file]
deps/crypto/aes.c [deleted file]
deps/crypto/aes.h [deleted file]
deps/crypto/aes_test.c [deleted file]
deps/crypto/arcfour.c [deleted file]
deps/crypto/arcfour.h [deleted file]
deps/crypto/arcfour_test.c [deleted file]
deps/crypto/base64.c [deleted file]
deps/crypto/base64.h [deleted file]
deps/crypto/base64_test.c [deleted file]
deps/crypto/blowfish.c [deleted file]
deps/crypto/blowfish.h [deleted file]
deps/crypto/blowfish_test.c [deleted file]
deps/crypto/crypto_types.h [deleted file]
deps/crypto/des.c [deleted file]
deps/crypto/des.h [deleted file]
deps/crypto/des_test.c [deleted file]
deps/crypto/md2.c [deleted file]
deps/crypto/md2.h [deleted file]
deps/crypto/md2_test.c [deleted file]
deps/crypto/md5.c [deleted file]
deps/crypto/md5.h [deleted file]
deps/crypto/md5_test.c [deleted file]
deps/crypto/rot-13.c [deleted file]
deps/crypto/rot-13.h [deleted file]
deps/crypto/rot-13_test.c [deleted file]
deps/crypto/sha1.c [deleted file]
deps/crypto/sha1.h [deleted file]
deps/crypto/sha1_test.c [deleted file]
deps/crypto/sha256.c [deleted file]
deps/crypto/sha256.h [deleted file]
deps/crypto/sha256_test.c [deleted file]
deps/libchdr/.gitrepo [new file with mode: 0644]
deps/libchdr/CMakeLists.txt [new file with mode: 0644]
deps/libchdr/deps/lzma-19.00/CMakeLists.txt [new file with mode: 0644]
deps/libchdr/deps/lzma-19.00/LICENSE [new file with mode: 0644]
deps/libchdr/deps/lzma-19.00/include/7zTypes.h [new file with mode: 0644]
deps/libchdr/deps/lzma-19.00/include/Alloc.h [moved from deps/lzma-16.04/C/Alloc.h with 52% similarity]
deps/libchdr/deps/lzma-19.00/include/Bra.h [moved from deps/lzma-16.04/C/Bra.h with 96% similarity]
deps/libchdr/deps/lzma-19.00/include/Compiler.h [moved from deps/lzma-16.04/C/Compiler.h with 89% similarity]
deps/libchdr/deps/lzma-19.00/include/CpuArch.h [moved from deps/lzma-16.04/C/CpuArch.h with 61% similarity]
deps/libchdr/deps/lzma-19.00/include/Delta.h [moved from deps/lzma-16.04/C/Delta.h with 95% similarity]
deps/libchdr/deps/lzma-19.00/include/LzFind.h [moved from deps/lzma-16.04/C/LzFind.h with 91% similarity]
deps/libchdr/deps/lzma-19.00/include/LzHash.h [moved from deps/lzma-16.04/C/LzHash.h with 96% similarity]
deps/libchdr/deps/lzma-19.00/include/Lzma86.h [moved from deps/lzma-16.04/C/Lzma86.h with 96% similarity]
deps/libchdr/deps/lzma-19.00/include/LzmaDec.h [moved from deps/lzma-16.04/C/LzmaDec.h with 85% similarity]
deps/libchdr/deps/lzma-19.00/include/LzmaEnc.h [moved from deps/lzma-16.04/C/LzmaEnc.h with 61% similarity]
deps/libchdr/deps/lzma-19.00/include/LzmaLib.h [moved from deps/lzma-16.04/C/LzmaLib.h with 97% similarity]
deps/libchdr/deps/lzma-19.00/include/Precomp.h [moved from deps/lzma-16.04/C/Precomp.h with 94% similarity]
deps/libchdr/deps/lzma-19.00/include/Sort.h [moved from deps/lzma-16.04/C/Sort.h with 94% similarity]
deps/libchdr/deps/lzma-19.00/lzma-history.txt [moved from deps/lzma-16.04/DOC/lzma-history.txt with 75% similarity]
deps/libchdr/deps/lzma-19.00/lzma.txt [moved from deps/lzma-16.04/DOC/lzma.txt with 95% similarity]
deps/libchdr/deps/lzma-19.00/lzma.vcxproj [new file with mode: 0644]
deps/libchdr/deps/lzma-19.00/lzma.vcxproj.filters [new file with mode: 0644]
deps/libchdr/deps/lzma-19.00/src/Alloc.c [new file with mode: 0644]
deps/libchdr/deps/lzma-19.00/src/Bra86.c [moved from deps/lzma-16.04/C/Bra86.c with 91% similarity]
deps/libchdr/deps/lzma-19.00/src/BraIA64.c [new file with mode: 0644]
deps/libchdr/deps/lzma-19.00/src/CpuArch.c [moved from deps/lzma-16.04/C/CpuArch.c with 87% similarity]
deps/libchdr/deps/lzma-19.00/src/Delta.c [moved from deps/lzma-16.04/C/Delta.c with 95% similarity]
deps/libchdr/deps/lzma-19.00/src/LzFind.c [moved from deps/lzma-16.04/C/LzFind.c with 74% similarity]
deps/libchdr/deps/lzma-19.00/src/Lzma86Dec.c [moved from deps/lzma-16.04/C/Lzma86Dec.c with 95% similarity]
deps/libchdr/deps/lzma-19.00/src/LzmaDec.c [moved from deps/lzma-16.04/C/LzmaDec.c with 72% similarity]
deps/libchdr/deps/lzma-19.00/src/LzmaEnc.c [new file with mode: 0644]
deps/libchdr/deps/lzma-19.00/src/Sort.c [moved from deps/lzma-16.04/C/Sort.c with 94% similarity]
deps/libchdr/deps/zlib-1.2.11/CMakeLists.txt [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/ChangeLog [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/FAQ [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/INDEX [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/Makefile [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/Makefile.in [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/README [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/adler32.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/compress.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/configure [new file with mode: 0755]
deps/libchdr/deps/zlib-1.2.11/crc32.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/crc32.h [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/deflate.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/deflate.h [moved from deps/zlib/deflate.h with 92% similarity]
deps/libchdr/deps/zlib-1.2.11/doc/algorithm.txt [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/doc/rfc1950.txt [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/doc/rfc1951.txt [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/doc/rfc1952.txt [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/doc/txtvsbin.txt [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/gzclose.c [moved from deps/zlib/gzclose.c with 59% similarity]
deps/libchdr/deps/zlib-1.2.11/gzguts.h [moved from deps/zlib/gzguts.h with 84% similarity]
deps/libchdr/deps/zlib-1.2.11/gzlib.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/gzread.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/gzwrite.c [moved from deps/zlib/gzwrite.c with 58% similarity]
deps/libchdr/deps/zlib-1.2.11/infback.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/inffast.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/inffast.h [moved from deps/zlib/inffast.h with 90% similarity]
deps/libchdr/deps/zlib-1.2.11/inffixed.h [moved from deps/zlib/inffixed.h with 98% similarity]
deps/libchdr/deps/zlib-1.2.11/inflate.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/inflate.h [moved from deps/zlib/inflate.h with 94% similarity]
deps/libchdr/deps/zlib-1.2.11/inftrees.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/inftrees.h [moved from deps/zlib/inftrees.h with 98% similarity]
deps/libchdr/deps/zlib-1.2.11/make_vms.com [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/treebuild.xml [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/trees.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/trees.h [moved from deps/zlib/trees.h with 99% similarity]
deps/libchdr/deps/zlib-1.2.11/uncompr.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/zconf.h [moved from deps/zlib/zconf.h with 93% similarity]
deps/libchdr/deps/zlib-1.2.11/zconf.h.cmakein [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/zconf.h.in [moved from deps/zlib/zconf.h.in with 93% similarity]
deps/libchdr/deps/zlib-1.2.11/zlib.3 [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/zlib.3.pdf [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/zlib.h [moved from deps/zlib/zlib.h with 81% similarity]
deps/libchdr/deps/zlib-1.2.11/zlib.map [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/zlib.pc.cmakein [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/zlib.pc.in [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/zlib2ansi [new file with mode: 0755]
deps/libchdr/deps/zlib-1.2.11/zutil.c [new file with mode: 0644]
deps/libchdr/deps/zlib-1.2.11/zutil.h [moved from deps/zlib/zutil.h with 87% similarity]
deps/libchdr/include/libchdr/chd.h
deps/libchdr/pkg-config.pc.in [new file with mode: 0644]
deps/libchdr/src/libchdr_chd.c
deps/libchdr/src/link.T [new file with mode: 0644]
deps/libchdr/tests/benchmark.c [new file with mode: 0644]
deps/libchdr/tests/build_tests.sh [new file with mode: 0755]
deps/lzma-16.04/C/7z.h [deleted file]
deps/lzma-16.04/C/7zAlloc.c [deleted file]
deps/lzma-16.04/C/7zAlloc.h [deleted file]
deps/lzma-16.04/C/7zArcIn.c [deleted file]
deps/lzma-16.04/C/7zBuf.c [deleted file]
deps/lzma-16.04/C/7zBuf.h [deleted file]
deps/lzma-16.04/C/7zBuf2.c [deleted file]
deps/lzma-16.04/C/7zCrc.c [deleted file]
deps/lzma-16.04/C/7zCrc.h [deleted file]
deps/lzma-16.04/C/7zCrcOpt.c [deleted file]
deps/lzma-16.04/C/7zDec.c [deleted file]
deps/lzma-16.04/C/7zFile.c [deleted file]
deps/lzma-16.04/C/7zFile.h [deleted file]
deps/lzma-16.04/C/7zStream.c [deleted file]
deps/lzma-16.04/C/7zTypes.h [deleted file]
deps/lzma-16.04/C/7zVersion.h [deleted file]
deps/lzma-16.04/C/7zVersion.rc [deleted file]
deps/lzma-16.04/C/Aes.c [deleted file]
deps/lzma-16.04/C/Aes.h [deleted file]
deps/lzma-16.04/C/AesOpt.c [deleted file]
deps/lzma-16.04/C/Alloc.c [deleted file]
deps/lzma-16.04/C/Bcj2.c [deleted file]
deps/lzma-16.04/C/Bcj2.h [deleted file]
deps/lzma-16.04/C/Bcj2Enc.c [deleted file]
deps/lzma-16.04/C/Bra.c [deleted file]
deps/lzma-16.04/C/BraIA64.c [deleted file]
deps/lzma-16.04/C/DllSecur.c [deleted file]
deps/lzma-16.04/C/DllSecur.h [deleted file]
deps/lzma-16.04/C/LzFindMt.c [deleted file]
deps/lzma-16.04/C/LzFindMt.h [deleted file]
deps/lzma-16.04/C/Lzma2Dec.c [deleted file]
deps/lzma-16.04/C/Lzma2Dec.h [deleted file]
deps/lzma-16.04/C/Lzma2Enc.c [deleted file]
deps/lzma-16.04/C/Lzma2Enc.h [deleted file]
deps/lzma-16.04/C/Lzma86Enc.c [deleted file]
deps/lzma-16.04/C/LzmaEnc.c [deleted file]
deps/lzma-16.04/C/LzmaLib.c [deleted file]
deps/lzma-16.04/C/MtCoder.c [deleted file]
deps/lzma-16.04/C/MtCoder.h [deleted file]
deps/lzma-16.04/C/Ppmd.h [deleted file]
deps/lzma-16.04/C/Ppmd7.c [deleted file]
deps/lzma-16.04/C/Ppmd7.h [deleted file]
deps/lzma-16.04/C/Ppmd7Dec.c [deleted file]
deps/lzma-16.04/C/Ppmd7Enc.c [deleted file]
deps/lzma-16.04/C/RotateDefs.h [deleted file]
deps/lzma-16.04/C/Sha256.c [deleted file]
deps/lzma-16.04/C/Sha256.h [deleted file]
deps/lzma-16.04/C/Threads.c [deleted file]
deps/lzma-16.04/C/Threads.h [deleted file]
deps/lzma-16.04/C/Util/7z/7z.dsp [deleted file]
deps/lzma-16.04/C/Util/7z/7z.dsw [deleted file]
deps/lzma-16.04/C/Util/7z/7zMain.c [deleted file]
deps/lzma-16.04/C/Util/7z/Precomp.c [deleted file]
deps/lzma-16.04/C/Util/7z/Precomp.h [deleted file]
deps/lzma-16.04/C/Util/7z/makefile [deleted file]
deps/lzma-16.04/C/Util/7z/makefile.gcc [deleted file]
deps/lzma-16.04/C/Util/Lzma/LzmaUtil.c [deleted file]
deps/lzma-16.04/C/Util/Lzma/LzmaUtil.dsp [deleted file]
deps/lzma-16.04/C/Util/Lzma/LzmaUtil.dsw [deleted file]
deps/lzma-16.04/C/Util/Lzma/makefile [deleted file]
deps/lzma-16.04/C/Util/Lzma/makefile.gcc [deleted file]
deps/lzma-16.04/C/Util/LzmaLib/LzmaLib.def [deleted file]
deps/lzma-16.04/C/Util/LzmaLib/LzmaLib.dsp [deleted file]
deps/lzma-16.04/C/Util/LzmaLib/LzmaLib.dsw [deleted file]
deps/lzma-16.04/C/Util/LzmaLib/LzmaLibExports.c [deleted file]
deps/lzma-16.04/C/Util/LzmaLib/makefile [deleted file]
deps/lzma-16.04/C/Util/LzmaLib/resource.rc [deleted file]
deps/lzma-16.04/C/Util/SfxSetup/Precomp.c [deleted file]
deps/lzma-16.04/C/Util/SfxSetup/Precomp.h [deleted file]
deps/lzma-16.04/C/Util/SfxSetup/SfxSetup.c [deleted file]
deps/lzma-16.04/C/Util/SfxSetup/SfxSetup.dsp [deleted file]
deps/lzma-16.04/C/Util/SfxSetup/SfxSetup.dsw [deleted file]
deps/lzma-16.04/C/Util/SfxSetup/makefile [deleted file]
deps/lzma-16.04/C/Util/SfxSetup/makefile_con [deleted file]
deps/lzma-16.04/C/Util/SfxSetup/resource.rc [deleted file]
deps/lzma-16.04/C/Util/SfxSetup/setup.ico [deleted file]
deps/lzma-16.04/C/Xz.c [deleted file]
deps/lzma-16.04/C/Xz.h [deleted file]
deps/lzma-16.04/C/XzCrc64.c [deleted file]
deps/lzma-16.04/C/XzCrc64.h [deleted file]
deps/lzma-16.04/C/XzCrc64Opt.c [deleted file]
deps/lzma-16.04/C/XzDec.c [deleted file]
deps/lzma-16.04/C/XzEnc.c [deleted file]
deps/lzma-16.04/C/XzEnc.h [deleted file]
deps/lzma-16.04/C/XzIn.c [deleted file]
deps/lzma-16.04/DOC/7zC.txt [deleted file]
deps/lzma-16.04/DOC/7zFormat.txt [deleted file]
deps/lzma-16.04/DOC/Methods.txt [deleted file]
deps/lzma-16.04/DOC/installer.txt [deleted file]
deps/lzma-16.04/DOC/lzma-sdk.txt [deleted file]
deps/lzma-16.04/DOC/lzma-specification.txt [deleted file]
deps/zlib/adler32.c [deleted file]
deps/zlib/compress.c [deleted file]
deps/zlib/crc32.c [deleted file]
deps/zlib/deflate.c [deleted file]
deps/zlib/gzfile.h [deleted file]
deps/zlib/gzlib.c [deleted file]
deps/zlib/gzread.c [deleted file]
deps/zlib/infback.c [deleted file]
deps/zlib/inffast.c [deleted file]
deps/zlib/inflate.c [deleted file]
deps/zlib/inftrees.c [deleted file]
deps/zlib/ioapi.c [deleted file]
deps/zlib/ioapi.h [deleted file]
deps/zlib/trees.c [deleted file]
deps/zlib/uncompr.c [deleted file]
deps/zlib/unzip.c [deleted file]
deps/zlib/unzip.h [deleted file]
deps/zlib/zutil.c [deleted file]
jni/Android.mk

index 11da964..3d2d94e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -53,21 +53,22 @@ OBJS += libpcsxcore/cdriso.o libpcsxcore/cdrom.o libpcsxcore/cheat.o libpcsxcore
        libpcsxcore/sio.o libpcsxcore/socket.o libpcsxcore/spu.o
 OBJS += libpcsxcore/gte.o libpcsxcore/gte_nf.o libpcsxcore/gte_divider.o
 ifeq ($(WANT_ZLIB),1)
-CFLAGS += -Ideps/zlib
-OBJS += deps/zlib/adler32.o \
-        deps/zlib/compress.o \
-        deps/zlib/crc32.o \
-        deps/zlib/deflate.o \
-        deps/zlib/gzclose.o \
-        deps/zlib/gzlib.o \
-        deps/zlib/gzread.o \
-        deps/zlib/gzwrite.o \
-        deps/zlib/inffast.o \
-        deps/zlib/inflate.o \
-        deps/zlib/inftrees.o \
-        deps/zlib/trees.o \
-        deps/zlib/uncompr.o \
-        deps/zlib/zutil.o
+CFLAGS += -Ideps/libchdr/deps/zlib-1.2.11
+OBJS += deps/libchdr/deps/zlib-1.2.11/adler32.o \
+        deps/libchdr/deps/zlib-1.2.11/compress.o \
+        deps/libchdr/deps/zlib-1.2.11/crc32.o \
+        deps/libchdr/deps/zlib-1.2.11/deflate.o \
+        deps/libchdr/deps/zlib-1.2.11/gzclose.o \
+        deps/libchdr/deps/zlib-1.2.11/gzlib.o \
+        deps/libchdr/deps/zlib-1.2.11/gzread.o \
+        deps/libchdr/deps/zlib-1.2.11/gzwrite.o \
+        deps/libchdr/deps/zlib-1.2.11/infback.o \
+        deps/libchdr/deps/zlib-1.2.11/inffast.o \
+        deps/libchdr/deps/zlib-1.2.11/inflate.o \
+        deps/libchdr/deps/zlib-1.2.11/inftrees.o \
+        deps/libchdr/deps/zlib-1.2.11/trees.o \
+        deps/libchdr/deps/zlib-1.2.11/uncompr.o \
+        deps/libchdr/deps/zlib-1.2.11/zutil.o
 endif
 ifeq "$(ARCH)" "arm"
 OBJS += libpcsxcore/gte_arm.o
@@ -209,27 +210,22 @@ OBJS += plugins/cdrcimg/cdrcimg.o
 ifeq "$(HAVE_CHD)" "1"
 CFLAGS += -Ideps/libchdr/include
 CFLAGS += -Ideps/libchdr/include/libchdr
-OBJS += deps/crypto/md5.o
-OBJS += deps/crypto/sha1.o
-OBJS += deps/lzma-16.04/C/Alloc.o
-OBJS += deps/lzma-16.04/C/Bra86.o
-OBJS += deps/lzma-16.04/C/Bra.o
-OBJS += deps/lzma-16.04/C/BraIA64.o
-OBJS += deps/lzma-16.04/C/CpuArch.o
-OBJS += deps/lzma-16.04/C/Delta.o
-OBJS += deps/lzma-16.04/C/LzFind.o
-OBJS += deps/lzma-16.04/C/Lzma86Dec.o
-OBJS += deps/lzma-16.04/C/Lzma86Enc.o
-OBJS += deps/lzma-16.04/C/LzmaDec.o
-OBJS += deps/lzma-16.04/C/LzmaEnc.o
-OBJS += deps/lzma-16.04/C/LzmaLib.o
-OBJS += deps/lzma-16.04/C/Sort.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/Alloc.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/Bra86.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/BraIA64.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/CpuArch.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/Delta.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/LzFind.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/Lzma86Dec.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/LzmaDec.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/LzmaEnc.o
+OBJS += deps/libchdr/deps/lzma-19.00/src/Sort.o
 OBJS += deps/libchdr/src/libchdr_bitstream.o
 OBJS += deps/libchdr/src/libchdr_cdrom.o
 OBJS += deps/libchdr/src/libchdr_chd.o
 OBJS += deps/libchdr/src/libchdr_flac.o
 OBJS += deps/libchdr/src/libchdr_huffman.o
-CFLAGS += -Ideps/crypto -Ideps/lzma-16.04/C
+CFLAGS += -Ideps/libchdr/deps/lzma-19.00/include
 CFLAGS += -DHAVE_CHD -D_7ZIP_ST
 LDFLAGS += -lm
 endif
index ac91cf8..bd74dec 100644 (file)
@@ -252,6 +252,7 @@ else ifeq ($(platform), ctr)
        CFLAGS += -fomit-frame-pointer -ffast-math -funroll-loops
        CFLAGS += -Ifrontend/3ds -I$(CTRULIB)/include
        CFLAGS += -Werror=implicit-function-declaration
+       CFLAGS += -DHAVE_UNISTD_H
 
        OBJS += frontend/3ds/utils.o
 
diff --git a/deps/crypto/README.md b/deps/crypto/README.md
deleted file mode 100644 (file)
index 64eafd2..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-crypto-algorithms
-=================
-
-
-About
----
-These are basic implementations of standard cryptography algorithms, written by Brad Conte (brad@bradconte.com) from scratch and without any cross-licensing. They exist to provide publically accessible, restriction-free implementations of popular cryptographic algorithms, like AES and SHA-1. These are primarily intended for educational and pragmatic purposes (such as comparing a specification to actual implementation code, or for building an internal application that computes test vectors for a product). The algorithms have been tested against standard test vectors.
-
-This code is released into the public domain free of any restrictions. The author requests acknowledgement if the code is used, but does not require it. This code is provided free of any liability and without any quality claims by the author.
-
-Note that these are *not* cryptographically secure implementations. They have no resistence to side-channel attacks and should not be used in contexts that need cryptographically secure implementations.
-
-These algorithms are not optimized for speed or space. They are primarily designed to be easy to read, although some basic optimization techniques have been employed.
-
-Building
----
-The source code for each algorithm will come in a pair of a source code file and a header file. There should be no inter-header file dependencies, no additional libraries, no platform-specific header files, or any other complicating matters. Compiling them should be as easy as adding the relevent source code to the project.
\ No newline at end of file
diff --git a/deps/crypto/aes.c b/deps/crypto/aes.c
deleted file mode 100644 (file)
index c572839..0000000
+++ /dev/null
@@ -1,1095 +0,0 @@
-/*********************************************************************
-* Filename:   aes.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    This code is the implementation of the AES algorithm and
-              the CTR, CBC, and CCM modes of operation it can be used in.
-               AES is, specified by the NIST in in publication FIPS PUB 197,
-              availible at:
-               * http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf .
-              The CBC and CTR modes of operation are specified by
-              NIST SP 800-38 A, available at:
-               * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf .
-              The CCM mode of operation is specified by NIST SP80-38 C, available at:
-               * http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdlib.h>
-#include <string.h>
-#include "aes.h"
-
-#include <stdio.h>
-
-/****************************** MACROS ******************************/
-// The least significant byte of the word is rotated to the end.
-#define KE_ROTWORD(x) (((x) << 8) | ((x) >> 24))
-
-#define TRUE  1
-#define FALSE 0
-
-/**************************** DATA TYPES ****************************/
-#define AES_128_ROUNDS 10
-#define AES_192_ROUNDS 12
-#define AES_256_ROUNDS 14
-
-/*********************** FUNCTION DECLARATIONS **********************/
-void ccm_prepare_first_ctr_blk(BYTE counter[], const BYTE nonce[], int nonce_len, int payload_len_store_size);
-void ccm_prepare_first_format_blk(BYTE buf[], int assoc_len, int payload_len, int payload_len_store_size, int mac_len, const BYTE nonce[], int nonce_len);
-void ccm_format_assoc_data(BYTE buf[], int *end_of_buf, const BYTE assoc[], int assoc_len);
-void ccm_format_payload_data(BYTE buf[], int *end_of_buf, const BYTE payload[], int payload_len);
-
-/**************************** VARIABLES *****************************/
-// This is the specified AES SBox. To look up a substitution value, put the first
-// nibble in the first index (row) and the second nibble in the second index (column).
-static const BYTE aes_sbox[16][16] = {
-       {0x63,0x7C,0x77,0x7B,0xF2,0x6B,0x6F,0xC5,0x30,0x01,0x67,0x2B,0xFE,0xD7,0xAB,0x76},
-       {0xCA,0x82,0xC9,0x7D,0xFA,0x59,0x47,0xF0,0xAD,0xD4,0xA2,0xAF,0x9C,0xA4,0x72,0xC0},
-       {0xB7,0xFD,0x93,0x26,0x36,0x3F,0xF7,0xCC,0x34,0xA5,0xE5,0xF1,0x71,0xD8,0x31,0x15},
-       {0x04,0xC7,0x23,0xC3,0x18,0x96,0x05,0x9A,0x07,0x12,0x80,0xE2,0xEB,0x27,0xB2,0x75},
-       {0x09,0x83,0x2C,0x1A,0x1B,0x6E,0x5A,0xA0,0x52,0x3B,0xD6,0xB3,0x29,0xE3,0x2F,0x84},
-       {0x53,0xD1,0x00,0xED,0x20,0xFC,0xB1,0x5B,0x6A,0xCB,0xBE,0x39,0x4A,0x4C,0x58,0xCF},
-       {0xD0,0xEF,0xAA,0xFB,0x43,0x4D,0x33,0x85,0x45,0xF9,0x02,0x7F,0x50,0x3C,0x9F,0xA8},
-       {0x51,0xA3,0x40,0x8F,0x92,0x9D,0x38,0xF5,0xBC,0xB6,0xDA,0x21,0x10,0xFF,0xF3,0xD2},
-       {0xCD,0x0C,0x13,0xEC,0x5F,0x97,0x44,0x17,0xC4,0xA7,0x7E,0x3D,0x64,0x5D,0x19,0x73},
-       {0x60,0x81,0x4F,0xDC,0x22,0x2A,0x90,0x88,0x46,0xEE,0xB8,0x14,0xDE,0x5E,0x0B,0xDB},
-       {0xE0,0x32,0x3A,0x0A,0x49,0x06,0x24,0x5C,0xC2,0xD3,0xAC,0x62,0x91,0x95,0xE4,0x79},
-       {0xE7,0xC8,0x37,0x6D,0x8D,0xD5,0x4E,0xA9,0x6C,0x56,0xF4,0xEA,0x65,0x7A,0xAE,0x08},
-       {0xBA,0x78,0x25,0x2E,0x1C,0xA6,0xB4,0xC6,0xE8,0xDD,0x74,0x1F,0x4B,0xBD,0x8B,0x8A},
-       {0x70,0x3E,0xB5,0x66,0x48,0x03,0xF6,0x0E,0x61,0x35,0x57,0xB9,0x86,0xC1,0x1D,0x9E},
-       {0xE1,0xF8,0x98,0x11,0x69,0xD9,0x8E,0x94,0x9B,0x1E,0x87,0xE9,0xCE,0x55,0x28,0xDF},
-       {0x8C,0xA1,0x89,0x0D,0xBF,0xE6,0x42,0x68,0x41,0x99,0x2D,0x0F,0xB0,0x54,0xBB,0x16}
-};
-
-static const BYTE aes_invsbox[16][16] = {
-       {0x52,0x09,0x6A,0xD5,0x30,0x36,0xA5,0x38,0xBF,0x40,0xA3,0x9E,0x81,0xF3,0xD7,0xFB},
-       {0x7C,0xE3,0x39,0x82,0x9B,0x2F,0xFF,0x87,0x34,0x8E,0x43,0x44,0xC4,0xDE,0xE9,0xCB},
-       {0x54,0x7B,0x94,0x32,0xA6,0xC2,0x23,0x3D,0xEE,0x4C,0x95,0x0B,0x42,0xFA,0xC3,0x4E},
-       {0x08,0x2E,0xA1,0x66,0x28,0xD9,0x24,0xB2,0x76,0x5B,0xA2,0x49,0x6D,0x8B,0xD1,0x25},
-       {0x72,0xF8,0xF6,0x64,0x86,0x68,0x98,0x16,0xD4,0xA4,0x5C,0xCC,0x5D,0x65,0xB6,0x92},
-       {0x6C,0x70,0x48,0x50,0xFD,0xED,0xB9,0xDA,0x5E,0x15,0x46,0x57,0xA7,0x8D,0x9D,0x84},
-       {0x90,0xD8,0xAB,0x00,0x8C,0xBC,0xD3,0x0A,0xF7,0xE4,0x58,0x05,0xB8,0xB3,0x45,0x06},
-       {0xD0,0x2C,0x1E,0x8F,0xCA,0x3F,0x0F,0x02,0xC1,0xAF,0xBD,0x03,0x01,0x13,0x8A,0x6B},
-       {0x3A,0x91,0x11,0x41,0x4F,0x67,0xDC,0xEA,0x97,0xF2,0xCF,0xCE,0xF0,0xB4,0xE6,0x73},
-       {0x96,0xAC,0x74,0x22,0xE7,0xAD,0x35,0x85,0xE2,0xF9,0x37,0xE8,0x1C,0x75,0xDF,0x6E},
-       {0x47,0xF1,0x1A,0x71,0x1D,0x29,0xC5,0x89,0x6F,0xB7,0x62,0x0E,0xAA,0x18,0xBE,0x1B},
-       {0xFC,0x56,0x3E,0x4B,0xC6,0xD2,0x79,0x20,0x9A,0xDB,0xC0,0xFE,0x78,0xCD,0x5A,0xF4},
-       {0x1F,0xDD,0xA8,0x33,0x88,0x07,0xC7,0x31,0xB1,0x12,0x10,0x59,0x27,0x80,0xEC,0x5F},
-       {0x60,0x51,0x7F,0xA9,0x19,0xB5,0x4A,0x0D,0x2D,0xE5,0x7A,0x9F,0x93,0xC9,0x9C,0xEF},
-       {0xA0,0xE0,0x3B,0x4D,0xAE,0x2A,0xF5,0xB0,0xC8,0xEB,0xBB,0x3C,0x83,0x53,0x99,0x61},
-       {0x17,0x2B,0x04,0x7E,0xBA,0x77,0xD6,0x26,0xE1,0x69,0x14,0x63,0x55,0x21,0x0C,0x7D}
-};
-
-// This table stores pre-calculated values for all possible GF(2^8) calculations.This
-// table is only used by the (Inv)MixColumns steps.
-// USAGE: The second index (column) is the coefficient of multiplication. Only 7 different
-// coefficients are used: 0x01, 0x02, 0x03, 0x09, 0x0b, 0x0d, 0x0e, but multiplication by
-// 1 is negligible leaving only 6 coefficients. Each column of the table is devoted to one
-// of these coefficients, in the ascending order of value, from values 0x00 to 0xFF.
-static const BYTE gf_mul[256][6] = {
-       {0x00,0x00,0x00,0x00,0x00,0x00},{0x02,0x03,0x09,0x0b,0x0d,0x0e},
-       {0x04,0x06,0x12,0x16,0x1a,0x1c},{0x06,0x05,0x1b,0x1d,0x17,0x12},
-       {0x08,0x0c,0x24,0x2c,0x34,0x38},{0x0a,0x0f,0x2d,0x27,0x39,0x36},
-       {0x0c,0x0a,0x36,0x3a,0x2e,0x24},{0x0e,0x09,0x3f,0x31,0x23,0x2a},
-       {0x10,0x18,0x48,0x58,0x68,0x70},{0x12,0x1b,0x41,0x53,0x65,0x7e},
-       {0x14,0x1e,0x5a,0x4e,0x72,0x6c},{0x16,0x1d,0x53,0x45,0x7f,0x62},
-       {0x18,0x14,0x6c,0x74,0x5c,0x48},{0x1a,0x17,0x65,0x7f,0x51,0x46},
-       {0x1c,0x12,0x7e,0x62,0x46,0x54},{0x1e,0x11,0x77,0x69,0x4b,0x5a},
-       {0x20,0x30,0x90,0xb0,0xd0,0xe0},{0x22,0x33,0x99,0xbb,0xdd,0xee},
-       {0x24,0x36,0x82,0xa6,0xca,0xfc},{0x26,0x35,0x8b,0xad,0xc7,0xf2},
-       {0x28,0x3c,0xb4,0x9c,0xe4,0xd8},{0x2a,0x3f,0xbd,0x97,0xe9,0xd6},
-       {0x2c,0x3a,0xa6,0x8a,0xfe,0xc4},{0x2e,0x39,0xaf,0x81,0xf3,0xca},
-       {0x30,0x28,0xd8,0xe8,0xb8,0x90},{0x32,0x2b,0xd1,0xe3,0xb5,0x9e},
-       {0x34,0x2e,0xca,0xfe,0xa2,0x8c},{0x36,0x2d,0xc3,0xf5,0xaf,0x82},
-       {0x38,0x24,0xfc,0xc4,0x8c,0xa8},{0x3a,0x27,0xf5,0xcf,0x81,0xa6},
-       {0x3c,0x22,0xee,0xd2,0x96,0xb4},{0x3e,0x21,0xe7,0xd9,0x9b,0xba},
-       {0x40,0x60,0x3b,0x7b,0xbb,0xdb},{0x42,0x63,0x32,0x70,0xb6,0xd5},
-       {0x44,0x66,0x29,0x6d,0xa1,0xc7},{0x46,0x65,0x20,0x66,0xac,0xc9},
-       {0x48,0x6c,0x1f,0x57,0x8f,0xe3},{0x4a,0x6f,0x16,0x5c,0x82,0xed},
-       {0x4c,0x6a,0x0d,0x41,0x95,0xff},{0x4e,0x69,0x04,0x4a,0x98,0xf1},
-       {0x50,0x78,0x73,0x23,0xd3,0xab},{0x52,0x7b,0x7a,0x28,0xde,0xa5},
-       {0x54,0x7e,0x61,0x35,0xc9,0xb7},{0x56,0x7d,0x68,0x3e,0xc4,0xb9},
-       {0x58,0x74,0x57,0x0f,0xe7,0x93},{0x5a,0x77,0x5e,0x04,0xea,0x9d},
-       {0x5c,0x72,0x45,0x19,0xfd,0x8f},{0x5e,0x71,0x4c,0x12,0xf0,0x81},
-       {0x60,0x50,0xab,0xcb,0x6b,0x3b},{0x62,0x53,0xa2,0xc0,0x66,0x35},
-       {0x64,0x56,0xb9,0xdd,0x71,0x27},{0x66,0x55,0xb0,0xd6,0x7c,0x29},
-       {0x68,0x5c,0x8f,0xe7,0x5f,0x03},{0x6a,0x5f,0x86,0xec,0x52,0x0d},
-       {0x6c,0x5a,0x9d,0xf1,0x45,0x1f},{0x6e,0x59,0x94,0xfa,0x48,0x11},
-       {0x70,0x48,0xe3,0x93,0x03,0x4b},{0x72,0x4b,0xea,0x98,0x0e,0x45},
-       {0x74,0x4e,0xf1,0x85,0x19,0x57},{0x76,0x4d,0xf8,0x8e,0x14,0x59},
-       {0x78,0x44,0xc7,0xbf,0x37,0x73},{0x7a,0x47,0xce,0xb4,0x3a,0x7d},
-       {0x7c,0x42,0xd5,0xa9,0x2d,0x6f},{0x7e,0x41,0xdc,0xa2,0x20,0x61},
-       {0x80,0xc0,0x76,0xf6,0x6d,0xad},{0x82,0xc3,0x7f,0xfd,0x60,0xa3},
-       {0x84,0xc6,0x64,0xe0,0x77,0xb1},{0x86,0xc5,0x6d,0xeb,0x7a,0xbf},
-       {0x88,0xcc,0x52,0xda,0x59,0x95},{0x8a,0xcf,0x5b,0xd1,0x54,0x9b},
-       {0x8c,0xca,0x40,0xcc,0x43,0x89},{0x8e,0xc9,0x49,0xc7,0x4e,0x87},
-       {0x90,0xd8,0x3e,0xae,0x05,0xdd},{0x92,0xdb,0x37,0xa5,0x08,0xd3},
-       {0x94,0xde,0x2c,0xb8,0x1f,0xc1},{0x96,0xdd,0x25,0xb3,0x12,0xcf},
-       {0x98,0xd4,0x1a,0x82,0x31,0xe5},{0x9a,0xd7,0x13,0x89,0x3c,0xeb},
-       {0x9c,0xd2,0x08,0x94,0x2b,0xf9},{0x9e,0xd1,0x01,0x9f,0x26,0xf7},
-       {0xa0,0xf0,0xe6,0x46,0xbd,0x4d},{0xa2,0xf3,0xef,0x4d,0xb0,0x43},
-       {0xa4,0xf6,0xf4,0x50,0xa7,0x51},{0xa6,0xf5,0xfd,0x5b,0xaa,0x5f},
-       {0xa8,0xfc,0xc2,0x6a,0x89,0x75},{0xaa,0xff,0xcb,0x61,0x84,0x7b},
-       {0xac,0xfa,0xd0,0x7c,0x93,0x69},{0xae,0xf9,0xd9,0x77,0x9e,0x67},
-       {0xb0,0xe8,0xae,0x1e,0xd5,0x3d},{0xb2,0xeb,0xa7,0x15,0xd8,0x33},
-       {0xb4,0xee,0xbc,0x08,0xcf,0x21},{0xb6,0xed,0xb5,0x03,0xc2,0x2f},
-       {0xb8,0xe4,0x8a,0x32,0xe1,0x05},{0xba,0xe7,0x83,0x39,0xec,0x0b},
-       {0xbc,0xe2,0x98,0x24,0xfb,0x19},{0xbe,0xe1,0x91,0x2f,0xf6,0x17},
-       {0xc0,0xa0,0x4d,0x8d,0xd6,0x76},{0xc2,0xa3,0x44,0x86,0xdb,0x78},
-       {0xc4,0xa6,0x5f,0x9b,0xcc,0x6a},{0xc6,0xa5,0x56,0x90,0xc1,0x64},
-       {0xc8,0xac,0x69,0xa1,0xe2,0x4e},{0xca,0xaf,0x60,0xaa,0xef,0x40},
-       {0xcc,0xaa,0x7b,0xb7,0xf8,0x52},{0xce,0xa9,0x72,0xbc,0xf5,0x5c},
-       {0xd0,0xb8,0x05,0xd5,0xbe,0x06},{0xd2,0xbb,0x0c,0xde,0xb3,0x08},
-       {0xd4,0xbe,0x17,0xc3,0xa4,0x1a},{0xd6,0xbd,0x1e,0xc8,0xa9,0x14},
-       {0xd8,0xb4,0x21,0xf9,0x8a,0x3e},{0xda,0xb7,0x28,0xf2,0x87,0x30},
-       {0xdc,0xb2,0x33,0xef,0x90,0x22},{0xde,0xb1,0x3a,0xe4,0x9d,0x2c},
-       {0xe0,0x90,0xdd,0x3d,0x06,0x96},{0xe2,0x93,0xd4,0x36,0x0b,0x98},
-       {0xe4,0x96,0xcf,0x2b,0x1c,0x8a},{0xe6,0x95,0xc6,0x20,0x11,0x84},
-       {0xe8,0x9c,0xf9,0x11,0x32,0xae},{0xea,0x9f,0xf0,0x1a,0x3f,0xa0},
-       {0xec,0x9a,0xeb,0x07,0x28,0xb2},{0xee,0x99,0xe2,0x0c,0x25,0xbc},
-       {0xf0,0x88,0x95,0x65,0x6e,0xe6},{0xf2,0x8b,0x9c,0x6e,0x63,0xe8},
-       {0xf4,0x8e,0x87,0x73,0x74,0xfa},{0xf6,0x8d,0x8e,0x78,0x79,0xf4},
-       {0xf8,0x84,0xb1,0x49,0x5a,0xde},{0xfa,0x87,0xb8,0x42,0x57,0xd0},
-       {0xfc,0x82,0xa3,0x5f,0x40,0xc2},{0xfe,0x81,0xaa,0x54,0x4d,0xcc},
-       {0x1b,0x9b,0xec,0xf7,0xda,0x41},{0x19,0x98,0xe5,0xfc,0xd7,0x4f},
-       {0x1f,0x9d,0xfe,0xe1,0xc0,0x5d},{0x1d,0x9e,0xf7,0xea,0xcd,0x53},
-       {0x13,0x97,0xc8,0xdb,0xee,0x79},{0x11,0x94,0xc1,0xd0,0xe3,0x77},
-       {0x17,0x91,0xda,0xcd,0xf4,0x65},{0x15,0x92,0xd3,0xc6,0xf9,0x6b},
-       {0x0b,0x83,0xa4,0xaf,0xb2,0x31},{0x09,0x80,0xad,0xa4,0xbf,0x3f},
-       {0x0f,0x85,0xb6,0xb9,0xa8,0x2d},{0x0d,0x86,0xbf,0xb2,0xa5,0x23},
-       {0x03,0x8f,0x80,0x83,0x86,0x09},{0x01,0x8c,0x89,0x88,0x8b,0x07},
-       {0x07,0x89,0x92,0x95,0x9c,0x15},{0x05,0x8a,0x9b,0x9e,0x91,0x1b},
-       {0x3b,0xab,0x7c,0x47,0x0a,0xa1},{0x39,0xa8,0x75,0x4c,0x07,0xaf},
-       {0x3f,0xad,0x6e,0x51,0x10,0xbd},{0x3d,0xae,0x67,0x5a,0x1d,0xb3},
-       {0x33,0xa7,0x58,0x6b,0x3e,0x99},{0x31,0xa4,0x51,0x60,0x33,0x97},
-       {0x37,0xa1,0x4a,0x7d,0x24,0x85},{0x35,0xa2,0x43,0x76,0x29,0x8b},
-       {0x2b,0xb3,0x34,0x1f,0x62,0xd1},{0x29,0xb0,0x3d,0x14,0x6f,0xdf},
-       {0x2f,0xb5,0x26,0x09,0x78,0xcd},{0x2d,0xb6,0x2f,0x02,0x75,0xc3},
-       {0x23,0xbf,0x10,0x33,0x56,0xe9},{0x21,0xbc,0x19,0x38,0x5b,0xe7},
-       {0x27,0xb9,0x02,0x25,0x4c,0xf5},{0x25,0xba,0x0b,0x2e,0x41,0xfb},
-       {0x5b,0xfb,0xd7,0x8c,0x61,0x9a},{0x59,0xf8,0xde,0x87,0x6c,0x94},
-       {0x5f,0xfd,0xc5,0x9a,0x7b,0x86},{0x5d,0xfe,0xcc,0x91,0x76,0x88},
-       {0x53,0xf7,0xf3,0xa0,0x55,0xa2},{0x51,0xf4,0xfa,0xab,0x58,0xac},
-       {0x57,0xf1,0xe1,0xb6,0x4f,0xbe},{0x55,0xf2,0xe8,0xbd,0x42,0xb0},
-       {0x4b,0xe3,0x9f,0xd4,0x09,0xea},{0x49,0xe0,0x96,0xdf,0x04,0xe4},
-       {0x4f,0xe5,0x8d,0xc2,0x13,0xf6},{0x4d,0xe6,0x84,0xc9,0x1e,0xf8},
-       {0x43,0xef,0xbb,0xf8,0x3d,0xd2},{0x41,0xec,0xb2,0xf3,0x30,0xdc},
-       {0x47,0xe9,0xa9,0xee,0x27,0xce},{0x45,0xea,0xa0,0xe5,0x2a,0xc0},
-       {0x7b,0xcb,0x47,0x3c,0xb1,0x7a},{0x79,0xc8,0x4e,0x37,0xbc,0x74},
-       {0x7f,0xcd,0x55,0x2a,0xab,0x66},{0x7d,0xce,0x5c,0x21,0xa6,0x68},
-       {0x73,0xc7,0x63,0x10,0x85,0x42},{0x71,0xc4,0x6a,0x1b,0x88,0x4c},
-       {0x77,0xc1,0x71,0x06,0x9f,0x5e},{0x75,0xc2,0x78,0x0d,0x92,0x50},
-       {0x6b,0xd3,0x0f,0x64,0xd9,0x0a},{0x69,0xd0,0x06,0x6f,0xd4,0x04},
-       {0x6f,0xd5,0x1d,0x72,0xc3,0x16},{0x6d,0xd6,0x14,0x79,0xce,0x18},
-       {0x63,0xdf,0x2b,0x48,0xed,0x32},{0x61,0xdc,0x22,0x43,0xe0,0x3c},
-       {0x67,0xd9,0x39,0x5e,0xf7,0x2e},{0x65,0xda,0x30,0x55,0xfa,0x20},
-       {0x9b,0x5b,0x9a,0x01,0xb7,0xec},{0x99,0x58,0x93,0x0a,0xba,0xe2},
-       {0x9f,0x5d,0x88,0x17,0xad,0xf0},{0x9d,0x5e,0x81,0x1c,0xa0,0xfe},
-       {0x93,0x57,0xbe,0x2d,0x83,0xd4},{0x91,0x54,0xb7,0x26,0x8e,0xda},
-       {0x97,0x51,0xac,0x3b,0x99,0xc8},{0x95,0x52,0xa5,0x30,0x94,0xc6},
-       {0x8b,0x43,0xd2,0x59,0xdf,0x9c},{0x89,0x40,0xdb,0x52,0xd2,0x92},
-       {0x8f,0x45,0xc0,0x4f,0xc5,0x80},{0x8d,0x46,0xc9,0x44,0xc8,0x8e},
-       {0x83,0x4f,0xf6,0x75,0xeb,0xa4},{0x81,0x4c,0xff,0x7e,0xe6,0xaa},
-       {0x87,0x49,0xe4,0x63,0xf1,0xb8},{0x85,0x4a,0xed,0x68,0xfc,0xb6},
-       {0xbb,0x6b,0x0a,0xb1,0x67,0x0c},{0xb9,0x68,0x03,0xba,0x6a,0x02},
-       {0xbf,0x6d,0x18,0xa7,0x7d,0x10},{0xbd,0x6e,0x11,0xac,0x70,0x1e},
-       {0xb3,0x67,0x2e,0x9d,0x53,0x34},{0xb1,0x64,0x27,0x96,0x5e,0x3a},
-       {0xb7,0x61,0x3c,0x8b,0x49,0x28},{0xb5,0x62,0x35,0x80,0x44,0x26},
-       {0xab,0x73,0x42,0xe9,0x0f,0x7c},{0xa9,0x70,0x4b,0xe2,0x02,0x72},
-       {0xaf,0x75,0x50,0xff,0x15,0x60},{0xad,0x76,0x59,0xf4,0x18,0x6e},
-       {0xa3,0x7f,0x66,0xc5,0x3b,0x44},{0xa1,0x7c,0x6f,0xce,0x36,0x4a},
-       {0xa7,0x79,0x74,0xd3,0x21,0x58},{0xa5,0x7a,0x7d,0xd8,0x2c,0x56},
-       {0xdb,0x3b,0xa1,0x7a,0x0c,0x37},{0xd9,0x38,0xa8,0x71,0x01,0x39},
-       {0xdf,0x3d,0xb3,0x6c,0x16,0x2b},{0xdd,0x3e,0xba,0x67,0x1b,0x25},
-       {0xd3,0x37,0x85,0x56,0x38,0x0f},{0xd1,0x34,0x8c,0x5d,0x35,0x01},
-       {0xd7,0x31,0x97,0x40,0x22,0x13},{0xd5,0x32,0x9e,0x4b,0x2f,0x1d},
-       {0xcb,0x23,0xe9,0x22,0x64,0x47},{0xc9,0x20,0xe0,0x29,0x69,0x49},
-       {0xcf,0x25,0xfb,0x34,0x7e,0x5b},{0xcd,0x26,0xf2,0x3f,0x73,0x55},
-       {0xc3,0x2f,0xcd,0x0e,0x50,0x7f},{0xc1,0x2c,0xc4,0x05,0x5d,0x71},
-       {0xc7,0x29,0xdf,0x18,0x4a,0x63},{0xc5,0x2a,0xd6,0x13,0x47,0x6d},
-       {0xfb,0x0b,0x31,0xca,0xdc,0xd7},{0xf9,0x08,0x38,0xc1,0xd1,0xd9},
-       {0xff,0x0d,0x23,0xdc,0xc6,0xcb},{0xfd,0x0e,0x2a,0xd7,0xcb,0xc5},
-       {0xf3,0x07,0x15,0xe6,0xe8,0xef},{0xf1,0x04,0x1c,0xed,0xe5,0xe1},
-       {0xf7,0x01,0x07,0xf0,0xf2,0xf3},{0xf5,0x02,0x0e,0xfb,0xff,0xfd},
-       {0xeb,0x13,0x79,0x92,0xb4,0xa7},{0xe9,0x10,0x70,0x99,0xb9,0xa9},
-       {0xef,0x15,0x6b,0x84,0xae,0xbb},{0xed,0x16,0x62,0x8f,0xa3,0xb5},
-       {0xe3,0x1f,0x5d,0xbe,0x80,0x9f},{0xe1,0x1c,0x54,0xb5,0x8d,0x91},
-       {0xe7,0x19,0x4f,0xa8,0x9a,0x83},{0xe5,0x1a,0x46,0xa3,0x97,0x8d}
-};
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-// XORs the in and out buffers, storing the result in out. Length is in bytes.
-void xor_buf(const BYTE in[], BYTE out[], size_t len)
-{
-       size_t idx;
-
-       for (idx = 0; idx < len; idx++)
-               out[idx] ^= in[idx];
-}
-
-/*******************
-* AES - CBC
-*******************/
-int aes_encrypt_cbc(const BYTE in[], size_t in_len, BYTE out[], const WORD key[], int keysize, const BYTE iv[])
-{
-       BYTE buf_in[AES_BLOCK_SIZE], buf_out[AES_BLOCK_SIZE], iv_buf[AES_BLOCK_SIZE];
-       int blocks, idx;
-
-       if (in_len % AES_BLOCK_SIZE != 0)
-               return(FALSE);
-
-       blocks = in_len / AES_BLOCK_SIZE;
-
-       memcpy(iv_buf, iv, AES_BLOCK_SIZE);
-
-       for (idx = 0; idx < blocks; idx++) {
-               memcpy(buf_in, &in[idx * AES_BLOCK_SIZE], AES_BLOCK_SIZE);
-               xor_buf(iv_buf, buf_in, AES_BLOCK_SIZE);
-               aes_encrypt(buf_in, buf_out, key, keysize);
-               memcpy(&out[idx * AES_BLOCK_SIZE], buf_out, AES_BLOCK_SIZE);
-               memcpy(iv_buf, buf_out, AES_BLOCK_SIZE);
-       }
-
-       return(TRUE);
-}
-
-int aes_encrypt_cbc_mac(const BYTE in[], size_t in_len, BYTE out[], const WORD key[], int keysize, const BYTE iv[])
-{
-       BYTE buf_in[AES_BLOCK_SIZE], buf_out[AES_BLOCK_SIZE], iv_buf[AES_BLOCK_SIZE];
-       int blocks, idx;
-
-       if (in_len % AES_BLOCK_SIZE != 0)
-               return(FALSE);
-
-       blocks = in_len / AES_BLOCK_SIZE;
-
-       memcpy(iv_buf, iv, AES_BLOCK_SIZE);
-
-       for (idx = 0; idx < blocks; idx++) {
-               memcpy(buf_in, &in[idx * AES_BLOCK_SIZE], AES_BLOCK_SIZE);
-               xor_buf(iv_buf, buf_in, AES_BLOCK_SIZE);
-               aes_encrypt(buf_in, buf_out, key, keysize);
-               memcpy(iv_buf, buf_out, AES_BLOCK_SIZE);
-               // Do not output all encrypted blocks.
-       }
-
-       memcpy(out, buf_out, AES_BLOCK_SIZE);   // Only output the last block.
-
-       return(TRUE);
-}
-
-int aes_decrypt_cbc(const BYTE in[], size_t in_len, BYTE out[], const WORD key[], int keysize, const BYTE iv[])
-{
-       BYTE buf_in[AES_BLOCK_SIZE], buf_out[AES_BLOCK_SIZE], iv_buf[AES_BLOCK_SIZE];
-       int blocks, idx;
-
-       if (in_len % AES_BLOCK_SIZE != 0)
-               return(FALSE);
-
-       blocks = in_len / AES_BLOCK_SIZE;
-
-       memcpy(iv_buf, iv, AES_BLOCK_SIZE);
-
-       for (idx = 0; idx < blocks; idx++) {
-               memcpy(buf_in, &in[idx * AES_BLOCK_SIZE], AES_BLOCK_SIZE);
-               aes_decrypt(buf_in, buf_out, key, keysize);
-               xor_buf(iv_buf, buf_out, AES_BLOCK_SIZE);
-               memcpy(&out[idx * AES_BLOCK_SIZE], buf_out, AES_BLOCK_SIZE);
-               memcpy(iv_buf, buf_in, AES_BLOCK_SIZE);
-       }
-
-       return(TRUE);
-}
-
-/*******************
-* AES - CTR
-*******************/
-void increment_iv(BYTE iv[], int counter_size)
-{
-       int idx;
-
-       // Use counter_size bytes at the end of the IV as the big-endian integer to increment.
-       for (idx = AES_BLOCK_SIZE - 1; idx >= AES_BLOCK_SIZE - counter_size; idx--) {
-               iv[idx]++;
-               if (iv[idx] != 0 || idx == AES_BLOCK_SIZE - counter_size)
-                       break;
-       }
-}
-
-// Performs the encryption in-place, the input and output buffers may be the same.
-// Input may be an arbitrary length (in bytes).
-void aes_encrypt_ctr(const BYTE in[], size_t in_len, BYTE out[], const WORD key[], int keysize, const BYTE iv[])
-{
-       size_t idx = 0, last_block_length;
-       BYTE iv_buf[AES_BLOCK_SIZE], out_buf[AES_BLOCK_SIZE];
-
-       if (in != out)
-               memcpy(out, in, in_len);
-
-       memcpy(iv_buf, iv, AES_BLOCK_SIZE);
-       last_block_length = in_len - AES_BLOCK_SIZE;
-
-       if (in_len > AES_BLOCK_SIZE) {
-               for (idx = 0; idx < last_block_length; idx += AES_BLOCK_SIZE) {
-                       aes_encrypt(iv_buf, out_buf, key, keysize);
-                       xor_buf(out_buf, &out[idx], AES_BLOCK_SIZE);
-                       increment_iv(iv_buf, AES_BLOCK_SIZE);
-               }
-       }
-
-       aes_encrypt(iv_buf, out_buf, key, keysize);
-       xor_buf(out_buf, &out[idx], in_len - idx);   // Use the Most Significant bytes.
-}
-
-void aes_decrypt_ctr(const BYTE in[], size_t in_len, BYTE out[], const WORD key[], int keysize, const BYTE iv[])
-{
-       // CTR encryption is its own inverse function.
-       aes_encrypt_ctr(in, in_len, out, key, keysize, iv);
-}
-
-/*******************
-* AES - CCM
-*******************/
-// out_len = payload_len + assoc_len
-int aes_encrypt_ccm(const BYTE payload[], WORD payload_len, const BYTE assoc[], unsigned short assoc_len,
-                    const BYTE nonce[], unsigned short nonce_len, BYTE out[], WORD *out_len,
-                    WORD mac_len, const BYTE key_str[], int keysize)
-{
-       BYTE temp_iv[AES_BLOCK_SIZE], counter[AES_BLOCK_SIZE], mac[16], *buf;
-       int end_of_buf, payload_len_store_size;
-       WORD key[60];
-
-       if (mac_len != 4 && mac_len != 6 && mac_len != 8 && mac_len != 10 &&
-          mac_len != 12 && mac_len != 14 && mac_len != 16)
-               return(FALSE);
-
-       if (nonce_len < 7 || nonce_len > 13)
-               return(FALSE);
-
-       if (assoc_len > 32768 /* = 2^15 */)
-               return(FALSE);
-
-       buf = (BYTE*)malloc(payload_len + assoc_len + 48 /*Round both payload and associated data up a block size and add an extra block.*/);
-       if (! buf)
-               return(FALSE);
-
-       // Prepare the key for usage.
-       aes_key_setup(key_str, key, keysize);
-
-       // Format the first block of the formatted data.
-       payload_len_store_size = AES_BLOCK_SIZE - 1 - nonce_len;
-       ccm_prepare_first_format_blk(buf, assoc_len, payload_len, payload_len_store_size, mac_len, nonce, nonce_len);
-       end_of_buf = AES_BLOCK_SIZE;
-
-       // Format the Associated Data, aka, assoc[].
-       ccm_format_assoc_data(buf, &end_of_buf, assoc, assoc_len);
-
-       // Format the Payload, aka payload[].
-       ccm_format_payload_data(buf, &end_of_buf, payload, payload_len);
-
-       // Create the first counter block.
-       ccm_prepare_first_ctr_blk(counter, nonce, nonce_len, payload_len_store_size);
-
-       // Perform the CBC operation with an IV of zeros on the formatted buffer to calculate the MAC.
-       memset(temp_iv, 0, AES_BLOCK_SIZE);
-       aes_encrypt_cbc_mac(buf, end_of_buf, mac, key, keysize, temp_iv);
-
-       // Copy the Payload and MAC to the output buffer.
-       memcpy(out, payload, payload_len);
-       memcpy(&out[payload_len], mac, mac_len);
-
-       // Encrypt the Payload with CTR mode with a counter starting at 1.
-       memcpy(temp_iv, counter, AES_BLOCK_SIZE);
-       increment_iv(temp_iv, AES_BLOCK_SIZE - 1 - mac_len);   // Last argument is the byte size of the counting portion of the counter block. /*BUG?*/
-       aes_encrypt_ctr(out, payload_len, out, key, keysize, temp_iv);
-
-       // Encrypt the MAC with CTR mode with a counter starting at 0.
-       aes_encrypt_ctr(&out[payload_len], mac_len, &out[payload_len], key, keysize, counter);
-
-       free(buf);
-       *out_len = payload_len + mac_len;
-
-       return(TRUE);
-}
-
-// plaintext_len = ciphertext_len - mac_len
-// Needs a flag for whether the MAC matches.
-int aes_decrypt_ccm(const BYTE ciphertext[], WORD ciphertext_len, const BYTE assoc[], unsigned short assoc_len,
-                    const BYTE nonce[], unsigned short nonce_len, BYTE plaintext[], WORD *plaintext_len,
-                    WORD mac_len, int *mac_auth, const BYTE key_str[], int keysize)
-{
-       BYTE temp_iv[AES_BLOCK_SIZE], counter[AES_BLOCK_SIZE], mac[16], mac_buf[16], *buf;
-       int end_of_buf, plaintext_len_store_size;
-       WORD key[60];
-
-       if (ciphertext_len <= mac_len)
-               return(FALSE);
-
-       buf = (BYTE*)malloc(assoc_len + ciphertext_len /*ciphertext_len = plaintext_len + mac_len*/ + 48);
-       if (! buf)
-               return(FALSE);
-
-       // Prepare the key for usage.
-       aes_key_setup(key_str, key, keysize);
-
-       // Copy the plaintext and MAC to the output buffers.
-       *plaintext_len = ciphertext_len - mac_len;
-       plaintext_len_store_size = AES_BLOCK_SIZE - 1 - nonce_len;
-       memcpy(plaintext, ciphertext, *plaintext_len);
-       memcpy(mac, &ciphertext[*plaintext_len], mac_len);
-
-       // Prepare the first counter block for use in decryption.
-       ccm_prepare_first_ctr_blk(counter, nonce, nonce_len, plaintext_len_store_size);
-
-       // Decrypt the Payload with CTR mode with a counter starting at 1.
-       memcpy(temp_iv, counter, AES_BLOCK_SIZE);
-       increment_iv(temp_iv, AES_BLOCK_SIZE - 1 - mac_len);   // (AES_BLOCK_SIZE - 1 - mac_len) is the byte size of the counting portion of the counter block.
-       aes_decrypt_ctr(plaintext, *plaintext_len, plaintext, key, keysize, temp_iv);
-
-       // Setting mac_auth to NULL disables the authentication check.
-       if (mac_auth != NULL) {
-               // Decrypt the MAC with CTR mode with a counter starting at 0.
-               aes_decrypt_ctr(mac, mac_len, mac, key, keysize, counter);
-
-               // Format the first block of the formatted data.
-               plaintext_len_store_size = AES_BLOCK_SIZE - 1 - nonce_len;
-               ccm_prepare_first_format_blk(buf, assoc_len, *plaintext_len, plaintext_len_store_size, mac_len, nonce, nonce_len);
-               end_of_buf = AES_BLOCK_SIZE;
-
-               // Format the Associated Data into the authentication buffer.
-               ccm_format_assoc_data(buf, &end_of_buf, assoc, assoc_len);
-
-               // Format the Payload into the authentication buffer.
-               ccm_format_payload_data(buf, &end_of_buf, plaintext, *plaintext_len);
-
-               // Perform the CBC operation with an IV of zeros on the formatted buffer to calculate the MAC.
-               memset(temp_iv, 0, AES_BLOCK_SIZE);
-               aes_encrypt_cbc_mac(buf, end_of_buf, mac_buf, key, keysize, temp_iv);
-
-               // Compare the calculated MAC against the MAC embedded in the ciphertext to see if they are the same.
-               if (! memcmp(mac, mac_buf, mac_len)) {
-                       *mac_auth = TRUE;
-               }
-               else {
-                       *mac_auth = FALSE;
-                       memset(plaintext, 0, *plaintext_len);
-               }
-       }
-
-       free(buf);
-
-       return(TRUE);
-}
-
-// Creates the first counter block. First byte is flags, then the nonce, then the incremented part.
-void ccm_prepare_first_ctr_blk(BYTE counter[], const BYTE nonce[], int nonce_len, int payload_len_store_size)
-{
-       memset(counter, 0, AES_BLOCK_SIZE);
-       counter[0] = (payload_len_store_size - 1) & 0x07;
-       memcpy(&counter[1], nonce, nonce_len);
-}
-
-void ccm_prepare_first_format_blk(BYTE buf[], int assoc_len, int payload_len, int payload_len_store_size, int mac_len, const BYTE nonce[], int nonce_len)
-{
-       // Set the flags for the first byte of the first block.
-       buf[0] = ((((mac_len - 2) / 2) & 0x07) << 3) | ((payload_len_store_size - 1) & 0x07);
-       if (assoc_len > 0)
-               buf[0] += 0x40;
-       // Format the rest of the first block, storing the nonce and the size of the payload.
-       memcpy(&buf[1], nonce, nonce_len);
-       memset(&buf[1 + nonce_len], 0, AES_BLOCK_SIZE - 1 - nonce_len);
-       buf[15] = payload_len & 0x000000FF;
-       buf[14] = (payload_len >> 8) & 0x000000FF;
-}
-
-void ccm_format_assoc_data(BYTE buf[], int *end_of_buf, const BYTE assoc[], int assoc_len)
-{
-       int pad;
-
-       buf[*end_of_buf + 1] = assoc_len & 0x00FF;
-       buf[*end_of_buf] = (assoc_len >> 8) & 0x00FF;
-       *end_of_buf += 2;
-       memcpy(&buf[*end_of_buf], assoc, assoc_len);
-       *end_of_buf += assoc_len;
-       pad = AES_BLOCK_SIZE - (*end_of_buf % AES_BLOCK_SIZE); /*BUG?*/
-       memset(&buf[*end_of_buf], 0, pad);
-       *end_of_buf += pad;
-}
-
-void ccm_format_payload_data(BYTE buf[], int *end_of_buf, const BYTE payload[], int payload_len)
-{
-       int pad;
-
-       memcpy(&buf[*end_of_buf], payload, payload_len);
-       *end_of_buf += payload_len;
-       pad = *end_of_buf % AES_BLOCK_SIZE;
-       if (pad != 0)
-               pad = AES_BLOCK_SIZE - pad;
-       memset(&buf[*end_of_buf], 0, pad);
-       *end_of_buf += pad;
-}
-
-/*******************
-* AES
-*******************/
-/////////////////
-// KEY EXPANSION
-/////////////////
-
-// Substitutes a word using the AES S-Box.
-WORD SubWord(WORD word)
-{
-       unsigned int result;
-
-       result = (int)aes_sbox[(word >> 4) & 0x0000000F][word & 0x0000000F];
-       result += (int)aes_sbox[(word >> 12) & 0x0000000F][(word >> 8) & 0x0000000F] << 8;
-       result += (int)aes_sbox[(word >> 20) & 0x0000000F][(word >> 16) & 0x0000000F] << 16;
-       result += (int)aes_sbox[(word >> 28) & 0x0000000F][(word >> 24) & 0x0000000F] << 24;
-       return(result);
-}
-
-// Performs the action of generating the keys that will be used in every round of
-// encryption. "key" is the user-supplied input key, "w" is the output key schedule,
-// "keysize" is the length in bits of "key", must be 128, 192, or 256.
-void aes_key_setup(const BYTE key[], WORD w[], int keysize)
-{
-       int Nb=4,Nr,Nk,idx;
-       WORD temp,Rcon[]={0x01000000,0x02000000,0x04000000,0x08000000,0x10000000,0x20000000,
-                         0x40000000,0x80000000,0x1b000000,0x36000000,0x6c000000,0xd8000000,
-                         0xab000000,0x4d000000,0x9a000000};
-
-       switch (keysize) {
-               case 128: Nr = 10; Nk = 4; break;
-               case 192: Nr = 12; Nk = 6; break;
-               case 256: Nr = 14; Nk = 8; break;
-               default: return;
-       }
-
-       for (idx=0; idx < Nk; ++idx) {
-               w[idx] = ((key[4 * idx]) << 24) | ((key[4 * idx + 1]) << 16) |
-                                  ((key[4 * idx + 2]) << 8) | ((key[4 * idx + 3]));
-       }
-
-       for (idx = Nk; idx < Nb * (Nr+1); ++idx) {
-               temp = w[idx - 1];
-               if ((idx % Nk) == 0)
-                       temp = SubWord(KE_ROTWORD(temp)) ^ Rcon[(idx-1)/Nk];
-               else if (Nk > 6 && (idx % Nk) == 4)
-                       temp = SubWord(temp);
-               w[idx] = w[idx-Nk] ^ temp;
-       }
-}
-
-/////////////////
-// ADD ROUND KEY
-/////////////////
-
-// Performs the AddRoundKey step. Each round has its own pre-generated 16-byte key in the
-// form of 4 integers (the "w" array). Each integer is XOR'd by one column of the state.
-// Also performs the job of InvAddRoundKey(); since the function is a simple XOR process,
-// it is its own inverse.
-void AddRoundKey(BYTE state[][4], const WORD w[])
-{
-       BYTE subkey[4];
-
-       // memcpy(subkey,&w[idx],4); // Not accurate for big endian machines
-       // Subkey 1
-       subkey[0] = w[0] >> 24;
-       subkey[1] = w[0] >> 16;
-       subkey[2] = w[0] >> 8;
-       subkey[3] = w[0];
-       state[0][0] ^= subkey[0];
-       state[1][0] ^= subkey[1];
-       state[2][0] ^= subkey[2];
-       state[3][0] ^= subkey[3];
-       // Subkey 2
-       subkey[0] = w[1] >> 24;
-       subkey[1] = w[1] >> 16;
-       subkey[2] = w[1] >> 8;
-       subkey[3] = w[1];
-       state[0][1] ^= subkey[0];
-       state[1][1] ^= subkey[1];
-       state[2][1] ^= subkey[2];
-       state[3][1] ^= subkey[3];
-       // Subkey 3
-       subkey[0] = w[2] >> 24;
-       subkey[1] = w[2] >> 16;
-       subkey[2] = w[2] >> 8;
-       subkey[3] = w[2];
-       state[0][2] ^= subkey[0];
-       state[1][2] ^= subkey[1];
-       state[2][2] ^= subkey[2];
-       state[3][2] ^= subkey[3];
-       // Subkey 4
-       subkey[0] = w[3] >> 24;
-       subkey[1] = w[3] >> 16;
-       subkey[2] = w[3] >> 8;
-       subkey[3] = w[3];
-       state[0][3] ^= subkey[0];
-       state[1][3] ^= subkey[1];
-       state[2][3] ^= subkey[2];
-       state[3][3] ^= subkey[3];
-}
-
-/////////////////
-// (Inv)SubBytes
-/////////////////
-
-// Performs the SubBytes step. All bytes in the state are substituted with a
-// pre-calculated value from a lookup table.
-void SubBytes(BYTE state[][4])
-{
-       state[0][0] = aes_sbox[state[0][0] >> 4][state[0][0] & 0x0F];
-       state[0][1] = aes_sbox[state[0][1] >> 4][state[0][1] & 0x0F];
-       state[0][2] = aes_sbox[state[0][2] >> 4][state[0][2] & 0x0F];
-       state[0][3] = aes_sbox[state[0][3] >> 4][state[0][3] & 0x0F];
-       state[1][0] = aes_sbox[state[1][0] >> 4][state[1][0] & 0x0F];
-       state[1][1] = aes_sbox[state[1][1] >> 4][state[1][1] & 0x0F];
-       state[1][2] = aes_sbox[state[1][2] >> 4][state[1][2] & 0x0F];
-       state[1][3] = aes_sbox[state[1][3] >> 4][state[1][3] & 0x0F];
-       state[2][0] = aes_sbox[state[2][0] >> 4][state[2][0] & 0x0F];
-       state[2][1] = aes_sbox[state[2][1] >> 4][state[2][1] & 0x0F];
-       state[2][2] = aes_sbox[state[2][2] >> 4][state[2][2] & 0x0F];
-       state[2][3] = aes_sbox[state[2][3] >> 4][state[2][3] & 0x0F];
-       state[3][0] = aes_sbox[state[3][0] >> 4][state[3][0] & 0x0F];
-       state[3][1] = aes_sbox[state[3][1] >> 4][state[3][1] & 0x0F];
-       state[3][2] = aes_sbox[state[3][2] >> 4][state[3][2] & 0x0F];
-       state[3][3] = aes_sbox[state[3][3] >> 4][state[3][3] & 0x0F];
-}
-
-void InvSubBytes(BYTE state[][4])
-{
-       state[0][0] = aes_invsbox[state[0][0] >> 4][state[0][0] & 0x0F];
-       state[0][1] = aes_invsbox[state[0][1] >> 4][state[0][1] & 0x0F];
-       state[0][2] = aes_invsbox[state[0][2] >> 4][state[0][2] & 0x0F];
-       state[0][3] = aes_invsbox[state[0][3] >> 4][state[0][3] & 0x0F];
-       state[1][0] = aes_invsbox[state[1][0] >> 4][state[1][0] & 0x0F];
-       state[1][1] = aes_invsbox[state[1][1] >> 4][state[1][1] & 0x0F];
-       state[1][2] = aes_invsbox[state[1][2] >> 4][state[1][2] & 0x0F];
-       state[1][3] = aes_invsbox[state[1][3] >> 4][state[1][3] & 0x0F];
-       state[2][0] = aes_invsbox[state[2][0] >> 4][state[2][0] & 0x0F];
-       state[2][1] = aes_invsbox[state[2][1] >> 4][state[2][1] & 0x0F];
-       state[2][2] = aes_invsbox[state[2][2] >> 4][state[2][2] & 0x0F];
-       state[2][3] = aes_invsbox[state[2][3] >> 4][state[2][3] & 0x0F];
-       state[3][0] = aes_invsbox[state[3][0] >> 4][state[3][0] & 0x0F];
-       state[3][1] = aes_invsbox[state[3][1] >> 4][state[3][1] & 0x0F];
-       state[3][2] = aes_invsbox[state[3][2] >> 4][state[3][2] & 0x0F];
-       state[3][3] = aes_invsbox[state[3][3] >> 4][state[3][3] & 0x0F];
-}
-
-/////////////////
-// (Inv)ShiftRows
-/////////////////
-
-// Performs the ShiftRows step. All rows are shifted cylindrically to the left.
-void ShiftRows(BYTE state[][4])
-{
-       int t;
-
-       // Shift left by 1
-       t = state[1][0];
-       state[1][0] = state[1][1];
-       state[1][1] = state[1][2];
-       state[1][2] = state[1][3];
-       state[1][3] = t;
-       // Shift left by 2
-       t = state[2][0];
-       state[2][0] = state[2][2];
-       state[2][2] = t;
-       t = state[2][1];
-       state[2][1] = state[2][3];
-       state[2][3] = t;
-       // Shift left by 3
-       t = state[3][0];
-       state[3][0] = state[3][3];
-       state[3][3] = state[3][2];
-       state[3][2] = state[3][1];
-       state[3][1] = t;
-}
-
-// All rows are shifted cylindrically to the right.
-void InvShiftRows(BYTE state[][4])
-{
-       int t;
-
-       // Shift right by 1
-       t = state[1][3];
-       state[1][3] = state[1][2];
-       state[1][2] = state[1][1];
-       state[1][1] = state[1][0];
-       state[1][0] = t;
-       // Shift right by 2
-       t = state[2][3];
-       state[2][3] = state[2][1];
-       state[2][1] = t;
-       t = state[2][2];
-       state[2][2] = state[2][0];
-       state[2][0] = t;
-       // Shift right by 3
-       t = state[3][3];
-       state[3][3] = state[3][0];
-       state[3][0] = state[3][1];
-       state[3][1] = state[3][2];
-       state[3][2] = t;
-}
-
-/////////////////
-// (Inv)MixColumns
-/////////////////
-
-// Performs the MixColums step. The state is multiplied by itself using matrix
-// multiplication in a Galios Field 2^8. All multiplication is pre-computed in a table.
-// Addition is equivilent to XOR. (Must always make a copy of the column as the original
-// values will be destoyed.)
-void MixColumns(BYTE state[][4])
-{
-       BYTE col[4];
-
-       // Column 1
-       col[0] = state[0][0];
-       col[1] = state[1][0];
-       col[2] = state[2][0];
-       col[3] = state[3][0];
-       state[0][0] = gf_mul[col[0]][0];
-       state[0][0] ^= gf_mul[col[1]][1];
-       state[0][0] ^= col[2];
-       state[0][0] ^= col[3];
-       state[1][0] = col[0];
-       state[1][0] ^= gf_mul[col[1]][0];
-       state[1][0] ^= gf_mul[col[2]][1];
-       state[1][0] ^= col[3];
-       state[2][0] = col[0];
-       state[2][0] ^= col[1];
-       state[2][0] ^= gf_mul[col[2]][0];
-       state[2][0] ^= gf_mul[col[3]][1];
-       state[3][0] = gf_mul[col[0]][1];
-       state[3][0] ^= col[1];
-       state[3][0] ^= col[2];
-       state[3][0] ^= gf_mul[col[3]][0];
-       // Column 2
-       col[0] = state[0][1];
-       col[1] = state[1][1];
-       col[2] = state[2][1];
-       col[3] = state[3][1];
-       state[0][1] = gf_mul[col[0]][0];
-       state[0][1] ^= gf_mul[col[1]][1];
-       state[0][1] ^= col[2];
-       state[0][1] ^= col[3];
-       state[1][1] = col[0];
-       state[1][1] ^= gf_mul[col[1]][0];
-       state[1][1] ^= gf_mul[col[2]][1];
-       state[1][1] ^= col[3];
-       state[2][1] = col[0];
-       state[2][1] ^= col[1];
-       state[2][1] ^= gf_mul[col[2]][0];
-       state[2][1] ^= gf_mul[col[3]][1];
-       state[3][1] = gf_mul[col[0]][1];
-       state[3][1] ^= col[1];
-       state[3][1] ^= col[2];
-       state[3][1] ^= gf_mul[col[3]][0];
-       // Column 3
-       col[0] = state[0][2];
-       col[1] = state[1][2];
-       col[2] = state[2][2];
-       col[3] = state[3][2];
-       state[0][2] = gf_mul[col[0]][0];
-       state[0][2] ^= gf_mul[col[1]][1];
-       state[0][2] ^= col[2];
-       state[0][2] ^= col[3];
-       state[1][2] = col[0];
-       state[1][2] ^= gf_mul[col[1]][0];
-       state[1][2] ^= gf_mul[col[2]][1];
-       state[1][2] ^= col[3];
-       state[2][2] = col[0];
-       state[2][2] ^= col[1];
-       state[2][2] ^= gf_mul[col[2]][0];
-       state[2][2] ^= gf_mul[col[3]][1];
-       state[3][2] = gf_mul[col[0]][1];
-       state[3][2] ^= col[1];
-       state[3][2] ^= col[2];
-       state[3][2] ^= gf_mul[col[3]][0];
-       // Column 4
-       col[0] = state[0][3];
-       col[1] = state[1][3];
-       col[2] = state[2][3];
-       col[3] = state[3][3];
-       state[0][3] = gf_mul[col[0]][0];
-       state[0][3] ^= gf_mul[col[1]][1];
-       state[0][3] ^= col[2];
-       state[0][3] ^= col[3];
-       state[1][3] = col[0];
-       state[1][3] ^= gf_mul[col[1]][0];
-       state[1][3] ^= gf_mul[col[2]][1];
-       state[1][3] ^= col[3];
-       state[2][3] = col[0];
-       state[2][3] ^= col[1];
-       state[2][3] ^= gf_mul[col[2]][0];
-       state[2][3] ^= gf_mul[col[3]][1];
-       state[3][3] = gf_mul[col[0]][1];
-       state[3][3] ^= col[1];
-       state[3][3] ^= col[2];
-       state[3][3] ^= gf_mul[col[3]][0];
-}
-
-void InvMixColumns(BYTE state[][4])
-{
-       BYTE col[4];
-
-       // Column 1
-       col[0] = state[0][0];
-       col[1] = state[1][0];
-       col[2] = state[2][0];
-       col[3] = state[3][0];
-       state[0][0] = gf_mul[col[0]][5];
-       state[0][0] ^= gf_mul[col[1]][3];
-       state[0][0] ^= gf_mul[col[2]][4];
-       state[0][0] ^= gf_mul[col[3]][2];
-       state[1][0] = gf_mul[col[0]][2];
-       state[1][0] ^= gf_mul[col[1]][5];
-       state[1][0] ^= gf_mul[col[2]][3];
-       state[1][0] ^= gf_mul[col[3]][4];
-       state[2][0] = gf_mul[col[0]][4];
-       state[2][0] ^= gf_mul[col[1]][2];
-       state[2][0] ^= gf_mul[col[2]][5];
-       state[2][0] ^= gf_mul[col[3]][3];
-       state[3][0] = gf_mul[col[0]][3];
-       state[3][0] ^= gf_mul[col[1]][4];
-       state[3][0] ^= gf_mul[col[2]][2];
-       state[3][0] ^= gf_mul[col[3]][5];
-       // Column 2
-       col[0] = state[0][1];
-       col[1] = state[1][1];
-       col[2] = state[2][1];
-       col[3] = state[3][1];
-       state[0][1] = gf_mul[col[0]][5];
-       state[0][1] ^= gf_mul[col[1]][3];
-       state[0][1] ^= gf_mul[col[2]][4];
-       state[0][1] ^= gf_mul[col[3]][2];
-       state[1][1] = gf_mul[col[0]][2];
-       state[1][1] ^= gf_mul[col[1]][5];
-       state[1][1] ^= gf_mul[col[2]][3];
-       state[1][1] ^= gf_mul[col[3]][4];
-       state[2][1] = gf_mul[col[0]][4];
-       state[2][1] ^= gf_mul[col[1]][2];
-       state[2][1] ^= gf_mul[col[2]][5];
-       state[2][1] ^= gf_mul[col[3]][3];
-       state[3][1] = gf_mul[col[0]][3];
-       state[3][1] ^= gf_mul[col[1]][4];
-       state[3][1] ^= gf_mul[col[2]][2];
-       state[3][1] ^= gf_mul[col[3]][5];
-       // Column 3
-       col[0] = state[0][2];
-       col[1] = state[1][2];
-       col[2] = state[2][2];
-       col[3] = state[3][2];
-       state[0][2] = gf_mul[col[0]][5];
-       state[0][2] ^= gf_mul[col[1]][3];
-       state[0][2] ^= gf_mul[col[2]][4];
-       state[0][2] ^= gf_mul[col[3]][2];
-       state[1][2] = gf_mul[col[0]][2];
-       state[1][2] ^= gf_mul[col[1]][5];
-       state[1][2] ^= gf_mul[col[2]][3];
-       state[1][2] ^= gf_mul[col[3]][4];
-       state[2][2] = gf_mul[col[0]][4];
-       state[2][2] ^= gf_mul[col[1]][2];
-       state[2][2] ^= gf_mul[col[2]][5];
-       state[2][2] ^= gf_mul[col[3]][3];
-       state[3][2] = gf_mul[col[0]][3];
-       state[3][2] ^= gf_mul[col[1]][4];
-       state[3][2] ^= gf_mul[col[2]][2];
-       state[3][2] ^= gf_mul[col[3]][5];
-       // Column 4
-       col[0] = state[0][3];
-       col[1] = state[1][3];
-       col[2] = state[2][3];
-       col[3] = state[3][3];
-       state[0][3] = gf_mul[col[0]][5];
-       state[0][3] ^= gf_mul[col[1]][3];
-       state[0][3] ^= gf_mul[col[2]][4];
-       state[0][3] ^= gf_mul[col[3]][2];
-       state[1][3] = gf_mul[col[0]][2];
-       state[1][3] ^= gf_mul[col[1]][5];
-       state[1][3] ^= gf_mul[col[2]][3];
-       state[1][3] ^= gf_mul[col[3]][4];
-       state[2][3] = gf_mul[col[0]][4];
-       state[2][3] ^= gf_mul[col[1]][2];
-       state[2][3] ^= gf_mul[col[2]][5];
-       state[2][3] ^= gf_mul[col[3]][3];
-       state[3][3] = gf_mul[col[0]][3];
-       state[3][3] ^= gf_mul[col[1]][4];
-       state[3][3] ^= gf_mul[col[2]][2];
-       state[3][3] ^= gf_mul[col[3]][5];
-}
-
-/////////////////
-// (En/De)Crypt
-/////////////////
-
-void aes_encrypt(const BYTE in[], BYTE out[], const WORD key[], int keysize)
-{
-       BYTE state[4][4];
-
-       // Copy input array (should be 16 bytes long) to a matrix (sequential bytes are ordered
-       // by row, not col) called "state" for processing.
-       // *** Implementation note: The official AES documentation references the state by
-       // column, then row. Accessing an element in C requires row then column. Thus, all state
-       // references in AES must have the column and row indexes reversed for C implementation.
-       state[0][0] = in[0];
-       state[1][0] = in[1];
-       state[2][0] = in[2];
-       state[3][0] = in[3];
-       state[0][1] = in[4];
-       state[1][1] = in[5];
-       state[2][1] = in[6];
-       state[3][1] = in[7];
-       state[0][2] = in[8];
-       state[1][2] = in[9];
-       state[2][2] = in[10];
-       state[3][2] = in[11];
-       state[0][3] = in[12];
-       state[1][3] = in[13];
-       state[2][3] = in[14];
-       state[3][3] = in[15];
-
-       // Perform the necessary number of rounds. The round key is added first.
-       // The last round does not perform the MixColumns step.
-       AddRoundKey(state,&key[0]);
-       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[4]);
-       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[8]);
-       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[12]);
-       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[16]);
-       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[20]);
-       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[24]);
-       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[28]);
-       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[32]);
-       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[36]);
-       if (keysize != 128) {
-               SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[40]);
-               SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[44]);
-               if (keysize != 192) {
-                       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[48]);
-                       SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[52]);
-                       SubBytes(state); ShiftRows(state); AddRoundKey(state,&key[56]);
-               }
-               else {
-                       SubBytes(state); ShiftRows(state); AddRoundKey(state,&key[48]);
-               }
-       }
-       else {
-               SubBytes(state); ShiftRows(state); AddRoundKey(state,&key[40]);
-       }
-
-       // Copy the state to the output array.
-       out[0] = state[0][0];
-       out[1] = state[1][0];
-       out[2] = state[2][0];
-       out[3] = state[3][0];
-       out[4] = state[0][1];
-       out[5] = state[1][1];
-       out[6] = state[2][1];
-       out[7] = state[3][1];
-       out[8] = state[0][2];
-       out[9] = state[1][2];
-       out[10] = state[2][2];
-       out[11] = state[3][2];
-       out[12] = state[0][3];
-       out[13] = state[1][3];
-       out[14] = state[2][3];
-       out[15] = state[3][3];
-}
-
-void aes_decrypt(const BYTE in[], BYTE out[], const WORD key[], int keysize)
-{
-       BYTE state[4][4];
-
-       // Copy the input to the state.
-       state[0][0] = in[0];
-       state[1][0] = in[1];
-       state[2][0] = in[2];
-       state[3][0] = in[3];
-       state[0][1] = in[4];
-       state[1][1] = in[5];
-       state[2][1] = in[6];
-       state[3][1] = in[7];
-       state[0][2] = in[8];
-       state[1][2] = in[9];
-       state[2][2] = in[10];
-       state[3][2] = in[11];
-       state[0][3] = in[12];
-       state[1][3] = in[13];
-       state[2][3] = in[14];
-       state[3][3] = in[15];
-
-       // Perform the necessary number of rounds. The round key is added first.
-       // The last round does not perform the MixColumns step.
-       if (keysize > 128) {
-               if (keysize > 192) {
-                       AddRoundKey(state,&key[56]);
-                       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[52]);InvMixColumns(state);
-                       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[48]);InvMixColumns(state);
-               }
-               else {
-                       AddRoundKey(state,&key[48]);
-               }
-               InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[44]);InvMixColumns(state);
-               InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[40]);InvMixColumns(state);
-       }
-       else {
-               AddRoundKey(state,&key[40]);
-       }
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[36]);InvMixColumns(state);
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[32]);InvMixColumns(state);
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[28]);InvMixColumns(state);
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[24]);InvMixColumns(state);
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[20]);InvMixColumns(state);
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[16]);InvMixColumns(state);
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[12]);InvMixColumns(state);
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[8]);InvMixColumns(state);
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[4]);InvMixColumns(state);
-       InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[0]);
-
-       // Copy the state to the output array.
-       out[0] = state[0][0];
-       out[1] = state[1][0];
-       out[2] = state[2][0];
-       out[3] = state[3][0];
-       out[4] = state[0][1];
-       out[5] = state[1][1];
-       out[6] = state[2][1];
-       out[7] = state[3][1];
-       out[8] = state[0][2];
-       out[9] = state[1][2];
-       out[10] = state[2][2];
-       out[11] = state[3][2];
-       out[12] = state[0][3];
-       out[13] = state[1][3];
-       out[14] = state[2][3];
-       out[15] = state[3][3];
-}
-
-/*******************
-** AES DEBUGGING FUNCTIONS
-*******************/
-/*
-// This prints the "state" grid as a linear hex string.
-void print_state(BYTE state[][4])
-{
-       int idx,idx2;
-
-       for (idx=0; idx < 4; idx++)
-               for (idx2=0; idx2 < 4; idx2++)
-                       printf("%02x",state[idx2][idx]);
-       printf("\n");
-}
-
-// This prints the key (4 consecutive ints) used for a given round as a linear hex string.
-void print_rnd_key(WORD key[])
-{
-       int idx;
-
-       for (idx=0; idx < 4; idx++)
-               printf("%08x",key[idx]);
-       printf("\n");
-}
-*/
diff --git a/deps/crypto/aes.h b/deps/crypto/aes.h
deleted file mode 100644 (file)
index 25721c8..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*********************************************************************\r
-* Filename:   aes.h\r
-* Author:     Brad Conte (brad AT bradconte.com)\r
-* Copyright:\r
-* Disclaimer: This code is presented "as is" without any guarantees.\r
-* Details:    Defines the API for the corresponding AES implementation.\r
-*********************************************************************/\r
-\r
-#ifndef AES_H\r
-#define AES_H\r
-\r
-/*************************** HEADER FILES ***************************/\r
-#include <stddef.h>\r
-\r
-/****************************** MACROS ******************************/\r
-#define AES_BLOCK_SIZE 16               // AES operates on 16 bytes at a time\r
-\r
-/**************************** DATA TYPES ****************************/\r
-typedef unsigned char BYTE;            // 8-bit byte\r
-typedef unsigned int WORD;             // 32-bit word, change to "long" for 16-bit machines\r
-\r
-/*********************** FUNCTION DECLARATIONS **********************/\r
-///////////////////\r
-// AES\r
-///////////////////\r
-// Key setup must be done before any AES en/de-cryption functions can be used.\r
-void aes_key_setup(const BYTE key[],          // The key, must be 128, 192, or 256 bits\r
-                   WORD w[],                  // Output key schedule to be used later\r
-                   int keysize);              // Bit length of the key, 128, 192, or 256\r
-\r
-void aes_encrypt(const BYTE in[],             // 16 bytes of plaintext\r
-                 BYTE out[],                  // 16 bytes of ciphertext\r
-                 const WORD key[],            // From the key setup\r
-                 int keysize);                // Bit length of the key, 128, 192, or 256\r
-\r
-void aes_decrypt(const BYTE in[],             // 16 bytes of ciphertext\r
-                 BYTE out[],                  // 16 bytes of plaintext\r
-                 const WORD key[],            // From the key setup\r
-                 int keysize);                // Bit length of the key, 128, 192, or 256\r
-\r
-///////////////////\r
-// AES - CBC\r
-///////////////////\r
-int aes_encrypt_cbc(const BYTE in[],          // Plaintext\r
-                    size_t in_len,            // Must be a multiple of AES_BLOCK_SIZE\r
-                    BYTE out[],               // Ciphertext, same length as plaintext\r
-                    const WORD key[],         // From the key setup\r
-                    int keysize,              // Bit length of the key, 128, 192, or 256\r
-                    const BYTE iv[]);         // IV, must be AES_BLOCK_SIZE bytes long\r
-\r
-// Only output the CBC-MAC of the input.\r
-int aes_encrypt_cbc_mac(const BYTE in[],      // plaintext\r
-                        size_t in_len,        // Must be a multiple of AES_BLOCK_SIZE\r
-                        BYTE out[],           // Output MAC\r
-                        const WORD key[],     // From the key setup\r
-                        int keysize,          // Bit length of the key, 128, 192, or 256\r
-                        const BYTE iv[]);     // IV, must be AES_BLOCK_SIZE bytes long\r
-\r
-///////////////////\r
-// AES - CTR\r
-///////////////////\r
-void increment_iv(BYTE iv[],                  // Must be a multiple of AES_BLOCK_SIZE\r
-                  int counter_size);          // Bytes of the IV used for counting (low end)\r
-\r
-void aes_encrypt_ctr(const BYTE in[],         // Plaintext\r
-                     size_t in_len,           // Any byte length\r
-                     BYTE out[],              // Ciphertext, same length as plaintext\r
-                     const WORD key[],        // From the key setup\r
-                     int keysize,             // Bit length of the key, 128, 192, or 256\r
-                     const BYTE iv[]);        // IV, must be AES_BLOCK_SIZE bytes long\r
-\r
-void aes_decrypt_ctr(const BYTE in[],         // Ciphertext\r
-                     size_t in_len,           // Any byte length\r
-                     BYTE out[],              // Plaintext, same length as ciphertext\r
-                     const WORD key[],        // From the key setup\r
-                     int keysize,             // Bit length of the key, 128, 192, or 256\r
-                     const BYTE iv[]);        // IV, must be AES_BLOCK_SIZE bytes long\r
-\r
-///////////////////\r
-// AES - CCM\r
-///////////////////\r
-// Returns True if the input parameters do not violate any constraint.\r
-int aes_encrypt_ccm(const BYTE plaintext[],              // IN  - Plaintext.\r
-                    WORD plaintext_len,                  // IN  - Plaintext length.\r
-                    const BYTE associated_data[],        // IN  - Associated Data included in authentication, but not encryption.\r
-                    unsigned short associated_data_len,  // IN  - Associated Data length in bytes.\r
-                    const BYTE nonce[],                  // IN  - The Nonce to be used for encryption.\r
-                    unsigned short nonce_len,            // IN  - Nonce length in bytes.\r
-                    BYTE ciphertext[],                   // OUT - Ciphertext, a concatination of the plaintext and the MAC.\r
-                    WORD *ciphertext_len,                // OUT - The length of the ciphertext, always plaintext_len + mac_len.\r
-                    WORD mac_len,                        // IN  - The desired length of the MAC, must be 4, 6, 8, 10, 12, 14, or 16.\r
-                    const BYTE key[],                    // IN  - The AES key for encryption.\r
-                    int keysize);                        // IN  - The length of the key in bits. Valid values are 128, 192, 256.\r
-\r
-// Returns True if the input parameters do not violate any constraint.\r
-// Use mac_auth to ensure decryption/validation was preformed correctly.\r
-// If authentication does not succeed, the plaintext is zeroed out. To overwride\r
-// this, call with mac_auth = NULL. The proper proceedure is to decrypt with\r
-// authentication enabled (mac_auth != NULL) and make a second call to that\r
-// ignores authentication explicitly if the first call failes.\r
-int aes_decrypt_ccm(const BYTE ciphertext[],             // IN  - Ciphertext, the concatination of encrypted plaintext and MAC.\r
-                    WORD ciphertext_len,                 // IN  - Ciphertext length in bytes.\r
-                    const BYTE assoc[],                  // IN  - The Associated Data, required for authentication.\r
-                    unsigned short assoc_len,            // IN  - Associated Data length in bytes.\r
-                    const BYTE nonce[],                  // IN  - The Nonce to use for decryption, same one as for encryption.\r
-                    unsigned short nonce_len,            // IN  - Nonce length in bytes.\r
-                    BYTE plaintext[],                    // OUT - The plaintext that was decrypted. Will need to be large enough to hold ciphertext_len - mac_len.\r
-                    WORD *plaintext_len,                 // OUT - Length in bytes of the output plaintext, always ciphertext_len - mac_len .\r
-                    WORD mac_len,                        // IN  - The length of the MAC that was calculated.\r
-                    int *mac_auth,                       // OUT - TRUE if authentication succeeded, FALSE if it did not. NULL pointer will ignore the authentication.\r
-                    const BYTE key[],                    // IN  - The AES key for decryption.\r
-                    int keysize);                        // IN  - The length of the key in BITS. Valid values are 128, 192, 256.\r
-\r
-///////////////////\r
-// Test functions\r
-///////////////////\r
-int aes_test();\r
-int aes_ecb_test();\r
-int aes_cbc_test();\r
-int aes_ctr_test();\r
-int aes_ccm_test();\r
-\r
-#endif   // AES_H\r
diff --git a/deps/crypto/aes_test.c b/deps/crypto/aes_test.c
deleted file mode 100644 (file)
index b8da963..0000000
+++ /dev/null
@@ -1,285 +0,0 @@
-/*********************************************************************\r
-* Filename:   aes_test.c\r
-* Author:     Brad Conte (brad AT bradconte.com)\r
-* Copyright:\r
-* Disclaimer: This code is presented "as is" without any guarantees.\r
-* Details:    Performs known-answer tests on the corresponding AES\r
-              implementation. These tests do not encompass the full\r
-              range of available test vectors and are not sufficient\r
-              for FIPS-140 certification. However, if the tests pass\r
-              it is very, very likely that the code is correct and was\r
-              compiled properly. This code also serves as\r
-                 example usage of the functions.\r
-*********************************************************************/\r
-\r
-/*************************** HEADER FILES ***************************/\r
-#include <stdio.h>\r
-#include <memory.h>\r
-#include "aes.h"\r
-\r
-/*********************** FUNCTION DEFINITIONS ***********************/\r
-void print_hex(BYTE str[], int len)\r
-{\r
-       int idx;\r
-\r
-       for(idx = 0; idx < len; idx++)\r
-               printf("%02x", str[idx]);\r
-}\r
-\r
-int aes_ecb_test()\r
-{\r
-       WORD key_schedule[60], idx;\r
-       BYTE enc_buf[128];\r
-       BYTE plaintext[2][16] = {\r
-               {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a},\r
-               {0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51}\r
-       };\r
-       BYTE ciphertext[2][16] = {\r
-               {0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8},\r
-               {0x59,0x1c,0xcb,0x10,0xd4,0x10,0xed,0x26,0xdc,0x5b,0xa7,0x4a,0x31,0x36,0x28,0x70}\r
-       };\r
-       BYTE key[1][32] = {\r
-               {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4}\r
-       };\r
-       int pass = 1;\r
-\r
-       // Raw ECB mode.\r
-       //printf("* ECB mode:\n");\r
-       aes_key_setup(key[0], key_schedule, 256);\r
-       //printf(  "Key          : ");\r
-       //print_hex(key[0], 32);\r
-\r
-       for(idx = 0; idx < 2; idx++) {\r
-               aes_encrypt(plaintext[idx], enc_buf, key_schedule, 256);\r
-               //printf("\nPlaintext    : ");\r
-               //print_hex(plaintext[idx], 16);\r
-               //printf("\n-encrypted to: ");\r
-               //print_hex(enc_buf, 16);\r
-               pass = pass && !memcmp(enc_buf, ciphertext[idx], 16);\r
-\r
-               aes_decrypt(ciphertext[idx], enc_buf, key_schedule, 256);\r
-               //printf("\nCiphertext   : ");\r
-               //print_hex(ciphertext[idx], 16);\r
-               //printf("\n-decrypted to: ");\r
-               //print_hex(enc_buf, 16);\r
-               pass = pass && !memcmp(enc_buf, plaintext[idx], 16);\r
-\r
-               //printf("\n\n");\r
-       }\r
-\r
-       return(pass);\r
-}\r
-\r
-int aes_cbc_test()\r
-{\r
-       WORD key_schedule[60];\r
-       BYTE enc_buf[128];\r
-       BYTE plaintext[1][32] = {\r
-               {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51}\r
-       };\r
-       BYTE ciphertext[1][32] = {\r
-               {0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6,0x9c,0xfc,0x4e,0x96,0x7e,0xdb,0x80,0x8d,0x67,0x9f,0x77,0x7b,0xc6,0x70,0x2c,0x7d}\r
-       };\r
-       BYTE iv[1][16] = {\r
-               {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}\r
-       };\r
-       BYTE key[1][32] = {\r
-               {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4}\r
-       };\r
-       int pass = 1;\r
-\r
-       //printf("* CBC mode:\n");\r
-       aes_key_setup(key[0], key_schedule, 256);\r
-\r
-       //printf(  "Key          : ");\r
-       //print_hex(key[0], 32);\r
-       //printf("\nIV           : ");\r
-       //print_hex(iv[0], 16);\r
-\r
-       aes_encrypt_cbc(plaintext[0], 32, enc_buf, key_schedule, 256, iv[0]);\r
-       //printf("\nPlaintext    : ");\r
-       //print_hex(plaintext[0], 32);\r
-       //printf("\n-encrypted to: ");\r
-       //print_hex(enc_buf, 32);\r
-       //printf("\nCiphertext   : ");\r
-       //print_hex(ciphertext[0], 32);\r
-       pass = pass && !memcmp(enc_buf, ciphertext[0], 32);\r
-\r
-       aes_decrypt_cbc(ciphertext[0], 32, enc_buf, key_schedule, 256, iv[0]);\r
-       //printf("\nCiphertext   : ");\r
-       //print_hex(ciphertext[0], 32);\r
-       //printf("\n-decrypted to: ");\r
-       //print_hex(enc_buf, 32);\r
-       //printf("\nPlaintext   : ");\r
-       //print_hex(plaintext[0], 32);\r
-       pass = pass && !memcmp(enc_buf, plaintext[0], 32);\r
-\r
-       //printf("\n\n");\r
-       return(pass);\r
-}\r
-\r
-int aes_ctr_test()\r
-{\r
-       WORD key_schedule[60];\r
-       BYTE enc_buf[128];\r
-       BYTE plaintext[1][32] = {\r
-               {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51}\r
-       };\r
-       BYTE ciphertext[1][32] = {\r
-               {0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5}\r
-       };\r
-       BYTE iv[1][16] = {\r
-               {0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff},\r
-       };\r
-       BYTE key[1][32] = {\r
-               {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4}\r
-       };\r
-       int pass = 1;\r
-\r
-       //printf("* CTR mode:\n");\r
-       aes_key_setup(key[0], key_schedule, 256);\r
-\r
-       //printf(  "Key          : ");\r
-       //print_hex(key[0], 32);\r
-       //printf("\nIV           : ");\r
-       //print_hex(iv[0], 16);\r
-\r
-       aes_encrypt_ctr(plaintext[0], 32, enc_buf, key_schedule, 256, iv[0]);\r
-       //printf("\nPlaintext    : ");\r
-       //print_hex(plaintext[0], 32);\r
-       //printf("\n-encrypted to: ");\r
-       //print_hex(enc_buf, 32);\r
-       pass = pass && !memcmp(enc_buf, ciphertext[0], 32);\r
-\r
-       aes_decrypt_ctr(ciphertext[0], 32, enc_buf, key_schedule, 256, iv[0]);\r
-       //printf("\nCiphertext   : ");\r
-       //print_hex(ciphertext[0], 32);\r
-       //printf("\n-decrypted to: ");\r
-       //print_hex(enc_buf, 32);\r
-       pass = pass && !memcmp(enc_buf, plaintext[0], 32);\r
-\r
-       //printf("\n\n");\r
-       return(pass);\r
-}\r
-\r
-int aes_ccm_test()\r
-{\r
-       int mac_auth;\r
-       WORD enc_buf_len;\r
-       BYTE enc_buf[128];\r
-       BYTE plaintext[3][32] = {\r
-               {0x20,0x21,0x22,0x23},\r
-               {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f},\r
-               {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37}\r
-       };\r
-       BYTE assoc[3][32] = {\r
-               {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07},\r
-               {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f},\r
-               {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13}\r
-       };\r
-       BYTE ciphertext[3][32 + 16] = {\r
-               {0x71,0x62,0x01,0x5b,0x4d,0xac,0x25,0x5d},\r
-               {0xd2,0xa1,0xf0,0xe0,0x51,0xea,0x5f,0x62,0x08,0x1a,0x77,0x92,0x07,0x3d,0x59,0x3d,0x1f,0xc6,0x4f,0xbf,0xac,0xcd},\r
-               {0xe3,0xb2,0x01,0xa9,0xf5,0xb7,0x1a,0x7a,0x9b,0x1c,0xea,0xec,0xcd,0x97,0xe7,0x0b,0x61,0x76,0xaa,0xd9,0xa4,0x42,0x8a,0xa5,0x48,0x43,0x92,0xfb,0xc1,0xb0,0x99,0x51}\r
-       };\r
-       BYTE iv[3][16] = {\r
-               {0x10,0x11,0x12,0x13,0x14,0x15,0x16},\r
-               {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17},\r
-               {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b}\r
-       };\r
-       BYTE key[1][32] = {\r
-               {0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f}\r
-       };\r
-       int pass = 1;\r
-\r
-       //printf("* CCM mode:\n");\r
-       //printf("Key           : ");\r
-       //print_hex(key[0], 16);\r
-\r
-       //print_hex(plaintext[0], 4);\r
-       //print_hex(assoc[0], 8);\r
-       //print_hex(ciphertext[0], 8);\r
-       //print_hex(iv[0], 7);\r
-       //print_hex(key[0], 16);\r
-\r
-       aes_encrypt_ccm(plaintext[0], 4, assoc[0], 8, iv[0], 7, enc_buf, &enc_buf_len, 4, key[0], 128);\r
-       //printf("\nNONCE        : ");\r
-       //print_hex(iv[0], 7);\r
-       //printf("\nAssoc. Data  : ");\r
-       //print_hex(assoc[0], 8);\r
-       //printf("\nPayload       : ");\r
-       //print_hex(plaintext[0], 4);\r
-       //printf("\n-encrypted to: ");\r
-       //print_hex(enc_buf, enc_buf_len);\r
-       pass = pass && !memcmp(enc_buf, ciphertext[0], enc_buf_len);\r
-\r
-       aes_decrypt_ccm(ciphertext[0], 8, assoc[0], 8, iv[0], 7, enc_buf, &enc_buf_len, 4, &mac_auth, key[0], 128);\r
-       //printf("\n-Ciphertext  : ");\r
-       //print_hex(ciphertext[0], 8);\r
-       //printf("\n-decrypted to: ");\r
-       //print_hex(enc_buf, enc_buf_len);\r
-       //printf("\nAuthenticated: %d ", mac_auth);\r
-       pass = pass && !memcmp(enc_buf, plaintext[0], enc_buf_len) && mac_auth;\r
-\r
-\r
-       aes_encrypt_ccm(plaintext[1], 16, assoc[1], 16, iv[1], 8, enc_buf, &enc_buf_len, 6, key[0], 128);\r
-       //printf("\n\nNONCE        : ");\r
-       //print_hex(iv[1], 8);\r
-       //printf("\nAssoc. Data  : ");\r
-       //print_hex(assoc[1], 16);\r
-       //printf("\nPayload      : ");\r
-       //print_hex(plaintext[1], 16);\r
-       //printf("\n-encrypted to: ");\r
-       //print_hex(enc_buf, enc_buf_len);\r
-       pass = pass && !memcmp(enc_buf, ciphertext[1], enc_buf_len);\r
-\r
-       aes_decrypt_ccm(ciphertext[1], 22, assoc[1], 16, iv[1], 8, enc_buf, &enc_buf_len, 6, &mac_auth, key[0], 128);\r
-       //printf("\n-Ciphertext  : ");\r
-       //print_hex(ciphertext[1], 22);\r
-       //printf("\n-decrypted to: ");\r
-       //print_hex(enc_buf, enc_buf_len);\r
-       //printf("\nAuthenticated: %d ", mac_auth);\r
-       pass = pass && !memcmp(enc_buf, plaintext[1], enc_buf_len) && mac_auth;\r
-\r
-\r
-       aes_encrypt_ccm(plaintext[2], 24, assoc[2], 20, iv[2], 12, enc_buf, &enc_buf_len, 8, key[0], 128);\r
-       //printf("\n\nNONCE        : ");\r
-       //print_hex(iv[2], 12);\r
-       //printf("\nAssoc. Data  : ");\r
-       //print_hex(assoc[2], 20);\r
-       //printf("\nPayload      : ");\r
-       //print_hex(plaintext[2], 24);\r
-       //printf("\n-encrypted to: ");\r
-       //print_hex(enc_buf, enc_buf_len);\r
-       pass = pass && !memcmp(enc_buf, ciphertext[2], enc_buf_len);\r
-\r
-       aes_decrypt_ccm(ciphertext[2], 32, assoc[2], 20, iv[2], 12, enc_buf, &enc_buf_len, 8, &mac_auth, key[0], 128);\r
-       //printf("\n-Ciphertext  : ");\r
-       //print_hex(ciphertext[2], 32);\r
-       //printf("\n-decrypted to: ");\r
-       //print_hex(enc_buf, enc_buf_len);\r
-       //printf("\nAuthenticated: %d ", mac_auth);\r
-       pass = pass && !memcmp(enc_buf, plaintext[2], enc_buf_len) && mac_auth;\r
-\r
-       //printf("\n\n");\r
-       return(pass);\r
-}\r
-\r
-int aes_test()\r
-{\r
-       int pass = 1;\r
-\r
-       pass = pass && aes_ecb_test();\r
-       pass = pass && aes_cbc_test();\r
-       pass = pass && aes_ctr_test();\r
-       pass = pass && aes_ccm_test();\r
-\r
-       return(pass);\r
-}\r
-\r
-int main(int argc, char *argv[])\r
-{\r
-       printf("AES Tests: %s\n", aes_test() ? "SUCCEEDED" : "FAILED");\r
-\r
-       return(0);\r
-}\r
diff --git a/deps/crypto/arcfour.c b/deps/crypto/arcfour.c
deleted file mode 100644 (file)
index 37a88e1..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*********************************************************************
-* Filename:   arcfour.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Implementation of the ARCFOUR encryption algorithm.
-              Algorithm specification can be found here:
-               * http://en.wikipedia.org/wiki/RC4
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdlib.h>
-#include "arcfour.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-void arcfour_key_setup(BYTE state[], const BYTE key[], int len)
-{
-       int i, j;
-       BYTE t;
-
-       for (i = 0; i < 256; ++i)
-               state[i] = i;
-       for (i = 0, j = 0; i < 256; ++i) {
-               j = (j + state[i] + key[i % len]) % 256;
-               t = state[i];
-               state[i] = state[j];
-               state[j] = t;
-       }
-}
-
-// This does not hold state between calls. It always generates the
-// stream starting from the first  output byte.
-void arcfour_generate_stream(BYTE state[], BYTE out[], size_t len)
-{
-       int i, j;
-       size_t idx;
-       BYTE t;
-
-       for (idx = 0, i = 0, j = 0; idx < len; ++idx)  {
-               i = (i + 1) % 256;
-               j = (j + state[i]) % 256;
-               t = state[i];
-               state[i] = state[j];
-               state[j] = t;
-               out[idx] = state[(state[i] + state[j]) % 256];
-       }
-}
diff --git a/deps/crypto/arcfour.h b/deps/crypto/arcfour.h
deleted file mode 100644 (file)
index f9f1e87..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*********************************************************************
-* Filename:   arcfour.h
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Defines the API for the corresponding ARCFOUR implementation.
-*********************************************************************/
-
-#ifndef ARCFOUR_H
-#define ARCFOUR_H
-
-/*************************** HEADER FILES ***************************/
-#include <stddef.h>
-
-/**************************** DATA TYPES ****************************/
-typedef unsigned char BYTE;             // 8-bit byte
-
-/*********************** FUNCTION DECLARATIONS **********************/
-// Input: state - the state used to generate the keystream
-//        key - Key to use to initialize the state
-//        len - length of key in bytes (valid lenth is 1 to 256)
-void arcfour_key_setup(BYTE state[], const BYTE key[], int len);
-
-// Pseudo-Random Generator Algorithm
-// Input: state - the state used to generate the keystream
-//        out - Must be allocated to be of at least "len" length
-//        len - number of bytes to generate
-void arcfour_generate_stream(BYTE state[], BYTE out[], size_t len);
-
-#endif   // ARCFOUR_H
diff --git a/deps/crypto/arcfour_test.c b/deps/crypto/arcfour_test.c
deleted file mode 100644 (file)
index 985f8a7..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*********************************************************************
-* Filename:   arcfour_test.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Performs known-answer tests on the corresponding ARCFOUR
-                 implementation. These tests do not encompass the full
-                 range of available test vectors, however, if the tests
-                 pass it is very, very likely that the code is correct
-                 and was compiled properly. This code also serves as
-                 example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include "arcfour.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int rc4_test()
-{
-       BYTE state[256];
-       BYTE key[3][10] = {{"Key"}, {"Wiki"}, {"Secret"}};
-       BYTE stream[3][10] = {{0xEB,0x9F,0x77,0x81,0xB7,0x34,0xCA,0x72,0xA7,0x19},
-                             {0x60,0x44,0xdb,0x6d,0x41,0xb7},
-                             {0x04,0xd4,0x6b,0x05,0x3c,0xa8,0x7b,0x59}};
-       int stream_len[3] = {10,6,8};
-       BYTE buf[1024];
-       int idx;
-       int pass = 1;
-
-       // Only test the output stream. Note that the state can be reused.
-       for (idx = 0; idx < 3; idx++) {
-               arcfour_key_setup(state, key[idx], strlen(key[idx]));
-               arcfour_generate_stream(state, buf, stream_len[idx]);
-               pass = pass && !memcmp(stream[idx], buf, stream_len[idx]);
-       }
-
-       return(pass);
-}
-
-int main()
-{
-       printf("ARCFOUR tests: %s\n", rc4_test() ? "SUCCEEDED" : "FAILED");
-
-       return(0);
-}
diff --git a/deps/crypto/base64.c b/deps/crypto/base64.c
deleted file mode 100644 (file)
index 5e89808..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*********************************************************************
-* Filename:   base64.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Implementation of the Base64 encoding algorithm.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdlib.h>
-#include "base64.h"
-
-/****************************** MACROS ******************************/
-#define NEWLINE_INVL 76
-
-/**************************** VARIABLES *****************************/
-// Note: To change the charset to a URL encoding, replace the '+' and '/' with '*' and '-'
-static const BYTE charset[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"};
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-BYTE revchar(char ch)
-{
-       if (ch >= 'A' && ch <= 'Z')
-               ch -= 'A';
-       else if (ch >= 'a' && ch <='z')
-               ch = ch - 'a' + 26;
-       else if (ch >= '0' && ch <='9')
-               ch = ch - '0' + 52;
-       else if (ch == '+')
-               ch = 62;
-       else if (ch == '/')
-               ch = 63;
-
-       return(ch);
-}
-
-size_t base64_encode(const BYTE in[], BYTE out[], size_t len, int newline_flag)
-{
-       size_t idx, idx2, blks, blk_ceiling, left_over, newline_count = 0;
-
-       blks = (len / 3);
-       left_over = len % 3;
-
-       if (out == NULL) {
-               idx2 = blks * 4 ;
-               if (left_over)
-                       idx2 += 4;
-               if (newline_flag)
-                       idx2 += len / 57;   // (NEWLINE_INVL / 4) * 3 = 57. One newline per 57 input bytes.
-       }
-       else {
-               // Since 3 input bytes = 4 output bytes, determine out how many even sets of
-               // 3 bytes the input has.
-               blk_ceiling = blks * 3;
-               for (idx = 0, idx2 = 0; idx < blk_ceiling; idx += 3, idx2 += 4) {
-                       out[idx2]     = charset[in[idx] >> 2];
-                       out[idx2 + 1] = charset[((in[idx] & 0x03) << 4) | (in[idx + 1] >> 4)];
-                       out[idx2 + 2] = charset[((in[idx + 1] & 0x0f) << 2) | (in[idx + 2] >> 6)];
-                       out[idx2 + 3] = charset[in[idx + 2] & 0x3F];
-                       // The offical standard requires a newline every 76 characters.
-                       // (Eg, first newline is character 77 of the output.)
-                       if (((idx2 - newline_count + 4) % NEWLINE_INVL == 0) && newline_flag) {
-                               out[idx2 + 4] = '\n';
-                               idx2++;
-                               newline_count++;
-                       }
-               }
-
-               if (left_over == 1) {
-                       out[idx2]     = charset[in[idx] >> 2];
-                       out[idx2 + 1] = charset[(in[idx] & 0x03) << 4];
-                       out[idx2 + 2] = '=';
-                       out[idx2 + 3] = '=';
-                       idx2 += 4;
-               }
-               else if (left_over == 2) {
-                       out[idx2]     = charset[in[idx] >> 2];
-                       out[idx2 + 1] = charset[((in[idx] & 0x03) << 4) | (in[idx + 1] >> 4)];
-                       out[idx2 + 2] = charset[(in[idx + 1] & 0x0F) << 2];
-                       out[idx2 + 3] = '=';
-                       idx2 += 4;
-               }
-       }
-
-       return(idx2);
-}
-
-size_t base64_decode(const BYTE in[], BYTE out[], size_t len)
-{
-       BYTE ch;
-       size_t idx, idx2, blks, blk_ceiling, left_over;
-
-       if (in[len - 1] == '=')
-               len--;
-       if (in[len - 1] == '=')
-               len--;
-
-       blks = len / 4;
-       left_over = len % 4;
-
-       if (out == NULL) {
-               if (len >= 77 && in[NEWLINE_INVL] == '\n')   // Verify that newlines where used.
-                       len -= len / (NEWLINE_INVL + 1);
-               blks = len / 4;
-               left_over = len % 4;
-
-               idx = blks * 3;
-               if (left_over == 2)
-                       idx ++;
-               else if (left_over == 3)
-                       idx += 2;
-       }
-       else {
-               blk_ceiling = blks * 4;
-               for (idx = 0, idx2 = 0; idx2 < blk_ceiling; idx += 3, idx2 += 4) {
-                       if (in[idx2] == '\n')
-                               idx2++;
-                       out[idx]     = (revchar(in[idx2]) << 2) | ((revchar(in[idx2 + 1]) & 0x30) >> 4);
-                       out[idx + 1] = (revchar(in[idx2 + 1]) << 4) | (revchar(in[idx2 + 2]) >> 2);
-                       out[idx + 2] = (revchar(in[idx2 + 2]) << 6) | revchar(in[idx2 + 3]);
-               }
-
-               if (left_over == 2) {
-                       out[idx]     = (revchar(in[idx2]) << 2) | ((revchar(in[idx2 + 1]) & 0x30) >> 4);
-                       idx++;
-               }
-               else if (left_over == 3) {
-                       out[idx]     = (revchar(in[idx2]) << 2) | ((revchar(in[idx2 + 1]) & 0x30) >> 4);
-                       out[idx + 1] = (revchar(in[idx2 + 1]) << 4) | (revchar(in[idx2 + 2]) >> 2);
-                       idx += 2;
-               }
-       }
-
-       return(idx);
-}
diff --git a/deps/crypto/base64.h b/deps/crypto/base64.h
deleted file mode 100644 (file)
index e35c6c7..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*********************************************************************
-* Filename:   base64.h
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Defines the API for the corresponding Base64 implementation.
-*********************************************************************/
-
-#ifndef BASE64_H
-#define BASE64_H
-
-/*************************** HEADER FILES ***************************/
-#include <stddef.h>
-
-/**************************** DATA TYPES ****************************/
-typedef unsigned char BYTE;             // 8-bit byte
-
-/*********************** FUNCTION DECLARATIONS **********************/
-// Returns the size of the output. If called with out = NULL, will just return
-// the size of what the output would have been (without a terminating NULL).
-size_t base64_encode(const BYTE in[], BYTE out[], size_t len, int newline_flag);
-
-// Returns the size of the output. If called with out = NULL, will just return
-// the size of what the output would have been (without a terminating NULL).
-size_t base64_decode(const BYTE in[], BYTE out[], size_t len);
-
-#endif   // BASE64_H
diff --git a/deps/crypto/base64_test.c b/deps/crypto/base64_test.c
deleted file mode 100644 (file)
index c59cc98..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*********************************************************************
-* Filename:   blowfish_test.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Performs known-answer tests on the corresponding Base64
-                 implementation. These tests do not encompass the full
-                 range of available test vectors, however, if the tests
-                 pass it is very, very likely that the code is correct
-                 and was compiled properly. This code also serves as
-                 example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include "base64.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int base64_test()
-{
-       BYTE text[3][1024] = {{"fo"},
-                             {"foobar"},
-                             {"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."}};
-       BYTE code[3][1024] = {{"Zm8="},
-                             {"Zm9vYmFy"},
-                             {"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\nIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\ndGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\ndWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\nZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="}};
-       BYTE buf[1024];
-       size_t buf_len;
-       int pass = 1;
-       int idx;
-
-       for (idx = 0; idx < 3; idx++) {
-               buf_len = base64_encode(text[idx], buf, strlen(text[idx]), 1);
-               pass = pass && ((buf_len == strlen(code[idx])) &&
-                                (buf_len == base64_encode(text[idx], NULL, strlen(text[idx]), 1)));
-               pass = pass && !strcmp(code[idx], buf);
-
-               memset(buf, 0, sizeof(buf));
-               buf_len = base64_decode(code[idx], buf, strlen(code[idx]));
-               pass = pass && ((buf_len == strlen(text[idx])) &&
-                               (buf_len == base64_decode(code[idx], NULL, strlen(code[idx]))));
-               pass = pass && !strcmp(text[idx], buf);
-       }
-
-       return(pass);
-}
-
-int main()
-{
-       printf("Base64 tests: %s\n", base64_test() ? "PASSED" : "FAILED");
-
-       return 0;
-}
diff --git a/deps/crypto/blowfish.c b/deps/crypto/blowfish.c
deleted file mode 100644 (file)
index 8de91dd..0000000
+++ /dev/null
@@ -1,269 +0,0 @@
-/*********************************************************************
-* Filename:   blowfish.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Implementation of the Blowfish encryption algorithm.
-              Modes of operation (such as CBC) are not included.
-              Algorithm specification can be found here:
-               * http://www.schneier.com/blowfish.html
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdlib.h>
-#include <string.h>
-#include "blowfish.h"
-
-/****************************** MACROS ******************************/
-#define F(x,t) t = keystruct->s[0][(x) >> 24]; \
-               t += keystruct->s[1][((x) >> 16) & 0xff]; \
-               t ^= keystruct->s[2][((x) >> 8) & 0xff]; \
-               t += keystruct->s[3][(x) & 0xff];
-#define swap(r,l,t) t = l; l = r; r = t;
-#define ITERATION(l,r,t,pval) l ^= keystruct->p[pval]; F(l,t); r^= t; swap(r,l,t);
-
-/**************************** VARIABLES *****************************/
-static const WORD p_perm[18] = {
-   0x243F6A88,0x85A308D3,0x13198A2E,0x03707344,0xA4093822,0x299F31D0,0x082EFA98,
-   0xEC4E6C89,0x452821E6,0x38D01377,0xBE5466CF,0x34E90C6C,0xC0AC29B7,0xC97C50DD,
-   0x3F84D5B5,0xB5470917,0x9216D5D9,0x8979FB1B
-};
-
-static const WORD s_perm[4][256] = { {
-   0xD1310BA6,0x98DFB5AC,0x2FFD72DB,0xD01ADFB7,0xB8E1AFED,0x6A267E96,0xBA7C9045,0xF12C7F99,
-   0x24A19947,0xB3916CF7,0x0801F2E2,0x858EFC16,0x636920D8,0x71574E69,0xA458FEA3,0xF4933D7E,
-   0x0D95748F,0x728EB658,0x718BCD58,0x82154AEE,0x7B54A41D,0xC25A59B5,0x9C30D539,0x2AF26013,
-   0xC5D1B023,0x286085F0,0xCA417918,0xB8DB38EF,0x8E79DCB0,0x603A180E,0x6C9E0E8B,0xB01E8A3E,
-   0xD71577C1,0xBD314B27,0x78AF2FDA,0x55605C60,0xE65525F3,0xAA55AB94,0x57489862,0x63E81440,
-   0x55CA396A,0x2AAB10B6,0xB4CC5C34,0x1141E8CE,0xA15486AF,0x7C72E993,0xB3EE1411,0x636FBC2A,
-   0x2BA9C55D,0x741831F6,0xCE5C3E16,0x9B87931E,0xAFD6BA33,0x6C24CF5C,0x7A325381,0x28958677,
-   0x3B8F4898,0x6B4BB9AF,0xC4BFE81B,0x66282193,0x61D809CC,0xFB21A991,0x487CAC60,0x5DEC8032,
-   0xEF845D5D,0xE98575B1,0xDC262302,0xEB651B88,0x23893E81,0xD396ACC5,0x0F6D6FF3,0x83F44239,
-   0x2E0B4482,0xA4842004,0x69C8F04A,0x9E1F9B5E,0x21C66842,0xF6E96C9A,0x670C9C61,0xABD388F0,
-   0x6A51A0D2,0xD8542F68,0x960FA728,0xAB5133A3,0x6EEF0B6C,0x137A3BE4,0xBA3BF050,0x7EFB2A98,
-   0xA1F1651D,0x39AF0176,0x66CA593E,0x82430E88,0x8CEE8619,0x456F9FB4,0x7D84A5C3,0x3B8B5EBE,
-   0xE06F75D8,0x85C12073,0x401A449F,0x56C16AA6,0x4ED3AA62,0x363F7706,0x1BFEDF72,0x429B023D,
-   0x37D0D724,0xD00A1248,0xDB0FEAD3,0x49F1C09B,0x075372C9,0x80991B7B,0x25D479D8,0xF6E8DEF7,
-   0xE3FE501A,0xB6794C3B,0x976CE0BD,0x04C006BA,0xC1A94FB6,0x409F60C4,0x5E5C9EC2,0x196A2463,
-   0x68FB6FAF,0x3E6C53B5,0x1339B2EB,0x3B52EC6F,0x6DFC511F,0x9B30952C,0xCC814544,0xAF5EBD09,
-   0xBEE3D004,0xDE334AFD,0x660F2807,0x192E4BB3,0xC0CBA857,0x45C8740F,0xD20B5F39,0xB9D3FBDB,
-   0x5579C0BD,0x1A60320A,0xD6A100C6,0x402C7279,0x679F25FE,0xFB1FA3CC,0x8EA5E9F8,0xDB3222F8,
-   0x3C7516DF,0xFD616B15,0x2F501EC8,0xAD0552AB,0x323DB5FA,0xFD238760,0x53317B48,0x3E00DF82,
-   0x9E5C57BB,0xCA6F8CA0,0x1A87562E,0xDF1769DB,0xD542A8F6,0x287EFFC3,0xAC6732C6,0x8C4F5573,
-   0x695B27B0,0xBBCA58C8,0xE1FFA35D,0xB8F011A0,0x10FA3D98,0xFD2183B8,0x4AFCB56C,0x2DD1D35B,
-   0x9A53E479,0xB6F84565,0xD28E49BC,0x4BFB9790,0xE1DDF2DA,0xA4CB7E33,0x62FB1341,0xCEE4C6E8,
-   0xEF20CADA,0x36774C01,0xD07E9EFE,0x2BF11FB4,0x95DBDA4D,0xAE909198,0xEAAD8E71,0x6B93D5A0,
-   0xD08ED1D0,0xAFC725E0,0x8E3C5B2F,0x8E7594B7,0x8FF6E2FB,0xF2122B64,0x8888B812,0x900DF01C,
-   0x4FAD5EA0,0x688FC31C,0xD1CFF191,0xB3A8C1AD,0x2F2F2218,0xBE0E1777,0xEA752DFE,0x8B021FA1,
-   0xE5A0CC0F,0xB56F74E8,0x18ACF3D6,0xCE89E299,0xB4A84FE0,0xFD13E0B7,0x7CC43B81,0xD2ADA8D9,
-   0x165FA266,0x80957705,0x93CC7314,0x211A1477,0xE6AD2065,0x77B5FA86,0xC75442F5,0xFB9D35CF,
-   0xEBCDAF0C,0x7B3E89A0,0xD6411BD3,0xAE1E7E49,0x00250E2D,0x2071B35E,0x226800BB,0x57B8E0AF,
-   0x2464369B,0xF009B91E,0x5563911D,0x59DFA6AA,0x78C14389,0xD95A537F,0x207D5BA2,0x02E5B9C5,
-   0x83260376,0x6295CFA9,0x11C81968,0x4E734A41,0xB3472DCA,0x7B14A94A,0x1B510052,0x9A532915,
-   0xD60F573F,0xBC9BC6E4,0x2B60A476,0x81E67400,0x08BA6FB5,0x571BE91F,0xF296EC6B,0x2A0DD915,
-   0xB6636521,0xE7B9F9B6,0xFF34052E,0xC5855664,0x53B02D5D,0xA99F8FA1,0x08BA4799,0x6E85076A
-},{
-   0x4B7A70E9,0xB5B32944,0xDB75092E,0xC4192623,0xAD6EA6B0,0x49A7DF7D,0x9CEE60B8,0x8FEDB266,
-   0xECAA8C71,0x699A17FF,0x5664526C,0xC2B19EE1,0x193602A5,0x75094C29,0xA0591340,0xE4183A3E,
-   0x3F54989A,0x5B429D65,0x6B8FE4D6,0x99F73FD6,0xA1D29C07,0xEFE830F5,0x4D2D38E6,0xF0255DC1,
-   0x4CDD2086,0x8470EB26,0x6382E9C6,0x021ECC5E,0x09686B3F,0x3EBAEFC9,0x3C971814,0x6B6A70A1,
-   0x687F3584,0x52A0E286,0xB79C5305,0xAA500737,0x3E07841C,0x7FDEAE5C,0x8E7D44EC,0x5716F2B8,
-   0xB03ADA37,0xF0500C0D,0xF01C1F04,0x0200B3FF,0xAE0CF51A,0x3CB574B2,0x25837A58,0xDC0921BD,
-   0xD19113F9,0x7CA92FF6,0x94324773,0x22F54701,0x3AE5E581,0x37C2DADC,0xC8B57634,0x9AF3DDA7,
-   0xA9446146,0x0FD0030E,0xECC8C73E,0xA4751E41,0xE238CD99,0x3BEA0E2F,0x3280BBA1,0x183EB331,
-   0x4E548B38,0x4F6DB908,0x6F420D03,0xF60A04BF,0x2CB81290,0x24977C79,0x5679B072,0xBCAF89AF,
-   0xDE9A771F,0xD9930810,0xB38BAE12,0xDCCF3F2E,0x5512721F,0x2E6B7124,0x501ADDE6,0x9F84CD87,
-   0x7A584718,0x7408DA17,0xBC9F9ABC,0xE94B7D8C,0xEC7AEC3A,0xDB851DFA,0x63094366,0xC464C3D2,
-   0xEF1C1847,0x3215D908,0xDD433B37,0x24C2BA16,0x12A14D43,0x2A65C451,0x50940002,0x133AE4DD,
-   0x71DFF89E,0x10314E55,0x81AC77D6,0x5F11199B,0x043556F1,0xD7A3C76B,0x3C11183B,0x5924A509,
-   0xF28FE6ED,0x97F1FBFA,0x9EBABF2C,0x1E153C6E,0x86E34570,0xEAE96FB1,0x860E5E0A,0x5A3E2AB3,
-   0x771FE71C,0x4E3D06FA,0x2965DCB9,0x99E71D0F,0x803E89D6,0x5266C825,0x2E4CC978,0x9C10B36A,
-   0xC6150EBA,0x94E2EA78,0xA5FC3C53,0x1E0A2DF4,0xF2F74EA7,0x361D2B3D,0x1939260F,0x19C27960,
-   0x5223A708,0xF71312B6,0xEBADFE6E,0xEAC31F66,0xE3BC4595,0xA67BC883,0xB17F37D1,0x018CFF28,
-   0xC332DDEF,0xBE6C5AA5,0x65582185,0x68AB9802,0xEECEA50F,0xDB2F953B,0x2AEF7DAD,0x5B6E2F84,
-   0x1521B628,0x29076170,0xECDD4775,0x619F1510,0x13CCA830,0xEB61BD96,0x0334FE1E,0xAA0363CF,
-   0xB5735C90,0x4C70A239,0xD59E9E0B,0xCBAADE14,0xEECC86BC,0x60622CA7,0x9CAB5CAB,0xB2F3846E,
-   0x648B1EAF,0x19BDF0CA,0xA02369B9,0x655ABB50,0x40685A32,0x3C2AB4B3,0x319EE9D5,0xC021B8F7,
-   0x9B540B19,0x875FA099,0x95F7997E,0x623D7DA8,0xF837889A,0x97E32D77,0x11ED935F,0x16681281,
-   0x0E358829,0xC7E61FD6,0x96DEDFA1,0x7858BA99,0x57F584A5,0x1B227263,0x9B83C3FF,0x1AC24696,
-   0xCDB30AEB,0x532E3054,0x8FD948E4,0x6DBC3128,0x58EBF2EF,0x34C6FFEA,0xFE28ED61,0xEE7C3C73,
-   0x5D4A14D9,0xE864B7E3,0x42105D14,0x203E13E0,0x45EEE2B6,0xA3AAABEA,0xDB6C4F15,0xFACB4FD0,
-   0xC742F442,0xEF6ABBB5,0x654F3B1D,0x41CD2105,0xD81E799E,0x86854DC7,0xE44B476A,0x3D816250,
-   0xCF62A1F2,0x5B8D2646,0xFC8883A0,0xC1C7B6A3,0x7F1524C3,0x69CB7492,0x47848A0B,0x5692B285,
-   0x095BBF00,0xAD19489D,0x1462B174,0x23820E00,0x58428D2A,0x0C55F5EA,0x1DADF43E,0x233F7061,
-   0x3372F092,0x8D937E41,0xD65FECF1,0x6C223BDB,0x7CDE3759,0xCBEE7460,0x4085F2A7,0xCE77326E,
-   0xA6078084,0x19F8509E,0xE8EFD855,0x61D99735,0xA969A7AA,0xC50C06C2,0x5A04ABFC,0x800BCADC,
-   0x9E447A2E,0xC3453484,0xFDD56705,0x0E1E9EC9,0xDB73DBD3,0x105588CD,0x675FDA79,0xE3674340,
-   0xC5C43465,0x713E38D8,0x3D28F89E,0xF16DFF20,0x153E21E7,0x8FB03D4A,0xE6E39F2B,0xDB83ADF7
-},{
-   0xE93D5A68,0x948140F7,0xF64C261C,0x94692934,0x411520F7,0x7602D4F7,0xBCF46B2E,0xD4A20068,
-   0xD4082471,0x3320F46A,0x43B7D4B7,0x500061AF,0x1E39F62E,0x97244546,0x14214F74,0xBF8B8840,
-   0x4D95FC1D,0x96B591AF,0x70F4DDD3,0x66A02F45,0xBFBC09EC,0x03BD9785,0x7FAC6DD0,0x31CB8504,
-   0x96EB27B3,0x55FD3941,0xDA2547E6,0xABCA0A9A,0x28507825,0x530429F4,0x0A2C86DA,0xE9B66DFB,
-   0x68DC1462,0xD7486900,0x680EC0A4,0x27A18DEE,0x4F3FFEA2,0xE887AD8C,0xB58CE006,0x7AF4D6B6,
-   0xAACE1E7C,0xD3375FEC,0xCE78A399,0x406B2A42,0x20FE9E35,0xD9F385B9,0xEE39D7AB,0x3B124E8B,
-   0x1DC9FAF7,0x4B6D1856,0x26A36631,0xEAE397B2,0x3A6EFA74,0xDD5B4332,0x6841E7F7,0xCA7820FB,
-   0xFB0AF54E,0xD8FEB397,0x454056AC,0xBA489527,0x55533A3A,0x20838D87,0xFE6BA9B7,0xD096954B,
-   0x55A867BC,0xA1159A58,0xCCA92963,0x99E1DB33,0xA62A4A56,0x3F3125F9,0x5EF47E1C,0x9029317C,
-   0xFDF8E802,0x04272F70,0x80BB155C,0x05282CE3,0x95C11548,0xE4C66D22,0x48C1133F,0xC70F86DC,
-   0x07F9C9EE,0x41041F0F,0x404779A4,0x5D886E17,0x325F51EB,0xD59BC0D1,0xF2BCC18F,0x41113564,
-   0x257B7834,0x602A9C60,0xDFF8E8A3,0x1F636C1B,0x0E12B4C2,0x02E1329E,0xAF664FD1,0xCAD18115,
-   0x6B2395E0,0x333E92E1,0x3B240B62,0xEEBEB922,0x85B2A20E,0xE6BA0D99,0xDE720C8C,0x2DA2F728,
-   0xD0127845,0x95B794FD,0x647D0862,0xE7CCF5F0,0x5449A36F,0x877D48FA,0xC39DFD27,0xF33E8D1E,
-   0x0A476341,0x992EFF74,0x3A6F6EAB,0xF4F8FD37,0xA812DC60,0xA1EBDDF8,0x991BE14C,0xDB6E6B0D,
-   0xC67B5510,0x6D672C37,0x2765D43B,0xDCD0E804,0xF1290DC7,0xCC00FFA3,0xB5390F92,0x690FED0B,
-   0x667B9FFB,0xCEDB7D9C,0xA091CF0B,0xD9155EA3,0xBB132F88,0x515BAD24,0x7B9479BF,0x763BD6EB,
-   0x37392EB3,0xCC115979,0x8026E297,0xF42E312D,0x6842ADA7,0xC66A2B3B,0x12754CCC,0x782EF11C,
-   0x6A124237,0xB79251E7,0x06A1BBE6,0x4BFB6350,0x1A6B1018,0x11CAEDFA,0x3D25BDD8,0xE2E1C3C9,
-   0x44421659,0x0A121386,0xD90CEC6E,0xD5ABEA2A,0x64AF674E,0xDA86A85F,0xBEBFE988,0x64E4C3FE,
-   0x9DBC8057,0xF0F7C086,0x60787BF8,0x6003604D,0xD1FD8346,0xF6381FB0,0x7745AE04,0xD736FCCC,
-   0x83426B33,0xF01EAB71,0xB0804187,0x3C005E5F,0x77A057BE,0xBDE8AE24,0x55464299,0xBF582E61,
-   0x4E58F48F,0xF2DDFDA2,0xF474EF38,0x8789BDC2,0x5366F9C3,0xC8B38E74,0xB475F255,0x46FCD9B9,
-   0x7AEB2661,0x8B1DDF84,0x846A0E79,0x915F95E2,0x466E598E,0x20B45770,0x8CD55591,0xC902DE4C,
-   0xB90BACE1,0xBB8205D0,0x11A86248,0x7574A99E,0xB77F19B6,0xE0A9DC09,0x662D09A1,0xC4324633,
-   0xE85A1F02,0x09F0BE8C,0x4A99A025,0x1D6EFE10,0x1AB93D1D,0x0BA5A4DF,0xA186F20F,0x2868F169,
-   0xDCB7DA83,0x573906FE,0xA1E2CE9B,0x4FCD7F52,0x50115E01,0xA70683FA,0xA002B5C4,0x0DE6D027,
-   0x9AF88C27,0x773F8641,0xC3604C06,0x61A806B5,0xF0177A28,0xC0F586E0,0x006058AA,0x30DC7D62,
-   0x11E69ED7,0x2338EA63,0x53C2DD94,0xC2C21634,0xBBCBEE56,0x90BCB6DE,0xEBFC7DA1,0xCE591D76,
-   0x6F05E409,0x4B7C0188,0x39720A3D,0x7C927C24,0x86E3725F,0x724D9DB9,0x1AC15BB4,0xD39EB8FC,
-   0xED545578,0x08FCA5B5,0xD83D7CD3,0x4DAD0FC4,0x1E50EF5E,0xB161E6F8,0xA28514D9,0x6C51133C,
-   0x6FD5C7E7,0x56E14EC4,0x362ABFCE,0xDDC6C837,0xD79A3234,0x92638212,0x670EFA8E,0x406000E0
-},{
-   0x3A39CE37,0xD3FAF5CF,0xABC27737,0x5AC52D1B,0x5CB0679E,0x4FA33742,0xD3822740,0x99BC9BBE,
-   0xD5118E9D,0xBF0F7315,0xD62D1C7E,0xC700C47B,0xB78C1B6B,0x21A19045,0xB26EB1BE,0x6A366EB4,
-   0x5748AB2F,0xBC946E79,0xC6A376D2,0x6549C2C8,0x530FF8EE,0x468DDE7D,0xD5730A1D,0x4CD04DC6,
-   0x2939BBDB,0xA9BA4650,0xAC9526E8,0xBE5EE304,0xA1FAD5F0,0x6A2D519A,0x63EF8CE2,0x9A86EE22,
-   0xC089C2B8,0x43242EF6,0xA51E03AA,0x9CF2D0A4,0x83C061BA,0x9BE96A4D,0x8FE51550,0xBA645BD6,
-   0x2826A2F9,0xA73A3AE1,0x4BA99586,0xEF5562E9,0xC72FEFD3,0xF752F7DA,0x3F046F69,0x77FA0A59,
-   0x80E4A915,0x87B08601,0x9B09E6AD,0x3B3EE593,0xE990FD5A,0x9E34D797,0x2CF0B7D9,0x022B8B51,
-   0x96D5AC3A,0x017DA67D,0xD1CF3ED6,0x7C7D2D28,0x1F9F25CF,0xADF2B89B,0x5AD6B472,0x5A88F54C,
-   0xE029AC71,0xE019A5E6,0x47B0ACFD,0xED93FA9B,0xE8D3C48D,0x283B57CC,0xF8D56629,0x79132E28,
-   0x785F0191,0xED756055,0xF7960E44,0xE3D35E8C,0x15056DD4,0x88F46DBA,0x03A16125,0x0564F0BD,
-   0xC3EB9E15,0x3C9057A2,0x97271AEC,0xA93A072A,0x1B3F6D9B,0x1E6321F5,0xF59C66FB,0x26DCF319,
-   0x7533D928,0xB155FDF5,0x03563482,0x8ABA3CBB,0x28517711,0xC20AD9F8,0xABCC5167,0xCCAD925F,
-   0x4DE81751,0x3830DC8E,0x379D5862,0x9320F991,0xEA7A90C2,0xFB3E7BCE,0x5121CE64,0x774FBE32,
-   0xA8B6E37E,0xC3293D46,0x48DE5369,0x6413E680,0xA2AE0810,0xDD6DB224,0x69852DFD,0x09072166,
-   0xB39A460A,0x6445C0DD,0x586CDECF,0x1C20C8AE,0x5BBEF7DD,0x1B588D40,0xCCD2017F,0x6BB4E3BB,
-   0xDDA26A7E,0x3A59FF45,0x3E350A44,0xBCB4CDD5,0x72EACEA8,0xFA6484BB,0x8D6612AE,0xBF3C6F47,
-   0xD29BE463,0x542F5D9E,0xAEC2771B,0xF64E6370,0x740E0D8D,0xE75B1357,0xF8721671,0xAF537D5D,
-   0x4040CB08,0x4EB4E2CC,0x34D2466A,0x0115AF84,0xE1B00428,0x95983A1D,0x06B89FB4,0xCE6EA048,
-   0x6F3F3B82,0x3520AB82,0x011A1D4B,0x277227F8,0x611560B1,0xE7933FDC,0xBB3A792B,0x344525BD,
-   0xA08839E1,0x51CE794B,0x2F32C9B7,0xA01FBAC9,0xE01CC87E,0xBCC7D1F6,0xCF0111C3,0xA1E8AAC7,
-   0x1A908749,0xD44FBD9A,0xD0DADECB,0xD50ADA38,0x0339C32A,0xC6913667,0x8DF9317C,0xE0B12B4F,
-   0xF79E59B7,0x43F5BB3A,0xF2D519FF,0x27D9459C,0xBF97222C,0x15E6FC2A,0x0F91FC71,0x9B941525,
-   0xFAE59361,0xCEB69CEB,0xC2A86459,0x12BAA8D1,0xB6C1075E,0xE3056A0C,0x10D25065,0xCB03A442,
-   0xE0EC6E0E,0x1698DB3B,0x4C98A0BE,0x3278E964,0x9F1F9532,0xE0D392DF,0xD3A0342B,0x8971F21E,
-   0x1B0A7441,0x4BA3348C,0xC5BE7120,0xC37632D8,0xDF359F8D,0x9B992F2E,0xE60B6F47,0x0FE3F11D,
-   0xE54CDA54,0x1EDAD891,0xCE6279CF,0xCD3E7E6F,0x1618B166,0xFD2C1D05,0x848FD2C5,0xF6FB2299,
-   0xF523F357,0xA6327623,0x93A83531,0x56CCCD02,0xACF08162,0x5A75EBB5,0x6E163697,0x88D273CC,
-   0xDE966292,0x81B949D0,0x4C50901B,0x71C65614,0xE6C6C7BD,0x327A140A,0x45E1D006,0xC3F27B9A,
-   0xC9AA53FD,0x62A80F00,0xBB25BFE2,0x35BDD2F6,0x71126905,0xB2040222,0xB6CBCF7C,0xCD769C2B,
-   0x53113EC0,0x1640E3D3,0x38ABBD60,0x2547ADF0,0xBA38209C,0xF746CE76,0x77AFA1C5,0x20756060,
-   0x85CBFE4E,0x8AE88DD8,0x7AAAF9B0,0x4CF9AA7E,0x1948C25C,0x02FB8A8C,0x01C36AE4,0xD6EBE1F9,
-   0x90D4F869,0xA65CDEA0,0x3F09252D,0xC208E69F,0xB74E6132,0xCE77E25B,0x578FDFE3,0x3AC372E6
-} };
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-void blowfish_encrypt(const BYTE in[], BYTE out[], const BLOWFISH_KEY *keystruct)
-{
-   WORD l,r,t; //,i;
-
-   l = (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | (in[3]);
-   r = (in[4] << 24) | (in[5] << 16) | (in[6] << 8) | (in[7]);
-
-   ITERATION(l,r,t,0);
-   ITERATION(l,r,t,1);
-   ITERATION(l,r,t,2);
-   ITERATION(l,r,t,3);
-   ITERATION(l,r,t,4);
-   ITERATION(l,r,t,5);
-   ITERATION(l,r,t,6);
-   ITERATION(l,r,t,7);
-   ITERATION(l,r,t,8);
-   ITERATION(l,r,t,9);
-   ITERATION(l,r,t,10);
-   ITERATION(l,r,t,11);
-   ITERATION(l,r,t,12);
-   ITERATION(l,r,t,13);
-   ITERATION(l,r,t,14);
-   l ^= keystruct->p[15]; F(l,t); r^= t; //Last iteration has no swap()
-   r ^= keystruct->p[16];
-   l ^= keystruct->p[17];
-
-   out[0] = l >> 24;
-   out[1] = l >> 16;
-   out[2] = l >> 8;
-   out[3] = l;
-   out[4] = r >> 24;
-   out[5] = r >> 16;
-   out[6] = r >> 8;
-   out[7] = r;
-}
-
-void blowfish_decrypt(const BYTE in[], BYTE out[], const BLOWFISH_KEY *keystruct)
-{
-   WORD l,r,t; //,i;
-
-   l = (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | (in[3]);
-   r = (in[4] << 24) | (in[5] << 16) | (in[6] << 8) | (in[7]);
-
-   ITERATION(l,r,t,17);
-   ITERATION(l,r,t,16);
-   ITERATION(l,r,t,15);
-   ITERATION(l,r,t,14);
-   ITERATION(l,r,t,13);
-   ITERATION(l,r,t,12);
-   ITERATION(l,r,t,11);
-   ITERATION(l,r,t,10);
-   ITERATION(l,r,t,9);
-   ITERATION(l,r,t,8);
-   ITERATION(l,r,t,7);
-   ITERATION(l,r,t,6);
-   ITERATION(l,r,t,5);
-   ITERATION(l,r,t,4);
-   ITERATION(l,r,t,3);
-   l ^= keystruct->p[2]; F(l,t); r^= t; //Last iteration has no swap()
-   r ^= keystruct->p[1];
-   l ^= keystruct->p[0];
-
-   out[0] = l >> 24;
-   out[1] = l >> 16;
-   out[2] = l >> 8;
-   out[3] = l;
-   out[4] = r >> 24;
-   out[5] = r >> 16;
-   out[6] = r >> 8;
-   out[7] = r;
-}
-
-void blowfish_key_setup(const BYTE user_key[], BLOWFISH_KEY *keystruct, size_t len)
-{
-   BYTE block[8];
-   int idx,idx2;
-
-   // Copy over the constant init array vals (so the originals aren't destroyed).
-   memcpy(keystruct->p,p_perm,sizeof(WORD) * 18);
-   memcpy(keystruct->s,s_perm,sizeof(WORD) * 1024);
-
-   // Combine the key with the P box. Assume key is standard 448 bits (56 bytes) or less.
-   for (idx = 0, idx2 = 0; idx < 18; ++idx, idx2 += 4)
-      keystruct->p[idx] ^= (user_key[idx2 % len] << 24) | (user_key[(idx2+1) % len] << 16)
-                           | (user_key[(idx2+2) % len] << 8) | (user_key[(idx2+3) % len]);
-   // Re-calculate the P box.
-   memset(block, 0, 8);
-   for (idx = 0; idx < 18; idx += 2) {
-      blowfish_encrypt(block,block,keystruct);
-      keystruct->p[idx] = (block[0] << 24) | (block[1] << 16) | (block[2] << 8) | block[3];
-      keystruct->p[idx+1]=(block[4] << 24) | (block[5] << 16) | (block[6] << 8) | block[7];
-   }
-   // Recalculate the S-boxes.
-   for (idx = 0; idx < 4; ++idx) {
-      for (idx2 = 0; idx2 < 256; idx2 += 2) {
-         blowfish_encrypt(block,block,keystruct);
-         keystruct->s[idx][idx2] = (block[0] << 24) | (block[1] << 16) |
-                                   (block[2] << 8) | block[3];
-         keystruct->s[idx][idx2+1] = (block[4] << 24) | (block[5] << 16) |
-                                     (block[6] << 8) | block[7];
-      }
-   }
-}
diff --git a/deps/crypto/blowfish.h b/deps/crypto/blowfish.h
deleted file mode 100644 (file)
index d8e9d4a..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*********************************************************************
-* Filename:   blowfish.h
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Defines the API for the corresponding Blowfish implementation.
-*********************************************************************/
-
-#ifndef BLOWFISH_H
-#define BLOWFISH_H
-
-/*************************** HEADER FILES ***************************/
-#include <stddef.h>
-
-/****************************** MACROS ******************************/
-#define BLOWFISH_BLOCK_SIZE 8           // Blowfish operates on 8 bytes at a time
-
-/**************************** DATA TYPES ****************************/
-typedef unsigned char BYTE;             // 8-bit byte
-typedef unsigned int  WORD;             // 32-bit word, change to "long" for 16-bit machines
-
-typedef struct {
-   WORD p[18];
-   WORD s[4][256];
-} BLOWFISH_KEY;
-
-/*********************** FUNCTION DECLARATIONS **********************/
-void blowfish_key_setup(const BYTE user_key[], BLOWFISH_KEY *keystruct, size_t len);
-void blowfish_encrypt(const BYTE in[], BYTE out[], const BLOWFISH_KEY *keystruct);
-void blowfish_decrypt(const BYTE in[], BYTE out[], const BLOWFISH_KEY *keystruct);
-
-#endif   // BLOWFISH_H
diff --git a/deps/crypto/blowfish_test.c b/deps/crypto/blowfish_test.c
deleted file mode 100644 (file)
index 0f0aa38..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*********************************************************************
-* Filename:   blowfish_test.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Performs known-answer tests on the corresponding Blowfish
-                 implementation. These tests do not encompass the full
-                 range of available test vectors, however, if the tests
-                 pass it is very, very likely that the code is correct
-                 and was compiled properly. This code also serves as
-                 example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include "blowfish.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int blowfish_test()
-{
-       BYTE key1[8]  = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       BYTE key2[8]  = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
-       BYTE key3[24] = {0xF0,0xE1,0xD2,0xC3,0xB4,0xA5,0x96,0x87,
-                        0x78,0x69,0x5A,0x4B,0x3C,0x2D,0x1E,0x0F,
-                        0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77};
-       BYTE p1[BLOWFISH_BLOCK_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       BYTE p2[BLOWFISH_BLOCK_SIZE] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
-       BYTE p3[BLOWFISH_BLOCK_SIZE] = {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
-
-       BYTE c1[BLOWFISH_BLOCK_SIZE] = {0x4e,0xf9,0x97,0x45,0x61,0x98,0xdd,0x78};
-       BYTE c2[BLOWFISH_BLOCK_SIZE] = {0x51,0x86,0x6f,0xd5,0xb8,0x5e,0xcb,0x8a};
-       BYTE c3[BLOWFISH_BLOCK_SIZE] = {0x05,0x04,0x4b,0x62,0xfa,0x52,0xd0,0x80};
-
-       BYTE enc_buf[BLOWFISH_BLOCK_SIZE];
-       BLOWFISH_KEY key;
-       int pass = 1;
-
-       // Test vector 1.
-       blowfish_key_setup(key1, &key, BLOWFISH_BLOCK_SIZE);
-       blowfish_encrypt(p1, enc_buf, &key);
-       pass = pass && !memcmp(c1, enc_buf, BLOWFISH_BLOCK_SIZE);
-       blowfish_decrypt(c1, enc_buf, &key);
-       pass = pass && !memcmp(p1, enc_buf, BLOWFISH_BLOCK_SIZE);
-
-       // Test vector 2.
-       blowfish_key_setup(key2, &key, BLOWFISH_BLOCK_SIZE);
-       blowfish_encrypt(p2, enc_buf, &key);
-       pass = pass && !memcmp(c2, enc_buf, BLOWFISH_BLOCK_SIZE);
-       blowfish_decrypt(c2, enc_buf, &key);
-       pass = pass && !memcmp(p2, enc_buf, BLOWFISH_BLOCK_SIZE);
-
-       // Test vector 3.
-       blowfish_key_setup(key3, &key, 24);
-       blowfish_encrypt(p3, enc_buf, &key);
-       pass = pass && !memcmp(c3, enc_buf, BLOWFISH_BLOCK_SIZE);
-       blowfish_decrypt(c3, enc_buf, &key);
-       pass = pass && !memcmp(p3, enc_buf, BLOWFISH_BLOCK_SIZE);
-
-       return(pass);
-}
-
-int main()
-{
-       printf("Blowfish tests: %s\n", blowfish_test() ? "SUCCEEDED" : "FAILED");
-
-       return(0);
-}
diff --git a/deps/crypto/crypto_types.h b/deps/crypto/crypto_types.h
deleted file mode 100644 (file)
index 697c983..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*********************************************************************\r
-* Filename:   crypto_types.h\r
-* Author:     Brad Conte (brad AT bradconte.com)\r
-* Copyright:\r
-* Disclaimer: This code is presented "as is" without any guarantees.\r
-* Details:    Defines the API for the corresponding AES implementation.\r
-*********************************************************************/\r
-\r
-#ifndef CRYPTO_TYPES_H\r
-#define CRYPTO_TYPES_H\r
-\r
-typedef unsigned char BYTE;             // 8-bit byte\r
-typedef unsigned int  WORD;             // 32-bit word, change to "long" for 16-bit machines\r
-\r
-#endif\r
diff --git a/deps/crypto/des.c b/deps/crypto/des.c
deleted file mode 100644 (file)
index 1118eb3..0000000
+++ /dev/null
@@ -1,269 +0,0 @@
-/*********************************************************************
-* Filename:   des.c
-* Author:     Brad Conte (brad AT radconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Implementation of the DES encryption algorithm.
-              Modes of operation (such as CBC) are not included.
-              The formal NIST algorithm specification can be found here:
-               * http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdlib.h>
-#include <string.h>
-#include "des.h"
-
-/****************************** MACROS ******************************/
-// Obtain bit "b" from the left and shift it "c" places from the right
-#define BITNUM(a,b,c) (((a[(b)/8] >> (7 - (b%8))) & 0x01) << (c))
-#define BITNUMINTR(a,b,c) ((((a) >> (31 - (b))) & 0x00000001) << (c))
-#define BITNUMINTL(a,b,c) ((((a) << (b)) & 0x80000000) >> (c))
-
-// This macro converts a 6 bit block with the S-Box row defined as the first and last
-// bits to a 6 bit block with the row defined by the first two bits.
-#define SBOXBIT(a) (((a) & 0x20) | (((a) & 0x1f) >> 1) | (((a) & 0x01) << 4))
-
-/**************************** VARIABLES *****************************/
-static const BYTE sbox1[64] = {
-       14,  4,  13,  1,   2, 15,  11,  8,   3, 10,   6, 12,   5,  9,   0,  7,
-        0, 15,   7,  4,  14,  2,  13,  1,  10,  6,  12, 11,   9,  5,   3,  8,
-        4,  1,  14,  8,  13,  6,   2, 11,  15, 12,   9,  7,   3, 10,   5,  0,
-       15, 12,   8,  2,   4,  9,   1,  7,   5, 11,   3, 14,  10,  0,   6, 13
-};
-static const BYTE sbox2[64] = {
-       15,  1,   8, 14,   6, 11,   3,  4,   9,  7,   2, 13,  12,  0,   5, 10,
-        3, 13,   4,  7,  15,  2,   8, 14,  12,  0,   1, 10,   6,  9,  11,  5,
-        0, 14,   7, 11,  10,  4,  13,  1,   5,  8,  12,  6,   9,  3,   2, 15,
-       13,  8,  10,  1,   3, 15,   4,  2,  11,  6,   7, 12,   0,  5,  14,  9
-};
-static const BYTE sbox3[64] = {
-       10,  0,   9, 14,   6,  3,  15,  5,   1, 13,  12,  7,  11,  4,   2,  8,
-       13,  7,   0,  9,   3,  4,   6, 10,   2,  8,   5, 14,  12, 11,  15,  1,
-       13,  6,   4,  9,   8, 15,   3,  0,  11,  1,   2, 12,   5, 10,  14,  7,
-        1, 10,  13,  0,   6,  9,   8,  7,   4, 15,  14,  3,  11,  5,   2, 12
-};
-static const BYTE sbox4[64] = {
-        7, 13,  14,  3,   0,  6,   9, 10,   1,  2,   8,  5,  11, 12,   4, 15,
-       13,  8,  11,  5,   6, 15,   0,  3,   4,  7,   2, 12,   1, 10,  14,  9,
-       10,  6,   9,  0,  12, 11,   7, 13,  15,  1,   3, 14,   5,  2,   8,  4,
-        3, 15,   0,  6,  10,  1,  13,  8,   9,  4,   5, 11,  12,  7,   2, 14
-};
-static const BYTE sbox5[64] = {
-        2, 12,   4,  1,   7, 10,  11,  6,   8,  5,   3, 15,  13,  0,  14,  9,
-       14, 11,   2, 12,   4,  7,  13,  1,   5,  0,  15, 10,   3,  9,   8,  6,
-        4,  2,   1, 11,  10, 13,   7,  8,  15,  9,  12,  5,   6,  3,   0, 14,
-       11,  8,  12,  7,   1, 14,   2, 13,   6, 15,   0,  9,  10,  4,   5,  3
-};
-static const BYTE sbox6[64] = {
-       12,  1,  10, 15,   9,  2,   6,  8,   0, 13,   3,  4,  14,  7,   5, 11,
-       10, 15,   4,  2,   7, 12,   9,  5,   6,  1,  13, 14,   0, 11,   3,  8,
-        9, 14,  15,  5,   2,  8,  12,  3,   7,  0,   4, 10,   1, 13,  11,  6,
-        4,  3,   2, 12,   9,  5,  15, 10,  11, 14,   1,  7,   6,  0,   8, 13
-};
-static const BYTE sbox7[64] = {
-        4, 11,   2, 14,  15,  0,   8, 13,   3, 12,   9,  7,   5, 10,   6,  1,
-       13,  0,  11,  7,   4,  9,   1, 10,  14,  3,   5, 12,   2, 15,   8,  6,
-        1,  4,  11, 13,  12,  3,   7, 14,  10, 15,   6,  8,   0,  5,   9,  2,
-        6, 11,  13,  8,   1,  4,  10,  7,   9,  5,   0, 15,  14,  2,   3, 12
-};
-static const BYTE sbox8[64] = {
-       13,  2,   8,  4,   6, 15,  11,  1,  10,  9,   3, 14,   5,  0,  12,  7,
-        1, 15,  13,  8,  10,  3,   7,  4,  12,  5,   6, 11,   0, 14,   9,  2,
-        7, 11,   4,  1,   9, 12,  14,  2,   0,  6,  10, 13,  15,  3,   5,  8,
-        2,  1,  14,  7,   4, 10,   8, 13,  15, 12,   9,  0,   3,  5,   6, 11
-};
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-// Initial (Inv)Permutation step
-void IP(WORD state[], const BYTE in[])
-{
-       state[0] = BITNUM(in,57,31) | BITNUM(in,49,30) | BITNUM(in,41,29) | BITNUM(in,33,28) |
-                                 BITNUM(in,25,27) | BITNUM(in,17,26) | BITNUM(in,9,25) | BITNUM(in,1,24) |
-                                 BITNUM(in,59,23) | BITNUM(in,51,22) | BITNUM(in,43,21) | BITNUM(in,35,20) |
-                                 BITNUM(in,27,19) | BITNUM(in,19,18) | BITNUM(in,11,17) | BITNUM(in,3,16) |
-                                 BITNUM(in,61,15) | BITNUM(in,53,14) | BITNUM(in,45,13) | BITNUM(in,37,12) |
-                                 BITNUM(in,29,11) | BITNUM(in,21,10) | BITNUM(in,13,9) | BITNUM(in,5,8) |
-                                 BITNUM(in,63,7) | BITNUM(in,55,6) | BITNUM(in,47,5) | BITNUM(in,39,4) |
-                                 BITNUM(in,31,3) | BITNUM(in,23,2) | BITNUM(in,15,1) | BITNUM(in,7,0);
-
-       state[1] = BITNUM(in,56,31) | BITNUM(in,48,30) | BITNUM(in,40,29) | BITNUM(in,32,28) |
-                                 BITNUM(in,24,27) | BITNUM(in,16,26) | BITNUM(in,8,25) | BITNUM(in,0,24) |
-                                 BITNUM(in,58,23) | BITNUM(in,50,22) | BITNUM(in,42,21) | BITNUM(in,34,20) |
-                                 BITNUM(in,26,19) | BITNUM(in,18,18) | BITNUM(in,10,17) | BITNUM(in,2,16) |
-                                 BITNUM(in,60,15) | BITNUM(in,52,14) | BITNUM(in,44,13) | BITNUM(in,36,12) |
-                                 BITNUM(in,28,11) | BITNUM(in,20,10) | BITNUM(in,12,9) | BITNUM(in,4,8) |
-                                 BITNUM(in,62,7) | BITNUM(in,54,6) | BITNUM(in,46,5) | BITNUM(in,38,4) |
-                                 BITNUM(in,30,3) | BITNUM(in,22,2) | BITNUM(in,14,1) | BITNUM(in,6,0);
-}
-
-void InvIP(WORD state[], BYTE in[])
-{
-       in[0] = BITNUMINTR(state[1],7,7) | BITNUMINTR(state[0],7,6) | BITNUMINTR(state[1],15,5) |
-                         BITNUMINTR(state[0],15,4) | BITNUMINTR(state[1],23,3) | BITNUMINTR(state[0],23,2) |
-                         BITNUMINTR(state[1],31,1) | BITNUMINTR(state[0],31,0);
-
-       in[1] = BITNUMINTR(state[1],6,7) | BITNUMINTR(state[0],6,6) | BITNUMINTR(state[1],14,5) |
-                         BITNUMINTR(state[0],14,4) | BITNUMINTR(state[1],22,3) | BITNUMINTR(state[0],22,2) |
-                         BITNUMINTR(state[1],30,1) | BITNUMINTR(state[0],30,0);
-
-       in[2] = BITNUMINTR(state[1],5,7) | BITNUMINTR(state[0],5,6) | BITNUMINTR(state[1],13,5) |
-                         BITNUMINTR(state[0],13,4) | BITNUMINTR(state[1],21,3) | BITNUMINTR(state[0],21,2) |
-                         BITNUMINTR(state[1],29,1) | BITNUMINTR(state[0],29,0);
-
-       in[3] = BITNUMINTR(state[1],4,7) | BITNUMINTR(state[0],4,6) | BITNUMINTR(state[1],12,5) |
-                         BITNUMINTR(state[0],12,4) | BITNUMINTR(state[1],20,3) | BITNUMINTR(state[0],20,2) |
-                         BITNUMINTR(state[1],28,1) | BITNUMINTR(state[0],28,0);
-
-       in[4] = BITNUMINTR(state[1],3,7) | BITNUMINTR(state[0],3,6) | BITNUMINTR(state[1],11,5) |
-                         BITNUMINTR(state[0],11,4) | BITNUMINTR(state[1],19,3) | BITNUMINTR(state[0],19,2) |
-                         BITNUMINTR(state[1],27,1) | BITNUMINTR(state[0],27,0);
-
-       in[5] = BITNUMINTR(state[1],2,7) | BITNUMINTR(state[0],2,6) | BITNUMINTR(state[1],10,5) |
-                         BITNUMINTR(state[0],10,4) | BITNUMINTR(state[1],18,3) | BITNUMINTR(state[0],18,2) |
-                         BITNUMINTR(state[1],26,1) | BITNUMINTR(state[0],26,0);
-
-       in[6] = BITNUMINTR(state[1],1,7) | BITNUMINTR(state[0],1,6) | BITNUMINTR(state[1],9,5) |
-                         BITNUMINTR(state[0],9,4) | BITNUMINTR(state[1],17,3) | BITNUMINTR(state[0],17,2) |
-                         BITNUMINTR(state[1],25,1) | BITNUMINTR(state[0],25,0);
-
-       in[7] = BITNUMINTR(state[1],0,7) | BITNUMINTR(state[0],0,6) | BITNUMINTR(state[1],8,5) |
-                         BITNUMINTR(state[0],8,4) | BITNUMINTR(state[1],16,3) | BITNUMINTR(state[0],16,2) |
-                         BITNUMINTR(state[1],24,1) | BITNUMINTR(state[0],24,0);
-}
-
-WORD f(WORD state, const BYTE key[])
-{
-       BYTE lrgstate[6]; //,i;
-       WORD t1,t2;
-
-       // Expantion Permutation
-       t1 = BITNUMINTL(state,31,0) | ((state & 0xf0000000) >> 1) | BITNUMINTL(state,4,5) |
-                 BITNUMINTL(state,3,6) | ((state & 0x0f000000) >> 3) | BITNUMINTL(state,8,11) |
-                 BITNUMINTL(state,7,12) | ((state & 0x00f00000) >> 5) | BITNUMINTL(state,12,17) |
-                 BITNUMINTL(state,11,18) | ((state & 0x000f0000) >> 7) | BITNUMINTL(state,16,23);
-
-       t2 = BITNUMINTL(state,15,0) | ((state & 0x0000f000) << 15) | BITNUMINTL(state,20,5) |
-                 BITNUMINTL(state,19,6) | ((state & 0x00000f00) << 13) | BITNUMINTL(state,24,11) |
-                 BITNUMINTL(state,23,12) | ((state & 0x000000f0) << 11) | BITNUMINTL(state,28,17) |
-                 BITNUMINTL(state,27,18) | ((state & 0x0000000f) << 9) | BITNUMINTL(state,0,23);
-
-       lrgstate[0] = (t1 >> 24) & 0x000000ff;
-       lrgstate[1] = (t1 >> 16) & 0x000000ff;
-       lrgstate[2] = (t1 >> 8) & 0x000000ff;
-       lrgstate[3] = (t2 >> 24) & 0x000000ff;
-       lrgstate[4] = (t2 >> 16) & 0x000000ff;
-       lrgstate[5] = (t2 >> 8) & 0x000000ff;
-
-       // Key XOR
-       lrgstate[0] ^= key[0];
-       lrgstate[1] ^= key[1];
-       lrgstate[2] ^= key[2];
-       lrgstate[3] ^= key[3];
-       lrgstate[4] ^= key[4];
-       lrgstate[5] ^= key[5];
-
-       // S-Box Permutation
-       state = (sbox1[SBOXBIT(lrgstate[0] >> 2)] << 28) |
-                         (sbox2[SBOXBIT(((lrgstate[0] & 0x03) << 4) | (lrgstate[1] >> 4))] << 24) |
-                         (sbox3[SBOXBIT(((lrgstate[1] & 0x0f) << 2) | (lrgstate[2] >> 6))] << 20) |
-                         (sbox4[SBOXBIT(lrgstate[2] & 0x3f)] << 16) |
-                         (sbox5[SBOXBIT(lrgstate[3] >> 2)] << 12) |
-                         (sbox6[SBOXBIT(((lrgstate[3] & 0x03) << 4) | (lrgstate[4] >> 4))] << 8) |
-                         (sbox7[SBOXBIT(((lrgstate[4] & 0x0f) << 2) | (lrgstate[5] >> 6))] << 4) |
-                               sbox8[SBOXBIT(lrgstate[5] & 0x3f)];
-
-       // P-Box Permutation
-       state = BITNUMINTL(state,15,0) | BITNUMINTL(state,6,1) | BITNUMINTL(state,19,2) |
-                         BITNUMINTL(state,20,3) | BITNUMINTL(state,28,4) | BITNUMINTL(state,11,5) |
-                         BITNUMINTL(state,27,6) | BITNUMINTL(state,16,7) | BITNUMINTL(state,0,8) |
-                         BITNUMINTL(state,14,9) | BITNUMINTL(state,22,10) | BITNUMINTL(state,25,11) |
-                         BITNUMINTL(state,4,12) | BITNUMINTL(state,17,13) | BITNUMINTL(state,30,14) |
-                         BITNUMINTL(state,9,15) | BITNUMINTL(state,1,16) | BITNUMINTL(state,7,17) |
-                         BITNUMINTL(state,23,18) | BITNUMINTL(state,13,19) | BITNUMINTL(state,31,20) |
-                         BITNUMINTL(state,26,21) | BITNUMINTL(state,2,22) | BITNUMINTL(state,8,23) |
-                         BITNUMINTL(state,18,24) | BITNUMINTL(state,12,25) | BITNUMINTL(state,29,26) |
-                         BITNUMINTL(state,5,27) | BITNUMINTL(state,21,28) | BITNUMINTL(state,10,29) |
-                         BITNUMINTL(state,3,30) | BITNUMINTL(state,24,31);
-
-       // Return the final state value
-       return(state);
-}
-
-void des_key_setup(const BYTE key[], BYTE schedule[][6], DES_MODE mode)
-{
-       WORD i, j, to_gen, C, D;
-       const WORD key_rnd_shift[16] = {1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1};
-       const WORD key_perm_c[28] = {56,48,40,32,24,16,8,0,57,49,41,33,25,17,
-                                    9,1,58,50,42,34,26,18,10,2,59,51,43,35};
-       const WORD key_perm_d[28] = {62,54,46,38,30,22,14,6,61,53,45,37,29,21,
-                                    13,5,60,52,44,36,28,20,12,4,27,19,11,3};
-       const WORD key_compression[48] = {13,16,10,23,0,4,2,27,14,5,20,9,
-                                         22,18,11,3,25,7,15,6,26,19,12,1,
-                                         40,51,30,36,46,54,29,39,50,44,32,47,
-                                         43,48,38,55,33,52,45,41,49,35,28,31};
-
-       // Permutated Choice #1 (copy the key in, ignoring parity bits).
-       for (i = 0, j = 31, C = 0; i < 28; ++i, --j)
-               C |= BITNUM(key,key_perm_c[i],j);
-       for (i = 0, j = 31, D = 0; i < 28; ++i, --j)
-               D |= BITNUM(key,key_perm_d[i],j);
-
-       // Generate the 16 subkeys.
-       for (i = 0; i < 16; ++i) {
-               C = ((C << key_rnd_shift[i]) | (C >> (28-key_rnd_shift[i]))) & 0xfffffff0;
-               D = ((D << key_rnd_shift[i]) | (D >> (28-key_rnd_shift[i]))) & 0xfffffff0;
-
-               // Decryption subkeys are reverse order of encryption subkeys so
-               // generate them in reverse if the key schedule is for decryption useage.
-               if (mode == DES_DECRYPT)
-                       to_gen = 15 - i;
-               else /*(if mode == DES_ENCRYPT)*/
-                       to_gen = i;
-               // Initialize the array
-               for (j = 0; j < 6; ++j)
-                       schedule[to_gen][j] = 0;
-               for (j = 0; j < 24; ++j)
-                       schedule[to_gen][j/8] |= BITNUMINTR(C,key_compression[j],7 - (j%8));
-               for ( ; j < 48; ++j)
-                       schedule[to_gen][j/8] |= BITNUMINTR(D,key_compression[j] - 28,7 - (j%8));
-       }
-}
-
-void des_crypt(const BYTE in[], BYTE out[], const BYTE key[][6])
-{
-       WORD state[2],idx,t;
-
-       IP(state,in);
-
-       for (idx=0; idx < 15; ++idx) {
-               t = state[1];
-               state[1] = f(state[1],key[idx]) ^ state[0];
-               state[0] = t;
-       }
-       // Perform the final loop manually as it doesn't switch sides
-       state[0] = f(state[1],key[15]) ^ state[0];
-
-       InvIP(state,out);
-}
-
-void three_des_key_setup(const BYTE key[], BYTE schedule[][16][6], DES_MODE mode)
-{
-       if (mode == DES_ENCRYPT) {
-               des_key_setup(&key[0],schedule[0],mode);
-               des_key_setup(&key[8],schedule[1],!mode);
-               des_key_setup(&key[16],schedule[2],mode);
-       }
-       else /*if (mode == DES_DECRYPT*/ {
-               des_key_setup(&key[16],schedule[0],mode);
-               des_key_setup(&key[8],schedule[1],!mode);
-               des_key_setup(&key[0],schedule[2],mode);
-       }
-}
-
-void three_des_crypt(const BYTE in[], BYTE out[], const BYTE key[][16][6])
-{
-       des_crypt(in,out,key[0]);
-       des_crypt(out,out,key[1]);
-       des_crypt(out,out,key[2]);
-}
diff --git a/deps/crypto/des.h b/deps/crypto/des.h
deleted file mode 100644 (file)
index 1503772..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*********************************************************************
-* Filename:   des.h
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Defines the API for the corresponding DES implementation.
-              Note that encryption and decryption are defined by how
-              the key setup is performed, the actual en/de-cryption is
-              performed by the same function.
-*********************************************************************/
-
-#ifndef DES_H
-#define DESH
-
-/*************************** HEADER FILES ***************************/
-#include <stddef.h>
-
-/****************************** MACROS ******************************/
-#define DES_BLOCK_SIZE 8                // DES operates on 8 bytes at a time
-
-/**************************** DATA TYPES ****************************/
-typedef unsigned char BYTE;             // 8-bit byte
-typedef unsigned int  WORD;             // 32-bit word, change to "long" for 16-bit machines
-
-typedef enum {
-       DES_ENCRYPT,
-       DES_DECRYPT
-} DES_MODE;
-
-/*********************** FUNCTION DECLARATIONS **********************/
-void des_key_setup(const BYTE key[], BYTE schedule[][6], DES_MODE mode);
-void des_crypt(const BYTE in[], BYTE out[], const BYTE key[][6]);
-
-void three_des_key_setup(const BYTE key[], BYTE schedule[][16][6], DES_MODE mode);
-void three_des_crypt(const BYTE in[], BYTE out[], const BYTE key[][16][6]);
-
-#endif   // DES_H
diff --git a/deps/crypto/des_test.c b/deps/crypto/des_test.c
deleted file mode 100644 (file)
index 3e46134..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*********************************************************************
-* Filename:   des_test.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Performs known-answer tests on the corresponding DES
-                 implementation. These tests do not encompass the full
-                 range of available test vectors, however, if the tests
-                 pass it is very, very likely that the code is correct
-                 and was compiled properly. This code also serves as
-                 example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include "des.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int des_test()
-{
-       BYTE pt1[DES_BLOCK_SIZE] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xE7};
-       BYTE pt2[DES_BLOCK_SIZE] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
-       BYTE pt3[DES_BLOCK_SIZE] = {0x54,0x68,0x65,0x20,0x71,0x75,0x66,0x63};
-       BYTE ct1[DES_BLOCK_SIZE] = {0xc9,0x57,0x44,0x25,0x6a,0x5e,0xd3,0x1d};
-       BYTE ct2[DES_BLOCK_SIZE] = {0x85,0xe8,0x13,0x54,0x0f,0x0a,0xb4,0x05};
-       BYTE ct3[DES_BLOCK_SIZE] = {0xc9,0x57,0x44,0x25,0x6a,0x5e,0xd3,0x1d};
-       BYTE ct4[DES_BLOCK_SIZE] = {0xA8,0x26,0xFD,0x8C,0xE5,0x3B,0x85,0x5F};
-       BYTE key1[DES_BLOCK_SIZE] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
-       BYTE key2[DES_BLOCK_SIZE] = {0x13,0x34,0x57,0x79,0x9B,0xBC,0xDF,0xF1};
-       BYTE three_key1[DES_BLOCK_SIZE * 3] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
-                                              0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
-                                              0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
-       BYTE three_key2[DES_BLOCK_SIZE * 3] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
-                                              0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,0x01,
-                                              0x45,0x67,0x89,0xAB,0xCD,0xEF,0x01,0x23};
-
-       BYTE schedule[16][6];
-       BYTE three_schedule[3][16][6];
-       BYTE buf[DES_BLOCK_SIZE];
-       int pass = 1;
-
-       des_key_setup(key1, schedule, DES_ENCRYPT);
-       des_crypt(pt1, buf, schedule);
-       pass = pass && !memcmp(ct1, buf, DES_BLOCK_SIZE);
-
-       des_key_setup(key1, schedule, DES_DECRYPT);
-       des_crypt(ct1, buf, schedule);
-       pass = pass && !memcmp(pt1, buf, DES_BLOCK_SIZE);
-
-       des_key_setup(key2, schedule, DES_ENCRYPT);
-       des_crypt(pt2, buf, schedule);
-       pass = pass && !memcmp(ct2, buf, DES_BLOCK_SIZE);
-
-       des_key_setup(key2, schedule, DES_DECRYPT);
-       des_crypt(ct2, buf, schedule);
-       pass = pass && !memcmp(pt2, buf, DES_BLOCK_SIZE);
-
-       three_des_key_setup(three_key1, three_schedule, DES_ENCRYPT);
-       three_des_crypt(pt1, buf, three_schedule);
-       pass = pass && !memcmp(ct3, buf, DES_BLOCK_SIZE);
-
-       three_des_key_setup(three_key1, three_schedule, DES_DECRYPT);
-       three_des_crypt(ct3, buf, three_schedule);
-       pass = pass && !memcmp(pt1, buf, DES_BLOCK_SIZE);
-
-       three_des_key_setup(three_key2, three_schedule, DES_ENCRYPT);
-       three_des_crypt(pt3, buf, three_schedule);
-       pass = pass && !memcmp(ct4, buf, DES_BLOCK_SIZE);
-
-       three_des_key_setup(three_key2, three_schedule, DES_DECRYPT);
-       three_des_crypt(ct4, buf, three_schedule);
-       pass = pass && !memcmp(pt3, buf, DES_BLOCK_SIZE);
-
-       return(pass);
-}
-
-int main()
-{
-       printf("DES test: %s\n", des_test() ? "SUCCEEDED" : "FAILED");
-
-       return(0);
-}
diff --git a/deps/crypto/md2.c b/deps/crypto/md2.c
deleted file mode 100644 (file)
index e66d667..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*********************************************************************
-* Filename:   md2.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Implementation of the MD2 hashing algorithm.
-                                 Algorithm specification can be found here:
-                                  * http://tools.ietf.org/html/rfc1319 .
-              Input is  little endian byte order.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdlib.h>
-#include <string.h>
-#include "md2.h"
-
-/**************************** VARIABLES *****************************/
-static const BYTE s[256] = {
-       41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,
-       19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,
-       76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,
-       138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,
-       245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,
-       148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,
-       39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,
-       181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,
-       150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
-       112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,
-       96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
-       85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,
-       234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,
-       129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,
-       8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,
-       203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,
-       166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,
-       31, 26, 219, 153, 141, 51, 159, 17, 131, 20
-};
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-void md2_transform(MD2_CTX *ctx, BYTE data[])
-{
-       int j,k,t;
-
-       //memcpy(&ctx->state[16], data);
-       for (j=0; j < 16; ++j) {
-               ctx->state[j + 16] = data[j];
-               ctx->state[j + 32] = (ctx->state[j+16] ^ ctx->state[j]);
-       }
-
-       t = 0;
-       for (j = 0; j < 18; ++j) {
-               for (k = 0; k < 48; ++k) {
-                       ctx->state[k] ^= s[t];
-                       t = ctx->state[k];
-               }
-               t = (t+j) & 0xFF;
-       }
-
-       t = ctx->checksum[15];
-       for (j=0; j < 16; ++j) {
-               ctx->checksum[j] ^= s[data[j] ^ t];
-               t = ctx->checksum[j];
-       }
-}
-
-void md2_init(MD2_CTX *ctx)
-{
-       int i;
-
-       for (i=0; i < 48; ++i)
-               ctx->state[i] = 0;
-       for (i=0; i < 16; ++i)
-               ctx->checksum[i] = 0;
-       ctx->len = 0;
-}
-
-void md2_update(MD2_CTX *ctx, const BYTE data[], size_t len)
-{
-       size_t i;
-
-       for (i = 0; i < len; ++i) {
-               ctx->data[ctx->len] = data[i];
-               ctx->len++;
-               if (ctx->len == MD2_BLOCK_SIZE) {
-                       md2_transform(ctx, ctx->data);
-                       ctx->len = 0;
-               }
-       }
-}
-
-void md2_final(MD2_CTX *ctx, BYTE hash[])
-{
-       int to_pad;
-
-       to_pad = MD2_BLOCK_SIZE - ctx->len;
-
-       while (ctx->len < MD2_BLOCK_SIZE)
-               ctx->data[ctx->len++] = to_pad;
-
-       md2_transform(ctx, ctx->data);
-       md2_transform(ctx, ctx->checksum);
-
-       memcpy(hash, ctx->state, MD2_BLOCK_SIZE);
-}
diff --git a/deps/crypto/md2.h b/deps/crypto/md2.h
deleted file mode 100644 (file)
index 97706af..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*********************************************************************
-* Filename:   md2.h
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Defines the API for the corresponding MD2 implementation.
-*********************************************************************/
-
-#ifndef MD2_H
-#define MD2_H
-
-/*************************** HEADER FILES ***************************/
-#include <stddef.h>
-
-/****************************** MACROS ******************************/
-#define MD2_BLOCK_SIZE 16
-
-/**************************** DATA TYPES ****************************/
-typedef unsigned char BYTE;             // 8-bit byte
-
-typedef struct {
-   BYTE data[16];
-   BYTE state[48];
-   BYTE checksum[16];
-   int len;
-} MD2_CTX;
-
-/*********************** FUNCTION DECLARATIONS **********************/
-void md2_init(MD2_CTX *ctx);
-void md2_update(MD2_CTX *ctx, const BYTE data[], size_t len);
-void md2_final(MD2_CTX *ctx, BYTE hash[]);   // size of hash must be MD2_BLOCK_SIZE
-
-#endif   // MD2_H
diff --git a/deps/crypto/md2_test.c b/deps/crypto/md2_test.c
deleted file mode 100644 (file)
index 883f20a..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*********************************************************************
-* Filename:   md2_test.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Performs known-answer tests on the corresponding MD2
-                 implementation. These tests do not encompass the full
-                 range of available test vectors, however, if the tests
-                 pass it is very, very likely that the code is correct
-                 and was compiled properly. This code also serves as
-                 example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <string.h>
-#include <memory.h>
-#include "md2.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int md2_test()
-{
-       BYTE text1[] = {"abc"};
-       BYTE text2[] = {"abcdefghijklmnopqrstuvwxyz"};
-       BYTE text3_1[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"};
-       BYTE text3_2[] = {"fghijklmnopqrstuvwxyz0123456789"};
-       BYTE hash1[MD2_BLOCK_SIZE] = {0xda,0x85,0x3b,0x0d,0x3f,0x88,0xd9,0x9b,0x30,0x28,0x3a,0x69,0xe6,0xde,0xd6,0xbb};
-       BYTE hash2[MD2_BLOCK_SIZE] = {0x4e,0x8d,0xdf,0xf3,0x65,0x02,0x92,0xab,0x5a,0x41,0x08,0xc3,0xaa,0x47,0x94,0x0b};
-       BYTE hash3[MD2_BLOCK_SIZE] = {0xda,0x33,0xde,0xf2,0xa4,0x2d,0xf1,0x39,0x75,0x35,0x28,0x46,0xc3,0x03,0x38,0xcd};
-       BYTE buf[16];
-       MD2_CTX ctx;
-       int pass = 1;
-
-       md2_init(&ctx);
-       md2_update(&ctx, text1, strlen(text1));
-       md2_final(&ctx, buf);
-       pass = pass && !memcmp(hash1, buf, MD2_BLOCK_SIZE);
-
-       // Note that the MD2 object can be re-used.
-       md2_init(&ctx);
-       md2_update(&ctx, text2, strlen(text2));
-       md2_final(&ctx, buf);
-       pass = pass && !memcmp(hash2, buf, MD2_BLOCK_SIZE);
-
-       // Note that the data is added in two chunks.
-       md2_init(&ctx);
-       md2_update(&ctx, text3_1, strlen(text3_1));
-       md2_update(&ctx, text3_2, strlen(text3_2));
-       md2_final(&ctx, buf);
-       pass = pass && !memcmp(hash3, buf, MD2_BLOCK_SIZE);
-
-       return(pass);
-}
-
-int main()
-{
-       printf("MD2 tests: %s\n", md2_test() ? "SUCCEEDED" : "FAILED");
-}
diff --git a/deps/crypto/md5.c b/deps/crypto/md5.c
deleted file mode 100644 (file)
index 769199e..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-/*********************************************************************
-* Filename:   md5.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Implementation of the MD5 hashing algorithm.
-                                 Algorithm specification can be found here:
-                                  * http://tools.ietf.org/html/rfc1321
-                                 This implementation uses little endian byte order.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdlib.h>
-#include <string.h>
-#include "md5.h"
-
-/****************************** MACROS ******************************/
-#define ROTLEFT(a,b) ((a << b) | (a >> (32-b)))
-
-#define F(x,y,z) ((x & y) | (~x & z))
-#define G(x,y,z) ((x & z) | (y & ~z))
-#define H(x,y,z) (x ^ y ^ z)
-#define I(x,y,z) (y ^ (x | ~z))
-
-#define FF(a,b,c,d,m,s,t) { a += F(b,c,d) + m + t; \
-                            a = b + ROTLEFT(a,s); }
-#define GG(a,b,c,d,m,s,t) { a += G(b,c,d) + m + t; \
-                            a = b + ROTLEFT(a,s); }
-#define HH(a,b,c,d,m,s,t) { a += H(b,c,d) + m + t; \
-                            a = b + ROTLEFT(a,s); }
-#define II(a,b,c,d,m,s,t) { a += I(b,c,d) + m + t; \
-                            a = b + ROTLEFT(a,s); }
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-void md5_transform(MD5_CTX *ctx, const BYTE data[])
-{
-       WORD a, b, c, d, m[16], i, j;
-
-       // MD5 specifies big endian byte order, but this implementation assumes a little
-       // endian byte order CPU. Reverse all the bytes upon input, and re-reverse them
-       // on output (in md5_final()).
-       for (i = 0, j = 0; i < 16; ++i, j += 4)
-               m[i] = (data[j]) + (data[j + 1] << 8) + (data[j + 2] << 16) + (data[j + 3] << 24);
-
-       a = ctx->state[0];
-       b = ctx->state[1];
-       c = ctx->state[2];
-       d = ctx->state[3];
-
-       FF(a,b,c,d,m[0],  7,0xd76aa478);
-       FF(d,a,b,c,m[1], 12,0xe8c7b756);
-       FF(c,d,a,b,m[2], 17,0x242070db);
-       FF(b,c,d,a,m[3], 22,0xc1bdceee);
-       FF(a,b,c,d,m[4],  7,0xf57c0faf);
-       FF(d,a,b,c,m[5], 12,0x4787c62a);
-       FF(c,d,a,b,m[6], 17,0xa8304613);
-       FF(b,c,d,a,m[7], 22,0xfd469501);
-       FF(a,b,c,d,m[8],  7,0x698098d8);
-       FF(d,a,b,c,m[9], 12,0x8b44f7af);
-       FF(c,d,a,b,m[10],17,0xffff5bb1);
-       FF(b,c,d,a,m[11],22,0x895cd7be);
-       FF(a,b,c,d,m[12], 7,0x6b901122);
-       FF(d,a,b,c,m[13],12,0xfd987193);
-       FF(c,d,a,b,m[14],17,0xa679438e);
-       FF(b,c,d,a,m[15],22,0x49b40821);
-
-       GG(a,b,c,d,m[1],  5,0xf61e2562);
-       GG(d,a,b,c,m[6],  9,0xc040b340);
-       GG(c,d,a,b,m[11],14,0x265e5a51);
-       GG(b,c,d,a,m[0], 20,0xe9b6c7aa);
-       GG(a,b,c,d,m[5],  5,0xd62f105d);
-       GG(d,a,b,c,m[10], 9,0x02441453);
-       GG(c,d,a,b,m[15],14,0xd8a1e681);
-       GG(b,c,d,a,m[4], 20,0xe7d3fbc8);
-       GG(a,b,c,d,m[9],  5,0x21e1cde6);
-       GG(d,a,b,c,m[14], 9,0xc33707d6);
-       GG(c,d,a,b,m[3], 14,0xf4d50d87);
-       GG(b,c,d,a,m[8], 20,0x455a14ed);
-       GG(a,b,c,d,m[13], 5,0xa9e3e905);
-       GG(d,a,b,c,m[2],  9,0xfcefa3f8);
-       GG(c,d,a,b,m[7], 14,0x676f02d9);
-       GG(b,c,d,a,m[12],20,0x8d2a4c8a);
-
-       HH(a,b,c,d,m[5],  4,0xfffa3942);
-       HH(d,a,b,c,m[8], 11,0x8771f681);
-       HH(c,d,a,b,m[11],16,0x6d9d6122);
-       HH(b,c,d,a,m[14],23,0xfde5380c);
-       HH(a,b,c,d,m[1],  4,0xa4beea44);
-       HH(d,a,b,c,m[4], 11,0x4bdecfa9);
-       HH(c,d,a,b,m[7], 16,0xf6bb4b60);
-       HH(b,c,d,a,m[10],23,0xbebfbc70);
-       HH(a,b,c,d,m[13], 4,0x289b7ec6);
-       HH(d,a,b,c,m[0], 11,0xeaa127fa);
-       HH(c,d,a,b,m[3], 16,0xd4ef3085);
-       HH(b,c,d,a,m[6], 23,0x04881d05);
-       HH(a,b,c,d,m[9],  4,0xd9d4d039);
-       HH(d,a,b,c,m[12],11,0xe6db99e5);
-       HH(c,d,a,b,m[15],16,0x1fa27cf8);
-       HH(b,c,d,a,m[2], 23,0xc4ac5665);
-
-       II(a,b,c,d,m[0],  6,0xf4292244);
-       II(d,a,b,c,m[7], 10,0x432aff97);
-       II(c,d,a,b,m[14],15,0xab9423a7);
-       II(b,c,d,a,m[5], 21,0xfc93a039);
-       II(a,b,c,d,m[12], 6,0x655b59c3);
-       II(d,a,b,c,m[3], 10,0x8f0ccc92);
-       II(c,d,a,b,m[10],15,0xffeff47d);
-       II(b,c,d,a,m[1], 21,0x85845dd1);
-       II(a,b,c,d,m[8],  6,0x6fa87e4f);
-       II(d,a,b,c,m[15],10,0xfe2ce6e0);
-       II(c,d,a,b,m[6], 15,0xa3014314);
-       II(b,c,d,a,m[13],21,0x4e0811a1);
-       II(a,b,c,d,m[4],  6,0xf7537e82);
-       II(d,a,b,c,m[11],10,0xbd3af235);
-       II(c,d,a,b,m[2], 15,0x2ad7d2bb);
-       II(b,c,d,a,m[9], 21,0xeb86d391);
-
-       ctx->state[0] += a;
-       ctx->state[1] += b;
-       ctx->state[2] += c;
-       ctx->state[3] += d;
-}
-
-void md5_init(MD5_CTX *ctx)
-{
-       ctx->datalen = 0;
-       ctx->bitlen = 0;
-       ctx->state[0] = 0x67452301;
-       ctx->state[1] = 0xEFCDAB89;
-       ctx->state[2] = 0x98BADCFE;
-       ctx->state[3] = 0x10325476;
-}
-
-void md5_update(MD5_CTX *ctx, const BYTE data[], size_t len)
-{
-       size_t i;
-
-       for (i = 0; i < len; ++i) {
-               ctx->data[ctx->datalen] = data[i];
-               ctx->datalen++;
-               if (ctx->datalen == 64) {
-                       md5_transform(ctx, ctx->data);
-                       ctx->bitlen += 512;
-                       ctx->datalen = 0;
-               }
-       }
-}
-
-void md5_final(MD5_CTX *ctx, BYTE hash[])
-{
-       size_t i;
-
-       i = ctx->datalen;
-
-       // Pad whatever data is left in the buffer.
-       if (ctx->datalen < 56) {
-               ctx->data[i++] = 0x80;
-               while (i < 56)
-                       ctx->data[i++] = 0x00;
-       }
-       else if (ctx->datalen >= 56) {
-               ctx->data[i++] = 0x80;
-               while (i < 64)
-                       ctx->data[i++] = 0x00;
-               md5_transform(ctx, ctx->data);
-               memset(ctx->data, 0, 56);
-       }
-
-       // Append to the padding the total message's length in bits and transform.
-       ctx->bitlen += ctx->datalen * 8;
-       ctx->data[56] = ctx->bitlen;
-       ctx->data[57] = ctx->bitlen >> 8;
-       ctx->data[58] = ctx->bitlen >> 16;
-       ctx->data[59] = ctx->bitlen >> 24;
-       ctx->data[60] = ctx->bitlen >> 32;
-       ctx->data[61] = ctx->bitlen >> 40;
-       ctx->data[62] = ctx->bitlen >> 48;
-       ctx->data[63] = ctx->bitlen >> 56;
-       md5_transform(ctx, ctx->data);
-
-       // Since this implementation uses little endian byte ordering and MD uses big endian,
-       // reverse all the bytes when copying the final state to the output hash.
-       for (i = 0; i < 4; ++i) {
-               hash[i]      = (ctx->state[0] >> (i * 8)) & 0x000000ff;
-               hash[i + 4]  = (ctx->state[1] >> (i * 8)) & 0x000000ff;
-               hash[i + 8]  = (ctx->state[2] >> (i * 8)) & 0x000000ff;
-               hash[i + 12] = (ctx->state[3] >> (i * 8)) & 0x000000ff;
-       }
-}
diff --git a/deps/crypto/md5.h b/deps/crypto/md5.h
deleted file mode 100644 (file)
index e5b4490..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*********************************************************************
-* Filename:   md5.h
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Defines the API for the corresponding MD5 implementation.
-*********************************************************************/
-
-#ifndef MD5_H
-#define MD5_H
-
-/*************************** HEADER FILES ***************************/
-#include <stddef.h>
-#include "crypto_types.h"
-
-/****************************** MACROS ******************************/
-#define MD5_BLOCK_SIZE 16               // MD5 outputs a 16 byte digest
-
-/**************************** DATA TYPES ****************************/
-
-typedef struct {
-   BYTE data[64];
-   WORD datalen;
-   unsigned long long bitlen;
-   WORD state[4];
-} MD5_CTX;
-
-/*********************** FUNCTION DECLARATIONS **********************/
-void md5_init(MD5_CTX *ctx);
-void md5_update(MD5_CTX *ctx, const BYTE data[], size_t len);
-void md5_final(MD5_CTX *ctx, BYTE hash[]);
-
-#endif   // MD5_H
diff --git a/deps/crypto/md5_test.c b/deps/crypto/md5_test.c
deleted file mode 100644 (file)
index e945c8b..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*********************************************************************
-* Filename:   md5_test.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Performs known-answer tests on the corresponding MD5
-                 implementation. These tests do not encompass the full
-                 range of available test vectors, however, if the tests
-                 pass it is very, very likely that the code is correct
-                 and was compiled properly. This code also serves as
-                 example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include <string.h>
-#include "md5.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int md5_test()
-{
-       BYTE text1[] = {""};
-       BYTE text2[] = {"abc"};
-       BYTE text3_1[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"};
-       BYTE text3_2[] = {"fghijklmnopqrstuvwxyz0123456789"};
-       BYTE hash1[MD5_BLOCK_SIZE] = {0xd4,0x1d,0x8c,0xd9,0x8f,0x00,0xb2,0x04,0xe9,0x80,0x09,0x98,0xec,0xf8,0x42,0x7e};
-       BYTE hash2[MD5_BLOCK_SIZE] = {0x90,0x01,0x50,0x98,0x3c,0xd2,0x4f,0xb0,0xd6,0x96,0x3f,0x7d,0x28,0xe1,0x7f,0x72};
-       BYTE hash3[MD5_BLOCK_SIZE] = {0xd1,0x74,0xab,0x98,0xd2,0x77,0xd9,0xf5,0xa5,0x61,0x1c,0x2c,0x9f,0x41,0x9d,0x9f};
-       BYTE buf[16];
-       MD5_CTX ctx;
-       int pass = 1;
-
-       md5_init(&ctx);
-       md5_update(&ctx, text1, strlen(text1));
-       md5_final(&ctx, buf);
-       pass = pass && !memcmp(hash1, buf, MD5_BLOCK_SIZE);
-
-       // Note the MD5 object can be reused.
-       md5_init(&ctx);
-       md5_update(&ctx, text2, strlen(text2));
-       md5_final(&ctx, buf);
-       pass = pass && !memcmp(hash2, buf, MD5_BLOCK_SIZE);
-
-       // Note the data is being added in two chunks.
-       md5_init(&ctx);
-       md5_update(&ctx, text3_1, strlen(text3_1));
-       md5_update(&ctx, text3_2, strlen(text3_2));
-       md5_final(&ctx, buf);
-       pass = pass && !memcmp(hash3, buf, MD5_BLOCK_SIZE);
-
-       return(pass);
-}
-
-int main()
-{
-       printf("MD5 tests: %s\n", md5_test() ? "SUCCEEDED" : "FAILED");
-
-       return(0);
-}
diff --git a/deps/crypto/rot-13.c b/deps/crypto/rot-13.c
deleted file mode 100644 (file)
index 0ab8497..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*********************************************************************
-* Filename:   rot-13.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Implementation of the ROT-13 encryption algorithm.
-                                 Algorithm specification can be found here:
-                                  *
-                                 This implementation uses little endian byte order.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <string.h>
-#include "rot-13.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-void rot13(char str[])
-{
-   int case_type, idx, len;
-
-   for (idx = 0, len = strlen(str); idx < len; idx++) {
-      // Only process alphabetic characters.
-      if (str[idx] < 'A' || (str[idx] > 'Z' && str[idx] < 'a') || str[idx] > 'z')
-         continue;
-      // Determine if the char is upper or lower case.
-      if (str[idx] >= 'a')
-         case_type = 'a';
-      else
-         case_type = 'A';
-      // Rotate the char's value, ensuring it doesn't accidentally "fall off" the end.
-      str[idx] = (str[idx] + 13) % (case_type + 26);
-      if (str[idx] < 26)
-         str[idx] += case_type;
-   }
-}
diff --git a/deps/crypto/rot-13.h b/deps/crypto/rot-13.h
deleted file mode 100644 (file)
index 4c581c3..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*********************************************************************
-* Filename:   rot-13.h
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Defines the API for the corresponding ROT-13 implementation.
-*********************************************************************/
-
-#ifndef ROT13_H
-#define ROT13_H
-
-/*************************** HEADER FILES ***************************/
-#include <stddef.h>
-
-/*********************** FUNCTION DECLARATIONS **********************/
-// Performs IN PLACE rotation of the input. Assumes input is NULL terminated.
-// Preserves each charcter's case. Ignores non alphabetic characters.
-void rot13(char str[]);
-
-#endif   // ROT13_H
diff --git a/deps/crypto/rot-13_test.c b/deps/crypto/rot-13_test.c
deleted file mode 100644 (file)
index a6fd01d..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*********************************************************************
-* Filename:   rot-13_test.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Performs known-answer tests on the corresponding ROT-13
-                 implementation. These tests do not encompass the full
-                 range of available test vectors, however, if the tests
-                 pass it is very, very likely that the code is correct
-                 and was compiled properly. This code also serves as
-                 example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <string.h>
-#include "rot-13.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int rot13_test()
-{
-       char text[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};
-       char code[] = {"NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"};
-       char buf[1024];
-       int pass = 1;
-
-       // To encode, just apply ROT-13.
-       strcpy(buf, text);
-       rot13(buf);
-       pass = pass && !strcmp(code, buf);
-
-       // To decode, just re-apply ROT-13.
-       rot13(buf);
-       pass = pass && !strcmp(text, buf);
-
-       return(pass);
-}
-
-int main()
-{
-       printf("ROT-13 tests: %s\n", rot13_test() ? "SUCCEEDED" : "FAILED");
-
-       return(0);
-}
diff --git a/deps/crypto/sha1.c b/deps/crypto/sha1.c
deleted file mode 100644 (file)
index eb0bda0..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/*********************************************************************
-* Filename:   sha1.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Implementation of the SHA1 hashing algorithm.
-              Algorithm specification can be found here:
-               * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
-              This implementation uses little endian byte order.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdlib.h>
-#include <string.h>
-#include "sha1.h"
-
-/****************************** MACROS ******************************/
-#define ROTLEFT(a, b) ((a << b) | (a >> (32 - b)))
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-void sha1_transform(SHA1_CTX *ctx, const BYTE data[])
-{
-       WORD a, b, c, d, e, i, j, t, m[80];
-
-       for (i = 0, j = 0; i < 16; ++i, j += 4)
-               m[i] = (data[j] << 24) + (data[j + 1] << 16) + (data[j + 2] << 8) + (data[j + 3]);
-       for ( ; i < 80; ++i) {
-               m[i] = (m[i - 3] ^ m[i - 8] ^ m[i - 14] ^ m[i - 16]);
-               m[i] = (m[i] << 1) | (m[i] >> 31);
-       }
-
-       a = ctx->state[0];
-       b = ctx->state[1];
-       c = ctx->state[2];
-       d = ctx->state[3];
-       e = ctx->state[4];
-
-       for (i = 0; i < 20; ++i) {
-               t = ROTLEFT(a, 5) + ((b & c) ^ (~b & d)) + e + ctx->k[0] + m[i];
-               e = d;
-               d = c;
-               c = ROTLEFT(b, 30);
-               b = a;
-               a = t;
-       }
-       for ( ; i < 40; ++i) {
-               t = ROTLEFT(a, 5) + (b ^ c ^ d) + e + ctx->k[1] + m[i];
-               e = d;
-               d = c;
-               c = ROTLEFT(b, 30);
-               b = a;
-               a = t;
-       }
-       for ( ; i < 60; ++i) {
-               t = ROTLEFT(a, 5) + ((b & c) ^ (b & d) ^ (c & d))  + e + ctx->k[2] + m[i];
-               e = d;
-               d = c;
-               c = ROTLEFT(b, 30);
-               b = a;
-               a = t;
-       }
-       for ( ; i < 80; ++i) {
-               t = ROTLEFT(a, 5) + (b ^ c ^ d) + e + ctx->k[3] + m[i];
-               e = d;
-               d = c;
-               c = ROTLEFT(b, 30);
-               b = a;
-               a = t;
-       }
-
-       ctx->state[0] += a;
-       ctx->state[1] += b;
-       ctx->state[2] += c;
-       ctx->state[3] += d;
-       ctx->state[4] += e;
-}
-
-void sha1_init(SHA1_CTX *ctx)
-{
-       ctx->datalen = 0;
-       ctx->bitlen = 0;
-       ctx->state[0] = 0x67452301;
-       ctx->state[1] = 0xEFCDAB89;
-       ctx->state[2] = 0x98BADCFE;
-       ctx->state[3] = 0x10325476;
-       ctx->state[4] = 0xc3d2e1f0;
-       ctx->k[0] = 0x5a827999;
-       ctx->k[1] = 0x6ed9eba1;
-       ctx->k[2] = 0x8f1bbcdc;
-       ctx->k[3] = 0xca62c1d6;
-}
-
-void sha1_update(SHA1_CTX *ctx, const BYTE data[], size_t len)
-{
-       size_t i;
-
-       for (i = 0; i < len; ++i) {
-               ctx->data[ctx->datalen] = data[i];
-               ctx->datalen++;
-               if (ctx->datalen == 64) {
-                       sha1_transform(ctx, ctx->data);
-                       ctx->bitlen += 512;
-                       ctx->datalen = 0;
-               }
-       }
-}
-
-void sha1_final(SHA1_CTX *ctx, BYTE hash[])
-{
-       WORD i;
-
-       i = ctx->datalen;
-
-       // Pad whatever data is left in the buffer.
-       if (ctx->datalen < 56) {
-               ctx->data[i++] = 0x80;
-               while (i < 56)
-                       ctx->data[i++] = 0x00;
-       }
-       else {
-               ctx->data[i++] = 0x80;
-               while (i < 64)
-                       ctx->data[i++] = 0x00;
-               sha1_transform(ctx, ctx->data);
-               memset(ctx->data, 0, 56);
-       }
-
-       // Append to the padding the total message's length in bits and transform.
-       ctx->bitlen += ctx->datalen * 8;
-       ctx->data[63] = ctx->bitlen;
-       ctx->data[62] = ctx->bitlen >> 8;
-       ctx->data[61] = ctx->bitlen >> 16;
-       ctx->data[60] = ctx->bitlen >> 24;
-       ctx->data[59] = ctx->bitlen >> 32;
-       ctx->data[58] = ctx->bitlen >> 40;
-       ctx->data[57] = ctx->bitlen >> 48;
-       ctx->data[56] = ctx->bitlen >> 56;
-       sha1_transform(ctx, ctx->data);
-
-       // Since this implementation uses little endian byte ordering and MD uses big endian,
-       // reverse all the bytes when copying the final state to the output hash.
-       for (i = 0; i < 4; ++i) {
-               hash[i]      = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 4]  = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 8]  = (ctx->state[2] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff;
-       }
-}
diff --git a/deps/crypto/sha1.h b/deps/crypto/sha1.h
deleted file mode 100644 (file)
index e4c7869..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*********************************************************************
-* Filename:   sha1.h
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Defines the API for the corresponding SHA1 implementation.
-*********************************************************************/
-
-#ifndef SHA1_H
-#define SHA1_H
-
-/*************************** HEADER FILES ***************************/
-#include <stddef.h>
-
-#include "crypto_types.h"
-
-/****************************** MACROS ******************************/
-#define SHA1_BLOCK_SIZE 20              // SHA1 outputs a 20 byte digest
-
-/**************************** DATA TYPES ****************************/
-typedef struct {
-       BYTE data[64];
-       WORD datalen;
-       unsigned long long bitlen;
-       WORD state[5];
-       WORD k[4];
-} SHA1_CTX;
-
-/*********************** FUNCTION DECLARATIONS **********************/
-void sha1_init(SHA1_CTX *ctx);
-void sha1_update(SHA1_CTX *ctx, const BYTE data[], size_t len);
-void sha1_final(SHA1_CTX *ctx, BYTE hash[]);
-
-#endif   // SHA1_H
diff --git a/deps/crypto/sha1_test.c b/deps/crypto/sha1_test.c
deleted file mode 100644 (file)
index 6c78f7d..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*********************************************************************
-* Filename:   sha1_test.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Performs known-answer tests on the corresponding SHA1
-                 implementation. These tests do not encompass the full
-                 range of available test vectors, however, if the tests
-                 pass it is very, very likely that the code is correct
-                 and was compiled properly. This code also serves as
-                 example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include <string.h>
-#include "sha1.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int sha1_test()
-{
-       BYTE text1[] = {"abc"};
-       BYTE text2[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
-       BYTE text3[] = {"aaaaaaaaaa"};
-       BYTE hash1[SHA1_BLOCK_SIZE] = {0xa9,0x99,0x3e,0x36,0x47,0x06,0x81,0x6a,0xba,0x3e,0x25,0x71,0x78,0x50,0xc2,0x6c,0x9c,0xd0,0xd8,0x9d};
-       BYTE hash2[SHA1_BLOCK_SIZE] = {0x84,0x98,0x3e,0x44,0x1c,0x3b,0xd2,0x6e,0xba,0xae,0x4a,0xa1,0xf9,0x51,0x29,0xe5,0xe5,0x46,0x70,0xf1};
-       BYTE hash3[SHA1_BLOCK_SIZE] = {0x34,0xaa,0x97,0x3c,0xd4,0xc4,0xda,0xa4,0xf6,0x1e,0xeb,0x2b,0xdb,0xad,0x27,0x31,0x65,0x34,0x01,0x6f};
-       BYTE buf[SHA1_BLOCK_SIZE];
-       int idx;
-       SHA1_CTX ctx;
-       int pass = 1;
-
-       sha1_init(&ctx);
-       sha1_update(&ctx, text1, strlen(text1));
-       sha1_final(&ctx, buf);
-       pass = pass && !memcmp(hash1, buf, SHA1_BLOCK_SIZE);
-
-       sha1_init(&ctx);
-       sha1_update(&ctx, text2, strlen(text2));
-       sha1_final(&ctx, buf);
-       pass = pass && !memcmp(hash2, buf, SHA1_BLOCK_SIZE);
-
-       sha1_init(&ctx);
-       for (idx = 0; idx < 100000; ++idx)
-          sha1_update(&ctx, text3, strlen(text3));
-       sha1_final(&ctx, buf);
-       pass = pass && !memcmp(hash3, buf, SHA1_BLOCK_SIZE);
-
-       return(pass);
-}
-
-int main()
-{
-       printf("SHA1 tests: %s\n", sha1_test() ? "SUCCEEDED" : "FAILED");
-
-       return(0);
-}
diff --git a/deps/crypto/sha256.c b/deps/crypto/sha256.c
deleted file mode 100644 (file)
index d644d2d..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*********************************************************************
-* Filename:   sha256.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Implementation of the SHA-256 hashing algorithm.
-              SHA-256 is one of the three algorithms in the SHA2
-              specification. The others, SHA-384 and SHA-512, are not
-              offered in this implementation.
-              Algorithm specification can be found here:
-               * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
-              This implementation uses little endian byte order.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdlib.h>
-#include <string.h>
-#include "sha256.h"
-
-/****************************** MACROS ******************************/
-#define ROTLEFT(a,b) (((a) << (b)) | ((a) >> (32-(b))))
-#define ROTRIGHT(a,b) (((a) >> (b)) | ((a) << (32-(b))))
-
-#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z)))
-#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
-#define EP0(x) (ROTRIGHT(x,2) ^ ROTRIGHT(x,13) ^ ROTRIGHT(x,22))
-#define EP1(x) (ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25))
-#define SIG0(x) (ROTRIGHT(x,7) ^ ROTRIGHT(x,18) ^ ((x) >> 3))
-#define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10))
-
-/**************************** VARIABLES *****************************/
-static const WORD k[64] = {
-       0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
-       0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
-       0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
-       0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,
-       0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,
-       0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
-       0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
-       0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
-};
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-void sha256_transform(SHA256_CTX *ctx, const BYTE data[])
-{
-       WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
-
-       for (i = 0, j = 0; i < 16; ++i, j += 4)
-               m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);
-       for ( ; i < 64; ++i)
-               m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];
-
-       a = ctx->state[0];
-       b = ctx->state[1];
-       c = ctx->state[2];
-       d = ctx->state[3];
-       e = ctx->state[4];
-       f = ctx->state[5];
-       g = ctx->state[6];
-       h = ctx->state[7];
-
-       for (i = 0; i < 64; ++i) {
-               t1 = h + EP1(e) + CH(e,f,g) + k[i] + m[i];
-               t2 = EP0(a) + MAJ(a,b,c);
-               h = g;
-               g = f;
-               f = e;
-               e = d + t1;
-               d = c;
-               c = b;
-               b = a;
-               a = t1 + t2;
-       }
-
-       ctx->state[0] += a;
-       ctx->state[1] += b;
-       ctx->state[2] += c;
-       ctx->state[3] += d;
-       ctx->state[4] += e;
-       ctx->state[5] += f;
-       ctx->state[6] += g;
-       ctx->state[7] += h;
-}
-
-void sha256_init(SHA256_CTX *ctx)
-{
-       ctx->datalen = 0;
-       ctx->bitlen = 0;
-       ctx->state[0] = 0x6a09e667;
-       ctx->state[1] = 0xbb67ae85;
-       ctx->state[2] = 0x3c6ef372;
-       ctx->state[3] = 0xa54ff53a;
-       ctx->state[4] = 0x510e527f;
-       ctx->state[5] = 0x9b05688c;
-       ctx->state[6] = 0x1f83d9ab;
-       ctx->state[7] = 0x5be0cd19;
-}
-
-void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
-{
-       WORD i;
-
-       for (i = 0; i < len; ++i) {
-               ctx->data[ctx->datalen] = data[i];
-               ctx->datalen++;
-               if (ctx->datalen == 64) {
-                       sha256_transform(ctx, ctx->data);
-                       ctx->bitlen += 512;
-                       ctx->datalen = 0;
-               }
-       }
-}
-
-void sha256_final(SHA256_CTX *ctx, BYTE hash[])
-{
-       WORD i;
-
-       i = ctx->datalen;
-
-       // Pad whatever data is left in the buffer.
-       if (ctx->datalen < 56) {
-               ctx->data[i++] = 0x80;
-               while (i < 56)
-                       ctx->data[i++] = 0x00;
-       }
-       else {
-               ctx->data[i++] = 0x80;
-               while (i < 64)
-                       ctx->data[i++] = 0x00;
-               sha256_transform(ctx, ctx->data);
-               memset(ctx->data, 0, 56);
-       }
-
-       // Append to the padding the total message's length in bits and transform.
-       ctx->bitlen += ctx->datalen * 8;
-       ctx->data[63] = ctx->bitlen;
-       ctx->data[62] = ctx->bitlen >> 8;
-       ctx->data[61] = ctx->bitlen >> 16;
-       ctx->data[60] = ctx->bitlen >> 24;
-       ctx->data[59] = ctx->bitlen >> 32;
-       ctx->data[58] = ctx->bitlen >> 40;
-       ctx->data[57] = ctx->bitlen >> 48;
-       ctx->data[56] = ctx->bitlen >> 56;
-       sha256_transform(ctx, ctx->data);
-
-       // Since this implementation uses little endian byte ordering and SHA uses big endian,
-       // reverse all the bytes when copying the final state to the output hash.
-       for (i = 0; i < 4; ++i) {
-               hash[i]      = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 4]  = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 8]  = (ctx->state[2] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0x000000ff;
-               hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0x000000ff;
-       }
-}
diff --git a/deps/crypto/sha256.h b/deps/crypto/sha256.h
deleted file mode 100644 (file)
index 7123a30..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*********************************************************************
-* Filename:   sha256.h
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Defines the API for the corresponding SHA1 implementation.
-*********************************************************************/
-
-#ifndef SHA256_H
-#define SHA256_H
-
-/*************************** HEADER FILES ***************************/
-#include <stddef.h>
-
-/****************************** MACROS ******************************/
-#define SHA256_BLOCK_SIZE 32            // SHA256 outputs a 32 byte digest
-
-/**************************** DATA TYPES ****************************/
-typedef unsigned char BYTE;             // 8-bit byte
-typedef unsigned int  WORD;             // 32-bit word, change to "long" for 16-bit machines
-
-typedef struct {
-       BYTE data[64];
-       WORD datalen;
-       unsigned long long bitlen;
-       WORD state[8];
-} SHA256_CTX;
-
-/*********************** FUNCTION DECLARATIONS **********************/
-void sha256_init(SHA256_CTX *ctx);
-void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
-void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
-
-#endif   // SHA256_H
diff --git a/deps/crypto/sha256_test.c b/deps/crypto/sha256_test.c
deleted file mode 100644 (file)
index 726a668..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*********************************************************************
-* Filename:   sha256.c
-* Author:     Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details:    Performs known-answer tests on the corresponding SHA1
-                 implementation. These tests do not encompass the full
-                 range of available test vectors, however, if the tests
-                 pass it is very, very likely that the code is correct
-                 and was compiled properly. This code also serves as
-                 example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include <string.h>
-#include "sha256.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int sha256_test()
-{
-       BYTE text1[] = {"abc"};
-       BYTE text2[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
-       BYTE text3[] = {"aaaaaaaaaa"};
-       BYTE hash1[SHA256_BLOCK_SIZE] = {0xba,0x78,0x16,0xbf,0x8f,0x01,0xcf,0xea,0x41,0x41,0x40,0xde,0x5d,0xae,0x22,0x23,
-                                        0xb0,0x03,0x61,0xa3,0x96,0x17,0x7a,0x9c,0xb4,0x10,0xff,0x61,0xf2,0x00,0x15,0xad};
-       BYTE hash2[SHA256_BLOCK_SIZE] = {0x24,0x8d,0x6a,0x61,0xd2,0x06,0x38,0xb8,0xe5,0xc0,0x26,0x93,0x0c,0x3e,0x60,0x39,
-                                        0xa3,0x3c,0xe4,0x59,0x64,0xff,0x21,0x67,0xf6,0xec,0xed,0xd4,0x19,0xdb,0x06,0xc1};
-       BYTE hash3[SHA256_BLOCK_SIZE] = {0xcd,0xc7,0x6e,0x5c,0x99,0x14,0xfb,0x92,0x81,0xa1,0xc7,0xe2,0x84,0xd7,0x3e,0x67,
-                                        0xf1,0x80,0x9a,0x48,0xa4,0x97,0x20,0x0e,0x04,0x6d,0x39,0xcc,0xc7,0x11,0x2c,0xd0};
-       BYTE buf[SHA256_BLOCK_SIZE];
-       SHA256_CTX ctx;
-       int idx;
-       int pass = 1;
-
-       sha256_init(&ctx);
-       sha256_update(&ctx, text1, strlen(text1));
-       sha256_final(&ctx, buf);
-       pass = pass && !memcmp(hash1, buf, SHA256_BLOCK_SIZE);
-
-       sha256_init(&ctx);
-       sha256_update(&ctx, text2, strlen(text2));
-       sha256_final(&ctx, buf);
-       pass = pass && !memcmp(hash2, buf, SHA256_BLOCK_SIZE);
-
-       sha256_init(&ctx);
-       for (idx = 0; idx < 100000; ++idx)
-          sha256_update(&ctx, text3, strlen(text3));
-       sha256_final(&ctx, buf);
-       pass = pass && !memcmp(hash3, buf, SHA256_BLOCK_SIZE);
-
-       return(pass);
-}
-
-int main()
-{
-       printf("SHA-256 tests: %s\n", sha256_test() ? "SUCCEEDED" : "FAILED");
-
-       return(0);
-}
diff --git a/deps/libchdr/.gitrepo b/deps/libchdr/.gitrepo
new file mode 100644 (file)
index 0000000..560b69c
--- /dev/null
@@ -0,0 +1,12 @@
+; DO NOT EDIT (unless you know what you are doing)
+;
+; This subdirectory is a git "subrepo", and this file is maintained by the
+; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
+;
+[subrepo]
+       remote = https://github.com/rtissera/libchdr
+       branch = master
+       commit = a17c0da7e9efa8cbb752c707df7d5457b2149fb8
+       parent = 2f8b37246c10773b391368f99311a192f1fb331f
+       method = merge
+       cmdver = 0.4.3
diff --git a/deps/libchdr/CMakeLists.txt b/deps/libchdr/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9842447
--- /dev/null
@@ -0,0 +1,126 @@
+cmake_minimum_required(VERSION 3.9)
+
+project(chdr C)
+
+set(CHDR_VERSION_MAJOR 0)
+set(CHDR_VERSION_MINOR 1)
+
+if(CMAKE_PROJECT_NAME STREQUAL "chdr")
+  option(BUILD_SHARED_LIBS "Build libchdr also as a shared library" ON)
+endif()
+option(INSTALL_STATIC_LIBS "Install static libraries" OFF)
+option(WITH_SYSTEM_ZLIB "Use system provided zlib library" OFF)
+
+if(CMAKE_C_COMPILER_ID MATCHES "GNU")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fPIC -O3 -flto")
+  set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
+elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
+  set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
+endif()
+
+include(FindPkgConfig)
+include(GNUInstallDirs)
+
+# Detect processor type.
+if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
+  set(CPU_ARCH "x64")
+elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
+  # MSVC x86/x64
+  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+    set(CPU_ARCH "x64")
+  else()
+    set(CPU_ARCH "x86")
+  endif()
+elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386" OR
+       ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
+  set(CPU_ARCH "x86")
+elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
+  set(CPU_ARCH "aarch64")
+elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
+  set(CPU_ARCH "arm")
+else()
+  message(FATAL_ERROR "Unknown system processor: " ${CMAKE_SYSTEM_PROCESSOR})
+endif()
+
+#--------------------------------------------------
+# dependencies
+#--------------------------------------------------
+
+
+# lzma
+add_subdirectory(deps/lzma-19.00 EXCLUDE_FROM_ALL)
+  list(APPEND CHDR_LIBS lzma)
+  list(APPEND CHDR_INCLUDES lzma)
+
+# zlib
+if (WITH_SYSTEM_ZLIB)
+  pkg_check_modules(ZLIB REQUIRED zlib)
+  list(APPEND PLATFORM_INCLUDES ${ZLIB_INCLUDE_DIRS})
+  list(APPEND PLATFORM_LIBS ${ZLIB_LIBRARIES})
+else()
+  add_subdirectory(deps/zlib-1.2.11 EXCLUDE_FROM_ALL)
+  list(APPEND CHDR_LIBS zlib)
+  list(APPEND CHDR_INCLUDES zlib)
+endif()
+
+#--------------------------------------------------
+# chdr
+#--------------------------------------------------
+
+set(CHDR_SOURCES
+  src/libchdr_bitstream.c
+  src/libchdr_cdrom.c
+  src/libchdr_chd.c
+  src/libchdr_flac.c
+  src/libchdr_huffman.c
+)
+
+list(APPEND CHDR_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/include)
+
+add_library(chdr-static STATIC ${CHDR_SOURCES})
+target_include_directories(chdr-static PRIVATE ${CHDR_INCLUDES} ${PLATFORM_INCLUDES} PUBLIC include)
+target_compile_definitions(chdr-static PRIVATE ${CHDR_DEFS})
+target_link_libraries(chdr-static PRIVATE ${CHDR_LIBS} ${PLATFORM_LIBS})
+
+if (INSTALL_STATIC_LIBS)
+  install(TARGETS chdr-static ${CHDR_LIBS}
+    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+  )
+endif()
+
+if (BUILD_SHARED_LIBS)
+  set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+  set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
+
+  add_library(chdr SHARED ${CHDR_SOURCES})
+  target_include_directories(chdr PRIVATE ${CHDR_INCLUDES} ${PLATFORM_INCLUDES} PUBLIC include)
+  target_compile_definitions(chdr PRIVATE ${CHDR_DEFS})
+  target_link_libraries(chdr PRIVATE ${CHDR_LIBS} ${PLATFORM_LIBS})
+
+  if(MSVC)
+    target_compile_definitions(chdr PUBLIC "CHD_DLL")
+    target_compile_definitions(chdr PRIVATE "CHD_DLL_EXPORTS")
+  elseif(APPLE)
+    target_link_options(chdr PRIVATE -Wl,-dead_strip -Wl,-exported_symbol,_chd_*)
+  else()
+    target_link_options(chdr PRIVATE -Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/src/link.T -Wl,--no-undefined)
+  endif()
+
+  set_target_properties(chdr PROPERTIES PUBLIC_HEADER "include/libchdr/bitstream.h;include/libchdr/cdrom.h;include/libchdr/chd.h;include/libchdr/chdconfig.h;include/libchdr/coretypes.h;include/libchdr/flac.h;include/libchdr/huffman.h")
+  set_target_properties(chdr PROPERTIES VERSION "${CHDR_VERSION_MAJOR}.${CHDR_VERSION_MINOR}")
+
+  if (CMAKE_BUILD_TYPE MATCHES Release)
+    #add_custom_command(TARGET chdr POST_BUILD COMMAND ${CMAKE_STRIP} libchdr.so)
+  endif (CMAKE_BUILD_TYPE MATCHES Release)
+
+  install(TARGETS chdr
+    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+    PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libchdr"
+  )
+
+  configure_file(pkg-config.pc.in ${CMAKE_BINARY_DIR}/libchdr.pc @ONLY)
+  install(FILES ${CMAKE_BINARY_DIR}/libchdr.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+endif()
+
diff --git a/deps/libchdr/deps/lzma-19.00/CMakeLists.txt b/deps/libchdr/deps/lzma-19.00/CMakeLists.txt
new file mode 100644 (file)
index 0000000..fb01f60
--- /dev/null
@@ -0,0 +1,32 @@
+add_library(lzma STATIC
+  include/7zTypes.h
+  include/Alloc.h
+  include/Bra.h
+  include/Compiler.h
+  include/CpuArch.h
+  include/Delta.h
+  include/LzFind.h
+  include/LzHash.h
+  include/Lzma86.h
+  include/LzmaDec.h
+  include/LzmaEnc.h
+  include/LzmaLib.h
+  include/Precomp.h
+  include/Sort.h
+  src/Alloc.c
+  src/Bra86.c
+  src/BraIA64.c
+  src/CpuArch.c
+  src/Delta.c
+  src/LzFind.c
+  src/Lzma86Dec.c
+  src/LzmaDec.c
+  src/LzmaEnc.c
+  src/Sort.c
+)
+
+target_compile_definitions(lzma PRIVATE _7ZIP_ST)
+
+target_include_directories(lzma PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
+target_include_directories(lzma INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
+
diff --git a/deps/libchdr/deps/lzma-19.00/LICENSE b/deps/libchdr/deps/lzma-19.00/LICENSE
new file mode 100644 (file)
index 0000000..5f57051
--- /dev/null
@@ -0,0 +1,3 @@
+LZMA SDK is placed in the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or distribute the original LZMA SDK code, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
\ No newline at end of file
diff --git a/deps/libchdr/deps/lzma-19.00/include/7zTypes.h b/deps/libchdr/deps/lzma-19.00/include/7zTypes.h
new file mode 100644 (file)
index 0000000..65b3af6
--- /dev/null
@@ -0,0 +1,375 @@
+/* 7zTypes.h -- Basic types
+2018-08-04 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_TYPES_H
+#define __7Z_TYPES_H
+
+#ifdef _WIN32
+/* #include <windows.h> */
+#endif
+
+#include <stddef.h>
+
+#ifndef EXTERN_C_BEGIN
+#ifdef __cplusplus
+#define EXTERN_C_BEGIN extern "C" {
+#define EXTERN_C_END }
+#else
+#define EXTERN_C_BEGIN
+#define EXTERN_C_END
+#endif
+#endif
+
+EXTERN_C_BEGIN
+
+#define SZ_OK 0
+
+#define SZ_ERROR_DATA 1
+#define SZ_ERROR_MEM 2
+#define SZ_ERROR_CRC 3
+#define SZ_ERROR_UNSUPPORTED 4
+#define SZ_ERROR_PARAM 5
+#define SZ_ERROR_INPUT_EOF 6
+#define SZ_ERROR_OUTPUT_EOF 7
+#define SZ_ERROR_READ 8
+#define SZ_ERROR_WRITE 9
+#define SZ_ERROR_PROGRESS 10
+#define SZ_ERROR_FAIL 11
+#define SZ_ERROR_THREAD 12
+
+#define SZ_ERROR_ARCHIVE 16
+#define SZ_ERROR_NO_ARCHIVE 17
+
+typedef int SRes;
+
+
+#ifdef _WIN32
+
+/* typedef DWORD WRes; */
+typedef unsigned WRes;
+#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
+
+#else
+
+typedef int WRes;
+#define MY__FACILITY_WIN32 7
+#define MY__FACILITY__WRes MY__FACILITY_WIN32
+#define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))
+
+#endif
+
+
+#ifndef RINOK
+#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
+#endif
+
+typedef unsigned char Byte;
+typedef short Int16;
+typedef unsigned short UInt16;
+
+#ifdef _LZMA_UINT32_IS_ULONG
+typedef long Int32;
+typedef unsigned long UInt32;
+#else
+typedef int Int32;
+typedef unsigned int UInt32;
+#endif
+
+#ifdef _SZ_NO_INT_64
+
+/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
+   NOTES: Some code will work incorrectly in that case! */
+
+typedef long Int64;
+typedef unsigned long UInt64;
+
+#else
+
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+typedef __int64 Int64;
+typedef unsigned __int64 UInt64;
+#define UINT64_CONST(n) n
+#else
+typedef long long int Int64;
+typedef unsigned long long int UInt64;
+#define UINT64_CONST(n) n ## ULL
+#endif
+
+#endif
+
+#ifdef _LZMA_NO_SYSTEM_SIZE_T
+typedef UInt32 SizeT;
+#else
+typedef size_t SizeT;
+#endif
+
+typedef int BoolInt;
+/* typedef BoolInt Bool; */
+#define True 1
+#define False 0
+
+
+#ifdef _WIN32
+#define MY_STD_CALL __stdcall
+#else
+#define MY_STD_CALL
+#endif
+
+#ifdef _MSC_VER
+
+#if _MSC_VER >= 1300
+#define MY_NO_INLINE __declspec(noinline)
+#else
+#define MY_NO_INLINE
+#endif
+
+#define MY_FORCE_INLINE __forceinline
+
+#define MY_CDECL __cdecl
+#define MY_FAST_CALL __fastcall
+
+#else
+
+#define MY_NO_INLINE
+#define MY_FORCE_INLINE
+#define MY_CDECL
+#define MY_FAST_CALL
+
+/* inline keyword : for C++ / C99 */
+
+/* GCC, clang: */
+/*
+#if defined (__GNUC__) && (__GNUC__ >= 4)
+#define MY_FORCE_INLINE __attribute__((always_inline))
+#define MY_NO_INLINE __attribute__((noinline))
+#endif
+*/
+
+#endif
+
+
+/* The following interfaces use first parameter as pointer to structure */
+
+typedef struct IByteIn IByteIn;
+struct IByteIn
+{
+  Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */
+};
+#define IByteIn_Read(p) (p)->Read(p)
+
+
+typedef struct IByteOut IByteOut;
+struct IByteOut
+{
+  void (*Write)(const IByteOut *p, Byte b);
+};
+#define IByteOut_Write(p, b) (p)->Write(p, b)
+
+
+typedef struct ISeqInStream ISeqInStream;
+struct ISeqInStream
+{
+  SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size);
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+       (output(*size) < input(*size)) is allowed */
+};
+#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
+
+/* it can return SZ_ERROR_INPUT_EOF */
+SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size);
+SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType);
+SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf);
+
+
+typedef struct ISeqOutStream ISeqOutStream;
+struct ISeqOutStream
+{
+  size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size);
+    /* Returns: result - the number of actually written bytes.
+       (result < size) means error */
+};
+#define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
+
+typedef enum
+{
+  SZ_SEEK_SET = 0,
+  SZ_SEEK_CUR = 1,
+  SZ_SEEK_END = 2
+} ESzSeek;
+
+
+typedef struct ISeekInStream ISeekInStream;
+struct ISeekInStream
+{
+  SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
+  SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin);
+};
+#define ISeekInStream_Read(p, buf, size)   (p)->Read(p, buf, size)
+#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
+
+
+typedef struct ILookInStream ILookInStream;
+struct ILookInStream
+{
+  SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size);
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+       (output(*size) > input(*size)) is not allowed
+       (output(*size) < input(*size)) is allowed */
+  SRes (*Skip)(const ILookInStream *p, size_t offset);
+    /* offset must be <= output(*size) of Look */
+
+  SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);
+    /* reads directly (without buffer). It's same as ISeqInStream::Read */
+  SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin);
+};
+
+#define ILookInStream_Look(p, buf, size)   (p)->Look(p, buf, size)
+#define ILookInStream_Skip(p, offset)      (p)->Skip(p, offset)
+#define ILookInStream_Read(p, buf, size)   (p)->Read(p, buf, size)
+#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
+
+
+SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size);
+SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset);
+
+/* reads via ILookInStream::Read */
+SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType);
+SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size);
+
+
+
+typedef struct
+{
+  ILookInStream vt;
+  const ISeekInStream *realStream;
+  size_t pos;
+  size_t size; /* it's data size */
+  
+  /* the following variables must be set outside */
+  Byte *buf;
+  size_t bufSize;
+} CLookToRead2;
+
+void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
+
+#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
+
+
+typedef struct
+{
+  ISeqInStream vt;
+  const ILookInStream *realStream;
+} CSecToLook;
+
+void SecToLook_CreateVTable(CSecToLook *p);
+
+
+
+typedef struct
+{
+  ISeqInStream vt;
+  const ILookInStream *realStream;
+} CSecToRead;
+
+void SecToRead_CreateVTable(CSecToRead *p);
+
+
+typedef struct ICompressProgress ICompressProgress;
+
+struct ICompressProgress
+{
+  SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize);
+    /* Returns: result. (result != SZ_OK) means break.
+       Value (UInt64)(Int64)-1 for size means unknown value. */
+};
+#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
+
+
+
+typedef struct ISzAlloc ISzAlloc;
+typedef const ISzAlloc * ISzAllocPtr;
+
+struct ISzAlloc
+{
+  void *(*Alloc)(ISzAllocPtr p, size_t size);
+  void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */
+};
+
+#define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
+#define ISzAlloc_Free(p, a) (p)->Free(p, a)
+
+/* deprecated */
+#define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
+#define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
+
+
+
+
+
+#ifndef MY_offsetof
+  #ifdef offsetof
+    #define MY_offsetof(type, m) offsetof(type, m)
+    /*
+    #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
+    */
+  #else
+    #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
+  #endif
+#endif
+
+
+
+#ifndef MY_container_of
+
+/*
+#define MY_container_of(ptr, type, m) container_of(ptr, type, m)
+#define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
+#define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
+#define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
+*/
+
+/*
+  GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
+    GCC 3.4.4 : classes with constructor
+    GCC 4.8.1 : classes with non-public variable members"
+*/
+
+#define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
+
+
+#endif
+
+#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
+
+/*
+#define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
+*/
+#define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
+
+#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
+/*
+#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
+*/
+
+
+
+#ifdef _WIN32
+
+#define CHAR_PATH_SEPARATOR '\\'
+#define WCHAR_PATH_SEPARATOR L'\\'
+#define STRING_PATH_SEPARATOR "\\"
+#define WSTRING_PATH_SEPARATOR L"\\"
+
+#else
+
+#define CHAR_PATH_SEPARATOR '/'
+#define WCHAR_PATH_SEPARATOR L'/'
+#define STRING_PATH_SEPARATOR "/"
+#define WSTRING_PATH_SEPARATOR L"/"
+
+#endif
+
+EXTERN_C_END
+
+#endif
similarity index 52%
rename from deps/lzma-16.04/C/Alloc.h
rename to deps/libchdr/deps/lzma-19.00/include/Alloc.h
index 73b282a..6482376 100644 (file)
@@ -1,37 +1,51 @@
-/* Alloc.h -- Memory allocation functions\r
-2015-02-21 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __COMMON_ALLOC_H\r
-#define __COMMON_ALLOC_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-void *MyAlloc(size_t size);\r
-void MyFree(void *address);\r
-\r
-#ifdef _WIN32\r
-\r
-void SetLargePageSize();\r
-\r
-void *MidAlloc(size_t size);\r
-void MidFree(void *address);\r
-void *BigAlloc(size_t size);\r
-void BigFree(void *address);\r
-\r
-#else\r
-\r
-#define MidAlloc(size) MyAlloc(size)\r
-#define MidFree(address) MyFree(address)\r
-#define BigAlloc(size) MyAlloc(size)\r
-#define BigFree(address) MyFree(address)\r
-\r
-#endif\r
-\r
-extern ISzAlloc g_Alloc;\r
-extern ISzAlloc g_BigAlloc;\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/* Alloc.h -- Memory allocation functions
+2018-02-19 : Igor Pavlov : Public domain */
+
+#ifndef __COMMON_ALLOC_H
+#define __COMMON_ALLOC_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+void *MyAlloc(size_t size);
+void MyFree(void *address);
+
+#ifdef _WIN32
+
+void SetLargePageSize();
+
+void *MidAlloc(size_t size);
+void MidFree(void *address);
+void *BigAlloc(size_t size);
+void BigFree(void *address);
+
+#else
+
+#define MidAlloc(size) MyAlloc(size)
+#define MidFree(address) MyFree(address)
+#define BigAlloc(size) MyAlloc(size)
+#define BigFree(address) MyFree(address)
+
+#endif
+
+extern const ISzAlloc g_Alloc;
+extern const ISzAlloc g_BigAlloc;
+extern const ISzAlloc g_MidAlloc;
+extern const ISzAlloc g_AlignedAlloc;
+
+
+typedef struct
+{
+  ISzAlloc vt;
+  ISzAllocPtr baseAlloc;
+  unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */
+  size_t offset;         /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */
+} CAlignOffsetAlloc;
+
+void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p);
+
+
+EXTERN_C_END
+
+#endif
similarity index 96%
rename from deps/lzma-16.04/C/Bra.h
rename to deps/libchdr/deps/lzma-19.00/include/Bra.h
index aba8dce..855e37a 100644 (file)
@@ -1,64 +1,64 @@
-/* Bra.h -- Branch converters for executables\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __BRA_H\r
-#define __BRA_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-/*\r
-These functions convert relative addresses to absolute addresses\r
-in CALL instructions to increase the compression ratio.\r
-  \r
-  In:\r
-    data     - data buffer\r
-    size     - size of data\r
-    ip       - current virtual Instruction Pinter (IP) value\r
-    state    - state variable for x86 converter\r
-    encoding - 0 (for decoding), 1 (for encoding)\r
-  \r
-  Out:\r
-    state    - state variable for x86 converter\r
-\r
-  Returns:\r
-    The number of processed bytes. If you call these functions with multiple calls,\r
-    you must start next call with first byte after block of processed bytes.\r
-  \r
-  Type   Endian  Alignment  LookAhead\r
-  \r
-  x86    little      1          4\r
-  ARMT   little      2          2\r
-  ARM    little      4          0\r
-  PPC     big        4          0\r
-  SPARC   big        4          0\r
-  IA64   little     16          0\r
-\r
-  size must be >= Alignment + LookAhead, if it's not last block.\r
-  If (size < Alignment + LookAhead), converter returns 0.\r
-\r
-  Example:\r
-\r
-    UInt32 ip = 0;\r
-    for ()\r
-    {\r
-      ; size must be >= Alignment + LookAhead, if it's not last block\r
-      SizeT processed = Convert(data, size, ip, 1);\r
-      data += processed;\r
-      size -= processed;\r
-      ip += processed;\r
-    }\r
-*/\r
-\r
-#define x86_Convert_Init(state) { state = 0; }\r
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);\r
-SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
-SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
-SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
-SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
-SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/* Bra.h -- Branch converters for executables
+2013-01-18 : Igor Pavlov : Public domain */
+
+#ifndef __BRA_H
+#define __BRA_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+/*
+These functions convert relative addresses to absolute addresses
+in CALL instructions to increase the compression ratio.
+  
+  In:
+    data     - data buffer
+    size     - size of data
+    ip       - current virtual Instruction Pinter (IP) value
+    state    - state variable for x86 converter
+    encoding - 0 (for decoding), 1 (for encoding)
+  
+  Out:
+    state    - state variable for x86 converter
+
+  Returns:
+    The number of processed bytes. If you call these functions with multiple calls,
+    you must start next call with first byte after block of processed bytes.
+  
+  Type   Endian  Alignment  LookAhead
+  
+  x86    little      1          4
+  ARMT   little      2          2
+  ARM    little      4          0
+  PPC     big        4          0
+  SPARC   big        4          0
+  IA64   little     16          0
+
+  size must be >= Alignment + LookAhead, if it's not last block.
+  If (size < Alignment + LookAhead), converter returns 0.
+
+  Example:
+
+    UInt32 ip = 0;
+    for ()
+    {
+      ; size must be >= Alignment + LookAhead, if it's not last block
+      SizeT processed = Convert(data, size, ip, 1);
+      data += processed;
+      size -= processed;
+      ip += processed;
+    }
+*/
+
+#define x86_Convert_Init(state) { state = 0; }
+SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
+SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+
+EXTERN_C_END
+
+#endif
similarity index 89%
rename from deps/lzma-16.04/C/Compiler.h
rename to deps/libchdr/deps/lzma-19.00/include/Compiler.h
index de8fab3..0cc409d 100644 (file)
@@ -1,32 +1,33 @@
-/* Compiler.h\r
-2015-08-02 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_COMPILER_H\r
-#define __7Z_COMPILER_H\r
-\r
-#ifdef _MSC_VER\r
-\r
-  #ifdef UNDER_CE\r
-    #define RPC_NO_WINDOWS_H\r
-    /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */\r
-    #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union\r
-    #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int\r
-  #endif\r
-\r
-  #if _MSC_VER >= 1300\r
-    #pragma warning(disable : 4996) // This function or variable may be unsafe\r
-  #else\r
-    #pragma warning(disable : 4511) // copy constructor could not be generated\r
-    #pragma warning(disable : 4512) // assignment operator could not be generated\r
-    #pragma warning(disable : 4514) // unreferenced inline function has been removed\r
-    #pragma warning(disable : 4702) // unreachable code\r
-    #pragma warning(disable : 4710) // not inlined\r
-    #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information\r
-  #endif\r
-\r
-#endif\r
-\r
-#define UNUSED_VAR(x) (void)x;\r
-/* #define UNUSED_VAR(x) x=x; */\r
-\r
-#endif\r
+/* Compiler.h
+2017-04-03 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_COMPILER_H
+#define __7Z_COMPILER_H
+
+#ifdef _MSC_VER
+
+  #ifdef UNDER_CE
+    #define RPC_NO_WINDOWS_H
+    /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */
+    #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
+    #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int
+  #endif
+
+  #if _MSC_VER >= 1300
+    #pragma warning(disable : 4996) // This function or variable may be unsafe
+  #else
+    #pragma warning(disable : 4511) // copy constructor could not be generated
+    #pragma warning(disable : 4512) // assignment operator could not be generated
+    #pragma warning(disable : 4514) // unreferenced inline function has been removed
+    #pragma warning(disable : 4702) // unreachable code
+    #pragma warning(disable : 4710) // not inlined
+    #pragma warning(disable : 4714) // function marked as __forceinline not inlined
+    #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information
+  #endif
+
+#endif
+
+#define UNUSED_VAR(x) (void)x;
+/* #define UNUSED_VAR(x) x=x; */
+
+#endif
similarity index 61%
rename from deps/lzma-16.04/C/CpuArch.h
rename to deps/libchdr/deps/lzma-19.00/include/CpuArch.h
index ef6083c..bd42938 100644 (file)
-/* CpuArch.h -- CPU specific code\r
-2016-06-09: Igor Pavlov : Public domain */\r
-\r
-#ifndef __CPU_ARCH_H\r
-#define __CPU_ARCH_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-/*\r
-MY_CPU_LE means that CPU is LITTLE ENDIAN.\r
-MY_CPU_BE means that CPU is BIG ENDIAN.\r
-If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.\r
-\r
-MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.\r
-*/\r
-\r
-#if defined(_M_X64) \\r
-   || defined(_M_AMD64) \\r
-   || defined(__x86_64__) \\r
-   || defined(__AMD64__) \\r
-   || defined(__amd64__)\r
-  #define MY_CPU_AMD64\r
-#endif\r
-\r
-#if defined(MY_CPU_AMD64) \\r
-    || defined(_M_IA64) \\r
-    || defined(__AARCH64EL__) \\r
-    || defined(__AARCH64EB__)\r
-  #define MY_CPU_64BIT\r
-#endif\r
-\r
-#if defined(_M_IX86) || defined(__i386__)\r
-#define MY_CPU_X86\r
-#endif\r
-\r
-#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)\r
-#define MY_CPU_X86_OR_AMD64\r
-#endif\r
-\r
-#if defined(MY_CPU_X86) \\r
-    || defined(_M_ARM) \\r
-    || defined(__ARMEL__) \\r
-    || defined(__THUMBEL__) \\r
-    || defined(__ARMEB__) \\r
-    || defined(__THUMBEB__)\r
-  #define MY_CPU_32BIT\r
-#endif\r
-\r
-#if defined(_WIN32) && defined(_M_ARM)\r
-#define MY_CPU_ARM_LE\r
-#endif\r
-\r
-#if defined(_WIN32) && defined(_M_IA64)\r
-#define MY_CPU_IA64_LE\r
-#endif\r
-\r
-#if defined(MY_CPU_X86_OR_AMD64) \\r
-    || defined(MY_CPU_ARM_LE) \\r
-    || defined(MY_CPU_IA64_LE) \\r
-    || defined(__LITTLE_ENDIAN__) \\r
-    || defined(__ARMEL__) \\r
-    || defined(__THUMBEL__) \\r
-    || defined(__AARCH64EL__) \\r
-    || defined(__MIPSEL__) \\r
-    || defined(__MIPSEL) \\r
-    || defined(_MIPSEL) \\r
-    || defined(__BFIN__) \\r
-    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))\r
-  #define MY_CPU_LE\r
-#endif\r
-\r
-#if defined(__BIG_ENDIAN__) \\r
-    || defined(__ARMEB__) \\r
-    || defined(__THUMBEB__) \\r
-    || defined(__AARCH64EB__) \\r
-    || defined(__MIPSEB__) \\r
-    || defined(__MIPSEB) \\r
-    || defined(_MIPSEB) \\r
-    || defined(__m68k__) \\r
-    || defined(__s390__) \\r
-    || defined(__s390x__) \\r
-    || defined(__zarch__) \\r
-    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))\r
-  #define MY_CPU_BE\r
-#endif\r
-\r
-#if defined(MY_CPU_LE) && defined(MY_CPU_BE)\r
-Stop_Compiling_Bad_Endian\r
-#endif\r
-\r
-\r
-#ifdef MY_CPU_LE\r
-  #if defined(MY_CPU_X86_OR_AMD64) \\r
-      /* || defined(__AARCH64EL__) */\r
-    #define MY_CPU_LE_UNALIGN\r
-  #endif\r
-#endif\r
-\r
-\r
-#ifdef MY_CPU_LE_UNALIGN\r
-\r
-#define GetUi16(p) (*(const UInt16 *)(const void *)(p))\r
-#define GetUi32(p) (*(const UInt32 *)(const void *)(p))\r
-#define GetUi64(p) (*(const UInt64 *)(const void *)(p))\r
-\r
-#define SetUi16(p, v) { *(UInt16 *)(p) = (v); }\r
-#define SetUi32(p, v) { *(UInt32 *)(p) = (v); }\r
-#define SetUi64(p, v) { *(UInt64 *)(p) = (v); }\r
-\r
-#else\r
-\r
-#define GetUi16(p) ( (UInt16) ( \\r
-             ((const Byte *)(p))[0] | \\r
-    ((UInt16)((const Byte *)(p))[1] << 8) ))\r
-\r
-#define GetUi32(p) ( \\r
-             ((const Byte *)(p))[0]        | \\r
-    ((UInt32)((const Byte *)(p))[1] <<  8) | \\r
-    ((UInt32)((const Byte *)(p))[2] << 16) | \\r
-    ((UInt32)((const Byte *)(p))[3] << 24))\r
-\r
-#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))\r
-\r
-#define SetUi16(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \\r
-    _ppp_[0] = (Byte)_vvv_; \\r
-    _ppp_[1] = (Byte)(_vvv_ >> 8); }\r
-\r
-#define SetUi32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \\r
-    _ppp_[0] = (Byte)_vvv_; \\r
-    _ppp_[1] = (Byte)(_vvv_ >> 8); \\r
-    _ppp_[2] = (Byte)(_vvv_ >> 16); \\r
-    _ppp_[3] = (Byte)(_vvv_ >> 24); }\r
-\r
-#define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v); \\r
-    SetUi32(_ppp2_    , (UInt32)_vvv2_); \\r
-    SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)); }\r
-\r
-#endif\r
-\r
-\r
-#if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300)\r
-\r
-/* Note: we use bswap instruction, that is unsupported in 386 cpu */\r
-\r
-#include <stdlib.h>\r
-\r
-#pragma intrinsic(_byteswap_ulong)\r
-#pragma intrinsic(_byteswap_uint64)\r
-#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))\r
-#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))\r
-\r
-#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = _byteswap_ulong(v)\r
-\r
-#elif defined(MY_CPU_LE_UNALIGN) && defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))\r
-\r
-#define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const Byte *)(p))\r
-#define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const Byte *)(p))\r
-\r
-#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)\r
-\r
-#else\r
-\r
-#define GetBe32(p) ( \\r
-    ((UInt32)((const Byte *)(p))[0] << 24) | \\r
-    ((UInt32)((const Byte *)(p))[1] << 16) | \\r
-    ((UInt32)((const Byte *)(p))[2] <<  8) | \\r
-             ((const Byte *)(p))[3] )\r
-\r
-#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))\r
-\r
-#define SetBe32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \\r
-    _ppp_[0] = (Byte)(_vvv_ >> 24); \\r
-    _ppp_[1] = (Byte)(_vvv_ >> 16); \\r
-    _ppp_[2] = (Byte)(_vvv_ >> 8); \\r
-    _ppp_[3] = (Byte)_vvv_; }\r
-\r
-#endif\r
-\r
-\r
-#define GetBe16(p) ( (UInt16) ( \\r
-    ((UInt16)((const Byte *)(p))[0] << 8) | \\r
-             ((const Byte *)(p))[1] ))\r
-\r
-\r
-\r
-#ifdef MY_CPU_X86_OR_AMD64\r
-\r
-typedef struct\r
-{\r
-  UInt32 maxFunc;\r
-  UInt32 vendor[3];\r
-  UInt32 ver;\r
-  UInt32 b;\r
-  UInt32 c;\r
-  UInt32 d;\r
-} Cx86cpuid;\r
-\r
-enum\r
-{\r
-  CPU_FIRM_INTEL,\r
-  CPU_FIRM_AMD,\r
-  CPU_FIRM_VIA\r
-};\r
-\r
-void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d);\r
-\r
-Bool x86cpuid_CheckAndRead(Cx86cpuid *p);\r
-int x86cpuid_GetFirm(const Cx86cpuid *p);\r
-\r
-#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))\r
-#define x86cpuid_GetModel(ver)  (((ver >> 12) &  0xF0) | ((ver >> 4) & 0xF))\r
-#define x86cpuid_GetStepping(ver) (ver & 0xF)\r
-\r
-Bool CPU_Is_InOrder();\r
-Bool CPU_Is_Aes_Supported();\r
-\r
-#endif\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/* CpuArch.h -- CPU specific code
+2018-02-18 : Igor Pavlov : Public domain */
+
+#ifndef __CPU_ARCH_H
+#define __CPU_ARCH_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+/*
+MY_CPU_LE means that CPU is LITTLE ENDIAN.
+MY_CPU_BE means that CPU is BIG ENDIAN.
+If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.
+
+MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
+*/
+
+#if  defined(_M_X64) \
+  || defined(_M_AMD64) \
+  || defined(__x86_64__) \
+  || defined(__AMD64__) \
+  || defined(__amd64__)
+  #define MY_CPU_AMD64
+  #ifdef __ILP32__
+    #define MY_CPU_NAME "x32"
+  #else
+    #define MY_CPU_NAME "x64"
+  #endif
+  #define MY_CPU_64BIT
+#endif
+
+
+#if  defined(_M_IX86) \
+  || defined(__i386__)
+  #define MY_CPU_X86
+  #define MY_CPU_NAME "x86"
+  #define MY_CPU_32BIT
+#endif
+
+
+#if  defined(_M_ARM64) \
+  || defined(__AARCH64EL__) \
+  || defined(__AARCH64EB__) \
+  || defined(__aarch64__)
+  #define MY_CPU_ARM64
+  #define MY_CPU_NAME "arm64"
+  #define MY_CPU_64BIT
+#endif
+
+
+#if  defined(_M_ARM) \
+  || defined(_M_ARM_NT) \
+  || defined(_M_ARMT) \
+  || defined(__arm__) \
+  || defined(__thumb__) \
+  || defined(__ARMEL__) \
+  || defined(__ARMEB__) \
+  || defined(__THUMBEL__) \
+  || defined(__THUMBEB__)
+  #define MY_CPU_ARM
+  #define MY_CPU_NAME "arm"
+  #define MY_CPU_32BIT
+#endif
+
+
+#if  defined(_M_IA64) \
+  || defined(__ia64__)
+  #define MY_CPU_IA64
+  #define MY_CPU_NAME "ia64"
+  #define MY_CPU_64BIT
+#endif
+
+
+#if  defined(__mips64) \
+  || defined(__mips64__) \
+  || (defined(__mips) && (__mips == 64 || __mips == 4 || __mips == 3))
+  #define MY_CPU_NAME "mips64"
+  #define MY_CPU_64BIT
+#elif defined(__mips__)
+  #define MY_CPU_NAME "mips"
+  /* #define MY_CPU_32BIT */
+#endif
+
+
+#if  defined(__ppc64__) \
+  || defined(__powerpc64__)
+  #ifdef __ILP32__
+    #define MY_CPU_NAME "ppc64-32"
+  #else
+    #define MY_CPU_NAME "ppc64"
+  #endif
+  #define MY_CPU_64BIT
+#elif defined(__ppc__) \
+  || defined(__powerpc__)
+  #define MY_CPU_NAME "ppc"
+  #define MY_CPU_32BIT
+#endif
+
+
+#if  defined(__sparc64__)
+  #define MY_CPU_NAME "sparc64"
+  #define MY_CPU_64BIT
+#elif defined(__sparc__)
+  #define MY_CPU_NAME "sparc"
+  /* #define MY_CPU_32BIT */
+#endif
+
+
+#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
+#define MY_CPU_X86_OR_AMD64
+#endif
+
+
+#ifdef _WIN32
+
+  #ifdef MY_CPU_ARM
+  #define MY_CPU_ARM_LE
+  #endif
+
+  #ifdef MY_CPU_ARM64
+  #define MY_CPU_ARM64_LE
+  #endif
+
+  #ifdef _M_IA64
+  #define MY_CPU_IA64_LE
+  #endif
+
+#endif
+
+
+#if defined(MY_CPU_X86_OR_AMD64) \
+    || defined(MY_CPU_ARM_LE) \
+    || defined(MY_CPU_ARM64_LE) \
+    || defined(MY_CPU_IA64_LE) \
+    || defined(__LITTLE_ENDIAN__) \
+    || defined(__ARMEL__) \
+    || defined(__THUMBEL__) \
+    || defined(__AARCH64EL__) \
+    || defined(__MIPSEL__) \
+    || defined(__MIPSEL) \
+    || defined(_MIPSEL) \
+    || defined(__BFIN__) \
+    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
+  #define MY_CPU_LE
+#endif
+
+#if defined(__BIG_ENDIAN__) \
+    || defined(__ARMEB__) \
+    || defined(__THUMBEB__) \
+    || defined(__AARCH64EB__) \
+    || defined(__MIPSEB__) \
+    || defined(__MIPSEB) \
+    || defined(_MIPSEB) \
+    || defined(__m68k__) \
+    || defined(__s390__) \
+    || defined(__s390x__) \
+    || defined(__zarch__) \
+    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
+  #define MY_CPU_BE
+#endif
+
+
+#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
+  #error Stop_Compiling_Bad_Endian
+#endif
+
+
+#if defined(MY_CPU_32BIT) && defined(MY_CPU_64BIT)
+  #error Stop_Compiling_Bad_32_64_BIT
+#endif
+
+
+#ifndef MY_CPU_NAME
+  #ifdef MY_CPU_LE
+    #define MY_CPU_NAME "LE"
+  #elif defined(MY_CPU_BE)
+    #define MY_CPU_NAME "BE"
+  #else
+    /*
+    #define MY_CPU_NAME ""
+    */
+  #endif
+#endif
+
+
+
+
+
+#ifdef MY_CPU_LE
+  #if defined(MY_CPU_X86_OR_AMD64) \
+      || defined(MY_CPU_ARM64) \
+      || defined(__ARM_FEATURE_UNALIGNED)
+    #define MY_CPU_LE_UNALIGN
+  #endif
+#endif
+
+
+#ifdef MY_CPU_LE_UNALIGN
+
+#define GetUi16(p) (*(const UInt16 *)(const void *)(p))
+#define GetUi32(p) (*(const UInt32 *)(const void *)(p))
+#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
+
+#define SetUi16(p, v) { *(UInt16 *)(p) = (v); }
+#define SetUi32(p, v) { *(UInt32 *)(p) = (v); }
+#define SetUi64(p, v) { *(UInt64 *)(p) = (v); }
+
+#else
+
+#define GetUi16(p) ( (UInt16) ( \
+             ((const Byte *)(p))[0] | \
+    ((UInt16)((const Byte *)(p))[1] << 8) ))
+
+#define GetUi32(p) ( \
+             ((const Byte *)(p))[0]        | \
+    ((UInt32)((const Byte *)(p))[1] <<  8) | \
+    ((UInt32)((const Byte *)(p))[2] << 16) | \
+    ((UInt32)((const Byte *)(p))[3] << 24))
+
+#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
+
+#define SetUi16(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
+    _ppp_[0] = (Byte)_vvv_; \
+    _ppp_[1] = (Byte)(_vvv_ >> 8); }
+
+#define SetUi32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
+    _ppp_[0] = (Byte)_vvv_; \
+    _ppp_[1] = (Byte)(_vvv_ >> 8); \
+    _ppp_[2] = (Byte)(_vvv_ >> 16); \
+    _ppp_[3] = (Byte)(_vvv_ >> 24); }
+
+#define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v); \
+    SetUi32(_ppp2_    , (UInt32)_vvv2_); \
+    SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)); }
+
+#endif
+
+#ifdef __has_builtin
+  #define MY__has_builtin(x) __has_builtin(x)
+#else
+  #define MY__has_builtin(x) 0
+#endif
+
+#if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300)
+
+/* Note: we use bswap instruction, that is unsupported in 386 cpu */
+
+#include <stdlib.h>
+
+#pragma intrinsic(_byteswap_ushort)
+#pragma intrinsic(_byteswap_ulong)
+#pragma intrinsic(_byteswap_uint64)
+
+/* #define GetBe16(p) _byteswap_ushort(*(const UInt16 *)(const Byte *)(p)) */
+#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
+#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
+
+#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = _byteswap_ulong(v)
+
+#elif defined(MY_CPU_LE_UNALIGN) && ( \
+       (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) \
+    || (defined(__clang__) && MY__has_builtin(__builtin_bswap16)) )
+
+/* #define GetBe16(p) __builtin_bswap16(*(const UInt16 *)(const Byte *)(p)) */
+#define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const Byte *)(p))
+#define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const Byte *)(p))
+
+#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)
+
+#else
+
+#define GetBe32(p) ( \
+    ((UInt32)((const Byte *)(p))[0] << 24) | \
+    ((UInt32)((const Byte *)(p))[1] << 16) | \
+    ((UInt32)((const Byte *)(p))[2] <<  8) | \
+             ((const Byte *)(p))[3] )
+
+#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
+
+#define SetBe32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
+    _ppp_[0] = (Byte)(_vvv_ >> 24); \
+    _ppp_[1] = (Byte)(_vvv_ >> 16); \
+    _ppp_[2] = (Byte)(_vvv_ >> 8); \
+    _ppp_[3] = (Byte)_vvv_; }
+
+#endif
+
+
+#ifndef GetBe16
+
+#define GetBe16(p) ( (UInt16) ( \
+    ((UInt16)((const Byte *)(p))[0] << 8) | \
+             ((const Byte *)(p))[1] ))
+
+#endif
+
+
+
+#ifdef MY_CPU_X86_OR_AMD64
+
+typedef struct
+{
+  UInt32 maxFunc;
+  UInt32 vendor[3];
+  UInt32 ver;
+  UInt32 b;
+  UInt32 c;
+  UInt32 d;
+} Cx86cpuid;
+
+enum
+{
+  CPU_FIRM_INTEL,
+  CPU_FIRM_AMD,
+  CPU_FIRM_VIA
+};
+
+void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d);
+
+BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p);
+int x86cpuid_GetFirm(const Cx86cpuid *p);
+
+#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))
+#define x86cpuid_GetModel(ver)  (((ver >> 12) &  0xF0) | ((ver >> 4) & 0xF))
+#define x86cpuid_GetStepping(ver) (ver & 0xF)
+
+BoolInt CPU_Is_InOrder();
+BoolInt CPU_Is_Aes_Supported();
+BoolInt CPU_IsSupported_PageGB();
+
+#endif
+
+EXTERN_C_END
+
+#endif
similarity index 95%
rename from deps/lzma-16.04/C/Delta.h
rename to deps/libchdr/deps/lzma-19.00/include/Delta.h
index e59d5a2..2fa54ad 100644 (file)
@@ -1,19 +1,19 @@
-/* Delta.h -- Delta converter\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __DELTA_H\r
-#define __DELTA_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define DELTA_STATE_SIZE 256\r
-\r
-void Delta_Init(Byte *state);\r
-void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size);\r
-void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/* Delta.h -- Delta converter
+2013-01-18 : Igor Pavlov : Public domain */
+
+#ifndef __DELTA_H
+#define __DELTA_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+#define DELTA_STATE_SIZE 256
+
+void Delta_Init(Byte *state);
+void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size);
+void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size);
+
+EXTERN_C_END
+
+#endif
similarity index 91%
rename from deps/lzma-16.04/C/LzFind.h
rename to deps/libchdr/deps/lzma-19.00/include/LzFind.h
index 2ff6673..42c13be 100644 (file)
-/* LzFind.h -- Match finder for LZ algorithms\r
-2015-10-15 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __LZ_FIND_H\r
-#define __LZ_FIND_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-typedef UInt32 CLzRef;\r
-\r
-typedef struct _CMatchFinder\r
-{\r
-  Byte *buffer;\r
-  UInt32 pos;\r
-  UInt32 posLimit;\r
-  UInt32 streamPos;\r
-  UInt32 lenLimit;\r
-\r
-  UInt32 cyclicBufferPos;\r
-  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r
-\r
-  Byte streamEndWasReached;\r
-  Byte btMode;\r
-  Byte bigHash;\r
-  Byte directInput;\r
-\r
-  UInt32 matchMaxLen;\r
-  CLzRef *hash;\r
-  CLzRef *son;\r
-  UInt32 hashMask;\r
-  UInt32 cutValue;\r
-\r
-  Byte *bufferBase;\r
-  ISeqInStream *stream;\r
-  \r
-  UInt32 blockSize;\r
-  UInt32 keepSizeBefore;\r
-  UInt32 keepSizeAfter;\r
-\r
-  UInt32 numHashBytes;\r
-  size_t directInputRem;\r
-  UInt32 historySize;\r
-  UInt32 fixedHashSize;\r
-  UInt32 hashSizeSum;\r
-  SRes result;\r
-  UInt32 crc[256];\r
-  size_t numRefs;\r
-} CMatchFinder;\r
-\r
-#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r
-\r
-#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r
-\r
-#define Inline_MatchFinder_IsFinishedOK(p) \\r
-    ((p)->streamEndWasReached \\r
-        && (p)->streamPos == (p)->pos \\r
-        && (!(p)->directInput || (p)->directInputRem == 0))\r
-      \r
-int MatchFinder_NeedMove(CMatchFinder *p);\r
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r
-void MatchFinder_MoveBlock(CMatchFinder *p);\r
-void MatchFinder_ReadIfRequired(CMatchFinder *p);\r
-\r
-void MatchFinder_Construct(CMatchFinder *p);\r
-\r
-/* Conditions:\r
-     historySize <= 3 GB\r
-     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r
-*/\r
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r
-    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r
-    ISzAlloc *alloc);\r
-void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems);\r
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r
-\r
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r
-    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r
-    UInt32 *distances, UInt32 maxLen);\r
-\r
-/*\r
-Conditions:\r
-  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r
-  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r
-*/\r
-\r
-typedef void (*Mf_Init_Func)(void *object);\r
-typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r
-typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r
-typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r
-typedef void (*Mf_Skip_Func)(void *object, UInt32);\r
-\r
-typedef struct _IMatchFinder\r
-{\r
-  Mf_Init_Func Init;\r
-  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r
-  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r
-  Mf_GetMatches_Func GetMatches;\r
-  Mf_Skip_Func Skip;\r
-} IMatchFinder;\r
-\r
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r
-\r
-void MatchFinder_Init_2(CMatchFinder *p, int readData);\r
-void MatchFinder_Init(CMatchFinder *p);\r
-\r
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r
-\r
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/* LzFind.h -- Match finder for LZ algorithms
+2017-06-10 : Igor Pavlov : Public domain */
+
+#ifndef __LZ_FIND_H
+#define __LZ_FIND_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+typedef UInt32 CLzRef;
+
+typedef struct _CMatchFinder
+{
+  Byte *buffer;
+  UInt32 pos;
+  UInt32 posLimit;
+  UInt32 streamPos;
+  UInt32 lenLimit;
+
+  UInt32 cyclicBufferPos;
+  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
+
+  Byte streamEndWasReached;
+  Byte btMode;
+  Byte bigHash;
+  Byte directInput;
+
+  UInt32 matchMaxLen;
+  CLzRef *hash;
+  CLzRef *son;
+  UInt32 hashMask;
+  UInt32 cutValue;
+
+  Byte *bufferBase;
+  ISeqInStream *stream;
+  
+  UInt32 blockSize;
+  UInt32 keepSizeBefore;
+  UInt32 keepSizeAfter;
+
+  UInt32 numHashBytes;
+  size_t directInputRem;
+  UInt32 historySize;
+  UInt32 fixedHashSize;
+  UInt32 hashSizeSum;
+  SRes result;
+  UInt32 crc[256];
+  size_t numRefs;
+
+  UInt64 expectedDataSize;
+} CMatchFinder;
+
+#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
+
+#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
+
+#define Inline_MatchFinder_IsFinishedOK(p) \
+    ((p)->streamEndWasReached \
+        && (p)->streamPos == (p)->pos \
+        && (!(p)->directInput || (p)->directInputRem == 0))
+      
+int MatchFinder_NeedMove(CMatchFinder *p);
+Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
+void MatchFinder_MoveBlock(CMatchFinder *p);
+void MatchFinder_ReadIfRequired(CMatchFinder *p);
+
+void MatchFinder_Construct(CMatchFinder *p);
+
+/* Conditions:
+     historySize <= 3 GB
+     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
+*/
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
+    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
+    ISzAllocPtr alloc);
+void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc);
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems);
+void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
+
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
+    UInt32 *distances, UInt32 maxLen);
+
+/*
+Conditions:
+  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
+  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
+*/
+
+typedef void (*Mf_Init_Func)(void *object);
+typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
+typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
+typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
+typedef void (*Mf_Skip_Func)(void *object, UInt32);
+
+typedef struct _IMatchFinder
+{
+  Mf_Init_Func Init;
+  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
+  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
+  Mf_GetMatches_Func GetMatches;
+  Mf_Skip_Func Skip;
+} IMatchFinder;
+
+void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
+
+void MatchFinder_Init_LowHash(CMatchFinder *p);
+void MatchFinder_Init_HighHash(CMatchFinder *p);
+void MatchFinder_Init_3(CMatchFinder *p, int readData);
+void MatchFinder_Init(CMatchFinder *p);
+
+UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
+UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
+
+void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
+void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
+
+EXTERN_C_END
+
+#endif
similarity index 96%
rename from deps/lzma-16.04/C/LzHash.h
rename to deps/libchdr/deps/lzma-19.00/include/LzHash.h
index 2191444..e7c9423 100644 (file)
@@ -1,57 +1,57 @@
-/* LzHash.h -- HASH functions for LZ algorithms\r
-2015-04-12 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __LZ_HASH_H\r
-#define __LZ_HASH_H\r
-\r
-#define kHash2Size (1 << 10)\r
-#define kHash3Size (1 << 16)\r
-#define kHash4Size (1 << 20)\r
-\r
-#define kFix3HashSize (kHash2Size)\r
-#define kFix4HashSize (kHash2Size + kHash3Size)\r
-#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r
-\r
-#define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8);\r
-\r
-#define HASH3_CALC { \\r
-  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  h2 = temp & (kHash2Size - 1); \\r
-  hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r
-\r
-#define HASH4_CALC { \\r
-  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  h2 = temp & (kHash2Size - 1); \\r
-  temp ^= ((UInt32)cur[2] << 8); \\r
-  h3 = temp & (kHash3Size - 1); \\r
-  hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r
-\r
-#define HASH5_CALC { \\r
-  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  h2 = temp & (kHash2Size - 1); \\r
-  temp ^= ((UInt32)cur[2] << 8); \\r
-  h3 = temp & (kHash3Size - 1); \\r
-  temp ^= (p->crc[cur[3]] << 5); \\r
-  h4 = temp & (kHash4Size - 1); \\r
-  hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; }\r
-\r
-/* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r
-#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r
-\r
-\r
-#define MT_HASH2_CALC \\r
-  h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r
-\r
-#define MT_HASH3_CALC { \\r
-  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  h2 = temp & (kHash2Size - 1); \\r
-  h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r
-\r
-#define MT_HASH4_CALC { \\r
-  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  h2 = temp & (kHash2Size - 1); \\r
-  temp ^= ((UInt32)cur[2] << 8); \\r
-  h3 = temp & (kHash3Size - 1); \\r
-  h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r
-\r
-#endif\r
+/* LzHash.h -- HASH functions for LZ algorithms
+2015-04-12 : Igor Pavlov : Public domain */
+
+#ifndef __LZ_HASH_H
+#define __LZ_HASH_H
+
+#define kHash2Size (1 << 10)
+#define kHash3Size (1 << 16)
+#define kHash4Size (1 << 20)
+
+#define kFix3HashSize (kHash2Size)
+#define kFix4HashSize (kHash2Size + kHash3Size)
+#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
+
+#define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8);
+
+#define HASH3_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  h2 = temp & (kHash2Size - 1); \
+  hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
+
+#define HASH4_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  h2 = temp & (kHash2Size - 1); \
+  temp ^= ((UInt32)cur[2] << 8); \
+  h3 = temp & (kHash3Size - 1); \
+  hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
+
+#define HASH5_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  h2 = temp & (kHash2Size - 1); \
+  temp ^= ((UInt32)cur[2] << 8); \
+  h3 = temp & (kHash3Size - 1); \
+  temp ^= (p->crc[cur[3]] << 5); \
+  h4 = temp & (kHash4Size - 1); \
+  hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; }
+
+/* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
+#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
+
+
+#define MT_HASH2_CALC \
+  h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
+
+#define MT_HASH3_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  h2 = temp & (kHash2Size - 1); \
+  h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
+
+#define MT_HASH4_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  h2 = temp & (kHash2Size - 1); \
+  temp ^= ((UInt32)cur[2] << 8); \
+  h3 = temp & (kHash3Size - 1); \
+  h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
+
+#endif
similarity index 96%
rename from deps/lzma-16.04/C/Lzma86.h
rename to deps/libchdr/deps/lzma-19.00/include/Lzma86.h
index 83057e5..bebed5c 100644 (file)
-/* Lzma86.h -- LZMA + x86 (BCJ) Filter\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __LZMA86_H\r
-#define __LZMA86_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define LZMA86_SIZE_OFFSET (1 + 5)\r
-#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\r
-\r
-/*\r
-It's an example for LZMA + x86 Filter use.\r
-You can use .lzma86 extension, if you write that stream to file.\r
-.lzma86 header adds one additional byte to standard .lzma header.\r
-.lzma86 header (14 bytes):\r
-  Offset Size  Description\r
-    0     1    = 0 - no filter, pure LZMA\r
-               = 1 - x86 filter + LZMA\r
-    1     1    lc, lp and pb in encoded form\r
-    2     4    dictSize (little endian)\r
-    6     8    uncompressed size (little endian)\r
-\r
-\r
-Lzma86_Encode\r
--------------\r
-level - compression level: 0 <= level <= 9, the default value for "level" is 5.\r
-\r
-dictSize - The dictionary size in bytes. The maximum value is\r
-        128 MB = (1 << 27) bytes for 32-bit version\r
-          1 GB = (1 << 30) bytes for 64-bit version\r
-     The default value is 16 MB = (1 << 24) bytes, for level = 5.\r
-     It's recommended to use the dictionary that is larger than 4 KB and\r
-     that can be calculated as (1 << N) or (3 << N) sizes.\r
-     For better compression ratio dictSize must be >= inSize.\r
-\r
-filterMode:\r
-    SZ_FILTER_NO   - no Filter\r
-    SZ_FILTER_YES  - x86 Filter\r
-    SZ_FILTER_AUTO - it tries both alternatives to select best.\r
-              Encoder will use 2 or 3 passes:\r
-              2 passes when FILTER_NO provides better compression.\r
-              3 passes when FILTER_YES provides better compression.\r
-\r
-Lzma86Encode allocates Data with MyAlloc functions.\r
-RAM Requirements for compressing:\r
-  RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize\r
-      filterMode     FilterBlockSize\r
-     SZ_FILTER_NO         0\r
-     SZ_FILTER_YES      inSize\r
-     SZ_FILTER_AUTO     inSize\r
-\r
-\r
-Return code:\r
-  SZ_OK               - OK\r
-  SZ_ERROR_MEM        - Memory allocation error\r
-  SZ_ERROR_PARAM      - Incorrect paramater\r
-  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r
-  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r
-*/\r
-\r
-enum ESzFilterMode\r
-{\r
-  SZ_FILTER_NO,\r
-  SZ_FILTER_YES,\r
-  SZ_FILTER_AUTO\r
-};\r
-\r
-SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r
-    int level, UInt32 dictSize, int filterMode);\r
-\r
-\r
-/*\r
-Lzma86_GetUnpackSize:\r
-  In:\r
-    src      - input data\r
-    srcLen   - input data size\r
-  Out:\r
-    unpackSize - size of uncompressed stream\r
-  Return code:\r
-    SZ_OK               - OK\r
-    SZ_ERROR_INPUT_EOF  - Error in headers\r
-*/\r
-\r
-SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);\r
-\r
-/*\r
-Lzma86_Decode:\r
-  In:\r
-    dest     - output data\r
-    destLen  - output data size\r
-    src      - input data\r
-    srcLen   - input data size\r
-  Out:\r
-    destLen  - processed output size\r
-    srcLen   - processed input size\r
-  Return code:\r
-    SZ_OK           - OK\r
-    SZ_ERROR_DATA  - Data error\r
-    SZ_ERROR_MEM   - Memory allocation error\r
-    SZ_ERROR_UNSUPPORTED - unsupported file\r
-    SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer\r
-*/\r
-\r
-SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/* Lzma86.h -- LZMA + x86 (BCJ) Filter
+2013-01-18 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA86_H
+#define __LZMA86_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+#define LZMA86_SIZE_OFFSET (1 + 5)
+#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)
+
+/*
+It's an example for LZMA + x86 Filter use.
+You can use .lzma86 extension, if you write that stream to file.
+.lzma86 header adds one additional byte to standard .lzma header.
+.lzma86 header (14 bytes):
+  Offset Size  Description
+    0     1    = 0 - no filter, pure LZMA
+               = 1 - x86 filter + LZMA
+    1     1    lc, lp and pb in encoded form
+    2     4    dictSize (little endian)
+    6     8    uncompressed size (little endian)
+
+
+Lzma86_Encode
+-------------
+level - compression level: 0 <= level <= 9, the default value for "level" is 5.
+
+dictSize - The dictionary size in bytes. The maximum value is
+        128 MB = (1 << 27) bytes for 32-bit version
+          1 GB = (1 << 30) bytes for 64-bit version
+     The default value is 16 MB = (1 << 24) bytes, for level = 5.
+     It's recommended to use the dictionary that is larger than 4 KB and
+     that can be calculated as (1 << N) or (3 << N) sizes.
+     For better compression ratio dictSize must be >= inSize.
+
+filterMode:
+    SZ_FILTER_NO   - no Filter
+    SZ_FILTER_YES  - x86 Filter
+    SZ_FILTER_AUTO - it tries both alternatives to select best.
+              Encoder will use 2 or 3 passes:
+              2 passes when FILTER_NO provides better compression.
+              3 passes when FILTER_YES provides better compression.
+
+Lzma86Encode allocates Data with MyAlloc functions.
+RAM Requirements for compressing:
+  RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize
+      filterMode     FilterBlockSize
+     SZ_FILTER_NO         0
+     SZ_FILTER_YES      inSize
+     SZ_FILTER_AUTO     inSize
+
+
+Return code:
+  SZ_OK               - OK
+  SZ_ERROR_MEM        - Memory allocation error
+  SZ_ERROR_PARAM      - Incorrect paramater
+  SZ_ERROR_OUTPUT_EOF - output buffer overflow
+  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
+*/
+
+enum ESzFilterMode
+{
+  SZ_FILTER_NO,
+  SZ_FILTER_YES,
+  SZ_FILTER_AUTO
+};
+
+SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
+    int level, UInt32 dictSize, int filterMode);
+
+
+/*
+Lzma86_GetUnpackSize:
+  In:
+    src      - input data
+    srcLen   - input data size
+  Out:
+    unpackSize - size of uncompressed stream
+  Return code:
+    SZ_OK               - OK
+    SZ_ERROR_INPUT_EOF  - Error in headers
+*/
+
+SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);
+
+/*
+Lzma86_Decode:
+  In:
+    dest     - output data
+    destLen  - output data size
+    src      - input data
+    srcLen   - input data size
+  Out:
+    destLen  - processed output size
+    srcLen   - processed input size
+  Return code:
+    SZ_OK           - OK
+    SZ_ERROR_DATA  - Data error
+    SZ_ERROR_MEM   - Memory allocation error
+    SZ_ERROR_UNSUPPORTED - unsupported file
+    SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer
+*/
+
+SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);
+
+EXTERN_C_END
+
+#endif
similarity index 85%
rename from deps/lzma-16.04/C/LzmaDec.h
rename to deps/libchdr/deps/lzma-19.00/include/LzmaDec.h
index 2633abe..1f0927a 100644 (file)
-/* LzmaDec.h -- LZMA Decoder\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __LZMA_DEC_H\r
-#define __LZMA_DEC_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-/* #define _LZMA_PROB32 */\r
-/* _LZMA_PROB32 can increase the speed on some CPUs,\r
-   but memory usage for CLzmaDec::probs will be doubled in that case */\r
-\r
-#ifdef _LZMA_PROB32\r
-#define CLzmaProb UInt32\r
-#else\r
-#define CLzmaProb UInt16\r
-#endif\r
-\r
-\r
-/* ---------- LZMA Properties ---------- */\r
-\r
-#define LZMA_PROPS_SIZE 5\r
-\r
-typedef struct _CLzmaProps\r
-{\r
-  unsigned lc, lp, pb;\r
-  UInt32 dicSize;\r
-} CLzmaProps;\r
-\r
-/* LzmaProps_Decode - decodes properties\r
-Returns:\r
-  SZ_OK\r
-  SZ_ERROR_UNSUPPORTED - Unsupported properties\r
-*/\r
-\r
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);\r
-\r
-\r
-/* ---------- LZMA Decoder state ---------- */\r
-\r
-/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.\r
-   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */\r
-\r
-#define LZMA_REQUIRED_INPUT_MAX 20\r
-\r
-typedef struct\r
-{\r
-  CLzmaProps prop;\r
-  CLzmaProb *probs;\r
-  Byte *dic;\r
-  const Byte *buf;\r
-  UInt32 range, code;\r
-  SizeT dicPos;\r
-  SizeT dicBufSize;\r
-  UInt32 processedPos;\r
-  UInt32 checkDicSize;\r
-  unsigned state;\r
-  UInt32 reps[4];\r
-  unsigned remainLen;\r
-  int needFlush;\r
-  int needInitState;\r
-  UInt32 numProbs;\r
-  unsigned tempBufSize;\r
-  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];\r
-} CLzmaDec;\r
-\r
-#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }\r
-\r
-void LzmaDec_Init(CLzmaDec *p);\r
-\r
-/* There are two types of LZMA streams:\r
-     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.\r
-     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */\r
-\r
-typedef enum\r
-{\r
-  LZMA_FINISH_ANY,   /* finish at any point */\r
-  LZMA_FINISH_END    /* block must be finished at the end */\r
-} ELzmaFinishMode;\r
-\r
-/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!\r
-\r
-   You must use LZMA_FINISH_END, when you know that current output buffer\r
-   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.\r
-\r
-   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,\r
-   and output value of destLen will be less than output buffer size limit.\r
-   You can check status result also.\r
-\r
-   You can use multiple checks to test data integrity after full decompression:\r
-     1) Check Result and "status" variable.\r
-     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r
-     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.\r
-        You must use correct finish mode in that case. */\r
-\r
-typedef enum\r
-{\r
-  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */\r
-  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\r
-  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */\r
-  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */\r
-  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */\r
-} ELzmaStatus;\r
-\r
-/* ELzmaStatus is used only as output value for function call */\r
-\r
-\r
-/* ---------- Interfaces ---------- */\r
-\r
-/* There are 3 levels of interfaces:\r
-     1) Dictionary Interface\r
-     2) Buffer Interface\r
-     3) One Call Interface\r
-   You can select any of these interfaces, but don't mix functions from different\r
-   groups for same object. */\r
-\r
-\r
-/* There are two variants to allocate state for Dictionary Interface:\r
-     1) LzmaDec_Allocate / LzmaDec_Free\r
-     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs\r
-   You can use variant 2, if you set dictionary buffer manually.\r
-   For Buffer Interface you must always use variant 1.\r
-\r
-LzmaDec_Allocate* can return:\r
-  SZ_OK\r
-  SZ_ERROR_MEM         - Memory allocation error\r
-  SZ_ERROR_UNSUPPORTED - Unsupported properties\r
-*/\r
-   \r
-SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);\r
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);\r
-\r
-SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);\r
-void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);\r
-\r
-/* ---------- Dictionary Interface ---------- */\r
-\r
-/* You can use it, if you want to eliminate the overhead for data copying from\r
-   dictionary to some other external buffer.\r
-   You must work with CLzmaDec variables directly in this interface.\r
-\r
-   STEPS:\r
-     LzmaDec_Constr()\r
-     LzmaDec_Allocate()\r
-     for (each new stream)\r
-     {\r
-       LzmaDec_Init()\r
-       while (it needs more decompression)\r
-       {\r
-         LzmaDec_DecodeToDic()\r
-         use data from CLzmaDec::dic and update CLzmaDec::dicPos\r
-       }\r
-     }\r
-     LzmaDec_Free()\r
-*/\r
-\r
-/* LzmaDec_DecodeToDic\r
-   \r
-   The decoding to internal dictionary buffer (CLzmaDec::dic).\r
-   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!\r
-\r
-finishMode:\r
-  It has meaning only if the decoding reaches output limit (dicLimit).\r
-  LZMA_FINISH_ANY - Decode just dicLimit bytes.\r
-  LZMA_FINISH_END - Stream must be finished after dicLimit.\r
-\r
-Returns:\r
-  SZ_OK\r
-    status:\r
-      LZMA_STATUS_FINISHED_WITH_MARK\r
-      LZMA_STATUS_NOT_FINISHED\r
-      LZMA_STATUS_NEEDS_MORE_INPUT\r
-      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r
-  SZ_ERROR_DATA - Data error\r
-*/\r
-\r
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\r
-    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r
-\r
-\r
-/* ---------- Buffer Interface ---------- */\r
-\r
-/* It's zlib-like interface.\r
-   See LzmaDec_DecodeToDic description for information about STEPS and return results,\r
-   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need\r
-   to work with CLzmaDec variables manually.\r
-\r
-finishMode:\r
-  It has meaning only if the decoding reaches output limit (*destLen).\r
-  LZMA_FINISH_ANY - Decode just destLen bytes.\r
-  LZMA_FINISH_END - Stream must be finished after (*destLen).\r
-*/\r
-\r
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,\r
-    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r
-\r
-\r
-/* ---------- One Call Interface ---------- */\r
-\r
-/* LzmaDecode\r
-\r
-finishMode:\r
-  It has meaning only if the decoding reaches output limit (*destLen).\r
-  LZMA_FINISH_ANY - Decode just destLen bytes.\r
-  LZMA_FINISH_END - Stream must be finished after (*destLen).\r
-\r
-Returns:\r
-  SZ_OK\r
-    status:\r
-      LZMA_STATUS_FINISHED_WITH_MARK\r
-      LZMA_STATUS_NOT_FINISHED\r
-      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r
-  SZ_ERROR_DATA - Data error\r
-  SZ_ERROR_MEM  - Memory allocation error\r
-  SZ_ERROR_UNSUPPORTED - Unsupported properties\r
-  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r
-*/\r
-\r
-SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r
-    ELzmaStatus *status, ISzAlloc *alloc);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/* LzmaDec.h -- LZMA Decoder
+2018-04-21 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA_DEC_H
+#define __LZMA_DEC_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+/* #define _LZMA_PROB32 */
+/* _LZMA_PROB32 can increase the speed on some CPUs,
+   but memory usage for CLzmaDec::probs will be doubled in that case */
+
+typedef
+#ifdef _LZMA_PROB32
+  UInt32
+#else
+  UInt16
+#endif
+  CLzmaProb;
+
+
+/* ---------- LZMA Properties ---------- */
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct _CLzmaProps
+{
+  Byte lc;
+  Byte lp;
+  Byte pb;
+  Byte _pad_;
+  UInt32 dicSize;
+} CLzmaProps;
+
+/* LzmaProps_Decode - decodes properties
+Returns:
+  SZ_OK
+  SZ_ERROR_UNSUPPORTED - Unsupported properties
+*/
+
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
+
+
+/* ---------- LZMA Decoder state ---------- */
+
+/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
+   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
+
+#define LZMA_REQUIRED_INPUT_MAX 20
+
+typedef struct
+{
+  /* Don't change this structure. ASM code can use it. */
+  CLzmaProps prop;
+  CLzmaProb *probs;
+  CLzmaProb *probs_1664;
+  Byte *dic;
+  SizeT dicBufSize;
+  SizeT dicPos;
+  const Byte *buf;
+  UInt32 range;
+  UInt32 code;
+  UInt32 processedPos;
+  UInt32 checkDicSize;
+  UInt32 reps[4];
+  UInt32 state;
+  UInt32 remainLen;
+
+  UInt32 numProbs;
+  unsigned tempBufSize;
+  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
+} CLzmaDec;
+
+#define LzmaDec_Construct(p) { (p)->dic = NULL; (p)->probs = NULL; }
+
+void LzmaDec_Init(CLzmaDec *p);
+
+/* There are two types of LZMA streams:
+     - Stream with end mark. That end mark adds about 6 bytes to compressed size.
+     - Stream without end mark. You must know exact uncompressed size to decompress such stream. */
+
+typedef enum
+{
+  LZMA_FINISH_ANY,   /* finish at any point */
+  LZMA_FINISH_END    /* block must be finished at the end */
+} ELzmaFinishMode;
+
+/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
+
+   You must use LZMA_FINISH_END, when you know that current output buffer
+   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
+
+   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
+   and output value of destLen will be less than output buffer size limit.
+   You can check status result also.
+
+   You can use multiple checks to test data integrity after full decompression:
+     1) Check Result and "status" variable.
+     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
+     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
+        You must use correct finish mode in that case. */
+
+typedef enum
+{
+  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */
+  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */
+  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */
+  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */
+  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */
+} ELzmaStatus;
+
+/* ELzmaStatus is used only as output value for function call */
+
+
+/* ---------- Interfaces ---------- */
+
+/* There are 3 levels of interfaces:
+     1) Dictionary Interface
+     2) Buffer Interface
+     3) One Call Interface
+   You can select any of these interfaces, but don't mix functions from different
+   groups for same object. */
+
+
+/* There are two variants to allocate state for Dictionary Interface:
+     1) LzmaDec_Allocate / LzmaDec_Free
+     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
+   You can use variant 2, if you set dictionary buffer manually.
+   For Buffer Interface you must always use variant 1.
+
+LzmaDec_Allocate* can return:
+  SZ_OK
+  SZ_ERROR_MEM         - Memory allocation error
+  SZ_ERROR_UNSUPPORTED - Unsupported properties
+*/
+   
+SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc);
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc);
+
+SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc);
+void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc);
+
+/* ---------- Dictionary Interface ---------- */
+
+/* You can use it, if you want to eliminate the overhead for data copying from
+   dictionary to some other external buffer.
+   You must work with CLzmaDec variables directly in this interface.
+
+   STEPS:
+     LzmaDec_Construct()
+     LzmaDec_Allocate()
+     for (each new stream)
+     {
+       LzmaDec_Init()
+       while (it needs more decompression)
+       {
+         LzmaDec_DecodeToDic()
+         use data from CLzmaDec::dic and update CLzmaDec::dicPos
+       }
+     }
+     LzmaDec_Free()
+*/
+
+/* LzmaDec_DecodeToDic
+   
+   The decoding to internal dictionary buffer (CLzmaDec::dic).
+   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
+
+finishMode:
+  It has meaning only if the decoding reaches output limit (dicLimit).
+  LZMA_FINISH_ANY - Decode just dicLimit bytes.
+  LZMA_FINISH_END - Stream must be finished after dicLimit.
+
+Returns:
+  SZ_OK
+    status:
+      LZMA_STATUS_FINISHED_WITH_MARK
+      LZMA_STATUS_NOT_FINISHED
+      LZMA_STATUS_NEEDS_MORE_INPUT
+      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+  SZ_ERROR_DATA - Data error
+*/
+
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
+    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- Buffer Interface ---------- */
+
+/* It's zlib-like interface.
+   See LzmaDec_DecodeToDic description for information about STEPS and return results,
+   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
+   to work with CLzmaDec variables manually.
+
+finishMode:
+  It has meaning only if the decoding reaches output limit (*destLen).
+  LZMA_FINISH_ANY - Decode just destLen bytes.
+  LZMA_FINISH_END - Stream must be finished after (*destLen).
+*/
+
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
+    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- One Call Interface ---------- */
+
+/* LzmaDecode
+
+finishMode:
+  It has meaning only if the decoding reaches output limit (*destLen).
+  LZMA_FINISH_ANY - Decode just destLen bytes.
+  LZMA_FINISH_END - Stream must be finished after (*destLen).
+
+Returns:
+  SZ_OK
+    status:
+      LZMA_STATUS_FINISHED_WITH_MARK
+      LZMA_STATUS_NOT_FINISHED
+      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+  SZ_ERROR_DATA - Data error
+  SZ_ERROR_MEM  - Memory allocation error
+  SZ_ERROR_UNSUPPORTED - Unsupported properties
+  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
+*/
+
+SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+    ELzmaStatus *status, ISzAllocPtr alloc);
+
+EXTERN_C_END
+
+#endif
similarity index 61%
rename from deps/lzma-16.04/C/LzmaEnc.h
rename to deps/libchdr/deps/lzma-19.00/include/LzmaEnc.h
index c2806b4..9194ee5 100644 (file)
@@ -1,78 +1,76 @@
-/*  LzmaEnc.h -- LZMA Encoder\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __LZMA_ENC_H\r
-#define __LZMA_ENC_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define LZMA_PROPS_SIZE 5\r
-\r
-typedef struct _CLzmaEncProps\r
-{\r
-  int level;       /*  0 <= level <= 9 */\r
-  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version\r
-                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version\r
-                       default = (1 << 24) */\r
-  UInt64 reduceSize; /* estimated size of data that will be compressed. default = 0xFFFFFFFF.\r
-                        Encoder uses this value to reduce dictionary size */\r
-  int lc;          /* 0 <= lc <= 8, default = 3 */\r
-  int lp;          /* 0 <= lp <= 4, default = 0 */\r
-  int pb;          /* 0 <= pb <= 4, default = 2 */\r
-  int algo;        /* 0 - fast, 1 - normal, default = 1 */\r
-  int fb;          /* 5 <= fb <= 273, default = 32 */\r
-  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */\r
-  int numHashBytes; /* 2, 3 or 4, default = 4 */\r
-  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */\r
-  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */\r
-  int numThreads;  /* 1 or 2, default = 2 */\r
-} CLzmaEncProps;\r
-\r
-void LzmaEncProps_Init(CLzmaEncProps *p);\r
-void LzmaEncProps_Normalize(CLzmaEncProps *p);\r
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);\r
-\r
-\r
-/* ---------- CLzmaEncHandle Interface ---------- */\r
-\r
-/* LzmaEnc_* functions can return the following exit codes:\r
-Returns:\r
-  SZ_OK           - OK\r
-  SZ_ERROR_MEM    - Memory allocation error\r
-  SZ_ERROR_PARAM  - Incorrect paramater in props\r
-  SZ_ERROR_WRITE  - Write callback error.\r
-  SZ_ERROR_PROGRESS - some break from progress callback\r
-  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)\r
-*/\r
-\r
-typedef void * CLzmaEncHandle;\r
-\r
-CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);\r
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);\r
-SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);\r
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);\r
-SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,\r
-    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r
-SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
-    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r
-\r
-/* ---------- One Call Interface ---------- */\r
-\r
-/* LzmaEncode\r
-Return code:\r
-  SZ_OK               - OK\r
-  SZ_ERROR_MEM        - Memory allocation error\r
-  SZ_ERROR_PARAM      - Incorrect paramater\r
-  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r
-  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r
-*/\r
-\r
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
-    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r
-    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/*  LzmaEnc.h -- LZMA Encoder
+2017-07-27 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA_ENC_H
+#define __LZMA_ENC_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct _CLzmaEncProps
+{
+  int level;       /* 0 <= level <= 9 */
+  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
+                      (1 << 12) <= dictSize <= (3 << 29) for 64-bit version
+                      default = (1 << 24) */
+  int lc;          /* 0 <= lc <= 8, default = 3 */
+  int lp;          /* 0 <= lp <= 4, default = 0 */
+  int pb;          /* 0 <= pb <= 4, default = 2 */
+  int algo;        /* 0 - fast, 1 - normal, default = 1 */
+  int fb;          /* 5 <= fb <= 273, default = 32 */
+  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
+  int numHashBytes; /* 2, 3 or 4, default = 4 */
+  UInt32 mc;       /* 1 <= mc <= (1 << 30), default = 32 */
+  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
+  int numThreads;  /* 1 or 2, default = 2 */
+
+  UInt64 reduceSize; /* estimated size of data that will be compressed. default = (UInt64)(Int64)-1.
+                        Encoder uses this value to reduce dictionary size */
+} CLzmaEncProps;
+
+void LzmaEncProps_Init(CLzmaEncProps *p);
+void LzmaEncProps_Normalize(CLzmaEncProps *p);
+UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
+
+
+/* ---------- CLzmaEncHandle Interface ---------- */
+
+/* LzmaEnc* functions can return the following exit codes:
+SRes:
+  SZ_OK           - OK
+  SZ_ERROR_MEM    - Memory allocation error
+  SZ_ERROR_PARAM  - Incorrect paramater in props
+  SZ_ERROR_WRITE  - ISeqOutStream write callback error
+  SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output
+  SZ_ERROR_PROGRESS - some break from progress callback
+  SZ_ERROR_THREAD - error in multithreading functions (only for Mt version)
+*/
+
+typedef void * CLzmaEncHandle;
+
+CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc);
+void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig);
+
+SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
+void LzmaEnc_SetDataSize(CLzmaEncHandle p, UInt64 expectedDataSiize);
+SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
+unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle p);
+
+SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
+    ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
+SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+    int writeEndMark, ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
+
+
+/* ---------- One Call Interface ---------- */
+
+SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+    ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
+
+EXTERN_C_END
+
+#endif
similarity index 97%
rename from deps/lzma-16.04/C/LzmaLib.h
rename to deps/libchdr/deps/lzma-19.00/include/LzmaLib.h
index 5c35e53..88fa87d 100644 (file)
-/* LzmaLib.h -- LZMA library interface\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __LZMA_LIB_H\r
-#define __LZMA_LIB_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define MY_STDAPI int MY_STD_CALL\r
-\r
-#define LZMA_PROPS_SIZE 5\r
-\r
-/*\r
-RAM requirements for LZMA:\r
-  for compression:   (dictSize * 11.5 + 6 MB) + state_size\r
-  for decompression: dictSize + state_size\r
-    state_size = (4 + (1.5 << (lc + lp))) KB\r
-    by default (lc=3, lp=0), state_size = 16 KB.\r
-\r
-LZMA properties (5 bytes) format\r
-    Offset Size  Description\r
-      0     1    lc, lp and pb in encoded form.\r
-      1     4    dictSize (little endian).\r
-*/\r
-\r
-/*\r
-LzmaCompress\r
-------------\r
-\r
-outPropsSize -\r
-     In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r
-     Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r
-\r
-  LZMA Encoder will use defult values for any parameter, if it is\r
-  -1  for any from: level, loc, lp, pb, fb, numThreads\r
-   0  for dictSize\r
-  \r
-level - compression level: 0 <= level <= 9;\r
-\r
-  level dictSize algo  fb\r
-    0:    16 KB   0    32\r
-    1:    64 KB   0    32\r
-    2:   256 KB   0    32\r
-    3:     1 MB   0    32\r
-    4:     4 MB   0    32\r
-    5:    16 MB   1    32\r
-    6:    32 MB   1    32\r
-    7+:   64 MB   1    64\r
\r
-  The default value for "level" is 5.\r
-\r
-  algo = 0 means fast method\r
-  algo = 1 means normal method\r
-\r
-dictSize - The dictionary size in bytes. The maximum value is\r
-        128 MB = (1 << 27) bytes for 32-bit version\r
-          1 GB = (1 << 30) bytes for 64-bit version\r
-     The default value is 16 MB = (1 << 24) bytes.\r
-     It's recommended to use the dictionary that is larger than 4 KB and\r
-     that can be calculated as (1 << N) or (3 << N) sizes.\r
-\r
-lc - The number of literal context bits (high bits of previous literal).\r
-     It can be in the range from 0 to 8. The default value is 3.\r
-     Sometimes lc=4 gives the gain for big files.\r
-\r
-lp - The number of literal pos bits (low bits of current position for literals).\r
-     It can be in the range from 0 to 4. The default value is 0.\r
-     The lp switch is intended for periodical data when the period is equal to 2^lp.\r
-     For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's\r
-     better to set lc=0, if you change lp switch.\r
-\r
-pb - The number of pos bits (low bits of current position).\r
-     It can be in the range from 0 to 4. The default value is 2.\r
-     The pb switch is intended for periodical data when the period is equal 2^pb.\r
-\r
-fb - Word size (the number of fast bytes).\r
-     It can be in the range from 5 to 273. The default value is 32.\r
-     Usually, a big number gives a little bit better compression ratio and\r
-     slower compression process.\r
-\r
-numThreads - The number of thereads. 1 or 2. The default value is 2.\r
-     Fast mode (algo = 0) can use only 1 thread.\r
-\r
-Out:\r
-  destLen  - processed output size\r
-Returns:\r
-  SZ_OK               - OK\r
-  SZ_ERROR_MEM        - Memory allocation error\r
-  SZ_ERROR_PARAM      - Incorrect paramater\r
-  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r
-  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r
-*/\r
-\r
-MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,\r
-  unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */\r
-  int level,      /* 0 <= level <= 9, default = 5 */\r
-  unsigned dictSize,  /* default = (1 << 24) */\r
-  int lc,        /* 0 <= lc <= 8, default = 3  */\r
-  int lp,        /* 0 <= lp <= 4, default = 0  */\r
-  int pb,        /* 0 <= pb <= 4, default = 2  */\r
-  int fb,        /* 5 <= fb <= 273, default = 32 */\r
-  int numThreads /* 1 or 2, default = 2 */\r
-  );\r
-\r
-/*\r
-LzmaUncompress\r
---------------\r
-In:\r
-  dest     - output data\r
-  destLen  - output data size\r
-  src      - input data\r
-  srcLen   - input data size\r
-Out:\r
-  destLen  - processed output size\r
-  srcLen   - processed input size\r
-Returns:\r
-  SZ_OK                - OK\r
-  SZ_ERROR_DATA        - Data error\r
-  SZ_ERROR_MEM         - Memory allocation arror\r
-  SZ_ERROR_UNSUPPORTED - Unsupported properties\r
-  SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)\r
-*/\r
-\r
-MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,\r
-  const unsigned char *props, size_t propsSize);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/* LzmaLib.h -- LZMA library interface
+2013-01-18 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA_LIB_H
+#define __LZMA_LIB_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+#define MY_STDAPI int MY_STD_CALL
+
+#define LZMA_PROPS_SIZE 5
+
+/*
+RAM requirements for LZMA:
+  for compression:   (dictSize * 11.5 + 6 MB) + state_size
+  for decompression: dictSize + state_size
+    state_size = (4 + (1.5 << (lc + lp))) KB
+    by default (lc=3, lp=0), state_size = 16 KB.
+
+LZMA properties (5 bytes) format
+    Offset Size  Description
+      0     1    lc, lp and pb in encoded form.
+      1     4    dictSize (little endian).
+*/
+
+/*
+LzmaCompress
+------------
+
+outPropsSize -
+     In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
+     Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
+
+  LZMA Encoder will use defult values for any parameter, if it is
+  -1  for any from: level, loc, lp, pb, fb, numThreads
+   0  for dictSize
+  
+level - compression level: 0 <= level <= 9;
+
+  level dictSize algo  fb
+    0:    16 KB   0    32
+    1:    64 KB   0    32
+    2:   256 KB   0    32
+    3:     1 MB   0    32
+    4:     4 MB   0    32
+    5:    16 MB   1    32
+    6:    32 MB   1    32
+    7+:   64 MB   1    64
+  The default value for "level" is 5.
+
+  algo = 0 means fast method
+  algo = 1 means normal method
+
+dictSize - The dictionary size in bytes. The maximum value is
+        128 MB = (1 << 27) bytes for 32-bit version
+          1 GB = (1 << 30) bytes for 64-bit version
+     The default value is 16 MB = (1 << 24) bytes.
+     It's recommended to use the dictionary that is larger than 4 KB and
+     that can be calculated as (1 << N) or (3 << N) sizes.
+
+lc - The number of literal context bits (high bits of previous literal).
+     It can be in the range from 0 to 8. The default value is 3.
+     Sometimes lc=4 gives the gain for big files.
+
+lp - The number of literal pos bits (low bits of current position for literals).
+     It can be in the range from 0 to 4. The default value is 0.
+     The lp switch is intended for periodical data when the period is equal to 2^lp.
+     For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
+     better to set lc=0, if you change lp switch.
+
+pb - The number of pos bits (low bits of current position).
+     It can be in the range from 0 to 4. The default value is 2.
+     The pb switch is intended for periodical data when the period is equal 2^pb.
+
+fb - Word size (the number of fast bytes).
+     It can be in the range from 5 to 273. The default value is 32.
+     Usually, a big number gives a little bit better compression ratio and
+     slower compression process.
+
+numThreads - The number of thereads. 1 or 2. The default value is 2.
+     Fast mode (algo = 0) can use only 1 thread.
+
+Out:
+  destLen  - processed output size
+Returns:
+  SZ_OK               - OK
+  SZ_ERROR_MEM        - Memory allocation error
+  SZ_ERROR_PARAM      - Incorrect paramater
+  SZ_ERROR_OUTPUT_EOF - output buffer overflow
+  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
+*/
+
+MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
+  unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
+  int level,      /* 0 <= level <= 9, default = 5 */
+  unsigned dictSize,  /* default = (1 << 24) */
+  int lc,        /* 0 <= lc <= 8, default = 3  */
+  int lp,        /* 0 <= lp <= 4, default = 0  */
+  int pb,        /* 0 <= pb <= 4, default = 2  */
+  int fb,        /* 5 <= fb <= 273, default = 32 */
+  int numThreads /* 1 or 2, default = 2 */
+  );
+
+/*
+LzmaUncompress
+--------------
+In:
+  dest     - output data
+  destLen  - output data size
+  src      - input data
+  srcLen   - input data size
+Out:
+  destLen  - processed output size
+  srcLen   - processed input size
+Returns:
+  SZ_OK                - OK
+  SZ_ERROR_DATA        - Data error
+  SZ_ERROR_MEM         - Memory allocation arror
+  SZ_ERROR_UNSUPPORTED - Unsupported properties
+  SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)
+*/
+
+MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
+  const unsigned char *props, size_t propsSize);
+
+EXTERN_C_END
+
+#endif
similarity index 94%
rename from deps/lzma-16.04/C/Precomp.h
rename to deps/libchdr/deps/lzma-19.00/include/Precomp.h
index edb5814..e8ff8b4 100644 (file)
@@ -1,10 +1,10 @@
-/* Precomp.h -- StdAfx\r
-2013-11-12 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_PRECOMP_H\r
-#define __7Z_PRECOMP_H\r
-\r
-#include "Compiler.h"\r
-/* #include "7zTypes.h" */\r
-\r
-#endif\r
+/* Precomp.h -- StdAfx
+2013-11-12 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_PRECOMP_H
+#define __7Z_PRECOMP_H
+
+#include "Compiler.h"
+/* #include "7zTypes.h" */
+
+#endif
similarity index 94%
rename from deps/lzma-16.04/C/Sort.h
rename to deps/libchdr/deps/lzma-19.00/include/Sort.h
index 7209d78..2e2963a 100644 (file)
@@ -1,18 +1,18 @@
-/* Sort.h -- Sort functions\r
-2014-04-05 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_SORT_H\r
-#define __7Z_SORT_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-void HeapSort(UInt32 *p, size_t size);\r
-void HeapSort64(UInt64 *p, size_t size);\r
-\r
-/* void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size); */\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
+/* Sort.h -- Sort functions
+2014-04-05 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_SORT_H
+#define __7Z_SORT_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+void HeapSort(UInt32 *p, size_t size);
+void HeapSort64(UInt64 *p, size_t size);
+
+/* void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size); */
+
+EXTERN_C_END
+
+#endif
similarity index 75%
rename from deps/lzma-16.04/DOC/lzma-history.txt
rename to deps/libchdr/deps/lzma-19.00/lzma-history.txt
index 603a9e8..48ee748 100644 (file)
-HISTORY of the LZMA SDK\r
------------------------\r
-\r
-16.04          2016-10-04\r
--------------------------\r
-- The bug was fixed in DllSecur.c.\r
-\r
-\r
-16.03          2016-09-28\r
--------------------------\r
-- SFX modules now use some protection against DLL preloading attack.\r
-- Some bugs in 7z code were fixed.\r
-\r
-\r
-16.02          2016-05-21\r
--------------------------\r
-- The BUG in 16.00 - 16.01 was fixed:\r
-  Split Handler (SplitHandler.cpp) returned incorrect \r
-  total size value (kpidSize) for split archives.\r
-\r
-\r
-16.01          2016-05-19\r
--------------------------      \r
-- Some internal changes to reduce the number of compiler warnings.\r
-\r
-\r
-16.00          2016-05-10\r
--------------------------      \r
-- Some bugs were fixed.\r
-\r
-\r
-15.12          2015-11-19\r
--------------------------      \r
-- The BUG in C version of 7z decoder was fixed:\r
-  7zDec.c : SzDecodeLzma2()\r
-  7z decoder could mistakenly report about decoding error for some 7z archives\r
-  that use LZMA2 compression method.\r
-  The probability to get that mistaken decoding error report was about \r
-  one error per 16384 solid blocks for solid blocks larger than 16 KB (compressed size). \r
-- The BUG (in 9.26-15.11) in C version of 7z decoder was fixed:\r
-  7zArcIn.c : SzReadHeader2()\r
-  7z decoder worked incorrectly for 7z archives that contain \r
-  empty solid blocks, that can be placed to 7z archive, if some file is \r
-  unavailable for reading during archive creation.\r
-\r
-\r
-15.09 beta     2015-10-16\r
--------------------------      \r
-- The BUG in LZMA / LZMA2 encoding code was fixed.\r
-  The BUG in LzFind.c::MatchFinder_ReadBlock() function.\r
-  If input data size is larger than (4 GiB - dictionary_size),\r
-  the following code worked incorrectly:\r
-  -  LZMA : LzmaEnc_MemEncode(), LzmaEncode() : LZMA encoding functions \r
-     for compressing from memory to memory. \r
-     That BUG is not related to LZMA encoder version that works via streams.\r
-  -  LZMA2 : multi-threaded version of LZMA2 encoder worked incorrectly, if \r
-     default value of chunk size (CLzma2EncProps::blockSize) is changed \r
-     to value larger than (4 GiB - dictionary_size).\r
-\r
-\r
-9.38 beta      2015-01-03\r
--------------------------      \r
-- The BUG in 9.31-9.37 was fixed:\r
-  IArchiveGetRawProps interface was disabled for 7z archives.\r
-- The BUG in 9.26-9.36 was fixed:\r
-  Some code in CPP\7zip\Archive\7z\ worked correctly only under Windows.\r
-\r
-\r
-9.36 beta      2014-12-26\r
--------------------------      \r
-- The BUG in command line version was fixed:\r
-  7-Zip created temporary archive in current folder during update archive\r
-  operation, if -w{Path} switch was not specified. \r
-  The fixed 7-Zip creates temporary archive in folder that contains updated archive.\r
-- The BUG in 9.33-9.35 was fixed:\r
-  7-Zip silently ignored file reading errors during 7z or gz archive creation,\r
-  and the created archive contained only part of file that was read before error.\r
-  The fixed 7-Zip stops archive creation and it reports about error.\r
-\r
-\r
-9.35 beta      2014-12-07\r
--------------------------      \r
-- 7zr.exe now support AES encryption.\r
-- SFX mudules were added to LZMA SDK\r
-- Some bugs were fixed.\r
-\r
-\r
-9.21 beta      2011-04-11\r
--------------------------      \r
-- New class FString for file names at file systems.\r
-- Speed optimization in CRC code for big-endian CPUs.\r
-- The BUG in Lzma2Dec.c was fixed:\r
-    Lzma2Decode function didn't work.\r
-\r
-\r
-9.18 beta      2010-11-02\r
--------------------------      \r
-- New small SFX module for installers (SfxSetup).\r
-\r
-\r
-9.12 beta      2010-03-24\r
--------------------------\r
-- The BUG in LZMA SDK 9.* was fixed: LZMA2 codec didn't work,\r
-  if more than 10 threads were used (or more than 20 threads in some modes).\r
-\r
-\r
-9.11 beta      2010-03-15\r
--------------------------\r
-- PPMd compression method support\r
-   \r
-\r
-9.09           2009-12-12\r
--------------------------\r
-- The bug was fixed:\r
-   Utf16_To_Utf8 funstions in UTFConvert.cpp and 7zMain.c\r
-   incorrectly converted surrogate characters (the code >= 0x10000) to UTF-8.\r
-- Some bugs were fixed\r
-\r
-\r
-9.06           2009-08-17\r
--------------------------\r
-- Some changes in ANSI-C 7z Decoder interfaces.\r
-\r
-\r
-9.04           2009-05-30\r
--------------------------\r
-- LZMA2 compression method support\r
-- xz format support\r
-\r
-\r
-4.65           2009-02-03\r
--------------------------\r
-- Some minor fixes\r
-\r
-\r
-4.63           2008-12-31\r
--------------------------\r
-- Some minor fixes\r
-\r
-\r
-4.61 beta      2008-11-23\r
--------------------------\r
-- The bug in ANSI-C LZMA Decoder was fixed:\r
-    If encoded stream was corrupted, decoder could access memory \r
-    outside of allocated range.\r
-- Some changes in ANSI-C 7z Decoder interfaces.\r
-- LZMA SDK is placed in the public domain.\r
-\r
-\r
-4.60 beta      2008-08-19\r
--------------------------\r
-- Some minor fixes.\r
-\r
-\r
-4.59 beta      2008-08-13\r
--------------------------\r
-- The bug was fixed:\r
-    LZMA Encoder in fast compression mode could access memory outside of \r
-    allocated range in some rare cases.\r
-\r
-\r
-4.58 beta      2008-05-05\r
--------------------------\r
-- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r
-- ANSI-C LZMA Encoder was included to LZMA SDK.\r
-- C++ LZMA code now is just wrapper over ANSI-C code.\r
-\r
-\r
-4.57           2007-12-12\r
--------------------------\r
-- Speed optimizations in Ã‘++ LZMA Decoder. \r
-- Small changes for more compatibility with some C/C++ compilers.\r
-\r
-\r
-4.49 beta      2007-07-05\r
--------------------------\r
-- .7z ANSI-C Decoder:\r
-     - now it supports BCJ and BCJ2 filters\r
-     - now it supports files larger than 4 GB.\r
-     - now it supports "Last Write Time" field for files.\r
-- C++ code for .7z archives compressing/decompressing from 7-zip \r
-  was included to LZMA SDK.\r
-  \r
-\r
-4.43           2006-06-04\r
--------------------------\r
-- Small changes for more compatibility with some C/C++ compilers.\r
-  \r
-\r
-4.42           2006-05-15\r
--------------------------\r
-- Small changes in .h files in ANSI-C version.\r
-  \r
-\r
-4.39 beta      2006-04-14\r
--------------------------\r
-- The bug in versions 4.33b:4.38b was fixed:\r
-  C++ version of LZMA encoder could not correctly compress \r
-  files larger than 2 GB with HC4 match finder (-mfhc4).\r
-  \r
-\r
-4.37 beta      2005-04-06\r
--------------------------\r
-- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r
-\r
-\r
-4.35 beta      2005-03-02\r
--------------------------\r
-- The bug was fixed in C++ version of LZMA Decoder:\r
-    If encoded stream was corrupted, decoder could access memory \r
-    outside of allocated range.\r
-\r
-\r
-4.34 beta      2006-02-27\r
--------------------------\r
-- Compressing speed and memory requirements for compressing were increased\r
-- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r
-\r
-\r
-4.32           2005-12-09\r
--------------------------\r
-- Java version of LZMA SDK was included\r
-\r
-\r
-4.30           2005-11-20\r
--------------------------\r
-- Compression ratio was improved in -a2 mode\r
-- Speed optimizations for compressing in -a2 mode\r
-- -fb switch now supports values up to 273\r
-- The bug in 7z_C (7zIn.c) was fixed:\r
-  It used Alloc/Free functions from different memory pools.\r
-  So if program used two memory pools, it worked incorrectly.\r
-- 7z_C: .7z format supporting was improved\r
-- LZMA# SDK (C#.NET version) was included\r
-\r
-\r
-4.27 (Updated) 2005-09-21\r
--------------------------\r
-- Some GUIDs/interfaces in C++ were changed.\r
- IStream.h:\r
-   ISequentialInStream::Read now works as old ReadPart\r
-   ISequentialOutStream::Write now works as old WritePart\r
-\r
-\r
-4.27           2005-08-07\r
--------------------------\r
-- The bug in LzmaDecodeSize.c was fixed:\r
-   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r
-   decompressing worked incorrectly.\r
-\r
-\r
-4.26           2005-08-05\r
--------------------------\r
-- Fixes in 7z_C code and LzmaTest.c:\r
-  previous versions could work incorrectly,\r
-  if malloc(0) returns 0\r
-\r
-\r
-4.23           2005-06-29\r
--------------------------\r
-- Small fixes in C++ code\r
-\r
-\r
-4.22           2005-06-10\r
--------------------------\r
-- Small fixes\r
-\r
-\r
-4.21           2005-06-08\r
--------------------------\r
-- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r
-- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r
-    - LzmaStateDecode.h\r
-    - LzmaStateDecode.c\r
-    - LzmaStateTest.c\r
-- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r
-\r
-\r
-4.17           2005-04-18\r
--------------------------\r
-- New example for RAM->RAM compressing/decompressing: \r
-  LZMA + BCJ (filter for x86 code):\r
-    - LzmaRam.h\r
-    - LzmaRam.cpp\r
-    - LzmaRamDecode.h\r
-    - LzmaRamDecode.c\r
-    - -f86 switch for lzma.exe\r
-\r
-\r
-4.16           2005-03-29\r
--------------------------\r
-- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r
-   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r
-   decoder could access memory outside of allocated range.\r
-- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r
-  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r
-  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r
-- Small speed optimization in LZMA C++ code\r
-- filter for SPARC's code was added\r
-- Simplified version of .7z ANSI-C Decoder was included\r
-\r
-\r
-4.06           2004-09-05\r
--------------------------\r
-- The bug in v4.05 was fixed:\r
-    LZMA-Encoder didn't release output stream in some cases.\r
-\r
-\r
-4.05           2004-08-25\r
--------------------------\r
-- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r
-  and PowerPC code was included to SDK\r
-- Some internal minor changes\r
-\r
-\r
-4.04           2004-07-28\r
--------------------------\r
-- More compatibility with some C++ compilers\r
-\r
-\r
-4.03           2004-06-18\r
--------------------------\r
-- "Benchmark" command was added. It measures compressing \r
-  and decompressing speed and shows rating values. \r
-  Also it checks hardware errors.\r
-\r
-\r
-4.02           2004-06-10\r
--------------------------\r
-- C++ LZMA Encoder/Decoder code now is more portable\r
-  and it can be compiled by GCC on Linux.\r
-\r
-\r
-4.01           2004-02-15\r
--------------------------\r
-- Some detection of data corruption was enabled.\r
-    LzmaDecode.c / RangeDecoderReadByte\r
-    .....\r
-    {\r
-      rd->ExtraBytes = 1;\r
-      return 0xFF;\r
-    }\r
-\r
-\r
-4.00           2004-02-13\r
--------------------------\r
-- Original version of LZMA SDK\r
-\r
-\r
-\r
-HISTORY of the LZMA\r
--------------------\r
-  2001-2008:  Improvements to LZMA compressing/decompressing code, \r
-              keeping compatibility with original LZMA format\r
-  1996-2001:  Development of LZMA compression format\r
-\r
-  Some milestones:\r
-\r
-  2001-08-30: LZMA compression was added to 7-Zip\r
-  1999-01-02: First version of 7-Zip was released\r
-  \r
-\r
-End of document\r
+HISTORY of the LZMA SDK
+-----------------------
+
+19.00          2019-02-21
+-------------------------
+- Encryption strength for 7z archives was increased:
+  the size of random initialization vector was increased from 64-bit to 128-bit,
+  and the pseudo-random number generator was improved.
+- The bug in 7zIn.c code was fixed.
+
+
+18.06          2018-12-30
+-------------------------
+- The speed for LZMA/LZMA2 compressing was increased by 3-10%,
+  and there are minor changes in compression ratio.
+- Some bugs were fixed.
+- The bug in 7-Zip 18.02-18.05 was fixed:
+  There was memory leak in multithreading xz decoder - XzDecMt_Decode(),
+  if xz stream contains only one block.
+- The changes for MSVS compiler makefiles: 
+   - the makefiles now use "PLATFORM" macroname with values (x64, x86, arm64)
+     instead of "CPU" macroname with values (AMD64, ARM64).
+   - the makefiles by default now use static version of the run-time library.
+
+
+18.05          2018-04-30
+-------------------------
+- The speed for LZMA/LZMA2 compressing was increased 
+    by 8% for fastest/fast compression levels and 
+    by 3% for normal/maximum compression levels.
+- Previous versions of 7-Zip could work incorrectly in "Large memory pages" mode in
+  Windows 10 because of some BUG with "Large Pages" in Windows 10. 
+  Now 7-Zip doesn't use "Large Pages" on Windows 10 up to revision 1709 (16299).
+- The BUG was fixed in Lzma2Enc.c
+    Lzma2Enc_Encode2() function worked incorretly,
+      if (inStream == NULL) and the number of block threads is more than 1.
+
+
+18.03 beta     2018-03-04
+-------------------------
+- Asm\x86\LzmaDecOpt.asm: new optimized LZMA decoder written in asm 
+  for x64 with about 30% higher speed than main version of LZMA decoder written in C.
+- The speed for single-thread LZMA/LZMA2 decoder written in C was increased by 3%.
+- 7-Zip now can use multi-threading for 7z/LZMA2 decoding,
+  if there are multiple independent data chunks in LZMA2 stream.
+- 7-Zip now can use multi-threading for xz decoding,
+  if there are multiple blocks in xz stream.
+
+
+18.01          2019-01-28
+-------------------------
+- The BUG in 17.01 - 18.00 beta was fixed:
+  XzDec.c : random block unpacking and XzUnpacker_IsBlockFinished()
+  didn't work correctly for xz archives without checksum (CRC).
+
+
+18.00 beta     2019-01-10
+-------------------------
+- The BUG in xz encoder was fixed:
+  There was memory leak of 16 KB for each file compressed with 
+  xz compression method, if additional filter was used.
+
+
+17.01 beta     2017-08-28
+-------------------------
+- Minor speed optimization for LZMA2 (xz and 7z) multi-threading compression.
+  7-Zip now uses additional memory buffers for multi-block LZMA2 compression.
+  CPU utilization was slightly improved.
+- 7-zip now creates multi-block xz archives by default. Block size can be 
+  specified with -ms[Size]{m|g} switch.
+- xz decoder now can unpack random block from multi-block xz archives.
+- 7-Zip command line: @listfile now doesn't work after -- switch.
+  Use -i@listfile before -- switch instead.
+- The BUGs were fixed:
+  7-Zip 17.00 beta crashed for commands that write anti-item to 7z archive.
+
+
+17.00 beta     2017-04-29
+-------------------------
+- NewHandler.h / NewHandler.cpp: 
+    now it redefines operator new() only for old MSVC compilers (_MSC_VER < 1900).
+- C/7zTypes.h : the names of variables in interface structures were changed (vt).
+- Some bugs were fixed. 7-Zip could crash in some cases.
+- Some internal changes in code.
+
+
+16.04          2016-10-04
+-------------------------
+- The bug was fixed in DllSecur.c.
+
+
+16.03          2016-09-28
+-------------------------
+- SFX modules now use some protection against DLL preloading attack.
+- Some bugs in 7z code were fixed.
+
+
+16.02          2016-05-21
+-------------------------
+- The BUG in 16.00 - 16.01 was fixed:
+  Split Handler (SplitHandler.cpp) returned incorrect 
+  total size value (kpidSize) for split archives.
+
+
+16.01          2016-05-19
+-------------------------      
+- Some internal changes to reduce the number of compiler warnings.
+
+
+16.00          2016-05-10
+-------------------------      
+- Some bugs were fixed.
+
+
+15.12          2015-11-19
+-------------------------      
+- The BUG in C version of 7z decoder was fixed:
+  7zDec.c : SzDecodeLzma2()
+  7z decoder could mistakenly report about decoding error for some 7z archives
+  that use LZMA2 compression method.
+  The probability to get that mistaken decoding error report was about 
+  one error per 16384 solid blocks for solid blocks larger than 16 KB (compressed size). 
+- The BUG (in 9.26-15.11) in C version of 7z decoder was fixed:
+  7zArcIn.c : SzReadHeader2()
+  7z decoder worked incorrectly for 7z archives that contain 
+  empty solid blocks, that can be placed to 7z archive, if some file is 
+  unavailable for reading during archive creation.
+
+
+15.09 beta     2015-10-16
+-------------------------      
+- The BUG in LZMA / LZMA2 encoding code was fixed.
+  The BUG in LzFind.c::MatchFinder_ReadBlock() function.
+  If input data size is larger than (4 GiB - dictionary_size),
+  the following code worked incorrectly:
+  -  LZMA : LzmaEnc_MemEncode(), LzmaEncode() : LZMA encoding functions 
+     for compressing from memory to memory. 
+     That BUG is not related to LZMA encoder version that works via streams.
+  -  LZMA2 : multi-threaded version of LZMA2 encoder worked incorrectly, if 
+     default value of chunk size (CLzma2EncProps::blockSize) is changed 
+     to value larger than (4 GiB - dictionary_size).
+
+
+9.38 beta      2015-01-03
+-------------------------      
+- The BUG in 9.31-9.37 was fixed:
+  IArchiveGetRawProps interface was disabled for 7z archives.
+- The BUG in 9.26-9.36 was fixed:
+  Some code in CPP\7zip\Archive\7z\ worked correctly only under Windows.
+
+
+9.36 beta      2014-12-26
+-------------------------      
+- The BUG in command line version was fixed:
+  7-Zip created temporary archive in current folder during update archive
+  operation, if -w{Path} switch was not specified. 
+  The fixed 7-Zip creates temporary archive in folder that contains updated archive.
+- The BUG in 9.33-9.35 was fixed:
+  7-Zip silently ignored file reading errors during 7z or gz archive creation,
+  and the created archive contained only part of file that was read before error.
+  The fixed 7-Zip stops archive creation and it reports about error.
+
+
+9.35 beta      2014-12-07
+-------------------------      
+- 7zr.exe now support AES encryption.
+- SFX mudules were added to LZMA SDK
+- Some bugs were fixed.
+
+
+9.21 beta      2011-04-11
+-------------------------      
+- New class FString for file names at file systems.
+- Speed optimization in CRC code for big-endian CPUs.
+- The BUG in Lzma2Dec.c was fixed:
+    Lzma2Decode function didn't work.
+
+
+9.18 beta      2010-11-02
+-------------------------      
+- New small SFX module for installers (SfxSetup).
+
+
+9.12 beta      2010-03-24
+-------------------------
+- The BUG in LZMA SDK 9.* was fixed: LZMA2 codec didn't work,
+  if more than 10 threads were used (or more than 20 threads in some modes).
+
+
+9.11 beta      2010-03-15
+-------------------------
+- PPMd compression method support
+   
+
+9.09           2009-12-12
+-------------------------
+- The bug was fixed:
+   Utf16_To_Utf8 funstions in UTFConvert.cpp and 7zMain.c
+   incorrectly converted surrogate characters (the code >= 0x10000) to UTF-8.
+- Some bugs were fixed
+
+
+9.06           2009-08-17
+-------------------------
+- Some changes in ANSI-C 7z Decoder interfaces.
+
+
+9.04           2009-05-30
+-------------------------
+- LZMA2 compression method support
+- xz format support
+
+
+4.65           2009-02-03
+-------------------------
+- Some minor fixes
+
+
+4.63           2008-12-31
+-------------------------
+- Some minor fixes
+
+
+4.61 beta      2008-11-23
+-------------------------
+- The bug in ANSI-C LZMA Decoder was fixed:
+    If encoded stream was corrupted, decoder could access memory 
+    outside of allocated range.
+- Some changes in ANSI-C 7z Decoder interfaces.
+- LZMA SDK is placed in the public domain.
+
+
+4.60 beta      2008-08-19
+-------------------------
+- Some minor fixes.
+
+
+4.59 beta      2008-08-13
+-------------------------
+- The bug was fixed:
+    LZMA Encoder in fast compression mode could access memory outside of 
+    allocated range in some rare cases.
+
+
+4.58 beta      2008-05-05
+-------------------------
+- ANSI-C LZMA Decoder was rewritten for speed optimizations.
+- ANSI-C LZMA Encoder was included to LZMA SDK.
+- C++ LZMA code now is just wrapper over ANSI-C code.
+
+
+4.57           2007-12-12
+-------------------------
+- Speed optimizations in Ã‘++ LZMA Decoder. 
+- Small changes for more compatibility with some C/C++ compilers.
+
+
+4.49 beta      2007-07-05
+-------------------------
+- .7z ANSI-C Decoder:
+     - now it supports BCJ and BCJ2 filters
+     - now it supports files larger than 4 GB.
+     - now it supports "Last Write Time" field for files.
+- C++ code for .7z archives compressing/decompressing from 7-zip 
+  was included to LZMA SDK.
+  
+
+4.43           2006-06-04
+-------------------------
+- Small changes for more compatibility with some C/C++ compilers.
+  
+
+4.42           2006-05-15
+-------------------------
+- Small changes in .h files in ANSI-C version.
+  
+
+4.39 beta      2006-04-14
+-------------------------
+- The bug in versions 4.33b:4.38b was fixed:
+  C++ version of LZMA encoder could not correctly compress 
+  files larger than 2 GB with HC4 match finder (-mfhc4).
+  
+
+4.37 beta      2005-04-06
+-------------------------
+- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. 
+
+
+4.35 beta      2005-03-02
+-------------------------
+- The bug was fixed in C++ version of LZMA Decoder:
+    If encoded stream was corrupted, decoder could access memory 
+    outside of allocated range.
+
+
+4.34 beta      2006-02-27
+-------------------------
+- Compressing speed and memory requirements for compressing were increased
+- LZMA now can use only these match finders: HC4, BT2, BT3, BT4
+
+
+4.32           2005-12-09
+-------------------------
+- Java version of LZMA SDK was included
+
+
+4.30           2005-11-20
+-------------------------
+- Compression ratio was improved in -a2 mode
+- Speed optimizations for compressing in -a2 mode
+- -fb switch now supports values up to 273
+- The bug in 7z_C (7zIn.c) was fixed:
+  It used Alloc/Free functions from different memory pools.
+  So if program used two memory pools, it worked incorrectly.
+- 7z_C: .7z format supporting was improved
+- LZMA# SDK (C#.NET version) was included
+
+
+4.27 (Updated) 2005-09-21
+-------------------------
+- Some GUIDs/interfaces in C++ were changed.
+ IStream.h:
+   ISequentialInStream::Read now works as old ReadPart
+   ISequentialOutStream::Write now works as old WritePart
+
+
+4.27           2005-08-07
+-------------------------
+- The bug in LzmaDecodeSize.c was fixed:
+   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,
+   decompressing worked incorrectly.
+
+
+4.26           2005-08-05
+-------------------------
+- Fixes in 7z_C code and LzmaTest.c:
+  previous versions could work incorrectly,
+  if malloc(0) returns 0
+
+
+4.23           2005-06-29
+-------------------------
+- Small fixes in C++ code
+
+
+4.22           2005-06-10
+-------------------------
+- Small fixes
+
+
+4.21           2005-06-08
+-------------------------
+- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed
+- New additional version of ANSI-C LZMA Decoder with zlib-like interface:
+    - LzmaStateDecode.h
+    - LzmaStateDecode.c
+    - LzmaStateTest.c
+- ANSI-C LZMA Decoder now can decompress files larger than 4 GB
+
+
+4.17           2005-04-18
+-------------------------
+- New example for RAM->RAM compressing/decompressing: 
+  LZMA + BCJ (filter for x86 code):
+    - LzmaRam.h
+    - LzmaRam.cpp
+    - LzmaRamDecode.h
+    - LzmaRamDecode.c
+    - -f86 switch for lzma.exe
+
+
+4.16           2005-03-29
+-------------------------
+- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): 
+   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,
+   decoder could access memory outside of allocated range.
+- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).
+  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. 
+  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c
+- Small speed optimization in LZMA C++ code
+- filter for SPARC's code was added
+- Simplified version of .7z ANSI-C Decoder was included
+
+
+4.06           2004-09-05
+-------------------------
+- The bug in v4.05 was fixed:
+    LZMA-Encoder didn't release output stream in some cases.
+
+
+4.05           2004-08-25
+-------------------------
+- Source code of filters for x86, IA-64, ARM, ARM-Thumb 
+  and PowerPC code was included to SDK
+- Some internal minor changes
+
+
+4.04           2004-07-28
+-------------------------
+- More compatibility with some C++ compilers
+
+
+4.03           2004-06-18
+-------------------------
+- "Benchmark" command was added. It measures compressing 
+  and decompressing speed and shows rating values. 
+  Also it checks hardware errors.
+
+
+4.02           2004-06-10
+-------------------------
+- C++ LZMA Encoder/Decoder code now is more portable
+  and it can be compiled by GCC on Linux.
+
+
+4.01           2004-02-15
+-------------------------
+- Some detection of data corruption was enabled.
+    LzmaDecode.c / RangeDecoderReadByte
+    .....
+    {
+      rd->ExtraBytes = 1;
+      return 0xFF;
+    }
+
+
+4.00           2004-02-13
+-------------------------
+- Original version of LZMA SDK
+
+
+
+HISTORY of the LZMA
+-------------------
+  2001-2008:  Improvements to LZMA compressing/decompressing code, 
+              keeping compatibility with original LZMA format
+  1996-2001:  Development of LZMA compression format
+
+  Some milestones:
+
+  2001-08-30: LZMA compression was added to 7-Zip
+  1999-01-02: First version of 7-Zip was released
+  
+
+End of document
similarity index 95%
rename from deps/lzma-16.04/DOC/lzma.txt
rename to deps/libchdr/deps/lzma-19.00/lzma.txt
index f9a80ae..a65988f 100644 (file)
-LZMA compression\r
-----------------\r
-Version: 9.35\r
-\r
-This file describes LZMA encoding and decoding functions written in C language.\r
-\r
-LZMA is an improved version of famous LZ77 compression algorithm. \r
-It was improved in way of maximum increasing of compression ratio,\r
-keeping high decompression speed and low memory requirements for \r
-decompressing.\r
-\r
-Note: you can read also LZMA Specification (lzma-specification.txt from LZMA SDK)\r
-\r
-Also you can look source code for LZMA encoding and decoding:\r
-  C/Util/Lzma/LzmaUtil.c\r
-\r
-\r
-LZMA compressed file format\r
----------------------------\r
-Offset Size Description\r
-  0     1   Special LZMA properties (lc,lp, pb in encoded form)\r
-  1     4   Dictionary size (little endian)\r
-  5     8   Uncompressed size (little endian). -1 means unknown size\r
- 13         Compressed data\r
-\r
-\r
-\r
-ANSI-C LZMA Decoder\r
-~~~~~~~~~~~~~~~~~~~\r
-\r
-Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.\r
-If you want to use old interfaces you can download previous version of LZMA SDK\r
-from sourceforge.net site.\r
-\r
-To use ANSI-C LZMA Decoder you need the following files:\r
-1) LzmaDec.h + LzmaDec.c + Types.h\r
-\r
-Look example code:\r
-  C/Util/Lzma/LzmaUtil.c\r
-\r
-\r
-Memory requirements for LZMA decoding\r
--------------------------------------\r
-\r
-Stack usage of LZMA decoding function for local variables is not \r
-larger than 200-400 bytes.\r
-\r
-LZMA Decoder uses dictionary buffer and internal state structure.\r
-Internal state structure consumes\r
-  state_size = (4 + (1.5 << (lc + lp))) KB\r
-by default (lc=3, lp=0), state_size = 16 KB.\r
-\r
-\r
-How To decompress data\r
-----------------------\r
-\r
-LZMA Decoder (ANSI-C version) now supports 2 interfaces:\r
-1) Single-call Decompressing\r
-2) Multi-call State Decompressing (zlib-like interface)\r
-\r
-You must use external allocator:\r
-Example:\r
-void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\r
-void SzFree(void *p, void *address) { p = p; free(address); }\r
-ISzAlloc alloc = { SzAlloc, SzFree };\r
-\r
-You can use p = p; operator to disable compiler warnings.\r
-\r
-\r
-Single-call Decompressing\r
--------------------------\r
-When to use: RAM->RAM decompressing\r
-Compile files: LzmaDec.h + LzmaDec.c + Types.h\r
-Compile defines: no defines\r
-Memory Requirements:\r
-  - Input buffer: compressed size\r
-  - Output buffer: uncompressed size\r
-  - LZMA Internal Structures: state_size (16 KB for default settings) \r
-\r
-Interface:\r
-  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, \r
-      ELzmaStatus *status, ISzAlloc *alloc);\r
-  In: \r
-    dest     - output data\r
-    destLen  - output data size\r
-    src      - input data\r
-    srcLen   - input data size\r
-    propData - LZMA properties  (5 bytes)\r
-    propSize - size of propData buffer (5 bytes)\r
-    finishMode - It has meaning only if the decoding reaches output limit (*destLen).\r
-         LZMA_FINISH_ANY - Decode just destLen bytes.\r
-         LZMA_FINISH_END - Stream must be finished after (*destLen).\r
-                           You can use LZMA_FINISH_END, when you know that \r
-                           current output buffer covers last bytes of stream. \r
-    alloc    - Memory allocator.\r
-\r
-  Out: \r
-    destLen  - processed output size \r
-    srcLen   - processed input size \r
-\r
-  Output:\r
-    SZ_OK\r
-      status:\r
-        LZMA_STATUS_FINISHED_WITH_MARK\r
-        LZMA_STATUS_NOT_FINISHED \r
-        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r
-    SZ_ERROR_DATA - Data error\r
-    SZ_ERROR_MEM  - Memory allocation error\r
-    SZ_ERROR_UNSUPPORTED - Unsupported properties\r
-    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r
-\r
-  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,\r
-  and output value of destLen will be less than output buffer size limit.\r
-\r
-  You can use multiple checks to test data integrity after full decompression:\r
-    1) Check Result and "status" variable.\r
-    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r
-    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. \r
-       You must use correct finish mode in that case. */ \r
-\r
-\r
-Multi-call State Decompressing (zlib-like interface)\r
-----------------------------------------------------\r
-\r
-When to use: file->file decompressing \r
-Compile files: LzmaDec.h + LzmaDec.c + Types.h\r
-\r
-Memory Requirements:\r
- - Buffer for input stream: any size (for example, 16 KB)\r
- - Buffer for output stream: any size (for example, 16 KB)\r
- - LZMA Internal Structures: state_size (16 KB for default settings) \r
- - LZMA dictionary (dictionary size is encoded in LZMA properties header)\r
-\r
-1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:\r
-   unsigned char header[LZMA_PROPS_SIZE + 8];\r
-   ReadFile(inFile, header, sizeof(header)\r
-\r
-2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties\r
-\r
-  CLzmaDec state;\r
-  LzmaDec_Constr(&state);\r
-  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);\r
-  if (res != SZ_OK)\r
-    return res;\r
-\r
-3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop\r
-\r
-  LzmaDec_Init(&state);\r
-  for (;;)\r
-  {\r
-    ... \r
-    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, \r
-        const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);\r
-    ...\r
-  }\r
-\r
-\r
-4) Free all allocated structures\r
-  LzmaDec_Free(&state, &g_Alloc);\r
-\r
-Look example code:\r
-  C/Util/Lzma/LzmaUtil.c\r
-\r
-\r
-How To compress data\r
---------------------\r
-\r
-Compile files: \r
-  Types.h\r
-  Threads.h    \r
-  LzmaEnc.h\r
-  LzmaEnc.c\r
-  LzFind.h\r
-  LzFind.c\r
-  LzFindMt.h\r
-  LzFindMt.c\r
-  LzHash.h\r
-\r
-Memory Requirements:\r
-  - (dictSize * 11.5 + 6 MB) + state_size\r
-\r
-Lzma Encoder can use two memory allocators:\r
-1) alloc - for small arrays.\r
-2) allocBig - for big arrays.\r
-\r
-For example, you can use Large RAM Pages (2 MB) in allocBig allocator for \r
-better compression speed. Note that Windows has bad implementation for \r
-Large RAM Pages. \r
-It's OK to use same allocator for alloc and allocBig.\r
-\r
-\r
-Single-call Compression with callbacks\r
---------------------------------------\r
-\r
-Look example code:\r
-  C/Util/Lzma/LzmaUtil.c\r
-\r
-When to use: file->file compressing \r
-\r
-1) you must implement callback structures for interfaces:\r
-ISeqInStream\r
-ISeqOutStream\r
-ICompressProgress\r
-ISzAlloc\r
-\r
-static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r
-static void SzFree(void *p, void *address) {  p = p; MyFree(address); }\r
-static ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
-\r
-  CFileSeqInStream inStream;\r
-  CFileSeqOutStream outStream;\r
-\r
-  inStream.funcTable.Read = MyRead;\r
-  inStream.file = inFile;\r
-  outStream.funcTable.Write = MyWrite;\r
-  outStream.file = outFile;\r
-\r
-\r
-2) Create CLzmaEncHandle object;\r
-\r
-  CLzmaEncHandle enc;\r
-\r
-  enc = LzmaEnc_Create(&g_Alloc);\r
-  if (enc == 0)\r
-    return SZ_ERROR_MEM;\r
-\r
-\r
-3) initialize CLzmaEncProps properties;\r
-\r
-  LzmaEncProps_Init(&props);\r
-\r
-  Then you can change some properties in that structure.\r
-\r
-4) Send LZMA properties to LZMA Encoder\r
-\r
-  res = LzmaEnc_SetProps(enc, &props);\r
-\r
-5) Write encoded properties to header\r
-\r
-    Byte header[LZMA_PROPS_SIZE + 8];\r
-    size_t headerSize = LZMA_PROPS_SIZE;\r
-    UInt64 fileSize;\r
-    int i;\r
-\r
-    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r
-    fileSize = MyGetFileLength(inFile);\r
-    for (i = 0; i < 8; i++)\r
-      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r
-    MyWriteFileAndCheck(outFile, header, headerSize)\r
-\r
-6) Call encoding function:\r
-      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, \r
-        NULL, &g_Alloc, &g_Alloc);\r
-\r
-7) Destroy LZMA Encoder Object\r
-  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r
-\r
-\r
-If callback function return some error code, LzmaEnc_Encode also returns that code\r
-or it can return the code like SZ_ERROR_READ, SZ_ERROR_WRITE or SZ_ERROR_PROGRESS.\r
-\r
-\r
-Single-call RAM->RAM Compression\r
---------------------------------\r
-\r
-Single-call RAM->RAM Compression is similar to Compression with callbacks,\r
-but you provide pointers to buffers instead of pointers to stream callbacks:\r
-\r
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
-    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, \r
-    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r
-\r
-Return code:\r
-  SZ_OK               - OK\r
-  SZ_ERROR_MEM        - Memory allocation error \r
-  SZ_ERROR_PARAM      - Incorrect paramater\r
-  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r
-  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r
-\r
-\r
-\r
-Defines\r
--------\r
-\r
-_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.\r
-\r
-_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for \r
-                 some structures will be doubled in that case.\r
-\r
-_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.\r
-\r
-_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.\r
-\r
-\r
-_7ZIP_PPMD_SUPPPORT - Define it if you don't want to support PPMD method in AMSI-C .7z decoder.\r
-\r
-\r
-C++ LZMA Encoder/Decoder \r
-~~~~~~~~~~~~~~~~~~~~~~~~\r
-C++ LZMA code use COM-like interfaces. So if you want to use it, \r
-you can study basics of COM/OLE.\r
-C++ LZMA code is just wrapper over ANSI-C code.\r
-\r
-\r
-C++ Notes\r
-~~~~~~~~~~~~~~~~~~~~~~~~\r
-If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),\r
-you must check that you correctly work with "new" operator.\r
-7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.\r
-So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:\r
-operator new(size_t size)\r
-{\r
-  void *p = ::malloc(size);\r
-  if (p == 0)\r
-    throw CNewException();\r
-  return p;\r
-}\r
-If you use MSCV that throws exception for "new" operator, you can compile without \r
-"NewHandler.cpp". So standard exception will be used. Actually some code of \r
-7-Zip catches any exception in internal code and converts it to HRESULT code.\r
-So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.\r
-\r
----\r
-\r
-http://www.7-zip.org\r
-http://www.7-zip.org/sdk.html\r
-http://www.7-zip.org/support.html\r
+LZMA compression
+----------------
+Version: 9.35
+
+This file describes LZMA encoding and decoding functions written in C language.
+
+LZMA is an improved version of famous LZ77 compression algorithm. 
+It was improved in way of maximum increasing of compression ratio,
+keeping high decompression speed and low memory requirements for 
+decompressing.
+
+Note: you can read also LZMA Specification (lzma-specification.txt from LZMA SDK)
+
+Also you can look source code for LZMA encoding and decoding:
+  C/Util/Lzma/LzmaUtil.c
+
+
+LZMA compressed file format
+---------------------------
+Offset Size Description
+  0     1   Special LZMA properties (lc,lp, pb in encoded form)
+  1     4   Dictionary size (little endian)
+  5     8   Uncompressed size (little endian). -1 means unknown size
+ 13         Compressed data
+
+
+
+ANSI-C LZMA Decoder
+~~~~~~~~~~~~~~~~~~~
+
+Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.
+If you want to use old interfaces you can download previous version of LZMA SDK
+from sourceforge.net site.
+
+To use ANSI-C LZMA Decoder you need the following files:
+1) LzmaDec.h + LzmaDec.c + 7zTypes.h + Precomp.h + Compiler.h
+
+Look example code:
+  C/Util/Lzma/LzmaUtil.c
+
+
+Memory requirements for LZMA decoding
+-------------------------------------
+
+Stack usage of LZMA decoding function for local variables is not 
+larger than 200-400 bytes.
+
+LZMA Decoder uses dictionary buffer and internal state structure.
+Internal state structure consumes
+  state_size = (4 + (1.5 << (lc + lp))) KB
+by default (lc=3, lp=0), state_size = 16 KB.
+
+
+How To decompress data
+----------------------
+
+LZMA Decoder (ANSI-C version) now supports 2 interfaces:
+1) Single-call Decompressing
+2) Multi-call State Decompressing (zlib-like interface)
+
+You must use external allocator:
+Example:
+void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }
+void SzFree(void *p, void *address) { p = p; free(address); }
+ISzAlloc alloc = { SzAlloc, SzFree };
+
+You can use p = p; operator to disable compiler warnings.
+
+
+Single-call Decompressing
+-------------------------
+When to use: RAM->RAM decompressing
+Compile files: LzmaDec.h + LzmaDec.c + 7zTypes.h
+Compile defines: no defines
+Memory Requirements:
+  - Input buffer: compressed size
+  - Output buffer: uncompressed size
+  - LZMA Internal Structures: state_size (16 KB for default settings) 
+
+Interface:
+  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, 
+      ELzmaStatus *status, ISzAlloc *alloc);
+  In: 
+    dest     - output data
+    destLen  - output data size
+    src      - input data
+    srcLen   - input data size
+    propData - LZMA properties  (5 bytes)
+    propSize - size of propData buffer (5 bytes)
+    finishMode - It has meaning only if the decoding reaches output limit (*destLen).
+         LZMA_FINISH_ANY - Decode just destLen bytes.
+         LZMA_FINISH_END - Stream must be finished after (*destLen).
+                           You can use LZMA_FINISH_END, when you know that 
+                           current output buffer covers last bytes of stream. 
+    alloc    - Memory allocator.
+
+  Out: 
+    destLen  - processed output size 
+    srcLen   - processed input size 
+
+  Output:
+    SZ_OK
+      status:
+        LZMA_STATUS_FINISHED_WITH_MARK
+        LZMA_STATUS_NOT_FINISHED 
+        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+    SZ_ERROR_DATA - Data error
+    SZ_ERROR_MEM  - Memory allocation error
+    SZ_ERROR_UNSUPPORTED - Unsupported properties
+    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
+
+  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,
+  and output value of destLen will be less than output buffer size limit.
+
+  You can use multiple checks to test data integrity after full decompression:
+    1) Check Result and "status" variable.
+    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
+    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. 
+       You must use correct finish mode in that case. */ 
+
+
+Multi-call State Decompressing (zlib-like interface)
+----------------------------------------------------
+
+When to use: file->file decompressing 
+Compile files: LzmaDec.h + LzmaDec.c + 7zTypes.h
+
+Memory Requirements:
+ - Buffer for input stream: any size (for example, 16 KB)
+ - Buffer for output stream: any size (for example, 16 KB)
+ - LZMA Internal Structures: state_size (16 KB for default settings) 
+ - LZMA dictionary (dictionary size is encoded in LZMA properties header)
+
+1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:
+   unsigned char header[LZMA_PROPS_SIZE + 8];
+   ReadFile(inFile, header, sizeof(header)
+
+2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties
+
+  CLzmaDec state;
+  LzmaDec_Constr(&state);
+  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
+  if (res != SZ_OK)
+    return res;
+
+3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop
+
+  LzmaDec_Init(&state);
+  for (;;)
+  {
+    ... 
+    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, 
+        const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);
+    ...
+  }
+
+
+4) Free all allocated structures
+  LzmaDec_Free(&state, &g_Alloc);
+
+Look example code:
+  C/Util/Lzma/LzmaUtil.c
+
+
+How To compress data
+--------------------
+
+Compile files: 
+  7zTypes.h
+  Threads.h    
+  LzmaEnc.h
+  LzmaEnc.c
+  LzFind.h
+  LzFind.c
+  LzFindMt.h
+  LzFindMt.c
+  LzHash.h
+
+Memory Requirements:
+  - (dictSize * 11.5 + 6 MB) + state_size
+
+Lzma Encoder can use two memory allocators:
+1) alloc - for small arrays.
+2) allocBig - for big arrays.
+
+For example, you can use Large RAM Pages (2 MB) in allocBig allocator for 
+better compression speed. Note that Windows has bad implementation for 
+Large RAM Pages. 
+It's OK to use same allocator for alloc and allocBig.
+
+
+Single-call Compression with callbacks
+--------------------------------------
+
+Look example code:
+  C/Util/Lzma/LzmaUtil.c
+
+When to use: file->file compressing 
+
+1) you must implement callback structures for interfaces:
+ISeqInStream
+ISeqOutStream
+ICompressProgress
+ISzAlloc
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) {  p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+  CFileSeqInStream inStream;
+  CFileSeqOutStream outStream;
+
+  inStream.funcTable.Read = MyRead;
+  inStream.file = inFile;
+  outStream.funcTable.Write = MyWrite;
+  outStream.file = outFile;
+
+
+2) Create CLzmaEncHandle object;
+
+  CLzmaEncHandle enc;
+
+  enc = LzmaEnc_Create(&g_Alloc);
+  if (enc == 0)
+    return SZ_ERROR_MEM;
+
+
+3) initialize CLzmaEncProps properties;
+
+  LzmaEncProps_Init(&props);
+
+  Then you can change some properties in that structure.
+
+4) Send LZMA properties to LZMA Encoder
+
+  res = LzmaEnc_SetProps(enc, &props);
+
+5) Write encoded properties to header
+
+    Byte header[LZMA_PROPS_SIZE + 8];
+    size_t headerSize = LZMA_PROPS_SIZE;
+    UInt64 fileSize;
+    int i;
+
+    res = LzmaEnc_WriteProperties(enc, header, &headerSize);
+    fileSize = MyGetFileLength(inFile);
+    for (i = 0; i < 8; i++)
+      header[headerSize++] = (Byte)(fileSize >> (8 * i));
+    MyWriteFileAndCheck(outFile, header, headerSize)
+
+6) Call encoding function:
+      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, 
+        NULL, &g_Alloc, &g_Alloc);
+
+7) Destroy LZMA Encoder Object
+  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
+
+
+If callback function return some error code, LzmaEnc_Encode also returns that code
+or it can return the code like SZ_ERROR_READ, SZ_ERROR_WRITE or SZ_ERROR_PROGRESS.
+
+
+Single-call RAM->RAM Compression
+--------------------------------
+
+Single-call RAM->RAM Compression is similar to Compression with callbacks,
+but you provide pointers to buffers instead of pointers to stream callbacks:
+
+SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, 
+    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+
+Return code:
+  SZ_OK               - OK
+  SZ_ERROR_MEM        - Memory allocation error 
+  SZ_ERROR_PARAM      - Incorrect paramater
+  SZ_ERROR_OUTPUT_EOF - output buffer overflow
+  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
+
+
+
+Defines
+-------
+
+_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.
+
+_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for 
+                 some structures will be doubled in that case.
+
+_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.
+
+_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.
+
+
+_7ZIP_PPMD_SUPPPORT - Define it if you don't want to support PPMD method in AMSI-C .7z decoder.
+
+
+C++ LZMA Encoder/Decoder 
+~~~~~~~~~~~~~~~~~~~~~~~~
+C++ LZMA code use COM-like interfaces. So if you want to use it, 
+you can study basics of COM/OLE.
+C++ LZMA code is just wrapper over ANSI-C code.
+
+
+C++ Notes
+~~~~~~~~~~~~~~~~~~~~~~~~
+If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),
+you must check that you correctly work with "new" operator.
+7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.
+So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:
+operator new(size_t size)
+{
+  void *p = ::malloc(size);
+  if (p == 0)
+    throw CNewException();
+  return p;
+}
+If you use MSCV that throws exception for "new" operator, you can compile without 
+"NewHandler.cpp". So standard exception will be used. Actually some code of 
+7-Zip catches any exception in internal code and converts it to HRESULT code.
+So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.
+
+---
+
+http://www.7-zip.org
+http://www.7-zip.org/sdk.html
+http://www.7-zip.org/support.html
diff --git a/deps/libchdr/deps/lzma-19.00/lzma.vcxproj b/deps/libchdr/deps/lzma-19.00/lzma.vcxproj
new file mode 100644 (file)
index 0000000..a421035
--- /dev/null
@@ -0,0 +1,543 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="DebugFast|ARM64">\r
+      <Configuration>DebugFast</Configuration>\r
+      <Platform>ARM64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="DebugFast|Win32">\r
+      <Configuration>DebugFast</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="DebugFast|x64">\r
+      <Configuration>DebugFast</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|ARM64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>ARM64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="ReleaseLTCG|ARM64">\r
+      <Configuration>ReleaseLTCG</Configuration>\r
+      <Platform>ARM64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="ReleaseLTCG|Win32">\r
+      <Configuration>ReleaseLTCG</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="ReleaseLTCG|x64">\r
+      <Configuration>ReleaseLTCG</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|ARM64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>ARM64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="src\Alloc.c" />\r
+    <ClCompile Include="src\Bra86.c" />\r
+    <ClCompile Include="src\BraIA64.c" />\r
+    <ClCompile Include="src\CpuArch.c" />\r
+    <ClCompile Include="src\Delta.c" />\r
+    <ClCompile Include="src\LzFind.c" />\r
+    <ClCompile Include="src\Lzma86Dec.c" />\r
+    <ClCompile Include="src\Lzma86Enc.c" />\r
+    <ClCompile Include="src\LzmaDec.c" />\r
+    <ClCompile Include="src\LzmaEnc.c" />\r
+    <ClCompile Include="src\LzmaLib.c" />\r
+    <ClCompile Include="src\Sort.c" />\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{DD944834-7899-4C1C-A4C1-064B5009D239}</ProjectGuid>\r
+    <Keyword>Win32Proj</Keyword>\r
+    <RootNamespace>lzma</RootNamespace>\r
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>true</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>true</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>true</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>true</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>true</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|ARM64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>true</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>false</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+    <SpectreMitigation>false</SpectreMitigation>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|Win32'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>false</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+    <SpectreMitigation>false</SpectreMitigation>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>false</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+    <SpectreMitigation>false</SpectreMitigation>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>false</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+    <SpectreMitigation>false</SpectreMitigation>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>false</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+    <SpectreMitigation>false</SpectreMitigation>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|ARM64'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>false</UseDebugLibraries>\r
+    <PlatformToolset>v142</PlatformToolset>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+    <CharacterSet>NotSet</CharacterSet>\r
+    <SpectreMitigation>false</SpectreMitigation>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|ARM64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|Win32'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|ARM64'" Label="PropertySheets">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <LinkIncremental>true</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+    <LinkIncremental>true</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+    <LinkIncremental>true</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'">\r
+    <LinkIncremental>true</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'">\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+    <LinkIncremental>true</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|ARM64'">\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+    <LinkIncremental>true</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <LinkIncremental>false</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|Win32'">\r
+    <LinkIncremental>false</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+    <LinkIncremental>false</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+    <LinkIncremental>false</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'">\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+    <LinkIncremental>false</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|ARM64'">\r
+    <IntDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>\r
+    <TargetName>$(ProjectName)-$(Platform)-$(Configuration)</TargetName>\r
+    <LinkIncremental>false</LinkIncremental>\r
+    <OutDir>$(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <Optimization>Disabled</Optimization>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <SDLCheck>true</SDLCheck>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <MinimalRebuild>false</MinimalRebuild>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+    <ClCompile>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <Optimization>Disabled</Optimization>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <SDLCheck>true</SDLCheck>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <MinimalRebuild>false</MinimalRebuild>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">\r
+    <ClCompile>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <Optimization>Disabled</Optimization>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <SDLCheck>true</SDLCheck>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <MinimalRebuild>false</MinimalRebuild>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'">\r
+    <ClCompile>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <Optimization>Disabled</Optimization>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_ITERATOR_DEBUG_LEVEL=1;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <SDLCheck>true</SDLCheck>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <BasicRuntimeChecks>Default</BasicRuntimeChecks>\r
+      <MinimalRebuild>false</MinimalRebuild>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <SupportJustMyCode>false</SupportJustMyCode>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'">\r
+    <ClCompile>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <Optimization>Disabled</Optimization>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_ITERATOR_DEBUG_LEVEL=1;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <SDLCheck>true</SDLCheck>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <BasicRuntimeChecks>Default</BasicRuntimeChecks>\r
+      <MinimalRebuild>false</MinimalRebuild>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <SupportJustMyCode>false</SupportJustMyCode>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|ARM64'">\r
+    <ClCompile>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <Optimization>Disabled</Optimization>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_ITERATOR_DEBUG_LEVEL=1;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <SDLCheck>true</SDLCheck>\r
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <BasicRuntimeChecks>Default</BasicRuntimeChecks>\r
+      <MinimalRebuild>false</MinimalRebuild>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <SupportJustMyCode>false</SupportJustMyCode>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <WholeProgramOptimization>false</WholeProgramOptimization>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|Win32'">\r
+    <ClCompile>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <WholeProgramOptimization>true</WholeProgramOptimization>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+    <ClCompile>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <WholeProgramOptimization>false</WholeProgramOptimization>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">\r
+    <ClCompile>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <WholeProgramOptimization>false</WholeProgramOptimization>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'">\r
+    <ClCompile>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <WholeProgramOptimization>true</WholeProgramOptimization>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|ARM64'">\r
+    <ClCompile>\r
+      <WarningLevel>Level2</WarningLevel>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <PreprocessorDefinitions>_7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <WholeProgramOptimization>true</WholeProgramOptimization>\r
+      <LanguageStandard>stdcpp17</LanguageStandard>\r
+      <OmitFramePointers>true</OmitFramePointers>\r
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <ConformanceMode>true</ConformanceMode>\r
+      <AdditionalOptions>/Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
+</Project>
\ No newline at end of file
diff --git a/deps/libchdr/deps/lzma-19.00/lzma.vcxproj.filters b/deps/libchdr/deps/lzma-19.00/lzma.vcxproj.filters
new file mode 100644 (file)
index 0000000..8725b39
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <ClCompile Include="src\BraIA64.c" />
+    <ClCompile Include="src\CpuArch.c" />
+    <ClCompile Include="src\Delta.c" />
+    <ClCompile Include="src\LzFind.c" />
+    <ClCompile Include="src\Lzma86Dec.c" />
+    <ClCompile Include="src\Lzma86Enc.c" />
+    <ClCompile Include="src\LzmaDec.c" />
+    <ClCompile Include="src\LzmaEnc.c" />
+    <ClCompile Include="src\LzmaLib.c" />
+    <ClCompile Include="src\Sort.c" />
+    <ClCompile Include="src\Alloc.c" />
+    <ClCompile Include="src\Bra86.c" />
+  </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/deps/libchdr/deps/lzma-19.00/src/Alloc.c b/deps/libchdr/deps/lzma-19.00/src/Alloc.c
new file mode 100644 (file)
index 0000000..bcede4b
--- /dev/null
@@ -0,0 +1,455 @@
+/* Alloc.c -- Memory allocation functions
+2018-04-27 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include <stdio.h>
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+#include <stdlib.h>
+
+#include "Alloc.h"
+
+/* #define _SZ_ALLOC_DEBUG */
+
+/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
+#ifdef _SZ_ALLOC_DEBUG
+
+#include <stdio.h>
+int g_allocCount = 0;
+int g_allocCountMid = 0;
+int g_allocCountBig = 0;
+
+
+#define CONVERT_INT_TO_STR(charType, tempSize) \
+  unsigned char temp[tempSize]; unsigned i = 0; \
+  while (val >= 10) { temp[i++] = (unsigned char)('0' + (unsigned)(val % 10)); val /= 10; } \
+  *s++ = (charType)('0' + (unsigned)val); \
+  while (i != 0) { i--; *s++ = temp[i]; } \
+  *s = 0;
+
+static void ConvertUInt64ToString(UInt64 val, char *s)
+{
+  CONVERT_INT_TO_STR(char, 24);
+}
+
+#define GET_HEX_CHAR(t) ((char)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))))
+
+static void ConvertUInt64ToHex(UInt64 val, char *s)
+{
+  UInt64 v = val;
+  unsigned i;
+  for (i = 1;; i++)
+  {
+    v >>= 4;
+    if (v == 0)
+      break;
+  }
+  s[i] = 0;
+  do
+  {
+    unsigned t = (unsigned)(val & 0xF);
+    val >>= 4;
+    s[--i] = GET_HEX_CHAR(t);
+  }
+  while (i);
+}
+
+#define DEBUG_OUT_STREAM stderr
+
+static void Print(const char *s)
+{
+  fputs(s, DEBUG_OUT_STREAM);
+}
+
+static void PrintAligned(const char *s, size_t align)
+{
+  size_t len = strlen(s);
+  for(;;)
+  {
+    fputc(' ', DEBUG_OUT_STREAM);
+    if (len >= align)
+      break;
+    ++len;
+  }
+  Print(s);
+}
+
+static void PrintLn()
+{
+  Print("\n");
+}
+
+static void PrintHex(UInt64 v, size_t align)
+{
+  char s[32];
+  ConvertUInt64ToHex(v, s);
+  PrintAligned(s, align);
+}
+
+static void PrintDec(UInt64 v, size_t align)
+{
+  char s[32];
+  ConvertUInt64ToString(v, s);
+  PrintAligned(s, align);
+}
+
+static void PrintAddr(void *p)
+{
+  PrintHex((UInt64)(size_t)(ptrdiff_t)p, 12);
+}
+
+
+#define PRINT_ALLOC(name, cnt, size, ptr) \
+    Print(name " "); \
+    PrintDec(cnt++, 10); \
+    PrintHex(size, 10); \
+    PrintAddr(ptr); \
+    PrintLn();
+#define PRINT_FREE(name, cnt, ptr) if (ptr) { \
+    Print(name " "); \
+    PrintDec(--cnt, 10); \
+    PrintAddr(ptr); \
+    PrintLn(); }
+#else
+
+#define PRINT_ALLOC(name, cnt, size, ptr)
+#define PRINT_FREE(name, cnt, ptr)
+#define Print(s)
+#define PrintLn()
+#define PrintHex(v, align)
+#define PrintDec(v, align)
+#define PrintAddr(p)
+
+#endif
+
+
+
+void *MyAlloc(size_t size)
+{
+  if (size == 0)
+    return NULL;
+  #ifdef _SZ_ALLOC_DEBUG
+  {
+    void *p = malloc(size);
+    PRINT_ALLOC("Alloc    ", g_allocCount, size, p);
+    return p;
+  }
+  #else
+  return malloc(size);
+  #endif
+}
+
+void MyFree(void *address)
+{
+  PRINT_FREE("Free    ", g_allocCount, address);
+  
+  free(address);
+}
+
+#ifdef _WIN32
+
+void *MidAlloc(size_t size)
+{
+  if (size == 0)
+    return NULL;
+  
+  PRINT_ALLOC("Alloc-Mid", g_allocCountMid, size, NULL);
+  
+  return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
+}
+
+void MidFree(void *address)
+{
+  PRINT_FREE("Free-Mid", g_allocCountMid, address);
+
+  if (!address)
+    return;
+  VirtualFree(address, 0, MEM_RELEASE);
+}
+
+#ifndef MEM_LARGE_PAGES
+#undef _7ZIP_LARGE_PAGES
+#endif
+
+#ifdef _7ZIP_LARGE_PAGES
+SIZE_T g_LargePageSize = 0;
+typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
+#endif
+
+void SetLargePageSize()
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  SIZE_T size;
+  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
+        GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
+  if (!largePageMinimum)
+    return;
+  size = largePageMinimum();
+  if (size == 0 || (size & (size - 1)) != 0)
+    return;
+  g_LargePageSize = size;
+  #endif
+}
+
+
+void *BigAlloc(size_t size)
+{
+  if (size == 0)
+    return NULL;
+
+  PRINT_ALLOC("Alloc-Big", g_allocCountBig, size, NULL);
+  
+  #ifdef _7ZIP_LARGE_PAGES
+  {
+    SIZE_T ps = g_LargePageSize;
+    if (ps != 0 && ps <= (1 << 30) && size > (ps / 2))
+    {
+      size_t size2;
+      ps--;
+      size2 = (size + ps) & ~ps;
+      if (size2 >= size)
+      {
+        void *res = VirtualAlloc(NULL, size2, MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
+        if (res)
+          return res;
+      }
+    }
+  }
+  #endif
+
+  return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
+}
+
+void BigFree(void *address)
+{
+  PRINT_FREE("Free-Big", g_allocCountBig, address);
+  
+  if (!address)
+    return;
+  VirtualFree(address, 0, MEM_RELEASE);
+}
+
+#endif
+
+
+static void *SzAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }
+static void SzFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); MyFree(address); }
+const ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+static void *SzMidAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return MidAlloc(size); }
+static void SzMidFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); MidFree(address); }
+const ISzAlloc g_MidAlloc = { SzMidAlloc, SzMidFree };
+
+static void *SzBigAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return BigAlloc(size); }
+static void SzBigFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); BigFree(address); }
+const ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
+
+
+/*
+  uintptr_t : <stdint.h> C99 (optional)
+            : unsupported in VS6
+*/
+
+#ifdef _WIN32
+  typedef UINT_PTR UIntPtr;
+#else
+  /*
+  typedef uintptr_t UIntPtr;
+  */
+  typedef ptrdiff_t UIntPtr;
+#endif
+
+
+#define ADJUST_ALLOC_SIZE 0
+/*
+#define ADJUST_ALLOC_SIZE (sizeof(void *) - 1)
+*/
+/*
+  Use (ADJUST_ALLOC_SIZE = (sizeof(void *) - 1)), if
+     MyAlloc() can return address that is NOT multiple of sizeof(void *).
+*/
+
+
+/*
+#define MY_ALIGN_PTR_DOWN(p, align) ((void *)((char *)(p) - ((size_t)(UIntPtr)(p) & ((align) - 1))))
+*/
+#define MY_ALIGN_PTR_DOWN(p, align) ((void *)((((UIntPtr)(p)) & ~((UIntPtr)(align) - 1))))
+
+#define MY_ALIGN_PTR_UP_PLUS(p, align) MY_ALIGN_PTR_DOWN(((char *)(p) + (align) + ADJUST_ALLOC_SIZE), align)
+
+
+#if (_POSIX_C_SOURCE >= 200112L) && !defined(_WIN32)
+  #define USE_posix_memalign
+#endif
+
+/*
+  This posix_memalign() is for test purposes only.
+  We also need special Free() function instead of free(),
+  if this posix_memalign() is used.
+*/
+
+/*
+static int posix_memalign(void **ptr, size_t align, size_t size)
+{
+  size_t newSize = size + align;
+  void *p;
+  void *pAligned;
+  *ptr = NULL;
+  if (newSize < size)
+    return 12; // ENOMEM
+  p = MyAlloc(newSize);
+  if (!p)
+    return 12; // ENOMEM
+  pAligned = MY_ALIGN_PTR_UP_PLUS(p, align);
+  ((void **)pAligned)[-1] = p;
+  *ptr = pAligned;
+  return 0;
+}
+*/
+
+/*
+  ALLOC_ALIGN_SIZE >= sizeof(void *)
+  ALLOC_ALIGN_SIZE >= cache_line_size
+*/
+
+#define ALLOC_ALIGN_SIZE ((size_t)1 << 7)
+
+static void *SzAlignedAlloc(ISzAllocPtr pp, size_t size)
+{
+  #ifndef USE_posix_memalign
+  
+  void *p;
+  void *pAligned;
+  size_t newSize;
+  UNUSED_VAR(pp);
+
+  /* also we can allocate additional dummy ALLOC_ALIGN_SIZE bytes after aligned
+     block to prevent cache line sharing with another allocated blocks */
+
+  newSize = size + ALLOC_ALIGN_SIZE * 1 + ADJUST_ALLOC_SIZE;
+  if (newSize < size)
+    return NULL;
+
+  p = MyAlloc(newSize);
+  
+  if (!p)
+    return NULL;
+  pAligned = MY_ALIGN_PTR_UP_PLUS(p, ALLOC_ALIGN_SIZE);
+
+  Print(" size="); PrintHex(size, 8);
+  Print(" a_size="); PrintHex(newSize, 8);
+  Print(" ptr="); PrintAddr(p);
+  Print(" a_ptr="); PrintAddr(pAligned);
+  PrintLn();
+
+  ((void **)pAligned)[-1] = p;
+
+  return pAligned;
+
+  #else
+
+  void *p;
+  UNUSED_VAR(pp);
+  if (posix_memalign(&p, ALLOC_ALIGN_SIZE, size))
+    return NULL;
+
+  Print(" posix_memalign="); PrintAddr(p);
+  PrintLn();
+
+  return p;
+
+  #endif
+}
+
+
+static void SzAlignedFree(ISzAllocPtr pp, void *address)
+{
+  UNUSED_VAR(pp);
+  #ifndef USE_posix_memalign
+  if (address)
+    MyFree(((void **)address)[-1]);
+  #else
+  free(address);
+  #endif
+}
+
+
+const ISzAlloc g_AlignedAlloc = { SzAlignedAlloc, SzAlignedFree };
+
+
+
+#define MY_ALIGN_PTR_DOWN_1(p) MY_ALIGN_PTR_DOWN(p, sizeof(void *))
+
+/* we align ptr to support cases where CAlignOffsetAlloc::offset is not multiply of sizeof(void *) */
+#define REAL_BLOCK_PTR_VAR(p) ((void **)MY_ALIGN_PTR_DOWN_1(p))[-1]
+/*
+#define REAL_BLOCK_PTR_VAR(p) ((void **)(p))[-1]
+*/
+
+static void *AlignOffsetAlloc_Alloc(ISzAllocPtr pp, size_t size)
+{
+  CAlignOffsetAlloc *p = CONTAINER_FROM_VTBL(pp, CAlignOffsetAlloc, vt);
+  void *adr;
+  void *pAligned;
+  size_t newSize;
+  size_t extra;
+  size_t alignSize = (size_t)1 << p->numAlignBits;
+
+  if (alignSize < sizeof(void *))
+    alignSize = sizeof(void *);
+  
+  if (p->offset >= alignSize)
+    return NULL;
+
+  /* also we can allocate additional dummy ALLOC_ALIGN_SIZE bytes after aligned
+     block to prevent cache line sharing with another allocated blocks */
+  extra = p->offset & (sizeof(void *) - 1);
+  newSize = size + alignSize + extra + ADJUST_ALLOC_SIZE;
+  if (newSize < size)
+    return NULL;
+
+  adr = ISzAlloc_Alloc(p->baseAlloc, newSize);
+  
+  if (!adr)
+    return NULL;
+
+  pAligned = (char *)MY_ALIGN_PTR_DOWN((char *)adr +
+      alignSize - p->offset + extra + ADJUST_ALLOC_SIZE, alignSize) + p->offset;
+
+  PrintLn();
+  Print("- Aligned: ");
+  Print(" size="); PrintHex(size, 8);
+  Print(" a_size="); PrintHex(newSize, 8);
+  Print(" ptr="); PrintAddr(adr);
+  Print(" a_ptr="); PrintAddr(pAligned);
+  PrintLn();
+
+  REAL_BLOCK_PTR_VAR(pAligned) = adr;
+
+  return pAligned;
+}
+
+
+static void AlignOffsetAlloc_Free(ISzAllocPtr pp, void *address)
+{
+  if (address)
+  {
+    CAlignOffsetAlloc *p = CONTAINER_FROM_VTBL(pp, CAlignOffsetAlloc, vt);
+    PrintLn();
+    Print("- Aligned Free: ");
+    PrintLn();
+    ISzAlloc_Free(p->baseAlloc, REAL_BLOCK_PTR_VAR(address));
+  }
+}
+
+
+void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p)
+{
+  p->vt.Alloc = AlignOffsetAlloc_Alloc;
+  p->vt.Free = AlignOffsetAlloc_Free;
+}
similarity index 91%
rename from deps/lzma-16.04/C/Bra86.c
rename to deps/libchdr/deps/lzma-19.00/src/Bra86.c
index 8dd3ed4..93ed4d7 100644 (file)
@@ -1,82 +1,82 @@
-/* Bra86.c -- Converter for x86 code (BCJ)\r
-2013-11-12 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Bra.h"\r
-\r
-#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)\r
-\r
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)\r
-{\r
-  SizeT pos = 0;\r
-  UInt32 mask = *state & 7;\r
-  if (size < 5)\r
-    return 0;\r
-  size -= 4;\r
-  ip += 5;\r
-\r
-  for (;;)\r
-  {\r
-    Byte *p = data + pos;\r
-    const Byte *limit = data + size;\r
-    for (; p < limit; p++)\r
-      if ((*p & 0xFE) == 0xE8)\r
-        break;\r
-\r
-    {\r
-      SizeT d = (SizeT)(p - data - pos);\r
-      pos = (SizeT)(p - data);\r
-      if (p >= limit)\r
-      {\r
-        *state = (d > 2 ? 0 : mask >> (unsigned)d);\r
-        return pos;\r
-      }\r
-      if (d > 2)\r
-        mask = 0;\r
-      else\r
-      {\r
-        mask >>= (unsigned)d;\r
-        if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(mask >> 1) + 1])))\r
-        {\r
-          mask = (mask >> 1) | 4;\r
-          pos++;\r
-          continue;\r
-        }\r
-      }\r
-    }\r
-\r
-    if (Test86MSByte(p[4]))\r
-    {\r
-      UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r
-      UInt32 cur = ip + (UInt32)pos;\r
-      pos += 5;\r
-      if (encoding)\r
-        v += cur;\r
-      else\r
-        v -= cur;\r
-      if (mask != 0)\r
-      {\r
-        unsigned sh = (mask & 6) << 2;\r
-        if (Test86MSByte((Byte)(v >> sh)))\r
-        {\r
-          v ^= (((UInt32)0x100 << sh) - 1);\r
-          if (encoding)\r
-            v += cur;\r
-          else\r
-            v -= cur;\r
-        }\r
-        mask = 0;\r
-      }\r
-      p[1] = (Byte)v;\r
-      p[2] = (Byte)(v >> 8);\r
-      p[3] = (Byte)(v >> 16);\r
-      p[4] = (Byte)(0 - ((v >> 24) & 1));\r
-    }\r
-    else\r
-    {\r
-      mask = (mask >> 1) | 4;\r
-      pos++;\r
-    }\r
-  }\r
-}\r
+/* Bra86.c -- Converter for x86 code (BCJ)
+2017-04-03 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include "Bra.h"
+
+#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)
+
+SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
+{
+  SizeT pos = 0;
+  UInt32 mask = *state & 7;
+  if (size < 5)
+    return 0;
+  size -= 4;
+  ip += 5;
+
+  for (;;)
+  {
+    Byte *p = data + pos;
+    const Byte *limit = data + size;
+    for (; p < limit; p++)
+      if ((*p & 0xFE) == 0xE8)
+        break;
+
+    {
+      SizeT d = (SizeT)(p - data - pos);
+      pos = (SizeT)(p - data);
+      if (p >= limit)
+      {
+        *state = (d > 2 ? 0 : mask >> (unsigned)d);
+        return pos;
+      }
+      if (d > 2)
+        mask = 0;
+      else
+      {
+        mask >>= (unsigned)d;
+        if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(size_t)(mask >> 1) + 1])))
+        {
+          mask = (mask >> 1) | 4;
+          pos++;
+          continue;
+        }
+      }
+    }
+
+    if (Test86MSByte(p[4]))
+    {
+      UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
+      UInt32 cur = ip + (UInt32)pos;
+      pos += 5;
+      if (encoding)
+        v += cur;
+      else
+        v -= cur;
+      if (mask != 0)
+      {
+        unsigned sh = (mask & 6) << 2;
+        if (Test86MSByte((Byte)(v >> sh)))
+        {
+          v ^= (((UInt32)0x100 << sh) - 1);
+          if (encoding)
+            v += cur;
+          else
+            v -= cur;
+        }
+        mask = 0;
+      }
+      p[1] = (Byte)v;
+      p[2] = (Byte)(v >> 8);
+      p[3] = (Byte)(v >> 16);
+      p[4] = (Byte)(0 - ((v >> 24) & 1));
+    }
+    else
+    {
+      mask = (mask >> 1) | 4;
+      pos++;
+    }
+  }
+}
diff --git a/deps/libchdr/deps/lzma-19.00/src/BraIA64.c b/deps/libchdr/deps/lzma-19.00/src/BraIA64.c
new file mode 100644 (file)
index 0000000..d1dbc62
--- /dev/null
@@ -0,0 +1,53 @@
+/* BraIA64.c -- Converter for IA-64 code
+2017-01-26 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include "CpuArch.h"
+#include "Bra.h"
+
+SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+  SizeT i;
+  if (size < 16)
+    return 0;
+  size -= 16;
+  i = 0;
+  do
+  {
+    unsigned m = ((UInt32)0x334B0000 >> (data[i] & 0x1E)) & 3;
+    if (m)
+    {
+      m++;
+      do
+      {
+        Byte *p = data + (i + (size_t)m * 5 - 8);
+        if (((p[3] >> m) & 15) == 5
+            && (((p[-1] | ((UInt32)p[0] << 8)) >> m) & 0x70) == 0)
+        {
+          unsigned raw = GetUi32(p);
+          unsigned v = raw >> m;
+          v = (v & 0xFFFFF) | ((v & (1 << 23)) >> 3);
+          
+          v <<= 4;
+          if (encoding)
+            v += ip + (UInt32)i;
+          else
+            v -= ip + (UInt32)i;
+          v >>= 4;
+          
+          v &= 0x1FFFFF;
+          v += 0x700000;
+          v &= 0x8FFFFF;
+          raw &= ~((UInt32)0x8FFFFF << m);
+          raw |= (v << m);
+          SetUi32(p, raw);
+        }
+      }
+      while (++m <= 4);
+    }
+    i += 16;
+  }
+  while (i <= size);
+  return i;
+}
similarity index 87%
rename from deps/lzma-16.04/C/CpuArch.c
rename to deps/libchdr/deps/lzma-19.00/src/CpuArch.c
index 098e301..02e482e 100644 (file)
-/* CpuArch.c -- CPU specific code\r
-2016-02-25: Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "CpuArch.h"\r
-\r
-#ifdef MY_CPU_X86_OR_AMD64\r
-\r
-#if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__)\r
-#define USE_ASM\r
-#endif\r
-\r
-#if !defined(USE_ASM) && _MSC_VER >= 1500\r
-#include <intrin.h>\r
-#endif\r
-\r
-#if defined(USE_ASM) && !defined(MY_CPU_AMD64)\r
-static UInt32 CheckFlag(UInt32 flag)\r
-{\r
-  #ifdef _MSC_VER\r
-  __asm pushfd;\r
-  __asm pop EAX;\r
-  __asm mov EDX, EAX;\r
-  __asm xor EAX, flag;\r
-  __asm push EAX;\r
-  __asm popfd;\r
-  __asm pushfd;\r
-  __asm pop EAX;\r
-  __asm xor EAX, EDX;\r
-  __asm push EDX;\r
-  __asm popfd;\r
-  __asm and flag, EAX;\r
-  #else\r
-  __asm__ __volatile__ (\r
-    "pushf\n\t"\r
-    "pop  %%EAX\n\t"\r
-    "movl %%EAX,%%EDX\n\t"\r
-    "xorl %0,%%EAX\n\t"\r
-    "push %%EAX\n\t"\r
-    "popf\n\t"\r
-    "pushf\n\t"\r
-    "pop  %%EAX\n\t"\r
-    "xorl %%EDX,%%EAX\n\t"\r
-    "push %%EDX\n\t"\r
-    "popf\n\t"\r
-    "andl %%EAX, %0\n\t":\r
-    "=c" (flag) : "c" (flag) :\r
-    "%eax", "%edx");\r
-  #endif\r
-  return flag;\r
-}\r
-#define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False;\r
-#else\r
-#define CHECK_CPUID_IS_SUPPORTED\r
-#endif\r
-\r
-void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)\r
-{\r
-  #ifdef USE_ASM\r
-\r
-  #ifdef _MSC_VER\r
-\r
-  UInt32 a2, b2, c2, d2;\r
-  __asm xor EBX, EBX;\r
-  __asm xor ECX, ECX;\r
-  __asm xor EDX, EDX;\r
-  __asm mov EAX, function;\r
-  __asm cpuid;\r
-  __asm mov a2, EAX;\r
-  __asm mov b2, EBX;\r
-  __asm mov c2, ECX;\r
-  __asm mov d2, EDX;\r
-\r
-  *a = a2;\r
-  *b = b2;\r
-  *c = c2;\r
-  *d = d2;\r
-\r
-  #else\r
-\r
-  __asm__ __volatile__ (\r
-  #if defined(MY_CPU_AMD64) && defined(__PIC__)\r
-    "mov %%rbx, %%rdi;"\r
-    "cpuid;"\r
-    "xchg %%rbx, %%rdi;"\r
-    : "=a" (*a) ,\r
-      "=D" (*b) ,\r
-  #elif defined(MY_CPU_X86) && defined(__PIC__)\r
-    "mov %%ebx, %%edi;"\r
-    "cpuid;"\r
-    "xchgl %%ebx, %%edi;"\r
-    : "=a" (*a) ,\r
-      "=D" (*b) ,\r
-  #else\r
-    "cpuid"\r
-    : "=a" (*a) ,\r
-      "=b" (*b) ,\r
-  #endif\r
-      "=c" (*c) ,\r
-      "=d" (*d)\r
-    : "0" (function)) ;\r
-\r
-  #endif\r
-  \r
-  #else\r
-\r
-  int CPUInfo[4];\r
-  __cpuid(CPUInfo, function);\r
-  *a = CPUInfo[0];\r
-  *b = CPUInfo[1];\r
-  *c = CPUInfo[2];\r
-  *d = CPUInfo[3];\r
-\r
-  #endif\r
-}\r
-\r
-Bool x86cpuid_CheckAndRead(Cx86cpuid *p)\r
-{\r
-  CHECK_CPUID_IS_SUPPORTED\r
-  MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]);\r
-  MyCPUID(1, &p->ver, &p->b, &p->c, &p->d);\r
-  return True;\r
-}\r
-\r
-static const UInt32 kVendors[][3] =\r
-{\r
-  { 0x756E6547, 0x49656E69, 0x6C65746E},\r
-  { 0x68747541, 0x69746E65, 0x444D4163},\r
-  { 0x746E6543, 0x48727561, 0x736C7561}\r
-};\r
-\r
-int x86cpuid_GetFirm(const Cx86cpuid *p)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++)\r
-  {\r
-    const UInt32 *v = kVendors[i];\r
-    if (v[0] == p->vendor[0] &&\r
-        v[1] == p->vendor[1] &&\r
-        v[2] == p->vendor[2])\r
-      return (int)i;\r
-  }\r
-  return -1;\r
-}\r
-\r
-Bool CPU_Is_InOrder()\r
-{\r
-  Cx86cpuid p;\r
-  int firm;\r
-  UInt32 family, model;\r
-  if (!x86cpuid_CheckAndRead(&p))\r
-    return True;\r
-\r
-  family = x86cpuid_GetFamily(p.ver);\r
-  model = x86cpuid_GetModel(p.ver);\r
-  \r
-  firm = x86cpuid_GetFirm(&p);\r
-\r
-  switch (firm)\r
-  {\r
-    case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && (\r
-        /* In-Order Atom CPU */\r
-           model == 0x1C  /* 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330 */\r
-        || model == 0x26  /* 45 nm, Z6xx */\r
-        || model == 0x27  /* 32 nm, Z2460 */\r
-        || model == 0x35  /* 32 nm, Z2760 */\r
-        || model == 0x36  /* 32 nm, N2xxx, D2xxx */\r
-        )));\r
-    case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA)));\r
-    case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF));\r
-  }\r
-  return True;\r
-}\r
-\r
-#if !defined(MY_CPU_AMD64) && defined(_WIN32)\r
-#include <windows.h>\r
-static Bool CPU_Sys_Is_SSE_Supported()\r
-{\r
-#if _MSC_VER >= 1900 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)\r
-  return True;\r
-#else\r
-  OSVERSIONINFO vi;\r
-  vi.dwOSVersionInfoSize = sizeof(vi);\r
-  if (!GetVersionEx(&vi))\r
-    return False;\r
-  return (vi.dwMajorVersion >= 5);\r
-#endif\r
-}\r
-#define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False;\r
-#else\r
-#define CHECK_SYS_SSE_SUPPORT\r
-#endif\r
-\r
-Bool CPU_Is_Aes_Supported()\r
-{\r
-  Cx86cpuid p;\r
-  CHECK_SYS_SSE_SUPPORT\r
-  if (!x86cpuid_CheckAndRead(&p))\r
-    return False;\r
-  return (p.c >> 25) & 1;\r
-}\r
-\r
-#endif\r
+/* CpuArch.c -- CPU specific code
+2018-02-18: Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include "CpuArch.h"
+
+#ifdef MY_CPU_X86_OR_AMD64
+
+#if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__)
+#define USE_ASM
+#endif
+
+#if !defined(USE_ASM) && _MSC_VER >= 1500
+#include <intrin.h>
+#endif
+
+#if defined(USE_ASM) && !defined(MY_CPU_AMD64)
+static UInt32 CheckFlag(UInt32 flag)
+{
+  #ifdef _MSC_VER
+  __asm pushfd;
+  __asm pop EAX;
+  __asm mov EDX, EAX;
+  __asm xor EAX, flag;
+  __asm push EAX;
+  __asm popfd;
+  __asm pushfd;
+  __asm pop EAX;
+  __asm xor EAX, EDX;
+  __asm push EDX;
+  __asm popfd;
+  __asm and flag, EAX;
+  #else
+  __asm__ __volatile__ (
+    "pushf\n\t"
+    "pop  %%EAX\n\t"
+    "movl %%EAX,%%EDX\n\t"
+    "xorl %0,%%EAX\n\t"
+    "push %%EAX\n\t"
+    "popf\n\t"
+    "pushf\n\t"
+    "pop  %%EAX\n\t"
+    "xorl %%EDX,%%EAX\n\t"
+    "push %%EDX\n\t"
+    "popf\n\t"
+    "andl %%EAX, %0\n\t":
+    "=c" (flag) : "c" (flag) :
+    "%eax", "%edx");
+  #endif
+  return flag;
+}
+#define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False;
+#else
+#define CHECK_CPUID_IS_SUPPORTED
+#endif
+
+void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
+{
+  #ifdef USE_ASM
+
+  #ifdef _MSC_VER
+
+  UInt32 a2, b2, c2, d2;
+  __asm xor EBX, EBX;
+  __asm xor ECX, ECX;
+  __asm xor EDX, EDX;
+  __asm mov EAX, function;
+  __asm cpuid;
+  __asm mov a2, EAX;
+  __asm mov b2, EBX;
+  __asm mov c2, ECX;
+  __asm mov d2, EDX;
+
+  *a = a2;
+  *b = b2;
+  *c = c2;
+  *d = d2;
+
+  #else
+
+  __asm__ __volatile__ (
+  #if defined(MY_CPU_AMD64) && defined(__PIC__)
+    "mov %%rbx, %%rdi;"
+    "cpuid;"
+    "xchg %%rbx, %%rdi;"
+    : "=a" (*a) ,
+      "=D" (*b) ,
+  #elif defined(MY_CPU_X86) && defined(__PIC__)
+    "mov %%ebx, %%edi;"
+    "cpuid;"
+    "xchgl %%ebx, %%edi;"
+    : "=a" (*a) ,
+      "=D" (*b) ,
+  #else
+    "cpuid"
+    : "=a" (*a) ,
+      "=b" (*b) ,
+  #endif
+      "=c" (*c) ,
+      "=d" (*d)
+    : "0" (function)) ;
+
+  #endif
+  
+  #else
+
+  int CPUInfo[4];
+  __cpuid(CPUInfo, function);
+  *a = CPUInfo[0];
+  *b = CPUInfo[1];
+  *c = CPUInfo[2];
+  *d = CPUInfo[3];
+
+  #endif
+}
+
+BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p)
+{
+  CHECK_CPUID_IS_SUPPORTED
+  MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]);
+  MyCPUID(1, &p->ver, &p->b, &p->c, &p->d);
+  return True;
+}
+
+static const UInt32 kVendors[][3] =
+{
+  { 0x756E6547, 0x49656E69, 0x6C65746E},
+  { 0x68747541, 0x69746E65, 0x444D4163},
+  { 0x746E6543, 0x48727561, 0x736C7561}
+};
+
+int x86cpuid_GetFirm(const Cx86cpuid *p)
+{
+  unsigned i;
+  for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++)
+  {
+    const UInt32 *v = kVendors[i];
+    if (v[0] == p->vendor[0] &&
+        v[1] == p->vendor[1] &&
+        v[2] == p->vendor[2])
+      return (int)i;
+  }
+  return -1;
+}
+
+BoolInt CPU_Is_InOrder()
+{
+  Cx86cpuid p;
+  int firm;
+  UInt32 family, model;
+  if (!x86cpuid_CheckAndRead(&p))
+    return True;
+
+  family = x86cpuid_GetFamily(p.ver);
+  model = x86cpuid_GetModel(p.ver);
+  
+  firm = x86cpuid_GetFirm(&p);
+
+  switch (firm)
+  {
+    case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && (
+        /* In-Order Atom CPU */
+           model == 0x1C  /* 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330 */
+        || model == 0x26  /* 45 nm, Z6xx */
+        || model == 0x27  /* 32 nm, Z2460 */
+        || model == 0x35  /* 32 nm, Z2760 */
+        || model == 0x36  /* 32 nm, N2xxx, D2xxx */
+        )));
+    case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA)));
+    case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF));
+  }
+  return True;
+}
+
+#if !defined(MY_CPU_AMD64) && defined(_WIN32)
+#include <windows.h>
+static BoolInt CPU_Sys_Is_SSE_Supported()
+{
+  OSVERSIONINFO vi;
+  vi.dwOSVersionInfoSize = sizeof(vi);
+  if (!GetVersionEx(&vi))
+    return False;
+  return (vi.dwMajorVersion >= 5);
+}
+#define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False;
+#else
+#define CHECK_SYS_SSE_SUPPORT
+#endif
+
+BoolInt CPU_Is_Aes_Supported()
+{
+  Cx86cpuid p;
+  CHECK_SYS_SSE_SUPPORT
+  if (!x86cpuid_CheckAndRead(&p))
+    return False;
+  return (p.c >> 25) & 1;
+}
+
+BoolInt CPU_IsSupported_PageGB()
+{
+  Cx86cpuid cpuid;
+  if (!x86cpuid_CheckAndRead(&cpuid))
+    return False;
+  {
+    UInt32 d[4] = { 0 };
+    MyCPUID(0x80000000, &d[0], &d[1], &d[2], &d[3]);
+    if (d[0] < 0x80000001)
+      return False;
+  }
+  {
+    UInt32 d[4] = { 0 };
+    MyCPUID(0x80000001, &d[0], &d[1], &d[2], &d[3]);
+    return (d[3] >> 26) & 1;
+  }
+}
+
+#endif
similarity index 95%
rename from deps/lzma-16.04/C/Delta.c
rename to deps/libchdr/deps/lzma-19.00/src/Delta.c
index 6cbbe46..e3edd21 100644 (file)
@@ -1,64 +1,64 @@
-/* Delta.c -- Delta converter\r
-2009-05-26 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Delta.h"\r
-\r
-void Delta_Init(Byte *state)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < DELTA_STATE_SIZE; i++)\r
-    state[i] = 0;\r
-}\r
-\r
-static void MyMemCpy(Byte *dest, const Byte *src, unsigned size)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < size; i++)\r
-    dest[i] = src[i];\r
-}\r
-\r
-void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)\r
-{\r
-  Byte buf[DELTA_STATE_SIZE];\r
-  unsigned j = 0;\r
-  MyMemCpy(buf, state, delta);\r
-  {\r
-    SizeT i;\r
-    for (i = 0; i < size;)\r
-    {\r
-      for (j = 0; j < delta && i < size; i++, j++)\r
-      {\r
-        Byte b = data[i];\r
-        data[i] = (Byte)(b - buf[j]);\r
-        buf[j] = b;\r
-      }\r
-    }\r
-  }\r
-  if (j == delta)\r
-    j = 0;\r
-  MyMemCpy(state, buf + j, delta - j);\r
-  MyMemCpy(state + delta - j, buf, j);\r
-}\r
-\r
-void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)\r
-{\r
-  Byte buf[DELTA_STATE_SIZE];\r
-  unsigned j = 0;\r
-  MyMemCpy(buf, state, delta);\r
-  {\r
-    SizeT i;\r
-    for (i = 0; i < size;)\r
-    {\r
-      for (j = 0; j < delta && i < size; i++, j++)\r
-      {\r
-        buf[j] = data[i] = (Byte)(buf[j] + data[i]);\r
-      }\r
-    }\r
-  }\r
-  if (j == delta)\r
-    j = 0;\r
-  MyMemCpy(state, buf + j, delta - j);\r
-  MyMemCpy(state + delta - j, buf, j);\r
-}\r
+/* Delta.c -- Delta converter
+2009-05-26 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include "Delta.h"
+
+void Delta_Init(Byte *state)
+{
+  unsigned i;
+  for (i = 0; i < DELTA_STATE_SIZE; i++)
+    state[i] = 0;
+}
+
+static void MyMemCpy(Byte *dest, const Byte *src, unsigned size)
+{
+  unsigned i;
+  for (i = 0; i < size; i++)
+    dest[i] = src[i];
+}
+
+void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
+{
+  Byte buf[DELTA_STATE_SIZE];
+  unsigned j = 0;
+  MyMemCpy(buf, state, delta);
+  {
+    SizeT i;
+    for (i = 0; i < size;)
+    {
+      for (j = 0; j < delta && i < size; i++, j++)
+      {
+        Byte b = data[i];
+        data[i] = (Byte)(b - buf[j]);
+        buf[j] = b;
+      }
+    }
+  }
+  if (j == delta)
+    j = 0;
+  MyMemCpy(state, buf + j, delta - j);
+  MyMemCpy(state + delta - j, buf, j);
+}
+
+void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
+{
+  Byte buf[DELTA_STATE_SIZE];
+  unsigned j = 0;
+  MyMemCpy(buf, state, delta);
+  {
+    SizeT i;
+    for (i = 0; i < size;)
+    {
+      for (j = 0; j < delta && i < size; i++, j++)
+      {
+        buf[j] = data[i] = (Byte)(buf[j] + data[i]);
+      }
+    }
+  }
+  if (j == delta)
+    j = 0;
+  MyMemCpy(state, buf + j, delta - j);
+  MyMemCpy(state + delta - j, buf, j);
+}
similarity index 74%
rename from deps/lzma-16.04/C/LzFind.c
rename to deps/libchdr/deps/lzma-19.00/src/LzFind.c
index c335d36..df55e86 100644 (file)
-/* LzFind.c -- Match finder for LZ algorithms\r
-2015-10-15 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-#include "LzFind.h"\r
-#include "LzHash.h"\r
-\r
-#define kEmptyHashValue 0\r
-#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r
-#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r
-#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))\r
-#define kMaxHistorySize ((UInt32)7 << 29)\r
-\r
-#define kStartMaxLen 3\r
-\r
-static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r
-{\r
-  if (!p->directInput)\r
-  {\r
-    alloc->Free(alloc, p->bufferBase);\r
-    p->bufferBase = NULL;\r
-  }\r
-}\r
-\r
-/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r
-\r
-static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r
-{\r
-  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r
-  if (p->directInput)\r
-  {\r
-    p->blockSize = blockSize;\r
-    return 1;\r
-  }\r
-  if (!p->bufferBase || p->blockSize != blockSize)\r
-  {\r
-    LzInWindow_Free(p, alloc);\r
-    p->blockSize = blockSize;\r
-    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r
-  }\r
-  return (p->bufferBase != NULL);\r
-}\r
-\r
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r
-\r
-UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r
-\r
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r
-{\r
-  p->posLimit -= subValue;\r
-  p->pos -= subValue;\r
-  p->streamPos -= subValue;\r
-}\r
-\r
-static void MatchFinder_ReadBlock(CMatchFinder *p)\r
-{\r
-  if (p->streamEndWasReached || p->result != SZ_OK)\r
-    return;\r
-\r
-  /* We use (p->streamPos - p->pos) value. (p->streamPos < p->pos) is allowed. */\r
-\r
-  if (p->directInput)\r
-  {\r
-    UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);\r
-    if (curSize > p->directInputRem)\r
-      curSize = (UInt32)p->directInputRem;\r
-    p->directInputRem -= curSize;\r
-    p->streamPos += curSize;\r
-    if (p->directInputRem == 0)\r
-      p->streamEndWasReached = 1;\r
-    return;\r
-  }\r
-  \r
-  for (;;)\r
-  {\r
-    Byte *dest = p->buffer + (p->streamPos - p->pos);\r
-    size_t size = (p->bufferBase + p->blockSize - dest);\r
-    if (size == 0)\r
-      return;\r
-\r
-    p->result = p->stream->Read(p->stream, dest, &size);\r
-    if (p->result != SZ_OK)\r
-      return;\r
-    if (size == 0)\r
-    {\r
-      p->streamEndWasReached = 1;\r
-      return;\r
-    }\r
-    p->streamPos += (UInt32)size;\r
-    if (p->streamPos - p->pos > p->keepSizeAfter)\r
-      return;\r
-  }\r
-}\r
-\r
-void MatchFinder_MoveBlock(CMatchFinder *p)\r
-{\r
-  memmove(p->bufferBase,\r
-      p->buffer - p->keepSizeBefore,\r
-      (size_t)(p->streamPos - p->pos) + p->keepSizeBefore);\r
-  p->buffer = p->bufferBase + p->keepSizeBefore;\r
-}\r
-\r
-int MatchFinder_NeedMove(CMatchFinder *p)\r
-{\r
-  if (p->directInput)\r
-    return 0;\r
-  /* if (p->streamEndWasReached) return 0; */\r
-  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r
-}\r
-\r
-void MatchFinder_ReadIfRequired(CMatchFinder *p)\r
-{\r
-  if (p->streamEndWasReached)\r
-    return;\r
-  if (p->keepSizeAfter >= p->streamPos - p->pos)\r
-    MatchFinder_ReadBlock(p);\r
-}\r
-\r
-static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r
-{\r
-  if (MatchFinder_NeedMove(p))\r
-    MatchFinder_MoveBlock(p);\r
-  MatchFinder_ReadBlock(p);\r
-}\r
-\r
-static void MatchFinder_SetDefaultSettings(CMatchFinder *p)\r
-{\r
-  p->cutValue = 32;\r
-  p->btMode = 1;\r
-  p->numHashBytes = 4;\r
-  p->bigHash = 0;\r
-}\r
-\r
-#define kCrcPoly 0xEDB88320\r
-\r
-void MatchFinder_Construct(CMatchFinder *p)\r
-{\r
-  UInt32 i;\r
-  p->bufferBase = NULL;\r
-  p->directInput = 0;\r
-  p->hash = NULL;\r
-  MatchFinder_SetDefaultSettings(p);\r
-\r
-  for (i = 0; i < 256; i++)\r
-  {\r
-    UInt32 r = i;\r
-    unsigned j;\r
-    for (j = 0; j < 8; j++)\r
-      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r
-    p->crc[i] = r;\r
-  }\r
-}\r
-\r
-static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->hash);\r
-  p->hash = NULL;\r
-}\r
-\r
-void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r
-{\r
-  MatchFinder_FreeThisClassMemory(p, alloc);\r
-  LzInWindow_Free(p, alloc);\r
-}\r
-\r
-static CLzRef* AllocRefs(size_t num, ISzAlloc *alloc)\r
-{\r
-  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r
-  if (sizeInBytes / sizeof(CLzRef) != num)\r
-    return NULL;\r
-  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r
-}\r
-\r
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r
-    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r
-    ISzAlloc *alloc)\r
-{\r
-  UInt32 sizeReserv;\r
-  \r
-  if (historySize > kMaxHistorySize)\r
-  {\r
-    MatchFinder_Free(p, alloc);\r
-    return 0;\r
-  }\r
-  \r
-  sizeReserv = historySize >> 1;\r
-       if (historySize >= ((UInt32)3 << 30)) sizeReserv = historySize >> 3;\r
-  else if (historySize >= ((UInt32)2 << 30)) sizeReserv = historySize >> 2;\r
-  \r
-  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r
-\r
-  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r
-  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r
-  \r
-  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r
-  \r
-  if (LzInWindow_Create(p, sizeReserv, alloc))\r
-  {\r
-    UInt32 newCyclicBufferSize = historySize + 1;\r
-    UInt32 hs;\r
-    p->matchMaxLen = matchMaxLen;\r
-    {\r
-      p->fixedHashSize = 0;\r
-      if (p->numHashBytes == 2)\r
-        hs = (1 << 16) - 1;\r
-      else\r
-      {\r
-        hs = historySize - 1;\r
-        hs |= (hs >> 1);\r
-        hs |= (hs >> 2);\r
-        hs |= (hs >> 4);\r
-        hs |= (hs >> 8);\r
-        hs >>= 1;\r
-        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r
-        if (hs > (1 << 24))\r
-        {\r
-          if (p->numHashBytes == 3)\r
-            hs = (1 << 24) - 1;\r
-          else\r
-            hs >>= 1;\r
-          /* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */\r
-        }\r
-      }\r
-      p->hashMask = hs;\r
-      hs++;\r
-      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r
-      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r
-      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r
-      hs += p->fixedHashSize;\r
-    }\r
-\r
-    {\r
-      size_t newSize;\r
-      size_t numSons;\r
-      p->historySize = historySize;\r
-      p->hashSizeSum = hs;\r
-      p->cyclicBufferSize = newCyclicBufferSize;\r
-      \r
-      numSons = newCyclicBufferSize;\r
-      if (p->btMode)\r
-        numSons <<= 1;\r
-      newSize = hs + numSons;\r
-\r
-      if (p->hash && p->numRefs == newSize)\r
-        return 1;\r
-      \r
-      MatchFinder_FreeThisClassMemory(p, alloc);\r
-      p->numRefs = newSize;\r
-      p->hash = AllocRefs(newSize, alloc);\r
-      \r
-      if (p->hash)\r
-      {\r
-        p->son = p->hash + p->hashSizeSum;\r
-        return 1;\r
-      }\r
-    }\r
-  }\r
-\r
-  MatchFinder_Free(p, alloc);\r
-  return 0;\r
-}\r
-\r
-static void MatchFinder_SetLimits(CMatchFinder *p)\r
-{\r
-  UInt32 limit = kMaxValForNormalize - p->pos;\r
-  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r
-  \r
-  if (limit2 < limit)\r
-    limit = limit2;\r
-  limit2 = p->streamPos - p->pos;\r
-  \r
-  if (limit2 <= p->keepSizeAfter)\r
-  {\r
-    if (limit2 > 0)\r
-      limit2 = 1;\r
-  }\r
-  else\r
-    limit2 -= p->keepSizeAfter;\r
-  \r
-  if (limit2 < limit)\r
-    limit = limit2;\r
-  \r
-  {\r
-    UInt32 lenLimit = p->streamPos - p->pos;\r
-    if (lenLimit > p->matchMaxLen)\r
-      lenLimit = p->matchMaxLen;\r
-    p->lenLimit = lenLimit;\r
-  }\r
-  p->posLimit = p->pos + limit;\r
-}\r
-\r
-void MatchFinder_Init_2(CMatchFinder *p, int readData)\r
-{\r
-  UInt32 i;\r
-  UInt32 *hash = p->hash;\r
-  UInt32 num = p->hashSizeSum;\r
-  for (i = 0; i < num; i++)\r
-    hash[i] = kEmptyHashValue;\r
-  \r
-  p->cyclicBufferPos = 0;\r
-  p->buffer = p->bufferBase;\r
-  p->pos = p->streamPos = p->cyclicBufferSize;\r
-  p->result = SZ_OK;\r
-  p->streamEndWasReached = 0;\r
-  \r
-  if (readData)\r
-    MatchFinder_ReadBlock(p);\r
-  \r
-  MatchFinder_SetLimits(p);\r
-}\r
-\r
-void MatchFinder_Init(CMatchFinder *p)\r
-{\r
-  MatchFinder_Init_2(p, True);\r
-}\r
-  \r
-static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r
-{\r
-  return (p->pos - p->historySize - 1) & kNormalizeMask;\r
-}\r
-\r
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems)\r
-{\r
-  size_t i;\r
-  for (i = 0; i < numItems; i++)\r
-  {\r
-    UInt32 value = items[i];\r
-    if (value <= subValue)\r
-      value = kEmptyHashValue;\r
-    else\r
-      value -= subValue;\r
-    items[i] = value;\r
-  }\r
-}\r
-\r
-static void MatchFinder_Normalize(CMatchFinder *p)\r
-{\r
-  UInt32 subValue = MatchFinder_GetSubValue(p);\r
-  MatchFinder_Normalize3(subValue, p->hash, p->numRefs);\r
-  MatchFinder_ReduceOffsets(p, subValue);\r
-}\r
-\r
-static void MatchFinder_CheckLimits(CMatchFinder *p)\r
-{\r
-  if (p->pos == kMaxValForNormalize)\r
-    MatchFinder_Normalize(p);\r
-  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r
-    MatchFinder_CheckAndMoveAndRead(p);\r
-  if (p->cyclicBufferPos == p->cyclicBufferSize)\r
-    p->cyclicBufferPos = 0;\r
-  MatchFinder_SetLimits(p);\r
-}\r
-\r
-static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r
-    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r
-    UInt32 *distances, UInt32 maxLen)\r
-{\r
-  son[_cyclicBufferPos] = curMatch;\r
-  for (;;)\r
-  {\r
-    UInt32 delta = pos - curMatch;\r
-    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r
-      return distances;\r
-    {\r
-      const Byte *pb = cur - delta;\r
-      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r
-      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r
-      {\r
-        UInt32 len = 0;\r
-        while (++len != lenLimit)\r
-          if (pb[len] != cur[len])\r
-            break;\r
-        if (maxLen < len)\r
-        {\r
-          *distances++ = maxLen = len;\r
-          *distances++ = delta - 1;\r
-          if (len == lenLimit)\r
-            return distances;\r
-        }\r
-      }\r
-    }\r
-  }\r
-}\r
-\r
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r
-    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r
-    UInt32 *distances, UInt32 maxLen)\r
-{\r
-  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r
-  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r
-  UInt32 len0 = 0, len1 = 0;\r
-  for (;;)\r
-  {\r
-    UInt32 delta = pos - curMatch;\r
-    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r
-    {\r
-      *ptr0 = *ptr1 = kEmptyHashValue;\r
-      return distances;\r
-    }\r
-    {\r
-      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r
-      const Byte *pb = cur - delta;\r
-      UInt32 len = (len0 < len1 ? len0 : len1);\r
-      if (pb[len] == cur[len])\r
-      {\r
-        if (++len != lenLimit && pb[len] == cur[len])\r
-          while (++len != lenLimit)\r
-            if (pb[len] != cur[len])\r
-              break;\r
-        if (maxLen < len)\r
-        {\r
-          *distances++ = maxLen = len;\r
-          *distances++ = delta - 1;\r
-          if (len == lenLimit)\r
-          {\r
-            *ptr1 = pair[0];\r
-            *ptr0 = pair[1];\r
-            return distances;\r
-          }\r
-        }\r
-      }\r
-      if (pb[len] < cur[len])\r
-      {\r
-        *ptr1 = curMatch;\r
-        ptr1 = pair + 1;\r
-        curMatch = *ptr1;\r
-        len1 = len;\r
-      }\r
-      else\r
-      {\r
-        *ptr0 = curMatch;\r
-        ptr0 = pair;\r
-        curMatch = *ptr0;\r
-        len0 = len;\r
-      }\r
-    }\r
-  }\r
-}\r
-\r
-static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r
-    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r
-{\r
-  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r
-  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r
-  UInt32 len0 = 0, len1 = 0;\r
-  for (;;)\r
-  {\r
-    UInt32 delta = pos - curMatch;\r
-    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r
-    {\r
-      *ptr0 = *ptr1 = kEmptyHashValue;\r
-      return;\r
-    }\r
-    {\r
-      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r
-      const Byte *pb = cur - delta;\r
-      UInt32 len = (len0 < len1 ? len0 : len1);\r
-      if (pb[len] == cur[len])\r
-      {\r
-        while (++len != lenLimit)\r
-          if (pb[len] != cur[len])\r
-            break;\r
-        {\r
-          if (len == lenLimit)\r
-          {\r
-            *ptr1 = pair[0];\r
-            *ptr0 = pair[1];\r
-            return;\r
-          }\r
-        }\r
-      }\r
-      if (pb[len] < cur[len])\r
-      {\r
-        *ptr1 = curMatch;\r
-        ptr1 = pair + 1;\r
-        curMatch = *ptr1;\r
-        len1 = len;\r
-      }\r
-      else\r
-      {\r
-        *ptr0 = curMatch;\r
-        ptr0 = pair;\r
-        curMatch = *ptr0;\r
-        len0 = len;\r
-      }\r
-    }\r
-  }\r
-}\r
-\r
-#define MOVE_POS \\r
-  ++p->cyclicBufferPos; \\r
-  p->buffer++; \\r
-  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r
-\r
-#define MOVE_POS_RET MOVE_POS return offset;\r
-\r
-static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r
-\r
-#define GET_MATCHES_HEADER2(minLen, ret_op) \\r
-  UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \\r
-  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\r
-  cur = p->buffer;\r
-\r
-#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r
-#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r
-\r
-#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r
-\r
-#define GET_MATCHES_FOOTER(offset, maxLen) \\r
-  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\r
-  distances + offset, maxLen) - distances); MOVE_POS_RET;\r
-\r
-#define SKIP_FOOTER \\r
-  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r
-\r
-#define UPDATE_maxLen { \\r
-    ptrdiff_t diff = (ptrdiff_t)0 - d2; \\r
-    const Byte *c = cur + maxLen; \\r
-    const Byte *lim = cur + lenLimit; \\r
-    for (; c != lim; c++) if (*(c + diff) != *c) break; \\r
-    maxLen = (UInt32)(c - cur); }\r
-\r
-static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
-{\r
-  UInt32 offset;\r
-  GET_MATCHES_HEADER(2)\r
-  HASH2_CALC;\r
-  curMatch = p->hash[hv];\r
-  p->hash[hv] = p->pos;\r
-  offset = 0;\r
-  GET_MATCHES_FOOTER(offset, 1)\r
-}\r
-\r
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
-{\r
-  UInt32 offset;\r
-  GET_MATCHES_HEADER(3)\r
-  HASH_ZIP_CALC;\r
-  curMatch = p->hash[hv];\r
-  p->hash[hv] = p->pos;\r
-  offset = 0;\r
-  GET_MATCHES_FOOTER(offset, 2)\r
-}\r
-\r
-static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
-{\r
-  UInt32 h2, d2, maxLen, offset, pos;\r
-  UInt32 *hash;\r
-  GET_MATCHES_HEADER(3)\r
-\r
-  HASH3_CALC;\r
-\r
-  hash = p->hash;\r
-  pos = p->pos;\r
-\r
-  d2 = pos - hash[h2];\r
-\r
-  curMatch = hash[kFix3HashSize + hv];\r
-  \r
-  hash[h2] = pos;\r
-  hash[kFix3HashSize + hv] = pos;\r
-\r
-  maxLen = 2;\r
-  offset = 0;\r
-\r
-  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
-  {\r
-    UPDATE_maxLen\r
-    distances[0] = maxLen;\r
-    distances[1] = d2 - 1;\r
-    offset = 2;\r
-    if (maxLen == lenLimit)\r
-    {\r
-      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
-      MOVE_POS_RET;\r
-    }\r
-  }\r
-  \r
-  GET_MATCHES_FOOTER(offset, maxLen)\r
-}\r
-\r
-static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
-{\r
-  UInt32 h2, h3, d2, d3, maxLen, offset, pos;\r
-  UInt32 *hash;\r
-  GET_MATCHES_HEADER(4)\r
-\r
-  HASH4_CALC;\r
-\r
-  hash = p->hash;\r
-  pos = p->pos;\r
-\r
-  d2 = pos - hash[                h2];\r
-  d3 = pos - hash[kFix3HashSize + h3];\r
-\r
-  curMatch = hash[kFix4HashSize + hv];\r
-\r
-  hash[                h2] = pos;\r
-  hash[kFix3HashSize + h3] = pos;\r
-  hash[kFix4HashSize + hv] = pos;\r
-\r
-  maxLen = 0;\r
-  offset = 0;\r
-  \r
-  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
-  {\r
-    distances[0] = maxLen = 2;\r
-    distances[1] = d2 - 1;\r
-    offset = 2;\r
-  }\r
-  \r
-  if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
-  {\r
-    maxLen = 3;\r
-    distances[offset + 1] = d3 - 1;\r
-    offset += 2;\r
-    d2 = d3;\r
-  }\r
-  \r
-  if (offset != 0)\r
-  {\r
-    UPDATE_maxLen\r
-    distances[offset - 2] = maxLen;\r
-    if (maxLen == lenLimit)\r
-    {\r
-      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
-      MOVE_POS_RET;\r
-    }\r
-  }\r
-  \r
-  if (maxLen < 3)\r
-    maxLen = 3;\r
-  \r
-  GET_MATCHES_FOOTER(offset, maxLen)\r
-}\r
-\r
-/*\r
-static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
-{\r
-  UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos;\r
-  UInt32 *hash;\r
-  GET_MATCHES_HEADER(5)\r
-\r
-  HASH5_CALC;\r
-\r
-  hash = p->hash;\r
-  pos = p->pos;\r
-\r
-  d2 = pos - hash[                h2];\r
-  d3 = pos - hash[kFix3HashSize + h3];\r
-  d4 = pos - hash[kFix4HashSize + h4];\r
-\r
-  curMatch = hash[kFix5HashSize + hv];\r
-\r
-  hash[                h2] = pos;\r
-  hash[kFix3HashSize + h3] = pos;\r
-  hash[kFix4HashSize + h4] = pos;\r
-  hash[kFix5HashSize + hv] = pos;\r
-\r
-  maxLen = 0;\r
-  offset = 0;\r
-\r
-  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
-  {\r
-    distances[0] = maxLen = 2;\r
-    distances[1] = d2 - 1;\r
-    offset = 2;\r
-    if (*(cur - d2 + 2) == cur[2])\r
-      distances[0] = maxLen = 3;\r
-    else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
-    {\r
-      distances[2] = maxLen = 3;\r
-      distances[3] = d3 - 1;\r
-      offset = 4;\r
-      d2 = d3;\r
-    }\r
-  }\r
-  else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
-  {\r
-    distances[0] = maxLen = 3;\r
-    distances[1] = d3 - 1;\r
-    offset = 2;\r
-    d2 = d3;\r
-  }\r
-  \r
-  if (d2 != d4 && d4 < p->cyclicBufferSize\r
-      && *(cur - d4) == *cur\r
-      && *(cur - d4 + 3) == *(cur + 3))\r
-  {\r
-    maxLen = 4;\r
-    distances[offset + 1] = d4 - 1;\r
-    offset += 2;\r
-    d2 = d4;\r
-  }\r
-  \r
-  if (offset != 0)\r
-  {\r
-    UPDATE_maxLen\r
-    distances[offset - 2] = maxLen;\r
-    if (maxLen == lenLimit)\r
-    {\r
-      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
-      MOVE_POS_RET;\r
-    }\r
-  }\r
-\r
-  if (maxLen < 4)\r
-    maxLen = 4;\r
-  \r
-  GET_MATCHES_FOOTER(offset, maxLen)\r
-}\r
-*/\r
-\r
-static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
-{\r
-  UInt32 h2, h3, d2, d3, maxLen, offset, pos;\r
-  UInt32 *hash;\r
-  GET_MATCHES_HEADER(4)\r
-\r
-  HASH4_CALC;\r
-\r
-  hash = p->hash;\r
-  pos = p->pos;\r
-  \r
-  d2 = pos - hash[                h2];\r
-  d3 = pos - hash[kFix3HashSize + h3];\r
-  \r
-  curMatch = hash[kFix4HashSize + hv];\r
-\r
-  hash[                h2] = pos;\r
-  hash[kFix3HashSize + h3] = pos;\r
-  hash[kFix4HashSize + hv] = pos;\r
-\r
-  maxLen = 0;\r
-  offset = 0;\r
-\r
-  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
-  {\r
-    distances[0] = maxLen = 2;\r
-    distances[1] = d2 - 1;\r
-    offset = 2;\r
-  }\r
-  \r
-  if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
-  {\r
-    maxLen = 3;\r
-    distances[offset + 1] = d3 - 1;\r
-    offset += 2;\r
-    d2 = d3;\r
-  }\r
-  \r
-  if (offset != 0)\r
-  {\r
-    UPDATE_maxLen\r
-    distances[offset - 2] = maxLen;\r
-    if (maxLen == lenLimit)\r
-    {\r
-      p->son[p->cyclicBufferPos] = curMatch;\r
-      MOVE_POS_RET;\r
-    }\r
-  }\r
-  \r
-  if (maxLen < 3)\r
-    maxLen = 3;\r
-\r
-  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
-      distances + offset, maxLen) - (distances));\r
-  MOVE_POS_RET\r
-}\r
-\r
-/*\r
-static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
-{\r
-  UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos\r
-  UInt32 *hash;\r
-  GET_MATCHES_HEADER(5)\r
-\r
-  HASH5_CALC;\r
-\r
-  hash = p->hash;\r
-  pos = p->pos;\r
-  \r
-  d2 = pos - hash[                h2];\r
-  d3 = pos - hash[kFix3HashSize + h3];\r
-  d4 = pos - hash[kFix4HashSize + h4];\r
-\r
-  curMatch = hash[kFix5HashSize + hv];\r
-\r
-  hash[                h2] = pos;\r
-  hash[kFix3HashSize + h3] = pos;\r
-  hash[kFix4HashSize + h4] = pos;\r
-  hash[kFix5HashSize + hv] = pos;\r
-\r
-  maxLen = 0;\r
-  offset = 0;\r
-\r
-  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
-  {\r
-    distances[0] = maxLen = 2;\r
-    distances[1] = d2 - 1;\r
-    offset = 2;\r
-    if (*(cur - d2 + 2) == cur[2])\r
-      distances[0] = maxLen = 3;\r
-    else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
-    {\r
-      distances[2] = maxLen = 3;\r
-      distances[3] = d3 - 1;\r
-      offset = 4;\r
-      d2 = d3;\r
-    }\r
-  }\r
-  else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
-  {\r
-    distances[0] = maxLen = 3;\r
-    distances[1] = d3 - 1;\r
-    offset = 2;\r
-    d2 = d3;\r
-  }\r
-  \r
-  if (d2 != d4 && d4 < p->cyclicBufferSize\r
-      && *(cur - d4) == *cur\r
-      && *(cur - d4 + 3) == *(cur + 3))\r
-  {\r
-    maxLen = 4;\r
-    distances[offset + 1] = d4 - 1;\r
-    offset += 2;\r
-    d2 = d4;\r
-  }\r
-  \r
-  if (offset != 0)\r
-  {\r
-    UPDATE_maxLen\r
-    distances[offset - 2] = maxLen;\r
-    if (maxLen == lenLimit)\r
-    {\r
-      p->son[p->cyclicBufferPos] = curMatch;\r
-      MOVE_POS_RET;\r
-    }\r
-  }\r
-  \r
-  if (maxLen < 4)\r
-    maxLen = 4;\r
-\r
-  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
-      distances + offset, maxLen) - (distances));\r
-  MOVE_POS_RET\r
-}\r
-*/\r
-\r
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
-{\r
-  UInt32 offset;\r
-  GET_MATCHES_HEADER(3)\r
-  HASH_ZIP_CALC;\r
-  curMatch = p->hash[hv];\r
-  p->hash[hv] = p->pos;\r
-  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
-      distances, 2) - (distances));\r
-  MOVE_POS_RET\r
-}\r
-\r
-static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
-{\r
-  do\r
-  {\r
-    SKIP_HEADER(2)\r
-    HASH2_CALC;\r
-    curMatch = p->hash[hv];\r
-    p->hash[hv] = p->pos;\r
-    SKIP_FOOTER\r
-  }\r
-  while (--num != 0);\r
-}\r
-\r
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
-{\r
-  do\r
-  {\r
-    SKIP_HEADER(3)\r
-    HASH_ZIP_CALC;\r
-    curMatch = p->hash[hv];\r
-    p->hash[hv] = p->pos;\r
-    SKIP_FOOTER\r
-  }\r
-  while (--num != 0);\r
-}\r
-\r
-static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
-{\r
-  do\r
-  {\r
-    UInt32 h2;\r
-    UInt32 *hash;\r
-    SKIP_HEADER(3)\r
-    HASH3_CALC;\r
-    hash = p->hash;\r
-    curMatch = hash[kFix3HashSize + hv];\r
-    hash[h2] =\r
-    hash[kFix3HashSize + hv] = p->pos;\r
-    SKIP_FOOTER\r
-  }\r
-  while (--num != 0);\r
-}\r
-\r
-static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
-{\r
-  do\r
-  {\r
-    UInt32 h2, h3;\r
-    UInt32 *hash;\r
-    SKIP_HEADER(4)\r
-    HASH4_CALC;\r
-    hash = p->hash;\r
-    curMatch = hash[kFix4HashSize + hv];\r
-    hash[                h2] =\r
-    hash[kFix3HashSize + h3] =\r
-    hash[kFix4HashSize + hv] = p->pos;\r
-    SKIP_FOOTER\r
-  }\r
-  while (--num != 0);\r
-}\r
-\r
-/*\r
-static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
-{\r
-  do\r
-  {\r
-    UInt32 h2, h3, h4;\r
-    UInt32 *hash;\r
-    SKIP_HEADER(5)\r
-    HASH5_CALC;\r
-    hash = p->hash;\r
-    curMatch = hash[kFix5HashSize + hv];\r
-    hash[                h2] =\r
-    hash[kFix3HashSize + h3] =\r
-    hash[kFix4HashSize + h4] =\r
-    hash[kFix5HashSize + hv] = p->pos;\r
-    SKIP_FOOTER\r
-  }\r
-  while (--num != 0);\r
-}\r
-*/\r
-\r
-static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
-{\r
-  do\r
-  {\r
-    UInt32 h2, h3;\r
-    UInt32 *hash;\r
-    SKIP_HEADER(4)\r
-    HASH4_CALC;\r
-    hash = p->hash;\r
-    curMatch = hash[kFix4HashSize + hv];\r
-    hash[                h2] =\r
-    hash[kFix3HashSize + h3] =\r
-    hash[kFix4HashSize + hv] = p->pos;\r
-    p->son[p->cyclicBufferPos] = curMatch;\r
-    MOVE_POS\r
-  }\r
-  while (--num != 0);\r
-}\r
-\r
-/*\r
-static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
-{\r
-  do\r
-  {\r
-    UInt32 h2, h3, h4;\r
-    UInt32 *hash;\r
-    SKIP_HEADER(5)\r
-    HASH5_CALC;\r
-    hash = p->hash;\r
-    curMatch = p->hash[kFix5HashSize + hv];\r
-    hash[                h2] =\r
-    hash[kFix3HashSize + h3] =\r
-    hash[kFix4HashSize + h4] =\r
-    hash[kFix5HashSize + hv] = p->pos;\r
-    p->son[p->cyclicBufferPos] = curMatch;\r
-    MOVE_POS\r
-  }\r
-  while (--num != 0);\r
-}\r
-*/\r
-\r
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
-{\r
-  do\r
-  {\r
-    SKIP_HEADER(3)\r
-    HASH_ZIP_CALC;\r
-    curMatch = p->hash[hv];\r
-    p->hash[hv] = p->pos;\r
-    p->son[p->cyclicBufferPos] = curMatch;\r
-    MOVE_POS\r
-  }\r
-  while (--num != 0);\r
-}\r
-\r
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r
-{\r
-  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r
-  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r
-  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r
-  if (!p->btMode)\r
-  {\r
-    /* if (p->numHashBytes <= 4) */\r
-    {\r
-      vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r
-      vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r
-    }\r
-    /*\r
-    else\r
-    {\r
-      vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches;\r
-      vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip;\r
-    }\r
-    */\r
-  }\r
-  else if (p->numHashBytes == 2)\r
-  {\r
-    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r
-    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r
-  }\r
-  else if (p->numHashBytes == 3)\r
-  {\r
-    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r
-    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r
-  }\r
-  else /* if (p->numHashBytes == 4) */\r
-  {\r
-    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r
-    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r
-  }\r
-  /*\r
-  else\r
-  {\r
-    vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches;\r
-    vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip;\r
-  }\r
-  */\r
-}\r
+/* LzFind.c -- Match finder for LZ algorithms
+2018-07-08 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include <string.h>
+
+#include "LzFind.h"
+#include "LzHash.h"
+
+#define kEmptyHashValue 0
+#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
+#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
+#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))
+#define kMaxHistorySize ((UInt32)7 << 29)
+
+#define kStartMaxLen 3
+
+static void LzInWindow_Free(CMatchFinder *p, ISzAllocPtr alloc)
+{
+  if (!p->directInput)
+  {
+    ISzAlloc_Free(alloc, p->bufferBase);
+    p->bufferBase = NULL;
+  }
+}
+
+/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
+
+static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAllocPtr alloc)
+{
+  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
+  if (p->directInput)
+  {
+    p->blockSize = blockSize;
+    return 1;
+  }
+  if (!p->bufferBase || p->blockSize != blockSize)
+  {
+    LzInWindow_Free(p, alloc);
+    p->blockSize = blockSize;
+    p->bufferBase = (Byte *)ISzAlloc_Alloc(alloc, (size_t)blockSize);
+  }
+  return (p->bufferBase != NULL);
+}
+
+Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
+
+UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
+
+void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
+{
+  p->posLimit -= subValue;
+  p->pos -= subValue;
+  p->streamPos -= subValue;
+}
+
+static void MatchFinder_ReadBlock(CMatchFinder *p)
+{
+  if (p->streamEndWasReached || p->result != SZ_OK)
+    return;
+
+  /* We use (p->streamPos - p->pos) value. (p->streamPos < p->pos) is allowed. */
+
+  if (p->directInput)
+  {
+    UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);
+    if (curSize > p->directInputRem)
+      curSize = (UInt32)p->directInputRem;
+    p->directInputRem -= curSize;
+    p->streamPos += curSize;
+    if (p->directInputRem == 0)
+      p->streamEndWasReached = 1;
+    return;
+  }
+  
+  for (;;)
+  {
+    Byte *dest = p->buffer + (p->streamPos - p->pos);
+    size_t size = (p->bufferBase + p->blockSize - dest);
+    if (size == 0)
+      return;
+
+    p->result = ISeqInStream_Read(p->stream, dest, &size);
+    if (p->result != SZ_OK)
+      return;
+    if (size == 0)
+    {
+      p->streamEndWasReached = 1;
+      return;
+    }
+    p->streamPos += (UInt32)size;
+    if (p->streamPos - p->pos > p->keepSizeAfter)
+      return;
+  }
+}
+
+void MatchFinder_MoveBlock(CMatchFinder *p)
+{
+  memmove(p->bufferBase,
+      p->buffer - p->keepSizeBefore,
+      (size_t)(p->streamPos - p->pos) + p->keepSizeBefore);
+  p->buffer = p->bufferBase + p->keepSizeBefore;
+}
+
+int MatchFinder_NeedMove(CMatchFinder *p)
+{
+  if (p->directInput)
+    return 0;
+  /* if (p->streamEndWasReached) return 0; */
+  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
+}
+
+void MatchFinder_ReadIfRequired(CMatchFinder *p)
+{
+  if (p->streamEndWasReached)
+    return;
+  if (p->keepSizeAfter >= p->streamPos - p->pos)
+    MatchFinder_ReadBlock(p);
+}
+
+static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
+{
+  if (MatchFinder_NeedMove(p))
+    MatchFinder_MoveBlock(p);
+  MatchFinder_ReadBlock(p);
+}
+
+static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
+{
+  p->cutValue = 32;
+  p->btMode = 1;
+  p->numHashBytes = 4;
+  p->bigHash = 0;
+}
+
+#define kCrcPoly 0xEDB88320
+
+void MatchFinder_Construct(CMatchFinder *p)
+{
+  unsigned i;
+  p->bufferBase = NULL;
+  p->directInput = 0;
+  p->hash = NULL;
+  p->expectedDataSize = (UInt64)(Int64)-1;
+  MatchFinder_SetDefaultSettings(p);
+
+  for (i = 0; i < 256; i++)
+  {
+    UInt32 r = (UInt32)i;
+    unsigned j;
+    for (j = 0; j < 8; j++)
+      r = (r >> 1) ^ (kCrcPoly & ((UInt32)0 - (r & 1)));
+    p->crc[i] = r;
+  }
+}
+
+static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAllocPtr alloc)
+{
+  ISzAlloc_Free(alloc, p->hash);
+  p->hash = NULL;
+}
+
+void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc)
+{
+  MatchFinder_FreeThisClassMemory(p, alloc);
+  LzInWindow_Free(p, alloc);
+}
+
+static CLzRef* AllocRefs(size_t num, ISzAllocPtr alloc)
+{
+  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
+  if (sizeInBytes / sizeof(CLzRef) != num)
+    return NULL;
+  return (CLzRef *)ISzAlloc_Alloc(alloc, sizeInBytes);
+}
+
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
+    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
+    ISzAllocPtr alloc)
+{
+  UInt32 sizeReserv;
+  
+  if (historySize > kMaxHistorySize)
+  {
+    MatchFinder_Free(p, alloc);
+    return 0;
+  }
+  
+  sizeReserv = historySize >> 1;
+       if (historySize >= ((UInt32)3 << 30)) sizeReserv = historySize >> 3;
+  else if (historySize >= ((UInt32)2 << 30)) sizeReserv = historySize >> 2;
+  
+  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
+
+  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
+  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
+  
+  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
+  
+  if (LzInWindow_Create(p, sizeReserv, alloc))
+  {
+    UInt32 newCyclicBufferSize = historySize + 1;
+    UInt32 hs;
+    p->matchMaxLen = matchMaxLen;
+    {
+      p->fixedHashSize = 0;
+      if (p->numHashBytes == 2)
+        hs = (1 << 16) - 1;
+      else
+      {
+        hs = historySize;
+        if (hs > p->expectedDataSize)
+          hs = (UInt32)p->expectedDataSize;
+        if (hs != 0)
+          hs--;
+        hs |= (hs >> 1);
+        hs |= (hs >> 2);
+        hs |= (hs >> 4);
+        hs |= (hs >> 8);
+        hs >>= 1;
+        hs |= 0xFFFF; /* don't change it! It's required for Deflate */
+        if (hs > (1 << 24))
+        {
+          if (p->numHashBytes == 3)
+            hs = (1 << 24) - 1;
+          else
+            hs >>= 1;
+          /* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */
+        }
+      }
+      p->hashMask = hs;
+      hs++;
+      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
+      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
+      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
+      hs += p->fixedHashSize;
+    }
+
+    {
+      size_t newSize;
+      size_t numSons;
+      p->historySize = historySize;
+      p->hashSizeSum = hs;
+      p->cyclicBufferSize = newCyclicBufferSize;
+      
+      numSons = newCyclicBufferSize;
+      if (p->btMode)
+        numSons <<= 1;
+      newSize = hs + numSons;
+
+      if (p->hash && p->numRefs == newSize)
+        return 1;
+      
+      MatchFinder_FreeThisClassMemory(p, alloc);
+      p->numRefs = newSize;
+      p->hash = AllocRefs(newSize, alloc);
+      
+      if (p->hash)
+      {
+        p->son = p->hash + p->hashSizeSum;
+        return 1;
+      }
+    }
+  }
+
+  MatchFinder_Free(p, alloc);
+  return 0;
+}
+
+static void MatchFinder_SetLimits(CMatchFinder *p)
+{
+  UInt32 limit = kMaxValForNormalize - p->pos;
+  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
+  
+  if (limit2 < limit)
+    limit = limit2;
+  limit2 = p->streamPos - p->pos;
+  
+  if (limit2 <= p->keepSizeAfter)
+  {
+    if (limit2 > 0)
+      limit2 = 1;
+  }
+  else
+    limit2 -= p->keepSizeAfter;
+  
+  if (limit2 < limit)
+    limit = limit2;
+  
+  {
+    UInt32 lenLimit = p->streamPos - p->pos;
+    if (lenLimit > p->matchMaxLen)
+      lenLimit = p->matchMaxLen;
+    p->lenLimit = lenLimit;
+  }
+  p->posLimit = p->pos + limit;
+}
+
+
+void MatchFinder_Init_LowHash(CMatchFinder *p)
+{
+  size_t i;
+  CLzRef *items = p->hash;
+  size_t numItems = p->fixedHashSize;
+  for (i = 0; i < numItems; i++)
+    items[i] = kEmptyHashValue;
+}
+
+
+void MatchFinder_Init_HighHash(CMatchFinder *p)
+{
+  size_t i;
+  CLzRef *items = p->hash + p->fixedHashSize;
+  size_t numItems = (size_t)p->hashMask + 1;
+  for (i = 0; i < numItems; i++)
+    items[i] = kEmptyHashValue;
+}
+
+
+void MatchFinder_Init_3(CMatchFinder *p, int readData)
+{
+  p->cyclicBufferPos = 0;
+  p->buffer = p->bufferBase;
+  p->pos =
+  p->streamPos = p->cyclicBufferSize;
+  p->result = SZ_OK;
+  p->streamEndWasReached = 0;
+  
+  if (readData)
+    MatchFinder_ReadBlock(p);
+  
+  MatchFinder_SetLimits(p);
+}
+
+
+void MatchFinder_Init(CMatchFinder *p)
+{
+  MatchFinder_Init_HighHash(p);
+  MatchFinder_Init_LowHash(p);
+  MatchFinder_Init_3(p, True);
+}
+
+  
+static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
+{
+  return (p->pos - p->historySize - 1) & kNormalizeMask;
+}
+
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems)
+{
+  size_t i;
+  for (i = 0; i < numItems; i++)
+  {
+    UInt32 value = items[i];
+    if (value <= subValue)
+      value = kEmptyHashValue;
+    else
+      value -= subValue;
+    items[i] = value;
+  }
+}
+
+static void MatchFinder_Normalize(CMatchFinder *p)
+{
+  UInt32 subValue = MatchFinder_GetSubValue(p);
+  MatchFinder_Normalize3(subValue, p->hash, p->numRefs);
+  MatchFinder_ReduceOffsets(p, subValue);
+}
+
+
+MY_NO_INLINE
+static void MatchFinder_CheckLimits(CMatchFinder *p)
+{
+  if (p->pos == kMaxValForNormalize)
+    MatchFinder_Normalize(p);
+  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
+    MatchFinder_CheckAndMoveAndRead(p);
+  if (p->cyclicBufferPos == p->cyclicBufferSize)
+    p->cyclicBufferPos = 0;
+  MatchFinder_SetLimits(p);
+}
+
+
+/*
+  (lenLimit > maxLen)
+*/
+MY_FORCE_INLINE
+static UInt32 * Hc_GetMatchesSpec(unsigned lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
+    UInt32 *distances, unsigned maxLen)
+{
+  /*
+  son[_cyclicBufferPos] = curMatch;
+  for (;;)
+  {
+    UInt32 delta = pos - curMatch;
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
+      return distances;
+    {
+      const Byte *pb = cur - delta;
+      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
+      if (pb[maxLen] == cur[maxLen] && *pb == *cur)
+      {
+        UInt32 len = 0;
+        while (++len != lenLimit)
+          if (pb[len] != cur[len])
+            break;
+        if (maxLen < len)
+        {
+          maxLen = len;
+          *distances++ = len;
+          *distances++ = delta - 1;
+          if (len == lenLimit)
+            return distances;
+        }
+      }
+    }
+  }
+  */
+
+  const Byte *lim = cur + lenLimit;
+  son[_cyclicBufferPos] = curMatch;
+  do
+  {
+    UInt32 delta = pos - curMatch;
+    if (delta >= _cyclicBufferSize)
+      break;
+    {
+      ptrdiff_t diff;
+      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
+      diff = (ptrdiff_t)0 - delta;
+      if (cur[maxLen] == cur[maxLen + diff])
+      {
+        const Byte *c = cur;
+        while (*c == c[diff])
+        {
+          if (++c == lim)
+          {
+            distances[0] = (UInt32)(lim - cur);
+            distances[1] = delta - 1;
+            return distances + 2;
+          }
+        }
+        {
+          unsigned len = (unsigned)(c - cur);
+          if (maxLen < len)
+          {
+            maxLen = len;
+            distances[0] = (UInt32)len;
+            distances[1] = delta - 1;
+            distances += 2;
+          }
+        }
+      }
+    }
+  }
+  while (--cutValue);
+  
+  return distances;
+}
+
+
+MY_FORCE_INLINE
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
+    UInt32 *distances, UInt32 maxLen)
+{
+  CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
+  CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
+  unsigned len0 = 0, len1 = 0;
+  for (;;)
+  {
+    UInt32 delta = pos - curMatch;
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
+    {
+      *ptr0 = *ptr1 = kEmptyHashValue;
+      return distances;
+    }
+    {
+      CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+      const Byte *pb = cur - delta;
+      unsigned len = (len0 < len1 ? len0 : len1);
+      UInt32 pair0 = pair[0];
+      if (pb[len] == cur[len])
+      {
+        if (++len != lenLimit && pb[len] == cur[len])
+          while (++len != lenLimit)
+            if (pb[len] != cur[len])
+              break;
+        if (maxLen < len)
+        {
+          maxLen = (UInt32)len;
+          *distances++ = (UInt32)len;
+          *distances++ = delta - 1;
+          if (len == lenLimit)
+          {
+            *ptr1 = pair0;
+            *ptr0 = pair[1];
+            return distances;
+          }
+        }
+      }
+      if (pb[len] < cur[len])
+      {
+        *ptr1 = curMatch;
+        ptr1 = pair + 1;
+        curMatch = *ptr1;
+        len1 = len;
+      }
+      else
+      {
+        *ptr0 = curMatch;
+        ptr0 = pair;
+        curMatch = *ptr0;
+        len0 = len;
+      }
+    }
+  }
+}
+
+static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
+{
+  CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
+  CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
+  unsigned len0 = 0, len1 = 0;
+  for (;;)
+  {
+    UInt32 delta = pos - curMatch;
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
+    {
+      *ptr0 = *ptr1 = kEmptyHashValue;
+      return;
+    }
+    {
+      CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+      const Byte *pb = cur - delta;
+      unsigned len = (len0 < len1 ? len0 : len1);
+      if (pb[len] == cur[len])
+      {
+        while (++len != lenLimit)
+          if (pb[len] != cur[len])
+            break;
+        {
+          if (len == lenLimit)
+          {
+            *ptr1 = pair[0];
+            *ptr0 = pair[1];
+            return;
+          }
+        }
+      }
+      if (pb[len] < cur[len])
+      {
+        *ptr1 = curMatch;
+        ptr1 = pair + 1;
+        curMatch = *ptr1;
+        len1 = len;
+      }
+      else
+      {
+        *ptr0 = curMatch;
+        ptr0 = pair;
+        curMatch = *ptr0;
+        len0 = len;
+      }
+    }
+  }
+}
+
+#define MOVE_POS \
+  ++p->cyclicBufferPos; \
+  p->buffer++; \
+  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
+
+#define MOVE_POS_RET MOVE_POS return (UInt32)offset;
+
+static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
+
+#define GET_MATCHES_HEADER2(minLen, ret_op) \
+  unsigned lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \
+  lenLimit = (unsigned)p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
+  cur = p->buffer;
+
+#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
+#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)
+
+#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
+
+#define GET_MATCHES_FOOTER(offset, maxLen) \
+  offset = (unsigned)(GetMatchesSpec1((UInt32)lenLimit, curMatch, MF_PARAMS(p), \
+  distances + offset, (UInt32)maxLen) - distances); MOVE_POS_RET;
+
+#define SKIP_FOOTER \
+  SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
+
+#define UPDATE_maxLen { \
+    ptrdiff_t diff = (ptrdiff_t)0 - d2; \
+    const Byte *c = cur + maxLen; \
+    const Byte *lim = cur + lenLimit; \
+    for (; c != lim; c++) if (*(c + diff) != *c) break; \
+    maxLen = (unsigned)(c - cur); }
+
+static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  unsigned offset;
+  GET_MATCHES_HEADER(2)
+  HASH2_CALC;
+  curMatch = p->hash[hv];
+  p->hash[hv] = p->pos;
+  offset = 0;
+  GET_MATCHES_FOOTER(offset, 1)
+}
+
+UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  unsigned offset;
+  GET_MATCHES_HEADER(3)
+  HASH_ZIP_CALC;
+  curMatch = p->hash[hv];
+  p->hash[hv] = p->pos;
+  offset = 0;
+  GET_MATCHES_FOOTER(offset, 2)
+}
+
+static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 h2, d2, pos;
+  unsigned maxLen, offset;
+  UInt32 *hash;
+  GET_MATCHES_HEADER(3)
+
+  HASH3_CALC;
+
+  hash = p->hash;
+  pos = p->pos;
+
+  d2 = pos - hash[h2];
+
+  curMatch = (hash + kFix3HashSize)[hv];
+  
+  hash[h2] = pos;
+  (hash + kFix3HashSize)[hv] = pos;
+
+  maxLen = 2;
+  offset = 0;
+
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
+  {
+    UPDATE_maxLen
+    distances[0] = (UInt32)maxLen;
+    distances[1] = d2 - 1;
+    offset = 2;
+    if (maxLen == lenLimit)
+    {
+      SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
+      MOVE_POS_RET;
+    }
+  }
+  
+  GET_MATCHES_FOOTER(offset, maxLen)
+}
+
+static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 h2, h3, d2, d3, pos;
+  unsigned maxLen, offset;
+  UInt32 *hash;
+  GET_MATCHES_HEADER(4)
+
+  HASH4_CALC;
+
+  hash = p->hash;
+  pos = p->pos;
+
+  d2 = pos - hash                  [h2];
+  d3 = pos - (hash + kFix3HashSize)[h3];
+
+  curMatch = (hash + kFix4HashSize)[hv];
+
+  hash                  [h2] = pos;
+  (hash + kFix3HashSize)[h3] = pos;
+  (hash + kFix4HashSize)[hv] = pos;
+
+  maxLen = 0;
+  offset = 0;
+  
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
+  {
+    maxLen = 2;
+    distances[0] = 2;
+    distances[1] = d2 - 1;
+    offset = 2;
+  }
+  
+  if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
+  {
+    maxLen = 3;
+    distances[(size_t)offset + 1] = d3 - 1;
+    offset += 2;
+    d2 = d3;
+  }
+  
+  if (offset != 0)
+  {
+    UPDATE_maxLen
+    distances[(size_t)offset - 2] = (UInt32)maxLen;
+    if (maxLen == lenLimit)
+    {
+      SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
+      MOVE_POS_RET;
+    }
+  }
+  
+  if (maxLen < 3)
+    maxLen = 3;
+  
+  GET_MATCHES_FOOTER(offset, maxLen)
+}
+
+/*
+static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos;
+  UInt32 *hash;
+  GET_MATCHES_HEADER(5)
+
+  HASH5_CALC;
+
+  hash = p->hash;
+  pos = p->pos;
+
+  d2 = pos - hash                  [h2];
+  d3 = pos - (hash + kFix3HashSize)[h3];
+  d4 = pos - (hash + kFix4HashSize)[h4];
+
+  curMatch = (hash + kFix5HashSize)[hv];
+
+  hash                  [h2] = pos;
+  (hash + kFix3HashSize)[h3] = pos;
+  (hash + kFix4HashSize)[h4] = pos;
+  (hash + kFix5HashSize)[hv] = pos;
+
+  maxLen = 0;
+  offset = 0;
+
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
+  {
+    distances[0] = maxLen = 2;
+    distances[1] = d2 - 1;
+    offset = 2;
+    if (*(cur - d2 + 2) == cur[2])
+      distances[0] = maxLen = 3;
+    else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
+    {
+      distances[2] = maxLen = 3;
+      distances[3] = d3 - 1;
+      offset = 4;
+      d2 = d3;
+    }
+  }
+  else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
+  {
+    distances[0] = maxLen = 3;
+    distances[1] = d3 - 1;
+    offset = 2;
+    d2 = d3;
+  }
+  
+  if (d2 != d4 && d4 < p->cyclicBufferSize
+      && *(cur - d4) == *cur
+      && *(cur - d4 + 3) == *(cur + 3))
+  {
+    maxLen = 4;
+    distances[(size_t)offset + 1] = d4 - 1;
+    offset += 2;
+    d2 = d4;
+  }
+  
+  if (offset != 0)
+  {
+    UPDATE_maxLen
+    distances[(size_t)offset - 2] = maxLen;
+    if (maxLen == lenLimit)
+    {
+      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
+      MOVE_POS_RET;
+    }
+  }
+
+  if (maxLen < 4)
+    maxLen = 4;
+  
+  GET_MATCHES_FOOTER(offset, maxLen)
+}
+*/
+
+static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 h2, h3, d2, d3, pos;
+  unsigned maxLen, offset;
+  UInt32 *hash;
+  GET_MATCHES_HEADER(4)
+
+  HASH4_CALC;
+
+  hash = p->hash;
+  pos = p->pos;
+  
+  d2 = pos - hash                  [h2];
+  d3 = pos - (hash + kFix3HashSize)[h3];
+  curMatch = (hash + kFix4HashSize)[hv];
+
+  hash                  [h2] = pos;
+  (hash + kFix3HashSize)[h3] = pos;
+  (hash + kFix4HashSize)[hv] = pos;
+
+  maxLen = 0;
+  offset = 0;
+
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
+  {
+    maxLen = 2;
+    distances[0] = 2;
+    distances[1] = d2 - 1;
+    offset = 2;
+  }
+  
+  if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
+  {
+    maxLen = 3;
+    distances[(size_t)offset + 1] = d3 - 1;
+    offset += 2;
+    d2 = d3;
+  }
+  
+  if (offset != 0)
+  {
+    UPDATE_maxLen
+    distances[(size_t)offset - 2] = (UInt32)maxLen;
+    if (maxLen == lenLimit)
+    {
+      p->son[p->cyclicBufferPos] = curMatch;
+      MOVE_POS_RET;
+    }
+  }
+  
+  if (maxLen < 3)
+    maxLen = 3;
+
+  offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
+      distances + offset, maxLen) - (distances));
+  MOVE_POS_RET
+}
+
+/*
+static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos
+  UInt32 *hash;
+  GET_MATCHES_HEADER(5)
+
+  HASH5_CALC;
+
+  hash = p->hash;
+  pos = p->pos;
+  
+  d2 = pos - hash                  [h2];
+  d3 = pos - (hash + kFix3HashSize)[h3];
+  d4 = pos - (hash + kFix4HashSize)[h4];
+
+  curMatch = (hash + kFix5HashSize)[hv];
+
+  hash                  [h2] = pos;
+  (hash + kFix3HashSize)[h3] = pos;
+  (hash + kFix4HashSize)[h4] = pos;
+  (hash + kFix5HashSize)[hv] = pos;
+
+  maxLen = 0;
+  offset = 0;
+
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
+  {
+    distances[0] = maxLen = 2;
+    distances[1] = d2 - 1;
+    offset = 2;
+    if (*(cur - d2 + 2) == cur[2])
+      distances[0] = maxLen = 3;
+    else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
+    {
+      distances[2] = maxLen = 3;
+      distances[3] = d3 - 1;
+      offset = 4;
+      d2 = d3;
+    }
+  }
+  else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
+  {
+    distances[0] = maxLen = 3;
+    distances[1] = d3 - 1;
+    offset = 2;
+    d2 = d3;
+  }
+  
+  if (d2 != d4 && d4 < p->cyclicBufferSize
+      && *(cur - d4) == *cur
+      && *(cur - d4 + 3) == *(cur + 3))
+  {
+    maxLen = 4;
+    distances[(size_t)offset + 1] = d4 - 1;
+    offset += 2;
+    d2 = d4;
+  }
+  
+  if (offset != 0)
+  {
+    UPDATE_maxLen
+    distances[(size_t)offset - 2] = maxLen;
+    if (maxLen == lenLimit)
+    {
+      p->son[p->cyclicBufferPos] = curMatch;
+      MOVE_POS_RET;
+    }
+  }
+  
+  if (maxLen < 4)
+    maxLen = 4;
+
+  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
+      distances + offset, maxLen) - (distances));
+  MOVE_POS_RET
+}
+*/
+
+UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  unsigned offset;
+  GET_MATCHES_HEADER(3)
+  HASH_ZIP_CALC;
+  curMatch = p->hash[hv];
+  p->hash[hv] = p->pos;
+  offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
+      distances, 2) - (distances));
+  MOVE_POS_RET
+}
+
+static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    SKIP_HEADER(2)
+    HASH2_CALC;
+    curMatch = p->hash[hv];
+    p->hash[hv] = p->pos;
+    SKIP_FOOTER
+  }
+  while (--num != 0);
+}
+
+void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    SKIP_HEADER(3)
+    HASH_ZIP_CALC;
+    curMatch = p->hash[hv];
+    p->hash[hv] = p->pos;
+    SKIP_FOOTER
+  }
+  while (--num != 0);
+}
+
+static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    UInt32 h2;
+    UInt32 *hash;
+    SKIP_HEADER(3)
+    HASH3_CALC;
+    hash = p->hash;
+    curMatch = (hash + kFix3HashSize)[hv];
+    hash[h2] =
+    (hash + kFix3HashSize)[hv] = p->pos;
+    SKIP_FOOTER
+  }
+  while (--num != 0);
+}
+
+static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    UInt32 h2, h3;
+    UInt32 *hash;
+    SKIP_HEADER(4)
+    HASH4_CALC;
+    hash = p->hash;
+    curMatch = (hash + kFix4HashSize)[hv];
+    hash                  [h2] =
+    (hash + kFix3HashSize)[h3] =
+    (hash + kFix4HashSize)[hv] = p->pos;
+    SKIP_FOOTER
+  }
+  while (--num != 0);
+}
+
+/*
+static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    UInt32 h2, h3, h4;
+    UInt32 *hash;
+    SKIP_HEADER(5)
+    HASH5_CALC;
+    hash = p->hash;
+    curMatch = (hash + kFix5HashSize)[hv];
+    hash                  [h2] =
+    (hash + kFix3HashSize)[h3] =
+    (hash + kFix4HashSize)[h4] =
+    (hash + kFix5HashSize)[hv] = p->pos;
+    SKIP_FOOTER
+  }
+  while (--num != 0);
+}
+*/
+
+static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    UInt32 h2, h3;
+    UInt32 *hash;
+    SKIP_HEADER(4)
+    HASH4_CALC;
+    hash = p->hash;
+    curMatch = (hash + kFix4HashSize)[hv];
+    hash                  [h2] =
+    (hash + kFix3HashSize)[h3] =
+    (hash + kFix4HashSize)[hv] = p->pos;
+    p->son[p->cyclicBufferPos] = curMatch;
+    MOVE_POS
+  }
+  while (--num != 0);
+}
+
+/*
+static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    UInt32 h2, h3, h4;
+    UInt32 *hash;
+    SKIP_HEADER(5)
+    HASH5_CALC;
+    hash = p->hash;
+    curMatch = hash + kFix5HashSize)[hv];
+    hash                  [h2] =
+    (hash + kFix3HashSize)[h3] =
+    (hash + kFix4HashSize)[h4] =
+    (hash + kFix5HashSize)[hv] = p->pos;
+    p->son[p->cyclicBufferPos] = curMatch;
+    MOVE_POS
+  }
+  while (--num != 0);
+}
+*/
+
+void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    SKIP_HEADER(3)
+    HASH_ZIP_CALC;
+    curMatch = p->hash[hv];
+    p->hash[hv] = p->pos;
+    p->son[p->cyclicBufferPos] = curMatch;
+    MOVE_POS
+  }
+  while (--num != 0);
+}
+
+void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
+{
+  vTable->Init = (Mf_Init_Func)MatchFinder_Init;
+  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
+  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
+  if (!p->btMode)
+  {
+    /* if (p->numHashBytes <= 4) */
+    {
+      vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
+      vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
+    }
+    /*
+    else
+    {
+      vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches;
+      vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip;
+    }
+    */
+  }
+  else if (p->numHashBytes == 2)
+  {
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
+    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
+  }
+  else if (p->numHashBytes == 3)
+  {
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
+    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
+  }
+  else /* if (p->numHashBytes == 4) */
+  {
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
+    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
+  }
+  /*
+  else
+  {
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches;
+    vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip;
+  }
+  */
+}
similarity index 95%
rename from deps/lzma-16.04/C/Lzma86Dec.c
rename to deps/libchdr/deps/lzma-19.00/src/Lzma86Dec.c
index 20ac5e7..2103174 100644 (file)
@@ -1,54 +1,54 @@
-/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder\r
-2016-05-16 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Lzma86.h"\r
-\r
-#include "Alloc.h"\r
-#include "Bra.h"\r
-#include "LzmaDec.h"\r
-\r
-SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)\r
-{\r
-  unsigned i;\r
-  if (srcLen < LZMA86_HEADER_SIZE)\r
-    return SZ_ERROR_INPUT_EOF;\r
-  *unpackSize = 0;\r
-  for (i = 0; i < sizeof(UInt64); i++)\r
-    *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);\r
-  return SZ_OK;\r
-}\r
-\r
-SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)\r
-{\r
-  SRes res;\r
-  int useFilter;\r
-  SizeT inSizePure;\r
-  ELzmaStatus status;\r
-\r
-  if (*srcLen < LZMA86_HEADER_SIZE)\r
-    return SZ_ERROR_INPUT_EOF;\r
-\r
-  useFilter = src[0];\r
-\r
-  if (useFilter > 1)\r
-  {\r
-    *destLen = 0;\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  }\r
-\r
-  inSizePure = *srcLen - LZMA86_HEADER_SIZE;\r
-  res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,\r
-      src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);\r
-  *srcLen = inSizePure + LZMA86_HEADER_SIZE;\r
-  if (res != SZ_OK)\r
-    return res;\r
-  if (useFilter == 1)\r
-  {\r
-    UInt32 x86State;\r
-    x86_Convert_Init(x86State);\r
-    x86_Convert(dest, *destLen, 0, &x86State, 0);\r
-  }\r
-  return SZ_OK;\r
-}\r
+/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
+2016-05-16 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include "Lzma86.h"
+
+#include "Alloc.h"
+#include "Bra.h"
+#include "LzmaDec.h"
+
+SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
+{
+  unsigned i;
+  if (srcLen < LZMA86_HEADER_SIZE)
+    return SZ_ERROR_INPUT_EOF;
+  *unpackSize = 0;
+  for (i = 0; i < sizeof(UInt64); i++)
+    *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);
+  return SZ_OK;
+}
+
+SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)
+{
+  SRes res;
+  int useFilter;
+  SizeT inSizePure;
+  ELzmaStatus status;
+
+  if (*srcLen < LZMA86_HEADER_SIZE)
+    return SZ_ERROR_INPUT_EOF;
+
+  useFilter = src[0];
+
+  if (useFilter > 1)
+  {
+    *destLen = 0;
+    return SZ_ERROR_UNSUPPORTED;
+  }
+
+  inSizePure = *srcLen - LZMA86_HEADER_SIZE;
+  res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,
+      src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);
+  *srcLen = inSizePure + LZMA86_HEADER_SIZE;
+  if (res != SZ_OK)
+    return res;
+  if (useFilter == 1)
+  {
+    UInt32 x86State;
+    x86_Convert_Init(x86State);
+    x86_Convert(dest, *destLen, 0, &x86State, 0);
+  }
+  return SZ_OK;
+}
similarity index 72%
rename from deps/lzma-16.04/C/LzmaDec.c
rename to deps/libchdr/deps/lzma-19.00/src/LzmaDec.c
index 64f1164..ba3e1dd 100644 (file)
-/* LzmaDec.c -- LZMA Decoder\r
-2016-05-16 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "LzmaDec.h"\r
-\r
-#include <string.h>\r
-\r
-#define kNumTopBits 24\r
-#define kTopValue ((UInt32)1 << kNumTopBits)\r
-\r
-#define kNumBitModelTotalBits 11\r
-#define kBitModelTotal (1 << kNumBitModelTotalBits)\r
-#define kNumMoveBits 5\r
-\r
-#define RC_INIT_SIZE 5\r
-\r
-#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\r
-\r
-#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r
-#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r
-#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));\r
-#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \\r
-  { UPDATE_0(p); i = (i + i); A0; } else \\r
-  { UPDATE_1(p); i = (i + i) + 1; A1; }\r
-#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)\r
-\r
-#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }\r
-#define TREE_DECODE(probs, limit, i) \\r
-  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }\r
-\r
-/* #define _LZMA_SIZE_OPT */\r
-\r
-#ifdef _LZMA_SIZE_OPT\r
-#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)\r
-#else\r
-#define TREE_6_DECODE(probs, i) \\r
-  { i = 1; \\r
-  TREE_GET_BIT(probs, i); \\r
-  TREE_GET_BIT(probs, i); \\r
-  TREE_GET_BIT(probs, i); \\r
-  TREE_GET_BIT(probs, i); \\r
-  TREE_GET_BIT(probs, i); \\r
-  TREE_GET_BIT(probs, i); \\r
-  i -= 0x40; }\r
-#endif\r
-\r
-#define NORMAL_LITER_DEC GET_BIT(prob + symbol, symbol)\r
-#define MATCHED_LITER_DEC \\r
-  matchByte <<= 1; \\r
-  bit = (matchByte & offs); \\r
-  probLit = prob + offs + bit + symbol; \\r
-  GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r
-\r
-#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r
-\r
-#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r
-#define UPDATE_0_CHECK range = bound;\r
-#define UPDATE_1_CHECK range -= bound; code -= bound;\r
-#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \\r
-  { UPDATE_0_CHECK; i = (i + i); A0; } else \\r
-  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }\r
-#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)\r
-#define TREE_DECODE_CHECK(probs, limit, i) \\r
-  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }\r
-\r
-\r
-#define kNumPosBitsMax 4\r
-#define kNumPosStatesMax (1 << kNumPosBitsMax)\r
-\r
-#define kLenNumLowBits 3\r
-#define kLenNumLowSymbols (1 << kLenNumLowBits)\r
-#define kLenNumMidBits 3\r
-#define kLenNumMidSymbols (1 << kLenNumMidBits)\r
-#define kLenNumHighBits 8\r
-#define kLenNumHighSymbols (1 << kLenNumHighBits)\r
-\r
-#define LenChoice 0\r
-#define LenChoice2 (LenChoice + 1)\r
-#define LenLow (LenChoice2 + 1)\r
-#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r
-#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r
-#define kNumLenProbs (LenHigh + kLenNumHighSymbols)\r
-\r
-\r
-#define kNumStates 12\r
-#define kNumLitStates 7\r
-\r
-#define kStartPosModelIndex 4\r
-#define kEndPosModelIndex 14\r
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r
-\r
-#define kNumPosSlotBits 6\r
-#define kNumLenToPosStates 4\r
-\r
-#define kNumAlignBits 4\r
-#define kAlignTableSize (1 << kNumAlignBits)\r
-\r
-#define kMatchMinLen 2\r
-#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r
-\r
-#define IsMatch 0\r
-#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r
-#define IsRepG0 (IsRep + kNumStates)\r
-#define IsRepG1 (IsRepG0 + kNumStates)\r
-#define IsRepG2 (IsRepG1 + kNumStates)\r
-#define IsRep0Long (IsRepG2 + kNumStates)\r
-#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r
-#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r
-#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r
-#define LenCoder (Align + kAlignTableSize)\r
-#define RepLenCoder (LenCoder + kNumLenProbs)\r
-#define Literal (RepLenCoder + kNumLenProbs)\r
-\r
-#define LZMA_BASE_SIZE 1846\r
-#define LZMA_LIT_SIZE 0x300\r
-\r
-#if Literal != LZMA_BASE_SIZE\r
-StopCompilingDueBUG\r
-#endif\r
-\r
-#define LzmaProps_GetNumProbs(p) (Literal + ((UInt32)LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r
-\r
-#define LZMA_DIC_MIN (1 << 12)\r
-\r
-/* First LZMA-symbol is always decoded.\r
-And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization\r
-Out:\r
-  Result:\r
-    SZ_OK - OK\r
-    SZ_ERROR_DATA - Error\r
-  p->remainLen:\r
-    < kMatchSpecLenStart : normal remain\r
-    = kMatchSpecLenStart : finished\r
-    = kMatchSpecLenStart + 1 : Flush marker (unused now)\r
-    = kMatchSpecLenStart + 2 : State Init Marker (unused now)\r
-*/\r
-\r
-static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r
-{\r
-  CLzmaProb *probs = p->probs;\r
-\r
-  unsigned state = p->state;\r
-  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];\r
-  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;\r
-  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;\r
-  unsigned lc = p->prop.lc;\r
-\r
-  Byte *dic = p->dic;\r
-  SizeT dicBufSize = p->dicBufSize;\r
-  SizeT dicPos = p->dicPos;\r
-  \r
-  UInt32 processedPos = p->processedPos;\r
-  UInt32 checkDicSize = p->checkDicSize;\r
-  unsigned len = 0;\r
-\r
-  const Byte *buf = p->buf;\r
-  UInt32 range = p->range;\r
-  UInt32 code = p->code;\r
-\r
-  do\r
-  {\r
-    CLzmaProb *prob;\r
-    UInt32 bound;\r
-    unsigned ttt;\r
-    unsigned posState = processedPos & pbMask;\r
-\r
-    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r
-    IF_BIT_0(prob)\r
-    {\r
-      unsigned symbol;\r
-      UPDATE_0(prob);\r
-      prob = probs + Literal;\r
-      if (processedPos != 0 || checkDicSize != 0)\r
-        prob += ((UInt32)LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r
-            (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r
-      processedPos++;\r
-\r
-      if (state < kNumLitStates)\r
-      {\r
-        state -= (state < 4) ? state : 3;\r
-        symbol = 1;\r
-        #ifdef _LZMA_SIZE_OPT\r
-        do { NORMAL_LITER_DEC } while (symbol < 0x100);\r
-        #else\r
-        NORMAL_LITER_DEC\r
-        NORMAL_LITER_DEC\r
-        NORMAL_LITER_DEC\r
-        NORMAL_LITER_DEC\r
-        NORMAL_LITER_DEC\r
-        NORMAL_LITER_DEC\r
-        NORMAL_LITER_DEC\r
-        NORMAL_LITER_DEC\r
-        #endif\r
-      }\r
-      else\r
-      {\r
-        unsigned matchByte = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\r
-        unsigned offs = 0x100;\r
-        state -= (state < 10) ? 3 : 6;\r
-        symbol = 1;\r
-        #ifdef _LZMA_SIZE_OPT\r
-        do\r
-        {\r
-          unsigned bit;\r
-          CLzmaProb *probLit;\r
-          MATCHED_LITER_DEC\r
-        }\r
-        while (symbol < 0x100);\r
-        #else\r
-        {\r
-          unsigned bit;\r
-          CLzmaProb *probLit;\r
-          MATCHED_LITER_DEC\r
-          MATCHED_LITER_DEC\r
-          MATCHED_LITER_DEC\r
-          MATCHED_LITER_DEC\r
-          MATCHED_LITER_DEC\r
-          MATCHED_LITER_DEC\r
-          MATCHED_LITER_DEC\r
-          MATCHED_LITER_DEC\r
-        }\r
-        #endif\r
-      }\r
-\r
-      dic[dicPos++] = (Byte)symbol;\r
-      continue;\r
-    }\r
-    \r
-    {\r
-      UPDATE_1(prob);\r
-      prob = probs + IsRep + state;\r
-      IF_BIT_0(prob)\r
-      {\r
-        UPDATE_0(prob);\r
-        state += kNumStates;\r
-        prob = probs + LenCoder;\r
-      }\r
-      else\r
-      {\r
-        UPDATE_1(prob);\r
-        if (checkDicSize == 0 && processedPos == 0)\r
-          return SZ_ERROR_DATA;\r
-        prob = probs + IsRepG0 + state;\r
-        IF_BIT_0(prob)\r
-        {\r
-          UPDATE_0(prob);\r
-          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r
-          IF_BIT_0(prob)\r
-          {\r
-            UPDATE_0(prob);\r
-            dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\r
-            dicPos++;\r
-            processedPos++;\r
-            state = state < kNumLitStates ? 9 : 11;\r
-            continue;\r
-          }\r
-          UPDATE_1(prob);\r
-        }\r
-        else\r
-        {\r
-          UInt32 distance;\r
-          UPDATE_1(prob);\r
-          prob = probs + IsRepG1 + state;\r
-          IF_BIT_0(prob)\r
-          {\r
-            UPDATE_0(prob);\r
-            distance = rep1;\r
-          }\r
-          else\r
-          {\r
-            UPDATE_1(prob);\r
-            prob = probs + IsRepG2 + state;\r
-            IF_BIT_0(prob)\r
-            {\r
-              UPDATE_0(prob);\r
-              distance = rep2;\r
-            }\r
-            else\r
-            {\r
-              UPDATE_1(prob);\r
-              distance = rep3;\r
-              rep3 = rep2;\r
-            }\r
-            rep2 = rep1;\r
-          }\r
-          rep1 = rep0;\r
-          rep0 = distance;\r
-        }\r
-        state = state < kNumLitStates ? 8 : 11;\r
-        prob = probs + RepLenCoder;\r
-      }\r
-      \r
-      #ifdef _LZMA_SIZE_OPT\r
-      {\r
-        unsigned lim, offset;\r
-        CLzmaProb *probLen = prob + LenChoice;\r
-        IF_BIT_0(probLen)\r
-        {\r
-          UPDATE_0(probLen);\r
-          probLen = prob + LenLow + (posState << kLenNumLowBits);\r
-          offset = 0;\r
-          lim = (1 << kLenNumLowBits);\r
-        }\r
-        else\r
-        {\r
-          UPDATE_1(probLen);\r
-          probLen = prob + LenChoice2;\r
-          IF_BIT_0(probLen)\r
-          {\r
-            UPDATE_0(probLen);\r
-            probLen = prob + LenMid + (posState << kLenNumMidBits);\r
-            offset = kLenNumLowSymbols;\r
-            lim = (1 << kLenNumMidBits);\r
-          }\r
-          else\r
-          {\r
-            UPDATE_1(probLen);\r
-            probLen = prob + LenHigh;\r
-            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r
-            lim = (1 << kLenNumHighBits);\r
-          }\r
-        }\r
-        TREE_DECODE(probLen, lim, len);\r
-        len += offset;\r
-      }\r
-      #else\r
-      {\r
-        CLzmaProb *probLen = prob + LenChoice;\r
-        IF_BIT_0(probLen)\r
-        {\r
-          UPDATE_0(probLen);\r
-          probLen = prob + LenLow + (posState << kLenNumLowBits);\r
-          len = 1;\r
-          TREE_GET_BIT(probLen, len);\r
-          TREE_GET_BIT(probLen, len);\r
-          TREE_GET_BIT(probLen, len);\r
-          len -= 8;\r
-        }\r
-        else\r
-        {\r
-          UPDATE_1(probLen);\r
-          probLen = prob + LenChoice2;\r
-          IF_BIT_0(probLen)\r
-          {\r
-            UPDATE_0(probLen);\r
-            probLen = prob + LenMid + (posState << kLenNumMidBits);\r
-            len = 1;\r
-            TREE_GET_BIT(probLen, len);\r
-            TREE_GET_BIT(probLen, len);\r
-            TREE_GET_BIT(probLen, len);\r
-          }\r
-          else\r
-          {\r
-            UPDATE_1(probLen);\r
-            probLen = prob + LenHigh;\r
-            TREE_DECODE(probLen, (1 << kLenNumHighBits), len);\r
-            len += kLenNumLowSymbols + kLenNumMidSymbols;\r
-          }\r
-        }\r
-      }\r
-      #endif\r
-\r
-      if (state >= kNumStates)\r
-      {\r
-        UInt32 distance;\r
-        prob = probs + PosSlot +\r
-            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);\r
-        TREE_6_DECODE(prob, distance);\r
-        if (distance >= kStartPosModelIndex)\r
-        {\r
-          unsigned posSlot = (unsigned)distance;\r
-          unsigned numDirectBits = (unsigned)(((distance >> 1) - 1));\r
-          distance = (2 | (distance & 1));\r
-          if (posSlot < kEndPosModelIndex)\r
-          {\r
-            distance <<= numDirectBits;\r
-            prob = probs + SpecPos + distance - posSlot - 1;\r
-            {\r
-              UInt32 mask = 1;\r
-              unsigned i = 1;\r
-              do\r
-              {\r
-                GET_BIT2(prob + i, i, ; , distance |= mask);\r
-                mask <<= 1;\r
-              }\r
-              while (--numDirectBits != 0);\r
-            }\r
-          }\r
-          else\r
-          {\r
-            numDirectBits -= kNumAlignBits;\r
-            do\r
-            {\r
-              NORMALIZE\r
-              range >>= 1;\r
-              \r
-              {\r
-                UInt32 t;\r
-                code -= range;\r
-                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */\r
-                distance = (distance << 1) + (t + 1);\r
-                code += range & t;\r
-              }\r
-              /*\r
-              distance <<= 1;\r
-              if (code >= range)\r
-              {\r
-                code -= range;\r
-                distance |= 1;\r
-              }\r
-              */\r
-            }\r
-            while (--numDirectBits != 0);\r
-            prob = probs + Align;\r
-            distance <<= kNumAlignBits;\r
-            {\r
-              unsigned i = 1;\r
-              GET_BIT2(prob + i, i, ; , distance |= 1);\r
-              GET_BIT2(prob + i, i, ; , distance |= 2);\r
-              GET_BIT2(prob + i, i, ; , distance |= 4);\r
-              GET_BIT2(prob + i, i, ; , distance |= 8);\r
-            }\r
-            if (distance == (UInt32)0xFFFFFFFF)\r
-            {\r
-              len += kMatchSpecLenStart;\r
-              state -= kNumStates;\r
-              break;\r
-            }\r
-          }\r
-        }\r
-        \r
-        rep3 = rep2;\r
-        rep2 = rep1;\r
-        rep1 = rep0;\r
-        rep0 = distance + 1;\r
-        if (checkDicSize == 0)\r
-        {\r
-          if (distance >= processedPos)\r
-          {\r
-            p->dicPos = dicPos;\r
-            return SZ_ERROR_DATA;\r
-          }\r
-        }\r
-        else if (distance >= checkDicSize)\r
-        {\r
-          p->dicPos = dicPos;\r
-          return SZ_ERROR_DATA;\r
-        }\r
-        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r
-      }\r
-\r
-      len += kMatchMinLen;\r
-\r
-      {\r
-        SizeT rem;\r
-        unsigned curLen;\r
-        SizeT pos;\r
-        \r
-        if ((rem = limit - dicPos) == 0)\r
-        {\r
-          p->dicPos = dicPos;\r
-          return SZ_ERROR_DATA;\r
-        }\r
-        \r
-        curLen = ((rem < len) ? (unsigned)rem : len);\r
-        pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);\r
-\r
-        processedPos += curLen;\r
-\r
-        len -= curLen;\r
-        if (curLen <= dicBufSize - pos)\r
-        {\r
-          Byte *dest = dic + dicPos;\r
-          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;\r
-          const Byte *lim = dest + curLen;\r
-          dicPos += curLen;\r
-          do\r
-            *(dest) = (Byte)*(dest + src);\r
-          while (++dest != lim);\r
-        }\r
-        else\r
-        {\r
-          do\r
-          {\r
-            dic[dicPos++] = dic[pos];\r
-            if (++pos == dicBufSize)\r
-              pos = 0;\r
-          }\r
-          while (--curLen != 0);\r
-        }\r
-      }\r
-    }\r
-  }\r
-  while (dicPos < limit && buf < bufLimit);\r
-\r
-  NORMALIZE;\r
-  \r
-  p->buf = buf;\r
-  p->range = range;\r
-  p->code = code;\r
-  p->remainLen = len;\r
-  p->dicPos = dicPos;\r
-  p->processedPos = processedPos;\r
-  p->reps[0] = rep0;\r
-  p->reps[1] = rep1;\r
-  p->reps[2] = rep2;\r
-  p->reps[3] = rep3;\r
-  p->state = state;\r
-\r
-  return SZ_OK;\r
-}\r
-\r
-static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\r
-{\r
-  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\r
-  {\r
-    Byte *dic = p->dic;\r
-    SizeT dicPos = p->dicPos;\r
-    SizeT dicBufSize = p->dicBufSize;\r
-    unsigned len = p->remainLen;\r
-    SizeT rep0 = p->reps[0]; /* we use SizeT to avoid the BUG of VC14 for AMD64 */\r
-    SizeT rem = limit - dicPos;\r
-    if (rem < len)\r
-      len = (unsigned)(rem);\r
-\r
-    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r
-      p->checkDicSize = p->prop.dicSize;\r
-\r
-    p->processedPos += len;\r
-    p->remainLen -= len;\r
-    while (len != 0)\r
-    {\r
-      len--;\r
-      dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\r
-      dicPos++;\r
-    }\r
-    p->dicPos = dicPos;\r
-  }\r
-}\r
-\r
-static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r
-{\r
-  do\r
-  {\r
-    SizeT limit2 = limit;\r
-    if (p->checkDicSize == 0)\r
-    {\r
-      UInt32 rem = p->prop.dicSize - p->processedPos;\r
-      if (limit - p->dicPos > rem)\r
-        limit2 = p->dicPos + rem;\r
-    }\r
-    \r
-    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r
-    \r
-    if (p->checkDicSize == 0 && p->processedPos >= p->prop.dicSize)\r
-      p->checkDicSize = p->prop.dicSize;\r
-    \r
-    LzmaDec_WriteRem(p, limit);\r
-  }\r
-  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r
-\r
-  if (p->remainLen > kMatchSpecLenStart)\r
-    p->remainLen = kMatchSpecLenStart;\r
-\r
-  return 0;\r
-}\r
-\r
-typedef enum\r
-{\r
-  DUMMY_ERROR, /* unexpected end of input stream */\r
-  DUMMY_LIT,\r
-  DUMMY_MATCH,\r
-  DUMMY_REP\r
-} ELzmaDummy;\r
-\r
-static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\r
-{\r
-  UInt32 range = p->range;\r
-  UInt32 code = p->code;\r
-  const Byte *bufLimit = buf + inSize;\r
-  const CLzmaProb *probs = p->probs;\r
-  unsigned state = p->state;\r
-  ELzmaDummy res;\r
-\r
-  {\r
-    const CLzmaProb *prob;\r
-    UInt32 bound;\r
-    unsigned ttt;\r
-    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r
-\r
-    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r
-    IF_BIT_0_CHECK(prob)\r
-    {\r
-      UPDATE_0_CHECK\r
-\r
-      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\r
-\r
-      prob = probs + Literal;\r
-      if (p->checkDicSize != 0 || p->processedPos != 0)\r
-        prob += ((UInt32)LZMA_LIT_SIZE *\r
-            ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r
-            (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r
-\r
-      if (state < kNumLitStates)\r
-      {\r
-        unsigned symbol = 1;\r
-        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);\r
-      }\r
-      else\r
-      {\r
-        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r
-            (p->dicPos < p->reps[0] ? p->dicBufSize : 0)];\r
-        unsigned offs = 0x100;\r
-        unsigned symbol = 1;\r
-        do\r
-        {\r
-          unsigned bit;\r
-          const CLzmaProb *probLit;\r
-          matchByte <<= 1;\r
-          bit = (matchByte & offs);\r
-          probLit = prob + offs + bit + symbol;\r
-          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)\r
-        }\r
-        while (symbol < 0x100);\r
-      }\r
-      res = DUMMY_LIT;\r
-    }\r
-    else\r
-    {\r
-      unsigned len;\r
-      UPDATE_1_CHECK;\r
-\r
-      prob = probs + IsRep + state;\r
-      IF_BIT_0_CHECK(prob)\r
-      {\r
-        UPDATE_0_CHECK;\r
-        state = 0;\r
-        prob = probs + LenCoder;\r
-        res = DUMMY_MATCH;\r
-      }\r
-      else\r
-      {\r
-        UPDATE_1_CHECK;\r
-        res = DUMMY_REP;\r
-        prob = probs + IsRepG0 + state;\r
-        IF_BIT_0_CHECK(prob)\r
-        {\r
-          UPDATE_0_CHECK;\r
-          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r
-          IF_BIT_0_CHECK(prob)\r
-          {\r
-            UPDATE_0_CHECK;\r
-            NORMALIZE_CHECK;\r
-            return DUMMY_REP;\r
-          }\r
-          else\r
-          {\r
-            UPDATE_1_CHECK;\r
-          }\r
-        }\r
-        else\r
-        {\r
-          UPDATE_1_CHECK;\r
-          prob = probs + IsRepG1 + state;\r
-          IF_BIT_0_CHECK(prob)\r
-          {\r
-            UPDATE_0_CHECK;\r
-          }\r
-          else\r
-          {\r
-            UPDATE_1_CHECK;\r
-            prob = probs + IsRepG2 + state;\r
-            IF_BIT_0_CHECK(prob)\r
-            {\r
-              UPDATE_0_CHECK;\r
-            }\r
-            else\r
-            {\r
-              UPDATE_1_CHECK;\r
-            }\r
-          }\r
-        }\r
-        state = kNumStates;\r
-        prob = probs + RepLenCoder;\r
-      }\r
-      {\r
-        unsigned limit, offset;\r
-        const CLzmaProb *probLen = prob + LenChoice;\r
-        IF_BIT_0_CHECK(probLen)\r
-        {\r
-          UPDATE_0_CHECK;\r
-          probLen = prob + LenLow + (posState << kLenNumLowBits);\r
-          offset = 0;\r
-          limit = 1 << kLenNumLowBits;\r
-        }\r
-        else\r
-        {\r
-          UPDATE_1_CHECK;\r
-          probLen = prob + LenChoice2;\r
-          IF_BIT_0_CHECK(probLen)\r
-          {\r
-            UPDATE_0_CHECK;\r
-            probLen = prob + LenMid + (posState << kLenNumMidBits);\r
-            offset = kLenNumLowSymbols;\r
-            limit = 1 << kLenNumMidBits;\r
-          }\r
-          else\r
-          {\r
-            UPDATE_1_CHECK;\r
-            probLen = prob + LenHigh;\r
-            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r
-            limit = 1 << kLenNumHighBits;\r
-          }\r
-        }\r
-        TREE_DECODE_CHECK(probLen, limit, len);\r
-        len += offset;\r
-      }\r
-\r
-      if (state < 4)\r
-      {\r
-        unsigned posSlot;\r
-        prob = probs + PosSlot +\r
-            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<\r
-            kNumPosSlotBits);\r
-        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r
-        if (posSlot >= kStartPosModelIndex)\r
-        {\r
-          unsigned numDirectBits = ((posSlot >> 1) - 1);\r
-\r
-          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r
-\r
-          if (posSlot < kEndPosModelIndex)\r
-          {\r
-            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;\r
-          }\r
-          else\r
-          {\r
-            numDirectBits -= kNumAlignBits;\r
-            do\r
-            {\r
-              NORMALIZE_CHECK\r
-              range >>= 1;\r
-              code -= range & (((code - range) >> 31) - 1);\r
-              /* if (code >= range) code -= range; */\r
-            }\r
-            while (--numDirectBits != 0);\r
-            prob = probs + Align;\r
-            numDirectBits = kNumAlignBits;\r
-          }\r
-          {\r
-            unsigned i = 1;\r
-            do\r
-            {\r
-              GET_BIT_CHECK(prob + i, i);\r
-            }\r
-            while (--numDirectBits != 0);\r
-          }\r
-        }\r
-      }\r
-    }\r
-  }\r
-  NORMALIZE_CHECK;\r
-  return res;\r
-}\r
-\r
-\r
-void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r
-{\r
-  p->needFlush = 1;\r
-  p->remainLen = 0;\r
-  p->tempBufSize = 0;\r
-\r
-  if (initDic)\r
-  {\r
-    p->processedPos = 0;\r
-    p->checkDicSize = 0;\r
-    p->needInitState = 1;\r
-  }\r
-  if (initState)\r
-    p->needInitState = 1;\r
-}\r
-\r
-void LzmaDec_Init(CLzmaDec *p)\r
-{\r
-  p->dicPos = 0;\r
-  LzmaDec_InitDicAndState(p, True, True);\r
-}\r
-\r
-static void LzmaDec_InitStateReal(CLzmaDec *p)\r
-{\r
-  SizeT numProbs = LzmaProps_GetNumProbs(&p->prop);\r
-  SizeT i;\r
-  CLzmaProb *probs = p->probs;\r
-  for (i = 0; i < numProbs; i++)\r
-    probs[i] = kBitModelTotal >> 1;\r
-  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;\r
-  p->state = 0;\r
-  p->needInitState = 0;\r
-}\r
-\r
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\r
-    ELzmaFinishMode finishMode, ELzmaStatus *status)\r
-{\r
-  SizeT inSize = *srcLen;\r
-  (*srcLen) = 0;\r
-  LzmaDec_WriteRem(p, dicLimit);\r
-  \r
-  *status = LZMA_STATUS_NOT_SPECIFIED;\r
-\r
-  while (p->remainLen != kMatchSpecLenStart)\r
-  {\r
-      int checkEndMarkNow;\r
-\r
-      if (p->needFlush)\r
-      {\r
-        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r
-          p->tempBuf[p->tempBufSize++] = *src++;\r
-        if (p->tempBufSize < RC_INIT_SIZE)\r
-        {\r
-          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r
-          return SZ_OK;\r
-        }\r
-        if (p->tempBuf[0] != 0)\r
-          return SZ_ERROR_DATA;\r
-        p->code =\r
-              ((UInt32)p->tempBuf[1] << 24)\r
-            | ((UInt32)p->tempBuf[2] << 16)\r
-            | ((UInt32)p->tempBuf[3] << 8)\r
-            | ((UInt32)p->tempBuf[4]);\r
-        p->range = 0xFFFFFFFF;\r
-        p->needFlush = 0;\r
-        p->tempBufSize = 0;\r
-      }\r
-\r
-      checkEndMarkNow = 0;\r
-      if (p->dicPos >= dicLimit)\r
-      {\r
-        if (p->remainLen == 0 && p->code == 0)\r
-        {\r
-          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;\r
-          return SZ_OK;\r
-        }\r
-        if (finishMode == LZMA_FINISH_ANY)\r
-        {\r
-          *status = LZMA_STATUS_NOT_FINISHED;\r
-          return SZ_OK;\r
-        }\r
-        if (p->remainLen != 0)\r
-        {\r
-          *status = LZMA_STATUS_NOT_FINISHED;\r
-          return SZ_ERROR_DATA;\r
-        }\r
-        checkEndMarkNow = 1;\r
-      }\r
-\r
-      if (p->needInitState)\r
-        LzmaDec_InitStateReal(p);\r
-  \r
-      if (p->tempBufSize == 0)\r
-      {\r
-        SizeT processed;\r
-        const Byte *bufLimit;\r
-        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r
-        {\r
-          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\r
-          if (dummyRes == DUMMY_ERROR)\r
-          {\r
-            memcpy(p->tempBuf, src, inSize);\r
-            p->tempBufSize = (unsigned)inSize;\r
-            (*srcLen) += inSize;\r
-            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r
-            return SZ_OK;\r
-          }\r
-          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r
-          {\r
-            *status = LZMA_STATUS_NOT_FINISHED;\r
-            return SZ_ERROR_DATA;\r
-          }\r
-          bufLimit = src;\r
-        }\r
-        else\r
-          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\r
-        p->buf = src;\r
-        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\r
-          return SZ_ERROR_DATA;\r
-        processed = (SizeT)(p->buf - src);\r
-        (*srcLen) += processed;\r
-        src += processed;\r
-        inSize -= processed;\r
-      }\r
-      else\r
-      {\r
-        unsigned rem = p->tempBufSize, lookAhead = 0;\r
-        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\r
-          p->tempBuf[rem++] = src[lookAhead++];\r
-        p->tempBufSize = rem;\r
-        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r
-        {\r
-          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);\r
-          if (dummyRes == DUMMY_ERROR)\r
-          {\r
-            (*srcLen) += lookAhead;\r
-            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r
-            return SZ_OK;\r
-          }\r
-          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r
-          {\r
-            *status = LZMA_STATUS_NOT_FINISHED;\r
-            return SZ_ERROR_DATA;\r
-          }\r
-        }\r
-        p->buf = p->tempBuf;\r
-        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r
-          return SZ_ERROR_DATA;\r
-        \r
-        {\r
-          unsigned kkk = (unsigned)(p->buf - p->tempBuf);\r
-          if (rem < kkk)\r
-            return SZ_ERROR_FAIL; /* some internal error */\r
-          rem -= kkk;\r
-          if (lookAhead < rem)\r
-            return SZ_ERROR_FAIL; /* some internal error */\r
-          lookAhead -= rem;\r
-        }\r
-        (*srcLen) += lookAhead;\r
-        src += lookAhead;\r
-        inSize -= lookAhead;\r
-        p->tempBufSize = 0;\r
-      }\r
-  }\r
-  if (p->code == 0)\r
-    *status = LZMA_STATUS_FINISHED_WITH_MARK;\r
-  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;\r
-}\r
-\r
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r
-{\r
-  SizeT outSize = *destLen;\r
-  SizeT inSize = *srcLen;\r
-  *srcLen = *destLen = 0;\r
-  for (;;)\r
-  {\r
-    SizeT inSizeCur = inSize, outSizeCur, dicPos;\r
-    ELzmaFinishMode curFinishMode;\r
-    SRes res;\r
-    if (p->dicPos == p->dicBufSize)\r
-      p->dicPos = 0;\r
-    dicPos = p->dicPos;\r
-    if (outSize > p->dicBufSize - dicPos)\r
-    {\r
-      outSizeCur = p->dicBufSize;\r
-      curFinishMode = LZMA_FINISH_ANY;\r
-    }\r
-    else\r
-    {\r
-      outSizeCur = dicPos + outSize;\r
-      curFinishMode = finishMode;\r
-    }\r
-\r
-    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);\r
-    src += inSizeCur;\r
-    inSize -= inSizeCur;\r
-    *srcLen += inSizeCur;\r
-    outSizeCur = p->dicPos - dicPos;\r
-    memcpy(dest, p->dic + dicPos, outSizeCur);\r
-    dest += outSizeCur;\r
-    outSize -= outSizeCur;\r
-    *destLen += outSizeCur;\r
-    if (res != 0)\r
-      return res;\r
-    if (outSizeCur == 0 || outSize == 0)\r
-      return SZ_OK;\r
-  }\r
-}\r
-\r
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->probs);\r
-  p->probs = NULL;\r
-}\r
-\r
-static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->dic);\r
-  p->dic = NULL;\r
-}\r
-\r
-void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r
-{\r
-  LzmaDec_FreeProbs(p, alloc);\r
-  LzmaDec_FreeDict(p, alloc);\r
-}\r
-\r
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)\r
-{\r
-  UInt32 dicSize;\r
-  Byte d;\r
-  \r
-  if (size < LZMA_PROPS_SIZE)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  else\r
-    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);\r
\r
-  if (dicSize < LZMA_DIC_MIN)\r
-    dicSize = LZMA_DIC_MIN;\r
-  p->dicSize = dicSize;\r
-\r
-  d = data[0];\r
-  if (d >= (9 * 5 * 5))\r
-    return SZ_ERROR_UNSUPPORTED;\r
-\r
-  p->lc = d % 9;\r
-  d /= 9;\r
-  p->pb = d / 5;\r
-  p->lp = d % 5;\r
-\r
-  return SZ_OK;\r
-}\r
-\r
-static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r
-{\r
-  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r
-  if (!p->probs || numProbs != p->numProbs)\r
-  {\r
-    LzmaDec_FreeProbs(p, alloc);\r
-    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r
-    p->numProbs = numProbs;\r
-    if (!p->probs)\r
-      return SZ_ERROR_MEM;\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r
-{\r
-  CLzmaProps propNew;\r
-  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r
-  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r
-  p->prop = propNew;\r
-  return SZ_OK;\r
-}\r
-\r
-SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r
-{\r
-  CLzmaProps propNew;\r
-  SizeT dicBufSize;\r
-  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r
-  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r
-\r
-  {\r
-    UInt32 dictSize = propNew.dicSize;\r
-    SizeT mask = ((UInt32)1 << 12) - 1;\r
-         if (dictSize >= ((UInt32)1 << 30)) mask = ((UInt32)1 << 22) - 1;\r
-    else if (dictSize >= ((UInt32)1 << 22)) mask = ((UInt32)1 << 20) - 1;;\r
-    dicBufSize = ((SizeT)dictSize + mask) & ~mask;\r
-    if (dicBufSize < dictSize)\r
-      dicBufSize = dictSize;\r
-  }\r
-\r
-  if (!p->dic || dicBufSize != p->dicBufSize)\r
-  {\r
-    LzmaDec_FreeDict(p, alloc);\r
-    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r
-    if (!p->dic)\r
-    {\r
-      LzmaDec_FreeProbs(p, alloc);\r
-      return SZ_ERROR_MEM;\r
-    }\r
-  }\r
-  p->dicBufSize = dicBufSize;\r
-  p->prop = propNew;\r
-  return SZ_OK;\r
-}\r
-\r
-SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r
-    ELzmaStatus *status, ISzAlloc *alloc)\r
-{\r
-  CLzmaDec p;\r
-  SRes res;\r
-  SizeT outSize = *destLen, inSize = *srcLen;\r
-  *destLen = *srcLen = 0;\r
-  *status = LZMA_STATUS_NOT_SPECIFIED;\r
-  if (inSize < RC_INIT_SIZE)\r
-    return SZ_ERROR_INPUT_EOF;\r
-  LzmaDec_Construct(&p);\r
-  RINOK(LzmaDec_AllocateProbs(&p, propData, propSize, alloc));\r
-  p.dic = dest;\r
-  p.dicBufSize = outSize;\r
-  LzmaDec_Init(&p);\r
-  *srcLen = inSize;\r
-  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r
-  *destLen = p.dicPos;\r
-  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r
-    res = SZ_ERROR_INPUT_EOF;\r
-  LzmaDec_FreeProbs(&p, alloc);\r
-  return res;\r
-}\r
+/* LzmaDec.c -- LZMA Decoder
+2018-07-04 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include <string.h>
+
+/* #include "CpuArch.h" */
+#include "LzmaDec.h"
+
+#define kNumTopBits 24
+#define kTopValue ((UInt32)1 << kNumTopBits)
+
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+#define kNumMoveBits 5
+
+#define RC_INIT_SIZE 5
+
+#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
+
+#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)
+#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
+#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
+#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \
+  { UPDATE_0(p); i = (i + i); A0; } else \
+  { UPDATE_1(p); i = (i + i) + 1; A1; }
+
+#define TREE_GET_BIT(probs, i) { GET_BIT2(probs + i, i, ;, ;); }
+
+#define REV_BIT(p, i, A0, A1) IF_BIT_0(p + i) \
+  { UPDATE_0(p + i); A0; } else \
+  { UPDATE_1(p + i); A1; }
+#define REV_BIT_VAR(  p, i, m) REV_BIT(p, i, i += m; m += m, m += m; i += m; )
+#define REV_BIT_CONST(p, i, m) REV_BIT(p, i, i += m;       , i += m * 2; )
+#define REV_BIT_LAST( p, i, m) REV_BIT(p, i, i -= m        , ; )
+
+#define TREE_DECODE(probs, limit, i) \
+  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
+
+/* #define _LZMA_SIZE_OPT */
+
+#ifdef _LZMA_SIZE_OPT
+#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
+#else
+#define TREE_6_DECODE(probs, i) \
+  { i = 1; \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  i -= 0x40; }
+#endif
+
+#define NORMAL_LITER_DEC TREE_GET_BIT(prob, symbol)
+#define MATCHED_LITER_DEC \
+  matchByte += matchByte; \
+  bit = offs; \
+  offs &= matchByte; \
+  probLit = prob + (offs + bit + symbol); \
+  GET_BIT2(probLit, symbol, offs ^= bit; , ;)
+
+
+
+#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
+
+#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)
+#define UPDATE_0_CHECK range = bound;
+#define UPDATE_1_CHECK range -= bound; code -= bound;
+#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
+  { UPDATE_0_CHECK; i = (i + i); A0; } else \
+  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
+#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
+#define TREE_DECODE_CHECK(probs, limit, i) \
+  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }
+
+
+#define REV_BIT_CHECK(p, i, m) IF_BIT_0_CHECK(p + i) \
+  { UPDATE_0_CHECK; i += m; m += m; } else \
+  { UPDATE_1_CHECK; m += m; i += m; }
+
+
+#define kNumPosBitsMax 4
+#define kNumPosStatesMax (1 << kNumPosBitsMax)
+
+#define kLenNumLowBits 3
+#define kLenNumLowSymbols (1 << kLenNumLowBits)
+#define kLenNumHighBits 8
+#define kLenNumHighSymbols (1 << kLenNumHighBits)
+
+#define LenLow 0
+#define LenHigh (LenLow + 2 * (kNumPosStatesMax << kLenNumLowBits))
+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
+
+#define LenChoice LenLow
+#define LenChoice2 (LenLow + (1 << kLenNumLowBits))
+
+#define kNumStates 12
+#define kNumStates2 16
+#define kNumLitStates 7
+
+#define kStartPosModelIndex 4
+#define kEndPosModelIndex 14
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
+
+#define kNumPosSlotBits 6
+#define kNumLenToPosStates 4
+
+#define kNumAlignBits 4
+#define kAlignTableSize (1 << kNumAlignBits)
+
+#define kMatchMinLen 2
+#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols)
+
+/* External ASM code needs same CLzmaProb array layout. So don't change it. */
+
+/* (probs_1664) is faster and better for code size at some platforms */
+/*
+#ifdef MY_CPU_X86_OR_AMD64
+*/
+#define kStartOffset 1664
+#define GET_PROBS p->probs_1664
+/*
+#define GET_PROBS p->probs + kStartOffset
+#else
+#define kStartOffset 0
+#define GET_PROBS p->probs
+#endif
+*/
+
+#define SpecPos (-kStartOffset)
+#define IsRep0Long (SpecPos + kNumFullDistances)
+#define RepLenCoder (IsRep0Long + (kNumStates2 << kNumPosBitsMax))
+#define LenCoder (RepLenCoder + kNumLenProbs)
+#define IsMatch (LenCoder + kNumLenProbs)
+#define Align (IsMatch + (kNumStates2 << kNumPosBitsMax))
+#define IsRep (Align + kAlignTableSize)
+#define IsRepG0 (IsRep + kNumStates)
+#define IsRepG1 (IsRepG0 + kNumStates)
+#define IsRepG2 (IsRepG1 + kNumStates)
+#define PosSlot (IsRepG2 + kNumStates)
+#define Literal (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
+#define NUM_BASE_PROBS (Literal + kStartOffset)
+
+#if Align != 0 && kStartOffset != 0
+  #error Stop_Compiling_Bad_LZMA_kAlign
+#endif
+
+#if NUM_BASE_PROBS != 1984
+  #error Stop_Compiling_Bad_LZMA_PROBS
+#endif
+
+
+#define LZMA_LIT_SIZE 0x300
+
+#define LzmaProps_GetNumProbs(p) (NUM_BASE_PROBS + ((UInt32)LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
+
+
+#define CALC_POS_STATE(processedPos, pbMask) (((processedPos) & (pbMask)) << 4)
+#define COMBINED_PS_STATE (posState + state)
+#define GET_LEN_STATE (posState)
+
+#define LZMA_DIC_MIN (1 << 12)
+
+/*
+p->remainLen : shows status of LZMA decoder:
+    < kMatchSpecLenStart : normal remain
+    = kMatchSpecLenStart : finished
+    = kMatchSpecLenStart + 1 : need init range coder
+    = kMatchSpecLenStart + 2 : need init range coder and state
+*/
+
+/* ---------- LZMA_DECODE_REAL ---------- */
+/*
+LzmaDec_DecodeReal_3() can be implemented in external ASM file.
+3 - is the code compatibility version of that function for check at link time.
+*/
+
+#define LZMA_DECODE_REAL LzmaDec_DecodeReal_3
+
+/*
+LZMA_DECODE_REAL()
+In:
+  RangeCoder is normalized
+  if (p->dicPos == limit)
+  {
+    LzmaDec_TryDummy() was called before to exclude LITERAL and MATCH-REP cases.
+    So first symbol can be only MATCH-NON-REP. And if that MATCH-NON-REP symbol
+    is not END_OF_PAYALOAD_MARKER, then function returns error code.
+  }
+
+Processing:
+  first LZMA symbol will be decoded in any case
+  All checks for limits are at the end of main loop,
+  It will decode new LZMA-symbols while (p->buf < bufLimit && dicPos < limit),
+  RangeCoder is still without last normalization when (p->buf < bufLimit) is being checked.
+
+Out:
+  RangeCoder is normalized
+  Result:
+    SZ_OK - OK
+    SZ_ERROR_DATA - Error
+  p->remainLen:
+    < kMatchSpecLenStart : normal remain
+    = kMatchSpecLenStart : finished
+*/
+
+
+#ifdef _LZMA_DEC_OPT
+
+int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit);
+
+#else
+
+static
+int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
+{
+  CLzmaProb *probs = GET_PROBS;
+  unsigned state = (unsigned)p->state;
+  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
+  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
+  unsigned lc = p->prop.lc;
+  unsigned lpMask = ((unsigned)0x100 << p->prop.lp) - ((unsigned)0x100 >> lc);
+
+  Byte *dic = p->dic;
+  SizeT dicBufSize = p->dicBufSize;
+  SizeT dicPos = p->dicPos;
+  
+  UInt32 processedPos = p->processedPos;
+  UInt32 checkDicSize = p->checkDicSize;
+  unsigned len = 0;
+
+  const Byte *buf = p->buf;
+  UInt32 range = p->range;
+  UInt32 code = p->code;
+
+  do
+  {
+    CLzmaProb *prob;
+    UInt32 bound;
+    unsigned ttt;
+    unsigned posState = CALC_POS_STATE(processedPos, pbMask);
+
+    prob = probs + IsMatch + COMBINED_PS_STATE;
+    IF_BIT_0(prob)
+    {
+      unsigned symbol;
+      UPDATE_0(prob);
+      prob = probs + Literal;
+      if (processedPos != 0 || checkDicSize != 0)
+        prob += (UInt32)3 * ((((processedPos << 8) + dic[(dicPos == 0 ? dicBufSize : dicPos) - 1]) & lpMask) << lc);
+      processedPos++;
+
+      if (state < kNumLitStates)
+      {
+        state -= (state < 4) ? state : 3;
+        symbol = 1;
+        #ifdef _LZMA_SIZE_OPT
+        do { NORMAL_LITER_DEC } while (symbol < 0x100);
+        #else
+        NORMAL_LITER_DEC
+        NORMAL_LITER_DEC
+        NORMAL_LITER_DEC
+        NORMAL_LITER_DEC
+        NORMAL_LITER_DEC
+        NORMAL_LITER_DEC
+        NORMAL_LITER_DEC
+        NORMAL_LITER_DEC
+        #endif
+      }
+      else
+      {
+        unsigned matchByte = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
+        unsigned offs = 0x100;
+        state -= (state < 10) ? 3 : 6;
+        symbol = 1;
+        #ifdef _LZMA_SIZE_OPT
+        do
+        {
+          unsigned bit;
+          CLzmaProb *probLit;
+          MATCHED_LITER_DEC
+        }
+        while (symbol < 0x100);
+        #else
+        {
+          unsigned bit;
+          CLzmaProb *probLit;
+          MATCHED_LITER_DEC
+          MATCHED_LITER_DEC
+          MATCHED_LITER_DEC
+          MATCHED_LITER_DEC
+          MATCHED_LITER_DEC
+          MATCHED_LITER_DEC
+          MATCHED_LITER_DEC
+          MATCHED_LITER_DEC
+        }
+        #endif
+      }
+
+      dic[dicPos++] = (Byte)symbol;
+      continue;
+    }
+    
+    {
+      UPDATE_1(prob);
+      prob = probs + IsRep + state;
+      IF_BIT_0(prob)
+      {
+        UPDATE_0(prob);
+        state += kNumStates;
+        prob = probs + LenCoder;
+      }
+      else
+      {
+        UPDATE_1(prob);
+        /*
+        // that case was checked before with kBadRepCode
+        if (checkDicSize == 0 && processedPos == 0)
+          return SZ_ERROR_DATA;
+        */
+        prob = probs + IsRepG0 + state;
+        IF_BIT_0(prob)
+        {
+          UPDATE_0(prob);
+          prob = probs + IsRep0Long + COMBINED_PS_STATE;
+          IF_BIT_0(prob)
+          {
+            UPDATE_0(prob);
+            dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
+            dicPos++;
+            processedPos++;
+            state = state < kNumLitStates ? 9 : 11;
+            continue;
+          }
+          UPDATE_1(prob);
+        }
+        else
+        {
+          UInt32 distance;
+          UPDATE_1(prob);
+          prob = probs + IsRepG1 + state;
+          IF_BIT_0(prob)
+          {
+            UPDATE_0(prob);
+            distance = rep1;
+          }
+          else
+          {
+            UPDATE_1(prob);
+            prob = probs + IsRepG2 + state;
+            IF_BIT_0(prob)
+            {
+              UPDATE_0(prob);
+              distance = rep2;
+            }
+            else
+            {
+              UPDATE_1(prob);
+              distance = rep3;
+              rep3 = rep2;
+            }
+            rep2 = rep1;
+          }
+          rep1 = rep0;
+          rep0 = distance;
+        }
+        state = state < kNumLitStates ? 8 : 11;
+        prob = probs + RepLenCoder;
+      }
+      
+      #ifdef _LZMA_SIZE_OPT
+      {
+        unsigned lim, offset;
+        CLzmaProb *probLen = prob + LenChoice;
+        IF_BIT_0(probLen)
+        {
+          UPDATE_0(probLen);
+          probLen = prob + LenLow + GET_LEN_STATE;
+          offset = 0;
+          lim = (1 << kLenNumLowBits);
+        }
+        else
+        {
+          UPDATE_1(probLen);
+          probLen = prob + LenChoice2;
+          IF_BIT_0(probLen)
+          {
+            UPDATE_0(probLen);
+            probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
+            offset = kLenNumLowSymbols;
+            lim = (1 << kLenNumLowBits);
+          }
+          else
+          {
+            UPDATE_1(probLen);
+            probLen = prob + LenHigh;
+            offset = kLenNumLowSymbols * 2;
+            lim = (1 << kLenNumHighBits);
+          }
+        }
+        TREE_DECODE(probLen, lim, len);
+        len += offset;
+      }
+      #else
+      {
+        CLzmaProb *probLen = prob + LenChoice;
+        IF_BIT_0(probLen)
+        {
+          UPDATE_0(probLen);
+          probLen = prob + LenLow + GET_LEN_STATE;
+          len = 1;
+          TREE_GET_BIT(probLen, len);
+          TREE_GET_BIT(probLen, len);
+          TREE_GET_BIT(probLen, len);
+          len -= 8;
+        }
+        else
+        {
+          UPDATE_1(probLen);
+          probLen = prob + LenChoice2;
+          IF_BIT_0(probLen)
+          {
+            UPDATE_0(probLen);
+            probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
+            len = 1;
+            TREE_GET_BIT(probLen, len);
+            TREE_GET_BIT(probLen, len);
+            TREE_GET_BIT(probLen, len);
+          }
+          else
+          {
+            UPDATE_1(probLen);
+            probLen = prob + LenHigh;
+            TREE_DECODE(probLen, (1 << kLenNumHighBits), len);
+            len += kLenNumLowSymbols * 2;
+          }
+        }
+      }
+      #endif
+
+      if (state >= kNumStates)
+      {
+        UInt32 distance;
+        prob = probs + PosSlot +
+            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
+        TREE_6_DECODE(prob, distance);
+        if (distance >= kStartPosModelIndex)
+        {
+          unsigned posSlot = (unsigned)distance;
+          unsigned numDirectBits = (unsigned)(((distance >> 1) - 1));
+          distance = (2 | (distance & 1));
+          if (posSlot < kEndPosModelIndex)
+          {
+            distance <<= numDirectBits;
+            prob = probs + SpecPos;
+            {
+              UInt32 m = 1;
+              distance++;
+              do
+              {
+                REV_BIT_VAR(prob, distance, m);
+              }
+              while (--numDirectBits);
+              distance -= m;
+            }
+          }
+          else
+          {
+            numDirectBits -= kNumAlignBits;
+            do
+            {
+              NORMALIZE
+              range >>= 1;
+              
+              {
+                UInt32 t;
+                code -= range;
+                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
+                distance = (distance << 1) + (t + 1);
+                code += range & t;
+              }
+              /*
+              distance <<= 1;
+              if (code >= range)
+              {
+                code -= range;
+                distance |= 1;
+              }
+              */
+            }
+            while (--numDirectBits);
+            prob = probs + Align;
+            distance <<= kNumAlignBits;
+            {
+              unsigned i = 1;
+              REV_BIT_CONST(prob, i, 1);
+              REV_BIT_CONST(prob, i, 2);
+              REV_BIT_CONST(prob, i, 4);
+              REV_BIT_LAST (prob, i, 8);
+              distance |= i;
+            }
+            if (distance == (UInt32)0xFFFFFFFF)
+            {
+              len = kMatchSpecLenStart;
+              state -= kNumStates;
+              break;
+            }
+          }
+        }
+        
+        rep3 = rep2;
+        rep2 = rep1;
+        rep1 = rep0;
+        rep0 = distance + 1;
+        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
+        if (distance >= (checkDicSize == 0 ? processedPos: checkDicSize))
+        {
+          p->dicPos = dicPos;
+          return SZ_ERROR_DATA;
+        }
+      }
+
+      len += kMatchMinLen;
+
+      {
+        SizeT rem;
+        unsigned curLen;
+        SizeT pos;
+        
+        if ((rem = limit - dicPos) == 0)
+        {
+          p->dicPos = dicPos;
+          return SZ_ERROR_DATA;
+        }
+        
+        curLen = ((rem < len) ? (unsigned)rem : len);
+        pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);
+
+        processedPos += (UInt32)curLen;
+
+        len -= curLen;
+        if (curLen <= dicBufSize - pos)
+        {
+          Byte *dest = dic + dicPos;
+          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
+          const Byte *lim = dest + curLen;
+          dicPos += (SizeT)curLen;
+          do
+            *(dest) = (Byte)*(dest + src);
+          while (++dest != lim);
+        }
+        else
+        {
+          do
+          {
+            dic[dicPos++] = dic[pos];
+            if (++pos == dicBufSize)
+              pos = 0;
+          }
+          while (--curLen != 0);
+        }
+      }
+    }
+  }
+  while (dicPos < limit && buf < bufLimit);
+
+  NORMALIZE;
+  
+  p->buf = buf;
+  p->range = range;
+  p->code = code;
+  p->remainLen = (UInt32)len;
+  p->dicPos = dicPos;
+  p->processedPos = processedPos;
+  p->reps[0] = rep0;
+  p->reps[1] = rep1;
+  p->reps[2] = rep2;
+  p->reps[3] = rep3;
+  p->state = (UInt32)state;
+
+  return SZ_OK;
+}
+#endif
+
+static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
+{
+  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
+  {
+    Byte *dic = p->dic;
+    SizeT dicPos = p->dicPos;
+    SizeT dicBufSize = p->dicBufSize;
+    unsigned len = (unsigned)p->remainLen;
+    SizeT rep0 = p->reps[0]; /* we use SizeT to avoid the BUG of VC14 for AMD64 */
+    SizeT rem = limit - dicPos;
+    if (rem < len)
+      len = (unsigned)(rem);
+
+    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
+      p->checkDicSize = p->prop.dicSize;
+
+    p->processedPos += (UInt32)len;
+    p->remainLen -= (UInt32)len;
+    while (len != 0)
+    {
+      len--;
+      dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
+      dicPos++;
+    }
+    p->dicPos = dicPos;
+  }
+}
+
+
+#define kRange0 0xFFFFFFFF
+#define kBound0 ((kRange0 >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1))
+#define kBadRepCode (kBound0 + (((kRange0 - kBound0) >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1)))
+#if kBadRepCode != (0xC0000000 - 0x400)
+  #error Stop_Compiling_Bad_LZMA_Check
+#endif
+
+static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
+{
+  do
+  {
+    SizeT limit2 = limit;
+    if (p->checkDicSize == 0)
+    {
+      UInt32 rem = p->prop.dicSize - p->processedPos;
+      if (limit - p->dicPos > rem)
+        limit2 = p->dicPos + rem;
+
+      if (p->processedPos == 0)
+        if (p->code >= kBadRepCode)
+          return SZ_ERROR_DATA;
+    }
+
+    RINOK(LZMA_DECODE_REAL(p, limit2, bufLimit));
+    
+    if (p->checkDicSize == 0 && p->processedPos >= p->prop.dicSize)
+      p->checkDicSize = p->prop.dicSize;
+    
+    LzmaDec_WriteRem(p, limit);
+  }
+  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
+
+  return 0;
+}
+
+typedef enum
+{
+  DUMMY_ERROR, /* unexpected end of input stream */
+  DUMMY_LIT,
+  DUMMY_MATCH,
+  DUMMY_REP
+} ELzmaDummy;
+
+static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
+{
+  UInt32 range = p->range;
+  UInt32 code = p->code;
+  const Byte *bufLimit = buf + inSize;
+  const CLzmaProb *probs = GET_PROBS;
+  unsigned state = (unsigned)p->state;
+  ELzmaDummy res;
+
+  {
+    const CLzmaProb *prob;
+    UInt32 bound;
+    unsigned ttt;
+    unsigned posState = CALC_POS_STATE(p->processedPos, (1 << p->prop.pb) - 1);
+
+    prob = probs + IsMatch + COMBINED_PS_STATE;
+    IF_BIT_0_CHECK(prob)
+    {
+      UPDATE_0_CHECK
+
+      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
+
+      prob = probs + Literal;
+      if (p->checkDicSize != 0 || p->processedPos != 0)
+        prob += ((UInt32)LZMA_LIT_SIZE *
+            ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
+            (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
+
+      if (state < kNumLitStates)
+      {
+        unsigned symbol = 1;
+        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
+      }
+      else
+      {
+        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
+            (p->dicPos < p->reps[0] ? p->dicBufSize : 0)];
+        unsigned offs = 0x100;
+        unsigned symbol = 1;
+        do
+        {
+          unsigned bit;
+          const CLzmaProb *probLit;
+          matchByte += matchByte;
+          bit = offs;
+          offs &= matchByte;
+          probLit = prob + (offs + bit + symbol);
+          GET_BIT2_CHECK(probLit, symbol, offs ^= bit; , ; )
+        }
+        while (symbol < 0x100);
+      }
+      res = DUMMY_LIT;
+    }
+    else
+    {
+      unsigned len;
+      UPDATE_1_CHECK;
+
+      prob = probs + IsRep + state;
+      IF_BIT_0_CHECK(prob)
+      {
+        UPDATE_0_CHECK;
+        state = 0;
+        prob = probs + LenCoder;
+        res = DUMMY_MATCH;
+      }
+      else
+      {
+        UPDATE_1_CHECK;
+        res = DUMMY_REP;
+        prob = probs + IsRepG0 + state;
+        IF_BIT_0_CHECK(prob)
+        {
+          UPDATE_0_CHECK;
+          prob = probs + IsRep0Long + COMBINED_PS_STATE;
+          IF_BIT_0_CHECK(prob)
+          {
+            UPDATE_0_CHECK;
+            NORMALIZE_CHECK;
+            return DUMMY_REP;
+          }
+          else
+          {
+            UPDATE_1_CHECK;
+          }
+        }
+        else
+        {
+          UPDATE_1_CHECK;
+          prob = probs + IsRepG1 + state;
+          IF_BIT_0_CHECK(prob)
+          {
+            UPDATE_0_CHECK;
+          }
+          else
+          {
+            UPDATE_1_CHECK;
+            prob = probs + IsRepG2 + state;
+            IF_BIT_0_CHECK(prob)
+            {
+              UPDATE_0_CHECK;
+            }
+            else
+            {
+              UPDATE_1_CHECK;
+            }
+          }
+        }
+        state = kNumStates;
+        prob = probs + RepLenCoder;
+      }
+      {
+        unsigned limit, offset;
+        const CLzmaProb *probLen = prob + LenChoice;
+        IF_BIT_0_CHECK(probLen)
+        {
+          UPDATE_0_CHECK;
+          probLen = prob + LenLow + GET_LEN_STATE;
+          offset = 0;
+          limit = 1 << kLenNumLowBits;
+        }
+        else
+        {
+          UPDATE_1_CHECK;
+          probLen = prob + LenChoice2;
+          IF_BIT_0_CHECK(probLen)
+          {
+            UPDATE_0_CHECK;
+            probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
+            offset = kLenNumLowSymbols;
+            limit = 1 << kLenNumLowBits;
+          }
+          else
+          {
+            UPDATE_1_CHECK;
+            probLen = prob + LenHigh;
+            offset = kLenNumLowSymbols * 2;
+            limit = 1 << kLenNumHighBits;
+          }
+        }
+        TREE_DECODE_CHECK(probLen, limit, len);
+        len += offset;
+      }
+
+      if (state < 4)
+      {
+        unsigned posSlot;
+        prob = probs + PosSlot +
+            ((len < kNumLenToPosStates - 1 ? len : kNumLenToPosStates - 1) <<
+            kNumPosSlotBits);
+        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
+        if (posSlot >= kStartPosModelIndex)
+        {
+          unsigned numDirectBits = ((posSlot >> 1) - 1);
+
+          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
+
+          if (posSlot < kEndPosModelIndex)
+          {
+            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits);
+          }
+          else
+          {
+            numDirectBits -= kNumAlignBits;
+            do
+            {
+              NORMALIZE_CHECK
+              range >>= 1;
+              code -= range & (((code - range) >> 31) - 1);
+              /* if (code >= range) code -= range; */
+            }
+            while (--numDirectBits);
+            prob = probs + Align;
+            numDirectBits = kNumAlignBits;
+          }
+          {
+            unsigned i = 1;
+            unsigned m = 1;
+            do
+            {
+              REV_BIT_CHECK(prob, i, m);
+            }
+            while (--numDirectBits);
+          }
+        }
+      }
+    }
+  }
+  NORMALIZE_CHECK;
+  return res;
+}
+
+
+void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState)
+{
+  p->remainLen = kMatchSpecLenStart + 1;
+  p->tempBufSize = 0;
+
+  if (initDic)
+  {
+    p->processedPos = 0;
+    p->checkDicSize = 0;
+    p->remainLen = kMatchSpecLenStart + 2;
+  }
+  if (initState)
+    p->remainLen = kMatchSpecLenStart + 2;
+}
+
+void LzmaDec_Init(CLzmaDec *p)
+{
+  p->dicPos = 0;
+  LzmaDec_InitDicAndState(p, True, True);
+}
+
+
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
+    ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+  SizeT inSize = *srcLen;
+  (*srcLen) = 0;
+  
+  *status = LZMA_STATUS_NOT_SPECIFIED;
+
+  if (p->remainLen > kMatchSpecLenStart)
+  {
+    for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
+      p->tempBuf[p->tempBufSize++] = *src++;
+    if (p->tempBufSize != 0 && p->tempBuf[0] != 0)
+      return SZ_ERROR_DATA;
+    if (p->tempBufSize < RC_INIT_SIZE)
+    {
+      *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+      return SZ_OK;
+    }
+    p->code =
+        ((UInt32)p->tempBuf[1] << 24)
+      | ((UInt32)p->tempBuf[2] << 16)
+      | ((UInt32)p->tempBuf[3] << 8)
+      | ((UInt32)p->tempBuf[4]);
+    p->range = 0xFFFFFFFF;
+    p->tempBufSize = 0;
+
+    if (p->remainLen > kMatchSpecLenStart + 1)
+    {
+      SizeT numProbs = LzmaProps_GetNumProbs(&p->prop);
+      SizeT i;
+      CLzmaProb *probs = p->probs;
+      for (i = 0; i < numProbs; i++)
+        probs[i] = kBitModelTotal >> 1;
+      p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
+      p->state = 0;
+    }
+
+    p->remainLen = 0;
+  }
+
+  LzmaDec_WriteRem(p, dicLimit);
+
+  while (p->remainLen != kMatchSpecLenStart)
+  {
+      int checkEndMarkNow = 0;
+
+      if (p->dicPos >= dicLimit)
+      {
+        if (p->remainLen == 0 && p->code == 0)
+        {
+          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
+          return SZ_OK;
+        }
+        if (finishMode == LZMA_FINISH_ANY)
+        {
+          *status = LZMA_STATUS_NOT_FINISHED;
+          return SZ_OK;
+        }
+        if (p->remainLen != 0)
+        {
+          *status = LZMA_STATUS_NOT_FINISHED;
+          return SZ_ERROR_DATA;
+        }
+        checkEndMarkNow = 1;
+      }
+
+      if (p->tempBufSize == 0)
+      {
+        SizeT processed;
+        const Byte *bufLimit;
+        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
+        {
+          int dummyRes = LzmaDec_TryDummy(p, src, inSize);
+          if (dummyRes == DUMMY_ERROR)
+          {
+            memcpy(p->tempBuf, src, inSize);
+            p->tempBufSize = (unsigned)inSize;
+            (*srcLen) += inSize;
+            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+            return SZ_OK;
+          }
+          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
+          {
+            *status = LZMA_STATUS_NOT_FINISHED;
+            return SZ_ERROR_DATA;
+          }
+          bufLimit = src;
+        }
+        else
+          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
+        p->buf = src;
+        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
+          return SZ_ERROR_DATA;
+        processed = (SizeT)(p->buf - src);
+        (*srcLen) += processed;
+        src += processed;
+        inSize -= processed;
+      }
+      else
+      {
+        unsigned rem = p->tempBufSize, lookAhead = 0;
+        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
+          p->tempBuf[rem++] = src[lookAhead++];
+        p->tempBufSize = rem;
+        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
+        {
+          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, (SizeT)rem);
+          if (dummyRes == DUMMY_ERROR)
+          {
+            (*srcLen) += (SizeT)lookAhead;
+            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+            return SZ_OK;
+          }
+          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
+          {
+            *status = LZMA_STATUS_NOT_FINISHED;
+            return SZ_ERROR_DATA;
+          }
+        }
+        p->buf = p->tempBuf;
+        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
+          return SZ_ERROR_DATA;
+        
+        {
+          unsigned kkk = (unsigned)(p->buf - p->tempBuf);
+          if (rem < kkk)
+            return SZ_ERROR_FAIL; /* some internal error */
+          rem -= kkk;
+          if (lookAhead < rem)
+            return SZ_ERROR_FAIL; /* some internal error */
+          lookAhead -= rem;
+        }
+        (*srcLen) += (SizeT)lookAhead;
+        src += lookAhead;
+        inSize -= (SizeT)lookAhead;
+        p->tempBufSize = 0;
+      }
+  }
+  
+  if (p->code != 0)
+    return SZ_ERROR_DATA;
+  *status = LZMA_STATUS_FINISHED_WITH_MARK;
+  return SZ_OK;
+}
+
+
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+  SizeT outSize = *destLen;
+  SizeT inSize = *srcLen;
+  *srcLen = *destLen = 0;
+  for (;;)
+  {
+    SizeT inSizeCur = inSize, outSizeCur, dicPos;
+    ELzmaFinishMode curFinishMode;
+    SRes res;
+    if (p->dicPos == p->dicBufSize)
+      p->dicPos = 0;
+    dicPos = p->dicPos;
+    if (outSize > p->dicBufSize - dicPos)
+    {
+      outSizeCur = p->dicBufSize;
+      curFinishMode = LZMA_FINISH_ANY;
+    }
+    else
+    {
+      outSizeCur = dicPos + outSize;
+      curFinishMode = finishMode;
+    }
+
+    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
+    src += inSizeCur;
+    inSize -= inSizeCur;
+    *srcLen += inSizeCur;
+    outSizeCur = p->dicPos - dicPos;
+    memcpy(dest, p->dic + dicPos, outSizeCur);
+    dest += outSizeCur;
+    outSize -= outSizeCur;
+    *destLen += outSizeCur;
+    if (res != 0)
+      return res;
+    if (outSizeCur == 0 || outSize == 0)
+      return SZ_OK;
+  }
+}
+
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc)
+{
+  ISzAlloc_Free(alloc, p->probs);
+  p->probs = NULL;
+}
+
+static void LzmaDec_FreeDict(CLzmaDec *p, ISzAllocPtr alloc)
+{
+  ISzAlloc_Free(alloc, p->dic);
+  p->dic = NULL;
+}
+
+void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc)
+{
+  LzmaDec_FreeProbs(p, alloc);
+  LzmaDec_FreeDict(p, alloc);
+}
+
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
+{
+  UInt32 dicSize;
+  Byte d;
+  
+  if (size < LZMA_PROPS_SIZE)
+    return SZ_ERROR_UNSUPPORTED;
+  else
+    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
+  if (dicSize < LZMA_DIC_MIN)
+    dicSize = LZMA_DIC_MIN;
+  p->dicSize = dicSize;
+
+  d = data[0];
+  if (d >= (9 * 5 * 5))
+    return SZ_ERROR_UNSUPPORTED;
+
+  p->lc = (Byte)(d % 9);
+  d /= 9;
+  p->pb = (Byte)(d / 5);
+  p->lp = (Byte)(d % 5);
+
+  return SZ_OK;
+}
+
+static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAllocPtr alloc)
+{
+  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
+  if (!p->probs || numProbs != p->numProbs)
+  {
+    LzmaDec_FreeProbs(p, alloc);
+    p->probs = (CLzmaProb *)ISzAlloc_Alloc(alloc, numProbs * sizeof(CLzmaProb));
+    if (!p->probs)
+      return SZ_ERROR_MEM;
+    p->probs_1664 = p->probs + 1664;
+    p->numProbs = numProbs;
+  }
+  return SZ_OK;
+}
+
+SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)
+{
+  CLzmaProps propNew;
+  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
+  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
+  p->prop = propNew;
+  return SZ_OK;
+}
+
+SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)
+{
+  CLzmaProps propNew;
+  SizeT dicBufSize;
+  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
+  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
+
+  {
+    UInt32 dictSize = propNew.dicSize;
+    SizeT mask = ((UInt32)1 << 12) - 1;
+         if (dictSize >= ((UInt32)1 << 30)) mask = ((UInt32)1 << 22) - 1;
+    else if (dictSize >= ((UInt32)1 << 22)) mask = ((UInt32)1 << 20) - 1;;
+    dicBufSize = ((SizeT)dictSize + mask) & ~mask;
+    if (dicBufSize < dictSize)
+      dicBufSize = dictSize;
+  }
+
+  if (!p->dic || dicBufSize != p->dicBufSize)
+  {
+    LzmaDec_FreeDict(p, alloc);
+    p->dic = (Byte *)ISzAlloc_Alloc(alloc, dicBufSize);
+    if (!p->dic)
+    {
+      LzmaDec_FreeProbs(p, alloc);
+      return SZ_ERROR_MEM;
+    }
+  }
+  p->dicBufSize = dicBufSize;
+  p->prop = propNew;
+  return SZ_OK;
+}
+
+SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+    ELzmaStatus *status, ISzAllocPtr alloc)
+{
+  CLzmaDec p;
+  SRes res;
+  SizeT outSize = *destLen, inSize = *srcLen;
+  *destLen = *srcLen = 0;
+  *status = LZMA_STATUS_NOT_SPECIFIED;
+  if (inSize < RC_INIT_SIZE)
+    return SZ_ERROR_INPUT_EOF;
+  LzmaDec_Construct(&p);
+  RINOK(LzmaDec_AllocateProbs(&p, propData, propSize, alloc));
+  p.dic = dest;
+  p.dicBufSize = outSize;
+  LzmaDec_Init(&p);
+  *srcLen = inSize;
+  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
+  *destLen = p.dicPos;
+  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
+    res = SZ_ERROR_INPUT_EOF;
+  LzmaDec_FreeProbs(&p, alloc);
+  return res;
+}
diff --git a/deps/libchdr/deps/lzma-19.00/src/LzmaEnc.c b/deps/libchdr/deps/lzma-19.00/src/LzmaEnc.c
new file mode 100644 (file)
index 0000000..2d3839d
--- /dev/null
@@ -0,0 +1,1330 @@
+/* LzmaEnc.c -- LZMA Encoder
+2019-01-10: Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include <string.h>
+
+/* #define SHOW_STAT */
+/* #define SHOW_STAT2 */
+
+#if defined(SHOW_STAT) || defined(SHOW_STAT2)
+#include <stdio.h>
+#endif
+
+#include "LzmaEnc.h"
+
+#include "LzFind.h"
+#ifndef _7ZIP_ST
+#include "LzFindMt.h"
+#endif
+
+#ifdef SHOW_STAT
+static unsigned g_STAT_OFFSET = 0;
+#endif
+
+#define kLzmaMaxHistorySize ((UInt32)3 << 29)
+/* #define kLzmaMaxHistorySize ((UInt32)7 << 29) */
+
+#define kNumTopBits 24
+#define kTopValue ((UInt32)1 << kNumTopBits)
+
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+#define kNumMoveBits 5
+#define kProbInitValue (kBitModelTotal >> 1)
+
+#define kNumMoveReducingBits 4
+#define kNumBitPriceShiftBits 4
+#define kBitPrice (1 << kNumBitPriceShiftBits)
+
+#define REP_LEN_COUNT 64
+
+void LzmaEncProps_Init(CLzmaEncProps *p)
+{
+  p->level = 5;
+  p->dictSize = p->mc = 0;
+  p->reduceSize = (UInt64)(Int64)-1;
+  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
+  p->writeEndMark = 0;
+}
+
+void LzmaEncProps_Normalize(CLzmaEncProps *p)
+{
+  int level = p->level;
+  if (level < 0) level = 5;
+  p->level = level;
+  
+  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level <= 7 ? (1 << 25) : (1 << 26)));
+  if (p->dictSize > p->reduceSize)
+  {
+    unsigned i;
+    UInt32 reduceSize = (UInt32)p->reduceSize;
+    for (i = 11; i <= 30; i++)
+    {
+      if (reduceSize <= ((UInt32)2 << i)) { p->dictSize = ((UInt32)2 << i); break; }
+      if (reduceSize <= ((UInt32)3 << i)) { p->dictSize = ((UInt32)3 << i); break; }
+    }
+  }
+
+  if (p->lc < 0) p->lc = 3;
+  if (p->lp < 0) p->lp = 0;
+  if (p->pb < 0) p->pb = 2;
+
+  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
+  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
+  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
+  if (p->numHashBytes < 0) p->numHashBytes = 4;
+  if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
+  
+  if (p->numThreads < 0)
+    p->numThreads =
+      #ifndef _7ZIP_ST
+      ((p->btMode && p->algo) ? 2 : 1);
+      #else
+      1;
+      #endif
+}
+
+UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
+{
+  CLzmaEncProps props = *props2;
+  LzmaEncProps_Normalize(&props);
+  return props.dictSize;
+}
+
+#if (_MSC_VER >= 1400)
+/* BSR code is fast for some new CPUs */
+/* #define LZMA_LOG_BSR */
+#endif
+
+#ifdef LZMA_LOG_BSR
+
+#define kDicLogSizeMaxCompress 32
+
+#define BSR2_RET(pos, res) { unsigned long zz; _BitScanReverse(&zz, (pos)); res = (zz + zz) + ((pos >> (zz - 1)) & 1); }
+
+static unsigned GetPosSlot1(UInt32 pos)
+{
+  unsigned res;
+  BSR2_RET(pos, res);
+  return res;
+}
+#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
+#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }
+
+#else
+
+#define kNumLogBits (9 + sizeof(size_t) / 2)
+/* #define kNumLogBits (11 + sizeof(size_t) / 8 * 3) */
+
+#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
+
+static void LzmaEnc_FastPosInit(Byte *g_FastPos)
+{
+  unsigned slot;
+  g_FastPos[0] = 0;
+  g_FastPos[1] = 1;
+  g_FastPos += 2;
+  
+  for (slot = 2; slot < kNumLogBits * 2; slot++)
+  {
+    size_t k = ((size_t)1 << ((slot >> 1) - 1));
+    size_t j;
+    for (j = 0; j < k; j++)
+      g_FastPos[j] = (Byte)slot;
+    g_FastPos += k;
+  }
+}
+
+/* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */
+/*
+#define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
+  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
+  res = p->g_FastPos[pos >> zz] + (zz * 2); }
+*/
+
+/*
+#define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
+  (0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \
+  res = p->g_FastPos[pos >> zz] + (zz * 2); }
+*/
+
+#define BSR2_RET(pos, res) { unsigned zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \
+  res = p->g_FastPos[pos >> zz] + (zz * 2); }
+
+/*
+#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
+  p->g_FastPos[pos >> 6] + 12 : \
+  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
+*/
+
+#define GetPosSlot1(pos) p->g_FastPos[pos]
+#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
+#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos & (kNumFullDistances - 1)]; else BSR2_RET(pos, res); }
+
+#endif
+
+
+#define LZMA_NUM_REPS 4
+
+typedef UInt16 CState;
+typedef UInt16 CExtra;
+
+typedef struct
+{
+  UInt32 price;
+  CState state;
+  CExtra extra;
+      // 0   : normal
+      // 1   : LIT : MATCH
+      // > 1 : MATCH (extra-1) : LIT : REP0 (len)
+  UInt32 len;
+  UInt32 dist;
+  UInt32 reps[LZMA_NUM_REPS];
+} COptimal;
+
+
+// 18.06
+#define kNumOpts (1 << 11)
+#define kPackReserve (kNumOpts * 8)
+// #define kNumOpts (1 << 12)
+// #define kPackReserve (1 + kNumOpts * 2)
+
+#define kNumLenToPosStates 4
+#define kNumPosSlotBits 6
+#define kDicLogSizeMin 0
+#define kDicLogSizeMax 32
+#define kDistTableSizeMax (kDicLogSizeMax * 2)
+
+#define kNumAlignBits 4
+#define kAlignTableSize (1 << kNumAlignBits)
+#define kAlignMask (kAlignTableSize - 1)
+
+#define kStartPosModelIndex 4
+#define kEndPosModelIndex 14
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
+
+typedef
+#ifdef _LZMA_PROB32
+  UInt32
+#else
+  UInt16
+#endif
+  CLzmaProb;
+
+#define LZMA_PB_MAX 4
+#define LZMA_LC_MAX 8
+#define LZMA_LP_MAX 4
+
+#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
+
+#define kLenNumLowBits 3
+#define kLenNumLowSymbols (1 << kLenNumLowBits)
+#define kLenNumHighBits 8
+#define kLenNumHighSymbols (1 << kLenNumHighBits)
+#define kLenNumSymbolsTotal (kLenNumLowSymbols * 2 + kLenNumHighSymbols)
+
+#define LZMA_MATCH_LEN_MIN 2
+#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
+
+#define kNumStates 12
+
+
+typedef struct
+{
+  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << (kLenNumLowBits + 1)];
+  CLzmaProb high[kLenNumHighSymbols];
+} CLenEnc;
+
+
+typedef struct
+{
+  unsigned tableSize;
+  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
+  // UInt32 prices1[LZMA_NUM_PB_STATES_MAX][kLenNumLowSymbols * 2];
+  // UInt32 prices2[kLenNumSymbolsTotal];
+} CLenPriceEnc;
+
+#define GET_PRICE_LEN(p, posState, len) \
+    ((p)->prices[posState][(size_t)(len) - LZMA_MATCH_LEN_MIN])
+
+/*
+#define GET_PRICE_LEN(p, posState, len) \
+    ((p)->prices2[(size_t)(len) - 2] + ((p)->prices1[posState][((len) - 2) & (kLenNumLowSymbols * 2 - 1)] & (((len) - 2 - kLenNumLowSymbols * 2) >> 9)))
+*/
+
+typedef struct
+{
+  UInt32 range;
+  unsigned cache;
+  UInt64 low;
+  UInt64 cacheSize;
+  Byte *buf;
+  Byte *bufLim;
+  Byte *bufBase;
+  ISeqOutStream *outStream;
+  UInt64 processed;
+  SRes res;
+} CRangeEnc;
+
+
+typedef struct
+{
+  CLzmaProb *litProbs;
+
+  unsigned state;
+  UInt32 reps[LZMA_NUM_REPS];
+
+  CLzmaProb posAlignEncoder[1 << kNumAlignBits];
+  CLzmaProb isRep[kNumStates];
+  CLzmaProb isRepG0[kNumStates];
+  CLzmaProb isRepG1[kNumStates];
+  CLzmaProb isRepG2[kNumStates];
+  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
+  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
+
+  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
+  CLzmaProb posEncoders[kNumFullDistances];
+  
+  CLenEnc lenProbs;
+  CLenEnc repLenProbs;
+
+} CSaveState;
+
+
+typedef UInt32 CProbPrice;
+
+
+typedef struct
+{
+  void *matchFinderObj;
+  IMatchFinder matchFinder;
+
+  unsigned optCur;
+  unsigned optEnd;
+
+  unsigned longestMatchLen;
+  unsigned numPairs;
+  UInt32 numAvail;
+
+  unsigned state;
+  unsigned numFastBytes;
+  unsigned additionalOffset;
+  UInt32 reps[LZMA_NUM_REPS];
+  unsigned lpMask, pbMask;
+  CLzmaProb *litProbs;
+  CRangeEnc rc;
+
+  UInt32 backRes;
+
+  unsigned lc, lp, pb;
+  unsigned lclp;
+
+  BoolInt fastMode;
+  BoolInt writeEndMark;
+  BoolInt finished;
+  BoolInt multiThread;
+  BoolInt needInit;
+  // BoolInt _maxMode;
+
+  UInt64 nowPos64;
+  
+  unsigned matchPriceCount;
+  // unsigned alignPriceCount;
+  int repLenEncCounter;
+
+  unsigned distTableSize;
+
+  UInt32 dictSize;
+  SRes result;
+
+  #ifndef _7ZIP_ST
+  BoolInt mtMode;
+  // begin of CMatchFinderMt is used in LZ thread
+  CMatchFinderMt matchFinderMt;
+  // end of CMatchFinderMt is used in BT and HASH threads
+  #endif
+
+  CMatchFinder matchFinderBase;
+
+  #ifndef _7ZIP_ST
+  Byte pad[128];
+  #endif
+  
+  // LZ thread
+  CProbPrice ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
+
+  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
+
+  UInt32 alignPrices[kAlignTableSize];
+  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
+  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];
+
+  CLzmaProb posAlignEncoder[1 << kNumAlignBits];
+  CLzmaProb isRep[kNumStates];
+  CLzmaProb isRepG0[kNumStates];
+  CLzmaProb isRepG1[kNumStates];
+  CLzmaProb isRepG2[kNumStates];
+  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
+  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
+  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
+  CLzmaProb posEncoders[kNumFullDistances];
+  
+  CLenEnc lenProbs;
+  CLenEnc repLenProbs;
+
+  #ifndef LZMA_LOG_BSR
+  Byte g_FastPos[1 << kNumLogBits];
+  #endif
+
+  CLenPriceEnc lenEnc;
+  CLenPriceEnc repLenEnc;
+
+  COptimal opt[kNumOpts];
+
+  CSaveState saveState;
+
+  #ifndef _7ZIP_ST
+  Byte pad2[128];
+  #endif
+} CLzmaEnc;
+
+
+SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  CLzmaEncProps props = *props2;
+  LzmaEncProps_Normalize(&props);
+
+  if (props.lc > LZMA_LC_MAX
+      || props.lp > LZMA_LP_MAX
+      || props.pb > LZMA_PB_MAX
+      || props.dictSize > ((UInt64)1 << kDicLogSizeMaxCompress)
+      || props.dictSize > kLzmaMaxHistorySize)
+    return SZ_ERROR_PARAM;
+
+  p->dictSize = props.dictSize;
+  {
+    unsigned fb = props.fb;
+    if (fb < 5)
+      fb = 5;
+    if (fb > LZMA_MATCH_LEN_MAX)
+      fb = LZMA_MATCH_LEN_MAX;
+    p->numFastBytes = fb;
+  }
+  p->lc = props.lc;
+  p->lp = props.lp;
+  p->pb = props.pb;
+  p->fastMode = (props.algo == 0);
+  // p->_maxMode = True;
+  p->matchFinderBase.btMode = (Byte)(props.btMode ? 1 : 0);
+  {
+    unsigned numHashBytes = 4;
+    if (props.btMode)
+    {
+      if (props.numHashBytes < 2)
+        numHashBytes = 2;
+      else if (props.numHashBytes < 4)
+        numHashBytes = props.numHashBytes;
+    }
+    p->matchFinderBase.numHashBytes = numHashBytes;
+  }
+
+  p->matchFinderBase.cutValue = props.mc;
+
+  p->writeEndMark = props.writeEndMark;
+
+  #ifndef _7ZIP_ST
+  /*
+  if (newMultiThread != _multiThread)
+  {
+    ReleaseMatchFinder();
+    _multiThread = newMultiThread;
+  }
+  */
+  p->multiThread = (props.numThreads > 1);
+  #endif
+
+  return SZ_OK;
+}
+
+
+void LzmaEnc_SetDataSize(CLzmaEncHandle pp, UInt64 expectedDataSiize)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  p->matchFinderBase.expectedDataSize = expectedDataSiize;
+}
+
+
+#define kState_Start 0
+#define kState_LitAfterMatch 4
+#define kState_LitAfterRep   5
+#define kState_MatchAfterLit 7
+#define kState_RepAfterLit   8
+
+static const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};
+static const Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
+static const Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
+static const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
+
+#define IsLitState(s) ((s) < 7)
+#define GetLenToPosState2(len) (((len) < kNumLenToPosStates - 1) ? (len) : kNumLenToPosStates - 1)
+#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
+
+#define kInfinityPrice (1 << 30)
+
+static void RangeEnc_Construct(CRangeEnc *p)
+{
+  p->outStream = NULL;
+  p->bufBase = NULL;
+}
+
+#define RangeEnc_GetProcessed(p)       ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
+#define RangeEnc_GetProcessed_sizet(p) ((size_t)(p)->processed + ((p)->buf - (p)->bufBase) + (size_t)(p)->cacheSize)
+
+#define RC_BUF_SIZE (1 << 16)
+
+static int RangeEnc_Alloc(CRangeEnc *p, ISzAllocPtr alloc)
+{
+  if (!p->bufBase)
+  {
+    p->bufBase = (Byte *)ISzAlloc_Alloc(alloc, RC_BUF_SIZE);
+    if (!p->bufBase)
+      return 0;
+    p->bufLim = p->bufBase + RC_BUF_SIZE;
+  }
+  return 1;
+}
+
+static void RangeEnc_Free(CRangeEnc *p, ISzAllocPtr alloc)
+{
+  ISzAlloc_Free(alloc, p->bufBase);
+  p->bufBase = 0;
+}
+
+static void RangeEnc_Init(CRangeEnc *p)
+{
+  /* Stream.Init(); */
+  p->range = 0xFFFFFFFF;
+  p->cache = 0;
+  p->low = 0;
+  p->cacheSize = 0;
+
+  p->buf = p->bufBase;
+
+  p->processed = 0;
+  p->res = SZ_OK;
+}
+
+MY_NO_INLINE static void RangeEnc_FlushStream(CRangeEnc *p)
+{
+  size_t num;
+  if (p->res != SZ_OK)
+    return;
+  num = p->buf - p->bufBase;
+  if (num != ISeqOutStream_Write(p->outStream, p->bufBase, num))
+    p->res = SZ_ERROR_WRITE;
+  p->processed += num;
+  p->buf = p->bufBase;
+}
+
+MY_NO_INLINE static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
+{
+  UInt32 low = (UInt32)p->low;
+  unsigned high = (unsigned)(p->low >> 32);
+  p->low = (UInt32)(low << 8);
+  if (low < (UInt32)0xFF000000 || high != 0)
+  {
+    {
+      Byte *buf = p->buf;
+      *buf++ = (Byte)(p->cache + high);
+      p->cache = (unsigned)(low >> 24);
+      p->buf = buf;
+      if (buf == p->bufLim)
+        RangeEnc_FlushStream(p);
+      if (p->cacheSize == 0)
+        return;
+    }
+    high += 0xFF;
+    for (;;)
+    {
+      Byte *buf = p->buf;
+      *buf++ = (Byte)(high);
+      p->buf = buf;
+      if (buf == p->bufLim)
+        RangeEnc_FlushStream(p);
+      if (--p->cacheSize == 0)
+        return;
+    }
+  }
+  p->cacheSize++;
+}
+
+static void RangeEnc_FlushData(CRangeEnc *p)
+{
+  int i;
+  for (i = 0; i < 5; i++)
+    RangeEnc_ShiftLow(p);
+}
+
+#define RC_NORM(p) if (range < kTopValue) { range <<= 8; RangeEnc_ShiftLow(p); }
+
+#define RC_BIT_PRE(p, prob) \
+  ttt = *(prob); \
+  newBound = (range >> kNumBitModelTotalBits) * ttt;
+
+// #define _LZMA_ENC_USE_BRANCH
+
+#ifdef _LZMA_ENC_USE_BRANCH
+
+#define RC_BIT(p, prob, bit) { \
+  RC_BIT_PRE(p, prob) \
+  if (bit == 0) { range = newBound; ttt += (kBitModelTotal - ttt) >> kNumMoveBits; } \
+  else { (p)->low += newBound; range -= newBound; ttt -= ttt >> kNumMoveBits; } \
+  *(prob) = (CLzmaProb)ttt; \
+  RC_NORM(p) \
+  }
+
+#else
+
+#define RC_BIT(p, prob, bit) { \
+  UInt32 mask; \
+  RC_BIT_PRE(p, prob) \
+  mask = 0 - (UInt32)bit; \
+  range &= mask; \
+  mask &= newBound; \
+  range -= mask; \
+  (p)->low += mask; \
+  mask = (UInt32)bit - 1; \
+  range += newBound & mask; \
+  mask &= (kBitModelTotal - ((1 << kNumMoveBits) - 1)); \
+  mask += ((1 << kNumMoveBits) - 1); \
+  ttt += (Int32)(mask - ttt) >> kNumMoveBits; \
+  *(prob) = (CLzmaProb)ttt; \
+  RC_NORM(p) \
+  }
+
+#endif
+
+
+
+
+#define RC_BIT_0_BASE(p, prob) \
+  range = newBound; *(prob) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
+
+#define RC_BIT_1_BASE(p, prob) \
+  range -= newBound; (p)->low += newBound; *(prob) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits)); \
+
+#define RC_BIT_0(p, prob) \
+  RC_BIT_0_BASE(p, prob) \
+  RC_NORM(p)
+
+#define RC_BIT_1(p, prob) \
+  RC_BIT_1_BASE(p, prob) \
+  RC_NORM(p)
+
+static void RangeEnc_EncodeBit_0(CRangeEnc *p, CLzmaProb *prob)
+{
+  UInt32 range, ttt, newBound;
+  range = p->range;
+  RC_BIT_PRE(p, prob)
+  RC_BIT_0(p, prob)
+  p->range = range;
+}
+
+static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 sym)
+{
+  UInt32 range = p->range;
+  sym |= 0x100;
+  do
+  {
+    UInt32 ttt, newBound;
+    // RangeEnc_EncodeBit(p, probs + (sym >> 8), (sym >> 7) & 1);
+    CLzmaProb *prob = probs + (sym >> 8);
+    UInt32 bit = (sym >> 7) & 1;
+    sym <<= 1;
+    RC_BIT(p, prob, bit);
+  }
+  while (sym < 0x10000);
+  p->range = range;
+}
+
+static void LzmaEnc_InitPriceTables(CProbPrice *ProbPrices)
+{
+  UInt32 i;
+  for (i = 0; i < (kBitModelTotal >> kNumMoveReducingBits); i++)
+  {
+    const unsigned kCyclesBits = kNumBitPriceShiftBits;
+    UInt32 w = (i << kNumMoveReducingBits) + (1 << (kNumMoveReducingBits - 1));
+    unsigned bitCount = 0;
+    unsigned j;
+    for (j = 0; j < kCyclesBits; j++)
+    {
+      w = w * w;
+      bitCount <<= 1;
+      while (w >= ((UInt32)1 << 16))
+      {
+        w >>= 1;
+        bitCount++;
+      }
+    }
+    ProbPrices[i] = (CProbPrice)((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
+    // printf("\n%3d: %5d", i, ProbPrices[i]);
+  }
+}
+
+
+#define GET_PRICE(prob, bit) \
+  p->ProbPrices[((prob) ^ (unsigned)(((-(int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
+
+#define GET_PRICEa(prob, bit) \
+     ProbPrices[((prob) ^ (unsigned)((-((int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
+
+#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
+#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
+
+#define GET_PRICEa_0(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
+#define GET_PRICEa_1(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
+
+
+static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 sym, const CProbPrice *ProbPrices)
+{
+  UInt32 price = 0;
+  sym |= 0x100;
+  do
+  {
+    unsigned bit = sym & 1;
+    sym >>= 1;
+    price += GET_PRICEa(probs[sym], bit);
+  }
+  while (sym >= 2);
+  return price;
+}
+
+
+static UInt32 LitEnc_Matched_GetPrice(const CLzmaProb *probs, UInt32 sym, UInt32 matchByte, const CProbPrice *ProbPrices)
+{
+  UInt32 price = 0;
+  UInt32 offs = 0x100;
+  sym |= 0x100;
+  do
+  {
+    matchByte <<= 1;
+    price += GET_PRICEa(probs[offs + (matchByte & offs) + (sym >> 8)], (sym >> 7) & 1);
+    sym <<= 1;
+    offs &= ~(matchByte ^ sym);
+  }
+  while (sym < 0x10000);
+  return price;
+}
+
+
+
+static void LenEnc_Init(CLenEnc *p)
+{
+  unsigned i;
+  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << (kLenNumLowBits + 1)); i++)
+    p->low[i] = kProbInitValue;
+  for (i = 0; i < kLenNumHighSymbols; i++)
+    p->high[i] = kProbInitValue;
+}
+
+static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned sym, unsigned posState)
+{
+  UInt32 range, ttt, newBound;
+  CLzmaProb *probs = p->low;
+  range = rc->range;
+  RC_BIT_PRE(rc, probs);
+  if (sym >= kLenNumLowSymbols)
+  {
+    RC_BIT_1(rc, probs);
+    probs += kLenNumLowSymbols;
+    RC_BIT_PRE(rc, probs);
+    if (sym >= kLenNumLowSymbols * 2)
+    {
+      RC_BIT_1(rc, probs);
+      rc->range = range;
+      // RcTree_Encode(rc, p->high, kLenNumHighBits, sym - kLenNumLowSymbols * 2);
+      LitEnc_Encode(rc, p->high, sym - kLenNumLowSymbols * 2);
+      return;
+    }
+    sym -= kLenNumLowSymbols;
+  }
+
+  // RcTree_Encode(rc, probs + (posState << kLenNumLowBits), kLenNumLowBits, sym);
+  {
+    unsigned m;
+    unsigned bit;
+    RC_BIT_0(rc, probs);
+    probs += (posState << (1 + kLenNumLowBits));
+    bit = (sym >> 2)    ; RC_BIT(rc, probs + 1, bit); m = (1 << 1) + bit;
+    bit = (sym >> 1) & 1; RC_BIT(rc, probs + m, bit); m = (m << 1) + bit;
+    bit =  sym       & 1; RC_BIT(rc, probs + m, bit);
+    rc->range = range;
+  }
+}
+
+static void SetPrices_3(const CLzmaProb *probs, UInt32 startPrice, UInt32 *prices, const CProbPrice *ProbPrices)
+{
+  unsigned i;
+  for (i = 0; i < 8; i += 2)
+  {
+    UInt32 price = startPrice;
+    UInt32 prob;
+    price += GET_PRICEa(probs[1           ], (i >> 2));
+    price += GET_PRICEa(probs[2 + (i >> 2)], (i >> 1) & 1);
+    prob = probs[4 + (i >> 1)];
+    prices[i    ] = price + GET_PRICEa_0(prob);
+    prices[i + 1] = price + GET_PRICEa_1(prob);
+  }
+}
+
+
+MY_NO_INLINE static void MY_FAST_CALL LenPriceEnc_UpdateTables(
+    CLenPriceEnc *p,
+    unsigned numPosStates,
+    const CLenEnc *enc,
+    const CProbPrice *ProbPrices)
+{
+  UInt32 b;
+  {
+    unsigned prob = enc->low[0];
+    UInt32 a, c;
+    unsigned posState;
+    b = GET_PRICEa_1(prob);
+    a = GET_PRICEa_0(prob);
+    c = b + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
+    for (posState = 0; posState < numPosStates; posState++)
+    {
+      UInt32 *prices = p->prices[posState];
+      const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits));
+      SetPrices_3(probs, a, prices, ProbPrices);
+      SetPrices_3(probs + kLenNumLowSymbols, c, prices + kLenNumLowSymbols, ProbPrices);
+    }
+  }
+
+  /*
+  {
+    unsigned i;
+    UInt32 b;
+    a = GET_PRICEa_0(enc->low[0]);
+    for (i = 0; i < kLenNumLowSymbols; i++)
+      p->prices2[i] = a;
+    a = GET_PRICEa_1(enc->low[0]);
+    b = a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
+    for (i = kLenNumLowSymbols; i < kLenNumLowSymbols * 2; i++)
+      p->prices2[i] = b;
+    a += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
+  }
+  */
+  // p->counter = numSymbols;
+  // p->counter = 64;
+
+  {
+    unsigned i = p->tableSize;
+    
+    if (i > kLenNumLowSymbols * 2)
+    {
+      const CLzmaProb *probs = enc->high;
+      UInt32 *prices = p->prices[0] + kLenNumLowSymbols * 2;
+      i -= kLenNumLowSymbols * 2 - 1;
+      i >>= 1;
+      b += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
+      do
+      {
+        /*
+        p->prices2[i] = a +
+        // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices);
+        LitEnc_GetPrice(probs, i - kLenNumLowSymbols * 2, ProbPrices);
+        */
+        // UInt32 price = a + RcTree_GetPrice(probs, kLenNumHighBits - 1, sym, ProbPrices);
+        unsigned sym = --i + (1 << (kLenNumHighBits - 1));
+        UInt32 price = b;
+        do
+        {
+          unsigned bit = sym & 1;
+          sym >>= 1;
+          price += GET_PRICEa(probs[sym], bit);
+        }
+        while (sym >= 2);
+
+        {
+          unsigned prob = probs[(size_t)i + (1 << (kLenNumHighBits - 1))];
+          prices[(size_t)i * 2    ] = price + GET_PRICEa_0(prob);
+          prices[(size_t)i * 2 + 1] = price + GET_PRICEa_1(prob);
+        }
+      }
+      while (i);
+
+      {
+        unsigned posState;
+        size_t num = (p->tableSize - kLenNumLowSymbols * 2) * sizeof(p->prices[0][0]);
+        for (posState = 1; posState < numPosStates; posState++)
+          memcpy(p->prices[posState] + kLenNumLowSymbols * 2, p->prices[0] + kLenNumLowSymbols * 2, num);
+      }
+    }
+  }
+}
+
+/*
+  #ifdef SHOW_STAT
+  g_STAT_OFFSET += num;
+  printf("\n MovePos %u", num);
+  #endif
+*/
+  
+#define MOVE_POS(p, num) { \
+    p->additionalOffset += (num); \
+    p->matchFinder.Skip(p->matchFinderObj, (UInt32)(num)); }
+
+
+#define MARK_LIT ((UInt32)(Int32)-1)
+
+#define MakeAs_Lit(p)       { (p)->dist = MARK_LIT; (p)->extra = 0; }
+#define MakeAs_ShortRep(p)  { (p)->dist = 0; (p)->extra = 0; }
+#define IsShortRep(p)       ((p)->dist == 0)
+
+
+#define GetPrice_ShortRep(p, state, posState) \
+  ( GET_PRICE_0(p->isRepG0[state]) + GET_PRICE_0(p->isRep0Long[state][posState]))
+
+#define GetPrice_Rep_0(p, state, posState) ( \
+    GET_PRICE_1(p->isMatch[state][posState]) \
+  + GET_PRICE_1(p->isRep0Long[state][posState])) \
+  + GET_PRICE_1(p->isRep[state]) \
+  + GET_PRICE_0(p->isRepG0[state])
+  
+MY_FORCE_INLINE
+static UInt32 GetPrice_PureRep(const CLzmaEnc *p, unsigned repIndex, size_t state, size_t posState)
+{
+  UInt32 price;
+  UInt32 prob = p->isRepG0[state];
+  if (repIndex == 0)
+  {
+    price = GET_PRICE_0(prob);
+    price += GET_PRICE_1(p->isRep0Long[state][posState]);
+  }
+  else
+  {
+    price = GET_PRICE_1(prob);
+    prob = p->isRepG1[state];
+    if (repIndex == 1)
+      price += GET_PRICE_0(prob);
+    else
+    {
+      price += GET_PRICE_1(prob);
+      price += GET_PRICE(p->isRepG2[state], repIndex - 2);
+    }
+  }
+  return price;
+}
+
+
+static SRes CheckErrors(CLzmaEnc *p)
+{
+  if (p->result != SZ_OK)
+    return p->result;
+  if (p->rc.res != SZ_OK)
+    p->result = SZ_ERROR_WRITE;
+  if (p->matchFinderBase.result != SZ_OK)
+    p->result = SZ_ERROR_READ;
+  if (p->result != SZ_OK)
+    p->finished = True;
+  return p->result;
+}
+
+
+MY_NO_INLINE static void FillAlignPrices(CLzmaEnc *p)
+{
+  unsigned i;
+  const CProbPrice *ProbPrices = p->ProbPrices;
+  const CLzmaProb *probs = p->posAlignEncoder;
+  // p->alignPriceCount = 0;
+  for (i = 0; i < kAlignTableSize / 2; i++)
+  {
+    UInt32 price = 0;
+    unsigned sym = i;
+    unsigned m = 1;
+    unsigned bit;
+    UInt32 prob;
+    bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
+    bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
+    bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
+    prob = probs[m];
+    p->alignPrices[i    ] = price + GET_PRICEa_0(prob);
+    p->alignPrices[i + 8] = price + GET_PRICEa_1(prob);
+    // p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);
+  }
+}
+
+
+MY_NO_INLINE static void FillDistancesPrices(CLzmaEnc *p)
+{
+  // int y; for (y = 0; y < 100; y++) {
+
+  UInt32 tempPrices[kNumFullDistances];
+  unsigned i, lps;
+
+  const CProbPrice *ProbPrices = p->ProbPrices;
+  p->matchPriceCount = 0;
+
+  for (i = kStartPosModelIndex / 2; i < kNumFullDistances / 2; i++)
+  {
+    unsigned posSlot = GetPosSlot1(i);
+    unsigned footerBits = (posSlot >> 1) - 1;
+    unsigned base = ((2 | (posSlot & 1)) << footerBits);
+    const CLzmaProb *probs = p->posEncoders + (size_t)base * 2;
+    // tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base, footerBits, i - base, p->ProbPrices);
+    UInt32 price = 0;
+    unsigned m = 1;
+    unsigned sym = i;
+    unsigned offset = (unsigned)1 << footerBits;
+    base += i;
+    
+    if (footerBits)
+    do
+    {
+      unsigned bit = sym & 1;
+      sym >>= 1;
+      price += GET_PRICEa(probs[m], bit);
+      m = (m << 1) + bit;
+    }
+    while (--footerBits);
+
+    {
+      unsigned prob = probs[m];
+      tempPrices[base         ] = price + GET_PRICEa_0(prob);
+      tempPrices[base + offset] = price + GET_PRICEa_1(prob);
+    }
+  }
+
+  for (lps = 0; lps < kNumLenToPosStates; lps++)
+  {
+    unsigned slot;
+    unsigned distTableSize2 = (p->distTableSize + 1) >> 1;
+    UInt32 *posSlotPrices = p->posSlotPrices[lps];
+    const CLzmaProb *probs = p->posSlotEncoder[lps];
+    
+    for (slot = 0; slot < distTableSize2; slot++)
+    {
+      // posSlotPrices[slot] = RcTree_GetPrice(encoder, kNumPosSlotBits, slot, p->ProbPrices);
+      UInt32 price;
+      unsigned bit;
+      unsigned sym = slot + (1 << (kNumPosSlotBits - 1));
+      unsigned prob;
+      bit = sym & 1; sym >>= 1; price  = GET_PRICEa(probs[sym], bit);
+      bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+      bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+      bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+      bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+      prob = probs[(size_t)slot + (1 << (kNumPosSlotBits - 1))];
+      posSlotPrices[(size_t)slot * 2    ] = price + GET_PRICEa_0(prob);
+      posSlotPrices[(size_t)slot * 2 + 1] = price + GET_PRICEa_1(prob);
+    }
+    
+    {
+      UInt32 delta = ((UInt32)((kEndPosModelIndex / 2 - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
+      for (slot = kEndPosModelIndex / 2; slot < distTableSize2; slot++)
+      {
+        posSlotPrices[(size_t)slot * 2    ] += delta;
+        posSlotPrices[(size_t)slot * 2 + 1] += delta;
+        delta += ((UInt32)1 << kNumBitPriceShiftBits);
+      }
+    }
+
+    {
+      UInt32 *dp = p->distancesPrices[lps];
+      
+      dp[0] = posSlotPrices[0];
+      dp[1] = posSlotPrices[1];
+      dp[2] = posSlotPrices[2];
+      dp[3] = posSlotPrices[3];
+
+      for (i = 4; i < kNumFullDistances; i += 2)
+      {
+        UInt32 slotPrice = posSlotPrices[GetPosSlot1(i)];
+        dp[i    ] = slotPrice + tempPrices[i];
+        dp[i + 1] = slotPrice + tempPrices[i + 1];
+      }
+    }
+  }
+  // }
+}
+
+
+
+void LzmaEnc_Construct(CLzmaEnc *p)
+{
+  RangeEnc_Construct(&p->rc);
+  MatchFinder_Construct(&p->matchFinderBase);
+  
+  #ifndef _7ZIP_ST
+  MatchFinderMt_Construct(&p->matchFinderMt);
+  p->matchFinderMt.MatchFinder = &p->matchFinderBase;
+  #endif
+
+  {
+    CLzmaEncProps props;
+    LzmaEncProps_Init(&props);
+    LzmaEnc_SetProps(p, &props);
+  }
+
+  #ifndef LZMA_LOG_BSR
+  LzmaEnc_FastPosInit(p->g_FastPos);
+  #endif
+
+  LzmaEnc_InitPriceTables(p->ProbPrices);
+  p->litProbs = NULL;
+  p->saveState.litProbs = NULL;
+
+}
+
+CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc)
+{
+  void *p;
+  p = ISzAlloc_Alloc(alloc, sizeof(CLzmaEnc));
+  if (p)
+    LzmaEnc_Construct((CLzmaEnc *)p);
+  return p;
+}
+
+void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAllocPtr alloc)
+{
+  ISzAlloc_Free(alloc, p->litProbs);
+  ISzAlloc_Free(alloc, p->saveState.litProbs);
+  p->litProbs = NULL;
+  p->saveState.litProbs = NULL;
+}
+
+void LzmaEnc_Destruct(CLzmaEnc *p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+  #ifndef _7ZIP_ST
+  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
+  #endif
+  
+  MatchFinder_Free(&p->matchFinderBase, allocBig);
+  LzmaEnc_FreeLits(p, alloc);
+  RangeEnc_Free(&p->rc, alloc);
+}
+
+void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);
+  ISzAlloc_Free(alloc, p);
+}
+
+
+#define kBigHashDicLimit ((UInt32)1 << 24)
+
+static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+  UInt32 beforeSize = kNumOpts;
+  if (!RangeEnc_Alloc(&p->rc, alloc))
+    return SZ_ERROR_MEM;
+
+  #ifndef _7ZIP_ST
+  p->mtMode = (p->multiThread && !p->fastMode && (p->matchFinderBase.btMode != 0));
+  #endif
+
+  {
+    unsigned lclp = p->lc + p->lp;
+    if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp)
+    {
+      LzmaEnc_FreeLits(p, alloc);
+      p->litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
+      p->saveState.litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
+      if (!p->litProbs || !p->saveState.litProbs)
+      {
+        LzmaEnc_FreeLits(p, alloc);
+        return SZ_ERROR_MEM;
+      }
+      p->lclp = lclp;
+    }
+  }
+
+  p->matchFinderBase.bigHash = (Byte)(p->dictSize > kBigHashDicLimit ? 1 : 0);
+
+  if (beforeSize + p->dictSize < keepWindowSize)
+    beforeSize = keepWindowSize - p->dictSize;
+
+  #ifndef _7ZIP_ST
+  if (p->mtMode)
+  {
+    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes,
+        LZMA_MATCH_LEN_MAX
+        + 1  /* 18.04 */
+        , allocBig));
+    p->matchFinderObj = &p->matchFinderMt;
+    p->matchFinderBase.bigHash = (Byte)(
+        (p->dictSize > kBigHashDicLimit && p->matchFinderBase.hashMask >= 0xFFFFFF) ? 1 : 0);
+    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
+  }
+  else
+  #endif
+  {
+    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))
+      return SZ_ERROR_MEM;
+    p->matchFinderObj = &p->matchFinderBase;
+    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);
+  }
+  
+  return SZ_OK;
+}
+
+void LzmaEnc_Init(CLzmaEnc *p)
+{
+  unsigned i;
+  p->state = 0;
+  p->reps[0] =
+  p->reps[1] =
+  p->reps[2] =
+  p->reps[3] = 1;
+
+  RangeEnc_Init(&p->rc);
+
+  for (i = 0; i < (1 << kNumAlignBits); i++)
+    p->posAlignEncoder[i] = kProbInitValue;
+
+  for (i = 0; i < kNumStates; i++)
+  {
+    unsigned j;
+    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
+    {
+      p->isMatch[i][j] = kProbInitValue;
+      p->isRep0Long[i][j] = kProbInitValue;
+    }
+    p->isRep[i] = kProbInitValue;
+    p->isRepG0[i] = kProbInitValue;
+    p->isRepG1[i] = kProbInitValue;
+    p->isRepG2[i] = kProbInitValue;
+  }
+
+  {
+    for (i = 0; i < kNumLenToPosStates; i++)
+    {
+      CLzmaProb *probs = p->posSlotEncoder[i];
+      unsigned j;
+      for (j = 0; j < (1 << kNumPosSlotBits); j++)
+        probs[j] = kProbInitValue;
+    }
+  }
+  {
+    for (i = 0; i < kNumFullDistances; i++)
+      p->posEncoders[i] = kProbInitValue;
+  }
+
+  {
+    UInt32 num = (UInt32)0x300 << (p->lp + p->lc);
+    UInt32 k;
+    CLzmaProb *probs = p->litProbs;
+    for (k = 0; k < num; k++)
+      probs[k] = kProbInitValue;
+  }
+
+
+  LenEnc_Init(&p->lenProbs);
+  LenEnc_Init(&p->repLenProbs);
+
+  p->optEnd = 0;
+  p->optCur = 0;
+
+  {
+    for (i = 0; i < kNumOpts; i++)
+      p->opt[i].price = kInfinityPrice;
+  }
+
+  p->additionalOffset = 0;
+
+  p->pbMask = (1 << p->pb) - 1;
+  p->lpMask = ((UInt32)0x100 << p->lp) - ((unsigned)0x100 >> p->lc);
+}
+
+
+void LzmaEnc_InitPrices(CLzmaEnc *p)
+{
+  if (!p->fastMode)
+  {
+    FillDistancesPrices(p);
+    FillAlignPrices(p);
+  }
+
+  p->lenEnc.tableSize =
+  p->repLenEnc.tableSize =
+      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
+
+  p->repLenEncCounter = REP_LEN_COUNT;
+
+  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices);
+  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, &p->repLenProbs, p->ProbPrices);
+}
+
+typedef struct
+{
+  ISeqOutStream vt;
+  Byte *data;
+  SizeT rem;
+  BoolInt overflow;
+} CLzmaEnc_SeqOutStreamBuf;
+
+static size_t SeqOutStreamBuf_Write(const ISeqOutStream *pp, const void *data, size_t size)
+{
+  CLzmaEnc_SeqOutStreamBuf *p = CONTAINER_FROM_VTBL(pp, CLzmaEnc_SeqOutStreamBuf, vt);
+  if (p->rem < size)
+  {
+    size = p->rem;
+    p->overflow = True;
+  }
+  memcpy(p->data, data, size);
+  p->rem -= size;
+  p->data += size;
+  return size;
+}
+
+
+UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
+{
+  const CLzmaEnc *p = (CLzmaEnc *)pp;
+  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+}
+
+
+const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
+{
+  const CLzmaEnc *p = (CLzmaEnc *)pp;
+  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
+}
+
+
+SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  unsigned i;
+  UInt32 dictSize = p->dictSize;
+  if (*size < LZMA_PROPS_SIZE)
+    return SZ_ERROR_PARAM;
+  *size = LZMA_PROPS_SIZE;
+  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);
+
+  if (dictSize >= ((UInt32)1 << 22))
+  {
+    UInt32 kDictMask = ((UInt32)1 << 20) - 1;
+    if (dictSize < (UInt32)0xFFFFFFFF - kDictMask)
+      dictSize = (dictSize + kDictMask) & ~kDictMask;
+  }
+  else for (i = 11; i <= 30; i++)
+  {
+    if (dictSize <= ((UInt32)2 << i)) { dictSize = (2 << i); break; }
+    if (dictSize <= ((UInt32)3 << i)) { dictSize = (3 << i); break; }
+  }
+
+  for (i = 0; i < 4; i++)
+    props[1 + i] = (Byte)(dictSize >> (8 * i));
+  return SZ_OK;
+}
+
+
+
+
similarity index 94%
rename from deps/lzma-16.04/C/Sort.c
rename to deps/libchdr/deps/lzma-19.00/src/Sort.c
index 73dcbf0..e1097e3 100644 (file)
-/* Sort.c -- Sort functions\r
-2014-04-05 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Sort.h"\r
-\r
-#define HeapSortDown(p, k, size, temp) \\r
-  { for (;;) { \\r
-    size_t s = (k << 1); \\r
-    if (s > size) break; \\r
-    if (s < size && p[s + 1] > p[s]) s++; \\r
-    if (temp >= p[s]) break; \\r
-    p[k] = p[s]; k = s; \\r
-  } p[k] = temp; }\r
-\r
-void HeapSort(UInt32 *p, size_t size)\r
-{\r
-  if (size <= 1)\r
-    return;\r
-  p--;\r
-  {\r
-    size_t i = size / 2;\r
-    do\r
-    {\r
-      UInt32 temp = p[i];\r
-      size_t k = i;\r
-      HeapSortDown(p, k, size, temp)\r
-    }\r
-    while (--i != 0);\r
-  }\r
-  /*\r
-  do\r
-  {\r
-    size_t k = 1;\r
-    UInt32 temp = p[size];\r
-    p[size--] = p[1];\r
-    HeapSortDown(p, k, size, temp)\r
-  }\r
-  while (size > 1);\r
-  */\r
-  while (size > 3)\r
-  {\r
-    UInt32 temp = p[size];\r
-    size_t k = (p[3] > p[2]) ? 3 : 2;\r
-    p[size--] = p[1];\r
-    p[1] = p[k];\r
-    HeapSortDown(p, k, size, temp)\r
-  }\r
-  {\r
-    UInt32 temp = p[size];\r
-    p[size] = p[1];\r
-    if (size > 2 && p[2] < temp)\r
-    {\r
-      p[1] = p[2];\r
-      p[2] = temp;\r
-    }\r
-    else\r
-      p[1] = temp;\r
-  }\r
-}\r
-\r
-void HeapSort64(UInt64 *p, size_t size)\r
-{\r
-  if (size <= 1)\r
-    return;\r
-  p--;\r
-  {\r
-    size_t i = size / 2;\r
-    do\r
-    {\r
-      UInt64 temp = p[i];\r
-      size_t k = i;\r
-      HeapSortDown(p, k, size, temp)\r
-    }\r
-    while (--i != 0);\r
-  }\r
-  /*\r
-  do\r
-  {\r
-    size_t k = 1;\r
-    UInt64 temp = p[size];\r
-    p[size--] = p[1];\r
-    HeapSortDown(p, k, size, temp)\r
-  }\r
-  while (size > 1);\r
-  */\r
-  while (size > 3)\r
-  {\r
-    UInt64 temp = p[size];\r
-    size_t k = (p[3] > p[2]) ? 3 : 2;\r
-    p[size--] = p[1];\r
-    p[1] = p[k];\r
-    HeapSortDown(p, k, size, temp)\r
-  }\r
-  {\r
-    UInt64 temp = p[size];\r
-    p[size] = p[1];\r
-    if (size > 2 && p[2] < temp)\r
-    {\r
-      p[1] = p[2];\r
-      p[2] = temp;\r
-    }\r
-    else\r
-      p[1] = temp;\r
-  }\r
-}\r
-\r
-/*\r
-#define HeapSortRefDown(p, vals, n, size, temp) \\r
-  { size_t k = n; UInt32 val = vals[temp]; for (;;) { \\r
-    size_t s = (k << 1); \\r
-    if (s > size) break; \\r
-    if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \\r
-    if (val >= vals[p[s]]) break; \\r
-    p[k] = p[s]; k = s; \\r
-  } p[k] = temp; }\r
-\r
-void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size)\r
-{\r
-  if (size <= 1)\r
-    return;\r
-  p--;\r
-  {\r
-    size_t i = size / 2;\r
-    do\r
-    {\r
-      UInt32 temp = p[i];\r
-      HeapSortRefDown(p, vals, i, size, temp);\r
-    }\r
-    while (--i != 0);\r
-  }\r
-  do\r
-  {\r
-    UInt32 temp = p[size];\r
-    p[size--] = p[1];\r
-    HeapSortRefDown(p, vals, 1, size, temp);\r
-  }\r
-  while (size > 1);\r
-}\r
-*/\r
+/* Sort.c -- Sort functions
+2014-04-05 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include "Sort.h"
+
+#define HeapSortDown(p, k, size, temp) \
+  { for (;;) { \
+    size_t s = (k << 1); \
+    if (s > size) break; \
+    if (s < size && p[s + 1] > p[s]) s++; \
+    if (temp >= p[s]) break; \
+    p[k] = p[s]; k = s; \
+  } p[k] = temp; }
+
+void HeapSort(UInt32 *p, size_t size)
+{
+  if (size <= 1)
+    return;
+  p--;
+  {
+    size_t i = size / 2;
+    do
+    {
+      UInt32 temp = p[i];
+      size_t k = i;
+      HeapSortDown(p, k, size, temp)
+    }
+    while (--i != 0);
+  }
+  /*
+  do
+  {
+    size_t k = 1;
+    UInt32 temp = p[size];
+    p[size--] = p[1];
+    HeapSortDown(p, k, size, temp)
+  }
+  while (size > 1);
+  */
+  while (size > 3)
+  {
+    UInt32 temp = p[size];
+    size_t k = (p[3] > p[2]) ? 3 : 2;
+    p[size--] = p[1];
+    p[1] = p[k];
+    HeapSortDown(p, k, size, temp)
+  }
+  {
+    UInt32 temp = p[size];
+    p[size] = p[1];
+    if (size > 2 && p[2] < temp)
+    {
+      p[1] = p[2];
+      p[2] = temp;
+    }
+    else
+      p[1] = temp;
+  }
+}
+
+void HeapSort64(UInt64 *p, size_t size)
+{
+  if (size <= 1)
+    return;
+  p--;
+  {
+    size_t i = size / 2;
+    do
+    {
+      UInt64 temp = p[i];
+      size_t k = i;
+      HeapSortDown(p, k, size, temp)
+    }
+    while (--i != 0);
+  }
+  /*
+  do
+  {
+    size_t k = 1;
+    UInt64 temp = p[size];
+    p[size--] = p[1];
+    HeapSortDown(p, k, size, temp)
+  }
+  while (size > 1);
+  */
+  while (size > 3)
+  {
+    UInt64 temp = p[size];
+    size_t k = (p[3] > p[2]) ? 3 : 2;
+    p[size--] = p[1];
+    p[1] = p[k];
+    HeapSortDown(p, k, size, temp)
+  }
+  {
+    UInt64 temp = p[size];
+    p[size] = p[1];
+    if (size > 2 && p[2] < temp)
+    {
+      p[1] = p[2];
+      p[2] = temp;
+    }
+    else
+      p[1] = temp;
+  }
+}
+
+/*
+#define HeapSortRefDown(p, vals, n, size, temp) \
+  { size_t k = n; UInt32 val = vals[temp]; for (;;) { \
+    size_t s = (k << 1); \
+    if (s > size) break; \
+    if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \
+    if (val >= vals[p[s]]) break; \
+    p[k] = p[s]; k = s; \
+  } p[k] = temp; }
+
+void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size)
+{
+  if (size <= 1)
+    return;
+  p--;
+  {
+    size_t i = size / 2;
+    do
+    {
+      UInt32 temp = p[i];
+      HeapSortRefDown(p, vals, i, size, temp);
+    }
+    while (--i != 0);
+  }
+  do
+  {
+    UInt32 temp = p[size];
+    p[size--] = p[1];
+    HeapSortRefDown(p, vals, 1, size, temp);
+  }
+  while (size > 1);
+}
+*/
diff --git a/deps/libchdr/deps/zlib-1.2.11/CMakeLists.txt b/deps/libchdr/deps/zlib-1.2.11/CMakeLists.txt
new file mode 100644 (file)
index 0000000..37b04b9
--- /dev/null
@@ -0,0 +1,27 @@
+add_library(zlib STATIC
+  zconf.h
+  zlib.h
+  adler32.c
+  compress.c
+  crc32.c
+  crc32.h
+  deflate.c
+  deflate.h
+  gzguts.h
+  infback.c
+  inffast.c
+  inffast.h
+  inffixed.h
+  inflate.c
+  inflate.h
+  inftrees.c
+  inftrees.h
+  trees.c
+  trees.h
+  uncompr.c
+  zutil.c
+  zutil.h
+)
+
+target_include_directories(zlib PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
+target_include_directories(zlib INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
diff --git a/deps/libchdr/deps/zlib-1.2.11/ChangeLog b/deps/libchdr/deps/zlib-1.2.11/ChangeLog
new file mode 100644 (file)
index 0000000..30199a6
--- /dev/null
@@ -0,0 +1,1515 @@
+
+                ChangeLog file for zlib
+
+Changes in 1.2.11 (15 Jan 2017)
+- Fix deflate stored bug when pulling last block from window
+- Permit immediate deflateParams changes before any deflate input
+
+Changes in 1.2.10 (2 Jan 2017)
+- Avoid warnings on snprintf() return value
+- Fix bug in deflate_stored() for zero-length input
+- Fix bug in gzwrite.c that produced corrupt gzip files
+- Remove files to be installed before copying them in Makefile.in
+- Add warnings when compiling with assembler code
+
+Changes in 1.2.9 (31 Dec 2016)
+- Fix contrib/minizip to permit unzipping with desktop API [Zouzou]
+- Improve contrib/blast to return unused bytes
+- Assure that gzoffset() is correct when appending
+- Improve compress() and uncompress() to support large lengths
+- Fix bug in test/example.c where error code not saved
+- Remedy Coverity warning [Randers-Pehrson]
+- Improve speed of gzprintf() in transparent mode
+- Fix inflateInit2() bug when windowBits is 16 or 32
+- Change DEBUG macro to ZLIB_DEBUG
+- Avoid uninitialized access by gzclose_w()
+- Allow building zlib outside of the source directory
+- Fix bug that accepted invalid zlib header when windowBits is zero
+- Fix gzseek() problem on MinGW due to buggy _lseeki64 there
+- Loop on write() calls in gzwrite.c in case of non-blocking I/O
+- Add --warn (-w) option to ./configure for more compiler warnings
+- Reject a window size of 256 bytes if not using the zlib wrapper
+- Fix bug when level 0 used with Z_HUFFMAN or Z_RLE
+- Add --debug (-d) option to ./configure to define ZLIB_DEBUG
+- Fix bugs in creating a very large gzip header
+- Add uncompress2() function, which returns the input size used
+- Assure that deflateParams() will not switch functions mid-block
+- Dramatically speed up deflation for level 0 (storing)
+- Add gzfread(), duplicating the interface of fread()
+- Add gzfwrite(), duplicating the interface of fwrite()
+- Add deflateGetDictionary() function
+- Use snprintf() for later versions of Microsoft C
+- Fix *Init macros to use z_ prefix when requested
+- Replace as400 with os400 for OS/400 support [Monnerat]
+- Add crc32_z() and adler32_z() functions with size_t lengths
+- Update Visual Studio project files [AraHaan]
+
+Changes in 1.2.8 (28 Apr 2013)
+- Update contrib/minizip/iowin32.c for Windows RT [Vollant]
+- Do not force Z_CONST for C++
+- Clean up contrib/vstudio [Roß]
+- Correct spelling error in zlib.h
+- Fix mixed line endings in contrib/vstudio
+
+Changes in 1.2.7.3 (13 Apr 2013)
+- Fix version numbers and DLL names in contrib/vstudio/*/zlib.rc
+
+Changes in 1.2.7.2 (13 Apr 2013)
+- Change check for a four-byte type back to hexadecimal
+- Fix typo in win32/Makefile.msc
+- Add casts in gzwrite.c for pointer differences
+
+Changes in 1.2.7.1 (24 Mar 2013)
+- Replace use of unsafe string functions with snprintf if available
+- Avoid including stddef.h on Windows for Z_SOLO compile [Niessink]
+- Fix gzgetc undefine when Z_PREFIX set [Turk]
+- Eliminate use of mktemp in Makefile (not always available)
+- Fix bug in 'F' mode for gzopen()
+- Add inflateGetDictionary() function
+- Correct comment in deflate.h
+- Use _snprintf for snprintf in Microsoft C
+- On Darwin, only use /usr/bin/libtool if libtool is not Apple
+- Delete "--version" file if created by "ar --version" [Richard G.]
+- Fix configure check for veracity of compiler error return codes
+- Fix CMake compilation of static lib for MSVC2010 x64
+- Remove unused variable in infback9.c
+- Fix argument checks in gzlog_compress() and gzlog_write()
+- Clean up the usage of z_const and respect const usage within zlib
+- Clean up examples/gzlog.[ch] comparisons of different types
+- Avoid shift equal to bits in type (caused endless loop)
+- Fix uninitialized value bug in gzputc() introduced by const patches
+- Fix memory allocation error in examples/zran.c [Nor]
+- Fix bug where gzopen(), gzclose() would write an empty file
+- Fix bug in gzclose() when gzwrite() runs out of memory
+- Check for input buffer malloc failure in examples/gzappend.c
+- Add note to contrib/blast to use binary mode in stdio
+- Fix comparisons of differently signed integers in contrib/blast
+- Check for invalid code length codes in contrib/puff
+- Fix serious but very rare decompression bug in inftrees.c
+- Update inflateBack() comments, since inflate() can be faster
+- Use underscored I/O function names for WINAPI_FAMILY
+- Add _tr_flush_bits to the external symbols prefixed by --zprefix
+- Add contrib/vstudio/vc10 pre-build step for static only
+- Quote --version-script argument in CMakeLists.txt
+- Don't specify --version-script on Apple platforms in CMakeLists.txt
+- Fix casting error in contrib/testzlib/testzlib.c
+- Fix types in contrib/minizip to match result of get_crc_table()
+- Simplify contrib/vstudio/vc10 with 'd' suffix
+- Add TOP support to win32/Makefile.msc
+- Suport i686 and amd64 assembler builds in CMakeLists.txt
+- Fix typos in the use of _LARGEFILE64_SOURCE in zconf.h
+- Add vc11 and vc12 build files to contrib/vstudio
+- Add gzvprintf() as an undocumented function in zlib
+- Fix configure for Sun shell
+- Remove runtime check in configure for four-byte integer type
+- Add casts and consts to ease user conversion to C++
+- Add man pages for minizip and miniunzip
+- In Makefile uninstall, don't rm if preceding cd fails
+- Do not return Z_BUF_ERROR if deflateParam() has nothing to write
+
+Changes in 1.2.7 (2 May 2012)
+- Replace use of memmove() with a simple copy for portability
+- Test for existence of strerror
+- Restore gzgetc_ for backward compatibility with 1.2.6
+- Fix build with non-GNU make on Solaris
+- Require gcc 4.0 or later on Mac OS X to use the hidden attribute
+- Include unistd.h for Watcom C
+- Use __WATCOMC__ instead of __WATCOM__
+- Do not use the visibility attribute if NO_VIZ defined
+- Improve the detection of no hidden visibility attribute
+- Avoid using __int64 for gcc or solo compilation
+- Cast to char * in gzprintf to avoid warnings [Zinser]
+- Fix make_vms.com for VAX [Zinser]
+- Don't use library or built-in byte swaps
+- Simplify test and use of gcc hidden attribute
+- Fix bug in gzclose_w() when gzwrite() fails to allocate memory
+- Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen()
+- Fix bug in test/minigzip.c for configure --solo
+- Fix contrib/vstudio project link errors [Mohanathas]
+- Add ability to choose the builder in make_vms.com [Schweda]
+- Add DESTDIR support to mingw32 win32/Makefile.gcc
+- Fix comments in win32/Makefile.gcc for proper usage
+- Allow overriding the default install locations for cmake
+- Generate and install the pkg-config file with cmake
+- Build both a static and a shared version of zlib with cmake
+- Include version symbols for cmake builds
+- If using cmake with MSVC, add the source directory to the includes
+- Remove unneeded EXTRA_CFLAGS from win32/Makefile.gcc [Truta]
+- Move obsolete emx makefile to old [Truta]
+- Allow the use of -Wundef when compiling or using zlib
+- Avoid the use of the -u option with mktemp
+- Improve inflate() documentation on the use of Z_FINISH
+- Recognize clang as gcc
+- Add gzopen_w() in Windows for wide character path names
+- Rename zconf.h in CMakeLists.txt to move it out of the way
+- Add source directory in CMakeLists.txt for building examples
+- Look in build directory for zlib.pc in CMakeLists.txt
+- Remove gzflags from zlibvc.def in vc9 and vc10
+- Fix contrib/minizip compilation in the MinGW environment
+- Update ./configure for Solaris, support --64 [Mooney]
+- Remove -R. from Solaris shared build (possible security issue)
+- Avoid race condition for parallel make (-j) running example
+- Fix type mismatch between get_crc_table() and crc_table
+- Fix parsing of version with "-" in CMakeLists.txt [Snider, Ziegler]
+- Fix the path to zlib.map in CMakeLists.txt
+- Force the native libtool in Mac OS X to avoid GNU libtool [Beebe]
+- Add instructions to win32/Makefile.gcc for shared install [Torri]
+
+Changes in 1.2.6.1 (12 Feb 2012)
+- Avoid the use of the Objective-C reserved name "id"
+- Include io.h in gzguts.h for Microsoft compilers
+- Fix problem with ./configure --prefix and gzgetc macro
+- Include gz_header definition when compiling zlib solo
+- Put gzflags() functionality back in zutil.c
+- Avoid library header include in crc32.c for Z_SOLO
+- Use name in GCC_CLASSIC as C compiler for coverage testing, if set
+- Minor cleanup in contrib/minizip/zip.c [Vollant]
+- Update make_vms.com [Zinser]
+- Remove unnecessary gzgetc_ function
+- Use optimized byte swap operations for Microsoft and GNU [Snyder]
+- Fix minor typo in zlib.h comments [Rzesniowiecki]
+
+Changes in 1.2.6 (29 Jan 2012)
+- Update the Pascal interface in contrib/pascal
+- Fix function numbers for gzgetc_ in zlibvc.def files
+- Fix configure.ac for contrib/minizip [Schiffer]
+- Fix large-entry detection in minizip on 64-bit systems [Schiffer]
+- Have ./configure use the compiler return code for error indication
+- Fix CMakeLists.txt for cross compilation [McClure]
+- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes]
+- Fix compilation of contrib/minizip on FreeBSD [Marquez]
+- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath]
+- Include io.h for Turbo C / Borland C on all platforms [Truta]
+- Make version explicit in contrib/minizip/configure.ac [Bosmans]
+- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant]
+- Minor cleanup up contrib/minizip/unzip.c [Vollant]
+- Fix bug when compiling minizip with C++ [Vollant]
+- Protect for long name and extra fields in contrib/minizip [Vollant]
+- Avoid some warnings in contrib/minizip [Vollant]
+- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip
+- Add missing libs to minizip linker command
+- Add support for VPATH builds in contrib/minizip
+- Add an --enable-demos option to contrib/minizip/configure
+- Add the generation of configure.log by ./configure
+- Exit when required parameters not provided to win32/Makefile.gcc
+- Have gzputc return the character written instead of the argument
+- Use the -m option on ldconfig for BSD systems [Tobias]
+- Correct in zlib.map when deflateResetKeep was added
+
+Changes in 1.2.5.3 (15 Jan 2012)
+- Restore gzgetc function for binary compatibility
+- Do not use _lseeki64 under Borland C++ [Truta]
+- Update win32/Makefile.msc to build test/*.c [Truta]
+- Remove old/visualc6 given CMakefile and other alternatives
+- Update AS400 build files and documentation [Monnerat]
+- Update win32/Makefile.gcc to build test/*.c [Truta]
+- Permit stronger flushes after Z_BLOCK flushes
+- Avoid extraneous empty blocks when doing empty flushes
+- Permit Z_NULL arguments to deflatePending
+- Allow deflatePrime() to insert bits in the middle of a stream
+- Remove second empty static block for Z_PARTIAL_FLUSH
+- Write out all of the available bits when using Z_BLOCK
+- Insert the first two strings in the hash table after a flush
+
+Changes in 1.2.5.2 (17 Dec 2011)
+- fix ld error: unable to find version dependency 'ZLIB_1.2.5'
+- use relative symlinks for shared libs
+- Avoid searching past window for Z_RLE strategy
+- Assure that high-water mark initialization is always applied in deflate
+- Add assertions to fill_window() in deflate.c to match comments
+- Update python link in README
+- Correct spelling error in gzread.c
+- Fix bug in gzgets() for a concatenated empty gzip stream
+- Correct error in comment for gz_make()
+- Change gzread() and related to ignore junk after gzip streams
+- Allow gzread() and related to continue after gzclearerr()
+- Allow gzrewind() and gzseek() after a premature end-of-file
+- Simplify gzseek() now that raw after gzip is ignored
+- Change gzgetc() to a macro for speed (~40% speedup in testing)
+- Fix gzclose() to return the actual error last encountered
+- Always add large file support for windows
+- Include zconf.h for windows large file support
+- Include zconf.h.cmakein for windows large file support
+- Update zconf.h.cmakein on make distclean
+- Merge vestigial vsnprintf determination from zutil.h to gzguts.h
+- Clarify how gzopen() appends in zlib.h comments
+- Correct documentation of gzdirect() since junk at end now ignored
+- Add a transparent write mode to gzopen() when 'T' is in the mode
+- Update python link in zlib man page
+- Get inffixed.h and MAKEFIXED result to match
+- Add a ./config --solo option to make zlib subset with no library use
+- Add undocumented inflateResetKeep() function for CAB file decoding
+- Add --cover option to ./configure for gcc coverage testing
+- Add #define ZLIB_CONST option to use const in the z_stream interface
+- Add comment to gzdopen() in zlib.h to use dup() when using fileno()
+- Note behavior of uncompress() to provide as much data as it can
+- Add files in contrib/minizip to aid in building libminizip
+- Split off AR options in Makefile.in and configure
+- Change ON macro to Z_ARG to avoid application conflicts
+- Facilitate compilation with Borland C++ for pragmas and vsnprintf
+- Include io.h for Turbo C / Borland C++
+- Move example.c and minigzip.c to test/
+- Simplify incomplete code table filling in inflate_table()
+- Remove code from inflate.c and infback.c that is impossible to execute
+- Test the inflate code with full coverage
+- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw)
+- Add deflateResetKeep and fix inflateResetKeep to retain dictionary
+- Fix gzwrite.c to accommodate reduced memory zlib compilation
+- Have inflate() with Z_FINISH avoid the allocation of a window
+- Do not set strm->adler when doing raw inflate
+- Fix gzeof() to behave just like feof() when read is not past end of file
+- Fix bug in gzread.c when end-of-file is reached
+- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF
+- Document gzread() capability to read concurrently written files
+- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo]
+
+Changes in 1.2.5.1 (10 Sep 2011)
+- Update FAQ entry on shared builds (#13)
+- Avoid symbolic argument to chmod in Makefile.in
+- Fix bug and add consts in contrib/puff [Oberhumer]
+- Update contrib/puff/zeros.raw test file to have all block types
+- Add full coverage test for puff in contrib/puff/Makefile
+- Fix static-only-build install in Makefile.in
+- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno]
+- Add libz.a dependency to shared in Makefile.in for parallel builds
+- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out
+- Replace $(...) with `...` in configure for non-bash sh [Bowler]
+- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen]
+- Add solaris* to Linux* in configure to allow gcc use [Groffen]
+- Add *bsd* to Linux* case in configure [Bar-Lev]
+- Add inffast.obj to dependencies in win32/Makefile.msc
+- Correct spelling error in deflate.h [Kohler]
+- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc
+- Add test to configure for GNU C looking for gcc in output of $cc -v
+- Add zlib.pc generation to win32/Makefile.gcc [Weigelt]
+- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not
+- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense
+- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser)
+- Make stronger test in zconf.h to include unistd.h for LFS
+- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack]
+- Fix zlib.h LFS support when Z_PREFIX used
+- Add updated as400 support (removed from old) [Monnerat]
+- Avoid deflate sensitivity to volatile input data
+- Avoid division in adler32_combine for NO_DIVIDE
+- Clarify the use of Z_FINISH with deflateBound() amount of space
+- Set binary for output file in puff.c
+- Use u4 type for crc_table to avoid conversion warnings
+- Apply casts in zlib.h to avoid conversion warnings
+- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller]
+- Improve inflateSync() documentation to note indeterminancy
+- Add deflatePending() function to return the amount of pending output
+- Correct the spelling of "specification" in FAQ [Randers-Pehrson]
+- Add a check in configure for stdarg.h, use for gzprintf()
+- Check that pointers fit in ints when gzprint() compiled old style
+- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler]
+- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt]
+- Add debug records in assmebler code [Londer]
+- Update RFC references to use http://tools.ietf.org/html/... [Li]
+- Add --archs option, use of libtool to configure for Mac OS X [Borstel]
+
+Changes in 1.2.5 (19 Apr 2010)
+- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev]
+- Default to libdir as sharedlibdir in configure [Nieder]
+- Update copyright dates on modified source files
+- Update trees.c to be able to generate modified trees.h
+- Exit configure for MinGW, suggesting win32/Makefile.gcc
+- Check for NULL path in gz_open [Homurlu]
+
+Changes in 1.2.4.5 (18 Apr 2010)
+- Set sharedlibdir in configure [Torok]
+- Set LDFLAGS in Makefile.in [Bar-Lev]
+- Avoid mkdir objs race condition in Makefile.in [Bowler]
+- Add ZLIB_INTERNAL in front of internal inter-module functions and arrays
+- Define ZLIB_INTERNAL to hide internal functions and arrays for GNU C
+- Don't use hidden attribute when it is a warning generator (e.g. Solaris)
+
+Changes in 1.2.4.4 (18 Apr 2010)
+- Fix CROSS_PREFIX executable testing, CHOST extract, mingw* [Torok]
+- Undefine _LARGEFILE64_SOURCE in zconf.h if it is zero, but not if empty
+- Try to use bash or ksh regardless of functionality of /bin/sh
+- Fix configure incompatibility with NetBSD sh
+- Remove attempt to run under bash or ksh since have better NetBSD fix
+- Fix win32/Makefile.gcc for MinGW [Bar-Lev]
+- Add diagnostic messages when using CROSS_PREFIX in configure
+- Added --sharedlibdir option to configure [Weigelt]
+- Use hidden visibility attribute when available [Frysinger]
+
+Changes in 1.2.4.3 (10 Apr 2010)
+- Only use CROSS_PREFIX in configure for ar and ranlib if they exist
+- Use CROSS_PREFIX for nm [Bar-Lev]
+- Assume _LARGEFILE64_SOURCE defined is equivalent to true
+- Avoid use of undefined symbols in #if with && and ||
+- Make *64 prototypes in gzguts.h consistent with functions
+- Add -shared load option for MinGW in configure [Bowler]
+- Move z_off64_t to public interface, use instead of off64_t
+- Remove ! from shell test in configure (not portable to Solaris)
+- Change +0 macro tests to -0 for possibly increased portability
+
+Changes in 1.2.4.2 (9 Apr 2010)
+- Add consistent carriage returns to readme.txt's in masmx86 and masmx64
+- Really provide prototypes for *64 functions when building without LFS
+- Only define unlink() in minigzip.c if unistd.h not included
+- Update README to point to contrib/vstudio project files
+- Move projects/vc6 to old/ and remove projects/
+- Include stdlib.h in minigzip.c for setmode() definition under WinCE
+- Clean up assembler builds in win32/Makefile.msc [Rowe]
+- Include sys/types.h for Microsoft for off_t definition
+- Fix memory leak on error in gz_open()
+- Symbolize nm as $NM in configure [Weigelt]
+- Use TEST_LDSHARED instead of LDSHARED to link test programs [Weigelt]
+- Add +0 to _FILE_OFFSET_BITS and _LFS64_LARGEFILE in case not defined
+- Fix bug in gzeof() to take into account unused input data
+- Avoid initialization of structures with variables in puff.c
+- Updated win32/README-WIN32.txt [Rowe]
+
+Changes in 1.2.4.1 (28 Mar 2010)
+- Remove the use of [a-z] constructs for sed in configure [gentoo 310225]
+- Remove $(SHAREDLIB) from LIBS in Makefile.in [Creech]
+- Restore "for debugging" comment on sprintf() in gzlib.c
+- Remove fdopen for MVS from gzguts.h
+- Put new README-WIN32.txt in win32 [Rowe]
+- Add check for shell to configure and invoke another shell if needed
+- Fix big fat stinking bug in gzseek() on uncompressed files
+- Remove vestigial F_OPEN64 define in zutil.h
+- Set and check the value of _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE
+- Avoid errors on non-LFS systems when applications define LFS macros
+- Set EXE to ".exe" in configure for MINGW [Kahle]
+- Match crc32() in crc32.c exactly to the prototype in zlib.h [Sherrill]
+- Add prefix for cross-compilation in win32/makefile.gcc [Bar-Lev]
+- Add DLL install in win32/makefile.gcc [Bar-Lev]
+- Allow Linux* or linux* from uname in configure [Bar-Lev]
+- Allow ldconfig to be redefined in configure and Makefile.in [Bar-Lev]
+- Add cross-compilation prefixes to configure [Bar-Lev]
+- Match type exactly in gz_load() invocation in gzread.c
+- Match type exactly of zcalloc() in zutil.c to zlib.h alloc_func
+- Provide prototypes for *64 functions when building zlib without LFS
+- Don't use -lc when linking shared library on MinGW
+- Remove errno.h check in configure and vestigial errno code in zutil.h
+
+Changes in 1.2.4 (14 Mar 2010)
+- Fix VER3 extraction in configure for no fourth subversion
+- Update zlib.3, add docs to Makefile.in to make .pdf out of it
+- Add zlib.3.pdf to distribution
+- Don't set error code in gzerror() if passed pointer is NULL
+- Apply destination directory fixes to CMakeLists.txt [Lowman]
+- Move #cmakedefine's to a new zconf.in.cmakein
+- Restore zconf.h for builds that don't use configure or cmake
+- Add distclean to dummy Makefile for convenience
+- Update and improve INDEX, README, and FAQ
+- Update CMakeLists.txt for the return of zconf.h [Lowman]
+- Update contrib/vstudio/vc9 and vc10 [Vollant]
+- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc
+- Apply license and readme changes to contrib/asm686 [Raiter]
+- Check file name lengths and add -c option in minigzip.c [Li]
+- Update contrib/amd64 and contrib/masmx86/ [Vollant]
+- Avoid use of "eof" parameter in trees.c to not shadow library variable
+- Update make_vms.com for removal of zlibdefs.h [Zinser]
+- Update assembler code and vstudio projects in contrib [Vollant]
+- Remove outdated assembler code contrib/masm686 and contrib/asm586
+- Remove old vc7 and vc8 from contrib/vstudio
+- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe]
+- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open()
+- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant]
+- Remove *64 functions from win32/zlib.def (they're not 64-bit yet)
+- Fix bug in void-returning vsprintf() case in gzwrite.c
+- Fix name change from inflate.h in contrib/inflate86/inffas86.c
+- Check if temporary file exists before removing in make_vms.com [Zinser]
+- Fix make install and uninstall for --static option
+- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta]
+- Update readme.txt in contrib/masmx64 and masmx86 to assemble
+
+Changes in 1.2.3.9 (21 Feb 2010)
+- Expunge gzio.c
+- Move as400 build information to old
+- Fix updates in contrib/minizip and contrib/vstudio
+- Add const to vsnprintf test in configure to avoid warnings [Weigelt]
+- Delete zconf.h (made by configure) [Weigelt]
+- Change zconf.in.h to zconf.h.in per convention [Weigelt]
+- Check for NULL buf in gzgets()
+- Return empty string for gzgets() with len == 1 (like fgets())
+- Fix description of gzgets() in zlib.h for end-of-file, NULL return
+- Update minizip to 1.1 [Vollant]
+- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c
+- Note in zlib.h that gzerror() should be used to distinguish from EOF
+- Remove use of snprintf() from gzlib.c
+- Fix bug in gzseek()
+- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant]
+- Fix zconf.h generation in CMakeLists.txt [Lowman]
+- Improve comments in zconf.h where modified by configure
+
+Changes in 1.2.3.8 (13 Feb 2010)
+- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer]
+- Use z_off64_t in gz_zero() and gz_skip() to match state->skip
+- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t)
+- Revert to Makefile.in from 1.2.3.6 (live with the clutter)
+- Fix missing error return in gzflush(), add zlib.h note
+- Add *64 functions to zlib.map [Levin]
+- Fix signed/unsigned comparison in gz_comp()
+- Use SFLAGS when testing shared linking in configure
+- Add --64 option to ./configure to use -m64 with gcc
+- Fix ./configure --help to correctly name options
+- Have make fail if a test fails [Levin]
+- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson]
+- Remove assembler object files from contrib
+
+Changes in 1.2.3.7 (24 Jan 2010)
+- Always gzopen() with O_LARGEFILE if available
+- Fix gzdirect() to work immediately after gzopen() or gzdopen()
+- Make gzdirect() more precise when the state changes while reading
+- Improve zlib.h documentation in many places
+- Catch memory allocation failure in gz_open()
+- Complete close operation if seek forward in gzclose_w() fails
+- Return Z_ERRNO from gzclose_r() if close() fails
+- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL
+- Return zero for gzwrite() errors to match zlib.h description
+- Return -1 on gzputs() error to match zlib.h description
+- Add zconf.in.h to allow recovery from configure modification [Weigelt]
+- Fix static library permissions in Makefile.in [Weigelt]
+- Avoid warnings in configure tests that hide functionality [Weigelt]
+- Add *BSD and DragonFly to Linux case in configure [gentoo 123571]
+- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212]
+- Avoid access of uninitialized data for first inflateReset2 call [Gomes]
+- Keep object files in subdirectories to reduce the clutter somewhat
+- Remove default Makefile and zlibdefs.h, add dummy Makefile
+- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_
+- Remove zlibdefs.h completely -- modify zconf.h instead
+
+Changes in 1.2.3.6 (17 Jan 2010)
+- Avoid void * arithmetic in gzread.c and gzwrite.c
+- Make compilers happier with const char * for gz_error message
+- Avoid unused parameter warning in inflate.c
+- Avoid signed-unsigned comparison warning in inflate.c
+- Indent #pragma's for traditional C
+- Fix usage of strwinerror() in glib.c, change to gz_strwinerror()
+- Correct email address in configure for system options
+- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser]
+- Update zlib.map [Brown]
+- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Torok]
+- Apply various fixes to CMakeLists.txt [Lowman]
+- Add checks on len in gzread() and gzwrite()
+- Add error message for no more room for gzungetc()
+- Remove zlib version check in gzwrite()
+- Defer compression of gzprintf() result until need to
+- Use snprintf() in gzdopen() if available
+- Remove USE_MMAP configuration determination (only used by minigzip)
+- Remove examples/pigz.c (available separately)
+- Update examples/gun.c to 1.6
+
+Changes in 1.2.3.5 (8 Jan 2010)
+- Add space after #if in zutil.h for some compilers
+- Fix relatively harmless bug in deflate_fast() [Exarevsky]
+- Fix same problem in deflate_slow()
+- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown]
+- Add deflate_rle() for faster Z_RLE strategy run-length encoding
+- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding
+- Change name of "write" variable in inffast.c to avoid library collisions
+- Fix premature EOF from gzread() in gzio.c [Brown]
+- Use zlib header window size if windowBits is 0 in inflateInit2()
+- Remove compressBound() call in deflate.c to avoid linking compress.o
+- Replace use of errno in gz* with functions, support WinCE [Alves]
+- Provide alternative to perror() in minigzip.c for WinCE [Alves]
+- Don't use _vsnprintf on later versions of MSVC [Lowman]
+- Add CMake build script and input file [Lowman]
+- Update contrib/minizip to 1.1 [Svensson, Vollant]
+- Moved nintendods directory from contrib to .
+- Replace gzio.c with a new set of routines with the same functionality
+- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above
+- Update contrib/minizip to 1.1b
+- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h
+
+Changes in 1.2.3.4 (21 Dec 2009)
+- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility
+- Update comments in configure and Makefile.in for default --shared
+- Fix test -z's in configure [Marquess]
+- Build examplesh and minigzipsh when not testing
+- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h
+- Import LDFLAGS from the environment in configure
+- Fix configure to populate SFLAGS with discovered CFLAGS options
+- Adapt make_vms.com to the new Makefile.in [Zinser]
+- Add zlib2ansi script for C++ compilation [Marquess]
+- Add _FILE_OFFSET_BITS=64 test to make test (when applicable)
+- Add AMD64 assembler code for longest match to contrib [Teterin]
+- Include options from $SFLAGS when doing $LDSHARED
+- Simplify 64-bit file support by introducing z_off64_t type
+- Make shared object files in objs directory to work around old Sun cc
+- Use only three-part version number for Darwin shared compiles
+- Add rc option to ar in Makefile.in for when ./configure not run
+- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4*
+- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile
+- Protect against _FILE_OFFSET_BITS being defined when compiling zlib
+- Rename Makefile.in targets allstatic to static and allshared to shared
+- Fix static and shared Makefile.in targets to be independent
+- Correct error return bug in gz_open() by setting state [Brown]
+- Put spaces before ;;'s in configure for better sh compatibility
+- Add pigz.c (parallel implementation of gzip) to examples/
+- Correct constant in crc32.c to UL [Leventhal]
+- Reject negative lengths in crc32_combine()
+- Add inflateReset2() function to work like inflateEnd()/inflateInit2()
+- Include sys/types.h for _LARGEFILE64_SOURCE [Brown]
+- Correct typo in doc/algorithm.txt [Janik]
+- Fix bug in adler32_combine() [Zhu]
+- Catch missing-end-of-block-code error in all inflates and in puff
+    Assures that random input to inflate eventually results in an error
+- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/
+- Update ENOUGH and its usage to reflect discovered bounds
+- Fix gzerror() error report on empty input file [Brown]
+- Add ush casts in trees.c to avoid pedantic runtime errors
+- Fix typo in zlib.h uncompress() description [Reiss]
+- Correct inflate() comments with regard to automatic header detection
+- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays)
+- Put new version of gzlog (2.0) in examples with interruption recovery
+- Add puff compile option to permit invalid distance-too-far streams
+- Add puff TEST command options, ability to read piped input
+- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but
+  _LARGEFILE64_SOURCE not defined
+- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart
+- Fix deflateSetDictionary() to use all 32K for output consistency
+- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h)
+- Clear bytes after deflate lookahead to avoid use of uninitialized data
+- Change a limit in inftrees.c to be more transparent to Coverity Prevent
+- Update win32/zlib.def with exported symbols from zlib.h
+- Correct spelling errors in zlib.h [Willem, Sobrado]
+- Allow Z_BLOCK for deflate() to force a new block
+- Allow negative bits in inflatePrime() to delete existing bit buffer
+- Add Z_TREES flush option to inflate() to return at end of trees
+- Add inflateMark() to return current state information for random access
+- Add Makefile for NintendoDS to contrib [Costa]
+- Add -w in configure compile tests to avoid spurious warnings [Beucler]
+- Fix typos in zlib.h comments for deflateSetDictionary()
+- Fix EOF detection in transparent gzread() [Maier]
+
+Changes in 1.2.3.3 (2 October 2006)
+- Make --shared the default for configure, add a --static option
+- Add compile option to permit invalid distance-too-far streams
+- Add inflateUndermine() function which is required to enable above
+- Remove use of "this" variable name for C++ compatibility [Marquess]
+- Add testing of shared library in make test, if shared library built
+- Use ftello() and fseeko() if available instead of ftell() and fseek()
+- Provide two versions of all functions that use the z_off_t type for
+  binary compatibility -- a normal version and a 64-bit offset version,
+  per the Large File Support Extension when _LARGEFILE64_SOURCE is
+  defined; use the 64-bit versions by default when _FILE_OFFSET_BITS
+  is defined to be 64
+- Add a --uname= option to configure to perhaps help with cross-compiling
+
+Changes in 1.2.3.2 (3 September 2006)
+- Turn off silly Borland warnings [Hay]
+- Use off64_t and define _LARGEFILE64_SOURCE when present
+- Fix missing dependency on inffixed.h in Makefile.in
+- Rig configure --shared to build both shared and static [Teredesai, Truta]
+- Remove zconf.in.h and instead create a new zlibdefs.h file
+- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant]
+- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt]
+
+Changes in 1.2.3.1 (16 August 2006)
+- Add watcom directory with OpenWatcom make files [Daniel]
+- Remove #undef of FAR in zconf.in.h for MVS [Fedtke]
+- Update make_vms.com [Zinser]
+- Use -fPIC for shared build in configure [Teredesai, Nicholson]
+- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen]
+- Use fdopen() (not _fdopen()) for Interix in zutil.h [Bäck]
+- Add some FAQ entries about the contrib directory
+- Update the MVS question in the FAQ
+- Avoid extraneous reads after EOF in gzio.c [Brown]
+- Correct spelling of "successfully" in gzio.c [Randers-Pehrson]
+- Add comments to zlib.h about gzerror() usage [Brown]
+- Set extra flags in gzip header in gzopen() like deflate() does
+- Make configure options more compatible with double-dash conventions
+  [Weigelt]
+- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen]
+- Fix uninstall target in Makefile.in [Truta]
+- Add pkgconfig support [Weigelt]
+- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt]
+- Replace set_data_type() with a more accurate detect_data_type() in
+  trees.c, according to the txtvsbin.txt document [Truta]
+- Swap the order of #include <stdio.h> and #include "zlib.h" in
+  gzio.c, example.c and minigzip.c [Truta]
+- Shut up annoying VS2005 warnings about standard C deprecation [Rowe,
+  Truta] (where?)
+- Fix target "clean" from win32/Makefile.bor [Truta]
+- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe]
+- Update zlib www home address in win32/DLL_FAQ.txt [Truta]
+- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove]
+- Enable browse info in the "Debug" and "ASM Debug" configurations in
+  the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta]
+- Add pkgconfig support [Weigelt]
+- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h,
+  for use in win32/zlib1.rc [Polushin, Rowe, Truta]
+- Add a document that explains the new text detection scheme to
+  doc/txtvsbin.txt [Truta]
+- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta]
+- Move algorithm.txt into doc/ [Truta]
+- Synchronize FAQ with website
+- Fix compressBound(), was low for some pathological cases [Fearnley]
+- Take into account wrapper variations in deflateBound()
+- Set examples/zpipe.c input and output to binary mode for Windows
+- Update examples/zlib_how.html with new zpipe.c (also web site)
+- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems
+  that gcc became pickier in 4.0)
+- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain
+  un-versioned, the patch adds versioning only for symbols introduced in
+  zlib-1.2.0 or later.  It also declares as local those symbols which are
+  not designed to be exported." [Levin]
+- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure
+- Do not initialize global static by default in trees.c, add a response
+  NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess]
+- Don't use strerror() in gzio.c under WinCE [Yakimov]
+- Don't use errno.h in zutil.h under WinCE [Yakimov]
+- Move arguments for AR to its usage to allow replacing ar [Marot]
+- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson]
+- Improve inflateInit() and inflateInit2() documentation
+- Fix structure size comment in inflate.h
+- Change configure help option from --h* to --help [Santos]
+
+Changes in 1.2.3 (18 July 2005)
+- Apply security vulnerability fixes to contrib/infback9 as well
+- Clean up some text files (carriage returns, trailing space)
+- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant]
+
+Changes in 1.2.2.4 (11 July 2005)
+- Add inflatePrime() function for starting inflation at bit boundary
+- Avoid some Visual C warnings in deflate.c
+- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit
+  compile
+- Fix some spelling errors in comments [Betts]
+- Correct inflateInit2() error return documentation in zlib.h
+- Add zran.c example of compressed data random access to examples
+  directory, shows use of inflatePrime()
+- Fix cast for assignments to strm->state in inflate.c and infback.c
+- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer]
+- Move declarations of gf2 functions to right place in crc32.c [Oberhumer]
+- Add cast in trees.c t avoid a warning [Oberhumer]
+- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer]
+- Update make_vms.com [Zinser]
+- Initialize state->write in inflateReset() since copied in inflate_fast()
+- Be more strict on incomplete code sets in inflate_table() and increase
+  ENOUGH and MAXD -- this repairs a possible security vulnerability for
+  invalid inflate input.  Thanks to Tavis Ormandy and Markus Oberhumer for
+  discovering the vulnerability and providing test cases.
+- Add ia64 support to configure for HP-UX [Smith]
+- Add error return to gzread() for format or i/o error [Levin]
+- Use malloc.h for OS/2 [Necasek]
+
+Changes in 1.2.2.3 (27 May 2005)
+- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile
+- Typecast fread() return values in gzio.c [Vollant]
+- Remove trailing space in minigzip.c outmode (VC++ can't deal with it)
+- Fix crc check bug in gzread() after gzungetc() [Heiner]
+- Add the deflateTune() function to adjust internal compression parameters
+- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack)
+- Remove an incorrect assertion in examples/zpipe.c
+- Add C++ wrapper in infback9.h [Donais]
+- Fix bug in inflateCopy() when decoding fixed codes
+- Note in zlib.h how much deflateSetDictionary() actually uses
+- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used)
+- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer]
+- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer]
+- Add gzdirect() function to indicate transparent reads
+- Update contrib/minizip [Vollant]
+- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer]
+- Add casts in crc32.c to avoid warnings [Oberhumer]
+- Add contrib/masmx64 [Vollant]
+- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant]
+
+Changes in 1.2.2.2 (30 December 2004)
+- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
+  avoid implicit memcpy calls (portability for no-library compilation)
+- Increase sprintf() buffer size in gzdopen() to allow for large numbers
+- Add INFLATE_STRICT to check distances against zlib header
+- Improve WinCE errno handling and comments [Chang]
+- Remove comment about no gzip header processing in FAQ
+- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
+- Add updated make_vms.com [Coghlan], update README
+- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
+  fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
+- Add FAQ entry and comments in deflate.c on uninitialized memory access
+- Add Solaris 9 make options in configure [Gilbert]
+- Allow strerror() usage in gzio.c for STDC
+- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
+- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
+- Use z_off_t for adler32_combine() and crc32_combine() lengths
+- Make adler32() much faster for small len
+- Use OS_CODE in deflate() default gzip header
+
+Changes in 1.2.2.1 (31 October 2004)
+- Allow inflateSetDictionary() call for raw inflate
+- Fix inflate header crc check bug for file names and comments
+- Add deflateSetHeader() and gz_header structure for custom gzip headers
+- Add inflateGetheader() to retrieve gzip headers
+- Add crc32_combine() and adler32_combine() functions
+- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list
+- Use zstreamp consistently in zlib.h (inflate_back functions)
+- Remove GUNZIP condition from definition of inflate_mode in inflate.h
+  and in contrib/inflate86/inffast.S [Truta, Anderson]
+- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson]
+- Update projects/README.projects and projects/visualc6 [Truta]
+- Update win32/DLL_FAQ.txt [Truta]
+- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta]
+- Deprecate Z_ASCII; use Z_TEXT instead [Truta]
+- Use a new algorithm for setting strm->data_type in trees.c [Truta]
+- Do not define an exit() prototype in zutil.c unless DEBUG defined
+- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
+- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
+- Fix Darwin build version identification [Peterson]
+
+Changes in 1.2.2 (3 October 2004)
+- Update zlib.h comments on gzip in-memory processing
+- Set adler to 1 in inflateReset() to support Java test suite [Walles]
+- Add contrib/dotzlib [Ravn]
+- Update win32/DLL_FAQ.txt [Truta]
+- Update contrib/minizip [Vollant]
+- Move contrib/visual-basic.txt to old/ [Truta]
+- Fix assembler builds in projects/visualc6/ [Truta]
+
+Changes in 1.2.1.2 (9 September 2004)
+- Update INDEX file
+- Fix trees.c to update strm->data_type (no one ever noticed!)
+- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown]
+- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE)
+- Add limited multitasking protection to DYNAMIC_CRC_TABLE
+- Add NO_vsnprintf for VMS in zutil.h [Mozilla]
+- Don't declare strerror() under VMS [Mozilla]
+- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize
+- Update contrib/ada [Anisimkov]
+- Update contrib/minizip [Vollant]
+- Fix configure to not hardcode directories for Darwin [Peterson]
+- Fix gzio.c to not return error on empty files [Brown]
+- Fix indentation; update version in contrib/delphi/ZLib.pas and
+  contrib/pascal/zlibpas.pas [Truta]
+- Update mkasm.bat in contrib/masmx86 [Truta]
+- Update contrib/untgz [Truta]
+- Add projects/README.projects [Truta]
+- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta]
+- Update win32/DLL_FAQ.txt [Truta]
+- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta]
+- Remove an unnecessary assignment to curr in inftrees.c [Truta]
+- Add OS/2 to exe builds in configure [Poltorak]
+- Remove err dummy parameter in zlib.h [Kientzle]
+
+Changes in 1.2.1.1 (9 January 2004)
+- Update email address in README
+- Several FAQ updates
+- Fix a big fat bug in inftrees.c that prevented decoding valid
+  dynamic blocks with only literals and no distance codes --
+  Thanks to "Hot Emu" for the bug report and sample file
+- Add a note to puff.c on no distance codes case.
+
+Changes in 1.2.1 (17 November 2003)
+- Remove a tab in contrib/gzappend/gzappend.c
+- Update some interfaces in contrib for new zlib functions
+- Update zlib version number in some contrib entries
+- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta]
+- Support shared libraries on Hurd and KFreeBSD [Brown]
+- Fix error in NO_DIVIDE option of adler32.c
+
+Changes in 1.2.0.8 (4 November 2003)
+- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas
+- Add experimental NO_DIVIDE #define in adler32.c
+    - Possibly faster on some processors (let me know if it is)
+- Correct Z_BLOCK to not return on first inflate call if no wrap
+- Fix strm->data_type on inflate() return to correctly indicate EOB
+- Add deflatePrime() function for appending in the middle of a byte
+- Add contrib/gzappend for an example of appending to a stream
+- Update win32/DLL_FAQ.txt [Truta]
+- Delete Turbo C comment in README [Truta]
+- Improve some indentation in zconf.h [Truta]
+- Fix infinite loop on bad input in configure script [Church]
+- Fix gzeof() for concatenated gzip files [Johnson]
+- Add example to contrib/visual-basic.txt [Michael B.]
+- Add -p to mkdir's in Makefile.in [vda]
+- Fix configure to properly detect presence or lack of printf functions
+- Add AS400 support [Monnerat]
+- Add a little Cygwin support [Wilson]
+
+Changes in 1.2.0.7 (21 September 2003)
+- Correct some debug formats in contrib/infback9
+- Cast a type in a debug statement in trees.c
+- Change search and replace delimiter in configure from % to # [Beebe]
+- Update contrib/untgz to 0.2 with various fixes [Truta]
+- Add build support for Amiga [Nikl]
+- Remove some directories in old that have been updated to 1.2
+- Add dylib building for Mac OS X in configure and Makefile.in
+- Remove old distribution stuff from Makefile
+- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X
+- Update links in README
+
+Changes in 1.2.0.6 (13 September 2003)
+- Minor FAQ updates
+- Update contrib/minizip to 1.00 [Vollant]
+- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta]
+- Update POSTINC comment for 68060 [Nikl]
+- Add contrib/infback9 with deflate64 decoding (unsupported)
+- For MVS define NO_vsnprintf and undefine FAR [van Burik]
+- Add pragma for fdopen on MVS [van Burik]
+
+Changes in 1.2.0.5 (8 September 2003)
+- Add OF to inflateBackEnd() declaration in zlib.h
+- Remember start when using gzdopen in the middle of a file
+- Use internal off_t counters in gz* functions to properly handle seeks
+- Perform more rigorous check for distance-too-far in inffast.c
+- Add Z_BLOCK flush option to return from inflate at block boundary
+- Set strm->data_type on return from inflate
+    - Indicate bits unused, if at block boundary, and if in last block
+- Replace size_t with ptrdiff_t in crc32.c, and check for correct size
+- Add condition so old NO_DEFLATE define still works for compatibility
+- FAQ update regarding the Windows DLL [Truta]
+- INDEX update: add qnx entry, remove aix entry [Truta]
+- Install zlib.3 into mandir [Wilson]
+- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta]
+- Adapt the zlib interface to the new DLL convention guidelines [Truta]
+- Introduce ZLIB_WINAPI macro to allow the export of functions using
+  the WINAPI calling convention, for Visual Basic [Vollant, Truta]
+- Update msdos and win32 scripts and makefiles [Truta]
+- Export symbols by name, not by ordinal, in win32/zlib.def [Truta]
+- Add contrib/ada [Anisimkov]
+- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta]
+- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant]
+- Add contrib/masm686 [Truta]
+- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm
+  [Truta, Vollant]
+- Update contrib/delphi; rename to contrib/pascal; add example [Truta]
+- Remove contrib/delphi2; add a new contrib/delphi [Truta]
+- Avoid inclusion of the nonstandard <memory.h> in contrib/iostream,
+  and fix some method prototypes [Truta]
+- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip
+  [Truta]
+- Avoid the use of backslash (\) in contrib/minizip [Vollant]
+- Fix file time handling in contrib/untgz; update makefiles [Truta]
+- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines
+  [Vollant]
+- Remove contrib/vstudio/vc15_16 [Vollant]
+- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta]
+- Update README.contrib [Truta]
+- Invert the assignment order of match_head and s->prev[...] in
+  INSERT_STRING [Truta]
+- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings
+  [Truta]
+- Compare function pointers with 0, not with NULL or Z_NULL [Truta]
+- Fix prototype of syncsearch in inflate.c [Truta]
+- Introduce ASMINF macro to be enabled when using an ASM implementation
+  of inflate_fast [Truta]
+- Change NO_DEFLATE to NO_GZCOMPRESS [Truta]
+- Modify test_gzio in example.c to take a single file name as a
+  parameter [Truta]
+- Exit the example.c program if gzopen fails [Truta]
+- Add type casts around strlen in example.c [Truta]
+- Remove casting to sizeof in minigzip.c; give a proper type
+  to the variable compared with SUFFIX_LEN [Truta]
+- Update definitions of STDC and STDC99 in zconf.h [Truta]
+- Synchronize zconf.h with the new Windows DLL interface [Truta]
+- Use SYS16BIT instead of __32BIT__ to distinguish between
+  16- and 32-bit platforms [Truta]
+- Use far memory allocators in small 16-bit memory models for
+  Turbo C [Truta]
+- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in
+  zlibCompileFlags [Truta]
+- Cygwin has vsnprintf [Wilson]
+- In Windows16, OS_CODE is 0, as in MSDOS [Truta]
+- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson]
+
+Changes in 1.2.0.4 (10 August 2003)
+- Minor FAQ updates
+- Be more strict when checking inflateInit2's windowBits parameter
+- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well
+- Add gzip wrapper option to deflateInit2 using windowBits
+- Add updated QNX rule in configure and qnx directory [Bonnefoy]
+- Make inflate distance-too-far checks more rigorous
+- Clean up FAR usage in inflate
+- Add casting to sizeof() in gzio.c and minigzip.c
+
+Changes in 1.2.0.3 (19 July 2003)
+- Fix silly error in gzungetc() implementation [Vollant]
+- Update contrib/minizip and contrib/vstudio [Vollant]
+- Fix printf format in example.c
+- Correct cdecl support in zconf.in.h [Anisimkov]
+- Minor FAQ updates
+
+Changes in 1.2.0.2 (13 July 2003)
+- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons
+- Attempt to avoid warnings in crc32.c for pointer-int conversion
+- Add AIX to configure, remove aix directory [Bakker]
+- Add some casts to minigzip.c
+- Improve checking after insecure sprintf() or vsprintf() calls
+- Remove #elif's from crc32.c
+- Change leave label to inf_leave in inflate.c and infback.c to avoid
+  library conflicts
+- Remove inflate gzip decoding by default--only enable gzip decoding by
+  special request for stricter backward compatibility
+- Add zlibCompileFlags() function to return compilation information
+- More typecasting in deflate.c to avoid warnings
+- Remove leading underscore from _Capital #defines [Truta]
+- Fix configure to link shared library when testing
+- Add some Windows CE target adjustments [Mai]
+- Remove #define ZLIB_DLL in zconf.h [Vollant]
+- Add zlib.3 [Rodgers]
+- Update RFC URL in deflate.c and algorithm.txt [Mai]
+- Add zlib_dll_FAQ.txt to contrib [Truta]
+- Add UL to some constants [Truta]
+- Update minizip and vstudio [Vollant]
+- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h
+- Expand use of NO_DUMMY_DECL to avoid all dummy structures
+- Added iostream3 to contrib [Schwardt]
+- Replace rewind() with fseek() for WinCE [Truta]
+- Improve setting of zlib format compression level flags
+    - Report 0 for huffman and rle strategies and for level == 0 or 1
+    - Report 2 only for level == 6
+- Only deal with 64K limit when necessary at compile time [Truta]
+- Allow TOO_FAR check to be turned off at compile time [Truta]
+- Add gzclearerr() function [Souza]
+- Add gzungetc() function
+
+Changes in 1.2.0.1 (17 March 2003)
+- Add Z_RLE strategy for run-length encoding [Truta]
+    - When Z_RLE requested, restrict matches to distance one
+    - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE
+- Correct FASTEST compilation to allow level == 0
+- Clean up what gets compiled for FASTEST
+- Incorporate changes to zconf.in.h [Vollant]
+    - Refine detection of Turbo C need for dummy returns
+    - Refine ZLIB_DLL compilation
+    - Include additional header file on VMS for off_t typedef
+- Try to use _vsnprintf where it supplants vsprintf [Vollant]
+- Add some casts in inffast.c
+- Enchance comments in zlib.h on what happens if gzprintf() tries to
+  write more than 4095 bytes before compression
+- Remove unused state from inflateBackEnd()
+- Remove exit(0) from minigzip.c, example.c
+- Get rid of all those darn tabs
+- Add "check" target to Makefile.in that does the same thing as "test"
+- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in
+- Update contrib/inflate86 [Anderson]
+- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant]
+- Add msdos and win32 directories with makefiles [Truta]
+- More additions and improvements to the FAQ
+
+Changes in 1.2.0 (9 March 2003)
+- New and improved inflate code
+    - About 20% faster
+    - Does not allocate 32K window unless and until needed
+    - Automatically detects and decompresses gzip streams
+    - Raw inflate no longer needs an extra dummy byte at end
+    - Added inflateBack functions using a callback interface--even faster
+      than inflate, useful for file utilities (gzip, zip)
+    - Added inflateCopy() function to record state for random access on
+      externally generated deflate streams (e.g. in gzip files)
+    - More readable code (I hope)
+- New and improved crc32()
+    - About 50% faster, thanks to suggestions from Rodney Brown
+- Add deflateBound() and compressBound() functions
+- Fix memory leak in deflateInit2()
+- Permit setting dictionary for raw deflate (for parallel deflate)
+- Fix const declaration for gzwrite()
+- Check for some malloc() failures in gzio.c
+- Fix bug in gzopen() on single-byte file 0x1f
+- Fix bug in gzread() on concatenated file with 0x1f at end of buffer
+  and next buffer doesn't start with 0x8b
+- Fix uncompress() to return Z_DATA_ERROR on truncated input
+- Free memory at end of example.c
+- Remove MAX #define in trees.c (conflicted with some libraries)
+- Fix static const's in deflate.c, gzio.c, and zutil.[ch]
+- Declare malloc() and free() in gzio.c if STDC not defined
+- Use malloc() instead of calloc() in zutil.c if int big enough
+- Define STDC for AIX
+- Add aix/ with approach for compiling shared library on AIX
+- Add HP-UX support for shared libraries in configure
+- Add OpenUNIX support for shared libraries in configure
+- Use $cc instead of gcc to build shared library
+- Make prefix directory if needed when installing
+- Correct Macintosh avoidance of typedef Byte in zconf.h
+- Correct Turbo C memory allocation when under Linux
+- Use libz.a instead of -lz in Makefile (assure use of compiled library)
+- Update configure to check for snprintf or vsnprintf functions and their
+  return value, warn during make if using an insecure function
+- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that
+  is lost when library is used--resolution is to build new zconf.h
+- Documentation improvements (in zlib.h):
+    - Document raw deflate and inflate
+    - Update RFCs URL
+    - Point out that zlib and gzip formats are different
+    - Note that Z_BUF_ERROR is not fatal
+    - Document string limit for gzprintf() and possible buffer overflow
+    - Note requirement on avail_out when flushing
+    - Note permitted values of flush parameter of inflate()
+- Add some FAQs (and even answers) to the FAQ
+- Add contrib/inflate86/ for x86 faster inflate
+- Add contrib/blast/ for PKWare Data Compression Library decompression
+- Add contrib/puff/ simple inflate for deflate format description
+
+Changes in 1.1.4 (11 March 2002)
+- ZFREE was repeated on same allocation on some error conditions.
+  This creates a security problem described in
+  http://www.zlib.org/advisory-2002-03-11.txt
+- Returned incorrect error (Z_MEM_ERROR) on some invalid data
+- Avoid accesses before window for invalid distances with inflate window
+  less than 32K.
+- force windowBits > 8 to avoid a bug in the encoder for a window size
+  of 256 bytes. (A complete fix will be available in 1.1.5).
+
+Changes in 1.1.3 (9 July 1998)
+- fix "an inflate input buffer bug that shows up on rare but persistent
+  occasions" (Mark)
+- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
+- fix gzseek(..., SEEK_SET) in write mode
+- fix crc check after a gzeek (Frank Faubert)
+- fix miniunzip when the last entry in a zip file is itself a zip file
+  (J Lillge)
+- add contrib/asm586 and contrib/asm686 (Brian Raiter)
+  See http://www.muppetlabs.com/~breadbox/software/assembly.html
+- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
+- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
+- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
+- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
+- added a FAQ file
+
+- Support gzdopen on Mac with Metrowerks (Jason Linhart)
+- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart)
+- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young)
+- avoid some warnings with Borland C (Tom Tanner)
+- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant)
+- emulate utime() for WIN32 in contrib/untgz  (Gilles Vollant)
+- allow several arguments to configure (Tim Mooney, Frodo Looijaard)
+- use libdir and includedir in Makefile.in (Tim Mooney)
+- support shared libraries on OSF1 V4 (Tim Mooney)
+- remove so_locations in "make clean"  (Tim Mooney)
+- fix maketree.c compilation error (Glenn, Mark)
+- Python interface to zlib now in Python 1.5 (Jeremy Hylton)
+- new Makefile.riscos (Rich Walker)
+- initialize static descriptors in trees.c for embedded targets (Nick Smith)
+- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith)
+- add the OS/2 files in Makefile.in too (Andrew Zabolotny)
+- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane)
+- fix maketree.c to allow clean compilation of inffixed.h (Mark)
+- fix parameter check in deflateCopy (Gunther Nikl)
+- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler)
+- Many portability patches by Christian Spieler:
+  . zutil.c, zutil.h: added "const" for zmem*
+  . Make_vms.com: fixed some typos
+  . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists
+  . msdos/Makefile.msc: remove "default rtl link library" info from obj files
+  . msdos/Makefile.*: use model-dependent name for the built zlib library
+  . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc:
+     new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT)
+- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane)
+- replace __far with _far for better portability (Christian Spieler, Tom Lane)
+- fix test for errno.h in configure (Tim Newsham)
+
+Changes in 1.1.2 (19 March 98)
+- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant)
+  See http://www.winimage.com/zLibDll/unzip.html
+- preinitialize the inflate tables for fixed codes, to make the code
+  completely thread safe (Mark)
+- some simplifications and slight speed-up to the inflate code (Mark)
+- fix gzeof on non-compressed files (Allan Schrum)
+- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs)
+- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn)
+- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny)
+- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori)
+- do not wrap extern "C" around system includes (Tom Lane)
+- mention zlib binding for TCL in README (Andreas Kupries)
+- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert)
+- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson)
+- allow "configure --prefix $HOME" (Tim Mooney)
+- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson)
+- move Makefile.sas to amiga/Makefile.sas
+
+Changes in 1.1.1 (27 Feb 98)
+- fix macros _tr_tally_* in deflate.h for debug mode  (Glenn Randers-Pehrson)
+- remove block truncation heuristic which had very marginal effect for zlib
+  (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
+  compression ratio on some files. This also allows inlining _tr_tally for
+  matches in deflate_slow.
+- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
+
+Changes in 1.1.0 (24 Feb 98)
+- do not return STREAM_END prematurely in inflate (John Bowler)
+- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
+- compile with -DFASTEST to get compression code optimized for speed only
+- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
+- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
+  on Sun but significant on HP)
+
+- add a pointer to experimental unzip library in README (Gilles Vollant)
+- initialize variable gcc in configure (Chris Herborth)
+
+Changes in 1.0.9 (17 Feb 1998)
+- added gzputs and gzgets functions
+- do not clear eof flag in gzseek (Mark Diekhans)
+- fix gzseek for files in transparent mode (Mark Diekhans)
+- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
+- replace EXPORT with ZEXPORT to avoid conflict with other programs
+- added compress2 in zconf.h, zlib.def, zlib.dnt
+- new asm code from Gilles Vollant in contrib/asm386
+- simplify the inflate code (Mark):
+ . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
+ . ZALLOC the length list in inflate_trees_fixed() instead of using stack
+ . ZALLOC the value area for huft_build() instead of using stack
+ . Simplify Z_FINISH check in inflate()
+
+- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
+- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
+- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
+  the declaration of FAR (Gilles VOllant)
+- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
+- read_buf buf parameter of type Bytef* instead of charf*
+- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
+- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
+- fix check for presence of directories in "make install" (Ian Willis)
+
+Changes in 1.0.8 (27 Jan 1998)
+- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
+- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
+- added compress2() to allow setting the compression level
+- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
+- use constant arrays for the static trees in trees.c instead of computing
+  them at run time (thanks to Ken Raeburn for this suggestion). To create
+  trees.h, compile with GEN_TREES_H and run "make test".
+- check return code of example in "make test" and display result
+- pass minigzip command line options to file_compress
+- simplifying code of inflateSync to avoid gcc 2.8 bug
+
+- support CC="gcc -Wall" in configure -s (QingLong)
+- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
+- fix test for shared library support to avoid compiler warnings
+- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
+- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
+- do not use fdopen for Metrowerks on Mac (Brad Pettit))
+- add checks for gzputc and gzputc in example.c
+- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
+- use const for the CRC table (Ken Raeburn)
+- fixed "make uninstall" for shared libraries
+- use Tracev instead of Trace in infblock.c
+- in example.c use correct compressed length for test_sync
+- suppress +vnocompatwarnings in configure for HPUX (not always supported)
+
+Changes in 1.0.7 (20 Jan 1998)
+- fix gzseek which was broken in write mode
+- return error for gzseek to negative absolute position
+- fix configure for Linux (Chun-Chung Chen)
+- increase stack space for MSC (Tim Wegner)
+- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
+- define EXPORTVA for gzprintf (Gilles Vollant)
+- added man page zlib.3 (Rick Rodgers)
+- for contrib/untgz, fix makedir() and improve Makefile
+
+- check gzseek in write mode in example.c
+- allocate extra buffer for seeks only if gzseek is actually called
+- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
+- add inflateSyncPoint in zconf.h
+- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
+
+Changes in 1.0.6 (19 Jan 1998)
+- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
+  gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
+- Fix a deflate bug occurring only with compression level 0 (thanks to
+  Andy Buckler for finding this one).
+- In minigzip, pass transparently also the first byte for .Z files.
+- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
+- check Z_FINISH in inflate (thanks to Marc Schluper)
+- Implement deflateCopy (thanks to Adam Costello)
+- make static libraries by default in configure, add --shared option.
+- move MSDOS or Windows specific files to directory msdos
+- suppress the notion of partial flush to simplify the interface
+  (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
+- suppress history buffer provided by application to simplify the interface
+  (this feature was not implemented anyway in 1.0.4)
+- next_in and avail_in must be initialized before calling inflateInit or
+  inflateInit2
+- add EXPORT in all exported functions (for Windows DLL)
+- added Makefile.nt (thanks to Stephen Williams)
+- added the unsupported "contrib" directory:
+   contrib/asm386/ by Gilles Vollant <info@winimage.com>
+        386 asm code replacing longest_match().
+   contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
+        A C++ I/O streams interface to the zlib gz* functions
+   contrib/iostream2/  by Tyge Løvset <Tyge.Lovset@cmr.no>
+        Another C++ I/O streams interface
+   contrib/untgz/  by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
+        A very simple tar.gz file extractor using zlib
+   contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
+        How to use compress(), uncompress() and the gz* functions from VB.
+- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
+  level) in minigzip (thanks to Tom Lane)
+
+- use const for rommable constants in deflate
+- added test for gzseek and gztell in example.c
+- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
+- add undocumented function zError to convert error code to string
+  (for Tim Smithers)
+- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
+- Use default memcpy for Symantec MSDOS compiler.
+- Add EXPORT keyword for check_func (needed for Windows DLL)
+- add current directory to LD_LIBRARY_PATH for "make test"
+- create also a link for libz.so.1
+- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
+- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
+- added -soname for Linux in configure (Chun-Chung Chen,
+- assign numbers to the exported functions in zlib.def (for Windows DLL)
+- add advice in zlib.h for best usage of deflateSetDictionary
+- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
+- allow compilation with ANSI keywords only enabled for TurboC in large model
+- avoid "versionString"[0] (Borland bug)
+- add NEED_DUMMY_RETURN for Borland
+- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
+- allow compilation with CC
+- defined STDC for OS/2 (David Charlap)
+- limit external names to 8 chars for MVS (Thomas Lund)
+- in minigzip.c, use static buffers only for 16-bit systems
+- fix suffix check for "minigzip -d foo.gz"
+- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
+- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
+- added makelcc.bat for lcc-win32 (Tom St Denis)
+- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
+- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
+- check for unistd.h in configure (for off_t)
+- remove useless check parameter in inflate_blocks_free
+- avoid useless assignment of s->check to itself in inflate_blocks_new
+- do not flush twice in gzclose (thanks to Ken Raeburn)
+- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
+- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
+- work around buggy fclose on pipes for HP/UX
+- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
+- fix configure if CC is already equal to gcc
+
+Changes in 1.0.5 (3 Jan 98)
+- Fix inflate to terminate gracefully when fed corrupted or invalid data
+- Use const for rommable constants in inflate
+- Eliminate memory leaks on error conditions in inflate
+- Removed some vestigial code in inflate
+- Update web address in README
+
+Changes in 1.0.4 (24 Jul 96)
+- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
+  bit, so the decompressor could decompress all the correct data but went
+  on to attempt decompressing extra garbage data. This affected minigzip too.
+- zlibVersion and gzerror return const char* (needed for DLL)
+- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
+- use z_error only for DEBUG (avoid problem with DLLs)
+
+Changes in 1.0.3 (2 Jul 96)
+- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS
+  small and medium models; this makes the library incompatible with previous
+  versions for these models. (No effect in large model or on other systems.)
+- return OK instead of BUF_ERROR if previous deflate call returned with
+  avail_out as zero but there is nothing to do
+- added memcmp for non STDC compilers
+- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly)
+- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO)
+- better check for 16-bit mode MSC (avoids problem with Symantec)
+
+Changes in 1.0.2 (23 May 96)
+- added Windows DLL support
+- added a function zlibVersion (for the DLL support)
+- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model)
+- Bytef is define's instead of typedef'd only for Borland C
+- avoid reading uninitialized memory in example.c
+- mention in README that the zlib format is now RFC1950
+- updated Makefile.dj2
+- added algorithm.doc
+
+Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
+- fix array overlay in deflate.c which sometimes caused bad compressed data
+- fix inflate bug with empty stored block
+- fix MSDOS medium model which was broken in 0.99
+- fix deflateParams() which could generate bad compressed data.
+- Bytef is define'd instead of typedef'ed (work around Borland bug)
+- added an INDEX file
+- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
+  Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
+- speed up adler32 for modern machines without auto-increment
+- added -ansi for IRIX in configure
+- static_init_done in trees.c is an int
+- define unlink as delete for VMS
+- fix configure for QNX
+- add configure branch for SCO and HPUX
+- avoid many warnings (unused variables, dead assignments, etc...)
+- no fdopen for BeOS
+- fix the Watcom fix for 32 bit mode (define FAR as empty)
+- removed redefinition of Byte for MKWERKS
+- work around an MWKERKS bug (incorrect merge of all .h files)
+
+Changes in 0.99 (27 Jan 96)
+- allow preset dictionary shared between compressor and decompressor
+- allow compression level 0 (no compression)
+- add deflateParams in zlib.h: allow dynamic change of compression level
+  and compression strategy.
+- test large buffers and deflateParams in example.c
+- add optional "configure" to build zlib as a shared library
+- suppress Makefile.qnx, use configure instead
+- fixed deflate for 64-bit systems (detected on Cray)
+- fixed inflate_blocks for 64-bit systems (detected on Alpha)
+- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2)
+- always return Z_BUF_ERROR when deflate() has nothing to do
+- deflateInit and inflateInit are now macros to allow version checking
+- prefix all global functions and types with z_ with -DZ_PREFIX
+- make falloc completely reentrant (inftrees.c)
+- fixed very unlikely race condition in ct_static_init
+- free in reverse order of allocation to help memory manager
+- use zlib-1.0/* instead of zlib/* inside the tar.gz
+- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
+  -Wconversion -Wstrict-prototypes -Wmissing-prototypes"
+- allow gzread on concatenated .gz files
+- deflateEnd now returns Z_DATA_ERROR if it was premature
+- deflate is finally (?) fully deterministic (no matches beyond end of input)
+- Document Z_SYNC_FLUSH
+- add uninstall in Makefile
+- Check for __cpluplus in zlib.h
+- Better test in ct_align for partial flush
+- avoid harmless warnings for Borland C++
+- initialize hash_head in deflate.c
+- avoid warning on fdopen (gzio.c) for HP cc -Aa
+- include stdlib.h for STDC compilers
+- include errno.h for Cray
+- ignore error if ranlib doesn't exist
+- call ranlib twice for NeXTSTEP
+- use exec_prefix instead of prefix for libz.a
+- renamed ct_* as _tr_* to avoid conflict with applications
+- clear z->msg in inflateInit2 before any error return
+- initialize opaque in example.c, gzio.c, deflate.c and inflate.c
+- fixed typo in zconf.h (_GNUC__ => __GNUC__)
+- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
+- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
+- in fcalloc, normalize pointer if size > 65520 bytes
+- don't use special fcalloc for 32 bit Borland C++
+- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
+- use Z_BINARY instead of BINARY
+- document that gzclose after gzdopen will close the file
+- allow "a" as mode in gzopen.
+- fix error checking in gzread
+- allow skipping .gz extra-field on pipes
+- added reference to Perl interface in README
+- put the crc table in FAR data (I dislike more and more the medium model :)
+- added get_crc_table
+- added a dimension to all arrays (Borland C can't count).
+- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
+- guard against multiple inclusion of *.h (for precompiled header on Mac)
+- Watcom C pretends to be Microsoft C small model even in 32 bit mode.
+- don't use unsized arrays to avoid silly warnings by Visual C++:
+     warning C4746: 'inflate_mask' : unsized array treated as  '__far'
+     (what's wrong with far data in far model?).
+- define enum out of inflate_blocks_state to allow compilation with C++
+
+Changes in 0.95 (16 Aug 95)
+- fix MSDOS small and medium model (now easier to adapt to any compiler)
+- inlined send_bits
+- fix the final (:-) bug for deflate with flush (output was correct but
+  not completely flushed in rare occasions).
+- default window size is same for compression and decompression
+  (it's now sufficient to set MAX_WBITS in zconf.h).
+- voidp -> voidpf and voidnp -> voidp (for consistency with other
+  typedefs and because voidnp was not near in large model).
+
+Changes in 0.94 (13 Aug 95)
+- support MSDOS medium model
+- fix deflate with flush (could sometimes generate bad output)
+- fix deflateReset (zlib header was incorrectly suppressed)
+- added support for VMS
+- allow a compression level in gzopen()
+- gzflush now calls fflush
+- For deflate with flush, flush even if no more input is provided.
+- rename libgz.a as libz.a
+- avoid complex expression in infcodes.c triggering Turbo C bug
+- work around a problem with gcc on Alpha (in INSERT_STRING)
+- don't use inline functions (problem with some gcc versions)
+- allow renaming of Byte, uInt, etc... with #define.
+- avoid warning about (unused) pointer before start of array in deflate.c
+- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
+- avoid reserved word 'new' in trees.c
+
+Changes in 0.93 (25 June 95)
+- temporarily disable inline functions
+- make deflate deterministic
+- give enough lookahead for PARTIAL_FLUSH
+- Set binary mode for stdin/stdout in minigzip.c for OS/2
+- don't even use signed char in inflate (not portable enough)
+- fix inflate memory leak for segmented architectures
+
+Changes in 0.92 (3 May 95)
+- don't assume that char is signed (problem on SGI)
+- Clear bit buffer when starting a stored block
+- no memcpy on Pyramid
+- suppressed inftest.c
+- optimized fill_window, put longest_match inline for gcc
+- optimized inflate on stored blocks.
+- untabify all sources to simplify patches
+
+Changes in 0.91 (2 May 95)
+- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
+- Document the memory requirements in zconf.h
+- added "make install"
+- fix sync search logic in inflateSync
+- deflate(Z_FULL_FLUSH) now works even if output buffer too short
+- after inflateSync, don't scare people with just "lo world"
+- added support for DJGPP
+
+Changes in 0.9 (1 May 95)
+- don't assume that zalloc clears the allocated memory (the TurboC bug
+  was Mark's bug after all :)
+- let again gzread copy uncompressed data unchanged (was working in 0.71)
+- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
+- added a test of inflateSync in example.c
+- moved MAX_WBITS to zconf.h because users might want to change that.
+- document explicitly that zalloc(64K) on MSDOS must return a normalized
+  pointer (zero offset)
+- added Makefiles for Microsoft C, Turbo C, Borland C++
+- faster crc32()
+
+Changes in 0.8 (29 April 95)
+- added fast inflate (inffast.c)
+- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
+  is incompatible with previous versions of zlib which returned Z_OK.
+- work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
+  (actually that was not a compiler bug, see 0.81 above)
+- gzread no longer reads one extra byte in certain cases
+- In gzio destroy(), don't reference a freed structure
+- avoid many warnings for MSDOS
+- avoid the ERROR symbol which is used by MS Windows
+
+Changes in 0.71 (14 April 95)
+- Fixed more MSDOS compilation problems :( There is still a bug with
+  TurboC large model.
+
+Changes in 0.7 (14 April 95)
+- Added full inflate support.
+- Simplified the crc32() interface. The pre- and post-conditioning
+  (one's complement) is now done inside crc32(). WARNING: this is
+  incompatible with previous versions; see zlib.h for the new usage.
+
+Changes in 0.61 (12 April 95)
+- workaround for a bug in TurboC. example and minigzip now work on MSDOS.
+
+Changes in 0.6 (11 April 95)
+- added minigzip.c
+- added gzdopen to reopen a file descriptor as gzFile
+- added transparent reading of non-gziped files in gzread.
+- fixed bug in gzread (don't read crc as data)
+- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose).
+- don't allocate big arrays in the stack (for MSDOS)
+- fix some MSDOS compilation problems
+
+Changes in 0.5:
+- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
+  not yet Z_FULL_FLUSH.
+- support decompression but only in a single step (forced Z_FINISH)
+- added opaque object for zalloc and zfree.
+- added deflateReset and inflateReset
+- added a variable zlib_version for consistency checking.
+- renamed the 'filter' parameter of deflateInit2 as 'strategy'.
+  Added Z_FILTERED and Z_HUFFMAN_ONLY constants.
+
+Changes in 0.4:
+- avoid "zip" everywhere, use zlib instead of ziplib.
+- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
+  if compression method == 8.
+- added adler32 and crc32
+- renamed deflateOptions as deflateInit2, call one or the other but not both
+- added the method parameter for deflateInit2.
+- added inflateInit2
+- simplied considerably deflateInit and inflateInit by not supporting
+  user-provided history buffer. This is supported only in deflateInit2
+  and inflateInit2.
+
+Changes in 0.3:
+- prefix all macro names with Z_
+- use Z_FINISH instead of deflateEnd to finish compression.
+- added Z_HUFFMAN_ONLY
+- added gzerror()
diff --git a/deps/libchdr/deps/zlib-1.2.11/FAQ b/deps/libchdr/deps/zlib-1.2.11/FAQ
new file mode 100644 (file)
index 0000000..99b7cf9
--- /dev/null
@@ -0,0 +1,368 @@
+
+                Frequently Asked Questions about zlib
+
+
+If your question is not there, please check the zlib home page
+http://zlib.net/ which may have more recent information.
+The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
+
+
+ 1. Is zlib Y2K-compliant?
+
+    Yes. zlib doesn't handle dates.
+
+ 2. Where can I get a Windows DLL version?
+
+    The zlib sources can be compiled without change to produce a DLL.  See the
+    file win32/DLL_FAQ.txt in the zlib distribution.  Pointers to the
+    precompiled DLL are found in the zlib web site at http://zlib.net/ .
+
+ 3. Where can I get a Visual Basic interface to zlib?
+
+    See
+        * http://marknelson.us/1997/01/01/zlib-engine/
+        * win32/DLL_FAQ.txt in the zlib distribution
+
+ 4. compress() returns Z_BUF_ERROR.
+
+    Make sure that before the call of compress(), the length of the compressed
+    buffer is equal to the available size of the compressed buffer and not
+    zero.  For Visual Basic, check that this parameter is passed by reference
+    ("as any"), not by value ("as long").
+
+ 5. deflate() or inflate() returns Z_BUF_ERROR.
+
+    Before making the call, make sure that avail_in and avail_out are not zero.
+    When setting the parameter flush equal to Z_FINISH, also make sure that
+    avail_out is big enough to allow processing all pending input.  Note that a
+    Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be
+    made with more input or output space.  A Z_BUF_ERROR may in fact be
+    unavoidable depending on how the functions are used, since it is not
+    possible to tell whether or not there is more output pending when
+    strm.avail_out returns with zero.  See http://zlib.net/zlib_how.html for a
+    heavily annotated example.
+
+ 6. Where's the zlib documentation (man pages, etc.)?
+
+    It's in zlib.h .  Examples of zlib usage are in the files test/example.c
+    and test/minigzip.c, with more in examples/ .
+
+ 7. Why don't you use GNU autoconf or libtool or ...?
+
+    Because we would like to keep zlib as a very small and simple package.
+    zlib is rather portable and doesn't need much configuration.
+
+ 8. I found a bug in zlib.
+
+    Most of the time, such problems are due to an incorrect usage of zlib.
+    Please try to reproduce the problem with a small program and send the
+    corresponding source to us at zlib@gzip.org .  Do not send multi-megabyte
+    data files without prior agreement.
+
+ 9. Why do I get "undefined reference to gzputc"?
+
+    If "make test" produces something like
+
+       example.o(.text+0x154): undefined reference to `gzputc'
+
+    check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
+    /usr/X11R6/lib. Remove any old versions, then do "make install".
+
+10. I need a Delphi interface to zlib.
+
+    See the contrib/delphi directory in the zlib distribution.
+
+11. Can zlib handle .zip archives?
+
+    Not by itself, no.  See the directory contrib/minizip in the zlib
+    distribution.
+
+12. Can zlib handle .Z files?
+
+    No, sorry.  You have to spawn an uncompress or gunzip subprocess, or adapt
+    the code of uncompress on your own.
+
+13. How can I make a Unix shared library?
+
+    By default a shared (and a static) library is built for Unix.  So:
+
+    make distclean
+    ./configure
+    make
+
+14. How do I install a shared zlib library on Unix?
+
+    After the above, then:
+
+    make install
+
+    However, many flavors of Unix come with a shared zlib already installed.
+    Before going to the trouble of compiling a shared version of zlib and
+    trying to install it, you may want to check if it's already there!  If you
+    can #include <zlib.h>, it's there.  The -lz option will probably link to
+    it.  You can check the version at the top of zlib.h or with the
+    ZLIB_VERSION symbol defined in zlib.h .
+
+15. I have a question about OttoPDF.
+
+    We are not the authors of OttoPDF. The real author is on the OttoPDF web
+    site: Joel Hainley, jhainley@myndkryme.com.
+
+16. Can zlib decode Flate data in an Adobe PDF file?
+
+    Yes. See http://www.pdflib.com/ . To modify PDF forms, see
+    http://sourceforge.net/projects/acroformtool/ .
+
+17. Why am I getting this "register_frame_info not found" error on Solaris?
+
+    After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
+    generates an error such as:
+
+        ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
+        symbol __register_frame_info: referenced symbol not found
+
+    The symbol __register_frame_info is not part of zlib, it is generated by
+    the C compiler (cc or gcc).  You must recompile applications using zlib
+    which have this problem.  This problem is specific to Solaris.  See
+    http://www.sunfreeware.com for Solaris versions of zlib and applications
+    using zlib.
+
+18. Why does gzip give an error on a file I make with compress/deflate?
+
+    The compress and deflate functions produce data in the zlib format, which
+    is different and incompatible with the gzip format.  The gz* functions in
+    zlib on the other hand use the gzip format.  Both the zlib and gzip formats
+    use the same compressed data format internally, but have different headers
+    and trailers around the compressed data.
+
+19. Ok, so why are there two different formats?
+
+    The gzip format was designed to retain the directory information about a
+    single file, such as the name and last modification date.  The zlib format
+    on the other hand was designed for in-memory and communication channel
+    applications, and has a much more compact header and trailer and uses a
+    faster integrity check than gzip.
+
+20. Well that's nice, but how do I make a gzip file in memory?
+
+    You can request that deflate write the gzip format instead of the zlib
+    format using deflateInit2().  You can also request that inflate decode the
+    gzip format using inflateInit2().  Read zlib.h for more details.
+
+21. Is zlib thread-safe?
+
+    Yes.  However any library routines that zlib uses and any application-
+    provided memory allocation routines must also be thread-safe.  zlib's gz*
+    functions use stdio library routines, and most of zlib's functions use the
+    library memory allocation routines by default.  zlib's *Init* functions
+    allow for the application to provide custom memory allocation routines.
+
+    Of course, you should only operate on any given zlib or gzip stream from a
+    single thread at a time.
+
+22. Can I use zlib in my commercial application?
+
+    Yes.  Please read the license in zlib.h.
+
+23. Is zlib under the GNU license?
+
+    No.  Please read the license in zlib.h.
+
+24. The license says that altered source versions must be "plainly marked". So
+    what exactly do I need to do to meet that requirement?
+
+    You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h.  In
+    particular, the final version number needs to be changed to "f", and an
+    identification string should be appended to ZLIB_VERSION.  Version numbers
+    x.x.x.f are reserved for modifications to zlib by others than the zlib
+    maintainers.  For example, if the version of the base zlib you are altering
+    is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
+    ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3".  You can also
+    update the version strings in deflate.c and inftrees.c.
+
+    For altered source distributions, you should also note the origin and
+    nature of the changes in zlib.h, as well as in ChangeLog and README, along
+    with the dates of the alterations.  The origin should include at least your
+    name (or your company's name), and an email address to contact for help or
+    issues with the library.
+
+    Note that distributing a compiled zlib library along with zlib.h and
+    zconf.h is also a source distribution, and so you should change
+    ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
+    in zlib.h as you would for a full source distribution.
+
+25. Will zlib work on a big-endian or little-endian architecture, and can I
+    exchange compressed data between them?
+
+    Yes and yes.
+
+26. Will zlib work on a 64-bit machine?
+
+    Yes.  It has been tested on 64-bit machines, and has no dependence on any
+    data types being limited to 32-bits in length.  If you have any
+    difficulties, please provide a complete problem report to zlib@gzip.org
+
+27. Will zlib decompress data from the PKWare Data Compression Library?
+
+    No.  The PKWare DCL uses a completely different compressed data format than
+    does PKZIP and zlib.  However, you can look in zlib's contrib/blast
+    directory for a possible solution to your problem.
+
+28. Can I access data randomly in a compressed stream?
+
+    No, not without some preparation.  If when compressing you periodically use
+    Z_FULL_FLUSH, carefully write all the pending data at those points, and
+    keep an index of those locations, then you can start decompression at those
+    points.  You have to be careful to not use Z_FULL_FLUSH too often, since it
+    can significantly degrade compression.  Alternatively, you can scan a
+    deflate stream once to generate an index, and then use that index for
+    random access.  See examples/zran.c .
+
+29. Does zlib work on MVS, OS/390, CICS, etc.?
+
+    It has in the past, but we have not heard of any recent evidence.  There
+    were working ports of zlib 1.1.4 to MVS, but those links no longer work.
+    If you know of recent, successful applications of zlib on these operating
+    systems, please let us know.  Thanks.
+
+30. Is there some simpler, easier to read version of inflate I can look at to
+    understand the deflate format?
+
+    First off, you should read RFC 1951.  Second, yes.  Look in zlib's
+    contrib/puff directory.
+
+31. Does zlib infringe on any patents?
+
+    As far as we know, no.  In fact, that was originally the whole point behind
+    zlib.  Look here for some more information:
+
+    http://www.gzip.org/#faq11
+
+32. Can zlib work with greater than 4 GB of data?
+
+    Yes.  inflate() and deflate() will process any amount of data correctly.
+    Each call of inflate() or deflate() is limited to input and output chunks
+    of the maximum value that can be stored in the compiler's "unsigned int"
+    type, but there is no limit to the number of chunks.  Note however that the
+    strm.total_in and strm_total_out counters may be limited to 4 GB.  These
+    counters are provided as a convenience and are not used internally by
+    inflate() or deflate().  The application can easily set up its own counters
+    updated after each call of inflate() or deflate() to count beyond 4 GB.
+    compress() and uncompress() may be limited to 4 GB, since they operate in a
+    single call.  gzseek() and gztell() may be limited to 4 GB depending on how
+    zlib is compiled.  See the zlibCompileFlags() function in zlib.h.
+
+    The word "may" appears several times above since there is a 4 GB limit only
+    if the compiler's "long" type is 32 bits.  If the compiler's "long" type is
+    64 bits, then the limit is 16 exabytes.
+
+33. Does zlib have any security vulnerabilities?
+
+    The only one that we are aware of is potentially in gzprintf().  If zlib is
+    compiled to use sprintf() or vsprintf(), then there is no protection
+    against a buffer overflow of an 8K string space (or other value as set by
+    gzbuffer()), other than the caller of gzprintf() assuring that the output
+    will not exceed 8K.  On the other hand, if zlib is compiled to use
+    snprintf() or vsnprintf(), which should normally be the case, then there is
+    no vulnerability.  The ./configure script will display warnings if an
+    insecure variation of sprintf() will be used by gzprintf().  Also the
+    zlibCompileFlags() function will return information on what variant of
+    sprintf() is used by gzprintf().
+
+    If you don't have snprintf() or vsnprintf() and would like one, you can
+    find a portable implementation here:
+
+        http://www.ijs.si/software/snprintf/
+
+    Note that you should be using the most recent version of zlib.  Versions
+    1.1.3 and before were subject to a double-free vulnerability, and versions
+    1.2.1 and 1.2.2 were subject to an access exception when decompressing
+    invalid compressed data.
+
+34. Is there a Java version of zlib?
+
+    Probably what you want is to use zlib in Java. zlib is already included
+    as part of the Java SDK in the java.util.zip package. If you really want
+    a version of zlib written in the Java language, look on the zlib home
+    page for links: http://zlib.net/ .
+
+35. I get this or that compiler or source-code scanner warning when I crank it
+    up to maximally-pedantic. Can't you guys write proper code?
+
+    Many years ago, we gave up attempting to avoid warnings on every compiler
+    in the universe.  It just got to be a waste of time, and some compilers
+    were downright silly as well as contradicted each other.  So now, we simply
+    make sure that the code always works.
+
+36. Valgrind (or some similar memory access checker) says that deflate is
+    performing a conditional jump that depends on an uninitialized value.
+    Isn't that a bug?
+
+    No.  That is intentional for performance reasons, and the output of deflate
+    is not affected.  This only started showing up recently since zlib 1.2.x
+    uses malloc() by default for allocations, whereas earlier versions used
+    calloc(), which zeros out the allocated memory.  Even though the code was
+    correct, versions 1.2.4 and later was changed to not stimulate these
+    checkers.
+
+37. Will zlib read the (insert any ancient or arcane format here) compressed
+    data format?
+
+    Probably not. Look in the comp.compression FAQ for pointers to various
+    formats and associated software.
+
+38. How can I encrypt/decrypt zip files with zlib?
+
+    zlib doesn't support encryption.  The original PKZIP encryption is very
+    weak and can be broken with freely available programs.  To get strong
+    encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib
+    compression.  For PKZIP compatible "encryption", look at
+    http://www.info-zip.org/
+
+39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
+
+    "gzip" is the gzip format, and "deflate" is the zlib format.  They should
+    probably have called the second one "zlib" instead to avoid confusion with
+    the raw deflate compressed data format.  While the HTTP 1.1 RFC 2616
+    correctly points to the zlib specification in RFC 1950 for the "deflate"
+    transfer encoding, there have been reports of servers and browsers that
+    incorrectly produce or expect raw deflate data per the deflate
+    specification in RFC 1951, most notably Microsoft.  So even though the
+    "deflate" transfer encoding using the zlib format would be the more
+    efficient approach (and in fact exactly what the zlib format was designed
+    for), using the "gzip" transfer encoding is probably more reliable due to
+    an unfortunate choice of name on the part of the HTTP 1.1 authors.
+
+    Bottom line: use the gzip format for HTTP 1.1 encoding.
+
+40. Does zlib support the new "Deflate64" format introduced by PKWare?
+
+    No.  PKWare has apparently decided to keep that format proprietary, since
+    they have not documented it as they have previous compression formats.  In
+    any case, the compression improvements are so modest compared to other more
+    modern approaches, that it's not worth the effort to implement.
+
+41. I'm having a problem with the zip functions in zlib, can you help?
+
+    There are no zip functions in zlib.  You are probably using minizip by
+    Giles Vollant, which is found in the contrib directory of zlib.  It is not
+    part of zlib.  In fact none of the stuff in contrib is part of zlib.  The
+    files in there are not supported by the zlib authors.  You need to contact
+    the authors of the respective contribution for help.
+
+42. The match.asm code in contrib is under the GNU General Public License.
+    Since it's part of zlib, doesn't that mean that all of zlib falls under the
+    GNU GPL?
+
+    No.  The files in contrib are not part of zlib.  They were contributed by
+    other authors and are provided as a convenience to the user within the zlib
+    distribution.  Each item in contrib has its own license.
+
+43. Is zlib subject to export controls?  What is its ECCN?
+
+    zlib is not subject to export controls, and so is classified as EAR99.
+
+44. Can you please sign these lengthy legal documents and fax them back to us
+    so that we can use your software in our product?
+
+    No. Go away. Shoo.
diff --git a/deps/libchdr/deps/zlib-1.2.11/INDEX b/deps/libchdr/deps/zlib-1.2.11/INDEX
new file mode 100644 (file)
index 0000000..2ba0641
--- /dev/null
@@ -0,0 +1,68 @@
+CMakeLists.txt  cmake build file
+ChangeLog       history of changes
+FAQ             Frequently Asked Questions about zlib
+INDEX           this file
+Makefile        dummy Makefile that tells you to ./configure
+Makefile.in     template for Unix Makefile
+README          guess what
+configure       configure script for Unix
+make_vms.com    makefile for VMS
+test/example.c  zlib usages examples for build testing
+test/minigzip.c minimal gzip-like functionality for build testing
+test/infcover.c inf*.c code coverage for build coverage testing
+treebuild.xml   XML description of source file dependencies
+zconf.h.cmakein zconf.h template for cmake
+zconf.h.in      zconf.h template for configure
+zlib.3          Man page for zlib
+zlib.3.pdf      Man page in PDF format
+zlib.map        Linux symbol information
+zlib.pc.in      Template for pkg-config descriptor
+zlib.pc.cmakein zlib.pc template for cmake
+zlib2ansi       perl script to convert source files for C++ compilation
+
+amiga/          makefiles for Amiga SAS C
+as400/          makefiles for AS/400
+doc/            documentation for formats and algorithms
+msdos/          makefiles for MSDOS
+nintendods/     makefile for Nintendo DS
+old/            makefiles for various architectures and zlib documentation
+                files that have not yet been updated for zlib 1.2.x
+qnx/            makefiles for QNX
+watcom/         makefiles for OpenWatcom
+win32/          makefiles for Windows
+
+                zlib public header files (required for library use):
+zconf.h
+zlib.h
+
+                private source files used to build the zlib library:
+adler32.c
+compress.c
+crc32.c
+crc32.h
+deflate.c
+deflate.h
+gzclose.c
+gzguts.h
+gzlib.c
+gzread.c
+gzwrite.c
+infback.c
+inffast.c
+inffast.h
+inffixed.h
+inflate.c
+inflate.h
+inftrees.c
+inftrees.h
+trees.c
+trees.h
+uncompr.c
+zutil.c
+zutil.h
+
+                source files for sample programs
+See examples/README.examples
+
+                unsupported contributions by third parties
+See contrib/README.contrib
diff --git a/deps/libchdr/deps/zlib-1.2.11/Makefile b/deps/libchdr/deps/zlib-1.2.11/Makefile
new file mode 100644 (file)
index 0000000..6bba86c
--- /dev/null
@@ -0,0 +1,5 @@
+all:
+       -@echo "Please use ./configure first.  Thank you."
+
+distclean:
+       make -f Makefile.in distclean
diff --git a/deps/libchdr/deps/zlib-1.2.11/Makefile.in b/deps/libchdr/deps/zlib-1.2.11/Makefile.in
new file mode 100644 (file)
index 0000000..5a77949
--- /dev/null
@@ -0,0 +1,410 @@
+# Makefile for zlib
+# Copyright (C) 1995-2017 Jean-loup Gailly, Mark Adler
+# For conditions of distribution and use, see copyright notice in zlib.h
+
+# To compile and test, type:
+#    ./configure; make test
+# Normally configure builds both a static and a shared library.
+# If you want to build just a static library, use: ./configure --static
+
+# To use the asm code, type:
+#    cp contrib/asm?86/match.S ./match.S
+#    make LOC=-DASMV OBJA=match.o
+
+# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
+#    make install
+# To install in $HOME instead of /usr/local, use:
+#    make install prefix=$HOME
+
+CC=cc
+
+CFLAGS=-O
+#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
+#CFLAGS=-g -DZLIB_DEBUG
+#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
+#           -Wstrict-prototypes -Wmissing-prototypes
+
+SFLAGS=-O
+LDFLAGS=
+TEST_LDFLAGS=-L. libz.a
+LDSHARED=$(CC)
+CPP=$(CC) -E
+
+STATICLIB=libz.a
+SHAREDLIB=libz.so
+SHAREDLIBV=libz.so.1.2.11
+SHAREDLIBM=libz.so.1
+LIBS=$(STATICLIB) $(SHAREDLIBV)
+
+AR=ar
+ARFLAGS=rc
+RANLIB=ranlib
+LDCONFIG=ldconfig
+LDSHAREDLIBC=-lc
+TAR=tar
+SHELL=/bin/sh
+EXE=
+
+prefix = /usr/local
+exec_prefix = ${prefix}
+libdir = ${exec_prefix}/lib
+sharedlibdir = ${libdir}
+includedir = ${prefix}/include
+mandir = ${prefix}/share/man
+man3dir = ${mandir}/man3
+pkgconfigdir = ${libdir}/pkgconfig
+SRCDIR=
+ZINC=
+ZINCOUT=-I.
+
+OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
+OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
+OBJC = $(OBJZ) $(OBJG)
+
+PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo
+PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo
+PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
+
+# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
+OBJA =
+PIC_OBJA =
+
+OBJS = $(OBJC) $(OBJA)
+
+PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
+
+all: static shared
+
+static: example$(EXE) minigzip$(EXE)
+
+shared: examplesh$(EXE) minigzipsh$(EXE)
+
+all64: example64$(EXE) minigzip64$(EXE)
+
+check: test
+
+test: all teststatic testshared
+
+teststatic: static
+       @TMPST=tmpst_$$; \
+       if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \
+         echo '                *** zlib test OK ***'; \
+       else \
+         echo '                *** zlib test FAILED ***'; false; \
+       fi; \
+       rm -f $$TMPST
+
+testshared: shared
+       @LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
+       LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
+       DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
+       SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
+       TMPSH=tmpsh_$$; \
+       if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \
+         echo '                *** zlib shared test OK ***'; \
+       else \
+         echo '                *** zlib shared test FAILED ***'; false; \
+       fi; \
+       rm -f $$TMPSH
+
+test64: all64
+       @TMP64=tmp64_$$; \
+       if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \
+         echo '                *** zlib 64-bit test OK ***'; \
+       else \
+         echo '                *** zlib 64-bit test FAILED ***'; false; \
+       fi; \
+       rm -f $$TMP64
+
+infcover.o: $(SRCDIR)test/infcover.c $(SRCDIR)zlib.h zconf.h
+       $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/infcover.c
+
+infcover: infcover.o libz.a
+       $(CC) $(CFLAGS) -o $@ infcover.o libz.a
+
+cover: infcover
+       rm -f *.gcda
+       ./infcover
+       gcov inf*.c
+
+libz.a: $(OBJS)
+       $(AR) $(ARFLAGS) $@ $(OBJS)
+       -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
+
+match.o: match.S
+       $(CPP) match.S > _match.s
+       $(CC) -c _match.s
+       mv _match.o match.o
+       rm -f _match.s
+
+match.lo: match.S
+       $(CPP) match.S > _match.s
+       $(CC) -c -fPIC _match.s
+       mv _match.o match.lo
+       rm -f _match.s
+
+example.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
+       $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/example.c
+
+minigzip.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
+       $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/minigzip.c
+
+example64.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
+       $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/example.c
+
+minigzip64.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
+       $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/minigzip.c
+
+
+adler32.o: $(SRCDIR)adler32.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)adler32.c
+
+crc32.o: $(SRCDIR)crc32.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)crc32.c
+
+deflate.o: $(SRCDIR)deflate.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c
+
+infback.o: $(SRCDIR)infback.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)infback.c
+
+inffast.o: $(SRCDIR)inffast.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)inffast.c
+
+inflate.o: $(SRCDIR)inflate.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)inflate.c
+
+inftrees.o: $(SRCDIR)inftrees.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)inftrees.c
+
+trees.o: $(SRCDIR)trees.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)trees.c
+
+zutil.o: $(SRCDIR)zutil.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)zutil.c
+
+compress.o: $(SRCDIR)compress.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)compress.c
+
+uncompr.o: $(SRCDIR)uncompr.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)uncompr.c
+
+gzclose.o: $(SRCDIR)gzclose.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzclose.c
+
+gzlib.o: $(SRCDIR)gzlib.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzlib.c
+
+gzread.o: $(SRCDIR)gzread.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzread.c
+
+gzwrite.o: $(SRCDIR)gzwrite.c
+       $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzwrite.c
+
+
+adler32.lo: $(SRCDIR)adler32.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/adler32.o $(SRCDIR)adler32.c
+       -@mv objs/adler32.o $@
+
+crc32.lo: $(SRCDIR)crc32.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c
+       -@mv objs/crc32.o $@
+
+deflate.lo: $(SRCDIR)deflate.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/deflate.o $(SRCDIR)deflate.c
+       -@mv objs/deflate.o $@
+
+infback.lo: $(SRCDIR)infback.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/infback.o $(SRCDIR)infback.c
+       -@mv objs/infback.o $@
+
+inffast.lo: $(SRCDIR)inffast.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/inffast.o $(SRCDIR)inffast.c
+       -@mv objs/inffast.o $@
+
+inflate.lo: $(SRCDIR)inflate.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/inflate.o $(SRCDIR)inflate.c
+       -@mv objs/inflate.o $@
+
+inftrees.lo: $(SRCDIR)inftrees.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/inftrees.o $(SRCDIR)inftrees.c
+       -@mv objs/inftrees.o $@
+
+trees.lo: $(SRCDIR)trees.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/trees.o $(SRCDIR)trees.c
+       -@mv objs/trees.o $@
+
+zutil.lo: $(SRCDIR)zutil.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/zutil.o $(SRCDIR)zutil.c
+       -@mv objs/zutil.o $@
+
+compress.lo: $(SRCDIR)compress.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/compress.o $(SRCDIR)compress.c
+       -@mv objs/compress.o $@
+
+uncompr.lo: $(SRCDIR)uncompr.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/uncompr.o $(SRCDIR)uncompr.c
+       -@mv objs/uncompr.o $@
+
+gzclose.lo: $(SRCDIR)gzclose.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzclose.o $(SRCDIR)gzclose.c
+       -@mv objs/gzclose.o $@
+
+gzlib.lo: $(SRCDIR)gzlib.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzlib.o $(SRCDIR)gzlib.c
+       -@mv objs/gzlib.o $@
+
+gzread.lo: $(SRCDIR)gzread.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzread.o $(SRCDIR)gzread.c
+       -@mv objs/gzread.o $@
+
+gzwrite.lo: $(SRCDIR)gzwrite.c
+       -@mkdir objs 2>/dev/null || test -d objs
+       $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzwrite.o $(SRCDIR)gzwrite.c
+       -@mv objs/gzwrite.o $@
+
+
+placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a
+       $(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS)
+       rm -f $(SHAREDLIB) $(SHAREDLIBM)
+       ln -s $@ $(SHAREDLIB)
+       ln -s $@ $(SHAREDLIBM)
+       -@rmdir objs
+
+example$(EXE): example.o $(STATICLIB)
+       $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS)
+
+minigzip$(EXE): minigzip.o $(STATICLIB)
+       $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
+
+examplesh$(EXE): example.o $(SHAREDLIBV)
+       $(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
+
+minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
+       $(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
+
+example64$(EXE): example64.o $(STATICLIB)
+       $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
+
+minigzip64$(EXE): minigzip64.o $(STATICLIB)
+       $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS)
+
+install-libs: $(LIBS)
+       -@if [ ! -d $(DESTDIR)$(exec_prefix)  ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
+       -@if [ ! -d $(DESTDIR)$(libdir)       ]; then mkdir -p $(DESTDIR)$(libdir); fi
+       -@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
+       -@if [ ! -d $(DESTDIR)$(man3dir)      ]; then mkdir -p $(DESTDIR)$(man3dir); fi
+       -@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
+       rm -f $(DESTDIR)$(libdir)/$(STATICLIB)
+       cp $(STATICLIB) $(DESTDIR)$(libdir)
+       chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB)
+       -@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1
+       -@if test -n "$(SHAREDLIBV)"; then \
+         rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
+         cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \
+         echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \
+         chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
+         echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \
+         rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
+         ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \
+         ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
+         ($(LDCONFIG) || true)  >/dev/null 2>&1; \
+       fi
+       rm -f $(DESTDIR)$(man3dir)/zlib.3
+       cp $(SRCDIR)zlib.3 $(DESTDIR)$(man3dir)
+       chmod 644 $(DESTDIR)$(man3dir)/zlib.3
+       rm -f $(DESTDIR)$(pkgconfigdir)/zlib.pc
+       cp zlib.pc $(DESTDIR)$(pkgconfigdir)
+       chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc
+# The ranlib in install is needed on NeXTSTEP which checks file times
+# ldconfig is for Linux
+
+install: install-libs
+       -@if [ ! -d $(DESTDIR)$(includedir)   ]; then mkdir -p $(DESTDIR)$(includedir); fi
+       rm -f $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
+       cp $(SRCDIR)zlib.h zconf.h $(DESTDIR)$(includedir)
+       chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
+
+uninstall:
+       cd $(DESTDIR)$(includedir) && rm -f zlib.h zconf.h
+       cd $(DESTDIR)$(libdir) && rm -f libz.a; \
+       if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
+         rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
+       fi
+       cd $(DESTDIR)$(man3dir) && rm -f zlib.3
+       cd $(DESTDIR)$(pkgconfigdir) && rm -f zlib.pc
+
+docs: zlib.3.pdf
+
+zlib.3.pdf: $(SRCDIR)zlib.3
+       groff -mandoc -f H -T ps $(SRCDIR)zlib.3 | ps2pdf - $@
+
+zconf.h.cmakein: $(SRCDIR)zconf.h.in
+       -@ TEMPFILE=zconfh_$$; \
+       echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\
+       sed -f $$TEMPFILE $(SRCDIR)zconf.h.in > $@ &&\
+       touch -r $(SRCDIR)zconf.h.in $@ &&\
+       rm $$TEMPFILE
+
+zconf: $(SRCDIR)zconf.h.in
+       cp -p $(SRCDIR)zconf.h.in zconf.h
+
+mostlyclean: clean
+clean:
+       rm -f *.o *.lo *~ \
+          example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
+          example64$(EXE) minigzip64$(EXE) \
+          infcover \
+          libz.* foo.gz so_locations \
+          _match.s maketree contrib/infback9/*.o
+       rm -rf objs
+       rm -f *.gcda *.gcno *.gcov
+       rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov
+
+maintainer-clean: distclean
+distclean: clean zconf zconf.h.cmakein docs
+       rm -f Makefile zlib.pc configure.log
+       -@rm -f .DS_Store
+       @if [ -f Makefile.in ]; then \
+       printf 'all:\n\t-@echo "Please use ./configure first.  Thank you."\n' > Makefile ; \
+       printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile ; \
+       touch -r $(SRCDIR)Makefile.in Makefile ; fi
+       @if [ ! -f zconf.h.in ]; then rm -f zconf.h zconf.h.cmakein ; fi
+       @if [ ! -f zlib.3 ]; then rm -f zlib.3.pdf ; fi
+
+tags:
+       etags $(SRCDIR)*.[ch]
+
+adler32.o zutil.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
+gzclose.o gzlib.o gzread.o gzwrite.o: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
+compress.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h
+crc32.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
+deflate.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
+infback.o inflate.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
+inffast.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h
+inftrees.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h
+trees.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)trees.h
+
+adler32.lo zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
+gzclose.lo gzlib.lo gzread.lo gzwrite.lo: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
+compress.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h
+crc32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
+deflate.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
+infback.lo inflate.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
+inffast.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h
+inftrees.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h
+trees.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)trees.h
diff --git a/deps/libchdr/deps/zlib-1.2.11/README b/deps/libchdr/deps/zlib-1.2.11/README
new file mode 100644 (file)
index 0000000..51106de
--- /dev/null
@@ -0,0 +1,115 @@
+ZLIB DATA COMPRESSION LIBRARY
+
+zlib 1.2.11 is a general purpose data compression library.  All the code is
+thread safe.  The data format used by the zlib library is described by RFCs
+(Request for Comments) 1950 to 1952 in the files
+http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
+rfc1952 (gzip format).
+
+All functions of the compression library are documented in the file zlib.h
+(volunteer to write man pages welcome, contact zlib@gzip.org).  A usage example
+of the library is given in the file test/example.c which also tests that
+the library is working correctly.  Another example is given in the file
+test/minigzip.c.  The compression library itself is composed of all source
+files in the root directory.
+
+To compile all files and run the test program, follow the instructions given at
+the top of Makefile.in.  In short "./configure; make test", and if that goes
+well, "make install" should work for most flavors of Unix.  For Windows, use
+one of the special makefiles in win32/ or contrib/vstudio/ .  For VMS, use
+make_vms.com.
+
+Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
+<info@winimage.com> for the Windows DLL version.  The zlib home page is
+http://zlib.net/ .  Before reporting a problem, please check this site to
+verify that you have the latest version of zlib; otherwise get the latest
+version and check whether the problem still exists or not.
+
+PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
+
+Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan.  1997
+issue of Dr.  Dobb's Journal; a copy of the article is available at
+http://marknelson.us/1997/01/01/zlib-engine/ .
+
+The changes made in version 1.2.11 are documented in the file ChangeLog.
+
+Unsupported third party contributions are provided in directory contrib/ .
+
+zlib is available in Java using the java.util.zip package, documented at
+http://java.sun.com/developer/technicalArticles/Programming/compression/ .
+
+A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is available
+at CPAN (Comprehensive Perl Archive Network) sites, including
+http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
+
+A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
+available in Python 1.5 and later versions, see
+http://docs.python.org/library/zlib.html .
+
+zlib is built into tcl: http://wiki.tcl.tk/4610 .
+
+An experimental package to read and write files in .zip format, written on top
+of zlib by Gilles Vollant <info@winimage.com>, is available in the
+contrib/minizip directory of zlib.
+
+
+Notes for some targets:
+
+- For Windows DLL versions, please see win32/DLL_FAQ.txt
+
+- For 64-bit Irix, deflate.c must be compiled without any optimization. With
+  -O, one libpng test fails. The test works in 32 bit mode (with the -n32
+  compiler flag). The compiler bug has been reported to SGI.
+
+- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
+  when compiled with cc.
+
+- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
+  necessary to get gzprintf working correctly. This is done by configure.
+
+- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
+  other compilers. Use "make test" to check your compiler.
+
+- gzdopen is not supported on RISCOS or BEOS.
+
+- For PalmOs, see http://palmzlib.sourceforge.net/
+
+
+Acknowledgments:
+
+  The deflate format used by zlib was defined by Phil Katz.  The deflate and
+  zlib specifications were written by L.  Peter Deutsch.  Thanks to all the
+  people who reported problems and suggested various improvements in zlib; they
+  are too numerous to cite here.
+
+Copyright notice:
+
+ (C) 1995-2017 Jean-loup Gailly and Mark Adler
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+
+  Jean-loup Gailly        Mark Adler
+  jloup@gzip.org          madler@alumni.caltech.edu
+
+If you use the zlib library in a product, we would appreciate *not* receiving
+lengthy legal documents to sign.  The sources are provided for free but without
+warranty of any kind.  The library has been entirely written by Jean-loup
+Gailly and Mark Adler; it does not include third-party code.
+
+If you redistribute modified sources, we would appreciate that you include in
+the file ChangeLog history information documenting your changes.  Please read
+the FAQ for more information on the distribution of modified source versions.
diff --git a/deps/libchdr/deps/zlib-1.2.11/adler32.c b/deps/libchdr/deps/zlib-1.2.11/adler32.c
new file mode 100644 (file)
index 0000000..d0be438
--- /dev/null
@@ -0,0 +1,186 @@
+/* adler32.c -- compute the Adler-32 checksum of a data stream
+ * Copyright (C) 1995-2011, 2016 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#include "zutil.h"
+
+local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
+
+#define BASE 65521U     /* largest prime smaller than 65536 */
+#define NMAX 5552
+/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
+
+#define DO1(buf,i)  {adler += (buf)[i]; sum2 += adler;}
+#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
+#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
+#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
+#define DO16(buf)   DO8(buf,0); DO8(buf,8);
+
+/* use NO_DIVIDE if your processor does not do division in hardware --
+   try it both ways to see which is faster */
+#ifdef NO_DIVIDE
+/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
+   (thank you to John Reiser for pointing this out) */
+#  define CHOP(a) \
+    do { \
+        unsigned long tmp = a >> 16; \
+        a &= 0xffffUL; \
+        a += (tmp << 4) - tmp; \
+    } while (0)
+#  define MOD28(a) \
+    do { \
+        CHOP(a); \
+        if (a >= BASE) a -= BASE; \
+    } while (0)
+#  define MOD(a) \
+    do { \
+        CHOP(a); \
+        MOD28(a); \
+    } while (0)
+#  define MOD63(a) \
+    do { /* this assumes a is not negative */ \
+        z_off64_t tmp = a >> 32; \
+        a &= 0xffffffffL; \
+        a += (tmp << 8) - (tmp << 5) + tmp; \
+        tmp = a >> 16; \
+        a &= 0xffffL; \
+        a += (tmp << 4) - tmp; \
+        tmp = a >> 16; \
+        a &= 0xffffL; \
+        a += (tmp << 4) - tmp; \
+        if (a >= BASE) a -= BASE; \
+    } while (0)
+#else
+#  define MOD(a) a %= BASE
+#  define MOD28(a) a %= BASE
+#  define MOD63(a) a %= BASE
+#endif
+
+/* ========================================================================= */
+uLong ZEXPORT adler32_z(adler, buf, len)
+    uLong adler;
+    const Bytef *buf;
+    z_size_t len;
+{
+    unsigned long sum2;
+    unsigned n;
+
+    /* split Adler-32 into component sums */
+    sum2 = (adler >> 16) & 0xffff;
+    adler &= 0xffff;
+
+    /* in case user likes doing a byte at a time, keep it fast */
+    if (len == 1) {
+        adler += buf[0];
+        if (adler >= BASE)
+            adler -= BASE;
+        sum2 += adler;
+        if (sum2 >= BASE)
+            sum2 -= BASE;
+        return adler | (sum2 << 16);
+    }
+
+    /* initial Adler-32 value (deferred check for len == 1 speed) */
+    if (buf == Z_NULL)
+        return 1L;
+
+    /* in case short lengths are provided, keep it somewhat fast */
+    if (len < 16) {
+        while (len--) {
+            adler += *buf++;
+            sum2 += adler;
+        }
+        if (adler >= BASE)
+            adler -= BASE;
+        MOD28(sum2);            /* only added so many BASE's */
+        return adler | (sum2 << 16);
+    }
+
+    /* do length NMAX blocks -- requires just one modulo operation */
+    while (len >= NMAX) {
+        len -= NMAX;
+        n = NMAX / 16;          /* NMAX is divisible by 16 */
+        do {
+            DO16(buf);          /* 16 sums unrolled */
+            buf += 16;
+        } while (--n);
+        MOD(adler);
+        MOD(sum2);
+    }
+
+    /* do remaining bytes (less than NMAX, still just one modulo) */
+    if (len) {                  /* avoid modulos if none remaining */
+        while (len >= 16) {
+            len -= 16;
+            DO16(buf);
+            buf += 16;
+        }
+        while (len--) {
+            adler += *buf++;
+            sum2 += adler;
+        }
+        MOD(adler);
+        MOD(sum2);
+    }
+
+    /* return recombined sums */
+    return adler | (sum2 << 16);
+}
+
+/* ========================================================================= */
+uLong ZEXPORT adler32(adler, buf, len)
+    uLong adler;
+    const Bytef *buf;
+    uInt len;
+{
+    return adler32_z(adler, buf, len);
+}
+
+/* ========================================================================= */
+local uLong adler32_combine_(adler1, adler2, len2)
+    uLong adler1;
+    uLong adler2;
+    z_off64_t len2;
+{
+    unsigned long sum1;
+    unsigned long sum2;
+    unsigned rem;
+
+    /* for negative len, return invalid adler32 as a clue for debugging */
+    if (len2 < 0)
+        return 0xffffffffUL;
+
+    /* the derivation of this formula is left as an exercise for the reader */
+    MOD63(len2);                /* assumes len2 >= 0 */
+    rem = (unsigned)len2;
+    sum1 = adler1 & 0xffff;
+    sum2 = rem * sum1;
+    MOD(sum2);
+    sum1 += (adler2 & 0xffff) + BASE - 1;
+    sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
+    if (sum1 >= BASE) sum1 -= BASE;
+    if (sum1 >= BASE) sum1 -= BASE;
+    if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
+    if (sum2 >= BASE) sum2 -= BASE;
+    return sum1 | (sum2 << 16);
+}
+
+/* ========================================================================= */
+uLong ZEXPORT adler32_combine(adler1, adler2, len2)
+    uLong adler1;
+    uLong adler2;
+    z_off_t len2;
+{
+    return adler32_combine_(adler1, adler2, len2);
+}
+
+uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
+    uLong adler1;
+    uLong adler2;
+    z_off64_t len2;
+{
+    return adler32_combine_(adler1, adler2, len2);
+}
diff --git a/deps/libchdr/deps/zlib-1.2.11/compress.c b/deps/libchdr/deps/zlib-1.2.11/compress.c
new file mode 100644 (file)
index 0000000..e2db404
--- /dev/null
@@ -0,0 +1,86 @@
+/* compress.c -- compress a memory buffer
+ * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+/* ===========================================================================
+     Compresses the source buffer into the destination buffer. The level
+   parameter has the same meaning as in deflateInit.  sourceLen is the byte
+   length of the source buffer. Upon entry, destLen is the total size of the
+   destination buffer, which must be at least 0.1% larger than sourceLen plus
+   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
+
+     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+   Z_STREAM_ERROR if the level parameter is invalid.
+*/
+int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
+    Bytef *dest;
+    uLongf *destLen;
+    const Bytef *source;
+    uLong sourceLen;
+    int level;
+{
+    z_stream stream;
+    int err;
+    const uInt max = (uInt)-1;
+    uLong left;
+
+    left = *destLen;
+    *destLen = 0;
+
+    stream.zalloc = (alloc_func)0;
+    stream.zfree = (free_func)0;
+    stream.opaque = (voidpf)0;
+
+    err = deflateInit(&stream, level);
+    if (err != Z_OK) return err;
+
+    stream.next_out = dest;
+    stream.avail_out = 0;
+    stream.next_in = (z_const Bytef *)source;
+    stream.avail_in = 0;
+
+    do {
+        if (stream.avail_out == 0) {
+            stream.avail_out = left > (uLong)max ? max : (uInt)left;
+            left -= stream.avail_out;
+        }
+        if (stream.avail_in == 0) {
+            stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
+            sourceLen -= stream.avail_in;
+        }
+        err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
+    } while (err == Z_OK);
+
+    *destLen = stream.total_out;
+    deflateEnd(&stream);
+    return err == Z_STREAM_END ? Z_OK : err;
+}
+
+/* ===========================================================================
+ */
+int ZEXPORT compress (dest, destLen, source, sourceLen)
+    Bytef *dest;
+    uLongf *destLen;
+    const Bytef *source;
+    uLong sourceLen;
+{
+    return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
+}
+
+/* ===========================================================================
+     If the default memLevel or windowBits for deflateInit() is changed, then
+   this function needs to be updated.
+ */
+uLong ZEXPORT compressBound (sourceLen)
+    uLong sourceLen;
+{
+    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
+           (sourceLen >> 25) + 13;
+}
diff --git a/deps/libchdr/deps/zlib-1.2.11/configure b/deps/libchdr/deps/zlib-1.2.11/configure
new file mode 100755 (executable)
index 0000000..e974d1f
--- /dev/null
@@ -0,0 +1,921 @@
+#!/bin/sh
+# configure script for zlib.
+#
+# Normally configure builds both a static and a shared library.
+# If you want to build just a static library, use: ./configure --static
+#
+# To impose specific compiler or flags or install directory, use for example:
+#    prefix=$HOME CC=cc CFLAGS="-O4" ./configure
+# or for csh/tcsh users:
+#    (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
+
+# Incorrect settings of CC or CFLAGS may prevent creating a shared library.
+# If you have problems, try without defining CC and CFLAGS before reporting
+# an error.
+
+# start off configure.log
+echo -------------------- >> configure.log
+echo $0 $* >> configure.log
+date >> configure.log
+
+# get source directory
+SRCDIR=`dirname $0`
+if test $SRCDIR = "."; then
+    ZINC=""
+    ZINCOUT="-I."
+    SRCDIR=""
+else
+    ZINC='-include zconf.h'
+    ZINCOUT='-I. -I$(SRCDIR)'
+    SRCDIR="$SRCDIR/"
+fi
+
+# set command prefix for cross-compilation
+if [ -n "${CHOST}" ]; then
+    uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`"
+    CROSS_PREFIX="${CHOST}-"
+fi
+
+# destination name for static library
+STATICLIB=libz.a
+
+# extract zlib version numbers from zlib.h
+VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h`
+VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < ${SRCDIR}zlib.h`
+VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
+VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
+
+# establish commands for library building
+if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
+    AR=${AR-"${CROSS_PREFIX}ar"}
+    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
+else
+    AR=${AR-"ar"}
+    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
+fi
+ARFLAGS=${ARFLAGS-"rc"}
+if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
+    RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
+    test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
+else
+    RANLIB=${RANLIB-"ranlib"}
+fi
+if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
+    NM=${NM-"${CROSS_PREFIX}nm"}
+    test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
+else
+    NM=${NM-"nm"}
+fi
+
+# set defaults before processing command line options
+LDCONFIG=${LDCONFIG-"ldconfig"}
+LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
+ARCHS=
+prefix=${prefix-/usr/local}
+exec_prefix=${exec_prefix-'${prefix}'}
+libdir=${libdir-'${exec_prefix}/lib'}
+sharedlibdir=${sharedlibdir-'${libdir}'}
+includedir=${includedir-'${prefix}/include'}
+mandir=${mandir-'${prefix}/share/man'}
+shared_ext='.so'
+shared=1
+solo=0
+cover=0
+zprefix=0
+zconst=0
+build64=0
+gcc=0
+warn=0
+debug=0
+old_cc="$CC"
+old_cflags="$CFLAGS"
+OBJC='$(OBJZ) $(OBJG)'
+PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
+
+# leave this script, optionally in a bad way
+leave()
+{
+  if test "$*" != "0"; then
+    echo "** $0 aborting." | tee -a configure.log
+  fi
+  rm -f $test.[co] $test $test$shared_ext $test.gcno ./--version
+  echo -------------------- >> configure.log
+  echo >> configure.log
+  echo >> configure.log
+  exit $1
+}
+
+# process command line options
+while test $# -ge 1
+do
+case "$1" in
+    -h* | --help)
+      echo 'usage:' | tee -a configure.log
+      echo '  configure [--const] [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]' | tee -a configure.log
+      echo '    [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
+      echo '    [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
+        exit 0 ;;
+    -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
+    -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
+    -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;;
+    --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
+    -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
+    -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
+    -p* | --prefix) prefix="$2"; shift; shift ;;
+    -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
+    -l* | --libdir) libdir="$2"; shift; shift ;;
+    -i* | --includedir) includedir="$2"; shift; shift ;;
+    -s* | --shared | --enable-shared) shared=1; shift ;;
+    -t | --static) shared=0; shift ;;
+    --solo) solo=1; shift ;;
+    --cover) cover=1; shift ;;
+    -z* | --zprefix) zprefix=1; shift ;;
+    -6* | --64) build64=1; shift ;;
+    -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
+    --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
+    --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
+    -c* | --const) zconst=1; shift ;;
+    -w* | --warn) warn=1; shift ;;
+    -d* | --debug) debug=1; shift ;;
+    *)
+      echo "unknown option: $1" | tee -a configure.log
+      echo "$0 --help for help" | tee -a configure.log
+      leave 1;;
+    esac
+done
+
+# temporary file name
+test=ztest$$
+
+# put arguments in log, also put test file in log if used in arguments
+show()
+{
+  case "$*" in
+    *$test.c*)
+      echo === $test.c === >> configure.log
+      cat $test.c >> configure.log
+      echo === >> configure.log;;
+  esac
+  echo $* >> configure.log
+}
+
+# check for gcc vs. cc and set compile and link flags based on the system identified by uname
+cat > $test.c <<EOF
+extern int getchar();
+int hello() {return getchar();}
+EOF
+
+test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
+cc=${CC-${CROSS_PREFIX}gcc}
+cflags=${CFLAGS-"-O3"}
+# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
+case "$cc" in
+  *gcc*) gcc=1 ;;
+  *clang*) gcc=1 ;;
+esac
+case `$cc -v 2>&1` in
+  *gcc*) gcc=1 ;;
+  *clang*) gcc=1 ;;
+esac
+
+show $cc -c $test.c
+if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
+  echo ... using gcc >> configure.log
+  CC="$cc"
+  CFLAGS="${CFLAGS--O3}"
+  SFLAGS="${CFLAGS--O3} -fPIC"
+  if test "$ARCHS"; then
+    CFLAGS="${CFLAGS} ${ARCHS}"
+    LDFLAGS="${LDFLAGS} ${ARCHS}"
+  fi
+  if test $build64 -eq 1; then
+    CFLAGS="${CFLAGS} -m64"
+    SFLAGS="${SFLAGS} -m64"
+  fi
+  if test "$warn" -eq 1; then
+    if test "$zconst" -eq 1; then
+      CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -pedantic -DZLIB_CONST"
+    else
+      CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
+    fi
+  fi
+  if test $debug -eq 1; then
+    CFLAGS="${CFLAGS} -DZLIB_DEBUG"
+    SFLAGS="${SFLAGS} -DZLIB_DEBUG"
+  fi
+  if test -z "$uname"; then
+    uname=`(uname -s || echo unknown) 2>/dev/null`
+  fi
+  case "$uname" in
+  Linux* | linux* | GNU | GNU/* | solaris*)
+        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"} ;;
+  *BSD | *bsd* | DragonFly)
+        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"}
+        LDCONFIG="ldconfig -m" ;;
+  CYGWIN* | Cygwin* | cygwin* | OS/2*)
+        EXE='.exe' ;;
+  MINGW* | mingw*)
+# temporary bypass
+        rm -f $test.[co] $test $test$shared_ext
+        echo "Please use win32/Makefile.gcc instead." | tee -a configure.log
+        leave 1
+        LDSHARED=${LDSHARED-"$cc -shared"}
+        LDSHAREDLIBC=""
+        EXE='.exe' ;;
+  QNX*)  # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
+         # (alain.bonnefoy@icbt.com)
+                 LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
+  HP-UX*)
+         LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
+         case `(uname -m || echo unknown) 2>/dev/null` in
+         ia64)
+                 shared_ext='.so'
+                 SHAREDLIB='libz.so' ;;
+         *)
+                 shared_ext='.sl'
+                 SHAREDLIB='libz.sl' ;;
+         esac ;;
+  Darwin* | darwin*)
+             shared_ext='.dylib'
+             SHAREDLIB=libz$shared_ext
+             SHAREDLIBV=libz.$VER$shared_ext
+             SHAREDLIBM=libz.$VER1$shared_ext
+             LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
+             if libtool -V 2>&1 | grep Apple > /dev/null; then
+                 AR="libtool"
+             else
+                 AR="/usr/bin/libtool"
+             fi
+             ARFLAGS="-o" ;;
+  *)             LDSHARED=${LDSHARED-"$cc -shared"} ;;
+  esac
+else
+  # find system name and corresponding cc options
+  CC=${CC-cc}
+  gcc=0
+  echo ... using $CC >> configure.log
+  if test -z "$uname"; then
+    uname=`(uname -sr || echo unknown) 2>/dev/null`
+  fi
+  case "$uname" in
+  HP-UX*)    SFLAGS=${CFLAGS-"-O +z"}
+             CFLAGS=${CFLAGS-"-O"}
+#            LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
+             LDSHARED=${LDSHARED-"ld -b"}
+         case `(uname -m || echo unknown) 2>/dev/null` in
+         ia64)
+             shared_ext='.so'
+             SHAREDLIB='libz.so' ;;
+         *)
+             shared_ext='.sl'
+             SHAREDLIB='libz.sl' ;;
+         esac ;;
+  IRIX*)     SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
+             CFLAGS=${CFLAGS-"-ansi -O2"}
+             LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
+  OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
+             CFLAGS=${CFLAGS-"-O -std1"}
+             LDFLAGS="${LDFLAGS} -Wl,-rpath,."
+             LDSHARED=${LDSHARED-"cc -shared  -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
+  OSF1*)     SFLAGS=${CFLAGS-"-O -std1"}
+             CFLAGS=${CFLAGS-"-O -std1"}
+             LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
+  QNX*)      SFLAGS=${CFLAGS-"-4 -O"}
+             CFLAGS=${CFLAGS-"-4 -O"}
+             LDSHARED=${LDSHARED-"cc"}
+             RANLIB=${RANLIB-"true"}
+             AR="cc"
+             ARFLAGS="-A" ;;
+  SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
+             CFLAGS=${CFLAGS-"-O3"}
+             LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
+  SunOS\ 5* | solaris*)
+         LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
+         SFLAGS=${CFLAGS-"-fast -KPIC"}
+         CFLAGS=${CFLAGS-"-fast"}
+         if test $build64 -eq 1; then
+             # old versions of SunPRO/Workshop/Studio don't support -m64,
+             # but newer ones do.  Check for it.
+             flag64=`$CC -flags | egrep -- '^-m64'`
+             if test x"$flag64" != x"" ; then
+                 CFLAGS="${CFLAGS} -m64"
+                 SFLAGS="${SFLAGS} -m64"
+             else
+                 case `(uname -m || echo unknown) 2>/dev/null` in
+                   i86*)
+                     SFLAGS="$SFLAGS -xarch=amd64"
+                     CFLAGS="$CFLAGS -xarch=amd64" ;;
+                   *)
+                     SFLAGS="$SFLAGS -xarch=v9"
+                     CFLAGS="$CFLAGS -xarch=v9" ;;
+                 esac
+             fi
+         fi
+         if test -n "$ZINC"; then
+             ZINC='-I- -I. -I$(SRCDIR)'
+         fi
+         ;;
+  SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
+             CFLAGS=${CFLAGS-"-O2"}
+             LDSHARED=${LDSHARED-"ld"} ;;
+  SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
+             CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
+             LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
+  UNIX_System_V\ 4.2.0)
+             SFLAGS=${CFLAGS-"-KPIC -O"}
+             CFLAGS=${CFLAGS-"-O"}
+             LDSHARED=${LDSHARED-"cc -G"} ;;
+  UNIX_SV\ 4.2MP)
+             SFLAGS=${CFLAGS-"-Kconform_pic -O"}
+             CFLAGS=${CFLAGS-"-O"}
+             LDSHARED=${LDSHARED-"cc -G"} ;;
+  OpenUNIX\ 5)
+             SFLAGS=${CFLAGS-"-KPIC -O"}
+             CFLAGS=${CFLAGS-"-O"}
+             LDSHARED=${LDSHARED-"cc -G"} ;;
+  AIX*)  # Courtesy of dbakker@arrayasolutions.com
+             SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
+             CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
+             LDSHARED=${LDSHARED-"xlc -G"} ;;
+  # send working options for other systems to zlib@gzip.org
+  *)         SFLAGS=${CFLAGS-"-O"}
+             CFLAGS=${CFLAGS-"-O"}
+             LDSHARED=${LDSHARED-"cc -shared"} ;;
+  esac
+fi
+
+# destination names for shared library if not defined above
+SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
+SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
+SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
+
+echo >> configure.log
+
+# define functions for testing compiler and library characteristics and logging the results
+
+cat > $test.c <<EOF
+#error error
+EOF
+if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
+  try()
+  {
+    show $*
+    test "`( $* ) 2>&1 | tee -a configure.log`" = ""
+  }
+  echo - using any output from compiler to indicate an error >> configure.log
+else
+  try()
+  {
+    show $*
+    ( $* ) >> configure.log 2>&1
+    ret=$?
+    if test $ret -ne 0; then
+      echo "(exit code "$ret")" >> configure.log
+    fi
+    return $ret
+  }
+fi
+
+tryboth()
+{
+  show $*
+  got=`( $* ) 2>&1`
+  ret=$?
+  printf %s "$got" >> configure.log
+  if test $ret -ne 0; then
+    return $ret
+  fi
+  test "$got" = ""
+}
+
+cat > $test.c << EOF
+int foo() { return 0; }
+EOF
+echo "Checking for obsessive-compulsive compiler options..." >> configure.log
+if try $CC -c $CFLAGS $test.c; then
+  :
+else
+  echo "Compiler error reporting is too harsh for $0 (perhaps remove -Werror)." | tee -a configure.log
+  leave 1
+fi
+
+echo >> configure.log
+
+# see if shared library build supported
+cat > $test.c <<EOF
+extern int getchar();
+int hello() {return getchar();}
+EOF
+if test $shared -eq 1; then
+  echo Checking for shared library support... | tee -a configure.log
+  # we must test in two steps (cc then ld), required at least on SunOS 4.x
+  if try $CC -w -c $SFLAGS $test.c &&
+     try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
+    echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
+  elif test -z "$old_cc" -a -z "$old_cflags"; then
+    echo No shared library support. | tee -a configure.log
+    shared=0;
+  else
+    echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
+    shared=0;
+  fi
+fi
+if test $shared -eq 0; then
+  LDSHARED="$CC"
+  ALL="static"
+  TEST="all teststatic"
+  SHAREDLIB=""
+  SHAREDLIBV=""
+  SHAREDLIBM=""
+  echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
+else
+  ALL="static shared"
+  TEST="all teststatic testshared"
+fi
+
+# check for underscores in external names for use by assembler code
+CPP=${CPP-"$CC -E"}
+case $CFLAGS in
+  *ASMV*)
+    echo >> configure.log
+    show "$NM $test.o | grep _hello"
+    if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then
+      CPP="$CPP -DNO_UNDERLINE"
+      echo Checking for underline in external names... No. | tee -a configure.log
+    else
+      echo Checking for underline in external names... Yes. | tee -a configure.log
+    fi ;;
+esac
+
+echo >> configure.log
+
+# check for size_t
+cat > $test.c <<EOF
+#include <stdio.h>
+#include <stdlib.h>
+size_t dummy = 0;
+EOF
+if try $CC -c $CFLAGS $test.c; then
+  echo "Checking for size_t... Yes." | tee -a configure.log
+  need_sizet=0
+else
+  echo "Checking for size_t... No." | tee -a configure.log
+  need_sizet=1
+fi
+
+echo >> configure.log
+
+# find the size_t integer type, if needed
+if test $need_sizet -eq 1; then
+  cat > $test.c <<EOF
+long long dummy = 0;
+EOF
+  if try $CC -c $CFLAGS $test.c; then
+    echo "Checking for long long... Yes." | tee -a configure.log
+    cat > $test.c <<EOF
+#include <stdio.h>
+int main(void) {
+    if (sizeof(void *) <= sizeof(int)) puts("int");
+    else if (sizeof(void *) <= sizeof(long)) puts("long");
+    else puts("z_longlong");
+    return 0;
+}
+EOF
+  else
+    echo "Checking for long long... No." | tee -a configure.log
+    cat > $test.c <<EOF
+#include <stdio.h>
+int main(void) {
+    if (sizeof(void *) <= sizeof(int)) puts("int");
+    else puts("long");
+    return 0;
+}
+EOF
+  fi
+  if try $CC $CFLAGS -o $test $test.c; then
+    sizet=`./$test`
+    echo "Checking for a pointer-size integer type..." $sizet"." | tee -a configure.log
+  else
+    echo "Failed to find a pointer-size integer type." | tee -a configure.log
+    leave 1
+  fi
+fi
+
+if test $need_sizet -eq 1; then
+  CFLAGS="${CFLAGS} -DNO_SIZE_T=${sizet}"
+  SFLAGS="${SFLAGS} -DNO_SIZE_T=${sizet}"
+fi
+
+echo >> configure.log
+
+# check for large file support, and if none, check for fseeko()
+cat > $test.c <<EOF
+#include <sys/types.h>
+off64_t dummy = 0;
+EOF
+if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
+  CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
+  SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
+  ALL="${ALL} all64"
+  TEST="${TEST} test64"
+  echo "Checking for off64_t... Yes." | tee -a configure.log
+  echo "Checking for fseeko... Yes." | tee -a configure.log
+else
+  echo "Checking for off64_t... No." | tee -a configure.log
+  echo >> configure.log
+  cat > $test.c <<EOF
+#include <stdio.h>
+int main(void) {
+  fseeko(NULL, 0, 0);
+  return 0;
+}
+EOF
+  if try $CC $CFLAGS -o $test $test.c; then
+    echo "Checking for fseeko... Yes." | tee -a configure.log
+  else
+    CFLAGS="${CFLAGS} -DNO_FSEEKO"
+    SFLAGS="${SFLAGS} -DNO_FSEEKO"
+    echo "Checking for fseeko... No." | tee -a configure.log
+  fi
+fi
+
+echo >> configure.log
+
+# check for strerror() for use by gz* functions
+cat > $test.c <<EOF
+#include <string.h>
+#include <errno.h>
+int main() { return strlen(strerror(errno)); }
+EOF
+if try $CC $CFLAGS -o $test $test.c; then
+  echo "Checking for strerror... Yes." | tee -a configure.log
+else
+  CFLAGS="${CFLAGS} -DNO_STRERROR"
+  SFLAGS="${SFLAGS} -DNO_STRERROR"
+  echo "Checking for strerror... No." | tee -a configure.log
+fi
+
+# copy clean zconf.h for subsequent edits
+cp -p ${SRCDIR}zconf.h.in zconf.h
+
+echo >> configure.log
+
+# check for unistd.h and save result in zconf.h
+cat > $test.c <<EOF
+#include <unistd.h>
+int main() { return 0; }
+EOF
+if try $CC -c $CFLAGS $test.c; then
+  sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
+  mv zconf.temp.h zconf.h
+  echo "Checking for unistd.h... Yes." | tee -a configure.log
+else
+  echo "Checking for unistd.h... No." | tee -a configure.log
+fi
+
+echo >> configure.log
+
+# check for stdarg.h and save result in zconf.h
+cat > $test.c <<EOF
+#include <stdarg.h>
+int main() { return 0; }
+EOF
+if try $CC -c $CFLAGS $test.c; then
+  sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
+  mv zconf.temp.h zconf.h
+  echo "Checking for stdarg.h... Yes." | tee -a configure.log
+else
+  echo "Checking for stdarg.h... No." | tee -a configure.log
+fi
+
+# if the z_ prefix was requested, save that in zconf.h
+if test $zprefix -eq 1; then
+  sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
+  mv zconf.temp.h zconf.h
+  echo >> configure.log
+  echo "Using z_ prefix on all symbols." | tee -a configure.log
+fi
+
+# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
+if test $solo -eq 1; then
+  sed '/#define ZCONF_H/a\
+#define Z_SOLO
+
+' < zconf.h > zconf.temp.h
+  mv zconf.temp.h zconf.h
+OBJC='$(OBJZ)'
+PIC_OBJC='$(PIC_OBJZ)'
+fi
+
+# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
+if test $cover -eq 1; then
+  CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
+  if test -n "$GCC_CLASSIC"; then
+    CC=$GCC_CLASSIC
+  fi
+fi
+
+echo >> configure.log
+
+# conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
+# (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
+# return value.  The most secure result is vsnprintf() with a return value.  snprintf() with a
+# return value is secure as well, but then gzprintf() will be limited to 20 arguments.
+cat > $test.c <<EOF
+#include <stdio.h>
+#include <stdarg.h>
+#include "zconf.h"
+int main()
+{
+#ifndef STDC
+  choke me
+#endif
+  return 0;
+}
+EOF
+if try $CC -c $CFLAGS $test.c; then
+  echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
+
+  echo >> configure.log
+  cat > $test.c <<EOF
+#include <stdio.h>
+#include <stdarg.h>
+int mytest(const char *fmt, ...)
+{
+  char buf[20];
+  va_list ap;
+  va_start(ap, fmt);
+  vsnprintf(buf, sizeof(buf), fmt, ap);
+  va_end(ap);
+  return 0;
+}
+int main()
+{
+  return (mytest("Hello%d\n", 1));
+}
+EOF
+  if try $CC $CFLAGS -o $test $test.c; then
+    echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
+
+    echo >> configure.log
+    cat >$test.c <<EOF
+#include <stdio.h>
+#include <stdarg.h>
+int mytest(const char *fmt, ...)
+{
+  int n;
+  char buf[20];
+  va_list ap;
+  va_start(ap, fmt);
+  n = vsnprintf(buf, sizeof(buf), fmt, ap);
+  va_end(ap);
+  return n;
+}
+int main()
+{
+  return (mytest("Hello%d\n", 1));
+}
+EOF
+
+    if try $CC -c $CFLAGS $test.c; then
+      echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
+    else
+      CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
+      SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
+      echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
+      echo "  WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
+      echo "  can build but will be open to possible string-format security" | tee -a configure.log
+      echo "  vulnerabilities." | tee -a configure.log
+    fi
+  else
+    CFLAGS="$CFLAGS -DNO_vsnprintf"
+    SFLAGS="$SFLAGS -DNO_vsnprintf"
+    echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
+    echo "  WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
+    echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
+    echo "  vulnerabilities." | tee -a configure.log
+
+    echo >> configure.log
+    cat >$test.c <<EOF
+#include <stdio.h>
+#include <stdarg.h>
+int mytest(const char *fmt, ...)
+{
+  int n;
+  char buf[20];
+  va_list ap;
+  va_start(ap, fmt);
+  n = vsprintf(buf, fmt, ap);
+  va_end(ap);
+  return n;
+}
+int main()
+{
+  return (mytest("Hello%d\n", 1));
+}
+EOF
+
+    if try $CC -c $CFLAGS $test.c; then
+      echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
+    else
+      CFLAGS="$CFLAGS -DHAS_vsprintf_void"
+      SFLAGS="$SFLAGS -DHAS_vsprintf_void"
+      echo "Checking for return value of vsprintf()... No." | tee -a configure.log
+      echo "  WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
+      echo "  can build but will be open to possible string-format security" | tee -a configure.log
+      echo "  vulnerabilities." | tee -a configure.log
+    fi
+  fi
+else
+  echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
+
+  echo >> configure.log
+  cat >$test.c <<EOF
+#include <stdio.h>
+int mytest()
+{
+  char buf[20];
+  snprintf(buf, sizeof(buf), "%s", "foo");
+  return 0;
+}
+int main()
+{
+  return (mytest());
+}
+EOF
+
+  if try $CC $CFLAGS -o $test $test.c; then
+    echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
+
+    echo >> configure.log
+    cat >$test.c <<EOF
+#include <stdio.h>
+int mytest()
+{
+  char buf[20];
+  return snprintf(buf, sizeof(buf), "%s", "foo");
+}
+int main()
+{
+  return (mytest());
+}
+EOF
+
+    if try $CC -c $CFLAGS $test.c; then
+      echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
+    else
+      CFLAGS="$CFLAGS -DHAS_snprintf_void"
+      SFLAGS="$SFLAGS -DHAS_snprintf_void"
+      echo "Checking for return value of snprintf()... No." | tee -a configure.log
+      echo "  WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
+      echo "  can build but will be open to possible string-format security" | tee -a configure.log
+      echo "  vulnerabilities." | tee -a configure.log
+    fi
+  else
+    CFLAGS="$CFLAGS -DNO_snprintf"
+    SFLAGS="$SFLAGS -DNO_snprintf"
+    echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
+    echo "  WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
+    echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
+    echo "  vulnerabilities." | tee -a configure.log
+
+    echo >> configure.log
+    cat >$test.c <<EOF
+#include <stdio.h>
+int mytest()
+{
+  char buf[20];
+  return sprintf(buf, "%s", "foo");
+}
+int main()
+{
+  return (mytest());
+}
+EOF
+
+    if try $CC -c $CFLAGS $test.c; then
+      echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
+    else
+      CFLAGS="$CFLAGS -DHAS_sprintf_void"
+      SFLAGS="$SFLAGS -DHAS_sprintf_void"
+      echo "Checking for return value of sprintf()... No." | tee -a configure.log
+      echo "  WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
+      echo "  can build but will be open to possible string-format security" | tee -a configure.log
+      echo "  vulnerabilities." | tee -a configure.log
+    fi
+  fi
+fi
+
+# see if we can hide zlib internal symbols that are linked between separate source files
+if test "$gcc" -eq 1; then
+  echo >> configure.log
+  cat > $test.c <<EOF
+#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
+int ZLIB_INTERNAL foo;
+int main()
+{
+  return 0;
+}
+EOF
+  if tryboth $CC -c $CFLAGS $test.c; then
+    CFLAGS="$CFLAGS -DHAVE_HIDDEN"
+    SFLAGS="$SFLAGS -DHAVE_HIDDEN"
+    echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
+  else
+    echo "Checking for attribute(visibility) support... No." | tee -a configure.log
+  fi
+fi
+
+# show the results in the log
+echo >> configure.log
+echo ALL = $ALL >> configure.log
+echo AR = $AR >> configure.log
+echo ARFLAGS = $ARFLAGS >> configure.log
+echo CC = $CC >> configure.log
+echo CFLAGS = $CFLAGS >> configure.log
+echo CPP = $CPP >> configure.log
+echo EXE = $EXE >> configure.log
+echo LDCONFIG = $LDCONFIG >> configure.log
+echo LDFLAGS = $LDFLAGS >> configure.log
+echo LDSHARED = $LDSHARED >> configure.log
+echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log
+echo OBJC = $OBJC >> configure.log
+echo PIC_OBJC = $PIC_OBJC >> configure.log
+echo RANLIB = $RANLIB >> configure.log
+echo SFLAGS = $SFLAGS >> configure.log
+echo SHAREDLIB = $SHAREDLIB >> configure.log
+echo SHAREDLIBM = $SHAREDLIBM >> configure.log
+echo SHAREDLIBV = $SHAREDLIBV >> configure.log
+echo STATICLIB = $STATICLIB >> configure.log
+echo TEST = $TEST >> configure.log
+echo VER = $VER >> configure.log
+echo Z_U4 = $Z_U4 >> configure.log
+echo SRCDIR = $SRCDIR >> configure.log
+echo exec_prefix = $exec_prefix >> configure.log
+echo includedir = $includedir >> configure.log
+echo libdir = $libdir >> configure.log
+echo mandir = $mandir >> configure.log
+echo prefix = $prefix >> configure.log
+echo sharedlibdir = $sharedlibdir >> configure.log
+echo uname = $uname >> configure.log
+
+# udpate Makefile with the configure results
+sed < ${SRCDIR}Makefile.in "
+/^CC *=/s#=.*#=$CC#
+/^CFLAGS *=/s#=.*#=$CFLAGS#
+/^SFLAGS *=/s#=.*#=$SFLAGS#
+/^LDFLAGS *=/s#=.*#=$LDFLAGS#
+/^LDSHARED *=/s#=.*#=$LDSHARED#
+/^CPP *=/s#=.*#=$CPP#
+/^STATICLIB *=/s#=.*#=$STATICLIB#
+/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
+/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
+/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
+/^AR *=/s#=.*#=$AR#
+/^ARFLAGS *=/s#=.*#=$ARFLAGS#
+/^RANLIB *=/s#=.*#=$RANLIB#
+/^LDCONFIG *=/s#=.*#=$LDCONFIG#
+/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
+/^EXE *=/s#=.*#=$EXE#
+/^SRCDIR *=/s#=.*#=$SRCDIR#
+/^ZINC *=/s#=.*#=$ZINC#
+/^ZINCOUT *=/s#=.*#=$ZINCOUT#
+/^prefix *=/s#=.*#=$prefix#
+/^exec_prefix *=/s#=.*#=$exec_prefix#
+/^libdir *=/s#=.*#=$libdir#
+/^sharedlibdir *=/s#=.*#=$sharedlibdir#
+/^includedir *=/s#=.*#=$includedir#
+/^mandir *=/s#=.*#=$mandir#
+/^OBJC *=/s#=.*#= $OBJC#
+/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
+/^all: */s#:.*#: $ALL#
+/^test: */s#:.*#: $TEST#
+" > Makefile
+
+# create zlib.pc with the configure results
+sed < ${SRCDIR}zlib.pc.in "
+/^CC *=/s#=.*#=$CC#
+/^CFLAGS *=/s#=.*#=$CFLAGS#
+/^CPP *=/s#=.*#=$CPP#
+/^LDSHARED *=/s#=.*#=$LDSHARED#
+/^STATICLIB *=/s#=.*#=$STATICLIB#
+/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
+/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
+/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
+/^AR *=/s#=.*#=$AR#
+/^ARFLAGS *=/s#=.*#=$ARFLAGS#
+/^RANLIB *=/s#=.*#=$RANLIB#
+/^EXE *=/s#=.*#=$EXE#
+/^prefix *=/s#=.*#=$prefix#
+/^exec_prefix *=/s#=.*#=$exec_prefix#
+/^libdir *=/s#=.*#=$libdir#
+/^sharedlibdir *=/s#=.*#=$sharedlibdir#
+/^includedir *=/s#=.*#=$includedir#
+/^mandir *=/s#=.*#=$mandir#
+/^LDFLAGS *=/s#=.*#=$LDFLAGS#
+" | sed -e "
+s/\@VERSION\@/$VER/g;
+" > zlib.pc
+
+# done
+leave 0
diff --git a/deps/libchdr/deps/zlib-1.2.11/crc32.c b/deps/libchdr/deps/zlib-1.2.11/crc32.c
new file mode 100644 (file)
index 0000000..9580440
--- /dev/null
@@ -0,0 +1,442 @@
+/* crc32.c -- compute the CRC-32 of a data stream
+ * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ *
+ * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
+ * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
+ * tables for updating the shift register in one step with three exclusive-ors
+ * instead of four steps with four exclusive-ors.  This results in about a
+ * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
+ */
+
+/* @(#) $Id$ */
+
+/*
+  Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
+  protection on the static variables used to control the first-use generation
+  of the crc tables.  Therefore, if you #define DYNAMIC_CRC_TABLE, you should
+  first call get_crc_table() to initialize the tables before allowing more than
+  one thread to use crc32().
+
+  DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
+ */
+
+#ifdef MAKECRCH
+#  include <stdio.h>
+#  ifndef DYNAMIC_CRC_TABLE
+#    define DYNAMIC_CRC_TABLE
+#  endif /* !DYNAMIC_CRC_TABLE */
+#endif /* MAKECRCH */
+
+#include "zutil.h"      /* for STDC and FAR definitions */
+
+/* Definitions for doing the crc four data bytes at a time. */
+#if !defined(NOBYFOUR) && defined(Z_U4)
+#  define BYFOUR
+#endif
+#ifdef BYFOUR
+   local unsigned long crc32_little OF((unsigned long,
+                        const unsigned char FAR *, z_size_t));
+   local unsigned long crc32_big OF((unsigned long,
+                        const unsigned char FAR *, z_size_t));
+#  define TBLS 8
+#else
+#  define TBLS 1
+#endif /* BYFOUR */
+
+/* Local functions for crc concatenation */
+local unsigned long gf2_matrix_times OF((unsigned long *mat,
+                                         unsigned long vec));
+local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
+local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
+
+
+#ifdef DYNAMIC_CRC_TABLE
+
+local volatile int crc_table_empty = 1;
+local z_crc_t FAR crc_table[TBLS][256];
+local void make_crc_table OF((void));
+#ifdef MAKECRCH
+   local void write_table OF((FILE *, const z_crc_t FAR *));
+#endif /* MAKECRCH */
+/*
+  Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
+  x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
+
+  Polynomials over GF(2) are represented in binary, one bit per coefficient,
+  with the lowest powers in the most significant bit.  Then adding polynomials
+  is just exclusive-or, and multiplying a polynomial by x is a right shift by
+  one.  If we call the above polynomial p, and represent a byte as the
+  polynomial q, also with the lowest power in the most significant bit (so the
+  byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
+  where a mod b means the remainder after dividing a by b.
+
+  This calculation is done using the shift-register method of multiplying and
+  taking the remainder.  The register is initialized to zero, and for each
+  incoming bit, x^32 is added mod p to the register if the bit is a one (where
+  x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
+  x (which is shifting right by one and adding x^32 mod p if the bit shifted
+  out is a one).  We start with the highest power (least significant bit) of
+  q and repeat for all eight bits of q.
+
+  The first table is simply the CRC of all possible eight bit values.  This is
+  all the information needed to generate CRCs on data a byte at a time for all
+  combinations of CRC register values and incoming bytes.  The remaining tables
+  allow for word-at-a-time CRC calculation for both big-endian and little-
+  endian machines, where a word is four bytes.
+*/
+local void make_crc_table()
+{
+    z_crc_t c;
+    int n, k;
+    z_crc_t poly;                       /* polynomial exclusive-or pattern */
+    /* terms of polynomial defining this crc (except x^32): */
+    static volatile int first = 1;      /* flag to limit concurrent making */
+    static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
+
+    /* See if another task is already doing this (not thread-safe, but better
+       than nothing -- significantly reduces duration of vulnerability in
+       case the advice about DYNAMIC_CRC_TABLE is ignored) */
+    if (first) {
+        first = 0;
+
+        /* make exclusive-or pattern from polynomial (0xedb88320UL) */
+        poly = 0;
+        for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
+            poly |= (z_crc_t)1 << (31 - p[n]);
+
+        /* generate a crc for every 8-bit value */
+        for (n = 0; n < 256; n++) {
+            c = (z_crc_t)n;
+            for (k = 0; k < 8; k++)
+                c = c & 1 ? poly ^ (c >> 1) : c >> 1;
+            crc_table[0][n] = c;
+        }
+
+#ifdef BYFOUR
+        /* generate crc for each value followed by one, two, and three zeros,
+           and then the byte reversal of those as well as the first table */
+        for (n = 0; n < 256; n++) {
+            c = crc_table[0][n];
+            crc_table[4][n] = ZSWAP32(c);
+            for (k = 1; k < 4; k++) {
+                c = crc_table[0][c & 0xff] ^ (c >> 8);
+                crc_table[k][n] = c;
+                crc_table[k + 4][n] = ZSWAP32(c);
+            }
+        }
+#endif /* BYFOUR */
+
+        crc_table_empty = 0;
+    }
+    else {      /* not first */
+        /* wait for the other guy to finish (not efficient, but rare) */
+        while (crc_table_empty)
+            ;
+    }
+
+#ifdef MAKECRCH
+    /* write out CRC tables to crc32.h */
+    {
+        FILE *out;
+
+        out = fopen("crc32.h", "w");
+        if (out == NULL) return;
+        fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
+        fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
+        fprintf(out, "local const z_crc_t FAR ");
+        fprintf(out, "crc_table[TBLS][256] =\n{\n  {\n");
+        write_table(out, crc_table[0]);
+#  ifdef BYFOUR
+        fprintf(out, "#ifdef BYFOUR\n");
+        for (k = 1; k < 8; k++) {
+            fprintf(out, "  },\n  {\n");
+            write_table(out, crc_table[k]);
+        }
+        fprintf(out, "#endif\n");
+#  endif /* BYFOUR */
+        fprintf(out, "  }\n};\n");
+        fclose(out);
+    }
+#endif /* MAKECRCH */
+}
+
+#ifdef MAKECRCH
+local void write_table(out, table)
+    FILE *out;
+    const z_crc_t FAR *table;
+{
+    int n;
+
+    for (n = 0; n < 256; n++)
+        fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : "    ",
+                (unsigned long)(table[n]),
+                n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
+}
+#endif /* MAKECRCH */
+
+#else /* !DYNAMIC_CRC_TABLE */
+/* ========================================================================
+ * Tables of CRC-32s of all single-byte values, made by make_crc_table().
+ */
+#include "crc32.h"
+#endif /* DYNAMIC_CRC_TABLE */
+
+/* =========================================================================
+ * This function can be used by asm versions of crc32()
+ */
+const z_crc_t FAR * ZEXPORT get_crc_table()
+{
+#ifdef DYNAMIC_CRC_TABLE
+    if (crc_table_empty)
+        make_crc_table();
+#endif /* DYNAMIC_CRC_TABLE */
+    return (const z_crc_t FAR *)crc_table;
+}
+
+/* ========================================================================= */
+#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
+#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
+
+/* ========================================================================= */
+unsigned long ZEXPORT crc32_z(crc, buf, len)
+    unsigned long crc;
+    const unsigned char FAR *buf;
+    z_size_t len;
+{
+    if (buf == Z_NULL) return 0UL;
+
+#ifdef DYNAMIC_CRC_TABLE
+    if (crc_table_empty)
+        make_crc_table();
+#endif /* DYNAMIC_CRC_TABLE */
+
+#ifdef BYFOUR
+    if (sizeof(void *) == sizeof(ptrdiff_t)) {
+        z_crc_t endian;
+
+        endian = 1;
+        if (*((unsigned char *)(&endian)))
+            return crc32_little(crc, buf, len);
+        else
+            return crc32_big(crc, buf, len);
+    }
+#endif /* BYFOUR */
+    crc = crc ^ 0xffffffffUL;
+    while (len >= 8) {
+        DO8;
+        len -= 8;
+    }
+    if (len) do {
+        DO1;
+    } while (--len);
+    return crc ^ 0xffffffffUL;
+}
+
+/* ========================================================================= */
+unsigned long ZEXPORT crc32(crc, buf, len)
+    unsigned long crc;
+    const unsigned char FAR *buf;
+    uInt len;
+{
+    return crc32_z(crc, buf, len);
+}
+
+#ifdef BYFOUR
+
+/*
+   This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit
+   integer pointer type. This violates the strict aliasing rule, where a
+   compiler can assume, for optimization purposes, that two pointers to
+   fundamentally different types won't ever point to the same memory. This can
+   manifest as a problem only if one of the pointers is written to. This code
+   only reads from those pointers. So long as this code remains isolated in
+   this compilation unit, there won't be a problem. For this reason, this code
+   should not be copied and pasted into a compilation unit in which other code
+   writes to the buffer that is passed to these routines.
+ */
+
+/* ========================================================================= */
+#define DOLIT4 c ^= *buf4++; \
+        c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
+            crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
+#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
+
+/* ========================================================================= */
+local unsigned long crc32_little(crc, buf, len)
+    unsigned long crc;
+    const unsigned char FAR *buf;
+    z_size_t len;
+{
+    register z_crc_t c;
+    register const z_crc_t FAR *buf4;
+
+    c = (z_crc_t)crc;
+    c = ~c;
+    while (len && ((ptrdiff_t)buf & 3)) {
+        c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
+        len--;
+    }
+
+    buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
+    while (len >= 32) {
+        DOLIT32;
+        len -= 32;
+    }
+    while (len >= 4) {
+        DOLIT4;
+        len -= 4;
+    }
+    buf = (const unsigned char FAR *)buf4;
+
+    if (len) do {
+        c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
+    } while (--len);
+    c = ~c;
+    return (unsigned long)c;
+}
+
+/* ========================================================================= */
+#define DOBIG4 c ^= *buf4++; \
+        c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
+            crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
+#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
+
+/* ========================================================================= */
+local unsigned long crc32_big(crc, buf, len)
+    unsigned long crc;
+    const unsigned char FAR *buf;
+    z_size_t len;
+{
+    register z_crc_t c;
+    register const z_crc_t FAR *buf4;
+
+    c = ZSWAP32((z_crc_t)crc);
+    c = ~c;
+    while (len && ((ptrdiff_t)buf & 3)) {
+        c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
+        len--;
+    }
+
+    buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
+    while (len >= 32) {
+        DOBIG32;
+        len -= 32;
+    }
+    while (len >= 4) {
+        DOBIG4;
+        len -= 4;
+    }
+    buf = (const unsigned char FAR *)buf4;
+
+    if (len) do {
+        c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
+    } while (--len);
+    c = ~c;
+    return (unsigned long)(ZSWAP32(c));
+}
+
+#endif /* BYFOUR */
+
+#define GF2_DIM 32      /* dimension of GF(2) vectors (length of CRC) */
+
+/* ========================================================================= */
+local unsigned long gf2_matrix_times(mat, vec)
+    unsigned long *mat;
+    unsigned long vec;
+{
+    unsigned long sum;
+
+    sum = 0;
+    while (vec) {
+        if (vec & 1)
+            sum ^= *mat;
+        vec >>= 1;
+        mat++;
+    }
+    return sum;
+}
+
+/* ========================================================================= */
+local void gf2_matrix_square(square, mat)
+    unsigned long *square;
+    unsigned long *mat;
+{
+    int n;
+
+    for (n = 0; n < GF2_DIM; n++)
+        square[n] = gf2_matrix_times(mat, mat[n]);
+}
+
+/* ========================================================================= */
+local uLong crc32_combine_(crc1, crc2, len2)
+    uLong crc1;
+    uLong crc2;
+    z_off64_t len2;
+{
+    int n;
+    unsigned long row;
+    unsigned long even[GF2_DIM];    /* even-power-of-two zeros operator */
+    unsigned long odd[GF2_DIM];     /* odd-power-of-two zeros operator */
+
+    /* degenerate case (also disallow negative lengths) */
+    if (len2 <= 0)
+        return crc1;
+
+    /* put operator for one zero bit in odd */
+    odd[0] = 0xedb88320UL;          /* CRC-32 polynomial */
+    row = 1;
+    for (n = 1; n < GF2_DIM; n++) {
+        odd[n] = row;
+        row <<= 1;
+    }
+
+    /* put operator for two zero bits in even */
+    gf2_matrix_square(even, odd);
+
+    /* put operator for four zero bits in odd */
+    gf2_matrix_square(odd, even);
+
+    /* apply len2 zeros to crc1 (first square will put the operator for one
+       zero byte, eight zero bits, in even) */
+    do {
+        /* apply zeros operator for this bit of len2 */
+        gf2_matrix_square(even, odd);
+        if (len2 & 1)
+            crc1 = gf2_matrix_times(even, crc1);
+        len2 >>= 1;
+
+        /* if no more bits set, then done */
+        if (len2 == 0)
+            break;
+
+        /* another iteration of the loop with odd and even swapped */
+        gf2_matrix_square(odd, even);
+        if (len2 & 1)
+            crc1 = gf2_matrix_times(odd, crc1);
+        len2 >>= 1;
+
+        /* if no more bits set, then done */
+    } while (len2 != 0);
+
+    /* return combined crc */
+    crc1 ^= crc2;
+    return crc1;
+}
+
+/* ========================================================================= */
+uLong ZEXPORT crc32_combine(crc1, crc2, len2)
+    uLong crc1;
+    uLong crc2;
+    z_off_t len2;
+{
+    return crc32_combine_(crc1, crc2, len2);
+}
+
+uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
+    uLong crc1;
+    uLong crc2;
+    z_off64_t len2;
+{
+    return crc32_combine_(crc1, crc2, len2);
+}
diff --git a/deps/libchdr/deps/zlib-1.2.11/crc32.h b/deps/libchdr/deps/zlib-1.2.11/crc32.h
new file mode 100644 (file)
index 0000000..9e0c778
--- /dev/null
@@ -0,0 +1,441 @@
+/* crc32.h -- tables for rapid CRC calculation
+ * Generated automatically by crc32.c
+ */
+
+local const z_crc_t FAR crc_table[TBLS][256] =
+{
+  {
+    0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
+    0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
+    0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
+    0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
+    0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
+    0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
+    0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
+    0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
+    0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
+    0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
+    0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
+    0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
+    0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
+    0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
+    0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
+    0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
+    0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
+    0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
+    0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
+    0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
+    0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
+    0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
+    0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
+    0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
+    0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
+    0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
+    0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
+    0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
+    0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
+    0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
+    0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
+    0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
+    0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
+    0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
+    0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
+    0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
+    0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
+    0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
+    0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
+    0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
+    0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
+    0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
+    0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
+    0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
+    0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
+    0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
+    0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
+    0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
+    0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
+    0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
+    0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
+    0x2d02ef8dUL
+#ifdef BYFOUR
+  },
+  {
+    0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
+    0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
+    0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
+    0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
+    0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
+    0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
+    0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
+    0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
+    0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
+    0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
+    0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
+    0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
+    0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
+    0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
+    0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
+    0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
+    0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
+    0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
+    0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
+    0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
+    0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
+    0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
+    0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
+    0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
+    0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
+    0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
+    0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
+    0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
+    0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
+    0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
+    0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
+    0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
+    0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
+    0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
+    0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
+    0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
+    0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
+    0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
+    0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
+    0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
+    0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
+    0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
+    0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
+    0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
+    0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
+    0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
+    0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
+    0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
+    0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
+    0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
+    0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
+    0x9324fd72UL
+  },
+  {
+    0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
+    0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
+    0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
+    0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
+    0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
+    0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
+    0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
+    0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
+    0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
+    0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
+    0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
+    0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
+    0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
+    0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
+    0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
+    0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
+    0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
+    0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
+    0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
+    0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
+    0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
+    0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
+    0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
+    0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
+    0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
+    0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
+    0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
+    0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
+    0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
+    0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
+    0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
+    0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
+    0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
+    0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
+    0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
+    0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
+    0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
+    0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
+    0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
+    0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
+    0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
+    0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
+    0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
+    0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
+    0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
+    0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
+    0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
+    0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
+    0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
+    0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
+    0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
+    0xbe9834edUL
+  },
+  {
+    0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
+    0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
+    0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
+    0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
+    0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
+    0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
+    0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
+    0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
+    0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
+    0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
+    0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
+    0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
+    0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
+    0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
+    0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
+    0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
+    0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
+    0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
+    0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
+    0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
+    0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
+    0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
+    0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
+    0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
+    0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
+    0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
+    0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
+    0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
+    0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
+    0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
+    0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
+    0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
+    0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
+    0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
+    0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
+    0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
+    0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
+    0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
+    0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
+    0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
+    0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
+    0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
+    0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
+    0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
+    0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
+    0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
+    0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
+    0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
+    0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
+    0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
+    0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
+    0xde0506f1UL
+  },
+  {
+    0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
+    0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
+    0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
+    0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
+    0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
+    0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
+    0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
+    0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
+    0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
+    0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
+    0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
+    0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
+    0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
+    0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
+    0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
+    0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
+    0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
+    0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
+    0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
+    0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
+    0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
+    0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
+    0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
+    0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
+    0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
+    0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
+    0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
+    0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
+    0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
+    0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
+    0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
+    0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
+    0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
+    0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
+    0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
+    0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
+    0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
+    0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
+    0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
+    0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
+    0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
+    0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
+    0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
+    0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
+    0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
+    0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
+    0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
+    0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
+    0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
+    0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
+    0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
+    0x8def022dUL
+  },
+  {
+    0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
+    0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
+    0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
+    0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
+    0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
+    0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
+    0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
+    0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
+    0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
+    0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
+    0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
+    0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
+    0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
+    0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
+    0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
+    0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
+    0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
+    0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
+    0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
+    0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
+    0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
+    0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
+    0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
+    0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
+    0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
+    0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
+    0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
+    0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
+    0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
+    0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
+    0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
+    0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
+    0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
+    0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
+    0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
+    0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
+    0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
+    0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
+    0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
+    0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
+    0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
+    0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
+    0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
+    0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
+    0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
+    0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
+    0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
+    0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
+    0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
+    0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
+    0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
+    0x72fd2493UL
+  },
+  {
+    0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
+    0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
+    0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
+    0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
+    0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
+    0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
+    0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
+    0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
+    0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
+    0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
+    0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
+    0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
+    0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
+    0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
+    0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
+    0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
+    0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
+    0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
+    0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
+    0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
+    0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
+    0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
+    0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
+    0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
+    0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
+    0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
+    0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
+    0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
+    0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
+    0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
+    0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
+    0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
+    0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
+    0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
+    0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
+    0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
+    0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
+    0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
+    0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
+    0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
+    0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
+    0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
+    0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
+    0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
+    0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
+    0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
+    0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
+    0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
+    0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
+    0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
+    0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
+    0xed3498beUL
+  },
+  {
+    0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
+    0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
+    0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
+    0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
+    0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
+    0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
+    0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
+    0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
+    0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
+    0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
+    0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
+    0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
+    0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
+    0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
+    0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
+    0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
+    0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
+    0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
+    0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
+    0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
+    0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
+    0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
+    0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
+    0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
+    0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
+    0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
+    0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
+    0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
+    0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
+    0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
+    0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
+    0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
+    0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
+    0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
+    0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
+    0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
+    0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
+    0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
+    0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
+    0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
+    0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
+    0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
+    0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
+    0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
+    0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
+    0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
+    0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
+    0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
+    0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
+    0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
+    0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
+    0xf10605deUL
+#endif
+  }
+};
diff --git a/deps/libchdr/deps/zlib-1.2.11/deflate.c b/deps/libchdr/deps/zlib-1.2.11/deflate.c
new file mode 100644 (file)
index 0000000..1ec7614
--- /dev/null
@@ -0,0 +1,2163 @@
+/* deflate.c -- compress data using the deflation algorithm
+ * Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ *  ALGORITHM
+ *
+ *      The "deflation" process depends on being able to identify portions
+ *      of the input text which are identical to earlier input (within a
+ *      sliding window trailing behind the input currently being processed).
+ *
+ *      The most straightforward technique turns out to be the fastest for
+ *      most input files: try all possible matches and select the longest.
+ *      The key feature of this algorithm is that insertions into the string
+ *      dictionary are very simple and thus fast, and deletions are avoided
+ *      completely. Insertions are performed at each input character, whereas
+ *      string matches are performed only when the previous match ends. So it
+ *      is preferable to spend more time in matches to allow very fast string
+ *      insertions and avoid deletions. The matching algorithm for small
+ *      strings is inspired from that of Rabin & Karp. A brute force approach
+ *      is used to find longer strings when a small match has been found.
+ *      A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
+ *      (by Leonid Broukhis).
+ *         A previous version of this file used a more sophisticated algorithm
+ *      (by Fiala and Greene) which is guaranteed to run in linear amortized
+ *      time, but has a larger average cost, uses more memory and is patented.
+ *      However the F&G algorithm may be faster for some highly redundant
+ *      files if the parameter max_chain_length (described below) is too large.
+ *
+ *  ACKNOWLEDGEMENTS
+ *
+ *      The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
+ *      I found it in 'freeze' written by Leonid Broukhis.
+ *      Thanks to many people for bug reports and testing.
+ *
+ *  REFERENCES
+ *
+ *      Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
+ *      Available in http://tools.ietf.org/html/rfc1951
+ *
+ *      A description of the Rabin and Karp algorithm is given in the book
+ *         "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
+ *
+ *      Fiala,E.R., and Greene,D.H.
+ *         Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
+ *
+ */
+
+/* @(#) $Id$ */
+
+#include "deflate.h"
+
+const char deflate_copyright[] =
+   " deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler ";
+/*
+  If you use the zlib library in a product, an acknowledgment is welcome
+  in the documentation of your product. If for some reason you cannot
+  include such an acknowledgment, I would appreciate that you keep this
+  copyright string in the executable of your product.
+ */
+
+/* ===========================================================================
+ *  Function prototypes.
+ */
+typedef enum {
+    need_more,      /* block not completed, need more input or more output */
+    block_done,     /* block flush performed */
+    finish_started, /* finish started, need only more output at next deflate */
+    finish_done     /* finish done, accept no more input or output */
+} block_state;
+
+typedef block_state (*compress_func) OF((deflate_state *s, int flush));
+/* Compression function. Returns the block state after the call. */
+
+local int deflateStateCheck      OF((z_streamp strm));
+local void slide_hash     OF((deflate_state *s));
+local void fill_window    OF((deflate_state *s));
+local block_state deflate_stored OF((deflate_state *s, int flush));
+local block_state deflate_fast   OF((deflate_state *s, int flush));
+#ifndef FASTEST
+local block_state deflate_slow   OF((deflate_state *s, int flush));
+#endif
+local block_state deflate_rle    OF((deflate_state *s, int flush));
+local block_state deflate_huff   OF((deflate_state *s, int flush));
+local void lm_init        OF((deflate_state *s));
+local void putShortMSB    OF((deflate_state *s, uInt b));
+local void flush_pending  OF((z_streamp strm));
+local unsigned read_buf   OF((z_streamp strm, Bytef *buf, unsigned size));
+#ifdef ASMV
+#  pragma message("Assembler code may have bugs -- use at your own risk")
+      void match_init OF((void)); /* asm code initialization */
+      uInt longest_match  OF((deflate_state *s, IPos cur_match));
+#else
+local uInt longest_match  OF((deflate_state *s, IPos cur_match));
+#endif
+
+#ifdef ZLIB_DEBUG
+local  void check_match OF((deflate_state *s, IPos start, IPos match,
+                            int length));
+#endif
+
+/* ===========================================================================
+ * Local data
+ */
+
+#define NIL 0
+/* Tail of hash chains */
+
+#ifndef TOO_FAR
+#  define TOO_FAR 4096
+#endif
+/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
+
+/* Values for max_lazy_match, good_match and max_chain_length, depending on
+ * the desired pack level (0..9). The values given below have been tuned to
+ * exclude worst case performance for pathological files. Better values may be
+ * found for specific files.
+ */
+typedef struct config_s {
+   ush good_length; /* reduce lazy search above this match length */
+   ush max_lazy;    /* do not perform lazy search above this match length */
+   ush nice_length; /* quit search above this match length */
+   ush max_chain;
+   compress_func func;
+} config;
+
+#ifdef FASTEST
+local const config configuration_table[2] = {
+/*      good lazy nice chain */
+/* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
+/* 1 */ {4,    4,  8,    4, deflate_fast}}; /* max speed, no lazy matches */
+#else
+local const config configuration_table[10] = {
+/*      good lazy nice chain */
+/* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
+/* 1 */ {4,    4,  8,    4, deflate_fast}, /* max speed, no lazy matches */
+/* 2 */ {4,    5, 16,    8, deflate_fast},
+/* 3 */ {4,    6, 32,   32, deflate_fast},
+
+/* 4 */ {4,    4, 16,   16, deflate_slow},  /* lazy matches */
+/* 5 */ {8,   16, 32,   32, deflate_slow},
+/* 6 */ {8,   16, 128, 128, deflate_slow},
+/* 7 */ {8,   32, 128, 256, deflate_slow},
+/* 8 */ {32, 128, 258, 1024, deflate_slow},
+/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
+#endif
+
+/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
+ * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
+ * meaning.
+ */
+
+/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
+#define RANK(f) (((f) * 2) - ((f) > 4 ? 9 : 0))
+
+/* ===========================================================================
+ * Update a hash value with the given input byte
+ * IN  assertion: all calls to UPDATE_HASH are made with consecutive input
+ *    characters, so that a running hash key can be computed from the previous
+ *    key instead of complete recalculation each time.
+ */
+#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
+
+
+/* ===========================================================================
+ * Insert string str in the dictionary and set match_head to the previous head
+ * of the hash chain (the most recent string with same hash key). Return
+ * the previous length of the hash chain.
+ * If this file is compiled with -DFASTEST, the compression level is forced
+ * to 1, and no hash chains are maintained.
+ * IN  assertion: all calls to INSERT_STRING are made with consecutive input
+ *    characters and the first MIN_MATCH bytes of str are valid (except for
+ *    the last MIN_MATCH-1 bytes of the input file).
+ */
+#ifdef FASTEST
+#define INSERT_STRING(s, str, match_head) \
+   (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
+    match_head = s->head[s->ins_h], \
+    s->head[s->ins_h] = (Pos)(str))
+#else
+#define INSERT_STRING(s, str, match_head) \
+   (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
+    match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
+    s->head[s->ins_h] = (Pos)(str))
+#endif
+
+/* ===========================================================================
+ * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
+ * prev[] will be initialized on the fly.
+ */
+#define CLEAR_HASH(s) \
+    s->head[s->hash_size-1] = NIL; \
+    zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
+
+/* ===========================================================================
+ * Slide the hash table when sliding the window down (could be avoided with 32
+ * bit values at the expense of memory usage). We slide even when level == 0 to
+ * keep the hash table consistent if we switch back to level > 0 later.
+ */
+local void slide_hash(s)
+    deflate_state *s;
+{
+    unsigned n, m;
+    Posf *p;
+    uInt wsize = s->w_size;
+
+    n = s->hash_size;
+    p = &s->head[n];
+    do {
+        m = *--p;
+        *p = (Pos)(m >= wsize ? m - wsize : NIL);
+    } while (--n);
+    n = wsize;
+#ifndef FASTEST
+    p = &s->prev[n];
+    do {
+        m = *--p;
+        *p = (Pos)(m >= wsize ? m - wsize : NIL);
+        /* If n is not on any hash chain, prev[n] is garbage but
+         * its value will never be used.
+         */
+    } while (--n);
+#endif
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateInit_(strm, level, version, stream_size)
+    z_streamp strm;
+    int level;
+    const char *version;
+    int stream_size;
+{
+    return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
+                         Z_DEFAULT_STRATEGY, version, stream_size);
+    /* To do: ignore strm->next_in if we use it as window */
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
+                  version, stream_size)
+    z_streamp strm;
+    int  level;
+    int  method;
+    int  windowBits;
+    int  memLevel;
+    int  strategy;
+    const char *version;
+    int stream_size;
+{
+    deflate_state *s;
+    int wrap = 1;
+    static const char my_version[] = ZLIB_VERSION;
+
+    ushf *overlay;
+    /* We overlay pending_buf and d_buf+l_buf. This works since the average
+     * output size for (length,distance) codes is <= 24 bits.
+     */
+
+    if (version == Z_NULL || version[0] != my_version[0] ||
+        stream_size != sizeof(z_stream)) {
+        return Z_VERSION_ERROR;
+    }
+    if (strm == Z_NULL) return Z_STREAM_ERROR;
+
+    strm->msg = Z_NULL;
+    if (strm->zalloc == (alloc_func)0) {
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
+        strm->zalloc = zcalloc;
+        strm->opaque = (voidpf)0;
+#endif
+    }
+    if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
+        strm->zfree = zcfree;
+#endif
+
+#ifdef FASTEST
+    if (level != 0) level = 1;
+#else
+    if (level == Z_DEFAULT_COMPRESSION) level = 6;
+#endif
+
+    if (windowBits < 0) { /* suppress zlib wrapper */
+        wrap = 0;
+        windowBits = -windowBits;
+    }
+#ifdef GZIP
+    else if (windowBits > 15) {
+        wrap = 2;       /* write gzip wrapper instead */
+        windowBits -= 16;
+    }
+#endif
+    if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
+        windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
+        strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) {
+        return Z_STREAM_ERROR;
+    }
+    if (windowBits == 8) windowBits = 9;  /* until 256-byte window bug fixed */
+    s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
+    if (s == Z_NULL) return Z_MEM_ERROR;
+    strm->state = (struct internal_state FAR *)s;
+    s->strm = strm;
+    s->status = INIT_STATE;     /* to pass state test in deflateReset() */
+
+    s->wrap = wrap;
+    s->gzhead = Z_NULL;
+    s->w_bits = (uInt)windowBits;
+    s->w_size = 1 << s->w_bits;
+    s->w_mask = s->w_size - 1;
+
+    s->hash_bits = (uInt)memLevel + 7;
+    s->hash_size = 1 << s->hash_bits;
+    s->hash_mask = s->hash_size - 1;
+    s->hash_shift =  ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
+
+    s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
+    s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
+    s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));
+
+    s->high_water = 0;      /* nothing written to s->window yet */
+
+    s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
+
+    overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
+    s->pending_buf = (uchf *) overlay;
+    s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
+
+    if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
+        s->pending_buf == Z_NULL) {
+        s->status = FINISH_STATE;
+        strm->msg = ERR_MSG(Z_MEM_ERROR);
+        deflateEnd (strm);
+        return Z_MEM_ERROR;
+    }
+    s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
+    s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
+
+    s->level = level;
+    s->strategy = strategy;
+    s->method = (Byte)method;
+
+    return deflateReset(strm);
+}
+
+/* =========================================================================
+ * Check for a valid deflate stream state. Return 0 if ok, 1 if not.
+ */
+local int deflateStateCheck (strm)
+    z_streamp strm;
+{
+    deflate_state *s;
+    if (strm == Z_NULL ||
+        strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
+        return 1;
+    s = strm->state;
+    if (s == Z_NULL || s->strm != strm || (s->status != INIT_STATE &&
+#ifdef GZIP
+                                           s->status != GZIP_STATE &&
+#endif
+                                           s->status != EXTRA_STATE &&
+                                           s->status != NAME_STATE &&
+                                           s->status != COMMENT_STATE &&
+                                           s->status != HCRC_STATE &&
+                                           s->status != BUSY_STATE &&
+                                           s->status != FINISH_STATE))
+        return 1;
+    return 0;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
+    z_streamp strm;
+    const Bytef *dictionary;
+    uInt  dictLength;
+{
+    deflate_state *s;
+    uInt str, n;
+    int wrap;
+    unsigned avail;
+    z_const unsigned char *next;
+
+    if (deflateStateCheck(strm) || dictionary == Z_NULL)
+        return Z_STREAM_ERROR;
+    s = strm->state;
+    wrap = s->wrap;
+    if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
+        return Z_STREAM_ERROR;
+
+    /* when using zlib wrappers, compute Adler-32 for provided dictionary */
+    if (wrap == 1)
+        strm->adler = adler32(strm->adler, dictionary, dictLength);
+    s->wrap = 0;                    /* avoid computing Adler-32 in read_buf */
+
+    /* if dictionary would fill window, just replace the history */
+    if (dictLength >= s->w_size) {
+        if (wrap == 0) {            /* already empty otherwise */
+            CLEAR_HASH(s);
+            s->strstart = 0;
+            s->block_start = 0L;
+            s->insert = 0;
+        }
+        dictionary += dictLength - s->w_size;  /* use the tail */
+        dictLength = s->w_size;
+    }
+
+    /* insert dictionary into window and hash */
+    avail = strm->avail_in;
+    next = strm->next_in;
+    strm->avail_in = dictLength;
+    strm->next_in = (z_const Bytef *)dictionary;
+    fill_window(s);
+    while (s->lookahead >= MIN_MATCH) {
+        str = s->strstart;
+        n = s->lookahead - (MIN_MATCH-1);
+        do {
+            UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
+#ifndef FASTEST
+            s->prev[str & s->w_mask] = s->head[s->ins_h];
+#endif
+            s->head[s->ins_h] = (Pos)str;
+            str++;
+        } while (--n);
+        s->strstart = str;
+        s->lookahead = MIN_MATCH-1;
+        fill_window(s);
+    }
+    s->strstart += s->lookahead;
+    s->block_start = (long)s->strstart;
+    s->insert = s->lookahead;
+    s->lookahead = 0;
+    s->match_length = s->prev_length = MIN_MATCH-1;
+    s->match_available = 0;
+    strm->next_in = next;
+    strm->avail_in = avail;
+    s->wrap = wrap;
+    return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength)
+    z_streamp strm;
+    Bytef *dictionary;
+    uInt  *dictLength;
+{
+    deflate_state *s;
+    uInt len;
+
+    if (deflateStateCheck(strm))
+        return Z_STREAM_ERROR;
+    s = strm->state;
+    len = s->strstart + s->lookahead;
+    if (len > s->w_size)
+        len = s->w_size;
+    if (dictionary != Z_NULL && len)
+        zmemcpy(dictionary, s->window + s->strstart + s->lookahead - len, len);
+    if (dictLength != Z_NULL)
+        *dictLength = len;
+    return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateResetKeep (strm)
+    z_streamp strm;
+{
+    deflate_state *s;
+
+    if (deflateStateCheck(strm)) {
+        return Z_STREAM_ERROR;
+    }
+
+    strm->total_in = strm->total_out = 0;
+    strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
+    strm->data_type = Z_UNKNOWN;
+
+    s = (deflate_state *)strm->state;
+    s->pending = 0;
+    s->pending_out = s->pending_buf;
+
+    if (s->wrap < 0) {
+        s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
+    }
+    s->status =
+#ifdef GZIP
+        s->wrap == 2 ? GZIP_STATE :
+#endif
+        s->wrap ? INIT_STATE : BUSY_STATE;
+    strm->adler =
+#ifdef GZIP
+        s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
+#endif
+        adler32(0L, Z_NULL, 0);
+    s->last_flush = Z_NO_FLUSH;
+
+    _tr_init(s);
+
+    return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateReset (strm)
+    z_streamp strm;
+{
+    int ret;
+
+    ret = deflateResetKeep(strm);
+    if (ret == Z_OK)
+        lm_init(strm->state);
+    return ret;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateSetHeader (strm, head)
+    z_streamp strm;
+    gz_headerp head;
+{
+    if (deflateStateCheck(strm) || strm->state->wrap != 2)
+        return Z_STREAM_ERROR;
+    strm->state->gzhead = head;
+    return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflatePending (strm, pending, bits)
+    unsigned *pending;
+    int *bits;
+    z_streamp strm;
+{
+    if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
+    if (pending != Z_NULL)
+        *pending = strm->state->pending;
+    if (bits != Z_NULL)
+        *bits = strm->state->bi_valid;
+    return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflatePrime (strm, bits, value)
+    z_streamp strm;
+    int bits;
+    int value;
+{
+    deflate_state *s;
+    int put;
+
+    if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
+    s = strm->state;
+    if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
+        return Z_BUF_ERROR;
+    do {
+        put = Buf_size - s->bi_valid;
+        if (put > bits)
+            put = bits;
+        s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
+        s->bi_valid += put;
+        _tr_flush_bits(s);
+        value >>= put;
+        bits -= put;
+    } while (bits);
+    return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateParams(strm, level, strategy)
+    z_streamp strm;
+    int level;
+    int strategy;
+{
+    deflate_state *s;
+    compress_func func;
+
+    if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
+    s = strm->state;
+
+#ifdef FASTEST
+    if (level != 0) level = 1;
+#else
+    if (level == Z_DEFAULT_COMPRESSION) level = 6;
+#endif
+    if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
+        return Z_STREAM_ERROR;
+    }
+    func = configuration_table[s->level].func;
+
+    if ((strategy != s->strategy || func != configuration_table[level].func) &&
+        s->high_water) {
+        /* Flush the last buffer: */
+        int err = deflate(strm, Z_BLOCK);
+        if (err == Z_STREAM_ERROR)
+            return err;
+        if (strm->avail_out == 0)
+            return Z_BUF_ERROR;
+    }
+    if (s->level != level) {
+        if (s->level == 0 && s->matches != 0) {
+            if (s->matches == 1)
+                slide_hash(s);
+            else
+                CLEAR_HASH(s);
+            s->matches = 0;
+        }
+        s->level = level;
+        s->max_lazy_match   = configuration_table[level].max_lazy;
+        s->good_match       = configuration_table[level].good_length;
+        s->nice_match       = configuration_table[level].nice_length;
+        s->max_chain_length = configuration_table[level].max_chain;
+    }
+    s->strategy = strategy;
+    return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
+    z_streamp strm;
+    int good_length;
+    int max_lazy;
+    int nice_length;
+    int max_chain;
+{
+    deflate_state *s;
+
+    if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
+    s = strm->state;
+    s->good_match = (uInt)good_length;
+    s->max_lazy_match = (uInt)max_lazy;
+    s->nice_match = nice_length;
+    s->max_chain_length = (uInt)max_chain;
+    return Z_OK;
+}
+
+/* =========================================================================
+ * For the default windowBits of 15 and memLevel of 8, this function returns
+ * a close to exact, as well as small, upper bound on the compressed size.
+ * They are coded as constants here for a reason--if the #define's are
+ * changed, then this function needs to be changed as well.  The return
+ * value for 15 and 8 only works for those exact settings.
+ *
+ * For any setting other than those defaults for windowBits and memLevel,
+ * the value returned is a conservative worst case for the maximum expansion
+ * resulting from using fixed blocks instead of stored blocks, which deflate
+ * can emit on compressed data for some combinations of the parameters.
+ *
+ * This function could be more sophisticated to provide closer upper bounds for
+ * every combination of windowBits and memLevel.  But even the conservative
+ * upper bound of about 14% expansion does not seem onerous for output buffer
+ * allocation.
+ */
+uLong ZEXPORT deflateBound(strm, sourceLen)
+    z_streamp strm;
+    uLong sourceLen;
+{
+    deflate_state *s;
+    uLong complen, wraplen;
+
+    /* conservative upper bound for compressed data */
+    complen = sourceLen +
+              ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
+
+    /* if can't get parameters, return conservative bound plus zlib wrapper */
+    if (deflateStateCheck(strm))
+        return complen + 6;
+
+    /* compute wrapper length */
+    s = strm->state;
+    switch (s->wrap) {
+    case 0:                                 /* raw deflate */
+        wraplen = 0;
+        break;
+    case 1:                                 /* zlib wrapper */
+        wraplen = 6 + (s->strstart ? 4 : 0);
+        break;
+#ifdef GZIP
+    case 2:                                 /* gzip wrapper */
+        wraplen = 18;
+        if (s->gzhead != Z_NULL) {          /* user-supplied gzip header */
+            Bytef *str;
+            if (s->gzhead->extra != Z_NULL)
+                wraplen += 2 + s->gzhead->extra_len;
+            str = s->gzhead->name;
+            if (str != Z_NULL)
+                do {
+                    wraplen++;
+                } while (*str++);
+            str = s->gzhead->comment;
+            if (str != Z_NULL)
+                do {
+                    wraplen++;
+                } while (*str++);
+            if (s->gzhead->hcrc)
+                wraplen += 2;
+        }
+        break;
+#endif
+    default:                                /* for compiler happiness */
+        wraplen = 6;
+    }
+
+    /* if not default parameters, return conservative bound */
+    if (s->w_bits != 15 || s->hash_bits != 8 + 7)
+        return complen + wraplen;
+
+    /* default settings: return tight bound for that case */
+    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
+           (sourceLen >> 25) + 13 - 6 + wraplen;
+}
+
+/* =========================================================================
+ * Put a short in the pending buffer. The 16-bit value is put in MSB order.
+ * IN assertion: the stream state is correct and there is enough room in
+ * pending_buf.
+ */
+local void putShortMSB (s, b)
+    deflate_state *s;
+    uInt b;
+{
+    put_byte(s, (Byte)(b >> 8));
+    put_byte(s, (Byte)(b & 0xff));
+}
+
+/* =========================================================================
+ * Flush as much pending output as possible. All deflate() output, except for
+ * some deflate_stored() output, goes through this function so some
+ * applications may wish to modify it to avoid allocating a large
+ * strm->next_out buffer and copying into it. (See also read_buf()).
+ */
+local void flush_pending(strm)
+    z_streamp strm;
+{
+    unsigned len;
+    deflate_state *s = strm->state;
+
+    _tr_flush_bits(s);
+    len = s->pending;
+    if (len > strm->avail_out) len = strm->avail_out;
+    if (len == 0) return;
+
+    zmemcpy(strm->next_out, s->pending_out, len);
+    strm->next_out  += len;
+    s->pending_out  += len;
+    strm->total_out += len;
+    strm->avail_out -= len;
+    s->pending      -= len;
+    if (s->pending == 0) {
+        s->pending_out = s->pending_buf;
+    }
+}
+
+/* ===========================================================================
+ * Update the header CRC with the bytes s->pending_buf[beg..s->pending - 1].
+ */
+#define HCRC_UPDATE(beg) \
+    do { \
+        if (s->gzhead->hcrc && s->pending > (beg)) \
+            strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
+                                s->pending - (beg)); \
+    } while (0)
+
+/* ========================================================================= */
+int ZEXPORT deflate (strm, flush)
+    z_streamp strm;
+    int flush;
+{
+    int old_flush; /* value of flush param for previous deflate call */
+    deflate_state *s;
+
+    if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
+        return Z_STREAM_ERROR;
+    }
+    s = strm->state;
+
+    if (strm->next_out == Z_NULL ||
+        (strm->avail_in != 0 && strm->next_in == Z_NULL) ||
+        (s->status == FINISH_STATE && flush != Z_FINISH)) {
+        ERR_RETURN(strm, Z_STREAM_ERROR);
+    }
+    if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
+
+    old_flush = s->last_flush;
+    s->last_flush = flush;
+
+    /* Flush as much pending output as possible */
+    if (s->pending != 0) {
+        flush_pending(strm);
+        if (strm->avail_out == 0) {
+            /* Since avail_out is 0, deflate will be called again with
+             * more output space, but possibly with both pending and
+             * avail_in equal to zero. There won't be anything to do,
+             * but this is not an error situation so make sure we
+             * return OK instead of BUF_ERROR at next call of deflate:
+             */
+            s->last_flush = -1;
+            return Z_OK;
+        }
+
+    /* Make sure there is something to do and avoid duplicate consecutive
+     * flushes. For repeated and useless calls with Z_FINISH, we keep
+     * returning Z_STREAM_END instead of Z_BUF_ERROR.
+     */
+    } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
+               flush != Z_FINISH) {
+        ERR_RETURN(strm, Z_BUF_ERROR);
+    }
+
+    /* User must not provide more input after the first FINISH: */
+    if (s->status == FINISH_STATE && strm->avail_in != 0) {
+        ERR_RETURN(strm, Z_BUF_ERROR);
+    }
+
+    /* Write the header */
+    if (s->status == INIT_STATE) {
+        /* zlib header */
+        uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
+        uInt level_flags;
+
+        if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
+            level_flags = 0;
+        else if (s->level < 6)
+            level_flags = 1;
+        else if (s->level == 6)
+            level_flags = 2;
+        else
+            level_flags = 3;
+        header |= (level_flags << 6);
+        if (s->strstart != 0) header |= PRESET_DICT;
+        header += 31 - (header % 31);
+
+        putShortMSB(s, header);
+
+        /* Save the adler32 of the preset dictionary: */
+        if (s->strstart != 0) {
+            putShortMSB(s, (uInt)(strm->adler >> 16));
+            putShortMSB(s, (uInt)(strm->adler & 0xffff));
+        }
+        strm->adler = adler32(0L, Z_NULL, 0);
+        s->status = BUSY_STATE;
+
+        /* Compression must start with an empty pending buffer */
+        flush_pending(strm);
+        if (s->pending != 0) {
+            s->last_flush = -1;
+            return Z_OK;
+        }
+    }
+#ifdef GZIP
+    if (s->status == GZIP_STATE) {
+        /* gzip header */
+        strm->adler = crc32(0L, Z_NULL, 0);
+        put_byte(s, 31);
+        put_byte(s, 139);
+        put_byte(s, 8);
+        if (s->gzhead == Z_NULL) {
+            put_byte(s, 0);
+            put_byte(s, 0);
+            put_byte(s, 0);
+            put_byte(s, 0);
+            put_byte(s, 0);
+            put_byte(s, s->level == 9 ? 2 :
+                     (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+                      4 : 0));
+            put_byte(s, OS_CODE);
+            s->status = BUSY_STATE;
+
+            /* Compression must start with an empty pending buffer */
+            flush_pending(strm);
+            if (s->pending != 0) {
+                s->last_flush = -1;
+                return Z_OK;
+            }
+        }
+        else {
+            put_byte(s, (s->gzhead->text ? 1 : 0) +
+                     (s->gzhead->hcrc ? 2 : 0) +
+                     (s->gzhead->extra == Z_NULL ? 0 : 4) +
+                     (s->gzhead->name == Z_NULL ? 0 : 8) +
+                     (s->gzhead->comment == Z_NULL ? 0 : 16)
+                     );
+            put_byte(s, (Byte)(s->gzhead->time & 0xff));
+            put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
+            put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
+            put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
+            put_byte(s, s->level == 9 ? 2 :
+                     (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+                      4 : 0));
+            put_byte(s, s->gzhead->os & 0xff);
+            if (s->gzhead->extra != Z_NULL) {
+                put_byte(s, s->gzhead->extra_len & 0xff);
+                put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
+            }
+            if (s->gzhead->hcrc)
+                strm->adler = crc32(strm->adler, s->pending_buf,
+                                    s->pending);
+            s->gzindex = 0;
+            s->status = EXTRA_STATE;
+        }
+    }
+    if (s->status == EXTRA_STATE) {
+        if (s->gzhead->extra != Z_NULL) {
+            ulg beg = s->pending;   /* start of bytes to update crc */
+            uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex;
+            while (s->pending + left > s->pending_buf_size) {
+                uInt copy = s->pending_buf_size - s->pending;
+                zmemcpy(s->pending_buf + s->pending,
+                        s->gzhead->extra + s->gzindex, copy);
+                s->pending = s->pending_buf_size;
+                HCRC_UPDATE(beg);
+                s->gzindex += copy;
+                flush_pending(strm);
+                if (s->pending != 0) {
+                    s->last_flush = -1;
+                    return Z_OK;
+                }
+                beg = 0;
+                left -= copy;
+            }
+            zmemcpy(s->pending_buf + s->pending,
+                    s->gzhead->extra + s->gzindex, left);
+            s->pending += left;
+            HCRC_UPDATE(beg);
+            s->gzindex = 0;
+        }
+        s->status = NAME_STATE;
+    }
+    if (s->status == NAME_STATE) {
+        if (s->gzhead->name != Z_NULL) {
+            ulg beg = s->pending;   /* start of bytes to update crc */
+            int val;
+            do {
+                if (s->pending == s->pending_buf_size) {
+                    HCRC_UPDATE(beg);
+                    flush_pending(strm);
+                    if (s->pending != 0) {
+                        s->last_flush = -1;
+                        return Z_OK;
+                    }
+                    beg = 0;
+                }
+                val = s->gzhead->name[s->gzindex++];
+                put_byte(s, val);
+            } while (val != 0);
+            HCRC_UPDATE(beg);
+            s->gzindex = 0;
+        }
+        s->status = COMMENT_STATE;
+    }
+    if (s->status == COMMENT_STATE) {
+        if (s->gzhead->comment != Z_NULL) {
+            ulg beg = s->pending;   /* start of bytes to update crc */
+            int val;
+            do {
+                if (s->pending == s->pending_buf_size) {
+                    HCRC_UPDATE(beg);
+                    flush_pending(strm);
+                    if (s->pending != 0) {
+                        s->last_flush = -1;
+                        return Z_OK;
+                    }
+                    beg = 0;
+                }
+                val = s->gzhead->comment[s->gzindex++];
+                put_byte(s, val);
+            } while (val != 0);
+            HCRC_UPDATE(beg);
+        }
+        s->status = HCRC_STATE;
+    }
+    if (s->status == HCRC_STATE) {
+        if (s->gzhead->hcrc) {
+            if (s->pending + 2 > s->pending_buf_size) {
+                flush_pending(strm);
+                if (s->pending != 0) {
+                    s->last_flush = -1;
+                    return Z_OK;
+                }
+            }
+            put_byte(s, (Byte)(strm->adler & 0xff));
+            put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
+            strm->adler = crc32(0L, Z_NULL, 0);
+        }
+        s->status = BUSY_STATE;
+
+        /* Compression must start with an empty pending buffer */
+        flush_pending(strm);
+        if (s->pending != 0) {
+            s->last_flush = -1;
+            return Z_OK;
+        }
+    }
+#endif
+
+    /* Start a new block or continue the current one.
+     */
+    if (strm->avail_in != 0 || s->lookahead != 0 ||
+        (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
+        block_state bstate;
+
+        bstate = s->level == 0 ? deflate_stored(s, flush) :
+                 s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
+                 s->strategy == Z_RLE ? deflate_rle(s, flush) :
+                 (*(configuration_table[s->level].func))(s, flush);
+
+        if (bstate == finish_started || bstate == finish_done) {
+            s->status = FINISH_STATE;
+        }
+        if (bstate == need_more || bstate == finish_started) {
+            if (strm->avail_out == 0) {
+                s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
+            }
+            return Z_OK;
+            /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
+             * of deflate should use the same flush parameter to make sure
+             * that the flush is complete. So we don't have to output an
+             * empty block here, this will be done at next call. This also
+             * ensures that for a very small output buffer, we emit at most
+             * one empty block.
+             */
+        }
+        if (bstate == block_done) {
+            if (flush == Z_PARTIAL_FLUSH) {
+                _tr_align(s);
+            } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
+                _tr_stored_block(s, (char*)0, 0L, 0);
+                /* For a full flush, this empty block will be recognized
+                 * as a special marker by inflate_sync().
+                 */
+                if (flush == Z_FULL_FLUSH) {
+                    CLEAR_HASH(s);             /* forget history */
+                    if (s->lookahead == 0) {
+                        s->strstart = 0;
+                        s->block_start = 0L;
+                        s->insert = 0;
+                    }
+                }
+            }
+            flush_pending(strm);
+            if (strm->avail_out == 0) {
+              s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
+              return Z_OK;
+            }
+        }
+    }
+
+    if (flush != Z_FINISH) return Z_OK;
+    if (s->wrap <= 0) return Z_STREAM_END;
+
+    /* Write the trailer */
+#ifdef GZIP
+    if (s->wrap == 2) {
+        put_byte(s, (Byte)(strm->adler & 0xff));
+        put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
+        put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
+        put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
+        put_byte(s, (Byte)(strm->total_in & 0xff));
+        put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
+        put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
+        put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
+    }
+    else
+#endif
+    {
+        putShortMSB(s, (uInt)(strm->adler >> 16));
+        putShortMSB(s, (uInt)(strm->adler & 0xffff));
+    }
+    flush_pending(strm);
+    /* If avail_out is zero, the application will call deflate again
+     * to flush the rest.
+     */
+    if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
+    return s->pending != 0 ? Z_OK : Z_STREAM_END;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateEnd (strm)
+    z_streamp strm;
+{
+    int status;
+
+    if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
+
+    status = strm->state->status;
+
+    /* Deallocate in reverse order of allocations: */
+    TRY_FREE(strm, strm->state->pending_buf);
+    TRY_FREE(strm, strm->state->head);
+    TRY_FREE(strm, strm->state->prev);
+    TRY_FREE(strm, strm->state->window);
+
+    ZFREE(strm, strm->state);
+    strm->state = Z_NULL;
+
+    return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
+}
+
+/* =========================================================================
+ * Copy the source state to the destination state.
+ * To simplify the source, this is not supported for 16-bit MSDOS (which
+ * doesn't have enough memory anyway to duplicate compression states).
+ */
+int ZEXPORT deflateCopy (dest, source)
+    z_streamp dest;
+    z_streamp source;
+{
+#ifdef MAXSEG_64K
+    return Z_STREAM_ERROR;
+#else
+    deflate_state *ds;
+    deflate_state *ss;
+    ushf *overlay;
+
+
+    if (deflateStateCheck(source) || dest == Z_NULL) {
+        return Z_STREAM_ERROR;
+    }
+
+    ss = source->state;
+
+    zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
+
+    ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
+    if (ds == Z_NULL) return Z_MEM_ERROR;
+    dest->state = (struct internal_state FAR *) ds;
+    zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
+    ds->strm = dest;
+
+    ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
+    ds->prev   = (Posf *)  ZALLOC(dest, ds->w_size, sizeof(Pos));
+    ds->head   = (Posf *)  ZALLOC(dest, ds->hash_size, sizeof(Pos));
+    overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
+    ds->pending_buf = (uchf *) overlay;
+
+    if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
+        ds->pending_buf == Z_NULL) {
+        deflateEnd (dest);
+        return Z_MEM_ERROR;
+    }
+    /* following zmemcpy do not work for 16-bit MSDOS */
+    zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
+    zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
+    zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
+    zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
+
+    ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
+    ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
+    ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
+
+    ds->l_desc.dyn_tree = ds->dyn_ltree;
+    ds->d_desc.dyn_tree = ds->dyn_dtree;
+    ds->bl_desc.dyn_tree = ds->bl_tree;
+
+    return Z_OK;
+#endif /* MAXSEG_64K */
+}
+
+/* ===========================================================================
+ * Read a new buffer from the current input stream, update the adler32
+ * and total number of bytes read.  All deflate() input goes through
+ * this function so some applications may wish to modify it to avoid
+ * allocating a large strm->next_in buffer and copying from it.
+ * (See also flush_pending()).
+ */
+local unsigned read_buf(strm, buf, size)
+    z_streamp strm;
+    Bytef *buf;
+    unsigned size;
+{
+    unsigned len = strm->avail_in;
+
+    if (len > size) len = size;
+    if (len == 0) return 0;
+
+    strm->avail_in  -= len;
+
+    zmemcpy(buf, strm->next_in, len);
+    if (strm->state->wrap == 1) {
+        strm->adler = adler32(strm->adler, buf, len);
+    }
+#ifdef GZIP
+    else if (strm->state->wrap == 2) {
+        strm->adler = crc32(strm->adler, buf, len);
+    }
+#endif
+    strm->next_in  += len;
+    strm->total_in += len;
+
+    return len;
+}
+
+/* ===========================================================================
+ * Initialize the "longest match" routines for a new zlib stream
+ */
+local void lm_init (s)
+    deflate_state *s;
+{
+    s->window_size = (ulg)2L*s->w_size;
+
+    CLEAR_HASH(s);
+
+    /* Set the default configuration parameters:
+     */
+    s->max_lazy_match   = configuration_table[s->level].max_lazy;
+    s->good_match       = configuration_table[s->level].good_length;
+    s->nice_match       = configuration_table[s->level].nice_length;
+    s->max_chain_length = configuration_table[s->level].max_chain;
+
+    s->strstart = 0;
+    s->block_start = 0L;
+    s->lookahead = 0;
+    s->insert = 0;
+    s->match_length = s->prev_length = MIN_MATCH-1;
+    s->match_available = 0;
+    s->ins_h = 0;
+#ifndef FASTEST
+#ifdef ASMV
+    match_init(); /* initialize the asm code */
+#endif
+#endif
+}
+
+#ifndef FASTEST
+/* ===========================================================================
+ * Set match_start to the longest match starting at the given string and
+ * return its length. Matches shorter or equal to prev_length are discarded,
+ * in which case the result is equal to prev_length and match_start is
+ * garbage.
+ * IN assertions: cur_match is the head of the hash chain for the current
+ *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
+ * OUT assertion: the match length is not greater than s->lookahead.
+ */
+#ifndef ASMV
+/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
+ * match.S. The code will be functionally equivalent.
+ */
+local uInt longest_match(s, cur_match)
+    deflate_state *s;
+    IPos cur_match;                             /* current match */
+{
+    unsigned chain_length = s->max_chain_length;/* max hash chain length */
+    register Bytef *scan = s->window + s->strstart; /* current string */
+    register Bytef *match;                      /* matched string */
+    register int len;                           /* length of current match */
+    int best_len = (int)s->prev_length;         /* best match length so far */
+    int nice_match = s->nice_match;             /* stop if match long enough */
+    IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
+        s->strstart - (IPos)MAX_DIST(s) : NIL;
+    /* Stop when cur_match becomes <= limit. To simplify the code,
+     * we prevent matches with the string of window index 0.
+     */
+    Posf *prev = s->prev;
+    uInt wmask = s->w_mask;
+
+#ifdef UNALIGNED_OK
+    /* Compare two bytes at a time. Note: this is not always beneficial.
+     * Try with and without -DUNALIGNED_OK to check.
+     */
+    register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
+    register ush scan_start = *(ushf*)scan;
+    register ush scan_end   = *(ushf*)(scan+best_len-1);
+#else
+    register Bytef *strend = s->window + s->strstart + MAX_MATCH;
+    register Byte scan_end1  = scan[best_len-1];
+    register Byte scan_end   = scan[best_len];
+#endif
+
+    /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
+     * It is easy to get rid of this optimization if necessary.
+     */
+    Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+
+    /* Do not waste too much time if we already have a good match: */
+    if (s->prev_length >= s->good_match) {
+        chain_length >>= 2;
+    }
+    /* Do not look for matches beyond the end of the input. This is necessary
+     * to make deflate deterministic.
+     */
+    if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead;
+
+    Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+
+    do {
+        Assert(cur_match < s->strstart, "no future");
+        match = s->window + cur_match;
+
+        /* Skip to next match if the match length cannot increase
+         * or if the match length is less than 2.  Note that the checks below
+         * for insufficient lookahead only occur occasionally for performance
+         * reasons.  Therefore uninitialized memory will be accessed, and
+         * conditional jumps will be made that depend on those values.
+         * However the length of the match is limited to the lookahead, so
+         * the output of deflate is not affected by the uninitialized values.
+         */
+#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
+        /* This code assumes sizeof(unsigned short) == 2. Do not use
+         * UNALIGNED_OK if your compiler uses a different size.
+         */
+        if (*(ushf*)(match+best_len-1) != scan_end ||
+            *(ushf*)match != scan_start) continue;
+
+        /* It is not necessary to compare scan[2] and match[2] since they are
+         * always equal when the other bytes match, given that the hash keys
+         * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
+         * strstart+3, +5, ... up to strstart+257. We check for insufficient
+         * lookahead only every 4th comparison; the 128th check will be made
+         * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
+         * necessary to put more guard bytes at the end of the window, or
+         * to check more often for insufficient lookahead.
+         */
+        Assert(scan[2] == match[2], "scan[2]?");
+        scan++, match++;
+        do {
+        } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+                 scan < strend);
+        /* The funny "do {}" generates better code on most compilers */
+
+        /* Here, scan <= window+strstart+257 */
+        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+        if (*scan == *match) scan++;
+
+        len = (MAX_MATCH - 1) - (int)(strend-scan);
+        scan = strend - (MAX_MATCH-1);
+
+#else /* UNALIGNED_OK */
+
+        if (match[best_len]   != scan_end  ||
+            match[best_len-1] != scan_end1 ||
+            *match            != *scan     ||
+            *++match          != scan[1])      continue;
+
+        /* The check at best_len-1 can be removed because it will be made
+         * again later. (This heuristic is not always a win.)
+         * It is not necessary to compare scan[2] and match[2] since they
+         * are always equal when the other bytes match, given that
+         * the hash keys are equal and that HASH_BITS >= 8.
+         */
+        scan += 2, match++;
+        Assert(*scan == *match, "match[2]?");
+
+        /* We check for insufficient lookahead only every 8th comparison;
+         * the 256th check will be made at strstart+258.
+         */
+        do {
+        } while (*++scan == *++match && *++scan == *++match &&
+                 *++scan == *++match && *++scan == *++match &&
+                 *++scan == *++match && *++scan == *++match &&
+                 *++scan == *++match && *++scan == *++match &&
+                 scan < strend);
+
+        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+
+        len = MAX_MATCH - (int)(strend - scan);
+        scan = strend - MAX_MATCH;
+
+#endif /* UNALIGNED_OK */
+
+        if (len > best_len) {
+            s->match_start = cur_match;
+            best_len = len;
+            if (len >= nice_match) break;
+#ifdef UNALIGNED_OK
+            scan_end = *(ushf*)(scan+best_len-1);
+#else
+            scan_end1  = scan[best_len-1];
+            scan_end   = scan[best_len];
+#endif
+        }
+    } while ((cur_match = prev[cur_match & wmask]) > limit
+             && --chain_length != 0);
+
+    if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
+    return s->lookahead;
+}
+#endif /* ASMV */
+
+#else /* FASTEST */
+
+/* ---------------------------------------------------------------------------
+ * Optimized version for FASTEST only
+ */
+local uInt longest_match(s, cur_match)
+    deflate_state *s;
+    IPos cur_match;                             /* current match */
+{
+    register Bytef *scan = s->window + s->strstart; /* current string */
+    register Bytef *match;                       /* matched string */
+    register int len;                           /* length of current match */
+    register Bytef *strend = s->window + s->strstart + MAX_MATCH;
+
+    /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
+     * It is easy to get rid of this optimization if necessary.
+     */
+    Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+
+    Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+
+    Assert(cur_match < s->strstart, "no future");
+
+    match = s->window + cur_match;
+
+    /* Return failure if the match length is less than 2:
+     */
+    if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
+
+    /* The check at best_len-1 can be removed because it will be made
+     * again later. (This heuristic is not always a win.)
+     * It is not necessary to compare scan[2] and match[2] since they
+     * are always equal when the other bytes match, given that
+     * the hash keys are equal and that HASH_BITS >= 8.
+     */
+    scan += 2, match += 2;
+    Assert(*scan == *match, "match[2]?");
+
+    /* We check for insufficient lookahead only every 8th comparison;
+     * the 256th check will be made at strstart+258.
+     */
+    do {
+    } while (*++scan == *++match && *++scan == *++match &&
+             *++scan == *++match && *++scan == *++match &&
+             *++scan == *++match && *++scan == *++match &&
+             *++scan == *++match && *++scan == *++match &&
+             scan < strend);
+
+    Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+
+    len = MAX_MATCH - (int)(strend - scan);
+
+    if (len < MIN_MATCH) return MIN_MATCH - 1;
+
+    s->match_start = cur_match;
+    return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
+}
+
+#endif /* FASTEST */
+
+#ifdef ZLIB_DEBUG
+
+#define EQUAL 0
+/* result of memcmp for equal strings */
+
+/* ===========================================================================
+ * Check that the match at match_start is indeed a match.
+ */
+local void check_match(s, start, match, length)
+    deflate_state *s;
+    IPos start, match;
+    int length;
+{
+    /* check that the match is indeed a match */
+    if (zmemcmp(s->window + match,
+                s->window + start, length) != EQUAL) {
+        fprintf(stderr, " start %u, match %u, length %d\n",
+                start, match, length);
+        do {
+            fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
+        } while (--length != 0);
+        z_error("invalid match");
+    }
+    if (z_verbose > 1) {
+        fprintf(stderr,"\\[%d,%d]", start-match, length);
+        do { putc(s->window[start++], stderr); } while (--length != 0);
+    }
+}
+#else
+#  define check_match(s, start, match, length)
+#endif /* ZLIB_DEBUG */
+
+/* ===========================================================================
+ * Fill the window when the lookahead becomes insufficient.
+ * Updates strstart and lookahead.
+ *
+ * IN assertion: lookahead < MIN_LOOKAHEAD
+ * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
+ *    At least one byte has been read, or avail_in == 0; reads are
+ *    performed for at least two bytes (required for the zip translate_eol
+ *    option -- not supported here).
+ */
+local void fill_window(s)
+    deflate_state *s;
+{
+    unsigned n;
+    unsigned more;    /* Amount of free space at the end of the window. */
+    uInt wsize = s->w_size;
+
+    Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
+
+    do {
+        more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
+
+        /* Deal with !@#$% 64K limit: */
+        if (sizeof(int) <= 2) {
+            if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
+                more = wsize;
+
+            } else if (more == (unsigned)(-1)) {
+                /* Very unlikely, but possible on 16 bit machine if
+                 * strstart == 0 && lookahead == 1 (input done a byte at time)
+                 */
+                more--;
+            }
+        }
+
+        /* If the window is almost full and there is insufficient lookahead,
+         * move the upper half to the lower one to make room in the upper half.
+         */
+        if (s->strstart >= wsize+MAX_DIST(s)) {
+
+            zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more);
+            s->match_start -= wsize;
+            s->strstart    -= wsize; /* we now have strstart >= MAX_DIST */
+            s->block_start -= (long) wsize;
+            slide_hash(s);
+            more += wsize;
+        }
+        if (s->strm->avail_in == 0) break;
+
+        /* If there was no sliding:
+         *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
+         *    more == window_size - lookahead - strstart
+         * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
+         * => more >= window_size - 2*WSIZE + 2
+         * In the BIG_MEM or MMAP case (not yet supported),
+         *   window_size == input_size + MIN_LOOKAHEAD  &&
+         *   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
+         * Otherwise, window_size == 2*WSIZE so more >= 2.
+         * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
+         */
+        Assert(more >= 2, "more < 2");
+
+        n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
+        s->lookahead += n;
+
+        /* Initialize the hash value now that we have some input: */
+        if (s->lookahead + s->insert >= MIN_MATCH) {
+            uInt str = s->strstart - s->insert;
+            s->ins_h = s->window[str];
+            UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
+#if MIN_MATCH != 3
+            Call UPDATE_HASH() MIN_MATCH-3 more times
+#endif
+            while (s->insert) {
+                UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
+#ifndef FASTEST
+                s->prev[str & s->w_mask] = s->head[s->ins_h];
+#endif
+                s->head[s->ins_h] = (Pos)str;
+                str++;
+                s->insert--;
+                if (s->lookahead + s->insert < MIN_MATCH)
+                    break;
+            }
+        }
+        /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
+         * but this is not important since only literal bytes will be emitted.
+         */
+
+    } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
+
+    /* If the WIN_INIT bytes after the end of the current data have never been
+     * written, then zero those bytes in order to avoid memory check reports of
+     * the use of uninitialized (or uninitialised as Julian writes) bytes by
+     * the longest match routines.  Update the high water mark for the next
+     * time through here.  WIN_INIT is set to MAX_MATCH since the longest match
+     * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
+     */
+    if (s->high_water < s->window_size) {
+        ulg curr = s->strstart + (ulg)(s->lookahead);
+        ulg init;
+
+        if (s->high_water < curr) {
+            /* Previous high water mark below current data -- zero WIN_INIT
+             * bytes or up to end of window, whichever is less.
+             */
+            init = s->window_size - curr;
+            if (init > WIN_INIT)
+                init = WIN_INIT;
+            zmemzero(s->window + curr, (unsigned)init);
+            s->high_water = curr + init;
+        }
+        else if (s->high_water < (ulg)curr + WIN_INIT) {
+            /* High water mark at or above current data, but below current data
+             * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
+             * to end of window, whichever is less.
+             */
+            init = (ulg)curr + WIN_INIT - s->high_water;
+            if (init > s->window_size - s->high_water)
+                init = s->window_size - s->high_water;
+            zmemzero(s->window + s->high_water, (unsigned)init);
+            s->high_water += init;
+        }
+    }
+
+    Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
+           "not enough room for search");
+}
+
+/* ===========================================================================
+ * Flush the current block, with given end-of-file flag.
+ * IN assertion: strstart is set to the end of the current match.
+ */
+#define FLUSH_BLOCK_ONLY(s, last) { \
+   _tr_flush_block(s, (s->block_start >= 0L ? \
+                   (charf *)&s->window[(unsigned)s->block_start] : \
+                   (charf *)Z_NULL), \
+                (ulg)((long)s->strstart - s->block_start), \
+                (last)); \
+   s->block_start = s->strstart; \
+   flush_pending(s->strm); \
+   Tracev((stderr,"[FLUSH]")); \
+}
+
+/* Same but force premature exit if necessary. */
+#define FLUSH_BLOCK(s, last) { \
+   FLUSH_BLOCK_ONLY(s, last); \
+   if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
+}
+
+/* Maximum stored block length in deflate format (not including header). */
+#define MAX_STORED 65535
+
+/* Minimum of a and b. */
+#define MIN(a, b) ((a) > (b) ? (b) : (a))
+
+/* ===========================================================================
+ * Copy without compression as much as possible from the input stream, return
+ * the current block state.
+ *
+ * In case deflateParams() is used to later switch to a non-zero compression
+ * level, s->matches (otherwise unused when storing) keeps track of the number
+ * of hash table slides to perform. If s->matches is 1, then one hash table
+ * slide will be done when switching. If s->matches is 2, the maximum value
+ * allowed here, then the hash table will be cleared, since two or more slides
+ * is the same as a clear.
+ *
+ * deflate_stored() is written to minimize the number of times an input byte is
+ * copied. It is most efficient with large input and output buffers, which
+ * maximizes the opportunites to have a single copy from next_in to next_out.
+ */
+local block_state deflate_stored(s, flush)
+    deflate_state *s;
+    int flush;
+{
+    /* Smallest worthy block size when not flushing or finishing. By default
+     * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
+     * large input and output buffers, the stored block size will be larger.
+     */
+    unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
+
+    /* Copy as many min_block or larger stored blocks directly to next_out as
+     * possible. If flushing, copy the remaining available input to next_out as
+     * stored blocks, if there is enough space.
+     */
+    unsigned len, left, have, last = 0;
+    unsigned used = s->strm->avail_in;
+    do {
+        /* Set len to the maximum size block that we can copy directly with the
+         * available input data and output space. Set left to how much of that
+         * would be copied from what's left in the window.
+         */
+        len = MAX_STORED;       /* maximum deflate stored block length */
+        have = (s->bi_valid + 42) >> 3;         /* number of header bytes */
+        if (s->strm->avail_out < have)          /* need room for header */
+            break;
+            /* maximum stored block length that will fit in avail_out: */
+        have = s->strm->avail_out - have;
+        left = s->strstart - s->block_start;    /* bytes left in window */
+        if (len > (ulg)left + s->strm->avail_in)
+            len = left + s->strm->avail_in;     /* limit len to the input */
+        if (len > have)
+            len = have;                         /* limit len to the output */
+
+        /* If the stored block would be less than min_block in length, or if
+         * unable to copy all of the available input when flushing, then try
+         * copying to the window and the pending buffer instead. Also don't
+         * write an empty block when flushing -- deflate() does that.
+         */
+        if (len < min_block && ((len == 0 && flush != Z_FINISH) ||
+                                flush == Z_NO_FLUSH ||
+                                len != left + s->strm->avail_in))
+            break;
+
+        /* Make a dummy stored block in pending to get the header bytes,
+         * including any pending bits. This also updates the debugging counts.
+         */
+        last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
+        _tr_stored_block(s, (char *)0, 0L, last);
+
+        /* Replace the lengths in the dummy stored block with len. */
+        s->pending_buf[s->pending - 4] = len;
+        s->pending_buf[s->pending - 3] = len >> 8;
+        s->pending_buf[s->pending - 2] = ~len;
+        s->pending_buf[s->pending - 1] = ~len >> 8;
+
+        /* Write the stored block header bytes. */
+        flush_pending(s->strm);
+
+#ifdef ZLIB_DEBUG
+        /* Update debugging counts for the data about to be copied. */
+        s->compressed_len += len << 3;
+        s->bits_sent += len << 3;
+#endif
+
+        /* Copy uncompressed bytes from the window to next_out. */
+        if (left) {
+            if (left > len)
+                left = len;
+            zmemcpy(s->strm->next_out, s->window + s->block_start, left);
+            s->strm->next_out += left;
+            s->strm->avail_out -= left;
+            s->strm->total_out += left;
+            s->block_start += left;
+            len -= left;
+        }
+
+        /* Copy uncompressed bytes directly from next_in to next_out, updating
+         * the check value.
+         */
+        if (len) {
+            read_buf(s->strm, s->strm->next_out, len);
+            s->strm->next_out += len;
+            s->strm->avail_out -= len;
+            s->strm->total_out += len;
+        }
+    } while (last == 0);
+
+    /* Update the sliding window with the last s->w_size bytes of the copied
+     * data, or append all of the copied data to the existing window if less
+     * than s->w_size bytes were copied. Also update the number of bytes to
+     * insert in the hash tables, in the event that deflateParams() switches to
+     * a non-zero compression level.
+     */
+    used -= s->strm->avail_in;      /* number of input bytes directly copied */
+    if (used) {
+        /* If any input was used, then no unused input remains in the window,
+         * therefore s->block_start == s->strstart.
+         */
+        if (used >= s->w_size) {    /* supplant the previous history */
+            s->matches = 2;         /* clear hash */
+            zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
+            s->strstart = s->w_size;
+        }
+        else {
+            if (s->window_size - s->strstart <= used) {
+                /* Slide the window down. */
+                s->strstart -= s->w_size;
+                zmemcpy(s->window, s->window + s->w_size, s->strstart);
+                if (s->matches < 2)
+                    s->matches++;   /* add a pending slide_hash() */
+            }
+            zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
+            s->strstart += used;
+        }
+        s->block_start = s->strstart;
+        s->insert += MIN(used, s->w_size - s->insert);
+    }
+    if (s->high_water < s->strstart)
+        s->high_water = s->strstart;
+
+    /* If the last block was written to next_out, then done. */
+    if (last)
+        return finish_done;
+
+    /* If flushing and all input has been consumed, then done. */
+    if (flush != Z_NO_FLUSH && flush != Z_FINISH &&
+        s->strm->avail_in == 0 && (long)s->strstart == s->block_start)
+        return block_done;
+
+    /* Fill the window with any remaining input. */
+    have = s->window_size - s->strstart - 1;
+    if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) {
+        /* Slide the window down. */
+        s->block_start -= s->w_size;
+        s->strstart -= s->w_size;
+        zmemcpy(s->window, s->window + s->w_size, s->strstart);
+        if (s->matches < 2)
+            s->matches++;           /* add a pending slide_hash() */
+        have += s->w_size;          /* more space now */
+    }
+    if (have > s->strm->avail_in)
+        have = s->strm->avail_in;
+    if (have) {
+        read_buf(s->strm, s->window + s->strstart, have);
+        s->strstart += have;
+    }
+    if (s->high_water < s->strstart)
+        s->high_water = s->strstart;
+
+    /* There was not enough avail_out to write a complete worthy or flushed
+     * stored block to next_out. Write a stored block to pending instead, if we
+     * have enough input for a worthy block, or if flushing and there is enough
+     * room for the remaining input as a stored block in the pending buffer.
+     */
+    have = (s->bi_valid + 42) >> 3;         /* number of header bytes */
+        /* maximum stored block length that will fit in pending: */
+    have = MIN(s->pending_buf_size - have, MAX_STORED);
+    min_block = MIN(have, s->w_size);
+    left = s->strstart - s->block_start;
+    if (left >= min_block ||
+        ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH &&
+         s->strm->avail_in == 0 && left <= have)) {
+        len = MIN(left, have);
+        last = flush == Z_FINISH && s->strm->avail_in == 0 &&
+               len == left ? 1 : 0;
+        _tr_stored_block(s, (charf *)s->window + s->block_start, len, last);
+        s->block_start += len;
+        flush_pending(s->strm);
+    }
+
+    /* We've done all we can with the available input and output. */
+    return last ? finish_started : need_more;
+}
+
+/* ===========================================================================
+ * Compress as much as possible from the input stream, return the current
+ * block state.
+ * This function does not perform lazy evaluation of matches and inserts
+ * new strings in the dictionary only for unmatched strings or for short
+ * matches. It is used only for the fast compression options.
+ */
+local block_state deflate_fast(s, flush)
+    deflate_state *s;
+    int flush;
+{
+    IPos hash_head;       /* head of the hash chain */
+    int bflush;           /* set if current block must be flushed */
+
+    for (;;) {
+        /* Make sure that we always have enough lookahead, except
+         * at the end of the input file. We need MAX_MATCH bytes
+         * for the next match, plus MIN_MATCH bytes to insert the
+         * string following the next match.
+         */
+        if (s->lookahead < MIN_LOOKAHEAD) {
+            fill_window(s);
+            if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+                return need_more;
+            }
+            if (s->lookahead == 0) break; /* flush the current block */
+        }
+
+        /* Insert the string window[strstart .. strstart+2] in the
+         * dictionary, and set hash_head to the head of the hash chain:
+         */
+        hash_head = NIL;
+        if (s->lookahead >= MIN_MATCH) {
+            INSERT_STRING(s, s->strstart, hash_head);
+        }
+
+        /* Find the longest match, discarding those <= prev_length.
+         * At this point we have always match_length < MIN_MATCH
+         */
+        if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
+            /* To simplify the code, we prevent matches with the string
+             * of window index 0 (in particular we have to avoid a match
+             * of the string with itself at the start of the input file).
+             */
+            s->match_length = longest_match (s, hash_head);
+            /* longest_match() sets match_start */
+        }
+        if (s->match_length >= MIN_MATCH) {
+            check_match(s, s->strstart, s->match_start, s->match_length);
+
+            _tr_tally_dist(s, s->strstart - s->match_start,
+                           s->match_length - MIN_MATCH, bflush);
+
+            s->lookahead -= s->match_length;
+
+            /* Insert new strings in the hash table only if the match length
+             * is not too large. This saves time but degrades compression.
+             */
+#ifndef FASTEST
+            if (s->match_length <= s->max_insert_length &&
+                s->lookahead >= MIN_MATCH) {
+                s->match_length--; /* string at strstart already in table */
+                do {
+                    s->strstart++;
+                    INSERT_STRING(s, s->strstart, hash_head);
+                    /* strstart never exceeds WSIZE-MAX_MATCH, so there are
+                     * always MIN_MATCH bytes ahead.
+                     */
+                } while (--s->match_length != 0);
+                s->strstart++;
+            } else
+#endif
+            {
+                s->strstart += s->match_length;
+                s->match_length = 0;
+                s->ins_h = s->window[s->strstart];
+                UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+#if MIN_MATCH != 3
+                Call UPDATE_HASH() MIN_MATCH-3 more times
+#endif
+                /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
+                 * matter since it will be recomputed at next deflate call.
+                 */
+            }
+        } else {
+            /* No match, output a literal byte */
+            Tracevv((stderr,"%c", s->window[s->strstart]));
+            _tr_tally_lit (s, s->window[s->strstart], bflush);
+            s->lookahead--;
+            s->strstart++;
+        }
+        if (bflush) FLUSH_BLOCK(s, 0);
+    }
+    s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+    if (flush == Z_FINISH) {
+        FLUSH_BLOCK(s, 1);
+        return finish_done;
+    }
+    if (s->last_lit)
+        FLUSH_BLOCK(s, 0);
+    return block_done;
+}
+
+#ifndef FASTEST
+/* ===========================================================================
+ * Same as above, but achieves better compression. We use a lazy
+ * evaluation for matches: a match is finally adopted only if there is
+ * no better match at the next window position.
+ */
+local block_state deflate_slow(s, flush)
+    deflate_state *s;
+    int flush;
+{
+    IPos hash_head;          /* head of hash chain */
+    int bflush;              /* set if current block must be flushed */
+
+    /* Process the input block. */
+    for (;;) {
+        /* Make sure that we always have enough lookahead, except
+         * at the end of the input file. We need MAX_MATCH bytes
+         * for the next match, plus MIN_MATCH bytes to insert the
+         * string following the next match.
+         */
+        if (s->lookahead < MIN_LOOKAHEAD) {
+            fill_window(s);
+            if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+                return need_more;
+            }
+            if (s->lookahead == 0) break; /* flush the current block */
+        }
+
+        /* Insert the string window[strstart .. strstart+2] in the
+         * dictionary, and set hash_head to the head of the hash chain:
+         */
+        hash_head = NIL;
+        if (s->lookahead >= MIN_MATCH) {
+            INSERT_STRING(s, s->strstart, hash_head);
+        }
+
+        /* Find the longest match, discarding those <= prev_length.
+         */
+        s->prev_length = s->match_length, s->prev_match = s->match_start;
+        s->match_length = MIN_MATCH-1;
+
+        if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
+            s->strstart - hash_head <= MAX_DIST(s)) {
+            /* To simplify the code, we prevent matches with the string
+             * of window index 0 (in particular we have to avoid a match
+             * of the string with itself at the start of the input file).
+             */
+            s->match_length = longest_match (s, hash_head);
+            /* longest_match() sets match_start */
+
+            if (s->match_length <= 5 && (s->strategy == Z_FILTERED
+#if TOO_FAR <= 32767
+                || (s->match_length == MIN_MATCH &&
+                    s->strstart - s->match_start > TOO_FAR)
+#endif
+                )) {
+
+                /* If prev_match is also MIN_MATCH, match_start is garbage
+                 * but we will ignore the current match anyway.
+                 */
+                s->match_length = MIN_MATCH-1;
+            }
+        }
+        /* If there was a match at the previous step and the current
+         * match is not better, output the previous match:
+         */
+        if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
+            uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
+            /* Do not insert strings in hash table beyond this. */
+
+            check_match(s, s->strstart-1, s->prev_match, s->prev_length);
+
+            _tr_tally_dist(s, s->strstart -1 - s->prev_match,
+                           s->prev_length - MIN_MATCH, bflush);
+
+            /* Insert in hash table all strings up to the end of the match.
+             * strstart-1 and strstart are already inserted. If there is not
+             * enough lookahead, the last two strings are not inserted in
+             * the hash table.
+             */
+            s->lookahead -= s->prev_length-1;
+            s->prev_length -= 2;
+            do {
+                if (++s->strstart <= max_insert) {
+                    INSERT_STRING(s, s->strstart, hash_head);
+                }
+            } while (--s->prev_length != 0);
+            s->match_available = 0;
+            s->match_length = MIN_MATCH-1;
+            s->strstart++;
+
+            if (bflush) FLUSH_BLOCK(s, 0);
+
+        } else if (s->match_available) {
+            /* If there was no match at the previous position, output a
+             * single literal. If there was a match but the current match
+             * is longer, truncate the previous match to a single literal.
+             */
+            Tracevv((stderr,"%c", s->window[s->strstart-1]));
+            _tr_tally_lit(s, s->window[s->strstart-1], bflush);
+            if (bflush) {
+                FLUSH_BLOCK_ONLY(s, 0);
+            }
+            s->strstart++;
+            s->lookahead--;
+            if (s->strm->avail_out == 0) return need_more;
+        } else {
+            /* There is no previous match to compare with, wait for
+             * the next step to decide.
+             */
+            s->match_available = 1;
+            s->strstart++;
+            s->lookahead--;
+        }
+    }
+    Assert (flush != Z_NO_FLUSH, "no flush?");
+    if (s->match_available) {
+        Tracevv((stderr,"%c", s->window[s->strstart-1]));
+        _tr_tally_lit(s, s->window[s->strstart-1], bflush);
+        s->match_available = 0;
+    }
+    s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+    if (flush == Z_FINISH) {
+        FLUSH_BLOCK(s, 1);
+        return finish_done;
+    }
+    if (s->last_lit)
+        FLUSH_BLOCK(s, 0);
+    return block_done;
+}
+#endif /* FASTEST */
+
+/* ===========================================================================
+ * For Z_RLE, simply look for runs of bytes, generate matches only of distance
+ * one.  Do not maintain a hash table.  (It will be regenerated if this run of
+ * deflate switches away from Z_RLE.)
+ */
+local block_state deflate_rle(s, flush)
+    deflate_state *s;
+    int flush;
+{
+    int bflush;             /* set if current block must be flushed */
+    uInt prev;              /* byte at distance one to match */
+    Bytef *scan, *strend;   /* scan goes up to strend for length of run */
+
+    for (;;) {
+        /* Make sure that we always have enough lookahead, except
+         * at the end of the input file. We need MAX_MATCH bytes
+         * for the longest run, plus one for the unrolled loop.
+         */
+        if (s->lookahead <= MAX_MATCH) {
+            fill_window(s);
+            if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
+                return need_more;
+            }
+            if (s->lookahead == 0) break; /* flush the current block */
+        }
+
+        /* See how many times the previous byte repeats */
+        s->match_length = 0;
+        if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
+            scan = s->window + s->strstart - 1;
+            prev = *scan;
+            if (prev == *++scan && prev == *++scan && prev == *++scan) {
+                strend = s->window + s->strstart + MAX_MATCH;
+                do {
+                } while (prev == *++scan && prev == *++scan &&
+                         prev == *++scan && prev == *++scan &&
+                         prev == *++scan && prev == *++scan &&
+                         prev == *++scan && prev == *++scan &&
+                         scan < strend);
+                s->match_length = MAX_MATCH - (uInt)(strend - scan);
+                if (s->match_length > s->lookahead)
+                    s->match_length = s->lookahead;
+            }
+            Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
+        }
+
+        /* Emit match if have run of MIN_MATCH or longer, else emit literal */
+        if (s->match_length >= MIN_MATCH) {
+            check_match(s, s->strstart, s->strstart - 1, s->match_length);
+
+            _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
+
+            s->lookahead -= s->match_length;
+            s->strstart += s->match_length;
+            s->match_length = 0;
+        } else {
+            /* No match, output a literal byte */
+            Tracevv((stderr,"%c", s->window[s->strstart]));
+            _tr_tally_lit (s, s->window[s->strstart], bflush);
+            s->lookahead--;
+            s->strstart++;
+        }
+        if (bflush) FLUSH_BLOCK(s, 0);
+    }
+    s->insert = 0;
+    if (flush == Z_FINISH) {
+        FLUSH_BLOCK(s, 1);
+        return finish_done;
+    }
+    if (s->last_lit)
+        FLUSH_BLOCK(s, 0);
+    return block_done;
+}
+
+/* ===========================================================================
+ * For Z_HUFFMAN_ONLY, do not look for matches.  Do not maintain a hash table.
+ * (It will be regenerated if this run of deflate switches away from Huffman.)
+ */
+local block_state deflate_huff(s, flush)
+    deflate_state *s;
+    int flush;
+{
+    int bflush;             /* set if current block must be flushed */
+
+    for (;;) {
+        /* Make sure that we have a literal to write. */
+        if (s->lookahead == 0) {
+            fill_window(s);
+            if (s->lookahead == 0) {
+                if (flush == Z_NO_FLUSH)
+                    return need_more;
+                break;      /* flush the current block */
+            }
+        }
+
+        /* Output a literal byte */
+        s->match_length = 0;
+        Tracevv((stderr,"%c", s->window[s->strstart]));
+        _tr_tally_lit (s, s->window[s->strstart], bflush);
+        s->lookahead--;
+        s->strstart++;
+        if (bflush) FLUSH_BLOCK(s, 0);
+    }
+    s->insert = 0;
+    if (flush == Z_FINISH) {
+        FLUSH_BLOCK(s, 1);
+        return finish_done;
+    }
+    if (s->last_lit)
+        FLUSH_BLOCK(s, 0);
+    return block_done;
+}
similarity index 92%
rename from deps/zlib/deflate.h
rename to deps/libchdr/deps/zlib-1.2.11/deflate.h
index 82fe93e..23ecdd3 100644 (file)
@@ -1,5 +1,5 @@
 /* deflate.h -- internal compression state
- * Copyright (C) 1995-2012 Jean-loup Gailly
+ * Copyright (C) 1995-2016 Jean-loup Gailly
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
 #define Buf_size 16
 /* size of bit buffer in bi_buf */
 
-#define INIT_STATE    42
-#define EXTRA_STATE   69
-#define NAME_STATE    73
-#define COMMENT_STATE 91
-#define HCRC_STATE   103
-#define BUSY_STATE   113
-#define FINISH_STATE 666
+#define INIT_STATE    42    /* zlib header -> BUSY_STATE */
+#ifdef GZIP
+#  define GZIP_STATE  57    /* gzip header -> BUSY_STATE | EXTRA_STATE */
+#endif
+#define EXTRA_STATE   69    /* gzip extra block -> NAME_STATE */
+#define NAME_STATE    73    /* gzip file name -> COMMENT_STATE */
+#define COMMENT_STATE 91    /* gzip comment -> HCRC_STATE */
+#define HCRC_STATE   103    /* gzip header CRC -> BUSY_STATE */
+#define BUSY_STATE   113    /* deflate -> FINISH_STATE */
+#define FINISH_STATE 666    /* stream complete */
 /* Stream status */
 
 
@@ -83,7 +86,7 @@ typedef struct static_tree_desc_s  static_tree_desc;
 typedef struct tree_desc_s {
     ct_data *dyn_tree;           /* the dynamic tree */
     int     max_code;            /* largest code with non zero frequency */
-    static_tree_desc *stat_desc; /* the corresponding static tree */
+    const static_tree_desc *stat_desc;  /* the corresponding static tree */
 } FAR tree_desc;
 
 typedef ush Pos;
@@ -94,16 +97,16 @@ typedef unsigned IPos;
  * save space in the various tables. IPos is used only for parameter passing.
  */
 
-typedef struct internal_state_deflate {
+typedef struct internal_state {
     z_streamp strm;      /* pointer back to this zlib stream */
     int   status;        /* as the name implies */
     Bytef *pending_buf;  /* output still pending */
     ulg   pending_buf_size; /* size of pending_buf */
     Bytef *pending_out;  /* next pending byte to output to the stream */
-    uInt   pending;      /* nb of bytes in the pending buffer */
+    ulg   pending;       /* nb of bytes in the pending buffer */
     int   wrap;          /* bit 0 true for zlib, bit 1 true for gzip */
     gz_headerp  gzhead;  /* gzip header information to write */
-    uInt   gzindex;      /* where in extra, name, or comment */
+    ulg   gzindex;       /* where in extra, name, or comment */
     Byte  method;        /* can only be DEFLATED */
     int   last_flush;    /* value of flush param for previous deflate call */
 
@@ -249,7 +252,7 @@ typedef struct internal_state_deflate {
     uInt matches;       /* number of string matches in current block */
     uInt insert;        /* bytes at end of window left to insert */
 
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
     ulg compressed_len; /* total bit length of compressed file mod 2^32 */
     ulg bits_sent;      /* bit length of compressed data sent mod 2^32 */
 #endif
@@ -270,12 +273,12 @@ typedef struct internal_state_deflate {
      * updated to the new high water mark.
      */
 
-} deflate_state;
+} FAR deflate_state;
 
 /* Output a byte on the stream.
  * IN assertion: there is enough room in pending_buf.
  */
-#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
+#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
 
 
 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
@@ -309,7 +312,7 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
  * used.
  */
 
-#ifndef DEBUG
+#ifndef ZLIB_DEBUG
 /* Inline versions of _tr_tally for speed: */
 
 #if defined(GEN_TREES_H) || !defined(STDC)
@@ -328,8 +331,8 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
     flush = (s->last_lit == s->lit_bufsize-1); \
    }
 # define _tr_tally_dist(s, distance, length, flush) \
-  { uch len = (length); \
-    ush dist = (distance); \
+  { uch len = (uch)(length); \
+    ush dist = (ush)(distance); \
     s->d_buf[s->last_lit] = dist; \
     s->l_buf[s->last_lit++] = len; \
     dist--; \
diff --git a/deps/libchdr/deps/zlib-1.2.11/doc/algorithm.txt b/deps/libchdr/deps/zlib-1.2.11/doc/algorithm.txt
new file mode 100644 (file)
index 0000000..c97f495
--- /dev/null
@@ -0,0 +1,209 @@
+1. Compression algorithm (deflate)
+
+The deflation algorithm used by gzip (also zip and zlib) is a variation of
+LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in
+the input data.  The second occurrence of a string is replaced by a
+pointer to the previous string, in the form of a pair (distance,
+length).  Distances are limited to 32K bytes, and lengths are limited
+to 258 bytes. When a string does not occur anywhere in the previous
+32K bytes, it is emitted as a sequence of literal bytes.  (In this
+description, `string' must be taken as an arbitrary sequence of bytes,
+and is not restricted to printable characters.)
+
+Literals or match lengths are compressed with one Huffman tree, and
+match distances are compressed with another tree. The trees are stored
+in a compact form at the start of each block. The blocks can have any
+size (except that the compressed data for one block must fit in
+available memory). A block is terminated when deflate() determines that
+it would be useful to start another block with fresh trees. (This is
+somewhat similar to the behavior of LZW-based _compress_.)
+
+Duplicated strings are found using a hash table. All input strings of
+length 3 are inserted in the hash table. A hash index is computed for
+the next 3 bytes. If the hash chain for this index is not empty, all
+strings in the chain are compared with the current input string, and
+the longest match is selected.
+
+The hash chains are searched starting with the most recent strings, to
+favor small distances and thus take advantage of the Huffman encoding.
+The hash chains are singly linked. There are no deletions from the
+hash chains, the algorithm simply discards matches that are too old.
+
+To avoid a worst-case situation, very long hash chains are arbitrarily
+truncated at a certain length, determined by a runtime option (level
+parameter of deflateInit). So deflate() does not always find the longest
+possible match but generally finds a match which is long enough.
+
+deflate() also defers the selection of matches with a lazy evaluation
+mechanism. After a match of length N has been found, deflate() searches for
+a longer match at the next input byte. If a longer match is found, the
+previous match is truncated to a length of one (thus producing a single
+literal byte) and the process of lazy evaluation begins again. Otherwise,
+the original match is kept, and the next match search is attempted only N
+steps later.
+
+The lazy match evaluation is also subject to a runtime parameter. If
+the current match is long enough, deflate() reduces the search for a longer
+match, thus speeding up the whole process. If compression ratio is more
+important than speed, deflate() attempts a complete second search even if
+the first match is already long enough.
+
+The lazy match evaluation is not performed for the fastest compression
+modes (level parameter 1 to 3). For these fast modes, new strings
+are inserted in the hash table only when no match was found, or
+when the match is not too long. This degrades the compression ratio
+but saves time since there are both fewer insertions and fewer searches.
+
+
+2. Decompression algorithm (inflate)
+
+2.1 Introduction
+
+The key question is how to represent a Huffman code (or any prefix code) so
+that you can decode fast.  The most important characteristic is that shorter
+codes are much more common than longer codes, so pay attention to decoding the
+short codes fast, and let the long codes take longer to decode.
+
+inflate() sets up a first level table that covers some number of bits of
+input less than the length of longest code.  It gets that many bits from the
+stream, and looks it up in the table.  The table will tell if the next
+code is that many bits or less and how many, and if it is, it will tell
+the value, else it will point to the next level table for which inflate()
+grabs more bits and tries to decode a longer code.
+
+How many bits to make the first lookup is a tradeoff between the time it
+takes to decode and the time it takes to build the table.  If building the
+table took no time (and if you had infinite memory), then there would only
+be a first level table to cover all the way to the longest code.  However,
+building the table ends up taking a lot longer for more bits since short
+codes are replicated many times in such a table.  What inflate() does is
+simply to make the number of bits in the first table a variable, and  then
+to set that variable for the maximum speed.
+
+For inflate, which has 286 possible codes for the literal/length tree, the size
+of the first table is nine bits.  Also the distance trees have 30 possible
+values, and the size of the first table is six bits.  Note that for each of
+those cases, the table ended up one bit longer than the ``average'' code
+length, i.e. the code length of an approximately flat code which would be a
+little more than eight bits for 286 symbols and a little less than five bits
+for 30 symbols.
+
+
+2.2 More details on the inflate table lookup
+
+Ok, you want to know what this cleverly obfuscated inflate tree actually
+looks like.  You are correct that it's not a Huffman tree.  It is simply a
+lookup table for the first, let's say, nine bits of a Huffman symbol.  The
+symbol could be as short as one bit or as long as 15 bits.  If a particular
+symbol is shorter than nine bits, then that symbol's translation is duplicated
+in all those entries that start with that symbol's bits.  For example, if the
+symbol is four bits, then it's duplicated 32 times in a nine-bit table.  If a
+symbol is nine bits long, it appears in the table once.
+
+If the symbol is longer than nine bits, then that entry in the table points
+to another similar table for the remaining bits.  Again, there are duplicated
+entries as needed.  The idea is that most of the time the symbol will be short
+and there will only be one table look up.  (That's whole idea behind data
+compression in the first place.)  For the less frequent long symbols, there
+will be two lookups.  If you had a compression method with really long
+symbols, you could have as many levels of lookups as is efficient.  For
+inflate, two is enough.
+
+So a table entry either points to another table (in which case nine bits in
+the above example are gobbled), or it contains the translation for the symbol
+and the number of bits to gobble.  Then you start again with the next
+ungobbled bit.
+
+You may wonder: why not just have one lookup table for how ever many bits the
+longest symbol is?  The reason is that if you do that, you end up spending
+more time filling in duplicate symbol entries than you do actually decoding.
+At least for deflate's output that generates new trees every several 10's of
+kbytes.  You can imagine that filling in a 2^15 entry table for a 15-bit code
+would take too long if you're only decoding several thousand symbols.  At the
+other extreme, you could make a new table for every bit in the code.  In fact,
+that's essentially a Huffman tree.  But then you spend too much time
+traversing the tree while decoding, even for short symbols.
+
+So the number of bits for the first lookup table is a trade of the time to
+fill out the table vs. the time spent looking at the second level and above of
+the table.
+
+Here is an example, scaled down:
+
+The code being decoded, with 10 symbols, from 1 to 6 bits long:
+
+A: 0
+B: 10
+C: 1100
+D: 11010
+E: 11011
+F: 11100
+G: 11101
+H: 11110
+I: 111110
+J: 111111
+
+Let's make the first table three bits long (eight entries):
+
+000: A,1
+001: A,1
+010: A,1
+011: A,1
+100: B,2
+101: B,2
+110: -> table X (gobble 3 bits)
+111: -> table Y (gobble 3 bits)
+
+Each entry is what the bits decode as and how many bits that is, i.e. how
+many bits to gobble.  Or the entry points to another table, with the number of
+bits to gobble implicit in the size of the table.
+
+Table X is two bits long since the longest code starting with 110 is five bits
+long:
+
+00: C,1
+01: C,1
+10: D,2
+11: E,2
+
+Table Y is three bits long since the longest code starting with 111 is six
+bits long:
+
+000: F,2
+001: F,2
+010: G,2
+011: G,2
+100: H,2
+101: H,2
+110: I,3
+111: J,3
+
+So what we have here are three tables with a total of 20 entries that had to
+be constructed.  That's compared to 64 entries for a single table.  Or
+compared to 16 entries for a Huffman tree (six two entry tables and one four
+entry table).  Assuming that the code ideally represents the probability of
+the symbols, it takes on the average 1.25 lookups per symbol.  That's compared
+to one lookup for the single table, or 1.66 lookups per symbol for the
+Huffman tree.
+
+There, I think that gives you a picture of what's going on.  For inflate, the
+meaning of a particular symbol is often more than just a letter.  It can be a
+byte (a "literal"), or it can be either a length or a distance which
+indicates a base value and a number of bits to fetch after the code that is
+added to the base value.  Or it might be the special end-of-block code.  The
+data structures created in inftrees.c try to encode all that information
+compactly in the tables.
+
+
+Jean-loup Gailly        Mark Adler
+jloup@gzip.org          madler@alumni.caltech.edu
+
+
+References:
+
+[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data
+Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
+pp. 337-343.
+
+``DEFLATE Compressed Data Format Specification'' available in
+http://tools.ietf.org/html/rfc1951
diff --git a/deps/libchdr/deps/zlib-1.2.11/doc/rfc1950.txt b/deps/libchdr/deps/zlib-1.2.11/doc/rfc1950.txt
new file mode 100644 (file)
index 0000000..ce6428a
--- /dev/null
@@ -0,0 +1,619 @@
+
+
+
+
+
+
+Network Working Group                                         P. Deutsch
+Request for Comments: 1950                           Aladdin Enterprises
+Category: Informational                                      J-L. Gailly
+                                                                Info-ZIP
+                                                                May 1996
+
+
+         ZLIB Compressed Data Format Specification version 3.3
+
+Status of This Memo
+
+   This memo provides information for the Internet community.  This memo
+   does not specify an Internet standard of any kind.  Distribution of
+   this memo is unlimited.
+
+IESG Note:
+
+   The IESG takes no position on the validity of any Intellectual
+   Property Rights statements contained in this document.
+
+Notices
+
+   Copyright (c) 1996 L. Peter Deutsch and Jean-Loup Gailly
+
+   Permission is granted to copy and distribute this document for any
+   purpose and without charge, including translations into other
+   languages and incorporation into compilations, provided that the
+   copyright notice and this notice are preserved, and that any
+   substantive changes or deletions from the original are clearly
+   marked.
+
+   A pointer to the latest version of this and related documentation in
+   HTML format can be found at the URL
+   <ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html>.
+
+Abstract
+
+   This specification defines a lossless compressed data format.  The
+   data can be produced or consumed, even for an arbitrarily long
+   sequentially presented input data stream, using only an a priori
+   bounded amount of intermediate storage.  The format presently uses
+   the DEFLATE compression method but can be easily extended to use
+   other compression methods.  It can be implemented readily in a manner
+   not covered by patents.  This specification also defines the ADLER-32
+   checksum (an extension and improvement of the Fletcher checksum),
+   used for detection of data corruption, and provides an algorithm for
+   computing it.
+
+
+
+
+Deutsch & Gailly             Informational                      [Page 1]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+Table of Contents
+
+   1. Introduction ................................................... 2
+      1.1. Purpose ................................................... 2
+      1.2. Intended audience ......................................... 3
+      1.3. Scope ..................................................... 3
+      1.4. Compliance ................................................ 3
+      1.5.  Definitions of terms and conventions used ................ 3
+      1.6. Changes from previous versions ............................ 3
+   2. Detailed specification ......................................... 3
+      2.1. Overall conventions ....................................... 3
+      2.2. Data format ............................................... 4
+      2.3. Compliance ................................................ 7
+   3. References ..................................................... 7
+   4. Source code .................................................... 8
+   5. Security Considerations ........................................ 8
+   6. Acknowledgements ............................................... 8
+   7. Authors' Addresses ............................................. 8
+   8. Appendix: Rationale ............................................ 9
+   9. Appendix: Sample code ..........................................10
+
+1. Introduction
+
+   1.1. Purpose
+
+      The purpose of this specification is to define a lossless
+      compressed data format that:
+
+          * Is independent of CPU type, operating system, file system,
+            and character set, and hence can be used for interchange;
+
+          * Can be produced or consumed, even for an arbitrarily long
+            sequentially presented input data stream, using only an a
+            priori bounded amount of intermediate storage, and hence can
+            be used in data communications or similar structures such as
+            Unix filters;
+
+          * Can use a number of different compression methods;
+
+          * Can be implemented readily in a manner not covered by
+            patents, and hence can be practiced freely.
+
+      The data format defined by this specification does not attempt to
+      allow random access to compressed data.
+
+
+
+
+
+
+
+Deutsch & Gailly             Informational                      [Page 2]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+   1.2. Intended audience
+
+      This specification is intended for use by implementors of software
+      to compress data into zlib format and/or decompress data from zlib
+      format.
+
+      The text of the specification assumes a basic background in
+      programming at the level of bits and other primitive data
+      representations.
+
+   1.3. Scope
+
+      The specification specifies a compressed data format that can be
+      used for in-memory compression of a sequence of arbitrary bytes.
+
+   1.4. Compliance
+
+      Unless otherwise indicated below, a compliant decompressor must be
+      able to accept and decompress any data set that conforms to all
+      the specifications presented here; a compliant compressor must
+      produce data sets that conform to all the specifications presented
+      here.
+
+   1.5.  Definitions of terms and conventions used
+
+      byte: 8 bits stored or transmitted as a unit (same as an octet).
+      (For this specification, a byte is exactly 8 bits, even on
+      machines which store a character on a number of bits different
+      from 8.) See below, for the numbering of bits within a byte.
+
+   1.6. Changes from previous versions
+
+      Version 3.1 was the first public release of this specification.
+      In version 3.2, some terminology was changed and the Adler-32
+      sample code was rewritten for clarity.  In version 3.3, the
+      support for a preset dictionary was introduced, and the
+      specification was converted to RFC style.
+
+2. Detailed specification
+
+   2.1. Overall conventions
+
+      In the diagrams below, a box like this:
+
+         +---+
+         |   | <-- the vertical bars might be missing
+         +---+
+
+
+
+
+Deutsch & Gailly             Informational                      [Page 3]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+      represents one byte; a box like this:
+
+         +==============+
+         |              |
+         +==============+
+
+      represents a variable number of bytes.
+
+      Bytes stored within a computer do not have a "bit order", since
+      they are always treated as a unit.  However, a byte considered as
+      an integer between 0 and 255 does have a most- and least-
+      significant bit, and since we write numbers with the most-
+      significant digit on the left, we also write bytes with the most-
+      significant bit on the left.  In the diagrams below, we number the
+      bits of a byte so that bit 0 is the least-significant bit, i.e.,
+      the bits are numbered:
+
+         +--------+
+         |76543210|
+         +--------+
+
+      Within a computer, a number may occupy multiple bytes.  All
+      multi-byte numbers in the format described here are stored with
+      the MOST-significant byte first (at the lower memory address).
+      For example, the decimal number 520 is stored as:
+
+             0     1
+         +--------+--------+
+         |00000010|00001000|
+         +--------+--------+
+          ^        ^
+          |        |
+          |        + less significant byte = 8
+          + more significant byte = 2 x 256
+
+   2.2. Data format
+
+      A zlib stream has the following structure:
+
+           0   1
+         +---+---+
+         |CMF|FLG|   (more-->)
+         +---+---+
+
+
+
+
+
+
+
+
+Deutsch & Gailly             Informational                      [Page 4]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+      (if FLG.FDICT set)
+
+           0   1   2   3
+         +---+---+---+---+
+         |     DICTID    |   (more-->)
+         +---+---+---+---+
+
+         +=====================+---+---+---+---+
+         |...compressed data...|    ADLER32    |
+         +=====================+---+---+---+---+
+
+      Any data which may appear after ADLER32 are not part of the zlib
+      stream.
+
+      CMF (Compression Method and flags)
+         This byte is divided into a 4-bit compression method and a 4-
+         bit information field depending on the compression method.
+
+            bits 0 to 3  CM     Compression method
+            bits 4 to 7  CINFO  Compression info
+
+      CM (Compression method)
+         This identifies the compression method used in the file. CM = 8
+         denotes the "deflate" compression method with a window size up
+         to 32K.  This is the method used by gzip and PNG (see
+         references [1] and [2] in Chapter 3, below, for the reference
+         documents).  CM = 15 is reserved.  It might be used in a future
+         version of this specification to indicate the presence of an
+         extra field before the compressed data.
+
+      CINFO (Compression info)
+         For CM = 8, CINFO is the base-2 logarithm of the LZ77 window
+         size, minus eight (CINFO=7 indicates a 32K window size). Values
+         of CINFO above 7 are not allowed in this version of the
+         specification.  CINFO is not defined in this specification for
+         CM not equal to 8.
+
+      FLG (FLaGs)
+         This flag byte is divided as follows:
+
+            bits 0 to 4  FCHECK  (check bits for CMF and FLG)
+            bit  5       FDICT   (preset dictionary)
+            bits 6 to 7  FLEVEL  (compression level)
+
+         The FCHECK value must be such that CMF and FLG, when viewed as
+         a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG),
+         is a multiple of 31.
+
+
+
+
+Deutsch & Gailly             Informational                      [Page 5]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+      FDICT (Preset dictionary)
+         If FDICT is set, a DICT dictionary identifier is present
+         immediately after the FLG byte. The dictionary is a sequence of
+         bytes which are initially fed to the compressor without
+         producing any compressed output. DICT is the Adler-32 checksum
+         of this sequence of bytes (see the definition of ADLER32
+         below).  The decompressor can use this identifier to determine
+         which dictionary has been used by the compressor.
+
+      FLEVEL (Compression level)
+         These flags are available for use by specific compression
+         methods.  The "deflate" method (CM = 8) sets these flags as
+         follows:
+
+            0 - compressor used fastest algorithm
+            1 - compressor used fast algorithm
+            2 - compressor used default algorithm
+            3 - compressor used maximum compression, slowest algorithm
+
+         The information in FLEVEL is not needed for decompression; it
+         is there to indicate if recompression might be worthwhile.
+
+      compressed data
+         For compression method 8, the compressed data is stored in the
+         deflate compressed data format as described in the document
+         "DEFLATE Compressed Data Format Specification" by L. Peter
+         Deutsch. (See reference [3] in Chapter 3, below)
+
+         Other compressed data formats are not specified in this version
+         of the zlib specification.
+
+      ADLER32 (Adler-32 checksum)
+         This contains a checksum value of the uncompressed data
+         (excluding any dictionary data) computed according to Adler-32
+         algorithm. This algorithm is a 32-bit extension and improvement
+         of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
+         standard. See references [4] and [5] in Chapter 3, below)
+
+         Adler-32 is composed of two sums accumulated per byte: s1 is
+         the sum of all bytes, s2 is the sum of all s1 values. Both sums
+         are done modulo 65521. s1 is initialized to 1, s2 to zero.  The
+         Adler-32 checksum is stored as s2*65536 + s1 in most-
+         significant-byte first (network) order.
+
+
+
+
+
+
+
+
+Deutsch & Gailly             Informational                      [Page 6]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+   2.3. Compliance
+
+      A compliant compressor must produce streams with correct CMF, FLG
+      and ADLER32, but need not support preset dictionaries.  When the
+      zlib data format is used as part of another standard data format,
+      the compressor may use only preset dictionaries that are specified
+      by this other data format.  If this other format does not use the
+      preset dictionary feature, the compressor must not set the FDICT
+      flag.
+
+      A compliant decompressor must check CMF, FLG, and ADLER32, and
+      provide an error indication if any of these have incorrect values.
+      A compliant decompressor must give an error indication if CM is
+      not one of the values defined in this specification (only the
+      value 8 is permitted in this version), since another value could
+      indicate the presence of new features that would cause subsequent
+      data to be interpreted incorrectly.  A compliant decompressor must
+      give an error indication if FDICT is set and DICTID is not the
+      identifier of a known preset dictionary.  A decompressor may
+      ignore FLEVEL and still be compliant.  When the zlib data format
+      is being used as a part of another standard format, a compliant
+      decompressor must support all the preset dictionaries specified by
+      the other format. When the other format does not use the preset
+      dictionary feature, a compliant decompressor must reject any
+      stream in which the FDICT flag is set.
+
+3. References
+
+   [1] Deutsch, L.P.,"GZIP Compressed Data Format Specification",
+       available in ftp://ftp.uu.net/pub/archiving/zip/doc/
+
+   [2] Thomas Boutell, "PNG (Portable Network Graphics) specification",
+       available in ftp://ftp.uu.net/graphics/png/documents/
+
+   [3] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification",
+       available in ftp://ftp.uu.net/pub/archiving/zip/doc/
+
+   [4] Fletcher, J. G., "An Arithmetic Checksum for Serial
+       Transmissions," IEEE Transactions on Communications, Vol. COM-30,
+       No. 1, January 1982, pp. 247-252.
+
+   [5] ITU-T Recommendation X.224, Annex D, "Checksum Algorithms,"
+       November, 1993, pp. 144, 145. (Available from
+       gopher://info.itu.ch). ITU-T X.244 is also the same as ISO 8073.
+
+
+
+
+
+
+
+Deutsch & Gailly             Informational                      [Page 7]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+4. Source code
+
+   Source code for a C language implementation of a "zlib" compliant
+   library is available at ftp://ftp.uu.net/pub/archiving/zip/zlib/.
+
+5. Security Considerations
+
+   A decoder that fails to check the ADLER32 checksum value may be
+   subject to undetected data corruption.
+
+6. Acknowledgements
+
+   Trademarks cited in this document are the property of their
+   respective owners.
+
+   Jean-Loup Gailly and Mark Adler designed the zlib format and wrote
+   the related software described in this specification.  Glenn
+   Randers-Pehrson converted this document to RFC and HTML format.
+
+7. Authors' Addresses
+
+   L. Peter Deutsch
+   Aladdin Enterprises
+   203 Santa Margarita Ave.
+   Menlo Park, CA 94025
+
+   Phone: (415) 322-0103 (AM only)
+   FAX:   (415) 322-1734
+   EMail: <ghost@aladdin.com>
+
+
+   Jean-Loup Gailly
+
+   EMail: <gzip@prep.ai.mit.edu>
+
+   Questions about the technical content of this specification can be
+   sent by email to
+
+   Jean-Loup Gailly <gzip@prep.ai.mit.edu> and
+   Mark Adler <madler@alumni.caltech.edu>
+
+   Editorial comments on this specification can be sent by email to
+
+   L. Peter Deutsch <ghost@aladdin.com> and
+   Glenn Randers-Pehrson <randeg@alumni.rpi.edu>
+
+
+
+
+
+
+Deutsch & Gailly             Informational                      [Page 8]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+8. Appendix: Rationale
+
+   8.1. Preset dictionaries
+
+      A preset dictionary is specially useful to compress short input
+      sequences. The compressor can take advantage of the dictionary
+      context to encode the input in a more compact manner. The
+      decompressor can be initialized with the appropriate context by
+      virtually decompressing a compressed version of the dictionary
+      without producing any output. However for certain compression
+      algorithms such as the deflate algorithm this operation can be
+      achieved without actually performing any decompression.
+
+      The compressor and the decompressor must use exactly the same
+      dictionary. The dictionary may be fixed or may be chosen among a
+      certain number of predefined dictionaries, according to the kind
+      of input data. The decompressor can determine which dictionary has
+      been chosen by the compressor by checking the dictionary
+      identifier. This document does not specify the contents of
+      predefined dictionaries, since the optimal dictionaries are
+      application specific. Standard data formats using this feature of
+      the zlib specification must precisely define the allowed
+      dictionaries.
+
+   8.2. The Adler-32 algorithm
+
+      The Adler-32 algorithm is much faster than the CRC32 algorithm yet
+      still provides an extremely low probability of undetected errors.
+
+      The modulo on unsigned long accumulators can be delayed for 5552
+      bytes, so the modulo operation time is negligible.  If the bytes
+      are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
+      and order sensitive, unlike the first sum, which is just a
+      checksum.  That 65521 is prime is important to avoid a possible
+      large class of two-byte errors that leave the check unchanged.
+      (The Fletcher checksum uses 255, which is not prime and which also
+      makes the Fletcher check insensitive to single byte changes 0 <->
+      255.)
+
+      The sum s1 is initialized to 1 instead of zero to make the length
+      of the sequence part of s2, so that the length does not have to be
+      checked separately. (Any sequence of zeroes has a Fletcher
+      checksum of zero.)
+
+
+
+
+
+
+
+
+Deutsch & Gailly             Informational                      [Page 9]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+9. Appendix: Sample code
+
+   The following C code computes the Adler-32 checksum of a data buffer.
+   It is written for clarity, not for speed.  The sample code is in the
+   ANSI C programming language. Non C users may find it easier to read
+   with these hints:
+
+      &      Bitwise AND operator.
+      >>     Bitwise right shift operator. When applied to an
+             unsigned quantity, as here, right shift inserts zero bit(s)
+             at the left.
+      <<     Bitwise left shift operator. Left shift inserts zero
+             bit(s) at the right.
+      ++     "n++" increments the variable n.
+      %      modulo operator: a % b is the remainder of a divided by b.
+
+      #define BASE 65521 /* largest prime smaller than 65536 */
+
+      /*
+         Update a running Adler-32 checksum with the bytes buf[0..len-1]
+       and return the updated checksum. The Adler-32 checksum should be
+       initialized to 1.
+
+       Usage example:
+
+         unsigned long adler = 1L;
+
+         while (read_buffer(buffer, length) != EOF) {
+           adler = update_adler32(adler, buffer, length);
+         }
+         if (adler != original_adler) error();
+      */
+      unsigned long update_adler32(unsigned long adler,
+         unsigned char *buf, int len)
+      {
+        unsigned long s1 = adler & 0xffff;
+        unsigned long s2 = (adler >> 16) & 0xffff;
+        int n;
+
+        for (n = 0; n < len; n++) {
+          s1 = (s1 + buf[n]) % BASE;
+          s2 = (s2 + s1)     % BASE;
+        }
+        return (s2 << 16) + s1;
+      }
+
+      /* Return the adler32 of the bytes buf[0..len-1] */
+
+
+
+
+Deutsch & Gailly             Informational                     [Page 10]
+\f
+RFC 1950       ZLIB Compressed Data Format Specification        May 1996
+
+
+      unsigned long adler32(unsigned char *buf, int len)
+      {
+        return update_adler32(1L, buf, len);
+      }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Deutsch & Gailly             Informational                     [Page 11]
+\f
diff --git a/deps/libchdr/deps/zlib-1.2.11/doc/rfc1951.txt b/deps/libchdr/deps/zlib-1.2.11/doc/rfc1951.txt
new file mode 100644 (file)
index 0000000..403c8c7
--- /dev/null
@@ -0,0 +1,955 @@
+
+
+
+
+
+
+Network Working Group                                         P. Deutsch
+Request for Comments: 1951                           Aladdin Enterprises
+Category: Informational                                         May 1996
+
+
+        DEFLATE Compressed Data Format Specification version 1.3
+
+Status of This Memo
+
+   This memo provides information for the Internet community.  This memo
+   does not specify an Internet standard of any kind.  Distribution of
+   this memo is unlimited.
+
+IESG Note:
+
+   The IESG takes no position on the validity of any Intellectual
+   Property Rights statements contained in this document.
+
+Notices
+
+   Copyright (c) 1996 L. Peter Deutsch
+
+   Permission is granted to copy and distribute this document for any
+   purpose and without charge, including translations into other
+   languages and incorporation into compilations, provided that the
+   copyright notice and this notice are preserved, and that any
+   substantive changes or deletions from the original are clearly
+   marked.
+
+   A pointer to the latest version of this and related documentation in
+   HTML format can be found at the URL
+   <ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html>.
+
+Abstract
+
+   This specification defines a lossless compressed data format that
+   compresses data using a combination of the LZ77 algorithm and Huffman
+   coding, with efficiency comparable to the best currently available
+   general-purpose compression methods.  The data can be produced or
+   consumed, even for an arbitrarily long sequentially presented input
+   data stream, using only an a priori bounded amount of intermediate
+   storage.  The format can be implemented readily in a manner not
+   covered by patents.
+
+
+
+
+
+
+
+
+Deutsch                      Informational                      [Page 1]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+Table of Contents
+
+   1. Introduction ................................................... 2
+      1.1. Purpose ................................................... 2
+      1.2. Intended audience ......................................... 3
+      1.3. Scope ..................................................... 3
+      1.4. Compliance ................................................ 3
+      1.5.  Definitions of terms and conventions used ................ 3
+      1.6. Changes from previous versions ............................ 4
+   2. Compressed representation overview ............................. 4
+   3. Detailed specification ......................................... 5
+      3.1. Overall conventions ....................................... 5
+          3.1.1. Packing into bytes .................................. 5
+      3.2. Compressed block format ................................... 6
+          3.2.1. Synopsis of prefix and Huffman coding ............... 6
+          3.2.2. Use of Huffman coding in the "deflate" format ....... 7
+          3.2.3. Details of block format ............................. 9
+          3.2.4. Non-compressed blocks (BTYPE=00) ................... 11
+          3.2.5. Compressed blocks (length and distance codes) ...... 11
+          3.2.6. Compression with fixed Huffman codes (BTYPE=01) .... 12
+          3.2.7. Compression with dynamic Huffman codes (BTYPE=10) .. 13
+      3.3. Compliance ............................................... 14
+   4. Compression algorithm details ................................. 14
+   5. References .................................................... 16
+   6. Security Considerations ....................................... 16
+   7. Source code ................................................... 16
+   8. Acknowledgements .............................................. 16
+   9. Author's Address .............................................. 17
+
+1. Introduction
+
+   1.1. Purpose
+
+      The purpose of this specification is to define a lossless
+      compressed data format that:
+          * Is independent of CPU type, operating system, file system,
+            and character set, and hence can be used for interchange;
+          * Can be produced or consumed, even for an arbitrarily long
+            sequentially presented input data stream, using only an a
+            priori bounded amount of intermediate storage, and hence
+            can be used in data communications or similar structures
+            such as Unix filters;
+          * Compresses data with efficiency comparable to the best
+            currently available general-purpose compression methods,
+            and in particular considerably better than the "compress"
+            program;
+          * Can be implemented readily in a manner not covered by
+            patents, and hence can be practiced freely;
+
+
+
+Deutsch                      Informational                      [Page 2]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+          * Is compatible with the file format produced by the current
+            widely used gzip utility, in that conforming decompressors
+            will be able to read data produced by the existing gzip
+            compressor.
+
+      The data format defined by this specification does not attempt to:
+
+          * Allow random access to compressed data;
+          * Compress specialized data (e.g., raster graphics) as well
+            as the best currently available specialized algorithms.
+
+      A simple counting argument shows that no lossless compression
+      algorithm can compress every possible input data set.  For the
+      format defined here, the worst case expansion is 5 bytes per 32K-
+      byte block, i.e., a size increase of 0.015% for large data sets.
+      English text usually compresses by a factor of 2.5 to 3;
+      executable files usually compress somewhat less; graphical data
+      such as raster images may compress much more.
+
+   1.2. Intended audience
+
+      This specification is intended for use by implementors of software
+      to compress data into "deflate" format and/or decompress data from
+      "deflate" format.
+
+      The text of the specification assumes a basic background in
+      programming at the level of bits and other primitive data
+      representations.  Familiarity with the technique of Huffman coding
+      is helpful but not required.
+
+   1.3. Scope
+
+      The specification specifies a method for representing a sequence
+      of bytes as a (usually shorter) sequence of bits, and a method for
+      packing the latter bit sequence into bytes.
+
+   1.4. Compliance
+
+      Unless otherwise indicated below, a compliant decompressor must be
+      able to accept and decompress any data set that conforms to all
+      the specifications presented here; a compliant compressor must
+      produce data sets that conform to all the specifications presented
+      here.
+
+   1.5.  Definitions of terms and conventions used
+
+      Byte: 8 bits stored or transmitted as a unit (same as an octet).
+      For this specification, a byte is exactly 8 bits, even on machines
+
+
+
+Deutsch                      Informational                      [Page 3]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+      which store a character on a number of bits different from eight.
+      See below, for the numbering of bits within a byte.
+
+      String: a sequence of arbitrary bytes.
+
+   1.6. Changes from previous versions
+
+      There have been no technical changes to the deflate format since
+      version 1.1 of this specification.  In version 1.2, some
+      terminology was changed.  Version 1.3 is a conversion of the
+      specification to RFC style.
+
+2. Compressed representation overview
+
+   A compressed data set consists of a series of blocks, corresponding
+   to successive blocks of input data.  The block sizes are arbitrary,
+   except that non-compressible blocks are limited to 65,535 bytes.
+
+   Each block is compressed using a combination of the LZ77 algorithm
+   and Huffman coding. The Huffman trees for each block are independent
+   of those for previous or subsequent blocks; the LZ77 algorithm may
+   use a reference to a duplicated string occurring in a previous block,
+   up to 32K input bytes before.
+
+   Each block consists of two parts: a pair of Huffman code trees that
+   describe the representation of the compressed data part, and a
+   compressed data part.  (The Huffman trees themselves are compressed
+   using Huffman encoding.)  The compressed data consists of a series of
+   elements of two types: literal bytes (of strings that have not been
+   detected as duplicated within the previous 32K input bytes), and
+   pointers to duplicated strings, where a pointer is represented as a
+   pair <length, backward distance>.  The representation used in the
+   "deflate" format limits distances to 32K bytes and lengths to 258
+   bytes, but does not limit the size of a block, except for
+   uncompressible blocks, which are limited as noted above.
+
+   Each type of value (literals, distances, and lengths) in the
+   compressed data is represented using a Huffman code, using one code
+   tree for literals and lengths and a separate code tree for distances.
+   The code trees for each block appear in a compact form just before
+   the compressed data for that block.
+
+
+
+
+
+
+
+
+
+
+Deutsch                      Informational                      [Page 4]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+3. Detailed specification
+
+   3.1. Overall conventions In the diagrams below, a box like this:
+
+         +---+
+         |   | <-- the vertical bars might be missing
+         +---+
+
+      represents one byte; a box like this:
+
+         +==============+
+         |              |
+         +==============+
+
+      represents a variable number of bytes.
+
+      Bytes stored within a computer do not have a "bit order", since
+      they are always treated as a unit.  However, a byte considered as
+      an integer between 0 and 255 does have a most- and least-
+      significant bit, and since we write numbers with the most-
+      significant digit on the left, we also write bytes with the most-
+      significant bit on the left.  In the diagrams below, we number the
+      bits of a byte so that bit 0 is the least-significant bit, i.e.,
+      the bits are numbered:
+
+         +--------+
+         |76543210|
+         +--------+
+
+      Within a computer, a number may occupy multiple bytes.  All
+      multi-byte numbers in the format described here are stored with
+      the least-significant byte first (at the lower memory address).
+      For example, the decimal number 520 is stored as:
+
+             0        1
+         +--------+--------+
+         |00001000|00000010|
+         +--------+--------+
+          ^        ^
+          |        |
+          |        + more significant byte = 2 x 256
+          + less significant byte = 8
+
+      3.1.1. Packing into bytes
+
+         This document does not address the issue of the order in which
+         bits of a byte are transmitted on a bit-sequential medium,
+         since the final data format described here is byte- rather than
+
+
+
+Deutsch                      Informational                      [Page 5]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+         bit-oriented.  However, we describe the compressed block format
+         in below, as a sequence of data elements of various bit
+         lengths, not a sequence of bytes.  We must therefore specify
+         how to pack these data elements into bytes to form the final
+         compressed byte sequence:
+
+             * Data elements are packed into bytes in order of
+               increasing bit number within the byte, i.e., starting
+               with the least-significant bit of the byte.
+             * Data elements other than Huffman codes are packed
+               starting with the least-significant bit of the data
+               element.
+             * Huffman codes are packed starting with the most-
+               significant bit of the code.
+
+         In other words, if one were to print out the compressed data as
+         a sequence of bytes, starting with the first byte at the
+         *right* margin and proceeding to the *left*, with the most-
+         significant bit of each byte on the left as usual, one would be
+         able to parse the result from right to left, with fixed-width
+         elements in the correct MSB-to-LSB order and Huffman codes in
+         bit-reversed order (i.e., with the first bit of the code in the
+         relative LSB position).
+
+   3.2. Compressed block format
+
+      3.2.1. Synopsis of prefix and Huffman coding
+
+         Prefix coding represents symbols from an a priori known
+         alphabet by bit sequences (codes), one code for each symbol, in
+         a manner such that different symbols may be represented by bit
+         sequences of different lengths, but a parser can always parse
+         an encoded string unambiguously symbol-by-symbol.
+
+         We define a prefix code in terms of a binary tree in which the
+         two edges descending from each non-leaf node are labeled 0 and
+         1 and in which the leaf nodes correspond one-for-one with (are
+         labeled with) the symbols of the alphabet; then the code for a
+         symbol is the sequence of 0's and 1's on the edges leading from
+         the root to the leaf labeled with that symbol.  For example:
+
+
+
+
+
+
+
+
+
+
+
+Deutsch                      Informational                      [Page 6]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+                          /\              Symbol    Code
+                         0  1             ------    ----
+                        /    \                A      00
+                       /\     B               B       1
+                      0  1                    C     011
+                     /    \                   D     010
+                    A     /\
+                         0  1
+                        /    \
+                       D      C
+
+         A parser can decode the next symbol from an encoded input
+         stream by walking down the tree from the root, at each step
+         choosing the edge corresponding to the next input bit.
+
+         Given an alphabet with known symbol frequencies, the Huffman
+         algorithm allows the construction of an optimal prefix code
+         (one which represents strings with those symbol frequencies
+         using the fewest bits of any possible prefix codes for that
+         alphabet).  Such a code is called a Huffman code.  (See
+         reference [1] in Chapter 5, references for additional
+         information on Huffman codes.)
+
+         Note that in the "deflate" format, the Huffman codes for the
+         various alphabets must not exceed certain maximum code lengths.
+         This constraint complicates the algorithm for computing code
+         lengths from symbol frequencies.  Again, see Chapter 5,
+         references for details.
+
+      3.2.2. Use of Huffman coding in the "deflate" format
+
+         The Huffman codes used for each alphabet in the "deflate"
+         format have two additional rules:
+
+             * All codes of a given bit length have lexicographically
+               consecutive values, in the same order as the symbols
+               they represent;
+
+             * Shorter codes lexicographically precede longer codes.
+
+
+
+
+
+
+
+
+
+
+
+
+Deutsch                      Informational                      [Page 7]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+         We could recode the example above to follow this rule as
+         follows, assuming that the order of the alphabet is ABCD:
+
+            Symbol  Code
+            ------  ----
+            A       10
+            B       0
+            C       110
+            D       111
+
+         I.e., 0 precedes 10 which precedes 11x, and 110 and 111 are
+         lexicographically consecutive.
+
+         Given this rule, we can define the Huffman code for an alphabet
+         just by giving the bit lengths of the codes for each symbol of
+         the alphabet in order; this is sufficient to determine the
+         actual codes.  In our example, the code is completely defined
+         by the sequence of bit lengths (2, 1, 3, 3).  The following
+         algorithm generates the codes as integers, intended to be read
+         from most- to least-significant bit.  The code lengths are
+         initially in tree[I].Len; the codes are produced in
+         tree[I].Code.
+
+         1)  Count the number of codes for each code length.  Let
+             bl_count[N] be the number of codes of length N, N >= 1.
+
+         2)  Find the numerical value of the smallest code for each
+             code length:
+
+                code = 0;
+                bl_count[0] = 0;
+                for (bits = 1; bits <= MAX_BITS; bits++) {
+                    code = (code + bl_count[bits-1]) << 1;
+                    next_code[bits] = code;
+                }
+
+         3)  Assign numerical values to all codes, using consecutive
+             values for all codes of the same length with the base
+             values determined at step 2. Codes that are never used
+             (which have a bit length of zero) must not be assigned a
+             value.
+
+                for (n = 0;  n <= max_code; n++) {
+                    len = tree[n].Len;
+                    if (len != 0) {
+                        tree[n].Code = next_code[len];
+                        next_code[len]++;
+                    }
+
+
+
+Deutsch                      Informational                      [Page 8]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+                }
+
+         Example:
+
+         Consider the alphabet ABCDEFGH, with bit lengths (3, 3, 3, 3,
+         3, 2, 4, 4).  After step 1, we have:
+
+            N      bl_count[N]
+            -      -----------
+            2      1
+            3      5
+            4      2
+
+         Step 2 computes the following next_code values:
+
+            N      next_code[N]
+            -      ------------
+            1      0
+            2      0
+            3      2
+            4      14
+
+         Step 3 produces the following code values:
+
+            Symbol Length   Code
+            ------ ------   ----
+            A       3        010
+            B       3        011
+            C       3        100
+            D       3        101
+            E       3        110
+            F       2         00
+            G       4       1110
+            H       4       1111
+
+      3.2.3. Details of block format
+
+         Each block of compressed data begins with 3 header bits
+         containing the following data:
+
+            first bit       BFINAL
+            next 2 bits     BTYPE
+
+         Note that the header bits do not necessarily begin on a byte
+         boundary, since a block does not necessarily occupy an integral
+         number of bytes.
+
+
+
+
+
+Deutsch                      Informational                      [Page 9]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+         BFINAL is set if and only if this is the last block of the data
+         set.
+
+         BTYPE specifies how the data are compressed, as follows:
+
+            00 - no compression
+            01 - compressed with fixed Huffman codes
+            10 - compressed with dynamic Huffman codes
+            11 - reserved (error)
+
+         The only difference between the two compressed cases is how the
+         Huffman codes for the literal/length and distance alphabets are
+         defined.
+
+         In all cases, the decoding algorithm for the actual data is as
+         follows:
+
+            do
+               read block header from input stream.
+               if stored with no compression
+                  skip any remaining bits in current partially
+                     processed byte
+                  read LEN and NLEN (see next section)
+                  copy LEN bytes of data to output
+               otherwise
+                  if compressed with dynamic Huffman codes
+                     read representation of code trees (see
+                        subsection below)
+                  loop (until end of block code recognized)
+                     decode literal/length value from input stream
+                     if value < 256
+                        copy value (literal byte) to output stream
+                     otherwise
+                        if value = end of block (256)
+                           break from loop
+                        otherwise (value = 257..285)
+                           decode distance from input stream
+
+                           move backwards distance bytes in the output
+                           stream, and copy length bytes from this
+                           position to the output stream.
+                  end loop
+            while not last block
+
+         Note that a duplicated string reference may refer to a string
+         in a previous block; i.e., the backward distance may cross one
+         or more block boundaries.  However a distance cannot refer past
+         the beginning of the output stream.  (An application using a
+
+
+
+Deutsch                      Informational                     [Page 10]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+         preset dictionary might discard part of the output stream; a
+         distance can refer to that part of the output stream anyway)
+         Note also that the referenced string may overlap the current
+         position; for example, if the last 2 bytes decoded have values
+         X and Y, a string reference with <length = 5, distance = 2>
+         adds X,Y,X,Y,X to the output stream.
+
+         We now specify each compression method in turn.
+
+      3.2.4. Non-compressed blocks (BTYPE=00)
+
+         Any bits of input up to the next byte boundary are ignored.
+         The rest of the block consists of the following information:
+
+              0   1   2   3   4...
+            +---+---+---+---+================================+
+            |  LEN  | NLEN  |... LEN bytes of literal data...|
+            +---+---+---+---+================================+
+
+         LEN is the number of data bytes in the block.  NLEN is the
+         one's complement of LEN.
+
+      3.2.5. Compressed blocks (length and distance codes)
+
+         As noted above, encoded data blocks in the "deflate" format
+         consist of sequences of symbols drawn from three conceptually
+         distinct alphabets: either literal bytes, from the alphabet of
+         byte values (0..255), or <length, backward distance> pairs,
+         where the length is drawn from (3..258) and the distance is
+         drawn from (1..32,768).  In fact, the literal and length
+         alphabets are merged into a single alphabet (0..285), where
+         values 0..255 represent literal bytes, the value 256 indicates
+         end-of-block, and values 257..285 represent length codes
+         (possibly in conjunction with extra bits following the symbol
+         code) as follows:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Deutsch                      Informational                     [Page 11]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+                 Extra               Extra               Extra
+            Code Bits Length(s) Code Bits Lengths   Code Bits Length(s)
+            ---- ---- ------     ---- ---- -------   ---- ---- -------
+             257   0     3       267   1   15,16     277   4   67-82
+             258   0     4       268   1   17,18     278   4   83-98
+             259   0     5       269   2   19-22     279   4   99-114
+             260   0     6       270   2   23-26     280   4  115-130
+             261   0     7       271   2   27-30     281   5  131-162
+             262   0     8       272   2   31-34     282   5  163-194
+             263   0     9       273   3   35-42     283   5  195-226
+             264   0    10       274   3   43-50     284   5  227-257
+             265   1  11,12      275   3   51-58     285   0    258
+             266   1  13,14      276   3   59-66
+
+         The extra bits should be interpreted as a machine integer
+         stored with the most-significant bit first, e.g., bits 1110
+         represent the value 14.
+
+                  Extra           Extra               Extra
+             Code Bits Dist  Code Bits   Dist     Code Bits Distance
+             ---- ---- ----  ---- ----  ------    ---- ---- --------
+               0   0    1     10   4     33-48    20    9   1025-1536
+               1   0    2     11   4     49-64    21    9   1537-2048
+               2   0    3     12   5     65-96    22   10   2049-3072
+               3   0    4     13   5     97-128   23   10   3073-4096
+               4   1   5,6    14   6    129-192   24   11   4097-6144
+               5   1   7,8    15   6    193-256   25   11   6145-8192
+               6   2   9-12   16   7    257-384   26   12  8193-12288
+               7   2  13-16   17   7    385-512   27   12 12289-16384
+               8   3  17-24   18   8    513-768   28   13 16385-24576
+               9   3  25-32   19   8   769-1024   29   13 24577-32768
+
+      3.2.6. Compression with fixed Huffman codes (BTYPE=01)
+
+         The Huffman codes for the two alphabets are fixed, and are not
+         represented explicitly in the data.  The Huffman code lengths
+         for the literal/length alphabet are:
+
+                   Lit Value    Bits        Codes
+                   ---------    ----        -----
+                     0 - 143     8          00110000 through
+                                            10111111
+                   144 - 255     9          110010000 through
+                                            111111111
+                   256 - 279     7          0000000 through
+                                            0010111
+                   280 - 287     8          11000000 through
+                                            11000111
+
+
+
+Deutsch                      Informational                     [Page 12]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+         The code lengths are sufficient to generate the actual codes,
+         as described above; we show the codes in the table for added
+         clarity.  Literal/length values 286-287 will never actually
+         occur in the compressed data, but participate in the code
+         construction.
+
+         Distance codes 0-31 are represented by (fixed-length) 5-bit
+         codes, with possible additional bits as shown in the table
+         shown in Paragraph 3.2.5, above.  Note that distance codes 30-
+         31 will never actually occur in the compressed data.
+
+      3.2.7. Compression with dynamic Huffman codes (BTYPE=10)
+
+         The Huffman codes for the two alphabets appear in the block
+         immediately after the header bits and before the actual
+         compressed data, first the literal/length code and then the
+         distance code.  Each code is defined by a sequence of code
+         lengths, as discussed in Paragraph 3.2.2, above.  For even
+         greater compactness, the code length sequences themselves are
+         compressed using a Huffman code.  The alphabet for code lengths
+         is as follows:
+
+               0 - 15: Represent code lengths of 0 - 15
+                   16: Copy the previous code length 3 - 6 times.
+                       The next 2 bits indicate repeat length
+                             (0 = 3, ... , 3 = 6)
+                          Example:  Codes 8, 16 (+2 bits 11),
+                                    16 (+2 bits 10) will expand to
+                                    12 code lengths of 8 (1 + 6 + 5)
+                   17: Repeat a code length of 0 for 3 - 10 times.
+                       (3 bits of length)
+                   18: Repeat a code length of 0 for 11 - 138 times
+                       (7 bits of length)
+
+         A code length of 0 indicates that the corresponding symbol in
+         the literal/length or distance alphabet will not occur in the
+         block, and should not participate in the Huffman code
+         construction algorithm given earlier.  If only one distance
+         code is used, it is encoded using one bit, not zero bits; in
+         this case there is a single code length of one, with one unused
+         code.  One distance code of zero bits means that there are no
+         distance codes used at all (the data is all literals).
+
+         We can now define the format of the block:
+
+               5 Bits: HLIT, # of Literal/Length codes - 257 (257 - 286)
+               5 Bits: HDIST, # of Distance codes - 1        (1 - 32)
+               4 Bits: HCLEN, # of Code Length codes - 4     (4 - 19)
+
+
+
+Deutsch                      Informational                     [Page 13]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+               (HCLEN + 4) x 3 bits: code lengths for the code length
+                  alphabet given just above, in the order: 16, 17, 18,
+                  0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+
+                  These code lengths are interpreted as 3-bit integers
+                  (0-7); as above, a code length of 0 means the
+                  corresponding symbol (literal/length or distance code
+                  length) is not used.
+
+               HLIT + 257 code lengths for the literal/length alphabet,
+                  encoded using the code length Huffman code
+
+               HDIST + 1 code lengths for the distance alphabet,
+                  encoded using the code length Huffman code
+
+               The actual compressed data of the block,
+                  encoded using the literal/length and distance Huffman
+                  codes
+
+               The literal/length symbol 256 (end of data),
+                  encoded using the literal/length Huffman code
+
+         The code length repeat codes can cross from HLIT + 257 to the
+         HDIST + 1 code lengths.  In other words, all code lengths form
+         a single sequence of HLIT + HDIST + 258 values.
+
+   3.3. Compliance
+
+      A compressor may limit further the ranges of values specified in
+      the previous section and still be compliant; for example, it may
+      limit the range of backward pointers to some value smaller than
+      32K.  Similarly, a compressor may limit the size of blocks so that
+      a compressible block fits in memory.
+
+      A compliant decompressor must accept the full range of possible
+      values defined in the previous section, and must accept blocks of
+      arbitrary size.
+
+4. Compression algorithm details
+
+   While it is the intent of this document to define the "deflate"
+   compressed data format without reference to any particular
+   compression algorithm, the format is related to the compressed
+   formats produced by LZ77 (Lempel-Ziv 1977, see reference [2] below);
+   since many variations of LZ77 are patented, it is strongly
+   recommended that the implementor of a compressor follow the general
+   algorithm presented here, which is known not to be patented per se.
+   The material in this section is not part of the definition of the
+
+
+
+Deutsch                      Informational                     [Page 14]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+   specification per se, and a compressor need not follow it in order to
+   be compliant.
+
+   The compressor terminates a block when it determines that starting a
+   new block with fresh trees would be useful, or when the block size
+   fills up the compressor's block buffer.
+
+   The compressor uses a chained hash table to find duplicated strings,
+   using a hash function that operates on 3-byte sequences.  At any
+   given point during compression, let XYZ be the next 3 input bytes to
+   be examined (not necessarily all different, of course).  First, the
+   compressor examines the hash chain for XYZ.  If the chain is empty,
+   the compressor simply writes out X as a literal byte and advances one
+   byte in the input.  If the hash chain is not empty, indicating that
+   the sequence XYZ (or, if we are unlucky, some other 3 bytes with the
+   same hash function value) has occurred recently, the compressor
+   compares all strings on the XYZ hash chain with the actual input data
+   sequence starting at the current point, and selects the longest
+   match.
+
+   The compressor searches the hash chains starting with the most recent
+   strings, to favor small distances and thus take advantage of the
+   Huffman encoding.  The hash chains are singly linked. There are no
+   deletions from the hash chains; the algorithm simply discards matches
+   that are too old.  To avoid a worst-case situation, very long hash
+   chains are arbitrarily truncated at a certain length, determined by a
+   run-time parameter.
+
+   To improve overall compression, the compressor optionally defers the
+   selection of matches ("lazy matching"): after a match of length N has
+   been found, the compressor searches for a longer match starting at
+   the next input byte.  If it finds a longer match, it truncates the
+   previous match to a length of one (thus producing a single literal
+   byte) and then emits the longer match.  Otherwise, it emits the
+   original match, and, as described above, advances N bytes before
+   continuing.
+
+   Run-time parameters also control this "lazy match" procedure.  If
+   compression ratio is most important, the compressor attempts a
+   complete second search regardless of the length of the first match.
+   In the normal case, if the current match is "long enough", the
+   compressor reduces the search for a longer match, thus speeding up
+   the process.  If speed is most important, the compressor inserts new
+   strings in the hash table only when no match was found, or when the
+   match is not "too long".  This degrades the compression ratio but
+   saves time since there are both fewer insertions and fewer searches.
+
+
+
+
+
+Deutsch                      Informational                     [Page 15]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+5. References
+
+   [1] Huffman, D. A., "A Method for the Construction of Minimum
+       Redundancy Codes", Proceedings of the Institute of Radio
+       Engineers, September 1952, Volume 40, Number 9, pp. 1098-1101.
+
+   [2] Ziv J., Lempel A., "A Universal Algorithm for Sequential Data
+       Compression", IEEE Transactions on Information Theory, Vol. 23,
+       No. 3, pp. 337-343.
+
+   [3] Gailly, J.-L., and Adler, M., ZLIB documentation and sources,
+       available in ftp://ftp.uu.net/pub/archiving/zip/doc/
+
+   [4] Gailly, J.-L., and Adler, M., GZIP documentation and sources,
+       available as gzip-*.tar in ftp://prep.ai.mit.edu/pub/gnu/
+
+   [5] Schwartz, E. S., and Kallick, B. "Generating a canonical prefix
+       encoding." Comm. ACM, 7,3 (Mar. 1964), pp. 166-169.
+
+   [6] Hirschberg and Lelewer, "Efficient decoding of prefix codes,"
+       Comm. ACM, 33,4, April 1990, pp. 449-459.
+
+6. Security Considerations
+
+   Any data compression method involves the reduction of redundancy in
+   the data.  Consequently, any corruption of the data is likely to have
+   severe effects and be difficult to correct.  Uncompressed text, on
+   the other hand, will probably still be readable despite the presence
+   of some corrupted bytes.
+
+   It is recommended that systems using this data format provide some
+   means of validating the integrity of the compressed data.  See
+   reference [3], for example.
+
+7. Source code
+
+   Source code for a C language implementation of a "deflate" compliant
+   compressor and decompressor is available within the zlib package at
+   ftp://ftp.uu.net/pub/archiving/zip/zlib/.
+
+8. Acknowledgements
+
+   Trademarks cited in this document are the property of their
+   respective owners.
+
+   Phil Katz designed the deflate format.  Jean-Loup Gailly and Mark
+   Adler wrote the related software described in this specification.
+   Glenn Randers-Pehrson converted this document to RFC and HTML format.
+
+
+
+Deutsch                      Informational                     [Page 16]
+\f
+RFC 1951      DEFLATE Compressed Data Format Specification      May 1996
+
+
+9. Author's Address
+
+   L. Peter Deutsch
+   Aladdin Enterprises
+   203 Santa Margarita Ave.
+   Menlo Park, CA 94025
+
+   Phone: (415) 322-0103 (AM only)
+   FAX:   (415) 322-1734
+   EMail: <ghost@aladdin.com>
+
+   Questions about the technical content of this specification can be
+   sent by email to:
+
+   Jean-Loup Gailly <gzip@prep.ai.mit.edu> and
+   Mark Adler <madler@alumni.caltech.edu>
+
+   Editorial comments on this specification can be sent by email to:
+
+   L. Peter Deutsch <ghost@aladdin.com> and
+   Glenn Randers-Pehrson <randeg@alumni.rpi.edu>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Deutsch                      Informational                     [Page 17]
+\f
diff --git a/deps/libchdr/deps/zlib-1.2.11/doc/rfc1952.txt b/deps/libchdr/deps/zlib-1.2.11/doc/rfc1952.txt
new file mode 100644 (file)
index 0000000..a8e51b4
--- /dev/null
@@ -0,0 +1,675 @@
+
+
+
+
+
+
+Network Working Group                                         P. Deutsch
+Request for Comments: 1952                           Aladdin Enterprises
+Category: Informational                                         May 1996
+
+
+               GZIP file format specification version 4.3
+
+Status of This Memo
+
+   This memo provides information for the Internet community.  This memo
+   does not specify an Internet standard of any kind.  Distribution of
+   this memo is unlimited.
+
+IESG Note:
+
+   The IESG takes no position on the validity of any Intellectual
+   Property Rights statements contained in this document.
+
+Notices
+
+   Copyright (c) 1996 L. Peter Deutsch
+
+   Permission is granted to copy and distribute this document for any
+   purpose and without charge, including translations into other
+   languages and incorporation into compilations, provided that the
+   copyright notice and this notice are preserved, and that any
+   substantive changes or deletions from the original are clearly
+   marked.
+
+   A pointer to the latest version of this and related documentation in
+   HTML format can be found at the URL
+   <ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html>.
+
+Abstract
+
+   This specification defines a lossless compressed data format that is
+   compatible with the widely used GZIP utility.  The format includes a
+   cyclic redundancy check value for detecting data corruption.  The
+   format presently uses the DEFLATE method of compression but can be
+   easily extended to use other compression methods.  The format can be
+   implemented readily in a manner not covered by patents.
+
+
+
+
+
+
+
+
+
+
+Deutsch                      Informational                      [Page 1]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+Table of Contents
+
+   1. Introduction ................................................... 2
+      1.1. Purpose ................................................... 2
+      1.2. Intended audience ......................................... 3
+      1.3. Scope ..................................................... 3
+      1.4. Compliance ................................................ 3
+      1.5. Definitions of terms and conventions used ................. 3
+      1.6. Changes from previous versions ............................ 3
+   2. Detailed specification ......................................... 4
+      2.1. Overall conventions ....................................... 4
+      2.2. File format ............................................... 5
+      2.3. Member format ............................................. 5
+          2.3.1. Member header and trailer ........................... 6
+              2.3.1.1. Extra field ................................... 8
+              2.3.1.2. Compliance .................................... 9
+      3. References .................................................. 9
+      4. Security Considerations .................................... 10
+      5. Acknowledgements ........................................... 10
+      6. Author's Address ........................................... 10
+      7. Appendix: Jean-Loup Gailly's gzip utility .................. 11
+      8. Appendix: Sample CRC Code .................................. 11
+
+1. Introduction
+
+   1.1. Purpose
+
+      The purpose of this specification is to define a lossless
+      compressed data format that:
+
+          * Is independent of CPU type, operating system, file system,
+            and character set, and hence can be used for interchange;
+          * Can compress or decompress a data stream (as opposed to a
+            randomly accessible file) to produce another data stream,
+            using only an a priori bounded amount of intermediate
+            storage, and hence can be used in data communications or
+            similar structures such as Unix filters;
+          * Compresses data with efficiency comparable to the best
+            currently available general-purpose compression methods,
+            and in particular considerably better than the "compress"
+            program;
+          * Can be implemented readily in a manner not covered by
+            patents, and hence can be practiced freely;
+          * Is compatible with the file format produced by the current
+            widely used gzip utility, in that conforming decompressors
+            will be able to read data produced by the existing gzip
+            compressor.
+
+
+
+
+Deutsch                      Informational                      [Page 2]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+      The data format defined by this specification does not attempt to:
+
+          * Provide random access to compressed data;
+          * Compress specialized data (e.g., raster graphics) as well as
+            the best currently available specialized algorithms.
+
+   1.2. Intended audience
+
+      This specification is intended for use by implementors of software
+      to compress data into gzip format and/or decompress data from gzip
+      format.
+
+      The text of the specification assumes a basic background in
+      programming at the level of bits and other primitive data
+      representations.
+
+   1.3. Scope
+
+      The specification specifies a compression method and a file format
+      (the latter assuming only that a file can store a sequence of
+      arbitrary bytes).  It does not specify any particular interface to
+      a file system or anything about character sets or encodings
+      (except for file names and comments, which are optional).
+
+   1.4. Compliance
+
+      Unless otherwise indicated below, a compliant decompressor must be
+      able to accept and decompress any file that conforms to all the
+      specifications presented here; a compliant compressor must produce
+      files that conform to all the specifications presented here.  The
+      material in the appendices is not part of the specification per se
+      and is not relevant to compliance.
+
+   1.5. Definitions of terms and conventions used
+
+      byte: 8 bits stored or transmitted as a unit (same as an octet).
+      (For this specification, a byte is exactly 8 bits, even on
+      machines which store a character on a number of bits different
+      from 8.)  See below for the numbering of bits within a byte.
+
+   1.6. Changes from previous versions
+
+      There have been no technical changes to the gzip format since
+      version 4.1 of this specification.  In version 4.2, some
+      terminology was changed, and the sample CRC code was rewritten for
+      clarity and to eliminate the requirement for the caller to do pre-
+      and post-conditioning.  Version 4.3 is a conversion of the
+      specification to RFC style.
+
+
+
+Deutsch                      Informational                      [Page 3]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+2. Detailed specification
+
+   2.1. Overall conventions
+
+      In the diagrams below, a box like this:
+
+         +---+
+         |   | <-- the vertical bars might be missing
+         +---+
+
+      represents one byte; a box like this:
+
+         +==============+
+         |              |
+         +==============+
+
+      represents a variable number of bytes.
+
+      Bytes stored within a computer do not have a "bit order", since
+      they are always treated as a unit.  However, a byte considered as
+      an integer between 0 and 255 does have a most- and least-
+      significant bit, and since we write numbers with the most-
+      significant digit on the left, we also write bytes with the most-
+      significant bit on the left.  In the diagrams below, we number the
+      bits of a byte so that bit 0 is the least-significant bit, i.e.,
+      the bits are numbered:
+
+         +--------+
+         |76543210|
+         +--------+
+
+      This document does not address the issue of the order in which
+      bits of a byte are transmitted on a bit-sequential medium, since
+      the data format described here is byte- rather than bit-oriented.
+
+      Within a computer, a number may occupy multiple bytes.  All
+      multi-byte numbers in the format described here are stored with
+      the least-significant byte first (at the lower memory address).
+      For example, the decimal number 520 is stored as:
+
+             0        1
+         +--------+--------+
+         |00001000|00000010|
+         +--------+--------+
+          ^        ^
+          |        |
+          |        + more significant byte = 2 x 256
+          + less significant byte = 8
+
+
+
+Deutsch                      Informational                      [Page 4]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+   2.2. File format
+
+      A gzip file consists of a series of "members" (compressed data
+      sets).  The format of each member is specified in the following
+      section.  The members simply appear one after another in the file,
+      with no additional information before, between, or after them.
+
+   2.3. Member format
+
+      Each member has the following structure:
+
+         +---+---+---+---+---+---+---+---+---+---+
+         |ID1|ID2|CM |FLG|     MTIME     |XFL|OS | (more-->)
+         +---+---+---+---+---+---+---+---+---+---+
+
+      (if FLG.FEXTRA set)
+
+         +---+---+=================================+
+         | XLEN  |...XLEN bytes of "extra field"...| (more-->)
+         +---+---+=================================+
+
+      (if FLG.FNAME set)
+
+         +=========================================+
+         |...original file name, zero-terminated...| (more-->)
+         +=========================================+
+
+      (if FLG.FCOMMENT set)
+
+         +===================================+
+         |...file comment, zero-terminated...| (more-->)
+         +===================================+
+
+      (if FLG.FHCRC set)
+
+         +---+---+
+         | CRC16 |
+         +---+---+
+
+         +=======================+
+         |...compressed blocks...| (more-->)
+         +=======================+
+
+           0   1   2   3   4   5   6   7
+         +---+---+---+---+---+---+---+---+
+         |     CRC32     |     ISIZE     |
+         +---+---+---+---+---+---+---+---+
+
+
+
+
+Deutsch                      Informational                      [Page 5]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+      2.3.1. Member header and trailer
+
+         ID1 (IDentification 1)
+         ID2 (IDentification 2)
+            These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139
+            (0x8b, \213), to identify the file as being in gzip format.
+
+         CM (Compression Method)
+            This identifies the compression method used in the file.  CM
+            = 0-7 are reserved.  CM = 8 denotes the "deflate"
+            compression method, which is the one customarily used by
+            gzip and which is documented elsewhere.
+
+         FLG (FLaGs)
+            This flag byte is divided into individual bits as follows:
+
+               bit 0   FTEXT
+               bit 1   FHCRC
+               bit 2   FEXTRA
+               bit 3   FNAME
+               bit 4   FCOMMENT
+               bit 5   reserved
+               bit 6   reserved
+               bit 7   reserved
+
+            If FTEXT is set, the file is probably ASCII text.  This is
+            an optional indication, which the compressor may set by
+            checking a small amount of the input data to see whether any
+            non-ASCII characters are present.  In case of doubt, FTEXT
+            is cleared, indicating binary data. For systems which have
+            different file formats for ascii text and binary data, the
+            decompressor can use FTEXT to choose the appropriate format.
+            We deliberately do not specify the algorithm used to set
+            this bit, since a compressor always has the option of
+            leaving it cleared and a decompressor always has the option
+            of ignoring it and letting some other program handle issues
+            of data conversion.
+
+            If FHCRC is set, a CRC16 for the gzip header is present,
+            immediately before the compressed data. The CRC16 consists
+            of the two least significant bytes of the CRC32 for all
+            bytes of the gzip header up to and not including the CRC16.
+            [The FHCRC bit was never set by versions of gzip up to
+            1.2.4, even though it was documented with a different
+            meaning in gzip 1.2.4.]
+
+            If FEXTRA is set, optional extra fields are present, as
+            described in a following section.
+
+
+
+Deutsch                      Informational                      [Page 6]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+            If FNAME is set, an original file name is present,
+            terminated by a zero byte.  The name must consist of ISO
+            8859-1 (LATIN-1) characters; on operating systems using
+            EBCDIC or any other character set for file names, the name
+            must be translated to the ISO LATIN-1 character set.  This
+            is the original name of the file being compressed, with any
+            directory components removed, and, if the file being
+            compressed is on a file system with case insensitive names,
+            forced to lower case. There is no original file name if the
+            data was compressed from a source other than a named file;
+            for example, if the source was stdin on a Unix system, there
+            is no file name.
+
+            If FCOMMENT is set, a zero-terminated file comment is
+            present.  This comment is not interpreted; it is only
+            intended for human consumption.  The comment must consist of
+            ISO 8859-1 (LATIN-1) characters.  Line breaks should be
+            denoted by a single line feed character (10 decimal).
+
+            Reserved FLG bits must be zero.
+
+         MTIME (Modification TIME)
+            This gives the most recent modification time of the original
+            file being compressed.  The time is in Unix format, i.e.,
+            seconds since 00:00:00 GMT, Jan.  1, 1970.  (Note that this
+            may cause problems for MS-DOS and other systems that use
+            local rather than Universal time.)  If the compressed data
+            did not come from a file, MTIME is set to the time at which
+            compression started.  MTIME = 0 means no time stamp is
+            available.
+
+         XFL (eXtra FLags)
+            These flags are available for use by specific compression
+            methods.  The "deflate" method (CM = 8) sets these flags as
+            follows:
+
+               XFL = 2 - compressor used maximum compression,
+                         slowest algorithm
+               XFL = 4 - compressor used fastest algorithm
+
+         OS (Operating System)
+            This identifies the type of file system on which compression
+            took place.  This may be useful in determining end-of-line
+            convention for text files.  The currently defined values are
+            as follows:
+
+
+
+
+
+
+Deutsch                      Informational                      [Page 7]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+                 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32)
+                 1 - Amiga
+                 2 - VMS (or OpenVMS)
+                 3 - Unix
+                 4 - VM/CMS
+                 5 - Atari TOS
+                 6 - HPFS filesystem (OS/2, NT)
+                 7 - Macintosh
+                 8 - Z-System
+                 9 - CP/M
+                10 - TOPS-20
+                11 - NTFS filesystem (NT)
+                12 - QDOS
+                13 - Acorn RISCOS
+               255 - unknown
+
+         XLEN (eXtra LENgth)
+            If FLG.FEXTRA is set, this gives the length of the optional
+            extra field.  See below for details.
+
+         CRC32 (CRC-32)
+            This contains a Cyclic Redundancy Check value of the
+            uncompressed data computed according to CRC-32 algorithm
+            used in the ISO 3309 standard and in section 8.1.1.6.2 of
+            ITU-T recommendation V.42.  (See http://www.iso.ch for
+            ordering ISO documents. See gopher://info.itu.ch for an
+            online version of ITU-T V.42.)
+
+         ISIZE (Input SIZE)
+            This contains the size of the original (uncompressed) input
+            data modulo 2^32.
+
+      2.3.1.1. Extra field
+
+         If the FLG.FEXTRA bit is set, an "extra field" is present in
+         the header, with total length XLEN bytes.  It consists of a
+         series of subfields, each of the form:
+
+            +---+---+---+---+==================================+
+            |SI1|SI2|  LEN  |... LEN bytes of subfield data ...|
+            +---+---+---+---+==================================+
+
+         SI1 and SI2 provide a subfield ID, typically two ASCII letters
+         with some mnemonic value.  Jean-Loup Gailly
+         <gzip@prep.ai.mit.edu> is maintaining a registry of subfield
+         IDs; please send him any subfield ID you wish to use.  Subfield
+         IDs with SI2 = 0 are reserved for future use.  The following
+         IDs are currently defined:
+
+
+
+Deutsch                      Informational                      [Page 8]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+            SI1         SI2         Data
+            ----------  ----------  ----
+            0x41 ('A')  0x70 ('P')  Apollo file type information
+
+         LEN gives the length of the subfield data, excluding the 4
+         initial bytes.
+
+      2.3.1.2. Compliance
+
+         A compliant compressor must produce files with correct ID1,
+         ID2, CM, CRC32, and ISIZE, but may set all the other fields in
+         the fixed-length part of the header to default values (255 for
+         OS, 0 for all others).  The compressor must set all reserved
+         bits to zero.
+
+         A compliant decompressor must check ID1, ID2, and CM, and
+         provide an error indication if any of these have incorrect
+         values.  It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC
+         at least so it can skip over the optional fields if they are
+         present.  It need not examine any other part of the header or
+         trailer; in particular, a decompressor may ignore FTEXT and OS
+         and always produce binary output, and still be compliant.  A
+         compliant decompressor must give an error indication if any
+         reserved bit is non-zero, since such a bit could indicate the
+         presence of a new field that would cause subsequent data to be
+         interpreted incorrectly.
+
+3. References
+
+   [1] "Information Processing - 8-bit single-byte coded graphic
+       character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987).
+       The ISO 8859-1 (Latin-1) character set is a superset of 7-bit
+       ASCII. Files defining this character set are available as
+       iso_8859-1.* in ftp://ftp.uu.net/graphics/png/documents/
+
+   [2] ISO 3309
+
+   [3] ITU-T recommendation V.42
+
+   [4] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification",
+       available in ftp://ftp.uu.net/pub/archiving/zip/doc/
+
+   [5] Gailly, J.-L., GZIP documentation, available as gzip-*.tar in
+       ftp://prep.ai.mit.edu/pub/gnu/
+
+   [6] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via Table
+       Look-Up", Communications of the ACM, 31(8), pp.1008-1013.
+
+
+
+
+Deutsch                      Informational                      [Page 9]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+   [7] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal,
+       pp.118-133.
+
+   [8] ftp://ftp.adelaide.edu.au/pub/rocksoft/papers/crc_v3.txt,
+       describing the CRC concept.
+
+4. Security Considerations
+
+   Any data compression method involves the reduction of redundancy in
+   the data.  Consequently, any corruption of the data is likely to have
+   severe effects and be difficult to correct.  Uncompressed text, on
+   the other hand, will probably still be readable despite the presence
+   of some corrupted bytes.
+
+   It is recommended that systems using this data format provide some
+   means of validating the integrity of the compressed data, such as by
+   setting and checking the CRC-32 check value.
+
+5. Acknowledgements
+
+   Trademarks cited in this document are the property of their
+   respective owners.
+
+   Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler,
+   the related software described in this specification.  Glenn
+   Randers-Pehrson converted this document to RFC and HTML format.
+
+6. Author's Address
+
+   L. Peter Deutsch
+   Aladdin Enterprises
+   203 Santa Margarita Ave.
+   Menlo Park, CA 94025
+
+   Phone: (415) 322-0103 (AM only)
+   FAX:   (415) 322-1734
+   EMail: <ghost@aladdin.com>
+
+   Questions about the technical content of this specification can be
+   sent by email to:
+
+   Jean-Loup Gailly <gzip@prep.ai.mit.edu> and
+   Mark Adler <madler@alumni.caltech.edu>
+
+   Editorial comments on this specification can be sent by email to:
+
+   L. Peter Deutsch <ghost@aladdin.com> and
+   Glenn Randers-Pehrson <randeg@alumni.rpi.edu>
+
+
+
+Deutsch                      Informational                     [Page 10]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+7. Appendix: Jean-Loup Gailly's gzip utility
+
+   The most widely used implementation of gzip compression, and the
+   original documentation on which this specification is based, were
+   created by Jean-Loup Gailly <gzip@prep.ai.mit.edu>.  Since this
+   implementation is a de facto standard, we mention some more of its
+   features here.  Again, the material in this section is not part of
+   the specification per se, and implementations need not follow it to
+   be compliant.
+
+   When compressing or decompressing a file, gzip preserves the
+   protection, ownership, and modification time attributes on the local
+   file system, since there is no provision for representing protection
+   attributes in the gzip file format itself.  Since the file format
+   includes a modification time, the gzip decompressor provides a
+   command line switch that assigns the modification time from the file,
+   rather than the local modification time of the compressed input, to
+   the decompressed output.
+
+8. Appendix: Sample CRC Code
+
+   The following sample code represents a practical implementation of
+   the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42
+   for a formal specification.)
+
+   The sample code is in the ANSI C programming language. Non C users
+   may find it easier to read with these hints:
+
+      &      Bitwise AND operator.
+      ^      Bitwise exclusive-OR operator.
+      >>     Bitwise right shift operator. When applied to an
+             unsigned quantity, as here, right shift inserts zero
+             bit(s) at the left.
+      !      Logical NOT operator.
+      ++     "n++" increments the variable n.
+      0xNNN  0x introduces a hexadecimal (base 16) constant.
+             Suffix L indicates a long value (at least 32 bits).
+
+      /* Table of CRCs of all 8-bit messages. */
+      unsigned long crc_table[256];
+
+      /* Flag: has the table been computed? Initially false. */
+      int crc_table_computed = 0;
+
+      /* Make the table for a fast CRC. */
+      void make_crc_table(void)
+      {
+        unsigned long c;
+
+
+
+Deutsch                      Informational                     [Page 11]
+\f
+RFC 1952             GZIP File Format Specification             May 1996
+
+
+        int n, k;
+        for (n = 0; n < 256; n++) {
+          c = (unsigned long) n;
+          for (k = 0; k < 8; k++) {
+            if (c & 1) {
+              c = 0xedb88320L ^ (c >> 1);
+            } else {
+              c = c >> 1;
+            }
+          }
+          crc_table[n] = c;
+        }
+        crc_table_computed = 1;
+      }
+
+      /*
+         Update a running crc with the bytes buf[0..len-1] and return
+       the updated crc. The crc should be initialized to zero. Pre- and
+       post-conditioning (one's complement) is performed within this
+       function so it shouldn't be done by the caller. Usage example:
+
+         unsigned long crc = 0L;
+
+         while (read_buffer(buffer, length) != EOF) {
+           crc = update_crc(crc, buffer, length);
+         }
+         if (crc != original_crc) error();
+      */
+      unsigned long update_crc(unsigned long crc,
+                      unsigned char *buf, int len)
+      {
+        unsigned long c = crc ^ 0xffffffffL;
+        int n;
+
+        if (!crc_table_computed)
+          make_crc_table();
+        for (n = 0; n < len; n++) {
+          c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
+        }
+        return c ^ 0xffffffffL;
+      }
+
+      /* Return the CRC of the bytes buf[0..len-1]. */
+      unsigned long crc(unsigned char *buf, int len)
+      {
+        return update_crc(0L, buf, len);
+      }
+
+
+
+
+Deutsch                      Informational                     [Page 12]
+\f
diff --git a/deps/libchdr/deps/zlib-1.2.11/doc/txtvsbin.txt b/deps/libchdr/deps/zlib-1.2.11/doc/txtvsbin.txt
new file mode 100644 (file)
index 0000000..3d0f063
--- /dev/null
@@ -0,0 +1,107 @@
+A Fast Method for Identifying Plain Text Files
+==============================================
+
+
+Introduction
+------------
+
+Given a file coming from an unknown source, it is sometimes desirable
+to find out whether the format of that file is plain text.  Although
+this may appear like a simple task, a fully accurate detection of the
+file type requires heavy-duty semantic analysis on the file contents.
+It is, however, possible to obtain satisfactory results by employing
+various heuristics.
+
+Previous versions of PKZip and other zip-compatible compression tools
+were using a crude detection scheme: if more than 80% (4/5) of the bytes
+found in a certain buffer are within the range [7..127], the file is
+labeled as plain text, otherwise it is labeled as binary.  A prominent
+limitation of this scheme is the restriction to Latin-based alphabets.
+Other alphabets, like Greek, Cyrillic or Asian, make extensive use of
+the bytes within the range [128..255], and texts using these alphabets
+are most often misidentified by this scheme; in other words, the rate
+of false negatives is sometimes too high, which means that the recall
+is low.  Another weakness of this scheme is a reduced precision, due to
+the false positives that may occur when binary files containing large
+amounts of textual characters are misidentified as plain text.
+
+In this article we propose a new, simple detection scheme that features
+a much increased precision and a near-100% recall.  This scheme is
+designed to work on ASCII, Unicode and other ASCII-derived alphabets,
+and it handles single-byte encodings (ISO-8859, MacRoman, KOI8, etc.)
+and variable-sized encodings (ISO-2022, UTF-8, etc.).  Wider encodings
+(UCS-2/UTF-16 and UCS-4/UTF-32) are not handled, however.
+
+
+The Algorithm
+-------------
+
+The algorithm works by dividing the set of bytecodes [0..255] into three
+categories:
+- The white list of textual bytecodes:
+  9 (TAB), 10 (LF), 13 (CR), 32 (SPACE) to 255.
+- The gray list of tolerated bytecodes:
+  7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB), 27 (ESC).
+- The black list of undesired, non-textual bytecodes:
+  0 (NUL) to 6, 14 to 31.
+
+If a file contains at least one byte that belongs to the white list and
+no byte that belongs to the black list, then the file is categorized as
+plain text; otherwise, it is categorized as binary.  (The boundary case,
+when the file is empty, automatically falls into the latter category.)
+
+
+Rationale
+---------
+
+The idea behind this algorithm relies on two observations.
+
+The first observation is that, although the full range of 7-bit codes
+[0..127] is properly specified by the ASCII standard, most control
+characters in the range [0..31] are not used in practice.  The only
+widely-used, almost universally-portable control codes are 9 (TAB),
+10 (LF) and 13 (CR).  There are a few more control codes that are
+recognized on a reduced range of platforms and text viewers/editors:
+7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB) and 27 (ESC); but these
+codes are rarely (if ever) used alone, without being accompanied by
+some printable text.  Even the newer, portable text formats such as
+XML avoid using control characters outside the list mentioned here.
+
+The second observation is that most of the binary files tend to contain
+control characters, especially 0 (NUL).  Even though the older text
+detection schemes observe the presence of non-ASCII codes from the range
+[128..255], the precision rarely has to suffer if this upper range is
+labeled as textual, because the files that are genuinely binary tend to
+contain both control characters and codes from the upper range.  On the
+other hand, the upper range needs to be labeled as textual, because it
+is used by virtually all ASCII extensions.  In particular, this range is
+used for encoding non-Latin scripts.
+
+Since there is no counting involved, other than simply observing the
+presence or the absence of some byte values, the algorithm produces
+consistent results, regardless what alphabet encoding is being used.
+(If counting were involved, it could be possible to obtain different
+results on a text encoded, say, using ISO-8859-16 versus UTF-8.)
+
+There is an extra category of plain text files that are "polluted" with
+one or more black-listed codes, either by mistake or by peculiar design
+considerations.  In such cases, a scheme that tolerates a small fraction
+of black-listed codes would provide an increased recall (i.e. more true
+positives).  This, however, incurs a reduced precision overall, since
+false positives are more likely to appear in binary files that contain
+large chunks of textual data.  Furthermore, "polluted" plain text should
+be regarded as binary by general-purpose text detection schemes, because
+general-purpose text processing algorithms might not be applicable.
+Under this premise, it is safe to say that our detection method provides
+a near-100% recall.
+
+Experiments have been run on many files coming from various platforms
+and applications.  We tried plain text files, system logs, source code,
+formatted office documents, compiled object code, etc.  The results
+confirm the optimistic assumptions about the capabilities of this
+algorithm.
+
+
+--
+Cosmin Truta
+Last updated: 2006-May-28
similarity index 59%
rename from deps/zlib/gzclose.c
rename to deps/libchdr/deps/zlib-1.2.11/gzclose.c
index edeee03..caeb99a 100644 (file)
@@ -5,23 +5,21 @@
 
 #include "gzguts.h"
 
-extern int gzclose_w(gzFile file);
-extern int gzclose_r(gzFile file);
-
 /* gzclose() is in a separate file so that it is linked in only if it is used.
    That way the other gzclose functions can be used instead to avoid linking in
    unneeded compression or decompression routines. */
-int gzclose(gzFile file)
+int ZEXPORT gzclose(file)
+    gzFile file;
 {
 #ifndef NO_GZCOMPRESS
-   gz_statep state;
+    gz_statep state;
 
-   if (file == NULL)
-      return Z_STREAM_ERROR;
-   state = (gz_statep)file;
+    if (file == NULL)
+        return Z_STREAM_ERROR;
+    state = (gz_statep)file;
 
-   return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
+    return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
 #else
-   return gzclose_r(file);
+    return gzclose_r(file);
 #endif
 }
similarity index 84%
rename from deps/zlib/gzguts.h
rename to deps/libchdr/deps/zlib-1.2.11/gzguts.h
index 6068d41..45be573 100644 (file)
@@ -1,10 +1,11 @@
 /* gzguts.h -- zlib internal header definitions for gz* operations
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-#ifndef _GZGUTS_H
-#define _GZGUTS_H
+#ifndef _WIN32
+#  include <unistd.h>
+#endif
 
 #ifdef _LARGEFILE64_SOURCE
 #  ifndef _LARGEFILE_SOURCE
 #  include <stdlib.h>
 #  include <limits.h>
 #endif
+
+#ifndef _POSIX_SOURCE
+#  define _POSIX_SOURCE
+#endif
 #include <fcntl.h>
 
 #ifdef _WIN32
 #  include <stddef.h>
-#else
-#  include <unistd.h>
 #endif
 
 #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
 #  include <io.h>
 #endif
 
+#if defined(_WIN32) || defined(__CYGWIN__)
+#  define WIDECHAR
+#endif
+
 #ifdef WINAPI_FAMILY
 #  define open _open
 #  define read _read
 #  endif
 #endif
 
-/* unlike snprintf (which is required in C99, yet still not supported by
-   Microsoft more than a decade later!), _snprintf does not guarantee null
-   termination of the result -- however this is only used in gzlib.c where
+/* unlike snprintf (which is required in C99), _snprintf does not guarantee
+   null termination of the result -- however this is only used in gzlib.c where
    the result is assured to fit in the space provided */
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && _MSC_VER < 1900
 #  define snprintf _snprintf
 #endif
 
 #ifndef local
 #  define local static
 #endif
-/* compile with -Dlocal if your debugger can't find static symbols */
+/* since "static" is used to mean two completely different things in C, we
+   define "local" for the non-static meaning of "static", for readability
+   (compile with -Dlocal if your debugger can't find static symbols) */
 
 /* gz* functions always use library allocation functions */
 #ifndef STDC
 
 /* provide prototypes for these when building zlib without LFS */
 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
-#ifndef z_off64_t
-#define z_off64_t z_off_t
-#endif
-
-    gzFile gzopen64 OF((const char *, const char *));
-    z_off64_t gzseek64 OF((gzFile, z_off64_t, int));
-    z_off64_t gztell64 OF((gzFile));
-    z_off64_t gzoffset64 OF((gzFile));
+    ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
+    ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
+    ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
+    ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
 #endif
 
 /* default memLevel */
 
 /* values for gz_state how */
 #define LOOK 0      /* look for a gzip header */
-#define MODE_COPY 1      /* copy input directly */
-#define MODE_GZIP 2      /* decompress a gzip stream */
-
-#include "gzfile.h"
+#define COPY 1      /* copy input directly */
+#define GZIP 2      /* decompress a gzip stream */
 
 /* internal gzip file state data structure */
 typedef struct {
@@ -181,7 +183,7 @@ typedef struct {
     char *path;             /* path or fd for error messages */
     unsigned size;          /* buffer size, zero if not allocated yet */
     unsigned want;          /* requested buffer size, default is GZBUFSIZE */
-    unsigned char *in;      /* input buffer */
+    unsigned char *in;      /* input buffer (double-sized when writing) */
     unsigned char *out;     /* output buffer (double-sized when reading) */
     int direct;             /* 0 if processing gzip, 1 if transparent */
         /* just for reading */
@@ -218,5 +220,3 @@ char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
 unsigned ZLIB_INTERNAL gz_intmax OF((void));
 #  define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
 #endif
-
-#endif
diff --git a/deps/libchdr/deps/zlib-1.2.11/gzlib.c b/deps/libchdr/deps/zlib-1.2.11/gzlib.c
new file mode 100644 (file)
index 0000000..4105e6a
--- /dev/null
@@ -0,0 +1,637 @@
+/* gzlib.c -- zlib functions common to reading and writing gzip files
+ * Copyright (C) 2004-2017 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "gzguts.h"
+
+#if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
+#  define LSEEK _lseeki64
+#else
+#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
+#  define LSEEK lseek64
+#else
+#  define LSEEK lseek
+#endif
+#endif
+
+/* Local functions */
+local void gz_reset OF((gz_statep));
+local gzFile gz_open OF((const void *, int, const char *));
+
+#if defined UNDER_CE
+
+/* Map the Windows error number in ERROR to a locale-dependent error message
+   string and return a pointer to it.  Typically, the values for ERROR come
+   from GetLastError.
+
+   The string pointed to shall not be modified by the application, but may be
+   overwritten by a subsequent call to gz_strwinerror
+
+   The gz_strwinerror function does not change the current setting of
+   GetLastError. */
+char ZLIB_INTERNAL *gz_strwinerror (error)
+     DWORD error;
+{
+    static char buf[1024];
+
+    wchar_t *msgbuf;
+    DWORD lasterr = GetLastError();
+    DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
+        | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+        NULL,
+        error,
+        0, /* Default language */
+        (LPVOID)&msgbuf,
+        0,
+        NULL);
+    if (chars != 0) {
+        /* If there is an \r\n appended, zap it.  */
+        if (chars >= 2
+            && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
+            chars -= 2;
+            msgbuf[chars] = 0;
+        }
+
+        if (chars > sizeof (buf) - 1) {
+            chars = sizeof (buf) - 1;
+            msgbuf[chars] = 0;
+        }
+
+        wcstombs(buf, msgbuf, chars + 1);
+        LocalFree(msgbuf);
+    }
+    else {
+        sprintf(buf, "unknown win32 error (%ld)", error);
+    }
+
+    SetLastError(lasterr);
+    return buf;
+}
+
+#endif /* UNDER_CE */
+
+/* Reset gzip file state */
+local void gz_reset(state)
+    gz_statep state;
+{
+    state->x.have = 0;              /* no output data available */
+    if (state->mode == GZ_READ) {   /* for reading ... */
+        state->eof = 0;             /* not at end of file */
+        state->past = 0;            /* have not read past end yet */
+        state->how = LOOK;          /* look for gzip header */
+    }
+    state->seek = 0;                /* no seek request pending */
+    gz_error(state, Z_OK, NULL);    /* clear error */
+    state->x.pos = 0;               /* no uncompressed data yet */
+    state->strm.avail_in = 0;       /* no input data yet */
+}
+
+/* Open a gzip file either by name or file descriptor. */
+local gzFile gz_open(path, fd, mode)
+    const void *path;
+    int fd;
+    const char *mode;
+{
+    gz_statep state;
+    z_size_t len;
+    int oflag;
+#ifdef O_CLOEXEC
+    int cloexec = 0;
+#endif
+#ifdef O_EXCL
+    int exclusive = 0;
+#endif
+
+    /* check input */
+    if (path == NULL)
+        return NULL;
+
+    /* allocate gzFile structure to return */
+    state = (gz_statep)malloc(sizeof(gz_state));
+    if (state == NULL)
+        return NULL;
+    state->size = 0;            /* no buffers allocated yet */
+    state->want = GZBUFSIZE;    /* requested buffer size */
+    state->msg = NULL;          /* no error message yet */
+
+    /* interpret mode */
+    state->mode = GZ_NONE;
+    state->level = Z_DEFAULT_COMPRESSION;
+    state->strategy = Z_DEFAULT_STRATEGY;
+    state->direct = 0;
+    while (*mode) {
+        if (*mode >= '0' && *mode <= '9')
+            state->level = *mode - '0';
+        else
+            switch (*mode) {
+            case 'r':
+                state->mode = GZ_READ;
+                break;
+#ifndef NO_GZCOMPRESS
+            case 'w':
+                state->mode = GZ_WRITE;
+                break;
+            case 'a':
+                state->mode = GZ_APPEND;
+                break;
+#endif
+            case '+':       /* can't read and write at the same time */
+                free(state);
+                return NULL;
+            case 'b':       /* ignore -- will request binary anyway */
+                break;
+#ifdef O_CLOEXEC
+            case 'e':
+                cloexec = 1;
+                break;
+#endif
+#ifdef O_EXCL
+            case 'x':
+                exclusive = 1;
+                break;
+#endif
+            case 'f':
+                state->strategy = Z_FILTERED;
+                break;
+            case 'h':
+                state->strategy = Z_HUFFMAN_ONLY;
+                break;
+            case 'R':
+                state->strategy = Z_RLE;
+                break;
+            case 'F':
+                state->strategy = Z_FIXED;
+                break;
+            case 'T':
+                state->direct = 1;
+                break;
+            default:        /* could consider as an error, but just ignore */
+                ;
+            }
+        mode++;
+    }
+
+    /* must provide an "r", "w", or "a" */
+    if (state->mode == GZ_NONE) {
+        free(state);
+        return NULL;
+    }
+
+    /* can't force transparent read */
+    if (state->mode == GZ_READ) {
+        if (state->direct) {
+            free(state);
+            return NULL;
+        }
+        state->direct = 1;      /* for empty file */
+    }
+
+    /* save the path name for error messages */
+#ifdef WIDECHAR
+    if (fd == -2) {
+        len = wcstombs(NULL, path, 0);
+        if (len == (z_size_t)-1)
+            len = 0;
+    }
+    else
+#endif
+        len = strlen((const char *)path);
+    state->path = (char *)malloc(len + 1);
+    if (state->path == NULL) {
+        free(state);
+        return NULL;
+    }
+#ifdef WIDECHAR
+    if (fd == -2)
+        if (len)
+            wcstombs(state->path, path, len + 1);
+        else
+            *(state->path) = 0;
+    else
+#endif
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+        (void)snprintf(state->path, len + 1, "%s", (const char *)path);
+#else
+        strcpy(state->path, path);
+#endif
+
+    /* compute the flags for open() */
+    oflag =
+#ifdef O_LARGEFILE
+        O_LARGEFILE |
+#endif
+#ifdef O_BINARY
+        O_BINARY |
+#endif
+#ifdef O_CLOEXEC
+        (cloexec ? O_CLOEXEC : 0) |
+#endif
+        (state->mode == GZ_READ ?
+         O_RDONLY :
+         (O_WRONLY | O_CREAT |
+#ifdef O_EXCL
+          (exclusive ? O_EXCL : 0) |
+#endif
+          (state->mode == GZ_WRITE ?
+           O_TRUNC :
+           O_APPEND)));
+
+    /* open the file with the appropriate flags (or just use fd) */
+    state->fd = fd > -1 ? fd : (
+#ifdef WIDECHAR
+        fd == -2 ? _wopen(path, oflag, 0666) :
+#endif
+        open((const char *)path, oflag, 0666));
+    if (state->fd == -1) {
+        free(state->path);
+        free(state);
+        return NULL;
+    }
+    if (state->mode == GZ_APPEND) {
+        LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */
+        state->mode = GZ_WRITE;         /* simplify later checks */
+    }
+
+    /* save the current position for rewinding (only if reading) */
+    if (state->mode == GZ_READ) {
+        state->start = LSEEK(state->fd, 0, SEEK_CUR);
+        if (state->start == -1) state->start = 0;
+    }
+
+    /* initialize stream */
+    gz_reset(state);
+
+    /* return stream */
+    return (gzFile)state;
+}
+
+/* -- see zlib.h -- */
+gzFile ZEXPORT gzopen(path, mode)
+    const char *path;
+    const char *mode;
+{
+    return gz_open(path, -1, mode);
+}
+
+/* -- see zlib.h -- */
+gzFile ZEXPORT gzopen64(path, mode)
+    const char *path;
+    const char *mode;
+{
+    return gz_open(path, -1, mode);
+}
+
+/* -- see zlib.h -- */
+gzFile ZEXPORT gzdopen(fd, mode)
+    int fd;
+    const char *mode;
+{
+    char *path;         /* identifier for error messages */
+    gzFile gz;
+
+    if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
+        return NULL;
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+    (void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
+#else
+    sprintf(path, "<fd:%d>", fd);   /* for debugging */
+#endif
+    gz = gz_open(path, fd, mode);
+    free(path);
+    return gz;
+}
+
+/* -- see zlib.h -- */
+#ifdef WIDECHAR
+gzFile ZEXPORT gzopen_w(path, mode)
+    const wchar_t *path;
+    const char *mode;
+{
+    return gz_open(path, -2, mode);
+}
+#endif
+
+/* -- see zlib.h -- */
+int ZEXPORT gzbuffer(file, size)
+    gzFile file;
+    unsigned size;
+{
+    gz_statep state;
+
+    /* get internal structure and check integrity */
+    if (file == NULL)
+        return -1;
+    state = (gz_statep)file;
+    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+        return -1;
+
+    /* make sure we haven't already allocated memory */
+    if (state->size != 0)
+        return -1;
+
+    /* check and set requested size */
+    if ((size << 1) < size)
+        return -1;              /* need to be able to double it */
+    if (size < 2)
+        size = 2;               /* need two bytes to check magic header */
+    state->want = size;
+    return 0;
+}
+
+/* -- see zlib.h -- */
+int ZEXPORT gzrewind(file)
+    gzFile file;
+{
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return -1;
+    state = (gz_statep)file;
+
+    /* check that we're reading and that there's no error */
+    if (state->mode != GZ_READ ||
+            (state->err != Z_OK && state->err != Z_BUF_ERROR))
+        return -1;
+
+    /* back up and start over */
+    if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
+        return -1;
+    gz_reset(state);
+    return 0;
+}
+
+/* -- see zlib.h -- */
+z_off64_t ZEXPORT gzseek64(file, offset, whence)
+    gzFile file;
+    z_off64_t offset;
+    int whence;
+{
+    unsigned n;
+    z_off64_t ret;
+    gz_statep state;
+
+    /* get internal structure and check integrity */
+    if (file == NULL)
+        return -1;
+    state = (gz_statep)file;
+    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+        return -1;
+
+    /* check that there's no error */
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR)
+        return -1;
+
+    /* can only seek from start or relative to current position */
+    if (whence != SEEK_SET && whence != SEEK_CUR)
+        return -1;
+
+    /* normalize offset to a SEEK_CUR specification */
+    if (whence == SEEK_SET)
+        offset -= state->x.pos;
+    else if (state->seek)
+        offset += state->skip;
+    state->seek = 0;
+
+    /* if within raw area while reading, just go there */
+    if (state->mode == GZ_READ && state->how == COPY &&
+            state->x.pos + offset >= 0) {
+        ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
+        if (ret == -1)
+            return -1;
+        state->x.have = 0;
+        state->eof = 0;
+        state->past = 0;
+        state->seek = 0;
+        gz_error(state, Z_OK, NULL);
+        state->strm.avail_in = 0;
+        state->x.pos += offset;
+        return state->x.pos;
+    }
+
+    /* calculate skip amount, rewinding if needed for back seek when reading */
+    if (offset < 0) {
+        if (state->mode != GZ_READ)         /* writing -- can't go backwards */
+            return -1;
+        offset += state->x.pos;
+        if (offset < 0)                     /* before start of file! */
+            return -1;
+        if (gzrewind(file) == -1)           /* rewind, then skip to offset */
+            return -1;
+    }
+
+    /* if reading, skip what's in output buffer (one less gzgetc() check) */
+    if (state->mode == GZ_READ) {
+        n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
+            (unsigned)offset : state->x.have;
+        state->x.have -= n;
+        state->x.next += n;
+        state->x.pos += n;
+        offset -= n;
+    }
+
+    /* request skip (if not zero) */
+    if (offset) {
+        state->seek = 1;
+        state->skip = offset;
+    }
+    return state->x.pos + offset;
+}
+
+/* -- see zlib.h -- */
+z_off_t ZEXPORT gzseek(file, offset, whence)
+    gzFile file;
+    z_off_t offset;
+    int whence;
+{
+    z_off64_t ret;
+
+    ret = gzseek64(file, (z_off64_t)offset, whence);
+    return ret == (z_off_t)ret ? (z_off_t)ret : -1;
+}
+
+/* -- see zlib.h -- */
+z_off64_t ZEXPORT gztell64(file)
+    gzFile file;
+{
+    gz_statep state;
+
+    /* get internal structure and check integrity */
+    if (file == NULL)
+        return -1;
+    state = (gz_statep)file;
+    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+        return -1;
+
+    /* return position */
+    return state->x.pos + (state->seek ? state->skip : 0);
+}
+
+/* -- see zlib.h -- */
+z_off_t ZEXPORT gztell(file)
+    gzFile file;
+{
+    z_off64_t ret;
+
+    ret = gztell64(file);
+    return ret == (z_off_t)ret ? (z_off_t)ret : -1;
+}
+
+/* -- see zlib.h -- */
+z_off64_t ZEXPORT gzoffset64(file)
+    gzFile file;
+{
+    z_off64_t offset;
+    gz_statep state;
+
+    /* get internal structure and check integrity */
+    if (file == NULL)
+        return -1;
+    state = (gz_statep)file;
+    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+        return -1;
+
+    /* compute and return effective offset in file */
+    offset = LSEEK(state->fd, 0, SEEK_CUR);
+    if (offset == -1)
+        return -1;
+    if (state->mode == GZ_READ)             /* reading */
+        offset -= state->strm.avail_in;     /* don't count buffered input */
+    return offset;
+}
+
+/* -- see zlib.h -- */
+z_off_t ZEXPORT gzoffset(file)
+    gzFile file;
+{
+    z_off64_t ret;
+
+    ret = gzoffset64(file);
+    return ret == (z_off_t)ret ? (z_off_t)ret : -1;
+}
+
+/* -- see zlib.h -- */
+int ZEXPORT gzeof(file)
+    gzFile file;
+{
+    gz_statep state;
+
+    /* get internal structure and check integrity */
+    if (file == NULL)
+        return 0;
+    state = (gz_statep)file;
+    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+        return 0;
+
+    /* return end-of-file state */
+    return state->mode == GZ_READ ? state->past : 0;
+}
+
+/* -- see zlib.h -- */
+const char * ZEXPORT gzerror(file, errnum)
+    gzFile file;
+    int *errnum;
+{
+    gz_statep state;
+
+    /* get internal structure and check integrity */
+    if (file == NULL)
+        return NULL;
+    state = (gz_statep)file;
+    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+        return NULL;
+
+    /* return error information */
+    if (errnum != NULL)
+        *errnum = state->err;
+    return state->err == Z_MEM_ERROR ? "out of memory" :
+                                       (state->msg == NULL ? "" : state->msg);
+}
+
+/* -- see zlib.h -- */
+void ZEXPORT gzclearerr(file)
+    gzFile file;
+{
+    gz_statep state;
+
+    /* get internal structure and check integrity */
+    if (file == NULL)
+        return;
+    state = (gz_statep)file;
+    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+        return;
+
+    /* clear error and end-of-file */
+    if (state->mode == GZ_READ) {
+        state->eof = 0;
+        state->past = 0;
+    }
+    gz_error(state, Z_OK, NULL);
+}
+
+/* Create an error message in allocated memory and set state->err and
+   state->msg accordingly.  Free any previous error message already there.  Do
+   not try to free or allocate space if the error is Z_MEM_ERROR (out of
+   memory).  Simply save the error message as a static string.  If there is an
+   allocation failure constructing the error message, then convert the error to
+   out of memory. */
+void ZLIB_INTERNAL gz_error(state, err, msg)
+    gz_statep state;
+    int err;
+    const char *msg;
+{
+    /* free previously allocated message and clear */
+    if (state->msg != NULL) {
+        if (state->err != Z_MEM_ERROR)
+            free(state->msg);
+        state->msg = NULL;
+    }
+
+    /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
+    if (err != Z_OK && err != Z_BUF_ERROR)
+        state->x.have = 0;
+
+    /* set error code, and if no message, then done */
+    state->err = err;
+    if (msg == NULL)
+        return;
+
+    /* for an out of memory error, return literal string when requested */
+    if (err == Z_MEM_ERROR)
+        return;
+
+    /* construct error message with path */
+    if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
+            NULL) {
+        state->err = Z_MEM_ERROR;
+        return;
+    }
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+    (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
+                   "%s%s%s", state->path, ": ", msg);
+#else
+    strcpy(state->msg, state->path);
+    strcat(state->msg, ": ");
+    strcat(state->msg, msg);
+#endif
+}
+
+#ifndef INT_MAX
+/* portably return maximum value for an int (when limits.h presumed not
+   available) -- we need to do this to cover cases where 2's complement not
+   used, since C standard permits 1's complement and sign-bit representations,
+   otherwise we could just use ((unsigned)-1) >> 1 */
+unsigned ZLIB_INTERNAL gz_intmax()
+{
+    unsigned p, q;
+
+    p = 1;
+    do {
+        q = p;
+        p <<= 1;
+        p++;
+    } while (p > q);
+    return q >> 1;
+}
+#endif
diff --git a/deps/libchdr/deps/zlib-1.2.11/gzread.c b/deps/libchdr/deps/zlib-1.2.11/gzread.c
new file mode 100644 (file)
index 0000000..956b91e
--- /dev/null
@@ -0,0 +1,654 @@
+/* gzread.c -- zlib functions for reading gzip files
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "gzguts.h"
+
+/* Local functions */
+local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
+local int gz_avail OF((gz_statep));
+local int gz_look OF((gz_statep));
+local int gz_decomp OF((gz_statep));
+local int gz_fetch OF((gz_statep));
+local int gz_skip OF((gz_statep, z_off64_t));
+local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
+
+/* Use read() to load a buffer -- return -1 on error, otherwise 0.  Read from
+   state->fd, and update state->eof, state->err, and state->msg as appropriate.
+   This function needs to loop on read(), since read() is not guaranteed to
+   read the number of bytes requested, depending on the type of descriptor. */
+local int gz_load(state, buf, len, have)
+    gz_statep state;
+    unsigned char *buf;
+    unsigned len;
+    unsigned *have;
+{
+    int ret;
+    unsigned get, max = ((unsigned)-1 >> 2) + 1;
+
+    *have = 0;
+    do {
+        get = len - *have;
+        if (get > max)
+            get = max;
+        ret = read(state->fd, buf + *have, get);
+        if (ret <= 0)
+            break;
+        *have += (unsigned)ret;
+    } while (*have < len);
+    if (ret < 0) {
+        gz_error(state, Z_ERRNO, zstrerror());
+        return -1;
+    }
+    if (ret == 0)
+        state->eof = 1;
+    return 0;
+}
+
+/* Load up input buffer and set eof flag if last data loaded -- return -1 on
+   error, 0 otherwise.  Note that the eof flag is set when the end of the input
+   file is reached, even though there may be unused data in the buffer.  Once
+   that data has been used, no more attempts will be made to read the file.
+   If strm->avail_in != 0, then the current data is moved to the beginning of
+   the input buffer, and then the remainder of the buffer is loaded with the
+   available data from the input file. */
+local int gz_avail(state)
+    gz_statep state;
+{
+    unsigned got;
+    z_streamp strm = &(state->strm);
+
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR)
+        return -1;
+    if (state->eof == 0) {
+        if (strm->avail_in) {       /* copy what's there to the start */
+            unsigned char *p = state->in;
+            unsigned const char *q = strm->next_in;
+            unsigned n = strm->avail_in;
+            do {
+                *p++ = *q++;
+            } while (--n);
+        }
+        if (gz_load(state, state->in + strm->avail_in,
+                    state->size - strm->avail_in, &got) == -1)
+            return -1;
+        strm->avail_in += got;
+        strm->next_in = state->in;
+    }
+    return 0;
+}
+
+/* Look for gzip header, set up for inflate or copy.  state->x.have must be 0.
+   If this is the first time in, allocate required memory.  state->how will be
+   left unchanged if there is no more input data available, will be set to COPY
+   if there is no gzip header and direct copying will be performed, or it will
+   be set to GZIP for decompression.  If direct copying, then leftover input
+   data from the input buffer will be copied to the output buffer.  In that
+   case, all further file reads will be directly to either the output buffer or
+   a user buffer.  If decompressing, the inflate state will be initialized.
+   gz_look() will return 0 on success or -1 on failure. */
+local int gz_look(state)
+    gz_statep state;
+{
+    z_streamp strm = &(state->strm);
+
+    /* allocate read buffers and inflate memory */
+    if (state->size == 0) {
+        /* allocate buffers */
+        state->in = (unsigned char *)malloc(state->want);
+        state->out = (unsigned char *)malloc(state->want << 1);
+        if (state->in == NULL || state->out == NULL) {
+            free(state->out);
+            free(state->in);
+            gz_error(state, Z_MEM_ERROR, "out of memory");
+            return -1;
+        }
+        state->size = state->want;
+
+        /* allocate inflate memory */
+        state->strm.zalloc = Z_NULL;
+        state->strm.zfree = Z_NULL;
+        state->strm.opaque = Z_NULL;
+        state->strm.avail_in = 0;
+        state->strm.next_in = Z_NULL;
+        if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) {    /* gunzip */
+            free(state->out);
+            free(state->in);
+            state->size = 0;
+            gz_error(state, Z_MEM_ERROR, "out of memory");
+            return -1;
+        }
+    }
+
+    /* get at least the magic bytes in the input buffer */
+    if (strm->avail_in < 2) {
+        if (gz_avail(state) == -1)
+            return -1;
+        if (strm->avail_in == 0)
+            return 0;
+    }
+
+    /* look for gzip magic bytes -- if there, do gzip decoding (note: there is
+       a logical dilemma here when considering the case of a partially written
+       gzip file, to wit, if a single 31 byte is written, then we cannot tell
+       whether this is a single-byte file, or just a partially written gzip
+       file -- for here we assume that if a gzip file is being written, then
+       the header will be written in a single operation, so that reading a
+       single byte is sufficient indication that it is not a gzip file) */
+    if (strm->avail_in > 1 &&
+            strm->next_in[0] == 31 && strm->next_in[1] == 139) {
+        inflateReset(strm);
+        state->how = GZIP;
+        state->direct = 0;
+        return 0;
+    }
+
+    /* no gzip header -- if we were decoding gzip before, then this is trailing
+       garbage.  Ignore the trailing garbage and finish. */
+    if (state->direct == 0) {
+        strm->avail_in = 0;
+        state->eof = 1;
+        state->x.have = 0;
+        return 0;
+    }
+
+    /* doing raw i/o, copy any leftover input to output -- this assumes that
+       the output buffer is larger than the input buffer, which also assures
+       space for gzungetc() */
+    state->x.next = state->out;
+    if (strm->avail_in) {
+        memcpy(state->x.next, strm->next_in, strm->avail_in);
+        state->x.have = strm->avail_in;
+        strm->avail_in = 0;
+    }
+    state->how = COPY;
+    state->direct = 1;
+    return 0;
+}
+
+/* Decompress from input to the provided next_out and avail_out in the state.
+   On return, state->x.have and state->x.next point to the just decompressed
+   data.  If the gzip stream completes, state->how is reset to LOOK to look for
+   the next gzip stream or raw data, once state->x.have is depleted.  Returns 0
+   on success, -1 on failure. */
+local int gz_decomp(state)
+    gz_statep state;
+{
+    int ret = Z_OK;
+    unsigned had;
+    z_streamp strm = &(state->strm);
+
+    /* fill output buffer up to end of deflate stream */
+    had = strm->avail_out;
+    do {
+        /* get more input for inflate() */
+        if (strm->avail_in == 0 && gz_avail(state) == -1)
+            return -1;
+        if (strm->avail_in == 0) {
+            gz_error(state, Z_BUF_ERROR, "unexpected end of file");
+            break;
+        }
+
+        /* decompress and handle errors */
+        ret = inflate(strm, Z_NO_FLUSH);
+        if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
+            gz_error(state, Z_STREAM_ERROR,
+                     "internal error: inflate stream corrupt");
+            return -1;
+        }
+        if (ret == Z_MEM_ERROR) {
+            gz_error(state, Z_MEM_ERROR, "out of memory");
+            return -1;
+        }
+        if (ret == Z_DATA_ERROR) {              /* deflate stream invalid */
+            gz_error(state, Z_DATA_ERROR,
+                     strm->msg == NULL ? "compressed data error" : strm->msg);
+            return -1;
+        }
+    } while (strm->avail_out && ret != Z_STREAM_END);
+
+    /* update available output */
+    state->x.have = had - strm->avail_out;
+    state->x.next = strm->next_out - state->x.have;
+
+    /* if the gzip stream completed successfully, look for another */
+    if (ret == Z_STREAM_END)
+        state->how = LOOK;
+
+    /* good decompression */
+    return 0;
+}
+
+/* Fetch data and put it in the output buffer.  Assumes state->x.have is 0.
+   Data is either copied from the input file or decompressed from the input
+   file depending on state->how.  If state->how is LOOK, then a gzip header is
+   looked for to determine whether to copy or decompress.  Returns -1 on error,
+   otherwise 0.  gz_fetch() will leave state->how as COPY or GZIP unless the
+   end of the input file has been reached and all data has been processed.  */
+local int gz_fetch(state)
+    gz_statep state;
+{
+    z_streamp strm = &(state->strm);
+
+    do {
+        switch(state->how) {
+        case LOOK:      /* -> LOOK, COPY (only if never GZIP), or GZIP */
+            if (gz_look(state) == -1)
+                return -1;
+            if (state->how == LOOK)
+                return 0;
+            break;
+        case COPY:      /* -> COPY */
+            if (gz_load(state, state->out, state->size << 1, &(state->x.have))
+                    == -1)
+                return -1;
+            state->x.next = state->out;
+            return 0;
+        case GZIP:      /* -> GZIP or LOOK (if end of gzip stream) */
+            strm->avail_out = state->size << 1;
+            strm->next_out = state->out;
+            if (gz_decomp(state) == -1)
+                return -1;
+        }
+    } while (state->x.have == 0 && (!state->eof || strm->avail_in));
+    return 0;
+}
+
+/* Skip len uncompressed bytes of output.  Return -1 on error, 0 on success. */
+local int gz_skip(state, len)
+    gz_statep state;
+    z_off64_t len;
+{
+    unsigned n;
+
+    /* skip over len bytes or reach end-of-file, whichever comes first */
+    while (len)
+        /* skip over whatever is in output buffer */
+        if (state->x.have) {
+            n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
+                (unsigned)len : state->x.have;
+            state->x.have -= n;
+            state->x.next += n;
+            state->x.pos += n;
+            len -= n;
+        }
+
+        /* output buffer empty -- return if we're at the end of the input */
+        else if (state->eof && state->strm.avail_in == 0)
+            break;
+
+        /* need more data to skip -- load up output buffer */
+        else {
+            /* get more output, looking for header if required */
+            if (gz_fetch(state) == -1)
+                return -1;
+        }
+    return 0;
+}
+
+/* Read len bytes into buf from file, or less than len up to the end of the
+   input.  Return the number of bytes read.  If zero is returned, either the
+   end of file was reached, or there was an error.  state->err must be
+   consulted in that case to determine which. */
+local z_size_t gz_read(state, buf, len)
+    gz_statep state;
+    voidp buf;
+    z_size_t len;
+{
+    z_size_t got;
+    unsigned n;
+
+    /* if len is zero, avoid unnecessary operations */
+    if (len == 0)
+        return 0;
+
+    /* process a skip request */
+    if (state->seek) {
+        state->seek = 0;
+        if (gz_skip(state, state->skip) == -1)
+            return 0;
+    }
+
+    /* get len bytes to buf, or less than len if at the end */
+    got = 0;
+    do {
+        /* set n to the maximum amount of len that fits in an unsigned int */
+        n = -1;
+        if (n > len)
+            n = len;
+
+        /* first just try copying data from the output buffer */
+        if (state->x.have) {
+            if (state->x.have < n)
+                n = state->x.have;
+            memcpy(buf, state->x.next, n);
+            state->x.next += n;
+            state->x.have -= n;
+        }
+
+        /* output buffer empty -- return if we're at the end of the input */
+        else if (state->eof && state->strm.avail_in == 0) {
+            state->past = 1;        /* tried to read past end */
+            break;
+        }
+
+        /* need output data -- for small len or new stream load up our output
+           buffer */
+        else if (state->how == LOOK || n < (state->size << 1)) {
+            /* get more output, looking for header if required */
+            if (gz_fetch(state) == -1)
+                return 0;
+            continue;       /* no progress yet -- go back to copy above */
+            /* the copy above assures that we will leave with space in the
+               output buffer, allowing at least one gzungetc() to succeed */
+        }
+
+        /* large len -- read directly into user buffer */
+        else if (state->how == COPY) {      /* read directly */
+            if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
+                return 0;
+        }
+
+        /* large len -- decompress directly into user buffer */
+        else {  /* state->how == GZIP */
+            state->strm.avail_out = n;
+            state->strm.next_out = (unsigned char *)buf;
+            if (gz_decomp(state) == -1)
+                return 0;
+            n = state->x.have;
+            state->x.have = 0;
+        }
+
+        /* update progress */
+        len -= n;
+        buf = (char *)buf + n;
+        got += n;
+        state->x.pos += n;
+    } while (len);
+
+    /* return number of bytes read into user buffer */
+    return got;
+}
+
+/* -- see zlib.h -- */
+int ZEXPORT gzread(file, buf, len)
+    gzFile file;
+    voidp buf;
+    unsigned len;
+{
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return -1;
+    state = (gz_statep)file;
+
+    /* check that we're reading and that there's no (serious) error */
+    if (state->mode != GZ_READ ||
+            (state->err != Z_OK && state->err != Z_BUF_ERROR))
+        return -1;
+
+    /* since an int is returned, make sure len fits in one, otherwise return
+       with an error (this avoids a flaw in the interface) */
+    if ((int)len < 0) {
+        gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
+        return -1;
+    }
+
+    /* read len or fewer bytes to buf */
+    len = gz_read(state, buf, len);
+
+    /* check for an error */
+    if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
+        return -1;
+
+    /* return the number of bytes read (this is assured to fit in an int) */
+    return (int)len;
+}
+
+/* -- see zlib.h -- */
+z_size_t ZEXPORT gzfread(buf, size, nitems, file)
+    voidp buf;
+    z_size_t size;
+    z_size_t nitems;
+    gzFile file;
+{
+    z_size_t len;
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return 0;
+    state = (gz_statep)file;
+
+    /* check that we're reading and that there's no (serious) error */
+    if (state->mode != GZ_READ ||
+            (state->err != Z_OK && state->err != Z_BUF_ERROR))
+        return 0;
+
+    /* compute bytes to read -- error on overflow */
+    len = nitems * size;
+    if (size && len / size != nitems) {
+        gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
+        return 0;
+    }
+
+    /* read len or fewer bytes to buf, return the number of full items read */
+    return len ? gz_read(state, buf, len) / size : 0;
+}
+
+/* -- see zlib.h -- */
+#ifdef Z_PREFIX_SET
+#  undef z_gzgetc
+#else
+#  undef gzgetc
+#endif
+int ZEXPORT gzgetc(file)
+    gzFile file;
+{
+    int ret;
+    unsigned char buf[1];
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return -1;
+    state = (gz_statep)file;
+
+    /* check that we're reading and that there's no (serious) error */
+    if (state->mode != GZ_READ ||
+        (state->err != Z_OK && state->err != Z_BUF_ERROR))
+        return -1;
+
+    /* try output buffer (no need to check for skip request) */
+    if (state->x.have) {
+        state->x.have--;
+        state->x.pos++;
+        return *(state->x.next)++;
+    }
+
+    /* nothing there -- try gz_read() */
+    ret = gz_read(state, buf, 1);
+    return ret < 1 ? -1 : buf[0];
+}
+
+int ZEXPORT gzgetc_(file)
+gzFile file;
+{
+    return gzgetc(file);
+}
+
+/* -- see zlib.h -- */
+int ZEXPORT gzungetc(c, file)
+    int c;
+    gzFile file;
+{
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return -1;
+    state = (gz_statep)file;
+
+    /* check that we're reading and that there's no (serious) error */
+    if (state->mode != GZ_READ ||
+        (state->err != Z_OK && state->err != Z_BUF_ERROR))
+        return -1;
+
+    /* process a skip request */
+    if (state->seek) {
+        state->seek = 0;
+        if (gz_skip(state, state->skip) == -1)
+            return -1;
+    }
+
+    /* can't push EOF */
+    if (c < 0)
+        return -1;
+
+    /* if output buffer empty, put byte at end (allows more pushing) */
+    if (state->x.have == 0) {
+        state->x.have = 1;
+        state->x.next = state->out + (state->size << 1) - 1;
+        state->x.next[0] = (unsigned char)c;
+        state->x.pos--;
+        state->past = 0;
+        return c;
+    }
+
+    /* if no room, give up (must have already done a gzungetc()) */
+    if (state->x.have == (state->size << 1)) {
+        gz_error(state, Z_DATA_ERROR, "out of room to push characters");
+        return -1;
+    }
+
+    /* slide output data if needed and insert byte before existing data */
+    if (state->x.next == state->out) {
+        unsigned char *src = state->out + state->x.have;
+        unsigned char *dest = state->out + (state->size << 1);
+        while (src > state->out)
+            *--dest = *--src;
+        state->x.next = dest;
+    }
+    state->x.have++;
+    state->x.next--;
+    state->x.next[0] = (unsigned char)c;
+    state->x.pos--;
+    state->past = 0;
+    return c;
+}
+
+/* -- see zlib.h -- */
+char * ZEXPORT gzgets(file, buf, len)
+    gzFile file;
+    char *buf;
+    int len;
+{
+    unsigned left, n;
+    char *str;
+    unsigned char *eol;
+    gz_statep state;
+
+    /* check parameters and get internal structure */
+    if (file == NULL || buf == NULL || len < 1)
+        return NULL;
+    state = (gz_statep)file;
+
+    /* check that we're reading and that there's no (serious) error */
+    if (state->mode != GZ_READ ||
+        (state->err != Z_OK && state->err != Z_BUF_ERROR))
+        return NULL;
+
+    /* process a skip request */
+    if (state->seek) {
+        state->seek = 0;
+        if (gz_skip(state, state->skip) == -1)
+            return NULL;
+    }
+
+    /* copy output bytes up to new line or len - 1, whichever comes first --
+       append a terminating zero to the string (we don't check for a zero in
+       the contents, let the user worry about that) */
+    str = buf;
+    left = (unsigned)len - 1;
+    if (left) do {
+        /* assure that something is in the output buffer */
+        if (state->x.have == 0 && gz_fetch(state) == -1)
+            return NULL;                /* error */
+        if (state->x.have == 0) {       /* end of file */
+            state->past = 1;            /* read past end */
+            break;                      /* return what we have */
+        }
+
+        /* look for end-of-line in current output buffer */
+        n = state->x.have > left ? left : state->x.have;
+        eol = (unsigned char *)memchr(state->x.next, '\n', n);
+        if (eol != NULL)
+            n = (unsigned)(eol - state->x.next) + 1;
+
+        /* copy through end-of-line, or remainder if not found */
+        memcpy(buf, state->x.next, n);
+        state->x.have -= n;
+        state->x.next += n;
+        state->x.pos += n;
+        left -= n;
+        buf += n;
+    } while (left && eol == NULL);
+
+    /* return terminated string, or if nothing, end of file */
+    if (buf == str)
+        return NULL;
+    buf[0] = 0;
+    return str;
+}
+
+/* -- see zlib.h -- */
+int ZEXPORT gzdirect(file)
+    gzFile file;
+{
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return 0;
+    state = (gz_statep)file;
+
+    /* if the state is not known, but we can find out, then do so (this is
+       mainly for right after a gzopen() or gzdopen()) */
+    if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
+        (void)gz_look(state);
+
+    /* return 1 if transparent, 0 if processing a gzip stream */
+    return state->direct;
+}
+
+/* -- see zlib.h -- */
+int ZEXPORT gzclose_r(file)
+    gzFile file;
+{
+    int ret, err;
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return Z_STREAM_ERROR;
+    state = (gz_statep)file;
+
+    /* check that we're reading */
+    if (state->mode != GZ_READ)
+        return Z_STREAM_ERROR;
+
+    /* free memory and close file */
+    if (state->size) {
+        inflateEnd(&(state->strm));
+        free(state->out);
+        free(state->in);
+    }
+    err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
+    gz_error(state, Z_OK, NULL);
+    free(state->path);
+    ret = close(state->fd);
+    free(state);
+    return ret ? Z_ERRNO : err;
+}
similarity index 58%
rename from deps/zlib/gzwrite.c
rename to deps/libchdr/deps/zlib-1.2.11/gzwrite.c
index 61b217e..c7b5651 100644 (file)
@@ -1,5 +1,5 @@
 /* gzwrite.c -- zlib functions for writing gzip files
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
+ * Copyright (C) 2004-2017 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -9,18 +9,19 @@
 local int gz_init OF((gz_statep));
 local int gz_comp OF((gz_statep, int));
 local int gz_zero OF((gz_statep, z_off64_t));
-
-int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va);
+local z_size_t gz_write OF((gz_statep, voidpc, z_size_t));
 
 /* Initialize state for writing a gzip file.  Mark initialization by setting
-   state->size to non-zero.  Return -1 on failure or 0 on success. */
-local int gz_init(gz_statep state)
+   state->size to non-zero.  Return -1 on a memory allocation failure, or 0 on
+   success. */
+local int gz_init(state)
+    gz_statep state;
 {
     int ret;
     z_streamp strm = &(state->strm);
 
-    /* allocate input buffer */
-    state->in = (unsigned char *)malloc(state->want);
+    /* allocate input buffer (double size for gzprintf) */
+    state->in = (unsigned char *)malloc(state->want << 1);
     if (state->in == NULL) {
         gz_error(state, Z_MEM_ERROR, "out of memory");
         return -1;
@@ -48,6 +49,7 @@ local int gz_init(gz_statep state)
             gz_error(state, Z_MEM_ERROR, "out of memory");
             return -1;
         }
+        strm->next_in = NULL;
     }
 
     /* mark state as initialized */
@@ -63,15 +65,17 @@ local int gz_init(gz_statep state)
 }
 
 /* Compress whatever is at avail_in and next_in and write to the output file.
-   Return -1 if there is an error writing to the output file, otherwise 0.
-   flush is assumed to be a valid deflate() flush value.  If flush is Z_FINISH,
-   then the deflate() state is reset to start a new gzip stream.  If gz->direct
-   is true, then simply write to the output file without compressing, and
-   ignore flush. */
-local int gz_comp(gz_statep state, int flush)
+   Return -1 if there is an error writing to the output file or if gz_init()
+   fails to allocate memory, otherwise 0.  flush is assumed to be a valid
+   deflate() flush value.  If flush is Z_FINISH, then the deflate() state is
+   reset to start a new gzip stream.  If gz->direct is true, then simply write
+   to the output file without compressing, and ignore flush. */
+local int gz_comp(state, flush)
+    gz_statep state;
+    int flush;
 {
-    int ret, got;
-    unsigned have;
+    int ret, writ;
+    unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
     z_streamp strm = &(state->strm);
 
     /* allocate memory if this is the first time through */
@@ -80,12 +84,16 @@ local int gz_comp(gz_statep state, int flush)
 
     /* write directly if requested */
     if (state->direct) {
-        got = write(state->fd, strm->next_in, strm->avail_in);
-        if (got < 0 || (unsigned)got != strm->avail_in) {
-            gz_error(state, Z_ERRNO, zstrerror());
-            return -1;
+        while (strm->avail_in) {
+            put = strm->avail_in > max ? max : strm->avail_in;
+            writ = write(state->fd, strm->next_in, put);
+            if (writ < 0) {
+                gz_error(state, Z_ERRNO, zstrerror());
+                return -1;
+            }
+            strm->avail_in -= (unsigned)writ;
+            strm->next_in += writ;
         }
-        strm->avail_in = 0;
         return 0;
     }
 
@@ -96,17 +104,21 @@ local int gz_comp(gz_statep state, int flush)
            doing Z_FINISH then don't write until we get to Z_STREAM_END */
         if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
             (flush != Z_FINISH || ret == Z_STREAM_END))) {
-            have = (unsigned)(strm->next_out - state->x.next);
-            if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
-                         (unsigned)got != have)) {
-                gz_error(state, Z_ERRNO, zstrerror());
-                return -1;
+            while (strm->next_out > state->x.next) {
+                put = strm->next_out - state->x.next > (int)max ? max :
+                      (unsigned)(strm->next_out - state->x.next);
+                writ = write(state->fd, state->x.next, put);
+                if (writ < 0) {
+                    gz_error(state, Z_ERRNO, zstrerror());
+                    return -1;
+                }
+                state->x.next += writ;
             }
             if (strm->avail_out == 0) {
                 strm->avail_out = state->size;
                 strm->next_out = state->out;
+                state->x.next = state->out;
             }
-            state->x.next = strm->next_out;
         }
 
         /* compress */
@@ -128,8 +140,11 @@ local int gz_comp(gz_statep state, int flush)
     return 0;
 }
 
-/* Compress len zeros to output.  Return -1 on error, 0 on success. */
-local int gz_zero(gz_statep state, z_off64_t len)
+/* Compress len zeros to output.  Return -1 on a write error or memory
+   allocation failure by gz_comp(), or 0 on success. */
+local int gz_zero(state, len)
+    gz_statep state;
+    z_off64_t len;
 {
     int first;
     unsigned n;
@@ -158,29 +173,14 @@ local int gz_zero(gz_statep state, z_off64_t len)
     return 0;
 }
 
-/* -- see zlib.h -- */
-int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
-{
-    unsigned put = len;
+/* Write len bytes from buf to file.  Return the number of bytes written.  If
+   the returned value is less than len, then there was an error. */
+local z_size_t gz_write(state, buf, len)
     gz_statep state;
-    z_streamp strm;
-
-    /* get internal structure */
-    if (file == NULL)
-        return 0;
-    state = (gz_statep)file;
-    strm = &(state->strm);
-
-    /* check that we're writing and that there's no error */
-    if (state->mode != GZ_WRITE || state->err != Z_OK)
-        return 0;
-
-    /* since an int is returned, make sure len fits in one, otherwise return
-       with an error (this avoids the flaw in the interface) */
-    if ((int)len < 0) {
-        gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
-        return 0;
-    }
+    voidpc buf;
+    z_size_t len;
+{
+    z_size_t put = len;
 
     /* if len is zero, avoid unnecessary operations */
     if (len == 0)
@@ -203,14 +203,15 @@ int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
         do {
             unsigned have, copy;
 
-            if (strm->avail_in == 0)
-                strm->next_in = state->in;
-            have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
+            if (state->strm.avail_in == 0)
+                state->strm.next_in = state->in;
+            have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
+                              state->in);
             copy = state->size - have;
             if (copy > len)
                 copy = len;
             memcpy(state->in + have, buf, copy);
-            strm->avail_in += copy;
+            state->strm.avail_in += copy;
             state->x.pos += copy;
             buf = (const char *)buf + copy;
             len -= copy;
@@ -220,23 +221,89 @@ int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
     }
     else {
         /* consume whatever's left in the input buffer */
-        if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
+        if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
             return 0;
 
         /* directly compress user buffer to file */
-        strm->avail_in = len;
-        strm->next_in = (Bytef *)buf;
-        state->x.pos += len;
-        if (gz_comp(state, Z_NO_FLUSH) == -1)
-            return 0;
+        state->strm.next_in = (z_const Bytef *)buf;
+        do {
+            unsigned n = (unsigned)-1;
+            if (n > len)
+                n = len;
+            state->strm.avail_in = n;
+            state->x.pos += n;
+            if (gz_comp(state, Z_NO_FLUSH) == -1)
+                return 0;
+            len -= n;
+        } while (len);
+    }
+
+    /* input was all buffered or compressed */
+    return put;
+}
+
+/* -- see zlib.h -- */
+int ZEXPORT gzwrite(file, buf, len)
+    gzFile file;
+    voidpc buf;
+    unsigned len;
+{
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return 0;
+    state = (gz_statep)file;
+
+    /* check that we're writing and that there's no error */
+    if (state->mode != GZ_WRITE || state->err != Z_OK)
+        return 0;
+
+    /* since an int is returned, make sure len fits in one, otherwise return
+       with an error (this avoids a flaw in the interface) */
+    if ((int)len < 0) {
+        gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
+        return 0;
+    }
+
+    /* write len bytes from buf (the return value will fit in an int) */
+    return (int)gz_write(state, buf, len);
+}
+
+/* -- see zlib.h -- */
+z_size_t ZEXPORT gzfwrite(buf, size, nitems, file)
+    voidpc buf;
+    z_size_t size;
+    z_size_t nitems;
+    gzFile file;
+{
+    z_size_t len;
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return 0;
+    state = (gz_statep)file;
+
+    /* check that we're writing and that there's no error */
+    if (state->mode != GZ_WRITE || state->err != Z_OK)
+        return 0;
+
+    /* compute bytes to read -- error on overflow */
+    len = nitems * size;
+    if (size && len / size != nitems) {
+        gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
+        return 0;
     }
 
-    /* input was all buffered or compressed (put will fit in int) */
-    return (int)put;
+    /* write len bytes to buf, return the number of full items written */
+    return len ? gz_write(state, buf, len) / size : 0;
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzputc(gzFile file, int c)
+int ZEXPORT gzputc(file, c)
+    gzFile file;
+    int c;
 {
     unsigned have;
     unsigned char buf[1];
@@ -267,7 +334,7 @@ int ZEXPORT gzputc(gzFile file, int c)
             strm->next_in = state->in;
         have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
         if (have < state->size) {
-            state->in[have] = c;
+            state->in[have] = (unsigned char)c;
             strm->avail_in++;
             state->x.pos++;
             return c & 0xff;
@@ -275,21 +342,33 @@ int ZEXPORT gzputc(gzFile file, int c)
     }
 
     /* no room in buffer or not initialized, use gz_write() */
-    buf[0] = c;
-    if (gzwrite(file, buf, 1) != 1)
+    buf[0] = (unsigned char)c;
+    if (gz_write(state, buf, 1) != 1)
         return -1;
     return c & 0xff;
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzputs(gzFile file, const char *str)
+int ZEXPORT gzputs(file, str)
+    gzFile file;
+    const char *str;
 {
     int ret;
-    unsigned len;
+    z_size_t len;
+    gz_statep state;
+
+    /* get internal structure */
+    if (file == NULL)
+        return -1;
+    state = (gz_statep)file;
+
+    /* check that we're writing and that there's no error */
+    if (state->mode != GZ_WRITE || state->err != Z_OK)
+        return -1;
 
     /* write string */
-    len = (unsigned)strlen(str);
-    ret = gzwrite(file, str, len);
+    len = strlen(str);
+    ret = gz_write(state, str, len);
     return ret == 0 && len != 0 ? -1 : ret;
 }
 
@@ -299,63 +378,73 @@ int ZEXPORT gzputs(gzFile file, const char *str)
 /* -- see zlib.h -- */
 int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
 {
-    int size, len;
+    int len;
+    unsigned left;
+    char *next;
     gz_statep state;
     z_streamp strm;
 
     /* get internal structure */
     if (file == NULL)
-        return -1;
+        return Z_STREAM_ERROR;
     state = (gz_statep)file;
     strm = &(state->strm);
 
     /* check that we're writing and that there's no error */
     if (state->mode != GZ_WRITE || state->err != Z_OK)
-        return 0;
+        return Z_STREAM_ERROR;
 
     /* make sure we have some buffer space */
     if (state->size == 0 && gz_init(state) == -1)
-        return 0;
+        return state->err;
 
     /* check for seek request */
     if (state->seek) {
         state->seek = 0;
         if (gz_zero(state, state->skip) == -1)
-            return 0;
+            return state->err;
     }
 
-    /* consume whatever's left in the input buffer */
-    if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
-        return 0;
-
-    /* do the printf() into the input buffer, put length in len */
-    size = (int)(state->size);
-    state->in[size - 1] = 0;
+    /* do the printf() into the input buffer, put length in len -- the input
+       buffer is double-sized just for this function, so there is guaranteed to
+       be state->size bytes available after the current contents */
+    if (strm->avail_in == 0)
+        strm->next_in = state->in;
+    next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
+    next[state->size - 1] = 0;
 #ifdef NO_vsnprintf
 #  ifdef HAS_vsprintf_void
-    (void)vsprintf((char *)(state->in), format, va);
-    for (len = 0; len < size; len++)
-        if (state->in[len] == 0) break;
+    (void)vsprintf(next, format, va);
+    for (len = 0; len < state->size; len++)
+        if (next[len] == 0) break;
 #  else
-    len = vsprintf((char *)(state->in), format, va);
+    len = vsprintf(next, format, va);
 #  endif
 #else
 #  ifdef HAS_vsnprintf_void
-    (void)vsnprintf((char *)(state->in), size, format, va);
-    len = strlen((char *)(state->in));
+    (void)vsnprintf(next, state->size, format, va);
+    len = strlen(next);
 #  else
-    len = vsnprintf((char *)(state->in), size, format, va);
+    len = vsnprintf(next, state->size, format, va);
 #  endif
 #endif
 
     /* check that printf() results fit in buffer */
-    if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
+    if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
         return 0;
 
-    /* update buffer and position, defer compression until needed */
-    strm->avail_in = (unsigned)len;
-    strm->next_in = state->in;
+    /* update buffer and position, compress first half if past that */
+    strm->avail_in += (unsigned)len;
     state->x.pos += len;
+    if (strm->avail_in >= state->size) {
+        left = strm->avail_in - state->size;
+        strm->avail_in = state->size;
+        if (gz_comp(state, Z_NO_FLUSH) == -1)
+            return state->err;
+        memcpy(state->in, state->in + state->size, left);
+        strm->next_in = state->in;
+        strm->avail_in = left;
+    }
     return len;
 }
 
@@ -373,88 +462,103 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
 #else /* !STDC && !Z_HAVE_STDARG_H */
 
 /* -- see zlib.h -- */
-int ZEXPORTVA gzprintf (gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10,
-                       int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
+int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
+                       a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
+    gzFile file;
+    const char *format;
+    int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
+        a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
 {
-    int size, len;
+    unsigned len, left;
+    char *next;
     gz_statep state;
     z_streamp strm;
 
     /* get internal structure */
     if (file == NULL)
-        return -1;
+        return Z_STREAM_ERROR;
     state = (gz_statep)file;
     strm = &(state->strm);
 
     /* check that can really pass pointer in ints */
     if (sizeof(int) != sizeof(void *))
-        return 0;
+        return Z_STREAM_ERROR;
 
     /* check that we're writing and that there's no error */
     if (state->mode != GZ_WRITE || state->err != Z_OK)
-        return 0;
+        return Z_STREAM_ERROR;
 
     /* make sure we have some buffer space */
     if (state->size == 0 && gz_init(state) == -1)
-        return 0;
+        return state->error;
 
     /* check for seek request */
     if (state->seek) {
         state->seek = 0;
         if (gz_zero(state, state->skip) == -1)
-            return 0;
+            return state->error;
     }
 
-    /* consume whatever's left in the input buffer */
-    if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
-        return 0;
-
-    /* do the printf() into the input buffer, put length in len */
-    size = (int)(state->size);
-    state->in[size - 1] = 0;
+    /* do the printf() into the input buffer, put length in len -- the input
+       buffer is double-sized just for this function, so there is guaranteed to
+       be state->size bytes available after the current contents */
+    if (strm->avail_in == 0)
+        strm->next_in = state->in;
+    next = (char *)(strm->next_in + strm->avail_in);
+    next[state->size - 1] = 0;
 #ifdef NO_snprintf
 #  ifdef HAS_sprintf_void
-    sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
-            a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+    sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
+            a13, a14, a15, a16, a17, a18, a19, a20);
     for (len = 0; len < size; len++)
-        if (state->in[len] == 0) break;
+        if (next[len] == 0)
+            break;
 #  else
-    len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
-                  a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+    len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
+                  a12, a13, a14, a15, a16, a17, a18, a19, a20);
 #  endif
 #else
 #  ifdef HAS_snprintf_void
-    snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
-             a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
-    len = strlen((char *)(state->in));
+    snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
+             a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+    len = strlen(next);
 #  else
-    len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
-                   a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
-                   a19, a20);
+    len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
+                   a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
 #  endif
 #endif
 
     /* check that printf() results fit in buffer */
-    if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
+    if (len == 0 || len >= state->size || next[state->size - 1] != 0)
         return 0;
 
-    /* update buffer and position, defer compression until needed */
-    strm->avail_in = (unsigned)len;
-    strm->next_in = state->in;
+    /* update buffer and position, compress first half if past that */
+    strm->avail_in += len;
     state->x.pos += len;
-    return len;
+    if (strm->avail_in >= state->size) {
+        left = strm->avail_in - state->size;
+        strm->avail_in = state->size;
+        if (gz_comp(state, Z_NO_FLUSH) == -1)
+            return state->err;
+        memcpy(state->in, state->in + state->size, left);
+        strm->next_in = state->in;
+        strm->avail_in = left;
+    }
+    return (int)len;
 }
 
 #endif
 
 /* -- see zlib.h -- */
-int ZEXPORT gzflush(gzFile file, int flush)
+int ZEXPORT gzflush(file, flush)
+    gzFile file;
+    int flush;
 {
     gz_statep state;
 
     /* get internal structure */
     if (file == NULL)
-        return -1;
+        return Z_STREAM_ERROR;
     state = (gz_statep)file;
 
     /* check that we're writing and that there's no error */
@@ -469,16 +573,19 @@ int ZEXPORT gzflush(gzFile file, int flush)
     if (state->seek) {
         state->seek = 0;
         if (gz_zero(state, state->skip) == -1)
-            return -1;
+            return state->err;
     }
 
     /* compress remaining data with requested flush */
-    gz_comp(state, flush);
+    (void)gz_comp(state, flush);
     return state->err;
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
+int ZEXPORT gzsetparams(file, level, strategy)
+    gzFile file;
+    int level;
+    int strategy;
 {
     gz_statep state;
     z_streamp strm;
@@ -501,13 +608,13 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
     if (state->seek) {
         state->seek = 0;
         if (gz_zero(state, state->skip) == -1)
-            return -1;
+            return state->err;
     }
 
     /* change compression parameters for subsequent input */
     if (state->size) {
         /* flush previous input with previous parameters before changing */
-        if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
+        if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
             return state->err;
         deflateParams(strm, level, strategy);
     }
@@ -517,7 +624,8 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
 }
 
 /* -- see zlib.h -- */
-int gzclose_w(gzFile file)
+int ZEXPORT gzclose_w(file)
+    gzFile file;
 {
     int ret = Z_OK;
     gz_statep state;
diff --git a/deps/libchdr/deps/zlib-1.2.11/infback.c b/deps/libchdr/deps/zlib-1.2.11/infback.c
new file mode 100644 (file)
index 0000000..59679ec
--- /dev/null
@@ -0,0 +1,640 @@
+/* infback.c -- inflate using a call-back interface
+ * Copyright (C) 1995-2016 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+   This code is largely copied from inflate.c.  Normally either infback.o or
+   inflate.o would be linked into an application--not both.  The interface
+   with inffast.c is retained so that optimized assembler-coded versions of
+   inflate_fast() can be used with either inflate.c or infback.c.
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+#include "inffast.h"
+
+/* function prototypes */
+local void fixedtables OF((struct inflate_state FAR *state));
+
+/*
+   strm provides memory allocation functions in zalloc and zfree, or
+   Z_NULL to use the library memory allocation functions.
+
+   windowBits is in the range 8..15, and window is a user-supplied
+   window and output buffer that is 2**windowBits bytes.
+ */
+int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
+z_streamp strm;
+int windowBits;
+unsigned char FAR *window;
+const char *version;
+int stream_size;
+{
+    struct inflate_state FAR *state;
+
+    if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
+        stream_size != (int)(sizeof(z_stream)))
+        return Z_VERSION_ERROR;
+    if (strm == Z_NULL || window == Z_NULL ||
+        windowBits < 8 || windowBits > 15)
+        return Z_STREAM_ERROR;
+    strm->msg = Z_NULL;                 /* in case we return an error */
+    if (strm->zalloc == (alloc_func)0) {
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
+        strm->zalloc = zcalloc;
+        strm->opaque = (voidpf)0;
+#endif
+    }
+    if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
+    strm->zfree = zcfree;
+#endif
+    state = (struct inflate_state FAR *)ZALLOC(strm, 1,
+                                               sizeof(struct inflate_state));
+    if (state == Z_NULL) return Z_MEM_ERROR;
+    Tracev((stderr, "inflate: allocated\n"));
+    strm->state = (struct internal_state FAR *)state;
+    state->dmax = 32768U;
+    state->wbits = (uInt)windowBits;
+    state->wsize = 1U << windowBits;
+    state->window = window;
+    state->wnext = 0;
+    state->whave = 0;
+    return Z_OK;
+}
+
+/*
+   Return state with length and distance decoding tables and index sizes set to
+   fixed code decoding.  Normally this returns fixed tables from inffixed.h.
+   If BUILDFIXED is defined, then instead this routine builds the tables the
+   first time it's called, and returns those tables the first time and
+   thereafter.  This reduces the size of the code by about 2K bytes, in
+   exchange for a little execution time.  However, BUILDFIXED should not be
+   used for threaded applications, since the rewriting of the tables and virgin
+   may not be thread-safe.
+ */
+local void fixedtables(state)
+struct inflate_state FAR *state;
+{
+#ifdef BUILDFIXED
+    static int virgin = 1;
+    static code *lenfix, *distfix;
+    static code fixed[544];
+
+    /* build fixed huffman tables if first call (may not be thread safe) */
+    if (virgin) {
+        unsigned sym, bits;
+        static code *next;
+
+        /* literal/length table */
+        sym = 0;
+        while (sym < 144) state->lens[sym++] = 8;
+        while (sym < 256) state->lens[sym++] = 9;
+        while (sym < 280) state->lens[sym++] = 7;
+        while (sym < 288) state->lens[sym++] = 8;
+        next = fixed;
+        lenfix = next;
+        bits = 9;
+        inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
+
+        /* distance table */
+        sym = 0;
+        while (sym < 32) state->lens[sym++] = 5;
+        distfix = next;
+        bits = 5;
+        inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
+
+        /* do this just once */
+        virgin = 0;
+    }
+#else /* !BUILDFIXED */
+#   include "inffixed.h"
+#endif /* BUILDFIXED */
+    state->lencode = lenfix;
+    state->lenbits = 9;
+    state->distcode = distfix;
+    state->distbits = 5;
+}
+
+/* Macros for inflateBack(): */
+
+/* Load returned state from inflate_fast() */
+#define LOAD() \
+    do { \
+        put = strm->next_out; \
+        left = strm->avail_out; \
+        next = strm->next_in; \
+        have = strm->avail_in; \
+        hold = state->hold; \
+        bits = state->bits; \
+    } while (0)
+
+/* Set state from registers for inflate_fast() */
+#define RESTORE() \
+    do { \
+        strm->next_out = put; \
+        strm->avail_out = left; \
+        strm->next_in = next; \
+        strm->avail_in = have; \
+        state->hold = hold; \
+        state->bits = bits; \
+    } while (0)
+
+/* Clear the input bit accumulator */
+#define INITBITS() \
+    do { \
+        hold = 0; \
+        bits = 0; \
+    } while (0)
+
+/* Assure that some input is available.  If input is requested, but denied,
+   then return a Z_BUF_ERROR from inflateBack(). */
+#define PULL() \
+    do { \
+        if (have == 0) { \
+            have = in(in_desc, &next); \
+            if (have == 0) { \
+                next = Z_NULL; \
+                ret = Z_BUF_ERROR; \
+                goto inf_leave; \
+            } \
+        } \
+    } while (0)
+
+/* Get a byte of input into the bit accumulator, or return from inflateBack()
+   with an error if there is no input available. */
+#define PULLBYTE() \
+    do { \
+        PULL(); \
+        have--; \
+        hold += (unsigned long)(*next++) << bits; \
+        bits += 8; \
+    } while (0)
+
+/* Assure that there are at least n bits in the bit accumulator.  If there is
+   not enough available input to do that, then return from inflateBack() with
+   an error. */
+#define NEEDBITS(n) \
+    do { \
+        while (bits < (unsigned)(n)) \
+            PULLBYTE(); \
+    } while (0)
+
+/* Return the low n bits of the bit accumulator (n < 16) */
+#define BITS(n) \
+    ((unsigned)hold & ((1U << (n)) - 1))
+
+/* Remove n bits from the bit accumulator */
+#define DROPBITS(n) \
+    do { \
+        hold >>= (n); \
+        bits -= (unsigned)(n); \
+    } while (0)
+
+/* Remove zero to seven bits as needed to go to a byte boundary */
+#define BYTEBITS() \
+    do { \
+        hold >>= bits & 7; \
+        bits -= bits & 7; \
+    } while (0)
+
+/* Assure that some output space is available, by writing out the window
+   if it's full.  If the write fails, return from inflateBack() with a
+   Z_BUF_ERROR. */
+#define ROOM() \
+    do { \
+        if (left == 0) { \
+            put = state->window; \
+            left = state->wsize; \
+            state->whave = left; \
+            if (out(out_desc, put, left)) { \
+                ret = Z_BUF_ERROR; \
+                goto inf_leave; \
+            } \
+        } \
+    } while (0)
+
+/*
+   strm provides the memory allocation functions and window buffer on input,
+   and provides information on the unused input on return.  For Z_DATA_ERROR
+   returns, strm will also provide an error message.
+
+   in() and out() are the call-back input and output functions.  When
+   inflateBack() needs more input, it calls in().  When inflateBack() has
+   filled the window with output, or when it completes with data in the
+   window, it calls out() to write out the data.  The application must not
+   change the provided input until in() is called again or inflateBack()
+   returns.  The application must not change the window/output buffer until
+   inflateBack() returns.
+
+   in() and out() are called with a descriptor parameter provided in the
+   inflateBack() call.  This parameter can be a structure that provides the
+   information required to do the read or write, as well as accumulated
+   information on the input and output such as totals and check values.
+
+   in() should return zero on failure.  out() should return non-zero on
+   failure.  If either in() or out() fails, than inflateBack() returns a
+   Z_BUF_ERROR.  strm->next_in can be checked for Z_NULL to see whether it
+   was in() or out() that caused in the error.  Otherwise,  inflateBack()
+   returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
+   error, or Z_MEM_ERROR if it could not allocate memory for the state.
+   inflateBack() can also return Z_STREAM_ERROR if the input parameters
+   are not correct, i.e. strm is Z_NULL or the state was not initialized.
+ */
+int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
+z_streamp strm;
+in_func in;
+void FAR *in_desc;
+out_func out;
+void FAR *out_desc;
+{
+    struct inflate_state FAR *state;
+    z_const unsigned char FAR *next;    /* next input */
+    unsigned char FAR *put;     /* next output */
+    unsigned have, left;        /* available input and output */
+    unsigned long hold;         /* bit buffer */
+    unsigned bits;              /* bits in bit buffer */
+    unsigned copy;              /* number of stored or match bytes to copy */
+    unsigned char FAR *from;    /* where to copy match bytes from */
+    code here;                  /* current decoding table entry */
+    code last;                  /* parent table entry */
+    unsigned len;               /* length to copy for repeats, bits to drop */
+    int ret;                    /* return code */
+    static const unsigned short order[19] = /* permutation of code lengths */
+        {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+
+    /* Check that the strm exists and that the state was initialized */
+    if (strm == Z_NULL || strm->state == Z_NULL)
+        return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+
+    /* Reset the state */
+    strm->msg = Z_NULL;
+    state->mode = TYPE;
+    state->last = 0;
+    state->whave = 0;
+    next = strm->next_in;
+    have = next != Z_NULL ? strm->avail_in : 0;
+    hold = 0;
+    bits = 0;
+    put = state->window;
+    left = state->wsize;
+
+    /* Inflate until end of block marked as last */
+    for (;;)
+        switch (state->mode) {
+        case TYPE:
+            /* determine and dispatch block type */
+            if (state->last) {
+                BYTEBITS();
+                state->mode = DONE;
+                break;
+            }
+            NEEDBITS(3);
+            state->last = BITS(1);
+            DROPBITS(1);
+            switch (BITS(2)) {
+            case 0:                             /* stored block */
+                Tracev((stderr, "inflate:     stored block%s\n",
+                        state->last ? " (last)" : ""));
+                state->mode = STORED;
+                break;
+            case 1:                             /* fixed block */
+                fixedtables(state);
+                Tracev((stderr, "inflate:     fixed codes block%s\n",
+                        state->last ? " (last)" : ""));
+                state->mode = LEN;              /* decode codes */
+                break;
+            case 2:                             /* dynamic block */
+                Tracev((stderr, "inflate:     dynamic codes block%s\n",
+                        state->last ? " (last)" : ""));
+                state->mode = TABLE;
+                break;
+            case 3:
+                strm->msg = (char *)"invalid block type";
+                state->mode = BAD;
+            }
+            DROPBITS(2);
+            break;
+
+        case STORED:
+            /* get and verify stored block length */
+            BYTEBITS();                         /* go to byte boundary */
+            NEEDBITS(32);
+            if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
+                strm->msg = (char *)"invalid stored block lengths";
+                state->mode = BAD;
+                break;
+            }
+            state->length = (unsigned)hold & 0xffff;
+            Tracev((stderr, "inflate:       stored length %u\n",
+                    state->length));
+            INITBITS();
+
+            /* copy stored block from input to output */
+            while (state->length != 0) {
+                copy = state->length;
+                PULL();
+                ROOM();
+                if (copy > have) copy = have;
+                if (copy > left) copy = left;
+                zmemcpy(put, next, copy);
+                have -= copy;
+                next += copy;
+                left -= copy;
+                put += copy;
+                state->length -= copy;
+            }
+            Tracev((stderr, "inflate:       stored end\n"));
+            state->mode = TYPE;
+            break;
+
+        case TABLE:
+            /* get dynamic table entries descriptor */
+            NEEDBITS(14);
+            state->nlen = BITS(5) + 257;
+            DROPBITS(5);
+            state->ndist = BITS(5) + 1;
+            DROPBITS(5);
+            state->ncode = BITS(4) + 4;
+            DROPBITS(4);
+#ifndef PKZIP_BUG_WORKAROUND
+            if (state->nlen > 286 || state->ndist > 30) {
+                strm->msg = (char *)"too many length or distance symbols";
+                state->mode = BAD;
+                break;
+            }
+#endif
+            Tracev((stderr, "inflate:       table sizes ok\n"));
+
+            /* get code length code lengths (not a typo) */
+            state->have = 0;
+            while (state->have < state->ncode) {
+                NEEDBITS(3);
+                state->lens[order[state->have++]] = (unsigned short)BITS(3);
+                DROPBITS(3);
+            }
+            while (state->have < 19)
+                state->lens[order[state->have++]] = 0;
+            state->next = state->codes;
+            state->lencode = (code const FAR *)(state->next);
+            state->lenbits = 7;
+            ret = inflate_table(CODES, state->lens, 19, &(state->next),
+                                &(state->lenbits), state->work);
+            if (ret) {
+                strm->msg = (char *)"invalid code lengths set";
+                state->mode = BAD;
+                break;
+            }
+            Tracev((stderr, "inflate:       code lengths ok\n"));
+
+            /* get length and distance code code lengths */
+            state->have = 0;
+            while (state->have < state->nlen + state->ndist) {
+                for (;;) {
+                    here = state->lencode[BITS(state->lenbits)];
+                    if ((unsigned)(here.bits) <= bits) break;
+                    PULLBYTE();
+                }
+                if (here.val < 16) {
+                    DROPBITS(here.bits);
+                    state->lens[state->have++] = here.val;
+                }
+                else {
+                    if (here.val == 16) {
+                        NEEDBITS(here.bits + 2);
+                        DROPBITS(here.bits);
+                        if (state->have == 0) {
+                            strm->msg = (char *)"invalid bit length repeat";
+                            state->mode = BAD;
+                            break;
+                        }
+                        len = (unsigned)(state->lens[state->have - 1]);
+                        copy = 3 + BITS(2);
+                        DROPBITS(2);
+                    }
+                    else if (here.val == 17) {
+                        NEEDBITS(here.bits + 3);
+                        DROPBITS(here.bits);
+                        len = 0;
+                        copy = 3 + BITS(3);
+                        DROPBITS(3);
+                    }
+                    else {
+                        NEEDBITS(here.bits + 7);
+                        DROPBITS(here.bits);
+                        len = 0;
+                        copy = 11 + BITS(7);
+                        DROPBITS(7);
+                    }
+                    if (state->have + copy > state->nlen + state->ndist) {
+                        strm->msg = (char *)"invalid bit length repeat";
+                        state->mode = BAD;
+                        break;
+                    }
+                    while (copy--)
+                        state->lens[state->have++] = (unsigned short)len;
+                }
+            }
+
+            /* handle error breaks in while */
+            if (state->mode == BAD) break;
+
+            /* check for end-of-block code (better have one) */
+            if (state->lens[256] == 0) {
+                strm->msg = (char *)"invalid code -- missing end-of-block";
+                state->mode = BAD;
+                break;
+            }
+
+            /* build code tables -- note: do not change the lenbits or distbits
+               values here (9 and 6) without reading the comments in inftrees.h
+               concerning the ENOUGH constants, which depend on those values */
+            state->next = state->codes;
+            state->lencode = (code const FAR *)(state->next);
+            state->lenbits = 9;
+            ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
+                                &(state->lenbits), state->work);
+            if (ret) {
+                strm->msg = (char *)"invalid literal/lengths set";
+                state->mode = BAD;
+                break;
+            }
+            state->distcode = (code const FAR *)(state->next);
+            state->distbits = 6;
+            ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
+                            &(state->next), &(state->distbits), state->work);
+            if (ret) {
+                strm->msg = (char *)"invalid distances set";
+                state->mode = BAD;
+                break;
+            }
+            Tracev((stderr, "inflate:       codes ok\n"));
+            state->mode = LEN;
+
+        case LEN:
+            /* use inflate_fast() if we have enough input and output */
+            if (have >= 6 && left >= 258) {
+                RESTORE();
+                if (state->whave < state->wsize)
+                    state->whave = state->wsize - left;
+                inflate_fast(strm, state->wsize);
+                LOAD();
+                break;
+            }
+
+            /* get a literal, length, or end-of-block code */
+            for (;;) {
+                here = state->lencode[BITS(state->lenbits)];
+                if ((unsigned)(here.bits) <= bits) break;
+                PULLBYTE();
+            }
+            if (here.op && (here.op & 0xf0) == 0) {
+                last = here;
+                for (;;) {
+                    here = state->lencode[last.val +
+                            (BITS(last.bits + last.op) >> last.bits)];
+                    if ((unsigned)(last.bits + here.bits) <= bits) break;
+                    PULLBYTE();
+                }
+                DROPBITS(last.bits);
+            }
+            DROPBITS(here.bits);
+            state->length = (unsigned)here.val;
+
+            /* process literal */
+            if (here.op == 0) {
+                Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
+                        "inflate:         literal '%c'\n" :
+                        "inflate:         literal 0x%02x\n", here.val));
+                ROOM();
+                *put++ = (unsigned char)(state->length);
+                left--;
+                state->mode = LEN;
+                break;
+            }
+
+            /* process end of block */
+            if (here.op & 32) {
+                Tracevv((stderr, "inflate:         end of block\n"));
+                state->mode = TYPE;
+                break;
+            }
+
+            /* invalid code */
+            if (here.op & 64) {
+                strm->msg = (char *)"invalid literal/length code";
+                state->mode = BAD;
+                break;
+            }
+
+            /* length code -- get extra bits, if any */
+            state->extra = (unsigned)(here.op) & 15;
+            if (state->extra != 0) {
+                NEEDBITS(state->extra);
+                state->length += BITS(state->extra);
+                DROPBITS(state->extra);
+            }
+            Tracevv((stderr, "inflate:         length %u\n", state->length));
+
+            /* get distance code */
+            for (;;) {
+                here = state->distcode[BITS(state->distbits)];
+                if ((unsigned)(here.bits) <= bits) break;
+                PULLBYTE();
+            }
+            if ((here.op & 0xf0) == 0) {
+                last = here;
+                for (;;) {
+                    here = state->distcode[last.val +
+                            (BITS(last.bits + last.op) >> last.bits)];
+                    if ((unsigned)(last.bits + here.bits) <= bits) break;
+                    PULLBYTE();
+                }
+                DROPBITS(last.bits);
+            }
+            DROPBITS(here.bits);
+            if (here.op & 64) {
+                strm->msg = (char *)"invalid distance code";
+                state->mode = BAD;
+                break;
+            }
+            state->offset = (unsigned)here.val;
+
+            /* get distance extra bits, if any */
+            state->extra = (unsigned)(here.op) & 15;
+            if (state->extra != 0) {
+                NEEDBITS(state->extra);
+                state->offset += BITS(state->extra);
+                DROPBITS(state->extra);
+            }
+            if (state->offset > state->wsize - (state->whave < state->wsize ?
+                                                left : 0)) {
+                strm->msg = (char *)"invalid distance too far back";
+                state->mode = BAD;
+                break;
+            }
+            Tracevv((stderr, "inflate:         distance %u\n", state->offset));
+
+            /* copy match from window to output */
+            do {
+                ROOM();
+                copy = state->wsize - state->offset;
+                if (copy < left) {
+                    from = put + copy;
+                    copy = left - copy;
+                }
+                else {
+                    from = put - state->offset;
+                    copy = left;
+                }
+                if (copy > state->length) copy = state->length;
+                state->length -= copy;
+                left -= copy;
+                do {
+                    *put++ = *from++;
+                } while (--copy);
+            } while (state->length != 0);
+            break;
+
+        case DONE:
+            /* inflate stream terminated properly -- write leftover output */
+            ret = Z_STREAM_END;
+            if (left < state->wsize) {
+                if (out(out_desc, state->window, state->wsize - left))
+                    ret = Z_BUF_ERROR;
+            }
+            goto inf_leave;
+
+        case BAD:
+            ret = Z_DATA_ERROR;
+            goto inf_leave;
+
+        default:                /* can't happen, but makes compilers happy */
+            ret = Z_STREAM_ERROR;
+            goto inf_leave;
+        }
+
+    /* Return unused input */
+  inf_leave:
+    strm->next_in = next;
+    strm->avail_in = have;
+    return ret;
+}
+
+int ZEXPORT inflateBackEnd(strm)
+z_streamp strm;
+{
+    if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
+        return Z_STREAM_ERROR;
+    ZFREE(strm, strm->state);
+    strm->state = Z_NULL;
+    Tracev((stderr, "inflate: end\n"));
+    return Z_OK;
+}
diff --git a/deps/libchdr/deps/zlib-1.2.11/inffast.c b/deps/libchdr/deps/zlib-1.2.11/inffast.c
new file mode 100644 (file)
index 0000000..0dbd1db
--- /dev/null
@@ -0,0 +1,323 @@
+/* inffast.c -- fast decoding
+ * Copyright (C) 1995-2017 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+#include "inffast.h"
+
+#ifdef ASMINF
+#  pragma message("Assembler code may have bugs -- use at your own risk")
+#else
+
+/*
+   Decode literal, length, and distance codes and write out the resulting
+   literal and match bytes until either not enough input or output is
+   available, an end-of-block is encountered, or a data error is encountered.
+   When large enough input and output buffers are supplied to inflate(), for
+   example, a 16K input buffer and a 64K output buffer, more than 95% of the
+   inflate execution time is spent in this routine.
+
+   Entry assumptions:
+
+        state->mode == LEN
+        strm->avail_in >= 6
+        strm->avail_out >= 258
+        start >= strm->avail_out
+        state->bits < 8
+
+   On return, state->mode is one of:
+
+        LEN -- ran out of enough output space or enough available input
+        TYPE -- reached end of block code, inflate() to interpret next block
+        BAD -- error in block data
+
+   Notes:
+
+    - The maximum input bits used by a length/distance pair is 15 bits for the
+      length code, 5 bits for the length extra, 15 bits for the distance code,
+      and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
+      Therefore if strm->avail_in >= 6, then there is enough input to avoid
+      checking for available input while decoding.
+
+    - The maximum bytes that a single length/distance pair can output is 258
+      bytes, which is the maximum length that can be coded.  inflate_fast()
+      requires strm->avail_out >= 258 for each loop to avoid checking for
+      output space.
+ */
+void ZLIB_INTERNAL inflate_fast(strm, start)
+z_streamp strm;
+unsigned start;         /* inflate()'s starting value for strm->avail_out */
+{
+    struct inflate_state FAR *state;
+    z_const unsigned char FAR *in;      /* local strm->next_in */
+    z_const unsigned char FAR *last;    /* have enough input while in < last */
+    unsigned char FAR *out;     /* local strm->next_out */
+    unsigned char FAR *beg;     /* inflate()'s initial strm->next_out */
+    unsigned char FAR *end;     /* while out < end, enough space available */
+#ifdef INFLATE_STRICT
+    unsigned dmax;              /* maximum distance from zlib header */
+#endif
+    unsigned wsize;             /* window size or zero if not using window */
+    unsigned whave;             /* valid bytes in the window */
+    unsigned wnext;             /* window write index */
+    unsigned char FAR *window;  /* allocated sliding window, if wsize != 0 */
+    unsigned long hold;         /* local strm->hold */
+    unsigned bits;              /* local strm->bits */
+    code const FAR *lcode;      /* local strm->lencode */
+    code const FAR *dcode;      /* local strm->distcode */
+    unsigned lmask;             /* mask for first level of length codes */
+    unsigned dmask;             /* mask for first level of distance codes */
+    code here;                  /* retrieved table entry */
+    unsigned op;                /* code bits, operation, extra bits, or */
+                                /*  window position, window bytes to copy */
+    unsigned len;               /* match length, unused bytes */
+    unsigned dist;              /* match distance */
+    unsigned char FAR *from;    /* where to copy match from */
+
+    /* copy state to local variables */
+    state = (struct inflate_state FAR *)strm->state;
+    in = strm->next_in;
+    last = in + (strm->avail_in - 5);
+    out = strm->next_out;
+    beg = out - (start - strm->avail_out);
+    end = out + (strm->avail_out - 257);
+#ifdef INFLATE_STRICT
+    dmax = state->dmax;
+#endif
+    wsize = state->wsize;
+    whave = state->whave;
+    wnext = state->wnext;
+    window = state->window;
+    hold = state->hold;
+    bits = state->bits;
+    lcode = state->lencode;
+    dcode = state->distcode;
+    lmask = (1U << state->lenbits) - 1;
+    dmask = (1U << state->distbits) - 1;
+
+    /* decode literals and length/distances until end-of-block or not enough
+       input data or output space */
+    do {
+        if (bits < 15) {
+            hold += (unsigned long)(*in++) << bits;
+            bits += 8;
+            hold += (unsigned long)(*in++) << bits;
+            bits += 8;
+        }
+        here = lcode[hold & lmask];
+      dolen:
+        op = (unsigned)(here.bits);
+        hold >>= op;
+        bits -= op;
+        op = (unsigned)(here.op);
+        if (op == 0) {                          /* literal */
+            Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
+                    "inflate:         literal '%c'\n" :
+                    "inflate:         literal 0x%02x\n", here.val));
+            *out++ = (unsigned char)(here.val);
+        }
+        else if (op & 16) {                     /* length base */
+            len = (unsigned)(here.val);
+            op &= 15;                           /* number of extra bits */
+            if (op) {
+                if (bits < op) {
+                    hold += (unsigned long)(*in++) << bits;
+                    bits += 8;
+                }
+                len += (unsigned)hold & ((1U << op) - 1);
+                hold >>= op;
+                bits -= op;
+            }
+            Tracevv((stderr, "inflate:         length %u\n", len));
+            if (bits < 15) {
+                hold += (unsigned long)(*in++) << bits;
+                bits += 8;
+                hold += (unsigned long)(*in++) << bits;
+                bits += 8;
+            }
+            here = dcode[hold & dmask];
+          dodist:
+            op = (unsigned)(here.bits);
+            hold >>= op;
+            bits -= op;
+            op = (unsigned)(here.op);
+            if (op & 16) {                      /* distance base */
+                dist = (unsigned)(here.val);
+                op &= 15;                       /* number of extra bits */
+                if (bits < op) {
+                    hold += (unsigned long)(*in++) << bits;
+                    bits += 8;
+                    if (bits < op) {
+                        hold += (unsigned long)(*in++) << bits;
+                        bits += 8;
+                    }
+                }
+                dist += (unsigned)hold & ((1U << op) - 1);
+#ifdef INFLATE_STRICT
+                if (dist > dmax) {
+                    strm->msg = (char *)"invalid distance too far back";
+                    state->mode = BAD;
+                    break;
+                }
+#endif
+                hold >>= op;
+                bits -= op;
+                Tracevv((stderr, "inflate:         distance %u\n", dist));
+                op = (unsigned)(out - beg);     /* max distance in output */
+                if (dist > op) {                /* see if copy from window */
+                    op = dist - op;             /* distance back in window */
+                    if (op > whave) {
+                        if (state->sane) {
+                            strm->msg =
+                                (char *)"invalid distance too far back";
+                            state->mode = BAD;
+                            break;
+                        }
+#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
+                        if (len <= op - whave) {
+                            do {
+                                *out++ = 0;
+                            } while (--len);
+                            continue;
+                        }
+                        len -= op - whave;
+                        do {
+                            *out++ = 0;
+                        } while (--op > whave);
+                        if (op == 0) {
+                            from = out - dist;
+                            do {
+                                *out++ = *from++;
+                            } while (--len);
+                            continue;
+                        }
+#endif
+                    }
+                    from = window;
+                    if (wnext == 0) {           /* very common case */
+                        from += wsize - op;
+                        if (op < len) {         /* some from window */
+                            len -= op;
+                            do {
+                                *out++ = *from++;
+                            } while (--op);
+                            from = out - dist;  /* rest from output */
+                        }
+                    }
+                    else if (wnext < op) {      /* wrap around window */
+                        from += wsize + wnext - op;
+                        op -= wnext;
+                        if (op < len) {         /* some from end of window */
+                            len -= op;
+                            do {
+                                *out++ = *from++;
+                            } while (--op);
+                            from = window;
+                            if (wnext < len) {  /* some from start of window */
+                                op = wnext;
+                                len -= op;
+                                do {
+                                    *out++ = *from++;
+                                } while (--op);
+                                from = out - dist;      /* rest from output */
+                            }
+                        }
+                    }
+                    else {                      /* contiguous in window */
+                        from += wnext - op;
+                        if (op < len) {         /* some from window */
+                            len -= op;
+                            do {
+                                *out++ = *from++;
+                            } while (--op);
+                            from = out - dist;  /* rest from output */
+                        }
+                    }
+                    while (len > 2) {
+                        *out++ = *from++;
+                        *out++ = *from++;
+                        *out++ = *from++;
+                        len -= 3;
+                    }
+                    if (len) {
+                        *out++ = *from++;
+                        if (len > 1)
+                            *out++ = *from++;
+                    }
+                }
+                else {
+                    from = out - dist;          /* copy direct from output */
+                    do {                        /* minimum length is three */
+                        *out++ = *from++;
+                        *out++ = *from++;
+                        *out++ = *from++;
+                        len -= 3;
+                    } while (len > 2);
+                    if (len) {
+                        *out++ = *from++;
+                        if (len > 1)
+                            *out++ = *from++;
+                    }
+                }
+            }
+            else if ((op & 64) == 0) {          /* 2nd level distance code */
+                here = dcode[here.val + (hold & ((1U << op) - 1))];
+                goto dodist;
+            }
+            else {
+                strm->msg = (char *)"invalid distance code";
+                state->mode = BAD;
+                break;
+            }
+        }
+        else if ((op & 64) == 0) {              /* 2nd level length code */
+            here = lcode[here.val + (hold & ((1U << op) - 1))];
+            goto dolen;
+        }
+        else if (op & 32) {                     /* end-of-block */
+            Tracevv((stderr, "inflate:         end of block\n"));
+            state->mode = TYPE;
+            break;
+        }
+        else {
+            strm->msg = (char *)"invalid literal/length code";
+            state->mode = BAD;
+            break;
+        }
+    } while (in < last && out < end);
+
+    /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
+    len = bits >> 3;
+    in -= len;
+    bits -= len << 3;
+    hold &= (1U << bits) - 1;
+
+    /* update state and return */
+    strm->next_in = in;
+    strm->next_out = out;
+    strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
+    strm->avail_out = (unsigned)(out < end ?
+                                 257 + (end - out) : 257 - (out - end));
+    state->hold = hold;
+    state->bits = bits;
+    return;
+}
+
+/*
+   inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
+   - Using bit fields for code structure
+   - Different op definition to avoid & for extra bits (do & for table bits)
+   - Three separate decoding do-loops for direct, window, and wnext == 0
+   - Special case for distance > 1 copies to do overlapped load and store copy
+   - Explicit branch predictions (based on measured branch probabilities)
+   - Deferring match copy and interspersed it with decoding subsequent codes
+   - Swapping literal/length else
+   - Swapping window/direct else
+   - Larger unrolled copy loops (three is about right)
+   - Moving len -= 3 statement into middle of loop
+ */
+
+#endif /* !ASMINF */
similarity index 90%
rename from deps/zlib/inffast.h
rename to deps/libchdr/deps/zlib-1.2.11/inffast.h
index 169a85a..e5c1aa4 100644 (file)
@@ -7,9 +7,5 @@
    part of the implementation of the compression library and is
    subject to change. Applications should only use zlib.h.
  */
-#ifndef _INFFAST_H
-#define _INFFAST_H
 
 void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
-
-#endif
similarity index 98%
rename from deps/zlib/inffixed.h
rename to deps/libchdr/deps/zlib-1.2.11/inffixed.h
index 238a55f..d628327 100644 (file)
@@ -1,7 +1,4 @@
-#ifndef _INFFIXED_H
-#define _INFFIXED_H
-
-/* inffixed.h -- table for decoding fixed codes
+    /* inffixed.h -- table for decoding fixed codes
      * Generated automatically by makefixed().
      */
 
@@ -95,5 +92,3 @@
         {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
         {22,5,193},{64,5,0}
     };
-
-#endif
diff --git a/deps/libchdr/deps/zlib-1.2.11/inflate.c b/deps/libchdr/deps/zlib-1.2.11/inflate.c
new file mode 100644 (file)
index 0000000..ac333e8
--- /dev/null
@@ -0,0 +1,1561 @@
+/* inflate.c -- zlib decompression
+ * Copyright (C) 1995-2016 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * Change history:
+ *
+ * 1.2.beta0    24 Nov 2002
+ * - First version -- complete rewrite of inflate to simplify code, avoid
+ *   creation of window when not needed, minimize use of window when it is
+ *   needed, make inffast.c even faster, implement gzip decoding, and to
+ *   improve code readability and style over the previous zlib inflate code
+ *
+ * 1.2.beta1    25 Nov 2002
+ * - Use pointers for available input and output checking in inffast.c
+ * - Remove input and output counters in inffast.c
+ * - Change inffast.c entry and loop from avail_in >= 7 to >= 6
+ * - Remove unnecessary second byte pull from length extra in inffast.c
+ * - Unroll direct copy to three copies per loop in inffast.c
+ *
+ * 1.2.beta2    4 Dec 2002
+ * - Change external routine names to reduce potential conflicts
+ * - Correct filename to inffixed.h for fixed tables in inflate.c
+ * - Make hbuf[] unsigned char to match parameter type in inflate.c
+ * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
+ *   to avoid negation problem on Alphas (64 bit) in inflate.c
+ *
+ * 1.2.beta3    22 Dec 2002
+ * - Add comments on state->bits assertion in inffast.c
+ * - Add comments on op field in inftrees.h
+ * - Fix bug in reuse of allocated window after inflateReset()
+ * - Remove bit fields--back to byte structure for speed
+ * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths
+ * - Change post-increments to pre-increments in inflate_fast(), PPC biased?
+ * - Add compile time option, POSTINC, to use post-increments instead (Intel?)
+ * - Make MATCH copy in inflate() much faster for when inflate_fast() not used
+ * - Use local copies of stream next and avail values, as well as local bit
+ *   buffer and bit count in inflate()--for speed when inflate_fast() not used
+ *
+ * 1.2.beta4    1 Jan 2003
+ * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings
+ * - Move a comment on output buffer sizes from inffast.c to inflate.c
+ * - Add comments in inffast.c to introduce the inflate_fast() routine
+ * - Rearrange window copies in inflate_fast() for speed and simplification
+ * - Unroll last copy for window match in inflate_fast()
+ * - Use local copies of window variables in inflate_fast() for speed
+ * - Pull out common wnext == 0 case for speed in inflate_fast()
+ * - Make op and len in inflate_fast() unsigned for consistency
+ * - Add FAR to lcode and dcode declarations in inflate_fast()
+ * - Simplified bad distance check in inflate_fast()
+ * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new
+ *   source file infback.c to provide a call-back interface to inflate for
+ *   programs like gzip and unzip -- uses window as output buffer to avoid
+ *   window copying
+ *
+ * 1.2.beta5    1 Jan 2003
+ * - Improved inflateBack() interface to allow the caller to provide initial
+ *   input in strm.
+ * - Fixed stored blocks bug in inflateBack()
+ *
+ * 1.2.beta6    4 Jan 2003
+ * - Added comments in inffast.c on effectiveness of POSTINC
+ * - Typecasting all around to reduce compiler warnings
+ * - Changed loops from while (1) or do {} while (1) to for (;;), again to
+ *   make compilers happy
+ * - Changed type of window in inflateBackInit() to unsigned char *
+ *
+ * 1.2.beta7    27 Jan 2003
+ * - Changed many types to unsigned or unsigned short to avoid warnings
+ * - Added inflateCopy() function
+ *
+ * 1.2.0        9 Mar 2003
+ * - Changed inflateBack() interface to provide separate opaque descriptors
+ *   for the in() and out() functions
+ * - Changed inflateBack() argument and in_func typedef to swap the length
+ *   and buffer address return values for the input function
+ * - Check next_in and next_out for Z_NULL on entry to inflate()
+ *
+ * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+#include "inffast.h"
+
+#ifdef MAKEFIXED
+#  ifndef BUILDFIXED
+#    define BUILDFIXED
+#  endif
+#endif
+
+/* function prototypes */
+local int inflateStateCheck OF((z_streamp strm));
+local void fixedtables OF((struct inflate_state FAR *state));
+local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
+                           unsigned copy));
+#ifdef BUILDFIXED
+   void makefixed OF((void));
+#endif
+local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
+                              unsigned len));
+
+local int inflateStateCheck(strm)
+z_streamp strm;
+{
+    struct inflate_state FAR *state;
+    if (strm == Z_NULL ||
+        strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
+        return 1;
+    state = (struct inflate_state FAR *)strm->state;
+    if (state == Z_NULL || state->strm != strm ||
+        state->mode < HEAD || state->mode > SYNC)
+        return 1;
+    return 0;
+}
+
+int ZEXPORT inflateResetKeep(strm)
+z_streamp strm;
+{
+    struct inflate_state FAR *state;
+
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    strm->total_in = strm->total_out = state->total = 0;
+    strm->msg = Z_NULL;
+    if (state->wrap)        /* to support ill-conceived Java test suite */
+        strm->adler = state->wrap & 1;
+    state->mode = HEAD;
+    state->last = 0;
+    state->havedict = 0;
+    state->dmax = 32768U;
+    state->head = Z_NULL;
+    state->hold = 0;
+    state->bits = 0;
+    state->lencode = state->distcode = state->next = state->codes;
+    state->sane = 1;
+    state->back = -1;
+    Tracev((stderr, "inflate: reset\n"));
+    return Z_OK;
+}
+
+int ZEXPORT inflateReset(strm)
+z_streamp strm;
+{
+    struct inflate_state FAR *state;
+
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    state->wsize = 0;
+    state->whave = 0;
+    state->wnext = 0;
+    return inflateResetKeep(strm);
+}
+
+int ZEXPORT inflateReset2(strm, windowBits)
+z_streamp strm;
+int windowBits;
+{
+    int wrap;
+    struct inflate_state FAR *state;
+
+    /* get the state */
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+
+    /* extract wrap request from windowBits parameter */
+    if (windowBits < 0) {
+        wrap = 0;
+        windowBits = -windowBits;
+    }
+    else {
+        wrap = (windowBits >> 4) + 5;
+#ifdef GUNZIP
+        if (windowBits < 48)
+            windowBits &= 15;
+#endif
+    }
+
+    /* set number of window bits, free window if different */
+    if (windowBits && (windowBits < 8 || windowBits > 15))
+        return Z_STREAM_ERROR;
+    if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
+        ZFREE(strm, state->window);
+        state->window = Z_NULL;
+    }
+
+    /* update state and reset the rest of it */
+    state->wrap = wrap;
+    state->wbits = (unsigned)windowBits;
+    return inflateReset(strm);
+}
+
+int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
+z_streamp strm;
+int windowBits;
+const char *version;
+int stream_size;
+{
+    int ret;
+    struct inflate_state FAR *state;
+
+    if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
+        stream_size != (int)(sizeof(z_stream)))
+        return Z_VERSION_ERROR;
+    if (strm == Z_NULL) return Z_STREAM_ERROR;
+    strm->msg = Z_NULL;                 /* in case we return an error */
+    if (strm->zalloc == (alloc_func)0) {
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
+        strm->zalloc = zcalloc;
+        strm->opaque = (voidpf)0;
+#endif
+    }
+    if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
+        strm->zfree = zcfree;
+#endif
+    state = (struct inflate_state FAR *)
+            ZALLOC(strm, 1, sizeof(struct inflate_state));
+    if (state == Z_NULL) return Z_MEM_ERROR;
+    Tracev((stderr, "inflate: allocated\n"));
+    strm->state = (struct internal_state FAR *)state;
+    state->strm = strm;
+    state->window = Z_NULL;
+    state->mode = HEAD;     /* to pass state test in inflateReset2() */
+    ret = inflateReset2(strm, windowBits);
+    if (ret != Z_OK) {
+        ZFREE(strm, state);
+        strm->state = Z_NULL;
+    }
+    return ret;
+}
+
+int ZEXPORT inflateInit_(strm, version, stream_size)
+z_streamp strm;
+const char *version;
+int stream_size;
+{
+    return inflateInit2_(strm, DEF_WBITS, version, stream_size);
+}
+
+int ZEXPORT inflatePrime(strm, bits, value)
+z_streamp strm;
+int bits;
+int value;
+{
+    struct inflate_state FAR *state;
+
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    if (bits < 0) {
+        state->hold = 0;
+        state->bits = 0;
+        return Z_OK;
+    }
+    if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
+    value &= (1L << bits) - 1;
+    state->hold += (unsigned)value << state->bits;
+    state->bits += (uInt)bits;
+    return Z_OK;
+}
+
+/*
+   Return state with length and distance decoding tables and index sizes set to
+   fixed code decoding.  Normally this returns fixed tables from inffixed.h.
+   If BUILDFIXED is defined, then instead this routine builds the tables the
+   first time it's called, and returns those tables the first time and
+   thereafter.  This reduces the size of the code by about 2K bytes, in
+   exchange for a little execution time.  However, BUILDFIXED should not be
+   used for threaded applications, since the rewriting of the tables and virgin
+   may not be thread-safe.
+ */
+local void fixedtables(state)
+struct inflate_state FAR *state;
+{
+#ifdef BUILDFIXED
+    static int virgin = 1;
+    static code *lenfix, *distfix;
+    static code fixed[544];
+
+    /* build fixed huffman tables if first call (may not be thread safe) */
+    if (virgin) {
+        unsigned sym, bits;
+        static code *next;
+
+        /* literal/length table */
+        sym = 0;
+        while (sym < 144) state->lens[sym++] = 8;
+        while (sym < 256) state->lens[sym++] = 9;
+        while (sym < 280) state->lens[sym++] = 7;
+        while (sym < 288) state->lens[sym++] = 8;
+        next = fixed;
+        lenfix = next;
+        bits = 9;
+        inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
+
+        /* distance table */
+        sym = 0;
+        while (sym < 32) state->lens[sym++] = 5;
+        distfix = next;
+        bits = 5;
+        inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
+
+        /* do this just once */
+        virgin = 0;
+    }
+#else /* !BUILDFIXED */
+#   include "inffixed.h"
+#endif /* BUILDFIXED */
+    state->lencode = lenfix;
+    state->lenbits = 9;
+    state->distcode = distfix;
+    state->distbits = 5;
+}
+
+#ifdef MAKEFIXED
+#include <stdio.h>
+
+/*
+   Write out the inffixed.h that is #include'd above.  Defining MAKEFIXED also
+   defines BUILDFIXED, so the tables are built on the fly.  makefixed() writes
+   those tables to stdout, which would be piped to inffixed.h.  A small program
+   can simply call makefixed to do this:
+
+    void makefixed(void);
+
+    int main(void)
+    {
+        makefixed();
+        return 0;
+    }
+
+   Then that can be linked with zlib built with MAKEFIXED defined and run:
+
+    a.out > inffixed.h
+ */
+void makefixed()
+{
+    unsigned low, size;
+    struct inflate_state state;
+
+    fixedtables(&state);
+    puts("    /* inffixed.h -- table for decoding fixed codes");
+    puts("     * Generated automatically by makefixed().");
+    puts("     */");
+    puts("");
+    puts("    /* WARNING: this file should *not* be used by applications.");
+    puts("       It is part of the implementation of this library and is");
+    puts("       subject to change. Applications should only use zlib.h.");
+    puts("     */");
+    puts("");
+    size = 1U << 9;
+    printf("    static const code lenfix[%u] = {", size);
+    low = 0;
+    for (;;) {
+        if ((low % 7) == 0) printf("\n        ");
+        printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
+               state.lencode[low].bits, state.lencode[low].val);
+        if (++low == size) break;
+        putchar(',');
+    }
+    puts("\n    };");
+    size = 1U << 5;
+    printf("\n    static const code distfix[%u] = {", size);
+    low = 0;
+    for (;;) {
+        if ((low % 6) == 0) printf("\n        ");
+        printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
+               state.distcode[low].val);
+        if (++low == size) break;
+        putchar(',');
+    }
+    puts("\n    };");
+}
+#endif /* MAKEFIXED */
+
+/*
+   Update the window with the last wsize (normally 32K) bytes written before
+   returning.  If window does not exist yet, create it.  This is only called
+   when a window is already in use, or when output has been written during this
+   inflate call, but the end of the deflate stream has not been reached yet.
+   It is also called to create a window for dictionary data when a dictionary
+   is loaded.
+
+   Providing output buffers larger than 32K to inflate() should provide a speed
+   advantage, since only the last 32K of output is copied to the sliding window
+   upon return from inflate(), and since all distances after the first 32K of
+   output will fall in the output data, making match copies simpler and faster.
+   The advantage may be dependent on the size of the processor's data caches.
+ */
+local int updatewindow(strm, end, copy)
+z_streamp strm;
+const Bytef *end;
+unsigned copy;
+{
+    struct inflate_state FAR *state;
+    unsigned dist;
+
+    state = (struct inflate_state FAR *)strm->state;
+
+    /* if it hasn't been done already, allocate space for the window */
+    if (state->window == Z_NULL) {
+        state->window = (unsigned char FAR *)
+                        ZALLOC(strm, 1U << state->wbits,
+                               sizeof(unsigned char));
+        if (state->window == Z_NULL) return 1;
+    }
+
+    /* if window not in use yet, initialize */
+    if (state->wsize == 0) {
+        state->wsize = 1U << state->wbits;
+        state->wnext = 0;
+        state->whave = 0;
+    }
+
+    /* copy state->wsize or less output bytes into the circular window */
+    if (copy >= state->wsize) {
+        zmemcpy(state->window, end - state->wsize, state->wsize);
+        state->wnext = 0;
+        state->whave = state->wsize;
+    }
+    else {
+        dist = state->wsize - state->wnext;
+        if (dist > copy) dist = copy;
+        zmemcpy(state->window + state->wnext, end - copy, dist);
+        copy -= dist;
+        if (copy) {
+            zmemcpy(state->window, end - copy, copy);
+            state->wnext = copy;
+            state->whave = state->wsize;
+        }
+        else {
+            state->wnext += dist;
+            if (state->wnext == state->wsize) state->wnext = 0;
+            if (state->whave < state->wsize) state->whave += dist;
+        }
+    }
+    return 0;
+}
+
+/* Macros for inflate(): */
+
+/* check function to use adler32() for zlib or crc32() for gzip */
+#ifdef GUNZIP
+#  define UPDATE(check, buf, len) \
+    (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
+#else
+#  define UPDATE(check, buf, len) adler32(check, buf, len)
+#endif
+
+/* check macros for header crc */
+#ifdef GUNZIP
+#  define CRC2(check, word) \
+    do { \
+        hbuf[0] = (unsigned char)(word); \
+        hbuf[1] = (unsigned char)((word) >> 8); \
+        check = crc32(check, hbuf, 2); \
+    } while (0)
+
+#  define CRC4(check, word) \
+    do { \
+        hbuf[0] = (unsigned char)(word); \
+        hbuf[1] = (unsigned char)((word) >> 8); \
+        hbuf[2] = (unsigned char)((word) >> 16); \
+        hbuf[3] = (unsigned char)((word) >> 24); \
+        check = crc32(check, hbuf, 4); \
+    } while (0)
+#endif
+
+/* Load registers with state in inflate() for speed */
+#define LOAD() \
+    do { \
+        put = strm->next_out; \
+        left = strm->avail_out; \
+        next = strm->next_in; \
+        have = strm->avail_in; \
+        hold = state->hold; \
+        bits = state->bits; \
+    } while (0)
+
+/* Restore state from registers in inflate() */
+#define RESTORE() \
+    do { \
+        strm->next_out = put; \
+        strm->avail_out = left; \
+        strm->next_in = next; \
+        strm->avail_in = have; \
+        state->hold = hold; \
+        state->bits = bits; \
+    } while (0)
+
+/* Clear the input bit accumulator */
+#define INITBITS() \
+    do { \
+        hold = 0; \
+        bits = 0; \
+    } while (0)
+
+/* Get a byte of input into the bit accumulator, or return from inflate()
+   if there is no input available. */
+#define PULLBYTE() \
+    do { \
+        if (have == 0) goto inf_leave; \
+        have--; \
+        hold += (unsigned long)(*next++) << bits; \
+        bits += 8; \
+    } while (0)
+
+/* Assure that there are at least n bits in the bit accumulator.  If there is
+   not enough available input to do that, then return from inflate(). */
+#define NEEDBITS(n) \
+    do { \
+        while (bits < (unsigned)(n)) \
+            PULLBYTE(); \
+    } while (0)
+
+/* Return the low n bits of the bit accumulator (n < 16) */
+#define BITS(n) \
+    ((unsigned)hold & ((1U << (n)) - 1))
+
+/* Remove n bits from the bit accumulator */
+#define DROPBITS(n) \
+    do { \
+        hold >>= (n); \
+        bits -= (unsigned)(n); \
+    } while (0)
+
+/* Remove zero to seven bits as needed to go to a byte boundary */
+#define BYTEBITS() \
+    do { \
+        hold >>= bits & 7; \
+        bits -= bits & 7; \
+    } while (0)
+
+/*
+   inflate() uses a state machine to process as much input data and generate as
+   much output data as possible before returning.  The state machine is
+   structured roughly as follows:
+
+    for (;;) switch (state) {
+    ...
+    case STATEn:
+        if (not enough input data or output space to make progress)
+            return;
+        ... make progress ...
+        state = STATEm;
+        break;
+    ...
+    }
+
+   so when inflate() is called again, the same case is attempted again, and
+   if the appropriate resources are provided, the machine proceeds to the
+   next state.  The NEEDBITS() macro is usually the way the state evaluates
+   whether it can proceed or should return.  NEEDBITS() does the return if
+   the requested bits are not available.  The typical use of the BITS macros
+   is:
+
+        NEEDBITS(n);
+        ... do something with BITS(n) ...
+        DROPBITS(n);
+
+   where NEEDBITS(n) either returns from inflate() if there isn't enough
+   input left to load n bits into the accumulator, or it continues.  BITS(n)
+   gives the low n bits in the accumulator.  When done, DROPBITS(n) drops
+   the low n bits off the accumulator.  INITBITS() clears the accumulator
+   and sets the number of available bits to zero.  BYTEBITS() discards just
+   enough bits to put the accumulator on a byte boundary.  After BYTEBITS()
+   and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
+
+   NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
+   if there is no input available.  The decoding of variable length codes uses
+   PULLBYTE() directly in order to pull just enough bytes to decode the next
+   code, and no more.
+
+   Some states loop until they get enough input, making sure that enough
+   state information is maintained to continue the loop where it left off
+   if NEEDBITS() returns in the loop.  For example, want, need, and keep
+   would all have to actually be part of the saved state in case NEEDBITS()
+   returns:
+
+    case STATEw:
+        while (want < need) {
+            NEEDBITS(n);
+            keep[want++] = BITS(n);
+            DROPBITS(n);
+        }
+        state = STATEx;
+    case STATEx:
+
+   As shown above, if the next state is also the next case, then the break
+   is omitted.
+
+   A state may also return if there is not enough output space available to
+   complete that state.  Those states are copying stored data, writing a
+   literal byte, and copying a matching string.
+
+   When returning, a "goto inf_leave" is used to update the total counters,
+   update the check value, and determine whether any progress has been made
+   during that inflate() call in order to return the proper return code.
+   Progress is defined as a change in either strm->avail_in or strm->avail_out.
+   When there is a window, goto inf_leave will update the window with the last
+   output written.  If a goto inf_leave occurs in the middle of decompression
+   and there is no window currently, goto inf_leave will create one and copy
+   output to the window for the next call of inflate().
+
+   In this implementation, the flush parameter of inflate() only affects the
+   return code (per zlib.h).  inflate() always writes as much as possible to
+   strm->next_out, given the space available and the provided input--the effect
+   documented in zlib.h of Z_SYNC_FLUSH.  Furthermore, inflate() always defers
+   the allocation of and copying into a sliding window until necessary, which
+   provides the effect documented in zlib.h for Z_FINISH when the entire input
+   stream available.  So the only thing the flush parameter actually does is:
+   when flush is set to Z_FINISH, inflate() cannot return Z_OK.  Instead it
+   will return Z_BUF_ERROR if it has not reached the end of the stream.
+ */
+
+int ZEXPORT inflate(strm, flush)
+z_streamp strm;
+int flush;
+{
+    struct inflate_state FAR *state;
+    z_const unsigned char FAR *next;    /* next input */
+    unsigned char FAR *put;     /* next output */
+    unsigned have, left;        /* available input and output */
+    unsigned long hold;         /* bit buffer */
+    unsigned bits;              /* bits in bit buffer */
+    unsigned in, out;           /* save starting available input and output */
+    unsigned copy;              /* number of stored or match bytes to copy */
+    unsigned char FAR *from;    /* where to copy match bytes from */
+    code here;                  /* current decoding table entry */
+    code last;                  /* parent table entry */
+    unsigned len;               /* length to copy for repeats, bits to drop */
+    int ret;                    /* return code */
+#ifdef GUNZIP
+    unsigned char hbuf[4];      /* buffer for gzip header crc calculation */
+#endif
+    static const unsigned short order[19] = /* permutation of code lengths */
+        {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+
+    if (inflateStateCheck(strm) || strm->next_out == Z_NULL ||
+        (strm->next_in == Z_NULL && strm->avail_in != 0))
+        return Z_STREAM_ERROR;
+
+    state = (struct inflate_state FAR *)strm->state;
+    if (state->mode == TYPE) state->mode = TYPEDO;      /* skip check */
+    LOAD();
+    in = have;
+    out = left;
+    ret = Z_OK;
+    for (;;)
+        switch (state->mode) {
+        case HEAD:
+            if (state->wrap == 0) {
+                state->mode = TYPEDO;
+                break;
+            }
+            NEEDBITS(16);
+#ifdef GUNZIP
+            if ((state->wrap & 2) && hold == 0x8b1f) {  /* gzip header */
+                if (state->wbits == 0)
+                    state->wbits = 15;
+                state->check = crc32(0L, Z_NULL, 0);
+                CRC2(state->check, hold);
+                INITBITS();
+                state->mode = FLAGS;
+                break;
+            }
+            state->flags = 0;           /* expect zlib header */
+            if (state->head != Z_NULL)
+                state->head->done = -1;
+            if (!(state->wrap & 1) ||   /* check if zlib header allowed */
+#else
+            if (
+#endif
+                ((BITS(8) << 8) + (hold >> 8)) % 31) {
+                strm->msg = (char *)"incorrect header check";
+                state->mode = BAD;
+                break;
+            }
+            if (BITS(4) != Z_DEFLATED) {
+                strm->msg = (char *)"unknown compression method";
+                state->mode = BAD;
+                break;
+            }
+            DROPBITS(4);
+            len = BITS(4) + 8;
+            if (state->wbits == 0)
+                state->wbits = len;
+            if (len > 15 || len > state->wbits) {
+                strm->msg = (char *)"invalid window size";
+                state->mode = BAD;
+                break;
+            }
+            state->dmax = 1U << len;
+            Tracev((stderr, "inflate:   zlib header ok\n"));
+            strm->adler = state->check = adler32(0L, Z_NULL, 0);
+            state->mode = hold & 0x200 ? DICTID : TYPE;
+            INITBITS();
+            break;
+#ifdef GUNZIP
+        case FLAGS:
+            NEEDBITS(16);
+            state->flags = (int)(hold);
+            if ((state->flags & 0xff) != Z_DEFLATED) {
+                strm->msg = (char *)"unknown compression method";
+                state->mode = BAD;
+                break;
+            }
+            if (state->flags & 0xe000) {
+                strm->msg = (char *)"unknown header flags set";
+                state->mode = BAD;
+                break;
+            }
+            if (state->head != Z_NULL)
+                state->head->text = (int)((hold >> 8) & 1);
+            if ((state->flags & 0x0200) && (state->wrap & 4))
+                CRC2(state->check, hold);
+            INITBITS();
+            state->mode = TIME;
+        case TIME:
+            NEEDBITS(32);
+            if (state->head != Z_NULL)
+                state->head->time = hold;
+            if ((state->flags & 0x0200) && (state->wrap & 4))
+                CRC4(state->check, hold);
+            INITBITS();
+            state->mode = OS;
+        case OS:
+            NEEDBITS(16);
+            if (state->head != Z_NULL) {
+                state->head->xflags = (int)(hold & 0xff);
+                state->head->os = (int)(hold >> 8);
+            }
+            if ((state->flags & 0x0200) && (state->wrap & 4))
+                CRC2(state->check, hold);
+            INITBITS();
+            state->mode = EXLEN;
+        case EXLEN:
+            if (state->flags & 0x0400) {
+                NEEDBITS(16);
+                state->length = (unsigned)(hold);
+                if (state->head != Z_NULL)
+                    state->head->extra_len = (unsigned)hold;
+                if ((state->flags & 0x0200) && (state->wrap & 4))
+                    CRC2(state->check, hold);
+                INITBITS();
+            }
+            else if (state->head != Z_NULL)
+                state->head->extra = Z_NULL;
+            state->mode = EXTRA;
+        case EXTRA:
+            if (state->flags & 0x0400) {
+                copy = state->length;
+                if (copy > have) copy = have;
+                if (copy) {
+                    if (state->head != Z_NULL &&
+                        state->head->extra != Z_NULL) {
+                        len = state->head->extra_len - state->length;
+                        zmemcpy(state->head->extra + len, next,
+                                len + copy > state->head->extra_max ?
+                                state->head->extra_max - len : copy);
+                    }
+                    if ((state->flags & 0x0200) && (state->wrap & 4))
+                        state->check = crc32(state->check, next, copy);
+                    have -= copy;
+                    next += copy;
+                    state->length -= copy;
+                }
+                if (state->length) goto inf_leave;
+            }
+            state->length = 0;
+            state->mode = NAME;
+        case NAME:
+            if (state->flags & 0x0800) {
+                if (have == 0) goto inf_leave;
+                copy = 0;
+                do {
+                    len = (unsigned)(next[copy++]);
+                    if (state->head != Z_NULL &&
+                            state->head->name != Z_NULL &&
+                            state->length < state->head->name_max)
+                        state->head->name[state->length++] = (Bytef)len;
+                } while (len && copy < have);
+                if ((state->flags & 0x0200) && (state->wrap & 4))
+                    state->check = crc32(state->check, next, copy);
+                have -= copy;
+                next += copy;
+                if (len) goto inf_leave;
+            }
+            else if (state->head != Z_NULL)
+                state->head->name = Z_NULL;
+            state->length = 0;
+            state->mode = COMMENT;
+        case COMMENT:
+            if (state->flags & 0x1000) {
+                if (have == 0) goto inf_leave;
+                copy = 0;
+                do {
+                    len = (unsigned)(next[copy++]);
+                    if (state->head != Z_NULL &&
+                            state->head->comment != Z_NULL &&
+                            state->length < state->head->comm_max)
+                        state->head->comment[state->length++] = (Bytef)len;
+                } while (len && copy < have);
+                if ((state->flags & 0x0200) && (state->wrap & 4))
+                    state->check = crc32(state->check, next, copy);
+                have -= copy;
+                next += copy;
+                if (len) goto inf_leave;
+            }
+            else if (state->head != Z_NULL)
+                state->head->comment = Z_NULL;
+            state->mode = HCRC;
+        case HCRC:
+            if (state->flags & 0x0200) {
+                NEEDBITS(16);
+                if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
+                    strm->msg = (char *)"header crc mismatch";
+                    state->mode = BAD;
+                    break;
+                }
+                INITBITS();
+            }
+            if (state->head != Z_NULL) {
+                state->head->hcrc = (int)((state->flags >> 9) & 1);
+                state->head->done = 1;
+            }
+            strm->adler = state->check = crc32(0L, Z_NULL, 0);
+            state->mode = TYPE;
+            break;
+#endif
+        case DICTID:
+            NEEDBITS(32);
+            strm->adler = state->check = ZSWAP32(hold);
+            INITBITS();
+            state->mode = DICT;
+        case DICT:
+            if (state->havedict == 0) {
+                RESTORE();
+                return Z_NEED_DICT;
+            }
+            strm->adler = state->check = adler32(0L, Z_NULL, 0);
+            state->mode = TYPE;
+        case TYPE:
+            if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
+        case TYPEDO:
+            if (state->last) {
+                BYTEBITS();
+                state->mode = CHECK;
+                break;
+            }
+            NEEDBITS(3);
+            state->last = BITS(1);
+            DROPBITS(1);
+            switch (BITS(2)) {
+            case 0:                             /* stored block */
+                Tracev((stderr, "inflate:     stored block%s\n",
+                        state->last ? " (last)" : ""));
+                state->mode = STORED;
+                break;
+            case 1:                             /* fixed block */
+                fixedtables(state);
+                Tracev((stderr, "inflate:     fixed codes block%s\n",
+                        state->last ? " (last)" : ""));
+                state->mode = LEN_;             /* decode codes */
+                if (flush == Z_TREES) {
+                    DROPBITS(2);
+                    goto inf_leave;
+                }
+                break;
+            case 2:                             /* dynamic block */
+                Tracev((stderr, "inflate:     dynamic codes block%s\n",
+                        state->last ? " (last)" : ""));
+                state->mode = TABLE;
+                break;
+            case 3:
+                strm->msg = (char *)"invalid block type";
+                state->mode = BAD;
+            }
+            DROPBITS(2);
+            break;
+        case STORED:
+            BYTEBITS();                         /* go to byte boundary */
+            NEEDBITS(32);
+            if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
+                strm->msg = (char *)"invalid stored block lengths";
+                state->mode = BAD;
+                break;
+            }
+            state->length = (unsigned)hold & 0xffff;
+            Tracev((stderr, "inflate:       stored length %u\n",
+                    state->length));
+            INITBITS();
+            state->mode = COPY_;
+            if (flush == Z_TREES) goto inf_leave;
+        case COPY_:
+            state->mode = COPY;
+        case COPY:
+            copy = state->length;
+            if (copy) {
+                if (copy > have) copy = have;
+                if (copy > left) copy = left;
+                if (copy == 0) goto inf_leave;
+                zmemcpy(put, next, copy);
+                have -= copy;
+                next += copy;
+                left -= copy;
+                put += copy;
+                state->length -= copy;
+                break;
+            }
+            Tracev((stderr, "inflate:       stored end\n"));
+            state->mode = TYPE;
+            break;
+        case TABLE:
+            NEEDBITS(14);
+            state->nlen = BITS(5) + 257;
+            DROPBITS(5);
+            state->ndist = BITS(5) + 1;
+            DROPBITS(5);
+            state->ncode = BITS(4) + 4;
+            DROPBITS(4);
+#ifndef PKZIP_BUG_WORKAROUND
+            if (state->nlen > 286 || state->ndist > 30) {
+                strm->msg = (char *)"too many length or distance symbols";
+                state->mode = BAD;
+                break;
+            }
+#endif
+            Tracev((stderr, "inflate:       table sizes ok\n"));
+            state->have = 0;
+            state->mode = LENLENS;
+        case LENLENS:
+            while (state->have < state->ncode) {
+                NEEDBITS(3);
+                state->lens[order[state->have++]] = (unsigned short)BITS(3);
+                DROPBITS(3);
+            }
+            while (state->have < 19)
+                state->lens[order[state->have++]] = 0;
+            state->next = state->codes;
+            state->lencode = (const code FAR *)(state->next);
+            state->lenbits = 7;
+            ret = inflate_table(CODES, state->lens, 19, &(state->next),
+                                &(state->lenbits), state->work);
+            if (ret) {
+                strm->msg = (char *)"invalid code lengths set";
+                state->mode = BAD;
+                break;
+            }
+            Tracev((stderr, "inflate:       code lengths ok\n"));
+            state->have = 0;
+            state->mode = CODELENS;
+        case CODELENS:
+            while (state->have < state->nlen + state->ndist) {
+                for (;;) {
+                    here = state->lencode[BITS(state->lenbits)];
+                    if ((unsigned)(here.bits) <= bits) break;
+                    PULLBYTE();
+                }
+                if (here.val < 16) {
+                    DROPBITS(here.bits);
+                    state->lens[state->have++] = here.val;
+                }
+                else {
+                    if (here.val == 16) {
+                        NEEDBITS(here.bits + 2);
+                        DROPBITS(here.bits);
+                        if (state->have == 0) {
+                            strm->msg = (char *)"invalid bit length repeat";
+                            state->mode = BAD;
+                            break;
+                        }
+                        len = state->lens[state->have - 1];
+                        copy = 3 + BITS(2);
+                        DROPBITS(2);
+                    }
+                    else if (here.val == 17) {
+                        NEEDBITS(here.bits + 3);
+                        DROPBITS(here.bits);
+                        len = 0;
+                        copy = 3 + BITS(3);
+                        DROPBITS(3);
+                    }
+                    else {
+                        NEEDBITS(here.bits + 7);
+                        DROPBITS(here.bits);
+                        len = 0;
+                        copy = 11 + BITS(7);
+                        DROPBITS(7);
+                    }
+                    if (state->have + copy > state->nlen + state->ndist) {
+                        strm->msg = (char *)"invalid bit length repeat";
+                        state->mode = BAD;
+                        break;
+                    }
+                    while (copy--)
+                        state->lens[state->have++] = (unsigned short)len;
+                }
+            }
+
+            /* handle error breaks in while */
+            if (state->mode == BAD) break;
+
+            /* check for end-of-block code (better have one) */
+            if (state->lens[256] == 0) {
+                strm->msg = (char *)"invalid code -- missing end-of-block";
+                state->mode = BAD;
+                break;
+            }
+
+            /* build code tables -- note: do not change the lenbits or distbits
+               values here (9 and 6) without reading the comments in inftrees.h
+               concerning the ENOUGH constants, which depend on those values */
+            state->next = state->codes;
+            state->lencode = (const code FAR *)(state->next);
+            state->lenbits = 9;
+            ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
+                                &(state->lenbits), state->work);
+            if (ret) {
+                strm->msg = (char *)"invalid literal/lengths set";
+                state->mode = BAD;
+                break;
+            }
+            state->distcode = (const code FAR *)(state->next);
+            state->distbits = 6;
+            ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
+                            &(state->next), &(state->distbits), state->work);
+            if (ret) {
+                strm->msg = (char *)"invalid distances set";
+                state->mode = BAD;
+                break;
+            }
+            Tracev((stderr, "inflate:       codes ok\n"));
+            state->mode = LEN_;
+            if (flush == Z_TREES) goto inf_leave;
+        case LEN_:
+            state->mode = LEN;
+        case LEN:
+            if (have >= 6 && left >= 258) {
+                RESTORE();
+                inflate_fast(strm, out);
+                LOAD();
+                if (state->mode == TYPE)
+                    state->back = -1;
+                break;
+            }
+            state->back = 0;
+            for (;;) {
+                here = state->lencode[BITS(state->lenbits)];
+                if ((unsigned)(here.bits) <= bits) break;
+                PULLBYTE();
+            }
+            if (here.op && (here.op & 0xf0) == 0) {
+                last = here;
+                for (;;) {
+                    here = state->lencode[last.val +
+                            (BITS(last.bits + last.op) >> last.bits)];
+                    if ((unsigned)(last.bits + here.bits) <= bits) break;
+                    PULLBYTE();
+                }
+                DROPBITS(last.bits);
+                state->back += last.bits;
+            }
+            DROPBITS(here.bits);
+            state->back += here.bits;
+            state->length = (unsigned)here.val;
+            if ((int)(here.op) == 0) {
+                Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
+                        "inflate:         literal '%c'\n" :
+                        "inflate:         literal 0x%02x\n", here.val));
+                state->mode = LIT;
+                break;
+            }
+            if (here.op & 32) {
+                Tracevv((stderr, "inflate:         end of block\n"));
+                state->back = -1;
+                state->mode = TYPE;
+                break;
+            }
+            if (here.op & 64) {
+                strm->msg = (char *)"invalid literal/length code";
+                state->mode = BAD;
+                break;
+            }
+            state->extra = (unsigned)(here.op) & 15;
+            state->mode = LENEXT;
+        case LENEXT:
+            if (state->extra) {
+                NEEDBITS(state->extra);
+                state->length += BITS(state->extra);
+                DROPBITS(state->extra);
+                state->back += state->extra;
+            }
+            Tracevv((stderr, "inflate:         length %u\n", state->length));
+            state->was = state->length;
+            state->mode = DIST;
+        case DIST:
+            for (;;) {
+                here = state->distcode[BITS(state->distbits)];
+                if ((unsigned)(here.bits) <= bits) break;
+                PULLBYTE();
+            }
+            if ((here.op & 0xf0) == 0) {
+                last = here;
+                for (;;) {
+                    here = state->distcode[last.val +
+                            (BITS(last.bits + last.op) >> last.bits)];
+                    if ((unsigned)(last.bits + here.bits) <= bits) break;
+                    PULLBYTE();
+                }
+                DROPBITS(last.bits);
+                state->back += last.bits;
+            }
+            DROPBITS(here.bits);
+            state->back += here.bits;
+            if (here.op & 64) {
+                strm->msg = (char *)"invalid distance code";
+                state->mode = BAD;
+                break;
+            }
+            state->offset = (unsigned)here.val;
+            state->extra = (unsigned)(here.op) & 15;
+            state->mode = DISTEXT;
+        case DISTEXT:
+            if (state->extra) {
+                NEEDBITS(state->extra);
+                state->offset += BITS(state->extra);
+                DROPBITS(state->extra);
+                state->back += state->extra;
+            }
+#ifdef INFLATE_STRICT
+            if (state->offset > state->dmax) {
+                strm->msg = (char *)"invalid distance too far back";
+                state->mode = BAD;
+                break;
+            }
+#endif
+            Tracevv((stderr, "inflate:         distance %u\n", state->offset));
+            state->mode = MATCH;
+        case MATCH:
+            if (left == 0) goto inf_leave;
+            copy = out - left;
+            if (state->offset > copy) {         /* copy from window */
+                copy = state->offset - copy;
+                if (copy > state->whave) {
+                    if (state->sane) {
+                        strm->msg = (char *)"invalid distance too far back";
+                        state->mode = BAD;
+                        break;
+                    }
+#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
+                    Trace((stderr, "inflate.c too far\n"));
+                    copy -= state->whave;
+                    if (copy > state->length) copy = state->length;
+                    if (copy > left) copy = left;
+                    left -= copy;
+                    state->length -= copy;
+                    do {
+                        *put++ = 0;
+                    } while (--copy);
+                    if (state->length == 0) state->mode = LEN;
+                    break;
+#endif
+                }
+                if (copy > state->wnext) {
+                    copy -= state->wnext;
+                    from = state->window + (state->wsize - copy);
+                }
+                else
+                    from = state->window + (state->wnext - copy);
+                if (copy > state->length) copy = state->length;
+            }
+            else {                              /* copy from output */
+                from = put - state->offset;
+                copy = state->length;
+            }
+            if (copy > left) copy = left;
+            left -= copy;
+            state->length -= copy;
+            do {
+                *put++ = *from++;
+            } while (--copy);
+            if (state->length == 0) state->mode = LEN;
+            break;
+        case LIT:
+            if (left == 0) goto inf_leave;
+            *put++ = (unsigned char)(state->length);
+            left--;
+            state->mode = LEN;
+            break;
+        case CHECK:
+            if (state->wrap) {
+                NEEDBITS(32);
+                out -= left;
+                strm->total_out += out;
+                state->total += out;
+                if ((state->wrap & 4) && out)
+                    strm->adler = state->check =
+                        UPDATE(state->check, put - out, out);
+                out = left;
+                if ((state->wrap & 4) && (
+#ifdef GUNZIP
+                     state->flags ? hold :
+#endif
+                     ZSWAP32(hold)) != state->check) {
+                    strm->msg = (char *)"incorrect data check";
+                    state->mode = BAD;
+                    break;
+                }
+                INITBITS();
+                Tracev((stderr, "inflate:   check matches trailer\n"));
+            }
+#ifdef GUNZIP
+            state->mode = LENGTH;
+        case LENGTH:
+            if (state->wrap && state->flags) {
+                NEEDBITS(32);
+                if (hold != (state->total & 0xffffffffUL)) {
+                    strm->msg = (char *)"incorrect length check";
+                    state->mode = BAD;
+                    break;
+                }
+                INITBITS();
+                Tracev((stderr, "inflate:   length matches trailer\n"));
+            }
+#endif
+            state->mode = DONE;
+        case DONE:
+            ret = Z_STREAM_END;
+            goto inf_leave;
+        case BAD:
+            ret = Z_DATA_ERROR;
+            goto inf_leave;
+        case MEM:
+            return Z_MEM_ERROR;
+        case SYNC:
+        default:
+            return Z_STREAM_ERROR;
+        }
+
+    /*
+       Return from inflate(), updating the total counts and the check value.
+       If there was no progress during the inflate() call, return a buffer
+       error.  Call updatewindow() to create and/or update the window state.
+       Note: a memory error from inflate() is non-recoverable.
+     */
+  inf_leave:
+    RESTORE();
+    if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
+            (state->mode < CHECK || flush != Z_FINISH)))
+        if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
+            state->mode = MEM;
+            return Z_MEM_ERROR;
+        }
+    in -= strm->avail_in;
+    out -= strm->avail_out;
+    strm->total_in += in;
+    strm->total_out += out;
+    state->total += out;
+    if ((state->wrap & 4) && out)
+        strm->adler = state->check =
+            UPDATE(state->check, strm->next_out - out, out);
+    strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
+                      (state->mode == TYPE ? 128 : 0) +
+                      (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
+    if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
+        ret = Z_BUF_ERROR;
+    return ret;
+}
+
+int ZEXPORT inflateEnd(strm)
+z_streamp strm;
+{
+    struct inflate_state FAR *state;
+    if (inflateStateCheck(strm))
+        return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    if (state->window != Z_NULL) ZFREE(strm, state->window);
+    ZFREE(strm, strm->state);
+    strm->state = Z_NULL;
+    Tracev((stderr, "inflate: end\n"));
+    return Z_OK;
+}
+
+int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
+z_streamp strm;
+Bytef *dictionary;
+uInt *dictLength;
+{
+    struct inflate_state FAR *state;
+
+    /* check state */
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+
+    /* copy dictionary */
+    if (state->whave && dictionary != Z_NULL) {
+        zmemcpy(dictionary, state->window + state->wnext,
+                state->whave - state->wnext);
+        zmemcpy(dictionary + state->whave - state->wnext,
+                state->window, state->wnext);
+    }
+    if (dictLength != Z_NULL)
+        *dictLength = state->whave;
+    return Z_OK;
+}
+
+int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
+z_streamp strm;
+const Bytef *dictionary;
+uInt dictLength;
+{
+    struct inflate_state FAR *state;
+    unsigned long dictid;
+    int ret;
+
+    /* check state */
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    if (state->wrap != 0 && state->mode != DICT)
+        return Z_STREAM_ERROR;
+
+    /* check for correct dictionary identifier */
+    if (state->mode == DICT) {
+        dictid = adler32(0L, Z_NULL, 0);
+        dictid = adler32(dictid, dictionary, dictLength);
+        if (dictid != state->check)
+            return Z_DATA_ERROR;
+    }
+
+    /* copy dictionary to window using updatewindow(), which will amend the
+       existing dictionary if appropriate */
+    ret = updatewindow(strm, dictionary + dictLength, dictLength);
+    if (ret) {
+        state->mode = MEM;
+        return Z_MEM_ERROR;
+    }
+    state->havedict = 1;
+    Tracev((stderr, "inflate:   dictionary set\n"));
+    return Z_OK;
+}
+
+int ZEXPORT inflateGetHeader(strm, head)
+z_streamp strm;
+gz_headerp head;
+{
+    struct inflate_state FAR *state;
+
+    /* check state */
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
+
+    /* save header structure */
+    state->head = head;
+    head->done = 0;
+    return Z_OK;
+}
+
+/*
+   Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff.  Return when found
+   or when out of input.  When called, *have is the number of pattern bytes
+   found in order so far, in 0..3.  On return *have is updated to the new
+   state.  If on return *have equals four, then the pattern was found and the
+   return value is how many bytes were read including the last byte of the
+   pattern.  If *have is less than four, then the pattern has not been found
+   yet and the return value is len.  In the latter case, syncsearch() can be
+   called again with more data and the *have state.  *have is initialized to
+   zero for the first call.
+ */
+local unsigned syncsearch(have, buf, len)
+unsigned FAR *have;
+const unsigned char FAR *buf;
+unsigned len;
+{
+    unsigned got;
+    unsigned next;
+
+    got = *have;
+    next = 0;
+    while (next < len && got < 4) {
+        if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
+            got++;
+        else if (buf[next])
+            got = 0;
+        else
+            got = 4 - got;
+        next++;
+    }
+    *have = got;
+    return next;
+}
+
+int ZEXPORT inflateSync(strm)
+z_streamp strm;
+{
+    unsigned len;               /* number of bytes to look at or looked at */
+    unsigned long in, out;      /* temporary to save total_in and total_out */
+    unsigned char buf[4];       /* to restore bit buffer to byte string */
+    struct inflate_state FAR *state;
+
+    /* check parameters */
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
+
+    /* if first time, start search in bit buffer */
+    if (state->mode != SYNC) {
+        state->mode = SYNC;
+        state->hold <<= state->bits & 7;
+        state->bits -= state->bits & 7;
+        len = 0;
+        while (state->bits >= 8) {
+            buf[len++] = (unsigned char)(state->hold);
+            state->hold >>= 8;
+            state->bits -= 8;
+        }
+        state->have = 0;
+        syncsearch(&(state->have), buf, len);
+    }
+
+    /* search available input */
+    len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
+    strm->avail_in -= len;
+    strm->next_in += len;
+    strm->total_in += len;
+
+    /* return no joy or set up to restart inflate() on a new block */
+    if (state->have != 4) return Z_DATA_ERROR;
+    in = strm->total_in;  out = strm->total_out;
+    inflateReset(strm);
+    strm->total_in = in;  strm->total_out = out;
+    state->mode = TYPE;
+    return Z_OK;
+}
+
+/*
+   Returns true if inflate is currently at the end of a block generated by
+   Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
+   implementation to provide an additional safety check. PPP uses
+   Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
+   block. When decompressing, PPP checks that at the end of input packet,
+   inflate is waiting for these length bytes.
+ */
+int ZEXPORT inflateSyncPoint(strm)
+z_streamp strm;
+{
+    struct inflate_state FAR *state;
+
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    return state->mode == STORED && state->bits == 0;
+}
+
+int ZEXPORT inflateCopy(dest, source)
+z_streamp dest;
+z_streamp source;
+{
+    struct inflate_state FAR *state;
+    struct inflate_state FAR *copy;
+    unsigned char FAR *window;
+    unsigned wsize;
+
+    /* check input */
+    if (inflateStateCheck(source) || dest == Z_NULL)
+        return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)source->state;
+
+    /* allocate space */
+    copy = (struct inflate_state FAR *)
+           ZALLOC(source, 1, sizeof(struct inflate_state));
+    if (copy == Z_NULL) return Z_MEM_ERROR;
+    window = Z_NULL;
+    if (state->window != Z_NULL) {
+        window = (unsigned char FAR *)
+                 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
+        if (window == Z_NULL) {
+            ZFREE(source, copy);
+            return Z_MEM_ERROR;
+        }
+    }
+
+    /* copy state */
+    zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
+    zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
+    copy->strm = dest;
+    if (state->lencode >= state->codes &&
+        state->lencode <= state->codes + ENOUGH - 1) {
+        copy->lencode = copy->codes + (state->lencode - state->codes);
+        copy->distcode = copy->codes + (state->distcode - state->codes);
+    }
+    copy->next = copy->codes + (state->next - state->codes);
+    if (window != Z_NULL) {
+        wsize = 1U << state->wbits;
+        zmemcpy(window, state->window, wsize);
+    }
+    copy->window = window;
+    dest->state = (struct internal_state FAR *)copy;
+    return Z_OK;
+}
+
+int ZEXPORT inflateUndermine(strm, subvert)
+z_streamp strm;
+int subvert;
+{
+    struct inflate_state FAR *state;
+
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
+    state->sane = !subvert;
+    return Z_OK;
+#else
+    (void)subvert;
+    state->sane = 1;
+    return Z_DATA_ERROR;
+#endif
+}
+
+int ZEXPORT inflateValidate(strm, check)
+z_streamp strm;
+int check;
+{
+    struct inflate_state FAR *state;
+
+    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    if (check)
+        state->wrap |= 4;
+    else
+        state->wrap &= ~4;
+    return Z_OK;
+}
+
+long ZEXPORT inflateMark(strm)
+z_streamp strm;
+{
+    struct inflate_state FAR *state;
+
+    if (inflateStateCheck(strm))
+        return -(1L << 16);
+    state = (struct inflate_state FAR *)strm->state;
+    return (long)(((unsigned long)((long)state->back)) << 16) +
+        (state->mode == COPY ? state->length :
+            (state->mode == MATCH ? state->was - state->length : 0));
+}
+
+unsigned long ZEXPORT inflateCodesUsed(strm)
+z_streamp strm;
+{
+    struct inflate_state FAR *state;
+    if (inflateStateCheck(strm)) return (unsigned long)-1;
+    state = (struct inflate_state FAR *)strm->state;
+    return (unsigned long)(state->next - state->codes);
+}
similarity index 94%
rename from deps/zlib/inflate.h
rename to deps/libchdr/deps/zlib-1.2.11/inflate.h
index dbc173a..a46cce6 100644 (file)
@@ -1,5 +1,5 @@
 /* inflate.h -- internal inflate state definition
- * Copyright (C) 1995-2009 Mark Adler
+ * Copyright (C) 1995-2016 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
    trailer decoding by inflate().  NO_GZIP would be used to avoid linking in
    the crc code when it is not needed.  For shared libraries, gzip decoding
    should be left enabled. */
-#ifndef _INFLATE_H
-#define _INFLATE_H
-
 #ifndef NO_GZIP
 #  define GUNZIP
 #endif
 
 /* Possible inflate modes between inflate() calls */
 typedef enum {
-    HEAD,       /* i: waiting for magic header */
+    HEAD = 16180,   /* i: waiting for magic header */
     FLAGS,      /* i: waiting for method and flags (gzip) */
     TIME,       /* i: waiting for modification time (gzip) */
     OS,         /* i: waiting for extra flags and operating system (gzip) */
@@ -80,11 +77,14 @@ typedef enum {
         CHECK -> LENGTH -> DONE
  */
 
-/* state maintained between inflate() calls.  Approximately 10K bytes. */
+/* State maintained between inflate() calls -- approximately 7K bytes, not
+   including the allocated sliding window, which is up to 32K bytes. */
 struct inflate_state {
+    z_streamp strm;             /* pointer back to this zlib stream */
     inflate_mode mode;          /* current inflate mode */
     int last;                   /* true if processing last block */
-    int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip */
+    int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip,
+                                   bit 2 true to validate check value */
     int havedict;               /* true if dictionary provided */
     int flags;                  /* gzip header method and flags (0 if zlib) */
     unsigned dmax;              /* zlib header max distance (INFLATE_STRICT) */
@@ -123,5 +123,3 @@ struct inflate_state {
     int back;                   /* bits back of last unprocessed length/lit */
     unsigned was;               /* initial length of match */
 };
-
-#endif
diff --git a/deps/libchdr/deps/zlib-1.2.11/inftrees.c b/deps/libchdr/deps/zlib-1.2.11/inftrees.c
new file mode 100644 (file)
index 0000000..2ea08fc
--- /dev/null
@@ -0,0 +1,304 @@
+/* inftrees.c -- generate Huffman trees for efficient decoding
+ * Copyright (C) 1995-2017 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+
+#define MAXBITS 15
+
+const char inflate_copyright[] =
+   " inflate 1.2.11 Copyright 1995-2017 Mark Adler ";
+/*
+  If you use the zlib library in a product, an acknowledgment is welcome
+  in the documentation of your product. If for some reason you cannot
+  include such an acknowledgment, I would appreciate that you keep this
+  copyright string in the executable of your product.
+ */
+
+/*
+   Build a set of tables to decode the provided canonical Huffman code.
+   The code lengths are lens[0..codes-1].  The result starts at *table,
+   whose indices are 0..2^bits-1.  work is a writable array of at least
+   lens shorts, which is used as a work area.  type is the type of code
+   to be generated, CODES, LENS, or DISTS.  On return, zero is success,
+   -1 is an invalid code, and +1 means that ENOUGH isn't enough.  table
+   on return points to the next available entry's address.  bits is the
+   requested root table index bits, and on return it is the actual root
+   table index bits.  It will differ if the request is greater than the
+   longest code or if it is less than the shortest code.
+ */
+int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)
+codetype type;
+unsigned short FAR *lens;
+unsigned codes;
+code FAR * FAR *table;
+unsigned FAR *bits;
+unsigned short FAR *work;
+{
+    unsigned len;               /* a code's length in bits */
+    unsigned sym;               /* index of code symbols */
+    unsigned min, max;          /* minimum and maximum code lengths */
+    unsigned root;              /* number of index bits for root table */
+    unsigned curr;              /* number of index bits for current table */
+    unsigned drop;              /* code bits to drop for sub-table */
+    int left;                   /* number of prefix codes available */
+    unsigned used;              /* code entries in table used */
+    unsigned huff;              /* Huffman code */
+    unsigned incr;              /* for incrementing code, index */
+    unsigned fill;              /* index for replicating entries */
+    unsigned low;               /* low bits for current root entry */
+    unsigned mask;              /* mask for low root bits */
+    code here;                  /* table entry for duplication */
+    code FAR *next;             /* next available space in table */
+    const unsigned short FAR *base;     /* base value table to use */
+    const unsigned short FAR *extra;    /* extra bits table to use */
+    unsigned match;             /* use base and extra for symbol >= match */
+    unsigned short count[MAXBITS+1];    /* number of codes of each length */
+    unsigned short offs[MAXBITS+1];     /* offsets in table for each length */
+    static const unsigned short lbase[31] = { /* Length codes 257..285 base */
+        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
+        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
+    static const unsigned short lext[31] = { /* Length codes 257..285 extra */
+        16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
+        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 202};
+    static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
+        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
+        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
+        8193, 12289, 16385, 24577, 0, 0};
+    static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
+        16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
+        23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
+        28, 28, 29, 29, 64, 64};
+
+    /*
+       Process a set of code lengths to create a canonical Huffman code.  The
+       code lengths are lens[0..codes-1].  Each length corresponds to the
+       symbols 0..codes-1.  The Huffman code is generated by first sorting the
+       symbols by length from short to long, and retaining the symbol order
+       for codes with equal lengths.  Then the code starts with all zero bits
+       for the first code of the shortest length, and the codes are integer
+       increments for the same length, and zeros are appended as the length
+       increases.  For the deflate format, these bits are stored backwards
+       from their more natural integer increment ordering, and so when the
+       decoding tables are built in the large loop below, the integer codes
+       are incremented backwards.
+
+       This routine assumes, but does not check, that all of the entries in
+       lens[] are in the range 0..MAXBITS.  The caller must assure this.
+       1..MAXBITS is interpreted as that code length.  zero means that that
+       symbol does not occur in this code.
+
+       The codes are sorted by computing a count of codes for each length,
+       creating from that a table of starting indices for each length in the
+       sorted table, and then entering the symbols in order in the sorted
+       table.  The sorted table is work[], with that space being provided by
+       the caller.
+
+       The length counts are used for other purposes as well, i.e. finding
+       the minimum and maximum length codes, determining if there are any
+       codes at all, checking for a valid set of lengths, and looking ahead
+       at length counts to determine sub-table sizes when building the
+       decoding tables.
+     */
+
+    /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
+    for (len = 0; len <= MAXBITS; len++)
+        count[len] = 0;
+    for (sym = 0; sym < codes; sym++)
+        count[lens[sym]]++;
+
+    /* bound code lengths, force root to be within code lengths */
+    root = *bits;
+    for (max = MAXBITS; max >= 1; max--)
+        if (count[max] != 0) break;
+    if (root > max) root = max;
+    if (max == 0) {                     /* no symbols to code at all */
+        here.op = (unsigned char)64;    /* invalid code marker */
+        here.bits = (unsigned char)1;
+        here.val = (unsigned short)0;
+        *(*table)++ = here;             /* make a table to force an error */
+        *(*table)++ = here;
+        *bits = 1;
+        return 0;     /* no symbols, but wait for decoding to report error */
+    }
+    for (min = 1; min < max; min++)
+        if (count[min] != 0) break;
+    if (root < min) root = min;
+
+    /* check for an over-subscribed or incomplete set of lengths */
+    left = 1;
+    for (len = 1; len <= MAXBITS; len++) {
+        left <<= 1;
+        left -= count[len];
+        if (left < 0) return -1;        /* over-subscribed */
+    }
+    if (left > 0 && (type == CODES || max != 1))
+        return -1;                      /* incomplete set */
+
+    /* generate offsets into symbol table for each length for sorting */
+    offs[1] = 0;
+    for (len = 1; len < MAXBITS; len++)
+        offs[len + 1] = offs[len] + count[len];
+
+    /* sort symbols by length, by symbol order within each length */
+    for (sym = 0; sym < codes; sym++)
+        if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
+
+    /*
+       Create and fill in decoding tables.  In this loop, the table being
+       filled is at next and has curr index bits.  The code being used is huff
+       with length len.  That code is converted to an index by dropping drop
+       bits off of the bottom.  For codes where len is less than drop + curr,
+       those top drop + curr - len bits are incremented through all values to
+       fill the table with replicated entries.
+
+       root is the number of index bits for the root table.  When len exceeds
+       root, sub-tables are created pointed to by the root entry with an index
+       of the low root bits of huff.  This is saved in low to check for when a
+       new sub-table should be started.  drop is zero when the root table is
+       being filled, and drop is root when sub-tables are being filled.
+
+       When a new sub-table is needed, it is necessary to look ahead in the
+       code lengths to determine what size sub-table is needed.  The length
+       counts are used for this, and so count[] is decremented as codes are
+       entered in the tables.
+
+       used keeps track of how many table entries have been allocated from the
+       provided *table space.  It is checked for LENS and DIST tables against
+       the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
+       the initial root table size constants.  See the comments in inftrees.h
+       for more information.
+
+       sym increments through all symbols, and the loop terminates when
+       all codes of length max, i.e. all codes, have been processed.  This
+       routine permits incomplete codes, so another loop after this one fills
+       in the rest of the decoding tables with invalid code markers.
+     */
+
+    /* set up for code type */
+    switch (type) {
+    case CODES:
+        base = extra = work;    /* dummy value--not used */
+        match = 20;
+        break;
+    case LENS:
+        base = lbase;
+        extra = lext;
+        match = 257;
+        break;
+    default:    /* DISTS */
+        base = dbase;
+        extra = dext;
+        match = 0;
+    }
+
+    /* initialize state for loop */
+    huff = 0;                   /* starting code */
+    sym = 0;                    /* starting code symbol */
+    len = min;                  /* starting code length */
+    next = *table;              /* current table to fill in */
+    curr = root;                /* current table index bits */
+    drop = 0;                   /* current bits to drop from code for index */
+    low = (unsigned)(-1);       /* trigger new sub-table when len > root */
+    used = 1U << root;          /* use root table entries */
+    mask = used - 1;            /* mask for comparing low */
+
+    /* check available table space */
+    if ((type == LENS && used > ENOUGH_LENS) ||
+        (type == DISTS && used > ENOUGH_DISTS))
+        return 1;
+
+    /* process all codes and make table entries */
+    for (;;) {
+        /* create table entry */
+        here.bits = (unsigned char)(len - drop);
+        if (work[sym] + 1U < match) {
+            here.op = (unsigned char)0;
+            here.val = work[sym];
+        }
+        else if (work[sym] >= match) {
+            here.op = (unsigned char)(extra[work[sym] - match]);
+            here.val = base[work[sym] - match];
+        }
+        else {
+            here.op = (unsigned char)(32 + 64);         /* end of block */
+            here.val = 0;
+        }
+
+        /* replicate for those indices with low len bits equal to huff */
+        incr = 1U << (len - drop);
+        fill = 1U << curr;
+        min = fill;                 /* save offset to next table */
+        do {
+            fill -= incr;
+            next[(huff >> drop) + fill] = here;
+        } while (fill != 0);
+
+        /* backwards increment the len-bit code huff */
+        incr = 1U << (len - 1);
+        while (huff & incr)
+            incr >>= 1;
+        if (incr != 0) {
+            huff &= incr - 1;
+            huff += incr;
+        }
+        else
+            huff = 0;
+
+        /* go to next symbol, update count, len */
+        sym++;
+        if (--(count[len]) == 0) {
+            if (len == max) break;
+            len = lens[work[sym]];
+        }
+
+        /* create new sub-table if needed */
+        if (len > root && (huff & mask) != low) {
+            /* if first time, transition to sub-tables */
+            if (drop == 0)
+                drop = root;
+
+            /* increment past last table */
+            next += min;            /* here min is 1 << curr */
+
+            /* determine length of next table */
+            curr = len - drop;
+            left = (int)(1 << curr);
+            while (curr + drop < max) {
+                left -= count[curr + drop];
+                if (left <= 0) break;
+                curr++;
+                left <<= 1;
+            }
+
+            /* check for enough space */
+            used += 1U << curr;
+            if ((type == LENS && used > ENOUGH_LENS) ||
+                (type == DISTS && used > ENOUGH_DISTS))
+                return 1;
+
+            /* point entry in root table to sub-table */
+            low = huff & mask;
+            (*table)[low].op = (unsigned char)curr;
+            (*table)[low].bits = (unsigned char)root;
+            (*table)[low].val = (unsigned short)(next - *table);
+        }
+    }
+
+    /* fill in remaining table entry if code is incomplete (guaranteed to have
+       at most one remaining entry, since if the code is incomplete, the
+       maximum code length that was allowed to get this far is one bit) */
+    if (huff != 0) {
+        here.op = (unsigned char)64;            /* invalid code marker */
+        here.bits = (unsigned char)(len - drop);
+        here.val = (unsigned short)0;
+        next[huff] = here;
+    }
+
+    /* set return parameters */
+    *table += used;
+    *bits = root;
+    return 0;
+}
similarity index 98%
rename from deps/zlib/inftrees.h
rename to deps/libchdr/deps/zlib-1.2.11/inftrees.h
index cd9e67c..baa53a0 100644 (file)
@@ -8,9 +8,6 @@
    subject to change. Applications should only use zlib.h.
  */
 
-#ifndef _INFTREES_H
-#define _INFTREES_H
-
 /* Structure for decoding tables.  Each entry provides either the
    information needed to do the operation requested by the code that
    indexed that table entry, or it provides a pointer to another
@@ -63,5 +60,3 @@ typedef enum {
 int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
                              unsigned codes, code FAR * FAR *table,
                              unsigned FAR *bits, unsigned short FAR *work));
-
-#endif
diff --git a/deps/libchdr/deps/zlib-1.2.11/make_vms.com b/deps/libchdr/deps/zlib-1.2.11/make_vms.com
new file mode 100644 (file)
index 0000000..65e9d0c
--- /dev/null
@@ -0,0 +1,867 @@
+$! make libz under VMS written by
+$! Martin P.J. Zinser
+$!
+$! In case of problems with the install you might contact me at
+$! zinser@zinser.no-ip.info(preferred) or
+$! martin.zinser@eurexchange.com (work)
+$!
+$! Make procedure history for Zlib
+$!
+$!------------------------------------------------------------------------------
+$! Version history
+$! 0.01 20060120 First version to receive a number
+$! 0.02 20061008 Adapt to new Makefile.in
+$! 0.03 20091224 Add support for large file check
+$! 0.04 20100110 Add new gzclose, gzlib, gzread, gzwrite
+$! 0.05 20100221 Exchange zlibdefs.h by zconf.h.in
+$! 0.06 20120111 Fix missing amiss_err, update zconf_h.in, fix new exmples
+$!               subdir path, update module search in makefile.in
+$! 0.07 20120115 Triggered by work done by Alexey Chupahin completly redesigned
+$!               shared image creation
+$! 0.08 20120219 Make it work on VAX again, pre-load missing symbols to shared
+$!               image
+$! 0.09 20120305 SMS.  P1 sets builder ("MMK", "MMS", " " (built-in)).
+$!               "" -> automatic, preference: MMK, MMS, built-in.
+$!
+$ on error then goto err_exit
+$!
+$ true  = 1
+$ false = 0
+$ tmpnam = "temp_" + f$getjpi("","pid")
+$ tt = tmpnam + ".txt"
+$ tc = tmpnam + ".c"
+$ th = tmpnam + ".h"
+$ define/nolog tconfig 'th'
+$ its_decc = false
+$ its_vaxc = false
+$ its_gnuc = false
+$ s_case   = False
+$!
+$! Setup variables holding "config" information
+$!
+$ Make    = "''p1'"
+$ name     = "Zlib"
+$ version  = "?.?.?"
+$ v_string = "ZLIB_VERSION"
+$ v_file   = "zlib.h"
+$ ccopt   = "/include = []"
+$ lopts   = ""
+$ dnsrl   = ""
+$ aconf_in_file = "zconf.h.in#zconf.h_in#zconf_h.in"
+$ conf_check_string = ""
+$ linkonly = false
+$ optfile  = name + ".opt"
+$ mapfile  = name + ".map"
+$ libdefs  = ""
+$ vax      = f$getsyi("HW_MODEL").lt.1024
+$ axp      = f$getsyi("HW_MODEL").ge.1024 .and. f$getsyi("HW_MODEL").lt.4096
+$ ia64     = f$getsyi("HW_MODEL").ge.4096
+$!
+$! 2012-03-05 SMS.
+$! Why is this needed?  And if it is needed, why not simply ".not. vax"?
+$!
+$!!! if axp .or. ia64 then  set proc/parse=extended
+$!
+$ whoami = f$parse(f$environment("Procedure"),,,,"NO_CONCEAL")
+$ mydef  = F$parse(whoami,,,"DEVICE")
+$ mydir  = f$parse(whoami,,,"DIRECTORY") - "]["
+$ myproc = f$parse(whoami,,,"Name") + f$parse(whoami,,,"type")
+$!
+$! Check for MMK/MMS
+$!
+$ if (Make .eqs. "")
+$ then
+$   If F$Search ("Sys$System:MMS.EXE") .nes. "" Then Make = "MMS"
+$   If F$Type (MMK) .eqs. "STRING" Then Make = "MMK"
+$ else
+$   Make = f$edit( Make, "trim")
+$ endif
+$!
+$ gosub find_version
+$!
+$  open/write topt tmp.opt
+$  open/write optf 'optfile'
+$!
+$ gosub check_opts
+$!
+$! Look for the compiler used
+$!
+$ gosub check_compiler
+$ close topt
+$ close optf
+$!
+$ if its_decc
+$ then
+$   ccopt = "/prefix=all" + ccopt
+$   if f$trnlnm("SYS") .eqs. ""
+$   then
+$     if axp
+$     then
+$       define sys sys$library:
+$     else
+$       ccopt = "/decc" + ccopt
+$       define sys decc$library_include:
+$     endif
+$   endif
+$!
+$! 2012-03-05 SMS.
+$! Why /NAMES = AS_IS?  Why not simply ".not. vax"?  And why not on VAX?
+$!
+$   if axp .or. ia64
+$   then
+$       ccopt = ccopt + "/name=as_is/opt=(inline=speed)"
+$       s_case = true
+$   endif
+$ endif
+$ if its_vaxc .or. its_gnuc
+$ then
+$    if f$trnlnm("SYS").eqs."" then define sys sys$library:
+$ endif
+$!
+$! Build a fake configure input header
+$!
+$ open/write conf_hin config.hin
+$ write conf_hin "#undef _LARGEFILE64_SOURCE"
+$ close conf_hin
+$!
+$!
+$ i = 0
+$FIND_ACONF:
+$ fname = f$element(i,"#",aconf_in_file)
+$ if fname .eqs. "#" then goto AMISS_ERR
+$ if f$search(fname) .eqs. ""
+$ then
+$   i = i + 1
+$   goto find_aconf
+$ endif
+$ open/read/err=aconf_err aconf_in 'fname'
+$ open/write aconf zconf.h
+$ACONF_LOOP:
+$ read/end_of_file=aconf_exit aconf_in line
+$ work = f$edit(line, "compress,trim")
+$ if f$extract(0,6,work) .nes. "#undef"
+$ then
+$   if f$extract(0,12,work) .nes. "#cmakedefine"
+$   then
+$       write aconf line
+$   endif
+$ else
+$   cdef = f$element(1," ",work)
+$   gosub check_config
+$ endif
+$ goto aconf_loop
+$ACONF_EXIT:
+$ write aconf ""
+$ write aconf "/* VMS specifics added by make_vms.com: */"
+$ write aconf "#define VMS 1"
+$ write aconf "#include <unistd.h>"
+$ write aconf "#include <unixio.h>"
+$ write aconf "#ifdef _LARGEFILE"
+$ write aconf "# define off64_t __off64_t"
+$ write aconf "# define fopen64 fopen"
+$ write aconf "# define fseeko64 fseeko"
+$ write aconf "# define lseek64 lseek"
+$ write aconf "# define ftello64 ftell"
+$ write aconf "#endif"
+$ write aconf "#if !defined( __VAX) && (__CRTL_VER >= 70312000)"
+$ write aconf "# define HAVE_VSNPRINTF"
+$ write aconf "#endif"
+$ close aconf_in
+$ close aconf
+$ if f$search("''th'") .nes. "" then delete 'th';*
+$! Build the thing plain or with mms
+$!
+$ write sys$output "Compiling Zlib sources ..."
+$ if make.eqs.""
+$ then
+$   if (f$search( "example.obj;*") .nes. "") then delete example.obj;*
+$   if (f$search( "minigzip.obj;*") .nes. "") then delete minigzip.obj;*
+$   CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" -
+                adler32.c zlib.h zconf.h
+$   CALL MAKE compress.OBJ "CC ''CCOPT' compress" -
+                compress.c zlib.h zconf.h
+$   CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" -
+                crc32.c zlib.h zconf.h
+$   CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" -
+                deflate.c deflate.h zutil.h zlib.h zconf.h
+$   CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" -
+                gzclose.c zutil.h zlib.h zconf.h
+$   CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" -
+                gzlib.c zutil.h zlib.h zconf.h
+$   CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" -
+                gzread.c zutil.h zlib.h zconf.h
+$   CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" -
+                gzwrite.c zutil.h zlib.h zconf.h
+$   CALL MAKE infback.OBJ "CC ''CCOPT' infback" -
+                infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h
+$   CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" -
+                inffast.c zutil.h zlib.h zconf.h inffast.h
+$   CALL MAKE inflate.OBJ "CC ''CCOPT' inflate" -
+                inflate.c zutil.h zlib.h zconf.h infblock.h
+$   CALL MAKE inftrees.OBJ "CC ''CCOPT' inftrees" -
+                inftrees.c zutil.h zlib.h zconf.h inftrees.h
+$   CALL MAKE trees.OBJ "CC ''CCOPT' trees" -
+                trees.c deflate.h zutil.h zlib.h zconf.h
+$   CALL MAKE uncompr.OBJ "CC ''CCOPT' uncompr" -
+                uncompr.c zlib.h zconf.h
+$   CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" -
+                zutil.c zutil.h zlib.h zconf.h
+$   write sys$output "Building Zlib ..."
+$   CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ
+$   write sys$output "Building example..."
+$   CALL MAKE example.OBJ "CC ''CCOPT' [.test]example" -
+                [.test]example.c zlib.h zconf.h
+$   call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb
+$   write sys$output "Building minigzip..."
+$   CALL MAKE minigzip.OBJ "CC ''CCOPT' [.test]minigzip" -
+              [.test]minigzip.c zlib.h zconf.h
+$   call make minigzip.exe -
+              "LINK minigzip,libz.olb/lib" -
+              minigzip.obj libz.olb
+$ else
+$   gosub crea_mms
+$   write sys$output "Make ''name' ''version' with ''Make' "
+$   'make'
+$ endif
+$!
+$! Create shareable image
+$!
+$ gosub crea_olist
+$ write sys$output "Creating libzshr.exe"
+$ call map_2_shopt 'mapfile' 'optfile'
+$ LINK_'lopts'/SHARE=libzshr.exe modules.opt/opt,'optfile'/opt
+$ write sys$output "Zlib build completed"
+$ delete/nolog tmp.opt;*
+$ exit
+$AMISS_ERR:
+$ write sys$output "No source for config.hin found."
+$ write sys$output "Tried any of ''aconf_in_file'"
+$ goto err_exit
+$CC_ERR:
+$ write sys$output "C compiler required to build ''name'"
+$ goto err_exit
+$ERR_EXIT:
+$ set message/facil/ident/sever/text
+$ close/nolog optf
+$ close/nolog topt
+$ close/nolog aconf_in
+$ close/nolog aconf
+$ close/nolog out
+$ close/nolog min
+$ close/nolog mod
+$ close/nolog h_in
+$ write sys$output "Exiting..."
+$ exit 2
+$!
+$!
+$MAKE: SUBROUTINE   !SUBROUTINE TO CHECK DEPENDENCIES
+$ V = 'F$Verify(0)
+$! P1 = What we are trying to make
+$! P2 = Command to make it
+$! P3 - P8  What it depends on
+$
+$ If F$Search(P1) .Eqs. "" Then Goto Makeit
+$ Time = F$CvTime(F$File(P1,"RDT"))
+$arg=3
+$Loop:
+$       Argument = P'arg
+$       If Argument .Eqs. "" Then Goto Exit
+$       El=0
+$Loop2:
+$       File = F$Element(El," ",Argument)
+$       If File .Eqs. " " Then Goto Endl
+$       AFile = ""
+$Loop3:
+$       OFile = AFile
+$       AFile = F$Search(File)
+$       If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
+$       If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
+$       Goto Loop3
+$NextEL:
+$       El = El + 1
+$       Goto Loop2
+$EndL:
+$ arg=arg+1
+$ If arg .Le. 8 Then Goto Loop
+$ Goto Exit
+$
+$Makeit:
+$ VV=F$VERIFY(0)
+$ write sys$output P2
+$ 'P2
+$ VV='F$Verify(VV)
+$Exit:
+$ If V Then Set Verify
+$ENDSUBROUTINE
+$!------------------------------------------------------------------------------
+$!
+$! Check command line options and set symbols accordingly
+$!
+$!------------------------------------------------------------------------------
+$! Version history
+$! 0.01 20041206 First version to receive a number
+$! 0.02 20060126 Add new "HELP" target
+$ CHECK_OPTS:
+$ i = 1
+$ OPT_LOOP:
+$ if i .lt. 9
+$ then
+$   cparm = f$edit(p'i',"upcase")
+$!
+$! Check if parameter actually contains something
+$!
+$   if f$edit(cparm,"trim") .nes. ""
+$   then
+$     if cparm .eqs. "DEBUG"
+$     then
+$       ccopt = ccopt + "/noopt/deb"
+$       lopts = lopts + "/deb"
+$     endif
+$     if f$locate("CCOPT=",cparm) .lt. f$length(cparm)
+$     then
+$       start = f$locate("=",cparm) + 1
+$       len   = f$length(cparm) - start
+$       ccopt = ccopt + f$extract(start,len,cparm)
+$       if f$locate("AS_IS",f$edit(ccopt,"UPCASE")) .lt. f$length(ccopt) -
+          then s_case = true
+$     endif
+$     if cparm .eqs. "LINK" then linkonly = true
+$     if f$locate("LOPTS=",cparm) .lt. f$length(cparm)
+$     then
+$       start = f$locate("=",cparm) + 1
+$       len   = f$length(cparm) - start
+$       lopts = lopts + f$extract(start,len,cparm)
+$     endif
+$     if f$locate("CC=",cparm) .lt. f$length(cparm)
+$     then
+$       start  = f$locate("=",cparm) + 1
+$       len    = f$length(cparm) - start
+$       cc_com = f$extract(start,len,cparm)
+        if (cc_com .nes. "DECC") .and. -
+           (cc_com .nes. "VAXC") .and. -
+           (cc_com .nes. "GNUC")
+$       then
+$         write sys$output "Unsupported compiler choice ''cc_com' ignored"
+$         write sys$output "Use DECC, VAXC, or GNUC instead"
+$       else
+$         if cc_com .eqs. "DECC" then its_decc = true
+$         if cc_com .eqs. "VAXC" then its_vaxc = true
+$         if cc_com .eqs. "GNUC" then its_gnuc = true
+$       endif
+$     endif
+$     if f$locate("MAKE=",cparm) .lt. f$length(cparm)
+$     then
+$       start  = f$locate("=",cparm) + 1
+$       len    = f$length(cparm) - start
+$       mmks = f$extract(start,len,cparm)
+$       if (mmks .eqs. "MMK") .or. (mmks .eqs. "MMS")
+$       then
+$         make = mmks
+$       else
+$         write sys$output "Unsupported make choice ''mmks' ignored"
+$         write sys$output "Use MMK or MMS instead"
+$       endif
+$     endif
+$     if cparm .eqs. "HELP" then gosub bhelp
+$   endif
+$   i = i + 1
+$   goto opt_loop
+$ endif
+$ return
+$!------------------------------------------------------------------------------
+$!
+$! Look for the compiler used
+$!
+$! Version history
+$! 0.01 20040223 First version to receive a number
+$! 0.02 20040229 Save/set value of decc$no_rooted_search_lists
+$! 0.03 20060202 Extend handling of GNU C
+$! 0.04 20090402 Compaq -> hp
+$CHECK_COMPILER:
+$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc))
+$ then
+$   its_decc = (f$search("SYS$SYSTEM:DECC$COMPILER.EXE") .nes. "")
+$   its_vaxc = .not. its_decc .and. (F$Search("SYS$System:VAXC.Exe") .nes. "")
+$   its_gnuc = .not. (its_decc .or. its_vaxc) .and. (f$trnlnm("gnu_cc") .nes. "")
+$ endif
+$!
+$! Exit if no compiler available
+$!
+$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc))
+$ then goto CC_ERR
+$ else
+$   if its_decc
+$   then
+$     write sys$output "CC compiler check ... hp C"
+$     if f$trnlnm("decc$no_rooted_search_lists") .nes. ""
+$     then
+$       dnrsl = f$trnlnm("decc$no_rooted_search_lists")
+$     endif
+$     define/nolog decc$no_rooted_search_lists 1
+$   else
+$     if its_vaxc then write sys$output "CC compiler check ... VAX C"
+$     if its_gnuc
+$     then
+$         write sys$output "CC compiler check ... GNU C"
+$         if f$trnlnm(topt) then write topt "gnu_cc:[000000]gcclib.olb/lib"
+$         if f$trnlnm(optf) then write optf "gnu_cc:[000000]gcclib.olb/lib"
+$         cc = "gcc"
+$     endif
+$     if f$trnlnm(topt) then write topt "sys$share:vaxcrtl.exe/share"
+$     if f$trnlnm(optf) then write optf "sys$share:vaxcrtl.exe/share"
+$   endif
+$ endif
+$ return
+$!------------------------------------------------------------------------------
+$!
+$! If MMS/MMK are available dump out the descrip.mms if required
+$!
+$CREA_MMS:
+$ write sys$output "Creating descrip.mms..."
+$ create descrip.mms
+$ open/append out descrip.mms
+$ copy sys$input: out
+$ deck
+# descrip.mms: MMS description file for building zlib on VMS
+# written by Martin P.J. Zinser
+# <zinser@zinser.no-ip.info or martin.zinser@eurexchange.com>
+
+OBJS = adler32.obj, compress.obj, crc32.obj, gzclose.obj, gzlib.obj\
+       gzread.obj, gzwrite.obj, uncompr.obj, infback.obj\
+       deflate.obj, trees.obj, zutil.obj, inflate.obj, \
+       inftrees.obj, inffast.obj
+
+$ eod
+$ write out "CFLAGS=", ccopt
+$ write out "LOPTS=", lopts
+$ write out "all : example.exe minigzip.exe libz.olb"
+$ copy sys$input: out
+$ deck
+        @ write sys$output " Example applications available"
+
+libz.olb : libz.olb($(OBJS))
+       @ write sys$output " libz available"
+
+example.exe : example.obj libz.olb
+              link $(LOPTS) example,libz.olb/lib
+
+minigzip.exe : minigzip.obj libz.olb
+              link $(LOPTS) minigzip,libz.olb/lib
+
+clean :
+       delete *.obj;*,libz.olb;*,*.opt;*,*.exe;*
+
+
+# Other dependencies.
+adler32.obj  : adler32.c zutil.h zlib.h zconf.h
+compress.obj : compress.c zlib.h zconf.h
+crc32.obj    : crc32.c zutil.h zlib.h zconf.h
+deflate.obj  : deflate.c deflate.h zutil.h zlib.h zconf.h
+example.obj  : [.test]example.c zlib.h zconf.h
+gzclose.obj  : gzclose.c zutil.h zlib.h zconf.h
+gzlib.obj    : gzlib.c zutil.h zlib.h zconf.h
+gzread.obj   : gzread.c zutil.h zlib.h zconf.h
+gzwrite.obj  : gzwrite.c zutil.h zlib.h zconf.h
+inffast.obj  : inffast.c zutil.h zlib.h zconf.h inftrees.h inffast.h
+inflate.obj  : inflate.c zutil.h zlib.h zconf.h
+inftrees.obj : inftrees.c zutil.h zlib.h zconf.h inftrees.h
+minigzip.obj : [.test]minigzip.c zlib.h zconf.h
+trees.obj    : trees.c deflate.h zutil.h zlib.h zconf.h
+uncompr.obj  : uncompr.c zlib.h zconf.h
+zutil.obj    : zutil.c zutil.h zlib.h zconf.h
+infback.obj  : infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h
+$ eod
+$ close out
+$ return
+$!------------------------------------------------------------------------------
+$!
+$! Read list of core library sources from makefile.in and create options
+$! needed to build shareable image
+$!
+$CREA_OLIST:
+$ open/read min makefile.in
+$ open/write mod modules.opt
+$ src_check_list = "OBJZ =#OBJG ="
+$MRLOOP:
+$ read/end=mrdone min rec
+$ i = 0
+$SRC_CHECK_LOOP:
+$ src_check = f$element(i, "#", src_check_list)
+$ i = i+1
+$ if src_check .eqs. "#" then goto mrloop
+$ if (f$extract(0,6,rec) .nes. src_check) then goto src_check_loop
+$ rec = rec - src_check
+$ gosub extra_filnam
+$ if (f$element(1,"\",rec) .eqs. "\") then goto mrloop
+$MRSLOOP:
+$ read/end=mrdone min rec
+$ gosub extra_filnam
+$ if (f$element(1,"\",rec) .nes. "\") then goto mrsloop
+$MRDONE:
+$ close min
+$ close mod
+$ return
+$!------------------------------------------------------------------------------
+$!
+$! Take record extracted in crea_olist and split it into single filenames
+$!
+$EXTRA_FILNAM:
+$ myrec = f$edit(rec - "\", "trim,compress")
+$ i = 0
+$FELOOP:
+$ srcfil = f$element(i," ", myrec)
+$ if (srcfil .nes. " ")
+$ then
+$   write mod f$parse(srcfil,,,"NAME"), ".obj"
+$   i = i + 1
+$   goto feloop
+$ endif
+$ return
+$!------------------------------------------------------------------------------
+$!
+$! Find current Zlib version number
+$!
+$FIND_VERSION:
+$ open/read h_in 'v_file'
+$hloop:
+$ read/end=hdone h_in rec
+$ rec = f$edit(rec,"TRIM")
+$ if (f$extract(0,1,rec) .nes. "#") then goto hloop
+$ rec = f$edit(rec - "#", "TRIM")
+$ if f$element(0," ",rec) .nes. "define" then goto hloop
+$ if f$element(1," ",rec) .eqs. v_string
+$ then
+$   version = 'f$element(2," ",rec)'
+$   goto hdone
+$ endif
+$ goto hloop
+$hdone:
+$ close h_in
+$ return
+$!------------------------------------------------------------------------------
+$!
+$CHECK_CONFIG:
+$!
+$ in_ldef = f$locate(cdef,libdefs)
+$ if (in_ldef .lt. f$length(libdefs))
+$ then
+$   write aconf "#define ''cdef' 1"
+$   libdefs = f$extract(0,in_ldef,libdefs) + -
+              f$extract(in_ldef + f$length(cdef) + 1, -
+                        f$length(libdefs) - in_ldef - f$length(cdef) - 1, -
+                        libdefs)
+$ else
+$   if (f$type('cdef') .eqs. "INTEGER")
+$   then
+$     write aconf "#define ''cdef' ", 'cdef'
+$   else
+$     if (f$type('cdef') .eqs. "STRING")
+$     then
+$       write aconf "#define ''cdef' ", """", '''cdef'', """"
+$     else
+$       gosub check_cc_def
+$     endif
+$   endif
+$ endif
+$ return
+$!------------------------------------------------------------------------------
+$!
+$! Check if this is a define relating to the properties of the C/C++
+$! compiler
+$!
+$ CHECK_CC_DEF:
+$ if (cdef .eqs. "_LARGEFILE64_SOURCE")
+$ then
+$   copy sys$input: 'tc'
+$   deck
+#include "tconfig"
+#define _LARGEFILE
+#include <stdio.h>
+
+int main(){
+FILE *fp;
+  fp = fopen("temp.txt","r");
+  fseeko(fp,1,SEEK_SET);
+  fclose(fp);
+}
+
+$   eod
+$   test_inv = false
+$   comm_h = false
+$   gosub cc_prop_check
+$   return
+$ endif
+$ write aconf "/* ", line, " */"
+$ return
+$!------------------------------------------------------------------------------
+$!
+$! Check for properties of C/C++ compiler
+$!
+$! Version history
+$! 0.01 20031020 First version to receive a number
+$! 0.02 20031022 Added logic for defines with value
+$! 0.03 20040309 Make sure local config file gets not deleted
+$! 0.04 20041230 Also write include for configure run
+$! 0.05 20050103 Add processing of "comment defines"
+$CC_PROP_CHECK:
+$ cc_prop = true
+$ is_need = false
+$ is_need = (f$extract(0,4,cdef) .eqs. "NEED") .or. (test_inv .eq. true)
+$ if f$search(th) .eqs. "" then create 'th'
+$ set message/nofac/noident/nosever/notext
+$ on error then continue
+$ cc 'tmpnam'
+$ if .not. ($status)  then cc_prop = false
+$ on error then continue
+$! The headers might lie about the capabilities of the RTL
+$ link 'tmpnam',tmp.opt/opt
+$ if .not. ($status)  then cc_prop = false
+$ set message/fac/ident/sever/text
+$ on error then goto err_exit
+$ delete/nolog 'tmpnam'.*;*/exclude='th'
+$ if (cc_prop .and. .not. is_need) .or. -
+     (.not. cc_prop .and. is_need)
+$ then
+$   write sys$output "Checking for ''cdef'... yes"
+$   if f$type('cdef_val'_yes) .nes. ""
+$   then
+$     if f$type('cdef_val'_yes) .eqs. "INTEGER" -
+         then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_yes)
+$     if f$type('cdef_val'_yes) .eqs. "STRING" -
+         then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_yes)
+$   else
+$     call write_config f$fao("#define !AS 1",cdef)
+$   endif
+$   if (cdef .eqs. "HAVE_FSEEKO") .or. (cdef .eqs. "_LARGE_FILES") .or. -
+       (cdef .eqs. "_LARGEFILE64_SOURCE") then -
+      call write_config f$string("#define _LARGEFILE 1")
+$ else
+$   write sys$output "Checking for ''cdef'... no"
+$   if (comm_h)
+$   then
+      call write_config f$fao("/* !AS */",line)
+$   else
+$     if f$type('cdef_val'_no) .nes. ""
+$     then
+$       if f$type('cdef_val'_no) .eqs. "INTEGER" -
+           then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_no)
+$       if f$type('cdef_val'_no) .eqs. "STRING" -
+           then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_no)
+$     else
+$       call write_config f$fao("#undef !AS",cdef)
+$     endif
+$   endif
+$ endif
+$ return
+$!------------------------------------------------------------------------------
+$!
+$! Check for properties of C/C++ compiler with multiple result values
+$!
+$! Version history
+$! 0.01 20040127 First version
+$! 0.02 20050103 Reconcile changes from cc_prop up to version 0.05
+$CC_MPROP_CHECK:
+$ cc_prop = true
+$ i    = 1
+$ idel = 1
+$ MT_LOOP:
+$ if f$type(result_'i') .eqs. "STRING"
+$ then
+$   set message/nofac/noident/nosever/notext
+$   on error then continue
+$   cc 'tmpnam'_'i'
+$   if .not. ($status)  then cc_prop = false
+$   on error then continue
+$! The headers might lie about the capabilities of the RTL
+$   link 'tmpnam'_'i',tmp.opt/opt
+$   if .not. ($status)  then cc_prop = false
+$   set message/fac/ident/sever/text
+$   on error then goto err_exit
+$   delete/nolog 'tmpnam'_'i'.*;*
+$   if (cc_prop)
+$   then
+$     write sys$output "Checking for ''cdef'... ", mdef_'i'
+$     if f$type(mdef_'i') .eqs. "INTEGER" -
+         then call write_config f$fao("#define !AS !UL",cdef,mdef_'i')
+$     if f$type('cdef_val'_yes) .eqs. "STRING" -
+         then call write_config f$fao("#define !AS !AS",cdef,mdef_'i')
+$     goto msym_clean
+$   else
+$     i = i + 1
+$     goto mt_loop
+$   endif
+$ endif
+$ write sys$output "Checking for ''cdef'... no"
+$ call write_config f$fao("#undef !AS",cdef)
+$ MSYM_CLEAN:
+$ if (idel .le. msym_max)
+$ then
+$   delete/sym mdef_'idel'
+$   idel = idel + 1
+$   goto msym_clean
+$ endif
+$ return
+$!------------------------------------------------------------------------------
+$!
+$! Write configuration to both permanent and temporary config file
+$!
+$! Version history
+$! 0.01 20031029 First version to receive a number
+$!
+$WRITE_CONFIG: SUBROUTINE
+$  write aconf 'p1'
+$  open/append confh 'th'
+$  write confh 'p1'
+$  close confh
+$ENDSUBROUTINE
+$!------------------------------------------------------------------------------
+$!
+$! Analyze the project map file and create the symbol vector for a shareable
+$! image from it
+$!
+$! Version history
+$! 0.01 20120128 First version
+$! 0.02 20120226 Add pre-load logic
+$!
+$ MAP_2_SHOPT: Subroutine
+$!
+$ SAY := "WRITE_ SYS$OUTPUT"
+$!
+$ IF F$SEARCH("''P1'") .EQS. ""
+$ THEN
+$    SAY "MAP_2_SHOPT-E-NOSUCHFILE:  Error, inputfile ''p1' not available"
+$    goto exit_m2s
+$ ENDIF
+$ IF "''P2'" .EQS. ""
+$ THEN
+$    SAY "MAP_2_SHOPT:  Error, no output file provided"
+$    goto exit_m2s
+$ ENDIF
+$!
+$ module1 = "deflate#deflateEnd#deflateInit_#deflateParams#deflateSetDictionary"
+$ module2 = "gzclose#gzerror#gzgetc#gzgets#gzopen#gzprintf#gzputc#gzputs#gzread"
+$ module3 = "gzseek#gztell#inflate#inflateEnd#inflateInit_#inflateSetDictionary"
+$ module4 = "inflateSync#uncompress#zlibVersion#compress"
+$ open/read map 'p1
+$ if axp .or. ia64
+$ then
+$     open/write aopt a.opt
+$     open/write bopt b.opt
+$     write aopt " CASE_SENSITIVE=YES"
+$     write bopt "SYMBOL_VECTOR= (-"
+$     mod_sym_num = 1
+$ MOD_SYM_LOOP:
+$     if f$type(module'mod_sym_num') .nes. ""
+$     then
+$         mod_in = 0
+$ MOD_SYM_IN:
+$         shared_proc = f$element(mod_in, "#", module'mod_sym_num')
+$         if shared_proc .nes. "#"
+$         then
+$             write aopt f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)",-
+                              f$edit(shared_proc,"upcase"),shared_proc)
+$             write bopt f$fao("!AS=PROCEDURE,-",shared_proc)
+$             mod_in = mod_in + 1
+$             goto mod_sym_in
+$         endif
+$         mod_sym_num = mod_sym_num + 1
+$         goto mod_sym_loop
+$     endif
+$MAP_LOOP:
+$     read/end=map_end map line
+$     if (f$locate("{",line).lt. f$length(line)) .or. -
+         (f$locate("global:", line) .lt. f$length(line))
+$     then
+$         proc = true
+$         goto map_loop
+$     endif
+$     if f$locate("}",line).lt. f$length(line) then proc = false
+$     if f$locate("local:", line) .lt. f$length(line) then proc = false
+$     if proc
+$     then
+$         shared_proc = f$edit(line,"collapse")
+$         chop_semi = f$locate(";", shared_proc)
+$         if chop_semi .lt. f$length(shared_proc) then -
+              shared_proc = f$extract(0, chop_semi, shared_proc)
+$         write aopt f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)",-
+                                f$edit(shared_proc,"upcase"),shared_proc)
+$         write bopt f$fao("!AS=PROCEDURE,-",shared_proc)
+$     endif
+$     goto map_loop
+$MAP_END:
+$     close/nolog aopt
+$     close/nolog bopt
+$     open/append libopt 'p2'
+$     open/read aopt a.opt
+$     open/read bopt b.opt
+$ALOOP:
+$     read/end=aloop_end aopt line
+$     write libopt line
+$     goto aloop
+$ALOOP_END:
+$     close/nolog aopt
+$     sv = ""
+$BLOOP:
+$     read/end=bloop_end bopt svn
+$     if (svn.nes."")
+$     then
+$        if (sv.nes."") then write libopt sv
+$        sv = svn
+$     endif
+$     goto bloop
+$BLOOP_END:
+$     write libopt f$extract(0,f$length(sv)-2,sv), "-"
+$     write libopt ")"
+$     close/nolog bopt
+$     delete/nolog/noconf a.opt;*,b.opt;*
+$ else
+$     if vax
+$     then
+$     open/append libopt 'p2'
+$     mod_sym_num = 1
+$ VMOD_SYM_LOOP:
+$     if f$type(module'mod_sym_num') .nes. ""
+$     then
+$         mod_in = 0
+$ VMOD_SYM_IN:
+$         shared_proc = f$element(mod_in, "#", module'mod_sym_num')
+$         if shared_proc .nes. "#"
+$         then
+$            write libopt f$fao("UNIVERSAL=!AS",-
+                                    f$edit(shared_proc,"upcase"))
+$             mod_in = mod_in + 1
+$             goto vmod_sym_in
+$         endif
+$         mod_sym_num = mod_sym_num + 1
+$         goto vmod_sym_loop
+$     endif
+$VMAP_LOOP:
+$        read/end=vmap_end map line
+$        if (f$locate("{",line).lt. f$length(line)) .or. -
+             (f$locate("global:", line) .lt. f$length(line))
+$        then
+$            proc = true
+$            goto vmap_loop
+$        endif
+$        if f$locate("}",line).lt. f$length(line) then proc = false
+$        if f$locate("local:", line) .lt. f$length(line) then proc = false
+$        if proc
+$        then
+$            shared_proc = f$edit(line,"collapse")
+$            chop_semi = f$locate(";", shared_proc)
+$            if chop_semi .lt. f$length(shared_proc) then -
+                 shared_proc = f$extract(0, chop_semi, shared_proc)
+$            write libopt f$fao("UNIVERSAL=!AS",-
+                                    f$edit(shared_proc,"upcase"))
+$        endif
+$        goto vmap_loop
+$VMAP_END:
+$     else
+$         write sys$output "Unknown Architecture (Not VAX, AXP, or IA64)"
+$         write sys$output "No options file created"
+$     endif
+$ endif
+$ EXIT_M2S:
+$ close/nolog map
+$ close/nolog libopt
+$ endsubroutine
diff --git a/deps/libchdr/deps/zlib-1.2.11/treebuild.xml b/deps/libchdr/deps/zlib-1.2.11/treebuild.xml
new file mode 100644 (file)
index 0000000..fd75525
--- /dev/null
@@ -0,0 +1,116 @@
+<?xml version="1.0" ?>
+<package name="zlib" version="1.2.11">
+    <library name="zlib" dlversion="1.2.11" dlname="z">
+       <property name="description"> zip compression library </property>
+       <property name="include-target-dir" value="$(@PACKAGE/install-includedir)" />
+
+       <!-- fixme: not implemented yet -->
+       <property name="compiler/c/inline" value="yes" />
+
+       <include-file name="zlib.h" scope="public" mode="644" />
+       <include-file name="zconf.h" scope="public" mode="644" />
+
+       <source name="adler32.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+       </source>
+       <source name="compress.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+       </source>
+       <source name="crc32.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="crc32.h" />
+       </source>
+       <source name="gzclose.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="gzguts.h" />
+       </source>
+       <source name="gzlib.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="gzguts.h" />
+       </source>
+       <source name="gzread.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="gzguts.h" />
+       </source>
+       <source name="gzwrite.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="gzguts.h" />
+       </source>
+       <source name="uncompr.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+       </source>
+       <source name="deflate.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="zutil.h" />
+           <depend name="deflate.h" />
+       </source>
+       <source name="trees.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="zutil.h" />
+           <depend name="deflate.h" />
+           <depend name="trees.h" />
+       </source>
+       <source name="zutil.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="zutil.h" />
+       </source>
+       <source name="inflate.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="zutil.h" />
+           <depend name="inftrees.h" />
+           <depend name="inflate.h" />
+           <depend name="inffast.h" />
+       </source>
+       <source name="infback.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="zutil.h" />
+           <depend name="inftrees.h" />
+           <depend name="inflate.h" />
+           <depend name="inffast.h" />
+       </source>
+       <source name="inftrees.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="zutil.h" />
+           <depend name="inftrees.h" />
+       </source>
+       <source name="inffast.c">
+           <depend name="zlib.h" />
+           <depend name="zconf.h" />
+           <depend name="zutil.h" />
+           <depend name="inftrees.h" />
+           <depend name="inflate.h" />
+           <depend name="inffast.h" />
+       </source>
+    </library>
+</package>
+
+<!--
+CFLAGS=-O
+#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
+#CFLAGS=-g -DZLIB_DEBUG
+#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
+#           -Wstrict-prototypes -Wmissing-prototypes
+
+# OBJA =
+# to use the asm code: make OBJA=match.o
+#
+match.o: match.S
+       $(CPP) match.S > _match.s
+       $(CC) -c _match.s
+       mv _match.o match.o
+       rm -f _match.s
+-->
diff --git a/deps/libchdr/deps/zlib-1.2.11/trees.c b/deps/libchdr/deps/zlib-1.2.11/trees.c
new file mode 100644 (file)
index 0000000..50cf4b4
--- /dev/null
@@ -0,0 +1,1203 @@
+/* trees.c -- output deflated data using Huffman coding
+ * Copyright (C) 1995-2017 Jean-loup Gailly
+ * detect_data_type() function provided freely by Cosmin Truta, 2006
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ *  ALGORITHM
+ *
+ *      The "deflation" process uses several Huffman trees. The more
+ *      common source values are represented by shorter bit sequences.
+ *
+ *      Each code tree is stored in a compressed form which is itself
+ * a Huffman encoding of the lengths of all the code strings (in
+ * ascending order by source values).  The actual code strings are
+ * reconstructed from the lengths in the inflate process, as described
+ * in the deflate specification.
+ *
+ *  REFERENCES
+ *
+ *      Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
+ *      Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
+ *
+ *      Storer, James A.
+ *          Data Compression:  Methods and Theory, pp. 49-50.
+ *          Computer Science Press, 1988.  ISBN 0-7167-8156-5.
+ *
+ *      Sedgewick, R.
+ *          Algorithms, p290.
+ *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
+ */
+
+/* @(#) $Id$ */
+
+/* #define GEN_TREES_H */
+
+#include "deflate.h"
+
+#ifdef ZLIB_DEBUG
+#  include <ctype.h>
+#endif
+
+/* ===========================================================================
+ * Constants
+ */
+
+#define MAX_BL_BITS 7
+/* Bit length codes must not exceed MAX_BL_BITS bits */
+
+#define END_BLOCK 256
+/* end of block literal code */
+
+#define REP_3_6      16
+/* repeat previous bit length 3-6 times (2 bits of repeat count) */
+
+#define REPZ_3_10    17
+/* repeat a zero length 3-10 times  (3 bits of repeat count) */
+
+#define REPZ_11_138  18
+/* repeat a zero length 11-138 times  (7 bits of repeat count) */
+
+local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
+   = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
+
+local const int extra_dbits[D_CODES] /* extra bits for each distance code */
+   = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
+
+local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
+   = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
+
+local const uch bl_order[BL_CODES]
+   = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
+/* The lengths of the bit length codes are sent in order of decreasing
+ * probability, to avoid transmitting the lengths for unused bit length codes.
+ */
+
+/* ===========================================================================
+ * Local data. These are initialized only once.
+ */
+
+#define DIST_CODE_LEN  512 /* see definition of array dist_code below */
+
+#if defined(GEN_TREES_H) || !defined(STDC)
+/* non ANSI compilers may not accept trees.h */
+
+local ct_data static_ltree[L_CODES+2];
+/* The static literal tree. Since the bit lengths are imposed, there is no
+ * need for the L_CODES extra codes used during heap construction. However
+ * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
+ * below).
+ */
+
+local ct_data static_dtree[D_CODES];
+/* The static distance tree. (Actually a trivial tree since all codes use
+ * 5 bits.)
+ */
+
+uch _dist_code[DIST_CODE_LEN];
+/* Distance codes. The first 256 values correspond to the distances
+ * 3 .. 258, the last 256 values correspond to the top 8 bits of
+ * the 15 bit distances.
+ */
+
+uch _length_code[MAX_MATCH-MIN_MATCH+1];
+/* length code for each normalized match length (0 == MIN_MATCH) */
+
+local int base_length[LENGTH_CODES];
+/* First normalized length for each code (0 = MIN_MATCH) */
+
+local int base_dist[D_CODES];
+/* First normalized distance for each code (0 = distance of 1) */
+
+#else
+#  include "trees.h"
+#endif /* GEN_TREES_H */
+
+struct static_tree_desc_s {
+    const ct_data *static_tree;  /* static tree or NULL */
+    const intf *extra_bits;      /* extra bits for each code or NULL */
+    int     extra_base;          /* base index for extra_bits */
+    int     elems;               /* max number of elements in the tree */
+    int     max_length;          /* max bit length for the codes */
+};
+
+local const static_tree_desc  static_l_desc =
+{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
+
+local const static_tree_desc  static_d_desc =
+{static_dtree, extra_dbits, 0,          D_CODES, MAX_BITS};
+
+local const static_tree_desc  static_bl_desc =
+{(const ct_data *)0, extra_blbits, 0,   BL_CODES, MAX_BL_BITS};
+
+/* ===========================================================================
+ * Local (static) routines in this file.
+ */
+
+local void tr_static_init OF((void));
+local void init_block     OF((deflate_state *s));
+local void pqdownheap     OF((deflate_state *s, ct_data *tree, int k));
+local void gen_bitlen     OF((deflate_state *s, tree_desc *desc));
+local void gen_codes      OF((ct_data *tree, int max_code, ushf *bl_count));
+local void build_tree     OF((deflate_state *s, tree_desc *desc));
+local void scan_tree      OF((deflate_state *s, ct_data *tree, int max_code));
+local void send_tree      OF((deflate_state *s, ct_data *tree, int max_code));
+local int  build_bl_tree  OF((deflate_state *s));
+local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
+                              int blcodes));
+local void compress_block OF((deflate_state *s, const ct_data *ltree,
+                              const ct_data *dtree));
+local int  detect_data_type OF((deflate_state *s));
+local unsigned bi_reverse OF((unsigned value, int length));
+local void bi_windup      OF((deflate_state *s));
+local void bi_flush       OF((deflate_state *s));
+
+#ifdef GEN_TREES_H
+local void gen_trees_header OF((void));
+#endif
+
+#ifndef ZLIB_DEBUG
+#  define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
+   /* Send a code of the given tree. c and tree must not have side effects */
+
+#else /* !ZLIB_DEBUG */
+#  define send_code(s, c, tree) \
+     { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
+       send_bits(s, tree[c].Code, tree[c].Len); }
+#endif
+
+/* ===========================================================================
+ * Output a short LSB first on the stream.
+ * IN assertion: there is enough room in pendingBuf.
+ */
+#define put_short(s, w) { \
+    put_byte(s, (uch)((w) & 0xff)); \
+    put_byte(s, (uch)((ush)(w) >> 8)); \
+}
+
+/* ===========================================================================
+ * Send a value on a given number of bits.
+ * IN assertion: length <= 16 and value fits in length bits.
+ */
+#ifdef ZLIB_DEBUG
+local void send_bits      OF((deflate_state *s, int value, int length));
+
+local void send_bits(s, value, length)
+    deflate_state *s;
+    int value;  /* value to send */
+    int length; /* number of bits */
+{
+    Tracevv((stderr," l %2d v %4x ", length, value));
+    Assert(length > 0 && length <= 15, "invalid length");
+    s->bits_sent += (ulg)length;
+
+    /* If not enough room in bi_buf, use (valid) bits from bi_buf and
+     * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
+     * unused bits in value.
+     */
+    if (s->bi_valid > (int)Buf_size - length) {
+        s->bi_buf |= (ush)value << s->bi_valid;
+        put_short(s, s->bi_buf);
+        s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
+        s->bi_valid += length - Buf_size;
+    } else {
+        s->bi_buf |= (ush)value << s->bi_valid;
+        s->bi_valid += length;
+    }
+}
+#else /* !ZLIB_DEBUG */
+
+#define send_bits(s, value, length) \
+{ int len = length;\
+  if (s->bi_valid > (int)Buf_size - len) {\
+    int val = (int)value;\
+    s->bi_buf |= (ush)val << s->bi_valid;\
+    put_short(s, s->bi_buf);\
+    s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
+    s->bi_valid += len - Buf_size;\
+  } else {\
+    s->bi_buf |= (ush)(value) << s->bi_valid;\
+    s->bi_valid += len;\
+  }\
+}
+#endif /* ZLIB_DEBUG */
+
+
+/* the arguments must not have side effects */
+
+/* ===========================================================================
+ * Initialize the various 'constant' tables.
+ */
+local void tr_static_init()
+{
+#if defined(GEN_TREES_H) || !defined(STDC)
+    static int static_init_done = 0;
+    int n;        /* iterates over tree elements */
+    int bits;     /* bit counter */
+    int length;   /* length value */
+    int code;     /* code value */
+    int dist;     /* distance index */
+    ush bl_count[MAX_BITS+1];
+    /* number of codes at each bit length for an optimal tree */
+
+    if (static_init_done) return;
+
+    /* For some embedded targets, global variables are not initialized: */
+#ifdef NO_INIT_GLOBAL_POINTERS
+    static_l_desc.static_tree = static_ltree;
+    static_l_desc.extra_bits = extra_lbits;
+    static_d_desc.static_tree = static_dtree;
+    static_d_desc.extra_bits = extra_dbits;
+    static_bl_desc.extra_bits = extra_blbits;
+#endif
+
+    /* Initialize the mapping length (0..255) -> length code (0..28) */
+    length = 0;
+    for (code = 0; code < LENGTH_CODES-1; code++) {
+        base_length[code] = length;
+        for (n = 0; n < (1<<extra_lbits[code]); n++) {
+            _length_code[length++] = (uch)code;
+        }
+    }
+    Assert (length == 256, "tr_static_init: length != 256");
+    /* Note that the length 255 (match length 258) can be represented
+     * in two different ways: code 284 + 5 bits or code 285, so we
+     * overwrite length_code[255] to use the best encoding:
+     */
+    _length_code[length-1] = (uch)code;
+
+    /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
+    dist = 0;
+    for (code = 0 ; code < 16; code++) {
+        base_dist[code] = dist;
+        for (n = 0; n < (1<<extra_dbits[code]); n++) {
+            _dist_code[dist++] = (uch)code;
+        }
+    }
+    Assert (dist == 256, "tr_static_init: dist != 256");
+    dist >>= 7; /* from now on, all distances are divided by 128 */
+    for ( ; code < D_CODES; code++) {
+        base_dist[code] = dist << 7;
+        for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
+            _dist_code[256 + dist++] = (uch)code;
+        }
+    }
+    Assert (dist == 256, "tr_static_init: 256+dist != 512");
+
+    /* Construct the codes of the static literal tree */
+    for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
+    n = 0;
+    while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
+    while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
+    while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
+    while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
+    /* Codes 286 and 287 do not exist, but we must include them in the
+     * tree construction to get a canonical Huffman tree (longest code
+     * all ones)
+     */
+    gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
+
+    /* The static distance tree is trivial: */
+    for (n = 0; n < D_CODES; n++) {
+        static_dtree[n].Len = 5;
+        static_dtree[n].Code = bi_reverse((unsigned)n, 5);
+    }
+    static_init_done = 1;
+
+#  ifdef GEN_TREES_H
+    gen_trees_header();
+#  endif
+#endif /* defined(GEN_TREES_H) || !defined(STDC) */
+}
+
+/* ===========================================================================
+ * Genererate the file trees.h describing the static trees.
+ */
+#ifdef GEN_TREES_H
+#  ifndef ZLIB_DEBUG
+#    include <stdio.h>
+#  endif
+
+#  define SEPARATOR(i, last, width) \
+      ((i) == (last)? "\n};\n\n" :    \
+       ((i) % (width) == (width)-1 ? ",\n" : ", "))
+
+void gen_trees_header()
+{
+    FILE *header = fopen("trees.h", "w");
+    int i;
+
+    Assert (header != NULL, "Can't open trees.h");
+    fprintf(header,
+            "/* header created automatically with -DGEN_TREES_H */\n\n");
+
+    fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
+    for (i = 0; i < L_CODES+2; i++) {
+        fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
+                static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
+    }
+
+    fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
+    for (i = 0; i < D_CODES; i++) {
+        fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
+                static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
+    }
+
+    fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
+    for (i = 0; i < DIST_CODE_LEN; i++) {
+        fprintf(header, "%2u%s", _dist_code[i],
+                SEPARATOR(i, DIST_CODE_LEN-1, 20));
+    }
+
+    fprintf(header,
+        "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
+    for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
+        fprintf(header, "%2u%s", _length_code[i],
+                SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
+    }
+
+    fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
+    for (i = 0; i < LENGTH_CODES; i++) {
+        fprintf(header, "%1u%s", base_length[i],
+                SEPARATOR(i, LENGTH_CODES-1, 20));
+    }
+
+    fprintf(header, "local const int base_dist[D_CODES] = {\n");
+    for (i = 0; i < D_CODES; i++) {
+        fprintf(header, "%5u%s", base_dist[i],
+                SEPARATOR(i, D_CODES-1, 10));
+    }
+
+    fclose(header);
+}
+#endif /* GEN_TREES_H */
+
+/* ===========================================================================
+ * Initialize the tree data structures for a new zlib stream.
+ */
+void ZLIB_INTERNAL _tr_init(s)
+    deflate_state *s;
+{
+    tr_static_init();
+
+    s->l_desc.dyn_tree = s->dyn_ltree;
+    s->l_desc.stat_desc = &static_l_desc;
+
+    s->d_desc.dyn_tree = s->dyn_dtree;
+    s->d_desc.stat_desc = &static_d_desc;
+
+    s->bl_desc.dyn_tree = s->bl_tree;
+    s->bl_desc.stat_desc = &static_bl_desc;
+
+    s->bi_buf = 0;
+    s->bi_valid = 0;
+#ifdef ZLIB_DEBUG
+    s->compressed_len = 0L;
+    s->bits_sent = 0L;
+#endif
+
+    /* Initialize the first block of the first file: */
+    init_block(s);
+}
+
+/* ===========================================================================
+ * Initialize a new block.
+ */
+local void init_block(s)
+    deflate_state *s;
+{
+    int n; /* iterates over tree elements */
+
+    /* Initialize the trees. */
+    for (n = 0; n < L_CODES;  n++) s->dyn_ltree[n].Freq = 0;
+    for (n = 0; n < D_CODES;  n++) s->dyn_dtree[n].Freq = 0;
+    for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
+
+    s->dyn_ltree[END_BLOCK].Freq = 1;
+    s->opt_len = s->static_len = 0L;
+    s->last_lit = s->matches = 0;
+}
+
+#define SMALLEST 1
+/* Index within the heap array of least frequent node in the Huffman tree */
+
+
+/* ===========================================================================
+ * Remove the smallest element from the heap and recreate the heap with
+ * one less element. Updates heap and heap_len.
+ */
+#define pqremove(s, tree, top) \
+{\
+    top = s->heap[SMALLEST]; \
+    s->heap[SMALLEST] = s->heap[s->heap_len--]; \
+    pqdownheap(s, tree, SMALLEST); \
+}
+
+/* ===========================================================================
+ * Compares to subtrees, using the tree depth as tie breaker when
+ * the subtrees have equal frequency. This minimizes the worst case length.
+ */
+#define smaller(tree, n, m, depth) \
+   (tree[n].Freq < tree[m].Freq || \
+   (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
+
+/* ===========================================================================
+ * Restore the heap property by moving down the tree starting at node k,
+ * exchanging a node with the smallest of its two sons if necessary, stopping
+ * when the heap property is re-established (each father smaller than its
+ * two sons).
+ */
+local void pqdownheap(s, tree, k)
+    deflate_state *s;
+    ct_data *tree;  /* the tree to restore */
+    int k;               /* node to move down */
+{
+    int v = s->heap[k];
+    int j = k << 1;  /* left son of k */
+    while (j <= s->heap_len) {
+        /* Set j to the smallest of the two sons: */
+        if (j < s->heap_len &&
+            smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
+            j++;
+        }
+        /* Exit if v is smaller than both sons */
+        if (smaller(tree, v, s->heap[j], s->depth)) break;
+
+        /* Exchange v with the smallest son */
+        s->heap[k] = s->heap[j];  k = j;
+
+        /* And continue down the tree, setting j to the left son of k */
+        j <<= 1;
+    }
+    s->heap[k] = v;
+}
+
+/* ===========================================================================
+ * Compute the optimal bit lengths for a tree and update the total bit length
+ * for the current block.
+ * IN assertion: the fields freq and dad are set, heap[heap_max] and
+ *    above are the tree nodes sorted by increasing frequency.
+ * OUT assertions: the field len is set to the optimal bit length, the
+ *     array bl_count contains the frequencies for each bit length.
+ *     The length opt_len is updated; static_len is also updated if stree is
+ *     not null.
+ */
+local void gen_bitlen(s, desc)
+    deflate_state *s;
+    tree_desc *desc;    /* the tree descriptor */
+{
+    ct_data *tree        = desc->dyn_tree;
+    int max_code         = desc->max_code;
+    const ct_data *stree = desc->stat_desc->static_tree;
+    const intf *extra    = desc->stat_desc->extra_bits;
+    int base             = desc->stat_desc->extra_base;
+    int max_length       = desc->stat_desc->max_length;
+    int h;              /* heap index */
+    int n, m;           /* iterate over the tree elements */
+    int bits;           /* bit length */
+    int xbits;          /* extra bits */
+    ush f;              /* frequency */
+    int overflow = 0;   /* number of elements with bit length too large */
+
+    for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
+
+    /* In a first pass, compute the optimal bit lengths (which may
+     * overflow in the case of the bit length tree).
+     */
+    tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
+
+    for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
+        n = s->heap[h];
+        bits = tree[tree[n].Dad].Len + 1;
+        if (bits > max_length) bits = max_length, overflow++;
+        tree[n].Len = (ush)bits;
+        /* We overwrite tree[n].Dad which is no longer needed */
+
+        if (n > max_code) continue; /* not a leaf node */
+
+        s->bl_count[bits]++;
+        xbits = 0;
+        if (n >= base) xbits = extra[n-base];
+        f = tree[n].Freq;
+        s->opt_len += (ulg)f * (unsigned)(bits + xbits);
+        if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits);
+    }
+    if (overflow == 0) return;
+
+    Tracev((stderr,"\nbit length overflow\n"));
+    /* This happens for example on obj2 and pic of the Calgary corpus */
+
+    /* Find the first bit length which could increase: */
+    do {
+        bits = max_length-1;
+        while (s->bl_count[bits] == 0) bits--;
+        s->bl_count[bits]--;      /* move one leaf down the tree */
+        s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
+        s->bl_count[max_length]--;
+        /* The brother of the overflow item also moves one step up,
+         * but this does not affect bl_count[max_length]
+         */
+        overflow -= 2;
+    } while (overflow > 0);
+
+    /* Now recompute all bit lengths, scanning in increasing frequency.
+     * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
+     * lengths instead of fixing only the wrong ones. This idea is taken
+     * from 'ar' written by Haruhiko Okumura.)
+     */
+    for (bits = max_length; bits != 0; bits--) {
+        n = s->bl_count[bits];
+        while (n != 0) {
+            m = s->heap[--h];
+            if (m > max_code) continue;
+            if ((unsigned) tree[m].Len != (unsigned) bits) {
+                Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
+                s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq;
+                tree[m].Len = (ush)bits;
+            }
+            n--;
+        }
+    }
+}
+
+/* ===========================================================================
+ * Generate the codes for a given tree and bit counts (which need not be
+ * optimal).
+ * IN assertion: the array bl_count contains the bit length statistics for
+ * the given tree and the field len is set for all tree elements.
+ * OUT assertion: the field code is set for all tree elements of non
+ *     zero code length.
+ */
+local void gen_codes (tree, max_code, bl_count)
+    ct_data *tree;             /* the tree to decorate */
+    int max_code;              /* largest code with non zero frequency */
+    ushf *bl_count;            /* number of codes at each bit length */
+{
+    ush next_code[MAX_BITS+1]; /* next code value for each bit length */
+    unsigned code = 0;         /* running code value */
+    int bits;                  /* bit index */
+    int n;                     /* code index */
+
+    /* The distribution counts are first used to generate the code values
+     * without bit reversal.
+     */
+    for (bits = 1; bits <= MAX_BITS; bits++) {
+        code = (code + bl_count[bits-1]) << 1;
+        next_code[bits] = (ush)code;
+    }
+    /* Check that the bit counts in bl_count are consistent. The last code
+     * must be all ones.
+     */
+    Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
+            "inconsistent bit counts");
+    Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
+
+    for (n = 0;  n <= max_code; n++) {
+        int len = tree[n].Len;
+        if (len == 0) continue;
+        /* Now reverse the bits */
+        tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
+
+        Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
+             n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
+    }
+}
+
+/* ===========================================================================
+ * Construct one Huffman tree and assigns the code bit strings and lengths.
+ * Update the total bit length for the current block.
+ * IN assertion: the field freq is set for all tree elements.
+ * OUT assertions: the fields len and code are set to the optimal bit length
+ *     and corresponding code. The length opt_len is updated; static_len is
+ *     also updated if stree is not null. The field max_code is set.
+ */
+local void build_tree(s, desc)
+    deflate_state *s;
+    tree_desc *desc; /* the tree descriptor */
+{
+    ct_data *tree         = desc->dyn_tree;
+    const ct_data *stree  = desc->stat_desc->static_tree;
+    int elems             = desc->stat_desc->elems;
+    int n, m;          /* iterate over heap elements */
+    int max_code = -1; /* largest code with non zero frequency */
+    int node;          /* new node being created */
+
+    /* Construct the initial heap, with least frequent element in
+     * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
+     * heap[0] is not used.
+     */
+    s->heap_len = 0, s->heap_max = HEAP_SIZE;
+
+    for (n = 0; n < elems; n++) {
+        if (tree[n].Freq != 0) {
+            s->heap[++(s->heap_len)] = max_code = n;
+            s->depth[n] = 0;
+        } else {
+            tree[n].Len = 0;
+        }
+    }
+
+    /* The pkzip format requires that at least one distance code exists,
+     * and that at least one bit should be sent even if there is only one
+     * possible code. So to avoid special checks later on we force at least
+     * two codes of non zero frequency.
+     */
+    while (s->heap_len < 2) {
+        node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
+        tree[node].Freq = 1;
+        s->depth[node] = 0;
+        s->opt_len--; if (stree) s->static_len -= stree[node].Len;
+        /* node is 0 or 1 so it does not have extra bits */
+    }
+    desc->max_code = max_code;
+
+    /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
+     * establish sub-heaps of increasing lengths:
+     */
+    for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
+
+    /* Construct the Huffman tree by repeatedly combining the least two
+     * frequent nodes.
+     */
+    node = elems;              /* next internal node of the tree */
+    do {
+        pqremove(s, tree, n);  /* n = node of least frequency */
+        m = s->heap[SMALLEST]; /* m = node of next least frequency */
+
+        s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
+        s->heap[--(s->heap_max)] = m;
+
+        /* Create a new node father of n and m */
+        tree[node].Freq = tree[n].Freq + tree[m].Freq;
+        s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
+                                s->depth[n] : s->depth[m]) + 1);
+        tree[n].Dad = tree[m].Dad = (ush)node;
+#ifdef DUMP_BL_TREE
+        if (tree == s->bl_tree) {
+            fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
+                    node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
+        }
+#endif
+        /* and insert the new node in the heap */
+        s->heap[SMALLEST] = node++;
+        pqdownheap(s, tree, SMALLEST);
+
+    } while (s->heap_len >= 2);
+
+    s->heap[--(s->heap_max)] = s->heap[SMALLEST];
+
+    /* At this point, the fields freq and dad are set. We can now
+     * generate the bit lengths.
+     */
+    gen_bitlen(s, (tree_desc *)desc);
+
+    /* The field len is now set, we can generate the bit codes */
+    gen_codes ((ct_data *)tree, max_code, s->bl_count);
+}
+
+/* ===========================================================================
+ * Scan a literal or distance tree to determine the frequencies of the codes
+ * in the bit length tree.
+ */
+local void scan_tree (s, tree, max_code)
+    deflate_state *s;
+    ct_data *tree;   /* the tree to be scanned */
+    int max_code;    /* and its largest code of non zero frequency */
+{
+    int n;                     /* iterates over all tree elements */
+    int prevlen = -1;          /* last emitted length */
+    int curlen;                /* length of current code */
+    int nextlen = tree[0].Len; /* length of next code */
+    int count = 0;             /* repeat count of the current code */
+    int max_count = 7;         /* max repeat count */
+    int min_count = 4;         /* min repeat count */
+
+    if (nextlen == 0) max_count = 138, min_count = 3;
+    tree[max_code+1].Len = (ush)0xffff; /* guard */
+
+    for (n = 0; n <= max_code; n++) {
+        curlen = nextlen; nextlen = tree[n+1].Len;
+        if (++count < max_count && curlen == nextlen) {
+            continue;
+        } else if (count < min_count) {
+            s->bl_tree[curlen].Freq += count;
+        } else if (curlen != 0) {
+            if (curlen != prevlen) s->bl_tree[curlen].Freq++;
+            s->bl_tree[REP_3_6].Freq++;
+        } else if (count <= 10) {
+            s->bl_tree[REPZ_3_10].Freq++;
+        } else {
+            s->bl_tree[REPZ_11_138].Freq++;
+        }
+        count = 0; prevlen = curlen;
+        if (nextlen == 0) {
+            max_count = 138, min_count = 3;
+        } else if (curlen == nextlen) {
+            max_count = 6, min_count = 3;
+        } else {
+            max_count = 7, min_count = 4;
+        }
+    }
+}
+
+/* ===========================================================================
+ * Send a literal or distance tree in compressed form, using the codes in
+ * bl_tree.
+ */
+local void send_tree (s, tree, max_code)
+    deflate_state *s;
+    ct_data *tree; /* the tree to be scanned */
+    int max_code;       /* and its largest code of non zero frequency */
+{
+    int n;                     /* iterates over all tree elements */
+    int prevlen = -1;          /* last emitted length */
+    int curlen;                /* length of current code */
+    int nextlen = tree[0].Len; /* length of next code */
+    int count = 0;             /* repeat count of the current code */
+    int max_count = 7;         /* max repeat count */
+    int min_count = 4;         /* min repeat count */
+
+    /* tree[max_code+1].Len = -1; */  /* guard already set */
+    if (nextlen == 0) max_count = 138, min_count = 3;
+
+    for (n = 0; n <= max_code; n++) {
+        curlen = nextlen; nextlen = tree[n+1].Len;
+        if (++count < max_count && curlen == nextlen) {
+            continue;
+        } else if (count < min_count) {
+            do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
+
+        } else if (curlen != 0) {
+            if (curlen != prevlen) {
+                send_code(s, curlen, s->bl_tree); count--;
+            }
+            Assert(count >= 3 && count <= 6, " 3_6?");
+            send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
+
+        } else if (count <= 10) {
+            send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
+
+        } else {
+            send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
+        }
+        count = 0; prevlen = curlen;
+        if (nextlen == 0) {
+            max_count = 138, min_count = 3;
+        } else if (curlen == nextlen) {
+            max_count = 6, min_count = 3;
+        } else {
+            max_count = 7, min_count = 4;
+        }
+    }
+}
+
+/* ===========================================================================
+ * Construct the Huffman tree for the bit lengths and return the index in
+ * bl_order of the last bit length code to send.
+ */
+local int build_bl_tree(s)
+    deflate_state *s;
+{
+    int max_blindex;  /* index of last bit length code of non zero freq */
+
+    /* Determine the bit length frequencies for literal and distance trees */
+    scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
+    scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
+
+    /* Build the bit length tree: */
+    build_tree(s, (tree_desc *)(&(s->bl_desc)));
+    /* opt_len now includes the length of the tree representations, except
+     * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
+     */
+
+    /* Determine the number of bit length codes to send. The pkzip format
+     * requires that at least 4 bit length codes be sent. (appnote.txt says
+     * 3 but the actual value used is 4.)
+     */
+    for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
+        if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
+    }
+    /* Update opt_len to include the bit length tree and counts */
+    s->opt_len += 3*((ulg)max_blindex+1) + 5+5+4;
+    Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
+            s->opt_len, s->static_len));
+
+    return max_blindex;
+}
+
+/* ===========================================================================
+ * Send the header for a block using dynamic Huffman trees: the counts, the
+ * lengths of the bit length codes, the literal tree and the distance tree.
+ * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
+ */
+local void send_all_trees(s, lcodes, dcodes, blcodes)
+    deflate_state *s;
+    int lcodes, dcodes, blcodes; /* number of codes for each tree */
+{
+    int rank;                    /* index in bl_order */
+
+    Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
+    Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
+            "too many codes");
+    Tracev((stderr, "\nbl counts: "));
+    send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
+    send_bits(s, dcodes-1,   5);
+    send_bits(s, blcodes-4,  4); /* not -3 as stated in appnote.txt */
+    for (rank = 0; rank < blcodes; rank++) {
+        Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
+        send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
+    }
+    Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
+
+    send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
+    Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
+
+    send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
+    Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
+}
+
+/* ===========================================================================
+ * Send a stored block
+ */
+void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
+    deflate_state *s;
+    charf *buf;       /* input block */
+    ulg stored_len;   /* length of input block */
+    int last;         /* one if this is the last block for a file */
+{
+    send_bits(s, (STORED_BLOCK<<1)+last, 3);    /* send block type */
+    bi_windup(s);        /* align on byte boundary */
+    put_short(s, (ush)stored_len);
+    put_short(s, (ush)~stored_len);
+    zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
+    s->pending += stored_len;
+#ifdef ZLIB_DEBUG
+    s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
+    s->compressed_len += (stored_len + 4) << 3;
+    s->bits_sent += 2*16;
+    s->bits_sent += stored_len<<3;
+#endif
+}
+
+/* ===========================================================================
+ * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
+ */
+void ZLIB_INTERNAL _tr_flush_bits(s)
+    deflate_state *s;
+{
+    bi_flush(s);
+}
+
+/* ===========================================================================
+ * Send one empty static block to give enough lookahead for inflate.
+ * This takes 10 bits, of which 7 may remain in the bit buffer.
+ */
+void ZLIB_INTERNAL _tr_align(s)
+    deflate_state *s;
+{
+    send_bits(s, STATIC_TREES<<1, 3);
+    send_code(s, END_BLOCK, static_ltree);
+#ifdef ZLIB_DEBUG
+    s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
+#endif
+    bi_flush(s);
+}
+
+/* ===========================================================================
+ * Determine the best encoding for the current block: dynamic trees, static
+ * trees or store, and write out the encoded block.
+ */
+void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
+    deflate_state *s;
+    charf *buf;       /* input block, or NULL if too old */
+    ulg stored_len;   /* length of input block */
+    int last;         /* one if this is the last block for a file */
+{
+    ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
+    int max_blindex = 0;  /* index of last bit length code of non zero freq */
+
+    /* Build the Huffman trees unless a stored block is forced */
+    if (s->level > 0) {
+
+        /* Check if the file is binary or text */
+        if (s->strm->data_type == Z_UNKNOWN)
+            s->strm->data_type = detect_data_type(s);
+
+        /* Construct the literal and distance trees */
+        build_tree(s, (tree_desc *)(&(s->l_desc)));
+        Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
+                s->static_len));
+
+        build_tree(s, (tree_desc *)(&(s->d_desc)));
+        Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
+                s->static_len));
+        /* At this point, opt_len and static_len are the total bit lengths of
+         * the compressed block data, excluding the tree representations.
+         */
+
+        /* Build the bit length tree for the above two trees, and get the index
+         * in bl_order of the last bit length code to send.
+         */
+        max_blindex = build_bl_tree(s);
+
+        /* Determine the best encoding. Compute the block lengths in bytes. */
+        opt_lenb = (s->opt_len+3+7)>>3;
+        static_lenb = (s->static_len+3+7)>>3;
+
+        Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
+                opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
+                s->last_lit));
+
+        if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
+
+    } else {
+        Assert(buf != (char*)0, "lost buf");
+        opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
+    }
+
+#ifdef FORCE_STORED
+    if (buf != (char*)0) { /* force stored block */
+#else
+    if (stored_len+4 <= opt_lenb && buf != (char*)0) {
+                       /* 4: two words for the lengths */
+#endif
+        /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
+         * Otherwise we can't have processed more than WSIZE input bytes since
+         * the last block flush, because compression would have been
+         * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
+         * transform a block into a stored block.
+         */
+        _tr_stored_block(s, buf, stored_len, last);
+
+#ifdef FORCE_STATIC
+    } else if (static_lenb >= 0) { /* force static trees */
+#else
+    } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
+#endif
+        send_bits(s, (STATIC_TREES<<1)+last, 3);
+        compress_block(s, (const ct_data *)static_ltree,
+                       (const ct_data *)static_dtree);
+#ifdef ZLIB_DEBUG
+        s->compressed_len += 3 + s->static_len;
+#endif
+    } else {
+        send_bits(s, (DYN_TREES<<1)+last, 3);
+        send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
+                       max_blindex+1);
+        compress_block(s, (const ct_data *)s->dyn_ltree,
+                       (const ct_data *)s->dyn_dtree);
+#ifdef ZLIB_DEBUG
+        s->compressed_len += 3 + s->opt_len;
+#endif
+    }
+    Assert (s->compressed_len == s->bits_sent, "bad compressed size");
+    /* The above check is made mod 2^32, for files larger than 512 MB
+     * and uLong implemented on 32 bits.
+     */
+    init_block(s);
+
+    if (last) {
+        bi_windup(s);
+#ifdef ZLIB_DEBUG
+        s->compressed_len += 7;  /* align on byte boundary */
+#endif
+    }
+    Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
+           s->compressed_len-7*last));
+}
+
+/* ===========================================================================
+ * Save the match info and tally the frequency counts. Return true if
+ * the current block must be flushed.
+ */
+int ZLIB_INTERNAL _tr_tally (s, dist, lc)
+    deflate_state *s;
+    unsigned dist;  /* distance of matched string */
+    unsigned lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */
+{
+    s->d_buf[s->last_lit] = (ush)dist;
+    s->l_buf[s->last_lit++] = (uch)lc;
+    if (dist == 0) {
+        /* lc is the unmatched char */
+        s->dyn_ltree[lc].Freq++;
+    } else {
+        s->matches++;
+        /* Here, lc is the match length - MIN_MATCH */
+        dist--;             /* dist = match distance - 1 */
+        Assert((ush)dist < (ush)MAX_DIST(s) &&
+               (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
+               (ush)d_code(dist) < (ush)D_CODES,  "_tr_tally: bad match");
+
+        s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
+        s->dyn_dtree[d_code(dist)].Freq++;
+    }
+
+#ifdef TRUNCATE_BLOCK
+    /* Try to guess if it is profitable to stop the current block here */
+    if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
+        /* Compute an upper bound for the compressed length */
+        ulg out_length = (ulg)s->last_lit*8L;
+        ulg in_length = (ulg)((long)s->strstart - s->block_start);
+        int dcode;
+        for (dcode = 0; dcode < D_CODES; dcode++) {
+            out_length += (ulg)s->dyn_dtree[dcode].Freq *
+                (5L+extra_dbits[dcode]);
+        }
+        out_length >>= 3;
+        Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
+               s->last_lit, in_length, out_length,
+               100L - out_length*100L/in_length));
+        if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
+    }
+#endif
+    return (s->last_lit == s->lit_bufsize-1);
+    /* We avoid equality with lit_bufsize because of wraparound at 64K
+     * on 16 bit machines and because stored blocks are restricted to
+     * 64K-1 bytes.
+     */
+}
+
+/* ===========================================================================
+ * Send the block data compressed using the given Huffman trees
+ */
+local void compress_block(s, ltree, dtree)
+    deflate_state *s;
+    const ct_data *ltree; /* literal tree */
+    const ct_data *dtree; /* distance tree */
+{
+    unsigned dist;      /* distance of matched string */
+    int lc;             /* match length or unmatched char (if dist == 0) */
+    unsigned lx = 0;    /* running index in l_buf */
+    unsigned code;      /* the code to send */
+    int extra;          /* number of extra bits to send */
+
+    if (s->last_lit != 0) do {
+        dist = s->d_buf[lx];
+        lc = s->l_buf[lx++];
+        if (dist == 0) {
+            send_code(s, lc, ltree); /* send a literal byte */
+            Tracecv(isgraph(lc), (stderr," '%c' ", lc));
+        } else {
+            /* Here, lc is the match length - MIN_MATCH */
+            code = _length_code[lc];
+            send_code(s, code+LITERALS+1, ltree); /* send the length code */
+            extra = extra_lbits[code];
+            if (extra != 0) {
+                lc -= base_length[code];
+                send_bits(s, lc, extra);       /* send the extra length bits */
+            }
+            dist--; /* dist is now the match distance - 1 */
+            code = d_code(dist);
+            Assert (code < D_CODES, "bad d_code");
+
+            send_code(s, code, dtree);       /* send the distance code */
+            extra = extra_dbits[code];
+            if (extra != 0) {
+                dist -= (unsigned)base_dist[code];
+                send_bits(s, dist, extra);   /* send the extra distance bits */
+            }
+        } /* literal or match pair ? */
+
+        /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
+        Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
+               "pendingBuf overflow");
+
+    } while (lx < s->last_lit);
+
+    send_code(s, END_BLOCK, ltree);
+}
+
+/* ===========================================================================
+ * Check if the data type is TEXT or BINARY, using the following algorithm:
+ * - TEXT if the two conditions below are satisfied:
+ *    a) There are no non-portable control characters belonging to the
+ *       "black list" (0..6, 14..25, 28..31).
+ *    b) There is at least one printable character belonging to the
+ *       "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
+ * - BINARY otherwise.
+ * - The following partially-portable control characters form a
+ *   "gray list" that is ignored in this detection algorithm:
+ *   (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
+ * IN assertion: the fields Freq of dyn_ltree are set.
+ */
+local int detect_data_type(s)
+    deflate_state *s;
+{
+    /* black_mask is the bit mask of black-listed bytes
+     * set bits 0..6, 14..25, and 28..31
+     * 0xf3ffc07f = binary 11110011111111111100000001111111
+     */
+    unsigned long black_mask = 0xf3ffc07fUL;
+    int n;
+
+    /* Check for non-textual ("black-listed") bytes. */
+    for (n = 0; n <= 31; n++, black_mask >>= 1)
+        if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0))
+            return Z_BINARY;
+
+    /* Check for textual ("white-listed") bytes. */
+    if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
+            || s->dyn_ltree[13].Freq != 0)
+        return Z_TEXT;
+    for (n = 32; n < LITERALS; n++)
+        if (s->dyn_ltree[n].Freq != 0)
+            return Z_TEXT;
+
+    /* There are no "black-listed" or "white-listed" bytes:
+     * this stream either is empty or has tolerated ("gray-listed") bytes only.
+     */
+    return Z_BINARY;
+}
+
+/* ===========================================================================
+ * Reverse the first len bits of a code, using straightforward code (a faster
+ * method would use a table)
+ * IN assertion: 1 <= len <= 15
+ */
+local unsigned bi_reverse(code, len)
+    unsigned code; /* the value to invert */
+    int len;       /* its bit length */
+{
+    register unsigned res = 0;
+    do {
+        res |= code & 1;
+        code >>= 1, res <<= 1;
+    } while (--len > 0);
+    return res >> 1;
+}
+
+/* ===========================================================================
+ * Flush the bit buffer, keeping at most 7 bits in it.
+ */
+local void bi_flush(s)
+    deflate_state *s;
+{
+    if (s->bi_valid == 16) {
+        put_short(s, s->bi_buf);
+        s->bi_buf = 0;
+        s->bi_valid = 0;
+    } else if (s->bi_valid >= 8) {
+        put_byte(s, (Byte)s->bi_buf);
+        s->bi_buf >>= 8;
+        s->bi_valid -= 8;
+    }
+}
+
+/* ===========================================================================
+ * Flush the bit buffer and align the output on a byte boundary
+ */
+local void bi_windup(s)
+    deflate_state *s;
+{
+    if (s->bi_valid > 8) {
+        put_short(s, s->bi_buf);
+    } else if (s->bi_valid > 0) {
+        put_byte(s, (Byte)s->bi_buf);
+    }
+    s->bi_buf = 0;
+    s->bi_valid = 0;
+#ifdef ZLIB_DEBUG
+    s->bits_sent = (s->bits_sent+7) & ~7;
+#endif
+}
similarity index 99%
rename from deps/zlib/trees.h
rename to deps/libchdr/deps/zlib-1.2.11/trees.h
index c0261b2..d35639d 100644 (file)
@@ -1,6 +1,4 @@
 /* header created automatically with -DGEN_TREES_H */
-#ifndef _TREES_H
-#define _TREES_H
 
 local const ct_data static_ltree[L_CODES+2] = {
 {{ 12},{  8}}, {{140},{  8}}, {{ 76},{  8}}, {{204},{  8}}, {{ 44},{  8}},
@@ -128,5 +126,3 @@ local const int base_dist[D_CODES] = {
  1024,  1536,  2048,  3072,  4096,  6144,  8192, 12288, 16384, 24576
 };
 
-
-#endif
diff --git a/deps/libchdr/deps/zlib-1.2.11/uncompr.c b/deps/libchdr/deps/zlib-1.2.11/uncompr.c
new file mode 100644 (file)
index 0000000..f03a1a8
--- /dev/null
@@ -0,0 +1,93 @@
+/* uncompr.c -- decompress a memory buffer
+ * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+/* ===========================================================================
+     Decompresses the source buffer into the destination buffer.  *sourceLen is
+   the byte length of the source buffer. Upon entry, *destLen is the total size
+   of the destination buffer, which must be large enough to hold the entire
+   uncompressed data. (The size of the uncompressed data must have been saved
+   previously by the compressor and transmitted to the decompressor by some
+   mechanism outside the scope of this compression library.) Upon exit,
+   *destLen is the size of the decompressed data and *sourceLen is the number
+   of source bytes consumed. Upon return, source + *sourceLen points to the
+   first unused input byte.
+
+     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
+   memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
+   Z_DATA_ERROR if the input data was corrupted, including if the input data is
+   an incomplete zlib stream.
+*/
+int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
+    Bytef *dest;
+    uLongf *destLen;
+    const Bytef *source;
+    uLong *sourceLen;
+{
+    z_stream stream;
+    int err;
+    const uInt max = (uInt)-1;
+    uLong len, left;
+    Byte buf[1];    /* for detection of incomplete stream when *destLen == 0 */
+
+    len = *sourceLen;
+    if (*destLen) {
+        left = *destLen;
+        *destLen = 0;
+    }
+    else {
+        left = 1;
+        dest = buf;
+    }
+
+    stream.next_in = (z_const Bytef *)source;
+    stream.avail_in = 0;
+    stream.zalloc = (alloc_func)0;
+    stream.zfree = (free_func)0;
+    stream.opaque = (voidpf)0;
+
+    err = inflateInit(&stream);
+    if (err != Z_OK) return err;
+
+    stream.next_out = dest;
+    stream.avail_out = 0;
+
+    do {
+        if (stream.avail_out == 0) {
+            stream.avail_out = left > (uLong)max ? max : (uInt)left;
+            left -= stream.avail_out;
+        }
+        if (stream.avail_in == 0) {
+            stream.avail_in = len > (uLong)max ? max : (uInt)len;
+            len -= stream.avail_in;
+        }
+        err = inflate(&stream, Z_NO_FLUSH);
+    } while (err == Z_OK);
+
+    *sourceLen -= len + stream.avail_in;
+    if (dest != buf)
+        *destLen = stream.total_out;
+    else if (stream.total_out && err == Z_BUF_ERROR)
+        left = 1;
+
+    inflateEnd(&stream);
+    return err == Z_STREAM_END ? Z_OK :
+           err == Z_NEED_DICT ? Z_DATA_ERROR  :
+           err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
+           err;
+}
+
+int ZEXPORT uncompress (dest, destLen, source, sourceLen)
+    Bytef *dest;
+    uLongf *destLen;
+    const Bytef *source;
+    uLong sourceLen;
+{
+    return uncompress2(dest, destLen, source, &sourceLen);
+}
similarity index 93%
rename from deps/zlib/zconf.h
rename to deps/libchdr/deps/zlib-1.2.11/zconf.h
index 9987a77..5e1d68a 100644 (file)
@@ -1,5 +1,5 @@
 /* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-2013 Jean-loup Gailly.
+ * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -17,7 +17,7 @@
 #ifdef Z_PREFIX     /* may be set to #if 1 by ./configure */
 #  define Z_PREFIX_SET
 
-/* all linked symbols */
+/* all linked symbols and init macros */
 #  define _dist_code            z__dist_code
 #  define _length_code          z__length_code
 #  define _tr_align             z__tr_align
@@ -29,6 +29,7 @@
 #  define adler32               z_adler32
 #  define adler32_combine       z_adler32_combine
 #  define adler32_combine64     z_adler32_combine64
+#  define adler32_z             z_adler32_z
 #  ifndef Z_SOLO
 #    define compress              z_compress
 #    define compress2             z_compress2
 #  define crc32                 z_crc32
 #  define crc32_combine         z_crc32_combine
 #  define crc32_combine64       z_crc32_combine64
+#  define crc32_z               z_crc32_z
 #  define deflate               z_deflate
 #  define deflateBound          z_deflateBound
 #  define deflateCopy           z_deflateCopy
 #  define deflateEnd            z_deflateEnd
+#  define deflateGetDictionary  z_deflateGetDictionary
+#  define deflateInit           z_deflateInit
+#  define deflateInit2          z_deflateInit2
 #  define deflateInit2_         z_deflateInit2_
 #  define deflateInit_          z_deflateInit_
 #  define deflateParams         z_deflateParams
@@ -67,6 +72,8 @@
 #    define gzeof                 z_gzeof
 #    define gzerror               z_gzerror
 #    define gzflush               z_gzflush
+#    define gzfread               z_gzfread
+#    define gzfwrite              z_gzfwrite
 #    define gzgetc                z_gzgetc
 #    define gzgetc_               z_gzgetc_
 #    define gzgets                z_gzgets
@@ -78,7 +85,6 @@
 #      define gzopen_w              z_gzopen_w
 #    endif
 #    define gzprintf              z_gzprintf
-#    define gzvprintf             z_gzvprintf
 #    define gzputc                z_gzputc
 #    define gzputs                z_gzputs
 #    define gzread                z_gzread
 #    define gztell                z_gztell
 #    define gztell64              z_gztell64
 #    define gzungetc              z_gzungetc
+#    define gzvprintf             z_gzvprintf
 #    define gzwrite               z_gzwrite
 #  endif
 #  define inflate               z_inflate
 #  define inflateBack           z_inflateBack
 #  define inflateBackEnd        z_inflateBackEnd
+#  define inflateBackInit       z_inflateBackInit
 #  define inflateBackInit_      z_inflateBackInit_
+#  define inflateCodesUsed      z_inflateCodesUsed
 #  define inflateCopy           z_inflateCopy
 #  define inflateEnd            z_inflateEnd
+#  define inflateGetDictionary  z_inflateGetDictionary
 #  define inflateGetHeader      z_inflateGetHeader
+#  define inflateInit           z_inflateInit
+#  define inflateInit2          z_inflateInit2
 #  define inflateInit2_         z_inflateInit2_
 #  define inflateInit_          z_inflateInit_
 #  define inflateMark           z_inflateMark
 #  define inflatePrime          z_inflatePrime
 #  define inflateReset          z_inflateReset
 #  define inflateReset2         z_inflateReset2
+#  define inflateResetKeep      z_inflateResetKeep
 #  define inflateSetDictionary  z_inflateSetDictionary
-#  define inflateGetDictionary  z_inflateGetDictionary
 #  define inflateSync           z_inflateSync
 #  define inflateSyncPoint      z_inflateSyncPoint
 #  define inflateUndermine      z_inflateUndermine
-#  define inflateResetKeep      z_inflateResetKeep
+#  define inflateValidate       z_inflateValidate
 #  define inflate_copyright     z_inflate_copyright
 #  define inflate_fast          z_inflate_fast
 #  define inflate_table         z_inflate_table
 #  ifndef Z_SOLO
 #    define uncompress            z_uncompress
+#    define uncompress2           z_uncompress2
 #  endif
 #  define zError                z_zError
 #  ifndef Z_SOLO
 #  define z_const
 #endif
 
-/* Some Mac compilers merge all .h files incorrectly: */
-#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
-#  define NO_DUMMY_DECL
+#ifdef Z_SOLO
+   typedef unsigned long z_size_t;
+#else
+#  define z_longlong long long
+#  if defined(NO_SIZE_T)
+     typedef unsigned NO_SIZE_T z_size_t;
+#  elif defined(STDC)
+#    include <stddef.h>
+     typedef size_t z_size_t;
+#  else
+     typedef unsigned long z_size_t;
+#  endif
+#  undef z_longlong
 #endif
 
 /* Maximum value for memLevel in deflateInit2 */
  Of course this will generally degrade compression (there's no free lunch).
 
    The memory requirements for inflate are (in bytes) 1 << windowBits
- that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
  for small objects.
 */
 
diff --git a/deps/libchdr/deps/zlib-1.2.11/zconf.h.cmakein b/deps/libchdr/deps/zlib-1.2.11/zconf.h.cmakein
new file mode 100644 (file)
index 0000000..a7f24cc
--- /dev/null
@@ -0,0 +1,536 @@
+/* zconf.h -- configuration of the zlib compression library
+ * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#ifndef ZCONF_H
+#define ZCONF_H
+#cmakedefine Z_PREFIX
+#cmakedefine Z_HAVE_UNISTD_H
+
+/*
+ * If you *really* need a unique prefix for all types and library functions,
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
+ * Even better than compiling with -DZ_PREFIX would be to use configure to set
+ * this permanently in zconf.h using "./configure --zprefix".
+ */
+#ifdef Z_PREFIX     /* may be set to #if 1 by ./configure */
+#  define Z_PREFIX_SET
+
+/* all linked symbols and init macros */
+#  define _dist_code            z__dist_code
+#  define _length_code          z__length_code
+#  define _tr_align             z__tr_align
+#  define _tr_flush_bits        z__tr_flush_bits
+#  define _tr_flush_block       z__tr_flush_block
+#  define _tr_init              z__tr_init
+#  define _tr_stored_block      z__tr_stored_block
+#  define _tr_tally             z__tr_tally
+#  define adler32               z_adler32
+#  define adler32_combine       z_adler32_combine
+#  define adler32_combine64     z_adler32_combine64
+#  define adler32_z             z_adler32_z
+#  ifndef Z_SOLO
+#    define compress              z_compress
+#    define compress2             z_compress2
+#    define compressBound         z_compressBound
+#  endif
+#  define crc32                 z_crc32
+#  define crc32_combine         z_crc32_combine
+#  define crc32_combine64       z_crc32_combine64
+#  define crc32_z               z_crc32_z
+#  define deflate               z_deflate
+#  define deflateBound          z_deflateBound
+#  define deflateCopy           z_deflateCopy
+#  define deflateEnd            z_deflateEnd
+#  define deflateGetDictionary  z_deflateGetDictionary
+#  define deflateInit           z_deflateInit
+#  define deflateInit2          z_deflateInit2
+#  define deflateInit2_         z_deflateInit2_
+#  define deflateInit_          z_deflateInit_
+#  define deflateParams         z_deflateParams
+#  define deflatePending        z_deflatePending
+#  define deflatePrime          z_deflatePrime
+#  define deflateReset          z_deflateReset
+#  define deflateResetKeep      z_deflateResetKeep
+#  define deflateSetDictionary  z_deflateSetDictionary
+#  define deflateSetHeader      z_deflateSetHeader
+#  define deflateTune           z_deflateTune
+#  define deflate_copyright     z_deflate_copyright
+#  define get_crc_table         z_get_crc_table
+#  ifndef Z_SOLO
+#    define gz_error              z_gz_error
+#    define gz_intmax             z_gz_intmax
+#    define gz_strwinerror        z_gz_strwinerror
+#    define gzbuffer              z_gzbuffer
+#    define gzclearerr            z_gzclearerr
+#    define gzclose               z_gzclose
+#    define gzclose_r             z_gzclose_r
+#    define gzclose_w             z_gzclose_w
+#    define gzdirect              z_gzdirect
+#    define gzdopen               z_gzdopen
+#    define gzeof                 z_gzeof
+#    define gzerror               z_gzerror
+#    define gzflush               z_gzflush
+#    define gzfread               z_gzfread
+#    define gzfwrite              z_gzfwrite
+#    define gzgetc                z_gzgetc
+#    define gzgetc_               z_gzgetc_
+#    define gzgets                z_gzgets
+#    define gzoffset              z_gzoffset
+#    define gzoffset64            z_gzoffset64
+#    define gzopen                z_gzopen
+#    define gzopen64              z_gzopen64
+#    ifdef _WIN32
+#      define gzopen_w              z_gzopen_w
+#    endif
+#    define gzprintf              z_gzprintf
+#    define gzputc                z_gzputc
+#    define gzputs                z_gzputs
+#    define gzread                z_gzread
+#    define gzrewind              z_gzrewind
+#    define gzseek                z_gzseek
+#    define gzseek64              z_gzseek64
+#    define gzsetparams           z_gzsetparams
+#    define gztell                z_gztell
+#    define gztell64              z_gztell64
+#    define gzungetc              z_gzungetc
+#    define gzvprintf             z_gzvprintf
+#    define gzwrite               z_gzwrite
+#  endif
+#  define inflate               z_inflate
+#  define inflateBack           z_inflateBack
+#  define inflateBackEnd        z_inflateBackEnd
+#  define inflateBackInit       z_inflateBackInit
+#  define inflateBackInit_      z_inflateBackInit_
+#  define inflateCodesUsed      z_inflateCodesUsed
+#  define inflateCopy           z_inflateCopy
+#  define inflateEnd            z_inflateEnd
+#  define inflateGetDictionary  z_inflateGetDictionary
+#  define inflateGetHeader      z_inflateGetHeader
+#  define inflateInit           z_inflateInit
+#  define inflateInit2          z_inflateInit2
+#  define inflateInit2_         z_inflateInit2_
+#  define inflateInit_          z_inflateInit_
+#  define inflateMark           z_inflateMark
+#  define inflatePrime          z_inflatePrime
+#  define inflateReset          z_inflateReset
+#  define inflateReset2         z_inflateReset2
+#  define inflateResetKeep      z_inflateResetKeep
+#  define inflateSetDictionary  z_inflateSetDictionary
+#  define inflateSync           z_inflateSync
+#  define inflateSyncPoint      z_inflateSyncPoint
+#  define inflateUndermine      z_inflateUndermine
+#  define inflateValidate       z_inflateValidate
+#  define inflate_copyright     z_inflate_copyright
+#  define inflate_fast          z_inflate_fast
+#  define inflate_table         z_inflate_table
+#  ifndef Z_SOLO
+#    define uncompress            z_uncompress
+#    define uncompress2           z_uncompress2
+#  endif
+#  define zError                z_zError
+#  ifndef Z_SOLO
+#    define zcalloc               z_zcalloc
+#    define zcfree                z_zcfree
+#  endif
+#  define zlibCompileFlags      z_zlibCompileFlags
+#  define zlibVersion           z_zlibVersion
+
+/* all zlib typedefs in zlib.h and zconf.h */
+#  define Byte                  z_Byte
+#  define Bytef                 z_Bytef
+#  define alloc_func            z_alloc_func
+#  define charf                 z_charf
+#  define free_func             z_free_func
+#  ifndef Z_SOLO
+#    define gzFile                z_gzFile
+#  endif
+#  define gz_header             z_gz_header
+#  define gz_headerp            z_gz_headerp
+#  define in_func               z_in_func
+#  define intf                  z_intf
+#  define out_func              z_out_func
+#  define uInt                  z_uInt
+#  define uIntf                 z_uIntf
+#  define uLong                 z_uLong
+#  define uLongf                z_uLongf
+#  define voidp                 z_voidp
+#  define voidpc                z_voidpc
+#  define voidpf                z_voidpf
+
+/* all zlib structs in zlib.h and zconf.h */
+#  define gz_header_s           z_gz_header_s
+#  define internal_state        z_internal_state
+
+#endif
+
+#if defined(__MSDOS__) && !defined(MSDOS)
+#  define MSDOS
+#endif
+#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
+#  define OS2
+#endif
+#if defined(_WINDOWS) && !defined(WINDOWS)
+#  define WINDOWS
+#endif
+#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
+#  ifndef WIN32
+#    define WIN32
+#  endif
+#endif
+#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
+#  if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
+#    ifndef SYS16BIT
+#      define SYS16BIT
+#    endif
+#  endif
+#endif
+
+/*
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
+ * than 64k bytes at a time (needed on systems with 16-bit int).
+ */
+#ifdef SYS16BIT
+#  define MAXSEG_64K
+#endif
+#ifdef MSDOS
+#  define UNALIGNED_OK
+#endif
+
+#ifdef __STDC_VERSION__
+#  ifndef STDC
+#    define STDC
+#  endif
+#  if __STDC_VERSION__ >= 199901L
+#    ifndef STDC99
+#      define STDC99
+#    endif
+#  endif
+#endif
+#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
+#  define STDC
+#endif
+#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
+#  define STDC
+#endif
+#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
+#  define STDC
+#endif
+#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
+#  define STDC
+#endif
+
+#if defined(__OS400__) && !defined(STDC)    /* iSeries (formerly AS/400). */
+#  define STDC
+#endif
+
+#ifndef STDC
+#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
+#    define const       /* note: need a more gentle solution here */
+#  endif
+#endif
+
+#if defined(ZLIB_CONST) && !defined(z_const)
+#  define z_const const
+#else
+#  define z_const
+#endif
+
+#ifdef Z_SOLO
+   typedef unsigned long z_size_t;
+#else
+#  define z_longlong long long
+#  if defined(NO_SIZE_T)
+     typedef unsigned NO_SIZE_T z_size_t;
+#  elif defined(STDC)
+#    include <stddef.h>
+     typedef size_t z_size_t;
+#  else
+     typedef unsigned long z_size_t;
+#  endif
+#  undef z_longlong
+#endif
+
+/* Maximum value for memLevel in deflateInit2 */
+#ifndef MAX_MEM_LEVEL
+#  ifdef MAXSEG_64K
+#    define MAX_MEM_LEVEL 8
+#  else
+#    define MAX_MEM_LEVEL 9
+#  endif
+#endif
+
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
+ * created by gzip. (Files created by minigzip can still be extracted by
+ * gzip.)
+ */
+#ifndef MAX_WBITS
+#  define MAX_WBITS   15 /* 32K LZ77 window */
+#endif
+
+/* The memory requirements for deflate are (in bytes):
+            (1 << (windowBits+2)) +  (1 << (memLevel+9))
+ that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
+ plus a few kilobytes for small objects. For example, if you want to reduce
+ the default memory requirements from 256K to 128K, compile with
+     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
+ Of course this will generally degrade compression (there's no free lunch).
+
+   The memory requirements for inflate are (in bytes) 1 << windowBits
+ that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
+ for small objects.
+*/
+
+                        /* Type declarations */
+
+#ifndef OF /* function prototypes */
+#  ifdef STDC
+#    define OF(args)  args
+#  else
+#    define OF(args)  ()
+#  endif
+#endif
+
+#ifndef Z_ARG /* function prototypes for stdarg */
+#  if defined(STDC) || defined(Z_HAVE_STDARG_H)
+#    define Z_ARG(args)  args
+#  else
+#    define Z_ARG(args)  ()
+#  endif
+#endif
+
+/* The following definitions for FAR are needed only for MSDOS mixed
+ * model programming (small or medium model with some far allocations).
+ * This was tested only with MSC; for other MSDOS compilers you may have
+ * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
+ * just define FAR to be empty.
+ */
+#ifdef SYS16BIT
+#  if defined(M_I86SM) || defined(M_I86MM)
+     /* MSC small or medium model */
+#    define SMALL_MEDIUM
+#    ifdef _MSC_VER
+#      define FAR _far
+#    else
+#      define FAR far
+#    endif
+#  endif
+#  if (defined(__SMALL__) || defined(__MEDIUM__))
+     /* Turbo C small or medium model */
+#    define SMALL_MEDIUM
+#    ifdef __BORLANDC__
+#      define FAR _far
+#    else
+#      define FAR far
+#    endif
+#  endif
+#endif
+
+#if defined(WINDOWS) || defined(WIN32)
+   /* If building or using zlib as a DLL, define ZLIB_DLL.
+    * This is not mandatory, but it offers a little performance increase.
+    */
+#  ifdef ZLIB_DLL
+#    if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
+#      ifdef ZLIB_INTERNAL
+#        define ZEXTERN extern __declspec(dllexport)
+#      else
+#        define ZEXTERN extern __declspec(dllimport)
+#      endif
+#    endif
+#  endif  /* ZLIB_DLL */
+   /* If building or using zlib with the WINAPI/WINAPIV calling convention,
+    * define ZLIB_WINAPI.
+    * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
+    */
+#  ifdef ZLIB_WINAPI
+#    ifdef FAR
+#      undef FAR
+#    endif
+#    include <windows.h>
+     /* No need for _export, use ZLIB.DEF instead. */
+     /* For complete Windows compatibility, use WINAPI, not __stdcall. */
+#    define ZEXPORT WINAPI
+#    ifdef WIN32
+#      define ZEXPORTVA WINAPIV
+#    else
+#      define ZEXPORTVA FAR CDECL
+#    endif
+#  endif
+#endif
+
+#if defined (__BEOS__)
+#  ifdef ZLIB_DLL
+#    ifdef ZLIB_INTERNAL
+#      define ZEXPORT   __declspec(dllexport)
+#      define ZEXPORTVA __declspec(dllexport)
+#    else
+#      define ZEXPORT   __declspec(dllimport)
+#      define ZEXPORTVA __declspec(dllimport)
+#    endif
+#  endif
+#endif
+
+#ifndef ZEXTERN
+#  define ZEXTERN extern
+#endif
+#ifndef ZEXPORT
+#  define ZEXPORT
+#endif
+#ifndef ZEXPORTVA
+#  define ZEXPORTVA
+#endif
+
+#ifndef FAR
+#  define FAR
+#endif
+
+#if !defined(__MACTYPES__)
+typedef unsigned char  Byte;  /* 8 bits */
+#endif
+typedef unsigned int   uInt;  /* 16 bits or more */
+typedef unsigned long  uLong; /* 32 bits or more */
+
+#ifdef SMALL_MEDIUM
+   /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
+#  define Bytef Byte FAR
+#else
+   typedef Byte  FAR Bytef;
+#endif
+typedef char  FAR charf;
+typedef int   FAR intf;
+typedef uInt  FAR uIntf;
+typedef uLong FAR uLongf;
+
+#ifdef STDC
+   typedef void const *voidpc;
+   typedef void FAR   *voidpf;
+   typedef void       *voidp;
+#else
+   typedef Byte const *voidpc;
+   typedef Byte FAR   *voidpf;
+   typedef Byte       *voidp;
+#endif
+
+#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
+#  include <limits.h>
+#  if (UINT_MAX == 0xffffffffUL)
+#    define Z_U4 unsigned
+#  elif (ULONG_MAX == 0xffffffffUL)
+#    define Z_U4 unsigned long
+#  elif (USHRT_MAX == 0xffffffffUL)
+#    define Z_U4 unsigned short
+#  endif
+#endif
+
+#ifdef Z_U4
+   typedef Z_U4 z_crc_t;
+#else
+   typedef unsigned long z_crc_t;
+#endif
+
+#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
+#  define Z_HAVE_UNISTD_H
+#endif
+
+#ifdef HAVE_STDARG_H    /* may be set to #if 1 by ./configure */
+#  define Z_HAVE_STDARG_H
+#endif
+
+#ifdef STDC
+#  ifndef Z_SOLO
+#    include <sys/types.h>      /* for off_t */
+#  endif
+#endif
+
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
+#  ifndef Z_SOLO
+#    include <stdarg.h>         /* for va_list */
+#  endif
+#endif
+
+#ifdef _WIN32
+#  ifndef Z_SOLO
+#    include <stddef.h>         /* for wchar_t */
+#  endif
+#endif
+
+/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
+ * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
+ * though the former does not conform to the LFS document), but considering
+ * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
+ * equivalently requesting no 64-bit operations
+ */
+#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
+#  undef _LARGEFILE64_SOURCE
+#endif
+
+#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
+#  define Z_HAVE_UNISTD_H
+#endif
+#ifndef Z_SOLO
+#  if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
+#    include <unistd.h>         /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
+#    ifdef VMS
+#      include <unixio.h>       /* for off_t */
+#    endif
+#    ifndef z_off_t
+#      define z_off_t off_t
+#    endif
+#  endif
+#endif
+
+#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
+#  define Z_LFS64
+#endif
+
+#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
+#  define Z_LARGE64
+#endif
+
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
+#  define Z_WANT64
+#endif
+
+#if !defined(SEEK_SET) && !defined(Z_SOLO)
+#  define SEEK_SET        0       /* Seek from beginning of file.  */
+#  define SEEK_CUR        1       /* Seek from current position.  */
+#  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
+#endif
+
+#ifndef z_off_t
+#  define z_off_t long
+#endif
+
+#if !defined(_WIN32) && defined(Z_LARGE64)
+#  define z_off64_t off64_t
+#else
+#  if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
+#    define z_off64_t __int64
+#  else
+#    define z_off64_t z_off_t
+#  endif
+#endif
+
+/* MVS linker does not support external names larger than 8 bytes */
+#if defined(__MVS__)
+  #pragma map(deflateInit_,"DEIN")
+  #pragma map(deflateInit2_,"DEIN2")
+  #pragma map(deflateEnd,"DEEND")
+  #pragma map(deflateBound,"DEBND")
+  #pragma map(inflateInit_,"ININ")
+  #pragma map(inflateInit2_,"ININ2")
+  #pragma map(inflateEnd,"INEND")
+  #pragma map(inflateSync,"INSY")
+  #pragma map(inflateSetDictionary,"INSEDI")
+  #pragma map(compressBound,"CMBND")
+  #pragma map(inflate_table,"INTABL")
+  #pragma map(inflate_fast,"INFA")
+  #pragma map(inflate_copyright,"INCOPY")
+#endif
+
+#endif /* ZCONF_H */
similarity index 93%
rename from deps/zlib/zconf.h.in
rename to deps/libchdr/deps/zlib-1.2.11/zconf.h.in
index 9987a77..5e1d68a 100644 (file)
@@ -1,5 +1,5 @@
 /* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-2013 Jean-loup Gailly.
+ * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -17,7 +17,7 @@
 #ifdef Z_PREFIX     /* may be set to #if 1 by ./configure */
 #  define Z_PREFIX_SET
 
-/* all linked symbols */
+/* all linked symbols and init macros */
 #  define _dist_code            z__dist_code
 #  define _length_code          z__length_code
 #  define _tr_align             z__tr_align
@@ -29,6 +29,7 @@
 #  define adler32               z_adler32
 #  define adler32_combine       z_adler32_combine
 #  define adler32_combine64     z_adler32_combine64
+#  define adler32_z             z_adler32_z
 #  ifndef Z_SOLO
 #    define compress              z_compress
 #    define compress2             z_compress2
 #  define crc32                 z_crc32
 #  define crc32_combine         z_crc32_combine
 #  define crc32_combine64       z_crc32_combine64
+#  define crc32_z               z_crc32_z
 #  define deflate               z_deflate
 #  define deflateBound          z_deflateBound
 #  define deflateCopy           z_deflateCopy
 #  define deflateEnd            z_deflateEnd
+#  define deflateGetDictionary  z_deflateGetDictionary
+#  define deflateInit           z_deflateInit
+#  define deflateInit2          z_deflateInit2
 #  define deflateInit2_         z_deflateInit2_
 #  define deflateInit_          z_deflateInit_
 #  define deflateParams         z_deflateParams
@@ -67,6 +72,8 @@
 #    define gzeof                 z_gzeof
 #    define gzerror               z_gzerror
 #    define gzflush               z_gzflush
+#    define gzfread               z_gzfread
+#    define gzfwrite              z_gzfwrite
 #    define gzgetc                z_gzgetc
 #    define gzgetc_               z_gzgetc_
 #    define gzgets                z_gzgets
@@ -78,7 +85,6 @@
 #      define gzopen_w              z_gzopen_w
 #    endif
 #    define gzprintf              z_gzprintf
-#    define gzvprintf             z_gzvprintf
 #    define gzputc                z_gzputc
 #    define gzputs                z_gzputs
 #    define gzread                z_gzread
 #    define gztell                z_gztell
 #    define gztell64              z_gztell64
 #    define gzungetc              z_gzungetc
+#    define gzvprintf             z_gzvprintf
 #    define gzwrite               z_gzwrite
 #  endif
 #  define inflate               z_inflate
 #  define inflateBack           z_inflateBack
 #  define inflateBackEnd        z_inflateBackEnd
+#  define inflateBackInit       z_inflateBackInit
 #  define inflateBackInit_      z_inflateBackInit_
+#  define inflateCodesUsed      z_inflateCodesUsed
 #  define inflateCopy           z_inflateCopy
 #  define inflateEnd            z_inflateEnd
+#  define inflateGetDictionary  z_inflateGetDictionary
 #  define inflateGetHeader      z_inflateGetHeader
+#  define inflateInit           z_inflateInit
+#  define inflateInit2          z_inflateInit2
 #  define inflateInit2_         z_inflateInit2_
 #  define inflateInit_          z_inflateInit_
 #  define inflateMark           z_inflateMark
 #  define inflatePrime          z_inflatePrime
 #  define inflateReset          z_inflateReset
 #  define inflateReset2         z_inflateReset2
+#  define inflateResetKeep      z_inflateResetKeep
 #  define inflateSetDictionary  z_inflateSetDictionary
-#  define inflateGetDictionary  z_inflateGetDictionary
 #  define inflateSync           z_inflateSync
 #  define inflateSyncPoint      z_inflateSyncPoint
 #  define inflateUndermine      z_inflateUndermine
-#  define inflateResetKeep      z_inflateResetKeep
+#  define inflateValidate       z_inflateValidate
 #  define inflate_copyright     z_inflate_copyright
 #  define inflate_fast          z_inflate_fast
 #  define inflate_table         z_inflate_table
 #  ifndef Z_SOLO
 #    define uncompress            z_uncompress
+#    define uncompress2           z_uncompress2
 #  endif
 #  define zError                z_zError
 #  ifndef Z_SOLO
 #  define z_const
 #endif
 
-/* Some Mac compilers merge all .h files incorrectly: */
-#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
-#  define NO_DUMMY_DECL
+#ifdef Z_SOLO
+   typedef unsigned long z_size_t;
+#else
+#  define z_longlong long long
+#  if defined(NO_SIZE_T)
+     typedef unsigned NO_SIZE_T z_size_t;
+#  elif defined(STDC)
+#    include <stddef.h>
+     typedef size_t z_size_t;
+#  else
+     typedef unsigned long z_size_t;
+#  endif
+#  undef z_longlong
 #endif
 
 /* Maximum value for memLevel in deflateInit2 */
  Of course this will generally degrade compression (there's no free lunch).
 
    The memory requirements for inflate are (in bytes) 1 << windowBits
- that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
  for small objects.
 */
 
diff --git a/deps/libchdr/deps/zlib-1.2.11/zlib.3 b/deps/libchdr/deps/zlib-1.2.11/zlib.3
new file mode 100644 (file)
index 0000000..bda4eb0
--- /dev/null
@@ -0,0 +1,149 @@
+.TH ZLIB 3 "15 Jan 2017"
+.SH NAME
+zlib \- compression/decompression library
+.SH SYNOPSIS
+[see
+.I zlib.h
+for full description]
+.SH DESCRIPTION
+The
+.I zlib
+library is a general purpose data compression library.
+The code is thread safe, assuming that the standard library functions
+used are thread safe, such as memory allocation routines.
+It provides in-memory compression and decompression functions,
+including integrity checks of the uncompressed data.
+This version of the library supports only one compression method (deflation)
+but other algorithms may be added later
+with the same stream interface.
+.LP
+Compression can be done in a single step if the buffers are large enough
+or can be done by repeated calls of the compression function.
+In the latter case,
+the application must provide more input and/or consume the output
+(providing more output space) before each call.
+.LP
+The library also supports reading and writing files in
+.IR gzip (1)
+(.gz) format
+with an interface similar to that of stdio.
+.LP
+The library does not install any signal handler.
+The decoder checks the consistency of the compressed data,
+so the library should never crash even in the case of corrupted input.
+.LP
+All functions of the compression library are documented in the file
+.IR zlib.h .
+The distribution source includes examples of use of the library
+in the files
+.I test/example.c
+and
+.IR test/minigzip.c,
+as well as other examples in the
+.IR examples/
+directory.
+.LP
+Changes to this version are documented in the file
+.I ChangeLog
+that accompanies the source.
+.LP
+.I zlib
+is built in to many languages and operating systems, including but not limited to
+Java, Python, .NET, PHP, Perl, Ruby, Swift, and Go.
+.LP
+An experimental package to read and write files in the .zip format,
+written on top of
+.I zlib
+by Gilles Vollant (info@winimage.com),
+is available at:
+.IP
+http://www.winimage.com/zLibDll/minizip.html
+and also in the
+.I contrib/minizip
+directory of the main
+.I zlib
+source distribution.
+.SH "SEE ALSO"
+The
+.I zlib
+web site can be found at:
+.IP
+http://zlib.net/
+.LP
+The data format used by the
+.I zlib
+library is described by RFC
+(Request for Comments) 1950 to 1952 in the files:
+.IP
+http://tools.ietf.org/html/rfc1950 (for the zlib header and trailer format)
+.br
+http://tools.ietf.org/html/rfc1951 (for the deflate compressed data format)
+.br
+http://tools.ietf.org/html/rfc1952 (for the gzip header and trailer format)
+.LP
+Mark Nelson wrote an article about
+.I zlib
+for the Jan. 1997 issue of  Dr. Dobb's Journal;
+a copy of the article is available at:
+.IP
+http://marknelson.us/1997/01/01/zlib-engine/
+.SH "REPORTING PROBLEMS"
+Before reporting a problem,
+please check the
+.I zlib
+web site to verify that you have the latest version of
+.IR zlib ;
+otherwise,
+obtain the latest version and see if the problem still exists.
+Please read the
+.I zlib
+FAQ at:
+.IP
+http://zlib.net/zlib_faq.html
+.LP
+before asking for help.
+Send questions and/or comments to zlib@gzip.org,
+or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
+.SH AUTHORS AND LICENSE
+Version 1.2.11
+.LP
+Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
+.LP
+This software is provided 'as-is', without any express or implied
+warranty.  In no event will the authors be held liable for any damages
+arising from the use of this software.
+.LP
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+.LP
+.nr step 1 1
+.IP \n[step]. 3
+The origin of this software must not be misrepresented; you must not
+claim that you wrote the original software. If you use this software
+in a product, an acknowledgment in the product documentation would be
+appreciated but is not required.
+.IP \n+[step].
+Altered source versions must be plainly marked as such, and must not be
+misrepresented as being the original software.
+.IP \n+[step].
+This notice may not be removed or altered from any source distribution.
+.LP
+Jean-loup Gailly        Mark Adler
+.br
+jloup@gzip.org          madler@alumni.caltech.edu
+.LP
+The deflate format used by
+.I zlib
+was defined by Phil Katz.
+The deflate and
+.I zlib
+specifications were written by L. Peter Deutsch.
+Thanks to all the people who reported problems and suggested various
+improvements in
+.IR zlib ;
+who are too numerous to cite here.
+.LP
+UNIX manual page by R. P. C. Rodgers,
+U.S. National Library of Medicine (rodgers@nlm.nih.gov).
+.\" end of man page
diff --git a/deps/libchdr/deps/zlib-1.2.11/zlib.3.pdf b/deps/libchdr/deps/zlib-1.2.11/zlib.3.pdf
new file mode 100644 (file)
index 0000000..6fa519c
Binary files /dev/null and b/deps/libchdr/deps/zlib-1.2.11/zlib.3.pdf differ
similarity index 81%
rename from deps/zlib/zlib.h
rename to deps/libchdr/deps/zlib-1.2.11/zlib.h
index aa5935d..f09cdaf 100644 (file)
@@ -1,7 +1,7 @@
 /* zlib.h -- interface of the 'zlib' general purpose compression library
-  version 1.2.8, April 28th, 2013
+  version 1.2.11, January 15th, 2017
 
-  Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
+  Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
 extern "C" {
 #endif
 
-#define ZLIB_VERSION "1.2.8"
-#define ZLIB_VERNUM 0x1280
+#define ZLIB_VERSION "1.2.11"
+#define ZLIB_VERNUM 0x12b0
 #define ZLIB_VER_MAJOR 1
 #define ZLIB_VER_MINOR 2
-#define ZLIB_VER_REVISION 8
+#define ZLIB_VER_REVISION 11
 #define ZLIB_VER_SUBREVISION 0
 
 /*
@@ -65,7 +65,8 @@ extern "C" {
   with "gz".  The gzip format is different from the zlib format.  gzip is a
   gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
 
-    This library can optionally read and write gzip streams in memory as well.
+    This library can optionally read and write gzip and raw deflate streams in
+  memory as well.
 
     The zlib format was designed to be compact and fast for use in memory
   and on communications channels.  The gzip format was designed for single-
@@ -74,7 +75,7 @@ extern "C" {
 
     The library does not install any signal handler.  The decoder checks
   the consistency of the compressed data, so the library should never crash
-  even in case of corrupted input.
+  even in the case of corrupted input.
 */
 
 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
@@ -87,19 +88,20 @@ typedef struct z_stream_s {
     uInt     avail_in;  /* number of bytes available at next_in */
     uLong    total_in;  /* total number of input bytes read so far */
 
-    Bytef    *next_out; /* next output byte should be put there */
+    Bytef    *next_out; /* next output byte will go here */
     uInt     avail_out; /* remaining free space at next_out */
     uLong    total_out; /* total number of bytes output so far */
 
     z_const char *msg;  /* last error message, NULL if no error */
-    void *state; /* not visible by applications */
+    struct internal_state FAR *state; /* not visible by applications */
 
     alloc_func zalloc;  /* used to allocate the internal state */
     free_func  zfree;   /* used to free the internal state */
     voidpf     opaque;  /* private data object passed to zalloc and zfree */
 
-    int     data_type;  /* best guess about the data type: binary or text */
-    uLong   adler;      /* adler32 value of the uncompressed data */
+    int     data_type;  /* best guess about the data type: binary or text
+                           for deflate, or the decoding state for inflate */
+    uLong   adler;      /* Adler-32 or CRC-32 value of the uncompressed data */
     uLong   reserved;   /* reserved for future use */
 } z_stream;
 
@@ -142,7 +144,9 @@ typedef gz_header FAR *gz_headerp;
 
      zalloc must return Z_NULL if there is not enough memory for the object.
    If zlib is used in a multi-threaded application, zalloc and zfree must be
-   thread safe.
+   thread safe.  In that case, zlib is thread-safe.  When zalloc and zfree are
+   Z_NULL on entry to the initialization function, they are set to internal
+   routines that use the standard library functions malloc() and free().
 
      On 16-bit systems, the functions zalloc and zfree must be able to allocate
    exactly 65536 bytes, but will not be required to allocate more than this if
@@ -155,7 +159,7 @@ typedef gz_header FAR *gz_headerp;
 
      The fields total_in and total_out can be used for statistics or progress
    reports.  After compression, total_in holds the total size of the
-   uncompressed data and may be saved for use in the decompressor (particularly
+   uncompressed data and may be saved for use by the decompressor (particularly
    if the decompressor wants to decompress everything in a single step).
 */
 
@@ -200,7 +204,7 @@ typedef gz_header FAR *gz_headerp;
 #define Z_TEXT     1
 #define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
 #define Z_UNKNOWN  2
-/* Possible values of the data_type field (though see inflate()) */
+/* Possible values of the data_type field for deflate() */
 
 #define Z_DEFLATED   8
 /* The deflate compression method (the only one supported in this version) */
@@ -258,11 +262,11 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
     enough room in the output buffer), next_in and avail_in are updated and
     processing will resume at this point for the next call of deflate().
 
-  - Provide more output starting at next_out and update next_out and avail_out
+  - Generate more output starting at next_out and update next_out and avail_out
     accordingly.  This action is forced if the parameter flush is non zero.
     Forcing flush frequently degrades the compression ratio, so this parameter
-    should be set only when necessary (in interactive applications).  Some
-    output may be provided even if flush is not set.
+    should be set only when necessary.  Some output may be provided even if
+    flush is zero.
 
     Before the call of deflate(), the application should ensure that at least
   one of the actions is possible, by providing more input and/or consuming more
@@ -271,7 +275,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
   output when it wants, for example when the output buffer is full (avail_out
   == 0), or after each call of deflate().  If deflate returns Z_OK and with
   zero avail_out, it must be called again after making room in the output
-  buffer because there might be more output pending.
+  buffer because there might be more output pending. See deflatePending(),
+  which can be used if desired to determine whether or not there is more ouput
+  in that case.
 
     Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
   decide how much data to accumulate before producing output, in order to
@@ -292,8 +298,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
   input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
   This completes the current deflate block and follows it with an empty fixed
   codes block that is 10 bits long.  This assures that enough bytes are output
-  in order for the decompressor to finish the block before the empty fixed code
-  block.
+  in order for the decompressor to finish the block before the empty fixed
+  codes block.
 
     If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
   for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
@@ -319,34 +325,38 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
 
     If the parameter flush is set to Z_FINISH, pending input is processed,
   pending output is flushed and deflate returns with Z_STREAM_END if there was
-  enough output space; if deflate returns with Z_OK, this function must be
-  called again with Z_FINISH and more output space (updated avail_out) but no
-  more input data, until it returns with Z_STREAM_END or an error.  After
-  deflate has returned Z_STREAM_END, the only possible operations on the stream
-  are deflateReset or deflateEnd.
-
-    Z_FINISH can be used immediately after deflateInit if all the compression
-  is to be done in a single step.  In this case, avail_out must be at least the
-  value returned by deflateBound (see below).  Then deflate is guaranteed to
-  return Z_STREAM_END.  If not enough output space is provided, deflate will
-  not return Z_STREAM_END, and it must be called again as described above.
-
-    deflate() sets strm->adler to the adler32 checksum of all input read
-  so far (that is, total_in bytes).
+  enough output space.  If deflate returns with Z_OK or Z_BUF_ERROR, this
+  function must be called again with Z_FINISH and more output space (updated
+  avail_out) but no more input data, until it returns with Z_STREAM_END or an
+  error.  After deflate has returned Z_STREAM_END, the only possible operations
+  on the stream are deflateReset or deflateEnd.
+
+    Z_FINISH can be used in the first deflate call after deflateInit if all the
+  compression is to be done in a single step.  In order to complete in one
+  call, avail_out must be at least the value returned by deflateBound (see
+  below).  Then deflate is guaranteed to return Z_STREAM_END.  If not enough
+  output space is provided, deflate will not return Z_STREAM_END, and it must
+  be called again as described above.
+
+    deflate() sets strm->adler to the Adler-32 checksum of all input read
+  so far (that is, total_in bytes).  If a gzip stream is being generated, then
+  strm->adler will be the CRC-32 checksum of the input read so far.  (See
+  deflateInit2 below.)
 
     deflate() may update strm->data_type if it can make a good guess about
-  the input data type (Z_BINARY or Z_TEXT).  In doubt, the data is considered
-  binary.  This field is only for information purposes and does not affect the
-  compression algorithm in any manner.
+  the input data type (Z_BINARY or Z_TEXT).  If in doubt, the data is
+  considered binary.  This field is only for information purposes and does not
+  affect the compression algorithm in any manner.
 
     deflate() returns Z_OK if some progress has been made (more input
   processed or more output produced), Z_STREAM_END if all input has been
   consumed and all output has been produced (only when flush is set to
   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
-  if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
-  (for example avail_in or avail_out was zero).  Note that Z_BUF_ERROR is not
-  fatal, and deflate() can be called again with more input and more output
-  space to continue compressing.
+  if next_in or next_out was Z_NULL or the state was inadvertently written over
+  by the application), or Z_BUF_ERROR if no progress is possible (for example
+  avail_in or avail_out was zero).  Note that Z_BUF_ERROR is not fatal, and
+  deflate() can be called again with more input and more output space to
+  continue compressing.
 */
 
 
@@ -369,23 +379,21 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
 
      Initializes the internal stream state for decompression.  The fields
    next_in, avail_in, zalloc, zfree and opaque must be initialized before by
-   the caller.  If next_in is not Z_NULL and avail_in is large enough (the
-   exact value depends on the compression method), inflateInit determines the
-   compression method from the zlib header and allocates all data structures
-   accordingly; otherwise the allocation will be deferred to the first call of
-   inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to
-   use default allocation functions.
+   the caller.  In the current version of inflate, the provided input is not
+   read or consumed.  The allocation of a sliding window will be deferred to
+   the first call of inflate (if the decompression does not complete on the
+   first call).  If zalloc and zfree are set to Z_NULL, inflateInit updates
+   them to use default allocation functions.
 
      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
    memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
    version assumed by the caller, or Z_STREAM_ERROR if the parameters are
    invalid, such as a null pointer to the structure.  msg is set to null if
-   there is no error message.  inflateInit does not perform any decompression
-   apart from possibly reading the zlib header if present: actual decompression
-   will be done by inflate().  (So next_in and avail_in may be modified, but
-   next_out and avail_out are unused and unchanged.) The current implementation
-   of inflateInit() does not process any header information -- that is deferred
-   until inflate() is called.
+   there is no error message.  inflateInit does not perform any decompression.
+   Actual decompression will be done by inflate().  So next_in, and avail_in,
+   next_out, and avail_out are unused and unchanged.  The current
+   implementation of inflateInit() does not process any header information --
+   that is deferred until inflate() is called.
 */
 
 
@@ -401,17 +409,20 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
 
   - Decompress more input starting at next_in and update next_in and avail_in
     accordingly.  If not all input can be processed (because there is not
-    enough room in the output buffer), next_in is updated and processing will
-    resume at this point for the next call of inflate().
+    enough room in the output buffer), then next_in and avail_in are updated
+    accordingly, and processing will resume at this point for the next call of
+    inflate().
 
-  - Provide more output starting at next_out and update next_out and avail_out
+  - Generate more output starting at next_out and update next_out and avail_out
     accordingly.  inflate() provides as much output as possible, until there is
     no more input data or no more space in the output buffer (see below about
     the flush parameter).
 
     Before the call of inflate(), the application should ensure that at least
   one of the actions is possible, by providing more input and/or consuming more
-  output, and updating the next_* and avail_* values accordingly.  The
+  output, and updating the next_* and avail_* values accordingly.  If the
+  caller of inflate() does not provide both available input and available
+  output space, it is possible that there will be no progress made.  The
   application can consume the uncompressed output when it wants, for example
   when the output buffer is full (avail_out == 0), or after each call of
   inflate().  If inflate returns Z_OK and with zero avail_out, it must be
@@ -428,7 +439,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
   gets to the end of that block, or when it runs out of data.
 
     The Z_BLOCK option assists in appending to or combining deflate streams.
-  Also to assist in this, on return inflate() will set strm->data_type to the
+  To assist in this, on return inflate() always sets strm->data_type to the
   number of unused bits in the last byte taken from strm->next_in, plus 64 if
   inflate() is currently decoding the last block in the deflate stream, plus
   128 if inflate() returned immediately after decoding an end-of-block code or
@@ -454,7 +465,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
   this case all pending input is processed and all pending output is flushed;
   avail_out must be large enough to hold all of the uncompressed data for the
   operation to complete.  (The size of the uncompressed data may have been
-  saved by the compressor for this purpose.) The use of Z_FINISH is not
+  saved by the compressor for this purpose.)  The use of Z_FINISH is not
   required to perform an inflation in one step.  However it may be used to
   inform inflate that a faster approach can be used for the single inflate()
   call.  Z_FINISH also informs inflate to not maintain a sliding window if the
@@ -476,32 +487,33 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
   chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
   strm->adler to the Adler-32 checksum of all output produced so far (that is,
   total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
-  below.  At the end of the stream, inflate() checks that its computed adler32
+  below.  At the end of the stream, inflate() checks that its computed Adler-32
   checksum is equal to that saved by the compressor and returns Z_STREAM_END
   only if the checksum is correct.
 
     inflate() can decompress and check either zlib-wrapped or gzip-wrapped
   deflate data.  The header type is detected automatically, if requested when
   initializing with inflateInit2().  Any information contained in the gzip
-  header is not retained, so applications that need that information should
-  instead use raw inflate, see inflateInit2() below, or inflateBack() and
-  perform their own processing of the gzip header and trailer.  When processing
+  header is not retained unless inflateGetHeader() is used.  When processing
   gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
-  producted so far.  The CRC-32 is checked against the gzip trailer.
+  produced so far.  The CRC-32 is checked against the gzip trailer, as is the
+  uncompressed length, modulo 2^32.
 
     inflate() returns Z_OK if some progress has been made (more input processed
   or more output produced), Z_STREAM_END if the end of the compressed data has
   been reached and all uncompressed output has been produced, Z_NEED_DICT if a
   preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
   corrupted (input stream not conforming to the zlib format or incorrect check
-  value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
-  next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
-  Z_BUF_ERROR if no progress is possible or if there was not enough room in the
-  output buffer when Z_FINISH is used.  Note that Z_BUF_ERROR is not fatal, and
+  value, in which case strm->msg points to a string with a more specific
+  error), Z_STREAM_ERROR if the stream structure was inconsistent (for example
+  next_in or next_out was Z_NULL, or the state was inadvertently written over
+  by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR
+  if no progress was possible or if there was not enough room in the output
+  buffer when Z_FINISH is used.  Note that Z_BUF_ERROR is not fatal, and
   inflate() can be called again with more input and more output space to
   continue decompressing.  If Z_DATA_ERROR is returned, the application may
   then call inflateSync() to look for a good compression block if a partial
-  recovery of the data is desired.
+  recovery of the data is to be attempted.
 */
 
 
@@ -511,9 +523,8 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
    This function discards any unprocessed input and does not flush any pending
    output.
 
-     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
-   was inconsistent.  In the error case, msg may be set but then points to a
-   static string (which must not be deallocated).
+     inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state
+   was inconsistent.
 */
 
 
@@ -544,16 +555,29 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
    compression at the expense of memory usage.  The default value is 15 if
    deflateInit is used instead.
 
+     For the current implementation of deflate(), a windowBits value of 8 (a
+   window size of 256 bytes) is not supported.  As a result, a request for 8
+   will result in 9 (a 512-byte window).  In that case, providing 8 to
+   inflateInit2() will result in an error when the zlib header with 9 is
+   checked against the initialization of inflate().  The remedy is to not use 8
+   with deflateInit2() with this initialization, or at least in that case use 9
+   with inflateInit2().
+
      windowBits can also be -8..-15 for raw deflate.  In this case, -windowBits
    determines the window size.  deflate() will then generate raw deflate data
-   with no zlib header or trailer, and will not compute an adler32 check value.
+   with no zlib header or trailer, and will not compute a check value.
 
      windowBits can also be greater than 15 for optional gzip encoding.  Add
    16 to windowBits to write a simple gzip header and trailer around the
    compressed data instead of a zlib wrapper.  The gzip header will have no
    file name, no extra data, no comment, no modification time (set to zero), no
-   header crc, and the operating system will be set to 255 (unknown).  If a
-   gzip stream is being written, strm->adler is a crc32 instead of an adler32.
+   header crc, and the operating system will be set to the appropriate value,
+   if the operating system was determined at compile time.  If a gzip stream is
+   being written, strm->adler is a CRC-32 instead of an Adler-32.
+
+     For raw deflate or gzip encoding, a request for a 256-byte window is
+   rejected as invalid, since only the zlib header provides a means of
+   transmitting the window size to the decompressor.
 
      The memLevel parameter specifies how much memory should be allocated
    for the internal compression state.  memLevel=1 uses minimum memory but is
@@ -614,12 +638,12 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
    addition, the current implementation of deflate will use at most the window
    size minus 262 bytes of the provided dictionary.
 
-     Upon return of this function, strm->adler is set to the adler32 value
+     Upon return of this function, strm->adler is set to the Adler-32 value
    of the dictionary; the decompressor may later use this value to determine
-   which dictionary has been used by the compressor.  (The adler32 value
+   which dictionary has been used by the compressor.  (The Adler-32 value
    applies to the whole dictionary even if only a subset of the dictionary is
    actually used by the compressor.) If a raw deflate was requested, then the
-   adler32 value is not computed and strm->adler is not set.
+   Adler-32 value is not computed and strm->adler is not set.
 
      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
    parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
@@ -628,6 +652,28 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
    not perform any compression: this will be done by deflate().
 */
 
+ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm,
+                                             Bytef *dictionary,
+                                             uInt  *dictLength));
+/*
+     Returns the sliding dictionary being maintained by deflate.  dictLength is
+   set to the number of bytes in the dictionary, and that many bytes are copied
+   to dictionary.  dictionary must have enough space, where 32768 bytes is
+   always enough.  If deflateGetDictionary() is called with dictionary equal to
+   Z_NULL, then only the dictionary length is returned, and nothing is copied.
+   Similary, if dictLength is Z_NULL, then it is not set.
+
+     deflateGetDictionary() may return a length less than the window size, even
+   when more than the window size in input has been provided. It may return up
+   to 258 bytes less in that case, due to how zlib's implementation of deflate
+   manages the sliding window and lookahead for matches, where matches can be
+   up to 258 bytes long. If the application needs the last window-size bytes of
+   input, then that would need to be saved by the application outside of zlib.
+
+     deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
+   stream state is inconsistent.
+*/
+
 ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
                                     z_streamp source));
 /*
@@ -648,10 +694,10 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
 
 ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
 /*
-     This function is equivalent to deflateEnd followed by deflateInit,
-   but does not free and reallocate all the internal compression state.  The
-   stream will keep the same compression level and any other attributes that
-   may have been set by deflateInit2.
+     This function is equivalent to deflateEnd followed by deflateInit, but
+   does not free and reallocate the internal compression state.  The stream
+   will leave the compression level and any other attributes that may have been
+   set unchanged.
 
      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
    stream state was inconsistent (such as zalloc or state being Z_NULL).
@@ -662,20 +708,36 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
                                       int strategy));
 /*
      Dynamically update the compression level and compression strategy.  The
-   interpretation of level and strategy is as in deflateInit2.  This can be
+   interpretation of level and strategy is as in deflateInit2().  This can be
    used to switch between compression and straight copy of the input data, or
    to switch to a different kind of input data requiring a different strategy.
-   If the compression level is changed, the input available so far is
-   compressed with the old level (and may be flushed); the new level will take
-   effect only at the next call of deflate().
-
-     Before the call of deflateParams, the stream state must be set as for
-   a call of deflate(), since the currently available input may have to be
-   compressed and flushed.  In particular, strm->avail_out must be non-zero.
-
-     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
-   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
-   strm->avail_out was zero.
+   If the compression approach (which is a function of the level) or the
+   strategy is changed, and if any input has been consumed in a previous
+   deflate() call, then the input available so far is compressed with the old
+   level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
+   for the compression levels 0, 1..3, and 4..9 respectively.  The new level
+   and strategy will take effect at the next call of deflate().
+
+     If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
+   not have enough output space to complete, then the parameter change will not
+   take effect.  In this case, deflateParams() can be called again with the
+   same parameters and more output space to try again.
+
+     In order to assure a change in the parameters on the first try, the
+   deflate stream should be flushed using deflate() with Z_BLOCK or other flush
+   request until strm.avail_out is not zero, before calling deflateParams().
+   Then no more input data should be provided before the deflateParams() call.
+   If this is done, the old level and strategy will be applied to the data
+   compressed before deflateParams(), and the new level and strategy will be
+   applied to the the data compressed after deflateParams().
+
+     deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
+   state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
+   there was not enough output space to complete the compression of the
+   available input data before a change in the strategy or approach.  Note that
+   in the case of a Z_BUF_ERROR, the parameters are not changed.  A return
+   value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
+   retried with more output space.
 */
 
 ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
@@ -793,7 +855,7 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
    is for use with other formats that use the deflate compressed data format
    such as zip.  Those formats provide their own check values.  If a custom
    format is developed using the raw deflate format for compressed data, it is
-   recommended that a check value such as an adler32 or a crc32 be applied to
+   recommended that a check value such as an Adler-32 or a CRC-32 be applied to
    the uncompressed data as is done in the zlib, gzip, and zip formats.  For
    most applications, the zlib format should be used as is.  Note that comments
    above on the use in deflateInit2() applies to the magnitude of windowBits.
@@ -802,7 +864,10 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
    32 to windowBits to enable zlib and gzip decoding with automatic header
    detection, or add 16 to decode only the gzip format (the zlib format will
    return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is a
-   crc32 instead of an adler32.
+   CRC-32 instead of an Adler-32.  Unlike the gunzip utility and gzread() (see
+   below), inflate() will not automatically decode concatenated gzip streams.
+   inflate() will return Z_STREAM_END at the end of the gzip stream.  The state
+   would need to be reset to continue decoding a subsequent gzip stream.
 
      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
    memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
@@ -823,7 +888,7 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
      Initializes the decompression dictionary from the given uncompressed byte
    sequence.  This function must be called immediately after a call of inflate,
    if that call returned Z_NEED_DICT.  The dictionary chosen by the compressor
-   can be determined from the adler32 value returned by that call of inflate.
+   can be determined from the Adler-32 value returned by that call of inflate.
    The compressor and decompressor must use exactly the same dictionary (see
    deflateSetDictionary).  For raw inflate, this function can be called at any
    time to set the dictionary.  If the provided dictionary is smaller than the
@@ -834,7 +899,7 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
    parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
-   expected one (incorrect adler32 value).  inflateSetDictionary does not
+   expected one (incorrect Adler-32 value).  inflateSetDictionary does not
    perform any decompression: this will be done by subsequent calls of
    inflate().
 */
@@ -892,7 +957,7 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
 ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
 /*
      This function is equivalent to inflateEnd followed by inflateInit,
-   but does not free and reallocate all the internal decompression state.  The
+   but does not free and reallocate the internal decompression state.  The
    stream will keep attributes that may have been set by inflateInit2.
 
      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
@@ -904,7 +969,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
 /*
      This function is the same as inflateReset, but it also permits changing
    the wrap and window size requests.  The windowBits parameter is interpreted
-   the same as it is for inflateInit2.
+   the same as it is for inflateInit2.  If the window size is changed, then the
+   memory allocated for the window is freed, and the window will be reallocated
+   by inflate() if needed.
 
      inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
    stream state was inconsistent (such as zalloc or state being Z_NULL), or if
@@ -956,7 +1023,7 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
    location in the input stream can be determined from avail_in and data_type
    as noted in the description for the Z_BLOCK flush parameter for inflate.
 
-     inflateMark returns the value noted above or -1 << 16 if the provided
+     inflateMark returns the value noted above, or -65536 if the provided
    source stream state was inconsistent.
 */
 
@@ -1048,9 +1115,9 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
    This routine would normally be used in a utility that reads zip or gzip
    files and writes out uncompressed files.  The utility would decode the
    header and process the trailer on its own, hence this routine expects only
-   the raw deflate stream to decompress.  This is different from the normal
-   behavior of inflate(), which expects either a zlib or gzip header and
-   trailer around the deflate stream.
+   the raw deflate stream to decompress.  This is different from the default
+   behavior of inflate(), which expects a zlib header and trailer around the
+   deflate stream.
 
      inflateBack() uses two subroutines supplied by the caller that are then
    called by inflateBack() for input and output.  inflateBack() calls those
@@ -1059,12 +1126,12 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
    parameters and return types are defined above in the in_func and out_func
    typedefs.  inflateBack() will call in(in_desc, &buf) which should return the
    number of bytes of provided input, and a pointer to that input in buf.  If
-   there is no input available, in() must return zero--buf is ignored in that
-   case--and inflateBack() will return a buffer error.  inflateBack() will call
-   out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].  out()
-   should return zero on success, or non-zero on failure.  If out() returns
-   non-zero, inflateBack() will return with an error.  Neither in() nor out()
-   are permitted to change the contents of the window provided to
+   there is no input available, in() must return zero -- buf is ignored in that
+   case -- and inflateBack() will return a buffer error.  inflateBack() will
+   call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
+   out() should return zero on success, or non-zero on failure.  If out()
+   returns non-zero, inflateBack() will return with an error.  Neither in() nor
+   out() are permitted to change the contents of the window provided to
    inflateBackInit(), which is also the buffer that out() uses to write from.
    The length written by out() will be at most the window size.  Any non-zero
    amount of input may be provided by in().
@@ -1092,7 +1159,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
    using strm->next_in which will be Z_NULL only if in() returned an error.  If
    strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
    non-zero.  (in() will always be called before out(), so strm->next_in is
-   assured to be defined if out() returns non-zero.) Note that inflateBack()
+   assured to be defined if out() returns non-zero.)  Note that inflateBack()
    cannot return Z_OK.
 */
 
@@ -1114,7 +1181,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
      7.6: size of z_off_t
 
     Compiler, assembler, and debug options:
-     8: DEBUG
+     8: ZLIB_DEBUG
      9: ASMV or ASMINF -- use ASM code
      10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
      11: 0 (reserved)
@@ -1164,7 +1231,8 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
    the byte length of the source buffer.  Upon entry, destLen is the total size
    of the destination buffer, which must be at least the value returned by
    compressBound(sourceLen).  Upon exit, destLen is the actual size of the
-   compressed buffer.
+   compressed data.  compress() is equivalent to compress2() with a level
+   parameter of Z_DEFAULT_COMPRESSION.
 
      compress returns Z_OK if success, Z_MEM_ERROR if there was not
    enough memory, Z_BUF_ERROR if there was not enough room in the output
@@ -1180,7 +1248,7 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
    length of the source buffer.  Upon entry, destLen is the total size of the
    destination buffer, which must be at least the value returned by
    compressBound(sourceLen).  Upon exit, destLen is the actual size of the
-   compressed buffer.
+   compressed data.
 
      compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
    memory, Z_BUF_ERROR if there was not enough room in the output buffer,
@@ -1203,7 +1271,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
    uncompressed data.  (The size of the uncompressed data must have been saved
    previously by the compressor and transmitted to the decompressor by some
    mechanism outside the scope of this compression library.) Upon exit, destLen
-   is the actual size of the uncompressed buffer.
+   is the actual size of the uncompressed data.
 
      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
    enough memory, Z_BUF_ERROR if there was not enough room in the output
@@ -1212,6 +1280,14 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
    buffer with the uncompressed data up to that point.
 */
 
+ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest,   uLongf *destLen,
+                                    const Bytef *source, uLong *sourceLen));
+/*
+     Same as uncompress, except that sourceLen is a pointer, where the
+   length of the source is *sourceLen.  On return, *sourceLen is the number of
+   source bytes consumed.
+*/
+
                         /* gzip file access functions */
 
 /*
@@ -1290,10 +1366,9 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
    default buffer size is 8192 bytes.  This function must be called after
    gzopen() or gzdopen(), and before any other calls that read or write the
    file.  The buffer memory allocation is always deferred to the first read or
-   write.  Two buffers are allocated, either both of the specified size when
-   writing, or one of the specified size and the other twice that size when
-   reading.  A larger buffer size of, for example, 64K or 128K bytes will
-   noticeably increase the speed of decompression (reading).
+   write.  Three times that size in buffer space is allocated.  A larger buffer
+   size of, for example, 64K or 128K bytes will noticeably increase the speed
+   of decompression (reading).
 
      The new buffer size also affects the maximum length for gzprintf().
 
@@ -1304,10 +1379,12 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
 ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
 /*
      Dynamically update the compression level or strategy.  See the description
-   of deflateInit2 for the meaning of these parameters.
+   of deflateInit2 for the meaning of these parameters.  Previously provided
+   data is flushed before the parameter change.
 
-     gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
-   opened for writing.
+     gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not
+   opened for writing, Z_ERRNO if there is an error writing the flushed data,
+   or Z_MEM_ERROR if there is a memory allocation error.
 */
 
 ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
@@ -1335,7 +1412,35 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
    case.
 
      gzread returns the number of uncompressed bytes actually read, less than
-   len for end of file, or -1 for error.
+   len for end of file, or -1 for error.  If len is too large to fit in an int,
+   then nothing is read, -1 is returned, and the error state is set to
+   Z_STREAM_ERROR.
+*/
+
+ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
+                                     gzFile file));
+/*
+     Read up to nitems items of size size from file to buf, otherwise operating
+   as gzread() does.  This duplicates the interface of stdio's fread(), with
+   size_t request and return types.  If the library defines size_t, then
+   z_size_t is identical to size_t.  If not, then z_size_t is an unsigned
+   integer type that can contain a pointer.
+
+     gzfread() returns the number of full items read of size size, or zero if
+   the end of the file was reached and a full item could not be read, or if
+   there was an error.  gzerror() must be consulted if zero is returned in
+   order to determine if there was an error.  If the multiplication of size and
+   nitems overflows, i.e. the product does not fit in a z_size_t, then nothing
+   is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
+
+     In the event that the end of file is reached and only a partial item is
+   available at the end, i.e. the remaining uncompressed data length is not a
+   multiple of size, then the final partial item is nevetheless read into buf
+   and the end-of-file flag is set.  The length of the partial item read is not
+   provided, but could be inferred from the result of gztell().  This behavior
+   is the same as the behavior of fread() implementations in common libraries,
+   but it prevents the direct use of gzfread() to read a concurrently written
+   file, reseting and retrying on end-of-file, when size is not 1.
 */
 
 ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
@@ -1346,19 +1451,33 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
    error.
 */
 
+ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
+                                      z_size_t nitems, gzFile file));
+/*
+     gzfwrite() writes nitems items of size size from buf to file, duplicating
+   the interface of stdio's fwrite(), with size_t request and return types.  If
+   the library defines size_t, then z_size_t is identical to size_t.  If not,
+   then z_size_t is an unsigned integer type that can contain a pointer.
+
+     gzfwrite() returns the number of full items written of size size, or zero
+   if there was an error.  If the multiplication of size and nitems overflows,
+   i.e. the product does not fit in a z_size_t, then nothing is written, zero
+   is returned, and the error state is set to Z_STREAM_ERROR.
+*/
+
 ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
 /*
      Converts, formats, and writes the arguments to the compressed file under
    control of the format string, as in fprintf.  gzprintf returns the number of
-   uncompressed bytes actually written, or 0 in case of error.  The number of
-   uncompressed bytes written is limited to 8191, or one less than the buffer
-   size given to gzbuffer().  The caller should assure that this limit is not
-   exceeded.  If it is exceeded, then gzprintf() will return an error (0) with
-   nothing written.  In this case, there may also be a buffer overflow with
-   unpredictable consequences, which is possible only if zlib was compiled with
-   the insecure functions sprintf() or vsprintf() because the secure snprintf()
-   or vsnprintf() functions were not available.  This can be determined using
-   zlibCompileFlags().
+   uncompressed bytes actually written, or a negative zlib error code in case
+   of error.  The number of uncompressed bytes written is limited to 8191, or
+   one less than the buffer size given to gzbuffer().  The caller should assure
+   that this limit is not exceeded.  If it is exceeded, then gzprintf() will
+   return an error (0) with nothing written.  In this case, there may also be a
+   buffer overflow with unpredictable consequences, which is possible only if
+   zlib was compiled with the insecure functions sprintf() or vsprintf()
+   because the secure snprintf() or vsnprintf() functions were not available.
+   This can be determined using zlibCompileFlags().
 */
 
 ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
@@ -1418,7 +1537,7 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
      If the flush parameter is Z_FINISH, the remaining data is written and the
    gzip stream is completed in the output.  If gzwrite() is called again, a new
    gzip stream will be started in the output.  gzread() is able to read such
-   concatented gzip streams.
+   concatenated gzip streams.
 
      gzflush should be called only when strictly necessary because it will
    degrade compression if called too often.
@@ -1572,7 +1691,7 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
    return the updated checksum.  If buf is Z_NULL, this function returns the
    required initial value for the checksum.
 
-     An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
+     An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed
    much faster.
 
    Usage example:
@@ -1585,6 +1704,12 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
      if (adler != original_adler) error();
 */
 
+ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf,
+                                    z_size_t len));
+/*
+     Same as adler32(), but with a size_t length.
+*/
+
 /*
 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
                                           z_off_t len2));
@@ -1614,6 +1739,12 @@ ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
      if (crc != original_crc) error();
 */
 
+ZEXTERN uLong ZEXPORT crc32_z OF((uLong adler, const Bytef *buf,
+                                  z_size_t len));
+/*
+     Same as crc32(), but with a size_t length.
+*/
+
 /*
 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
 
@@ -1644,19 +1775,35 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
                                          unsigned char FAR *window,
                                          const char *version,
                                          int stream_size));
-#define deflateInit(strm, level) \
-        deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
-#define inflateInit(strm) \
-        inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
-#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
-        deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
-                      (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
-#define inflateInit2(strm, windowBits) \
-        inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
-                      (int)sizeof(z_stream))
-#define inflateBackInit(strm, windowBits, window) \
-        inflateBackInit_((strm), (windowBits), (window), \
-                      ZLIB_VERSION, (int)sizeof(z_stream))
+#ifdef Z_PREFIX_SET
+#  define z_deflateInit(strm, level) \
+          deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
+#  define z_inflateInit(strm) \
+          inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
+#  define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
+          deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
+                        (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
+#  define z_inflateInit2(strm, windowBits) \
+          inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
+                        (int)sizeof(z_stream))
+#  define z_inflateBackInit(strm, windowBits, window) \
+          inflateBackInit_((strm), (windowBits), (window), \
+                           ZLIB_VERSION, (int)sizeof(z_stream))
+#else
+#  define deflateInit(strm, level) \
+          deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
+#  define inflateInit(strm) \
+          inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
+#  define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
+          deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
+                        (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
+#  define inflateInit2(strm, windowBits) \
+          inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
+                        (int)sizeof(z_stream))
+#  define inflateBackInit(strm, windowBits, window) \
+          inflateBackInit_((strm), (windowBits), (window), \
+                           ZLIB_VERSION, (int)sizeof(z_stream))
+#endif
 
 #ifndef Z_SOLO
 
@@ -1667,14 +1814,19 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  * behavior could change in the future, perhaps even capriciously.  They can
  * only be used by the gzgetc() macro.  You have been warned.
  */
+struct gzFile_s {
+    unsigned have;
+    unsigned char *next;
+    z_off64_t pos;
+};
 ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file));  /* backward compatibility */
 #ifdef Z_PREFIX_SET
 #  undef z_gzgetc
 #  define z_gzgetc(g) \
-          ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+          ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
 #else
 #  define gzgetc(g) \
-          ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+          ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
 #endif
 
 /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
@@ -1732,19 +1884,16 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file));  /* backward compatibility */
 
 #endif /* !Z_SOLO */
 
-/* hack for buggy compilers */
-#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
-    struct internal_state {int dummy;};
-#endif
-
 /* undocumented functions */
 ZEXTERN const char   * ZEXPORT zError           OF((int));
 ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp));
 ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table    OF((void));
 ZEXTERN int            ZEXPORT inflateUndermine OF((z_streamp, int));
+ZEXTERN int            ZEXPORT inflateValidate OF((z_streamp, int));
+ZEXTERN unsigned long  ZEXPORT inflateCodesUsed OF ((z_streamp));
 ZEXTERN int            ZEXPORT inflateResetKeep OF((z_streamp));
 ZEXTERN int            ZEXPORT deflateResetKeep OF((z_streamp));
-#if defined(_WIN32) && !defined(Z_SOLO)
+#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(Z_SOLO)
 ZEXTERN gzFile         ZEXPORT gzopen_w OF((const wchar_t *path,
                                             const char *mode));
 #endif
diff --git a/deps/libchdr/deps/zlib-1.2.11/zlib.map b/deps/libchdr/deps/zlib-1.2.11/zlib.map
new file mode 100644 (file)
index 0000000..40fa9db
--- /dev/null
@@ -0,0 +1,94 @@
+ZLIB_1.2.0 {\r
+  global:\r
+    compressBound;\r
+    deflateBound;\r
+    inflateBack;\r
+    inflateBackEnd;\r
+    inflateBackInit_;\r
+    inflateCopy;\r
+  local:\r
+    deflate_copyright;\r
+    inflate_copyright;\r
+    inflate_fast;\r
+    inflate_table;\r
+    zcalloc;\r
+    zcfree;\r
+    z_errmsg;\r
+    gz_error;\r
+    gz_intmax;\r
+    _*;\r
+};\r
+\r
+ZLIB_1.2.0.2 {\r
+    gzclearerr;\r
+    gzungetc;\r
+    zlibCompileFlags;\r
+} ZLIB_1.2.0;\r
+\r
+ZLIB_1.2.0.8 {\r
+    deflatePrime;\r
+} ZLIB_1.2.0.2;\r
+\r
+ZLIB_1.2.2 {\r
+    adler32_combine;\r
+    crc32_combine;\r
+    deflateSetHeader;\r
+    inflateGetHeader;\r
+} ZLIB_1.2.0.8;\r
+\r
+ZLIB_1.2.2.3 {\r
+    deflateTune;\r
+    gzdirect;\r
+} ZLIB_1.2.2;\r
+\r
+ZLIB_1.2.2.4 {\r
+    inflatePrime;\r
+} ZLIB_1.2.2.3;\r
+\r
+ZLIB_1.2.3.3 {\r
+    adler32_combine64;\r
+    crc32_combine64;\r
+    gzopen64;\r
+    gzseek64;\r
+    gztell64;\r
+    inflateUndermine;\r
+} ZLIB_1.2.2.4;\r
+\r
+ZLIB_1.2.3.4 {\r
+    inflateReset2;\r
+    inflateMark;\r
+} ZLIB_1.2.3.3;\r
+\r
+ZLIB_1.2.3.5 {\r
+    gzbuffer;\r
+    gzoffset;\r
+    gzoffset64;\r
+    gzclose_r;\r
+    gzclose_w;\r
+} ZLIB_1.2.3.4;\r
+\r
+ZLIB_1.2.5.1 {\r
+    deflatePending;\r
+} ZLIB_1.2.3.5;\r
+\r
+ZLIB_1.2.5.2 {\r
+    deflateResetKeep;\r
+    gzgetc_;\r
+    inflateResetKeep;\r
+} ZLIB_1.2.5.1;\r
+\r
+ZLIB_1.2.7.1 {\r
+    inflateGetDictionary;\r
+    gzvprintf;\r
+} ZLIB_1.2.5.2;\r
+\r
+ZLIB_1.2.9 {\r
+    inflateCodesUsed;\r
+    inflateValidate;\r
+    uncompress2;\r
+    gzfread;\r
+    gzfwrite;\r
+    deflateGetDictionary;\r
+    adler32_z;\r
+    crc32_z;\r
+} ZLIB_1.2.7.1;\r
diff --git a/deps/libchdr/deps/zlib-1.2.11/zlib.pc.cmakein b/deps/libchdr/deps/zlib-1.2.11/zlib.pc.cmakein
new file mode 100644 (file)
index 0000000..a5e6429
--- /dev/null
@@ -0,0 +1,13 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=@CMAKE_INSTALL_PREFIX@
+libdir=@INSTALL_LIB_DIR@
+sharedlibdir=@INSTALL_LIB_DIR@
+includedir=@INSTALL_INC_DIR@
+
+Name: zlib
+Description: zlib compression library
+Version: @VERSION@
+
+Requires:
+Libs: -L${libdir} -L${sharedlibdir} -lz
+Cflags: -I${includedir}
diff --git a/deps/libchdr/deps/zlib-1.2.11/zlib.pc.in b/deps/libchdr/deps/zlib-1.2.11/zlib.pc.in
new file mode 100644 (file)
index 0000000..7e5acf9
--- /dev/null
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+sharedlibdir=@sharedlibdir@
+includedir=@includedir@
+
+Name: zlib
+Description: zlib compression library
+Version: @VERSION@
+
+Requires:
+Libs: -L${libdir} -L${sharedlibdir} -lz
+Cflags: -I${includedir}
diff --git a/deps/libchdr/deps/zlib-1.2.11/zlib2ansi b/deps/libchdr/deps/zlib-1.2.11/zlib2ansi
new file mode 100755 (executable)
index 0000000..15e3e16
--- /dev/null
@@ -0,0 +1,152 @@
+#!/usr/bin/perl
+
+# Transform K&R C function definitions into ANSI equivalent.
+#
+# Author: Paul Marquess
+# Version: 1.0
+# Date: 3 October 2006
+
+# TODO
+#
+# Asumes no function pointer parameters. unless they are typedefed.
+# Assumes no literal strings that look like function definitions
+# Assumes functions start at the beginning of a line
+
+use strict;
+use warnings;
+
+local $/;
+$_ = <>;
+
+my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments
+
+my $d1    = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ;
+my $decl  = qr{ $sp (?: \w+ $sp )+ $d1 }xo ;
+my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ;
+
+
+while (s/^
+            (                  # Start $1
+                (              #   Start $2
+                    .*?        #     Minimal eat content
+                    ( ^ \w [\w\s\*]+ )    #     $3 -- function name
+                    \s*        #     optional whitespace
+                )              # $2 - Matched up to before parameter list
+
+                \( \s*         # Literal "(" + optional whitespace
+                ( [^\)]+ )     # $4 - one or more anythings except ")"
+                \s* \)         # optional whitespace surrounding a Literal ")"
+
+                ( (?: $dList )+ ) # $5
+
+                $sp ^ {        # literal "{" at start of line
+            )                  # Remember to $1
+        //xsom
+      )
+{
+    my $all = $1 ;
+    my $prefix = $2;
+    my $param_list = $4 ;
+    my $params = $5;
+
+    StripComments($params);
+    StripComments($param_list);
+    $param_list =~ s/^\s+//;
+    $param_list =~ s/\s+$//;
+
+    my $i = 0 ;
+    my %pList = map { $_ => $i++ }
+                split /\s*,\s*/, $param_list;
+    my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ;
+
+    my @params = split /\s*;\s*/, $params;
+    my @outParams = ();
+    foreach my $p (@params)
+    {
+        if ($p =~ /,/)
+        {
+            my @bits = split /\s*,\s*/, $p;
+            my $first = shift @bits;
+            $first =~ s/^\s*//;
+            push @outParams, $first;
+            $first =~ /^(\w+\s*)/;
+            my $type = $1 ;
+            push @outParams, map { $type . $_ } @bits;
+        }
+        else
+        {
+            $p =~ s/^\s+//;
+            push @outParams, $p;
+        }
+    }
+
+
+    my %tmp = map { /$pMatch/;  $_ => $pList{$1}  }
+              @outParams ;
+
+    @outParams = map  { "    $_" }
+                 sort { $tmp{$a} <=> $tmp{$b} }
+                 @outParams ;
+
+    print $prefix ;
+    print "(\n" . join(",\n", @outParams) . ")\n";
+    print "{" ;
+
+}
+
+# Output any trailing code.
+print ;
+exit 0;
+
+
+sub StripComments
+{
+
+  no warnings;
+
+  # Strip C & C++ coments
+  # From the perlfaq
+  $_[0] =~
+
+    s{
+       /\*         ##  Start of /* ... */ comment
+       [^*]*\*+    ##  Non-* followed by 1-or-more *'s
+       (
+         [^/*][^*]*\*+
+       )*          ##  0-or-more things which don't start with /
+                   ##    but do end with '*'
+       /           ##  End of /* ... */ comment
+
+     |         ##     OR  C++ Comment
+       //          ## Start of C++ comment //
+       [^\n]*      ## followed by 0-or-more non end of line characters
+
+     |         ##     OR  various things which aren't comments:
+
+       (
+         "           ##  Start of " ... " string
+         (
+           \\.           ##  Escaped char
+         |               ##    OR
+           [^"\\]        ##  Non "\
+         )*
+         "           ##  End of " ... " string
+
+       |         ##     OR
+
+         '           ##  Start of ' ... ' string
+         (
+           \\.           ##  Escaped char
+         |               ##    OR
+           [^'\\]        ##  Non '\
+         )*
+         '           ##  End of ' ... ' string
+
+       |         ##     OR
+
+         .           ##  Anything other char
+         [^/"'\\]*   ##  Chars which doesn't start a comment, string or escape
+       )
+     }{$2}gxs;
+
+}
diff --git a/deps/libchdr/deps/zlib-1.2.11/zutil.c b/deps/libchdr/deps/zlib-1.2.11/zutil.c
new file mode 100644 (file)
index 0000000..a76c6b0
--- /dev/null
@@ -0,0 +1,325 @@
+/* zutil.c -- target dependent utility functions for the compression library
+ * Copyright (C) 1995-2017 Jean-loup Gailly
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#include "zutil.h"
+#ifndef Z_SOLO
+#  include "gzguts.h"
+#endif
+
+z_const char * const z_errmsg[10] = {
+    (z_const char *)"need dictionary",     /* Z_NEED_DICT       2  */
+    (z_const char *)"stream end",          /* Z_STREAM_END      1  */
+    (z_const char *)"",                    /* Z_OK              0  */
+    (z_const char *)"file error",          /* Z_ERRNO         (-1) */
+    (z_const char *)"stream error",        /* Z_STREAM_ERROR  (-2) */
+    (z_const char *)"data error",          /* Z_DATA_ERROR    (-3) */
+    (z_const char *)"insufficient memory", /* Z_MEM_ERROR     (-4) */
+    (z_const char *)"buffer error",        /* Z_BUF_ERROR     (-5) */
+    (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
+    (z_const char *)""
+};
+
+
+const char * ZEXPORT zlibVersion()
+{
+    return ZLIB_VERSION;
+}
+
+uLong ZEXPORT zlibCompileFlags()
+{
+    uLong flags;
+
+    flags = 0;
+    switch ((int)(sizeof(uInt))) {
+    case 2:     break;
+    case 4:     flags += 1;     break;
+    case 8:     flags += 2;     break;
+    default:    flags += 3;
+    }
+    switch ((int)(sizeof(uLong))) {
+    case 2:     break;
+    case 4:     flags += 1 << 2;        break;
+    case 8:     flags += 2 << 2;        break;
+    default:    flags += 3 << 2;
+    }
+    switch ((int)(sizeof(voidpf))) {
+    case 2:     break;
+    case 4:     flags += 1 << 4;        break;
+    case 8:     flags += 2 << 4;        break;
+    default:    flags += 3 << 4;
+    }
+    switch ((int)(sizeof(z_off_t))) {
+    case 2:     break;
+    case 4:     flags += 1 << 6;        break;
+    case 8:     flags += 2 << 6;        break;
+    default:    flags += 3 << 6;
+    }
+#ifdef ZLIB_DEBUG
+    flags += 1 << 8;
+#endif
+#if defined(ASMV) || defined(ASMINF)
+    flags += 1 << 9;
+#endif
+#ifdef ZLIB_WINAPI
+    flags += 1 << 10;
+#endif
+#ifdef BUILDFIXED
+    flags += 1 << 12;
+#endif
+#ifdef DYNAMIC_CRC_TABLE
+    flags += 1 << 13;
+#endif
+#ifdef NO_GZCOMPRESS
+    flags += 1L << 16;
+#endif
+#ifdef NO_GZIP
+    flags += 1L << 17;
+#endif
+#ifdef PKZIP_BUG_WORKAROUND
+    flags += 1L << 20;
+#endif
+#ifdef FASTEST
+    flags += 1L << 21;
+#endif
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
+#  ifdef NO_vsnprintf
+    flags += 1L << 25;
+#    ifdef HAS_vsprintf_void
+    flags += 1L << 26;
+#    endif
+#  else
+#    ifdef HAS_vsnprintf_void
+    flags += 1L << 26;
+#    endif
+#  endif
+#else
+    flags += 1L << 24;
+#  ifdef NO_snprintf
+    flags += 1L << 25;
+#    ifdef HAS_sprintf_void
+    flags += 1L << 26;
+#    endif
+#  else
+#    ifdef HAS_snprintf_void
+    flags += 1L << 26;
+#    endif
+#  endif
+#endif
+    return flags;
+}
+
+#ifdef ZLIB_DEBUG
+#include <stdlib.h>
+#  ifndef verbose
+#    define verbose 0
+#  endif
+int ZLIB_INTERNAL z_verbose = verbose;
+
+void ZLIB_INTERNAL z_error (m)
+    char *m;
+{
+    fprintf(stderr, "%s\n", m);
+    exit(1);
+}
+#endif
+
+/* exported to allow conversion of error code to string for compress() and
+ * uncompress()
+ */
+const char * ZEXPORT zError(err)
+    int err;
+{
+    return ERR_MSG(err);
+}
+
+#if defined(_WIN32_WCE)
+    /* The Microsoft C Run-Time Library for Windows CE doesn't have
+     * errno.  We define it as a global variable to simplify porting.
+     * Its value is always 0 and should not be used.
+     */
+    int errno = 0;
+#endif
+
+#ifndef HAVE_MEMCPY
+
+void ZLIB_INTERNAL zmemcpy(dest, source, len)
+    Bytef* dest;
+    const Bytef* source;
+    uInt  len;
+{
+    if (len == 0) return;
+    do {
+        *dest++ = *source++; /* ??? to be unrolled */
+    } while (--len != 0);
+}
+
+int ZLIB_INTERNAL zmemcmp(s1, s2, len)
+    const Bytef* s1;
+    const Bytef* s2;
+    uInt  len;
+{
+    uInt j;
+
+    for (j = 0; j < len; j++) {
+        if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
+    }
+    return 0;
+}
+
+void ZLIB_INTERNAL zmemzero(dest, len)
+    Bytef* dest;
+    uInt  len;
+{
+    if (len == 0) return;
+    do {
+        *dest++ = 0;  /* ??? to be unrolled */
+    } while (--len != 0);
+}
+#endif
+
+#ifndef Z_SOLO
+
+#ifdef SYS16BIT
+
+#ifdef __TURBOC__
+/* Turbo C in 16-bit mode */
+
+#  define MY_ZCALLOC
+
+/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
+ * and farmalloc(64K) returns a pointer with an offset of 8, so we
+ * must fix the pointer. Warning: the pointer must be put back to its
+ * original form in order to free it, use zcfree().
+ */
+
+#define MAX_PTR 10
+/* 10*64K = 640K */
+
+local int next_ptr = 0;
+
+typedef struct ptr_table_s {
+    voidpf org_ptr;
+    voidpf new_ptr;
+} ptr_table;
+
+local ptr_table table[MAX_PTR];
+/* This table is used to remember the original form of pointers
+ * to large buffers (64K). Such pointers are normalized with a zero offset.
+ * Since MSDOS is not a preemptive multitasking OS, this table is not
+ * protected from concurrent access. This hack doesn't work anyway on
+ * a protected system like OS/2. Use Microsoft C instead.
+ */
+
+voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
+{
+    voidpf buf;
+    ulg bsize = (ulg)items*size;
+
+    (void)opaque;
+
+    /* If we allocate less than 65520 bytes, we assume that farmalloc
+     * will return a usable pointer which doesn't have to be normalized.
+     */
+    if (bsize < 65520L) {
+        buf = farmalloc(bsize);
+        if (*(ush*)&buf != 0) return buf;
+    } else {
+        buf = farmalloc(bsize + 16L);
+    }
+    if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
+    table[next_ptr].org_ptr = buf;
+
+    /* Normalize the pointer to seg:0 */
+    *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
+    *(ush*)&buf = 0;
+    table[next_ptr++].new_ptr = buf;
+    return buf;
+}
+
+void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
+{
+    int n;
+
+    (void)opaque;
+
+    if (*(ush*)&ptr != 0) { /* object < 64K */
+        farfree(ptr);
+        return;
+    }
+    /* Find the original pointer */
+    for (n = 0; n < next_ptr; n++) {
+        if (ptr != table[n].new_ptr) continue;
+
+        farfree(table[n].org_ptr);
+        while (++n < next_ptr) {
+            table[n-1] = table[n];
+        }
+        next_ptr--;
+        return;
+    }
+    Assert(0, "zcfree: ptr not found");
+}
+
+#endif /* __TURBOC__ */
+
+
+#ifdef M_I86
+/* Microsoft C in 16-bit mode */
+
+#  define MY_ZCALLOC
+
+#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
+#  define _halloc  halloc
+#  define _hfree   hfree
+#endif
+
+voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
+{
+    (void)opaque;
+    return _halloc((long)items, size);
+}
+
+void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
+{
+    (void)opaque;
+    _hfree(ptr);
+}
+
+#endif /* M_I86 */
+
+#endif /* SYS16BIT */
+
+
+#ifndef MY_ZCALLOC /* Any system without a special alloc function */
+
+#ifndef STDC
+extern voidp  malloc OF((uInt size));
+extern voidp  calloc OF((uInt items, uInt size));
+extern void   free   OF((voidpf ptr));
+#endif
+
+voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
+    voidpf opaque;
+    unsigned items;
+    unsigned size;
+{
+    (void)opaque;
+    return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
+                              (voidpf)calloc(items, size);
+}
+
+void ZLIB_INTERNAL zcfree (opaque, ptr)
+    voidpf opaque;
+    voidpf ptr;
+{
+    (void)opaque;
+    free(ptr);
+}
+
+#endif /* MY_ZCALLOC */
+
+#endif /* !Z_SOLO */
similarity index 87%
rename from deps/zlib/zutil.h
rename to deps/libchdr/deps/zlib-1.2.11/zutil.h
index 5c6929f..b079ea6 100644 (file)
@@ -1,5 +1,5 @@
 /* zutil.h -- internal interface and configuration of the compression library
- * Copyright (C) 1995-2013 Jean-loup Gailly.
+ * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -36,7 +36,9 @@
 #ifndef local
 #  define local static
 #endif
-/* compile with -Dlocal if your debugger can't find static symbols */
+/* since "static" is used to mean two completely different things in C, we
+   define "local" for the non-static meaning of "static", for readability
+   (compile with -Dlocal if your debugger can't find static symbols) */
 
 typedef unsigned char  uch;
 typedef uch FAR uchf;
@@ -44,7 +46,7 @@ typedef unsigned short ush;
 typedef ush FAR ushf;
 typedef unsigned long  ulg;
 
-extern char * const z_errmsg[10]; /* indexed by 2-zlib_error */
+extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 /* (size given to avoid silly warnings with Visual C++) */
 
 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
@@ -98,28 +100,38 @@ extern char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #endif
 
 #ifdef AMIGA
-#  define OS_CODE  0x01
+#  define OS_CODE  1
 #endif
 
 #if defined(VAXC) || defined(VMS)
-#  define OS_CODE  0x02
+#  define OS_CODE  2
 #  define F_OPEN(name, mode) \
      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
 #endif
 
+#ifdef __370__
+#  if __TARGET_LIB__ < 0x20000000
+#    define OS_CODE 4
+#  elif __TARGET_LIB__ < 0x40000000
+#    define OS_CODE 11
+#  else
+#    define OS_CODE 8
+#  endif
+#endif
+
 #if defined(ATARI) || defined(atarist)
-#  define OS_CODE  0x05
+#  define OS_CODE  5
 #endif
 
 #ifdef OS2
-#  define OS_CODE  0x06
+#  define OS_CODE  6
 #  if defined(M_I86) && !defined(Z_SOLO)
 #    include <malloc.h>
 #  endif
 #endif
 
 #if defined(MACOS) || defined(TARGET_OS_MAC)
-#  define OS_CODE  0x07
+#  define OS_CODE  7
 #  ifndef Z_SOLO
 #    if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
 #      include <unix.h> /* for fdopen */
@@ -131,18 +143,24 @@ extern char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #  endif
 #endif
 
-#ifdef TOPS20
-#  define OS_CODE  0x0a
+#ifdef __acorn
+#  define OS_CODE 13
 #endif
 
-#ifdef WIN32
-#  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */
-#    define OS_CODE  0x0b
-#  endif
+#if defined(WIN32) && !defined(__CYGWIN__)
+#  define OS_CODE  10
+#endif
+
+#ifdef _BEOS_
+#  define OS_CODE  16
+#endif
+
+#ifdef __TOS_OS400__
+#  define OS_CODE 18
 #endif
 
-#ifdef __50SERIES /* Prime/PRIMOS */
-#  define OS_CODE  0x0f
+#ifdef __APPLE__
+#  define OS_CODE 19
 #endif
 
 #if defined(_BEOS_) || defined(RISCOS)
@@ -177,7 +195,7 @@ extern char * const z_errmsg[10]; /* indexed by 2-zlib_error */
         /* common defaults */
 
 #ifndef OS_CODE
-#  define OS_CODE  0x03  /* assume Unix */
+#  define OS_CODE  3     /* assume Unix */
 #endif
 
 #ifndef F_OPEN
@@ -216,7 +234,7 @@ extern char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #endif
 
 /* Diagnostic functions */
-#ifdef DEBUG
+#ifdef ZLIB_DEBUG
 #  include <stdio.h>
    extern int ZLIB_INTERNAL z_verbose;
    extern void ZLIB_INTERNAL z_error OF((char *m));
index 61b149d..a37edc3 100644 (file)
@@ -392,6 +392,8 @@ CHD_EXPORT const char *chd_error_string(chd_error err);
 /* return a pointer to the extracted CHD header data */
 CHD_EXPORT const chd_header *chd_get_header(chd_file *chd);
 
+/* read CHD header data from file into the pointed struct */
+CHD_EXPORT chd_error chd_read_header(const char *filename, chd_header *header);
 
 
 
diff --git a/deps/libchdr/pkg-config.pc.in b/deps/libchdr/pkg-config.pc.in
new file mode 100644 (file)
index 0000000..0289632
--- /dev/null
@@ -0,0 +1,10 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/libchdr
+
+Name: libchdr
+Description: Standalone library for reading MAME's CHDv1-v5 formats
+Version: @CHDR_VERSION_MAJOR@.@CHDR_VERSION_MINOR@
+Libs: -L${libdir} -lchdr @LIBS@
+Cflags: -I${includedir}
+
index 913abaa..c5cc179 100644 (file)
@@ -1382,8 +1382,15 @@ CHD_EXPORT chd_error chd_open_file(core_file *file, int mode, chd_file *parent,
                EARLY_EXIT(err = CHDERR_UNSUPPORTED_VERSION);
 
        /* if we need a parent, make sure we have one */
-       if (parent == NULL && (newchd->header.flags & CHDFLAGS_HAS_PARENT))
-               EARLY_EXIT(err = CHDERR_REQUIRES_PARENT);
+       if (parent == NULL)
+       {
+               /* Detect parent requirement for versions below 5 */
+               if (newchd->header.version < 5 && newchd->header.flags & CHDFLAGS_HAS_PARENT)
+                       EARLY_EXIT(err = CHDERR_REQUIRES_PARENT);
+               /* Detection for version 5 and above - if parentsha1 != 0, we have a parent */
+               else if (newchd->header.version >= 5 && memcmp(nullsha1, newchd->header.parentsha1, sizeof(newchd->header.parentsha1)) != 0)
+                       EARLY_EXIT(err = CHDERR_REQUIRES_PARENT);
+       }
 
        /* make sure we have a valid parent */
        if (parent != NULL)
@@ -1676,6 +1683,9 @@ CHD_EXPORT void chd_close(chd_file *chd)
        if (chd->file_cache)
                free(chd->file_cache);
 
+       if (chd->parent)
+               chd_close(chd->parent);
+
        /* free our memory */
        free(chd);
 }
@@ -1749,6 +1759,41 @@ CHD_EXPORT const chd_header *chd_get_header(chd_file *chd)
        return &chd->header;
 }
 
+/*-------------------------------------------------
+    chd_read_header - read CHD header data
+       from file into the pointed struct
+-------------------------------------------------*/
+CHD_EXPORT chd_error chd_read_header(const char *filename, chd_header *header)
+{
+       chd_error err = CHDERR_NONE;
+       chd_file chd;
+
+       /* punt if NULL */
+       if (filename == NULL || header == NULL)
+               EARLY_EXIT(err = CHDERR_INVALID_PARAMETER);
+
+       /* open the file */
+       chd.file = core_fopen(filename);
+       if (chd.file == NULL)
+               EARLY_EXIT(err = CHDERR_FILE_NOT_FOUND);
+
+       /* attempt to read the header */
+       err = header_read(&chd, header);
+       if (err != CHDERR_NONE)
+               EARLY_EXIT(err);
+
+       /* validate the header */
+       err = header_validate(header);
+       if (err != CHDERR_NONE)
+               EARLY_EXIT(err);
+
+cleanup:
+       if (chd.file != NULL)
+               core_fclose(chd.file);
+
+       return err;
+}
+
 /***************************************************************************
     CORE DATA READ/WRITE
 ***************************************************************************/
@@ -2343,13 +2388,33 @@ static chd_error hunk_read_into_memory(chd_file *chd, UINT32 hunknum, UINT8 *des
                                return hunk_read_into_memory(chd, blockoffs, dest);
 
                        case COMPRESSION_PARENT:
-#if 0
-                               /* TODO */
-                               if (m_parent_missing)
+                               if (chd->parent == NULL)
                                        return CHDERR_REQUIRES_PARENT;
-                               return m_parent->read_bytes(uint64_t(blockoffs) * uint64_t(m_parent->unit_bytes()), dest, m_hunkbytes);
-#endif
-                               return CHDERR_DECOMPRESSION_ERROR;
+                               UINT8 units_in_hunk = chd->header.hunkbytes / chd->header.unitbytes;
+
+                               /* blockoffs is aligned to units_in_hunk */
+                               if (blockoffs % units_in_hunk == 0) {
+                                       return hunk_read_into_memory(chd->parent, blockoffs / units_in_hunk, dest);
+                               /* blockoffs is not aligned to units_in_hunk */
+                               } else {
+                                       UINT32 unit_in_hunk = blockoffs % units_in_hunk;
+                                       UINT8 *buf = malloc(chd->header.hunkbytes);
+                                       /* Read first half of hunk which contains blockoffs */
+                                       err = hunk_read_into_memory(chd->parent, blockoffs / units_in_hunk, buf);
+                                       if (err != CHDERR_NONE) {
+                                               free(buf);
+                                               return err;
+                                       }
+                                       memcpy(dest, buf + unit_in_hunk * chd->header.unitbytes, (units_in_hunk - unit_in_hunk) * chd->header.unitbytes);
+                                       /* Read second half of hunk which contains blockoffs */
+                                       err = hunk_read_into_memory(chd->parent, (blockoffs / units_in_hunk) + 1, buf);
+                                       if (err != CHDERR_NONE) {
+                                               free(buf);
+                                               return err;
+                                       }
+                                       memcpy(dest + (units_in_hunk - unit_in_hunk) * chd->header.unitbytes, buf, unit_in_hunk * chd->header.unitbytes);
+                                       free(buf);
+                               }
                }
                return CHDERR_NONE;
        }
diff --git a/deps/libchdr/src/link.T b/deps/libchdr/src/link.T
new file mode 100644 (file)
index 0000000..ea37716
--- /dev/null
@@ -0,0 +1,5 @@
+{
+   global: chd_*;
+   local: *;
+};
+
diff --git a/deps/libchdr/tests/benchmark.c b/deps/libchdr/tests/benchmark.c
new file mode 100644 (file)
index 0000000..5c10bae
--- /dev/null
@@ -0,0 +1,49 @@
+#include <libchdr/chd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+
+int main(int argc, char** argv)
+{
+  chd_error err;
+  chd_file* file;
+  const chd_header* header;
+  void* buffer;
+  int i;
+  unsigned int totalbytes;
+  clock_t start, end;
+  double time_taken;
+
+  printf("\nlibchdr benchmark tool....");
+
+  /* Recording the starting clock tick.*/
+  start = clock(); 
+  
+  /* Sequential read all hunks */
+  err = chd_open(argv[1], CHD_OPEN_READ, NULL, &file);
+  if (err)
+       printf("\nchd_open() error: %s", chd_error_string(err));
+  header = chd_get_header(file);
+  totalbytes = header->hunkbytes * header->totalhunks;
+  buffer = malloc(header->hunkbytes);
+  for (i = 0 ; i < header->totalhunks ; i++)
+  {
+    err = chd_read(file, i, buffer);
+    if (err)
+      printf("\nchd_read() error: %s", chd_error_string(err));
+  }
+  free(buffer);
+  chd_close(file);
+
+  /* Recording the end clock tick. */
+  end = clock();
+
+  /* Calculating total time taken by the program. */
+  time_taken = ((double)(end - start)) / ((double)CLOCKS_PER_SEC);
+
+  /* Print results */
+  printf("\nRead %d bytes in %lf seconds", totalbytes, time_taken);
+  printf("\nRate is %lf MB/s", (((double)totalbytes)/(1024*1024)) / time_taken);
+  printf("\n\n");
+  return 0;
+}
diff --git a/deps/libchdr/tests/build_tests.sh b/deps/libchdr/tests/build_tests.sh
new file mode 100755 (executable)
index 0000000..8d9af6f
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+gcc benchmark.c -lchdr -o benchmark
diff --git a/deps/lzma-16.04/C/7z.h b/deps/lzma-16.04/C/7z.h
deleted file mode 100644 (file)
index 216f381..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-/* 7z.h -- 7z interface\r
-2015-11-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_H\r
-#define __7Z_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define k7zStartHeaderSize 0x20\r
-#define k7zSignatureSize 6\r
-\r
-extern const Byte k7zSignature[k7zSignatureSize];\r
-\r
-typedef struct\r
-{\r
-  const Byte *Data;\r
-  size_t Size;\r
-} CSzData;\r
-\r
-/* CSzCoderInfo & CSzFolder support only default methods */\r
-\r
-typedef struct\r
-{\r
-  size_t PropsOffset;\r
-  UInt32 MethodID;\r
-  Byte NumStreams;\r
-  Byte PropsSize;\r
-} CSzCoderInfo;\r
-\r
-typedef struct\r
-{\r
-  UInt32 InIndex;\r
-  UInt32 OutIndex;\r
-} CSzBond;\r
-\r
-#define SZ_NUM_CODERS_IN_FOLDER_MAX 4\r
-#define SZ_NUM_BONDS_IN_FOLDER_MAX 3\r
-#define SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX 4\r
-\r
-typedef struct\r
-{\r
-  UInt32 NumCoders;\r
-  UInt32 NumBonds;\r
-  UInt32 NumPackStreams;\r
-  UInt32 UnpackStream;\r
-  UInt32 PackStreams[SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX];\r
-  CSzBond Bonds[SZ_NUM_BONDS_IN_FOLDER_MAX];\r
-  CSzCoderInfo Coders[SZ_NUM_CODERS_IN_FOLDER_MAX];\r
-} CSzFolder;\r
-\r
-\r
-SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd);\r
-\r
-typedef struct\r
-{\r
-  UInt32 Low;\r
-  UInt32 High;\r
-} CNtfsFileTime;\r
-\r
-typedef struct\r
-{\r
-  Byte *Defs; /* MSB 0 bit numbering */\r
-  UInt32 *Vals;\r
-} CSzBitUi32s;\r
-\r
-typedef struct\r
-{\r
-  Byte *Defs; /* MSB 0 bit numbering */\r
-  // UInt64 *Vals;\r
-  CNtfsFileTime *Vals;\r
-} CSzBitUi64s;\r
-\r
-#define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)\r
-\r
-#define SzBitWithVals_Check(p, i) ((p)->Defs && ((p)->Defs[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)\r
-\r
-typedef struct\r
-{\r
-  UInt32 NumPackStreams;\r
-  UInt32 NumFolders;\r
-\r
-  UInt64 *PackPositions;          // NumPackStreams + 1\r
-  CSzBitUi32s FolderCRCs;         // NumFolders\r
-\r
-  size_t *FoCodersOffsets;        // NumFolders + 1\r
-  UInt32 *FoStartPackStreamIndex; // NumFolders + 1\r
-  UInt32 *FoToCoderUnpackSizes;   // NumFolders + 1\r
-  Byte *FoToMainUnpackSizeIndex;  // NumFolders\r
-  UInt64 *CoderUnpackSizes;       // for all coders in all folders\r
-\r
-  Byte *CodersData;\r
-} CSzAr;\r
-\r
-UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex);\r
-\r
-SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,\r
-    ILookInStream *stream, UInt64 startPos,\r
-    Byte *outBuffer, size_t outSize,\r
-    ISzAlloc *allocMain);\r
-\r
-typedef struct\r
-{\r
-  CSzAr db;\r
-\r
-  UInt64 startPosAfterHeader;\r
-  UInt64 dataPos;\r
-  \r
-  UInt32 NumFiles;\r
-\r
-  UInt64 *UnpackPositions;  // NumFiles + 1\r
-  // Byte *IsEmptyFiles;\r
-  Byte *IsDirs;\r
-  CSzBitUi32s CRCs;\r
-\r
-  CSzBitUi32s Attribs;\r
-  // CSzBitUi32s Parents;\r
-  CSzBitUi64s MTime;\r
-  CSzBitUi64s CTime;\r
-\r
-  UInt32 *FolderToFile;   // NumFolders + 1\r
-  UInt32 *FileToFolder;   // NumFiles\r
-\r
-  size_t *FileNameOffsets; /* in 2-byte steps */\r
-  Byte *FileNames;  /* UTF-16-LE */\r
-} CSzArEx;\r
-\r
-#define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i))\r
-\r
-#define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i])\r
-\r
-void SzArEx_Init(CSzArEx *p);\r
-void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);\r
-UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);\r
-int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);\r
-\r
-/*\r
-if dest == NULL, the return value specifies the required size of the buffer,\r
-  in 16-bit characters, including the null-terminating character.\r
-if dest != NULL, the return value specifies the number of 16-bit characters that\r
-  are written to the dest, including the null-terminating character. */\r
-\r
-size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest);\r
-\r
-/*\r
-size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex);\r
-UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest);\r
-*/\r
-\r
-\r
-\r
-/*\r
-  SzArEx_Extract extracts file from archive\r
-\r
-  *outBuffer must be 0 before first call for each new archive.\r
-\r
-  Extracting cache:\r
-    If you need to decompress more than one file, you can send\r
-    these values from previous call:\r
-      *blockIndex,\r
-      *outBuffer,\r
-      *outBufferSize\r
-    You can consider "*outBuffer" as cache of solid block. If your archive is solid,\r
-    it will increase decompression speed.\r
-  \r
-    If you use external function, you can declare these 3 cache variables\r
-    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r
-    \r
-    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r
-*/\r
-\r
-SRes SzArEx_Extract(\r
-    const CSzArEx *db,\r
-    ILookInStream *inStream,\r
-    UInt32 fileIndex,         /* index of file */\r
-    UInt32 *blockIndex,       /* index of solid block */\r
-    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r
-    size_t *outBufferSize,    /* buffer size for output buffer */\r
-    size_t *offset,           /* offset of stream for required file in *outBuffer */\r
-    size_t *outSizeProcessed, /* size of file in *outBuffer */\r
-    ISzAlloc *allocMain,\r
-    ISzAlloc *allocTemp);\r
-\r
-\r
-/*\r
-SzArEx_Open Errors:\r
-SZ_ERROR_NO_ARCHIVE\r
-SZ_ERROR_ARCHIVE\r
-SZ_ERROR_UNSUPPORTED\r
-SZ_ERROR_MEM\r
-SZ_ERROR_CRC\r
-SZ_ERROR_INPUT_EOF\r
-SZ_ERROR_FAIL\r
-*/\r
-\r
-SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,\r
-    ISzAlloc *allocMain, ISzAlloc *allocTemp);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/7zAlloc.c b/deps/lzma-16.04/C/7zAlloc.c
deleted file mode 100644 (file)
index 360da05..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/* 7zAlloc.c -- Allocation functions\r
-2015-11-09 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "7zAlloc.h"\r
-\r
-/* #define _SZ_ALLOC_DEBUG */\r
-/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r
-\r
-#ifdef _SZ_ALLOC_DEBUG\r
-\r
-#ifdef _WIN32\r
-#include <windows.h>\r
-#endif\r
-\r
-#include <stdio.h>\r
-int g_allocCount = 0;\r
-int g_allocCountTemp = 0;\r
-\r
-#endif\r
-\r
-void *SzAlloc(void *p, size_t size)\r
-{\r
-  UNUSED_VAR(p);\r
-  if (size == 0)\r
-    return 0;\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  fprintf(stderr, "\nAlloc %10u bytes; count = %10d", (unsigned)size, g_allocCount);\r
-  g_allocCount++;\r
-  #endif\r
-  return malloc(size);\r
-}\r
-\r
-void SzFree(void *p, void *address)\r
-{\r
-  UNUSED_VAR(p);\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  if (address != 0)\r
-  {\r
-    g_allocCount--;\r
-    fprintf(stderr, "\nFree; count = %10d", g_allocCount);\r
-  }\r
-  #endif\r
-  free(address);\r
-}\r
-\r
-void *SzAllocTemp(void *p, size_t size)\r
-{\r
-  UNUSED_VAR(p);\r
-  if (size == 0)\r
-    return 0;\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  fprintf(stderr, "\nAlloc_temp %10u bytes;  count = %10d", (unsigned)size, g_allocCountTemp);\r
-  g_allocCountTemp++;\r
-  #ifdef _WIN32\r
-  return HeapAlloc(GetProcessHeap(), 0, size);\r
-  #endif\r
-  #endif\r
-  return malloc(size);\r
-}\r
-\r
-void SzFreeTemp(void *p, void *address)\r
-{\r
-  UNUSED_VAR(p);\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  if (address != 0)\r
-  {\r
-    g_allocCountTemp--;\r
-    fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp);\r
-  }\r
-  #ifdef _WIN32\r
-  HeapFree(GetProcessHeap(), 0, address);\r
-  return;\r
-  #endif\r
-  #endif\r
-  free(address);\r
-}\r
diff --git a/deps/lzma-16.04/C/7zAlloc.h b/deps/lzma-16.04/C/7zAlloc.h
deleted file mode 100644 (file)
index 4d7502f..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* 7zAlloc.h -- Allocation functions\r
-2013-03-25 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_ALLOC_H\r
-#define __7Z_ALLOC_H\r
-\r
-#include <stdlib.h>\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-void *SzAlloc(void *p, size_t size);\r
-void SzFree(void *p, void *address);\r
-\r
-void *SzAllocTemp(void *p, size_t size);\r
-void SzFreeTemp(void *p, void *address);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/7zArcIn.c b/deps/lzma-16.04/C/7zArcIn.c
deleted file mode 100644 (file)
index c324c37..0000000
+++ /dev/null
@@ -1,1771 +0,0 @@
-/* 7zArcIn.c -- 7z Input functions\r
-2016-05-16 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-#include "7z.h"\r
-#include "7zBuf.h"\r
-#include "7zCrc.h"\r
-#include "CpuArch.h"\r
-\r
-#define MY_ALLOC(T, p, size, alloc) { \\r
-  if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == NULL) return SZ_ERROR_MEM; }\r
-\r
-#define MY_ALLOC_ZE(T, p, size, alloc) { if ((size) == 0) p = NULL; else MY_ALLOC(T, p, size, alloc) }\r
-\r
-#define MY_ALLOC_AND_CPY(to, size, from, alloc) \\r
-  { MY_ALLOC(Byte, to, size, alloc); memcpy(to, from, size); }\r
-\r
-#define MY_ALLOC_ZE_AND_CPY(to, size, from, alloc) \\r
-  { if ((size) == 0) p = NULL; else { MY_ALLOC_AND_CPY(to, size, from, alloc) } }\r
-\r
-#define k7zMajorVersion 0\r
-\r
-enum EIdEnum\r
-{\r
-  k7zIdEnd,\r
-  k7zIdHeader,\r
-  k7zIdArchiveProperties,\r
-  k7zIdAdditionalStreamsInfo,\r
-  k7zIdMainStreamsInfo,\r
-  k7zIdFilesInfo,\r
-  k7zIdPackInfo,\r
-  k7zIdUnpackInfo,\r
-  k7zIdSubStreamsInfo,\r
-  k7zIdSize,\r
-  k7zIdCRC,\r
-  k7zIdFolder,\r
-  k7zIdCodersUnpackSize,\r
-  k7zIdNumUnpackStream,\r
-  k7zIdEmptyStream,\r
-  k7zIdEmptyFile,\r
-  k7zIdAnti,\r
-  k7zIdName,\r
-  k7zIdCTime,\r
-  k7zIdATime,\r
-  k7zIdMTime,\r
-  k7zIdWinAttrib,\r
-  k7zIdComment,\r
-  k7zIdEncodedHeader,\r
-  k7zIdStartPos,\r
-  k7zIdDummy\r
-  // k7zNtSecure,\r
-  // k7zParent,\r
-  // k7zIsReal\r
-};\r
-\r
-const Byte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r
-\r
-#define SzBitUi32s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; }\r
-\r
-static SRes SzBitUi32s_Alloc(CSzBitUi32s *p, size_t num, ISzAlloc *alloc)\r
-{\r
-  if (num == 0)\r
-  {\r
-    p->Defs = NULL;\r
-    p->Vals = NULL;\r
-  }\r
-  else\r
-  {\r
-    MY_ALLOC(Byte, p->Defs, (num + 7) >> 3, alloc);\r
-    MY_ALLOC(UInt32, p->Vals, num, alloc);\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-void SzBitUi32s_Free(CSzBitUi32s *p, ISzAlloc *alloc)\r
-{\r
-  IAlloc_Free(alloc, p->Defs); p->Defs = NULL;\r
-  IAlloc_Free(alloc, p->Vals); p->Vals = NULL;\r
-}\r
-\r
-#define SzBitUi64s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; }\r
-\r
-void SzBitUi64s_Free(CSzBitUi64s *p, ISzAlloc *alloc)\r
-{\r
-  IAlloc_Free(alloc, p->Defs); p->Defs = NULL;\r
-  IAlloc_Free(alloc, p->Vals); p->Vals = NULL;\r
-}\r
-\r
-\r
-static void SzAr_Init(CSzAr *p)\r
-{\r
-  p->NumPackStreams = 0;\r
-  p->NumFolders = 0;\r
-  \r
-  p->PackPositions = NULL;\r
-  SzBitUi32s_Init(&p->FolderCRCs);\r
-\r
-  p->FoCodersOffsets = NULL;\r
-  p->FoStartPackStreamIndex = NULL;\r
-  p->FoToCoderUnpackSizes = NULL;\r
-  p->FoToMainUnpackSizeIndex = NULL;\r
-  p->CoderUnpackSizes = NULL;\r
-\r
-  p->CodersData = NULL;\r
-}\r
-\r
-static void SzAr_Free(CSzAr *p, ISzAlloc *alloc)\r
-{\r
-  IAlloc_Free(alloc, p->PackPositions);\r
-  SzBitUi32s_Free(&p->FolderCRCs, alloc);\r
\r
-  IAlloc_Free(alloc, p->FoCodersOffsets);\r
-  IAlloc_Free(alloc, p->FoStartPackStreamIndex);\r
-  IAlloc_Free(alloc, p->FoToCoderUnpackSizes);\r
-  IAlloc_Free(alloc, p->FoToMainUnpackSizeIndex);\r
-  IAlloc_Free(alloc, p->CoderUnpackSizes);\r
-  \r
-  IAlloc_Free(alloc, p->CodersData);\r
-\r
-  SzAr_Init(p);\r
-}\r
-\r
-\r
-void SzArEx_Init(CSzArEx *p)\r
-{\r
-  SzAr_Init(&p->db);\r
-  \r
-  p->NumFiles = 0;\r
-  p->dataPos = 0;\r
-  \r
-  p->UnpackPositions = NULL;\r
-  p->IsDirs = NULL;\r
-  \r
-  p->FolderToFile = NULL;\r
-  p->FileToFolder = NULL;\r
-  \r
-  p->FileNameOffsets = NULL;\r
-  p->FileNames = NULL;\r
-  \r
-  SzBitUi32s_Init(&p->CRCs);\r
-  SzBitUi32s_Init(&p->Attribs);\r
-  // SzBitUi32s_Init(&p->Parents);\r
-  SzBitUi64s_Init(&p->MTime);\r
-  SzBitUi64s_Init(&p->CTime);\r
-}\r
-\r
-void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)\r
-{\r
-  IAlloc_Free(alloc, p->UnpackPositions);\r
-  IAlloc_Free(alloc, p->IsDirs);\r
-\r
-  IAlloc_Free(alloc, p->FolderToFile);\r
-  IAlloc_Free(alloc, p->FileToFolder);\r
-\r
-  IAlloc_Free(alloc, p->FileNameOffsets);\r
-  IAlloc_Free(alloc, p->FileNames);\r
-\r
-  SzBitUi32s_Free(&p->CRCs, alloc);\r
-  SzBitUi32s_Free(&p->Attribs, alloc);\r
-  // SzBitUi32s_Free(&p->Parents, alloc);\r
-  SzBitUi64s_Free(&p->MTime, alloc);\r
-  SzBitUi64s_Free(&p->CTime, alloc);\r
-  \r
-  SzAr_Free(&p->db, alloc);\r
-  SzArEx_Init(p);\r
-}\r
-\r
-\r
-static int TestSignatureCandidate(const Byte *testBytes)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < k7zSignatureSize; i++)\r
-    if (testBytes[i] != k7zSignature[i])\r
-      return 0;\r
-  return 1;\r
-}\r
-\r
-#define SzData_Clear(p) { (p)->Data = NULL; (p)->Size = 0; }\r
-\r
-#define SZ_READ_BYTE_SD(_sd_, dest) if ((_sd_)->Size == 0) return SZ_ERROR_ARCHIVE; (_sd_)->Size--; dest = *(_sd_)->Data++;\r
-#define SZ_READ_BYTE(dest) SZ_READ_BYTE_SD(sd, dest)\r
-#define SZ_READ_BYTE_2(dest) if (sd.Size == 0) return SZ_ERROR_ARCHIVE; sd.Size--; dest = *sd.Data++;\r
-\r
-#define SKIP_DATA(sd, size) { sd->Size -= (size_t)(size); sd->Data += (size_t)(size); }\r
-#define SKIP_DATA2(sd, size) { sd.Size -= (size_t)(size); sd.Data += (size_t)(size); }\r
-\r
-#define SZ_READ_32(dest) if (sd.Size < 4) return SZ_ERROR_ARCHIVE; \\r
-   dest = GetUi32(sd.Data); SKIP_DATA2(sd, 4);\r
-\r
-static MY_NO_INLINE SRes ReadNumber(CSzData *sd, UInt64 *value)\r
-{\r
-  Byte firstByte, mask;\r
-  unsigned i;\r
-  UInt32 v;\r
-\r
-  SZ_READ_BYTE(firstByte);\r
-  if ((firstByte & 0x80) == 0)\r
-  {\r
-    *value = firstByte;\r
-    return SZ_OK;\r
-  }\r
-  SZ_READ_BYTE(v);\r
-  if ((firstByte & 0x40) == 0)\r
-  {\r
-    *value = (((UInt32)firstByte & 0x3F) << 8) | v;\r
-    return SZ_OK;\r
-  }\r
-  SZ_READ_BYTE(mask);\r
-  *value = v | ((UInt32)mask << 8);\r
-  mask = 0x20;\r
-  for (i = 2; i < 8; i++)\r
-  {\r
-    Byte b;\r
-    if ((firstByte & mask) == 0)\r
-    {\r
-      UInt64 highPart = (unsigned)firstByte & (unsigned)(mask - 1);\r
-      *value |= (highPart << (8 * i));\r
-      return SZ_OK;\r
-    }\r
-    SZ_READ_BYTE(b);\r
-    *value |= ((UInt64)b << (8 * i));\r
-    mask >>= 1;\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-\r
-static MY_NO_INLINE SRes SzReadNumber32(CSzData *sd, UInt32 *value)\r
-{\r
-  Byte firstByte;\r
-  UInt64 value64;\r
-  if (sd->Size == 0)\r
-    return SZ_ERROR_ARCHIVE;\r
-  firstByte = *sd->Data;\r
-  if ((firstByte & 0x80) == 0)\r
-  {\r
-    *value = firstByte;\r
-    sd->Data++;\r
-    sd->Size--;\r
-    return SZ_OK;\r
-  }\r
-  RINOK(ReadNumber(sd, &value64));\r
-  if (value64 >= (UInt32)0x80000000 - 1)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 4)))\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  *value = (UInt32)value64;\r
-  return SZ_OK;\r
-}\r
-\r
-#define ReadID(sd, value) ReadNumber(sd, value)\r
-\r
-static SRes SkipData(CSzData *sd)\r
-{\r
-  UInt64 size;\r
-  RINOK(ReadNumber(sd, &size));\r
-  if (size > sd->Size)\r
-    return SZ_ERROR_ARCHIVE;\r
-  SKIP_DATA(sd, size);\r
-  return SZ_OK;\r
-}\r
-\r
-static SRes WaitId(CSzData *sd, UInt32 id)\r
-{\r
-  for (;;)\r
-  {\r
-    UInt64 type;\r
-    RINOK(ReadID(sd, &type));\r
-    if (type == id)\r
-      return SZ_OK;\r
-    if (type == k7zIdEnd)\r
-      return SZ_ERROR_ARCHIVE;\r
-    RINOK(SkipData(sd));\r
-  }\r
-}\r
-\r
-static SRes RememberBitVector(CSzData *sd, UInt32 numItems, const Byte **v)\r
-{\r
-  UInt32 numBytes = (numItems + 7) >> 3;\r
-  if (numBytes > sd->Size)\r
-    return SZ_ERROR_ARCHIVE;\r
-  *v = sd->Data;\r
-  SKIP_DATA(sd, numBytes);\r
-  return SZ_OK;\r
-}\r
-\r
-static UInt32 CountDefinedBits(const Byte *bits, UInt32 numItems)\r
-{\r
-  Byte b = 0;\r
-  unsigned m = 0;\r
-  UInt32 sum = 0;\r
-  for (; numItems != 0; numItems--)\r
-  {\r
-    if (m == 0)\r
-    {\r
-      b = *bits++;\r
-      m = 8;\r
-    }\r
-    m--;\r
-    sum += ((b >> m) & 1);\r
-  }\r
-  return sum;\r
-}\r
-\r
-static MY_NO_INLINE SRes ReadBitVector(CSzData *sd, UInt32 numItems, Byte **v, ISzAlloc *alloc)\r
-{\r
-  Byte allAreDefined;\r
-  Byte *v2;\r
-  UInt32 numBytes = (numItems + 7) >> 3;\r
-  *v = NULL;\r
-  SZ_READ_BYTE(allAreDefined);\r
-  if (numBytes == 0)\r
-    return SZ_OK;\r
-  if (allAreDefined == 0)\r
-  {\r
-    if (numBytes > sd->Size)\r
-      return SZ_ERROR_ARCHIVE;\r
-    MY_ALLOC_AND_CPY(*v, numBytes, sd->Data, alloc);\r
-    SKIP_DATA(sd, numBytes);\r
-    return SZ_OK;\r
-  }\r
-  MY_ALLOC(Byte, *v, numBytes, alloc);\r
-  v2 = *v;\r
-  memset(v2, 0xFF, (size_t)numBytes);\r
-  {\r
-    unsigned numBits = (unsigned)numItems & 7;\r
-    if (numBits != 0)\r
-      v2[numBytes - 1] = (Byte)((((UInt32)1 << numBits) - 1) << (8 - numBits));\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-static MY_NO_INLINE SRes ReadUi32s(CSzData *sd2, UInt32 numItems, CSzBitUi32s *crcs, ISzAlloc *alloc)\r
-{\r
-  UInt32 i;\r
-  CSzData sd;\r
-  UInt32 *vals;\r
-  const Byte *defs;\r
-  MY_ALLOC_ZE(UInt32, crcs->Vals, numItems, alloc);\r
-  sd = *sd2;\r
-  defs = crcs->Defs;\r
-  vals = crcs->Vals;\r
-  for (i = 0; i < numItems; i++)\r
-    if (SzBitArray_Check(defs, i))\r
-    {\r
-      SZ_READ_32(vals[i]);\r
-    }\r
-    else\r
-      vals[i] = 0;\r
-  *sd2 = sd;\r
-  return SZ_OK;\r
-}\r
-\r
-static SRes ReadBitUi32s(CSzData *sd, UInt32 numItems, CSzBitUi32s *crcs, ISzAlloc *alloc)\r
-{\r
-  SzBitUi32s_Free(crcs, alloc);\r
-  RINOK(ReadBitVector(sd, numItems, &crcs->Defs, alloc));\r
-  return ReadUi32s(sd, numItems, crcs, alloc);\r
-}\r
-\r
-static SRes SkipBitUi32s(CSzData *sd, UInt32 numItems)\r
-{\r
-  Byte allAreDefined;\r
-  UInt32 numDefined = numItems;\r
-  SZ_READ_BYTE(allAreDefined);\r
-  if (!allAreDefined)\r
-  {\r
-    size_t numBytes = (numItems + 7) >> 3;\r
-    if (numBytes > sd->Size)\r
-      return SZ_ERROR_ARCHIVE;\r
-    numDefined = CountDefinedBits(sd->Data, numItems);\r
-    SKIP_DATA(sd, numBytes);\r
-  }\r
-  if (numDefined > (sd->Size >> 2))\r
-    return SZ_ERROR_ARCHIVE;\r
-  SKIP_DATA(sd, (size_t)numDefined * 4);\r
-  return SZ_OK;\r
-}\r
-\r
-static SRes ReadPackInfo(CSzAr *p, CSzData *sd, ISzAlloc *alloc)\r
-{\r
-  RINOK(SzReadNumber32(sd, &p->NumPackStreams));\r
-\r
-  RINOK(WaitId(sd, k7zIdSize));\r
-  MY_ALLOC(UInt64, p->PackPositions, (size_t)p->NumPackStreams + 1, alloc);\r
-  {\r
-    UInt64 sum = 0;\r
-    UInt32 i;\r
-    UInt32 numPackStreams = p->NumPackStreams;\r
-    for (i = 0; i < numPackStreams; i++)\r
-    {\r
-      UInt64 packSize;\r
-      p->PackPositions[i] = sum;\r
-      RINOK(ReadNumber(sd, &packSize));\r
-      sum += packSize;\r
-      if (sum < packSize)\r
-        return SZ_ERROR_ARCHIVE;\r
-    }\r
-    p->PackPositions[i] = sum;\r
-  }\r
-\r
-  for (;;)\r
-  {\r
-    UInt64 type;\r
-    RINOK(ReadID(sd, &type));\r
-    if (type == k7zIdEnd)\r
-      return SZ_OK;\r
-    if (type == k7zIdCRC)\r
-    {\r
-      /* CRC of packed streams is unused now */\r
-      RINOK(SkipBitUi32s(sd, p->NumPackStreams));\r
-      continue;\r
-    }\r
-    RINOK(SkipData(sd));\r
-  }\r
-}\r
-\r
-/*\r
-static SRes SzReadSwitch(CSzData *sd)\r
-{\r
-  Byte external;\r
-  RINOK(SzReadByte(sd, &external));\r
-  return (external == 0) ? SZ_OK: SZ_ERROR_UNSUPPORTED;\r
-}\r
-*/\r
-\r
-#define k_NumCodersStreams_in_Folder_MAX (SZ_NUM_BONDS_IN_FOLDER_MAX + SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX)\r
-\r
-SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd)\r
-{\r
-  UInt32 numCoders, i;\r
-  UInt32 numInStreams = 0;\r
-  const Byte *dataStart = sd->Data;\r
-\r
-  f->NumCoders = 0;\r
-  f->NumBonds = 0;\r
-  f->NumPackStreams = 0;\r
-  f->UnpackStream = 0;\r
-  \r
-  RINOK(SzReadNumber32(sd, &numCoders));\r
-  if (numCoders == 0 || numCoders > SZ_NUM_CODERS_IN_FOLDER_MAX)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  \r
-  for (i = 0; i < numCoders; i++)\r
-  {\r
-    Byte mainByte;\r
-    CSzCoderInfo *coder = f->Coders + i;\r
-    unsigned idSize, j;\r
-    UInt64 id;\r
-    \r
-    SZ_READ_BYTE(mainByte);\r
-    if ((mainByte & 0xC0) != 0)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    \r
-    idSize = (unsigned)(mainByte & 0xF);\r
-    if (idSize > sizeof(id))\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    if (idSize > sd->Size)\r
-      return SZ_ERROR_ARCHIVE;\r
-    id = 0;\r
-    for (j = 0; j < idSize; j++)\r
-    {\r
-      id = ((id << 8) | *sd->Data);\r
-      sd->Data++;\r
-      sd->Size--;\r
-    }\r
-    if (id > (UInt32)0xFFFFFFFF)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    coder->MethodID = (UInt32)id;\r
-    \r
-    coder->NumStreams = 1;\r
-    coder->PropsOffset = 0;\r
-    coder->PropsSize = 0;\r
-    \r
-    if ((mainByte & 0x10) != 0)\r
-    {\r
-      UInt32 numStreams;\r
-      \r
-      RINOK(SzReadNumber32(sd, &numStreams));\r
-      if (numStreams > k_NumCodersStreams_in_Folder_MAX)\r
-        return SZ_ERROR_UNSUPPORTED;\r
-      coder->NumStreams = (Byte)numStreams;\r
-\r
-      RINOK(SzReadNumber32(sd, &numStreams));\r
-      if (numStreams != 1)\r
-        return SZ_ERROR_UNSUPPORTED;\r
-    }\r
-\r
-    numInStreams += coder->NumStreams;\r
-\r
-    if (numInStreams > k_NumCodersStreams_in_Folder_MAX)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-\r
-    if ((mainByte & 0x20) != 0)\r
-    {\r
-      UInt32 propsSize = 0;\r
-      RINOK(SzReadNumber32(sd, &propsSize));\r
-      if (propsSize > sd->Size)\r
-        return SZ_ERROR_ARCHIVE;\r
-      if (propsSize >= 0x80)\r
-        return SZ_ERROR_UNSUPPORTED;\r
-      coder->PropsOffset = sd->Data - dataStart;\r
-      coder->PropsSize = (Byte)propsSize;\r
-      sd->Data += (size_t)propsSize;\r
-      sd->Size -= (size_t)propsSize;\r
-    }\r
-  }\r
-\r
-  /*\r
-  if (numInStreams == 1 && numCoders == 1)\r
-  {\r
-    f->NumPackStreams = 1;\r
-    f->PackStreams[0] = 0;\r
-  }\r
-  else\r
-  */\r
-  {\r
-    Byte streamUsed[k_NumCodersStreams_in_Folder_MAX];\r
-    UInt32 numBonds, numPackStreams;\r
-    \r
-    numBonds = numCoders - 1;\r
-    if (numInStreams < numBonds)\r
-      return SZ_ERROR_ARCHIVE;\r
-    if (numBonds > SZ_NUM_BONDS_IN_FOLDER_MAX)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    f->NumBonds = numBonds;\r
-    \r
-    numPackStreams = numInStreams - numBonds;\r
-    if (numPackStreams > SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    f->NumPackStreams = numPackStreams;\r
-  \r
-    for (i = 0; i < numInStreams; i++)\r
-      streamUsed[i] = False;\r
-    \r
-    if (numBonds != 0)\r
-    {\r
-      Byte coderUsed[SZ_NUM_CODERS_IN_FOLDER_MAX];\r
-\r
-      for (i = 0; i < numCoders; i++)\r
-        coderUsed[i] = False;\r
-      \r
-      for (i = 0; i < numBonds; i++)\r
-      {\r
-        CSzBond *bp = f->Bonds + i;\r
-        \r
-        RINOK(SzReadNumber32(sd, &bp->InIndex));\r
-        if (bp->InIndex >= numInStreams || streamUsed[bp->InIndex])\r
-          return SZ_ERROR_ARCHIVE;\r
-        streamUsed[bp->InIndex] = True;\r
-        \r
-        RINOK(SzReadNumber32(sd, &bp->OutIndex));\r
-        if (bp->OutIndex >= numCoders || coderUsed[bp->OutIndex])\r
-          return SZ_ERROR_ARCHIVE;\r
-        coderUsed[bp->OutIndex] = True;\r
-      }\r
-      \r
-      for (i = 0; i < numCoders; i++)\r
-        if (!coderUsed[i])\r
-        {\r
-          f->UnpackStream = i;\r
-          break;\r
-        }\r
-      \r
-      if (i == numCoders)\r
-        return SZ_ERROR_ARCHIVE;\r
-    }\r
-    \r
-    if (numPackStreams == 1)\r
-    {\r
-      for (i = 0; i < numInStreams; i++)\r
-        if (!streamUsed[i])\r
-          break;\r
-      if (i == numInStreams)\r
-        return SZ_ERROR_ARCHIVE;\r
-      f->PackStreams[0] = i;\r
-    }\r
-    else\r
-      for (i = 0; i < numPackStreams; i++)\r
-      {\r
-        UInt32 index;\r
-        RINOK(SzReadNumber32(sd, &index));\r
-        if (index >= numInStreams || streamUsed[index])\r
-          return SZ_ERROR_ARCHIVE;\r
-        streamUsed[index] = True;\r
-        f->PackStreams[i] = index;\r
-      }\r
-  }\r
-\r
-  f->NumCoders = numCoders;\r
-\r
-  return SZ_OK;\r
-}\r
-\r
-\r
-static MY_NO_INLINE SRes SkipNumbers(CSzData *sd2, UInt32 num)\r
-{\r
-  CSzData sd;\r
-  sd = *sd2;\r
-  for (; num != 0; num--)\r
-  {\r
-    Byte firstByte, mask;\r
-    unsigned i;\r
-    SZ_READ_BYTE_2(firstByte);\r
-    if ((firstByte & 0x80) == 0)\r
-      continue;\r
-    if ((firstByte & 0x40) == 0)\r
-    {\r
-      if (sd.Size == 0)\r
-        return SZ_ERROR_ARCHIVE;\r
-      sd.Size--;\r
-      sd.Data++;\r
-      continue;\r
-    }\r
-    mask = 0x20;\r
-    for (i = 2; i < 8 && (firstByte & mask) != 0; i++)\r
-      mask >>= 1;\r
-    if (i > sd.Size)\r
-      return SZ_ERROR_ARCHIVE;\r
-    SKIP_DATA2(sd, i);\r
-  }\r
-  *sd2 = sd;\r
-  return SZ_OK;\r
-}\r
-\r
-\r
-#define k_Scan_NumCoders_MAX 64\r
-#define k_Scan_NumCodersStreams_in_Folder_MAX 64\r
-\r
-\r
-static SRes ReadUnpackInfo(CSzAr *p,\r
-    CSzData *sd2,\r
-    UInt32 numFoldersMax,\r
-    const CBuf *tempBufs, UInt32 numTempBufs,\r
-    ISzAlloc *alloc)\r
-{\r
-  CSzData sd;\r
-  \r
-  UInt32 fo, numFolders, numCodersOutStreams, packStreamIndex;\r
-  const Byte *startBufPtr;\r
-  Byte external;\r
-  \r
-  RINOK(WaitId(sd2, k7zIdFolder));\r
-  \r
-  RINOK(SzReadNumber32(sd2, &numFolders));\r
-  if (numFolders > numFoldersMax)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  p->NumFolders = numFolders;\r
-\r
-  SZ_READ_BYTE_SD(sd2, external);\r
-  if (external == 0)\r
-    sd = *sd2;\r
-  else\r
-  {\r
-    UInt32 index;\r
-    RINOK(SzReadNumber32(sd2, &index));\r
-    if (index >= numTempBufs)\r
-      return SZ_ERROR_ARCHIVE;\r
-    sd.Data = tempBufs[index].data;\r
-    sd.Size = tempBufs[index].size;\r
-  }\r
-  \r
-  MY_ALLOC(size_t, p->FoCodersOffsets, (size_t)numFolders + 1, alloc);\r
-  MY_ALLOC(UInt32, p->FoStartPackStreamIndex, (size_t)numFolders + 1, alloc);\r
-  MY_ALLOC(UInt32, p->FoToCoderUnpackSizes, (size_t)numFolders + 1, alloc);\r
-  MY_ALLOC(Byte, p->FoToMainUnpackSizeIndex, (size_t)numFolders, alloc);\r
-  \r
-  startBufPtr = sd.Data;\r
-  \r
-  packStreamIndex = 0;\r
-  numCodersOutStreams = 0;\r
-\r
-  for (fo = 0; fo < numFolders; fo++)\r
-  {\r
-    UInt32 numCoders, ci, numInStreams = 0;\r
-    \r
-    p->FoCodersOffsets[fo] = sd.Data - startBufPtr;\r
-    \r
-    RINOK(SzReadNumber32(&sd, &numCoders));\r
-    if (numCoders == 0 || numCoders > k_Scan_NumCoders_MAX)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    \r
-    for (ci = 0; ci < numCoders; ci++)\r
-    {\r
-      Byte mainByte;\r
-      unsigned idSize;\r
-      UInt32 coderInStreams;\r
-      \r
-      SZ_READ_BYTE_2(mainByte);\r
-      if ((mainByte & 0xC0) != 0)\r
-        return SZ_ERROR_UNSUPPORTED;\r
-      idSize = (mainByte & 0xF);\r
-      if (idSize > 8)\r
-        return SZ_ERROR_UNSUPPORTED;\r
-      if (idSize > sd.Size)\r
-        return SZ_ERROR_ARCHIVE;\r
-      SKIP_DATA2(sd, idSize);\r
-      \r
-      coderInStreams = 1;\r
-      \r
-      if ((mainByte & 0x10) != 0)\r
-      {\r
-        UInt32 coderOutStreams;\r
-        RINOK(SzReadNumber32(&sd, &coderInStreams));\r
-        RINOK(SzReadNumber32(&sd, &coderOutStreams));\r
-        if (coderInStreams > k_Scan_NumCodersStreams_in_Folder_MAX || coderOutStreams != 1)\r
-          return SZ_ERROR_UNSUPPORTED;\r
-      }\r
-      \r
-      numInStreams += coderInStreams;\r
-\r
-      if ((mainByte & 0x20) != 0)\r
-      {\r
-        UInt32 propsSize;\r
-        RINOK(SzReadNumber32(&sd, &propsSize));\r
-        if (propsSize > sd.Size)\r
-          return SZ_ERROR_ARCHIVE;\r
-        SKIP_DATA2(sd, propsSize);\r
-      }\r
-    }\r
-    \r
-    {\r
-      UInt32 indexOfMainStream = 0;\r
-      UInt32 numPackStreams = 1;\r
-      \r
-      if (numCoders != 1 || numInStreams != 1)\r
-      {\r
-        Byte streamUsed[k_Scan_NumCodersStreams_in_Folder_MAX];\r
-        Byte coderUsed[k_Scan_NumCoders_MAX];\r
-    \r
-        UInt32 i;\r
-        UInt32 numBonds = numCoders - 1;\r
-        if (numInStreams < numBonds)\r
-          return SZ_ERROR_ARCHIVE;\r
-        \r
-        if (numInStreams > k_Scan_NumCodersStreams_in_Folder_MAX)\r
-          return SZ_ERROR_UNSUPPORTED;\r
-        \r
-        for (i = 0; i < numInStreams; i++)\r
-          streamUsed[i] = False;\r
-        for (i = 0; i < numCoders; i++)\r
-          coderUsed[i] = False;\r
-        \r
-        for (i = 0; i < numBonds; i++)\r
-        {\r
-          UInt32 index;\r
-          \r
-          RINOK(SzReadNumber32(&sd, &index));\r
-          if (index >= numInStreams || streamUsed[index])\r
-            return SZ_ERROR_ARCHIVE;\r
-          streamUsed[index] = True;\r
-          \r
-          RINOK(SzReadNumber32(&sd, &index));\r
-          if (index >= numCoders || coderUsed[index])\r
-            return SZ_ERROR_ARCHIVE;\r
-          coderUsed[index] = True;\r
-        }\r
-        \r
-        numPackStreams = numInStreams - numBonds;\r
-        \r
-        if (numPackStreams != 1)\r
-          for (i = 0; i < numPackStreams; i++)\r
-          {\r
-            UInt32 index;\r
-            RINOK(SzReadNumber32(&sd, &index));\r
-            if (index >= numInStreams || streamUsed[index])\r
-              return SZ_ERROR_ARCHIVE;\r
-            streamUsed[index] = True;\r
-          }\r
-          \r
-        for (i = 0; i < numCoders; i++)\r
-          if (!coderUsed[i])\r
-          {\r
-            indexOfMainStream = i;\r
-            break;\r
-          }\r
\r
-        if (i == numCoders)\r
-          return SZ_ERROR_ARCHIVE;\r
-      }\r
-      \r
-      p->FoStartPackStreamIndex[fo] = packStreamIndex;\r
-      p->FoToCoderUnpackSizes[fo] = numCodersOutStreams;\r
-      p->FoToMainUnpackSizeIndex[fo] = (Byte)indexOfMainStream;\r
-      numCodersOutStreams += numCoders;\r
-      if (numCodersOutStreams < numCoders)\r
-        return SZ_ERROR_UNSUPPORTED;\r
-      if (numPackStreams > p->NumPackStreams - packStreamIndex)\r
-        return SZ_ERROR_ARCHIVE;\r
-      packStreamIndex += numPackStreams;\r
-    }\r
-  }\r
-\r
-  p->FoToCoderUnpackSizes[fo] = numCodersOutStreams;\r
-  \r
-  {\r
-    size_t dataSize = sd.Data - startBufPtr;\r
-    p->FoStartPackStreamIndex[fo] = packStreamIndex;\r
-    p->FoCodersOffsets[fo] = dataSize;\r
-    MY_ALLOC_ZE_AND_CPY(p->CodersData, dataSize, startBufPtr, alloc);\r
-  }\r
-  \r
-  if (external != 0)\r
-  {\r
-    if (sd.Size != 0)\r
-      return SZ_ERROR_ARCHIVE;\r
-    sd = *sd2;\r
-  }\r
-  \r
-  RINOK(WaitId(&sd, k7zIdCodersUnpackSize));\r
-  \r
-  MY_ALLOC_ZE(UInt64, p->CoderUnpackSizes, (size_t)numCodersOutStreams, alloc);\r
-  {\r
-    UInt32 i;\r
-    for (i = 0; i < numCodersOutStreams; i++)\r
-    {\r
-      RINOK(ReadNumber(&sd, p->CoderUnpackSizes + i));\r
-    }\r
-  }\r
-\r
-  for (;;)\r
-  {\r
-    UInt64 type;\r
-    RINOK(ReadID(&sd, &type));\r
-    if (type == k7zIdEnd)\r
-    {\r
-      *sd2 = sd;\r
-      return SZ_OK;\r
-    }\r
-    if (type == k7zIdCRC)\r
-    {\r
-      RINOK(ReadBitUi32s(&sd, numFolders, &p->FolderCRCs, alloc));\r
-      continue;\r
-    }\r
-    RINOK(SkipData(&sd));\r
-  }\r
-}\r
-\r
-\r
-UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex)\r
-{\r
-  return p->CoderUnpackSizes[p->FoToCoderUnpackSizes[folderIndex] + p->FoToMainUnpackSizeIndex[folderIndex]];\r
-}\r
-\r
-\r
-typedef struct\r
-{\r
-  UInt32 NumTotalSubStreams;\r
-  UInt32 NumSubDigests;\r
-  CSzData sdNumSubStreams;\r
-  CSzData sdSizes;\r
-  CSzData sdCRCs;\r
-} CSubStreamInfo;\r
-\r
-\r
-static SRes ReadSubStreamsInfo(CSzAr *p, CSzData *sd, CSubStreamInfo *ssi)\r
-{\r
-  UInt64 type = 0;\r
-  UInt32 numSubDigests = 0;\r
-  UInt32 numFolders = p->NumFolders;\r
-  UInt32 numUnpackStreams = numFolders;\r
-  UInt32 numUnpackSizesInData = 0;\r
-\r
-  for (;;)\r
-  {\r
-    RINOK(ReadID(sd, &type));\r
-    if (type == k7zIdNumUnpackStream)\r
-    {\r
-      UInt32 i;\r
-      ssi->sdNumSubStreams.Data = sd->Data;\r
-      numUnpackStreams = 0;\r
-      numSubDigests = 0;\r
-      for (i = 0; i < numFolders; i++)\r
-      {\r
-        UInt32 numStreams;\r
-        RINOK(SzReadNumber32(sd, &numStreams));\r
-        if (numUnpackStreams > numUnpackStreams + numStreams)\r
-          return SZ_ERROR_UNSUPPORTED;\r
-        numUnpackStreams += numStreams;\r
-        if (numStreams != 0)\r
-          numUnpackSizesInData += (numStreams - 1);\r
-        if (numStreams != 1 || !SzBitWithVals_Check(&p->FolderCRCs, i))\r
-          numSubDigests += numStreams;\r
-      }\r
-      ssi->sdNumSubStreams.Size = sd->Data - ssi->sdNumSubStreams.Data;\r
-      continue;\r
-    }\r
-    if (type == k7zIdCRC || type == k7zIdSize || type == k7zIdEnd)\r
-      break;\r
-    RINOK(SkipData(sd));\r
-  }\r
-\r
-  if (!ssi->sdNumSubStreams.Data)\r
-  {\r
-    numSubDigests = numFolders;\r
-    if (p->FolderCRCs.Defs)\r
-      numSubDigests = numFolders - CountDefinedBits(p->FolderCRCs.Defs, numFolders);\r
-  }\r
-  \r
-  ssi->NumTotalSubStreams = numUnpackStreams;\r
-  ssi->NumSubDigests = numSubDigests;\r
-\r
-  if (type == k7zIdSize)\r
-  {\r
-    ssi->sdSizes.Data = sd->Data;\r
-    RINOK(SkipNumbers(sd, numUnpackSizesInData));\r
-    ssi->sdSizes.Size = sd->Data - ssi->sdSizes.Data;\r
-    RINOK(ReadID(sd, &type));\r
-  }\r
-\r
-  for (;;)\r
-  {\r
-    if (type == k7zIdEnd)\r
-      return SZ_OK;\r
-    if (type == k7zIdCRC)\r
-    {\r
-      ssi->sdCRCs.Data = sd->Data;\r
-      RINOK(SkipBitUi32s(sd, numSubDigests));\r
-      ssi->sdCRCs.Size = sd->Data - ssi->sdCRCs.Data;\r
-    }\r
-    else\r
-    {\r
-      RINOK(SkipData(sd));\r
-    }\r
-    RINOK(ReadID(sd, &type));\r
-  }\r
-}\r
-\r
-static SRes SzReadStreamsInfo(CSzAr *p,\r
-    CSzData *sd,\r
-    UInt32 numFoldersMax, const CBuf *tempBufs, UInt32 numTempBufs,\r
-    UInt64 *dataOffset,\r
-    CSubStreamInfo *ssi,\r
-    ISzAlloc *alloc)\r
-{\r
-  UInt64 type;\r
-\r
-  SzData_Clear(&ssi->sdSizes);\r
-  SzData_Clear(&ssi->sdCRCs);\r
-  SzData_Clear(&ssi->sdNumSubStreams);\r
-\r
-  *dataOffset = 0;\r
-  RINOK(ReadID(sd, &type));\r
-  if (type == k7zIdPackInfo)\r
-  {\r
-    RINOK(ReadNumber(sd, dataOffset));\r
-    RINOK(ReadPackInfo(p, sd, alloc));\r
-    RINOK(ReadID(sd, &type));\r
-  }\r
-  if (type == k7zIdUnpackInfo)\r
-  {\r
-    RINOK(ReadUnpackInfo(p, sd, numFoldersMax, tempBufs, numTempBufs, alloc));\r
-    RINOK(ReadID(sd, &type));\r
-  }\r
-  if (type == k7zIdSubStreamsInfo)\r
-  {\r
-    RINOK(ReadSubStreamsInfo(p, sd, ssi));\r
-    RINOK(ReadID(sd, &type));\r
-  }\r
-  else\r
-  {\r
-    ssi->NumTotalSubStreams = p->NumFolders;\r
-    // ssi->NumSubDigests = 0;\r
-  }\r
-\r
-  return (type == k7zIdEnd ? SZ_OK : SZ_ERROR_UNSUPPORTED);\r
-}\r
-\r
-static SRes SzReadAndDecodePackedStreams(\r
-    ILookInStream *inStream,\r
-    CSzData *sd,\r
-    CBuf *tempBufs,\r
-    UInt32 numFoldersMax,\r
-    UInt64 baseOffset,\r
-    CSzAr *p,\r
-    ISzAlloc *allocTemp)\r
-{\r
-  UInt64 dataStartPos;\r
-  UInt32 fo;\r
-  CSubStreamInfo ssi;\r
-\r
-  RINOK(SzReadStreamsInfo(p, sd, numFoldersMax, NULL, 0, &dataStartPos, &ssi, allocTemp));\r
-  \r
-  dataStartPos += baseOffset;\r
-  if (p->NumFolders == 0)\r
-    return SZ_ERROR_ARCHIVE;\r
\r
-  for (fo = 0; fo < p->NumFolders; fo++)\r
-    Buf_Init(tempBufs + fo);\r
-  \r
-  for (fo = 0; fo < p->NumFolders; fo++)\r
-  {\r
-    CBuf *tempBuf = tempBufs + fo;\r
-    UInt64 unpackSize = SzAr_GetFolderUnpackSize(p, fo);\r
-    if ((size_t)unpackSize != unpackSize)\r
-      return SZ_ERROR_MEM;\r
-    if (!Buf_Create(tempBuf, (size_t)unpackSize, allocTemp))\r
-      return SZ_ERROR_MEM;\r
-  }\r
-  \r
-  for (fo = 0; fo < p->NumFolders; fo++)\r
-  {\r
-    const CBuf *tempBuf = tempBufs + fo;\r
-    RINOK(LookInStream_SeekTo(inStream, dataStartPos));\r
-    RINOK(SzAr_DecodeFolder(p, fo, inStream, dataStartPos, tempBuf->data, tempBuf->size, allocTemp));\r
-  }\r
-  \r
-  return SZ_OK;\r
-}\r
-\r
-static SRes SzReadFileNames(const Byte *data, size_t size, UInt32 numFiles, size_t *offsets)\r
-{\r
-  size_t pos = 0;\r
-  *offsets++ = 0;\r
-  if (numFiles == 0)\r
-    return (size == 0) ? SZ_OK : SZ_ERROR_ARCHIVE;\r
-  if (size < 2)\r
-    return SZ_ERROR_ARCHIVE;\r
-  if (data[size - 2] != 0 || data[size - 1] != 0)\r
-    return SZ_ERROR_ARCHIVE;\r
-  do\r
-  {\r
-    const Byte *p;\r
-    if (pos == size)\r
-      return SZ_ERROR_ARCHIVE;\r
-    for (p = data + pos;\r
-      #ifdef _WIN32\r
-      *(const UInt16 *)p != 0\r
-      #else\r
-      p[0] != 0 || p[1] != 0\r
-      #endif\r
-      ; p += 2);\r
-    pos = p - data + 2;\r
-    *offsets++ = (pos >> 1);\r
-  }\r
-  while (--numFiles);\r
-  return (pos == size) ? SZ_OK : SZ_ERROR_ARCHIVE;\r
-}\r
-\r
-static MY_NO_INLINE SRes ReadTime(CSzBitUi64s *p, UInt32 num,\r
-    CSzData *sd2,\r
-    const CBuf *tempBufs, UInt32 numTempBufs,\r
-    ISzAlloc *alloc)\r
-{\r
-  CSzData sd;\r
-  UInt32 i;\r
-  CNtfsFileTime *vals;\r
-  Byte *defs;\r
-  Byte external;\r
-  \r
-  RINOK(ReadBitVector(sd2, num, &p->Defs, alloc));\r
-  \r
-  SZ_READ_BYTE_SD(sd2, external);\r
-  if (external == 0)\r
-    sd = *sd2;\r
-  else\r
-  {\r
-    UInt32 index;\r
-    RINOK(SzReadNumber32(sd2, &index));\r
-    if (index >= numTempBufs)\r
-      return SZ_ERROR_ARCHIVE;\r
-    sd.Data = tempBufs[index].data;\r
-    sd.Size = tempBufs[index].size;\r
-  }\r
-  \r
-  MY_ALLOC_ZE(CNtfsFileTime, p->Vals, num, alloc);\r
-  vals = p->Vals;\r
-  defs = p->Defs;\r
-  for (i = 0; i < num; i++)\r
-    if (SzBitArray_Check(defs, i))\r
-    {\r
-      if (sd.Size < 8)\r
-        return SZ_ERROR_ARCHIVE;\r
-      vals[i].Low = GetUi32(sd.Data);\r
-      vals[i].High = GetUi32(sd.Data + 4);\r
-      SKIP_DATA2(sd, 8);\r
-    }\r
-    else\r
-      vals[i].High = vals[i].Low = 0;\r
-  \r
-  if (external == 0)\r
-    *sd2 = sd;\r
-  \r
-  return SZ_OK;\r
-}\r
-\r
-\r
-#define NUM_ADDITIONAL_STREAMS_MAX 8\r
-\r
-\r
-static SRes SzReadHeader2(\r
-    CSzArEx *p,   /* allocMain */\r
-    CSzData *sd,\r
-    ILookInStream *inStream,\r
-    CBuf *tempBufs, UInt32 *numTempBufs,\r
-    ISzAlloc *allocMain,\r
-    ISzAlloc *allocTemp\r
-    )\r
-{\r
-  CSubStreamInfo ssi;\r
-\r
-{\r
-  UInt64 type;\r
-  \r
-  SzData_Clear(&ssi.sdSizes);\r
-  SzData_Clear(&ssi.sdCRCs);\r
-  SzData_Clear(&ssi.sdNumSubStreams);\r
-\r
-  ssi.NumSubDigests = 0;\r
-  ssi.NumTotalSubStreams = 0;\r
-\r
-  RINOK(ReadID(sd, &type));\r
-\r
-  if (type == k7zIdArchiveProperties)\r
-  {\r
-    for (;;)\r
-    {\r
-      UInt64 type2;\r
-      RINOK(ReadID(sd, &type2));\r
-      if (type2 == k7zIdEnd)\r
-        break;\r
-      RINOK(SkipData(sd));\r
-    }\r
-    RINOK(ReadID(sd, &type));\r
-  }\r
-\r
-  if (type == k7zIdAdditionalStreamsInfo)\r
-  {\r
-    CSzAr tempAr;\r
-    SRes res;\r
-    \r
-    SzAr_Init(&tempAr);\r
-    res = SzReadAndDecodePackedStreams(inStream, sd, tempBufs, NUM_ADDITIONAL_STREAMS_MAX,\r
-        p->startPosAfterHeader, &tempAr, allocTemp);\r
-    *numTempBufs = tempAr.NumFolders;\r
-    SzAr_Free(&tempAr, allocTemp);\r
-    \r
-    if (res != SZ_OK)\r
-      return res;\r
-    RINOK(ReadID(sd, &type));\r
-  }\r
-\r
-  if (type == k7zIdMainStreamsInfo)\r
-  {\r
-    RINOK(SzReadStreamsInfo(&p->db, sd, (UInt32)1 << 30, tempBufs, *numTempBufs,\r
-        &p->dataPos, &ssi, allocMain));\r
-    p->dataPos += p->startPosAfterHeader;\r
-    RINOK(ReadID(sd, &type));\r
-  }\r
-\r
-  if (type == k7zIdEnd)\r
-  {\r
-    return SZ_OK;\r
-  }\r
-\r
-  if (type != k7zIdFilesInfo)\r
-    return SZ_ERROR_ARCHIVE;\r
-}\r
-\r
-{\r
-  UInt32 numFiles = 0;\r
-  UInt32 numEmptyStreams = 0;\r
-  const Byte *emptyStreams = NULL;\r
-  const Byte *emptyFiles = NULL;\r
-  \r
-  RINOK(SzReadNumber32(sd, &numFiles));\r
-  p->NumFiles = numFiles;\r
-\r
-  for (;;)\r
-  {\r
-    UInt64 type;\r
-    UInt64 size;\r
-    RINOK(ReadID(sd, &type));\r
-    if (type == k7zIdEnd)\r
-      break;\r
-    RINOK(ReadNumber(sd, &size));\r
-    if (size > sd->Size)\r
-      return SZ_ERROR_ARCHIVE;\r
-    \r
-    if (type >= ((UInt32)1 << 8))\r
-    {\r
-      SKIP_DATA(sd, size);\r
-    }\r
-    else switch ((unsigned)type)\r
-    {\r
-      case k7zIdName:\r
-      {\r
-        size_t namesSize;\r
-        const Byte *namesData;\r
-        Byte external;\r
-\r
-        SZ_READ_BYTE(external);\r
-        if (external == 0)\r
-        {\r
-          namesSize = (size_t)size - 1;\r
-          namesData = sd->Data;\r
-        }\r
-        else\r
-        {\r
-          UInt32 index;\r
-          RINOK(SzReadNumber32(sd, &index));\r
-          if (index >= *numTempBufs)\r
-            return SZ_ERROR_ARCHIVE;\r
-          namesData = (tempBufs)[index].data;\r
-          namesSize = (tempBufs)[index].size;\r
-        }\r
-\r
-        if ((namesSize & 1) != 0)\r
-          return SZ_ERROR_ARCHIVE;\r
-        MY_ALLOC(size_t, p->FileNameOffsets, numFiles + 1, allocMain);\r
-        MY_ALLOC_ZE_AND_CPY(p->FileNames, namesSize, namesData, allocMain);\r
-        RINOK(SzReadFileNames(p->FileNames, namesSize, numFiles, p->FileNameOffsets))\r
-        if (external == 0)\r
-        {\r
-          SKIP_DATA(sd, namesSize);\r
-        }\r
-        break;\r
-      }\r
-      case k7zIdEmptyStream:\r
-      {\r
-        RINOK(RememberBitVector(sd, numFiles, &emptyStreams));\r
-        numEmptyStreams = CountDefinedBits(emptyStreams, numFiles);\r
-        emptyFiles = NULL;\r
-        break;\r
-      }\r
-      case k7zIdEmptyFile:\r
-      {\r
-        RINOK(RememberBitVector(sd, numEmptyStreams, &emptyFiles));\r
-        break;\r
-      }\r
-      case k7zIdWinAttrib:\r
-      {\r
-        Byte external;\r
-        CSzData sdSwitch;\r
-        CSzData *sdPtr;\r
-        SzBitUi32s_Free(&p->Attribs, allocMain);\r
-        RINOK(ReadBitVector(sd, numFiles, &p->Attribs.Defs, allocMain));\r
-\r
-        SZ_READ_BYTE(external);\r
-        if (external == 0)\r
-          sdPtr = sd;\r
-        else\r
-        {\r
-          UInt32 index;\r
-          RINOK(SzReadNumber32(sd, &index));\r
-          if (index >= *numTempBufs)\r
-            return SZ_ERROR_ARCHIVE;\r
-          sdSwitch.Data = (tempBufs)[index].data;\r
-          sdSwitch.Size = (tempBufs)[index].size;\r
-          sdPtr = &sdSwitch;\r
-        }\r
-        RINOK(ReadUi32s(sdPtr, numFiles, &p->Attribs, allocMain));\r
-        break;\r
-      }\r
-      /*\r
-      case k7zParent:\r
-      {\r
-        SzBitUi32s_Free(&p->Parents, allocMain);\r
-        RINOK(ReadBitVector(sd, numFiles, &p->Parents.Defs, allocMain));\r
-        RINOK(SzReadSwitch(sd));\r
-        RINOK(ReadUi32s(sd, numFiles, &p->Parents, allocMain));\r
-        break;\r
-      }\r
-      */\r
-      case k7zIdMTime: RINOK(ReadTime(&p->MTime, numFiles, sd, tempBufs, *numTempBufs, allocMain)); break;\r
-      case k7zIdCTime: RINOK(ReadTime(&p->CTime, numFiles, sd, tempBufs, *numTempBufs, allocMain)); break;\r
-      default:\r
-      {\r
-        SKIP_DATA(sd, size);\r
-      }\r
-    }\r
-  }\r
-\r
-  if (numFiles - numEmptyStreams != ssi.NumTotalSubStreams)\r
-    return SZ_ERROR_ARCHIVE;\r
-\r
-  for (;;)\r
-  {\r
-    UInt64 type;\r
-    RINOK(ReadID(sd, &type));\r
-    if (type == k7zIdEnd)\r
-      break;\r
-    RINOK(SkipData(sd));\r
-  }\r
-\r
-  {\r
-    UInt32 i;\r
-    UInt32 emptyFileIndex = 0;\r
-    UInt32 folderIndex = 0;\r
-    UInt32 remSubStreams = 0;\r
-    UInt32 numSubStreams = 0;\r
-    UInt64 unpackPos = 0;\r
-    const Byte *digestsDefs = NULL;\r
-    const Byte *digestsVals = NULL;\r
-    UInt32 digestsValsIndex = 0;\r
-    UInt32 digestIndex;\r
-    Byte allDigestsDefined = 0;\r
-    Byte isDirMask = 0;\r
-    Byte crcMask = 0;\r
-    Byte mask = 0x80;\r
-    \r
-    MY_ALLOC(UInt32, p->FolderToFile, p->db.NumFolders + 1, allocMain);\r
-    MY_ALLOC_ZE(UInt32, p->FileToFolder, p->NumFiles, allocMain);\r
-    MY_ALLOC(UInt64, p->UnpackPositions, p->NumFiles + 1, allocMain);\r
-    MY_ALLOC_ZE(Byte, p->IsDirs, (p->NumFiles + 7) >> 3, allocMain);\r
-\r
-    RINOK(SzBitUi32s_Alloc(&p->CRCs, p->NumFiles, allocMain));\r
-\r
-    if (ssi.sdCRCs.Size != 0)\r
-    {\r
-      SZ_READ_BYTE_SD(&ssi.sdCRCs, allDigestsDefined);\r
-      if (allDigestsDefined)\r
-        digestsVals = ssi.sdCRCs.Data;\r
-      else\r
-      {\r
-        size_t numBytes = (ssi.NumSubDigests + 7) >> 3;\r
-        digestsDefs = ssi.sdCRCs.Data;\r
-        digestsVals = digestsDefs + numBytes;\r
-      }\r
-    }\r
-\r
-    digestIndex = 0;\r
-    \r
-    for (i = 0; i < numFiles; i++, mask >>= 1)\r
-    {\r
-      if (mask == 0)\r
-      {\r
-        UInt32 byteIndex = (i - 1) >> 3;\r
-        p->IsDirs[byteIndex] = isDirMask;\r
-        p->CRCs.Defs[byteIndex] = crcMask;\r
-        isDirMask = 0;\r
-        crcMask = 0;\r
-        mask = 0x80;\r
-      }\r
-\r
-      p->UnpackPositions[i] = unpackPos;\r
-      p->CRCs.Vals[i] = 0;\r
-      \r
-      if (emptyStreams && SzBitArray_Check(emptyStreams, i))\r
-      {\r
-        if (emptyFiles)\r
-        {\r
-          if (!SzBitArray_Check(emptyFiles, emptyFileIndex))\r
-            isDirMask |= mask;\r
-          emptyFileIndex++;\r
-        }\r
-        else\r
-          isDirMask |= mask;\r
-        if (remSubStreams == 0)\r
-        {\r
-          p->FileToFolder[i] = (UInt32)-1;\r
-          continue;\r
-        }\r
-      }\r
-      \r
-      if (remSubStreams == 0)\r
-      {\r
-        for (;;)\r
-        {\r
-          if (folderIndex >= p->db.NumFolders)\r
-            return SZ_ERROR_ARCHIVE;\r
-          p->FolderToFile[folderIndex] = i;\r
-          numSubStreams = 1;\r
-          if (ssi.sdNumSubStreams.Data)\r
-          {\r
-            RINOK(SzReadNumber32(&ssi.sdNumSubStreams, &numSubStreams));\r
-          }\r
-          remSubStreams = numSubStreams;\r
-          if (numSubStreams != 0)\r
-            break;\r
-          {\r
-            UInt64 folderUnpackSize = SzAr_GetFolderUnpackSize(&p->db, folderIndex);\r
-            unpackPos += folderUnpackSize;\r
-            if (unpackPos < folderUnpackSize)\r
-              return SZ_ERROR_ARCHIVE;\r
-          }\r
-\r
-          folderIndex++;\r
-        }\r
-      }\r
-      \r
-      p->FileToFolder[i] = folderIndex;\r
-      \r
-      if (emptyStreams && SzBitArray_Check(emptyStreams, i))\r
-        continue;\r
-      \r
-      if (--remSubStreams == 0)\r
-      {\r
-        UInt64 folderUnpackSize = SzAr_GetFolderUnpackSize(&p->db, folderIndex);\r
-        UInt64 startFolderUnpackPos = p->UnpackPositions[p->FolderToFile[folderIndex]];\r
-        if (folderUnpackSize < unpackPos - startFolderUnpackPos)\r
-          return SZ_ERROR_ARCHIVE;\r
-        unpackPos = startFolderUnpackPos + folderUnpackSize;\r
-        if (unpackPos < folderUnpackSize)\r
-          return SZ_ERROR_ARCHIVE;\r
-\r
-        if (numSubStreams == 1 && SzBitWithVals_Check(&p->db.FolderCRCs, i))\r
-        {\r
-          p->CRCs.Vals[i] = p->db.FolderCRCs.Vals[folderIndex];\r
-          crcMask |= mask;\r
-        }\r
-        else if (allDigestsDefined || (digestsDefs && SzBitArray_Check(digestsDefs, digestIndex)))\r
-        {\r
-          p->CRCs.Vals[i] = GetUi32(digestsVals + (size_t)digestsValsIndex * 4);\r
-          digestsValsIndex++;\r
-          crcMask |= mask;\r
-        }\r
-        \r
-        folderIndex++;\r
-      }\r
-      else\r
-      {\r
-        UInt64 v;\r
-        RINOK(ReadNumber(&ssi.sdSizes, &v));\r
-        unpackPos += v;\r
-        if (unpackPos < v)\r
-          return SZ_ERROR_ARCHIVE;\r
-        if (allDigestsDefined || (digestsDefs && SzBitArray_Check(digestsDefs, digestIndex)))\r
-        {\r
-          p->CRCs.Vals[i] = GetUi32(digestsVals + (size_t)digestsValsIndex * 4);\r
-          digestsValsIndex++;\r
-          crcMask |= mask;\r
-        }\r
-      }\r
-    }\r
-\r
-    if (mask != 0x80)\r
-    {\r
-      UInt32 byteIndex = (i - 1) >> 3;\r
-      p->IsDirs[byteIndex] = isDirMask;\r
-      p->CRCs.Defs[byteIndex] = crcMask;\r
-    }\r
-    \r
-    p->UnpackPositions[i] = unpackPos;\r
-\r
-    if (remSubStreams != 0)\r
-      return SZ_ERROR_ARCHIVE;\r
-\r
-    for (;;)\r
-    {\r
-      p->FolderToFile[folderIndex] = i;\r
-      if (folderIndex >= p->db.NumFolders)\r
-        break;\r
-      if (!ssi.sdNumSubStreams.Data)\r
-        return SZ_ERROR_ARCHIVE;\r
-      RINOK(SzReadNumber32(&ssi.sdNumSubStreams, &numSubStreams));\r
-      if (numSubStreams != 0)\r
-        return SZ_ERROR_ARCHIVE;\r
-      /*\r
-      {\r
-        UInt64 folderUnpackSize = SzAr_GetFolderUnpackSize(&p->db, folderIndex);\r
-        unpackPos += folderUnpackSize;\r
-        if (unpackPos < folderUnpackSize)\r
-          return SZ_ERROR_ARCHIVE;\r
-      }\r
-      */\r
-      folderIndex++;\r
-    }\r
-\r
-    if (ssi.sdNumSubStreams.Data && ssi.sdNumSubStreams.Size != 0)\r
-      return SZ_ERROR_ARCHIVE;\r
-  }\r
-}\r
-  return SZ_OK;\r
-}\r
-\r
-\r
-static SRes SzReadHeader(\r
-    CSzArEx *p,\r
-    CSzData *sd,\r
-    ILookInStream *inStream,\r
-    ISzAlloc *allocMain,\r
-    ISzAlloc *allocTemp)\r
-{\r
-  UInt32 i;\r
-  UInt32 numTempBufs = 0;\r
-  SRes res;\r
-  CBuf tempBufs[NUM_ADDITIONAL_STREAMS_MAX];\r
-\r
-  for (i = 0; i < NUM_ADDITIONAL_STREAMS_MAX; i++)\r
-    Buf_Init(tempBufs + i);\r
-  \r
-  res = SzReadHeader2(p, sd, inStream,\r
-      tempBufs, &numTempBufs,\r
-      allocMain, allocTemp);\r
-  \r
-  for (i = 0; i < NUM_ADDITIONAL_STREAMS_MAX; i++)\r
-    Buf_Free(tempBufs + i, allocTemp);\r
-\r
-  RINOK(res);\r
-\r
-  if (sd->Size != 0)\r
-    return SZ_ERROR_FAIL;\r
-\r
-  return res;\r
-}\r
-\r
-static SRes SzArEx_Open2(\r
-    CSzArEx *p,\r
-    ILookInStream *inStream,\r
-    ISzAlloc *allocMain,\r
-    ISzAlloc *allocTemp)\r
-{\r
-  Byte header[k7zStartHeaderSize];\r
-  Int64 startArcPos;\r
-  UInt64 nextHeaderOffset, nextHeaderSize;\r
-  size_t nextHeaderSizeT;\r
-  UInt32 nextHeaderCRC;\r
-  CBuf buf;\r
-  SRes res;\r
-\r
-  startArcPos = 0;\r
-  RINOK(inStream->Seek(inStream, &startArcPos, SZ_SEEK_CUR));\r
-\r
-  RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));\r
-\r
-  if (!TestSignatureCandidate(header))\r
-    return SZ_ERROR_NO_ARCHIVE;\r
-  if (header[6] != k7zMajorVersion)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-\r
-  nextHeaderOffset = GetUi64(header + 12);\r
-  nextHeaderSize = GetUi64(header + 20);\r
-  nextHeaderCRC = GetUi32(header + 28);\r
-\r
-  p->startPosAfterHeader = startArcPos + k7zStartHeaderSize;\r
-  \r
-  if (CrcCalc(header + 12, 20) != GetUi32(header + 8))\r
-    return SZ_ERROR_CRC;\r
-\r
-  nextHeaderSizeT = (size_t)nextHeaderSize;\r
-  if (nextHeaderSizeT != nextHeaderSize)\r
-    return SZ_ERROR_MEM;\r
-  if (nextHeaderSizeT == 0)\r
-    return SZ_OK;\r
-  if (nextHeaderOffset > nextHeaderOffset + nextHeaderSize ||\r
-      nextHeaderOffset > nextHeaderOffset + nextHeaderSize + k7zStartHeaderSize)\r
-    return SZ_ERROR_NO_ARCHIVE;\r
-\r
-  {\r
-    Int64 pos = 0;\r
-    RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));\r
-    if ((UInt64)pos < startArcPos + nextHeaderOffset ||\r
-        (UInt64)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset ||\r
-        (UInt64)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)\r
-      return SZ_ERROR_INPUT_EOF;\r
-  }\r
-\r
-  RINOK(LookInStream_SeekTo(inStream, startArcPos + k7zStartHeaderSize + nextHeaderOffset));\r
-\r
-  if (!Buf_Create(&buf, nextHeaderSizeT, allocTemp))\r
-    return SZ_ERROR_MEM;\r
-\r
-  res = LookInStream_Read(inStream, buf.data, nextHeaderSizeT);\r
-  \r
-  if (res == SZ_OK)\r
-  {\r
-    res = SZ_ERROR_ARCHIVE;\r
-    if (CrcCalc(buf.data, nextHeaderSizeT) == nextHeaderCRC)\r
-    {\r
-      CSzData sd;\r
-      UInt64 type;\r
-      sd.Data = buf.data;\r
-      sd.Size = buf.size;\r
-      \r
-      res = ReadID(&sd, &type);\r
-      \r
-      if (res == SZ_OK && type == k7zIdEncodedHeader)\r
-      {\r
-        CSzAr tempAr;\r
-        CBuf tempBuf;\r
-        Buf_Init(&tempBuf);\r
-        \r
-        SzAr_Init(&tempAr);\r
-        res = SzReadAndDecodePackedStreams(inStream, &sd, &tempBuf, 1, p->startPosAfterHeader, &tempAr, allocTemp);\r
-        SzAr_Free(&tempAr, allocTemp);\r
-       \r
-        if (res != SZ_OK)\r
-        {\r
-          Buf_Free(&tempBuf, allocTemp);\r
-        }\r
-        else\r
-        {\r
-          Buf_Free(&buf, allocTemp);\r
-          buf.data = tempBuf.data;\r
-          buf.size = tempBuf.size;\r
-          sd.Data = buf.data;\r
-          sd.Size = buf.size;\r
-          res = ReadID(&sd, &type);\r
-        }\r
-      }\r
-  \r
-      if (res == SZ_OK)\r
-      {\r
-        if (type == k7zIdHeader)\r
-        {\r
-          /*\r
-          CSzData sd2;\r
-          unsigned ttt;\r
-          for (ttt = 0; ttt < 40000; ttt++)\r
-          {\r
-            SzArEx_Free(p, allocMain);\r
-            sd2 = sd;\r
-            res = SzReadHeader(p, &sd2, inStream, allocMain, allocTemp);\r
-            if (res != SZ_OK)\r
-              break;\r
-          }\r
-          */\r
-          res = SzReadHeader(p, &sd, inStream, allocMain, allocTemp);\r
-        }\r
-        else\r
-          res = SZ_ERROR_UNSUPPORTED;\r
-      }\r
-    }\r
-  }\r
\r
-  Buf_Free(&buf, allocTemp);\r
-  return res;\r
-}\r
-\r
-\r
-SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,\r
-    ISzAlloc *allocMain, ISzAlloc *allocTemp)\r
-{\r
-  SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);\r
-  if (res != SZ_OK)\r
-    SzArEx_Free(p, allocMain);\r
-  return res;\r
-}\r
-\r
-\r
-SRes SzArEx_Extract(\r
-    const CSzArEx *p,\r
-    ILookInStream *inStream,\r
-    UInt32 fileIndex,\r
-    UInt32 *blockIndex,\r
-    Byte **tempBuf,\r
-    size_t *outBufferSize,\r
-    size_t *offset,\r
-    size_t *outSizeProcessed,\r
-    ISzAlloc *allocMain,\r
-    ISzAlloc *allocTemp)\r
-{\r
-  UInt32 folderIndex = p->FileToFolder[fileIndex];\r
-  SRes res = SZ_OK;\r
-  \r
-  *offset = 0;\r
-  *outSizeProcessed = 0;\r
-  \r
-  if (folderIndex == (UInt32)-1)\r
-  {\r
-    IAlloc_Free(allocMain, *tempBuf);\r
-    *blockIndex = folderIndex;\r
-    *tempBuf = NULL;\r
-    *outBufferSize = 0;\r
-    return SZ_OK;\r
-  }\r
-\r
-  if (*tempBuf == NULL || *blockIndex != folderIndex)\r
-  {\r
-    UInt64 unpackSizeSpec = SzAr_GetFolderUnpackSize(&p->db, folderIndex);\r
-    /*\r
-    UInt64 unpackSizeSpec =\r
-        p->UnpackPositions[p->FolderToFile[folderIndex + 1]] -\r
-        p->UnpackPositions[p->FolderToFile[folderIndex]];\r
-    */\r
-    size_t unpackSize = (size_t)unpackSizeSpec;\r
-\r
-    if (unpackSize != unpackSizeSpec)\r
-      return SZ_ERROR_MEM;\r
-    *blockIndex = folderIndex;\r
-    IAlloc_Free(allocMain, *tempBuf);\r
-    *tempBuf = NULL;\r
-    \r
-    if (res == SZ_OK)\r
-    {\r
-      *outBufferSize = unpackSize;\r
-      if (unpackSize != 0)\r
-      {\r
-        *tempBuf = (Byte *)IAlloc_Alloc(allocMain, unpackSize);\r
-        if (*tempBuf == NULL)\r
-          res = SZ_ERROR_MEM;\r
-      }\r
-  \r
-      if (res == SZ_OK)\r
-      {\r
-        res = SzAr_DecodeFolder(&p->db, folderIndex,\r
-            inStream, p->dataPos, *tempBuf, unpackSize, allocTemp);\r
-      }\r
-    }\r
-  }\r
-\r
-  if (res == SZ_OK)\r
-  {\r
-    UInt64 unpackPos = p->UnpackPositions[fileIndex];\r
-    *offset = (size_t)(unpackPos - p->UnpackPositions[p->FolderToFile[folderIndex]]);\r
-    *outSizeProcessed = (size_t)(p->UnpackPositions[fileIndex + 1] - unpackPos);\r
-    if (*offset + *outSizeProcessed > *outBufferSize)\r
-      return SZ_ERROR_FAIL;\r
-    if (SzBitWithVals_Check(&p->CRCs, fileIndex))\r
-      if (CrcCalc(*tempBuf + *offset, *outSizeProcessed) != p->CRCs.Vals[fileIndex])\r
-        res = SZ_ERROR_CRC;\r
-  }\r
-\r
-  return res;\r
-}\r
-\r
-\r
-size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest)\r
-{\r
-  size_t offs = p->FileNameOffsets[fileIndex];\r
-  size_t len = p->FileNameOffsets[fileIndex + 1] - offs;\r
-  if (dest != 0)\r
-  {\r
-    size_t i;\r
-    const Byte *src = p->FileNames + offs * 2;\r
-    for (i = 0; i < len; i++)\r
-      dest[i] = GetUi16(src + i * 2);\r
-  }\r
-  return len;\r
-}\r
-\r
-/*\r
-size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex)\r
-{\r
-  size_t len;\r
-  if (!p->FileNameOffsets)\r
-    return 1;\r
-  len = 0;\r
-  for (;;)\r
-  {\r
-    UInt32 parent = (UInt32)(Int32)-1;\r
-    len += p->FileNameOffsets[fileIndex + 1] - p->FileNameOffsets[fileIndex];\r
-    if SzBitWithVals_Check(&p->Parents, fileIndex)\r
-      parent = p->Parents.Vals[fileIndex];\r
-    if (parent == (UInt32)(Int32)-1)\r
-      return len;\r
-    fileIndex = parent;\r
-  }\r
-}\r
-\r
-UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest)\r
-{\r
-  Bool needSlash;\r
-  if (!p->FileNameOffsets)\r
-  {\r
-    *(--dest) = 0;\r
-    return dest;\r
-  }\r
-  needSlash = False;\r
-  for (;;)\r
-  {\r
-    UInt32 parent = (UInt32)(Int32)-1;\r
-    size_t curLen = p->FileNameOffsets[fileIndex + 1] - p->FileNameOffsets[fileIndex];\r
-    SzArEx_GetFileNameUtf16(p, fileIndex, dest - curLen);\r
-    if (needSlash)\r
-      *(dest - 1) = '/';\r
-    needSlash = True;\r
-    dest -= curLen;\r
-\r
-    if SzBitWithVals_Check(&p->Parents, fileIndex)\r
-      parent = p->Parents.Vals[fileIndex];\r
-    if (parent == (UInt32)(Int32)-1)\r
-      return dest;\r
-    fileIndex = parent;\r
-  }\r
-}\r
-*/\r
diff --git a/deps/lzma-16.04/C/7zBuf.c b/deps/lzma-16.04/C/7zBuf.c
deleted file mode 100644 (file)
index b0ac110..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* 7zBuf.c -- Byte Buffer\r
-2013-01-21 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "7zBuf.h"\r
-\r
-void Buf_Init(CBuf *p)\r
-{\r
-  p->data = 0;\r
-  p->size = 0;\r
-}\r
-\r
-int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)\r
-{\r
-  p->size = 0;\r
-  if (size == 0)\r
-  {\r
-    p->data = 0;\r
-    return 1;\r
-  }\r
-  p->data = (Byte *)alloc->Alloc(alloc, size);\r
-  if (p->data != 0)\r
-  {\r
-    p->size = size;\r
-    return 1;\r
-  }\r
-  return 0;\r
-}\r
-\r
-void Buf_Free(CBuf *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->data);\r
-  p->data = 0;\r
-  p->size = 0;\r
-}\r
diff --git a/deps/lzma-16.04/C/7zBuf.h b/deps/lzma-16.04/C/7zBuf.h
deleted file mode 100644 (file)
index e5f9218..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/* 7zBuf.h -- Byte Buffer\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_BUF_H\r
-#define __7Z_BUF_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-typedef struct\r
-{\r
-  Byte *data;\r
-  size_t size;\r
-} CBuf;\r
-\r
-void Buf_Init(CBuf *p);\r
-int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);\r
-void Buf_Free(CBuf *p, ISzAlloc *alloc);\r
-\r
-typedef struct\r
-{\r
-  Byte *data;\r
-  size_t size;\r
-  size_t pos;\r
-} CDynBuf;\r
-\r
-void DynBuf_Construct(CDynBuf *p);\r
-void DynBuf_SeekToBeg(CDynBuf *p);\r
-int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);\r
-void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/7zBuf2.c b/deps/lzma-16.04/C/7zBuf2.c
deleted file mode 100644 (file)
index 8e3fe92..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/* 7zBuf2.c -- Byte Buffer\r
-2014-08-22 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-#include "7zBuf.h"\r
-\r
-void DynBuf_Construct(CDynBuf *p)\r
-{\r
-  p->data = 0;\r
-  p->size = 0;\r
-  p->pos = 0;\r
-}\r
-\r
-void DynBuf_SeekToBeg(CDynBuf *p)\r
-{\r
-  p->pos = 0;\r
-}\r
-\r
-int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)\r
-{\r
-  if (size > p->size - p->pos)\r
-  {\r
-    size_t newSize = p->pos + size;\r
-    Byte *data;\r
-    newSize += newSize / 4;\r
-    data = (Byte *)alloc->Alloc(alloc, newSize);\r
-    if (data == 0)\r
-      return 0;\r
-    p->size = newSize;\r
-    memcpy(data, p->data, p->pos);\r
-    alloc->Free(alloc, p->data);\r
-    p->data = data;\r
-  }\r
-  if (size != 0)\r
-  {\r
-    memcpy(p->data + p->pos, buf, size);\r
-    p->pos += size;\r
-  }\r
-  return 1;\r
-}\r
-\r
-void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->data);\r
-  p->data = 0;\r
-  p->size = 0;\r
-  p->pos = 0;\r
-}\r
diff --git a/deps/lzma-16.04/C/7zCrc.c b/deps/lzma-16.04/C/7zCrc.c
deleted file mode 100644 (file)
index 607db34..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/* 7zCrc.c -- CRC32 init\r
-2015-03-10 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "7zCrc.h"\r
-#include "CpuArch.h"\r
-\r
-#define kCrcPoly 0xEDB88320\r
-\r
-#ifdef MY_CPU_LE\r
-  #define CRC_NUM_TABLES 8\r
-#else\r
-  #define CRC_NUM_TABLES 9\r
-\r
-  #define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24))\r
-\r
-  UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table);\r
-  UInt32 MY_FAST_CALL CrcUpdateT1_BeT8(UInt32 v, const void *data, size_t size, const UInt32 *table);\r
-#endif\r
-\r
-#ifndef MY_CPU_BE\r
-  UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table);\r
-  UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);\r
-#endif\r
-\r
-typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table);\r
-\r
-CRC_FUNC g_CrcUpdateT4;\r
-CRC_FUNC g_CrcUpdateT8;\r
-CRC_FUNC g_CrcUpdate;\r
-\r
-UInt32 g_CrcTable[256 * CRC_NUM_TABLES];\r
-\r
-UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r
-{\r
-  return g_CrcUpdate(v, data, size, g_CrcTable);\r
-}\r
-\r
-UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r
-{\r
-  return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL;\r
-}\r
-\r
-#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r
-\r
-UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table)\r
-{\r
-  const Byte *p = (const Byte *)data;\r
-  const Byte *pEnd = p + size;\r
-  for (; p != pEnd; p++)\r
-    v = CRC_UPDATE_BYTE_2(v, *p);\r
-  return v;\r
-}\r
-\r
-void MY_FAST_CALL CrcGenerateTable()\r
-{\r
-  UInt32 i;\r
-  for (i = 0; i < 256; i++)\r
-  {\r
-    UInt32 r = i;\r
-    unsigned j;\r
-    for (j = 0; j < 8; j++)\r
-      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r
-    g_CrcTable[i] = r;\r
-  }\r
-  for (; i < 256 * CRC_NUM_TABLES; i++)\r
-  {\r
-    UInt32 r = g_CrcTable[i - 256];\r
-    g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);\r
-  }\r
-\r
-  #if CRC_NUM_TABLES < 4\r
-  \r
-  g_CrcUpdate = CrcUpdateT1;\r
-  \r
-  #else\r
\r
-  #ifdef MY_CPU_LE\r
-\r
-    g_CrcUpdateT4 = CrcUpdateT4;\r
-    g_CrcUpdate = CrcUpdateT4;\r
-\r
-    #if CRC_NUM_TABLES >= 8\r
-      g_CrcUpdateT8 = CrcUpdateT8;\r
-  \r
-      #ifdef MY_CPU_X86_OR_AMD64\r
-      if (!CPU_Is_InOrder())\r
-        g_CrcUpdate = CrcUpdateT8;\r
-      #endif\r
-    #endif\r
-\r
-  #else\r
-  {\r
-    #ifndef MY_CPU_BE\r
-    UInt32 k = 0x01020304;\r
-    const Byte *p = (const Byte *)&k;\r
-    if (p[0] == 4 && p[1] == 3)\r
-    {\r
-      g_CrcUpdateT4 = CrcUpdateT4;\r
-      g_CrcUpdate = CrcUpdateT4;\r
-      #if CRC_NUM_TABLES >= 8\r
-      g_CrcUpdateT8 = CrcUpdateT8;\r
-      // g_CrcUpdate = CrcUpdateT8;\r
-      #endif\r
-    }\r
-    else if (p[0] != 1 || p[1] != 2)\r
-      g_CrcUpdate = CrcUpdateT1;\r
-    else\r
-    #endif\r
-    {\r
-      for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--)\r
-      {\r
-        UInt32 x = g_CrcTable[i - 256];\r
-        g_CrcTable[i] = CRC_UINT32_SWAP(x);\r
-      }\r
-      g_CrcUpdateT4 = CrcUpdateT1_BeT4;\r
-      g_CrcUpdate = CrcUpdateT1_BeT4;\r
-      #if CRC_NUM_TABLES >= 8\r
-      g_CrcUpdateT8 = CrcUpdateT1_BeT8;\r
-      // g_CrcUpdate = CrcUpdateT1_BeT8;\r
-      #endif\r
-    }\r
-  }\r
-  #endif\r
-\r
-  #endif\r
-}\r
diff --git a/deps/lzma-16.04/C/7zCrc.h b/deps/lzma-16.04/C/7zCrc.h
deleted file mode 100644 (file)
index 3b04594..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/* 7zCrc.h -- CRC32 calculation\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_CRC_H\r
-#define __7Z_CRC_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-extern UInt32 g_CrcTable[];\r
-\r
-/* Call CrcGenerateTable one time before other CRC functions */\r
-void MY_FAST_CALL CrcGenerateTable(void);\r
-\r
-#define CRC_INIT_VAL 0xFFFFFFFF\r
-#define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL)\r
-#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r
-\r
-UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);\r
-UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/7zCrcOpt.c b/deps/lzma-16.04/C/7zCrcOpt.c
deleted file mode 100644 (file)
index 58628ef..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/* 7zCrcOpt.c -- CRC32 calculation\r
-2015-03-01 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "CpuArch.h"\r
-\r
-#ifndef MY_CPU_BE\r
-\r
-#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r
-\r
-UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table)\r
-{\r
-  const Byte *p = (const Byte *)data;\r
-  for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2(v, *p);\r
-  for (; size >= 4; size -= 4, p += 4)\r
-  {\r
-    v ^= *(const UInt32 *)p;\r
-    v =\r
-          table[0x300 + ((v      ) & 0xFF)]\r
-        ^ table[0x200 + ((v >>  8) & 0xFF)]\r
-        ^ table[0x100 + ((v >> 16) & 0xFF)]\r
-        ^ table[0x000 + ((v >> 24))];\r
-  }\r
-  for (; size > 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2(v, *p);\r
-  return v;\r
-}\r
-\r
-UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table)\r
-{\r
-  const Byte *p = (const Byte *)data;\r
-  for (; size > 0 && ((unsigned)(ptrdiff_t)p & 7) != 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2(v, *p);\r
-  for (; size >= 8; size -= 8, p += 8)\r
-  {\r
-    UInt32 d;\r
-    v ^= *(const UInt32 *)p;\r
-    v =\r
-          table[0x700 + ((v      ) & 0xFF)]\r
-        ^ table[0x600 + ((v >>  8) & 0xFF)]\r
-        ^ table[0x500 + ((v >> 16) & 0xFF)]\r
-        ^ table[0x400 + ((v >> 24))];\r
-    d = *((const UInt32 *)p + 1);\r
-    v ^=\r
-          table[0x300 + ((d      ) & 0xFF)]\r
-        ^ table[0x200 + ((d >>  8) & 0xFF)]\r
-        ^ table[0x100 + ((d >> 16) & 0xFF)]\r
-        ^ table[0x000 + ((d >> 24))];\r
-  }\r
-  for (; size > 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2(v, *p);\r
-  return v;\r
-}\r
-\r
-#endif\r
-\r
-\r
-#ifndef MY_CPU_LE\r
-\r
-#define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24))\r
-\r
-#define CRC_UPDATE_BYTE_2_BE(crc, b) (table[(((crc) >> 24) ^ (b))] ^ ((crc) << 8))\r
-\r
-UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table)\r
-{\r
-  const Byte *p = (const Byte *)data;\r
-  table += 0x100;\r
-  v = CRC_UINT32_SWAP(v);\r
-  for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2_BE(v, *p);\r
-  for (; size >= 4; size -= 4, p += 4)\r
-  {\r
-    v ^= *(const UInt32 *)p;\r
-    v =\r
-          table[0x000 + ((v      ) & 0xFF)]\r
-        ^ table[0x100 + ((v >>  8) & 0xFF)]\r
-        ^ table[0x200 + ((v >> 16) & 0xFF)]\r
-        ^ table[0x300 + ((v >> 24))];\r
-  }\r
-  for (; size > 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2_BE(v, *p);\r
-  return CRC_UINT32_SWAP(v);\r
-}\r
-\r
-UInt32 MY_FAST_CALL CrcUpdateT1_BeT8(UInt32 v, const void *data, size_t size, const UInt32 *table)\r
-{\r
-  const Byte *p = (const Byte *)data;\r
-  table += 0x100;\r
-  v = CRC_UINT32_SWAP(v);\r
-  for (; size > 0 && ((unsigned)(ptrdiff_t)p & 7) != 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2_BE(v, *p);\r
-  for (; size >= 8; size -= 8, p += 8)\r
-  {\r
-    UInt32 d;\r
-    v ^= *(const UInt32 *)p;\r
-    v =\r
-          table[0x400 + ((v      ) & 0xFF)]\r
-        ^ table[0x500 + ((v >>  8) & 0xFF)]\r
-        ^ table[0x600 + ((v >> 16) & 0xFF)]\r
-        ^ table[0x700 + ((v >> 24))];\r
-    d = *((const UInt32 *)p + 1);\r
-    v ^=\r
-          table[0x000 + ((d      ) & 0xFF)]\r
-        ^ table[0x100 + ((d >>  8) & 0xFF)]\r
-        ^ table[0x200 + ((d >> 16) & 0xFF)]\r
-        ^ table[0x300 + ((d >> 24))];\r
-  }\r
-  for (; size > 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2_BE(v, *p);\r
-  return CRC_UINT32_SWAP(v);\r
-}\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/7zDec.c b/deps/lzma-16.04/C/7zDec.c
deleted file mode 100644 (file)
index e39b4ff..0000000
+++ /dev/null
@@ -1,591 +0,0 @@
-/* 7zDec.c -- Decoding from 7z folder\r
-2015-11-18 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-/* #define _7ZIP_PPMD_SUPPPORT */\r
-\r
-#include "7z.h"\r
-#include "7zCrc.h"\r
-\r
-#include "Bcj2.h"\r
-#include "Bra.h"\r
-#include "CpuArch.h"\r
-#include "Delta.h"\r
-#include "LzmaDec.h"\r
-#include "Lzma2Dec.h"\r
-#ifdef _7ZIP_PPMD_SUPPPORT\r
-#include "Ppmd7.h"\r
-#endif\r
-\r
-#define k_Copy 0\r
-#define k_Delta 3\r
-#define k_LZMA2 0x21\r
-#define k_LZMA  0x30101\r
-#define k_BCJ   0x3030103\r
-#define k_BCJ2  0x303011B\r
-#define k_PPC   0x3030205\r
-#define k_IA64  0x3030401\r
-#define k_ARM   0x3030501\r
-#define k_ARMT  0x3030701\r
-#define k_SPARC 0x3030805\r
-\r
-\r
-#ifdef _7ZIP_PPMD_SUPPPORT\r
-\r
-#define k_PPMD 0x30401\r
-\r
-typedef struct\r
-{\r
-  IByteIn p;\r
-  const Byte *cur;\r
-  const Byte *end;\r
-  const Byte *begin;\r
-  UInt64 processed;\r
-  Bool extra;\r
-  SRes res;\r
-  ILookInStream *inStream;\r
-} CByteInToLook;\r
-\r
-static Byte ReadByte(void *pp)\r
-{\r
-  CByteInToLook *p = (CByteInToLook *)pp;\r
-  if (p->cur != p->end)\r
-    return *p->cur++;\r
-  if (p->res == SZ_OK)\r
-  {\r
-    size_t size = p->cur - p->begin;\r
-    p->processed += size;\r
-    p->res = p->inStream->Skip(p->inStream, size);\r
-    size = (1 << 25);\r
-    p->res = p->inStream->Look(p->inStream, (const void **)&p->begin, &size);\r
-    p->cur = p->begin;\r
-    p->end = p->begin + size;\r
-    if (size != 0)\r
-      return *p->cur++;;\r
-  }\r
-  p->extra = True;\r
-  return 0;\r
-}\r
-\r
-static SRes SzDecodePpmd(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream,\r
-    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)\r
-{\r
-  CPpmd7 ppmd;\r
-  CByteInToLook s;\r
-  SRes res = SZ_OK;\r
-\r
-  s.p.Read = ReadByte;\r
-  s.inStream = inStream;\r
-  s.begin = s.end = s.cur = NULL;\r
-  s.extra = False;\r
-  s.res = SZ_OK;\r
-  s.processed = 0;\r
-\r
-  if (propsSize != 5)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-\r
-  {\r
-    unsigned order = props[0];\r
-    UInt32 memSize = GetUi32(props + 1);\r
-    if (order < PPMD7_MIN_ORDER ||\r
-        order > PPMD7_MAX_ORDER ||\r
-        memSize < PPMD7_MIN_MEM_SIZE ||\r
-        memSize > PPMD7_MAX_MEM_SIZE)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    Ppmd7_Construct(&ppmd);\r
-    if (!Ppmd7_Alloc(&ppmd, memSize, allocMain))\r
-      return SZ_ERROR_MEM;\r
-    Ppmd7_Init(&ppmd, order);\r
-  }\r
-  {\r
-    CPpmd7z_RangeDec rc;\r
-    Ppmd7z_RangeDec_CreateVTable(&rc);\r
-    rc.Stream = &s.p;\r
-    if (!Ppmd7z_RangeDec_Init(&rc))\r
-      res = SZ_ERROR_DATA;\r
-    else if (s.extra)\r
-      res = (s.res != SZ_OK ? s.res : SZ_ERROR_DATA);\r
-    else\r
-    {\r
-      SizeT i;\r
-      for (i = 0; i < outSize; i++)\r
-      {\r
-        int sym = Ppmd7_DecodeSymbol(&ppmd, &rc.p);\r
-        if (s.extra || sym < 0)\r
-          break;\r
-        outBuffer[i] = (Byte)sym;\r
-      }\r
-      if (i != outSize)\r
-        res = (s.res != SZ_OK ? s.res : SZ_ERROR_DATA);\r
-      else if (s.processed + (s.cur - s.begin) != inSize || !Ppmd7z_RangeDec_IsFinishedOK(&rc))\r
-        res = SZ_ERROR_DATA;\r
-    }\r
-  }\r
-  Ppmd7_Free(&ppmd, allocMain);\r
-  return res;\r
-}\r
-\r
-#endif\r
-\r
-\r
-static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream,\r
-    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)\r
-{\r
-  CLzmaDec state;\r
-  SRes res = SZ_OK;\r
-\r
-  LzmaDec_Construct(&state);\r
-  RINOK(LzmaDec_AllocateProbs(&state, props, propsSize, allocMain));\r
-  state.dic = outBuffer;\r
-  state.dicBufSize = outSize;\r
-  LzmaDec_Init(&state);\r
-\r
-  for (;;)\r
-  {\r
-    const void *inBuf = NULL;\r
-    size_t lookahead = (1 << 18);\r
-    if (lookahead > inSize)\r
-      lookahead = (size_t)inSize;\r
-    res = inStream->Look(inStream, &inBuf, &lookahead);\r
-    if (res != SZ_OK)\r
-      break;\r
-\r
-    {\r
-      SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;\r
-      ELzmaStatus status;\r
-      res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);\r
-      lookahead -= inProcessed;\r
-      inSize -= inProcessed;\r
-      if (res != SZ_OK)\r
-        break;\r
-\r
-      if (status == LZMA_STATUS_FINISHED_WITH_MARK)\r
-      {\r
-        if (outSize != state.dicPos || inSize != 0)\r
-          res = SZ_ERROR_DATA;\r
-        break;\r
-      }\r
-\r
-      if (outSize == state.dicPos && inSize == 0 && status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)\r
-        break;\r
-\r
-      if (inProcessed == 0 && dicPos == state.dicPos)\r
-      {\r
-        res = SZ_ERROR_DATA;\r
-        break;\r
-      }\r
-\r
-      res = inStream->Skip((void *)inStream, inProcessed);\r
-      if (res != SZ_OK)\r
-        break;\r
-    }\r
-  }\r
-\r
-  LzmaDec_FreeProbs(&state, allocMain);\r
-  return res;\r
-}\r
-\r
-\r
-#ifndef _7Z_NO_METHOD_LZMA2\r
-\r
-static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream,\r
-    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)\r
-{\r
-  CLzma2Dec state;\r
-  SRes res = SZ_OK;\r
-\r
-  Lzma2Dec_Construct(&state);\r
-  if (propsSize != 1)\r
-    return SZ_ERROR_DATA;\r
-  RINOK(Lzma2Dec_AllocateProbs(&state, props[0], allocMain));\r
-  state.decoder.dic = outBuffer;\r
-  state.decoder.dicBufSize = outSize;\r
-  Lzma2Dec_Init(&state);\r
-\r
-  for (;;)\r
-  {\r
-    const void *inBuf = NULL;\r
-    size_t lookahead = (1 << 18);\r
-    if (lookahead > inSize)\r
-      lookahead = (size_t)inSize;\r
-    res = inStream->Look(inStream, &inBuf, &lookahead);\r
-    if (res != SZ_OK)\r
-      break;\r
-\r
-    {\r
-      SizeT inProcessed = (SizeT)lookahead, dicPos = state.decoder.dicPos;\r
-      ELzmaStatus status;\r
-      res = Lzma2Dec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);\r
-      lookahead -= inProcessed;\r
-      inSize -= inProcessed;\r
-      if (res != SZ_OK)\r
-        break;\r
-\r
-      if (status == LZMA_STATUS_FINISHED_WITH_MARK)\r
-      {\r
-        if (outSize != state.decoder.dicPos || inSize != 0)\r
-          res = SZ_ERROR_DATA;\r
-        break;\r
-      }\r
-\r
-      if (inProcessed == 0 && dicPos == state.decoder.dicPos)\r
-      {\r
-        res = SZ_ERROR_DATA;\r
-        break;\r
-      }\r
-\r
-      res = inStream->Skip((void *)inStream, inProcessed);\r
-      if (res != SZ_OK)\r
-        break;\r
-    }\r
-  }\r
-\r
-  Lzma2Dec_FreeProbs(&state, allocMain);\r
-  return res;\r
-}\r
-\r
-#endif\r
-\r
-\r
-static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)\r
-{\r
-  while (inSize > 0)\r
-  {\r
-    const void *inBuf;\r
-    size_t curSize = (1 << 18);\r
-    if (curSize > inSize)\r
-      curSize = (size_t)inSize;\r
-    RINOK(inStream->Look(inStream, &inBuf, &curSize));\r
-    if (curSize == 0)\r
-      return SZ_ERROR_INPUT_EOF;\r
-    memcpy(outBuffer, inBuf, curSize);\r
-    outBuffer += curSize;\r
-    inSize -= curSize;\r
-    RINOK(inStream->Skip((void *)inStream, curSize));\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-static Bool IS_MAIN_METHOD(UInt32 m)\r
-{\r
-  switch (m)\r
-  {\r
-    case k_Copy:\r
-    case k_LZMA:\r
-    #ifndef _7Z_NO_METHOD_LZMA2\r
-    case k_LZMA2:\r
-    #endif\r
-    #ifdef _7ZIP_PPMD_SUPPPORT\r
-    case k_PPMD:\r
-    #endif\r
-      return True;\r
-  }\r
-  return False;\r
-}\r
-\r
-static Bool IS_SUPPORTED_CODER(const CSzCoderInfo *c)\r
-{\r
-  return\r
-      c->NumStreams == 1\r
-      /* && c->MethodID <= (UInt32)0xFFFFFFFF */\r
-      && IS_MAIN_METHOD((UInt32)c->MethodID);\r
-}\r
-\r
-#define IS_BCJ2(c) ((c)->MethodID == k_BCJ2 && (c)->NumStreams == 4)\r
-\r
-static SRes CheckSupportedFolder(const CSzFolder *f)\r
-{\r
-  if (f->NumCoders < 1 || f->NumCoders > 4)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  if (!IS_SUPPORTED_CODER(&f->Coders[0]))\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  if (f->NumCoders == 1)\r
-  {\r
-    if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBonds != 0)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    return SZ_OK;\r
-  }\r
-  \r
-  \r
-  #ifndef _7Z_NO_METHODS_FILTERS\r
-\r
-  if (f->NumCoders == 2)\r
-  {\r
-    const CSzCoderInfo *c = &f->Coders[1];\r
-    if (\r
-        /* c->MethodID > (UInt32)0xFFFFFFFF || */\r
-        c->NumStreams != 1\r
-        || f->NumPackStreams != 1\r
-        || f->PackStreams[0] != 0\r
-        || f->NumBonds != 1\r
-        || f->Bonds[0].InIndex != 1\r
-        || f->Bonds[0].OutIndex != 0)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    switch ((UInt32)c->MethodID)\r
-    {\r
-      case k_Delta:\r
-      case k_BCJ:\r
-      case k_PPC:\r
-      case k_IA64:\r
-      case k_SPARC:\r
-      case k_ARM:\r
-      case k_ARMT:\r
-        break;\r
-      default:\r
-        return SZ_ERROR_UNSUPPORTED;\r
-    }\r
-    return SZ_OK;\r
-  }\r
-\r
-  #endif\r
-\r
-  \r
-  if (f->NumCoders == 4)\r
-  {\r
-    if (!IS_SUPPORTED_CODER(&f->Coders[1])\r
-        || !IS_SUPPORTED_CODER(&f->Coders[2])\r
-        || !IS_BCJ2(&f->Coders[3]))\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    if (f->NumPackStreams != 4\r
-        || f->PackStreams[0] != 2\r
-        || f->PackStreams[1] != 6\r
-        || f->PackStreams[2] != 1\r
-        || f->PackStreams[3] != 0\r
-        || f->NumBonds != 3\r
-        || f->Bonds[0].InIndex != 5 || f->Bonds[0].OutIndex != 0\r
-        || f->Bonds[1].InIndex != 4 || f->Bonds[1].OutIndex != 1\r
-        || f->Bonds[2].InIndex != 3 || f->Bonds[2].OutIndex != 2)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    return SZ_OK;\r
-  }\r
-  \r
-  return SZ_ERROR_UNSUPPORTED;\r
-}\r
-\r
-#define CASE_BRA_CONV(isa) case k_ ## isa: isa ## _Convert(outBuffer, outSize, 0, 0); break;\r
-\r
-static SRes SzFolder_Decode2(const CSzFolder *folder,\r
-    const Byte *propsData,\r
-    const UInt64 *unpackSizes,\r
-    const UInt64 *packPositions,\r
-    ILookInStream *inStream, UInt64 startPos,\r
-    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,\r
-    Byte *tempBuf[])\r
-{\r
-  UInt32 ci;\r
-  SizeT tempSizes[3] = { 0, 0, 0};\r
-  SizeT tempSize3 = 0;\r
-  Byte *tempBuf3 = 0;\r
-\r
-  RINOK(CheckSupportedFolder(folder));\r
-\r
-  for (ci = 0; ci < folder->NumCoders; ci++)\r
-  {\r
-    const CSzCoderInfo *coder = &folder->Coders[ci];\r
-\r
-    if (IS_MAIN_METHOD((UInt32)coder->MethodID))\r
-    {\r
-      UInt32 si = 0;\r
-      UInt64 offset;\r
-      UInt64 inSize;\r
-      Byte *outBufCur = outBuffer;\r
-      SizeT outSizeCur = outSize;\r
-      if (folder->NumCoders == 4)\r
-      {\r
-        UInt32 indices[] = { 3, 2, 0 };\r
-        UInt64 unpackSize = unpackSizes[ci];\r
-        si = indices[ci];\r
-        if (ci < 2)\r
-        {\r
-          Byte *temp;\r
-          outSizeCur = (SizeT)unpackSize;\r
-          if (outSizeCur != unpackSize)\r
-            return SZ_ERROR_MEM;\r
-          temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);\r
-          if (!temp && outSizeCur != 0)\r
-            return SZ_ERROR_MEM;\r
-          outBufCur = tempBuf[1 - ci] = temp;\r
-          tempSizes[1 - ci] = outSizeCur;\r
-        }\r
-        else if (ci == 2)\r
-        {\r
-          if (unpackSize > outSize) /* check it */\r
-            return SZ_ERROR_PARAM;\r
-          tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);\r
-          tempSize3 = outSizeCur = (SizeT)unpackSize;\r
-        }\r
-        else\r
-          return SZ_ERROR_UNSUPPORTED;\r
-      }\r
-      offset = packPositions[si];\r
-      inSize = packPositions[si + 1] - offset;\r
-      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r
-\r
-      if (coder->MethodID == k_Copy)\r
-      {\r
-        if (inSize != outSizeCur) /* check it */\r
-          return SZ_ERROR_DATA;\r
-        RINOK(SzDecodeCopy(inSize, inStream, outBufCur));\r
-      }\r
-      else if (coder->MethodID == k_LZMA)\r
-      {\r
-        RINOK(SzDecodeLzma(propsData + coder->PropsOffset, coder->PropsSize, inSize, inStream, outBufCur, outSizeCur, allocMain));\r
-      }\r
-      #ifndef _7Z_NO_METHOD_LZMA2\r
-      else if (coder->MethodID == k_LZMA2)\r
-      {\r
-        RINOK(SzDecodeLzma2(propsData + coder->PropsOffset, coder->PropsSize, inSize, inStream, outBufCur, outSizeCur, allocMain));\r
-      }\r
-      #endif\r
-      #ifdef _7ZIP_PPMD_SUPPPORT\r
-      else if (coder->MethodID == k_PPMD)\r
-      {\r
-        RINOK(SzDecodePpmd(propsData + coder->PropsOffset, coder->PropsSize, inSize, inStream, outBufCur, outSizeCur, allocMain));\r
-      }\r
-      #endif\r
-      else\r
-        return SZ_ERROR_UNSUPPORTED;\r
-    }\r
-    else if (coder->MethodID == k_BCJ2)\r
-    {\r
-      UInt64 offset = packPositions[1];\r
-      UInt64 s3Size = packPositions[2] - offset;\r
-      \r
-      if (ci != 3)\r
-        return SZ_ERROR_UNSUPPORTED;\r
-      \r
-      tempSizes[2] = (SizeT)s3Size;\r
-      if (tempSizes[2] != s3Size)\r
-        return SZ_ERROR_MEM;\r
-      tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);\r
-      if (!tempBuf[2] && tempSizes[2] != 0)\r
-        return SZ_ERROR_MEM;\r
-      \r
-      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r
-      RINOK(SzDecodeCopy(s3Size, inStream, tempBuf[2]));\r
-\r
-      if ((tempSizes[0] & 3) != 0 ||\r
-          (tempSizes[1] & 3) != 0 ||\r
-          tempSize3 + tempSizes[0] + tempSizes[1] != outSize)\r
-        return SZ_ERROR_DATA;\r
-\r
-      {\r
-        CBcj2Dec p;\r
-        \r
-        p.bufs[0] = tempBuf3;   p.lims[0] = tempBuf3 + tempSize3;\r
-        p.bufs[1] = tempBuf[0]; p.lims[1] = tempBuf[0] + tempSizes[0];\r
-        p.bufs[2] = tempBuf[1]; p.lims[2] = tempBuf[1] + tempSizes[1];\r
-        p.bufs[3] = tempBuf[2]; p.lims[3] = tempBuf[2] + tempSizes[2];\r
-        \r
-        p.dest = outBuffer;\r
-        p.destLim = outBuffer + outSize;\r
-        \r
-        Bcj2Dec_Init(&p);\r
-        RINOK(Bcj2Dec_Decode(&p));\r
-\r
-        {\r
-          unsigned i;\r
-          for (i = 0; i < 4; i++)\r
-            if (p.bufs[i] != p.lims[i])\r
-              return SZ_ERROR_DATA;\r
-          \r
-          if (!Bcj2Dec_IsFinished(&p))\r
-            return SZ_ERROR_DATA;\r
-\r
-          if (p.dest != p.destLim\r
-             || p.state != BCJ2_STREAM_MAIN)\r
-            return SZ_ERROR_DATA;\r
-        }\r
-      }\r
-    }\r
-    #ifndef _7Z_NO_METHODS_FILTERS\r
-    else if (ci == 1)\r
-    {\r
-      if (coder->MethodID == k_Delta)\r
-      {\r
-        if (coder->PropsSize != 1)\r
-          return SZ_ERROR_UNSUPPORTED;\r
-        {\r
-          Byte state[DELTA_STATE_SIZE];\r
-          Delta_Init(state);\r
-          Delta_Decode(state, (unsigned)(propsData[coder->PropsOffset]) + 1, outBuffer, outSize);\r
-        }\r
-      }\r
-      else\r
-      {\r
-        if (coder->PropsSize != 0)\r
-          return SZ_ERROR_UNSUPPORTED;\r
-        switch (coder->MethodID)\r
-        {\r
-          case k_BCJ:\r
-          {\r
-            UInt32 state;\r
-            x86_Convert_Init(state);\r
-            x86_Convert(outBuffer, outSize, 0, &state, 0);\r
-            break;\r
-          }\r
-          CASE_BRA_CONV(PPC)\r
-          CASE_BRA_CONV(IA64)\r
-          CASE_BRA_CONV(SPARC)\r
-          CASE_BRA_CONV(ARM)\r
-          CASE_BRA_CONV(ARMT)\r
-          default:\r
-            return SZ_ERROR_UNSUPPORTED;\r
-        }\r
-      }\r
-    }\r
-    #endif\r
-    else\r
-      return SZ_ERROR_UNSUPPORTED;\r
-  }\r
-\r
-  return SZ_OK;\r
-}\r
-\r
-\r
-SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,\r
-    ILookInStream *inStream, UInt64 startPos,\r
-    Byte *outBuffer, size_t outSize,\r
-    ISzAlloc *allocMain)\r
-{\r
-  SRes res;\r
-  CSzFolder folder;\r
-  CSzData sd;\r
-  \r
-  const Byte *data = p->CodersData + p->FoCodersOffsets[folderIndex];\r
-  sd.Data = data;\r
-  sd.Size = p->FoCodersOffsets[folderIndex + 1] - p->FoCodersOffsets[folderIndex];\r
-  \r
-  res = SzGetNextFolderItem(&folder, &sd);\r
-  \r
-  if (res != SZ_OK)\r
-    return res;\r
-\r
-  if (sd.Size != 0\r
-      || folder.UnpackStream != p->FoToMainUnpackSizeIndex[folderIndex]\r
-      || outSize != SzAr_GetFolderUnpackSize(p, folderIndex))\r
-    return SZ_ERROR_FAIL;\r
-  {\r
-    unsigned i;\r
-    Byte *tempBuf[3] = { 0, 0, 0};\r
-\r
-    res = SzFolder_Decode2(&folder, data,\r
-        &p->CoderUnpackSizes[p->FoToCoderUnpackSizes[folderIndex]],\r
-        p->PackPositions + p->FoStartPackStreamIndex[folderIndex],\r
-        inStream, startPos,\r
-        outBuffer, (SizeT)outSize, allocMain, tempBuf);\r
-    \r
-    for (i = 0; i < 3; i++)\r
-      IAlloc_Free(allocMain, tempBuf[i]);\r
-\r
-    if (res == SZ_OK)\r
-      if (SzBitWithVals_Check(&p->FolderCRCs, folderIndex))\r
-        if (CrcCalc(outBuffer, outSize) != p->FolderCRCs.Vals[folderIndex])\r
-          res = SZ_ERROR_CRC;\r
-\r
-    return res;\r
-  }\r
-}\r
diff --git a/deps/lzma-16.04/C/7zFile.c b/deps/lzma-16.04/C/7zFile.c
deleted file mode 100644 (file)
index 98fe716..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/* 7zFile.c -- File IO\r
-2009-11-24 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "7zFile.h"\r
-\r
-#ifndef USE_WINDOWS_FILE\r
-\r
-#ifndef UNDER_CE\r
-#include <errno.h>\r
-#endif\r
-\r
-#else\r
-\r
-/*\r
-   ReadFile and WriteFile functions in Windows have BUG:\r
-   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r
-   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r
-   (Insufficient system resources exist to complete the requested service).\r
-   Probably in some version of Windows there are problems with other sizes:\r
-   for 32 MB (maybe also for 16 MB).\r
-   And message can be "Network connection was lost"\r
-*/\r
-\r
-#define kChunkSizeMax (1 << 22)\r
-\r
-#endif\r
-\r
-void File_Construct(CSzFile *p)\r
-{\r
-  #ifdef USE_WINDOWS_FILE\r
-  p->handle = INVALID_HANDLE_VALUE;\r
-  #else\r
-  p->file = NULL;\r
-  #endif\r
-}\r
-\r
-#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)\r
-static WRes File_Open(CSzFile *p, const char *name, int writeMode)\r
-{\r
-  #ifdef USE_WINDOWS_FILE\r
-  p->handle = CreateFileA(name,\r
-      writeMode ? GENERIC_WRITE : GENERIC_READ,\r
-      FILE_SHARE_READ, NULL,\r
-      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\r
-      FILE_ATTRIBUTE_NORMAL, NULL);\r
-  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r
-  #else\r
-  p->file = fopen(name, writeMode ? "wb+" : "rb");\r
-  return (p->file != 0) ? 0 :\r
-    #ifdef UNDER_CE\r
-    2; /* ENOENT */\r
-    #else\r
-    errno;\r
-    #endif\r
-  #endif\r
-}\r
-\r
-WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }\r
-WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }\r
-#endif\r
-\r
-#ifdef USE_WINDOWS_FILE\r
-static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode)\r
-{\r
-  p->handle = CreateFileW(name,\r
-      writeMode ? GENERIC_WRITE : GENERIC_READ,\r
-      FILE_SHARE_READ, NULL,\r
-      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\r
-      FILE_ATTRIBUTE_NORMAL, NULL);\r
-  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r
-}\r
-WRes InFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 0); }\r
-WRes OutFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 1); }\r
-#endif\r
-\r
-WRes File_Close(CSzFile *p)\r
-{\r
-  #ifdef USE_WINDOWS_FILE\r
-  if (p->handle != INVALID_HANDLE_VALUE)\r
-  {\r
-    if (!CloseHandle(p->handle))\r
-      return GetLastError();\r
-    p->handle = INVALID_HANDLE_VALUE;\r
-  }\r
-  #else\r
-  if (p->file != NULL)\r
-  {\r
-    int res = fclose(p->file);\r
-    if (res != 0)\r
-      return res;\r
-    p->file = NULL;\r
-  }\r
-  #endif\r
-  return 0;\r
-}\r
-\r
-WRes File_Read(CSzFile *p, void *data, size_t *size)\r
-{\r
-  size_t originalSize = *size;\r
-  if (originalSize == 0)\r
-    return 0;\r
-\r
-  #ifdef USE_WINDOWS_FILE\r
-\r
-  *size = 0;\r
-  do\r
-  {\r
-    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r
-    DWORD processed = 0;\r
-    BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);\r
-    data = (void *)((Byte *)data + processed);\r
-    originalSize -= processed;\r
-    *size += processed;\r
-    if (!res)\r
-      return GetLastError();\r
-    if (processed == 0)\r
-      break;\r
-  }\r
-  while (originalSize > 0);\r
-  return 0;\r
-\r
-  #else\r
-  \r
-  *size = fread(data, 1, originalSize, p->file);\r
-  if (*size == originalSize)\r
-    return 0;\r
-  return ferror(p->file);\r
-  \r
-  #endif\r
-}\r
-\r
-WRes File_Write(CSzFile *p, const void *data, size_t *size)\r
-{\r
-  size_t originalSize = *size;\r
-  if (originalSize == 0)\r
-    return 0;\r
-  \r
-  #ifdef USE_WINDOWS_FILE\r
-\r
-  *size = 0;\r
-  do\r
-  {\r
-    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r
-    DWORD processed = 0;\r
-    BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);\r
-    data = (void *)((Byte *)data + processed);\r
-    originalSize -= processed;\r
-    *size += processed;\r
-    if (!res)\r
-      return GetLastError();\r
-    if (processed == 0)\r
-      break;\r
-  }\r
-  while (originalSize > 0);\r
-  return 0;\r
-\r
-  #else\r
-\r
-  *size = fwrite(data, 1, originalSize, p->file);\r
-  if (*size == originalSize)\r
-    return 0;\r
-  return ferror(p->file);\r
-  \r
-  #endif\r
-}\r
-\r
-WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)\r
-{\r
-  #ifdef USE_WINDOWS_FILE\r
-\r
-  LARGE_INTEGER value;\r
-  DWORD moveMethod;\r
-  value.LowPart = (DWORD)*pos;\r
-  value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */\r
-  switch (origin)\r
-  {\r
-    case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;\r
-    case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;\r
-    case SZ_SEEK_END: moveMethod = FILE_END; break;\r
-    default: return ERROR_INVALID_PARAMETER;\r
-  }\r
-  value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);\r
-  if (value.LowPart == 0xFFFFFFFF)\r
-  {\r
-    WRes res = GetLastError();\r
-    if (res != NO_ERROR)\r
-      return res;\r
-  }\r
-  *pos = ((Int64)value.HighPart << 32) | value.LowPart;\r
-  return 0;\r
-\r
-  #else\r
-  \r
-  int moveMethod;\r
-  int res;\r
-  switch (origin)\r
-  {\r
-    case SZ_SEEK_SET: moveMethod = SEEK_SET; break;\r
-    case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;\r
-    case SZ_SEEK_END: moveMethod = SEEK_END; break;\r
-    default: return 1;\r
-  }\r
-  res = fseek(p->file, (long)*pos, moveMethod);\r
-  *pos = ftell(p->file);\r
-  return res;\r
-  \r
-  #endif\r
-}\r
-\r
-WRes File_GetLength(CSzFile *p, UInt64 *length)\r
-{\r
-  #ifdef USE_WINDOWS_FILE\r
-  \r
-  DWORD sizeHigh;\r
-  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);\r
-  if (sizeLow == 0xFFFFFFFF)\r
-  {\r
-    DWORD res = GetLastError();\r
-    if (res != NO_ERROR)\r
-      return res;\r
-  }\r
-  *length = (((UInt64)sizeHigh) << 32) + sizeLow;\r
-  return 0;\r
-  \r
-  #else\r
-  \r
-  long pos = ftell(p->file);\r
-  int res = fseek(p->file, 0, SEEK_END);\r
-  *length = ftell(p->file);\r
-  fseek(p->file, pos, SEEK_SET);\r
-  return res;\r
-  \r
-  #endif\r
-}\r
-\r
-\r
-/* ---------- FileSeqInStream ---------- */\r
-\r
-static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)\r
-{\r
-  CFileSeqInStream *p = (CFileSeqInStream *)pp;\r
-  return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;\r
-}\r
-\r
-void FileSeqInStream_CreateVTable(CFileSeqInStream *p)\r
-{\r
-  p->s.Read = FileSeqInStream_Read;\r
-}\r
-\r
-\r
-/* ---------- FileInStream ---------- */\r
-\r
-static SRes FileInStream_Read(void *pp, void *buf, size_t *size)\r
-{\r
-  CFileInStream *p = (CFileInStream *)pp;\r
-  return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;\r
-}\r
-\r
-static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)\r
-{\r
-  CFileInStream *p = (CFileInStream *)pp;\r
-  return File_Seek(&p->file, pos, origin);\r
-}\r
-\r
-void FileInStream_CreateVTable(CFileInStream *p)\r
-{\r
-  p->s.Read = FileInStream_Read;\r
-  p->s.Seek = FileInStream_Seek;\r
-}\r
-\r
-\r
-/* ---------- FileOutStream ---------- */\r
-\r
-static size_t FileOutStream_Write(void *pp, const void *data, size_t size)\r
-{\r
-  CFileOutStream *p = (CFileOutStream *)pp;\r
-  File_Write(&p->file, data, &size);\r
-  return size;\r
-}\r
-\r
-void FileOutStream_CreateVTable(CFileOutStream *p)\r
-{\r
-  p->s.Write = FileOutStream_Write;\r
-}\r
diff --git a/deps/lzma-16.04/C/7zFile.h b/deps/lzma-16.04/C/7zFile.h
deleted file mode 100644 (file)
index d62a192..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/* 7zFile.h -- File IO\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_FILE_H\r
-#define __7Z_FILE_H\r
-\r
-#ifdef _WIN32\r
-#define USE_WINDOWS_FILE\r
-#endif\r
-\r
-#ifdef USE_WINDOWS_FILE\r
-#include <windows.h>\r
-#else\r
-#include <stdio.h>\r
-#endif\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-/* ---------- File ---------- */\r
-\r
-typedef struct\r
-{\r
-  #ifdef USE_WINDOWS_FILE\r
-  HANDLE handle;\r
-  #else\r
-  FILE *file;\r
-  #endif\r
-} CSzFile;\r
-\r
-void File_Construct(CSzFile *p);\r
-#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)\r
-WRes InFile_Open(CSzFile *p, const char *name);\r
-WRes OutFile_Open(CSzFile *p, const char *name);\r
-#endif\r
-#ifdef USE_WINDOWS_FILE\r
-WRes InFile_OpenW(CSzFile *p, const WCHAR *name);\r
-WRes OutFile_OpenW(CSzFile *p, const WCHAR *name);\r
-#endif\r
-WRes File_Close(CSzFile *p);\r
-\r
-/* reads max(*size, remain file's size) bytes */\r
-WRes File_Read(CSzFile *p, void *data, size_t *size);\r
-\r
-/* writes *size bytes */\r
-WRes File_Write(CSzFile *p, const void *data, size_t *size);\r
-\r
-WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);\r
-WRes File_GetLength(CSzFile *p, UInt64 *length);\r
-\r
-\r
-/* ---------- FileInStream ---------- */\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream s;\r
-  CSzFile file;\r
-} CFileSeqInStream;\r
-\r
-void FileSeqInStream_CreateVTable(CFileSeqInStream *p);\r
-\r
-\r
-typedef struct\r
-{\r
-  ISeekInStream s;\r
-  CSzFile file;\r
-} CFileInStream;\r
-\r
-void FileInStream_CreateVTable(CFileInStream *p);\r
-\r
-\r
-typedef struct\r
-{\r
-  ISeqOutStream s;\r
-  CSzFile file;\r
-} CFileOutStream;\r
-\r
-void FileOutStream_CreateVTable(CFileOutStream *p);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/7zStream.c b/deps/lzma-16.04/C/7zStream.c
deleted file mode 100644 (file)
index 5a92d53..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/* 7zStream.c -- 7z Stream functions\r
-2013-11-12 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-#include "7zTypes.h"\r
-\r
-SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)\r
-{\r
-  while (size != 0)\r
-  {\r
-    size_t processed = size;\r
-    RINOK(stream->Read(stream, buf, &processed));\r
-    if (processed == 0)\r
-      return errorType;\r
-    buf = (void *)((Byte *)buf + processed);\r
-    size -= processed;\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)\r
-{\r
-  return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r
-}\r
-\r
-SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)\r
-{\r
-  size_t processed = 1;\r
-  RINOK(stream->Read(stream, buf, &processed));\r
-  return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;\r
-}\r
-\r
-SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)\r
-{\r
-  Int64 t = offset;\r
-  return stream->Seek(stream, &t, SZ_SEEK_SET);\r
-}\r
-\r
-SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)\r
-{\r
-  const void *lookBuf;\r
-  if (*size == 0)\r
-    return SZ_OK;\r
-  RINOK(stream->Look(stream, &lookBuf, size));\r
-  memcpy(buf, lookBuf, *size);\r
-  return stream->Skip(stream, *size);\r
-}\r
-\r
-SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)\r
-{\r
-  while (size != 0)\r
-  {\r
-    size_t processed = size;\r
-    RINOK(stream->Read(stream, buf, &processed));\r
-    if (processed == 0)\r
-      return errorType;\r
-    buf = (void *)((Byte *)buf + processed);\r
-    size -= processed;\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)\r
-{\r
-  return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r
-}\r
-\r
-static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size)\r
-{\r
-  SRes res = SZ_OK;\r
-  CLookToRead *p = (CLookToRead *)pp;\r
-  size_t size2 = p->size - p->pos;\r
-  if (size2 == 0 && *size > 0)\r
-  {\r
-    p->pos = 0;\r
-    size2 = LookToRead_BUF_SIZE;\r
-    res = p->realStream->Read(p->realStream, p->buf, &size2);\r
-    p->size = size2;\r
-  }\r
-  if (size2 < *size)\r
-    *size = size2;\r
-  *buf = p->buf + p->pos;\r
-  return res;\r
-}\r
-\r
-static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size)\r
-{\r
-  SRes res = SZ_OK;\r
-  CLookToRead *p = (CLookToRead *)pp;\r
-  size_t size2 = p->size - p->pos;\r
-  if (size2 == 0 && *size > 0)\r
-  {\r
-    p->pos = 0;\r
-    if (*size > LookToRead_BUF_SIZE)\r
-      *size = LookToRead_BUF_SIZE;\r
-    res = p->realStream->Read(p->realStream, p->buf, size);\r
-    size2 = p->size = *size;\r
-  }\r
-  if (size2 < *size)\r
-    *size = size2;\r
-  *buf = p->buf + p->pos;\r
-  return res;\r
-}\r
-\r
-static SRes LookToRead_Skip(void *pp, size_t offset)\r
-{\r
-  CLookToRead *p = (CLookToRead *)pp;\r
-  p->pos += offset;\r
-  return SZ_OK;\r
-}\r
-\r
-static SRes LookToRead_Read(void *pp, void *buf, size_t *size)\r
-{\r
-  CLookToRead *p = (CLookToRead *)pp;\r
-  size_t rem = p->size - p->pos;\r
-  if (rem == 0)\r
-    return p->realStream->Read(p->realStream, buf, size);\r
-  if (rem > *size)\r
-    rem = *size;\r
-  memcpy(buf, p->buf + p->pos, rem);\r
-  p->pos += rem;\r
-  *size = rem;\r
-  return SZ_OK;\r
-}\r
-\r
-static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)\r
-{\r
-  CLookToRead *p = (CLookToRead *)pp;\r
-  p->pos = p->size = 0;\r
-  return p->realStream->Seek(p->realStream, pos, origin);\r
-}\r
-\r
-void LookToRead_CreateVTable(CLookToRead *p, int lookahead)\r
-{\r
-  p->s.Look = lookahead ?\r
-      LookToRead_Look_Lookahead :\r
-      LookToRead_Look_Exact;\r
-  p->s.Skip = LookToRead_Skip;\r
-  p->s.Read = LookToRead_Read;\r
-  p->s.Seek = LookToRead_Seek;\r
-}\r
-\r
-void LookToRead_Init(CLookToRead *p)\r
-{\r
-  p->pos = p->size = 0;\r
-}\r
-\r
-static SRes SecToLook_Read(void *pp, void *buf, size_t *size)\r
-{\r
-  CSecToLook *p = (CSecToLook *)pp;\r
-  return LookInStream_LookRead(p->realStream, buf, size);\r
-}\r
-\r
-void SecToLook_CreateVTable(CSecToLook *p)\r
-{\r
-  p->s.Read = SecToLook_Read;\r
-}\r
-\r
-static SRes SecToRead_Read(void *pp, void *buf, size_t *size)\r
-{\r
-  CSecToRead *p = (CSecToRead *)pp;\r
-  return p->realStream->Read(p->realStream, buf, size);\r
-}\r
-\r
-void SecToRead_CreateVTable(CSecToRead *p)\r
-{\r
-  p->s.Read = SecToRead_Read;\r
-}\r
diff --git a/deps/lzma-16.04/C/7zTypes.h b/deps/lzma-16.04/C/7zTypes.h
deleted file mode 100644 (file)
index 894212a..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-/* 7zTypes.h -- Basic types\r
-2013-11-12 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_TYPES_H\r
-#define __7Z_TYPES_H\r
-\r
-#ifdef _WIN32\r
-/* #include <windows.h> */\r
-#endif\r
-\r
-#include <stddef.h>\r
-\r
-#ifndef EXTERN_C_BEGIN\r
-#ifdef __cplusplus\r
-#define EXTERN_C_BEGIN extern "C" {\r
-#define EXTERN_C_END }\r
-#else\r
-#define EXTERN_C_BEGIN\r
-#define EXTERN_C_END\r
-#endif\r
-#endif\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define SZ_OK 0\r
-\r
-#define SZ_ERROR_DATA 1\r
-#define SZ_ERROR_MEM 2\r
-#define SZ_ERROR_CRC 3\r
-#define SZ_ERROR_UNSUPPORTED 4\r
-#define SZ_ERROR_PARAM 5\r
-#define SZ_ERROR_INPUT_EOF 6\r
-#define SZ_ERROR_OUTPUT_EOF 7\r
-#define SZ_ERROR_READ 8\r
-#define SZ_ERROR_WRITE 9\r
-#define SZ_ERROR_PROGRESS 10\r
-#define SZ_ERROR_FAIL 11\r
-#define SZ_ERROR_THREAD 12\r
-\r
-#define SZ_ERROR_ARCHIVE 16\r
-#define SZ_ERROR_NO_ARCHIVE 17\r
-\r
-typedef int SRes;\r
-\r
-#ifdef _WIN32\r
-/* typedef DWORD WRes; */\r
-typedef unsigned WRes;\r
-#else\r
-typedef int WRes;\r
-#endif\r
-\r
-#ifndef RINOK\r
-#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r
-#endif\r
-\r
-#ifndef DONT_SET_BYTE\r
-typedef unsigned char Byte;\r
-#endif\r
-typedef short Int16;\r
-typedef unsigned short UInt16;\r
-\r
-#ifdef _LZMA_UINT32_IS_ULONG\r
-typedef long Int32;\r
-typedef unsigned long UInt32;\r
-#else\r
-typedef int Int32;\r
-typedef unsigned int UInt32;\r
-#endif\r
-\r
-#ifdef _SZ_NO_INT_64\r
-\r
-/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r
-   NOTES: Some code will work incorrectly in that case! */\r
-\r
-typedef long Int64;\r
-typedef unsigned long UInt64;\r
-\r
-#else\r
-\r
-#if defined(_MSC_VER) || defined(__BORLANDC__)\r
-typedef __int64 Int64;\r
-typedef unsigned __int64 UInt64;\r
-#define UINT64_CONST(n) n\r
-#else\r
-typedef long long int Int64;\r
-typedef unsigned long long int UInt64;\r
-#define UINT64_CONST(n) n ## ULL\r
-#endif\r
-\r
-#endif\r
-\r
-#ifdef _LZMA_NO_SYSTEM_SIZE_T\r
-typedef UInt32 SizeT;\r
-#else\r
-typedef size_t SizeT;\r
-#endif\r
-\r
-typedef int Bool;\r
-#define True 1\r
-#define False 0\r
-\r
-\r
-#ifdef _WIN32\r
-#define MY_STD_CALL __stdcall\r
-#else\r
-#define MY_STD_CALL\r
-#endif\r
-\r
-#ifdef _MSC_VER\r
-\r
-#if _MSC_VER >= 1300\r
-#define MY_NO_INLINE __declspec(noinline)\r
-#else\r
-#define MY_NO_INLINE\r
-#endif\r
-\r
-#define MY_CDECL __cdecl\r
-#define MY_FAST_CALL __fastcall\r
-\r
-#else\r
-\r
-#define MY_NO_INLINE\r
-#define MY_CDECL\r
-#define MY_FAST_CALL\r
-\r
-#endif\r
-\r
-\r
-/* The following interfaces use first parameter as pointer to structure */\r
-\r
-typedef struct\r
-{\r
-  Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */\r
-} IByteIn;\r
-\r
-typedef struct\r
-{\r
-  void (*Write)(void *p, Byte b);\r
-} IByteOut;\r
-\r
-typedef struct\r
-{\r
-  SRes (*Read)(void *p, void *buf, size_t *size);\r
-    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
-       (output(*size) < input(*size)) is allowed */\r
-} ISeqInStream;\r
-\r
-/* it can return SZ_ERROR_INPUT_EOF */\r
-SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r
-SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r
-SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r
-\r
-typedef struct\r
-{\r
-  size_t (*Write)(void *p, const void *buf, size_t size);\r
-    /* Returns: result - the number of actually written bytes.\r
-       (result < size) means error */\r
-} ISeqOutStream;\r
-\r
-typedef enum\r
-{\r
-  SZ_SEEK_SET = 0,\r
-  SZ_SEEK_CUR = 1,\r
-  SZ_SEEK_END = 2\r
-} ESzSeek;\r
-\r
-typedef struct\r
-{\r
-  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r
-  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
-} ISeekInStream;\r
-\r
-typedef struct\r
-{\r
-  SRes (*Look)(void *p, const void **buf, size_t *size);\r
-    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
-       (output(*size) > input(*size)) is not allowed\r
-       (output(*size) < input(*size)) is allowed */\r
-  SRes (*Skip)(void *p, size_t offset);\r
-    /* offset must be <= output(*size) of Look */\r
-\r
-  SRes (*Read)(void *p, void *buf, size_t *size);\r
-    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r
-  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
-} ILookInStream;\r
-\r
-SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r
-SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r
-\r
-/* reads via ILookInStream::Read */\r
-SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r
-SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r
-\r
-#define LookToRead_BUF_SIZE (1 << 14)\r
-\r
-typedef struct\r
-{\r
-  ILookInStream s;\r
-  ISeekInStream *realStream;\r
-  size_t pos;\r
-  size_t size;\r
-  Byte buf[LookToRead_BUF_SIZE];\r
-} CLookToRead;\r
-\r
-void LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r
-void LookToRead_Init(CLookToRead *p);\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream s;\r
-  ILookInStream *realStream;\r
-} CSecToLook;\r
-\r
-void SecToLook_CreateVTable(CSecToLook *p);\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream s;\r
-  ILookInStream *realStream;\r
-} CSecToRead;\r
-\r
-void SecToRead_CreateVTable(CSecToRead *p);\r
-\r
-typedef struct\r
-{\r
-  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r
-    /* Returns: result. (result != SZ_OK) means break.\r
-       Value (UInt64)(Int64)-1 for size means unknown value. */\r
-} ICompressProgress;\r
-\r
-typedef struct\r
-{\r
-  void *(*Alloc)(void *p, size_t size);\r
-  void (*Free)(void *p, void *address); /* address can be 0 */\r
-} ISzAlloc;\r
-\r
-#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r
-#define IAlloc_Free(p, a) (p)->Free((p), a)\r
-\r
-#ifdef _WIN32\r
-\r
-#define CHAR_PATH_SEPARATOR '\\'\r
-#define WCHAR_PATH_SEPARATOR L'\\'\r
-#define STRING_PATH_SEPARATOR "\\"\r
-#define WSTRING_PATH_SEPARATOR L"\\"\r
-\r
-#else\r
-\r
-#define CHAR_PATH_SEPARATOR '/'\r
-#define WCHAR_PATH_SEPARATOR L'/'\r
-#define STRING_PATH_SEPARATOR "/"\r
-#define WSTRING_PATH_SEPARATOR L"/"\r
-\r
-#endif\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/7zVersion.h b/deps/lzma-16.04/C/7zVersion.h
deleted file mode 100644 (file)
index acb67a9..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#define MY_VER_MAJOR 16\r
-#define MY_VER_MINOR 04\r
-#define MY_VER_BUILD 0\r
-#define MY_VERSION_NUMBERS "16.04"\r
-#define MY_VERSION "16.04"\r
-#define MY_DATE "2016-10-04"\r
-#undef MY_COPYRIGHT\r
-#undef MY_VERSION_COPYRIGHT_DATE\r
-#define MY_AUTHOR_NAME "Igor Pavlov"\r
-#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain"\r
-#define MY_COPYRIGHT_CR "Copyright (c) 1999-2016 Igor Pavlov"\r
-\r
-#ifdef USE_COPYRIGHT_CR\r
-  #define MY_COPYRIGHT MY_COPYRIGHT_CR\r
-#else\r
-  #define MY_COPYRIGHT MY_COPYRIGHT_PD\r
-#endif\r
-\r
-#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " : " MY_COPYRIGHT " : " MY_DATE\r
diff --git a/deps/lzma-16.04/C/7zVersion.rc b/deps/lzma-16.04/C/7zVersion.rc
deleted file mode 100644 (file)
index 6ed26de..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#define MY_VS_FFI_FILEFLAGSMASK  0x0000003FL\r
-#define MY_VOS_NT_WINDOWS32  0x00040004L\r
-#define MY_VOS_CE_WINDOWS32  0x00050004L\r
-\r
-#define MY_VFT_APP  0x00000001L\r
-#define MY_VFT_DLL  0x00000002L\r
-\r
-// #include <WinVer.h>\r
-\r
-#ifndef MY_VERSION\r
-#include "7zVersion.h"\r
-#endif\r
-\r
-#define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0\r
-\r
-#ifdef DEBUG\r
-#define DBG_FL VS_FF_DEBUG\r
-#else\r
-#define DBG_FL 0\r
-#endif\r
-\r
-#define MY_VERSION_INFO(fileType, descr, intName, origName)  \\r
-LANGUAGE 9, 1 \\r
-1 VERSIONINFO \\r
-  FILEVERSION MY_VER \\r
-  PRODUCTVERSION MY_VER \\r
-  FILEFLAGSMASK MY_VS_FFI_FILEFLAGSMASK \\r
-  FILEFLAGS DBG_FL \\r
-  FILEOS MY_VOS_NT_WINDOWS32 \\r
-  FILETYPE fileType \\r
-  FILESUBTYPE 0x0L \\r
-BEGIN \\r
-    BLOCK "StringFileInfo" \\r
-    BEGIN  \\r
-        BLOCK "040904b0" \\r
-        BEGIN \\r
-            VALUE "CompanyName", "Igor Pavlov" \\r
-            VALUE "FileDescription", descr \\r
-            VALUE "FileVersion", MY_VERSION  \\r
-            VALUE "InternalName", intName \\r
-            VALUE "LegalCopyright", MY_COPYRIGHT \\r
-            VALUE "OriginalFilename", origName \\r
-            VALUE "ProductName", "7-Zip" \\r
-            VALUE "ProductVersion", MY_VERSION \\r
-        END \\r
-    END \\r
-    BLOCK "VarFileInfo" \\r
-    BEGIN \\r
-        VALUE "Translation", 0x409, 1200 \\r
-    END \\r
-END\r
-\r
-#define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(MY_VFT_APP, descr, intName, intName ".exe")\r
-\r
-#define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(MY_VFT_DLL, descr, intName, intName ".dll")\r
diff --git a/deps/lzma-16.04/C/Aes.c b/deps/lzma-16.04/C/Aes.c
deleted file mode 100644 (file)
index 8e658e7..0000000
+++ /dev/null
@@ -1,295 +0,0 @@
-/* Aes.c -- AES encryption / decryption\r
-2016-05-21 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Aes.h"\r
-#include "CpuArch.h"\r
-\r
-static UInt32 T[256 * 4];\r
-static const Byte Sbox[256] = {\r
-  0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,\r
-  0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,\r
-  0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,\r
-  0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,\r
-  0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,\r
-  0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,\r
-  0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,\r
-  0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,\r
-  0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,\r
-  0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,\r
-  0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,\r
-  0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,\r
-  0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,\r
-  0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,\r
-  0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,\r
-  0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16};\r
-\r
-void MY_FAST_CALL AesCbc_Encode(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-void MY_FAST_CALL AesCbc_Decode(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-void MY_FAST_CALL AesCtr_Code(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-\r
-void MY_FAST_CALL AesCbc_Encode_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-void MY_FAST_CALL AesCbc_Decode_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-void MY_FAST_CALL AesCtr_Code_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-\r
-AES_CODE_FUNC g_AesCbc_Encode;\r
-AES_CODE_FUNC g_AesCbc_Decode;\r
-AES_CODE_FUNC g_AesCtr_Code;\r
-\r
-static UInt32 D[256 * 4];\r
-static Byte InvS[256];\r
-\r
-static const Byte Rcon[11] = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };\r
-\r
-#define xtime(x) ((((x) << 1) ^ (((x) & 0x80) != 0 ? 0x1B : 0)) & 0xFF)\r
-\r
-#define Ui32(a0, a1, a2, a3) ((UInt32)(a0) | ((UInt32)(a1) << 8) | ((UInt32)(a2) << 16) | ((UInt32)(a3) << 24))\r
-\r
-#define gb0(x) ( (x)          & 0xFF)\r
-#define gb1(x) (((x) >> ( 8)) & 0xFF)\r
-#define gb2(x) (((x) >> (16)) & 0xFF)\r
-#define gb3(x) (((x) >> (24)) & 0xFF)\r
-\r
-void AesGenTables(void)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < 256; i++)\r
-    InvS[Sbox[i]] = (Byte)i;\r
-  \r
-  for (i = 0; i < 256; i++)\r
-  {\r
-    {\r
-      UInt32 a1 = Sbox[i];\r
-      UInt32 a2 = xtime(a1);\r
-      UInt32 a3 = a2 ^ a1;\r
-      T[        i] = Ui32(a2, a1, a1, a3);\r
-      T[0x100 + i] = Ui32(a3, a2, a1, a1);\r
-      T[0x200 + i] = Ui32(a1, a3, a2, a1);\r
-      T[0x300 + i] = Ui32(a1, a1, a3, a2);\r
-    }\r
-    {\r
-      UInt32 a1 = InvS[i];\r
-      UInt32 a2 = xtime(a1);\r
-      UInt32 a4 = xtime(a2);\r
-      UInt32 a8 = xtime(a4);\r
-      UInt32 a9 = a8 ^ a1;\r
-      UInt32 aB = a8 ^ a2 ^ a1;\r
-      UInt32 aD = a8 ^ a4 ^ a1;\r
-      UInt32 aE = a8 ^ a4 ^ a2;\r
-      D[        i] = Ui32(aE, a9, aD, aB);\r
-      D[0x100 + i] = Ui32(aB, aE, a9, aD);\r
-      D[0x200 + i] = Ui32(aD, aB, aE, a9);\r
-      D[0x300 + i] = Ui32(a9, aD, aB, aE);\r
-    }\r
-  }\r
-  \r
-  g_AesCbc_Encode = AesCbc_Encode;\r
-  g_AesCbc_Decode = AesCbc_Decode;\r
-  g_AesCtr_Code = AesCtr_Code;\r
-  \r
-  #ifdef MY_CPU_X86_OR_AMD64\r
-  if (CPU_Is_Aes_Supported())\r
-  {\r
-    g_AesCbc_Encode = AesCbc_Encode_Intel;\r
-    g_AesCbc_Decode = AesCbc_Decode_Intel;\r
-    g_AesCtr_Code = AesCtr_Code_Intel;\r
-  }\r
-  #endif\r
-}\r
-\r
-\r
-#define HT(i, x, s) (T + (x << 8))[gb ## x(s[(i + x) & 3])]\r
-\r
-#define HT4(m, i, s, p) m[i] = \\r
-    HT(i, 0, s) ^ \\r
-    HT(i, 1, s) ^ \\r
-    HT(i, 2, s) ^ \\r
-    HT(i, 3, s) ^ w[p + i]\r
-\r
-#define HT16(m, s, p) \\r
-    HT4(m, 0, s, p); \\r
-    HT4(m, 1, s, p); \\r
-    HT4(m, 2, s, p); \\r
-    HT4(m, 3, s, p); \\r
-\r
-#define FT(i, x) Sbox[gb ## x(m[(i + x) & 3])]\r
-#define FT4(i) dest[i] = Ui32(FT(i, 0), FT(i, 1), FT(i, 2), FT(i, 3)) ^ w[i];\r
-\r
-\r
-#define HD(i, x, s) (D + (x << 8))[gb ## x(s[(i - x) & 3])]\r
-\r
-#define HD4(m, i, s, p) m[i] = \\r
-    HD(i, 0, s) ^ \\r
-    HD(i, 1, s) ^ \\r
-    HD(i, 2, s) ^ \\r
-    HD(i, 3, s) ^ w[p + i];\r
-\r
-#define HD16(m, s, p) \\r
-    HD4(m, 0, s, p); \\r
-    HD4(m, 1, s, p); \\r
-    HD4(m, 2, s, p); \\r
-    HD4(m, 3, s, p); \\r
-\r
-#define FD(i, x) InvS[gb ## x(m[(i - x) & 3])]\r
-#define FD4(i) dest[i] = Ui32(FD(i, 0), FD(i, 1), FD(i, 2), FD(i, 3)) ^ w[i];\r
-\r
-void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *w, const Byte *key, unsigned keySize)\r
-{\r
-  unsigned i, wSize;\r
-  wSize = keySize + 28;\r
-  keySize /= 4;\r
-  w[0] = ((UInt32)keySize / 2) + 3;\r
-  w += 4;\r
-\r
-  for (i = 0; i < keySize; i++, key += 4)\r
-    w[i] = GetUi32(key);\r
-\r
-  for (; i < wSize; i++)\r
-  {\r
-    UInt32 t = w[i - 1];\r
-    unsigned rem = i % keySize;\r
-    if (rem == 0)\r
-      t = Ui32(Sbox[gb1(t)] ^ Rcon[i / keySize], Sbox[gb2(t)], Sbox[gb3(t)], Sbox[gb0(t)]);\r
-    else if (keySize > 6 && rem == 4)\r
-      t = Ui32(Sbox[gb0(t)], Sbox[gb1(t)], Sbox[gb2(t)], Sbox[gb3(t)]);\r
-    w[i] = w[i - keySize] ^ t;\r
-  }\r
-}\r
-\r
-void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *w, const Byte *key, unsigned keySize)\r
-{\r
-  unsigned i, num;\r
-  Aes_SetKey_Enc(w, key, keySize);\r
-  num = keySize + 20;\r
-  w += 8;\r
-  for (i = 0; i < num; i++)\r
-  {\r
-    UInt32 r = w[i];\r
-    w[i] =\r
-      D[        (unsigned)Sbox[gb0(r)]] ^\r
-      D[0x100 + (unsigned)Sbox[gb1(r)]] ^\r
-      D[0x200 + (unsigned)Sbox[gb2(r)]] ^\r
-      D[0x300 + (unsigned)Sbox[gb3(r)]];\r
-  }\r
-}\r
-\r
-/* Aes_Encode and Aes_Decode functions work with little-endian words.\r
-  src and dest are pointers to 4 UInt32 words.\r
-  src and dest can point to same block */\r
-\r
-static void Aes_Encode(const UInt32 *w, UInt32 *dest, const UInt32 *src)\r
-{\r
-  UInt32 s[4];\r
-  UInt32 m[4];\r
-  UInt32 numRounds2 = w[0];\r
-  w += 4;\r
-  s[0] = src[0] ^ w[0];\r
-  s[1] = src[1] ^ w[1];\r
-  s[2] = src[2] ^ w[2];\r
-  s[3] = src[3] ^ w[3];\r
-  w += 4;\r
-  for (;;)\r
-  {\r
-    HT16(m, s, 0);\r
-    if (--numRounds2 == 0)\r
-      break;\r
-    HT16(s, m, 4);\r
-    w += 8;\r
-  }\r
-  w += 4;\r
-  FT4(0); FT4(1); FT4(2); FT4(3);\r
-}\r
-\r
-static void Aes_Decode(const UInt32 *w, UInt32 *dest, const UInt32 *src)\r
-{\r
-  UInt32 s[4];\r
-  UInt32 m[4];\r
-  UInt32 numRounds2 = w[0];\r
-  w += 4 + numRounds2 * 8;\r
-  s[0] = src[0] ^ w[0];\r
-  s[1] = src[1] ^ w[1];\r
-  s[2] = src[2] ^ w[2];\r
-  s[3] = src[3] ^ w[3];\r
-  for (;;)\r
-  {\r
-    w -= 8;\r
-    HD16(m, s, 4);\r
-    if (--numRounds2 == 0)\r
-      break;\r
-    HD16(s, m, 0);\r
-  }\r
-  FD4(0); FD4(1); FD4(2); FD4(3);\r
-}\r
-\r
-void AesCbc_Init(UInt32 *p, const Byte *iv)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < 4; i++)\r
-    p[i] = GetUi32(iv + i * 4);\r
-}\r
-\r
-void MY_FAST_CALL AesCbc_Encode(UInt32 *p, Byte *data, size_t numBlocks)\r
-{\r
-  for (; numBlocks != 0; numBlocks--, data += AES_BLOCK_SIZE)\r
-  {\r
-    p[0] ^= GetUi32(data);\r
-    p[1] ^= GetUi32(data + 4);\r
-    p[2] ^= GetUi32(data + 8);\r
-    p[3] ^= GetUi32(data + 12);\r
-    \r
-    Aes_Encode(p + 4, p, p);\r
-    \r
-    SetUi32(data,      p[0]);\r
-    SetUi32(data + 4,  p[1]);\r
-    SetUi32(data + 8,  p[2]);\r
-    SetUi32(data + 12, p[3]);\r
-  }\r
-}\r
-\r
-void MY_FAST_CALL AesCbc_Decode(UInt32 *p, Byte *data, size_t numBlocks)\r
-{\r
-  UInt32 in[4], out[4];\r
-  for (; numBlocks != 0; numBlocks--, data += AES_BLOCK_SIZE)\r
-  {\r
-    in[0] = GetUi32(data);\r
-    in[1] = GetUi32(data + 4);\r
-    in[2] = GetUi32(data + 8);\r
-    in[3] = GetUi32(data + 12);\r
-\r
-    Aes_Decode(p + 4, out, in);\r
-\r
-    SetUi32(data,      p[0] ^ out[0]);\r
-    SetUi32(data + 4,  p[1] ^ out[1]);\r
-    SetUi32(data + 8,  p[2] ^ out[2]);\r
-    SetUi32(data + 12, p[3] ^ out[3]);\r
-    \r
-    p[0] = in[0];\r
-    p[1] = in[1];\r
-    p[2] = in[2];\r
-    p[3] = in[3];\r
-  }\r
-}\r
-\r
-void MY_FAST_CALL AesCtr_Code(UInt32 *p, Byte *data, size_t numBlocks)\r
-{\r
-  for (; numBlocks != 0; numBlocks--)\r
-  {\r
-    UInt32 temp[4];\r
-    Byte buf[16];\r
-    int i;\r
-\r
-    if (++p[0] == 0)\r
-      p[1]++;\r
-    \r
-    Aes_Encode(p + 4, temp, p);\r
-    \r
-    SetUi32(buf,      temp[0]);\r
-    SetUi32(buf + 4,  temp[1]);\r
-    SetUi32(buf + 8,  temp[2]);\r
-    SetUi32(buf + 12, temp[3]);\r
-    \r
-    for (i = 0; i < 16; i++)\r
-      *data++ ^= buf[i];\r
-  }\r
-}\r
diff --git a/deps/lzma-16.04/C/Aes.h b/deps/lzma-16.04/C/Aes.h
deleted file mode 100644 (file)
index 381e979..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Aes.h -- AES encryption / decryption\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __AES_H\r
-#define __AES_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define AES_BLOCK_SIZE 16\r
-\r
-/* Call AesGenTables one time before other AES functions */\r
-void AesGenTables(void);\r
-\r
-/* UInt32 pointers must be 16-byte aligned */\r
-\r
-/* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */\r
-#define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4)\r
-\r
-/* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */\r
-/* keySize = 16 or 24 or 32 (bytes) */\r
-typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize);\r
-void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize);\r
-void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize);\r
-\r
-/* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */\r
-void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */\r
-/* data - 16-byte aligned pointer to data */\r
-/* numBlocks - the number of 16-byte blocks in data array */\r
-typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-extern AES_CODE_FUNC g_AesCbc_Encode;\r
-extern AES_CODE_FUNC g_AesCbc_Decode;\r
-extern AES_CODE_FUNC g_AesCtr_Code;\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/AesOpt.c b/deps/lzma-16.04/C/AesOpt.c
deleted file mode 100644 (file)
index e5d4d26..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-/* AesOpt.c -- Intel's AES\r
-2013-11-12 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "CpuArch.h"\r
-\r
-#ifdef MY_CPU_X86_OR_AMD64\r
-#if _MSC_VER >= 1500\r
-#define USE_INTEL_AES\r
-#endif\r
-#endif\r
-\r
-#ifdef USE_INTEL_AES\r
-\r
-#include <wmmintrin.h>\r
-\r
-void MY_FAST_CALL AesCbc_Encode_Intel(__m128i *p, __m128i *data, size_t numBlocks)\r
-{\r
-  __m128i m = *p;\r
-  for (; numBlocks != 0; numBlocks--, data++)\r
-  {\r
-    UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;\r
-    const __m128i *w = p + 3;\r
-    m = _mm_xor_si128(m, *data);\r
-    m = _mm_xor_si128(m, p[2]);\r
-    do\r
-    {\r
-      m = _mm_aesenc_si128(m, w[0]);\r
-      m = _mm_aesenc_si128(m, w[1]);\r
-      w += 2;\r
-    }\r
-    while (--numRounds2 != 0);\r
-    m = _mm_aesenc_si128(m, w[0]);\r
-    m = _mm_aesenclast_si128(m, w[1]);\r
-    *data = m;\r
-  }\r
-  *p = m;\r
-}\r
-\r
-#define NUM_WAYS 3\r
-\r
-#define AES_OP_W(op, n) { \\r
-    const __m128i t = w[n]; \\r
-    m0 = op(m0, t); \\r
-    m1 = op(m1, t); \\r
-    m2 = op(m2, t); \\r
-    }\r
-\r
-#define AES_DEC(n) AES_OP_W(_mm_aesdec_si128, n)\r
-#define AES_DEC_LAST(n) AES_OP_W(_mm_aesdeclast_si128, n)\r
-#define AES_ENC(n) AES_OP_W(_mm_aesenc_si128, n)\r
-#define AES_ENC_LAST(n) AES_OP_W(_mm_aesenclast_si128, n)\r
-\r
-void MY_FAST_CALL AesCbc_Decode_Intel(__m128i *p, __m128i *data, size_t numBlocks)\r
-{\r
-  __m128i iv = *p;\r
-  for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS)\r
-  {\r
-    UInt32 numRounds2 = *(const UInt32 *)(p + 1);\r
-    const __m128i *w = p + numRounds2 * 2;\r
-    __m128i m0, m1, m2;\r
-    {\r
-      const __m128i t = w[2];\r
-      m0 = _mm_xor_si128(t, data[0]);\r
-      m1 = _mm_xor_si128(t, data[1]);\r
-      m2 = _mm_xor_si128(t, data[2]);\r
-    }\r
-    numRounds2--;\r
-    do\r
-    {\r
-      AES_DEC(1)\r
-      AES_DEC(0)\r
-      w -= 2;\r
-    }\r
-    while (--numRounds2 != 0);\r
-    AES_DEC(1)\r
-    AES_DEC_LAST(0)\r
-\r
-    {\r
-      __m128i t;\r
-      t = _mm_xor_si128(m0, iv); iv = data[0]; data[0] = t;\r
-      t = _mm_xor_si128(m1, iv); iv = data[1]; data[1] = t;\r
-      t = _mm_xor_si128(m2, iv); iv = data[2]; data[2] = t;\r
-    }\r
-  }\r
-  for (; numBlocks != 0; numBlocks--, data++)\r
-  {\r
-    UInt32 numRounds2 = *(const UInt32 *)(p + 1);\r
-    const __m128i *w = p + numRounds2 * 2;\r
-    __m128i m = _mm_xor_si128(w[2], *data);\r
-    numRounds2--;\r
-    do\r
-    {\r
-      m = _mm_aesdec_si128(m, w[1]);\r
-      m = _mm_aesdec_si128(m, w[0]);\r
-      w -= 2;\r
-    }\r
-    while (--numRounds2 != 0);\r
-    m = _mm_aesdec_si128(m, w[1]);\r
-    m = _mm_aesdeclast_si128(m, w[0]);\r
-\r
-    m = _mm_xor_si128(m, iv);\r
-    iv = *data;\r
-    *data = m;\r
-  }\r
-  *p = iv;\r
-}\r
-\r
-void MY_FAST_CALL AesCtr_Code_Intel(__m128i *p, __m128i *data, size_t numBlocks)\r
-{\r
-  __m128i ctr = *p;\r
-  __m128i one;\r
-  one.m128i_u64[0] = 1;\r
-  one.m128i_u64[1] = 0;\r
-  for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS)\r
-  {\r
-    UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;\r
-    const __m128i *w = p;\r
-    __m128i m0, m1, m2;\r
-    {\r
-      const __m128i t = w[2];\r
-      ctr = _mm_add_epi64(ctr, one); m0 = _mm_xor_si128(ctr, t);\r
-      ctr = _mm_add_epi64(ctr, one); m1 = _mm_xor_si128(ctr, t);\r
-      ctr = _mm_add_epi64(ctr, one); m2 = _mm_xor_si128(ctr, t);\r
-    }\r
-    w += 3;\r
-    do\r
-    {\r
-      AES_ENC(0)\r
-      AES_ENC(1)\r
-      w += 2;\r
-    }\r
-    while (--numRounds2 != 0);\r
-    AES_ENC(0)\r
-    AES_ENC_LAST(1)\r
-    data[0] = _mm_xor_si128(data[0], m0);\r
-    data[1] = _mm_xor_si128(data[1], m1);\r
-    data[2] = _mm_xor_si128(data[2], m2);\r
-  }\r
-  for (; numBlocks != 0; numBlocks--, data++)\r
-  {\r
-    UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;\r
-    const __m128i *w = p;\r
-    __m128i m;\r
-    ctr = _mm_add_epi64(ctr, one);\r
-    m = _mm_xor_si128(ctr, p[2]);\r
-    w += 3;\r
-    do\r
-    {\r
-      m = _mm_aesenc_si128(m, w[0]);\r
-      m = _mm_aesenc_si128(m, w[1]);\r
-      w += 2;\r
-    }\r
-    while (--numRounds2 != 0);\r
-    m = _mm_aesenc_si128(m, w[0]);\r
-    m = _mm_aesenclast_si128(m, w[1]);\r
-    *data = _mm_xor_si128(*data, m);\r
-  }\r
-  *p = ctr;\r
-}\r
-\r
-#else\r
-\r
-void MY_FAST_CALL AesCbc_Encode(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-void MY_FAST_CALL AesCbc_Decode(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-void MY_FAST_CALL AesCtr_Code(UInt32 *ivAes, Byte *data, size_t numBlocks);\r
-\r
-void MY_FAST_CALL AesCbc_Encode_Intel(UInt32 *p, Byte *data, size_t numBlocks)\r
-{\r
-  AesCbc_Encode(p, data, numBlocks);\r
-}\r
-\r
-void MY_FAST_CALL AesCbc_Decode_Intel(UInt32 *p, Byte *data, size_t numBlocks)\r
-{\r
-  AesCbc_Decode(p, data, numBlocks);\r
-}\r
-\r
-void MY_FAST_CALL AesCtr_Code_Intel(UInt32 *p, Byte *data, size_t numBlocks)\r
-{\r
-  AesCtr_Code(p, data, numBlocks);\r
-}\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Alloc.c b/deps/lzma-16.04/C/Alloc.c
deleted file mode 100644 (file)
index 9f1d036..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/* Alloc.c -- Memory allocation functions\r
-2015-02-21 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#ifdef _WIN32\r
-#include <windows.h>\r
-#endif\r
-#include <stdlib.h>\r
-\r
-#include "Alloc.h"\r
-\r
-/* #define _SZ_ALLOC_DEBUG */\r
-\r
-/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r
-#ifdef _SZ_ALLOC_DEBUG\r
-#include <stdio.h>\r
-int g_allocCount = 0;\r
-int g_allocCountMid = 0;\r
-int g_allocCountBig = 0;\r
-#endif\r
-\r
-void *MyAlloc(size_t size)\r
-{\r
-  if (size == 0)\r
-    return 0;\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  {\r
-    void *p = malloc(size);\r
-    fprintf(stderr, "\nAlloc %10d bytes, count = %10d,  addr = %8X", size, g_allocCount++, (unsigned)p);\r
-    return p;\r
-  }\r
-  #else\r
-  return malloc(size);\r
-  #endif\r
-}\r
-\r
-void MyFree(void *address)\r
-{\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  if (address != 0)\r
-    fprintf(stderr, "\nFree; count = %10d,  addr = %8X", --g_allocCount, (unsigned)address);\r
-  #endif\r
-  free(address);\r
-}\r
-\r
-#ifdef _WIN32\r
-\r
-void *MidAlloc(size_t size)\r
-{\r
-  if (size == 0)\r
-    return 0;\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  fprintf(stderr, "\nAlloc_Mid %10d bytes;  count = %10d", size, g_allocCountMid++);\r
-  #endif\r
-  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r
-}\r
-\r
-void MidFree(void *address)\r
-{\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  if (address != 0)\r
-    fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);\r
-  #endif\r
-  if (address == 0)\r
-    return;\r
-  VirtualFree(address, 0, MEM_RELEASE);\r
-}\r
-\r
-#ifndef MEM_LARGE_PAGES\r
-#undef _7ZIP_LARGE_PAGES\r
-#endif\r
-\r
-#ifdef _7ZIP_LARGE_PAGES\r
-SIZE_T g_LargePageSize = 0;\r
-typedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r
-#endif\r
-\r
-void SetLargePageSize()\r
-{\r
-  #ifdef _7ZIP_LARGE_PAGES\r
-  SIZE_T size = 0;\r
-  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r
-        GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");\r
-  if (largePageMinimum == 0)\r
-    return;\r
-  size = largePageMinimum();\r
-  if (size == 0 || (size & (size - 1)) != 0)\r
-    return;\r
-  g_LargePageSize = size;\r
-  #endif\r
-}\r
-\r
-\r
-void *BigAlloc(size_t size)\r
-{\r
-  if (size == 0)\r
-    return 0;\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  fprintf(stderr, "\nAlloc_Big %10d bytes;  count = %10d", size, g_allocCountBig++);\r
-  #endif\r
-  \r
-  #ifdef _7ZIP_LARGE_PAGES\r
-  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))\r
-  {\r
-    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),\r
-        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r
-    if (res != 0)\r
-      return res;\r
-  }\r
-  #endif\r
-  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r
-}\r
-\r
-void BigFree(void *address)\r
-{\r
-  #ifdef _SZ_ALLOC_DEBUG\r
-  if (address != 0)\r
-    fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);\r
-  #endif\r
-  \r
-  if (address == 0)\r
-    return;\r
-  VirtualFree(address, 0, MEM_RELEASE);\r
-}\r
-\r
-#endif\r
-\r
-\r
-static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }\r
-static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); }\r
-ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
-\r
-static void *SzBigAlloc(void *p, size_t size) { UNUSED_VAR(p); return BigAlloc(size); }\r
-static void SzBigFree(void *p, void *address) { UNUSED_VAR(p); BigFree(address); }\r
-ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };\r
diff --git a/deps/lzma-16.04/C/Bcj2.c b/deps/lzma-16.04/C/Bcj2.c
deleted file mode 100644 (file)
index 707362a..0000000
+++ /dev/null
@@ -1,256 +0,0 @@
-/* Bcj2.c -- BCJ2 Decoder (Converter for x86 code)\r
-2015-08-01 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Bcj2.h"\r
-#include "CpuArch.h"\r
-\r
-#define CProb UInt16\r
-\r
-#define kTopValue ((UInt32)1 << 24)\r
-#define kNumModelBits 11\r
-#define kBitModelTotal (1 << kNumModelBits)\r
-#define kNumMoveBits 5\r
-\r
-#define _IF_BIT_0 ttt = *prob; bound = (p->range >> kNumModelBits) * ttt; if (p->code < bound)\r
-#define _UPDATE_0 p->range = bound; *prob = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r
-#define _UPDATE_1 p->range -= bound; p->code -= bound; *prob = (CProb)(ttt - (ttt >> kNumMoveBits));\r
-\r
-void Bcj2Dec_Init(CBcj2Dec *p)\r
-{\r
-  unsigned i;\r
-\r
-  p->state = BCJ2_DEC_STATE_OK;\r
-  p->ip = 0;\r
-  p->temp[3] = 0;\r
-  p->range = 0;\r
-  p->code = 0;\r
-  for (i = 0; i < sizeof(p->probs) / sizeof(p->probs[0]); i++)\r
-    p->probs[i] = kBitModelTotal >> 1;\r
-}\r
-\r
-SRes Bcj2Dec_Decode(CBcj2Dec *p)\r
-{\r
-  if (p->range <= 5)\r
-  {\r
-    p->state = BCJ2_DEC_STATE_OK;\r
-    for (; p->range != 5; p->range++)\r
-    {\r
-      if (p->range == 1 && p->code != 0)\r
-        return SZ_ERROR_DATA;\r
-      \r
-      if (p->bufs[BCJ2_STREAM_RC] == p->lims[BCJ2_STREAM_RC])\r
-      {\r
-        p->state = BCJ2_STREAM_RC;\r
-        return SZ_OK;\r
-      }\r
-\r
-      p->code = (p->code << 8) | *(p->bufs[BCJ2_STREAM_RC])++;\r
-    }\r
-    \r
-    if (p->code == 0xFFFFFFFF)\r
-      return SZ_ERROR_DATA;\r
-    \r
-    p->range = 0xFFFFFFFF;\r
-  }\r
-  else if (p->state >= BCJ2_DEC_STATE_ORIG_0)\r
-  {\r
-    while (p->state <= BCJ2_DEC_STATE_ORIG_3)\r
-    {\r
-      Byte *dest = p->dest;\r
-      if (dest == p->destLim)\r
-        return SZ_OK;\r
-      *dest = p->temp[p->state++ - BCJ2_DEC_STATE_ORIG_0];\r
-      p->dest = dest + 1;\r
-    }\r
-  }\r
-\r
-  /*\r
-  if (BCJ2_IS_32BIT_STREAM(p->state))\r
-  {\r
-    const Byte *cur = p->bufs[p->state];\r
-    if (cur == p->lims[p->state])\r
-      return SZ_OK;\r
-    p->bufs[p->state] = cur + 4;\r
-    \r
-    {\r
-      UInt32 val;\r
-      Byte *dest;\r
-      SizeT rem;\r
-      \r
-      p->ip += 4;\r
-      val = GetBe32(cur) - p->ip;\r
-      dest = p->dest;\r
-      rem = p->destLim - dest;\r
-      if (rem < 4)\r
-      {\r
-        SizeT i;\r
-        SetUi32(p->temp, val);\r
-        for (i = 0; i < rem; i++)\r
-          dest[i] = p->temp[i];\r
-        p->dest = dest + rem;\r
-        p->state = BCJ2_DEC_STATE_ORIG_0 + (unsigned)rem;\r
-        return SZ_OK;\r
-      }\r
-      SetUi32(dest, val);\r
-      p->temp[3] = (Byte)(val >> 24);\r
-      p->dest = dest + 4;\r
-      p->state = BCJ2_DEC_STATE_OK;\r
-    }\r
-  }\r
-  */\r
-\r
-  for (;;)\r
-  {\r
-    if (BCJ2_IS_32BIT_STREAM(p->state))\r
-      p->state = BCJ2_DEC_STATE_OK;\r
-    else\r
-    {\r
-      if (p->range < kTopValue)\r
-      {\r
-        if (p->bufs[BCJ2_STREAM_RC] == p->lims[BCJ2_STREAM_RC])\r
-        {\r
-          p->state = BCJ2_STREAM_RC;\r
-          return SZ_OK;\r
-        }\r
-        p->range <<= 8;\r
-        p->code = (p->code << 8) | *(p->bufs[BCJ2_STREAM_RC])++;\r
-      }\r
-\r
-      {\r
-        const Byte *src = p->bufs[BCJ2_STREAM_MAIN];\r
-        const Byte *srcLim;\r
-        Byte *dest;\r
-        SizeT num = p->lims[BCJ2_STREAM_MAIN] - src;\r
-        \r
-        if (num == 0)\r
-        {\r
-          p->state = BCJ2_STREAM_MAIN;\r
-          return SZ_OK;\r
-        }\r
-        \r
-        dest = p->dest;\r
-        if (num > (SizeT)(p->destLim - dest))\r
-        {\r
-          num = p->destLim - dest;\r
-          if (num == 0)\r
-          {\r
-            p->state = BCJ2_DEC_STATE_ORIG;\r
-            return SZ_OK;\r
-          }\r
-        }\r
-       \r
-        srcLim = src + num;\r
-\r
-        if (p->temp[3] == 0x0F && (src[0] & 0xF0) == 0x80)\r
-          *dest = src[0];\r
-        else for (;;)\r
-        {\r
-          Byte b = *src;\r
-          *dest = b;\r
-          if (b != 0x0F)\r
-          {\r
-            if ((b & 0xFE) == 0xE8)\r
-              break;\r
-            dest++;\r
-            if (++src != srcLim)\r
-              continue;\r
-            break;\r
-          }\r
-          dest++;\r
-          if (++src == srcLim)\r
-            break;\r
-          if ((*src & 0xF0) != 0x80)\r
-            continue;\r
-          *dest = *src;\r
-          break;\r
-        }\r
-        \r
-        num = src - p->bufs[BCJ2_STREAM_MAIN];\r
-        \r
-        if (src == srcLim)\r
-        {\r
-          p->temp[3] = src[-1];\r
-          p->bufs[BCJ2_STREAM_MAIN] = src;\r
-          p->ip += (UInt32)num;\r
-          p->dest += num;\r
-          p->state =\r
-            p->bufs[BCJ2_STREAM_MAIN] ==\r
-            p->lims[BCJ2_STREAM_MAIN] ?\r
-              (unsigned)BCJ2_STREAM_MAIN :\r
-              (unsigned)BCJ2_DEC_STATE_ORIG;\r
-          return SZ_OK;\r
-        }\r
-        \r
-        {\r
-          UInt32 bound, ttt;\r
-          CProb *prob;\r
-          Byte b = src[0];\r
-          Byte prev = (Byte)(num == 0 ? p->temp[3] : src[-1]);\r
-          \r
-          p->temp[3] = b;\r
-          p->bufs[BCJ2_STREAM_MAIN] = src + 1;\r
-          num++;\r
-          p->ip += (UInt32)num;\r
-          p->dest += num;\r
-          \r
-          prob = p->probs + (unsigned)(b == 0xE8 ? 2 + (unsigned)prev : (b == 0xE9 ? 1 : 0));\r
-          \r
-          _IF_BIT_0\r
-          {\r
-            _UPDATE_0\r
-            continue;\r
-          }\r
-          _UPDATE_1\r
-            \r
-        }\r
-      }\r
-    }\r
-\r
-    {\r
-      UInt32 val;\r
-      unsigned cj = (p->temp[3] == 0xE8) ? BCJ2_STREAM_CALL : BCJ2_STREAM_JUMP;\r
-      const Byte *cur = p->bufs[cj];\r
-      Byte *dest;\r
-      SizeT rem;\r
-      \r
-      if (cur == p->lims[cj])\r
-      {\r
-        p->state = cj;\r
-        break;\r
-      }\r
-      \r
-      val = GetBe32(cur);\r
-      p->bufs[cj] = cur + 4;\r
-\r
-      p->ip += 4;\r
-      val -= p->ip;\r
-      dest = p->dest;\r
-      rem = p->destLim - dest;\r
-      \r
-      if (rem < 4)\r
-      {\r
-        SizeT i;\r
-        SetUi32(p->temp, val);\r
-        for (i = 0; i < rem; i++)\r
-          dest[i] = p->temp[i];\r
-        p->dest = dest + rem;\r
-        p->state = BCJ2_DEC_STATE_ORIG_0 + (unsigned)rem;\r
-        break;\r
-      }\r
-      \r
-      SetUi32(dest, val);\r
-      p->temp[3] = (Byte)(val >> 24);\r
-      p->dest = dest + 4;\r
-    }\r
-  }\r
-\r
-  if (p->range < kTopValue && p->bufs[BCJ2_STREAM_RC] != p->lims[BCJ2_STREAM_RC])\r
-  {\r
-    p->range <<= 8;\r
-    p->code = (p->code << 8) | *(p->bufs[BCJ2_STREAM_RC])++;\r
-  }\r
-\r
-  return SZ_OK;\r
-}\r
diff --git a/deps/lzma-16.04/C/Bcj2.h b/deps/lzma-16.04/C/Bcj2.h
deleted file mode 100644 (file)
index 68893d2..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/* Bcj2.h -- BCJ2 Converter for x86 code\r
-2014-11-10 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __BCJ2_H\r
-#define __BCJ2_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define BCJ2_NUM_STREAMS 4\r
-\r
-enum\r
-{\r
-  BCJ2_STREAM_MAIN,\r
-  BCJ2_STREAM_CALL,\r
-  BCJ2_STREAM_JUMP,\r
-  BCJ2_STREAM_RC\r
-};\r
-\r
-enum\r
-{\r
-  BCJ2_DEC_STATE_ORIG_0 = BCJ2_NUM_STREAMS,\r
-  BCJ2_DEC_STATE_ORIG_1,\r
-  BCJ2_DEC_STATE_ORIG_2,\r
-  BCJ2_DEC_STATE_ORIG_3,\r
-  \r
-  BCJ2_DEC_STATE_ORIG,\r
-  BCJ2_DEC_STATE_OK\r
-};\r
-\r
-enum\r
-{\r
-  BCJ2_ENC_STATE_ORIG = BCJ2_NUM_STREAMS,\r
-  BCJ2_ENC_STATE_OK\r
-};\r
-\r
-\r
-#define BCJ2_IS_32BIT_STREAM(s) ((s) == BCJ2_STREAM_CALL || (s) == BCJ2_STREAM_JUMP)\r
-\r
-/*\r
-CBcj2Dec / CBcj2Enc\r
-bufs sizes:\r
-  BUF_SIZE(n) = lims[n] - bufs[n]\r
-bufs sizes for BCJ2_STREAM_CALL and BCJ2_STREAM_JUMP must be mutliply of 4:\r
-    (BUF_SIZE(BCJ2_STREAM_CALL) & 3) == 0\r
-    (BUF_SIZE(BCJ2_STREAM_JUMP) & 3) == 0\r
-*/\r
-\r
-/*\r
-CBcj2Dec:\r
-dest is allowed to overlap with bufs[BCJ2_STREAM_MAIN], with the following conditions:\r
-  bufs[BCJ2_STREAM_MAIN] >= dest &&\r
-  bufs[BCJ2_STREAM_MAIN] - dest >= tempReserv +\r
-        BUF_SIZE(BCJ2_STREAM_CALL) +\r
-        BUF_SIZE(BCJ2_STREAM_JUMP)\r
-     tempReserv = 0 : for first call of Bcj2Dec_Decode\r
-     tempReserv = 4 : for any other calls of Bcj2Dec_Decode\r
-  overlap with offset = 1 is not allowed\r
-*/\r
-\r
-typedef struct\r
-{\r
-  const Byte *bufs[BCJ2_NUM_STREAMS];\r
-  const Byte *lims[BCJ2_NUM_STREAMS];\r
-  Byte *dest;\r
-  const Byte *destLim;\r
-\r
-  unsigned state; /* BCJ2_STREAM_MAIN has more priority than BCJ2_STATE_ORIG */\r
-\r
-  UInt32 ip;\r
-  Byte temp[4];\r
-  UInt32 range;\r
-  UInt32 code;\r
-  UInt16 probs[2 + 256];\r
-} CBcj2Dec;\r
-\r
-void Bcj2Dec_Init(CBcj2Dec *p);\r
-\r
-/* Returns: SZ_OK or SZ_ERROR_DATA */\r
-SRes Bcj2Dec_Decode(CBcj2Dec *p);\r
-\r
-#define Bcj2Dec_IsFinished(_p_) ((_p_)->code == 0)\r
-\r
-\r
-\r
-typedef enum\r
-{\r
-  BCJ2_ENC_FINISH_MODE_CONTINUE,\r
-  BCJ2_ENC_FINISH_MODE_END_BLOCK,\r
-  BCJ2_ENC_FINISH_MODE_END_STREAM\r
-} EBcj2Enc_FinishMode;\r
-\r
-typedef struct\r
-{\r
-  Byte *bufs[BCJ2_NUM_STREAMS];\r
-  const Byte *lims[BCJ2_NUM_STREAMS];\r
-  const Byte *src;\r
-  const Byte *srcLim;\r
-\r
-  unsigned state;\r
-  EBcj2Enc_FinishMode finishMode;\r
-\r
-  Byte prevByte;\r
-\r
-  Byte cache;\r
-  UInt32 range;\r
-  UInt64 low;\r
-  UInt64 cacheSize;\r
-\r
-  UInt32 ip;\r
-\r
-  /* 32-bit ralative offset in JUMP/CALL commands is\r
-       - (mod 4 GB)   in 32-bit mode\r
-       - signed Int32 in 64-bit mode\r
-     We use (mod 4 GB) check for fileSize.\r
-     Use fileSize up to 2 GB, if you want to support 32-bit and 64-bit code conversion. */\r
-  UInt32 fileIp;\r
-  UInt32 fileSize;    /* (fileSize <= ((UInt32)1 << 31)), 0 means no_limit */\r
-  UInt32 relatLimit;  /* (relatLimit <= ((UInt32)1 << 31)), 0 means desable_conversion */\r
-\r
-  UInt32 tempTarget;\r
-  unsigned tempPos;\r
-  Byte temp[4 * 2];\r
-\r
-  unsigned flushPos;\r
-  \r
-  UInt16 probs[2 + 256];\r
-} CBcj2Enc;\r
-\r
-void Bcj2Enc_Init(CBcj2Enc *p);\r
-void Bcj2Enc_Encode(CBcj2Enc *p);\r
-\r
-#define Bcj2Enc_Get_InputData_Size(p) ((SizeT)((p)->srcLim - (p)->src) + (p)->tempPos)\r
-#define Bcj2Enc_IsFinished(p) ((p)->flushPos == 5)\r
-\r
-\r
-#define BCJ2_RELAT_LIMIT_NUM_BITS 26\r
-#define BCJ2_RELAT_LIMIT ((UInt32)1 << BCJ2_RELAT_LIMIT_NUM_BITS)\r
-\r
-/* limit for CBcj2Enc::fileSize variable */\r
-#define BCJ2_FileSize_MAX ((UInt32)1 << 31)\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Bcj2Enc.c b/deps/lzma-16.04/C/Bcj2Enc.c
deleted file mode 100644 (file)
index 6a21015..0000000
+++ /dev/null
@@ -1,312 +0,0 @@
-/* Bcj2Enc.c -- BCJ2 Encoder (Converter for x86 code)\r
-2014-11-10 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-/* #define SHOW_STAT */\r
-\r
-#ifdef SHOW_STAT\r
-#include <stdio.h>\r
-#define PRF(x) x\r
-#else\r
-#define PRF(x)\r
-#endif\r
-\r
-#include <windows.h>\r
-#include <string.h>\r
-\r
-#include "Bcj2.h"\r
-#include "CpuArch.h"\r
-\r
-#define CProb UInt16\r
-\r
-#define kTopValue ((UInt32)1 << 24)\r
-#define kNumModelBits 11\r
-#define kBitModelTotal (1 << kNumModelBits)\r
-#define kNumMoveBits 5\r
-\r
-void Bcj2Enc_Init(CBcj2Enc *p)\r
-{\r
-  unsigned i;\r
-\r
-  p->state = BCJ2_ENC_STATE_OK;\r
-  p->finishMode = BCJ2_ENC_FINISH_MODE_CONTINUE;\r
-\r
-  p->prevByte = 0;\r
-\r
-  p->cache = 0;\r
-  p->range = 0xFFFFFFFF;\r
-  p->low = 0;\r
-  p->cacheSize = 1;\r
-\r
-  p->ip = 0;\r
-\r
-  p->fileIp = 0;\r
-  p->fileSize = 0;\r
-  p->relatLimit = BCJ2_RELAT_LIMIT;\r
-\r
-  p->tempPos = 0;\r
-\r
-  p->flushPos = 0;\r
-\r
-  for (i = 0; i < sizeof(p->probs) / sizeof(p->probs[0]); i++)\r
-    p->probs[i] = kBitModelTotal >> 1;\r
-}\r
-\r
-static Bool MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc *p)\r
-{\r
-  if ((UInt32)p->low < (UInt32)0xFF000000 || (UInt32)(p->low >> 32) != 0)\r
-  {\r
-    Byte *buf = p->bufs[BCJ2_STREAM_RC];\r
-    do\r
-    {\r
-      if (buf == p->lims[BCJ2_STREAM_RC])\r
-      {\r
-        p->state = BCJ2_STREAM_RC;\r
-        p->bufs[BCJ2_STREAM_RC] = buf;\r
-        return True;\r
-      }\r
-      *buf++ = (Byte)(p->cache + (Byte)(p->low >> 32));\r
-      p->cache = 0xFF;\r
-    }\r
-    while (--p->cacheSize);\r
-    p->bufs[BCJ2_STREAM_RC] = buf;\r
-    p->cache = (Byte)((UInt32)p->low >> 24);\r
-  }\r
-  p->cacheSize++;\r
-  p->low = (UInt32)p->low << 8;\r
-  return False;\r
-}\r
-\r
-static void Bcj2Enc_Encode_2(CBcj2Enc *p)\r
-{\r
-  if (BCJ2_IS_32BIT_STREAM(p->state))\r
-  {\r
-    Byte *cur = p->bufs[p->state];\r
-    if (cur == p->lims[p->state])\r
-      return;\r
-    SetBe32(cur, p->tempTarget);\r
-    p->bufs[p->state] = cur + 4;\r
-  }\r
-\r
-  p->state = BCJ2_ENC_STATE_ORIG;\r
-\r
-  for (;;)\r
-  {\r
-    if (p->range < kTopValue)\r
-    {\r
-      if (RangeEnc_ShiftLow(p))\r
-        return;\r
-      p->range <<= 8;\r
-    }\r
-\r
-    {\r
-      {\r
-        const Byte *src = p->src;\r
-        const Byte *srcLim;\r
-        Byte *dest;\r
-        SizeT num = p->srcLim - src;\r
-\r
-        if (p->finishMode == BCJ2_ENC_FINISH_MODE_CONTINUE)\r
-        {\r
-          if (num <= 4)\r
-            return;\r
-          num -= 4;\r
-        }\r
-        else if (num == 0)\r
-          break;\r
-\r
-        dest = p->bufs[BCJ2_STREAM_MAIN];\r
-        if (num > (SizeT)(p->lims[BCJ2_STREAM_MAIN] - dest))\r
-        {\r
-          num = p->lims[BCJ2_STREAM_MAIN] - dest;\r
-          if (num == 0)\r
-          {\r
-            p->state = BCJ2_STREAM_MAIN;\r
-            return;\r
-          }\r
-        }\r
-       \r
-        srcLim = src + num;\r
-\r
-        if (p->prevByte == 0x0F && (src[0] & 0xF0) == 0x80)\r
-          *dest = src[0];\r
-        else for (;;)\r
-        {\r
-          Byte b = *src;\r
-          *dest = b;\r
-          if (b != 0x0F)\r
-          {\r
-            if ((b & 0xFE) == 0xE8)\r
-              break;\r
-            dest++;\r
-            if (++src != srcLim)\r
-              continue;\r
-            break;\r
-          }\r
-          dest++;\r
-          if (++src == srcLim)\r
-            break;\r
-          if ((*src & 0xF0) != 0x80)\r
-            continue;\r
-          *dest = *src;\r
-          break;\r
-        }\r
-        \r
-        num = src - p->src;\r
-        \r
-        if (src == srcLim)\r
-        {\r
-          p->prevByte = src[-1];\r
-          p->bufs[BCJ2_STREAM_MAIN] = dest;\r
-          p->src = src;\r
-          p->ip += (UInt32)num;\r
-          continue;\r
-        }\r
\r
-        {\r
-          Byte context = (Byte)(num == 0 ? p->prevByte : src[-1]);\r
-          Bool needConvert;\r
-\r
-          p->bufs[BCJ2_STREAM_MAIN] = dest + 1;\r
-          p->ip += (UInt32)num + 1;\r
-          src++;\r
-          \r
-          needConvert = False;\r
-\r
-          if ((SizeT)(p->srcLim - src) >= 4)\r
-          {\r
-            UInt32 relatVal = GetUi32(src);\r
-            if ((p->fileSize == 0 || (UInt32)(p->ip + 4 + relatVal - p->fileIp) < p->fileSize)\r
-                && ((relatVal + p->relatLimit) >> 1) < p->relatLimit)\r
-              needConvert = True;\r
-          }\r
-\r
-          {\r
-            UInt32 bound;\r
-            unsigned ttt;\r
-            Byte b = src[-1];\r
-            CProb *prob = p->probs + (unsigned)(b == 0xE8 ? 2 + (unsigned)context : (b == 0xE9 ? 1 : 0));\r
-\r
-            ttt = *prob;\r
-            bound = (p->range >> kNumModelBits) * ttt;\r
-            \r
-            if (!needConvert)\r
-            {\r
-              p->range = bound;\r
-              *prob = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r
-              p->src = src;\r
-              p->prevByte = b;\r
-              continue;\r
-            }\r
-            \r
-            p->low += bound;\r
-            p->range -= bound;\r
-            *prob = (CProb)(ttt - (ttt >> kNumMoveBits));\r
-\r
-            {\r
-              UInt32 relatVal = GetUi32(src);\r
-              UInt32 absVal;\r
-              p->ip += 4;\r
-              absVal = p->ip + relatVal;\r
-              p->prevByte = src[3];\r
-              src += 4;\r
-              p->src = src;\r
-              {\r
-                unsigned cj = (b == 0xE8) ? BCJ2_STREAM_CALL : BCJ2_STREAM_JUMP;\r
-                Byte *cur = p->bufs[cj];\r
-                if (cur == p->lims[cj])\r
-                {\r
-                  p->state = cj;\r
-                  p->tempTarget = absVal;\r
-                  return;\r
-                }\r
-                SetBe32(cur, absVal);\r
-                p->bufs[cj] = cur + 4;\r
-              }\r
-            }\r
-          }\r
-        }\r
-      }\r
-    }\r
-  }\r
-\r
-  if (p->finishMode != BCJ2_ENC_FINISH_MODE_END_STREAM)\r
-    return;\r
-\r
-  for (; p->flushPos < 5; p->flushPos++)\r
-    if (RangeEnc_ShiftLow(p))\r
-      return;\r
-  p->state = BCJ2_ENC_STATE_OK;\r
-}\r
-\r
-\r
-void Bcj2Enc_Encode(CBcj2Enc *p)\r
-{\r
-  PRF(printf("\n"));\r
-  PRF(printf("---- ip = %8d   tempPos = %8d   src = %8d\n", p->ip, p->tempPos, p->srcLim - p->src));\r
-\r
-  if (p->tempPos != 0)\r
-  {\r
-    unsigned extra = 0;\r
-   \r
-    for (;;)\r
-    {\r
-      const Byte *src = p->src;\r
-      const Byte *srcLim = p->srcLim;\r
-      unsigned finishMode = p->finishMode;\r
-      \r
-      p->src = p->temp;\r
-      p->srcLim = p->temp + p->tempPos;\r
-      if (src != srcLim)\r
-        p->finishMode = BCJ2_ENC_FINISH_MODE_CONTINUE;\r
-      \r
-      PRF(printf("     ip = %8d   tempPos = %8d   src = %8d\n", p->ip, p->tempPos, p->srcLim - p->src));\r
-\r
-      Bcj2Enc_Encode_2(p);\r
-      \r
-      {\r
-        unsigned num = (unsigned)(p->src - p->temp);\r
-        unsigned tempPos = p->tempPos - num;\r
-        unsigned i;\r
-        p->tempPos = tempPos;\r
-        for (i = 0; i < tempPos; i++)\r
-          p->temp[i] = p->temp[i + num];\r
-      \r
-        p->src = src;\r
-        p->srcLim = srcLim;\r
-        p->finishMode = finishMode;\r
-        \r
-        if (p->state != BCJ2_ENC_STATE_ORIG || src == srcLim)\r
-          return;\r
-        \r
-        if (extra >= tempPos)\r
-        {\r
-          p->src = src - tempPos;\r
-          p->tempPos = 0;\r
-          break;\r
-        }\r
-        \r
-        p->temp[tempPos] = src[0];\r
-        p->tempPos = tempPos + 1;\r
-        p->src = src + 1;\r
-        extra++;\r
-      }\r
-    }\r
-  }\r
-\r
-  PRF(printf("++++ ip = %8d   tempPos = %8d   src = %8d\n", p->ip, p->tempPos, p->srcLim - p->src));\r
-\r
-  Bcj2Enc_Encode_2(p);\r
-  \r
-  if (p->state == BCJ2_ENC_STATE_ORIG)\r
-  {\r
-    const Byte *src = p->src;\r
-    unsigned rem = (unsigned)(p->srcLim - src);\r
-    unsigned i;\r
-    for (i = 0; i < rem; i++)\r
-      p->temp[i] = src[i];\r
-    p->tempPos = rem;\r
-    p->src = src + rem;\r
-  }\r
-}\r
diff --git a/deps/lzma-16.04/C/Bra.c b/deps/lzma-16.04/C/Bra.c
deleted file mode 100644 (file)
index 976810c..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/* Bra.c -- Converters for RISC code\r
-2010-04-16 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Bra.h"\r
-\r
-SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r
-{\r
-  SizeT i;\r
-  if (size < 4)\r
-    return 0;\r
-  size -= 4;\r
-  ip += 8;\r
-  for (i = 0; i <= size; i += 4)\r
-  {\r
-    if (data[i + 3] == 0xEB)\r
-    {\r
-      UInt32 dest;\r
-      UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);\r
-      src <<= 2;\r
-      if (encoding)\r
-        dest = ip + (UInt32)i + src;\r
-      else\r
-        dest = src - (ip + (UInt32)i);\r
-      dest >>= 2;\r
-      data[i + 2] = (Byte)(dest >> 16);\r
-      data[i + 1] = (Byte)(dest >> 8);\r
-      data[i + 0] = (Byte)dest;\r
-    }\r
-  }\r
-  return i;\r
-}\r
-\r
-SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r
-{\r
-  SizeT i;\r
-  if (size < 4)\r
-    return 0;\r
-  size -= 4;\r
-  ip += 4;\r
-  for (i = 0; i <= size; i += 2)\r
-  {\r
-    if ((data[i + 1] & 0xF8) == 0xF0 &&\r
-        (data[i + 3] & 0xF8) == 0xF8)\r
-    {\r
-      UInt32 dest;\r
-      UInt32 src =\r
-        (((UInt32)data[i + 1] & 0x7) << 19) |\r
-        ((UInt32)data[i + 0] << 11) |\r
-        (((UInt32)data[i + 3] & 0x7) << 8) |\r
-        (data[i + 2]);\r
-      \r
-      src <<= 1;\r
-      if (encoding)\r
-        dest = ip + (UInt32)i + src;\r
-      else\r
-        dest = src - (ip + (UInt32)i);\r
-      dest >>= 1;\r
-      \r
-      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));\r
-      data[i + 0] = (Byte)(dest >> 11);\r
-      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));\r
-      data[i + 2] = (Byte)dest;\r
-      i += 2;\r
-    }\r
-  }\r
-  return i;\r
-}\r
-\r
-SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r
-{\r
-  SizeT i;\r
-  if (size < 4)\r
-    return 0;\r
-  size -= 4;\r
-  for (i = 0; i <= size; i += 4)\r
-  {\r
-    if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)\r
-    {\r
-      UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |\r
-        ((UInt32)data[i + 1] << 16) |\r
-        ((UInt32)data[i + 2] << 8) |\r
-        ((UInt32)data[i + 3] & (~3));\r
-      \r
-      UInt32 dest;\r
-      if (encoding)\r
-        dest = ip + (UInt32)i + src;\r
-      else\r
-        dest = src - (ip + (UInt32)i);\r
-      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));\r
-      data[i + 1] = (Byte)(dest >> 16);\r
-      data[i + 2] = (Byte)(dest >> 8);\r
-      data[i + 3] &= 0x3;\r
-      data[i + 3] |= dest;\r
-    }\r
-  }\r
-  return i;\r
-}\r
-\r
-SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r
-{\r
-  UInt32 i;\r
-  if (size < 4)\r
-    return 0;\r
-  size -= 4;\r
-  for (i = 0; i <= size; i += 4)\r
-  {\r
-    if ((data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00) ||\r
-        (data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0))\r
-    {\r
-      UInt32 src =\r
-        ((UInt32)data[i + 0] << 24) |\r
-        ((UInt32)data[i + 1] << 16) |\r
-        ((UInt32)data[i + 2] << 8) |\r
-        ((UInt32)data[i + 3]);\r
-      UInt32 dest;\r
-      \r
-      src <<= 2;\r
-      if (encoding)\r
-        dest = ip + i + src;\r
-      else\r
-        dest = src - (ip + i);\r
-      dest >>= 2;\r
-      \r
-      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r
-\r
-      data[i + 0] = (Byte)(dest >> 24);\r
-      data[i + 1] = (Byte)(dest >> 16);\r
-      data[i + 2] = (Byte)(dest >> 8);\r
-      data[i + 3] = (Byte)dest;\r
-    }\r
-  }\r
-  return i;\r
-}\r
diff --git a/deps/lzma-16.04/C/BraIA64.c b/deps/lzma-16.04/C/BraIA64.c
deleted file mode 100644 (file)
index 813830c..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/* BraIA64.c -- Converter for IA-64 code\r
-2013-11-12 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Bra.h"\r
-\r
-static const Byte kBranchTable[32] =\r
-{\r
-  0, 0, 0, 0, 0, 0, 0, 0,\r
-  0, 0, 0, 0, 0, 0, 0, 0,\r
-  4, 4, 6, 6, 0, 0, 7, 7,\r
-  4, 4, 0, 0, 4, 4, 0, 0\r
-};\r
-\r
-SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r
-{\r
-  SizeT i;\r
-  if (size < 16)\r
-    return 0;\r
-  size -= 16;\r
-  for (i = 0; i <= size; i += 16)\r
-  {\r
-    UInt32 instrTemplate = data[i] & 0x1F;\r
-    UInt32 mask = kBranchTable[instrTemplate];\r
-    UInt32 bitPos = 5;\r
-    int slot;\r
-    for (slot = 0; slot < 3; slot++, bitPos += 41)\r
-    {\r
-      UInt32 bytePos, bitRes;\r
-      UInt64 instruction, instNorm;\r
-      int j;\r
-      if (((mask >> slot) & 1) == 0)\r
-        continue;\r
-      bytePos = (bitPos >> 3);\r
-      bitRes = bitPos & 0x7;\r
-      instruction = 0;\r
-      for (j = 0; j < 6; j++)\r
-        instruction += (UInt64)data[i + j + bytePos] << (8 * j);\r
-\r
-      instNorm = instruction >> bitRes;\r
-      if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)\r
-      {\r
-        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);\r
-        UInt32 dest;\r
-        src |= ((UInt32)(instNorm >> 36) & 1) << 20;\r
-        \r
-        src <<= 4;\r
-        \r
-        if (encoding)\r
-          dest = ip + (UInt32)i + src;\r
-        else\r
-          dest = src - (ip + (UInt32)i);\r
-        \r
-        dest >>= 4;\r
-        \r
-        instNorm &= ~((UInt64)(0x8FFFFF) << 13);\r
-        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);\r
-        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));\r
-        \r
-        instruction &= (1 << bitRes) - 1;\r
-        instruction |= (instNorm << bitRes);\r
-        for (j = 0; j < 6; j++)\r
-          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));\r
-      }\r
-    }\r
-  }\r
-  return i;\r
-}\r
diff --git a/deps/lzma-16.04/C/DllSecur.c b/deps/lzma-16.04/C/DllSecur.c
deleted file mode 100644 (file)
index 8745421..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/* DllSecur.c -- DLL loading security\r
-2016-10-04 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#ifdef _WIN32\r
-\r
-#include <windows.h>\r
-\r
-#include "DllSecur.h"\r
-\r
-#ifndef UNDER_CE\r
-\r
-typedef BOOL (WINAPI *Func_SetDefaultDllDirectories)(DWORD DirectoryFlags);\r
-\r
-#define MY_LOAD_LIBRARY_SEARCH_USER_DIRS 0x400\r
-#define MY_LOAD_LIBRARY_SEARCH_SYSTEM32  0x800\r
-\r
-static const char * const g_Dlls =\r
-  #ifndef _CONSOLE\r
-  "UXTHEME\0"\r
-  #endif\r
-  "USERENV\0"\r
-  "SETUPAPI\0"\r
-  "APPHELP\0"\r
-  "PROPSYS\0"\r
-  "DWMAPI\0"\r
-  "CRYPTBASE\0"\r
-  "OLEACC\0"\r
-  "CLBCATQ\0"\r
-  ;\r
-\r
-#endif\r
-\r
-void LoadSecurityDlls()\r
-{\r
-  #ifndef UNDER_CE\r
-  \r
-  wchar_t buf[MAX_PATH + 100];\r
-\r
-  {\r
-    // at Vista (ver 6.0) : CoCreateInstance(CLSID_ShellLink, ...) doesn't work after SetDefaultDllDirectories() : Check it ???\r
-    OSVERSIONINFO vi;\r
-    vi.dwOSVersionInfoSize = sizeof(vi);\r
-    if (!GetVersionEx(&vi) || vi.dwMajorVersion != 6 || vi.dwMinorVersion != 0)\r
-    {\r
-      Func_SetDefaultDllDirectories setDllDirs = (Func_SetDefaultDllDirectories)\r
-          GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "SetDefaultDllDirectories");\r
-      if (setDllDirs)\r
-        if (setDllDirs(MY_LOAD_LIBRARY_SEARCH_SYSTEM32 | MY_LOAD_LIBRARY_SEARCH_USER_DIRS))\r
-          return;\r
-    }\r
-  }\r
-\r
-  {\r
-    unsigned len = GetSystemDirectoryW(buf, MAX_PATH + 2);\r
-    if (len == 0 || len > MAX_PATH)\r
-      return;\r
-  }\r
-  {\r
-    const char *dll;\r
-    unsigned pos = (unsigned)lstrlenW(buf);\r
-\r
-    if (buf[pos - 1] != '\\')\r
-      buf[pos++] = '\\';\r
-    \r
-    for (dll = g_Dlls; dll[0] != 0;)\r
-    {\r
-      unsigned k = 0;\r
-      for (;;)\r
-      {\r
-        char c = *dll++;\r
-        buf[pos + k] = c;\r
-        k++;\r
-        if (c == 0)\r
-          break;\r
-      }\r
-\r
-      lstrcatW(buf, L".dll");\r
-      LoadLibraryExW(buf, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);\r
-    }\r
-  }\r
-  \r
-  #endif\r
-}\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/DllSecur.h b/deps/lzma-16.04/C/DllSecur.h
deleted file mode 100644 (file)
index 023c509..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/* DllSecur.h -- DLL loading for security\r
-2016-06-08 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __DLL_SECUR_H\r
-#define __DLL_SECUR_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#ifdef _WIN32\r
-\r
-void LoadSecurityDlls();\r
-\r
-#endif\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/LzFindMt.c b/deps/lzma-16.04/C/LzFindMt.c
deleted file mode 100644 (file)
index cb61e09..0000000
+++ /dev/null
@@ -1,803 +0,0 @@
-/* LzFindMt.c -- multithreaded Match finder for LZ algorithms\r
-2015-10-15 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "LzHash.h"\r
-\r
-#include "LzFindMt.h"\r
-\r
-static void MtSync_Construct(CMtSync *p)\r
-{\r
-  p->wasCreated = False;\r
-  p->csWasInitialized = False;\r
-  p->csWasEntered = False;\r
-  Thread_Construct(&p->thread);\r
-  Event_Construct(&p->canStart);\r
-  Event_Construct(&p->wasStarted);\r
-  Event_Construct(&p->wasStopped);\r
-  Semaphore_Construct(&p->freeSemaphore);\r
-  Semaphore_Construct(&p->filledSemaphore);\r
-}\r
-\r
-static void MtSync_GetNextBlock(CMtSync *p)\r
-{\r
-  if (p->needStart)\r
-  {\r
-    p->numProcessedBlocks = 1;\r
-    p->needStart = False;\r
-    p->stopWriting = False;\r
-    p->exit = False;\r
-    Event_Reset(&p->wasStarted);\r
-    Event_Reset(&p->wasStopped);\r
-\r
-    Event_Set(&p->canStart);\r
-    Event_Wait(&p->wasStarted);\r
-  }\r
-  else\r
-  {\r
-    CriticalSection_Leave(&p->cs);\r
-    p->csWasEntered = False;\r
-    p->numProcessedBlocks++;\r
-    Semaphore_Release1(&p->freeSemaphore);\r
-  }\r
-  Semaphore_Wait(&p->filledSemaphore);\r
-  CriticalSection_Enter(&p->cs);\r
-  p->csWasEntered = True;\r
-}\r
-\r
-/* MtSync_StopWriting must be called if Writing was started */\r
-\r
-static void MtSync_StopWriting(CMtSync *p)\r
-{\r
-  UInt32 myNumBlocks = p->numProcessedBlocks;\r
-  if (!Thread_WasCreated(&p->thread) || p->needStart)\r
-    return;\r
-  p->stopWriting = True;\r
-  if (p->csWasEntered)\r
-  {\r
-    CriticalSection_Leave(&p->cs);\r
-    p->csWasEntered = False;\r
-  }\r
-  Semaphore_Release1(&p->freeSemaphore);\r
\r
-  Event_Wait(&p->wasStopped);\r
-\r
-  while (myNumBlocks++ != p->numProcessedBlocks)\r
-  {\r
-    Semaphore_Wait(&p->filledSemaphore);\r
-    Semaphore_Release1(&p->freeSemaphore);\r
-  }\r
-  p->needStart = True;\r
-}\r
-\r
-static void MtSync_Destruct(CMtSync *p)\r
-{\r
-  if (Thread_WasCreated(&p->thread))\r
-  {\r
-    MtSync_StopWriting(p);\r
-    p->exit = True;\r
-    if (p->needStart)\r
-      Event_Set(&p->canStart);\r
-    Thread_Wait(&p->thread);\r
-    Thread_Close(&p->thread);\r
-  }\r
-  if (p->csWasInitialized)\r
-  {\r
-    CriticalSection_Delete(&p->cs);\r
-    p->csWasInitialized = False;\r
-  }\r
-\r
-  Event_Close(&p->canStart);\r
-  Event_Close(&p->wasStarted);\r
-  Event_Close(&p->wasStopped);\r
-  Semaphore_Close(&p->freeSemaphore);\r
-  Semaphore_Close(&p->filledSemaphore);\r
-\r
-  p->wasCreated = False;\r
-}\r
-\r
-#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }\r
-\r
-static SRes MtSync_Create2(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks)\r
-{\r
-  if (p->wasCreated)\r
-    return SZ_OK;\r
-\r
-  RINOK_THREAD(CriticalSection_Init(&p->cs));\r
-  p->csWasInitialized = True;\r
-\r
-  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));\r
-  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));\r
-  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));\r
-  \r
-  RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));\r
-  RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));\r
-\r
-  p->needStart = True;\r
-  \r
-  RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));\r
-  p->wasCreated = True;\r
-  return SZ_OK;\r
-}\r
-\r
-static SRes MtSync_Create(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks)\r
-{\r
-  SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\r
-  if (res != SZ_OK)\r
-    MtSync_Destruct(p);\r
-  return res;\r
-}\r
-\r
-void MtSync_Init(CMtSync *p) { p->needStart = True; }\r
-\r
-#define kMtMaxValForNormalize 0xFFFFFFFF\r
-\r
-#define DEF_GetHeads2(name, v, action) \\r
-  static void GetHeads ## name(const Byte *p, UInt32 pos, \\r
-      UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \\r
-    { action; for (; numHeads != 0; numHeads--) { \\r
-      const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r
-\r
-#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)\r
-\r
-DEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), UNUSED_VAR(hashMask); UNUSED_VAR(crc); )\r
-DEF_GetHeads(3,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\r
-DEF_GetHeads(4,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)\r
-DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\r
-/* DEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask) */\r
-\r
-static void HashThreadFunc(CMatchFinderMt *mt)\r
-{\r
-  CMtSync *p = &mt->hashSync;\r
-  for (;;)\r
-  {\r
-    UInt32 numProcessedBlocks = 0;\r
-    Event_Wait(&p->canStart);\r
-    Event_Set(&p->wasStarted);\r
-    for (;;)\r
-    {\r
-      if (p->exit)\r
-        return;\r
-      if (p->stopWriting)\r
-      {\r
-        p->numProcessedBlocks = numProcessedBlocks;\r
-        Event_Set(&p->wasStopped);\r
-        break;\r
-      }\r
-\r
-      {\r
-        CMatchFinder *mf = mt->MatchFinder;\r
-        if (MatchFinder_NeedMove(mf))\r
-        {\r
-          CriticalSection_Enter(&mt->btSync.cs);\r
-          CriticalSection_Enter(&mt->hashSync.cs);\r
-          {\r
-            const Byte *beforePtr = Inline_MatchFinder_GetPointerToCurrentPos(mf);\r
-            ptrdiff_t offset;\r
-            MatchFinder_MoveBlock(mf);\r
-            offset = beforePtr - Inline_MatchFinder_GetPointerToCurrentPos(mf);\r
-            mt->pointerToCurPos -= offset;\r
-            mt->buffer -= offset;\r
-          }\r
-          CriticalSection_Leave(&mt->btSync.cs);\r
-          CriticalSection_Leave(&mt->hashSync.cs);\r
-          continue;\r
-        }\r
-\r
-        Semaphore_Wait(&p->freeSemaphore);\r
-\r
-        MatchFinder_ReadIfRequired(mf);\r
-        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))\r
-        {\r
-          UInt32 subValue = (mf->pos - mf->historySize - 1);\r
-          MatchFinder_ReduceOffsets(mf, subValue);\r
-          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, (size_t)mf->hashMask + 1);\r
-        }\r
-        {\r
-          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r
-          UInt32 num = mf->streamPos - mf->pos;\r
-          heads[0] = 2;\r
-          heads[1] = num;\r
-          if (num >= mf->numHashBytes)\r
-          {\r
-            num = num - mf->numHashBytes + 1;\r
-            if (num > kMtHashBlockSize - 2)\r
-              num = kMtHashBlockSize - 2;\r
-            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);\r
-            heads[0] += num;\r
-          }\r
-          mf->pos += num;\r
-          mf->buffer += num;\r
-        }\r
-      }\r
-\r
-      Semaphore_Release1(&p->filledSemaphore);\r
-    }\r
-  }\r
-}\r
-\r
-static void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r
-{\r
-  MtSync_GetNextBlock(&p->hashSync);\r
-  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r
-  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];\r
-  p->hashNumAvail = p->hashBuf[p->hashBufPos++];\r
-}\r
-\r
-#define kEmptyHashValue 0\r
-\r
-/* #define MFMT_GM_INLINE */\r
-\r
-#ifdef MFMT_GM_INLINE\r
-\r
-#define NO_INLINE MY_FAST_CALL\r
-\r
-static Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,\r
-    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r
-    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\r
-{\r
-  do\r
-  {\r
-  UInt32 *distances = _distances + 1;\r
-  UInt32 curMatch = pos - *hash++;\r
-\r
-  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r
-  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r
-  UInt32 len0 = 0, len1 = 0;\r
-  UInt32 cutValue = _cutValue;\r
-  UInt32 maxLen = _maxLen;\r
-  for (;;)\r
-  {\r
-    UInt32 delta = pos - curMatch;\r
-    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r
-    {\r
-      *ptr0 = *ptr1 = kEmptyHashValue;\r
-      break;\r
-    }\r
-    {\r
-      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r
-      const Byte *pb = cur - delta;\r
-      UInt32 len = (len0 < len1 ? len0 : len1);\r
-      if (pb[len] == cur[len])\r
-      {\r
-        if (++len != lenLimit && pb[len] == cur[len])\r
-          while (++len != lenLimit)\r
-            if (pb[len] != cur[len])\r
-              break;\r
-        if (maxLen < len)\r
-        {\r
-          *distances++ = maxLen = len;\r
-          *distances++ = delta - 1;\r
-          if (len == lenLimit)\r
-          {\r
-            *ptr1 = pair[0];\r
-            *ptr0 = pair[1];\r
-            break;\r
-          }\r
-        }\r
-      }\r
-      if (pb[len] < cur[len])\r
-      {\r
-        *ptr1 = curMatch;\r
-        ptr1 = pair + 1;\r
-        curMatch = *ptr1;\r
-        len1 = len;\r
-      }\r
-      else\r
-      {\r
-        *ptr0 = curMatch;\r
-        ptr0 = pair;\r
-        curMatch = *ptr0;\r
-        len0 = len;\r
-      }\r
-    }\r
-  }\r
-  pos++;\r
-  _cyclicBufferPos++;\r
-  cur++;\r
-  {\r
-    UInt32 num = (UInt32)(distances - _distances);\r
-    *_distances = num - 1;\r
-    _distances += num;\r
-    limit -= num;\r
-  }\r
-  }\r
-  while (limit > 0 && --size != 0);\r
-  *posRes = pos;\r
-  return limit;\r
-}\r
-\r
-#endif\r
-\r
-static void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r
-{\r
-  UInt32 numProcessed = 0;\r
-  UInt32 curPos = 2;\r
-  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\r
-  \r
-  distances[1] = p->hashNumAvail;\r
-  \r
-  while (curPos < limit)\r
-  {\r
-    if (p->hashBufPos == p->hashBufPosLimit)\r
-    {\r
-      MatchFinderMt_GetNextBlock_Hash(p);\r
-      distances[1] = numProcessed + p->hashNumAvail;\r
-      if (p->hashNumAvail >= p->numHashBytes)\r
-        continue;\r
-      distances[0] = curPos + p->hashNumAvail;\r
-      distances += curPos;\r
-      for (; p->hashNumAvail != 0; p->hashNumAvail--)\r
-        *distances++ = 0;\r
-      return;\r
-    }\r
-    {\r
-      UInt32 size = p->hashBufPosLimit - p->hashBufPos;\r
-      UInt32 lenLimit = p->matchMaxLen;\r
-      UInt32 pos = p->pos;\r
-      UInt32 cyclicBufferPos = p->cyclicBufferPos;\r
-      if (lenLimit >= p->hashNumAvail)\r
-        lenLimit = p->hashNumAvail;\r
-      {\r
-        UInt32 size2 = p->hashNumAvail - lenLimit + 1;\r
-        if (size2 < size)\r
-          size = size2;\r
-        size2 = p->cyclicBufferSize - cyclicBufferPos;\r
-        if (size2 < size)\r
-          size = size2;\r
-      }\r
-      \r
-      #ifndef MFMT_GM_INLINE\r
-      while (curPos < limit && size-- != 0)\r
-      {\r
-        UInt32 *startDistances = distances + curPos;\r
-        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],\r
-            pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r
-            startDistances + 1, p->numHashBytes - 1) - startDistances);\r
-        *startDistances = num - 1;\r
-        curPos += num;\r
-        cyclicBufferPos++;\r
-        pos++;\r
-        p->buffer++;\r
-      }\r
-      #else\r
-      {\r
-        UInt32 posRes;\r
-        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r
-            distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos), size, &posRes);\r
-        p->hashBufPos += posRes - pos;\r
-        cyclicBufferPos += posRes - pos;\r
-        p->buffer += posRes - pos;\r
-        pos = posRes;\r
-      }\r
-      #endif\r
-\r
-      numProcessed += pos - p->pos;\r
-      p->hashNumAvail -= pos - p->pos;\r
-      p->pos = pos;\r
-      if (cyclicBufferPos == p->cyclicBufferSize)\r
-        cyclicBufferPos = 0;\r
-      p->cyclicBufferPos = cyclicBufferPos;\r
-    }\r
-  }\r
-  \r
-  distances[0] = curPos;\r
-}\r
-\r
-static void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r
-{\r
-  CMtSync *sync = &p->hashSync;\r
-  if (!sync->needStart)\r
-  {\r
-    CriticalSection_Enter(&sync->cs);\r
-    sync->csWasEntered = True;\r
-  }\r
-  \r
-  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);\r
-\r
-  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\r
-  {\r
-    UInt32 subValue = p->pos - p->cyclicBufferSize;\r
-    MatchFinder_Normalize3(subValue, p->son, (size_t)p->cyclicBufferSize * 2);\r
-    p->pos -= subValue;\r
-  }\r
-\r
-  if (!sync->needStart)\r
-  {\r
-    CriticalSection_Leave(&sync->cs);\r
-    sync->csWasEntered = False;\r
-  }\r
-}\r
-\r
-void BtThreadFunc(CMatchFinderMt *mt)\r
-{\r
-  CMtSync *p = &mt->btSync;\r
-  for (;;)\r
-  {\r
-    UInt32 blockIndex = 0;\r
-    Event_Wait(&p->canStart);\r
-    Event_Set(&p->wasStarted);\r
-    for (;;)\r
-    {\r
-      if (p->exit)\r
-        return;\r
-      if (p->stopWriting)\r
-      {\r
-        p->numProcessedBlocks = blockIndex;\r
-        MtSync_StopWriting(&mt->hashSync);\r
-        Event_Set(&p->wasStopped);\r
-        break;\r
-      }\r
-      Semaphore_Wait(&p->freeSemaphore);\r
-      BtFillBlock(mt, blockIndex++);\r
-      Semaphore_Release1(&p->filledSemaphore);\r
-    }\r
-  }\r
-}\r
-\r
-void MatchFinderMt_Construct(CMatchFinderMt *p)\r
-{\r
-  p->hashBuf = NULL;\r
-  MtSync_Construct(&p->hashSync);\r
-  MtSync_Construct(&p->btSync);\r
-}\r
-\r
-static void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->hashBuf);\r
-  p->hashBuf = NULL;\r
-}\r
-\r
-void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r
-{\r
-  MtSync_Destruct(&p->hashSync);\r
-  MtSync_Destruct(&p->btSync);\r
-  MatchFinderMt_FreeMem(p, alloc);\r
-}\r
-\r
-#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\r
-#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\r
-\r
-static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r
-static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE BtThreadFunc2(void *p)\r
-{\r
-  Byte allocaDummy[0x180];\r
-  unsigned i = 0;\r
-  for (i = 0; i < 16; i++)\r
-    allocaDummy[i] = (Byte)0;\r
-  if (allocaDummy[0] == 0)\r
-    BtThreadFunc((CMatchFinderMt *)p);\r
-  return 0;\r
-}\r
-\r
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r
-    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\r
-{\r
-  CMatchFinder *mf = p->MatchFinder;\r
-  p->historySize = historySize;\r
-  if (kMtBtBlockSize <= matchMaxLen * 4)\r
-    return SZ_ERROR_PARAM;\r
-  if (!p->hashBuf)\r
-  {\r
-    p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r
-    if (!p->hashBuf)\r
-      return SZ_ERROR_MEM;\r
-    p->btBuf = p->hashBuf + kHashBufferSize;\r
-  }\r
-  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);\r
-  keepAddBufferAfter += kMtHashBlockSize;\r
-  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))\r
-    return SZ_ERROR_MEM;\r
-\r
-  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));\r
-  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));\r
-  return SZ_OK;\r
-}\r
-\r
-/* Call it after ReleaseStream / SetStream */\r
-void MatchFinderMt_Init(CMatchFinderMt *p)\r
-{\r
-  CMatchFinder *mf = p->MatchFinder;\r
-  p->btBufPos = p->btBufPosLimit = 0;\r
-  p->hashBufPos = p->hashBufPosLimit = 0;\r
-\r
-  /* Init without data reading. We don't want to read data in this thread */\r
-  MatchFinder_Init_2(mf, False);\r
-  \r
-  p->pointerToCurPos = Inline_MatchFinder_GetPointerToCurrentPos(mf);\r
-  p->btNumAvailBytes = 0;\r
-  p->lzPos = p->historySize + 1;\r
-\r
-  p->hash = mf->hash;\r
-  p->fixedHashSize = mf->fixedHashSize;\r
-  p->crc = mf->crc;\r
-\r
-  p->son = mf->son;\r
-  p->matchMaxLen = mf->matchMaxLen;\r
-  p->numHashBytes = mf->numHashBytes;\r
-  p->pos = mf->pos;\r
-  p->buffer = mf->buffer;\r
-  p->cyclicBufferPos = mf->cyclicBufferPos;\r
-  p->cyclicBufferSize = mf->cyclicBufferSize;\r
-  p->cutValue = mf->cutValue;\r
-}\r
-\r
-/* ReleaseStream is required to finish multithreading */\r
-void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)\r
-{\r
-  MtSync_StopWriting(&p->btSync);\r
-  /* p->MatchFinder->ReleaseStream(); */\r
-}\r
-\r
-static void MatchFinderMt_Normalize(CMatchFinderMt *p)\r
-{\r
-  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\r
-  p->lzPos = p->historySize + 1;\r
-}\r
-\r
-static void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r
-{\r
-  UInt32 blockIndex;\r
-  MtSync_GetNextBlock(&p->btSync);\r
-  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);\r
-  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;\r
-  p->btBufPosLimit += p->btBuf[p->btBufPos++];\r
-  p->btNumAvailBytes = p->btBuf[p->btBufPos++];\r
-  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)\r
-    MatchFinderMt_Normalize(p);\r
-}\r
-\r
-static const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r
-{\r
-  return p->pointerToCurPos;\r
-}\r
-\r
-#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\r
-\r
-static UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r
-{\r
-  GET_NEXT_BLOCK_IF_REQUIRED;\r
-  return p->btNumAvailBytes;\r
-}\r
-\r
-static UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r
-{\r
-  UInt32 h2, curMatch2;\r
-  UInt32 *hash = p->hash;\r
-  const Byte *cur = p->pointerToCurPos;\r
-  UInt32 lzPos = p->lzPos;\r
-  MT_HASH2_CALC\r
-      \r
-  curMatch2 = hash[h2];\r
-  hash[h2] = lzPos;\r
-\r
-  if (curMatch2 >= matchMinPos)\r
-    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r
-    {\r
-      *distances++ = 2;\r
-      *distances++ = lzPos - curMatch2 - 1;\r
-    }\r
-  \r
-  return distances;\r
-}\r
-\r
-static UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r
-{\r
-  UInt32 h2, h3, curMatch2, curMatch3;\r
-  UInt32 *hash = p->hash;\r
-  const Byte *cur = p->pointerToCurPos;\r
-  UInt32 lzPos = p->lzPos;\r
-  MT_HASH3_CALC\r
-\r
-  curMatch2 = hash[                h2];\r
-  curMatch3 = hash[kFix3HashSize + h3];\r
-  \r
-  hash[                h2] = lzPos;\r
-  hash[kFix3HashSize + h3] = lzPos;\r
-\r
-  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r
-  {\r
-    distances[1] = lzPos - curMatch2 - 1;\r
-    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r
-    {\r
-      distances[0] = 3;\r
-      return distances + 2;\r
-    }\r
-    distances[0] = 2;\r
-    distances += 2;\r
-  }\r
-  \r
-  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r
-  {\r
-    *distances++ = 3;\r
-    *distances++ = lzPos - curMatch3 - 1;\r
-  }\r
-  \r
-  return distances;\r
-}\r
-\r
-/*\r
-static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r
-{\r
-  UInt32 h2, h3, h4, curMatch2, curMatch3, curMatch4;\r
-  UInt32 *hash = p->hash;\r
-  const Byte *cur = p->pointerToCurPos;\r
-  UInt32 lzPos = p->lzPos;\r
-  MT_HASH4_CALC\r
-      \r
-  curMatch2 = hash[                h2];\r
-  curMatch3 = hash[kFix3HashSize + h3];\r
-  curMatch4 = hash[kFix4HashSize + h4];\r
-  \r
-  hash[                h2] = lzPos;\r
-  hash[kFix3HashSize + h3] = lzPos;\r
-  hash[kFix4HashSize + h4] = lzPos;\r
-\r
-  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r
-  {\r
-    distances[1] = lzPos - curMatch2 - 1;\r
-    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r
-    {\r
-      distances[0] = (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r
-      return distances + 2;\r
-    }\r
-    distances[0] = 2;\r
-    distances += 2;\r
-  }\r
-  \r
-  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r
-  {\r
-    distances[1] = lzPos - curMatch3 - 1;\r
-    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])\r
-    {\r
-      distances[0] = 4;\r
-      return distances + 2;\r
-    }\r
-    distances[0] = 3;\r
-    distances += 2;\r
-  }\r
-\r
-  if (curMatch4 >= matchMinPos)\r
-    if (\r
-      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&\r
-      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]\r
-      )\r
-    {\r
-      *distances++ = 4;\r
-      *distances++ = lzPos - curMatch4 - 1;\r
-    }\r
-  \r
-  return distances;\r
-}\r
-*/\r
-\r
-#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\r
-\r
-static UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r
-{\r
-  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r
-  UInt32 len = *btBuf++;\r
-  p->btBufPos += 1 + len;\r
-  p->btNumAvailBytes--;\r
-  {\r
-    UInt32 i;\r
-    for (i = 0; i < len; i += 2)\r
-    {\r
-      *distances++ = *btBuf++;\r
-      *distances++ = *btBuf++;\r
-    }\r
-  }\r
-  INCREASE_LZ_POS\r
-  return len;\r
-}\r
-\r
-static UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r
-{\r
-  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r
-  UInt32 len = *btBuf++;\r
-  p->btBufPos += 1 + len;\r
-\r
-  if (len == 0)\r
-  {\r
-    /* change for bt5 ! */\r
-    if (p->btNumAvailBytes-- >= 4)\r
-      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\r
-  }\r
-  else\r
-  {\r
-    /* Condition: there are matches in btBuf with length < p->numHashBytes */\r
-    UInt32 *distances2;\r
-    p->btNumAvailBytes--;\r
-    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\r
-    do\r
-    {\r
-      *distances2++ = *btBuf++;\r
-      *distances2++ = *btBuf++;\r
-    }\r
-    while ((len -= 2) != 0);\r
-    len = (UInt32)(distances2 - (distances));\r
-  }\r
-  INCREASE_LZ_POS\r
-  return len;\r
-}\r
-\r
-#define SKIP_HEADER2_MT  do { GET_NEXT_BLOCK_IF_REQUIRED\r
-#define SKIP_HEADER_MT(n) SKIP_HEADER2_MT if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r
-#define SKIP_FOOTER_MT } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);\r
-\r
-static void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r
-{\r
-  SKIP_HEADER2_MT { p->btNumAvailBytes--;\r
-  SKIP_FOOTER_MT\r
-}\r
-\r
-static void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r
-{\r
-  SKIP_HEADER_MT(2)\r
-      UInt32 h2;\r
-      MT_HASH2_CALC\r
-      hash[h2] = p->lzPos;\r
-  SKIP_FOOTER_MT\r
-}\r
-\r
-static void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r
-{\r
-  SKIP_HEADER_MT(3)\r
-      UInt32 h2, h3;\r
-      MT_HASH3_CALC\r
-      hash[kFix3HashSize + h3] =\r
-      hash[                h2] =\r
-        p->lzPos;\r
-  SKIP_FOOTER_MT\r
-}\r
-\r
-/*\r
-static void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r
-{\r
-  SKIP_HEADER_MT(4)\r
-      UInt32 h2, h3, h4;\r
-      MT_HASH4_CALC\r
-      hash[kFix4HashSize + h4] =\r
-      hash[kFix3HashSize + h3] =\r
-      hash[                h2] =\r
-        p->lzPos;\r
-  SKIP_FOOTER_MT\r
-}\r
-*/\r
-\r
-void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\r
-{\r
-  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\r
-  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\r
-  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\r
-  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\r
-  \r
-  switch (p->MatchFinder->numHashBytes)\r
-  {\r
-    case 2:\r
-      p->GetHeadsFunc = GetHeads2;\r
-      p->MixMatchesFunc = (Mf_Mix_Matches)0;\r
-      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\r
-      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\r
-      break;\r
-    case 3:\r
-      p->GetHeadsFunc = GetHeads3;\r
-      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;\r
-      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;\r
-      break;\r
-    default:\r
-    /* case 4: */\r
-      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\r
-      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\r
-      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\r
-      break;\r
-    /*\r
-    default:\r
-      p->GetHeadsFunc = GetHeads5;\r
-      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;\r
-      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;\r
-      break;\r
-    */\r
-  }\r
-}\r
diff --git a/deps/lzma-16.04/C/LzFindMt.h b/deps/lzma-16.04/C/LzFindMt.h
deleted file mode 100644 (file)
index 46b6924..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/* LzFindMt.h -- multithreaded Match finder for LZ algorithms\r
-2015-05-03 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __LZ_FIND_MT_H\r
-#define __LZ_FIND_MT_H\r
-\r
-#include "LzFind.h"\r
-#include "Threads.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define kMtHashBlockSize (1 << 13)\r
-#define kMtHashNumBlocks (1 << 3)\r
-#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)\r
-\r
-#define kMtBtBlockSize (1 << 14)\r
-#define kMtBtNumBlocks (1 << 6)\r
-#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)\r
-\r
-typedef struct _CMtSync\r
-{\r
-  Bool wasCreated;\r
-  Bool needStart;\r
-  Bool exit;\r
-  Bool stopWriting;\r
-\r
-  CThread thread;\r
-  CAutoResetEvent canStart;\r
-  CAutoResetEvent wasStarted;\r
-  CAutoResetEvent wasStopped;\r
-  CSemaphore freeSemaphore;\r
-  CSemaphore filledSemaphore;\r
-  Bool csWasInitialized;\r
-  Bool csWasEntered;\r
-  CCriticalSection cs;\r
-  UInt32 numProcessedBlocks;\r
-} CMtSync;\r
-\r
-typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);\r
-\r
-/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */\r
-#define kMtCacheLineDummy 128\r
-\r
-typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,\r
-  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);\r
-\r
-typedef struct _CMatchFinderMt\r
-{\r
-  /* LZ */\r
-  const Byte *pointerToCurPos;\r
-  UInt32 *btBuf;\r
-  UInt32 btBufPos;\r
-  UInt32 btBufPosLimit;\r
-  UInt32 lzPos;\r
-  UInt32 btNumAvailBytes;\r
-\r
-  UInt32 *hash;\r
-  UInt32 fixedHashSize;\r
-  UInt32 historySize;\r
-  const UInt32 *crc;\r
-\r
-  Mf_Mix_Matches MixMatchesFunc;\r
-  \r
-  /* LZ + BT */\r
-  CMtSync btSync;\r
-  Byte btDummy[kMtCacheLineDummy];\r
-\r
-  /* BT */\r
-  UInt32 *hashBuf;\r
-  UInt32 hashBufPos;\r
-  UInt32 hashBufPosLimit;\r
-  UInt32 hashNumAvail;\r
-\r
-  CLzRef *son;\r
-  UInt32 matchMaxLen;\r
-  UInt32 numHashBytes;\r
-  UInt32 pos;\r
-  const Byte *buffer;\r
-  UInt32 cyclicBufferPos;\r
-  UInt32 cyclicBufferSize; /* it must be historySize + 1 */\r
-  UInt32 cutValue;\r
-\r
-  /* BT + Hash */\r
-  CMtSync hashSync;\r
-  /* Byte hashDummy[kMtCacheLineDummy]; */\r
-  \r
-  /* Hash */\r
-  Mf_GetHeads GetHeadsFunc;\r
-  CMatchFinder *MatchFinder;\r
-} CMatchFinderMt;\r
-\r
-void MatchFinderMt_Construct(CMatchFinderMt *p);\r
-void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);\r
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r
-    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);\r
-void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\r
-void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Lzma2Dec.c b/deps/lzma-16.04/C/Lzma2Dec.c
deleted file mode 100644 (file)
index b688457..0000000
+++ /dev/null
@@ -1,378 +0,0 @@
-/* Lzma2Dec.c -- LZMA2 Decoder\r
-2015-11-09 : Igor Pavlov : Public domain */\r
-\r
-/* #define SHOW_DEBUG_INFO */\r
-\r
-#include "Precomp.h"\r
-\r
-#ifdef SHOW_DEBUG_INFO\r
-#include <stdio.h>\r
-#endif\r
-\r
-#include <string.h>\r
-\r
-#include "Lzma2Dec.h"\r
-\r
-/*\r
-00000000  -  EOS\r
-00000001 U U  -  Uncompressed Reset Dic\r
-00000010 U U  -  Uncompressed No Reset\r
-100uuuuu U U P P  -  LZMA no reset\r
-101uuuuu U U P P  -  LZMA reset state\r
-110uuuuu U U P P S  -  LZMA reset state + new prop\r
-111uuuuu U U P P S  -  LZMA reset state + new prop + reset dic\r
-\r
-  u, U - Unpack Size\r
-  P - Pack Size\r
-  S - Props\r
-*/\r
-\r
-#define LZMA2_CONTROL_LZMA (1 << 7)\r
-#define LZMA2_CONTROL_COPY_NO_RESET 2\r
-#define LZMA2_CONTROL_COPY_RESET_DIC 1\r
-#define LZMA2_CONTROL_EOF 0\r
-\r
-#define LZMA2_IS_UNCOMPRESSED_STATE(p) (((p)->control & LZMA2_CONTROL_LZMA) == 0)\r
-\r
-#define LZMA2_GET_LZMA_MODE(p) (((p)->control >> 5) & 3)\r
-#define LZMA2_IS_THERE_PROP(mode) ((mode) >= 2)\r
-\r
-#define LZMA2_LCLP_MAX 4\r
-#define LZMA2_DIC_SIZE_FROM_PROP(p) (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11))\r
-\r
-#ifdef SHOW_DEBUG_INFO\r
-#define PRF(x) x\r
-#else\r
-#define PRF(x)\r
-#endif\r
-\r
-typedef enum\r
-{\r
-  LZMA2_STATE_CONTROL,\r
-  LZMA2_STATE_UNPACK0,\r
-  LZMA2_STATE_UNPACK1,\r
-  LZMA2_STATE_PACK0,\r
-  LZMA2_STATE_PACK1,\r
-  LZMA2_STATE_PROP,\r
-  LZMA2_STATE_DATA,\r
-  LZMA2_STATE_DATA_CONT,\r
-  LZMA2_STATE_FINISHED,\r
-  LZMA2_STATE_ERROR\r
-} ELzma2State;\r
-\r
-static SRes Lzma2Dec_GetOldProps(Byte prop, Byte *props)\r
-{\r
-  UInt32 dicSize;\r
-  if (prop > 40)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  dicSize = (prop == 40) ? 0xFFFFFFFF : LZMA2_DIC_SIZE_FROM_PROP(prop);\r
-  props[0] = (Byte)LZMA2_LCLP_MAX;\r
-  props[1] = (Byte)(dicSize);\r
-  props[2] = (Byte)(dicSize >> 8);\r
-  props[3] = (Byte)(dicSize >> 16);\r
-  props[4] = (Byte)(dicSize >> 24);\r
-  return SZ_OK;\r
-}\r
-\r
-SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)\r
-{\r
-  Byte props[LZMA_PROPS_SIZE];\r
-  RINOK(Lzma2Dec_GetOldProps(prop, props));\r
-  return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc);\r
-}\r
-\r
-SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)\r
-{\r
-  Byte props[LZMA_PROPS_SIZE];\r
-  RINOK(Lzma2Dec_GetOldProps(prop, props));\r
-  return LzmaDec_Allocate(&p->decoder, props, LZMA_PROPS_SIZE, alloc);\r
-}\r
-\r
-void Lzma2Dec_Init(CLzma2Dec *p)\r
-{\r
-  p->state = LZMA2_STATE_CONTROL;\r
-  p->needInitDic = True;\r
-  p->needInitState = True;\r
-  p->needInitProp = True;\r
-  LzmaDec_Init(&p->decoder);\r
-}\r
-\r
-static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)\r
-{\r
-  switch (p->state)\r
-  {\r
-    case LZMA2_STATE_CONTROL:\r
-      p->control = b;\r
-      PRF(printf("\n %4X ", (unsigned)p->decoder.dicPos));\r
-      PRF(printf(" %2X", (unsigned)b));\r
-      if (p->control == 0)\r
-        return LZMA2_STATE_FINISHED;\r
-      if (LZMA2_IS_UNCOMPRESSED_STATE(p))\r
-      {\r
-        if ((p->control & 0x7F) > 2)\r
-          return LZMA2_STATE_ERROR;\r
-        p->unpackSize = 0;\r
-      }\r
-      else\r
-        p->unpackSize = (UInt32)(p->control & 0x1F) << 16;\r
-      return LZMA2_STATE_UNPACK0;\r
-    \r
-    case LZMA2_STATE_UNPACK0:\r
-      p->unpackSize |= (UInt32)b << 8;\r
-      return LZMA2_STATE_UNPACK1;\r
-    \r
-    case LZMA2_STATE_UNPACK1:\r
-      p->unpackSize |= (UInt32)b;\r
-      p->unpackSize++;\r
-      PRF(printf(" %8u", (unsigned)p->unpackSize));\r
-      return (LZMA2_IS_UNCOMPRESSED_STATE(p)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;\r
-    \r
-    case LZMA2_STATE_PACK0:\r
-      p->packSize = (UInt32)b << 8;\r
-      return LZMA2_STATE_PACK1;\r
-\r
-    case LZMA2_STATE_PACK1:\r
-      p->packSize |= (UInt32)b;\r
-      p->packSize++;\r
-      PRF(printf(" %8u", (unsigned)p->packSize));\r
-      return LZMA2_IS_THERE_PROP(LZMA2_GET_LZMA_MODE(p)) ? LZMA2_STATE_PROP:\r
-        (p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA);\r
-\r
-    case LZMA2_STATE_PROP:\r
-    {\r
-      unsigned lc, lp;\r
-      if (b >= (9 * 5 * 5))\r
-        return LZMA2_STATE_ERROR;\r
-      lc = b % 9;\r
-      b /= 9;\r
-      p->decoder.prop.pb = b / 5;\r
-      lp = b % 5;\r
-      if (lc + lp > LZMA2_LCLP_MAX)\r
-        return LZMA2_STATE_ERROR;\r
-      p->decoder.prop.lc = lc;\r
-      p->decoder.prop.lp = lp;\r
-      p->needInitProp = False;\r
-      return LZMA2_STATE_DATA;\r
-    }\r
-  }\r
-  return LZMA2_STATE_ERROR;\r
-}\r
-\r
-static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT size)\r
-{\r
-  memcpy(p->dic + p->dicPos, src, size);\r
-  p->dicPos += size;\r
-  if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= size)\r
-    p->checkDicSize = p->prop.dicSize;\r
-  p->processedPos += (UInt32)size;\r
-}\r
-\r
-void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState);\r
-\r
-SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,\r
-    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r
-{\r
-  SizeT inSize = *srcLen;\r
-  *srcLen = 0;\r
-  *status = LZMA_STATUS_NOT_SPECIFIED;\r
-\r
-  while (p->state != LZMA2_STATE_FINISHED)\r
-  {\r
-    SizeT dicPos = p->decoder.dicPos;\r
-    \r
-    if (p->state == LZMA2_STATE_ERROR)\r
-      return SZ_ERROR_DATA;\r
-    \r
-    if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY)\r
-    {\r
-      *status = LZMA_STATUS_NOT_FINISHED;\r
-      return SZ_OK;\r
-    }\r
-\r
-    if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)\r
-    {\r
-      if (*srcLen == inSize)\r
-      {\r
-        *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r
-        return SZ_OK;\r
-      }\r
-      (*srcLen)++;\r
-      p->state = Lzma2Dec_UpdateState(p, *src++);\r
-\r
-      if (dicPos == dicLimit && p->state != LZMA2_STATE_FINISHED)\r
-      {\r
-        p->state = LZMA2_STATE_ERROR;\r
-        return SZ_ERROR_DATA;\r
-      }\r
-      continue;\r
-    }\r
-    \r
-    {\r
-      SizeT destSizeCur = dicLimit - dicPos;\r
-      SizeT srcSizeCur = inSize - *srcLen;\r
-      ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;\r
-      \r
-      if (p->unpackSize <= destSizeCur)\r
-      {\r
-        destSizeCur = (SizeT)p->unpackSize;\r
-        curFinishMode = LZMA_FINISH_END;\r
-      }\r
-\r
-      if (LZMA2_IS_UNCOMPRESSED_STATE(p))\r
-      {\r
-        if (*srcLen == inSize)\r
-        {\r
-          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r
-          return SZ_OK;\r
-        }\r
-\r
-        if (p->state == LZMA2_STATE_DATA)\r
-        {\r
-          Bool initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC);\r
-          if (initDic)\r
-            p->needInitProp = p->needInitState = True;\r
-          else if (p->needInitDic)\r
-          {\r
-            p->state = LZMA2_STATE_ERROR;\r
-            return SZ_ERROR_DATA;\r
-          }\r
-          p->needInitDic = False;\r
-          LzmaDec_InitDicAndState(&p->decoder, initDic, False);\r
-        }\r
-\r
-        if (srcSizeCur > destSizeCur)\r
-          srcSizeCur = destSizeCur;\r
-\r
-        if (srcSizeCur == 0)\r
-        {\r
-          p->state = LZMA2_STATE_ERROR;\r
-          return SZ_ERROR_DATA;\r
-        }\r
-\r
-        LzmaDec_UpdateWithUncompressed(&p->decoder, src, srcSizeCur);\r
-\r
-        src += srcSizeCur;\r
-        *srcLen += srcSizeCur;\r
-        p->unpackSize -= (UInt32)srcSizeCur;\r
-        p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;\r
-      }\r
-      else\r
-      {\r
-        SizeT outSizeProcessed;\r
-        SRes res;\r
-\r
-        if (p->state == LZMA2_STATE_DATA)\r
-        {\r
-          unsigned mode = LZMA2_GET_LZMA_MODE(p);\r
-          Bool initDic = (mode == 3);\r
-          Bool initState = (mode != 0);\r
-          if ((!initDic && p->needInitDic) || (!initState && p->needInitState))\r
-          {\r
-            p->state = LZMA2_STATE_ERROR;\r
-            return SZ_ERROR_DATA;\r
-          }\r
-          \r
-          LzmaDec_InitDicAndState(&p->decoder, initDic, initState);\r
-          p->needInitDic = False;\r
-          p->needInitState = False;\r
-          p->state = LZMA2_STATE_DATA_CONT;\r
-        }\r
-  \r
-        if (srcSizeCur > p->packSize)\r
-          srcSizeCur = (SizeT)p->packSize;\r
-          \r
-        res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status);\r
-        \r
-        src += srcSizeCur;\r
-        *srcLen += srcSizeCur;\r
-        p->packSize -= (UInt32)srcSizeCur;\r
-\r
-        outSizeProcessed = p->decoder.dicPos - dicPos;\r
-        p->unpackSize -= (UInt32)outSizeProcessed;\r
-\r
-        RINOK(res);\r
-        if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)\r
-          return res;\r
-\r
-        if (srcSizeCur == 0 && outSizeProcessed == 0)\r
-        {\r
-          if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r
-              || p->unpackSize != 0\r
-              || p->packSize != 0)\r
-          {\r
-            p->state = LZMA2_STATE_ERROR;\r
-            return SZ_ERROR_DATA;\r
-          }\r
-          p->state = LZMA2_STATE_CONTROL;\r
-        }\r
-        \r
-        if (*status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)\r
-          *status = LZMA_STATUS_NOT_FINISHED;\r
-      }\r
-    }\r
-  }\r
-  \r
-  *status = LZMA_STATUS_FINISHED_WITH_MARK;\r
-  return SZ_OK;\r
-}\r
-\r
-SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r
-{\r
-  SizeT outSize = *destLen, inSize = *srcLen;\r
-  *srcLen = *destLen = 0;\r
-  for (;;)\r
-  {\r
-    SizeT srcSizeCur = inSize, outSizeCur, dicPos;\r
-    ELzmaFinishMode curFinishMode;\r
-    SRes res;\r
-    if (p->decoder.dicPos == p->decoder.dicBufSize)\r
-      p->decoder.dicPos = 0;\r
-    dicPos = p->decoder.dicPos;\r
-    if (outSize > p->decoder.dicBufSize - dicPos)\r
-    {\r
-      outSizeCur = p->decoder.dicBufSize;\r
-      curFinishMode = LZMA_FINISH_ANY;\r
-    }\r
-    else\r
-    {\r
-      outSizeCur = dicPos + outSize;\r
-      curFinishMode = finishMode;\r
-    }\r
-\r
-    res = Lzma2Dec_DecodeToDic(p, outSizeCur, src, &srcSizeCur, curFinishMode, status);\r
-    src += srcSizeCur;\r
-    inSize -= srcSizeCur;\r
-    *srcLen += srcSizeCur;\r
-    outSizeCur = p->decoder.dicPos - dicPos;\r
-    memcpy(dest, p->decoder.dic + dicPos, outSizeCur);\r
-    dest += outSizeCur;\r
-    outSize -= outSizeCur;\r
-    *destLen += outSizeCur;\r
-    if (res != 0)\r
-      return res;\r
-    if (outSizeCur == 0 || outSize == 0)\r
-      return SZ_OK;\r
-  }\r
-}\r
-\r
-SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-    Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)\r
-{\r
-  CLzma2Dec p;\r
-  SRes res;\r
-  SizeT outSize = *destLen, inSize = *srcLen;\r
-  *destLen = *srcLen = 0;\r
-  *status = LZMA_STATUS_NOT_SPECIFIED;\r
-  Lzma2Dec_Construct(&p);\r
-  RINOK(Lzma2Dec_AllocateProbs(&p, prop, alloc));\r
-  p.decoder.dic = dest;\r
-  p.decoder.dicBufSize = outSize;\r
-  Lzma2Dec_Init(&p);\r
-  *srcLen = inSize;\r
-  res = Lzma2Dec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r
-  *destLen = p.decoder.dicPos;\r
-  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r
-    res = SZ_ERROR_INPUT_EOF;\r
-  Lzma2Dec_FreeProbs(&p, alloc);\r
-  return res;\r
-}\r
diff --git a/deps/lzma-16.04/C/Lzma2Dec.h b/deps/lzma-16.04/C/Lzma2Dec.h
deleted file mode 100644 (file)
index 026cdef..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/* Lzma2Dec.h -- LZMA2 Decoder\r
-2015-05-13 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __LZMA2_DEC_H\r
-#define __LZMA2_DEC_H\r
-\r
-#include "LzmaDec.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-/* ---------- State Interface ---------- */\r
-\r
-typedef struct\r
-{\r
-  CLzmaDec decoder;\r
-  UInt32 packSize;\r
-  UInt32 unpackSize;\r
-  unsigned state;\r
-  Byte control;\r
-  Bool needInitDic;\r
-  Bool needInitState;\r
-  Bool needInitProp;\r
-} CLzma2Dec;\r
-\r
-#define Lzma2Dec_Construct(p) LzmaDec_Construct(&(p)->decoder)\r
-#define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc);\r
-#define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc);\r
-\r
-SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc);\r
-SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc);\r
-void Lzma2Dec_Init(CLzma2Dec *p);\r
-\r
-\r
-/*\r
-finishMode:\r
-  It has meaning only if the decoding reaches output limit (*destLen or dicLimit).\r
-  LZMA_FINISH_ANY - use smallest number of input bytes\r
-  LZMA_FINISH_END - read EndOfStream marker after decoding\r
-\r
-Returns:\r
-  SZ_OK\r
-    status:\r
-      LZMA_STATUS_FINISHED_WITH_MARK\r
-      LZMA_STATUS_NOT_FINISHED\r
-      LZMA_STATUS_NEEDS_MORE_INPUT\r
-  SZ_ERROR_DATA - Data error\r
-*/\r
-\r
-SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,\r
-    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r
-\r
-SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen,\r
-    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r
-\r
-\r
-/* ---------- One Call Interface ---------- */\r
-\r
-/*\r
-finishMode:\r
-  It has meaning only if the decoding reaches output limit (*destLen).\r
-  LZMA_FINISH_ANY - use smallest number of input bytes\r
-  LZMA_FINISH_END - read EndOfStream marker after decoding\r
-\r
-Returns:\r
-  SZ_OK\r
-    status:\r
-      LZMA_STATUS_FINISHED_WITH_MARK\r
-      LZMA_STATUS_NOT_FINISHED\r
-  SZ_ERROR_DATA - Data error\r
-  SZ_ERROR_MEM  - Memory allocation error\r
-  SZ_ERROR_UNSUPPORTED - Unsupported properties\r
-  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r
-*/\r
-\r
-SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-    Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Lzma2Enc.c b/deps/lzma-16.04/C/Lzma2Enc.c
deleted file mode 100644 (file)
index cba0134..0000000
+++ /dev/null
@@ -1,520 +0,0 @@
-/* Lzma2Enc.c -- LZMA2 Encoder\r
-2015-10-04 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-/* #include <stdio.h> */\r
-#include <string.h>\r
-\r
-/* #define _7ZIP_ST */\r
-\r
-#include "Lzma2Enc.h"\r
-\r
-#ifndef _7ZIP_ST\r
-#include "MtCoder.h"\r
-#else\r
-#define NUM_MT_CODER_THREADS_MAX 1\r
-#endif\r
-\r
-#define LZMA2_CONTROL_LZMA (1 << 7)\r
-#define LZMA2_CONTROL_COPY_NO_RESET 2\r
-#define LZMA2_CONTROL_COPY_RESET_DIC 1\r
-#define LZMA2_CONTROL_EOF 0\r
-\r
-#define LZMA2_LCLP_MAX 4\r
-\r
-#define LZMA2_DIC_SIZE_FROM_PROP(p) (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11))\r
-\r
-#define LZMA2_PACK_SIZE_MAX (1 << 16)\r
-#define LZMA2_COPY_CHUNK_SIZE LZMA2_PACK_SIZE_MAX\r
-#define LZMA2_UNPACK_SIZE_MAX (1 << 21)\r
-#define LZMA2_KEEP_WINDOW_SIZE LZMA2_UNPACK_SIZE_MAX\r
-\r
-#define LZMA2_CHUNK_SIZE_COMPRESSED_MAX ((1 << 16) + 16)\r
-\r
-\r
-#define PRF(x) /* x */\r
-\r
-/* ---------- CLzma2EncInt ---------- */\r
-\r
-typedef struct\r
-{\r
-  CLzmaEncHandle enc;\r
-  UInt64 srcPos;\r
-  Byte props;\r
-  Bool needInitState;\r
-  Bool needInitProp;\r
-} CLzma2EncInt;\r
-\r
-static SRes Lzma2EncInt_Init(CLzma2EncInt *p, const CLzma2EncProps *props)\r
-{\r
-  Byte propsEncoded[LZMA_PROPS_SIZE];\r
-  SizeT propsSize = LZMA_PROPS_SIZE;\r
-  RINOK(LzmaEnc_SetProps(p->enc, &props->lzmaProps));\r
-  RINOK(LzmaEnc_WriteProperties(p->enc, propsEncoded, &propsSize));\r
-  p->srcPos = 0;\r
-  p->props = propsEncoded[0];\r
-  p->needInitState = True;\r
-  p->needInitProp = True;\r
-  return SZ_OK;\r
-}\r
-\r
-SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 keepWindowSize,\r
-    ISzAlloc *alloc, ISzAlloc *allocBig);\r
-SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\r
-    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig);\r
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\r
-    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);\r
-const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp);\r
-void LzmaEnc_Finish(CLzmaEncHandle pp);\r
-void LzmaEnc_SaveState(CLzmaEncHandle pp);\r
-void LzmaEnc_RestoreState(CLzmaEncHandle pp);\r
-\r
-\r
-static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,\r
-    size_t *packSizeRes, ISeqOutStream *outStream)\r
-{\r
-  size_t packSizeLimit = *packSizeRes;\r
-  size_t packSize = packSizeLimit;\r
-  UInt32 unpackSize = LZMA2_UNPACK_SIZE_MAX;\r
-  unsigned lzHeaderSize = 5 + (p->needInitProp ? 1 : 0);\r
-  Bool useCopyBlock;\r
-  SRes res;\r
-\r
-  *packSizeRes = 0;\r
-  if (packSize < lzHeaderSize)\r
-    return SZ_ERROR_OUTPUT_EOF;\r
-  packSize -= lzHeaderSize;\r
-  \r
-  LzmaEnc_SaveState(p->enc);\r
-  res = LzmaEnc_CodeOneMemBlock(p->enc, p->needInitState,\r
-      outBuf + lzHeaderSize, &packSize, LZMA2_PACK_SIZE_MAX, &unpackSize);\r
-  \r
-  PRF(printf("\npackSize = %7d unpackSize = %7d  ", packSize, unpackSize));\r
-\r
-  if (unpackSize == 0)\r
-    return res;\r
-\r
-  if (res == SZ_OK)\r
-    useCopyBlock = (packSize + 2 >= unpackSize || packSize > (1 << 16));\r
-  else\r
-  {\r
-    if (res != SZ_ERROR_OUTPUT_EOF)\r
-      return res;\r
-    res = SZ_OK;\r
-    useCopyBlock = True;\r
-  }\r
-\r
-  if (useCopyBlock)\r
-  {\r
-    size_t destPos = 0;\r
-    PRF(printf("################# COPY           "));\r
-\r
-    while (unpackSize > 0)\r
-    {\r
-      UInt32 u = (unpackSize < LZMA2_COPY_CHUNK_SIZE) ? unpackSize : LZMA2_COPY_CHUNK_SIZE;\r
-      if (packSizeLimit - destPos < u + 3)\r
-        return SZ_ERROR_OUTPUT_EOF;\r
-      outBuf[destPos++] = (Byte)(p->srcPos == 0 ? LZMA2_CONTROL_COPY_RESET_DIC : LZMA2_CONTROL_COPY_NO_RESET);\r
-      outBuf[destPos++] = (Byte)((u - 1) >> 8);\r
-      outBuf[destPos++] = (Byte)(u - 1);\r
-      memcpy(outBuf + destPos, LzmaEnc_GetCurBuf(p->enc) - unpackSize, u);\r
-      unpackSize -= u;\r
-      destPos += u;\r
-      p->srcPos += u;\r
-      \r
-      if (outStream)\r
-      {\r
-        *packSizeRes += destPos;\r
-        if (outStream->Write(outStream, outBuf, destPos) != destPos)\r
-          return SZ_ERROR_WRITE;\r
-        destPos = 0;\r
-      }\r
-      else\r
-        *packSizeRes = destPos;\r
-      /* needInitState = True; */\r
-    }\r
-    \r
-    LzmaEnc_RestoreState(p->enc);\r
-    return SZ_OK;\r
-  }\r
-\r
-  {\r
-    size_t destPos = 0;\r
-    UInt32 u = unpackSize - 1;\r
-    UInt32 pm = (UInt32)(packSize - 1);\r
-    unsigned mode = (p->srcPos == 0) ? 3 : (p->needInitState ? (p->needInitProp ? 2 : 1) : 0);\r
-\r
-    PRF(printf("               "));\r
-\r
-    outBuf[destPos++] = (Byte)(LZMA2_CONTROL_LZMA | (mode << 5) | ((u >> 16) & 0x1F));\r
-    outBuf[destPos++] = (Byte)(u >> 8);\r
-    outBuf[destPos++] = (Byte)u;\r
-    outBuf[destPos++] = (Byte)(pm >> 8);\r
-    outBuf[destPos++] = (Byte)pm;\r
-    \r
-    if (p->needInitProp)\r
-      outBuf[destPos++] = p->props;\r
-    \r
-    p->needInitProp = False;\r
-    p->needInitState = False;\r
-    destPos += packSize;\r
-    p->srcPos += unpackSize;\r
-\r
-    if (outStream)\r
-      if (outStream->Write(outStream, outBuf, destPos) != destPos)\r
-        return SZ_ERROR_WRITE;\r
-    \r
-    *packSizeRes = destPos;\r
-    return SZ_OK;\r
-  }\r
-}\r
-\r
-\r
-/* ---------- Lzma2 Props ---------- */\r
-\r
-void Lzma2EncProps_Init(CLzma2EncProps *p)\r
-{\r
-  LzmaEncProps_Init(&p->lzmaProps);\r
-  p->numTotalThreads = -1;\r
-  p->numBlockThreads = -1;\r
-  p->blockSize = 0;\r
-}\r
-\r
-void Lzma2EncProps_Normalize(CLzma2EncProps *p)\r
-{\r
-  int t1, t1n, t2, t3;\r
-  {\r
-    CLzmaEncProps lzmaProps = p->lzmaProps;\r
-    LzmaEncProps_Normalize(&lzmaProps);\r
-    t1n = lzmaProps.numThreads;\r
-  }\r
-\r
-  t1 = p->lzmaProps.numThreads;\r
-  t2 = p->numBlockThreads;\r
-  t3 = p->numTotalThreads;\r
-\r
-  if (t2 > NUM_MT_CODER_THREADS_MAX)\r
-    t2 = NUM_MT_CODER_THREADS_MAX;\r
-\r
-  if (t3 <= 0)\r
-  {\r
-    if (t2 <= 0)\r
-      t2 = 1;\r
-    t3 = t1n * t2;\r
-  }\r
-  else if (t2 <= 0)\r
-  {\r
-    t2 = t3 / t1n;\r
-    if (t2 == 0)\r
-    {\r
-      t1 = 1;\r
-      t2 = t3;\r
-    }\r
-    if (t2 > NUM_MT_CODER_THREADS_MAX)\r
-      t2 = NUM_MT_CODER_THREADS_MAX;\r
-  }\r
-  else if (t1 <= 0)\r
-  {\r
-    t1 = t3 / t2;\r
-    if (t1 == 0)\r
-      t1 = 1;\r
-  }\r
-  else\r
-    t3 = t1n * t2;\r
-\r
-  p->lzmaProps.numThreads = t1;\r
-\r
-  LzmaEncProps_Normalize(&p->lzmaProps);\r
-\r
-  t1 = p->lzmaProps.numThreads;\r
-\r
-  if (p->blockSize == 0)\r
-  {\r
-    UInt32 dictSize = p->lzmaProps.dictSize;\r
-    UInt64 blockSize = (UInt64)dictSize << 2;\r
-    const UInt32 kMinSize = (UInt32)1 << 20;\r
-    const UInt32 kMaxSize = (UInt32)1 << 28;\r
-    if (blockSize < kMinSize) blockSize = kMinSize;\r
-    if (blockSize > kMaxSize) blockSize = kMaxSize;\r
-    if (blockSize < dictSize) blockSize = dictSize;\r
-    p->blockSize = (size_t)blockSize;\r
-  }\r
-  \r
-  if (t2 > 1 && p->lzmaProps.reduceSize != (UInt64)(Int64)-1)\r
-  {\r
-    UInt64 temp = p->lzmaProps.reduceSize + p->blockSize - 1;\r
-    if (temp > p->lzmaProps.reduceSize)\r
-    {\r
-      UInt64 numBlocks = temp / p->blockSize;\r
-      if (numBlocks < (unsigned)t2)\r
-      {\r
-        t2 = (unsigned)numBlocks;\r
-        if (t2 == 0)\r
-          t2 = 1;\r
-        t3 = t1 * t2;\r
-      }\r
-    }\r
-  }\r
-  \r
-  p->numBlockThreads = t2;\r
-  p->numTotalThreads = t3;\r
-}\r
-\r
-\r
-static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)\r
-{\r
-  return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;\r
-}\r
-\r
-\r
-/* ---------- Lzma2 ---------- */\r
-\r
-typedef struct\r
-{\r
-  Byte propEncoded;\r
-  CLzma2EncProps props;\r
-  \r
-  Byte *outBuf;\r
-\r
-  ISzAlloc *alloc;\r
-  ISzAlloc *allocBig;\r
-\r
-  CLzma2EncInt coders[NUM_MT_CODER_THREADS_MAX];\r
-\r
-  #ifndef _7ZIP_ST\r
-  CMtCoder mtCoder;\r
-  #endif\r
-\r
-} CLzma2Enc;\r
-\r
-\r
-/* ---------- Lzma2EncThread ---------- */\r
-\r
-static SRes Lzma2Enc_EncodeMt1(CLzma2EncInt *p, CLzma2Enc *mainEncoder,\r
-  ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress)\r
-{\r
-  UInt64 packTotal = 0;\r
-  SRes res = SZ_OK;\r
-\r
-  if (!mainEncoder->outBuf)\r
-  {\r
-    mainEncoder->outBuf = (Byte *)IAlloc_Alloc(mainEncoder->alloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX);\r
-    if (!mainEncoder->outBuf)\r
-      return SZ_ERROR_MEM;\r
-  }\r
-  \r
-  RINOK(Lzma2EncInt_Init(p, &mainEncoder->props));\r
-  RINOK(LzmaEnc_PrepareForLzma2(p->enc, inStream, LZMA2_KEEP_WINDOW_SIZE,\r
-      mainEncoder->alloc, mainEncoder->allocBig));\r
-  \r
-  for (;;)\r
-  {\r
-    size_t packSize = LZMA2_CHUNK_SIZE_COMPRESSED_MAX;\r
-    res = Lzma2EncInt_EncodeSubblock(p, mainEncoder->outBuf, &packSize, outStream);\r
-    if (res != SZ_OK)\r
-      break;\r
-    packTotal += packSize;\r
-    res = Progress(progress, p->srcPos, packTotal);\r
-    if (res != SZ_OK)\r
-      break;\r
-    if (packSize == 0)\r
-      break;\r
-  }\r
-  \r
-  LzmaEnc_Finish(p->enc);\r
-\r
-  if (res == SZ_OK)\r
-  {\r
-    Byte b = 0;\r
-    if (outStream->Write(outStream, &b, 1) != 1)\r
-      return SZ_ERROR_WRITE;\r
-  }\r
-  \r
-  return res;\r
-}\r
-\r
-\r
-#ifndef _7ZIP_ST\r
-\r
-typedef struct\r
-{\r
-  IMtCoderCallback funcTable;\r
-  CLzma2Enc *lzma2Enc;\r
-} CMtCallbackImp;\r
-\r
-static SRes MtCallbackImp_Code(void *pp, unsigned index, Byte *dest, size_t *destSize,\r
-      const Byte *src, size_t srcSize, int finished)\r
-{\r
-  CMtCallbackImp *imp = (CMtCallbackImp *)pp;\r
-  CLzma2Enc *mainEncoder = imp->lzma2Enc;\r
-  CLzma2EncInt *p = &mainEncoder->coders[index];\r
-\r
-  SRes res = SZ_OK;\r
-  {\r
-    size_t destLim = *destSize;\r
-    *destSize = 0;\r
-\r
-    if (srcSize != 0)\r
-    {\r
-      RINOK(Lzma2EncInt_Init(p, &mainEncoder->props));\r
-     \r
-      RINOK(LzmaEnc_MemPrepare(p->enc, src, srcSize, LZMA2_KEEP_WINDOW_SIZE,\r
-          mainEncoder->alloc, mainEncoder->allocBig));\r
-     \r
-      while (p->srcPos < srcSize)\r
-      {\r
-        size_t packSize = destLim - *destSize;\r
-        res = Lzma2EncInt_EncodeSubblock(p, dest + *destSize, &packSize, NULL);\r
-        if (res != SZ_OK)\r
-          break;\r
-        *destSize += packSize;\r
-\r
-        if (packSize == 0)\r
-        {\r
-          res = SZ_ERROR_FAIL;\r
-          break;\r
-        }\r
-\r
-        if (MtProgress_Set(&mainEncoder->mtCoder.mtProgress, index, p->srcPos, *destSize) != SZ_OK)\r
-        {\r
-          res = SZ_ERROR_PROGRESS;\r
-          break;\r
-        }\r
-      }\r
-      \r
-      LzmaEnc_Finish(p->enc);\r
-      if (res != SZ_OK)\r
-        return res;\r
-    }\r
-    \r
-    if (finished)\r
-    {\r
-      if (*destSize == destLim)\r
-        return SZ_ERROR_OUTPUT_EOF;\r
-      dest[(*destSize)++] = 0;\r
-    }\r
-  }\r
-  return res;\r
-}\r
-\r
-#endif\r
-\r
-\r
-/* ---------- Lzma2Enc ---------- */\r
-\r
-CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  CLzma2Enc *p = (CLzma2Enc *)alloc->Alloc(alloc, sizeof(CLzma2Enc));\r
-  if (!p)\r
-    return NULL;\r
-  Lzma2EncProps_Init(&p->props);\r
-  Lzma2EncProps_Normalize(&p->props);\r
-  p->outBuf = 0;\r
-  p->alloc = alloc;\r
-  p->allocBig = allocBig;\r
-  {\r
-    unsigned i;\r
-    for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)\r
-      p->coders[i].enc = 0;\r
-  }\r
-  \r
-  #ifndef _7ZIP_ST\r
-  MtCoder_Construct(&p->mtCoder);\r
-  #endif\r
-\r
-  return p;\r
-}\r
-\r
-void Lzma2Enc_Destroy(CLzma2EncHandle pp)\r
-{\r
-  CLzma2Enc *p = (CLzma2Enc *)pp;\r
-  unsigned i;\r
-  for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)\r
-  {\r
-    CLzma2EncInt *t = &p->coders[i];\r
-    if (t->enc)\r
-    {\r
-      LzmaEnc_Destroy(t->enc, p->alloc, p->allocBig);\r
-      t->enc = 0;\r
-    }\r
-  }\r
-\r
-  #ifndef _7ZIP_ST\r
-  MtCoder_Destruct(&p->mtCoder);\r
-  #endif\r
-\r
-  IAlloc_Free(p->alloc, p->outBuf);\r
-  IAlloc_Free(p->alloc, pp);\r
-}\r
-\r
-SRes Lzma2Enc_SetProps(CLzma2EncHandle pp, const CLzma2EncProps *props)\r
-{\r
-  CLzma2Enc *p = (CLzma2Enc *)pp;\r
-  CLzmaEncProps lzmaProps = props->lzmaProps;\r
-  LzmaEncProps_Normalize(&lzmaProps);\r
-  if (lzmaProps.lc + lzmaProps.lp > LZMA2_LCLP_MAX)\r
-    return SZ_ERROR_PARAM;\r
-  p->props = *props;\r
-  Lzma2EncProps_Normalize(&p->props);\r
-  return SZ_OK;\r
-}\r
-\r
-Byte Lzma2Enc_WriteProperties(CLzma2EncHandle pp)\r
-{\r
-  CLzma2Enc *p = (CLzma2Enc *)pp;\r
-  unsigned i;\r
-  UInt32 dicSize = LzmaEncProps_GetDictSize(&p->props.lzmaProps);\r
-  for (i = 0; i < 40; i++)\r
-    if (dicSize <= LZMA2_DIC_SIZE_FROM_PROP(i))\r
-      break;\r
-  return (Byte)i;\r
-}\r
-\r
-SRes Lzma2Enc_Encode(CLzma2EncHandle pp,\r
-    ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress)\r
-{\r
-  CLzma2Enc *p = (CLzma2Enc *)pp;\r
-  int i;\r
-\r
-  for (i = 0; i < p->props.numBlockThreads; i++)\r
-  {\r
-    CLzma2EncInt *t = &p->coders[(unsigned)i];\r
-    if (!t->enc)\r
-    {\r
-      t->enc = LzmaEnc_Create(p->alloc);\r
-      if (!t->enc)\r
-        return SZ_ERROR_MEM;\r
-    }\r
-  }\r
-\r
-  #ifndef _7ZIP_ST\r
-  if (p->props.numBlockThreads > 1)\r
-  {\r
-    CMtCallbackImp mtCallback;\r
-\r
-    mtCallback.funcTable.Code = MtCallbackImp_Code;\r
-    mtCallback.lzma2Enc = p;\r
-    \r
-    p->mtCoder.progress = progress;\r
-    p->mtCoder.inStream = inStream;\r
-    p->mtCoder.outStream = outStream;\r
-    p->mtCoder.alloc = p->alloc;\r
-    p->mtCoder.mtCallback = &mtCallback.funcTable;\r
-\r
-    p->mtCoder.blockSize = p->props.blockSize;\r
-    p->mtCoder.destBlockSize = p->props.blockSize + (p->props.blockSize >> 10) + 16;\r
-    if (p->mtCoder.destBlockSize < p->props.blockSize)\r
-    {\r
-      p->mtCoder.destBlockSize = (size_t)0 - 1;\r
-      if (p->mtCoder.destBlockSize < p->props.blockSize)\r
-        return SZ_ERROR_FAIL;\r
-    }\r
-    p->mtCoder.numThreads = p->props.numBlockThreads;\r
-    \r
-    return MtCoder_Code(&p->mtCoder);\r
-  }\r
-  #endif\r
-\r
-  return Lzma2Enc_EncodeMt1(&p->coders[0], p, outStream, inStream, progress);\r
-}\r
diff --git a/deps/lzma-16.04/C/Lzma2Enc.h b/deps/lzma-16.04/C/Lzma2Enc.h
deleted file mode 100644 (file)
index 061178a..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Lzma2Enc.h -- LZMA2 Encoder\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __LZMA2_ENC_H\r
-#define __LZMA2_ENC_H\r
-\r
-#include "LzmaEnc.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-typedef struct\r
-{\r
-  CLzmaEncProps lzmaProps;\r
-  size_t blockSize;\r
-  int numBlockThreads;\r
-  int numTotalThreads;\r
-} CLzma2EncProps;\r
-\r
-void Lzma2EncProps_Init(CLzma2EncProps *p);\r
-void Lzma2EncProps_Normalize(CLzma2EncProps *p);\r
-\r
-/* ---------- CLzmaEnc2Handle Interface ---------- */\r
-\r
-/* Lzma2Enc_* functions can return the following exit codes:\r
-Returns:\r
-  SZ_OK           - OK\r
-  SZ_ERROR_MEM    - Memory allocation error\r
-  SZ_ERROR_PARAM  - Incorrect paramater in props\r
-  SZ_ERROR_WRITE  - Write callback error\r
-  SZ_ERROR_PROGRESS - some break from progress callback\r
-  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)\r
-*/\r
-\r
-typedef void * CLzma2EncHandle;\r
-\r
-CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig);\r
-void Lzma2Enc_Destroy(CLzma2EncHandle p);\r
-SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props);\r
-Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p);\r
-SRes Lzma2Enc_Encode(CLzma2EncHandle p,\r
-    ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress);\r
-\r
-/* ---------- One Call Interface ---------- */\r
-\r
-/* Lzma2Encode\r
-Return code:\r
-  SZ_OK               - OK\r
-  SZ_ERROR_MEM        - Memory allocation error\r
-  SZ_ERROR_PARAM      - Incorrect paramater\r
-  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r
-  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r
-*/\r
-\r
-/*\r
-SRes Lzma2Encode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
-    const CLzmaEncProps *props, Byte *propsEncoded, int writeEndMark,\r
-    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r
-*/\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Lzma86Enc.c b/deps/lzma-16.04/C/Lzma86Enc.c
deleted file mode 100644 (file)
index ee59fb7..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder\r
-2016-05-16 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-#include "Lzma86.h"\r
-\r
-#include "Alloc.h"\r
-#include "Bra.h"\r
-#include "LzmaEnc.h"\r
-\r
-#define SZE_OUT_OVERFLOW SZE_DATA_ERROR\r
-\r
-int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r
-    int level, UInt32 dictSize, int filterMode)\r
-{\r
-  size_t outSize2 = *destLen;\r
-  Byte *filteredStream;\r
-  Bool useFilter;\r
-  int mainResult = SZ_ERROR_OUTPUT_EOF;\r
-  CLzmaEncProps props;\r
-  LzmaEncProps_Init(&props);\r
-  props.level = level;\r
-  props.dictSize = dictSize;\r
-  \r
-  *destLen = 0;\r
-  if (outSize2 < LZMA86_HEADER_SIZE)\r
-    return SZ_ERROR_OUTPUT_EOF;\r
-\r
-  {\r
-    int i;\r
-    UInt64 t = srcLen;\r
-    for (i = 0; i < 8; i++, t >>= 8)\r
-      dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;\r
-  }\r
-\r
-  filteredStream = 0;\r
-  useFilter = (filterMode != SZ_FILTER_NO);\r
-  if (useFilter)\r
-  {\r
-    if (srcLen != 0)\r
-    {\r
-      filteredStream = (Byte *)MyAlloc(srcLen);\r
-      if (filteredStream == 0)\r
-        return SZ_ERROR_MEM;\r
-      memcpy(filteredStream, src, srcLen);\r
-    }\r
-    {\r
-      UInt32 x86State;\r
-      x86_Convert_Init(x86State);\r
-      x86_Convert(filteredStream, srcLen, 0, &x86State, 1);\r
-    }\r
-  }\r
-\r
-  {\r
-    size_t minSize = 0;\r
-    Bool bestIsFiltered = False;\r
-\r
-    /* passes for SZ_FILTER_AUTO:\r
-        0 - BCJ + LZMA\r
-        1 - LZMA\r
-        2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.\r
-    */\r
-    int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r
-\r
-    int i;\r
-    for (i = 0; i < numPasses; i++)\r
-    {\r
-      size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;\r
-      size_t outPropsSize = 5;\r
-      SRes curRes;\r
-      Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);\r
-      if (curModeIsFiltered && !bestIsFiltered)\r
-        break;\r
-      if (useFilter && i == 0)\r
-        curModeIsFiltered = True;\r
-      \r
-      curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,\r
-          curModeIsFiltered ? filteredStream : src, srcLen,\r
-          &props, dest + 1, &outPropsSize, 0,\r
-          NULL, &g_Alloc, &g_Alloc);\r
-      \r
-      if (curRes != SZ_ERROR_OUTPUT_EOF)\r
-      {\r
-        if (curRes != SZ_OK)\r
-        {\r
-          mainResult = curRes;\r
-          break;\r
-        }\r
-        if (outSizeProcessed <= minSize || mainResult != SZ_OK)\r
-        {\r
-          minSize = outSizeProcessed;\r
-          bestIsFiltered = curModeIsFiltered;\r
-          mainResult = SZ_OK;\r
-        }\r
-      }\r
-    }\r
-    dest[0] = (Byte)(bestIsFiltered ? 1 : 0);\r
-    *destLen = LZMA86_HEADER_SIZE + minSize;\r
-  }\r
-  if (useFilter)\r
-    MyFree(filteredStream);\r
-  return mainResult;\r
-}\r
diff --git a/deps/lzma-16.04/C/LzmaEnc.c b/deps/lzma-16.04/C/LzmaEnc.c
deleted file mode 100644 (file)
index 462ca67..0000000
+++ /dev/null
@@ -1,2351 +0,0 @@
-/* LzmaEnc.c -- LZMA Encoder\r
-2016-05-16 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-/* #define SHOW_STAT */\r
-/* #define SHOW_STAT2 */\r
-\r
-#if defined(SHOW_STAT) || defined(SHOW_STAT2)\r
-#include <stdio.h>\r
-#endif\r
-\r
-#include "LzmaEnc.h"\r
-\r
-#include "LzFind.h"\r
-#ifndef _7ZIP_ST\r
-#include "LzFindMt.h"\r
-#endif\r
-\r
-#ifdef SHOW_STAT\r
-static unsigned g_STAT_OFFSET = 0;\r
-#endif\r
-\r
-#define kMaxHistorySize ((UInt32)3 << 29)\r
-/* #define kMaxHistorySize ((UInt32)7 << 29) */\r
-\r
-#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)\r
-\r
-#define kBlockSize (9 << 10)\r
-#define kUnpackBlockSize (1 << 18)\r
-#define kMatchArraySize (1 << 21)\r
-#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)\r
-\r
-#define kNumMaxDirectBits (31)\r
-\r
-#define kNumTopBits 24\r
-#define kTopValue ((UInt32)1 << kNumTopBits)\r
-\r
-#define kNumBitModelTotalBits 11\r
-#define kBitModelTotal (1 << kNumBitModelTotalBits)\r
-#define kNumMoveBits 5\r
-#define kProbInitValue (kBitModelTotal >> 1)\r
-\r
-#define kNumMoveReducingBits 4\r
-#define kNumBitPriceShiftBits 4\r
-#define kBitPrice (1 << kNumBitPriceShiftBits)\r
-\r
-void LzmaEncProps_Init(CLzmaEncProps *p)\r
-{\r
-  p->level = 5;\r
-  p->dictSize = p->mc = 0;\r
-  p->reduceSize = (UInt64)(Int64)-1;\r
-  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\r
-  p->writeEndMark = 0;\r
-}\r
-\r
-void LzmaEncProps_Normalize(CLzmaEncProps *p)\r
-{\r
-  int level = p->level;\r
-  if (level < 0) level = 5;\r
-  p->level = level;\r
-  \r
-  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));\r
-  if (p->dictSize > p->reduceSize)\r
-  {\r
-    unsigned i;\r
-    for (i = 11; i <= 30; i++)\r
-    {\r
-      if ((UInt32)p->reduceSize <= ((UInt32)2 << i)) { p->dictSize = ((UInt32)2 << i); break; }\r
-      if ((UInt32)p->reduceSize <= ((UInt32)3 << i)) { p->dictSize = ((UInt32)3 << i); break; }\r
-    }\r
-  }\r
-\r
-  if (p->lc < 0) p->lc = 3;\r
-  if (p->lp < 0) p->lp = 0;\r
-  if (p->pb < 0) p->pb = 2;\r
-\r
-  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);\r
-  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);\r
-  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);\r
-  if (p->numHashBytes < 0) p->numHashBytes = 4;\r
-  if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\r
-  \r
-  if (p->numThreads < 0)\r
-    p->numThreads =\r
-      #ifndef _7ZIP_ST\r
-      ((p->btMode && p->algo) ? 2 : 1);\r
-      #else\r
-      1;\r
-      #endif\r
-}\r
-\r
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)\r
-{\r
-  CLzmaEncProps props = *props2;\r
-  LzmaEncProps_Normalize(&props);\r
-  return props.dictSize;\r
-}\r
-\r
-#if (_MSC_VER >= 1400)\r
-/* BSR code is fast for some new CPUs */\r
-/* #define LZMA_LOG_BSR */\r
-#endif\r
-\r
-#ifdef LZMA_LOG_BSR\r
-\r
-#define kDicLogSizeMaxCompress 32\r
-\r
-#define BSR2_RET(pos, res) { unsigned long zz; _BitScanReverse(&zz, (pos)); res = (zz + zz) + ((pos >> (zz - 1)) & 1); }\r
-\r
-static UInt32 GetPosSlot1(UInt32 pos)\r
-{\r
-  UInt32 res;\r
-  BSR2_RET(pos, res);\r
-  return res;\r
-}\r
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r
-#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }\r
-\r
-#else\r
-\r
-#define kNumLogBits (9 + sizeof(size_t) / 2)\r
-/* #define kNumLogBits (11 + sizeof(size_t) / 8 * 3) */\r
-\r
-#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)\r
-\r
-static void LzmaEnc_FastPosInit(Byte *g_FastPos)\r
-{\r
-  unsigned slot;\r
-  g_FastPos[0] = 0;\r
-  g_FastPos[1] = 1;\r
-  g_FastPos += 2;\r
-  \r
-  for (slot = 2; slot < kNumLogBits * 2; slot++)\r
-  {\r
-    size_t k = ((size_t)1 << ((slot >> 1) - 1));\r
-    size_t j;\r
-    for (j = 0; j < k; j++)\r
-      g_FastPos[j] = (Byte)slot;\r
-    g_FastPos += k;\r
-  }\r
-}\r
-\r
-/* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */\r
-/*\r
-#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \\r
-  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \\r
-  res = p->g_FastPos[pos >> zz] + (zz * 2); }\r
-*/\r
-\r
-/*\r
-#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \\r
-  (0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \\r
-  res = p->g_FastPos[pos >> zz] + (zz * 2); }\r
-*/\r
-\r
-#define BSR2_RET(pos, res) { UInt32 zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \\r
-  res = p->g_FastPos[pos >> zz] + (zz * 2); }\r
-\r
-/*\r
-#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \\r
-  p->g_FastPos[pos >> 6] + 12 : \\r
-  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }\r
-*/\r
-\r
-#define GetPosSlot1(pos) p->g_FastPos[pos]\r
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r
-#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }\r
-\r
-#endif\r
-\r
-\r
-#define LZMA_NUM_REPS 4\r
-\r
-typedef unsigned CState;\r
-\r
-typedef struct\r
-{\r
-  UInt32 price;\r
-\r
-  CState state;\r
-  int prev1IsChar;\r
-  int prev2;\r
-\r
-  UInt32 posPrev2;\r
-  UInt32 backPrev2;\r
-\r
-  UInt32 posPrev;\r
-  UInt32 backPrev;\r
-  UInt32 backs[LZMA_NUM_REPS];\r
-} COptimal;\r
-\r
-#define kNumOpts (1 << 12)\r
-\r
-#define kNumLenToPosStates 4\r
-#define kNumPosSlotBits 6\r
-#define kDicLogSizeMin 0\r
-#define kDicLogSizeMax 32\r
-#define kDistTableSizeMax (kDicLogSizeMax * 2)\r
-\r
-\r
-#define kNumAlignBits 4\r
-#define kAlignTableSize (1 << kNumAlignBits)\r
-#define kAlignMask (kAlignTableSize - 1)\r
-\r
-#define kStartPosModelIndex 4\r
-#define kEndPosModelIndex 14\r
-#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)\r
-\r
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r
-\r
-#ifdef _LZMA_PROB32\r
-#define CLzmaProb UInt32\r
-#else\r
-#define CLzmaProb UInt16\r
-#endif\r
-\r
-#define LZMA_PB_MAX 4\r
-#define LZMA_LC_MAX 8\r
-#define LZMA_LP_MAX 4\r
-\r
-#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)\r
-\r
-\r
-#define kLenNumLowBits 3\r
-#define kLenNumLowSymbols (1 << kLenNumLowBits)\r
-#define kLenNumMidBits 3\r
-#define kLenNumMidSymbols (1 << kLenNumMidBits)\r
-#define kLenNumHighBits 8\r
-#define kLenNumHighSymbols (1 << kLenNumHighBits)\r
-\r
-#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r
-\r
-#define LZMA_MATCH_LEN_MIN 2\r
-#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)\r
-\r
-#define kNumStates 12\r
-\r
-\r
-typedef struct\r
-{\r
-  CLzmaProb choice;\r
-  CLzmaProb choice2;\r
-  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];\r
-  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];\r
-  CLzmaProb high[kLenNumHighSymbols];\r
-} CLenEnc;\r
-\r
-\r
-typedef struct\r
-{\r
-  CLenEnc p;\r
-  UInt32 tableSize;\r
-  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\r
-  UInt32 counters[LZMA_NUM_PB_STATES_MAX];\r
-} CLenPriceEnc;\r
-\r
-\r
-typedef struct\r
-{\r
-  UInt32 range;\r
-  Byte cache;\r
-  UInt64 low;\r
-  UInt64 cacheSize;\r
-  Byte *buf;\r
-  Byte *bufLim;\r
-  Byte *bufBase;\r
-  ISeqOutStream *outStream;\r
-  UInt64 processed;\r
-  SRes res;\r
-} CRangeEnc;\r
-\r
-\r
-typedef struct\r
-{\r
-  CLzmaProb *litProbs;\r
-\r
-  UInt32 state;\r
-  UInt32 reps[LZMA_NUM_REPS];\r
-\r
-  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r
-  CLzmaProb isRep[kNumStates];\r
-  CLzmaProb isRepG0[kNumStates];\r
-  CLzmaProb isRepG1[kNumStates];\r
-  CLzmaProb isRepG2[kNumStates];\r
-  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r
-\r
-  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r
-  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r
-  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r
-  \r
-  CLenPriceEnc lenEnc;\r
-  CLenPriceEnc repLenEnc;\r
-} CSaveState;\r
-\r
-\r
-typedef struct\r
-{\r
-  void *matchFinderObj;\r
-  IMatchFinder matchFinder;\r
-\r
-  UInt32 optimumEndIndex;\r
-  UInt32 optimumCurrentIndex;\r
-\r
-  UInt32 longestMatchLength;\r
-  UInt32 numPairs;\r
-  UInt32 numAvail;\r
-\r
-  UInt32 numFastBytes;\r
-  UInt32 additionalOffset;\r
-  UInt32 reps[LZMA_NUM_REPS];\r
-  UInt32 state;\r
-\r
-  unsigned lc, lp, pb;\r
-  unsigned lpMask, pbMask;\r
-  unsigned lclp;\r
-\r
-  CLzmaProb *litProbs;\r
-\r
-  Bool fastMode;\r
-  Bool writeEndMark;\r
-  Bool finished;\r
-  Bool multiThread;\r
-  Bool needInit;\r
-\r
-  UInt64 nowPos64;\r
-  \r
-  UInt32 matchPriceCount;\r
-  UInt32 alignPriceCount;\r
-\r
-  UInt32 distTableSize;\r
-\r
-  UInt32 dictSize;\r
-  SRes result;\r
-\r
-  CRangeEnc rc;\r
-\r
-  #ifndef _7ZIP_ST\r
-  Bool mtMode;\r
-  CMatchFinderMt matchFinderMt;\r
-  #endif\r
-\r
-  CMatchFinder matchFinderBase;\r
-\r
-  #ifndef _7ZIP_ST\r
-  Byte pad[128];\r
-  #endif\r
-  \r
-  COptimal opt[kNumOpts];\r
-  \r
-  #ifndef LZMA_LOG_BSR\r
-  Byte g_FastPos[1 << kNumLogBits];\r
-  #endif\r
-\r
-  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r
-  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];\r
-\r
-  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r
-  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];\r
-  UInt32 alignPrices[kAlignTableSize];\r
-\r
-  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r
-  CLzmaProb isRep[kNumStates];\r
-  CLzmaProb isRepG0[kNumStates];\r
-  CLzmaProb isRepG1[kNumStates];\r
-  CLzmaProb isRepG2[kNumStates];\r
-  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r
-\r
-  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r
-  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r
-  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r
-  \r
-  CLenPriceEnc lenEnc;\r
-  CLenPriceEnc repLenEnc;\r
-\r
-  CSaveState saveState;\r
-\r
-  #ifndef _7ZIP_ST\r
-  Byte pad2[128];\r
-  #endif\r
-} CLzmaEnc;\r
-\r
-\r
-void LzmaEnc_SaveState(CLzmaEncHandle pp)\r
-{\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  CSaveState *dest = &p->saveState;\r
-  int i;\r
-  dest->lenEnc = p->lenEnc;\r
-  dest->repLenEnc = p->repLenEnc;\r
-  dest->state = p->state;\r
-\r
-  for (i = 0; i < kNumStates; i++)\r
-  {\r
-    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r
-    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r
-  }\r
-  for (i = 0; i < kNumLenToPosStates; i++)\r
-    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r
-  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r
-  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r
-  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r
-  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r
-  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r
-  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r
-  memcpy(dest->reps, p->reps, sizeof(p->reps));\r
-  memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << p->lclp) * sizeof(CLzmaProb));\r
-}\r
-\r
-void LzmaEnc_RestoreState(CLzmaEncHandle pp)\r
-{\r
-  CLzmaEnc *dest = (CLzmaEnc *)pp;\r
-  const CSaveState *p = &dest->saveState;\r
-  int i;\r
-  dest->lenEnc = p->lenEnc;\r
-  dest->repLenEnc = p->repLenEnc;\r
-  dest->state = p->state;\r
-\r
-  for (i = 0; i < kNumStates; i++)\r
-  {\r
-    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r
-    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r
-  }\r
-  for (i = 0; i < kNumLenToPosStates; i++)\r
-    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r
-  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r
-  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r
-  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r
-  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r
-  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r
-  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r
-  memcpy(dest->reps, p->reps, sizeof(p->reps));\r
-  memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << dest->lclp) * sizeof(CLzmaProb));\r
-}\r
-\r
-SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)\r
-{\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  CLzmaEncProps props = *props2;\r
-  LzmaEncProps_Normalize(&props);\r
-\r
-  if (props.lc > LZMA_LC_MAX\r
-      || props.lp > LZMA_LP_MAX\r
-      || props.pb > LZMA_PB_MAX\r
-      || props.dictSize > ((UInt64)1 << kDicLogSizeMaxCompress)\r
-      || props.dictSize > kMaxHistorySize)\r
-    return SZ_ERROR_PARAM;\r
-\r
-  p->dictSize = props.dictSize;\r
-  {\r
-    unsigned fb = props.fb;\r
-    if (fb < 5)\r
-      fb = 5;\r
-    if (fb > LZMA_MATCH_LEN_MAX)\r
-      fb = LZMA_MATCH_LEN_MAX;\r
-    p->numFastBytes = fb;\r
-  }\r
-  p->lc = props.lc;\r
-  p->lp = props.lp;\r
-  p->pb = props.pb;\r
-  p->fastMode = (props.algo == 0);\r
-  p->matchFinderBase.btMode = (Byte)(props.btMode ? 1 : 0);\r
-  {\r
-    UInt32 numHashBytes = 4;\r
-    if (props.btMode)\r
-    {\r
-      if (props.numHashBytes < 2)\r
-        numHashBytes = 2;\r
-      else if (props.numHashBytes < 4)\r
-        numHashBytes = props.numHashBytes;\r
-    }\r
-    p->matchFinderBase.numHashBytes = numHashBytes;\r
-  }\r
-\r
-  p->matchFinderBase.cutValue = props.mc;\r
-\r
-  p->writeEndMark = props.writeEndMark;\r
-\r
-  #ifndef _7ZIP_ST\r
-  /*\r
-  if (newMultiThread != _multiThread)\r
-  {\r
-    ReleaseMatchFinder();\r
-    _multiThread = newMultiThread;\r
-  }\r
-  */\r
-  p->multiThread = (props.numThreads > 1);\r
-  #endif\r
-\r
-  return SZ_OK;\r
-}\r
-\r
-static const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r
-static const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r
-static const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r
-static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r
-\r
-#define IsCharState(s) ((s) < 7)\r
-\r
-#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)\r
-\r
-#define kInfinityPrice (1 << 30)\r
-\r
-static void RangeEnc_Construct(CRangeEnc *p)\r
-{\r
-  p->outStream = NULL;\r
-  p->bufBase = NULL;\r
-}\r
-\r
-#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)\r
-\r
-#define RC_BUF_SIZE (1 << 16)\r
-static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)\r
-{\r
-  if (!p->bufBase)\r
-  {\r
-    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);\r
-    if (!p->bufBase)\r
-      return 0;\r
-    p->bufLim = p->bufBase + RC_BUF_SIZE;\r
-  }\r
-  return 1;\r
-}\r
-\r
-static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->bufBase);\r
-  p->bufBase = 0;\r
-}\r
-\r
-static void RangeEnc_Init(CRangeEnc *p)\r
-{\r
-  /* Stream.Init(); */\r
-  p->low = 0;\r
-  p->range = 0xFFFFFFFF;\r
-  p->cacheSize = 1;\r
-  p->cache = 0;\r
-\r
-  p->buf = p->bufBase;\r
-\r
-  p->processed = 0;\r
-  p->res = SZ_OK;\r
-}\r
-\r
-static void RangeEnc_FlushStream(CRangeEnc *p)\r
-{\r
-  size_t num;\r
-  if (p->res != SZ_OK)\r
-    return;\r
-  num = p->buf - p->bufBase;\r
-  if (num != p->outStream->Write(p->outStream, p->bufBase, num))\r
-    p->res = SZ_ERROR_WRITE;\r
-  p->processed += num;\r
-  p->buf = p->bufBase;\r
-}\r
-\r
-static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)\r
-{\r
-  if ((UInt32)p->low < (UInt32)0xFF000000 || (unsigned)(p->low >> 32) != 0)\r
-  {\r
-    Byte temp = p->cache;\r
-    do\r
-    {\r
-      Byte *buf = p->buf;\r
-      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));\r
-      p->buf = buf;\r
-      if (buf == p->bufLim)\r
-        RangeEnc_FlushStream(p);\r
-      temp = 0xFF;\r
-    }\r
-    while (--p->cacheSize != 0);\r
-    p->cache = (Byte)((UInt32)p->low >> 24);\r
-  }\r
-  p->cacheSize++;\r
-  p->low = (UInt32)p->low << 8;\r
-}\r
-\r
-static void RangeEnc_FlushData(CRangeEnc *p)\r
-{\r
-  int i;\r
-  for (i = 0; i < 5; i++)\r
-    RangeEnc_ShiftLow(p);\r
-}\r
-\r
-static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, unsigned numBits)\r
-{\r
-  do\r
-  {\r
-    p->range >>= 1;\r
-    p->low += p->range & (0 - ((value >> --numBits) & 1));\r
-    if (p->range < kTopValue)\r
-    {\r
-      p->range <<= 8;\r
-      RangeEnc_ShiftLow(p);\r
-    }\r
-  }\r
-  while (numBits != 0);\r
-}\r
-\r
-static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)\r
-{\r
-  UInt32 ttt = *prob;\r
-  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;\r
-  if (symbol == 0)\r
-  {\r
-    p->range = newBound;\r
-    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;\r
-  }\r
-  else\r
-  {\r
-    p->low += newBound;\r
-    p->range -= newBound;\r
-    ttt -= ttt >> kNumMoveBits;\r
-  }\r
-  *prob = (CLzmaProb)ttt;\r
-  if (p->range < kTopValue)\r
-  {\r
-    p->range <<= 8;\r
-    RangeEnc_ShiftLow(p);\r
-  }\r
-}\r
-\r
-static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)\r
-{\r
-  symbol |= 0x100;\r
-  do\r
-  {\r
-    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);\r
-    symbol <<= 1;\r
-  }\r
-  while (symbol < 0x10000);\r
-}\r
-\r
-static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)\r
-{\r
-  UInt32 offs = 0x100;\r
-  symbol |= 0x100;\r
-  do\r
-  {\r
-    matchByte <<= 1;\r
-    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);\r
-    symbol <<= 1;\r
-    offs &= ~(matchByte ^ symbol);\r
-  }\r
-  while (symbol < 0x10000);\r
-}\r
-\r
-static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\r
-{\r
-  UInt32 i;\r
-  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))\r
-  {\r
-    const int kCyclesBits = kNumBitPriceShiftBits;\r
-    UInt32 w = i;\r
-    UInt32 bitCount = 0;\r
-    int j;\r
-    for (j = 0; j < kCyclesBits; j++)\r
-    {\r
-      w = w * w;\r
-      bitCount <<= 1;\r
-      while (w >= ((UInt32)1 << 16))\r
-      {\r
-        w >>= 1;\r
-        bitCount++;\r
-      }\r
-    }\r
-    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);\r
-  }\r
-}\r
-\r
-\r
-#define GET_PRICE(prob, symbol) \\r
-  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r
-\r
-#define GET_PRICEa(prob, symbol) \\r
-  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r
-\r
-#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]\r
-#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r
-\r
-#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]\r
-#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r
-\r
-static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, const UInt32 *ProbPrices)\r
-{\r
-  UInt32 price = 0;\r
-  symbol |= 0x100;\r
-  do\r
-  {\r
-    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);\r
-    symbol <<= 1;\r
-  }\r
-  while (symbol < 0x10000);\r
-  return price;\r
-}\r
-\r
-static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, const UInt32 *ProbPrices)\r
-{\r
-  UInt32 price = 0;\r
-  UInt32 offs = 0x100;\r
-  symbol |= 0x100;\r
-  do\r
-  {\r
-    matchByte <<= 1;\r
-    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);\r
-    symbol <<= 1;\r
-    offs &= ~(matchByte ^ symbol);\r
-  }\r
-  while (symbol < 0x10000);\r
-  return price;\r
-}\r
-\r
-\r
-static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r
-{\r
-  UInt32 m = 1;\r
-  int i;\r
-  for (i = numBitLevels; i != 0;)\r
-  {\r
-    UInt32 bit;\r
-    i--;\r
-    bit = (symbol >> i) & 1;\r
-    RangeEnc_EncodeBit(rc, probs + m, bit);\r
-    m = (m << 1) | bit;\r
-  }\r
-}\r
-\r
-static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r
-{\r
-  UInt32 m = 1;\r
-  int i;\r
-  for (i = 0; i < numBitLevels; i++)\r
-  {\r
-    UInt32 bit = symbol & 1;\r
-    RangeEnc_EncodeBit(rc, probs + m, bit);\r
-    m = (m << 1) | bit;\r
-    symbol >>= 1;\r
-  }\r
-}\r
-\r
-static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, const UInt32 *ProbPrices)\r
-{\r
-  UInt32 price = 0;\r
-  symbol |= (1 << numBitLevels);\r
-  while (symbol != 1)\r
-  {\r
-    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);\r
-    symbol >>= 1;\r
-  }\r
-  return price;\r
-}\r
-\r
-static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, const UInt32 *ProbPrices)\r
-{\r
-  UInt32 price = 0;\r
-  UInt32 m = 1;\r
-  int i;\r
-  for (i = numBitLevels; i != 0; i--)\r
-  {\r
-    UInt32 bit = symbol & 1;\r
-    symbol >>= 1;\r
-    price += GET_PRICEa(probs[m], bit);\r
-    m = (m << 1) | bit;\r
-  }\r
-  return price;\r
-}\r
-\r
-\r
-static void LenEnc_Init(CLenEnc *p)\r
-{\r
-  unsigned i;\r
-  p->choice = p->choice2 = kProbInitValue;\r
-  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)\r
-    p->low[i] = kProbInitValue;\r
-  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)\r
-    p->mid[i] = kProbInitValue;\r
-  for (i = 0; i < kLenNumHighSymbols; i++)\r
-    p->high[i] = kProbInitValue;\r
-}\r
-\r
-static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)\r
-{\r
-  if (symbol < kLenNumLowSymbols)\r
-  {\r
-    RangeEnc_EncodeBit(rc, &p->choice, 0);\r
-    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);\r
-  }\r
-  else\r
-  {\r
-    RangeEnc_EncodeBit(rc, &p->choice, 1);\r
-    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)\r
-    {\r
-      RangeEnc_EncodeBit(rc, &p->choice2, 0);\r
-      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);\r
-    }\r
-    else\r
-    {\r
-      RangeEnc_EncodeBit(rc, &p->choice2, 1);\r
-      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);\r
-    }\r
-  }\r
-}\r
-\r
-static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, const UInt32 *ProbPrices)\r
-{\r
-  UInt32 a0 = GET_PRICE_0a(p->choice);\r
-  UInt32 a1 = GET_PRICE_1a(p->choice);\r
-  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);\r
-  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);\r
-  UInt32 i = 0;\r
-  for (i = 0; i < kLenNumLowSymbols; i++)\r
-  {\r
-    if (i >= numSymbols)\r
-      return;\r
-    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);\r
-  }\r
-  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)\r
-  {\r
-    if (i >= numSymbols)\r
-      return;\r
-    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);\r
-  }\r
-  for (; i < numSymbols; i++)\r
-    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);\r
-}\r
-\r
-static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, const UInt32 *ProbPrices)\r
-{\r
-  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);\r
-  p->counters[posState] = p->tableSize;\r
-}\r
-\r
-static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, const UInt32 *ProbPrices)\r
-{\r
-  UInt32 posState;\r
-  for (posState = 0; posState < numPosStates; posState++)\r
-    LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r
-}\r
-\r
-static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, const UInt32 *ProbPrices)\r
-{\r
-  LenEnc_Encode(&p->p, rc, symbol, posState);\r
-  if (updatePrice)\r
-    if (--p->counters[posState] == 0)\r
-      LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r
-}\r
-\r
-\r
-\r
-\r
-static void MovePos(CLzmaEnc *p, UInt32 num)\r
-{\r
-  #ifdef SHOW_STAT\r
-  g_STAT_OFFSET += num;\r
-  printf("\n MovePos %u", num);\r
-  #endif\r
-  \r
-  if (num != 0)\r
-  {\r
-    p->additionalOffset += num;\r
-    p->matchFinder.Skip(p->matchFinderObj, num);\r
-  }\r
-}\r
-\r
-static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)\r
-{\r
-  UInt32 lenRes = 0, numPairs;\r
-  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r
-  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);\r
-  \r
-  #ifdef SHOW_STAT\r
-  printf("\n i = %u numPairs = %u    ", g_STAT_OFFSET, numPairs / 2);\r
-  g_STAT_OFFSET++;\r
-  {\r
-    UInt32 i;\r
-    for (i = 0; i < numPairs; i += 2)\r
-      printf("%2u %6u   | ", p->matches[i], p->matches[i + 1]);\r
-  }\r
-  #endif\r
-  \r
-  if (numPairs > 0)\r
-  {\r
-    lenRes = p->matches[numPairs - 2];\r
-    if (lenRes == p->numFastBytes)\r
-    {\r
-      UInt32 numAvail = p->numAvail;\r
-      if (numAvail > LZMA_MATCH_LEN_MAX)\r
-        numAvail = LZMA_MATCH_LEN_MAX;\r
-      {\r
-        const Byte *pbyCur = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r
-        const Byte *pby = pbyCur + lenRes;\r
-        ptrdiff_t dif = (ptrdiff_t)-1 - p->matches[numPairs - 1];\r
-        const Byte *pbyLim = pbyCur + numAvail;\r
-        for (; pby != pbyLim && *pby == pby[dif]; pby++);\r
-        lenRes = (UInt32)(pby - pbyCur);\r
-      }\r
-    }\r
-  }\r
-  p->additionalOffset++;\r
-  *numDistancePairsRes = numPairs;\r
-  return lenRes;\r
-}\r
-\r
-\r
-#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;\r
-#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;\r
-#define IsShortRep(p) ((p)->backPrev == 0)\r
-\r
-static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)\r
-{\r
-  return\r
-    GET_PRICE_0(p->isRepG0[state]) +\r
-    GET_PRICE_0(p->isRep0Long[state][posState]);\r
-}\r
-\r
-static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)\r
-{\r
-  UInt32 price;\r
-  if (repIndex == 0)\r
-  {\r
-    price = GET_PRICE_0(p->isRepG0[state]);\r
-    price += GET_PRICE_1(p->isRep0Long[state][posState]);\r
-  }\r
-  else\r
-  {\r
-    price = GET_PRICE_1(p->isRepG0[state]);\r
-    if (repIndex == 1)\r
-      price += GET_PRICE_0(p->isRepG1[state]);\r
-    else\r
-    {\r
-      price += GET_PRICE_1(p->isRepG1[state]);\r
-      price += GET_PRICE(p->isRepG2[state], repIndex - 2);\r
-    }\r
-  }\r
-  return price;\r
-}\r
-\r
-static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)\r
-{\r
-  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +\r
-    GetPureRepPrice(p, repIndex, state, posState);\r
-}\r
-\r
-static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)\r
-{\r
-  UInt32 posMem = p->opt[cur].posPrev;\r
-  UInt32 backMem = p->opt[cur].backPrev;\r
-  p->optimumEndIndex = cur;\r
-  do\r
-  {\r
-    if (p->opt[cur].prev1IsChar)\r
-    {\r
-      MakeAsChar(&p->opt[posMem])\r
-      p->opt[posMem].posPrev = posMem - 1;\r
-      if (p->opt[cur].prev2)\r
-      {\r
-        p->opt[posMem - 1].prev1IsChar = False;\r
-        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;\r
-        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;\r
-      }\r
-    }\r
-    {\r
-      UInt32 posPrev = posMem;\r
-      UInt32 backCur = backMem;\r
-      \r
-      backMem = p->opt[posPrev].backPrev;\r
-      posMem = p->opt[posPrev].posPrev;\r
-      \r
-      p->opt[posPrev].backPrev = backCur;\r
-      p->opt[posPrev].posPrev = cur;\r
-      cur = posPrev;\r
-    }\r
-  }\r
-  while (cur != 0);\r
-  *backRes = p->opt[0].backPrev;\r
-  p->optimumCurrentIndex  = p->opt[0].posPrev;\r
-  return p->optimumCurrentIndex;\r
-}\r
-\r
-#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * (UInt32)0x300)\r
-\r
-static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)\r
-{\r
-  UInt32 lenEnd, cur;\r
-  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];\r
-  UInt32 *matches;\r
-\r
-  {\r
-\r
-  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, len;\r
-  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\r
-  const Byte *data;\r
-  Byte curByte, matchByte;\r
-\r
-  if (p->optimumEndIndex != p->optimumCurrentIndex)\r
-  {\r
-    const COptimal *opt = &p->opt[p->optimumCurrentIndex];\r
-    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;\r
-    *backRes = opt->backPrev;\r
-    p->optimumCurrentIndex = opt->posPrev;\r
-    return lenRes;\r
-  }\r
-  p->optimumCurrentIndex = p->optimumEndIndex = 0;\r
-  \r
-  if (p->additionalOffset == 0)\r
-    mainLen = ReadMatchDistances(p, &numPairs);\r
-  else\r
-  {\r
-    mainLen = p->longestMatchLength;\r
-    numPairs = p->numPairs;\r
-  }\r
-\r
-  numAvail = p->numAvail;\r
-  if (numAvail < 2)\r
-  {\r
-    *backRes = (UInt32)(-1);\r
-    return 1;\r
-  }\r
-  if (numAvail > LZMA_MATCH_LEN_MAX)\r
-    numAvail = LZMA_MATCH_LEN_MAX;\r
-\r
-  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r
-  repMaxIndex = 0;\r
-  for (i = 0; i < LZMA_NUM_REPS; i++)\r
-  {\r
-    UInt32 lenTest;\r
-    const Byte *data2;\r
-    reps[i] = p->reps[i];\r
-    data2 = data - reps[i] - 1;\r
-    if (data[0] != data2[0] || data[1] != data2[1])\r
-    {\r
-      repLens[i] = 0;\r
-      continue;\r
-    }\r
-    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r
-    repLens[i] = lenTest;\r
-    if (lenTest > repLens[repMaxIndex])\r
-      repMaxIndex = i;\r
-  }\r
-  if (repLens[repMaxIndex] >= p->numFastBytes)\r
-  {\r
-    UInt32 lenRes;\r
-    *backRes = repMaxIndex;\r
-    lenRes = repLens[repMaxIndex];\r
-    MovePos(p, lenRes - 1);\r
-    return lenRes;\r
-  }\r
-\r
-  matches = p->matches;\r
-  if (mainLen >= p->numFastBytes)\r
-  {\r
-    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r
-    MovePos(p, mainLen - 1);\r
-    return mainLen;\r
-  }\r
-  curByte = *data;\r
-  matchByte = *(data - (reps[0] + 1));\r
-\r
-  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)\r
-  {\r
-    *backRes = (UInt32)-1;\r
-    return 1;\r
-  }\r
-\r
-  p->opt[0].state = (CState)p->state;\r
-\r
-  posState = (position & p->pbMask);\r
-\r
-  {\r
-    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r
-    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +\r
-        (!IsCharState(p->state) ?\r
-          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r
-          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r
-  }\r
-\r
-  MakeAsChar(&p->opt[1]);\r
-\r
-  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);\r
-  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);\r
-\r
-  if (matchByte == curByte)\r
-  {\r
-    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);\r
-    if (shortRepPrice < p->opt[1].price)\r
-    {\r
-      p->opt[1].price = shortRepPrice;\r
-      MakeAsShortRep(&p->opt[1]);\r
-    }\r
-  }\r
-  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);\r
-\r
-  if (lenEnd < 2)\r
-  {\r
-    *backRes = p->opt[1].backPrev;\r
-    return 1;\r
-  }\r
-\r
-  p->opt[1].posPrev = 0;\r
-  for (i = 0; i < LZMA_NUM_REPS; i++)\r
-    p->opt[0].backs[i] = reps[i];\r
-\r
-  len = lenEnd;\r
-  do\r
-    p->opt[len--].price = kInfinityPrice;\r
-  while (len >= 2);\r
-\r
-  for (i = 0; i < LZMA_NUM_REPS; i++)\r
-  {\r
-    UInt32 repLen = repLens[i];\r
-    UInt32 price;\r
-    if (repLen < 2)\r
-      continue;\r
-    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);\r
-    do\r
-    {\r
-      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];\r
-      COptimal *opt = &p->opt[repLen];\r
-      if (curAndLenPrice < opt->price)\r
-      {\r
-        opt->price = curAndLenPrice;\r
-        opt->posPrev = 0;\r
-        opt->backPrev = i;\r
-        opt->prev1IsChar = False;\r
-      }\r
-    }\r
-    while (--repLen >= 2);\r
-  }\r
-\r
-  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);\r
-\r
-  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r
-  if (len <= mainLen)\r
-  {\r
-    UInt32 offs = 0;\r
-    while (len > matches[offs])\r
-      offs += 2;\r
-    for (; ; len++)\r
-    {\r
-      COptimal *opt;\r
-      UInt32 distance = matches[offs + 1];\r
-\r
-      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];\r
-      UInt32 lenToPosState = GetLenToPosState(len);\r
-      if (distance < kNumFullDistances)\r
-        curAndLenPrice += p->distancesPrices[lenToPosState][distance];\r
-      else\r
-      {\r
-        UInt32 slot;\r
-        GetPosSlot2(distance, slot);\r
-        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];\r
-      }\r
-      opt = &p->opt[len];\r
-      if (curAndLenPrice < opt->price)\r
-      {\r
-        opt->price = curAndLenPrice;\r
-        opt->posPrev = 0;\r
-        opt->backPrev = distance + LZMA_NUM_REPS;\r
-        opt->prev1IsChar = False;\r
-      }\r
-      if (len == matches[offs])\r
-      {\r
-        offs += 2;\r
-        if (offs == numPairs)\r
-          break;\r
-      }\r
-    }\r
-  }\r
-\r
-  cur = 0;\r
-\r
-    #ifdef SHOW_STAT2\r
-    /* if (position >= 0) */\r
-    {\r
-      unsigned i;\r
-      printf("\n pos = %4X", position);\r
-      for (i = cur; i <= lenEnd; i++)\r
-      printf("\nprice[%4X] = %u", position - cur + i, p->opt[i].price);\r
-    }\r
-    #endif\r
-\r
-  }\r
-\r
-  for (;;)\r
-  {\r
-    UInt32 numAvail;\r
-    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;\r
-    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;\r
-    Bool nextIsChar;\r
-    Byte curByte, matchByte;\r
-    const Byte *data;\r
-    COptimal *curOpt;\r
-    COptimal *nextOpt;\r
-\r
-    cur++;\r
-    if (cur == lenEnd)\r
-      return Backward(p, backRes, cur);\r
-\r
-    newLen = ReadMatchDistances(p, &numPairs);\r
-    if (newLen >= p->numFastBytes)\r
-    {\r
-      p->numPairs = numPairs;\r
-      p->longestMatchLength = newLen;\r
-      return Backward(p, backRes, cur);\r
-    }\r
-    position++;\r
-    curOpt = &p->opt[cur];\r
-    posPrev = curOpt->posPrev;\r
-    if (curOpt->prev1IsChar)\r
-    {\r
-      posPrev--;\r
-      if (curOpt->prev2)\r
-      {\r
-        state = p->opt[curOpt->posPrev2].state;\r
-        if (curOpt->backPrev2 < LZMA_NUM_REPS)\r
-          state = kRepNextStates[state];\r
-        else\r
-          state = kMatchNextStates[state];\r
-      }\r
-      else\r
-        state = p->opt[posPrev].state;\r
-      state = kLiteralNextStates[state];\r
-    }\r
-    else\r
-      state = p->opt[posPrev].state;\r
-    if (posPrev == cur - 1)\r
-    {\r
-      if (IsShortRep(curOpt))\r
-        state = kShortRepNextStates[state];\r
-      else\r
-        state = kLiteralNextStates[state];\r
-    }\r
-    else\r
-    {\r
-      UInt32 pos;\r
-      const COptimal *prevOpt;\r
-      if (curOpt->prev1IsChar && curOpt->prev2)\r
-      {\r
-        posPrev = curOpt->posPrev2;\r
-        pos = curOpt->backPrev2;\r
-        state = kRepNextStates[state];\r
-      }\r
-      else\r
-      {\r
-        pos = curOpt->backPrev;\r
-        if (pos < LZMA_NUM_REPS)\r
-          state = kRepNextStates[state];\r
-        else\r
-          state = kMatchNextStates[state];\r
-      }\r
-      prevOpt = &p->opt[posPrev];\r
-      if (pos < LZMA_NUM_REPS)\r
-      {\r
-        UInt32 i;\r
-        reps[0] = prevOpt->backs[pos];\r
-        for (i = 1; i <= pos; i++)\r
-          reps[i] = prevOpt->backs[i - 1];\r
-        for (; i < LZMA_NUM_REPS; i++)\r
-          reps[i] = prevOpt->backs[i];\r
-      }\r
-      else\r
-      {\r
-        UInt32 i;\r
-        reps[0] = (pos - LZMA_NUM_REPS);\r
-        for (i = 1; i < LZMA_NUM_REPS; i++)\r
-          reps[i] = prevOpt->backs[i - 1];\r
-      }\r
-    }\r
-    curOpt->state = (CState)state;\r
-\r
-    curOpt->backs[0] = reps[0];\r
-    curOpt->backs[1] = reps[1];\r
-    curOpt->backs[2] = reps[2];\r
-    curOpt->backs[3] = reps[3];\r
-\r
-    curPrice = curOpt->price;\r
-    nextIsChar = False;\r
-    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r
-    curByte = *data;\r
-    matchByte = *(data - (reps[0] + 1));\r
-\r
-    posState = (position & p->pbMask);\r
-\r
-    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);\r
-    {\r
-      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r
-      curAnd1Price +=\r
-        (!IsCharState(state) ?\r
-          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r
-          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r
-    }\r
-\r
-    nextOpt = &p->opt[cur + 1];\r
-\r
-    if (curAnd1Price < nextOpt->price)\r
-    {\r
-      nextOpt->price = curAnd1Price;\r
-      nextOpt->posPrev = cur;\r
-      MakeAsChar(nextOpt);\r
-      nextIsChar = True;\r
-    }\r
-\r
-    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);\r
-    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);\r
-    \r
-    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))\r
-    {\r
-      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);\r
-      if (shortRepPrice <= nextOpt->price)\r
-      {\r
-        nextOpt->price = shortRepPrice;\r
-        nextOpt->posPrev = cur;\r
-        MakeAsShortRep(nextOpt);\r
-        nextIsChar = True;\r
-      }\r
-    }\r
-    numAvailFull = p->numAvail;\r
-    {\r
-      UInt32 temp = kNumOpts - 1 - cur;\r
-      if (temp < numAvailFull)\r
-        numAvailFull = temp;\r
-    }\r
-\r
-    if (numAvailFull < 2)\r
-      continue;\r
-    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);\r
-\r
-    if (!nextIsChar && matchByte != curByte) /* speed optimization */\r
-    {\r
-      /* try Literal + rep0 */\r
-      UInt32 temp;\r
-      UInt32 lenTest2;\r
-      const Byte *data2 = data - reps[0] - 1;\r
-      UInt32 limit = p->numFastBytes + 1;\r
-      if (limit > numAvailFull)\r
-        limit = numAvailFull;\r
-\r
-      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r
-      lenTest2 = temp - 1;\r
-      if (lenTest2 >= 2)\r
-      {\r
-        UInt32 state2 = kLiteralNextStates[state];\r
-        UInt32 posStateNext = (position + 1) & p->pbMask;\r
-        UInt32 nextRepMatchPrice = curAnd1Price +\r
-            GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r
-            GET_PRICE_1(p->isRep[state2]);\r
-        /* for (; lenTest2 >= 2; lenTest2--) */\r
-        {\r
-          UInt32 curAndLenPrice;\r
-          COptimal *opt;\r
-          UInt32 offset = cur + 1 + lenTest2;\r
-          while (lenEnd < offset)\r
-            p->opt[++lenEnd].price = kInfinityPrice;\r
-          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r
-          opt = &p->opt[offset];\r
-          if (curAndLenPrice < opt->price)\r
-          {\r
-            opt->price = curAndLenPrice;\r
-            opt->posPrev = cur + 1;\r
-            opt->backPrev = 0;\r
-            opt->prev1IsChar = True;\r
-            opt->prev2 = False;\r
-          }\r
-        }\r
-      }\r
-    }\r
-    \r
-    startLen = 2; /* speed optimization */\r
-    {\r
-    UInt32 repIndex;\r
-    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)\r
-    {\r
-      UInt32 lenTest;\r
-      UInt32 lenTestTemp;\r
-      UInt32 price;\r
-      const Byte *data2 = data - reps[repIndex] - 1;\r
-      if (data[0] != data2[0] || data[1] != data2[1])\r
-        continue;\r
-      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r
-      while (lenEnd < cur + lenTest)\r
-        p->opt[++lenEnd].price = kInfinityPrice;\r
-      lenTestTemp = lenTest;\r
-      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);\r
-      do\r
-      {\r
-        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];\r
-        COptimal *opt = &p->opt[cur + lenTest];\r
-        if (curAndLenPrice < opt->price)\r
-        {\r
-          opt->price = curAndLenPrice;\r
-          opt->posPrev = cur;\r
-          opt->backPrev = repIndex;\r
-          opt->prev1IsChar = False;\r
-        }\r
-      }\r
-      while (--lenTest >= 2);\r
-      lenTest = lenTestTemp;\r
-      \r
-      if (repIndex == 0)\r
-        startLen = lenTest + 1;\r
-        \r
-      /* if (_maxMode) */\r
-        {\r
-          UInt32 lenTest2 = lenTest + 1;\r
-          UInt32 limit = lenTest2 + p->numFastBytes;\r
-          if (limit > numAvailFull)\r
-            limit = numAvailFull;\r
-          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r
-          lenTest2 -= lenTest + 1;\r
-          if (lenTest2 >= 2)\r
-          {\r
-            UInt32 nextRepMatchPrice;\r
-            UInt32 state2 = kRepNextStates[state];\r
-            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r
-            UInt32 curAndLenCharPrice =\r
-                price + p->repLenEnc.prices[posState][lenTest - 2] +\r
-                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r
-                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r
-                    data[lenTest], data2[lenTest], p->ProbPrices);\r
-            state2 = kLiteralNextStates[state2];\r
-            posStateNext = (position + lenTest + 1) & p->pbMask;\r
-            nextRepMatchPrice = curAndLenCharPrice +\r
-                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r
-                GET_PRICE_1(p->isRep[state2]);\r
-            \r
-            /* for (; lenTest2 >= 2; lenTest2--) */\r
-            {\r
-              UInt32 curAndLenPrice;\r
-              COptimal *opt;\r
-              UInt32 offset = cur + lenTest + 1 + lenTest2;\r
-              while (lenEnd < offset)\r
-                p->opt[++lenEnd].price = kInfinityPrice;\r
-              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r
-              opt = &p->opt[offset];\r
-              if (curAndLenPrice < opt->price)\r
-              {\r
-                opt->price = curAndLenPrice;\r
-                opt->posPrev = cur + lenTest + 1;\r
-                opt->backPrev = 0;\r
-                opt->prev1IsChar = True;\r
-                opt->prev2 = True;\r
-                opt->posPrev2 = cur;\r
-                opt->backPrev2 = repIndex;\r
-              }\r
-            }\r
-          }\r
-        }\r
-    }\r
-    }\r
-    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */\r
-    if (newLen > numAvail)\r
-    {\r
-      newLen = numAvail;\r
-      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);\r
-      matches[numPairs] = newLen;\r
-      numPairs += 2;\r
-    }\r
-    if (newLen >= startLen)\r
-    {\r
-      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\r
-      UInt32 offs, curBack, posSlot;\r
-      UInt32 lenTest;\r
-      while (lenEnd < cur + newLen)\r
-        p->opt[++lenEnd].price = kInfinityPrice;\r
-\r
-      offs = 0;\r
-      while (startLen > matches[offs])\r
-        offs += 2;\r
-      curBack = matches[offs + 1];\r
-      GetPosSlot2(curBack, posSlot);\r
-      for (lenTest = /*2*/ startLen; ; lenTest++)\r
-      {\r
-        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\r
-        {\r
-        UInt32 lenToPosState = GetLenToPosState(lenTest);\r
-        COptimal *opt;\r
-        if (curBack < kNumFullDistances)\r
-          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];\r
-        else\r
-          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];\r
-        \r
-        opt = &p->opt[cur + lenTest];\r
-        if (curAndLenPrice < opt->price)\r
-        {\r
-          opt->price = curAndLenPrice;\r
-          opt->posPrev = cur;\r
-          opt->backPrev = curBack + LZMA_NUM_REPS;\r
-          opt->prev1IsChar = False;\r
-        }\r
-        }\r
-\r
-        if (/*_maxMode && */lenTest == matches[offs])\r
-        {\r
-          /* Try Match + Literal + Rep0 */\r
-          const Byte *data2 = data - curBack - 1;\r
-          UInt32 lenTest2 = lenTest + 1;\r
-          UInt32 limit = lenTest2 + p->numFastBytes;\r
-          if (limit > numAvailFull)\r
-            limit = numAvailFull;\r
-          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r
-          lenTest2 -= lenTest + 1;\r
-          if (lenTest2 >= 2)\r
-          {\r
-            UInt32 nextRepMatchPrice;\r
-            UInt32 state2 = kMatchNextStates[state];\r
-            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r
-            UInt32 curAndLenCharPrice = curAndLenPrice +\r
-                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r
-                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r
-                    data[lenTest], data2[lenTest], p->ProbPrices);\r
-            state2 = kLiteralNextStates[state2];\r
-            posStateNext = (posStateNext + 1) & p->pbMask;\r
-            nextRepMatchPrice = curAndLenCharPrice +\r
-                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r
-                GET_PRICE_1(p->isRep[state2]);\r
-            \r
-            /* for (; lenTest2 >= 2; lenTest2--) */\r
-            {\r
-              UInt32 offset = cur + lenTest + 1 + lenTest2;\r
-              UInt32 curAndLenPrice2;\r
-              COptimal *opt;\r
-              while (lenEnd < offset)\r
-                p->opt[++lenEnd].price = kInfinityPrice;\r
-              curAndLenPrice2 = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r
-              opt = &p->opt[offset];\r
-              if (curAndLenPrice2 < opt->price)\r
-              {\r
-                opt->price = curAndLenPrice2;\r
-                opt->posPrev = cur + lenTest + 1;\r
-                opt->backPrev = 0;\r
-                opt->prev1IsChar = True;\r
-                opt->prev2 = True;\r
-                opt->posPrev2 = cur;\r
-                opt->backPrev2 = curBack + LZMA_NUM_REPS;\r
-              }\r
-            }\r
-          }\r
-          offs += 2;\r
-          if (offs == numPairs)\r
-            break;\r
-          curBack = matches[offs + 1];\r
-          if (curBack >= kNumFullDistances)\r
-            GetPosSlot2(curBack, posSlot);\r
-        }\r
-      }\r
-    }\r
-  }\r
-}\r
-\r
-#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))\r
-\r
-static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)\r
-{\r
-  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;\r
-  const Byte *data;\r
-  const UInt32 *matches;\r
-\r
-  if (p->additionalOffset == 0)\r
-    mainLen = ReadMatchDistances(p, &numPairs);\r
-  else\r
-  {\r
-    mainLen = p->longestMatchLength;\r
-    numPairs = p->numPairs;\r
-  }\r
-\r
-  numAvail = p->numAvail;\r
-  *backRes = (UInt32)-1;\r
-  if (numAvail < 2)\r
-    return 1;\r
-  if (numAvail > LZMA_MATCH_LEN_MAX)\r
-    numAvail = LZMA_MATCH_LEN_MAX;\r
-  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r
-\r
-  repLen = repIndex = 0;\r
-  for (i = 0; i < LZMA_NUM_REPS; i++)\r
-  {\r
-    UInt32 len;\r
-    const Byte *data2 = data - p->reps[i] - 1;\r
-    if (data[0] != data2[0] || data[1] != data2[1])\r
-      continue;\r
-    for (len = 2; len < numAvail && data[len] == data2[len]; len++);\r
-    if (len >= p->numFastBytes)\r
-    {\r
-      *backRes = i;\r
-      MovePos(p, len - 1);\r
-      return len;\r
-    }\r
-    if (len > repLen)\r
-    {\r
-      repIndex = i;\r
-      repLen = len;\r
-    }\r
-  }\r
-\r
-  matches = p->matches;\r
-  if (mainLen >= p->numFastBytes)\r
-  {\r
-    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r
-    MovePos(p, mainLen - 1);\r
-    return mainLen;\r
-  }\r
-\r
-  mainDist = 0; /* for GCC */\r
-  if (mainLen >= 2)\r
-  {\r
-    mainDist = matches[numPairs - 1];\r
-    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)\r
-    {\r
-      if (!ChangePair(matches[numPairs - 3], mainDist))\r
-        break;\r
-      numPairs -= 2;\r
-      mainLen = matches[numPairs - 2];\r
-      mainDist = matches[numPairs - 1];\r
-    }\r
-    if (mainLen == 2 && mainDist >= 0x80)\r
-      mainLen = 1;\r
-  }\r
-\r
-  if (repLen >= 2 && (\r
-        (repLen + 1 >= mainLen) ||\r
-        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||\r
-        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))\r
-  {\r
-    *backRes = repIndex;\r
-    MovePos(p, repLen - 1);\r
-    return repLen;\r
-  }\r
-  \r
-  if (mainLen < 2 || numAvail <= 2)\r
-    return 1;\r
-\r
-  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);\r
-  if (p->longestMatchLength >= 2)\r
-  {\r
-    UInt32 newDistance = matches[p->numPairs - 1];\r
-    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||\r
-        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||\r
-        (p->longestMatchLength > mainLen + 1) ||\r
-        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))\r
-      return 1;\r
-  }\r
-  \r
-  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r
-  for (i = 0; i < LZMA_NUM_REPS; i++)\r
-  {\r
-    UInt32 len, limit;\r
-    const Byte *data2 = data - p->reps[i] - 1;\r
-    if (data[0] != data2[0] || data[1] != data2[1])\r
-      continue;\r
-    limit = mainLen - 1;\r
-    for (len = 2; len < limit && data[len] == data2[len]; len++);\r
-    if (len >= limit)\r
-      return 1;\r
-  }\r
-  *backRes = mainDist + LZMA_NUM_REPS;\r
-  MovePos(p, mainLen - 2);\r
-  return mainLen;\r
-}\r
-\r
-static void WriteEndMarker(CLzmaEnc *p, UInt32 posState)\r
-{\r
-  UInt32 len;\r
-  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r
-  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r
-  p->state = kMatchNextStates[p->state];\r
-  len = LZMA_MATCH_LEN_MIN;\r
-  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r
-  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);\r
-  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);\r
-  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);\r
-}\r
-\r
-static SRes CheckErrors(CLzmaEnc *p)\r
-{\r
-  if (p->result != SZ_OK)\r
-    return p->result;\r
-  if (p->rc.res != SZ_OK)\r
-    p->result = SZ_ERROR_WRITE;\r
-  if (p->matchFinderBase.result != SZ_OK)\r
-    p->result = SZ_ERROR_READ;\r
-  if (p->result != SZ_OK)\r
-    p->finished = True;\r
-  return p->result;\r
-}\r
-\r
-static SRes Flush(CLzmaEnc *p, UInt32 nowPos)\r
-{\r
-  /* ReleaseMFStream(); */\r
-  p->finished = True;\r
-  if (p->writeEndMark)\r
-    WriteEndMarker(p, nowPos & p->pbMask);\r
-  RangeEnc_FlushData(&p->rc);\r
-  RangeEnc_FlushStream(&p->rc);\r
-  return CheckErrors(p);\r
-}\r
-\r
-static void FillAlignPrices(CLzmaEnc *p)\r
-{\r
-  UInt32 i;\r
-  for (i = 0; i < kAlignTableSize; i++)\r
-    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);\r
-  p->alignPriceCount = 0;\r
-}\r
-\r
-static void FillDistancesPrices(CLzmaEnc *p)\r
-{\r
-  UInt32 tempPrices[kNumFullDistances];\r
-  UInt32 i, lenToPosState;\r
-  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)\r
-  {\r
-    UInt32 posSlot = GetPosSlot1(i);\r
-    UInt32 footerBits = ((posSlot >> 1) - 1);\r
-    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r
-    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);\r
-  }\r
-\r
-  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r
-  {\r
-    UInt32 posSlot;\r
-    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];\r
-    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];\r
-    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)\r
-      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);\r
-    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)\r
-      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);\r
-\r
-    {\r
-      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];\r
-      for (i = 0; i < kStartPosModelIndex; i++)\r
-        distancesPrices[i] = posSlotPrices[i];\r
-      for (; i < kNumFullDistances; i++)\r
-        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];\r
-    }\r
-  }\r
-  p->matchPriceCount = 0;\r
-}\r
-\r
-void LzmaEnc_Construct(CLzmaEnc *p)\r
-{\r
-  RangeEnc_Construct(&p->rc);\r
-  MatchFinder_Construct(&p->matchFinderBase);\r
-  \r
-  #ifndef _7ZIP_ST\r
-  MatchFinderMt_Construct(&p->matchFinderMt);\r
-  p->matchFinderMt.MatchFinder = &p->matchFinderBase;\r
-  #endif\r
-\r
-  {\r
-    CLzmaEncProps props;\r
-    LzmaEncProps_Init(&props);\r
-    LzmaEnc_SetProps(p, &props);\r
-  }\r
-\r
-  #ifndef LZMA_LOG_BSR\r
-  LzmaEnc_FastPosInit(p->g_FastPos);\r
-  #endif\r
-\r
-  LzmaEnc_InitPriceTables(p->ProbPrices);\r
-  p->litProbs = NULL;\r
-  p->saveState.litProbs = NULL;\r
-}\r
-\r
-CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)\r
-{\r
-  void *p;\r
-  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));\r
-  if (p)\r
-    LzmaEnc_Construct((CLzmaEnc *)p);\r
-  return p;\r
-}\r
-\r
-void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->litProbs);\r
-  alloc->Free(alloc, p->saveState.litProbs);\r
-  p->litProbs = NULL;\r
-  p->saveState.litProbs = NULL;\r
-}\r
-\r
-void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  #ifndef _7ZIP_ST\r
-  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);\r
-  #endif\r
-  \r
-  MatchFinder_Free(&p->matchFinderBase, allocBig);\r
-  LzmaEnc_FreeLits(p, alloc);\r
-  RangeEnc_Free(&p->rc, alloc);\r
-}\r
-\r
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);\r
-  alloc->Free(alloc, p);\r
-}\r
-\r
-static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)\r
-{\r
-  UInt32 nowPos32, startPos32;\r
-  if (p->needInit)\r
-  {\r
-    p->matchFinder.Init(p->matchFinderObj);\r
-    p->needInit = 0;\r
-  }\r
-\r
-  if (p->finished)\r
-    return p->result;\r
-  RINOK(CheckErrors(p));\r
-\r
-  nowPos32 = (UInt32)p->nowPos64;\r
-  startPos32 = nowPos32;\r
-\r
-  if (p->nowPos64 == 0)\r
-  {\r
-    UInt32 numPairs;\r
-    Byte curByte;\r
-    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r
-      return Flush(p, nowPos32);\r
-    ReadMatchDistances(p, &numPairs);\r
-    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);\r
-    p->state = kLiteralNextStates[p->state];\r
-    curByte = *(p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset);\r
-    LitEnc_Encode(&p->rc, p->litProbs, curByte);\r
-    p->additionalOffset--;\r
-    nowPos32++;\r
-  }\r
-\r
-  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)\r
-  for (;;)\r
-  {\r
-    UInt32 pos, len, posState;\r
-\r
-    if (p->fastMode)\r
-      len = GetOptimumFast(p, &pos);\r
-    else\r
-      len = GetOptimum(p, nowPos32, &pos);\r
-\r
-    #ifdef SHOW_STAT2\r
-    printf("\n pos = %4X,   len = %u   pos = %u", nowPos32, len, pos);\r
-    #endif\r
-\r
-    posState = nowPos32 & p->pbMask;\r
-    if (len == 1 && pos == (UInt32)-1)\r
-    {\r
-      Byte curByte;\r
-      CLzmaProb *probs;\r
-      const Byte *data;\r
-\r
-      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);\r
-      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r
-      curByte = *data;\r
-      probs = LIT_PROBS(nowPos32, *(data - 1));\r
-      if (IsCharState(p->state))\r
-        LitEnc_Encode(&p->rc, probs, curByte);\r
-      else\r
-        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));\r
-      p->state = kLiteralNextStates[p->state];\r
-    }\r
-    else\r
-    {\r
-      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r
-      if (pos < LZMA_NUM_REPS)\r
-      {\r
-        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);\r
-        if (pos == 0)\r
-        {\r
-          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);\r
-          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));\r
-        }\r
-        else\r
-        {\r
-          UInt32 distance = p->reps[pos];\r
-          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);\r
-          if (pos == 1)\r
-            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);\r
-          else\r
-          {\r
-            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);\r
-            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);\r
-            if (pos == 3)\r
-              p->reps[3] = p->reps[2];\r
-            p->reps[2] = p->reps[1];\r
-          }\r
-          p->reps[1] = p->reps[0];\r
-          p->reps[0] = distance;\r
-        }\r
-        if (len == 1)\r
-          p->state = kShortRepNextStates[p->state];\r
-        else\r
-        {\r
-          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r
-          p->state = kRepNextStates[p->state];\r
-        }\r
-      }\r
-      else\r
-      {\r
-        UInt32 posSlot;\r
-        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r
-        p->state = kMatchNextStates[p->state];\r
-        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r
-        pos -= LZMA_NUM_REPS;\r
-        GetPosSlot(pos, posSlot);\r
-        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);\r
-        \r
-        if (posSlot >= kStartPosModelIndex)\r
-        {\r
-          UInt32 footerBits = ((posSlot >> 1) - 1);\r
-          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r
-          UInt32 posReduced = pos - base;\r
-\r
-          if (posSlot < kEndPosModelIndex)\r
-            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);\r
-          else\r
-          {\r
-            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r
-            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);\r
-            p->alignPriceCount++;\r
-          }\r
-        }\r
-        p->reps[3] = p->reps[2];\r
-        p->reps[2] = p->reps[1];\r
-        p->reps[1] = p->reps[0];\r
-        p->reps[0] = pos;\r
-        p->matchPriceCount++;\r
-      }\r
-    }\r
-    p->additionalOffset -= len;\r
-    nowPos32 += len;\r
-    if (p->additionalOffset == 0)\r
-    {\r
-      UInt32 processed;\r
-      if (!p->fastMode)\r
-      {\r
-        if (p->matchPriceCount >= (1 << 7))\r
-          FillDistancesPrices(p);\r
-        if (p->alignPriceCount >= kAlignTableSize)\r
-          FillAlignPrices(p);\r
-      }\r
-      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r
-        break;\r
-      processed = nowPos32 - startPos32;\r
-      if (useLimits)\r
-      {\r
-        if (processed + kNumOpts + 300 >= maxUnpackSize ||\r
-            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)\r
-          break;\r
-      }\r
-      else if (processed >= (1 << 17))\r
-      {\r
-        p->nowPos64 += nowPos32 - startPos32;\r
-        return CheckErrors(p);\r
-      }\r
-    }\r
-  }\r
-  p->nowPos64 += nowPos32 - startPos32;\r
-  return Flush(p, nowPos32);\r
-}\r
-\r
-#define kBigHashDicLimit ((UInt32)1 << 24)\r
-\r
-static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  UInt32 beforeSize = kNumOpts;\r
-  if (!RangeEnc_Alloc(&p->rc, alloc))\r
-    return SZ_ERROR_MEM;\r
-\r
-  #ifndef _7ZIP_ST\r
-  p->mtMode = (p->multiThread && !p->fastMode && (p->matchFinderBase.btMode != 0));\r
-  #endif\r
-\r
-  {\r
-    unsigned lclp = p->lc + p->lp;\r
-    if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp)\r
-    {\r
-      LzmaEnc_FreeLits(p, alloc);\r
-      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));\r
-      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));\r
-      if (!p->litProbs || !p->saveState.litProbs)\r
-      {\r
-        LzmaEnc_FreeLits(p, alloc);\r
-        return SZ_ERROR_MEM;\r
-      }\r
-      p->lclp = lclp;\r
-    }\r
-  }\r
-\r
-  p->matchFinderBase.bigHash = (Byte)(p->dictSize > kBigHashDicLimit ? 1 : 0);\r
-\r
-  if (beforeSize + p->dictSize < keepWindowSize)\r
-    beforeSize = keepWindowSize - p->dictSize;\r
-\r
-  #ifndef _7ZIP_ST\r
-  if (p->mtMode)\r
-  {\r
-    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));\r
-    p->matchFinderObj = &p->matchFinderMt;\r
-    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);\r
-  }\r
-  else\r
-  #endif\r
-  {\r
-    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))\r
-      return SZ_ERROR_MEM;\r
-    p->matchFinderObj = &p->matchFinderBase;\r
-    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);\r
-  }\r
-  \r
-  return SZ_OK;\r
-}\r
-\r
-void LzmaEnc_Init(CLzmaEnc *p)\r
-{\r
-  UInt32 i;\r
-  p->state = 0;\r
-  for (i = 0 ; i < LZMA_NUM_REPS; i++)\r
-    p->reps[i] = 0;\r
-\r
-  RangeEnc_Init(&p->rc);\r
-\r
-\r
-  for (i = 0; i < kNumStates; i++)\r
-  {\r
-    UInt32 j;\r
-    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)\r
-    {\r
-      p->isMatch[i][j] = kProbInitValue;\r
-      p->isRep0Long[i][j] = kProbInitValue;\r
-    }\r
-    p->isRep[i] = kProbInitValue;\r
-    p->isRepG0[i] = kProbInitValue;\r
-    p->isRepG1[i] = kProbInitValue;\r
-    p->isRepG2[i] = kProbInitValue;\r
-  }\r
-\r
-  {\r
-    UInt32 num = (UInt32)0x300 << (p->lp + p->lc);\r
-    CLzmaProb *probs = p->litProbs;\r
-    for (i = 0; i < num; i++)\r
-      probs[i] = kProbInitValue;\r
-  }\r
-\r
-  {\r
-    for (i = 0; i < kNumLenToPosStates; i++)\r
-    {\r
-      CLzmaProb *probs = p->posSlotEncoder[i];\r
-      UInt32 j;\r
-      for (j = 0; j < (1 << kNumPosSlotBits); j++)\r
-        probs[j] = kProbInitValue;\r
-    }\r
-  }\r
-  {\r
-    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r
-      p->posEncoders[i] = kProbInitValue;\r
-  }\r
-\r
-  LenEnc_Init(&p->lenEnc.p);\r
-  LenEnc_Init(&p->repLenEnc.p);\r
-\r
-  for (i = 0; i < (1 << kNumAlignBits); i++)\r
-    p->posAlignEncoder[i] = kProbInitValue;\r
-\r
-  p->optimumEndIndex = 0;\r
-  p->optimumCurrentIndex = 0;\r
-  p->additionalOffset = 0;\r
-\r
-  p->pbMask = (1 << p->pb) - 1;\r
-  p->lpMask = (1 << p->lp) - 1;\r
-}\r
-\r
-void LzmaEnc_InitPrices(CLzmaEnc *p)\r
-{\r
-  if (!p->fastMode)\r
-  {\r
-    FillDistancesPrices(p);\r
-    FillAlignPrices(p);\r
-  }\r
-\r
-  p->lenEnc.tableSize =\r
-  p->repLenEnc.tableSize =\r
-      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;\r
-  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);\r
-  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);\r
-}\r
-\r
-static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  UInt32 i;\r
-  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)\r
-    if (p->dictSize <= ((UInt32)1 << i))\r
-      break;\r
-  p->distTableSize = i * 2;\r
-\r
-  p->finished = False;\r
-  p->result = SZ_OK;\r
-  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));\r
-  LzmaEnc_Init(p);\r
-  LzmaEnc_InitPrices(p);\r
-  p->nowPos64 = 0;\r
-  return SZ_OK;\r
-}\r
-\r
-static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,\r
-    ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  p->matchFinderBase.stream = inStream;\r
-  p->needInit = 1;\r
-  p->rc.outStream = outStream;\r
-  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);\r
-}\r
-\r
-SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,\r
-    ISeqInStream *inStream, UInt32 keepWindowSize,\r
-    ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  p->matchFinderBase.stream = inStream;\r
-  p->needInit = 1;\r
-  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r
-}\r
-\r
-static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)\r
-{\r
-  p->matchFinderBase.directInput = 1;\r
-  p->matchFinderBase.bufferBase = (Byte *)src;\r
-  p->matchFinderBase.directInputRem = srcLen;\r
-}\r
-\r
-SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\r
-    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  LzmaEnc_SetInputBuf(p, src, srcLen);\r
-  p->needInit = 1;\r
-\r
-  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r
-}\r
-\r
-void LzmaEnc_Finish(CLzmaEncHandle pp)\r
-{\r
-  #ifndef _7ZIP_ST\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  if (p->mtMode)\r
-    MatchFinderMt_ReleaseStream(&p->matchFinderMt);\r
-  #else\r
-  UNUSED_VAR(pp);\r
-  #endif\r
-}\r
-\r
-\r
-typedef struct\r
-{\r
-  ISeqOutStream funcTable;\r
-  Byte *data;\r
-  SizeT rem;\r
-  Bool overflow;\r
-} CSeqOutStreamBuf;\r
-\r
-static size_t MyWrite(void *pp, const void *data, size_t size)\r
-{\r
-  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;\r
-  if (p->rem < size)\r
-  {\r
-    size = p->rem;\r
-    p->overflow = True;\r
-  }\r
-  memcpy(p->data, data, size);\r
-  p->rem -= size;\r
-  p->data += size;\r
-  return size;\r
-}\r
-\r
-\r
-UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)\r
-{\r
-  const CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r
-}\r
-\r
-\r
-const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)\r
-{\r
-  const CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r
-}\r
-\r
-\r
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\r
-    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)\r
-{\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  UInt64 nowPos64;\r
-  SRes res;\r
-  CSeqOutStreamBuf outStream;\r
-\r
-  outStream.funcTable.Write = MyWrite;\r
-  outStream.data = dest;\r
-  outStream.rem = *destLen;\r
-  outStream.overflow = False;\r
-\r
-  p->writeEndMark = False;\r
-  p->finished = False;\r
-  p->result = SZ_OK;\r
-\r
-  if (reInit)\r
-    LzmaEnc_Init(p);\r
-  LzmaEnc_InitPrices(p);\r
-  nowPos64 = p->nowPos64;\r
-  RangeEnc_Init(&p->rc);\r
-  p->rc.outStream = &outStream.funcTable;\r
-\r
-  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);\r
-  \r
-  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);\r
-  *destLen -= outStream.rem;\r
-  if (outStream.overflow)\r
-    return SZ_ERROR_OUTPUT_EOF;\r
-\r
-  return res;\r
-}\r
-\r
-\r
-static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)\r
-{\r
-  SRes res = SZ_OK;\r
-\r
-  #ifndef _7ZIP_ST\r
-  Byte allocaDummy[0x300];\r
-  allocaDummy[0] = 0;\r
-  allocaDummy[1] = allocaDummy[0];\r
-  #endif\r
-\r
-  for (;;)\r
-  {\r
-    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);\r
-    if (res != SZ_OK || p->finished)\r
-      break;\r
-    if (progress)\r
-    {\r
-      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));\r
-      if (res != SZ_OK)\r
-      {\r
-        res = SZ_ERROR_PROGRESS;\r
-        break;\r
-      }\r
-    }\r
-  }\r
-  \r
-  LzmaEnc_Finish(p);\r
-\r
-  /*\r
-  if (res == S_OK && !Inline_MatchFinder_IsFinishedOK(&p->matchFinderBase))\r
-    res = SZ_ERROR_FAIL;\r
-  }\r
-  */\r
-\r
-  return res;\r
-}\r
-\r
-\r
-SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\r
-    ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));\r
-  return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);\r
-}\r
-\r
-\r
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)\r
-{\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  unsigned i;\r
-  UInt32 dictSize = p->dictSize;\r
-  if (*size < LZMA_PROPS_SIZE)\r
-    return SZ_ERROR_PARAM;\r
-  *size = LZMA_PROPS_SIZE;\r
-  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);\r
-\r
-  if (dictSize >= ((UInt32)1 << 22))\r
-  {\r
-    UInt32 kDictMask = ((UInt32)1 << 20) - 1;\r
-    if (dictSize < (UInt32)0xFFFFFFFF - kDictMask)\r
-      dictSize = (dictSize + kDictMask) & ~kDictMask;\r
-  }\r
-  else for (i = 11; i <= 30; i++)\r
-  {\r
-    if (dictSize <= ((UInt32)2 << i)) { dictSize = (2 << i); break; }\r
-    if (dictSize <= ((UInt32)3 << i)) { dictSize = (3 << i); break; }\r
-  }\r
-\r
-  for (i = 0; i < 4; i++)\r
-    props[1 + i] = (Byte)(dictSize >> (8 * i));\r
-  return SZ_OK;\r
-}\r
-\r
-\r
-SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
-    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  SRes res;\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
-\r
-  CSeqOutStreamBuf outStream;\r
-\r
-  outStream.funcTable.Write = MyWrite;\r
-  outStream.data = dest;\r
-  outStream.rem = *destLen;\r
-  outStream.overflow = False;\r
-\r
-  p->writeEndMark = writeEndMark;\r
-  p->rc.outStream = &outStream.funcTable;\r
-\r
-  res = LzmaEnc_MemPrepare(pp, src, srcLen, 0, alloc, allocBig);\r
-  \r
-  if (res == SZ_OK)\r
-  {\r
-    res = LzmaEnc_Encode2(p, progress);\r
-    if (res == SZ_OK && p->nowPos64 != srcLen)\r
-      res = SZ_ERROR_FAIL;\r
-  }\r
-\r
-  *destLen -= outStream.rem;\r
-  if (outStream.overflow)\r
-    return SZ_ERROR_OUTPUT_EOF;\r
-  return res;\r
-}\r
-\r
-\r
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
-    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r
-    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r
-{\r
-  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);\r
-  SRes res;\r
-  if (!p)\r
-    return SZ_ERROR_MEM;\r
-\r
-  res = LzmaEnc_SetProps(p, props);\r
-  if (res == SZ_OK)\r
-  {\r
-    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);\r
-    if (res == SZ_OK)\r
-      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,\r
-          writeEndMark, progress, alloc, allocBig);\r
-  }\r
-\r
-  LzmaEnc_Destroy(p, alloc, allocBig);\r
-  return res;\r
-}\r
diff --git a/deps/lzma-16.04/C/LzmaLib.c b/deps/lzma-16.04/C/LzmaLib.c
deleted file mode 100644 (file)
index c10cf1a..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/* LzmaLib.c -- LZMA library wrapper\r
-2015-06-13 : Igor Pavlov : Public domain */\r
-\r
-#include "Alloc.h"\r
-#include "LzmaDec.h"\r
-#include "LzmaEnc.h"\r
-#include "LzmaLib.h"\r
-\r
-MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,\r
-  unsigned char *outProps, size_t *outPropsSize,\r
-  int level, /* 0 <= level <= 9, default = 5 */\r
-  unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */\r
-  int lc, /* 0 <= lc <= 8, default = 3  */\r
-  int lp, /* 0 <= lp <= 4, default = 0  */\r
-  int pb, /* 0 <= pb <= 4, default = 2  */\r
-  int fb,  /* 5 <= fb <= 273, default = 32 */\r
-  int numThreads /* 1 or 2, default = 2 */\r
-)\r
-{\r
-  CLzmaEncProps props;\r
-  LzmaEncProps_Init(&props);\r
-  props.level = level;\r
-  props.dictSize = dictSize;\r
-  props.lc = lc;\r
-  props.lp = lp;\r
-  props.pb = pb;\r
-  props.fb = fb;\r
-  props.numThreads = numThreads;\r
-\r
-  return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,\r
-      NULL, &g_Alloc, &g_Alloc);\r
-}\r
-\r
-\r
-MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen,\r
-  const unsigned char *props, size_t propsSize)\r
-{\r
-  ELzmaStatus status;\r
-  return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);\r
-}\r
diff --git a/deps/lzma-16.04/C/MtCoder.c b/deps/lzma-16.04/C/MtCoder.c
deleted file mode 100644 (file)
index 8c0d9b3..0000000
+++ /dev/null
@@ -1,327 +0,0 @@
-/* MtCoder.c -- Multi-thread Coder\r
-2015-10-13 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "MtCoder.h"\r
-\r
-void LoopThread_Construct(CLoopThread *p)\r
-{\r
-  Thread_Construct(&p->thread);\r
-  Event_Construct(&p->startEvent);\r
-  Event_Construct(&p->finishedEvent);\r
-}\r
-\r
-void LoopThread_Close(CLoopThread *p)\r
-{\r
-  Thread_Close(&p->thread);\r
-  Event_Close(&p->startEvent);\r
-  Event_Close(&p->finishedEvent);\r
-}\r
-\r
-static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE LoopThreadFunc(void *pp)\r
-{\r
-  CLoopThread *p = (CLoopThread *)pp;\r
-  for (;;)\r
-  {\r
-    if (Event_Wait(&p->startEvent) != 0)\r
-      return SZ_ERROR_THREAD;\r
-    if (p->stop)\r
-      return 0;\r
-    p->res = p->func(p->param);\r
-    if (Event_Set(&p->finishedEvent) != 0)\r
-      return SZ_ERROR_THREAD;\r
-  }\r
-}\r
-\r
-WRes LoopThread_Create(CLoopThread *p)\r
-{\r
-  p->stop = 0;\r
-  RINOK(AutoResetEvent_CreateNotSignaled(&p->startEvent));\r
-  RINOK(AutoResetEvent_CreateNotSignaled(&p->finishedEvent));\r
-  return Thread_Create(&p->thread, LoopThreadFunc, p);\r
-}\r
-\r
-WRes LoopThread_StopAndWait(CLoopThread *p)\r
-{\r
-  p->stop = 1;\r
-  if (Event_Set(&p->startEvent) != 0)\r
-    return SZ_ERROR_THREAD;\r
-  return Thread_Wait(&p->thread);\r
-}\r
-\r
-WRes LoopThread_StartSubThread(CLoopThread *p) { return Event_Set(&p->startEvent); }\r
-WRes LoopThread_WaitSubThread(CLoopThread *p) { return Event_Wait(&p->finishedEvent); }\r
-\r
-static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)\r
-{\r
-  return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;\r
-}\r
-\r
-static void MtProgress_Init(CMtProgress *p, ICompressProgress *progress)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)\r
-    p->inSizes[i] = p->outSizes[i] = 0;\r
-  p->totalInSize = p->totalOutSize = 0;\r
-  p->progress = progress;\r
-  p->res = SZ_OK;\r
-}\r
-\r
-static void MtProgress_Reinit(CMtProgress *p, unsigned index)\r
-{\r
-  p->inSizes[index] = 0;\r
-  p->outSizes[index] = 0;\r
-}\r
-\r
-#define UPDATE_PROGRESS(size, prev, total) \\r
-  if (size != (UInt64)(Int64)-1) { total += size - prev; prev = size; }\r
-\r
-SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize)\r
-{\r
-  SRes res;\r
-  CriticalSection_Enter(&p->cs);\r
-  UPDATE_PROGRESS(inSize, p->inSizes[index], p->totalInSize)\r
-  UPDATE_PROGRESS(outSize, p->outSizes[index], p->totalOutSize)\r
-  if (p->res == SZ_OK)\r
-    p->res = Progress(p->progress, p->totalInSize, p->totalOutSize);\r
-  res = p->res;\r
-  CriticalSection_Leave(&p->cs);\r
-  return res;\r
-}\r
-\r
-static void MtProgress_SetError(CMtProgress *p, SRes res)\r
-{\r
-  CriticalSection_Enter(&p->cs);\r
-  if (p->res == SZ_OK)\r
-    p->res = res;\r
-  CriticalSection_Leave(&p->cs);\r
-}\r
-\r
-static void MtCoder_SetError(CMtCoder* p, SRes res)\r
-{\r
-  CriticalSection_Enter(&p->cs);\r
-  if (p->res == SZ_OK)\r
-    p->res = res;\r
-  CriticalSection_Leave(&p->cs);\r
-}\r
-\r
-/* ---------- MtThread ---------- */\r
-\r
-void CMtThread_Construct(CMtThread *p, CMtCoder *mtCoder)\r
-{\r
-  p->mtCoder = mtCoder;\r
-  p->outBuf = 0;\r
-  p->inBuf = 0;\r
-  Event_Construct(&p->canRead);\r
-  Event_Construct(&p->canWrite);\r
-  LoopThread_Construct(&p->thread);\r
-}\r
-\r
-#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }\r
-\r
-static void CMtThread_CloseEvents(CMtThread *p)\r
-{\r
-  Event_Close(&p->canRead);\r
-  Event_Close(&p->canWrite);\r
-}\r
-\r
-static void CMtThread_Destruct(CMtThread *p)\r
-{\r
-  CMtThread_CloseEvents(p);\r
-\r
-  if (Thread_WasCreated(&p->thread.thread))\r
-  {\r
-    LoopThread_StopAndWait(&p->thread);\r
-    LoopThread_Close(&p->thread);\r
-  }\r
-\r
-  if (p->mtCoder->alloc)\r
-    IAlloc_Free(p->mtCoder->alloc, p->outBuf);\r
-  p->outBuf = 0;\r
-\r
-  if (p->mtCoder->alloc)\r
-    IAlloc_Free(p->mtCoder->alloc, p->inBuf);\r
-  p->inBuf = 0;\r
-}\r
-\r
-#define MY_BUF_ALLOC(buf, size, newSize) \\r
-  if (buf == 0 || size != newSize) \\r
-  { IAlloc_Free(p->mtCoder->alloc, buf); \\r
-    size = newSize; buf = (Byte *)IAlloc_Alloc(p->mtCoder->alloc, size); \\r
-    if (buf == 0) return SZ_ERROR_MEM; }\r
-\r
-static SRes CMtThread_Prepare(CMtThread *p)\r
-{\r
-  MY_BUF_ALLOC(p->inBuf, p->inBufSize, p->mtCoder->blockSize)\r
-  MY_BUF_ALLOC(p->outBuf, p->outBufSize, p->mtCoder->destBlockSize)\r
-\r
-  p->stopReading = False;\r
-  p->stopWriting = False;\r
-  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canRead));\r
-  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canWrite));\r
-\r
-  return SZ_OK;\r
-}\r
-\r
-static SRes FullRead(ISeqInStream *stream, Byte *data, size_t *processedSize)\r
-{\r
-  size_t size = *processedSize;\r
-  *processedSize = 0;\r
-  while (size != 0)\r
-  {\r
-    size_t curSize = size;\r
-    SRes res = stream->Read(stream, data, &curSize);\r
-    *processedSize += curSize;\r
-    data += curSize;\r
-    size -= curSize;\r
-    RINOK(res);\r
-    if (curSize == 0)\r
-      return SZ_OK;\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-#define GET_NEXT_THREAD(p) &p->mtCoder->threads[p->index == p->mtCoder->numThreads  - 1 ? 0 : p->index + 1]\r
-\r
-static SRes MtThread_Process(CMtThread *p, Bool *stop)\r
-{\r
-  CMtThread *next;\r
-  *stop = True;\r
-  if (Event_Wait(&p->canRead) != 0)\r
-    return SZ_ERROR_THREAD;\r
-  \r
-  next = GET_NEXT_THREAD(p);\r
-  \r
-  if (p->stopReading)\r
-  {\r
-    next->stopReading = True;\r
-    return Event_Set(&next->canRead) == 0 ? SZ_OK : SZ_ERROR_THREAD;\r
-  }\r
-\r
-  {\r
-    size_t size = p->mtCoder->blockSize;\r
-    size_t destSize = p->outBufSize;\r
-\r
-    RINOK(FullRead(p->mtCoder->inStream, p->inBuf, &size));\r
-    next->stopReading = *stop = (size != p->mtCoder->blockSize);\r
-    if (Event_Set(&next->canRead) != 0)\r
-      return SZ_ERROR_THREAD;\r
-\r
-    RINOK(p->mtCoder->mtCallback->Code(p->mtCoder->mtCallback, p->index,\r
-        p->outBuf, &destSize, p->inBuf, size, *stop));\r
-\r
-    MtProgress_Reinit(&p->mtCoder->mtProgress, p->index);\r
-\r
-    if (Event_Wait(&p->canWrite) != 0)\r
-      return SZ_ERROR_THREAD;\r
-    if (p->stopWriting)\r
-      return SZ_ERROR_FAIL;\r
-    if (p->mtCoder->outStream->Write(p->mtCoder->outStream, p->outBuf, destSize) != destSize)\r
-      return SZ_ERROR_WRITE;\r
-    return Event_Set(&next->canWrite) == 0 ? SZ_OK : SZ_ERROR_THREAD;\r
-  }\r
-}\r
-\r
-static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE ThreadFunc(void *pp)\r
-{\r
-  CMtThread *p = (CMtThread *)pp;\r
-  for (;;)\r
-  {\r
-    Bool stop;\r
-    CMtThread *next = GET_NEXT_THREAD(p);\r
-    SRes res = MtThread_Process(p, &stop);\r
-    if (res != SZ_OK)\r
-    {\r
-      MtCoder_SetError(p->mtCoder, res);\r
-      MtProgress_SetError(&p->mtCoder->mtProgress, res);\r
-      next->stopReading = True;\r
-      next->stopWriting = True;\r
-      Event_Set(&next->canRead);\r
-      Event_Set(&next->canWrite);\r
-      return res;\r
-    }\r
-    if (stop)\r
-      return 0;\r
-  }\r
-}\r
-\r
-void MtCoder_Construct(CMtCoder* p)\r
-{\r
-  unsigned i;\r
-  p->alloc = 0;\r
-  for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)\r
-  {\r
-    CMtThread *t = &p->threads[i];\r
-    t->index = i;\r
-    CMtThread_Construct(t, p);\r
-  }\r
-  CriticalSection_Init(&p->cs);\r
-  CriticalSection_Init(&p->mtProgress.cs);\r
-}\r
-\r
-void MtCoder_Destruct(CMtCoder* p)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)\r
-    CMtThread_Destruct(&p->threads[i]);\r
-  CriticalSection_Delete(&p->cs);\r
-  CriticalSection_Delete(&p->mtProgress.cs);\r
-}\r
-\r
-SRes MtCoder_Code(CMtCoder *p)\r
-{\r
-  unsigned i, numThreads = p->numThreads;\r
-  SRes res = SZ_OK;\r
-  p->res = SZ_OK;\r
-\r
-  MtProgress_Init(&p->mtProgress, p->progress);\r
-\r
-  for (i = 0; i < numThreads; i++)\r
-  {\r
-    RINOK(CMtThread_Prepare(&p->threads[i]));\r
-  }\r
-\r
-  for (i = 0; i < numThreads; i++)\r
-  {\r
-    CMtThread *t = &p->threads[i];\r
-    CLoopThread *lt = &t->thread;\r
-\r
-    if (!Thread_WasCreated(&lt->thread))\r
-    {\r
-      lt->func = ThreadFunc;\r
-      lt->param = t;\r
-\r
-      if (LoopThread_Create(lt) != SZ_OK)\r
-      {\r
-        res = SZ_ERROR_THREAD;\r
-        break;\r
-      }\r
-    }\r
-  }\r
-\r
-  if (res == SZ_OK)\r
-  {\r
-    unsigned j;\r
-    for (i = 0; i < numThreads; i++)\r
-    {\r
-      CMtThread *t = &p->threads[i];\r
-      if (LoopThread_StartSubThread(&t->thread) != SZ_OK)\r
-      {\r
-        res = SZ_ERROR_THREAD;\r
-        p->threads[0].stopReading = True;\r
-        break;\r
-      }\r
-    }\r
-\r
-    Event_Set(&p->threads[0].canWrite);\r
-    Event_Set(&p->threads[0].canRead);\r
-\r
-    for (j = 0; j < i; j++)\r
-      LoopThread_WaitSubThread(&p->threads[j].thread);\r
-  }\r
-\r
-  for (i = 0; i < numThreads; i++)\r
-    CMtThread_CloseEvents(&p->threads[i]);\r
-  return (res == SZ_OK) ? p->res : res;\r
-}\r
diff --git a/deps/lzma-16.04/C/MtCoder.h b/deps/lzma-16.04/C/MtCoder.h
deleted file mode 100644 (file)
index 705208e..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/* MtCoder.h -- Multi-thread Coder\r
-2009-11-19 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __MT_CODER_H\r
-#define __MT_CODER_H\r
-\r
-#include "Threads.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-typedef struct\r
-{\r
-  CThread thread;\r
-  CAutoResetEvent startEvent;\r
-  CAutoResetEvent finishedEvent;\r
-  int stop;\r
-  \r
-  THREAD_FUNC_TYPE func;\r
-  LPVOID param;\r
-  THREAD_FUNC_RET_TYPE res;\r
-} CLoopThread;\r
-\r
-void LoopThread_Construct(CLoopThread *p);\r
-void LoopThread_Close(CLoopThread *p);\r
-WRes LoopThread_Create(CLoopThread *p);\r
-WRes LoopThread_StopAndWait(CLoopThread *p);\r
-WRes LoopThread_StartSubThread(CLoopThread *p);\r
-WRes LoopThread_WaitSubThread(CLoopThread *p);\r
-\r
-#ifndef _7ZIP_ST\r
-#define NUM_MT_CODER_THREADS_MAX 32\r
-#else\r
-#define NUM_MT_CODER_THREADS_MAX 1\r
-#endif\r
-\r
-typedef struct\r
-{\r
-  UInt64 totalInSize;\r
-  UInt64 totalOutSize;\r
-  ICompressProgress *progress;\r
-  SRes res;\r
-  CCriticalSection cs;\r
-  UInt64 inSizes[NUM_MT_CODER_THREADS_MAX];\r
-  UInt64 outSizes[NUM_MT_CODER_THREADS_MAX];\r
-} CMtProgress;\r
-\r
-SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize);\r
-\r
-struct _CMtCoder;\r
-\r
-typedef struct\r
-{\r
-  struct _CMtCoder *mtCoder;\r
-  Byte *outBuf;\r
-  size_t outBufSize;\r
-  Byte *inBuf;\r
-  size_t inBufSize;\r
-  unsigned index;\r
-  CLoopThread thread;\r
-\r
-  Bool stopReading;\r
-  Bool stopWriting;\r
-  CAutoResetEvent canRead;\r
-  CAutoResetEvent canWrite;\r
-} CMtThread;\r
-\r
-typedef struct\r
-{\r
-  SRes (*Code)(void *p, unsigned index, Byte *dest, size_t *destSize,\r
-      const Byte *src, size_t srcSize, int finished);\r
-} IMtCoderCallback;\r
-\r
-typedef struct _CMtCoder\r
-{\r
-  size_t blockSize;\r
-  size_t destBlockSize;\r
-  unsigned numThreads;\r
-  \r
-  ISeqInStream *inStream;\r
-  ISeqOutStream *outStream;\r
-  ICompressProgress *progress;\r
-  ISzAlloc *alloc;\r
-\r
-  IMtCoderCallback *mtCallback;\r
-  CCriticalSection cs;\r
-  SRes res;\r
-\r
-  CMtProgress mtProgress;\r
-  CMtThread threads[NUM_MT_CODER_THREADS_MAX];\r
-} CMtCoder;\r
-\r
-void MtCoder_Construct(CMtCoder* p);\r
-void MtCoder_Destruct(CMtCoder* p);\r
-SRes MtCoder_Code(CMtCoder *p);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Ppmd.h b/deps/lzma-16.04/C/Ppmd.h
deleted file mode 100644 (file)
index e807ca1..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/* Ppmd.h -- PPMD codec common code\r
-2016-05-16 : Igor Pavlov : Public domain\r
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */\r
-\r
-#ifndef __PPMD_H\r
-#define __PPMD_H\r
-\r
-#include "CpuArch.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#ifdef MY_CPU_32BIT\r
-  #define PPMD_32BIT\r
-#endif\r
-\r
-#define PPMD_INT_BITS 7\r
-#define PPMD_PERIOD_BITS 7\r
-#define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS))\r
-\r
-#define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift))\r
-#define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2)\r
-#define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob))\r
-#define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob))\r
-\r
-#define PPMD_N1 4\r
-#define PPMD_N2 4\r
-#define PPMD_N3 4\r
-#define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4)\r
-#define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4)\r
-\r
-#pragma pack(push, 1)\r
-/* Most compilers works OK here even without #pragma pack(push, 1), but some GCC compilers need it. */\r
-\r
-/* SEE-contexts for PPM-contexts with masked symbols */\r
-typedef struct\r
-{\r
-  UInt16 Summ; /* Freq */\r
-  Byte Shift;  /* Speed of Freq change; low Shift is for fast change */\r
-  Byte Count;  /* Count to next change of Shift */\r
-} CPpmd_See;\r
-\r
-#define Ppmd_See_Update(p)  if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \\r
-    { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); }\r
-\r
-typedef struct\r
-{\r
-  Byte Symbol;\r
-  Byte Freq;\r
-  UInt16 SuccessorLow;\r
-  UInt16 SuccessorHigh;\r
-} CPpmd_State;\r
-\r
-#pragma pack(pop)\r
-\r
-typedef\r
-  #ifdef PPMD_32BIT\r
-    CPpmd_State *\r
-  #else\r
-    UInt32\r
-  #endif\r
-  CPpmd_State_Ref;\r
-\r
-typedef\r
-  #ifdef PPMD_32BIT\r
-    void *\r
-  #else\r
-    UInt32\r
-  #endif\r
-  CPpmd_Void_Ref;\r
-\r
-typedef\r
-  #ifdef PPMD_32BIT\r
-    Byte *\r
-  #else\r
-    UInt32\r
-  #endif\r
-  CPpmd_Byte_Ref;\r
-\r
-#define PPMD_SetAllBitsIn256Bytes(p) \\r
-  { unsigned z; for (z = 0; z < 256 / sizeof(p[0]); z += 8) { \\r
-  p[z+7] = p[z+6] = p[z+5] = p[z+4] = p[z+3] = p[z+2] = p[z+1] = p[z+0] = ~(size_t)0; }}\r
-\r
-EXTERN_C_END\r
\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Ppmd7.c b/deps/lzma-16.04/C/Ppmd7.c
deleted file mode 100644 (file)
index ba5d329..0000000
+++ /dev/null
@@ -1,710 +0,0 @@
-/* Ppmd7.c -- PPMdH codec\r
-2016-05-21 : Igor Pavlov : Public domain\r
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-#include "Ppmd7.h"\r
-\r
-const Byte PPMD7_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };\r
-static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};\r
-\r
-#define MAX_FREQ 124\r
-#define UNIT_SIZE 12\r
-\r
-#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE)\r
-#define U2I(nu) (p->Units2Indx[(nu) - 1])\r
-#define I2U(indx) (p->Indx2Units[indx])\r
-\r
-#ifdef PPMD_32BIT\r
-  #define REF(ptr) (ptr)\r
-#else\r
-  #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base))\r
-#endif\r
-\r
-#define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr))\r
-\r
-#define CTX(ref) ((CPpmd7_Context *)Ppmd7_GetContext(p, ref))\r
-#define STATS(ctx) Ppmd7_GetStats(p, ctx)\r
-#define ONE_STATE(ctx) Ppmd7Context_OneState(ctx)\r
-#define SUFFIX(ctx) CTX((ctx)->Suffix)\r
-\r
-typedef CPpmd7_Context * CTX_PTR;\r
-\r
-struct CPpmd7_Node_;\r
-\r
-typedef\r
-  #ifdef PPMD_32BIT\r
-    struct CPpmd7_Node_ *\r
-  #else\r
-    UInt32\r
-  #endif\r
-  CPpmd7_Node_Ref;\r
-\r
-typedef struct CPpmd7_Node_\r
-{\r
-  UInt16 Stamp; /* must be at offset 0 as CPpmd7_Context::NumStats. Stamp=0 means free */\r
-  UInt16 NU;\r
-  CPpmd7_Node_Ref Next; /* must be at offset >= 4 */\r
-  CPpmd7_Node_Ref Prev;\r
-} CPpmd7_Node;\r
-\r
-#ifdef PPMD_32BIT\r
-  #define NODE(ptr) (ptr)\r
-#else\r
-  #define NODE(offs) ((CPpmd7_Node *)(p->Base + (offs)))\r
-#endif\r
-\r
-void Ppmd7_Construct(CPpmd7 *p)\r
-{\r
-  unsigned i, k, m;\r
-\r
-  p->Base = 0;\r
-\r
-  for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)\r
-  {\r
-    unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);\r
-    do { p->Units2Indx[k++] = (Byte)i; } while (--step);\r
-    p->Indx2Units[i] = (Byte)k;\r
-  }\r
-\r
-  p->NS2BSIndx[0] = (0 << 1);\r
-  p->NS2BSIndx[1] = (1 << 1);\r
-  memset(p->NS2BSIndx + 2, (2 << 1), 9);\r
-  memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11);\r
-\r
-  for (i = 0; i < 3; i++)\r
-    p->NS2Indx[i] = (Byte)i;\r
-  for (m = i, k = 1; i < 256; i++)\r
-  {\r
-    p->NS2Indx[i] = (Byte)m;\r
-    if (--k == 0)\r
-      k = (++m) - 2;\r
-  }\r
-\r
-  memset(p->HB2Flag, 0, 0x40);\r
-  memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40);\r
-}\r
-\r
-void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->Base);\r
-  p->Size = 0;\r
-  p->Base = 0;\r
-}\r
-\r
-Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc)\r
-{\r
-  if (p->Base == 0 || p->Size != size)\r
-  {\r
-    Ppmd7_Free(p, alloc);\r
-    p->AlignOffset =\r
-      #ifdef PPMD_32BIT\r
-        (4 - size) & 3;\r
-      #else\r
-        4 - (size & 3);\r
-      #endif\r
-    if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size\r
-        #ifndef PPMD_32BIT\r
-        + UNIT_SIZE\r
-        #endif\r
-        )) == 0)\r
-      return False;\r
-    p->Size = size;\r
-  }\r
-  return True;\r
-}\r
-\r
-static void InsertNode(CPpmd7 *p, void *node, unsigned indx)\r
-{\r
-  *((CPpmd_Void_Ref *)node) = p->FreeList[indx];\r
-  p->FreeList[indx] = REF(node);\r
-}\r
-\r
-static void *RemoveNode(CPpmd7 *p, unsigned indx)\r
-{\r
-  CPpmd_Void_Ref *node = (CPpmd_Void_Ref *)Ppmd7_GetPtr(p, p->FreeList[indx]);\r
-  p->FreeList[indx] = *node;\r
-  return node;\r
-}\r
-\r
-static void SplitBlock(CPpmd7 *p, void *ptr, unsigned oldIndx, unsigned newIndx)\r
-{\r
-  unsigned i, nu = I2U(oldIndx) - I2U(newIndx);\r
-  ptr = (Byte *)ptr + U2B(I2U(newIndx));\r
-  if (I2U(i = U2I(nu)) != nu)\r
-  {\r
-    unsigned k = I2U(--i);\r
-    InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1);\r
-  }\r
-  InsertNode(p, ptr, i);\r
-}\r
-\r
-static void GlueFreeBlocks(CPpmd7 *p)\r
-{\r
-  #ifdef PPMD_32BIT\r
-  CPpmd7_Node headItem;\r
-  CPpmd7_Node_Ref head = &headItem;\r
-  #else\r
-  CPpmd7_Node_Ref head = p->AlignOffset + p->Size;\r
-  #endif\r
-  \r
-  CPpmd7_Node_Ref n = head;\r
-  unsigned i;\r
-\r
-  p->GlueCount = 255;\r
-\r
-  /* create doubly-linked list of free blocks */\r
-  for (i = 0; i < PPMD_NUM_INDEXES; i++)\r
-  {\r
-    UInt16 nu = I2U(i);\r
-    CPpmd7_Node_Ref next = (CPpmd7_Node_Ref)p->FreeList[i];\r
-    p->FreeList[i] = 0;\r
-    while (next != 0)\r
-    {\r
-      CPpmd7_Node *node = NODE(next);\r
-      node->Next = n;\r
-      n = NODE(n)->Prev = next;\r
-      next = *(const CPpmd7_Node_Ref *)node;\r
-      node->Stamp = 0;\r
-      node->NU = (UInt16)nu;\r
-    }\r
-  }\r
-  NODE(head)->Stamp = 1;\r
-  NODE(head)->Next = n;\r
-  NODE(n)->Prev = head;\r
-  if (p->LoUnit != p->HiUnit)\r
-    ((CPpmd7_Node *)p->LoUnit)->Stamp = 1;\r
-  \r
-  /* Glue free blocks */\r
-  while (n != head)\r
-  {\r
-    CPpmd7_Node *node = NODE(n);\r
-    UInt32 nu = (UInt32)node->NU;\r
-    for (;;)\r
-    {\r
-      CPpmd7_Node *node2 = NODE(n) + nu;\r
-      nu += node2->NU;\r
-      if (node2->Stamp != 0 || nu >= 0x10000)\r
-        break;\r
-      NODE(node2->Prev)->Next = node2->Next;\r
-      NODE(node2->Next)->Prev = node2->Prev;\r
-      node->NU = (UInt16)nu;\r
-    }\r
-    n = node->Next;\r
-  }\r
-  \r
-  /* Fill lists of free blocks */\r
-  for (n = NODE(head)->Next; n != head;)\r
-  {\r
-    CPpmd7_Node *node = NODE(n);\r
-    unsigned nu;\r
-    CPpmd7_Node_Ref next = node->Next;\r
-    for (nu = node->NU; nu > 128; nu -= 128, node += 128)\r
-      InsertNode(p, node, PPMD_NUM_INDEXES - 1);\r
-    if (I2U(i = U2I(nu)) != nu)\r
-    {\r
-      unsigned k = I2U(--i);\r
-      InsertNode(p, node + k, nu - k - 1);\r
-    }\r
-    InsertNode(p, node, i);\r
-    n = next;\r
-  }\r
-}\r
-\r
-static void *AllocUnitsRare(CPpmd7 *p, unsigned indx)\r
-{\r
-  unsigned i;\r
-  void *retVal;\r
-  if (p->GlueCount == 0)\r
-  {\r
-    GlueFreeBlocks(p);\r
-    if (p->FreeList[indx] != 0)\r
-      return RemoveNode(p, indx);\r
-  }\r
-  i = indx;\r
-  do\r
-  {\r
-    if (++i == PPMD_NUM_INDEXES)\r
-    {\r
-      UInt32 numBytes = U2B(I2U(indx));\r
-      p->GlueCount--;\r
-      return ((UInt32)(p->UnitsStart - p->Text) > numBytes) ? (p->UnitsStart -= numBytes) : (NULL);\r
-    }\r
-  }\r
-  while (p->FreeList[i] == 0);\r
-  retVal = RemoveNode(p, i);\r
-  SplitBlock(p, retVal, i, indx);\r
-  return retVal;\r
-}\r
-\r
-static void *AllocUnits(CPpmd7 *p, unsigned indx)\r
-{\r
-  UInt32 numBytes;\r
-  if (p->FreeList[indx] != 0)\r
-    return RemoveNode(p, indx);\r
-  numBytes = U2B(I2U(indx));\r
-  if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit))\r
-  {\r
-    void *retVal = p->LoUnit;\r
-    p->LoUnit += numBytes;\r
-    return retVal;\r
-  }\r
-  return AllocUnitsRare(p, indx);\r
-}\r
-\r
-#define MyMem12Cpy(dest, src, num) \\r
-  { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \\r
-    do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while (--n); }\r
-\r
-static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU)\r
-{\r
-  unsigned i0 = U2I(oldNU);\r
-  unsigned i1 = U2I(newNU);\r
-  if (i0 == i1)\r
-    return oldPtr;\r
-  if (p->FreeList[i1] != 0)\r
-  {\r
-    void *ptr = RemoveNode(p, i1);\r
-    MyMem12Cpy(ptr, oldPtr, newNU);\r
-    InsertNode(p, oldPtr, i0);\r
-    return ptr;\r
-  }\r
-  SplitBlock(p, oldPtr, i0, i1);\r
-  return oldPtr;\r
-}\r
-\r
-#define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16)))\r
-\r
-static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v)\r
-{\r
-  (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF);\r
-  (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF);\r
-}\r
-\r
-static void RestartModel(CPpmd7 *p)\r
-{\r
-  unsigned i, k, m;\r
-\r
-  memset(p->FreeList, 0, sizeof(p->FreeList));\r
-  p->Text = p->Base + p->AlignOffset;\r
-  p->HiUnit = p->Text + p->Size;\r
-  p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE;\r
-  p->GlueCount = 0;\r
-\r
-  p->OrderFall = p->MaxOrder;\r
-  p->RunLength = p->InitRL = -(Int32)((p->MaxOrder < 12) ? p->MaxOrder : 12) - 1;\r
-  p->PrevSuccess = 0;\r
-\r
-  p->MinContext = p->MaxContext = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */\r
-  p->MinContext->Suffix = 0;\r
-  p->MinContext->NumStats = 256;\r
-  p->MinContext->SummFreq = 256 + 1;\r
-  p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */\r
-  p->LoUnit += U2B(256 / 2);\r
-  p->MinContext->Stats = REF(p->FoundState);\r
-  for (i = 0; i < 256; i++)\r
-  {\r
-    CPpmd_State *s = &p->FoundState[i];\r
-    s->Symbol = (Byte)i;\r
-    s->Freq = 1;\r
-    SetSuccessor(s, 0);\r
-  }\r
-\r
-  for (i = 0; i < 128; i++)\r
-    for (k = 0; k < 8; k++)\r
-    {\r
-      UInt16 *dest = p->BinSumm[i] + k;\r
-      UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 2));\r
-      for (m = 0; m < 64; m += 8)\r
-        dest[m] = val;\r
-    }\r
-  \r
-  for (i = 0; i < 25; i++)\r
-    for (k = 0; k < 16; k++)\r
-    {\r
-      CPpmd_See *s = &p->See[i][k];\r
-      s->Summ = (UInt16)((5 * i + 10) << (s->Shift = PPMD_PERIOD_BITS - 4));\r
-      s->Count = 4;\r
-    }\r
-}\r
-\r
-void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder)\r
-{\r
-  p->MaxOrder = maxOrder;\r
-  RestartModel(p);\r
-  p->DummySee.Shift = PPMD_PERIOD_BITS;\r
-  p->DummySee.Summ = 0; /* unused */\r
-  p->DummySee.Count = 64; /* unused */\r
-}\r
-\r
-static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip)\r
-{\r
-  CPpmd_State upState;\r
-  CTX_PTR c = p->MinContext;\r
-  CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState);\r
-  CPpmd_State *ps[PPMD7_MAX_ORDER];\r
-  unsigned numPs = 0;\r
-  \r
-  if (!skip)\r
-    ps[numPs++] = p->FoundState;\r
-  \r
-  while (c->Suffix)\r
-  {\r
-    CPpmd_Void_Ref successor;\r
-    CPpmd_State *s;\r
-    c = SUFFIX(c);\r
-    if (c->NumStats != 1)\r
-    {\r
-      for (s = STATS(c); s->Symbol != p->FoundState->Symbol; s++);\r
-    }\r
-    else\r
-      s = ONE_STATE(c);\r
-    successor = SUCCESSOR(s);\r
-    if (successor != upBranch)\r
-    {\r
-      c = CTX(successor);\r
-      if (numPs == 0)\r
-        return c;\r
-      break;\r
-    }\r
-    ps[numPs++] = s;\r
-  }\r
-  \r
-  upState.Symbol = *(const Byte *)Ppmd7_GetPtr(p, upBranch);\r
-  SetSuccessor(&upState, upBranch + 1);\r
-  \r
-  if (c->NumStats == 1)\r
-    upState.Freq = ONE_STATE(c)->Freq;\r
-  else\r
-  {\r
-    UInt32 cf, s0;\r
-    CPpmd_State *s;\r
-    for (s = STATS(c); s->Symbol != upState.Symbol; s++);\r
-    cf = s->Freq - 1;\r
-    s0 = c->SummFreq - c->NumStats - cf;\r
-    upState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : ((2 * cf + 3 * s0 - 1) / (2 * s0))));\r
-  }\r
-\r
-  do\r
-  {\r
-    /* Create Child */\r
-    CTX_PTR c1; /* = AllocContext(p); */\r
-    if (p->HiUnit != p->LoUnit)\r
-      c1 = (CTX_PTR)(p->HiUnit -= UNIT_SIZE);\r
-    else if (p->FreeList[0] != 0)\r
-      c1 = (CTX_PTR)RemoveNode(p, 0);\r
-    else\r
-    {\r
-      c1 = (CTX_PTR)AllocUnitsRare(p, 0);\r
-      if (!c1)\r
-        return NULL;\r
-    }\r
-    c1->NumStats = 1;\r
-    *ONE_STATE(c1) = upState;\r
-    c1->Suffix = REF(c);\r
-    SetSuccessor(ps[--numPs], REF(c1));\r
-    c = c1;\r
-  }\r
-  while (numPs != 0);\r
-  \r
-  return c;\r
-}\r
-\r
-static void SwapStates(CPpmd_State *t1, CPpmd_State *t2)\r
-{\r
-  CPpmd_State tmp = *t1;\r
-  *t1 = *t2;\r
-  *t2 = tmp;\r
-}\r
-\r
-static void UpdateModel(CPpmd7 *p)\r
-{\r
-  CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState);\r
-  CTX_PTR c;\r
-  unsigned s0, ns;\r
-  \r
-  if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0)\r
-  {\r
-    c = SUFFIX(p->MinContext);\r
-    \r
-    if (c->NumStats == 1)\r
-    {\r
-      CPpmd_State *s = ONE_STATE(c);\r
-      if (s->Freq < 32)\r
-        s->Freq++;\r
-    }\r
-    else\r
-    {\r
-      CPpmd_State *s = STATS(c);\r
-      if (s->Symbol != p->FoundState->Symbol)\r
-      {\r
-        do { s++; } while (s->Symbol != p->FoundState->Symbol);\r
-        if (s[0].Freq >= s[-1].Freq)\r
-        {\r
-          SwapStates(&s[0], &s[-1]);\r
-          s--;\r
-        }\r
-      }\r
-      if (s->Freq < MAX_FREQ - 9)\r
-      {\r
-        s->Freq += 2;\r
-        c->SummFreq += 2;\r
-      }\r
-    }\r
-  }\r
-\r
-  if (p->OrderFall == 0)\r
-  {\r
-    p->MinContext = p->MaxContext = CreateSuccessors(p, True);\r
-    if (p->MinContext == 0)\r
-    {\r
-      RestartModel(p);\r
-      return;\r
-    }\r
-    SetSuccessor(p->FoundState, REF(p->MinContext));\r
-    return;\r
-  }\r
-  \r
-  *p->Text++ = p->FoundState->Symbol;\r
-  successor = REF(p->Text);\r
-  if (p->Text >= p->UnitsStart)\r
-  {\r
-    RestartModel(p);\r
-    return;\r
-  }\r
-  \r
-  if (fSuccessor)\r
-  {\r
-    if (fSuccessor <= successor)\r
-    {\r
-      CTX_PTR cs = CreateSuccessors(p, False);\r
-      if (cs == NULL)\r
-      {\r
-        RestartModel(p);\r
-        return;\r
-      }\r
-      fSuccessor = REF(cs);\r
-    }\r
-    if (--p->OrderFall == 0)\r
-    {\r
-      successor = fSuccessor;\r
-      p->Text -= (p->MaxContext != p->MinContext);\r
-    }\r
-  }\r
-  else\r
-  {\r
-    SetSuccessor(p->FoundState, successor);\r
-    fSuccessor = REF(p->MinContext);\r
-  }\r
-  \r
-  s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - (p->FoundState->Freq - 1);\r
-  \r
-  for (c = p->MaxContext; c != p->MinContext; c = SUFFIX(c))\r
-  {\r
-    unsigned ns1;\r
-    UInt32 cf, sf;\r
-    if ((ns1 = c->NumStats) != 1)\r
-    {\r
-      if ((ns1 & 1) == 0)\r
-      {\r
-        /* Expand for one UNIT */\r
-        unsigned oldNU = ns1 >> 1;\r
-        unsigned i = U2I(oldNU);\r
-        if (i != U2I(oldNU + 1))\r
-        {\r
-          void *ptr = AllocUnits(p, i + 1);\r
-          void *oldPtr;\r
-          if (!ptr)\r
-          {\r
-            RestartModel(p);\r
-            return;\r
-          }\r
-          oldPtr = STATS(c);\r
-          MyMem12Cpy(ptr, oldPtr, oldNU);\r
-          InsertNode(p, oldPtr, i);\r
-          c->Stats = STATS_REF(ptr);\r
-        }\r
-      }\r
-      c->SummFreq = (UInt16)(c->SummFreq + (2 * ns1 < ns) + 2 * ((4 * ns1 <= ns) & (c->SummFreq <= 8 * ns1)));\r
-    }\r
-    else\r
-    {\r
-      CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0);\r
-      if (!s)\r
-      {\r
-        RestartModel(p);\r
-        return;\r
-      }\r
-      *s = *ONE_STATE(c);\r
-      c->Stats = REF(s);\r
-      if (s->Freq < MAX_FREQ / 4 - 1)\r
-        s->Freq <<= 1;\r
-      else\r
-        s->Freq = MAX_FREQ - 4;\r
-      c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 3));\r
-    }\r
-    cf = 2 * (UInt32)p->FoundState->Freq * (c->SummFreq + 6);\r
-    sf = (UInt32)s0 + c->SummFreq;\r
-    if (cf < 6 * sf)\r
-    {\r
-      cf = 1 + (cf > sf) + (cf >= 4 * sf);\r
-      c->SummFreq += 3;\r
-    }\r
-    else\r
-    {\r
-      cf = 4 + (cf >= 9 * sf) + (cf >= 12 * sf) + (cf >= 15 * sf);\r
-      c->SummFreq = (UInt16)(c->SummFreq + cf);\r
-    }\r
-    {\r
-      CPpmd_State *s = STATS(c) + ns1;\r
-      SetSuccessor(s, successor);\r
-      s->Symbol = p->FoundState->Symbol;\r
-      s->Freq = (Byte)cf;\r
-      c->NumStats = (UInt16)(ns1 + 1);\r
-    }\r
-  }\r
-  p->MaxContext = p->MinContext = CTX(fSuccessor);\r
-}\r
-  \r
-static void Rescale(CPpmd7 *p)\r
-{\r
-  unsigned i, adder, sumFreq, escFreq;\r
-  CPpmd_State *stats = STATS(p->MinContext);\r
-  CPpmd_State *s = p->FoundState;\r
-  {\r
-    CPpmd_State tmp = *s;\r
-    for (; s != stats; s--)\r
-      s[0] = s[-1];\r
-    *s = tmp;\r
-  }\r
-  escFreq = p->MinContext->SummFreq - s->Freq;\r
-  s->Freq += 4;\r
-  adder = (p->OrderFall != 0);\r
-  s->Freq = (Byte)((s->Freq + adder) >> 1);\r
-  sumFreq = s->Freq;\r
-  \r
-  i = p->MinContext->NumStats - 1;\r
-  do\r
-  {\r
-    escFreq -= (++s)->Freq;\r
-    s->Freq = (Byte)((s->Freq + adder) >> 1);\r
-    sumFreq += s->Freq;\r
-    if (s[0].Freq > s[-1].Freq)\r
-    {\r
-      CPpmd_State *s1 = s;\r
-      CPpmd_State tmp = *s1;\r
-      do\r
-        s1[0] = s1[-1];\r
-      while (--s1 != stats && tmp.Freq > s1[-1].Freq);\r
-      *s1 = tmp;\r
-    }\r
-  }\r
-  while (--i);\r
-  \r
-  if (s->Freq == 0)\r
-  {\r
-    unsigned numStats = p->MinContext->NumStats;\r
-    unsigned n0, n1;\r
-    do { i++; } while ((--s)->Freq == 0);\r
-    escFreq += i;\r
-    p->MinContext->NumStats = (UInt16)(p->MinContext->NumStats - i);\r
-    if (p->MinContext->NumStats == 1)\r
-    {\r
-      CPpmd_State tmp = *stats;\r
-      do\r
-      {\r
-        tmp.Freq = (Byte)(tmp.Freq - (tmp.Freq >> 1));\r
-        escFreq >>= 1;\r
-      }\r
-      while (escFreq > 1);\r
-      InsertNode(p, stats, U2I(((numStats + 1) >> 1)));\r
-      *(p->FoundState = ONE_STATE(p->MinContext)) = tmp;\r
-      return;\r
-    }\r
-    n0 = (numStats + 1) >> 1;\r
-    n1 = (p->MinContext->NumStats + 1) >> 1;\r
-    if (n0 != n1)\r
-      p->MinContext->Stats = STATS_REF(ShrinkUnits(p, stats, n0, n1));\r
-  }\r
-  p->MinContext->SummFreq = (UInt16)(sumFreq + escFreq - (escFreq >> 1));\r
-  p->FoundState = STATS(p->MinContext);\r
-}\r
-\r
-CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq)\r
-{\r
-  CPpmd_See *see;\r
-  unsigned nonMasked = p->MinContext->NumStats - numMasked;\r
-  if (p->MinContext->NumStats != 256)\r
-  {\r
-    see = p->See[(unsigned)p->NS2Indx[nonMasked - 1]] +\r
-        (nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) +\r
-        2 * (unsigned)(p->MinContext->SummFreq < 11 * p->MinContext->NumStats) +\r
-        4 * (unsigned)(numMasked > nonMasked) +\r
-        p->HiBitsFlag;\r
-    {\r
-      unsigned r = (see->Summ >> see->Shift);\r
-      see->Summ = (UInt16)(see->Summ - r);\r
-      *escFreq = r + (r == 0);\r
-    }\r
-  }\r
-  else\r
-  {\r
-    see = &p->DummySee;\r
-    *escFreq = 1;\r
-  }\r
-  return see;\r
-}\r
-\r
-static void NextContext(CPpmd7 *p)\r
-{\r
-  CTX_PTR c = CTX(SUCCESSOR(p->FoundState));\r
-  if (p->OrderFall == 0 && (Byte *)c > p->Text)\r
-    p->MinContext = p->MaxContext = c;\r
-  else\r
-    UpdateModel(p);\r
-}\r
-\r
-void Ppmd7_Update1(CPpmd7 *p)\r
-{\r
-  CPpmd_State *s = p->FoundState;\r
-  s->Freq += 4;\r
-  p->MinContext->SummFreq += 4;\r
-  if (s[0].Freq > s[-1].Freq)\r
-  {\r
-    SwapStates(&s[0], &s[-1]);\r
-    p->FoundState = --s;\r
-    if (s->Freq > MAX_FREQ)\r
-      Rescale(p);\r
-  }\r
-  NextContext(p);\r
-}\r
-\r
-void Ppmd7_Update1_0(CPpmd7 *p)\r
-{\r
-  p->PrevSuccess = (2 * p->FoundState->Freq > p->MinContext->SummFreq);\r
-  p->RunLength += p->PrevSuccess;\r
-  p->MinContext->SummFreq += 4;\r
-  if ((p->FoundState->Freq += 4) > MAX_FREQ)\r
-    Rescale(p);\r
-  NextContext(p);\r
-}\r
-\r
-void Ppmd7_UpdateBin(CPpmd7 *p)\r
-{\r
-  p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 128 ? 1: 0));\r
-  p->PrevSuccess = 1;\r
-  p->RunLength++;\r
-  NextContext(p);\r
-}\r
-\r
-void Ppmd7_Update2(CPpmd7 *p)\r
-{\r
-  p->MinContext->SummFreq += 4;\r
-  if ((p->FoundState->Freq += 4) > MAX_FREQ)\r
-    Rescale(p);\r
-  p->RunLength = p->InitRL;\r
-  UpdateModel(p);\r
-}\r
diff --git a/deps/lzma-16.04/C/Ppmd7.h b/deps/lzma-16.04/C/Ppmd7.h
deleted file mode 100644 (file)
index 1c7870c..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/* Ppmd7.h -- PPMdH compression codec\r
-2016-05-21 : Igor Pavlov : Public domain\r
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */\r
-\r
-/* This code supports virtual RangeDecoder and includes the implementation\r
-of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H.\r
-If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */\r
-\r
-#ifndef __PPMD7_H\r
-#define __PPMD7_H\r
-\r
-#include "Ppmd.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define PPMD7_MIN_ORDER 2\r
-#define PPMD7_MAX_ORDER 64\r
-\r
-#define PPMD7_MIN_MEM_SIZE (1 << 11)\r
-#define PPMD7_MAX_MEM_SIZE (0xFFFFFFFF - 12 * 3)\r
-\r
-struct CPpmd7_Context_;\r
-\r
-typedef\r
-  #ifdef PPMD_32BIT\r
-    struct CPpmd7_Context_ *\r
-  #else\r
-    UInt32\r
-  #endif\r
-  CPpmd7_Context_Ref;\r
-\r
-typedef struct CPpmd7_Context_\r
-{\r
-  UInt16 NumStats;\r
-  UInt16 SummFreq;\r
-  CPpmd_State_Ref Stats;\r
-  CPpmd7_Context_Ref Suffix;\r
-} CPpmd7_Context;\r
-\r
-#define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq)\r
-\r
-typedef struct\r
-{\r
-  CPpmd7_Context *MinContext, *MaxContext;\r
-  CPpmd_State *FoundState;\r
-  unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag;\r
-  Int32 RunLength, InitRL; /* must be 32-bit at least */\r
-\r
-  UInt32 Size;\r
-  UInt32 GlueCount;\r
-  Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart;\r
-  UInt32 AlignOffset;\r
-\r
-  Byte Indx2Units[PPMD_NUM_INDEXES];\r
-  Byte Units2Indx[128];\r
-  CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES];\r
-  Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256];\r
-  CPpmd_See DummySee, See[25][16];\r
-  UInt16 BinSumm[128][64];\r
-} CPpmd7;\r
-\r
-void Ppmd7_Construct(CPpmd7 *p);\r
-Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc);\r
-void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc);\r
-void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder);\r
-#define Ppmd7_WasAllocated(p) ((p)->Base != NULL)\r
-\r
-\r
-/* ---------- Internal Functions ---------- */\r
-\r
-extern const Byte PPMD7_kExpEscape[16];\r
-\r
-#ifdef PPMD_32BIT\r
-  #define Ppmd7_GetPtr(p, ptr) (ptr)\r
-  #define Ppmd7_GetContext(p, ptr) (ptr)\r
-  #define Ppmd7_GetStats(p, ctx) ((ctx)->Stats)\r
-#else\r
-  #define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs)))\r
-  #define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs)))\r
-  #define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats)))\r
-#endif\r
-\r
-void Ppmd7_Update1(CPpmd7 *p);\r
-void Ppmd7_Update1_0(CPpmd7 *p);\r
-void Ppmd7_Update2(CPpmd7 *p);\r
-void Ppmd7_UpdateBin(CPpmd7 *p);\r
-\r
-#define Ppmd7_GetBinSumm(p) \\r
-    &p->BinSumm[(unsigned)Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \\r
-    p->NS2BSIndx[Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \\r
-    (p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \\r
-    2 * p->HB2Flag[(unsigned)Ppmd7Context_OneState(p->MinContext)->Symbol] + \\r
-    ((p->RunLength >> 26) & 0x20)]\r
-\r
-CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *scale);\r
-\r
-\r
-/* ---------- Decode ---------- */\r
-\r
-typedef struct\r
-{\r
-  UInt32 (*GetThreshold)(void *p, UInt32 total);\r
-  void (*Decode)(void *p, UInt32 start, UInt32 size);\r
-  UInt32 (*DecodeBit)(void *p, UInt32 size0);\r
-} IPpmd7_RangeDec;\r
-\r
-typedef struct\r
-{\r
-  IPpmd7_RangeDec p;\r
-  UInt32 Range;\r
-  UInt32 Code;\r
-  IByteIn *Stream;\r
-} CPpmd7z_RangeDec;\r
-\r
-void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p);\r
-Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p);\r
-#define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0)\r
-\r
-int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc);\r
-\r
-\r
-/* ---------- Encode ---------- */\r
-\r
-typedef struct\r
-{\r
-  UInt64 Low;\r
-  UInt32 Range;\r
-  Byte Cache;\r
-  UInt64 CacheSize;\r
-  IByteOut *Stream;\r
-} CPpmd7z_RangeEnc;\r
-\r
-void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p);\r
-void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p);\r
-\r
-void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol);\r
-\r
-EXTERN_C_END\r
\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Ppmd7Dec.c b/deps/lzma-16.04/C/Ppmd7Dec.c
deleted file mode 100644 (file)
index 3d01d76..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-/* Ppmd7Dec.c -- PPMdH Decoder\r
-2010-03-12 : Igor Pavlov : Public domain\r
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Ppmd7.h"\r
-\r
-#define kTopValue (1 << 24)\r
-\r
-Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p)\r
-{\r
-  unsigned i;\r
-  p->Code = 0;\r
-  p->Range = 0xFFFFFFFF;\r
-  if (p->Stream->Read((void *)p->Stream) != 0)\r
-    return False;\r
-  for (i = 0; i < 4; i++)\r
-    p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);\r
-  return (p->Code < 0xFFFFFFFF);\r
-}\r
-\r
-static UInt32 Range_GetThreshold(void *pp, UInt32 total)\r
-{\r
-  CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;\r
-  return (p->Code) / (p->Range /= total);\r
-}\r
-\r
-static void Range_Normalize(CPpmd7z_RangeDec *p)\r
-{\r
-  if (p->Range < kTopValue)\r
-  {\r
-    p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);\r
-    p->Range <<= 8;\r
-    if (p->Range < kTopValue)\r
-    {\r
-      p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);\r
-      p->Range <<= 8;\r
-    }\r
-  }\r
-}\r
-\r
-static void Range_Decode(void *pp, UInt32 start, UInt32 size)\r
-{\r
-  CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;\r
-  p->Code -= start * p->Range;\r
-  p->Range *= size;\r
-  Range_Normalize(p);\r
-}\r
-\r
-static UInt32 Range_DecodeBit(void *pp, UInt32 size0)\r
-{\r
-  CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;\r
-  UInt32 newBound = (p->Range >> 14) * size0;\r
-  UInt32 symbol;\r
-  if (p->Code < newBound)\r
-  {\r
-    symbol = 0;\r
-    p->Range = newBound;\r
-  }\r
-  else\r
-  {\r
-    symbol = 1;\r
-    p->Code -= newBound;\r
-    p->Range -= newBound;\r
-  }\r
-  Range_Normalize(p);\r
-  return symbol;\r
-}\r
-\r
-void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p)\r
-{\r
-  p->p.GetThreshold = Range_GetThreshold;\r
-  p->p.Decode = Range_Decode;\r
-  p->p.DecodeBit = Range_DecodeBit;\r
-}\r
-\r
-\r
-#define MASK(sym) ((signed char *)charMask)[sym]\r
-\r
-int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc)\r
-{\r
-  size_t charMask[256 / sizeof(size_t)];\r
-  if (p->MinContext->NumStats != 1)\r
-  {\r
-    CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext);\r
-    unsigned i;\r
-    UInt32 count, hiCnt;\r
-    if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq))\r
-    {\r
-      Byte symbol;\r
-      rc->Decode(rc, 0, s->Freq);\r
-      p->FoundState = s;\r
-      symbol = s->Symbol;\r
-      Ppmd7_Update1_0(p);\r
-      return symbol;\r
-    }\r
-    p->PrevSuccess = 0;\r
-    i = p->MinContext->NumStats - 1;\r
-    do\r
-    {\r
-      if ((hiCnt += (++s)->Freq) > count)\r
-      {\r
-        Byte symbol;\r
-        rc->Decode(rc, hiCnt - s->Freq, s->Freq);\r
-        p->FoundState = s;\r
-        symbol = s->Symbol;\r
-        Ppmd7_Update1(p);\r
-        return symbol;\r
-      }\r
-    }\r
-    while (--i);\r
-    if (count >= p->MinContext->SummFreq)\r
-      return -2;\r
-    p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];\r
-    rc->Decode(rc, hiCnt, p->MinContext->SummFreq - hiCnt);\r
-    PPMD_SetAllBitsIn256Bytes(charMask);\r
-    MASK(s->Symbol) = 0;\r
-    i = p->MinContext->NumStats - 1;\r
-    do { MASK((--s)->Symbol) = 0; } while (--i);\r
-  }\r
-  else\r
-  {\r
-    UInt16 *prob = Ppmd7_GetBinSumm(p);\r
-    if (rc->DecodeBit(rc, *prob) == 0)\r
-    {\r
-      Byte symbol;\r
-      *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);\r
-      symbol = (p->FoundState = Ppmd7Context_OneState(p->MinContext))->Symbol;\r
-      Ppmd7_UpdateBin(p);\r
-      return symbol;\r
-    }\r
-    *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);\r
-    p->InitEsc = PPMD7_kExpEscape[*prob >> 10];\r
-    PPMD_SetAllBitsIn256Bytes(charMask);\r
-    MASK(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0;\r
-    p->PrevSuccess = 0;\r
-  }\r
-  for (;;)\r
-  {\r
-    CPpmd_State *ps[256], *s;\r
-    UInt32 freqSum, count, hiCnt;\r
-    CPpmd_See *see;\r
-    unsigned i, num, numMasked = p->MinContext->NumStats;\r
-    do\r
-    {\r
-      p->OrderFall++;\r
-      if (!p->MinContext->Suffix)\r
-        return -1;\r
-      p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix);\r
-    }\r
-    while (p->MinContext->NumStats == numMasked);\r
-    hiCnt = 0;\r
-    s = Ppmd7_GetStats(p, p->MinContext);\r
-    i = 0;\r
-    num = p->MinContext->NumStats - numMasked;\r
-    do\r
-    {\r
-      int k = (int)(MASK(s->Symbol));\r
-      hiCnt += (s->Freq & k);\r
-      ps[i] = s++;\r
-      i -= k;\r
-    }\r
-    while (i != num);\r
-    \r
-    see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum);\r
-    freqSum += hiCnt;\r
-    count = rc->GetThreshold(rc, freqSum);\r
-    \r
-    if (count < hiCnt)\r
-    {\r
-      Byte symbol;\r
-      CPpmd_State **pps = ps;\r
-      for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++);\r
-      s = *pps;\r
-      rc->Decode(rc, hiCnt - s->Freq, s->Freq);\r
-      Ppmd_See_Update(see);\r
-      p->FoundState = s;\r
-      symbol = s->Symbol;\r
-      Ppmd7_Update2(p);\r
-      return symbol;\r
-    }\r
-    if (count >= freqSum)\r
-      return -2;\r
-    rc->Decode(rc, hiCnt, freqSum - hiCnt);\r
-    see->Summ = (UInt16)(see->Summ + freqSum);\r
-    do { MASK(ps[--i]->Symbol) = 0; } while (i != 0);\r
-  }\r
-}\r
diff --git a/deps/lzma-16.04/C/Ppmd7Enc.c b/deps/lzma-16.04/C/Ppmd7Enc.c
deleted file mode 100644 (file)
index 9b49e5d..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-/* Ppmd7Enc.c -- PPMdH Encoder\r
-2015-09-28 : Igor Pavlov : Public domain\r
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "Ppmd7.h"\r
-\r
-#define kTopValue (1 << 24)\r
-\r
-void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p)\r
-{\r
-  p->Low = 0;\r
-  p->Range = 0xFFFFFFFF;\r
-  p->Cache = 0;\r
-  p->CacheSize = 1;\r
-}\r
-\r
-static void RangeEnc_ShiftLow(CPpmd7z_RangeEnc *p)\r
-{\r
-  if ((UInt32)p->Low < (UInt32)0xFF000000 || (unsigned)(p->Low >> 32) != 0)\r
-  {\r
-    Byte temp = p->Cache;\r
-    do\r
-    {\r
-      p->Stream->Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32)));\r
-      temp = 0xFF;\r
-    }\r
-    while (--p->CacheSize != 0);\r
-    p->Cache = (Byte)((UInt32)p->Low >> 24);\r
-  }\r
-  p->CacheSize++;\r
-  p->Low = (UInt32)p->Low << 8;\r
-}\r
-\r
-static void RangeEnc_Encode(CPpmd7z_RangeEnc *p, UInt32 start, UInt32 size, UInt32 total)\r
-{\r
-  p->Low += start * (p->Range /= total);\r
-  p->Range *= size;\r
-  while (p->Range < kTopValue)\r
-  {\r
-    p->Range <<= 8;\r
-    RangeEnc_ShiftLow(p);\r
-  }\r
-}\r
-\r
-static void RangeEnc_EncodeBit_0(CPpmd7z_RangeEnc *p, UInt32 size0)\r
-{\r
-  p->Range = (p->Range >> 14) * size0;\r
-  while (p->Range < kTopValue)\r
-  {\r
-    p->Range <<= 8;\r
-    RangeEnc_ShiftLow(p);\r
-  }\r
-}\r
-\r
-static void RangeEnc_EncodeBit_1(CPpmd7z_RangeEnc *p, UInt32 size0)\r
-{\r
-  UInt32 newBound = (p->Range >> 14) * size0;\r
-  p->Low += newBound;\r
-  p->Range -= newBound;\r
-  while (p->Range < kTopValue)\r
-  {\r
-    p->Range <<= 8;\r
-    RangeEnc_ShiftLow(p);\r
-  }\r
-}\r
-\r
-void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < 5; i++)\r
-    RangeEnc_ShiftLow(p);\r
-}\r
-\r
-\r
-#define MASK(sym) ((signed char *)charMask)[sym]\r
-\r
-void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol)\r
-{\r
-  size_t charMask[256 / sizeof(size_t)];\r
-  if (p->MinContext->NumStats != 1)\r
-  {\r
-    CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext);\r
-    UInt32 sum;\r
-    unsigned i;\r
-    if (s->Symbol == symbol)\r
-    {\r
-      RangeEnc_Encode(rc, 0, s->Freq, p->MinContext->SummFreq);\r
-      p->FoundState = s;\r
-      Ppmd7_Update1_0(p);\r
-      return;\r
-    }\r
-    p->PrevSuccess = 0;\r
-    sum = s->Freq;\r
-    i = p->MinContext->NumStats - 1;\r
-    do\r
-    {\r
-      if ((++s)->Symbol == symbol)\r
-      {\r
-        RangeEnc_Encode(rc, sum, s->Freq, p->MinContext->SummFreq);\r
-        p->FoundState = s;\r
-        Ppmd7_Update1(p);\r
-        return;\r
-      }\r
-      sum += s->Freq;\r
-    }\r
-    while (--i);\r
-    \r
-    p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];\r
-    PPMD_SetAllBitsIn256Bytes(charMask);\r
-    MASK(s->Symbol) = 0;\r
-    i = p->MinContext->NumStats - 1;\r
-    do { MASK((--s)->Symbol) = 0; } while (--i);\r
-    RangeEnc_Encode(rc, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq);\r
-  }\r
-  else\r
-  {\r
-    UInt16 *prob = Ppmd7_GetBinSumm(p);\r
-    CPpmd_State *s = Ppmd7Context_OneState(p->MinContext);\r
-    if (s->Symbol == symbol)\r
-    {\r
-      RangeEnc_EncodeBit_0(rc, *prob);\r
-      *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);\r
-      p->FoundState = s;\r
-      Ppmd7_UpdateBin(p);\r
-      return;\r
-    }\r
-    else\r
-    {\r
-      RangeEnc_EncodeBit_1(rc, *prob);\r
-      *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);\r
-      p->InitEsc = PPMD7_kExpEscape[*prob >> 10];\r
-      PPMD_SetAllBitsIn256Bytes(charMask);\r
-      MASK(s->Symbol) = 0;\r
-      p->PrevSuccess = 0;\r
-    }\r
-  }\r
-  for (;;)\r
-  {\r
-    UInt32 escFreq;\r
-    CPpmd_See *see;\r
-    CPpmd_State *s;\r
-    UInt32 sum;\r
-    unsigned i, numMasked = p->MinContext->NumStats;\r
-    do\r
-    {\r
-      p->OrderFall++;\r
-      if (!p->MinContext->Suffix)\r
-        return; /* EndMarker (symbol = -1) */\r
-      p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix);\r
-    }\r
-    while (p->MinContext->NumStats == numMasked);\r
-    \r
-    see = Ppmd7_MakeEscFreq(p, numMasked, &escFreq);\r
-    s = Ppmd7_GetStats(p, p->MinContext);\r
-    sum = 0;\r
-    i = p->MinContext->NumStats;\r
-    do\r
-    {\r
-      int cur = s->Symbol;\r
-      if (cur == symbol)\r
-      {\r
-        UInt32 low = sum;\r
-        CPpmd_State *s1 = s;\r
-        do\r
-        {\r
-          sum += (s->Freq & (int)(MASK(s->Symbol)));\r
-          s++;\r
-        }\r
-        while (--i);\r
-        RangeEnc_Encode(rc, low, s1->Freq, sum + escFreq);\r
-        Ppmd_See_Update(see);\r
-        p->FoundState = s1;\r
-        Ppmd7_Update2(p);\r
-        return;\r
-      }\r
-      sum += (s->Freq & (int)(MASK(cur)));\r
-      MASK(cur) = 0;\r
-      s++;\r
-    }\r
-    while (--i);\r
-    \r
-    RangeEnc_Encode(rc, sum, escFreq, sum + escFreq);\r
-    see->Summ = (UInt16)(see->Summ + sum + escFreq);\r
-  }\r
-}\r
diff --git a/deps/lzma-16.04/C/RotateDefs.h b/deps/lzma-16.04/C/RotateDefs.h
deleted file mode 100644 (file)
index 6c790e7..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* RotateDefs.h -- Rotate functions\r
-2015-03-25 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __ROTATE_DEFS_H\r
-#define __ROTATE_DEFS_H\r
-\r
-#ifdef _MSC_VER\r
-\r
-#include <stdlib.h>\r
-\r
-/* don't use _rotl with MINGW. It can insert slow call to function. */\r
\r
-/* #if (_MSC_VER >= 1200) */\r
-#pragma intrinsic(_rotl)\r
-#pragma intrinsic(_rotr)\r
-/* #endif */\r
-\r
-#define rotlFixed(x, n) _rotl((x), (n))\r
-#define rotrFixed(x, n) _rotr((x), (n))\r
-\r
-#else\r
-\r
-/* new compilers can translate these macros to fast commands. */\r
-\r
-#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n))))\r
-#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n))))\r
-\r
-#endif\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Sha256.c b/deps/lzma-16.04/C/Sha256.c
deleted file mode 100644 (file)
index 47e2f42..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-/* Crypto/Sha256.c -- SHA-256 Hash\r
-2015-11-14 : Igor Pavlov : Public domain\r
-This code is based on public domain code from Wei Dai's Crypto++ library. */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-#include "CpuArch.h"\r
-#include "RotateDefs.h"\r
-#include "Sha256.h"\r
-\r
-/* define it for speed optimization */\r
-#ifndef _SFX\r
-#define _SHA256_UNROLL\r
-#define _SHA256_UNROLL2\r
-#endif\r
-\r
-/* #define _SHA256_UNROLL2 */\r
-\r
-void Sha256_Init(CSha256 *p)\r
-{\r
-  p->state[0] = 0x6a09e667;\r
-  p->state[1] = 0xbb67ae85;\r
-  p->state[2] = 0x3c6ef372;\r
-  p->state[3] = 0xa54ff53a;\r
-  p->state[4] = 0x510e527f;\r
-  p->state[5] = 0x9b05688c;\r
-  p->state[6] = 0x1f83d9ab;\r
-  p->state[7] = 0x5be0cd19;\r
-  p->count = 0;\r
-}\r
-\r
-#define S0(x) (rotrFixed(x, 2) ^ rotrFixed(x,13) ^ rotrFixed(x, 22))\r
-#define S1(x) (rotrFixed(x, 6) ^ rotrFixed(x,11) ^ rotrFixed(x, 25))\r
-#define s0(x) (rotrFixed(x, 7) ^ rotrFixed(x,18) ^ (x >> 3))\r
-#define s1(x) (rotrFixed(x,17) ^ rotrFixed(x,19) ^ (x >> 10))\r
-\r
-#define blk0(i) (W[i])\r
-#define blk2(i) (W[i] += s1(W[((i)-2)&15]) + W[((i)-7)&15] + s0(W[((i)-15)&15]))\r
-\r
-#define Ch(x,y,z) (z^(x&(y^z)))\r
-#define Maj(x,y,z) ((x&y)|(z&(x|y)))\r
-\r
-#ifdef _SHA256_UNROLL2\r
-\r
-#define R(a,b,c,d,e,f,g,h, i) \\r
-    h += S1(e) + Ch(e,f,g) + K[(i)+(j)] + (j ? blk2(i) : blk0(i)); \\r
-    d += h; \\r
-    h += S0(a) + Maj(a, b, c)\r
-\r
-#define RX_8(i) \\r
-  R(a,b,c,d,e,f,g,h, i); \\r
-  R(h,a,b,c,d,e,f,g, i+1); \\r
-  R(g,h,a,b,c,d,e,f, i+2); \\r
-  R(f,g,h,a,b,c,d,e, i+3); \\r
-  R(e,f,g,h,a,b,c,d, i+4); \\r
-  R(d,e,f,g,h,a,b,c, i+5); \\r
-  R(c,d,e,f,g,h,a,b, i+6); \\r
-  R(b,c,d,e,f,g,h,a, i+7)\r
-\r
-#define RX_16  RX_8(0); RX_8(8);\r
-\r
-#else\r
-\r
-#define a(i) T[(0-(i))&7]\r
-#define b(i) T[(1-(i))&7]\r
-#define c(i) T[(2-(i))&7]\r
-#define d(i) T[(3-(i))&7]\r
-#define e(i) T[(4-(i))&7]\r
-#define f(i) T[(5-(i))&7]\r
-#define g(i) T[(6-(i))&7]\r
-#define h(i) T[(7-(i))&7]\r
-\r
-#define R(i) \\r
-    h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[(i)+(j)] + (j ? blk2(i) : blk0(i)); \\r
-    d(i) += h(i); \\r
-    h(i) += S0(a(i)) + Maj(a(i), b(i), c(i)) \\r
-\r
-#ifdef _SHA256_UNROLL\r
-\r
-#define RX_8(i)  R(i+0); R(i+1); R(i+2); R(i+3); R(i+4); R(i+5); R(i+6); R(i+7);\r
-#define RX_16  RX_8(0); RX_8(8);\r
-\r
-#else\r
-\r
-#define RX_16  unsigned i; for (i = 0; i < 16; i++) { R(i); }\r
-\r
-#endif\r
-\r
-#endif\r
-\r
-static const UInt32 K[64] = {\r
-  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\r
-  0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\r
-  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\r
-  0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\r
-  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,\r
-  0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\r
-  0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\r
-  0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\r
-  0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\r
-  0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\r
-  0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,\r
-  0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\r
-  0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,\r
-  0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\r
-  0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\r
-  0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2\r
-};\r
-\r
-static void Sha256_WriteByteBlock(CSha256 *p)\r
-{\r
-  UInt32 W[16];\r
-  unsigned j;\r
-  UInt32 *state;\r
-\r
-  #ifdef _SHA256_UNROLL2\r
-  UInt32 a,b,c,d,e,f,g,h;\r
-  #else\r
-  UInt32 T[8];\r
-  #endif\r
-\r
-  for (j = 0; j < 16; j += 4)\r
-  {\r
-    const Byte *ccc = p->buffer + j * 4;\r
-    W[j    ] = GetBe32(ccc);\r
-    W[j + 1] = GetBe32(ccc + 4);\r
-    W[j + 2] = GetBe32(ccc + 8);\r
-    W[j + 3] = GetBe32(ccc + 12);\r
-  }\r
-\r
-  state = p->state;\r
-\r
-  #ifdef _SHA256_UNROLL2\r
-  a = state[0];\r
-  b = state[1];\r
-  c = state[2];\r
-  d = state[3];\r
-  e = state[4];\r
-  f = state[5];\r
-  g = state[6];\r
-  h = state[7];\r
-  #else\r
-  for (j = 0; j < 8; j++)\r
-    T[j] = state[j];\r
-  #endif\r
-\r
-  for (j = 0; j < 64; j += 16)\r
-  {\r
-    RX_16\r
-  }\r
-\r
-  #ifdef _SHA256_UNROLL2\r
-  state[0] += a;\r
-  state[1] += b;\r
-  state[2] += c;\r
-  state[3] += d;\r
-  state[4] += e;\r
-  state[5] += f;\r
-  state[6] += g;\r
-  state[7] += h;\r
-  #else\r
-  for (j = 0; j < 8; j++)\r
-    state[j] += T[j];\r
-  #endif\r
-  \r
-  /* Wipe variables */\r
-  /* memset(W, 0, sizeof(W)); */\r
-  /* memset(T, 0, sizeof(T)); */\r
-}\r
-\r
-#undef S0\r
-#undef S1\r
-#undef s0\r
-#undef s1\r
-\r
-void Sha256_Update(CSha256 *p, const Byte *data, size_t size)\r
-{\r
-  if (size == 0)\r
-    return;\r
-\r
-  {\r
-    unsigned pos = (unsigned)p->count & 0x3F;\r
-    unsigned num;\r
-    \r
-    p->count += size;\r
-    \r
-    num = 64 - pos;\r
-    if (num > size)\r
-    {\r
-      memcpy(p->buffer + pos, data, size);\r
-      return;\r
-    }\r
-    \r
-    size -= num;\r
-    memcpy(p->buffer + pos, data, num);\r
-    data += num;\r
-  }\r
-\r
-  for (;;)\r
-  {\r
-    Sha256_WriteByteBlock(p);\r
-    if (size < 64)\r
-      break;\r
-    size -= 64;\r
-    memcpy(p->buffer, data, 64);\r
-    data += 64;\r
-  }\r
-\r
-  if (size != 0)\r
-    memcpy(p->buffer, data, size);\r
-}\r
-\r
-void Sha256_Final(CSha256 *p, Byte *digest)\r
-{\r
-  unsigned pos = (unsigned)p->count & 0x3F;\r
-  unsigned i;\r
-  \r
-  p->buffer[pos++] = 0x80;\r
-  \r
-  while (pos != (64 - 8))\r
-  {\r
-    pos &= 0x3F;\r
-    if (pos == 0)\r
-      Sha256_WriteByteBlock(p);\r
-    p->buffer[pos++] = 0;\r
-  }\r
-\r
-  {\r
-    UInt64 numBits = (p->count << 3);\r
-    SetBe32(p->buffer + 64 - 8, (UInt32)(numBits >> 32));\r
-    SetBe32(p->buffer + 64 - 4, (UInt32)(numBits));\r
-  }\r
-  \r
-  Sha256_WriteByteBlock(p);\r
-\r
-  for (i = 0; i < 8; i += 2)\r
-  {\r
-    UInt32 v0 = p->state[i];\r
-    UInt32 v1 = p->state[i + 1];\r
-    SetBe32(digest    , v0);\r
-    SetBe32(digest + 4, v1);\r
-    digest += 8;\r
-  }\r
-  \r
-  Sha256_Init(p);\r
-}\r
diff --git a/deps/lzma-16.04/C/Sha256.h b/deps/lzma-16.04/C/Sha256.h
deleted file mode 100644 (file)
index 7f17ccf..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Sha256.h -- SHA-256 Hash\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __CRYPTO_SHA256_H\r
-#define __CRYPTO_SHA256_H\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define SHA256_DIGEST_SIZE 32\r
-\r
-typedef struct\r
-{\r
-  UInt32 state[8];\r
-  UInt64 count;\r
-  Byte buffer[64];\r
-} CSha256;\r
-\r
-void Sha256_Init(CSha256 *p);\r
-void Sha256_Update(CSha256 *p, const Byte *data, size_t size);\r
-void Sha256_Final(CSha256 *p, Byte *digest);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Threads.c b/deps/lzma-16.04/C/Threads.c
deleted file mode 100644 (file)
index ece07e6..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/* Threads.c -- multithreading library\r
-2014-09-21 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#ifndef UNDER_CE\r
-#include <process.h>\r
-#endif\r
-\r
-#include "Threads.h"\r
-\r
-static WRes GetError()\r
-{\r
-  DWORD res = GetLastError();\r
-  return (res) ? (WRes)(res) : 1;\r
-}\r
-\r
-WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }\r
-WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }\r
-\r
-WRes HandlePtr_Close(HANDLE *p)\r
-{\r
-  if (*p != NULL)\r
-    if (!CloseHandle(*p))\r
-      return GetError();\r
-  *p = NULL;\r
-  return 0;\r
-}\r
-\r
-WRes Handle_WaitObject(HANDLE h) { return (WRes)WaitForSingleObject(h, INFINITE); }\r
-\r
-WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param)\r
-{\r
-  /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r
-  \r
-  #ifdef UNDER_CE\r
-  \r
-  DWORD threadId;\r
-  *p = CreateThread(0, 0, func, param, 0, &threadId);\r
-\r
-  #else\r
-\r
-  unsigned threadId;\r
-  *p = (HANDLE)_beginthreadex(NULL, 0, func, param, 0, &threadId);\r
-   \r
-  #endif\r
-\r
-  /* maybe we must use errno here, but probably GetLastError() is also OK. */\r
-  return HandleToWRes(*p);\r
-}\r
-\r
-WRes Event_Create(CEvent *p, BOOL manualReset, int signaled)\r
-{\r
-  *p = CreateEvent(NULL, manualReset, (signaled ? TRUE : FALSE), NULL);\r
-  return HandleToWRes(*p);\r
-}\r
-\r
-WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(*p)); }\r
-WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(*p)); }\r
-\r
-WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled) { return Event_Create(p, TRUE, signaled); }\r
-WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled) { return Event_Create(p, FALSE, signaled); }\r
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) { return ManualResetEvent_Create(p, 0); }\r
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) { return AutoResetEvent_Create(p, 0); }\r
-\r
-\r
-WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount)\r
-{\r
-  *p = CreateSemaphore(NULL, (LONG)initCount, (LONG)maxCount, NULL);\r
-  return HandleToWRes(*p);\r
-}\r
-\r
-static WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)\r
-  { return BOOLToWRes(ReleaseSemaphore(*p, releaseCount, previousCount)); }\r
-WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num)\r
-  { return Semaphore_Release(p, (LONG)num, NULL); }\r
-WRes Semaphore_Release1(CSemaphore *p) { return Semaphore_ReleaseN(p, 1); }\r
-\r
-WRes CriticalSection_Init(CCriticalSection *p)\r
-{\r
-  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\r
-  #ifdef _MSC_VER\r
-  __try\r
-  #endif\r
-  {\r
-    InitializeCriticalSection(p);\r
-    /* InitializeCriticalSectionAndSpinCount(p, 0); */\r
-  }\r
-  #ifdef _MSC_VER\r
-  __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }\r
-  #endif\r
-  return 0;\r
-}\r
diff --git a/deps/lzma-16.04/C/Threads.h b/deps/lzma-16.04/C/Threads.h
deleted file mode 100644 (file)
index e927208..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Threads.h -- multithreading library\r
-2013-11-12 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_THREADS_H\r
-#define __7Z_THREADS_H\r
-\r
-#ifdef _WIN32\r
-#include <windows.h>\r
-#endif\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-WRes HandlePtr_Close(HANDLE *h);\r
-WRes Handle_WaitObject(HANDLE h);\r
-\r
-typedef HANDLE CThread;\r
-#define Thread_Construct(p) *(p) = NULL\r
-#define Thread_WasCreated(p) (*(p) != NULL)\r
-#define Thread_Close(p) HandlePtr_Close(p)\r
-#define Thread_Wait(p) Handle_WaitObject(*(p))\r
-\r
-typedef\r
-#ifdef UNDER_CE\r
-  DWORD\r
-#else\r
-  unsigned\r
-#endif\r
-  THREAD_FUNC_RET_TYPE;\r
-\r
-#define THREAD_FUNC_CALL_TYPE MY_STD_CALL\r
-#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r
-typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *);\r
-WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param);\r
-\r
-typedef HANDLE CEvent;\r
-typedef CEvent CAutoResetEvent;\r
-typedef CEvent CManualResetEvent;\r
-#define Event_Construct(p) *(p) = NULL\r
-#define Event_IsCreated(p) (*(p) != NULL)\r
-#define Event_Close(p) HandlePtr_Close(p)\r
-#define Event_Wait(p) Handle_WaitObject(*(p))\r
-WRes Event_Set(CEvent *p);\r
-WRes Event_Reset(CEvent *p);\r
-WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled);\r
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p);\r
-WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled);\r
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p);\r
-\r
-typedef HANDLE CSemaphore;\r
-#define Semaphore_Construct(p) (*p) = NULL\r
-#define Semaphore_Close(p) HandlePtr_Close(p)\r
-#define Semaphore_Wait(p) Handle_WaitObject(*(p))\r
-WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount);\r
-WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\r
-WRes Semaphore_Release1(CSemaphore *p);\r
-\r
-typedef CRITICAL_SECTION CCriticalSection;\r
-WRes CriticalSection_Init(CCriticalSection *p);\r
-#define CriticalSection_Delete(p) DeleteCriticalSection(p)\r
-#define CriticalSection_Enter(p) EnterCriticalSection(p)\r
-#define CriticalSection_Leave(p) LeaveCriticalSection(p)\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Util/7z/7z.dsp b/deps/lzma-16.04/C/Util/7z/7z.dsp
deleted file mode 100644 (file)
index d3bf0fe..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-# Microsoft Developer Studio Project File - Name="7z" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=7z - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "7z.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "7z.mak" CFG="7z - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "7z - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "7z - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "7z - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir "Release"\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MD /W4 /WX /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /FAcs /Yu"Precomp.h" /FD /c\r
-# ADD BASE RSC /l 0x419 /d "NDEBUG"\r
-# ADD RSC /l 0x419 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\util\7zDec.exe" /opt:NOWIN98\r
-# SUBTRACT LINK32 /pdb:none\r
-\r
-!ELSEIF  "$(CFG)" == "7z - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "Debug"\r
-# PROP BASE Intermediate_Dir "Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir "Debug"\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W4 /WX /Gm /GX /ZI /Od /D "_DEBUG" /D "_SZ_ALLOC_DEBUG2" /D "_SZ_NO_INT_64_A" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Yu"Precomp.h" /FD /GZ /c\r
-# ADD BASE RSC /l 0x419 /d "_DEBUG"\r
-# ADD RSC /l 0x419 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\util\7zDec.exe" /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "7z - Win32 Release"\r
-# Name "7z - Win32 Debug"\r
-# Begin Group "Common"\r
-\r
-# PROP Default_Filter ""\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7z.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zAlloc.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zAlloc.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zArcIn.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zBuf.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zBuf.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zCrc.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zCrc.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zCrcOpt.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zDec.c\r
-# ADD CPP /D "_7ZIP_PPMD_SUPPPORT"\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zFile.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zFile.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zStream.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zTypes.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bcj2.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bcj2.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bra.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bra.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bra86.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\BraIA64.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\CpuArch.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\CpuArch.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Delta.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Delta.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Lzma2Dec.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Lzma2Dec.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaDec.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaDec.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Ppmd.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Ppmd7.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Ppmd7.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Ppmd7Dec.c\r
-# End Source File\r
-# End Group\r
-# Begin Group "Spec"\r
-\r
-# PROP Default_Filter ""\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Compiler.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\Precomp.c\r
-# ADD CPP /Yc"Precomp.h"\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\Precomp.h\r
-# End Source File\r
-# End Group\r
-# Begin Source File\r
-\r
-SOURCE=.\7zMain.c\r
-# End Source File\r
-# End Target\r
-# End Project\r
diff --git a/deps/lzma-16.04/C/Util/7z/7z.dsw b/deps/lzma-16.04/C/Util/7z/7z.dsw
deleted file mode 100644 (file)
index 23089fb..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00\r
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
-\r
-###############################################################################\r
-\r
-Project: "7z"=.\7z.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Global:\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<3>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
diff --git a/deps/lzma-16.04/C/Util/7z/7zMain.c b/deps/lzma-16.04/C/Util/7z/7zMain.c
deleted file mode 100644 (file)
index 92bce0a..0000000
+++ /dev/null
@@ -1,604 +0,0 @@
-/* 7zMain.c - Test application for 7z Decoder\r
-2016-05-16 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-\r
-#include "../../7z.h"\r
-#include "../../7zAlloc.h"\r
-#include "../../7zBuf.h"\r
-#include "../../7zCrc.h"\r
-#include "../../7zFile.h"\r
-#include "../../7zVersion.h"\r
-\r
-#ifndef USE_WINDOWS_FILE\r
-/* for mkdir */\r
-#ifdef _WIN32\r
-#include <direct.h>\r
-#else\r
-#include <sys/stat.h>\r
-#include <errno.h>\r
-#endif\r
-#endif\r
-\r
-static ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
-\r
-static int Buf_EnsureSize(CBuf *dest, size_t size)\r
-{\r
-  if (dest->size >= size)\r
-    return 1;\r
-  Buf_Free(dest, &g_Alloc);\r
-  return Buf_Create(dest, size, &g_Alloc);\r
-}\r
-\r
-#ifndef _WIN32\r
-#define _USE_UTF8\r
-#endif\r
-\r
-/* #define _USE_UTF8 */\r
-\r
-#ifdef _USE_UTF8\r
-\r
-#define _UTF8_START(n) (0x100 - (1 << (7 - (n))))\r
-\r
-#define _UTF8_RANGE(n) (((UInt32)1) << ((n) * 5 + 6))\r
-\r
-#define _UTF8_HEAD(n, val) ((Byte)(_UTF8_START(n) + (val >> (6 * (n)))))\r
-#define _UTF8_CHAR(n, val) ((Byte)(0x80 + (((val) >> (6 * (n))) & 0x3F)))\r
-\r
-static size_t Utf16_To_Utf8_Calc(const UInt16 *src, const UInt16 *srcLim)\r
-{\r
-  size_t size = 0;\r
-  for (;;)\r
-  {\r
-    UInt32 val;\r
-    if (src == srcLim)\r
-      return size;\r
-    \r
-    size++;\r
-    val = *src++;\r
-   \r
-    if (val < 0x80)\r
-      continue;\r
-\r
-    if (val < _UTF8_RANGE(1))\r
-    {\r
-      size++;\r
-      continue;\r
-    }\r
-\r
-    if (val >= 0xD800 && val < 0xDC00 && src != srcLim)\r
-    {\r
-      UInt32 c2 = *src;\r
-      if (c2 >= 0xDC00 && c2 < 0xE000)\r
-      {\r
-        src++;\r
-        size += 3;\r
-        continue;\r
-      }\r
-    }\r
-\r
-    size += 2;\r
-  }\r
-}\r
-\r
-static Byte *Utf16_To_Utf8(Byte *dest, const UInt16 *src, const UInt16 *srcLim)\r
-{\r
-  for (;;)\r
-  {\r
-    UInt32 val;\r
-    if (src == srcLim)\r
-      return dest;\r
-    \r
-    val = *src++;\r
-    \r
-    if (val < 0x80)\r
-    {\r
-      *dest++ = (char)val;\r
-      continue;\r
-    }\r
-\r
-    if (val < _UTF8_RANGE(1))\r
-    {\r
-      dest[0] = _UTF8_HEAD(1, val);\r
-      dest[1] = _UTF8_CHAR(0, val);\r
-      dest += 2;\r
-      continue;\r
-    }\r
-\r
-    if (val >= 0xD800 && val < 0xDC00 && src != srcLim)\r
-    {\r
-      UInt32 c2 = *src;\r
-      if (c2 >= 0xDC00 && c2 < 0xE000)\r
-      {\r
-        src++;\r
-        val = (((val - 0xD800) << 10) | (c2 - 0xDC00)) + 0x10000;\r
-        dest[0] = _UTF8_HEAD(3, val);\r
-        dest[1] = _UTF8_CHAR(2, val);\r
-        dest[2] = _UTF8_CHAR(1, val);\r
-        dest[3] = _UTF8_CHAR(0, val);\r
-        dest += 4;\r
-        continue;\r
-      }\r
-    }\r
-    \r
-    dest[0] = _UTF8_HEAD(2, val);\r
-    dest[1] = _UTF8_CHAR(1, val);\r
-    dest[2] = _UTF8_CHAR(0, val);\r
-    dest += 3;\r
-  }\r
-}\r
-\r
-static SRes Utf16_To_Utf8Buf(CBuf *dest, const UInt16 *src, size_t srcLen)\r
-{\r
-  size_t destLen = Utf16_To_Utf8_Calc(src, src + srcLen);\r
-  destLen += 1;\r
-  if (!Buf_EnsureSize(dest, destLen))\r
-    return SZ_ERROR_MEM;\r
-  *Utf16_To_Utf8(dest->data, src, src + srcLen) = 0;\r
-  return SZ_OK;\r
-}\r
-\r
-#endif\r
-\r
-static SRes Utf16_To_Char(CBuf *buf, const UInt16 *s\r
-    #ifndef _USE_UTF8\r
-    , UINT codePage\r
-    #endif\r
-    )\r
-{\r
-  unsigned len = 0;\r
-  for (len = 0; s[len] != 0; len++);\r
-\r
-  #ifndef _USE_UTF8\r
-  {\r
-    unsigned size = len * 3 + 100;\r
-    if (!Buf_EnsureSize(buf, size))\r
-      return SZ_ERROR_MEM;\r
-    {\r
-      buf->data[0] = 0;\r
-      if (len != 0)\r
-      {\r
-        char defaultChar = '_';\r
-        BOOL defUsed;\r
-        unsigned numChars = 0;\r
-        numChars = WideCharToMultiByte(codePage, 0, s, len, (char *)buf->data, size, &defaultChar, &defUsed);\r
-        if (numChars == 0 || numChars >= size)\r
-          return SZ_ERROR_FAIL;\r
-        buf->data[numChars] = 0;\r
-      }\r
-      return SZ_OK;\r
-    }\r
-  }\r
-  #else\r
-  return Utf16_To_Utf8Buf(buf, s, len);\r
-  #endif\r
-}\r
-\r
-#ifdef _WIN32\r
-  #ifndef USE_WINDOWS_FILE\r
-    static UINT g_FileCodePage = CP_ACP;\r
-  #endif\r
-  #define MY_FILE_CODE_PAGE_PARAM ,g_FileCodePage\r
-#else\r
-  #define MY_FILE_CODE_PAGE_PARAM\r
-#endif\r
-\r
-static WRes MyCreateDir(const UInt16 *name)\r
-{\r
-  #ifdef USE_WINDOWS_FILE\r
-  \r
-  return CreateDirectoryW(name, NULL) ? 0 : GetLastError();\r
-  \r
-  #else\r
-\r
-  CBuf buf;\r
-  WRes res;\r
-  Buf_Init(&buf);\r
-  RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM));\r
-\r
-  res =\r
-  #ifdef _WIN32\r
-  _mkdir((const char *)buf.data)\r
-  #else\r
-  mkdir((const char *)buf.data, 0777)\r
-  #endif\r
-  == 0 ? 0 : errno;\r
-  Buf_Free(&buf, &g_Alloc);\r
-  return res;\r
-  \r
-  #endif\r
-}\r
-\r
-static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name)\r
-{\r
-  #ifdef USE_WINDOWS_FILE\r
-  return OutFile_OpenW(p, name);\r
-  #else\r
-  CBuf buf;\r
-  WRes res;\r
-  Buf_Init(&buf);\r
-  RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM));\r
-  res = OutFile_Open(p, (const char *)buf.data);\r
-  Buf_Free(&buf, &g_Alloc);\r
-  return res;\r
-  #endif\r
-}\r
-\r
-static SRes PrintString(const UInt16 *s)\r
-{\r
-  CBuf buf;\r
-  SRes res;\r
-  Buf_Init(&buf);\r
-  res = Utf16_To_Char(&buf, s\r
-      #ifndef _USE_UTF8\r
-      , CP_OEMCP\r
-      #endif\r
-      );\r
-  if (res == SZ_OK)\r
-    fputs((const char *)buf.data, stdout);\r
-  Buf_Free(&buf, &g_Alloc);\r
-  return res;\r
-}\r
-\r
-static void UInt64ToStr(UInt64 value, char *s)\r
-{\r
-  char temp[32];\r
-  int pos = 0;\r
-  do\r
-  {\r
-    temp[pos++] = (char)('0' + (unsigned)(value % 10));\r
-    value /= 10;\r
-  }\r
-  while (value != 0);\r
-  do\r
-    *s++ = temp[--pos];\r
-  while (pos);\r
-  *s = '\0';\r
-}\r
-\r
-static char *UIntToStr(char *s, unsigned value, int numDigits)\r
-{\r
-  char temp[16];\r
-  int pos = 0;\r
-  do\r
-    temp[pos++] = (char)('0' + (value % 10));\r
-  while (value /= 10);\r
-  for (numDigits -= pos; numDigits > 0; numDigits--)\r
-    *s++ = '0';\r
-  do\r
-    *s++ = temp[--pos];\r
-  while (pos);\r
-  *s = '\0';\r
-  return s;\r
-}\r
-\r
-static void UIntToStr_2(char *s, unsigned value)\r
-{\r
-  s[0] = (char)('0' + (value / 10));\r
-  s[1] = (char)('0' + (value % 10));\r
-}\r
-\r
-#define PERIOD_4 (4 * 365 + 1)\r
-#define PERIOD_100 (PERIOD_4 * 25 - 1)\r
-#define PERIOD_400 (PERIOD_100 * 4 + 1)\r
-\r
-static void ConvertFileTimeToString(const CNtfsFileTime *nt, char *s)\r
-{\r
-  unsigned year, mon, hour, min, sec;\r
-  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r
-  unsigned t;\r
-  UInt32 v;\r
-  UInt64 v64 = nt->Low | ((UInt64)nt->High << 32);\r
-  v64 /= 10000000;\r
-  sec = (unsigned)(v64 % 60); v64 /= 60;\r
-  min = (unsigned)(v64 % 60); v64 /= 60;\r
-  hour = (unsigned)(v64 % 24); v64 /= 24;\r
-\r
-  v = (UInt32)v64;\r
-\r
-  year = (unsigned)(1601 + v / PERIOD_400 * 400);\r
-  v %= PERIOD_400;\r
-\r
-  t = v / PERIOD_100; if (t ==  4) t =  3; year += t * 100; v -= t * PERIOD_100;\r
-  t = v / PERIOD_4;   if (t == 25) t = 24; year += t * 4;   v -= t * PERIOD_4;\r
-  t = v / 365;        if (t ==  4) t =  3; year += t;       v -= t * 365;\r
-\r
-  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r
-    ms[1] = 29;\r
-  for (mon = 0;; mon++)\r
-  {\r
-    unsigned d = ms[mon];\r
-    if (v < d)\r
-      break;\r
-    v -= d;\r
-  }\r
-  s = UIntToStr(s, year, 4); *s++ = '-';\r
-  UIntToStr_2(s, mon + 1); s[2] = '-'; s += 3;\r
-  UIntToStr_2(s, (unsigned)v + 1); s[2] = ' '; s += 3;\r
-  UIntToStr_2(s, hour); s[2] = ':'; s += 3;\r
-  UIntToStr_2(s, min); s[2] = ':'; s += 3;\r
-  UIntToStr_2(s, sec); s[2] = 0;\r
-}\r
-\r
-void PrintError(char *sz)\r
-{\r
-  printf("\nERROR: %s\n", sz);\r
-}\r
-\r
-static void GetAttribString(UInt32 wa, Bool isDir, char *s)\r
-{\r
-  #ifdef USE_WINDOWS_FILE\r
-  s[0] = (char)(((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : '.');\r
-  s[1] = (char)(((wa & FILE_ATTRIBUTE_READONLY ) != 0) ? 'R': '.');\r
-  s[2] = (char)(((wa & FILE_ATTRIBUTE_HIDDEN   ) != 0) ? 'H': '.');\r
-  s[3] = (char)(((wa & FILE_ATTRIBUTE_SYSTEM   ) != 0) ? 'S': '.');\r
-  s[4] = (char)(((wa & FILE_ATTRIBUTE_ARCHIVE  ) != 0) ? 'A': '.');\r
-  s[5] = 0;\r
-  #else\r
-  s[0] = (char)(((wa & (1 << 4)) != 0 || isDir) ? 'D' : '.');\r
-  s[1] = 0;\r
-  #endif\r
-}\r
-\r
-// #define NUM_PARENTS_MAX 128\r
-\r
-int MY_CDECL main(int numargs, char *args[])\r
-{\r
-  CFileInStream archiveStream;\r
-  CLookToRead lookStream;\r
-  CSzArEx db;\r
-  SRes res;\r
-  ISzAlloc allocImp;\r
-  ISzAlloc allocTempImp;\r
-  UInt16 *temp = NULL;\r
-  size_t tempSize = 0;\r
-  // UInt32 parents[NUM_PARENTS_MAX];\r
-\r
-  printf("\n7z ANSI-C Decoder " MY_VERSION_COPYRIGHT_DATE "\n\n");\r
-\r
-  if (numargs == 1)\r
-  {\r
-    printf(\r
-      "Usage: 7zDec <command> <archive_name>\n\n"\r
-      "<Commands>\n"\r
-      "  e: Extract files from archive (without using directory names)\n"\r
-      "  l: List contents of archive\n"\r
-      "  t: Test integrity of archive\n"\r
-      "  x: eXtract files with full paths\n");\r
-    return 0;\r
-  }\r
-  \r
-  if (numargs < 3)\r
-  {\r
-    PrintError("incorrect command");\r
-    return 1;\r
-  }\r
-\r
-  #if defined(_WIN32) && !defined(USE_WINDOWS_FILE) && !defined(UNDER_CE)\r
-  g_FileCodePage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;\r
-  #endif\r
-\r
-  allocImp.Alloc = SzAlloc;\r
-  allocImp.Free = SzFree;\r
-\r
-  allocTempImp.Alloc = SzAllocTemp;\r
-  allocTempImp.Free = SzFreeTemp;\r
-\r
-  #ifdef UNDER_CE\r
-  if (InFile_OpenW(&archiveStream.file, L"\test.7z"))\r
-  #else\r
-  if (InFile_Open(&archiveStream.file, args[2]))\r
-  #endif\r
-  {\r
-    PrintError("can not open input file");\r
-    return 1;\r
-  }\r
-\r
-  FileInStream_CreateVTable(&archiveStream);\r
-  LookToRead_CreateVTable(&lookStream, False);\r
-  \r
-  lookStream.realStream = &archiveStream.s;\r
-  LookToRead_Init(&lookStream);\r
-\r
-  CrcGenerateTable();\r
-\r
-  SzArEx_Init(&db);\r
-  \r
-  res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);\r
-  \r
-  if (res == SZ_OK)\r
-  {\r
-    char *command = args[1];\r
-    int listCommand = 0, testCommand = 0, fullPaths = 0;\r
-    \r
-    if (strcmp(command, "l") == 0) listCommand = 1;\r
-    else if (strcmp(command, "t") == 0) testCommand = 1;\r
-    else if (strcmp(command, "e") == 0) { }\r
-    else if (strcmp(command, "x") == 0) { fullPaths = 1; }\r
-    else\r
-    {\r
-      PrintError("incorrect command");\r
-      res = SZ_ERROR_FAIL;\r
-    }\r
-\r
-    if (res == SZ_OK)\r
-    {\r
-      UInt32 i;\r
-\r
-      /*\r
-      if you need cache, use these 3 variables.\r
-      if you use external function, you can make these variable as static.\r
-      */\r
-      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r
-      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r
-      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r
-\r
-      for (i = 0; i < db.NumFiles; i++)\r
-      {\r
-        size_t offset = 0;\r
-        size_t outSizeProcessed = 0;\r
-        // const CSzFileItem *f = db.Files + i;\r
-        size_t len;\r
-        unsigned isDir = SzArEx_IsDir(&db, i);\r
-        if (listCommand == 0 && isDir && !fullPaths)\r
-          continue;\r
-        len = SzArEx_GetFileNameUtf16(&db, i, NULL);\r
-        // len = SzArEx_GetFullNameLen(&db, i);\r
-\r
-        if (len > tempSize)\r
-        {\r
-          SzFree(NULL, temp);\r
-          tempSize = len;\r
-          temp = (UInt16 *)SzAlloc(NULL, tempSize * sizeof(temp[0]));\r
-          if (!temp)\r
-          {\r
-            res = SZ_ERROR_MEM;\r
-            break;\r
-          }\r
-        }\r
-\r
-        SzArEx_GetFileNameUtf16(&db, i, temp);\r
-        /*\r
-        if (SzArEx_GetFullNameUtf16_Back(&db, i, temp + len) != temp)\r
-        {\r
-          res = SZ_ERROR_FAIL;\r
-          break;\r
-        }\r
-        */\r
-\r
-        if (listCommand)\r
-        {\r
-          char attr[8], s[32], t[32];\r
-          UInt64 fileSize;\r
-\r
-          GetAttribString(SzBitWithVals_Check(&db.Attribs, i) ? db.Attribs.Vals[i] : 0, isDir, attr);\r
-\r
-          fileSize = SzArEx_GetFileSize(&db, i);\r
-          UInt64ToStr(fileSize, s);\r
-          \r
-          if (SzBitWithVals_Check(&db.MTime, i))\r
-            ConvertFileTimeToString(&db.MTime.Vals[i], t);\r
-          else\r
-          {\r
-            size_t j;\r
-            for (j = 0; j < 19; j++)\r
-              t[j] = ' ';\r
-            t[j] = '\0';\r
-          }\r
-          \r
-          printf("%s %s %10s  ", t, attr, s);\r
-          res = PrintString(temp);\r
-          if (res != SZ_OK)\r
-            break;\r
-          if (isDir)\r
-            printf("/");\r
-          printf("\n");\r
-          continue;\r
-        }\r
-\r
-        fputs(testCommand ?\r
-            "Testing    ":\r
-            "Extracting ",\r
-            stdout);\r
-        res = PrintString(temp);\r
-        if (res != SZ_OK)\r
-          break;\r
-        \r
-        if (isDir)\r
-          printf("/");\r
-        else\r
-        {\r
-          res = SzArEx_Extract(&db, &lookStream.s, i,\r
-              &blockIndex, &outBuffer, &outBufferSize,\r
-              &offset, &outSizeProcessed,\r
-              &allocImp, &allocTempImp);\r
-          if (res != SZ_OK)\r
-            break;\r
-        }\r
-        \r
-        if (!testCommand)\r
-        {\r
-          CSzFile outFile;\r
-          size_t processedSize;\r
-          size_t j;\r
-          UInt16 *name = (UInt16 *)temp;\r
-          const UInt16 *destPath = (const UInt16 *)name;\r
\r
-          for (j = 0; name[j] != 0; j++)\r
-            if (name[j] == '/')\r
-            {\r
-              if (fullPaths)\r
-              {\r
-                name[j] = 0;\r
-                MyCreateDir(name);\r
-                name[j] = CHAR_PATH_SEPARATOR;\r
-              }\r
-              else\r
-                destPath = name + j + 1;\r
-            }\r
-    \r
-          if (isDir)\r
-          {\r
-            MyCreateDir(destPath);\r
-            printf("\n");\r
-            continue;\r
-          }\r
-          else if (OutFile_OpenUtf16(&outFile, destPath))\r
-          {\r
-            PrintError("can not open output file");\r
-            res = SZ_ERROR_FAIL;\r
-            break;\r
-          }\r
-\r
-          processedSize = outSizeProcessed;\r
-          \r
-          if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 || processedSize != outSizeProcessed)\r
-          {\r
-            PrintError("can not write output file");\r
-            res = SZ_ERROR_FAIL;\r
-            break;\r
-          }\r
-          \r
-          if (File_Close(&outFile))\r
-          {\r
-            PrintError("can not close output file");\r
-            res = SZ_ERROR_FAIL;\r
-            break;\r
-          }\r
-          \r
-          #ifdef USE_WINDOWS_FILE\r
-          if (SzBitWithVals_Check(&db.Attribs, i))\r
-            SetFileAttributesW(destPath, db.Attribs.Vals[i]);\r
-          #endif\r
-        }\r
-        printf("\n");\r
-      }\r
-      IAlloc_Free(&allocImp, outBuffer);\r
-    }\r
-  }\r
-\r
-  SzArEx_Free(&db, &allocImp);\r
-  SzFree(NULL, temp);\r
-\r
-  File_Close(&archiveStream.file);\r
-  \r
-  if (res == SZ_OK)\r
-  {\r
-    printf("\nEverything is Ok\n");\r
-    return 0;\r
-  }\r
-  \r
-  if (res == SZ_ERROR_UNSUPPORTED)\r
-    PrintError("decoder doesn't support this archive");\r
-  else if (res == SZ_ERROR_MEM)\r
-    PrintError("can not allocate memory");\r
-  else if (res == SZ_ERROR_CRC)\r
-    PrintError("CRC error");\r
-  else\r
-    printf("\nERROR #%d\n", res);\r
-  \r
-  return 1;\r
-}\r
diff --git a/deps/lzma-16.04/C/Util/7z/Precomp.c b/deps/lzma-16.04/C/Util/7z/Precomp.c
deleted file mode 100644 (file)
index 34b60f8..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-/* Precomp.c -- StdAfx\r
-2013-01-21 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
diff --git a/deps/lzma-16.04/C/Util/7z/Precomp.h b/deps/lzma-16.04/C/Util/7z/Precomp.h
deleted file mode 100644 (file)
index 9f398d0..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-/* Precomp.h -- StdAfx\r
-2013-06-16 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_PRECOMP_H\r
-#define __7Z_PRECOMP_H\r
-\r
-#include "../../Compiler.h"\r
-#include "../../7zTypes.h"\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Util/7z/makefile b/deps/lzma-16.04/C/Util/7z/makefile
deleted file mode 100644 (file)
index f4a54af..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-CFLAGS = $(CFLAGS) -D_7ZIP_PPMD_SUPPPORT\r
-\r
-PROG = 7zDec.exe\r
-\r
-C_OBJS = \\r
-  $O\7zAlloc.obj \\r
-  $O\7zBuf.obj \\r
-  $O\7zCrc.obj \\r
-  $O\7zCrcOpt.obj \\r
-  $O\7zFile.obj \\r
-  $O\7zDec.obj \\r
-  $O\7zArcIn.obj \\r
-  $O\7zStream.obj \\r
-  $O\Bcj2.obj \\r
-  $O\Bra.obj \\r
-  $O\Bra86.obj \\r
-  $O\BraIA64.obj \\r
-  $O\CpuArch.obj \\r
-  $O\Delta.obj \\r
-  $O\Lzma2Dec.obj \\r
-  $O\LzmaDec.obj \\r
-  $O\Ppmd7.obj \\r
-  $O\Ppmd7Dec.obj \\r
-\r
-7Z_OBJS = \\r
-  $O\7zMain.obj \\r
-\r
-OBJS = \\r
-  $O\Precomp.obj \\r
-  $(7Z_OBJS) \\r
-  $(C_OBJS) \\r
-\r
-!include "../../../CPP/Build.mak"\r
-\r
-$(7Z_OBJS): $(*B).c\r
-       $(CCOMPL_USE)\r
-$(C_OBJS): ../../$(*B).c\r
-       $(CCOMPL_USE)\r
-$O\Precomp.obj: Precomp.c\r
-       $(CCOMPL_PCH)\r
diff --git a/deps/lzma-16.04/C/Util/7z/makefile.gcc b/deps/lzma-16.04/C/Util/7z/makefile.gcc
deleted file mode 100644 (file)
index f707935..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-PROG = 7zDec\r
-CXX = gcc\r
-LIB =\r
-RM = rm -f\r
-CFLAGS = -c -O2 -Wall\r
-\r
-OBJS = 7zMain.o 7zAlloc.o 7zArcIn.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zCrcOpt.o 7zDec.o CpuArch.o Delta.o LzmaDec.o Lzma2Dec.o Bra.o Bra86.o BraIA64.o Bcj2.o Ppmd7.o Ppmd7Dec.o 7zFile.o 7zStream.o\r
-\r
-all: $(PROG)\r
-\r
-$(PROG): $(OBJS)\r
-       $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r
-\r
-7zMain.o: 7zMain.c\r
-       $(CXX) $(CFLAGS) 7zMain.c\r
-\r
-7zAlloc.o: ../../7zAlloc.c\r
-       $(CXX) $(CFLAGS) ../../7zAlloc.c\r
-\r
-7zArcIn.o: ../../7zArcIn.c\r
-       $(CXX) $(CFLAGS) ../../7zArcIn.c\r
-\r
-7zBuf.o: ../../7zBuf.c\r
-       $(CXX) $(CFLAGS) ../../7zBuf.c\r
-\r
-7zBuf2.o: ../../7zBuf2.c\r
-       $(CXX) $(CFLAGS) ../../7zBuf2.c\r
-\r
-7zCrc.o: ../../7zCrc.c\r
-       $(CXX) $(CFLAGS) ../../7zCrc.c\r
-\r
-7zCrcOpt.o: ../../7zCrc.c\r
-       $(CXX) $(CFLAGS) ../../7zCrcOpt.c\r
-\r
-7zDec.o: ../../7zDec.c\r
-       $(CXX) $(CFLAGS) -D_7ZIP_PPMD_SUPPPORT ../../7zDec.c\r
-\r
-CpuArch.o: ../../CpuArch.c\r
-       $(CXX) $(CFLAGS) ../../CpuArch.c\r
-\r
-Delta.o: ../../Delta.c\r
-       $(CXX) $(CFLAGS) ../../Delta.c\r
-\r
-LzmaDec.o: ../../LzmaDec.c\r
-       $(CXX) $(CFLAGS) ../../LzmaDec.c\r
-\r
-Lzma2Dec.o: ../../Lzma2Dec.c\r
-       $(CXX) $(CFLAGS) ../../Lzma2Dec.c\r
-\r
-Bra.o: ../../Bra.c\r
-       $(CXX) $(CFLAGS) ../../Bra.c\r
-\r
-Bra86.o: ../../Bra86.c\r
-       $(CXX) $(CFLAGS) ../../Bra86.c\r
-\r
-BraIA64.o: ../../BraIA64.c\r
-       $(CXX) $(CFLAGS) ../../BraIA64.c\r
-\r
-Bcj2.o: ../../Bcj2.c\r
-       $(CXX) $(CFLAGS) ../../Bcj2.c\r
-\r
-Ppmd7.o: ../../Ppmd7.c\r
-       $(CXX) $(CFLAGS) ../../Ppmd7.c\r
-\r
-Ppmd7Dec.o: ../../Ppmd7Dec.c\r
-       $(CXX) $(CFLAGS) ../../Ppmd7Dec.c\r
-\r
-7zFile.o: ../../7zFile.c\r
-       $(CXX) $(CFLAGS) ../../7zFile.c\r
-\r
-7zStream.o: ../../7zStream.c\r
-       $(CXX) $(CFLAGS) ../../7zStream.c\r
-\r
-clean:\r
-       -$(RM) $(PROG) $(OBJS)\r
diff --git a/deps/lzma-16.04/C/Util/Lzma/LzmaUtil.c b/deps/lzma-16.04/C/Util/Lzma/LzmaUtil.c
deleted file mode 100644 (file)
index 98331b4..0000000
+++ /dev/null
@@ -1,250 +0,0 @@
-/* LzmaUtil.c -- Test application for LZMA compression\r
-2015-11-08 : Igor Pavlov : Public domain */\r
-\r
-#include "../../Precomp.h"\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#include "../../Alloc.h"\r
-#include "../../7zFile.h"\r
-#include "../../7zVersion.h"\r
-#include "../../LzmaDec.h"\r
-#include "../../LzmaEnc.h"\r
-\r
-const char *kCantReadMessage = "Can not read input file";\r
-const char *kCantWriteMessage = "Can not write output file";\r
-const char *kCantAllocateMessage = "Can not allocate memory";\r
-const char *kDataErrorMessage = "Data error";\r
-\r
-void PrintHelp(char *buffer)\r
-{\r
-  strcat(buffer, "\nLZMA Utility " MY_VERSION_COPYRIGHT_DATE "\n"\r
-      "\nUsage:  lzma <e|d> inputFile outputFile\n"\r
-             "  e: encode file\n"\r
-             "  d: decode file\n");\r
-}\r
-\r
-int PrintError(char *buffer, const char *message)\r
-{\r
-  strcat(buffer, "\nError: ");\r
-  strcat(buffer, message);\r
-  strcat(buffer, "\n");\r
-  return 1;\r
-}\r
-\r
-int PrintErrorNumber(char *buffer, SRes val)\r
-{\r
-  sprintf(buffer + strlen(buffer), "\nError code: %x\n", (unsigned)val);\r
-  return 1;\r
-}\r
-\r
-int PrintUserError(char *buffer)\r
-{\r
-  return PrintError(buffer, "Incorrect command");\r
-}\r
-\r
-#define IN_BUF_SIZE (1 << 16)\r
-#define OUT_BUF_SIZE (1 << 16)\r
-\r
-static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,\r
-    UInt64 unpackSize)\r
-{\r
-  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);\r
-  Byte inBuf[IN_BUF_SIZE];\r
-  Byte outBuf[OUT_BUF_SIZE];\r
-  size_t inPos = 0, inSize = 0, outPos = 0;\r
-  LzmaDec_Init(state);\r
-  for (;;)\r
-  {\r
-    if (inPos == inSize)\r
-    {\r
-      inSize = IN_BUF_SIZE;\r
-      RINOK(inStream->Read(inStream, inBuf, &inSize));\r
-      inPos = 0;\r
-    }\r
-    {\r
-      SRes res;\r
-      SizeT inProcessed = inSize - inPos;\r
-      SizeT outProcessed = OUT_BUF_SIZE - outPos;\r
-      ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\r
-      ELzmaStatus status;\r
-      if (thereIsSize && outProcessed > unpackSize)\r
-      {\r
-        outProcessed = (SizeT)unpackSize;\r
-        finishMode = LZMA_FINISH_END;\r
-      }\r
-      \r
-      res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,\r
-        inBuf + inPos, &inProcessed, finishMode, &status);\r
-      inPos += inProcessed;\r
-      outPos += outProcessed;\r
-      unpackSize -= outProcessed;\r
-      \r
-      if (outStream)\r
-        if (outStream->Write(outStream, outBuf, outPos) != outPos)\r
-          return SZ_ERROR_WRITE;\r
-        \r
-      outPos = 0;\r
-      \r
-      if (res != SZ_OK || (thereIsSize && unpackSize == 0))\r
-        return res;\r
-      \r
-      if (inProcessed == 0 && outProcessed == 0)\r
-      {\r
-        if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)\r
-          return SZ_ERROR_DATA;\r
-        return res;\r
-      }\r
-    }\r
-  }\r
-}\r
-\r
-static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)\r
-{\r
-  UInt64 unpackSize;\r
-  int i;\r
-  SRes res = 0;\r
-\r
-  CLzmaDec state;\r
-\r
-  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */\r
-  unsigned char header[LZMA_PROPS_SIZE + 8];\r
-\r
-  /* Read and parse header */\r
-\r
-  RINOK(SeqInStream_Read(inStream, header, sizeof(header)));\r
-\r
-  unpackSize = 0;\r
-  for (i = 0; i < 8; i++)\r
-    unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);\r
-\r
-  LzmaDec_Construct(&state);\r
-  RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));\r
-  res = Decode2(&state, outStream, inStream, unpackSize);\r
-  LzmaDec_Free(&state, &g_Alloc);\r
-  return res;\r
-}\r
-\r
-static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)\r
-{\r
-  CLzmaEncHandle enc;\r
-  SRes res;\r
-  CLzmaEncProps props;\r
-\r
-  UNUSED_VAR(rs);\r
-\r
-  enc = LzmaEnc_Create(&g_Alloc);\r
-  if (enc == 0)\r
-    return SZ_ERROR_MEM;\r
-\r
-  LzmaEncProps_Init(&props);\r
-  res = LzmaEnc_SetProps(enc, &props);\r
-\r
-  if (res == SZ_OK)\r
-  {\r
-    Byte header[LZMA_PROPS_SIZE + 8];\r
-    size_t headerSize = LZMA_PROPS_SIZE;\r
-    int i;\r
-\r
-    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r
-    for (i = 0; i < 8; i++)\r
-      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r
-    if (outStream->Write(outStream, header, headerSize) != headerSize)\r
-      res = SZ_ERROR_WRITE;\r
-    else\r
-    {\r
-      if (res == SZ_OK)\r
-        res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);\r
-    }\r
-  }\r
-  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r
-  return res;\r
-}\r
-\r
-int main2(int numArgs, const char *args[], char *rs)\r
-{\r
-  CFileSeqInStream inStream;\r
-  CFileOutStream outStream;\r
-  char c;\r
-  int res;\r
-  int encodeMode;\r
-  Bool useOutFile = False;\r
-\r
-  FileSeqInStream_CreateVTable(&inStream);\r
-  File_Construct(&inStream.file);\r
-\r
-  FileOutStream_CreateVTable(&outStream);\r
-  File_Construct(&outStream.file);\r
-\r
-  if (numArgs == 1)\r
-  {\r
-    PrintHelp(rs);\r
-    return 0;\r
-  }\r
-\r
-  if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1)\r
-    return PrintUserError(rs);\r
-\r
-  c = args[1][0];\r
-  encodeMode = (c == 'e' || c == 'E');\r
-  if (!encodeMode && c != 'd' && c != 'D')\r
-    return PrintUserError(rs);\r
-\r
-  {\r
-    size_t t4 = sizeof(UInt32);\r
-    size_t t8 = sizeof(UInt64);\r
-    if (t4 != 4 || t8 != 8)\r
-      return PrintError(rs, "Incorrect UInt32 or UInt64");\r
-  }\r
-\r
-  if (InFile_Open(&inStream.file, args[2]) != 0)\r
-    return PrintError(rs, "Can not open input file");\r
-\r
-  if (numArgs > 3)\r
-  {\r
-    useOutFile = True;\r
-    if (OutFile_Open(&outStream.file, args[3]) != 0)\r
-      return PrintError(rs, "Can not open output file");\r
-  }\r
-  else if (encodeMode)\r
-    PrintUserError(rs);\r
-\r
-  if (encodeMode)\r
-  {\r
-    UInt64 fileSize;\r
-    File_GetLength(&inStream.file, &fileSize);\r
-    res = Encode(&outStream.s, &inStream.s, fileSize, rs);\r
-  }\r
-  else\r
-  {\r
-    res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL);\r
-  }\r
-\r
-  if (useOutFile)\r
-    File_Close(&outStream.file);\r
-  File_Close(&inStream.file);\r
-\r
-  if (res != SZ_OK)\r
-  {\r
-    if (res == SZ_ERROR_MEM)\r
-      return PrintError(rs, kCantAllocateMessage);\r
-    else if (res == SZ_ERROR_DATA)\r
-      return PrintError(rs, kDataErrorMessage);\r
-    else if (res == SZ_ERROR_WRITE)\r
-      return PrintError(rs, kCantWriteMessage);\r
-    else if (res == SZ_ERROR_READ)\r
-      return PrintError(rs, kCantReadMessage);\r
-    return PrintErrorNumber(rs, res);\r
-  }\r
-  return 0;\r
-}\r
-\r
-int MY_CDECL main(int numArgs, const char *args[])\r
-{\r
-  char rs[800] = { 0 };\r
-  int res = main2(numArgs, args, rs);\r
-  fputs(rs, stdout);\r
-  return res;\r
-}\r
diff --git a/deps/lzma-16.04/C/Util/Lzma/LzmaUtil.dsp b/deps/lzma-16.04/C/Util/Lzma/LzmaUtil.dsp
deleted file mode 100644 (file)
index df1f0cb..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-# Microsoft Developer Studio Project File - Name="LzmaUtil" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=LzmaUtil - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "LzmaUtil.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "LzmaUtil.mak" CFG="LzmaUtil - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "LzmaUtil - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "LzmaUtil - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "LzmaUtil - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir "Release"\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W4 /WX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c\r
-# SUBTRACT CPP /YX\r
-# ADD BASE RSC /l 0x419 /d "NDEBUG"\r
-# ADD RSC /l 0x419 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\util\7lzma.exe"\r
-\r
-!ELSEIF  "$(CFG)" == "LzmaUtil - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "Debug"\r
-# PROP BASE Intermediate_Dir "Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir "Debug"\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W4 /WX /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c\r
-# SUBTRACT CPP /YX\r
-# ADD BASE RSC /l 0x419 /d "_DEBUG"\r
-# ADD RSC /l 0x419 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\util\7lzma.exe" /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "LzmaUtil - Win32 Release"\r
-# Name "LzmaUtil - Win32 Debug"\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zFile.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zFile.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zStream.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zVersion.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Alloc.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Alloc.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\CpuArch.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzFind.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzFind.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzFindMt.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzFindMt.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzHash.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaDec.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaDec.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaEnc.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaEnc.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\LzmaUtil.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Threads.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Threads.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Types.h\r
-# End Source File\r
-# End Target\r
-# End Project\r
diff --git a/deps/lzma-16.04/C/Util/Lzma/LzmaUtil.dsw b/deps/lzma-16.04/C/Util/Lzma/LzmaUtil.dsw
deleted file mode 100644 (file)
index f435487..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00\r
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
-\r
-###############################################################################\r
-\r
-Project: "LzmaUtil"=.\LzmaUtil.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Global:\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<3>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
diff --git a/deps/lzma-16.04/C/Util/Lzma/makefile b/deps/lzma-16.04/C/Util/Lzma/makefile
deleted file mode 100644 (file)
index 3b825f2..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-# MY_STATIC_LINK=1\r
-PROG = LZMAc.exe\r
-\r
-CFLAGS = $(CFLAGS) \\r
-\r
-LIB_OBJS = \\r
-  $O\LzmaUtil.obj \\r
-\r
-C_OBJS = \\r
-  $O\Alloc.obj \\r
-  $O\LzFind.obj \\r
-  $O\LzFindMt.obj \\r
-  $O\LzmaDec.obj \\r
-  $O\LzmaEnc.obj \\r
-  $O\7zFile.obj \\r
-  $O\7zStream.obj \\r
-  $O\Threads.obj \\r
-\r
-OBJS = \\r
-  $(LIB_OBJS) \\r
-  $(C_OBJS) \\r
-\r
-!include "../../../CPP/Build.mak"\r
-\r
-$(LIB_OBJS): $(*B).c\r
-       $(COMPL_O2)\r
-$(C_OBJS): ../../$(*B).c\r
-       $(COMPL_O2)\r
diff --git a/deps/lzma-16.04/C/Util/Lzma/makefile.gcc b/deps/lzma-16.04/C/Util/Lzma/makefile.gcc
deleted file mode 100644 (file)
index 12a72bb..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-PROG = lzma\r
-CXX = g++\r
-LIB =\r
-RM = rm -f\r
-CFLAGS = -c -O2 -Wall -D_7ZIP_ST\r
-\r
-OBJS = \\r
-  LzmaUtil.o \\r
-  Alloc.o \\r
-  LzFind.o \\r
-  LzmaDec.o \\r
-  LzmaEnc.o \\r
-  7zFile.o \\r
-  7zStream.o \\r
-\r
-\r
-all: $(PROG)\r
-\r
-$(PROG): $(OBJS)\r
-       $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r
-\r
-LzmaUtil.o: LzmaUtil.c\r
-       $(CXX) $(CFLAGS) LzmaUtil.c\r
-\r
-Alloc.o: ../../Alloc.c\r
-       $(CXX) $(CFLAGS) ../../Alloc.c\r
-\r
-LzFind.o: ../../LzFind.c\r
-       $(CXX) $(CFLAGS) ../../LzFind.c\r
-\r
-LzmaDec.o: ../../LzmaDec.c\r
-       $(CXX) $(CFLAGS) ../../LzmaDec.c\r
-\r
-LzmaEnc.o: ../../LzmaEnc.c\r
-       $(CXX) $(CFLAGS) ../../LzmaEnc.c\r
-\r
-7zFile.o: ../../7zFile.c\r
-       $(CXX) $(CFLAGS) ../../7zFile.c\r
-\r
-7zStream.o: ../../7zStream.c\r
-       $(CXX) $(CFLAGS) ../../7zStream.c\r
-\r
-clean:\r
-       -$(RM) $(PROG) $(OBJS)\r
diff --git a/deps/lzma-16.04/C/Util/LzmaLib/LzmaLib.def b/deps/lzma-16.04/C/Util/LzmaLib/LzmaLib.def
deleted file mode 100644 (file)
index 43b9597..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-EXPORTS\r
-  LzmaCompress\r
-  LzmaUncompress\r
-\r
diff --git a/deps/lzma-16.04/C/Util/LzmaLib/LzmaLib.dsp b/deps/lzma-16.04/C/Util/LzmaLib/LzmaLib.dsp
deleted file mode 100644 (file)
index 0d4c981..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-# Microsoft Developer Studio Project File - Name="LzmaLib" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102\r
-\r
-CFG=LzmaLib - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "LzmaLib.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "LzmaLib.mak" CFG="LzmaLib - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "LzmaLib - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")\r
-!MESSAGE "LzmaLib - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-MTL=midl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "LzmaLib - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir "Release"\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /YX /FD /c\r
-# ADD CPP /nologo /Gr /MT /W3 /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /FD /c\r
-# SUBTRACT CPP /YX\r
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
-# ADD BASE RSC /l 0x419 /d "NDEBUG"\r
-# ADD RSC /l 0x419 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Util\LZMA.dll" /opt:NOWIN98\r
-# SUBTRACT LINK32 /pdb:none\r
-\r
-!ELSEIF  "$(CFG)" == "LzmaLib - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "Debug"\r
-# PROP BASE Intermediate_Dir "Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir "Debug"\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /D "COMPRESS_MF_MT" /FD /GZ /c\r
-# SUBTRACT CPP /YX\r
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
-# ADD BASE RSC /l 0x419 /d "_DEBUG"\r
-# ADD RSC /l 0x419 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Util\LZMA.dll" /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "LzmaLib - Win32 Release"\r
-# Name "LzmaLib - Win32 Debug"\r
-# Begin Group "Spec"\r
-\r
-# PROP Default_Filter ""\r
-# Begin Source File\r
-\r
-SOURCE=.\LzmaLib.def\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\LzmaLibExports.c\r
-# End Source File\r
-# End Group\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zTypes.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Alloc.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Alloc.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\IStream.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzFind.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzFind.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzFindMt.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzFindMt.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzHash.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaDec.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaDec.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaEnc.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaEnc.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaLib.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaLib.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\resource.rc\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Threads.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Threads.h\r
-# End Source File\r
-# End Target\r
-# End Project\r
diff --git a/deps/lzma-16.04/C/Util/LzmaLib/LzmaLib.dsw b/deps/lzma-16.04/C/Util/LzmaLib/LzmaLib.dsw
deleted file mode 100644 (file)
index f6c5559..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00\r
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
-\r
-###############################################################################\r
-\r
-Project: "LzmaLib"=.\LzmaLib.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Global:\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<3>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
diff --git a/deps/lzma-16.04/C/Util/LzmaLib/LzmaLibExports.c b/deps/lzma-16.04/C/Util/LzmaLib/LzmaLibExports.c
deleted file mode 100644 (file)
index 02600c7..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/* LzmaLibExports.c -- LZMA library DLL Entry point\r
-2015-11-08 : Igor Pavlov : Public domain */\r
-\r
-#include "../../Precomp.h"\r
-\r
-#include <windows.h>\r
-\r
-BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
-{\r
-  UNUSED_VAR(hInstance);\r
-  UNUSED_VAR(dwReason);\r
-  UNUSED_VAR(lpReserved);\r
-  return TRUE;\r
-}\r
diff --git a/deps/lzma-16.04/C/Util/LzmaLib/makefile b/deps/lzma-16.04/C/Util/LzmaLib/makefile
deleted file mode 100644 (file)
index e0f3114..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-MY_STATIC_LINK=1\r
-SLIB = sLZMA.lib\r
-PROG = LZMA.dll\r
-SLIBPATH = $O\$(SLIB)\r
-\r
-DEF_FILE = LzmaLib.def\r
-CFLAGS = $(CFLAGS) \\r
-\r
-LIB_OBJS = \\r
-  $O\LzmaLibExports.obj \\r
-\r
-C_OBJS = \\r
-  $O\Alloc.obj \\r
-  $O\LzFind.obj \\r
-  $O\LzFindMt.obj \\r
-  $O\LzmaDec.obj \\r
-  $O\LzmaEnc.obj \\r
-  $O\LzmaLib.obj \\r
-  $O\Threads.obj \\r
-\r
-OBJS = \\r
-  $(LIB_OBJS) \\r
-  $(C_OBJS) \\r
-  $O\resource.res\r
-\r
-!include "../../../CPP/Build.mak"\r
-\r
-$(SLIBPATH): $O $(OBJS)\r
-       lib -out:$(SLIBPATH) $(OBJS) $(LIBS)\r
-\r
-$(LIB_OBJS): $(*B).c\r
-       $(COMPL_O2)\r
-$(C_OBJS): ../../$(*B).c\r
-       $(COMPL_O2)\r
diff --git a/deps/lzma-16.04/C/Util/LzmaLib/resource.rc b/deps/lzma-16.04/C/Util/LzmaLib/resource.rc
deleted file mode 100644 (file)
index d95e3f3..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "../../7zVersion.rc"\r
-\r
-MY_VERSION_INFO_DLL("LZMA library", "LZMA")\r
diff --git a/deps/lzma-16.04/C/Util/SfxSetup/Precomp.c b/deps/lzma-16.04/C/Util/SfxSetup/Precomp.c
deleted file mode 100644 (file)
index 34b60f8..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-/* Precomp.c -- StdAfx\r
-2013-01-21 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
diff --git a/deps/lzma-16.04/C/Util/SfxSetup/Precomp.h b/deps/lzma-16.04/C/Util/SfxSetup/Precomp.h
deleted file mode 100644 (file)
index 9f398d0..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-/* Precomp.h -- StdAfx\r
-2013-06-16 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_PRECOMP_H\r
-#define __7Z_PRECOMP_H\r
-\r
-#include "../../Compiler.h"\r
-#include "../../7zTypes.h"\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/Util/SfxSetup/SfxSetup.c b/deps/lzma-16.04/C/Util/SfxSetup/SfxSetup.c
deleted file mode 100644 (file)
index 50e57ae..0000000
+++ /dev/null
@@ -1,626 +0,0 @@
-/* SfxSetup.c - 7z SFX Setup\r
-2016-05-16 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#ifndef UNICODE\r
-#define UNICODE\r
-#endif\r
-\r
-#ifndef _UNICODE\r
-#define _UNICODE\r
-#endif\r
-\r
-#ifdef _CONSOLE\r
-#include <stdio.h>\r
-#endif\r
-\r
-#include "../../7z.h"\r
-#include "../../7zAlloc.h"\r
-#include "../../7zCrc.h"\r
-#include "../../7zFile.h"\r
-#include "../../CpuArch.h"\r
-#include "../../DllSecur.h"\r
-\r
-#define k_EXE_ExtIndex 2\r
-\r
-static const char * const kExts[] =\r
-{\r
-    "bat"\r
-  , "cmd"\r
-  , "exe"\r
-  , "inf"\r
-  , "msi"\r
-  #ifdef UNDER_CE\r
-  , "cab"\r
-  #endif\r
-  , "html"\r
-  , "htm"\r
-};\r
-\r
-static const char * const kNames[] =\r
-{\r
-    "setup"\r
-  , "install"\r
-  , "run"\r
-  , "start"\r
-};\r
-\r
-static unsigned FindExt(const wchar_t *s, unsigned *extLen)\r
-{\r
-  unsigned len = (unsigned)wcslen(s);\r
-  unsigned i;\r
-  for (i = len; i > 0; i--)\r
-  {\r
-    if (s[i - 1] == '.')\r
-    {\r
-      *extLen = len - i;\r
-      return i - 1;\r
-    }\r
-  }\r
-  *extLen = 0;\r
-  return len;\r
-}\r
-\r
-#define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c)))\r
-\r
-static unsigned FindItem(const char * const *items, unsigned num, const wchar_t *s, unsigned len)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < num; i++)\r
-  {\r
-    const char *item = items[i];\r
-    unsigned itemLen = (unsigned)strlen(item);\r
-    unsigned j;\r
-    if (len != itemLen)\r
-      continue;\r
-    for (j = 0; j < len; j++)\r
-    {\r
-      unsigned c = (Byte)item[j];\r
-      if (c != s[j] && MAKE_CHAR_UPPER(c) != s[j])\r
-        break;\r
-    }\r
-    if (j == len)\r
-      return i;\r
-  }\r
-  return i;\r
-}\r
-\r
-#ifdef _CONSOLE\r
-static BOOL WINAPI HandlerRoutine(DWORD ctrlType)\r
-{\r
-  UNUSED_VAR(ctrlType);\r
-  return TRUE;\r
-}\r
-#endif\r
-\r
-static void PrintErrorMessage(const char *message)\r
-{\r
-  #ifdef _CONSOLE\r
-  printf("\n7-Zip Error: %s\n", message);\r
-  #else\r
-  #ifdef UNDER_CE\r
-  WCHAR messageW[256 + 4];\r
-  unsigned i;\r
-  for (i = 0; i < 256 && message[i] != 0; i++)\r
-    messageW[i] = message[i];\r
-  messageW[i] = 0;\r
-  MessageBoxW(0, messageW, L"7-Zip Error", MB_ICONERROR);\r
-  #else\r
-  MessageBoxA(0, message, "7-Zip Error", MB_ICONERROR);\r
-  #endif\r
-  #endif\r
-}\r
-\r
-static WRes MyCreateDir(const WCHAR *name)\r
-{\r
-  return CreateDirectoryW(name, NULL) ? 0 : GetLastError();\r
-}\r
-\r
-#ifdef UNDER_CE\r
-#define kBufferSize (1 << 13)\r
-#else\r
-#define kBufferSize (1 << 15)\r
-#endif\r
-\r
-#define kSignatureSearchLimit (1 << 22)\r
-\r
-static Bool FindSignature(CSzFile *stream, UInt64 *resPos)\r
-{\r
-  Byte buf[kBufferSize];\r
-  size_t numPrevBytes = 0;\r
-  *resPos = 0;\r
-  for (;;)\r
-  {\r
-    size_t processed, pos;\r
-    if (*resPos > kSignatureSearchLimit)\r
-      return False;\r
-    processed = kBufferSize - numPrevBytes;\r
-    if (File_Read(stream, buf + numPrevBytes, &processed) != 0)\r
-      return False;\r
-    processed += numPrevBytes;\r
-    if (processed < k7zStartHeaderSize ||\r
-        (processed == k7zStartHeaderSize && numPrevBytes != 0))\r
-      return False;\r
-    processed -= k7zStartHeaderSize;\r
-    for (pos = 0; pos <= processed; pos++)\r
-    {\r
-      for (; pos <= processed && buf[pos] != '7'; pos++);\r
-      if (pos > processed)\r
-        break;\r
-      if (memcmp(buf + pos, k7zSignature, k7zSignatureSize) == 0)\r
-        if (CrcCalc(buf + pos + 12, 20) == GetUi32(buf + pos + 8))\r
-        {\r
-          *resPos += pos;\r
-          return True;\r
-        }\r
-    }\r
-    *resPos += processed;\r
-    numPrevBytes = k7zStartHeaderSize;\r
-    memmove(buf, buf + processed, k7zStartHeaderSize);\r
-  }\r
-}\r
-\r
-static Bool DoesFileOrDirExist(const WCHAR *path)\r
-{\r
-  WIN32_FIND_DATAW fd;\r
-  HANDLE handle;\r
-  handle = FindFirstFileW(path, &fd);\r
-  if (handle == INVALID_HANDLE_VALUE)\r
-    return False;\r
-  FindClose(handle);\r
-  return True;\r
-}\r
-\r
-static WRes RemoveDirWithSubItems(WCHAR *path)\r
-{\r
-  WIN32_FIND_DATAW fd;\r
-  HANDLE handle;\r
-  WRes res = 0;\r
-  size_t len = wcslen(path);\r
-  wcscpy(path + len, L"*");\r
-  handle = FindFirstFileW(path, &fd);\r
-  path[len] = L'\0';\r
-  if (handle == INVALID_HANDLE_VALUE)\r
-    return GetLastError();\r
-  \r
-  for (;;)\r
-  {\r
-    if (wcscmp(fd.cFileName, L".") != 0 &&\r
-        wcscmp(fd.cFileName, L"..") != 0)\r
-    {\r
-      wcscpy(path + len, fd.cFileName);\r
-      if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)\r
-      {\r
-        wcscat(path, WSTRING_PATH_SEPARATOR);\r
-        res = RemoveDirWithSubItems(path);\r
-      }\r
-      else\r
-      {\r
-        SetFileAttributesW(path, 0);\r
-        if (DeleteFileW(path) == 0)\r
-          res = GetLastError();\r
-      }\r
-    \r
-      if (res != 0)\r
-        break;\r
-    }\r
-  \r
-    if (!FindNextFileW(handle, &fd))\r
-    {\r
-      res = GetLastError();\r
-      if (res == ERROR_NO_MORE_FILES)\r
-        res = 0;\r
-      break;\r
-    }\r
-  }\r
-  \r
-  path[len] = L'\0';\r
-  FindClose(handle);\r
-  if (res == 0)\r
-  {\r
-    if (!RemoveDirectoryW(path))\r
-      res = GetLastError();\r
-  }\r
-  return res;\r
-}\r
-\r
-#ifdef _CONSOLE\r
-int MY_CDECL main()\r
-#else\r
-int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,\r
-  #ifdef UNDER_CE\r
-  LPWSTR\r
-  #else\r
-  LPSTR\r
-  #endif\r
-  lpCmdLine, int nCmdShow)\r
-#endif\r
-{\r
-  CFileInStream archiveStream;\r
-  CLookToRead lookStream;\r
-  CSzArEx db;\r
-  SRes res = SZ_OK;\r
-  ISzAlloc allocImp;\r
-  ISzAlloc allocTempImp;\r
-  WCHAR sfxPath[MAX_PATH + 2];\r
-  WCHAR path[MAX_PATH * 3 + 2];\r
-  #ifndef UNDER_CE\r
-  WCHAR workCurDir[MAX_PATH + 32];\r
-  #endif\r
-  size_t pathLen;\r
-  DWORD winRes;\r
-  const wchar_t *cmdLineParams;\r
-  const char *errorMessage = NULL;\r
-  Bool useShellExecute = True;\r
-  DWORD exitCode = 0;\r
-\r
-  LoadSecurityDlls();\r
-\r
-  #ifdef _CONSOLE\r
-  SetConsoleCtrlHandler(HandlerRoutine, TRUE);\r
-  #else\r
-  UNUSED_VAR(hInstance);\r
-  UNUSED_VAR(hPrevInstance);\r
-  UNUSED_VAR(lpCmdLine);\r
-  UNUSED_VAR(nCmdShow);\r
-  #endif\r
-\r
-  CrcGenerateTable();\r
-\r
-  allocImp.Alloc = SzAlloc;\r
-  allocImp.Free = SzFree;\r
-\r
-  allocTempImp.Alloc = SzAllocTemp;\r
-  allocTempImp.Free = SzFreeTemp;\r
-\r
-  FileInStream_CreateVTable(&archiveStream);\r
-  LookToRead_CreateVTable(&lookStream, False);\r
\r
-  winRes = GetModuleFileNameW(NULL, sfxPath, MAX_PATH);\r
-  if (winRes == 0 || winRes > MAX_PATH)\r
-    return 1;\r
-  {\r
-    cmdLineParams = GetCommandLineW();\r
-    #ifndef UNDER_CE\r
-    {\r
-      Bool quoteMode = False;\r
-      for (;; cmdLineParams++)\r
-      {\r
-        wchar_t c = *cmdLineParams;\r
-        if (c == L'\"')\r
-          quoteMode = !quoteMode;\r
-        else if (c == 0 || (c == L' ' && !quoteMode))\r
-          break;\r
-      }\r
-    }\r
-    #endif\r
-  }\r
-\r
-  {\r
-    unsigned i;\r
-    DWORD d;\r
-    winRes = GetTempPathW(MAX_PATH, path);\r
-    if (winRes == 0 || winRes > MAX_PATH)\r
-      return 1;\r
-    pathLen = wcslen(path);\r
-    d = (GetTickCount() << 12) ^ (GetCurrentThreadId() << 14) ^ GetCurrentProcessId();\r
-    \r
-    for (i = 0;; i++, d += GetTickCount())\r
-    {\r
-      if (i >= 100)\r
-      {\r
-        res = SZ_ERROR_FAIL;\r
-        break;\r
-      }\r
-      wcscpy(path + pathLen, L"7z");\r
-\r
-      {\r
-        wchar_t *s = path + wcslen(path);\r
-        UInt32 value = d;\r
-        unsigned k;\r
-        for (k = 0; k < 8; k++)\r
-        {\r
-          unsigned t = value & 0xF;\r
-          value >>= 4;\r
-          s[7 - k] = (wchar_t)((t < 10) ? ('0' + t) : ('A' + (t - 10)));\r
-        }\r
-        s[k] = '\0';\r
-      }\r
-\r
-      if (DoesFileOrDirExist(path))\r
-        continue;\r
-      if (CreateDirectoryW(path, NULL))\r
-      {\r
-        wcscat(path, WSTRING_PATH_SEPARATOR);\r
-        pathLen = wcslen(path);\r
-        break;\r
-      }\r
-      if (GetLastError() != ERROR_ALREADY_EXISTS)\r
-      {\r
-        res = SZ_ERROR_FAIL;\r
-        break;\r
-      }\r
-    }\r
-    \r
-    #ifndef UNDER_CE\r
-    wcscpy(workCurDir, path);\r
-    #endif\r
-    if (res != SZ_OK)\r
-      errorMessage = "Can't create temp folder";\r
-  }\r
-\r
-  if (res != SZ_OK)\r
-  {\r
-    if (!errorMessage)\r
-      errorMessage = "Error";\r
-    PrintErrorMessage(errorMessage);\r
-    return 1;\r
-  }\r
-\r
-  if (InFile_OpenW(&archiveStream.file, sfxPath) != 0)\r
-  {\r
-    errorMessage = "can not open input file";\r
-    res = SZ_ERROR_FAIL;\r
-  }\r
-  else\r
-  {\r
-    UInt64 pos = 0;\r
-    if (!FindSignature(&archiveStream.file, &pos))\r
-      res = SZ_ERROR_FAIL;\r
-    else if (File_Seek(&archiveStream.file, (Int64 *)&pos, SZ_SEEK_SET) != 0)\r
-      res = SZ_ERROR_FAIL;\r
-    if (res != 0)\r
-      errorMessage = "Can't find 7z archive";\r
-  }\r
-\r
-  if (res == SZ_OK)\r
-  {\r
-    lookStream.realStream = &archiveStream.s;\r
-    LookToRead_Init(&lookStream);\r
-  }\r
-\r
-  SzArEx_Init(&db);\r
-  if (res == SZ_OK)\r
-  {\r
-    res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);\r
-  }\r
-  \r
-  if (res == SZ_OK)\r
-  {\r
-    UInt32 executeFileIndex = (UInt32)(Int32)-1;\r
-    UInt32 minPrice = 1 << 30;\r
-    UInt32 i;\r
-    UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r
-    Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r
-    size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r
-    \r
-    for (i = 0; i < db.NumFiles; i++)\r
-    {\r
-      size_t offset = 0;\r
-      size_t outSizeProcessed = 0;\r
-      WCHAR *temp;\r
-\r
-      if (SzArEx_GetFileNameUtf16(&db, i, NULL) >= MAX_PATH)\r
-      {\r
-        res = SZ_ERROR_FAIL;\r
-        break;\r
-      }\r
-      \r
-      temp = path + pathLen;\r
-      \r
-      SzArEx_GetFileNameUtf16(&db, i, temp);\r
-      {\r
-        res = SzArEx_Extract(&db, &lookStream.s, i,\r
-          &blockIndex, &outBuffer, &outBufferSize,\r
-          &offset, &outSizeProcessed,\r
-          &allocImp, &allocTempImp);\r
-        if (res != SZ_OK)\r
-          break;\r
-      }\r
-      {\r
-        CSzFile outFile;\r
-        size_t processedSize;\r
-        size_t j;\r
-        size_t nameStartPos = 0;\r
-        for (j = 0; temp[j] != 0; j++)\r
-        {\r
-          if (temp[j] == '/')\r
-          {\r
-            temp[j] = 0;\r
-            MyCreateDir(path);\r
-            temp[j] = CHAR_PATH_SEPARATOR;\r
-            nameStartPos = j + 1;\r
-          }\r
-        }\r
-\r
-        if (SzArEx_IsDir(&db, i))\r
-        {\r
-          MyCreateDir(path);\r
-          continue;\r
-        }\r
-        else\r
-        {\r
-          unsigned extLen;\r
-          const WCHAR *name = temp + nameStartPos;\r
-          unsigned len = (unsigned)wcslen(name);\r
-          unsigned nameLen = FindExt(temp + nameStartPos, &extLen);\r
-          unsigned extPrice = FindItem(kExts, sizeof(kExts) / sizeof(kExts[0]), name + len - extLen, extLen);\r
-          unsigned namePrice = FindItem(kNames, sizeof(kNames) / sizeof(kNames[0]), name, nameLen);\r
-\r
-          unsigned price = namePrice + extPrice * 64 + (nameStartPos == 0 ? 0 : (1 << 12));\r
-          if (minPrice > price)\r
-          {\r
-            minPrice = price;\r
-            executeFileIndex = i;\r
-            useShellExecute = (extPrice != k_EXE_ExtIndex);\r
-          }\r
-         \r
-          if (DoesFileOrDirExist(path))\r
-          {\r
-            errorMessage = "Duplicate file";\r
-            res = SZ_ERROR_FAIL;\r
-            break;\r
-          }\r
-          if (OutFile_OpenW(&outFile, path))\r
-          {\r
-            errorMessage = "Can't open output file";\r
-            res = SZ_ERROR_FAIL;\r
-            break;\r
-          }\r
-        }\r
-  \r
-        processedSize = outSizeProcessed;\r
-        if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 || processedSize != outSizeProcessed)\r
-        {\r
-          errorMessage = "Can't write output file";\r
-          res = SZ_ERROR_FAIL;\r
-        }\r
-        \r
-        #ifdef USE_WINDOWS_FILE\r
-        if (SzBitWithVals_Check(&db.MTime, i))\r
-        {\r
-          const CNtfsFileTime *t = db.MTime.Vals + i;\r
-          FILETIME mTime;\r
-          mTime.dwLowDateTime = t->Low;\r
-          mTime.dwHighDateTime = t->High;\r
-          SetFileTime(outFile.handle, NULL, NULL, &mTime);\r
-        }\r
-        #endif\r
-        \r
-        {\r
-          SRes res2 = File_Close(&outFile);\r
-          if (res != SZ_OK)\r
-            break;\r
-          if (res2 != SZ_OK)\r
-          {\r
-            res = res2;\r
-            break;\r
-          }\r
-        }\r
-        #ifdef USE_WINDOWS_FILE\r
-        if (SzBitWithVals_Check(&db.Attribs, i))\r
-          SetFileAttributesW(path, db.Attribs.Vals[i]);\r
-        #endif\r
-      }\r
-    }\r
-\r
-    if (res == SZ_OK)\r
-    {\r
-      if (executeFileIndex == (UInt32)(Int32)-1)\r
-      {\r
-        errorMessage = "There is no file to execute";\r
-        res = SZ_ERROR_FAIL;\r
-      }\r
-      else\r
-      {\r
-        WCHAR *temp = path + pathLen;\r
-        UInt32 j;\r
-        SzArEx_GetFileNameUtf16(&db, executeFileIndex, temp);\r
-        for (j = 0; temp[j] != 0; j++)\r
-          if (temp[j] == '/')\r
-            temp[j] = CHAR_PATH_SEPARATOR;\r
-      }\r
-    }\r
-    IAlloc_Free(&allocImp, outBuffer);\r
-  }\r
-  SzArEx_Free(&db, &allocImp);\r
-\r
-  File_Close(&archiveStream.file);\r
-\r
-  if (res == SZ_OK)\r
-  {\r
-    HANDLE hProcess = 0;\r
-    \r
-    #ifndef UNDER_CE\r
-    WCHAR oldCurDir[MAX_PATH + 2];\r
-    oldCurDir[0] = 0;\r
-    {\r
-      DWORD needLen = GetCurrentDirectory(MAX_PATH + 1, oldCurDir);\r
-      if (needLen == 0 || needLen > MAX_PATH)\r
-        oldCurDir[0] = 0;\r
-      SetCurrentDirectory(workCurDir);\r
-    }\r
-    #endif\r
-    \r
-    if (useShellExecute)\r
-    {\r
-      SHELLEXECUTEINFO ei;\r
-      UINT32 executeRes;\r
-      BOOL success;\r
-      \r
-      memset(&ei, 0, sizeof(ei));\r
-      ei.cbSize = sizeof(ei);\r
-      ei.lpFile = path;\r
-      ei.fMask = SEE_MASK_NOCLOSEPROCESS\r
-          #ifndef UNDER_CE\r
-          | SEE_MASK_FLAG_DDEWAIT\r
-          #endif\r
-          /* | SEE_MASK_NO_CONSOLE */\r
-          ;\r
-      if (wcslen(cmdLineParams) != 0)\r
-        ei.lpParameters = cmdLineParams;\r
-      ei.nShow = SW_SHOWNORMAL; /* SW_HIDE; */\r
-      success = ShellExecuteEx(&ei);\r
-      executeRes = (UINT32)(UINT_PTR)ei.hInstApp;\r
-      if (!success || (executeRes <= 32 && executeRes != 0))  /* executeRes = 0 in Windows CE */\r
-        res = SZ_ERROR_FAIL;\r
-      else\r
-        hProcess = ei.hProcess;\r
-    }\r
-    else\r
-    {\r
-      STARTUPINFOW si;\r
-      PROCESS_INFORMATION pi;\r
-      WCHAR cmdLine[MAX_PATH * 3];\r
-\r
-      wcscpy(cmdLine, path);\r
-      wcscat(cmdLine, cmdLineParams);\r
-      memset(&si, 0, sizeof(si));\r
-      si.cb = sizeof(si);\r
-      if (CreateProcessW(NULL, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) == 0)\r
-        res = SZ_ERROR_FAIL;\r
-      else\r
-      {\r
-        CloseHandle(pi.hThread);\r
-        hProcess = pi.hProcess;\r
-      }\r
-    }\r
-    \r
-    if (hProcess != 0)\r
-    {\r
-      WaitForSingleObject(hProcess, INFINITE);\r
-      if (!GetExitCodeProcess(hProcess, &exitCode))\r
-        exitCode = 1;\r
-      CloseHandle(hProcess);\r
-    }\r
-    \r
-    #ifndef UNDER_CE\r
-    SetCurrentDirectory(oldCurDir);\r
-    #endif\r
-  }\r
-\r
-  path[pathLen] = L'\0';\r
-  RemoveDirWithSubItems(path);\r
-\r
-  if (res == SZ_OK)\r
-    return (int)exitCode;\r
-  \r
-  {\r
-    if (res == SZ_ERROR_UNSUPPORTED)\r
-      errorMessage = "Decoder doesn't support this archive";\r
-    else if (res == SZ_ERROR_MEM)\r
-      errorMessage = "Can't allocate required memory";\r
-    else if (res == SZ_ERROR_CRC)\r
-      errorMessage = "CRC error";\r
-    else\r
-    {\r
-      if (!errorMessage)\r
-        errorMessage = "ERROR";\r
-    }\r
\r
-    if (errorMessage)\r
-      PrintErrorMessage(errorMessage);\r
-  }\r
-  return 1;\r
-}\r
diff --git a/deps/lzma-16.04/C/Util/SfxSetup/SfxSetup.dsp b/deps/lzma-16.04/C/Util/SfxSetup/SfxSetup.dsp
deleted file mode 100644 (file)
index be9de6d..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-# Microsoft Developer Studio Project File - Name="SfxSetup" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Application" 0x0101\r
-\r
-CFG=SfxSetup - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "SfxSetup.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "SfxSetup.mak" CFG="SfxSetup - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "SfxSetup - Win32 Release" (based on "Win32 (x86) Application")\r
-!MESSAGE "SfxSetup - Win32 Debug" (based on "Win32 (x86) Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-MTL=midl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "SfxSetup - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir "Release"\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /W4 /WX /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Yu"Precomp.h" /FD /c\r
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
-# ADD BASE RSC /l 0x419 /d "NDEBUG"\r
-# ADD RSC /l 0x419 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "SfxSetup - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "Debug"\r
-# PROP BASE Intermediate_Dir "Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir "Debug"\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W4 /WX /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Yu"Precomp.h" /FD /GZ /c\r
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
-# ADD BASE RSC /l 0x419 /d "_DEBUG"\r
-# ADD RSC /l 0x419 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "SfxSetup - Win32 Release"\r
-# Name "SfxSetup - Win32 Debug"\r
-# Begin Group "Common"\r
-\r
-# PROP Default_Filter ""\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7z.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zAlloc.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zAlloc.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zArcIn.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zBuf.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zBuf.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zCrc.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zCrc.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zCrcOpt.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zDec.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zFile.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zFile.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zStream.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\7zTypes.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bcj2.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bcj2.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bra.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bra.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Bra86.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\BraIA64.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\CpuArch.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\CpuArch.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Delta.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Delta.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\DllSecur.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\DllSecur.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Lzma2Dec.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\Lzma2Dec.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaDec.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\LzmaDec.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Spec"\r
-\r
-# PROP Default_Filter ""\r
-# Begin Source File\r
-\r
-SOURCE=.\Precomp.c\r
-# ADD CPP /Yc"Precomp.h"\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\Precomp.h\r
-# End Source File\r
-# End Group\r
-# Begin Source File\r
-\r
-SOURCE=.\SfxSetup.c\r
-# End Source File\r
-# End Target\r
-# End Project\r
diff --git a/deps/lzma-16.04/C/Util/SfxSetup/SfxSetup.dsw b/deps/lzma-16.04/C/Util/SfxSetup/SfxSetup.dsw
deleted file mode 100644 (file)
index 128fcdd..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00\r
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
-\r
-###############################################################################\r
-\r
-Project: "SfxSetup"=.\SfxSetup.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Global:\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<3>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
diff --git a/deps/lzma-16.04/C/Util/SfxSetup/makefile b/deps/lzma-16.04/C/Util/SfxSetup/makefile
deleted file mode 100644 (file)
index 6985944..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-PROG = 7zS2.sfx\r
-\r
-C_OBJS = \\r
-  $O\7zAlloc.obj \\r
-  $O\7zArcIn.obj \\r
-  $O\7zBuf.obj \\r
-  $O\7zBuf2.obj \\r
-  $O\7zCrc.obj \\r
-  $O\7zCrcOpt.obj \\r
-  $O\7zFile.obj \\r
-  $O\7zDec.obj \\r
-  $O\7zStream.obj \\r
-  $O\Bcj2.obj \\r
-  $O\Bra.obj \\r
-  $O\Bra86.obj \\r
-  $O\BraIA64.obj \\r
-  $O\CpuArch.obj \\r
-  $O\Delta.obj \\r
-  $O\DllSecur.obj \\r
-  $O\Lzma2Dec.obj \\r
-  $O\LzmaDec.obj \\r
-\r
-7Z_OBJS = \\r
-  $O\SfxSetup.obj \\r
-\r
-OBJS = \\r
-  $(7Z_OBJS) \\r
-  $(C_OBJS) \\r
-  $O\resource.res\r
-\r
-!include "../../../CPP/Build.mak"\r
-\r
-$(7Z_OBJS): $(*B).c\r
-       $(COMPL_O1)\r
-$(C_OBJS): ../../$(*B).c\r
-       $(COMPL_O1)\r
diff --git a/deps/lzma-16.04/C/Util/SfxSetup/makefile_con b/deps/lzma-16.04/C/Util/SfxSetup/makefile_con
deleted file mode 100644 (file)
index cb2c1a4..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-PROG = 7zS2con.sfx\r
-CFLAGS = $(CFLAGS) -D_CONSOLE\r
-\r
-C_OBJS = \\r
-  $O\7zAlloc.obj \\r
-  $O\7zArcIn.obj \\r
-  $O\7zBuf.obj \\r
-  $O\7zBuf2.obj \\r
-  $O\7zCrc.obj \\r
-  $O\7zCrcOpt.obj \\r
-  $O\7zFile.obj \\r
-  $O\7zDec.obj \\r
-  $O\7zStream.obj \\r
-  $O\Bcj2.obj \\r
-  $O\Bra.obj \\r
-  $O\Bra86.obj \\r
-  $O\BraIA64.obj \\r
-  $O\CpuArch.obj \\r
-  $O\Delta.obj \\r
-  $O\DllSecur.obj \\r
-  $O\Lzma2Dec.obj \\r
-  $O\LzmaDec.obj \\r
-\r
-7Z_OBJS = \\r
-  $O\SfxSetup.obj \\r
-\r
-OBJS = \\r
-  $(7Z_OBJS) \\r
-  $(C_OBJS) \\r
-  $O\resource.res\r
-\r
-!include "../../../CPP/Build.mak"\r
-\r
-$(7Z_OBJS): $(*B).c\r
-       $(COMPL_O1)\r
-$(C_OBJS): ../../$(*B).c\r
-       $(COMPL_O1)\r
diff --git a/deps/lzma-16.04/C/Util/SfxSetup/resource.rc b/deps/lzma-16.04/C/Util/SfxSetup/resource.rc
deleted file mode 100644 (file)
index 64f4e2c..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "../../7zVersion.rc"\r
-\r
-MY_VERSION_INFO_APP("7z Setup SFX small", "7zS2.sfx")\r
-\r
-1  ICON "setup.ico"\r
diff --git a/deps/lzma-16.04/C/Util/SfxSetup/setup.ico b/deps/lzma-16.04/C/Util/SfxSetup/setup.ico
deleted file mode 100644 (file)
index dbb6ca8..0000000
Binary files a/deps/lzma-16.04/C/Util/SfxSetup/setup.ico and /dev/null differ
diff --git a/deps/lzma-16.04/C/Xz.c b/deps/lzma-16.04/C/Xz.c
deleted file mode 100644 (file)
index 92144db..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/* Xz.c - Xz\r
-2015-05-01 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "7zCrc.h"\r
-#include "CpuArch.h"\r
-#include "Xz.h"\r
-#include "XzCrc64.h"\r
-\r
-const Byte XZ_SIG[XZ_SIG_SIZE] = { 0xFD, '7', 'z', 'X', 'Z', 0 };\r
-const Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE] = { 'Y', 'Z' };\r
-\r
-unsigned Xz_WriteVarInt(Byte *buf, UInt64 v)\r
-{\r
-  unsigned i = 0;\r
-  do\r
-  {\r
-    buf[i++] = (Byte)((v & 0x7F) | 0x80);\r
-    v >>= 7;\r
-  }\r
-  while (v != 0);\r
-  buf[i - 1] &= 0x7F;\r
-  return i;\r
-}\r
-\r
-void Xz_Construct(CXzStream *p)\r
-{\r
-  p->numBlocks = p->numBlocksAllocated = 0;\r
-  p->blocks = 0;\r
-  p->flags = 0;\r
-}\r
-\r
-void Xz_Free(CXzStream *p, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, p->blocks);\r
-  p->numBlocks = p->numBlocksAllocated = 0;\r
-  p->blocks = 0;\r
-}\r
-\r
-unsigned XzFlags_GetCheckSize(CXzStreamFlags f)\r
-{\r
-  unsigned t = XzFlags_GetCheckType(f);\r
-  return (t == 0) ? 0 : (4 << ((t - 1) / 3));\r
-}\r
-\r
-void XzCheck_Init(CXzCheck *p, unsigned mode)\r
-{\r
-  p->mode = mode;\r
-  switch (mode)\r
-  {\r
-    case XZ_CHECK_CRC32: p->crc = CRC_INIT_VAL; break;\r
-    case XZ_CHECK_CRC64: p->crc64 = CRC64_INIT_VAL; break;\r
-    case XZ_CHECK_SHA256: Sha256_Init(&p->sha); break;\r
-  }\r
-}\r
-\r
-void XzCheck_Update(CXzCheck *p, const void *data, size_t size)\r
-{\r
-  switch (p->mode)\r
-  {\r
-    case XZ_CHECK_CRC32: p->crc = CrcUpdate(p->crc, data, size); break;\r
-    case XZ_CHECK_CRC64: p->crc64 = Crc64Update(p->crc64, data, size); break;\r
-    case XZ_CHECK_SHA256: Sha256_Update(&p->sha, (const Byte *)data, size); break;\r
-  }\r
-}\r
-\r
-int XzCheck_Final(CXzCheck *p, Byte *digest)\r
-{\r
-  switch (p->mode)\r
-  {\r
-    case XZ_CHECK_CRC32:\r
-      SetUi32(digest, CRC_GET_DIGEST(p->crc));\r
-      break;\r
-    case XZ_CHECK_CRC64:\r
-    {\r
-      int i;\r
-      UInt64 v = CRC64_GET_DIGEST(p->crc64);\r
-      for (i = 0; i < 8; i++, v >>= 8)\r
-        digest[i] = (Byte)(v & 0xFF);\r
-      break;\r
-    }\r
-    case XZ_CHECK_SHA256:\r
-      Sha256_Final(&p->sha, digest);\r
-      break;\r
-    default:\r
-      return 0;\r
-  }\r
-  return 1;\r
-}\r
diff --git a/deps/lzma-16.04/C/Xz.h b/deps/lzma-16.04/C/Xz.h
deleted file mode 100644 (file)
index 6937bea..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-/* Xz.h - Xz interface\r
-2015-05-01 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __XZ_H\r
-#define __XZ_H\r
-\r
-#include "Sha256.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-#define XZ_ID_Subblock 1\r
-#define XZ_ID_Delta 3\r
-#define XZ_ID_X86 4\r
-#define XZ_ID_PPC 5\r
-#define XZ_ID_IA64 6\r
-#define XZ_ID_ARM 7\r
-#define XZ_ID_ARMT 8\r
-#define XZ_ID_SPARC 9\r
-#define XZ_ID_LZMA2 0x21\r
-\r
-unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value);\r
-unsigned Xz_WriteVarInt(Byte *buf, UInt64 v);\r
-\r
-/* ---------- xz block ---------- */\r
-\r
-#define XZ_BLOCK_HEADER_SIZE_MAX 1024\r
-\r
-#define XZ_NUM_FILTERS_MAX 4\r
-#define XZ_BF_NUM_FILTERS_MASK 3\r
-#define XZ_BF_PACK_SIZE (1 << 6)\r
-#define XZ_BF_UNPACK_SIZE (1 << 7)\r
-\r
-#define XZ_FILTER_PROPS_SIZE_MAX 20\r
-\r
-typedef struct\r
-{\r
-  UInt64 id;\r
-  UInt32 propsSize;\r
-  Byte props[XZ_FILTER_PROPS_SIZE_MAX];\r
-} CXzFilter;\r
-\r
-typedef struct\r
-{\r
-  UInt64 packSize;\r
-  UInt64 unpackSize;\r
-  Byte flags;\r
-  CXzFilter filters[XZ_NUM_FILTERS_MAX];\r
-} CXzBlock;\r
-\r
-#define XzBlock_GetNumFilters(p) (((p)->flags & XZ_BF_NUM_FILTERS_MASK) + 1)\r
-#define XzBlock_HasPackSize(p)   (((p)->flags & XZ_BF_PACK_SIZE) != 0)\r
-#define XzBlock_HasUnpackSize(p) (((p)->flags & XZ_BF_UNPACK_SIZE) != 0)\r
-\r
-SRes XzBlock_Parse(CXzBlock *p, const Byte *header);\r
-SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes);\r
-\r
-/* ---------- xz stream ---------- */\r
-\r
-#define XZ_SIG_SIZE 6\r
-#define XZ_FOOTER_SIG_SIZE 2\r
-\r
-extern const Byte XZ_SIG[XZ_SIG_SIZE];\r
-extern const Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE];\r
-\r
-#define XZ_STREAM_FLAGS_SIZE 2\r
-#define XZ_STREAM_CRC_SIZE 4\r
-\r
-#define XZ_STREAM_HEADER_SIZE (XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE)\r
-#define XZ_STREAM_FOOTER_SIZE (XZ_FOOTER_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE + 4)\r
-\r
-#define XZ_CHECK_MASK 0xF\r
-#define XZ_CHECK_NO 0\r
-#define XZ_CHECK_CRC32 1\r
-#define XZ_CHECK_CRC64 4\r
-#define XZ_CHECK_SHA256 10\r
-\r
-typedef struct\r
-{\r
-  unsigned mode;\r
-  UInt32 crc;\r
-  UInt64 crc64;\r
-  CSha256 sha;\r
-} CXzCheck;\r
-\r
-void XzCheck_Init(CXzCheck *p, unsigned mode);\r
-void XzCheck_Update(CXzCheck *p, const void *data, size_t size);\r
-int XzCheck_Final(CXzCheck *p, Byte *digest);\r
-\r
-typedef UInt16 CXzStreamFlags;\r
-\r
-#define XzFlags_IsSupported(f) ((f) <= XZ_CHECK_MASK)\r
-#define XzFlags_GetCheckType(f) ((f) & XZ_CHECK_MASK)\r
-#define XzFlags_HasDataCrc32(f) (Xz_GetCheckType(f) == XZ_CHECK_CRC32)\r
-unsigned XzFlags_GetCheckSize(CXzStreamFlags f);\r
-\r
-SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf);\r
-SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream);\r
-\r
-typedef struct\r
-{\r
-  UInt64 unpackSize;\r
-  UInt64 totalSize;\r
-} CXzBlockSizes;\r
-\r
-typedef struct\r
-{\r
-  CXzStreamFlags flags;\r
-  size_t numBlocks;\r
-  size_t numBlocksAllocated;\r
-  CXzBlockSizes *blocks;\r
-  UInt64 startOffset;\r
-} CXzStream;\r
-\r
-void Xz_Construct(CXzStream *p);\r
-void Xz_Free(CXzStream *p, ISzAlloc *alloc);\r
-\r
-#define XZ_SIZE_OVERFLOW ((UInt64)(Int64)-1)\r
-\r
-UInt64 Xz_GetUnpackSize(const CXzStream *p);\r
-UInt64 Xz_GetPackSize(const CXzStream *p);\r
-\r
-typedef struct\r
-{\r
-  size_t num;\r
-  size_t numAllocated;\r
-  CXzStream *streams;\r
-} CXzs;\r
-\r
-void Xzs_Construct(CXzs *p);\r
-void Xzs_Free(CXzs *p, ISzAlloc *alloc);\r
-SRes Xzs_ReadBackward(CXzs *p, ILookInStream *inStream, Int64 *startOffset, ICompressProgress *progress, ISzAlloc *alloc);\r
-\r
-UInt64 Xzs_GetNumBlocks(const CXzs *p);\r
-UInt64 Xzs_GetUnpackSize(const CXzs *p);\r
-\r
-typedef enum\r
-{\r
-  CODER_STATUS_NOT_SPECIFIED,               /* use main error code instead */\r
-  CODER_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\r
-  CODER_STATUS_NOT_FINISHED,                /* stream was not finished */\r
-  CODER_STATUS_NEEDS_MORE_INPUT             /* you must provide more input bytes */\r
-} ECoderStatus;\r
-\r
-typedef enum\r
-{\r
-  CODER_FINISH_ANY,   /* finish at any point */\r
-  CODER_FINISH_END    /* block must be finished at the end */\r
-} ECoderFinishMode;\r
-\r
-typedef struct _IStateCoder\r
-{\r
-  void *p;\r
-  void (*Free)(void *p, ISzAlloc *alloc);\r
-  SRes (*SetProps)(void *p, const Byte *props, size_t propSize, ISzAlloc *alloc);\r
-  void (*Init)(void *p);\r
-  SRes (*Code)(void *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-      int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished);\r
-} IStateCoder;\r
-\r
-#define MIXCODER_NUM_FILTERS_MAX 4\r
-\r
-typedef struct\r
-{\r
-  ISzAlloc *alloc;\r
-  Byte *buf;\r
-  unsigned numCoders;\r
-  int finished[MIXCODER_NUM_FILTERS_MAX - 1];\r
-  size_t pos[MIXCODER_NUM_FILTERS_MAX - 1];\r
-  size_t size[MIXCODER_NUM_FILTERS_MAX - 1];\r
-  UInt64 ids[MIXCODER_NUM_FILTERS_MAX];\r
-  IStateCoder coders[MIXCODER_NUM_FILTERS_MAX];\r
-} CMixCoder;\r
-\r
-void MixCoder_Construct(CMixCoder *p, ISzAlloc *alloc);\r
-void MixCoder_Free(CMixCoder *p);\r
-void MixCoder_Init(CMixCoder *p);\r
-SRes MixCoder_SetFromMethod(CMixCoder *p, unsigned coderIndex, UInt64 methodId);\r
-SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,\r
-    const Byte *src, SizeT *srcLen, int srcWasFinished,\r
-    ECoderFinishMode finishMode, ECoderStatus *status);\r
-\r
-typedef enum\r
-{\r
-  XZ_STATE_STREAM_HEADER,\r
-  XZ_STATE_STREAM_INDEX,\r
-  XZ_STATE_STREAM_INDEX_CRC,\r
-  XZ_STATE_STREAM_FOOTER,\r
-  XZ_STATE_STREAM_PADDING,\r
-  XZ_STATE_BLOCK_HEADER,\r
-  XZ_STATE_BLOCK,\r
-  XZ_STATE_BLOCK_FOOTER\r
-} EXzState;\r
-\r
-typedef struct\r
-{\r
-  EXzState state;\r
-  UInt32 pos;\r
-  unsigned alignPos;\r
-  unsigned indexPreSize;\r
-\r
-  CXzStreamFlags streamFlags;\r
-  \r
-  UInt32 blockHeaderSize;\r
-  UInt64 packSize;\r
-  UInt64 unpackSize;\r
-\r
-  UInt64 numBlocks;\r
-  UInt64 indexSize;\r
-  UInt64 indexPos;\r
-  UInt64 padSize;\r
-\r
-  UInt64 numStartedStreams;\r
-  UInt64 numFinishedStreams;\r
-  UInt64 numTotalBlocks;\r
-\r
-  UInt32 crc;\r
-  CMixCoder decoder;\r
-  CXzBlock block;\r
-  CXzCheck check;\r
-  CSha256 sha;\r
-  Byte shaDigest[SHA256_DIGEST_SIZE];\r
-  Byte buf[XZ_BLOCK_HEADER_SIZE_MAX];\r
-} CXzUnpacker;\r
-\r
-void XzUnpacker_Construct(CXzUnpacker *p, ISzAlloc *alloc);\r
-void XzUnpacker_Init(CXzUnpacker *p);\r
-void XzUnpacker_Free(CXzUnpacker *p);\r
-\r
-/*\r
-finishMode:\r
-  It has meaning only if the decoding reaches output limit (*destLen).\r
-  CODER_FINISH_ANY - use smallest number of input bytes\r
-  CODER_FINISH_END - read EndOfStream marker after decoding\r
-\r
-Returns:\r
-  SZ_OK\r
-    status:\r
-      CODER_STATUS_NOT_FINISHED,\r
-      CODER_STATUS_NEEDS_MORE_INPUT - maybe there are more xz streams,\r
-                                      call XzUnpacker_IsStreamWasFinished to check that current stream was finished\r
-  SZ_ERROR_MEM  - Memory allocation error\r
-  SZ_ERROR_DATA - Data error\r
-  SZ_ERROR_UNSUPPORTED - Unsupported method or method properties\r
-  SZ_ERROR_CRC  - CRC error\r
-  // SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r
-\r
-  SZ_ERROR_NO_ARCHIVE - the error with xz Stream Header with one of the following reasons:\r
-     - xz Stream Signature failure\r
-     - CRC32 of xz Stream Header is failed\r
-     - The size of Stream padding is not multiple of four bytes.\r
-    It's possible to get that error, if xz stream was finished and the stream\r
-    contains some another data. In that case you can call XzUnpacker_GetExtraSize()\r
-    function to get real size of xz stream.\r
-*/\r
-\r
-\r
-SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,\r
-    const Byte *src, SizeT *srcLen, ECoderFinishMode finishMode,\r
-    ECoderStatus *status);\r
-\r
-Bool XzUnpacker_IsStreamWasFinished(CXzUnpacker *p);\r
-\r
-/*\r
-Call XzUnpacker_GetExtraSize after XzUnpacker_Code function to detect real size of\r
-xz stream in two cases:\r
-XzUnpacker_Code() returns:\r
-  res == SZ_OK && status == CODER_STATUS_NEEDS_MORE_INPUT\r
-  res == SZ_ERROR_NO_ARCHIVE\r
-*/\r
-\r
-UInt64 XzUnpacker_GetExtraSize(CXzUnpacker *p);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/XzCrc64.c b/deps/lzma-16.04/C/XzCrc64.c
deleted file mode 100644 (file)
index bd0cf5a..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/* XzCrc64.c -- CRC64 calculation\r
-2015-03-01 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "XzCrc64.h"\r
-#include "CpuArch.h"\r
-\r
-#define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42)\r
-\r
-#ifdef MY_CPU_LE\r
-  #define CRC_NUM_TABLES 4\r
-#else\r
-  #define CRC_NUM_TABLES 5\r
-  #define CRC_UINT64_SWAP(v) \\r
-      ((v >> 56) \\r
-    | ((v >> 40) & ((UInt64)0xFF <<  8)) \\r
-    | ((v >> 24) & ((UInt64)0xFF << 16)) \\r
-    | ((v >>  8) & ((UInt64)0xFF << 24)) \\r
-    | ((v <<  8) & ((UInt64)0xFF << 32)) \\r
-    | ((v << 24) & ((UInt64)0xFF << 40)) \\r
-    | ((v << 40) & ((UInt64)0xFF << 48)) \\r
-    | ((v << 56)))\r
-\r
-  UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table);\r
-#endif\r
-\r
-#ifndef MY_CPU_BE\r
-  UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table);\r
-#endif\r
-\r
-typedef UInt64 (MY_FAST_CALL *CRC_FUNC)(UInt64 v, const void *data, size_t size, const UInt64 *table);\r
-\r
-static CRC_FUNC g_Crc64Update;\r
-UInt64 g_Crc64Table[256 * CRC_NUM_TABLES];\r
-\r
-UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size)\r
-{\r
-  return g_Crc64Update(v, data, size, g_Crc64Table);\r
-}\r
-\r
-UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size)\r
-{\r
-  return g_Crc64Update(CRC64_INIT_VAL, data, size, g_Crc64Table) ^ CRC64_INIT_VAL;\r
-}\r
-\r
-void MY_FAST_CALL Crc64GenerateTable()\r
-{\r
-  UInt32 i;\r
-  for (i = 0; i < 256; i++)\r
-  {\r
-    UInt64 r = i;\r
-    unsigned j;\r
-    for (j = 0; j < 8; j++)\r
-      r = (r >> 1) ^ (kCrc64Poly & ~((r & 1) - 1));\r
-    g_Crc64Table[i] = r;\r
-  }\r
-  for (; i < 256 * CRC_NUM_TABLES; i++)\r
-  {\r
-    UInt64 r = g_Crc64Table[i - 256];\r
-    g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8);\r
-  }\r
-  \r
-  #ifdef MY_CPU_LE\r
-\r
-  g_Crc64Update = XzCrc64UpdateT4;\r
-\r
-  #else\r
-  {\r
-    #ifndef MY_CPU_BE\r
-    UInt32 k = 1;\r
-    if (*(const Byte *)&k == 1)\r
-      g_Crc64Update = XzCrc64UpdateT4;\r
-    else\r
-    #endif\r
-    {\r
-      for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--)\r
-      {\r
-        UInt64 x = g_Crc64Table[i - 256];\r
-        g_Crc64Table[i] = CRC_UINT64_SWAP(x);\r
-      }\r
-      g_Crc64Update = XzCrc64UpdateT1_BeT4;\r
-    }\r
-  }\r
-  #endif\r
-}\r
diff --git a/deps/lzma-16.04/C/XzCrc64.h b/deps/lzma-16.04/C/XzCrc64.h
deleted file mode 100644 (file)
index 71b10d5..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/* XzCrc64.h -- CRC64 calculation\r
-2013-01-18 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __XZ_CRC64_H\r
-#define __XZ_CRC64_H\r
-\r
-#include <stddef.h>\r
-\r
-#include "7zTypes.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-extern UInt64 g_Crc64Table[];\r
-\r
-void MY_FAST_CALL Crc64GenerateTable(void);\r
-\r
-#define CRC64_INIT_VAL UINT64_CONST(0xFFFFFFFFFFFFFFFF)\r
-#define CRC64_GET_DIGEST(crc) ((crc) ^ CRC64_INIT_VAL)\r
-#define CRC64_UPDATE_BYTE(crc, b) (g_Crc64Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r
-\r
-UInt64 MY_FAST_CALL Crc64Update(UInt64 crc, const void *data, size_t size);\r
-UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/XzCrc64Opt.c b/deps/lzma-16.04/C/XzCrc64Opt.c
deleted file mode 100644 (file)
index 97d086e..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/* XzCrc64Opt.c -- CRC64 calculation\r
-2015-03-01 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include "CpuArch.h"\r
-\r
-#ifndef MY_CPU_BE\r
-\r
-#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r
-\r
-UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table)\r
-{\r
-  const Byte *p = (const Byte *)data;\r
-  for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2(v, *p);\r
-  for (; size >= 4; size -= 4, p += 4)\r
-  {\r
-    UInt32 d = (UInt32)v ^ *(const UInt32 *)p;\r
-    v = (v >> 32)\r
-        ^ table[0x300 + ((d      ) & 0xFF)]\r
-        ^ table[0x200 + ((d >>  8) & 0xFF)]\r
-        ^ table[0x100 + ((d >> 16) & 0xFF)]\r
-        ^ table[0x000 + ((d >> 24))];\r
-  }\r
-  for (; size > 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2(v, *p);\r
-  return v;\r
-}\r
-\r
-#endif\r
-\r
-\r
-#ifndef MY_CPU_LE\r
-\r
-#define CRC_UINT64_SWAP(v) \\r
-      ((v >> 56) \\r
-    | ((v >> 40) & ((UInt64)0xFF <<  8)) \\r
-    | ((v >> 24) & ((UInt64)0xFF << 16)) \\r
-    | ((v >>  8) & ((UInt64)0xFF << 24)) \\r
-    | ((v <<  8) & ((UInt64)0xFF << 32)) \\r
-    | ((v << 24) & ((UInt64)0xFF << 40)) \\r
-    | ((v << 40) & ((UInt64)0xFF << 48)) \\r
-    | ((v << 56)))\r
-\r
-#define CRC_UPDATE_BYTE_2_BE(crc, b) (table[(Byte)((crc) >> 56) ^ (b)] ^ ((crc) << 8))\r
-\r
-UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table)\r
-{\r
-  const Byte *p = (const Byte *)data;\r
-  table += 0x100;\r
-  v = CRC_UINT64_SWAP(v);\r
-  for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2_BE(v, *p);\r
-  for (; size >= 4; size -= 4, p += 4)\r
-  {\r
-    UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)p;\r
-    v = (v << 32)\r
-        ^ table[0x000 + ((d      ) & 0xFF)]\r
-        ^ table[0x100 + ((d >>  8) & 0xFF)]\r
-        ^ table[0x200 + ((d >> 16) & 0xFF)]\r
-        ^ table[0x300 + ((d >> 24))];\r
-  }\r
-  for (; size > 0; size--, p++)\r
-    v = CRC_UPDATE_BYTE_2_BE(v, *p);\r
-  return CRC_UINT64_SWAP(v);\r
-}\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/XzDec.c b/deps/lzma-16.04/C/XzDec.c
deleted file mode 100644 (file)
index 29831b0..0000000
+++ /dev/null
@@ -1,913 +0,0 @@
-/* XzDec.c -- Xz Decode\r
-2015-11-09 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-/* #define XZ_DUMP */\r
-\r
-#ifdef XZ_DUMP\r
-#include <stdio.h>\r
-#endif\r
-\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#include "7zCrc.h"\r
-#include "Alloc.h"\r
-#include "Bra.h"\r
-#include "CpuArch.h"\r
-#include "Delta.h"\r
-#include "Lzma2Dec.h"\r
-\r
-#ifdef USE_SUBBLOCK\r
-#include "Bcj3Dec.c"\r
-#include "SbDec.c"\r
-#endif\r
-\r
-#include "Xz.h"\r
-\r
-#define XZ_CHECK_SIZE_MAX 64\r
-\r
-#define CODER_BUF_SIZE (1 << 17)\r
-\r
-unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value)\r
-{\r
-  unsigned i, limit;\r
-  *value = 0;\r
-  limit = (maxSize > 9) ? 9 : (unsigned)maxSize;\r
-\r
-  for (i = 0; i < limit;)\r
-  {\r
-    Byte b = p[i];\r
-    *value |= (UInt64)(b & 0x7F) << (7 * i++);\r
-    if ((b & 0x80) == 0)\r
-      return (b == 0 && i != 1) ? 0 : i;\r
-  }\r
-  return 0;\r
-}\r
-\r
-/* ---------- BraState ---------- */\r
-\r
-#define BRA_BUF_SIZE (1 << 14)\r
-\r
-typedef struct\r
-{\r
-  size_t bufPos;\r
-  size_t bufConv;\r
-  size_t bufTotal;\r
-\r
-  UInt32 methodId;\r
-  int encodeMode;\r
-  UInt32 delta;\r
-  UInt32 ip;\r
-  UInt32 x86State;\r
-  Byte deltaState[DELTA_STATE_SIZE];\r
-\r
-  Byte buf[BRA_BUF_SIZE];\r
-} CBraState;\r
-\r
-static void BraState_Free(void *pp, ISzAlloc *alloc)\r
-{\r
-  alloc->Free(alloc, pp);\r
-}\r
-\r
-static SRes BraState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)\r
-{\r
-  CBraState *p = ((CBraState *)pp);\r
-  UNUSED_VAR(alloc);\r
-  p->ip = 0;\r
-  if (p->methodId == XZ_ID_Delta)\r
-  {\r
-    if (propSize != 1)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-    p->delta = (unsigned)props[0] + 1;\r
-  }\r
-  else\r
-  {\r
-    if (propSize == 4)\r
-    {\r
-      UInt32 v = GetUi32(props);\r
-      switch (p->methodId)\r
-      {\r
-        case XZ_ID_PPC:\r
-        case XZ_ID_ARM:\r
-        case XZ_ID_SPARC:\r
-          if ((v & 3) != 0)\r
-            return SZ_ERROR_UNSUPPORTED;\r
-          break;\r
-        case XZ_ID_ARMT:\r
-          if ((v & 1) != 0)\r
-            return SZ_ERROR_UNSUPPORTED;\r
-          break;\r
-        case XZ_ID_IA64:\r
-          if ((v & 0xF) != 0)\r
-            return SZ_ERROR_UNSUPPORTED;\r
-          break;\r
-      }\r
-      p->ip = v;\r
-    }\r
-    else if (propSize != 0)\r
-      return SZ_ERROR_UNSUPPORTED;\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-static void BraState_Init(void *pp)\r
-{\r
-  CBraState *p = ((CBraState *)pp);\r
-  p->bufPos = p->bufConv = p->bufTotal = 0;\r
-  x86_Convert_Init(p->x86State);\r
-  if (p->methodId == XZ_ID_Delta)\r
-    Delta_Init(p->deltaState);\r
-}\r
-\r
-#define CASE_BRA_CONV(isa) case XZ_ID_ ## isa: p->bufConv = isa ## _Convert(p->buf, p->bufTotal, p->ip, p->encodeMode); break;\r
-\r
-static SRes BraState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-    int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)\r
-{\r
-  CBraState *p = ((CBraState *)pp);\r
-  SizeT destLenOrig = *destLen;\r
-  SizeT srcLenOrig = *srcLen;\r
-  UNUSED_VAR(finishMode);\r
-  *destLen = 0;\r
-  *srcLen = 0;\r
-  *wasFinished = 0;\r
-  while (destLenOrig > 0)\r
-  {\r
-    if (p->bufPos != p->bufConv)\r
-    {\r
-      size_t curSize = p->bufConv - p->bufPos;\r
-      if (curSize > destLenOrig)\r
-        curSize = destLenOrig;\r
-      memcpy(dest, p->buf + p->bufPos, curSize);\r
-      p->bufPos += curSize;\r
-      *destLen += curSize;\r
-      dest += curSize;\r
-      destLenOrig -= curSize;\r
-      continue;\r
-    }\r
-    p->bufTotal -= p->bufPos;\r
-    memmove(p->buf, p->buf + p->bufPos, p->bufTotal);\r
-    p->bufPos = 0;\r
-    p->bufConv = 0;\r
-    {\r
-      size_t curSize = BRA_BUF_SIZE - p->bufTotal;\r
-      if (curSize > srcLenOrig)\r
-        curSize = srcLenOrig;\r
-      memcpy(p->buf + p->bufTotal, src, curSize);\r
-      *srcLen += curSize;\r
-      src += curSize;\r
-      srcLenOrig -= curSize;\r
-      p->bufTotal += curSize;\r
-    }\r
-    if (p->bufTotal == 0)\r
-      break;\r
-    switch (p->methodId)\r
-    {\r
-      case XZ_ID_Delta:\r
-        if (p->encodeMode)\r
-          Delta_Encode(p->deltaState, p->delta, p->buf, p->bufTotal);\r
-        else\r
-          Delta_Decode(p->deltaState, p->delta, p->buf, p->bufTotal);\r
-        p->bufConv = p->bufTotal;\r
-        break;\r
-      case XZ_ID_X86:\r
-        p->bufConv = x86_Convert(p->buf, p->bufTotal, p->ip, &p->x86State, p->encodeMode);\r
-        break;\r
-      CASE_BRA_CONV(PPC)\r
-      CASE_BRA_CONV(IA64)\r
-      CASE_BRA_CONV(ARM)\r
-      CASE_BRA_CONV(ARMT)\r
-      CASE_BRA_CONV(SPARC)\r
-      default:\r
-        return SZ_ERROR_UNSUPPORTED;\r
-    }\r
-    p->ip += (UInt32)p->bufConv;\r
-\r
-    if (p->bufConv == 0)\r
-    {\r
-      if (!srcWasFinished)\r
-        break;\r
-      p->bufConv = p->bufTotal;\r
-    }\r
-  }\r
-  if (p->bufTotal == p->bufPos && srcLenOrig == 0 && srcWasFinished)\r
-    *wasFinished = 1;\r
-  return SZ_OK;\r
-}\r
-\r
-SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc *alloc)\r
-{\r
-  CBraState *decoder;\r
-  if (id != XZ_ID_Delta &&\r
-      id != XZ_ID_X86 &&\r
-      id != XZ_ID_PPC &&\r
-      id != XZ_ID_IA64 &&\r
-      id != XZ_ID_ARM &&\r
-      id != XZ_ID_ARMT &&\r
-      id != XZ_ID_SPARC)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  p->p = 0;\r
-  decoder = (CBraState *)alloc->Alloc(alloc, sizeof(CBraState));\r
-  if (decoder == 0)\r
-    return SZ_ERROR_MEM;\r
-  decoder->methodId = (UInt32)id;\r
-  decoder->encodeMode = encodeMode;\r
-  p->p = decoder;\r
-  p->Free = BraState_Free;\r
-  p->SetProps = BraState_SetProps;\r
-  p->Init = BraState_Init;\r
-  p->Code = BraState_Code;\r
-  return SZ_OK;\r
-}\r
-\r
-/* ---------- SbState ---------- */\r
-\r
-#ifdef USE_SUBBLOCK\r
-\r
-static void SbState_Free(void *pp, ISzAlloc *alloc)\r
-{\r
-  CSbDec *p = (CSbDec *)pp;\r
-  SbDec_Free(p);\r
-  alloc->Free(alloc, pp);\r
-}\r
-\r
-static SRes SbState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)\r
-{\r
-  UNUSED_VAR(pp);\r
-  UNUSED_VAR(props);\r
-  UNUSED_VAR(alloc);\r
-  return (propSize == 0) ? SZ_OK : SZ_ERROR_UNSUPPORTED;\r
-}\r
-\r
-static void SbState_Init(void *pp)\r
-{\r
-  SbDec_Init((CSbDec *)pp);\r
-}\r
-\r
-static SRes SbState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-    int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)\r
-{\r
-  CSbDec *p = (CSbDec *)pp;\r
-  SRes res;\r
-  UNUSED_VAR(srcWasFinished);\r
-  p->dest = dest;\r
-  p->destLen = *destLen;\r
-  p->src = src;\r
-  p->srcLen = *srcLen;\r
-  p->finish = finishMode; /* change it */\r
-  res = SbDec_Decode((CSbDec *)pp);\r
-  *destLen -= p->destLen;\r
-  *srcLen -= p->srcLen;\r
-  *wasFinished = (*destLen == 0 && *srcLen == 0); /* change it */\r
-  return res;\r
-}\r
-\r
-SRes SbState_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)\r
-{\r
-  CSbDec *decoder;\r
-  p->p = 0;\r
-  decoder = alloc->Alloc(alloc, sizeof(CSbDec));\r
-  if (decoder == 0)\r
-    return SZ_ERROR_MEM;\r
-  p->p = decoder;\r
-  p->Free = SbState_Free;\r
-  p->SetProps = SbState_SetProps;\r
-  p->Init = SbState_Init;\r
-  p->Code = SbState_Code;\r
-  SbDec_Construct(decoder);\r
-  SbDec_SetAlloc(decoder, alloc);\r
-  return SZ_OK;\r
-}\r
-#endif\r
-\r
-/* ---------- Lzma2State ---------- */\r
-\r
-static void Lzma2State_Free(void *pp, ISzAlloc *alloc)\r
-{\r
-  Lzma2Dec_Free((CLzma2Dec *)pp, alloc);\r
-  alloc->Free(alloc, pp);\r
-}\r
-\r
-static SRes Lzma2State_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)\r
-{\r
-  if (propSize != 1)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  return Lzma2Dec_Allocate((CLzma2Dec *)pp, props[0], alloc);\r
-}\r
-\r
-static void Lzma2State_Init(void *pp)\r
-{\r
-  Lzma2Dec_Init((CLzma2Dec *)pp);\r
-}\r
-\r
-static SRes Lzma2State_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-    int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)\r
-{\r
-  ELzmaStatus status;\r
-  /* ELzmaFinishMode fm = (finishMode == LZMA_FINISH_ANY) ? LZMA_FINISH_ANY : LZMA_FINISH_END; */\r
-  SRes res = Lzma2Dec_DecodeToBuf((CLzma2Dec *)pp, dest, destLen, src, srcLen, (ELzmaFinishMode)finishMode, &status);\r
-  UNUSED_VAR(srcWasFinished);\r
-  *wasFinished = (status == LZMA_STATUS_FINISHED_WITH_MARK);\r
-  return res;\r
-}\r
-\r
-static SRes Lzma2State_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)\r
-{\r
-  CLzma2Dec *decoder = (CLzma2Dec *)alloc->Alloc(alloc, sizeof(CLzma2Dec));\r
-  p->p = decoder;\r
-  if (decoder == 0)\r
-    return SZ_ERROR_MEM;\r
-  p->Free = Lzma2State_Free;\r
-  p->SetProps = Lzma2State_SetProps;\r
-  p->Init = Lzma2State_Init;\r
-  p->Code = Lzma2State_Code;\r
-  Lzma2Dec_Construct(decoder);\r
-  return SZ_OK;\r
-}\r
-\r
-\r
-void MixCoder_Construct(CMixCoder *p, ISzAlloc *alloc)\r
-{\r
-  unsigned i;\r
-  p->alloc = alloc;\r
-  p->buf = NULL;\r
-  p->numCoders = 0;\r
-  for (i = 0; i < MIXCODER_NUM_FILTERS_MAX; i++)\r
-    p->coders[i].p = NULL;\r
-}\r
-\r
-void MixCoder_Free(CMixCoder *p)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < p->numCoders; i++)\r
-  {\r
-    IStateCoder *sc = &p->coders[i];\r
-    if (p->alloc && sc->p)\r
-      sc->Free(sc->p, p->alloc);\r
-  }\r
-  p->numCoders = 0;\r
-  if (p->buf)\r
-  {\r
-    p->alloc->Free(p->alloc, p->buf);\r
-    p->buf = NULL; /* 9.31: the BUG was fixed */\r
-  }\r
-}\r
-\r
-void MixCoder_Init(CMixCoder *p)\r
-{\r
-  unsigned i;\r
-  for (i = 0; i < MIXCODER_NUM_FILTERS_MAX - 1; i++)\r
-  {\r
-    p->size[i] = 0;\r
-    p->pos[i] = 0;\r
-    p->finished[i] = 0;\r
-  }\r
-  for (i = 0; i < p->numCoders; i++)\r
-  {\r
-    IStateCoder *coder = &p->coders[i];\r
-    coder->Init(coder->p);\r
-  }\r
-}\r
-\r
-SRes MixCoder_SetFromMethod(CMixCoder *p, unsigned coderIndex, UInt64 methodId)\r
-{\r
-  IStateCoder *sc = &p->coders[coderIndex];\r
-  p->ids[coderIndex] = methodId;\r
-  switch (methodId)\r
-  {\r
-    case XZ_ID_LZMA2: return Lzma2State_SetFromMethod(sc, p->alloc);\r
-    #ifdef USE_SUBBLOCK\r
-    case XZ_ID_Subblock: return SbState_SetFromMethod(sc, p->alloc);\r
-    #endif\r
-  }\r
-  if (coderIndex == 0)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  return BraState_SetFromMethod(sc, methodId, 0, p->alloc);\r
-}\r
-\r
-SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,\r
-    const Byte *src, SizeT *srcLen, int srcWasFinished,\r
-    ECoderFinishMode finishMode, ECoderStatus *status)\r
-{\r
-  SizeT destLenOrig = *destLen;\r
-  SizeT srcLenOrig = *srcLen;\r
-  Bool allFinished = True;\r
-  *destLen = 0;\r
-  *srcLen = 0;\r
-  *status = CODER_STATUS_NOT_FINISHED;\r
-\r
-  if (!p->buf)\r
-  {\r
-    p->buf = (Byte *)p->alloc->Alloc(p->alloc, CODER_BUF_SIZE * (MIXCODER_NUM_FILTERS_MAX - 1));\r
-    if (!p->buf)\r
-      return SZ_ERROR_MEM;\r
-  }\r
-\r
-  if (p->numCoders != 1)\r
-    finishMode = CODER_FINISH_ANY;\r
-\r
-  for (;;)\r
-  {\r
-    Bool processed = False;\r
-    unsigned i;\r
-    /*\r
-    if (p->numCoders == 1 && *destLen == destLenOrig && finishMode == LZMA_FINISH_ANY)\r
-      break;\r
-    */\r
-\r
-    for (i = 0; i < p->numCoders; i++)\r
-    {\r
-      SRes res;\r
-      IStateCoder *coder = &p->coders[i];\r
-      Byte *destCur;\r
-      SizeT destLenCur, srcLenCur;\r
-      const Byte *srcCur;\r
-      int srcFinishedCur;\r
-      int encodingWasFinished;\r
-      \r
-      if (i == 0)\r
-      {\r
-        srcCur = src;\r
-        srcLenCur = srcLenOrig - *srcLen;\r
-        srcFinishedCur = srcWasFinished;\r
-      }\r
-      else\r
-      {\r
-        srcCur = p->buf + (CODER_BUF_SIZE * (i - 1)) + p->pos[i - 1];\r
-        srcLenCur = p->size[i - 1] - p->pos[i - 1];\r
-        srcFinishedCur = p->finished[i - 1];\r
-      }\r
-      \r
-      if (i == p->numCoders - 1)\r
-      {\r
-        destCur = dest;\r
-        destLenCur = destLenOrig - *destLen;\r
-      }\r
-      else\r
-      {\r
-        if (p->pos[i] != p->size[i])\r
-          continue;\r
-        destCur = p->buf + (CODER_BUF_SIZE * i);\r
-        destLenCur = CODER_BUF_SIZE;\r
-      }\r
-      \r
-      res = coder->Code(coder->p, destCur, &destLenCur, srcCur, &srcLenCur, srcFinishedCur, finishMode, &encodingWasFinished);\r
-\r
-      if (!encodingWasFinished)\r
-        allFinished = False;\r
-\r
-      if (i == 0)\r
-      {\r
-        *srcLen += srcLenCur;\r
-        src += srcLenCur;\r
-      }\r
-      else\r
-      {\r
-        p->pos[i - 1] += srcLenCur;\r
-      }\r
-\r
-      if (i == p->numCoders - 1)\r
-      {\r
-        *destLen += destLenCur;\r
-        dest += destLenCur;\r
-      }\r
-      else\r
-      {\r
-        p->size[i] = destLenCur;\r
-        p->pos[i] = 0;\r
-        p->finished[i] = encodingWasFinished;\r
-      }\r
-      \r
-      if (res != SZ_OK)\r
-        return res;\r
-\r
-      if (destLenCur != 0 || srcLenCur != 0)\r
-        processed = True;\r
-    }\r
-    if (!processed)\r
-      break;\r
-  }\r
-  if (allFinished)\r
-    *status = CODER_STATUS_FINISHED_WITH_MARK;\r
-  return SZ_OK;\r
-}\r
-\r
-SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf)\r
-{\r
-  *p = (CXzStreamFlags)GetBe16(buf + XZ_SIG_SIZE);\r
-  if (CrcCalc(buf + XZ_SIG_SIZE, XZ_STREAM_FLAGS_SIZE) !=\r
-      GetUi32(buf + XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE))\r
-    return SZ_ERROR_NO_ARCHIVE;\r
-  return XzFlags_IsSupported(*p) ? SZ_OK : SZ_ERROR_UNSUPPORTED;\r
-}\r
-\r
-static Bool Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte *buf)\r
-{\r
-  return\r
-      indexSize == (((UInt64)GetUi32(buf + 4) + 1) << 2) &&\r
-      (GetUi32(buf) == CrcCalc(buf + 4, 6) &&\r
-      flags == GetBe16(buf + 8) &&\r
-      memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) == 0);\r
-}\r
-\r
-#define READ_VARINT_AND_CHECK(buf, pos, size, res) \\r
-  { unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \\r
-  if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; }\r
-\r
-\r
-SRes XzBlock_Parse(CXzBlock *p, const Byte *header)\r
-{\r
-  unsigned pos;\r
-  unsigned numFilters, i;\r
-  unsigned headerSize = (unsigned)header[0] << 2;\r
-\r
-  if (CrcCalc(header, headerSize) != GetUi32(header + headerSize))\r
-    return SZ_ERROR_ARCHIVE;\r
-\r
-  pos = 1;\r
-  if (pos == headerSize)\r
-    return SZ_ERROR_ARCHIVE;\r
-  p->flags = header[pos++];\r
-\r
-  if (XzBlock_HasPackSize(p))\r
-  {\r
-    READ_VARINT_AND_CHECK(header, pos, headerSize, &p->packSize);\r
-    if (p->packSize == 0 || p->packSize + headerSize >= (UInt64)1 << 63)\r
-      return SZ_ERROR_ARCHIVE;\r
-  }\r
-\r
-  if (XzBlock_HasUnpackSize(p))\r
-    READ_VARINT_AND_CHECK(header, pos, headerSize, &p->unpackSize);\r
-\r
-  numFilters = XzBlock_GetNumFilters(p);\r
-  for (i = 0; i < numFilters; i++)\r
-  {\r
-    CXzFilter *filter = p->filters + i;\r
-    UInt64 size;\r
-    READ_VARINT_AND_CHECK(header, pos, headerSize, &filter->id);\r
-    READ_VARINT_AND_CHECK(header, pos, headerSize, &size);\r
-    if (size > headerSize - pos || size > XZ_FILTER_PROPS_SIZE_MAX)\r
-      return SZ_ERROR_ARCHIVE;\r
-    filter->propsSize = (UInt32)size;\r
-    memcpy(filter->props, header + pos, (size_t)size);\r
-    pos += (unsigned)size;\r
-\r
-    #ifdef XZ_DUMP\r
-    printf("\nf[%u] = %2X: ", i, (unsigned)filter->id);\r
-    {\r
-      unsigned i;\r
-      for (i = 0; i < size; i++)\r
-        printf(" %2X", filter->props[i]);\r
-    }\r
-    #endif\r
-  }\r
-\r
-  while (pos < headerSize)\r
-    if (header[pos++] != 0)\r
-      return SZ_ERROR_ARCHIVE;\r
-  return SZ_OK;\r
-}\r
-\r
-SRes XzDec_Init(CMixCoder *p, const CXzBlock *block)\r
-{\r
-  unsigned i;\r
-  Bool needReInit = True;\r
-  unsigned numFilters = XzBlock_GetNumFilters(block);\r
-  \r
-  if (numFilters == p->numCoders)\r
-  {\r
-    for (i = 0; i < numFilters; i++)\r
-      if (p->ids[i] != block->filters[numFilters - 1 - i].id)\r
-        break;\r
-    needReInit = (i != numFilters);\r
-  }\r
-  \r
-  if (needReInit)\r
-  {\r
-    MixCoder_Free(p);\r
-    p->numCoders = numFilters;\r
-    for (i = 0; i < numFilters; i++)\r
-    {\r
-      const CXzFilter *f = &block->filters[numFilters - 1 - i];\r
-      RINOK(MixCoder_SetFromMethod(p, i, f->id));\r
-    }\r
-  }\r
-  \r
-  for (i = 0; i < numFilters; i++)\r
-  {\r
-    const CXzFilter *f = &block->filters[numFilters - 1 - i];\r
-    IStateCoder *sc = &p->coders[i];\r
-    RINOK(sc->SetProps(sc->p, f->props, f->propsSize, p->alloc));\r
-  }\r
-  \r
-  MixCoder_Init(p);\r
-  return SZ_OK;\r
-}\r
-\r
-void XzUnpacker_Init(CXzUnpacker *p)\r
-{\r
-  p->state = XZ_STATE_STREAM_HEADER;\r
-  p->pos = 0;\r
-  p->numStartedStreams = 0;\r
-  p->numFinishedStreams = 0;\r
-  p->numTotalBlocks = 0;\r
-  p->padSize = 0;\r
-}\r
-\r
-void XzUnpacker_Construct(CXzUnpacker *p, ISzAlloc *alloc)\r
-{\r
-  MixCoder_Construct(&p->decoder, alloc);\r
-  XzUnpacker_Init(p);\r
-}\r
-\r
-void XzUnpacker_Free(CXzUnpacker *p)\r
-{\r
-  MixCoder_Free(&p->decoder);\r
-}\r
-\r
-SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,\r
-    const Byte *src, SizeT *srcLen, ECoderFinishMode finishMode, ECoderStatus *status)\r
-{\r
-  SizeT destLenOrig = *destLen;\r
-  SizeT srcLenOrig = *srcLen;\r
-  *destLen = 0;\r
-  *srcLen = 0;\r
-  *status = CODER_STATUS_NOT_SPECIFIED;\r
-  for (;;)\r
-  {\r
-    SizeT srcRem = srcLenOrig - *srcLen;\r
-\r
-    if (p->state == XZ_STATE_BLOCK)\r
-    {\r
-      SizeT destLen2 = destLenOrig - *destLen;\r
-      SizeT srcLen2 = srcLenOrig - *srcLen;\r
-      SRes res;\r
-      if (srcLen2 == 0 && destLen2 == 0)\r
-      {\r
-        *status = CODER_STATUS_NOT_FINISHED;\r
-        return SZ_OK;\r
-      }\r
-      \r
-      res = MixCoder_Code(&p->decoder, dest, &destLen2, src, &srcLen2, False, finishMode, status);\r
-      XzCheck_Update(&p->check, dest, destLen2);\r
-      \r
-      (*srcLen) += srcLen2;\r
-      src += srcLen2;\r
-      p->packSize += srcLen2;\r
-      \r
-      (*destLen) += destLen2;\r
-      dest += destLen2;\r
-      p->unpackSize += destLen2;\r
-      \r
-      RINOK(res);\r
-      \r
-      if (*status == CODER_STATUS_FINISHED_WITH_MARK)\r
-      {\r
-        Byte temp[32];\r
-        unsigned num = Xz_WriteVarInt(temp, p->packSize + p->blockHeaderSize + XzFlags_GetCheckSize(p->streamFlags));\r
-        num += Xz_WriteVarInt(temp + num, p->unpackSize);\r
-        Sha256_Update(&p->sha, temp, num);\r
-        p->indexSize += num;\r
-        p->numBlocks++;\r
-        \r
-        p->state = XZ_STATE_BLOCK_FOOTER;\r
-        p->pos = 0;\r
-        p->alignPos = 0;\r
-      }\r
-      else if (srcLen2 == 0 && destLen2 == 0)\r
-        return SZ_OK;\r
-      \r
-      continue;\r
-    }\r
-\r
-    if (srcRem == 0)\r
-    {\r
-      *status = CODER_STATUS_NEEDS_MORE_INPUT;\r
-      return SZ_OK;\r
-    }\r
-\r
-    switch (p->state)\r
-    {\r
-      case XZ_STATE_STREAM_HEADER:\r
-      {\r
-        if (p->pos < XZ_STREAM_HEADER_SIZE)\r
-        {\r
-          if (p->pos < XZ_SIG_SIZE && *src != XZ_SIG[p->pos])\r
-            return SZ_ERROR_NO_ARCHIVE;\r
-          p->buf[p->pos++] = *src++;\r
-          (*srcLen)++;\r
-        }\r
-        else\r
-        {\r
-          RINOK(Xz_ParseHeader(&p->streamFlags, p->buf));\r
-          p->numStartedStreams++;\r
-          p->state = XZ_STATE_BLOCK_HEADER;\r
-          Sha256_Init(&p->sha);\r
-          p->indexSize = 0;\r
-          p->numBlocks = 0;\r
-          p->pos = 0;\r
-        }\r
-        break;\r
-      }\r
-\r
-      case XZ_STATE_BLOCK_HEADER:\r
-      {\r
-        if (p->pos == 0)\r
-        {\r
-          p->buf[p->pos++] = *src++;\r
-          (*srcLen)++;\r
-          if (p->buf[0] == 0)\r
-          {\r
-            p->indexPreSize = 1 + Xz_WriteVarInt(p->buf + 1, p->numBlocks);\r
-            p->indexPos = p->indexPreSize;\r
-            p->indexSize += p->indexPreSize;\r
-            Sha256_Final(&p->sha, p->shaDigest);\r
-            Sha256_Init(&p->sha);\r
-            p->crc = CrcUpdate(CRC_INIT_VAL, p->buf, p->indexPreSize);\r
-            p->state = XZ_STATE_STREAM_INDEX;\r
-          }\r
-          p->blockHeaderSize = ((UInt32)p->buf[0] << 2) + 4;\r
-        }\r
-        else if (p->pos != p->blockHeaderSize)\r
-        {\r
-          UInt32 cur = p->blockHeaderSize - p->pos;\r
-          if (cur > srcRem)\r
-            cur = (UInt32)srcRem;\r
-          memcpy(p->buf + p->pos, src, cur);\r
-          p->pos += cur;\r
-          (*srcLen) += cur;\r
-          src += cur;\r
-        }\r
-        else\r
-        {\r
-          RINOK(XzBlock_Parse(&p->block, p->buf));\r
-          p->numTotalBlocks++;\r
-          p->state = XZ_STATE_BLOCK;\r
-          p->packSize = 0;\r
-          p->unpackSize = 0;\r
-          XzCheck_Init(&p->check, XzFlags_GetCheckType(p->streamFlags));\r
-          RINOK(XzDec_Init(&p->decoder, &p->block));\r
-        }\r
-        break;\r
-      }\r
-\r
-      case XZ_STATE_BLOCK_FOOTER:\r
-      {\r
-        if (((p->packSize + p->alignPos) & 3) != 0)\r
-        {\r
-          (*srcLen)++;\r
-          p->alignPos++;\r
-          if (*src++ != 0)\r
-            return SZ_ERROR_CRC;\r
-        }\r
-        else\r
-        {\r
-          UInt32 checkSize = XzFlags_GetCheckSize(p->streamFlags);\r
-          UInt32 cur = checkSize - p->pos;\r
-          if (cur != 0)\r
-          {\r
-            if (cur > srcRem)\r
-              cur = (UInt32)srcRem;\r
-            memcpy(p->buf + p->pos, src, cur);\r
-            p->pos += cur;\r
-            (*srcLen) += cur;\r
-            src += cur;\r
-          }\r
-          else\r
-          {\r
-            Byte digest[XZ_CHECK_SIZE_MAX];\r
-            p->state = XZ_STATE_BLOCK_HEADER;\r
-            p->pos = 0;\r
-            if (XzCheck_Final(&p->check, digest) && memcmp(digest, p->buf, checkSize) != 0)\r
-              return SZ_ERROR_CRC;\r
-          }\r
-        }\r
-        break;\r
-      }\r
-\r
-      case XZ_STATE_STREAM_INDEX:\r
-      {\r
-        if (p->pos < p->indexPreSize)\r
-        {\r
-          (*srcLen)++;\r
-          if (*src++ != p->buf[p->pos++])\r
-            return SZ_ERROR_CRC;\r
-        }\r
-        else\r
-        {\r
-          if (p->indexPos < p->indexSize)\r
-          {\r
-            UInt64 cur = p->indexSize - p->indexPos;\r
-            if (srcRem > cur)\r
-              srcRem = (SizeT)cur;\r
-            p->crc = CrcUpdate(p->crc, src, srcRem);\r
-            Sha256_Update(&p->sha, src, srcRem);\r
-            (*srcLen) += srcRem;\r
-            src += srcRem;\r
-            p->indexPos += srcRem;\r
-          }\r
-          else if ((p->indexPos & 3) != 0)\r
-          {\r
-            Byte b = *src++;\r
-            p->crc = CRC_UPDATE_BYTE(p->crc, b);\r
-            (*srcLen)++;\r
-            p->indexPos++;\r
-            p->indexSize++;\r
-            if (b != 0)\r
-              return SZ_ERROR_CRC;\r
-          }\r
-          else\r
-          {\r
-            Byte digest[SHA256_DIGEST_SIZE];\r
-            p->state = XZ_STATE_STREAM_INDEX_CRC;\r
-            p->indexSize += 4;\r
-            p->pos = 0;\r
-            Sha256_Final(&p->sha, digest);\r
-            if (memcmp(digest, p->shaDigest, SHA256_DIGEST_SIZE) != 0)\r
-              return SZ_ERROR_CRC;\r
-          }\r
-        }\r
-        break;\r
-      }\r
-\r
-      case XZ_STATE_STREAM_INDEX_CRC:\r
-      {\r
-        if (p->pos < 4)\r
-        {\r
-          (*srcLen)++;\r
-          p->buf[p->pos++] = *src++;\r
-        }\r
-        else\r
-        {\r
-          p->state = XZ_STATE_STREAM_FOOTER;\r
-          p->pos = 0;\r
-          if (CRC_GET_DIGEST(p->crc) != GetUi32(p->buf))\r
-            return SZ_ERROR_CRC;\r
-        }\r
-        break;\r
-      }\r
-\r
-      case XZ_STATE_STREAM_FOOTER:\r
-      {\r
-        UInt32 cur = XZ_STREAM_FOOTER_SIZE - p->pos;\r
-        if (cur > srcRem)\r
-          cur = (UInt32)srcRem;\r
-        memcpy(p->buf + p->pos, src, cur);\r
-        p->pos += cur;\r
-        (*srcLen) += cur;\r
-        src += cur;\r
-        if (p->pos == XZ_STREAM_FOOTER_SIZE)\r
-        {\r
-          p->state = XZ_STATE_STREAM_PADDING;\r
-          p->numFinishedStreams++;\r
-          p->padSize = 0;\r
-          if (!Xz_CheckFooter(p->streamFlags, p->indexSize, p->buf))\r
-            return SZ_ERROR_CRC;\r
-        }\r
-        break;\r
-      }\r
-\r
-      case XZ_STATE_STREAM_PADDING:\r
-      {\r
-        if (*src != 0)\r
-        {\r
-          if (((UInt32)p->padSize & 3) != 0)\r
-            return SZ_ERROR_NO_ARCHIVE;\r
-          p->pos = 0;\r
-          p->state = XZ_STATE_STREAM_HEADER;\r
-        }\r
-        else\r
-        {\r
-          (*srcLen)++;\r
-          src++;\r
-          p->padSize++;\r
-        }\r
-        break;\r
-      }\r
-      \r
-      case XZ_STATE_BLOCK: break; /* to disable GCC warning */\r
-    }\r
-  }\r
-  /*\r
-  if (p->state == XZ_STATE_FINISHED)\r
-    *status = CODER_STATUS_FINISHED_WITH_MARK;\r
-  return SZ_OK;\r
-  */\r
-}\r
-\r
-Bool XzUnpacker_IsStreamWasFinished(CXzUnpacker *p)\r
-{\r
-  return (p->state == XZ_STATE_STREAM_PADDING) && (((UInt32)p->padSize & 3) == 0);\r
-}\r
-\r
-UInt64 XzUnpacker_GetExtraSize(CXzUnpacker *p)\r
-{\r
-  UInt64 num = 0;\r
-  if (p->state == XZ_STATE_STREAM_PADDING)\r
-    num += p->padSize;\r
-  else if (p->state == XZ_STATE_STREAM_HEADER)\r
-    num += p->padSize + p->pos;\r
-  return num;\r
-}\r
diff --git a/deps/lzma-16.04/C/XzEnc.c b/deps/lzma-16.04/C/XzEnc.c
deleted file mode 100644 (file)
index 2e5a003..0000000
+++ /dev/null
@@ -1,538 +0,0 @@
-/* XzEnc.c -- Xz Encode\r
-2015-09-16 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#include "7zCrc.h"\r
-#include "Alloc.h"\r
-#include "Bra.h"\r
-#include "CpuArch.h"\r
-\r
-#ifdef USE_SUBBLOCK\r
-#include "Bcj3Enc.c"\r
-#include "SbFind.c"\r
-#include "SbEnc.c"\r
-#endif\r
-\r
-#include "XzEnc.h"\r
-\r
-#define XzBlock_ClearFlags(p)       (p)->flags = 0;\r
-#define XzBlock_SetNumFilters(p, n) (p)->flags |= ((n) - 1);\r
-#define XzBlock_SetHasPackSize(p)   (p)->flags |= XZ_BF_PACK_SIZE;\r
-#define XzBlock_SetHasUnpackSize(p) (p)->flags |= XZ_BF_UNPACK_SIZE;\r
-\r
-static SRes WriteBytes(ISeqOutStream *s, const void *buf, UInt32 size)\r
-{\r
-  return (s->Write(s, buf, size) == size) ? SZ_OK : SZ_ERROR_WRITE;\r
-}\r
-\r
-static SRes WriteBytesAndCrc(ISeqOutStream *s, const void *buf, UInt32 size, UInt32 *crc)\r
-{\r
-  *crc = CrcUpdate(*crc, buf, size);\r
-  return WriteBytes(s, buf, size);\r
-}\r
-\r
-static SRes Xz_WriteHeader(CXzStreamFlags f, ISeqOutStream *s)\r
-{\r
-  UInt32 crc;\r
-  Byte header[XZ_STREAM_HEADER_SIZE];\r
-  memcpy(header, XZ_SIG, XZ_SIG_SIZE);\r
-  header[XZ_SIG_SIZE] = (Byte)(f >> 8);\r
-  header[XZ_SIG_SIZE + 1] = (Byte)(f & 0xFF);\r
-  crc = CrcCalc(header + XZ_SIG_SIZE, XZ_STREAM_FLAGS_SIZE);\r
-  SetUi32(header + XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE, crc);\r
-  return WriteBytes(s, header, XZ_STREAM_HEADER_SIZE);\r
-}\r
-\r
-\r
-static SRes XzBlock_WriteHeader(const CXzBlock *p, ISeqOutStream *s)\r
-{\r
-  Byte header[XZ_BLOCK_HEADER_SIZE_MAX];\r
-\r
-  unsigned pos = 1;\r
-  unsigned numFilters, i;\r
-  header[pos++] = p->flags;\r
-\r
-  if (XzBlock_HasPackSize(p)) pos += Xz_WriteVarInt(header + pos, p->packSize);\r
-  if (XzBlock_HasUnpackSize(p)) pos += Xz_WriteVarInt(header + pos, p->unpackSize);\r
-  numFilters = XzBlock_GetNumFilters(p);\r
-  \r
-  for (i = 0; i < numFilters; i++)\r
-  {\r
-    const CXzFilter *f = &p->filters[i];\r
-    pos += Xz_WriteVarInt(header + pos, f->id);\r
-    pos += Xz_WriteVarInt(header + pos, f->propsSize);\r
-    memcpy(header + pos, f->props, f->propsSize);\r
-    pos += f->propsSize;\r
-  }\r
-\r
-  while ((pos & 3) != 0)\r
-    header[pos++] = 0;\r
-\r
-  header[0] = (Byte)(pos >> 2);\r
-  SetUi32(header + pos, CrcCalc(header, pos));\r
-  return WriteBytes(s, header, pos + 4);\r
-}\r
-\r
-\r
-static SRes Xz_WriteFooter(CXzStream *p, ISeqOutStream *s)\r
-{\r
-  Byte buf[32];\r
-  UInt64 globalPos;\r
-  {\r
-    UInt32 crc = CRC_INIT_VAL;\r
-    unsigned pos = 1 + Xz_WriteVarInt(buf + 1, p->numBlocks);\r
-    size_t i;\r
-\r
-    globalPos = pos;\r
-    buf[0] = 0;\r
-    RINOK(WriteBytesAndCrc(s, buf, pos, &crc));\r
-\r
-    for (i = 0; i < p->numBlocks; i++)\r
-    {\r
-      const CXzBlockSizes *block = &p->blocks[i];\r
-      pos = Xz_WriteVarInt(buf, block->totalSize);\r
-      pos += Xz_WriteVarInt(buf + pos, block->unpackSize);\r
-      globalPos += pos;\r
-      RINOK(WriteBytesAndCrc(s, buf, pos, &crc));\r
-    }\r
-    \r
-    pos = ((unsigned)globalPos & 3);\r
-    \r
-    if (pos != 0)\r
-    {\r
-      buf[0] = buf[1] = buf[2] = 0;\r
-      RINOK(WriteBytesAndCrc(s, buf, 4 - pos, &crc));\r
-      globalPos += 4 - pos;\r
-    }\r
-    {\r
-      SetUi32(buf, CRC_GET_DIGEST(crc));\r
-      RINOK(WriteBytes(s, buf, 4));\r
-      globalPos += 4;\r
-    }\r
-  }\r
-\r
-  {\r
-    UInt32 indexSize = (UInt32)((globalPos >> 2) - 1);\r
-    SetUi32(buf + 4, indexSize);\r
-    buf[8] = (Byte)(p->flags >> 8);\r
-    buf[9] = (Byte)(p->flags & 0xFF);\r
-    SetUi32(buf, CrcCalc(buf + 4, 6));\r
-    memcpy(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE);\r
-    return WriteBytes(s, buf, 12);\r
-  }\r
-}\r
-\r
-\r
-static SRes Xz_AddIndexRecord(CXzStream *p, UInt64 unpackSize, UInt64 totalSize, ISzAlloc *alloc)\r
-{\r
-  if (!p->blocks || p->numBlocksAllocated == p->numBlocks)\r
-  {\r
-    size_t num = p->numBlocks * 2 + 1;\r
-    size_t newSize = sizeof(CXzBlockSizes) * num;\r
-    CXzBlockSizes *blocks;\r
-    if (newSize / sizeof(CXzBlockSizes) != num)\r
-      return SZ_ERROR_MEM;\r
-    blocks = (CXzBlockSizes *)alloc->Alloc(alloc, newSize);\r
-    if (!blocks)\r
-      return SZ_ERROR_MEM;\r
-    if (p->numBlocks != 0)\r
-    {\r
-      memcpy(blocks, p->blocks, p->numBlocks * sizeof(CXzBlockSizes));\r
-      alloc->Free(alloc, p->blocks);\r
-    }\r
-    p->blocks = blocks;\r
-    p->numBlocksAllocated = num;\r
-  }\r
-  {\r
-    CXzBlockSizes *block = &p->blocks[p->numBlocks++];\r
-    block->unpackSize = unpackSize;\r
-    block->totalSize = totalSize;\r
-  }\r
-  return SZ_OK;\r
-}\r
-\r
-\r
-/* ---------- CSeqCheckInStream ---------- */\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream p;\r
-  ISeqInStream *realStream;\r
-  UInt64 processed;\r
-  CXzCheck check;\r
-} CSeqCheckInStream;\r
-\r
-static void SeqCheckInStream_Init(CSeqCheckInStream *p, unsigned mode)\r
-{\r
-  p->processed = 0;\r
-  XzCheck_Init(&p->check, mode);\r
-}\r
-\r
-static void SeqCheckInStream_GetDigest(CSeqCheckInStream *p, Byte *digest)\r
-{\r
-  XzCheck_Final(&p->check, digest);\r
-}\r
-\r
-static SRes SeqCheckInStream_Read(void *pp, void *data, size_t *size)\r
-{\r
-  CSeqCheckInStream *p = (CSeqCheckInStream *)pp;\r
-  SRes res = p->realStream->Read(p->realStream, data, size);\r
-  XzCheck_Update(&p->check, data, *size);\r
-  p->processed += *size;\r
-  return res;\r
-}\r
-\r
-\r
-/* ---------- CSeqSizeOutStream ---------- */\r
-\r
-typedef struct\r
-{\r
-  ISeqOutStream p;\r
-  ISeqOutStream *realStream;\r
-  UInt64 processed;\r
-} CSeqSizeOutStream;\r
-\r
-static size_t MyWrite(void *pp, const void *data, size_t size)\r
-{\r
-  CSeqSizeOutStream *p = (CSeqSizeOutStream *)pp;\r
-  size = p->realStream->Write(p->realStream, data, size);\r
-  p->processed += size;\r
-  return size;\r
-}\r
-\r
-\r
-/* ---------- CSeqInFilter ---------- */\r
-\r
-#define FILTER_BUF_SIZE (1 << 20)\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream p;\r
-  ISeqInStream *realStream;\r
-  IStateCoder StateCoder;\r
-  Byte *buf;\r
-  size_t curPos;\r
-  size_t endPos;\r
-  int srcWasFinished;\r
-} CSeqInFilter;\r
-\r
-static SRes SeqInFilter_Read(void *pp, void *data, size_t *size)\r
-{\r
-  CSeqInFilter *p = (CSeqInFilter *)pp;\r
-  size_t sizeOriginal = *size;\r
-  if (sizeOriginal == 0)\r
-    return SZ_OK;\r
-  *size = 0;\r
-  \r
-  for (;;)\r
-  {\r
-    if (!p->srcWasFinished && p->curPos == p->endPos)\r
-    {\r
-      p->curPos = 0;\r
-      p->endPos = FILTER_BUF_SIZE;\r
-      RINOK(p->realStream->Read(p->realStream, p->buf, &p->endPos));\r
-      if (p->endPos == 0)\r
-        p->srcWasFinished = 1;\r
-    }\r
-    {\r
-      SizeT srcLen = p->endPos - p->curPos;\r
-      int wasFinished;\r
-      SRes res;\r
-      *size = sizeOriginal;\r
-      res = p->StateCoder.Code(p->StateCoder.p, data, size, p->buf + p->curPos, &srcLen,\r
-        p->srcWasFinished, CODER_FINISH_ANY, &wasFinished);\r
-      p->curPos += srcLen;\r
-      if (*size != 0 || srcLen == 0 || res != 0)\r
-        return res;\r
-    }\r
-  }\r
-}\r
-\r
-static void SeqInFilter_Construct(CSeqInFilter *p)\r
-{\r
-  p->buf = NULL;\r
-  p->p.Read = SeqInFilter_Read;\r
-}\r
-\r
-static void SeqInFilter_Free(CSeqInFilter *p)\r
-{\r
-  if (p->buf)\r
-  {\r
-    g_Alloc.Free(&g_Alloc, p->buf);\r
-    p->buf = NULL;\r
-  }\r
-}\r
-\r
-SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc *alloc);\r
-\r
-static SRes SeqInFilter_Init(CSeqInFilter *p, const CXzFilter *props)\r
-{\r
-  if (!p->buf)\r
-  {\r
-    p->buf = g_Alloc.Alloc(&g_Alloc, FILTER_BUF_SIZE);\r
-    if (!p->buf)\r
-      return SZ_ERROR_MEM;\r
-  }\r
-  p->curPos = p->endPos = 0;\r
-  p->srcWasFinished = 0;\r
-  RINOK(BraState_SetFromMethod(&p->StateCoder, props->id, 1, &g_Alloc));\r
-  RINOK(p->StateCoder.SetProps(p->StateCoder.p, props->props, props->propsSize, &g_Alloc));\r
-  p->StateCoder.Init(p->StateCoder.p);\r
-  return SZ_OK;\r
-}\r
-\r
-\r
-/* ---------- CSbEncInStream ---------- */\r
-\r
-#ifdef USE_SUBBLOCK\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream p;\r
-  ISeqInStream *inStream;\r
-  CSbEnc enc;\r
-} CSbEncInStream;\r
-\r
-static SRes SbEncInStream_Read(void *pp, void *data, size_t *size)\r
-{\r
-  CSbEncInStream *p = (CSbEncInStream *)pp;\r
-  size_t sizeOriginal = *size;\r
-  if (sizeOriginal == 0)\r
-    return S_OK;\r
-  \r
-  for (;;)\r
-  {\r
-    if (p->enc.needRead && !p->enc.readWasFinished)\r
-    {\r
-      size_t processed = p->enc.needReadSizeMax;\r
-      RINOK(p->inStream->Read(p->inStream, p->enc.buf + p->enc.readPos, &processed));\r
-      p->enc.readPos += processed;\r
-      if (processed == 0)\r
-      {\r
-        p->enc.readWasFinished = True;\r
-        p->enc.isFinalFinished = True;\r
-      }\r
-      p->enc.needRead = False;\r
-    }\r
-  \r
-    *size = sizeOriginal;\r
-    RINOK(SbEnc_Read(&p->enc, data, size));\r
-    if (*size != 0 || !p->enc.needRead)\r
-      return S_OK;\r
-  }\r
-}\r
-\r
-void SbEncInStream_Construct(CSbEncInStream *p, ISzAlloc *alloc)\r
-{\r
-  SbEnc_Construct(&p->enc, alloc);\r
-  p->p.Read = SbEncInStream_Read;\r
-}\r
-\r
-SRes SbEncInStream_Init(CSbEncInStream *p)\r
-{\r
-  return SbEnc_Init(&p->enc);\r
-}\r
-\r
-void SbEncInStream_Free(CSbEncInStream *p)\r
-{\r
-  SbEnc_Free(&p->enc);\r
-}\r
-\r
-#endif\r
-\r
-\r
-typedef struct\r
-{\r
-  CLzma2EncHandle lzma2;\r
-  #ifdef USE_SUBBLOCK\r
-  CSbEncInStream sb;\r
-  #endif\r
-  CSeqInFilter filter;\r
-  ISzAlloc *alloc;\r
-  ISzAlloc *bigAlloc;\r
-} CLzma2WithFilters;\r
-\r
-\r
-static void Lzma2WithFilters_Construct(CLzma2WithFilters *p, ISzAlloc *alloc, ISzAlloc *bigAlloc)\r
-{\r
-  p->alloc = alloc;\r
-  p->bigAlloc = bigAlloc;\r
-  p->lzma2 = NULL;\r
-  #ifdef USE_SUBBLOCK\r
-  SbEncInStream_Construct(&p->sb, alloc);\r
-  #endif\r
-  SeqInFilter_Construct(&p->filter);\r
-}\r
-\r
-static SRes Lzma2WithFilters_Create(CLzma2WithFilters *p)\r
-{\r
-  p->lzma2 = Lzma2Enc_Create(p->alloc, p->bigAlloc);\r
-  if (!p->lzma2)\r
-    return SZ_ERROR_MEM;\r
-  return SZ_OK;\r
-}\r
-\r
-static void Lzma2WithFilters_Free(CLzma2WithFilters *p)\r
-{\r
-  SeqInFilter_Free(&p->filter);\r
-  #ifdef USE_SUBBLOCK\r
-  SbEncInStream_Free(&p->sb);\r
-  #endif\r
-  if (p->lzma2)\r
-  {\r
-    Lzma2Enc_Destroy(p->lzma2);\r
-    p->lzma2 = NULL;\r
-  }\r
-}\r
-\r
-\r
-void XzProps_Init(CXzProps *p)\r
-{\r
-  p->lzma2Props = NULL;\r
-  p->filterProps = NULL;\r
-  p->checkId = XZ_CHECK_CRC32;\r
-}\r
-\r
-void XzFilterProps_Init(CXzFilterProps *p)\r
-{\r
-  p->id = 0;\r
-  p->delta = 0;\r
-  p->ip = 0;\r
-  p->ipDefined = False;\r
-}\r
-\r
-\r
-static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,\r
-    ISeqOutStream *outStream, ISeqInStream *inStream,\r
-    const CXzProps *props, ICompressProgress *progress)\r
-{\r
-  xz->flags = (Byte)props->checkId;\r
-\r
-  RINOK(Lzma2Enc_SetProps(lzmaf->lzma2, props->lzma2Props));\r
-  RINOK(Xz_WriteHeader(xz->flags, outStream));\r
-\r
-  {\r
-    CSeqCheckInStream checkInStream;\r
-    CSeqSizeOutStream seqSizeOutStream;\r
-    CXzBlock block;\r
-    unsigned filterIndex = 0;\r
-    CXzFilter *filter = NULL;\r
-    const CXzFilterProps *fp = props->filterProps;\r
-    \r
-    XzBlock_ClearFlags(&block);\r
-    XzBlock_SetNumFilters(&block, 1 + (fp ? 1 : 0));\r
-    \r
-    if (fp)\r
-    {\r
-      filter = &block.filters[filterIndex++];\r
-      filter->id = fp->id;\r
-      filter->propsSize = 0;\r
-      \r
-      if (fp->id == XZ_ID_Delta)\r
-      {\r
-        filter->props[0] = (Byte)(fp->delta - 1);\r
-        filter->propsSize = 1;\r
-      }\r
-      else if (fp->ipDefined)\r
-      {\r
-        SetUi32(filter->props, fp->ip);\r
-        filter->propsSize = 4;\r
-      }\r
-    }\r
-\r
-    {\r
-      CXzFilter *f = &block.filters[filterIndex++];\r
-      f->id = XZ_ID_LZMA2;\r
-      f->propsSize = 1;\r
-      f->props[0] = Lzma2Enc_WriteProperties(lzmaf->lzma2);\r
-    }\r
-\r
-    seqSizeOutStream.p.Write = MyWrite;\r
-    seqSizeOutStream.realStream = outStream;\r
-    seqSizeOutStream.processed = 0;\r
-    \r
-    RINOK(XzBlock_WriteHeader(&block, &seqSizeOutStream.p));\r
-    \r
-    checkInStream.p.Read = SeqCheckInStream_Read;\r
-    checkInStream.realStream = inStream;\r
-    SeqCheckInStream_Init(&checkInStream, XzFlags_GetCheckType(xz->flags));\r
-    \r
-    if (fp)\r
-    {\r
-      #ifdef USE_SUBBLOCK\r
-      if (fp->id == XZ_ID_Subblock)\r
-      {\r
-        lzmaf->sb.inStream = &checkInStream.p;\r
-        RINOK(SbEncInStream_Init(&lzmaf->sb));\r
-      }\r
-      else\r
-      #endif\r
-      {\r
-        lzmaf->filter.realStream = &checkInStream.p;\r
-        RINOK(SeqInFilter_Init(&lzmaf->filter, filter));\r
-      }\r
-    }\r
-\r
-    {\r
-      UInt64 packPos = seqSizeOutStream.processed;\r
-      \r
-      SRes res = Lzma2Enc_Encode(lzmaf->lzma2, &seqSizeOutStream.p,\r
-          fp ?\r
-            #ifdef USE_SUBBLOCK\r
-            (fp->id == XZ_ID_Subblock) ? &lzmaf->sb.p:\r
-            #endif\r
-            &lzmaf->filter.p:\r
-            &checkInStream.p,\r
-          progress);\r
-      \r
-      RINOK(res);\r
-      block.unpackSize = checkInStream.processed;\r
-      block.packSize = seqSizeOutStream.processed - packPos;\r
-    }\r
-\r
-    {\r
-      unsigned padSize = 0;\r
-      Byte buf[128];\r
-      while ((((unsigned)block.packSize + padSize) & 3) != 0)\r
-        buf[padSize++] = 0;\r
-      SeqCheckInStream_GetDigest(&checkInStream, buf + padSize);\r
-      RINOK(WriteBytes(&seqSizeOutStream.p, buf, padSize + XzFlags_GetCheckSize(xz->flags)));\r
-      RINOK(Xz_AddIndexRecord(xz, block.unpackSize, seqSizeOutStream.processed - padSize, &g_Alloc));\r
-    }\r
-  }\r
-  return Xz_WriteFooter(xz, outStream);\r
-}\r
-\r
-\r
-SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,\r
-    const CXzProps *props, ICompressProgress *progress)\r
-{\r
-  SRes res;\r
-  CXzStream xz;\r
-  CLzma2WithFilters lzmaf;\r
-  Xz_Construct(&xz);\r
-  Lzma2WithFilters_Construct(&lzmaf, &g_Alloc, &g_BigAlloc);\r
-  res = Lzma2WithFilters_Create(&lzmaf);\r
-  if (res == SZ_OK)\r
-    res = Xz_Compress(&xz, &lzmaf, outStream, inStream, props, progress);\r
-  Lzma2WithFilters_Free(&lzmaf);\r
-  Xz_Free(&xz, &g_Alloc);\r
-  return res;\r
-}\r
-\r
-\r
-SRes Xz_EncodeEmpty(ISeqOutStream *outStream)\r
-{\r
-  SRes res;\r
-  CXzStream xz;\r
-  Xz_Construct(&xz);\r
-  res = Xz_WriteHeader(xz.flags, outStream);\r
-  if (res == SZ_OK)\r
-    res = Xz_WriteFooter(&xz, outStream);\r
-  Xz_Free(&xz, &g_Alloc);\r
-  return res;\r
-}\r
diff --git a/deps/lzma-16.04/C/XzEnc.h b/deps/lzma-16.04/C/XzEnc.h
deleted file mode 100644 (file)
index e9cea34..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/* XzEnc.h -- Xz Encode\r
-2011-02-07 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __XZ_ENC_H\r
-#define __XZ_ENC_H\r
-\r
-#include "Lzma2Enc.h"\r
-\r
-#include "Xz.h"\r
-\r
-EXTERN_C_BEGIN\r
-\r
-typedef struct\r
-{\r
-  UInt32 id;\r
-  UInt32 delta;\r
-  UInt32 ip;\r
-  int ipDefined;\r
-} CXzFilterProps;\r
-\r
-void XzFilterProps_Init(CXzFilterProps *p);\r
-\r
-typedef struct\r
-{\r
-  const CLzma2EncProps *lzma2Props;\r
-  const CXzFilterProps *filterProps;\r
-  unsigned checkId;\r
-} CXzProps;\r
-\r
-void XzProps_Init(CXzProps *p);\r
-\r
-SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,\r
-    const CXzProps *props, ICompressProgress *progress);\r
-\r
-SRes Xz_EncodeEmpty(ISeqOutStream *outStream);\r
-\r
-EXTERN_C_END\r
-\r
-#endif\r
diff --git a/deps/lzma-16.04/C/XzIn.c b/deps/lzma-16.04/C/XzIn.c
deleted file mode 100644 (file)
index aaa0597..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-/* XzIn.c - Xz input\r
-2015-11-08 : Igor Pavlov : Public domain */\r
-\r
-#include "Precomp.h"\r
-\r
-#include <string.h>\r
-\r
-#include "7zCrc.h"\r
-#include "CpuArch.h"\r
-#include "Xz.h"\r
-\r
-SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream)\r
-{\r
-  Byte sig[XZ_STREAM_HEADER_SIZE];\r
-  RINOK(SeqInStream_Read2(inStream, sig, XZ_STREAM_HEADER_SIZE, SZ_ERROR_NO_ARCHIVE));\r
-  if (memcmp(sig, XZ_SIG, XZ_SIG_SIZE) != 0)\r
-    return SZ_ERROR_NO_ARCHIVE;\r
-  return Xz_ParseHeader(p, sig);\r
-}\r
-\r
-#define READ_VARINT_AND_CHECK(buf, pos, size, res) \\r
-  { unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \\r
-  if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; }\r
-\r
-SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes)\r
-{\r
-  Byte header[XZ_BLOCK_HEADER_SIZE_MAX];\r
-  unsigned headerSize;\r
-  *headerSizeRes = 0;\r
-  RINOK(SeqInStream_ReadByte(inStream, &header[0]));\r
-  headerSize = ((unsigned)header[0] << 2) + 4;\r
-  if (headerSize == 0)\r
-  {\r
-    *headerSizeRes = 1;\r
-    *isIndex = True;\r
-    return SZ_OK;\r
-  }\r
-\r
-  *isIndex = False;\r
-  *headerSizeRes = headerSize;\r
-  RINOK(SeqInStream_Read(inStream, header + 1, headerSize - 1));\r
-  return XzBlock_Parse(p, header);\r
-}\r
-\r
-#define ADD_SIZE_CHECH(size, val) \\r
-  { UInt64 newSize = size + (val); if (newSize < size) return XZ_SIZE_OVERFLOW; size = newSize; }\r
-\r
-UInt64 Xz_GetUnpackSize(const CXzStream *p)\r
-{\r
-  UInt64 size = 0;\r
-  size_t i;\r
-  for (i = 0; i < p->numBlocks; i++)\r
-    ADD_SIZE_CHECH(size, p->blocks[i].unpackSize);\r
-  return size;\r
-}\r
-\r
-UInt64 Xz_GetPackSize(const CXzStream *p)\r
-{\r
-  UInt64 size = 0;\r
-  size_t i;\r
-  for (i = 0; i < p->numBlocks; i++)\r
-    ADD_SIZE_CHECH(size, (p->blocks[i].totalSize + 3) & ~(UInt64)3);\r
-  return size;\r
-}\r
-\r
-/*\r
-SRes XzBlock_ReadFooter(CXzBlock *p, CXzStreamFlags f, ISeqInStream *inStream)\r
-{\r
-  return SeqInStream_Read(inStream, p->check, XzFlags_GetCheckSize(f));\r
-}\r
-*/\r
-\r
-static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAlloc *alloc)\r
-{\r
-  size_t numBlocks, pos = 1;\r
-  UInt32 crc;\r
-\r
-  if (size < 5 || buf[0] != 0)\r
-    return SZ_ERROR_ARCHIVE;\r
-\r
-  size -= 4;\r
-  crc = CrcCalc(buf, size);\r
-  if (crc != GetUi32(buf + size))\r
-    return SZ_ERROR_ARCHIVE;\r
-\r
-  {\r
-    UInt64 numBlocks64;\r
-    READ_VARINT_AND_CHECK(buf, pos, size, &numBlocks64);\r
-    numBlocks = (size_t)numBlocks64;\r
-    if (numBlocks != numBlocks64 || numBlocks * 2 > size)\r
-      return SZ_ERROR_ARCHIVE;\r
-  }\r
-  \r
-  Xz_Free(p, alloc);\r
-  if (numBlocks != 0)\r
-  {\r
-    size_t i;\r
-    p->numBlocks = numBlocks;\r
-    p->numBlocksAllocated = numBlocks;\r
-    p->blocks = alloc->Alloc(alloc, sizeof(CXzBlockSizes) * numBlocks);\r
-    if (p->blocks == 0)\r
-      return SZ_ERROR_MEM;\r
-    for (i = 0; i < numBlocks; i++)\r
-    {\r
-      CXzBlockSizes *block = &p->blocks[i];\r
-      READ_VARINT_AND_CHECK(buf, pos, size, &block->totalSize);\r
-      READ_VARINT_AND_CHECK(buf, pos, size, &block->unpackSize);\r
-      if (block->totalSize == 0)\r
-        return SZ_ERROR_ARCHIVE;\r
-    }\r
-  }\r
-  while ((pos & 3) != 0)\r
-    if (buf[pos++] != 0)\r
-      return SZ_ERROR_ARCHIVE;\r
-  return (pos == size) ? SZ_OK : SZ_ERROR_ARCHIVE;\r
-}\r
-\r
-static SRes Xz_ReadIndex(CXzStream *p, ILookInStream *stream, UInt64 indexSize, ISzAlloc *alloc)\r
-{\r
-  SRes res;\r
-  size_t size;\r
-  Byte *buf;\r
-  if (indexSize > ((UInt32)1 << 31))\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  size = (size_t)indexSize;\r
-  if (size != indexSize)\r
-    return SZ_ERROR_UNSUPPORTED;\r
-  buf = alloc->Alloc(alloc, size);\r
-  if (buf == 0)\r
-    return SZ_ERROR_MEM;\r
-  res = LookInStream_Read2(stream, buf, size, SZ_ERROR_UNSUPPORTED);\r
-  if (res == SZ_OK)\r
-    res = Xz_ReadIndex2(p, buf, size, alloc);\r
-  alloc->Free(alloc, buf);\r
-  return res;\r
-}\r
-\r
-static SRes LookInStream_SeekRead_ForArc(ILookInStream *stream, UInt64 offset, void *buf, size_t size)\r
-{\r
-  RINOK(LookInStream_SeekTo(stream, offset));\r
-  return LookInStream_Read(stream, buf, size);\r
-  /* return LookInStream_Read2(stream, buf, size, SZ_ERROR_NO_ARCHIVE); */\r
-}\r
-\r
-static SRes Xz_ReadBackward(CXzStream *p, ILookInStream *stream, Int64 *startOffset, ISzAlloc *alloc)\r
-{\r
-  UInt64 indexSize;\r
-  Byte buf[XZ_STREAM_FOOTER_SIZE];\r
-  UInt64 pos = *startOffset;\r
-\r
-  if ((pos & 3) != 0 || pos < XZ_STREAM_FOOTER_SIZE)\r
-    return SZ_ERROR_NO_ARCHIVE;\r
-\r
-  pos -= XZ_STREAM_FOOTER_SIZE;\r
-  RINOK(LookInStream_SeekRead_ForArc(stream, pos, buf, XZ_STREAM_FOOTER_SIZE));\r
-  \r
-  if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)\r
-  {\r
-    UInt32 total = 0;\r
-    pos += XZ_STREAM_FOOTER_SIZE;\r
-    \r
-    for (;;)\r
-    {\r
-      size_t i;\r
-      #define TEMP_BUF_SIZE (1 << 10)\r
-      Byte temp[TEMP_BUF_SIZE];\r
-      \r
-      i = (pos > TEMP_BUF_SIZE) ? TEMP_BUF_SIZE : (size_t)pos;\r
-      pos -= i;\r
-      RINOK(LookInStream_SeekRead_ForArc(stream, pos, temp, i));\r
-      total += (UInt32)i;\r
-      for (; i != 0; i--)\r
-        if (temp[i - 1] != 0)\r
-          break;\r
-      if (i != 0)\r
-      {\r
-        if ((i & 3) != 0)\r
-          return SZ_ERROR_NO_ARCHIVE;\r
-        pos += i;\r
-        break;\r
-      }\r
-      if (pos < XZ_STREAM_FOOTER_SIZE || total > (1 << 16))\r
-        return SZ_ERROR_NO_ARCHIVE;\r
-    }\r
-    \r
-    if (pos < XZ_STREAM_FOOTER_SIZE)\r
-      return SZ_ERROR_NO_ARCHIVE;\r
-    pos -= XZ_STREAM_FOOTER_SIZE;\r
-    RINOK(LookInStream_SeekRead_ForArc(stream, pos, buf, XZ_STREAM_FOOTER_SIZE));\r
-    if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)\r
-      return SZ_ERROR_NO_ARCHIVE;\r
-  }\r
-  \r
-  p->flags = (CXzStreamFlags)GetBe16(buf + 8);\r
-\r
-  if (!XzFlags_IsSupported(p->flags))\r
-    return SZ_ERROR_UNSUPPORTED;\r
-\r
-  if (GetUi32(buf) != CrcCalc(buf + 4, 6))\r
-    return SZ_ERROR_ARCHIVE;\r
-\r
-  indexSize = ((UInt64)GetUi32(buf + 4) + 1) << 2;\r
-\r
-  if (pos < indexSize)\r
-    return SZ_ERROR_ARCHIVE;\r
-\r
-  pos -= indexSize;\r
-  RINOK(LookInStream_SeekTo(stream, pos));\r
-  RINOK(Xz_ReadIndex(p, stream, indexSize, alloc));\r
-\r
-  {\r
-    UInt64 totalSize = Xz_GetPackSize(p);\r
-    if (totalSize == XZ_SIZE_OVERFLOW\r
-        || totalSize >= ((UInt64)1 << 63)\r
-        || pos < totalSize + XZ_STREAM_HEADER_SIZE)\r
-      return SZ_ERROR_ARCHIVE;\r
-    pos -= (totalSize + XZ_STREAM_HEADER_SIZE);\r
-    RINOK(LookInStream_SeekTo(stream, pos));\r
-    *startOffset = pos;\r
-  }\r
-  {\r
-    CXzStreamFlags headerFlags;\r
-    CSecToRead secToRead;\r
-    SecToRead_CreateVTable(&secToRead);\r
-    secToRead.realStream = stream;\r
-\r
-    RINOK(Xz_ReadHeader(&headerFlags, &secToRead.s));\r
-    return (p->flags == headerFlags) ? SZ_OK : SZ_ERROR_ARCHIVE;\r
-  }\r
-}\r
-\r
-\r
-/* ---------- Xz Streams ---------- */\r
-\r
-void Xzs_Construct(CXzs *p)\r
-{\r
-  p->num = p->numAllocated = 0;\r
-  p->streams = 0;\r
-}\r
-\r
-void Xzs_Free(CXzs *p, ISzAlloc *alloc)\r
-{\r
-  size_t i;\r
-  for (i = 0; i < p->num; i++)\r
-    Xz_Free(&p->streams[i], alloc);\r
-  alloc->Free(alloc, p->streams);\r
-  p->num = p->numAllocated = 0;\r
-  p->streams = 0;\r
-}\r
-\r
-UInt64 Xzs_GetNumBlocks(const CXzs *p)\r
-{\r
-  UInt64 num = 0;\r
-  size_t i;\r
-  for (i = 0; i < p->num; i++)\r
-    num += p->streams[i].numBlocks;\r
-  return num;\r
-}\r
-\r
-UInt64 Xzs_GetUnpackSize(const CXzs *p)\r
-{\r
-  UInt64 size = 0;\r
-  size_t i;\r
-  for (i = 0; i < p->num; i++)\r
-    ADD_SIZE_CHECH(size, Xz_GetUnpackSize(&p->streams[i]));\r
-  return size;\r
-}\r
-\r
-/*\r
-UInt64 Xzs_GetPackSize(const CXzs *p)\r
-{\r
-  UInt64 size = 0;\r
-  size_t i;\r
-  for (i = 0; i < p->num; i++)\r
-    ADD_SIZE_CHECH(size, Xz_GetTotalSize(&p->streams[i]));\r
-  return size;\r
-}\r
-*/\r
-\r
-SRes Xzs_ReadBackward(CXzs *p, ILookInStream *stream, Int64 *startOffset, ICompressProgress *progress, ISzAlloc *alloc)\r
-{\r
-  Int64 endOffset = 0;\r
-  RINOK(stream->Seek(stream, &endOffset, SZ_SEEK_END));\r
-  *startOffset = endOffset;\r
-  for (;;)\r
-  {\r
-    CXzStream st;\r
-    SRes res;\r
-    Xz_Construct(&st);\r
-    res = Xz_ReadBackward(&st, stream, startOffset, alloc);\r
-    st.startOffset = *startOffset;\r
-    RINOK(res);\r
-    if (p->num == p->numAllocated)\r
-    {\r
-      size_t newNum = p->num + p->num / 4 + 1;\r
-      Byte *data = (Byte *)alloc->Alloc(alloc, newNum * sizeof(CXzStream));\r
-      if (data == 0)\r
-        return SZ_ERROR_MEM;\r
-      p->numAllocated = newNum;\r
-      if (p->num != 0)\r
-        memcpy(data, p->streams, p->num * sizeof(CXzStream));\r
-      alloc->Free(alloc, p->streams);\r
-      p->streams = (CXzStream *)data;\r
-    }\r
-    p->streams[p->num++] = st;\r
-    if (*startOffset == 0)\r
-      break;\r
-    RINOK(LookInStream_SeekTo(stream, *startOffset));\r
-    if (progress && progress->Progress(progress, endOffset - *startOffset, (UInt64)(Int64)-1) != SZ_OK)\r
-      return SZ_ERROR_PROGRESS;\r
-  }\r
-  return SZ_OK;\r
-}\r
diff --git a/deps/lzma-16.04/DOC/7zC.txt b/deps/lzma-16.04/DOC/7zC.txt
deleted file mode 100644 (file)
index 4927678..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-7z ANSI-C Decoder 9.35\r
-----------------------\r
-\r
-7z ANSI-C provides 7z/LZMA decoding.\r
-7z ANSI-C version is simplified version ported from C++ code.\r
-\r
-LZMA is default and general compression method of 7z format\r
-in 7-Zip compression program (www.7-zip.org). LZMA provides high \r
-compression ratio and very fast decompression.\r
-\r
-\r
-LICENSE\r
--------\r
-\r
-7z ANSI-C Decoder is part of the LZMA SDK.\r
-LZMA SDK is written and placed in the public domain by Igor Pavlov.\r
-\r
-Files\r
----------------------\r
-\r
-7zDecode.*   - Low level 7z decoding\r
-7zExtract.*  - High level 7z decoding\r
-7zHeader.*   - .7z format constants\r
-7zIn.*       - .7z archive opening\r
-7zItem.*     - .7z structures\r
-7zMain.c     - Test application\r
-\r
-\r
-How To Use\r
-----------\r
-\r
-You can create .7z archive with 7z.exe, 7za.exe or 7zr.exe:\r
-\r
-  7z.exe a archive.7z *.htm -r -mx -m0fb=255\r
-\r
-If you have big number of files in archive, and you need fast extracting, \r
-you can use partly-solid archives:\r
-  \r
-  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\r
-\r
-In that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r
-512KB for extracting one file from such archive.\r
-\r
-\r
-Limitations of current version of 7z ANSI-C Decoder\r
----------------------------------------------------\r
-\r
- - It reads only "FileName", "Size", "LastWriteTime" and "CRC" information for each file in archive.\r
- - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.\r
- - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r
\r
-These limitations will be fixed in future versions.\r
-\r
-\r
-Using 7z ANSI-C Decoder Test application:\r
------------------------------------------\r
-\r
-Usage: 7zDec <command> <archive_name>\r
-\r
-<Command>:\r
-  e: Extract files from archive\r
-  l: List contents of archive\r
-  t: Test integrity of archive\r
-\r
-Example: \r
-\r
-  7zDec l archive.7z\r
-\r
-lists contents of archive.7z\r
-\r
-  7zDec e archive.7z\r
-\r
-extracts files from archive.7z to current folder.\r
-\r
-\r
-How to use .7z Decoder\r
-----------------------\r
-\r
-Memory allocation\r
-~~~~~~~~~~~~~~~~~\r
-\r
-7z Decoder uses two memory pools:\r
-1) Temporary pool\r
-2) Main pool\r
-Such scheme can allow you to avoid fragmentation of allocated blocks.\r
-\r
-\r
-Steps for using 7z decoder\r
---------------------------\r
-\r
-Use code at 7zMain.c as example.\r
-\r
-1) Declare variables:\r
-  inStream                 /* implements ILookInStream interface */\r
-  CSzArEx db;              /* 7z archive database structure */\r
-  ISzAlloc allocImp;       /* memory functions for main pool */\r
-  ISzAlloc allocTempImp;   /* memory functions for temporary pool */\r
-\r
-2) call CrcGenerateTable(); function to initialize CRC structures.\r
-\r
-3) call SzArEx_Init(&db); function to initialize db structures.\r
-\r
-4) call SzArEx_Open(&db, inStream, &allocMain, &allocTemp) to open archive\r
-\r
-This function opens archive "inStream" and reads headers to "db".\r
-All items in "db" will be allocated with "allocMain" functions.\r
-SzArEx_Open function allocates and frees temporary structures by "allocTemp" functions.\r
-\r
-5) List items or Extract items\r
-\r
-  Listing code:\r
-  ~~~~~~~~~~~~~\r
-\r
-    Use SzArEx_GetFileNameUtf16 function. Look example code in C\Util\7z\7zMain.c file. \r
-    \r
-\r
-  Extracting code:\r
-  ~~~~~~~~~~~~~~~~\r
-\r
-  SZ_RESULT SzAr_Extract(\r
-    CArchiveDatabaseEx *db,\r
-    ILookInStream *inStream, \r
-    UInt32 fileIndex,         /* index of file */\r
-    UInt32 *blockIndex,       /* index of solid block */\r
-    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r
-    size_t *outBufferSize,    /* buffer size for output buffer */\r
-    size_t *offset,           /* offset of stream for required file in *outBuffer */\r
-    size_t *outSizeProcessed, /* size of file in *outBuffer */\r
-    ISzAlloc *allocMain,\r
-    ISzAlloc *allocTemp);\r
-\r
-  If you need to decompress more than one file, you can send these values from previous call:\r
-    blockIndex, \r
-    outBuffer, \r
-    outBufferSize,\r
-  You can consider "outBuffer" as cache of solid block. If your archive is solid, \r
-  it will increase decompression speed.\r
-\r
-  After decompressing you must free "outBuffer":\r
-  allocImp.Free(outBuffer);\r
-\r
-6) call SzArEx_Free(&db, allocImp.Free) to free allocated items in "db".\r
-\r
-\r
-\r
-\r
-Memory requirements for .7z decoding \r
-------------------------------------\r
-\r
-Memory usage for Archive opening:\r
-  - Temporary pool:\r
-     - Memory for uncompressed .7z headers\r
-     - some other temporary blocks\r
-  - Main pool:\r
-     - Memory for database: \r
-       Estimated size of one file structures in solid archive:\r
-         - Size (4 or 8 Bytes)\r
-         - CRC32 (4 bytes)\r
-         - LastWriteTime (8 bytes)\r
-         - Some file information (4 bytes)\r
-         - File Name (variable length) + pointer + allocation structures\r
-\r
-Memory usage for archive Decompressing:\r
-  - Temporary pool:\r
-     - Memory for LZMA decompressing structures\r
-  - Main pool:\r
-     - Memory for decompressed solid block\r
-     - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these \r
-       temprorary buffers can be about 15% of solid block size. \r
-  \r
-\r
-7z Decoder doesn't allocate memory for compressed blocks. \r
-Instead of this, you must allocate buffer with desired \r
-size before calling 7z Decoder. Use 7zMain.c as example.\r
-\r
-\r
-Defines\r
--------\r
-\r
-_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r
-\r
-\r
----\r
-\r
-http://www.7-zip.org\r
-http://www.7-zip.org/sdk.html\r
-http://www.7-zip.org/support.html\r
diff --git a/deps/lzma-16.04/DOC/7zFormat.txt b/deps/lzma-16.04/DOC/7zFormat.txt
deleted file mode 100644 (file)
index 6b8678f..0000000
+++ /dev/null
@@ -1,469 +0,0 @@
-7z Format description (4.59)\r
-----------------------------\r
-\r
-This file contains description of 7z archive format. \r
-7z archive can contain files compressed with any method.\r
-See "Methods.txt" for description for defined compressing methods.\r
-\r
-\r
-Format structure Overview\r
--------------------------\r
-\r
-Some fields can be optional.\r
-\r
-Archive structure\r
-~~~~~~~~~~~~~~~~~  \r
-SignatureHeader\r
-[PackedStreams]\r
-[PackedStreamsForHeaders]\r
-[\r
-  Header \r
-  or \r
-  {\r
-    Packed Header\r
-    HeaderInfo\r
-  }\r
-]\r
-\r
-\r
-\r
-Header structure\r
-~~~~~~~~~~~~~~~~  \r
-{\r
-  ArchiveProperties\r
-  AdditionalStreams\r
-  {\r
-    PackInfo\r
-    {\r
-      PackPos\r
-      NumPackStreams\r
-      Sizes[NumPackStreams]\r
-      CRCs[NumPackStreams]\r
-    }\r
-    CodersInfo\r
-    {\r
-      NumFolders\r
-      Folders[NumFolders]\r
-      {\r
-        NumCoders\r
-        CodersInfo[NumCoders]\r
-        {\r
-          ID\r
-          NumInStreams;\r
-          NumOutStreams;\r
-          PropertiesSize\r
-          Properties[PropertiesSize]\r
-        }\r
-        NumBindPairs\r
-        BindPairsInfo[NumBindPairs]\r
-        {\r
-          InIndex;\r
-          OutIndex;\r
-        }\r
-        PackedIndices\r
-      }\r
-      UnPackSize[Folders][Folders.NumOutstreams]\r
-      CRCs[NumFolders]\r
-    }\r
-    SubStreamsInfo\r
-    {\r
-      NumUnPackStreamsInFolders[NumFolders];\r
-      UnPackSizes[]\r
-      CRCs[]\r
-    }\r
-  }\r
-  MainStreamsInfo\r
-  {\r
-    (Same as in AdditionalStreams)\r
-  }\r
-  FilesInfo\r
-  {\r
-    NumFiles\r
-    Properties[]\r
-    {\r
-      ID\r
-      Size\r
-      Data\r
-    }\r
-  }\r
-}\r
-\r
-HeaderInfo structure\r
-~~~~~~~~~~~~~~~~~~~~\r
-{\r
-  (Same as in AdditionalStreams)\r
-}\r
-\r
-\r
-\r
-Notes about Notation and encoding\r
----------------------------------\r
-\r
-7z uses little endian encoding.\r
-\r
-7z archive format has optional headers that are marked as\r
-[]\r
-Header\r
-[]\r
-\r
-REAL_UINT64 means real UINT64.\r
-\r
-UINT64 means real UINT64 encoded with the following scheme:\r
-\r
-  Size of encoding sequence depends from first byte:\r
-  First_Byte  Extra_Bytes        Value\r
-  (binary)   \r
-  0xxxxxxx               : ( xxxxxxx           )\r
-  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r
-  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r
-  ...\r
-  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r
-  11111110    BYTE y[7]  :                         y\r
-  11111111    BYTE y[8]  :                         y\r
-\r
-\r
-\r
-Property IDs\r
-------------\r
-\r
-0x00 = kEnd\r
-\r
-0x01 = kHeader\r
-\r
-0x02 = kArchiveProperties\r
-    \r
-0x03 = kAdditionalStreamsInfo\r
-0x04 = kMainStreamsInfo\r
-0x05 = kFilesInfo\r
-    \r
-0x06 = kPackInfo\r
-0x07 = kUnPackInfo\r
-0x08 = kSubStreamsInfo\r
-\r
-0x09 = kSize\r
-0x0A = kCRC\r
-\r
-0x0B = kFolder\r
-\r
-0x0C = kCodersUnPackSize\r
-0x0D = kNumUnPackStream\r
-\r
-0x0E = kEmptyStream\r
-0x0F = kEmptyFile\r
-0x10 = kAnti\r
-\r
-0x11 = kName\r
-0x12 = kCTime\r
-0x13 = kATime\r
-0x14 = kMTime\r
-0x15 = kWinAttributes\r
-0x16 = kComment\r
-\r
-0x17 = kEncodedHeader\r
-\r
-0x18 = kStartPos\r
-0x19 = kDummy\r
-\r
-\r
-7z format headers\r
------------------\r
-\r
-SignatureHeader\r
-~~~~~~~~~~~~~~~\r
-  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r
-\r
-  ArchiveVersion\r
-  {\r
-    BYTE Major;   // now = 0\r
-    BYTE Minor;   // now = 2\r
-  };\r
-\r
-  UINT32 StartHeaderCRC;\r
-\r
-  StartHeader\r
-  {\r
-    REAL_UINT64 NextHeaderOffset\r
-    REAL_UINT64 NextHeaderSize\r
-    UINT32 NextHeaderCRC\r
-  }\r
-\r
-\r
-...........................\r
-\r
-\r
-ArchiveProperties\r
-~~~~~~~~~~~~~~~~~\r
-BYTE NID::kArchiveProperties (0x02)\r
-for (;;)\r
-{\r
-  BYTE PropertyType;\r
-  if (aType == 0)\r
-    break;\r
-  UINT64 PropertySize;\r
-  BYTE PropertyData[PropertySize];\r
-}\r
-\r
-\r
-Digests (NumStreams)\r
-~~~~~~~~~~~~~~~~~~~~~\r
-  BYTE AllAreDefined\r
-  if (AllAreDefined == 0)\r
-  {\r
-    for(NumStreams)\r
-      BIT Defined\r
-  }\r
-  UINT32 CRCs[NumDefined]\r
-\r
-\r
-PackInfo\r
-~~~~~~~~~~~~\r
-  BYTE NID::kPackInfo  (0x06)\r
-  UINT64 PackPos\r
-  UINT64 NumPackStreams\r
-\r
-  []\r
-  BYTE NID::kSize    (0x09)\r
-  UINT64 PackSizes[NumPackStreams]\r
-  []\r
-\r
-  []\r
-  BYTE NID::kCRC      (0x0A)\r
-  PackStreamDigests[NumPackStreams]\r
-  []\r
-\r
-  BYTE NID::kEnd\r
-\r
-\r
-Folder\r
-~~~~~~\r
-  UINT64 NumCoders;\r
-  for (NumCoders)\r
-  {\r
-    BYTE \r
-    {\r
-      0:3 CodecIdSize\r
-      4:  Is Complex Coder\r
-      5:  There Are Attributes\r
-      6:  Reserved\r
-      7:  There are more alternative methods. (Not used anymore, must be 0).\r
-    } \r
-    BYTE CodecId[CodecIdSize]\r
-    if (Is Complex Coder)\r
-    {\r
-      UINT64 NumInStreams;\r
-      UINT64 NumOutStreams;\r
-    }\r
-    if (There Are Attributes)\r
-    {\r
-      UINT64 PropertiesSize\r
-      BYTE Properties[PropertiesSize]\r
-    }\r
-  }\r
-    \r
-  NumBindPairs = NumOutStreamsTotal - 1;\r
-\r
-  for (NumBindPairs)\r
-  {\r
-    UINT64 InIndex;\r
-    UINT64 OutIndex;\r
-  }\r
-\r
-  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r
-  if (NumPackedStreams > 1)\r
-    for(NumPackedStreams)\r
-    {\r
-      UINT64 Index;\r
-    };\r
-\r
-\r
-\r
-\r
-Coders Info\r
-~~~~~~~~~~~\r
-\r
-  BYTE NID::kUnPackInfo  (0x07)\r
-\r
-\r
-  BYTE NID::kFolder  (0x0B)\r
-  UINT64 NumFolders\r
-  BYTE External\r
-  switch(External)\r
-  {\r
-    case 0:\r
-      Folders[NumFolders]\r
-    case 1:\r
-      UINT64 DataStreamIndex\r
-  }\r
-\r
-\r
-  BYTE ID::kCodersUnPackSize  (0x0C)\r
-  for(Folders)\r
-    for(Folder.NumOutStreams)\r
-     UINT64 UnPackSize;\r
-\r
-\r
-  []\r
-  BYTE NID::kCRC   (0x0A)\r
-  UnPackDigests[NumFolders]\r
-  []\r
-\r
-  \r
-\r
-  BYTE NID::kEnd\r
-\r
-\r
-\r
-SubStreams Info\r
-~~~~~~~~~~~~~~\r
-  BYTE NID::kSubStreamsInfo; (0x08)\r
-\r
-  []\r
-  BYTE NID::kNumUnPackStream; (0x0D)\r
-  UINT64 NumUnPackStreamsInFolders[NumFolders];\r
-  []\r
-\r
-\r
-  []\r
-  BYTE NID::kSize  (0x09)\r
-  UINT64 UnPackSizes[]\r
-  []\r
-\r
-\r
-  []\r
-  BYTE NID::kCRC  (0x0A)\r
-  Digests[Number of streams with unknown CRC]\r
-  []\r
-\r
-  \r
-  BYTE NID::kEnd\r
-\r
-\r
-Streams Info\r
-~~~~~~~~~~~~\r
-\r
-  []\r
-  PackInfo\r
-  []\r
-\r
-\r
-  []\r
-  CodersInfo\r
-  []\r
-\r
-\r
-  []\r
-  SubStreamsInfo\r
-  []\r
-\r
-  BYTE NID::kEnd\r
-\r
-\r
-FilesInfo\r
-~~~~~~~~~\r
-  BYTE NID::kFilesInfo;  (0x05)\r
-  UINT64 NumFiles\r
-\r
-  for (;;)\r
-  {\r
-    BYTE PropertyType;\r
-    if (aType == 0)\r
-      break;\r
-\r
-    UINT64 Size;\r
-\r
-    switch(PropertyType)\r
-    {\r
-      kEmptyStream:   (0x0E)\r
-        for(NumFiles)\r
-          BIT IsEmptyStream\r
-\r
-      kEmptyFile:     (0x0F)\r
-        for(EmptyStreams)\r
-          BIT IsEmptyFile\r
-\r
-      kAnti:          (0x10)\r
-        for(EmptyStreams)\r
-          BIT IsAntiFile\r
-      \r
-      case kCTime: (0x12)\r
-      case kATime: (0x13)\r
-      case kMTime: (0x14)\r
-        BYTE AllAreDefined\r
-        if (AllAreDefined == 0)\r
-        {\r
-          for(NumFiles)\r
-            BIT TimeDefined\r
-        }\r
-        BYTE External;\r
-        if(External != 0)\r
-          UINT64 DataIndex\r
-        []\r
-        for(Definded Items)\r
-          UINT64 Time\r
-        []\r
-      \r
-      kNames:     (0x11)\r
-        BYTE External;\r
-        if(External != 0)\r
-          UINT64 DataIndex\r
-        []\r
-        for(Files)\r
-        {\r
-          wchar_t Names[NameSize];\r
-          wchar_t 0;\r
-        }\r
-        []\r
-\r
-      kAttributes:  (0x15)\r
-        BYTE AllAreDefined\r
-        if (AllAreDefined == 0)\r
-        {\r
-          for(NumFiles)\r
-            BIT AttributesAreDefined\r
-        }\r
-        BYTE External;\r
-        if(External != 0)\r
-          UINT64 DataIndex\r
-        []\r
-        for(Definded Attributes)\r
-          UINT32 Attributes\r
-        []\r
-    }\r
-  }\r
-\r
-\r
-Header\r
-~~~~~~\r
-  BYTE NID::kHeader (0x01)\r
-\r
-  []\r
-  ArchiveProperties\r
-  []\r
-\r
-  []\r
-  BYTE NID::kAdditionalStreamsInfo; (0x03)\r
-  StreamsInfo\r
-  []\r
-\r
-  []\r
-  BYTE NID::kMainStreamsInfo;    (0x04)\r
-  StreamsInfo\r
-  []\r
-\r
-  []\r
-  FilesInfo\r
-  []\r
-\r
-  BYTE NID::kEnd\r
-\r
-\r
-HeaderInfo\r
-~~~~~~~~~~\r
-  []\r
-  BYTE NID::kEncodedHeader; (0x17)\r
-  StreamsInfo for Encoded Header\r
-  []\r
-\r
-\r
----\r
-End of document\r
diff --git a/deps/lzma-16.04/DOC/Methods.txt b/deps/lzma-16.04/DOC/Methods.txt
deleted file mode 100644 (file)
index 3ca9057..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-7-Zip method IDs for 7z and xz archives\r
----------------------------------------\r
-\r
-Version: 16.03\r
-Date: 2016-09-27\r
-\r
-Each compression or crypto method in 7z is associated with unique binary value (ID).\r
-The length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).\r
-\r
-xz and 7z formats use same ID map.\r
-\r
-If you want to add some new ID, you have two ways:\r
-  1) Write request for allocating IDs to 7-Zip developers.\r
-  2) Generate 8-bytes ID:\r
-\r
-    3F ZZ ZZ ZZ ZZ ZZ MM MM \r
-\r
-    3F              - Prefix for random IDs (1 byte)\r
-    ZZ ZZ ZZ ZZ ZZ  - Developer ID (5 bytes). Use real random bytes. \r
-                      \r
-    MM MM           - Method ID (2 bytes)\r
-\r
-    You can notify 7-Zip developers about your Developer ID / Method ID.\r
-\r
-    Note: Use new ID, if old codec can not decode data encoded with new version.\r
-\r
-\r
-List of defined IDs\r
--------------------\r
-      \r
-00 - Copy\r
-\r
-03 - Delta\r
-04 - BCJ (x86)\r
-05 - PPC (big-endian)\r
-06 - IA64\r
-07 - ARM (little-endian)\r
-08 - ARMT (little-endian)\r
-09 - SPARC\r
-\r
-21 - LZMA2\r
-          \r
-02.. - Common\r
-   03 [Swap]\r
-      - 2 Swap2\r
-      - 4 Swap4\r
-\r
-03.. - 7z\r
-   01 - \r
-      01 - LZMA\r
-  \r
-   03 - [Branch Codecs]\r
-      01 - [x86 Codecs]\r
-         03  - BCJ\r
-         1B  - BCJ2 (4 packed streams)\r
-      02 - \r
-         05 - PPC (big-endian)\r
-      03 - \r
-         01 - Alpha\r
-      04 - \r
-         01 - IA64\r
-      05 - \r
-         01 - ARM (little-endian)\r
-      06 - \r
-         05 - M68 (big-endian)\r
-      07 - \r
-         01 - ARMT (little-endian)\r
-      08 - \r
-         05 - SPARC\r
-\r
-   04 - \r
-      01 - PPMD\r
-\r
-   7F -\r
-      01 - experimental method.\r
-\r
-\r
-04.. - Misc codecs\r
-\r
-   00 - Reserved\r
-\r
-   01 - [Zip]\r
-      00 - Copy (not used. Use {00} instead)\r
-      01 - Shrink\r
-      06 - Implode\r
-      08 - Deflate\r
-      09 - Deflate64\r
-      0A - Imploding\r
-      0C - BZip2 (not used. Use {040202} instead)\r
-      0E - LZMA (LZMA-zip)\r
-      5F - xz\r
-      60 - Jpeg\r
-      61 - WavPack\r
-      62 - PPMd (PPMd-zip)\r
-      63 - wzAES\r
-\r
-   02 - \r
-      02 - BZip2\r
-\r
-   03 - [Rar]\r
-      01 - Rar1\r
-      02 - Rar2\r
-      03 - Rar3\r
-      05 - Rar5\r
-\r
-   04 - [Arj]\r
-      01 - Arj(1,2,3)\r
-      02 - Arj4\r
-\r
-   05 - [Z]\r
-\r
-   06 - [Lzh]\r
-\r
-   07 - Reserved for 7z\r
-\r
-   08 - [Cab]\r
-\r
-   09 - [NSIS]\r
-      01 - DeflateNSIS\r
-      02 - BZip2NSIS\r
-\r
-   F7 - External codecs (that are not included to 7-Zip)\r
-\r
-      0x xx - reserved\r
-      10 xx - reserved (LZHAM)\r
-      11 xx - reserved (Zstd)\r
-\r
-\r
-06.. - Crypto \r
-\r
-   F0 - Ciphers without hashing algo\r
-\r
-      01 - [AES]\r
-         0x - AES-128\r
-         4x - AES-192\r
-         8x - AES-256\r
-         Cx - AES\r
-\r
-         x0 - ECB\r
-         x1 - CBC\r
-         x2 - CFB\r
-         x3 - OFB\r
-         x4 - CTR\r
-\r
-   F1 - Combine Ciphers\r
-\r
-      01 - [Zip]\r
-         01 - ZipCrypto (Main Zip crypto algo)\r
-\r
-      03 - [RAR]\r
-         02 - \r
-         03 - Rar29AES (AES-128 + modified SHA-1)\r
-\r
-      07 - [7z]\r
-         01 - 7zAES (AES-256 + SHA-256)\r
-\r
-\r
----\r
-End of document\r
diff --git a/deps/lzma-16.04/DOC/installer.txt b/deps/lzma-16.04/DOC/installer.txt
deleted file mode 100644 (file)
index 70ad7dc..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-7-Zip for installers 9.38\r
--------------------------\r
-\r
-7-Zip is a file archiver for Windows NT/2000/2003/2008/XP/Vista/7/8/10. \r
-\r
-7-Zip for installers is part of LZMA SDK.\r
-LZMA SDK is written and placed in the public domain by Igor Pavlov.\r
-\r
-It's allowed to join 7-Zip SFX module with another software.\r
-It's allowed to change resources of 7-Zip's SFX modules.\r
-\r
-\r
-HOW to use\r
------------\r
-\r
-7zr.exe is reduced version of 7za.exe of 7-Zip.\r
-7zr.exe supports only format with these codecs: LZMA, LZMA2, BCJ, BCJ2, ARM, Copy.\r
-\r
-Example of compressing command for installation packages:\r
-\r
-7zr a archive.7z files\r
-\r
-7zSD.sfx is SFX module for installers. 7zSD.sfx uses msvcrt.dll.\r
-\r
-SFX modules for installers allow to create installation program. \r
-Such module extracts archive to temp folder and then runs specified program and removes \r
-temp files after program finishing. Self-extract archive for installers must be created \r
-as joining 3 files: SFX_Module, Installer_Config, 7z_Archive. \r
-Installer_Config is optional file. You can use the following command to create installer \r
-self-extract archive:\r
-\r
-copy /b 7zSD.sfx + config.txt + archive.7z archive.exe\r
-\r
-The smallest installation package size can be achieved, if installation files was \r
-uncompressed before including to 7z archive.\r
-\r
--y switch for installer module (at runtime) specifies quiet mode for extracting.\r
-\r
-Installer Config file format\r
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
-Config file contains commands for Installer. File begins from string \r
-;!@Install@!UTF-8! and ends with ;!@InstallEnd@!. File must be written \r
-in UTF-8 encoding. File contains string pairs: \r
-\r
-ID_String="Value"\r
-\r
-ID_String          Description \r
-\r
-Title              Title for messages \r
-BeginPrompt        Begin Prompt message \r
-Progress           Value can be "yes" or "no". Default value is "yes". \r
-RunProgram         Command for executing. Default value is "setup.exe". \r
-                   Substring %%T will be replaced with path to temporary \r
-                   folder, where files were extracted \r
-Directory          Directory prefix for "RunProgram". Default value is ".\\" \r
-ExecuteFile        Name of file for executing \r
-ExecuteParameters  Parameters for "ExecuteFile" \r
-\r
-\r
-You can omit any string pair.\r
-\r
-There are two ways to run program: RunProgram and ExecuteFile. \r
-Use RunProgram, if you want to run some program from .7z archive. \r
-Use ExecuteFile, if you want to open some document from .7z archive or \r
-if you want to execute some command from Windows.\r
-\r
-If you use RunProgram and if you specify empty directory prefix: Directory="", \r
-the system searches for the executable file in the following sequence:\r
-\r
-1. The directory from which the application (installer) loaded. \r
-2. The temporary folder, where files were extracted. \r
-3. The Windows system directory. \r
-\r
-\r
-Config file Examples\r
-~~~~~~~~~~~~~~~~~~~~\r
-\r
-;!@Install@!UTF-8!\r
-Title="7-Zip 4.00"\r
-BeginPrompt="Do you want to install the 7-Zip 4.00?"\r
-RunProgram="setup.exe"\r
-;!@InstallEnd@!\r
-\r
-\r
-\r
-;!@Install@!UTF-8!\r
-Title="7-Zip 4.00"\r
-BeginPrompt="Do you want to install the 7-Zip 4.00?"\r
-ExecuteFile="7zip.msi"\r
-;!@InstallEnd@!\r
-\r
-\r
-\r
-;!@Install@!UTF-8!\r
-Title="7-Zip 4.01 Update"\r
-BeginPrompt="Do you want to install the 7-Zip 4.01 Update?"\r
-ExecuteFile="msiexec.exe"\r
-ExecuteParameters="/i 7zip.msi REINSTALL=ALL REINSTALLMODE=vomus"\r
-;!@InstallEnd@!\r
-\r
-\r
-\r
-Small SFX modules for installers\r
---------------------------------\r
-\r
-7zS2.sfx     - small SFX module (GUI version)\r
-7zS2con.sfx  - small SFX module (Console version)\r
-\r
-Small SFX modules support this codecs: LZMA, LZMA2, BCJ, BCJ2, ARM, COPY\r
-\r
-Small SFX module is similar to common SFX module for installers.\r
-The difference (what's new in small version):\r
- - Smaller size (30 KB vs 100 KB)\r
- - C source code instead of Ã‘++\r
- - No installer Configuration file\r
- - No extracting progress window\r
- - It decompresses solid 7z blocks (it can be whole 7z archive) to RAM.\r
-   So user that calls SFX installer must have free RAM of size of largest \r
-   solid 7z block (size of 7z archive at simplest case).\r
-\r
-How to use\r
-----------\r
-\r
-copy /b 7zS2.sfx + archive.7z sfx.exe\r
-\r
-When you run installer sfx module (sfx.exe)\r
-1) It creates "7zNNNNNNNN" temp folder in system temp folder.\r
-2) It extracts .7z archive to that folder\r
-3) It executes one file from "7zNNNNNNNN" temp folder. \r
-4) It removes "7zNNNNNNNN" temp folder\r
-\r
-You can send parameters to installer, and installer will transfer them to extracted .exe file.\r
-\r
-Small SFX uses 3 levels of priorities to select file to execute:\r
-\r
-  1) Files in root folder have higher priority than files in subfolders.\r
-  2) File extension priorities (from high to low priority order): \r
-       bat, cmd, exe, inf, msi, cab (under Windows CE), html, htm\r
-  3) File name priorities (from high to low priority order): \r
-       setup, install, run, start\r
-\r
-Windows CE (ARM) version of 7zS2.sfx is included to 7-Zip for Windows Mobile package.\r
-\r
-\r
-Examples\r
---------\r
-\r
-1) To create compressed console 7-Zip:\r
-\r
-7zr a c.7z 7z.exe 7z.dll -mx\r
-copy /b 7zS2con.sfx + c.7z 7zCompr.exe\r
-7zCompr.exe b -md22\r
-\r
-\r
-2) To create compressed GUI 7-Zip:\r
-\r
-7zr a g.7z 7zg.exe 7z.dll -mx\r
-copy /b 7zS2.sfx + g.7z 7zgCompr.exe\r
-7zgCompr.exe b -md22\r
-\r
-\r
-3) To open some file:\r
-\r
-7zr a h.7z readme.txt -mx\r
-copy /b 7zS2.sfx + h.7z 7zTxt.exe \r
-7zTxt.exe\r
diff --git a/deps/lzma-16.04/DOC/lzma-sdk.txt b/deps/lzma-16.04/DOC/lzma-sdk.txt
deleted file mode 100644 (file)
index 86fef24..0000000
+++ /dev/null
@@ -1,357 +0,0 @@
-LZMA SDK 16.04\r
---------------\r
-\r
-LZMA SDK provides the documentation, samples, header files,\r
-libraries, and tools you need to develop applications that \r
-use 7z / LZMA / LZMA2 / XZ compression.\r
-\r
-LZMA is an improved version of famous LZ77 compression algorithm. \r
-It was improved in way of maximum increasing of compression ratio,\r
-keeping high decompression speed and low memory requirements for \r
-decompressing.\r
-\r
-LZMA2 is a LZMA based compression method. LZMA2 provides better \r
-multithreading support for compression than LZMA and some other improvements.\r
-\r
-7z is a file format for data compression and file archiving.\r
-7z is a main file format for 7-Zip compression program (www.7-zip.org).\r
-7z format supports different compression methods: LZMA, LZMA2 and others.\r
-7z also supports AES-256 based encryption.\r
-\r
-XZ is a file format for data compression that uses LZMA2 compression.\r
-XZ format provides additional features: SHA/CRC check, filters for \r
-improved compression ratio, splitting to blocks and streams,\r
-\r
-\r
-\r
-LICENSE\r
--------\r
-\r
-LZMA SDK is written and placed in the public domain by Igor Pavlov.\r
-\r
-Some code in LZMA SDK is based on public domain code from another developers:\r
-  1) PPMd var.H (2001): Dmitry Shkarin\r
-  2) SHA-256: Wei Dai (Crypto++ library)\r
-\r
-Anyone is free to copy, modify, publish, use, compile, sell, or distribute the \r
-original LZMA SDK code, either in source code form or as a compiled binary, for \r
-any purpose, commercial or non-commercial, and by any means.\r
-\r
-LZMA SDK code is compatible with open source licenses, for example, you can \r
-include it to GNU GPL or GNU LGPL code.\r
-\r
-\r
-LZMA SDK Contents\r
------------------\r
-\r
-  Source code:\r
-\r
-    - C / C++ / C# / Java   - LZMA compression and decompression\r
-    - C / C++               - LZMA2 compression and decompression\r
-    - C / C++               - XZ compression and decompression\r
-    - C                     - 7z decompression\r
-    -     C++               - 7z compression and decompression\r
-    - C                     - small SFXs for installers (7z decompression)\r
-    -     C++               - SFXs and SFXs for installers (7z decompression)\r
-\r
-  Precomiled binaries:\r
-\r
-    - console programs for lzma / 7z / xz compression and decompression\r
-    - SFX modules for installers.\r
-\r
-\r
-UNIX/Linux version \r
-------------------\r
-To compile C++ version of file->file LZMA encoding, go to directory\r
-CPP/7zip/Bundles/LzmaCon\r
-and call make to recompile it:\r
-  make -f makefile.gcc clean all\r
-\r
-In some UNIX/Linux versions you must compile LZMA with static libraries.\r
-To compile with static libraries, you can use \r
-LIB = -lm -static\r
-\r
-Also you can use p7zip (port of 7-Zip for POSIX systems like Unix or Linux):\r
-  \r
-  http://p7zip.sourceforge.net/\r
-\r
-\r
-Files\r
------\r
-\r
-DOC/7zC.txt          - 7z ANSI-C Decoder description\r
-DOC/7zFormat.txt     - 7z Format description\r
-DOC/installer.txt    - information about 7-Zip for installers\r
-DOC/lzma.txt         - LZMA compression description\r
-DOC/lzma-sdk.txt     - LZMA SDK description (this file)\r
-DOC/lzma-history.txt - history of LZMA SDK\r
-DOC/lzma-specification.txt - Specification of LZMA\r
-DOC/Methods.txt      - Compression method IDs for .7z\r
-\r
-bin/installer/   - example script to create installer that uses SFX module,\r
-\r
-bin/7zdec.exe    - simplified 7z archive decoder\r
-bin/7zr.exe      - 7-Zip console program (reduced version)\r
-bin/x64/7zr.exe  - 7-Zip console program (reduced version) (x64 version)\r
-bin/lzma.exe     - file->file LZMA encoder/decoder for Windows\r
-bin/7zS2.sfx     - small SFX module for installers (GUI version)\r
-bin/7zS2con.sfx  - small SFX module for installers (Console version)\r
-bin/7zSD.sfx     - SFX module for installers.\r
-\r
-\r
-7zDec.exe\r
----------\r
-7zDec.exe is simplified 7z archive decoder.\r
-It supports only LZMA, LZMA2, and PPMd methods.\r
-7zDec decodes whole solid block from 7z archive to RAM.\r
-The RAM consumption can be high.\r
-\r
-\r
-\r
-\r
-Source code structure\r
----------------------\r
-\r
-\r
-Asm/ - asm files (optimized code for CRC calculation and Intel-AES encryption)\r
-\r
-C/  - C files (compression / decompression and other)\r
-  Util/\r
-    7z       - 7z decoder program (decoding 7z files)\r
-    Lzma     - LZMA program (file->file LZMA encoder/decoder).\r
-    LzmaLib  - LZMA library (.DLL for Windows)\r
-    SfxSetup - small SFX module for installers \r
-\r
-CPP/ -- CPP files\r
-\r
-  Common  - common files for C++ projects\r
-  Windows - common files for Windows related code\r
-\r
-  7zip    - files related to 7-Zip\r
-\r
-    Archive - files related to archiving\r
-\r
-      Common   - common files for archive handling\r
-      7z       - 7z C++ Encoder/Decoder\r
-\r
-    Bundles  - Modules that are bundles of other modules (files)\r
-  \r
-      Alone7z       - 7zr.exe: Standalone 7-Zip console program (reduced version)\r
-      Format7zExtractR  - 7zxr.dll: Reduced version of 7z DLL: extracting from 7z/LZMA/BCJ/BCJ2.\r
-      Format7zR         - 7zr.dll:  Reduced version of 7z DLL: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r
-      LzmaCon       - lzma.exe: LZMA compression/decompression\r
-      LzmaSpec      - example code for LZMA Specification\r
-      SFXCon        - 7zCon.sfx: Console 7z SFX module\r
-      SFXSetup      - 7zS.sfx: 7z SFX module for installers\r
-      SFXWin        - 7z.sfx: GUI 7z SFX module\r
-\r
-    Common   - common files for 7-Zip\r
-\r
-    Compress - files for compression/decompression\r
-\r
-    Crypto   - files for encryption / decompression\r
-\r
-    UI       - User Interface files\r
-         \r
-      Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll\r
-      Common   - Common UI files\r
-      Console  - Code for console program (7z.exe)\r
-      Explorer    - Some code from 7-Zip Shell extension\r
-      FileManager - Some GUI code from 7-Zip File Manager\r
-      GUI         - Some GUI code from 7-Zip\r
-\r
-\r
-CS/ - C# files\r
-  7zip\r
-    Common   - some common files for 7-Zip\r
-    Compress - files related to compression/decompression\r
-      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r
-      LZMA         - LZMA compression/decompression\r
-      LzmaAlone    - file->file LZMA compression/decompression\r
-      RangeCoder   - Range Coder (special code of compression/decompression)\r
-\r
-Java/  - Java files\r
-  SevenZip\r
-    Compression    - files related to compression/decompression\r
-      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r
-      LZMA         - LZMA compression/decompression\r
-      RangeCoder   - Range Coder (special code of compression/decompression)\r
-\r
-\r
-Note: \r
-  Asm / C / C++ source code of LZMA SDK is part of 7-Zip's source code.\r
-  7-Zip's source code can be downloaded from 7-Zip's SourceForge page:\r
-\r
-  http://sourceforge.net/projects/sevenzip/\r
-\r
-\r
-\r
-LZMA features\r
--------------\r
-  - Variable dictionary size (up to 1 GB)\r
-  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r
-  - Estimated decompressing speed: \r
-      - 20-30 MB/s on modern 2 GHz cpu\r
-      - 1-2 MB/s on 200 MHz simple RISC cpu: (ARM, MIPS, PowerPC)\r
-  - Small memory requirements for decompressing (16 KB + DictionarySize)\r
-  - Small code size for decompressing: 5-8 KB\r
-\r
-LZMA decoder uses only integer operations and can be \r
-implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r
-\r
-Some critical operations that affect the speed of LZMA decompression:\r
-  1) 32*16 bit integer multiply\r
-  2) Mispredicted branches (penalty mostly depends from pipeline length)\r
-  3) 32-bit shift and arithmetic operations\r
-\r
-The speed of LZMA decompressing mostly depends from CPU speed.\r
-Memory speed has no big meaning. But if your CPU has small data cache, \r
-overall weight of memory speed will slightly increase.\r
-\r
-\r
-How To Use\r
-----------\r
-\r
-Using LZMA encoder/decoder executable\r
---------------------------------------\r
-\r
-Usage:  LZMA <e|d> inputFile outputFile [<switches>...]\r
-\r
-  e: encode file\r
-\r
-  d: decode file\r
-\r
-  b: Benchmark. There are two tests: compressing and decompressing \r
-     with LZMA method. Benchmark shows rating in MIPS (million \r
-     instructions per second). Rating value is calculated from \r
-     measured speed and it is normalized with Intel's Core 2 results.\r
-     Also Benchmark checks possible hardware errors (RAM \r
-     errors in most cases). Benchmark uses these settings:\r
-     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r
-     Also you can change the number of iterations. Example for 30 iterations:\r
-       LZMA b 30\r
-     Default number of iterations is 10.\r
-\r
-<Switches>\r
-  \r
-\r
-  -a{N}:  set compression mode 0 = fast, 1 = normal\r
-          default: 1 (normal)\r
-\r
-  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r
-          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r
-          Dictionary size is calculated as DictionarySize = 2^N bytes. \r
-          For decompressing file compressed by LZMA method with dictionary \r
-          size D = 2^N you need about D bytes of memory (RAM).\r
-\r
-  -fb{N}: set number of fast bytes - [5, 273], default: 128\r
-          Usually big number gives a little bit better compression ratio \r
-          and slower compression process.\r
-\r
-  -lc{N}: set number of literal context bits - [0, 8], default: 3\r
-          Sometimes lc=4 gives gain for big files.\r
-\r
-  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r
-          lp switch is intended for periodical data when period is \r
-          equal 2^N. For example, for 32-bit (4 bytes) \r
-          periodical data you can use lp=2. Often it's better to set lc0, \r
-          if you change lp switch.\r
-\r
-  -pb{N}: set number of pos bits - [0, 4], default: 2\r
-          pb switch is intended for periodical data \r
-          when period is equal 2^N.\r
-\r
-  -mf{MF_ID}: set Match Finder. Default: bt4. \r
-              Algorithms from hc* group doesn't provide good compression \r
-              ratio, but they often works pretty fast in combination with \r
-              fast mode (-a0).\r
-\r
-              Memory requirements depend from dictionary size \r
-              (parameter "d" in table below). \r
-\r
-               MF_ID     Memory                   Description\r
-\r
-                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r
-                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r
-                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r
-                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r
-\r
-  -eos:   write End Of Stream marker. By default LZMA doesn't write \r
-          eos marker, since LZMA decoder knows uncompressed size \r
-          stored in .lzma file header.\r
-\r
-  -si:    Read data from stdin (it will write End Of Stream marker).\r
-  -so:    Write data to stdout\r
-\r
-\r
-Examples:\r
-\r
-1) LZMA e file.bin file.lzma -d16 -lc0 \r
-\r
-compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r
-and 0 literal context bits. -lc0 allows to reduce memory requirements \r
-for decompression.\r
-\r
-\r
-2) LZMA e file.bin file.lzma -lc0 -lp2\r
-\r
-compresses file.bin to file.lzma with settings suitable \r
-for 32-bit periodical data (for example, ARM or MIPS code).\r
-\r
-3) LZMA d file.lzma file.bin\r
-\r
-decompresses file.lzma to file.bin.\r
-\r
-\r
-Compression ratio hints\r
------------------------\r
-\r
-Recommendations\r
----------------\r
-\r
-To increase the compression ratio for LZMA compressing it's desirable \r
-to have aligned data (if it's possible) and also it's desirable to locate\r
-data in such order, where code is grouped in one place and data is \r
-grouped in other place (it's better than such mixing: code, data, code,\r
-data, ...).\r
-\r
-\r
-Filters\r
--------\r
-You can increase the compression ratio for some data types, using\r
-special filters before compressing. For example, it's possible to \r
-increase the compression ratio on 5-10% for code for those CPU ISAs: \r
-x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r
-\r
-You can find C source code of such filters in C/Bra*.* files\r
-\r
-You can check the compression ratio gain of these filters with such \r
-7-Zip commands (example for ARM code):\r
-No filter:\r
-  7z a a1.7z a.bin -m0=lzma\r
-\r
-With filter for little-endian ARM code:\r
-  7z a a2.7z a.bin -m0=arm -m1=lzma        \r
-\r
-It works in such manner:\r
-Compressing    = Filter_encoding + LZMA_encoding\r
-Decompressing  = LZMA_decoding + Filter_decoding\r
-\r
-Compressing and decompressing speed of such filters is very high,\r
-so it will not increase decompressing time too much.\r
-Moreover, it reduces decompression time for LZMA_decoding, \r
-since compression ratio with filtering is higher.\r
-\r
-These filters convert CALL (calling procedure) instructions \r
-from relative offsets to absolute addresses, so such data becomes more \r
-compressible.\r
-\r
-For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r
-\r
-\r
-\r
----\r
-\r
-http://www.7-zip.org\r
-http://www.7-zip.org/sdk.html\r
-http://www.7-zip.org/support.html\r
diff --git a/deps/lzma-16.04/DOC/lzma-specification.txt b/deps/lzma-16.04/DOC/lzma-specification.txt
deleted file mode 100644 (file)
index b6796df..0000000
+++ /dev/null
@@ -1,1176 +0,0 @@
-LZMA specification (DRAFT version)\r
-----------------------------------\r
-\r
-Author: Igor Pavlov\r
-Date: 2015-06-14\r
-\r
-This specification defines the format of LZMA compressed data and lzma file format.\r
-\r
-Notation \r
---------\r
-\r
-We use the syntax of C++ programming language.\r
-We use the following types in C++ code:\r
-  unsigned - unsigned integer, at least 16 bits in size\r
-  int      - signed integer, at least 16 bits in size\r
-  UInt64   - 64-bit unsigned integer\r
-  UInt32   - 32-bit unsigned integer\r
-  UInt16   - 16-bit unsigned integer\r
-  Byte     - 8-bit unsigned integer\r
-  bool     - boolean type with two possible values: false, true\r
-\r
-\r
-lzma file format\r
-================\r
-\r
-The lzma file contains the raw LZMA stream and the header with related properties.\r
-\r
-The files in that format use ".lzma" extension.\r
-\r
-The lzma file format layout:\r
-\r
-Offset Size Description\r
-\r
-  0     1   LZMA model properties (lc, lp, pb) in encoded form\r
-  1     4   Dictionary size (32-bit unsigned integer, little-endian)\r
-  5     8   Uncompressed size (64-bit unsigned integer, little-endian)\r
- 13         Compressed data (LZMA stream)\r
-\r
-LZMA properties:\r
-\r
-    name  Range          Description\r
-\r
-      lc  [0, 8]         the number of "literal context" bits\r
-      lp  [0, 4]         the number of "literal pos" bits\r
-      pb  [0, 4]         the number of "pos" bits\r
-dictSize  [0, 2^32 - 1]  the dictionary size \r
-\r
-The following code encodes LZMA properties:\r
-\r
-void EncodeProperties(Byte *properties)\r
-{\r
-  properties[0] = (Byte)((pb * 5 + lp) * 9 + lc);\r
-  Set_UInt32_LittleEndian(properties + 1, dictSize);\r
-}\r
-\r
-If the value of dictionary size in properties is smaller than (1 << 12),\r
-the LZMA decoder must set the dictionary size variable to (1 << 12).\r
-\r
-#define LZMA_DIC_MIN (1 << 12)\r
-\r
-  unsigned lc, pb, lp;\r
-  UInt32 dictSize;\r
-  UInt32 dictSizeInProperties;\r
-\r
-  void DecodeProperties(const Byte *properties)\r
-  {\r
-    unsigned d = properties[0];\r
-    if (d >= (9 * 5 * 5))\r
-      throw "Incorrect LZMA properties";\r
-    lc = d % 9;\r
-    d /= 9;\r
-    pb = d / 5;\r
-    lp = d % 5;\r
-    dictSizeInProperties = 0;\r
-    for (int i = 0; i < 4; i++)\r
-      dictSizeInProperties |= (UInt32)properties[i + 1] << (8 * i);\r
-    dictSize = dictSizeInProperties;\r
-    if (dictSize < LZMA_DIC_MIN)\r
-      dictSize = LZMA_DIC_MIN;\r
-  }\r
-\r
-If "Uncompressed size" field contains ones in all 64 bits, it means that\r
-uncompressed size is unknown and there is the "end marker" in stream,\r
-that indicates the end of decoding point.\r
-In opposite case, if the value from "Uncompressed size" field is not\r
-equal to ((2^64) - 1), the LZMA stream decoding must be finished after\r
-specified number of bytes (Uncompressed size) is decoded. And if there \r
-is the "end marker", the LZMA decoder must read that marker also.\r
-\r
-\r
-The new scheme to encode LZMA properties\r
-----------------------------------------\r
-\r
-If LZMA compression is used for some another format, it's recommended to\r
-use a new improved scheme to encode LZMA properties. That new scheme was\r
-used in xz format that uses the LZMA2 compression algorithm.\r
-The LZMA2 is a new compression algorithm that is based on the LZMA algorithm.\r
-\r
-The dictionary size in LZMA2 is encoded with just one byte and LZMA2 supports\r
-only reduced set of dictionary sizes:\r
-  (2 << 11), (3 << 11),\r
-  (2 << 12), (3 << 12),\r
-  ...\r
-  (2 << 30), (3 << 30),\r
-  (2 << 31) - 1\r
-\r
-The dictionary size can be extracted from encoded value with the following code:\r
-\r
-  dictSize = (p == 40) ? 0xFFFFFFFF : (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11));\r
-\r
-Also there is additional limitation (lc + lp <= 4) in LZMA2 for values of \r
-"lc" and "lp" properties:\r
-\r
-  if (lc + lp > 4)\r
-    throw "Unsupported properties: (lc + lp) > 4";\r
-\r
-There are some advantages for LZMA decoder with such (lc + lp) value\r
-limitation. It reduces the maximum size of tables allocated by decoder.\r
-And it reduces the complexity of initialization procedure, that can be \r
-important to keep high speed of decoding of big number of small LZMA streams.\r
-\r
-It's recommended to use that limitation (lc + lp <= 4) for any new format\r
-that uses LZMA compression. Note that the combinations of "lc" and "lp" \r
-parameters, where (lc + lp > 4), can provide significant improvement in \r
-compression ratio only in some rare cases.\r
-\r
-The LZMA properties can be encoded into two bytes in new scheme:\r
-\r
-Offset Size Description\r
-\r
-  0     1   The dictionary size encoded with LZMA2 scheme\r
-  1     1   LZMA model properties (lc, lp, pb) in encoded form\r
-\r
-\r
-The RAM usage \r
-=============\r
-\r
-The RAM usage for LZMA decoder is determined by the following parts:\r
-\r
-1) The Sliding Window (from 4 KiB to 4 GiB).\r
-2) The probability model counter arrays (arrays of 16-bit variables).\r
-3) Some additional state variables (about 10 variables of 32-bit integers).\r
-\r
-\r
-The RAM usage for Sliding Window\r
---------------------------------\r
-\r
-There are two main scenarios of decoding:\r
-\r
-1) The decoding of full stream to one RAM buffer.\r
-\r
-  If we decode full LZMA stream to one output buffer in RAM, the decoder \r
-  can use that output buffer as sliding window. So the decoder doesn't \r
-  need additional buffer allocated for sliding window.\r
-\r
-2) The decoding to some external storage.\r
-\r
-  If we decode LZMA stream to external storage, the decoder must allocate\r
-  the buffer for sliding window. The size of that buffer must be equal \r
-  or larger than the value of dictionary size from properties of LZMA stream.\r
-\r
-In this specification we describe the code for decoding to some external\r
-storage. The optimized version of code for decoding of full stream to one\r
-output RAM buffer can require some minor changes in code.\r
-\r
-\r
-The RAM usage for the probability model counters\r
-------------------------------------------------\r
-\r
-The size of the probability model counter arrays is calculated with the \r
-following formula:\r
-\r
-size_of_prob_arrays = 1846 + 768 * (1 << (lp + lc))\r
-\r
-Each probability model counter is 11-bit unsigned integer.\r
-If we use 16-bit integer variables (2-byte integers) for these probability \r
-model counters, the RAM usage required by probability model counter arrays \r
-can be estimated with the following formula:\r
-\r
-  RAM = 4 KiB + 1.5 KiB * (1 << (lp + lc))\r
-\r
-For example, for default LZMA parameters (lp = 0 and lc = 3), the RAM usage is\r
-\r
-  RAM_lc3_lp0 = 4 KiB + 1.5 KiB * 8 = 16 KiB\r
-\r
-The maximum RAM state usage is required for decoding the stream with lp = 4 \r
-and lc = 8:\r
-\r
-  RAM_lc8_lp4 = 4 KiB + 1.5 KiB * 4096 = 6148 KiB\r
-\r
-If the decoder uses LZMA2's limited property condition \r
-(lc + lp <= 4), the RAM usage will be not larger than\r
-\r
-  RAM_lc_lp_4 = 4 KiB + 1.5 KiB * 16 = 28 KiB\r
-\r
-\r
-The RAM usage for encoder\r
--------------------------\r
-\r
-There are many variants for LZMA encoding code.\r
-These variants have different values for memory consumption.\r
-Note that memory consumption for LZMA Encoder can not be \r
-smaller than memory consumption of LZMA Decoder for same stream.\r
-\r
-The RAM usage required by modern effective implementation of \r
-LZMA Encoder can be estimated with the following formula:\r
-\r
-  Encoder_RAM_Usage = 4 MiB + 11 * dictionarySize.\r
-\r
-But there are some modes of the encoder that require less memory.\r
-\r
-\r
-LZMA Decoding\r
-=============\r
-\r
-The LZMA compression algorithm uses LZ-based compression with Sliding Window\r
-and Range Encoding as entropy coding method.\r
-\r
-\r
-Sliding Window\r
---------------\r
-\r
-LZMA uses Sliding Window compression similar to LZ77 algorithm.\r
-\r
-LZMA stream must be decoded to the sequence that consists\r
-of MATCHES and LITERALS:\r
-  \r
-  - a LITERAL is a 8-bit character (one byte).\r
-    The decoder just puts that LITERAL to the uncompressed stream.\r
-  \r
-  - a MATCH is a pair of two numbers (DISTANCE-LENGTH pair).\r
-    The decoder takes one byte exactly "DISTANCE" characters behind\r
-    current position in the uncompressed stream and puts it to \r
-    uncompressed stream. The decoder must repeat it "LENGTH" times.\r
-\r
-The "DISTANCE" can not be larger than dictionary size.\r
-And the "DISTANCE" can not be larger than the number of bytes in\r
-the uncompressed stream that were decoded before that match.\r
-\r
-In this specification we use cyclic buffer to implement Sliding Window\r
-for LZMA decoder:\r
-\r
-class COutWindow\r
-{\r
-  Byte *Buf;\r
-  UInt32 Pos;\r
-  UInt32 Size;\r
-  bool IsFull;\r
-\r
-public:\r
-  unsigned TotalPos;\r
-  COutStream OutStream;\r
-\r
-  COutWindow(): Buf(NULL) {}\r
-  ~COutWindow() { delete []Buf; }\r
\r
-  void Create(UInt32 dictSize)\r
-  {\r
-    Buf = new Byte[dictSize];\r
-    Pos = 0;\r
-    Size = dictSize;\r
-    IsFull = false;\r
-    TotalPos = 0;\r
-  }\r
-\r
-  void PutByte(Byte b)\r
-  {\r
-    TotalPos++;\r
-    Buf[Pos++] = b;\r
-    if (Pos == Size)\r
-    {\r
-      Pos = 0;\r
-      IsFull = true;\r
-    }\r
-    OutStream.WriteByte(b);\r
-  }\r
-\r
-  Byte GetByte(UInt32 dist) const\r
-  {\r
-    return Buf[dist <= Pos ? Pos - dist : Size - dist + Pos];\r
-  }\r
-\r
-  void CopyMatch(UInt32 dist, unsigned len)\r
-  {\r
-    for (; len > 0; len--)\r
-      PutByte(GetByte(dist));\r
-  }\r
-\r
-  bool CheckDistance(UInt32 dist) const\r
-  {\r
-    return dist <= Pos || IsFull;\r
-  }\r
-\r
-  bool IsEmpty() const\r
-  {\r
-    return Pos == 0 && !IsFull;\r
-  }\r
-};\r
-\r
-\r
-In another implementation it's possible to use one buffer that contains \r
-Sliding Window and the whole data stream after uncompressing.\r
-\r
-\r
-Range Decoder\r
--------------\r
-\r
-LZMA algorithm uses Range Encoding (1) as entropy coding method.\r
-\r
-LZMA stream contains just one very big number in big-endian encoding.\r
-LZMA decoder uses the Range Decoder to extract a sequence of binary\r
-symbols from that big number.\r
-\r
-The state of the Range Decoder:\r
-\r
-struct CRangeDecoder\r
-{\r
-  UInt32 Range; \r
-  UInt32 Code;\r
-  InputStream *InStream;\r
-\r
-  bool Corrupted;\r
-}\r
-\r
-The notes about UInt32 type for the "Range" and "Code" variables:\r
-\r
-  It's possible to use 64-bit (unsigned or signed) integer type\r
-  for the "Range" and the "Code" variables instead of 32-bit unsigned,\r
-  but some additional code must be used to truncate the values to \r
-  low 32-bits after some operations.\r
-\r
-  If the programming language does not support 32-bit unsigned integer type \r
-  (like in case of JAVA language), it's possible to use 32-bit signed integer, \r
-  but some code must be changed. For example, it's required to change the code\r
-  that uses comparison operations for UInt32 variables in this specification.\r
-\r
-The Range Decoder can be in some states that can be treated as \r
-"Corruption" in LZMA stream. The Range Decoder uses the variable "Corrupted":\r
-\r
-  (Corrupted == false), if the Range Decoder has not detected any corruption.\r
-  (Corrupted == true), if the Range Decoder has detected some corruption.\r
-\r
-The reference LZMA Decoder ignores the value of the "Corrupted" variable.\r
-So it continues to decode the stream, even if the corruption can be detected\r
-in the Range Decoder. To provide the full compatibility with output of the \r
-reference LZMA Decoder, another LZMA Decoder implementations must also \r
-ignore the value of the "Corrupted" variable.\r
-\r
-The LZMA Encoder is required to create only such LZMA streams, that will not \r
-lead the Range Decoder to states, where the "Corrupted" variable is set to true.\r
-\r
-The Range Decoder reads first 5 bytes from input stream to initialize\r
-the state:\r
-\r
-bool CRangeDecoder::Init()\r
-{\r
-  Corrupted = false;\r
-  Range = 0xFFFFFFFF;\r
-  Code = 0;\r
-\r
-  Byte b = InStream->ReadByte();\r
-  \r
-  for (int i = 0; i < 4; i++)\r
-    Code = (Code << 8) | InStream->ReadByte();\r
-  \r
-  if (b != 0 || Code == Range)\r
-    Corrupted = true;\r
-  return b == 0;\r
-}\r
-\r
-The LZMA Encoder always writes ZERO in initial byte of compressed stream.\r
-That scheme allows to simplify the code of the Range Encoder in the \r
-LZMA Encoder. If initial byte is not equal to ZERO, the LZMA Decoder must\r
-stop decoding and report error.\r
-\r
-After the last bit of data was decoded by Range Decoder, the value of the\r
-"Code" variable must be equal to 0. The LZMA Decoder must check it by \r
-calling the IsFinishedOK() function:\r
-\r
-  bool IsFinishedOK() const { return Code == 0; }\r
-\r
-If there is corruption in data stream, there is big probability that\r
-the "Code" value will be not equal to 0 in the Finish() function. So that\r
-check in the IsFinishedOK() function provides very good feature for \r
-corruption detection.\r
-\r
-The value of the "Range" variable before each bit decoding can not be smaller \r
-than ((UInt32)1 << 24). The Normalize() function keeps the "Range" value in \r
-described range.\r
-\r
-#define kTopValue ((UInt32)1 << 24)\r
-\r
-void CRangeDecoder::Normalize()\r
-{\r
-  if (Range < kTopValue)\r
-  {\r
-    Range <<= 8;\r
-    Code = (Code << 8) | InStream->ReadByte();\r
-  }\r
-}\r
-\r
-Notes: if the size of the "Code" variable is larger than 32 bits, it's\r
-required to keep only low 32 bits of the "Code" variable after the change\r
-in Normalize() function.\r
-\r
-If the LZMA Stream is not corrupted, the value of the "Code" variable is\r
-always smaller than value of the "Range" variable.\r
-But the Range Decoder ignores some types of corruptions, so the value of\r
-the "Code" variable can be equal or larger than value of the "Range" variable\r
-for some "Corrupted" archives.\r
-\r
-\r
-LZMA uses Range Encoding only with binary symbols of two types:\r
-  1) binary symbols with fixed and equal probabilities (direct bits)\r
-  2) binary symbols with predicted probabilities\r
-\r
-The DecodeDirectBits() function decodes the sequence of direct bits:\r
-\r
-UInt32 CRangeDecoder::DecodeDirectBits(unsigned numBits)\r
-{\r
-  UInt32 res = 0;\r
-  do\r
-  {\r
-    Range >>= 1;\r
-    Code -= Range;\r
-    UInt32 t = 0 - ((UInt32)Code >> 31);\r
-    Code += Range & t;\r
-    \r
-    if (Code == Range)\r
-      Corrupted = true;\r
-    \r
-    Normalize();\r
-    res <<= 1;\r
-    res += t + 1;\r
-  }\r
-  while (--numBits);\r
-  return res;\r
-}\r
-\r
-\r
-The Bit Decoding with Probability Model\r
----------------------------------------\r
-\r
-The task of Bit Probability Model is to estimate probabilities of binary\r
-symbols. And then it provides the Range Decoder with that information.\r
-The better prediction provides better compression ratio.\r
-The Bit Probability Model uses statistical data of previous decoded\r
-symbols.\r
-\r
-That estimated probability is presented as 11-bit unsigned integer value\r
-that represents the probability of symbol "0".\r
-\r
-#define kNumBitModelTotalBits 11\r
-\r
-Mathematical probabilities can be presented with the following formulas:\r
-     probability(symbol_0) = prob / 2048.\r
-     probability(symbol_1) =  1 - Probability(symbol_0) =  \r
-                           =  1 - prob / 2048 =  \r
-                           =  (2048 - prob) / 2048\r
-where the "prob" variable contains 11-bit integer probability counter.\r
-\r
-It's recommended to use 16-bit unsigned integer type, to store these 11-bit\r
-probability values:\r
-\r
-typedef UInt16 CProb;\r
-\r
-Each probability value must be initialized with value ((1 << 11) / 2),\r
-that represents the state, where probabilities of symbols 0 and 1 \r
-are equal to 0.5:\r
-\r
-#define PROB_INIT_VAL ((1 << kNumBitModelTotalBits) / 2)\r
-\r
-The INIT_PROBS macro is used to initialize the array of CProb variables:\r
-\r
-#define INIT_PROBS(p) \\r
- { for (unsigned i = 0; i < sizeof(p) / sizeof(p[0]); i++) p[i] = PROB_INIT_VAL; }\r
-\r
-\r
-The DecodeBit() function decodes one bit.\r
-The LZMA decoder provides the pointer to CProb variable that contains \r
-information about estimated probability for symbol 0 and the Range Decoder \r
-updates that CProb variable after decoding. The Range Decoder increases \r
-estimated probability of the symbol that was decoded:\r
-\r
-#define kNumMoveBits 5\r
-\r
-unsigned CRangeDecoder::DecodeBit(CProb *prob)\r
-{\r
-  unsigned v = *prob;\r
-  UInt32 bound = (Range >> kNumBitModelTotalBits) * v;\r
-  unsigned symbol;\r
-  if (Code < bound)\r
-  {\r
-    v += ((1 << kNumBitModelTotalBits) - v) >> kNumMoveBits;\r
-    Range = bound;\r
-    symbol = 0;\r
-  }\r
-  else\r
-  {\r
-    v -= v >> kNumMoveBits;\r
-    Code -= bound;\r
-    Range -= bound;\r
-    symbol = 1;\r
-  }\r
-  *prob = (CProb)v;\r
-  Normalize();\r
-  return symbol;\r
-}\r
-\r
-\r
-The Binary Tree of bit model counters\r
--------------------------------------\r
-\r
-LZMA uses a tree of Bit model variables to decode symbol that needs\r
-several bits for storing. There are two versions of such trees in LZMA:\r
-  1) the tree that decodes bits from high bit to low bit (the normal scheme).\r
-  2) the tree that decodes bits from low bit to high bit (the reverse scheme).\r
-\r
-Each binary tree structure supports different size of decoded symbol\r
-(the size of binary sequence that contains value of symbol).\r
-If that size of decoded symbol is "NumBits" bits, the tree structure \r
-uses the array of (2 << NumBits) counters of CProb type. \r
-But only ((2 << NumBits) - 1) items are used by encoder and decoder.\r
-The first item (the item with index equal to 0) in array is unused.\r
-That scheme with unused array's item allows to simplify the code.\r
-\r
-unsigned BitTreeReverseDecode(CProb *probs, unsigned numBits, CRangeDecoder *rc)\r
-{\r
-  unsigned m = 1;\r
-  unsigned symbol = 0;\r
-  for (unsigned i = 0; i < numBits; i++)\r
-  {\r
-    unsigned bit = rc->DecodeBit(&probs[m]);\r
-    m <<= 1;\r
-    m += bit;\r
-    symbol |= (bit << i);\r
-  }\r
-  return symbol;\r
-}\r
-\r
-template <unsigned NumBits>\r
-class CBitTreeDecoder\r
-{\r
-  CProb Probs[(unsigned)1 << NumBits];\r
-\r
-public:\r
-\r
-  void Init()\r
-  {\r
-    INIT_PROBS(Probs);\r
-  }\r
-\r
-  unsigned Decode(CRangeDecoder *rc)\r
-  {\r
-    unsigned m = 1;\r
-    for (unsigned i = 0; i < NumBits; i++)\r
-      m = (m << 1) + rc->DecodeBit(&Probs[m]);\r
-    return m - ((unsigned)1 << NumBits);\r
-  }\r
-\r
-  unsigned ReverseDecode(CRangeDecoder *rc)\r
-  {\r
-    return BitTreeReverseDecode(Probs, NumBits, rc);\r
-  }\r
-};\r
-\r
-\r
-LZ part of LZMA \r
----------------\r
-\r
-LZ part of LZMA describes details about the decoding of MATCHES and LITERALS.\r
-\r
-\r
-The Literal Decoding\r
---------------------\r
-\r
-The LZMA Decoder uses (1 << (lc + lp)) tables with CProb values, where \r
-each table contains 0x300 CProb values:\r
-\r
-  CProb *LitProbs;\r
-\r
-  void CreateLiterals()\r
-  {\r
-    LitProbs = new CProb[(UInt32)0x300 << (lc + lp)];\r
-  }\r
-  \r
-  void InitLiterals()\r
-  {\r
-    UInt32 num = (UInt32)0x300 << (lc + lp);\r
-    for (UInt32 i = 0; i < num; i++)\r
-      LitProbs[i] = PROB_INIT_VAL;\r
-  }\r
-\r
-To select the table for decoding it uses the context that consists of\r
-(lc) high bits from previous literal and (lp) low bits from value that\r
-represents current position in outputStream.\r
-\r
-If (State > 7), the Literal Decoder also uses "matchByte" that represents \r
-the byte in OutputStream at position the is the DISTANCE bytes before \r
-current position, where the DISTANCE is the distance in DISTANCE-LENGTH pair\r
-of latest decoded match.\r
-\r
-The following code decodes one literal and puts it to Sliding Window buffer:\r
-\r
-  void DecodeLiteral(unsigned state, UInt32 rep0)\r
-  {\r
-    unsigned prevByte = 0;\r
-    if (!OutWindow.IsEmpty())\r
-      prevByte = OutWindow.GetByte(1);\r
-    \r
-    unsigned symbol = 1;\r
-    unsigned litState = ((OutWindow.TotalPos & ((1 << lp) - 1)) << lc) + (prevByte >> (8 - lc));\r
-    CProb *probs = &LitProbs[(UInt32)0x300 * litState];\r
-    \r
-    if (state >= 7)\r
-    {\r
-      unsigned matchByte = OutWindow.GetByte(rep0 + 1);\r
-      do\r
-      {\r
-        unsigned matchBit = (matchByte >> 7) & 1;\r
-        matchByte <<= 1;\r
-        unsigned bit = RangeDec.DecodeBit(&probs[((1 + matchBit) << 8) + symbol]);\r
-        symbol = (symbol << 1) | bit;\r
-        if (matchBit != bit)\r
-          break;\r
-      }\r
-      while (symbol < 0x100);\r
-    }\r
-    while (symbol < 0x100)\r
-      symbol = (symbol << 1) | RangeDec.DecodeBit(&probs[symbol]);\r
-    OutWindow.PutByte((Byte)(symbol - 0x100));\r
-  }\r
-\r
-\r
-The match length decoding\r
--------------------------\r
-\r
-The match length decoder returns normalized (zero-based value) \r
-length of match. That value can be converted to real length of the match \r
-with the following code:\r
-\r
-#define kMatchMinLen 2\r
-\r
-    matchLen = len + kMatchMinLen;\r
-\r
-The match length decoder can return the values from 0 to 271.\r
-And the corresponded real match length values can be in the range \r
-from 2 to 273.\r
-\r
-The following scheme is used for the match length encoding:\r
-\r
-  Binary encoding    Binary Tree structure    Zero-based match length \r
-  sequence                                    (binary + decimal):\r
-\r
-  0 xxx              LowCoder[posState]       xxx\r
-  1 0 yyy            MidCoder[posState]       yyy + 8\r
-  1 1 zzzzzzzz       HighCoder                zzzzzzzz + 16\r
-\r
-LZMA uses bit model variable "Choice" to decode the first selection bit.\r
-\r
-If the first selection bit is equal to 0, the decoder uses binary tree \r
-  LowCoder[posState] to decode 3-bit zero-based match length (xxx).\r
-\r
-If the first selection bit is equal to 1, the decoder uses bit model \r
-  variable "Choice2" to decode the second selection bit.\r
-\r
-  If the second selection bit is equal to 0, the decoder uses binary tree \r
-    MidCoder[posState] to decode 3-bit "yyy" value, and zero-based match\r
-    length is equal to (yyy + 8).\r
-\r
-  If the second selection bit is equal to 1, the decoder uses binary tree \r
-    HighCoder to decode 8-bit "zzzzzzzz" value, and zero-based \r
-    match length is equal to (zzzzzzzz + 16).\r
-\r
-LZMA uses "posState" value as context to select the binary tree \r
-from LowCoder and MidCoder binary tree arrays:\r
-\r
-    unsigned posState = OutWindow.TotalPos & ((1 << pb) - 1);\r
-\r
-The full code of the length decoder:\r
-\r
-class CLenDecoder\r
-{\r
-  CProb Choice;\r
-  CProb Choice2;\r
-  CBitTreeDecoder<3> LowCoder[1 << kNumPosBitsMax];\r
-  CBitTreeDecoder<3> MidCoder[1 << kNumPosBitsMax];\r
-  CBitTreeDecoder<8> HighCoder;\r
-\r
-public:\r
-\r
-  void Init()\r
-  {\r
-    Choice = PROB_INIT_VAL;\r
-    Choice2 = PROB_INIT_VAL;\r
-    HighCoder.Init();\r
-    for (unsigned i = 0; i < (1 << kNumPosBitsMax); i++)\r
-    {\r
-      LowCoder[i].Init();\r
-      MidCoder[i].Init();\r
-    }\r
-  }\r
-\r
-  unsigned Decode(CRangeDecoder *rc, unsigned posState)\r
-  {\r
-    if (rc->DecodeBit(&Choice) == 0)\r
-      return LowCoder[posState].Decode(rc);\r
-    if (rc->DecodeBit(&Choice2) == 0)\r
-      return 8 + MidCoder[posState].Decode(rc);\r
-    return 16 + HighCoder.Decode(rc);\r
-  }\r
-};\r
-\r
-The LZMA decoder uses two instances of CLenDecoder class.\r
-The first instance is for the matches of "Simple Match" type,\r
-and the second instance is for the matches of "Rep Match" type:\r
-\r
-  CLenDecoder LenDecoder;\r
-  CLenDecoder RepLenDecoder;\r
-\r
-\r
-The match distance decoding\r
----------------------------\r
-\r
-LZMA supports dictionary sizes up to 4 GiB minus 1.\r
-The value of match distance (decoded by distance decoder) can be \r
-from 1 to 2^32. But the distance value that is equal to 2^32 is used to\r
-indicate the "End of stream" marker. So real largest match distance \r
-that is used for LZ-window match is (2^32 - 1).\r
-\r
-LZMA uses normalized match length (zero-based length) \r
-to calculate the context state "lenState" do decode the distance value:\r
-\r
-#define kNumLenToPosStates 4\r
-\r
-    unsigned lenState = len;\r
-    if (lenState > kNumLenToPosStates - 1)\r
-      lenState = kNumLenToPosStates - 1;\r
-\r
-The distance decoder returns the "dist" value that is zero-based value \r
-of match distance. The real match distance can be calculated with the\r
-following code:\r
-  \r
-  matchDistance = dist + 1; \r
-\r
-The state of the distance decoder and the initialization code: \r
-\r
-  #define kEndPosModelIndex 14\r
-  #define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r
-  #define kNumAlignBits 4\r
-\r
-  CBitTreeDecoder<6> PosSlotDecoder[kNumLenToPosStates];\r
-  CProb PosDecoders[1 + kNumFullDistances - kEndPosModelIndex];\r
-  CBitTreeDecoder<kNumAlignBits> AlignDecoder;\r
-\r
-  void InitDist()\r
-  {\r
-    for (unsigned i = 0; i < kNumLenToPosStates; i++)\r
-      PosSlotDecoder[i].Init();\r
-    AlignDecoder.Init();\r
-    INIT_PROBS(PosDecoders);\r
-  }\r
-\r
-At first stage the distance decoder decodes 6-bit "posSlot" value with bit\r
-tree decoder from PosSlotDecoder array. It's possible to get 2^6=64 different \r
-"posSlot" values.\r
-\r
-    unsigned posSlot = PosSlotDecoder[lenState].Decode(&RangeDec);\r
-\r
-The encoding scheme for distance value is shown in the following table:\r
-\r
-posSlot (decimal) /\r
-      zero-based distance (binary)\r
- 0    0\r
- 1    1\r
- 2    10\r
- 3    11\r
-\r
- 4    10 x\r
- 5    11 x\r
- 6    10 xx\r
- 7    11 xx\r
- 8    10 xxx\r
- 9    11 xxx\r
-10    10 xxxx\r
-11    11 xxxx\r
-12    10 xxxxx\r
-13    11 xxxxx\r
-\r
-14    10 yy zzzz\r
-15    11 yy zzzz\r
-16    10 yyy zzzz\r
-17    11 yyy zzzz\r
-...\r
-62    10 yyyyyyyyyyyyyyyyyyyyyyyyyy zzzz\r
-63    11 yyyyyyyyyyyyyyyyyyyyyyyyyy zzzz\r
-\r
-where \r
-  "x ... x" means the sequence of binary symbols encoded with binary tree and \r
-      "Reverse" scheme. It uses separated binary tree for each posSlot from 4 to 13.\r
-  "y" means direct bit encoded with range coder.\r
-  "zzzz" means the sequence of four binary symbols encoded with binary\r
-      tree with "Reverse" scheme, where one common binary tree "AlignDecoder"\r
-      is used for all posSlot values.\r
-\r
-If (posSlot < 4), the "dist" value is equal to posSlot value.\r
-\r
-If (posSlot >= 4), the decoder uses "posSlot" value to calculate the value of\r
-  the high bits of "dist" value and the number of the low bits.\r
-\r
-  If (4 <= posSlot < kEndPosModelIndex), the decoder uses bit tree decoders.\r
-    (one separated bit tree decoder per one posSlot value) and "Reverse" scheme.\r
-    In this implementation we use one CProb array "PosDecoders" that contains \r
-    all CProb variables for all these bit decoders.\r
-  \r
-  if (posSlot >= kEndPosModelIndex), the middle bits are decoded as direct \r
-    bits from RangeDecoder and the low 4 bits are decoded with a bit tree \r
-    decoder "AlignDecoder" with "Reverse" scheme.\r
-\r
-The code to decode zero-based match distance:\r
-  \r
-  unsigned DecodeDistance(unsigned len)\r
-  {\r
-    unsigned lenState = len;\r
-    if (lenState > kNumLenToPosStates - 1)\r
-      lenState = kNumLenToPosStates - 1;\r
-    \r
-    unsigned posSlot = PosSlotDecoder[lenState].Decode(&RangeDec);\r
-    if (posSlot < 4)\r
-      return posSlot;\r
-    \r
-    unsigned numDirectBits = (unsigned)((posSlot >> 1) - 1);\r
-    UInt32 dist = ((2 | (posSlot & 1)) << numDirectBits);\r
-    if (posSlot < kEndPosModelIndex)\r
-      dist += BitTreeReverseDecode(PosDecoders + dist - posSlot, numDirectBits, &RangeDec);\r
-    else\r
-    {\r
-      dist += RangeDec.DecodeDirectBits(numDirectBits - kNumAlignBits) << kNumAlignBits;\r
-      dist += AlignDecoder.ReverseDecode(&RangeDec);\r
-    }\r
-    return dist;\r
-  }\r
-\r
-\r
-\r
-LZMA Decoding modes\r
--------------------\r
-\r
-There are 2 types of LZMA streams:\r
-\r
-1) The stream with "End of stream" marker.\r
-2) The stream without "End of stream" marker.\r
-\r
-And the LZMA Decoder supports 3 modes of decoding:\r
-\r
-1) The unpack size is undefined. The LZMA decoder stops decoding after \r
-   getting "End of stream" marker. \r
-   The input variables for that case:\r
-    \r
-      markerIsMandatory = true\r
-      unpackSizeDefined = false\r
-      unpackSize contains any value\r
-\r
-2) The unpack size is defined and LZMA decoder supports both variants, \r
-   where the stream can contain "End of stream" marker or the stream is\r
-   finished without "End of stream" marker. The LZMA decoder must detect \r
-   any of these situations.\r
-   The input variables for that case:\r
-    \r
-      markerIsMandatory = false\r
-      unpackSizeDefined = true\r
-      unpackSize contains unpack size\r
-\r
-3) The unpack size is defined and the LZMA stream must contain \r
-   "End of stream" marker\r
-   The input variables for that case:\r
-    \r
-      markerIsMandatory = true\r
-      unpackSizeDefined = true\r
-      unpackSize contains unpack size\r
-\r
-\r
-The main loop of decoder\r
-------------------------\r
-\r
-The main loop of LZMA decoder:\r
-\r
-Initialize the LZMA state.\r
-loop\r
-{\r
-  // begin of loop\r
-  Check "end of stream" conditions.\r
-  Decode Type of MATCH / LITERAL. \r
-    If it's LITERAL, decode LITERAL value and put the LITERAL to Window.\r
-    If it's MATCH, decode the length of match and the match distance. \r
-        Check error conditions, check end of stream conditions and copy\r
-        the sequence of match bytes from sliding window to current position\r
-        in window.\r
-  Go to begin of loop\r
-}\r
-\r
-The reference implementation of LZMA decoder uses "unpackSize" variable\r
-to keep the number of remaining bytes in output stream. So it reduces \r
-"unpackSize" value after each decoded LITERAL or MATCH.\r
-\r
-The following code contains the "end of stream" condition check at the start\r
-of the loop:\r
-\r
-    if (unpackSizeDefined && unpackSize == 0 && !markerIsMandatory)\r
-      if (RangeDec.IsFinishedOK())\r
-        return LZMA_RES_FINISHED_WITHOUT_MARKER;\r
-\r
-LZMA uses three types of matches:\r
-\r
-1) "Simple Match" -     the match with distance value encoded with bit models.\r
-\r
-2) "Rep Match" -        the match that uses the distance from distance\r
-                        history table.\r
-\r
-3) "Short Rep Match" -  the match of single byte length, that uses the latest \r
-                        distance from distance history table.\r
-\r
-The LZMA decoder keeps the history of latest 4 match distances that were used \r
-by decoder. That set of 4 variables contains zero-based match distances and \r
-these variables are initialized with zero values:\r
-\r
-  UInt32 rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r
-\r
-The LZMA decoder uses binary model variables to select type of MATCH or LITERAL:\r
-\r
-#define kNumStates 12\r
-#define kNumPosBitsMax 4\r
-\r
-  CProb IsMatch[kNumStates << kNumPosBitsMax];\r
-  CProb IsRep[kNumStates];\r
-  CProb IsRepG0[kNumStates];\r
-  CProb IsRepG1[kNumStates];\r
-  CProb IsRepG2[kNumStates];\r
-  CProb IsRep0Long[kNumStates << kNumPosBitsMax];\r
-\r
-The decoder uses "state" variable value to select exact variable \r
-from "IsRep", "IsRepG0", "IsRepG1" and "IsRepG2" arrays.\r
-The "state" variable can get the value from 0 to 11.\r
-Initial value for "state" variable is zero:\r
-\r
-  unsigned state = 0;\r
-\r
-The "state" variable is updated after each LITERAL or MATCH with one of the\r
-following functions:\r
-\r
-unsigned UpdateState_Literal(unsigned state)\r
-{\r
-  if (state < 4) return 0;\r
-  else if (state < 10) return state - 3;\r
-  else return state - 6;\r
-}\r
-unsigned UpdateState_Match   (unsigned state) { return state < 7 ? 7 : 10; }\r
-unsigned UpdateState_Rep     (unsigned state) { return state < 7 ? 8 : 11; }\r
-unsigned UpdateState_ShortRep(unsigned state) { return state < 7 ? 9 : 11; }\r
-\r
-The decoder calculates "state2" variable value to select exact variable from \r
-"IsMatch" and "IsRep0Long" arrays:\r
-\r
-unsigned posState = OutWindow.TotalPos & ((1 << pb) - 1);\r
-unsigned state2 = (state << kNumPosBitsMax) + posState;\r
-\r
-The decoder uses the following code flow scheme to select exact \r
-type of LITERAL or MATCH:\r
-\r
-IsMatch[state2] decode\r
-  0 - the Literal\r
-  1 - the Match\r
-    IsRep[state] decode\r
-      0 - Simple Match\r
-      1 - Rep Match\r
-        IsRepG0[state] decode\r
-          0 - the distance is rep0\r
-            IsRep0Long[state2] decode\r
-              0 - Short Rep Match\r
-              1 - Rep Match 0\r
-          1 - \r
-            IsRepG1[state] decode\r
-              0 - Rep Match 1\r
-              1 - \r
-                IsRepG2[state] decode\r
-                  0 - Rep Match 2\r
-                  1 - Rep Match 3\r
-\r
-\r
-LITERAL symbol\r
---------------\r
-If the value "0" was decoded with IsMatch[state2] decoding, we have "LITERAL" type.\r
-\r
-At first the LZMA decoder must check that it doesn't exceed \r
-specified uncompressed size:\r
-\r
-      if (unpackSizeDefined && unpackSize == 0)\r
-        return LZMA_RES_ERROR;\r
-\r
-Then it decodes literal value and puts it to sliding window:\r
-\r
-      DecodeLiteral(state, rep0);\r
-\r
-Then the decoder must update the "state" value and "unpackSize" value;\r
-\r
-      state = UpdateState_Literal(state);\r
-      unpackSize--;\r
-\r
-Then the decoder must go to the begin of main loop to decode next Match or Literal.\r
-\r
-\r
-Simple Match\r
-------------\r
-\r
-If the value "1" was decoded with IsMatch[state2] decoding,\r
-we have the "Simple Match" type.\r
-\r
-The distance history table is updated with the following scheme:\r
-    \r
-      rep3 = rep2;\r
-      rep2 = rep1;\r
-      rep1 = rep0;\r
-\r
-The zero-based length is decoded with "LenDecoder":\r
-\r
-      len = LenDecoder.Decode(&RangeDec, posState);\r
-\r
-The state is update with UpdateState_Match function:\r
-\r
-      state = UpdateState_Match(state);\r
-\r
-and the new "rep0" value is decoded with DecodeDistance:\r
-\r
-      rep0 = DecodeDistance(len);\r
-\r
-That "rep0" will be used as zero-based distance for current match.\r
-\r
-If the value of "rep0" is equal to 0xFFFFFFFF, it means that we have \r
-"End of stream" marker, so we can stop decoding and check finishing \r
-condition in Range Decoder:\r
-\r
-      if (rep0 == 0xFFFFFFFF)\r
-        return RangeDec.IsFinishedOK() ?\r
-            LZMA_RES_FINISHED_WITH_MARKER :\r
-            LZMA_RES_ERROR;\r
-\r
-If uncompressed size is defined, LZMA decoder must check that it doesn't \r
-exceed that specified uncompressed size:\r
-\r
-      if (unpackSizeDefined && unpackSize == 0)\r
-        return LZMA_RES_ERROR;\r
-\r
-Also the decoder must check that "rep0" value is not larger than dictionary size\r
-and is not larger than the number of already decoded bytes:\r
-\r
-      if (rep0 >= dictSize || !OutWindow.CheckDistance(rep0))\r
-        return LZMA_RES_ERROR;\r
-\r
-Then the decoder must copy match bytes as described in \r
-"The match symbols copying" section.\r
-\r
-\r
-Rep Match\r
----------\r
-\r
-If the LZMA decoder has decoded the value "1" with IsRep[state] variable,\r
-we have "Rep Match" type.\r
-\r
-At first the LZMA decoder must check that it doesn't exceed \r
-specified uncompressed size:\r
-\r
-      if (unpackSizeDefined && unpackSize == 0)\r
-        return LZMA_RES_ERROR;\r
-\r
-Also the decoder must return error, if the LZ window is empty:\r
-\r
-      if (OutWindow.IsEmpty())\r
-        return LZMA_RES_ERROR;\r
-\r
-If the match type is "Rep Match", the decoder uses one of the 4 variables of\r
-distance history table to get the value of distance for current match.\r
-And there are 4 corresponding ways of decoding flow. \r
-\r
-The decoder updates the distance history with the following scheme \r
-depending from type of match:\r
-\r
-- "Rep Match 0" or "Short Rep Match":\r
-      ; LZMA doesn't update the distance history    \r
-\r
-- "Rep Match 1":\r
-      UInt32 dist = rep1;\r
-      rep1 = rep0;\r
-      rep0 = dist;\r
-\r
-- "Rep Match 2":\r
-      UInt32 dist = rep2;\r
-      rep2 = rep1;\r
-      rep1 = rep0;\r
-      rep0 = dist;\r
-\r
-- "Rep Match 3":\r
-      UInt32 dist = rep3;\r
-      rep3 = rep2;\r
-      rep2 = rep1;\r
-      rep1 = rep0;\r
-      rep0 = dist;\r
-\r
-Then the decoder decodes exact subtype of "Rep Match" using "IsRepG0", "IsRep0Long",\r
-"IsRepG1", "IsRepG2".\r
-\r
-If the subtype is "Short Rep Match", the decoder updates the state, puts \r
-the one byte from window to current position in window and goes to next \r
-MATCH/LITERAL symbol (the begin of main loop):\r
-\r
-          state = UpdateState_ShortRep(state);\r
-          OutWindow.PutByte(OutWindow.GetByte(rep0 + 1));\r
-          unpackSize--;\r
-          continue;\r
-\r
-In other cases (Rep Match 0/1/2/3), it decodes the zero-based \r
-length of match with "RepLenDecoder" decoder:\r
-\r
-      len = RepLenDecoder.Decode(&RangeDec, posState);\r
-\r
-Then it updates the state:\r
-\r
-      state = UpdateState_Rep(state);\r
-\r
-Then the decoder must copy match bytes as described in \r
-"The Match symbols copying" section.\r
-\r
-\r
-The match symbols copying\r
--------------------------\r
-\r
-If we have the match (Simple Match or Rep Match 0/1/2/3), the decoder must\r
-copy the sequence of bytes with calculated match distance and match length.\r
-If uncompressed size is defined, LZMA decoder must check that it doesn't \r
-exceed that specified uncompressed size:\r
-\r
-    len += kMatchMinLen;\r
-    bool isError = false;\r
-    if (unpackSizeDefined && unpackSize < len)\r
-    {\r
-      len = (unsigned)unpackSize;\r
-      isError = true;\r
-    }\r
-    OutWindow.CopyMatch(rep0 + 1, len);\r
-    unpackSize -= len;\r
-    if (isError)\r
-      return LZMA_RES_ERROR;\r
-\r
-Then the decoder must go to the begin of main loop to decode next MATCH or LITERAL.\r
-\r
-\r
-\r
-NOTES\r
------\r
-\r
-This specification doesn't describe the variant of decoder implementation \r
-that supports partial decoding. Such partial decoding case can require some \r
-changes in "end of stream" condition checks code. Also such code \r
-can use additional status codes, returned by decoder.\r
-\r
-This specification uses C++ code with templates to simplify describing.\r
-The optimized version of LZMA decoder doesn't need templates.\r
-Such optimized version can use just two arrays of CProb variables:\r
-  1) The dynamic array of CProb variables allocated for the Literal Decoder.\r
-  2) The one common array that contains all other CProb variables.\r
-\r
-\r
-References:      \r
-\r
-1. G. N. N. Martin, Range encoding: an algorithm for removing redundancy \r
-   from a digitized message, Video & Data Recording Conference, \r
-   Southampton, UK, July 24-27, 1979.\r
diff --git a/deps/zlib/adler32.c b/deps/zlib/adler32.c
deleted file mode 100644 (file)
index cccb3a2..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995-2003 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#define ZLIB_INTERNAL
-#include <stdint.h>
-#include <stddef.h>
-#include "zutil.h"
-
-#define BASE 65521UL    /* largest prime smaller than 65536 */
-#define NMAX 5552
-/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-
-#define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
-#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
-#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
-#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
-#define DO16(buf)   DO8(buf,0); DO8(buf,8);
-
-#ifdef NO_DIVIDE
-#  define MOD(a) \
-   do { \
-      if (a >= (BASE << 16)) a -= (BASE << 16); \
-      if (a >= (BASE << 15)) a -= (BASE << 15); \
-      if (a >= (BASE << 14)) a -= (BASE << 14); \
-      if (a >= (BASE << 13)) a -= (BASE << 13); \
-      if (a >= (BASE << 12)) a -= (BASE << 12); \
-      if (a >= (BASE << 11)) a -= (BASE << 11); \
-      if (a >= (BASE << 10)) a -= (BASE << 10); \
-      if (a >= (BASE << 9)) a -= (BASE << 9); \
-      if (a >= (BASE << 8)) a -= (BASE << 8); \
-      if (a >= (BASE << 7)) a -= (BASE << 7); \
-      if (a >= (BASE << 6)) a -= (BASE << 6); \
-      if (a >= (BASE << 5)) a -= (BASE << 5); \
-      if (a >= (BASE << 4)) a -= (BASE << 4); \
-      if (a >= (BASE << 3)) a -= (BASE << 3); \
-      if (a >= (BASE << 2)) a -= (BASE << 2); \
-      if (a >= (BASE << 1)) a -= (BASE << 1); \
-      if (a >= BASE) a -= BASE; \
-   } while (0)
-#else
-#  define MOD(a) a %= BASE
-#endif
-
-/* ========================================================================= */
-uLong adler32(uLong adler, const Bytef *buf, uInt len)
-{
-   uint32_t s1 = adler & 0xffff;
-   uint32_t s2 = (adler >> 16) & 0xffff;
-   int k;
-
-   if (buf == NULL)
-      return 1L;
-
-   while (len > 0) {
-      k = len < NMAX ? (int)len : NMAX;
-      len -= k;
-      while (k >= 16) {
-         DO16(buf);
-         buf += 16;
-         k -= 16;
-      }
-      if (k != 0) do {
-         s1 += *buf++;
-         s2 += s1;
-      } while (--k);
-      MOD(s1);
-      MOD(s2);
-   }
-   return (s2 << 16) | s1;
-}
-
diff --git a/deps/zlib/compress.c b/deps/zlib/compress.c
deleted file mode 100644 (file)
index 48465bd..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/* compress.c -- compress a memory buffer
- * Copyright (C) 1995-2005 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#define ZLIB_INTERNAL
-#include "zlib.h"
-
-/* ===========================================================================
-   Compresses the source buffer into the destination buffer. The level
-   parameter has the same meaning as in deflateInit.  sourceLen is the byte
-   length of the source buffer. Upon entry, destLen is the total size of the
-   destination buffer, which must be at least 0.1% larger than sourceLen plus
-   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
-
-   compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
-   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
-   Z_STREAM_ERROR if the level parameter is invalid.
-   */
-int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
-{
-   z_stream stream;
-   int err;
-
-   stream.next_in = (Bytef *)source;
-   stream.avail_in = (uInt)sourceLen;
-#ifdef MAXSEG_64K
-   /* Check for source > 64K on 16-bit machine: */
-   if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
-#endif
-   stream.next_out = dest;
-   stream.avail_out = (uInt)*destLen;
-   if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
-
-   stream.zalloc = Z_NULL;
-   stream.zfree = Z_NULL;
-   stream.opaque = (voidpf)0;
-
-   err = deflateInit(&stream, level);
-   if (err != Z_OK) return err;
-
-   err = deflate(&stream, Z_FINISH);
-   if (err != Z_STREAM_END) {
-      deflateEnd(&stream);
-      return err == Z_OK ? Z_BUF_ERROR : err;
-   }
-   *destLen = stream.total_out;
-
-   err = deflateEnd(&stream);
-   return err;
-}
-
-/* ===========================================================================
-*/
-int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
-{
-   return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
-}
-
-/* ===========================================================================
-   If the default memLevel or windowBits for deflateInit() is changed, then
-   this function needs to be updated.
-   */
-uLong ZEXPORT compressBound (uLong sourceLen)
-{
-   return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
-      (sourceLen >> 25) + 13;
-}
diff --git a/deps/zlib/crc32.c b/deps/zlib/crc32.c
deleted file mode 100644 (file)
index 73369a2..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-#ifndef _S_CRC32_H
-#define _S_CRC32_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-   static const unsigned long crc_table[256] = {
-      0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
-      0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
-      0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
-      0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
-      0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
-      0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
-      0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
-      0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
-      0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
-      0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
-      0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
-      0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
-      0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
-      0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
-      0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
-      0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
-      0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
-      0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
-      0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
-      0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
-      0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
-      0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
-      0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
-      0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
-      0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
-      0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
-      0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
-      0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
-      0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
-      0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
-      0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
-      0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
-      0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
-      0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
-      0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
-      0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
-      0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
-      0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
-      0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
-      0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
-      0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
-      0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
-      0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
-      0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
-      0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
-      0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
-      0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
-      0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
-      0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
-      0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
-      0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
-      0x2d02ef8dL
-   };
-
-#define DO1_CRC32(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
-#define DO2_CRC32(buf) DO1_CRC32(buf); DO1_CRC32(buf);
-#define DO4_CRC32(buf) DO2_CRC32(buf); DO2_CRC32(buf);
-#define DO8_CRC32(buf) DO4_CRC32(buf); DO4_CRC32(buf);
-
-   unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len)
-   {
-      if (buf == 0) return 0L;
-      crc = crc ^ 0xffffffffL;
-      while (len >= 8)
-      {
-         DO8_CRC32(buf);
-         len -= 8;
-      }
-      if (len) do {
-         DO1_CRC32(buf);
-      } while (--len);
-      return crc ^ 0xffffffffL;
-   }
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/deps/zlib/deflate.c b/deps/zlib/deflate.c
deleted file mode 100644 (file)
index f8fbc48..0000000
+++ /dev/null
@@ -1,1913 +0,0 @@
-/* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/*
- *  ALGORITHM
- *
- *      The "deflation" process depends on being able to identify portions
- *      of the input text which are identical to earlier input (within a
- *      sliding window trailing behind the input currently being processed).
- *
- *      The most straightforward technique turns out to be the fastest for
- *      most input files: try all possible matches and select the longest.
- *      The key feature of this algorithm is that insertions into the string
- *      dictionary are very simple and thus fast, and deletions are avoided
- *      completely. Insertions are performed at each input character, whereas
- *      string matches are performed only when the previous match ends. So it
- *      is preferable to spend more time in matches to allow very fast string
- *      insertions and avoid deletions. The matching algorithm for small
- *      strings is inspired from that of Rabin & Karp. A brute force approach
- *      is used to find longer strings when a small match has been found.
- *      A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
- *      (by Leonid Broukhis).
- *         A previous version of this file used a more sophisticated algorithm
- *      (by Fiala and Greene) which is guaranteed to run in linear amortized
- *      time, but has a larger average cost, uses more memory and is patented.
- *      However the F&G algorithm may be faster for some highly redundant
- *      files if the parameter max_chain_length (described below) is too large.
- *
- *  ACKNOWLEDGEMENTS
- *
- *      The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
- *      I found it in 'freeze' written by Leonid Broukhis.
- *      Thanks to many people for bug reports and testing.
- *
- *  REFERENCES
- *
- *      Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
- *      Available in http://tools.ietf.org/html/rfc1951
- *
- *      A description of the Rabin and Karp algorithm is given in the book
- *         "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
- *
- *      Fiala,E.R., and Greene,D.H.
- *         Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
- *
- */
-
-/* @(#) $Id$ */
-
-#include "deflate.h"
-
-const char deflate_copyright[] =
-" deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler ";
-/*
-   If you use the zlib library in a product, an acknowledgment is welcome
-   in the documentation of your product. If for some reason you cannot
-   include such an acknowledgment, I would appreciate that you keep this
-   copyright string in the executable of your product.
-   */
-
-/* ===========================================================================
- *  Function prototypes.
- */
-typedef enum {
-   need_more,      /* block not completed, need more input or more output */
-   block_done,     /* block flush performed */
-   finish_started, /* finish started, need only more output at next deflate */
-   finish_done     /* finish done, accept no more input or output */
-} block_state;
-
-typedef block_state (*compress_func) OF((deflate_state *s, int flush));
-/* Compression function. Returns the block state after the call. */
-
-local void fill_window    OF((deflate_state *s));
-local block_state deflate_stored OF((deflate_state *s, int flush));
-local block_state deflate_fast   OF((deflate_state *s, int flush));
-#ifndef FASTEST
-local block_state deflate_slow   OF((deflate_state *s, int flush));
-#endif
-local block_state deflate_rle    OF((deflate_state *s, int flush));
-local block_state deflate_huff   OF((deflate_state *s, int flush));
-local void lm_init        OF((deflate_state *s));
-local void putShortMSB    OF((deflate_state *s, uInt b));
-local void flush_pending  OF((z_streamp strm));
-local int read_buf        OF((z_streamp strm, Bytef *buf, unsigned size));
-#ifdef ASMV
-void match_init OF((void)); /* asm code initialization */
-uInt longest_match  OF((deflate_state *s, IPos cur_match));
-#else
-local uInt longest_match  OF((deflate_state *s, IPos cur_match));
-#endif
-
-#ifdef DEBUG
-local  void check_match OF((deflate_state *s, IPos start, IPos match,
-         int length));
-#endif
-
-/* ===========================================================================
- * Local data
- */
-
-#define NIL 0
-/* Tail of hash chains */
-
-#ifndef TOO_FAR
-#  define TOO_FAR 4096
-#endif
-/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
-
-/* Values for max_lazy_match, good_match and max_chain_length, depending on
- * the desired pack level (0..9). The values given below have been tuned to
- * exclude worst case performance for pathological files. Better values may be
- * found for specific files.
- */
-typedef struct config_s {
-   ush good_length; /* reduce lazy search above this match length */
-   ush max_lazy;    /* do not perform lazy search above this match length */
-   ush nice_length; /* quit search above this match length */
-   ush max_chain;
-   compress_func func;
-} config;
-
-#ifdef FASTEST
-local const config configuration_table[2] = {
-   /*      good lazy nice chain */
-   /* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
-   /* 1 */ {4,    4,  8,    4, deflate_fast}}; /* max speed, no lazy matches */
-#else
-local const config configuration_table[10] = {
-   /*      good lazy nice chain */
-   /* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
-   /* 1 */ {4,    4,  8,    4, deflate_fast}, /* max speed, no lazy matches */
-   /* 2 */ {4,    5, 16,    8, deflate_fast},
-   /* 3 */ {4,    6, 32,   32, deflate_fast},
-
-   /* 4 */ {4,    4, 16,   16, deflate_slow},  /* lazy matches */
-   /* 5 */ {8,   16, 32,   32, deflate_slow},
-   /* 6 */ {8,   16, 128, 128, deflate_slow},
-   /* 7 */ {8,   32, 128, 256, deflate_slow},
-   /* 8 */ {32, 128, 258, 1024, deflate_slow},
-   /* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
-#endif
-
-/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
- * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
- * meaning.
- */
-
-#define EQUAL 0
-/* result of memcmp for equal strings */
-
-/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
-#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
-
-/* ===========================================================================
- * Update a hash value with the given input byte
- * IN  assertion: all calls to to UPDATE_HASH are made with consecutive
- *    input characters, so that a running hash key can be computed from the
- *    previous key instead of complete recalculation each time.
- */
-#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
-
-
-/* ===========================================================================
- * Insert string str in the dictionary and set match_head to the previous head
- * of the hash chain (the most recent string with same hash key). Return
- * the previous length of the hash chain.
- * If this file is compiled with -DFASTEST, the compression level is forced
- * to 1, and no hash chains are maintained.
- * IN  assertion: all calls to to INSERT_STRING are made with consecutive
- *    input characters and the first MIN_MATCH bytes of str are valid
- *    (except for the last MIN_MATCH-1 bytes of the input file).
- */
-#ifdef FASTEST
-#define INSERT_STRING(s, str, match_head) \
-   (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
-    match_head = s->head[s->ins_h], \
-    s->head[s->ins_h] = (Pos)(str))
-#else
-#define INSERT_STRING(s, str, match_head) \
-   (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
-    match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
-    s->head[s->ins_h] = (Pos)(str))
-#endif
-
-/* ===========================================================================
- * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
- * prev[] will be initialized on the fly.
- */
-#define CLEAR_HASH(s) \
-   s->head[s->hash_size-1] = NIL; \
-zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
-
-int ZEXPORT deflateResetKeep (z_streamp strm);
-
-int ZEXPORT deflatePending (z_streamp strm, unsigned *pending, int *bits);
-
-/* ========================================================================= */
-int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
-{
-   return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
-         Z_DEFAULT_STRATEGY, version, stream_size);
-   /* To do: ignore strm->next_in if we use it as window */
-}
-
-/* ========================================================================= */
-int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy,
-      const char *version, int stream_size)
-{
-   deflate_state *s;
-   int wrap = 1;
-   static const char my_version[] = ZLIB_VERSION;
-
-   ushf *overlay;
-   /* We overlay pending_buf and d_buf+l_buf. This works since the average
-    * output size for (length,distance) codes is <= 24 bits.
-    */
-
-   if (version == Z_NULL || version[0] != my_version[0] ||
-         stream_size != sizeof(z_stream)) {
-      return Z_VERSION_ERROR;
-   }
-   if (strm == Z_NULL) return Z_STREAM_ERROR;
-
-   strm->msg = Z_NULL;
-   if (strm->zalloc == (alloc_func)0) {
-#ifdef Z_SOLO
-      return Z_STREAM_ERROR;
-#else
-      strm->zalloc = zcalloc;
-      strm->opaque = (voidpf)0;
-#endif
-   }
-   if (strm->zfree == NULL)
-#ifdef Z_SOLO
-      return Z_STREAM_ERROR;
-#else
-   strm->zfree = zcfree;
-#endif
-
-#ifdef FASTEST
-   if (level != 0) level = 1;
-#else
-   if (level == Z_DEFAULT_COMPRESSION) level = 6;
-#endif
-
-   if (windowBits < 0) { /* suppress zlib wrapper */
-      wrap = 0;
-      windowBits = -windowBits;
-   }
-#ifdef GZIP
-   else if (windowBits > 15) {
-      wrap = 2;       /* write gzip wrapper instead */
-      windowBits -= 16;
-   }
-#endif
-   if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
-         windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
-         strategy < 0 || strategy > Z_FIXED) {
-      return Z_STREAM_ERROR;
-   }
-   if (windowBits == 8) windowBits = 9;  /* until 256-byte window bug fixed */
-   s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
-   if (s == Z_NULL) return Z_MEM_ERROR;
-   strm->state = (struct internal_state*)s;
-   s->strm = strm;
-
-   s->wrap = wrap;
-   s->gzhead = Z_NULL;
-   s->w_bits = windowBits;
-   s->w_size = 1 << s->w_bits;
-   s->w_mask = s->w_size - 1;
-
-   s->hash_bits = memLevel + 7;
-   s->hash_size = 1 << s->hash_bits;
-   s->hash_mask = s->hash_size - 1;
-   s->hash_shift =  ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
-
-   s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
-   s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
-   s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));
-
-   s->high_water = 0;      /* nothing written to s->window yet */
-
-   s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
-
-   overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
-   s->pending_buf = (uchf *) overlay;
-   s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
-
-   if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
-         s->pending_buf == Z_NULL) {
-      s->status = FINISH_STATE;
-      strm->msg = ERR_MSG(Z_MEM_ERROR);
-      deflateEnd (strm);
-      return Z_MEM_ERROR;
-   }
-   s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
-   s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
-
-   s->level = level;
-   s->strategy = strategy;
-   s->method = (Byte)method;
-
-   return deflateReset(strm);
-}
-
-/* ========================================================================= */
-int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
-{
-   deflate_state *s;
-   uInt str, n;
-   int wrap;
-   unsigned avail;
-   unsigned char *next;
-
-   if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
-      return Z_STREAM_ERROR;
-   s = (deflate_state*)strm->state;
-   wrap = s->wrap;
-   if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
-      return Z_STREAM_ERROR;
-
-   /* when using zlib wrappers, compute Adler-32 for provided dictionary */
-   if (wrap == 1)
-      strm->adler = adler32(strm->adler, dictionary, dictLength);
-   s->wrap = 0;                    /* avoid computing Adler-32 in read_buf */
-
-   /* if dictionary would fill window, just replace the history */
-   if (dictLength >= s->w_size) {
-      if (wrap == 0) {            /* already empty otherwise */
-         CLEAR_HASH(s);
-         s->strstart = 0;
-         s->block_start = 0L;
-         s->insert = 0;
-      }
-      dictionary += dictLength - s->w_size;  /* use the tail */
-      dictLength = s->w_size;
-   }
-
-   /* insert dictionary into window and hash */
-   avail = strm->avail_in;
-   next = strm->next_in;
-   strm->avail_in = dictLength;
-   strm->next_in = (Bytef *)dictionary;
-   fill_window(s);
-   while (s->lookahead >= MIN_MATCH) {
-      str = s->strstart;
-      n = s->lookahead - (MIN_MATCH-1);
-      do {
-         UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
-#ifndef FASTEST
-         s->prev[str & s->w_mask] = s->head[s->ins_h];
-#endif
-         s->head[s->ins_h] = (Pos)str;
-         str++;
-      } while (--n);
-      s->strstart = str;
-      s->lookahead = MIN_MATCH-1;
-      fill_window(s);
-   }
-   s->strstart += s->lookahead;
-   s->block_start = (long)s->strstart;
-   s->insert = s->lookahead;
-   s->lookahead = 0;
-   s->match_length = s->prev_length = MIN_MATCH-1;
-   s->match_available = 0;
-   strm->next_in = next;
-   strm->avail_in = avail;
-   s->wrap = wrap;
-   return Z_OK;
-}
-
-/* ========================================================================= */
-int ZEXPORT deflateResetKeep (z_streamp strm)
-{
-   deflate_state *s;
-
-   if (strm == Z_NULL || strm->state == Z_NULL ||
-         strm->zalloc == Z_NULL || strm->zfree == Z_NULL) {
-      return Z_STREAM_ERROR;
-   }
-
-   strm->total_in = strm->total_out = 0;
-   strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
-   strm->data_type = Z_UNKNOWN;
-
-   s = (deflate_state *)strm->state;
-   s->pending = 0;
-   s->pending_out = s->pending_buf;
-
-   if (s->wrap < 0) {
-      s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
-   }
-   s->status = s->wrap ? INIT_STATE : BUSY_STATE;
-   strm->adler =
-#ifdef GZIP
-      s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
-#endif
-      adler32(0L, Z_NULL, 0);
-   s->last_flush = Z_NO_FLUSH;
-
-   _tr_init(s);
-
-   return Z_OK;
-}
-
-/* ========================================================================= */
-int ZEXPORT deflateReset (z_streamp strm)
-{
-   int ret;
-
-   ret = deflateResetKeep(strm);
-   if (ret == Z_OK)
-      lm_init((deflate_state*)strm->state);
-   return ret;
-}
-
-/* ========================================================================= */
-int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
-{
-   struct internal_state_deflate *state = (struct internal_state_deflate*)strm->state;
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   if (state->wrap != 2)
-      return Z_STREAM_ERROR;
-   state->gzhead = head;
-   return Z_OK;
-}
-
-/* ========================================================================= */
-int ZEXPORT deflatePending (z_streamp strm, unsigned *pending, int *bits)
-{
-   struct internal_state_deflate *state = (struct internal_state_deflate*)strm->state;
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   if (pending != Z_NULL)
-      *pending = state->pending;
-   if (bits != Z_NULL)
-      *bits = state->bi_valid;
-   return Z_OK;
-}
-
-/* ========================================================================= */
-int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
-{
-   deflate_state *s;
-   int put;
-
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   s = (deflate_state*)strm->state;
-   if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
-      return Z_BUF_ERROR;
-   do {
-      put = Buf_size - s->bi_valid;
-      if (put > bits)
-         put = bits;
-      s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
-      s->bi_valid += put;
-      _tr_flush_bits(s);
-      value >>= put;
-      bits -= put;
-   } while (bits);
-   return Z_OK;
-}
-
-/* ========================================================================= */
-int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
-{
-   deflate_state *s;
-   compress_func func;
-   int err = Z_OK;
-
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   s = (deflate_state*)strm->state;
-
-#ifdef FASTEST
-   if (level != 0) level = 1;
-#else
-   if (level == Z_DEFAULT_COMPRESSION) level = 6;
-#endif
-   if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
-      return Z_STREAM_ERROR;
-   }
-   func = configuration_table[s->level].func;
-
-   if ((strategy != s->strategy || func != configuration_table[level].func) &&
-         strm->total_in != 0) {
-      /* Flush the last buffer: */
-      err = deflate(strm, Z_BLOCK);
-      if (err == Z_BUF_ERROR && s->pending == 0)
-         err = Z_OK;
-   }
-   if (s->level != level) {
-      s->level = level;
-      s->max_lazy_match   = configuration_table[level].max_lazy;
-      s->good_match       = configuration_table[level].good_length;
-      s->nice_match       = configuration_table[level].nice_length;
-      s->max_chain_length = configuration_table[level].max_chain;
-   }
-   s->strategy = strategy;
-   return err;
-}
-
-/* ========================================================================= */
-int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
-{
-   deflate_state *s;
-
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   s = (deflate_state*)strm->state;
-   s->good_match = good_length;
-   s->max_lazy_match = max_lazy;
-   s->nice_match = nice_length;
-   s->max_chain_length = max_chain;
-   return Z_OK;
-}
-
-/* =========================================================================
- * For the default windowBits of 15 and memLevel of 8, this function returns
- * a close to exact, as well as small, upper bound on the compressed size.
- * They are coded as constants here for a reason--if the #define's are
- * changed, then this function needs to be changed as well.  The return
- * value for 15 and 8 only works for those exact settings.
- *
- * For any setting other than those defaults for windowBits and memLevel,
- * the value returned is a conservative worst case for the maximum expansion
- * resulting from using fixed blocks instead of stored blocks, which deflate
- * can emit on compressed data for some combinations of the parameters.
- *
- * This function could be more sophisticated to provide closer upper bounds for
- * every combination of windowBits and memLevel.  But even the conservative
- * upper bound of about 14% expansion does not seem onerous for output buffer
- * allocation.
- */
-uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen)
-{
-   deflate_state *s;
-   uLong complen, wraplen;
-   Bytef *str;
-
-   /* conservative upper bound for compressed data */
-   complen = sourceLen +
-      ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
-
-   /* if can't get parameters, return conservative bound plus zlib wrapper */
-   if (strm == Z_NULL || strm->state == Z_NULL)
-      return complen + 6;
-
-   /* compute wrapper length */
-   s = (deflate_state*)strm->state;
-   switch (s->wrap) {
-      case 0:                                 /* raw deflate */
-         wraplen = 0;
-         break;
-      case 1:                                 /* zlib wrapper */
-         wraplen = 6 + (s->strstart ? 4 : 0);
-         break;
-      case 2:                                 /* gzip wrapper */
-         wraplen = 18;
-         if (s->gzhead != Z_NULL) {          /* user-supplied gzip header */
-            if (s->gzhead->extra != Z_NULL)
-               wraplen += 2 + s->gzhead->extra_len;
-            str = s->gzhead->name;
-            if (str != Z_NULL)
-               do {
-                  wraplen++;
-               } while (*str++);
-            str = s->gzhead->comment;
-            if (str != Z_NULL)
-               do {
-                  wraplen++;
-               } while (*str++);
-            if (s->gzhead->hcrc)
-               wraplen += 2;
-         }
-         break;
-      default:                                /* for compiler happiness */
-         wraplen = 6;
-   }
-
-   /* if not default parameters, return conservative bound */
-   if (s->w_bits != 15 || s->hash_bits != 8 + 7)
-      return complen + wraplen;
-
-   /* default settings: return tight bound for that case */
-   return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
-      (sourceLen >> 25) + 13 - 6 + wraplen;
-}
-
-/* =========================================================================
- * Put a short in the pending buffer. The 16-bit value is put in MSB order.
- * IN assertion: the stream state is correct and there is enough room in
- * pending_buf.
- */
-local void putShortMSB (deflate_state *s, uInt b)
-{
-   put_byte(s, (Byte)(b >> 8));
-   put_byte(s, (Byte)(b & 0xff));
-}
-
-/* =========================================================================
- * Flush as much pending output as possible. All deflate() output goes
- * through this function so some applications may wish to modify it
- * to avoid allocating a large strm->next_out buffer and copying into it.
- * (See also read_buf()).
- */
-local void flush_pending(z_streamp strm)
-{
-   unsigned len;
-   deflate_state *s = (deflate_state*)strm->state;
-
-   _tr_flush_bits(s);
-   len = s->pending;
-   if (len > strm->avail_out) len = strm->avail_out;
-   if (len == 0) return;
-
-   zmemcpy(strm->next_out, s->pending_out, len);
-   strm->next_out  += len;
-   s->pending_out  += len;
-   strm->total_out += len;
-   strm->avail_out  -= len;
-   s->pending -= len;
-   if (s->pending == 0) {
-      s->pending_out = s->pending_buf;
-   }
-}
-
-/* ========================================================================= */
-int ZEXPORT deflate (z_streamp strm, int flush)
-{
-   int old_flush; /* value of flush param for previous deflate call */
-   deflate_state *s;
-
-   if (strm == Z_NULL || strm->state == Z_NULL ||
-         flush > Z_BLOCK || flush < 0) {
-      return Z_STREAM_ERROR;
-   }
-   s = (deflate_state*)strm->state;
-
-   if (strm->next_out == Z_NULL ||
-         (strm->next_in == Z_NULL && strm->avail_in != 0) ||
-         (s->status == FINISH_STATE && flush != Z_FINISH)) {
-      ERR_RETURN(strm, Z_STREAM_ERROR);
-   }
-   if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
-
-   s->strm = strm; /* just in case */
-   old_flush = s->last_flush;
-   s->last_flush = flush;
-
-   /* Write the header */
-   if (s->status == INIT_STATE) {
-#ifdef GZIP
-      if (s->wrap == 2) {
-         strm->adler = crc32(0L, Z_NULL, 0);
-         put_byte(s, 31);
-         put_byte(s, 139);
-         put_byte(s, 8);
-         if (s->gzhead == Z_NULL) {
-            put_byte(s, 0);
-            put_byte(s, 0);
-            put_byte(s, 0);
-            put_byte(s, 0);
-            put_byte(s, 0);
-            put_byte(s, s->level == 9 ? 2 :
-                  (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
-                   4 : 0));
-            put_byte(s, OS_CODE);
-            s->status = BUSY_STATE;
-         }
-         else {
-            put_byte(s, (s->gzhead->text ? 1 : 0) +
-                  (s->gzhead->hcrc ? 2 : 0) +
-                  (s->gzhead->extra == Z_NULL ? 0 : 4) +
-                  (s->gzhead->name == Z_NULL ? 0 : 8) +
-                  (s->gzhead->comment == Z_NULL ? 0 : 16)
-                  );
-            put_byte(s, (Byte)(s->gzhead->time & 0xff));
-            put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
-            put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
-            put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
-            put_byte(s, s->level == 9 ? 2 :
-                  (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
-                   4 : 0));
-            put_byte(s, s->gzhead->os & 0xff);
-            if (s->gzhead->extra != Z_NULL) {
-               put_byte(s, s->gzhead->extra_len & 0xff);
-               put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
-            }
-            if (s->gzhead->hcrc)
-               strm->adler = crc32(strm->adler, s->pending_buf,
-                     s->pending);
-            s->gzindex = 0;
-            s->status = EXTRA_STATE;
-         }
-      }
-      else
-#endif
-      {
-         uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
-         uInt level_flags;
-
-         if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
-            level_flags = 0;
-         else if (s->level < 6)
-            level_flags = 1;
-         else if (s->level == 6)
-            level_flags = 2;
-         else
-            level_flags = 3;
-         header |= (level_flags << 6);
-         if (s->strstart != 0) header |= PRESET_DICT;
-         header += 31 - (header % 31);
-
-         s->status = BUSY_STATE;
-         putShortMSB(s, header);
-
-         /* Save the adler32 of the preset dictionary: */
-         if (s->strstart != 0) {
-            putShortMSB(s, (uInt)(strm->adler >> 16));
-            putShortMSB(s, (uInt)(strm->adler & 0xffff));
-         }
-         strm->adler = adler32(0L, Z_NULL, 0);
-      }
-   }
-#ifdef GZIP
-   if (s->status == EXTRA_STATE) {
-      if (s->gzhead->extra != Z_NULL) {
-         uInt beg = s->pending;  /* start of bytes to update crc */
-
-         while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
-            if (s->pending == s->pending_buf_size) {
-               if (s->gzhead->hcrc && s->pending > beg)
-                  strm->adler = crc32(strm->adler, s->pending_buf + beg,
-                        s->pending - beg);
-               flush_pending(strm);
-               beg = s->pending;
-               if (s->pending == s->pending_buf_size)
-                  break;
-            }
-            put_byte(s, s->gzhead->extra[s->gzindex]);
-            s->gzindex++;
-         }
-         if (s->gzhead->hcrc && s->pending > beg)
-            strm->adler = crc32(strm->adler, s->pending_buf + beg,
-                  s->pending - beg);
-         if (s->gzindex == s->gzhead->extra_len) {
-            s->gzindex = 0;
-            s->status = NAME_STATE;
-         }
-      }
-      else
-         s->status = NAME_STATE;
-   }
-   if (s->status == NAME_STATE) {
-      if (s->gzhead->name != Z_NULL) {
-         uInt beg = s->pending;  /* start of bytes to update crc */
-         int val;
-
-         do {
-            if (s->pending == s->pending_buf_size) {
-               if (s->gzhead->hcrc && s->pending > beg)
-                  strm->adler = crc32(strm->adler, s->pending_buf + beg,
-                        s->pending - beg);
-               flush_pending(strm);
-               beg = s->pending;
-               if (s->pending == s->pending_buf_size) {
-                  val = 1;
-                  break;
-               }
-            }
-            val = s->gzhead->name[s->gzindex++];
-            put_byte(s, val);
-         } while (val != 0);
-         if (s->gzhead->hcrc && s->pending > beg)
-            strm->adler = crc32(strm->adler, s->pending_buf + beg,
-                  s->pending - beg);
-         if (val == 0) {
-            s->gzindex = 0;
-            s->status = COMMENT_STATE;
-         }
-      }
-      else
-         s->status = COMMENT_STATE;
-   }
-   if (s->status == COMMENT_STATE) {
-      if (s->gzhead->comment != Z_NULL) {
-         uInt beg = s->pending;  /* start of bytes to update crc */
-         int val;
-
-         do {
-            if (s->pending == s->pending_buf_size) {
-               if (s->gzhead->hcrc && s->pending > beg)
-                  strm->adler = crc32(strm->adler, s->pending_buf + beg,
-                        s->pending - beg);
-               flush_pending(strm);
-               beg = s->pending;
-               if (s->pending == s->pending_buf_size) {
-                  val = 1;
-                  break;
-               }
-            }
-            val = s->gzhead->comment[s->gzindex++];
-            put_byte(s, val);
-         } while (val != 0);
-         if (s->gzhead->hcrc && s->pending > beg)
-            strm->adler = crc32(strm->adler, s->pending_buf + beg,
-                  s->pending - beg);
-         if (val == 0)
-            s->status = HCRC_STATE;
-      }
-      else
-         s->status = HCRC_STATE;
-   }
-   if (s->status == HCRC_STATE) {
-      if (s->gzhead->hcrc) {
-         if (s->pending + 2 > s->pending_buf_size)
-            flush_pending(strm);
-         if (s->pending + 2 <= s->pending_buf_size) {
-            put_byte(s, (Byte)(strm->adler & 0xff));
-            put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
-            strm->adler = crc32(0L, Z_NULL, 0);
-            s->status = BUSY_STATE;
-         }
-      }
-      else
-         s->status = BUSY_STATE;
-   }
-#endif
-
-   /* Flush as much pending output as possible */
-   if (s->pending != 0) {
-      flush_pending(strm);
-      if (strm->avail_out == 0) {
-         /* Since avail_out is 0, deflate will be called again with
-          * more output space, but possibly with both pending and
-          * avail_in equal to zero. There won't be anything to do,
-          * but this is not an error situation so make sure we
-          * return OK instead of BUF_ERROR at next call of deflate:
-          */
-         s->last_flush = -1;
-         return Z_OK;
-      }
-
-      /* Make sure there is something to do and avoid duplicate consecutive
-       * flushes. For repeated and useless calls with Z_FINISH, we keep
-       * returning Z_STREAM_END instead of Z_BUF_ERROR.
-       */
-   } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
-         flush != Z_FINISH) {
-      ERR_RETURN(strm, Z_BUF_ERROR);
-   }
-
-   /* User must not provide more input after the first FINISH: */
-   if (s->status == FINISH_STATE && strm->avail_in != 0) {
-      ERR_RETURN(strm, Z_BUF_ERROR);
-   }
-
-   /* Start a new block or continue the current one.
-   */
-   if (strm->avail_in != 0 || s->lookahead != 0 ||
-         (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
-      block_state bstate;
-
-      bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
-         (s->strategy == Z_RLE ? deflate_rle(s, flush) :
-          (*(configuration_table[s->level].func))(s, flush));
-
-      if (bstate == finish_started || bstate == finish_done) {
-         s->status = FINISH_STATE;
-      }
-      if (bstate == need_more || bstate == finish_started) {
-         if (strm->avail_out == 0) {
-            s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
-         }
-         return Z_OK;
-         /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
-          * of deflate should use the same flush parameter to make sure
-          * that the flush is complete. So we don't have to output an
-          * empty block here, this will be done at next call. This also
-          * ensures that for a very small output buffer, we emit at most
-          * one empty block.
-          */
-      }
-      if (bstate == block_done) {
-         if (flush == Z_PARTIAL_FLUSH) {
-            _tr_align(s);
-         } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
-            _tr_stored_block(s, (char*)0, 0L, 0);
-            /* For a full flush, this empty block will be recognized
-             * as a special marker by inflate_sync().
-             */
-            if (flush == Z_FULL_FLUSH) {
-               CLEAR_HASH(s);             /* forget history */
-               if (s->lookahead == 0) {
-                  s->strstart = 0;
-                  s->block_start = 0L;
-                  s->insert = 0;
-               }
-            }
-         }
-         flush_pending(strm);
-         if (strm->avail_out == 0) {
-            s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
-            return Z_OK;
-         }
-      }
-   }
-   Assert(strm->avail_out > 0, "bug2");
-
-   if (flush != Z_FINISH) return Z_OK;
-   if (s->wrap <= 0) return Z_STREAM_END;
-
-   /* Write the trailer */
-#ifdef GZIP
-   if (s->wrap == 2) {
-      put_byte(s, (Byte)(strm->adler & 0xff));
-      put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
-      put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
-      put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
-      put_byte(s, (Byte)(strm->total_in & 0xff));
-      put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
-      put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
-      put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
-   }
-   else
-#endif
-   {
-      putShortMSB(s, (uInt)(strm->adler >> 16));
-      putShortMSB(s, (uInt)(strm->adler & 0xffff));
-   }
-   flush_pending(strm);
-   /* If avail_out is zero, the application will call deflate again
-    * to flush the rest.
-    */
-   if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
-   return s->pending != 0 ? Z_OK : Z_STREAM_END;
-}
-
-/* ========================================================================= */
-int ZEXPORT deflateEnd (z_streamp strm)
-{
-   struct internal_state_deflate *state;
-   int status;
-
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   state = (struct internal_state_deflate*)strm->state;
-
-   status = state->status;
-   if (status != INIT_STATE &&
-         status != EXTRA_STATE &&
-         status != NAME_STATE &&
-         status != COMMENT_STATE &&
-         status != HCRC_STATE &&
-         status != BUSY_STATE &&
-         status != FINISH_STATE) {
-      return Z_STREAM_ERROR;
-   }
-
-   /* Deallocate in reverse order of allocations: */
-   TRY_FREE(strm, state->pending_buf);
-   TRY_FREE(strm, state->head);
-   TRY_FREE(strm, state->prev);
-   TRY_FREE(strm, state->window);
-
-   ZFREE(strm, state);
-   state = Z_NULL;
-
-   return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
-}
-
-/* =========================================================================
- * Copy the source state to the destination state.
- * To simplify the source, this is not supported for 16-bit MSDOS (which
- * doesn't have enough memory anyway to duplicate compression states).
- */
-int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
-{
-#ifdef MAXSEG_64K
-   return Z_STREAM_ERROR;
-#else
-   deflate_state *ds;
-   deflate_state *ss;
-   ushf *overlay;
-
-
-   if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
-      return Z_STREAM_ERROR;
-   }
-
-   ss = (deflate_state*)source->state;
-
-   zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
-
-   ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
-   if (ds == Z_NULL) return Z_MEM_ERROR;
-   dest->state = (struct internal_state FAR *) ds;
-   zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
-   ds->strm = dest;
-
-   ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
-   ds->prev   = (Posf *)  ZALLOC(dest, ds->w_size, sizeof(Pos));
-   ds->head   = (Posf *)  ZALLOC(dest, ds->hash_size, sizeof(Pos));
-   overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
-   ds->pending_buf = (uchf *) overlay;
-
-   if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
-         ds->pending_buf == Z_NULL) {
-      deflateEnd (dest);
-      return Z_MEM_ERROR;
-   }
-   /* following zmemcpy do not work for 16-bit MSDOS */
-   zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
-   zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
-   zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
-   zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
-
-   ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
-   ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
-   ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
-
-   ds->l_desc.dyn_tree = ds->dyn_ltree;
-   ds->d_desc.dyn_tree = ds->dyn_dtree;
-   ds->bl_desc.dyn_tree = ds->bl_tree;
-
-   return Z_OK;
-#endif /* MAXSEG_64K */
-}
-
-/* ===========================================================================
- * Read a new buffer from the current input stream, update the adler32
- * and total number of bytes read.  All deflate() input goes through
- * this function so some applications may wish to modify it to avoid
- * allocating a large strm->next_in buffer and copying from it.
- * (See also flush_pending()).
- */
-local int read_buf(z_streamp strm, Bytef *buf, unsigned size)
-{
-   struct internal_state_deflate *state = (struct internal_state_deflate*)strm->state;
-   unsigned len = strm->avail_in;
-
-   if (len > size) len = size;
-   if (len == 0) return 0;
-
-   strm->avail_in  -= len;
-
-   zmemcpy(buf, strm->next_in, len);
-   if (state->wrap == 1) {
-      strm->adler = adler32(strm->adler, buf, len);
-   }
-#ifdef GZIP
-   else if (state->wrap == 2) {
-      strm->adler = crc32(strm->adler, buf, len);
-   }
-#endif
-   strm->next_in  += len;
-   strm->total_in += len;
-
-   return (int)len;
-}
-
-/* ===========================================================================
- * Initialize the "longest match" routines for a new zlib stream
- */
-local void lm_init (deflate_state *s)
-{
-   s->window_size = (ulg)2L*s->w_size;
-
-   CLEAR_HASH(s);
-
-   /* Set the default configuration parameters:
-   */
-   s->max_lazy_match   = configuration_table[s->level].max_lazy;
-   s->good_match       = configuration_table[s->level].good_length;
-   s->nice_match       = configuration_table[s->level].nice_length;
-   s->max_chain_length = configuration_table[s->level].max_chain;
-
-   s->strstart = 0;
-   s->block_start = 0L;
-   s->lookahead = 0;
-   s->insert = 0;
-   s->match_length = s->prev_length = MIN_MATCH-1;
-   s->match_available = 0;
-   s->ins_h = 0;
-#ifndef FASTEST
-#ifdef ASMV
-   match_init(); /* initialize the asm code */
-#endif
-#endif
-}
-
-#ifndef FASTEST
-/* ===========================================================================
- * Set match_start to the longest match starting at the given string and
- * return its length. Matches shorter or equal to prev_length are discarded,
- * in which case the result is equal to prev_length and match_start is
- * garbage.
- * IN assertions: cur_match is the head of the hash chain for the current
- *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
- * OUT assertion: the match length is not greater than s->lookahead.
- */
-#ifndef ASMV
-/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
- * match.S. The code will be functionally equivalent.
- */
-local uInt longest_match(deflate_state *s, IPos cur_match)
-{
-   unsigned chain_length = s->max_chain_length;/* max hash chain length */
-   register Bytef *scan = s->window + s->strstart; /* current string */
-   register Bytef *match;                       /* matched string */
-   register int len;                           /* length of current match */
-   int best_len = s->prev_length;              /* best match length so far */
-   int nice_match = s->nice_match;             /* stop if match long enough */
-   IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
-      s->strstart - (IPos)MAX_DIST(s) : NIL;
-   /* Stop when cur_match becomes <= limit. To simplify the code,
-    * we prevent matches with the string of window index 0.
-    */
-   Posf *prev = s->prev;
-   uInt wmask = s->w_mask;
-
-#ifdef UNALIGNED_OK
-   /* Compare two bytes at a time. Note: this is not always beneficial.
-    * Try with and without -DUNALIGNED_OK to check.
-    */
-   register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
-   register ush scan_start = *(ushf*)scan;
-   register ush scan_end   = *(ushf*)(scan+best_len-1);
-#else
-   register Bytef *strend = s->window + s->strstart + MAX_MATCH;
-   register Byte scan_end1  = scan[best_len-1];
-   register Byte scan_end   = scan[best_len];
-#endif
-
-   /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
-    * It is easy to get rid of this optimization if necessary.
-    */
-   Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
-
-   /* Do not waste too much time if we already have a good match: */
-   if (s->prev_length >= s->good_match) {
-      chain_length >>= 2;
-   }
-   /* Do not look for matches beyond the end of the input. This is necessary
-    * to make deflate deterministic.
-    */
-   if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
-
-   Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
-
-   do {
-      Assert(cur_match < s->strstart, "no future");
-      match = s->window + cur_match;
-
-      /* Skip to next match if the match length cannot increase
-       * or if the match length is less than 2.  Note that the checks below
-       * for insufficient lookahead only occur occasionally for performance
-       * reasons.  Therefore uninitialized memory will be accessed, and
-       * conditional jumps will be made that depend on those values.
-       * However the length of the match is limited to the lookahead, so
-       * the output of deflate is not affected by the uninitialized values.
-       */
-#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
-      /* This code assumes sizeof(unsigned short) == 2. Do not use
-       * UNALIGNED_OK if your compiler uses a different size.
-       */
-      if (*(ushf*)(match+best_len-1) != scan_end ||
-            *(ushf*)match != scan_start) continue;
-
-      /* It is not necessary to compare scan[2] and match[2] since they are
-       * always equal when the other bytes match, given that the hash keys
-       * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
-       * strstart+3, +5, ... up to strstart+257. We check for insufficient
-       * lookahead only every 4th comparison; the 128th check will be made
-       * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
-       * necessary to put more guard bytes at the end of the window, or
-       * to check more often for insufficient lookahead.
-       */
-      Assert(scan[2] == match[2], "scan[2]?");
-      scan++, match++;
-      do {
-      } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-            *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-            *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-            *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-            scan < strend);
-      /* The funny "do {}" generates better code on most compilers */
-
-      /* Here, scan <= window+strstart+257 */
-      Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-      if (*scan == *match) scan++;
-
-      len = (MAX_MATCH - 1) - (int)(strend-scan);
-      scan = strend - (MAX_MATCH-1);
-
-#else /* UNALIGNED_OK */
-
-      if (match[best_len]   != scan_end  ||
-            match[best_len-1] != scan_end1 ||
-            *match            != *scan     ||
-            *++match          != scan[1])      continue;
-
-      /* The check at best_len-1 can be removed because it will be made
-       * again later. (This heuristic is not always a win.)
-       * It is not necessary to compare scan[2] and match[2] since they
-       * are always equal when the other bytes match, given that
-       * the hash keys are equal and that HASH_BITS >= 8.
-       */
-      scan += 2, match++;
-      Assert(*scan == *match, "match[2]?");
-
-      /* We check for insufficient lookahead only every 8th comparison;
-       * the 256th check will be made at strstart+258.
-       */
-      do {
-      } while (*++scan == *++match && *++scan == *++match &&
-            *++scan == *++match && *++scan == *++match &&
-            *++scan == *++match && *++scan == *++match &&
-            *++scan == *++match && *++scan == *++match &&
-            scan < strend);
-
-      Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-
-      len = MAX_MATCH - (int)(strend - scan);
-      scan = strend - MAX_MATCH;
-
-#endif /* UNALIGNED_OK */
-
-      if (len > best_len) {
-         s->match_start = cur_match;
-         best_len = len;
-         if (len >= nice_match) break;
-#ifdef UNALIGNED_OK
-         scan_end = *(ushf*)(scan+best_len-1);
-#else
-         scan_end1  = scan[best_len-1];
-         scan_end   = scan[best_len];
-#endif
-      }
-   } while ((cur_match = prev[cur_match & wmask]) > limit
-         && --chain_length != 0);
-
-   if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
-   return s->lookahead;
-}
-#endif /* ASMV */
-
-#else /* FASTEST */
-
-/* ---------------------------------------------------------------------------
- * Optimized version for FASTEST only
- */
-local uInt longest_match(s, cur_match)
-   deflate_state *s;
-   IPos cur_match;                             /* current match */
-{
-   register Bytef *scan = s->window + s->strstart; /* current string */
-   register Bytef *match;                       /* matched string */
-   register int len;                           /* length of current match */
-   register Bytef *strend = s->window + s->strstart + MAX_MATCH;
-
-   /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
-    * It is easy to get rid of this optimization if necessary.
-    */
-   Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
-
-   Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
-
-   Assert(cur_match < s->strstart, "no future");
-
-   match = s->window + cur_match;
-
-   /* Return failure if the match length is less than 2:
-   */
-   if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
-
-   /* The check at best_len-1 can be removed because it will be made
-    * again later. (This heuristic is not always a win.)
-    * It is not necessary to compare scan[2] and match[2] since they
-    * are always equal when the other bytes match, given that
-    * the hash keys are equal and that HASH_BITS >= 8.
-    */
-   scan += 2, match += 2;
-   Assert(*scan == *match, "match[2]?");
-
-   /* We check for insufficient lookahead only every 8th comparison;
-    * the 256th check will be made at strstart+258.
-    */
-   do {
-   } while (*++scan == *++match && *++scan == *++match &&
-         *++scan == *++match && *++scan == *++match &&
-         *++scan == *++match && *++scan == *++match &&
-         *++scan == *++match && *++scan == *++match &&
-         scan < strend);
-
-   Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-
-   len = MAX_MATCH - (int)(strend - scan);
-
-   if (len < MIN_MATCH) return MIN_MATCH - 1;
-
-   s->match_start = cur_match;
-   return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
-}
-
-#endif /* FASTEST */
-
-#ifdef DEBUG
-/* ===========================================================================
- * Check that the match at match_start is indeed a match.
- */
-local void check_match(s, start, match, length)
-   deflate_state *s;
-   IPos start, match;
-   int length;
-{
-   /* check that the match is indeed a match */
-   if (zmemcmp(s->window + match,
-            s->window + start, length) != EQUAL) {
-      fprintf(stderr, " start %u, match %u, length %d\n",
-            start, match, length);
-      do {
-         fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
-      } while (--length != 0);
-      z_error("invalid match");
-   }
-   if (z_verbose > 1) {
-      fprintf(stderr,"\\[%d,%d]", start-match, length);
-      do { putc(s->window[start++], stderr); } while (--length != 0);
-   }
-}
-#else
-#  define check_match(s, start, match, length)
-#endif /* DEBUG */
-
-/* ===========================================================================
- * Fill the window when the lookahead becomes insufficient.
- * Updates strstart and lookahead.
- *
- * IN assertion: lookahead < MIN_LOOKAHEAD
- * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
- *    At least one byte has been read, or avail_in == 0; reads are
- *    performed for at least two bytes (required for the zip translate_eol
- *    option -- not supported here).
- */
-local void fill_window(deflate_state *s)
-{
-   register unsigned n, m;
-   register Posf *p;
-   unsigned more;    /* Amount of free space at the end of the window. */
-   uInt wsize = s->w_size;
-
-   Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
-
-   do {
-      more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
-
-      /* Deal with !@#$% 64K limit: */
-      if (sizeof(int) <= 2) {
-         if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
-            more = wsize;
-
-         } else if (more == (unsigned)(-1)) {
-            /* Very unlikely, but possible on 16 bit machine if
-             * strstart == 0 && lookahead == 1 (input done a byte at time)
-             */
-            more--;
-         }
-      }
-
-      /* If the window is almost full and there is insufficient lookahead,
-       * move the upper half to the lower one to make room in the upper half.
-       */
-      if (s->strstart >= wsize+MAX_DIST(s)) {
-
-         zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
-         s->match_start -= wsize;
-         s->strstart    -= wsize; /* we now have strstart >= MAX_DIST */
-         s->block_start -= (long) wsize;
-
-         /* Slide the hash table (could be avoided with 32 bit values
-            at the expense of memory usage). We slide even when level == 0
-            to keep the hash table consistent if we switch back to level > 0
-            later. (Using level 0 permanently is not an optimal usage of
-            zlib, so we don't care about this pathological case.)
-            */
-         n = s->hash_size;
-         p = &s->head[n];
-         do {
-            m = *--p;
-            *p = (Pos)(m >= wsize ? m-wsize : NIL);
-         } while (--n);
-
-         n = wsize;
-#ifndef FASTEST
-         p = &s->prev[n];
-         do {
-            m = *--p;
-            *p = (Pos)(m >= wsize ? m-wsize : NIL);
-            /* If n is not on any hash chain, prev[n] is garbage but
-             * its value will never be used.
-             */
-         } while (--n);
-#endif
-         more += wsize;
-      }
-      if (s->strm->avail_in == 0) break;
-
-      /* If there was no sliding:
-       *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
-       *    more == window_size - lookahead - strstart
-       * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
-       * => more >= window_size - 2*WSIZE + 2
-       * In the BIG_MEM or MMAP case (not yet supported),
-       *   window_size == input_size + MIN_LOOKAHEAD  &&
-       *   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
-       * Otherwise, window_size == 2*WSIZE so more >= 2.
-       * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
-       */
-      Assert(more >= 2, "more < 2");
-
-      n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
-      s->lookahead += n;
-
-      /* Initialize the hash value now that we have some input: */
-      if (s->lookahead + s->insert >= MIN_MATCH) {
-         uInt str = s->strstart - s->insert;
-         s->ins_h = s->window[str];
-         UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
-#if MIN_MATCH != 3
-         Call UPDATE_HASH() MIN_MATCH-3 more times
-#endif
-            while (s->insert) {
-               UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
-#ifndef FASTEST
-               s->prev[str & s->w_mask] = s->head[s->ins_h];
-#endif
-               s->head[s->ins_h] = (Pos)str;
-               str++;
-               s->insert--;
-               if (s->lookahead + s->insert < MIN_MATCH)
-                  break;
-            }
-      }
-      /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
-       * but this is not important since only literal bytes will be emitted.
-       */
-
-   } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
-
-   /* If the WIN_INIT bytes after the end of the current data have never been
-    * written, then zero those bytes in order to avoid memory check reports of
-    * the use of uninitialized (or uninitialised as Julian writes) bytes by
-    * the longest match routines.  Update the high water mark for the next
-    * time through here.  WIN_INIT is set to MAX_MATCH since the longest match
-    * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
-    */
-   if (s->high_water < s->window_size) {
-      ulg curr = s->strstart + (ulg)(s->lookahead);
-      ulg init;
-
-      if (s->high_water < curr) {
-         /* Previous high water mark below current data -- zero WIN_INIT
-          * bytes or up to end of window, whichever is less.
-          */
-         init = s->window_size - curr;
-         if (init > WIN_INIT)
-            init = WIN_INIT;
-         zmemzero(s->window + curr, (unsigned)init);
-         s->high_water = curr + init;
-      }
-      else if (s->high_water < (ulg)curr + WIN_INIT) {
-         /* High water mark at or above current data, but below current data
-          * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
-          * to end of window, whichever is less.
-          */
-         init = (ulg)curr + WIN_INIT - s->high_water;
-         if (init > s->window_size - s->high_water)
-            init = s->window_size - s->high_water;
-         zmemzero(s->window + s->high_water, (unsigned)init);
-         s->high_water += init;
-      }
-   }
-
-   Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
-         "not enough room for search");
-}
-
-/* ===========================================================================
- * Flush the current block, with given end-of-file flag.
- * IN assertion: strstart is set to the end of the current match.
- */
-#define FLUSH_BLOCK_ONLY(s, last) { \
-   _tr_flush_block(s, (s->block_start >= 0L ? \
-            (charf *)&s->window[(unsigned)s->block_start] : \
-            (charf *)Z_NULL), \
-         (ulg)((long)s->strstart - s->block_start), \
-         (last)); \
-   s->block_start = s->strstart; \
-   flush_pending(s->strm); \
-   Tracev((stderr,"[FLUSH]")); \
-}
-
-/* Same but force premature exit if necessary. */
-#define FLUSH_BLOCK(s, last) { \
-   FLUSH_BLOCK_ONLY(s, last); \
-   if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
-}
-
-/* ===========================================================================
- * Copy without compression as much as possible from the input stream, return
- * the current block state.
- * This function does not insert new strings in the dictionary since
- * uncompressible data is probably not useful. This function is used
- * only for the level=0 compression option.
- * NOTE: this function should be optimized to avoid extra copying from
- * window to pending_buf.
- */
-local block_state deflate_stored(deflate_state *s, int flush)
-{
-   /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
-    * to pending_buf_size, and each stored block has a 5 byte header:
-    */
-   ulg max_block_size = 0xffff;
-   ulg max_start;
-
-   if (max_block_size > s->pending_buf_size - 5) {
-      max_block_size = s->pending_buf_size - 5;
-   }
-
-   /* Copy as much as possible from input to output: */
-   for (;;) {
-      /* Fill the window as much as possible: */
-      if (s->lookahead <= 1) {
-
-         Assert(s->strstart < s->w_size+MAX_DIST(s) ||
-               s->block_start >= (long)s->w_size, "slide too late");
-
-         fill_window(s);
-         if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
-
-         if (s->lookahead == 0) break; /* flush the current block */
-      }
-      Assert(s->block_start >= 0L, "block gone");
-
-      s->strstart += s->lookahead;
-      s->lookahead = 0;
-
-      /* Emit a stored block if pending_buf will be full: */
-      max_start = s->block_start + max_block_size;
-      if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
-         /* strstart == 0 is possible when wraparound on 16-bit machine */
-         s->lookahead = (uInt)(s->strstart - max_start);
-         s->strstart = (uInt)max_start;
-         FLUSH_BLOCK(s, 0);
-      }
-      /* Flush if we may have to slide, otherwise block_start may become
-       * negative and the data will be gone:
-       */
-      if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
-         FLUSH_BLOCK(s, 0);
-      }
-   }
-   s->insert = 0;
-   if (flush == Z_FINISH) {
-      FLUSH_BLOCK(s, 1);
-      return finish_done;
-   }
-   if ((long)s->strstart > s->block_start)
-      FLUSH_BLOCK(s, 0);
-   return block_done;
-}
-
-/* ===========================================================================
- * Compress as much as possible from the input stream, return the current
- * block state.
- * This function does not perform lazy evaluation of matches and inserts
- * new strings in the dictionary only for unmatched strings or for short
- * matches. It is used only for the fast compression options.
- */
-local block_state deflate_fast(deflate_state *s, int flush)
-{
-   IPos hash_head;       /* head of the hash chain */
-   int bflush;           /* set if current block must be flushed */
-
-   for (;;) {
-      /* Make sure that we always have enough lookahead, except
-       * at the end of the input file. We need MAX_MATCH bytes
-       * for the next match, plus MIN_MATCH bytes to insert the
-       * string following the next match.
-       */
-      if (s->lookahead < MIN_LOOKAHEAD) {
-         fill_window(s);
-         if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
-            return need_more;
-         }
-         if (s->lookahead == 0) break; /* flush the current block */
-      }
-
-      /* Insert the string window[strstart .. strstart+2] in the
-       * dictionary, and set hash_head to the head of the hash chain:
-       */
-      hash_head = NIL;
-      if (s->lookahead >= MIN_MATCH) {
-         INSERT_STRING(s, s->strstart, hash_head);
-      }
-
-      /* Find the longest match, discarding those <= prev_length.
-       * At this point we have always match_length < MIN_MATCH
-       */
-      if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
-         /* To simplify the code, we prevent matches with the string
-          * of window index 0 (in particular we have to avoid a match
-          * of the string with itself at the start of the input file).
-          */
-         s->match_length = longest_match (s, hash_head);
-         /* longest_match() sets match_start */
-      }
-      if (s->match_length >= MIN_MATCH) {
-         check_match(s, s->strstart, s->match_start, s->match_length);
-
-         _tr_tally_dist(s, s->strstart - s->match_start,
-               s->match_length - MIN_MATCH, bflush);
-
-         s->lookahead -= s->match_length;
-
-         /* Insert new strings in the hash table only if the match length
-          * is not too large. This saves time but degrades compression.
-          */
-#ifndef FASTEST
-         if (s->match_length <= s->max_insert_length &&
-               s->lookahead >= MIN_MATCH) {
-            s->match_length--; /* string at strstart already in table */
-            do {
-               s->strstart++;
-               INSERT_STRING(s, s->strstart, hash_head);
-               /* strstart never exceeds WSIZE-MAX_MATCH, so there are
-                * always MIN_MATCH bytes ahead.
-                */
-            } while (--s->match_length != 0);
-            s->strstart++;
-         } else
-#endif
-         {
-            s->strstart += s->match_length;
-            s->match_length = 0;
-            s->ins_h = s->window[s->strstart];
-            UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
-#if MIN_MATCH != 3
-            Call UPDATE_HASH() MIN_MATCH-3 more times
-#endif
-               /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
-                * matter since it will be recomputed at next deflate call.
-                */
-         }
-      } else {
-         /* No match, output a literal byte */
-         Tracevv((stderr,"%c", s->window[s->strstart]));
-         _tr_tally_lit (s, s->window[s->strstart], bflush);
-         s->lookahead--;
-         s->strstart++;
-      }
-      if (bflush) FLUSH_BLOCK(s, 0);
-   }
-   s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
-   if (flush == Z_FINISH) {
-      FLUSH_BLOCK(s, 1);
-      return finish_done;
-   }
-   if (s->last_lit)
-      FLUSH_BLOCK(s, 0);
-   return block_done;
-}
-
-#ifndef FASTEST
-/* ===========================================================================
- * Same as above, but achieves better compression. We use a lazy
- * evaluation for matches: a match is finally adopted only if there is
- * no better match at the next window position.
- */
-local block_state deflate_slow(deflate_state *s, int flush)
-{
-   IPos hash_head;          /* head of hash chain */
-   int bflush;              /* set if current block must be flushed */
-
-   /* Process the input block. */
-   for (;;) {
-      /* Make sure that we always have enough lookahead, except
-       * at the end of the input file. We need MAX_MATCH bytes
-       * for the next match, plus MIN_MATCH bytes to insert the
-       * string following the next match.
-       */
-      if (s->lookahead < MIN_LOOKAHEAD) {
-         fill_window(s);
-         if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
-            return need_more;
-         }
-         if (s->lookahead == 0) break; /* flush the current block */
-      }
-
-      /* Insert the string window[strstart .. strstart+2] in the
-       * dictionary, and set hash_head to the head of the hash chain:
-       */
-      hash_head = NIL;
-      if (s->lookahead >= MIN_MATCH) {
-         INSERT_STRING(s, s->strstart, hash_head);
-      }
-
-      /* Find the longest match, discarding those <= prev_length.
-      */
-      s->prev_length = s->match_length, s->prev_match = s->match_start;
-      s->match_length = MIN_MATCH-1;
-
-      if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
-            s->strstart - hash_head <= MAX_DIST(s)) {
-         /* To simplify the code, we prevent matches with the string
-          * of window index 0 (in particular we have to avoid a match
-          * of the string with itself at the start of the input file).
-          */
-         s->match_length = longest_match (s, hash_head);
-         /* longest_match() sets match_start */
-
-         if (s->match_length <= 5 && (s->strategy == Z_FILTERED
-#if TOO_FAR <= 32767
-                  || (s->match_length == MIN_MATCH &&
-                     s->strstart - s->match_start > TOO_FAR)
-#endif
-                  )) {
-
-            /* If prev_match is also MIN_MATCH, match_start is garbage
-             * but we will ignore the current match anyway.
-             */
-            s->match_length = MIN_MATCH-1;
-         }
-      }
-      /* If there was a match at the previous step and the current
-       * match is not better, output the previous match:
-       */
-      if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
-         uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
-         /* Do not insert strings in hash table beyond this. */
-
-         check_match(s, s->strstart-1, s->prev_match, s->prev_length);
-
-         _tr_tally_dist(s, s->strstart -1 - s->prev_match,
-               s->prev_length - MIN_MATCH, bflush);
-
-         /* Insert in hash table all strings up to the end of the match.
-          * strstart-1 and strstart are already inserted. If there is not
-          * enough lookahead, the last two strings are not inserted in
-          * the hash table.
-          */
-         s->lookahead -= s->prev_length-1;
-         s->prev_length -= 2;
-         do {
-            if (++s->strstart <= max_insert) {
-               INSERT_STRING(s, s->strstart, hash_head);
-            }
-         } while (--s->prev_length != 0);
-         s->match_available = 0;
-         s->match_length = MIN_MATCH-1;
-         s->strstart++;
-
-         if (bflush) FLUSH_BLOCK(s, 0);
-
-      } else if (s->match_available) {
-         /* If there was no match at the previous position, output a
-          * single literal. If there was a match but the current match
-          * is longer, truncate the previous match to a single literal.
-          */
-         Tracevv((stderr,"%c", s->window[s->strstart-1]));
-         _tr_tally_lit(s, s->window[s->strstart-1], bflush);
-         if (bflush) {
-            FLUSH_BLOCK_ONLY(s, 0);
-         }
-         s->strstart++;
-         s->lookahead--;
-         if (s->strm->avail_out == 0) return need_more;
-      } else {
-         /* There is no previous match to compare with, wait for
-          * the next step to decide.
-          */
-         s->match_available = 1;
-         s->strstart++;
-         s->lookahead--;
-      }
-   }
-   Assert (flush != Z_NO_FLUSH, "no flush?");
-   if (s->match_available) {
-      Tracevv((stderr,"%c", s->window[s->strstart-1]));
-      _tr_tally_lit(s, s->window[s->strstart-1], bflush);
-      s->match_available = 0;
-   }
-   s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
-   if (flush == Z_FINISH) {
-      FLUSH_BLOCK(s, 1);
-      return finish_done;
-   }
-   if (s->last_lit)
-      FLUSH_BLOCK(s, 0);
-   return block_done;
-}
-#endif /* FASTEST */
-
-/* ===========================================================================
- * For Z_RLE, simply look for runs of bytes, generate matches only of distance
- * one.  Do not maintain a hash table.  (It will be regenerated if this run of
- * deflate switches away from Z_RLE.)
- */
-local block_state deflate_rle(deflate_state *s, int flush)
-{
-   int bflush;             /* set if current block must be flushed */
-   uInt prev;              /* byte at distance one to match */
-   Bytef *scan, *strend;   /* scan goes up to strend for length of run */
-
-   for (;;) {
-      /* Make sure that we always have enough lookahead, except
-       * at the end of the input file. We need MAX_MATCH bytes
-       * for the longest run, plus one for the unrolled loop.
-       */
-      if (s->lookahead <= MAX_MATCH) {
-         fill_window(s);
-         if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
-            return need_more;
-         }
-         if (s->lookahead == 0) break; /* flush the current block */
-      }
-
-      /* See how many times the previous byte repeats */
-      s->match_length = 0;
-      if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
-         scan = s->window + s->strstart - 1;
-         prev = *scan;
-         if (prev == *++scan && prev == *++scan && prev == *++scan) {
-            strend = s->window + s->strstart + MAX_MATCH;
-            do {
-            } while (prev == *++scan && prev == *++scan &&
-                  prev == *++scan && prev == *++scan &&
-                  prev == *++scan && prev == *++scan &&
-                  prev == *++scan && prev == *++scan &&
-                  scan < strend);
-            s->match_length = MAX_MATCH - (int)(strend - scan);
-            if (s->match_length > s->lookahead)
-               s->match_length = s->lookahead;
-         }
-         Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
-      }
-
-      /* Emit match if have run of MIN_MATCH or longer, else emit literal */
-      if (s->match_length >= MIN_MATCH) {
-         check_match(s, s->strstart, s->strstart - 1, s->match_length);
-
-         _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
-
-         s->lookahead -= s->match_length;
-         s->strstart += s->match_length;
-         s->match_length = 0;
-      } else {
-         /* No match, output a literal byte */
-         Tracevv((stderr,"%c", s->window[s->strstart]));
-         _tr_tally_lit (s, s->window[s->strstart], bflush);
-         s->lookahead--;
-         s->strstart++;
-      }
-      if (bflush) FLUSH_BLOCK(s, 0);
-   }
-   s->insert = 0;
-   if (flush == Z_FINISH) {
-      FLUSH_BLOCK(s, 1);
-      return finish_done;
-   }
-   if (s->last_lit)
-      FLUSH_BLOCK(s, 0);
-   return block_done;
-}
-
-/* ===========================================================================
- * For Z_HUFFMAN_ONLY, do not look for matches.  Do not maintain a hash table.
- * (It will be regenerated if this run of deflate switches away from Huffman.)
- */
-local block_state deflate_huff(deflate_state *s, int flush)
-{
-   int bflush;             /* set if current block must be flushed */
-
-   for (;;) {
-      /* Make sure that we have a literal to write. */
-      if (s->lookahead == 0) {
-         fill_window(s);
-         if (s->lookahead == 0) {
-            if (flush == Z_NO_FLUSH)
-               return need_more;
-            break;      /* flush the current block */
-         }
-      }
-
-      /* Output a literal byte */
-      s->match_length = 0;
-      Tracevv((stderr,"%c", s->window[s->strstart]));
-      _tr_tally_lit (s, s->window[s->strstart], bflush);
-      s->lookahead--;
-      s->strstart++;
-      if (bflush) FLUSH_BLOCK(s, 0);
-   }
-   s->insert = 0;
-   if (flush == Z_FINISH) {
-      FLUSH_BLOCK(s, 1);
-      return finish_done;
-   }
-   if (s->last_lit)
-      FLUSH_BLOCK(s, 0);
-   return block_done;
-}
diff --git a/deps/zlib/gzfile.h b/deps/zlib/gzfile.h
deleted file mode 100644 (file)
index 2df4842..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-
-#ifndef _GZFILE_H
-#define _GZFILE_H
-
-struct gzFile_s
-{
-   unsigned have;
-   unsigned char *next;
-   z_off64_t pos;
-};
-
-#endif
diff --git a/deps/zlib/gzlib.c b/deps/zlib/gzlib.c
deleted file mode 100644 (file)
index 7443a75..0000000
+++ /dev/null
@@ -1,604 +0,0 @@
-/* gzlib.c -- zlib functions common to reading and writing gzip files
- * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-#include "gzguts.h"
-
-#if defined(_WIN32) && !defined(__BORLANDC__)
-#  define LSEEK _lseeki64
-#else
-#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
-#  define LSEEK lseek64
-#else
-#  define LSEEK lseek
-#endif
-#endif
-
-/* Forward declarations */
-z_off_t ZEXPORT gzoffset(gzFile file);
-int ZEXPORT gzbuffer(gzFile file, unsigned size);
-
-/* Local functions */
-local void gz_reset OF((gz_statep));
-local gzFile gz_open OF((const void *, int, const char *));
-
-#if defined UNDER_CE
-
-/* Map the Windows error number in ERROR to a locale-dependent error message
-   string and return a pointer to it.  Typically, the values for ERROR come
-   from GetLastError.
-
-   The string pointed to shall not be modified by the application, but may be
-   overwritten by a subsequent call to gz_strwinerror
-
-   The gz_strwinerror function does not change the current setting of
-   GetLastError. */
-char ZLIB_INTERNAL *gz_strwinerror (error)
-   DWORD error;
-{
-   static char buf[1024];
-
-   wchar_t *msgbuf;
-   DWORD lasterr = GetLastError();
-   DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
-         | FORMAT_MESSAGE_ALLOCATE_BUFFER,
-         NULL,
-         error,
-         0, /* Default language */
-         (LPVOID)&msgbuf,
-         0,
-         NULL);
-   if (chars != 0) {
-      /* If there is an \r\n appended, zap it.  */
-      if (chars >= 2
-            && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
-         chars -= 2;
-         msgbuf[chars] = 0;
-      }
-
-      if (chars > sizeof (buf) - 1) {
-         chars = sizeof (buf) - 1;
-         msgbuf[chars] = 0;
-      }
-
-      wcstombs(buf, msgbuf, chars + 1);
-      LocalFree(msgbuf);
-   }
-   else {
-      sprintf(buf, "unknown win32 error (%ld)", error);
-   }
-
-   SetLastError(lasterr);
-   return buf;
-}
-
-#endif /* UNDER_CE */
-
-/* Reset gzip file state */
-local void gz_reset(gz_statep state)
-{
-   state->x.have = 0;              /* no output data available */
-   if (state->mode == GZ_READ) {   /* for reading ... */
-      state->eof = 0;             /* not at end of file */
-      state->past = 0;            /* have not read past end yet */
-      state->how = LOOK;          /* look for gzip header */
-   }
-   state->seek = 0;                /* no seek request pending */
-   gz_error(state, Z_OK, NULL);    /* clear error */
-   state->x.pos = 0;               /* no uncompressed data yet */
-   state->strm.avail_in = 0;       /* no input data yet */
-}
-
-/* Open a gzip file either by name or file descriptor. */
-local gzFile gz_open(const void *path, int fd, const char *mode)
-{
-   gz_statep state;
-   size_t len;
-   int oflag;
-#ifdef O_CLOEXEC
-   int cloexec = 0;
-#endif
-#ifdef O_EXCL
-   int exclusive = 0;
-#endif
-
-   /* check input */
-   if (path == NULL)
-      return NULL;
-
-   /* allocate gzFile structure to return */
-   state = (gz_statep)malloc(sizeof(gz_state));
-   if (state == NULL)
-      return NULL;
-   state->size = 0;            /* no buffers allocated yet */
-   state->want = GZBUFSIZE;    /* requested buffer size */
-   state->msg = NULL;          /* no error message yet */
-
-   /* interpret mode */
-   state->mode = GZ_NONE;
-   state->level = Z_DEFAULT_COMPRESSION;
-   state->strategy = Z_DEFAULT_STRATEGY;
-   state->direct = 0;
-   while (*mode) {
-      if (*mode >= '0' && *mode <= '9')
-         state->level = *mode - '0';
-      else
-         switch (*mode) {
-            case 'r':
-               state->mode = GZ_READ;
-               break;
-#ifndef NO_GZCOMPRESS
-            case 'w':
-               state->mode = GZ_WRITE;
-               break;
-            case 'a':
-               state->mode = GZ_APPEND;
-               break;
-#endif
-            case '+':       /* can't read and write at the same time */
-               free(state);
-               return NULL;
-            case 'b':       /* ignore -- will request binary anyway */
-               break;
-#ifdef O_CLOEXEC
-            case 'e':
-               cloexec = 1;
-               break;
-#endif
-#ifdef O_EXCL
-            case 'x':
-               exclusive = 1;
-               break;
-#endif
-            case 'f':
-               state->strategy = Z_FILTERED;
-               break;
-            case 'h':
-               state->strategy = Z_HUFFMAN_ONLY;
-               break;
-            case 'R':
-               state->strategy = Z_RLE;
-               break;
-            case 'F':
-               state->strategy = Z_FIXED;
-               break;
-            case 'T':
-               state->direct = 1;
-               break;
-            default:        /* could consider as an error, but just ignore */
-               ;
-         }
-      mode++;
-   }
-
-   /* must provide an "r", "w", or "a" */
-   if (state->mode == GZ_NONE) {
-      free(state);
-      return NULL;
-   }
-
-   /* can't force transparent read */
-   if (state->mode == GZ_READ) {
-      if (state->direct) {
-         free(state);
-         return NULL;
-      }
-      state->direct = 1;      /* for empty file */
-   }
-
-   /* save the path name for error messages */
-#ifdef _WIN32
-   if (fd == -2) {
-      len = wcstombs(NULL, (const wchar_t*)path, 0);
-      if (len == (size_t)-1)
-         len = 0;
-   }
-   else
-#endif
-      len = strlen((const char *)path);
-   state->path = (char *)malloc(len + 1);
-   if (state->path == NULL) {
-      free(state);
-      return NULL;
-   }
-#ifdef _WIN32
-   if (fd == -2)
-      if (len)
-         wcstombs(state->path, (const wchar_t*)path, len + 1);
-      else
-         *(state->path) = 0;
-   else
-#endif
-#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
-      snprintf(state->path, len + 1, "%s", (const char *)path);
-#else
-   strlcpy(state->path, path, sizeof(state->path));
-#endif
-
-   /* compute the flags for open() */
-   oflag =
-#ifdef O_LARGEFILE
-      O_LARGEFILE |
-#endif
-#ifdef O_BINARY
-      O_BINARY |
-#endif
-#ifdef O_CLOEXEC
-      (cloexec ? O_CLOEXEC : 0) |
-#endif
-      (state->mode == GZ_READ ?
-       O_RDONLY :
-       (O_WRONLY | O_CREAT |
-#ifdef O_EXCL
-        (exclusive ? O_EXCL : 0) |
-#endif
-        (state->mode == GZ_WRITE ?
-         O_TRUNC :
-         O_APPEND)));
-
-   /* open the file with the appropriate flags (or just use fd) */
-   state->fd = fd > -1 ? fd : (
-#ifdef _WIN32
-         fd == -2 ? _wopen((const wchar_t*)path, oflag, 0666) :
-#endif
-         open((const char *)path, oflag, 0666));
-   if (state->fd == -1) {
-      free(state->path);
-      free(state);
-      return NULL;
-   }
-   if (state->mode == GZ_APPEND)
-      state->mode = GZ_WRITE;         /* simplify later checks */
-
-   /* save the current position for rewinding (only if reading) */
-   if (state->mode == GZ_READ) {
-      state->start = LSEEK(state->fd, 0, SEEK_CUR);
-      if (state->start == -1) state->start = 0;
-   }
-
-   /* initialize stream */
-   gz_reset(state);
-
-   /* return stream */
-   return (gzFile)state;
-}
-
-/* -- see zlib.h -- */
-gzFile ZEXPORT gzopen(const char *path, const char *mode)
-{
-   return gz_open(path, -1, mode);
-}
-
-/* -- see zlib.h -- */
-gzFile ZEXPORT gzopen64(const char *path, const char *mode)
-{
-   return gz_open(path, -1, mode);
-}
-
-/* -- see zlib.h -- */
-gzFile ZEXPORT gzdopen(int fd, const char *mode)
-{
-   char *path;         /* identifier for error messages */
-   gzFile gz;
-
-   if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
-      return NULL;
-#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
-   snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
-#else
-   sprintf(path, "<fd:%d>", fd);   /* for debugging */
-#endif
-   gz = gz_open(path, fd, mode);
-   free(path);
-   return gz;
-}
-
-/* -- see zlib.h -- */
-#ifdef _WIN32
-gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode)
-{
-   return gz_open(path, -2, mode);
-}
-#endif
-
-/* -- see zlib.h -- */
-int ZEXPORT gzbuffer(gzFile file, unsigned size)
-{
-   gz_statep state;
-
-   /* get internal structure and check integrity */
-   if (file == NULL)
-      return -1;
-   state = (gz_statep)file;
-   if (state->mode != GZ_READ && state->mode != GZ_WRITE)
-      return -1;
-
-   /* make sure we haven't already allocated memory */
-   if (state->size != 0)
-      return -1;
-
-   /* check and set requested size */
-   if (size < 2)
-      size = 2;               /* need two bytes to check magic header */
-   state->want = size;
-   return 0;
-}
-
-/* -- see zlib.h -- */
-int ZEXPORT gzrewind(gzFile file)
-{
-   gz_statep state;
-
-   /* get internal structure */
-   if (file == NULL)
-      return -1;
-   state = (gz_statep)file;
-
-   /* check that we're reading and that there's no error */
-   if (state->mode != GZ_READ ||
-         (state->err != Z_OK && state->err != Z_BUF_ERROR))
-      return -1;
-
-   /* back up and start over */
-   if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
-      return -1;
-   gz_reset(state);
-   return 0;
-}
-
-/* -- see zlib.h -- */
-z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
-{
-   unsigned n;
-   z_off64_t ret;
-   gz_statep state;
-
-   /* get internal structure and check integrity */
-   if (file == NULL)
-      return -1;
-   state = (gz_statep)file;
-   if (state->mode != GZ_READ && state->mode != GZ_WRITE)
-      return -1;
-
-   /* check that there's no error */
-   if (state->err != Z_OK && state->err != Z_BUF_ERROR)
-      return -1;
-
-   /* can only seek from start or relative to current position */
-   if (whence != SEEK_SET && whence != SEEK_CUR)
-      return -1;
-
-   /* normalize offset to a SEEK_CUR specification */
-   if (whence == SEEK_SET)
-      offset -= state->x.pos;
-   else if (state->seek)
-      offset += state->skip;
-   state->seek = 0;
-
-   /* if within raw area while reading, just go there */
-   if (state->mode == GZ_READ && state->how == MODE_COPY &&
-         state->x.pos + offset >= 0) {
-      ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
-      if (ret == -1)
-         return -1;
-      state->x.have = 0;
-      state->eof = 0;
-      state->past = 0;
-      state->seek = 0;
-      gz_error(state, Z_OK, NULL);
-      state->strm.avail_in = 0;
-      state->x.pos += offset;
-      return state->x.pos;
-   }
-
-   /* calculate skip amount, rewinding if needed for back seek when reading */
-   if (offset < 0) {
-      if (state->mode != GZ_READ)         /* writing -- can't go backwards */
-         return -1;
-      offset += state->x.pos;
-      if (offset < 0)                     /* before start of file! */
-         return -1;
-      if (gzrewind(file) == -1)           /* rewind, then skip to offset */
-         return -1;
-   }
-
-   /* if reading, skip what's in output buffer (one less gzgetc() check) */
-   if (state->mode == GZ_READ) {
-      n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
-         (unsigned)offset : state->x.have;
-      state->x.have -= n;
-      state->x.next += n;
-      state->x.pos += n;
-      offset -= n;
-   }
-
-   /* request skip (if not zero) */
-   if (offset) {
-      state->seek = 1;
-      state->skip = offset;
-   }
-   return state->x.pos + offset;
-}
-
-/* -- see zlib.h -- */
-z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
-{
-   z_off64_t ret;
-
-   ret = gzseek64(file, (z_off64_t)offset, whence);
-   return ret == (z_off_t)ret ? (z_off_t)ret : -1;
-}
-
-/* -- see zlib.h -- */
-z_off64_t ZEXPORT gztell64(gzFile file)
-{
-   gz_statep state;
-
-   /* get internal structure and check integrity */
-   if (file == NULL)
-      return -1;
-   state = (gz_statep)file;
-   if (state->mode != GZ_READ && state->mode != GZ_WRITE)
-      return -1;
-
-   /* return position */
-   return state->x.pos + (state->seek ? state->skip : 0);
-}
-
-/* -- see zlib.h -- */
-z_off_t ZEXPORT gztell(gzFile file)
-{
-   z_off64_t ret;
-
-   ret = gztell64(file);
-   return ret == (z_off_t)ret ? (z_off_t)ret : -1;
-}
-
-/* -- see zlib.h -- */
-z_off64_t ZEXPORT gzoffset64(gzFile file)
-{
-   z_off64_t offset;
-   gz_statep state;
-
-   /* get internal structure and check integrity */
-   if (file == NULL)
-      return -1;
-   state = (gz_statep)file;
-   if (state->mode != GZ_READ && state->mode != GZ_WRITE)
-      return -1;
-
-   /* compute and return effective offset in file */
-   offset = LSEEK(state->fd, 0, SEEK_CUR);
-   if (offset == -1)
-      return -1;
-   if (state->mode == GZ_READ)             /* reading */
-      offset -= state->strm.avail_in;     /* don't count buffered input */
-   return offset;
-}
-
-/* -- see zlib.h -- */
-z_off_t ZEXPORT gzoffset(gzFile file)
-{
-   z_off64_t ret = gzoffset64(file);
-   return ret == (z_off_t)ret ? (z_off_t)ret : -1;
-}
-
-/* -- see zlib.h -- */
-int ZEXPORT gzeof(gzFile file)
-{
-   gz_statep state;
-
-   /* get internal structure and check integrity */
-   if (file == NULL)
-      return 0;
-   state = (gz_statep)file;
-   if (state->mode != GZ_READ && state->mode != GZ_WRITE)
-      return 0;
-
-   /* return end-of-file state */
-   return state->mode == GZ_READ ? state->past : 0;
-}
-
-/* -- see zlib.h -- */
-const char * ZEXPORT gzerror(gzFile file, int *errnum)
-{
-   gz_statep state;
-
-   /* get internal structure and check integrity */
-   if (file == NULL)
-      return NULL;
-   state = (gz_statep)file;
-   if (state->mode != GZ_READ && state->mode != GZ_WRITE)
-      return NULL;
-
-   /* return error information */
-   if (errnum != NULL)
-      *errnum = state->err;
-   return state->err == Z_MEM_ERROR ? "out of memory" :
-      (state->msg == NULL ? "" : state->msg);
-}
-
-/* -- see zlib.h -- */
-void ZEXPORT gzclearerr(gzFile file)
-{
-   gz_statep state;
-
-   /* get internal structure and check integrity */
-   if (file == NULL)
-      return;
-   state = (gz_statep)file;
-   if (state->mode != GZ_READ && state->mode != GZ_WRITE)
-      return;
-
-   /* clear error and end-of-file */
-   if (state->mode == GZ_READ) {
-      state->eof = 0;
-      state->past = 0;
-   }
-   gz_error(state, Z_OK, NULL);
-}
-
-/* Create an error message in allocated memory and set state->err and
-   state->msg accordingly.  Free any previous error message already there.  Do
-   not try to free or allocate space if the error is Z_MEM_ERROR (out of
-   memory).  Simply save the error message as a static string.  If there is an
-   allocation failure constructing the error message, then convert the error to
-   out of memory. */
-void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
-{
-   /* free previously allocated message and clear */
-   if (state->msg != NULL) {
-      if (state->err != Z_MEM_ERROR)
-         free(state->msg);
-      state->msg = NULL;
-   }
-
-   /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
-   if (err != Z_OK && err != Z_BUF_ERROR)
-      state->x.have = 0;
-
-   /* set error code, and if no message, then done */
-   state->err = err;
-   if (msg == NULL)
-      return;
-
-   /* for an out of memory error, return literal string when requested */
-   if (err == Z_MEM_ERROR)
-      return;
-
-   /* construct error message with path */
-   if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
-         NULL) {
-      state->err = Z_MEM_ERROR;
-      return;
-   }
-#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
-   snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
-         "%s%s%s", state->path, ": ", msg);
-#else
-   strlcpy(state->msg, state->path, sizeof(state->msg));
-   strlcat(state->msg, ": ", sizeof(state->msg));
-   strlcat(state->msg, msg, sizeof(state->msg));
-#endif
-   return;
-}
-
-#ifndef INT_MAX
-/* portably return maximum value for an int (when limits.h presumed not
-   available) -- we need to do this to cover cases where 2's complement not
-   used, since C standard permits 1's complement and sign-bit representations,
-   otherwise we could just use ((unsigned)-1) >> 1 */
-unsigned ZLIB_INTERNAL gz_intmax()
-{
-   unsigned p, q;
-
-   p = 1;
-   do {
-      q = p;
-      p <<= 1;
-      p++;
-   } while (p > q);
-   return q >> 1;
-}
-#endif
diff --git a/deps/zlib/gzread.c b/deps/zlib/gzread.c
deleted file mode 100644 (file)
index 7f6ec7e..0000000
+++ /dev/null
@@ -1,575 +0,0 @@
-/* gzread.c -- zlib functions for reading gzip files
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-#include "gzguts.h"
-
-/* Local functions */
-local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
-local int gz_avail OF((gz_statep));
-local int gz_look OF((gz_statep));
-local int gz_decomp OF((gz_statep));
-local int gz_fetch OF((gz_statep));
-local int gz_skip OF((gz_statep, z_off64_t));
-
-int ZEXPORT gzgetc_(gzFile file);
-
-/* Use read() to load a buffer -- return -1 on error, otherwise 0.  Read from
-   state->fd, and update state->eof, state->err, and state->msg as appropriate.
-   This function needs to loop on read(), since read() is not guaranteed to
-   read the number of bytes requested, depending on the type of descriptor. */
-local int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *have)
-{
-   int ret;
-
-   *have = 0;
-   do {
-      ret = read(state->fd, buf + *have, len - *have);
-      if (ret <= 0)
-         break;
-      *have += ret;
-   } while (*have < len);
-   if (ret < 0) {
-      gz_error(state, Z_ERRNO, zstrerror());
-      return -1;
-   }
-   if (ret == 0)
-      state->eof = 1;
-   return 0;
-}
-
-/* Load up input buffer and set eof flag if last data loaded -- return -1 on
-   error, 0 otherwise.  Note that the eof flag is set when the end of the input
-   file is reached, even though there may be unused data in the buffer.  Once
-   that data has been used, no more attempts will be made to read the file.
-   If strm->avail_in != 0, then the current data is moved to the beginning of
-   the input buffer, and then the remainder of the buffer is loaded with the
-   available data from the input file. */
-local int gz_avail(gz_statep state)
-{
-   unsigned got;
-   z_streamp strm = &(state->strm);
-
-   if (state->err != Z_OK && state->err != Z_BUF_ERROR)
-      return -1;
-   if (state->eof == 0) {
-      if (strm->avail_in) {       /* copy what's there to the start */
-         unsigned char *p = state->in;
-         unsigned const char *q = strm->next_in;
-         unsigned n = strm->avail_in;
-         do {
-            *p++ = *q++;
-         } while (--n);
-      }
-      if (gz_load(state, state->in + strm->avail_in,
-               state->size - strm->avail_in, &got) == -1)
-         return -1;
-      strm->avail_in += got;
-      strm->next_in = state->in;
-   }
-   return 0;
-}
-
-/* Look for gzip header, set up for inflate or copy.  state->x.have must be 0.
-   If this is the first time in, allocate required memory.  state->how will be
-   left unchanged if there is no more input data available, will be set to COPY
-   if there is no gzip header and direct copying will be performed, or it will
-   be set to GZIP for decompression.  If direct copying, then leftover input
-   data from the input buffer will be copied to the output buffer.  In that
-   case, all further file reads will be directly to either the output buffer or
-   a user buffer.  If decompressing, the inflate state will be initialized.
-   gz_look() will return 0 on success or -1 on failure. */
-local int gz_look(gz_statep state)
-{
-   z_streamp strm = &(state->strm);
-
-   /* allocate read buffers and inflate memory */
-   if (state->size == 0) {
-      /* allocate buffers */
-      state->in = (unsigned char *)malloc(state->want);
-      state->out = (unsigned char *)malloc(state->want << 1);
-      if (state->in == NULL || state->out == NULL) {
-         if (state->out != NULL)
-            free(state->out);
-         if (state->in != NULL)
-            free(state->in);
-         gz_error(state, Z_MEM_ERROR, "out of memory");
-         return -1;
-      }
-      state->size = state->want;
-
-      /* allocate inflate memory */
-      state->strm.zalloc = Z_NULL;
-      state->strm.zfree = Z_NULL;
-      state->strm.opaque = Z_NULL;
-      state->strm.avail_in = 0;
-      state->strm.next_in = Z_NULL;
-      if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) {    /* gunzip */
-         free(state->out);
-         free(state->in);
-         state->size = 0;
-         gz_error(state, Z_MEM_ERROR, "out of memory");
-         return -1;
-      }
-   }
-
-   /* get at least the magic bytes in the input buffer */
-   if (strm->avail_in < 2) {
-      if (gz_avail(state) == -1)
-         return -1;
-      if (strm->avail_in == 0)
-         return 0;
-   }
-
-   /* look for gzip magic bytes -- if there, do gzip decoding (note: there is
-      a logical dilemma here when considering the case of a partially written
-      gzip file, to wit, if a single 31 byte is written, then we cannot tell
-      whether this is a single-byte file, or just a partially written gzip
-      file -- for here we assume that if a gzip file is being written, then
-      the header will be written in a single operation, so that reading a
-      single byte is sufficient indication that it is not a gzip file) */
-   if (strm->avail_in > 1 &&
-         strm->next_in[0] == 31 && strm->next_in[1] == 139) {
-      inflateReset(strm);
-      state->how = MODE_GZIP;
-      state->direct = 0;
-      return 0;
-   }
-
-   /* no gzip header -- if we were decoding gzip before, then this is trailing
-      garbage.  Ignore the trailing garbage and finish. */
-   if (state->direct == 0) {
-      strm->avail_in = 0;
-      state->eof = 1;
-      state->x.have = 0;
-      return 0;
-   }
-
-   /* doing raw i/o, copy any leftover input to output -- this assumes that
-      the output buffer is larger than the input buffer, which also assures
-      space for gzungetc() */
-   state->x.next = state->out;
-   if (strm->avail_in) {
-      memcpy(state->x.next, strm->next_in, strm->avail_in);
-      state->x.have = strm->avail_in;
-      strm->avail_in = 0;
-   }
-   state->how = MODE_COPY;
-   state->direct = 1;
-   return 0;
-}
-
-/* Decompress from input to the provided next_out and avail_out in the state.
-   On return, state->x.have and state->x.next point to the just decompressed
-   data.  If the gzip stream completes, state->how is reset to LOOK to look for
-   the next gzip stream or raw data, once state->x.have is depleted.  Returns 0
-   on success, -1 on failure. */
-local int gz_decomp(gz_statep state)
-{
-   int ret = Z_OK;
-   unsigned had;
-   z_streamp strm = &(state->strm);
-
-   /* fill output buffer up to end of deflate stream */
-   had = strm->avail_out;
-   do {
-      /* get more input for inflate() */
-      if (strm->avail_in == 0 && gz_avail(state) == -1)
-         return -1;
-      if (strm->avail_in == 0) {
-         gz_error(state, Z_BUF_ERROR, "unexpected end of file");
-         break;
-      }
-
-      /* decompress and handle errors */
-      ret = inflate(strm, Z_NO_FLUSH);
-      if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
-         gz_error(state, Z_STREAM_ERROR,
-               "internal error: inflate stream corrupt");
-         return -1;
-      }
-      if (ret == Z_MEM_ERROR) {
-         gz_error(state, Z_MEM_ERROR, "out of memory");
-         return -1;
-      }
-      if (ret == Z_DATA_ERROR) {              /* deflate stream invalid */
-         gz_error(state, Z_DATA_ERROR,
-               strm->msg == NULL ? "compressed data error" : strm->msg);
-         return -1;
-      }
-   } while (strm->avail_out && ret != Z_STREAM_END);
-
-   /* update available output */
-   state->x.have = had - strm->avail_out;
-   state->x.next = strm->next_out - state->x.have;
-
-   /* if the gzip stream completed successfully, look for another */
-   if (ret == Z_STREAM_END)
-      state->how = LOOK;
-
-   /* good decompression */
-   return 0;
-}
-
-/* Fetch data and put it in the output buffer.  Assumes state->x.have is 0.
-   Data is either copied from the input file or decompressed from the input
-   file depending on state->how.  If state->how is LOOK, then a gzip header is
-   looked for to determine whether to copy or decompress.  Returns -1 on error,
-   otherwise 0.  gz_fetch() will leave state->how as COPY or GZIP unless the
-   end of the input file has been reached and all data has been processed.  */
-local int gz_fetch(gz_statep state)
-{
-   z_streamp strm = &(state->strm);
-
-   do {
-      switch(state->how) {
-         case LOOK:      /* -> LOOK, MODE_COPY (only if never GZIP), or MODE_GZIP */
-            if (gz_look(state) == -1)
-               return -1;
-            if (state->how == LOOK)
-               return 0;
-            break;
-         case MODE_COPY:      /* -> MODE_COPY */
-            if (gz_load(state, state->out, state->size << 1, &(state->x.have))
-                  == -1)
-               return -1;
-            state->x.next = state->out;
-            return 0;
-         case MODE_GZIP:      /* -> GZIP or LOOK (if end of gzip stream) */
-            strm->avail_out = state->size << 1;
-            strm->next_out = state->out;
-            if (gz_decomp(state) == -1)
-               return -1;
-      }
-   } while (state->x.have == 0 && (!state->eof || strm->avail_in));
-   return 0;
-}
-
-/* Skip len uncompressed bytes of output.  Return -1 on error, 0 on success. */
-local int gz_skip(gz_statep state, z_off64_t len)
-{
-   unsigned n;
-
-   /* skip over len bytes or reach end-of-file, whichever comes first */
-   while (len)
-      /* skip over whatever is in output buffer */
-      if (state->x.have) {
-         n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
-            (unsigned)len : state->x.have;
-         state->x.have -= n;
-         state->x.next += n;
-         state->x.pos += n;
-         len -= n;
-      }
-
-   /* output buffer empty -- return if we're at the end of the input */
-      else if (state->eof && state->strm.avail_in == 0)
-         break;
-
-   /* need more data to skip -- load up output buffer */
-      else {
-         /* get more output, looking for header if required */
-         if (gz_fetch(state) == -1)
-            return -1;
-      }
-   return 0;
-}
-
-/* -- see zlib.h -- */
-int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
-{
-   unsigned got, n;
-   gz_statep state;
-   z_streamp strm;
-
-   /* get internal structure */
-   if (file == NULL)
-      return -1;
-   state = (gz_statep)file;
-   strm = &(state->strm);
-
-   /* check that we're reading and that there's no (serious) error */
-   if (state->mode != GZ_READ ||
-         (state->err != Z_OK && state->err != Z_BUF_ERROR))
-      return -1;
-
-   /* since an int is returned, make sure len fits in one, otherwise return
-      with an error (this avoids the flaw in the interface) */
-   if ((int)len < 0) {
-      gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
-      return -1;
-   }
-
-   /* if len is zero, avoid unnecessary operations */
-   if (len == 0)
-      return 0;
-
-   /* process a skip request */
-   if (state->seek) {
-      state->seek = 0;
-      if (gz_skip(state, state->skip) == -1)
-         return -1;
-   }
-
-   /* get len bytes to buf, or less than len if at the end */
-   got = 0;
-   n = 0;
-   do {
-      /* first just try copying data from the output buffer */
-      if (state->x.have) {
-         n = state->x.have > len ? len : state->x.have;
-         memcpy(buf, state->x.next, n);
-         state->x.next += n;
-         state->x.have -= n;
-      }
-
-      /* output buffer empty -- return if we're at the end of the input */
-      else if (state->eof && strm->avail_in == 0) {
-         state->past = 1;        /* tried to read past end */
-         break;
-      }
-
-      /* need output data -- for small len or new stream load up our output
-         buffer */
-      else if (state->how == LOOK || len < (state->size << 1)) {
-         /* get more output, looking for header if required */
-         if (gz_fetch(state) == -1)
-            return -1;
-         continue;       /* no progress yet -- go back to copy above */
-         /* the copy above assures that we will leave with space in the
-            output buffer, allowing at least one gzungetc() to succeed */
-      }
-
-      /* large len -- read directly into user buffer */
-      else if (state->how == MODE_COPY) {      /* read directly */
-         if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
-            return -1;
-      }
-
-      /* large len -- decompress directly into user buffer */
-      else {  /* state->how == GZIP */
-         strm->avail_out = len;
-         strm->next_out = (unsigned char *)buf;
-         if (gz_decomp(state) == -1)
-            return -1;
-         n = state->x.have;
-         state->x.have = 0;
-      }
-
-      /* update progress */
-      len -= n;
-      buf = (char *)buf + n;
-      got += n;
-      state->x.pos += n;
-   } while (len);
-
-   /* return number of bytes read into user buffer (will fit in int) */
-   return (int)got;
-}
-
-/* -- see zlib.h -- */
-#ifdef Z_PREFIX_SET
-#  undef z_gzgetc
-#else
-#  undef gzgetc
-#endif
-int ZEXPORT gzgetc(gzFile file)
-{
-   int ret;
-   unsigned char buf[1];
-   gz_statep state;
-
-   /* get internal structure */
-   if (file == NULL)
-      return -1;
-   state = (gz_statep)file;
-
-   /* check that we're reading and that there's no (serious) error */
-   if (state->mode != GZ_READ ||
-         (state->err != Z_OK && state->err != Z_BUF_ERROR))
-      return -1;
-
-   /* try output buffer (no need to check for skip request) */
-   if (state->x.have) {
-      state->x.have--;
-      state->x.pos++;
-      return *(state->x.next)++;
-   }
-
-   /* nothing there -- try gzread() */
-   ret = gzread(file, buf, 1);
-   return ret < 1 ? -1 : buf[0];
-}
-
-int ZEXPORT gzgetc_(gzFile file)
-{
-   return gzgetc(file);
-}
-
-/* -- see zlib.h -- */
-int ZEXPORT gzungetc(int c, gzFile file)
-{
-   gz_statep state;
-
-   /* get internal structure */
-   if (file == NULL)
-      return -1;
-   state = (gz_statep)file;
-
-   /* check that we're reading and that there's no (serious) error */
-   if (state->mode != GZ_READ ||
-         (state->err != Z_OK && state->err != Z_BUF_ERROR))
-      return -1;
-
-   /* process a skip request */
-   if (state->seek) {
-      state->seek = 0;
-      if (gz_skip(state, state->skip) == -1)
-         return -1;
-   }
-
-   /* can't push EOF */
-   if (c < 0)
-      return -1;
-
-   /* if output buffer empty, put byte at end (allows more pushing) */
-   if (state->x.have == 0) {
-      state->x.have = 1;
-      state->x.next = state->out + (state->size << 1) - 1;
-      state->x.next[0] = c;
-      state->x.pos--;
-      state->past = 0;
-      return c;
-   }
-
-   /* if no room, give up (must have already done a gzungetc()) */
-   if (state->x.have == (state->size << 1)) {
-      gz_error(state, Z_DATA_ERROR, "out of room to push characters");
-      return -1;
-   }
-
-   /* slide output data if needed and insert byte before existing data */
-   if (state->x.next == state->out) {
-      unsigned char *src = state->out + state->x.have;
-      unsigned char *dest = state->out + (state->size << 1);
-      while (src > state->out)
-         *--dest = *--src;
-      state->x.next = dest;
-   }
-   state->x.have++;
-   state->x.next--;
-   state->x.next[0] = c;
-   state->x.pos--;
-   state->past = 0;
-   return c;
-}
-
-/* -- see zlib.h -- */
-char * ZEXPORT gzgets(gzFile file, char *buf, int len)
-{
-   unsigned left, n;
-   char *str;
-   unsigned char *eol;
-   gz_statep state;
-
-   /* check parameters and get internal structure */
-   if (file == NULL || buf == NULL || len < 1)
-      return NULL;
-   state = (gz_statep)file;
-
-   /* check that we're reading and that there's no (serious) error */
-   if (state->mode != GZ_READ ||
-         (state->err != Z_OK && state->err != Z_BUF_ERROR))
-      return NULL;
-
-   /* process a skip request */
-   if (state->seek) {
-      state->seek = 0;
-      if (gz_skip(state, state->skip) == -1)
-         return NULL;
-   }
-
-   /* copy output bytes up to new line or len - 1, whichever comes first --
-      append a terminating zero to the string (we don't check for a zero in
-      the contents, let the user worry about that) */
-   str = buf;
-   left = (unsigned)len - 1;
-   if (left) do {
-      /* assure that something is in the output buffer */
-      if (state->x.have == 0 && gz_fetch(state) == -1)
-         return NULL;                /* error */
-      if (state->x.have == 0) {       /* end of file */
-         state->past = 1;            /* read past end */
-         break;                      /* return what we have */
-      }
-
-      /* look for end-of-line in current output buffer */
-      n = state->x.have > left ? left : state->x.have;
-      eol = (unsigned char *)memchr(state->x.next, '\n', n);
-      if (eol != NULL)
-         n = (unsigned)(eol - state->x.next) + 1;
-
-      /* copy through end-of-line, or remainder if not found */
-      memcpy(buf, state->x.next, n);
-      state->x.have -= n;
-      state->x.next += n;
-      state->x.pos += n;
-      left -= n;
-      buf += n;
-   } while (left && eol == NULL);
-
-   /* return terminated string, or if nothing, end of file */
-   if (buf == str)
-      return NULL;
-   buf[0] = 0;
-   return str;
-}
-
-/* -- see zlib.h -- */
-int ZEXPORT gzdirect(gzFile file)
-{
-   gz_statep state;
-
-   /* get internal structure */
-   if (file == NULL)
-      return 0;
-   state = (gz_statep)file;
-
-   /* if the state is not known, but we can find out, then do so (this is
-      mainly for right after a gzopen() or gzdopen()) */
-   if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
-      (void)gz_look(state);
-
-   /* return 1 if transparent, 0 if processing a gzip stream */
-   return state->direct;
-}
-
-/* -- see zlib.h -- */
-int gzclose_r(gzFile file)
-{
-   int ret, err;
-   gz_statep state;
-
-   /* get internal structure */
-   if (file == NULL)
-      return Z_STREAM_ERROR;
-   state = (gz_statep)file;
-
-   /* check that we're reading */
-   if (state->mode != GZ_READ)
-      return Z_STREAM_ERROR;
-
-   /* free memory and close file */
-   if (state->size) {
-      inflateEnd(&(state->strm));
-      free(state->out);
-      free(state->in);
-   }
-   err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
-   gz_error(state, Z_OK, NULL);
-   free(state->path);
-   ret = close(state->fd);
-   free(state);
-   return ret ? Z_ERRNO : err;
-}
diff --git a/deps/zlib/infback.c b/deps/zlib/infback.c
deleted file mode 100644 (file)
index 7206cde..0000000
+++ /dev/null
@@ -1,628 +0,0 @@
-/* infback.c -- inflate using a call-back interface
- * Copyright (C) 1995-2011 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/*
-   This code is largely copied from inflate.c.  Normally either infback.o or
-   inflate.o would be linked into an application--not both.  The interface
-   with inffast.c is retained so that optimized assembler-coded versions of
-   inflate_fast() can be used with either inflate.c or infback.c.
-   */
-
-#include "zutil.h"
-#include "inftrees.h"
-#include "inflate.h"
-#include "inffast.h"
-
-/* function prototypes */
-local void fixedtables OF((struct inflate_state FAR *state));
-
-/*
-   strm provides memory allocation functions in zalloc and zfree, or
-   Z_NULL to use the library memory allocation functions.
-
-   windowBits is in the range 8..15, and window is a user-supplied
-   window and output buffer that is 2**windowBits bytes.
-   */
-int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, int stream_size)
-{
-   struct inflate_state FAR *state;
-
-   if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
-         stream_size != (int)(sizeof(z_stream)))
-      return Z_VERSION_ERROR;
-   if (strm == Z_NULL || window == Z_NULL ||
-         windowBits < 8 || windowBits > 15)
-      return Z_STREAM_ERROR;
-   strm->msg = Z_NULL;                 /* in case we return an error */
-   if (strm->zalloc == (alloc_func)0) {
-#ifdef Z_SOLO
-      return Z_STREAM_ERROR;
-#else
-      strm->zalloc = zcalloc;
-      strm->opaque = (voidpf)0;
-#endif
-   }
-   if (strm->zfree == Z_NULL)
-#ifdef Z_SOLO
-      return Z_STREAM_ERROR;
-#else
-   strm->zfree = zcfree;
-#endif
-   state = (struct inflate_state FAR *)ZALLOC(strm, 1,
-         sizeof(struct inflate_state));
-   if (state == Z_NULL) return Z_MEM_ERROR;
-   Tracev((stderr, "inflate: allocated\n"));
-   strm->state = (struct internal_state FAR *)state;
-   state->dmax = 32768U;
-   state->wbits = windowBits;
-   state->wsize = 1U << windowBits;
-   state->window = window;
-   state->wnext = 0;
-   state->whave = 0;
-   return Z_OK;
-}
-
-/*
-   Return state with length and distance decoding tables and index sizes set to
-   fixed code decoding.  Normally this returns fixed tables from inffixed.h.
-   If BUILDFIXED is defined, then instead this routine builds the tables the
-   first time it's called, and returns those tables the first time and
-   thereafter.  This reduces the size of the code by about 2K bytes, in
-   exchange for a little execution time.  However, BUILDFIXED should not be
-   used for threaded applications, since the rewriting of the tables and virgin
-   may not be thread-safe.
-   */
-local void fixedtables(struct inflate_state FAR *state)
-{
-#ifdef BUILDFIXED
-   static int virgin = 1;
-   static code *lenfix, *distfix;
-   static code fixed[544];
-
-   /* build fixed huffman tables if first call (may not be thread safe) */
-   if (virgin) {
-      unsigned sym, bits;
-      static code *next;
-
-      /* literal/length table */
-      sym = 0;
-      while (sym < 144) state->lens[sym++] = 8;
-      while (sym < 256) state->lens[sym++] = 9;
-      while (sym < 280) state->lens[sym++] = 7;
-      while (sym < 288) state->lens[sym++] = 8;
-      next = fixed;
-      lenfix = next;
-      bits = 9;
-      inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
-
-      /* distance table */
-      sym = 0;
-      while (sym < 32) state->lens[sym++] = 5;
-      distfix = next;
-      bits = 5;
-      inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
-
-      /* do this just once */
-      virgin = 0;
-   }
-#else /* !BUILDFIXED */
-#   include "inffixed.h"
-#endif /* BUILDFIXED */
-   state->lencode = lenfix;
-   state->lenbits = 9;
-   state->distcode = distfix;
-   state->distbits = 5;
-}
-
-/* Macros for inflateBack(): */
-
-/* Load returned state from inflate_fast() */
-#define LOAD() \
-   do { \
-      put = strm->next_out; \
-      left = strm->avail_out; \
-      next = strm->next_in; \
-      have = strm->avail_in; \
-      hold = state->hold; \
-      bits = state->bits; \
-   } while (0)
-
-/* Set state from registers for inflate_fast() */
-#define RESTORE() \
-   do { \
-      strm->next_out = put; \
-      strm->avail_out = left; \
-      strm->next_in = next; \
-      strm->avail_in = have; \
-      state->hold = hold; \
-      state->bits = bits; \
-   } while (0)
-
-/* Clear the input bit accumulator */
-#define INITBITS() \
-   do { \
-      hold = 0; \
-      bits = 0; \
-   } while (0)
-
-/* Assure that some input is available.  If input is requested, but denied,
-   then return a Z_BUF_ERROR from inflateBack(). */
-#define PULL() \
-   do { \
-      if (have == 0) { \
-         have = in(in_desc, &next); \
-         if (have == 0) { \
-            next = Z_NULL; \
-            ret = Z_BUF_ERROR; \
-            goto inf_leave; \
-         } \
-      } \
-   } while (0)
-
-/* Get a byte of input into the bit accumulator, or return from inflateBack()
-   with an error if there is no input available. */
-#define PULLBYTE() \
-   do { \
-      PULL(); \
-      have--; \
-      hold += (unsigned long)(*next++) << bits; \
-      bits += 8; \
-   } while (0)
-
-/* Assure that there are at least n bits in the bit accumulator.  If there is
-   not enough available input to do that, then return from inflateBack() with
-   an error. */
-#define NEEDBITS(n) \
-   do { \
-      while (bits < (unsigned)(n)) \
-      PULLBYTE(); \
-   } while (0)
-
-/* Return the low n bits of the bit accumulator (n < 16) */
-#define BITS(n) \
-   ((unsigned)hold & ((1U << (n)) - 1))
-
-/* Remove n bits from the bit accumulator */
-#define DROPBITS(n) \
-   do { \
-      hold >>= (n); \
-      bits -= (unsigned)(n); \
-   } while (0)
-
-/* Remove zero to seven bits as needed to go to a byte boundary */
-#define BYTEBITS() \
-   do { \
-      hold >>= bits & 7; \
-      bits -= bits & 7; \
-   } while (0)
-
-/* Assure that some output space is available, by writing out the window
-   if it's full.  If the write fails, return from inflateBack() with a
-   Z_BUF_ERROR. */
-#define ROOM() \
-   do { \
-      if (left == 0) { \
-         put = state->window; \
-         left = state->wsize; \
-         state->whave = left; \
-         if (out(out_desc, put, left)) { \
-            ret = Z_BUF_ERROR; \
-            goto inf_leave; \
-         } \
-      } \
-   } while (0)
-
-/*
-   strm provides the memory allocation functions and window buffer on input,
-   and provides information on the unused input on return.  For Z_DATA_ERROR
-   returns, strm will also provide an error message.
-
-   in() and out() are the call-back input and output functions.  When
-   inflateBack() needs more input, it calls in().  When inflateBack() has
-   filled the window with output, or when it completes with data in the
-   window, it calls out() to write out the data.  The application must not
-   change the provided input until in() is called again or inflateBack()
-   returns.  The application must not change the window/output buffer until
-   inflateBack() returns.
-
-   in() and out() are called with a descriptor parameter provided in the
-   inflateBack() call.  This parameter can be a structure that provides the
-   information required to do the read or write, as well as accumulated
-   information on the input and output such as totals and check values.
-
-   in() should return zero on failure.  out() should return non-zero on
-   failure.  If either in() or out() fails, than inflateBack() returns a
-   Z_BUF_ERROR.  strm->next_in can be checked for Z_NULL to see whether it
-   was in() or out() that caused in the error.  Otherwise,  inflateBack()
-   returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
-   error, or Z_MEM_ERROR if it could not allocate memory for the state.
-   inflateBack() can also return Z_STREAM_ERROR if the input parameters
-   are not correct, i.e. strm is Z_NULL or the state was not initialized.
-   */
-int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc)
-{
-   struct inflate_state FAR *state;
-   z_const unsigned char FAR *next;    /* next input */
-   unsigned char FAR *put;     /* next output */
-   unsigned have, left;        /* available input and output */
-   unsigned long hold;         /* bit buffer */
-   unsigned bits;              /* bits in bit buffer */
-   unsigned copy;              /* number of stored or match bytes to copy */
-   unsigned char FAR *from;    /* where to copy match bytes from */
-   code here;                  /* current decoding table entry */
-   code last;                  /* parent table entry */
-   unsigned len;               /* length to copy for repeats, bits to drop */
-   int ret;                    /* return code */
-   static const unsigned short order[19] = /* permutation of code lengths */
-   {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-
-   /* Check that the strm exists and that the state was initialized */
-   if (strm == Z_NULL || strm->state == Z_NULL)
-      return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-
-   /* Reset the state */
-   strm->msg = Z_NULL;
-   state->mode = TYPE;
-   state->last = 0;
-   state->whave = 0;
-   next = strm->next_in;
-   have = next != Z_NULL ? strm->avail_in : 0;
-   hold = 0;
-   bits = 0;
-   put = state->window;
-   left = state->wsize;
-
-   /* Inflate until end of block marked as last */
-   for (;;)
-      switch (state->mode) {
-         case TYPE:
-            /* determine and dispatch block type */
-            if (state->last) {
-               BYTEBITS();
-               state->mode = DONE;
-               break;
-            }
-            NEEDBITS(3);
-            state->last = BITS(1);
-            DROPBITS(1);
-            switch (BITS(2)) {
-               case 0:                             /* stored block */
-                  Tracev((stderr, "inflate:     stored block%s\n",
-                           state->last ? " (last)" : ""));
-                  state->mode = STORED;
-                  break;
-               case 1:                             /* fixed block */
-                  fixedtables(state);
-                  Tracev((stderr, "inflate:     fixed codes block%s\n",
-                           state->last ? " (last)" : ""));
-                  state->mode = LEN;              /* decode codes */
-                  break;
-               case 2:                             /* dynamic block */
-                  Tracev((stderr, "inflate:     dynamic codes block%s\n",
-                           state->last ? " (last)" : ""));
-                  state->mode = TABLE;
-                  break;
-               case 3:
-                  strm->msg = (char *)"invalid block type";
-                  state->mode = BAD;
-            }
-            DROPBITS(2);
-            break;
-
-         case STORED:
-            /* get and verify stored block length */
-            BYTEBITS();                         /* go to byte boundary */
-            NEEDBITS(32);
-            if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
-               strm->msg = (char *)"invalid stored block lengths";
-               state->mode = BAD;
-               break;
-            }
-            state->length = (unsigned)hold & 0xffff;
-            Tracev((stderr, "inflate:       stored length %u\n",
-                     state->length));
-            INITBITS();
-
-            /* copy stored block from input to output */
-            while (state->length != 0) {
-               copy = state->length;
-               PULL();
-               ROOM();
-               if (copy > have) copy = have;
-               if (copy > left) copy = left;
-               zmemcpy(put, next, copy);
-               have -= copy;
-               next += copy;
-               left -= copy;
-               put += copy;
-               state->length -= copy;
-            }
-            Tracev((stderr, "inflate:       stored end\n"));
-            state->mode = TYPE;
-            break;
-
-         case TABLE:
-            /* get dynamic table entries descriptor */
-            NEEDBITS(14);
-            state->nlen = BITS(5) + 257;
-            DROPBITS(5);
-            state->ndist = BITS(5) + 1;
-            DROPBITS(5);
-            state->ncode = BITS(4) + 4;
-            DROPBITS(4);
-#ifndef PKZIP_BUG_WORKAROUND
-            if (state->nlen > 286 || state->ndist > 30) {
-               strm->msg = (char *)"too many length or distance symbols";
-               state->mode = BAD;
-               break;
-            }
-#endif
-            Tracev((stderr, "inflate:       table sizes ok\n"));
-
-            /* get code length code lengths (not a typo) */
-            state->have = 0;
-            while (state->have < state->ncode) {
-               NEEDBITS(3);
-               state->lens[order[state->have++]] = (unsigned short)BITS(3);
-               DROPBITS(3);
-            }
-            while (state->have < 19)
-               state->lens[order[state->have++]] = 0;
-            state->next = state->codes;
-            state->lencode = (code const FAR *)(state->next);
-            state->lenbits = 7;
-            ret = inflate_table(CODES, state->lens, 19, &(state->next),
-                  &(state->lenbits), state->work);
-            if (ret) {
-               strm->msg = (char *)"invalid code lengths set";
-               state->mode = BAD;
-               break;
-            }
-            Tracev((stderr, "inflate:       code lengths ok\n"));
-
-            /* get length and distance code code lengths */
-            state->have = 0;
-            while (state->have < state->nlen + state->ndist) {
-               for (;;) {
-                  here = state->lencode[BITS(state->lenbits)];
-                  if ((unsigned)(here.bits) <= bits) break;
-                  PULLBYTE();
-               }
-               if (here.val < 16) {
-                  DROPBITS(here.bits);
-                  state->lens[state->have++] = here.val;
-               }
-               else {
-                  if (here.val == 16) {
-                     NEEDBITS(here.bits + 2);
-                     DROPBITS(here.bits);
-                     if (state->have == 0) {
-                        strm->msg = (char *)"invalid bit length repeat";
-                        state->mode = BAD;
-                        break;
-                     }
-                     len = (unsigned)(state->lens[state->have - 1]);
-                     copy = 3 + BITS(2);
-                     DROPBITS(2);
-                  }
-                  else if (here.val == 17) {
-                     NEEDBITS(here.bits + 3);
-                     DROPBITS(here.bits);
-                     len = 0;
-                     copy = 3 + BITS(3);
-                     DROPBITS(3);
-                  }
-                  else {
-                     NEEDBITS(here.bits + 7);
-                     DROPBITS(here.bits);
-                     len = 0;
-                     copy = 11 + BITS(7);
-                     DROPBITS(7);
-                  }
-                  if (state->have + copy > state->nlen + state->ndist) {
-                     strm->msg = (char *)"invalid bit length repeat";
-                     state->mode = BAD;
-                     break;
-                  }
-                  while (copy--)
-                     state->lens[state->have++] = (unsigned short)len;
-               }
-            }
-
-            /* handle error breaks in while */
-            if (state->mode == BAD) break;
-
-            /* check for end-of-block code (better have one) */
-            if (state->lens[256] == 0) {
-               strm->msg = (char *)"invalid code -- missing end-of-block";
-               state->mode = BAD;
-               break;
-            }
-
-            /* build code tables -- note: do not change the lenbits or distbits
-               values here (9 and 6) without reading the comments in inftrees.h
-               concerning the ENOUGH constants, which depend on those values */
-            state->next = state->codes;
-            state->lencode = (code const FAR *)(state->next);
-            state->lenbits = 9;
-            ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
-                  &(state->lenbits), state->work);
-            if (ret) {
-               strm->msg = (char *)"invalid literal/lengths set";
-               state->mode = BAD;
-               break;
-            }
-            state->distcode = (code const FAR *)(state->next);
-            state->distbits = 6;
-            ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
-                  &(state->next), &(state->distbits), state->work);
-            if (ret) {
-               strm->msg = (char *)"invalid distances set";
-               state->mode = BAD;
-               break;
-            }
-            Tracev((stderr, "inflate:       codes ok\n"));
-            state->mode = LEN;
-
-         case LEN:
-            /* use inflate_fast() if we have enough input and output */
-            if (have >= 6 && left >= 258) {
-               RESTORE();
-               if (state->whave < state->wsize)
-                  state->whave = state->wsize - left;
-               inflate_fast(strm, state->wsize);
-               LOAD();
-               break;
-            }
-
-            /* get a literal, length, or end-of-block code */
-            for (;;) {
-               here = state->lencode[BITS(state->lenbits)];
-               if ((unsigned)(here.bits) <= bits) break;
-               PULLBYTE();
-            }
-            if (here.op && (here.op & 0xf0) == 0) {
-               last = here;
-               for (;;) {
-                  here = state->lencode[last.val +
-                     (BITS(last.bits + last.op) >> last.bits)];
-                  if ((unsigned)(last.bits + here.bits) <= bits) break;
-                  PULLBYTE();
-               }
-               DROPBITS(last.bits);
-            }
-            DROPBITS(here.bits);
-            state->length = (unsigned)here.val;
-
-            /* process literal */
-            if (here.op == 0) {
-               Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
-                        "inflate:         literal '%c'\n" :
-                        "inflate:         literal 0x%02x\n", here.val));
-               ROOM();
-               *put++ = (unsigned char)(state->length);
-               left--;
-               state->mode = LEN;
-               break;
-            }
-
-            /* process end of block */
-            if (here.op & 32) {
-               Tracevv((stderr, "inflate:         end of block\n"));
-               state->mode = TYPE;
-               break;
-            }
-
-            /* invalid code */
-            if (here.op & 64) {
-               strm->msg = (char *)"invalid literal/length code";
-               state->mode = BAD;
-               break;
-            }
-
-            /* length code -- get extra bits, if any */
-            state->extra = (unsigned)(here.op) & 15;
-            if (state->extra != 0) {
-               NEEDBITS(state->extra);
-               state->length += BITS(state->extra);
-               DROPBITS(state->extra);
-            }
-            Tracevv((stderr, "inflate:         length %u\n", state->length));
-
-            /* get distance code */
-            for (;;) {
-               here = state->distcode[BITS(state->distbits)];
-               if ((unsigned)(here.bits) <= bits) break;
-               PULLBYTE();
-            }
-            if ((here.op & 0xf0) == 0) {
-               last = here;
-               for (;;) {
-                  here = state->distcode[last.val +
-                     (BITS(last.bits + last.op) >> last.bits)];
-                  if ((unsigned)(last.bits + here.bits) <= bits) break;
-                  PULLBYTE();
-               }
-               DROPBITS(last.bits);
-            }
-            DROPBITS(here.bits);
-            if (here.op & 64) {
-               strm->msg = (char *)"invalid distance code";
-               state->mode = BAD;
-               break;
-            }
-            state->offset = (unsigned)here.val;
-
-            /* get distance extra bits, if any */
-            state->extra = (unsigned)(here.op) & 15;
-            if (state->extra != 0) {
-               NEEDBITS(state->extra);
-               state->offset += BITS(state->extra);
-               DROPBITS(state->extra);
-            }
-            if (state->offset > state->wsize - (state->whave < state->wsize ?
-                     left : 0)) {
-               strm->msg = (char *)"invalid distance too far back";
-               state->mode = BAD;
-               break;
-            }
-            Tracevv((stderr, "inflate:         distance %u\n", state->offset));
-
-            /* copy match from window to output */
-            do {
-               ROOM();
-               copy = state->wsize - state->offset;
-               if (copy < left) {
-                  from = put + copy;
-                  copy = left - copy;
-               }
-               else {
-                  from = put - state->offset;
-                  copy = left;
-               }
-               if (copy > state->length) copy = state->length;
-               state->length -= copy;
-               left -= copy;
-               do {
-                  *put++ = *from++;
-               } while (--copy);
-            } while (state->length != 0);
-            break;
-
-         case DONE:
-            /* inflate stream terminated properly -- write leftover output */
-            ret = Z_STREAM_END;
-            if (left < state->wsize) {
-               if (out(out_desc, state->window, state->wsize - left))
-                  ret = Z_BUF_ERROR;
-            }
-            goto inf_leave;
-
-         case BAD:
-            ret = Z_DATA_ERROR;
-            goto inf_leave;
-
-         default:                /* can't happen, but makes compilers happy */
-            ret = Z_STREAM_ERROR;
-            goto inf_leave;
-      }
-
-   /* Return unused input */
-inf_leave:
-   strm->next_in = next;
-   strm->avail_in = have;
-   return ret;
-}
-
-int ZEXPORT inflateBackEnd(z_streamp strm)
-{
-   if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == Z_NULL)
-      return Z_STREAM_ERROR;
-   ZFREE(strm, strm->state);
-   strm->state = Z_NULL;
-   Tracev((stderr, "inflate: end\n"));
-   return Z_OK;
-}
diff --git a/deps/zlib/inffast.c b/deps/zlib/inffast.c
deleted file mode 100644 (file)
index a88859f..0000000
+++ /dev/null
@@ -1,338 +0,0 @@
-/* inffast.c -- fast decoding
- * Copyright (C) 1995-2008, 2010, 2013 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-#include "zutil.h"
-#include "inftrees.h"
-#include "inflate.h"
-#include "inffast.h"
-
-#ifndef ASMINF
-
-/* Allow machine dependent optimization for post-increment or pre-increment.
-   Based on testing to date,
-   Pre-increment preferred for:
-   - PowerPC G3 (Adler)
-   - MIPS R5000 (Randers-Pehrson)
-   Post-increment preferred for:
-   - none
-   No measurable difference:
-   - Pentium III (Anderson)
-   - M68060 (Nikl)
-   */
-#ifdef POSTINC
-#  define OFF 0
-#  define PUP(a) *(a)++
-#else
-#  define OFF 1
-#  define PUP(a) *++(a)
-#endif
-
-/*
-   Decode literal, length, and distance codes and write out the resulting
-   literal and match bytes until either not enough input or output is
-   available, an end-of-block is encountered, or a data error is encountered.
-   When large enough input and output buffers are supplied to inflate(), for
-   example, a 16K input buffer and a 64K output buffer, more than 95% of the
-   inflate execution time is spent in this routine.
-
-   Entry assumptions:
-
-   state->mode == LEN
-   strm->avail_in >= 6
-   strm->avail_out >= 258
-   start >= strm->avail_out
-   state->bits < 8
-
-   On return, state->mode is one of:
-
-   LEN -- ran out of enough output space or enough available input
-   TYPE -- reached end of block code, inflate() to interpret next block
-   BAD -- error in block data
-
-Notes:
-
-- The maximum input bits used by a length/distance pair is 15 bits for the
-length code, 5 bits for the length extra, 15 bits for the distance code,
-and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
-Therefore if strm->avail_in >= 6, then there is enough input to avoid
-checking for available input while decoding.
-
-- The maximum bytes that a single length/distance pair can output is 258
-bytes, which is the maximum length that can be coded.  inflate_fast()
-requires strm->avail_out >= 258 for each loop to avoid checking for
-output space.
-*/
-void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
-{
-   struct inflate_state FAR *state;
-   unsigned char FAR *in;      /* local strm->next_in */
-   unsigned char FAR *last;    /* have enough input while in < last */
-   unsigned char FAR *out;     /* local strm->next_out */
-   unsigned char FAR *beg;     /* inflate()'s initial strm->next_out */
-   unsigned char FAR *end;     /* while out < end, enough space available */
-#ifdef INFLATE_STRICT
-   unsigned dmax;              /* maximum distance from zlib header */
-#endif
-   unsigned wsize;             /* window size or zero if not using window */
-   unsigned whave;             /* valid bytes in the window */
-   unsigned wnext;             /* window write index */
-   unsigned char FAR *window;  /* allocated sliding window, if wsize != 0 */
-   unsigned long hold;         /* local strm->hold */
-   unsigned bits;              /* local strm->bits */
-   code const FAR *lcode;      /* local strm->lencode */
-   code const FAR *dcode;      /* local strm->distcode */
-   unsigned lmask;             /* mask for first level of length codes */
-   unsigned dmask;             /* mask for first level of distance codes */
-   code here;                  /* retrieved table entry */
-   unsigned op;                /* code bits, operation, extra bits, or */
-   /*  window position, window bytes to copy */
-   unsigned len;               /* match length, unused bytes */
-   unsigned dist;              /* match distance */
-   unsigned char FAR *from;    /* where to copy match from */
-
-   /* copy state to local variables */
-   state = (struct inflate_state FAR *)strm->state;
-   in = strm->next_in - OFF;
-   last = in + (strm->avail_in - 5);
-   out = strm->next_out - OFF;
-   beg = out - (start - strm->avail_out);
-   end = out + (strm->avail_out - 257);
-#ifdef INFLATE_STRICT
-   dmax = state->dmax;
-#endif
-   wsize = state->wsize;
-   whave = state->whave;
-   wnext = state->wnext;
-   window = state->window;
-   hold = state->hold;
-   bits = state->bits;
-   lcode = state->lencode;
-   dcode = state->distcode;
-   lmask = (1U << state->lenbits) - 1;
-   dmask = (1U << state->distbits) - 1;
-
-   /* decode literals and length/distances until end-of-block or not enough
-      input data or output space */
-   do {
-      if (bits < 15) {
-         hold += (unsigned long)(PUP(in)) << bits;
-         bits += 8;
-         hold += (unsigned long)(PUP(in)) << bits;
-         bits += 8;
-      }
-      here = lcode[hold & lmask];
-dolen:
-      op = (unsigned)(here.bits);
-      hold >>= op;
-      bits -= op;
-      op = (unsigned)(here.op);
-      if (op == 0) {                          /* literal */
-         Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
-                  "inflate:         literal '%c'\n" :
-                  "inflate:         literal 0x%02x\n", here.val));
-         PUP(out) = (unsigned char)(here.val);
-      }
-      else if (op & 16) {                     /* length base */
-         len = (unsigned)(here.val);
-         op &= 15;                           /* number of extra bits */
-         if (op) {
-            if (bits < op) {
-               hold += (unsigned long)(PUP(in)) << bits;
-               bits += 8;
-            }
-            len += (unsigned)hold & ((1U << op) - 1);
-            hold >>= op;
-            bits -= op;
-         }
-         Tracevv((stderr, "inflate:         length %u\n", len));
-         if (bits < 15) {
-            hold += (unsigned long)(PUP(in)) << bits;
-            bits += 8;
-            hold += (unsigned long)(PUP(in)) << bits;
-            bits += 8;
-         }
-         here = dcode[hold & dmask];
-dodist:
-         op = (unsigned)(here.bits);
-         hold >>= op;
-         bits -= op;
-         op = (unsigned)(here.op);
-         if (op & 16) {                      /* distance base */
-            dist = (unsigned)(here.val);
-            op &= 15;                       /* number of extra bits */
-            if (bits < op) {
-               hold += (unsigned long)(PUP(in)) << bits;
-               bits += 8;
-               if (bits < op) {
-                  hold += (unsigned long)(PUP(in)) << bits;
-                  bits += 8;
-               }
-            }
-            dist += (unsigned)hold & ((1U << op) - 1);
-#ifdef INFLATE_STRICT
-            if (dist > dmax) {
-               strm->msg = (char *)"invalid distance too far back";
-               state->mode = BAD;
-               break;
-            }
-#endif
-            hold >>= op;
-            bits -= op;
-            Tracevv((stderr, "inflate:         distance %u\n", dist));
-            op = (unsigned)(out - beg);     /* max distance in output */
-            if (dist > op) {                /* see if copy from window */
-               op = dist - op;             /* distance back in window */
-               if (op > whave) {
-                  if (state->sane) {
-                     strm->msg =
-                        (char *)"invalid distance too far back";
-                     state->mode = BAD;
-                     break;
-                  }
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
-                  if (len <= op - whave) {
-                     do {
-                        PUP(out) = 0;
-                     } while (--len);
-                     continue;
-                  }
-                  len -= op - whave;
-                  do {
-                     PUP(out) = 0;
-                  } while (--op > whave);
-                  if (op == 0) {
-                     from = out - dist;
-                     do {
-                        PUP(out) = PUP(from);
-                     } while (--len);
-                     continue;
-                  }
-#endif
-               }
-               from = window - OFF;
-               if (wnext == 0) {           /* very common case */
-                  from += wsize - op;
-                  if (op < len) {         /* some from window */
-                     len -= op;
-                     do {
-                        PUP(out) = PUP(from);
-                     } while (--op);
-                     from = out - dist;  /* rest from output */
-                  }
-               }
-               else if (wnext < op) {      /* wrap around window */
-                  from += wsize + wnext - op;
-                  op -= wnext;
-                  if (op < len) {         /* some from end of window */
-                     len -= op;
-                     do {
-                        PUP(out) = PUP(from);
-                     } while (--op);
-                     from = window - OFF;
-                     if (wnext < len) {  /* some from start of window */
-                        op = wnext;
-                        len -= op;
-                        do {
-                           PUP(out) = PUP(from);
-                        } while (--op);
-                        from = out - dist;      /* rest from output */
-                     }
-                  }
-               }
-               else {                      /* contiguous in window */
-                  from += wnext - op;
-                  if (op < len) {         /* some from window */
-                     len -= op;
-                     do {
-                        PUP(out) = PUP(from);
-                     } while (--op);
-                     from = out - dist;  /* rest from output */
-                  }
-               }
-               while (len > 2) {
-                  PUP(out) = PUP(from);
-                  PUP(out) = PUP(from);
-                  PUP(out) = PUP(from);
-                  len -= 3;
-               }
-               if (len) {
-                  PUP(out) = PUP(from);
-                  if (len > 1)
-                     PUP(out) = PUP(from);
-               }
-            }
-            else {
-               from = out - dist;          /* copy direct from output */
-               do {                        /* minimum length is three */
-                  PUP(out) = PUP(from);
-                  PUP(out) = PUP(from);
-                  PUP(out) = PUP(from);
-                  len -= 3;
-               } while (len > 2);
-               if (len) {
-                  PUP(out) = PUP(from);
-                  if (len > 1)
-                     PUP(out) = PUP(from);
-               }
-            }
-         }
-         else if ((op & 64) == 0) {          /* 2nd level distance code */
-            here = dcode[here.val + (hold & ((1U << op) - 1))];
-            goto dodist;
-         }
-         else {
-            strm->msg = (char *)"invalid distance code";
-            state->mode = BAD;
-            break;
-         }
-      }
-      else if ((op & 64) == 0) {              /* 2nd level length code */
-         here = lcode[here.val + (hold & ((1U << op) - 1))];
-         goto dolen;
-      }
-      else if (op & 32) {                     /* end-of-block */
-         Tracevv((stderr, "inflate:         end of block\n"));
-         state->mode = TYPE;
-         break;
-      }
-      else {
-         strm->msg = (char *)"invalid literal/length code";
-         state->mode = BAD;
-         break;
-      }
-   } while (in < last && out < end);
-
-   /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
-   len = bits >> 3;
-   in -= len;
-   bits -= len << 3;
-   hold &= (1U << bits) - 1;
-
-   /* update state and return */
-   strm->next_in = in + OFF;
-   strm->next_out = out + OFF;
-   strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
-   strm->avail_out = (unsigned)(out < end ?
-         257 + (end - out) : 257 - (out - end));
-   state->hold = hold;
-   state->bits = bits;
-   return;
-}
-
-/*
-   inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
-   - Using bit fields for code structure
-   - Different op definition to avoid & for extra bits (do & for table bits)
-   - Three separate decoding do-loops for direct, window, and wnext == 0
-   - Special case for distance > 1 copies to do overlapped load and store copy
-   - Explicit branch predictions (based on measured branch probabilities)
-   - Deferring match copy and interspersed it with decoding subsequent codes
-   - Swapping literal/length else
-   - Swapping window/direct else
-   - Larger unrolled copy loops (three is about right)
-   - Moving len -= 3 statement into middle of loop
-   */
-
-#endif /* !ASMINF */
diff --git a/deps/zlib/inflate.c b/deps/zlib/inflate.c
deleted file mode 100644 (file)
index 0b4f0b7..0000000
+++ /dev/null
@@ -1,1489 +0,0 @@
-/* inflate.c -- zlib decompression
- * Copyright (C) 1995-2012 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/*
- * Change history:
- *
- * 1.2.beta0    24 Nov 2002
- * - First version -- complete rewrite of inflate to simplify code, avoid
- *   creation of window when not needed, minimize use of window when it is
- *   needed, make inffast.c even faster, implement gzip decoding, and to
- *   improve code readability and style over the previous zlib inflate code
- *
- * 1.2.beta1    25 Nov 2002
- * - Use pointers for available input and output checking in inffast.c
- * - Remove input and output counters in inffast.c
- * - Change inffast.c entry and loop from avail_in >= 7 to >= 6
- * - Remove unnecessary second byte pull from length extra in inffast.c
- * - Unroll direct copy to three copies per loop in inffast.c
- *
- * 1.2.beta2    4 Dec 2002
- * - Change external routine names to reduce potential conflicts
- * - Correct filename to inffixed.h for fixed tables in inflate.c
- * - Make hbuf[] unsigned char to match parameter type in inflate.c
- * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
- *   to avoid negation problem on Alphas (64 bit) in inflate.c
- *
- * 1.2.beta3    22 Dec 2002
- * - Add comments on state->bits assertion in inffast.c
- * - Add comments on op field in inftrees.h
- * - Fix bug in reuse of allocated window after inflateReset()
- * - Remove bit fields--back to byte structure for speed
- * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths
- * - Change post-increments to pre-increments in inflate_fast(), PPC biased?
- * - Add compile time option, POSTINC, to use post-increments instead (Intel?)
- * - Make MATCH copy in inflate() much faster for when inflate_fast() not used
- * - Use local copies of stream next and avail values, as well as local bit
- *   buffer and bit count in inflate()--for speed when inflate_fast() not used
- *
- * 1.2.beta4    1 Jan 2003
- * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings
- * - Move a comment on output buffer sizes from inffast.c to inflate.c
- * - Add comments in inffast.c to introduce the inflate_fast() routine
- * - Rearrange window copies in inflate_fast() for speed and simplification
- * - Unroll last copy for window match in inflate_fast()
- * - Use local copies of window variables in inflate_fast() for speed
- * - Pull out common wnext == 0 case for speed in inflate_fast()
- * - Make op and len in inflate_fast() unsigned for consistency
- * - Add FAR to lcode and dcode declarations in inflate_fast()
- * - Simplified bad distance check in inflate_fast()
- * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new
- *   source file infback.c to provide a call-back interface to inflate for
- *   programs like gzip and unzip -- uses window as output buffer to avoid
- *   window copying
- *
- * 1.2.beta5    1 Jan 2003
- * - Improved inflateBack() interface to allow the caller to provide initial
- *   input in strm.
- * - Fixed stored blocks bug in inflateBack()
- *
- * 1.2.beta6    4 Jan 2003
- * - Added comments in inffast.c on effectiveness of POSTINC
- * - Typecasting all around to reduce compiler warnings
- * - Changed loops from while (1) or do {} while (1) to for (;;), again to
- *   make compilers happy
- * - Changed type of window in inflateBackInit() to unsigned char *
- *
- * 1.2.beta7    27 Jan 2003
- * - Changed many types to unsigned or unsigned short to avoid warnings
- * - Added inflateCopy() function
- *
- * 1.2.0        9 Mar 2003
- * - Changed inflateBack() interface to provide separate opaque descriptors
- *   for the in() and out() functions
- * - Changed inflateBack() argument and in_func typedef to swap the length
-   *   and buffer address return values for the input function
-* - Check next_in and next_out for Z_NULL on entry to inflate()
-   *
-   * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
-   */
-
-#include "zutil.h"
-#include "inftrees.h"
-#include "inflate.h"
-#include "inffast.h"
-
-#ifdef MAKEFIXED
-#  ifndef BUILDFIXED
-#    define BUILDFIXED
-#  endif
-#endif
-
-#ifndef Z_TREES
-#define Z_TREES 6
-#endif
-
-   /* function prototypes */
-int ZEXPORT inflateReset2(z_streamp strm, int windowBits);
-   local void fixedtables OF((struct inflate_state FAR *state));
-   local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
-            unsigned copy));
-#ifdef BUILDFIXED
-void makefixed OF((void));
-#endif
-local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
-         unsigned len));
-
-long ZEXPORT inflateMark(z_streamp strm);
-
-int ZEXPORT inflateResetKeep(z_streamp strm);
-
-int ZEXPORT inflateUndermine(z_streamp strm, int subvert);
-
-int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);
-
-int ZEXPORT inflateResetKeep(z_streamp strm)
-{
-   struct inflate_state FAR *state;
-
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-   strm->total_in = strm->total_out = state->total = 0;
-   strm->msg = Z_NULL;
-   if (state->wrap)        /* to support ill-conceived Java test suite */
-      strm->adler = state->wrap & 1;
-   state->mode = HEAD;
-   state->last = 0;
-   state->havedict = 0;
-   state->dmax = 32768U;
-   state->head = Z_NULL;
-   state->hold = 0;
-   state->bits = 0;
-   state->lencode = state->distcode = state->next = state->codes;
-   state->sane = 1;
-   state->back = -1;
-   Tracev((stderr, "inflate: reset\n"));
-   return Z_OK;
-}
-
-int ZEXPORT inflateReset(z_streamp strm)
-{
-   struct inflate_state FAR *state;
-
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-   state->wsize = 0;
-   state->whave = 0;
-   state->wnext = 0;
-   return inflateResetKeep(strm);
-}
-
-int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
-{
-   int wrap;
-   struct inflate_state FAR *state = NULL;
-
-   /* get the state */
-   if (strm == Z_NULL || strm->state == Z_NULL)
-          return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-
-   /* extract wrap request from windowBits parameter */
-   if (windowBits < 0) {
-      wrap = 0;
-      windowBits = -windowBits;
-   }
-   else {
-      wrap = (windowBits >> 4) + 1;
-#ifdef GUNZIP
-      if (windowBits < 48)
-         windowBits &= 15;
-#endif
-   }
-
-   /* set number of window bits, free window if different */
-   if (windowBits && (windowBits < 8 || windowBits > 15))
-      return Z_STREAM_ERROR;
-   if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
-      ZFREE(strm, state->window);
-      state->window = Z_NULL;
-   }
-
-   /* update state and reset the rest of it */
-   state->wrap = wrap;
-   state->wbits = (unsigned)windowBits;
-   return inflateReset(strm);
-}
-
-int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
-{
-   int ret;
-   struct inflate_state FAR *state;
-
-   if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
-         stream_size != (int)(sizeof(z_stream)))
-      return Z_VERSION_ERROR;
-   if (strm == Z_NULL) return Z_STREAM_ERROR;
-   strm->msg = Z_NULL;                 /* in case we return an error */
-   if (strm->zalloc == (alloc_func)0) {
-#ifdef Z_SOLO
-      return Z_STREAM_ERROR;
-#else
-      strm->zalloc = zcalloc;
-      strm->opaque = (voidpf)0;
-#endif
-   }
-   if (strm->zfree == Z_NULL)
-#ifdef Z_SOLO
-      return Z_STREAM_ERROR;
-#else
-   strm->zfree = zcfree;
-#endif
-   state = (struct inflate_state FAR *)
-      ZALLOC(strm, 1, sizeof(struct inflate_state));
-   if (state == Z_NULL) return Z_MEM_ERROR;
-   Tracev((stderr, "inflate: allocated\n"));
-   strm->state = (struct internal_state FAR *)state;
-   state->window = Z_NULL;
-   ret = inflateReset2(strm, windowBits);
-   if (ret != Z_OK) {
-      ZFREE(strm, state);
-      strm->state = Z_NULL;
-   }
-   return ret;
-}
-
-int ZEXPORT inflateInit_(z_streamp strm, const char *version, int stream_size)
-{
-   return inflateInit2_(strm, DEF_WBITS, version, stream_size);
-}
-
-int ZEXPORT inflatePrime(z_streamp strm, int bits, int value)
-{
-   struct inflate_state FAR *state;
-
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-   if (bits < 0) {
-      state->hold = 0;
-      state->bits = 0;
-      return Z_OK;
-   }
-   if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
-   value &= (1L << bits) - 1;
-   state->hold += value << state->bits;
-   state->bits += bits;
-   return Z_OK;
-}
-
-/*
-   Return state with length and distance decoding tables and index sizes set to
-   fixed code decoding.  Normally this returns fixed tables from inffixed.h.
-   If BUILDFIXED is defined, then instead this routine builds the tables the
-   first time it's called, and returns those tables the first time and
-   thereafter.  This reduces the size of the code by about 2K bytes, in
-   exchange for a little execution time.  However, BUILDFIXED should not be
-   used for threaded applications, since the rewriting of the tables and virgin
-   may not be thread-safe.
-   */
-local void fixedtables(struct inflate_state FAR *state)
-{
-#ifdef BUILDFIXED
-   static int virgin = 1;
-   static code *lenfix, *distfix;
-   static code fixed[544];
-
-   /* build fixed huffman tables if first call (may not be thread safe) */
-   if (virgin) {
-      unsigned sym, bits;
-      static code *next;
-
-      /* literal/length table */
-      sym = 0;
-      while (sym < 144) state->lens[sym++] = 8;
-      while (sym < 256) state->lens[sym++] = 9;
-      while (sym < 280) state->lens[sym++] = 7;
-      while (sym < 288) state->lens[sym++] = 8;
-      next = fixed;
-      lenfix = next;
-      bits = 9;
-      inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
-
-      /* distance table */
-      sym = 0;
-      while (sym < 32) state->lens[sym++] = 5;
-      distfix = next;
-      bits = 5;
-      inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
-
-      /* do this just once */
-      virgin = 0;
-   }
-#else /* !BUILDFIXED */
-#   include "inffixed.h"
-#endif /* BUILDFIXED */
-   state->lencode = lenfix;
-   state->lenbits = 9;
-   state->distcode = distfix;
-   state->distbits = 5;
-}
-
-#ifdef MAKEFIXED
-#include <stdio.h>
-
-/*
-   Write out the inffixed.h that is #include'd above.  Defining MAKEFIXED also
-   defines BUILDFIXED, so the tables are built on the fly.  makefixed() writes
-   those tables to stdout, which would be piped to inffixed.h.  A small program
-   can simply call makefixed to do this:
-
-   void makefixed(void);
-
-   int main(void)
-   {
-   makefixed();
-   return 0;
-   }
-
-   Then that can be linked with zlib built with MAKEFIXED defined and run:
-
-   a.out > inffixed.h
-   */
-void makefixed(void)
-{
-   unsigned low, size;
-   struct inflate_state state;
-
-   fixedtables(&state);
-   puts("    /* inffixed.h -- table for decoding fixed codes");
-   puts("     * Generated automatically by makefixed().");
-   puts("     */");
-   puts("");
-   puts("    /* WARNING: this file should *not* be used by applications.");
-   puts("       It is part of the implementation of this library and is");
-   puts("       subject to change. Applications should only use zlib.h.");
-   puts("     */");
-   puts("");
-   size = 1U << 9;
-   printf("    static const code lenfix[%u] = {", size);
-   low = 0;
-   for (;;) {
-      if ((low % 7) == 0) printf("\n        ");
-      printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
-            state.lencode[low].bits, state.lencode[low].val);
-      if (++low == size) break;
-      putchar(',');
-   }
-   puts("\n    };");
-   size = 1U << 5;
-   printf("\n    static const code distfix[%u] = {", size);
-   low = 0;
-   for (;;) {
-      if ((low % 6) == 0) printf("\n        ");
-      printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
-            state.distcode[low].val);
-      if (++low == size) break;
-      putchar(',');
-   }
-   puts("\n    };");
-}
-#endif /* MAKEFIXED */
-
-/*
-   Update the window with the last wsize (normally 32K) bytes written before
-   returning.  If window does not exist yet, create it.  This is only called
-   when a window is already in use, or when output has been written during this
-   inflate call, but the end of the deflate stream has not been reached yet.
-   It is also called to create a window for dictionary data when a dictionary
-   is loaded.
-
-   Providing output buffers larger than 32K to inflate() should provide a speed
-   advantage, since only the last 32K of output is copied to the sliding window
-   upon return from inflate(), and since all distances after the first 32K of
-   output will fall in the output data, making match copies simpler and faster.
-   The advantage may be dependent on the size of the processor's data caches.
-   */
-local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
-{
-   struct inflate_state FAR *state;
-   unsigned dist;
-
-   state = (struct inflate_state FAR *)strm->state;
-
-   /* if it hasn't been done already, allocate space for the window */
-   if (state->window == Z_NULL) {
-      state->window = (unsigned char FAR *)
-         ZALLOC(strm, 1U << state->wbits,
-               sizeof(unsigned char));
-      if (state->window == Z_NULL) return 1;
-   }
-
-   /* if window not in use yet, initialize */
-   if (state->wsize == 0) {
-      state->wsize = 1U << state->wbits;
-      state->wnext = 0;
-      state->whave = 0;
-   }
-
-   /* copy state->wsize or less output bytes into the circular window */
-   if (copy >= state->wsize) {
-      zmemcpy(state->window, end - state->wsize, state->wsize);
-      state->wnext = 0;
-      state->whave = state->wsize;
-   }
-   else {
-      dist = state->wsize - state->wnext;
-      if (dist > copy) dist = copy;
-      zmemcpy(state->window + state->wnext, end - copy, dist);
-      copy -= dist;
-      if (copy) {
-         zmemcpy(state->window, end - copy, copy);
-         state->wnext = copy;
-         state->whave = state->wsize;
-      }
-      else {
-         state->wnext += dist;
-         if (state->wnext == state->wsize) state->wnext = 0;
-         if (state->whave < state->wsize) state->whave += dist;
-      }
-   }
-   return 0;
-}
-
-/* Macros for inflate(): */
-
-/* check function to use adler32() for zlib or crc32() for gzip */
-#ifdef GUNZIP
-#  define UPDATE(check, buf, len) \
-   (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
-#else
-#  define UPDATE(check, buf, len) adler32(check, buf, len)
-#endif
-
-/* check macros for header crc */
-#ifdef GUNZIP
-#  define CRC2(check, word) \
-   do { \
-      hbuf[0] = (unsigned char)(word); \
-      hbuf[1] = (unsigned char)((word) >> 8); \
-      check = crc32(check, hbuf, 2); \
-   } while (0)
-
-#  define CRC4(check, word) \
-   do { \
-      hbuf[0] = (unsigned char)(word); \
-      hbuf[1] = (unsigned char)((word) >> 8); \
-      hbuf[2] = (unsigned char)((word) >> 16); \
-      hbuf[3] = (unsigned char)((word) >> 24); \
-      check = crc32(check, hbuf, 4); \
-   } while (0)
-#endif
-
-/* Load registers with state in inflate() for speed */
-#define LOAD() \
-   do { \
-      put = strm->next_out; \
-      left = strm->avail_out; \
-      next = strm->next_in; \
-      have = strm->avail_in; \
-      hold = state->hold; \
-      bits = state->bits; \
-   } while (0)
-
-/* Restore state from registers in inflate() */
-#define RESTORE() \
-   do { \
-      strm->next_out = put; \
-      strm->avail_out = left; \
-      strm->next_in = next; \
-      strm->avail_in = have; \
-      state->hold = hold; \
-      state->bits = bits; \
-   } while (0)
-
-/* Clear the input bit accumulator */
-#define INITBITS() \
-   do { \
-      hold = 0; \
-      bits = 0; \
-   } while (0)
-
-/* Get a byte of input into the bit accumulator, or return from inflate()
-   if there is no input available. */
-#define PULLBYTE() \
-   do { \
-      if (have == 0) goto inf_leave; \
-      have--; \
-      hold += (unsigned long)(*next++) << bits; \
-      bits += 8; \
-   } while (0)
-
-/* Assure that there are at least n bits in the bit accumulator.  If there is
-   not enough available input to do that, then return from inflate(). */
-#define NEEDBITS(n) \
-   do { \
-      while (bits < (unsigned)(n)) \
-      PULLBYTE(); \
-   } while (0)
-
-/* Return the low n bits of the bit accumulator (n < 16) */
-#define BITS(n) \
-   ((unsigned)hold & ((1U << (n)) - 1))
-
-/* Remove n bits from the bit accumulator */
-#define DROPBITS(n) \
-   do { \
-      hold >>= (n); \
-      bits -= (unsigned)(n); \
-   } while (0)
-
-/* Remove zero to seven bits as needed to go to a byte boundary */
-#define BYTEBITS() \
-   do { \
-      hold >>= bits & 7; \
-      bits -= bits & 7; \
-   } while (0)
-
-/*
-   inflate() uses a state machine to process as much input data and generate as
-   much output data as possible before returning.  The state machine is
-   structured roughly as follows:
-
-   for (;;) switch (state) {
-   ...
-   case STATEn:
-   if (not enough input data or output space to make progress)
-   return;
-   ... make progress ...
-   state = STATEm;
-   break;
-   ...
-   }
-
-   so when inflate() is called again, the same case is attempted again, and
-   if the appropriate resources are provided, the machine proceeds to the
-   next state.  The NEEDBITS() macro is usually the way the state evaluates
-   whether it can proceed or should return.  NEEDBITS() does the return if
-   the requested bits are not available.  The typical use of the BITS macros
-is:
-
-NEEDBITS(n);
-... do something with BITS(n) ...
-DROPBITS(n);
-
-where NEEDBITS(n) either returns from inflate() if there isn't enough
-input left to load n bits into the accumulator, or it continues.  BITS(n)
-gives the low n bits in the accumulator.  When done, DROPBITS(n) drops
-the low n bits off the accumulator.  INITBITS() clears the accumulator
-and sets the number of available bits to zero.  BYTEBITS() discards just
-enough bits to put the accumulator on a byte boundary.  After BYTEBITS()
-and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
-
-NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
-if there is no input available.  The decoding of variable length codes uses
-PULLBYTE() directly in order to pull just enough bytes to decode the next
-code, and no more.
-
-Some states loop until they get enough input, making sure that enough
-state information is maintained to continue the loop where it left off
-if NEEDBITS() returns in the loop.  For example, want, need, and keep
-would all have to actually be part of the saved state in case NEEDBITS()
-returns:
-
-case STATEw:
-while (want < need) {
-NEEDBITS(n);
-keep[want++] = BITS(n);
-DROPBITS(n);
-}
-state = STATEx;
-case STATEx:
-
-As shown above, if the next state is also the next case, then the break
-is omitted.
-
-A state may also return if there is not enough output space available to
-complete that state.  Those states are copying stored data, writing a
-literal byte, and copying a matching string.
-
-When returning, a "goto inf_leave" is used to update the total counters,
-update the check value, and determine whether any progress has been made
-during that inflate() call in order to return the proper return code.
-Progress is defined as a change in either strm->avail_in or strm->avail_out.
-When there is a window, goto inf_leave will update the window with the last
-output written.  If a goto inf_leave occurs in the middle of decompression
-and there is no window currently, goto inf_leave will create one and copy
-output to the window for the next call of inflate().
-
-In this implementation, the flush parameter of inflate() only affects the
-return code (per zlib.h).  inflate() always writes as much as possible to
-strm->next_out, given the space available and the provided input--the effect
-documented in zlib.h of Z_SYNC_FLUSH.  Furthermore, inflate() always defers
-the allocation of and copying into a sliding window until necessary, which
-provides the effect documented in zlib.h for Z_FINISH when the entire input
-stream available.  So the only thing the flush parameter actually does is:
-when flush is set to Z_FINISH, inflate() cannot return Z_OK.  Instead it
-will return Z_BUF_ERROR if it has not reached the end of the stream.
-*/
-
-int ZEXPORT inflate(z_streamp strm, int flush)
-{
-   struct inflate_state FAR *state;
-   unsigned char FAR *next;    /* next input */
-   unsigned char FAR *put;     /* next output */
-   unsigned have, left;        /* available input and output */
-   unsigned long hold;         /* bit buffer */
-   unsigned bits;              /* bits in bit buffer */
-   unsigned in, out;           /* save starting available input and output */
-   unsigned copy;              /* number of stored or match bytes to copy */
-   unsigned char FAR *from;    /* where to copy match bytes from */
-   code here;                  /* current decoding table entry */
-   code last;                  /* parent table entry */
-   unsigned len;               /* length to copy for repeats, bits to drop */
-   int ret;                    /* return code */
-#ifdef GUNZIP
-   unsigned char hbuf[4];      /* buffer for gzip header crc calculation */
-#endif
-   static const unsigned short order[19] = /* permutation of code lengths */
-   {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-
-   if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
-         (strm->next_in == Z_NULL && strm->avail_in != 0))
-      return Z_STREAM_ERROR;
-
-   state = (struct inflate_state FAR *)strm->state;
-   if (state->mode == TYPE) state->mode = TYPEDO;      /* skip check */
-   LOAD();
-   in = have;
-   out = left;
-   ret = Z_OK;
-   for (;;)
-      switch (state->mode) {
-         case HEAD:
-            if (state->wrap == 0) {
-               state->mode = TYPEDO;
-               break;
-            }
-            NEEDBITS(16);
-#ifdef GUNZIP
-            if ((state->wrap & 2) && hold == 0x8b1f) {  /* gzip header */
-               state->check = crc32(0L, Z_NULL, 0);
-               CRC2(state->check, hold);
-               INITBITS();
-               state->mode = FLAGS;
-               break;
-            }
-            state->flags = 0;           /* expect zlib header */
-            if (state->head != Z_NULL)
-               state->head->done = -1;
-            if (!(state->wrap & 1) ||   /* check if zlib header allowed */
-#else
-                  if (
-#endif
-                     ((BITS(8) << 8) + (hold >> 8)) % 31) {
-                  strm->msg = (char *)"incorrect header check";
-                  state->mode = BAD;
-                  break;
-                  }
-                  if (BITS(4) != Z_DEFLATED) {
-                  strm->msg = (char *)"unknown compression method";
-                  state->mode = BAD;
-                  break;
-                  }
-                  DROPBITS(4);
-                  len = BITS(4) + 8;
-                  if (state->wbits == 0)
-                  state->wbits = len;
-                  else if (len > state->wbits) {
-                  strm->msg = (char *)"invalid window size";
-                  state->mode = BAD;
-                  break;
-                  }
-                  state->dmax = 1U << len;
-                  Tracev((stderr, "inflate:   zlib header ok\n"));
-                  strm->adler = state->check = adler32(0L, Z_NULL, 0);
-                  state->mode = hold & 0x200 ? DICTID : TYPE;
-                  INITBITS();
-                  break;
-#ifdef GUNZIP
-         case FLAGS:
-                  NEEDBITS(16);
-                  state->flags = (int)(hold);
-                  if ((state->flags & 0xff) != Z_DEFLATED) {
-                     strm->msg = (char *)"unknown compression method";
-                     state->mode = BAD;
-                     break;
-                  }
-                  if (state->flags & 0xe000) {
-                     strm->msg = (char *)"unknown header flags set";
-                     state->mode = BAD;
-                     break;
-                  }
-                  if (state->head != Z_NULL)
-                     state->head->text = (int)((hold >> 8) & 1);
-                  if (state->flags & 0x0200) CRC2(state->check, hold);
-                  INITBITS();
-                  state->mode = TIME;
-         case TIME:
-                  NEEDBITS(32);
-                  if (state->head != Z_NULL)
-                     state->head->time = hold;
-                  if (state->flags & 0x0200) CRC4(state->check, hold);
-                  INITBITS();
-                  state->mode = OS;
-         case OS:
-                  NEEDBITS(16);
-                  if (state->head != Z_NULL) {
-                     state->head->xflags = (int)(hold & 0xff);
-                     state->head->os = (int)(hold >> 8);
-                  }
-                  if (state->flags & 0x0200) CRC2(state->check, hold);
-                  INITBITS();
-                  state->mode = EXLEN;
-         case EXLEN:
-                  if (state->flags & 0x0400) {
-                     NEEDBITS(16);
-                     state->length = (unsigned)(hold);
-                     if (state->head != Z_NULL)
-                        state->head->extra_len = (unsigned)hold;
-                     if (state->flags & 0x0200) CRC2(state->check, hold);
-                     INITBITS();
-                  }
-                  else if (state->head != Z_NULL)
-                     state->head->extra = Z_NULL;
-                  state->mode = EXTRA;
-         case EXTRA:
-                  if (state->flags & 0x0400) {
-                     copy = state->length;
-                     if (copy > have) copy = have;
-                     if (copy) {
-                        if (state->head != Z_NULL &&
-                              state->head->extra != Z_NULL) {
-                           len = state->head->extra_len - state->length;
-                           zmemcpy(state->head->extra + len, next,
-                                 len + copy > state->head->extra_max ?
-                                 state->head->extra_max - len : copy);
-                        }
-                        if (state->flags & 0x0200)
-                           state->check = crc32(state->check, next, copy);
-                        have -= copy;
-                        next += copy;
-                        state->length -= copy;
-                     }
-                     if (state->length) goto inf_leave;
-                  }
-                  state->length = 0;
-                  state->mode = NAME;
-         case NAME:
-                  if (state->flags & 0x0800) {
-                     if (have == 0) goto inf_leave;
-                     copy = 0;
-                     do {
-                        len = (unsigned)(next[copy++]);
-                        if (state->head != Z_NULL &&
-                              state->head->name != Z_NULL &&
-                              state->length < state->head->name_max)
-                           state->head->name[state->length++] = len;
-                     } while (len && copy < have);
-                     if (state->flags & 0x0200)
-                        state->check = crc32(state->check, next, copy);
-                     have -= copy;
-                     next += copy;
-                     if (len) goto inf_leave;
-                  }
-                  else if (state->head != Z_NULL)
-                     state->head->name = Z_NULL;
-                  state->length = 0;
-                  state->mode = COMMENT;
-         case COMMENT:
-                  if (state->flags & 0x1000) {
-                     if (have == 0) goto inf_leave;
-                     copy = 0;
-                     do {
-                        len = (unsigned)(next[copy++]);
-                        if (state->head != Z_NULL &&
-                              state->head->comment != Z_NULL &&
-                              state->length < state->head->comm_max)
-                           state->head->comment[state->length++] = len;
-                     } while (len && copy < have);
-                     if (state->flags & 0x0200)
-                        state->check = crc32(state->check, next, copy);
-                     have -= copy;
-                     next += copy;
-                     if (len) goto inf_leave;
-                  }
-                  else if (state->head != Z_NULL)
-                     state->head->comment = Z_NULL;
-                  state->mode = HCRC;
-         case HCRC:
-                  if (state->flags & 0x0200) {
-                     NEEDBITS(16);
-                     if (hold != (state->check & 0xffff)) {
-                        strm->msg = (char *)"header crc mismatch";
-                        state->mode = BAD;
-                        break;
-                     }
-                     INITBITS();
-                  }
-                  if (state->head != Z_NULL) {
-                     state->head->hcrc = (int)((state->flags >> 9) & 1);
-                     state->head->done = 1;
-                  }
-                  strm->adler = state->check = crc32(0L, Z_NULL, 0);
-                  state->mode = TYPE;
-                  break;
-#endif
-         case DICTID:
-                  NEEDBITS(32);
-                  strm->adler = state->check = ZSWAP32(hold);
-                  INITBITS();
-                  state->mode = DICT;
-         case DICT:
-                  if (state->havedict == 0) {
-                     RESTORE();
-                     return Z_NEED_DICT;
-                  }
-                  strm->adler = state->check = adler32(0L, Z_NULL, 0);
-                  state->mode = TYPE;
-         case TYPE:
-                  if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
-         case TYPEDO:
-                  if (state->last) {
-                     BYTEBITS();
-                     state->mode = CHECK;
-                     break;
-                  }
-                  NEEDBITS(3);
-                  state->last = BITS(1);
-                  DROPBITS(1);
-                  switch (BITS(2)) {
-                     case 0:                             /* stored block */
-                        Tracev((stderr, "inflate:     stored block%s\n",
-                                 state->last ? " (last)" : ""));
-                        state->mode = STORED;
-                        break;
-                     case 1:                             /* fixed block */
-                        fixedtables(state);
-                        Tracev((stderr, "inflate:     fixed codes block%s\n",
-                                 state->last ? " (last)" : ""));
-                        state->mode = LEN_;             /* decode codes */
-                        if (flush == Z_TREES) {
-                           DROPBITS(2);
-                           goto inf_leave;
-                        }
-                        break;
-                     case 2:                             /* dynamic block */
-                        Tracev((stderr, "inflate:     dynamic codes block%s\n",
-                                 state->last ? " (last)" : ""));
-                        state->mode = TABLE;
-                        break;
-                     case 3:
-                        strm->msg = (char *)"invalid block type";
-                        state->mode = BAD;
-                  }
-                  DROPBITS(2);
-                  break;
-         case STORED:
-                  BYTEBITS();                         /* go to byte boundary */
-                  NEEDBITS(32);
-                  if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
-                     strm->msg = (char *)"invalid stored block lengths";
-                     state->mode = BAD;
-                     break;
-                  }
-                  state->length = (unsigned)hold & 0xffff;
-                  Tracev((stderr, "inflate:       stored length %u\n",
-                           state->length));
-                  INITBITS();
-                  state->mode = COPY_;
-                  if (flush == Z_TREES) goto inf_leave;
-         case COPY_:
-                  state->mode = COPY;
-         case COPY:
-                  copy = state->length;
-                  if (copy) {
-                     if (copy > have) copy = have;
-                     if (copy > left) copy = left;
-                     if (copy == 0) goto inf_leave;
-                     zmemcpy(put, next, copy);
-                     have -= copy;
-                     next += copy;
-                     left -= copy;
-                     put += copy;
-                     state->length -= copy;
-                     break;
-                  }
-                  Tracev((stderr, "inflate:       stored end\n"));
-                  state->mode = TYPE;
-                  break;
-         case TABLE:
-                  NEEDBITS(14);
-                  state->nlen = BITS(5) + 257;
-                  DROPBITS(5);
-                  state->ndist = BITS(5) + 1;
-                  DROPBITS(5);
-                  state->ncode = BITS(4) + 4;
-                  DROPBITS(4);
-#ifndef PKZIP_BUG_WORKAROUND
-                  if (state->nlen > 286 || state->ndist > 30) {
-                     strm->msg = (char *)"too many length or distance symbols";
-                     state->mode = BAD;
-                     break;
-                  }
-#endif
-                  Tracev((stderr, "inflate:       table sizes ok\n"));
-                  state->have = 0;
-                  state->mode = LENLENS;
-         case LENLENS:
-                  while (state->have < state->ncode) {
-                     NEEDBITS(3);
-                     state->lens[order[state->have++]] = (unsigned short)BITS(3);
-                     DROPBITS(3);
-                  }
-                  while (state->have < 19)
-                     state->lens[order[state->have++]] = 0;
-                  state->next = state->codes;
-                  state->lencode = (const code FAR *)(state->next);
-                  state->lenbits = 7;
-                  ret = inflate_table(CODES, state->lens, 19, &(state->next),
-                        &(state->lenbits), state->work);
-                  if (ret) {
-                     strm->msg = (char *)"invalid code lengths set";
-                     state->mode = BAD;
-                     break;
-                  }
-                  Tracev((stderr, "inflate:       code lengths ok\n"));
-                  state->have = 0;
-                  state->mode = CODELENS;
-         case CODELENS:
-                  while (state->have < state->nlen + state->ndist) {
-                     for (;;) {
-                        here = state->lencode[BITS(state->lenbits)];
-                        if ((unsigned)(here.bits) <= bits) break;
-                        PULLBYTE();
-                     }
-                     if (here.val < 16) {
-                        DROPBITS(here.bits);
-                        state->lens[state->have++] = here.val;
-                     }
-                     else {
-                        if (here.val == 16) {
-                           NEEDBITS(here.bits + 2);
-                           DROPBITS(here.bits);
-                           if (state->have == 0) {
-                              strm->msg = (char *)"invalid bit length repeat";
-                              state->mode = BAD;
-                              break;
-                           }
-                           len = state->lens[state->have - 1];
-                           copy = 3 + BITS(2);
-                           DROPBITS(2);
-                        }
-                        else if (here.val == 17) {
-                           NEEDBITS(here.bits + 3);
-                           DROPBITS(here.bits);
-                           len = 0;
-                           copy = 3 + BITS(3);
-                           DROPBITS(3);
-                        }
-                        else {
-                           NEEDBITS(here.bits + 7);
-                           DROPBITS(here.bits);
-                           len = 0;
-                           copy = 11 + BITS(7);
-                           DROPBITS(7);
-                        }
-                        if (state->have + copy > state->nlen + state->ndist) {
-                           strm->msg = (char *)"invalid bit length repeat";
-                           state->mode = BAD;
-                           break;
-                        }
-                        while (copy--)
-                           state->lens[state->have++] = (unsigned short)len;
-                     }
-                  }
-
-                  /* handle error breaks in while */
-                  if (state->mode == BAD) break;
-
-                  /* check for end-of-block code (better have one) */
-                  if (state->lens[256] == 0) {
-                     strm->msg = (char *)"invalid code -- missing end-of-block";
-                     state->mode = BAD;
-                     break;
-                  }
-
-                  /* build code tables -- note: do not change the lenbits or distbits
-                     values here (9 and 6) without reading the comments in inftrees.h
-                     concerning the ENOUGH constants, which depend on those values */
-                  state->next = state->codes;
-                  state->lencode = (const code FAR *)(state->next);
-                  state->lenbits = 9;
-                  ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
-                        &(state->lenbits), state->work);
-                  if (ret) {
-                     strm->msg = (char *)"invalid literal/lengths set";
-                     state->mode = BAD;
-                     break;
-                  }
-                  state->distcode = (const code FAR *)(state->next);
-                  state->distbits = 6;
-                  ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
-                        &(state->next), &(state->distbits), state->work);
-                  if (ret) {
-                     strm->msg = (char *)"invalid distances set";
-                     state->mode = BAD;
-                     break;
-                  }
-                  Tracev((stderr, "inflate:       codes ok\n"));
-                  state->mode = LEN_;
-                  if (flush == Z_TREES) goto inf_leave;
-         case LEN_:
-                  state->mode = LEN;
-         case LEN:
-                  if (have >= 6 && left >= 258) {
-                     RESTORE();
-                     inflate_fast(strm, out);
-                     LOAD();
-                     if (state->mode == TYPE)
-                        state->back = -1;
-                     break;
-                  }
-                  state->back = 0;
-                  for (;;) {
-                     here = state->lencode[BITS(state->lenbits)];
-                     if ((unsigned)(here.bits) <= bits) break;
-                     PULLBYTE();
-                  }
-                  if (here.op && (here.op & 0xf0) == 0) {
-                     last = here;
-                     for (;;) {
-                        here = state->lencode[last.val +
-                           (BITS(last.bits + last.op) >> last.bits)];
-                        if ((unsigned)(last.bits + here.bits) <= bits) break;
-                        PULLBYTE();
-                     }
-                     DROPBITS(last.bits);
-                     state->back += last.bits;
-                  }
-                  DROPBITS(here.bits);
-                  state->back += here.bits;
-                  state->length = (unsigned)here.val;
-                  if ((int)(here.op) == 0) {
-                     Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
-                              "inflate:         literal '%c'\n" :
-                              "inflate:         literal 0x%02x\n", here.val));
-                     state->mode = LIT;
-                     break;
-                  }
-                  if (here.op & 32) {
-                     Tracevv((stderr, "inflate:         end of block\n"));
-                     state->back = -1;
-                     state->mode = TYPE;
-                     break;
-                  }
-                  if (here.op & 64) {
-                     strm->msg = (char *)"invalid literal/length code";
-                     state->mode = BAD;
-                     break;
-                  }
-                  state->extra = (unsigned)(here.op) & 15;
-                  state->mode = LENEXT;
-         case LENEXT:
-                  if (state->extra) {
-                     NEEDBITS(state->extra);
-                     state->length += BITS(state->extra);
-                     DROPBITS(state->extra);
-                     state->back += state->extra;
-                  }
-                  Tracevv((stderr, "inflate:         length %u\n", state->length));
-                  state->was = state->length;
-                  state->mode = DIST;
-         case DIST:
-                  for (;;) {
-                     here = state->distcode[BITS(state->distbits)];
-                     if ((unsigned)(here.bits) <= bits) break;
-                     PULLBYTE();
-                  }
-                  if ((here.op & 0xf0) == 0) {
-                     last = here;
-                     for (;;) {
-                        here = state->distcode[last.val +
-                           (BITS(last.bits + last.op) >> last.bits)];
-                        if ((unsigned)(last.bits + here.bits) <= bits) break;
-                        PULLBYTE();
-                     }
-                     DROPBITS(last.bits);
-                     state->back += last.bits;
-                  }
-                  DROPBITS(here.bits);
-                  state->back += here.bits;
-                  if (here.op & 64) {
-                     strm->msg = (char *)"invalid distance code";
-                     state->mode = BAD;
-                     break;
-                  }
-                  state->offset = (unsigned)here.val;
-                  state->extra = (unsigned)(here.op) & 15;
-                  state->mode = DISTEXT;
-         case DISTEXT:
-                  if (state->extra) {
-                     NEEDBITS(state->extra);
-                     state->offset += BITS(state->extra);
-                     DROPBITS(state->extra);
-                     state->back += state->extra;
-                  }
-#ifdef INFLATE_STRICT
-                  if (state->offset > state->dmax) {
-                     strm->msg = (char *)"invalid distance too far back";
-                     state->mode = BAD;
-                     break;
-                  }
-#endif
-                  Tracevv((stderr, "inflate:         distance %u\n", state->offset));
-                  state->mode = MATCH;
-         case MATCH:
-                  if (left == 0) goto inf_leave;
-                  copy = out - left;
-                  if (state->offset > copy) {         /* copy from window */
-                     copy = state->offset - copy;
-                     if (copy > state->whave) {
-                        if (state->sane) {
-                           strm->msg = (char *)"invalid distance too far back";
-                           state->mode = BAD;
-                           break;
-                        }
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
-                        Trace((stderr, "inflate.c too far\n"));
-                        copy -= state->whave;
-                        if (copy > state->length) copy = state->length;
-                        if (copy > left) copy = left;
-                        left -= copy;
-                        state->length -= copy;
-                        do {
-                           *put++ = 0;
-                        } while (--copy);
-                        if (state->length == 0) state->mode = LEN;
-                        break;
-#endif
-                     }
-                     if (copy > state->wnext) {
-                        copy -= state->wnext;
-                        from = state->window + (state->wsize - copy);
-                     }
-                     else
-                        from = state->window + (state->wnext - copy);
-                     if (copy > state->length) copy = state->length;
-                  }
-                  else {                              /* copy from output */
-                     from = put - state->offset;
-                     copy = state->length;
-                  }
-                  if (copy > left) copy = left;
-                  left -= copy;
-                  state->length -= copy;
-                  do {
-                     *put++ = *from++;
-                  } while (--copy);
-                  if (state->length == 0) state->mode = LEN;
-                  break;
-         case LIT:
-                  if (left == 0) goto inf_leave;
-                  *put++ = (unsigned char)(state->length);
-                  left--;
-                  state->mode = LEN;
-                  break;
-         case CHECK:
-                  if (state->wrap) {
-                     NEEDBITS(32);
-                     out -= left;
-                     strm->total_out += out;
-                     state->total += out;
-                     if (out)
-                        strm->adler = state->check =
-                           UPDATE(state->check, put - out, out);
-                     out = left;
-                     if ((
-#ifdef GUNZIP
-                              state->flags ? hold :
-#endif
-                              ZSWAP32(hold)) != state->check) {
-                        strm->msg = (char *)"incorrect data check";
-                        state->mode = BAD;
-                        break;
-                     }
-                     INITBITS();
-                     Tracev((stderr, "inflate:   check matches trailer\n"));
-                  }
-#ifdef GUNZIP
-                  state->mode = LENGTH;
-         case LENGTH:
-                  if (state->wrap && state->flags) {
-                     NEEDBITS(32);
-                     if (hold != (state->total & 0xffffffffUL)) {
-                        strm->msg = (char *)"incorrect length check";
-                        state->mode = BAD;
-                        break;
-                     }
-                     INITBITS();
-                     Tracev((stderr, "inflate:   length matches trailer\n"));
-                  }
-#endif
-                  state->mode = DONE;
-         case DONE:
-                  ret = Z_STREAM_END;
-                  goto inf_leave;
-         case BAD:
-                  ret = Z_DATA_ERROR;
-                  goto inf_leave;
-         case MEM:
-                  return Z_MEM_ERROR;
-         case SYNC:
-         default:
-                  return Z_STREAM_ERROR;
-      }
-
-   /*
-      Return from inflate(), updating the total counts and the check value.
-      If there was no progress during the inflate() call, return a buffer
-      error.  Call updatewindow() to create and/or update the window state.
-Note: a memory error from inflate() is non-recoverable.
-*/
-inf_leave:
-   RESTORE();
-   if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
-            (state->mode < CHECK || flush != Z_FINISH)))
-      if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
-         state->mode = MEM;
-         return Z_MEM_ERROR;
-      }
-   in -= strm->avail_in;
-   out -= strm->avail_out;
-   strm->total_in += in;
-   strm->total_out += out;
-   state->total += out;
-   if (state->wrap && out)
-      strm->adler = state->check =
-         UPDATE(state->check, strm->next_out - out, out);
-   strm->data_type = state->bits + (state->last ? 64 : 0) +
-      (state->mode == TYPE ? 128 : 0) +
-      (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
-   if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
-      ret = Z_BUF_ERROR;
-   return ret;
-}
-
-int ZEXPORT inflateEnd(z_streamp strm)
-{
-   struct inflate_state FAR *state;
-   if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == Z_NULL)
-      return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-   if (state->window != Z_NULL) ZFREE(strm, state->window);
-   ZFREE(strm, strm->state);
-   strm->state = Z_NULL;
-   Tracev((stderr, "inflate: end\n"));
-   return Z_OK;
-}
-
-int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength)
-{
-   struct inflate_state FAR *state;
-
-   /* check state */
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-
-   /* copy dictionary */
-   if (state->whave && dictionary != Z_NULL) {
-      zmemcpy(dictionary, state->window + state->wnext,
-            state->whave - state->wnext);
-      zmemcpy(dictionary + state->whave - state->wnext,
-            state->window, state->wnext);
-   }
-   if (dictLength != Z_NULL)
-      *dictLength = state->whave;
-   return Z_OK;
-}
-
-int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
-{
-   struct inflate_state FAR *state;
-   unsigned long dictid;
-   int ret;
-
-   /* check state */
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-   if (state->wrap != 0 && state->mode != DICT)
-      return Z_STREAM_ERROR;
-
-   /* check for correct dictionary identifier */
-   if (state->mode == DICT) {
-      dictid = adler32(0L, Z_NULL, 0);
-      dictid = adler32(dictid, dictionary, dictLength);
-      if (dictid != state->check)
-         return Z_DATA_ERROR;
-   }
-
-   /* copy dictionary to window using updatewindow(), which will amend the
-      existing dictionary if appropriate */
-   ret = updatewindow(strm, dictionary + dictLength, dictLength);
-   if (ret) {
-      state->mode = MEM;
-      return Z_MEM_ERROR;
-   }
-   state->havedict = 1;
-   Tracev((stderr, "inflate:   dictionary set\n"));
-   return Z_OK;
-}
-
-int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head)
-{
-   struct inflate_state FAR *state;
-
-   /* check state */
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-   if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
-
-   /* save header structure */
-   state->head = head;
-   head->done = 0;
-   return Z_OK;
-}
-
-/*
-   Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff.  Return when found
-   or when out of input.  When called, *have is the number of pattern bytes
-   found in order so far, in 0..3.  On return *have is updated to the new
-   state.  If on return *have equals four, then the pattern was found and the
-   return value is how many bytes were read including the last byte of the
-   pattern.  If *have is less than four, then the pattern has not been found
-   yet and the return value is len.  In the latter case, syncsearch() can be
-   called again with more data and the *have state.  *have is initialized to
-   zero for the first call.
-   */
-local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
-{
-   unsigned got;
-   unsigned next;
-
-   got = *have;
-   next = 0;
-   while (next < len && got < 4) {
-      if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
-         got++;
-      else if (buf[next])
-         got = 0;
-      else
-         got = 4 - got;
-      next++;
-   }
-   *have = got;
-   return next;
-}
-
-int ZEXPORT inflateSync(z_streamp strm)
-{
-   unsigned len;               /* number of bytes to look at or looked at */
-   unsigned long in, out;      /* temporary to save total_in and total_out */
-   unsigned char buf[4];       /* to restore bit buffer to byte string */
-   struct inflate_state FAR *state;
-
-   /* check parameters */
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-   if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
-
-   /* if first time, start search in bit buffer */
-   if (state->mode != SYNC) {
-      state->mode = SYNC;
-      state->hold <<= state->bits & 7;
-      state->bits -= state->bits & 7;
-      len = 0;
-      while (state->bits >= 8) {
-         buf[len++] = (unsigned char)(state->hold);
-         state->hold >>= 8;
-         state->bits -= 8;
-      }
-      state->have = 0;
-      syncsearch(&(state->have), buf, len);
-   }
-
-   /* search available input */
-   len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
-   strm->avail_in -= len;
-   strm->next_in += len;
-   strm->total_in += len;
-
-   /* return no joy or set up to restart inflate() on a new block */
-   if (state->have != 4) return Z_DATA_ERROR;
-   in = strm->total_in;  out = strm->total_out;
-   inflateReset(strm);
-   strm->total_in = in;  strm->total_out = out;
-   state->mode = TYPE;
-   return Z_OK;
-}
-
-/*
-   Returns true if inflate is currently at the end of a block generated by
-   Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
-   implementation to provide an additional safety check. PPP uses
-   Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
-   block. When decompressing, PPP checks that at the end of input packet,
-   inflate is waiting for these length bytes.
-   */
-int ZEXPORT inflateSyncPoint(z_streamp strm)
-{
-   struct inflate_state FAR *state;
-
-   if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-   return state->mode == STORED && state->bits == 0;
-}
-
-int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
-{
-   struct inflate_state FAR *state;
-   struct inflate_state FAR *copy;
-   unsigned char FAR *window;
-   unsigned wsize;
-
-   /* check input */
-   if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
-         source->zalloc == Z_NULL || source->zfree == Z_NULL)
-      return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)source->state;
-
-   /* allocate space */
-   copy = (struct inflate_state FAR *)
-      ZALLOC(source, 1, sizeof(struct inflate_state));
-   if (copy == Z_NULL) return Z_MEM_ERROR;
-   window = Z_NULL;
-   if (state->window != Z_NULL) {
-      window = (unsigned char FAR *)
-         ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
-      if (window == Z_NULL) {
-         ZFREE(source, copy);
-         return Z_MEM_ERROR;
-      }
-   }
-
-   /* copy state */
-   zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
-   zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
-   if (state->lencode >= state->codes &&
-         state->lencode <= state->codes + ENOUGH - 1) {
-      copy->lencode = copy->codes + (state->lencode - state->codes);
-      copy->distcode = copy->codes + (state->distcode - state->codes);
-   }
-   copy->next = copy->codes + (state->next - state->codes);
-   if (window != Z_NULL) {
-      wsize = 1U << state->wbits;
-      zmemcpy(window, state->window, wsize);
-   }
-   copy->window = window;
-   dest->state = (struct internal_state FAR *)copy;
-   return Z_OK;
-}
-
-int ZEXPORT inflateUndermine(z_streamp strm, int subvert)
-{
-   struct inflate_state FAR *state = NULL;
-
-   if (strm == Z_NULL || strm->state == Z_NULL)
-          return Z_STREAM_ERROR;
-   state = (struct inflate_state FAR *)strm->state;
-   state->sane = !subvert;
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
-   return Z_OK;
-#else
-   state->sane = 1;
-   return Z_DATA_ERROR;
-#endif
-}
-
-long ZEXPORT inflateMark(z_streamp strm)
-{
-   struct inflate_state FAR *state = NULL;
-
-   if (strm == Z_NULL || strm->state == Z_NULL)
-          return -1L << 16;
-   state = (struct inflate_state FAR *)strm->state;
-   return ((long)(state->back) << 16) +
-      (state->mode == COPY ? state->length :
-       (state->mode == MATCH ? state->was - state->length : 0));
-}
diff --git a/deps/zlib/inftrees.c b/deps/zlib/inftrees.c
deleted file mode 100644 (file)
index 8b8a964..0000000
+++ /dev/null
@@ -1,300 +0,0 @@
-/* inftrees.c -- generate Huffman trees for efficient decoding
- * Copyright (C) 1995-2013 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-#include "zutil.h"
-#include "inftrees.h"
-
-#define MAXBITS 15
-
-const char inflate_copyright[] =
-" inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
-/*
-   If you use the zlib library in a product, an acknowledgment is welcome
-   in the documentation of your product. If for some reason you cannot
-   include such an acknowledgment, I would appreciate that you keep this
-   copyright string in the executable of your product.
-   */
-
-/*
-   Build a set of tables to decode the provided canonical Huffman code.
-   The code lengths are lens[0..codes-1].  The result starts at *table,
-   whose indices are 0..2^bits-1.  work is a writable array of at least
-   lens shorts, which is used as a work area.  type is the type of code
-   to be generated, CODES, LENS, or DISTS.  On return, zero is success,
-   -1 is an invalid code, and +1 means that ENOUGH isn't enough.  table
-   on return points to the next available entry's address.  bits is the
-   requested root table index bits, and on return it is the actual root
-   table index bits.  It will differ if the request is greater than the
-   longest code or if it is less than the shortest code.
-   */
-int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR * FAR *table, unsigned FAR *bits, unsigned short FAR *work)
-{
-   unsigned len;               /* a code's length in bits */
-   unsigned sym;               /* index of code symbols */
-   unsigned min, max;          /* minimum and maximum code lengths */
-   unsigned root;              /* number of index bits for root table */
-   unsigned curr;              /* number of index bits for current table */
-   unsigned drop;              /* code bits to drop for sub-table */
-   int left;                   /* number of prefix codes available */
-   unsigned used;              /* code entries in table used */
-   unsigned huff;              /* Huffman code */
-   unsigned incr;              /* for incrementing code, index */
-   unsigned fill;              /* index for replicating entries */
-   unsigned low;               /* low bits for current root entry */
-   unsigned mask;              /* mask for low root bits */
-   code here;                  /* table entry for duplication */
-   code FAR *next;             /* next available space in table */
-   const unsigned short FAR *base;     /* base value table to use */
-   const unsigned short FAR *extra;    /* extra bits table to use */
-   int end;                    /* use base and extra for symbol > end */
-   unsigned short count[MAXBITS+1];    /* number of codes of each length */
-   unsigned short offs[MAXBITS+1];     /* offsets in table for each length */
-   static const unsigned short lbase[31] = { /* Length codes 257..285 base */
-      3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
-      35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
-   static const unsigned short lext[31] = { /* Length codes 257..285 extra */
-      16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
-      19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78};
-   static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
-      1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
-      257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
-      8193, 12289, 16385, 24577, 0, 0};
-   static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
-      16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
-      23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
-      28, 28, 29, 29, 64, 64};
-
-   /*
-      Process a set of code lengths to create a canonical Huffman code.  The
-      code lengths are lens[0..codes-1].  Each length corresponds to the
-      symbols 0..codes-1.  The Huffman code is generated by first sorting the
-      symbols by length from short to long, and retaining the symbol order
-      for codes with equal lengths.  Then the code starts with all zero bits
-      for the first code of the shortest length, and the codes are integer
-      increments for the same length, and zeros are appended as the length
-      increases.  For the deflate format, these bits are stored backwards
-      from their more natural integer increment ordering, and so when the
-      decoding tables are built in the large loop below, the integer codes
-      are incremented backwards.
-
-      This routine assumes, but does not check, that all of the entries in
-      lens[] are in the range 0..MAXBITS.  The caller must assure this.
-      1..MAXBITS is interpreted as that code length.  zero means that that
-      symbol does not occur in this code.
-
-      The codes are sorted by computing a count of codes for each length,
-      creating from that a table of starting indices for each length in the
-      sorted table, and then entering the symbols in order in the sorted
-      table.  The sorted table is work[], with that space being provided by
-      the caller.
-
-      The length counts are used for other purposes as well, i.e. finding
-      the minimum and maximum length codes, determining if there are any
-      codes at all, checking for a valid set of lengths, and looking ahead
-      at length counts to determine sub-table sizes when building the
-      decoding tables.
-      */
-
-   /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
-   for (len = 0; len <= MAXBITS; len++)
-      count[len] = 0;
-   for (sym = 0; sym < codes; sym++)
-      count[lens[sym]]++;
-
-   /* bound code lengths, force root to be within code lengths */
-   root = *bits;
-   for (max = MAXBITS; max >= 1; max--)
-      if (count[max] != 0) break;
-   if (root > max) root = max;
-   if (max == 0) {                     /* no symbols to code at all */
-      here.op = (unsigned char)64;    /* invalid code marker */
-      here.bits = (unsigned char)1;
-      here.val = (unsigned short)0;
-      *(*table)++ = here;             /* make a table to force an error */
-      *(*table)++ = here;
-      *bits = 1;
-      return 0;     /* no symbols, but wait for decoding to report error */
-   }
-   for (min = 1; min < max; min++)
-      if (count[min] != 0) break;
-   if (root < min) root = min;
-
-   /* check for an over-subscribed or incomplete set of lengths */
-   left = 1;
-   for (len = 1; len <= MAXBITS; len++) {
-      left <<= 1;
-      left -= count[len];
-      if (left < 0) return -1;        /* over-subscribed */
-   }
-   if (left > 0 && (type == CODES || max != 1))
-      return -1;                      /* incomplete set */
-
-   /* generate offsets into symbol table for each length for sorting */
-   offs[1] = 0;
-   for (len = 1; len < MAXBITS; len++)
-      offs[len + 1] = offs[len] + count[len];
-
-   /* sort symbols by length, by symbol order within each length */
-   for (sym = 0; sym < codes; sym++)
-      if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
-
-   /*
-      Create and fill in decoding tables.  In this loop, the table being
-      filled is at next and has curr index bits.  The code being used is huff
-      with length len.  That code is converted to an index by dropping drop
-      bits off of the bottom.  For codes where len is less than drop + curr,
-      those top drop + curr - len bits are incremented through all values to
-      fill the table with replicated entries.
-
-      root is the number of index bits for the root table.  When len exceeds
-      root, sub-tables are created pointed to by the root entry with an index
-      of the low root bits of huff.  This is saved in low to check for when a
-      new sub-table should be started.  drop is zero when the root table is
-      being filled, and drop is root when sub-tables are being filled.
-
-      When a new sub-table is needed, it is necessary to look ahead in the
-      code lengths to determine what size sub-table is needed.  The length
-      counts are used for this, and so count[] is decremented as codes are
-      entered in the tables.
-
-      used keeps track of how many table entries have been allocated from the
-      provided *table space.  It is checked for LENS and DIST tables against
-      the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
-      the initial root table size constants.  See the comments in inftrees.h
-      for more information.
-
-      sym increments through all symbols, and the loop terminates when
-      all codes of length max, i.e. all codes, have been processed.  This
-      routine permits incomplete codes, so another loop after this one fills
-      in the rest of the decoding tables with invalid code markers.
-      */
-
-   /* set up for code type */
-   switch (type) {
-      case CODES:
-         base = extra = work;    /* dummy value--not used */
-         end = 19;
-         break;
-      case LENS:
-         base = lbase;
-         base -= 257;
-         extra = lext;
-         extra -= 257;
-         end = 256;
-         break;
-      default:            /* DISTS */
-         base = dbase;
-         extra = dext;
-         end = -1;
-   }
-
-   /* initialize state for loop */
-   huff = 0;                   /* starting code */
-   sym = 0;                    /* starting code symbol */
-   len = min;                  /* starting code length */
-   next = *table;              /* current table to fill in */
-   curr = root;                /* current table index bits */
-   drop = 0;                   /* current bits to drop from code for index */
-   low = (unsigned)(-1);       /* trigger new sub-table when len > root */
-   used = 1U << root;          /* use root table entries */
-   mask = used - 1;            /* mask for comparing low */
-
-   /* check available table space */
-   if ((type == LENS && used > ENOUGH_LENS) ||
-         (type == DISTS && used > ENOUGH_DISTS))
-      return 1;
-
-   /* process all codes and make table entries */
-   for (;;) {
-      /* create table entry */
-      here.bits = (unsigned char)(len - drop);
-      if ((int)(work[sym]) < end) {
-         here.op = (unsigned char)0;
-         here.val = work[sym];
-      }
-      else if ((int)(work[sym]) > end) {
-         here.op = (unsigned char)(extra[work[sym]]);
-         here.val = base[work[sym]];
-      }
-      else {
-         here.op = (unsigned char)(32 + 64);         /* end of block */
-         here.val = 0;
-      }
-
-      /* replicate for those indices with low len bits equal to huff */
-      incr = 1U << (len - drop);
-      fill = 1U << curr;
-      min = fill;                 /* save offset to next table */
-      do {
-         fill -= incr;
-         next[(huff >> drop) + fill] = here;
-      } while (fill != 0);
-
-      /* backwards increment the len-bit code huff */
-      incr = 1U << (len - 1);
-      while (huff & incr)
-         incr >>= 1;
-      if (incr != 0) {
-         huff &= incr - 1;
-         huff += incr;
-      }
-      else
-         huff = 0;
-
-      /* go to next symbol, update count, len */
-      sym++;
-      if (--(count[len]) == 0) {
-         if (len == max) break;
-         len = lens[work[sym]];
-      }
-
-      /* create new sub-table if needed */
-      if (len > root && (huff & mask) != low) {
-         /* if first time, transition to sub-tables */
-         if (drop == 0)
-            drop = root;
-
-         /* increment past last table */
-         next += min;            /* here min is 1 << curr */
-
-         /* determine length of next table */
-         curr = len - drop;
-         left = (int)(1 << curr);
-         while (curr + drop < max) {
-            left -= count[curr + drop];
-            if (left <= 0) break;
-            curr++;
-            left <<= 1;
-         }
-
-         /* check for enough space */
-         used += 1U << curr;
-         if ((type == LENS && used > ENOUGH_LENS) ||
-               (type == DISTS && used > ENOUGH_DISTS))
-            return 1;
-
-         /* point entry in root table to sub-table */
-         low = huff & mask;
-         (*table)[low].op = (unsigned char)curr;
-         (*table)[low].bits = (unsigned char)root;
-         (*table)[low].val = (unsigned short)(next - *table);
-      }
-   }
-
-   /* fill in remaining table entry if code is incomplete (guaranteed to have
-      at most one remaining entry, since if the code is incomplete, the
-      maximum code length that was allowed to get this far is one bit) */
-   if (huff != 0) {
-      here.op = (unsigned char)64;            /* invalid code marker */
-      here.bits = (unsigned char)(len - drop);
-      here.val = (unsigned short)0;
-      next[huff] = here;
-   }
-
-   /* set return parameters */
-   *table += used;
-   *bits = root;
-   return 0;
-}
diff --git a/deps/zlib/ioapi.c b/deps/zlib/ioapi.c
deleted file mode 100644 (file)
index 767ac2f..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/* ioapi.h -- IO base function header for compress/uncompress .zip
-   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
-   Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
-   Modifications for Zip64 support
-   Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
-   For more info read MiniZip_info.txt
-
-*/
-
-#ifdef _WIN32
-#ifndef _CRT_SECURE_NO_WARNINGS
-#define _CRT_SECURE_NO_WARNINGS
-#endif
-#endif
-
-#include "ioapi.h"
-
-voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
-{
-   if (pfilefunc->zfile_func64.zopen64_file != NULL)
-      return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
-   else
-   {
-      return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
-   }
-}
-
-long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
-{
-   if (pfilefunc->zfile_func64.zseek64_file != NULL)
-      return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
-   else
-   {
-      uLong offsetTruncated = (uLong)offset;
-      if (offsetTruncated != offset)
-         return -1;
-      else
-         return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
-   }
-}
-
-ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
-{
-   if (pfilefunc->zfile_func64.zseek64_file != NULL)
-      return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
-   else
-   {
-      uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
-      if ((tell_uLong) == ((uLong)-1))
-         return (ZPOS64_T)-1;
-      else
-         return tell_uLong;
-   }
-}
-
-void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
-{
-   p_filefunc64_32->zfile_func64.zopen64_file = NULL;
-   p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
-   p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
-   p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
-   p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
-   p_filefunc64_32->zfile_func64.ztell64_file = NULL;
-   p_filefunc64_32->zfile_func64.zseek64_file = NULL;
-   p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
-   p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
-   p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
-   p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
-   p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
-}
-
-
-
-static voidpf  ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
-static uLong   ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-static uLong   ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
-static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
-static long    ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
-static int     ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
-static int     ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
-
-static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
-{
-   FILE* file = NULL;
-   const char* mode_fopen = NULL;
-   if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
-      mode_fopen = "rb";
-   else
-      if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
-         mode_fopen = "r+b";
-      else
-         if (mode & ZLIB_FILEFUNC_MODE_CREATE)
-            mode_fopen = "wb";
-
-   if ((filename!=NULL) && (mode_fopen != NULL))
-      file = fopen(filename, mode_fopen);
-   return file;
-}
-
-static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
-{
-   FILE* file = NULL;
-   const char* mode_fopen = NULL;
-   if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
-      mode_fopen = "rb";
-   else
-      if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
-         mode_fopen = "r+b";
-      else
-         if (mode & ZLIB_FILEFUNC_MODE_CREATE)
-            mode_fopen = "wb";
-
-   if ((filename!=NULL) && (mode_fopen != NULL))
-      file = fopen((const char*)filename, mode_fopen);
-   return file;
-}
-
-
-static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
-{
-   uLong ret;
-   ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
-   return ret;
-}
-
-static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
-{
-   uLong ret;
-   ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
-   return ret;
-}
-
-static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
-{
-   long ret;
-   ret = ftell((FILE *)stream);
-   return ret;
-}
-
-
-static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
-{
-   ZPOS64_T ret;
-   ret = ftell((FILE *)stream);
-   return ret;
-}
-
-static long ZCALLBACK fseek_file_func (voidpf  opaque, voidpf stream, uLong offset, int origin)
-{
-   int fseek_origin=0;
-   long ret;
-   switch (origin)
-   {
-      case ZLIB_FILEFUNC_SEEK_CUR :
-         fseek_origin = SEEK_CUR;
-         break;
-      case ZLIB_FILEFUNC_SEEK_END :
-         fseek_origin = SEEK_END;
-         break;
-      case ZLIB_FILEFUNC_SEEK_SET :
-         fseek_origin = SEEK_SET;
-         break;
-      default: return -1;
-   }
-   ret = 0;
-   if (fseek((FILE *)stream, offset, fseek_origin) != 0)
-      ret = -1;
-   return ret;
-}
-
-static long ZCALLBACK fseek64_file_func (voidpf  opaque, voidpf stream, ZPOS64_T offset, int origin)
-{
-   int fseek_origin=0;
-   long ret;
-   switch (origin)
-   {
-      case ZLIB_FILEFUNC_SEEK_CUR :
-         fseek_origin = SEEK_CUR;
-         break;
-      case ZLIB_FILEFUNC_SEEK_END :
-         fseek_origin = SEEK_END;
-         break;
-      case ZLIB_FILEFUNC_SEEK_SET :
-         fseek_origin = SEEK_SET;
-         break;
-      default: return -1;
-   }
-   ret = 0;
-
-   if(fseek((FILE *)stream, (long)offset, fseek_origin) != 0)
-      ret = -1;
-
-   return ret;
-}
-
-
-static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
-{
-   int ret;
-   ret = fclose((FILE *)stream);
-   return ret;
-}
-
-static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
-{
-   int ret;
-   ret = ferror((FILE *)stream);
-   return ret;
-}
-
-void fill_fopen_filefunc (zlib_filefunc_def *pzlib_filefunc_def)
-{
-   pzlib_filefunc_def->zopen_file = fopen_file_func;
-   pzlib_filefunc_def->zread_file = fread_file_func;
-   pzlib_filefunc_def->zwrite_file = fwrite_file_func;
-   pzlib_filefunc_def->ztell_file = ftell_file_func;
-   pzlib_filefunc_def->zseek_file = fseek_file_func;
-   pzlib_filefunc_def->zclose_file = fclose_file_func;
-   pzlib_filefunc_def->zerror_file = ferror_file_func;
-   pzlib_filefunc_def->opaque = NULL;
-}
-
-void fill_fopen64_filefunc (zlib_filefunc64_def*  pzlib_filefunc_def)
-{
-   pzlib_filefunc_def->zopen64_file = fopen64_file_func;
-   pzlib_filefunc_def->zread_file = fread_file_func;
-   pzlib_filefunc_def->zwrite_file = fwrite_file_func;
-   pzlib_filefunc_def->ztell64_file = ftell64_file_func;
-   pzlib_filefunc_def->zseek64_file = fseek64_file_func;
-   pzlib_filefunc_def->zclose_file = fclose_file_func;
-   pzlib_filefunc_def->zerror_file = ferror_file_func;
-   pzlib_filefunc_def->opaque = NULL;
-}
diff --git a/deps/zlib/ioapi.h b/deps/zlib/ioapi.h
deleted file mode 100644 (file)
index 8309c4c..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-/* ioapi.h -- IO base function header for compress/uncompress .zip
-   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
-         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
-         Modifications for Zip64 support
-         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
-         For more info read MiniZip_info.txt
-
-         Changes
-
-    Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
-    Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
-               More if/def section may be needed to support other platforms
-    Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
-                          (but you should use iowin32.c for windows instead)
-
-*/
-
-#ifndef _ZLIBIOAPI64_H
-#define _ZLIBIOAPI64_H
-
-#if (!defined(_WIN32)) && (!defined(WIN32))
-
-  // Linux needs this to support file operation on files larger then 4+GB
-  // But might need better if/def to select just the platforms that needs them.
-
-        #ifndef __USE_FILE_OFFSET64
-                #define __USE_FILE_OFFSET64
-        #endif
-        #ifndef __USE_LARGEFILE64
-                #define __USE_LARGEFILE64
-        #endif
-        #ifndef _LARGEFILE64_SOURCE
-                #define _LARGEFILE64_SOURCE
-        #endif
-        #ifndef _FILE_OFFSET_BIT
-                #define _FILE_OFFSET_BIT 64
-        #endif
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "zlib.h"
-
-#if defined(USE_FILE32API)
-#define fopen64 fopen
-#define ftello64 ftell
-#define fseeko64 fseek
-#else
-#ifdef _MSC_VER
- #define fopen64 fopen
- #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
-  #define ftello64 _ftelli64
-  #define fseeko64 _fseeki64
- #else // old MSC
-  #define ftello64 ftell
-  #define fseeko64 fseek
- #endif
-#endif
-#endif
-
-/*
-#ifndef ZPOS64_T
-  #ifdef _WIN32
-                #define ZPOS64_T fpos_t
-  #else
-    #include <stdint.h>
-    #define ZPOS64_T uint64_t
-  #endif
-#endif
-*/
-
-#ifdef HAVE_MINIZIP64_CONF_H
-#include "mz64conf.h"
-#endif
-
-/* a type choosen by DEFINE */
-#ifdef HAVE_64BIT_INT_CUSTOM
-typedef  64BIT_INT_CUSTOM_TYPE ZPOS64_T;
-#else
-#ifdef HAS_STDINT_H
-#include "stdint.h"
-typedef uint64_t ZPOS64_T;
-#else
-
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-typedef unsigned __int64 ZPOS64_T;
-#else
-typedef unsigned long long int ZPOS64_T;
-#endif
-#endif
-#endif
-
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define ZLIB_FILEFUNC_SEEK_CUR (1)
-#define ZLIB_FILEFUNC_SEEK_END (2)
-#define ZLIB_FILEFUNC_SEEK_SET (0)
-
-#define ZLIB_FILEFUNC_MODE_READ      (1)
-#define ZLIB_FILEFUNC_MODE_WRITE     (2)
-#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
-
-#define ZLIB_FILEFUNC_MODE_EXISTING (4)
-#define ZLIB_FILEFUNC_MODE_CREATE   (8)
-
-
-#ifndef ZCALLBACK
- #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
-   #define ZCALLBACK CALLBACK
- #else
-   #define ZCALLBACK
- #endif
-#endif
-
-
-
-
-typedef voidpf   (ZCALLBACK *open_file_func)      OF((voidpf opaque, const char* filename, int mode));
-typedef uLong    (ZCALLBACK *read_file_func)      OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-typedef uLong    (ZCALLBACK *write_file_func)     OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
-typedef int      (ZCALLBACK *close_file_func)     OF((voidpf opaque, voidpf stream));
-typedef int      (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
-
-typedef long     (ZCALLBACK *tell_file_func)      OF((voidpf opaque, voidpf stream));
-typedef long     (ZCALLBACK *seek_file_func)      OF((voidpf opaque, voidpf stream, uLong offset, int origin));
-
-
-/* here is the "old" 32 bits structure structure */
-typedef struct zlib_filefunc_def_s
-{
-    open_file_func      zopen_file;
-    read_file_func      zread_file;
-    write_file_func     zwrite_file;
-    tell_file_func      ztell_file;
-    seek_file_func      zseek_file;
-    close_file_func     zclose_file;
-    testerror_file_func zerror_file;
-    voidpf              opaque;
-} zlib_filefunc_def;
-
-typedef ZPOS64_T (ZCALLBACK *tell64_file_func)    OF((voidpf opaque, voidpf stream));
-typedef long     (ZCALLBACK *seek64_file_func)    OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
-typedef voidpf   (ZCALLBACK *open64_file_func)    OF((voidpf opaque, const void* filename, int mode));
-
-typedef struct zlib_filefunc64_def_s
-{
-    open64_file_func    zopen64_file;
-    read_file_func      zread_file;
-    write_file_func     zwrite_file;
-    tell64_file_func    ztell64_file;
-    seek64_file_func    zseek64_file;
-    close_file_func     zclose_file;
-    testerror_file_func zerror_file;
-    voidpf              opaque;
-} zlib_filefunc64_def;
-
-void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
-void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
-
-/* now internal definition, only for zip.c and unzip.h */
-typedef struct zlib_filefunc64_32_def_s
-{
-    zlib_filefunc64_def zfile_func64;
-    open_file_func      zopen32_file;
-    tell_file_func      ztell32_file;
-    seek_file_func      zseek32_file;
-} zlib_filefunc64_32_def;
-
-
-#define ZREAD64(filefunc,filestream,buf,size)     ((*((filefunc).zfile_func64.zread_file))   ((filefunc).zfile_func64.opaque,filestream,buf,size))
-#define ZWRITE64(filefunc,filestream,buf,size)    ((*((filefunc).zfile_func64.zwrite_file))  ((filefunc).zfile_func64.opaque,filestream,buf,size))
-//#define ZTELL64(filefunc,filestream)            ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
-//#define ZSEEK64(filefunc,filestream,pos,mode)   ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
-#define ZCLOSE64(filefunc,filestream)             ((*((filefunc).zfile_func64.zclose_file))  ((filefunc).zfile_func64.opaque,filestream))
-#define ZERROR64(filefunc,filestream)             ((*((filefunc).zfile_func64.zerror_file))  ((filefunc).zfile_func64.opaque,filestream))
-
-voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
-long    call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
-ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
-
-void    fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
-
-#define ZOPEN64(filefunc,filename,mode)         (call_zopen64((&(filefunc)),(filename),(mode)))
-#define ZTELL64(filefunc,filestream)            (call_ztell64((&(filefunc)),(filestream)))
-#define ZSEEK64(filefunc,filestream,pos,mode)   (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/deps/zlib/trees.c b/deps/zlib/trees.c
deleted file mode 100644 (file)
index fa41a13..0000000
+++ /dev/null
@@ -1,1177 +0,0 @@
-/* trees.c -- output deflated data using Huffman coding
- * Copyright (C) 1995-2012 Jean-loup Gailly
- * detect_data_type() function provided freely by Cosmin Truta, 2006
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/*
- *  ALGORITHM
- *
- *      The "deflation" process uses several Huffman trees. The more
- *      common source values are represented by shorter bit sequences.
- *
- *      Each code tree is stored in a compressed form which is itself
- * a Huffman encoding of the lengths of all the code strings (in
- * ascending order by source values).  The actual code strings are
- * reconstructed from the lengths in the inflate process, as described
- * in the deflate specification.
- *
- *  REFERENCES
- *
- *      Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
- *      Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
- *
- *      Storer, James A.
- *          Data Compression:  Methods and Theory, pp. 49-50.
- *          Computer Science Press, 1988.  ISBN 0-7167-8156-5.
- *
- *      Sedgewick, R.
- *          Algorithms, p290.
- *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
- */
-
-/* @(#) $Id$ */
-
-/* #define GEN_TREES_H */
-
-#include "deflate.h"
-
-#ifdef DEBUG
-#  include <ctype.h>
-#endif
-
-/* ===========================================================================
- * Constants
- */
-
-#define MAX_BL_BITS 7
-/* Bit length codes must not exceed MAX_BL_BITS bits */
-
-#define END_BLOCK 256
-/* end of block literal code */
-
-#define REP_3_6      16
-/* repeat previous bit length 3-6 times (2 bits of repeat count) */
-
-#define REPZ_3_10    17
-/* repeat a zero length 3-10 times  (3 bits of repeat count) */
-
-#define REPZ_11_138  18
-/* repeat a zero length 11-138 times  (7 bits of repeat count) */
-
-local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
-= {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
-
-local const int extra_dbits[D_CODES] /* extra bits for each distance code */
-= {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
-
-local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
-= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
-
-local const uch bl_order[BL_CODES]
-= {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
-/* The lengths of the bit length codes are sent in order of decreasing
- * probability, to avoid transmitting the lengths for unused bit length codes.
- */
-
-/* ===========================================================================
- * Local data. These are initialized only once.
- */
-
-#define DIST_CODE_LEN  512 /* see definition of array dist_code below */
-
-#if defined(GEN_TREES_H) || !defined(STDC)
-/* non ANSI compilers may not accept trees.h */
-
-local ct_data static_ltree[L_CODES+2];
-/* The static literal tree. Since the bit lengths are imposed, there is no
- * need for the L_CODES extra codes used during heap construction. However
- * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
- * below).
- */
-
-local ct_data static_dtree[D_CODES];
-/* The static distance tree. (Actually a trivial tree since all codes use
- * 5 bits.)
- */
-
-uch _dist_code[DIST_CODE_LEN];
-/* Distance codes. The first 256 values correspond to the distances
- * 3 .. 258, the last 256 values correspond to the top 8 bits of
- * the 15 bit distances.
- */
-
-uch _length_code[MAX_MATCH-MIN_MATCH+1];
-/* length code for each normalized match length (0 == MIN_MATCH) */
-
-local int base_length[LENGTH_CODES];
-/* First normalized length for each code (0 = MIN_MATCH) */
-
-local int base_dist[D_CODES];
-/* First normalized distance for each code (0 = distance of 1) */
-
-#else
-#  include "trees.h"
-#endif /* GEN_TREES_H */
-
-struct static_tree_desc_s {
-   const ct_data *static_tree;  /* static tree or NULL */
-   const intf *extra_bits;      /* extra bits for each code or NULL */
-   int     extra_base;          /* base index for extra_bits */
-   int     elems;               /* max number of elements in the tree */
-   int     max_length;          /* max bit length for the codes */
-};
-
-local static_tree_desc  static_l_desc =
-{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
-
-local static_tree_desc  static_d_desc =
-{static_dtree, extra_dbits, 0,          D_CODES, MAX_BITS};
-
-local static_tree_desc  static_bl_desc =
-{(const ct_data *)0, extra_blbits, 0,   BL_CODES, MAX_BL_BITS};
-
-/* ===========================================================================
- * Local (static) routines in this file.
- */
-
-local void tr_static_init OF((void));
-local void init_block     OF((deflate_state *s));
-local void pqdownheap     OF((deflate_state *s, ct_data *tree, int k));
-local void gen_bitlen     OF((deflate_state *s, tree_desc *desc));
-local void gen_codes      OF((ct_data *tree, int max_code, ushf *bl_count));
-local void build_tree     OF((deflate_state *s, tree_desc *desc));
-local void scan_tree      OF((deflate_state *s, ct_data *tree, int max_code));
-local void send_tree      OF((deflate_state *s, ct_data *tree, int max_code));
-local int  build_bl_tree  OF((deflate_state *s));
-local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
-         int blcodes));
-local void compress_block OF((deflate_state *s, const ct_data *ltree,
-         const ct_data *dtree));
-local int  detect_data_type OF((deflate_state *s));
-local unsigned bi_reverse OF((unsigned value, int length));
-local void bi_windup      OF((deflate_state *s));
-local void bi_flush       OF((deflate_state *s));
-local void copy_block     OF((deflate_state *s, charf *buf, unsigned len,
-         int header));
-
-#ifdef GEN_TREES_H
-local void gen_trees_header OF((void));
-#endif
-
-#ifndef DEBUG
-#  define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
-/* Send a code of the given tree. c and tree must not have side effects */
-
-#else /* DEBUG */
-#  define send_code(s, c, tree) \
-{ if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
-   send_bits(s, tree[c].Code, tree[c].Len); }
-#endif
-
-/* ===========================================================================
- * Output a short LSB first on the stream.
- * IN assertion: there is enough room in pendingBuf.
- */
-#define put_short(s, w) { \
-   put_byte(s, (uch)((w) & 0xff)); \
-   put_byte(s, (uch)((ush)(w) >> 8)); \
-}
-
-/* ===========================================================================
- * Send a value on a given number of bits.
- * IN assertion: length <= 16 and value fits in length bits.
- */
-#ifdef DEBUG
-local void send_bits      OF((deflate_state *s, int value, int length));
-
-local void send_bits(deflate_state *s, int value, int length)
-{
-   Tracevv((stderr," l %2d v %4x ", length, value));
-   Assert(length > 0 && length <= 15, "invalid length");
-   s->bits_sent += (ulg)length;
-
-   /* If not enough room in bi_buf, use (valid) bits from bi_buf and
-    * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
-    * unused bits in value.
-    */
-   if (s->bi_valid > (int)Buf_size - length) {
-      s->bi_buf |= (ush)value << s->bi_valid;
-      put_short(s, s->bi_buf);
-      s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
-      s->bi_valid += length - Buf_size;
-   } else {
-      s->bi_buf |= (ush)value << s->bi_valid;
-      s->bi_valid += length;
-   }
-}
-#else /* !DEBUG */
-
-#define send_bits(s, value, length) \
-{ int len = length;\
-   if (s->bi_valid > (int)Buf_size - len) {\
-      int val = value;\
-      s->bi_buf |= (ush)val << s->bi_valid;\
-      put_short(s, s->bi_buf);\
-      s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
-      s->bi_valid += len - Buf_size;\
-   } else {\
-      s->bi_buf |= (ush)(value) << s->bi_valid;\
-      s->bi_valid += len;\
-   }\
-}
-#endif /* DEBUG */
-
-
-/* the arguments must not have side effects */
-
-/* ===========================================================================
- * Initialize the various 'constant' tables.
- */
-local void tr_static_init(void)
-{
-#if defined(GEN_TREES_H) || !defined(STDC)
-   static int static_init_done = 0;
-   int n;        /* iterates over tree elements */
-   int bits;     /* bit counter */
-   int length;   /* length value */
-   int codes;    /* code value */
-   int dist;     /* distance index */
-   ush bl_count[MAX_BITS+1];
-   /* number of codes at each bit length for an optimal tree */
-
-   if (static_init_done) return;
-
-   /* For some embedded targets, global variables are not initialized: */
-#ifdef NO_INIT_GLOBAL_POINTERS
-   static_l_desc.static_tree = static_ltree;
-   static_l_desc.extra_bits = extra_lbits;
-   static_d_desc.static_tree = static_dtree;
-   static_d_desc.extra_bits = extra_dbits;
-   static_bl_desc.extra_bits = extra_blbits;
-#endif
-
-   /* Initialize the mapping length (0..255) -> length code (0..28) */
-   length = 0;
-   for (codes = 0; codes < LENGTH_CODES-1; codes++) {
-      base_length[codes] = length;
-      for (n = 0; n < (1<<extra_lbits[codes]); n++) {
-         _length_code[length++] = (uch)codes;
-      }
-   }
-   Assert (length == 256, "tr_static_init: length != 256");
-   /* Note that the length 255 (match length 258) can be represented
-    * in two different ways: code 284 + 5 bits or code 285, so we
-    * overwrite length_code[255] to use the best encoding:
-    */
-   _length_code[length-1] = (uch)codes;
-
-   /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
-   dist = 0;
-   for (codes = 0 ; codes < 16; codes++) {
-      base_dist[codes] = dist;
-      for (n = 0; n < (1<<extra_dbits[codes]); n++) {
-         _dist_code[dist++] = (uch)codes;
-      }
-   }
-   Assert (dist == 256, "tr_static_init: dist != 256");
-   dist >>= 7; /* from now on, all distances are divided by 128 */
-   for ( ; codes < D_CODES; codes++) {
-      base_dist[codes] = dist << 7;
-      for (n = 0; n < (1<<(extra_dbits[codes]-7)); n++) {
-         _dist_code[256 + dist++] = (uch)codes;
-      }
-   }
-   Assert (dist == 256, "tr_static_init: 256+dist != 512");
-
-   /* Construct the codes of the static literal tree */
-   for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
-   n = 0;
-   while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
-   while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
-   while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
-   while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
-   /* Codes 286 and 287 do not exist, but we must include them in the
-    * tree construction to get a canonical Huffman tree (longest code
-    * all ones)
-    */
-   gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
-
-   /* The static distance tree is trivial: */
-   for (n = 0; n < D_CODES; n++) {
-      static_dtree[n].Len = 5;
-      static_dtree[n].Code = bi_reverse((unsigned)n, 5);
-   }
-   static_init_done = 1;
-
-#  ifdef GEN_TREES_H
-   gen_trees_header();
-#  endif
-#endif /* defined(GEN_TREES_H) || !defined(STDC) */
-}
-
-/* ===========================================================================
- * Genererate the file trees.h describing the static trees.
- */
-#ifdef GEN_TREES_H
-#  ifndef DEBUG
-#    include <stdio.h>
-#  endif
-
-#  define SEPARATOR(i, last, width) \
-   ((i) == (last)? "\n};\n\n" :    \
-    ((i) % (width) == (width)-1 ? ",\n" : ", "))
-
-void gen_trees_header(void)
-{
-   FILE *header = fopen("trees.h", "w");
-   int i;
-
-   Assert (header != NULL, "Can't open trees.h");
-   fprintf(header,
-         "/* header created automatically with -DGEN_TREES_H */\n\n");
-
-   fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
-   for (i = 0; i < L_CODES+2; i++) {
-      fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
-            static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
-   }
-
-   fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
-   for (i = 0; i < D_CODES; i++) {
-      fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
-            static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
-   }
-
-   fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
-   for (i = 0; i < DIST_CODE_LEN; i++) {
-      fprintf(header, "%2u%s", _dist_code[i],
-            SEPARATOR(i, DIST_CODE_LEN-1, 20));
-   }
-
-   fprintf(header,
-         "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
-   for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
-      fprintf(header, "%2u%s", _length_code[i],
-            SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
-   }
-
-   fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
-   for (i = 0; i < LENGTH_CODES; i++) {
-      fprintf(header, "%1u%s", base_length[i],
-            SEPARATOR(i, LENGTH_CODES-1, 20));
-   }
-
-   fprintf(header, "local const int base_dist[D_CODES] = {\n");
-   for (i = 0; i < D_CODES; i++) {
-      fprintf(header, "%5u%s", base_dist[i],
-            SEPARATOR(i, D_CODES-1, 10));
-   }
-
-   fclose(header);
-}
-#endif /* GEN_TREES_H */
-
-/* ===========================================================================
- * Initialize the tree data structures for a new zlib stream.
- */
-void ZLIB_INTERNAL _tr_init(deflate_state *s)
-{
-   tr_static_init();
-
-   s->l_desc.dyn_tree = s->dyn_ltree;
-   s->l_desc.stat_desc = &static_l_desc;
-
-   s->d_desc.dyn_tree = s->dyn_dtree;
-   s->d_desc.stat_desc = &static_d_desc;
-
-   s->bl_desc.dyn_tree = s->bl_tree;
-   s->bl_desc.stat_desc = &static_bl_desc;
-
-   s->bi_buf = 0;
-   s->bi_valid = 0;
-#ifdef DEBUG
-   s->compressed_len = 0L;
-   s->bits_sent = 0L;
-#endif
-
-   /* Initialize the first block of the first file: */
-   init_block(s);
-}
-
-/* ===========================================================================
- * Initialize a new block.
- */
-local void init_block(deflate_state *s)
-{
-   int n; /* iterates over tree elements */
-
-   /* Initialize the trees. */
-   for (n = 0; n < L_CODES;  n++) s->dyn_ltree[n].Freq = 0;
-   for (n = 0; n < D_CODES;  n++) s->dyn_dtree[n].Freq = 0;
-   for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
-
-   s->dyn_ltree[END_BLOCK].Freq = 1;
-   s->opt_len = s->static_len = 0L;
-   s->last_lit = s->matches = 0;
-}
-
-#define SMALLEST 1
-/* Index within the heap array of least frequent node in the Huffman tree */
-
-
-/* ===========================================================================
- * Remove the smallest element from the heap and recreate the heap with
- * one less element. Updates heap and heap_len.
- */
-#define pqremove(s, tree, top) \
-{\
-   top = s->heap[SMALLEST]; \
-   s->heap[SMALLEST] = s->heap[s->heap_len--]; \
-   pqdownheap(s, tree, SMALLEST); \
-}
-
-/* ===========================================================================
- * Compares to subtrees, using the tree depth as tie breaker when
- * the subtrees have equal frequency. This minimizes the worst case length.
- */
-#define smaller(tree, n, m, depth) \
-   (tree[n].Freq < tree[m].Freq || \
-    (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
-
-/* ===========================================================================
- * Restore the heap property by moving down the tree starting at node k,
- * exchanging a node with the smallest of its two sons if necessary, stopping
- * when the heap property is re-established (each father smaller than its
- * two sons).
- */
-local void pqdownheap(deflate_state *s, ct_data *tree, int k)
-{
-   int v = s->heap[k];
-   int j = k << 1;  /* left son of k */
-   while (j <= s->heap_len) {
-      /* Set j to the smallest of the two sons: */
-      if (j < s->heap_len &&
-            smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
-         j++;
-      }
-      /* Exit if v is smaller than both sons */
-      if (smaller(tree, v, s->heap[j], s->depth)) break;
-
-      /* Exchange v with the smallest son */
-      s->heap[k] = s->heap[j];  k = j;
-
-      /* And continue down the tree, setting j to the left son of k */
-      j <<= 1;
-   }
-   s->heap[k] = v;
-}
-
-/* ===========================================================================
- * Compute the optimal bit lengths for a tree and update the total bit length
- * for the current block.
- * IN assertion: the fields freq and dad are set, heap[heap_max] and
- *    above are the tree nodes sorted by increasing frequency.
- * OUT assertions: the field len is set to the optimal bit length, the
- *     array bl_count contains the frequencies for each bit length.
- *     The length opt_len is updated; static_len is also updated if stree is
- *     not null.
- */
-local void gen_bitlen(deflate_state *s, tree_desc *desc)
-{
-   ct_data *tree        = desc->dyn_tree;
-   int max_code         = desc->max_code;
-   const ct_data *stree = desc->stat_desc->static_tree;
-   const intf *extra    = desc->stat_desc->extra_bits;
-   int base             = desc->stat_desc->extra_base;
-   int max_length       = desc->stat_desc->max_length;
-   int h;              /* heap index */
-   int n, m;           /* iterate over the tree elements */
-   int bits;           /* bit length */
-   int xbits;          /* extra bits */
-   ush f;              /* frequency */
-   int overflow = 0;   /* number of elements with bit length too large */
-
-   for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
-
-   /* In a first pass, compute the optimal bit lengths (which may
-    * overflow in the case of the bit length tree).
-    */
-   tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
-
-   for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
-      n = s->heap[h];
-      bits = tree[tree[n].Dad].Len + 1;
-      if (bits > max_length) bits = max_length, overflow++;
-      tree[n].Len = (ush)bits;
-      /* We overwrite tree[n].Dad which is no longer needed */
-
-      if (n > max_code) continue; /* not a leaf node */
-
-      s->bl_count[bits]++;
-      xbits = 0;
-      if (n >= base) xbits = extra[n-base];
-      f = tree[n].Freq;
-      s->opt_len += (ulg)f * (bits + xbits);
-      if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
-   }
-   if (overflow == 0) return;
-
-   Trace((stderr,"\nbit length overflow\n"));
-   /* This happens for example on obj2 and pic of the Calgary corpus */
-
-   /* Find the first bit length which could increase: */
-   do {
-      bits = max_length-1;
-      while (s->bl_count[bits] == 0) bits--;
-      s->bl_count[bits]--;      /* move one leaf down the tree */
-      s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
-      s->bl_count[max_length]--;
-      /* The brother of the overflow item also moves one step up,
-       * but this does not affect bl_count[max_length]
-       */
-      overflow -= 2;
-   } while (overflow > 0);
-
-   /* Now recompute all bit lengths, scanning in increasing frequency.
-    * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
-    * lengths instead of fixing only the wrong ones. This idea is taken
-    * from 'ar' written by Haruhiko Okumura.)
-    */
-   for (bits = max_length; bits != 0; bits--) {
-      n = s->bl_count[bits];
-      while (n != 0) {
-         m = s->heap[--h];
-         if (m > max_code) continue;
-         if ((unsigned) tree[m].Len != (unsigned) bits) {
-            Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
-            s->opt_len += ((long)bits - (long)tree[m].Len)
-               *(long)tree[m].Freq;
-            tree[m].Len = (ush)bits;
-         }
-         n--;
-      }
-   }
-}
-
-/* ===========================================================================
- * Generate the codes for a given tree and bit counts (which need not be
- * optimal).
- * IN assertion: the array bl_count contains the bit length statistics for
- * the given tree and the field len is set for all tree elements.
- * OUT assertion: the field code is set for all tree elements of non
- *     zero code length.
- */
-local void gen_codes (ct_data *tree, int max_code, ushf *bl_count)
-{
-   ush next_code[MAX_BITS+1]; /* next code value for each bit length */
-   ush codes = 0;              /* running code value */
-   int bits;                  /* bit index */
-   int n;                     /* code index */
-
-   /* The distribution counts are first used to generate the code values
-    * without bit reversal.
-    */
-   for (bits = 1; bits <= MAX_BITS; bits++) {
-      next_code[bits] = codes = (codes + bl_count[bits-1]) << 1;
-   }
-   /* Check that the bit counts in bl_count are consistent. The last code
-    * must be all ones.
-    */
-   Assert (codes + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
-         "inconsistent bit counts");
-   Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
-
-   for (n = 0;  n <= max_code; n++) {
-      int len = tree[n].Len;
-      if (len == 0) continue;
-      /* Now reverse the bits */
-      tree[n].Code = bi_reverse(next_code[len]++, len);
-
-      Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
-               n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
-   }
-}
-
-/* ===========================================================================
- * Construct one Huffman tree and assigns the code bit strings and lengths.
- * Update the total bit length for the current block.
- * IN assertion: the field freq is set for all tree elements.
- * OUT assertions: the fields len and code are set to the optimal bit length
- *     and corresponding code. The length opt_len is updated; static_len is
- *     also updated if stree is not null. The field max_code is set.
- */
-local void build_tree(deflate_state *s, tree_desc *desc)
-{
-   ct_data *tree         = desc->dyn_tree;
-   const ct_data *stree  = desc->stat_desc->static_tree;
-   int elems             = desc->stat_desc->elems;
-   int n, m;          /* iterate over heap elements */
-   int max_code = -1; /* largest code with non zero frequency */
-   int node;          /* new node being created */
-
-   /* Construct the initial heap, with least frequent element in
-    * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
-    * heap[0] is not used.
-    */
-   s->heap_len = 0, s->heap_max = HEAP_SIZE;
-
-   for (n = 0; n < elems; n++) {
-      if (tree[n].Freq != 0) {
-         s->heap[++(s->heap_len)] = max_code = n;
-         s->depth[n] = 0;
-      } else {
-         tree[n].Len = 0;
-      }
-   }
-
-   /* The pkzip format requires that at least one distance code exists,
-    * and that at least one bit should be sent even if there is only one
-    * possible code. So to avoid special checks later on we force at least
-    * two codes of non zero frequency.
-    */
-   while (s->heap_len < 2) {
-      node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
-      tree[node].Freq = 1;
-      s->depth[node] = 0;
-      s->opt_len--; if (stree) s->static_len -= stree[node].Len;
-      /* node is 0 or 1 so it does not have extra bits */
-   }
-   desc->max_code = max_code;
-
-   /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
-    * establish sub-heaps of increasing lengths:
-    */
-   for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
-
-   /* Construct the Huffman tree by repeatedly combining the least two
-    * frequent nodes.
-    */
-   node = elems;              /* next internal node of the tree */
-   do {
-      pqremove(s, tree, n);  /* n = node of least frequency */
-      m = s->heap[SMALLEST]; /* m = node of next least frequency */
-
-      s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
-      s->heap[--(s->heap_max)] = m;
-
-      /* Create a new node father of n and m */
-      tree[node].Freq = tree[n].Freq + tree[m].Freq;
-      s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
-               s->depth[n] : s->depth[m]) + 1);
-      tree[n].Dad = tree[m].Dad = (ush)node;
-#ifdef DUMP_BL_TREE
-      if (tree == s->bl_tree) {
-         fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
-               node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
-      }
-#endif
-      /* and insert the new node in the heap */
-      s->heap[SMALLEST] = node++;
-      pqdownheap(s, tree, SMALLEST);
-
-   } while (s->heap_len >= 2);
-
-   s->heap[--(s->heap_max)] = s->heap[SMALLEST];
-
-   /* At this point, the fields freq and dad are set. We can now
-    * generate the bit lengths.
-    */
-   gen_bitlen(s, (tree_desc *)desc);
-
-   /* The field len is now set, we can generate the bit codes */
-   gen_codes ((ct_data *)tree, max_code, s->bl_count);
-}
-
-/* ===========================================================================
- * Scan a literal or distance tree to determine the frequencies of the codes
- * in the bit length tree.
- */
-local void scan_tree (deflate_state *s, ct_data *tree, int max_code)
-{
-   int n;                     /* iterates over all tree elements */
-   int prevlen = -1;          /* last emitted length */
-   int curlen;                /* length of current code */
-   int nextlen = tree[0].Len; /* length of next code */
-   int count = 0;             /* repeat count of the current code */
-   int max_count = 7;         /* max repeat count */
-   int min_count = 4;         /* min repeat count */
-
-   if (nextlen == 0) max_count = 138, min_count = 3;
-   tree[max_code+1].Len = (ush)0xffff; /* guard */
-
-   for (n = 0; n <= max_code; n++) {
-      curlen = nextlen; nextlen = tree[n+1].Len;
-      if (++count < max_count && curlen == nextlen) {
-         continue;
-      } else if (count < min_count) {
-         s->bl_tree[curlen].Freq += count;
-      } else if (curlen != 0) {
-         if (curlen != prevlen) s->bl_tree[curlen].Freq++;
-         s->bl_tree[REP_3_6].Freq++;
-      } else if (count <= 10) {
-         s->bl_tree[REPZ_3_10].Freq++;
-      } else {
-         s->bl_tree[REPZ_11_138].Freq++;
-      }
-      count = 0; prevlen = curlen;
-      if (nextlen == 0) {
-         max_count = 138, min_count = 3;
-      } else if (curlen == nextlen) {
-         max_count = 6, min_count = 3;
-      } else {
-         max_count = 7, min_count = 4;
-      }
-   }
-}
-
-/* ===========================================================================
- * Send a literal or distance tree in compressed form, using the codes in
- * bl_tree.
- */
-local void send_tree (deflate_state *s, ct_data *tree, int max_code)
-{
-   int n;                     /* iterates over all tree elements */
-   int prevlen = -1;          /* last emitted length */
-   int curlen;                /* length of current code */
-   int nextlen = tree[0].Len; /* length of next code */
-   int count = 0;             /* repeat count of the current code */
-   int max_count = 7;         /* max repeat count */
-   int min_count = 4;         /* min repeat count */
-
-   /* tree[max_code+1].Len = -1; */  /* guard already set */
-   if (nextlen == 0) max_count = 138, min_count = 3;
-
-   for (n = 0; n <= max_code; n++) {
-      curlen = nextlen; nextlen = tree[n+1].Len;
-      if (++count < max_count && curlen == nextlen) {
-         continue;
-      } else if (count < min_count) {
-         do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
-
-      } else if (curlen != 0) {
-         if (curlen != prevlen) {
-            send_code(s, curlen, s->bl_tree); count--;
-         }
-         Assert(count >= 3 && count <= 6, " 3_6?");
-         send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
-
-      } else if (count <= 10) {
-         send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
-
-      } else {
-         send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
-      }
-      count = 0; prevlen = curlen;
-      if (nextlen == 0) {
-         max_count = 138, min_count = 3;
-      } else if (curlen == nextlen) {
-         max_count = 6, min_count = 3;
-      } else {
-         max_count = 7, min_count = 4;
-      }
-   }
-}
-
-/* ===========================================================================
- * Construct the Huffman tree for the bit lengths and return the index in
- * bl_order of the last bit length code to send.
- */
-local int build_bl_tree(deflate_state *s)
-{
-   int max_blindex;  /* index of last bit length code of non zero freq */
-
-   /* Determine the bit length frequencies for literal and distance trees */
-   scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
-   scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
-
-   /* Build the bit length tree: */
-   build_tree(s, (tree_desc *)(&(s->bl_desc)));
-   /* opt_len now includes the length of the tree representations, except
-    * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
-    */
-
-   /* Determine the number of bit length codes to send. The pkzip format
-    * requires that at least 4 bit length codes be sent. (appnote.txt says
-    * 3 but the actual value used is 4.)
-    */
-   for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
-      if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
-   }
-   /* Update opt_len to include the bit length tree and counts */
-   s->opt_len += 3*(max_blindex+1) + 5+5+4;
-   Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
-            s->opt_len, s->static_len));
-
-   return max_blindex;
-}
-
-/* ===========================================================================
- * Send the header for a block using dynamic Huffman trees: the counts, the
- * lengths of the bit length codes, the literal tree and the distance tree.
- * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
- */
-local void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes)
-{
-   int rank;                    /* index in bl_order */
-
-   Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
-   Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
-         "too many codes");
-   Tracev((stderr, "\nbl counts: "));
-   send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
-   send_bits(s, dcodes-1,   5);
-   send_bits(s, blcodes-4,  4); /* not -3 as stated in appnote.txt */
-   for (rank = 0; rank < blcodes; rank++) {
-      Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
-      send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
-   }
-   Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
-
-   send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
-   Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
-
-   send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
-   Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
-}
-
-/* ===========================================================================
- * Send a stored block
- */
-void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
-{
-   send_bits(s, (STORED_BLOCK<<1)+last, 3);    /* send block type */
-#ifdef DEBUG
-   s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
-   s->compressed_len += (stored_len + 4) << 3;
-#endif
-   copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
-}
-
-/* ===========================================================================
- * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
- */
-void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s)
-{
-   bi_flush(s);
-}
-
-/* ===========================================================================
- * Send one empty static block to give enough lookahead for inflate.
- * This takes 10 bits, of which 7 may remain in the bit buffer.
- */
-void ZLIB_INTERNAL _tr_align(deflate_state *s)
-{
-   send_bits(s, STATIC_TREES<<1, 3);
-   send_code(s, END_BLOCK, static_ltree);
-#ifdef DEBUG
-   s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
-#endif
-   bi_flush(s);
-}
-
-/* ===========================================================================
- * Determine the best encoding for the current block: dynamic trees, static
- * trees or store, and output the encoded block to the zip file.
- */
-void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len, int last)
-{
-   ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
-   int max_blindex = 0;  /* index of last bit length code of non zero freq */
-
-   /* Build the Huffman trees unless a stored block is forced */
-   if (s->level > 0) {
-
-      /* Check if the file is binary or text */
-      if (s->strm->data_type == Z_UNKNOWN)
-         s->strm->data_type = detect_data_type(s);
-
-      /* Construct the literal and distance trees */
-      build_tree(s, (tree_desc *)(&(s->l_desc)));
-      Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
-               s->static_len));
-
-      build_tree(s, (tree_desc *)(&(s->d_desc)));
-      Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
-               s->static_len));
-      /* At this point, opt_len and static_len are the total bit lengths of
-       * the compressed block data, excluding the tree representations.
-       */
-
-      /* Build the bit length tree for the above two trees, and get the index
-       * in bl_order of the last bit length code to send.
-       */
-      max_blindex = build_bl_tree(s);
-
-      /* Determine the best encoding. Compute the block lengths in bytes. */
-      opt_lenb = (s->opt_len+3+7)>>3;
-      static_lenb = (s->static_len+3+7)>>3;
-
-      Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
-               opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
-               s->last_lit));
-
-      if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
-
-   } else {
-      Assert(buf != (char*)0, "lost buf");
-      opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
-   }
-
-#ifdef FORCE_STORED
-   if (buf != (char*)0) { /* force stored block */
-#else
-      if (stored_len+4 <= opt_lenb && buf != (char*)0) {
-         /* 4: two words for the lengths */
-#endif
-         /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
-          * Otherwise we can't have processed more than WSIZE input bytes since
-          * the last block flush, because compression would have been
-          * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
-          * transform a block into a stored block.
-          */
-         _tr_stored_block(s, buf, stored_len, last);
-
-#ifdef FORCE_STATIC
-      } else if (static_lenb >= 0) { /* force static trees */
-#else
-      } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
-#endif
-         send_bits(s, (STATIC_TREES<<1)+last, 3);
-         compress_block(s, (const ct_data *)static_ltree,
-               (const ct_data *)static_dtree);
-#ifdef DEBUG
-         s->compressed_len += 3 + s->static_len;
-#endif
-      } else {
-         send_bits(s, (DYN_TREES<<1)+last, 3);
-         send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
-               max_blindex+1);
-         compress_block(s, (const ct_data *)s->dyn_ltree,
-               (const ct_data *)s->dyn_dtree);
-#ifdef DEBUG
-         s->compressed_len += 3 + s->opt_len;
-#endif
-      }
-      Assert (s->compressed_len == s->bits_sent, "bad compressed size");
-      /* The above check is made mod 2^32, for files larger than 512 MB
-       * and uLong implemented on 32 bits.
-       */
-      init_block(s);
-
-      if (last) {
-         bi_windup(s);
-#ifdef DEBUG
-         s->compressed_len += 7;  /* align on byte boundary */
-#endif
-      }
-      Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
-               s->compressed_len-7*last));
-   }
-
-   /* ===========================================================================
-    * Save the match info and tally the frequency counts. Return true if
-    * the current block must be flushed.
-    */
-   int ZLIB_INTERNAL _tr_tally (deflate_state *s, unsigned dist, unsigned lc)
-   {
-      s->d_buf[s->last_lit] = (ush)dist;
-      s->l_buf[s->last_lit++] = (uch)lc;
-      if (dist == 0) {
-         /* lc is the unmatched char */
-         s->dyn_ltree[lc].Freq++;
-      } else {
-         s->matches++;
-         /* Here, lc is the match length - MIN_MATCH */
-         dist--;             /* dist = match distance - 1 */
-         Assert((ush)dist < (ush)MAX_DIST(s) &&
-               (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
-               (ush)d_code(dist) < (ush)D_CODES,  "_tr_tally: bad match");
-
-         s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
-         s->dyn_dtree[d_code(dist)].Freq++;
-      }
-
-#ifdef TRUNCATE_BLOCK
-      /* Try to guess if it is profitable to stop the current block here */
-      if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
-         /* Compute an upper bound for the compressed length */
-         ulg out_length = (ulg)s->last_lit*8L;
-         ulg in_length = (ulg)((long)s->strstart - s->block_start);
-         int dcode;
-         for (dcode = 0; dcode < D_CODES; dcode++) {
-            out_length += (ulg)s->dyn_dtree[dcode].Freq *
-               (5L+extra_dbits[dcode]);
-         }
-         out_length >>= 3;
-         Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
-                  s->last_lit, in_length, out_length,
-                  100L - out_length*100L/in_length));
-         if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
-      }
-#endif
-      return (s->last_lit == s->lit_bufsize-1);
-      /* We avoid equality with lit_bufsize because of wraparound at 64K
-       * on 16 bit machines and because stored blocks are restricted to
-       * 64K-1 bytes.
-       */
-   }
-
-   /* ===========================================================================
-    * Send the block data compressed using the given Huffman trees
-    */
-   local void compress_block(deflate_state *s, const ct_data *ltree, const ct_data *dtree)
-   {
-      unsigned dist;      /* distance of matched string */
-      int lc;             /* match length or unmatched char (if dist == 0) */
-      unsigned lx = 0;    /* running index in l_buf */
-      unsigned codes;      /* the code to send */
-      int extra;          /* number of extra bits to send */
-
-      if (s->last_lit != 0) do {
-         dist = s->d_buf[lx];
-         lc = s->l_buf[lx++];
-         if (dist == 0) {
-            send_code(s, lc, ltree); /* send a literal byte */
-            Tracecv(isgraph(lc), (stderr," '%c' ", lc));
-         } else {
-            /* Here, lc is the match length - MIN_MATCH */
-            codes = _length_code[lc];
-            send_code(s, codes + LITERALS+1, ltree); /* send the length code */
-            extra = extra_lbits[codes];
-            if (extra != 0) {
-               lc -= base_length[codes];
-               send_bits(s, lc, extra);       /* send the extra length bits */
-            }
-            dist--; /* dist is now the match distance - 1 */
-            codes = d_code(dist);
-            Assert (codes < D_CODES, "bad d_code");
-
-            send_code(s, codes, dtree);       /* send the distance code */
-            extra = extra_dbits[codes];
-            if (extra != 0) {
-               dist -= base_dist[codes];
-               send_bits(s, dist, extra);   /* send the extra distance bits */
-            }
-         } /* literal or match pair ? */
-
-         /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
-         Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
-               "pendingBuf overflow");
-
-      } while (lx < s->last_lit);
-
-      send_code(s, END_BLOCK, ltree);
-   }
-
-   /* ===========================================================================
-    * Check if the data type is TEXT or BINARY, using the following algorithm:
-    * - TEXT if the two conditions below are satisfied:
-    *    a) There are no non-portable control characters belonging to the
-    *       "black list" (0..6, 14..25, 28..31).
-    *    b) There is at least one printable character belonging to the
-    *       "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
-    * - BINARY otherwise.
-    * - The following partially-portable control characters form a
-    *   "gray list" that is ignored in this detection algorithm:
-    *   (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
-    * IN assertion: the fields Freq of dyn_ltree are set.
-    */
-   local int detect_data_type(deflate_state *s)
-   {
-      /* black_mask is the bit mask of black-listed bytes
-       * set bits 0..6, 14..25, and 28..31
-       * 0xf3ffc07f = binary 11110011111111111100000001111111
-       */
-      unsigned long black_mask = 0xf3ffc07fUL;
-      int n;
-
-      /* Check for non-textual ("black-listed") bytes. */
-      for (n = 0; n <= 31; n++, black_mask >>= 1)
-         if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0))
-            return Z_BINARY;
-
-      /* Check for textual ("white-listed") bytes. */
-      if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
-            || s->dyn_ltree[13].Freq != 0)
-         return Z_TEXT;
-      for (n = 32; n < LITERALS; n++)
-         if (s->dyn_ltree[n].Freq != 0)
-            return Z_TEXT;
-
-      /* There are no "black-listed" or "white-listed" bytes:
-       * this stream either is empty or has tolerated ("gray-listed") bytes only.
-       */
-      return Z_BINARY;
-   }
-
-   /* ===========================================================================
-    * Reverse the first len bits of a code, using straightforward code (a faster
-    * method would use a table)
-    * IN assertion: 1 <= len <= 15
-    */
-   local unsigned bi_reverse(unsigned codes, int len)
-   {
-      register unsigned res = 0;
-      do {
-         res |= codes & 1;
-         codes >>= 1, res <<= 1;
-      } while (--len > 0);
-      return res >> 1;
-   }
-
-   /* ===========================================================================
-    * Flush the bit buffer, keeping at most 7 bits in it.
-    */
-   local void bi_flush(deflate_state *s)
-   {
-      if (s->bi_valid == 16) {
-         put_short(s, s->bi_buf);
-         s->bi_buf = 0;
-         s->bi_valid = 0;
-      } else if (s->bi_valid >= 8) {
-         put_byte(s, (Byte)s->bi_buf);
-         s->bi_buf >>= 8;
-         s->bi_valid -= 8;
-      }
-   }
-
-   /* ===========================================================================
-    * Flush the bit buffer and align the output on a byte boundary
-    */
-   local void bi_windup(deflate_state *s)
-   {
-      if (s->bi_valid > 8) {
-         put_short(s, s->bi_buf);
-      } else if (s->bi_valid > 0) {
-         put_byte(s, (Byte)s->bi_buf);
-      }
-      s->bi_buf = 0;
-      s->bi_valid = 0;
-#ifdef DEBUG
-      s->bits_sent = (s->bits_sent+7) & ~7;
-#endif
-   }
-
-   /* ===========================================================================
-    * Copy a stored block, storing first the length and its
-    * one's complement if requested.
-    */
-   local void copy_block(deflate_state *s, charf *buf, unsigned len, int header)
-   {
-      bi_windup(s);        /* align on byte boundary */
-
-      if (header) {
-         put_short(s, (ush)len);
-         put_short(s, (ush)~len);
-#ifdef DEBUG
-         s->bits_sent += 2*16;
-#endif
-      }
-#ifdef DEBUG
-      s->bits_sent += (ulg)len<<3;
-#endif
-      while (len--) {
-         put_byte(s, *buf++);
-      }
-   }
diff --git a/deps/zlib/uncompr.c b/deps/zlib/uncompr.c
deleted file mode 100644 (file)
index c7e30b3..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/* uncompr.c -- decompress a memory buffer
- * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#define ZLIB_INTERNAL
-#include "zlib.h"
-
-/* ===========================================================================
-   Decompresses the source buffer into the destination buffer.  sourceLen is
-   the byte length of the source buffer. Upon entry, destLen is the total
-   size of the destination buffer, which must be large enough to hold the
-   entire uncompressed data. (The size of the uncompressed data must have
-   been saved previously by the compressor and transmitted to the decompressor
-   by some mechanism outside the scope of this compression library.)
-   Upon exit, destLen is the actual size of the compressed buffer.
-
-   uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_BUF_ERROR if there was not enough room in the output
-   buffer, or Z_DATA_ERROR if the input data was corrupted.
-   */
-int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
-{
-   z_stream stream;
-   int err;
-
-   stream.next_in = (Bytef *)source;
-   stream.avail_in = (uInt)sourceLen;
-   /* Check for source > 64K on 16-bit machine: */
-   if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
-
-   stream.next_out = dest;
-   stream.avail_out = (uInt)*destLen;
-   if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
-
-   stream.zalloc = Z_NULL;
-   stream.zfree = Z_NULL;
-
-   err = inflateInit(&stream);
-   if (err != Z_OK) return err;
-
-   err = inflate(&stream, Z_FINISH);
-   if (err != Z_STREAM_END) {
-      inflateEnd(&stream);
-      if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
-         return Z_DATA_ERROR;
-      return err;
-   }
-   *destLen = stream.total_out;
-
-   err = inflateEnd(&stream);
-   return err;
-}
diff --git a/deps/zlib/unzip.c b/deps/zlib/unzip.c
deleted file mode 100644 (file)
index ba6abbf..0000000
+++ /dev/null
@@ -1,2126 +0,0 @@
-/* unzip.c -- IO for uncompress .zip files using zlib
-   Version 1.1, February 14h, 2010
-   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
-   Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
-   Modifications of Unzip for Zip64
-   Copyright (C) 2007-2008 Even Rouault
-
-   Modifications for Zip64 support on both zip and unzip
-   Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
-   For more info read MiniZip_info.txt
-
-
-   ------------------------------------------------------------------------------------
-   Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
-   compatibility with older software. The following is from the original crypt.c.
-   Code woven in by Terry Thorsen 1/2003.
-
-   Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.
-
-   See the accompanying file LICENSE, version 2000-Apr-09 or later
-   (the contents of which are also included in zip.h) for terms of use.
-   If, for some reason, all these files are missing, the Info-ZIP license
-   also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
-
-   crypt.c (full version) by Info-ZIP.      Last revised:  [see crypt.h]
-
-   The encryption/decryption parts of this source code (as opposed to the
-   non-echoing password parts) were originally written in Europe.  The
-   whole source package can be freely distributed, including from the USA.
-   (Prior to January 2000, re-export from the US was a violation of US law.)
-
-   This encryption code is a direct transcription of the algorithm from
-   Roger Schlafly, described by Phil Katz in the file appnote.txt.  This
-   file (appnote.txt) is distributed with the PKZIP program (even in the
-   version without encryption capabilities).
-
-   ------------------------------------------------------------------------------------
-
-   Changes in unzip.c
-
-   2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
-   2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
-   2007-2008 - Even Rouault - Remove old C style function prototypes
-   2007-2008 - Even Rouault - Add unzip support for ZIP64
-
-   Copyright (C) 2007-2008 Even Rouault
-
-
-   Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
-   Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
-   should only read the compressed/uncompressed size from the Zip64 format if
-   the size from normal header was 0xFFFFFFFF
-   Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
-   Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
-   Patch created by Daniel Borca
-
-   Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
-
-   Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
-
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef NOUNCRYPT
-#define NOUNCRYPT
-#endif
-
-#include "zlib.h"
-#include "unzip.h"
-
-#ifdef STDC
-#  include <stddef.h>
-#  include <string.h>
-#  include <stdlib.h>
-#endif
-#ifdef NO_ERRNO_H
-extern int errno;
-#else
-#   include <errno.h>
-#endif
-
-
-#ifndef local
-#  define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-
-#ifndef CASESENSITIVITYDEFAULT_NO
-#  if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
-#    define CASESENSITIVITYDEFAULT_NO
-#  endif
-#endif
-
-
-#ifndef UNZ_BUFSIZE
-#define UNZ_BUFSIZE (16384)
-#endif
-
-#ifndef UNZ_MAXFILENAMEINZIP
-#define UNZ_MAXFILENAMEINZIP (256)
-#endif
-
-#ifndef ALLOC
-# define ALLOC(size) (malloc(size))
-#endif
-#ifndef TRYFREE
-# define TRYFREE(p) {if (p) free(p);}
-#endif
-
-#define SIZECENTRALDIRITEM (0x2e)
-#define SIZEZIPLOCALHEADER (0x1e)
-
-
-const char unz_copyright[] =
-" unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
-
-/* unz_file_info_interntal contain internal info about a file in zipfile*/
-typedef struct unz_file_info64_internal_s
-{
-   ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
-} unz_file_info64_internal;
-
-
-/* file_in_zip_read_info_s contain internal information about a file in zipfile,
-   when reading and decompress it */
-typedef struct
-{
-   char  *read_buffer;         /* internal buffer for compressed data */
-   z_stream stream;            /* zLib stream structure for inflate */
-
-#ifdef HAVE_BZIP2
-   bz_stream bstream;          /* bzLib stream structure for bziped */
-#endif
-
-   ZPOS64_T pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/
-   uLong stream_initialised;   /* flag set if stream structure is initialised*/
-
-   ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
-   uInt  size_local_extrafield;/* size of the local extra field */
-   ZPOS64_T pos_local_extrafield;   /* position in the local extra field in read*/
-   ZPOS64_T total_out_64;
-
-   uLong crc32;                /* crc32 of all data uncompressed */
-   uLong crc32_wait;           /* crc32 we must obtain after decompress all */
-   ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
-   ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
-   zlib_filefunc64_32_def z_filefunc;
-   voidpf filestream;        /* io structore of the zipfile */
-   uLong compression_method;   /* compression method (0==store) */
-   ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
-   int   raw;
-} file_in_zip64_read_info_s;
-
-
-/* unz64_s contain internal information about the zipfile
-*/
-typedef struct
-{
-   zlib_filefunc64_32_def z_filefunc;
-   int is64bitOpenFunction;
-   voidpf filestream;        /* io structore of the zipfile */
-   unz_global_info64 gi;       /* public global information */
-   ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
-   ZPOS64_T num_file;             /* number of the current file in the zipfile*/
-   ZPOS64_T pos_in_central_dir;   /* pos of the current file in the central dir*/
-   ZPOS64_T current_file_ok;      /* flag about the usability of the current file*/
-   ZPOS64_T central_pos;          /* position of the beginning of the central dir*/
-
-   ZPOS64_T size_central_dir;     /* size of the central directory  */
-   ZPOS64_T offset_central_dir;   /* offset of start of central directory with
-                                     respect to the starting disk number */
-
-   unz_file_info64 cur_file_info; /* public info about the current file in zip*/
-   unz_file_info64_internal cur_file_info_internal; /* private info about it*/
-   file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
-                                                    file if we are decompressing it */
-   int encrypted;
-
-   int isZip64;
-
-#    ifndef NOUNCRYPT
-   unsigned long keys[3];     /* keys defining the pseudo-random sequence */
-   const unsigned long* pcrc_32_tab;
-#    endif
-} unz64_s;
-
-
-#ifndef NOUNCRYPT
-#include "crypt.h"
-#endif
-
-/* ===========================================================================
-   Read a byte from a gz_stream; update next_in and avail_in. Return EOF
-   for end of file.
-   IN assertion: the stream s has been sucessfully opened for reading.
-   */
-
-
-local int unz64local_getByte OF((
-         const zlib_filefunc64_32_def* pzlib_filefunc_def,
-         voidpf filestream,
-         int *pi));
-
-local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,
-                             voidpf filestream, int *_pi)
-{
-   unsigned char c;
-   int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
-   if (err==1)
-   {
-      *_pi = (int)c;
-      return UNZ_OK;
-   }
-   else
-   {
-      if (ZERROR64(*pzlib_filefunc_def,filestream))
-         return UNZ_ERRNO;
-      else
-         return UNZ_EOF;
-   }
-}
-
-
-/* ===========================================================================
-   Reads a long in LSB order from the given gz_stream. Sets
-   */
-local int unz64local_getShort OF((
-         const zlib_filefunc64_32_def* pzlib_filefunc_def,
-         voidpf filestream,
-         uLong *pX));
-
-local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
-      voidpf filestream,
-      uLong *pX)
-{
-   uLong x ;
-   int i = 0;
-   int err;
-
-   err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x = (uLong)i;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((uLong)i)<<8;
-
-   if (err==UNZ_OK)
-      *pX = x;
-   else
-      *pX = 0;
-   return err;
-}
-
-local int unz64local_getLong OF((
-         const zlib_filefunc64_32_def* pzlib_filefunc_def,
-         voidpf filestream,
-         uLong *pX));
-
-local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
-      voidpf filestream,
-      uLong *pX)
-{
-   uLong x ;
-   int i = 0;
-   int err;
-
-   err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x = (uLong)i;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((uLong)i)<<8;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((uLong)i)<<16;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x += ((uLong)i)<<24;
-
-   if (err==UNZ_OK)
-      *pX = x;
-   else
-      *pX = 0;
-   return err;
-}
-
-local int unz64local_getLong64 OF((
-         const zlib_filefunc64_32_def* pzlib_filefunc_def,
-         voidpf filestream,
-         ZPOS64_T *pX));
-
-
-local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
-      voidpf filestream,
-      ZPOS64_T *pX)
-{
-   ZPOS64_T x ;
-   int i = 0;
-   int err;
-
-   err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x = (ZPOS64_T)i;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((ZPOS64_T)i)<<8;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((ZPOS64_T)i)<<16;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((ZPOS64_T)i)<<24;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((ZPOS64_T)i)<<32;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((ZPOS64_T)i)<<40;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((ZPOS64_T)i)<<48;
-
-   if (err==UNZ_OK)
-      err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
-   x |= ((ZPOS64_T)i)<<56;
-
-   if (err==UNZ_OK)
-      *pX = x;
-   else
-      *pX = 0;
-   return err;
-}
-
-/* My own strcmpi / strcasecmp */
-local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
-{
-   for (;;)
-   {
-      char c1=*(fileName1++);
-      char c2=*(fileName2++);
-      if ((c1>='a') && (c1<='z'))
-         c1 -= 0x20;
-      if ((c2>='a') && (c2<='z'))
-         c2 -= 0x20;
-      if (c1=='\0')
-         return ((c2=='\0') ? 0 : -1);
-      if (c2=='\0')
-         return 1;
-      if (c1<c2)
-         return -1;
-      if (c1>c2)
-         return 1;
-   }
-}
-
-
-#ifdef  CASESENSITIVITYDEFAULT_NO
-#define CASESENSITIVITYDEFAULTVALUE 2
-#else
-#define CASESENSITIVITYDEFAULTVALUE 1
-#endif
-
-#ifndef STRCMPCASENOSENTIVEFUNCTION
-#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
-#endif
-
-/*
-   Compare two filename (fileName1,fileName2).
-   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
-   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
-   or strcasecmp)
-   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
-   (like 1 on Unix, 2 on Windows)
-
-*/
-extern int ZEXPORT unzStringFileNameCompare (const char*  fileName1,
-      const char*  fileName2,
-      int iCaseSensitivity)
-
-{
-   if (iCaseSensitivity==0)
-      iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
-
-   if (iCaseSensitivity==1)
-      return strcmp(fileName1,fileName2);
-
-   return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
-}
-
-#ifndef BUFREADCOMMENT
-#define BUFREADCOMMENT (0x400)
-#endif
-
-/*
-   Locate the Central directory of a zipfile (at the end, just before
-   the global comment)
-   */
-local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
-local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
-{
-   unsigned char* buf;
-   ZPOS64_T uSizeFile;
-   ZPOS64_T uBackRead;
-   ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
-   ZPOS64_T uPosFound=0;
-
-   if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
-      return 0;
-
-
-   uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
-   if (uMaxBack>uSizeFile)
-      uMaxBack = uSizeFile;
-
-   buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
-   if (buf==NULL)
-      return 0;
-
-   uBackRead = 4;
-   while (uBackRead<uMaxBack)
-   {
-      uLong uReadSize;
-      ZPOS64_T uReadPos ;
-      int i;
-      if (uBackRead+BUFREADCOMMENT>uMaxBack)
-         uBackRead = uMaxBack;
-      else
-         uBackRead+=BUFREADCOMMENT;
-      uReadPos = uSizeFile-uBackRead ;
-
-      uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
-         (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
-      if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
-         break;
-
-      if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
-         break;
-
-      for (i=(int)uReadSize-3; (i--)>0;)
-         if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
-               ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
-         {
-            uPosFound = uReadPos+i;
-            break;
-         }
-
-      if (uPosFound!=0)
-         break;
-   }
-   TRYFREE(buf);
-   return uPosFound;
-}
-
-
-/*
-   Locate the Central directory 64 of a zipfile (at the end, just before
-   the global comment)
-   */
-local ZPOS64_T unz64local_SearchCentralDir64 OF((
-         const zlib_filefunc64_32_def* pzlib_filefunc_def,
-         voidpf filestream));
-
-local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
-      voidpf filestream)
-{
-   unsigned char* buf;
-   ZPOS64_T uSizeFile;
-   ZPOS64_T uBackRead;
-   ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
-   ZPOS64_T uPosFound=0;
-   uLong uL;
-   ZPOS64_T relativeOffset;
-
-   if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
-      return 0;
-
-
-   uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
-   if (uMaxBack>uSizeFile)
-      uMaxBack = uSizeFile;
-
-   buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
-   if (buf==NULL)
-      return 0;
-
-   uBackRead = 4;
-   while (uBackRead<uMaxBack)
-   {
-      uLong uReadSize;
-      ZPOS64_T uReadPos;
-      int i;
-      if (uBackRead+BUFREADCOMMENT>uMaxBack)
-         uBackRead = uMaxBack;
-      else
-         uBackRead+=BUFREADCOMMENT;
-      uReadPos = uSizeFile-uBackRead ;
-
-      uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
-         (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
-      if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
-         break;
-
-      if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
-         break;
-
-      for (i=(int)uReadSize-3; (i--)>0;)
-         if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
-               ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
-         {
-            uPosFound = uReadPos+i;
-            break;
-         }
-
-      if (uPosFound!=0)
-         break;
-   }
-   TRYFREE(buf);
-   if (uPosFound == 0)
-      return 0;
-
-   /* Zip64 end of central directory locator */
-   if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
-      return 0;
-
-   /* the signature, already checked */
-   if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
-      return 0;
-
-   /* number of the disk with the start of the zip64 end of  central directory */
-   if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
-      return 0;
-   if (uL != 0)
-      return 0;
-
-   /* relative offset of the zip64 end of central directory record */
-   if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
-      return 0;
-
-   /* total number of disks */
-   if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
-      return 0;
-   if (uL != 1)
-      return 0;
-
-   /* Goto end of central directory record */
-   if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
-      return 0;
-
-   /* the signature */
-   if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
-      return 0;
-
-   if (uL != 0x06064b50)
-      return 0;
-
-   return relativeOffset;
-}
-
-/*
-   Open a Zip file. path contain the full pathname (by example,
-   on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
-   "zlib/zlib114.zip".
-   If the zipfile cannot be opened (file doesn't exist or in not valid), the
-   return value is NULL.
-   Else, the return value is a unzFile Handle, usable with other function
-   of this unzip package.
-   */
-local unzFile unzOpenInternal (const void *path,
-      zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
-      int is64bitOpenFunction)
-{
-   unz64_s us;
-   unz64_s *s;
-   ZPOS64_T central_pos;
-   uLong   uL;
-
-   uLong number_disk;          /* number of the current dist, used for
-                                  spaning ZIP, unsupported, always 0*/
-   uLong number_disk_with_CD;  /* number the the disk with central dir, used
-                                  for spaning ZIP, unsupported, always 0*/
-   ZPOS64_T number_entry_CD;      /* total number of entries in
-                                     the central dir
-                                     (same than number_entry on nospan) */
-
-   int err=UNZ_OK;
-
-   if (unz_copyright[0]!=' ')
-      return NULL;
-
-   us.z_filefunc.zseek32_file = NULL;
-   us.z_filefunc.ztell32_file = NULL;
-   if (pzlib_filefunc64_32_def==NULL)
-      fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
-   else
-      us.z_filefunc = *pzlib_filefunc64_32_def;
-   us.is64bitOpenFunction = is64bitOpenFunction;
-
-
-
-   us.filestream = ZOPEN64(us.z_filefunc,
-         path,
-         ZLIB_FILEFUNC_MODE_READ |
-         ZLIB_FILEFUNC_MODE_EXISTING);
-   if (us.filestream==NULL)
-      return NULL;
-
-   central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
-   if (central_pos)
-   {
-      uLong uS;
-      ZPOS64_T uL64;
-
-      us.isZip64 = 1;
-
-      if (ZSEEK64(us.z_filefunc, us.filestream,
-               central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
-         err=UNZ_ERRNO;
-
-      /* the signature, already checked */
-      if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* size of zip64 end of central directory record */
-      if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* version made by */
-      if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* version needed to extract */
-      if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* number of this disk */
-      if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* number of the disk with the start of the central directory */
-      if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* total number of entries in the central directory on this disk */
-      if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* total number of entries in the central directory */
-      if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      if ((number_entry_CD!=us.gi.number_entry) ||
-            (number_disk_with_CD!=0) ||
-            (number_disk!=0))
-         err=UNZ_BADZIPFILE;
-
-      /* size of the central directory */
-      if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* offset of start of central directory with respect to the
-         starting disk number */
-      if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      us.gi.size_comment = 0;
-   }
-   else
-   {
-      central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
-      if (central_pos==0)
-         err=UNZ_ERRNO;
-
-      us.isZip64 = 0;
-
-      if (ZSEEK64(us.z_filefunc, us.filestream,
-               central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
-         err=UNZ_ERRNO;
-
-      /* the signature, already checked */
-      if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* number of this disk */
-      if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* number of the disk with the start of the central directory */
-      if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
-         err=UNZ_ERRNO;
-
-      /* total number of entries in the central dir on this disk */
-      if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
-         err=UNZ_ERRNO;
-      us.gi.number_entry = uL;
-
-      /* total number of entries in the central dir */
-      if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
-         err=UNZ_ERRNO;
-      number_entry_CD = uL;
-
-      if ((number_entry_CD!=us.gi.number_entry) ||
-            (number_disk_with_CD!=0) ||
-            (number_disk!=0))
-         err=UNZ_BADZIPFILE;
-
-      /* size of the central directory */
-      if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
-         err=UNZ_ERRNO;
-      us.size_central_dir = uL;
-
-      /* offset of start of central directory with respect to the
-         starting disk number */
-      if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
-         err=UNZ_ERRNO;
-      us.offset_central_dir = uL;
-
-      /* zipfile comment length */
-      if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
-         err=UNZ_ERRNO;
-   }
-
-   if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
-         (err==UNZ_OK))
-      err=UNZ_BADZIPFILE;
-
-   if (err!=UNZ_OK)
-   {
-      ZCLOSE64(us.z_filefunc, us.filestream);
-      return NULL;
-   }
-
-   us.byte_before_the_zipfile = central_pos -
-      (us.offset_central_dir+us.size_central_dir);
-   us.central_pos = central_pos;
-   us.pfile_in_zip_read = NULL;
-   us.encrypted = 0;
-
-
-   s=(unz64_s*)ALLOC(sizeof(unz64_s));
-   if( s != NULL)
-   {
-      *s=us;
-      unzGoToFirstFile((unzFile)s);
-   }
-   return (unzFile)s;
-}
-
-
-extern unzFile ZEXPORT unzOpen2 (const char *path,
-      zlib_filefunc_def* pzlib_filefunc32_def)
-{
-   if (pzlib_filefunc32_def != NULL)
-   {
-      zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
-      fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
-      return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
-   }
-   else
-      return unzOpenInternal(path, NULL, 0);
-}
-
-extern unzFile ZEXPORT unzOpen2_64 (const void *path,
-      zlib_filefunc64_def* pzlib_filefunc_def)
-{
-   if (pzlib_filefunc_def != NULL)
-   {
-      zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
-      zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
-      zlib_filefunc64_32_def_fill.ztell32_file = NULL;
-      zlib_filefunc64_32_def_fill.zseek32_file = NULL;
-      return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
-   }
-   else
-      return unzOpenInternal(path, NULL, 1);
-}
-
-extern unzFile ZEXPORT unzOpen (const char *path)
-{
-   return unzOpenInternal(path, NULL, 0);
-}
-
-extern unzFile ZEXPORT unzOpen64 (const void *path)
-{
-   return unzOpenInternal(path, NULL, 1);
-}
-
-/*
-   Close a ZipFile opened with unzipOpen.
-   If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
-   these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
-   return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzClose (unzFile file)
-{
-   unz64_s* s;
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-
-   if (s->pfile_in_zip_read!=NULL)
-      unzCloseCurrentFile(file);
-
-   ZCLOSE64(s->z_filefunc, s->filestream);
-   TRYFREE(s);
-   return UNZ_OK;
-}
-
-
-/*
-   Write info about the ZipFile in the *pglobal_info structure.
-   No preparation of the structure is needed
-   return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
-{
-   unz64_s* s;
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   *pglobal_info=s->gi;
-   return UNZ_OK;
-}
-
-extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
-{
-   unz64_s* s;
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   /* to do : check if number_entry is not truncated */
-   pglobal_info32->number_entry = (uLong)s->gi.number_entry;
-   pglobal_info32->size_comment = s->gi.size_comment;
-   return UNZ_OK;
-}
-/*
-   Translate date/time from Dos format to tm_unz (readable more easilty)
-   */
-local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
-{
-   ZPOS64_T uDate;
-   uDate = (ZPOS64_T)(ulDosDate>>16);
-   ptm->tm_mday = (uInt)(uDate&0x1f) ;
-   ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
-   ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
-
-   ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
-   ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
-   ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;
-}
-
-/*
-   Get Info about the current file in the zipfile, with internal only info
-   */
-local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
-         unz_file_info64 *pfile_info,
-         unz_file_info64_internal
-         *pfile_info_internal,
-         char *szFileName,
-         uLong fileNameBufferSize,
-         void *extraField,
-         uLong extraFieldBufferSize,
-         char *szComment,
-         uLong commentBufferSize));
-
-local int unz64local_GetCurrentFileInfoInternal (unzFile file,
-      unz_file_info64 *pfile_info,
-      unz_file_info64_internal
-      *pfile_info_internal,
-      char *szFileName,
-      uLong fileNameBufferSize,
-      void *extraField,
-      uLong extraFieldBufferSize,
-      char *szComment,
-      uLong commentBufferSize)
-{
-   unz64_s* s;
-   unz_file_info64 file_info;
-   unz_file_info64_internal file_info_internal;
-   int err=UNZ_OK;
-   uLong uMagic;
-   long lSeek=0;
-   uLong uL;
-
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   if (ZSEEK64(s->z_filefunc, s->filestream,
-            s->pos_in_central_dir+s->byte_before_the_zipfile,
-            ZLIB_FILEFUNC_SEEK_SET)!=0)
-      err=UNZ_ERRNO;
-
-
-   /* we check the magic */
-   if (err==UNZ_OK)
-   {
-      if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
-         err=UNZ_ERRNO;
-      else if (uMagic!=0x02014b50)
-         err=UNZ_BADZIPFILE;
-   }
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
-
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
-      err=UNZ_ERRNO;
-   file_info.compressed_size = uL;
-
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
-      err=UNZ_ERRNO;
-   file_info.uncompressed_size = uL;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   // relative offset of local header
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
-      err=UNZ_ERRNO;
-   file_info_internal.offset_curfile = uL;
-
-   lSeek+=file_info.size_filename;
-   if ((err==UNZ_OK) && (szFileName!=NULL))
-   {
-      uLong uSizeRead ;
-      if (file_info.size_filename<fileNameBufferSize)
-      {
-         *(szFileName+file_info.size_filename)='\0';
-         uSizeRead = file_info.size_filename;
-      }
-      else
-         uSizeRead = fileNameBufferSize;
-
-      if ((file_info.size_filename>0) && (fileNameBufferSize>0))
-         if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
-            err=UNZ_ERRNO;
-      lSeek -= uSizeRead;
-   }
-
-   // Read extrafield
-   if ((err==UNZ_OK) && (extraField!=NULL))
-   {
-      ZPOS64_T uSizeRead ;
-      if (file_info.size_file_extra<extraFieldBufferSize)
-         uSizeRead = file_info.size_file_extra;
-      else
-         uSizeRead = extraFieldBufferSize;
-
-      if (lSeek!=0)
-      {
-         if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
-            lSeek=0;
-         else
-            err=UNZ_ERRNO;
-      }
-
-      if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
-         if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
-            err=UNZ_ERRNO;
-
-      lSeek += file_info.size_file_extra - (uLong)uSizeRead;
-   }
-   else
-      lSeek += file_info.size_file_extra;
-
-
-   if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
-   {
-      uLong acc = 0;
-
-      // since lSeek now points to after the extra field we need to move back
-      lSeek -= file_info.size_file_extra;
-
-      if (lSeek!=0)
-      {
-         if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
-            lSeek=0;
-         else
-            err=UNZ_ERRNO;
-      }
-
-      while(acc < file_info.size_file_extra)
-      {
-         uLong headerId;
-         uLong dataSize;
-
-         if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
-            err=UNZ_ERRNO;
-
-         if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
-            err=UNZ_ERRNO;
-
-         /* ZIP64 extra fields */
-         if (headerId == 0x0001)
-         {
-            uLong tmp;
-
-            if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1)
-            {
-               if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
-                  err=UNZ_ERRNO;
-            }
-
-            if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1)
-            {
-               if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
-                  err=UNZ_ERRNO;
-            }
-
-            if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1)
-            {
-               /* Relative Header offset */
-               if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
-                  err=UNZ_ERRNO;
-            }
-
-            if(file_info.disk_num_start == (unsigned long)-1)
-            {
-               /* Disk Start Number */
-               if (unz64local_getLong(&s->z_filefunc, s->filestream,&tmp) != UNZ_OK)
-                  err=UNZ_ERRNO;
-            }
-
-         }
-         else
-         {
-            if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
-               err=UNZ_ERRNO;
-         }
-
-         acc += 2 + 2 + dataSize;
-      }
-   }
-
-   if ((err==UNZ_OK) && (szComment!=NULL))
-   {
-      uLong uSizeRead ;
-      if (file_info.size_file_comment<commentBufferSize)
-      {
-         *(szComment+file_info.size_file_comment)='\0';
-         uSizeRead = file_info.size_file_comment;
-      }
-      else
-         uSizeRead = commentBufferSize;
-
-      if (lSeek!=0)
-      {
-         if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
-            lSeek=0;
-         else
-            err=UNZ_ERRNO;
-      }
-
-      if ((file_info.size_file_comment>0) && (commentBufferSize>0))
-         if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
-            err=UNZ_ERRNO;
-      lSeek+=file_info.size_file_comment - uSizeRead;
-   }
-   else
-      lSeek+=file_info.size_file_comment;
-
-
-   if ((err==UNZ_OK) && (pfile_info!=NULL))
-      *pfile_info=file_info;
-
-   if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
-      *pfile_info_internal=file_info_internal;
-
-   return err;
-}
-
-
-
-/*
-   Write info about the ZipFile in the *pglobal_info structure.
-   No preparation of the structure is needed
-   return UNZ_OK if there is no problem.
-   */
-extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
-      unz_file_info64 * pfile_info,
-      char * szFileName, uLong fileNameBufferSize,
-      void *extraField, uLong extraFieldBufferSize,
-      char* szComment,  uLong commentBufferSize)
-{
-   return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
-         szFileName,fileNameBufferSize,
-         extraField,extraFieldBufferSize,
-         szComment,commentBufferSize);
-}
-
-extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
-      unz_file_info * pfile_info,
-      char * szFileName, uLong fileNameBufferSize,
-      void *extraField, uLong extraFieldBufferSize,
-      char* szComment,  uLong commentBufferSize)
-{
-   int err;
-   unz_file_info64 file_info64;
-   err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
-         szFileName,fileNameBufferSize,
-         extraField,extraFieldBufferSize,
-         szComment,commentBufferSize);
-   if (err==UNZ_OK)
-   {
-      pfile_info->version = file_info64.version;
-      pfile_info->version_needed = file_info64.version_needed;
-      pfile_info->flag = file_info64.flag;
-      pfile_info->compression_method = file_info64.compression_method;
-      pfile_info->dosDate = file_info64.dosDate;
-      pfile_info->crc = file_info64.crc;
-
-      pfile_info->size_filename = file_info64.size_filename;
-      pfile_info->size_file_extra = file_info64.size_file_extra;
-      pfile_info->size_file_comment = file_info64.size_file_comment;
-
-      pfile_info->disk_num_start = file_info64.disk_num_start;
-      pfile_info->internal_fa = file_info64.internal_fa;
-      pfile_info->external_fa = file_info64.external_fa;
-
-      pfile_info->tmu_date = file_info64.tmu_date,
-
-
-         pfile_info->compressed_size = (uLong)file_info64.compressed_size;
-      pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
-
-   }
-   return err;
-}
-/*
-   Set the current file of the zipfile to the first file.
-   return UNZ_OK if there is no problem
-   */
-extern int ZEXPORT unzGoToFirstFile (unzFile file)
-{
-   int err=UNZ_OK;
-   unz64_s* s;
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   s->pos_in_central_dir=s->offset_central_dir;
-   s->num_file=0;
-   err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
-         &s->cur_file_info_internal,
-         NULL,0,NULL,0,NULL,0);
-   s->current_file_ok = (err == UNZ_OK);
-   return err;
-}
-
-/*
-   Set the current file of the zipfile to the next file.
-   return UNZ_OK if there is no problem
-   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-   */
-extern int ZEXPORT unzGoToNextFile (unzFile  file)
-{
-   unz64_s* s;
-   int err;
-
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   if (!s->current_file_ok)
-      return UNZ_END_OF_LIST_OF_FILE;
-   if (s->gi.number_entry != 0xffff)    /* 2^16 files overflow hack */
-      if (s->num_file+1==s->gi.number_entry)
-         return UNZ_END_OF_LIST_OF_FILE;
-
-   s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
-      s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
-   s->num_file++;
-   err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
-         &s->cur_file_info_internal,
-         NULL,0,NULL,0,NULL,0);
-   s->current_file_ok = (err == UNZ_OK);
-   return err;
-}
-
-
-/*
-   Try locate the file szFileName in the zipfile.
-   For the iCaseSensitivity signification, see unzipStringFileNameCompare
-
-   return value :
-   UNZ_OK if the file is found. It becomes the current file.
-   UNZ_END_OF_LIST_OF_FILE if the file is not found
-   */
-extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
-{
-   unz64_s* s;
-   int err;
-
-   /* We remember the 'current' position in the file so that we can jump
-    * back there if we fail.
-    */
-   unz_file_info64 cur_file_infoSaved;
-   unz_file_info64_internal cur_file_info_internalSaved;
-   ZPOS64_T num_fileSaved;
-   ZPOS64_T pos_in_central_dirSaved;
-
-
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-
-   if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
-      return UNZ_PARAMERROR;
-
-   s=(unz64_s*)file;
-   if (!s->current_file_ok)
-      return UNZ_END_OF_LIST_OF_FILE;
-
-   /* Save the current state */
-   num_fileSaved = s->num_file;
-   pos_in_central_dirSaved = s->pos_in_central_dir;
-   cur_file_infoSaved = s->cur_file_info;
-   cur_file_info_internalSaved = s->cur_file_info_internal;
-
-   err = unzGoToFirstFile(file);
-
-   while (err == UNZ_OK)
-   {
-      char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
-      err = unzGetCurrentFileInfo64(file,NULL,
-            szCurrentFileName,sizeof(szCurrentFileName)-1,
-            NULL,0,NULL,0);
-      if (err == UNZ_OK)
-      {
-         if (unzStringFileNameCompare(szCurrentFileName,
-                  szFileName,iCaseSensitivity)==0)
-            return UNZ_OK;
-         err = unzGoToNextFile(file);
-      }
-   }
-
-   /* We failed, so restore the state of the 'current file' to where we
-    * were.
-    */
-   s->num_file = num_fileSaved ;
-   s->pos_in_central_dir = pos_in_central_dirSaved ;
-   s->cur_file_info = cur_file_infoSaved;
-   s->cur_file_info_internal = cur_file_info_internalSaved;
-   return err;
-}
-
-
-/*
-///////////////////////////////////////////
-// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
-// I need random access
-//
-// Further optimization could be realized by adding an ability
-// to cache the directory in memory. The goal being a single
-// comprehensive file read to put the file I need in a memory.
-*/
-
-/*
-   typedef struct unz_file_pos_s
-   {
-   ZPOS64_T pos_in_zip_directory;   // offset in file
-   ZPOS64_T num_of_file;            // # of file
-   } unz_file_pos;
-   */
-
-extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos*  file_pos)
-{
-   unz64_s* s;
-
-   if (file==NULL || file_pos==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   if (!s->current_file_ok)
-      return UNZ_END_OF_LIST_OF_FILE;
-
-   file_pos->pos_in_zip_directory  = s->pos_in_central_dir;
-   file_pos->num_of_file           = s->num_file;
-
-   return UNZ_OK;
-}
-
-extern int ZEXPORT unzGetFilePos(
-      unzFile file,
-      unz_file_pos* file_pos)
-{
-   unz64_file_pos file_pos64;
-   int err = unzGetFilePos64(file,&file_pos64);
-   if (err==UNZ_OK)
-   {
-      file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
-      file_pos->num_of_file = (uLong)file_pos64.num_of_file;
-   }
-   return err;
-}
-
-extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
-{
-   unz64_s* s;
-   int err;
-
-   if (file==NULL || file_pos==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-
-   /* jump to the right spot */
-   s->pos_in_central_dir = file_pos->pos_in_zip_directory;
-   s->num_file           = file_pos->num_of_file;
-
-   /* set the current file */
-   err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
-         &s->cur_file_info_internal,
-         NULL,0,NULL,0,NULL,0);
-   /* return results */
-   s->current_file_ok = (err == UNZ_OK);
-   return err;
-}
-
-extern int ZEXPORT unzGoToFilePos(
-      unzFile file,
-      unz_file_pos* file_pos)
-{
-   unz64_file_pos file_pos64;
-   if (file_pos == NULL)
-      return UNZ_PARAMERROR;
-
-   file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
-   file_pos64.num_of_file = file_pos->num_of_file;
-   return unzGoToFilePos64(file,&file_pos64);
-}
-
-/*
-// Unzip Helper Functions - should be here?
-///////////////////////////////////////////
-*/
-
-/*
-   Read the local header of the current zipfile
-   Check the coherency of the local header and info in the end of central
-   directory about this file
-   store in *piSizeVar the size of extra info in local header
-   (filename and size of extra field data)
-   */
-local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
-      ZPOS64_T * poffset_local_extrafield,
-      uInt  * psize_local_extrafield)
-{
-   uLong uMagic,uData,uFlags;
-   uLong size_filename;
-   uLong size_extra_field;
-   int err=UNZ_OK;
-
-   *piSizeVar = 0;
-   *poffset_local_extrafield = 0;
-   *psize_local_extrafield = 0;
-
-   if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
-            s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
-      return UNZ_ERRNO;
-
-
-   if (err==UNZ_OK)
-   {
-      if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
-         err=UNZ_ERRNO;
-      else if (uMagic!=0x04034b50)
-         err=UNZ_BADZIPFILE;
-   }
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
-      err=UNZ_ERRNO;
-   /*
-      else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
-      err=UNZ_BADZIPFILE;
-      */
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
-      err=UNZ_ERRNO;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
-      err=UNZ_ERRNO;
-   else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
-      err=UNZ_BADZIPFILE;
-
-   if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
-         /* #ifdef HAVE_BZIP2 */
-         (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
-         /* #endif */
-         (s->cur_file_info.compression_method!=Z_DEFLATED))
-      err=UNZ_BADZIPFILE;
-
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
-      err=UNZ_ERRNO;
-
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
-      err=UNZ_ERRNO;
-   else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
-      err=UNZ_BADZIPFILE;
-
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
-      err=UNZ_ERRNO;
-   else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
-      err=UNZ_BADZIPFILE;
-
-   if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
-      err=UNZ_ERRNO;
-   else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
-      err=UNZ_BADZIPFILE;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
-      err=UNZ_ERRNO;
-   else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
-      err=UNZ_BADZIPFILE;
-
-   *piSizeVar += (uInt)size_filename;
-
-   if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
-      err=UNZ_ERRNO;
-   *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
-      SIZEZIPLOCALHEADER + size_filename;
-   *psize_local_extrafield = (uInt)size_extra_field;
-
-   *piSizeVar += (uInt)size_extra_field;
-
-   return err;
-}
-
-/*
-   Open for reading data the current file in the zipfile.
-   If there is no error and the file is opened, the return value is UNZ_OK.
-   */
-extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
-      int* level, int raw, const char* password)
-{
-   int err=UNZ_OK;
-   uInt iSizeVar;
-   unz64_s* s;
-   file_in_zip64_read_info_s* pfile_in_zip_read_info;
-   ZPOS64_T offset_local_extrafield;  /* offset of the local extra field */
-   uInt  size_local_extrafield;    /* size of the local extra field */
-#    ifndef NOUNCRYPT
-   char source[12];
-#    else
-   if (password != NULL)
-      return UNZ_PARAMERROR;
-#    endif
-
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   if (!s->current_file_ok)
-      return UNZ_PARAMERROR;
-
-   if (s->pfile_in_zip_read != NULL)
-      unzCloseCurrentFile(file);
-
-   if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
-      return UNZ_BADZIPFILE;
-
-   pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
-   if (pfile_in_zip_read_info==NULL)
-      return UNZ_INTERNALERROR;
-
-   pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
-   pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
-   pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
-   pfile_in_zip_read_info->pos_local_extrafield=0;
-   pfile_in_zip_read_info->raw=raw;
-
-   if (pfile_in_zip_read_info->read_buffer==NULL)
-   {
-      TRYFREE(pfile_in_zip_read_info);
-      return UNZ_INTERNALERROR;
-   }
-
-   pfile_in_zip_read_info->stream_initialised=0;
-
-   if (method!=NULL)
-      *method = (int)s->cur_file_info.compression_method;
-
-   if (level!=NULL)
-   {
-      *level = 6;
-      switch (s->cur_file_info.flag & 0x06)
-      {
-         case 6 : *level = 1; break;
-         case 4 : *level = 2; break;
-         case 2 : *level = 9; break;
-      }
-   }
-
-   if ((s->cur_file_info.compression_method!=0) &&
-         /* #ifdef HAVE_BZIP2 */
-         (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
-         /* #endif */
-         (s->cur_file_info.compression_method!=Z_DEFLATED))
-
-      err=UNZ_BADZIPFILE;
-
-   pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
-   pfile_in_zip_read_info->crc32=0;
-   pfile_in_zip_read_info->total_out_64=0;
-   pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
-   pfile_in_zip_read_info->filestream=s->filestream;
-   pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
-   pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
-
-   pfile_in_zip_read_info->stream.total_out = 0;
-
-   if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
-   {
-#ifdef HAVE_BZIP2
-      pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
-      pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
-      pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
-      pfile_in_zip_read_info->bstream.state = (voidpf)0;
-
-      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
-      pfile_in_zip_read_info->stream.zfree = (free_func)0;
-      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
-      pfile_in_zip_read_info->stream.next_in = (voidpf)0;
-      pfile_in_zip_read_info->stream.avail_in = 0;
-
-      err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
-      if (err == Z_OK)
-         pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
-      else
-      {
-         TRYFREE(pfile_in_zip_read_info);
-         return err;
-      }
-#else
-      pfile_in_zip_read_info->raw=1;
-#endif
-   }
-   else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
-   {
-      pfile_in_zip_read_info->stream.zalloc = Z_NULL;
-      pfile_in_zip_read_info->stream.zfree = Z_NULL;
-      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
-      pfile_in_zip_read_info->stream.next_in = 0;
-      pfile_in_zip_read_info->stream.avail_in = 0;
-
-      err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
-      if (err == Z_OK)
-         pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
-      else
-      {
-         TRYFREE(pfile_in_zip_read_info);
-         return err;
-      }
-      /* windowBits is passed < 0 to tell that there is no zlib header.
-       * Note that in this case inflate *requires* an extra "dummy" byte
-       * after the compressed stream in order to complete decompression and
-       * return Z_STREAM_END.
-       * In unzip, i don't wait absolutely Z_STREAM_END because I known the
-       * size of both compressed and uncompressed data
-       */
-   }
-   pfile_in_zip_read_info->rest_read_compressed =
-      s->cur_file_info.compressed_size ;
-   pfile_in_zip_read_info->rest_read_uncompressed =
-      s->cur_file_info.uncompressed_size ;
-
-
-   pfile_in_zip_read_info->pos_in_zipfile =
-      s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
-      iSizeVar;
-
-   pfile_in_zip_read_info->stream.avail_in = (uInt)0;
-
-   s->pfile_in_zip_read = pfile_in_zip_read_info;
-   s->encrypted = 0;
-
-#    ifndef NOUNCRYPT
-   if (password != NULL)
-   {
-      int i;
-      s->pcrc_32_tab = get_crc_table();
-      init_keys(password,s->keys,s->pcrc_32_tab);
-      if (ZSEEK64(s->z_filefunc, s->filestream,
-               s->pfile_in_zip_read->pos_in_zipfile +
-               s->pfile_in_zip_read->byte_before_the_zipfile,
-               SEEK_SET)!=0)
-         return UNZ_INTERNALERROR;
-      if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
-         return UNZ_INTERNALERROR;
-
-      for (i = 0; i<12; i++)
-         zdecode(s->keys,s->pcrc_32_tab,source[i]);
-
-      s->pfile_in_zip_read->pos_in_zipfile+=12;
-      s->encrypted=1;
-   }
-#    endif
-
-
-   return UNZ_OK;
-}
-
-extern int ZEXPORT unzOpenCurrentFile (unzFile file)
-{
-   return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
-}
-
-extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char*  password)
-{
-   return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
-}
-
-extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
-{
-   return unzOpenCurrentFile3(file, method, level, raw, NULL);
-}
-
-/** Addition for GDAL : START */
-
-extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
-{
-   unz64_s* s;
-   file_in_zip64_read_info_s* pfile_in_zip_read_info;
-   s=(unz64_s*)file;
-   if (file==NULL)
-      return 0; //UNZ_PARAMERROR;
-   pfile_in_zip_read_info=s->pfile_in_zip_read;
-   if (pfile_in_zip_read_info==NULL)
-      return 0; //UNZ_PARAMERROR;
-   return pfile_in_zip_read_info->pos_in_zipfile +
-      pfile_in_zip_read_info->byte_before_the_zipfile;
-}
-
-/** Addition for GDAL : END */
-
-/*
-   Read bytes from the current file.
-   buf contain buffer where data must be copied
-   len the size of buf.
-
-   return the number of byte copied if somes bytes are copied
-   return 0 if the end of file was reached
-   return <0 with error code if there is an error
-   (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-   */
-extern int ZEXPORT unzReadCurrentFile  (unzFile file, voidp buf, unsigned len)
-{
-   int err=UNZ_OK;
-   uInt iRead = 0;
-   unz64_s* s;
-   file_in_zip64_read_info_s* pfile_in_zip_read_info;
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-   if (pfile_in_zip_read_info==NULL)
-      return UNZ_PARAMERROR;
-
-
-   if (pfile_in_zip_read_info->read_buffer == NULL)
-      return UNZ_END_OF_LIST_OF_FILE;
-   if (len==0)
-      return 0;
-
-   pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
-
-   pfile_in_zip_read_info->stream.avail_out = (uInt)len;
-
-   if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
-         (!(pfile_in_zip_read_info->raw)))
-      pfile_in_zip_read_info->stream.avail_out =
-         (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
-
-   if ((len>pfile_in_zip_read_info->rest_read_compressed+
-            pfile_in_zip_read_info->stream.avail_in) &&
-         (pfile_in_zip_read_info->raw))
-      pfile_in_zip_read_info->stream.avail_out =
-         (uInt)pfile_in_zip_read_info->rest_read_compressed+
-         pfile_in_zip_read_info->stream.avail_in;
-
-   while (pfile_in_zip_read_info->stream.avail_out>0)
-   {
-      if ((pfile_in_zip_read_info->stream.avail_in==0) &&
-            (pfile_in_zip_read_info->rest_read_compressed>0))
-      {
-         uInt uReadThis = UNZ_BUFSIZE;
-         if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
-            uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
-         if (uReadThis == 0)
-            return UNZ_EOF;
-         if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
-                  pfile_in_zip_read_info->filestream,
-                  pfile_in_zip_read_info->pos_in_zipfile +
-                  pfile_in_zip_read_info->byte_before_the_zipfile,
-                  ZLIB_FILEFUNC_SEEK_SET)!=0)
-            return UNZ_ERRNO;
-         if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
-                  pfile_in_zip_read_info->filestream,
-                  pfile_in_zip_read_info->read_buffer,
-                  uReadThis)!=uReadThis)
-            return UNZ_ERRNO;
-
-
-#            ifndef NOUNCRYPT
-         if(s->encrypted)
-         {
-            uInt i;
-            for(i=0;i<uReadThis;i++)
-               pfile_in_zip_read_info->read_buffer[i] =
-                  zdecode(s->keys,s->pcrc_32_tab,
-                        pfile_in_zip_read_info->read_buffer[i]);
-         }
-#            endif
-
-
-         pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
-
-         pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
-
-         pfile_in_zip_read_info->stream.next_in =
-            (Bytef*)pfile_in_zip_read_info->read_buffer;
-         pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
-      }
-
-      if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
-      {
-         uInt uDoCopy,i ;
-
-         if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
-               (pfile_in_zip_read_info->rest_read_compressed == 0))
-            return (iRead==0) ? UNZ_EOF : iRead;
-
-         if (pfile_in_zip_read_info->stream.avail_out <
-               pfile_in_zip_read_info->stream.avail_in)
-            uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
-         else
-            uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
-
-         for (i=0;i<uDoCopy;i++)
-            *(pfile_in_zip_read_info->stream.next_out+i) =
-               *(pfile_in_zip_read_info->stream.next_in+i);
-
-         pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
-
-         pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
-               pfile_in_zip_read_info->stream.next_out,
-               uDoCopy);
-         pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
-         pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
-         pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
-         pfile_in_zip_read_info->stream.next_out += uDoCopy;
-         pfile_in_zip_read_info->stream.next_in += uDoCopy;
-         pfile_in_zip_read_info->stream.total_out += uDoCopy;
-         iRead += uDoCopy;
-      }
-      else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
-      {
-#ifdef HAVE_BZIP2
-         uLong uTotalOutBefore,uTotalOutAfter;
-         const Bytef *bufBefore;
-         uLong uOutThis;
-
-         pfile_in_zip_read_info->bstream.next_in        = (char*)pfile_in_zip_read_info->stream.next_in;
-         pfile_in_zip_read_info->bstream.avail_in       = pfile_in_zip_read_info->stream.avail_in;
-         pfile_in_zip_read_info->bstream.total_in_lo32  = pfile_in_zip_read_info->stream.total_in;
-         pfile_in_zip_read_info->bstream.total_in_hi32  = 0;
-         pfile_in_zip_read_info->bstream.next_out       = (char*)pfile_in_zip_read_info->stream.next_out;
-         pfile_in_zip_read_info->bstream.avail_out      = pfile_in_zip_read_info->stream.avail_out;
-         pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
-         pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
-
-         uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
-         bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
-
-         err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
-
-         uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
-         uOutThis = uTotalOutAfter-uTotalOutBefore;
-
-         pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
-
-         pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
-         pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
-         iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
-
-         pfile_in_zip_read_info->stream.next_in   = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
-         pfile_in_zip_read_info->stream.avail_in  = pfile_in_zip_read_info->bstream.avail_in;
-         pfile_in_zip_read_info->stream.total_in  = pfile_in_zip_read_info->bstream.total_in_lo32;
-         pfile_in_zip_read_info->stream.next_out  = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
-         pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
-         pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
-
-         if (err==BZ_STREAM_END)
-            return (iRead==0) ? UNZ_EOF : iRead;
-         if (err!=BZ_OK)
-            break;
-#endif
-      } // end Z_BZIP2ED
-      else
-      {
-         ZPOS64_T uTotalOutBefore,uTotalOutAfter;
-         const Bytef *bufBefore;
-         ZPOS64_T uOutThis;
-         int flush=Z_SYNC_FLUSH;
-
-         uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
-         bufBefore = pfile_in_zip_read_info->stream.next_out;
-
-         /*
-            if ((pfile_in_zip_read_info->rest_read_uncompressed ==
-            pfile_in_zip_read_info->stream.avail_out) &&
-            (pfile_in_zip_read_info->rest_read_compressed == 0))
-            flush = Z_FINISH;
-            */
-         err=inflate(&pfile_in_zip_read_info->stream,flush);
-
-         if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
-            err = Z_DATA_ERROR;
-
-         uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
-         uOutThis = uTotalOutAfter-uTotalOutBefore;
-
-         pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
-
-         pfile_in_zip_read_info->crc32 =
-            crc32(pfile_in_zip_read_info->crc32,bufBefore,
-                  (uInt)(uOutThis));
-
-         pfile_in_zip_read_info->rest_read_uncompressed -=
-            uOutThis;
-
-         iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
-
-         if (err==Z_STREAM_END)
-            return (iRead==0) ? UNZ_EOF : iRead;
-         if (err!=Z_OK)
-            break;
-      }
-   }
-
-   if (err==Z_OK)
-      return iRead;
-   return err;
-}
-
-
-/*
-   Give the current position in uncompressed data
-   */
-extern z_off_t ZEXPORT unztell (unzFile file)
-{
-   unz64_s* s;
-   file_in_zip64_read_info_s* pfile_in_zip_read_info;
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-   if (pfile_in_zip_read_info==NULL)
-      return UNZ_PARAMERROR;
-
-   return (z_off_t)pfile_in_zip_read_info->stream.total_out;
-}
-
-extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
-{
-
-   unz64_s* s;
-   file_in_zip64_read_info_s* pfile_in_zip_read_info;
-   if (file==NULL)
-      return (ZPOS64_T)-1;
-   s=(unz64_s*)file;
-   pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-   if (pfile_in_zip_read_info==NULL)
-      return (ZPOS64_T)-1;
-
-   return pfile_in_zip_read_info->total_out_64;
-}
-
-
-/*
-   return 1 if the end of file was reached, 0 elsewhere
-   */
-extern int ZEXPORT unzeof (unzFile file)
-{
-   unz64_s* s;
-   file_in_zip64_read_info_s* pfile_in_zip_read_info;
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-   if (pfile_in_zip_read_info==NULL)
-      return UNZ_PARAMERROR;
-
-   if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
-      return 1;
-   else
-      return 0;
-}
-
-
-
-/*
-   Read extra field from the current file (opened by unzOpenCurrentFile)
-   This is the local-header version of the extra field (sometimes, there is
-   more info in the local-header version than in the central-header)
-
-   if buf==NULL, it return the size of the local extra field that can be read
-
-   if buf!=NULL, len is the size of the buffer, the extra header is copied in
-   buf.
-   the return value is the number of bytes copied in buf, or (if <0)
-   the error code
-   */
-extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
-{
-   unz64_s* s;
-   file_in_zip64_read_info_s* pfile_in_zip_read_info;
-   uInt read_now;
-   ZPOS64_T size_to_read;
-
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-   if (pfile_in_zip_read_info==NULL)
-      return UNZ_PARAMERROR;
-
-   size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
-         pfile_in_zip_read_info->pos_local_extrafield);
-
-   if (buf==NULL)
-      return (int)size_to_read;
-
-   if (len>size_to_read)
-      read_now = (uInt)size_to_read;
-   else
-      read_now = (uInt)len ;
-
-   if (read_now==0)
-      return 0;
-
-   if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
-            pfile_in_zip_read_info->filestream,
-            pfile_in_zip_read_info->offset_local_extrafield +
-            pfile_in_zip_read_info->pos_local_extrafield,
-            ZLIB_FILEFUNC_SEEK_SET)!=0)
-      return UNZ_ERRNO;
-
-   if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
-            pfile_in_zip_read_info->filestream,
-            buf,read_now)!=read_now)
-      return UNZ_ERRNO;
-
-   return (int)read_now;
-}
-
-/*
-   Close the file in zip opened with unzipOpenCurrentFile
-   Return UNZ_CRCERROR if all the file was read but the CRC is not good
-   */
-extern int ZEXPORT unzCloseCurrentFile (unzFile file)
-{
-   int err=UNZ_OK;
-
-   unz64_s* s;
-   file_in_zip64_read_info_s* pfile_in_zip_read_info;
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-   if (pfile_in_zip_read_info==NULL)
-      return UNZ_PARAMERROR;
-
-
-   if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
-         (!pfile_in_zip_read_info->raw))
-   {
-      if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
-         err=UNZ_CRCERROR;
-   }
-
-
-   TRYFREE(pfile_in_zip_read_info->read_buffer);
-   pfile_in_zip_read_info->read_buffer = NULL;
-   if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
-      inflateEnd(&pfile_in_zip_read_info->stream);
-#ifdef HAVE_BZIP2
-   else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
-      BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
-#endif
-
-
-   pfile_in_zip_read_info->stream_initialised = 0;
-   TRYFREE(pfile_in_zip_read_info);
-
-   s->pfile_in_zip_read=NULL;
-
-   return err;
-}
-
-
-/*
-   Get the global comment string of the ZipFile, in the szComment buffer.
-   uSizeBuf is the size of the szComment buffer.
-   return the number of byte copied or an error code <0
-   */
-extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
-{
-   unz64_s* s;
-   uLong uReadThis ;
-   if (file==NULL)
-      return (int)UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-
-   uReadThis = uSizeBuf;
-   if (uReadThis>s->gi.size_comment)
-      uReadThis = s->gi.size_comment;
-
-   if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
-      return UNZ_ERRNO;
-
-   if (uReadThis>0)
-   {
-      *szComment='\0';
-      if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
-         return UNZ_ERRNO;
-   }
-
-   if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
-      *(szComment+s->gi.size_comment)='\0';
-   return (int)uReadThis;
-}
-
-/* Additions by RX '2004 */
-extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
-{
-   unz64_s* s;
-
-   if (file==NULL)
-      return 0; //UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-   if (!s->current_file_ok)
-      return 0;
-   if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
-      if (s->num_file==s->gi.number_entry)
-         return 0;
-   return s->pos_in_central_dir;
-}
-
-extern uLong ZEXPORT unzGetOffset (unzFile file)
-{
-   ZPOS64_T offset64;
-
-   if (file==NULL)
-      return 0; //UNZ_PARAMERROR;
-   offset64 = unzGetOffset64(file);
-   return (uLong)offset64;
-}
-
-extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
-{
-   unz64_s* s;
-   int err;
-
-   if (file==NULL)
-      return UNZ_PARAMERROR;
-   s=(unz64_s*)file;
-
-   s->pos_in_central_dir = pos;
-   s->num_file = s->gi.number_entry;      /* hack */
-   err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
-         &s->cur_file_info_internal,
-         NULL,0,NULL,0,NULL,0);
-   s->current_file_ok = (err == UNZ_OK);
-   return err;
-}
-
-extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
-{
-   return unzSetOffset64(file,pos);
-}
diff --git a/deps/zlib/unzip.h b/deps/zlib/unzip.h
deleted file mode 100644 (file)
index 3183968..0000000
+++ /dev/null
@@ -1,437 +0,0 @@
-/* unzip.h -- IO for uncompress .zip files using zlib
-   Version 1.1, February 14h, 2010
-   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
-         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
-         Modifications of Unzip for Zip64
-         Copyright (C) 2007-2008 Even Rouault
-
-         Modifications for Zip64 support on both zip and unzip
-         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
-         For more info read MiniZip_info.txt
-
-         ---------------------------------------------------------------------------------
-
-        Condition of use and distribution are the same than zlib :
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  ---------------------------------------------------------------------------------
-
-        Changes
-
-        See header of unzip64.c
-
-*/
-
-#ifndef _unz64_H
-#define _unz64_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef _ZLIB_H
-#include "zlib.h"
-#endif
-
-#ifndef  _ZLIBIOAPI_H
-#include "ioapi.h"
-#endif
-
-#ifdef HAVE_BZIP2
-#include "bzlib.h"
-#endif
-
-#define Z_BZIP2ED 12
-
-#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
-    from (void*) without cast */
-typedef struct TagunzFile__ { int unused; } unzFile__;
-typedef unzFile__ *unzFile;
-#else
-typedef voidp unzFile;
-#endif
-
-
-#define UNZ_OK                          (0)
-#define UNZ_END_OF_LIST_OF_FILE         (-100)
-#define UNZ_ERRNO                       (Z_ERRNO)
-#define UNZ_EOF                         (0)
-#define UNZ_PARAMERROR                  (-102)
-#define UNZ_BADZIPFILE                  (-103)
-#define UNZ_INTERNALERROR               (-104)
-#define UNZ_CRCERROR                    (-105)
-
-/* tm_unz contain date/time info */
-typedef struct tm_unz_s
-{
-    uInt tm_sec;            /* seconds after the minute - [0,59] */
-    uInt tm_min;            /* minutes after the hour - [0,59] */
-    uInt tm_hour;           /* hours since midnight - [0,23] */
-    uInt tm_mday;           /* day of the month - [1,31] */
-    uInt tm_mon;            /* months since January - [0,11] */
-    uInt tm_year;           /* years - [1980..2044] */
-} tm_unz;
-
-/* unz_global_info structure contain global data about the ZIPfile
-   These data comes from the end of central dir */
-typedef struct unz_global_info64_s
-{
-    ZPOS64_T number_entry;         /* total number of entries in
-                                     the central dir on this disk */
-    uLong size_comment;         /* size of the global comment of the zipfile */
-} unz_global_info64;
-
-typedef struct unz_global_info_s
-{
-    uLong number_entry;         /* total number of entries in
-                                     the central dir on this disk */
-    uLong size_comment;         /* size of the global comment of the zipfile */
-} unz_global_info;
-
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_info64_s
-{
-    uLong version;              /* version made by                 2 bytes */
-    uLong version_needed;       /* version needed to extract       2 bytes */
-    uLong flag;                 /* general purpose bit flag        2 bytes */
-    uLong compression_method;   /* compression method              2 bytes */
-    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
-    uLong crc;                  /* crc-32                          4 bytes */
-    ZPOS64_T compressed_size;   /* compressed size                 8 bytes */
-    ZPOS64_T uncompressed_size; /* uncompressed size               8 bytes */
-    uLong size_filename;        /* filename length                 2 bytes */
-    uLong size_file_extra;      /* extra field length              2 bytes */
-    uLong size_file_comment;    /* file comment length             2 bytes */
-
-    uLong disk_num_start;       /* disk number start               2 bytes */
-    uLong internal_fa;          /* internal file attributes        2 bytes */
-    uLong external_fa;          /* external file attributes        4 bytes */
-
-    tm_unz tmu_date;
-} unz_file_info64;
-
-typedef struct unz_file_info_s
-{
-    uLong version;              /* version made by                 2 bytes */
-    uLong version_needed;       /* version needed to extract       2 bytes */
-    uLong flag;                 /* general purpose bit flag        2 bytes */
-    uLong compression_method;   /* compression method              2 bytes */
-    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
-    uLong crc;                  /* crc-32                          4 bytes */
-    uLong compressed_size;      /* compressed size                 4 bytes */
-    uLong uncompressed_size;    /* uncompressed size               4 bytes */
-    uLong size_filename;        /* filename length                 2 bytes */
-    uLong size_file_extra;      /* extra field length              2 bytes */
-    uLong size_file_comment;    /* file comment length             2 bytes */
-
-    uLong disk_num_start;       /* disk number start               2 bytes */
-    uLong internal_fa;          /* internal file attributes        2 bytes */
-    uLong external_fa;          /* external file attributes        4 bytes */
-
-    tm_unz tmu_date;
-} unz_file_info;
-
-extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
-                                                 const char* fileName2,
-                                                 int iCaseSensitivity));
-/*
-   Compare two filename (fileName1,fileName2).
-   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
-   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
-                                or strcasecmp)
-   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
-    (like 1 on Unix, 2 on Windows)
-*/
-
-
-extern unzFile ZEXPORT unzOpen OF((const char *path));
-extern unzFile ZEXPORT unzOpen64 OF((const void *path));
-/*
-  Open a Zip file. path contain the full pathname (by example,
-     on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
-     "zlib/zlib113.zip".
-     If the zipfile cannot be opened (file don't exist or in not valid), the
-       return value is NULL.
-     Else, the return value is a unzFile Handle, usable with other function
-       of this unzip package.
-     the "64" function take a const void* pointer, because the path is just the
-       value passed to the open64_file_func callback.
-     Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
-       is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
-       does not describe the reality
-*/
-
-
-extern unzFile ZEXPORT unzOpen2 OF((const char *path,
-                                    zlib_filefunc_def* pzlib_filefunc_def));
-/*
-   Open a Zip file, like unzOpen, but provide a set of file low level API
-      for read/write the zip file (see ioapi.h)
-*/
-
-extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
-                                    zlib_filefunc64_def* pzlib_filefunc_def));
-/*
-   Open a Zip file, like unz64Open, but provide a set of file low level API
-      for read/write the zip file (see ioapi.h)
-*/
-
-extern int ZEXPORT unzClose OF((unzFile file));
-/*
-  Close a ZipFile opened with unzipOpen.
-  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
-    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
-  return UNZ_OK if there is no problem. */
-
-extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
-                                        unz_global_info *pglobal_info));
-
-extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
-                                        unz_global_info64 *pglobal_info));
-/*
-  Write info about the ZipFile in the *pglobal_info structure.
-  No preparation of the structure is needed
-  return UNZ_OK if there is no problem. */
-
-
-extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
-                                           char *szComment,
-                                           uLong uSizeBuf));
-/*
-  Get the global comment string of the ZipFile, in the szComment buffer.
-  uSizeBuf is the size of the szComment buffer.
-  return the number of byte copied or an error code <0
-*/
-
-
-/***************************************************************************/
-/* Unzip package allow you browse the directory of the zipfile */
-
-extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
-/*
-  Set the current file of the zipfile to the first file.
-  return UNZ_OK if there is no problem
-*/
-
-extern int ZEXPORT unzGoToNextFile OF((unzFile file));
-/*
-  Set the current file of the zipfile to the next file.
-  return UNZ_OK if there is no problem
-  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-
-extern int ZEXPORT unzLocateFile OF((unzFile file,
-                     const char *szFileName,
-                     int iCaseSensitivity));
-/*
-  Try locate the file szFileName in the zipfile.
-  For the iCaseSensitivity signification, see unzStringFileNameCompare
-
-  return value :
-  UNZ_OK if the file is found. It becomes the current file.
-  UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-
-
-/* ****************************************** */
-/* Ryan supplied functions */
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_pos_s
-{
-    uLong pos_in_zip_directory;   /* offset in zip file directory */
-    uLong num_of_file;            /* # of file */
-} unz_file_pos;
-
-extern int ZEXPORT unzGetFilePos(
-    unzFile file,
-    unz_file_pos* file_pos);
-
-extern int ZEXPORT unzGoToFilePos(
-    unzFile file,
-    unz_file_pos* file_pos);
-
-typedef struct unz64_file_pos_s
-{
-    ZPOS64_T pos_in_zip_directory;   /* offset in zip file directory */
-    ZPOS64_T num_of_file;            /* # of file */
-} unz64_file_pos;
-
-extern int ZEXPORT unzGetFilePos64(
-    unzFile file,
-    unz64_file_pos* file_pos);
-
-extern int ZEXPORT unzGoToFilePos64(
-    unzFile file,
-    const unz64_file_pos* file_pos);
-
-/* ****************************************** */
-
-extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
-                         unz_file_info64 *pfile_info,
-                         char *szFileName,
-                         uLong fileNameBufferSize,
-                         void *extraField,
-                         uLong extraFieldBufferSize,
-                         char *szComment,
-                         uLong commentBufferSize));
-
-extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
-                         unz_file_info *pfile_info,
-                         char *szFileName,
-                         uLong fileNameBufferSize,
-                         void *extraField,
-                         uLong extraFieldBufferSize,
-                         char *szComment,
-                         uLong commentBufferSize));
-/*
-  Get Info about the current file
-  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
-        the current file
-  if szFileName!=NULL, the filemane string will be copied in szFileName
-            (fileNameBufferSize is the size of the buffer)
-  if extraField!=NULL, the extra field information will be copied in extraField
-            (extraFieldBufferSize is the size of the buffer).
-            This is the Central-header version of the extra field
-  if szComment!=NULL, the comment string of the file will be copied in szComment
-            (commentBufferSize is the size of the buffer)
-*/
-
-
-/** Addition for GDAL : START */
-
-extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
-
-/** Addition for GDAL : END */
-
-
-/***************************************************************************/
-/* for reading the content of the current zipfile, you can open it, read data
-   from it, and close it (you can close it before reading all the file)
-   */
-
-extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
-/*
-  Open for reading data the current file in the zipfile.
-  If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
-                                                  const char* password));
-/*
-  Open for reading data the current file in the zipfile.
-  password is a crypting password
-  If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
-                                           int* method,
-                                           int* level,
-                                           int raw));
-/*
-  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
-    if raw==1
-  *method will receive method of compression, *level will receive level of
-     compression
-  note : you can set level parameter as NULL (if you did not want known level,
-         but you CANNOT set method parameter as NULL
-*/
-
-extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
-                                           int* method,
-                                           int* level,
-                                           int raw,
-                                           const char* password));
-/*
-  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
-    if raw==1
-  *method will receive method of compression, *level will receive level of
-     compression
-  note : you can set level parameter as NULL (if you did not want known level,
-         but you CANNOT set method parameter as NULL
-*/
-
-
-extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
-/*
-  Close the file in zip opened with unzOpenCurrentFile
-  Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-
-extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
-                      voidp buf,
-                      unsigned len));
-/*
-  Read bytes from the current file (opened by unzOpenCurrentFile)
-  buf contain buffer where data must be copied
-  len the size of buf.
-
-  return the number of byte copied if somes bytes are copied
-  return 0 if the end of file was reached
-  return <0 with error code if there is an error
-    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-
-extern z_off_t ZEXPORT unztell OF((unzFile file));
-
-extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
-/*
-  Give the current position in uncompressed data
-*/
-
-extern int ZEXPORT unzeof OF((unzFile file));
-/*
-  return 1 if the end of file was reached, 0 elsewhere
-*/
-
-extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
-                                             voidp buf,
-                                             unsigned len));
-/*
-  Read extra field from the current file (opened by unzOpenCurrentFile)
-  This is the local-header version of the extra field (sometimes, there is
-    more info in the local-header version than in the central-header)
-
-  if buf==NULL, it return the size of the local extra field
-
-  if buf!=NULL, len is the size of the buffer, the extra header is copied in
-    buf.
-  the return value is the number of bytes copied in buf, or (if <0)
-    the error code
-*/
-
-/***************************************************************************/
-
-/* Get the current file offset */
-extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
-extern uLong ZEXPORT unzGetOffset (unzFile file);
-
-/* Set the current file offset */
-extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
-extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _unz64_H */
diff --git a/deps/zlib/zutil.c b/deps/zlib/zutil.c
deleted file mode 100644 (file)
index c9353fe..0000000
+++ /dev/null
@@ -1,305 +0,0 @@
-/* zutil.c -- target dependent utility functions for the compression library
- * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#include "zutil.h"
-#ifndef Z_SOLO
-#  include "gzguts.h"
-#endif
-
-char * const z_errmsg[10] = {
-   "need dictionary",     /* Z_NEED_DICT       2  */
-   "stream end",          /* Z_STREAM_END      1  */
-   "",                    /* Z_OK              0  */
-   "file error",          /* Z_ERRNO         (-1) */
-   "stream error",        /* Z_STREAM_ERROR  (-2) */
-   "data error",          /* Z_DATA_ERROR    (-3) */
-   "insufficient memory", /* Z_MEM_ERROR     (-4) */
-   "buffer error",        /* Z_BUF_ERROR     (-5) */
-   "incompatible version",/* Z_VERSION_ERROR (-6) */
-   ""};
-
-
-const char * ZEXPORT zlibVersion(void)
-{
-   return ZLIB_VERSION;
-}
-
-uLong ZEXPORT zlibCompileFlags(void)
-{
-   uLong flags;
-
-   flags = 0;
-   switch ((int)(sizeof(uInt))) {
-      case 2:     break;
-      case 4:     flags += 1;     break;
-      case 8:     flags += 2;     break;
-      default:    flags += 3;
-   }
-   switch ((int)(sizeof(uLong))) {
-      case 2:     break;
-      case 4:     flags += 1 << 2;        break;
-      case 8:     flags += 2 << 2;        break;
-      default:    flags += 3 << 2;
-   }
-   switch ((int)(sizeof(voidpf))) {
-      case 2:     break;
-      case 4:     flags += 1 << 4;        break;
-      case 8:     flags += 2 << 4;        break;
-      default:    flags += 3 << 4;
-   }
-   switch ((int)(sizeof(z_off_t))) {
-      case 2:     break;
-      case 4:     flags += 1 << 6;        break;
-      case 8:     flags += 2 << 6;        break;
-      default:    flags += 3 << 6;
-   }
-#ifdef DEBUG
-   flags += 1 << 8;
-#endif
-#if defined(ASMV) || defined(ASMINF)
-   flags += 1 << 9;
-#endif
-#ifdef ZLIB_WINAPI
-   flags += 1 << 10;
-#endif
-#ifdef BUILDFIXED
-   flags += 1 << 12;
-#endif
-#ifdef DYNAMIC_CRC_TABLE
-   flags += 1 << 13;
-#endif
-#ifdef NO_GZCOMPRESS
-   flags += 1L << 16;
-#endif
-#ifdef NO_GZIP
-   flags += 1L << 17;
-#endif
-#ifdef PKZIP_BUG_WORKAROUND
-   flags += 1L << 20;
-#endif
-#ifdef FASTEST
-   flags += 1L << 21;
-#endif
-#if defined(STDC) || defined(Z_HAVE_STDARG_H)
-#  ifdef NO_vsnprintf
-   flags += 1L << 25;
-#    ifdef HAS_vsprintf_void
-   flags += 1L << 26;
-#    endif
-#  else
-#    ifdef HAS_vsnprintf_void
-   flags += 1L << 26;
-#    endif
-#  endif
-#else
-   flags += 1L << 24;
-#  ifdef NO_snprintf
-   flags += 1L << 25;
-#    ifdef HAS_sprintf_void
-   flags += 1L << 26;
-#    endif
-#  else
-#    ifdef HAS_snprintf_void
-   flags += 1L << 26;
-#    endif
-#  endif
-#endif
-   return flags;
-}
-
-#ifdef DEBUG
-
-#  ifndef verbose
-#    define verbose 0
-#  endif
-int ZLIB_INTERNAL z_verbose = verbose;
-
-void ZLIB_INTERNAL z_error (char *m)
-{
-   fprintf(stderr, "%s\n", m);
-   exit(1);
-}
-#endif
-
-/* exported to allow conversion of error code to string for compress() and
- * uncompress()
- */
-const char * ZEXPORT zError(int err)
-{
-   return ERR_MSG(err);
-}
-
-#if defined(_WIN32_WCE)
-/* The Microsoft C Run-Time Library for Windows CE doesn't have
- * errno.  We define it as a global variable to simplify porting.
- * Its value is always 0 and should not be used.
- */
-int errno = 0;
-#endif
-
-#ifndef HAVE_MEMCPY
-
-void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
-{
-   if (len == 0) return;
-   do {
-      *dest++ = *source++; /* ??? to be unrolled */
-   } while (--len != 0);
-}
-
-int ZLIB_INTERNAL zmemcmp(const Bytef *s1, const Bytef *s2, uInt len)
-{
-   uInt j;
-
-   for (j = 0; j < len; j++) {
-      if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
-   }
-   return 0;
-}
-
-void ZLIB_INTERNAL zmemzero(Bytef *dest, uInt len)
-{
-   if (len == 0) return;
-   do {
-      *dest++ = 0;  /* ??? to be unrolled */
-   } while (--len != 0);
-}
-#endif
-
-#ifndef Z_SOLO
-
-#ifdef SYS16BIT
-
-#ifdef __TURBOC__
-/* Turbo C in 16-bit mode */
-
-#  define MY_ZCALLOC
-
-/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
- * and farmalloc(64K) returns a pointer with an offset of 8, so we
- * must fix the pointer. Warning: the pointer must be put back to its
- * original form in order to free it, use zcfree().
- */
-
-#define MAX_PTR 10
-/* 10*64K = 640K */
-
-local int next_ptr = 0;
-
-typedef struct ptr_table_s {
-   voidpf org_ptr;
-   voidpf new_ptr;
-} ptr_table;
-
-local ptr_table table[MAX_PTR];
-/* This table is used to remember the original form of pointers
- * to large buffers (64K). Such pointers are normalized with a zero offset.
- * Since MSDOS is not a preemptive multitasking OS, this table is not
- * protected from concurrent access. This hack doesn't work anyway on
- * a protected system like OS/2. Use Microsoft C instead.
- */
-
-voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
-{
-   voidpf buf = opaque; /* just to make some compilers happy */
-   ulg bsize = (ulg)items*size;
-
-   /* If we allocate less than 65520 bytes, we assume that farmalloc
-    * will return a usable pointer which doesn't have to be normalized.
-    */
-   if (bsize < 65520L) {
-      buf = farmalloc(bsize);
-      if (*(ush*)&buf != 0) return buf;
-   } else {
-      buf = farmalloc(bsize + 16L);
-   }
-   if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
-   table[next_ptr].org_ptr = buf;
-
-   /* Normalize the pointer to seg:0 */
-   *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
-   *(ush*)&buf = 0;
-   table[next_ptr++].new_ptr = buf;
-   return buf;
-}
-
-void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
-{
-   int n;
-   if (*(ush*)&ptr != 0) { /* object < 64K */
-      farfree(ptr);
-      return;
-   }
-   /* Find the original pointer */
-   for (n = 0; n < next_ptr; n++) {
-      if (ptr != table[n].new_ptr) continue;
-
-      farfree(table[n].org_ptr);
-      while (++n < next_ptr) {
-         table[n-1] = table[n];
-      }
-      next_ptr--;
-      return;
-   }
-   ptr = opaque; /* just to make some compilers happy */
-   Assert(0, "zcfree: ptr not found");
-}
-
-#endif /* __TURBOC__ */
-
-
-#ifdef M_I86
-/* Microsoft C in 16-bit mode */
-
-#  define MY_ZCALLOC
-
-#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
-#  define _halloc  halloc
-#  define _hfree   hfree
-#endif
-
-voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
-{
-   if (opaque) opaque = 0; /* to make compiler happy */
-   return _halloc((long)items, size);
-}
-
-void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
-{
-   if (opaque) opaque = 0; /* to make compiler happy */
-   _hfree(ptr);
-}
-
-#endif /* M_I86 */
-
-#endif /* SYS16BIT */
-
-
-#ifndef MY_ZCALLOC /* Any system without a special alloc function */
-
-#ifndef STDC
-extern voidp  malloc OF((uInt size));
-extern voidp  calloc OF((uInt items, uInt size));
-extern void   free   OF((voidpf ptr));
-#endif
-
-voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
-{
-   if (opaque) items += size - size; /* make compiler happy */
-   return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
-      (voidpf)calloc(items, size);
-}
-
-void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
-{
-   free(ptr);
-   if (opaque) return; /* make compiler happy */
-}
-
-#endif /* MY_ZCALLOC */
-
-#endif /* !Z_SOLO */
index 572e9bd..4e828f1 100644 (file)
@@ -75,21 +75,16 @@ SOURCES_C += $(FRONTEND_DIR)/main.c \
 
 # libchdr
 SOURCES_C += \
-             $(DEPS_DIR)/crypto/md5.c \
-             $(DEPS_DIR)/crypto/sha1.c \
-             $(DEPS_DIR)/lzma-16.04/C/Alloc.c \
-             $(DEPS_DIR)/lzma-16.04/C/Bra86.c \
-             $(DEPS_DIR)/lzma-16.04/C/Bra.c \
-             $(DEPS_DIR)/lzma-16.04/C/BraIA64.c \
-             $(DEPS_DIR)/lzma-16.04/C/CpuArch.c \
-             $(DEPS_DIR)/lzma-16.04/C/Delta.c \
-             $(DEPS_DIR)/lzma-16.04/C/LzFind.c \
-             $(DEPS_DIR)/lzma-16.04/C/Lzma86Dec.c \
-             $(DEPS_DIR)/lzma-16.04/C/Lzma86Enc.c \
-             $(DEPS_DIR)/lzma-16.04/C/LzmaDec.c \
-             $(DEPS_DIR)/lzma-16.04/C/LzmaEnc.c \
-             $(DEPS_DIR)/lzma-16.04/C/LzmaLib.c \
-             $(DEPS_DIR)/lzma-16.04/C/Sort.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Alloc.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Bra86.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/BraIA64.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/CpuArch.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Delta.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/LzFind.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Lzma86Dec.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/LzmaDec.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/LzmaEnc.c \
+             $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Sort.c \
              $(DEPS_DIR)/libchdr/src/libchdr_bitstream.c \
              $(DEPS_DIR)/libchdr/src/libchdr_cdrom.c \
              $(DEPS_DIR)/libchdr/src/libchdr_chd.c \
@@ -177,7 +172,7 @@ LOCAL_MODULE        := retro
 LOCAL_SRC_FILES     := $(SOURCES_C) $(SOURCES_ASM)
 LOCAL_CFLAGS        := $(COREFLAGS)
 LOCAL_C_INCLUDES    := $(ROOT_DIR)/include
-LOCAL_C_INCLUDES    += $(DEPS_DIR)/crypto $(DEPS_DIR)/lzma-16.04/C $(DEPS_DIR)/libchdr/include $(DEPS_DIR)/libchdr/include/libchdr
+LOCAL_C_INCLUDES    += $(DEPS_DIR)/crypto $(DEPS_DIR)/libchdr/deps/lzma-19.00/include $(DEPS_DIR)/libchdr/include $(DEPS_DIR)/libchdr/include/libchdr
 LOCAL_C_INCLUDES    += $(LIBRETRO_COMMON)/include
 LOCAL_C_INCLUDES    += $(EXTRA_INCLUDES)
 LOCAL_LDFLAGS       := -Wl,-version-script=$(FRONTEND_DIR)/link.T