Fossil SCM

Remove support for miniz because the upstream project appears to be unmaintained.

mistachkin 2016-03-12 22:02 UTC trunk
Commit b9f31fe1e724d11ff25ca0a97ab654d91c39bbbc
--- Makefile.classic
+++ Makefile.classic
@@ -35,32 +35,27 @@
3535
#
3636
#TCC = gcc -O6
3737
#TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage
3838
TCC = gcc -g -Os -Wall
3939
40
-# To use the included miniz library
41
-# FOSSIL_ENABLE_MINIZ = 1
42
-# TCC += -DFOSSIL_ENABLE_MINIZ
43
-
4440
# To add support for HTTPS
4541
TCC += -DFOSSIL_ENABLE_SSL
4642
4743
#### We sometimes add the -static option here so that we can build a
4844
# static executable that will run in a chroot jail.
4945
#LIB = -static
5046
TCC += -DFOSSIL_DYNAMIC_BUILD=1
5147
5248
#### Extra arguments for linking the finished binary. Fossil needs
53
-# to link against the Z-Lib compression library unless the miniz
54
-# library in the source tree is being used. There are no other
55
-# required dependencies.
49
+# to link against the Z-Lib compression library. There are no
50
+# other required dependencies.
5651
ZLIB_LIB.0 = -lz
5752
ZLIB_LIB.1 =
5853
ZLIB_LIB. = $(ZLIB_LIB.0)
5954
6055
# If using zlib:
61
-LIB += $(ZLIB_LIB.$(FOSSIL_ENABLE_MINIZ)) $(LDFLAGS)
56
+LIB += $(ZLIB_LIB.0) $(LDFLAGS)
6257
6358
# If using HTTPS:
6459
LIB += -lcrypto -lssl
6560
6661
#### Tcl shell for use in running the fossil testsuite. If you do not
6762
--- Makefile.classic
+++ Makefile.classic
@@ -35,32 +35,27 @@
35 #
36 #TCC = gcc -O6
37 #TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage
38 TCC = gcc -g -Os -Wall
39
40 # To use the included miniz library
41 # FOSSIL_ENABLE_MINIZ = 1
42 # TCC += -DFOSSIL_ENABLE_MINIZ
43
44 # To add support for HTTPS
45 TCC += -DFOSSIL_ENABLE_SSL
46
47 #### We sometimes add the -static option here so that we can build a
48 # static executable that will run in a chroot jail.
49 #LIB = -static
50 TCC += -DFOSSIL_DYNAMIC_BUILD=1
51
52 #### Extra arguments for linking the finished binary. Fossil needs
53 # to link against the Z-Lib compression library unless the miniz
54 # library in the source tree is being used. There are no other
55 # required dependencies.
56 ZLIB_LIB.0 = -lz
57 ZLIB_LIB.1 =
58 ZLIB_LIB. = $(ZLIB_LIB.0)
59
60 # If using zlib:
61 LIB += $(ZLIB_LIB.$(FOSSIL_ENABLE_MINIZ)) $(LDFLAGS)
62
63 # If using HTTPS:
64 LIB += -lcrypto -lssl
65
66 #### Tcl shell for use in running the fossil testsuite. If you do not
67
--- Makefile.classic
+++ Makefile.classic
@@ -35,32 +35,27 @@
35 #
36 #TCC = gcc -O6
37 #TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage
38 TCC = gcc -g -Os -Wall
39
 
 
 
 
40 # To add support for HTTPS
41 TCC += -DFOSSIL_ENABLE_SSL
42
43 #### We sometimes add the -static option here so that we can build a
44 # static executable that will run in a chroot jail.
45 #LIB = -static
46 TCC += -DFOSSIL_DYNAMIC_BUILD=1
47
48 #### Extra arguments for linking the finished binary. Fossil needs
49 # to link against the Z-Lib compression library. There are no
50 # other required dependencies.
 
51 ZLIB_LIB.0 = -lz
52 ZLIB_LIB.1 =
53 ZLIB_LIB. = $(ZLIB_LIB.0)
54
55 # If using zlib:
56 LIB += $(ZLIB_LIB.0) $(LDFLAGS)
57
58 # If using HTTPS:
59 LIB += -lcrypto -lssl
60
61 #### Tcl shell for use in running the fossil testsuite. If you do not
62
--- Makefile.in
+++ Makefile.in
@@ -41,11 +41,10 @@
4141
LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
4242
TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ @CFLAGS@ -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H
4343
INSTALLDIR = $(DESTDIR)@prefix@/bin
4444
USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
4545
USE_LINENOISE = @USE_LINENOISE@
46
-FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
4746
4847
include $(SRCDIR)/main.mk
4948
5049
distclean: clean
5150
rm -f autoconfig.h config.log Makefile
5251
--- Makefile.in
+++ Makefile.in
@@ -41,11 +41,10 @@
41 LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
42 TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ @CFLAGS@ -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H
43 INSTALLDIR = $(DESTDIR)@prefix@/bin
44 USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
45 USE_LINENOISE = @USE_LINENOISE@
46 FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
47
48 include $(SRCDIR)/main.mk
49
50 distclean: clean
51 rm -f autoconfig.h config.log Makefile
52
--- Makefile.in
+++ Makefile.in
@@ -41,11 +41,10 @@
41 LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
42 TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ @CFLAGS@ -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H
43 INSTALLDIR = $(DESTDIR)@prefix@/bin
44 USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
45 USE_LINENOISE = @USE_LINENOISE@
 
