[sword-svn] r3040 - in trunk: . src/modules/common

chrislit at crosswire.org chrislit at crosswire.org
Sat Mar 1 06:36:02 MST 2014


Author: chrislit
Date: 2014-03-01 06:36:02 -0700 (Sat, 01 Mar 2014)
New Revision: 3040

Modified:
   trunk/configure.ac
   trunk/src/modules/common/bz2comprs.cpp
Log:
added bzip2 compression (*not tested, but it compiles via autotools*)


Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2014-02-28 11:33:23 UTC (rev 3039)
+++ trunk/configure.ac	2014-03-01 13:36:02 UTC (rev 3040)
@@ -49,6 +49,8 @@
 # ---------------------------------------------------------------------
 AC_ARG_WITH(zlib,
 	AC_HELP_STRING([--with-zlib],[allow zlib compressed modules (default=yes)]),,with_zlib=yes)
+AC_ARG_WITH(bzip2,
+	AC_HELP_STRING([--with-bzip2],[allow bzip2 compressed modules (default=yes)]),,with_bzip2=yes)
 AC_ARG_WITH(icu,
 	AC_HELP_STRING([--with-icu],[use ICU for unicode (default=yes)]),,with_icu=yes)
 AC_ARG_WITH(icusword,
@@ -125,6 +127,17 @@
 	AM_CXXFLAGS="$AM_CXXFLAGS -DEXCLUDEZLIB"
 fi
 
+if test x$with_bzip2  = xyes; then
+	AC_CHECK_LIB(bz2, BZ2_bzBuffToBuffCompress,,with_bzip2="no")
+else
+	with_bzip2="no"
+fi
+
+if test x$with_bzip2 = xno; then
+	AM_CFLAGS="$AM_CFLAGS -DEXCLUDEBZIP2"
+	AM_CXXFLAGS="$AM_CXXFLAGS -DEXCLUDEBZIP2"
+fi
+
 AS_IF([test "x$with_internalregex" = "xyes"],
       [have_systemregex="no"],
       [AC_SEARCH_LIBS(regexec, regex, [have_systemregex="yes"], [have_systemregex="no"])])
@@ -333,6 +346,7 @@
 # Substitute variables into makefiles
 # ---------------------------------------------------------------------
 AC_SUBST(with_zlib)
+AC_SUBST(with_bzip2)
 AC_SUBST(with_icu)
 AC_SUBST(with_icusword)
 AC_SUBST(with_conf)
@@ -363,6 +377,7 @@
 # ---------------------------------------------------------------------
 
 AM_CONDITIONAL(HAVE_LIBZ, test x$with_zlib = xyes)
+AM_CONDITIONAL(HAVE_BZIP2, test x$with_bzip2 = xyes)
 AM_CONDITIONAL(HAVE_ICU, test x$with_icu = xyes)
 AM_CONDITIONAL(HAVE_ICUSWORD, test x$with_icusword = xyes)
 AM_CONDITIONAL(HAVE_VSNPRINTF, test x$have_vsnprintf = xyes)
@@ -397,6 +412,7 @@
 echo     "     BUILD EXAMPLES:   $enable_examples"
 echo     "     BUILD UTILITIES:  $enable_utilities"
 echo     "     LIBZ:             $with_zlib"
+echo     "     BZIP2:            $with_bzip2"
 echo     "     ICU:              $with_icu"
 echo     "     ICUSWORD:         $with_icusword"
 echo     "     CXX11REGEX:       $with_cxx11regex"

Modified: trunk/src/modules/common/bz2comprs.cpp
===================================================================
--- trunk/src/modules/common/bz2comprs.cpp	2014-02-28 11:33:23 UTC (rev 3039)
+++ trunk/src/modules/common/bz2comprs.cpp	2014-03-01 13:36:02 UTC (rev 3040)
@@ -26,7 +26,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <bz2comprs.h>
-#include <zlib.h>
+#include <bzlib.h>
 
 SWORD_NAMESPACE_START
 
@@ -59,20 +59,6 @@
 
 void Bzip2Compress::Encode(void)
 {
-/*
-ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
-                                 const Bytef *source, uLong sourceLen));
-     Compresses the source buffer into the destination buffer.  sourceLen is
-   the byte length of the source buffer. Upon entry, destLen is the total
-   size of the destination buffer, which must be at least 0.1% larger than
-   sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
-   compressed buffer.
-     This function can be used to compress a whole file at once if the
-   input file is mmap'ed.
-     compress returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_BUF_ERROR if there was not enough room in the output
-   buffer.
-*/
 	direct = 0;	// set direction needed by parent [Get|Send]Chars()
 
 	// get buffer
@@ -91,12 +77,12 @@
 	}
 
 
-	zlen = (long) (len*1.001)+15;
+	zlen = (long) (len*1.01)+600;
 	char *zbuf = new char[zlen+1];
 	if (len)
 	{
 		//printf("Doing compress\n");
-		if (compress((Bytef*)zbuf, &zlen, (const Bytef*)buf, len) != Z_OK)
+		if (BZ2_bzBuffToBuffCompress(zbuf, (unsigned int*)&zlen, buf, len, 9, 0, 0) != BZ_OK)
 		{
 			printf("ERROR in compression\n");
 		}
@@ -123,24 +109,6 @@
 
 void Bzip2Compress::Decode(void)
 {
-/*
-ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
-                                   const Bytef *source, uLong sourceLen));
-     Decompresses the source buffer into the destination buffer.  sourceLen is
-   the byte length of the source buffer. Upon entry, destLen is the total
-   size of the destination buffer, which must be large enough to hold the
-   entire uncompressed data. (The size of the uncompressed data must have
-   been saved previously by the compressor and transmitted to the decompressor
-   by some mechanism outside the scope of this compression library.)
-   Upon exit, destLen is the actual size of the compressed buffer.
-     This function can be used to decompress a whole file at once if the
-   input file is mmap'ed.
-
-     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_BUF_ERROR if there was not enough room in the output
-   buffer, or Z_DATA_ERROR if the input data was corrupted.
-*/
-
 	// get buffer
 	char chunk[1024];
 	char *zbuf = (char *)calloc(1, 1024);
@@ -158,15 +126,15 @@
 
 	//printf("Decoding complength{%ld} uncomp{%ld}\n", zlen, blen);
 	if (zlen) {
-		unsigned long blen = zlen*20;	// trust compression is less than 1000%
+		unsigned int blen = zlen*20;	// trust compression is less than 1000%
 		char *buf = new char[blen]; 
 		//printf("Doing decompress {%s}\n", zbuf);
 		slen = 0;
-		switch (uncompress((Bytef*)buf, &blen, (Bytef*)zbuf, zlen)){
-			case Z_OK: SendChars(buf, blen); slen = blen; break;
-			case Z_MEM_ERROR: fprintf(stderr, "ERROR: not enough memory during decompression.\n"); break;
-			case Z_BUF_ERROR: fprintf(stderr, "ERROR: not enough room in the out buffer during decompression.\n"); break;
-			case Z_DATA_ERROR: fprintf(stderr, "ERROR: corrupt data during decompression.\n"); break;
+		switch (BZ2_bzBuffToBuffDecompress(buf, &blen, zbuf, zlen, 0, 0)){
+			case BZ_OK: SendChars(buf, blen); slen = blen; break;
+			case BZ_MEM_ERROR: fprintf(stderr, "ERROR: not enough memory during decompression.\n"); break;
+			case BZ_OUTBUFF_FULL: fprintf(stderr, "ERROR: not enough room in the out buffer during decompression.\n"); break;
+			case BZ_DATA_ERROR: fprintf(stderr, "ERROR: corrupt data during decompression.\n"); break;
 			default: fprintf(stderr, "ERROR: an unknown error occured during decompression.\n"); break;
 		}
 		delete [] buf;




More information about the sword-cvs mailing list