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