upgrade lzma sdk to 4.32
[openwrt/openwrt.git] / openwrt / target / lzma / lzma-zlib.patch
1 diff -Nur lzma432/C/7zip/Compress/LZMA_Lib/makefile lzma432-owrt/C/7zip/Compress/LZMA_Lib/makefile
2 --- lzma432/C/7zip/Compress/LZMA_Lib/makefile 1970-01-01 01:00:00.000000000 +0100
3 +++ lzma432-owrt/C/7zip/Compress/LZMA_Lib/makefile 2006-03-22 14:23:38.000000000 +0100
4 @@ -0,0 +1,88 @@
5 +PROG = liblzma.a
6 +CXX = g++ -O3 -Wall
7 +AR = ar
8 +RM = rm -f
9 +CFLAGS = -c
10 +
11 +OBJS = \
12 + ZLib.o \
13 + LZMADecoder.o \
14 + LZMAEncoder.o \
15 + LZInWindow.o \
16 + LZOutWindow.o \
17 + RangeCoderBit.o \
18 + InBuffer.o \
19 + OutBuffer.o \
20 + FileStreams.o \
21 + Alloc.o \
22 + C_FileIO.o \
23 + CommandLineParser.o \
24 + CRC.o \
25 + String.o \
26 + StringConvert.o \
27 + StringToInt.o \
28 + Vector.o \
29 +
30 +
31 +all: $(PROG)
32 +
33 +$(PROG): $(OBJS)
34 + $(AR) r $(PROG) $(OBJS)
35 +
36 +ZLib.o: ZLib.cpp
37 + $(CXX) $(CFLAGS) ZLib.cpp
38 +
39 +LZMADecoder.o: ../LZMA/LZMADecoder.cpp
40 + $(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp
41 +
42 +LZMAEncoder.o: ../LZMA/LZMAEncoder.cpp
43 + $(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp
44 +
45 +LZInWindow.o: ../LZ/LZInWindow.cpp
46 + $(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp
47 +
48 +LZOutWindow.o: ../LZ/LZOutWindow.cpp
49 + $(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp
50 +
51 +RangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp
52 + $(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp
53 +
54 +InBuffer.o: ../../Common/InBuffer.cpp
55 + $(CXX) $(CFLAGS) ../../Common/InBuffer.cpp
56 +
57 +OutBuffer.o: ../../Common/OutBuffer.cpp
58 + $(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp
59 +
60 +FileStreams.o: ../../Common/FileStreams.cpp
61 + $(CXX) $(CFLAGS) ../../Common/FileStreams.cpp
62 +
63 +Alloc.o: ../../../Common/Alloc.cpp
64 + $(CXX) $(CFLAGS) ../../../Common/Alloc.cpp
65 +
66 +C_FileIO.o: ../../../Common/C_FileIO.cpp
67 + $(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp
68 +
69 +CommandLineParser.o: ../../../Common/CommandLineParser.cpp
70 + $(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp
71 +
72 +CRC.o: ../../../Common/CRC.cpp
73 + $(CXX) $(CFLAGS) ../../../Common/CRC.cpp
74 +
75 +MyWindows.o: ../../../Common/MyWindows.cpp
76 + $(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp
77 +
78 +String.o: ../../../Common/String.cpp
79 + $(CXX) $(CFLAGS) ../../../Common/String.cpp
80 +
81 +StringConvert.o: ../../../Common/StringConvert.cpp
82 + $(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp
83 +
84 +StringToInt.o: ../../../Common/StringToInt.cpp
85 + $(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp
86 +
87 +Vector.o: ../../../Common/Vector.cpp
88 + $(CXX) $(CFLAGS) ../../../Common/Vector.cpp
89 +
90 +clean:
91 + -$(RM) $(PROG) $(OBJS)
92 +
93 diff -Nur lzma432/C/7zip/Compress/LZMA_Lib/ZLib.cpp lzma432-owrt/C/7zip/Compress/LZMA_Lib/ZLib.cpp
94 --- lzma432/C/7zip/Compress/LZMA_Lib/ZLib.cpp 1970-01-01 01:00:00.000000000 +0100
95 +++ lzma432-owrt/C/7zip/Compress/LZMA_Lib/ZLib.cpp 2006-03-22 14:23:38.000000000 +0100
96 @@ -0,0 +1,283 @@
97 +/*
98 + * lzma zlib simplified wrapper
99 + *
100 + * Copyright (c) 2005 Oleg I. Vdovikin <oleg@cs.msu.su>
101 + * Modified for LZMA 4.27 SDK Craig.Peacock@beyondlogic.org
102 + *
103 + * This library is free software; you can redistribute
104 + * it and/or modify it under the terms of the GNU Lesser
105 + * General Public License as published by the Free Software
106 + * Foundation; either version 2.1 of the License, or
107 + * (at your option) any later version.
108 + *
109 + * This library is distributed in the hope that it will be
110 + * useful, but WITHOUT ANY WARRANTY; without even the implied
111 + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
112 + * PURPOSE. See the GNU Lesser General Public License
113 + * for more details.
114 + *
115 + * You should have received a copy of the GNU Lesser General
116 + * Public License along with this library; if not, write to
117 + * the Free Software Foundation, Inc., 59 Temple Place,
118 + * Suite 330, Boston, MA 02111-1307 USA
119 + */
120 +
121 +/*
122 + * default values for encoder/decoder used by wrapper
123 + */
124 +
125 +#include <zlib.h>
126 +
127 +#define ZLIB_LC 3
128 +#define ZLIB_LP 0
129 +#define ZLIB_PB 2
130 +
131 +#ifdef WIN32
132 +#include <initguid.h>
133 +#else
134 +#define INITGUID
135 +#endif
136 +
137 +#include "../../../Common/MyWindows.h"
138 +#include "../LZMA/LZMADecoder.h"
139 +#include "../LZMA/LZMAEncoder.h"
140 +
141 +#define STG_E_SEEKERROR ((HRESULT)0x80030019L)
142 +#define STG_E_MEDIUMFULL ((HRESULT)0x80030070L)
143 +
144 +class CInMemoryStream:
145 + public IInStream,
146 + public IStreamGetSize,
147 + public CMyUnknownImp
148 +{
149 +public:
150 + CInMemoryStream(const Bytef *data, UInt64 size) :
151 + m_data(data), m_size(size), m_offset(0) {}
152 +
153 + virtual ~CInMemoryStream() {}
154 +
155 + MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)
156 +
157 + STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)
158 + {
159 + if (size > m_size - m_offset)
160 + size = m_size - m_offset;
161 +
162 + if (size) {
163 + memcpy(data, m_data + m_offset, size);
164 + }
165 +
166 + m_offset += size;
167 +
168 + if (processedSize)
169 + *processedSize = size;
170 +
171 + return S_OK;
172 + }
173 +
174 + STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)
175 + {
176 + return Read(data, size, processedSize);
177 + }
178 +
179 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
180 + {
181 + UInt64 _offset;
182 +
183 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
184 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
185 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
186 + else return STG_E_INVALIDFUNCTION;
187 +
188 + if (_offset < 0 || _offset > m_size)
189 + return STG_E_SEEKERROR;
190 +
191 + m_offset = _offset;
192 +
193 + if (newPosition)
194 + *newPosition = m_offset;
195 +
196 + return S_OK;
197 + }
198 +
199 + STDMETHOD(GetSize)(UInt64 *size)
200 + {
201 + *size = m_size;
202 + return S_OK;
203 + }
204 +protected:
205 + const Bytef *m_data;
206 + UInt64 m_size;
207 + UInt64 m_offset;
208 +};
209 +
210 +class COutMemoryStream:
211 + public IOutStream,
212 + public CMyUnknownImp
213 +{
214 +public:
215 + COutMemoryStream(Bytef *data, UInt64 maxsize) :
216 + m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}
217 + virtual ~COutMemoryStream() {}
218 +
219 + MY_UNKNOWN_IMP1(IOutStream)
220 +
221 + STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)
222 + {
223 + if (size > m_maxsize - m_offset)
224 + size = m_maxsize - m_offset;
225 +
226 + if (size) {
227 + memcpy(m_data + m_offset, data, size);
228 + }
229 +
230 + m_offset += size;
231 +
232 + if (m_offset > m_size)
233 + m_size = m_offset;
234 +
235 + if (processedSize)
236 + *processedSize = size;
237 +
238 + return S_OK;
239 + }
240 +
241 + STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)
242 + {
243 + return Write(data, size, processedSize);
244 + }
245 +
246 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
247 + {
248 + UInt64 _offset;
249 +
250 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
251 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
252 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
253 + else return STG_E_INVALIDFUNCTION;
254 +
255 + if (_offset < 0 || _offset > m_maxsize)
256 + return STG_E_SEEKERROR;
257 +
258 + m_offset = _offset;
259 +
260 + if (newPosition)
261 + *newPosition = m_offset;
262 +
263 + return S_OK;
264 + }
265 +
266 + STDMETHOD(SetSize)(Int64 newSize)
267 + {
268 + if ((UInt64)newSize > m_maxsize)
269 + return STG_E_MEDIUMFULL;
270 +
271 + return S_OK;
272 + }
273 +protected:
274 + Bytef *m_data;
275 + UInt64 m_size;
276 + UInt64 m_maxsize;
277 + UInt64 m_offset;
278 +};
279 +
280 +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
281 + const Bytef *source, uLong sourceLen,
282 + int level))
283 +{
284 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
285 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
286 +
287 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest+4, (*destLen)-4);
288 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
289 +
290 + NCompress::NLZMA::CEncoder *encoderSpec =
291 + new NCompress::NLZMA::CEncoder;
292 + CMyComPtr<ICompressCoder> encoder = encoderSpec;
293 +
294 + PROPID propIDs[] =
295 + {
296 + NCoderPropID::kDictionarySize,
297 + NCoderPropID::kPosStateBits,
298 + NCoderPropID::kLitContextBits,
299 + NCoderPropID::kLitPosBits,
300 + NCoderPropID::kAlgorithm,
301 + NCoderPropID::kNumFastBytes,
302 + NCoderPropID::kMatchFinder,
303 + NCoderPropID::kEndMarker
304 + };
305 + const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
306 +
307 + PROPVARIANT properties[kNumProps];
308 + for (int p = 0; p < 6; p++)
309 + properties[p].vt = VT_UI4;
310 + properties[0].ulVal = UInt32(1 << 15);
311 + properties[1].ulVal = UInt32(ZLIB_PB);
312 + properties[2].ulVal = UInt32(ZLIB_LC); // for normal files
313 + properties[3].ulVal = UInt32(ZLIB_LP); // for normal files
314 + properties[4].ulVal = UInt32(0);
315 + properties[5].ulVal = UInt32(0x28);
316 +
317 + properties[6].vt = VT_BSTR;
318 + properties[6].bstrVal = (BSTR)(const wchar_t *)L"BT4";
319 +
320 + properties[7].vt = VT_BOOL;
321 + properties[7].boolVal = VARIANT_TRUE;
322 +
323 + if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
324 + return Z_MEM_ERROR; // should not happen
325 +
326 + if (encoderSpec->WriteCoderProperties(outStream) != S_OK)
327 + return Z_MEM_ERROR;
328 +
329 + HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);
330 + if (result == E_OUTOFMEMORY)
331 + {
332 + return Z_MEM_ERROR;
333 + }
334 + else if (result != S_OK)
335 + {
336 + return Z_BUF_ERROR; // should not happen
337 + }
338 +
339 + UInt64 fileSize;
340 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
341 + *destLen = fileSize;
342 +
343 + /* Copy size of uncompressed string into first four bytes */
344 + memcpy(dest, &sourceLen, 4);
345 +
346 + return Z_OK;
347 +}
348 +
349 +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
350 + const Bytef *source, uLong sourceLen))
351 +{
352 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source+9, sourceLen-9);
353 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
354 +
355 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
356 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
357 +
358 + NCompress::NLZMA::CDecoder *decoderSpec =
359 + new NCompress::NLZMA::CDecoder;
360 + CMyComPtr<ICompressCoder> decoder = decoderSpec;
361 +
362 + //if (decoderSpec->SetDecoderPropertiesRaw(ZLIB_LC,
363 + // ZLIB_LP, ZLIB_PB, (1 << 23)) != S_OK) return Z_DATA_ERROR;
364 +
365 + if (decoderSpec->SetDecoderProperties2(source+4, 5) != S_OK)
366 + return Z_DATA_ERROR;
367 +
368 + UInt64 fileSize = *destLen;
369 +
370 + if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)
371 + {
372 + return Z_DATA_ERROR;
373 + }
374 +
375 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
376 + *destLen = fileSize;
377 +
378 + return Z_OK;
379 +}
380 diff -Nur lzma432/C/Common/CommandLineParser.h lzma432-owrt/C/Common/CommandLineParser.h
381 --- lzma432/C/Common/CommandLineParser.h 2005-03-07 17:03:46.000000000 +0100
382 +++ lzma432-owrt/C/Common/CommandLineParser.h 2006-03-22 14:23:38.000000000 +0100
383 @@ -3,7 +3,7 @@
384 #ifndef __COMMON_COMMANDLINEPARSER_H
385 #define __COMMON_COMMANDLINEPARSER_H
386
387 -#include "Common/String.h"
388 +#include "String.h"
389
390 namespace NCommandLineParser {
391
392 diff -Nur lzma432/C/Common/StringConvert.h lzma432-owrt/C/Common/StringConvert.h
393 --- lzma432/C/Common/StringConvert.h 2005-09-16 10:19:44.000000000 +0200
394 +++ lzma432-owrt/C/Common/StringConvert.h 2006-03-22 14:23:38.000000000 +0100
395 @@ -4,7 +4,7 @@
396 #define __COMMON_STRINGCONVERT_H
397
398 #include "MyWindows.h"
399 -#include "Common/String.h"
400 +#include "String.h"
401 #include "Types.h"
402
403 UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);
404 diff -Nur lzma432/C/Common/String.cpp lzma432-owrt/C/Common/String.cpp
405 --- lzma432/C/Common/String.cpp 2005-09-28 11:44:06.000000000 +0200
406 +++ lzma432-owrt/C/Common/String.cpp 2006-03-22 14:23:38.000000000 +0100
407 @@ -8,7 +8,7 @@
408 #include <ctype.h>
409 #endif
410
411 -#include "Common/String.h"
412 +#include "String.h"
413
414
415 #ifdef _WIN32