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