46
47 include $(SRCDIR)/main.mk
48
49 distclean: clean
50 rm -f autoconfig.h config.log Makefile
51
+25 -34
--- auto.def
+++ auto.def
@@ -3,11 +3,10 @@
33
use cc cc-lib
44
55
options {
66
with-openssl:path|auto|tree|none
77
=> {Look for OpenSSL in the given path, automatically, in the source tree, or none}
8
- with-miniz=0 => {Use miniz from the source tree}
98
with-zlib:path|auto|tree
109
=> {Look for zlib in the given path, automatically, or in the source tree}
1110
with-exec-rel-paths=0
1211
=> {Enable relative paths for external diff/gdiff}
1312
with-legacy-mv-rm=0 => {Enable legacy behavior for mv/rm (skip checkout files)}
@@ -37,11 +36,10 @@
3736
3837
define EXTRA_CFLAGS ""
3938
define EXTRA_LDFLAGS ""
4039
define USE_SYSTEM_SQLITE 0
4140
define USE_LINENOISE 0
42
-define FOSSIL_ENABLE_MINIZ 0
4341
4442
# This procedure is a customized version of "cc-check-function-in-lib",
4543
# that does not modify the LIBS variable. Its use prevents prematurely
4644
# pulling in libraries that will be added later anyhow (e.g. "-ldl").
4745
proc check-function-in-lib {function libs {otherlibs {}}} {
@@ -216,45 +214,38 @@
216214
msg-result "no"
217215
return 0
218216
}
219217
}
220218
221
-if {[opt-bool with-miniz]} {
222
- define FOSSIL_ENABLE_MINIZ 1
223
- msg-result "Using miniz for compression"
224
-} else {
225
- # Check for zlib, using the given location if specified
226
- set zlibpath [opt-val with-zlib]
227
- if {$zlibpath eq "tree"} {
228
- set zlibdir [file dirname $autosetup(dir)]/compat/zlib
229
- if {![file isdirectory $zlibdir]} {
230
- user-error "The zlib in source tree directory does not exist"
231
- }
232
- cc-with [list -cflags "-I$zlibdir -L$zlibdir"]
233
- define-append EXTRA_CFLAGS -I$zlibdir
234
- define-append LIBS $zlibdir/libz.a
235
- set ::zlib_lib $zlibdir/libz.a
236
- msg-result "Using zlib in source tree"
237
- } else {
238
- if {$zlibpath ni {auto ""}} {
239
- cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
240
- define-append EXTRA_CFLAGS -I$zlibpath
241
- define-append EXTRA_LDFLAGS -L$zlibpath
242
- msg-result "Using zlib from $zlibpath"
243
- }
244
- if {![cc-check-includes zlib.h] || ![check-function-in-lib inflateEnd z]} {
245
- user-error "zlib not found please install it or specify the location with --with-zlib"
246
- }
247
- set ::zlib_lib -lz
248
- }
249
-}
219
+# Check for zlib, using the given location if specified
220
+set zlibpath [opt-val with-zlib]
221
+if {$zlibpath eq "tree"} {
222
+ set zlibdir [file dirname $autosetup(dir)]/compat/zlib
223
+ if {![file isdirectory $zlibdir]} {
224
+ user-error "The zlib in source tree directory does not exist"
225
+ }
226
+ cc-with [list -cflags "-I$zlibdir -L$zlibdir"]
227
+ define-append EXTRA_CFLAGS -I$zlibdir
228
+ define-append LIBS $zlibdir/libz.a
229
+ set ::zlib_lib $zlibdir/libz.a
230
+ msg-result "Using zlib in source tree"
231
+} else {
232
+ if {$zlibpath ni {auto ""}} {
233
+ cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
234
+ define-append EXTRA_CFLAGS -I$zlibpath
235
+ define-append EXTRA_LDFLAGS -L$zlibpath
236
+ msg-result "Using zlib from $zlibpath"
237
+ }
238
+ if {![cc-check-includes zlib.h] || ![check-function-in-lib inflateEnd z]} {
239
+ user-error "zlib not found please install it or specify the location with --with-zlib"
240
+ }
241
+ set ::zlib_lib -lz
242
+}
243
+
250244
251245
set ssldirs [opt-val with-openssl]
252246
if {$ssldirs ne "none"} {
253
- if {[opt-bool with-miniz]} {
254
- user-error "The --with-miniz option is incompatible with OpenSSL"
255
- }
256247
set found 0
257248
if {$ssldirs eq "tree"} {
258249
set ssldir [file dirname $autosetup(dir)]/compat/openssl
259250
if {![file isdirectory $ssldir]} {
260251
user-error "The OpenSSL in source tree directory does not exist"
261252
--- auto.def
+++ auto.def
@@ -3,11 +3,10 @@
3 use cc cc-lib
4
5 options {
6 with-openssl:path|auto|tree|none
7 => {Look for OpenSSL in the given path, automatically, in the source tree, or none}
8 with-miniz=0 => {Use miniz from the source tree}
9 with-zlib:path|auto|tree
10 => {Look for zlib in the given path, automatically, or in the source tree}
11 with-exec-rel-paths=0
12 => {Enable relative paths for external diff/gdiff}
13 with-legacy-mv-rm=0 => {Enable legacy behavior for mv/rm (skip checkout files)}
@@ -37,11 +36,10 @@
37
38 define EXTRA_CFLAGS ""
39 define EXTRA_LDFLAGS ""
40 define USE_SYSTEM_SQLITE 0
41 define USE_LINENOISE 0
42 define FOSSIL_ENABLE_MINIZ 0
43
44 # This procedure is a customized version of "cc-check-function-in-lib",
45 # that does not modify the LIBS variable. Its use prevents prematurely
46 # pulling in libraries that will be added later anyhow (e.g. "-ldl").
47 proc check-function-in-lib {function libs {otherlibs {}}} {
@@ -216,45 +214,38 @@
216 msg-result "no"
217 return 0
218 }
219 }
220
221 if {[opt-bool with-miniz]} {
222 define FOSSIL_ENABLE_MINIZ 1
223 msg-result "Using miniz for compression"
224 } else {
225 # Check for zlib, using the given location if specified
226 set zlibpath [opt-val with-zlib]
227 if {$zlibpath eq "tree"} {
228 set zlibdir [file dirname $autosetup(dir)]/compat/zlib
229 if {![file isdirectory $zlibdir]} {
230 user-error "The zlib in source tree directory does not exist"
231 }
232 cc-with [list -cflags "-I$zlibdir -L$zlibdir"]
233 define-append EXTRA_CFLAGS -I$zlibdir
234 define-append LIBS $zlibdir/libz.a
235 set ::zlib_lib $zlibdir/libz.a
236 msg-result "Using zlib in source tree"
237 } else {
238 if {$zlibpath ni {auto ""}} {
239 cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
240 define-append EXTRA_CFLAGS -I$zlibpath
241 define-append EXTRA_LDFLAGS -L$zlibpath
242 msg-result "Using zlib from $zlibpath"
243 }
244 if {![cc-check-includes zlib.h] || ![check-function-in-lib inflateEnd z]} {
245 user-error "zlib not found please install it or specify the location with --with-zlib"
246 }
247 set ::zlib_lib -lz
248 }
249 }
250
251 set ssldirs [opt-val with-openssl]
252 if {$ssldirs ne "none"} {
253 if {[opt-bool with-miniz]} {
254 user-error "The --with-miniz option is incompatible with OpenSSL"
255 }
256 set found 0
257 if {$ssldirs eq "tree"} {
258 set ssldir [file dirname $autosetup(dir)]/compat/openssl
259 if {![file isdirectory $ssldir]} {
260 user-error "The OpenSSL in source tree directory does not exist"
261
--- auto.def
+++ auto.def
@@ -3,11 +3,10 @@
3 use cc cc-lib
4
5 options {
6 with-openssl:path|auto|tree|none
7 => {Look for OpenSSL in the given path, automatically, in the source tree, or none}
 
8 with-zlib:path|auto|tree
9 => {Look for zlib in the given path, automatically, or in the source tree}
10 with-exec-rel-paths=0
11 => {Enable relative paths for external diff/gdiff}
12 with-legacy-mv-rm=0 => {Enable legacy behavior for mv/rm (skip checkout files)}
@@ -37,11 +36,10 @@
36
37 define EXTRA_CFLAGS ""
38 define EXTRA_LDFLAGS ""
39 define USE_SYSTEM_SQLITE 0
40 define USE_LINENOISE 0
 
41
42 # This procedure is a customized version of "cc-check-function-in-lib",
43 # that does not modify the LIBS variable. Its use prevents prematurely
44 # pulling in libraries that will be added later anyhow (e.g. "-ldl").
45 proc check-function-in-lib {function libs {otherlibs {}}} {
@@ -216,45 +214,38 @@
214 msg-result "no"
215 return 0
216 }
217 }
218
219 # Check for zlib, using the given location if specified
220 set zlibpath [opt-val with-zlib]
221 if {$zlibpath eq "tree"} {
222 set zlibdir [file dirname $autosetup(dir)]/compat/zlib
223 if {![file isdirectory $zlibdir]} {
224 user-error "The zlib in source tree directory does not exist"
225 }
226 cc-with [list -cflags "-I$zlibdir -L$zlibdir"]
227 define-append EXTRA_CFLAGS -I$zlibdir
228 define-append LIBS $zlibdir/libz.a
229 set ::zlib_lib $zlibdir/libz.a
230 msg-result "Using zlib in source tree"
231 } else {
232 if {$zlibpath ni {auto ""}} {
233 cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
234 define-append EXTRA_CFLAGS -I$zlibpath
235 define-append EXTRA_LDFLAGS -L$zlibpath
236 msg-result "Using zlib from $zlibpath"
237 }
238 if {![cc-check-includes zlib.h] || ![check-function-in-lib inflateEnd z]} {
239 user-error "zlib not found please install it or specify the location with --with-zlib"
240 }
241 set ::zlib_lib -lz
242 }
243
 
 
 
 
244
245 set ssldirs [opt-val with-openssl]
246 if {$ssldirs ne "none"} {
 
 
 
247 set found 0
248 if {$ssldirs eq "tree"} {
249 set ssldir [file dirname $autosetup(dir)]/compat/openssl
250 if {![file isdirectory $ssldir]} {
251 user-error "The OpenSSL in source tree directory does not exist"
252
+1 -6
--- src/blob.c
+++ src/blob.c
@@ -17,16 +17,11 @@
1717
**
1818
** A Blob is a variable-length containers for arbitrary string
1919
** or binary data.
2020
*/
2121
#include "config.h"
22
-#if defined(FOSSIL_ENABLE_MINIZ)
23
-# define MINIZ_HEADER_FILE_ONLY
24
-# include "miniz.c"
25
-#else
26
-# include <zlib.h>
27
-#endif
22
+#include <zlib.h>
2823
#include "blob.h"
2924
#if defined(_WIN32)
3025
#include <fcntl.h>
3126
#include <io.h>
3227
#endif
3328
--- src/blob.c
+++ src/blob.c
@@ -17,16 +17,11 @@
17 **
18 ** A Blob is a variable-length containers for arbitrary string
19 ** or binary data.
20 */
21 #include "config.h"
22 #if defined(FOSSIL_ENABLE_MINIZ)
23 # define MINIZ_HEADER_FILE_ONLY
24 # include "miniz.c"
25 #else
26 # include <zlib.h>
27 #endif
28 #include "blob.h"
29 #if defined(_WIN32)
30 #include <fcntl.h>
31 #include <io.h>
32 #endif
33
--- src/blob.c
+++ src/blob.c
@@ -17,16 +17,11 @@
17 **
18 ** A Blob is a variable-length containers for arbitrary string
19 ** or binary data.
20 */
21 #include "config.h"
22 #include <zlib.h>
 
 
 
 
 
23 #include "blob.h"
24 #if defined(_WIN32)
25 #include <fcntl.h>
26 #include <io.h>
27 #endif
28
+1 -6
--- src/gzip.c
+++ src/gzip.c
@@ -21,16 +21,11 @@
2121
** State information is stored in static variables, so this implementation
2222
** can only be building up a single GZIP file at a time.
2323
*/
2424
#include "config.h"
2525
#include <assert.h>
26
-#if defined(FOSSIL_ENABLE_MINIZ)
27
-# define MINIZ_HEADER_FILE_ONLY
28
-# include "miniz.c"
29
-#else
30
-# include <zlib.h>
31
-#endif
26
+#include <zlib.h>
3227
#include "gzip.h"
3328
3429
/*
3530
** State information for the GZIP file under construction.
3631
*/
3732
--- src/gzip.c
+++ src/gzip.c
@@ -21,16 +21,11 @@
21 ** State information is stored in static variables, so this implementation
22 ** can only be building up a single GZIP file at a time.
23 */
24 #include "config.h"
25 #include <assert.h>
26 #if defined(FOSSIL_ENABLE_MINIZ)
27 # define MINIZ_HEADER_FILE_ONLY
28 # include "miniz.c"
29 #else
30 # include <zlib.h>
31 #endif
32 #include "gzip.h"
33
34 /*
35 ** State information for the GZIP file under construction.
36 */
37
--- src/gzip.c
+++ src/gzip.c
@@ -21,16 +21,11 @@
21 ** State information is stored in static variables, so this implementation
22 ** can only be building up a single GZIP file at a time.
23 */
24 #include "config.h"
25 #include <assert.h>
26 #include <zlib.h>
 
 
 
 
 
27 #include "gzip.h"
28
29 /*
30 ** State information for the GZIP file under construction.
31 */
32
+1 -10
--- src/main.c
+++ src/main.c
@@ -33,16 +33,11 @@
3333
# include <errno.h> /* errno global */
3434
#endif
3535
#ifdef FOSSIL_ENABLE_SSL
3636
# include "openssl/crypto.h"
3737
#endif
38
-#if defined(FOSSIL_ENABLE_MINIZ)
39
-# define MINIZ_HEADER_FILE_ONLY
40
-# include "miniz.c"
41
-#else
42
-# include <zlib.h>
43
-#endif
38
+#include <zlib.h>
4439
#if INTERFACE
4540
#ifdef FOSSIL_ENABLE_TCL
4641
# include "tcl.h"
4742
#endif
4843
#ifdef FOSSIL_ENABLE_JSON
@@ -1031,15 +1026,11 @@
10311026
blob_appendf(pOut, "Compiled on %s %s using %s (%d-bit)\n",
10321027
__DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
10331028
blob_appendf(pOut, "SQLite %s %.30s\n", sqlite3_libversion(),
10341029
sqlite3_sourceid());
10351030
blob_appendf(pOut, "Schema version %s\n", AUX_SCHEMA_MAX);
1036
-#if defined(FOSSIL_ENABLE_MINIZ)
1037
- blob_appendf(pOut, "miniz %s, loaded %s\n", MZ_VERSION, mz_version());
1038
-#else
10391031
blob_appendf(pOut, "zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
1040
-#endif
10411032
#if defined(FOSSIL_ENABLE_SSL)
10421033
blob_appendf(pOut, "SSL (%s)\n", SSLeay_version(SSLEAY_VERSION));
10431034
#endif
10441035
#if defined(FOSSIL_ENABLE_LEGACY_MV_RM)
10451036
blob_append(pOut, "LEGACY_MV_RM\n", -1);
10461037
--- src/main.c
+++ src/main.c
@@ -33,16 +33,11 @@
33 # include <errno.h> /* errno global */
34 #endif
35 #ifdef FOSSIL_ENABLE_SSL
36 # include "openssl/crypto.h"
37 #endif
38 #if defined(FOSSIL_ENABLE_MINIZ)
39 # define MINIZ_HEADER_FILE_ONLY
40 # include "miniz.c"
41 #else
42 # include <zlib.h>
43 #endif
44 #if INTERFACE
45 #ifdef FOSSIL_ENABLE_TCL
46 # include "tcl.h"
47 #endif
48 #ifdef FOSSIL_ENABLE_JSON
@@ -1031,15 +1026,11 @@
1031 blob_appendf(pOut, "Compiled on %s %s using %s (%d-bit)\n",
1032 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
1033 blob_appendf(pOut, "SQLite %s %.30s\n", sqlite3_libversion(),
1034 sqlite3_sourceid());
1035 blob_appendf(pOut, "Schema version %s\n", AUX_SCHEMA_MAX);
1036 #if defined(FOSSIL_ENABLE_MINIZ)
1037 blob_appendf(pOut, "miniz %s, loaded %s\n", MZ_VERSION, mz_version());
1038 #else
1039 blob_appendf(pOut, "zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
1040 #endif
1041 #if defined(FOSSIL_ENABLE_SSL)
1042 blob_appendf(pOut, "SSL (%s)\n", SSLeay_version(SSLEAY_VERSION));
1043 #endif
1044 #if defined(FOSSIL_ENABLE_LEGACY_MV_RM)
1045 blob_append(pOut, "LEGACY_MV_RM\n", -1);
1046
--- src/main.c
+++ src/main.c
@@ -33,16 +33,11 @@
33 # include <errno.h> /* errno global */
34 #endif
35 #ifdef FOSSIL_ENABLE_SSL
36 # include "openssl/crypto.h"
37 #endif
38 #include <zlib.h>
 
 
 
 
 
39 #if INTERFACE
40 #ifdef FOSSIL_ENABLE_TCL
41 # include "tcl.h"
42 #endif
43 #ifdef FOSSIL_ENABLE_JSON
@@ -1031,15 +1026,11 @@
1026 blob_appendf(pOut, "Compiled on %s %s using %s (%d-bit)\n",
1027 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
1028 blob_appendf(pOut, "SQLite %s %.30s\n", sqlite3_libversion(),
1029 sqlite3_sourceid());
1030 blob_appendf(pOut, "Schema version %s\n", AUX_SCHEMA_MAX);
 
 
 
1031 blob_appendf(pOut, "zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
 
1032 #if defined(FOSSIL_ENABLE_SSL)
1033 blob_appendf(pOut, "SSL (%s)\n", SSLeay_version(SSLEAY_VERSION));
1034 #endif
1035 #if defined(FOSSIL_ENABLE_LEGACY_MV_RM)
1036 blob_append(pOut, "LEGACY_MV_RM\n", -1);
1037
+1 -17
--- src/main.mk
+++ src/main.mk
@@ -459,11 +459,11 @@
459459
$(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
460460
461461
$(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
462462
$(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
463463
464
-# Run the test suite.
464
+# Run the test suite.
465465
# Other flags that can be included in TESTFLAGS are:
466466
#
467467
# -halt Stop testing after the first failed test
468468
# -keep Keep the temporary workspace for debugging
469469
# -prot Write a detailed log of the tests to the file ./prot
@@ -498,30 +498,18 @@
498498
SHELL_OPTIONS = -Dmain=sqlite3_shell \
499499
-DSQLITE_OMIT_LOAD_EXTENSION=1 \
500500
-DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
501501
-DSQLITE_SHELL_DBNAME_PROC=fossil_open
502502
503
-# Setup the options used to compile the included miniz library.
504
-MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
505
- -DMINIZ_NO_TIME \
506
- -DMINIZ_NO_ARCHIVE_APIS
507
-
508503
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
509504
# to 1. If it is set to 1, then there is no need to build or link
510505
# the sqlite3.o object. Instead, the system SQLite will be linked
511506
# using -lsqlite3.
512507
SQLITE3_OBJ.1 =
513508
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
514509
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
515510
516
-# The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
517
-# set to 1. If it is set to 1, the miniz library included in the
518
-# source tree should be used; otherwise, it should not.
519
-MINIZ_OBJ.0 =
520
-MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
521
-MINIZ_OBJ. = $(MINIZ_OBJ.0)
522
-
523511
# The USE_LINENOISE variable may be undefined, set to 0, or set
524512
# to 1. If it is set to 0, then there is no need to build or link
525513
# the linenoise.o object.
526514
LINENOISE_DEF.0 =
527515
LINENOISE_DEF.1 = -DHAVE_LINENOISE
@@ -531,11 +519,10 @@
531519
LINENOISE_OBJ. = $(LINENOISE_OBJ.0)
532520
533521
534522
EXTRAOBJ = \
535523
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
536
- $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
537524
$(LINENOISE_OBJ.$(USE_LINENOISE)) \
538525
$(OBJDIR)/shell.o \
539526
$(OBJDIR)/th.o \
540527
$(OBJDIR)/th_lang.o \
541528
$(OBJDIR)/th_tcl.o \
@@ -1658,13 +1645,10 @@
16581645
16591646
$(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
16601647
$(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
16611648
16621649
1663
-$(OBJDIR)/miniz.o: $(SRCDIR)/miniz.c
1664
- $(XTCC) $(MINIZ_OPTIONS) -c $(SRCDIR)/miniz.c -o $@
1665
-
16661650
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
16671651
$(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
16681652
16691653
#
16701654
# The list of all the targets that do not correspond to real files. This stops
16711655
--- src/main.mk
+++ src/main.mk
@@ -459,11 +459,11 @@
459 $(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
460
461 $(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
462 $(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
463
464 # Run the test suite.
465 # Other flags that can be included in TESTFLAGS are:
466 #
467 # -halt Stop testing after the first failed test
468 # -keep Keep the temporary workspace for debugging
469 # -prot Write a detailed log of the tests to the file ./prot
@@ -498,30 +498,18 @@
498 SHELL_OPTIONS = -Dmain=sqlite3_shell \
499 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
500 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
501 -DSQLITE_SHELL_DBNAME_PROC=fossil_open
502
503 # Setup the options used to compile the included miniz library.
504 MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
505 -DMINIZ_NO_TIME \
506 -DMINIZ_NO_ARCHIVE_APIS
507
508 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
509 # to 1. If it is set to 1, then there is no need to build or link
510 # the sqlite3.o object. Instead, the system SQLite will be linked
511 # using -lsqlite3.
512 SQLITE3_OBJ.1 =
513 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
514 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
515
516 # The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
517 # set to 1. If it is set to 1, the miniz library included in the
518 # source tree should be used; otherwise, it should not.
519 MINIZ_OBJ.0 =
520 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
521 MINIZ_OBJ. = $(MINIZ_OBJ.0)
522
523 # The USE_LINENOISE variable may be undefined, set to 0, or set
524 # to 1. If it is set to 0, then there is no need to build or link
525 # the linenoise.o object.
526 LINENOISE_DEF.0 =
527 LINENOISE_DEF.1 = -DHAVE_LINENOISE
@@ -531,11 +519,10 @@
531 LINENOISE_OBJ. = $(LINENOISE_OBJ.0)
532
533
534 EXTRAOBJ = \
535 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
536 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
537 $(LINENOISE_OBJ.$(USE_LINENOISE)) \
538 $(OBJDIR)/shell.o \
539 $(OBJDIR)/th.o \
540 $(OBJDIR)/th_lang.o \
541 $(OBJDIR)/th_tcl.o \
@@ -1658,13 +1645,10 @@
1658
1659 $(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
1660 $(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
1661
1662
1663 $(OBJDIR)/miniz.o: $(SRCDIR)/miniz.c
1664 $(XTCC) $(MINIZ_OPTIONS) -c $(SRCDIR)/miniz.c -o $@
1665
1666 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1667 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
1668
1669 #
1670 # The list of all the targets that do not correspond to real files. This stops
1671
--- src/main.mk
+++ src/main.mk
@@ -459,11 +459,11 @@
459 $(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
460
461 $(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
462 $(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
463
464 # Run the test suite.
465 # Other flags that can be included in TESTFLAGS are:
466 #
467 # -halt Stop testing after the first failed test
468 # -keep Keep the temporary workspace for debugging
469 # -prot Write a detailed log of the tests to the file ./prot
@@ -498,30 +498,18 @@
498 SHELL_OPTIONS = -Dmain=sqlite3_shell \
499 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
500 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
501 -DSQLITE_SHELL_DBNAME_PROC=fossil_open
502
 
 
 
 
 
503 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
504 # to 1. If it is set to 1, then there is no need to build or link
505 # the sqlite3.o object. Instead, the system SQLite will be linked
506 # using -lsqlite3.
507 SQLITE3_OBJ.1 =
508 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
509 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
510
 
 
 
 
 
 
 
511 # The USE_LINENOISE variable may be undefined, set to 0, or set
512 # to 1. If it is set to 0, then there is no need to build or link
513 # the linenoise.o object.
514 LINENOISE_DEF.0 =
515 LINENOISE_DEF.1 = -DHAVE_LINENOISE
@@ -531,11 +519,10 @@
519 LINENOISE_OBJ. = $(LINENOISE_OBJ.0)
520
521
522 EXTRAOBJ = \
523 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
 
524 $(LINENOISE_OBJ.$(USE_LINENOISE)) \
525 $(OBJDIR)/shell.o \
526 $(OBJDIR)/th.o \
527 $(OBJDIR)/th_lang.o \
528 $(OBJDIR)/th_tcl.o \
@@ -1658,13 +1645,10 @@
1645
1646 $(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
1647 $(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
1648
1649
 
 
 
1650 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1651 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
1652
1653 #
1654 # The list of all the targets that do not correspond to real files. This stops
1655
+4 -102
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -178,18 +178,10 @@
178178
-DSQLITE_OMIT_LOAD_EXTENSION=1
179179
-DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE)
180180
-DSQLITE_SHELL_DBNAME_PROC=fossil_open
181181
}
182182
183
-# miniz (libz drop-in alternative) precompiler flags.
184
-#
185
-set MINIZ_OPTIONS {
186
- -DMINIZ_NO_STDIO
187
- -DMINIZ_NO_TIME
188
- -DMINIZ_NO_ARCHIVE_APIS
189
-}
190
-
191183
# Options used to compile the included SQLite shell on Windows.
192184
#
193185
set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
194186
lappend SHELL_WIN32_OPTIONS -Daccess=file_access
195187
lappend SHELL_WIN32_OPTIONS -Dsystem=fossil_system
@@ -271,12 +263,11 @@
271263
writeln "APPNAME = $name\$(E)"
272264
writeln "\n"
273265
274266
writeln [string map [list \
275267
<<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
276
- <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "] \
277
- <<<MINIZ_OPTIONS>>> [join $MINIZ_OPTIONS " \\\n "]] {
268
+ <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "]] {
278269
all: $(OBJDIR) $(APPNAME)
279270
280271
install: $(APPNAME)
281272
mkdir -p $(INSTALLDIR)
282273
mv $(APPNAME) $(INSTALLDIR)
@@ -303,11 +294,11 @@
303294
$(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
304295
305296
$(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
306297
$(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
307298
308
-# Run the test suite.
299
+# Run the test suite.
309300
# Other flags that can be included in TESTFLAGS are:
310301
#
311302
# -halt Stop testing after the first failed test
312303
# -keep Keep the temporary workspace for debugging
313304
# -prot Write a detailed log of the tests to the file ./prot
@@ -330,28 +321,18 @@
330321
SQLITE_OPTIONS = <<<SQLITE_OPTIONS>>>
331322
332323
# Setup the options used to compile the included SQLite shell.
333324
SHELL_OPTIONS = <<<SHELL_OPTIONS>>>
334325
335
-# Setup the options used to compile the included miniz library.
336
-MINIZ_OPTIONS = <<<MINIZ_OPTIONS>>>
337
-
338326
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
339327
# to 1. If it is set to 1, then there is no need to build or link
340328
# the sqlite3.o object. Instead, the system SQLite will be linked
341329
# using -lsqlite3.
342330
SQLITE3_OBJ.1 =
343331
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
344332
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
345333
346
-# The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
347
-# set to 1. If it is set to 1, the miniz library included in the
348
-# source tree should be used; otherwise, it should not.
349
-MINIZ_OBJ.0 =
350
-MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
351
-MINIZ_OBJ. = $(MINIZ_OBJ.0)
352
-
353334
# The USE_LINENOISE variable may be undefined, set to 0, or set
354335
# to 1. If it is set to 0, then there is no need to build or link
355336
# the linenoise.o object.
356337
LINENOISE_DEF.0 =
357338
LINENOISE_DEF.1 = -DHAVE_LINENOISE
@@ -362,11 +343,10 @@
362343
}]
363344
364345
writeln [string map [list <<<NEXT_LINE>>> \\] {
365346
EXTRAOBJ = <<<NEXT_LINE>>>
366347
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
367
- $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) <<<NEXT_LINE>>>
368348
$(LINENOISE_OBJ.$(USE_LINENOISE)) <<<NEXT_LINE>>>
369349
$(OBJDIR)/shell.o <<<NEXT_LINE>>>
370350
$(OBJDIR)/th.o <<<NEXT_LINE>>>
371351
$(OBJDIR)/th_lang.o <<<NEXT_LINE>>>
372352
$(OBJDIR)/th_tcl.o <<<NEXT_LINE>>>
@@ -439,13 +419,10 @@
439419
440420
writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
441421
writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$@\n"
442422
443423
writeln {
444
-$(OBJDIR)/miniz.o: $(SRCDIR)/miniz.c
445
- $(XTCC) $(MINIZ_OPTIONS) -c $(SRCDIR)/miniz.c -o $@
446
-
447424
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
448425
$(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
449426
450427
#
451428
# The list of all the targets that do not correspond to real files. This stops
@@ -558,14 +535,10 @@
558535
559536
#### Use 'system' SQLite
560537
#
561538
# USE_SYSTEM_SQLITE = 1
562539
563
-#### Use the miniz compression library
564
-#
565
-# FOSSIL_ENABLE_MINIZ = 1
566
-
567540
#### Use the Tcl source directory instead of the install directory?
568541
# This is useful when Tcl has been compiled statically with MinGW.
569542
#
570543
FOSSIL_TCL_SOURCE = 1
571544
@@ -597,18 +570,13 @@
597570
# used, taking into account whether zlib is actually enabled and the target
598571
# processor architecture.
599572
#
600573
ifndef X64
601574
SSLCONFIG = mingw
602
-ifndef FOSSIL_ENABLE_MINIZ
603575
ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
604576
LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
605577
else
606
-ZLIBCONFIG =
607
-LIBTARGETS =
608
-endif
609
-else
610578
SSLCONFIG = mingw64
611579
ZLIBCONFIG =
612580
LIBTARGETS =
613581
endif
614582
@@ -618,13 +586,11 @@
618586
SSLCONFIG += no-ssl2 no-ssl3 no-shared
619587
620588
#### When using zlib, make sure that OpenSSL is configured to use the zlib
621589
# that Fossil knows about (i.e. the one within the source tree).
622590
#
623
-ifndef FOSSIL_ENABLE_MINIZ
624591
SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
625
-endif
626592
627593
#### The directories where the OpenSSL include and library files are located.
628594
# The recommended usage here is to use the Sysinternals junction tool
629595
# to create a hard link between an "openssl-1.x" sub-directory of the
630596
# Fossil source code directory and the target OpenSSL source directory.
@@ -685,24 +651,19 @@
685651
TCC += -g
686652
else
687653
TCC += -Os
688654
endif
689655
690
-#### When not using the miniz compression library, zlib is required.
656
+#### zlib is required.
691657
#
692
-ifndef FOSSIL_ENABLE_MINIZ
693658
TCC += -L$(ZLIBDIR) -I$(ZINCDIR)
694
-endif
695659
696660
#### Compile resources for use in building executables that will run
697661
# on the target platform.
698662
#
699663
RCC = $(PREFIX)windres -I$(SRCDIR)
700
-
701
-ifndef FOSSIL_ENABLE_MINIZ
702664
RCC += -I$(ZINCDIR)
703
-endif
704665
705666
# With HTTPS support
706667
ifdef FOSSIL_ENABLE_SSL
707668
TCC += -L$(OPENSSLLIBDIR) -I$(OPENSSLINCDIR)
708669
RCC += -I$(OPENSSLINCDIR)
@@ -717,16 +678,10 @@
717678
TCC += -L$(TCLLIBDIR) -I$(TCLINCDIR)
718679
RCC += -I$(TCLINCDIR)
719680
endif
720681
endif
721682
722
-# With miniz (i.e. instead of zlib)
723
-ifdef FOSSIL_ENABLE_MINIZ
724
-TCC += -DFOSSIL_ENABLE_MINIZ=1
725
-RCC += -DFOSSIL_ENABLE_MINIZ=1
726
-endif
727
-
728683
# With MinGW command line handling workaround
729684
ifdef MINGW_IS_32BIT_ONLY
730685
TCC += -DBROKEN_MINGW_CMDLINE=1
731686
RCC += -DBROKEN_MINGW_CMDLINE=1
732687
endif
@@ -822,15 +777,13 @@
822777
# to link against the Z-Lib compression library. There are no
823778
# other mandatory dependencies.
824779
#
825780
LIB += -lmingwex
826781
827
-#### When not using the miniz compression library, zlib is required.
782
+#### zlib is required.
828783
#
829
-ifndef FOSSIL_ENABLE_MINIZ
830784
LIB += -lz
831
-endif
832785
833786
#### These libraries MUST appear in the same order as they do for Tcl
834787
# or linking with it will not work (exact reason unknown).
835788
#
836789
ifdef FOSSIL_ENABLE_TCL
@@ -928,16 +881,14 @@
928881
writeln {
929882
all: $(OBJDIR) $(APPNAME)
930883
931884
$(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
932885
ifdef USE_WINDOWS
933
- $(CAT) $(subst /,\,$(SRCDIR)\miniz.c) | $(GREP) "define MZ_VERSION" > $(subst /,\,$(OBJDIR)\minizver.h)
934886
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
935887
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
936888
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
937889
else
938
- $(CAT) $(SRCDIR)/miniz.c | $(GREP) "define MZ_VERSION" > $(OBJDIR)/minizver.h
939890
$(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
940891
$(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
941892
$(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
942893
endif
943894
$(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
@@ -990,23 +941,15 @@
990941
# the sqlite3.o object. Instead, the system SQLite will be linked
991942
# using -lsqlite3.
992943
SQLITE3_OBJ.1 =
993944
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
994945
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
995
-
996
-# The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
997
-# set to 1. If it is set to 1, the miniz library included in the
998
-# source tree should be used; otherwise, it should not.
999
-MINIZ_OBJ.0 =
1000
-MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
1001
-MINIZ_OBJ. = $(MINIZ_OBJ.0)
1002946
}
1003947
1004948
writeln [string map [list <<<NEXT_LINE>>> \\] {
1005949
EXTRAOBJ = <<<NEXT_LINE>>>
1006950
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
1007
- $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) <<<NEXT_LINE>>>
1008951
$(OBJDIR)/shell.o <<<NEXT_LINE>>>
1009952
$(OBJDIR)/th.o <<<NEXT_LINE>>>
1010953
$(OBJDIR)/th_lang.o <<<NEXT_LINE>>>
1011954
$(OBJDIR)/th_tcl.o <<<NEXT_LINE>>>
1012955
$(OBJDIR)/cson_amalgamation.o
@@ -1023,14 +966,11 @@
1023966
$(TCC) -c -o $@ -DASMINF -I$(ZLIBDIR) -O3 $(ZLIBDIR)/contrib/inflate86/inffas86.c
1024967
1025968
$(ZLIBDIR)/match.o:
1026969
$(TCC) -c -o $@ -DASMV $(ZLIBDIR)/contrib/asm686/match.S
1027970
1028
-
1029
-ifndef FOSSIL_ENABLE_MINIZ
1030971
LIBTARGETS += zlib
1031
-endif
1032972
1033973
openssl: $(LIBTARGETS)
1034974
cd $(OPENSSLLIBDIR);./Configure --cross-compile-prefix=$(PREFIX) $(SSLCONFIG)
1035975
$(MAKE) -C $(OPENSSLLIBDIR) build_libs
1036976
@@ -1113,18 +1053,14 @@
11131053
set MINGW_SQLITE_OPTIONS $SQLITE_WIN32_OPTIONS
11141054
lappend MINGW_SQLITE_OPTIONS -D_HAVE__MINGW_H
11151055
lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MALLOC_H
11161056
lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MSIZE
11171057
1118
-set MINIZ_WIN32_OPTIONS $MINIZ_OPTIONS
1119
-
11201058
set j " \\\n "
11211059
writeln "SQLITE_OPTIONS = [join $MINGW_SQLITE_OPTIONS $j]\n"
11221060
set j " \\\n "
11231061
writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS $j]\n"
1124
-set j " \\\n "
1125
-writeln "MINIZ_OPTIONS = [join $MINIZ_WIN32_OPTIONS $j]\n"
11261062
11271063
writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c \$(SRCDIR)/../win/Makefile.mingw"
11281064
writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$@\n"
11291065
11301066
writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
@@ -1141,13 +1077,10 @@
11411077
writeln "\t\$(XTCC) -c \$(SRCDIR)/th_lang.c -o \$@\n"
11421078
11431079
writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
11441080
writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$@\n"
11451081
1146
-writeln "\$(OBJDIR)/miniz.o:\t\$(SRCDIR)/miniz.c"
1147
-writeln "\t\$(XTCC) \$(MINIZ_OPTIONS) -c \$(SRCDIR)/miniz.c -o \$@\n"
1148
-
11491082
close $output_file
11501083
#
11511084
# End of the win/Makefile.mingw output
11521085
##############################################################################
11531086
##############################################################################
@@ -1385,15 +1318,10 @@
13851318
# Enable legacy treatment of the mv/rm commands?
13861319
!ifndef FOSSIL_ENABLE_LEGACY_MV_RM
13871320
FOSSIL_ENABLE_LEGACY_MV_RM = 0
13881321
!endif
13891322
1390
-# Enable use of miniz instead of zlib?
1391
-!ifndef FOSSIL_ENABLE_MINIZ
1392
-FOSSIL_ENABLE_MINIZ = 0
1393
-!endif
1394
-
13951323
# Enable OpenSSL support?
13961324
!ifndef FOSSIL_ENABLE_SSL
13971325
FOSSIL_ENABLE_SSL = 0
13981326
!endif
13991327
@@ -1505,14 +1433,11 @@
15051433
!else
15061434
ZLIB = zlib.lib
15071435
!endif
15081436
15091437
INCL = /I. /I$(SRCDIR) /I$B\win\include
1510
-
1511
-!if $(FOSSIL_ENABLE_MINIZ)==0
15121438
INCL = $(INCL) /I$(ZINCDIR)
1513
-!endif
15141439
15151440
!if $(FOSSIL_ENABLE_SSL)!=0
15161441
INCL = $(INCL) /I$(SSLINCDIR)
15171442
!endif
15181443
@@ -1571,19 +1496,12 @@
15711496
!if $(FOSSIL_DYNAMIC_BUILD)!=0
15721497
TCC = $(TCC) /DFOSSIL_DYNAMIC_BUILD=1
15731498
RCC = $(RCC) /DFOSSIL_DYNAMIC_BUILD=1
15741499
!endif
15751500
1576
-!if $(FOSSIL_ENABLE_MINIZ)==0
15771501
LIBS = $(LIBS) $(ZLIB)
15781502
LIBDIR = $(LIBDIR) /LIBPATH:$(ZLIBDIR)
1579
-!endif
1580
-
1581
-!if $(FOSSIL_ENABLE_MINIZ)!=0
1582
-TCC = $(TCC) /DFOSSIL_ENABLE_MINIZ=1
1583
-RCC = $(RCC) /DFOSSIL_ENABLE_MINIZ=1
1584
-!endif
15851503
15861504
!if $(FOSSIL_ENABLE_JSON)!=0
15871505
TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
15881506
RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
15891507
!endif
@@ -1632,14 +1550,10 @@
16321550
16331551
regsub -all {[-]D} [join $SHELL_WIN32_OPTIONS { }] {/D} MSC_SHELL_OPTIONS
16341552
set j " \\\n "
16351553
writeln "SHELL_OPTIONS = [join $MSC_SHELL_OPTIONS $j]\n"
16361554
1637
-regsub -all {[-]D} [join $MINIZ_WIN32_OPTIONS { }] {/D} MSC_MINIZ_OPTIONS
1638
-set j " \\\n "
1639
-writeln "MINIZ_OPTIONS = [join $MSC_MINIZ_OPTIONS $j]\n"
1640
-
16411555
writeln -nonewline "SRC = "
16421556
set i 0
16431557
foreach s [lsort $src] {
16441558
if {$i > 0} {
16451559
writeln " \\"
@@ -1669,14 +1583,10 @@
16691583
writeln -nonewline "\$(OX)\\$s\$O"; incr i
16701584
}
16711585
if {$i > 0} {
16721586
writeln " \\"
16731587
}
1674
-writeln "!if \$(FOSSIL_ENABLE_MINIZ)!=0"
1675
-writeln -nonewline " "
1676
-writeln "\$(OX)\\miniz\$O \\"; incr i
1677
-writeln "!endif"
16781588
writeln -nonewline " \$(OX)\\fossil.res\n\n"
16791589
writeln [string map [list <<<NEXT_LINE>>> \\] {
16801590
APPNAME = $(OX)\fossil$(E)
16811591
PDBNAME = $(OX)\fossil$(P)
16821592
APPTARGETS =
@@ -1704,14 +1614,12 @@
17041614
!else
17051615
@pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
17061616
!endif
17071617
!endif
17081618
1709
-!if $(FOSSIL_ENABLE_MINIZ)==0
17101619
!if $(FOSSIL_BUILD_ZLIB)!=0
17111620
APPTARGETS = $(APPTARGETS) zlib
1712
-!endif
17131621
!endif
17141622
17151623
!if $(FOSSIL_ENABLE_SSL)!=0
17161624
!if $(FOSSIL_BUILD_SSL)!=0
17171625
APPTARGETS = $(APPTARGETS) openssl
@@ -1730,13 +1638,10 @@
17301638
foreach s [lsort [concat $src $AdditionalObj]] {
17311639
writeln "\techo \$(OX)\\$s.obj $redir \$@"
17321640
set redir {>>}
17331641
}
17341642
set redir {>>}
1735
-writeln "!if \$(FOSSIL_ENABLE_MINIZ)!=0"
1736
-writeln "\techo \$(OX)\\miniz.obj $redir \$@"
1737
-writeln "!endif"
17381643
writeln "\techo \$(LIBS) $redir \$@"
17391644
writeln {
17401645
$(OX):
17411646
@-mkdir $@
17421647
@@ -1771,13 +1676,10 @@
17711676
$(TCC) /Fo$@ -c $**
17721677
17731678
$(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
17741679
$(TCC) /Fo$@ -c $**
17751680
1776
-$(OX)\miniz$O : $(SRCDIR)\miniz.c
1777
- $(TCC) /Fo$@ -c $(MINIZ_OPTIONS) $(SRCDIR)\miniz.c
1778
-
17791681
VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
17801682
$** > $@
17811683
$(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
17821684
$(TCC) /Fo$@ /c $**
17831685
17841686
17851687
DELETED src/miniz.c
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -178,18 +178,10 @@
178 -DSQLITE_OMIT_LOAD_EXTENSION=1
179 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE)
180 -DSQLITE_SHELL_DBNAME_PROC=fossil_open
181 }
182
183 # miniz (libz drop-in alternative) precompiler flags.
184 #
185 set MINIZ_OPTIONS {
186 -DMINIZ_NO_STDIO
187 -DMINIZ_NO_TIME
188 -DMINIZ_NO_ARCHIVE_APIS
189 }
190
191 # Options used to compile the included SQLite shell on Windows.
192 #
193 set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
194 lappend SHELL_WIN32_OPTIONS -Daccess=file_access
195 lappend SHELL_WIN32_OPTIONS -Dsystem=fossil_system
@@ -271,12 +263,11 @@
271 writeln "APPNAME = $name\$(E)"
272 writeln "\n"
273
274 writeln [string map [list \
275 <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
276 <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "] \
277 <<<MINIZ_OPTIONS>>> [join $MINIZ_OPTIONS " \\\n "]] {
278 all: $(OBJDIR) $(APPNAME)
279
280 install: $(APPNAME)
281 mkdir -p $(INSTALLDIR)
282 mv $(APPNAME) $(INSTALLDIR)
@@ -303,11 +294,11 @@
303 $(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
304
305 $(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
306 $(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
307
308 # Run the test suite.
309 # Other flags that can be included in TESTFLAGS are:
310 #
311 # -halt Stop testing after the first failed test
312 # -keep Keep the temporary workspace for debugging
313 # -prot Write a detailed log of the tests to the file ./prot
@@ -330,28 +321,18 @@
330 SQLITE_OPTIONS = <<<SQLITE_OPTIONS>>>
331
332 # Setup the options used to compile the included SQLite shell.
333 SHELL_OPTIONS = <<<SHELL_OPTIONS>>>
334
335 # Setup the options used to compile the included miniz library.
336 MINIZ_OPTIONS = <<<MINIZ_OPTIONS>>>
337
338 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
339 # to 1. If it is set to 1, then there is no need to build or link
340 # the sqlite3.o object. Instead, the system SQLite will be linked
341 # using -lsqlite3.
342 SQLITE3_OBJ.1 =
343 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
344 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
345
346 # The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
347 # set to 1. If it is set to 1, the miniz library included in the
348 # source tree should be used; otherwise, it should not.
349 MINIZ_OBJ.0 =
350 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
351 MINIZ_OBJ. = $(MINIZ_OBJ.0)
352
353 # The USE_LINENOISE variable may be undefined, set to 0, or set
354 # to 1. If it is set to 0, then there is no need to build or link
355 # the linenoise.o object.
356 LINENOISE_DEF.0 =
357 LINENOISE_DEF.1 = -DHAVE_LINENOISE
@@ -362,11 +343,10 @@
362 }]
363
364 writeln [string map [list <<<NEXT_LINE>>> \\] {
365 EXTRAOBJ = <<<NEXT_LINE>>>
366 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
367 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) <<<NEXT_LINE>>>
368 $(LINENOISE_OBJ.$(USE_LINENOISE)) <<<NEXT_LINE>>>
369 $(OBJDIR)/shell.o <<<NEXT_LINE>>>
370 $(OBJDIR)/th.o <<<NEXT_LINE>>>
371 $(OBJDIR)/th_lang.o <<<NEXT_LINE>>>
372 $(OBJDIR)/th_tcl.o <<<NEXT_LINE>>>
@@ -439,13 +419,10 @@
439
440 writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
441 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$@\n"
442
443 writeln {
444 $(OBJDIR)/miniz.o: $(SRCDIR)/miniz.c
445 $(XTCC) $(MINIZ_OPTIONS) -c $(SRCDIR)/miniz.c -o $@
446
447 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
448 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
449
450 #
451 # The list of all the targets that do not correspond to real files. This stops
@@ -558,14 +535,10 @@
558
559 #### Use 'system' SQLite
560 #
561 # USE_SYSTEM_SQLITE = 1
562
563 #### Use the miniz compression library
564 #
565 # FOSSIL_ENABLE_MINIZ = 1
566
567 #### Use the Tcl source directory instead of the install directory?
568 # This is useful when Tcl has been compiled statically with MinGW.
569 #
570 FOSSIL_TCL_SOURCE = 1
571
@@ -597,18 +570,13 @@
597 # used, taking into account whether zlib is actually enabled and the target
598 # processor architecture.
599 #
600 ifndef X64
601 SSLCONFIG = mingw
602 ifndef FOSSIL_ENABLE_MINIZ
603 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
604 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
605 else
606 ZLIBCONFIG =
607 LIBTARGETS =
608 endif
609 else
610 SSLCONFIG = mingw64
611 ZLIBCONFIG =
612 LIBTARGETS =
613 endif
614
@@ -618,13 +586,11 @@
618 SSLCONFIG += no-ssl2 no-ssl3 no-shared
619
620 #### When using zlib, make sure that OpenSSL is configured to use the zlib
621 # that Fossil knows about (i.e. the one within the source tree).
622 #
623 ifndef FOSSIL_ENABLE_MINIZ
624 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
625 endif
626
627 #### The directories where the OpenSSL include and library files are located.
628 # The recommended usage here is to use the Sysinternals junction tool
629 # to create a hard link between an "openssl-1.x" sub-directory of the
630 # Fossil source code directory and the target OpenSSL source directory.
@@ -685,24 +651,19 @@
685 TCC += -g
686 else
687 TCC += -Os
688 endif
689
690 #### When not using the miniz compression library, zlib is required.
691 #
692 ifndef FOSSIL_ENABLE_MINIZ
693 TCC += -L$(ZLIBDIR) -I$(ZINCDIR)
694 endif
695
696 #### Compile resources for use in building executables that will run
697 # on the target platform.
698 #
699 RCC = $(PREFIX)windres -I$(SRCDIR)
700
701 ifndef FOSSIL_ENABLE_MINIZ
702 RCC += -I$(ZINCDIR)
703 endif
704
705 # With HTTPS support
706 ifdef FOSSIL_ENABLE_SSL
707 TCC += -L$(OPENSSLLIBDIR) -I$(OPENSSLINCDIR)
708 RCC += -I$(OPENSSLINCDIR)
@@ -717,16 +678,10 @@
717 TCC += -L$(TCLLIBDIR) -I$(TCLINCDIR)
718 RCC += -I$(TCLINCDIR)
719 endif
720 endif
721
722 # With miniz (i.e. instead of zlib)
723 ifdef FOSSIL_ENABLE_MINIZ
724 TCC += -DFOSSIL_ENABLE_MINIZ=1
725 RCC += -DFOSSIL_ENABLE_MINIZ=1
726 endif
727
728 # With MinGW command line handling workaround
729 ifdef MINGW_IS_32BIT_ONLY
730 TCC += -DBROKEN_MINGW_CMDLINE=1
731 RCC += -DBROKEN_MINGW_CMDLINE=1
732 endif
@@ -822,15 +777,13 @@
822 # to link against the Z-Lib compression library. There are no
823 # other mandatory dependencies.
824 #
825 LIB += -lmingwex
826
827 #### When not using the miniz compression library, zlib is required.
828 #
829 ifndef FOSSIL_ENABLE_MINIZ
830 LIB += -lz
831 endif
832
833 #### These libraries MUST appear in the same order as they do for Tcl
834 # or linking with it will not work (exact reason unknown).
835 #
836 ifdef FOSSIL_ENABLE_TCL
@@ -928,16 +881,14 @@
928 writeln {
929 all: $(OBJDIR) $(APPNAME)
930
931 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
932 ifdef USE_WINDOWS
933 $(CAT) $(subst /,\,$(SRCDIR)\miniz.c) | $(GREP) "define MZ_VERSION" > $(subst /,\,$(OBJDIR)\minizver.h)
934 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
935 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
936 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
937 else
938 $(CAT) $(SRCDIR)/miniz.c | $(GREP) "define MZ_VERSION" > $(OBJDIR)/minizver.h
939 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
940 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
941 $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
942 endif
943 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
@@ -990,23 +941,15 @@
990 # the sqlite3.o object. Instead, the system SQLite will be linked
991 # using -lsqlite3.
992 SQLITE3_OBJ.1 =
993 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
994 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
995
996 # The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
997 # set to 1. If it is set to 1, the miniz library included in the
998 # source tree should be used; otherwise, it should not.
999 MINIZ_OBJ.0 =
1000 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
1001 MINIZ_OBJ. = $(MINIZ_OBJ.0)
1002 }
1003
1004 writeln [string map [list <<<NEXT_LINE>>> \\] {
1005 EXTRAOBJ = <<<NEXT_LINE>>>
1006 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
1007 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) <<<NEXT_LINE>>>
1008 $(OBJDIR)/shell.o <<<NEXT_LINE>>>
1009 $(OBJDIR)/th.o <<<NEXT_LINE>>>
1010 $(OBJDIR)/th_lang.o <<<NEXT_LINE>>>
1011 $(OBJDIR)/th_tcl.o <<<NEXT_LINE>>>
1012 $(OBJDIR)/cson_amalgamation.o
@@ -1023,14 +966,11 @@
1023 $(TCC) -c -o $@ -DASMINF -I$(ZLIBDIR) -O3 $(ZLIBDIR)/contrib/inflate86/inffas86.c
1024
1025 $(ZLIBDIR)/match.o:
1026 $(TCC) -c -o $@ -DASMV $(ZLIBDIR)/contrib/asm686/match.S
1027
1028
1029 ifndef FOSSIL_ENABLE_MINIZ
1030 LIBTARGETS += zlib
1031 endif
1032
1033 openssl: $(LIBTARGETS)
1034 cd $(OPENSSLLIBDIR);./Configure --cross-compile-prefix=$(PREFIX) $(SSLCONFIG)
1035 $(MAKE) -C $(OPENSSLLIBDIR) build_libs
1036
@@ -1113,18 +1053,14 @@
1113 set MINGW_SQLITE_OPTIONS $SQLITE_WIN32_OPTIONS
1114 lappend MINGW_SQLITE_OPTIONS -D_HAVE__MINGW_H
1115 lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MALLOC_H
1116 lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MSIZE
1117
1118 set MINIZ_WIN32_OPTIONS $MINIZ_OPTIONS
1119
1120 set j " \\\n "
1121 writeln "SQLITE_OPTIONS = [join $MINGW_SQLITE_OPTIONS $j]\n"
1122 set j " \\\n "
1123 writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS $j]\n"
1124 set j " \\\n "
1125 writeln "MINIZ_OPTIONS = [join $MINIZ_WIN32_OPTIONS $j]\n"
1126
1127 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c \$(SRCDIR)/../win/Makefile.mingw"
1128 writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$@\n"
1129
1130 writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
@@ -1141,13 +1077,10 @@
1141 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_lang.c -o \$@\n"
1142
1143 writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
1144 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$@\n"
1145
1146 writeln "\$(OBJDIR)/miniz.o:\t\$(SRCDIR)/miniz.c"
1147 writeln "\t\$(XTCC) \$(MINIZ_OPTIONS) -c \$(SRCDIR)/miniz.c -o \$@\n"
1148
1149 close $output_file
1150 #
1151 # End of the win/Makefile.mingw output
1152 ##############################################################################
1153 ##############################################################################
@@ -1385,15 +1318,10 @@
1385 # Enable legacy treatment of the mv/rm commands?
1386 !ifndef FOSSIL_ENABLE_LEGACY_MV_RM
1387 FOSSIL_ENABLE_LEGACY_MV_RM = 0
1388 !endif
1389
1390 # Enable use of miniz instead of zlib?
1391 !ifndef FOSSIL_ENABLE_MINIZ
1392 FOSSIL_ENABLE_MINIZ = 0
1393 !endif
1394
1395 # Enable OpenSSL support?
1396 !ifndef FOSSIL_ENABLE_SSL
1397 FOSSIL_ENABLE_SSL = 0
1398 !endif
1399
@@ -1505,14 +1433,11 @@
1505 !else
1506 ZLIB = zlib.lib
1507 !endif
1508
1509 INCL = /I. /I$(SRCDIR) /I$B\win\include
1510
1511 !if $(FOSSIL_ENABLE_MINIZ)==0
1512 INCL = $(INCL) /I$(ZINCDIR)
1513 !endif
1514
1515 !if $(FOSSIL_ENABLE_SSL)!=0
1516 INCL = $(INCL) /I$(SSLINCDIR)
1517 !endif
1518
@@ -1571,19 +1496,12 @@
1571 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1572 TCC = $(TCC) /DFOSSIL_DYNAMIC_BUILD=1
1573 RCC = $(RCC) /DFOSSIL_DYNAMIC_BUILD=1
1574 !endif
1575
1576 !if $(FOSSIL_ENABLE_MINIZ)==0
1577 LIBS = $(LIBS) $(ZLIB)
1578 LIBDIR = $(LIBDIR) /LIBPATH:$(ZLIBDIR)
1579 !endif
1580
1581 !if $(FOSSIL_ENABLE_MINIZ)!=0
1582 TCC = $(TCC) /DFOSSIL_ENABLE_MINIZ=1
1583 RCC = $(RCC) /DFOSSIL_ENABLE_MINIZ=1
1584 !endif
1585
1586 !if $(FOSSIL_ENABLE_JSON)!=0
1587 TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
1588 RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
1589 !endif
@@ -1632,14 +1550,10 @@
1632
1633 regsub -all {[-]D} [join $SHELL_WIN32_OPTIONS { }] {/D} MSC_SHELL_OPTIONS
1634 set j " \\\n "
1635 writeln "SHELL_OPTIONS = [join $MSC_SHELL_OPTIONS $j]\n"
1636
1637 regsub -all {[-]D} [join $MINIZ_WIN32_OPTIONS { }] {/D} MSC_MINIZ_OPTIONS
1638 set j " \\\n "
1639 writeln "MINIZ_OPTIONS = [join $MSC_MINIZ_OPTIONS $j]\n"
1640
1641 writeln -nonewline "SRC = "
1642 set i 0
1643 foreach s [lsort $src] {
1644 if {$i > 0} {
1645 writeln " \\"
@@ -1669,14 +1583,10 @@
1669 writeln -nonewline "\$(OX)\\$s\$O"; incr i
1670 }
1671 if {$i > 0} {
1672 writeln " \\"
1673 }
1674 writeln "!if \$(FOSSIL_ENABLE_MINIZ)!=0"
1675 writeln -nonewline " "
1676 writeln "\$(OX)\\miniz\$O \\"; incr i
1677 writeln "!endif"
1678 writeln -nonewline " \$(OX)\\fossil.res\n\n"
1679 writeln [string map [list <<<NEXT_LINE>>> \\] {
1680 APPNAME = $(OX)\fossil$(E)
1681 PDBNAME = $(OX)\fossil$(P)
1682 APPTARGETS =
@@ -1704,14 +1614,12 @@
1704 !else
1705 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
1706 !endif
1707 !endif
1708
1709 !if $(FOSSIL_ENABLE_MINIZ)==0
1710 !if $(FOSSIL_BUILD_ZLIB)!=0
1711 APPTARGETS = $(APPTARGETS) zlib
1712 !endif
1713 !endif
1714
1715 !if $(FOSSIL_ENABLE_SSL)!=0
1716 !if $(FOSSIL_BUILD_SSL)!=0
1717 APPTARGETS = $(APPTARGETS) openssl
@@ -1730,13 +1638,10 @@
1730 foreach s [lsort [concat $src $AdditionalObj]] {
1731 writeln "\techo \$(OX)\\$s.obj $redir \$@"
1732 set redir {>>}
1733 }
1734 set redir {>>}
1735 writeln "!if \$(FOSSIL_ENABLE_MINIZ)!=0"
1736 writeln "\techo \$(OX)\\miniz.obj $redir \$@"
1737 writeln "!endif"
1738 writeln "\techo \$(LIBS) $redir \$@"
1739 writeln {
1740 $(OX):
1741 @-mkdir $@
1742
@@ -1771,13 +1676,10 @@
1771 $(TCC) /Fo$@ -c $**
1772
1773 $(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
1774 $(TCC) /Fo$@ -c $**
1775
1776 $(OX)\miniz$O : $(SRCDIR)\miniz.c
1777 $(TCC) /Fo$@ -c $(MINIZ_OPTIONS) $(SRCDIR)\miniz.c
1778
1779 VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
1780 $** > $@
1781 $(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
1782 $(TCC) /Fo$@ /c $**
1783
1784
1785 ELETED src/miniz.c
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -178,18 +178,10 @@
178 -DSQLITE_OMIT_LOAD_EXTENSION=1
179 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE)
180 -DSQLITE_SHELL_DBNAME_PROC=fossil_open
181 }
182
 
 
 
 
 
 
 
 
183 # Options used to compile the included SQLite shell on Windows.
184 #
185 set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
186 lappend SHELL_WIN32_OPTIONS -Daccess=file_access
187 lappend SHELL_WIN32_OPTIONS -Dsystem=fossil_system
@@ -271,12 +263,11 @@
263 writeln "APPNAME = $name\$(E)"
264 writeln "\n"
265
266 writeln [string map [list \
267 <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
268 <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "]] {
 
269 all: $(OBJDIR) $(APPNAME)
270
271 install: $(APPNAME)
272 mkdir -p $(INSTALLDIR)
273 mv $(APPNAME) $(INSTALLDIR)
@@ -303,11 +294,11 @@
294 $(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
295
296 $(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
297 $(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
298
299 # Run the test suite.
300 # Other flags that can be included in TESTFLAGS are:
301 #
302 # -halt Stop testing after the first failed test
303 # -keep Keep the temporary workspace for debugging
304 # -prot Write a detailed log of the tests to the file ./prot
@@ -330,28 +321,18 @@
321 SQLITE_OPTIONS = <<<SQLITE_OPTIONS>>>
322
323 # Setup the options used to compile the included SQLite shell.
324 SHELL_OPTIONS = <<<SHELL_OPTIONS>>>
325
 
 
 
326 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
327 # to 1. If it is set to 1, then there is no need to build or link
328 # the sqlite3.o object. Instead, the system SQLite will be linked
329 # using -lsqlite3.
330 SQLITE3_OBJ.1 =
331 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
332 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
333
 
 
 
 
 
 
 
334 # The USE_LINENOISE variable may be undefined, set to 0, or set
335 # to 1. If it is set to 0, then there is no need to build or link
336 # the linenoise.o object.
337 LINENOISE_DEF.0 =
338 LINENOISE_DEF.1 = -DHAVE_LINENOISE
@@ -362,11 +343,10 @@
343 }]
344
345 writeln [string map [list <<<NEXT_LINE>>> \\] {
346 EXTRAOBJ = <<<NEXT_LINE>>>
347 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
 
348 $(LINENOISE_OBJ.$(USE_LINENOISE)) <<<NEXT_LINE>>>
349 $(OBJDIR)/shell.o <<<NEXT_LINE>>>
350 $(OBJDIR)/th.o <<<NEXT_LINE>>>
351 $(OBJDIR)/th_lang.o <<<NEXT_LINE>>>
352 $(OBJDIR)/th_tcl.o <<<NEXT_LINE>>>
@@ -439,13 +419,10 @@
419
420 writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
421 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$@\n"
422
423 writeln {
 
 
 
424 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
425 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
426
427 #
428 # The list of all the targets that do not correspond to real files. This stops
@@ -558,14 +535,10 @@
535
536 #### Use 'system' SQLite
537 #
538 # USE_SYSTEM_SQLITE = 1
539
 
 
 
 
540 #### Use the Tcl source directory instead of the install directory?
541 # This is useful when Tcl has been compiled statically with MinGW.
542 #
543 FOSSIL_TCL_SOURCE = 1
544
@@ -597,18 +570,13 @@
570 # used, taking into account whether zlib is actually enabled and the target
571 # processor architecture.
572 #
573 ifndef X64
574 SSLCONFIG = mingw
 
575 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
576 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
577 else
 
 
 
 
578 SSLCONFIG = mingw64
579 ZLIBCONFIG =
580 LIBTARGETS =
581 endif
582
@@ -618,13 +586,11 @@
586 SSLCONFIG += no-ssl2 no-ssl3 no-shared
587
588 #### When using zlib, make sure that OpenSSL is configured to use the zlib
589 # that Fossil knows about (i.e. the one within the source tree).
590 #
 
591 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
 
592
593 #### The directories where the OpenSSL include and library files are located.
594 # The recommended usage here is to use the Sysinternals junction tool
595 # to create a hard link between an "openssl-1.x" sub-directory of the
596 # Fossil source code directory and the target OpenSSL source directory.
@@ -685,24 +651,19 @@
651 TCC += -g
652 else
653 TCC += -Os
654 endif
655
656 #### zlib is required.
657 #
 
658 TCC += -L$(ZLIBDIR) -I$(ZINCDIR)
 
659
660 #### Compile resources for use in building executables that will run
661 # on the target platform.
662 #
663 RCC = $(PREFIX)windres -I$(SRCDIR)
 
 
664 RCC += -I$(ZINCDIR)
 
665
666 # With HTTPS support
667 ifdef FOSSIL_ENABLE_SSL
668 TCC += -L$(OPENSSLLIBDIR) -I$(OPENSSLINCDIR)
669 RCC += -I$(OPENSSLINCDIR)
@@ -717,16 +678,10 @@
678 TCC += -L$(TCLLIBDIR) -I$(TCLINCDIR)
679 RCC += -I$(TCLINCDIR)
680 endif
681 endif
682
 
 
 
 
 
 
683 # With MinGW command line handling workaround
684 ifdef MINGW_IS_32BIT_ONLY
685 TCC += -DBROKEN_MINGW_CMDLINE=1
686 RCC += -DBROKEN_MINGW_CMDLINE=1
687 endif
@@ -822,15 +777,13 @@
777 # to link against the Z-Lib compression library. There are no
778 # other mandatory dependencies.
779 #
780 LIB += -lmingwex
781
782 #### zlib is required.
783 #
 
784 LIB += -lz
 
785
786 #### These libraries MUST appear in the same order as they do for Tcl
787 # or linking with it will not work (exact reason unknown).
788 #
789 ifdef FOSSIL_ENABLE_TCL
@@ -928,16 +881,14 @@
881 writeln {
882 all: $(OBJDIR) $(APPNAME)
883
884 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
885 ifdef USE_WINDOWS
 
886 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
887 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
888 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
889 else
 
890 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
891 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
892 $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
893 endif
894 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
@@ -990,23 +941,15 @@
941 # the sqlite3.o object. Instead, the system SQLite will be linked
942 # using -lsqlite3.
943 SQLITE3_OBJ.1 =
944 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
945 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
 
 
 
 
 
 
 
946 }
947
948 writeln [string map [list <<<NEXT_LINE>>> \\] {
949 EXTRAOBJ = <<<NEXT_LINE>>>
950 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
 
951 $(OBJDIR)/shell.o <<<NEXT_LINE>>>
952 $(OBJDIR)/th.o <<<NEXT_LINE>>>
953 $(OBJDIR)/th_lang.o <<<NEXT_LINE>>>
954 $(OBJDIR)/th_tcl.o <<<NEXT_LINE>>>
955 $(OBJDIR)/cson_amalgamation.o
@@ -1023,14 +966,11 @@
966 $(TCC) -c -o $@ -DASMINF -I$(ZLIBDIR) -O3 $(ZLIBDIR)/contrib/inflate86/inffas86.c
967
968 $(ZLIBDIR)/match.o:
969 $(TCC) -c -o $@ -DASMV $(ZLIBDIR)/contrib/asm686/match.S
970
 
 
971 LIBTARGETS += zlib
 
972
973 openssl: $(LIBTARGETS)
974 cd $(OPENSSLLIBDIR);./Configure --cross-compile-prefix=$(PREFIX) $(SSLCONFIG)
975 $(MAKE) -C $(OPENSSLLIBDIR) build_libs
976
@@ -1113,18 +1053,14 @@
1053 set MINGW_SQLITE_OPTIONS $SQLITE_WIN32_OPTIONS
1054 lappend MINGW_SQLITE_OPTIONS -D_HAVE__MINGW_H
1055 lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MALLOC_H
1056 lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MSIZE
1057
 
 
1058 set j " \\\n "
1059 writeln "SQLITE_OPTIONS = [join $MINGW_SQLITE_OPTIONS $j]\n"
1060 set j " \\\n "
1061 writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS $j]\n"
 
 
1062
1063 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c \$(SRCDIR)/../win/Makefile.mingw"
1064 writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$@\n"
1065
1066 writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
@@ -1141,13 +1077,10 @@
1077 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_lang.c -o \$@\n"
1078
1079 writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
1080 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$@\n"
1081
 
 
 
1082 close $output_file
1083 #
1084 # End of the win/Makefile.mingw output
1085 ##############################################################################
1086 ##############################################################################
@@ -1385,15 +1318,10 @@
1318 # Enable legacy treatment of the mv/rm commands?
1319 !ifndef FOSSIL_ENABLE_LEGACY_MV_RM
1320 FOSSIL_ENABLE_LEGACY_MV_RM = 0
1321 !endif
1322
 
 
 
 
 
1323 # Enable OpenSSL support?
1324 !ifndef FOSSIL_ENABLE_SSL
1325 FOSSIL_ENABLE_SSL = 0
1326 !endif
1327
@@ -1505,14 +1433,11 @@
1433 !else
1434 ZLIB = zlib.lib
1435 !endif
1436
1437 INCL = /I. /I$(SRCDIR) /I$B\win\include
 
 
1438 INCL = $(INCL) /I$(ZINCDIR)
 
1439
1440 !if $(FOSSIL_ENABLE_SSL)!=0
1441 INCL = $(INCL) /I$(SSLINCDIR)
1442 !endif
1443
@@ -1571,19 +1496,12 @@
1496 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1497 TCC = $(TCC) /DFOSSIL_DYNAMIC_BUILD=1
1498 RCC = $(RCC) /DFOSSIL_DYNAMIC_BUILD=1
1499 !endif
1500
 
1501 LIBS = $(LIBS) $(ZLIB)
1502 LIBDIR = $(LIBDIR) /LIBPATH:$(ZLIBDIR)
 
 
 
 
 
 
1503
1504 !if $(FOSSIL_ENABLE_JSON)!=0
1505 TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
1506 RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
1507 !endif
@@ -1632,14 +1550,10 @@
1550
1551 regsub -all {[-]D} [join $SHELL_WIN32_OPTIONS { }] {/D} MSC_SHELL_OPTIONS
1552 set j " \\\n "
1553 writeln "SHELL_OPTIONS = [join $MSC_SHELL_OPTIONS $j]\n"
1554
 
 
 
 
1555 writeln -nonewline "SRC = "
1556 set i 0
1557 foreach s [lsort $src] {
1558 if {$i > 0} {
1559 writeln " \\"
@@ -1669,14 +1583,10 @@
1583 writeln -nonewline "\$(OX)\\$s\$O"; incr i
1584 }
1585 if {$i > 0} {
1586 writeln " \\"
1587 }
 
 
 
 
1588 writeln -nonewline " \$(OX)\\fossil.res\n\n"
1589 writeln [string map [list <<<NEXT_LINE>>> \\] {
1590 APPNAME = $(OX)\fossil$(E)
1591 PDBNAME = $(OX)\fossil$(P)
1592 APPTARGETS =
@@ -1704,14 +1614,12 @@
1614 !else
1615 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
1616 !endif
1617 !endif
1618
 
1619 !if $(FOSSIL_BUILD_ZLIB)!=0
1620 APPTARGETS = $(APPTARGETS) zlib
 
1621 !endif
1622
1623 !if $(FOSSIL_ENABLE_SSL)!=0
1624 !if $(FOSSIL_BUILD_SSL)!=0
1625 APPTARGETS = $(APPTARGETS) openssl
@@ -1730,13 +1638,10 @@
1638 foreach s [lsort [concat $src $AdditionalObj]] {
1639 writeln "\techo \$(OX)\\$s.obj $redir \$@"
1640 set redir {>>}
1641 }
1642 set redir {>>}
 
 
 
1643 writeln "\techo \$(LIBS) $redir \$@"
1644 writeln {
1645 $(OX):
1646 @-mkdir $@
1647
@@ -1771,13 +1676,10 @@
1676 $(TCC) /Fo$@ -c $**
1677
1678 $(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
1679 $(TCC) /Fo$@ -c $**
1680
 
 
 
1681 VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
1682 $** > $@
1683 $(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
1684 $(TCC) /Fo$@ /c $**
1685
1686
1687 ELETED src/miniz.c
D src/miniz.c
-2251
--- a/src/miniz.c
+++ b/src/miniz.c
@@ -1,2251 +0,0 @@
1
-/* miniz.c v1.15 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
2
- See "unlicense" statement at the end of this file.
3
- Rich Geldreich <[email protected]>, last updated Oct. 13, 2013
4
- Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
5
-
6
- Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define
7
- MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros).
8
-
9
- * Change History
10
- 10/1ller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
11
-void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip);
12
-void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
13
-
14
-// Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
15
-typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
16
-
17
-// tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function intern return MZ_DATA_ERROR;
18
-
19
- if (pState->m_has_flushed && (flush != MZ_FINISH)) return MZ_STREAM_ERROR;
20
- pState->m_has_flushed |= (flush == MZ_FINISH);
21
-
22
- if ((flush == MZ_FINISH) && (first_call))
23
- {
24
- // MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file.
25
- decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
26
- in_bytes = pStream->avail_in; out_bytes = pStream->avail_out;
27
- status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags);
28
- pState->m_last_status = status;
29
- pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes;
30
- pStream->adler = tinfl_get_adler32(&pState->m_decomp);
31
- pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes; pStream->total_out += (mz_uint)out_bytes;
32
-
33
- if (status < 0)
34
- return MZ_DATA_ERROR;
35
- else if (status != TINFL_STATUS_DONE)
36
- {
37
- pState->m_last_status = TINFL_STATUS_FAILED;
38
- return MZ_BUF_ERROR;
39
- }
40
- return MZ_STREAM_END;
41
- }
42
- // flush != MZ_FINISH then we must assume there's more input.
43
- if (flush != MZ_FINISH) decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;
44
-
45
- if (pState->m_dict_avail)
46
- {
47
- n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
48
- memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
49
- pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n;
50
- pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
51
- return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
52
- }
53
-
54
- for ( ; ; )
55
- {
56
- in_bytes = pStream->avail_in;
57
- out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs;
58
-
59
- status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags);
60
- pState->m_last_status = status;
61
-
62
- pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes;
63
- pStream->total_in += (mz_uint)in_bytes; pStream->adler = tinfl_get_adler32(&pState->m_decomp);
64
-
65
- pState->m_dict_avail = (mz_uint)out_bytes;
66
-
67
- n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
68
- memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
69
- pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n;
70
- pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
71
-
72
- if (status < 0)
73
- return MZ_DATA_ERROR; // Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well).
74
- else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
75
- return MZ_BUF_ERROR; // Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH.
76
- else if (flush == MZ_FINISH)
77
- {
78
- // The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH.
79
- if (status == TINFL_STATUS_DONE)
80
- return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END;
81
- // status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong.
82
- else if (!pStream->avail_out)
83
- return MZ_BUF_ERROR;
84
- }
85
- else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail))
86
- break;
87
- }
88
-
89
- return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
90
-}
91
-
92
-int mz_inflateEnd(mz_streamp pStream)
93
-{
94
- if (!pStream)
95
- return MZ_STREAM_ERROR;
96
- if (pStream->state)
97
- {
98
- pStream->zfree(pStream->opaque, pStream->state);
99
- pStream->state = NULL;
100
- }
101
- return MZ_OK;
102
-}
103
-
104
-int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
105
-{
106
- mz_stream stream;
107
- int status;
108
- memset(&stream, 0, sizeof(stream));
109
-
110
- // In case mz_ulong is 64-bits (argh I hate longs).
111
- if ((source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR;
112
-
113
- stream.next_in = pSource;
114
- stream.avail_in = (mz_uint32)source_len;
115
- stream.next_out = pDest;
116
- stream.avail_out = (mz_uint32)*pDest_len;
117
-
118
- status = mz_inflateInit(&stream);
119
- if (status != MZ_OK)
120
- return status;
121
-
122
- status = mz_inflate(&stream, MZ_FINISH);
123
- if (status != MZ_STREAM_END)
124
- {
125
- mz_inflateEnd(&stream);
126
- return ((status == MZ_BUF_ERROR) && (!stream.avail_in)) ? MZ_DATA_ERROR : status;
127
- }
128
- *pDest_len = stream.total_out;
129
-
130
- return mz_inflateEnd(&stream);
131
-}
132
-
133
-const char *mz_error(int err)
134
-{
135
- static const struct { int m_err; const char *m_pDesc; } s_error_descs[] =
136
- {
137
- { MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" },
138
- { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" }
139
- };
140
- mz_uint i; for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i) if (s_error_descs[i].m_err == err) return s_error_descs[i].m_pDesc;
141
- return NULL;
142
-}
143
-
144
-#endif //MINIZ_NO_ZLIB_APIS
145
-
146
-// ------------------- Low-level Decompression (completely independent from all compression API's)
147
-
148
-#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
149
-#define TINFL_MEMSET(p, c, l) memset(p, c, l)
150
-
151
-#define TINFL_CR_BEGIN switch(r->m_state) { case 0:
152
-#define TINFL_CR_RETURN(state_index, result) do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END
153
-#define TINFL_CR_RETURN_FOREVER(state_index, result) do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END
154
-#define TINFL_CR_FINISH }
155
-
156
-// TODO: If the caller has indicated that there's no more input, and we attempt to read beyond the input buf, then something is wrong with the input because the inflator never
157
-// reads ahead more than it needs to. Currently TINFL_GET_BYTE() pads the end of the stream with 0's in this scenario.
158
-#define TINFL_GET_BYTE(state_index, c) do { \
159
- if (pIn_buf_cur >= pIn_buf_end) { \
160
- for ( ; ; ) { \
161
- if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \
162
- TINFL_CR_RETURN(state_index, TINFL_STATUS_NEEDS_MORE_INPUT); \
163
- if (pIn_buf_cur < pIn_buf_end) { \
164
- c = *pIn_buf_cur++; \
165
- break; \
166
- } \
167
- } else { \
168
- c = 0; \
169
- break; \
170
- } \
171
- } \
172
- } else c = *pIn_buf_cur++; } MZ_MACRO_END
173
-
174
-#define TINFL_NEED_BITS(state_index, n) do { mz_uint c; TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; } while (num_bits < (mz_uint)(n))
175
-#define TINFL_SKIP_BITS(state_index, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
176
-#define TINFL_GET_BITS(state_index, b, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } b = bit_buf & ((1 << (n)) - 1); bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
177
-
178
-// TINFL_HUFF_BITBUF_FILL() is only used rarely, when the number of bytes remaining in the input buffer falls below 2.
179
-// It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a
180
-// Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the
181
-// bit buffer contains >=15 bits (deflate's max. Huffman code size).
182
-#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \
183
- do { \
184
- temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
185
- if (temp >= 0) { \
186
- code_len = temp >> 9; \
187
- if ((code_len) && (num_bits >= code_len)) \
188
- break; \
189
- } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \
190
- code_len = TINFL_FAST_LOOKUP_BITS; \
191
- do { \
192
- temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
193
- } while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \
194
- } TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \
195
- } while (num_bits < 15);
196
-
197
-// TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read
198
-// beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully
199
-// decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32.
200
-// The slow path is only executed at the very end of the input buffer.
201
-#define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \
202
- int temp; mz_uint code_len, c; \
203
- if (num_bits < 15) { \
204
- if ((pIn_buf_end - pIn_buf_cur) < 2) { \
205
- TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
206
- } else { \
207
- bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \
208
- } \
209
- } \
210
- if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
211
- code_len = temp >> 9, temp &= 511; \
212
- else { \
213
- code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \
214
- } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END
215
-
216
-tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags)
217
-{
218
- static const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 };
219
- static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
220
- static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
221
- static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
222
- static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
223
- static const int s_min_table_sizes[3] = { 257, 1, 4 };
224
-
225
- tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf;
226
- const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
227
- mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
228
- size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
229
-
230
- // Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter).
231
- if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; }
232
-
233
- num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start;
234
- TINFL_CR_BEGIN
235
-
236
- bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1;
237
- if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
238
- {
239
- TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1);
240
- counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
241
- if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
242
- if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); }
243
- }
244
-
245
- do
246
- {
247
- TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1;
248
- if (r->m_type == 0)
249
- {
250
- TINFL_SKIP_BITS(5, num_bits & 7);
251
- for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); }
252
- if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); }
253
- while ((counter) && (num_bits))
254
- {
255
- TINFL_GET_BITS(51, dist, 8);
256
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); }
257
- *pOut_buf_cur++ = (mz_uint8)dist;
258
- counter--;
259
- }
260
- while (counter)
261
- {
262
- size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); }
263
- while (pIn_buf_cur >= pIn_buf_end)
264
- {
265
- if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT)
266
- {
267
- TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT);
268
- }
269
- else
270
- {
271
- TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED);
272
- }
273
- }
274
- n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter);
275
- TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n;
276
- }
277
- }
278
- else if (r->m_type == 3)
279
- {
280
- TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
281
- }
282
- else
283
- {
284
- if (r->m_type == 1)
285
- {
286
- mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i;
287
- r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
288
- for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
289
- }
290
- else
291
- {
292
- for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
293
- MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
294
- r->m_table_sizes[2] = 19;
295
- }
296
- for ( ; (int)r->m_type >= 0; r->m_type--)
297
- {
298
- int tree_next, tree_cur; tinfl_huff_table *pTable;
299
- mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree);
300
- for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
301
- used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
302
- for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
303
- if ((65536 != total) && (used_syms > 1))
304
- {
305
- TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
306
- }
307
- for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
308
- {
309
- mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue;
310
- cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
311
- if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; }
312
- if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
313
- rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
314
- for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
315
- {
316
- tree_cur -= ((rev_code >>= 1) & 1);
317
- if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1];
318
- }
319
- tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
320
- }
321
- if (r->m_type == 2)
322
- {
323
- for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); )
324
- {
325
- mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; }
326
- if ((dist == 16) && (!counter))
327
- {
328
- TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED);
329
- }
330
- num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16];
331
- TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s;
332
- }
333
- if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
334
- {
335
- TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
336
- }
337
- TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
338
- }
339
- }
340
- for ( ; ; )
341
- {
342
- mz_uint8 *pSrc;
343
- for ( ; ; )
344
- {
345
- if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
346
- {
347
- TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
348
- if (counter >= 256)
349
- break;
350
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
351
- *pOut_buf_cur++ = (mz_uint8)counter;
352
- }
353
- else
354
- {
355
- int sym2; mz_uint code_len;
356
-#if TINFL_USE_64BIT_BITBUF
357
- if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; }
358
-#else
359
- if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
360
-#endif
361
- if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
362
- code_len = sym2 >> 9;
363
- else
364
- {
365
- code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
366
- }
367
- counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
368
- if (counter & 256)
369
- break;
370
-
371
-#if !TINFL_USE_64BIT_BITBUF
372
- if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
373
-#endif
374
- if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
375
- code_len = sym2 >> 9;
376
- else
377
- {
378
- code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
379
- }
380
- bit_buf >>= code_len; num_bits -= code_len;
381
-
382
- pOut_buf_cur[0] = (mz_uint8)counter;
383
- if (sym2 & 256)
384
- {
385
- pOut_buf_cur++;
386
- counter = sym2;
387
- break;
388
- }
389
- pOut_buf_cur[1] = (mz_uint8)sym2;
390
- pOut_buf_cur += 2;
391
- }
392
- }
393
- if ((counter &= 511) == 256) break;
394
-
395
- num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
396
- if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
397
-
398
- TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
399
- num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
400
- if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
401
-
402
- dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
403
- if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
404
- {
405
- TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
406
- }
407
-
408
- pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
409
-
410
- if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
411
- {
412
- while (counter--)
413
- {
414
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); }
415
- *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
416
- }
417
- continue;
418
- }
419
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
420
- else if ((counter >= 9) && (counter <= dist))
421
- {
422
- const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
423
- do
424
- {
425
- ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
426
- ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
427
- pOut_buf_cur += 8;
428
- } while ((pSrc += 8) < pSrc_end);
429
- if ((counter &= 7) < 3)
430
- {
431
- if (counter)
432
- {
433
- pOut_buf_cur[0] = pSrc[0];
434
- if (counter > 1)
435
- pOut_buf_cur[1] = pSrc[1];
436
- pOut_buf_cur += counter;
437
- }
438
- continue;
439
- }
440
- }
441
-#endif
442
- do
443
- {
444
- pOut_buf_cur[0] = pSrc[0];
445
- pOut_buf_cur[1] = pSrc[1];
446
- pOut_buf_cur[2] = pSrc[2];
447
- pOut_buf_cur += 3; pSrc += 3;
448
- } while ((int)(counter -= 3) > 2);
449
- if ((int)counter > 0)
450
- {
451
- pOut_buf_cur[0] = pSrc[0];
452
- if ((int)counter > 1)
453
- pOut_buf_cur[1] = pSrc[1];
454
- pOut_buf_cur += counter;
455
- }
456
- }
457
- }
458
- } while (!(r->m_final & 1));
459
- if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
460
- {
461
- TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; }
462
- }
463
- TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE);
464
- TINFL_CR_FINISH
465
-
466
-common_exit:
467
- r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start;
468
- *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
469
- if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
470
- {
471
- const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size;
472
- mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552;
473
- while (buf_len)
474
- {
475
- for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
476
- {
477
- s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
478
- s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
479
- }
480
- for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
481
- s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
482
- }
483
- r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH;
484
- }
485
- return status;
486
-}
487
-
488
-// Higher level helper functions.
489
-void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
490
-{
491
- tinfl_decompressor decomp; void *pBuf = NULL, *pNew_buf; size_t src_buf_ofs = 0, out_buf_capacity = 0;
492
- *pOut_len = 0;
493
- tinfl_init(&decomp);
494
- for ( ; ; )
495
- {
496
- size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
497
- tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size,
498
- (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
499
- if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
500
- {
501
- MZ_FREE(pBuf); *pOut_len = 0; return NULL;
502
- }
503
- src_buf_ofs += src_buf_size;
504
- *pOut_len += dst_buf_size;
505
- if (status == TINFL_STATUS_DONE) break;
506
- new_out_buf_capacity = out_buf_capacit7,278,278,278,278,278,278,27880,
507
- 281,2 w deflate (non-zlib) = -1,,277,278,278,278DONE = 0,,277,278,278,278 byte in order t = 1,,277,278,278,278HAS_MORE_OUTPUT = 215,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,
508
- 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
509
- 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
510
- 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
511
- 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
512
- 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
513
- 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17 };
514
-
515
-static const mz_uint8 s_tdefl_small_dist_extra[512] = {
516
- 0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
517
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
518
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
519
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
520
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
521
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
522
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
523
- 7,7,7,7,7,7,7,7 };
524
-
525
-static const mz_uint8 s_tdefl_large_dist_sym[128] = {
526
- 0,0,18,19,20,20,21,21,22,22,22,22,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,
527
- 26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
528
- 28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 };
529
-
530
-static const mz_uint8 s_tdefl_large_dist_extra[128] = {
531
- 0,0,8,8,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
532
- 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
533
- 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13 };
534
-
535
-// Radix sorts tdefl_sym_freq[] array by 16-bit key m_key. Returns ptr to sorted values.
536
-typedef struct { mz_uint16 m_key, m_sym_index; } tdefl_sym_freq;
537
-static tdefl_sym_freq* tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq* pSyms0, tdefl_sym_freq* pSyms1)
538
-{
539
- mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; tdefl_sym_freq* pCur_syms = pSyms0, *pNew_syms = pSyms1; MZ_CLEAR_OBJ(hist);
540
- for (i = 0; i < num_syms; i++) { mz_uint freq = pSyms0[i].m_key; hist[freq & 0xFF]++; hist[256 + ((freq >> 8) & 0xFF)]++; }
541
- while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--;
542
- for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
543
- {
544
- const mz_uint32* pHist = &hist[pass << 8];
545
- mz_uint offsets[256], cur_ofs = 0;
546
- for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; }
547
- for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
548
- { tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; }
549
- }
550
- return pCur_syms;
551
-}
552
-
553
-// tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, [email protected], Jyrki Katajainen, [email protected], November 1996.
554
-static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
555
-{
556
- int root, leaf, next, avbl, used, dpth;
557
- if (n==0) return; else if (n==1) { A[0].m_key = 1; return; }
558
- A[0].m_key += A[1].m_key; root = 0; leaf = 2;
559
- for (next=1; next < n-1; next++)
560
- {
561
- if (leaf>=n || A[root].m_key<A[leaf].m_key) { A[next].m_key = A[root].m_key; A[root++].m_key = (mz_uint16)next; } else A[next].m_key = A[leaf++].m_key;
562
- if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key); A[root++].m_key = (mz_uint16)next; } else A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
563
- }
564
- A[n-2].m_key = 0; for (next=n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1;
565
- avbl = 1; used = dpth = 0; root = n-2; next = n-1;
566
- while (avbl>0)
567
- {
568
- while (root>=0 && (int)A[root].m_key==dpth) { used++; root--; }
569
- while (avbl>used) { A[next--].m_key = (mz_uint16)(dpth); avbl--; }
570
- avbl = 2*used; dpth++; used = 0;
571
- }
572
-}
573
-
574
-// Limits canonical Huffman code table's max um_syms == hist[(total_passes - 1) * 256])) total_passes--;
575
- for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
576
- {
577
- const mz_uint32* pHist = &hist[pass << 8];
578
- mz_uint offsets[256], cur_ofs = 0;
579
- for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; }
580
- for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
581
- { tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; }
582
- }
583
- return pCur_syms;
584
-}
585
-
586
-// tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, [email protected], Jyrki Katajainen, [email protected], November 1996.
587
-static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
588
-{
589
- int root, leaf, next, avbl, used, dpth;
590
- if (n==0) return; else if (n==1) { A[0].m_key = 1; return; }
591
- A[0].m_key += A[1].m_key; root = 0; leaf = 2;
592
- for (next=1; next < n-1; next++)
593
- {
594
- if (leaf>=n || A[root].m_key<A[leaf].m_key) { A[next].m_key = A[root].m_key; A[root++].m_key = (mz_uint16)next; } else A[next].m_key = A[leaf++].m_key;
595
- if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key); A[root++].m_key = (mz_uint16)next; } else A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
596
- }
597
- A[n-2].m_key = 0; for (next=n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1;
598
- avbl = 1; used = dpth = 0; root = n-2; next = n-1;
599
- while (avbl>0)
600
- {
601
- while (root>=0 && (int)A[root].m_key==dpth) { used++; root--; }
602
- while (avbl>used) { A[next--].m_key = (mz_uint16)(dpth); avbl--; }
603
- avbl = 2*used; dpth++; used = 0;
604
- }
605
-}
606
-
607
-// Limits canonical Huffman code table's max code size.
608
-enum { TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32 };
609
-static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size)
610
-{
611
- int i; mz_uint32 total = 0; if (code_list_len <= 1) return;
612
- for (i = max_code_size + 1; i <= TDEFL_MAX_SUPPORTED_HUFF_CODESIZE; i++) pNum_codes[max_code_size] += pNum_codes[i];
613
- for (i = max_code_size; i > 0; i--) total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i));
614
- while (total != (1UL << max_code_size))
615
- {
616
- pNum_codes[max_code_size]--;
617
- for (i = max_code_size - 1; i > 0; i--) if (pNum_codes[i]) { pNum_codes[i]--; pNum_codes[i + 1] += 2; break; }
618
- total--;
619
- }
620
-}
621
-
622
-static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table)
623
-{
624
- int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; MZ_CLEAR_OBJ(num_codes);
625
- if (static_table)
626
- {
627
- for (i = 0; i < table_len; i++) num_codes[d->m_huff_code_sizes[table_num][i]]++;
628
- }
629
- else
630
- {
631
- tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms;
632
- int num_used_syms = 0;
633
- const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0];
634
- for (i = 0; i < table_len; i++) if (pSym_count[i]) { syms0[num_used_syms].m_key = (mz_uint16)pSym_count[i]; syms0[num_used_syms++].m_sym_index = (mz_uint16)i; }
635
-
636
- pSyms = tdefl_radix_sort_syms(num_used_syms, syms0, syms1); tdefl_calculate_minimum_redundancy(pSyms, num_used_syms);
637
-
638
- for (i = 0; i < num_used_syms; i++) num_codes[pSyms[i].m_key]++;
639
-
640
- tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit);
641
-
642
- MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); MZ_CLEAR_OBJ(d->m_huff_codes[table_num]);
643
- for (i = 1, j = num_used_syms; i <= code_size_limit; i++)
644
- for (l = num_codes[i]; l > 0; l--) d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i);
645
- }
646
-
647
- next_code[1] = 0; for (j = 0, i = 2; i <= code_size_limit; i++) next_code[i] = j = ((j + num_codes[i - 1]) << 1);
648
-
649
- for (i = 0; i < table_len; i++)
650
- {
651
- mz_uint rev_code = 0, code, code_size; if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0) continue;
652
- code = next_code[code_size]++; for (l = code_size; l > 0; l--, code >>= 1) rev_code = (rev_code << 1) | (code & 1);
653
- d->m_huff_codes[table_num][i] = (mz_uint16)rev_code;
654
- }
655
-}
656
-
657
-#define TDEFL_PUT_BITS(b, l) do { \
658
- mz_uint bits = b; mz_uint len = l; MZ_ASSERT(bits <= ((1U << len) - 1U)); \
659
- d->m_bit_buffer |= (bits << d->m_bits_in); d->m_bits_in += len; \
660
- while (d->m_bits_in >= 8) { \
661
- if (d->m_pOutput_buf < d->m_pOutput_buf_end) \
662
- *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \
663
- d->m_bit_buffer >>= 8; \
664
- d->m_bits_in -= 8; \
665
- } \
666
-} MZ_MACRO_END
667
-
668
-#define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \
669
- if (rle_repeat_count < 3) { \
670
- d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \
671
- while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \
672
- } else { \
673
- d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \
674
-} rle_repeat_count = 0; } }
675
-
676
-#define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \
677
- if (rle_z_count < 3) { \
678
- d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \
679
- } else if (rle_z_count <= 10) { \
680
- d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \
681
- } else { \
682
- d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \
683
-} rle_z_count = 0; } }
684
-
685
-static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
686
-
687
-static void tdefl_start_dynamic_block(tdefl_compressor *d)
688
-{
689
- int num_lit_codes, num_dist_codes, num_bit_lengths; mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_indITS(num_bit_lengths - 4, 4);
690
- for (i = 0; (int)i < num_bit_lengths; i++) TDEFL_PUT_BITS(d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[i]], 3);
691
-
692
- for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes; )
693
- {
694
- mz_uint code = packed_code_sizes[packed_code_sizes_index++]; MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2);
695
- TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]);
696
- if (code >= 16) TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++], "\02\03\07"[code - 16]);
697
- }
698
-}
699
-
700
-static void tdefl_start_static_block(tdefl_compressor *d)
701
-{
702
- mz_uint i;
703
- mz_uint8 *p = &d->m_huff_code_sizes[0][0];
704
-
705
- for (i = 0; i <= 143; ++i) *p++ = 8;
706
- for ( ; i <= 255; ++i) *p++ = 9;
707
- for ( ; i <= 279; ++i) *p++ = 7;
708
- for ( ; i <= 287; ++i) *p++ = 8;
709
-
710
- memset(d->m_huff_code_sizes[1], 5, 32);
711
-
712
- tdefl_optimize_huffman_table(d, 0, 288, 15, MZ_TRUE);
713
- tdefl_optimize_huffman_table(d, 1, 32, 15, MZ_TRUE);
714
-
715
- TDEFL_PUT_BITS(1, 2);
716
-}
717
-
718
-static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
719
-
720
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
721
-static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
722
-{
723
- mz_uint flags;
724
- mz_uint8 *pLZ_codes;
725
- mz_uint8 *pOutput_buf = d->m_pOutput_buf;
726
- mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf;
727
- mz_uint64 bit_buffer = d->m_bit_buffer;
728
- mz_uint bits_in = d->m_bits_in;
729
-
730
-#define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); }
731
-
732
- flags = 1;
733
- for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1)
734
- {
735
- if (flags == 1)
736
- flags = *pLZ_codes++ | 0x100;
737
-
738
- if (flags & 1)
739
- {
740
- mz_uint s0, s1, n0, n1, sym, num_extra_bits;
741
- mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3;
742
-
743
- MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
744
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
745
- TDEFL_PUT_BITS_FAST(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
746
-
747
- // This sequence coaxes MSVC into using cmov's vs. jmp's.
748
- s0 = s_tdefl_small_dist_sym[match_dist & 511];
749
- n0 = s_tdefl_small_dist_extra[match_dist & 511];
750
- s1 = s_tdefl_large_dist_sym[match_dist >> 8];
751
- n1 = s_tdefl_large_dist_extra[match_dist >> 8];
752
- sym = (match_dist < 512) ? s0 : s1;
753
- num_extra_bits = (match_dist < 512) ? n0 : n1;
754
-
755
- MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
756
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
757
- TDEFL_PUT_BITS_FAST(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
758
- }
759
- else
760
- {
761
- mz_uint lit = *pLZ_codes++;
762
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
763
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
764
-
765
- if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
766
- {
767
- flags >>= 1;
768
- lit = *pLZ_codes++;
769
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
770
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
771
-
772
- if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
773
- {
774
- flags >>= 1;
775
- lit = *pLZ_codes++;
776
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
777
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
778
- }
779
- }
780
- }
781
-
782
- if (pOutput_buf >= d->m_pOutput_buf_end)
783
- return MZ_FALSE;
784
-
785
- *(mz_uint64*)pOutput_buf = bit_buffer;
786
- pOutput_buf += (bits_in >> 3);
787
- bit_buffer >>= (bits_in & ~7);
788
- bits_in &= 7;
789
- }
790
-
791
-#undef TDEFL_PUT_BITS_FAST
792
-
793
- d->m_pOutput_buf = pOutput_buf;
794
- d->m_bits_in = 0;
795
- d->m_bit_buffer = 0;
796
-
797
- while (bits_in)
798
- {
799
- mz_uint32 n = MZ_MIN(bits_in, 16);
800
- TDEFL_PUT_BITS((mz_uint)bit_buffer & mz_bitmasks[n], n);
801
- bit_buffer >>= n;
802
- bits_in -= n;
803
- }
804
-
805
- TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
806
-
807
- return (d->m_pOutput_buf < d->m_pOutput_buf_end);
808
-}
809
-#else
810
-static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
811
-{
812
- mz_uint flags;
813
- mz_uint8 *pLZ_codes;
814
-
815
- flags = 1;
816
- for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1)
817
- {
818
- if (flags == 1)
819
- flags = *pLZ_codes++ | 0x100;
820
- if (flags & 1)
821
- {
822
- mz_uint sym, num_extra_bits;
823
- mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); pLZ_codes += 3;
824
-
825
- MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
826
- TDEFL_PUT_BITS(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
827
- TDEFL_PUT_BITS(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
828
-
829
- if (match_dist < 512)
830
- {
831
- sym = s_tdefl_small_dist_sym[match_dist]; num_extra_bits = s_tdefl_small_dist_extra[match_dist];
832
- }
833
- else
834
- {
835
- sym = s_tdefl_large_dist_sym[match_dist >> 8]; num_extra_bits = s_tdefl_large_dist_extra[match_dist >> 8];
836
- }
837
- MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
838
- TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
839
- TDEFL_PUT_BITS(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
840
- }
841
- else
842
- {
843
- mz_uint lit = *pLZ_codes++;
844
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
845
- TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
846
- }
847
- }
848
-
849
- TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
850
-
851
- return (d->m_pOutput_buf < d->m_pOutput_buf_end);
852
-}
853
-#endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
854
-
855
-static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block)
856
-{
857
- if (static_block)
858
- tdefl_start_static_block(d);
859
- else
860
- tdefl_start_dynamic_block(d);
861
- return tdefl_compress_lz_codes(d);
862
-}
863
-
864
-static int tdefl_flush_block(tdefl_compressor *d, int flush)
865
-{
866
- mz_uint saved_bit_buf, saved_bits_in;
867
- mz_uint8 *pSaved_output_buf;
868
- mz_bool comp_block_succeeded = MZ_FALSE;
869
- int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
870
- mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf;
871
-
872
- d->m_pOutput_buf = pOutput_buf_start;
873
- d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;
874
-
875
- MZ_ASSERT(!d->m_output_flush_remaining);
876
- d->m_output_flush_ofs = 0;
877
- d->m_output_flush_remaining = 0;
878
-
879
- *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
880
- d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
881
-
882
- if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index))
883
- {
884
- TDEFL_PUT_BITS(0x78, 8); TDEFL_PUT_BITS(0x01, 8);
885
- }
886
-
887
- TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1);
888
-
889
- pSaved_output_buf = d->m_pOutput_buf; saved_bit_buf = d->m_bit_buffer; saved_bits_in = d->m_bits_in;
890
-
891
- if (!use_raw_block)
892
- comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48));
893
-
894
- // If the block gets expanded, forget the current contents of the output buffer and send a raw block instead.
895
- if ( ((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
896
- ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size) )
897
- {
898
- mz_uint i; d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
899
- TDEFL_PUT_BITS(0, 2);
900
- if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); }
901
- for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF)
902
- {
903
- TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16);
904
- }
905
- for (i = 0; i < d->m_total_lz_bytes; ++i)
906
- {
907
- TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8);
908
- }
909
- }
910
- // Check for the extremely unlikely (if not impossible) case of the compressed block not fitting into the output buffer when using dynamic codes.
911
- else if (!comp_block_succeeded)
912
- {
913
- d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
914
- tdefl_compress_block(d, MZ_TRUE);
915
- }
916
-
917
- if (flush)
918
- {
919
- if (flush == TDEFL_FINISH)
920
- {
921
- if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); }
922
- if (d->m_flags & TDEFL_WRITE_ZLIB_HEADER) { mz_uint i, a = d->m_adler32; for (i = 0; i < 4; i++) { TDEFL_PUT_BITS((a >> 24) & 0xFF, 8); a <<= 8; } }
923
- }
924
- else
925
- {
926
- mz_uint i, z = 0; TDEFL_PUT_BITS(0, 3); if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); } for (i = 2; i; --i, z ^= 0xFFFF) { TDEFL_PUT_BITS(z & 0xFFFF, 16); }
927
- }
928
- }
929
-
930
- MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end);
931
-
932
- memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
933
- memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
934
-
935
- d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8; d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes; d->m_total_lz_bytes = 0; d->m_block_index++;
936
-
937
- if ((n = (int)(d->m_pOutput_buf - pOutput_buf_start)) != 0)
938
- {
939
- if (d->m_pPut_buf_func)
940
- {
941
- *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf;
942
- if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
943
- return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED);
944
- }
945
- else if (pOutput_buf_start == d->m_output_buf)
946
- {
947
- int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
948
- memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
949
- d->m_out_buf_ofs += bytes_to_copy;
950
- if ((n -= bytes_to_copy) != 0)
951
- {
952
- d->m_output_flush_ofs = bytes_to_copy;
953
- d->m_output_flush_remaining = n;
954
- }
955
- }
956
- else
957
- {
958
- d->m_out_buf_ofs += n;
959
- }
960
- }
961
-
962
- return d->m_output_flush_remaining;
963
-}
964
-
965
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
966
-#define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p)
967
-static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
968
-{
969
- mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
970
- mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
971
- const mz_uint16 *s = (const mz_uint16*)(d->m_dict + pos), *p, *q;
972
- mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD(s);
973
- MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return;
974
- for ( ; ; )
975
- {
976
- for ( ; ; )
977
- {
978
- if (--num_probes_left == 0) return;
979
- #define TDEFL_PROBE \
980
- next_probe_pos = d->m_next[probe_pos]; \
981
- if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
982
- probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
983
- if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break;
984
- TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE;
985
- }
986
- if (!dist) break; q = (const mz_uint16*)(d->m_dict + probe_pos); if (TDEFL_READ_UNALIGNED_WORD(q) != s01) continue; p = s; probe_len = 32;
987
- do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
988
- (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) );
989
- if (!probe_len)
990
- {
991
- *pMatch_dist = dist; *pMatch_len = MZ_MIN(max_match_len, TDEFL_MAX_MATCH_LEN); break;
992
- }
993
- else if ((probe_len = ((mz_uint)(p - s) * 2) + (mz_uint)(*(const mz_uint8*)p == *(const mz_uint8*)q)) > match_len)
994
- {
995
- *pMatch_dist = dist; if ((*pMatch_len = match_len = MZ_MIN(max_match_len, probe_len)) == max_match_len) break;
996
- c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]);
997
- }
998
- }
999
-}
1000
-#else
1001
-static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
1002
-{
1003
- mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
1004
- mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
1005
- const mz_uint8 *s = d->m_dict + pos, *p, *q;
1006
- mz_uint8 c0 = d->m_dict[pos + match_len], c1 = d->m_dict[pos + match_len - 1];
1007
- MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return;
1008
- for ( ; ; )
1009
- {
1010
- for ( ; ; )
1011
- {
1012
- if (--num_probes_left == 0) return;
1013
- #define TDEFL_PROBE \
1014
- next_probe_pos = d->m_next[probe_pos]; \
1015
- if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
1016
- probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
1017
- if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) break;
1018
- TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE;
1019
- }
1020
- if (!dist) break; p = s; q = d->m_dict + probe_pos; for (probe_len = 0; probe_len < max_match_len; probe_len++) if (*p++ != *q++) break;
1021
- if (probe_len > match_len)
1022
- {
1023
- *pMatch_dist = dist; if ((*pMatch_len = match_len = probe_len) == max_match_len) return;
1024
- c0 = d->m_dict[pos + match_len]; c1 = d->m_dict[pos + match_len - 1];
1025
- }
1026
- }
1027
-}
1028
-#endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
1029
-
1030
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
1031
-static mz_bool tdefl_compress_fast(tdefl_compressor *d)
1032
-{
1033
- // Faster, minimally featured LZRW1-style match+parse loop with better register utilization. Intended for applications where raw throughput is valued more highly than ratio.
1034
- mz_uint lookahead_pos = d->m_lookahead_pos, lookahead_size = d->m_lookahead_size, dict_size = d->m_dict_size, total_lz_bytes = d->m_total_lz_bytes, num_flags_left = d->m_num_flags_left;
1035
- mz_uint8 *pLZ_code_buf = d->m_pLZ_code_buf, *pLZ_flags = d->m_pLZ_flags;
1036
- mz_uint cur_pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK;
1037
-
1038
- while ((d->m_src_buf_left) || ((d->m_flush) && (lookahead_size)))
1039
- {
1040
- const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096;
1041
- mz_uint dst_pos = (lookahead_pos + lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK;
1042
- mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(d->m_src_buf_left, TDEFL_COMP_FAST_LOOKAHEAD_SIZE - lookahead_size);
1043
- d->m_src_buf_left -= num_bytes_to_process;
1044
- lookahead_size += num_bytes_to_process;
1045
-
1046
- while (num_bytes_to_process)
1047
- {
1048
- mz_uint32 n = MZ_MIN(TDEFL_LZ_DICT_SIZE - dst_pos, num_bytes_to_process);
1049
- memcpy(d->m_dict + dst_pos, d->m_pSrc, n);
1050
- if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
1051
- memcpy(d->m_dict + TDEFL_LZ_DICT_SIZE + dst_pos, d->m_pSrc, MZ_MIN(n, (TDEFL_MAX_MATCH_LEN - 1) - dst_pos));
1052
- d->m_pSrc += n;
1053
- dst_pos = (dst_pos + n) & TDEFL_LZ_DICT_SIZE_MASK;
1054
- num_bytes_to_process -= n;
1055
- }
1056
-
1057
- dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - lookahead_size, dict_size);
1058
- if ((!d->m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE)) break;
1059
-
1060
- while (lookahead_size >= 4)
1061
- {
1062
- mz_uint cur_match_dist, cur_match_len = 1;
1063
- mz_uint8 *pCur_dict = d->m_dict + cur_pos;
1064
- mz_uint first_trigram = (*(const mz_uint32 *)pCur_dict) & 0xFFFFFF;
1065
- mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK;
1066
- mz_uint probe_pos = d->m_hash[hash];
1067
- d->m_hash[hash] = (mz_uint16)lookahead_pos;
1068
-
1069
- if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((*(const mz_uint32 *)(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram))
1070
- {
1071
- const mz_uint16 *p = (const mz_uint16 *)pCur_dict;
1072
- const mz_uint16 *q = (const mz_uint16 *)(d->m_dict + probe_pos);
1073
- mz_uint32 probe_len = 32;
1074
- do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(// TODO: Ifhe raw deflate data (problem dithere's no more input, and we attempt to read beyond the input buf,
1075
- {
1076
- *pMatch_dis with the input because_capacity = 128;ver
1077
-// reads ahead more than it needs to. Currently TINFL_GET_BYTE() pads
1078
-}
1079
-
1080
-int mz_deflastream with 0's in this scenario.GNED_WORD(++p) == TDEFifD_UNALIGNEDfor ( ; ; ) { \
1081
- r" }, { MZ_PARAM_ERROR, "parametHAS_MORE_INPUT) { \
1082
-) << num_bits); num_bitsstate_index, memcpy(d->m_dict + dst_pos, \
1083
- if (pIn_buf_cur < pIn_buf_end) { \
1084
- c = *pIn_buf_cur++; \, { MZ_BUF_ERROR, \
1085
- n} \
1086
- m.avail_out = (mz_uint c = 0; \
1087
- break; \) );
1088
- cur_match_le }, { MZ_PARAM_ERROR, "parametHAS_MORE_INPUTr1);
1089
- counter = (((r->mTINFL_CR_RETURN(38, memcpy(d->m_dict + dst_pos, if (decomp_flags *)(d->m_dict + probe_po4 particularly important on raTPUT); }
1090
- while (pI expects the decompressor to never read
1091
-// beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully
1092
-// decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32.
1093
-// The slow path is only executed at the very end of the input buffer.
1094
-#define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \
1095
- int temp; mz_uint code_len, c; \
1096
- if (num_bits < 15) { \
1097
- if ((pIn_buf_end - pIn_buf_cur) < 2) { \
1098
- TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
1099
- } else { \
1100
- bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \
1101
- } \
1102
- } \
1103
- if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
1104
- code_len = temp >> 9, temp &= 511; \
1105
- else { \
1106
- code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \
1107
- } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END
1108
-
1109
-tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags)
1110
-{
1111
- static const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 };
1112
- static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
1113
- static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
1114
- static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
1115
- static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
1116
- static const int s_min_table_sizes[3] = { 257, 1, 4 };
1117
-
1118
- tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf;
1119
- const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
1120
- mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
1121
- size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
1122
-
1123
- // Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter).
1124
- if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; }
1125
-
1126
- num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start;
1127
- TINFL_CR_BEGIN
1128
-
1129
- bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1;
1130
- if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
1131
- {
1132
- TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1);
1133
- counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
1134
- if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
1135
- if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); }
1136
- }
1137
-
1138
- do
1139
- {
1140
- TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1;
1141
- if (r->m_type == 0)
1142
- {
1143
- TINFL_SKIP_BITS(5, num_bits & 7);
1144
- for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); }
1145
- if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); }
1146
- while ((counter) && (num_bits))
1147
- {
1148
- TINFL_GET_BITS(51, dist, 8);
1149
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); }
1150
- *pOut_buf_cur++ = (mz_uint8)dist;
1151
- counter--;
1152
- }
1153
- while (counter)
1154
- {
1155
- size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); }
1156
- while (pIn_buf_cur >= pIn_buf_end)
1157
- {
1158
- if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT)
1159
- {
1160
- TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT);
1161
- }
1162
- else
1163
- {
1164
- TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED);
1165
- }
1166
- }
1167
- n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter);
1168
- TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n;
1169
- }
1170
- }
1171
- else if (r->m_type == 3)
1172
- {
1173
- TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
1174
- }
1175
- else
1176
- {
1177
- if (r->m_type == 1)
1178
- {
1179
- mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i;
1180
- r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
1181
- for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
1182
- }
1183
- else
1184
- {
1185
- for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
1186
- MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
1187
- r->m_table_sizes[2] = 19;
1188
- }
1189
- for ( ; (int)r->m_type >= 0; r->m_type--)
1190
- {
1191
- int tree_next, tree_cur; tinfl_huff_table *pTable;
1192
- mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree);
1193
- for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
1194
- used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
1195
- for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
1196
- if ((65536 != total) && (used_syms > 1))
1197
- {
1198
- TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
1199
- }
1200
- for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
1201
- {
1202
- mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue;
1203
- cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
1204
- if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; }
1205
- if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
1206
- rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
1207
- for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
1208
- {
1209
- tree_cur -= ((rev_code >>= 1) & 1);
1210
- if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1];
1211
- }
1212
- tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
1213
- }
1214
- if (r->m_type == 2)
1215
- {
1216
- for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); )
1217
- {
1218
- mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; }
1219
- if ((dist == 16) && (!counter))
1220
- {
1221
- TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED);
1222
- }
1223
- num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16];
1224
- TINFL_MEMSET(r->m_len_codes + counter, (disr" }, { MZ_PARAM_ERROR, "parameter error" }
1225
- };
1226
- mz_uint i; forSKIP_BITS(32, num_bits & 7);result) do { for (pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
1227
- *pOut_buf_cur++ = (mz_uint8)counter;
1228
- }
1229
- else
1230
- z_uint code_len;
1231
-#if TINFL_USE_64BINFL_GET_BITS(18, s, n_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s;
1232
- }
1233
- if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
1234
- {
1235
- TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
1236
- }
1237
- TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
1238
- }
1239
- }
1240
- for ( ; ; )
1241
- {
1242
- mz_uint8 *pSrc;
1243
- for ( ; ; )
1244
- {
1245
- if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
1246
- {
1247
- TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
1248
- if (counter >= 256)
1249
- break;
1250
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
1251
- *pOut_buf_cur++ = (mz_uint8)counter;
1252
- }
1253
- else
1254
- {
1255
- int sym2; mz_uint code_len;
1256
-#if TINFL_USE_64BIT_BITBUF
1257
- if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; }
1258
-#else
1259
- if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
1260
-#endif
1261
- if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
1262
- code_len = sym2 >> 9;
1263
- else
1264
- {
1265
- code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
1266
- }
1267
- counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
1268
- if (counter & 256)
1269
- break;
1270
-
1271
-#if !TINFL_USE_64BIT_BITBUF
1272
- if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
1273
-#endif
1274
- if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
1275
- code_len = sym2 >> 9;
1276
- else
1277
- {
1278
- code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
1279
- }
1280
- bit_buf >>= code_len; num_bits -= code_len;
1281
-
1282
- pOut_buf_cur[0] = (mz_uint8)counter;
1283
- if (sym2 & 256)
1284
- {
1285
- pOut_buf_cur++;
1286
- counter = sym2;
1287
- break;
1288
- }
1289
- pOut_buf_cur[1] = (mz_uint8)sym2;
1290
- pOut_buf_cur += 2;
1291
- }
1292
- }
1293
- if ((counter &= 511) == 256) break;
1294
-
1295
- num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
1296
- if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
1297
-
1298
- TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
1299
- num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
1300
- if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
1301
-
1302
- dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
1303
- if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
1304
- {
1305
- TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
1306
- }
1307
-
1308
- pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
1309
-
1310
- if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
1311
- {
1312
- while (counter--)
1313
- {
1314
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); }
1315
- *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
1316
- }
1317
- continue;
1318
- }
1319
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
1320
- else if ((counter >= 9) && (counter <= dist))
1321
- {
1322
- const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
1323
- do
1324
- {
1325
- ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
1326
- ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
1327
- pOut_buf_cur += 8;
1328
- } while ((pSrc += 8) < pSrc_end);
1329
- if ((counter &= 7) < 3)
1330
- {
1331
- if (counter)
1332
- {
1333
- pOut_buf_cur[0] = pSrc[0];
1334
- if (counter > 1)
1335
- pOut_buf_cur[1] = pSrc[1];
1336
- pOut_buf_cur += counter;
1337
- }
1338
- continue;
1339
- }
1340
- }
1341
-#endif
1342
- do
1343
- {
1344
- pOut_buf_cur[0] = pSrc[0];
1345
- pOut_buf_cur[1] = pSrc[1];
1346
- pOut_buf_cur[2] = pSrc[2];
1347
- pOut_buf_cur += 3; pSrc += 3;
1348
- } while ((int)(counter -= 3) > 2);
1349
- if ((int)counter > 0)
1350
- {
1351
- pOut_buf_cur[0] = pSrc[0];
1352
- if ((int)counter > 1)
1353
- pOut_buf_cur[1] = pSrc[1];
1354
- pOut_buf_cur += counter;
1355
- }
1356
- }
1357
- }
1358
- } while (!(r->m_final & 1));
1359
- if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
1360
- {
1361
- TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; }
1362
- }
1363
- TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE);
1364
- TINFL_CR_FINISH
1365
-
1366
-common_exit:
1367
- r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start;
1368
- *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
1369
- if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
1370
- {
1371
- const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size;
1372
- mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552;
1373
- while (buf_len)
1374
- {
1375
- for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
1376
- {
1377
- s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
1378
- s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
1379
- }
1380
- for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
1381
- s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
1382
- }
1383
- r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH;
1384
- }
1385
- return status;
1386
-}
1387
-
1388
-// Higher level helper functions.
1389
-void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
1390
-{
1391
- tinfl_decompressor decomp; void *pBuf = NULL, *pNew_buf; size_t src_buf_ofs = 0, out_buf_capacity = 0;
1392
- *pOut_len = 0;
1393
- tinfl_init(&decomp);
1394
- for ( ; ; )
1395
- {
1396
- size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
1397
- tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size,
1398
- (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
1399
- if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
1400
- {
1401
- MZ_FREE(pBuf); *pOut_len = 0; return NULL;
1402
- }
1403
- src_buf_ofs += src_buf_size;
1404
- *pOut_len += dst_buf_size;
1405
- if (status == TINFL_STATUS_DONE) break;
1406
- new_out_buf_capacity = out_buf_capacity * 2; if (new_out_buf_capacity < 128) new_out_buf_capacity = 128;
1407
- pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity);
1408
- if (!pNew_buf)
1409
- {
1410
- MZ_FREE(pBuf); *pOut_len = 0; return NULL;
1411
- }
1412
- pBuf = pNew_buf; out_buf_capacity = new_out_buf_capacity;
1413
- }
1414
- return pBuf;
1415
-}
1416
-
1417
-size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
1418
-{
1419
- tinfl_decompressor decomp; tinfl_status status; tinfl_init(&decomp);
1420
- status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf, &src_buf_len, (mz_uint8*)pOut_buf, (mz_uint8*)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
1421
- return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len;
1422
-}
1423
-
1424
-int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
1425
-{
1426
- int result = 0;
1427
- tinfl_decompressor decomp;
1428
- mz_uint8 *pDict = (mz_uint8*)MZ_MALLOC(TINFL_LZ_DICT_SIZE); size_t in_buf_ofs = 0, dict_ofs = 0;
1429
- if (!pDict)
1430
- return TINFL_STATUS_FAILED;
1431
- tinfl_init(&decomp);
1432
- for ( ; ; )
1433
- {
1434
- size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
1435
- tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size,
1436
- (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
1437
- in_buf_ofs += in_buf_size;
1438
- if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user)))
1439
- break;
1440
- if (status != TINFL_STATUS_HAS_MORE_OUTPUT)
1441
- {
1442
- result = (status == TINFL_STATUS_DONE);
1443
- break;
1444
- }
1445
- dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1);
1446
- }
1447
- MZ_FREE(pDict);
1448
- *pIn_buf_size = in_buf_ofs;
1449
- return result;
1450
-}
1451
-
1452
-// ------------------- Low-level Compression (independent from all decompression API's)
1453
-
1454
-// Purposely making these tables static for faster init and thread safety.
1455
-static const mz_uint16 s_tdefl_len_sym[256] = {
1456
- 257,258,259,260,261,262,263,264,265,265,266,266,267,267,268,268,269,269,269,269,270,270,270,270,271,271,271,271,272,272,272,272,
1457
- 273,273,273,273,273,273,273,273,274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,276,
1458
- 277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
1459
- 279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,
1460
- 281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,
1461
- 282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,
1462
- 283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,
1463
- 284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,285 };
1464
-
1465
-static const mz_uint8 s_tdefl_len_extra[256] = {
1466
- 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
1467
- 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
1468
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1469
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0 };
1470
-
1471
-static const mz_uint8 s_tdefl_small_dist_sym[512] = {
1472
- 0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
1473
- 11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,
1474
- 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,
1475
- 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
1476
- 14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
1477
- 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,
1478
- 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1479
- 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1480
- 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1481
- 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1482
- 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1483
- 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17 };
1484
-
1485
-static const mz_uint8 s_tdefl_small_dist_extra[512] = {
1486
- 0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
1487
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1488
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1489
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1490
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1491
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1492
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1493
- 7,7,7,7,7,7,7,7 };
1494
-
1495
-static const mz_uint8 s_tdefl_large_dist_sym[128] = {
1496
- 0,0,18,19,20,20,21,21,22,22,22,22,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,
1497
- 26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
1498
- 28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 };
1499
-
1500
-static const mz_uint8 s_tdefl_large_dist_extra[128] = {
1501
- 0,0,8,8,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
1502
- 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
1503
- 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13 };
1504
-
1505
-// Radix sorts tdefl_sym_freq[] array by 16-bit key m_key. Returns ptr to sorted values.
1506
-typedef struct { mz_uint16 m_key, m_sym_index; } tdefl_sym_freq;
1507
-static tdefl_sym_freq* tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq* pSyms0, tdefl_sym_freq* pSyms1)
1508
-{
1509
- mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; tdefl_sym_freq* pCur_syms = pSyms0, *pNew_syms = pSyms1; MZ_CLEAR_OBJ(hist);
1510
- for (i = 0; i < num_syms; i++) { mz_uint freq = pSyms0[i].m_key; hist[freq & 0xFF]++; hist[256 + ((freq >> 8) & 0xFF)]++; }
1511
- while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--;
1512
- for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
1513
- {
1514
- const mz_uint32* pHist = &hist[pass << 8];
1515
- mz_uint offsets[256], cur_ofs = 0;
1516
- for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; }
1517
- for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
1518
- { tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; }
1519
- }
1520
- return pCur_syms;
1521
-}
1522
-
1523
-// tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, [email protected], Jyrki Katajainen, [email protected], November 1996.
1524
-static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
1525
-{
1526
- int root, leaf, next, avbl, used, dpth;
1527
- if (n==0) return; else if (n==1) { A[0].m_key = 1; return; }
1528
- A[0].m_key += A[1].m_key; root = 0; leaf = 2;
1529
- for (next=1; next < n-1; next++)
1530
- {
1531
- if (leaf>=n || A[root].m_key<A[leaf].m_key) { A[next].m_key = A[root].m_key; A[root++].m_key = (mz_uint16)next; } else A[next].m_key = A[leaf++].m_key;
1532
- if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key); A[root++].m_key = (mz_uint16)next; } else A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
1533
- }
1534
- A[n-2].m_key = 0; for (next=n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1;
1535
- avbl = 1; used = dpth = 0; root = n-2; next = n-1;
1536
- while (avbl>0)
1537
- {
1538
- while (root>=0 && (int)A[root].m_key==dpth) { used++; root--; }
1539
- while (avbl>used) { A[next--].m_key = (mz_uint16)(dpth); avbl--; }
1540
- avbl = 2*used; dpth++; used = 0;
1541
- }
1542
-}
1543
-
1544
-// Limits canonical Huffman code table's max code size.
1545
-enum { TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32 };
1546
-static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size)
1547
-{
1548
- int i; mz_uint32 total = 0; if (code_list_len <= 1) return;
1549
- for (i = max_code_size + 1; i <= TDEFL_MAX_SUPPORTED_HUFF_CODESIZE; i++) pNum_codes[max_code_size] += pNum_codes[i];
1550
- for (i = max_code_size; i > 0; i--) total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i));
1551
- while (total != (1UL << max_code_size))
1552
- {
1553
- pNum_codes[max_code_size]--;
1554
- for (i = max_code_size - 1; i > 0; i--) if (pNum_codes[i]) { pNum_codes[i]--; pNum_codes[i + 1] += 2; break; }
1555
- total--;
1556
- }
1557
-}
1558
-
1559
-static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table)
1560
-{
1561
- int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; MZ_CLEAR_OBJ(num_codes);
1562
- if (static_table)
1563
- {
1564
- for (i = 0; i < table_len; i++) num_codes[d->m_huff_code_sizes[table_num][i]]++;
1565
- }
1566
- else
1567
- {
1568
- tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms;
1569
- int num_used_syms = 0;
1570
- const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0];
1571
- for (i = 0; i < table_len; i++) if (pSym_count[i]) { syms0[num_used_syms].m_key = (mz_uint16)pSym_count[i]; syms0[num_used_syms++].m_sym_index = (mz_uint16)i; }
1572
-
1573
- pSyms = tdefl_radix_sort_syms(num_used_syms, syms0, syms1); tdefl_calculate_minimum_redundancy(pSyms, num_used_syms);
1574
-
1575
- for (i = 0; i < num_used_syms; i++) num_codes[pSyms[i].m_key]++;
1576
-
1577
- tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit);
1578
-
1579
- MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); MZ_CLEAR_OBJ(d->m_huff_codes[table_num]);
1580
- for (i = 1, j = num_used_syms; i <= code_size_limit; i++)
1581
- for (l = num_codes[i]; l > 0; l--) d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i);
1582
- }
1583
-
1584
- next_code[1] = 0; for (j = 0, i = 2; i <= code_size_limit; i++) next_code[i] = j = ((j + num_codes[i - 1]) << 1);
1585
-
1586
- for (i = 0; i < table_len; i++)
1587
- {
1588
- mz_uint rev_code = 0, code, code_size; if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0) continue;
1589
- code = next_code[code_size]++; for (l = code_size; l > 0; l--, code >>= 1) rev_code = (rev_code << 1) | (code & 1);
1590
- d->m_huff_codes[table_num][i] = (mz_uint16)rev_code;
1591
- }
1592
-}
1593
-
1594
-#define TDEFL_PUT_BITS(b, l) do { \
1595
- mz_uint bits = b; mz_uint len = l; MZ_ASSERT(bits <= ((1U << len) - 1U)); \
1596
- d->m_bit_buffer |= (bits << d->m_bits_in); d->m_bits_in += len; \
1597
- while (d->m_bits_in >= 8) { \
1598
- if (d->m_pOutput_buf < d->m_pOutput_buf_end) \
1599
- *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \
1600
- d->m_bit_buffer >>= 8; \
1601
- d->m_bits_in -= 8; \
1602
- } \
1603
-} MZ_MACRO_END
1604
-
1605
-#define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \
1606
- if (rle_repeat_count < 3) { \
1607
- d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \
1608
- while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \
1609
- } else { \
1610
- d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \
1611
-} rle_repeat_count = 0; } }
1612
-
1613
-#define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \
1614
- if (rle_z_count < 3) { \
1615
- d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \
1616
- } else if (rle_z_count <= 10) { \
1617
- d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \
1618
- } else { \
1619
- d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \
1620
-} rle_z_count = 0; } }
1621
-
1622
-static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
1623
-
1624
-static void tdefl_start_dynamic_block(tdefl_compressor *d)
1625
-{
1626
- int num_lit_codes, num_dist_codes, num_bit_lengths; mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index;
1627
- mz_uint8 code_sizes_to_pack[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], packed_code_sizes[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], prev_code_size = 0xFF;
1628
-
1629
- d->m_huff_count[0][256] = 1;
1630
-
1631
- tdefl_optimize_huffman_table(d, 0, TDEFL_MAX_HUFF_SYMBOLS_0, 15, MZ_FALSE);
1632
- tdefl_optimize_huffman_table(d, 1, TDEFL_MAX_HUFF_SYMBOLS_1, 15, MZ_FALSE);
1633
-
1634
- for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--) if (d->m_huff_code_sizes[0][num_lit_codes - 1]) break;
1635
- for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--) if (d->m_huff_code_sizes[1][num_dist_codes - 1]) break;
1636
-
1637
- memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes);
1638
- memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes);
1639
- total_code_sizes_to_pack = num_lit_codes + num_dist_codes; num_packed_code_sizes = 0; rle_z_count = 0; rle_repeat_count = 0;
1640
-
1641
- memset(&d->m_huff_count[2][0], 0, sizeof(d->m_huff_count[2][0]) * TDEFL_MAX_HUFF_SYMBOLS_2);
1642
- for (i = 0; i < total_code_sizes_to_pack; i++)
1643
- {
1644
- mz_uint8 code_size = code_sizes_to_pack[i];
1645
- if (!code_size)
1646
- {
1647
- TDEFL_RLE_PREV_CODE_SIZE();
1648
- if (++rle_z_count == 138) { TDEFL_RLE_ZERO_CODE_SIZE(); }
1649
- }
1650
- else
1651
- {
1652
- TDEFL_RLE_ZERO_CODE_SIZE();
1653
- if (code_size != prev_code_size)
1654
- {
1655
- TDEFL_RLE_PREV_CODE_SIZE();
1656
- d->m_huff_count[2][code_size] = (mz_uint16)(d->m_huff_count[2][code_size] + 1); packed_code_sizes[num_packed_code_sizes++] = code_size;
1657
- }
1658
- else if (++rle_repeat_count == 6)
1659
- {
1660
- TDEFL_RLE_PREV_CODE_SIZE();
1661
- }
1662
- }
1663
- prev_code_size = code_size;
1664
- }
1665
- if (rle_repeat_count) { TDEFL_RLE_PREV_CODE_SIZE(); } else { TDEFL_RLE_ZERO_CODE_SIZE(); }
1666
-
1667
- tdefl_optimize_huffman_table(d, 2, TDEFL_MAX_HUFF_SYMBOLS_2, 7, MZ_FALSE);
1668
-
1669
- TDEFL_PUT_BITS(2, 2);
1670
-
1671
- TDEFL_PUT_BITS(num_lit_codes - 257, 5);
1672
- TDEFL_PUT_BITS(num_dist_codes - 1, 5);
1673
-
1674
- for (num_bit_lengths = 18; num_bit_lengths >= 0; num_bit_lengths--) if (d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[num_bit_lengths]]) break;
1675
- num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1)); TDEFL_PUT_BITS(num_bit_lengths - 4, 4);
1676
- for (i = 0; (int)i < num_bit_lengths; i++) TDEFL_PUT_BITS(d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[i]], 3);
1677
-
1678
- for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes; )
1679
- {
1680
- mz_uint code = packed_code_sizes[packed_code_sizes_index++]; MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2);
1681
- TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]);
1682
- if (code >= 16) TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++], "\02\03\07"[code - 16]);
1683
- }
1684
-}
1685
-
1686
-static void tdefl_start_static_block(tdefl_compressor *d)
1687
-{
1688
- mz_uint i;
1689
- mz_uint8 *p = &d->m_huff_code_sizes[0][0];
1690
-
1691
- for (i = 0; i <= 143; ++i) *p++ = 8;
1692
- for ( ; i <= 255; ++i) *p++ = 9;
1693
- for ( ; i <= 279; ++i) *p++ = 7;
1694
- for ( ; i <= 287; ++i) *p++ = 8;
1695
-
1696
- memset(d->m_huff_code_sizes[1], 5, 32);
1697
-
1698
- tdefl_optimize_huffman_table(d, 0, 288, 15, MZ_TRUE);
1699
- tdefl_optimize_huffman_table(d, 1, 32, 15, MZ_TRUE);
1700
-
1701
- TDEFL_PUT_BITS(1, 2);
1702
-}
1703
-
1704
-static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
1705
-
1706
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
1707
-static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
1708
-{
1709
- mz_uint flags;
1710
- mz_uint8 *pLZ_codes;
1711
- mz_uint8 *pOutput_buf = d->m_pOutput_buf;
1712
- mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf;
1713
- mz_uint64 bit_buffer = d->m_bit_buffer;
1714
- mz_uint bits_in = d->m_bits_in;
1715
-
1716
-#define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); }
1717
-
1718
- flags = 1;
1719
- for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1)
1720
- {
1721
- if (flags == 1)
1722
- flags = *pLZ_codes++ | 0x100;
1723
-
1724
- if (flags & 1)
1725
- {
1726
- mz_uint s0, s1, n0, n1, sym, num_extra_bits;
1727
- mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3;
1728
-
1729
- MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
1730
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
1731
- TDEFL_PUT_BITS_FAST(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
1732
-
1733
- // This sequence coaxes MSVC into using cmov's vs. jmp's.
1734
- s0 = s_tdefl_small_dist_sym[match_dist & 511];
1735
- n0 = s_tdefl_small_dist_extra[match_dist & 511];
1736
- s1 = s_tdefl_large_dist_sym[match_dist >> 8];
1737
- n1 = s_tdefl_large_dist_extra[match_dist >> 8];
1738
- sym = (match_dist < 512) ? s0 : s1;
1739
- num_extra_bits = (match_dist < 512) ? n0 : n1;
1740
-
1741
- MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1742
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1743
- TDEFL_PUT_BITS_FAST(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
1744
- }
1745
- else
1746
- {
1747
- mz_uint lit = *pLZ_codes++;
1748
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1749
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1750
-
1751
- if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
1752
- {
1753
- flags >>= 1;
1754
- lit = *pLZ_codes++;
1755
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1756
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1757
-
1758
- if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
1759
- {
1760
- flags >>= 1;
1761
- lit = *pLZ_codes++;
1762
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1763
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1764
- }
1765
- }
1766
- }
1767
-
1768
- if (pOutput_buf >= d->m_pOutput_buf_end)
1769
- return MZ_FALSE;
1770
-
1771
- *(mz_uint64*)pOutput_buf = bit_buffer;
1772
- pOutput_buf += (bits_in >> 3);
1773
- bit_buffer >>= (bits_in & ~7);
1774
- bits_in &= 7;
1775
- }
1776
-
1777
-#undef TDEFL_PUT_BITS_FAST
1778
-
1779
- d->m_pOutput_buf = pOutput_buf;
1780
- d->m_bits_in = 0;
1781
- d->m_bit_buffer = 0;
1782
-
1783
- while (bits_in)
1784
- {
1785
- mz_uint32 n = MZ_MIN(bits_in, 16);
1786
- TDEFL_PUT_BITS((mz_uint)bit_buffer & mz_bitmasks[n], n);
1787
- bit_buffer >>= n;
1788
- bits_in -= n;
1789
- }
1790
-
1791
- TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1792
-
1793
- return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1794
-}
1795
-#else
1796
-static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
1797
-{
1798
- mz_uint flags;
1799
- mz_uint8 *pLZ_codes;
1800
-
1801
- flags = 1;
1802
- for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1)
1803
- {
1804
- if (flags == 1)
1805
- flags = *pLZ_codes++ | 0x100;
1806
- if (flags & 1)
1807
- {
1808
- mz_uint sym, num_extra_bits;
1809
- mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); pLZ_codes += 3;
1810
-
1811
- MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
1812
- TDEFL_PUT_BITS(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
1813
- TDEFL_PUT_BITS(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
1814
-
1815
- if (match_dist < 512)
1816
- {
1817
- sym = s_tdefl_small_dist_sym[match_dist]; num_extra_bits = s_tdefl_small_dist_extra[match_dist];
1818
- }
1819
- else
1820
- {
1821
- sym = s_tdefl_large_dist_sym[match_dist >> 8]; num_extra_bits = s_tdefl_large_dist_extra[match_dist >> 8];
1822
- }
1823
- MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1824
- TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1825
- TDEFL_PUT_BITS(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
1826
- }
1827
- else
1828
- {
1829
- mz_uint lit = *pLZ_codes++;
1830
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1831
- TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1832
- }
1833
- }
1834
-
1835
- TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1836
-
1837
- return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1838
-}
1839
-#endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
1840
-
1841
-static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block)
1842
-{
1843
- if (static_block)
1844
- tdefl_start_static_block(d);
1845
- else
1846
- tdefl_start_dynamic_block(d);
1847
- return tdefl_compress_lz_codes(d);
1848
-}
1849
-
1850
-static int tdefl_flush_block(tdefl_compressor *d, int flush)
1851
-{
1852
- mz_uint saved_bit_buf, saved_bits_in;
1853
- mz_uint8 *pSaved_output_buf;
1854
- mz_bool comp_block_succeeded = MZ_FALSE;
1855
- int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
1856
- mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf;
1857
-
1858
- d->m_pOutput_buf = pOutput_buf_start;
1859
- d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;
1860
-
1861
- MZ_ASSERT(!d->m_output_flush_remaining);
1862
- d->m_output_flush_ofs = 0;
1863
- d->m_output_flush_remaining = 0;
1864
-
1865
- *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
1866
- d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
1867
-
1868
- if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index))
1869
- {
1870
- TDEFL_PUT_BITS(0x78, 8); TDEFL_PUT_BITS(0x01, 8);
1871
- }
1872
-
1873
- TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1);
1874
-
1875
- pSaved_output_buf = d->m_pOutput_buf; saved_bit_buf = d->m_bit_buffer; saved_bits_in = d->m_bits_in;
1876
-
1877
- if (!use_raw_block)
1878
- comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48));
1879
-
1880
- // If the block gets expanded, forget the current contents of the output buffer and send a raw block instead.
1881
- if ( ((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
1882
- ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size) )
1883
- {
1884
- mz_uint i; d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
1885
- TDEFL_PUT_BITS(0, 2);
1886
- if (d->m_bits_in) { TDEFL_PUT_BITS(0, /* miniz.c v1.16 beta r1 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
1887
- See "unlicense" statement at the end of this file.
1888
- Rich Geldreich <[email protected]>, last updated Oct. 13, 2013
1889
- Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
1890
-
1891
- Most API's defined in miniz.c are optionaljority of prev. users so I'm
1892
- op)w deflate data (pr/* matic const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 };
1893
- static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
1894
- static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
1895
- static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
1896
- static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
1897
- static const int s_min_table_sizes[3] = { 257, 1, 4 };
1898
-
1899
- tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf;
1900
- const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
1901
- mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
1902
- size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
1903
-
1904
- // Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter).
1905
- if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; }
1906
-
1907
- num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start;
1908
- TINFL_CR_BEGIN
1909
-
1910
- bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1;
1911
- if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
1912
- {
1913
- TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1);
1914
- counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
1915
- if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
1916
- if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); }
1917
- }
1918
-
1919
- do
1920
- {
1921
- TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1;
1922
- if (r->m_type == 0)
1923
- {
1924
- TINFL_SKIP_BITS(5, num_bits & 7);
1925
- for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); }
1926
- if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); }
1927
- while ((counter) && (num_bits))
1928
- {
1929
- TINFL_GET_BITS(51, dist, 8);
1930
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); }
1931
- *pOut_buf_cur++ = (mz_uint8)dist;
1932
- counter--;
1933
- }
1934
- while (counter)
1935
- {
1936
- size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); }
1937
- while (pIn_buf_cur >= pIn_buf_end)
1938
- {
1939
- if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT)
1940
- {
1941
- TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT);
1942
- }
1943
- else
1944
- {
1945
- TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED);
1946
- }
1947
- }
1948
- n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter);
1949
- TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n;
1950
- }
1951
- }
1952
- else if (r->m_type == 3)
1953
- {
1954
- TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
1955
- }
1956
- else
1957
- {
1958
- if (r->m_type == 1)
1959
- {
1960
- mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i;
1961
- r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
1962
- for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
1963
- }
1964
- else
1965
- {
1966
- for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
1967
- MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
1968
- r->m_table_sizes[2] = 19;
1969
- }
1970
- for ( ; (int)r->m_type >= 0; r->m_type--)
1971
- {
1972
- int tree_next, tree_cur; tinfl_huff_table *pTable;
1973
- mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree);
1974
- for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
1975
- used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
1976
- for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
1977
- if ((65536 != total) && (used_syms > 1))
1978
- {
1979
- TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
1980
- }
1981
- for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
1982
- {
1983
- mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue;
1984
- cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
1985
- if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; }
1986
- if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
1987
- rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
1988
- for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
1989
- {
1990
- tree_cur -= ((rev_code >>= 1) & 1);
1991
- if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1];
1992
- }
1993
- tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
1994
- }
1995
- if (r->m_type == 2)
1996
- {
1997
- for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); )
1998
- {
1999
- mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; }
2000
- if ((dist == 16) && (!counter))
2001
- {
2002
- TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED);
2003
- }
2004
- num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16];
2005
- TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s;
2006
- }
2007
- if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
2008
- {
2009
- TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
2010
- }
2011
- TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
2012
- }
2013
- }
2014
- for ( ; ; )
2015
- {
2016
- mz_uint8 *pSrc;
2017
- for ( ; ; )
2018
- {
2019
- if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
2020
- {
2021
- TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
2022
- if (counter >= 256)
2023
- break;
2024
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
2025
- *pOut_buf_cur++ = (mz_uint8)counter;
2026
- }
2027
- else
2028
- {
2029
- int sym2; mz_uint code_len;
2030
-#if TINFL_USE_64BIT_BITBUF
2031
- if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; }
2032
-#else
2033
- if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
2034
-#endif
2035
- if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
2036
- code_len = sym2 >> 9;
2037
- else
2038
- {
2039
- code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
2040
- }
2041
- counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
2042
- if (counter & 256)
2043
- break;
2044
-
2045
-#if !TINFL_USE_64BIT_BITBUF
2046
- if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
2047
-#endif
2048
- if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
2049
- code_len = sym2 >> 9;
2050
- else
2051
- {
2052
- code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
2053
- }
2054
- bit_buf >>= code_len; num_bits -= code_len;
2055
-
2056
- pOut_buf_cur[0] = (mz_uint8)counter;
2057
- if (sym2 & 256)
2058
- {
2059
- pOut_buf_cur++;
2060
- counter = sym2;
2061
- break;
2062
- }
2063
- pOut_buf_cur[1] = (mz_uint8)sym2;
2064
- pOut_buf_cur += 2;
2065
- }
2066
- }
2067
- if ((counter &= 511) == 256) break;
2068
-
2069
- num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
2070
- if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
2071
-
2072
- TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
2073
- num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
2074
- if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
2075
-
2076
- dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
2077
- if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
2078
- {
2079
- TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
2080
- }
2081
-
2082
- pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
2083
-
2084
- if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
2085
- {
2086
- while (counter--)
2087
- {
2088
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); }
2089
- *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
2090
- }
2091
- continue;
2092
- }
2093
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
2094
- else if ((counter >= 9) && (counter <= dist))
2095
- {
2096
- const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
2097
- do
2098
- {
2099
- ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
2100
- ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
2101
- pOut_buf_cur += 8;
2102
- } while ((pSrc += 8) < pSrc_end);
2103
- if ((counter &= 7) < 3)
2104
- {
2105
- if (counter)
2106
- {
2107
- pOut_buf_cur[0] = pSrc[0];
2108
- if (counter > 1)
2109
- pOut_buf_cur[1] = pSrc[1];
2110
- pOut_buf_cur += counter;
2111
- }
2112
- continue;
2113
- }
2114
- }
2115
-#endif
2116
- do
2117
- {
2118
- pOut_buf_cur[0] = pSrc[0];
2119
- pOut_buf_cur[1] = pSrc[1];
2120
- pOut_buf_cur[2] = pSrc[2];
2121
- pOut_buf_cur += 3; pSrc += 3;
2122
- } while ((int)(counter -= 3) > 2);
2123
- if ((int)counter > 0)
2124
- {
2125
- pOut_buf_cur[0] = pSrc[0];
2126
- if ((int)counter > 1)
2127
- pOut_buf_cur[1] = pSrc[1];
2128
- pOut_buf_cur += counter;
2129
- }
2130
- }
2131
- }
2132
- } while (!(r->m_final & 1));
2133
- if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
2134
- {
2135
- TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; }
2136
- }
2137
- TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE);
2138
- TINFL_CR_FINISH
2139
-
2140
-common_exit:
2141
- r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start;
2142
- *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
2143
- if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
2144
- {
2145
- const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size;
2146
- mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552;
2147
- while (buf_len)
2148
- {
2149
- for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
2150
- {
2151
- s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
2152
- s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
2153
- }
2154
- for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
2155
- s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
2156
- }
2157
- r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH;
2158
- }
2159
- return status;
2160
-}
2161
-
2162
-// Higher level helper functions.
2163
-void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
2164
-{
2165
- tinfl_decompressor decomp; void *pBuf = NULL, *pNew_buf; size_t src_buf_ofs = 0, out_buf_capacity = 0;
2166
- *pOut_len = 0;
2167
- tinfl_init(&decomp);
2168
- for ( ; ; )
2169
- {
2170
- size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
2171
- tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size,
2172
- (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
2173
- if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
2174
- {
2175
- MZ_FREE(pBuf); *pOut_len = 0; return NULL;
2176
- }
2177
- src_buf_ofs += src_buf_size;
2178
- *pOut_len += dst_buf_size;
2179
- if (status == TINFL_STATUS_DONE) break;
2180
- new_out_buf_capacity = out_buf_capacity * 2; if (new_out_buf_capacity < 128) new_out_buf_capacity = 128;
2181
- pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity);
2182
- if (!pNew_buf)
2183
- {
2184
- MZ_FREE(pBuf); *pOut_len = 0; return NULL;
2185
- }
2186
- pBuf = pNew_buf; out_buf_capacity = new_out_buf_capacity;
2187
- }
2188
- return pBuf;
2189
-}
2190
-
2191
-size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
2192
-{
2193
- tinfl_decompressor decomp; tinfl_status status; tinfl_init(&decomp);
2194
- status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf, &src_buf_len, (mz_uint8*)pOut_buf, (mz_uint8*)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
2195
- return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len;
2196
-}
2197
-
2198
-int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
2199
-{
2200
- int result = 0;
2201
- tinfl_decompressor decomp;
2202
- mz_uint8 *pDict = (mz_uint8*)MZ_MALLOC(TINFL_LZ_DICT_SIZE); size_t in_buf_ofs = 0, dict_ofs = 0;
2203
- if (!pDict)
2204
- return TINFL_STATUS_FAILED;
2205
- tinfl_init(&decomp);
2206
- for ( ; ; )
2207
- {
2208
- size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
2209
- tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size,
2210
- (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
2211
- in_buf_ofs += in_buf_size;
2212
- if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user)))
2213
- break;
2214
- if (status != TINFL_STATUS_HAS_MORE_OUTPUT)
2215
- {
2216
- result = (status == TINFL_STATUS_DONE);
2217
- break;
2218
- }
2219
- dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1);
2220
- }
2221
- MZ_FREE(pDict);
2222
- *pIn_buf_size = in_buf_ofs;
2223
- return result;
2224
-}
2225
-
2226
-// ------------------- Low-level Compression (independent from all decompression API's)
2227
-
2228
-// Purposely making these tables static for faster init and thread safety.
2229
-static const mz_uint16 s_tdefl_len_sym[256] = {
2230
- 257,258,259,260,261,262,263,264,265,265,266,266,267,267,268,268,269,269,269,269,270,270,270,270,271,271,271,271,272,272,272,272,
2231
- 273,273,273,273,273,273,273,273,274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,276,
2232
- 277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
2233
- 279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,
2234
- 281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,
2235
- 282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,
2236
- 283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,
2237
- 284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,285 };
2238
-
2239
-static const mz_uint8 s_tdefl_len_extra[256] = {
2240
- 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
2241
- 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
2242
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
2243
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0 };
2244
-
2245
-static const mz_uint8 s_tdefl_small_dist_sym[512] = {
2246
- 0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
2247
- 11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,
2248
- 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,
2249
- 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
2250
- 14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
2251
- 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16
--- a/src/miniz.c
+++ b/src/miniz.c
@@ -1,2251 +0,0 @@
1 /* miniz.c v1.15 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
2 See "unlicense" statement at the end of this file.
3 Rich Geldreich <[email protected]>, last updated Oct. 13, 2013
4 Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
5
6 Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define
7 MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros).
8
9 * Change History
10 10/1ller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
11 void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip);
12 void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
13
14 // Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
15 typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
16
17 // tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function intern return MZ_DATA_ERROR;
18
19 if (pState->m_has_flushed && (flush != MZ_FINISH)) return MZ_STREAM_ERROR;
20 pState->m_has_flushed |= (flush == MZ_FINISH);
21
22 if ((flush == MZ_FINISH) && (first_call))
23 {
24 // MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file.
25 decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
26 in_bytes = pStream->avail_in; out_bytes = pStream->avail_out;
27 status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags);
28 pState->m_last_status = status;
29 pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes;
30 pStream->adler = tinfl_get_adler32(&pState->m_decomp);
31 pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes; pStream->total_out += (mz_uint)out_bytes;
32
33 if (status < 0)
34 return MZ_DATA_ERROR;
35 else if (status != TINFL_STATUS_DONE)
36 {
37 pState->m_last_status = TINFL_STATUS_FAILED;
38 return MZ_BUF_ERROR;
39 }
40 return MZ_STREAM_END;
41 }
42 // flush != MZ_FINISH then we must assume there's more input.
43 if (flush != MZ_FINISH) decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;
44
45 if (pState->m_dict_avail)
46 {
47 n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
48 memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
49 pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n;
50 pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
51 return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
52 }
53
54 for ( ; ; )
55 {
56 in_bytes = pStream->avail_in;
57 out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs;
58
59 status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags);
60 pState->m_last_status = status;
61
62 pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes;
63 pStream->total_in += (mz_uint)in_bytes; pStream->adler = tinfl_get_adler32(&pState->m_decomp);
64
65 pState->m_dict_avail = (mz_uint)out_bytes;
66
67 n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
68 memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
69 pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n;
70 pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
71
72 if (status < 0)
73 return MZ_DATA_ERROR; // Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well).
74 else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
75 return MZ_BUF_ERROR; // Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH.
76 else if (flush == MZ_FINISH)
77 {
78 // The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH.
79 if (status == TINFL_STATUS_DONE)
80 return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END;
81 // status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong.
82 else if (!pStream->avail_out)
83 return MZ_BUF_ERROR;
84 }
85 else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail))
86 break;
87 }
88
89 return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
90 }
91
92 int mz_inflateEnd(mz_streamp pStream)
93 {
94 if (!pStream)
95 return MZ_STREAM_ERROR;
96 if (pStream->state)
97 {
98 pStream->zfree(pStream->opaque, pStream->state);
99 pStream->state = NULL;
100 }
101 return MZ_OK;
102 }
103
104 int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
105 {
106 mz_stream stream;
107 int status;
108 memset(&stream, 0, sizeof(stream));
109
110 // In case mz_ulong is 64-bits (argh I hate longs).
111 if ((source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR;
112
113 stream.next_in = pSource;
114 stream.avail_in = (mz_uint32)source_len;
115 stream.next_out = pDest;
116 stream.avail_out = (mz_uint32)*pDest_len;
117
118 status = mz_inflateInit(&stream);
119 if (status != MZ_OK)
120 return status;
121
122 status = mz_inflate(&stream, MZ_FINISH);
123 if (status != MZ_STREAM_END)
124 {
125 mz_inflateEnd(&stream);
126 return ((status == MZ_BUF_ERROR) && (!stream.avail_in)) ? MZ_DATA_ERROR : status;
127 }
128 *pDest_len = stream.total_out;
129
130 return mz_inflateEnd(&stream);
131 }
132
133 const char *mz_error(int err)
134 {
135 static const struct { int m_err; const char *m_pDesc; } s_error_descs[] =
136 {
137 { MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" },
138 { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" }
139 };
140 mz_uint i; for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i) if (s_error_descs[i].m_err == err) return s_error_descs[i].m_pDesc;
141 return NULL;
142 }
143
144 #endif //MINIZ_NO_ZLIB_APIS
145
146 // ------------------- Low-level Decompression (completely independent from all compression API's)
147
148 #define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
149 #define TINFL_MEMSET(p, c, l) memset(p, c, l)
150
151 #define TINFL_CR_BEGIN switch(r->m_state) { case 0:
152 #define TINFL_CR_RETURN(state_index, result) do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END
153 #define TINFL_CR_RETURN_FOREVER(state_index, result) do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END
154 #define TINFL_CR_FINISH }
155
156 // TODO: If the caller has indicated that there's no more input, and we attempt to read beyond the input buf, then something is wrong with the input because the inflator never
157 // reads ahead more than it needs to. Currently TINFL_GET_BYTE() pads the end of the stream with 0's in this scenario.
158 #define TINFL_GET_BYTE(state_index, c) do { \
159 if (pIn_buf_cur >= pIn_buf_end) { \
160 for ( ; ; ) { \
161 if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \
162 TINFL_CR_RETURN(state_index, TINFL_STATUS_NEEDS_MORE_INPUT); \
163 if (pIn_buf_cur < pIn_buf_end) { \
164 c = *pIn_buf_cur++; \
165 break; \
166 } \
167 } else { \
168 c = 0; \
169 break; \
170 } \
171 } \
172 } else c = *pIn_buf_cur++; } MZ_MACRO_END
173
174 #define TINFL_NEED_BITS(state_index, n) do { mz_uint c; TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; } while (num_bits < (mz_uint)(n))
175 #define TINFL_SKIP_BITS(state_index, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
176 #define TINFL_GET_BITS(state_index, b, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } b = bit_buf & ((1 << (n)) - 1); bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
177
178 // TINFL_HUFF_BITBUF_FILL() is only used rarely, when the number of bytes remaining in the input buffer falls below 2.
179 // It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a
180 // Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the
181 // bit buffer contains >=15 bits (deflate's max. Huffman code size).
182 #define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \
183 do { \
184 temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
185 if (temp >= 0) { \
186 code_len = temp >> 9; \
187 if ((code_len) && (num_bits >= code_len)) \
188 break; \
189 } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \
190 code_len = TINFL_FAST_LOOKUP_BITS; \
191 do { \
192 temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
193 } while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \
194 } TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \
195 } while (num_bits < 15);
196
197 // TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read
198 // beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully
199 // decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32.
200 // The slow path is only executed at the very end of the input buffer.
201 #define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \
202 int temp; mz_uint code_len, c; \
203 if (num_bits < 15) { \
204 if ((pIn_buf_end - pIn_buf_cur) < 2) { \
205 TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
206 } else { \
207 bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \
208 } \
209 } \
210 if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
211 code_len = temp >> 9, temp &= 511; \
212 else { \
213 code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \
214 } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END
215
216 tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags)
217 {
218 static const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 };
219 static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
220 static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
221 static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
222 static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
223 static const int s_min_table_sizes[3] = { 257, 1, 4 };
224
225 tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf;
226 const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
227 mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
228 size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
229
230 // Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter).
231 if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; }
232
233 num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start;
234 TINFL_CR_BEGIN
235
236 bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1;
237 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
238 {
239 TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1);
240 counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
241 if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
242 if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); }
243 }
244
245 do
246 {
247 TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1;
248 if (r->m_type == 0)
249 {
250 TINFL_SKIP_BITS(5, num_bits & 7);
251 for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); }
252 if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); }
253 while ((counter) && (num_bits))
254 {
255 TINFL_GET_BITS(51, dist, 8);
256 while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); }
257 *pOut_buf_cur++ = (mz_uint8)dist;
258 counter--;
259 }
260 while (counter)
261 {
262 size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); }
263 while (pIn_buf_cur >= pIn_buf_end)
264 {
265 if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT)
266 {
267 TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT);
268 }
269 else
270 {
271 TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED);
272 }
273 }
274 n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter);
275 TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n;
276 }
277 }
278 else if (r->m_type == 3)
279 {
280 TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
281 }
282 else
283 {
284 if (r->m_type == 1)
285 {
286 mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i;
287 r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
288 for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
289 }
290 else
291 {
292 for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
293 MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
294 r->m_table_sizes[2] = 19;
295 }
296 for ( ; (int)r->m_type >= 0; r->m_type--)
297 {
298 int tree_next, tree_cur; tinfl_huff_table *pTable;
299 mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree);
300 for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
301 used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
302 for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
303 if ((65536 != total) && (used_syms > 1))
304 {
305 TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
306 }
307 for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
308 {
309 mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue;
310 cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
311 if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; }
312 if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
313 rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
314 for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
315 {
316 tree_cur -= ((rev_code >>= 1) & 1);
317 if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1];
318 }
319 tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
320 }
321 if (r->m_type == 2)
322 {
323 for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); )
324 {
325 mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; }
326 if ((dist == 16) && (!counter))
327 {
328 TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED);
329 }
330 num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16];
331 TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s;
332 }
333 if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
334 {
335 TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
336 }
337 TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
338 }
339 }
340 for ( ; ; )
341 {
342 mz_uint8 *pSrc;
343 for ( ; ; )
344 {
345 if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
346 {
347 TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
348 if (counter >= 256)
349 break;
350 while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
351 *pOut_buf_cur++ = (mz_uint8)counter;
352 }
353 else
354 {
355 int sym2; mz_uint code_len;
356 #if TINFL_USE_64BIT_BITBUF
357 if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; }
358 #else
359 if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
360 #endif
361 if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
362 code_len = sym2 >> 9;
363 else
364 {
365 code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
366 }
367 counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
368 if (counter & 256)
369 break;
370
371 #if !TINFL_USE_64BIT_BITBUF
372 if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
373 #endif
374 if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
375 code_len = sym2 >> 9;
376 else
377 {
378 code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
379 }
380 bit_buf >>= code_len; num_bits -= code_len;
381
382 pOut_buf_cur[0] = (mz_uint8)counter;
383 if (sym2 & 256)
384 {
385 pOut_buf_cur++;
386 counter = sym2;
387 break;
388 }
389 pOut_buf_cur[1] = (mz_uint8)sym2;
390 pOut_buf_cur += 2;
391 }
392 }
393 if ((counter &= 511) == 256) break;
394
395 num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
396 if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
397
398 TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
399 num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
400 if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
401
402 dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
403 if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
404 {
405 TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
406 }
407
408 pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
409
410 if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
411 {
412 while (counter--)
413 {
414 while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); }
415 *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
416 }
417 continue;
418 }
419 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
420 else if ((counter >= 9) && (counter <= dist))
421 {
422 const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
423 do
424 {
425 ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
426 ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
427 pOut_buf_cur += 8;
428 } while ((pSrc += 8) < pSrc_end);
429 if ((counter &= 7) < 3)
430 {
431 if (counter)
432 {
433 pOut_buf_cur[0] = pSrc[0];
434 if (counter > 1)
435 pOut_buf_cur[1] = pSrc[1];
436 pOut_buf_cur += counter;
437 }
438 continue;
439 }
440 }
441 #endif
442 do
443 {
444 pOut_buf_cur[0] = pSrc[0];
445 pOut_buf_cur[1] = pSrc[1];
446 pOut_buf_cur[2] = pSrc[2];
447 pOut_buf_cur += 3; pSrc += 3;
448 } while ((int)(counter -= 3) > 2);
449 if ((int)counter > 0)
450 {
451 pOut_buf_cur[0] = pSrc[0];
452 if ((int)counter > 1)
453 pOut_buf_cur[1] = pSrc[1];
454 pOut_buf_cur += counter;
455 }
456 }
457 }
458 } while (!(r->m_final & 1));
459 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
460 {
461 TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; }
462 }
463 TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE);
464 TINFL_CR_FINISH
465
466 common_exit:
467 r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start;
468 *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
469 if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
470 {
471 const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size;
472 mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552;
473 while (buf_len)
474 {
475 for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
476 {
477 s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
478 s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
479 }
480 for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
481 s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
482 }
483 r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH;
484 }
485 return status;
486 }
487
488 // Higher level helper functions.
489 void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
490 {
491 tinfl_decompressor decomp; void *pBuf = NULL, *pNew_buf; size_t src_buf_ofs = 0, out_buf_capacity = 0;
492 *pOut_len = 0;
493 tinfl_init(&decomp);
494 for ( ; ; )
495 {
496 size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
497 tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size,
498 (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
499 if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
500 {
501 MZ_FREE(pBuf); *pOut_len = 0; return NULL;
502 }
503 src_buf_ofs += src_buf_size;
504 *pOut_len += dst_buf_size;
505 if (status == TINFL_STATUS_DONE) break;
506 new_out_buf_capacity = out_buf_capacit7,278,278,278,278,278,278,27880,
507 281,2 w deflate (non-zlib) = -1,,277,278,278,278DONE = 0,,277,278,278,278 byte in order t = 1,,277,278,278,278HAS_MORE_OUTPUT = 215,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,
508 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
509 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
510 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
511 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
512 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
513 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17 };
514
515 static const mz_uint8 s_tdefl_small_dist_extra[512] = {
516 0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
517 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
518 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
519 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
520 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
521 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
522 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
523 7,7,7,7,7,7,7,7 };
524
525 static const mz_uint8 s_tdefl_large_dist_sym[128] = {
526 0,0,18,19,20,20,21,21,22,22,22,22,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,
527 26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
528 28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 };
529
530 static const mz_uint8 s_tdefl_large_dist_extra[128] = {
531 0,0,8,8,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
532 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
533 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13 };
534
535 // Radix sorts tdefl_sym_freq[] array by 16-bit key m_key. Returns ptr to sorted values.
536 typedef struct { mz_uint16 m_key, m_sym_index; } tdefl_sym_freq;
537 static tdefl_sym_freq* tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq* pSyms0, tdefl_sym_freq* pSyms1)
538 {
539 mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; tdefl_sym_freq* pCur_syms = pSyms0, *pNew_syms = pSyms1; MZ_CLEAR_OBJ(hist);
540 for (i = 0; i < num_syms; i++) { mz_uint freq = pSyms0[i].m_key; hist[freq & 0xFF]++; hist[256 + ((freq >> 8) & 0xFF)]++; }
541 while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--;
542 for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
543 {
544 const mz_uint32* pHist = &hist[pass << 8];
545 mz_uint offsets[256], cur_ofs = 0;
546 for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; }
547 for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
548 { tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; }
549 }
550 return pCur_syms;
551 }
552
553 // tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, [email protected], Jyrki Katajainen, [email protected], November 1996.
554 static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
555 {
556 int root, leaf, next, avbl, used, dpth;
557 if (n==0) return; else if (n==1) { A[0].m_key = 1; return; }
558 A[0].m_key += A[1].m_key; root = 0; leaf = 2;
559 for (next=1; next < n-1; next++)
560 {
561 if (leaf>=n || A[root].m_key<A[leaf].m_key) { A[next].m_key = A[root].m_key; A[root++].m_key = (mz_uint16)next; } else A[next].m_key = A[leaf++].m_key;
562 if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key); A[root++].m_key = (mz_uint16)next; } else A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
563 }
564 A[n-2].m_key = 0; for (next=n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1;
565 avbl = 1; used = dpth = 0; root = n-2; next = n-1;
566 while (avbl>0)
567 {
568 while (root>=0 && (int)A[root].m_key==dpth) { used++; root--; }
569 while (avbl>used) { A[next--].m_key = (mz_uint16)(dpth); avbl--; }
570 avbl = 2*used; dpth++; used = 0;
571 }
572 }
573
574 // Limits canonical Huffman code table's max um_syms == hist[(total_passes - 1) * 256])) total_passes--;
575 for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
576 {
577 const mz_uint32* pHist = &hist[pass << 8];
578 mz_uint offsets[256], cur_ofs = 0;
579 for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; }
580 for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
581 { tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; }
582 }
583 return pCur_syms;
584 }
585
586 // tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, [email protected], Jyrki Katajainen, [email protected], November 1996.
587 static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
588 {
589 int root, leaf, next, avbl, used, dpth;
590 if (n==0) return; else if (n==1) { A[0].m_key = 1; return; }
591 A[0].m_key += A[1].m_key; root = 0; leaf = 2;
592 for (next=1; next < n-1; next++)
593 {
594 if (leaf>=n || A[root].m_key<A[leaf].m_key) { A[next].m_key = A[root].m_key; A[root++].m_key = (mz_uint16)next; } else A[next].m_key = A[leaf++].m_key;
595 if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key); A[root++].m_key = (mz_uint16)next; } else A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
596 }
597 A[n-2].m_key = 0; for (next=n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1;
598 avbl = 1; used = dpth = 0; root = n-2; next = n-1;
599 while (avbl>0)
600 {
601 while (root>=0 && (int)A[root].m_key==dpth) { used++; root--; }
602 while (avbl>used) { A[next--].m_key = (mz_uint16)(dpth); avbl--; }
603 avbl = 2*used; dpth++; used = 0;
604 }
605 }
606
607 // Limits canonical Huffman code table's max code size.
608 enum { TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32 };
609 static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size)
610 {
611 int i; mz_uint32 total = 0; if (code_list_len <= 1) return;
612 for (i = max_code_size + 1; i <= TDEFL_MAX_SUPPORTED_HUFF_CODESIZE; i++) pNum_codes[max_code_size] += pNum_codes[i];
613 for (i = max_code_size; i > 0; i--) total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i));
614 while (total != (1UL << max_code_size))
615 {
616 pNum_codes[max_code_size]--;
617 for (i = max_code_size - 1; i > 0; i--) if (pNum_codes[i]) { pNum_codes[i]--; pNum_codes[i + 1] += 2; break; }
618 total--;
619 }
620 }
621
622 static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table)
623 {
624 int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; MZ_CLEAR_OBJ(num_codes);
625 if (static_table)
626 {
627 for (i = 0; i < table_len; i++) num_codes[d->m_huff_code_sizes[table_num][i]]++;
628 }
629 else
630 {
631 tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms;
632 int num_used_syms = 0;
633 const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0];
634 for (i = 0; i < table_len; i++) if (pSym_count[i]) { syms0[num_used_syms].m_key = (mz_uint16)pSym_count[i]; syms0[num_used_syms++].m_sym_index = (mz_uint16)i; }
635
636 pSyms = tdefl_radix_sort_syms(num_used_syms, syms0, syms1); tdefl_calculate_minimum_redundancy(pSyms, num_used_syms);
637
638 for (i = 0; i < num_used_syms; i++) num_codes[pSyms[i].m_key]++;
639
640 tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit);
641
642 MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); MZ_CLEAR_OBJ(d->m_huff_codes[table_num]);
643 for (i = 1, j = num_used_syms; i <= code_size_limit; i++)
644 for (l = num_codes[i]; l > 0; l--) d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i);
645 }
646
647 next_code[1] = 0; for (j = 0, i = 2; i <= code_size_limit; i++) next_code[i] = j = ((j + num_codes[i - 1]) << 1);
648
649 for (i = 0; i < table_len; i++)
650 {
651 mz_uint rev_code = 0, code, code_size; if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0) continue;
652 code = next_code[code_size]++; for (l = code_size; l > 0; l--, code >>= 1) rev_code = (rev_code << 1) | (code & 1);
653 d->m_huff_codes[table_num][i] = (mz_uint16)rev_code;
654 }
655 }
656
657 #define TDEFL_PUT_BITS(b, l) do { \
658 mz_uint bits = b; mz_uint len = l; MZ_ASSERT(bits <= ((1U << len) - 1U)); \
659 d->m_bit_buffer |= (bits << d->m_bits_in); d->m_bits_in += len; \
660 while (d->m_bits_in >= 8) { \
661 if (d->m_pOutput_buf < d->m_pOutput_buf_end) \
662 *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \
663 d->m_bit_buffer >>= 8; \
664 d->m_bits_in -= 8; \
665 } \
666 } MZ_MACRO_END
667
668 #define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \
669 if (rle_repeat_count < 3) { \
670 d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \
671 while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \
672 } else { \
673 d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \
674 } rle_repeat_count = 0; } }
675
676 #define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \
677 if (rle_z_count < 3) { \
678 d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \
679 } else if (rle_z_count <= 10) { \
680 d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \
681 } else { \
682 d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \
683 } rle_z_count = 0; } }
684
685 static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
686
687 static void tdefl_start_dynamic_block(tdefl_compressor *d)
688 {
689 int num_lit_codes, num_dist_codes, num_bit_lengths; mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_indITS(num_bit_lengths - 4, 4);
690 for (i = 0; (int)i < num_bit_lengths; i++) TDEFL_PUT_BITS(d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[i]], 3);
691
692 for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes; )
693 {
694 mz_uint code = packed_code_sizes[packed_code_sizes_index++]; MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2);
695 TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]);
696 if (code >= 16) TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++], "\02\03\07"[code - 16]);
697 }
698 }
699
700 static void tdefl_start_static_block(tdefl_compressor *d)
701 {
702 mz_uint i;
703 mz_uint8 *p = &d->m_huff_code_sizes[0][0];
704
705 for (i = 0; i <= 143; ++i) *p++ = 8;
706 for ( ; i <= 255; ++i) *p++ = 9;
707 for ( ; i <= 279; ++i) *p++ = 7;
708 for ( ; i <= 287; ++i) *p++ = 8;
709
710 memset(d->m_huff_code_sizes[1], 5, 32);
711
712 tdefl_optimize_huffman_table(d, 0, 288, 15, MZ_TRUE);
713 tdefl_optimize_huffman_table(d, 1, 32, 15, MZ_TRUE);
714
715 TDEFL_PUT_BITS(1, 2);
716 }
717
718 static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
719
720 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
721 static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
722 {
723 mz_uint flags;
724 mz_uint8 *pLZ_codes;
725 mz_uint8 *pOutput_buf = d->m_pOutput_buf;
726 mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf;
727 mz_uint64 bit_buffer = d->m_bit_buffer;
728 mz_uint bits_in = d->m_bits_in;
729
730 #define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); }
731
732 flags = 1;
733 for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1)
734 {
735 if (flags == 1)
736 flags = *pLZ_codes++ | 0x100;
737
738 if (flags & 1)
739 {
740 mz_uint s0, s1, n0, n1, sym, num_extra_bits;
741 mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3;
742
743 MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
744 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
745 TDEFL_PUT_BITS_FAST(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
746
747 // This sequence coaxes MSVC into using cmov's vs. jmp's.
748 s0 = s_tdefl_small_dist_sym[match_dist & 511];
749 n0 = s_tdefl_small_dist_extra[match_dist & 511];
750 s1 = s_tdefl_large_dist_sym[match_dist >> 8];
751 n1 = s_tdefl_large_dist_extra[match_dist >> 8];
752 sym = (match_dist < 512) ? s0 : s1;
753 num_extra_bits = (match_dist < 512) ? n0 : n1;
754
755 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
756 TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
757 TDEFL_PUT_BITS_FAST(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
758 }
759 else
760 {
761 mz_uint lit = *pLZ_codes++;
762 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
763 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
764
765 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
766 {
767 flags >>= 1;
768 lit = *pLZ_codes++;
769 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
770 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
771
772 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
773 {
774 flags >>= 1;
775 lit = *pLZ_codes++;
776 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
777 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
778 }
779 }
780 }
781
782 if (pOutput_buf >= d->m_pOutput_buf_end)
783 return MZ_FALSE;
784
785 *(mz_uint64*)pOutput_buf = bit_buffer;
786 pOutput_buf += (bits_in >> 3);
787 bit_buffer >>= (bits_in & ~7);
788 bits_in &= 7;
789 }
790
791 #undef TDEFL_PUT_BITS_FAST
792
793 d->m_pOutput_buf = pOutput_buf;
794 d->m_bits_in = 0;
795 d->m_bit_buffer = 0;
796
797 while (bits_in)
798 {
799 mz_uint32 n = MZ_MIN(bits_in, 16);
800 TDEFL_PUT_BITS((mz_uint)bit_buffer & mz_bitmasks[n], n);
801 bit_buffer >>= n;
802 bits_in -= n;
803 }
804
805 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
806
807 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
808 }
809 #else
810 static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
811 {
812 mz_uint flags;
813 mz_uint8 *pLZ_codes;
814
815 flags = 1;
816 for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1)
817 {
818 if (flags == 1)
819 flags = *pLZ_codes++ | 0x100;
820 if (flags & 1)
821 {
822 mz_uint sym, num_extra_bits;
823 mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); pLZ_codes += 3;
824
825 MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
826 TDEFL_PUT_BITS(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
827 TDEFL_PUT_BITS(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
828
829 if (match_dist < 512)
830 {
831 sym = s_tdefl_small_dist_sym[match_dist]; num_extra_bits = s_tdefl_small_dist_extra[match_dist];
832 }
833 else
834 {
835 sym = s_tdefl_large_dist_sym[match_dist >> 8]; num_extra_bits = s_tdefl_large_dist_extra[match_dist >> 8];
836 }
837 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
838 TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
839 TDEFL_PUT_BITS(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
840 }
841 else
842 {
843 mz_uint lit = *pLZ_codes++;
844 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
845 TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
846 }
847 }
848
849 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
850
851 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
852 }
853 #endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
854
855 static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block)
856 {
857 if (static_block)
858 tdefl_start_static_block(d);
859 else
860 tdefl_start_dynamic_block(d);
861 return tdefl_compress_lz_codes(d);
862 }
863
864 static int tdefl_flush_block(tdefl_compressor *d, int flush)
865 {
866 mz_uint saved_bit_buf, saved_bits_in;
867 mz_uint8 *pSaved_output_buf;
868 mz_bool comp_block_succeeded = MZ_FALSE;
869 int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
870 mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf;
871
872 d->m_pOutput_buf = pOutput_buf_start;
873 d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;
874
875 MZ_ASSERT(!d->m_output_flush_remaining);
876 d->m_output_flush_ofs = 0;
877 d->m_output_flush_remaining = 0;
878
879 *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
880 d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
881
882 if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index))
883 {
884 TDEFL_PUT_BITS(0x78, 8); TDEFL_PUT_BITS(0x01, 8);
885 }
886
887 TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1);
888
889 pSaved_output_buf = d->m_pOutput_buf; saved_bit_buf = d->m_bit_buffer; saved_bits_in = d->m_bits_in;
890
891 if (!use_raw_block)
892 comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48));
893
894 // If the block gets expanded, forget the current contents of the output buffer and send a raw block instead.
895 if ( ((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
896 ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size) )
897 {
898 mz_uint i; d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
899 TDEFL_PUT_BITS(0, 2);
900 if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); }
901 for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF)
902 {
903 TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16);
904 }
905 for (i = 0; i < d->m_total_lz_bytes; ++i)
906 {
907 TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8);
908 }
909 }
910 // Check for the extremely unlikely (if not impossible) case of the compressed block not fitting into the output buffer when using dynamic codes.
911 else if (!comp_block_succeeded)
912 {
913 d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
914 tdefl_compress_block(d, MZ_TRUE);
915 }
916
917 if (flush)
918 {
919 if (flush == TDEFL_FINISH)
920 {
921 if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); }
922 if (d->m_flags & TDEFL_WRITE_ZLIB_HEADER) { mz_uint i, a = d->m_adler32; for (i = 0; i < 4; i++) { TDEFL_PUT_BITS((a >> 24) & 0xFF, 8); a <<= 8; } }
923 }
924 else
925 {
926 mz_uint i, z = 0; TDEFL_PUT_BITS(0, 3); if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); } for (i = 2; i; --i, z ^= 0xFFFF) { TDEFL_PUT_BITS(z & 0xFFFF, 16); }
927 }
928 }
929
930 MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end);
931
932 memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
933 memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
934
935 d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8; d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes; d->m_total_lz_bytes = 0; d->m_block_index++;
936
937 if ((n = (int)(d->m_pOutput_buf - pOutput_buf_start)) != 0)
938 {
939 if (d->m_pPut_buf_func)
940 {
941 *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf;
942 if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
943 return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED);
944 }
945 else if (pOutput_buf_start == d->m_output_buf)
946 {
947 int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
948 memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
949 d->m_out_buf_ofs += bytes_to_copy;
950 if ((n -= bytes_to_copy) != 0)
951 {
952 d->m_output_flush_ofs = bytes_to_copy;
953 d->m_output_flush_remaining = n;
954 }
955 }
956 else
957 {
958 d->m_out_buf_ofs += n;
959 }
960 }
961
962 return d->m_output_flush_remaining;
963 }
964
965 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
966 #define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p)
967 static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
968 {
969 mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
970 mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
971 const mz_uint16 *s = (const mz_uint16*)(d->m_dict + pos), *p, *q;
972 mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD(s);
973 MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return;
974 for ( ; ; )
975 {
976 for ( ; ; )
977 {
978 if (--num_probes_left == 0) return;
979 #define TDEFL_PROBE \
980 next_probe_pos = d->m_next[probe_pos]; \
981 if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
982 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
983 if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break;
984 TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE;
985 }
986 if (!dist) break; q = (const mz_uint16*)(d->m_dict + probe_pos); if (TDEFL_READ_UNALIGNED_WORD(q) != s01) continue; p = s; probe_len = 32;
987 do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
988 (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) );
989 if (!probe_len)
990 {
991 *pMatch_dist = dist; *pMatch_len = MZ_MIN(max_match_len, TDEFL_MAX_MATCH_LEN); break;
992 }
993 else if ((probe_len = ((mz_uint)(p - s) * 2) + (mz_uint)(*(const mz_uint8*)p == *(const mz_uint8*)q)) > match_len)
994 {
995 *pMatch_dist = dist; if ((*pMatch_len = match_len = MZ_MIN(max_match_len, probe_len)) == max_match_len) break;
996 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]);
997 }
998 }
999 }
1000 #else
1001 static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
1002 {
1003 mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
1004 mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
1005 const mz_uint8 *s = d->m_dict + pos, *p, *q;
1006 mz_uint8 c0 = d->m_dict[pos + match_len], c1 = d->m_dict[pos + match_len - 1];
1007 MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return;
1008 for ( ; ; )
1009 {
1010 for ( ; ; )
1011 {
1012 if (--num_probes_left == 0) return;
1013 #define TDEFL_PROBE \
1014 next_probe_pos = d->m_next[probe_pos]; \
1015 if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
1016 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
1017 if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) break;
1018 TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE;
1019 }
1020 if (!dist) break; p = s; q = d->m_dict + probe_pos; for (probe_len = 0; probe_len < max_match_len; probe_len++) if (*p++ != *q++) break;
1021 if (probe_len > match_len)
1022 {
1023 *pMatch_dist = dist; if ((*pMatch_len = match_len = probe_len) == max_match_len) return;
1024 c0 = d->m_dict[pos + match_len]; c1 = d->m_dict[pos + match_len - 1];
1025 }
1026 }
1027 }
1028 #endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
1029
1030 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
1031 static mz_bool tdefl_compress_fast(tdefl_compressor *d)
1032 {
1033 // Faster, minimally featured LZRW1-style match+parse loop with better register utilization. Intended for applications where raw throughput is valued more highly than ratio.
1034 mz_uint lookahead_pos = d->m_lookahead_pos, lookahead_size = d->m_lookahead_size, dict_size = d->m_dict_size, total_lz_bytes = d->m_total_lz_bytes, num_flags_left = d->m_num_flags_left;
1035 mz_uint8 *pLZ_code_buf = d->m_pLZ_code_buf, *pLZ_flags = d->m_pLZ_flags;
1036 mz_uint cur_pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK;
1037
1038 while ((d->m_src_buf_left) || ((d->m_flush) && (lookahead_size)))
1039 {
1040 const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096;
1041 mz_uint dst_pos = (lookahead_pos + lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK;
1042 mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(d->m_src_buf_left, TDEFL_COMP_FAST_LOOKAHEAD_SIZE - lookahead_size);
1043 d->m_src_buf_left -= num_bytes_to_process;
1044 lookahead_size += num_bytes_to_process;
1045
1046 while (num_bytes_to_process)
1047 {
1048 mz_uint32 n = MZ_MIN(TDEFL_LZ_DICT_SIZE - dst_pos, num_bytes_to_process);
1049 memcpy(d->m_dict + dst_pos, d->m_pSrc, n);
1050 if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
1051 memcpy(d->m_dict + TDEFL_LZ_DICT_SIZE + dst_pos, d->m_pSrc, MZ_MIN(n, (TDEFL_MAX_MATCH_LEN - 1) - dst_pos));
1052 d->m_pSrc += n;
1053 dst_pos = (dst_pos + n) & TDEFL_LZ_DICT_SIZE_MASK;
1054 num_bytes_to_process -= n;
1055 }
1056
1057 dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - lookahead_size, dict_size);
1058 if ((!d->m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE)) break;
1059
1060 while (lookahead_size >= 4)
1061 {
1062 mz_uint cur_match_dist, cur_match_len = 1;
1063 mz_uint8 *pCur_dict = d->m_dict + cur_pos;
1064 mz_uint first_trigram = (*(const mz_uint32 *)pCur_dict) & 0xFFFFFF;
1065 mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK;
1066 mz_uint probe_pos = d->m_hash[hash];
1067 d->m_hash[hash] = (mz_uint16)lookahead_pos;
1068
1069 if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((*(const mz_uint32 *)(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram))
1070 {
1071 const mz_uint16 *p = (const mz_uint16 *)pCur_dict;
1072 const mz_uint16 *q = (const mz_uint16 *)(d->m_dict + probe_pos);
1073 mz_uint32 probe_len = 32;
1074 do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(// TODO: Ifhe raw deflate data (problem dithere's no more input, and we attempt to read beyond the input buf,
1075 {
1076 *pMatch_dis with the input because_capacity = 128;ver
1077 // reads ahead more than it needs to. Currently TINFL_GET_BYTE() pads
1078 }
1079
1080 int mz_deflastream with 0's in this scenario.GNED_WORD(++p) == TDEFifD_UNALIGNEDfor ( ; ; ) { \
1081 r" }, { MZ_PARAM_ERROR, "parametHAS_MORE_INPUT) { \
1082 ) << num_bits); num_bitsstate_index, memcpy(d->m_dict + dst_pos, \
1083 if (pIn_buf_cur < pIn_buf_end) { \
1084 c = *pIn_buf_cur++; \, { MZ_BUF_ERROR, \
1085 n} \
1086 m.avail_out = (mz_uint c = 0; \
1087 break; \) );
1088 cur_match_le }, { MZ_PARAM_ERROR, "parametHAS_MORE_INPUTr1);
1089 counter = (((r->mTINFL_CR_RETURN(38, memcpy(d->m_dict + dst_pos, if (decomp_flags *)(d->m_dict + probe_po4 particularly important on raTPUT); }
1090 while (pI expects the decompressor to never read
1091 // beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully
1092 // decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32.
1093 // The slow path is only executed at the very end of the input buffer.
1094 #define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \
1095 int temp; mz_uint code_len, c; \
1096 if (num_bits < 15) { \
1097 if ((pIn_buf_end - pIn_buf_cur) < 2) { \
1098 TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
1099 } else { \
1100 bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \
1101 } \
1102 } \
1103 if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
1104 code_len = temp >> 9, temp &= 511; \
1105 else { \
1106 code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \
1107 } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END
1108
1109 tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags)
1110 {
1111 static const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 };
1112 static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
1113 static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
1114 static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
1115 static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
1116 static const int s_min_table_sizes[3] = { 257, 1, 4 };
1117
1118 tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf;
1119 const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
1120 mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
1121 size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
1122
1123 // Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter).
1124 if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; }
1125
1126 num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start;
1127 TINFL_CR_BEGIN
1128
1129 bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1;
1130 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
1131 {
1132 TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1);
1133 counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
1134 if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
1135 if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); }
1136 }
1137
1138 do
1139 {
1140 TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1;
1141 if (r->m_type == 0)
1142 {
1143 TINFL_SKIP_BITS(5, num_bits & 7);
1144 for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); }
1145 if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); }
1146 while ((counter) && (num_bits))
1147 {
1148 TINFL_GET_BITS(51, dist, 8);
1149 while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); }
1150 *pOut_buf_cur++ = (mz_uint8)dist;
1151 counter--;
1152 }
1153 while (counter)
1154 {
1155 size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); }
1156 while (pIn_buf_cur >= pIn_buf_end)
1157 {
1158 if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT)
1159 {
1160 TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT);
1161 }
1162 else
1163 {
1164 TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED);
1165 }
1166 }
1167 n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter);
1168 TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n;
1169 }
1170 }
1171 else if (r->m_type == 3)
1172 {
1173 TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
1174 }
1175 else
1176 {
1177 if (r->m_type == 1)
1178 {
1179 mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i;
1180 r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
1181 for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
1182 }
1183 else
1184 {
1185 for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
1186 MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
1187 r->m_table_sizes[2] = 19;
1188 }
1189 for ( ; (int)r->m_type >= 0; r->m_type--)
1190 {
1191 int tree_next, tree_cur; tinfl_huff_table *pTable;
1192 mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree);
1193 for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
1194 used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
1195 for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
1196 if ((65536 != total) && (used_syms > 1))
1197 {
1198 TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
1199 }
1200 for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
1201 {
1202 mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue;
1203 cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
1204 if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; }
1205 if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
1206 rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
1207 for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
1208 {
1209 tree_cur -= ((rev_code >>= 1) & 1);
1210 if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1];
1211 }
1212 tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
1213 }
1214 if (r->m_type == 2)
1215 {
1216 for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); )
1217 {
1218 mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; }
1219 if ((dist == 16) && (!counter))
1220 {
1221 TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED);
1222 }
1223 num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16];
1224 TINFL_MEMSET(r->m_len_codes + counter, (disr" }, { MZ_PARAM_ERROR, "parameter error" }
1225 };
1226 mz_uint i; forSKIP_BITS(32, num_bits & 7);result) do { for (pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
1227 *pOut_buf_cur++ = (mz_uint8)counter;
1228 }
1229 else
1230 z_uint code_len;
1231 #if TINFL_USE_64BINFL_GET_BITS(18, s, n_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s;
1232 }
1233 if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
1234 {
1235 TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
1236 }
1237 TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
1238 }
1239 }
1240 for ( ; ; )
1241 {
1242 mz_uint8 *pSrc;
1243 for ( ; ; )
1244 {
1245 if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
1246 {
1247 TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
1248 if (counter >= 256)
1249 break;
1250 while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
1251 *pOut_buf_cur++ = (mz_uint8)counter;
1252 }
1253 else
1254 {
1255 int sym2; mz_uint code_len;
1256 #if TINFL_USE_64BIT_BITBUF
1257 if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; }
1258 #else
1259 if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
1260 #endif
1261 if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
1262 code_len = sym2 >> 9;
1263 else
1264 {
1265 code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
1266 }
1267 counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
1268 if (counter & 256)
1269 break;
1270
1271 #if !TINFL_USE_64BIT_BITBUF
1272 if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
1273 #endif
1274 if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
1275 code_len = sym2 >> 9;
1276 else
1277 {
1278 code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
1279 }
1280 bit_buf >>= code_len; num_bits -= code_len;
1281
1282 pOut_buf_cur[0] = (mz_uint8)counter;
1283 if (sym2 & 256)
1284 {
1285 pOut_buf_cur++;
1286 counter = sym2;
1287 break;
1288 }
1289 pOut_buf_cur[1] = (mz_uint8)sym2;
1290 pOut_buf_cur += 2;
1291 }
1292 }
1293 if ((counter &= 511) == 256) break;
1294
1295 num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
1296 if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
1297
1298 TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
1299 num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
1300 if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
1301
1302 dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
1303 if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
1304 {
1305 TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
1306 }
1307
1308 pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
1309
1310 if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
1311 {
1312 while (counter--)
1313 {
1314 while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); }
1315 *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
1316 }
1317 continue;
1318 }
1319 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
1320 else if ((counter >= 9) && (counter <= dist))
1321 {
1322 const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
1323 do
1324 {
1325 ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
1326 ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
1327 pOut_buf_cur += 8;
1328 } while ((pSrc += 8) < pSrc_end);
1329 if ((counter &= 7) < 3)
1330 {
1331 if (counter)
1332 {
1333 pOut_buf_cur[0] = pSrc[0];
1334 if (counter > 1)
1335 pOut_buf_cur[1] = pSrc[1];
1336 pOut_buf_cur += counter;
1337 }
1338 continue;
1339 }
1340 }
1341 #endif
1342 do
1343 {
1344 pOut_buf_cur[0] = pSrc[0];
1345 pOut_buf_cur[1] = pSrc[1];
1346 pOut_buf_cur[2] = pSrc[2];
1347 pOut_buf_cur += 3; pSrc += 3;
1348 } while ((int)(counter -= 3) > 2);
1349 if ((int)counter > 0)
1350 {
1351 pOut_buf_cur[0] = pSrc[0];
1352 if ((int)counter > 1)
1353 pOut_buf_cur[1] = pSrc[1];
1354 pOut_buf_cur += counter;
1355 }
1356 }
1357 }
1358 } while (!(r->m_final & 1));
1359 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
1360 {
1361 TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; }
1362 }
1363 TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE);
1364 TINFL_CR_FINISH
1365
1366 common_exit:
1367 r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start;
1368 *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
1369 if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
1370 {
1371 const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size;
1372 mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552;
1373 while (buf_len)
1374 {
1375 for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
1376 {
1377 s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
1378 s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
1379 }
1380 for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
1381 s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
1382 }
1383 r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH;
1384 }
1385 return status;
1386 }
1387
1388 // Higher level helper functions.
1389 void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
1390 {
1391 tinfl_decompressor decomp; void *pBuf = NULL, *pNew_buf; size_t src_buf_ofs = 0, out_buf_capacity = 0;
1392 *pOut_len = 0;
1393 tinfl_init(&decomp);
1394 for ( ; ; )
1395 {
1396 size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
1397 tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size,
1398 (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
1399 if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
1400 {
1401 MZ_FREE(pBuf); *pOut_len = 0; return NULL;
1402 }
1403 src_buf_ofs += src_buf_size;
1404 *pOut_len += dst_buf_size;
1405 if (status == TINFL_STATUS_DONE) break;
1406 new_out_buf_capacity = out_buf_capacity * 2; if (new_out_buf_capacity < 128) new_out_buf_capacity = 128;
1407 pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity);
1408 if (!pNew_buf)
1409 {
1410 MZ_FREE(pBuf); *pOut_len = 0; return NULL;
1411 }
1412 pBuf = pNew_buf; out_buf_capacity = new_out_buf_capacity;
1413 }
1414 return pBuf;
1415 }
1416
1417 size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
1418 {
1419 tinfl_decompressor decomp; tinfl_status status; tinfl_init(&decomp);
1420 status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf, &src_buf_len, (mz_uint8*)pOut_buf, (mz_uint8*)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
1421 return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len;
1422 }
1423
1424 int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
1425 {
1426 int result = 0;
1427 tinfl_decompressor decomp;
1428 mz_uint8 *pDict = (mz_uint8*)MZ_MALLOC(TINFL_LZ_DICT_SIZE); size_t in_buf_ofs = 0, dict_ofs = 0;
1429 if (!pDict)
1430 return TINFL_STATUS_FAILED;
1431 tinfl_init(&decomp);
1432 for ( ; ; )
1433 {
1434 size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
1435 tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size,
1436 (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
1437 in_buf_ofs += in_buf_size;
1438 if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user)))
1439 break;
1440 if (status != TINFL_STATUS_HAS_MORE_OUTPUT)
1441 {
1442 result = (status == TINFL_STATUS_DONE);
1443 break;
1444 }
1445 dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1);
1446 }
1447 MZ_FREE(pDict);
1448 *pIn_buf_size = in_buf_ofs;
1449 return result;
1450 }
1451
1452 // ------------------- Low-level Compression (independent from all decompression API's)
1453
1454 // Purposely making these tables static for faster init and thread safety.
1455 static const mz_uint16 s_tdefl_len_sym[256] = {
1456 257,258,259,260,261,262,263,264,265,265,266,266,267,267,268,268,269,269,269,269,270,270,270,270,271,271,271,271,272,272,272,272,
1457 273,273,273,273,273,273,273,273,274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,276,
1458 277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
1459 279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,
1460 281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,
1461 282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,
1462 283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,
1463 284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,285 };
1464
1465 static const mz_uint8 s_tdefl_len_extra[256] = {
1466 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
1467 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
1468 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1469 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0 };
1470
1471 static const mz_uint8 s_tdefl_small_dist_sym[512] = {
1472 0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
1473 11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,
1474 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,
1475 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
1476 14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
1477 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,
1478 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1479 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1480 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1481 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1482 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1483 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17 };
1484
1485 static const mz_uint8 s_tdefl_small_dist_extra[512] = {
1486 0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
1487 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1488 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1489 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1490 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1491 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1492 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1493 7,7,7,7,7,7,7,7 };
1494
1495 static const mz_uint8 s_tdefl_large_dist_sym[128] = {
1496 0,0,18,19,20,20,21,21,22,22,22,22,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,
1497 26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
1498 28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 };
1499
1500 static const mz_uint8 s_tdefl_large_dist_extra[128] = {
1501 0,0,8,8,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
1502 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
1503 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13 };
1504
1505 // Radix sorts tdefl_sym_freq[] array by 16-bit key m_key. Returns ptr to sorted values.
1506 typedef struct { mz_uint16 m_key, m_sym_index; } tdefl_sym_freq;
1507 static tdefl_sym_freq* tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq* pSyms0, tdefl_sym_freq* pSyms1)
1508 {
1509 mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; tdefl_sym_freq* pCur_syms = pSyms0, *pNew_syms = pSyms1; MZ_CLEAR_OBJ(hist);
1510 for (i = 0; i < num_syms; i++) { mz_uint freq = pSyms0[i].m_key; hist[freq & 0xFF]++; hist[256 + ((freq >> 8) & 0xFF)]++; }
1511 while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--;
1512 for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
1513 {
1514 const mz_uint32* pHist = &hist[pass << 8];
1515 mz_uint offsets[256], cur_ofs = 0;
1516 for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; }
1517 for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
1518 { tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; }
1519 }
1520 return pCur_syms;
1521 }
1522
1523 // tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, [email protected], Jyrki Katajainen, [email protected], November 1996.
1524 static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
1525 {
1526 int root, leaf, next, avbl, used, dpth;
1527 if (n==0) return; else if (n==1) { A[0].m_key = 1; return; }
1528 A[0].m_key += A[1].m_key; root = 0; leaf = 2;
1529 for (next=1; next < n-1; next++)
1530 {
1531 if (leaf>=n || A[root].m_key<A[leaf].m_key) { A[next].m_key = A[root].m_key; A[root++].m_key = (mz_uint16)next; } else A[next].m_key = A[leaf++].m_key;
1532 if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key); A[root++].m_key = (mz_uint16)next; } else A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
1533 }
1534 A[n-2].m_key = 0; for (next=n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1;
1535 avbl = 1; used = dpth = 0; root = n-2; next = n-1;
1536 while (avbl>0)
1537 {
1538 while (root>=0 && (int)A[root].m_key==dpth) { used++; root--; }
1539 while (avbl>used) { A[next--].m_key = (mz_uint16)(dpth); avbl--; }
1540 avbl = 2*used; dpth++; used = 0;
1541 }
1542 }
1543
1544 // Limits canonical Huffman code table's max code size.
1545 enum { TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32 };
1546 static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size)
1547 {
1548 int i; mz_uint32 total = 0; if (code_list_len <= 1) return;
1549 for (i = max_code_size + 1; i <= TDEFL_MAX_SUPPORTED_HUFF_CODESIZE; i++) pNum_codes[max_code_size] += pNum_codes[i];
1550 for (i = max_code_size; i > 0; i--) total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i));
1551 while (total != (1UL << max_code_size))
1552 {
1553 pNum_codes[max_code_size]--;
1554 for (i = max_code_size - 1; i > 0; i--) if (pNum_codes[i]) { pNum_codes[i]--; pNum_codes[i + 1] += 2; break; }
1555 total--;
1556 }
1557 }
1558
1559 static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table)
1560 {
1561 int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; MZ_CLEAR_OBJ(num_codes);
1562 if (static_table)
1563 {
1564 for (i = 0; i < table_len; i++) num_codes[d->m_huff_code_sizes[table_num][i]]++;
1565 }
1566 else
1567 {
1568 tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms;
1569 int num_used_syms = 0;
1570 const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0];
1571 for (i = 0; i < table_len; i++) if (pSym_count[i]) { syms0[num_used_syms].m_key = (mz_uint16)pSym_count[i]; syms0[num_used_syms++].m_sym_index = (mz_uint16)i; }
1572
1573 pSyms = tdefl_radix_sort_syms(num_used_syms, syms0, syms1); tdefl_calculate_minimum_redundancy(pSyms, num_used_syms);
1574
1575 for (i = 0; i < num_used_syms; i++) num_codes[pSyms[i].m_key]++;
1576
1577 tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit);
1578
1579 MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); MZ_CLEAR_OBJ(d->m_huff_codes[table_num]);
1580 for (i = 1, j = num_used_syms; i <= code_size_limit; i++)
1581 for (l = num_codes[i]; l > 0; l--) d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i);
1582 }
1583
1584 next_code[1] = 0; for (j = 0, i = 2; i <= code_size_limit; i++) next_code[i] = j = ((j + num_codes[i - 1]) << 1);
1585
1586 for (i = 0; i < table_len; i++)
1587 {
1588 mz_uint rev_code = 0, code, code_size; if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0) continue;
1589 code = next_code[code_size]++; for (l = code_size; l > 0; l--, code >>= 1) rev_code = (rev_code << 1) | (code & 1);
1590 d->m_huff_codes[table_num][i] = (mz_uint16)rev_code;
1591 }
1592 }
1593
1594 #define TDEFL_PUT_BITS(b, l) do { \
1595 mz_uint bits = b; mz_uint len = l; MZ_ASSERT(bits <= ((1U << len) - 1U)); \
1596 d->m_bit_buffer |= (bits << d->m_bits_in); d->m_bits_in += len; \
1597 while (d->m_bits_in >= 8) { \
1598 if (d->m_pOutput_buf < d->m_pOutput_buf_end) \
1599 *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \
1600 d->m_bit_buffer >>= 8; \
1601 d->m_bits_in -= 8; \
1602 } \
1603 } MZ_MACRO_END
1604
1605 #define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \
1606 if (rle_repeat_count < 3) { \
1607 d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \
1608 while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \
1609 } else { \
1610 d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \
1611 } rle_repeat_count = 0; } }
1612
1613 #define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \
1614 if (rle_z_count < 3) { \
1615 d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \
1616 } else if (rle_z_count <= 10) { \
1617 d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \
1618 } else { \
1619 d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \
1620 } rle_z_count = 0; } }
1621
1622 static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
1623
1624 static void tdefl_start_dynamic_block(tdefl_compressor *d)
1625 {
1626 int num_lit_codes, num_dist_codes, num_bit_lengths; mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index;
1627 mz_uint8 code_sizes_to_pack[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], packed_code_sizes[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], prev_code_size = 0xFF;
1628
1629 d->m_huff_count[0][256] = 1;
1630
1631 tdefl_optimize_huffman_table(d, 0, TDEFL_MAX_HUFF_SYMBOLS_0, 15, MZ_FALSE);
1632 tdefl_optimize_huffman_table(d, 1, TDEFL_MAX_HUFF_SYMBOLS_1, 15, MZ_FALSE);
1633
1634 for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--) if (d->m_huff_code_sizes[0][num_lit_codes - 1]) break;
1635 for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--) if (d->m_huff_code_sizes[1][num_dist_codes - 1]) break;
1636
1637 memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes);
1638 memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes);
1639 total_code_sizes_to_pack = num_lit_codes + num_dist_codes; num_packed_code_sizes = 0; rle_z_count = 0; rle_repeat_count = 0;
1640
1641 memset(&d->m_huff_count[2][0], 0, sizeof(d->m_huff_count[2][0]) * TDEFL_MAX_HUFF_SYMBOLS_2);
1642 for (i = 0; i < total_code_sizes_to_pack; i++)
1643 {
1644 mz_uint8 code_size = code_sizes_to_pack[i];
1645 if (!code_size)
1646 {
1647 TDEFL_RLE_PREV_CODE_SIZE();
1648 if (++rle_z_count == 138) { TDEFL_RLE_ZERO_CODE_SIZE(); }
1649 }
1650 else
1651 {
1652 TDEFL_RLE_ZERO_CODE_SIZE();
1653 if (code_size != prev_code_size)
1654 {
1655 TDEFL_RLE_PREV_CODE_SIZE();
1656 d->m_huff_count[2][code_size] = (mz_uint16)(d->m_huff_count[2][code_size] + 1); packed_code_sizes[num_packed_code_sizes++] = code_size;
1657 }
1658 else if (++rle_repeat_count == 6)
1659 {
1660 TDEFL_RLE_PREV_CODE_SIZE();
1661 }
1662 }
1663 prev_code_size = code_size;
1664 }
1665 if (rle_repeat_count) { TDEFL_RLE_PREV_CODE_SIZE(); } else { TDEFL_RLE_ZERO_CODE_SIZE(); }
1666
1667 tdefl_optimize_huffman_table(d, 2, TDEFL_MAX_HUFF_SYMBOLS_2, 7, MZ_FALSE);
1668
1669 TDEFL_PUT_BITS(2, 2);
1670
1671 TDEFL_PUT_BITS(num_lit_codes - 257, 5);
1672 TDEFL_PUT_BITS(num_dist_codes - 1, 5);
1673
1674 for (num_bit_lengths = 18; num_bit_lengths >= 0; num_bit_lengths--) if (d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[num_bit_lengths]]) break;
1675 num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1)); TDEFL_PUT_BITS(num_bit_lengths - 4, 4);
1676 for (i = 0; (int)i < num_bit_lengths; i++) TDEFL_PUT_BITS(d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[i]], 3);
1677
1678 for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes; )
1679 {
1680 mz_uint code = packed_code_sizes[packed_code_sizes_index++]; MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2);
1681 TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]);
1682 if (code >= 16) TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++], "\02\03\07"[code - 16]);
1683 }
1684 }
1685
1686 static void tdefl_start_static_block(tdefl_compressor *d)
1687 {
1688 mz_uint i;
1689 mz_uint8 *p = &d->m_huff_code_sizes[0][0];
1690
1691 for (i = 0; i <= 143; ++i) *p++ = 8;
1692 for ( ; i <= 255; ++i) *p++ = 9;
1693 for ( ; i <= 279; ++i) *p++ = 7;
1694 for ( ; i <= 287; ++i) *p++ = 8;
1695
1696 memset(d->m_huff_code_sizes[1], 5, 32);
1697
1698 tdefl_optimize_huffman_table(d, 0, 288, 15, MZ_TRUE);
1699 tdefl_optimize_huffman_table(d, 1, 32, 15, MZ_TRUE);
1700
1701 TDEFL_PUT_BITS(1, 2);
1702 }
1703
1704 static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
1705
1706 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
1707 static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
1708 {
1709 mz_uint flags;
1710 mz_uint8 *pLZ_codes;
1711 mz_uint8 *pOutput_buf = d->m_pOutput_buf;
1712 mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf;
1713 mz_uint64 bit_buffer = d->m_bit_buffer;
1714 mz_uint bits_in = d->m_bits_in;
1715
1716 #define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); }
1717
1718 flags = 1;
1719 for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1)
1720 {
1721 if (flags == 1)
1722 flags = *pLZ_codes++ | 0x100;
1723
1724 if (flags & 1)
1725 {
1726 mz_uint s0, s1, n0, n1, sym, num_extra_bits;
1727 mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3;
1728
1729 MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
1730 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
1731 TDEFL_PUT_BITS_FAST(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
1732
1733 // This sequence coaxes MSVC into using cmov's vs. jmp's.
1734 s0 = s_tdefl_small_dist_sym[match_dist & 511];
1735 n0 = s_tdefl_small_dist_extra[match_dist & 511];
1736 s1 = s_tdefl_large_dist_sym[match_dist >> 8];
1737 n1 = s_tdefl_large_dist_extra[match_dist >> 8];
1738 sym = (match_dist < 512) ? s0 : s1;
1739 num_extra_bits = (match_dist < 512) ? n0 : n1;
1740
1741 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1742 TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1743 TDEFL_PUT_BITS_FAST(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
1744 }
1745 else
1746 {
1747 mz_uint lit = *pLZ_codes++;
1748 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1749 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1750
1751 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
1752 {
1753 flags >>= 1;
1754 lit = *pLZ_codes++;
1755 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1756 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1757
1758 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
1759 {
1760 flags >>= 1;
1761 lit = *pLZ_codes++;
1762 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1763 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1764 }
1765 }
1766 }
1767
1768 if (pOutput_buf >= d->m_pOutput_buf_end)
1769 return MZ_FALSE;
1770
1771 *(mz_uint64*)pOutput_buf = bit_buffer;
1772 pOutput_buf += (bits_in >> 3);
1773 bit_buffer >>= (bits_in & ~7);
1774 bits_in &= 7;
1775 }
1776
1777 #undef TDEFL_PUT_BITS_FAST
1778
1779 d->m_pOutput_buf = pOutput_buf;
1780 d->m_bits_in = 0;
1781 d->m_bit_buffer = 0;
1782
1783 while (bits_in)
1784 {
1785 mz_uint32 n = MZ_MIN(bits_in, 16);
1786 TDEFL_PUT_BITS((mz_uint)bit_buffer & mz_bitmasks[n], n);
1787 bit_buffer >>= n;
1788 bits_in -= n;
1789 }
1790
1791 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1792
1793 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1794 }
1795 #else
1796 static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
1797 {
1798 mz_uint flags;
1799 mz_uint8 *pLZ_codes;
1800
1801 flags = 1;
1802 for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1)
1803 {
1804 if (flags == 1)
1805 flags = *pLZ_codes++ | 0x100;
1806 if (flags & 1)
1807 {
1808 mz_uint sym, num_extra_bits;
1809 mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); pLZ_codes += 3;
1810
1811 MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
1812 TDEFL_PUT_BITS(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
1813 TDEFL_PUT_BITS(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
1814
1815 if (match_dist < 512)
1816 {
1817 sym = s_tdefl_small_dist_sym[match_dist]; num_extra_bits = s_tdefl_small_dist_extra[match_dist];
1818 }
1819 else
1820 {
1821 sym = s_tdefl_large_dist_sym[match_dist >> 8]; num_extra_bits = s_tdefl_large_dist_extra[match_dist >> 8];
1822 }
1823 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1824 TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1825 TDEFL_PUT_BITS(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
1826 }
1827 else
1828 {
1829 mz_uint lit = *pLZ_codes++;
1830 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1831 TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1832 }
1833 }
1834
1835 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1836
1837 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1838 }
1839 #endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
1840
1841 static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block)
1842 {
1843 if (static_block)
1844 tdefl_start_static_block(d);
1845 else
1846 tdefl_start_dynamic_block(d);
1847 return tdefl_compress_lz_codes(d);
1848 }
1849
1850 static int tdefl_flush_block(tdefl_compressor *d, int flush)
1851 {
1852 mz_uint saved_bit_buf, saved_bits_in;
1853 mz_uint8 *pSaved_output_buf;
1854 mz_bool comp_block_succeeded = MZ_FALSE;
1855 int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
1856 mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf;
1857
1858 d->m_pOutput_buf = pOutput_buf_start;
1859 d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;
1860
1861 MZ_ASSERT(!d->m_output_flush_remaining);
1862 d->m_output_flush_ofs = 0;
1863 d->m_output_flush_remaining = 0;
1864
1865 *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
1866 d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
1867
1868 if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index))
1869 {
1870 TDEFL_PUT_BITS(0x78, 8); TDEFL_PUT_BITS(0x01, 8);
1871 }
1872
1873 TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1);
1874
1875 pSaved_output_buf = d->m_pOutput_buf; saved_bit_buf = d->m_bit_buffer; saved_bits_in = d->m_bits_in;
1876
1877 if (!use_raw_block)
1878 comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48));
1879
1880 // If the block gets expanded, forget the current contents of the output buffer and send a raw block instead.
1881 if ( ((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
1882 ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size) )
1883 {
1884 mz_uint i; d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
1885 TDEFL_PUT_BITS(0, 2);
1886 if (d->m_bits_in) { TDEFL_PUT_BITS(0, /* miniz.c v1.16 beta r1 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
1887 See "unlicense" statement at the end of this file.
1888 Rich Geldreich <[email protected]>, last updated Oct. 13, 2013
1889 Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
1890
1891 Most API's defined in miniz.c are optionaljority of prev. users so I'm
1892 op)w deflate data (pr/* matic const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 };
1893 static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
1894 static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
1895 static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
1896 static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
1897 static const int s_min_table_sizes[3] = { 257, 1, 4 };
1898
1899 tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf;
1900 const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
1901 mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
1902 size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
1903
1904 // Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter).
1905 if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; }
1906
1907 num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start;
1908 TINFL_CR_BEGIN
1909
1910 bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1;
1911 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
1912 {
1913 TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1);
1914 counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
1915 if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
1916 if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); }
1917 }
1918
1919 do
1920 {
1921 TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1;
1922 if (r->m_type == 0)
1923 {
1924 TINFL_SKIP_BITS(5, num_bits & 7);
1925 for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); }
1926 if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); }
1927 while ((counter) && (num_bits))
1928 {
1929 TINFL_GET_BITS(51, dist, 8);
1930 while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); }
1931 *pOut_buf_cur++ = (mz_uint8)dist;
1932 counter--;
1933 }
1934 while (counter)
1935 {
1936 size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); }
1937 while (pIn_buf_cur >= pIn_buf_end)
1938 {
1939 if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT)
1940 {
1941 TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT);
1942 }
1943 else
1944 {
1945 TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED);
1946 }
1947 }
1948 n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter);
1949 TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n;
1950 }
1951 }
1952 else if (r->m_type == 3)
1953 {
1954 TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
1955 }
1956 else
1957 {
1958 if (r->m_type == 1)
1959 {
1960 mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i;
1961 r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
1962 for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
1963 }
1964 else
1965 {
1966 for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
1967 MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
1968 r->m_table_sizes[2] = 19;
1969 }
1970 for ( ; (int)r->m_type >= 0; r->m_type--)
1971 {
1972 int tree_next, tree_cur; tinfl_huff_table *pTable;
1973 mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree);
1974 for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
1975 used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
1976 for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
1977 if ((65536 != total) && (used_syms > 1))
1978 {
1979 TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
1980 }
1981 for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
1982 {
1983 mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue;
1984 cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
1985 if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; }
1986 if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
1987 rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
1988 for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
1989 {
1990 tree_cur -= ((rev_code >>= 1) & 1);
1991 if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1];
1992 }
1993 tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
1994 }
1995 if (r->m_type == 2)
1996 {
1997 for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); )
1998 {
1999 mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; }
2000 if ((dist == 16) && (!counter))
2001 {
2002 TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED);
2003 }
2004 num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16];
2005 TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s;
2006 }
2007 if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
2008 {
2009 TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
2010 }
2011 TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
2012 }
2013 }
2014 for ( ; ; )
2015 {
2016 mz_uint8 *pSrc;
2017 for ( ; ; )
2018 {
2019 if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
2020 {
2021 TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
2022 if (counter >= 256)
2023 break;
2024 while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
2025 *pOut_buf_cur++ = (mz_uint8)counter;
2026 }
2027 else
2028 {
2029 int sym2; mz_uint code_len;
2030 #if TINFL_USE_64BIT_BITBUF
2031 if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; }
2032 #else
2033 if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
2034 #endif
2035 if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
2036 code_len = sym2 >> 9;
2037 else
2038 {
2039 code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
2040 }
2041 counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
2042 if (counter & 256)
2043 break;
2044
2045 #if !TINFL_USE_64BIT_BITBUF
2046 if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
2047 #endif
2048 if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
2049 code_len = sym2 >> 9;
2050 else
2051 {
2052 code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
2053 }
2054 bit_buf >>= code_len; num_bits -= code_len;
2055
2056 pOut_buf_cur[0] = (mz_uint8)counter;
2057 if (sym2 & 256)
2058 {
2059 pOut_buf_cur++;
2060 counter = sym2;
2061 break;
2062 }
2063 pOut_buf_cur[1] = (mz_uint8)sym2;
2064 pOut_buf_cur += 2;
2065 }
2066 }
2067 if ((counter &= 511) == 256) break;
2068
2069 num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
2070 if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
2071
2072 TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
2073 num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
2074 if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
2075
2076 dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
2077 if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
2078 {
2079 TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
2080 }
2081
2082 pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
2083
2084 if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
2085 {
2086 while (counter--)
2087 {
2088 while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); }
2089 *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
2090 }
2091 continue;
2092 }
2093 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
2094 else if ((counter >= 9) && (counter <= dist))
2095 {
2096 const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
2097 do
2098 {
2099 ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
2100 ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
2101 pOut_buf_cur += 8;
2102 } while ((pSrc += 8) < pSrc_end);
2103 if ((counter &= 7) < 3)
2104 {
2105 if (counter)
2106 {
2107 pOut_buf_cur[0] = pSrc[0];
2108 if (counter > 1)
2109 pOut_buf_cur[1] = pSrc[1];
2110 pOut_buf_cur += counter;
2111 }
2112 continue;
2113 }
2114 }
2115 #endif
2116 do
2117 {
2118 pOut_buf_cur[0] = pSrc[0];
2119 pOut_buf_cur[1] = pSrc[1];
2120 pOut_buf_cur[2] = pSrc[2];
2121 pOut_buf_cur += 3; pSrc += 3;
2122 } while ((int)(counter -= 3) > 2);
2123 if ((int)counter > 0)
2124 {
2125 pOut_buf_cur[0] = pSrc[0];
2126 if ((int)counter > 1)
2127 pOut_buf_cur[1] = pSrc[1];
2128 pOut_buf_cur += counter;
2129 }
2130 }
2131 }
2132 } while (!(r->m_final & 1));
2133 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
2134 {
2135 TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; }
2136 }
2137 TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE);
2138 TINFL_CR_FINISH
2139
2140 common_exit:
2141 r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start;
2142 *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
2143 if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
2144 {
2145 const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size;
2146 mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552;
2147 while (buf_len)
2148 {
2149 for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
2150 {
2151 s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
2152 s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
2153 }
2154 for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
2155 s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
2156 }
2157 r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH;
2158 }
2159 return status;
2160 }
2161
2162 // Higher level helper functions.
2163 void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
2164 {
2165 tinfl_decompressor decomp; void *pBuf = NULL, *pNew_buf; size_t src_buf_ofs = 0, out_buf_capacity = 0;
2166 *pOut_len = 0;
2167 tinfl_init(&decomp);
2168 for ( ; ; )
2169 {
2170 size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
2171 tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size,
2172 (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
2173 if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
2174 {
2175 MZ_FREE(pBuf); *pOut_len = 0; return NULL;
2176 }
2177 src_buf_ofs += src_buf_size;
2178 *pOut_len += dst_buf_size;
2179 if (status == TINFL_STATUS_DONE) break;
2180 new_out_buf_capacity = out_buf_capacity * 2; if (new_out_buf_capacity < 128) new_out_buf_capacity = 128;
2181 pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity);
2182 if (!pNew_buf)
2183 {
2184 MZ_FREE(pBuf); *pOut_len = 0; return NULL;
2185 }
2186 pBuf = pNew_buf; out_buf_capacity = new_out_buf_capacity;
2187 }
2188 return pBuf;
2189 }
2190
2191 size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
2192 {
2193 tinfl_decompressor decomp; tinfl_status status; tinfl_init(&decomp);
2194 status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf, &src_buf_len, (mz_uint8*)pOut_buf, (mz_uint8*)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
2195 return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len;
2196 }
2197
2198 int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
2199 {
2200 int result = 0;
2201 tinfl_decompressor decomp;
2202 mz_uint8 *pDict = (mz_uint8*)MZ_MALLOC(TINFL_LZ_DICT_SIZE); size_t in_buf_ofs = 0, dict_ofs = 0;
2203 if (!pDict)
2204 return TINFL_STATUS_FAILED;
2205 tinfl_init(&decomp);
2206 for ( ; ; )
2207 {
2208 size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
2209 tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size,
2210 (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
2211 in_buf_ofs += in_buf_size;
2212 if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user)))
2213 break;
2214 if (status != TINFL_STATUS_HAS_MORE_OUTPUT)
2215 {
2216 result = (status == TINFL_STATUS_DONE);
2217 break;
2218 }
2219 dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1);
2220 }
2221 MZ_FREE(pDict);
2222 *pIn_buf_size = in_buf_ofs;
2223 return result;
2224 }
2225
2226 // ------------------- Low-level Compression (independent from all decompression API's)
2227
2228 // Purposely making these tables static for faster init and thread safety.
2229 static const mz_uint16 s_tdefl_len_sym[256] = {
2230 257,258,259,260,261,262,263,264,265,265,266,266,267,267,268,268,269,269,269,269,270,270,270,270,271,271,271,271,272,272,272,272,
2231 273,273,273,273,273,273,273,273,274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,276,
2232 277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
2233 279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,
2234 281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,
2235 282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,
2236 283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,
2237 284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,285 };
2238
2239 static const mz_uint8 s_tdefl_len_extra[256] = {
2240 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
2241 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
2242 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
2243 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0 };
2244
2245 static const mz_uint8 s_tdefl_small_dist_sym[512] = {
2246 0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
2247 11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,
2248 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,
2249 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
2250 14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
2251 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16
--- a/src/miniz.c
+++ b/src/miniz.c
@@ -1,2251 +0,0 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
+1 -6
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -20,16 +20,11 @@
2020
** is a copy of the "shell.c" code from SQLite. This file contains logic
2121
** to initialize the code in shell.c.
2222
*/
2323
#include "config.h"
2424
#include "sqlcmd.h"
25
-#if defined(FOSSIL_ENABLE_MINIZ)
26
-# define MINIZ_HEADER_FILE_ONLY
27
-# include "miniz.c"
28
-#else
29
-# include <zlib.h>
30
-#endif
25
+#include <zlib.h>
3126
3227
/*
3328
** Implementation of the "content(X)" SQL function. Return the complete
3429
** content of artifact identified by X as a blob.
3530
*/
3631
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -20,16 +20,11 @@
20 ** is a copy of the "shell.c" code from SQLite. This file contains logic
21 ** to initialize the code in shell.c.
22 */
23 #include "config.h"
24 #include "sqlcmd.h"
25 #if defined(FOSSIL_ENABLE_MINIZ)
26 # define MINIZ_HEADER_FILE_ONLY
27 # include "miniz.c"
28 #else
29 # include <zlib.h>
30 #endif
31
32 /*
33 ** Implementation of the "content(X)" SQL function. Return the complete
34 ** content of artifact identified by X as a blob.
35 */
36
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -20,16 +20,11 @@
20 ** is a copy of the "shell.c" code from SQLite. This file contains logic
21 ** to initialize the code in shell.c.
22 */
23 #include "config.h"
24 #include "sqlcmd.h"
25 #include <zlib.h>
 
 
 
 
 
26
27 /*
28 ** Implementation of the "content(X)" SQL function. Return the complete
29 ** content of artifact identified by X as a blob.
30 */
31
+1 -6
--- src/tar.c
+++ src/tar.c
@@ -17,16 +17,11 @@
1717
**
1818
** This file contains code used to generate tarballs.
1919
*/
2020
#include "config.h"
2121
#include <assert.h>
22
-#if defined(FOSSIL_ENABLE_MINIZ)
23
-# define MINIZ_HEADER_FILE_ONLY
24
-# include "miniz.c"
25
-#else
26
-# include <zlib.h>
27
-#endif
22
+#include <zlib.h>
2823
#include "tar.h"
2924
3025
/*
3126
** State information for the tarball builder.
3227
*/
3328
--- src/tar.c
+++ src/tar.c
@@ -17,16 +17,11 @@
17 **
18 ** This file contains code used to generate tarballs.
19 */
20 #include "config.h"
21 #include <assert.h>
22 #if defined(FOSSIL_ENABLE_MINIZ)
23 # define MINIZ_HEADER_FILE_ONLY
24 # include "miniz.c"
25 #else
26 # include <zlib.h>
27 #endif
28 #include "tar.h"
29
30 /*
31 ** State information for the tarball builder.
32 */
33
--- src/tar.c
+++ src/tar.c
@@ -17,16 +17,11 @@
17 **
18 ** This file contains code used to generate tarballs.
19 */
20 #include "config.h"
21 #include <assert.h>
22 #include <zlib.h>
 
 
 
 
 
23 #include "tar.h"
24
25 /*
26 ** State information for the tarball builder.
27 */
28
+1 -6
--- src/zip.c
+++ src/zip.c
@@ -17,16 +17,11 @@
1717
**
1818
** This file contains code used to generate ZIP archives.
1919
*/
2020
#include "config.h"
2121
#include <assert.h>
22
-#if defined(FOSSIL_ENABLE_MINIZ)
23
-# define MINIZ_HEADER_FILE_ONLY
24
-# include "miniz.c"
25
-#else
26
-# include <zlib.h>
27
-#endif
22
+#include <zlib.h>
2823
#include "zip.h"
2924
3025
/*
3126
** Write a 16- or 32-bit integer as little-endian into the given buffer.
3227
*/
3328
--- src/zip.c
+++ src/zip.c
@@ -17,16 +17,11 @@
17 **
18 ** This file contains code used to generate ZIP archives.
19 */
20 #include "config.h"
21 #include <assert.h>
22 #if defined(FOSSIL_ENABLE_MINIZ)
23 # define MINIZ_HEADER_FILE_ONLY
24 # include "miniz.c"
25 #else
26 # include <zlib.h>
27 #endif
28 #include "zip.h"
29
30 /*
31 ** Write a 16- or 32-bit integer as little-endian into the given buffer.
32 */
33
--- src/zip.c
+++ src/zip.c
@@ -17,16 +17,11 @@
17 **
18 ** This file contains code used to generate ZIP archives.
19 */
20 #include "config.h"
21 #include <assert.h>
22 #include <zlib.h>
 
 
 
 
 
23 #include "zip.h"
24
25 /*
26 ** Write a 16- or 32-bit integer as little-endian into the given buffer.
27 */
28
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -89,14 +89,10 @@
8989
9090
#### Use 'system' SQLite
9191
#
9292
# USE_SYSTEM_SQLITE = 1
9393
94
-#### Use the miniz compression library
95
-#
96
-# FOSSIL_ENABLE_MINIZ = 1
97
-
9894
#### Use the Tcl source directory instead of the install directory?
9995
# This is useful when Tcl has been compiled statically with MinGW.
10096
#
10197
FOSSIL_TCL_SOURCE = 1
10298
@@ -128,18 +124,13 @@
128124
# used, taking into account whether zlib is actually enabled and the target
129125
# processor architecture.
130126
#
131127
ifndef X64
132128
SSLCONFIG = mingw
133
-ifndef FOSSIL_ENABLE_MINIZ
134129
ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
135130
LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
136131
else
137
-ZLIBCONFIG =
138
-LIBTARGETS =
139
-endif
140
-else
141132
SSLCONFIG = mingw64
142133
ZLIBCONFIG =
143134
LIBTARGETS =
144135
endif
145136
@@ -149,13 +140,11 @@
149140
SSLCONFIG += no-ssl2 no-ssl3 no-shared
150141
151142
#### When using zlib, make sure that OpenSSL is configured to use the zlib
152143
# that Fossil knows about (i.e. the one within the source tree).
153144
#
154
-ifndef FOSSIL_ENABLE_MINIZ
155145
SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
156
-endif
157146
158147
#### The directories where the OpenSSL include and library files are located.
159148
# The recommended usage here is to use the Sysinternals junction tool
160149
# to create a hard link between an "openssl-1.x" sub-directory of the
161150
# Fossil source code directory and the target OpenSSL source directory.
@@ -216,24 +205,19 @@
216205
TCC += -g
217206
else
218207
TCC += -Os
219208
endif
220209
221
-#### When not using the miniz compression library, zlib is required.
210
+#### zlib is required.
222211
#
223
-ifndef FOSSIL_ENABLE_MINIZ
224212
TCC += -L$(ZLIBDIR) -I$(ZINCDIR)
225
-endif
226213
227214
#### Compile resources for use in building executables that will run
228215
# on the target platform.
229216
#
230217
RCC = $(PREFIX)windres -I$(SRCDIR)
231
-
232
-ifndef FOSSIL_ENABLE_MINIZ
233218
RCC += -I$(ZINCDIR)
234
-endif
235219
236220
# With HTTPS support
237221
ifdef FOSSIL_ENABLE_SSL
238222
TCC += -L$(OPENSSLLIBDIR) -I$(OPENSSLINCDIR)
239223
RCC += -I$(OPENSSLINCDIR)
@@ -248,16 +232,10 @@
248232
TCC += -L$(TCLLIBDIR) -I$(TCLINCDIR)
249233
RCC += -I$(TCLINCDIR)
250234
endif
251235
endif
252236
253
-# With miniz (i.e. instead of zlib)
254
-ifdef FOSSIL_ENABLE_MINIZ
255
-TCC += -DFOSSIL_ENABLE_MINIZ=1
256
-RCC += -DFOSSIL_ENABLE_MINIZ=1
257
-endif
258
-
259237
# With MinGW command line handling workaround
260238
ifdef MINGW_IS_32BIT_ONLY
261239
TCC += -DBROKEN_MINGW_CMDLINE=1
262240
RCC += -DBROKEN_MINGW_CMDLINE=1
263241
endif
@@ -353,15 +331,13 @@
353331
# to link against the Z-Lib compression library. There are no
354332
# other mandatory dependencies.
355333
#
356334
LIB += -lmingwex
357335
358
-#### When not using the miniz compression library, zlib is required.
336
+#### zlib is required.
359337
#
360
-ifndef FOSSIL_ENABLE_MINIZ
361338
LIB += -lz
362
-endif
363339
364340
#### These libraries MUST appear in the same order as they do for Tcl
365341
# or linking with it will not work (exact reason unknown).
366342
#
367343
ifdef FOSSIL_ENABLE_TCL
@@ -852,16 +828,14 @@
852828
853829
all: $(OBJDIR) $(APPNAME)
854830
855831
$(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
856832
ifdef USE_WINDOWS
857
- $(CAT) $(subst /,\,$(SRCDIR)\miniz.c) | $(GREP) "define MZ_VERSION" > $(subst /,\,$(OBJDIR)\minizver.h)
858833
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
859834
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
860835
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
861836
else
862
- $(CAT) $(SRCDIR)/miniz.c | $(GREP) "define MZ_VERSION" > $(OBJDIR)/minizver.h
863837
$(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
864838
$(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
865839
$(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
866840
endif
867841
$(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
@@ -915,21 +889,13 @@
915889
# using -lsqlite3.
916890
SQLITE3_OBJ.1 =
917891
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
918892
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
919893
920
-# The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
921
-# set to 1. If it is set to 1, the miniz library included in the
922
-# source tree should be used; otherwise, it should not.
923
-MINIZ_OBJ.0 =
924
-MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
925
-MINIZ_OBJ. = $(MINIZ_OBJ.0)
926
-
927894
928895
EXTRAOBJ = \
929896
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
930
- $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
931897
$(OBJDIR)/shell.o \
932898
$(OBJDIR)/th.o \
933899
$(OBJDIR)/th_lang.o \
934900
$(OBJDIR)/th_tcl.o \
935901
$(OBJDIR)/cson_amalgamation.o
@@ -945,14 +911,11 @@
945911
$(TCC) -c -o $@ -DASMINF -I$(ZLIBDIR) -O3 $(ZLIBDIR)/contrib/inflate86/inffas86.c
946912
947913
$(ZLIBDIR)/match.o:
948914
$(TCC) -c -o $@ -DASMV $(ZLIBDIR)/contrib/asm686/match.S
949915
950
-
951
-ifndef FOSSIL_ENABLE_MINIZ
952916
LIBTARGETS += zlib
953
-endif
954917
955918
openssl: $(LIBTARGETS)
956919
cd $(OPENSSLLIBDIR);./Configure --cross-compile-prefix=$(PREFIX) $(SSLCONFIG)
957920
$(MAKE) -C $(OPENSSLLIBDIR) build_libs
958921
@@ -2108,14 +2071,10 @@
21082071
-Daccess=file_access \
21092072
-Dsystem=fossil_system \
21102073
-Dgetenv=fossil_getenv \
21112074
-Dfopen=fossil_fopen
21122075
2113
-MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
2114
- -DMINIZ_NO_TIME \
2115
- -DMINIZ_NO_ARCHIVE_APIS
2116
-
21172076
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
21182077
$(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
21192078
21202079
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
21212080
$(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
@@ -2132,8 +2091,5 @@
21322091
$(XTCC) -c $(SRCDIR)/th_lang.c -o $@
21332092
21342093
$(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
21352094
$(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
21362095
2137
-$(OBJDIR)/miniz.o: $(SRCDIR)/miniz.c
2138
- $(XTCC) $(MINIZ_OPTIONS) -c $(SRCDIR)/miniz.c -o $@
2139
-
21402096
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -89,14 +89,10 @@
89
90 #### Use 'system' SQLite
91 #
92 # USE_SYSTEM_SQLITE = 1
93
94 #### Use the miniz compression library
95 #
96 # FOSSIL_ENABLE_MINIZ = 1
97
98 #### Use the Tcl source directory instead of the install directory?
99 # This is useful when Tcl has been compiled statically with MinGW.
100 #
101 FOSSIL_TCL_SOURCE = 1
102
@@ -128,18 +124,13 @@
128 # used, taking into account whether zlib is actually enabled and the target
129 # processor architecture.
130 #
131 ifndef X64
132 SSLCONFIG = mingw
133 ifndef FOSSIL_ENABLE_MINIZ
134 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
135 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
136 else
137 ZLIBCONFIG =
138 LIBTARGETS =
139 endif
140 else
141 SSLCONFIG = mingw64
142 ZLIBCONFIG =
143 LIBTARGETS =
144 endif
145
@@ -149,13 +140,11 @@
149 SSLCONFIG += no-ssl2 no-ssl3 no-shared
150
151 #### When using zlib, make sure that OpenSSL is configured to use the zlib
152 # that Fossil knows about (i.e. the one within the source tree).
153 #
154 ifndef FOSSIL_ENABLE_MINIZ
155 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
156 endif
157
158 #### The directories where the OpenSSL include and library files are located.
159 # The recommended usage here is to use the Sysinternals junction tool
160 # to create a hard link between an "openssl-1.x" sub-directory of the
161 # Fossil source code directory and the target OpenSSL source directory.
@@ -216,24 +205,19 @@
216 TCC += -g
217 else
218 TCC += -Os
219 endif
220
221 #### When not using the miniz compression library, zlib is required.
222 #
223 ifndef FOSSIL_ENABLE_MINIZ
224 TCC += -L$(ZLIBDIR) -I$(ZINCDIR)
225 endif
226
227 #### Compile resources for use in building executables that will run
228 # on the target platform.
229 #
230 RCC = $(PREFIX)windres -I$(SRCDIR)
231
232 ifndef FOSSIL_ENABLE_MINIZ
233 RCC += -I$(ZINCDIR)
234 endif
235
236 # With HTTPS support
237 ifdef FOSSIL_ENABLE_SSL
238 TCC += -L$(OPENSSLLIBDIR) -I$(OPENSSLINCDIR)
239 RCC += -I$(OPENSSLINCDIR)
@@ -248,16 +232,10 @@
248 TCC += -L$(TCLLIBDIR) -I$(TCLINCDIR)
249 RCC += -I$(TCLINCDIR)
250 endif
251 endif
252
253 # With miniz (i.e. instead of zlib)
254 ifdef FOSSIL_ENABLE_MINIZ
255 TCC += -DFOSSIL_ENABLE_MINIZ=1
256 RCC += -DFOSSIL_ENABLE_MINIZ=1
257 endif
258
259 # With MinGW command line handling workaround
260 ifdef MINGW_IS_32BIT_ONLY
261 TCC += -DBROKEN_MINGW_CMDLINE=1
262 RCC += -DBROKEN_MINGW_CMDLINE=1
263 endif
@@ -353,15 +331,13 @@
353 # to link against the Z-Lib compression library. There are no
354 # other mandatory dependencies.
355 #
356 LIB += -lmingwex
357
358 #### When not using the miniz compression library, zlib is required.
359 #
360 ifndef FOSSIL_ENABLE_MINIZ
361 LIB += -lz
362 endif
363
364 #### These libraries MUST appear in the same order as they do for Tcl
365 # or linking with it will not work (exact reason unknown).
366 #
367 ifdef FOSSIL_ENABLE_TCL
@@ -852,16 +828,14 @@
852
853 all: $(OBJDIR) $(APPNAME)
854
855 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
856 ifdef USE_WINDOWS
857 $(CAT) $(subst /,\,$(SRCDIR)\miniz.c) | $(GREP) "define MZ_VERSION" > $(subst /,\,$(OBJDIR)\minizver.h)
858 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
859 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
860 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
861 else
862 $(CAT) $(SRCDIR)/miniz.c | $(GREP) "define MZ_VERSION" > $(OBJDIR)/minizver.h
863 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
864 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
865 $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
866 endif
867 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
@@ -915,21 +889,13 @@
915 # using -lsqlite3.
916 SQLITE3_OBJ.1 =
917 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
918 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
919
920 # The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
921 # set to 1. If it is set to 1, the miniz library included in the
922 # source tree should be used; otherwise, it should not.
923 MINIZ_OBJ.0 =
924 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
925 MINIZ_OBJ. = $(MINIZ_OBJ.0)
926
927
928 EXTRAOBJ = \
929 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
930 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
931 $(OBJDIR)/shell.o \
932 $(OBJDIR)/th.o \
933 $(OBJDIR)/th_lang.o \
934 $(OBJDIR)/th_tcl.o \
935 $(OBJDIR)/cson_amalgamation.o
@@ -945,14 +911,11 @@
945 $(TCC) -c -o $@ -DASMINF -I$(ZLIBDIR) -O3 $(ZLIBDIR)/contrib/inflate86/inffas86.c
946
947 $(ZLIBDIR)/match.o:
948 $(TCC) -c -o $@ -DASMV $(ZLIBDIR)/contrib/asm686/match.S
949
950
951 ifndef FOSSIL_ENABLE_MINIZ
952 LIBTARGETS += zlib
953 endif
954
955 openssl: $(LIBTARGETS)
956 cd $(OPENSSLLIBDIR);./Configure --cross-compile-prefix=$(PREFIX) $(SSLCONFIG)
957 $(MAKE) -C $(OPENSSLLIBDIR) build_libs
958
@@ -2108,14 +2071,10 @@
2108 -Daccess=file_access \
2109 -Dsystem=fossil_system \
2110 -Dgetenv=fossil_getenv \
2111 -Dfopen=fossil_fopen
2112
2113 MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
2114 -DMINIZ_NO_TIME \
2115 -DMINIZ_NO_ARCHIVE_APIS
2116
2117 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
2118 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
2119
2120 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
2121 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
@@ -2132,8 +2091,5 @@
2132 $(XTCC) -c $(SRCDIR)/th_lang.c -o $@
2133
2134 $(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
2135 $(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
2136
2137 $(OBJDIR)/miniz.o: $(SRCDIR)/miniz.c
2138 $(XTCC) $(MINIZ_OPTIONS) -c $(SRCDIR)/miniz.c -o $@
2139
2140
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -89,14 +89,10 @@
89
90 #### Use 'system' SQLite
91 #
92 # USE_SYSTEM_SQLITE = 1
93
 
 
 
 
94 #### Use the Tcl source directory instead of the install directory?
95 # This is useful when Tcl has been compiled statically with MinGW.
96 #
97 FOSSIL_TCL_SOURCE = 1
98
@@ -128,18 +124,13 @@
124 # used, taking into account whether zlib is actually enabled and the target
125 # processor architecture.
126 #
127 ifndef X64
128 SSLCONFIG = mingw
 
129 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
130 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
131 else
 
 
 
 
132 SSLCONFIG = mingw64
133 ZLIBCONFIG =
134 LIBTARGETS =
135 endif
136
@@ -149,13 +140,11 @@
140 SSLCONFIG += no-ssl2 no-ssl3 no-shared
141
142 #### When using zlib, make sure that OpenSSL is configured to use the zlib
143 # that Fossil knows about (i.e. the one within the source tree).
144 #
 
145 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
 
146
147 #### The directories where the OpenSSL include and library files are located.
148 # The recommended usage here is to use the Sysinternals junction tool
149 # to create a hard link between an "openssl-1.x" sub-directory of the
150 # Fossil source code directory and the target OpenSSL source directory.
@@ -216,24 +205,19 @@
205 TCC += -g
206 else
207 TCC += -Os
208 endif
209
210 #### zlib is required.
211 #
 
212 TCC += -L$(ZLIBDIR) -I$(ZINCDIR)
 
213
214 #### Compile resources for use in building executables that will run
215 # on the target platform.
216 #
217 RCC = $(PREFIX)windres -I$(SRCDIR)
 
 
218 RCC += -I$(ZINCDIR)
 
219
220 # With HTTPS support
221 ifdef FOSSIL_ENABLE_SSL
222 TCC += -L$(OPENSSLLIBDIR) -I$(OPENSSLINCDIR)
223 RCC += -I$(OPENSSLINCDIR)
@@ -248,16 +232,10 @@
232 TCC += -L$(TCLLIBDIR) -I$(TCLINCDIR)
233 RCC += -I$(TCLINCDIR)
234 endif
235 endif
236
 
 
 
 
 
 
237 # With MinGW command line handling workaround
238 ifdef MINGW_IS_32BIT_ONLY
239 TCC += -DBROKEN_MINGW_CMDLINE=1
240 RCC += -DBROKEN_MINGW_CMDLINE=1
241 endif
@@ -353,15 +331,13 @@
331 # to link against the Z-Lib compression library. There are no
332 # other mandatory dependencies.
333 #
334 LIB += -lmingwex
335
336 #### zlib is required.
337 #
 
338 LIB += -lz
 
339
340 #### These libraries MUST appear in the same order as they do for Tcl
341 # or linking with it will not work (exact reason unknown).
342 #
343 ifdef FOSSIL_ENABLE_TCL
@@ -852,16 +828,14 @@
828
829 all: $(OBJDIR) $(APPNAME)
830
831 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
832 ifdef USE_WINDOWS
 
833 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
834 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
835 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
836 else
 
837 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
838 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
839 $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
840 endif
841 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
@@ -915,21 +889,13 @@
889 # using -lsqlite3.
890 SQLITE3_OBJ.1 =
891 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
892 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
893
 
 
 
 
 
 
 
894
895 EXTRAOBJ = \
896 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
 
897 $(OBJDIR)/shell.o \
898 $(OBJDIR)/th.o \
899 $(OBJDIR)/th_lang.o \
900 $(OBJDIR)/th_tcl.o \
901 $(OBJDIR)/cson_amalgamation.o
@@ -945,14 +911,11 @@
911 $(TCC) -c -o $@ -DASMINF -I$(ZLIBDIR) -O3 $(ZLIBDIR)/contrib/inflate86/inffas86.c
912
913 $(ZLIBDIR)/match.o:
914 $(TCC) -c -o $@ -DASMV $(ZLIBDIR)/contrib/asm686/match.S
915
 
 
916 LIBTARGETS += zlib
 
917
918 openssl: $(LIBTARGETS)
919 cd $(OPENSSLLIBDIR);./Configure --cross-compile-prefix=$(PREFIX) $(SSLCONFIG)
920 $(MAKE) -C $(OPENSSLLIBDIR) build_libs
921
@@ -2108,14 +2071,10 @@
2071 -Daccess=file_access \
2072 -Dsystem=fossil_system \
2073 -Dgetenv=fossil_getenv \
2074 -Dfopen=fossil_fopen
2075
 
 
 
 
2076 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
2077 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
2078
2079 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
2080 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
@@ -2132,8 +2091,5 @@
2091 $(XTCC) -c $(SRCDIR)/th_lang.c -o $@
2092
2093 $(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
2094 $(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
2095
 
 
 
2096
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -89,14 +89,10 @@
8989
9090
#### Use 'system' SQLite
9191
#
9292
# USE_SYSTEM_SQLITE = 1
9393
94
-#### Use the miniz compression library
95
-#
96
-# FOSSIL_ENABLE_MINIZ = 1
97
-
9894
#### Use the Tcl source directory instead of the install directory?
9995
# This is useful when Tcl has been compiled statically with MinGW.
10096
#
10197
FOSSIL_TCL_SOURCE = 1
10298
@@ -128,18 +124,13 @@
128124
# used, taking into account whether zlib is actually enabled and the target
129125
# processor architecture.
130126
#
131127
ifndef X64
132128
SSLCONFIG = mingw
133
-ifndef FOSSIL_ENABLE_MINIZ
134129
ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
135130
LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
136131
else
137
-ZLIBCONFIG =
138
-LIBTARGETS =
139
-endif
140
-else
141132
SSLCONFIG = mingw64
142133
ZLIBCONFIG =
143134
LIBTARGETS =
144135
endif
145136
@@ -149,13 +140,11 @@
149140
SSLCONFIG += no-ssl2 no-ssl3 no-shared
150141
151142
#### When using zlib, make sure that OpenSSL is configured to use the zlib
152143
# that Fossil knows about (i.e. the one within the source tree).
153144
#
154
-ifndef FOSSIL_ENABLE_MINIZ
155145
SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
156
-endif
157146
158147
#### The directories where the OpenSSL include and library files are located.
159148
# The recommended usage here is to use the Sysinternals junction tool
160149
# to create a hard link between an "openssl-1.x" sub-directory of the
161150
# Fossil source code directory and the target OpenSSL source directory.
@@ -216,24 +205,19 @@
216205
TCC += -g
217206
else
218207
TCC += -Os
219208
endif
220209
221
-#### When not using the miniz compression library, zlib is required.
210
+#### zlib is required.
222211
#
223
-ifndef FOSSIL_ENABLE_MINIZ
224212
TCC += -L$(ZLIBDIR) -I$(ZINCDIR)
225
-endif
226213
227214
#### Compile resources for use in building executables that will run
228215
# on the target platform.
229216
#
230217
RCC = $(PREFIX)windres -I$(SRCDIR)
231
-
232
-ifndef FOSSIL_ENABLE_MINIZ
233218
RCC += -I$(ZINCDIR)
234
-endif
235219
236220
# With HTTPS support
237221
ifdef FOSSIL_ENABLE_SSL
238222
TCC += -L$(OPENSSLLIBDIR) -I$(OPENSSLINCDIR)
239223
RCC += -I$(OPENSSLINCDIR)
@@ -248,16 +232,10 @@
248232
TCC += -L$(TCLLIBDIR) -I$(TCLINCDIR)
249233
RCC += -I$(TCLINCDIR)
250234
endif
251235
endif
252236
253
-# With miniz (i.e. instead of zlib)
254
-ifdef FOSSIL_ENABLE_MINIZ
255
-TCC += -DFOSSIL_ENABLE_MINIZ=1
256
-RCC += -DFOSSIL_ENABLE_MINIZ=1
257
-endif
258
-
259237
# With MinGW command line handling workaround
260238
ifdef MINGW_IS_32BIT_ONLY
261239
TCC += -DBROKEN_MINGW_CMDLINE=1
262240
RCC += -DBROKEN_MINGW_CMDLINE=1
263241
endif
@@ -353,15 +331,13 @@
353331
# to link against the Z-Lib compression library. There are no
354332
# other mandatory dependencies.
355333
#
356334
LIB += -lmingwex
357335
358
-#### When not using the miniz compression library, zlib is required.
336
+#### zlib is required.
359337
#
360
-ifndef FOSSIL_ENABLE_MINIZ
361338
LIB += -lz
362
-endif
363339
364340
#### These libraries MUST appear in the same order as they do for Tcl
365341
# or linking with it will not work (exact reason unknown).
366342
#
367343
ifdef FOSSIL_ENABLE_TCL
@@ -852,16 +828,14 @@
852828
853829
all: $(OBJDIR) $(APPNAME)
854830
855831
$(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
856832
ifdef USE_WINDOWS
857
- $(CAT) $(subst /,\,$(SRCDIR)\miniz.c) | $(GREP) "define MZ_VERSION" > $(subst /,\,$(OBJDIR)\minizver.h)
858833
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
859834
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
860835
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
861836
else
862
- $(CAT) $(SRCDIR)/miniz.c | $(GREP) "define MZ_VERSION" > $(OBJDIR)/minizver.h
863837
$(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
864838
$(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
865839
$(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
866840
endif
867841
$(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
@@ -915,21 +889,13 @@
915889
# using -lsqlite3.
916890
SQLITE3_OBJ.1 =
917891
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
918892
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
919893
920
-# The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
921
-# set to 1. If it is set to 1, the miniz library included in the
922
-# source tree should be used; otherwise, it should not.
923
-MINIZ_OBJ.0 =
924
-MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
925
-MINIZ_OBJ. = $(MINIZ_OBJ.0)
926
-
927894
928895
EXTRAOBJ = \
929896
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
930
- $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
931897
$(OBJDIR)/shell.o \
932898
$(OBJDIR)/th.o \
933899
$(OBJDIR)/th_lang.o \
934900
$(OBJDIR)/th_tcl.o \
935901
$(OBJDIR)/cson_amalgamation.o
@@ -945,14 +911,11 @@
945911
$(TCC) -c -o $@ -DASMINF -I$(ZLIBDIR) -O3 $(ZLIBDIR)/contrib/inflate86/inffas86.c
946912
947913
$(ZLIBDIR)/match.o:
948914
$(TCC) -c -o $@ -DASMV $(ZLIBDIR)/contrib/asm686/match.S
949915
950
-
951
-ifndef FOSSIL_ENABLE_MINIZ
952916
LIBTARGETS += zlib
953
-endif
954917
955918
openssl: $(LIBTARGETS)
956919
cd $(OPENSSLLIBDIR);./Configure --cross-compile-prefix=$(PREFIX) $(SSLCONFIG)
957920
$(MAKE) -C $(OPENSSLLIBDIR) build_libs
958921
@@ -2108,14 +2071,10 @@
21082071
-Daccess=file_access \
21092072
-Dsystem=fossil_system \
21102073
-Dgetenv=fossil_getenv \
21112074
-Dfopen=fossil_fopen
21122075
2113
-MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
2114
- -DMINIZ_NO_TIME \
2115
- -DMINIZ_NO_ARCHIVE_APIS
2116
-
21172076
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw.mistachkin
21182077
$(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
21192078
21202079
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
21212080
$(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
@@ -2132,8 +2091,5 @@
21322091
$(XTCC) -c $(SRCDIR)/th_lang.c -o $@
21332092
21342093
$(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
21352094
$(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
21362095
2137
-$(OBJDIR)/miniz.o: $(SRCDIR)/miniz.c
2138
- $(XTCC) $(MINIZ_OPTIONS) -c $(SRCDIR)/miniz.c -o $@
2139
-
21402096
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -89,14 +89,10 @@
89
90 #### Use 'system' SQLite
91 #
92 # USE_SYSTEM_SQLITE = 1
93
94 #### Use the miniz compression library
95 #
96 # FOSSIL_ENABLE_MINIZ = 1
97
98 #### Use the Tcl source directory instead of the install directory?
99 # This is useful when Tcl has been compiled statically with MinGW.
100 #
101 FOSSIL_TCL_SOURCE = 1
102
@@ -128,18 +124,13 @@
128 # used, taking into account whether zlib is actually enabled and the target
129 # processor architecture.
130 #
131 ifndef X64
132 SSLCONFIG = mingw
133 ifndef FOSSIL_ENABLE_MINIZ
134 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
135 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
136 else
137 ZLIBCONFIG =
138 LIBTARGETS =
139 endif
140 else
141 SSLCONFIG = mingw64
142 ZLIBCONFIG =
143 LIBTARGETS =
144 endif
145
@@ -149,13 +140,11 @@
149 SSLCONFIG += no-ssl2 no-ssl3 no-shared
150
151 #### When using zlib, make sure that OpenSSL is configured to use the zlib
152 # that Fossil knows about (i.e. the one within the source tree).
153 #
154 ifndef FOSSIL_ENABLE_MINIZ
155 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
156 endif
157
158 #### The directories where the OpenSSL include and library files are located.
159 # The recommended usage here is to use the Sysinternals junction tool
160 # to create a hard link between an "openssl-1.x" sub-directory of the
161 # Fossil source code directory and the target OpenSSL source directory.
@@ -216,24 +205,19 @@
216 TCC += -g
217 else
218 TCC += -Os
219 endif
220
221 #### When not using the miniz compression library, zlib is required.
222 #
223 ifndef FOSSIL_ENABLE_MINIZ
224 TCC += -L$(ZLIBDIR) -I$(ZINCDIR)
225 endif
226
227 #### Compile resources for use in building executables that will run
228 # on the target platform.
229 #
230 RCC = $(PREFIX)windres -I$(SRCDIR)
231
232 ifndef FOSSIL_ENABLE_MINIZ
233 RCC += -I$(ZINCDIR)
234 endif
235
236 # With HTTPS support
237 ifdef FOSSIL_ENABLE_SSL
238 TCC += -L$(OPENSSLLIBDIR) -I$(OPENSSLINCDIR)
239 RCC += -I$(OPENSSLINCDIR)
@@ -248,16 +232,10 @@
248 TCC += -L$(TCLLIBDIR) -I$(TCLINCDIR)
249 RCC += -I$(TCLINCDIR)
250 endif
251 endif
252
253 # With miniz (i.e. instead of zlib)
254 ifdef FOSSIL_ENABLE_MINIZ
255 TCC += -DFOSSIL_ENABLE_MINIZ=1
256 RCC += -DFOSSIL_ENABLE_MINIZ=1
257 endif
258
259 # With MinGW command line handling workaround
260 ifdef MINGW_IS_32BIT_ONLY
261 TCC += -DBROKEN_MINGW_CMDLINE=1
262 RCC += -DBROKEN_MINGW_CMDLINE=1
263 endif
@@ -353,15 +331,13 @@
353 # to link against the Z-Lib compression library. There are no
354 # other mandatory dependencies.
355 #
356 LIB += -lmingwex
357
358 #### When not using the miniz compression library, zlib is required.
359 #
360 ifndef FOSSIL_ENABLE_MINIZ
361 LIB += -lz
362 endif
363
364 #### These libraries MUST appear in the same order as they do for Tcl
365 # or linking with it will not work (exact reason unknown).
366 #
367 ifdef FOSSIL_ENABLE_TCL
@@ -852,16 +828,14 @@
852
853 all: $(OBJDIR) $(APPNAME)
854
855 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
856 ifdef USE_WINDOWS
857 $(CAT) $(subst /,\,$(SRCDIR)\miniz.c) | $(GREP) "define MZ_VERSION" > $(subst /,\,$(OBJDIR)\minizver.h)
858 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
859 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
860 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
861 else
862 $(CAT) $(SRCDIR)/miniz.c | $(GREP) "define MZ_VERSION" > $(OBJDIR)/minizver.h
863 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
864 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
865 $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
866 endif
867 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
@@ -915,21 +889,13 @@
915 # using -lsqlite3.
916 SQLITE3_OBJ.1 =
917 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
918 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
919
920 # The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
921 # set to 1. If it is set to 1, the miniz library included in the
922 # source tree should be used; otherwise, it should not.
923 MINIZ_OBJ.0 =
924 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
925 MINIZ_OBJ. = $(MINIZ_OBJ.0)
926
927
928 EXTRAOBJ = \
929 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
930 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
931 $(OBJDIR)/shell.o \
932 $(OBJDIR)/th.o \
933 $(OBJDIR)/th_lang.o \
934 $(OBJDIR)/th_tcl.o \
935 $(OBJDIR)/cson_amalgamation.o
@@ -945,14 +911,11 @@
945 $(TCC) -c -o $@ -DASMINF -I$(ZLIBDIR) -O3 $(ZLIBDIR)/contrib/inflate86/inffas86.c
946
947 $(ZLIBDIR)/match.o:
948 $(TCC) -c -o $@ -DASMV $(ZLIBDIR)/contrib/asm686/match.S
949
950
951 ifndef FOSSIL_ENABLE_MINIZ
952 LIBTARGETS += zlib
953 endif
954
955 openssl: $(LIBTARGETS)
956 cd $(OPENSSLLIBDIR);./Configure --cross-compile-prefix=$(PREFIX) $(SSLCONFIG)
957 $(MAKE) -C $(OPENSSLLIBDIR) build_libs
958
@@ -2108,14 +2071,10 @@
2108 -Daccess=file_access \
2109 -Dsystem=fossil_system \
2110 -Dgetenv=fossil_getenv \
2111 -Dfopen=fossil_fopen
2112
2113 MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
2114 -DMINIZ_NO_TIME \
2115 -DMINIZ_NO_ARCHIVE_APIS
2116
2117 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw.mistachkin
2118 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
2119
2120 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
2121 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
@@ -2132,8 +2091,5 @@
2132 $(XTCC) -c $(SRCDIR)/th_lang.c -o $@
2133
2134 $(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
2135 $(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
2136
2137 $(OBJDIR)/miniz.o: $(SRCDIR)/miniz.c
2138 $(XTCC) $(MINIZ_OPTIONS) -c $(SRCDIR)/miniz.c -o $@
2139
2140
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -89,14 +89,10 @@
89
90 #### Use 'system' SQLite
91 #
92 # USE_SYSTEM_SQLITE = 1
93
 
 
 
 
94 #### Use the Tcl source directory instead of the install directory?
95 # This is useful when Tcl has been compiled statically with MinGW.
96 #
97 FOSSIL_TCL_SOURCE = 1
98
@@ -128,18 +124,13 @@
124 # used, taking into account whether zlib is actually enabled and the target
125 # processor architecture.
126 #
127 ifndef X64
128 SSLCONFIG = mingw
 
129 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
130 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
131 else
 
 
 
 
132 SSLCONFIG = mingw64
133 ZLIBCONFIG =
134 LIBTARGETS =
135 endif
136
@@ -149,13 +140,11 @@
140 SSLCONFIG += no-ssl2 no-ssl3 no-shared
141
142 #### When using zlib, make sure that OpenSSL is configured to use the zlib
143 # that Fossil knows about (i.e. the one within the source tree).
144 #
 
145 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
 
146
147 #### The directories where the OpenSSL include and library files are located.
148 # The recommended usage here is to use the Sysinternals junction tool
149 # to create a hard link between an "openssl-1.x" sub-directory of the
150 # Fossil source code directory and the target OpenSSL source directory.
@@ -216,24 +205,19 @@
205 TCC += -g
206 else
207 TCC += -Os
208 endif
209
210 #### zlib is required.
211 #
 
212 TCC += -L$(ZLIBDIR) -I$(ZINCDIR)
 
213
214 #### Compile resources for use in building executables that will run
215 # on the target platform.
216 #
217 RCC = $(PREFIX)windres -I$(SRCDIR)
 
 
218 RCC += -I$(ZINCDIR)
 
219
220 # With HTTPS support
221 ifdef FOSSIL_ENABLE_SSL
222 TCC += -L$(OPENSSLLIBDIR) -I$(OPENSSLINCDIR)
223 RCC += -I$(OPENSSLINCDIR)
@@ -248,16 +232,10 @@
232 TCC += -L$(TCLLIBDIR) -I$(TCLINCDIR)
233 RCC += -I$(TCLINCDIR)
234 endif
235 endif
236
 
 
 
 
 
 
237 # With MinGW command line handling workaround
238 ifdef MINGW_IS_32BIT_ONLY
239 TCC += -DBROKEN_MINGW_CMDLINE=1
240 RCC += -DBROKEN_MINGW_CMDLINE=1
241 endif
@@ -353,15 +331,13 @@
331 # to link against the Z-Lib compression library. There are no
332 # other mandatory dependencies.
333 #
334 LIB += -lmingwex
335
336 #### zlib is required.
337 #
 
338 LIB += -lz
 
339
340 #### These libraries MUST appear in the same order as they do for Tcl
341 # or linking with it will not work (exact reason unknown).
342 #
343 ifdef FOSSIL_ENABLE_TCL
@@ -852,16 +828,14 @@
828
829 all: $(OBJDIR) $(APPNAME)
830
831 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
832 ifdef USE_WINDOWS
 
833 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
834 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
835 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
836 else
 
837 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
838 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
839 $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
840 endif
841 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
@@ -915,21 +889,13 @@
889 # using -lsqlite3.
890 SQLITE3_OBJ.1 =
891 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
892 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
893
 
 
 
 
 
 
 
894
895 EXTRAOBJ = \
896 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
 
897 $(OBJDIR)/shell.o \
898 $(OBJDIR)/th.o \
899 $(OBJDIR)/th_lang.o \
900 $(OBJDIR)/th_tcl.o \
901 $(OBJDIR)/cson_amalgamation.o
@@ -945,14 +911,11 @@
911 $(TCC) -c -o $@ -DASMINF -I$(ZLIBDIR) -O3 $(ZLIBDIR)/contrib/inflate86/inffas86.c
912
913 $(ZLIBDIR)/match.o:
914 $(TCC) -c -o $@ -DASMV $(ZLIBDIR)/contrib/asm686/match.S
915
 
 
916 LIBTARGETS += zlib
 
917
918 openssl: $(LIBTARGETS)
919 cd $(OPENSSLLIBDIR);./Configure --cross-compile-prefix=$(PREFIX) $(SSLCONFIG)
920 $(MAKE) -C $(OPENSSLLIBDIR) build_libs
921
@@ -2108,14 +2071,10 @@
2071 -Daccess=file_access \
2072 -Dsystem=fossil_system \
2073 -Dgetenv=fossil_getenv \
2074 -Dfopen=fossil_fopen
2075
 
 
 
 
2076 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw.mistachkin
2077 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
2078
2079 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
2080 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
@@ -2132,8 +2091,5 @@
2091 $(XTCC) -c $(SRCDIR)/th_lang.c -o $@
2092
2093 $(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
2094 $(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
2095
 
 
 
2096
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -62,15 +62,10 @@
6262
# Enable legacy treatment of the mv/rm commands?
6363
!ifndef FOSSIL_ENABLE_LEGACY_MV_RM
6464
FOSSIL_ENABLE_LEGACY_MV_RM = 0
6565
!endif
6666
67
-# Enable use of miniz instead of zlib?
68
-!ifndef FOSSIL_ENABLE_MINIZ
69
-FOSSIL_ENABLE_MINIZ = 0
70
-!endif
71
-
7267
# Enable OpenSSL support?
7368
!ifndef FOSSIL_ENABLE_SSL
7469
FOSSIL_ENABLE_SSL = 0
7570
!endif
7671
@@ -182,14 +177,11 @@
182177
!else
183178
ZLIB = zlib.lib
184179
!endif
185180
186181
INCL = /I. /I$(SRCDIR) /I$B\win\include
187
-
188
-!if $(FOSSIL_ENABLE_MINIZ)==0
189182
INCL = $(INCL) /I$(ZINCDIR)
190
-!endif
191183
192184
!if $(FOSSIL_ENABLE_SSL)!=0
193185
INCL = $(INCL) /I$(SSLINCDIR)
194186
!endif
195187
@@ -248,19 +240,12 @@
248240
!if $(FOSSIL_DYNAMIC_BUILD)!=0
249241
TCC = $(TCC) /DFOSSIL_DYNAMIC_BUILD=1
250242
RCC = $(RCC) /DFOSSIL_DYNAMIC_BUILD=1
251243
!endif
252244
253
-!if $(FOSSIL_ENABLE_MINIZ)==0
254245
LIBS = $(LIBS) $(ZLIB)
255246
LIBDIR = $(LIBDIR) /LIBPATH:$(ZLIBDIR)
256
-!endif
257
-
258
-!if $(FOSSIL_ENABLE_MINIZ)!=0
259
-TCC = $(TCC) /DFOSSIL_ENABLE_MINIZ=1
260
-RCC = $(RCC) /DFOSSIL_ENABLE_MINIZ=1
261
-!endif
262247
263248
!if $(FOSSIL_ENABLE_JSON)!=0
264249
TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
265250
RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
266251
!endif
@@ -324,14 +309,10 @@
324309
/Daccess=file_access \
325310
/Dsystem=fossil_system \
326311
/Dgetenv=fossil_getenv \
327312
/Dfopen=fossil_fopen
328313
329
-MINIZ_OPTIONS = /DMINIZ_NO_STDIO \
330
- /DMINIZ_NO_TIME \
331
- /DMINIZ_NO_ARCHIVE_APIS
332
-
333314
SRC = add_.c \
334315
allrepo_.c \
335316
attach_.c \
336317
bag_.c \
337318
bisect_.c \
@@ -623,13 +604,10 @@
623604
$(OX)\winhttp$O \
624605
$(OX)\wysiwyg$O \
625606
$(OX)\xfer$O \
626607
$(OX)\xfersetup$O \
627608
$(OX)\zip$O \
628
-!if $(FOSSIL_ENABLE_MINIZ)!=0
629
- $(OX)\miniz$O \
630
-!endif
631609
$(OX)\fossil.res
632610
633611
634612
APPNAME = $(OX)\fossil$(E)
635613
PDBNAME = $(OX)\fossil$(P)
@@ -658,14 +636,12 @@
658636
!else
659637
@pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
660638
!endif
661639
!endif
662640
663
-!if $(FOSSIL_ENABLE_MINIZ)==0
664641
!if $(FOSSIL_BUILD_ZLIB)!=0
665642
APPTARGETS = $(APPTARGETS) zlib
666
-!endif
667643
!endif
668644
669645
!if $(FOSSIL_ENABLE_SSL)!=0
670646
!if $(FOSSIL_BUILD_SSL)!=0
671647
APPTARGETS = $(APPTARGETS) openssl
@@ -803,13 +779,10 @@
803779
echo $(OX)\winhttp.obj >> $@
804780
echo $(OX)\wysiwyg.obj >> $@
805781
echo $(OX)\xfer.obj >> $@
806782
echo $(OX)\xfersetup.obj >> $@
807783
echo $(OX)\zip.obj >> $@
808
-!if $(FOSSIL_ENABLE_MINIZ)!=0
809
- echo $(OX)\miniz.obj >> $@
810
-!endif
811784
echo $(LIBS) >> $@
812785
813786
$(OX):
814787
@-mkdir $@
815788
@@ -844,13 +817,10 @@
844817
$(TCC) /Fo$@ -c $**
845818
846819
$(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
847820
$(TCC) /Fo$@ -c $**
848821
849
-$(OX)\miniz$O : $(SRCDIR)\miniz.c
850
- $(TCC) /Fo$@ -c $(MINIZ_OPTIONS) $(SRCDIR)\miniz.c
851
-
852822
VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
853823
$** > $@
854824
$(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
855825
$(TCC) /Fo$@ /c $**
856826
857827
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -62,15 +62,10 @@
62 # Enable legacy treatment of the mv/rm commands?
63 !ifndef FOSSIL_ENABLE_LEGACY_MV_RM
64 FOSSIL_ENABLE_LEGACY_MV_RM = 0
65 !endif
66
67 # Enable use of miniz instead of zlib?
68 !ifndef FOSSIL_ENABLE_MINIZ
69 FOSSIL_ENABLE_MINIZ = 0
70 !endif
71
72 # Enable OpenSSL support?
73 !ifndef FOSSIL_ENABLE_SSL
74 FOSSIL_ENABLE_SSL = 0
75 !endif
76
@@ -182,14 +177,11 @@
182 !else
183 ZLIB = zlib.lib
184 !endif
185
186 INCL = /I. /I$(SRCDIR) /I$B\win\include
187
188 !if $(FOSSIL_ENABLE_MINIZ)==0
189 INCL = $(INCL) /I$(ZINCDIR)
190 !endif
191
192 !if $(FOSSIL_ENABLE_SSL)!=0
193 INCL = $(INCL) /I$(SSLINCDIR)
194 !endif
195
@@ -248,19 +240,12 @@
248 !if $(FOSSIL_DYNAMIC_BUILD)!=0
249 TCC = $(TCC) /DFOSSIL_DYNAMIC_BUILD=1
250 RCC = $(RCC) /DFOSSIL_DYNAMIC_BUILD=1
251 !endif
252
253 !if $(FOSSIL_ENABLE_MINIZ)==0
254 LIBS = $(LIBS) $(ZLIB)
255 LIBDIR = $(LIBDIR) /LIBPATH:$(ZLIBDIR)
256 !endif
257
258 !if $(FOSSIL_ENABLE_MINIZ)!=0
259 TCC = $(TCC) /DFOSSIL_ENABLE_MINIZ=1
260 RCC = $(RCC) /DFOSSIL_ENABLE_MINIZ=1
261 !endif
262
263 !if $(FOSSIL_ENABLE_JSON)!=0
264 TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
265 RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
266 !endif
@@ -324,14 +309,10 @@
324 /Daccess=file_access \
325 /Dsystem=fossil_system \
326 /Dgetenv=fossil_getenv \
327 /Dfopen=fossil_fopen
328
329 MINIZ_OPTIONS = /DMINIZ_NO_STDIO \
330 /DMINIZ_NO_TIME \
331 /DMINIZ_NO_ARCHIVE_APIS
332
333 SRC = add_.c \
334 allrepo_.c \
335 attach_.c \
336 bag_.c \
337 bisect_.c \
@@ -623,13 +604,10 @@
623 $(OX)\winhttp$O \
624 $(OX)\wysiwyg$O \
625 $(OX)\xfer$O \
626 $(OX)\xfersetup$O \
627 $(OX)\zip$O \
628 !if $(FOSSIL_ENABLE_MINIZ)!=0
629 $(OX)\miniz$O \
630 !endif
631 $(OX)\fossil.res
632
633
634 APPNAME = $(OX)\fossil$(E)
635 PDBNAME = $(OX)\fossil$(P)
@@ -658,14 +636,12 @@
658 !else
659 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
660 !endif
661 !endif
662
663 !if $(FOSSIL_ENABLE_MINIZ)==0
664 !if $(FOSSIL_BUILD_ZLIB)!=0
665 APPTARGETS = $(APPTARGETS) zlib
666 !endif
667 !endif
668
669 !if $(FOSSIL_ENABLE_SSL)!=0
670 !if $(FOSSIL_BUILD_SSL)!=0
671 APPTARGETS = $(APPTARGETS) openssl
@@ -803,13 +779,10 @@
803 echo $(OX)\winhttp.obj >> $@
804 echo $(OX)\wysiwyg.obj >> $@
805 echo $(OX)\xfer.obj >> $@
806 echo $(OX)\xfersetup.obj >> $@
807 echo $(OX)\zip.obj >> $@
808 !if $(FOSSIL_ENABLE_MINIZ)!=0
809 echo $(OX)\miniz.obj >> $@
810 !endif
811 echo $(LIBS) >> $@
812
813 $(OX):
814 @-mkdir $@
815
@@ -844,13 +817,10 @@
844 $(TCC) /Fo$@ -c $**
845
846 $(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
847 $(TCC) /Fo$@ -c $**
848
849 $(OX)\miniz$O : $(SRCDIR)\miniz.c
850 $(TCC) /Fo$@ -c $(MINIZ_OPTIONS) $(SRCDIR)\miniz.c
851
852 VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
853 $** > $@
854 $(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
855 $(TCC) /Fo$@ /c $**
856
857
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -62,15 +62,10 @@
62 # Enable legacy treatment of the mv/rm commands?
63 !ifndef FOSSIL_ENABLE_LEGACY_MV_RM
64 FOSSIL_ENABLE_LEGACY_MV_RM = 0
65 !endif
66
 
 
 
 
 
67 # Enable OpenSSL support?
68 !ifndef FOSSIL_ENABLE_SSL
69 FOSSIL_ENABLE_SSL = 0
70 !endif
71
@@ -182,14 +177,11 @@
177 !else
178 ZLIB = zlib.lib
179 !endif
180
181 INCL = /I. /I$(SRCDIR) /I$B\win\include
 
 
182 INCL = $(INCL) /I$(ZINCDIR)
 
183
184 !if $(FOSSIL_ENABLE_SSL)!=0
185 INCL = $(INCL) /I$(SSLINCDIR)
186 !endif
187
@@ -248,19 +240,12 @@
240 !if $(FOSSIL_DYNAMIC_BUILD)!=0
241 TCC = $(TCC) /DFOSSIL_DYNAMIC_BUILD=1
242 RCC = $(RCC) /DFOSSIL_DYNAMIC_BUILD=1
243 !endif
244
 
245 LIBS = $(LIBS) $(ZLIB)
246 LIBDIR = $(LIBDIR) /LIBPATH:$(ZLIBDIR)
 
 
 
 
 
 
247
248 !if $(FOSSIL_ENABLE_JSON)!=0
249 TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
250 RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
251 !endif
@@ -324,14 +309,10 @@
309 /Daccess=file_access \
310 /Dsystem=fossil_system \
311 /Dgetenv=fossil_getenv \
312 /Dfopen=fossil_fopen
313
 
 
 
 
314 SRC = add_.c \
315 allrepo_.c \
316 attach_.c \
317 bag_.c \
318 bisect_.c \
@@ -623,13 +604,10 @@
604 $(OX)\winhttp$O \
605 $(OX)\wysiwyg$O \
606 $(OX)\xfer$O \
607 $(OX)\xfersetup$O \
608 $(OX)\zip$O \
 
 
 
609 $(OX)\fossil.res
610
611
612 APPNAME = $(OX)\fossil$(E)
613 PDBNAME = $(OX)\fossil$(P)
@@ -658,14 +636,12 @@
636 !else
637 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
638 !endif
639 !endif
640
 
641 !if $(FOSSIL_BUILD_ZLIB)!=0
642 APPTARGETS = $(APPTARGETS) zlib
 
643 !endif
644
645 !if $(FOSSIL_ENABLE_SSL)!=0
646 !if $(FOSSIL_BUILD_SSL)!=0
647 APPTARGETS = $(APPTARGETS) openssl
@@ -803,13 +779,10 @@
779 echo $(OX)\winhttp.obj >> $@
780 echo $(OX)\wysiwyg.obj >> $@
781 echo $(OX)\xfer.obj >> $@
782 echo $(OX)\xfersetup.obj >> $@
783 echo $(OX)\zip.obj >> $@
 
 
 
784 echo $(LIBS) >> $@
785
786 $(OX):
787 @-mkdir $@
788
@@ -844,13 +817,10 @@
817 $(TCC) /Fo$@ -c $**
818
819 $(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
820 $(TCC) /Fo$@ -c $**
821
 
 
 
822 VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
823 $** > $@
824 $(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
825 $(TCC) /Fo$@ /c $**
826
827
--- win/fossil.rc
+++ win/fossil.rc
@@ -30,21 +30,11 @@
3030
3131
#include "VERSION.h"
3232
#define _RC_COMPILE_
3333
#include "config.h"
3434
#include "sqlite3.h"
35
-
36
-#if defined(FOSSIL_ENABLE_MINIZ)
37
-#if defined(__MINGW32__)
38
-#include "minizver.h"
39
-#else
40
-#define MINIZ_HEADER_FILE_ONLY
41
-#include "miniz.c"
42
-#endif /* defined(__MINGW32__) */
43
-#else
4435
#include "zlib.h"
45
-#endif /* defined(FOSSIL_ENABLE_MINIZ) */
4636
4737
#if defined(FOSSIL_ENABLE_SSL)
4838
#include "openssl/opensslv.h"
4939
#endif /* defined(FOSSIL_ENABLE_SSL) */
5040
@@ -107,15 +97,11 @@
10797
#if defined(FOSSIL_DYNAMIC_BUILD)
10898
VALUE "DynamicBuild", "yes\0"
10999
#else
110100
VALUE "DynamicBuild", "no\0"
111101
#endif
112
-#if defined(FOSSIL_ENABLE_MINIZ)
113
- VALUE "MinizVersion", "miniz " MZ_VERSION "\0"
114
-#else
115102
VALUE "ZlibVersion", "zlib " ZLIB_VERSION "\0"
116
-#endif /* defined(FOSSIL_ENABLE_MINIZ) */
117103
#if defined(BROKEN_MINGW_CMDLINE)
118104
VALUE "CommandLineIsUnicode", "No\0"
119105
#else
120106
VALUE "CommandLineIsUnicode", "Yes\0"
121107
#endif /* defined(BROKEN_MINGW_CMDLINE) */
122108
--- win/fossil.rc
+++ win/fossil.rc
@@ -30,21 +30,11 @@
30
31 #include "VERSION.h"
32 #define _RC_COMPILE_
33 #include "config.h"
34 #include "sqlite3.h"
35
36 #if defined(FOSSIL_ENABLE_MINIZ)
37 #if defined(__MINGW32__)
38 #include "minizver.h"
39 #else
40 #define MINIZ_HEADER_FILE_ONLY
41 #include "miniz.c"
42 #endif /* defined(__MINGW32__) */
43 #else
44 #include "zlib.h"
45 #endif /* defined(FOSSIL_ENABLE_MINIZ) */
46
47 #if defined(FOSSIL_ENABLE_SSL)
48 #include "openssl/opensslv.h"
49 #endif /* defined(FOSSIL_ENABLE_SSL) */
50
@@ -107,15 +97,11 @@
107 #if defined(FOSSIL_DYNAMIC_BUILD)
108 VALUE "DynamicBuild", "yes\0"
109 #else
110 VALUE "DynamicBuild", "no\0"
111 #endif
112 #if defined(FOSSIL_ENABLE_MINIZ)
113 VALUE "MinizVersion", "miniz " MZ_VERSION "\0"
114 #else
115 VALUE "ZlibVersion", "zlib " ZLIB_VERSION "\0"
116 #endif /* defined(FOSSIL_ENABLE_MINIZ) */
117 #if defined(BROKEN_MINGW_CMDLINE)
118 VALUE "CommandLineIsUnicode", "No\0"
119 #else
120 VALUE "CommandLineIsUnicode", "Yes\0"
121 #endif /* defined(BROKEN_MINGW_CMDLINE) */
122
--- win/fossil.rc
+++ win/fossil.rc
@@ -30,21 +30,11 @@
30
31 #include "VERSION.h"
32 #define _RC_COMPILE_
33 #include "config.h"
34 #include "sqlite3.h"
 
 
 
 
 
 
 
 
 
35 #include "zlib.h"
 
36
37 #if defined(FOSSIL_ENABLE_SSL)
38 #include "openssl/opensslv.h"
39 #endif /* defined(FOSSIL_ENABLE_SSL) */
40
@@ -107,15 +97,11 @@
97 #if defined(FOSSIL_DYNAMIC_BUILD)
98 VALUE "DynamicBuild", "yes\0"
99 #else
100 VALUE "DynamicBuild", "no\0"
101 #endif
 
 
 
102 VALUE "ZlibVersion", "zlib " ZLIB_VERSION "\0"
 
103 #if defined(BROKEN_MINGW_CMDLINE)
104 VALUE "CommandLineIsUnicode", "No\0"
105 #else
106 VALUE "CommandLineIsUnicode", "Yes\0"
107 #endif /* defined(BROKEN_MINGW_CMDLINE) */
108
--- www/changes.wiki
+++ www/changes.wiki
@@ -29,10 +29,12 @@
2929
</ul>
3030
* Get autosetup working with MinGW.
3131
* Fix autosetup detection of zlib in the source tree.
3232
* Added autosetup detection of OpenSSL when it may be present under the
3333
"compat" subdirectory of the source tree.
34
+ * Remove support for miniz because the upstream project appears to be
35
+ unmaintained.
3436
3537
<h2>Changes for Version 1.34 (2015-11-02)</h2>
3638
3739
* Make the [/help?cmd=clean|fossil clean] command undoable for files less
3840
than 10MiB.
3941
--- www/changes.wiki
+++ www/changes.wiki
@@ -29,10 +29,12 @@
29 </ul>
30 * Get autosetup working with MinGW.
31 * Fix autosetup detection of zlib in the source tree.
32 * Added autosetup detection of OpenSSL when it may be present under the
33 "compat" subdirectory of the source tree.
 
 
34
35 <h2>Changes for Version 1.34 (2015-11-02)</h2>
36
37 * Make the [/help?cmd=clean|fossil clean] command undoable for files less
38 than 10MiB.
39
--- www/changes.wiki
+++ www/changes.wiki
@@ -29,10 +29,12 @@
29 </ul>
30 * Get autosetup working with MinGW.
31 * Fix autosetup detection of zlib in the source tree.
32 * Added autosetup detection of OpenSSL when it may be present under the
33 "compat" subdirectory of the source tree.
34 * Remove support for miniz because the upstream project appears to be
35 unmaintained.
36
37 <h2>Changes for Version 1.34 (2015-11-02)</h2>
38
39 * Make the [/help?cmd=clean|fossil clean] command undoable for files less
40 than 10MiB.
41

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button