summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--recipes/lzma/files/lzma-406-zlib-stream.patch405
-rw-r--r--recipes/lzma/lzma-4.65/001-large_files.patch13
-rw-r--r--recipes/lzma/lzma-4.65/002-lzmp.patch1059
-rw-r--r--recipes/lzma/lzma-4.65/003-compile_fixes.patch26
-rw-r--r--recipes/lzma/lzma-4.65/100-static_library.patch70
-rw-r--r--recipes/lzma/lzma-native_4.17.bb25
-rw-r--r--recipes/lzma/lzma-native_4.65.bb4
-rw-r--r--recipes/lzma/lzma.inc39
-rw-r--r--recipes/lzma/lzma_4.17.bb36
-rw-r--r--recipes/lzma/lzma_4.65.bb2
10 files changed, 1213 insertions, 466 deletions
diff --git a/recipes/lzma/files/lzma-406-zlib-stream.patch b/recipes/lzma/files/lzma-406-zlib-stream.patch
deleted file mode 100644
index 5af976372c..0000000000
--- a/recipes/lzma/files/lzma-406-zlib-stream.patch
+++ /dev/null
@@ -1,405 +0,0 @@
-diff -BurN lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.cpp lzma/SRC/7zip/Compress/LZMA/LZMADecoder.cpp
---- lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.cpp 2004-08-25 01:40:48.000000000 +0400
-+++ lzma/SRC/7zip/Compress/LZMA/LZMADecoder.cpp 2005-01-20 14:47:45.789801629 +0300
-@@ -288,12 +288,17 @@
- Byte remainder = (Byte)(properties[0] / 9);
- int lp = remainder % 5;
- int pb = remainder / 5;
-- if (pb > NLength::kNumPosStatesBitsMax)
-- return E_INVALIDARG;
-- _posStateMask = (1 << pb) - 1;
- UInt32 dictionarySize = 0;
- for (int i = 0; i < 4; i++)
- dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);
-+ return SetDecoderPropertiesRaw(lc, lp, pb, dictionarySize);
-+}
-+
-+STDMETHODIMP CDecoder::SetDecoderPropertiesRaw(int lc, int lp, int pb, UInt32 dictionarySize)
-+{
-+ if (pb > NLength::kNumPosStatesBitsMax)
-+ return E_INVALIDARG;
-+ _posStateMask = (1 << pb) - 1;
- _dictionarySizeCheck = MyMax(dictionarySize, UInt32(1));
- UInt32 blockSize = MyMax(_dictionarySizeCheck, UInt32(1 << 12));
- if (!_outWindowStream.Create(blockSize))
-diff -BurN lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.h lzma/SRC/7zip/Compress/LZMA/LZMADecoder.h
---- lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.h 2004-08-25 01:40:08.000000000 +0400
-+++ lzma/SRC/7zip/Compress/LZMA/LZMADecoder.h 2005-01-20 13:06:59.081297916 +0300
-@@ -234,6 +234,8 @@
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
- STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);
-
-+ STDMETHOD(SetDecoderPropertiesRaw)(int lc, int lp, int pb, UInt32 dictionarySize);
-+
- virtual ~CDecoder() {}
- };
-
-diff -BurN lzma406/SRC/7zip/Compress/LZMA_Lib/makefile lzma/SRC/7zip/Compress/LZMA_Lib/makefile
---- lzma406/SRC/7zip/Compress/LZMA_Lib/makefile 1970-01-01 03:00:00.000000000 +0300
-+++ lzma/SRC/7zip/Compress/LZMA_Lib/makefile 2005-01-19 13:49:20.000000000 +0300
-@@ -0,0 +1,88 @@
-+PROG = liblzma.a
-+CXX = g++ -O3 -Wall
-+AR = ar
-+RM = rm -f
-+CFLAGS = -c
-+
-+OBJS = \
-+ ZLib.o \
-+ LZMADecoder.o \
-+ LZMAEncoder.o \
-+ LZInWindow.o \
-+ LZOutWindow.o \
-+ RangeCoderBit.o \
-+ InBuffer.o \
-+ OutBuffer.o \
-+ FileStreams.o \
-+ Alloc.o \
-+ C_FileIO.o \
-+ CommandLineParser.o \
-+ CRC.o \
-+ String.o \
-+ StringConvert.o \
-+ StringToInt.o \
-+ Vector.o \
-+
-+
-+all: $(PROG)
-+
-+$(PROG): $(OBJS)
-+ $(AR) r $(PROG) $(OBJS)
-+
-+ZLib.o: ZLib.cpp
-+ $(CXX) $(CFLAGS) ZLib.cpp
-+
-+LZMADecoder.o: ../LZMA/LZMADecoder.cpp
-+ $(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp
-+
-+LZMAEncoder.o: ../LZMA/LZMAEncoder.cpp
-+ $(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp
-+
-+LZInWindow.o: ../LZ/LZInWindow.cpp
-+ $(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp
-+
-+LZOutWindow.o: ../LZ/LZOutWindow.cpp
-+ $(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp
-+
-+RangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp
-+ $(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp
-+
-+InBuffer.o: ../../Common/InBuffer.cpp
-+ $(CXX) $(CFLAGS) ../../Common/InBuffer.cpp
-+
-+OutBuffer.o: ../../Common/OutBuffer.cpp
-+ $(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp
-+
-+FileStreams.o: ../../Common/FileStreams.cpp
-+ $(CXX) $(CFLAGS) ../../Common/FileStreams.cpp
-+
-+Alloc.o: ../../../Common/Alloc.cpp
-+ $(CXX) $(CFLAGS) ../../../Common/Alloc.cpp
-+
-+C_FileIO.o: ../../../Common/C_FileIO.cpp
-+ $(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp
-+
-+CommandLineParser.o: ../../../Common/CommandLineParser.cpp
-+ $(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp
-+
-+CRC.o: ../../../Common/CRC.cpp
-+ $(CXX) $(CFLAGS) ../../../Common/CRC.cpp
-+
-+MyWindows.o: ../../../Common/MyWindows.cpp
-+ $(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp
-+
-+String.o: ../../../Common/String.cpp
-+ $(CXX) $(CFLAGS) ../../../Common/String.cpp
-+
-+StringConvert.o: ../../../Common/StringConvert.cpp
-+ $(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp
-+
-+StringToInt.o: ../../../Common/StringToInt.cpp
-+ $(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp
-+
-+Vector.o: ../../../Common/Vector.cpp
-+ $(CXX) $(CFLAGS) ../../../Common/Vector.cpp
-+
-+clean:
-+ -$(RM) $(PROG) $(OBJS)
-+
-diff -BurN lzma406/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp lzma/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp
---- lzma406/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp 1970-01-01 03:00:00.000000000 +0300
-+++ lzma/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp 2005-01-20 15:01:18.439221129 +0300
-@@ -0,0 +1,273 @@
-+/*
-+ * lzma zlib simplified wrapper
-+ *
-+ * Copyright (c) 2005 Oleg I. Vdovikin <oleg@cs.msu.su>
-+ *
-+ * This library is free software; you can redistribute
-+ * it and/or modify it under the terms of the GNU Lesser
-+ * General Public License as published by the Free Software
-+ * Foundation; either version 2.1 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This library is distributed in the hope that it will be
-+ * useful, but WITHOUT ANY WARRANTY; without even the implied
-+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-+ * PURPOSE. See the GNU Lesser General Public License
-+ * for more details.
-+ *
-+ * You should have received a copy of the GNU Lesser General
-+ * Public License along with this library; if not, write to
-+ * the Free Software Foundation, Inc., 59 Temple Place,
-+ * Suite 330, Boston, MA 02111-1307 USA
-+ */
-+
-+/*
-+ * default values for encoder/decoder used by wrapper
-+ */
-+
-+#include <zlib.h>
-+
-+#define ZLIB_LC 3
-+#define ZLIB_LP 0
-+#define ZLIB_PB 2
-+
-+#ifdef WIN32
-+#include <initguid.h>
-+#else
-+#define INITGUID
-+#endif
-+
-+#include "../../../Common/MyWindows.h"
-+#include "../LZMA/LZMADecoder.h"
-+#include "../LZMA/LZMAEncoder.h"
-+
-+#define STG_E_SEEKERROR ((HRESULT)0x80030019L)
-+#define STG_E_MEDIUMFULL ((HRESULT)0x80030070L)
-+
-+class CInMemoryStream:
-+ public IInStream,
-+ public IStreamGetSize,
-+ public CMyUnknownImp
-+{
-+public:
-+ CInMemoryStream(const Bytef *data, UInt64 size) :
-+ m_data(data), m_size(size), m_offset(0) {}
-+
-+ virtual ~CInMemoryStream() {}
-+
-+ MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)
-+
-+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)
-+ {
-+ if (size > m_size - m_offset)
-+ size = m_size - m_offset;
-+
-+ if (size) {
-+ memcpy(data, m_data + m_offset, size);
-+ }
-+
-+ m_offset += size;
-+
-+ if (processedSize)
-+ *processedSize = size;
-+
-+ return S_OK;
-+ }
-+
-+ STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)
-+ {
-+ return Read(data, size, processedSize);
-+ }
-+
-+ STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
-+ {
-+ UInt64 _offset;
-+
-+ if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
-+ else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
-+ else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
-+ else return STG_E_INVALIDFUNCTION;
-+
-+ if (_offset < 0 || _offset > m_size)
-+ return STG_E_SEEKERROR;
-+
-+ m_offset = _offset;
-+
-+ if (newPosition)
-+ *newPosition = m_offset;
-+
-+ return S_OK;
-+ }
-+
-+ STDMETHOD(GetSize)(UInt64 *size)
-+ {
-+ *size = m_size;
-+ return S_OK;
-+ }
-+protected:
-+ const Bytef *m_data;
-+ UInt64 m_size;
-+ UInt64 m_offset;
-+};
-+
-+class COutMemoryStream:
-+ public IOutStream,
-+ public CMyUnknownImp
-+{
-+public:
-+ COutMemoryStream(Bytef *data, UInt64 maxsize) :
-+ m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}
-+ virtual ~COutMemoryStream() {}
-+
-+ MY_UNKNOWN_IMP1(IOutStream)
-+
-+ STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)
-+ {
-+ if (size > m_maxsize - m_offset)
-+ size = m_maxsize - m_offset;
-+
-+ if (size) {
-+ memcpy(m_data + m_offset, data, size);
-+ }
-+
-+ m_offset += size;
-+
-+ if (m_offset > m_size)
-+ m_size = m_offset;
-+
-+ if (processedSize)
-+ *processedSize = size;
-+
-+ return S_OK;
-+ }
-+
-+ STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)
-+ {
-+ return Write(data, size, processedSize);
-+ }
-+
-+ STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
-+ {
-+ UInt64 _offset;
-+
-+ if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
-+ else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
-+ else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
-+ else return STG_E_INVALIDFUNCTION;
-+
-+ if (_offset < 0 || _offset > m_maxsize)
-+ return STG_E_SEEKERROR;
-+
-+ m_offset = _offset;
-+
-+ if (newPosition)
-+ *newPosition = m_offset;
-+
-+ return S_OK;
-+ }
-+
-+ STDMETHOD(SetSize)(Int64 newSize)
-+ {
-+ if ((UInt64)newSize > m_maxsize)
-+ return STG_E_MEDIUMFULL;
-+
-+ return S_OK;
-+ }
-+protected:
-+ Bytef *m_data;
-+ UInt64 m_size;
-+ UInt64 m_maxsize;
-+ UInt64 m_offset;
-+};
-+
-+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
-+ const Bytef *source, uLong sourceLen,
-+ int level))
-+{
-+ CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
-+ CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
-+
-+ COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
-+ CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
-+
-+ NCompress::NLZMA::CEncoder *encoderSpec =
-+ new NCompress::NLZMA::CEncoder;
-+ CMyComPtr<ICompressCoder> encoder = encoderSpec;
-+
-+ PROPID propIDs[] =
-+ {
-+ NCoderPropID::kDictionarySize,
-+ NCoderPropID::kPosStateBits,
-+ NCoderPropID::kLitContextBits,
-+ NCoderPropID::kLitPosBits,
-+ NCoderPropID::kAlgorithm,
-+ NCoderPropID::kNumFastBytes,
-+ NCoderPropID::kMatchFinder,
-+ NCoderPropID::kEndMarker
-+ };
-+ const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
-+
-+ PROPVARIANT properties[kNumProps];
-+ for (int p = 0; p < 6; p++)
-+ properties[p].vt = VT_UI4;
-+ properties[0].ulVal = UInt32(1 << (level + 14));
-+ properties[1].ulVal = UInt32(ZLIB_PB);
-+ properties[2].ulVal = UInt32(ZLIB_LC); // for normal files
-+ properties[3].ulVal = UInt32(ZLIB_LP); // for normal files
-+ properties[4].ulVal = UInt32(2);
-+ properties[5].ulVal = UInt32(128);
-+
-+ properties[6].vt = VT_BSTR;
-+ properties[6].bstrVal = (BSTR)(const wchar_t *)L"BT4";
-+
-+ properties[7].vt = VT_BOOL;
-+ properties[7].boolVal = VARIANT_TRUE;
-+
-+ if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
-+ return Z_MEM_ERROR; // should not happen
-+
-+ HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);
-+ if (result == E_OUTOFMEMORY)
-+ {
-+ return Z_MEM_ERROR;
-+ }
-+ else if (result != S_OK)
-+ {
-+ return Z_BUF_ERROR; // should not happen
-+ }
-+
-+ UInt64 fileSize;
-+ outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
-+ *destLen = fileSize;
-+
-+ return Z_OK;
-+}
-+
-+ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
-+ const Bytef *source, uLong sourceLen))
-+{
-+ CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
-+ CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
-+
-+ COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
-+ CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
-+
-+ NCompress::NLZMA::CDecoder *decoderSpec =
-+ new NCompress::NLZMA::CDecoder;
-+ CMyComPtr<ICompressCoder> decoder = decoderSpec;
-+
-+ if (decoderSpec->SetDecoderPropertiesRaw(ZLIB_LC,
-+ ZLIB_LP, ZLIB_PB, (1 << 23)) != S_OK) return Z_DATA_ERROR;
-+
-+ UInt64 fileSize = *destLen;
-+
-+ if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)
-+ {
-+ return Z_DATA_ERROR;
-+ }
-+
-+ outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
-+ *destLen = fileSize;
-+
-+ return Z_OK;
-+}
diff --git a/recipes/lzma/lzma-4.65/001-large_files.patch b/recipes/lzma/lzma-4.65/001-large_files.patch
new file mode 100644
index 0000000000..b95fe9e90f
--- /dev/null
+++ b/recipes/lzma/lzma-4.65/001-large_files.patch
@@ -0,0 +1,13 @@
+Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc
+===================================================================
+--- lzma-4.65.orig/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-05-15 23:33:51.000000000 +0200
++++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-06-01 22:00:54.000000000 +0200
+@@ -3,7 +3,7 @@
+ CXX_C = gcc -O2 -Wall
+ LIB = -lm
+ RM = rm -f
+-CFLAGS = -c
++CFLAGS = -c -D_FILE_OFFSET_BITS=64
+
+ ifdef SystemDrive
+ IS_MINGW = 1
diff --git a/recipes/lzma/lzma-4.65/002-lzmp.patch b/recipes/lzma/lzma-4.65/002-lzmp.patch
new file mode 100644
index 0000000000..72d881cdb2
--- /dev/null
+++ b/recipes/lzma/lzma-4.65/002-lzmp.patch
@@ -0,0 +1,1059 @@
+Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzmp.cpp
+===================================================================
+--- /dev/null 1970-01-01 00:00:00.000000000 +0000
++++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzmp.cpp 2009-06-01 22:01:10.000000000 +0200
+@@ -0,0 +1,895 @@
++/*
++ * LZMA command line tool similar to gzip to encode and decode LZMA files.
++ *
++ * Copyright (C) 2005 Ville Koskinen
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License
++ * as published by the Free Software Foundation; either version 2
++ * of the License, or (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
++ * USA.
++ */
++
++#include "../../../Common/MyInitGuid.h"
++
++#include <iostream>
++using std::cout;
++using std::cerr;
++using std::endl;
++
++#include <cstdio>
++#include <cstdlib>
++#include <cstring>
++
++#include <string>
++using std::string;
++#include <vector>
++using std::vector;
++typedef vector<string> stringVector;
++
++#include <unistd.h>
++#include <getopt.h>
++#include <signal.h>
++
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <utime.h>
++#include <sys/time.h> // futimes()
++
++// For Solaris
++#ifndef HAVE_FUTIMES
++//#define futimes(fd, tv) futimesat(fd, NULL, tv)
++#endif
++
++#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
++#include <fcntl.h>
++#include <io.h>
++#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)
++#else
++#define MY_SET_BINARY_MODE(file)
++#endif
++
++#include "../../../7zip/Common/FileStreams.h"
++
++#include "../../../Common/Types.h"
++
++#include "../../../7zip/Compress/LzmaDecoder.h"
++#include "../../../7zip/Compress/LzmaEncoder.h"
++
++#include "Exception.h"
++
++#include "lzma_version.h"
++
++namespace lzma {
++
++const char *PROGRAM_VERSION = PACKAGE_VERSION;
++const char *PROGRAM_COPYRIGHT = "Copyright (C) 2006 Ville Koskinen";
++
++/* LZMA_Alone switches:
++ -a{N}: set compression mode - [0, 2], default: 2 (max)
++ -d{N}: set dictionary - [0,28], default: 23 (8MB)
++ -fb{N}: set number of fast bytes - [5, 255], default: 128
++ -lc{N}: set number of literal context bits - [0, 8], default: 3
++ -lp{N}: set number of literal pos bits - [0, 4], default: 0
++ -pb{N}: set number of pos bits - [0, 4], default: 2
++ -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, bt4b, pat2r, pat2,
++ pat2h, pat3h, pat4h, hc3, hc4], default: bt4
++*/
++
++struct lzma_option {
++ short compression_mode; // -a
++ short dictionary; // -d
++ short fast_bytes; // -fb
++ wchar_t *match_finder; // -mf
++ short literal_context_bits; // -lc
++ short literal_pos_bits; // -lp
++ short pos_bits; // -pb
++};
++
++/* The following is a mapping from gzip/bzip2 style -1 .. -9 compression modes
++ * to the corresponding LZMA compression modes. Thanks, Larhzu, for coining
++ * these. */
++const lzma_option option_mapping[] = {
++ { 0, 0, 0, NULL, 0, 0, 0}, // -0 (needed for indexing)
++ { 0, 16, 64, L"hc4", 3, 0, 2}, // -1
++ { 0, 20, 64, L"hc4", 3, 0, 2}, // -2
++ { 1, 19, 64, L"bt4", 3, 0, 2}, // -3
++ { 2, 20, 64, L"bt4", 3, 0, 2}, // -4
++ { 2, 21, 128, L"bt4", 3, 0, 2}, // -5
++ { 2, 22, 128, L"bt4", 3, 0, 2}, // -6
++ { 2, 23, 128, L"bt4", 3, 0, 2}, // -7
++ { 2, 24, 255, L"bt4", 3, 0, 2}, // -8
++ { 2, 25, 255, L"bt4", 3, 0, 2}, // -9
++};
++
++struct extension_pair {
++ char *from;
++ char *to;
++};
++
++const extension_pair known_extensions[] = {
++ { ".lzma", "" },
++ { ".tlz", ".tar" },
++ { NULL, NULL }
++};
++
++/* Sorry, I just happen to like enumerations. */
++enum PROGRAM_MODE {
++ PM_COMPRESS = 0,
++ PM_DECOMPRESS,
++ PM_TEST,
++ PM_HELP,
++ PM_LICENSE,
++ PM_VERSION
++};
++
++enum {
++ STATUS_OK = 0,
++ STATUS_ERROR = 1,
++ STATUS_WARNING = 2
++};
++
++/* getopt options. */
++/* struct option { name, has_arg, flag, val } */
++const struct option long_options[] = {
++ { "stdout", 0, 0, 'c' },
++ { "decompress", 0, 0, 'd' },
++ { "compress", 0, 0, 'z' },
++ { "keep", 0, 0, 'k' },
++ { "force", 0, 0, 'f' },
++ { "test", 0, 0, 't' },
++ { "suffix", 1, 0, 'S' },
++ { "quiet", 0, 0, 'q' },
++ { "verbose", 0, 0, 'v' },
++ { "help", 0, 0, 'h' },
++ { "license", 0, 0, 'L' },
++ { "version", 0, 0, 'V' },
++ { "fast", 0, 0, '1' },
++ { "best", 0, 0, '9' },
++ { 0, 0, 0, 0 }
++};
++
++/* getopt option string (for the above options). */
++const char option_string[] = "cdzkftS:qvhLV123456789A:D:F:";
++
++/* Defaults. */
++PROGRAM_MODE program_mode = PM_COMPRESS;
++int verbosity = 0;
++bool stdinput = false;
++bool stdoutput = false;
++bool keep = false;
++bool force = false;
++int compression_mode = 7;
++//char *suffix = strdup(".lzma");
++char *suffix = strdup(known_extensions[0].from);
++lzma_option advanced_options = { -1, -1, -1, NULL, -1, -1, -1 };
++
++void print_help(const char *const argv0)
++{
++ // Help goes to stdout while other messages go to stderr.
++ cout << "\nlzma " << PROGRAM_VERSION
++ << " " << PROGRAM_COPYRIGHT << "\n"
++ "Based on LZMA SDK " << LZMA_SDK_VERSION_STRING << " "
++ << LZMA_SDK_COPYRIGHT_STRING
++ << "\n\nUsage: " << argv0
++ << " [flags and input files in any order]\n"
++" -c --stdout output to standard output\n"
++" -d --decompress force decompression\n"
++" -z --compress force compression\n"
++" -k --keep keep (don't delete) input files\n"
++" -f --force force overwrite of output file and compress links\n"
++" -t --test test compressed file integrity\n"
++" -S .suf --suffix .suf use suffix .suf on compressed files\n"
++" -q --quiet suppress error messages\n"
++" -v --verbose be verbose\n"
++" -h --help print this message\n"
++" -L --license display the license information\n"
++" -V --version display version numbers of LZMA SDK and lzma\n"
++" -1 .. -2 fast compression\n"
++" -3 .. -9 good to excellent compression. -7 is the default.\n"
++" --fast alias for -1\n"
++" --best alias for -9 (usually *not* what you want)\n\n"
++" Memory usage depends a lot on the chosen compression mode -1 .. -9.\n"
++" See the man page lzma(1) for details.\n\n";
++}
++
++void print_license(void)
++{
++ cout << "\n LZMA command line tool " << PROGRAM_VERSION << " - "
++ << PROGRAM_COPYRIGHT
++ << "\n LZMA SDK " << LZMA_SDK_VERSION_STRING << " - "
++ << LZMA_SDK_COPYRIGHT_STRING
++ << "\n This program is a part of the LZMA utils package.\n"
++ " http://tukaani.org/lzma/\n\n"
++" This program is free software; you can redistribute it and/or\n"
++" modify it under the terms of the GNU General Public License\n"
++" as published by the Free Software Foundation; either version 2\n"
++" of the License, or (at your option) any later version.\n"
++"\n"
++" This program is distributed in the hope that it will be useful,\n"
++" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
++" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
++" GNU General Public License for more details.\n"
++"\n";
++}
++
++void print_version(void)
++{
++ cout << "LZMA command line tool " << PROGRAM_VERSION << "\n"
++ << "LZMA SDK " << LZMA_SDK_VERSION_STRING << "\n";
++}
++
++short str2int (const char *str, const int &min, const int &max)
++{
++ int value = -1;
++ char *endptr = NULL;
++ if (str == NULL || str[0] == '\0')
++ throw ArgumentException("Invalid integer option");
++ value = strtol (str, &endptr, 10);
++ if (*endptr != '\0' || value < min || value > max)
++ throw ArgumentException("Invalid integer option");
++ return value;
++}
++
++void parse_options(int argc, char **argv, stringVector &filenames)
++{
++ /* Snatched from getopt(3). */
++ int c;
++
++ /* Check how we were called */
++ {
++ char *p = strrchr (argv[0], '/'); // Remove path prefix, if any
++ if (p++ == NULL)
++ p = argv[0];
++ if (strstr (p, "un") != NULL) {
++ program_mode = PM_DECOMPRESS;
++ } else if (strstr (p, "cat") != NULL) {
++ program_mode = PM_DECOMPRESS;
++ stdoutput = true;
++ }
++ }
++
++ while (-1 != (c = getopt_long(argc, argv, option_string,
++ long_options, NULL))) {
++ switch (c) {
++ // stdout
++ case 'c':
++ stdoutput = true;
++ break;
++
++ // decompress
++ case 'd':
++ program_mode = PM_DECOMPRESS;
++ break;
++
++ // compress
++ case 'z':
++ program_mode = PM_COMPRESS;
++ break;
++
++ // keep
++ case 'k':
++ keep = true;
++ break;
++
++ // force
++ case 'f':
++ force = true;
++ break;
++
++ // test
++ case 't':
++ program_mode = PM_TEST;
++ break;
++
++ // suffix
++ case 'S':
++ if (optarg) {
++ free(suffix);
++ suffix = strdup(optarg);
++ }
++ break;
++
++ // quiet
++ case 'q':
++ verbosity = 0;
++ break;
++
++ // verbose
++ case 'v':
++ verbosity++;
++ break;
++
++ // help
++ case 'h':
++ program_mode = PM_HELP;
++ break;
++
++ // license
++ case 'L':
++ program_mode = PM_LICENSE;
++ break;
++
++ // version
++ case 'V':
++ program_mode = PM_VERSION;
++ break;
++
++ case '1': case '2': case '3': case '4': case '5':
++ case '6': case '7': case '8': case '9':
++ compression_mode = c - '0';
++ break;
++
++ // Advanced options //
++ // Compression mode
++ case 'A':
++ advanced_options.compression_mode =
++ str2int (optarg, 0, 2);
++ break;
++
++ // Dictionary size
++ case 'D':
++ advanced_options.dictionary =
++ str2int (optarg, 0, 28);
++ break;
++
++ // Fast bytes
++ case 'F':
++ advanced_options.fast_bytes =
++ str2int (optarg, 0, 273);
++ break;
++
++ default:
++ throw ArgumentException("");
++ break;
++ } // switch(c)
++ } // while(1)
++
++ for (int i = optind; i < argc; i++) {
++ if (strcmp("-", argv[i]) == 0)
++ continue;
++ filenames.push_back(argv[i]);
++ }
++} // parse_options
++
++void set_encoder_properties(NCompress::NLzma::CEncoder *encoder,
++ lzma_option &opt)
++{
++ /* Almost verbatim from LzmaAlone.cpp. */
++ PROPID propIDs[] =
++ {
++ NCoderPropID::kDictionarySize,
++ NCoderPropID::kPosStateBits,
++ NCoderPropID::kLitContextBits,
++ NCoderPropID::kLitPosBits,
++ NCoderPropID::kAlgorithm,
++ NCoderPropID::kNumFastBytes,
++ NCoderPropID::kMatchFinder,
++ NCoderPropID::kEndMarker
++ };
++ const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
++#define VALUE(x) (advanced_options.x >= 0 ? advanced_options.x : opt.x)
++ PROPVARIANT properties[kNumProps];
++ for (int p = 0; p < 6; p++)
++ properties[p].vt = VT_UI4;
++ properties[0].ulVal = UInt32(1 << VALUE (dictionary));
++ properties[1].ulVal = UInt32(VALUE (pos_bits));
++ properties[2].ulVal = UInt32(VALUE (literal_context_bits));
++ properties[3].ulVal = UInt32(VALUE (literal_pos_bits));
++ properties[4].ulVal = UInt32(VALUE (compression_mode));
++ properties[5].ulVal = UInt32(VALUE (fast_bytes));
++#undef VALUE
++
++ properties[6].vt = VT_BSTR;
++ properties[6].bstrVal = (BSTR)opt.match_finder;
++
++ properties[7].vt = VT_BOOL;
++ properties[7].boolVal = stdinput ? VARIANT_TRUE : VARIANT_FALSE;
++
++ if (encoder->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
++ throw Exception("SetCoderProperties() error");
++}
++
++void encode(NCompress::NLzma::CEncoder *encoderSpec,
++ CMyComPtr<ISequentialInStream> inStream,
++ CMyComPtr<ISequentialOutStream> outStream,
++ lzma_option encoder_options,
++ UInt64 fileSize)
++{
++ set_encoder_properties(encoderSpec, encoder_options);
++
++ encoderSpec->WriteCoderProperties(outStream);
++
++ for (int i = 0; i < 8; i++)
++ {
++ Byte b = Byte(fileSize >> (8 * i));
++ if (outStream->Write(&b, sizeof(b), 0) != S_OK)
++ throw Exception("Write error while encoding");
++ }
++
++ HRESULT result = encoderSpec->Code(inStream, outStream, 0, 0, 0);
++
++ if (result == E_OUTOFMEMORY)
++ throw Exception("Cannot allocate memory");
++ else if (result != S_OK) {
++ char buffer[33];
++ snprintf(buffer, 33, "%d", (unsigned int)result);
++ throw Exception(string("Encoder error: ") + buffer);
++ }
++}
++
++void decode(NCompress::NLzma::CDecoder *decoderSpec,
++ CMyComPtr<ISequentialInStream> inStream,
++ CMyComPtr<ISequentialOutStream> outStream)
++{
++ const UInt32 kPropertiesSize = 5;
++ Byte properties[kPropertiesSize];
++ UInt32 processedSize;
++ UInt64 fileSize = 0;
++
++ if (inStream->Read(properties, kPropertiesSize, &processedSize) != S_OK)
++ throw Exception("Read error");
++ if (processedSize != kPropertiesSize)
++ throw Exception("Read error");
++ if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)
++ throw Exception("SetDecoderProperties() error");
++
++ for (int i = 0; i < 8; i++)
++ {
++ Byte b;
++
++ if (inStream->Read(&b, sizeof(b), &processedSize) != S_OK)
++ throw Exception("Read error");
++ if (processedSize != 1)
++ throw Exception("Read error");
++
++ fileSize |= ((UInt64)b) << (8 * i);
++ }
++
++ if (decoderSpec->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)
++ throw Exception("Decoder error");
++}
++
++int open_instream(const string infile,
++ CMyComPtr<ISequentialInStream> &inStream,
++ UInt64 &fileSize)
++{
++ CInFileStream *inStreamSpec = new CInFileStream;
++ inStream = inStreamSpec;
++ if (!inStreamSpec->Open(infile.c_str()))
++ throw Exception("Cannot open input file " + infile);
++
++ inStreamSpec->File.GetLength(fileSize);
++
++ return inStreamSpec->File.GetHandle();
++}
++
++int open_outstream(const string outfile,
++ CMyComPtr<ISequentialOutStream> &outStream)
++{
++ COutFileStream *outStreamSpec = new COutFileStream;
++ outStream = outStreamSpec;
++
++ bool open_by_force = (program_mode == PM_TEST) | force;
++
++ if (!outStreamSpec->Create(outfile.c_str(), open_by_force))
++ throw Exception("Cannot open output file " + outfile);
++
++ return outStreamSpec->File.GetHandle();
++}
++
++double get_ratio(int inhandle, int outhandle)
++{
++ struct stat in_stats, out_stats;
++ fstat(inhandle, &in_stats);
++ fstat(outhandle, &out_stats);
++
++ return (double)out_stats.st_size / (double)in_stats.st_size;
++}
++
++mode_t get_file_mode(string filename)
++{
++ struct stat in_stat;
++ lstat(filename.c_str(), &in_stat);
++
++ return in_stat.st_mode;
++}
++
++bool string_ends_with(string str, string ending)
++{
++ return equal(ending.rbegin(), ending.rend(), str.rbegin());
++}
++
++bool extension_is_known(string filename)
++{
++ bool known_format = false;
++ extension_pair extension; int i = 1;
++
++ extension = known_extensions[0];
++ while (extension.from != NULL) {
++ if (string_ends_with(filename, extension.from)) {
++ known_format = true;
++ break;
++ }
++ extension = known_extensions[i];
++ i++;
++ }
++
++ if (!known_format) {
++ if (!string_ends_with(filename, suffix)) {
++ return false;
++ }
++ }
++
++ return true;
++}
++
++string replace_extension(string filename)
++{
++ int suffix_starts_at = filename.length() - strlen (suffix);
++ string from_suffix = filename.substr(suffix_starts_at, strlen (suffix));
++ string ret = filename.substr(0, suffix_starts_at);
++ extension_pair extension; int i = 1;
++
++ bool found_replacement = false;
++ extension = known_extensions[0];
++ while (extension.from != NULL) {
++ if (from_suffix.compare(extension.from) == 0) {
++ ret += extension.to;
++ found_replacement = true;
++ break;
++ }
++
++ extension = known_extensions[i];
++ i++;
++ }
++
++ return ret;
++}
++
++string pretty_print_status(string filename, string output_filename,
++ string ratio)
++{
++ string ret = "";
++
++ ret += filename;
++ ret += ":\t ";
++
++ if (program_mode == PM_TEST) {
++ ret += "decoded succesfully";
++
++ return ret;
++ }
++
++ if (!stdinput && !stdoutput) {
++ ret += ratio;
++ ret += " -- ";
++ }
++
++ if (program_mode == PM_COMPRESS) {
++ if (keep) {
++ ret += "encoded succesfully";
++
++ return ret;
++ }
++
++ ret += "replaced with ";
++ ret += output_filename;
++
++ return ret;
++ }
++
++ if (program_mode == PM_DECOMPRESS) {
++ if (keep) {
++ ret += "decoded succesfully";
++
++ return ret;
++ }
++
++ ret += "replaced with ";
++ ret += output_filename;
++
++ return ret;
++ }
++
++ return ret;
++}
++
++static string archive_name; // I know, it is crude, but I haven't found any other
++ // way then making a global variable to transfer filename to handler
++
++void signal_handler (int signum)
++{
++ unlink (archive_name.c_str()); // deleting
++ signal (signum, SIG_DFL); // we return the default function to used signal
++ kill (getpid(), signum); // and then send this signal to the process again
++}
++
++} // namespace lzma
++
++
++int main(int argc, char **argv)
++{
++ using namespace lzma;
++ using std::cerr;
++
++ stringVector filenames;
++
++ signal (SIGTERM,signal_handler);
++ signal (SIGHUP,signal_handler);
++ signal (SIGINT,signal_handler);
++
++ try {
++ parse_options(argc, argv, filenames);
++ }
++ catch (...) {
++ return STATUS_ERROR;
++ }
++
++ if (program_mode == PM_HELP) {
++ print_help(argv[0]);
++ return STATUS_OK;
++ }
++ else if (program_mode == PM_LICENSE) {
++ print_license();
++ return STATUS_OK;
++ }
++ else if (program_mode == PM_VERSION) {
++ print_version();
++ return STATUS_OK;
++ }
++
++ if (filenames.empty()) {
++ stdinput = true;
++ stdoutput = true;
++
<