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

chrislit at crosswire.org chrislit at crosswire.org
Sat Mar 1 10:22:56 MST 2014


Author: chrislit
Date: 2014-03-01 10:22:56 -0700 (Sat, 01 Mar 2014)
New Revision: 3041

Modified:
   trunk/configure.ac
   trunk/include/xzcomprs.h
   trunk/src/modules/common/xzcomprs.cpp
Log:
added xz compression (*not tested & unlikely to work correctly, but it compiles via autotools*)


Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2014-03-01 13:36:02 UTC (rev 3040)
+++ trunk/configure.ac	2014-03-01 17:22:56 UTC (rev 3041)
@@ -51,6 +51,8 @@
 	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(xz,
+	AC_HELP_STRING([--with-xz],[allow xz compressed modules (default=yes)]),,with_xz=yes)
 AC_ARG_WITH(icu,
 	AC_HELP_STRING([--with-icu],[use ICU for unicode (default=yes)]),,with_icu=yes)
 AC_ARG_WITH(icusword,
@@ -138,6 +140,17 @@
 	AM_CXXFLAGS="$AM_CXXFLAGS -DEXCLUDEBZIP2"
 fi
 
+if test x$with_xz  = xyes; then
+	AC_CHECK_LIB(lzma, lzma_block_buffer_encode,,with_xz="no")
+else
+	with_xz="no"
+fi
+
+if test x$with_xz = xno; then
+	AM_CFLAGS="$AM_CFLAGS -DEXCLUDEXZ"
+	AM_CXXFLAGS="$AM_CXXFLAGS -DEXCLUDEXZ"
+fi
+
 AS_IF([test "x$with_internalregex" = "xyes"],
       [have_systemregex="no"],
       [AC_SEARCH_LIBS(regexec, regex, [have_systemregex="yes"], [have_systemregex="no"])])
@@ -413,6 +426,7 @@
 echo     "     BUILD UTILITIES:  $enable_utilities"
 echo     "     LIBZ:             $with_zlib"
 echo     "     BZIP2:            $with_bzip2"
+echo     "     XZ:               $with_xz"
 echo     "     ICU:              $with_icu"
 echo     "     ICUSWORD:         $with_icusword"
 echo     "     CXX11REGEX:       $with_cxx11regex"

Modified: trunk/include/xzcomprs.h
===================================================================
--- trunk/include/xzcomprs.h	2014-03-01 13:36:02 UTC (rev 3040)
+++ trunk/include/xzcomprs.h	2014-03-01 17:22:56 UTC (rev 3041)
@@ -28,6 +28,8 @@
 
 #include <defs.h>
 
+#include <lzma.h>
+
 SWORD_NAMESPACE_START
 
 class SWDLLEXPORT XzCompress : public SWCompress {
@@ -39,6 +41,8 @@
 
 	virtual void Encode(void);
 	virtual void Decode(void);
+private:
+	lzma_block block;
 };
 
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/common/xzcomprs.cpp
===================================================================
--- trunk/src/modules/common/xzcomprs.cpp	2014-03-01 13:36:02 UTC (rev 3040)
+++ trunk/src/modules/common/xzcomprs.cpp	2014-03-01 17:22:56 UTC (rev 3041)
@@ -26,7 +26,6 @@
 #include <string.h>
 #include <stdio.h>
 #include <xzcomprs.h>
-#include <zlib.h>
 
 SWORD_NAMESPACE_START
 
@@ -59,20 +58,6 @@
 
 void XzCompress::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 +76,13 @@
 	}
 
 
-	zlen = (long) (len*1.001)+15;
+	zlen = (long) (len*1.001)+15;  // TODO: check that this is sufficient
 	char *zbuf = new char[zlen+1];
+	size_t zpos = 0;
 	if (len)
 	{
 		//printf("Doing compress\n");
-		if (compress((Bytef*)zbuf, &zlen, (const Bytef*)buf, len) != Z_OK)
+		if (lzma_block_buffer_encode(&block, NULL, (const uint8_t*)buf, (size_t)len, (uint8_t*)zbuf, &zpos, (size_t)zlen) != LZMA_OK)
 		{
 			printf("ERROR in compression\n");
 		}
@@ -123,24 +109,6 @@
 
 void XzCompress::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);
@@ -162,11 +130,14 @@
 		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;
+		size_t zpos = 0;
+		size_t bpos = 0;
+
+		switch (lzma_block_buffer_decode(&block, NULL, (const uint8_t*)zbuf, &zpos, (size_t)zlen, (uint8_t*)buf, &bpos, (size_t)&blen)){
+			case LZMA_OK: SendChars(buf, blen); slen = blen; break;
+			case LZMA_MEM_ERROR: fprintf(stderr, "ERROR: not enough memory during decompression.\n"); break;
+			case LZMA_BUF_ERROR: fprintf(stderr, "ERROR: not enough room in the out buffer during decompression.\n"); break;
+			case LZMA_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